Search in sources :

Example 16 with Observation

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

the class TriggerQueryDstu2Bundle method createDSTU2Bundle.

public Bundle createDSTU2Bundle(LaunchDetails launchDetails, Dstu2FhirData dstu2FhirData, Date start, Date end) {
    Bundle bundle = new Bundle();
    logger.info("Initializing FHIR Context for Version:::: {}", launchDetails.getFhirVersion());
    FhirContext context = fhirContextInitializer.getFhirContext(launchDetails.getFhirVersion());
    logger.info("Initializing Client");
    IGenericClient client = fhirContextInitializer.createClient(context, launchDetails);
    // GET Patient Details and Add to Bundle
    try {
        logger.info("Get Patient Data");
        Patient patient = (Patient) fhirContextInitializer.getResouceById(launchDetails, client, context, "Patient", launchDetails.getLaunchPatientId());
        Entry patientEntry = new Entry();
        patientEntry.setResource(patient);
        bundle.addEntry(patientEntry);
    } catch (Exception e) {
        logger.error("Error in getting Patient Data", e);
    }
    // Step 1: Get Encounters for Patient based on encId. (Create a method to get
    // encounters)
    // If encId is null, find encounters for patient within the start and end time
    // provided.
    // Add to the bundle.
    // As you are adding to the bundle within Fhir Data, add the codeable concept
    // also to the list of encounterCodes.
    Encounter encounter = null;
    try {
        logger.info("Get Encounter Data");
        encounter = dstu2ResourcesData.getEncounterData(context, client, launchDetails, dstu2FhirData, start, end);
        if (encounter.getParticipant() != null) {
            List<Participant> participants = encounter.getParticipant();
            for (Participant participant : participants) {
                if (participant.getIndividual() != null) {
                    ResourceReferenceDt practitionerReference = participant.getIndividual();
                    Practitioner practitioner = (Practitioner) fhirContextInitializer.getResouceById(launchDetails, client, context, "Practitioner", practitionerReference.getReference().getIdPart());
                    Entry practitionerEntry = new Entry().setResource(practitioner);
                    bundle.addEntry(practitionerEntry);
                }
            }
        }
        if (encounter.getServiceProvider() != null) {
            ResourceReferenceDt organizationReference = encounter.getServiceProvider();
            Organization organization = (Organization) fhirContextInitializer.getResouceById(launchDetails, client, context, "Organization", organizationReference.getReference().getIdPart());
            Entry organizationEntry = new Entry().setResource(organization);
            bundle.addEntry(organizationEntry);
        }
        if (encounter.getLocation() != null) {
            List<Location> enocunterLocations = encounter.getLocation();
            for (Location location : enocunterLocations) {
                if (location.getLocation() != null) {
                    ResourceReferenceDt locationReference = location.getLocation();
                    ca.uhn.fhir.model.dstu2.resource.Location locationResource = (ca.uhn.fhir.model.dstu2.resource.Location) fhirContextInitializer.getResouceById(launchDetails, client, context, "Location", locationReference.getReference().getIdPart());
                    Entry locationEntry = new Entry().setResource(locationResource);
                    bundle.addEntry(locationEntry);
                }
            }
        }
        Entry encounterEntry = new Entry().setResource(encounter);
        bundle.addEntry(encounterEntry);
    } catch (Exception e) {
        logger.error("Error in getting Encounter Data", e);
    }
    // also to the list of ConditionCodes.
    try {
        logger.info("Get Condition Data");
        List<Condition> conditionsList = dstu2ResourcesData.getConditionData(context, client, launchDetails, dstu2FhirData, encounter, start, end);
        logger.info("Filtered ConditionsList----> {}", conditionsList.size());
        dstu2FhirData.setConditions(conditionsList);
        for (Condition condition : conditionsList) {
            Entry conditionsEntry = new Entry().setResource(condition);
            bundle.addEntry(conditionsEntry);
        }
    } catch (Exception e) {
        logger.error("Error in getting Condition Data", e);
    }
    // also to the list of labResultCodes.
    try {
        logger.info("Get Observation Data");
        List<Observation> observationList = dstu2ResourcesData.getObservationData(context, client, launchDetails, dstu2FhirData, encounter, start, end);
        logger.info("Filtered Observations----> {}", observationList.size());
        dstu2FhirData.setLabResults(observationList);
        for (Observation observation : observationList) {
            Entry observationsEntry = new Entry().setResource(observation);
            bundle.addEntry(observationsEntry);
        }
    } catch (Exception e) {
        logger.error("Error in getting Observation Data", e);
    }
    // also to the list of medicationCodes.
    try {
        logger.info("Get MedicationAdministration Data");
        List<MedicationAdministration> medAdministrationsList = dstu2ResourcesData.getMedicationAdministrationData(context, client, launchDetails, dstu2FhirData, encounter, start, end);
        logger.info("Filtered MedicationAdministration-----------> {}", medAdministrationsList.size());
        dstu2FhirData.setMedicationAdministrations(medAdministrationsList);
        for (MedicationAdministration medAdministration : medAdministrationsList) {
            if (!medAdministration.getMedication().isEmpty() && medAdministration.getMedication() != null) {
                if (medAdministration.getMedication() instanceof ResourceReferenceDt) {
                    BaseResourceReferenceDt medRef = (BaseResourceReferenceDt) medAdministration.getMedication();
                    String medReference = medRef.getReference().getValue();
                    if (medReference.startsWith("#")) {
                        BaseContainedDt medAdministrationContained = medAdministration.getContained();
                        List<Medication> containedResources = (List<Medication>) medAdministrationContained.getContainedResources();
                        if (containedResources.stream().anyMatch(resource -> resource.getIdElement().getValue().equals(medReference))) {
                            logger.info("Medication Resource exists in MedicationAdministration.contained. So no need to add again in Bundle.");
                        }
                    } else {
                        logger.info("Medication Reference Found=============>");
                        Medication medication = dstu2ResourcesData.getMedicationData(context, client, launchDetails, dstu2FhirData, medReference);
                        Entry medicationEntry = new Entry().setResource(medication);
                        bundle.addEntry(medicationEntry);
                        if (medication != null) {
                            List<Medication> medicationList = new ArrayList<>();
                            medicationList.add(medication);
                            dstu2FhirData.setMedicationList(medicationList);
                        }
                    }
                }
            }
            Entry medAdministrationEntry = new Entry().setResource(medAdministration);
            bundle.addEntry(medAdministrationEntry);
        }
    } catch (Exception e) {
        logger.error("Error in getting the MedicationAdministration Data", e);
    }
    try {
        logger.info("Get DiagnosticOrder Data");
        List<DiagnosticOrder> diagnosticOrdersList = dstu2ResourcesData.getDiagnosticOrderData(context, client, launchDetails, dstu2FhirData, encounter, start, end);
        logger.info("Filtered DiagnosticOrders-----------> {}", diagnosticOrdersList.size());
        dstu2FhirData.setDiagOrders(diagnosticOrdersList);
        for (DiagnosticOrder diagnosticOrder : diagnosticOrdersList) {
            Entry diagnosticOrderEntry = new Entry().setResource(diagnosticOrder);
            bundle.addEntry(diagnosticOrderEntry);
        }
    } catch (Exception e) {
        logger.error("Error in getting the DiagnosticOrder Data", e);
    }
    try {
        List<DiagnosticReport> diagnosticReportList = dstu2ResourcesData.getDiagnosticReportData(context, client, launchDetails, dstu2FhirData, encounter, start, end);
        logger.info("Filtered DiagnosticReports-----------> {}", diagnosticReportList.size());
        dstu2FhirData.setDiagReports(diagnosticReportList);
        for (DiagnosticReport diagnosticReport : diagnosticReportList) {
            Entry diagnosticReportEntry = new Entry().setResource(diagnosticReport);
            bundle.addEntry(diagnosticReportEntry);
        }
    } catch (Exception e) {
        logger.error("Error in getting the DiagnosticReport Data", e);
    }
    // Setting bundle to FHIR Data
    logger.info("------------------------------CodeableConcept Codes------------------------------");
    logger.info("Encounter Codes Size=====> {}", dstu2FhirData.getEncounterCodes().size());
    logger.info("Conditions Codes Size=====> {}", dstu2FhirData.getConditionCodes().size());
    logger.info("Observation Codes Size=====> {}", dstu2FhirData.getLabResultCodes().size());
    logger.info("Medication Codes Size=====> {}", dstu2FhirData.getMedicationCodes().size());
    logger.info("DiagnosticReport Codes Size=====> {}", dstu2FhirData.getDiagnosticReportCodes().size());
    logger.info("DiagnosticOrders Codes Size=====> {}", dstu2FhirData.getDiagnosticOrderCodes().size());
    String fileName = ActionRepo.getInstance().getLogFileDirectory() + "/TriggerQueryDSTU2Bundle-" + launchDetails.getLaunchPatientId() + ".json";
    ApplicationUtils.saveDataToFile(context.newJsonParser().encodeResourceToString(bundle), fileName);
    return bundle;
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) BaseResourceReferenceDt(ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt) Organization(ca.uhn.fhir.model.dstu2.resource.Organization) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ArrayList(java.util.ArrayList) DiagnosticReport(ca.uhn.fhir.model.dstu2.resource.DiagnosticReport) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) Medication(ca.uhn.fhir.model.dstu2.resource.Medication) Encounter(ca.uhn.fhir.model.dstu2.resource.Encounter) ArrayList(java.util.ArrayList) List(java.util.List) Condition(ca.uhn.fhir.model.dstu2.resource.Condition) BaseContainedDt(ca.uhn.fhir.model.base.composite.BaseContainedDt) Bundle(ca.uhn.fhir.model.dstu2.resource.Bundle) Patient(ca.uhn.fhir.model.dstu2.resource.Patient) DiagnosticOrder(ca.uhn.fhir.model.dstu2.resource.DiagnosticOrder) BaseResourceReferenceDt(ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt) Practitioner(ca.uhn.fhir.model.dstu2.resource.Practitioner) Participant(ca.uhn.fhir.model.dstu2.resource.Encounter.Participant) Observation(ca.uhn.fhir.model.dstu2.resource.Observation) MedicationAdministration(ca.uhn.fhir.model.dstu2.resource.MedicationAdministration) Location(ca.uhn.fhir.model.dstu2.resource.Encounter.Location)

