Search in sources :

Example 66 with Medication

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

the class ArgonautConverter method processMedicationsSection.

private void processMedicationsSection(CDAUtilities cda, Convert convert, Element section, Context context) throws Exception {
    scanSection("Medications", section);
    ListResource list = new ListResource();
    list.setId(context.getBaseId() + "-list-medications");
    list.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/list-daf-dafmedicationlist");
    list.setSubject(context.getSubjectRef());
    list.setCode(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(section, "code")), null));
    list.setTitle(cda.getChild(section, "title").getTextContent());
    list.setStatus(ListStatus.CURRENT);
    list.setMode(ListMode.SNAPSHOT);
    list.setDateElement(context.getNow());
    list.setSource(context.getAuthorRef());
    buildNarrative(list, cda.getChild(section, "text"));
    int i = 0;
    for (Element c : cda.getChildren(section, "entry")) {
        // allergy problem act
        Element sa = cda.getChild(c, "substanceAdministration");
        MedicationStatement ms = new MedicationStatement();
        ms.setId(context.getBaseId() + "-medication-" + i);
        ms.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/medicationstatement-daf-dafmedicationstatement");
        i++;
        ms.setSubject(context.getSubjectRef());
        boolean found = false;
        for (Element e : cda.getChildren(sa, "id")) {
            Identifier id = convert.makeIdentifierFromII(e);
            ms.getIdentifier().add(id);
        }
        if (!found) {
            ms.setStatus(MedicationStatementStatus.COMPLETED);
            list.addEntry().setItem(new Reference().setReference("MedicationStatement/" + ms.getId()));
            // allergy observation
            Element mm = cda.getChild(cda.getChild(cda.getChild(sa, "consumable"), "manufacturedProduct"), "manufacturedMaterial");
            ms.setMedication(new Reference().setReference("#med"));
            Medication med = new Medication();
            med.setId("med");
            med.setCode(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(mm, "code")), null));
            ms.getContained().add(med);
            Dosage dosage = ms.addDosage();
            // allergy observation
            Element qty = cda.getChild(sa, "doseQuantity");
            try {
                if (cda.getChild(qty, "low") != null) {
                    // todo: this is not correct?
                    dosage.getExtension().add(new Extension().setUrl("http://healthintersections.com.au/fhir/extensions/medication-statement-range").setValue(convert.makeRangeFromIVLPQ(qty)));
                } else {
                    dosage.setDose(convert.makeQuantityFromPQ(qty));
                }
            } catch (Exception e) {
                System.out.println("  invalid dose quantity '" + qty.getAttribute("value") + " " + qty.getAttribute("unit") + "' (" + e.getClass().getName() + ") in " + context.getBaseId());
            }
            dosage.setRoute(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(sa, "routeCode")), null));
            Type t = convert.makeSomethingFromGTS(cda.getChildren(sa, "effectiveTime"));
            if (t instanceof Timing) {
                dosage.setTiming((Timing) t);
                if (dosage.getTiming().hasRepeat() && dosage.getTiming().getRepeat().hasBounds())
                    ms.setEffective(dosage.getTiming().getRepeat().getBounds());
            } else if (t instanceof Period)
                ms.setEffective(t);
            else
                throw new Exception("Undecided how to handle " + t.getClass().getName());
            for (Element e : cda.getChildren(sa, "author")) {
                if (ms.hasInformationSource())
                    throw new Error("additional author discovered");
                Practitioner p = processPerformer(cda, convert, context, e, "assignedAuthor", "assignedPerson");
                Reference ref = new Reference().setReference("Practitioner/" + p.getId()).setDisplay(p.getUserString("display"));
                ms.setInformationSource(ref);
                ms.setDateAssertedElement(convert.makeDateTimeFromTS(cda.getChild(e, "time")));
            }
            saveResource(ms);
        }
    }
    saveResource(list);
}
Also used : Element(org.w3c.dom.Element) IOException(java.io.IOException) NodeType(org.hl7.fhir.utilities.xhtml.NodeType) ObservationRelationshipType(org.hl7.fhir.dstu3.model.Observation.ObservationRelationshipType)

Example 67 with Medication

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

the class RdfParser method composeMedicationMedicationProductBatchComponent.

protected void composeMedicationMedicationProductBatchComponent(Complex parent, String parentType, String name, Medication.MedicationProductBatchComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "batch", name, element, index);
    if (element.hasLotNumberElement())
        composeString(t, "Medication", "lotNumber", element.getLotNumberElement(), -1);
    if (element.hasExpirationDateElement())
        composeDateTime(t, "Medication", "expirationDate", element.getExpirationDateElement(), -1);
}
Also used : Complex(org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)

Example 68 with Medication

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

the class RdfParser method composeMedicationDispense.

