Search in sources :

Example 41 with Timing

use of org.hl7.fhir.r4b.model.Timing in project eCRNow by drajer-health.

the class PlanDefinitionProcessor method processTriggerDefinitions.

private void processTriggerDefinitions(List<TriggerDefinition> tdlist, AbstractAction act) {
    if (tdlist != null && !tdlist.isEmpty()) {
        for (TriggerDefinition triggerDefinition : tdlist) {
            if (triggerDefinition.getType() != TriggerType.NAMEDEVENT && triggerDefinition.getType() != TriggerType.PERIODIC && triggerDefinition.hasData()) {
                logger.info(" Identified Data Trigger for Act {}", act.getActionId());
                List<DataRequirement> dr = triggerDefinition.getData();
                for (DataRequirement d : dr) {
                    // Create ActionData object
                    ActionData ad = new ActionData();
                    ad.setTriggerType(triggerDefinition.getType());
                    ad.setFhirDataType(FHIRAllTypes.valueOf(d.getType().toUpperCase()));
                    if (d.hasProfile())
                        ad.setProfiles(d.getProfile());
                    if (d.hasCodeFilter()) {
                        DataRequirementCodeFilterComponent cf = d.getCodeFilterFirstRep();
                        if (cf.hasPath()) {
                            ad.setPath(d.getType() + "." + cf.getPath());
                            logger.info(" Evaluation Path = {}", ad.getPath());
                        }
                        if (cf.hasValueSet())
                            ad.setValueSet(cf.getValueSetElement());
                    }
                    act.addActionData(ad);
                }
            } else if (triggerDefinition.getType() == TriggerType.PERIODIC) {
                if (triggerDefinition.hasTimingTiming()) {
                    Timing t = triggerDefinition.getTimingTiming();
                    if (t.hasRepeat()) {
                        TimingSchedule ts = getTimingSchedule(t, triggerDefinition.getType());
                        if (ts != null) {
                            act.addTimingData(ts);
                        }
                    }
                } else {
                // Not handling the others for eCR
                }
            } else {
            // Ignore other types for eCR
            }
        }
    }
}
Also used : TriggerDefinition(org.hl7.fhir.r4.model.TriggerDefinition) DataRequirement(org.hl7.fhir.r4.model.DataRequirement) ActionData(com.drajer.eca.model.ActionData) Timing(org.hl7.fhir.r4.model.Timing) DataRequirementCodeFilterComponent(org.hl7.fhir.r4.model.DataRequirement.DataRequirementCodeFilterComponent) TimingSchedule(com.drajer.eca.model.TimingSchedule)

Example 42 with Timing

use of org.hl7.fhir.r4b.model.Timing in project bunsen by cerner.

the class TestData method newMedicationRequest.

/**
 * Returns a new MedicationRequest for testing.
 *
 * @return a FHIR MedicationRequest for testing.
 */
public static MedicationRequest newMedicationRequest() {
    MedicationRequest medicationRequest = new MedicationRequest();
    medicationRequest.setId("test-medication-request");
    CodeableConcept itemCodeableConcept = new CodeableConcept();
    itemCodeableConcept.addCoding().setSystem("http://www.nlm.nih.gov/research/umls/rxnorm").setCode("103109").setDisplay("Vitamin E 3 MG Oral Tablet [Ephynal]").setUserSelected(true);
    medicationRequest.setMedication(itemCodeableConcept);
    medicationRequest.setSubject(new Reference("Patient/12345").setDisplay("Here is a display for you."));
    medicationRequest.setDosageInstruction(ImmutableList.of(new Dosage().setTiming(new Timing().setRepeat(new TimingRepeatComponent().setCount(10)))));
    medicationRequest.setSubstitution(new MedicationRequestSubstitutionComponent().setAllowed(true));
    return medicationRequest;
}
Also used : MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) MedicationRequestSubstitutionComponent(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestSubstitutionComponent) Reference(org.hl7.fhir.dstu3.model.Reference) TimingRepeatComponent(org.hl7.fhir.dstu3.model.Timing.TimingRepeatComponent) Timing(org.hl7.fhir.dstu3.model.Timing) Dosage(org.hl7.fhir.dstu3.model.Dosage) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 43 with Timing

