use of org.hl7.fhir.utilities.xls.XLSXmlParser in project kindling by HL7.
the class ResourceNameConceptMapGenerator method main.
public static void main(String[] args) throws IOException, FHIRException {
String srcFolder = args[0];
String filename = Utilities.path(srcFolder, "resource-name-tracker.xml");
Date date = new Date(new File(filename).lastModified());
XLSXmlParser xls = new XLSXmlParser(new FileInputStream(filename), "resource-name-tracker.xml");
String dstFolder = args[1];
genMap("r2", "1.0", "r3", "3.0", xls.getSheets().get("Map"), dstFolder, "resource-names-r2-r3", date);
genMap("r2", "1.0", "r4", "4.0", xls.getSheets().get("Map"), dstFolder, "resource-names-r2-r4", date);
genMap("r3", "3.0", "r2", "1.0", xls.getSheets().get("Map"), dstFolder, "resource-names-r3-r2", date);
genMap("r3", "3.0", "r4", "4.0", xls.getSheets().get("Map"), dstFolder, "resource-names-r3-r4", date);
genMap("r4", "4.0", "r2", "1.0", xls.getSheets().get("Map"), dstFolder, "resource-names-r4-r2", date);
genMap("r4", "4.0", "r3", "3.0", xls.getSheets().get("Map"), dstFolder, "resource-names-r4-r3", date);
}
use of org.hl7.fhir.utilities.xls.XLSXmlParser in project kindling by HL7.
the class BindingsParser method parse.
public List<BindingSpecification> parse() throws Exception {
List<BindingSpecification> results = new ArrayList<BindingSpecification>();
// BindingSpecification n = new BindingSpecification();
// n.setName("*unbound*");
// n.setBinding(BindingSpecification.Binding.Unbound);
// results.add(n);
xls = new XLSXmlParser(file, filename);
new XLSXmlNormaliser(filename, exceptionIfExcelNotNormalised).go();
Sheet sheet = xls.getSheets().get("Bindings");
for (int row = 0; row < sheet.rows.size(); row++) {
processLine(results, sheet, row);
}
return results;
}
use of org.hl7.fhir.utilities.xls.XLSXmlParser in project kindling by HL7.
the class SourceParser method loadCompositeType.
private String loadCompositeType(String n, Map<String, org.hl7.fhir.definitions.model.TypeDefn> map, String fmm, boolean isAbstract) throws Exception {
TypeParser tp = new TypeParser(version.toString());
List<TypeRef> ts = tp.parse(n, false, null, context, true);
definitions.getKnownTypes().addAll(ts);
StandardsStatus status = loadStatus(n);
String nv = loadNormativeVersion(n);
try {
TypeRef t = ts.get(0);
File csv = new CSFile(dtDir + t.getName().toLowerCase() + ".xml");
if (csv.exists()) {
OldSpreadsheetParser p = new OldSpreadsheetParser("core", new CSFileInputStream(csv), csv.getName(), csv.getAbsolutePath(), definitions, srcDir, logger, registry, version, context, genDate, isAbstract, page, true, ini, wg("fhir"), definitions.getProfileIds(), fpUsages, page.getConceptMaps(), exceptionIfExcelNotNormalised, page.packageInfo(), page.getRc());
org.hl7.fhir.definitions.model.TypeDefn el = p.parseCompositeType();
el.setFmmLevel(fmm);
el.setStandardsStatus(status);
el.setNormativeVersion(nv);
map.put(t.getName(), el);
genTypeProfile(el);
errors.addAll(p.getErrors());
return el.getName();
} else {
String p = ini.getStringProperty("types", n);
csv = new CSFile(dtDir + p.toLowerCase() + ".xml");
if (!csv.exists())
throw new Exception("unable to find a definition for " + n + " in " + p);
XLSXmlParser xls = new XLSXmlParser(new CSFileInputStream(csv), csv.getAbsolutePath());
new XLSXmlNormaliser(csv.getAbsolutePath(), exceptionIfExcelNotNormalised).go();
Sheet sheet = xls.getSheets().get("Restrictions");
boolean found = false;
for (int i = 0; i < sheet.rows.size(); i++) {
if (sheet.getColumn(i, "Name").equals(n)) {
found = true;
Invariant inv = new Invariant();
inv.setId(n);
inv.setEnglish(sheet.getColumn(i, "Rules"));
inv.setOcl(sheet.getColumn(i, "OCL"));
inv.setXpath(sheet.getColumn(i, "XPath"));
inv.setExpression(sheet.getColumn(i, "Expression"));
inv.setExplanation(sheet.getColumn(i, "Explanation"));
inv.setTurtle(sheet.getColumn(i, "RDF"));
ProfiledType pt = new ProfiledType();
pt.setDefinition(sheet.getColumn(i, "Definition"));
pt.setDescription(sheet.getColumn(i, "Rules"));
String structure = sheet.getColumn(i, "Structure");
if (!Utilities.noString(structure)) {
String[] parts = structure.split("\\;");
for (String pp : parts) {
String[] words = pp.split("\\=");
pt.getRules().put(words[0], words[1]);
}
}
pt.setName(n);
pt.setBaseType(p);
pt.setInvariant(inv);
definitions.getConstraints().put(n, pt);
}
}
if (!found)
throw new Exception("Unable to find definition for " + n);
return n;
}
} catch (Exception e) {
throw new Exception("Unable to load " + n + ": " + e.getMessage(), e);
}
}
use of org.hl7.fhir.utilities.xls.XLSXmlParser in project kindling by HL7.
the class SourceParser method loadStatusCodes.
private void loadStatusCodes() throws FileNotFoundException, Exception {
XLSXmlParser xml = new XLSXmlParser(new CSFileInputStream(srcDir + "status-codes.xml"), "Status Codes");
new XLSXmlNormaliser(srcDir + "status-codes.xml", exceptionIfExcelNotNormalised).go();
Sheet sheet = xml.getSheets().get("Status Codes");
for (int row = 0; row < sheet.rows.size(); row++) {
String path = sheet.getColumn(row, "Path");
ArrayList<String> codes = new ArrayList<String>();
for (int i = 1; i <= 80; i++) {
String s = sheet.getColumn(row, "c" + Integer.toString(i));
if (s.endsWith("?"))
s = s.substring(0, s.length() - 1);
codes.add(s);
}
definitions.getStatusCodes().put(path, codes);
}
}
use of org.hl7.fhir.utilities.xls.XLSXmlParser in project kindling by HL7.
the class BindingsFixer method processSheet.
private static void processSheet(XLSXmlParser xls, Sheet sheet, String dir, String sfx) throws Exception {
for (int row = 0; row < sheet.rows.size(); row++) {
String bindingName = sheet.getColumn(row, "Binding Name");
if (Utilities.noString(bindingName) || bindingName.startsWith("!"))
continue;
BindingMethod method = BindingsParser.readBinding(sheet.getColumn(row, "Binding"), "??");
String ref = sheet.getColumn(row, "Reference");
if (method == BindingMethod.CodeList) {
if (ref.startsWith("#valueset-"))
throw new Exception("don't start code list references with #valueset-");
String vfn = Utilities.path(dir, "valueset-" + sfx + ref.substring(1) + ".xml");
String cfn = Utilities.path(dir, "codesystem-" + sfx + ref.substring(1) + ".xml");
File vf = new File(vfn);
File cf = new File(cfn);
if (!vf.exists()) {
System.out.println("Produce " + vfn);
ValueSet vs = ValueSetUtilities.makeShareable(new ValueSet());
vs.setVersion(Constants.VERSION);
vs.setId(sfx + ref.substring(1));
vs.setUrl("http://hl7.org/fhir/ValueSet/" + sfx + ref.substring(1));
vs.setDescription(sheet.getColumn(row, "Description"));
vs.setName(bindingName);
vs.setStatus(PublicationStatus.fromCode(sheet.getColumn(row, "Status")));
vs.setCopyright(sheet.getColumn(row, "Copyright"));
Sheet css = xls.getSheets().get(ref.substring(1));
if (css == null) {
throw new Exception("Error parsing binding " + bindingName + ": code list reference '" + ref + "' not resolved");
}
CodeSystem cs = CodeSystemUtilities.makeShareable(new CodeSystem());
cs.setVersion(Constants.VERSION);
cs.setId(sfx + ref.substring(1));
cs.setUrl("http://hl7.org/fhir/" + sfx + ref.substring(1));
cs.setDescription(sheet.getColumn(row, "Description"));
cs.setName(bindingName);
cs.setStatus(PublicationStatus.fromCode(sheet.getColumn(row, "Status")));
cs.setCopyright(sheet.getColumn(row, "Copyright"));
vs.getCompose().addInclude().setSystem(cs.getUrl());
processCodes(cs, css);
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(vf), vs);
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(cf), cs);
}
}
}
}
Aggregations