Search in sources :

Example 1 with Dosage

use of ca.uhn.fhir.model.dstu2.resource.MedicationAdministration.Dosage in project synthea by synthetichealth.

the class FhirDstu2 method medicationAdministration.

/**
 * Add a MedicationAdministration if needed for the given medication.
 *
 * @param rand              Source of randomness to use when generating ids etc
 * @param personEntry       The Entry for the Person
 * @param bundle            Bundle to add the MedicationAdministration to
 * @param encounterEntry    Current Encounter entry
 * @param medication        The Medication
 * @return The added Entry
 */
private static Entry medicationAdministration(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, Medication medication) {
    MedicationAdministration medicationResource = new MedicationAdministration();
    medicationResource.setPatient(new ResourceReferenceDt(personEntry.getFullUrl()));
    medicationResource.setEncounter(new ResourceReferenceDt(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.setEffectiveTime(new DateTimeDt(new Date(medication.start)));
    medicationResource.setStatus(MedicationAdministrationStatusEnum.COMPLETED);
    if (medication.prescriptionDetails != null) {
        JsonObject rxInfo = medication.prescriptionDetails;
        MedicationAdministration.Dosage dosage = new MedicationAdministration.Dosage();
        // as_needed is true if present
        if ((rxInfo.has("dosage")) && (!rxInfo.has("as_needed"))) {
            SimpleQuantityDt dose = new SimpleQuantityDt();
            dose.setValue(rxInfo.get("dosage").getAsJsonObject().get("amount").getAsDouble());
            dosage.setQuantity(dose);
            if (rxInfo.has("instructions")) {
                for (JsonElement instructionElement : rxInfo.get("instructions").getAsJsonArray()) {
                    JsonObject instruction = instructionElement.getAsJsonObject();
                    dosage.setText(instruction.get("display").getAsString());
                }
            }
        }
        medicationResource.setDosage(dosage);
    }
    if (!medication.reasons.isEmpty()) {
        // Only one element in list
        Code reason = medication.reasons.get(0);
        for (Entry entry : bundle.getEntry()) {
            if (entry.getResource().getResourceName().equals("Condition")) {
                Condition condition = (Condition) entry.getResource();
                // Only one element in list
                CodeableConceptDt coding = condition.getCode();
                if (reason.code.equals(coding.getCodingFirstRep().getCode())) {
                    medicationResource.addReasonGiven(coding);
                }
            }
        }
    }
    Entry medicationAdminEntry = newEntry(rand, bundle, medicationResource);
    return medicationAdminEntry;
}
Also used : Condition(ca.uhn.fhir.model.dstu2.resource.Condition) ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) CodeableConceptDt(ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt) SimpleQuantityDt(ca.uhn.fhir.model.dstu2.composite.SimpleQuantityDt) JsonObject(com.google.gson.JsonObject) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) JsonElement(com.google.gson.JsonElement) MedicationAdministration(ca.uhn.fhir.model.dstu2.resource.MedicationAdministration)

Example 2 with Dosage

use of ca.uhn.fhir.model.dstu2.resource.MedicationAdministration.Dosage in project synthea by synthetichealth.

