Search in sources :

Example 1 with SearchParameterDefn

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

the class Publisher method buildSearchDefinition.

private void buildSearchDefinition(ResourceDefn rd, SearchParameterDefn spd) throws Exception {
    StructureDefinition p = new StructureDefinition();
    p.setFhirVersion(page.getVersion());
    p.setKind(StructureDefinitionKind.RESOURCE);
    p.setAbstract(true);
    p.setPublisher("Health Level Seven International (" + rd.getWg() + ")");
    p.setName(rd.getName());
    p.setVersion(page.getVersion().toCode());
    p.setType(rd.getName());
    p.addContact().addTelecom().setSystem(ContactPointSystem.URL).setValue("http://hl7.org/fhir");
    SearchParameter sp = new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).makeSearchParam(p, rd.getName() + "-" + spd.getCode(), rd.getName(), spd, rd);
    spd.setResource(sp);
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileGenerator(org.hl7.fhir.definitions.generators.specification.ProfileGenerator) SearchParameter(org.hl7.fhir.r5.model.SearchParameter)

Example 2 with SearchParameterDefn

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

the class PageProcessor method getCompositeExpression.

private String getCompositeExpression(SearchParameterDefn p) {
    StringBuilder b = new StringBuilder();
    b.append("On ");
    b.append(Utilities.escapeXml(p.getExpression()));
    b.append(":");
    for (CompositeDefinition cp : p.getComposites()) {
        b.append("<br/>&nbsp;&nbsp;");
        b.append(cp.getDefinition());
        b.append(": ");
        b.append(Utilities.escapeXml(cp.getExpression()));
    }
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) CompositeDefinition(org.hl7.fhir.definitions.model.SearchParameterDefn.CompositeDefinition)

Example 3 with SearchParameterDefn

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

the class PageProcessor method getSearch.

/*
  private String prepWikiName(String name) {
    return Utilities.noString(name) ? "Index" : Utilities.capitalize(Utilities.fileTitle(name));
  }
  */
private String getSearch(ResourceDefn resource, String searchAdditions) {
    if (resource.getSearchParams().size() == 0)
        return "";
    else {
        StandardsStatus st = resource.getStatus();
        StringBuilder b = new StringBuilder();
        b.append("<h2>Search Parameters</h2>\r\n");
        if (resource.getName().equals("Query"))
            b.append("<p>Search parameters for this resource. The <a href=\"#all\">common parameters</a> also apply.</p>\r\n");
        else
            b.append("<p>Search parameters for this resource. The <a href=\"search.html#all\">common parameters</a> also apply. See <a href=\"search.html\">Searching</a> for more information about searching in REST, messaging, and services.</p>\r\n");
        b.append("<table class=\"list\">\r\n");
        b.append("<tr><td><b>Name</b></td><td><b>Type</b></td><td><b>Description</b></td><td><b>Expression</b></td><td><b>In Common</b></td></tr>\r\n");
        List<String> names = new ArrayList<String>();
        names.addAll(resource.getSearchParams().keySet());
        Collections.sort(names);
        for (String name : names) {
            SearchParameterDefn p = resource.getSearchParams().get(name);
            String pp = presentPaths(p.getPaths());
            String sst = (p.getStandardsStatus() == null || p.getStandardsStatus() == st) ? "" : makeStandardsStatusRef(p.getStandardsStatus());
            b.append("<tr><td><a name=\"sp-").append(p.getCode()).append("\"> </a>").append(p.getCode()).append(sst).append("</td><td><a href=\"search.html#").append(p.getType()).append("\">").append(p.getType()).append("</a></td><td>").append(Utilities.escapeXml(p.getDescription())).append("</td><td>").append(p.getType() == SearchType.composite ? getCompositeExpression(p) : Utilities.escapeXml(p.getExpression())).append(p.getType() == SearchType.reference ? p.getTargetTypesAsText() : "").append("</td><td>").append(presentOthers(p)).append("</td></tr>\r\n");
        }
        b.append(searchAdditions);
        b.append("</table>\r\n");
        return b.toString();
    }
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) SearchParameterDefn(org.hl7.fhir.definitions.model.SearchParameterDefn) ArrayList(java.util.ArrayList) StandardsStatus(org.hl7.fhir.utilities.StandardsStatus)

