Search in sources :

Example 1 with Sheet

use of org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet 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 Sheet

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

the class OldSpreadsheetParser method parseProfileSheet.

private ConstraintStructure parseProfileSheet(Definitions definitions, Profile ap, String n, List<String> namedSheets, boolean published, String usage, List<ValidationMessage> issues, WorkGroup wg, String fmm) throws Exception {
    Sheet sheet;
    ResourceDefn resource = new ResourceDefn();
    sheet = loadSheet(n + "-Inv");
    Map<String, Invariant> invariants = null;
    if (sheet != null) {
        invariants = readInvariants(sheet, n, n + "-Inv");
    } else {
        invariants = new HashMap<String, Invariant>();
    }
    sheet = loadSheet(n);
    if (sheet == null)
        throw new Exception("The StructureDefinition referred to a tab by the name of '" + n + "', but no tab by the name could be found");
    for (int row = 0; row < sheet.rows.size(); row++) {
        ElementDefn e = processLine(resource, sheet, row, invariants, true, ap, row == 0);
        if (e != null)
            for (TypeRef t : e.getTypes()) {
                if (t.getProfile() != null && !t.getName().equals("Extension") && t.getProfile().startsWith("#")) {
                    if (!namedSheets.contains(t.getProfile().substring(1)))
                        namedSheets.add(t.getProfile().substring(1));
                }
            }
    }
    sheet = loadSheet(n + "-Extensions");
    if (sheet != null) {
        int row = 0;
        while (row < sheet.rows.size()) {
            if (sheet.getColumn(row, "Code").startsWith("!"))
                row++;
            else
                row = processExtension(resource.getRoot().getElementByName(definitions, "extensions", true, false), sheet, row, definitions, ap.metadata("extension.uri"), ap, issues, invariants, wg);
        }
    }
    sheet = loadSheet(n + "-Search");
    if (sheet != null) {
        readSearchParams(resource, sheet, true);
    }
    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");
                // TODO: Need to resolve context based on element name, not just path
                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()))
            // throw new Exception("Type "+resource.getRoot().getName()+" Invariant "+inv.getId()+" ("+inv.getEnglish()+") has no Expression statement (in FHIRPath format)");
            }
        }
    }
    resource.getRoot().setProfileName(n);
    if (n.toLowerCase().equals(ap.getId()))
        throw new Exception("Duplicate Profile Name: Package id " + ap.getId() + " and profile id " + n.toLowerCase() + " are the same");
    if (profileIds.containsKey(n.toLowerCase()))
        throw new Exception("Duplicate Profile Name: " + n.toLowerCase() + " in " + ap.getId() + ", already registered in " + profileIds.get(n.toLowerCase()).getOwner());
    ConstraintStructure p = new ConstraintStructure(n.toLowerCase(), resource.getRoot().getProfileName(), resource, ig != null ? ig : definitions.getUsageIG(usage, "Parsing " + name), wg, fmm, Utilities.existsInList(ap.metadata("Experimental"), "y", "Y", "true", "TRUE", "1"));
    p.setOwner(ap.getId());
    profileIds.put(n.toLowerCase(), p);
    return p;
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure) Sheet(org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 3 with Sheet

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

the class OldSpreadsheetParser method getIsUtg.

private boolean getIsUtg(String bindingName) {
    Sheet sheet = loadSheet("Data Elements");
    if (sheet != null)
        for (int row = 0; row < sheet.rows.size(); row++) {
            if (bindingName.equals(sheet.getColumn(row, "Binding"))) {
                return !"code".equals(sheet.getColumn(row, "Type"));
            }
        }
    sheet = loadSheet("Operations");
    if (sheet != null)
        for (int row = 0; row < sheet.rows.size(); row++) {
            if (bindingName.equals(sheet.getColumn(row, "Binding"))) {
                return !"code".equals(sheet.getColumn(row, "Type"));
            }
        }
    return true;
}
Also used : Sheet(org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet)

Example 4 with Sheet

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

the class OldSpreadsheetParser method readExamples.

private void readExamples(ResourceDefn defn, Sheet sheet) throws Exception {
    if (sheet != null) {
        for (int row = 0; row < sheet.rows.size(); row++) {
            String name = sheet.getColumn(row, "Name");
            if (name != null && !name.equals("") && !name.startsWith("!")) {
                String id = sheet.getColumn(row, "Identity");
                if (id == null || id.equals(""))
                    throw new Exception("Example " + name + " has no identity parsing " + this.name);
                String desc = sheet.getColumn(row, "Description");
                if (desc == null || desc.equals(""))
                    throw new Exception("Example " + name + " has no description parsing " + this.name);
                String filename = sheet.getColumn(row, "Filename");
                if (filename.startsWith(defn.getName().toLowerCase() + "-examples."))
                    throw new Exception("Cannot name an example file " + filename);
                File file = new CSFile(folder + filename);
                String type = sheet.getColumn(row, "Type");
                if (!file.exists() && !("tool".equals(type) || isSpecialType(type)))
                    throw new Exception("Example " + name + " file '" + file.getAbsolutePath() + "' not found parsing " + this.name);
                List<Example> list = defn.getExamples();
                String pn = sheet.getColumn(row, "Profile");
                if (!Utilities.noString(pn) && !pn.startsWith("!")) {
                    Profile ap = null;
                    for (Profile r : defn.getConformancePackages()) {
                        if (r.getTitle().equals(pn))
                            ap = r;
                    }
                    if (ap == null)
                        throw new Exception("Example " + name + " profile '" + pn + "' not found parsing " + this.name);
                    else
                        list = ap.getExamples();
                }
                ExampleType etype = parseExampleType(type, row);
                list.add(new Example(name, id, desc, file, parseBoolean(sheet.getColumn(row, "Registered"), row, true), etype, isAbstract));
            }
        }
    }
    if (defn.getExamples().size() == 0) {
        File file = new CSFile(folder + title + "-example.xml");
        if (!file.exists() && !isAbstract)
            throw new Exception("Example (file '" + file.getAbsolutePath() + "') not found parsing " + this.name);
        if (file.exists())
            defn.getExamples().add(new Example("General", "example", "Example of " + title, file, true, ExampleType.XmlFile, isAbstract));
    }
}
Also used : Example(org.hl7.fhir.definitions.model.Example) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) CSFile(org.hl7.fhir.utilities.CSFile) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) FHIRException(org.hl7.fhir.exceptions.FHIRException) Profile(org.hl7.fhir.definitions.model.Profile) ExampleType(org.hl7.fhir.definitions.model.Example.ExampleType)

