Search in sources :

Example 86 with Resource

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

the class PageProcessor method profileDictionaryLink.

private String profileDictionaryLink(ConstraintStructure profile) {
    String uri = ToolingExtensions.readStringExtension(profile.getResource(), "http://hl7.org/fhir/StructureDefinition/datadictionary");
    if (Utilities.noString(uri))
        return "<!-- no uri -->";
    Dictionary dict = definitions.getDictionaries().get(uri);
    if (dict == null)
        return "<p>This profile specifies that the value of the " + profile.getResource().getSnapshot().getElement().get(0).getPath() + " resource must be a valid Observation as defined in the data dictionary (Unknown? - " + uri + ").</p>";
    else
        return "<p>This profile specifies that the value of the " + profile.getResource().getSnapshot().getElement().get(0).getPath() + " resource must be a valid Observation as defined in the data dictionary <a href=\"" + uri + ".html\">" + dict.getName() + "</a>.</p>";
}
Also used : Dictionary(org.hl7.fhir.definitions.model.Dictionary)

Example 87 with Resource

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

the class PageProcessor method processProfileIncludes.

public String processProfileIncludes(String filename, String fileid, Profile pack, ConstraintStructure profile, String xml, String json, String tx, String src, String master, String path, String intro, String notes, ImplementationGuideDefn ig, boolean isDict, boolean hasNarrative) throws Exception {
    String workingTitle = null;
    int level = (ig == null || ig.isCore()) ? 0 : 1;
    while (src.contains("<%") || src.contains("[%")) {
        int i1 = src.indexOf("<%");
        int i2 = src.indexOf("%>");
        if (i1 == -1) {
            i1 = src.indexOf("[%");
            i2 = src.indexOf("%]");
        }
        String s1 = src.substring(0, i1);
        String s2 = src.substring(i1 + 2, i2).trim();
        String s3 = src.substring(i2 + 2);
        String[] com = s2.split(" ");
        if (com[0].equals("profileheader"))
            src = s1 + profileHeader(fileid, com.length > 1 ? com[1] : "", hasExamples(pack)) + s3;
        else if (com[0].equals("file")) {
            if (new File(folders.templateDir + com[1] + ".html").exists()) {
                src = s1 + TextFile.fileToString(folders.templateDir + com[1] + ".html") + s3;
            } else {
                src = s1 + TextFile.fileToString(folders.srcDir + com[1] + ".html") + s3;
            }
        } else if (com[0].equals("settitle")) {
            workingTitle = s2.substring(9).replace("{", "<%").replace("}", "%>");
            src = s1 + s3;
        } else if (com.length != 1)
            throw new Exception("Instruction <%" + s2 + "%> not understood parsing resource " + filename);
        else if (com[0].equals("pageheader"))
            src = s1 + pageHeader(pack.metadata("name")) + s3;
        else if (com[0].equals("level"))
            src = s1 + genlevel(level) + s3;
        else if (com[0].equals("newheader"))
            src = s1 + TextFile.fileToString(folders.srcDir + "newheader.html") + s3;
        else if (com[0].equals("newheader1"))
            src = s1 + TextFile.fileToString(folders.srcDir + "newheader1.html") + s3;
        else if (com[0].equals("footer"))
            src = s1 + TextFile.fileToString(folders.srcDir + "footer.html") + s3;
        else if (com[0].equals("newfooter"))
            src = s1 + TextFile.fileToString(folders.srcDir + "newfooter.html") + s3;
        else if (com[0].equals("footer1"))
            src = s1 + TextFile.fileToString(folders.srcDir + "footer1.html") + s3;
        else if (com[0].equals("footer2"))
            src = s1 + TextFile.fileToString(folders.srcDir + "footer2.html") + s3;
        else if (com[0].equals("footer3"))
            src = s1 + TextFile.fileToString(folders.srcDir + "footer3.html") + s3;
        else if (com[0].equals("title"))
            src = s1 + (workingTitle == null ? Utilities.escapeXml("StructureDefinition: " + profile.getTitle()) : workingTitle) + s3;
        else if (com[0].equals("xtitle"))
            src = s1 + (workingTitle == null ? Utilities.escapeXml("StructureDefinition: " + profile.getTitle()) : Utilities.escapeXml(workingTitle)) + s3;
        else if (com[0].equals("profiletitle"))
            src = s1 + Utilities.escapeXml(pack.metadata("name")) + s3;
        else if (com[0].equals("filetitle"))
            src = s1 + (filename.contains(".") ? filename.substring(0, filename.lastIndexOf(".")) : filename) + s3;
        else if (com[0].equals("name"))
            src = s1 + filename + s3;
        else if (com[0].equals("date")) {
            if (!Utilities.noString(pack.metadata("date"))) {
                Date d = new SimpleDateFormat("yyyy-MM-dd").parse(pack.metadata("date"));
                src = s1 + Config.DATE_FORMAT().format(d) + s3;
            } else
                src = s1 + "[no date]" + s3;
        } else if (com[0].equals("version"))
            src = s1 + ini.getStringProperty("FHIR", "version") + s3;
        else if (com[0].equals("gendate"))
            src = s1 + Config.DATE_FORMAT().format(new Date()) + s3;
        else if (com[0].equals("definition"))
            src = s1 + Utilities.escapeXml(pack.metadata("description")) + s3;
        else if (com[0].equals("status"))
            src = s1 + describeStatus(pack.metadata("status")) + s3;
        else if (com[0].equals("author"))
            src = s1 + Utilities.escapeXml(pack.metadata("author.name")) + s3;
        else if (com[0].equals("xml"))
            src = s1 + xml + s3;
        else if (com[0].equals("json"))
            src = s1 + json + s3;
        else if (com[0].equals("profiledesc")) {
            src = s1 + Utilities.escapeXml(profile.getResource().getDescription()) + s3;
        } else if (com[0].equals("tx"))
            src = s1 + tx + s3;
        else if (com[0].equals("inv"))
            src = s1 + genProfileConstraints(profile.getResource()) + s3;
        else if (com[0].equals("plural"))
            src = s1 + Utilities.pluralizeMe(filename) + s3;
        else if (com[0].equals("notes"))
            src = s1 + "todo" + /*Utilities.fileToString(folders.srcDir + filename+File.separatorChar+filename+".html")*/
            s3;
        else if (com[0].equals("dictionary"))
            src = s1 + "todo" + s3;
        else if (com[0].equals("breadcrumb"))
            src = s1 + breadCrumbManager.make(filename) + s3;
        else if (com[0].equals("navlist"))
            src = s1 + breadCrumbManager.navlist(filename, genlevel(level)) + s3;
        else if (com[0].equals("breadcrumblist"))
            src = s1 + ((ig == null || ig.isCore()) ? breadCrumbManager.makelist(filename, "profile:" + path, genlevel(0), profile.getResource().getName()) : ig.makeList(filename, "profile:" + path, genlevel(level), profile.getResource().getName())) + s3;
        else if (com[0].equals("year"))
            src = s1 + new SimpleDateFormat("yyyy").format(new Date()) + s3;
        else if (com[0].equals("buildId"))
            src = s1 + buildId + s3;
        else if (com[0].equals("level"))
            src = s1 + genlevel(0) + s3;
        else if (com[0].equals("pub-type"))
            src = s1 + publicationType + s3;
        else if (com[0].equals("pub-notice"))
            src = s1 + publicationNotice + s3;
        else if (com[0].equals("profileurl"))
            src = s1 + profile.getResource().getUrl() + s3;
        else if (com[0].equals("baseURL"))
            src = s1 + Utilities.URLEncode(baseURL) + s3;
        else if (com[0].equals("baseURLn"))
            src = s1 + Utilities.appendForwardSlash(baseURL) + s3;
        else if (com[0].equals("base-link"))
            src = s1 + baseLink(profile.getResource(), genlevel(level)) + s3;
        else if (com[0].equals("profile-structure-table-diff"))
            src = s1 + generateProfileStructureTable(profile, true, filename, pack.getId(), genlevel(level)) + s3;
        else if (com[0].equals("profile-structure-table"))
            src = s1 + generateProfileStructureTable(profile, false, filename, pack.getId(), genlevel(level)) + s3;
        else if (com[0].equals("maponthispage"))
            src = s1 + mapOnPageProfile(profile.getResource()) + s3;
        else if (com[0].equals("mappings"))
            src = s1 + mappingsProfile(profile.getResource()) + s3;
        else if (com[0].equals("definitions"))
            src = s1 + definitionsProfile(profile.getResource(), genlevel(level)) + s3;
        else if (com[0].equals("profile.review"))
            src = s1 + profileReviewLink(profile) + s3;
        else if (com[0].equals("profile.datadictionary"))
            src = s1 + profileDictionaryLink(profile) + s3;
        else if (com[0].equals("profile.tx"))
            src = s1 + getTerminologyNotes(profile.getResource(), level) + s3;
        else if (com[0].equals("profile.inv"))
            src = s1 + getInvariantList(profile.getResource()) + s3;
        else if (com[0].equals("draft-note"))
            src = s1 + getDraftNote(pack, genlevel(level)) + s3;
        else if (com[0].equals("pagepath"))
            src = s1 + filename + s3;
        else if (com[0].equals("rellink")) {
            if (!filename.contains(".html"))
                src = s1 + filename + ".html" + s3;
            else
                src = s1 + filename + s3;
        } else if (com[0].equals("schematron"))
            src = s1 + (isDict ? "<i>None</i>" : "<a href=\"" + filename + ".sch\">Schematron</a>") + s3;
        else if (com[0].equals("summary"))
            src = s1 + generateHumanSummary(profile.getResource(), genlevel(level)) + s3;
        else if (com[0].equals("profile-examples"))
            src = s1 + generateProfileExamples(pack, profile) + s3;
        else if (com[0].equals("profile-extensions-table"))
            src = s1 + "<p><i>Todo</i></p>" + s3;
        else if (com[0].equals("definitionsonthispage"))
            src = s1 + "<p><i>Todo</i></p>" + s3;
        else if (com[0].equals("profile.intro"))
            src = s1 + genProfileDoco(pack, intro) + s3;
        else if (com[0].equals("profile.notes"))
            src = s1 + genProfileDoco(pack, notes) + s3;
        else if (com[0].equals("search-footer"))
            src = s1 + searchFooter(level) + s3;
        else if (com[0].equals("search-header"))
            src = s1 + searchHeader(level) + s3;
        else if (com[0].startsWith("!"))
            src = s1 + s3;
        else if (com[0].equals("wg")) {
            String wg = profile.getWg().getCode();
            if (Utilities.noString(wg))
                pack.getWg();
            if (Utilities.noString(wg) && profile.getDefn() != null)
                wg = profile.getDefn().getWg().getCode();
            if (wg == null || !definitions.getWorkgroups().containsKey(wg))
                src = s1 + "(No assigned work group) (" + wg + ") (4)" + s3;
            else
                src = s1 + "<a _target=\"blank\" href=\"" + definitions.getWorkgroups().get(wg).getUrl() + "\">" + definitions.getWorkgroups().get(wg).getName() + "</a> Work Group" + s3;
        } else if (com[0].equals("fmm-style")) {
            String fmm = ToolingExtensions.readStringExtension(profile.getResource(), ToolingExtensions.EXT_FMM_LEVEL);
            StandardsStatus ss = ToolingExtensions.getStandardsStatus(profile.getResource());
            src = s1 + fmmBarColorStyle(ss, fmm) + s3;
        } else if (com[0].equals("fmm")) {
            String fmm = profile.getFmm();
            if (Utilities.noString(fmm))
                fmm = pack.getFmmLevel();
            src = s1 + getFmmFromlevel(genlevel(level), fmm) + s3;
        } else if (com[0].equals("profile-context"))
            src = s1 + getProfileContext(pack.getCandidateResource(), genlevel(level)) + s3;
        else if (com[0].equals("sstatus")) {
            StandardsStatus ss = ToolingExtensions.getStandardsStatus(profile.getResource());
            if (ss == null)
                ss = StandardsStatus.INFORMATIVE;
            if (ss == StandardsStatus.NORMATIVE && ToolingExtensions.hasExtension(profile.getResource(), ToolingExtensions.EXT_NORMATIVE_VERSION))
                src = s1 + "<a href=\"" + genlevel(level) + "versions.html#std-process\">" + ss.toDisplay() + "</a> (from v" + ToolingExtensions.readStringExtension(profile.getResource(), ToolingExtensions.EXT_NORMATIVE_VERSION) + ")" + s3;
            else
                src = s1 + "<a href=\"" + genlevel(level) + "versions.html#std-process\">" + ss.toDisplay() + "</a>" + s3;
        } else if (com[0].equals("past-narrative-link")) {
            if (hasNarrative)
                src = s1 + s3;
            else
                src = s1 + "<p><a href=\"#DomainResource.text.div-end\">Jump past Narrative</a></p>" + s3;
        } else if (com[0].equals("resurl")) {
            if (Utilities.noString(pack.metadata("id")))
                src = s1 + s3;
            else
                src = s1 + "The id of this profile is " + pack.metadata("id") + s3;
        } else if (com[0].equals("res-type-count")) {
            src = s1 + definitions.getResources().size() + s3;
        } else if (macros.containsKey(com[0])) {
            src = s1 + macros.get(com[0]) + s3;
        } else
            throw new Exception("Instruction <%" + s2 + "%> not understood parsing resource " + filename);
    }
    return src;
}
Also used : IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) SimpleDateFormat(java.text.SimpleDateFormat) StandardsStatus(org.hl7.fhir.utilities.StandardsStatus) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) 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) Date(java.util.Date)

