Search in sources :

Example 46 with COMPLETED

use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project eCRNow by drajer-health.

the class CdaMedicationGenerator method generateMedicationSection.

public static String generateMedicationSection(R4FhirData data, LaunchDetails details) {
    StringBuilder sb = new StringBuilder(2000);
    List<Medication> medList = data.getMedicationList();
    List<MedicationStatement> meds = data.getMedications();
    List<MedicationAdministration> medAdms = data.getMedicationAdministrations();
    List<MedicationRequest> medReqs = getValidMedicationRequests(data, medList);
    if ((meds != null && !meds.isEmpty()) || (medAdms != null && !medAdms.isEmpty()) || (medReqs != null && !medReqs.isEmpty())) {
        // 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.MED_ADM_SEC_TEMPLATE_ID));
        sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.MED_ADM_SEC_TEMPLATE_ID, CdaGeneratorConstants.MED_SEC_TEMPLATE_ID_EXT));
        sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.MED_ADM_SEC_CODE, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.MED_ADM_SEC_NAME));
        // add Title
        sb.append(CdaGeneratorUtils.getXmlForText(CdaGeneratorConstants.TITLE_EL_NAME, CdaGeneratorConstants.MED_ADM_SEC_TITLE));
        // add Narrative Text
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TEXT_EL_NAME));
        // Create Table Header.
        List<String> list = new ArrayList<>();
        list.add(CdaGeneratorConstants.MED_TABLE_COL_1_TITLE);
        list.add(CdaGeneratorConstants.MED_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;
        StringBuilder medEntries = new StringBuilder();
        for (MedicationStatement med : meds) {
            String medDisplayName = CdaGeneratorConstants.UNKNOWN_VALUE;
            if (med.getMedication() != null) {
                medDisplayName = CdaFhirUtilities.getStringForMedicationType(med);
            }
            String dt = null;
            if (med.getEffective() != null) {
                dt = CdaFhirUtilities.getStringForType(med.getEffective());
            }
            Map<String, String> bodyvals = new LinkedHashMap<>();
            bodyvals.put(CdaGeneratorConstants.MED_TABLE_COL_1_BODY_CONTENT, medDisplayName);
            bodyvals.put(CdaGeneratorConstants.MED_TABLE_COL_2_BODY_CONTENT, dt);
            sb.append(CdaGeneratorUtils.addTableRow(bodyvals, rowNum));
            // TODO: ++rowNum or rowNum++
            ++rowNum;
            // Create the Med Entry for the Medication Statement.
            String medstatus = "";
            if (med.getStatus() != null) {
                medstatus = CdaFhirUtilities.getStatusCodeForFhirMedStatusCodes(med.getStatus().toString());
            } else {
                medstatus = COMPLETED;
            }
            Dosage dosage = null;
            if (med.getDosageFirstRep() != null)
                dosage = med.getDosageFirstRep();
            medEntries.append(getEntryForMedication(med.getId(), med.getMedication(), med.getEffective(), medstatus, dosage, details, null, null, CdaGeneratorConstants.MOOD_CODE_DEF, med));
        }
        // Add Medication Administration
        for (MedicationAdministration medAdm : medAdms) {
            String medDisplayName = CdaGeneratorConstants.UNKNOWN_VALUE;
            if (medAdm.getMedication() != null) {
                medDisplayName = CdaFhirUtilities.getStringForMedicationType(medAdm);
            }
            String dt = null;
            if (medAdm.getEffective() != null) {
                dt = CdaFhirUtilities.getStringForType(medAdm.getEffective());
            }
            Map<String, String> bodyvals = new HashMap<>();
            bodyvals.put(CdaGeneratorConstants.MED_TABLE_COL_1_BODY_CONTENT, medDisplayName);
            bodyvals.put(CdaGeneratorConstants.MED_TABLE_COL_2_BODY_CONTENT, dt);
            sb.append(CdaGeneratorUtils.addTableRow(bodyvals, rowNum));
            // TODO: ++rowNum or rowNum++
            ++rowNum;
            // Create the Med Entry for the Medication Statement.
            String medstatus = "";
            if (medAdm.getStatus() != null) {
                medstatus = CdaFhirUtilities.getStatusCodeForFhirMedStatusCodes(medAdm.getStatus());
            } else {
                medstatus = COMPLETED;
            }
            Quantity dose = null;
            if (medAdm.getDosage() != null && medAdm.getDosage().getDose() != null)
                dose = medAdm.getDosage().getDose();
            medEntries.append(getEntryForMedication(medAdm.getId(), medAdm.getMedication(), medAdm.getEffective(), medstatus, null, details, dose, null, CdaGeneratorConstants.MOOD_CODE_DEF, medAdm));
        }
        // Add Medication Requests
        for (MedicationRequest medReq : medReqs) {
            String medDisplayName = CdaGeneratorConstants.UNKNOWN_VALUE;
            if (medReq.getMedication() != null) {
                medDisplayName = CdaFhirUtilities.getStringForMedicationType(medReq);
            }
            DateTimeType startDate = null;
            Dosage dosage = null;
            if (medReq.getDosageInstructionFirstRep() != null && medReq.getDosageInstructionFirstRep().getTiming() != null) {
                dosage = medReq.getDosageInstructionFirstRep();
                Timing t = medReq.getDosageInstructionFirstRep().getTiming();
                if (t != null && t.getRepeat() != null && t.getRepeat().getBoundsPeriod() != null) {
                    startDate = t.getRepeat().getBoundsPeriod().getStartElement();
                }
            }
            String dt = CdaGeneratorConstants.UNKNOWN_VALUE;
            if (startDate != null) {
                dt = CdaFhirUtilities.getDisplayStringForDateTimeType(startDate);
            } else {
                logger.error(" Dosage field does not have a valid period either due to datetime or timezone being null ");
            }
            Map<String, String> bodyvals = new HashMap<>();
            bodyvals.put(CdaGeneratorConstants.MED_TABLE_COL_1_BODY_CONTENT, medDisplayName);
            bodyvals.put(CdaGeneratorConstants.MED_TABLE_COL_2_BODY_CONTENT, dt);
            sb.append(CdaGeneratorUtils.addTableRow(bodyvals, rowNum));
            // TODO: ++rowNum or rowNum++
            ++rowNum;
            // Create the Med Entry for the Medication Request.
            String medstatus = "";
            String moodCode = CdaGeneratorConstants.MOOD_CODE_INT;
            if (medReq.getStatus() != null) {
                medstatus = CdaFhirUtilities.getStatusCodeForFhirMedStatusCodes(medReq.getStatus().toString());
                if (medstatus.equalsIgnoreCase(COMPLETED)) {
                    moodCode = CdaGeneratorConstants.MOOD_CODE_DEF;
                }
            } else {
                medstatus = "active";
            }
            medEntries.append(getEntryForMedication(medReq.getId(), medReq.getMedication(), null, medstatus, dosage, details, null, startDate, moodCode, medReq));
        }
        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));
        // Add Medication Entries
        sb.append(medEntries);
        // Complete the section end tags.
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.SECTION_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.COMP_EL_NAME));
    } else {
        sb.append(generateEmptyMedications());
    }
    return sb.toString();
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) Quantity(org.hl7.fhir.r4.model.Quantity) Dosage(org.hl7.fhir.r4.model.Dosage) LinkedHashMap(java.util.LinkedHashMap) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Medication(org.hl7.fhir.r4.model.Medication) MedicationAdministration(org.hl7.fhir.r4.model.MedicationAdministration) Timing(org.hl7.fhir.r4.model.Timing) MedicationStatement(org.hl7.fhir.r4.model.MedicationStatement)

