Search in sources :

Example 56 with Sheet

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

the class TypeParser method parse.

public List<TypeRef> parse(String n, boolean inProfile, String profileExtensionBase, BaseWorkerContext resolver, boolean allowElement, String sheetName) throws Exception {
    ArrayList<TypeRef> a = new ArrayList<TypeRef>();
    String exceptionPrefix = sheetName == null ? "" : "Error parsing sheet " + sheetName + " - ";
    if (n == null || n.equals("") || n.startsWith("!"))
        return a;
    // to allow splitting
    if (n.indexOf("(") != -1 && n.indexOf("|") != -1) {
        String[] typeParts = n.split("[\\(\\)]");
        n = "";
        for (int i = 0; i < typeParts.length; i++) {
            n = n + typeParts[i++];
            if (i < typeParts.length) {
                n = n + "(" + typeParts[i].replace("|", ",") + ")";
            }
        }
    }
    String[] typeList = n.split("[\\|]");
    for (int i = 0; i < typeList.length; i++) {
        TypeRef t = new TypeRef();
        String typeString = typeList[i].trim();
        if (typeString.contains("<")) {
            if (!inProfile) {
                throw new Exception(exceptionPrefix + "Can't specify aggregation mode for types unless defining a profile: " + typeString);
            }
            int startPos = typeString.indexOf("<");
            int endPos = typeString.indexOf(">");
            if (endPos < startPos) {
                throw new Exception(exceptionPrefix + "Missing '>' in data type definition: " + typeList[i]);
            }
            t.getAggregations().addAll(Arrays.asList(typeString.substring(startPos + 1, endPos).trim().split(",")));
            typeString = typeString.substring(0, startPos);
        }
        if (typeString.contains("~")) {
            String v = typeString.substring(typeString.indexOf("~"));
            typeString = typeString.substring(0, typeString.indexOf("~") - 1);
            t.setVersioning(org.hl7.fhir.r5.model.ElementDefinition.ReferenceVersionRules.fromCode(v));
        }
        if (typeString.contains("{")) {
            if (!inProfile) {
                throw new Exception(exceptionPrefix + "Can't specify profile for types unless defining a profile");
            }
            int startPos = typeString.indexOf("{");
            int endPos = typeString.indexOf("}");
            if (endPos < startPos) {
                throw new Exception(exceptionPrefix + "Missing '}' in data type definition: " + typeList[i]);
            }
            String pt = typeString.substring(startPos + 1, endPos).trim();
            typeString = typeString.substring(0, startPos);
            if (pt.startsWith("#")) {
                // what to do here depends on what it refers to
                if (typeString.trim().equals("Extension"))
                    pt = profileExtensionBase + pt.substring(1);
                else if (typeString.trim().startsWith("Reference") || typeString.trim().startsWith("Resource"))
                    pt = pt.substring(1).toLowerCase();
                else
                    throw new Exception(exceptionPrefix + "Unhandled case");
            }
            t.setProfile(pt);
        }
        if (typeString.contains("(")) {
            int startPos = typeString.indexOf("(");
            int endPos = typeString.indexOf(")");
            if (endPos < startPos) {
                throw new Exception(exceptionPrefix + "Missing ')' in data type definition: " + typeList[i]);
            }
            String[] params = typeString.substring(startPos + 1, endPos).split(",");
            for (int j = 0; j < params.length; j++) {
                if (typeString.startsWith("Reference("))
                    if (inProfile && !resolver.getResourceNames().contains(params[j].trim()) && !"Any".equals(params[j].trim()))
                        throw new Exception(exceptionPrefix + "Unknown resource " + params[j].trim());
                t.getParams().add(params[j].trim());
            }
            typeString = typeString.substring(0, startPos);
        }
        t.setName(typeString.trim());
        if (t.getName().equals("Element") && !allowElement)
            throw new Exception(exceptionPrefix + "The type 'Element' is illegal in this context");
        a.add(t);
    }
    return a;
}
Also used : TypeRef(org.hl7.fhir.definitions.model.TypeRef) ArrayList(java.util.ArrayList)

