use of org.hl7.fhir.r4.model.AllergyIntolerance in project openmrs-module-fhir2 by openmrs.
the class AllergyIntoleranceFhirResourceProviderWebTest method updateAllergyIntolerance_shouldUpdateRequestedAllergyIntolerance.
@Test
public void updateAllergyIntolerance_shouldUpdateRequestedAllergyIntolerance() throws Exception {
AllergyIntolerance allergy = new AllergyIntolerance();
allergy.setId(ALLERGY_UUID);
String createAllergyJson;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_UPDATE_ALLERGY_PATH)) {
Objects.requireNonNull(is);
createAllergyJson = IOUtils.toString(is, StandardCharsets.UTF_8);
}
when(allergyService.update(any(String.class), any(AllergyIntolerance.class))).thenReturn(allergy);
MockHttpServletResponse response = put("/AllergyIntolerance/" + ALLERGY_UUID).jsonContent(createAllergyJson).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
}
use of org.hl7.fhir.r4.model.AllergyIntolerance in project openmrs-module-fhir2 by openmrs.
the class AllergyIntoleranceFhirResourceProviderWebTest method getAllergyIntoleranceByUuid_shouldReturnAllergy.
@Test
public void getAllergyIntoleranceByUuid_shouldReturnAllergy() throws Exception {
AllergyIntolerance allergy = new AllergyIntolerance();
allergy.setId(ALLERGY_UUID);
when(allergyService.get(ALLERGY_UUID)).thenReturn(allergy);
MockHttpServletResponse response = get("/AllergyIntolerance/" + ALLERGY_UUID).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
assertThat(readResponse(response).getIdElement().getIdPart(), equalTo(ALLERGY_UUID));
}
use of org.hl7.fhir.r4.model.AllergyIntolerance in project openmrs-module-fhir2 by openmrs.
the class AllergyIntoleranceFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenDeletingNonExistentAllergyAsXML.
@Test
public void shouldReturnNotFoundWhenDeletingNonExistentAllergyAsXML() throws Exception {
MockHttpServletResponse response = delete("/AllergyIntolerance/" + UNKNOWN_ALLERGY_UUID).accept(FhirMediaTypes.XML).go();
assertThat(response, isNotFound());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
OperationOutcome operationOutcome = readOperationOutcome(response);
assertThat(operationOutcome, notNullValue());
assertThat(operationOutcome.hasIssue(), is(true));
}
use of org.hl7.fhir.r4.model.AllergyIntolerance in project openmrs-module-fhir2 by openmrs.
the class AllergyIntoleranceFhirResourceProviderIntegrationTest method shouldSearchForExistingAllergyAsJson.
@Test
public void shouldSearchForExistingAllergyAsJson() throws Exception {
MockHttpServletResponse response = get("/AllergyIntolerance").accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
Bundle results = readBundleResponse(response);
assertThat(results, notNullValue());
assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET));
assertThat(results.hasEntry(), is(true));
List<Bundle.BundleEntryComponent> entries = results.getEntry();
assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/AllergyIntolerance/"))));
assertThat(entries, everyItem(hasResource(instanceOf(AllergyIntolerance.class))));
assertThat(entries, everyItem(hasResource(validResource())));
response = get("/AllergyIntolerance?patient.identifier=M4001-1&_sort=severity").accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
results = readBundleResponse(response);
assertThat(results, notNullValue());
assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET));
assertThat(results.hasEntry(), is(true));
entries = results.getEntry();
assertThat(entries, everyItem(hasResource(hasProperty("patient", hasProperty("referenceElement", hasProperty("idPart", equalTo("8d703ff2-c3e2-4070-9737-73e713d5a50d")))))));
assertThat(entries, containsInRelativeOrder(hasResource(hasProperty("criticality", hasProperty("display", equalTo("Low Risk")))), // mild
hasResource(hasProperty("criticality", hasProperty("display", equalTo("Unable to Assess Risk")))), // severe
hasResource(hasProperty("criticality", hasProperty("display", equalTo("High Risk")))), // null
hasResource(hasProperty("criticality", equalTo(null)))));
assertThat(entries, everyItem(hasResource(validResource())));
}
use of org.hl7.fhir.r4.model.AllergyIntolerance in project openmrs-module-fhir2 by openmrs.
the class AllergyIntoleranceFhirResourceProviderIntegrationTest method shouldReturnCountForAllergyIntoleranceAsXml.
@Test
public void shouldReturnCountForAllergyIntoleranceAsXml() throws Exception {
MockHttpServletResponse response = get("/AllergyIntolerance?_summary=count").accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
Bundle result = readBundleResponse(response);
assertThat(result, notNullValue());
assertThat(result.getType(), equalTo(Bundle.BundleType.SEARCHSET));
assertThat(result, hasProperty("total", equalTo(6)));
}
Aggregations