Search in sources :

Example 1 with PeriodDt

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

the class FhirDstu2 method procedure.

/**
 * Map the given Procedure into a FHIR Procedure resource, and add it to the given Bundle.
 *
 * @param rand
 *          Source of randomness to use when generating ids etc
 * @param personEntry
 *          The Person entry
 * @param bundle
 *          Bundle to add to
 * @param encounterEntry
 *          The current Encounter entry
 * @param procedure
 *          The Procedure
 * @return The added Entry
 */
private static Entry procedure(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, Procedure procedure) {
    ca.uhn.fhir.model.dstu2.resource.Procedure procedureResource = new ca.uhn.fhir.model.dstu2.resource.Procedure();
    procedureResource.setStatus(ProcedureStatusEnum.COMPLETED);
    procedureResource.setSubject(new ResourceReferenceDt(personEntry.getFullUrl()));
    procedureResource.setEncounter(new ResourceReferenceDt(encounterEntry.getFullUrl()));
    Code code = procedure.codes.get(0);
    procedureResource.setCode(mapCodeToCodeableConcept(code, SNOMED_URI));
    if (procedure.stop != 0L) {
        Date startDate = new Date(procedure.start);
        Date endDate = new Date(procedure.stop);
        procedureResource.setPerformed(new PeriodDt().setStart(new DateTimeDt(startDate)).setEnd(new DateTimeDt(endDate)));
    } else {
        procedureResource.setPerformed(convertFhirDateTime(procedure.start, true));
    }
    if (!procedure.reasons.isEmpty()) {
        // Only one element in list
        Code reason = procedure.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())) {
                    procedureResource.setReason(new ResourceReferenceDt(entry.getFullUrl()));
                }
            }
        }
    }
    Entry procedureEntry = newEntry(rand, bundle, procedureResource);
    procedure.fullUrl = procedureEntry.getFullUrl();
    return procedureEntry;
}
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) 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) CodingDt(ca.uhn.fhir.model.dstu2.composite.CodingDt) Procedure(org.mitre.synthea.world.concepts.HealthRecord.Procedure)

Example 2 with PeriodDt

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

the class FhirDstu2 method encounter.

/**
 * Map the given Encounter into a FHIR Encounter resource, and add it to the given Bundle.
 *
 * @param person
 *          Patient at the encounter.
 * @param personEntry
 *          Entry for the Person
 * @param bundle
 *          The Bundle to add to
 * @param encounter
 *          The current Encounter
 * @return The added Entry
 */
private static Entry encounter(Person person, Entry personEntry, Bundle bundle, Encounter encounter) {
    ca.uhn.fhir.model.dstu2.resource.Encounter encounterResource = new ca.uhn.fhir.model.dstu2.resource.Encounter();
    encounterResource.setPatient(new ResourceReferenceDt(personEntry.getFullUrl()));
    encounterResource.setStatus(EncounterStateEnum.FINISHED);
    if (encounter.codes.isEmpty()) {
        // wellness encounter
        encounterResource.addType().addCoding().setCode("185349003").setDisplay("Encounter for check up").setSystem(SNOMED_URI);
    } else {
        Code code = encounter.codes.get(0);
        encounterResource.addType(mapCodeToCodeableConcept(code, SNOMED_URI));
    }
    EncounterClassEnum encounterClass = EncounterClassEnum.forCode(encounter.type);
    if (encounterClass == null) {
        encounterClass = EncounterClassEnum.AMBULATORY;
    }
    encounterResource.setClassElement(encounterClass);
    encounterResource.setPeriod(new PeriodDt().setStart(new DateTimeDt(new Date(encounter.start))).setEnd(new DateTimeDt(new Date(encounter.stop))));
    if (encounter.reason != null) {
        encounterResource.addReason().addCoding().setCode(encounter.reason.code).setDisplay(encounter.reason.display).setSystem(SNOMED_URI);
    }
    Provider provider = encounter.provider;
    if (provider == null) {
        // no associated provider, patient goes to wellness provider
        provider = person.getProvider(EncounterType.WELLNESS, encounter.start);
    }
    if (TRANSACTION_BUNDLE) {
        encounterResource.setServiceProvider(new ResourceReferenceDt(ExportHelper.buildFhirSearchUrl("Organization", provider.getResourceID())));
    } else {
        String providerFullUrl = findProviderUrl(provider, bundle);
        if (providerFullUrl != null) {
            encounterResource.setServiceProvider(new ResourceReferenceDt(providerFullUrl));
        } else {
            Entry providerOrganization = provider(bundle, provider);
            encounterResource.setServiceProvider(new ResourceReferenceDt(providerOrganization.getFullUrl()));
        }
    }
    encounterResource.getServiceProvider().setDisplay(provider.name);
    if (encounter.clinician != null) {
        if (TRANSACTION_BUNDLE) {
            encounterResource.addParticipant().setIndividual(new ResourceReferenceDt(ExportHelper.buildFhirNpiSearchUrl(encounter.clinician)));
        } else {
            String practitionerFullUrl = findPractitioner(encounter.clinician, bundle);
            if (practitionerFullUrl != null) {
                encounterResource.addParticipant().setIndividual(new ResourceReferenceDt(practitionerFullUrl));
            } else {
                Entry practitioner = practitioner(bundle, encounter.clinician);
                encounterResource.addParticipant().setIndividual(new ResourceReferenceDt(practitioner.getFullUrl()));
            }
        }
        encounterResource.getParticipantFirstRep().getIndividual().setDisplay(encounter.clinician.getFullname());
    }
    if (encounter.discharge != null) {
        Hospitalization hospitalization = new Hospitalization();
        Code dischargeDisposition = new Code(DISCHARGE_URI, encounter.discharge.code, encounter.discharge.display);
        hospitalization.setDischargeDisposition(mapCodeToCodeableConcept(dischargeDisposition, DISCHARGE_URI));
        encounterResource.setHospitalization(hospitalization);
    }
    return newEntry(person, bundle, encounterResource);
}
Also used : ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) PeriodDt(ca.uhn.fhir.model.dstu2.composite.PeriodDt) Hospitalization(ca.uhn.fhir.model.dstu2.resource.Encounter.Hospitalization) EncounterClassEnum(ca.uhn.fhir.model.dstu2.valueset.EncounterClassEnum) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Provider(org.mitre.synthea.world.agents.Provider) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter)

