Search in sources :

Example 81 with Section

use of org.hl7.fhir.utilities.turtle.Turtle.Section in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method generateForChildren.

private void generateForChildren(SchematronWriter sch, String xpath, ElementDefinition ed, StructureDefinition structure, StructureDefinition base) throws IOException {
    // generateForChild(txt, structure, child);
    List<ElementDefinition> children = getChildList(structure, ed);
    String sliceName = null;
    ElementDefinitionSlicingComponent slicing = null;
    for (ElementDefinition child : children) {
        String name = tail(child.getPath());
        if (child.hasSlicing()) {
            sliceName = name;
            slicing = child.getSlicing();
        } else if (!name.equals(sliceName))
            slicing = null;
        ElementDefinition based = getByPath(base, child.getPath());
        boolean doMin = (child.getMin() > 0) && (based == null || (child.getMin() != based.getMin()));
        boolean doMax = !child.getMax().equals("*") && (based == null || (!child.getMax().equals(based.getMax())));
        Slicer slicer = slicing == null ? new Slicer(true) : generateSlicer(child, slicing, structure);
        if (slicer.check) {
            if (doMin || doMax) {
                Section s = sch.section(xpath);
                Rule r = s.rule(xpath);
                if (doMin)
                    r.assrt("count(f:" + name + slicer.criteria + ") >= " + Integer.toString(child.getMin()), name + slicer.name + ": minimum cardinality of '" + name + "' is " + Integer.toString(child.getMin()));
                if (doMax)
                    r.assrt("count(f:" + name + slicer.criteria + ") <= " + child.getMax(), name + slicer.name + ": maximum cardinality of '" + name + "' is " + child.getMax());
            }
        }
    }
    for (ElementDefinitionConstraintComponent inv : ed.getConstraint()) {
        if (inv.hasXpath()) {
            Section s = sch.section(ed.getPath());
            Rule r = s.rule(xpath);
            r.assrt(inv.getXpath(), (inv.hasId() ? inv.getId() + ": " : "") + inv.getHuman() + (inv.hasUserData(IS_DERIVED) ? " (inherited)" : ""));
        }
    }
    for (ElementDefinition child : children) {
        String name = tail(child.getPath());
        generateForChildren(sch, xpath + "/f:" + name, child, structure, base);
    }
}
Also used : ElementDefinitionSlicingComponent(org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionSlicingComponent) ElementDefinition(org.hl7.fhir.dstu2016may.model.ElementDefinition) Rule(org.hl7.fhir.utilities.xml.SchematronWriter.Rule) TypeDerivationRule(org.hl7.fhir.dstu2016may.model.StructureDefinition.TypeDerivationRule) Section(org.hl7.fhir.utilities.xml.SchematronWriter.Section) ElementDefinitionConstraintComponent(org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionConstraintComponent)

Example 82 with Section

use of org.hl7.fhir.utilities.turtle.Turtle.Section in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeCompositionSectionComponent.

protected void composeCompositionSectionComponent(Complex parent, String parentType, String name, Composition.SectionComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "section", name, element, index);
    if (element.hasTitleElement())
        composeString(t, "Composition", "title", element.getTitleElement(), -1);
    if (element.hasCode())
        composeCodeableConcept(t, "Composition", "code", element.getCode(), -1);
    for (int i = 0; i < element.getAuthor().size(); i++) composeReference(t, "Composition", "author", element.getAuthor().get(i), i);
    if (element.hasFocus())
        composeReference(t, "Composition", "focus", element.getFocus(), -1);
    if (element.hasText())
        composeNarrative(t, "Composition", "text", element.getText(), -1);
    if (element.hasModeElement())
        composeEnum(t, "Composition", "mode", element.getModeElement(), -1);
    if (element.hasOrderedBy())
        composeCodeableConcept(t, "Composition", "orderedBy", element.getOrderedBy(), -1);
    for (int i = 0; i < element.getEntry().size(); i++) composeReference(t, "Composition", "entry", element.getEntry().get(i), i);
    if (element.hasEmptyReason())
        composeCodeableConcept(t, "Composition", "emptyReason", element.getEmptyReason(), -1);
    for (int i = 0; i < element.getSection().size(); i++) composeCompositionSectionComponent(t, "Composition", "section", element.getSection().get(i), i);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Example 83 with Section

