Search in sources :

Example 1 with Dosage

use of org.hl7.fhir.r4b.model.Dosage in project cqf-ruler by DBCG.

the class ActivityDefinitionApplyProvider method resolveServiceRequest.

private ServiceRequest resolveServiceRequest(ActivityDefinition activityDefinition, String patientId, String practitionerId, String organizationId) throws ActivityDefinitionApplyException {
    // status, intent, code, and subject are required
    ServiceRequest serviceRequest = new ServiceRequest();
    serviceRequest.setStatus(ServiceRequest.ServiceRequestStatus.DRAFT);
    serviceRequest.setIntent(ServiceRequest.ServiceRequestIntent.PROPOSAL);
    String patientReferenceString = patientId;
    URI patientIdAsUri = URI.create(patientReferenceString);
    if (!patientIdAsUri.isAbsolute() && patientIdAsUri.getFragment() == null && !patientReferenceString.startsWith("Patient/")) {
        patientReferenceString = "Patient/" + patientId;
    }
    serviceRequest.setSubject(new Reference(patientReferenceString));
    if (practitionerId != null) {
        serviceRequest.setRequester(new Reference(practitionerId));
    } else if (organizationId != null) {
        serviceRequest.setRequester(new Reference(organizationId));
    }
    if (activityDefinition.hasExtension()) {
        serviceRequest.setExtension(activityDefinition.getExtension());
    }
    if (activityDefinition.hasCode()) {
        serviceRequest.setCode(activityDefinition.getCode());
    } else // code can be set as a dynamicValue
    if (!activityDefinition.hasCode() && !activityDefinition.hasDynamicValue()) {
        throw new ActivityDefinitionApplyException("Missing required code property");
    }
    if (activityDefinition.hasBodySite()) {
        serviceRequest.setBodySite(activityDefinition.getBodySite());
    }
    if (activityDefinition.hasProduct()) {
        throw new ActivityDefinitionApplyException("Product does not map to " + activityDefinition.getKind());
    }
    if (activityDefinition.hasDosage()) {
        throw new ActivityDefinitionApplyException("Dosage does not map to " + activityDefinition.getKind());
    }
    return serviceRequest;
}
Also used : Reference(org.hl7.fhir.r4.model.Reference) URI(java.net.URI) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest)

Example 2 with Dosage

use of org.hl7.fhir.r4b.model.Dosage in project openmrs-module-fhir2 by openmrs.

the class DosageTranslatorImplTest method toFhirResource_shouldTranslateDrugOrderRouteToRoute.

@Test
public void toFhirResource_shouldTranslateDrugOrderRouteToRoute() {
    drugOrder.setAsNeeded(true);
    Dosage result = dosageTranslator.toFhirResource(drugOrder);
    assertThat(result, notNullValue());
    assertThat(result.getAsNeededBooleanType().booleanValue(), is(true));
}
Also used : Dosage(org.hl7.fhir.r4.model.Dosage) Test(org.junit.Test)

Example 3 with Dosage

use of org.hl7.fhir.r4b.model.Dosage in project openmrs-module-fhir2 by openmrs.

the class DosageTranslatorImplTest method toFhirResource_shouldTranslateDrugOrderAsNeededToAsNeeded.

@Test
public void toFhirResource_shouldTranslateDrugOrderAsNeededToAsNeeded() {
    Concept concept = new Concept();
    concept.setUuid(CONCEPT_UUID);
    concept.setConceptId(1000);
    CodeableConcept codeableConcept = new CodeableConcept();
    codeableConcept.addCoding(new Coding().setCode(concept.getConceptId().toString()));
    drugOrder.setRoute(concept);
    when(conceptTranslator.toFhirResource(concept)).thenReturn(codeableConcept);
    Dosage result = dosageTranslator.toFhirResource(drugOrder);
    assertThat(result, notNullValue());
    assertThat(result.getRoute(), equalTo(codeableConcept));
    assertThat(result.getRoute().getCodingFirstRep().getCode(), equalTo("1000"));
}
Also used : CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Concept(org.openmrs.Concept) Coding(org.hl7.fhir.r4.model.Coding) Dosage(org.hl7.fhir.r4.model.Dosage) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 4 with Dosage

use of org.hl7.fhir.r4b.model.Dosage in project openmrs-module-fhir2 by openmrs.

the class DosageTranslatorImplTest method toFhirResource_shouldTranslateDosingInstructionToDosageText.

@Test
public void toFhirResource_shouldTranslateDosingInstructionToDosageText() {
    drugOrder.setDosingInstructions(DOSING_INSTRUCTION);
    Dosage result = dosageTranslator.toFhirResource(drugOrder);
    assertThat(result, notNullValue());
    assertThat(result.getText(), equalTo(DOSING_INSTRUCTION));
}
Also used : Dosage(org.hl7.fhir.r4.model.Dosage) Test(org.junit.Test)

Example 5 with Dosage

use of org.hl7.fhir.r4b.model.Dosage 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)

Aggregations

Dosage (org.hl7.fhir.r4.model.Dosage)8 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)8 Date (java.util.Date)6 ArrayList (java.util.ArrayList)5 Reference (org.hl7.fhir.dstu3.model.Reference)5 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)5 Test (org.junit.Test)5 JsonElement (com.google.gson.JsonElement)4 JsonObject (com.google.gson.JsonObject)4 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)4 Dosage (org.hl7.fhir.dstu3.model.Dosage)4 Coding (org.hl7.fhir.r4.model.Coding)4 Quantity (org.hl7.fhir.r4.model.Quantity)4 NotImplementedException (org.apache.commons.lang3.NotImplementedException)3 Coding (org.hl7.fhir.dstu3.model.Coding)3 Quantity (org.hl7.fhir.dstu3.model.Quantity)3 Timing (org.hl7.fhir.dstu3.model.Timing)3 BooleanType (org.hl7.fhir.r4.model.BooleanType)3 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)3 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)3