use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class OldSpreadsheetParser method findContext.
private ElementDefn findContext(ElementDefn root, String pathname, String source) throws Exception {
String[] path = pathname.split("\\.");
if (!path[0].equals(root.getName()))
throw new Exception("Element Path '" + pathname + "' is not legal found at " + source);
ElementDefn res = root;
for (int i = 1; i < path.length; i++) {
String en = path[i];
if (en.length() == 0)
throw new Exception("Improper path " + pathname + " found at " + source);
if (en.charAt(en.length() - 1) == '*')
throw new Exception("no-list wrapper found at " + source);
ElementDefn t = res.getElementByName(en, true, definitions, "find context", false);
if (t == null) {
throw new Exception("Reference to undefined Element " + pathname + " found at " + source);
}
res = t;
}
return res;
}
use of org.hl7.fhir.definitions.model.ElementDefn 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);
}
}
}
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class OldSpreadsheetParser method readSearchParams.
/* for profiles that have a "search" tab not tied to a structure */
private void readSearchParams(Profile pack, Sheet sheet, String prefix) throws Exception {
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("!")) {
SearchParameter sp = new SearchParameter();
if (!sheet.hasColumn(row, "Type"))
throw new Exception("Search Param " + pack.getTitle() + "/" + n + " has no type " + getLocation(row));
if (n.endsWith("-before") || n.endsWith("-after"))
throw new Exception("Search Param " + pack.getTitle() + "/" + n + " includes relative time " + getLocation(row));
// if (!n.toLowerCase().equals(n))
// throw new Exception("Search Param "+pack.getTitle()+"/"+n+" must be all lowercase "+ getLocation(row));
sp.setVersion(version.toCode());
sp.setName(n);
sp.setCode(n);
if (pack.getProfiles().size() > 0 && pack.getProfiles().get(0).getResource() != null) {
sp.setStatus(pack.getProfiles().get(0).getResource().getStatus());
sp.setExperimental(pack.getProfiles().get(0).getResource().getExperimental());
} else {
// we just guess
sp.setStatus(PublicationStatus.DRAFT);
sp.setExperimental(true);
}
String d = sheet.getColumn(row, "Description");
sp.setType(SearchParamType.fromCode(sheet.getColumn(row, "Type")));
List<String> pn = new ArrayList<String>();
String path = sheet.getColumn(row, "Path");
if (Utilities.noString(path))
throw new Exception("Search Param " + pack.getTitle() + "/" + n + " has no path");
if (!path.contains(".") && !path.startsWith("#"))
throw new Exception("Search Param " + pack.getTitle() + "/" + n + " has an invalid path: " + path);
ResourceDefn root2 = null;
if (!path.startsWith("#")) {
path = path.substring(0, path.indexOf('.'));
if (!pkp.isResource(path))
throw new Exception("Ilegal Search Parameter path " + sheet.getColumn(row, "Path"));
sp.addBase(path);
sp.setId(pack.getId() + "-" + path + "-" + sp.getName());
if (definitions != null) {
// igtodo (and below)
root2 = definitions.getResourceByName(path);
if (root2 == null)
throw new Exception("Search Param " + pack.getTitle() + "/" + n + " has an invalid path (resource not found)");
if (!pkp.isResource(root2.getName()))
throw new Exception("Ilegal Search Parameter path " + sheet.getColumn(row, "Path"));
sp.getBase().clear();
sp.addBase(root2.getName());
sp.setId(pack.getId() + "-" + (root2 == null ? "all" : root2.getName()) + "-" + sp.getName());
}
}
if (!Utilities.noString(sheet.getColumn(row, "Target Types")))
throw new Exception("Search Param " + pack.getTitle() + "/" + n + " has manually specified targets (not allowed)");
if (root2 != null && root2.getSearchParams().containsKey(n))
throw new Exception("Search Param " + root2.getName() + "/" + n + ": duplicate name " + getLocation(row));
if (sp.getType() == SearchParamType.COMPOSITE) {
throw new Exception("not supported");
} else {
String[] pl = sheet.getColumn(row, "Path").split("\\|");
String xp = sheet.getColumn(row, "XPath");
for (String pi : pl) {
String p = pi.trim();
ElementDefn e = null;
if (Utilities.noString(p))
throw new Exception("Search Param " + root2.getName() + "/" + n + ": empty path " + getLocation(row));
if (p.startsWith("#")) {
// root less extension search parameter
StructureDefinition ex = pack.getExtension(prefix + p.substring(1));
if (ex == null)
throw new Exception("Search Param " + pack.getTitle() + "/" + n + " refers to unknown extension '" + p + "' " + getLocation(row));
e = definitions.getElementDefn("Extension");
if (ex.getContext().size() != 1 || ex.getContext().get(0).getType() != ExtensionContextType.ELEMENT)
throw new Exception("Search Param " + pack.getTitle() + "/" + n + " refers to an extension with multiple contexts, not not an element context - not supported '" + p + "' " + getLocation(row));
path = ex.getContext().get(0).getExpression();
if (Utilities.noString(path))
throw new Exception("Search Param " + pack.getTitle() + "/" + n + " has no path");
if (path.contains("."))
path = path.substring(0, path.indexOf('.'));
sp.setId(pack.getId() + "-" + path + "-" + sp.getName());
root2 = definitions.getResourceByName(path);
if (root2 == null)
throw new Exception("Search Param " + pack.getTitle() + "/" + n + " has an invalid path (resource not found)");
if (root2 != null && root2.getSearchParams().containsKey(n))
throw new Exception("Search Param " + root2.getName() + "/" + n + ": duplicate name " + getLocation(row));
sp.setId(pack.getId() + "-" + path + "-" + sp.getName());
pn.add(ex.getContext().get(0).getExpression() + ".extension{" + ex.getUrl() + "}");
} else if (p.contains(".extension{")) {
String url = extractExtensionUrl(p);
// not created yet?
StructureDefinition ex = context.fetchResource(StructureDefinition.class, url);
if (ex == null)
ex = context.getExtensionStructure(null, url);
if (ex == null)
throw new Exception("Search Param " + pack.getTitle() + "/" + n + " refers to unknown extension '" + url + "' " + getLocation(row));
if (Utilities.noString(d))
d = ex.getDescription();
if (definitions != null)
e = definitions.getElementDefn("Extension");
pn.add(p);
} else if (!p.startsWith("!") && !p.startsWith("Extension{") && root2 != null) {
e = root2.getRoot().getElementForPath(p, definitions, "search param", true, true);
}
if (e == null && Utilities.noString(d))
throw new Exception("unable to resolve sarch param " + p);
if (e == null)
sp.setExpression(p);
if (Utilities.noString(d) && e != null)
d = e.getShortDefn();
if (d == null)
throw new Exception("Search Param " + root2.getName() + "/" + n + " has no description " + getLocation(row));
if (e != null)
pn.add(p);
if (sp.getType() == SearchParamType.REFERENCE) {
// no check?
} else if (e != null && e.typeCode().startsWith("Reference("))
throw new Exception("Search Param " + root2.getName() + "/" + n + " wrong type. The search type is " + sp.getType().toCode() + ", but the element type is " + e.typeCode());
sp.setDescription(d);
}
sp.setXpath(Utilities.noString(xp) ? new XPathQueryGenerator(definitions, log, null).generateXpath(pn, null) : xp);
sp.setXpathUsage(readSearchXPathUsage(sheet.getColumn(row, "Path Usage"), row));
}
sp.setUrl("http://hl7.org/fhir/SearchParameter/" + sp.getId());
if (definitions != null)
definitions.addNs(sp.getUrl(), "Search Parameter " + sp.getName(), pack.getId() + ".html#search");
if (context.getSearchParameter(sp.getUrl()) != null)
throw new Exception("Duplicated Search Parameter " + sp.getUrl());
context.cacheResource(sp);
pack.getSearchParameters().add(sp);
}
}
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class SourceParser method processEvent.
private void processEvent(EventDefn defn, ElementDefn root) throws Exception {
// Exception("Event "+defn.getCode()+" has a mismatched request resource - should be "+root.getName()+", is "+defn.getUsages().get(0).getRequestResources().get(0));
if (definitions.getEvents().containsKey(defn.getCode())) {
EventDefn master = definitions.getEvents().get(defn.getCode());
master.getUsages().add(defn.getUsages().get(0));
if (!defn.getDefinition().startsWith("(see"))
master.setDefinition(defn.getDefinition());
} else
definitions.getEvents().put(defn.getCode(), defn);
}
use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.
the class PatternFinder method sortRefs.
private String sortRefs(ElementDefn focus) {
List<String> s = new ArrayList<>();
for (TypeRef t : focus.getTypes()) {
if ("Reference".equals(t.getName())) {
for (String p : t.getParams()) {
if (definitions.hasLogicalModel(p))
s.addAll(definitions.getLogicalModel(p).getImplementations());
else
s.add(p);
}
}
}
Collections.sort(s);
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
for (String n : s) b.append(n);
return b.toString();
}
Aggregations