Search in sources :

Example 6 with Condition

use of ca.uhn.fhir.model.dstu2.resource.Condition 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 7 with Condition

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

the class FhirDstu2 method careplan.

/**
 * Map the given CarePlan to a FHIR CarePlan 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 CarePlan to
 * @param encounterEntry
 *          Current Encounter entry
 * @param carePlan
 *          The CarePlan to map to FHIR and add to the bundle
 * @return The added Entry
 */
private static Entry careplan(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, CarePlan carePlan) {
    ca.uhn.fhir.model.dstu2.resource.CarePlan careplanResource = new ca.uhn.fhir.model.dstu2.resource.CarePlan();
    careplanResource.setSubject(new ResourceReferenceDt(personEntry.getFullUrl()));
    careplanResource.setContext(new ResourceReferenceDt(encounterEntry.getFullUrl()));
    Code code = carePlan.codes.get(0);
    careplanResource.addCategory(mapCodeToCodeableConcept(code, SNOMED_URI));
    NarrativeDt narrative = new NarrativeDt();
    narrative.setStatus(NarrativeStatusEnum.GENERATED);
    narrative.setDiv(code.display);
    careplanResource.setText(narrative);
    CarePlanActivityStatusEnum activityStatus;
    GoalStatusEnum goalStatus;
    PeriodDt period = new PeriodDt().setStart(new DateTimeDt(new Date(carePlan.start)));
    careplanResource.setPeriod(period);
    if (carePlan.stop != 0L) {
        period.setEnd(new DateTimeDt(new Date(carePlan.stop)));
        careplanResource.setStatus(CarePlanStatusEnum.COMPLETED);
        activityStatus = CarePlanActivityStatusEnum.COMPLETED;
        goalStatus = GoalStatusEnum.ACHIEVED;
    } else {
        careplanResource.setStatus(CarePlanStatusEnum.ACTIVE);
        activityStatus = CarePlanActivityStatusEnum.IN_PROGRESS;
        goalStatus = GoalStatusEnum.IN_PROGRESS;
    }
    if (!carePlan.activities.isEmpty()) {
        for (Code activity : carePlan.activities) {
            Activity activityComponent = new Activity();
            ActivityDetail activityDetailComponent = new ActivityDetail();
            activityDetailComponent.setStatus(activityStatus);
            activityDetailComponent.setCode(mapCodeToCodeableConcept(activity, SNOMED_URI));
            activityDetailComponent.setProhibited(new BooleanDt(false));
            activityComponent.setDetail(activityDetailComponent);
            careplanResource.addActivity(activityComponent);
        }
    }
    if (!carePlan.reasons.isEmpty()) {
        // Only one element in list
        Code reason = carePlan.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())) {
                    careplanResource.addAddresses().setReference(entry.getFullUrl());
                }
            }
        }
    }
    for (JsonObject goal : carePlan.goals) {
        Entry goalEntry = caregoal(rand, bundle, goalStatus, goal);
        careplanResource.addGoal().setReference(goalEntry.getFullUrl());
    }
    return newEntry(rand, bundle, careplanResource);
}
Also used : Condition(ca.uhn.fhir.model.dstu2.resource.Condition) ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) PeriodDt(ca.uhn.fhir.model.dstu2.composite.PeriodDt) Activity(ca.uhn.fhir.model.dstu2.resource.CarePlan.Activity) JsonObject(com.google.gson.JsonObject) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) NarrativeDt(ca.uhn.fhir.model.dstu2.composite.NarrativeDt) Date(java.util.Date) CarePlan(org.mitre.synthea.world.concepts.HealthRecord.CarePlan) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) GoalStatusEnum(ca.uhn.fhir.model.dstu2.valueset.GoalStatusEnum) CodingDt(ca.uhn.fhir.model.dstu2.composite.CodingDt) BooleanDt(ca.uhn.fhir.model.primitive.BooleanDt) CarePlanActivityStatusEnum(ca.uhn.fhir.model.dstu2.valueset.CarePlanActivityStatusEnum) ActivityDetail(ca.uhn.fhir.model.dstu2.resource.CarePlan.ActivityDetail)

Example 8 with Condition

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

the class FhirDstu2 method condition.

/**
 * Map the Condition into a FHIR Condition 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
 *          The Bundle to add to
 * @param encounterEntry
 *          The current Encounter entry
 * @param condition
 *          The Condition
 * @return The added Entry
 */
