Search in sources :

Example 66 with Immunization

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

the class ImmunizationFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenImmunizationNotFoundAsJson.

@Test
public void shouldReturnNotFoundWhenImmunizationNotFoundAsJson() throws Exception {
    MockHttpServletResponse response = get("/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 67 with Immunization

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

the class ImmunizationFhirResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchImmunizationIdAsJson.

@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchImmunizationIdAsJson() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Immunization/" + IMMUNIZATION_UUID).accept(FhirMediaTypes.JSON).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).jsonContent(toJson(immunization)).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isBadRequest());
    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 : 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 68 with Immunization

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

the class ImmunizationFhirResourceProviderIntegrationTest method shouldUpdateExistingImmunizationAsJson.

@Test
public void shouldUpdateExistingImmunizationAsJson() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Immunization/" + IMMUNIZATION_UUID).accept(FhirMediaTypes.JSON).go();
    Immunization immunization = readResponse(response);
    // update the existing record
    Date expirationDate = DateUtils.truncate(new Date(), Calendar.DATE);
    immunization.setExpirationDate(expirationDate);
    // send the update to the server
    response = put("/Immunization/" + IMMUNIZATION_UUID).jsonContent(toJson(immunization)).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    // read the updated record
    Immunization updatedImmunization = readResponse(response);
    assertThat(updatedImmunization, notNullValue());
    assertThat(updatedImmunization.getIdElement().getIdPart(), equalTo(IMMUNIZATION_UUID));
    assertThat(updatedImmunization.getExpirationDate(), equalTo(expirationDate));
    assertThat(immunization, validResource());
    // double-check the record returned via get
    response = get("/Immunization/" + IMMUNIZATION_UUID).accept(FhirMediaTypes.JSON).go();
    Immunization reReadImmunization = readResponse(response);
    assertThat(reReadImmunization.getExpirationDate(), equalTo(expirationDate));
}
Also used : Immunization(org.hl7.fhir.r4.model.Immunization) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 69 with Immunization

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

the class ImmunizationFhirResourceProviderIntegrationTest method shouldSearchForExistingImmunizationAsJson.

@Test
public void shouldSearchForExistingImmunizationAsJson() throws Exception {
    MockHttpServletResponse response = get("/Immunization").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/Immunization/"))));
    assertThat(entries, everyItem(hasResource(instanceOf(Immunization.class))));
    assertThat(entries, everyItem(hasResource(validResource())));
    response = get("/Immunization?patient.identifier=M4001-1&_sort=status").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(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 70 with Immunization

use of org.hl7.fhir.r4.model.Immunization in project odm2fhir by num-codex.

the class ImmunizationStatus method createImmunization.

@SuppressWarnings("fallthrough")
private Immunization createImmunization(ItemData immunizationCoding, ItemData dateCoding, ItemData textValue) {
    var immunization = (Immunization) new Immunization().addIdentifier(createIdentifier(IMMUNIZATION, immunizationCoding)).setOccurrence(createDateTimeType(dateCoding)).setMeta(createMeta(NUMStructureDefinition.IMMUNIZATION));
    var vaccineCodeableCoding = new CodeableConcept();
    var diseaseCodeableCoding = new CodeableConcept();
    for (var coding : createCodings(immunizationCoding)) {
        switch(coding.getCode()) {
            case // YES
            "410605003":
                immunization.setStatus(COMPLETED);
                break;
            case // NO
            "410594000":
                immunization.setStatus(NOTDONE);
                break;
            case // Answer = Sonstige/Other
            "385432009":
                diseaseCodeableCoding.addCoding(coding.setDisplay("Not applicable (qualifier value)"));
                if (!textValue.isEmpty()) {
                    diseaseCodeableCoding.setText(textValue.getValue());
                }
                break;
            case // UNKNOWN
            "261665006":
                // do not create FHIR-resources
                return new Immunization();
            // Influenza
            case "836377006":
            // Pneumokokken
            case "836398006":
            // BCG
            case "836402002":
            case // Covid19
            "1119349007":
                vaccineCodeableCoding.addCoding(coding);
                break;
            // cases for targetDisease
            case // Andere
            "64572001":
                if (!textValue.isEmpty()) {
                    diseaseCodeableCoding.setText(textValue.getValue());
                }
            // Influenza
            case "6142004":
            // Pneumokokken
            case "16814004":
            // BCG
            case "56717001":
            case // Covid19
            "840539006":
                diseaseCodeableCoding.addCoding(coding);
                break;
        }
    }
    if (vaccineCodeableCoding.isEmpty()) {
        // add No-Known-Immunuzations if no vaccineCode given
        vaccineCodeableCoding.addCoding(createCoding(NO_IMMUNIZATION_INFO_UV_IPS, "no-known-immunizations", "vaccineCode unknown"));
    }
    if (diseaseCodeableCoding.isEmpty()) {
        // add targetDisease unknown if none present
        diseaseCodeableCoding.addCoding(createCoding(SNOMED_CT, "64572001", "Disease (disorder)"));
    }
    immunization.setVaccineCode(vaccineCodeableCoding).addProtocolApplied(new ImmunizationProtocolAppliedComponent().setDoseNumber((StringType) new StringType().addExtension(DATA_ABSENT_FOR_UNKNOWN_REASON)).addTargetDisease(diseaseCodeableCoding));
    return immunization;
}
Also used : Immunization(org.hl7.fhir.r4.model.Immunization) StringType(org.hl7.fhir.r4.model.StringType) ImmunizationProtocolAppliedComponent(org.hl7.fhir.r4.model.Immunization.ImmunizationProtocolAppliedComponent) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

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