Search in sources :

Example 86 with Section

use of org.hl7.fhir.r4.utils.formats.Turtle.Section in project eCRNow by drajer-health.

the class CdaResultGenerator method generateResultsSection.

public static String generateResultsSection(R4FhirData data, LaunchDetails details) {
    StringBuilder hsb = new StringBuilder(5000);
    StringBuilder sb = new StringBuilder(2000);
    StringBuilder resultEntries = new StringBuilder();
    List<Observation> results = getValidLabResults(data);
    if (results != null && !results.isEmpty()) {
        hsb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.COMP_EL_NAME));
        hsb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.SECTION_EL_NAME));
        hsb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.LAB_RESULTS_SEC_TEMPLATE_ID));
        hsb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.LAB_RESULTS_SEC_TEMPLATE_ID, CdaGeneratorConstants.LAB_RESULTS_SEC_TEMPLATE_ID_EXT));
        hsb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.LAB_RESULTS_SEC_CODE, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.LAB_RESULTS_SEC_NAME));
        // Add Title
        hsb.append(CdaGeneratorUtils.getXmlForText(CdaGeneratorConstants.TITLE_EL_NAME, CdaGeneratorConstants.LAB_RESULTS_SEC_TITLE));
        // Add Narrative Text
        hsb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TEXT_EL_NAME));
        // Create Table Header.
        List<String> list = new ArrayList<>();
        list.add(CdaGeneratorConstants.LABTEST_TABLE_COL_1_TITLE);
        list.add(CdaGeneratorConstants.LABTEST_TABLE_COL_2_TITLE);
        list.add(CdaGeneratorConstants.LABTEST_TABLE_COL_3_TITLE);
        hsb.append(CdaGeneratorUtils.getXmlForTableHeader(list, CdaGeneratorConstants.TABLE_BORDER, CdaGeneratorConstants.TABLE_WIDTH));
        // Add Table Body
        hsb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
        int rowNum = 1;
        for (Observation obs : results) {
            String obsDisplayName = CdaGeneratorConstants.UNKNOWN_VALUE;
            List<Coding> cds = null;
            if (obs.getCode() != null && obs.getCode().getCodingFirstRep() != null) {
                cds = obs.getCode().getCoding();
                if (!StringUtils.isEmpty(obs.getCode().getCodingFirstRep().getDisplay())) {
                    obsDisplayName = obs.getCode().getCodingFirstRep().getDisplay();
                } else if (!StringUtils.isEmpty(obs.getCode().getText())) {
                    obsDisplayName = obs.getCode().getText();
                }
            }
            Map<String, String> bodyvals = new LinkedHashMap<>();
            bodyvals.put(CdaGeneratorConstants.LABTEST_TABLE_COL_1_BODY_CONTENT, obsDisplayName);
            String val = CdaGeneratorConstants.UNKNOWN_VALUE;
            if (obs.getValue() != null) {
                val = CdaFhirUtilities.getStringForType(obs.getValue());
            }
            bodyvals.put(CdaGeneratorConstants.LABTEST_TABLE_COL_2_BODY_CONTENT, val);
            String dt = CdaGeneratorConstants.UNKNOWN_VALUE;
            if (obs.getEffective() != null) {
                dt = CdaFhirUtilities.getStringForType(obs.getEffective());
            }
            bodyvals.put(CdaGeneratorConstants.LABTEST_TABLE_COL_3_BODY_CONTENT, dt);
            sb.append(CdaGeneratorUtils.addTableRow(bodyvals, rowNum));
            // Setup the Organizer and Entries
            StringBuilder lrEntry = new StringBuilder();
            // Add the Entries.
            lrEntry.append(CdaGeneratorUtils.getXmlForActEntry(CdaGeneratorConstants.TYPE_CODE_DEF));
            // Add the Organizer Act
            lrEntry.append(CdaGeneratorUtils.getXmlForAct(CdaGeneratorConstants.ORGANIZER_EL_NAME, CdaGeneratorConstants.ORGANIZER_CLASS_CODE_CLUSTER, CdaGeneratorConstants.MOOD_CODE_DEF));
            lrEntry.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.LAB_RESULTS_ORG_TEMPLATE_ID));
            lrEntry.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.LAB_RESULTS_ORG_TEMPLATE_ID, CdaGeneratorConstants.LAB_RESULTS_ORG_TEMPLATE_ID_EXT));
            lrEntry.append(CdaGeneratorUtils.getXmlForIIUsingGuid());
            // Fix the Code to be the same as the result code..
            logger.debug("Find the Loinc Code as a priority first for Lab Results");
            String codeXml = CdaFhirUtilities.getCodingXmlForCodeSystem(cds, CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.FHIR_LOINC_URL, false, "");
            logger.debug("Code Xml = {}", codeXml);
            if (!codeXml.isEmpty()) {
                lrEntry.append(codeXml);
            } else {
                lrEntry.append(CdaFhirUtilities.getCodingXml(cds, CdaGeneratorConstants.CODE_EL_NAME, ""));
            }
            lrEntry.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.STATUS_CODE_EL_NAME, CdaGeneratorConstants.COMPLETED_STATUS));
            lrEntry.append(getXmlForObservation(details, obs, CdaGeneratorConstants.LABTEST_TABLE_COL_1_BODY_CONTENT, rowNum));
            // End Tags for Entries
            lrEntry.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ORGANIZER_EL_NAME));
            lrEntry.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ENTRY_EL_NAME));
            resultEntries.append(lrEntry);
            rowNum++;
        }
        // End the Sb string.
        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));
        hsb.append(sb);
        // Add lab results
        hsb.append(resultEntries);
        // Complete the section end tags.
        hsb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.SECTION_EL_NAME));
        hsb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.COMP_EL_NAME));
    } else {
        hsb.append(generateEmptyLabResults());
    }
    return hsb.toString();
}
Also used : Coding(org.hl7.fhir.r4.model.Coding) Observation(org.hl7.fhir.r4.model.Observation) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap)

