Search in sources :

Example 6 with OtherElementComponent

use of org.hl7.fhir.r4b.model.ConceptMap.OtherElementComponent in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generate.

public void generate(ConceptMap cm) {
    XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
    x.addTag("h2").addText(cm.getName() + " (" + cm.getUrl() + ")");
    XhtmlNode p = x.addTag("p");
    p.addText("Mapping from ");
    AddVsRef(((Reference) cm.getSource()).getReference(), p);
    p.addText(" to ");
    AddVsRef(((Reference) cm.getTarget()).getReference(), p);
    p = x.addTag("p");
    if (cm.getExperimental())
        p.addText(Utilities.capitalize(cm.getStatus().toString()) + " (not intended for production usage). ");
    else
        p.addText(Utilities.capitalize(cm.getStatus().toString()) + ". ");
    p.addText("Published on " + cm.getDateElement().toHumanDisplay() + " by " + cm.getPublisher());
    if (!cm.getContact().isEmpty()) {
        p.addText(" (");
        boolean firsti = true;
        for (ConceptMapContactComponent ci : cm.getContact()) {
            if (firsti)
                firsti = false;
            else
                p.addText(", ");
            if (ci.hasName())
                p.addText(ci.getName() + ": ");
            boolean first = true;
            for (ContactPoint c : ci.getTelecom()) {
                if (first)
                    first = false;
                else
                    p.addText(", ");
                addTelecom(p, c);
            }
            p.addText("; ");
        }
        p.addText(")");
    }
    p.addText(". ");
    p.addText(cm.getCopyright());
    if (!Utilities.noString(cm.getDescription()))
        x.addTag("p").addText(cm.getDescription());
    x.addTag("br");
    if (!cm.getElement().isEmpty()) {
        SourceElementComponent cc = cm.getElement().get(0);
        String src = cc.getCodeSystem();
        boolean comments = false;
        boolean ok = cc.getTarget().size() == 1;
        Map<String, HashSet<String>> sources = new HashMap<String, HashSet<String>>();
        sources.put("code", new HashSet<String>());
        Map<String, HashSet<String>> targets = new HashMap<String, HashSet<String>>();
        targets.put("code", new HashSet<String>());
        if (ok) {
            String dst = cc.getTarget().get(0).getCodeSystem();
            for (SourceElementComponent ccl : cm.getElement()) {
                ok = ok && src.equals(ccl.getCodeSystem()) && ccl.getTarget().size() == 1 && dst.equals(ccl.getTarget().get(0).getCodeSystem()) && ccl.getTarget().get(0).getDependsOn().isEmpty() && ccl.getTarget().get(0).getProduct().isEmpty();
                if (ccl.hasCodeSystem())
                    sources.get("code").add(ccl.getCodeSystem());
                for (TargetElementComponent ccm : ccl.getTarget()) {
                    comments = comments || !Utilities.noString(ccm.getComments());
                    for (OtherElementComponent d : ccm.getDependsOn()) {
                        if (!sources.containsKey(d.getElement()))
                            sources.put(d.getElement(), new HashSet<String>());
                        sources.get(d.getElement()).add(d.getCodeSystem());
                    }
                    if (ccm.hasCodeSystem())
                        targets.get("code").add(ccm.getCodeSystem());
                    for (OtherElementComponent d : ccm.getProduct()) {
                        if (!targets.containsKey(d.getElement()))
                            targets.put(d.getElement(), new HashSet<String>());
                        targets.get(d.getElement()).add(d.getCodeSystem());
                    }
                }
            }
        }
        String display;
        if (ok) {
            // simple
            XhtmlNode tbl = x.addTag("table").setAttribute("class", "grid");
            XhtmlNode tr = tbl.addTag("tr");
            tr.addTag("td").addTag("b").addText("Source Code");
            tr.addTag("td").addTag("b").addText("Equivalence");
            tr.addTag("td").addTag("b").addText("Destination Code");
            if (comments)
                tr.addTag("td").addTag("b").addText("Comments");
            for (SourceElementComponent ccl : cm.getElement()) {
                tr = tbl.addTag("tr");
                XhtmlNode td = tr.addTag("td");
                td.addText(ccl.getCode());
                display = getDisplayForConcept(ccl.getCodeSystem(), ccl.getCode());
                if (display != null)
                    td.addText(" (" + display + ")");
                TargetElementComponent ccm = ccl.getTarget().get(0);
                tr.addTag("td").addText(!ccm.hasEquivalence() ? "" : ccm.getEquivalence().toCode());
                td = tr.addTag("td");
                td.addText(ccm.getCode());
                display = getDisplayForConcept(ccm.getCodeSystem(), ccm.getCode());
                if (display != null)
                    td.addText(" (" + display + ")");
                if (comments)
                    tr.addTag("td").addText(ccm.getComments());
            }
        } else {
            XhtmlNode tbl = x.addTag("table").setAttribute("class", "grid");
            XhtmlNode tr = tbl.addTag("tr");
            XhtmlNode td;
            tr.addTag("td").setAttribute("colspan", Integer.toString(sources.size())).addTag("b").addText("Source Concept");
            tr.addTag("td").addTag("b").addText("Equivalence");
            tr.addTag("td").setAttribute("colspan", Integer.toString(targets.size())).addTag("b").addText("Destination Concept");
            if (comments)
                tr.addTag("td").addTag("b").addText("Comments");
            tr = tbl.addTag("tr");
            if (sources.get("code").size() == 1)
                tr.addTag("td").addTag("b").addText("Code " + sources.get("code").toString() + "");
            else
                tr.addTag("td").addTag("b").addText("Code");
            for (String s : sources.keySet()) {
                if (!s.equals("code")) {
                    if (sources.get(s).size() == 1)
                        tr.addTag("td").addTag("b").addText(getDescForConcept(s) + " " + sources.get(s).toString());
                    else
                        tr.addTag("td").addTag("b").addText(getDescForConcept(s));
                }
            }
            tr.addTag("td");
            if (targets.get("code").size() == 1)
                tr.addTag("td").addTag("b").addText("Code " + targets.get("code").toString());
            else
                tr.addTag("td").addTag("b").addText("Code");
            for (String s : targets.keySet()) {
                if (!s.equals("code")) {
                    if (targets.get(s).size() == 1)
                        tr.addTag("td").addTag("b").addText(getDescForConcept(s) + " " + targets.get(s).toString() + "");
                    else
                        tr.addTag("td").addTag("b").addText(getDescForConcept(s));
                }
            }
            if (comments)
                tr.addTag("td");
            for (SourceElementComponent ccl : cm.getElement()) {
                tr = tbl.addTag("tr");
                td = tr.addTag("td");
                if (sources.get("code").size() == 1)
                    td.addText(ccl.getCode());
                else
                    td.addText(ccl.getCodeSystem() + " / " + ccl.getCode());
                display = getDisplayForConcept(ccl.getCodeSystem(), ccl.getCode());
                if (display != null)
                    td.addText(" (" + display + ")");
                TargetElementComponent ccm = ccl.getTarget().get(0);
                for (String s : sources.keySet()) {
                    if (!s.equals("code")) {
                        td = tr.addTag("td");
                        td.addText(getCode(ccm.getDependsOn(), s, sources.get(s).size() != 1));
                        display = getDisplay(ccm.getDependsOn(), s);
                        if (display != null)
                            td.addText(" (" + display + ")");
                    }
                }
                tr.addTag("td").addText(ccm.getEquivalence().toString());
                td = tr.addTag("td");
                if (targets.get("code").size() == 1)
                    td.addText(ccm.getCode());
                else
                    td.addText(ccm.getCodeSystem() + " / " + ccm.getCode());
                display = getDisplayForConcept(ccm.getCodeSystem(), ccm.getCode());
                if (display != null)
                    td.addText(" (" + display + ")");
                for (String s : targets.keySet()) {
                    if (!s.equals("code")) {
                        td = tr.addTag("td");
                        td.addText(getCode(ccm.getProduct(), s, targets.get(s).size() != 1));
                        display = getDisplay(ccm.getProduct(), s);
                        if (display != null)
                            td.addText(" (" + display + ")");
                    }
                }
                if (comments)
                    tr.addTag("td").addText(ccm.getComments());
            }
        }
    }
    inject(cm, x, NarrativeStatus.GENERATED);
}
Also used : ContactPoint(org.hl7.fhir.dstu2.model.ContactPoint) OtherElementComponent(org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent) HashMap(java.util.HashMap) TargetElementComponent(org.hl7.fhir.dstu2.model.ConceptMap.TargetElementComponent) ConceptMapContactComponent(org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent) SourceElementComponent(org.hl7.fhir.dstu2.model.ConceptMap.SourceElementComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) HashSet(java.util.HashSet)

