Search in sources :

Example 1 with ConceptSetComponent

use of org.hl7.fhir.dstu2016may.model.ValueSet.ConceptSetComponent in project kindling by HL7.

the class PageProcessor method summariseSCTCLD.

private String summariseSCTCLD(ValueSet vs) {
    boolean hasNonSCT = false;
    for (ConceptSetComponent cc : vs.getCompose().getInclude()) {
        if (!"http://snomed.info/sct".equals(cc.getSystem()))
            hasNonSCT = true;
    }
    StringBuilder b = new StringBuilder();
    b.append("<ul>");
    for (ConceptSetComponent cc : vs.getCompose().getInclude()) {
        if ("http://snomed.info/sct".equals(cc.getSystem())) {
            if (!cc.hasConcept() && !cc.hasFilter()) {
                b.append("<li>any SCT concept</li>");
            } else if (cc.hasConcept()) {
                b.append("<li>" + Integer.toString(cc.getConcept().size()) + " enumerated concepts</li>");
            } else {
                if (cc.getFilter().size() != 1 || !cc.getFilter().get(0).getProperty().equals("concept"))
                    b.append("<li>ERROR!</li>");
                else {
                    ConceptDefinitionComponent def = workerContext.getCodeDefinition("http://snomed.info/sct", cc.getFilter().get(0).getValue());
                    b.append("<li>" + cc.getFilter().get(0).getOp().toCode() + " " + (def == null ? cc.getFilter().get(0).getValue() : Utilities.escapeXml(def.getDisplay())) + "</li>");
                }
            }
        }
    }
    if (hasNonSCT)
        b.append("<li>other code systems</li>");
    b.append("</ul>");
    return b.toString();
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)

Example 2 with ConceptSetComponent

use of org.hl7.fhir.dstu2016may.model.ValueSet.ConceptSetComponent in project kindling by HL7.

the class PageProcessor method getSnomedCTConceptList.

private String getSnomedCTConceptList() throws Exception {
    Map<String, SnomedConceptUsage> concepts = new HashMap<String, SnomedConceptUsage>();
    for (ValueSet vs : definitions.getValuesets().getList()) {
        if (!vs.hasUrl() || !vs.getUrl().startsWith("http://terminology.hl7.org")) {
            for (ConceptSetComponent cc : vs.getCompose().getInclude()) if (cc.hasSystem() && cc.getSystem().equals("http://snomed.info/sct")) {
                for (ConceptReferenceComponent c : cc.getConcept()) {
                    String d = c.hasDisplay() ? c.getDisplay() : workerContext.getCodeDefinition("http://snomed.info/sct", c.getCode()).getDisplay();
                    if (concepts.containsKey(c.getCode()))
                        concepts.get(c.getCode()).update(d, vs);
                    else
                        concepts.put(c.getCode(), new SnomedConceptUsage(c.getCode(), d, vs));
                }
                for (ConceptSetFilterComponent c : cc.getFilter()) {
                    if ("concept".equals(c.getProperty())) {
                        getSnomedCTConcept(concepts, vs, c);
                    }
                }
            }
        }
    }
    List<String> sorts = new ArrayList<String>();
    for (String s : concepts.keySet()) sorts.add(s);
    Collections.sort(sorts);
    StringBuilder b = new StringBuilder();
    b.append("<table class=\"codes\">\r\n");
    b.append(" <tr><td><b>Code</b></td><td><b>Display</b></td><td>ValueSets</td></tr>\r\n");
    for (String s : sorts) {
        SnomedConceptUsage usage = concepts.get(s);
        b.append(" <tr>\r\n   <td>" + s + "</td>\r\n    <td>" + Utilities.escapeXml(usage.getDisplay()) + "</td>\r\n    <td>");
        boolean first = true;
        for (ValueSet vs : usage.getValueSets()) {
            if (first)
                first = false;
            else
                b.append("<br/>");
            String path = (String) vs.getUserData("path");
            b.append(" <a href=\"" + pathTail(Utilities.changeFileExt(path, ".html")) + "\">" + Utilities.escapeXml(vs.present()) + "</a>");
        }
        b.append("</td>\r\n  </tr>\r\n");
    }
    b.append("</table>\r\n");
    return b.toString();
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) ConceptSetFilterComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ValueSet(org.hl7.fhir.r5.model.ValueSet) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)