Example 17 with Observation

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

the class Dstu2ResourcesData method getObservationData.

public List<Observation> getObservationData(FhirContext context, IGenericClient client, LaunchDetails launchDetails, Dstu2FhirData dstu2FhirData, Encounter encounter, Date start, Date end) {
    Bundle bundle = (Bundle) resourceData.getObservationByPatientId(launchDetails, client, context, "Observation", "laboratory");
    List<Observation> observations = new ArrayList<>();
    List<CodeableConceptDt> observationCodes = new ArrayList<>();
    // Filter Observations based on Encounter Reference
    if (encounter != null && !encounter.getId().getValue().isEmpty()) {
        for (Entry entry : bundle.getEntry()) {
            Observation observation = (Observation) entry.getResource();
            if (!observation.getEncounter().isEmpty()) {
                if (observation.getEncounter().getReference().getIdPart().equals(encounter.getIdElement().getIdPart())) {
                    observations.add(observation);
                    observationCodes.addAll(findLaboratoryCodes(observation));
                }
            }
        }
    // If Encounter Id is not present using start and end dates to filter
    // Observations
    } else {
        for (Entry entry : bundle.getEntry()) {
            Observation observation = (Observation) entry.getResource();
            // Checking If Issued Date is present in Observation resource
            if (observation.getIssued() != null) {
                if (observation.getIssued().after(start) && observation.getIssued().before(end)) {
                    observations.add(observation);
                    observationCodes.addAll(findLaboratoryCodes(observation));
                }
            // If Issued date is not present, Checking for Effective Date
            } else if (!observation.getEffective().isEmpty()) {
                Date effectiveDate = (Date) observation.getEffective();
                if (effectiveDate.after(start) && effectiveDate.before(end)) {
                    observations.add(observation);
                    observationCodes.addAll(findLaboratoryCodes(observation));
                }
            // If Issued and Effective Date are not present looking for LastUpdatedDate
            } else {
                Date lastUpdatedDateTime = observation.getMeta().getLastUpdated();
                if (lastUpdatedDateTime.after(start) && lastUpdatedDateTime.before(end)) {
                    observations.add(observation);
                    observationCodes.addAll(findLaboratoryCodes(observation));
                }
            }
        }
    }
    dstu2FhirData.setLabResultCodes(observationCodes);
    return observations;
}
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) Observation(ca.uhn.fhir.model.dstu2.resource.Observation) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 18 with Observation

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

