Search in sources :

Example 96 with Narrative

use of org.hl7.fhir.r5.model.Narrative in project pathling by aehrc.

the class TestData method newCondition.

/**
 * Returns a FHIR Condition for testing purposes.
 */
public static Condition newCondition() {
    final Condition condition = new Condition();
    // Condition based on example from FHIR:
    // https://www.hl7.org/fhir/condition-example.json.html
    condition.setId("example");
    condition.setLanguage("en_US");
    // Narrative text
    final Narrative narrative = new Narrative();
    narrative.setStatusAsString("generated");
    narrative.setDivAsString("This data was generated for test purposes.");
    final XhtmlNode node = new XhtmlNode();
    node.setNodeType(NodeType.Text);
    node.setValue("Severe burn of left ear (Date: 24-May 2012)");
    condition.setText(narrative);
    condition.setSubject(new Reference("Patient/example").setDisplay("Here is a display for you."));
    final CodeableConcept verificationStatus = new CodeableConcept();
    verificationStatus.addCoding(new Coding(ConditionVerStatus.CONFIRMED.getSystem(), ConditionVerStatus.CONFIRMED.toCode(), ConditionVerStatus.CONFIRMED.getDisplay()));
    condition.setVerificationStatus(verificationStatus);
    // Condition code
    final CodeableConcept code = new CodeableConcept();
    code.addCoding().setSystem("http://snomed.info/sct").setCode("39065001").setDisplay("Severe");
    condition.setSeverity(code);
    // Severity code
    final CodeableConcept severity = new CodeableConcept();
    severity.addCoding().setSystem("http://snomed.info/sct").setCode("24484000").setDisplay("Burn of ear").setUserSelected(true);
    condition.setSeverity(severity);
    // Onset date time
    final DateTimeType onset = new DateTimeType();
    onset.setValueAsString("2012-05-24");
    condition.setOnset(onset);
    return condition;
}
Also used : XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 97 with Narrative

use of org.hl7.fhir.r5.model.Narrative in project eCRNow by drajer-health.

the class CdaHistoryOfPresentIllnessGenerator method generateHistoryOfPresentIllnessSection.

public static String generateHistoryOfPresentIllnessSection(R4FhirData data) {
    StringBuilder sb = new StringBuilder(2000);
    // Will have to wait to discuss with vendors on History of Present Illness and how to obtain
    // that information reliably..
    // Then we can generate better text.
    sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.COMP_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.SECTION_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.HISTORY_OF_PRESENT_ILLNESS_SEC_TEMPLATE_ID));
    sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.HISTORY_OF_PRESENT_ILLNESS_SEC_CODE, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.HISTORY_OF_PRESENT_ILLNESS_SEC_CODE_NAME));
    // Add Title
    sb.append(CdaGeneratorUtils.getXmlForText(CdaGeneratorConstants.TITLE_EL_NAME, CdaGeneratorConstants.HISTORY_OF_PRESENT_ILLNESS_SEC_TITLE));
    // Add Narrative Text
    sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TEXT_EL_NAME));
    List<Condition> conds = data.getEncounterDiagnosisConditions();
    // Create Table Header.
    List<String> list = new ArrayList<>();
    list.add(CdaGeneratorConstants.NARRATIVE_TEXT_EL_NAME);
    sb.append(CdaGeneratorUtils.getXmlForTableHeader(list, CdaGeneratorConstants.TABLE_BORDER, CdaGeneratorConstants.TABLE_WIDTH));
    // Add Table Body
    sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
    String text = CdaGeneratorConstants.UNKNOWN_HISTORY_OF_PRESENT_ILLNESS;
    int rowNum = 1;
    if (conds != null && !conds.isEmpty()) {
        // Add Body Rows
        for (Condition prob : conds) {
            String probDisplayName = CdaGeneratorConstants.UNKNOWN_VALUE;
            if (prob.getCode() != null && !StringUtils.isEmpty(prob.getCode().getText())) {
                probDisplayName = prob.getCode().getText();
            } else if (prob.getCode().getCodingFirstRep() != null && !StringUtils.isEmpty(prob.getCode().getCodingFirstRep().getDisplay())) {
                probDisplayName = prob.getCode().getCodingFirstRep().getDisplay();
            }
            Map<String, String> bodyvals = new LinkedHashMap<>();
            bodyvals.put(CdaGeneratorConstants.HISTORY_OF_PRESENT_ILLNESS_BODY_CONTENT, probDisplayName);
            sb.append(CdaGeneratorUtils.addTableRow(bodyvals, rowNum));
            ++rowNum;
        }
    } else {
        Map<String, String> bodyvals = new HashMap<>();
        bodyvals.put(CdaGeneratorConstants.HISTORY_OF_PRESENT_ILLNESS_BODY_CONTENT, text);
        sb.append(CdaGeneratorUtils.addTableRow(bodyvals, 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));
    // Complete the section end tags.
    sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.SECTION_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.COMP_EL_NAME));
    return sb.toString();
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap)

