Search in sources :

Example 81 with AllergyIntolerance

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

the class AllergyIntoleranceFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenDeletingNonExistentAllergyAsJson.

@Test
public void shouldReturnNotFoundWhenDeletingNonExistentAllergyAsJson() throws Exception {
    MockHttpServletResponse response = delete("/AllergyIntolerance/" + UNKNOWN_ALLERGY_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.dstu3.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 82 with AllergyIntolerance

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

the class AllergyIntoleranceFhirResourceProviderIntegrationTest method shouldUpdateExistingAllergyAsXML.

@Test
public void shouldUpdateExistingAllergyAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/AllergyIntolerance/" + ALLERGY_UUID).accept(FhirMediaTypes.XML).go();
    AllergyIntolerance allergy = readResponse(response);
    // update the existing record
    Enumeration<AllergyIntolerance.AllergyIntoleranceCategory> category = new Enumeration<>(new AllergyIntolerance.AllergyIntoleranceCategoryEnumFactory());
    category.setValue(AllergyIntolerance.AllergyIntoleranceCategory.ENVIRONMENT);
    allergy.getCategory().set(0, category);
    // send the update to the server
    response = put("/AllergyIntolerance/" + ALLERGY_UUID).xmlContent(toXML(allergy)).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    // read the updated record
    AllergyIntolerance updatedAllergy = readResponse(response);
    assertThat(updatedAllergy, notNullValue());
    assertThat(updatedAllergy.getIdElement().getIdPart(), equalTo(ALLERGY_UUID));
    assertThat(updatedAllergy.getCategory().get(0).getValue().toCode(), equalTo("environment"));
    assertThat(updatedAllergy, validResource());
    // double-check the record returned via get
    response = get("/AllergyIntolerance/" + ALLERGY_UUID).accept(FhirMediaTypes.XML).go();
    AllergyIntolerance reReadAllergy = readResponse(response);
    assertThat(reReadAllergy.getCategory().get(0).getValue().toCode(), equalTo("environment"));
}
Also used : AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance) Enumeration(org.hl7.fhir.dstu3.model.Enumeration) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 83 with AllergyIntolerance

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

the class AllergyIntoleranceFhirResourceProviderIntegrationTest method shouldSearchForExistingAllergyAsXML.