use of org.hl7.fhir.utilities.turtle.Turtle.Section in project eCRNow by drajer-health.

the class CdaImmunizationGenerator method generateImmunizationSection.

public static String generateImmunizationSection(R4FhirData data, LaunchDetails details) {
    StringBuilder sb = new StringBuilder(2000);
    List<Immunization> imms = data.getImmunizations();
    if (imms != null && !imms.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.IMMUNIZATION_SEC_TEMPLATE_ID));
        sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.IMMUNIZATION_SEC_TEMPLATE_ID, CdaGeneratorConstants.IMMUNIZATION_SEC_TEMPLATE_ID_EXT));
        sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.IMMUNIZATION_SEC_CODE, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.IMMUNIZATION_SEC_NAME));
        // add Title
        sb.append(CdaGeneratorUtils.getXmlForText(CdaGeneratorConstants.TITLE_EL_NAME, CdaGeneratorConstants.IMMUNIZATION_SEC_TITLE));
        // add Narrative Text
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TEXT_EL_NAME));
        // Create Table Header.
        List<String> list = new ArrayList<>();
        list.add(CdaGeneratorConstants.IMM_TABLE_COL_1_TITLE);
        list.add(CdaGeneratorConstants.IMM_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 (Immunization imm : imms) {
            String medDisplayName = CdaGeneratorConstants.UNKNOWN_VALUE;
            if (imm.getVaccineCode() != null && imm.getVaccineCode().getCodingFirstRep() != null && !StringUtils.isEmpty(imm.getVaccineCode().getCodingFirstRep().getDisplay())) {
                medDisplayName = imm.getVaccineCode().getCodingFirstRep().getDisplay();
            }
            String dt = null;
            if (imm.getOccurrenceDateTimeType() != null) {
                dt = imm.getOccurrenceDateTimeType().getValue().toString();
            }
            Map<String, String> bodyvals = new LinkedHashMap<>();
            bodyvals.put(CdaGeneratorConstants.IMM_TABLE_COL_1_BODY_CONTENT, medDisplayName);
            bodyvals.put(CdaGeneratorConstants.IMM_TABLE_COL_2_BODY_CONTENT, dt);
            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));
        for (Immunization imm : imms) {
            // add the Entries.
            sb.append(CdaGeneratorUtils.getXmlForActEntry(CdaGeneratorConstants.TYPE_CODE_DEF));
            // add the immunization Act
            if (imm.getStatus() != ImmunizationStatus.COMPLETED) {
                sb.append(CdaGeneratorUtils.getXmlForActWithNegationInd(CdaGeneratorConstants.MED_ACT_EL_NAME, CdaGeneratorConstants.MED_CLASS_CODE, CdaGeneratorConstants.MOOD_CODE_DEF, "true", true));
            } else {
                sb.append(CdaGeneratorUtils.getXmlForActWithNegationInd(CdaGeneratorConstants.MED_ACT_EL_NAME, CdaGeneratorConstants.MED_CLASS_CODE, CdaGeneratorConstants.MOOD_CODE_DEF, "false", true));
            }
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.IMMUNIZATION_ACTIVITY_TEMPLATE_ID));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.IMMUNIZATION_ACTIVITY_TEMPLATE_ID, CdaGeneratorConstants.IMMUNIZATION_ACTIVITY_TEMPLATE_ID_EXT));
            sb.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), imm.getId()));
            // set status code
            sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.STATUS_CODE_EL_NAME, CdaGeneratorConstants.COMPLETED_STATUS));
            // Set up Effective Time for start and End time.
            if (imm.getOccurrenceDateTimeType() != null) {
                logger.debug("Date Value = {}", imm.getOccurrenceDateTimeType().getValue());
                sb.append(CdaFhirUtilities.getDateTimeTypeXml(imm.getOccurrenceDateTimeType(), CdaGeneratorConstants.EFF_TIME_EL_NAME));
            } else {
                sb.append(CdaGeneratorUtils.getXmlForNullEffectiveTime(CdaGeneratorConstants.EFF_TIME_EL_NAME, CdaGeneratorConstants.NF_NI));
            }
            // add the consumable presentation.
            sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.CONSUMABLE_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForStartElementWithClassCode(CdaGeneratorConstants.MAN_PROD_EL_NAME, CdaGeneratorConstants.MANU_CLASS_CODE));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.IMMUNIZATION_MEDICATION_INFORMATION));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.IMMUNIZATION_MEDICATION_INFORMATION, CdaGeneratorConstants.IMMUNIZATION_MEDICATION_INFORMATION_EXT));
            sb.append(CdaGeneratorUtils.getXmlForIIUsingGuid());
            sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.MANU_MAT_EL_NAME));
            List<CodeableConcept> cds = new ArrayList<>();
            cds.add(imm.getVaccineCode());
            String codeXml = CdaFhirUtilities.getCodeableConceptXmlForCodeSystem(cds, CdaGeneratorConstants.CODE_EL_NAME, false, CdaGeneratorConstants.FHIR_CVX_URL, false);
            if (!codeXml.isEmpty()) {
                sb.append(codeXml);
            } else {
                sb.append(CdaFhirUtilities.getCodeableConceptXml(cds, CdaGeneratorConstants.CODE_EL_NAME, false));
            }
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.MANU_MAT_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.MAN_PROD_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.CONSUMABLE_EL_NAME));
            // End Tags for Entries
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.MED_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(generateEmptyImmunizations());
    }
    return sb.toString();
}
Also used : Immunization(org.hl7.fhir.r4.model.Immunization) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 84 with Section

