Search in sources :

Example 1 with XLSXmlNormaliser

use of org.hl7.fhir.utilities.xls.XLSXmlNormaliser 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 2 with XLSXmlNormaliser

use of org.hl7.fhir.utilities.xls.XLSXmlNormaliser 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 3 with XLSXmlNormaliser

use of org.hl7.fhir.utilities.xls.XLSXmlNormaliser 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 4 with XLSXmlNormaliser

use of org.hl7.fhir.utilities.xls.XLSXmlNormaliser in project org.hl7.fhir.core by hapifhir.

the class XLSXmlNormaliserTests method testConvert.

@Test
public void testConvert() throws FHIRException, TransformerException, ParserConfigurationException, SAXException, IOException {
    XLSXmlNormaliser n = new XLSXmlNormaliser("src/test/resources/observation-spreadsheet.xml", "target/observation-spreadsheet.out.xml", true);
    n.go();
    // n = new XLSXmlNormaliser("C:\\work\\org.hl7.fhir\\build\\source\\observation\\observation-spreadsheet.before.xml", "C:\\\\work\\\\org.hl7.fhir\\\\build\\\\source\\\\observation\\\\observation-spreadsheet.before.out.xml", true);
    // n.go();
    Assertions.assertTrue(true);
}
Also used : XLSXmlNormaliser(org.hl7.fhir.utilities.xls.XLSXmlNormaliser) Test(org.junit.jupiter.api.Test)

Example 5 with XLSXmlNormaliser

use of org.hl7.fhir.utilities.xls.XLSXmlNormaliser in project kindling by HL7.

the class SourceParser method loadPrimitives.

private void loadPrimitives() throws Exception {
    XLSXmlParser xls = new XLSXmlParser(new CSFileInputStream(dtDir + "primitives.xml"), "primitives");
    new XLSXmlNormaliser(dtDir + "primitives.xml", exceptionIfExcelNotNormalised).go();
    Sheet sheet = xls.getSheets().get("Imports");
    for (int row = 0; row < sheet.rows.size(); row++) {
        processImport(sheet, row);
    }
    sheet = xls.getSheets().get("Patterns");
    for (int row = 0; row < sheet.rows.size(); row++) {
        processStringPattern(sheet, row);
    }
}
Also used : 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)

Aggregations

XLSXmlNormaliser (org.hl7.fhir.utilities.xls.XLSXmlNormaliser)6 XLSXmlParser (org.hl7.fhir.utilities.xls.XLSXmlParser)5 Sheet (org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet)5 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)4 ArrayList (java.util.ArrayList)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)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 OldSpreadsheetParser (org.hl7.fhir.definitions.parsers.spreadsheets.OldSpreadsheetParser)1 FHIRException (org.hl7.fhir.exceptions.FHIRException)1 CSFile (org.hl7.fhir.utilities.CSFile)1 IniFile (org.hl7.fhir.utilities.IniFile)1