Example 98 with Narrative

use of org.hl7.fhir.r5.model.Narrative in project eCRNow by drajer-health.

the class CdaProblemGenerator method generateProblemSection.

public static String generateProblemSection(R4FhirData data, LaunchDetails details) {
    StringBuilder sb = new StringBuilder(2000);
    List<Condition> conds = data.getConditions();
    if (conds != null && !conds.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.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<>();
        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 LinkedHashMap<>();
            bodyvals.put(CdaGeneratorConstants.PROB_TABLE_COL_1_BODY_CONTENT, probDisplayName);
            if (prob.getClinicalStatus() != null && prob.getClinicalStatus().getCodingFirstRep() != null && !StringUtils.isEmpty(prob.getClinicalStatus().getCodingFirstRep().getCode()) && (prob.getClinicalStatus().getCodingFirstRep().getCode().contentEquals(ConditionClinical.ACTIVE.toCode()) || prob.getClinicalStatus().getCodingFirstRep().getCode().contentEquals(ConditionClinical.RELAPSE.toCode()))) {
                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));
        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().getCodingFirstRep() != null && !StringUtils.isEmpty(pr.getClinicalStatus().getCodingFirstRep().getCode()) && (pr.getClinicalStatus().getCodingFirstRep().getCode().contentEquals(ConditionClinical.ACTIVE.toCode()) || pr.getClinicalStatus().getCodingFirstRep().getCode().contentEquals(ConditionClinical.RELAPSE.toCode()))) {
                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 = CdaFhirUtilities.getActualDate(pr.getOnset());
            Pair<Date, TimeZone> abatement = CdaFhirUtilities.getActualDate(pr.getAbatement());
            Pair<Date, TimeZone> recordedDate = null;
            if (pr.getRecordedDateElement() != null) {
                recordedDate = new Pair<>(pr.getRecordedDate(), pr.getRecordedDateElement().getTimeZone());
            }
            sb.append(CdaGeneratorUtils.getXmlForIVLWithTS(CdaGeneratorConstants.EFF_TIME_EL_NAME, recordedDate, 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()));
            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<CodeableConcept> cds = new ArrayList<>();
            cds.add(pr.getCode());
            String codeXml = CdaFhirUtilities.getCodeableConceptXmlForCodeSystem(cds, CdaGeneratorConstants.VAL_EL_NAME, true, CdaGeneratorConstants.FHIR_SNOMED_URL, false);
            if (!codeXml.isEmpty()) {
                sb.append(codeXml);
            } else {
                sb.append(CdaFhirUtilities.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));
            logger.debug("Add Trigger Codes to Problem Observation if applicable {}", pr.getId());
            sb.append(addTriggerCodes(details, pr, onset, abatement));
            logger.debug("Completed adding Trigger Codes ");
            // 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(org.hl7.fhir.r4.model.Condition) ArrayList(java.util.ArrayList) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) TimeZone(java.util.TimeZone) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 99 with Narrative

use of org.hl7.fhir.r5.model.Narrative in project eCRNow by drajer-health.

the class CdaPlanOfTreatmentGenerator method generatePlanOfTreatmentSection.

public static String generatePlanOfTreatmentSection(R4FhirData data, LaunchDetails details) {
    StringBuilder sb = new StringBuilder(2000);
    List<ServiceRequest> sr = getValidServiceRequests(data);
    if (sr != null && !sr.isEmpty()) {
        logger.debug("Found a total of {} service request objects to translate to CDA.", sr.size());
        // 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.CAREPLAN_SEC_TEMPLATE_ID));
        sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.CAREPLAN_SEC_TEMPLATE_ID, CdaGeneratorConstants.CAREPLAN_SEC_TEMPLATE_ID_EXT));
        sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.CAREPLAN_SEC_CODE, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.CAREPLAN_SEC_NAME));
        // Add Title
        sb.append(CdaGeneratorUtils.getXmlForText(CdaGeneratorConstants.TITLE_EL_NAME, CdaGeneratorConstants.CAREPLAN_SEC_TITLE));
        // Add Narrative Text
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TEXT_EL_NAME));
        // Create Table Header.
        List<String> list = new ArrayList<>();
        list.add(CdaGeneratorConstants.POT_OBS_TABLE_COL_1_TITLE);
        list.add(CdaGeneratorConstants.POT_OBS_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));
        int rowNum = 1;
        StringBuilder potObsXml = new StringBuilder();
        for (ServiceRequest s : sr) {
            Pair<String, Boolean> srDisplayName = CdaFhirUtilities.getCodeableConceptDisplayForCodeSystem(s.getCode(), CdaGeneratorConstants.FHIR_LOINC_URL, false);
            if (srDisplayName.getValue0().isEmpty()) {
                srDisplayName.setAt0(CdaGeneratorConstants.UNKNOWN_VALUE);
            }
            String serviceDate = CdaFhirUtilities.getStringForType(s.getOccurrence());
            logger.debug("Service Date for display {} ", serviceDate);
            if (serviceDate.isEmpty() && s.getAuthoredOnElement() != null) {
                serviceDate = CdaFhirUtilities.getDisplayStringForDateTimeType(s.getAuthoredOnElement());
            }
            Map<String, String> bodyvals = new LinkedHashMap<>();
            bodyvals.put(CdaGeneratorConstants.POT_OBS_TABLE_COL_1_BODY_CONTENT, srDisplayName.getValue0());
            bodyvals.put(CdaGeneratorConstants.POT_OBS_TABLE_COL_2_BODY_CONTENT, serviceDate);
            sb.append(CdaGeneratorUtils.addTableRow(bodyvals, rowNum));
            String contentRef = CdaGeneratorConstants.POT_OBS_TABLE_COL_1_BODY_CONTENT + Integer.toString(rowNum);
            rowNum++;
            potObsXml.append(getPlannedObservationXml(s, details, contentRef));
        }
        // Close the Text Element
        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 Entries
        sb.append(potObsXml);
        // Complete the section end tags.
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.SECTION_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.COMP_EL_NAME));
    } else {
        sb.append(generateEmptyPlanOfTreatmentSection());
    }
    return sb.toString();
}
Also used : ArrayList(java.util.ArrayList) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) LinkedHashMap(java.util.LinkedHashMap)