Example 47 with COMPLETED

use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project eCRNow by drajer-health.

the class ApplicationUtils method readBundleFromFile.

public Bundle readBundleFromFile(String filename) {
    logger.info("About to read File {}", filename);
    Bundle bundle = null;
    try (InputStream in = new FileInputStream(new File(filename))) {
        logger.info("Reading File ");
        bundle = jsonParser.parseResource(Bundle.class, in);
        logger.info("Completed Reading File");
    } catch (Exception e) {
        logger.error("Exception Reading File", e);
    }
    return bundle;
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) ObjectDeletedException(org.hibernate.ObjectDeletedException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Aggregations

Immunization (org.hl7.fhir.r4.model.Immunization)13 Date (java.util.Date)9 ArrayList (java.util.ArrayList)8 InputStream (java.io.InputStream)7 Reference (org.hl7.fhir.dstu3.model.Reference)7 Test (org.junit.jupiter.api.Test)7 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)6 Collectors (java.util.stream.Collectors)5 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)5 Reference (org.hl7.fhir.r4.model.Reference)5 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)5 FhirContext (ca.uhn.fhir.context.FhirContext)4 Search (ca.uhn.fhir.rest.annotation.Search)4 Trace (com.newrelic.api.agent.Trace)4 File (java.io.File)4 List (java.util.List)4 BundleEntryComponent (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)4 Coding (org.hl7.fhir.dstu3.model.Coding)4 Bundle (org.hl7.fhir.r4.model.Bundle)4 CodeType (org.hl7.fhir.r4.model.CodeType)4