use of org.hl7.fhir.r4b.model.Timing in project synthea by synthetichealth.

the class FhirR4 method medicationRequest.

/**
 * Map the given Medication to a FHIR MedicationRequest resource, and add it to the given Bundle.
 *
 * @param person         The person being prescribed medication
 * @param personEntry    The Entry for the Person
 * @param bundle         Bundle to add the Medication to
 * @param encounterEntry Current Encounter entry
 * @param medication     The Medication
 * @return The added Entry
 */
private static BundleEntryComponent medicationRequest(Person person, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Medication medication) {
    MedicationRequest medicationResource = new MedicationRequest();
    if (USE_US_CORE_IG) {
        Meta meta = new Meta();
        meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-medicationrequest");
        medicationResource.setMeta(meta);
    } else if (USE_SHR_EXTENSIONS) {
        medicationResource.addExtension().setUrl(SHR_EXT + "shr-base-ActionCode-extension").setValue(PRESCRIPTION_OF_DRUG_CC);
        medicationResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-medication-MedicationRequested"));
        Extension requestedContext = new Extension();
        requestedContext.setUrl(SHR_EXT + "shr-action-RequestedContext-extension");
        requestedContext.addExtension(SHR_EXT + "shr-action-Status-extension", new CodeType("completed"));
        requestedContext.addExtension(SHR_EXT + "shr-action-RequestIntent-extension", new CodeType("original-order"));
        medicationResource.addExtension(requestedContext);
    }
    medicationResource.setSubject(new Reference(personEntry.getFullUrl()));
    medicationResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
    Code code = medication.codes.get(0);
    String system = code.system.equals("SNOMED-CT") ? SNOMED_URI : RXNORM_URI;
    medicationResource.setMedication(mapCodeToCodeableConcept(code, system));
    if (USE_US_CORE_IG && medication.administration) {
        // Occasionally, rather than use medication codes, we want to use a Medication
        // Resource. We only want to do this when we use US Core, to make sure we
        // sometimes produce a resource for the us-core-medication profile, and the
        // 'administration' flag is an arbitrary way to decide without flipping a coin.
        org.hl7.fhir.r4.model.Medication drugResource = new org.hl7.fhir.r4.model.Medication();
        Meta meta = new Meta();
        meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-medication");
        drugResource.setMeta(meta);
        drugResource.setCode(mapCodeToCodeableConcept(code, system));
        drugResource.setStatus(MedicationStatus.ACTIVE);
        BundleEntryComponent drugEntry = newEntry(person, bundle, drugResource);
        medicationResource.setMedication(new Reference(drugEntry.getFullUrl()));
    }
    medicationResource.setAuthoredOn(new Date(medication.start));
    medicationResource.setIntent(MedicationRequestIntent.ORDER);
    org.hl7.fhir.r4.model.Encounter encounter = (org.hl7.fhir.r4.model.Encounter) encounterEntry.getResource();
    medicationResource.setRequester(encounter.getParticipantFirstRep().getIndividual());
    if (medication.stop != 0L) {
        medicationResource.setStatus(MedicationRequestStatus.STOPPED);
    } else {
        medicationResource.setStatus(MedicationRequestStatus.ACTIVE);
    }
    if (!medication.reasons.isEmpty()) {
        // Only one element in list
        Code reason = medication.reasons.get(0);
        for (BundleEntryComponent entry : bundle.getEntry()) {
            if (entry.getResource().fhirType().equals("Condition")) {
                Condition condition = (Condition) entry.getResource();
                // Only one element in list
                Coding coding = condition.getCode().getCoding().get(0);
                if (reason.code.equals(coding.getCode())) {
                    medicationResource.addReasonReference().setReference(entry.getFullUrl());
                }
            }
        }
    }
    if (medication.prescriptionDetails != null) {
        JsonObject rxInfo = medication.prescriptionDetails;
        Dosage dosage = new Dosage();
        dosage.setSequence(1);
        // as_needed is true if present
        dosage.setAsNeeded(new BooleanType(rxInfo.has("as_needed")));
        if (rxInfo.has("as_needed")) {
            dosage.setText("Take as needed.");
        }
        // as_needed is false
        if ((rxInfo.has("dosage")) && (!rxInfo.has("as_needed"))) {
            Timing timing = new Timing();
            TimingRepeatComponent timingRepeatComponent = new TimingRepeatComponent();
            timingRepeatComponent.setFrequency(rxInfo.get("dosage").getAsJsonObject().get("frequency").getAsInt());
            timingRepeatComponent.setPeriod(rxInfo.get("dosage").getAsJsonObject().get("period").getAsDouble());
            timingRepeatComponent.setPeriodUnit(convertUcumCode(rxInfo.get("dosage").getAsJsonObject().get("unit").getAsString()));
            timing.setRepeat(timingRepeatComponent);
            dosage.setTiming(timing);
            Quantity dose = new SimpleQuantity().setValue(rxInfo.get("dosage").getAsJsonObject().get("amount").getAsDouble());
            DosageDoseAndRateComponent dosageDetails = new DosageDoseAndRateComponent();
            dosageDetails.setType(new CodeableConcept().addCoding(new Coding().setCode(DoseRateType.ORDERED.toCode()).setSystem(DoseRateType.ORDERED.getSystem()).setDisplay(DoseRateType.ORDERED.getDisplay())));
            dosageDetails.setDose(dose);
            List<DosageDoseAndRateComponent> details = new ArrayList<DosageDoseAndRateComponent>();
            details.add(dosageDetails);
            dosage.setDoseAndRate(details);
            if (rxInfo.has("instructions")) {
                String text = "";
                for (JsonElement instructionElement : rxInfo.get("instructions").getAsJsonArray()) {
                    JsonObject instruction = instructionElement.getAsJsonObject();
                    Code instructionCode = new Code(SNOMED_URI, instruction.get("code").getAsString(), instruction.get("display").getAsString());
                    text += instructionCode.display + "\n";
                    dosage.addAdditionalInstruction(mapCodeToCodeableConcept(instructionCode, SNOMED_URI));
                }
                dosage.setText(text);
            }
        }
        List<Dosage> dosageInstruction = new ArrayList<Dosage>();
        dosageInstruction.add(dosage);
        medicationResource.setDosageInstruction(dosageInstruction);
    }
    BundleEntryComponent medicationEntry = newEntry(person, bundle, medicationResource);
    // create new claim for medication
    medicationClaim(person, personEntry, bundle, encounterEntry, medication.claim, medicationEntry);
    // Create new administration for medication, if needed
    if (medication.administration) {
        medicationAdministration(person, personEntry, bundle, encounterEntry, medication, medicationResource);
    }
    return medicationEntry;
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) DosageDoseAndRateComponent(org.hl7.fhir.r4.model.Dosage.DosageDoseAndRateComponent) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Dosage(org.hl7.fhir.r4.model.Dosage) Coding(org.hl7.fhir.r4.model.Coding) Medication(org.mitre.synthea.world.concepts.HealthRecord.Medication) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) TimingRepeatComponent(org.hl7.fhir.r4.model.Timing.TimingRepeatComponent) Condition(org.hl7.fhir.r4.model.Condition) MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) BooleanType(org.hl7.fhir.r4.model.BooleanType) SimpleQuantity(org.hl7.fhir.r4.model.SimpleQuantity) SimpleQuantity(org.hl7.fhir.r4.model.SimpleQuantity) Quantity(org.hl7.fhir.r4.model.Quantity) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Extension(org.hl7.fhir.r4.model.Extension) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) JsonElement(com.google.gson.JsonElement) CodeType(org.hl7.fhir.r4.model.CodeType) Timing(org.hl7.fhir.r4.model.Timing) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 44 with Timing

use of org.hl7.fhir.r4b.model.Timing in project synthea by synthetichealth.

the class FhirStu3 method medication.

/**
 * Map the given Medication to a FHIR MedicationRequest resource, and add it to the given Bundle.
 *
 * @param rand Source of randomness to use when generating ids etc
 * @param personEntry The Entry for the Person
 * @param bundle Bundle to add the Medication to
 * @param encounterEntry Current Encounter entry
 * @param medication The Medication
 * @return The added Entry
 */
private static BundleEntryComponent medication(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Medication medication) {
    MedicationRequest medicationResource = new MedicationRequest();
    medicationResource.setSubject(new Reference(personEntry.getFullUrl()));
    medicationResource.setContext(new Reference(encounterEntry.getFullUrl()));
    Code code = medication.codes.get(0);
    String system = code.system.equals("SNOMED-CT") ? SNOMED_URI : RXNORM_URI;
    medicationResource.setMedication(mapCodeToCodeableConcept(code, system));
    medicationResource.setAuthoredOn(new Date(medication.start));
    medicationResource.setIntent(MedicationRequestIntent.ORDER);
    org.hl7.fhir.dstu3.model.Encounter encounter = (org.hl7.fhir.dstu3.model.Encounter) encounterEntry.getResource();
    MedicationRequestRequesterComponent requester = new MedicationRequestRequesterComponent();
    requester.setAgent(encounter.getParticipantFirstRep().getIndividual());
    requester.setOnBehalfOf(encounter.getServiceProvider());
    medicationResource.setRequester(requester);
    if (medication.stop != 0L) {
        medicationResource.setStatus(MedicationRequestStatus.STOPPED);
    } else {
        medicationResource.setStatus(MedicationRequestStatus.ACTIVE);
    }
    if (!medication.reasons.isEmpty()) {
        // Only one element in list
        Code reason = medication.reasons.get(0);
        for (BundleEntryComponent entry : bundle.getEntry()) {
            if (entry.getResource().fhirType().equals("Condition")) {
                Condition condition = (Condition) entry.getResource();
                // Only one element in list
                Coding coding = condition.getCode().getCoding().get(0);
                if (reason.code.equals(coding.getCode())) {
                    medicationResource.addReasonReference().setReference(entry.getFullUrl());
                }
            }
        }
    }
    if (medication.prescriptionDetails != null) {
        JsonObject rxInfo = medication.prescriptionDetails;
        Dosage dosage = new Dosage();
        dosage.setSequence(1);
        // as_needed is true if present
        dosage.setAsNeeded(new BooleanType(rxInfo.has("as_needed")));
        // as_needed is true if present
        if ((rxInfo.has("dosage")) && (!rxInfo.has("as_needed"))) {
            Timing timing = new Timing();
            TimingRepeatComponent timingRepeatComponent = new TimingRepeatComponent();
            timingRepeatComponent.setFrequency(rxInfo.get("dosage").getAsJsonObject().get("frequency").getAsInt());
            timingRepeatComponent.setPeriod(rxInfo.get("dosage").getAsJsonObject().get("period").getAsDouble());
            timingRepeatComponent.setPeriodUnit(convertUcumCode(rxInfo.get("dosage").getAsJsonObject().get("unit").getAsString()));
            timing.setRepeat(timingRepeatComponent);
            dosage.setTiming(timing);
            Quantity dose = new SimpleQuantity().setValue(rxInfo.get("dosage").getAsJsonObject().get("amount").getAsDouble());
            dosage.setDose(dose);
            if (rxInfo.has("instructions")) {
                for (JsonElement instructionElement : rxInfo.get("instructions").getAsJsonArray()) {
                    JsonObject instruction = instructionElement.getAsJsonObject();
                    Code instructionCode = new Code(SNOMED_URI, instruction.get("code").getAsString(), instruction.get("display").getAsString());
                    dosage.addAdditionalInstruction(mapCodeToCodeableConcept(instructionCode, SNOMED_URI));
                }
            }
        }
        List<Dosage> dosageInstruction = new ArrayList<Dosage>();
        dosageInstruction.add(dosage);
        medicationResource.setDosageInstruction(dosageInstruction);
    }
    if (USE_SHR_EXTENSIONS) {
        medicationResource.addExtension().setUrl(SHR_EXT + "shr-base-ActionCode-extension").setValue(PRESCRIPTION_OF_DRUG_CC);
        medicationResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-medication-MedicationRequested"));
        // required fields for this profile are status, action-RequestedContext-extension,
        // medication[x]subject, authoredOn, requester
        Extension requestedContext = new Extension();
        requestedContext.setUrl(SHR_EXT + "shr-action-RequestedContext-extension");
        requestedContext.addExtension(SHR_EXT + "shr-action-Status-extension", new CodeType("completed"));
        requestedContext.addExtension(SHR_EXT + "shr-action-RequestIntent-extension", new CodeType("original-order"));
        medicationResource.addExtension(requestedContext);
    }
    BundleEntryComponent medicationEntry = newEntry(rand, bundle, medicationResource);
    // create new claim for medication
    medicationClaim(rand, personEntry, bundle, encounterEntry, medication.claim, medicationEntry);
    // Create new administration for medication, if needed
    if (medication.administration) {
        medicationAdministration(rand, personEntry, bundle, encounterEntry, medication, medicationResource);
    }
    return medicationEntry;
}
Also used : Meta(org.hl7.fhir.dstu3.model.Meta) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Dosage(org.hl7.fhir.dstu3.model.Dosage) Coding(org.hl7.fhir.dstu3.model.Coding) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) TimingRepeatComponent(org.hl7.fhir.dstu3.model.Timing.TimingRepeatComponent) Condition(org.hl7.fhir.dstu3.model.Condition) MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) MedicationRequestRequesterComponent(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestRequesterComponent) Reference(org.hl7.fhir.dstu3.model.Reference) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) SimpleQuantity(org.hl7.fhir.dstu3.model.SimpleQuantity) SimpleQuantity(org.hl7.fhir.dstu3.model.SimpleQuantity) Quantity(org.hl7.fhir.dstu3.model.Quantity) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Extension(org.hl7.fhir.dstu3.model.Extension) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) JsonElement(com.google.gson.JsonElement) CodeType(org.hl7.fhir.dstu3.model.CodeType) Timing(org.hl7.fhir.dstu3.model.Timing)