Example 7 with OtherElementComponent

use of org.hl7.fhir.r4b.model.ConceptMap.OtherElementComponent in project org.hl7.fhir.core by hapifhir.

the class MappingSheetParser method readConceptMap.

private void readConceptMap(ConceptMap cm) throws FHIRException {
    for (ConceptMapGroupComponent g : cm.getGroup()) {
        for (SourceElementComponent e : g.getElement()) {
            if (e.hasId() && e.getTarget().size() == 1 && e.hasExtension(ToolingExtensions.EXT_MAPPING_TYPE)) {
                TargetElementComponent t = e.getTargetFirstRep();
                MappingRow row = new MappingRow();
                row.sequence = e.getId();
                row.identifier = e.getCode();
                row.name = e.getExtensionString(ToolingExtensions.EXT_MAPPING_NAME);
                row.dataType = e.getExtensionString(ToolingExtensions.EXT_MAPPING_TYPE);
                row.cardinality = e.getExtensionString(ToolingExtensions.EXT_MAPPING_CARD);
                if (e.getNoMap() == true) {
                    row.attribute = "N/A";
                } else {
                    OtherElementComponent dep = getDependency(t, "http://hl7.org/fhirpath");
                    if (dep != null)
                        row.condition = dep.getValue();
                    row.attribute = t.getCode();
                    row.type = t.getExtensionString(ToolingExtensions.EXT_MAPPING_TGTTYPE);
                    row.minMax = t.getExtensionString(ToolingExtensions.EXT_MAPPING_TGTCARD);
                    row.dtMapping = t.getExtensionString("http://hl7.org/fhir/StructureDefinition/ConceptMap-type-mapping");
                    row.vocabMapping = t.getExtensionString("http://hl7.org/fhir/StructureDefinition/ConceptMap-vocab-mapping");
                    if (t.getProduct().size() > 0) {
                        row.derived = t.getProductFirstRep().getProperty();
                        row.derivedMapping = t.getProductFirstRep().getValue();
                    }
                }
                row.comments = t.getComment();
                rows.add(row);
            }
        }
    }
}
Also used : OtherElementComponent(org.hl7.fhir.r5.model.ConceptMap.OtherElementComponent) TargetElementComponent(org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent) ConceptMapGroupComponent(org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent)

