Search in sources :

Example 21 with Sheet

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

the class ReviewSpreadsheetGenerator method processRows.

private int processRows(HSSFWorkbook workbook, String path, StructureDefinition profile, List<ElementDefinition> list, int i, HSSFSheet sheet, String indent) throws FHIRException {
    ElementDefinition ed = list.get(i);
    HSSFFont font = workbook.createFont();
    font.setFontName("Calibri");
    HSSFCellStyle style = workbook.createCellStyle();
    style.setFont(font);
    while (i < list.size() && ed.getPath().startsWith(path + ".")) {
        HSSFRow row = sheet.createRow(sheet.getPhysicalNumberOfRows());
        int c = 0;
        HSSFRichTextString richString;
        if (ed.getType().size() == 0) {
            richString = new HSSFRichTextString(indent + ed.getPath().substring(path.length() + 1) + " [" + describeCardinality(ed) + "]");
        } else if (ed.getType().size() == 1) {
            richString = new HSSFRichTextString(indent + ed.getPath().substring(path.length() + 1) + " : " + ed.getType().get(0).getWorkingCode() + " [" + describeCardinality(ed) + "]");
            HSSFFont fontBlue = workbook.createFont();
            fontBlue.setFontName("Calibri");
            fontBlue.setColor(IndexedColors.DARK_BLUE.getIndex());
            richString.applyFont(indent.length() + ed.getPath().length() - (path.length() + 1), richString.length() - describeCardinality(ed).length() - 3, fontBlue);
        } else {
            richString = new HSSFRichTextString(indent + ed.getPath().substring(path.length() + 1) + " : * [" + describeCardinality(ed) + "]");
        }
        HSSFCell cell = row.createCell(c++);
        cell.setCellStyle(style);
        cell.setCellValue(richString);
        if (ed.getType().size() == 0) {
            cell = row.createCell(c++);
            cell.setCellStyle(style);
            cell.setCellValue(ed.getSliceName());
            cell = row.createCell(c++);
            cell.setCellStyle(style);
            cell.setCellValue("");
            i++;
            if (i < list.size())
                i = processRows(workbook, ed.getPath(), profile, list, i, sheet, indent + "  ");
        } else if (ed.getType().size() == 1) {
            cell = row.createCell(c++);
            cell.setCellStyle(style);
            if (ed.getType().get(0).hasProfile())
                cell.setCellValue(ed.getType().get(0).getProfile().get(0).getValue());
            if (ed.getType().get(0).hasTargetProfile())
                cell.setCellValue(ed.getType().get(0).getTargetProfile().get(0).getValue());
            cell = row.createCell(c++);
            cell.setCellStyle(style);
            cell.setCellValue(describeBinding(profile, ed));
            i++;
        } else {
            cell = row.createCell(c++);
            cell.setCellStyle(style);
            cell.setCellValue(ed.getSliceName());
            cell = row.createCell(c++);
            cell.setCellStyle(style);
            cell.setCellValue(describeBinding(profile, ed));
            i++;
        }
        cell = row.createCell(c++);
        cell.setCellStyle(style);
        cell = row.createCell(c++);
        cell.setCellStyle(style);
        cell.setCellValue("");
        if (i < list.size())
            ed = list.get(i);
    }
    return i;
}
Also used : HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFFont(org.apache.poi.hssf.usermodel.HSSFFont) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition)

Example 22 with Sheet

use of org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet in project quality-measure-and-cohort-service by Alvearie.

the class ValueSetUtil method createArtifact.

