Search in sources :

Example 6 with ShExGenerator

use of org.hl7.fhir.r5.conformance.ShExGenerator in project org.hl7.fhir.core by hapifhir.

the class ShexGeneratorTests method doTest.

private void doTest(String name) throws FileNotFoundException, IOException, FHIRException, UcumException {
    StructureDefinition sd = TestingUtilities.getSharedWorkerContext().fetchResource(StructureDefinition.class, ProfileUtilities.sdNs(name, null));
    if (sd == null) {
        throw new FHIRException("StructuredDefinition for " + name + "was null");
    }
    Path outPath = FileSystems.getDefault().getPath(System.getProperty("java.io.tmpdir"), name.toLowerCase() + ".shex");
    TextFile.stringToFile(new ShExGenerator(TestingUtilities.getSharedWorkerContext()).generate(HTMLLinkPolicy.NONE, sd), outPath.toString());
}
Also used : Path(java.nio.file.Path) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException) ShExGenerator(org.hl7.fhir.r5.conformance.ShExGenerator)

Example 7 with ShExGenerator

use of org.hl7.fhir.r5.conformance.ShExGenerator in project org.hl7.fhir.core by hapifhir.

the class ShexGeneratorTests method doTest.

private void doTest(String name) throws FileNotFoundException, IOException, FHIRException, UcumException {
    // FileSystems.getDefault().getPath(System.getProperty("user.dir"), "data").toString();
    String workingDirectory = "C:\\work\\org.hl7.fhir\\build\\publish";
    // String workingDirectory = FileSystems.getDefault().getPath(System.getProperty("user.dir"), "..", "..", "..", "publish").toString();
    StructureDefinition sd = TestingUtilities.context().fetchResource(StructureDefinition.class, ProfileUtilities.sdNs(name, null));
    if (sd == null) {
        throw new FHIRException("StructuredDefinition for " + name + "was null");
    }
    Path outPath = FileSystems.getDefault().getPath(workingDirectory, name.toLowerCase() + ".shex");
    TextFile.stringToFile(new ShExGenerator(TestingUtilities.context()).generate(HTMLLinkPolicy.NONE, sd), outPath.toString());
}
Also used : Path(java.nio.file.Path) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException) ShExGenerator(org.hl7.fhir.r4.conformance.ShExGenerator)

Example 8 with ShExGenerator

use of org.hl7.fhir.r5.conformance.ShExGenerator in project kindling by HL7.

the class Publisher method produceXhtmlProfile.

