Search in sources :

Example 1 with ProfiledType

use of org.hl7.fhir.r4b.model.TypeDetails.ProfiledType in project kindling by HL7.

the class Publisher method produceProfiledTypeProfile.

private void produceProfiledTypeProfile(ProfiledType pt) throws Exception {
    String fn = pt.getName().toLowerCase() + ".profile.xml";
    StructureDefinition rp = pt.getProfile();
    FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + fn);
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, rp);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(fn, ".canonical.xml"));
    new XmlParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, rp);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(fn, ".json"));
    new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, rp);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(fn, ".canonical.json"));
    new JsonParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, rp);
    s.close();
    Utilities.copyFile(new CSFile(page.getFolders().dstDir + fn), new CSFile(Utilities.path(page.getFolders().dstDir, "examples", fn)));
    addToResourceFeed(rp, page.getTypeBundle(), (fn));
    cloneToXhtml(pt.getName().toLowerCase() + ".profile", "StructureDefinition for " + pt.getName(), false, "profile-instance:type:" + pt.getName(), "Type", null, wg("mnm"));
    jsonToXhtml(pt.getName().toLowerCase() + ".profile", "StructureDefinition for " + pt.getName(), resource2Json(rp), "profile-instance:type:" + pt.getName(), "Type", null, wg("mnm"));
    ttlToXhtml(pt.getName().toLowerCase() + ".profile", "StructureDefinition for " + pt.getName(), resource2Ttl(rp), "profile-instance:type:" + pt.getName(), "Type", null, wg("mnm"));
    String shex = new ShExGenerator(page.getWorkerContext()).generate(HTMLLinkPolicy.NONE, rp);
    TextFile.stringToFile(shex, Utilities.changeFileExt(page.getFolders().dstDir + fn, ".shex"));
    shexToXhtml(pt.getName().toLowerCase(), "ShEx statement for " + pt.getName(), shex, "profile-instance:type:" + pt.getName(), "Type", null, wg("mnm"));
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) FileOutputStream(java.io.FileOutputStream) CSFile(org.hl7.fhir.utilities.CSFile) JsonParser(org.hl7.fhir.r5.formats.JsonParser) ShExGenerator(org.hl7.fhir.r5.conformance.ShExGenerator)

Example 2 with ProfiledType

use of org.hl7.fhir.r4b.model.TypeDetails.ProfiledType in project kindling by HL7.

the class Publisher method genProfiledTypeProfile.

