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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations