Search in sources :

Example 1 with NamespaceContextMap

use of org.hl7.fhir.utilities.xml.NamespaceContextMap in project kindling by HL7.

the class ExampleInspector method testSearchParameters.

private void testSearchParameters(org.w3c.dom.Element xe, String rn, boolean inBundle) throws FHIRException {
    ResourceDefn r = definitions.getResources().get(rn);
    for (SearchParameterDefn sp : r.getSearchParams().values()) {
        if (!sp.isXPathDone() && !Utilities.noString(sp.getXPath())) {
            try {
                sp.setXPathDone(true);
                NamespaceContext context = new NamespaceContextMap("f", "http://hl7.org/fhir", "h", "http://www.w3.org/1999/xhtml");
                XPathFactory factory = XPathFactory.newInstance();
                XPath xpath = factory.newXPath();
                xpath.setNamespaceContext(context);
                XPathExpression expression;
                expression = inBundle ? xpath.compile("/f:Bundle/f:entry/f:resource/" + sp.getXPath()) : xpath.compile("/" + sp.getXPath());
                NodeList resultNodes = (NodeList) expression.evaluate(xe, XPathConstants.NODESET);
                if (resultNodes.getLength() > 0)
                    sp.setWorks(true);
            } catch (Exception e1) {
                throw new FHIRException("Xpath \"" + sp.getXPath() + "\" execution failed: " + e1.getMessage(), e1);
            }
        }
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) XPathFactory(javax.xml.xpath.XPathFactory) SearchParameterDefn(org.hl7.fhir.definitions.model.SearchParameterDefn) NamespaceContext(javax.xml.namespace.NamespaceContext) NamespaceContextMap(org.hl7.fhir.utilities.xml.NamespaceContextMap) NodeList(org.w3c.dom.NodeList) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) ValidationException(org.everit.json.schema.ValidationException) MalformedURLException(java.net.MalformedURLException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 2 with NamespaceContextMap

use of org.hl7.fhir.utilities.xml.NamespaceContextMap 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

ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)2 SearchParameterDefn (org.hl7.fhir.definitions.model.SearchParameterDefn)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 NamespaceContext (javax.xml.namespace.NamespaceContext)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XPath (javax.xml.xpath.XPath)1 XPathExpression (javax.xml.xpath.XPathExpression)1 XPathFactory (javax.xml.xpath.XPathFactory)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1 ValidationException (org.everit.json.schema.ValidationException)1 SchematronGenerator (org.hl7.fhir.definitions.generators.specification.SchematronGenerator)1 SchemaGenerator (org.hl7.fhir.definitions.generators.xsd.SchemaGenerator)1 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)1