the class FhirDstu2 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 Entry medication(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, Medication medication) {
    MedicationOrder medicationResource = new MedicationOrder();
    medicationResource.setPatient(new ResourceReferenceDt(personEntry.getFullUrl()));
    medicationResource.setEncounter(new ResourceReferenceDt(encounterEntry.getFullUrl()));
    ca.uhn.fhir.model.dstu2.resource.Encounter encounter = (ca.uhn.fhir.model.dstu2.resource.Encounter) encounterEntry.getResource();
    medicationResource.setPrescriber(encounter.getParticipantFirstRep().getIndividual());
    Code code = medication.codes.get(0);
    String system = code.system.equals("SNOMED-CT") ? SNOMED_URI : RXNORM_URI;
    medicationResource.setMedication(mapCodeToCodeableConcept(code, system));
    medicationResource.setDateWritten(new DateTimeDt(new Date(medication.start)));
    if (medication.stop != 0L) {
        medicationResource.setStatus(MedicationOrderStatusEnum.STOPPED);
    } else {
        medicationResource.setStatus(MedicationOrderStatusEnum.ACTIVE);
    }
    if (!medication.reasons.isEmpty()) {
        // Only one element in list
        Code reason = medication.reasons.get(0);
        for (Entry entry : bundle.getEntry()) {
            if (entry.getResource().getResourceName().equals("Condition")) {
                Condition condition = (Condition) entry.getResource();
                // Only one element in list
                CodingDt coding = condition.getCode().getCoding().get(0);
                if (reason.code.equals(coding.getCode())) {
                    medicationResource.setReason(new ResourceReferenceDt(entry.getFullUrl()));
                }
            }
        }
    }
    if (medication.prescriptionDetails != null) {
        JsonObject rxInfo = medication.prescriptionDetails;
        DosageInstruction dosage = new DosageInstruction();
        // as_needed is true if present
        dosage.setAsNeeded(new BooleanDt(rxInfo.has("as_needed")));
        // as_needed is true if present
        if ((rxInfo.has("dosage")) && (!rxInfo.has("as_needed"))) {
            TimingDt timing = new TimingDt();
            Repeat timingRepeatComponent = new Repeat();
            timingRepeatComponent.setFrequency(rxInfo.get("dosage").getAsJsonObject().get("frequency").getAsInt());
            timingRepeatComponent.setPeriod(rxInfo.get("dosage").getAsJsonObject().get("period").getAsDouble());
            timingRepeatComponent.setPeriodUnits(convertUcumCode(rxInfo.get("dosage").getAsJsonObject().get("unit").getAsString()));
            timing.setRepeat(timingRepeatComponent);
            dosage.setTiming(timing);
            QuantityDt dose = new SimpleQuantityDt().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.setAdditionalInstructions(mapCodeToCodeableConcept(instructionCode, SNOMED_URI));
                }
            }
        }
        List<DosageInstruction> dosageInstruction = new ArrayList<DosageInstruction>();
        dosageInstruction.add(dosage);
        medicationResource.setDosageInstruction(dosageInstruction);
    }
    Entry 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);
    }
    return medicationEntry;
}
Also used : ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) SimpleQuantityDt(ca.uhn.fhir.model.dstu2.composite.SimpleQuantityDt) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Repeat(ca.uhn.fhir.model.dstu2.composite.TimingDt.Repeat) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) TimingDt(ca.uhn.fhir.model.dstu2.composite.TimingDt) CodingDt(ca.uhn.fhir.model.dstu2.composite.CodingDt) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) MedicationOrder(ca.uhn.fhir.model.dstu2.resource.MedicationOrder) BooleanDt(ca.uhn.fhir.model.primitive.BooleanDt) DosageInstruction(ca.uhn.fhir.model.dstu2.resource.MedicationOrder.DosageInstruction) Condition(ca.uhn.fhir.model.dstu2.resource.Condition) SimpleQuantityDt(ca.uhn.fhir.model.dstu2.composite.SimpleQuantityDt) QuantityDt(ca.uhn.fhir.model.dstu2.composite.QuantityDt) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) JsonElement(com.google.gson.JsonElement)

Example 3 with Dosage

use of ca.uhn.fhir.model.dstu2.resource.MedicationAdministration.Dosage in project eCRNow by drajer-health.

the class Dstu2CdaMedicationGenerator method generateMedicationSection.