Example 45 with Timing

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

the class DosageTranslatorImplTest method toFhirResource_shouldSetDosageTiming.

@Test
public void toFhirResource_shouldSetDosageTiming() {
    Timing.TimingRepeatComponent repeatComponent = new Timing.TimingRepeatComponent();
    repeatComponent.setPeriod(1);
    repeatComponent.setPeriodUnit(Timing.UnitsOfTime.D);
    Timing timing = new Timing();
    timing.addEvent(new Date());
    timing.setRepeat(repeatComponent);
    when(timingTranslator.toFhirResource(drugOrder)).thenReturn(timing);
    Dosage result = dosageTranslator.toFhirResource(drugOrder);
    assertThat(result, notNullValue());
    assertThat(result.getTiming(), notNullValue());
    assertThat(result.getTiming().getEvent(), not(empty()));
    assertThat(result.getTiming().getEvent().get(0).getValue(), DateMatchers.sameDay(new Date()));
    assertThat(result.getTiming().getRepeat().getPeriod(), equalTo(new BigDecimal(1)));
    assertThat(result.getTiming().getRepeat().getPeriodUnit(), equalTo(Timing.UnitsOfTime.D));
}
Also used : Timing(org.hl7.fhir.r4.model.Timing) Dosage(org.hl7.fhir.r4.model.Dosage) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

NotImplementedException (org.apache.commons.lang3.NotImplementedException)14 Timing (org.hl7.fhir.r4.model.Timing)11 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)10 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)9 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)8 Base64 (org.apache.commons.codec.binary.Base64)6 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)6 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 Timing (org.hl7.fhir.dstu3.model.Timing)5 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)5 Reference (org.hl7.fhir.dstu3.model.Reference)4 EventTiming (org.hl7.fhir.dstu3.model.Timing.EventTiming)4 TimingRepeatComponent (org.hl7.fhir.dstu3.model.Timing.TimingRepeatComponent)4 BigDecimal (java.math.BigDecimal)3 Dosage (org.hl7.fhir.r4.model.Dosage)3 Period (org.hl7.fhir.r4.model.Period)3 Quantity (org.hl7.fhir.r4.model.Quantity)3 TimingRepeatComponent (org.hl7.fhir.r4.model.Timing.TimingRepeatComponent)3 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)3