Search in sources :

Example 6 with Entry

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

the class LoadingQueryService method getData.

@Override
public FhirData getData(LaunchDetails launchDetails, Date start, Date end) {
    // Data to be pulled.
    if (launchDetails.getFhirVersion().equalsIgnoreCase(FhirVersionEnum.DSTU2.toString())) {
        Dstu2FhirData dstu2FhirData = new Dstu2FhirData();
        Bundle bundle = new Bundle();
        try {
            bundle = generateDSTU2Bundle.createDSTU2Bundle(launchDetails, dstu2FhirData, start, end);
        } catch (Exception e) {
            logger.error("Error in Generating the DSTU2 Bundle", e);
        }
        dstu2FhirData.setData(bundle);
        logger.info("Bundle Entry Size====> {}", dstu2FhirData.getData().getEntry().size());
        return dstu2FhirData;
    } else if (launchDetails.getFhirVersion().equalsIgnoreCase(FhirVersionEnum.R4.toString())) {
        R4FhirData r4FhirData = new R4FhirData();
        try {
            org.hl7.fhir.r4.model.Bundle bundle = generateR4Bundle.createR4Bundle(launchDetails, r4FhirData, start, end);
            r4FhirData.setData(bundle);
        } catch (Exception e) {
            ApplicationUtils.handleException(e, "Error in Generating the R4 Bundle", LogLevel.ERROR);
        }
        return r4FhirData;
    }
    return null;
}
Also used : Bundle(ca.uhn.fhir.model.dstu2.resource.Bundle) R4FhirData(com.drajer.sof.model.R4FhirData) Dstu2FhirData(com.drajer.sof.model.Dstu2FhirData)

Example 7 with Entry

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

the class TriggerQueryService method getData.

@Override
public FhirData getData(LaunchDetails launchDetails, Date start, Date end) {
    // Data to be pulled.
    if (launchDetails.getFhirVersion().equalsIgnoreCase(FhirVersionEnum.DSTU2.toString())) {
        Dstu2FhirData dstu2FhirData = new Dstu2FhirData();
        Bundle bundle = new Bundle();
        try {
            bundle = generateDstu2Bundles.createDSTU2Bundle(launchDetails, dstu2FhirData, start, end);
        } catch (Exception e) {
            logger.error("Error in Generating the DSTU2 Bundle", e);
        }
        dstu2FhirData.setData(bundle);
        if (logger.isInfoEnabled()) {
            logger.info("Bundle Entry Size====> {}", dstu2FhirData.getData().getEntry().size());
        }
        return dstu2FhirData;
    } else if (launchDetails.getFhirVersion().equalsIgnoreCase(FhirVersionEnum.R4.toString())) {
        R4FhirData r4FhirData = new R4FhirData();
        try {
            org.hl7.fhir.r4.model.Bundle bundle = generateR4Bundles.createR4Bundle(launchDetails, r4FhirData, start, end);
            r4FhirData.setData(bundle);
        } catch (Exception e) {
            ApplicationUtils.handleException(e, "Error in Generating the R4 Bundle", LogLevel.ERROR);
        }
        return r4FhirData;
    }
    return null;
}
Also used : Bundle(ca.uhn.fhir.model.dstu2.resource.Bundle) R4FhirData(com.drajer.sof.model.R4FhirData) Dstu2FhirData(com.drajer.sof.model.Dstu2FhirData)

Example 8 with Entry

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

the class Dstu2ResourcesData method getMedicationAdministrationData.

