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);
}
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/> ");
b.append(cp.getDefinition());
b.append(": ");
b.append(Utilities.escapeXml(cp.getExpression()));
}
return b.toString();
}
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();
}
}
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);
}
}
}
}
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);
}
}
}
}
Aggregations