Search in sources :

Example 1 with SchemaGenerator

use of org.hl7.fhir.definitions.generators.xsd.SchemaGenerator 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)

Aggregations

FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 SchematronGenerator (org.hl7.fhir.definitions.generators.specification.SchematronGenerator)1 SchemaGenerator (org.hl7.fhir.definitions.generators.xsd.SchemaGenerator)1 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)1 SearchParameterDefn (org.hl7.fhir.definitions.model.SearchParameterDefn)1 ShExGenerator (org.hl7.fhir.r5.conformance.ShExGenerator)1 SearchParameter (org.hl7.fhir.r5.model.SearchParameter)1 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)1 GraphQLSchemaGenerator (org.hl7.fhir.r5.utils.GraphQLSchemaGenerator)1 FHIROperationType (org.hl7.fhir.r5.utils.GraphQLSchemaGenerator.FHIROperationType)1