Search in sources :

Example 1 with ImplementationGuideDefinitionResourceComponent

use of org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent 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 2 with ImplementationGuideDefinitionResourceComponent

use of org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent in project kindling by HL7.

the class PageProcessor method buildIgRegistry.

private String buildIgRegistry(ImplementationGuideDefn ig, String types) throws Exception {
    StringBuilder b = new StringBuilder();
    b.append("<table class=\"codes\">\r\n");
    b.append("<tr><td><b>Id</b></td><td><b>Name</b></td><td><b>Description</b></td></tr>\r\n");
    // examples second:
    boolean example = false;
    while (true) {
        boolean usedPurpose = false;
        for (String type : types.split("\\,")) {
            List<String> ids = new ArrayList<String>();
            Map<String, ImplementationGuideDefinitionResourceComponent> map = new HashMap<String, ImplementationGuideDefinitionResourceComponent>();
            for (ImplementationGuideDefinitionResourceComponent r : ig.getIg().getDefinition().getResource()) {
                Resource ar = (Resource) r.getUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE);
                if (ar != null && ar.getResourceType().toString().equals(type) && r.hasExample() == example) {
                    String id = ar.getId();
                    ids.add(id);
                    map.put(id, r);
                }
                Example ex = (Example) r.getUserData(ToolResourceUtilities.NAME_RES_EXAMPLE);
                if (ex != null && ex.getResourceName().equals(type) && r.hasExample() == example) {
                    String id = ex.getId();
                    ids.add(id);
                    map.put(id, r);
                }
            }
            if (ids.size() > 0) {
                if (!usedPurpose) {
                    b.append("<tr><td colspan=\"3\" style=\"background: #DFDFDF\"><b>" + (example ? "Specification" : "Example") + "</b> </td></tr>\r\n");
                    usedPurpose = true;
                }
                Collections.sort(ids);
                b.append("<tr><td colspan=\"3\" style=\"background: #EFEFEF\">" + getTypePluralDesc(type) + "</td></tr>\r\n");
                for (String id : ids) {
                    ImplementationGuideDefinitionResourceComponent r = map.get(id);
                    b.append("<tr><td><a href=\"" + Utilities.changeFileExt(r.getReference().getReference(), ".html") + "\">" + id + "</a></td><td>" + Utilities.escapeXml(r.getName()) + "</td><td>" + Utilities.escapeXml(r.getDescription()) + "</td></tr>\r\n");
                }
            }
        }
        if (example)
            break;
        else
            example = true;
    }
    b.append("</table>\r\n");
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) Example(org.hl7.fhir.definitions.model.Example) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) ArrayList(java.util.ArrayList) Resource(org.hl7.fhir.r5.model.Resource) DomainResource(org.hl7.fhir.r5.model.DomainResource) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) ImplementationGuideDefinitionResourceComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent)

Example 3 with ImplementationGuideDefinitionResourceComponent

use of org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent in project kindling by HL7.

the class Regenerator method generateCP.

private void generateCP(String root, ResourceDefn r, Profile p) throws IOException {
    ImplementationGuide ig = new ImplementationGuide();
    ig.setId(r.getName() + "-" + p.getCategory());
    ig.setTitle(p.getTitle());
    ig.setStatus(PublicationStatus.ACTIVE);
    ig.setDate(new Date(r.getTimestamp()));
    for (String s : p.getMetadata().keySet()) {
        List<String> vl = p.getMetadata().get(s);
        for (String v : vl) {
            if (!Utilities.noString(v)) {
                switch(s) {
                    // case "id": ig.setId(v); break;
                    case "name":
                        ig.setName(v);
                        break;
                    case "author.name":
                        ig.setPublisher(v);
                        break;
                    case "code":
                        ig.addExtension(BuildExtensions.EXT_CODE, new CodeType(v));
                        break;
                    case "fmm":
                        ig.addExtension(ToolingExtensions.EXT_FMM_LEVEL, new CodeType(v));
                        break;
                    case "description":
                        ig.setDescription(v);
                        break;
                    case "status":
                        ig.setStatus(PublicationStatus.fromCode(v));
                        break;
                    case "publication.status":
                        break;
                    case "version":
                        ig.setVersion(v);
                        break;
                    case "display":
                        ig.setTitle(v);
                        break;
                    case "workgroup":
                        ig.addExtension(ToolingExtensions.EXT_WORKGROUP, new CodeType(v));
                        break;
                    case "date":
                        ig.getDateElement().setValueAsString(v);
                        break;
                    case "Experimental":
                        ig.setExperimental(Utilities.existsInList(v.toLowerCase(), "y", "yes", "1", "true"));
                        break;
                    default:
                        if (s.startsWith("fmm-") || Utilities.existsInList(s, "extension.uri", "author.reference", "published.structure", "notes", "introduction") || s.startsWith("!")) {
                        // ignore these
                        } else if (s.startsWith("summary-")) {
                            String n = s.substring(8);
                            for (ConstraintStructure cs : p.getProfiles()) {
                                if (n.equals(cs.getTitle()) || n.equals(cs.getId())) {
                                    cs.setSummary(v);
                                }
                            }
                        } else {
                            System.out.println("Unknown metadata item: " + s + "=" + v);
                        }
                }
            }
        }
    }
    if (!Utilities.noString(p.getIntroduction())) {
        ig.addExtension(BuildExtensions.EXT_INTRODUCTION, new StringType(p.getIntroduction()));
    }
    if (!Utilities.noString(p.getNotes())) {
        ig.addExtension(BuildExtensions.EXT_NOTES, new StringType(p.getNotes()));
    }
    for (ConstraintStructure cs : p.getProfiles()) {
        CanonicalResource cr = generateProfile(root, r, p, cs);
        ImplementationGuideDefinitionResourceComponent res = ig.getDefinition().addResource();
        res.getReference().setReference(cr.fhirType() + "/" + cr.getId());
    }
    for (StructureDefinition cs : p.getExtensions()) {
        CanonicalResource cr = generateExtension(root, r, p, cs.copy());
        ImplementationGuideDefinitionResourceComponent res = ig.getDefinition().addResource();
        res.getReference().setReference(cr.fhirType() + "/" + cr.getId());
    }
    for (SearchParameter cs : p.getSearchParameters()) {
        CanonicalResource cr = generateSearchParameter(root, r, p, cs);
        ImplementationGuideDefinitionResourceComponent res = ig.getDefinition().addResource();
        res.getReference().setReference(cr.fhirType() + "/" + cr.getId());
    }
    for (Example cs : p.getExamples()) {
        ImplementationGuideDefinitionResourceComponent res = ig.getDefinition().addResource();
        generateExample(root, r, p, cs, res);
    }
    File fn = new File(Utilities.path(root, ig.fhirType().toLowerCase() + "-" + ig.getId() + ".gen.xml"));
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), ig);
    fn.setLastModified(r.getTimestamp());
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) ImplementationGuide(org.hl7.fhir.r5.model.ImplementationGuide) StringType(org.hl7.fhir.r5.model.StringType) Date(java.util.Date) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Example(org.hl7.fhir.definitions.model.Example) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) FileOutputStream(java.io.FileOutputStream) CodeType(org.hl7.fhir.r5.model.CodeType) ImplementationGuideDefinitionResourceComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) File(java.io.File)