protected void composeMedicationDispense(Complex parent, String parentType, String name, MedicationDispense element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeDomainResource(t, "MedicationDispense", name, element, index);
    if (element.hasIdentifier())
        composeIdentifier(t, "MedicationDispense", "identifier", element.getIdentifier(), -1);
    if (element.hasStatusElement())
        composeEnum(t, "MedicationDispense", "status", element.getStatusElement(), -1);
    if (element.hasMedication())
        composeType(t, "MedicationDispense", "medication", element.getMedication(), -1);
    if (element.hasPatient())
        composeReference(t, "MedicationDispense", "patient", element.getPatient(), -1);
    if (element.hasDispenser())
        composeReference(t, "MedicationDispense", "dispenser", element.getDispenser(), -1);
    for (int i = 0; i < element.getAuthorizingPrescription().size(); i++) composeReference(t, "MedicationDispense", "authorizingPrescription", element.getAuthorizingPrescription().get(i), i);
    if (element.hasType())
        composeCodeableConcept(t, "MedicationDispense", "type", element.getType(), -1);
    if (element.hasQuantity())
        composeQuantity(t, "MedicationDispense", "quantity", element.getQuantity(), -1);
    if (element.hasDaysSupply())
        composeQuantity(t, "MedicationDispense", "daysSupply", element.getDaysSupply(), -1);
    if (element.hasWhenPreparedElement())
        composeDateTime(t, "MedicationDispense", "whenPrepared", element.getWhenPreparedElement(), -1);
    if (element.hasWhenHandedOverElement())
        composeDateTime(t, "MedicationDispense", "whenHandedOver", element.getWhenHandedOverElement(), -1);
    if (element.hasDestination())
        composeReference(t, "MedicationDispense", "destination", element.getDestination(), -1);
    for (int i = 0; i < element.getReceiver().size(); i++) composeReference(t, "MedicationDispense", "receiver", element.getReceiver().get(i), i);
    for (int i = 0; i < element.getNote().size(); i++) composeAnnotation(t, "MedicationDispense", "note", element.getNote().get(i), i);
    for (int i = 0; i < element.getDosageInstruction().size(); i++) composeMedicationDispenseMedicationDispenseDosageInstructionComponent(t, "MedicationDispense", "dosageInstruction", element.getDosageInstruction().get(i), i);
    if (element.hasSubstitution())
        composeMedicationDispenseMedicationDispenseSubstitutionComponent(t, "MedicationDispense", "substitution", element.getSubstitution(), -1);
}
Also used : Complex(org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)

Example 69 with Medication

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

the class RdfParser method composeMedicationRequest.