Example 5 with Sheet

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

the class OldSpreadsheetParser method readOperations.

private void readOperations(List<Operation> oplist, Sheet sheet) throws Exception {
    Map<String, Operation> ops = new HashMap<String, Operation>();
    Map<String, OperationParameter> params = new HashMap<String, OperationParameter>();
    if (sheet != null) {
        for (int row = 0; row < sheet.rows.size(); row++) {
            String name = sheet.getColumn(row, "Name");
            String use = sheet.getColumn(row, "Use");
            String doco = sheet.getColumn(row, "Documentation");
            String type = sheet.getColumn(row, "Type");
            List<OperationExample> examples = loadOperationExamples(sheet.getColumn(row, "Example.Request"), sheet.getColumn(row, "Example.Response"));
            List<OperationExample> examples2 = loadOperationExamples(sheet.getColumn(row, "Example2.Request"), sheet.getColumn(row, "Example2.Response"));
            if (name != null && !name.equals("") && !name.startsWith("!")) {
                if (!name.contains(".")) {
                    if (!type.equals("operation"))
                        throw new Exception("Invalid type on operation " + type + " at " + getLocation(row));
                    if (!name.toLowerCase().equals(name))
                        throw new Exception("Invalid name on operation " + name + " - must be all lower case (use dashes) at " + getLocation(row));
                    params.clear();
                    boolean system = false;
                    boolean istype = false;
                    boolean instance = false;
                    for (String c : use.split("\\|")) {
                        c = c.trim();
                        if ("system".equalsIgnoreCase(c))
                            system = true;
                        else if ("resource".equalsIgnoreCase(c))
                            istype = true;
                        else if ("instance".equalsIgnoreCase(c))
                            instance = true;
                        else
                            throw new Exception("unknown operation use code " + c + " at " + getLocation(row));
                    }
                    Operation op = new Operation(name, system, istype, instance, sheet.getColumn(row, "Type"), sheet.getColumn(row, "Title"), doco, sheet.getColumn(row, "Footer"), examples, parseBoolean(sheet.getColumn(row, "Idempotent"), row, false));
                    op.setStandardsStatus(StandardsStatus.fromCode(sheet.getColumn(row, "Standards-Status")));
                    op.setNormativeVersion(sheet.getColumn(row, "Normative-Version"));
                    op.setFooter2(sheet.getColumn(row, "Footer2"));
                    op.setFmm(sheet.getColumn(row, "fmm"));
                    op.getExamples2().addAll(examples2);
                    oplist.add(op);
                    ops.put(name, op);
                } else {
                    String context = name.substring(0, name.lastIndexOf('.'));
                    String pname = name.substring(name.lastIndexOf('.') + 1);
                    Operation operation;
                    List<OperationParameter> plist;
                    if (context.contains(".")) {
                        String opname = name.substring(0, name.indexOf('.'));
                        // inside of a tuple
                        if (!Utilities.noString(use))
                            throw new Exception("Tuple parameters: use must be blank at " + getLocation(row));
                        operation = ops.get(opname);
                        if (operation == null)
                            throw new Exception("Unknown Operation '" + opname + "' at " + getLocation(row));
                        OperationParameter param = params.get(context);
                        if (param == null)
                            throw new Exception("Tuple parameter '" + context + "' not found at " + getLocation(row));
                        if (!param.getFhirType().equals("Tuple"))
                            throw new Exception("Tuple parameter '" + context + "' type must be Tuple at " + getLocation(row));
                        plist = param.getParts();
                    } else {
                        if (!use.equals("in") && !use.equals("out"))
                            throw new Exception("Only allowed use is 'in' or 'out' at " + getLocation(row));
                        operation = ops.get(context);
                        if (operation == null)
                            throw new Exception("Unknown Operation '" + context + "' at " + getLocation(row));
                        plist = operation.getParameters();
                    }
                    String profile = sheet.getColumn(row, "Profile");
                    String min = sheet.getColumn(row, "Min");
                    String max = sheet.getColumn(row, "Max");
                    OperationParameter p = new OperationParameter(pname, use, doco, Integer.parseInt(min), max, type, sheet.getColumn(row, "Search Type"), profile);
                    String bs = sheet.getColumn(row, "Binding");
                    if (!Utilities.noString(bs))
                        p.setBs(bindings.get(bs));
                    plist.add(p);
                    params.put(name, p);
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) OperationParameter(org.hl7.fhir.definitions.model.OperationParameter) Operation(org.hl7.fhir.definitions.model.Operation) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)18 Sheet (org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet)15 Sheet (org.apache.poi.ss.usermodel.Sheet)14 Row (org.apache.poi.ss.usermodel.Row)13 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)12 ArrayList (java.util.ArrayList)8 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)8 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)8 Invariant (org.hl7.fhir.definitions.model.Invariant)8 XLSXmlParser (org.hl7.fhir.utilities.xls.XLSXmlParser)8 TypeRef (org.hl7.fhir.definitions.model.TypeRef)7 File (java.io.File)6 BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)5 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)5 IniFile (org.hl7.fhir.utilities.IniFile)5 HashMap (java.util.HashMap)4 ConditionalFormattingRule (org.apache.poi.ss.usermodel.ConditionalFormattingRule)4 FontFormatting (org.apache.poi.ss.usermodel.FontFormatting)4 PatternFormatting (org.apache.poi.ss.usermodel.PatternFormatting)4 SheetConditionalFormatting (org.apache.poi.ss.usermodel.SheetConditionalFormatting)4