Example 57 with Sheet

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

the class BindingsParser method processLine.

private void processLine(List<BindingSpecification> results, Sheet sheet, int row) throws Exception {
    BindingSpecification cd = new BindingSpecification("core", sheet.getColumn(row, "Binding Name"), true);
    if (!cd.getName().startsWith("!")) {
        if (Character.isLowerCase(cd.getName().charAt(0)))
            throw new Exception("binding name " + cd.getName() + " is illegal - must start with a capital letter");
        cd.setDefinition(Utilities.appendPeriod(sheet.getColumn(row, "Definition")));
        cd.setBindingMethod(readBinding(sheet.getColumn(row, "Binding"), cd.getName() + " in " + filename));
        boolean utg = "y".equals(sheet.getColumn(row, "UTG"));
        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) {
            cd.setValueSet(new ValueSet());
            cd.getValueSet().setId(ref.substring(1));
            cd.getValueSet().setUrl("http://hl7.org/fhir/ValueSet/" + ref.substring(1));
            cd.getValueSet().setVersion(version);
            if (!Utilities.noString(sheet.getColumn(row, "Committee"))) {
                cd.getValueSet().addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType(sheet.getColumn(row, "Committee").toLowerCase()));
            }
            cd.getValueSet().setUserData("filename", "valueset-" + cd.getValueSet().getId());
            cd.getValueSet().setUserData("path", "valueset-" + cd.getValueSet().getId() + ".html");
            cd.getValueSet().setName(cd.getName());
            cd.getValueSet().setTitle(cd.getName());
            cd.getValueSet().setDateElement(new DateTimeType(genDate));
            cd.getValueSet().setStatus(PublicationStatus.DRAFT);
            cd.getValueSet().setDescription(sheet.getColumn(row, "Description"));
            if (!cd.getValueSet().hasDescription())
                cd.getValueSet().setDescription(cd.getDefinition());
            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");
            new CodeListToValueSetParser(cs, ref.substring(1), cd.getValueSet(), version, codeSystems, maps, packageInfo).execute(sheet.getColumn(row, "v2"), sheet.getColumn(row, "v3"), utg);
        } 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, sheet.getColumn(row, "Committee").toLowerCase()));
            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, sheet.getColumn(row, "Committee").toLowerCase()));
        } else if (cd.getBinding() == BindingMethod.Special) {
            cd.setValueSet(new ValueSet());
            cd.getValueSet().setId(ref.substring(1));
            cd.getValueSet().setUrl("http://hl7.org/fhir/ValueSet/" + ref.substring(1));
            cd.getValueSet().setVersion(version);
            cd.getValueSet().setName(cd.getName());
        // do nothing more: this will get filled out once all the resources are loaded
        }
        // do this anyway in the short term
        cd.setReference(sheet.getColumn(row, "Reference"));
        if (cd.getValueSet() != null) {
            touchVS(cd.getValueSet());
            ValueSetUtilities.markStatus(cd.getValueSet(), Utilities.noString(sheet.getColumn(row, "Committee")) ? "vocab" : sheet.getColumn(row, "Committee").toLowerCase(), null, null, Utilities.noString(sheet.getColumn(row, "FMM")) ? null : sheet.getColumn(row, "FMM"), null, Utilities.noString(sheet.getColumn(row, "Normative-Version")) ? null : sheet.getColumn(row, "Normative-Version"));
        }
        if (cd.getMaxValueSet() != null) {
            touchVS(cd.getMaxValueSet());
            ValueSetUtilities.markStatus(cd.getMaxValueSet(), Utilities.noString(sheet.getColumn(row, "Committee")) ? "vocab" : sheet.getColumn(row, "Committee").toLowerCase(), null, null, Utilities.noString(sheet.getColumn(row, "FMM")) ? null : sheet.getColumn(row, "FMM"), null, Utilities.noString(sheet.getColumn(row, "Max-Normative-Version")) ? null : sheet.getColumn(row, "Max-Normative-Version"));
        }
        cd.setDescription(sheet.getColumn(row, "Description"));
        cd.setSource(filename);
        cd.setUri(sheet.getColumn(row, "Uri"));
        cd.setStrength(readBindingStrength(sheet.getColumn(row, "Conformance")));
        String oid = sheet.getColumn(row, "Oid");
        if (!Utilities.noString(oid))
            // no cs oid in this case
            cd.setVsOid(oid);
        cd.setWebSite(sheet.getColumn(row, "Website"));
        cd.setStatus(PublicationStatus.fromCode(sheet.getColumn(row, "Status")));
        cd.setEmail(sheet.getColumn(row, "Email"));
        cd.setV2Map(sheet.getColumn(row, "v2"));
        cd.setV3Map(sheet.getColumn(row, "v3"));
        if (cd.getBinding() == BindingMethod.Unbound) {
            cd.setStrength(BindingStrength.EXAMPLE);
        }
        results.add(cd);
    }
}
Also used : DateTimeType(org.hl7.fhir.r5.model.DateTimeType) CodeListToValueSetParser(org.hl7.fhir.definitions.parsers.CodeListToValueSetParser) BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) CodeType(org.hl7.fhir.r5.model.CodeType) ValueSet(org.hl7.fhir.r5.model.ValueSet) Sheet(org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet) URISyntaxException(java.net.URISyntaxException)

