Search in sources :

Example 1 with QuantityDt

use of ca.uhn.fhir.model.dstu2.composite.QuantityDt in project synthea by synthetichealth.

the class FHIRDSTU2ExporterTest method testDecimalRounding.

@Test
public void testDecimalRounding() {
    Integer i = 123456;
    Object v = FhirDstu2.mapValueToFHIRType(i, "fake");
    assertTrue(v instanceof QuantityDt);
    QuantityDt q = (QuantityDt) v;
    assertTrue(q.getValue().compareTo(BigDecimal.valueOf(123460)) == 0);
    Double d = 0.000123456;
    v = FhirDstu2.mapValueToFHIRType(d, "fake");
    assertTrue(v instanceof QuantityDt);
    q = (QuantityDt) v;
    assertTrue(q.getValue().compareTo(BigDecimal.valueOf(0.00012346)) == 0);
    d = 0.00012345678901234;
    v = FhirDstu2.mapValueToFHIRType(d, "fake");
    assertTrue(v instanceof QuantityDt);
    q = (QuantityDt) v;
    assertTrue(q.getValue().compareTo(BigDecimal.valueOf(0.00012346)) == 0);
}
Also used : QuantityDt(ca.uhn.fhir.model.dstu2.composite.QuantityDt) Test(org.junit.Test)

Example 2 with QuantityDt

use of ca.uhn.fhir.model.dstu2.composite.QuantityDt in project eCRNow by drajer-health.

the class Dstu2CdaFhirUtilities method getIDataTypeXml.

public static String getIDataTypeXml(IDatatype dt, String elName, Boolean valFlag) {
    if (dt != null) {
        logger.info(" Printing the class name " + dt.getClass());
        String val = "";
        if (dt instanceof CodingDt) {
            CodingDt cd = (CodingDt) dt;
            List<CodingDt> cds = new ArrayList<CodingDt>();
            cds.add(cd);
            if (!valFlag)
                val += getCodingXml(cds, elName);
            else
                val += getCodingXmlForValue(cds, elName);
        } else if (dt instanceof CodeableConceptDt) {
            CodeableConceptDt cd = (CodeableConceptDt) dt;
            List<CodingDt> cds = cd.getCoding();
            if (!valFlag)
                val += getCodingXml(cds, elName);
            else
                val += getCodingXmlForValue(cds, elName);
        } else if (dt instanceof QuantityDt) {
            QuantityDt qt = (QuantityDt) dt;
            val += getQuantityXml(qt, elName, valFlag);
        } else if (dt instanceof DateTimeDt) {
            DateTimeDt d = (DateTimeDt) dt;
            val += CdaGeneratorUtils.getXmlForEffectiveTime(elName, d.getValue(), d.getTimeZone());
        } else if (dt instanceof PeriodDt) {
            PeriodDt pt = (PeriodDt) dt;
            val += getPeriodXml(pt, elName);
        } else if (dt instanceof CodeDt) {
            CodeDt cd = (CodeDt) dt;
            if (!valFlag)
                val += CdaGeneratorUtils.getXmlForNullCD(elName, CdaGeneratorConstants.NF_NI);
            else
                val += CdaGeneratorUtils.getNFXMLForValue(CdaGeneratorConstants.NF_NI);
        }
        return val;
    }
    return CdaGeneratorConstants.UNKNOWN_VALUE;
}
Also used : CodeDt(ca.uhn.fhir.model.primitive.CodeDt) BoundCodeDt(ca.uhn.fhir.model.primitive.BoundCodeDt) CodeableConceptDt(ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt) BoundCodeableConceptDt(ca.uhn.fhir.model.dstu2.composite.BoundCodeableConceptDt) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) PeriodDt(ca.uhn.fhir.model.dstu2.composite.PeriodDt) CodingDt(ca.uhn.fhir.model.dstu2.composite.CodingDt) ArrayList(java.util.ArrayList) QuantityDt(ca.uhn.fhir.model.dstu2.composite.QuantityDt) BaseQuantityDt(ca.uhn.fhir.model.base.composite.BaseQuantityDt) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with QuantityDt

use of ca.uhn.fhir.model.dstu2.composite.QuantityDt in project synthea by synthetichealth.

the class FhirDstu2 method mapValueToFHIRType.

