Search in sources :

Example 66 with AllergyIntolerance

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

Example 67 with AllergyIntolerance

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));
}
Also used : AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) BaseFhirResourceProviderWebTest(org.openmrs.module.fhir2.providers.BaseFhirResourceProviderWebTest) Test(org.junit.Test)

Example 68 with AllergyIntolerance

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

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

Example 70 with AllergyIntolerance

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)));
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) 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