Example 3 with ConceptSetComponent

use of org.hl7.fhir.dstu2016may.model.ValueSet.ConceptSetComponent in project kindling by HL7.

the class PageProcessor method generateValueSetUsage.

private String generateValueSetUsage(ValueSet vs, String prefix, boolean addTitle) throws Exception {
    List<String> items = new ArrayList<>();
    if (vs.hasUrl()) {
        for (CodeSystem cs : getCodeSystems().getList()) {
            if (cs != null) {
                if (vs.getUrl().equals(cs.getValueSet())) {
                    String p = cs.getUserString("path");
                    addItem(items, "<li>CodeSystem: This value set is the designated 'entire code system' value set for <a href=\"" + (Utilities.isAbsoluteUrl(p) ? "" : prefix) + p + "\">" + cs.getName() + "</a> " + "</li>\r\n");
                }
            }
        }
    }
    for (ConceptMap cm : getConceptMaps().getList()) {
        String p = cm.getUserString("path");
        if (cm.hasSourceUriType() && cm.getSourceUriType().equals(vs.getUrl())) {
            addItem(items, "<li>ConceptMap: Translation source in <a href=\"" + (Utilities.isAbsoluteUrl(p) ? "" : prefix) + p + "\">" + cm.present() + "</a> " + "</li>\r\n");
        } else if (cm.hasSourceCanonicalType() && (cm.getSourceCanonicalType().getValue().equals(vs.getUrl()) || vs.getUrl().endsWith("/" + cm.getSourceCanonicalType().getValue()))) {
            addItem(items, "<li>ConceptMap: Translation source in <a href=\"" + (Utilities.isAbsoluteUrl(p) ? "" : prefix) + p + "\">" + cm.getName() + "</a> " + "</li>\r\n");
        }
    }
    for (ConceptMap cm : getConceptMaps().getList()) {
        String p = cm.getUserString("path");
        if (cm.hasTargetUriType() && cm.getTargetUriType().equals(vs.getUrl())) {
            addItem(items, "<li>ConceptMap: Translation target in <a href=\"" + (Utilities.isAbsoluteUrl(p) ? "" : prefix) + p + "\">" + cm.present() + "</a> " + "</li>\r\n");
        } else if (cm.hasTargetCanonicalType() && (cm.getTargetCanonicalType().getValue().equals(vs.getUrl()) || vs.getUrl().endsWith("/" + cm.getTargetCanonicalType().getValue()))) {
            addItem(items, "<li>ConceptMap: Translation target ConceptMap <a href=\"" + (Utilities.isAbsoluteUrl(p) ? "" : prefix) + p + "\">" + cm.getName() + "</a> " + "</li>\r\n");
        }
    }
    for (ResourceDefn r : definitions.getBaseResources().values()) {
        scanForUsage(items, vs, r.getRoot(), r.getName().toLowerCase() + "-definitions.html", prefix);
        scanForOperationUsage(items, vs, r, r.getName().toLowerCase() + "-operation-", prefix);
        scanForProfileUsage(items, vs, r, prefix);
    }
    for (ResourceDefn r : definitions.getResources().values()) {
        scanForUsage(items, vs, r.getRoot(), r.getName().toLowerCase() + "-definitions.html", prefix);
        scanForOperationUsage(items, vs, r, r.getName().toLowerCase() + "-operation-", prefix);
        scanForProfileUsage(items, vs, r, prefix);
    }
    for (ElementDefn e : definitions.getInfrastructure().values()) {
        scanForUsage(items, vs, e, definitions.getSrcFile(e.getName()) + "-definitions.html", prefix);
    }
    for (ElementDefn e : definitions.getTypes().values()) {
        if (!definitions.dataTypeIsSharedInfo(e.getName())) {
            scanForUsage(items, vs, e, definitions.getSrcFile(e.getName()) + "-definitions.html", prefix);
        }
    }
    for (StructureDefinition sd : workerContext.getExtensionDefinitions()) {
        scanForUsage(items, vs, sd, sd.getUserString("path"), prefix);
    }
    for (ValueSet vsi : definitions.getValuesets().getList()) {
        String path = (String) vsi.getUserData("path");
        if (vs.hasCompose()) {
            for (ConceptSetComponent t : vs.getCompose().getInclude()) {
                for (UriType uri : t.getValueSet()) {
                    if (uri.getValue().equals(vs.getUrl())) {
                        addItem(items, "<li>ValueSet: Included in <a href=\"" + prefix + path + "\">" + Utilities.escapeXml(vs.present()) + "</a></li>\r\n");
                    }
                }
            }
            for (ConceptSetComponent t : vs.getCompose().getExclude()) {
                for (UriType uri : t.getValueSet()) {
                    if (uri.getValue().equals(vs.getUrl())) {
                        addItem(items, "<li>ValueSet: Excluded from  <a href=\"" + prefix + path + "\">" + Utilities.escapeXml(vs.present()) + "</a></li>\r\n");
                    }
                }
            }
        // for (ConceptSetComponent t : vsi.getCompose().getInclude()) {
        // if (vs.hasCodeSystem() && t.getSystem().equals(vs.getCodeSystem().getSystem()))
        // b.append(" <li>Included in Valueset <a href=\""+prefix+path+"\">"+Utilities.escapeXml(vs.getName())+"</a></li>\r\n");
        // }
        // for (ConceptSetComponent t : vsi.getCompose().getExclude()) {
        // if (vs.hasCodeSystem() && t.getSystem().equals(vs.getCodeSystem().getSystem()))
        // b.append(" <li>Excluded in Valueset <a href=\""+prefix+path+"\">"+Utilities.escapeXml(vs.getName())+"</a></li>\r\n");
        // }
        }
    }
    if (ini.getPropertyNames(vs.getUrl()) != null) {
        for (String n : ini.getPropertyNames(vs.getUrl())) {
            addItem(items, "<li>" + ini.getStringProperty(vs.getUrl(), n) + "</li>\r\n");
        }
    }
    if (items.size() == 0)
        return "<p>\r\nThis value set is not currently used\r\n</p>\r\n";
    else {
        StringBuilder b = new StringBuilder();
        for (String s : items) {
            b.append(" " + s);
        }
        return (addTitle ? "<p>\r\nThis value set is used in the following places:\r\n</p>\r\n" : "") + "<ul>\r\n" + b.toString() + "</ul>\r\n";
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ArrayList(java.util.ArrayList) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) ValueSet(org.hl7.fhir.r5.model.ValueSet) UriType(org.hl7.fhir.r5.model.UriType)

Example 4 with ConceptSetComponent

use of org.hl7.fhir.dstu2016may.model.ValueSet.ConceptSetComponent in project kindling by HL7.

the class CodeListToValueSetParser method generateConceptMapV2.

private void generateConceptMapV2(String v2map, ValueSet vs, CodeSystem cs) throws Exception {
    ConceptMap cm = new ConceptMap();
    cm.setId("cm-" + vs.getId() + "-v2");
    cm.setVersion(version);
    cm.setUserData("path", cm.getId() + ".html");
    cm.setUserData("generate", true);
    cm.setUrl("http://hl7.org/fhir/ConceptMap/" + cm.getId());
    cm.setName("v2." + vs.getName());
    cm.setTitle("v2 map for " + vs.present());
    cm.setPublisher("HL7 (FHIR Project)");
    for (ContactDetail cc : vs.getContact()) {
        ContactDetail cd = cm.addContact();
        cd.setName(cc.getName());
        for (ContactPoint ccs : cc.getTelecom()) cd.addTelecom(ccs.copy());
    }
    cm.setCopyright(vs.getCopyright());
    // until we publish DSTU, then .review
    cm.setStatus(vs.getStatus());
    cm.setDate(vs.getDate());
    cm.setSource(Factory.newCanonical(vs.getUrl()));
    cm.setTarget(Factory.newCanonical(v2map));
    if (cs != null)
        processV2ConceptDefs(cm, cs.getUrl(), cs.getConcept());
    for (ConceptSetComponent cc : vs.getCompose().getInclude()) for (ConceptReferenceComponent c : cc.getConcept()) {
        processV2Map(cm, cc.getSystem(), c.getCode(), c.getUserString("v2"));
    }
    maps.see(cm, packageInfo);
}
Also used : ContactDetail(org.hl7.fhir.r5.model.ContactDetail) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)

