Search in sources :

Example 16 with SearchParameterDefn

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

the class Regenerator method generateSearchParams.

private void generateSearchParams(String root, ResourceDefn r) throws FileNotFoundException, IOException {
    Bundle bnd = new Bundle();
    bnd.setId(r.getName() + "-search-params");
    for (String s : sorted(r.getSearchParams().keySet())) {
        SearchParameterDefn spd = r.getSearchParams().get(s);
        SearchParameter sp = new SearchParameter();
        sp.setId(r.getName() + "-" + spd.getCode());
        bnd.addEntry().setResource(sp);
        sp.setUrl("http://hl7.org/fhir/build/SearchParameter/" + sp.getId());
        sp.setCode(spd.getCode());
        sp.setDescription(spd.getDescription());
        sp.setXpath(spd.getXPath());
        switch(spd.getType()) {
            case composite:
                sp.setType(SearchParamType.COMPOSITE);
                break;
            case date:
                sp.setType(SearchParamType.DATE);
                break;
            case number:
                sp.setType(SearchParamType.NUMBER);
                break;
            case quantity:
                sp.setType(SearchParamType.QUANTITY);
                break;
            case reference:
                sp.setType(SearchParamType.REFERENCE);
                break;
            case special:
                sp.setType(SearchParamType.SPECIAL);
                break;
            case string:
                sp.setType(SearchParamType.STRING);
                break;
            case token:
                sp.setType(SearchParamType.TOKEN);
                break;
            case uri:
                sp.setType(SearchParamType.URI);
                break;
        }
        sp.setXpathUsage(spd.getxPathUsage());
        CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder(",");
        for (String p : spd.getPaths()) {
            b.append(p);
        }
        if (!Utilities.noString(b.toString())) {
            sp.addExtension(BuildExtensions.EXT_PATH, new StringType(b.toString()));
        }
        sp.setExpression(spd.getExpression());
        if (spd.hasManualTypes()) {
            for (String t : sorted(spd.getManualTypes())) {
                sp.addTarget(t);
            }
        }
        if (spd.getStandardsStatus() != null) {
            sp.addExtension(ToolingExtensions.EXT_STANDARDS_STATUS, new CodeType(spd.getStandardsStatus().toCode()));
        }
        for (CompositeDefinition c : spd.getComposites()) {
            sp.addComponent().setExpression(c.getExpression()).setDefinition(c.getDefinition());
        }
    }
    File fn = new File(Utilities.path(root, bnd.fhirType().toLowerCase() + "-" + bnd.getId() + ".gen.xml"));
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), bnd);
    fn.setLastModified(r.getTimestamp());
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) StringType(org.hl7.fhir.r5.model.StringType) Bundle(org.hl7.fhir.r5.model.Bundle) SearchParameterDefn(org.hl7.fhir.definitions.model.SearchParameterDefn) FileOutputStream(java.io.FileOutputStream) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) CodeType(org.hl7.fhir.r5.model.CodeType) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) File(java.io.File) CompositeDefinition(org.hl7.fhir.definitions.model.SearchParameterDefn.CompositeDefinition)

Example 17 with SearchParameterDefn

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

the class Publisher method addSearchParams.

private void addSearchParams(Set<String> uris, Bundle bundle, ResourceDefn rd) throws Exception {
    if (rd.getConformancePack() == null) {
        for (SearchParameterDefn spd : rd.getSearchParams().values()) {
            if (spd.getResource() == null) {
                buildSearchDefinition(rd, spd);
            }
            SearchParameter sp = spd.getResource();
            if (!uris.contains(sp.getUrl())) {
                bundle.addEntry().setResource(sp).setFullUrl("http://hl7.org/fhir/" + sp.fhirType() + "/" + sp.getId());
                uris.add(sp.getUrl());
            }
        }
    } else
        addSearchParams(uris, bundle, rd.getConformancePack());
}
Also used : SearchParameterDefn(org.hl7.fhir.definitions.model.SearchParameterDefn) SearchParameter(org.hl7.fhir.r5.model.SearchParameter)

Example 18 with SearchParameterDefn

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

the class Publisher method makeSearchParam.

private CapabilityStatementRestResourceSearchParamComponent makeSearchParam(String rn, SearchParameterDefn i) throws Exception {
    CapabilityStatementRestResourceSearchParamComponent result = new CapabilityStatement.CapabilityStatementRestResourceSearchParamComponent();
    result.setName(i.getCode());
    result.setDefinition("http://hl7.org/fhir/SearchParameter/" + i.getCommonId());
    result.setType(getSearchParamType(i.getType()));
    result.setDocumentation(i.getDescription());
    if (Utilities.noString(i.getXPath()))
        // used elsewhere later
        i.setXPath(new XPathQueryGenerator(page.getDefinitions(), page, page.getQa()).generateXpath(i.getPaths(), rn));
    return result;
}
Also used : XPathQueryGenerator(org.hl7.fhir.definitions.generators.specification.XPathQueryGenerator) CapabilityStatementRestResourceSearchParamComponent(org.hl7.fhir.r5.model.CapabilityStatement.CapabilityStatementRestResourceSearchParamComponent)

Example 19 with SearchParameterDefn

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

the class Publisher method miscValidation.

private void miscValidation() throws Exception {
    page.log("Other Validation", LogMessageType.Process);
    page.clean2();
    for (String rn : page.getDefinitions().sortedResourceNames()) {
        ResourceDefn r = page.getDefinitions().getResourceByName(rn);
        for (SearchParameterDefn sp : r.getSearchParams().values()) {
            if (!sp.isWorks() && !sp.getCode().equals("_id") && !Utilities.noString(sp.getExpression())) {
                page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.INFORMATIONAL, -1, -1, rn + "." + sp.getCode(), "Search Parameter '" + rn + "." + sp.getCode() + "' had no found values in any example. Consider reviewing the expression (" + sp.getExpression() + ")", IssueSeverity.WARNING));
            }
        }
    }
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) SearchParameterDefn(org.hl7.fhir.definitions.model.SearchParameterDefn) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 20 with SearchParameterDefn

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

SearchParameterDefn (org.hl7.fhir.definitions.model.SearchParameterDefn)15 ArrayList (java.util.ArrayList)8 SearchParameter (org.hl7.fhir.r5.model.SearchParameter)8 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)5 CompositeDefinition (org.hl7.fhir.definitions.model.SearchParameterDefn.CompositeDefinition)5 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)5 FHIRException (org.hl7.fhir.exceptions.FHIRException)4 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)4 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)3 CodeType (org.hl7.fhir.r5.model.CodeType)3 StandardsStatus (org.hl7.fhir.utilities.StandardsStatus)3 FileNotFoundException (java.io.FileNotFoundException)2 URISyntaxException (java.net.URISyntaxException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 ProfileGenerator (org.hl7.fhir.definitions.generators.specification.ProfileGenerator)2 CommonSearchParameter (org.hl7.fhir.definitions.model.CommonSearchParameter)2 XmlParser (org.hl7.fhir.r5.formats.XmlParser)2