Search in sources :

Example 86 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.

the class PageProcessor method checkFormat.

private void checkFormat(String filename, String res, ResourceDefn r) throws FHIRException {
    XhtmlNode doc;
    try {
        doc = new XhtmlParser().parse("<div>" + res + "</div>", null).getFirstElement();
        if (doc.getFirstElement() == null || !doc.getFirstElement().getName().equals("div"))
            log("file \"" + filename + "\": root element should be 'div'", LogMessageType.Error);
        else if (doc.getFirstElement() == null) {
            log("file \"" + filename + "\": there is no 'Scope and Usage'", LogMessageType.Error);
        } else {
            XhtmlNode scope = null;
            XhtmlNode context = null;
            for (XhtmlNode x : doc.getChildNodes()) {
                if (x.getNodeType() == NodeType.Element) {
                    if (!x.getName().equals("div")) {
                        log("file \"" + filename + "\": all child elements of the root div should be 'div's too (found '" + x.getName() + "')", LogMessageType.Error);
                        return;
                    } else if (x.getChildNodes().isEmpty()) {
                        log("file \"" + filename + "\": div/div[" + Integer.toString(doc.getChildNodes().indexOf(x)) + "] must have at least an h2", LogMessageType.Error);
                        return;
                    } else if (!isFirstChildElementH2(x)) {
                        log("file \"" + filename + "\": div/div[" + Integer.toString(doc.getChildNodes().indexOf(x)) + "] must start with an h2", LogMessageType.Error);
                        return;
                    } else {
                        XhtmlNode fn = getH2Element(x);
                        String s = fn.allText();
                        if (!((s.equals("Scope and Usage")) || (s.equals("Boundaries and Relationships")) || (s.equals("Background and Context")))) {
                            log("file \"" + filename + "\": div/div[" + Integer.toString(doc.getChildNodes().indexOf(x)) + "]/h2 must be either 'Scope and Usage', 'Boundaries and Relationships', or 'Background and Context'", LogMessageType.Error);
                            return;
                        } else {
                            if (scope == null) {
                                if (s.equals("Scope and Usage")) {
                                    scope = x;
                                    if (r != null)
                                        r.setRequirements(new XhtmlComposer(XhtmlComposer.HTML).composePlainText(x));
                                } else {
                                    log("file \"" + filename + "\": 'Scope and Usage' must come first", LogMessageType.Error);
                                    return;
                                }
                                if (s.equals("Boundaries and Relationships")) {
                                    if (context != null) {
                                        log("file \"" + filename + "\": 'Boundaries and Relationships' must come first before 'Background and Context'", LogMessageType.Error);
                                        return;
                                    }
                                }
                                if (s.equals("Background and Context"))
                                    context = x;
                            }
                        }
                        boolean found = false;
                        for (XhtmlNode n : x.getChildNodes()) {
                            if (!found)
                                found = n == fn;
                            else {
                                if ("h1".equals(n.getName()) || "h2".equals(n.getName())) {
                                    log("file \"" + filename + "\": content of a <div> inner section cannot contain h1 or h2 headings", LogMessageType.Error);
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
        List<String> allowed = Arrays.asList("div", "h2", "h3", "h4", "h5", "i", "b", "code", "pre", "blockquote", "p", "a", "img", "table", "thead", "tbody", "tr", "th", "td", "ol", "ul", "li", "br", "span", "em", "strong");
        iterateAllChildNodes(doc, allowed);
    } catch (Exception e) {
        throw new FHIRException("Error processing " + filename + ": " + e.getMessage(), e);
    }
}
Also used : XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) FHIRException(org.hl7.fhir.exceptions.FHIRException) UcumException(org.fhir.ucum.UcumException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FileNotFoundException(java.io.FileNotFoundException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 87 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.

the class PageProcessor method allParamlist.

private String allParamlist() {
    ResourceDefn rd = definitions.getBaseResources().get("Resource");
    List<String> names = new ArrayList<String>();
    names.addAll(rd.getSearchParams().keySet());
    Collections.sort(names);
    CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
    for (String n : names) b.append("<code>" + n + "</code>");
    return b.toString();
}
Also used : ArrayList(java.util.ArrayList) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 88 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.

the class PageProcessor method genProfilelist.

private String genProfilelist() throws Exception {
    StringBuilder b = new StringBuilder();
    b.append("<table class=\"grid\">\r\n");
    b.append("  <tr>\r\n");
    b.append("    <td><b>Name</b></td>\r\n");
    b.append("    <td><b>Description</b></td>\r\n");
    b.append("    <td><b>Kind</b></td>\r\n");
    b.append("    <td><b><a href=\"versions.html#Maturity\">FMM</a></b></td>");
    b.append("  </tr>\r\n");
    b.append("  <tr>\r\n");
    b.append("    <td colspan=\"2\"><b>General</b></td>\r\n");
    b.append("  </tr>\r\n");
    List<String> names = new ArrayList<String>();
    names.addAll(definitions.getPackMap().keySet());
    Collections.sort(names);
    for (String s : names) {
        Profile ap = definitions.getPackMap().get(s);
        ImplementationGuideDefn ig = definitions.getIgs().get(ap.getCategory());
        b.append("  <tr>\r\n");
        b.append("    <td><a href=\"").append(ig.getPrefix() + ap.getId().toLowerCase()).append(".html\">").append(Utilities.escapeXml(ap.getTitle())).append("</a></td>\r\n");
        b.append("    <td>").append(Utilities.escapeXml(ap.getDescription())).append("</td>\r\n");
        b.append("    <td>").append(Utilities.escapeXml(ap.describeKind())).append("</td>\r\n");
        b.append("    <td>").append(Utilities.escapeXml(ap.getFmmLevel())).append("</td>\r\n");
        b.append(" </tr>\r\n");
    }
    for (String n : definitions.sortedResourceNames()) {
        ResourceDefn r = definitions.getResourceByName(n);
        if (!r.getConformancePackages().isEmpty()) {
            b.append("  <tr>\r\n");
            b.append("    <td colspan=\"4\"><b>" + r.getName() + "</b></td>\r\n");
            b.append("  </tr>\r\n");
            for (Profile p : r.getConformancePackages()) {
                ImplementationGuideDefn ig = definitions.getIgs().get(p.getCategory());
                b.append("  <tr>\r\n");
                b.append("    <td><a href=\"" + ig.getPrefix() + p.getId().toLowerCase() + ".html\">" + Utilities.escapeXml(p.getTitle()) + "</a></td>\r\n");
                b.append("    <td>" + Utilities.escapeXml(p.getDescription()) + "</td>\r\n");
                b.append("    <td>" + Utilities.escapeXml(p.describeKind()) + "</td>\r\n");
                b.append("    <td>" + Utilities.escapeXml(p.getFmmLevel()) + "</td>\r\n");
                b.append(" </tr>\r\n");
            }
        }
    }
    b.append("</table>\r\n");
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ArrayList(java.util.ArrayList) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) Profile(org.hl7.fhir.definitions.model.Profile)

Example 89 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.

the class PageProcessor method genLogicalMappings.

private String genLogicalMappings(ResourceDefn logical, String genlevel) throws FHIRException {
    String url = logical.getMappingUrl();
    StringBuilder b = new StringBuilder();
    b.append("<table class=\"lmap\">");
    b.append(" <tr>");
    b.append("  <th></th>\r\n");
    List<ElementDefn> elements = new ArrayList<ElementDefn>();
    listAllElements(elements, logical.getRoot().getName(), logical.getRoot());
    for (ElementDefn e : elements) {
        if (logical.getRoot().getElements().contains(e)) {
            b.append("<td><a href=\"" + logical.getName().toLowerCase() + "-definitions.html#" + e.getPath() + "\">" + e.getName() + "</a></td>\r\n");
        } else {
            b.append("<td><a href=\"" + logical.getName().toLowerCase() + "-definitions.html#" + e.getPath() + "\">." + e.getName() + "</a></td>\r\n");
        }
    }
    b.append(" </tr>\r\n");
    boolean any = false;
    for (String s : sorted(definitions.getResources().keySet())) {
        ResourceDefn rd = definitions.getResourceByName(s);
        StructureDefinition sd = rd.getProfile();
        String code = null;
        for (StructureDefinitionMappingComponent m : sd.getMapping()) {
            if (m.getUri().equals(url))
                code = m.getIdentity();
        }
        if (code != null) {
            if (hasLogicalMapping(sd, logical, code)) {
                any = true;
                b.append(" <tr>\r\n");
                b.append("  <td><a href=\"" + rd.getName().toLowerCase() + ".html\">" + rd.getName() + "</a></td>\r\n");
                for (ElementDefn e : elements) {
                    populateLogicalMappingColumn(b, logical.getRoot().getName(), rd.getName().toLowerCase() + "-definitions.html#", e, sd, rd.getName(), code, url, null, null, null);
                }
                b.append(" </tr>\r\n");
            }
        }
    }
    b.append("</table>\r\n");
    if (any)
        return "<a name=\"mappings\"></a><h3>Mappings</h3>\r\n\r\n" + b.toString();
    else
        return "";
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) StructureDefinitionMappingComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ArrayList(java.util.ArrayList) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 90 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.

the class PageProcessor method buildResListBySecurity.

private String buildResListBySecurity() throws FHIRException {
    List<String> res = new ArrayList<String>();
    for (ResourceDefn rd : definitions.getResources().values()) res.add((rd.getSecurityCategorization() == null ? "9" : rd.getSecurityCategorization().toIndex()) + ":" + rd.getName());
    Collections.sort(res);
    StringBuilder b = new StringBuilder();
    for (int i = 0; i <= 5; i++) {
        b.append("<p><b>" + secCategory(i));
        b.append("</b></p>\r\n<ul style=\"width: 90%; -moz-column-count: 4; -moz-column-gap: 10px; -webkit-column-count: 4; -webkit-column-gap: 10px; column-count: 4; column-gap: 10px\">\r\n");
        for (String rn : res) {
            if (rn.startsWith(Integer.toString(i))) {
                String r = rn.substring(2);
                ResourceDefn rd = definitions.getResourceByName(r);
                if (rd.getNormativePackage() != null || rd.getNormativeVersion() != null)
                    b.append("  <li><a title=\"[%resdesc " + r + "%]\" href=\"" + r.toLowerCase() + ".html\">" + r + "</a> <a href=\"versions.html#std-process\"  title=\"Normative Content\" class=\"normative-flag\">N</a></li>\r\n");
                else
                    b.append("  <li><a title=\"[%resdesc " + r + "%]\" href=\"" + r.toLowerCase() + ".html\">" + r + "</a></li>\r\n");
            }
        }
        b.append("</ul>\r\n");
    }
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ArrayList(java.util.ArrayList) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) ContactPoint(org.hl7.fhir.r5.model.ContactPoint)

Aggregations

ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)75 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)42 ArrayList (java.util.ArrayList)38 FHIRException (org.hl7.fhir.exceptions.FHIRException)36 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)31 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)28 File (java.io.File)26 FileOutputStream (java.io.FileOutputStream)25 CSFile (org.hl7.fhir.utilities.CSFile)24 XmlParser (org.hl7.fhir.r5.formats.XmlParser)22 FileNotFoundException (java.io.FileNotFoundException)20 IOException (java.io.IOException)20 Example (org.hl7.fhir.definitions.model.Example)20 Profile (org.hl7.fhir.definitions.model.Profile)20 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)18 IniFile (org.hl7.fhir.utilities.IniFile)18 ImplementationGuideDefn (org.hl7.fhir.definitions.model.ImplementationGuideDefn)16 TransformerException (javax.xml.transform.TransformerException)15 TextFile (org.hl7.fhir.utilities.TextFile)15 SearchParameterDefn (org.hl7.fhir.definitions.model.SearchParameterDefn)14