use of org.hl7.fhir.utilities.turtle.Turtle.Section 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 85 with Section

use of org.hl7.fhir.utilities.turtle.Turtle.Section in project eCRNow by drajer-health.

the class CdaEncounterGenerator method generateEncounterSection.

public static String generateEncounterSection(R4FhirData data, LaunchDetails details) {
    StringBuilder sb = new StringBuilder(2000);
    Encounter encounter = data.getEncounter();
    if (encounter != null) {
        logger.debug("Generating Encounter section");
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.COMP_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.SECTION_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.ENC_SEC_TEMPLATE_ID));
        sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.ENC_SEC_TEMPLATE_ID, CdaGeneratorConstants.ENC_SEC_TEMPLATE_ID_EXT));
        sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.ENC_SEC_CODE, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.ENC_SEC_NAME));
        // Add Title
        sb.append(CdaGeneratorUtils.getXmlForText(CdaGeneratorConstants.TITLE_EL_NAME, CdaGeneratorConstants.ENC_SEC_TITLE));
        // Add Narrative Text
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TEXT_EL_NAME));
        // Create Table Header.
        List<String> list = new ArrayList<>();
        list.add(CdaGeneratorConstants.ENC_TABLE_COL_1_TITLE);
        list.add(CdaGeneratorConstants.ENC_TABLE_COL_2_TITLE);
        sb.append(CdaGeneratorUtils.getXmlForTableHeader(list, CdaGeneratorConstants.TABLE_BORDER, CdaGeneratorConstants.TABLE_WIDTH));
        // Add Body
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
        String actDisplayName = CdaGeneratorConstants.UNKNOWN_VALUE;
        if (encounter.getClass_() != null && encounter.getClass_().getCode() != null && !StringUtils.isEmpty(encounter.getClass_().getDisplay())) {
            logger.debug("Found Encounter Class value, so using it for display");
            actDisplayName = encounter.getClass_().getDisplay();
        } else if (encounter.getTypeFirstRep() != null && encounter.getTypeFirstRep().getCodingFirstRep() != null && !StringUtils.isEmpty(encounter.getTypeFirstRep().getCodingFirstRep().getDisplay())) {
            logger.debug("Did not find Encounter class, but Found Encounter Type value, so using it");
            actDisplayName = encounter.getTypeFirstRep().getCodingFirstRep().getDisplay();
        }
        String dt = CdaGeneratorConstants.UNKNOWN_VALUE;
        if (encounter.getPeriod() != null && encounter.getPeriod().getStartElement() != null) {
            dt = CdaFhirUtilities.getDisplayStringForDateTimeType(encounter.getPeriod().getStartElement());
        } else {
            logger.error(" Period is either null or the Period.DateTime has a null value or null timezone value ");
        }
        Map<String, String> bodyvals = new LinkedHashMap<>();
        bodyvals.put(CdaGeneratorConstants.ENC_TABLE_COL_1_BODY_CONTENT, actDisplayName);
        bodyvals.put(CdaGeneratorConstants.ENC_TABLE_COL_2_BODY_CONTENT, dt);
        String contentRef = CdaGeneratorConstants.ENC_TABLE_COL_1_BODY_CONTENT + Integer.toString(1);
        sb.append(CdaGeneratorUtils.addTableRow(bodyvals, 1));
        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 the Entries.
        sb.append(CdaGeneratorUtils.getXmlForActEntry(CdaGeneratorConstants.TYPE_CODE_DEF));
        sb.append(CdaGeneratorUtils.getXmlForAct(CdaGeneratorConstants.ENC_ACT_EL_NAME, CdaGeneratorConstants.ENC_CLASS_CODE, CdaGeneratorConstants.MOOD_CODE_DEF));
        sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.ENC_ENTRY_TEMPLATE_ID));
        sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.ENC_ENTRY_TEMPLATE_ID, CdaGeneratorConstants.ENC_ENTRY_TEMPLATE_ID_EXT));
        sb.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), encounter.getId()));
        // Add Identifiers
        List<Identifier> ids = encounter.getIdentifier();
        if (ids != null) {
            for (Identifier id : ids) {
                if (id.getSystem() != null && id.getValue() != null) {
                    sb.append(CdaGeneratorUtils.getXmlForII(CdaGeneratorUtils.getRootOid(id.getSystem(), details.getAssigningAuthorityId()), id.getValue()));
                }
            }
        }
        sb.append(getEncounterCodeXml(encounter, contentRef));
        sb.append(CdaFhirUtilities.getPeriodXml(encounter.getPeriod(), CdaGeneratorConstants.EFF_TIME_EL_NAME));
        String encDiagXml = generateEncounterDiagnosisXml(data, details);
        if (encDiagXml != null && !encDiagXml.isEmpty()) {
            logger.debug("Adding Encounter Diagnosis to the Encounter Section");
            sb.append(encDiagXml);
        }
        // End Entry Tags
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ENC_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(generateEmptyEncounterSection());
    }
    return sb.toString();
}
Also used : Identifier(org.hl7.fhir.r4.model.Identifier) ArrayList(java.util.ArrayList) Encounter(org.hl7.fhir.r4.model.Encounter) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ArrayList (java.util.ArrayList)21 Element (org.w3c.dom.Element)11 IOException (java.io.IOException)10 LinkedHashMap (java.util.LinkedHashMap)9 Section (org.hl7.fhir.utilities.xml.SchematronWriter.Section)9 POCDMT000002UK01Section (uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Section)8 Rule (org.hl7.fhir.utilities.xml.SchematronWriter.Rule)7 POCDMT000002UK01Component3 (uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component3)7 Reference (org.hl7.fhir.dstu3.model.Reference)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 SectionComponent (org.hl7.fhir.dstu3.model.Composition.SectionComponent)5 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 HashMap (java.util.HashMap)4 NotImplementedException (org.apache.commons.lang3.NotImplementedException)4 IdType (org.hl7.fhir.dstu3.model.IdType)4 Section (org.hl7.fhir.utilities.turtle.Turtle.Section)4 Subject (org.hl7.fhir.utilities.turtle.Turtle.Subject)4 POCDMT000002UK01Component5 (uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component5)4 FileNotFoundException (java.io.FileNotFoundException)3