use of org.hl7.fhir.definitions.model.BindingSpecification in project kindling by HL7.
the class SvgGenerator method addAttribute.
private void addAttribute(XMLWriter xml, double left, double top, ElementDefn e, String path, LineStatus ls, double height, double width) throws Exception {
if (e.getStandardsStatus() != null) {
xml.attribute("x", Double.toString(left + 1));
xml.attribute("y", Double.toString(top - height + GAP_HEIGHT));
xml.attribute("id", "n" + (++nc));
xml.attribute("width", Double.toString(width - 2));
xml.attribute("height", Double.toString(height));
xml.attribute("style", "fill:" + e.getStandardsStatus().getColorSvg() + ";stroke:black;stroke-width:0");
xml.element("rect", null);
}
xml.attribute("x", Double.toString(left + LEFT_MARGIN + (ls.line == 0 ? 0 : WRAP_INDENT)));
xml.attribute("y", Double.toString(top + LINE_HEIGHT * ls.line));
xml.attribute("fill", "black");
xml.attribute("class", "diagram-class-detail");
xml.attribute("id", "n" + (++nc));
xml.enter("text");
xml.attribute("xlink:href", baseUrl(path) + path + "." + e.getName().replace("[", "_").replace("]", "_"));
xml.attribute("id", "n" + (++nc));
xml.enter("a");
xml.element("title", e.getEnhancedDefinition());
xml.text(ls.see(e.getName()));
xml.exit("a");
xml.text(ls.see(" : "));
encodeType(xml, ls, getTypeCodeForElement(e.getTypes()));
xml.text(ls.see(" [" + e.describeCardinality() + "]"));
// now, the stereotypes
boolean hasTS = !((e.getTypes().isEmpty()) || (e.getTypes().size() == 1 && !isReference(e.getTypes().get(0).getName())));
boolean hasBinding = (e.hasBinding() && e.getBinding().getBinding() != BindingMethod.Unbound);
if (hasTS || hasBinding) {
xml.text(ls.see(" \u00AB "));
if (hasTS) {
if (isReference(e.getTypes().get(0).getName()) && e.getTypes().size() == 1) {
boolean first = true;
for (String p : e.getTypes().get(0).getParams()) {
if (first)
first = false;
else
xml.text(ls.see("|"));
ls.check(xml, left, top, p.length(), null);
encodeType(xml, ls, p);
}
} else {
boolean firstOuter = true;
for (TypeRef t : e.getTypes()) {
if (firstOuter)
firstOuter = false;
else
xml.text(ls.see("|"));
ls.check(xml, left, top, t.getName().length(), null);
encodeType(xml, ls, t.getName());
if (t.getParams().size() > 0) {
xml.text(ls.see("("));
boolean first = true;
for (String p : t.getParams()) {
if (first)
first = false;
else
xml.text(ls.see("|"));
ls.check(xml, left, top, p.length(), null);
encodeType(xml, ls, p);
}
xml.text(ls.see(")"));
}
}
}
}
if (hasTS && hasBinding) {
xml.text(ls.see("; "));
}
if (hasBinding) {
BindingSpecification b = e.getBinding();
String name = e.getBinding().getValueSet() != null ? e.getBinding().getValueSet().getName() : e.getBinding().getName();
if (name.toLowerCase().endsWith(" codes"))
name = name.substring(0, name.length() - 5);
if (name.length() > 30)
name = name.substring(0, 29) + "...";
String link = getBindingLink(prefix, e);
if (b.getStrength() == BindingStrength.EXAMPLE) {
if (link != null) {
xml.attribute("xlink:href", link);
xml.attribute("id", "n" + (++nc));
xml.enter("a");
xml.attribute("id", "n" + (++nc));
}
xml.element("title", b.getDefinition() + " (Strength=Example)");
for (String p : parts(name)) {
ls.check(xml, left, top, p.length(), link);
xml.text(ls.see(p));
}
if (link != null) {
xml.exit("a");
}
xml.text("??");
} else if (b.getStrength() == BindingStrength.PREFERRED) {
xml.attribute("xlink:href", link);
xml.attribute("id", "n" + (++nc));
xml.enter("a");
xml.element("title", b.getDefinition() + " (Strength=Preferred)");
for (String p : parts(name)) {
ls.check(xml, left, top, p.length(), link);
xml.text(ls.see(p));
}
xml.exit("a");
xml.text("?");
} else if (b.getStrength() == BindingStrength.EXTENSIBLE) {
// if (b.hasMax())
// what do in this case...
xml.attribute("xlink:href", link);
xml.attribute("id", "n" + (++nc));
xml.enter("a");
xml.attribute("id", "n" + (++nc));
xml.element("title", b.getDefinition() + " (Strength=Extensible)");
for (String p : parts(name)) {
ls.check(xml, left, top, p.length(), link);
xml.text(ls.see(p));
}
xml.exit("a");
xml.text("+");
} else if (b.getStrength() == BindingStrength.REQUIRED) {
xml.attribute("xlink:href", link);
xml.attribute("id", "n" + (++nc));
xml.enter("a");
xml.attribute("id", "n" + (++nc));
xml.element("title", b.getDefinition() + " (Strength=Required)");
// xml.open("b");
for (String p : parts(name)) {
ls.check(xml, left, top, p.length(), link);
xml.text(ls.see(p));
}
// xml.close("b");
xml.exit("a");
xml.text("!");
} else {
xml.attribute("id", "n" + (++nc));
xml.attribute("xlink:href", link);
xml.enter("a");
xml.attribute("id", "n" + (++nc));
xml.element("title", b.getDefinition() + " (??)");
for (String p : parts(name)) {
ls.check(xml, left, top, p.length(), link);
xml.text(ls.see(p));
}
xml.exit("a");
}
}
xml.text(ls.see(" \u00BB"));
}
xml.exit("text");
}
use of org.hl7.fhir.definitions.model.BindingSpecification in project kindling by HL7.
the class PageProcessor method generateCode.
private void generateCode(BindingSpecification cd, StringBuilder s, boolean hasSource, boolean hasId, boolean hasComment, boolean hasDefinition, boolean hasParent, int level, DefinedCode c) {
String id = hasId ? "<td>" + fixNull(c.getId()) + "</td>" : "";
String src = "";
if (hasSource) {
if (Utilities.noString(c.getSystem())) {
src = "<td></td>";
} else {
String url = c.getSystem();
url = fixUrlReference(url);
src = "<td><a href=\"" + url + "\">" + codeSystemDescription(c.getSystem()) + "</a></td>";
}
}
String lvl = hasParent ? "<td>" + Integer.toString(level) + "</td>" : "";
String indent = "";
for (int i = 1; i < level; i++) indent = indent + " ";
if (hasComment)
s.append(" <tr>" + id + src + lvl + "<td>" + indent + Utilities.escapeXml(c.getCode()) + "</td><td>" + Utilities.escapeXml(c.getDefinition()) + "</td><td>" + Utilities.escapeXml(c.getComment()) + "</td></tr>\r\n");
else if (hasDefinition)
s.append(" <tr>" + id + src + lvl + "<td>" + indent + Utilities.escapeXml(c.getCode()) + "</td><td colspan=\"2\">" + Utilities.escapeXml(c.getDefinition()) + "</td></tr>\r\n");
else
s.append(" <tr>" + id + src + lvl + "<td colspan=\"3\">" + indent + Utilities.escapeXml(c.getCode()) + "</td></tr>\r\n");
for (DefinedCode ch : c.getChildCodes()) {
generateCode(cd, s, hasSource, hasId, hasComment, hasDefinition, hasParent, level + 1, ch);
}
}
use of org.hl7.fhir.definitions.model.BindingSpecification in project kindling by HL7.
the class IgParser method load.
public void load(String rootDir, ImplementationGuideDefn igd, List<ValidationMessage> issues, Set<String> loadedIgs) throws Exception {
logger.log(" ..." + igd.getName(), LogMessageType.Process);
// first: parse the IG, then use it
String myRoot = Utilities.path(rootDir, "guides", igd.getCode());
CSFile file = new CSFile(Utilities.path(rootDir, igd.getSource()));
ImplementationGuide ig = (ImplementationGuide) new XmlParser().parse(new FileInputStream(file));
if (// for things published in the hl7.org/fhir namespace...
!ig.getUrl().startsWith("http://hl7.org/fhir/"))
throw new Exception("Illegal namespace");
if (!ig.getUrl().equals("http://hl7.org/fhir/" + ig.getId()))
throw new Exception("Illegal URL");
if (!ig.hasName())
throw new Exception("no name on IG");
ig.setDateElement(new DateTimeType(genDate));
igd.setName(ig.getName());
igd.setIg(ig);
Map<String, Resource> resources = new HashMap<String, Resource>();
for (ImplementationGuideDependsOnComponent d : ig.getDependsOn()) {
if (!loadedIgs.contains(d.getUri()))
throw new Exception("Dependency on " + ig.getName() + " not satisfied: " + d.getUri());
}
loadedIgs.add(ig.getUrl());
// for (UriType bin : ig.getBinary()) {
// if (!new File(Utilities.path(myRoot, bin.getValue())).exists())
// throw new Exception("Binary dependency in "+ig.getName()+" not found: "+bin.getValue());
// igd.getImageList().add(bin.getValue());
// }
processPage(ig.getDefinition().getPage(), igd);
List<Example> exr = new ArrayList<Example>();
// first pass - verify the resources can be loaded
for (ImplementationGuideDefinitionResourceComponent r : ig.getDefinition().getResource()) {
if (!r.hasReference())
throw new Exception("no source on resource in IG " + ig.getName());
CSFile fn = new CSFile(Utilities.path(myRoot, r.getReference().getReference()));
if (!fn.exists())
throw new Exception("Source " + r.getReference().getReference() + " resource in IG " + ig.getName() + " could not be located @ " + fn.getAbsolutePath());
String id = Utilities.changeFileExt(fn.getName(), "");
// we're going to try and load the resource directly.
// if that fails, then we'll treat it as an example.
boolean isExample = r.hasExample();
ResourceType rt = null;
try {
rt = new XmlParser().parse(new FileInputStream(fn)).getResourceType();
} catch (Exception e) {
rt = null;
isExample = true;
}
if (isExample) {
if (// which means that non conformance resources must be named
!r.hasName())
throw new Exception("no name on resource in IG " + ig.getName());
Example example = new Example(r.getName(), id, r.getDescription(), fn, false, ExampleType.XmlFile, false);
example.setIg(igd.getCode());
if (r.hasExampleCanonicalType()) {
example.setExampleFor(r.getExampleCanonicalType().asStringValue());
example.setRegistered(true);
exr.add(example);
}
igd.getExamples().add(example);
r.setUserData(ToolResourceUtilities.NAME_RES_EXAMPLE, example);
r.setReference(new Reference(example.getId() + ".html"));
} else if (rt == ResourceType.ValueSet) {
ValueSet vs = (ValueSet) new XmlParser().parse(new FileInputStream(fn));
if (id.startsWith("valueset-"))
id = id.substring(9);
vs.setId(id);
if (vs.getUrl() == null) {
// Asserting this all the time causes issues for non-HL7 URL value sets
vs.setUrl("http://hl7.org/fhir/ValueSet/" + id);
}
vs.setUserData(ToolResourceUtilities.NAME_RES_IG, igd);
vs.setUserData("path", igd.getPath() + "valueset-" + id + ".html");
vs.setUserData("filename", "valueset-" + id);
if (committee != null) {
if (!vs.hasExtension(ToolingExtensions.EXT_WORKGROUP)) {
vs.addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType(committee.getCode()));
} else {
String ec = ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_WORKGROUP);
if (!ec.equals(committee.getCode()))
System.out.println("ValueSet " + vs.getUrl() + " WG mismatch 2: is " + ec + ", want to set to " + committee);
}
}
new CodeSystemConvertor(codeSystems).convert(new XmlParser(), vs, fn.getAbsolutePath(), packageInfo);
// if (id.contains(File.separator))
igd.getValueSets().add(vs);
if (!r.hasName())
r.setName(vs.getName());
if (!r.hasDescription())
r.setDescription(vs.getDescription());
r.setUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE, vs);
r.setReference(new Reference(fn.getName()));
} else if (rt == ResourceType.StructureDefinition) {
StructureDefinition sd;
sd = (StructureDefinition) new XmlParser().parse(new CSFileInputStream(fn));
new ProfileUtilities(context, null, pkp).setIds(sd, false);
if (sd.getKind() == StructureDefinitionKind.LOGICAL) {
fn = new CSFile(Utilities.path(myRoot, r.getReference().getReference()));
LogicalModel lm = new LogicalModel(sd);
lm.setSource(fn.getAbsolutePath());
lm.setId(sd.getId());
igd.getLogicalModels().add(lm);
} else if ("Extension".equals(sd.getType())) {
sd.setId(tail(sd.getUrl()));
sd.setUserData(ToolResourceUtilities.NAME_RES_IG, igd.getCode());
ToolResourceUtilities.updateUsage(sd, igd.getCode());
this.context.cacheResource(sd);
} else {
Profile pr = new Profile(igd.getCode());
pr.setSource(fn.getAbsolutePath());
pr.setTitle(sd.getName());
if (!sd.hasId())
sd.setId(tail(sd.getUrl()));
// Lloyd: This causes issues for profiles & extensions defined outside of HL7
// sd.setUrl("http://hl7.org/fhir/StructureDefinition/"+sd.getId());
pr.forceMetadata("id", sd.getId() + "-profile");
pr.setSourceType(ConformancePackageSourceType.StructureDefinition);
ConstraintStructure cs = new ConstraintStructure(sd, igd, wg(sd), fmm(sd), sd.getExperimental());
pr.getProfiles().add(cs);
igd.getProfiles().add(pr);
}
} else if (rt == ResourceType.Bundle) {
Dictionary d = new Dictionary(id, r.getName(), igd.getCode(), fn.getAbsolutePath(), igd);
igd.getDictionaries().add(d);
} else
logger.log("Implementation Guides do not yet support " + rt.toString(), LogMessageType.Process);
// throw new Error("Not implemented yet - type = "+rt.toString());
// if (r.hasExampleFor()) {
// if (!resources.containsKey(r.getExampleFor().getReference()))
// throw new Exception("Unable to resolve example-for reference to "+r.getExampleFor().getReference());
// }
}
// second pass: load the spreadsheets
for (ImplementationGuideDefinitionGroupingComponent p : ig.getDefinition().getGrouping()) {
if (!p.hasName())
throw new Exception("no name on package in IG " + ig.getName());
for (Extension ex : p.getExtension()) {
if (ex.getUrl().equals(ToolResourceUtilities.EXT_PROFILE_SPREADSHEET)) {
String s = ((UriType) ex.getValue()).getValue();
File fn = new File(Utilities.path(myRoot, s));
if (!fn.exists())
throw new Exception("Spreadsheet " + s + " in package " + p.getName() + " in IG " + ig.getName() + " could not be located");
Profile pr = new Profile(igd.getCode());
ex.setUserData(ToolResourceUtilities.NAME_RES_PROFILE, pr);
pr.setSource(fn.getAbsolutePath());
pr.setSourceType(ConformancePackageSourceType.Spreadsheet);
OldSpreadsheetParser sparser = new OldSpreadsheetParser(pr.getCategory(), new CSFileInputStream(pr.getSource()), Utilities.noString(pr.getId()) ? pr.getSource() : pr.getId(), pr.getSource(), igd, rootDir, logger, registry, FHIRVersion.fromCode(context.getVersion()), context, genDate, false, pkp, false, committee, mappings, profileIds, codeSystems, maps, workgroups, exceptionIfExcelNotNormalised);
sparser.getBindings().putAll(commonBindings);
sparser.setFolder(Utilities.getDirectoryForFile(pr.getSource()));
sparser.parseConformancePackage(pr, null, Utilities.getDirectoryForFile(pr.getSource()), pr.getCategory(), issues, null);
// System.out.println("load "+pr.getId()+" from "+s);
igd.getProfiles().add(pr);
// what remains to be done now is to update the package with the loaded resources, but we need to wait for all the profiles to generated, so we'll do that later
for (BindingSpecification bs : sparser.getBindings().values()) {
if (!commonBindings.containsValue(bs) && bs.getValueSet() != null) {
ValueSet vs = bs.getValueSet();
String path = vs.getUserString("path");
path = path.substring(path.lastIndexOf("/") + 1);
ig.getDefinition().addResource().setName(vs.getName()).setDescription(vs.getDescription()).setReference(new Reference(path)).setUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE, vs);
}
}
// now, register resources for all the things in the spreadsheet
for (ValueSet vs : sparser.getValuesets()) ig.getDefinition().addResource().setExample(new BooleanType(false)).setName(vs.getName()).setDescription(vs.getDescription()).setReference(new Reference("valueset-" + vs.getId() + ".html")).setUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE, vs);
for (StructureDefinition exd : pr.getExtensions()) ig.getDefinition().addResource().setExample(new BooleanType(false)).setName(exd.getName()).setDescription(exd.getDescription()).setReference(new Reference("extension-" + exd.getId().toLowerCase() + ".html")).setUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE, exd);
for (ConstraintStructure cs : pr.getProfiles()) {
cs.setResourceInfo(ig.getDefinition().addResource());
cs.getResourceInfo().setExample(new BooleanType(false)).setName(cs.getDefn().getName()).setDescription(cs.getDefn().getDefinition()).setReference(new Reference(cs.getId().toLowerCase() + ".html"));
}
}
if (ex.getUrl().equals(ToolResourceUtilities.EXT_LOGICAL_SPREADSHEET)) {
File fn = new CSFile(Utilities.path(myRoot, ((UriType) ex.getValue()).getValue()));
// String source = Utilities.path(file.getParent(), e.getAttribute("source"));
String s = fn.getName();
if (s.endsWith("-spreadsheet.xml"))
s = s.substring(0, s.length() - 16);
String id = igd.getCode() + "-" + s;
OldSpreadsheetParser sparser = new OldSpreadsheetParser(igd.getCode(), new CSFileInputStream(fn), id, fn.getAbsolutePath(), igd, rootDir, logger, registry, FHIRVersion.fromCode(context.getVersion()), context, genDate, false, pkp, false, committee, mappings, profileIds, codeSystems, maps, workgroups, exceptionIfExcelNotNormalised);
sparser.getBindings().putAll(commonBindings);
sparser.setFolder(Utilities.getDirectoryForFile(fn.getAbsolutePath()));
LogicalModel lm = sparser.parseLogicalModel();
lm.setId(id);
lm.setSource(fn.getAbsolutePath());
lm.getResource().setName(lm.getId());
igd.getLogicalModels().add(lm);
}
}
ToolingExtensions.removeExtension(p, ToolResourceUtilities.EXT_PROFILE_SPREADSHEET);
ToolingExtensions.removeExtension(p, ToolResourceUtilities.EXT_LOGICAL_SPREADSHEET);
}
for (Example ex : exr) {
Profile tp = null;
for (Profile pr : igd.getProfiles()) {
if (("StructureDefinition/" + pr.getId()).equals(ex.getExampleFor())) {
tp = pr;
break;
} else
for (ConstraintStructure cc : pr.getProfiles()) {
if (("StructureDefinition/" + cc.getId()).equals(ex.getExampleFor())) {
tp = pr;
break;
}
}
}
if (tp != null)
tp.getExamples().add(ex);
else
throw new Exception("no profile found matching exampleFor = " + ex.getExampleFor());
}
igd.numberPages();
// // second, parse the old ig, and use that. This is being phased out
// CSFile file = new CSFile(Utilities.path(rootDir, igd.getSource()));
// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// factory.setNamespaceAware(true);
// DocumentBuilder builder = factory.newDocumentBuilder();
// Document xdoc = builder.parse(new CSFileInputStream(file));
// Element root = xdoc.getDocumentElement();
// if (!root.getNodeName().equals("ig"))
// throw new Exception("wrong base node");
// Element e = XMLUtil.getFirstChild(root);
// while (e != null) {
// if (e.getNodeName().equals("dependsOn")) {
// // we ignore this for now
// } else if (e.getNodeName().equals("publishing")) {
// // if (e.hasAttribute("homepage"))
// // igd.setPage(e.getAttribute("homepage"));
// } else if (e.getNodeName().equals("page")) {
// // igd.getPageList().add(e.getAttribute("source"));
// } else if (e.getNodeName().equals("image")) {
// // moved above igd.getImageList().add(e.getAttribute("source"));
// } else if (e.getNodeName().equals("valueset")) {
// // XmlParser xml = new XmlParser();
// // ValueSet vs = (ValueSet) xml.parse(new CSFileInputStream(Utilities.path(file.getParent(), e.getAttribute("source"))));
// // String id = Utilities.changeFileExt(new File(Utilities.path(file.getParent(), e.getAttribute("source"))).getName(), "");
// // if (id.startsWith("valueset-"))
// // id = id.substring(9);
// // if (!vs.hasId() || !vs.hasUrl()) {
// // vs.setId(id);
// // vs.setUrl("http://hl7.org/fhir/ValueSet/"+vs.getId());
// // }
// // vs.setUserData(ToolResourceUtilities.NAME_RES_IG, igd);
// // vs.setUserData("path", igd.getCode()+File.separator+"valueset-"+vs.getId()+".html");
// // vs.setUserData("filename", "valueset-"+vs.getId());
// // vs.setUserData("committee", committee);
// // igd.getValueSets().add(vs);
// } else if (e.getNodeName().equals("acronym")) {
// igd.getTlas().put(e.getAttribute("target"), e.getAttribute("id"));
// } else if (e.getNodeName().equals("example")) {
// // String filename = e.getAttribute("source");
// // File efile = new File(Utilities.path(file.getParent(), filename));
// // Example example = new Example(e.getAttribute("name"), Utilities.changeFileExt(efile.getName(), ""), e.getAttribute("name"), efile, false, ExampleType.XmlFile, false);
// // example.setIg(igd.getCode());
// // igd.getExamples().add(example);
// } else if (e.getNodeName().equals("profile")) {
// // moved above
// // Profile p = new Profile(igd.getCode());
// // p.setSource(Utilities.path(file.getParent(), e.getAttribute("source")));
// // if ("spreadsheet".equals(e.getAttribute("type"))) {
// // p.setSourceType(ConformancePackageSourceType.Spreadsheet);
// // SpreadsheetParser sparser = new SpreadsheetParser(p.getCategory(), new CSFileInputStream(p.getSource()), Utilities.noString(p.getId()) ? p.getSource() : p.getId(), igd,
// // rootDir, logger, null, context.getVersion(), context, genDate, false, igd.getExtensions(), pkp, false, committee, mappings);
// // sparser.getBindings().putAll(commonBindings);
// // sparser.setFolder(Utilities.getDirectoryForFile(p.getSource()));
// // sparser.parseConformancePackage(p, null, Utilities.getDirectoryForFile(p.getSource()), p.getCategory(), issues);
// // for (BindingSpecification bs : sparser.getBindings().values()) {
// // if (!commonBindings.containsValue(bs) && bs.getValueSet() != null) {
// // ValueSet vs = bs.getValueSet();
// // String path = vs.getUserString("filename")+".xml";
// // ig.getPackage().get(0).addResource().setName(vs.getName()).setDescription(vs.getDescription()).setSource(new UriType(path)).setUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE, vs);
// // }
// // }
// // } else {
// // throw new Exception("Unknown profile type in IG : "+e.getNodeName());
// // // parseConformanceDocument(p, p.getId(), new File(p.getSource()), p.getCategory());
// // }
// //
// // String id = e.getAttribute("id");
// // if (Utilities.noString(id))
// // id = Utilities.changeFileExt(e.getAttribute("source"), "");
// // igd.getProfiles().add(p);
// // Element ex = XMLUtil.getFirstChild(e);
// // while (ex != null) {
// // if (ex.getNodeName().equals("example")) {
// // String filename = ex.getAttribute("source");
// // Example example = new Example(ex.getAttribute("name"), Utilities.changeFileExt(Utilities.getFileNameForName(filename), ""), ex.getAttribute("name"), new File(Utilities.path(file.getParent(), filename)), false, ExampleType.XmlFile, false);
// // p.getExamples().add(example);
// // } else
// // throw new Exception("Unknown element name in IG: "+ex.getNodeName());
// // ex = XMLUtil.getNextSibling(ex);
// // }
// } else if (e.getNodeName().equals("dictionary")) {
// // Dictionary d = new Dictionary(e.getAttribute("id"), e.getAttribute("name"), igd.getCode(), Utilities.path(Utilities.path(file.getParent(), e.getAttribute("source"))), igd);
// // igd.getDictionaries().add(d);
// } else if (e.getNodeName().equals("logicalModel")) {
// // String source = Utilities.path(file.getParent(), e.getAttribute("source"));
// // String id = igd.getCode()+"-"+e.getAttribute("id");
// // SpreadsheetParser sparser = new SpreadsheetParser(igd.getCode(), new CSFileInputStream(source), id, igd, rootDir, logger, null, context.getVersion(), context, genDate, false, igd.getExtensions(), pkp, false, committee, mappings);
// // sparser.getBindings().putAll(commonBindings);
// // sparser.setFolder(Utilities.getDirectoryForFile(source));
// // LogicalModel lm = sparser.parseLogicalModel(source);
// // lm.setId(id);
// // lm.setSource(source);
// // lm.getResource().setName(lm.getId());
// // igd.getLogicalModels().add(lm);
// } else
// throw new Exception("Unknown element name in IG: "+e.getNodeName());
// e = XMLUtil.getNextSibling(e);
// }
}
use of org.hl7.fhir.definitions.model.BindingSpecification in project kindling by HL7.
the class OldSpreadsheetParser method processLine.
private ElementDefn processLine(ResourceDefn root, Sheet sheet, int row, Map<String, Invariant> invariants, boolean profile, Profile pack, boolean firstTime) throws Exception {
ElementDefn e;
String path = sheet.getColumn(row, "Element");
if (path.startsWith("!"))
return null;
if (Utilities.noString(path))
throw new Exception("Error reading definitions - no path found @ " + getLocation(row));
if (path.contains("#"))
throw new Exception("Old path style @ " + getLocation(row));
String profileName = isProfile ? sheet.getColumn(row, "Profile Name") : "";
String discriminator = isProfile ? sheet.getColumn(row, "Discriminator") : "";
boolean isRoot = !path.contains(".");
if (isRoot) {
if (root.getRoot() != null)
throw new Exception("Definitions in " + getLocation(row) + " contain two roots: " + path + " in " + root.getName());
root.setName(path);
e = new TypeDefn();
e.setName(path);
root.setRoot((TypeDefn) e);
if (template != null)
e.copyFrom(template.getRoot(), root.getName(), templateTitle);
} else {
e = makeFromPath(root.getRoot(), path, row, profileName, true);
if (template != null) {
ElementDefn ted = getTemplateDefinition(path);
if (ted != null) {
e.copyFrom(ted, root.getName(), templateTitle);
}
}
}
e.setStandardsStatus(StandardsStatus.fromCode(sheet.getColumn(row, "Standards-Status")));
e.setNormativeVersion(sheet.getColumn(row, "Normative-Version"));
if (e.getName().startsWith("@")) {
e.setName(e.getName().substring(1));
e.setXmlAttribute(true);
}
String c = sheet.getColumn(row, "Card.");
if (c == null || c.equals("") || c.startsWith("!")) {
if (!isRoot && !profile && (template == null))
throw new Exception("Missing cardinality at " + getLocation(row) + " on " + path);
if (isRoot && (template == null)) {
e.setMinCardinality(0);
e.setMaxCardinality(Integer.MAX_VALUE);
}
} else {
String[] card = c.split("\\.\\.");
if (card.length != 2 || !Utilities.isInteger(card[0]) || (!"*".equals(card[1]) && !Utilities.isInteger(card[1])))
throw new Exception("Unable to parse Cardinality '" + c + "' " + c + " in " + getLocation(row) + " on " + path);
e.setMinCardinality(Integer.parseInt(card[0]));
e.setMaxCardinality("*".equals(card[1]) ? Integer.MAX_VALUE : Integer.parseInt(card[1]));
}
if (profileName.startsWith("#"))
throw new Exception("blah: " + profileName);
e.setProfileName(profileName);
e.setSliceDescription(isProfile ? sheet.getColumn(row, "Slice Description") : "");
for (String d : discriminator.split("\\,")) if (!Utilities.noString(d))
e.getDiscriminator().add(d);
doAliases(sheet, row, e);
if (sheet.hasColumn(row, "Must Understand"))
throw new Exception("Column 'Must Understand' has been renamed to 'Is Modifier'");
if (sheet.hasColumn(row, "Is Modifier")) {
e.setIsModifier(parseBoolean(sheet.getColumn(row, "Is Modifier"), row, null));
String reason = sheet.getColumn(row, "Modifier Reason");
if (Utilities.noString(reason) && e.getName().toLowerCase().contains("status") && sheet.getColumn(row, "Short Name").contains("error"))
reason = "This element is labelled as a modifier because it is a status element that contains status entered-in-error which means that the resource should not be treated as valid";
if (Utilities.noString(reason) && e.getName().equals("active"))
reason = "This element is labelled as a modifier because it is a status element that can indicate that a record should not be treated as valid";
if (Utilities.noString(reason)) {
System.out.println("Missing IsModifierReason on " + path);
reason = "Not known why this is labelled a modifier";
}
e.setModifierReason(reason);
}
if (isProfile) {
// later, this will get hooked in from the underlying definitions, but we need to know this now to validate the extension modifier matching
if (e.getName().equals("modifierExtension"))
e.setIsModifier(true);
e.setMustSupport(parseBoolean(sheet.getColumn(row, "Must Support"), row, null));
}
if (sheet.hasColumn(row, "Summary"))
e.setSummaryItem(parseBoolean(sheet.getColumn(row, "Summary"), row, null));
e.setRegex(sheet.getColumn(row, "Regex"));
String uml = sheet.getColumn(row, "UML");
if (uml != null) {
if (uml.contains(";")) {
String[] parts = uml.split("\\;");
e.setSvgLeft(Integer.parseInt(parts[0]));
e.setSvgTop(Integer.parseInt(parts[1]));
if (parts.length > 2)
e.setSvgWidth(Integer.parseInt(parts[2]));
e.setUmlDir("");
} else if (uml.startsWith("break:")) {
e.setUmlBreak(true);
e.setUmlDir(uml.substring(6));
} else {
e.setUmlDir(uml);
}
}
String s = sheet.getColumn(row, "Condition");
if (s != null && !s.equals(""))
throw new Exception("Found Condition in spreadsheet " + getLocation(row));
s = sheet.getColumn(row, "Inv.");
if (s != null && !s.equals("")) {
for (String sn : s.split(",")) {
if (!sn.startsWith("!")) {
Invariant inv = invariants.get(sn);
if (inv == null)
throw new Exception("unable to find Invariant '" + sn + "' " + getLocation(row));
e.getStatedInvariants().add(inv);
}
}
}
TypeParser tp = new TypeParser(version.toCode());
e.getTypes().addAll(tp.parse(sheet.getColumn(row, "Type"), isProfile, profileExtensionBase, context, !path.contains("."), this.name));
if (isRoot && e.getTypes().size() == 1 && definitions != null) {
String t = e.getTypes().get(0).getName();
if (definitions.getResourceTemplates().containsKey(t)) {
// we've got a template in play.
template = definitions.getResourceTemplates().get(t);
templateTitle = Utilities.unCamelCase(e.getName());
e.getTypes().get(0).setName(template.getRoot().getTypes().get(0).getName());
} else if (definitions.getBaseResources().containsKey(t) && definitions.getBaseResources().get(t).isInterface()) {
// we've got a template in play.
template = definitions.getBaseResources().get(t);
templateTitle = Utilities.unCamelCase(e.getName());
}
}
if (isProfile && ((path.endsWith(".extension") || path.endsWith(".modifierExtension")) && (e.getTypes().size() == 1) && e.getTypes().get(0).hasProfile()) && Utilities.noString(profileName))
throw new Exception("need to have a profile name if a profiled extension is referenced for " + e.getTypes().get(0).getProfile());
if (sheet.hasColumn(row, "Concept Domain"))
throw new Exception("Column 'Concept Domain' has been retired in " + path);
String bindingName = sheet.getColumn(row, "Binding");
if (!Utilities.noString(bindingName)) {
BindingSpecification binding = bindings.get(bindingName);
if (binding == null && definitions != null)
binding = definitions.getCommonBindings().get(bindingName);
if (binding == null) {
if (bindingName.startsWith("!"))
e.setNoBindingAllowed(true);
else
throw new Exception("Binding name " + bindingName + " could not be resolved in local spreadsheet");
}
e.setBinding(binding);
if (binding != null && !binding.getUseContexts().contains(name))
binding.getUseContexts().add(name);
} else if (e.getBinding() != null) {
if (!e.getBinding().getUseContexts().contains(name))
e.getBinding().getUseContexts().add(name);
}
if (!Utilities.noString(sheet.getColumn(row, "Short Label")))
throw new Exception("Short Label is no longer used");
if (// todo: make this a warning when a fair chunk of the spreadsheets have been converted
sheet.hasColumn(row, "Short Name"))
if (sheet.getColumn(row, "Short Name").startsWith("&"))
e.setShortDefn(e.getShortDefn() + sheet.getColumn(row, "Short Name").substring(1));
else
e.setShortDefn(sheet.getColumn(row, "Short Name"));
if (!isProfile && e.getShortDefn() == null)
throw new Exception("A short definition is required for " + e.getName() + " at " + getLocation(row));
if (sheet.hasColumn(row, "Definition"))
if (sheet.getColumn(row, "Definition").startsWith("&"))
e.setDefinition(Utilities.appendPeriod(e.getDefinition() + processDefinition(sheet.getColumn(row, "Definition")).substring(1)));
else
e.setDefinition(Utilities.appendPeriod(processDefinition(sheet.getColumn(row, "Definition"))));
if (isRoot) {
root.setDefinition(e.getDefinition());
}
if (isProfile || isLogicalModel)
e.setMaxLength(sheet.getColumn(row, "Max Length"));
if (sheet.hasColumn(row, "Requirements"))
if (sheet.getColumn(row, "Requirements").startsWith("&"))
e.setRequirements(Utilities.appendPeriod(e.getRequirements() + sheet.getColumn(row, "Requirements").substring(1)));
else
e.setRequirements(Utilities.appendPeriod(sheet.getColumn(row, "Requirements")));
if (sheet.hasColumn(row, "Comments"))
if (sheet.getColumn(row, "Comments").startsWith("&"))
e.setComments(Utilities.appendPeriod(e.getComments() + Utilities.appendPeriod(sheet.getColumn(row, "Comments").substring(1))));
else
e.setComments(Utilities.appendPeriod(Utilities.appendPeriod(sheet.getColumn(row, "Comments"))));
for (String n : mappings.keySet()) {
String ms = sheet.getColumn(row, mappings.get(n).getColumnName());
if (mappings.get(n).getColumnName().equals("Snomed Code") && !Utilities.noString(ms))
System.out.println("!!");
e.addMapping(n, ms.trim());
}
if (pack != null) {
for (String n : pack.getMappingSpaces().keySet()) {
e.addMapping(n, sheet.getColumn(row, pack.getMappingSpaces().get(n).getColumnName()).trim());
}
}
if (sheet.hasColumn("Hierarchy"))
e.setHierarchy(parseBoolean(sheet.getColumn(row, "Hierarchy"), row, null));
if (sheet.hasColumn(row, "To Do"))
e.setTodo(Utilities.appendPeriod(sheet.getColumn(row, "To Do")));
if (sheet.hasColumn(row, "Example"))
e.setExample(processValue(sheet, row, "Example", sheet.getColumn(row, "Example"), e));
processOtherExamples(e, sheet, row);
if (sheet.hasColumn(row, "Committee Notes"))
e.setCommitteeNotes(Utilities.appendPeriod(sheet.getColumn(row, "Committee Notes")));
if (sheet.hasColumn(row, "Display Hint"))
e.setDisplayHint(sheet.getColumn(row, "Display Hint"));
if (isProfile) {
e.setFixed(processValue(sheet, row, "Value", sheet.getColumn(row, "Value"), e));
e.setPattern(processValue(sheet, row, "Pattern", sheet.getColumn(row, "Pattern"), e));
} else {
if (sheet.hasColumn(row, "Default Value"))
errors.add(path + ": Default value '" + sheet.getColumn(row, "Default Value") + "' found @ " + getLocation(row));
if (sheet.hasColumn(row, "Missing Meaning"))
e.setMeaningWhenMissing(sheet.getColumn(row, "Missing Meaning"));
}
if (sheet.hasColumn(row, "w5"))
e.setW5(checkW5(sheet.getColumn(row, "w5"), path));
if (sheet.hasColumn(row, "Translatable"))
e.setTranslatable(parseBoolean(sheet.getColumn(row, "Translatable"), row, false));
if (sheet.hasColumn(row, "Order Meaning"))
e.setOrderMeaning(sheet.getColumn(row, "Order Meaning"));
return e;
}
use of org.hl7.fhir.definitions.model.BindingSpecification in project kindling by HL7.
the class OldSpreadsheetParser method parseExtensionElement.
private void parseExtensionElement(Sheet sheet, int row, Definitions definitions, ElementDefn exe, boolean nested) throws Exception {
// things that go on Extension
String[] card = sheet.getColumn(row, "Card.").split("\\.\\.");
if (card.length != 2 || !Utilities.isInteger(card[0]) || (!"*".equals(card[1]) && !Utilities.isInteger(card[1])))
throw new Exception("Unable to parse Cardinality " + sheet.getColumn(row, "Card.") + " in " + getLocation(row));
exe.setMinCardinality(Integer.parseInt(card[0]));
exe.setMaxCardinality("*".equals(card[1]) ? Integer.MAX_VALUE : Integer.parseInt(card[1]));
exe.setDefinition(Utilities.appendPeriod(processDefinition(sheet.getColumn(row, "Definition"))));
exe.setRequirements(Utilities.appendPeriod(sheet.getColumn(row, "Requirements")));
exe.setComments(Utilities.appendPeriod(sheet.getColumn(row, "Comments")));
doAliases(sheet, row, exe);
for (String n : mappings.keySet()) {
exe.addMapping(n, sheet.getColumn(row, mappings.get(n).getColumnName()).trim());
}
exe.setTodo(Utilities.appendPeriod(sheet.getColumn(row, "To Do")));
exe.setCommitteeNotes(Utilities.appendPeriod(sheet.getColumn(row, "Committee Notes")));
exe.setShortDefn(sheet.getColumn(row, "Short Name"));
exe.setIsModifier(parseBoolean(sheet.getColumn(row, "Is Modifier"), row, null));
if (exe.isModifier()) {
String reason = sheet.getColumn(row, "Modifier Reason");
if (Utilities.noString(reason)) {
System.out.println("Missing IsModifierReason on extension @ " + getLocation(row));
reason = "Not known why this is labelled a modifier";
}
exe.setModifierReason(reason);
}
if (nested && exe.isModifier())
throw new Exception("Cannot create a nested extension that is a modifier @" + getLocation(row));
exe.getTypes().add(new TypeRef().setName("Extension"));
// things that go on Extension.value
if (!Utilities.noString(sheet.getColumn(row, "Type"))) {
ElementDefn exv = new ElementDefn();
exv.setName("value[x]");
exv.getTypes().addAll(new TypeParser(version.toCode()).parse(sheet.getColumn(row, "Type"), true, profileExtensionBase, context, false, sheet.title));
/* if (!exv.getName().equals("value[x]")) {
ElementDefn exd = new ElementDefn();
exd.setName("value[x]");
exd.setMaxCardinality(1);
exd.getTypes().add(new TypeRef(exv.getTypes().get(0).getName()));
List<String> discriminator = new ArrayList<String>();
discriminator.add("@type");
exd.setDiscriminator(discriminator);
exe.getElements().add(exd);
exv.setProfileName("value");
}*/
exe.getElements().add(exv);
String bindingName = sheet.getColumn(row, "Binding");
if (!Utilities.noString(bindingName)) {
BindingSpecification binding = bindings.get(bindingName);
if (binding == null && definitions != null)
binding = definitions.getCommonBindings().get(bindingName);
if (binding == null) {
if (bindingName.startsWith("!"))
exv.setNoBindingAllowed(true);
else
throw new Exception("Binding name " + bindingName + " could not be resolved in local spreadsheet");
}
exv.setBinding(binding);
if (binding != null && !binding.getUseContexts().contains(name))
binding.getUseContexts().add(name);
}
// exv.setBinding();
exv.setMaxLength(sheet.getColumn(row, "Max Length"));
exv.setExample(processValue(sheet, row, "Example", sheet.getColumn(row, "Example"), exv));
}
}
Aggregations