Search in sources :

Example 6 with ResourceDefn

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

the class Publisher method produceCoverageWarnings.

private void produceCoverageWarnings() throws Exception {
    for (ElementDefn e : page.getDefinitions().getTypes().values()) produceCoverageWarning("", e);
    for (String s : page.getDefinitions().sortedResourceNames()) {
        ResourceDefn e = page.getDefinitions().getResourceByName(s);
        produceCoverageWarning("", e.getRoot());
    }
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 7 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn 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 8 with ResourceDefn

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

the class Publisher method produceMap.

private void produceMap(String name, SectionTracker st, ResourceDefn res) throws Exception {
    File f = new File(Utilities.path(page.getFolders().rootDir, "implementations", "r3maps", "R4toR3", name + ".map"));
    if (!f.exists())
        return;
    String n = name.toLowerCase();
    Map<String, String> values = new HashMap<String, String>();
    values.put("conv-status", page.r3r4StatusForResource(name));
    String fwds = TextFile.fileToString(Utilities.path(page.getFolders().rootDir, "implementations", "r3maps", "R3toR4", page.r3nameForResource(name) + ".map"));
    String bcks = TextFile.fileToString(Utilities.path(page.getFolders().rootDir, "implementations", "r3maps", "R4toR3", name + ".map"));
    values.put("fwds", Utilities.escapeXml(fwds));
    values.put("bcks", Utilities.escapeXml(bcks));
    values.put("fwds-status", "");
    values.put("bcks-status", "");
    values.put("r3errs", Utilities.escapeXml(page.getR3R4ValidationErrors(name)));
    try {
        new StructureMapUtilities(page.getWorkerContext()).parse(fwds, page.r3nameForResource(name) + ".map");
    } catch (FHIRException e) {
        values.put("fwds-status", "<p style=\"background-color: #ffb3b3; border:1px solid maroon; padding: 5px;\">This script does not compile: " + e.getMessage() + "</p>\r\n");
    }
    try {
        new StructureMapUtilities(page.getWorkerContext()).parse(bcks, name + ".map");
    } catch (FHIRException e) {
        values.put("bcks-status", "<p style=\"background-color: #ffb3b3; border:1px solid maroon; padding: 5px;\">This script does not compile: " + e.getMessage() + "</p>\r\n");
    } catch (IllegalArgumentException e) {
        values.put("bcks-status", "<p style=\"background-color: #ffb3b3; border:1px solid maroon; padding: 5px;\">This script does not compile: " + e.getMessage() + "</p>\r\n");
    }
    if (page.getDefinitions().hasResource(name) || (page.getDefinitions().getBaseResources().containsKey(name) && !name.equals("Parameters"))) {
        String src = TextFile.fileToString(page.getFolders().templateDir + "template-version-maps.html");
        TextFile.stringToFile(insertSectionNumbers(page.processResourceIncludes(n, page.getDefinitions().getResourceByName(name), null, null, null, null, null, src, null, null, "res-R3/R4 Conversions", n + "-version-maps.html", null, values, res.getWg(), null), st, n + "-version-maps.html", 0, null), page.getFolders().dstDir + n + "-version-maps.html");
        page.getHTMLChecker().registerFile(n + "-version-maps.html", "Version Maps for " + name, HTMLLinkChecker.XHTML_TYPE, true);
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureMapUtilities(org.hl7.fhir.r5.utils.structuremap.StructureMapUtilities)

Example 9 with ResourceDefn

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

the class Publisher method makeConformancePack.

private Profile makeConformancePack(ResourceDefn r) {
    Profile result = new Profile("core");
    result.setTitle("Base Profile for " + r.getName());
    return result;
}
Also used : Profile(org.hl7.fhir.definitions.model.Profile)

Example 10 with ResourceDefn

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

the class PageProcessor method genResRefList.

private String genResRefList(String n) throws Exception {
    ResourceDefn e = definitions.getResourceByName(n);
    StringBuilder b = new StringBuilder();
    b.append("<ul>\r\n");
    for (ElementDefn c : e.getRoot().getElements()) genResRefItem(b, n.toLowerCase(), n, c);
    b.append("</ul>\r\n");
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

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