Search in sources :

Example 1 with CommonSearchParameter

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

Example 2 with CommonSearchParameter

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

the class SourceParser method loadCommonSearchParameters.

private void loadCommonSearchParameters() throws FHIRFormatError, FileNotFoundException, IOException {
    Bundle bnd = (Bundle) new XmlParser().parse(new CSFileInputStream(Utilities.path(srcDir, "searchparameter", "common-search-parameters.xml")));
    for (BundleEntryComponent be : bnd.getEntry()) {
        SearchParameter sp = (SearchParameter) be.getResource();
        CommonSearchParameter csp = new CommonSearchParameter();
        csp.setId(sp.getId());
        csp.setCode(sp.getCode());
        for (CodeType ct : sp.getBase()) {
            csp.getResources().add(ct.asStringValue());
            definitions.getCommonSearchParameters().put(ct.asStringValue() + "::" + sp.getCode(), csp);
        }
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r5.model.Bundle) CommonSearchParameter(org.hl7.fhir.definitions.model.CommonSearchParameter) CodeType(org.hl7.fhir.r5.model.CodeType) CommonSearchParameter(org.hl7.fhir.definitions.model.CommonSearchParameter) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream)

Example 3 with CommonSearchParameter

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

the class ProfileGenerator method makeSearchParam.