private void genProfiledTypeProfile(ProfiledType pt) throws Exception {
    StructureDefinition profile = new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(pt, page.getValidationErrors());
    if (page.getProfiles().has(profile.getUrl()))
        throw new Exception("Duplicate Profile URL " + profile.getUrl());
    page.getProfiles().see(profile, page.packageInfo());
    pt.setProfile(profile);
// todo: what to do in the narrative?
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileGenerator(org.hl7.fhir.definitions.generators.specification.ProfileGenerator) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with ProfiledType

use of org.hl7.fhir.r4b.model.TypeDetails.ProfiledType in project kindling by HL7.

the class Publisher method processProfiles.

@SuppressWarnings("unchecked")
private void processProfiles() throws Exception {
    page.log(" ...process profiles (base)", LogMessageType.Process);
    // first, for each type and resource, we build it's master profile
    for (DefinedCode t : page.getDefinitions().getPrimitives().values()) {
        if (t instanceof PrimitiveType)
            genPrimitiveTypeProfile((PrimitiveType) t);
        else
            genPrimitiveTypeProfile((DefinedStringPattern) t);
    }
    genXhtmlProfile();
    for (TypeDefn t : page.getDefinitions().getTypes().values()) genTypeProfile(t);
    for (TypeDefn t : page.getDefinitions().getInfrastructure().values()) genTypeProfile(t);
    page.log(" ...process profiles (resources)", LogMessageType.Process);
    for (ResourceDefn r : page.getDefinitions().getBaseResources().values()) {
        r.setConformancePack(makeConformancePack(r));
        r.setProfile(new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(r.getConformancePack(), r, "core", false));
        if (page.getProfiles().has(r.getProfile().getUrl()))
            throw new Exception("Duplicate Profile URL " + r.getProfile().getUrl());
        page.getProfiles().see(r.getProfile(), page.packageInfo());
        ResourceTableGenerator rtg = new ResourceTableGenerator(page.getFolders().dstDir, page, null, true, page.getVersion());
        r.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
        r.getProfile().getText().getDiv().getChildNodes().add(rtg.generate(r, "", false));
    }
    for (String rn : page.getDefinitions().sortedResourceNames()) {
        ResourceDefn r = page.getDefinitions().getResourceByName(rn);
        r.setConformancePack(makeConformancePack(r));
        r.setProfile(new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(r.getConformancePack(), r, "core", false));
        if (page.getProfiles().has(r.getProfile().getUrl()))
            throw new Exception("Duplicate Profile URL " + r.getProfile().getUrl());
        page.getProfiles().see(r.getProfile(), page.packageInfo());
        ResourceTableGenerator rtg = new ResourceTableGenerator(page.getFolders().dstDir, page, null, true, page.getVersion());
        r.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
        r.getProfile().getText().getDiv().getChildNodes().add(rtg.generate(r, "", false));
    }
    for (ResourceDefn r : page.getDefinitions().getResourceTemplates().values()) {
        r.setConformancePack(makeConformancePack(r));
        r.setProfile(new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(r.getConformancePack(), r, "core", true));
        ResourceTableGenerator rtg = new ResourceTableGenerator(page.getFolders().dstDir, page, null, true, page.getVersion());
        r.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
        r.getProfile().getText().getDiv().getChildNodes().add(rtg.generate(r, "", true));
        if (page.getProfiles().has(r.getProfile().getUrl()))
            throw new Exception("Duplicate Profile URL " + r.getProfile().getUrl());
        page.getProfiles().see(r.getProfile(), page.packageInfo());
    }
    for (ProfiledType pt : page.getDefinitions().getConstraints().values()) {
        genProfiledTypeProfile(pt);
    }
    page.log(" ...process profiles (extensions)", LogMessageType.Process);
    for (StructureDefinition ex : page.getWorkerContext().getExtensionDefinitions()) processExtension(ex);
    for (ResourceDefn r : page.getDefinitions().getResources().values()) {
        // boolean logged = false;
        for (Profile ap : r.getConformancePackages()) {
            // logged = true;
            for (ConstraintStructure p : ap.getProfiles()) processProfile(ap, p, ap.getId(), r);
        }
    }
    page.log(" ...process profiles (packs)", LogMessageType.Process);
    // we have profiles scoped by resources, and stand alone profiles
    for (Profile ap : page.getDefinitions().getPackList()) {
        // page.log(" ...  pack "+ap.getId(), LogMessageType.Process);
        for (ConstraintStructure p : ap.getProfiles()) processProfile(ap, p, ap.getId(), null);
    }
    page.log(" ...process logical models", LogMessageType.Process);
    for (ImplementationGuideDefn ig : page.getDefinitions().getSortedIgs()) {
        for (LogicalModel lm : ig.getLogicalModels()) {
            page.log(" ...process logical model " + lm.getId(), LogMessageType.Process);
            if (lm.getDefinition() == null)
                lm.setDefinition(new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generateLogicalModel(ig, lm.getResource()));
        }
    }
    // now, validate the profiles
    for (Profile ap : page.getDefinitions().getPackList()) for (ConstraintStructure p : ap.getProfiles()) validateProfile(p);
    for (ResourceDefn r : page.getDefinitions().getResources().values()) for (Profile ap : r.getConformancePackages()) for (ConstraintStructure p : ap.getProfiles()) validateProfile(p);
    page.log(" ...Check FHIR Path Expressions", LogMessageType.Process);
    StringBuilder b = new StringBuilder();
    FHIRPathEngine fp = new FHIRPathEngine(page.getWorkerContext());
    fp.setHostServices(page.getExpressionResolver());
    for (FHIRPathUsage p : fpUsages) {
        checkExpression(b, fp, p);
    }
    TextFile.stringToFile(b.toString(), Utilities.path(page.getFolders().dstDir, "fhirpaths.txt"));
    checkAllOk();
}
Also used : TypeDefn(org.hl7.fhir.definitions.model.TypeDefn) ProfileGenerator(org.hl7.fhir.definitions.generators.specification.ProfileGenerator) ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) FHIRPathEngine(org.hl7.fhir.r5.utils.FHIRPathEngine) ResourceTableGenerator(org.hl7.fhir.definitions.generators.specification.ResourceTableGenerator) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Profile(org.hl7.fhir.definitions.model.Profile) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) LogicalModel(org.hl7.fhir.definitions.model.LogicalModel) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) DefinedStringPattern(org.hl7.fhir.definitions.model.DefinedStringPattern) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) PrimitiveType(org.hl7.fhir.definitions.model.PrimitiveType) FHIRPathUsage(org.hl7.fhir.definitions.validation.FHIRPathUsage) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure)

