Search in sources :

Example 11 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source 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 12 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project kindling by HL7.

the class PageProcessor method genConceptMapsTable.

private String genConceptMapsTable() throws Exception {
    StringBuilder s = new StringBuilder();
    s.append("<table class=\"codes\">\r\n");
    s.append(" <tr><td><b>Name</b></td><td><b>Source</b></td><td><b>Target</b></td></tr>\r\n");
    List<String> sorts = new ArrayList<String>();
    sorts.addAll(conceptMaps.keys());
    Collections.sort(sorts);
    for (String sn : sorts) {
        ConceptMap ae = conceptMaps.get(sn);
        // String n = sn.substring(23);
        ConceptMap cm = ae;
        s.append(" <tr><td><a href=\"").append(ae.getUserData("path")).append("\">").append(cm.getName()).append("</a></td>").append("<td><a href=\"").append(getValueSetRef("", cm.hasSourceCanonicalType() ? (cm.getSourceCanonicalType()).getValue() : cm.getSourceUriType().asStringValue())).append("\">").append(describeValueSetByRef(cm.getSource())).append("</a></td>").append("<td><a href=\"").append(getValueSetRef("", cm.hasTargetCanonicalType() ? (cm.getTargetCanonicalType()).getValue() : cm.getTargetUriType().asStringValue())).append("\">").append(describeValueSetByRef(cm.getTarget())).append("</a></td></tr>\r\n");
    }
    s.append("</table>\r\n");
    return s.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ArrayList(java.util.ArrayList) ConceptMap(org.hl7.fhir.r5.model.ConceptMap)

Example 13 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project kindling by HL7.

the class DSTU3ValidationConvertor method convert.

public void convert(String bundleSource, String bundleTarget) throws Exception {
    System.out.println("Convert " + bundleSource);
    try {
        source = (Bundle) new XmlParser().parse(new FileInputStream(bundleSource));
        org.hl7.fhir.dstu3.model.Bundle target = Bundle30_50.convertBundle(source);
        new org.hl7.fhir.dstu3.formats.XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(bundleTarget), target);
    } catch (Exception e) {
        throw new Exception(e);
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) FileOutputStream(java.io.FileOutputStream) FileInputStream(java.io.FileInputStream)

Example 14 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project kindling by HL7.

the class CKMImporter method processArchetype.

private void processArchetype(String id) throws Exception {
    String cfg = info == null ? null : Utilities.path(info, id + ".config");
    String src = Utilities.path(dest, id + ".xml");
    String dst = Utilities.path(dest, id.substring(id.indexOf(".") + 1) + ".xml");
    if (new File(dst).exists())
        System.out.println(id + " Already Processed");
    else {
        System.out.print("Process " + id + ": ");
        try {
            if (!new File(src).exists())
                downloadArchetype(id);
            if (cfg != null && new File(cfg).exists())
                ADLImporter.main(new String[] { "-source", src, "-dest", dst, "-config", config, "-info", cfg });
            else
                ADLImporter.main(new String[] { "-source", src, "-dest", dst, "-config", config });
            System.out.println("  ok");
        } catch (Exception e) {
            System.out.println("  error - " + e.getMessage());
        }
    }
}
Also used : File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile)

Example 15 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project kindling by HL7.

the class HTMLLinkChecker method check.

private void check(XhtmlNode node, String href, String base, String source) throws FileNotFoundException, Exception {
    if (href == null)
        throw new Exception("no ref at " + node.allText());
    if (href.startsWith("http:") || href.startsWith("https:") || href.startsWith("ftp:") || href.startsWith("mailto:"))
        return;
    String path = href;
    String anchor = null;
    if (href.contains("#")) {
        path = href.substring(0, href.indexOf("#"));
        anchor = href.substring(href.indexOf("#") + 1);
    }
    Entry e;
    if (!Utilities.noString(path)) {
        if (href.endsWith("qa.html") || href.endsWith(".epub.zip"))
            return;
        if ("self-link".equals(node.getAttribute("class")))
            return;
        String target = collapse(base, path, source);
        if (target.endsWith(".xml") || target.endsWith(".json") || target.endsWith(".jsonld") || target.endsWith(".xsd") || target.endsWith(".shex") || target.endsWith(".txt") || target.endsWith(".sch") || target.endsWith(".pdf") || target.endsWith(".epub")) {
            if (!(new File(Utilities.path(page.getFolders().dstDir, target)).exists()))
                reportError(base, "Broken Link (1) in " + base + ": '" + href + "' not found at \"" + Utilities.path(page.getFolders().dstDir, target) + "\" (" + node.allText() + ")");
            node.setAttribute("href", webPath + "/" + target.replace(File.separatorChar, '/'));
            e = null;
        } else if (externals.contains(target)) {
            node.setAttribute("href", webPath + "/" + target.replace(File.separatorChar, '/'));
            e = null;
        } else {
            e = getEntryForFile(target, source);
            if (e == null) {
                if (// we can't check those links
                href.startsWith("v2/") || href.startsWith("v3/"))
                    return;
                if (target.endsWith(".zip") || target.endsWith(".ttl") || target.endsWith(".jar") || target.endsWith(".cfm") || target.endsWith(".tgz") || target.endsWith(".xlsx"))
                    return;
                reportError(base, "Broken Link (2) in " + base + ": '" + href + "' not found at \"" + target + "\"(" + node.allText() + ")");
                return;
            } else if (!e.include) {
                node.setAttribute("href", webPath + "/" + node.getAttribute("href"));
            }
        }
    } else
        e = getEntryForFile(base, source);
    if (Utilities.noString(anchor)) {
    // if (e == null) - need to enable this an fix everything it finds
    // reportError("Broken Link in "+base+": '"+href+"' anchor not found ("+node.allText()+")");
    } else {
        if (e != null) {
            if (!e.checked)
                check(e);
        // td        if (!e.anchors.contains(anchor))
        // td          reportError("Broken Link in "+base+": '"+href+"' anchor not found ("+node.allText()+")");
        }
    }
}
Also used : File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)125 FileInputStream (java.io.FileInputStream)59 FileOutputStream (java.io.FileOutputStream)55 IOException (java.io.IOException)55 ArrayList (java.util.ArrayList)48 File (java.io.File)45 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)45 TextFile (org.hl7.fhir.utilities.TextFile)41 CSFile (org.hl7.fhir.utilities.CSFile)35 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)35 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)30 XmlParser (org.hl7.fhir.r5.formats.XmlParser)28 Date (java.util.Date)27 HashMap (java.util.HashMap)26 Reference (org.hl7.fhir.r4.model.Reference)26 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)24 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)24 Coding (org.hl7.fhir.r4.model.Coding)24 JsonObject (com.google.gson.JsonObject)22 NotImplementedException (org.apache.commons.lang3.NotImplementedException)22