Example 88 with Resource

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

the class PageProcessor method compResourceMap.

private String compResourceMap(String name) throws Exception {
    String n = name.split("\\-")[1];
    StringBuilder in = new StringBuilder();
    StringBuilder out = new StringBuilder();
    Map<ResourceDefn, String> map = definitions.getCompartmentByName(n).getResources();
    for (String rn : definitions.sortedResourceNames()) {
        ResourceDefn rd = definitions.getResourceByName(rn);
        String rules = map.get(rd);
        if (Utilities.noString(rules)) {
            out.append(" <li><a href=\"").append(rd.getName().toLowerCase()).append(".html\">").append(rd.getName()).append("</a></li>\r\n");
        } else if (!rules.equals("{def}")) {
            in.append(" <tr><td><a href=\"").append(rd.getName().toLowerCase()).append(".html\">").append(rd.getName()).append("</a></td><td>").append(rules.replace("|", "or")).append("</td></tr>\r\n");
        }
    }
    return "<p>\r\nThe following resources may be in this compartment:\r\n</p>\r\n" + "<table class=\"grid\">\r\n" + " <tr><td><b>Resource</b></td><td><b>Inclusion Criteria</b></td></tr>\r\n" + in.toString() + "</table>\r\n" + "<p>\r\nA resource is in this compartment if the nominated search parameter (or chain) refers to the patient resource that defines the compartment.\r\n</p>\r\n" + "<p>\r\n\r\n</p>\r\n" + "<p>\r\nThe following resources are never in this compartment:\r\n</p>\r\n" + "<ul>\r\n" + out.toString() + "</ul>\r\n";
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 89 with Resource

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

the class PageProcessor method produceStructureDefinitionExamples.

private String produceStructureDefinitionExamples(ResourceDefn resource) throws Exception {
    StringBuilder s = new StringBuilder();
    s.append("<div id=\"tabs\">\r\n");
    s.append("<ul>\r\n");
    s.append("  <li><a href=\"#tabs-1\">Base Types</a></li>\r\n");
    s.append("  <li><a href=\"#tabs-2\">Resources</a></li>\r\n");
    s.append("  <li><a href=\"#tabs-3\">Constraints</a></li>\r\n");
    s.append("  <li><a href=\"#tabs-4\">Extensions</a></li>\r\n");
    s.append("  <li><a href=\"#tabs-5\">Examples</a></li>\r\n");
    s.append("</ul>\r\n");
    s.append("<div id=\"tabs-1\">\r\n");
    // base types
    s.append("<table class=\"list\">\r\n");
    genStructureExampleCategory(s, "Abstract Types", "3");
    genStructureExample(s, definitions.getElementLink(), "element.profile", "element", "Element");
    genStructureExample(s, definitions.getBackboneLink(), "backboneelement.profile", "backboneelement", "BackBoneElement");
    genStructureExample(s, "resource.html", "resource.profile", "resource", "Resource");
    genStructureExample(s, "domainresource.html", "domainresource.profile", "domainresource", "DomainResource");
    genStructureExampleCategory(s, "Primitive Types", "3");
    List<String> names = new ArrayList<String>();
    names.addAll(definitions.getPrimitives().keySet());
    Collections.sort(names);
    for (String n : names) {
        DefinedCode dc = definitions.getPrimitives().get(n);
        genStructureExample(s, "datatypes.html#" + dc.getCode(), dc.getCode().toLowerCase() + ".profile", dc.getCode().toLowerCase(), dc.getCode());
    }
    genStructureExampleCategory(s, "Data Types", "3");
    names.clear();
    names.addAll(definitions.getTypes().keySet());
    names.addAll(definitions.getInfrastructure().keySet());
    Collections.sort(names);
    for (String n : names) {
        org.hl7.fhir.definitions.model.TypeDefn t = definitions.getTypes().get(n);
        if (t == null)
            t = definitions.getInfrastructure().get(n);
        genStructureExample(s, getLinkFor("", t.getName()), t.getName().toLowerCase() + ".profile", t.getName().toLowerCase(), t.getName());
    }
    s.append("</table>\r\n");
    s.append("</div>\r\n");
    s.append("<div id=\"tabs-2\">\r\n");
    s.append("<table class=\"list\">\r\n");
    genStructureExampleCategory(s, "Resources", "3");
    for (String n : definitions.sortedResourceNames()) {
        ResourceDefn r = definitions.getResources().get(n);
        genStructureExample(s, r.getName().toLowerCase() + ".html", r.getName().toLowerCase() + ".profile", r.getName().toLowerCase(), r.getName());
    }
    s.append("</table>\r\n");
    s.append("</div>\r\n");
    s.append("<div id=\"tabs-3\">\r\n");
    s.append("<table class=\"list\">\r\n");
    Map<String, ConstraintStructure> constraints = new HashMap<String, ConstraintStructure>();
    for (Profile pp : definitions.getPackList()) {
        for (ConstraintStructure p : pp.getProfiles()) constraints.put(p.getId(), p);
    }
    for (String rn : definitions.sortedResourceNames()) for (Profile ap : definitions.getResourceByName(rn).getConformancePackages()) for (ConstraintStructure p : ap.getProfiles()) constraints.put(p.getId(), p);
    names.clear();
    names.addAll(constraints.keySet());
    Collections.sort(names);
    for (ImplementationGuideDefn ig : definitions.getSortedIgs()) {
        boolean started = false;
        for (String n : names) {
            ConstraintStructure p = constraints.get(n);
            if (ig == p.getUsage()) {
                if (!started) {
                    started = true;
                    genStructureExampleCategory(s, ig.getName(), "3");
                }
                String prefix = ig.isCore() ? "" : ig.getCode() + "/";
                genStructureExample(s, prefix + p.getId().toLowerCase() + ".html", prefix + p.getId().toLowerCase() + ".profile", p.getId().toLowerCase(), p.getTitle());
            }
        }
    }
    s.append("</table>\r\n");
    s.append("</div>\r\n");
    s.append("<div id=\"tabs-4\">\r\n");
    s.append("<table class=\"list\">\r\n");
    names.clear();
    for (StructureDefinition sd : workerContext.getExtensionDefinitions()) names.add(sd.getUrl());
    Collections.sort(names);
    for (ImplementationGuideDefn ig : definitions.getSortedIgs()) {
        boolean started = false;
        for (String n : names) {
            StructureDefinition ed = workerContext.fetchResource(StructureDefinition.class, n);
            if (ig.getCode().equals(ToolResourceUtilities.getUsage(ed))) {
                if (!started) {
                    started = true;
                    genStructureExampleCategory(s, ig.getName(), "3");
                }
                String prefix = ig.isCore() ? "" : ig.getCode() + "/";
                genStructureExample(s, prefix + "extension-" + ed.getId().toLowerCase() + ".html", prefix + "extension-" + ed.getId().toLowerCase(), ed.getId().toLowerCase(), ed.getUrl().startsWith("http://hl7.org/fhir/StructureDefinition/") ? ed.getUrl().substring(40) : ed.getUrl(), ed.getName());
            }
        }
    }
    s.append("</table>\r\n");
    s.append("</div>\r\n");
    s.append("<div id=\"tabs-5\">\r\n");
    s.append("<table class=\"list\">\r\n");
    for (Example e : resource.getExamples()) {
        if (e.isRegistered() && Utilities.noString(e.getIg()))
            produceExampleListEntry(s, e, null, null);
    }
    for (Profile p : resource.getConformancePackages()) {
        for (Example e : p.getExamples()) {
            produceExampleListEntry(s, e, p, null);
        }
    }
    for (Profile p : definitions.getPackList()) {
        ImplementationGuideDefn ig = definitions.getIgs().get(p.getCategory());
        for (Example e : p.getExamples()) {
            String rn = e.getResourceName();
            if (Utilities.noString(rn))
                rn = e.getXml().getDocumentElement().getNodeName();
            if (rn.equals(resource.getName()))
                produceExampleListEntry(s, e, p, ig);
        }
    }
    for (ImplementationGuideDefn ig : definitions.getSortedIgs()) {
        if (ig.getIg() != null) {
            for (ImplementationGuideDefinitionResourceComponent res : ig.getIg().getDefinition().getResource()) {
                Example e = (Example) res.getUserData(ToolResourceUtilities.NAME_RES_EXAMPLE);
                if (res.hasExample() && e != null && e.getResourceName().equals(resource.getName()))
                    produceExampleListEntry(s, res, ig);
            }
        }
    }
    s.append("</table>\r\n");
    s.append("</div>\r\n");
    s.append("</div>\r\n");
    s.append("\r\n");
    s.append("<script src=\"external/jquery/jquery.js\"> </script>\r\n");
    s.append("<script src=\"jquery-ui.min.js\"> </script>\r\n");
    s.append("<script>\r\n");
    s.append("try {\r\n");
    s.append("  var currentTabIndex = sessionStorage.getItem('fhir-sdelist-tab-index');\r\n");
    s.append("}\r\n");
    s.append("catch(exception){\r\n");
    s.append("}\r\n");
    s.append("\r\n");
    s.append("if (!currentTabIndex)\r\n");
    s.append("  currentTabIndex = '0';\r\n");
    s.append("  \r\n");
    s.append("$( '#tabs' ).tabs({\r\n");
    s.append("         active: currentTabIndex,\r\n");
    s.append("         activate: function( event, ui ) {\r\n");
    s.append("             var active = $('.selector').tabs('option', 'active');\r\n");
    s.append("             currentTabIndex = ui.newTab.index();\r\n");
    s.append("             document.activeElement.blur();\r\n");
    s.append("             try {\r\n");
    s.append("               sessionStorage.setItem('fhir-sdelist-tab-index', currentTabIndex);\r\n");
    s.append("             }\r\n");
    s.append("             catch(exception){\r\n");
    s.append("             }\r\n");
    s.append("         }\r\n");
    s.append("     });\r\n");
    s.append("</script>\r\n");
    s.append("\r\n");
    return s.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) 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) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) Example(org.hl7.fhir.definitions.model.Example) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) TypeDefn(org.hl7.fhir.definitions.model.TypeDefn) ImplementationGuideDefinitionResourceComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure)