public List<MedicationAdministration> getMedicationAdministrationData(FhirContext context, IGenericClient client, LaunchDetails launchDetails, Dstu2FhirData dstu2FhirData, Encounter encounter, Date start, Date end) {
    Bundle bundle = (Bundle) resourceData.getResourceByPatientId(launchDetails, client, context, "MedicationAdministration");
    List<MedicationAdministration> medAdministrations = new ArrayList<>();
    List<CodeableConceptDt> medicationCodes = new ArrayList<>();
    // Filter MedicationAdministrations based on Encounter Reference
    if (bundle != null && encounter != null && !encounter.getId().getValue().isEmpty()) {
        for (Entry entry : bundle.getEntry()) {
            MedicationAdministration medAdministration = (MedicationAdministration) entry.getResource();
            if (!medAdministration.getEncounter().isEmpty()) {
                if (medAdministration.getEncounter().getReference().getIdPart().equals(encounter.getIdElement().getIdPart())) {
                    medAdministrations.add(medAdministration);
                    medicationCodes.addAll(findMedicationCodes(medAdministration));
                }
            }
        }
    // If Encounter Id is not present using start and end dates to filter
    // MedicationAdministrations
    } else if (bundle != null) {
        for (Entry entry : bundle.getEntry()) {
            MedicationAdministration medAdministration = (MedicationAdministration) entry.getResource();
            // Checking If Effective Date is present in MedicationAdministration resource
            if (medAdministration.getEffectiveTime() != null) {
                Date effectiveDateTime = (Date) medAdministration.getEffectiveTime();
                if (effectiveDateTime.after(start) && effectiveDateTime.before(end)) {
                    medAdministrations.add(medAdministration);
                    medicationCodes.addAll(findMedicationCodes(medAdministration));
                }
            } else // If Effective Date is not present looking for LastUpdatedDate
            {
                Date lastUpdatedDateTime = medAdministration.getMeta().getLastUpdated();
                if (lastUpdatedDateTime.after(start) && lastUpdatedDateTime.before(end)) {
                    medAdministrations.add(medAdministration);
                    medicationCodes.addAll(findMedicationCodes(medAdministration));
                }
            }
        }
    }
    dstu2FhirData.setMedicationCodes(medicationCodes);
    return medAdministrations;
}
Also used : Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) CodeableConceptDt(ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt) Bundle(ca.uhn.fhir.model.dstu2.resource.Bundle) ArrayList(java.util.ArrayList) MedicationAdministration(ca.uhn.fhir.model.dstu2.resource.MedicationAdministration) Date(java.util.Date)

Example 9 with Entry

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

the class Dstu2ResourcesData method getConditionData.

public List<Condition> getConditionData(FhirContext context, IGenericClient client, LaunchDetails launchDetails, Dstu2FhirData dstu2FhirData, Encounter encounter, Date start, Date end) {
    Bundle bundle = (Bundle) resourceData.getResourceByPatientId(launchDetails, client, context, "Condition");
    List<Condition> conditions = new ArrayList<>();
    List<CodeableConceptDt> conditionCodes = new ArrayList<>();
    // Filter Conditions based on Encounter Reference
    if (encounter != null && !encounter.getId().getValue().isEmpty()) {
        for (Entry entry : bundle.getEntry()) {
            Condition condition = (Condition) entry.getResource();
            if (!condition.getEncounter().isEmpty()) {
                if (condition.getEncounter().getReference().getIdPart().equals(encounter.getIdElement().getIdPart())) {
                    conditions.add(condition);
                    conditionCodes.addAll(findConditionCodes(condition));
                }
            }
        }
    // If Encounter Id is not present using start and end dates to filter conditions
    } else {
        for (Entry entry : bundle.getEntry()) {
            Condition condition = (Condition) entry.getResource();
            // Checking If Date Recorded present in Condition resource
            if (condition.getDateRecorded() != null) {
                if (condition.getDateRecorded().after(start) && condition.getDateRecorded().before(end)) {
                    conditions.add(condition);
                    conditionCodes.addAll(findConditionCodes(condition));
                }
            // If Date Recorded is not present using LastUpdatedDate
            } else {
                Date lastUpdatedDateTime = condition.getMeta().getLastUpdated();
                if (lastUpdatedDateTime.after(start) && lastUpdatedDateTime.before(end)) {
                    conditions.add(condition);
                    conditionCodes.addAll(findConditionCodes(condition));
                }
            }
        }
    }
    dstu2FhirData.setConditionCodes(conditionCodes);
    return conditions;
}
Also used : Condition(ca.uhn.fhir.model.dstu2.resource.Condition) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) CodeableConceptDt(ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt) Bundle(ca.uhn.fhir.model.dstu2.resource.Bundle) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 10 with Entry

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