Example 58 with Sheet

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

the class OldSpreadsheetParser method checkFile.

private String checkFile(Sheet sheet, int row, String column, boolean canBeNull, String defaultValue) throws Exception {
    String name = sheet.getColumn(row, column);
    if (Utilities.noString(name))
        name = defaultValue;
    if (Utilities.noString(name)) {
        if (!canBeNull)
            throw new Exception("Missing filename for '" + column + "' at " + getLocation(row));
        return null;
    }
    String filename = Utilities.path(folder, name);
    if (!(new File(filename).exists()))
        throw new Exception("Unable to find source file " + name);
    return filename;
}
Also used : 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)

Example 59 with Sheet

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

the class ConceptMapSpreadsheetGenerator method renderGroup.

private void renderGroup(ConceptMapGroupComponent grp, int i) {
    Sheet sheet = makeSheet("Mapping Table " + Integer.toString(i));
    addHeaders(sheet, "Source", "Display", "Relationship", "Target", "Display");
    addRow(sheet, grp.getSource(), "", "", grp.getTarget(), "");
    for (SourceElementComponent s : grp.getElement()) {
        for (TargetElementComponent t : s.getTarget()) {
            addRow(sheet, s.getCode(), s.getDisplay(), t.getRelationshipElement().asStringValue(), t.getCode(), t.getDisplay());
        }
    }
}
Also used : TargetElementComponent(org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent) Sheet(org.apache.poi.ss.usermodel.Sheet) SourceElementComponent(org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent)

Example 60 with Sheet

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

the class StructureDefinitionSpreadsheetGenerator method renderStructureDefinition.

public StructureDefinitionSpreadsheetGenerator renderStructureDefinition(StructureDefinition sd) throws Exception {
    if (sd == null) {
        System.out.println("no structure!");
    }
    if (!sd.hasSnapshot()) {
        throw new DefinitionException(context.formatMessage(I18nConstants.NEEDS_A_SNAPSHOT));
    }
    addStructureDefinitionMetadata(renderCanonicalResource(sd), sd);
    Sheet sheet = makeSheet("Elements");
    Row headerRow = sheet.createRow(0);
    for (int i = 0; i < titles.length; i++) {
        addCell(headerRow, i, titles[i], styles.get("header"));
    }
    int i = titles.length - 1;
    for (StructureDefinitionMappingComponent map : sd.getMapping()) {
        i++;
        addCell(headerRow, i, "Mapping: " + map.getName(), styles.get("header"));
    }
    for (ElementDefinition child : sd.getSnapshot().getElement()) {
        processElement(sheet, sd, child);
    }
    configureSheet(sheet, sd);
    return this;
}
Also used : StructureDefinitionMappingComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) Row(org.apache.poi.ss.usermodel.Row) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet)

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