Search in sources :

Example 1 with Cell

use of org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell in project kindling by HL7.

the class PageProcessor method generateToc.

private String generateToc() throws Exception {
    // return breadCrumbManager.makeToc();
    List<String> entries = new ArrayList<String>();
    entries.addAll(toc.keySet());
    Collections.sort(entries, new SectionSorter());
    Set<String> pages = new HashSet<String>();
    HierarchicalTableGenerator gen = new HierarchicalTableGenerator(folders.dstDir, false, true);
    TableModel model = gen.new TableModel("toc", true);
    model.getTitles().add(gen.new Title(null, model.getDocoRef(), "Table of Contents", "Table of Contents", null, 0));
    Deque<TocItem> stack = new ArrayDeque<TocItem>();
    for (String s : entries) {
        TocEntry t = toc.get(s);
        if (!t.isIg() && !s.startsWith("?")) {
            String nd = s;
            while (nd.endsWith(".0")) nd = nd.substring(0, nd.length() - 2);
            int d = Utilities.charCount(nd, '.');
            if (d < 4 && !pages.contains(t.getLink())) {
                String np = getNormativePackageForPage(t.getLink());
                pages.add(t.getLink());
                while (!stack.isEmpty() && stack.getFirst().depth >= d) stack.pop();
                Row row = gen.new Row();
                row.setIcon("icon_page.gif", null);
                String td = t.getText();
                if (!stack.isEmpty()) {
                    if (td.startsWith(stack.getFirst().entry.getText() + " - "))
                        td = td.substring(stack.getFirst().entry.getText().length() + 3);
                    else if (td.startsWith(stack.getFirst().entry.getText()))
                        td = td.substring(stack.getFirst().entry.getText().length());
                }
                Cell cell = gen.new Cell(null, t.getLink(), nd + " " + td, t.getText() + " ", null);
                row.getCells().add(cell);
                if (np != null) {
                    cell.addPiece(gen.new Piece(null, " ", null));
                    cell.addPiece(gen.new Piece("versions.html#std-process", "basic".equals(np) ? "(Normative)" : "(Normative / " + Utilities.capitalize(np) + ")", null).addStyle("color: #008000"));
                    if (np.equals("infrastructure"))
                        row.setIcon("icon_page_n_i.gif", null);
                    else if (np.equals("conformance"))
                        row.setIcon("icon_page_n_c.gif", null);
                    else if (np.equals("patient"))
                        row.setIcon("icon_page_n_p.gif", null);
                    else if (np.equals("observation"))
                        row.setIcon("icon_page_n_o.gif", null);
                    else
                        row.setIcon("icon_page_n.gif", null);
                } else {
                    cell.addPiece(gen.new Piece(null, " ", null));
                    cell.addPiece(gen.new Piece("versions.html#std-process", "(Trial Use)", null).addStyle("color: #b3b3b3"));
                }
                if (stack.isEmpty())
                    model.getRows().add(row);
                else
                    stack.getFirst().row.getSubRows().add(row);
                stack.push(new TocItem(t, row, d));
            }
        }
    }
    return new XhtmlComposer(XhtmlComposer.HTML).compose(gen.generate(model, "", 0, null));
}
Also used : ArrayList(java.util.ArrayList) HierarchicalTableGenerator(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator) ArrayDeque(java.util.ArrayDeque) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) TableModel(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel) HashSet(java.util.HashSet)

Example 2 with Cell

use of org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell in project kindling by HL7.

the class ImplementationGuideDefn method addPage.

private void addPage(HierarchicalTableGenerator gen, List<Row> rows, ImplementationGuideDefinitionPageComponent page) throws FHIRException {
    Row row = gen.new Row();
    rows.add(row);
    row.setIcon(getIcon(IgParser.getKind(page)), IgParser.getKind(page).getDisplay());
    String ndx = page.getUserString(ToolResourceUtilities.NAME_PAGE_INDEX);
    if (ndx == null)
        ndx = "";
    else
        ndx = ndx + " ";
    row.getCells().add(gen.new Cell("", page.getNameUrlType().getValue(), ndx + page.getTitle(), null, null));
    for (ImplementationGuideDefinitionPageComponent p : page.getPage()) {
        addPage(gen, row.getSubRows(), p);
    }
}
Also used : Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) ImplementationGuideDefinitionPageComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionPageComponent)

Example 3 with Cell

use of org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell in project kindling by HL7.

the class ResourceDependencyGenerator method addBindingToAnalysis.

private void addBindingToAnalysis(HierarchicalTableGenerator gen, Row row, Cell dc, boolean req, StandardsStatus elementStatus, BindingSpecification binding) throws FHIRException {
    String tgtFMM = null;
    StandardsStatus tgtSS = null;
    ValueSet vs = binding.getValueSet();
    if (vs != null) {
        tgtFMM = ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_FMM_LEVEL);
        tgtSS = ToolingExtensions.getStandardsStatus(vs);
    } else if (Utilities.existsInList(binding.getReference(), "http://www.rfc-editor.org/bcp/bcp13.txt")) {
        tgtFMM = "5";
        tgtSS = StandardsStatus.EXTERNAL;
    }
    if (elementStatus == null)
        elementStatus = sstatus;
    if (tgtFMM == null)
        addError(gen, row, dc, "Binding Error: Unable to resolve vs '" + binding.getReference() + "' to check dependencies", null);
    else {
        boolean ok = elementStatus.canDependOn(tgtSS);
        if (ok)
            ok = fmm.compareTo(tgtFMM) <= 0;
        if (ok)
            // addInfo(gen, row, dc, "Binding OK (ValueSet = FMM"+tgtFMM+"-"+tgtSS.toDisplay()+" vs. Element = FMM"+fmm+"-"+elementStatus.toDisplay()+")", null);
            ;
        else
            addError(gen, row, dc, "Binding Error: (ValueSet = FMM" + tgtFMM + "-" + tgtSS.toDisplay() + " vs. Element = FMM" + fmm + "-" + elementStatus.toDisplay() + ")", vs.getUserString("path"));
    }
}
Also used : StandardsStatus(org.hl7.fhir.utilities.StandardsStatus) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 4 with Cell

use of org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell 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 5 with Cell

use of org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell 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)

Aggregations

Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)101 Row (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row)77 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)61 ArrayList (java.util.ArrayList)18 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)11 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)11 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)8 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)8 List (java.util.List)7 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)7 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)7 HierarchicalTableGenerator (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator)7 TableModel (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel)7 FHIRException (org.hl7.fhir.exceptions.FHIRException)6 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 ElementDefinition (org.hl7.fhir.dstu2016may.model.ElementDefinition)5 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)5 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)4 Extension (org.hl7.fhir.r5.model.Extension)4