Example 5 with ConceptSetComponent

use of org.hl7.fhir.dstu2016may.model.ValueSet.ConceptSetComponent in project org.hl7.fhir.core by hapifhir.

the class PhinVadsImporter method importValueSet.

private ValueSet importValueSet(byte[] source) throws FHIRException, IOException, ParseException {
    // first thing do is split into 2
    List<byte[]> parts = Utilities.splitBytes(source, "\r\n\r\n".getBytes());
    if (parts.size() < 2) {
        TextFile.bytesToFile(source, Utilities.path("[tmp]", "phinvads.txt"));
        throw new FHIRException("Unable to parse phinvads value set: " + parts.size() + " parts found");
    }
    CSVReader rdr = new CSVReader(new ByteArrayInputStream(parts.get(0)));
    rdr.setDelimiter('\t');
    rdr.setMultiline(true);
    rdr.readHeaders();
    rdr.line();
    ValueSet vs = new ValueSet();
    vs.setId(rdr.cell("Value Set OID"));
    vs.setUrl("http://phinvads.cdc.gov/fhir/ValueSet/" + vs.getId());
    vs.getMeta().setSource("https://phinvads.cdc.gov/vads/ViewValueSet.action?oid=" + vs.getId());
    vs.setVersion(rdr.cell("Value Set Version"));
    vs.setTitle(rdr.cell("Value Set Name"));
    vs.setName(rdr.cell("Value Set Code"));
    vs.setDescription(rdr.cell("Value Set Definition"));
    if ("Published".equals(rdr.cell("Value Set Status"))) {
        vs.setStatus(PublicationStatus.ACTIVE);
    } else {
        vs.setStatus(PublicationStatus.DRAFT);
    }
    if (rdr.has("VS Last Updated Date")) {
        vs.setDate(new SimpleDateFormat("mm/dd/yyyy").parse(rdr.cell("VS Last Updated Date")));
    }
    rdr = new CSVReader(new ByteArrayInputStream(parts.get(parts.size() - 1)));
    rdr.setMultiline(true);
    rdr.setDelimiter('\t');
    rdr.readHeaders();
    while (rdr.line()) {
        String code = rdr.cell("Concept Code");
        String display = rdr.cell("Preferred Concept Name");
        String csoid = rdr.cell("Code System OID");
        String csver = rdr.cell("Code System Version");
        String url = context.oid2Uri(csoid);
        if (url == null) {
            url = "urn:oid:" + csoid;
        }
        csver = fixVersionforSystem(url, csver);
        ConceptSetComponent inc = getInclude(vs, url, csver);
        inc.addConcept().setCode(code).setDisplay(display);
    }
    return vs;
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) CSVReader(org.hl7.fhir.utilities.CSVReader) ByteArrayInputStream(java.io.ByteArrayInputStream) FHIRException(org.hl7.fhir.exceptions.FHIRException) ValueSet(org.hl7.fhir.r5.model.ValueSet) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

ConceptSetComponent (org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent)25 ArrayList (java.util.ArrayList)22 ConceptSetComponent (org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent)21 IOException (java.io.IOException)20 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)20 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)19 FHIRException (org.hl7.fhir.exceptions.FHIRException)17 HashMap (java.util.HashMap)15 ConceptSetComponent (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent)14 ConceptReferenceComponent (org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)14 ValueSet (org.hl7.fhir.r4.model.ValueSet)13 ValueSet (org.hl7.fhir.r5.model.ValueSet)13 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)12 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)12 ConceptSetComponent (org.hl7.fhir.r4b.model.ValueSet.ConceptSetComponent)12 FileNotFoundException (java.io.FileNotFoundException)10 NotImplementedException (org.apache.commons.lang3.NotImplementedException)10 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)10 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)10 ValueSet (org.hl7.fhir.dstu3.model.ValueSet)9