the class Dstu2ResourcesData method getPregnancyObservationData.

public List<Observation> getPregnancyObservationData(FhirContext context, IGenericClient client, LaunchDetails launchDetails, Dstu2FhirData dstu2FhirData, Encounter encounter, Date start, Date end) {
    Bundle bundle = (Bundle) resourceData.getResourceByPatientIdAndCode(launchDetails, client, context, "Observation", QueryConstants.PREGNANCY_CODE, QueryConstants.LOINC_CODE_SYSTEM);
    List<Observation> observations = filterObservation(bundle, encounter, start, end);
    return observations;
}
Also used : Bundle(ca.uhn.fhir.model.dstu2.resource.Bundle) Observation(ca.uhn.fhir.model.dstu2.resource.Observation)

Example 19 with Observation

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

the class Dstu2CdaProblemGenerator method generateProblemSection.

public static String generateProblemSection(Dstu2FhirData data, LaunchDetails details) {
    StringBuilder sb = new StringBuilder(2000);
    List<Condition> conds = data.getConditions();
    if (conds != null && conds.size() > 0) {
        // Generate the component and section end tags
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.COMP_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.SECTION_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.PROB_SEC_TEMPLATE_ID));
        sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.PROB_SEC_TEMPLATE_ID, CdaGeneratorConstants.PROB_SEC_TEMPLATE_ID_EXT));
        sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.PROB_SEC_CODE, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.PROB_SEC_NAME));
        // Add Title
        sb.append(CdaGeneratorUtils.getXmlForText(CdaGeneratorConstants.TITLE_EL_NAME, CdaGeneratorConstants.PROB_SEC_TITLE));
        // Add Narrative Text
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TEXT_EL_NAME));
        // Create Table Header.
        List<String> list = new ArrayList<String>();
        list.add(CdaGeneratorConstants.PROB_TABLE_COL_1_TITLE);
        list.add(CdaGeneratorConstants.PROB_TABLE_COL_2_TITLE);
        sb.append(CdaGeneratorUtils.getXmlForTableHeader(list, CdaGeneratorConstants.TABLE_BORDER, CdaGeneratorConstants.TABLE_WIDTH));
        // Add Table Body
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
        // Add Body Rows
        int rowNum = 1;
        for (Condition prob : conds) {
            String probDisplayName = CdaGeneratorConstants.UNKNOWN_VALUE;
            if (prob.getCode() != null && prob.getCode().getCodingFirstRep() != null && !StringUtils.isEmpty(prob.getCode().getCodingFirstRep().getDisplay())) {
                probDisplayName = prob.getCode().getCodingFirstRep().getDisplay();
            }
            Map<String, String> bodyvals = new HashMap<String, String>();
            bodyvals.put(CdaGeneratorConstants.PROB_TABLE_COL_1_BODY_CONTENT, probDisplayName);
            if (prob.getClinicalStatus() != null && (prob.getClinicalStatus().contentEquals(ConditionClinicalStatusCodesEnum.ACTIVE.getCode()) || prob.getClinicalStatus().contentEquals(ConditionClinicalStatusCodesEnum.RELAPSE.getCode()))) {
                bodyvals.put(CdaGeneratorConstants.PROB_TABLE_COL_2_BODY_CONTENT, CdaGeneratorConstants.TABLE_ACTIVE_STATUS);
            } else {
                bodyvals.put(CdaGeneratorConstants.PROB_TABLE_COL_2_BODY_CONTENT, CdaGeneratorConstants.TABLE_RESOLVED_STATUS);
            }
            sb.append(CdaGeneratorUtils.addTableRow(bodyvals, rowNum));
            // TODO: ++rowNum or rowNum++
            ++rowNum;
        }
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
        // End Table.
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TEXT_EL_NAME));
        Boolean triggerCodesAdded = false;
        for (Condition pr : conds) {
            // Add the Entries.
            sb.append(CdaGeneratorUtils.getXmlForActEntry(CdaGeneratorConstants.TYPE_CODE_DEF));
            // Add the problem Concern Act
            sb.append(CdaGeneratorUtils.getXmlForAct(CdaGeneratorConstants.ACT_EL_NAME, CdaGeneratorConstants.ACT_CLASS_CODE, CdaGeneratorConstants.MOOD_CODE_DEF));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.PROB_CONCERN_TEMPLATE_ID));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.PROB_CONCERN_TEMPLATE_ID, CdaGeneratorConstants.PROB_CONCERN_TEMPLATE_ID_EXT));
            sb.append(CdaGeneratorUtils.getXmlForIIUsingGuid());
            sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.PROB_CONC_ACT_CODE, CdaGeneratorConstants.HL7_ACT_CLASS_OID, CdaGeneratorConstants.HL7_ACT_CLASS_NAME, CdaGeneratorConstants.PROB_CONC_ACT_NAME));
            if (pr.getClinicalStatus() != null && (pr.getClinicalStatus().contentEquals(ConditionClinicalStatusCodesEnum.ACTIVE.getCode()) || pr.getClinicalStatus().contentEquals(ConditionClinicalStatusCodesEnum.RELAPSE.getCode()))) {
                sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.STATUS_CODE_EL_NAME, CdaGeneratorConstants.ACTIVE_STATUS));
            } else {
                sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.STATUS_CODE_EL_NAME, CdaGeneratorConstants.COMPLETED_STATUS));
            }
            Pair<Date, TimeZone> onset = null;
            Pair<Date, TimeZone> abatement = null;
            Pair<Date, TimeZone> recorded = null;
            if (pr.getOnset() != null && pr.getOnset() instanceof DateTimeDt) {
                DateTimeDt dt = (DateTimeDt) pr.getOnset();
                onset = new Pair<>(dt.getValue(), dt.getTimeZone());
            }
            if (pr.getAbatement() != null && pr.getAbatement() instanceof DateTimeDt) {
                DateTimeDt dt = (DateTimeDt) pr.getAbatement();
                abatement = new Pair<>(dt.getValue(), dt.getTimeZone());
            }
            if (pr.getDateRecordedElement() != null) {
                recorded = new Pair<>(pr.getDateRecorded(), null);
            }
            sb.append(CdaGeneratorUtils.getXmlForIVLWithTS(CdaGeneratorConstants.EFF_TIME_EL_NAME, recorded, abatement, true));
            // Add the Problem Observation
            sb.append(CdaGeneratorUtils.getXmlForEntryRelationship(CdaGeneratorConstants.ENTRY_REL_SUBJ_CODE));
            sb.append(CdaGeneratorUtils.getXmlForAct(CdaGeneratorConstants.OBS_ACT_EL_NAME, CdaGeneratorConstants.OBS_CLASS_CODE, CdaGeneratorConstants.MOOD_CODE_DEF));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.PROB_OBS_TEMPLATE_ID));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.PROB_OBS_TEMPLATE_ID, CdaGeneratorConstants.PROB_OBS_TEMPALTE_ID_EXT));
            sb.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), pr.getId().getValue()));
            sb.append(CdaGeneratorUtils.getXmlForCDWithoutEndTag(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.DIAGNOSIS_SNOMED, CdaGeneratorConstants.SNOMED_CODESYSTEM_OID, CdaGeneratorConstants.SNOMED_CODESYSTEM_NAME, CdaGeneratorConstants.DIAGNOSIS_DISPLAY_NAME));
            sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.TRANSLATION_EL_NAME, CdaGeneratorConstants.DIAGNOSIS_LOINC, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.DIAGNOSIS_DISPLAY_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.CODE_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.STATUS_CODE_EL_NAME, CdaGeneratorConstants.COMPLETED_STATUS));
            sb.append(CdaGeneratorUtils.getXmlForIVLWithTS(CdaGeneratorConstants.EFF_TIME_EL_NAME, onset, abatement, true));
            List<CodeableConceptDt> cds = new ArrayList<CodeableConceptDt>();
            cds.add(pr.getCode());
            sb.append(Dstu2CdaFhirUtilities.getCodeableConceptXml(cds, CdaGeneratorConstants.VAL_EL_NAME, true));
            // End Tag for Entry Relationship
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.OBS_ACT_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ENTRY_REL_EL_NAME));
            if (!triggerCodesAdded) {
                sb.append(addTriggerCodes(data, details, pr, onset, abatement));
                triggerCodesAdded = true;
            }
            // End Tags for Entries
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ACT_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ENTRY_EL_NAME));
        }
        // Complete the section end tags.
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.SECTION_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.COMP_EL_NAME));
    } else {
        sb.append(generateEmptyProblemSection());
    }
    return sb.toString();
}
Also used : Condition(ca.uhn.fhir.model.dstu2.resource.Condition) CodeableConceptDt(ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(java.util.Date) TimeZone(java.util.TimeZone) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt)

