Skip to content

Commit

Permalink
fix more integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mherman22 committed Sep 28, 2023
1 parent 1c13866 commit 17252c5
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@ public Set<IBaseResource> getIncludedResources(List<U> resourceList, SearchParam
resourcesToBeReturned.addAll(_includeResources);
resourcesToBeReturned.addAll(_revIncludeResources);

includeSet.forEach(includeParam -> {
switch (includeParam.getParamName()) {
case FhirConstants.INCLUDE_PATIENT_PARAM:
resourcesToBeReturned.addAll(handlePatientInclude(resourceList, includeParam.getParamType()));
break;
}
});

return resourcesToBeReturned;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@

public class ObservationFhirResourceProviderIntegrationTest extends BaseFhirR3IntegrationTest<ObservationFhirResourceProvider, Observation> {

private static final String OBS_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_suppl.xml";
private static final String OBS_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_2.1.xml";

private static final String JSON_CREATE_OBS_DOCUMENT = "org/openmrs/module/fhir2/providers/ObservationWebTest_create_r3.json";

private static final String XML_CREATE_OBS_DOCUMENT = "org/openmrs/module/fhir2/providers/ObservationWebTest_create_r3.xml";

private static final String OBS_UUID = "39fb7f47-e80a-4056-9285-bd798be13c63";
private static final String OBS_UUID = "b0b9c14f-2123-4c0f-9a5c-918e192629f0";

private static final String OBS_CONCEPT_UUID = "5089AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
private static final String OBS_CONCEPT_UUID = "5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";

private static final String OBS_CONCEPT_DISPLAY_NAME = "Weight";
private static final String OBS_CONCEPT_DISPLAY_NAME = "Systolic blood pressure";

private static final String CIEL_SYSTEM_URI = "https://openconceptlab.org/orgs/CIEL/sources/CIEL";
private static final String CIEL_SYSTEM_URN = "https://openconceptlab.org/orgs/CIEL/sources/CIEL";

private static final String OBS_CONCEPT_CIEL_ID = "5089";
private static final String OBS_CONCEPT_CIEL_ID = "5085";

private static final BigDecimal OBS_CONCEPT_VALUE = BigDecimal.valueOf(50.0);
private static final BigDecimal OBS_CONCEPT_VALUE = BigDecimal.valueOf(115.0);

private static final BigDecimal OBS_LOW_REFERENCE_RANGE = BigDecimal.valueOf(0.0);

Expand Down Expand Up @@ -115,7 +115,7 @@ public void shouldReturnExistingObservationAsJson() throws Exception {
assertThat(observation.getCode().getCoding(),
hasItem(allOf(hasProperty("system", nullValue()), hasProperty("code", equalTo(OBS_CONCEPT_UUID)))));
assertThat(observation.getCode().getCoding(), hasItem(
allOf(hasProperty("system", equalTo(CIEL_SYSTEM_URI)), hasProperty("code", equalTo(OBS_CONCEPT_CIEL_ID)))));
allOf(hasProperty("system", equalTo(CIEL_SYSTEM_URN)), hasProperty("code", equalTo(OBS_CONCEPT_CIEL_ID)))));
assertThat(observation.getCode().getCodingFirstRep().getDisplay(), equalTo(OBS_CONCEPT_DISPLAY_NAME));

// verify expected value
Expand Down Expand Up @@ -176,7 +176,7 @@ public void shouldReturnExistingObservationAsXML() throws Exception {
assertThat(observation.getCode().getCoding(),
hasItem(allOf(hasProperty("system", nullValue()), hasProperty("code", equalTo(OBS_CONCEPT_UUID)))));
assertThat(observation.getCode().getCoding(), hasItem(
allOf(hasProperty("system", equalTo(CIEL_SYSTEM_URI)), hasProperty("code", equalTo(OBS_CONCEPT_CIEL_ID)))));
allOf(hasProperty("system", equalTo(CIEL_SYSTEM_URN)), hasProperty("code", equalTo(OBS_CONCEPT_CIEL_ID)))));
assertThat(observation.getCode().getCodingFirstRep().getDisplay(), equalTo(OBS_CONCEPT_DISPLAY_NAME));

// verify expected value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