public SearchParameter makeSearchParam(StructureDefinition p, String id, String rn, SearchParameterDefn spd, ResourceDefn rd) throws Exception {
    boolean shared;
    boolean created = true;
    SearchParameter sp;
    if (definitions.getCommonSearchParameters().containsKey(rn + "::" + spd.getCode())) {
        shared = true;
        CommonSearchParameter csp = definitions.getCommonSearchParameters().get(rn + "::" + spd.getCode());
        if (csp.getDefinition() == null) {
            sp = new SearchParameter();
            csp.setDefinition(sp);
            sp.setId(csp.getId());
        } else {
            created = false;
            sp = csp.getDefinition();
        }
    } else {
        shared = false;
        sp = new SearchParameter();
        sp.setId(id.replace("[", "").replace("]", ""));
    }
    spd.setCommonId(sp.getId());
    if (created) {
        sp.setUrl("http://hl7.org/fhir/SearchParameter/" + sp.getId());
        sp.setVersion(version.toCode());
        if (context.getSearchParameter(sp.getUrl()) != null)
            throw new Exception("Duplicated Search Parameter " + sp.getUrl());
        context.cacheResource(sp);
        spd.setResource(sp);
        definitions.addNs(sp.getUrl(), "Search Parameter: " + sp.getName(), rn.toLowerCase() + ".html#search");
        sp.setStatus(spd.getStandardsStatus() == StandardsStatus.NORMATIVE ? PublicationStatus.fromCode("active") : PublicationStatus.fromCode("draft"));
        StandardsStatus sst = ToolingExtensions.getStandardsStatus(sp);
        if (sst == null || (spd.getStandardsStatus() == null && spd.getStandardsStatus().isLowerThan(sst)))
            ToolingExtensions.setStandardsStatus(sp, spd.getStandardsStatus(), spd.getNormativeVersion());
        sp.setExperimental(p.getExperimental());
        sp.setName(spd.getCode());
        sp.setCode(spd.getCode());
        sp.setDate(genDate.getTime());
        sp.setPublisher(p.getPublisher());
        for (ContactDetail tc : p.getContact()) {
            ContactDetail t = sp.addContact();
            if (tc.hasNameElement())
                t.setNameElement(tc.getNameElement().copy());
            for (ContactPoint ts : tc.getTelecom()) t.getTelecom().add(ts.copy());
        }
        if (!definitions.hasResource(p.getType()) && !p.getType().equals("Resource") && !p.getType().equals("DomainResource"))
            throw new Exception("unknown resource type " + p.getType());
        sp.setType(getSearchParamType(spd.getType()));
        if (sp.getType() == SearchParamType.REFERENCE && spd.isHierarchy()) {
            sp.addModifier(SearchParameter.SearchModifierCode.BELOW);
            sp.addModifier(SearchParameter.SearchModifierCode.ABOVE);
        }
        if (shared) {
            sp.setDescription("Multiple Resources: \r\n\r\n* [" + rn + "](" + rn.toLowerCase() + ".html): " + spd.getDescription() + "\r\n");
        } else
            sp.setDescription(preProcessMarkdown(spd.getDescription(), "Search Description"));
        if (!Utilities.noString(spd.getExpression()))
            sp.setExpression(spd.getExpression());
        // addModifiers(sp);
        addComparators(sp);
        String xpath = Utilities.noString(spd.getXPath()) ? new XPathQueryGenerator(this.definitions, null, null).generateXpath(spd.getPaths(), rn) : spd.getXPath();
        if (xpath != null) {
            if (xpath.contains("[x]"))
                xpath = convertToXpath(xpath);
            sp.setXpath(xpath);
            sp.setXpathUsage(spd.getxPathUsage());
        }
        if (sp.getType() == SearchParamType.COMPOSITE) {
            for (CompositeDefinition cs : spd.getComposites()) {
                SearchParameterDefn cspd = findSearchParameter(rd, cs.getDefinition());
                if (cspd != null)
                    sp.addComponent().setExpression(cs.getExpression()).setDefinition(cspd.getUrl());
                else
                    sp.addComponent().setExpression(cs.getExpression()).setDefinition("http://hl7.org/fhir/SearchParameter/" + rn + "-" + cs.getDefinition());
            }
            sp.setMultipleOr(false);
        }
        sp.addBase(p.getType());
    } else {
        if (sp.getType() != getSearchParamType(spd.getType()))
            throw new FHIRException("Type mismatch on common parameter: expected " + sp.getType().toCode() + " but found " + getSearchParamType(spd.getType()).toCode());
        if (!sp.getDescription().contains("[" + rn + "](" + rn.toLowerCase() + ".html)"))
            sp.setDescription(sp.getDescription() + "* [" + rn + "](" + rn.toLowerCase() + ".html): " + spd.getDescription() + "\r\n");
        // ext.addExtension("description", new MarkdownType(spd.getDescription()));
        if (!Utilities.noString(spd.getExpression()) && !sp.getExpression().contains(spd.getExpression()))
            sp.setExpression(sp.getExpression() + " | " + spd.getExpression());
        String xpath = new XPathQueryGenerator(this.definitions, null, null).generateXpath(spd.getPaths(), rn);
        if (xpath != null) {
            if (xpath.contains("[x]"))
                xpath = convertToXpath(xpath);
            if (sp.getXpath() != null && !sp.getXpath().contains(xpath))
                sp.setXpath(sp.getXpath() + " | " + xpath);
            if (sp.getXpathUsage() != spd.getxPathUsage())
                throw new FHIRException("Usage mismatch on common parameter: expected " + sp.getXpathUsage().toCode() + " but found " + spd.getxPathUsage().toCode());
        }
        boolean found = false;
        for (CodeType ct : sp.getBase()) found = found || p.getType().equals(ct.asStringValue());
        if (!found)
            sp.addBase(p.getType());
    }
    spd.setUrl(sp.getUrl());
    for (String target : spd.getWorkingTargets()) {
        if ("Any".equals(target) == true) {
            for (String resourceName : definitions.sortedResourceNames()) {
                boolean found = false;
                for (CodeType st : sp.getTarget()) found = found || st.asStringValue().equals(resourceName);
                if (!found)
                    sp.addTarget(resourceName);
            }
        } else {
            boolean found = false;
            for (CodeType st : sp.getTarget()) found = found || st.asStringValue().equals(target);
            if (!found)
                sp.addTarget(target);
        }
    }
    return sp;
}
Also used : SearchParameterDefn(org.hl7.fhir.definitions.model.SearchParameterDefn) FHIRException(org.hl7.fhir.exceptions.FHIRException) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) CompositeDefinition(org.hl7.fhir.definitions.model.SearchParameterDefn.CompositeDefinition) ContactDetail(org.hl7.fhir.r5.model.ContactDetail) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) CommonSearchParameter(org.hl7.fhir.definitions.model.CommonSearchParameter) CodeType(org.hl7.fhir.r5.model.CodeType) CommonSearchParameter(org.hl7.fhir.definitions.model.CommonSearchParameter) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) StandardsStatus(org.hl7.fhir.utilities.StandardsStatus)

Aggregations

CommonSearchParameter (org.hl7.fhir.definitions.model.CommonSearchParameter)3 SearchParameter (org.hl7.fhir.r5.model.SearchParameter)3 SearchParameterDefn (org.hl7.fhir.definitions.model.SearchParameterDefn)2 CompositeDefinition (org.hl7.fhir.definitions.model.SearchParameterDefn.CompositeDefinition)2 FHIRException (org.hl7.fhir.exceptions.FHIRException)2 CodeType (org.hl7.fhir.r5.model.CodeType)2 StandardsStatus (org.hl7.fhir.utilities.StandardsStatus)2 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)1 SearchType (org.hl7.fhir.definitions.model.SearchParameterDefn.SearchType)1 XmlParser (org.hl7.fhir.r5.formats.XmlParser)1 Bundle (org.hl7.fhir.r5.model.Bundle)1 BundleEntryComponent (org.hl7.fhir.r5.model.Bundle.BundleEntryComponent)1 ContactDetail (org.hl7.fhir.r5.model.ContactDetail)1 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)1 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)1 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)1 XLSXmlParser (org.hl7.fhir.utilities.xls.XLSXmlParser)1