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/R3/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 shouldReturnBadRequestWhenDocumentIdDoesNotMatchAllergyIdAsXML.
@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchAllergyIdAsXML() throws Exception {
// get the existing record
MockHttpServletResponse response = get("/AllergyIntolerance/" + ALLERGY_UUID).accept(FhirMediaTypes.XML).go();
AllergyIntolerance allergy = readResponse(response);
// update the existing record
allergy.setId(UNKNOWN_ALLERGY_UUID);
// send the update to the server
response = put("/AllergyIntolerance/" + ALLERGY_UUID).xmlContent(toXML(allergy)).accept(FhirMediaTypes.XML).go();
assertThat(response, isBadRequest());
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 shouldReturnNotFoundWhenUpdatingNonExistentAllergyAsJson.
@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentAllergyAsJson() throws Exception {
// get the existing record
MockHttpServletResponse response = get("/AllergyIntolerance/" + ALLERGY_UUID).accept(FhirMediaTypes.JSON).go();
AllergyIntolerance allergy = readResponse(response);
// update the existing record
allergy.setId(UNKNOWN_ALLERGY_UUID);
// send the update to the server
response = put("/AllergyIntolerance/" + UNKNOWN_ALLERGY_UUID).jsonContent(toJson(allergy)).accept(FhirMediaTypes.JSON).go();
assertThat(response, isNotFound());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.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 shouldReturnCountForAllergyIntoleranceAsJson.
@Test
public void shouldReturnCountForAllergyIntoleranceAsJson() throws Exception {
MockHttpServletResponse response = get("/AllergyIntolerance?_summary=count").accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.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)));
}
use of org.hl7.fhir.r4.model.AllergyIntolerance in project openmrs-module-fhir2 by openmrs.
the class AllergyIntoleranceFhirResourceProviderIntegrationTest method shouldCreateNewAllergyAsJson.
@Test
public void shouldCreateNewAllergyAsJson() throws Exception {
// read JSON record
String jsonAllergy;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_ALLERGY_DOCUMENT)) {
Objects.requireNonNull(is);
jsonAllergy = IOUtils.toString(is, StandardCharsets.UTF_8);
}
// create allergy
MockHttpServletResponse response = post("/AllergyIntolerance").accept(FhirMediaTypes.JSON).jsonContent(jsonAllergy).go();
// verify created correctly
assertThat(response, isCreated());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
AllergyIntolerance allergy = readResponse(response);
assertThat(allergy, notNullValue());
assertThat(allergy.getPatient().getReferenceElement().getIdPart(), equalTo("da7f524f-27ce-4bb2-86d6-6d1d05312bd5"));
assertThat(allergy.getRecorder().getReferenceElement().getIdPart(), equalTo("c98a1558-e131-11de-babe-001e378eb67e"));
assertThat(allergy.getCategory().get(0).getValue().toCode(), equalTo("medication"));
assertThat(allergy.getReactionFirstRep().getSeverity().toCode(), equalTo("severe"));
assertThat(allergy.getReactionFirstRep().getManifestationFirstRep().getCodingFirstRep().getCode(), equalTo("5088AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
assertThat(allergy.getReactionFirstRep().getManifestationFirstRep().getText(), equalTo("manifestation text"));
assertThat(allergy.getCode().getCodingFirstRep().getCode(), equalTo("5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
assertThat(allergy.getClinicalStatus().toCode(), equalTo("active"));
assertThat(allergy.getVerificationStatus().toCode(), equalTo("confirmed"));
assertThat(allergy.getType().toCode(), equalTo("allergy"));
assertThat(allergy, validResource());
// try to get new allergy
response = get("/AllergyIntolerance/" + allergy.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
AllergyIntolerance newAllergy = readResponse(response);
assertThat(newAllergy.getId(), equalTo(allergy.getId()));
}
Aggregations