Search in sources :

Example 1 with XLSXmlParser

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);
}
Also used : XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) File(java.io.File) Date(java.util.Date) FileInputStream(java.io.FileInputStream)

Example 2 with XLSXmlParser

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;
}
Also used : BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) ArrayList(java.util.ArrayList) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) XLSXmlNormaliser(org.hl7.fhir.utilities.xls.XLSXmlNormaliser) Sheet(org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet)

Example 3 with XLSXmlParser

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);
    }
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) TypeRef(org.hl7.fhir.definitions.model.TypeRef) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) XLSXmlNormaliser(org.hl7.fhir.utilities.xls.XLSXmlNormaliser) CSFile(org.hl7.fhir.utilities.CSFile) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) OldSpreadsheetParser(org.hl7.fhir.definitions.parsers.spreadsheets.OldSpreadsheetParser) TypeDefn(org.hl7.fhir.definitions.model.TypeDefn) StandardsStatus(org.hl7.fhir.utilities.StandardsStatus) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) Sheet(org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream)

Example 4 with XLSXmlParser

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);
    }
}
Also used : ArrayList(java.util.ArrayList) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) XLSXmlNormaliser(org.hl7.fhir.utilities.xls.XLSXmlNormaliser) Sheet(org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream)

Example 5 with XLSXmlParser

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);
            }
        }
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ValueSet(org.hl7.fhir.r5.model.ValueSet) Sheet(org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) BindingMethod(org.hl7.fhir.definitions.model.BindingSpecification.BindingMethod)

Aggregations

XLSXmlParser (org.hl7.fhir.utilities.xls.XLSXmlParser)8 Sheet (org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet)7 XLSXmlNormaliser (org.hl7.fhir.utilities.xls.XLSXmlNormaliser)5 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 Date (java.util.Date)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)1 BindingMethod (org.hl7.fhir.definitions.model.BindingSpecification.BindingMethod)1 Compartment (org.hl7.fhir.definitions.model.Compartment)1 Invariant (org.hl7.fhir.definitions.model.Invariant)1 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)1 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)1 TypeDefn (org.hl7.fhir.definitions.model.TypeDefn)1 TypeRef (org.hl7.fhir.definitions.model.TypeRef)1