Search in sources :

Example 36 with ValueSet

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

the class TerminologyNotesGenerator method describeBinding.

public static String describeBinding(String prefix, ElementDefinitionBindingComponent def, PageProcessor page) throws Exception {
    if (!def.hasValueSet())
        return def.getDescription();
    String ref = def.getValueSet();
    ValueSet vs = page.getValueSets().get(ref);
    if (vs != null) {
        String pp = vs.hasUserData("external.url") ? vs.getUserString("external.url") : vs.getUserString("path");
        return def.getDescription() + "<br/>" + conf(def) + "<a href=\"" + (Utilities.isAbsoluteUrl(pp) ? "" : prefix) + pp.replace(File.separatorChar, '/') + "\">" + vs.present() + "</a>" + confTail(def);
    }
    if (ref.startsWith("http:") || ref.startsWith("https:"))
        return def.getDescription() + "<br/>" + conf(def) + " <a href=\"" + ref + "\">" + ref + "</a>" + confTail(def);
    else
        return def.getDescription() + "<br/>" + conf(def) + " ?? Broken Reference to " + ref + " ??" + confTail(def);
}
Also used : ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 37 with ValueSet

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

the class TerminologyNotesGenerator method gen.

private void gen(String prefix, Map<BindingSpecification, List<CDUsage>> txusages2) throws Exception {
    List<BindingSpecification> cds = new ArrayList<BindingSpecification>();
    cds.addAll(txusages.keySet());
    if (cds.size() == 0)
        return;
    Collections.sort(cds, new MyCompare());
    if (noHeader)
        write("<p>\r\n<b>Terminology Bindings</b>\r\n</p>\r\n");
    else
        write("<h3>\r\nTerminology Bindings\r\n</h3>\r\n");
    // 1. new form
    write("<table class=\"grid\">\r\n");
    write(" <tr><th>Path</th><th>Definition</th><th>Type</th><th>Reference</th></tr>\r\n");
    for (BindingSpecification cd : cds) {
        String path;
        List<CDUsage> list = txusages.get(cd);
        for (int i = 2; i < list.size(); i++) {
            if (!matchesTypes(list.get(i).element.typeCodeNoParams(), list.get(1).element.typeCodeNoParams()))
                throw new Exception("Mixed types on one concept domain in one type - not yet supported by the build process for binding " + cd.getName() + " (" + list.get(i).element.typeCode() + " vs " + list.get(1).element.typeCode() + ")");
        }
        String name = cd.getValueSet() != null ? cd.getValueSet().present() : cd.getName();
        write(" <tr><td valign=\"top\" title=\"" + name + "\">");
        boolean first = true;
        for (int i = 1; i < list.size(); i++) {
            if (!first)
                write("<br/>");
            first = false;
            write(list.get(i).path);
        }
        write(" </td>");
        write("<td valign=\"top\">" + Utilities.escapeXml(cd.getDefinition()) + "</td>");
        if (cd.getBinding() == BindingMethod.Unbound)
            write("<td>Unknown</td><td valign=\"top\">No details provided yet</td>");
        else {
            if (cd.hasMax()) {
                ValueSet vs = cd.getMaxValueSet();
                if (vs == null) {
                    write("<td><a href=\"" + prefix + "terminologies.html#" + cd.getStrength().toCode() + "\">" + cd.getStrength().getDisplay() + "</a>, but limited to <a href=\"" + cd.getMaxReference() + "\">" + cd.getMaxReference() + "</a></td>");
                } else {
                    String pp = vs.hasUserData("external.url") ? vs.getUserString("external.url") : vs.getUserString("path");
                    write("<td><a href=\"" + prefix + "terminologies.html#" + cd.getStrength().toCode() + "\">" + cd.getStrength().getDisplay() + "</a>, but limited to <a href=\"" + prefix + pp.replace(File.separatorChar, '/') + "\">" + vs.getName() + "</a></td>");
                }
            } else
                write("<td><a href=\"" + prefix + "terminologies.html#" + cd.getStrength().toCode() + "\">" + cd.getStrength().getDisplay() + "</a></td>");
            write("<td valign=\"top\">");
            if (cd.getBinding() == BindingSpecification.BindingMethod.Special) {
                if (name.equals("MessageEvent"))
                    write("<a href=\"" + prefix + "valueset-message-events.html\">Message Events</a>");
                else if (name.equals("ResourceType"))
                    write("<a href=\"" + prefix + "valueset-resource-types.html\">Resource Types</a>");
                else if (name.equals("DataType"))
                    write("<a href=\"" + prefix + "valueset-data-types.html\">Data Types</a>");
                else if (name.equals("FHIRDefinedType"))
                    write("<a href=\"" + prefix + "valueset-defined-types.html\">Defined Types</a>");
                else if (name.equals("FHIRAllTypes"))
                    write("<a href=\"" + prefix + "valueset-all-types.html\">All Types</a>");
                else
                    throw new Exception("Unknown special type " + name);
            } else if (cd.getValueSet() != null) {
                ValueSet vs = cd.getValueSet();
                String pp = vs.hasUserData("external.url") ? vs.getUserString("external.url") : vs.getUserString("path");
                if (pp == null)
                    throw new Exception("unknown path on " + cd.getReference());
                write("<a href=\"" + prefix + pp.replace(File.separatorChar, '/') + "\">" + vs.getName() + "</a><!-- b -->");
            } else if (cd.getBinding() == BindingSpecification.BindingMethod.ValueSet) {
                if (Utilities.noString(cd.getReference()))
                    write("??");
                else if (cd.getReference().startsWith("valueset-"))
                    write("<a href=\"" + prefix + cd.getReference() + ".html\">http://hl7.org/fhir/ValueSet/" + cd.getReference().substring(9) + "</a><!-- a -->");
                else if (cd.getReference().startsWith("http://hl7.org/fhir")) {
                    if (cd.getReference().startsWith("http://terminology.hl7.org/ValueSet/v3-")) {
                        ValueSet vs = page.getValueSets().get(cd.getReference());
                        String pp = vs.hasUserData("external.url") ? vs.getUserString("external.url") : vs.getUserString("path");
                        if (pp == null)
                            throw new Exception("unknown path on " + cd.getReference());
                        write("<a href=\"" + prefix + pp.replace(File.separatorChar, '/') + "\">" + cd.getReference() + "</a><!-- b -->");
                    } else if (cd.getReference().startsWith("http://terminology.hl7.org/ValueSet/v2-")) {
                        ValueSet vs = page.getValueSets().get(cd.getReference());
                        String pp = vs.hasUserData("external.url") ? vs.getUserString("external.url") : vs.getUserString("path");
                        write("<a href=\"" + prefix + pp.replace(File.separatorChar, '/') + "\">" + cd.getReference() + "</a><!-- c -->");
                    } else if (cd.getReference().startsWith("http://hl7.org/fhir/ValueSet/")) {
                        String ref = getBindingLink(cd);
                        write("<a href=\"" + prefix + ref + "\">" + cd.getReference() + "</a><!-- d -->");
                    // BindingSpecification bs1 = page.getDefinitions().getBindingByURL(cd.getReference());
                    // if (bs1 != null)
                    // write("<a href=\""+cd.getReference().substring(23)+".html\">"+cd.getReference()+"</a><!-- d -->");
                    // else
                    // write("<a href=\"valueset-"+cd.getReference().substring(23)+".html\">"+cd.getReference()+"</a><!-- d -->");
                    } else
                        throw new Exception("Internal reference " + cd.getReference() + " not handled yet");
                } else if (cd.getReference().startsWith("http:"))
                    write("<a href=\"" + cd.getReference() + "\">" + cd.getReference() + "</a><!-- e -->");
                else
                    write("<a href=\"" + prefix + "valueset-" + cd.getReference() + ".html\">http://hl7.org/fhir/" + cd.getReference() + "</a><!-- e -->");
            } else if (cd.getBinding() == BindingSpecification.BindingMethod.CodeList) {
                write("<a href=\"" + prefix + "valueset-" + cd.getReference().substring(1) + ".html\">http://hl7.org/fhir/" + cd.getReference().substring(1) + "</a><!-- f -->");
            }
            write("</td>");
        }
        write(" </tr>\r\n");
    }
    write("</table>\r\n<p> </p>\r\n");
}
Also used : BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) ArrayList(java.util.ArrayList) ValueSet(org.hl7.fhir.r5.model.ValueSet) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 38 with ValueSet