Example 8 with OtherElementComponent

use of org.hl7.fhir.r4b.model.ConceptMap.OtherElementComponent in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generate.

public boolean generate(ResourceContext rcontext, ConceptMap cm) throws FHIRFormatError, DefinitionException, IOException {
    XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
    x.h2().addText(cm.getName() + " (" + cm.getUrl() + ")");
    XhtmlNode p = x.para();
    p.tx("Mapping from ");
    if (cm.hasSource())
        AddVsRef(rcontext, cm.getSource().primitiveValue(), p);
    else
        p.tx("(not specified)");
    p.tx(" to ");
    if (cm.hasTarget())
        AddVsRef(rcontext, cm.getTarget().primitiveValue(), p);
    else
        p.tx("(not specified)");
    p = x.para();
    if (cm.getExperimental())
        p.addText(Utilities.capitalize(cm.getStatus().toString()) + " (not intended for production usage). ");
    else
        p.addText(Utilities.capitalize(cm.getStatus().toString()) + ". ");
    p.tx("Published on " + (cm.hasDate() ? cm.getDateElement().toHumanDisplay() : "??") + " by " + cm.getPublisher());
    if (!cm.getContact().isEmpty()) {
        p.tx(" (");
        boolean firsti = true;
        for (ContactDetail ci : cm.getContact()) {
            if (firsti)
                firsti = false;
            else
                p.tx(", ");
            if (ci.hasName())
                p.addText(ci.getName() + ": ");
            boolean first = true;
            for (ContactPoint c : ci.getTelecom()) {
                if (first)
                    first = false;
                else
                    p.tx(", ");
                addTelecom(p, c);
            }
        }
        p.tx(")");
    }
    p.tx(". ");
    p.addText(cm.getCopyright());
    if (!Utilities.noString(cm.getDescription()))
        addMarkdown(x, cm.getDescription());
    x.br();
    CodeSystem cs = context.fetchCodeSystem("http://hl7.org/fhir/concept-map-equivalence");
    String eqpath = cs.getUserString("path");
    for (ConceptMapGroupComponent grp : cm.getGroup()) {
        String src = grp.getSource();
        boolean comment = false;
        boolean ok = true;
        Map<String, HashSet<String>> sources = new HashMap<String, HashSet<String>>();
        Map<String, HashSet<String>> targets = new HashMap<String, HashSet<String>>();
        sources.put("code", new HashSet<String>());
        targets.put("code", new HashSet<String>());
        SourceElementComponent cc = grp.getElement().get(0);
        String dst = grp.getTarget();
        sources.get("code").add(grp.getSource());
        targets.get("code").add(grp.getTarget());
        for (SourceElementComponent ccl : grp.getElement()) {
            ok = ok && ccl.getTarget().size() == 1 && ccl.getTarget().get(0).getDependsOn().isEmpty() && ccl.getTarget().get(0).getProduct().isEmpty();
            for (TargetElementComponent ccm : ccl.getTarget()) {
                comment = comment || !Utilities.noString(ccm.getComment());
                for (OtherElementComponent d : ccm.getDependsOn()) {
                    if (!sources.containsKey(d.getProperty()))
                        sources.put(d.getProperty(), new HashSet<String>());
                    sources.get(d.getProperty()).add(d.getSystem());
                }
                for (OtherElementComponent d : ccm.getProduct()) {
                    if (!targets.containsKey(d.getProperty()))
                        targets.put(d.getProperty(), new HashSet<String>());
                    targets.get(d.getProperty()).add(d.getSystem());
                }
            }
        }
        String display;
        if (ok) {
            // simple
            XhtmlNode tbl = x.table("grid");
            XhtmlNode tr = tbl.tr();
            tr.td().b().tx("Source Code");
            tr.td().b().tx("Equivalence");
            tr.td().b().tx("Destination Code");
            if (comment)
                tr.td().b().tx("Comment");
            for (SourceElementComponent ccl : grp.getElement()) {
                tr = tbl.tr();
                XhtmlNode td = tr.td();
                td.addText(ccl.getCode());
                display = getDisplayForConcept(grp.getSource(), ccl.getCode());
                if (display != null && !isSameCodeAndDisplay(ccl.getCode(), display))
                    td.tx(" (" + display + ")");
                TargetElementComponent ccm = ccl.getTarget().get(0);
                tr.td().addText(!ccm.hasEquivalence() ? "" : ccm.getEquivalence().toCode());
                td = tr.td();
                td.addText(ccm.getCode());
                display = getDisplayForConcept(grp.getTarget(), ccm.getCode());
                if (display != null && !isSameCodeAndDisplay(ccm.getCode(), display))
                    td.tx(" (" + display + ")");
                if (comment)
                    tr.td().addText(ccm.getComment());
            }
        } else {
            XhtmlNode tbl = x.table("grid");
            XhtmlNode tr = tbl.tr();
            XhtmlNode td;
            tr.td().colspan(Integer.toString(sources.size())).b().tx("Source Concept Details");
            tr.td().b().tx("Equivalence");
            tr.td().colspan(Integer.toString(targets.size())).b().tx("Destination Concept Details");
            if (comment)
                tr.td().b().tx("Comment");
            tr = tbl.tr();
            if (sources.get("code").size() == 1) {
                String url = sources.get("code").iterator().next();
                renderCSDetailsLink(tr, url);
            } else
                tr.td().b().tx("Code");
            for (String s : sources.keySet()) {
                if (!s.equals("code")) {
                    if (sources.get(s).size() == 1) {
                        String url = sources.get(s).iterator().next();
                        renderCSDetailsLink(tr, url);
                    } else
                        tr.td().b().addText(getDescForConcept(s));
                }
            }
            tr.td();
            if (targets.get("code").size() == 1) {
                String url = targets.get("code").iterator().next();
                renderCSDetailsLink(tr, url);
            } else
                tr.td().b().tx("Code");
            for (String s : targets.keySet()) {
                if (!s.equals("code")) {
                    if (targets.get(s).size() == 1) {
                        String url = targets.get(s).iterator().next();
                        renderCSDetailsLink(tr, url);
                    } else
                        tr.td().b().addText(getDescForConcept(s));
                }
            }
            if (comment)
                tr.td();
            for (int si = 0; si < grp.getElement().size(); si++) {
                SourceElementComponent ccl = grp.getElement().get(si);
                boolean slast = si == grp.getElement().size() - 1;
                boolean first = true;
                for (int ti = 0; ti < ccl.getTarget().size(); ti++) {
                    TargetElementComponent ccm = ccl.getTarget().get(ti);
                    boolean last = ti == ccl.getTarget().size() - 1;
                    tr = tbl.tr();
                    td = tr.td();
                    if (!first && !last)
                        td.setAttribute("style", "border-top-style: none; border-bottom-style: none");
                    else if (!first)
                        td.setAttribute("style", "border-top-style: none");
                    else if (!last)
                        td.setAttribute("style", "border-bottom-style: none");
                    if (first) {
                        if (sources.get("code").size() == 1)
                            td.addText(ccl.getCode());
                        else
                            td.addText(grp.getSource() + " / " + ccl.getCode());
                        display = getDisplayForConcept(grp.getSource(), ccl.getCode());
                        if (display != null)
                            td.tx(" (" + display + ")");
                    }
                    for (String s : sources.keySet()) {
                        if (!s.equals("code")) {
                            td = tr.td();
                            if (first) {
                                td.addText(getValue(ccm.getDependsOn(), s, sources.get(s).size() != 1));
                                display = getDisplay(ccm.getDependsOn(), s);
                                if (display != null)
                                    td.tx(" (" + display + ")");
                            }
                        }
                    }
                    first = false;
                    if (!ccm.hasEquivalence())
                        tr.td().tx(":" + "(" + ConceptMapEquivalence.EQUIVALENT.toCode() + ")");
                    else
                        tr.td().ah(eqpath + "#" + ccm.getEquivalence().toCode()).tx(ccm.getEquivalence().toCode());
                    td = tr.td();
                    if (targets.get("code").size() == 1)
                        td.addText(ccm.getCode());
                    else
                        td.addText(grp.getTarget() + " / " + ccm.getCode());
                    display = getDisplayForConcept(grp.getTarget(), ccm.getCode());
                    if (display != null)
                        td.tx(" (" + display + ")");
                    for (String s : targets.keySet()) {
                        if (!s.equals("code")) {
                            td = tr.td();
                            td.addText(getValue(ccm.getProduct(), s, targets.get(s).size() != 1));
                            display = getDisplay(ccm.getProduct(), s);
                            if (display != null)
                                td.tx(" (" + display + ")");
                        }
                    }
                    if (comment)
                        tr.td().addText(ccm.getComment());
                }
            }
        }
    }
    inject(cm, x, NarrativeStatus.GENERATED);
    return true;
}
Also used : CodeSystem(org.hl7.fhir.r4.model.CodeSystem) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) OtherElementComponent(org.hl7.fhir.r4.model.ConceptMap.OtherElementComponent) TargetElementComponent(org.hl7.fhir.r4.model.ConceptMap.TargetElementComponent) ConceptMapGroupComponent(org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.r4.model.ConceptMap.SourceElementComponent)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 ConceptMapGroupComponent (org.hl7.fhir.r4b.model.ConceptMap.ConceptMapGroupComponent)2 OtherElementComponent (org.hl7.fhir.r4b.model.ConceptMap.OtherElementComponent)2 SourceElementComponent (org.hl7.fhir.r4b.model.ConceptMap.SourceElementComponent)2 TargetElementComponent (org.hl7.fhir.r4b.model.ConceptMap.TargetElementComponent)2 ConceptMapGroupComponent (org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent)2 OtherElementComponent (org.hl7.fhir.r5.model.ConceptMap.OtherElementComponent)2 SourceElementComponent (org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent)2 TargetElementComponent (org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent)2 ConceptMapContactComponent (org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent)1 OtherElementComponent (org.hl7.fhir.dstu2.model.ConceptMap.OtherElementComponent)1 SourceElementComponent (org.hl7.fhir.dstu2.model.ConceptMap.SourceElementComponent)1 TargetElementComponent (org.hl7.fhir.dstu2.model.ConceptMap.TargetElementComponent)1 ContactPoint (org.hl7.fhir.dstu2.model.ContactPoint)1 ConceptMapContactComponent (org.hl7.fhir.dstu2016may.model.ConceptMap.ConceptMapContactComponent)1 OtherElementComponent (org.hl7.fhir.dstu2016may.model.ConceptMap.OtherElementComponent)1 SourceElementComponent (org.hl7.fhir.dstu2016may.model.ConceptMap.SourceElementComponent)1 TargetElementComponent (org.hl7.fhir.dstu2016may.model.ConceptMap.TargetElementComponent)1