Search in sources :

Example 31 with SourceElementComponent

use of org.hl7.fhir.r4b.model.ConceptMap.SourceElementComponent in project kindling by HL7.

the class CodeListToValueSetParser method processV2Map.

private void processV2Map(ConceptMap cm, String url, String code, String v2map) throws Exception {
    if (Utilities.noString(v2map))
        return;
    for (String m : v2map.split(",")) {
        // analyse m
        String[] n = m.split("\\(");
        String comm = (n.length > 1) ? n[1].substring(0, n[1].length() - 1) : null;
        n = n[0].split("\\.");
        if (n.length != 2)
            throw new Exception("Error processing v2 map value for " + cm.getName() + "." + code + " '" + m + "' - format should be CodeSystem.code (comment) - the comment bit is optional");
        String rel = n[0].substring(0, 1);
        String tbl = n[0].substring(1);
        String cd = n[1];
        ConceptMapGroupComponent grp = getGroup(cm, url, "http://terminology.hl7.org/CodeSystem/v2-" + tbl);
        SourceElementComponent src = getSource(grp, code);
        TargetElementComponent tgt = src.addTarget();
        tgt.setCode(cd.trim());
        tgt.setComment(comm);
        if (rel.equals("="))
            tgt.setRelationship(ConceptMapRelationship.EQUIVALENT);
        else if (rel.equals("~"))
            tgt.setRelationship(ConceptMapRelationship.EQUIVALENT);
        else if (rel.equals(">"))
            tgt.setRelationship(ConceptMapRelationship.SOURCEISBROADERTHANTARGET);
        else if (rel.equals("<")) {
            tgt.setRelationship(ConceptMapRelationship.SOURCEISNARROWERTHANTARGET);
            if (!tgt.hasComment())
                throw new Exception("Missing comment for narrower match on " + cm.getName() + "/" + code);
        } else
            throw new Exception("Unable to understand relationship character " + rel);
    }
}
Also used : 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 32 with SourceElementComponent

use of org.hl7.fhir.r4b.model.ConceptMap.SourceElementComponent in project kindling by HL7.

the class Publisher method buildConceptMap.

private ConceptMap buildConceptMap(String path, ValueSet vs, ResourceDefn rd) throws EOperationOutcome, FHIRException, IOException {
    ConceptMap cm = new ConceptMap();
    cm.setUserData("path", "sc-" + vs.getUserString("path"));
    cm.setUserData("resource-definition", rd);
    cm.setId("sc-" + vs.getId());
    cm.setUrl("http://hl7.org/fhir/ConceptMap/" + cm.getId());
    cm.setVersion(page.getVersion().toCode());
    cm.setName(vs.getName() + "CanonicalMap");
    cm.setTitle("Canonical Mapping for \"" + vs.present() + "\"");
    cm.setStatus(PublicationStatus.DRAFT);
    cm.setDate(vs.getDate());
    cm.setPublisher(vs.getPublisher());
    cm.addContact(vs.getContactFirstRep());
    cm.setDescription("Canonical Mapping for \"" + vs.getDescription() + "\"");
    cm.setSource(new CanonicalType(vs.getUrl()));
    cm.setTarget(new CanonicalType("http://hl7.org/fhir/ValueSet/resource-status"));
    List<String> canonical = page.getDefinitions().getStatusCodes().get("@code");
    List<String> self = page.getDefinitions().getStatusCodes().get(path);
    ConceptMapGroupComponent grp = cm.addGroup();
    grp.setTarget("http://hl7.org/fhir/resource-status");
    grp.setSource(vs.getCompose().getIncludeFirstRep().getSystem());
    for (int i = 0; i < self.size(); i++) {
        if (!Utilities.noString(self.get(i))) {
            String cc = canonical.get(i);
            String sc = self.get(i);
            SourceElementComponent e = grp.addElement();
            e.setCode(sc);
            TargetElementComponent t = e.addTarget();
            t.setCode(cc);
            t.setRelationship(ConceptMapRelationship.EQUIVALENT);
        }
    }
    if (!grp.hasElement())
        return null;
    page.getConceptMaps().see(cm, page.packageInfo());
    statusCodeConceptMaps.add(cm);
    return cm;
}
Also used : TargetElementComponent(org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) ConceptMapGroupComponent(org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) SourceElementComponent(org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent)