Example 20 with Observation

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

the class Dstu2CdaSocialHistoryGenerator method generateSocialHistorySection.

public static String generateSocialHistorySection(Dstu2FhirData data, LaunchDetails details) {
    StringBuilder sb = new StringBuilder(2000);
    // Will have to wait to discuss with vendors on Travel History, Pregnancy, and Birth Sex
    // Observations.
    // Then we can generte the entries. Till then it will be empty section.
    CodeDt birthSex = Dstu2CdaFhirUtilities.getCodeExtension(data.getPatient().getUndeclaredExtensions(), CdaGeneratorConstants.FHIR_ARGO_BIRTHSEX_EXT_URL);
    List<Observation> pregObs = data.getPregnancyObs();
    List<Observation> travelHistory = data.getTravelObs();
    if (birthSex != null || (pregObs != null && pregObs.size() > 0) || (travelHistory != null && travelHistory.size() > 0)) {
        sb.append(generateSocialHistorySectionHeader(""));
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TEXT_EL_NAME));
        // Create Table Header.
        List<String> list = new ArrayList<String>();
        list.add(CdaGeneratorConstants.SOC_HISTORY_TABLE_COL_1_TITLE);
        list.add(CdaGeneratorConstants.SOC_HISTORY_TABLE_COL_2_TITLE);
        sb.append(CdaGeneratorUtils.getXmlForTableHeader(list, CdaGeneratorConstants.TABLE_BORDER, CdaGeneratorConstants.TABLE_WIDTH));
        // Add Table Body
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
        String birthSexXml = "";
        String pregObsXml = "";
        String travelHistoryXml = "";
        if (birthSex != null) {
            Map<String, String> bodyvals = new HashMap<String, String>();
            bodyvals.put(CdaGeneratorConstants.SOC_HISTORY_TABLE_COL_1_BODY_CONTENT, CdaGeneratorConstants.BIRTH_SEX_DISPLAY);
            bodyvals.put(CdaGeneratorConstants.SOC_HISTORY_TABLE_COL_2_BODY_CONTENT, Dstu2CdaFhirUtilities.getStringForIDataType(birthSex));
            sb.append(CdaGeneratorUtils.addTableRow(bodyvals, 0));
            birthSexXml = generateBirthSexEntry(data, details, birthSex);
        }
        if (pregObs != null && pregObs.size() > 0) {
            logger.error(" Pregnancy Status Observation Found , translation not implemented ");
        // These are not available in FHIR right now reliably, so nothing to process until further
        // discussion with vendors.
        // Setup Table Text Entries
        // Setup XML Entries
        }
        if (travelHistory != null && travelHistory.size() > 0) {
            logger.error(" Pregnancy Status Observation Found , translation not implemented ");
        // These are not available in FHIR right now reliably, so nothing to process until further
        // discussion with vendors.
        // Setup Table Text Entries
        // Setup XML Entries
        }
        // Close the Table.
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TEXT_EL_NAME));
        // Add entry
        if (!StringUtils.isEmpty(birthSexXml)) {
            sb.append(birthSexXml);
        }
        if (!StringUtils.isEmpty(pregObsXml)) {
            sb.append(birthSexXml);
        }
        if (!StringUtils.isEmpty(travelHistoryXml)) {
            sb.append(birthSexXml);
        }
        sb.append(generateSocialHistorySectionEndHeader());
    } else {
        sb.append(generateEmptySocialHistorySection());
    }
    return sb.toString();
}
Also used : CodeDt(ca.uhn.fhir.model.primitive.CodeDt) HashMap(java.util.HashMap) Observation(ca.uhn.fhir.model.dstu2.resource.Observation) ArrayList(java.util.ArrayList)

Aggregations

Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)12 Observation (ca.uhn.fhir.model.dstu2.resource.Observation)9 Bundle (ca.uhn.fhir.model.dstu2.resource.Bundle)8 CodeableConceptDt (ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt)7 ArrayList (java.util.ArrayList)7 Condition (ca.uhn.fhir.model.dstu2.resource.Condition)6 CodingDt (ca.uhn.fhir.model.dstu2.composite.CodingDt)5 ResourceReferenceDt (ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt)5 DiagnosticReport (ca.uhn.fhir.model.dstu2.resource.DiagnosticReport)5 List (java.util.List)5 Encounter (org.mitre.synthea.world.concepts.HealthRecord.Encounter)4 FhirContext (ca.uhn.fhir.context.FhirContext)3 DiagnosticOrder (ca.uhn.fhir.model.dstu2.resource.DiagnosticOrder)3 Encounter (ca.uhn.fhir.model.dstu2.resource.Encounter)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 WireMock (com.github.tomakehurst.wiremock.client.WireMock)3 WireMockRule (com.github.tomakehurst.wiremock.junit.WireMockRule)3 File (java.io.File)3