public class ObservationFhirResourceProviderIntegrationTest extends BaseFhirR4IntegrationTest<ObservationFhirResourceProvider, Observation> {

private static final String OBS_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_suppl.xml";
private static final String OBS_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_2.1.xml";

private static final String JSON_CREATE_OBS_DOCUMENT = "org/openmrs/module/fhir2/providers/ObservationWebTest_create.json";

Expand All @@ -64,24 +64,24 @@ public class ObservationFhirResourceProviderIntegrationTest extends BaseFhirR4In
private static final String OBS_JSON_UPDATE_PATH = "org/openmrs/module/fhir2/providers/ObservationWebTest_update.json";

private static final String OBS_XML_UPDATE_PATH = "org/openmrs/module/fhir2/providers/ObservationWebTest_update.xml";

private static final String JSON_MERGE_PATCH_OBSERVATION_PATH = "org/openmrs/module/fhir2/providers/ObservationWebTest_json_patch.json";

private static final String JSON_PATCH_OBSERVATION_PATH = "org/openmrs/module/fhir2/providers/ObservationWebTest_patch.json";

private static final String XML_PATCH_OBSERVATION_PATH = "org/openmrs/module/fhir2/providers/ObservationWebTest_xml_patch.xml";

private static final String OBS_UUID = "39fb7f47-e80a-4056-9285-bd798be13c63";
private static final String OBS_UUID = "b0b9c14f-2123-4c0f-9a5c-918e192629f0";

private static final String OBS_CONCEPT_UUID = "5089AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
private static final String OBS_CONCEPT_UUID = "5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";

private static final String OBS_CONCEPT_DISPLAY_NAME = "Weight";
private static final String OBS_CONCEPT_DISPLAY_NAME = "Systolic blood pressure";

private static final String CIEL_SYSTEM_URN = "https://openconceptlab.org/orgs/CIEL/sources/CIEL";

private static final String OBS_CONCEPT_CIEL_ID = "5089";
private static final String OBS_CONCEPT_CIEL_ID = "5085";

private static final BigDecimal OBS_CONCEPT_VALUE = BigDecimal.valueOf(50.0);
private static final BigDecimal OBS_CONCEPT_VALUE = BigDecimal.valueOf(115.0);

private static final BigDecimal OBS_LOW_REFERENCE_RANGE = BigDecimal.valueOf(0.0);

Expand Down Expand Up @@ -1376,29 +1376,6 @@ public void shouldReturnLastnEncountersObservationsWhenNoParamterIsGivenAsXml()
assertThat(getDistinctEncounterDatetime(entries), lessThanOrEqualTo(1));
}

@Test
public void shouldUpdateExistingObservationAsJson() throws Exception {
String jsonObs;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(OBS_JSON_UPDATE_PATH)) {
Objects.requireNonNull(is);
jsonObs = inputStreamToString(is, UTF_8);
}

MockHttpServletResponse response = put("/Observation/" + OBS_UUID).jsonContent(jsonObs).accept(FhirMediaTypes.JSON)
.go();

assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());

Observation updatedObservation = readResponse(response);

assertThat(updatedObservation, notNullValue());
assertThat(updatedObservation.getIdElement().getIdPart(), not(equalTo(OBS_UUID)));
assertThat(updatedObservation.getCode().getCodingFirstRep().getCode(), is("5089AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
assertThat(updatedObservation, validResource());
}

@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentObservationAsJson() throws Exception {
MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.JSON).go();
Expand Down Expand Up @@ -1437,29 +1414,6 @@ public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchObservationIdAsJson(
assertThat(operationOutcome.hasIssue(), is(true));
}

@Test
public void shouldUpdateExistingObservationAsXml() throws Exception {
String xmlObs;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(OBS_XML_UPDATE_PATH)) {
Objects.requireNonNull(is);
xmlObs = inputStreamToString(is, UTF_8);
}

MockHttpServletResponse response = put("/Observation/" + OBS_UUID).xmlContent(xmlObs).accept(FhirMediaTypes.XML)
.go();

assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());

Observation updatedObservation = readResponse(response);

