Search in sources :

Example 61 with Medication

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

the class MedicationFhirResourceProviderIntegrationTest method shouldUpdateExistingMedicationAsJson.

@Test
public void shouldUpdateExistingMedicationAsJson() throws Exception {
    // Before update
    MockHttpServletResponse response = get("/Medication/" + MEDICATION_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Medication medication = readResponse(response);
    Extension medExtension = medication.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_MEDICINE);
    Extension strengthExtension = medExtension.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_MEDICINE + "#strength");
    assertThat(medication, notNullValue());
    assertThat(medication, validResource());
    assertThat(medication.getIdElement().getIdPart(), equalTo(MEDICATION_UUID));
    assertThat(strengthExtension.getValue().toString(), equalTo("200mg"));
    // Get existing medication with updated medication strength
    String jsonMedication;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_UPDATE_MEDICATION_DOCUMENT)) {
        Objects.requireNonNull(is);
        jsonMedication = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    // Update
    response = put("/Medication/" + MEDICATION_UUID).jsonContent(jsonMedication).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    // read updated record
    medication = readResponse(response);
    medExtension = medication.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_MEDICINE);
    strengthExtension = medExtension.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_MEDICINE + "#strength");
    assertThat(medication, notNullValue());
    assertThat(medication.getIdElement().getIdPart(), equalTo(MEDICATION_UUID));
    assertThat(medication.getStatus(), is(Medication.MedicationStatus.ACTIVE));
    assertThat(strengthExtension.getValue().toString(), equalTo("800mg"));
    assertThat(medication, validResource());
    // Double-check via get
    response = get("/Medication/" + MEDICATION_UUID).accept(FhirMediaTypes.JSON).go();
    Medication updatedMedication = readResponse(response);
    medExtension = updatedMedication.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_MEDICINE);
    strengthExtension = medExtension.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_MEDICINE + "#strength");
    assertThat(updatedMedication, validResource());
    assertThat(updatedMedication, notNullValue());
    assertThat(updatedMedication.getStatus(), is(Medication.MedicationStatus.ACTIVE));
    assertThat(strengthExtension.getValue().toString(), equalTo("800mg"));
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) InputStream(java.io.InputStream) Medication(org.hl7.fhir.r4.model.Medication) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 62 with Medication

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

the class MedicationFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentMedicationAsXML.

@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentMedicationAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Medication/" + MEDICATION_UUID).accept(FhirMediaTypes.XML).go();
    Medication medication = readResponse(response);
    // update the existing record
    medication.setId(WRONG_MEDICATION_UUID);
    // send the update to the server
    response = put("/Medication/" + WRONG_MEDICATION_UUID).xmlContent(toXML(medication)).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) Medication(org.hl7.fhir.r4.model.Medication) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 63 with Medication

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

the class MedicationFhirResourceProviderIntegrationTest method shouldReturnCountForMedicationAsJson.

