use of org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet in project kindling by HL7.
the class OldSpreadsheetParser method readBindings.
// Adds bindings to global definition.bindings. Returns list of
// newly found bindings in the sheet.
private void readBindings(Sheet sheet) throws Exception {
for (int row = 0; row < sheet.rows.size(); row++) {
String bindingName = sheet.getColumn(row, "Binding Name");
}
ValueSetGenerator vsGen = new ValueSetGenerator(definitions, version.toCode(), genDate, context.translator(), packageInfo);
for (int row = 0; row < sheet.rows.size(); row++) {
String bindingName = sheet.getColumn(row, "Binding Name");
// Ignore bindings whose name start with "!"
if (Utilities.noString(bindingName) || bindingName.startsWith("!"))
continue;
// if (Character.isLowerCase(bindingName.charAt(0)))
// throw new Exception("binding name "+bindingName+" is illegal - must start with a capital letter");
BindingSpecification cd = new BindingSpecification(usageContext, bindingName, false);
if (definitions != null)
definitions.getAllBindings().add(cd);
cd.setDefinition(Utilities.appendPeriod(sheet.getColumn(row, "Definition")));
cd.setBindingMethod(BindingsParser.readBinding(sheet.getColumn(row, "Binding"), cd.getName() + " in " + folder));
String ref = sheet.getColumn(row, "Reference");
if (!cd.getBinding().equals(BindingMethod.Unbound) && Utilities.noString(ref))
throw new Exception("binding " + cd.getName() + " is missing a reference");
if (cd.getBinding() == BindingMethod.CodeList) {
if (ref.startsWith("#valueset-"))
throw new Exception("don't start code list references with #valueset-");
cd.setValueSet(ValueSetUtilities.makeShareable(new ValueSet()));
valuesets.add(cd.getValueSet());
cd.getValueSet().setVersion(version.toCode());
cd.getValueSet().setId(igSuffix(ig) + ref.substring(1));
cd.getValueSet().setUrl("http://hl7.org/fhir/ValueSet/" + igSuffix(ig) + ref.substring(1));
cd.getValueSet().setUserData("filename", "valueset-" + cd.getValueSet().getId());
if (!cd.getValueSet().hasExtension(ToolingExtensions.EXT_WORKGROUP)) {
cd.getValueSet().addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType(committee.getCode()));
} else {
String ec = ToolingExtensions.readStringExtension(cd.getValueSet(), ToolingExtensions.EXT_WORKGROUP);
if (!ec.equals(committee))
System.out.println("ValueSet " + cd.getValueSet().getUrl() + " WG mismatch 3: is " + ec + ", want to set to " + committee.getCode());
}
if (ig != null) {
cd.getValueSet().setUserDataINN(ToolResourceUtilities.NAME_RES_IG, ig);
cd.getValueSet().setUserData("path", "valueset-" + cd.getValueSet().getId() + ".html");
} else
cd.getValueSet().setUserData("path", "valueset-" + cd.getValueSet().getId() + ".html");
if (!cd.getValueSet().getUserData("path").equals(cd.getValueSet().getUserData("filename") + ".html"))
throw new Exception("Mis-identified value set");
if (!ref.startsWith("#"))
throw new Exception("Error parsing binding " + cd.getName() + ": code list reference '" + ref + "' must started with '#'");
Sheet cs = xls.getSheets().get(ref.substring(1));
if (cs == null)
throw new Exception("Error parsing binding " + cd.getName() + ": code list reference '" + ref + "' not resolved");
vsGen.updateHeader(cd, cd.getValueSet());
new CodeListToValueSetParser(cs, ref.substring(1), cd.getValueSet(), version.toCode(), codeSystems, maps, packageInfo).execute(sheet.getColumn(row, "v2"), checkV3Mapping(sheet.getColumn(row, "v3")), getIsUtg(bindingName));
} else if (cd.getBinding() == BindingMethod.ValueSet) {
if (ref.startsWith("http:"))
// will sort this out later
cd.setReference(sheet.getColumn(row, "Reference"));
else
cd.setValueSet(loadValueSet(ref));
} else if (cd.getBinding() == BindingMethod.Special) {
if ("#operation-outcome".equals(sheet.getColumn(row, "Reference")))
new ValueSetGenerator(definitions, version.toCode(), genDate, context.translator(), packageInfo).loadOperationOutcomeValueSet(cd);
else
throw new Exception("Special bindings are only allowed in bindings.xml");
}
// do this anyway in the short term
cd.setReference(sheet.getColumn(row, "Reference"));
if (cd.getValueSet() != null) {
ValueSet vs = cd.getValueSet();
ValueSetUtilities.makeShareable(vs);
vs.setUserData("filename", "valueset-" + vs.getId());
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 4: is " + ec + ", want to set to " + committee.getCode());
}
if (ig != null) {
vs.setUserDataINN(ToolResourceUtilities.NAME_RES_IG, ig);
vs.setUserData("path", ig.getCode() + "/valueset-" + vs.getId() + ".html");
} else
vs.setUserData("path", "valueset-" + vs.getId() + ".html");
if (!ValueSetUtilities.hasOID(vs))
ValueSetUtilities.setOID(vs, "urn:oid:" + BindingSpecification.DEFAULT_OID_VS + registry.idForUri(vs.getUrl()));
if (vs.getUserData("cs") != null) {
if (!CodeSystemUtilities.hasOID((CodeSystem) vs.getUserData("cs")))
CodeSystemUtilities.setOID((CodeSystem) vs.getUserData("cs"), "urn:oid:" + BindingSpecification.DEFAULT_OID_CS + registry.idForUri(((CodeSystem) vs.getUserData("cs")).getUrl()));
}
if (definitions != null)
definitions.getBoundValueSets().put(vs.getUrl(), vs);
else
ig.getValueSets().add(vs);
} else if (cd.getReference() != null && cd.getReference().startsWith("http:")) {
if (definitions != null)
definitions.getUnresolvedBindings().add(cd);
else
ig.getUnresolvedBindings().add(cd);
}
cd.setDescription(sheet.getColumn(row, "Description"));
if (!Utilities.noString(sheet.getColumn(row, "Example")))
throw new Exception("The 'Example' column is no longer supported");
if (!Utilities.noString(sheet.getColumn(row, "Extensible")))
throw new Exception("The 'Extensible' column is no longer supported");
cd.setStrength(BindingsParser.readBindingStrength(sheet.getColumn(row, "Conformance")));
if (cd.getBinding() == BindingMethod.Unbound) {
cd.setStrength(BindingStrength.EXAMPLE);
}
cd.setSource(name);
cd.setUri(sheet.getColumn(row, "Uri"));
String oid = sheet.getColumn(row, "Oid");
if (!Utilities.noString(oid))
// no cs oid in this case
cd.setVsOid(oid);
cd.setStatus(PublicationStatus.fromCode(sheet.getColumn(row, "Status")));
cd.setWebSite(sheet.getColumn(row, "Website"));
cd.setEmail(sheet.getColumn(row, "Email"));
cd.setCopyright(sheet.getColumn(row, "Copyright"));
cd.setV2Map(sheet.getColumn(row, "v2"));
cd.setV3Map(checkV3Mapping(sheet.getColumn(row, "v3")));
String max = sheet.getColumn(row, "Max");
if (!Utilities.noString(max))
if (max.startsWith("http:")) {
// will sort this out later
cd.setMaxReference(max);
} else
cd.setMaxValueSet(loadValueSet(max));
bindings.put(cd.getName(), cd);
if (cd.getValueSet() != null) {
ValueSet vs = cd.getValueSet();
vsGen.updateHeader(cd, cd.getValueSet());
}
}
}
use of org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet in project kindling by HL7.
the class OldSpreadsheetParser method parseConformancePackage.
public void parseConformancePackage(Profile ap, Definitions definitions, String folder, String usage, List<ValidationMessage> issues, WorkGroup wg) throws Exception {
try {
isProfile = true;
this.folder = folder;
checkMappings(ap);
Sheet sheet = loadSheet("Bindings");
if (sheet != null)
readBindings(sheet);
sheet = loadSheet("Metadata");
for (int row = 0; row < sheet.rows.size(); row++) {
String n = sheet.getColumn(row, "Name");
String v = sheet.getColumn(row, "Value");
if (n != null && v != null) {
if (ap.getMetadata().containsKey(n))
ap.getMetadata().get(n).add(v);
else {
ArrayList<String> vl = new ArrayList<String>();
vl.add(v);
ap.getMetadata().put(n, vl);
}
}
}
if (!Utilities.noString(ap.metadata("category")))
usage = ap.metadata("category");
if (ap.hasMetadata("name"))
ap.setTitle(ap.metadata("name"));
if (ap.hasMetadata("introduction"))
ap.setIntroduction(Utilities.path(folder, ap.metadata("introduction")));
if (ap.hasMetadata("notes"))
ap.setNotes(Utilities.path(folder, ap.metadata("notes")));
if (!ap.hasMetadata("id"))
throw new Exception("Error parsing " + ap.getId() + "/" + ap.getTitle() + " no 'id' found in metadata");
if (!ap.metadata("id").matches(FormatUtilities.ID_REGEX))
throw new Exception("Error parsing " + ap.getId() + "/" + ap.getTitle() + " 'id' is not a valid id");
if (wg == null)
wg = workgroups.get(ap.metadata("workgroup"));
if (wg == null)
wg = committee;
if (wg == null)
throw new Exception("Error parsing " + ap.getId() + "/" + ap.getTitle() + " : no workgroup value in the metadata");
if (!ap.metadata("id").equals(ap.metadata("id").toLowerCase()))
throw new Exception("Error parsing " + ap.getId() + "/" + ap.getTitle() + " 'id' must be all lowercase");
this.profileExtensionBase = ap.metadata("extension.uri");
if (ig == null || ig.isCore()) {
if (!profileExtensionBase.startsWith("http://hl7.org/fhir/StructureDefinition/") && !profileExtensionBase.startsWith("http://fhir-registry.smarthealthit.org/StructureDefinition/"))
throw new Exception("Core extensions must have a url starting with http://hl7.org/fhir/StructureDefinition/ for " + ap.getId());
} else {
if (!profileExtensionBase.startsWith("http://hl7.org/fhir/StructureDefinition/" + ig.getCode() + "-"))
throw new Exception("Core extensions must have a url starting with http://hl7.org/fhir/StructureDefinition/" + ig.getCode() + "- for " + ap.getId());
}
Map<String, Invariant> invariants = null;
sheet = loadSheet("Extensions-Inv");
if (sheet != null) {
invariants = readInvariants(sheet, "", "Extensions-Inv");
}
sheet = loadSheet("Extensions");
if (sheet != null) {
int row = 0;
while (row < sheet.rows.size()) {
if (sheet.getColumn(row, "Code").startsWith("!"))
row++;
else
row = processExtension(null, sheet, row, definitions, ap.metadata("extension.uri"), ap, issues, invariants, wg);
}
}
List<String> namedSheets = new ArrayList<String>();
if (ap.getMetadata().containsKey("published.structure")) {
for (String n : ap.getMetadata().get("published.structure")) {
if (!Utilities.noString(n)) {
if (ig != null && !ig.isCore() && !n.toLowerCase().startsWith(ig.getCode() + "-"))
throw new Exception("Error: published structure names must start with the implementation guide code (" + ig.getCode() + "-)");
String fmm = ap.metadata("fmm-" + n);
if (Utilities.noString(fmm))
fmm = ap.metadata("fmm");
if (Utilities.noString(fmm))
// default fmm value
fmm = "1";
ap.getProfiles().add(parseProfileSheet(definitions, ap, n, namedSheets, true, usage, issues, wg, fmm));
}
}
}
int i = 0;
while (i < namedSheets.size()) {
String fmm = ap.metadata("fmm-" + namedSheets.get(i));
if (Utilities.noString(fmm))
fmm = ap.metadata("fmm");
if (Utilities.noString(fmm))
// default fmm value
fmm = "1";
ap.getProfiles().add(parseProfileSheet(definitions, ap, namedSheets.get(i), namedSheets, false, usage, issues, wg, fmm));
i++;
}
if (namedSheets.isEmpty() && xls.getSheets().containsKey("Search"))
readSearchParams(ap, xls.getSheets().get("Search"), this.profileExtensionBase);
if (xls.getSheets().containsKey("Operations"))
readOperations(ap.getOperations(), loadSheet("Operations"));
} catch (Exception e) {
throw new Exception("exception parsing pack " + ap.getSource() + ": " + e.getMessage(), e);
}
}
use of org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet 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.utilities.xls.XLSXmlParser.Sheet in project kindling by HL7.
the class OldSpreadsheetParser method checkMappings.
private void checkMappings(Profile pack) throws Exception {
pack.getMappingSpaces().clear();
Sheet sheet = loadSheet("Mappings");
if (sheet != null) {
for (int row = 0; row < sheet.rows.size(); row++) {
String uri = sheet.getNonEmptyColumn(row, "Uri");
MappingSpace ms = new MappingSpace(sheet.getNonEmptyColumn(row, "Column"), sheet.getNonEmptyColumn(row, "Title"), sheet.getNonEmptyColumn(row, "Id"), sheet.getIntColumn(row, "Sort Order"), true, false, false, sheet.hasColumn(row, "Link") ? sheet.getColumn(row, "Link") : uri);
pack.getMappingSpaces().put(uri, ms);
}
}
}
use of org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet 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);
}
}
}
}
Aggregations