Search in sources :

Example 6 with ProfileGenerator

use of org.hl7.fhir.definitions.generators.specification.ProfileGenerator in project kindling by HL7.

the class Publisher method processProfile.

private void processProfile(Profile ap, ConstraintStructure profile, String filename, ResourceDefn baseResource) throws Exception {
    // create StructureDefinition structures if needed (create differential definitions from spreadsheets)
    if (profile.getResource() == null) {
        StructureDefinition p = new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(ap, profile, profile.getDefn(), profile.getId(), profile.getUsage(), page.getValidationErrors(), baseResource);
        p.setUserData("pack", ap);
        profile.setResource(p);
        if (profile.getResourceInfo() != null) {
            profile.getResourceInfo().setUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE, p);
        }
        if (page.getProfiles().has(p.getUrl()))
            throw new Exception("Duplicate Profile URL " + p.getUrl());
        page.getProfiles().see(p, page.packageInfo());
    } else {
        profile.getResource().setUserData("pack", ap);
        sortProfile(profile.getResource());
        for (ElementDefinition ed : profile.getResource().getDifferential().getElement()) if (!ed.hasId())
            throw new Exception("Missing ID");
        // special case: if the profile itself doesn't claim a date, it's date is the date of this publication
        if (!profile.getResource().hasDate())
            profile.getResource().setDate(page.getGenDate().getTime());
        if (profile.getResource().hasBaseDefinition() && !profile.getResource().hasSnapshot()) {
            // cause it probably doesn't, coming from the profile directly
            StructureDefinition base = getSnapShotForProfile(profile.getResource().getBaseDefinition());
            new ProfileUtilities(page.getWorkerContext(), page.getValidationErrors(), page).generateSnapshot(base, profile.getResource(), profile.getResource().getBaseDefinition().split("#")[0], "http://hl7.org/fhir", profile.getResource().getName());
        }
        if (page.getProfiles().has(profile.getResource().getUrl()))
            throw new Exception("Duplicate Profile URL " + profile.getResource().getUrl());
        System.out.println("register " + profile.getResource().getUrl());
        page.getProfiles().see(profile.getResource(), page.packageInfo());
    }
    if (!Utilities.noString(filename))
        profile.getResource().setUserData("filename", filename + ".html");
    if (Utilities.noString(profile.getResource().getUserString("path"))) {
        String path = "";
        ImplementationGuideDefn ig = page.getDefinitions().getUsageIG(ap.getCategory(), "processProfile");
        if (ig != null && !ig.isCore())
            path = ig.getCode() + File.separator;
        profile.getResource().setUserData("path", path + filename + ".html");
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileGenerator(org.hl7.fhir.definitions.generators.specification.ProfileGenerator) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 7 with ProfileGenerator

use of org.hl7.fhir.definitions.generators.specification.ProfileGenerator in project kindling by HL7.

the class Publisher method genPrimitiveTypeProfile.

private void genPrimitiveTypeProfile(DefinedStringPattern t) 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(t);
    if (page.getProfiles().has(profile.getUrl()))
        throw new Exception("Duplicate Profile URL " + profile.getUrl());
    page.getProfiles().see(profile, page.packageInfo());
    t.setProfile(profile);
// DataTypeTableGenerator dtg = new DataTypeTableGenerator(page.getFolders().dstDir, page, t.getCode(), true);
// t.setProfile(profile);
// t.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
// t.getProfile().getText().getDiv().getChildNodes().add(dtg.generate(t));
}
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 8 with ProfileGenerator

use of org.hl7.fhir.definitions.generators.specification.ProfileGenerator in project kindling by HL7.

the class SourceParser method genTypeProfile.