Example 87 with Section

use of org.hl7.fhir.r4.utils.formats.Turtle.Section in project eCRNow by drajer-health.

the class EicrCompositionGenerator method convertR4FhirBundletoCdaEicr.

public static Composition convertR4FhirBundletoCdaEicr(R4FhirData data) {
    Composition comp = new Composition();
    // Add version number extension.
    comp.addExtension(FhirGeneratorConstants.COMP_CLIN_DOC_VERSION_NUM_URL, new StringType(String.valueOf(FhirGeneratorConstants.VERSION_NUM)));
    // Add Type
    comp.setType(FhirGeneratorUtils.getCodeableConcept(FhirGeneratorConstants.LOINC_CS_URL, FhirGeneratorConstants.COMP_TYPE_CODE, FhirGeneratorConstants.COMP_TYPE_CODE_DISPLAY));
    // Setup Patient.
    comp.getSubject().setResource(data.getPatient());
    // Setup Encounter
    if (data.getEncounter() != null)
        comp.getEncounter().setResource(data.getEncounter());
    // Add Authors.
    List<Reference> auths = new ArrayList<>();
    // Add organization
    if (data.getOrganization() != null)
        auths.add(FhirGeneratorUtils.getReference(data.getOrganization()));
    if (data.getPractitioner() != null)
        auths.add(FhirGeneratorUtils.getReference(data.getPractitioner()));
    comp.setAuthor(auths);
    // Add Reason for Visit Section;
    SectionComponent rvs = FhirGeneratorUtils.getSectionComponent(FhirGeneratorConstants.LOINC_CS_URL, FhirGeneratorConstants.REASON_FOR_VISIT_CODE, FhirGeneratorConstants.REASON_FOR_VISIT_CODE_DISPLAY);
    // Set the Section Code Display to be the narrative text.
    rvs.getCode().setTextElement(new StringType(FhirGeneratorUtils.getReasonForVisitNarrativeText(data.getEncounter())));
    comp.getSection().add(rvs);
    return comp;
}
Also used : Composition(org.hl7.fhir.r4.model.Composition) StringType(org.hl7.fhir.r4.model.StringType) Reference(org.hl7.fhir.r4.model.Reference) ArrayList(java.util.ArrayList) SectionComponent(org.hl7.fhir.r4.model.Composition.SectionComponent)

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