private void produceXhtmlProfile() throws Exception {
    String fn = "xhtml.profile.xml";
    StructureDefinition rp = page.getProfiles().get("xhtml");
    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();
    String shex = new ShExGenerator(page.getWorkerContext()).generate(HTMLLinkPolicy.NONE, rp);
    TextFile.stringToFile(shex, Utilities.changeFileExt(page.getFolders().dstDir + fn, ".shex"));
    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("xhtml.profile", "StructureDefinition for xhtml", false, "profile-instance:type:xhtml", "Type", null, wg("mnm"));
    jsonToXhtml("xhtml.profile", "StructureDefinition for xhtml", resource2Json(rp), "profile-instance:type:xhtml", "Type", null, wg("mnm"));
    ttlToXhtml("xhtml.profile", "StructureDefinition for xhtml", resource2Ttl(rp), "profile-instance:type:xhtml", "Type", null, wg("mnm"));
    shexToXhtml("xhtml", "ShEx statement for xhtml", shex, "profile-instance:type:xhtml", "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 9 with ShExGenerator

use of org.hl7.fhir.r5.conformance.ShExGenerator in project kindling by HL7.

the class Publisher method produceSpecification.

// private List<Element> xPathQuery(String path, Element e) throws Exception {
// NamespaceContext context = new NamespaceContextMap("f",
// "http://hl7.org/fhir", "h", "http://www.w3.org/1999/xhtml", "a", );
// 
// XPathFactory factory = XPathFactory.newInstance();
// XPath xpath = factory.newXPath();
// xpath.setNamespaceContext(context);
// XPathExpression expression= xpath.compile(path);
// NodeList resultNodes = (NodeList)expression.evaluate(e,
// XPathConstants.NODESET);
// List<Element> result = new ArrayList<Element>();
// for (int i = 0; i < resultNodes.getLength(); i++) {
// result.add((Element) resultNodes.item(i));
// }
// return result;
// }
private void produceSpecification() throws Exception {
    page.setNavigation(new Navigation());
    page.getNavigation().parse(page.getFolders().srcDir + "navigation.xml");
    processCDA();
    page.log("Generate RDF", LogMessageType.Process);
    processRDF();
    page.log("Produce Schemas", LogMessageType.Process);
    new SchemaGenerator().generate(page.getDefinitions(), page.getIni(), page.getFolders().tmpResDir, page.getFolders().xsdDir + "codegen" + File.separator, page.getFolders().dstDir, page.getFolders().srcDir, page.getVersion().toCode(), Config.DATE_FORMAT().format(page.getGenDate().getTime()), true, page.getWorkerContext());
    new SchemaGenerator().generate(page.getDefinitions(), page.getIni(), page.getFolders().tmpResDir, page.getFolders().xsdDir, page.getFolders().dstDir, page.getFolders().srcDir, page.getVersion().toCode(), Config.DATE_FORMAT().format(page.getGenDate().getTime()), false, page.getWorkerContext());
    new org.hl7.fhir.definitions.generators.specification.json.SchemaGenerator().generate(page.getDefinitions(), page.getIni(), page.getFolders().tmpResDir, page.getFolders().xsdDir, page.getFolders().dstDir, page.getFolders().srcDir, page.getVersion().toCode(), Config.DATE_FORMAT().format(page.getGenDate().getTime()), page.getWorkerContext());
    new org.hl7.fhir.definitions.generators.specification.json.JsonLDDefinitionsGenerator().generate(page.getDefinitions(), page.getIni(), page.getFolders().tmpResDir, page.getFolders().dstDir, page.getFolders().srcDir, page.getVersion(), Config.DATE_FORMAT().format(page.getGenDate().getTime()), page.getWorkerContext());
    List<StructureDefinition> list = new ArrayList<StructureDefinition>();
    for (StructureDefinition sd : page.getWorkerContext().allStructures()) {
        if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION)
            list.add(sd);
    }
    ShExGenerator shgen = new ShExGenerator(page.getWorkerContext());
    shgen.completeModel = true;
    shgen.withComments = false;
    TextFile.stringToFile(shgen.generate(HTMLLinkPolicy.NONE, list), page.getFolders().dstDir + "fhir.shex", false);
    new XVerPathsGenerator(page.getDefinitions(), Utilities.path(page.getFolders().dstDir, "xver-paths-" + Constants.VERSION_MM + ".json"), Utilities.path(page.getFolders().rootDir, "tools", "history", "release4", "xver-paths-4.0.json")).execute();
    GraphQLSchemaGenerator gql = new GraphQLSchemaGenerator(page.getWorkerContext(), page.getVersion().toCode());
    gql.generateTypes(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "types.graphql")));
    Set<String> names = new HashSet<String>();
    for (StructureDefinition sd : page.getWorkerContext().allStructures()) {
        if (sd.getKind() == StructureDefinitionKind.RESOURCE && sd.getAbstract() == false && sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && !names.contains(sd.getUrl())) {
            String filename = Utilities.path(page.getFolders().dstDir, sd.getName().toLowerCase() + ".graphql");
            names.add(sd.getUrl());
            List<SearchParameter> splist = new ArrayList<SearchParameter>();
            ResourceDefn rd = page.getDefinitions().getResourceByName(sd.getName());
            while (rd != null) {
                for (String n : sorted(rd.getSearchParams().keySet())) {
                    SearchParameterDefn spd = rd.getSearchParams().get(n);
                    if (spd.getResource() == null)
                        buildSearchDefinition(rd, spd);
                    splist.add(spd.getResource());
                }
                rd = "Base".equals(rd.getRoot().typeCode()) || rd.getRoot().getTypes().isEmpty() ? null : page.getDefinitions().getResourceByName(rd.getRoot().typeCode());
            }
            EnumSet<FHIROperationType> ops = EnumSet.of(FHIROperationType.READ, FHIROperationType.SEARCH, FHIROperationType.CREATE, FHIROperationType.UPDATE, FHIROperationType.DELETE);
            gql.generateResource(new FileOutputStream(filename), sd, splist, ops);
        }
    }
    TextFile.stringToFile(page.genBackboneElementsJson(), Utilities.path(page.getFolders().dstDir, "backbone-elements.json"));
    TextFile.stringToFile(page.genChoiceElementsJson(), Utilities.path(page.getFolders().dstDir, "choice-elements.json"));
    page.log("Produce Schematrons", LogMessageType.Process);
    for (String rname : page.getDefinitions().sortedResourceNames()) {
        ResourceDefn r = page.getDefinitions().getResources().get(rname);
        String n = r.getName().toLowerCase();
        SchematronGenerator sch = new SchematronGenerator(page);
        sch.generate(new FileOutputStream(page.getFolders().dstDir + n + ".sch"), r, page.getDefinitions());
    }
    ResourceDefn r = page.getDefinitions().getBaseResources().get("Parameters");
    String n = r.getName().toLowerCase();
    SchematronGenerator sch = new SchematronGenerator(page);
    sch.generate(new FileOutputStream(page.getFolders().dstDir + n + ".sch"), r, page.getDefinitions());
    SchematronGenerator sg = new SchematronGenerator(page);
    sg.generate(new FileOutputStream(page.getFolders().dstDir + "fhir-invariants.sch"), page.getDefinitions());
    produceSchemaZip();
    page.log("Load R4 Definitions", LogMessageType.Process);
    loadR4Definitions();
    page.log("Produce Content", LogMessageType.Process);
    produceSpec();
    if (buildFlags.get("all")) {
        if (web) {
            generateRedirects();
        }
    }
    page.clean();
}
Also used : ArrayList(java.util.ArrayList) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) HashSet(java.util.HashSet) SearchParameterDefn(org.hl7.fhir.definitions.model.SearchParameterDefn) GraphQLSchemaGenerator(org.hl7.fhir.r5.utils.GraphQLSchemaGenerator) SchemaGenerator(org.hl7.fhir.definitions.generators.xsd.SchemaGenerator) ShExGenerator(org.hl7.fhir.r5.conformance.ShExGenerator) GraphQLSchemaGenerator(org.hl7.fhir.r5.utils.GraphQLSchemaGenerator) FileOutputStream(java.io.FileOutputStream) FHIROperationType(org.hl7.fhir.r5.utils.GraphQLSchemaGenerator.FHIROperationType) SchematronGenerator(org.hl7.fhir.definitions.generators.specification.SchematronGenerator)

