use of org.hl7.fhir.definitions.model.ResourceDefn 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.ResourceDefn in project kindling by HL7.
the class BookMaker method addContent.
private void addContent(XhtmlNode body) throws Exception {
List<String> list = new ArrayList<String>();
loadResources(list, page.getDefinitions().getResources().keySet());
XhtmlNode e = body.getElement("contents");
XhtmlNode div = body.addTag(body.getChildNodes().indexOf(e), "div");
body.getChildNodes().remove(e);
List<String> links = new ArrayList<String>();
LevelCounter lvl = new LevelCounter();
lvl.l1 = 0;
for (Navigation.Category s : page.getNavigation().getCategories()) {
lvl.l1++;
// div.addTag("div").setAttribute("class", "page-break");
XhtmlNode divS = div.addTag("div");
divS.attribute("class", "section");
XhtmlNode h1 = divS.addTag("h1");
h1.addText(Integer.toString(lvl.l1) + ": " + s.getName());
addPageContent(lvl, divS, s.getLink(), s.getName());
links.add(s.getLink());
lvl.l2 = 0;
for (Navigation.Entry n : s.getEntries()) {
lvl.l2++;
lvl.l3 = 0;
if (n.getLink() != null) {
if (n.getLink().equals("[codes]")) {
lvl.l2--;
List<String> names = new ArrayList<String>();
throw new Error("fix this");
// for (BindingSpecification bs : page.getDefinitions().getBindings().values()) {
// if (bs.getBinding() == Binding.CodeList)
// names.add(bs.getReference());
// }
// Collections.sort(names);
// for (String l : names) {
// addPageContent(lvl, divS, l.substring(1), page.getDefinitions().getBindingByReference(l).getName());
// // links.add(l.substring(1));
// }
} else {
addPageContent(lvl, divS, n.getLink(), n.getName());
links.add(n.getLink());
}
}
for (Navigation.Entry g : n.getEntries()) {
if (g.getLink() != null) {
addPageContent(lvl, divS, g.getLink(), g.getName());
links.add(g.getLink());
}
}
}
if (s.getEntries().size() == 0 && s.getLink().equals("resourcelist")) {
for (String rn : list) {
if (!links.contains(rn.toLowerCase())) {
lvl.l2++;
lvl.l3 = 0;
ResourceDefn r = page.getDefinitions().getResourceByName(rn);
addPageContent(lvl, divS, rn.toLowerCase(), r.getName());
}
}
}
if (s.getLink().equals("page") && s.getName().equals("Examples")) {
for (String rn : list) {
lvl.l2++;
lvl.l3 = 0;
ResourceDefn r = page.getDefinitions().getResourceByName(rn);
addPageContent(lvl, divS, rn.toLowerCase() + "Ex", r.getName());
}
}
if (s.getLink().equals("page") && s.getName().equals("Detailed Descriptions")) {
for (String rn : list) {
lvl.l2++;
lvl.l3 = 0;
ResourceDefn r = page.getDefinitions().getResourceByName(rn);
addPageContent(lvl, divS, rn.toLowerCase() + "Defn", r.getName());
}
}
}
}
use of org.hl7.fhir.definitions.model.ResourceDefn 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.definitions.model.ResourceDefn in project kindling by HL7.
the class OldSpreadsheetParser method readExamples.
private void readExamples(ResourceDefn defn, Sheet sheet) throws Exception {
if (sheet != null) {
for (int row = 0; row < sheet.rows.size(); row++) {
String name = sheet.getColumn(row, "Name");
if (name != null && !name.equals("") && !name.startsWith("!")) {
String id = sheet.getColumn(row, "Identity");
if (id == null || id.equals(""))
throw new Exception("Example " + name + " has no identity parsing " + this.name);
String desc = sheet.getColumn(row, "Description");
if (desc == null || desc.equals(""))
throw new Exception("Example " + name + " has no description parsing " + this.name);
String filename = sheet.getColumn(row, "Filename");
if (filename.startsWith(defn.getName().toLowerCase() + "-examples."))
throw new Exception("Cannot name an example file " + filename);
File file = new CSFile(folder + filename);
String type = sheet.getColumn(row, "Type");
if (!file.exists() && !("tool".equals(type) || isSpecialType(type)))
throw new Exception("Example " + name + " file '" + file.getAbsolutePath() + "' not found parsing " + this.name);
List<Example> list = defn.getExamples();
String pn = sheet.getColumn(row, "Profile");
if (!Utilities.noString(pn) && !pn.startsWith("!")) {
Profile ap = null;
for (Profile r : defn.getConformancePackages()) {
if (r.getTitle().equals(pn))
ap = r;
}
if (ap == null)
throw new Exception("Example " + name + " profile '" + pn + "' not found parsing " + this.name);
else
list = ap.getExamples();
}
ExampleType etype = parseExampleType(type, row);
list.add(new Example(name, id, desc, file, parseBoolean(sheet.getColumn(row, "Registered"), row, true), etype, isAbstract));
}
}
}
if (defn.getExamples().size() == 0) {
File file = new CSFile(folder + title + "-example.xml");
if (!file.exists() && !isAbstract)
throw new Exception("Example (file '" + file.getAbsolutePath() + "') not found parsing " + this.name);
if (file.exists())
defn.getExamples().add(new Example("General", "example", "Example of " + title, file, true, ExampleType.XmlFile, isAbstract));
}
}
use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.
the class OldSpreadsheetParser method resolveElementReferences.
private void resolveElementReferences(ResourceDefn parent, ElementDefn root) throws Exception {
for (TypeRef ref : root.getTypes()) {
if (ref.isElementReference()) {
ElementDefn referredElement = parent.getRoot().getElementByName(definitions, ref.getName().substring(1), true, false, null);
if (referredElement == null)
throw new Exception("Element reference " + ref.getName() + " cannot be found in type " + parent.getName());
if (referredElement.getDeclaredTypeName() == null)
throw new Exception("Element reference " + ref.getName() + " in " + parent.getName() + " refers to an anonymous group of elements. Please specify names with the '=<name>' construct in the typename column.");
ref.setResolvedTypeName(referredElement.getDeclaredTypeName());
}
}
for (ElementDefn element : root.getElements()) {
resolveElementReferences(parent, element);
}
}
Aggregations