Search in sources :

Example 46 with SearchParameter

use of org.hl7.fhir.r4.model.SearchParameter in project kindling by HL7.

the class SpreadSheetCreator method addPack.

private void addPack(XSSFSheet sheet, String ref) throws FHIRFormatError, FileNotFoundException, IOException {
    ImplementationGuide ig = (ImplementationGuide) parseXml(fnIG(ref));
    ig.setText(null);
    int rowCount = 1;
    sortExtensions(ig);
    addPackRow(sheet, CN_ID, ig.getId(), rowCount++);
    addPackRow(sheet, CN_CODE, BuildExtensions.readStringExtension(ig, BuildExtensions.EXT_CODE), rowCount++);
    addPackRow(sheet, CN_NAME, ig.getName(), rowCount++);
    addPackRow(sheet, CN_TITLE, ig.getTitle(), rowCount++);
    addPackRow(sheet, CN_VERSION, ig.getVersion(), rowCount++);
    addPackRow(sheet, CN_DESCRIPTION, ig.getDescription(), rowCount++);
    addPackRow(sheet, CN_PUBLISHER, ig.getPublisher(), rowCount++);
    addPackRow(sheet, CN_STATUS, ig.getStatus().toCode(), rowCount++);
    addPackRow(sheet, CN_EXPERIMENTAL, ig.getExperimentalElement().primitiveValue(), rowCount++);
    addPackRow(sheet, CN_DATE, ig.getDateElement().primitiveValue(), rowCount++);
    addPackRow(sheet, CN_FMM, BuildExtensions.readStringExtension(ig, BuildExtensions.EXT_FMM_LEVEL), rowCount++);
    addPackRow(sheet, CN_WORK_GROUP, BuildExtensions.readStringExtension(ig, BuildExtensions.EXT_WORKGROUP), rowCount++);
    addPackRow(sheet, CN_INTRODUCTION, BuildExtensions.readStringExtension(ig, BuildExtensions.EXT_INTRODUCTION), rowCount++);
    addPackRow(sheet, CN_NOTES, BuildExtensions.readStringExtension(ig, BuildExtensions.EXT_NOTES), rowCount++);
    for (ImplementationGuideDefinitionResourceComponent res : ig.getDefinition().getResource()) {
        String r = res.getReference().getReference();
        String id = r.substring(r.indexOf("/") + 1);
        if (r.startsWith("SearchParameter/")) {
            addPackRow(sheet, CN_SEARCH_PARAMETER, id, rowCount++);
        } else if (r.startsWith("StructureDefinition/")) {
            String fn = fnExt(id);
            if (new File(fn).exists()) {
                addPackRow(sheet, CN_EXTENSION, id, rowCount++);
            } else {
                addPackRow(sheet, CN_PROFILE, id, rowCount++);
            }
        } else {
            addPackRow(sheet, CN_EXAMPLE, r, rowCount++);
        }
    }
}
Also used : ImplementationGuide(org.hl7.fhir.r5.model.ImplementationGuide) ImplementationGuideDefinitionResourceComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent) File(java.io.File) IniFile(org.hl7.fhir.utilities.IniFile)

Example 47 with SearchParameter

use of org.hl7.fhir.r4.model.SearchParameter 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 48 with SearchParameter

use of org.hl7.fhir.r4.model.SearchParameter 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 49 with SearchParameter

use of org.hl7.fhir.r4.model.SearchParameter in project kindling by HL7.

the class Publisher method produceConformancePackage.