Example 4 with ProfiledType

use of org.hl7.fhir.r4b.model.TypeDetails.ProfiledType in project kindling by HL7.

the class PageProcessor method genConstraints.

private String genConstraints(String name, String prefix) throws Exception {
    Map<String, String> invs = new HashMap<String, String>();
    if (definitions.getConstraints().containsKey(name)) {
        ProfiledType cnst = definitions.getConstraints().get(name);
        generateConstraintsTable(name, cnst, invs, true, prefix);
    } else {
        ElementDefn e = definitions.getElementDefn(name);
        generateConstraintsTable(name, e, invs, true, prefix);
    }
    List<String> ids = new ArrayList<String>();
    for (String n : invs.keySet()) {
        ids.add(n);
    }
    Collections.sort(ids, new ConstraintsSorter());
    StringBuilder b = new StringBuilder();
    for (String n : ids) {
        b.append(invs.get(n));
    }
    if (b.length() > 0)
        return "<a name=\"" + name + "-inv\"> </a><table class=\"grid\"><tr><td width=\"60\"><b>id</b></td><td><b>Level</b></td><td><b>Location</b></td><td><b>Description</b></td><td><b><a href=\"" + prefix + "fhirpath.html\">Expression</a></b></td></tr>" + b + "</table>";
    else
        return "";
}
Also used : ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ArrayList(java.util.ArrayList)

Example 5 with ProfiledType

use of org.hl7.fhir.r4b.model.TypeDetails.ProfiledType in project kindling by HL7.

the class PageProcessor method genRestrictions.

private String genRestrictions(String name) throws Exception {
    StringBuilder b = new StringBuilder();
    StringBuilder b2 = new StringBuilder();
    for (ProfiledType c : definitions.getConstraints().values()) {
        if (c.getBaseType().equals(name)) {
            b.append("<a name=\"" + c.getName() + "\"> </a><a name=\"" + c.getName().toLowerCase() + "\"> </a>\r\n");
            b2.append(" <tr><td>" + c.getName() + "</td><td>" + Utilities.escapeXml(c.getDefinition()) + "</td><td>StructureDefinition (<a href=\"" + c.getName().toLowerCase() + ".profile.xml.html\">XML</a>, <a href=\"" + c.getName().toLowerCase() + ".profile.json.html\">JSON</a>)</td>");
            b2.append("<td>" + genDataTypeUsage(c.getName()) + "</td>");
            b2.append("</tr>\r\n");
        }
    }
    if (b.length() > 0)
        return b.toString() + "<table class=\"list\">\r\n" + b2.toString() + "</table>\r\n";
    else
        return "";
}
Also used : ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)19 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)14 ArrayList (java.util.ArrayList)11 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)9 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)7 TypeRef (org.hl7.fhir.definitions.model.TypeRef)7 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)7 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)6 IOException (java.io.IOException)5 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)5 URISyntaxException (java.net.URISyntaxException)4 ProfiledType (org.hl7.fhir.dstu3.model.TypeDetails.ProfiledType)4 ProfiledType (org.hl7.fhir.r4.model.TypeDetails.ProfiledType)4 ProfiledType (org.hl7.fhir.r4b.model.TypeDetails.ProfiledType)4 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)4 ProfiledType (org.hl7.fhir.r5.model.TypeDetails.ProfiledType)4 FileNotFoundException (java.io.FileNotFoundException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 List (java.util.List)3 DefinedCode (org.hl7.fhir.definitions.model.DefinedCode)3