use of org.hl7.fhir.r5.model.Extension in project kindling by HL7.
the class DefinitionsUsageTracker method usage.
private void usage(org.hl7.fhir.r5.elementmodel.Element instance, ElementDefn definition, String path) throws Exception {
definition.setCoveredByExample(true);
for (Element c : instance.getChildren()) {
String p = c.getProperty().getDefinition().getPath();
ElementDefn ed = definitions.getElementByPath(p.split("\\."), "example usage", true);
if (ed != null)
usage(c, ed, path + "." + c.getName());
// else if (!c.getName().equals("extension"))
// System.out.println("error finding "+c.getName()+" at "+path);
}
}
use of org.hl7.fhir.r5.model.Extension in project kindling by HL7.
the class CDAGenerator method addCDExtensions.
private void addCDExtensions(List<ElementDefinition> list, String n) {
ElementDefinition ed = new ElementDefinition();
ed.setPath(n + ".valueSet");
seePath(ed);
ed.setMin(0);
ed.setMax("1");
ed.addType().setCode("string");
ed.addRepresentation(PropertyRepresentation.XMLATTR);
ed.setDefinition("The valueSet extension adds an attribute for elements with a CD dataType which indicates the particular value set constraining the coded concept");
ed.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("urn:hl7-org:sdtc"));
ed = new ElementDefinition();
ed.setPath(n + ".valueSetVersion");
seePath(ed);
ed.setMin(0);
ed.setMax("1");
ed.addType().setCode("string");
ed.addRepresentation(PropertyRepresentation.XMLATTR);
ed.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("urn:hl7-org:sdtc"));
ed.setDefinition("The valueSetVersion extension adds an attribute for elements with a CD dataType which indicates the version of the particular value set constraining the coded concept.");
list.add(ed);
}
use of org.hl7.fhir.r5.model.Extension in project kindling by HL7.
the class OldSpreadsheetParser method parseProfileSheet.
private ConstraintStructure parseProfileSheet(Definitions definitions, Profile ap, String n, List<String> namedSheets, boolean published, String usage, List<ValidationMessage> issues, WorkGroup wg, String fmm) throws Exception {
Sheet sheet;
ResourceDefn resource = new ResourceDefn();
sheet = loadSheet(n + "-Inv");
Map<String, Invariant> invariants = null;
if (sheet != null) {
invariants = readInvariants(sheet, n, n + "-Inv");
} else {
invariants = new HashMap<String, Invariant>();
}
sheet = loadSheet(n);
if (sheet == null)
throw new Exception("The StructureDefinition referred to a tab by the name of '" + n + "', but no tab by the name could be found");
for (int row = 0; row < sheet.rows.size(); row++) {
ElementDefn e = processLine(resource, sheet, row, invariants, true, ap, row == 0);
if (e != null)
for (TypeRef t : e.getTypes()) {
if (t.getProfile() != null && !t.getName().equals("Extension") && t.getProfile().startsWith("#")) {
if (!namedSheets.contains(t.getProfile().substring(1)))
namedSheets.add(t.getProfile().substring(1));
}
}
}
sheet = loadSheet(n + "-Extensions");
if (sheet != null) {
int row = 0;
while (row < sheet.rows.size()) {
if (sheet.getColumn(row, "Code").startsWith("!"))
row++;
else
row = processExtension(resource.getRoot().getElementByName(definitions, "extensions", true, false), sheet, row, definitions, ap.metadata("extension.uri"), ap, issues, invariants, wg);
}
}
sheet = loadSheet(n + "-Search");
if (sheet != null) {
readSearchParams(resource, sheet, true);
}
if (invariants != null) {
for (Invariant inv : invariants.values()) {
if (Utilities.noString(inv.getContext()))
throw new Exception("Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " has no context");
else {
ElementDefn ed = findContext(resource.getRoot(), inv.getContext(), "Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " Context");
// TODO: Need to resolve context based on element name, not just path
if (ed.getName().endsWith("[x]") && !inv.getContext().endsWith("[x]"))
inv.setFixedName(inv.getContext().substring(inv.getContext().lastIndexOf(".") + 1));
ed.getInvariants().put(inv.getId(), inv);
if (Utilities.noString(inv.getXpath())) {
throw new Exception("Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " (" + inv.getEnglish() + ") has no XPath statement");
} else if (inv.getXpath().contains("\""))
throw new Exception("Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " (" + inv.getEnglish() + ") contains a \" character");
// if (Utilities.noString(inv.getExpression()))
// throw new Exception("Type "+resource.getRoot().getName()+" Invariant "+inv.getId()+" ("+inv.getEnglish()+") has no Expression statement (in FHIRPath format)");
}
}
}
resource.getRoot().setProfileName(n);
if (n.toLowerCase().equals(ap.getId()))
throw new Exception("Duplicate Profile Name: Package id " + ap.getId() + " and profile id " + n.toLowerCase() + " are the same");
if (profileIds.containsKey(n.toLowerCase()))
throw new Exception("Duplicate Profile Name: " + n.toLowerCase() + " in " + ap.getId() + ", already registered in " + profileIds.get(n.toLowerCase()).getOwner());
ConstraintStructure p = new ConstraintStructure(n.toLowerCase(), resource.getRoot().getProfileName(), resource, ig != null ? ig : definitions.getUsageIG(usage, "Parsing " + name), wg, fmm, Utilities.existsInList(ap.metadata("Experimental"), "y", "Y", "true", "TRUE", "1"));
p.setOwner(ap.getId());
profileIds.put(n.toLowerCase(), p);
return p;
}
use of org.hl7.fhir.r5.model.Extension 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.r5.model.Extension 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);
}
}
}
Aggregations