protected void composeMedicationRequest(Complex parent, String parentType, String name, MedicationRequest element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeDomainResource(t, "MedicationRequest", name, element, index);
    for (int i = 0; i < element.getIdentifier().size(); i++) composeIdentifier(t, "MedicationRequest", "identifier", element.getIdentifier().get(i), i);
    for (int i = 0; i < element.getDefinition().size(); i++) composeReference(t, "MedicationRequest", "definition", element.getDefinition().get(i), i);
    for (int i = 0; i < element.getBasedOn().size(); i++) composeReference(t, "MedicationRequest", "basedOn", element.getBasedOn().get(i), i);
    if (element.hasGroupIdentifier())
        composeIdentifier(t, "MedicationRequest", "groupIdentifier", element.getGroupIdentifier(), -1);
    if (element.hasStatusElement())
        composeEnum(t, "MedicationRequest", "status", element.getStatusElement(), -1);
    if (element.hasIntentElement())
        composeEnum(t, "MedicationRequest", "intent", element.getIntentElement(), -1);
    if (element.hasCategory())
        composeCodeableConcept(t, "MedicationRequest", "category", element.getCategory(), -1);
    if (element.hasPriorityElement())
        composeEnum(t, "MedicationRequest", "priority", element.getPriorityElement(), -1);
    if (element.hasMedication())
        composeType(t, "MedicationRequest", "medication", element.getMedication(), -1);
    if (element.hasSubject())
        composeReference(t, "MedicationRequest", "subject", element.getSubject(), -1);
    if (element.hasContext())
        composeReference(t, "MedicationRequest", "context", element.getContext(), -1);
    for (int i = 0; i < element.getSupportingInformation().size(); i++) composeReference(t, "MedicationRequest", "supportingInformation", element.getSupportingInformation().get(i), i);
    if (element.hasAuthoredOnElement())
        composeDateTime(t, "MedicationRequest", "authoredOn", element.getAuthoredOnElement(), -1);
    if (element.hasRequester())
        composeMedicationRequestMedicationRequestRequesterComponent(t, "MedicationRequest", "requester", element.getRequester(), -1);
    if (element.hasRecorder())
        composeReference(t, "MedicationRequest", "recorder", element.getRecorder(), -1);
    for (int i = 0; i < element.getReasonCode().size(); i++) composeCodeableConcept(t, "MedicationRequest", "reasonCode", element.getReasonCode().get(i), i);
    for (int i = 0; i < element.getReasonReference().size(); i++) composeReference(t, "MedicationRequest", "reasonReference", element.getReasonReference().get(i), i);
    for (int i = 0; i < element.getNote().size(); i++) composeAnnotation(t, "MedicationRequest", "note", element.getNote().get(i), i);
    for (int i = 0; i < element.getDosageInstruction().size(); i++) composeDosage(t, "MedicationRequest", "dosageInstruction", element.getDosageInstruction().get(i), i);
    if (element.hasDispenseRequest())
        composeMedicationRequestMedicationRequestDispenseRequestComponent(t, "MedicationRequest", "dispenseRequest", element.getDispenseRequest(), -1);
    if (element.hasSubstitution())
        composeMedicationRequestMedicationRequestSubstitutionComponent(t, "MedicationRequest", "substitution", element.getSubstitution(), -1);
    if (element.hasPriorPrescription())
        composeReference(t, "MedicationRequest", "priorPrescription", element.getPriorPrescription(), -1);
    for (int i = 0; i < element.getDetectedIssue().size(); i++) composeReference(t, "MedicationRequest", "detectedIssue", element.getDetectedIssue().get(i), i);
    for (int i = 0; i < element.getEventHistory().size(); i++) composeReference(t, "MedicationRequest", "eventHistory", element.getEventHistory().get(i), i);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Example 70 with Medication

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

the class RdfParser method composeMedicationDispense.

protected void composeMedicationDispense(Complex parent, String parentType, String name, MedicationDispense element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeDomainResource(t, "MedicationDispense", name, element, index);
    for (int i = 0; i < element.getIdentifier().size(); i++) composeIdentifier(t, "MedicationDispense", "identifier", element.getIdentifier().get(i), i);
    for (int i = 0; i < element.getPartOf().size(); i++) composeReference(t, "MedicationDispense", "partOf", element.getPartOf().get(i), i);
    if (element.hasStatusElement())
        composeEnum(t, "MedicationDispense", "status", element.getStatusElement(), -1);
    if (element.hasCategory())
        composeCodeableConcept(t, "MedicationDispense", "category", element.getCategory(), -1);
    if (element.hasMedication())
        composeType(t, "MedicationDispense", "medication", element.getMedication(), -1);
    if (element.hasSubject())
        composeReference(t, "MedicationDispense", "subject", element.getSubject(), -1);
    if (element.hasContext())
        composeReference(t, "MedicationDispense", "context", element.getContext(), -1);
    for (int i = 0; i < element.getSupportingInformation().size(); i++) composeReference(t, "MedicationDispense", "supportingInformation", element.getSupportingInformation().get(i), i);
    for (int i = 0; i < element.getPerformer().size(); i++) composeMedicationDispenseMedicationDispensePerformerComponent(t, "MedicationDispense", "performer", element.getPerformer().get(i), i);
    for (int i = 0; i < element.getAuthorizingPrescription().size(); i++) composeReference(t, "MedicationDispense", "authorizingPrescription", element.getAuthorizingPrescription().get(i), i);
    if (element.hasType())
        composeCodeableConcept(t, "MedicationDispense", "type", element.getType(), -1);
    if (element.hasQuantity())
        composeQuantity(t, "MedicationDispense", "quantity", element.getQuantity(), -1);
    if (element.hasDaysSupply())
        composeQuantity(t, "MedicationDispense", "daysSupply", element.getDaysSupply(), -1);
    if (element.hasWhenPreparedElement())
        composeDateTime(t, "MedicationDispense", "whenPrepared", element.getWhenPreparedElement(), -1);
    if (element.hasWhenHandedOverElement())
        composeDateTime(t, "MedicationDispense", "whenHandedOver", element.getWhenHandedOverElement(), -1);
    if (element.hasDestination())
        composeReference(t, "MedicationDispense", "destination", element.getDestination(), -1);
    for (int i = 0; i < element.getReceiver().size(); i++) composeReference(t, "MedicationDispense", "receiver", element.getReceiver().get(i), i);
    for (int i = 0; i < element.getNote().size(); i++) composeAnnotation(t, "MedicationDispense", "note", element.getNote().get(i), i);
    for (int i = 0; i < element.getDosageInstruction().size(); i++) composeDosage(t, "MedicationDispense", "dosageInstruction", element.getDosageInstruction().get(i), i);
    if (element.hasSubstitution())
        composeMedicationDispenseMedicationDispenseSubstitutionComponent(t, "MedicationDispense", "substitution", element.getSubstitution(), -1);
    for (int i = 0; i < element.getDetectedIssue().size(); i++) composeReference(t, "MedicationDispense", "detectedIssue", element.getDetectedIssue().get(i), i);
    if (element.hasNotDoneElement())
        composeBoolean(t, "MedicationDispense", "notDone", element.getNotDoneElement(), -1);
    if (element.hasNotDoneReason())
        composeType(t, "MedicationDispense", "notDoneReason", element.getNotDoneReason(), -1);
    for (int i = 0; i < element.getEventHistory().size(); i++) composeReference(t, "MedicationDispense", "eventHistory", element.getEventHistory().get(i), i);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

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