@Test
public void shouldReturnCountForMedicationAsJson() throws Exception {
    MockHttpServletResponse response = get("/Medication?_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(4)));
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 64 with Medication

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

the class MedicationFhirResourceProviderIntegrationTest method shouldCreateNewMedicationAsJson.

@Test
public void shouldCreateNewMedicationAsJson() throws Exception {
    // read JSON record
    String jsonMedication;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_MEDICATION_DOCUMENT)) {
        Objects.requireNonNull(is);
        jsonMedication = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    // create medication
    MockHttpServletResponse response = post("/Medication").accept(FhirMediaTypes.JSON).jsonContent(jsonMedication).go();
    // verify created correctly
    assertThat(response, isCreated());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Medication medication = readResponse(response);
    assertThat(medication, notNullValue());
    assertThat(medication.getStatus(), is(Medication.MedicationStatus.ACTIVE));
    assertThat(medication.getCode().getCodingFirstRep().getCode(), equalTo(MEDICATION_CODE_UUID));
    // try to get new medication
    response = get(medication.getId()).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    Medication newMedication = readResponse(response);
    assertThat(newMedication.getId(), equalTo(medication.getId()));
    assertThat(newMedication.getStatus(), equalTo(medication.getStatus()));
}
Also used : InputStream(java.io.InputStream) Medication(org.hl7.fhir.r4.model.Medication) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 65 with Medication

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

the class CCDAConverter method processProcedure.

protected void processProcedure(ListResource list, Element procedure, ProcedureType type) throws Exception {
    switch(type) {
        case Procedure:
            cda.checkTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.14");
            break;
        case Observation:
            cda.checkTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.13");
            break;
        case Act:
            cda.checkTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.12");
    }
    checkNoNegationOrNullFlavor(procedure, "Procedure (" + type + ")");
    checkNoSubject(procedure, "Procedure (" + type + ")");
    Procedure p = new Procedure();
    addItemToList(list, p);
    // moodCode is either INT or EVN. INT is not handled yet. INT is deprecated anyway
    if (procedure.getAttribute("moodCode").equals("INT"))
        p.getModifierExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-planned", Factory.newBoolean(true), false));
    // SHALL contain at least one [1..*] id (CONF:7655).
    for (Element e : cda.getChildren(procedure, "id")) p.getIdentifier().add(convert.makeIdentifierFromII(e));
    // SHALL contain exactly one [1..1] code (CONF:7656).
    // This code @code in a procedure activity SHOULD be selected from LOINC or SNOMED CT and MAY be selected from CPT-4, ICD9 Procedures, ICD10 Procedures
    p.setCode(convert.makeCodeableConceptFromCD(cda.getChild(procedure, "code")));
    // SHALL contain exactly one [1..1] statusCode/@code, which SHALL be selected from ValueSet 2.16.840.1.113883.11.20.9.22 ProcedureAct
    // completed | active | aborted | cancelled - not in FHIR
    p.getModifierExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-status", Factory.newCode(cda.getStatus(procedure)), false));
    // SHOULD contain zero or one [0..1] effectiveTime (CONF:7662).
    p.setPerformed(convert.makePeriodFromIVL(cda.getChild(procedure, "effectiveTime")));
    // MAY contain zero or one [0..1] priorityCode/@code, which SHALL be selected from ValueSet 2.16.840.1.113883.1.11.16866 ActPriority DYNAMIC (CONF:7668)
    p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-priority", convert.makeCodeableConceptFromCD(cda.getChild(procedure, "priorityCode")), false));
    // MAY contain zero or one [0..1] methodCode (CONF:7670).
    p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-method", convert.makeCodeableConceptFromCD(cda.getChild(procedure, "methodCode")), false));
    if (type == ProcedureType.Observation) {
    // for Procedure-Observation:
    // 9.	SHALL contain exactly one [1..1] value (CONF:16846).
    // don't know what this is. It's not the actual result of the procedure (that goes in results "This section records ... procedure observations"), and there seems to be no value. The example as <value xsi:type="CD"/> which is not valid
    // so we ignore this for now
    }
    // SHOULD contain zero or more [0..*] targetSiteCode/@code, which SHALL be selected from ValueSet 2.16.840.1.113883.3.88.12.3221.8.9 Body site DYNAMIC (CONF:7683).
    for (Element e : cda.getChildren(procedure, "targetSiteCode")) p.addBodySite(convert.makeCodeableConceptFromCD(e));
    // SHOULD contain zero or more [0..*] performer (CONF:7718) such that it
    for (Element e : cda.getChildren(procedure, "performer")) {
        ProcedurePerformerComponent pp = new ProcedurePerformerComponent();
        p.getPerformer().add(pp);
        pp.setActor(makeReferenceToPractitionerForAssignedEntity(e, p));
    }
    for (Element participant : cda.getChildren(procedure, "participant")) {
        Element participantRole = cda.getlastChild(participant);
        if (type == ProcedureType.Procedure && cda.hasTemplateId(participantRole, "2.16.840.1.113883.10.20.22.4.37")) {
            // MAY contain zero or more [0..*] participant (CONF:7751) such that it  SHALL contain exactly one [1..1] @typeCode="DEV" Device
            // implanted devices
            p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/implanted-devices", Factory.makeReference(processDevice(participantRole, p)), false));
        } else if (cda.hasTemplateId(participantRole, "2.16.840.1.113883.10.20.22.4.32")) {
            // MAY contain zero or more [0..*] participant (CONF:7765) such that it SHALL contain exactly one [1..1] Service Delivery Location (templateId:2.16.840.1.113883.10.20.22.4.32) (CONF:7767)
            p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/location", Factory.makeReference(processSDLocation(participantRole, p)), false));
        }
    }
    for (Element e : cda.getChildren(procedure, "entryRelationship")) {
        Element a = /* act*/
        cda.getlastChild(e);
        if (a.getLocalName().equals("encounter")) {
        // MAY contain zero or more [0..*] entryRelationship (CONF:7768) such that it SHALL contain exactly one encounter which SHALL contain exactly one [1..1] id (CONF:7773).
        // todo - and process as a full encounter while we're at it
        } else if (cda.hasTemplateId(a, "2.16.840.1.113883.10.20.22.4.20")) {
            // MAY contain zero or one [0..1] entryRelationship (CONF:7775) such that it SHALL contain exactly one [1..1] Instructions (templateId:2.16.840.1.113883.10.20.22.4.20) (CONF:7778).
            // had code for type, plus text for instructions
            Extension n = Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-instructions", null, true);
            n.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-instructions-type", convert.makeCodeableConceptFromCD(cda.getChild(a, "code")), false));
            n.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-instructions-text", convert.makeStringFromED(cda.getChild(a, "text")), false));
            p.getExtension().add(n);
        } else if (cda.hasTemplateId(a, "2.16.840.1.113883.10.20.22.4.19")) {
            // MAY contain zero or more [0..*] entryRelationship (CONF:7779) such that it SHALL contain exactly one [1..1] Indication (templateId:2.16.840.1.113883.10.20.22.4.19) (CONF:7781).
            p.addReasonCode(processIndication(a));
        } else if (cda.hasTemplateId(cda.getlastChild(e), "2.16.840.1.113883.10.20.22.4.16")) {
        // MAY contain zero or one [0..1] entryRelationship (CONF:7886) such that it SHALL contain exactly one [1..1] Medication Activity (templateId:2.16.840.1.113883.10.20.22.4.16) (CONF:7888).
        // todo
        }
    }
}
Also used : Element(org.w3c.dom.Element) ProcedurePerformerComponent(org.hl7.fhir.dstu3.model.Procedure.ProcedurePerformerComponent)

Aggregations

Test (org.junit.Test)112 Medication (org.hl7.fhir.r4.model.Medication)62 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)43 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)34 Medication (org.hl7.fhir.dstu3.model.Medication)33 BaseFhirIntegrationTest (org.openmrs.module.fhir2.BaseFhirIntegrationTest)30 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)24 TokenParam (ca.uhn.fhir.rest.param.TokenParam)24 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)20 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)20 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)19 MedicationRequest (org.hl7.fhir.r4.model.MedicationRequest)18 InputStream (java.io.InputStream)17 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)16 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)14 Coding (org.hl7.fhir.r4.model.Coding)14 Date (java.util.Date)13 ArrayList (java.util.ArrayList)12 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)12 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)11