public static ValueSetArtifact createArtifact(InputStream is, Map<String, String> customCodeSystem) throws IOException {
    XSSFSheet informationSheet;
    try (XSSFWorkbook wb = new XSSFWorkbook(is)) {
        informationSheet = wb.getSheetAt(wb.getSheetIndex("Expansion List"));
    } catch (IllegalArgumentException e) {
        throw new RuntimeException("Spreadsheet is missing required sheet \"Expansion List\"", e);
    }
    ValueSet valueSet = new ValueSet();
    boolean inCodesSection = false;
    valueSet.setStatus(Enumerations.PublicationStatus.ACTIVE);
    HashMap<CodeSystemKey, List<ValueSet.ConceptReferenceComponent>> codeSystemToCodes = new HashMap<>();
    String url = "http://cts.nlm.nih.gov/fhir/ValueSet/";
    String identifier = null;
    for (Row currentRow : informationSheet) {
        String code = currentRow.getCell(0) == null ? "" : currentRow.getCell(0).getStringCellValue();
        if (!code.equals("") && currentRow.getCell(1) != null && !inCodesSection) {
            String value;
            switch(currentRow.getCell(1).getCellType()) {
                case NUMERIC:
                    value = Double.toString(currentRow.getCell(1).getNumericCellValue());
                    break;
                case STRING:
                    value = currentRow.getCell(1).getStringCellValue();
                    break;
                default:
                    throw new RuntimeException("Cell type does not match either String or Numeric for key " + code);
            }
            switch(currentRow.getCell(0).getStringCellValue().toLowerCase()) {
                case "value set name":
                    valueSet.setName(value);
                    valueSet.setTitle(value);
                    break;
                case "id":
                    valueSet.setId(value);
                    identifier = value;
                    break;
                case "oid":
                    if (valueSet.getId() == null) {
                        valueSet.setId(value);
                        identifier = value;
                    }
                    break;
                case "url":
                    // fallthrough
                    url = value.endsWith("/") ? value : value + "/";
                case "definition version":
                    valueSet.setVersion(value);
                    break;
                case "code":
                    inCodesSection = true;
                    break;
                default:
                    break;
            }
        } else if (inCodesSection) {
            String display = currentRow.getCell(1).getStringCellValue();
            String codeSystemEntry = currentRow.getCell(2).getStringCellValue();
            String codeSystemVersion = currentRow.getCell(3).getStringCellValue();
            String codeSystem;
            if (codeSystemEntry.startsWith("http://") || codeSystemEntry.startsWith("https://")) {
                codeSystem = codeSystemEntry;
            } else if (customCodeSystem != null && customCodeSystem.get(codeSystemEntry) != null) {
                codeSystem = customCodeSystem.get(codeSystemEntry);
            } else {
                codeSystem = CodeSystemLookup.getUrlFromName(codeSystemEntry);
            }
            if (codeSystem == null) {
                throw new IllegalArgumentException("Unmatched Code System! " + codeSystemEntry + " not found!");
            }
            ValueSet.ConceptReferenceComponent concept = new ValueSet.ConceptReferenceComponent();
            concept.setCode(code);
            concept.setDisplay(display);
            List<ValueSet.ConceptReferenceComponent> conceptsSoFar = codeSystemToCodes.computeIfAbsent(new CodeSystemKey(codeSystem, codeSystemVersion), x -> new ArrayList<>());
            conceptsSoFar.add(concept);
        }
    }
    if (identifier == null || identifier.equals("")) {
        throw new RuntimeException("There must be an Identifier specified! Please populate the ID field");
    }
    valueSet.setUrl(url + identifier);
    valueSet.setId(identifier);
    ValueSet.ValueSetComposeComponent compose = new ValueSet.ValueSetComposeComponent();
    for (Entry<CodeSystemKey, List<ConceptReferenceComponent>> singleInclude : codeSystemToCodes.entrySet()) {
        ValueSet.ConceptSetComponent component = new ValueSet.ConceptSetComponent();
        component.setSystem(singleInclude.getKey().getCodeSystem());
        component.setVersion(singleInclude.getKey().getCodeSystemVersion());
        component.setConcept(singleInclude.getValue());
        compose.addInclude(component);
    }
    valueSet.setCompose(compose);
    ValueSetArtifact artifact = new ValueSetArtifact();
    artifact.setName(valueSet.getName());
    artifact.setFhirResource(valueSet);
    artifact.setUrl(valueSet.getUrl());
    return artifact;
}
Also used : ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent) Enumerations(org.hl7.fhir.r4.model.Enumerations) IOException(java.io.IOException) HashMap(java.util.HashMap) ValueSet(org.hl7.fhir.r4.model.ValueSet) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) List(java.util.List) Map(java.util.Map) Entry(java.util.Map.Entry) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) Row(org.apache.poi.ss.usermodel.Row) Bundle(org.hl7.fhir.r4.model.Bundle) BufferedReader(java.io.BufferedReader) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) InputStream(java.io.InputStream) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) ArrayList(java.util.ArrayList) List(java.util.List) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent) Row(org.apache.poi.ss.usermodel.Row) ValueSet(org.hl7.fhir.r4.model.ValueSet)

Example 23 with Sheet

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

the class StructureDefinitionSpreadsheetGenerator method processElement.