Example 4 with SearchParameterDefn

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

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

the class OldSpreadsheetParser method readSearchParams.

private void readSearchParams(ResourceDefn root2, Sheet sheet, boolean forProfile) throws Exception {
    if (sheet != null) {
        for (int row = 0; row < sheet.rows.size(); row++) {
            if (!sheet.hasColumn(row, "Name"))
                throw new Exception("Search Param has no name " + getLocation(row));
            String n = sheet.getColumn(row, "Name");
            if (!n.startsWith("!")) {
                if (!sheet.hasColumn(row, "Type"))
                    throw new Exception("Search Param " + root2.getName() + "/" + n + " has no type " + getLocation(row));
                if (n.endsWith("-before") || n.endsWith("-after"))
                    throw new Exception("Search Param " + root2.getName() + "/" + n + " includes relative time " + getLocation(row));
                if (root2.getSearchParams().containsKey(n))
                    throw new Exception("Search Param " + root2.getName() + "/" + n + ": duplicate name " + getLocation(row));
                String d = sheet.getColumn(row, "Description");
                SearchType t = readSearchType(sheet.getColumn(row, "Type"), row);
                SearchParameter.XPathUsageType pu = readSearchXPathUsage(sheet.getColumn(row, "Path Usage"), row);
                if (Utilities.noString(sheet.getColumn(row, "Path")) && !root2.getName().equals("Resource") && !root2.getName().equals("DomainResource"))
                    throw new Exception("Search Param " + root2.getName() + "/" + n + " has no path at " + getLocation(row));
                SearchParameterDefn sp = null;
                if (t == SearchType.composite) {
                    List<CompositeDefinition> pn = new ArrayList<CompositeDefinition>();
                    if (Utilities.noString(d))
                        throw new Exception("Search Param " + root2.getName() + "/" + n + " has no description " + getLocation(row));
                    String[] pl = sheet.getColumn(row, "Path").split("\\&");
                    String[] pe = sheet.getColumn(row, "Expression").split("\\;");
                    if (pe.length != pl.length + 1)
                        throw new Exception("Composite Search Param " + root2.getName() + "/" + n + " needs expressions " + getLocation(row));
                    int i = 0;
                    for (String pi : pl) {
                        String p = pi.trim();
                        i++;
                        String e = pe[i].trim();
                        if (!root2.getSearchParams().containsKey(p)) {
                            boolean found = false;
                            if (p.endsWith("[x]"))
                                for (String pan : root2.getSearchParams().keySet()) {
                                    if (pan.startsWith(p.substring(0, p.length() - 3)))
                                        found = true;
                                }
                            if (!found)
                                throw new Exception("Composite Search Param " + root2.getName() + "/" + n + "  refers to an unknown component " + p + " at " + getLocation(row));
                        }
                        pn.add(new CompositeDefinition(p, e));
                    }
                    StandardsStatus ss = root2.getStatus();
                    if (!Utilities.noString(sheet.getColumn(row, "Standards-Status")))
                        ss = StandardsStatus.fromCode(sheet.getColumn(row, "Standards-Status"));
                    sp = new SearchParameterDefn(n, d, t, pu, ss);
                    sp.setExpression(pe[0].trim());
                    sp.getComposites().addAll(pn);
                } else {
                    List<String> pn = new ArrayList<String>();
                    String xp = sheet.getColumn(row, "XPath");
                    String[] pl = sheet.getColumn(row, "Path").split("\\|");
                    boolean hierarchy = false;
                    for (String pi : pl) {
                        String p = pi.trim();
                        ElementDefn e = null;
                        if (!Utilities.noString(p) && !p.startsWith("!") && !p.startsWith("Extension{") && definitions != null) {
                            e = root2.getRoot().getElementForPath(trimIndexes(p), definitions, "search param", true, true);
                        }
                        if (e != null && e.hasHierarchy() && e.getHierarchy())
                            hierarchy = true;
                        if (Utilities.noString(d) && e != null)
                            d = e.getShortDefn();
                        if (p.startsWith("Extension(")) {
                            String url = extractExtensionUrl(p);
                            StructureDefinition ex = context.fetchResource(StructureDefinition.class, url);
                            if (ex == null)
                                throw new Exception("Search Param " + root2.getName() + "/" + n + " refers to unknown extension '" + url + "' " + getLocation(row));
                            if (Utilities.noString(d))
                                d = ex.getDescription();
                            pn.add(p);
                        }
                        if (d == null)
                            throw new Exception("Search Param " + root2.getName() + "/" + n + " has no description " + getLocation(row));
                        if (e != null)
                            pn.add(p);
                        if (t == SearchType.reference) {
                            if (e == null && !forProfile && !sheet.hasColumn(row, "Target Types"))
                                throw new Exception("Search Param " + root2.getName() + "/" + n + " of type reference has wrong path '" + p + "' at " + getLocation(row));
                            if (!forProfile && e != null && (!e.hasType("Reference")) && (!e.hasType("canonical")) && (!e.hasType("Resource")))
                                throw new Exception("Search Param " + root2.getName() + "/" + n + " wrong type. The search type is reference, but the element type is " + e.typeCode());
                        } else {
                            if (e != null && e.hasOnlyType("Reference"))
                                throw new Exception("Search Param " + root2.getName() + "/" + n + " wrong type. The search type is " + t.toString() + ", but the element type is " + e.typeCode());
                            if (t == SearchType.uri) {
                                if (e != null && !(e.typeCode().equals("uri") || e.typeCode().equals("url") || e.typeCode().equals("oid") || e.typeCode().startsWith("canonical(")))
                                    throw new Exception("Search Param " + root2.getName() + "/" + n + " wrong type. The search type is " + t.toString() + ", but the element type is " + e.typeCode());
                            } else {
                                if (e != null && e.typeCode().equals("uri"))
                                    throw new Exception("Search Param " + root2.getName() + "/" + n + " wrong type. The search type is " + t.toString() + ", but the element type is " + e.typeCode());
                            }
                        }
                    }
                    if (!forProfile && t == SearchType.reference && pn.size() == 0 && !sheet.hasColumn(row, "Target Types"))
                        throw new Exception("Search Param " + root2.getName() + "/" + n + " of type reference has no path(s) " + getLocation(row));
                    StandardsStatus ss = root2.getStatus();
                    if (!Utilities.noString(sheet.getColumn(row, "Standards-Status")))
                        ss = StandardsStatus.fromCode(sheet.getColumn(row, "Standards-Status"));
                    sp = new SearchParameterDefn(n, d, t, pu, ss);
                    sp.getPaths().addAll(pn);
                    if (!Utilities.noString(xp))
                        sp.setXPath(xp);
                    if (!Utilities.noString(sheet.getColumn(row, "Expression")))
                        sp.setExpression(sheet.getColumn(row, "Expression"));
                    if (!Utilities.noString(sheet.getColumn(row, "Target Types"))) {
                        sp.setManualTypes(sheet.getColumn(row, "Target Types").split("\\,"));
                    }
                    sp.setHierarchy(hierarchy);
                    CommonSearchParameter csp = definitions.getCommonSearchParameters().get(root2.getName() + "::" + n);
                    if (csp != null)
                        for (String s : csp.getResources()) {
                            if (!root2.getName().equals(s))
                                sp.getOtherResources().add(s);
                        }
                }
                root2.getSearchParams().put(n, sp);
            }
        }
    }
}
Also used : SearchParameterDefn(org.hl7.fhir.definitions.model.SearchParameterDefn) ArrayList(java.util.ArrayList) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) FHIRException(org.hl7.fhir.exceptions.FHIRException) CompositeDefinition(org.hl7.fhir.definitions.model.SearchParameterDefn.CompositeDefinition) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) CommonSearchParameter(org.hl7.fhir.definitions.model.CommonSearchParameter) SearchType(org.hl7.fhir.definitions.model.SearchParameterDefn.SearchType) CommonSearchParameter(org.hl7.fhir.definitions.model.CommonSearchParameter) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) StandardsStatus(org.hl7.fhir.utilities.StandardsStatus)

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