Example 100 with Narrative

use of org.hl7.fhir.r5.model.Narrative in project eCRNow by drajer-health.

the class CdaReasonForVisitGenerator method generateReasonForVisitSection.

public static String generateReasonForVisitSection(R4FhirData data) {
    StringBuilder sb = new StringBuilder(2000);
    Encounter encounter = data.getEncounter();
    // Will have to wait to discuss with vendors on Reason For Visit and how to obtain that
    // information reliably..
    // Then we can generate better text.
    sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.COMP_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.SECTION_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.REASON_FOR_VISIT_SEC_TEMPLATE_ID));
    sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.REASON_FOR_VISIT_SEC_CODE, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.REASON_FOR_VISIT_SEC_CODE_NAME));
    // Add Title
    sb.append(CdaGeneratorUtils.getXmlForText(CdaGeneratorConstants.TITLE_EL_NAME, CdaGeneratorConstants.REASON_FOR_VISIT_SEC_TITLE));
    // Add Narrative Text
    // Need to Discuss with vendors on how to best get this information.
    sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TEXT_EL_NAME));
    // Create Table Header.
    List<String> list = new ArrayList<>();
    list.add(CdaGeneratorConstants.TEXT_EL_NAME);
    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;
    String text = CdaGeneratorConstants.UNKNOWN_REASON_FOR_VISIT;
    if (encounter != null && encounter.getReasonCodeFirstRep() != null) {
        if (!StringUtils.isEmpty(encounter.getReasonCodeFirstRep().getText())) {
            text = encounter.getReasonCodeFirstRep().getText();
        } else if (encounter.getReasonCodeFirstRep().getCodingFirstRep() != null && !StringUtils.isEmpty(encounter.getReasonCodeFirstRep().getCodingFirstRep().getDisplay())) {
            text = encounter.getReasonCodeFirstRep().getCodingFirstRep().getDisplay();
        }
    }
    Map<String, String> bodyvals = new LinkedHashMap<>();
    bodyvals.put(CdaGeneratorConstants.TEXT_EL_NAME, text);
    sb.append(CdaGeneratorUtils.addTableRow(bodyvals, 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));
    // Complete the section end tags.
    sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.SECTION_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.COMP_EL_NAME));
    return sb.toString();
}
Also used : ArrayList(java.util.ArrayList) Encounter(org.hl7.fhir.r4.model.Encounter) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)80 FHIRException (org.hl7.fhir.exceptions.FHIRException)40 IOException (java.io.IOException)34 NotImplementedException (org.apache.commons.lang3.NotImplementedException)30 UnsupportedEncodingException (java.io.UnsupportedEncodingException)27 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)23 Test (org.junit.Test)22 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)19 ArrayList (java.util.ArrayList)19 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)17 Narrative (org.hl7.fhir.r4.model.Narrative)15 Narrative (org.hl7.fhir.r5.model.Narrative)15 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)14 XhtmlComposer (org.hl7.fhir.utilities.xhtml.XhtmlComposer)14 GET (javax.ws.rs.GET)12 Path (javax.ws.rs.Path)12 Produces (javax.ws.rs.Produces)12 IBaseOperationOutcome (org.hl7.fhir.instance.model.api.IBaseOperationOutcome)12 FileNotFoundException (java.io.FileNotFoundException)10 LinkedHashMap (java.util.LinkedHashMap)10