public void processElement(Sheet sheet, StructureDefinition sd, ElementDefinition ed) throws Exception {
    Row row = sheet.createRow(sheet.getLastRowNum() + 1);
    int i = 0;
    addCell(row, i++, ed.getPath(), styles.get("body"));
    addCell(row, i++, ed.getSliceName());
    addCell(row, i++, itemList(ed.getAlias()));
    addCell(row, i++, ed.getLabel());
    addCell(row, i++, ed.getMin());
    addCell(row, i++, ed.getMax());
    addCell(row, i++, ed.getMustSupport() ? "Y" : "");
    addCell(row, i++, ed.getIsModifier() ? "Y" : "");
    addCell(row, i++, ed.getIsSummary() ? "Y" : "");
    addCell(row, i++, itemList(ed.getType()));
    addCell(row, i++, ed.getShort());
    addCell(row, i++, ed.getDefinition());
    addCell(row, i++, ed.getComment());
    addCell(row, i++, ed.getRequirements());
    addCell(row, i++, ed.getDefaultValue() != null ? renderType(ed.getDefaultValue()) : "");
    addCell(row, i++, ed.getMeaningWhenMissing());
    addCell(row, i++, ed.hasFixed() ? renderType(ed.getFixed()) : "");
    addCell(row, i++, ed.hasPattern() ? renderType(ed.getPattern()) : "");
    // todo...?
    addCell(row, i++, ed.hasExample() ? renderType(ed.getExample().get(0).getValue()) : "");
    addCell(row, i++, ed.hasMinValue() ? renderType(ed.getMinValue()) : "");
    addCell(row, i++, ed.hasMaxValue() ? renderType(ed.getMaxValue()) : "");
    addCell(row, i++, (ed.hasMaxLength() ? Integer.toString(ed.getMaxLength()) : ""));
    if (ed.hasBinding()) {
        addCell(row, i++, ed.getBinding().getStrength() != null ? ed.getBinding().getStrength().toCode() : "");
        addCell(row, i++, ed.getBinding().getDescription());
        if (ed.getBinding().getValueSet() == null)
            addCell(row, i++, "");
        else
            addCell(row, i++, ed.getBinding().getValueSet());
    } else {
        addCell(row, i++, "");
        addCell(row, i++, "");
        addCell(row, i++, "");
    }
    addCell(row, i++, itemList(ed.getCode()));
    if (ed.hasSlicing()) {
        addCell(row, i++, itemList(ed.getSlicing().getDiscriminator()));
        addCell(row, i++, ed.getSlicing().getDescription());
        addCell(row, i++, ed.getSlicing().getOrdered());
        addCell(row, i++, ed.getSlicing().getRules() != null ? ed.getSlicing().getRules().toCode() : "");
    } else {
        addCell(row, i++, "");
        addCell(row, i++, "");
        addCell(row, i++, "");
        addCell(row, i++, "");
    }
    if (ed.getBase() != null) {
        addCell(row, i++, ed.getBase().getPath());
        addCell(row, i++, ed.getBase().getMin());
        addCell(row, i++, ed.getBase().getMax());
    } else {
        addCell(row, i++, "");
        addCell(row, i++, "");
        addCell(row, i++, "");
    }
    addCell(row, i++, itemList(ed.getCondition()));
    addCell(row, i++, itemList(ed.getConstraint()));
    for (StructureDefinitionMappingComponent mapKey : sd.getMapping()) {
        String mapString = "";
        for (ElementDefinitionMappingComponent map : ed.getMapping()) {
            if (map.getIdentity().equals(mapKey.getIdentity()))
                mapString = map.getMap();
        }
        addCell(row, i++, mapString);
    }
}
Also used : StructureDefinitionMappingComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) Row(org.apache.poi.ss.usermodel.Row) ElementDefinitionMappingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionMappingComponent)

Example 24 with Sheet

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

the class StructureDefinitionSpreadsheetGenerator method addStructureDefinitionMetadata.

private void addStructureDefinitionMetadata(Sheet sheet, StructureDefinition sd) {
    for (Coding k : sd.getKeyword()) {
        addMetadataRow(sheet, "Keyword", dr.display(k));
    }
    addMetadataRow(sheet, "FHIR Version", sd.getFhirVersionElement().asStringValue());
    addMetadataRow(sheet, "Kind", sd.getKindElement().asStringValue());
    addMetadataRow(sheet, "Type", sd.getType());
    addMetadataRow(sheet, "Base Definition", sd.getBaseDefinition());
    addMetadataRow(sheet, "Abstract", sd.getAbstractElement().asStringValue());
    addMetadataRow(sheet, "Derivation", sd.getDerivationElement().asStringValue());
    for (StructureDefinitionContextComponent k : sd.getContext()) {
        addMetadataRow(sheet, "Context", k.getTypeElement().asStringValue() + ":" + k.getExpression());
    }
    for (StringType k : sd.getContextInvariant()) {
        addMetadataRow(sheet, "Context Inv.", k.getValue());
    }
}
Also used : StructureDefinitionContextComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent) Coding(org.hl7.fhir.r5.model.Coding) StringType(org.hl7.fhir.r5.model.StringType)