static IDatatype mapValueToFHIRType(Object value, String unit) {
    if (value == null) {
        return null;
    } else if (value instanceof Condition) {
        Code conditionCode = ((HealthRecord.Entry) value).codes.get(0);
        return mapCodeToCodeableConcept(conditionCode, SNOMED_URI);
    } else if (value instanceof Code) {
        return mapCodeToCodeableConcept((Code) value, SNOMED_URI);
    } else if (value instanceof String) {
        return new StringDt((String) value);
    } else if (value instanceof Number) {
        double dblVal = ((Number) value).doubleValue();
        PlainBigDecimal bigVal = new PlainBigDecimal(dblVal);
        return new QuantityDt().setValue(bigVal).setCode(unit).setSystem(UNITSOFMEASURE_URI).setUnit(unit);
    } else if (value instanceof Components.SampledData) {
        return mapValueToSampledData((Components.SampledData) value, unit);
    } else {
        throw new IllegalArgumentException("unexpected observation value class: " + value.getClass().toString() + "; " + value);
    }
}
Also used : 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) Components(org.mitre.synthea.engine.Components) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) StringDt(ca.uhn.fhir.model.primitive.StringDt)

Example 4 with QuantityDt

use of ca.uhn.fhir.model.dstu2.composite.QuantityDt 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 5 with QuantityDt

use of ca.uhn.fhir.model.dstu2.composite.QuantityDt in project eCRNow by drajer-health.

the class Dstu2CdaFhirUtilities method getStringForIDataType.

public static String getStringForIDataType(IDatatype dt) {
    if (dt != null) {
        logger.info(" Printing the class name " + dt.getClass());
        String val = "";
        if (dt instanceof CodingDt) {
            CodingDt cd = (CodingDt) dt;
            if (cd.getCodeElement() != null && cd.getSystemElement() != null) {
                val += cd.getSystemElement().getValue() + CdaGeneratorConstants.PIPE + cd.getCodeElement().getValue();
            }
        } else if (dt instanceof BaseQuantityDt) {
            QuantityDt qt = (QuantityDt) dt;
            if (qt.getValueElement() != null && qt.getSystemElement() != null && qt.getUnit() != null) {
                val += qt.getValueElement().getValueAsString() + CdaGeneratorConstants.PIPE + qt.getSystemElement().getValueAsString() + CdaGeneratorConstants.PIPE + qt.getUnit();
            }
        } else if (dt instanceof DateTimeDt) {
            DateTimeDt d = (DateTimeDt) dt;
            val += d.getValueAsString();
        } else if (dt instanceof PeriodDt) {
            PeriodDt pt = (PeriodDt) dt;
            if (pt.getStart() != null && pt.getEnd() != null) {
                val += pt.getStart().toString() + CdaGeneratorConstants.PIPE + pt.getEnd().toString();
            } else if (pt.getStart() != null) {
                val += pt.getStart().toString();
            }
        } else if (dt instanceof CodeDt) {
            CodeDt cd = (CodeDt) dt;
            val += cd.getValue();
        }
        return val;
    }
    return CdaGeneratorConstants.UNKNOWN_VALUE;
}
Also used : BaseQuantityDt(ca.uhn.fhir.model.base.composite.BaseQuantityDt) CodeDt(ca.uhn.fhir.model.primitive.CodeDt) BoundCodeDt(ca.uhn.fhir.model.primitive.BoundCodeDt) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) PeriodDt(ca.uhn.fhir.model.dstu2.composite.PeriodDt) CodingDt(ca.uhn.fhir.model.dstu2.composite.CodingDt) QuantityDt(ca.uhn.fhir.model.dstu2.composite.QuantityDt) BaseQuantityDt(ca.uhn.fhir.model.base.composite.BaseQuantityDt)

Aggregations

QuantityDt (ca.uhn.fhir.model.dstu2.composite.QuantityDt)5 CodingDt (ca.uhn.fhir.model.dstu2.composite.CodingDt)3 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)3 BaseQuantityDt (ca.uhn.fhir.model.base.composite.BaseQuantityDt)2 PeriodDt (ca.uhn.fhir.model.dstu2.composite.PeriodDt)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 BoundCodeDt (ca.uhn.fhir.model.primitive.BoundCodeDt)2 CodeDt (ca.uhn.fhir.model.primitive.CodeDt)2 ArrayList (java.util.ArrayList)2 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)2 BoundCodeableConceptDt (ca.uhn.fhir.model.dstu2.composite.BoundCodeableConceptDt)1 CodeableConceptDt (ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt)1 ResourceReferenceDt (ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt)1 TimingDt (ca.uhn.fhir.model.dstu2.composite.TimingDt)1 Repeat (ca.uhn.fhir.model.dstu2.composite.TimingDt.Repeat)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