Example 90 with Resource

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

the class PageProcessor method produceExtensions.

private String produceExtensions(ResourceDefn resource) {
    int count = 0;
    Map<String, StructureDefinition> map = new HashMap<String, StructureDefinition>();
    for (StructureDefinition sd : workerContext.getExtensionDefinitions()) {
        boolean inc = false;
        for (StructureDefinitionContextComponent ec : sd.getContext()) {
            if (ec.getType() == ExtensionContextType.ELEMENT) {
                inc = inc || (ec.getExpression().equals(resource.getName()) || ec.getExpression().startsWith(resource.getName() + "."));
            }
            if (inc)
                map.put(sd.getId(), sd);
        }
    }
    StringBuilder b = new StringBuilder();
    for (String s : sorted(map.keySet())) {
        StructureDefinition cs = map.get(s);
        count++;
        b.append("  <tr>\r\n");
        String ref = cs.getUserString("path");
        b.append("    <td><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.getId())).append("</a></td>\r\n");
        b.append("    <td>").append(presentContext(cs, resource.getName())).append("</td>\r\n");
        b.append("    <td>").append(Utilities.escapeXml(cs.getName())).append("</td>\r\n");
        Profile ap = (Profile) cs.getUserData("profile");
        if (ap == null)
            b.append("    <td></td>\r\n");
        else {
            ImplementationGuideDefn ig = definitions.getIgs().get(ap.getCategory());
            b.append("    <td>for <a href=\"" + ig.getPrefix() + ap.getId().toLowerCase() + ".html\">" + Utilities.escapeXml(ap.getTitle()) + "</a></td>\r\n");
        }
        b.append(" </tr>\r\n");
    }
    if (count == 0)
        b.append("<tr><td>No Extensions defined for this resource</td></tr>");
    map.clear();
    for (StructureDefinition sd : workerContext.getExtensionDefinitions()) {
        boolean inc = false;
        for (StructureDefinitionContextComponent ec : sd.getContext()) inc = inc || (ec.getExpression().equals("Resource") || ec.getExpression().equals("DomainResource") || ec.getExpression().equals("Any"));
        if (inc)
            map.put(sd.getId(), sd);
    }
    b.append("<tr><td colspan=\"4\">Extensions for all resources or elements</td></tr>");
    for (String s : sorted(map.keySet())) {
        StructureDefinition cs = map.get(s);
        count++;
        b.append("  <tr>\r\n");
        String ref = cs.getUserString("path");
        b.append("    <td colspan=\"2\"><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.getId())).append("</a></td>\r\n");
        b.append("    <td>").append(Utilities.escapeXml(cs.getName())).append("</td>\r\n");
        Profile ap = (Profile) cs.getUserData("profile");
        if (ap == null)
            b.append("    <td></td>\r\n");
        else {
            ImplementationGuideDefn ig = definitions.getIgs().get(ap.getCategory());
            b.append("    <td>for <a href=\"" + ig.getPrefix() + ap.getId() + ".html\">" + Utilities.escapeXml(ap.getTitle()) + "</a></td>\r\n");
        }
        b.append(" </tr>\r\n");
    }
    return b.toString();
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) StructureDefinitionContextComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) Profile(org.hl7.fhir.definitions.model.Profile)

Aggregations

ArrayList (java.util.ArrayList)319 Resource (org.hl7.fhir.r4.model.Resource)312 Test (org.junit.jupiter.api.Test)297 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)270 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)230 FHIRException (org.hl7.fhir.exceptions.FHIRException)201 Test (org.junit.Test)190 IOException (java.io.IOException)181 Bundle (org.hl7.fhir.r4.model.Bundle)169 Date (java.util.Date)147 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)139 List (java.util.List)133 HashMap (java.util.HashMap)131 Patient (org.hl7.fhir.r4.model.Patient)118 FileOutputStream (java.io.FileOutputStream)110 Reference (org.hl7.fhir.r4.model.Reference)109 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)102 File (java.io.File)100 Collectors (java.util.stream.Collectors)95 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)92