Search in sources :

Example 26 with Immunization

use of org.hl7.fhir.r4.model.Immunization in project openmrs-module-fhir2 by openmrs.

the class ImmunizationFhirResourceProviderIntegrationTest method shouldCreateNewImmunizationAsXML.

@Test
public void shouldCreateNewImmunizationAsXML() throws Exception {
    // read XML record
    String xmlImmunization;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_IMMUNIZATION_DOCUMENT)) {
        Objects.requireNonNull(is);
        xmlImmunization = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    // create IMMUNIZATION
    MockHttpServletResponse response = post("/Immunization").accept(FhirMediaTypes.XML).xmlContent(xmlImmunization).go();
    // verify created correctly
    assertThat(response, isCreated());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Immunization immunization = readResponse(response);
    assertThat(immunization, notNullValue());
    assertThat(immunization.getResourceType().toString(), equalTo("Immunization"));
    assertThat(immunization.getStatus().toCode(), equalTo("completed"));
    assertThat(immunization.getVaccineCode().getCodingFirstRep().getCode(), equalTo("15f83cd6-64e9-4e06-a5f9-364d3b14a43d"));
    assertThat(immunization.getPatient().getReferenceElement().getIdPart(), equalTo("8d703ff2-c3e2-4070-9737-73e713d5a50d"));
    assertThat(immunization.getOccurrenceDateTimeType().getValueAsCalendar().getTime(), sameInstant(Date.from(ZonedDateTime.parse("2020-07-08T18:30:00.000Z").toInstant())));
    assertThat(immunization.hasManufacturer(), is(true));
    assertThat(immunization.getManufacturer().getDisplay(), equalTo("ACME"));
    assertThat(immunization.getLotNumber(), equalTo("FOO1234"));
    assertThat(immunization.getExpirationDate(), sameDay(Date.from(ZonedDateTime.parse("2022-07-31T18:30:00.000Z").toInstant())));
    assertThat(immunization.getPerformer().get(0).getActor().getReferenceElement().getIdPart(), equalTo("6f763a67-2bd1-451c-93b9-95caeb36cc24"));
    assertThat(immunization, validResource());
    // try to get new IMMUNIZATION
    response = get("/Immunization/" + immunization.getIdElement().getIdPart()).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    Immunization newImmunization = readResponse(response);
    assertThat(newImmunization.getId(), equalTo(immunization.getId()));
}
Also used : Immunization(org.hl7.fhir.r4.model.Immunization) InputStream(java.io.InputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 27 with Immunization

use of org.hl7.fhir.r4.model.Immunization in project openmrs-module-fhir2 by openmrs.

the class ImmunizationFhirResourceProviderIntegrationTest method shouldSearchForExistingImmunizationAsXML.

@Test
public void shouldSearchForExistingImmunizationAsXML() throws Exception {
    MockHttpServletResponse response = get("/Immunization").accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.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/Immunization/"))));
    assertThat(entries, everyItem(hasResource(instanceOf(Immunization.class))));
    assertThat(entries, everyItem(hasResource(validResource())));
    response = get("/Immunization?patient.identifier=M4001-1&_sort=status").accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.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(PATIENT_UUID)))))));
    assertThat(entries, everyItem(hasResource(validResource())));
}
Also used : Immunization(org.hl7.fhir.r4.model.Immunization) Bundle(org.hl7.fhir.r4.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 28 with Immunization

use of org.hl7.fhir.r4.model.Immunization in project openmrs-module-fhir2 by openmrs.

the class ImmunizationFhirResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchImmunizationIdAsXML.

@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchImmunizationIdAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Immunization/" + IMMUNIZATION_UUID).accept(FhirMediaTypes.XML).go();
    Immunization immunization = readResponse(response);
    // update the existing record
    immunization.setId(UNKNOWN_IMMUNIZATION_UUID);
    // send the update to the server
    response = put("/Immunization/" + IMMUNIZATION_UUID).xmlContent(toXML(immunization)).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 : Immunization(org.hl7.fhir.r4.model.Immunization) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 29 with Immunization

use of org.hl7.fhir.r4.model.Immunization in project openmrs-module-fhir2 by openmrs.

the class ImmunizationFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenDeletingNonExistentImmunizationAsJson.

@Test
public void shouldReturnNotFoundWhenDeletingNonExistentImmunizationAsJson() throws Exception {
    MockHttpServletResponse response = delete("/Immunization/" + UNKNOWN_IMMUNIZATION_UUID).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 : OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 30 with Immunization

use of org.hl7.fhir.r4.model.Immunization in project openmrs-module-fhir2 by openmrs.

the class ImmunizationFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentImmunizationAsXML.

@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentImmunizationAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Immunization/" + IMMUNIZATION_UUID).accept(FhirMediaTypes.XML).go();
    Immunization immunization = readResponse(response);
    // update the existing record
    immunization.setId(UNKNOWN_IMMUNIZATION_UUID);
    // send the update to the server
    response = put("/Immunization/" + UNKNOWN_IMMUNIZATION_UUID).xmlContent(toXML(immunization)).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 : Immunization(org.hl7.fhir.r4.model.Immunization) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

Immunization (org.hl7.fhir.r4.model.Immunization)47 Test (org.junit.Test)27 Test (org.junit.jupiter.api.Test)22 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)18 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)15 Resource (org.hl7.fhir.r4.model.Resource)13 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)8 Bundle (org.hl7.fhir.r4.model.Bundle)7 Organization (org.hl7.fhir.r4.model.Organization)7 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)6 Date (java.util.Date)5 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)5 IdType (org.hl7.fhir.r4.model.IdType)5 Observation (org.hl7.fhir.r4.model.Observation)5 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)5 InputStream (java.io.InputStream)4 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)4 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)4 Obs (org.openmrs.Obs)4 FhirContext (ca.uhn.fhir.context.FhirContext)3