the class Dstu2ResourcesData method getEncounterData.

public Encounter getEncounterData(FhirContext context, IGenericClient client, LaunchDetails launchDetails, Dstu2FhirData dstu2FhirData, Date start, Date end) {
    Encounter encounter;
    // If Encounter Id is present in Launch Details
    if (launchDetails.getEncounterId() != null) {
        encounter = (Encounter) resourceData.getResouceById(launchDetails, client, context, "Encounter", launchDetails.getEncounterId());
        dstu2FhirData.setEncounterCodes(findEncounterCodes(encounter));
    } else {
        // If Encounter Id is not Present in Launch Details Get Encounters by Patient Id
        // and Find the latest Encounter
        Bundle bundle = (Bundle) resourceData.getResourceByPatientId(launchDetails, client, context, "Encounter");
        Map<Encounter, Date> encounterMap = new HashMap<>();
        for (Entry entry : bundle.getEntry()) {
            Encounter encounterEntry = (Encounter) entry.getResource();
            // falling in between Start and End Date
            if (!encounterEntry.getPeriod().isEmpty()) {
                PeriodDt period = encounterEntry.getPeriod();
                if (period.getStart().after(start) || period.getEnd().before(end)) {
                    encounterMap.put(encounterEntry, encounterEntry.getMeta().getLastUpdated());
                }
            // If period is not present using LastUpdatedDate in meta information to filter
            // the Encounter
            } else {
                Date lastUpdatedDateTime = encounterEntry.getMeta().getLastUpdated();
                if (lastUpdatedDateTime.after(start) && lastUpdatedDateTime.before(end)) {
                    encounterMap.put(encounterEntry, encounterEntry.getMeta().getLastUpdated());
                }
            }
        }
        encounter = Collections.max(encounterMap.entrySet(), Map.Entry.comparingByValue()).getKey();
        dstu2FhirData.setEncounterCodes(findEncounterCodes(encounter));
    }
    return encounter;
}
Also used : Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) HashMap(java.util.HashMap) Bundle(ca.uhn.fhir.model.dstu2.resource.Bundle) PeriodDt(ca.uhn.fhir.model.dstu2.composite.PeriodDt) Encounter(ca.uhn.fhir.model.dstu2.resource.Encounter) Date(java.util.Date)

Aggregations

Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)36 Bundle (ca.uhn.fhir.model.dstu2.resource.Bundle)21 Date (java.util.Date)21 ArrayList (java.util.ArrayList)20 CodeableConceptDt (ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt)18 ResourceReferenceDt (ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt)18 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)15 Condition (ca.uhn.fhir.model.dstu2.resource.Condition)11 CodingDt (ca.uhn.fhir.model.dstu2.composite.CodingDt)10 Encounter (org.mitre.synthea.world.concepts.HealthRecord.Encounter)9 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)8 Provider (org.mitre.synthea.world.agents.Provider)8 Encounter (ca.uhn.fhir.model.dstu2.resource.Encounter)7 Observation (ca.uhn.fhir.model.dstu2.resource.Observation)7 Practitioner (ca.uhn.fhir.model.dstu2.resource.Practitioner)7 List (java.util.List)7 FhirContext (ca.uhn.fhir.context.FhirContext)6 DiagnosticReport (ca.uhn.fhir.model.dstu2.resource.DiagnosticReport)6 Organization (ca.uhn.fhir.model.dstu2.resource.Organization)6 IOException (java.io.IOException)6