Example 3 with PeriodDt

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

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

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

the class LaunchController method setStartAndEndDates.

public void setStartAndEndDates(ClientDetails clientDetails, LaunchDetails launchDetails, IBaseResource encounter) {
    String fhirVersion = launchDetails.getFhirVersion();
    // This is explicitly set to null so that when we don't have the encounter
    // period present, we can default it to launch immediately.
    launchDetails.setStartDate(null);
    launchDetails.setEndDate(null);
    if (fhirVersion.equalsIgnoreCase(FhirVersionEnum.R4.toString())) {
        org.hl7.fhir.r4.model.Encounter r4Encounter = (org.hl7.fhir.r4.model.Encounter) encounter;
        if (r4Encounter != null) {
            Period r4Period = r4Encounter.getPeriod();
            if (r4Period != null) {
                if (r4Period.getStart() != null) {
                    launchDetails.setStartDate(r4Period.getStart());
                } else {
                    launchDetails.setStartDate(getDate(clientDetails.getEncounterStartThreshold()));
                }
                if (r4Period.getEnd() != null) {
                    launchDetails.setEndDate(r4Period.getEnd());
                } else {
                    launchDetails.setEndDate(getDate(clientDetails.getEncounterEndThreshold()));
                }
            }
        }
        return;
    }
    if (fhirVersion.equalsIgnoreCase(FhirVersionEnum.DSTU2.toString())) {
        Encounter dstu2Encounter = (Encounter) encounter;
        if (dstu2Encounter != null) {
            PeriodDt dstu2Period = dstu2Encounter.getPeriod();
            if (dstu2Period != null) {
                if (dstu2Period.getStart() != null) {
                    launchDetails.setStartDate(dstu2Period.getStart());
                } else {
                    launchDetails.setStartDate(getDate(clientDetails.getEncounterStartThreshold()));
                }
                if (dstu2Period.getEnd() != null) {
                    launchDetails.setEndDate(dstu2Period.getEnd());
                } else {
                    launchDetails.setEndDate(getDate(clientDetails.getEncounterEndThreshold()));
                }
            }
        }
    }
}
Also used : PeriodDt(ca.uhn.fhir.model.dstu2.composite.PeriodDt) Encounter(ca.uhn.fhir.model.dstu2.resource.Encounter) Period(org.hl7.fhir.r4.model.Period)

Aggregations

PeriodDt (ca.uhn.fhir.model.dstu2.composite.PeriodDt)9 Date (java.util.Date)6 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)5 CodingDt (ca.uhn.fhir.model.dstu2.composite.CodingDt)4 Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)4 Encounter (ca.uhn.fhir.model.dstu2.resource.Encounter)4 ResourceReferenceDt (ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt)3 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)3 BaseQuantityDt (ca.uhn.fhir.model.base.composite.BaseQuantityDt)2 QuantityDt (ca.uhn.fhir.model.dstu2.composite.QuantityDt)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 Test (org.junit.Test)2 BoundCodeableConceptDt (ca.uhn.fhir.model.dstu2.composite.BoundCodeableConceptDt)1 CodeableConceptDt (ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt)1 NarrativeDt (ca.uhn.fhir.model.dstu2.composite.NarrativeDt)1 Bundle (ca.uhn.fhir.model.dstu2.resource.Bundle)1 Activity (ca.uhn.fhir.model.dstu2.resource.CarePlan.Activity)1 ActivityDetail (ca.uhn.fhir.model.dstu2.resource.CarePlan.ActivityDetail)1