Example 25 with Sheet

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

the class StructureDefinitionSpreadsheetGenerator method configureSheet.

public void configureSheet(Sheet sheet, StructureDefinition sd) throws IOException {
    for (int i = 0; i < 34; i++) {
        sheet.autoSizeColumn(i);
    }
    sheet.setColumnHidden(2, true);
    sheet.setColumnHidden(3, true);
    sheet.setColumnHidden(30, true);
    sheet.setColumnHidden(31, true);
    sheet.setColumnHidden(32, true);
    sheet.setColumnWidth(9, columnPixels(20));
    sheet.setColumnWidth(11, columnPixels(100));
    sheet.setColumnWidth(12, columnPixels(100));
    sheet.setColumnWidth(13, columnPixels(100));
    sheet.setColumnWidth(15, columnPixels(20));
    sheet.setColumnWidth(16, columnPixels(20));
    sheet.setColumnWidth(17, columnPixels(20));
    sheet.setColumnWidth(18, columnPixels(20));
    sheet.setColumnWidth(34, columnPixels(100));
    int i = titles.length - 1;
    for (StructureDefinitionMappingComponent map : sd.getMapping()) {
        i++;
        sheet.setColumnWidth(i, columnPixels(50));
        sheet.autoSizeColumn(i);
    // sheet.setColumnHidden(i,  true);
    }
    sheet.createFreezePane(2, 1);
    if (hideMustSupportFalse) {
        SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
        String address = "A2:AI" + Math.max(Integer.valueOf(sheet.getLastRowNum()), 2);
        CellRangeAddress[] regions = { CellRangeAddress.valueOf(address) };
        ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule("$G2<>\"Y\"");
        PatternFormatting fill1 = rule1.createPatternFormatting();
        fill1.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.index);
        fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
        ConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule("$Q2<>\"\"");
        FontFormatting font = rule2.createFontFormatting();
        font.setFontColorIndex(IndexedColors.GREY_25_PERCENT.index);
        font.setFontStyle(true, false);
        sheetCF.addConditionalFormatting(regions, rule1, rule2);
        sheet.setAutoFilter(new CellRangeAddress(0, sheet.getLastRowNum(), 0, titles.length + sd.getMapping().size() - 1));
        XSSFSheet xSheet = (XSSFSheet) sheet;
        CTAutoFilter sheetFilter = xSheet.getCTWorksheet().getAutoFilter();
        CTFilterColumn filterColumn1 = sheetFilter.addNewFilterColumn();
        filterColumn1.setColId(6);
        CTCustomFilters filters = filterColumn1.addNewCustomFilters();
        CTCustomFilter filter1 = filters.addNewCustomFilter();
        filter1.setOperator(STFilterOperator.NOT_EQUAL);
        filter1.setVal(" ");
        CTFilterColumn filterColumn2 = sheetFilter.addNewFilterColumn();
        filterColumn2.setColId(26);
        CTFilters filters2 = filterColumn2.addNewFilters();
        filters2.setBlank(true);
        // We have to apply the filter ourselves by hiding the rows:
        for (Row row : sheet) {
            if (row.getRowNum() > 0 && (!row.getCell(6).getStringCellValue().equals("Y") || !row.getCell(26).getStringCellValue().isEmpty())) {
                ((XSSFRow) row).getCTRow().setHidden(true);
            }
        }
    }
    sheet.setActiveCell(new CellAddress(sheet.getRow(1).getCell(0)));
}
Also used : StructureDefinitionMappingComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent) CTAutoFilter(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTAutoFilter) ConditionalFormattingRule(org.apache.poi.ss.usermodel.ConditionalFormattingRule) FontFormatting(org.apache.poi.ss.usermodel.FontFormatting) PatternFormatting(org.apache.poi.ss.usermodel.PatternFormatting) CellAddress(org.apache.poi.ss.util.CellAddress) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) CTFilterColumn(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFilterColumn) SheetConditionalFormatting(org.apache.poi.ss.usermodel.SheetConditionalFormatting) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) Row(org.apache.poi.ss.usermodel.Row) CTCustomFilters(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCustomFilters) CTCustomFilter(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCustomFilter) CTFilters(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFilters)

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