Example 4 with ImplementationGuideDefinitionResourceComponent

use of org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent in project kindling by HL7.

the class ResourceParser method processProfile.

private ConstraintStructure processProfile(String rid, String igId, ImplementationGuideDefinitionResourceComponent res, WorkGroup wg) throws FHIRFormatError, FileNotFoundException, IOException {
    StructureDefinition sd = (StructureDefinition) parseXml("structuredefinition-profile-" + rid + ".xml");
    ImplementationGuideDefn ig = definitions.getIgs().get(BuildExtensions.readStringExtension(res, igId));
    if (ig == null) {
        ig = definitions.getIgs().get("core");
    }
    ConstraintStructure cs = new ConstraintStructure(sd, ig, wg == null ? wg(sd) : wg, null, false);
    return cs;
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure)

Example 5 with ImplementationGuideDefinitionResourceComponent

use of org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent in project kindling by HL7.

the class ImplementationGuideDefn method findLogicalPage.

private boolean findLogicalPage(String n, String type, List<LinkTriple> res, List<ImplementationGuideDefinitionPageComponent> page) throws Exception {
    // see if we can find it as an example of an existing profile
    String src = Utilities.fileTitle(n) + ".html";
    for (ImplementationGuideDefinitionResourceComponent r : ig.getDefinition().getResource()) {
        if (src.equals(r.getReference().getReference())) {
            if (r.hasExampleCanonicalType()) {
                String psrc = r.getExampleCanonicalType().getValueAsString().substring(r.getExampleCanonicalType().getValueAsString().lastIndexOf("/") + 1) + ".html";
                if (findPage(psrc, res, page)) {
                    res.add(new LinkTriple(null, r.getName(), null));
                    return true;
                }
            }
        }
    }
    // now, see if we can find a registry to make it a child of
    String id = Utilities.fileTitle(n);
    for (Example e : examples) {
        if (e.getId().equals(id))
            if (findRegistryPage(e.getResourceName(), res, page)) {
                res.add(new LinkTriple(null, e.getName(), null));
                return true;
            }
    }
    if (type.startsWith("profile:"))
        if (findRegistryPage("StructureDefinition", res, page)) {
            res.add(new LinkTriple(null, "Profile", null));
            return true;
        }
    if (findModified(n, "-operations.html", "Operations", res, page))
        return true;
    if (findModified(n, "-questionnaire.html", "Questionnaire", res, page))
        return true;
    if (findModified(n, ".profile.html", "StructureDefinition", res, page))
        return true;
    return false;
}
Also used : ImplementationGuideDefinitionResourceComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent)

Aggregations

ImplementationGuideDefinitionResourceComponent (org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent)8 ConstraintStructure (org.hl7.fhir.definitions.model.ConstraintStructure)5 Example (org.hl7.fhir.definitions.model.Example)5 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)5 File (java.io.File)4 OperationExample (org.hl7.fhir.definitions.model.Operation.OperationExample)4 Profile (org.hl7.fhir.definitions.model.Profile)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ImplementationGuideDefn (org.hl7.fhir.definitions.model.ImplementationGuideDefn)3 ImplementationGuide (org.hl7.fhir.r5.model.ImplementationGuide)3 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)3 XmlParser (org.hl7.fhir.r5.formats.XmlParser)2 CanonicalResource (org.hl7.fhir.r5.model.CanonicalResource)2 CodeType (org.hl7.fhir.r5.model.CodeType)2 Resource (org.hl7.fhir.r5.model.Resource)2 SearchParameter (org.hl7.fhir.r5.model.SearchParameter)2 CSFile (org.hl7.fhir.utilities.CSFile)2 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1