private static Entry condition(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, HealthRecord.Entry condition) {
    Condition conditionResource = new Condition();
    conditionResource.setPatient(new ResourceReferenceDt(personEntry.getFullUrl()));
    conditionResource.setEncounter(new ResourceReferenceDt(encounterEntry.getFullUrl()));
    Code code = condition.codes.get(0);
    conditionResource.setCode(mapCodeToCodeableConcept(code, SNOMED_URI));
    conditionResource.setCategory(ConditionCategoryCodesEnum.DIAGNOSIS);
    conditionResource.setVerificationStatus(ConditionVerificationStatusEnum.CONFIRMED);
    conditionResource.setClinicalStatus(ConditionClinicalStatusCodesEnum.ACTIVE);
    conditionResource.setOnset(convertFhirDateTime(condition.start, true));
    conditionResource.setDateRecorded(new DateDt(new Date(condition.start)));
    if (condition.stop != 0) {
        conditionResource.setAbatement(convertFhirDateTime(condition.stop, true));
        conditionResource.setClinicalStatus(ConditionClinicalStatusCodesEnum.RESOLVED);
    }
    Entry conditionEntry = newEntry(rand, bundle, conditionResource);
    condition.fullUrl = conditionEntry.getFullUrl();
    return conditionEntry;
}
Also used : Condition(ca.uhn.fhir.model.dstu2.resource.Condition) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) DateDt(ca.uhn.fhir.model.primitive.DateDt) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date)

Example 9 with Condition

use of ca.uhn.fhir.model.dstu2.resource.Condition 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 10 with Condition

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

the class FhirDstu2 method caregoal.

/**
 * Map the JsonObject into a FHIR Goal resource, and add it to the given Bundle.
 *
 * @param rand Source of randomness to use when generating ids etc
 * @param bundle The Bundle to add to
 * @param goalStatus The GoalStatus
 * @param goal The JsonObject
 * @return The added Entry
 */
private static Entry caregoal(RandomNumberGenerator rand, Bundle bundle, GoalStatusEnum goalStatus, JsonObject goal) {
    ca.uhn.fhir.model.dstu2.resource.Goal goalResource = new ca.uhn.fhir.model.dstu2.resource.Goal();
    goalResource.setStatus(goalStatus);
    if (goal.has("text")) {
        goalResource.setDescription(goal.get("text").getAsString());
    } else if (goal.has("codes")) {
        JsonObject code = goal.get("codes").getAsJsonArray().get(0).getAsJsonObject();
        goalResource.setDescription(code.get("display").getAsString());
    } else if (goal.has("observation")) {
        // build up our own text from the observation condition, similar to the graphviz logic
        JsonObject logic = goal.get("observation").getAsJsonObject();
        String[] text = { logic.get("codes").getAsJsonArray().get(0).getAsJsonObject().get("display").getAsString(), logic.get("operator").getAsString(), logic.get("value").getAsString() };
        goalResource.setDescription(String.join(" ", text));
    }
    if (goal.has("addresses")) {
        for (JsonElement reasonElement : goal.get("addresses").getAsJsonArray()) {
            if (reasonElement instanceof JsonObject) {
                JsonObject reasonObject = reasonElement.getAsJsonObject();
                String reasonCode = reasonObject.get("codes").getAsJsonObject().get("SNOMED-CT").getAsJsonArray().get(0).getAsString();
                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 (reasonCode.equals(coding.getCode())) {
                            goalResource.addAddresses().setReference(entry.getFullUrl());
                        }
                    }
                }
            }
        }
    }
    return newEntry(rand, bundle, goalResource);
}
Also used : Condition(ca.uhn.fhir.model.dstu2.resource.Condition) JsonObject(com.google.gson.JsonObject) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) JsonElement(com.google.gson.JsonElement) CodingDt(ca.uhn.fhir.model.dstu2.composite.CodingDt)

Aggregations

Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)13 Condition (ca.uhn.fhir.model.dstu2.resource.Condition)13 ResourceReferenceDt (ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt)9 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)8 Date (java.util.Date)7 ArrayList (java.util.ArrayList)6 CodingDt (ca.uhn.fhir.model.dstu2.composite.CodingDt)5 Bundle (ca.uhn.fhir.model.dstu2.resource.Bundle)5 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)5 DiagnosticReport (ca.uhn.fhir.model.dstu2.resource.DiagnosticReport)4 JsonObject (com.google.gson.JsonObject)4 CodeableConceptDt (ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt)3 SimpleQuantityDt (ca.uhn.fhir.model.dstu2.composite.SimpleQuantityDt)3 DiagnosticOrder (ca.uhn.fhir.model.dstu2.resource.DiagnosticOrder)3 Encounter (ca.uhn.fhir.model.dstu2.resource.Encounter)3 MedicationAdministration (ca.uhn.fhir.model.dstu2.resource.MedicationAdministration)3 Observation (ca.uhn.fhir.model.dstu2.resource.Observation)3 Organization (ca.uhn.fhir.model.dstu2.resource.Organization)3 Patient (ca.uhn.fhir.model.dstu2.resource.Patient)3 Practitioner (ca.uhn.fhir.model.dstu2.resource.Practitioner)3