Search in sources :

Example 1 with Activity

use of ca.uhn.fhir.model.dstu2.resource.CarePlan.Activity 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)

Aggregations

CodingDt (ca.uhn.fhir.model.dstu2.composite.CodingDt)1 NarrativeDt (ca.uhn.fhir.model.dstu2.composite.NarrativeDt)1 PeriodDt (ca.uhn.fhir.model.dstu2.composite.PeriodDt)1 ResourceReferenceDt (ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt)1 Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)1 Activity (ca.uhn.fhir.model.dstu2.resource.CarePlan.Activity)1 ActivityDetail (ca.uhn.fhir.model.dstu2.resource.CarePlan.ActivityDetail)1 Condition (ca.uhn.fhir.model.dstu2.resource.Condition)1 CarePlanActivityStatusEnum (ca.uhn.fhir.model.dstu2.valueset.CarePlanActivityStatusEnum)1 GoalStatusEnum (ca.uhn.fhir.model.dstu2.valueset.GoalStatusEnum)1 BooleanDt (ca.uhn.fhir.model.primitive.BooleanDt)1 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)1 JsonObject (com.google.gson.JsonObject)1 Date (java.util.Date)1 CarePlan (org.mitre.synthea.world.concepts.HealthRecord.CarePlan)1 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)1