Example 33 with SourceElementComponent

use of org.hl7.fhir.r4b.model.ConceptMap.SourceElementComponent 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 34 with SourceElementComponent

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

the class SearchParameterProcessor method generate.

private void generate(String src, String dst, String srcURL, String tgtURL) throws IOException {
    ConceptMap map = new ConceptMap();
    map.setId("search-parameters-" + src + "-to-" + dst);
    map.setUrl("http://hl7.org/fhir/interversion/ConceptMap/" + map.getId());
    map.setName("SearchParameterMap" + src + dst);
    map.setTitle("Search Parameter Map - " + src + " to " + dst);
    map.setStatus(PublicationStatus.DRAFT);
    map.setDate(new Date());
    map.setExperimental(false);
    map.setPublisher("HL7");
    ConceptMapGroupComponent group = map.addGroup();
    group.setSource("http://hl7.org/fhir/" + srcURL);
    group.setTarget("http://hl7.org/fhir/" + tgtURL);
    for (SPRelationship sp : list) {
        String s = sp.getByCode(src);
        String d = sp.getByCode(dst);
        if (!Utilities.noString(s) && !Utilities.noString(d)) {
            SourceElementComponent e = makeElement(s, group);
            e.addTarget().setCode(d).setRelationship(ConceptMapRelationship.RELATEDTO);
        }
    }
    new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(ROOT, "ConceptMap-" + map.getId() + ".json")), map);
}
Also used : FileOutputStream(java.io.FileOutputStream) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) Date(java.util.Date) ConceptMapGroupComponent(org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 35 with SourceElementComponent

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

the class ConceptMapSpreadsheetGenerator method renderGroup.

private void renderGroup(ConceptMapGroupComponent grp, int i) {
    Sheet sheet = makeSheet("Mapping Table " + Integer.toString(i));
    addHeaders(sheet, "Source", "Display", "Relationship", "Target", "Display");
    addRow(sheet, grp.getSource(), "", "", grp.getTarget(), "");
    for (SourceElementComponent s : grp.getElement()) {
        for (TargetElementComponent t : s.getTarget()) {
            addRow(sheet, s.getCode(), s.getDisplay(), t.getRelationshipElement().asStringValue(), t.getCode(), t.getDisplay());
        }
    }
}
Also used : TargetElementComponent(org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent) Sheet(org.apache.poi.ss.usermodel.Sheet) SourceElementComponent(org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent)

Aggregations

SourceElementComponent (org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent)14 FHIRException (org.hl7.fhir.exceptions.FHIRException)11 ConceptMapGroupComponent (org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent)11 HashMap (java.util.HashMap)10 ConceptMapGroupComponent (org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent)9 SourceElementComponent (org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent)9 TargetElementComponent (org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent)9 ConceptMapGroupComponent (org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent)8 SourceElementComponent (org.hl7.fhir.r4.model.ConceptMap.SourceElementComponent)8 SourceElementComponent (org.hl7.fhir.r4b.model.ConceptMap.SourceElementComponent)8 ArrayList (java.util.ArrayList)7 TargetElementComponent (org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent)6 TargetElementComponent (org.hl7.fhir.r4.model.ConceptMap.TargetElementComponent)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 HashSet (java.util.HashSet)5 ConceptMap (org.hl7.fhir.r4.model.ConceptMap)5 ConceptMapGroupComponent (org.hl7.fhir.r4b.model.ConceptMap.ConceptMapGroupComponent)5 TargetElementComponent (org.hl7.fhir.r4b.model.ConceptMap.TargetElementComponent)5 Coding (org.hl7.fhir.r4.model.Coding)4 ConceptMap (org.hl7.fhir.r5.model.ConceptMap)4