private void produceConformancePackage(ResourceDefn res, Profile pack, SectionTracker st) throws Exception {
    String resourceName = res == null ? "" : res.getName();
    if (Utilities.noString(resourceName)) {
        if (pack.getProfiles().size() == 1)
            if (pack.getProfiles().get(0).getDefn() != null)
                resourceName = pack.getProfiles().get(0).getDefn().getName();
            else
                resourceName = pack.getProfiles().get(0).getResource().getType();
        else if (pack.getProfiles().size() == 0) {
        // throw new Exception("Unable to determine resource name - no profiles"); no, we don't complain
        } else if (pack.getProfiles().get(0).getDefn() != null) {
            resourceName = pack.getProfiles().get(0).getDefn().getName();
            for (int i = 1; i < pack.getProfiles().size(); i++) if (!pack.getProfiles().get(i).getDefn().getName().equals(resourceName))
                throw new Exception("Unable to determine resource name - profile mismatch " + resourceName + "/" + pack.getProfiles().get(i).getDefn().getName());
        }
    }
    ImplementationGuideDefn ig = page.getDefinitions().getIgs().get(pack.getCategory());
    String prefix = (ig == null || ig.isCore()) ? "" : ig.getCode() + File.separator;
    String intro = pack.getIntroduction() != null ? page.loadXmlNotesFromFile(pack.getIntroduction(), false, null, null, null, null, res == null ? wg("fhir") : res.getWg()) : null;
    String notes = pack.getNotes() != null ? page.loadXmlNotesFromFile(pack.getNotes(), false, null, null, null, null, res == null ? wg("fhir") : res.getWg()) : null;
    if (!("profile".equals(pack.metadata("navigation")) && pack.getProfiles().size() == 1)) {
        String src = TextFile.fileToString(page.getFolders().templateDir + "template-conformance-pack.html");
        src = page.processConformancePackageIncludes(pack, src, intro, notes, resourceName, ig);
        if (st != null)
            src = insertSectionNumbers(src, st, pack.getId().toLowerCase() + ".html", 0, null);
        else if (ig != null && !ig.isCore())
            src = addSectionNumbers(pack.getId() + ".html", pack.getId().toLowerCase(), src, null, 1, null, ig);
        page.getHTMLChecker().registerFile(prefix + pack.getId().toLowerCase() + ".html", "Profile " + pack.getId(), HTMLLinkChecker.XHTML_TYPE, true);
        TextFile.stringToFile(src, page.getFolders().dstDir + prefix + pack.getId().toLowerCase() + ".html");
    }
    // now, we produce each profile
    for (ConstraintStructure profile : pack.getProfiles()) produceProfile(res, pack, profile, st, intro, notes, prefix, ig);
    for (SearchParameter sp : pack.getSearchParameters()) producePackSearchParameter(res, pack, sp, st, ig);
    for (Example ex : pack.getExamples()) {
        StructureDefinition sd = null;
        boolean ambiguous = false;
        for (ConstraintStructure sdt : pack.getProfiles()) {
            if (sdt.getResource().getSnapshot().getElement().get(0).getPath().equals(resourceName))
                if (sd == null)
                    sd = sdt.getResource();
                else
                    ambiguous = true;
        }
        if (ambiguous)
            processExample(ex, res, null, null, ig);
        else
            processExample(ex, res, sd, pack, ig);
    }
// create examples here
// if (examples != null) {
// for (String en : examples.keySet()) {
// processExample(examples.get(en), null, profile.getSource());
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Example(org.hl7.fhir.definitions.model.Example) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 50 with SearchParameter

use of org.hl7.fhir.r4.model.SearchParameter 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

SearchParameter (org.hl7.fhir.r5.model.SearchParameter)32 FHIRException (org.hl7.fhir.exceptions.FHIRException)13 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)13 ArrayList (java.util.ArrayList)12 File (java.io.File)9 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)9 SearchParameter (org.hl7.fhir.r4b.model.SearchParameter)9 CodeType (org.hl7.fhir.r5.model.CodeType)9 HashSet (java.util.HashSet)8 FileOutputStream (java.io.FileOutputStream)7 XmlParser (org.hl7.fhir.r5.formats.XmlParser)7 FileNotFoundException (java.io.FileNotFoundException)6 IOException (java.io.IOException)6 SearchParameterDefn (org.hl7.fhir.definitions.model.SearchParameterDefn)6 CanonicalResource (org.hl7.fhir.r5.model.CanonicalResource)6 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)6 ImplementationGuide (org.hl7.fhir.r5.model.ImplementationGuide)6 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)6 ConstraintStructure (org.hl7.fhir.definitions.model.ConstraintStructure)5 Example (org.hl7.fhir.definitions.model.Example)5