Search in sources :

Example 76 with AllergyIntolerance

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())));
}
Also used : AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance) Bundle(org.hl7.fhir.dstu3.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 77 with AllergyIntolerance

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));
}
Also used : AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 78 with AllergyIntolerance

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));
}
Also used : AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 79 with AllergyIntolerance

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)));
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 80 with AllergyIntolerance

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()));
}
Also used : AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance) InputStream(java.io.InputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)158 AllergyIntolerance (org.hl7.fhir.r4.model.AllergyIntolerance)93 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)53 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)53 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)43 AllergyIntolerance (org.hl7.fhir.dstu3.model.AllergyIntolerance)42 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)29 TokenParam (ca.uhn.fhir.rest.param.TokenParam)29 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)26 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)25 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)25 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)23 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)23 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)23 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)21 MockIBundleProvider (org.openmrs.module.fhir2.providers.r4.MockIBundleProvider)14 InputStream (java.io.InputStream)12 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)12 Date (java.util.Date)10 IdType (org.hl7.fhir.r4.model.IdType)10