Example 10 with ShExGenerator

use of org.hl7.fhir.r5.conformance.ShExGenerator in project org.hl7.fhir.core by hapifhir.

the class ShexGeneratorTests method doTest.

private void doTest(String name) throws FileNotFoundException, IOException, FHIRException, UcumException {
    StructureDefinition sd = TestingUtilities.context().fetchResource(StructureDefinition.class, ProfileUtilities.sdNs(name, null));
    if (sd == null) {
        throw new FHIRException("StructuredDefinition for " + name + "was null");
    }
    Path outPath = FileSystems.getDefault().getPath(System.getProperty("java.io.tmpdir"), name.toLowerCase() + ".shex");
    TextFile.stringToFile(new ShExGenerator(TestingUtilities.context()).generate(HTMLLinkPolicy.NONE, sd), outPath.toString());
}
Also used : Path(java.nio.file.Path) StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException) ShExGenerator(org.hl7.fhir.r4b.conformance.ShExGenerator)

Aggregations

FileOutputStream (java.io.FileOutputStream)7 ShExGenerator (org.hl7.fhir.r5.conformance.ShExGenerator)7 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)7 FHIRException (org.hl7.fhir.exceptions.FHIRException)6 JsonParser (org.hl7.fhir.r5.formats.JsonParser)6 XmlParser (org.hl7.fhir.r5.formats.XmlParser)6 CSFile (org.hl7.fhir.utilities.CSFile)6 Path (java.nio.file.Path)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 TransformerException (javax.xml.transform.TransformerException)1 JsonSpecGenerator (org.hl7.fhir.definitions.generators.specification.JsonSpecGenerator)1 ReviewSpreadsheetGenerator (org.hl7.fhir.definitions.generators.specification.ReviewSpreadsheetGenerator)1