@Test
public void shouldSearchForExistingAllergyAsXML() throws Exception {
    MockHttpServletResponse response = get("/AllergyIntolerance").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/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.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("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 84 with AllergyIntolerance

use of org.hl7.fhir.r4.model.AllergyIntolerance in project org.hl7.fhir.core by hapifhir.

the class CCDAConverter method processAllergyProblemAct.

protected void processAllergyProblemAct(ListResource list, Element concern) throws Exception {
    cda.checkTemplateId(concern, "2.16.840.1.113883.10.20.22.4.30");
    // Allergy Problem Act - this is a concern - we treat the concern as information about it's place in the list
    checkNoNegationOrNullFlavor(concern, "Allergy Problem Act");
    checkNoSubject(concern, "Allergy Problem Act");
    // SHALL contain exactly one [1..1] Allergy - intolerance Observation
    for (Element entry : cda.getChildren(concern, "entryRelationship")) {
        Element obs = cda.getChild(entry, "observation");
        cda.checkTemplateId(obs, "2.16.840.1.113883.10.20.22.4.7");
        checkNoNegationOrNullFlavor(obs, "Allergy - intolerance Observation");
        checkNoSubject(obs, "Allergy Problem Act");
        AllergyIntolerance ai = new AllergyIntolerance();
        ListEntryComponent item = addItemToList(list, ai);
        // SHALL contain at least one [1..*] id (CONF:7472).
        for (Element e : cda.getChildren(concern, "id")) ai.getIdentifier().add(convert.makeIdentifierFromII(e));
        // SHALL contain exactly one [1..1] statusCode, which SHALL be selected from ValueSet 2.16.840.1.113883.3.88.12.80.68 HITSPProblemStatus DYNAMIC (CONF:7485)
        // the status code is about the concern (e.g. the entry in the list)
        // possible values: active, suspended, aborted, completed, with an effective time
        String s = cda.getStatus(concern);
        item.setFlag(Factory.newCodeableConcept(s, "http://hl7.org/fhir/v3/ActStatus", s));
        if (// only on this condition?
        s.equals("aborted"))
            item.setDeleted(true);
        // SHALL contain exactly one [1..1] effectiveTime (CONF:7498)
        Period p = convert.makePeriodFromIVL(cda.getChild(concern, "effectiveTime"));
        item.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/list-period", p, false));
        if (p.getEnd() != null)
            item.setDate(p.getEnd());
        else
            item.setDate(p.getStart());
        // SHALL contain at least one [1..*] id (CONF:7382)
        for (Element e : cda.getChildren(obs, "id")) ai.getIdentifier().add(convert.makeIdentifierFromII(e));
        // SHALL contain exactly one [1..1] effectiveTime (CONF:7387)
        ai.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/allergyintolerance-period", convert.makePeriodFromIVL(cda.getChild(obs, "effectiveTime")), false));
        // SHALL contain exactly one [1..1] value with @xsi:type="CD" (CONF:7390)
        CodeableConcept type = convert.makeCodeableConceptFromCD(cda.getChild(obs, "value"));
        // This value SHALL contain @code, which SHALL be selected from ValueSet 2.16.840.1.113883.3.88.12.3221.6.2 Allergy/Adverse Event Type
        String ss = type.getCoding().get(0).getCode();
        if (ss.equals("416098002") || ss.equals("414285001"))
            ai.setType(AllergyIntoleranceType.ALLERGY);
        else if (ss.equals("59037007") || ss.equals("235719002"))
            ai.setType(AllergyIntoleranceType.INTOLERANCE);
        ai.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/allergy-category", type, false));
        // SHOULD contain zero or one [0..1] participant (CONF:7402) such that it
        // ......This playingEntity SHALL contain exactly one [1..1] code
        ai.setCode(convert.makeCodeableConceptFromCD(cda.getDescendent(obs, "participant/participantRole/playingEntity/code")));
        // SHOULD contain zero or more [0..*] entryRelationship (CONF:7447) such that it SHALL contain exactly one [1..1] Reaction Observation (templateId:2.16.840.1.113883.10.20.22.4.9) (CONF:7450).
        for (Element e : cda.getChildren(obs, "entryRelationship")) {
            Element child = cda.getChild(e, "observation");
            if (cda.hasTemplateId(child, "2.16.840.1.113883.10.20.22.4.28") && ai.getClinicalStatus() == null) {
                // SHALL contain exactly one [1..1] value with @xsi:type="CE", where the @code SHALL be selected from ValueSet Problem Status Value Set 2.16.840.1.113883.3.88.12.80.68 DYNAMIC (CONF:7322).
                // 55561003  SNOMED CT  Active
                // 73425007  SNOMED CT  Inactive
                // 413322009  SNOMED CT  Resolved
                String sc = cda.getChild(child, "value").getAttribute("code");
                if (sc.equals("55561003")) {
                    ai.setClinicalStatus(AllergyIntoleranceClinicalStatus.ACTIVE);
                    ai.setVerificationStatus(AllergyIntoleranceVerificationStatus.CONFIRMED);
                } else
                    ai.setClinicalStatus(AllergyIntoleranceClinicalStatus.RESOLVED);
            } else if (cda.hasTemplateId(child, "2.16.840.1.113883.10.20.22.4.9")) {
                ai.getReaction().add(processAdverseReactionObservation(child));
            }
        }
        // SHOULD contain zero or one [0..1] entryRelationship (CONF:9961) such that it SHALL contain exactly one [1..1] Severity Observation (templateId:2.16.840.1.113883.10.20.22.4.8) (CONF:9963).
        ai.setCriticality(readCriticality(cda.getSeverity(obs)));
    }
}
Also used : AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance) Element(org.w3c.dom.Element) ListEntryComponent(org.hl7.fhir.dstu3.model.ListResource.ListEntryComponent)

Example 85 with AllergyIntolerance

use of org.hl7.fhir.r4.model.AllergyIntolerance in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeAllergyIntoleranceAllergyIntoleranceReactionComponent.

protected void composeAllergyIntoleranceAllergyIntoleranceReactionComponent(Complex parent, String parentType, String name, AllergyIntolerance.AllergyIntoleranceReactionComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "reaction", name, element, index);
    if (element.hasSubstance())
        composeCodeableConcept(t, "AllergyIntolerance", "substance", element.getSubstance(), -1);
    for (int i = 0; i < element.getManifestation().size(); i++) composeCodeableConcept(t, "AllergyIntolerance", "manifestation", element.getManifestation().get(i), i);
    if (element.hasDescriptionElement())
        composeString(t, "AllergyIntolerance", "description", element.getDescriptionElement(), -1);
    if (element.hasOnsetElement())
        composeDateTime(t, "AllergyIntolerance", "onset", element.getOnsetElement(), -1);
    if (element.hasSeverityElement())
        composeEnum(t, "AllergyIntolerance", "severity", element.getSeverityElement(), -1);
    if (element.hasExposureRoute())
        composeCodeableConcept(t, "AllergyIntolerance", "exposureRoute", element.getExposureRoute(), -1);
    for (int i = 0; i < element.getNote().size(); i++) composeAnnotation(t, "AllergyIntolerance", "note", element.getNote().get(i), i);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

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