use of org.hl7.fhir.r4.model.ValueSet 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 39 with ValueSet

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

the class CodeSystemConvertor method convert.

public void convert(IParser p, ValueSet vs, String name, PackageVersion packageInfo) throws Exception {
    String nname = name.replace("valueset-", "codesystem-");
    if (nname.equals(name))
        nname = Utilities.changeFileExt(name, "-cs.xml");
    if (new File(nname).exists()) {
        FileInputStream input = new FileInputStream(nname);
        CodeSystem cs = CodeSystemUtilities.makeShareable((CodeSystem) p.parse(input));
        if (!cs.hasTitle())
            cs.setTitle(Utilities.capitalize(Utilities.unCamelCase(cs.getName())));
        populate(cs, vs);
        // if (codeSystems.containsKey(cs.getUrl()))
        // throw new Exception("Duplicate Code System: "+cs.getUrl());
        codeSystems.see(cs, packageInfo);
    }
}
Also used : File(java.io.File) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) FileInputStream(java.io.FileInputStream)

Example 40 with ValueSet

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

the class CodeSystemConvertor method populate.

public static void populate(CodeSystem cs, ValueSet vs) {
    if (!vs.hasName())
        throw new Error("No name vs " + vs.getUrl());
    if (!vs.hasDescription())
        throw new Error("No description vs " + vs.getUrl());
    if (cs.getUserData("conv-vs") != null)
        throw new Error("This code system has already been converted");
    cs.setUserData("conv-vs", "done");
    vs.setUserData("cs", cs);
    if (vs.hasUserData("filename"))
        cs.setUserData("filename", vs.getUserString("filename").replace("valueset-", "codesystem-"));
    if (vs.hasUserData("path"))
        cs.setUserData("path", vs.getUserString("path").replace("valueset-", "codesystem-"));
    if (vs.hasUserData("committee"))
        cs.setUserData("committee", vs.getUserData("committee"));
    cs.setId(vs.getId());
    cs.setVersion(vs.getVersion());
    cs.setName(vs.getName());
    cs.setTitle(vs.getTitle());
    cs.setStatus(vs.getStatus());
    cs.setExperimentalElement(vs.getExperimentalElement());
    cs.setPublisher(vs.getPublisher());
    for (ContactDetail csrc : vs.getContact()) {
        ContactDetail ctgt = cs.addContact();
        ctgt.setName(csrc.getName());
        for (ContactPoint cc : csrc.getTelecom()) ctgt.addTelecom(cc);
    }
    cs.setDate(vs.getDate());
    cs.setDescription(vs.getDescription());
    cs.getDescriptionElement().getExtension().addAll(vs.getDescriptionElement().getExtension());
    for (UsageContext cc : vs.getUseContext()) cs.addUseContext(cc);
    cs.setPurpose(vs.getPurpose());
    cs.setCopyright(vs.getCopyright());
    if (vs.hasCompose() && vs.getCompose().getInclude().size() == 1 && vs.getCompose().getExclude().size() == 0 && vs.getCompose().getInclude().get(0).getSystem().equals(cs.getUrl()) && !vs.getCompose().getInclude().get(0).hasValueSet() && !vs.getCompose().getInclude().get(0).hasConcept() && !vs.getCompose().getInclude().get(0).hasFilter())
        cs.setValueSet(vs.getUrl());
    vs.setImmutable(true);
}
Also used : ContactDetail(org.hl7.fhir.r5.model.ContactDetail) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) UsageContext(org.hl7.fhir.r5.model.UsageContext)

Aggregations

ValueSet (org.hl7.fhir.r5.model.ValueSet)159 ValueSet (org.hl7.fhir.r4.model.ValueSet)116 Test (org.junit.jupiter.api.Test)115 ArrayList (java.util.ArrayList)101 FHIRException (org.hl7.fhir.exceptions.FHIRException)100 IOException (java.io.IOException)97 ValueSet (org.hl7.fhir.dstu3.model.ValueSet)59 ValueSet (org.hl7.fhir.r4b.model.ValueSet)59 FileNotFoundException (java.io.FileNotFoundException)58 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)56 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)46 HashMap (java.util.HashMap)45 Test (org.junit.Test)45 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)43 File (java.io.File)36 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)36 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)31 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)29 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)29 FileInputStream (java.io.FileInputStream)27