use of org.hl7.fhir.r4b.model.DomainResource in project kindling by HL7.
the class OldSpreadsheetParser method parseCommonTypeColumns.
private ResourceDefn parseCommonTypeColumns(boolean isResource, boolean isTemplate) throws Exception {
ResourceDefn resource = new ResourceDefn();
resource.setInterface(isTemplate);
Sheet sheet = loadSheet("Bindings");
if (sheet != null)
readBindings(sheet);
sheet = loadSheet("Invariants");
Map<String, Invariant> invariants = null;
if (sheet != null)
invariants = readInvariants(sheet, title, "Invariants");
sheet = loadSheet("Data Elements");
if (sheet == null)
throw new Exception("No Sheet found for Data Elements");
for (int row = 0; row < sheet.rows.size(); row++) {
processLine(resource, sheet, row, invariants, false, null, row == 0);
}
// default...
StandardsStatus ss = StandardsStatus.TRIAL_USE;
String s = ini.getStringProperty("normative", resource.getName());
if (!Utilities.noString(s))
ss = StandardsStatus.NORMATIVE;
resource.setStatus(ss);
resource.setRequirements(resource.getRoot().getRequirements());
resource.addHints(checkIgnoredColumns(sheet));
if (template != null) {
resource.setTemplate(template.getRoot());
copySearchParameters(resource);
copyInvariants(resource);
template = null;
}
parseMetadata(resource);
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");
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())) {
// This has been disabled for now, per Lloyd McKenzie's request via Skype - jamesagnew
// throw new Exception("Type "+resource.getRoot().getName()+" Invariant "+inv.getId()+" ("+inv.getEnglish()+") has no Expression statement (in FHIRPath format)");
} else {
fpUsages.add(new FHIRPathUsage(inv.getContext(), isResource ? resource.getName() : "DomainResource", inv.getContext(), null, inv.getExpression(), inv.getXpath()));
}
}
}
}
// EK: Future types. But those won't get there.
if (bindings != null)
resource.getRoot().getNestedBindings().putAll(bindings);
scanNestedTypes(resource, resource.getRoot(), resource.getName());
resolveElementReferences(resource, resource.getRoot());
resource.getRoot().setAbstractType(isAbstract);
return resource;
}
use of org.hl7.fhir.r4b.model.DomainResource 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.r4b.model.DomainResource in project kindling by HL7.
the class SpreadSheetReloader method parseStatus.
private void parseStatus(DomainResource ed, String value) {
ed.getExtension().removeIf(ext -> ext.getUrl().equals(BuildExtensions.EXT_FMM_LEVEL));
ed.getExtension().removeIf(ext -> ext.getUrl().equals(BuildExtensions.EXT_STANDARDS_STATUS));
ed.getExtension().removeIf(ext -> ext.getUrl().equals(BuildExtensions.EXT_NORMATIVE_VERSION));
if (!Utilities.noString(value) && value.contains("/")) {
String[] p = value.split("\\/");
if (Utilities.noString(p[0].trim())) {
ed.getExtension().removeIf(ext -> ext.getUrl().equals(BuildExtensions.EXT_FMM_LEVEL));
} else {
ed.addExtension(BuildExtensions.EXT_FMM_LEVEL, new IntegerType(p[0]));
}
if (p[1].contains(";")) {
ed.addExtension(BuildExtensions.EXT_STANDARDS_STATUS, new CodeType(p[1].substring(0, p[1].indexOf(";"))));
ed.addExtension(BuildExtensions.EXT_NORMATIVE_VERSION, new CodeType(p[1].substring(p[1].indexOf("from=") + 5)));
} else {
ed.addExtension(BuildExtensions.EXT_STANDARDS_STATUS, new CodeType(p[1]));
}
}
sortExtensions(ed);
}
use of org.hl7.fhir.r4b.model.DomainResource in project kindling by HL7.
the class TurtleSpecGenerator method generateInner.
private void generateInner(ElementDefn root, boolean resource, boolean isAbstract) throws IOException, Exception {
String rn;
if (root.getName().equals("Extension"))
rn = "extension|modifierExtension";
else if (root.getName().equals("Meta"))
rn = "meta";
else if (root.getTypes().size() > 0 && (root.getTypes().get(0).getName().equals("Type") || (root.getTypes().get(0).getName().equals("Structure"))) || isAbstract)
rn = "[name]";
else
rn = root.getName();
write("@prefix fhir: <http://hl7.org/fhir/> .");
if (resource)
write("<span style=\"float: right\"><a title=\"Documentation for this format\" href=\"" + prefix + "rdf.html\"><img src=\"" + prefix + "help.png\" alt=\"doco\"/></a></span>\r\n");
write("\r\n");
write("\r\n");
if (resource) {
write("[ a fhir:");
if (defPage == null)
write("<span title=\"" + Utilities.escapeXml(root.getDefinition()) + "\"><b>");
else
write("<a href=\"" + (defPage + "#" + root.getName()) + "\" title=\"" + Utilities.escapeXml(root.getDefinition()) + "\" class=\"dict\"><b>");
write(rn);
if ((defPage == null))
write("</b></span>;");
else
write("</b></a>;");
write("\r\n fhir:nodeRole fhir:treeRoot; # if this is the parser root\r\n");
} else
write("[");
write("\r\n");
if (rn.equals(root.getName()) && resource) {
if (!Utilities.noString(root.typeCode())) {
write(" # from <a href=\"" + prefix + "resource.html\">Resource</a>: <a href=\"" + prefix + "resource.html#id\">.id</a>, <a href=\"" + prefix + "resource.html#meta\">.meta</a>, <a href=\"" + prefix + "resource.html#implicitRules\">.implicitRules</a>, and <a href=\"" + prefix + "resource.html#language\">.language</a>\r\n");
if (root.typeCode().equals("DomainResource"))
write(" # from <a href=\"" + prefix + "domainresource.html\">DomainResource</a>: <a href=\"" + prefix + "narrative.html#Narrative\">.text</a>, <a href=\"" + prefix + "references.html#contained\">.contained</a>, <a href=\"" + prefix + "extensibility.html\">.extension</a>, and <a href=\"" + prefix + "extensibility.html#modifierExtension\">.modifierExtension</a>\r\n");
}
} else {
if (root.typeCode().equals("BackboneElement"))
write(" # from BackboneElement: <a href=\"" + prefix + "extensibility.html\">Element.extension</a>, <a href=\"" + prefix + "extensibility.html\">BackboneElement.modifierextension</a>\r\n");
else
write(" # from Element: <a href=\"" + prefix + "extensibility.html\">Element.extension</a>\r\n");
}
for (ElementDefn elem : root.getElements()) {
generateCoreElem(elem, 1, root.getName(), rn.equals(root.getName()) && resource);
}
write("]\r\n");
}
use of org.hl7.fhir.r4b.model.DomainResource 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;
}
Aggregations