public static String generateMedicationSection(Dstu2FhirData data, LaunchDetails details) {
    StringBuilder sb = new StringBuilder(2000);
    // List<MedicationStatement> meds = data.getMedications();
    List<MedicationAdministration> meds = data.getMedicationAdministrations();
    if (meds != null && meds.size() > 0) {
        // Generate the component and section end tags
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.COMP_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForNFSection(CdaGeneratorConstants.SECTION_EL_NAME, CdaGeneratorConstants.NF_NI));
        sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.MED_ADM_SEC_TEMPLATE_ID));
        sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.MED_ADM_SEC_TEMPLATE_ID, CdaGeneratorConstants.MED_SEC_TEMPLATE_ID_EXT));
        sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.MED_ADM_SEC_CODE, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.MED_ADM_SEC_NAME));
        // add Title
        sb.append(CdaGeneratorUtils.getXmlForText(CdaGeneratorConstants.TITLE_EL_NAME, CdaGeneratorConstants.MED_ADM_SEC_TITLE));
        // add Narrative Text
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TEXT_EL_NAME));
        // Create Table Header.
        List<String> list = new ArrayList<String>();
        list.add(CdaGeneratorConstants.MED_TABLE_COL_1_TITLE);
        list.add(CdaGeneratorConstants.MED_TABLE_COL_2_TITLE);
        sb.append(CdaGeneratorUtils.getXmlForTableHeader(list, CdaGeneratorConstants.TABLE_BORDER, CdaGeneratorConstants.TABLE_WIDTH));
        // add Table Body
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
        // add Body Rows
        int rowNum = 1;
        for (MedicationAdministration med : meds) {
            String medDisplayName = CdaGeneratorConstants.UNKNOWN_VALUE;
            if (med.getMedication() != null) {
                medDisplayName = Dstu2CdaFhirUtilities.getStringForIDataType(med.getMedication());
            }
            String dt = null;
            if (med.getEffectiveTime() != null) {
                dt = Dstu2CdaFhirUtilities.getStringForIDataType(med.getEffectiveTime());
            }
            Map<String, String> bodyvals = new HashMap<String, String>();
            bodyvals.put(CdaGeneratorConstants.MED_TABLE_COL_1_BODY_CONTENT, medDisplayName);
            bodyvals.put(CdaGeneratorConstants.MED_TABLE_COL_2_BODY_CONTENT, dt);
            sb.append(CdaGeneratorUtils.addTableRow(bodyvals, rowNum));
            // TODO: ++rowNum or rowNum++
            ++rowNum;
        }
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
        // End Table.
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TEXT_EL_NAME));
        for (MedicationAdministration med : meds) {
            // add the Entries.
            sb.append(CdaGeneratorUtils.getXmlForActEntry(CdaGeneratorConstants.TYPE_CODE_DEF));
            // add the medication Act
            sb.append(CdaGeneratorUtils.getXmlForAct(CdaGeneratorConstants.MED_ACT_EL_NAME, CdaGeneratorConstants.MED_CLASS_CODE, CdaGeneratorConstants.MOOD_CODE_DEF));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.MED_ENTRY_TEMPLATE_ID));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.MED_ENTRY_TEMPLATE_ID, CdaGeneratorConstants.MED_ENTRY_TEMPLATE_ID_EXT));
            sb.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), med.getId().getIdPart()));
            // set status code
            sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.STATUS_CODE_EL_NAME, CdaGeneratorConstants.COMPLETED_STATUS));
            // Set up Effective Time for start and End time.
            sb.append(Dstu2CdaFhirUtilities.getIDataTypeXml(med.getEffectiveTime(), CdaGeneratorConstants.EFF_TIME_EL_NAME, false));
            // Set up Effective Time for Frequency.
            String ds = "";
            String freqInHours = CdaGeneratorConstants.UNKNOWN_VALUE;
            if (med.getDosage() != null) {
                Dosage dsg = med.getDosage();
                if (dsg.getQuantity() != null && dsg.getQuantity().getValue() != null && dsg.getQuantity().getUnit() != null) {
                    // add Dose quantity
                    sb.append(CdaGeneratorUtils.getXmlForQuantity(CdaGeneratorConstants.DOSE_QUANTITY_EL_NAME, dsg.getQuantity().getValue().toString(), dsg.getQuantity().getUnit(), false));
                }
            }
            // add the consumable presentation.
            sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.CONSUMABLE_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForStartElementWithClassCode(CdaGeneratorConstants.MAN_PROD_EL_NAME, CdaGeneratorConstants.MANU_CLASS_CODE));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.CONSUMABLE_ENTRY_TEMPLATE_ID));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.CONSUMABLE_ENTRY_TEMPLATE_ID, CdaGeneratorConstants.CONSUMABLE_ENTRY_TEMPLATE_ID_EXT));
            sb.append(CdaGeneratorUtils.getXmlForIIUsingGuid());
            sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.MANU_MAT_EL_NAME));
            sb.append(Dstu2CdaFhirUtilities.getIDataTypeXml(med.getMedication(), CdaGeneratorConstants.CODE_EL_NAME, false));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.MANU_MAT_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.MAN_PROD_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.CONSUMABLE_EL_NAME));
            // End Tags for Entries
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.MED_ACT_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ENTRY_EL_NAME));
        }
        // Complete the section end tags.
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.SECTION_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.COMP_EL_NAME));
    } else {
        sb.append(generateEmptyMedications());
    }
    return sb.toString();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MedicationAdministration(ca.uhn.fhir.model.dstu2.resource.MedicationAdministration) Dosage(ca.uhn.fhir.model.dstu2.resource.MedicationAdministration.Dosage)

Aggregations

ResourceReferenceDt (ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt)2 SimpleQuantityDt (ca.uhn.fhir.model.dstu2.composite.SimpleQuantityDt)2 Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)2 Condition (ca.uhn.fhir.model.dstu2.resource.Condition)2 MedicationAdministration (ca.uhn.fhir.model.dstu2.resource.MedicationAdministration)2 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)2 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)2 CodeableConceptDt (ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt)1 CodingDt (ca.uhn.fhir.model.dstu2.composite.CodingDt)1 QuantityDt (ca.uhn.fhir.model.dstu2.composite.QuantityDt)1 TimingDt (ca.uhn.fhir.model.dstu2.composite.TimingDt)1 Repeat (ca.uhn.fhir.model.dstu2.composite.TimingDt.Repeat)1 Dosage (ca.uhn.fhir.model.dstu2.resource.MedicationAdministration.Dosage)1 MedicationOrder (ca.uhn.fhir.model.dstu2.resource.MedicationOrder)1 DosageInstruction (ca.uhn.fhir.model.dstu2.resource.MedicationOrder.DosageInstruction)1 BooleanDt (ca.uhn.fhir.model.primitive.BooleanDt)1