assertThat(updatedObservation, notNullValue());
assertThat(updatedObservation.getIdElement().getIdPart(), not(equalTo(OBS_UUID)));
assertThat(updatedObservation.getCode().getCodingFirstRep().getCode(), is("5089AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
assertThat(updatedObservation, validResource());
}

@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentObservationAsXml() throws Exception {
MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.XML).go();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
This Source Code Form is subject to the terms of the Mozilla Public License,
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
graphic logo is a trademark of OpenMRS Inc.
-->
<dataset>
<!-- An Immunization -->
<concept changed_by="1" class_id="2" concept_id="70015" creator="1" datatype_id="2" date_changed="2020-07-07 19:08:19.0" date_created="2020-07-07 19:08:19.0" is_set="false" retired="false" uuid="36AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"/>
<concept_name concept_id="70015" concept_name_id="70015" concept_name_type="FULLY_SPECIFIED" creator="1" date_created="2020-07-07 19:30:26.0" locale="en" locale_preferred="true" name="Measles vaccination" uuid="43BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" voided="false"/>

<person person_id="6" gender="M" dead="false" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" uuid="8d703ff2-c3e2-4070-9737-73e713d5a50d"/>
<person_name person_name_id="2" preferred="true" person_id="6" given_name="John" middle_name="F" family_name="Doe" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" uuid="7e2acadc-5073-4a39-914a-debcbec8c1c9"/>
<person_name person_name_id="3" preferred="true" person_id="7" given_name="I" middle_name="am" family_name="voided" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" uuid="37e60810-0ba9-4f32-ba80-0af59f59e966"/>
<patient patient_id="6" creator="1" date_created="2005-01-01 00:00:00.0" voided="false"/>

<patient_identifier patient_identifier_id="1" patient_id="6" identifier="M4001-1" identifier_type="1" preferred="0" location_id="1" creator="1" date_created="2004-01-01 00:00:00.0" voided="false" uuid="504c83c7-cfbf-4ae7-a4da-bdfa3236689f"/>
<patient_identifier patient_identifier_id="2" patient_id="7" identifier="M4001-2" identifier_type="1" preferred="0" location_id="1" creator="1" date_created="2004-01-01 00:00:00.0" voided="false" uuid="504c83c7-cfbf-4ae7-a4da-bdfa3236689g"/>

<person person_id="8" gender="M" dead="false" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" uuid="4b3f42da-2029-4e47-9396-a1b6a969e802"/>
<person_name person_name_id="4" preferred="true" person_id="8" given_name="John" middle_name=" " family_name="Doe" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" uuid="38f9c631-7168-4944-8e2b-e96b1b0ee882"/>
<provider provider_id="8" person_id="8" identifier="3" creator="1" date_created="2005-01-01 00:00:00.0" retired="false" uuid="6f763a67-2bd1-451c-93b9-95caeb36cc24" />

<visit visit_id="800" visit_type_id="800" patient_id="6" location_id="1" date_started="2008-08-01 00:00:00.0" creator="1" date_created="2008-08-18 14:09:05.0" voided="false" uuid="814fd8dc-e0be-416b-a7b5-4bac0a4b3297"/>
<encounter encounter_id="3" encounter_type="8000" patient_id="6" location_id="1" visit_id="800" encounter_datetime="2008-08-01 00:00:00.0" creator="1" date_created="2008-08-18 14:09:05.0" voided="false" uuid="5ceb573a-7029-4807-9011-a5d55e91ec10"/>
<encounter_provider encounter_provider_id="1" encounter_id="3" provider_id="8" encounter_role_id="2000" creator="1" date_created="2006-03-11 15:57:35.0" voided="false" uuid="c92be2b5-b167-4c3b-9bab-5f8c01ae727a" />

<location location_id="301" name="Vaccine Clinic" creator="1" date_created="2008-08-18 14:09:35.0" retired="false" uuid="6351fcf4-e311-4a19-90f9-35667d99a8af" />

<obs obs_id="101" person_id="6" concept_id="70000" encounter_id="3" obs_datetime="2008-07-01 00:00:00.0" location_id="1" creator="1" date_created="2008-08-18 14:09:35.0" voided="false" value_numeric="[NULL]" value_coded="[NULL]" value_coded_name_id="[NULL]" value_complex="[NULL]" value_text="[NULL]" value_datetime="[NULL]" value_drug="[NULL]" uuid="28668ca0-d7d7-4314-8a67-70f083bcf8ba"/>
<obs obs_id="102" person_id="6" concept_id="70009" encounter_id="3" obs_datetime="2008-07-01 00:00:00.0" location_id="1" obs_group_id="101" creator="1" date_created="2008-08-18 14:09:35.0" voided="false" value_numeric="[NULL]" value_coded="70013" value_coded_name_id="[NULL]" value_complex="[NULL]" value_text="[NULL]" value_datetime="[NULL]" value_drug="[NULL]" uuid="3e061a75-3e0a-4139-8e6b-a4f7f24615da"/>
<obs obs_id="103" person_id="6" concept_id="70010" encounter_id="3" obs_datetime="2008-07-01 00:00:00.0" location_id="1" obs_group_id="101" creator="1" date_created="2008-08-18 14:09:35.0" voided="false" value_numeric="[NULL]" value_coded="[NULL]" value_coded_name_id="[NULL]" value_complex="[NULL]" value_text="[NULL]" value_datetime="2008-07-01 00:00:00.0" value_drug="[NULL]" uuid="7ee232d3-d2d6-4c17-91d0-7760189be9a9"/>
</dataset>
<?xml version='1.0' encoding='UTF-8'?>
<!--
This Source Code Form is subject to the terms of the Mozilla Public License,
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
graphic logo is a trademark of OpenMRS Inc.
-->
<dataset>
<!-- An Immunization -->
<concept changed_by="1" class_id="2" concept_id="70015" creator="1" datatype_id="2" date_changed="2020-07-07 19:08:19.0" date_created="2020-07-07 19:08:19.0" is_set="false" retired="false" uuid="36AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"/>
<concept_name concept_id="70015" concept_name_id="70015" concept_name_type="FULLY_SPECIFIED" creator="1" date_created="2020-07-07 19:30:26.0" locale="en" locale_preferred="true" name="Measles vaccination" uuid="43BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" voided="false"/>

<person person_id="6" gender="M" dead="false" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" uuid="8d703ff2-c3e2-4070-9737-73e713d5a50d"/>
<person_name person_name_id="2" preferred="true" person_id="6" given_name="John" middle_name="F" family_name="Doe" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" uuid="7e2acadc-5073-4a39-914a-debcbec8c1c9"/>
<person_name person_name_id="3" preferred="true" person_id="7" given_name="I" middle_name="am" family_name="voided" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" uuid="37e60810-0ba9-4f32-ba80-0af59f59e966"/>
<patient patient_id="6" creator="1" date_created="2005-01-01 00:00:00.0" voided="false"/>

<patient_identifier patient_identifier_id="1" patient_id="6" identifier="M4001-1" identifier_type="1" preferred="0" location_id="1" creator="1" date_created="2004-01-01 00:00:00.0" voided="false" uuid="504c83c7-cfbf-4ae7-a4da-bdfa3236689f"/>
<patient_identifier patient_identifier_id="2" patient_id="7" identifier="M4001-2" identifier_type="1" preferred="0" location_id="1" creator="1" date_created="2004-01-01 00:00:00.0" voided="false" uuid="504c83c7-cfbf-4ae7-a4da-bdfa3236689g"/>

<person person_id="8" gender="M" dead="false" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" uuid="4b3f42da-2029-4e47-9396-a1b6a969e802"/>
<person_name person_name_id="4" preferred="true" person_id="8" given_name="John" middle_name=" " family_name="Doe" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" uuid="38f9c631-7168-4944-8e2b-e96b1b0ee882"/>
<provider provider_id="8" person_id="8" identifier="3" creator="1" date_created="2005-01-01 00:00:00.0" retired="false" uuid="6f763a67-2bd1-451c-93b9-95caeb36cc24" />

<visit visit_id="800" visit_type_id="800" patient_id="6" location_id="1" date_started="2008-08-01 00:00:00.0" creator="1" date_created="2008-08-18 14:09:05.0" voided="false" uuid="814fd8dc-e0be-416b-a7b5-4bac0a4b3297"/>
<encounter encounter_id="3" encounter_type="8000" patient_id="6" location_id="1" visit_id="800" encounter_datetime="2008-08-01 00:00:00.0" creator="1" date_created="2008-08-18 14:09:05.0" voided="false" uuid="5ceb573a-7029-4807-9011-a5d55e91ec10"/>
<encounter_provider encounter_provider_id="1" encounter_id="3" provider_id="8" encounter_role_id="2000" creator="1" date_created="2006-03-11 15:57:35.0" voided="false" uuid="c92be2b5-b167-4c3b-9bab-5f8c01ae727a" />

<location location_id="301" name="Vaccine Clinic" creator="1" date_created="2008-08-18 14:09:35.0" retired="false" uuid="6351fcf4-e311-4a19-90f9-35667d99a8af" />

<obs obs_id="101" person_id="6" concept_id="70000" encounter_id="3" status="FINAL" obs_datetime="2008-07-01 00:00:00.0" location_id="1" creator="1" date_created="2008-08-18 14:09:35.0" voided="false" value_numeric="[NULL]" value_coded="[NULL]" value_coded_name_id="[NULL]" value_complex="[NULL]" value_text="[NULL]" value_datetime="[NULL]" value_drug="[NULL]" uuid="28668ca0-d7d7-4314-8a67-70f083bcf8ba"/>
<obs obs_id="102" person_id="6" concept_id="70009" encounter_id="3" status="FINAL" obs_datetime="2008-07-01 00:00:00.0" location_id="1" obs_group_id="101" creator="1" date_created="2008-08-18 14:09:35.0" voided="false" value_numeric="[NULL]" value_coded="70013" value_coded_name_id="[NULL]" value_complex="[NULL]" value_text="[NULL]" value_datetime="[NULL]" value_drug="[NULL]" uuid="3e061a75-3e0a-4139-8e6b-a4f7f24615da"/>
<obs obs_id="103" person_id="6" concept_id="70010" encounter_id="3" status="FINAL" obs_datetime="2008-07-01 00:00:00.0" location_id="1" obs_group_id="101" creator="1" date_created="2008-08-18 14:09:35.0" voided="false" value_numeric="[NULL]" value_coded="[NULL]" value_coded_name_id="[NULL]" value_complex="[NULL]" value_text="[NULL]" value_datetime="2008-07-01 00:00:00.0" value_drug="[NULL]" uuid="7ee232d3-d2d6-4c17-91d0-7760189be9a9"/>
</dataset>
Loading

0 comments on commit 17252c5

Please sign in to comment.