private void genTypeProfile(org.hl7.fhir.definitions.model.TypeDefn t) throws Exception {
    StructureDefinition profile;
    try {
        profile = new ProfileGenerator(definitions, context, page, genDate, version, null, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(t);
        t.setProfile(profile);
        DataTypeTableGenerator dtg = new DataTypeTableGenerator(dstDir, page, t.getName(), true, version);
        t.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
        t.getProfile().getText().getDiv().getChildNodes().add(dtg.generate(t, null, false));
        if (context.hasResource(StructureDefinition.class, t.getProfile().getUrl()))
            throw new Exception("Duplicate Profile " + t.getProfile().getUrl());
        context.cacheResource(t.getProfile());
    } catch (Exception e) {
        throw new Exception("Error generating profile for '" + t.getName() + "': " + e.getMessage(), e);
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileGenerator(org.hl7.fhir.definitions.generators.specification.ProfileGenerator) DataTypeTableGenerator(org.hl7.fhir.definitions.generators.specification.DataTypeTableGenerator) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 9 with ProfileGenerator

use of org.hl7.fhir.definitions.generators.specification.ProfileGenerator in project kindling by HL7.

the class Publisher method genTypeProfile.

private void genTypeProfile(TypeDefn t) throws Exception {
    StructureDefinition profile;
    try {
        profile = new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(t);
        page.getProfiles().see(profile, page.packageInfo());
        t.setProfile(profile);
        DataTypeTableGenerator dtg = new DataTypeTableGenerator(page.getFolders().dstDir, page, t.getName(), true, page.getVersion());
        t.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
        t.getProfile().getText().getDiv().getChildNodes().add(dtg.generate(t, null, false));
    } catch (Exception e) {
        throw new Exception("Error generating profile for '" + t.getName() + "': " + e.getMessage(), e);
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileGenerator(org.hl7.fhir.definitions.generators.specification.ProfileGenerator) DataTypeTableGenerator(org.hl7.fhir.definitions.generators.specification.DataTypeTableGenerator) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 10 with ProfileGenerator

use of org.hl7.fhir.definitions.generators.specification.ProfileGenerator in project kindling by HL7.

the class Publisher method produceTypeProfile.

private void produceTypeProfile(TypeDefn type) throws Exception {
    // ProfileDefn p = new ProfileDefn();
    // p.putMetadata("id", type.getName());
    // p.putMetadata("name", "Basic StructureDefinition for " + type.getName());
    // p.putMetadata("author.name", "FHIR Specification");
    // p.putMetadata("author.ref", "http://hl7.org/fhir");
    // p.putMetadata("description", "Basic StructureDefinition for " + type.getName() + " for validation support");
    // p.putMetadata("status", "draft");
    // p.putMetadata("date", new SimpleDateFormat("yyyy-MM-dd", new Locale("en", "US")).format(new Date()));
    // p.getElements().add(type);
    // ProfileGenerator pgen = new ProfileGenerator(page.getDefinitions());
    // String fn = "type-" + type.getName() + ".profile.xml";
    // StructureDefinition rp = pgen.generate(p, "type-" + type.getName() + ".profile", "<div>Type definition for " + type.getName() + " from <a href=\"http://hl7.org/fhir/datatypes.html#" + type.getName()
    // + "\">FHIR Specification</a></div>");
    String fn = type.getName().toLowerCase() + ".profile.xml";
    StructureDefinition rp = type.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);
    // saveAsPureHtml(rp, new FileOutputStream(page.getFolders().dstDir+ "html"
    // + File.separator + "datatypes.html"));
    cloneToXhtml(type.getName().toLowerCase() + ".profile", "StructureDefinition for " + type.getName(), false, "profile-instance:type:" + type.getName(), "Type", null, wg("mnm"));
    jsonToXhtml(type.getName().toLowerCase() + ".profile", "StructureDefinition for " + type.getName(), resource2Json(rp), "profile-instance:type:" + type.getName(), "Type", null, wg("mnm"));
    ttlToXhtml(type.getName().toLowerCase() + ".profile", "StructureDefinition for " + type.getName(), resource2Ttl(rp), "profile-instance:type:" + type.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(type.getName().toLowerCase(), "ShEx statement for " + type.getName(), shex, "profile-instance:type:" + type.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)

Aggregations

ProfileGenerator (org.hl7.fhir.definitions.generators.specification.ProfileGenerator)12 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)11 FHIRException (org.hl7.fhir.exceptions.FHIRException)9 FileNotFoundException (java.io.FileNotFoundException)8 IOException (java.io.IOException)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 TransformerException (javax.xml.transform.TransformerException)7 FileOutputStream (java.io.FileOutputStream)3 JsonParser (org.hl7.fhir.r5.formats.JsonParser)3 XmlParser (org.hl7.fhir.r5.formats.XmlParser)3 CSFile (org.hl7.fhir.utilities.CSFile)3 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)3 DataTypeTableGenerator (org.hl7.fhir.definitions.generators.specification.DataTypeTableGenerator)2 ImplementationGuideDefn (org.hl7.fhir.definitions.model.ImplementationGuideDefn)2 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)2 ProfileUtilities (org.hl7.fhir.r5.conformance.ProfileUtilities)2 RdfParser (org.hl7.fhir.r5.formats.RdfParser)2 ArrayList (java.util.ArrayList)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 ResourceTableGenerator (org.hl7.fhir.definitions.generators.specification.ResourceTableGenerator)1