Search in sources :

Example 31 with StructureDefinitionMappingComponent

use of org.hl7.fhir.dstu3.model.StructureDefinition.StructureDefinitionMappingComponent 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.r4b.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.r4b.model.ElementDefinition) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet)

Example 32 with StructureDefinitionMappingComponent

use of org.hl7.fhir.dstu3.model.StructureDefinition.StructureDefinitionMappingComponent in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method generateGridDescription.

private Cell generateGridDescription(HierarchicalTableGenerator gen, Row row, ElementDefinition definition, ElementDefinition fallback, boolean used, String baseURL, String url, StructureDefinition profile, String corePath, String imagePath, boolean root, ElementDefinition valueDefn) throws IOException, FHIRException {
    Cell c = gen.new Cell();
    row.getCells().add(c);
    if (used) {
        if (definition.hasContentReference()) {
            ElementInStructure ed = getElementByName(profile.getSnapshot().getElement(), definition.getContentReference(), profile);
            if (ed == null)
                c.getPieces().add(gen.new Piece(null, "Unknown reference to " + definition.getContentReference(), null));
            else {
                if (ed.getSource() == profile) {
                    c.getPieces().add(gen.new Piece("#" + ed.getElement().getPath(), "See " + ed.getElement().getPath(), null));
                } else {
                    c.getPieces().add(gen.new Piece(ed.getSource().getUserData("path") + "#" + ed.getElement().getPath(), "See " + ed.getSource().getType() + "." + ed.getElement().getPath(), null));
                }
            }
        }
        if (definition.getPath().endsWith("url") && definition.hasFixed()) {
            c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "\"" + buildJson(definition.getFixed()) + "\"", null).addStyle("color: darkgreen")));
        } else {
            if (url != null) {
                if (!c.getPieces().isEmpty())
                    c.addPiece(gen.new Piece("br"));
                String fullUrl = url.startsWith("#") ? baseURL + url : url;
                StructureDefinition ed = context.fetchResource(StructureDefinition.class, url);
                String ref = null;
                if (ed != null) {
                    String p = ed.getUserString("path");
                    if (p != null) {
                        ref = p.startsWith("http:") || igmode ? p : Utilities.pathURL(corePath, p);
                    }
                }
                c.getPieces().add(gen.new Piece(null, "URL: ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(ref, fullUrl, null));
            }
            if (definition.hasSlicing()) {
                if (!c.getPieces().isEmpty()) {
                    c.addPiece(gen.new Piece("br"));
                }
                c.getPieces().add(gen.new Piece(null, "Slice: ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(null, describeSlice(definition.getSlicing()), null));
            }
            if (definition != null) {
                ElementDefinitionBindingComponent binding = null;
                if (valueDefn != null && valueDefn.hasBinding() && !valueDefn.getBinding().isEmpty())
                    binding = valueDefn.getBinding();
                else if (definition.hasBinding())
                    binding = definition.getBinding();
                if (binding != null && !binding.isEmpty()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    BindingResolution br = pkp.resolveBinding(profile, binding, definition.getPath());
                    c.getPieces().add(checkForNoChange(binding, gen.new Piece(null, "Binding: ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(binding, gen.new Piece(br.url == null ? null : Utilities.isAbsoluteUrl(br.url) || !pkp.prependLinks() ? br.url : corePath + br.url, br.display, null)));
                    if (binding.hasStrength()) {
                        c.getPieces().add(checkForNoChange(binding, gen.new Piece(null, " (", null)));
                        c.getPieces().add(checkForNoChange(binding, gen.new Piece(corePath + "terminologies.html#" + binding.getStrength().toCode(), binding.getStrength().toCode(), binding.getStrength().getDefinition())));
                        c.getPieces().add(gen.new Piece(null, ")", null));
                    }
                    if (binding.hasDescription() && MarkDownProcessor.isSimpleMarkdown(binding.getDescription())) {
                        c.getPieces().add(gen.new Piece(null, ": ", null));
                        c.addMarkdownNoPara(PublicationHacker.fixBindingDescriptions(context, binding.getDescriptionElement()).asStringValue());
                    }
                }
                for (ElementDefinitionConstraintComponent inv : definition.getConstraint()) {
                    if (!c.getPieces().isEmpty()) {
                        c.addPiece(gen.new Piece("br"));
                    }
                    c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, inv.getKey() + ": ", null).addStyle("font-weight:bold")));
                    if (inv.getHumanElement().hasExtension("http://hl7.org/fhir/StructureDefinition/rendering-markdown")) {
                        c.addMarkdown(inv.getHumanElement().getExtensionString("http://hl7.org/fhir/StructureDefinition/rendering-markdown"));
                    } else {
                        c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, inv.getHuman(), null)));
                    }
                }
                if (definition.hasFixed()) {
                    if (!c.getPieces().isEmpty()) {
                        c.addPiece(gen.new Piece("br"));
                    }
                    c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "Fixed Value: ", null).addStyle("font-weight:bold")));
                    String s = buildJson(definition.getFixed());
                    String link = null;
                    if (Utilities.isAbsoluteUrl(s))
                        link = pkp.getLinkForUrl(corePath, s);
                    c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(link, s, null).addStyle("color: darkgreen")));
                } else if (definition.hasPattern()) {
                    if (!c.getPieces().isEmpty()) {
                        c.addPiece(gen.new Piece("br"));
                    }
                    c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, "Required Pattern: ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, buildJson(definition.getPattern()), null).addStyle("color: darkgreen")));
                } else if (definition.hasExample()) {
                    for (ElementDefinitionExampleComponent ex : definition.getExample()) {
                        if (!c.getPieces().isEmpty()) {
                            c.addPiece(gen.new Piece("br"));
                        }
                        c.getPieces().add(checkForNoChange(ex, gen.new Piece(null, "Example'" + ("".equals("General") ? "" : " " + ex.getLabel() + "'") + ": ", null).addStyle("font-weight:bold")));
                        c.getPieces().add(checkForNoChange(ex, gen.new Piece(null, buildJson(ex.getValue()), null).addStyle("color: darkgreen")));
                    }
                }
                if (definition.hasMaxLength() && definition.getMaxLength() != 0) {
                    if (!c.getPieces().isEmpty()) {
                        c.addPiece(gen.new Piece("br"));
                    }
                    c.getPieces().add(checkForNoChange(definition.getMaxLengthElement(), gen.new Piece(null, "Max Length: ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(definition.getMaxLengthElement(), gen.new Piece(null, Integer.toString(definition.getMaxLength()), null).addStyle("color: darkgreen")));
                }
                if (profile != null) {
                    for (StructureDefinitionMappingComponent md : profile.getMapping()) {
                        if (md.hasExtension(ToolingExtensions.EXT_TABLE_NAME)) {
                            ElementDefinitionMappingComponent map = null;
                            for (ElementDefinitionMappingComponent m : definition.getMapping()) if (m.getIdentity().equals(md.getIdentity()))
                                map = m;
                            if (map != null) {
                                for (int i = 0; i < definition.getMapping().size(); i++) {
                                    c.addPiece(gen.new Piece("br"));
                                    c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(md, ToolingExtensions.EXT_TABLE_NAME) + ": " + map.getMap(), null));
                                }
                            }
                        }
                    }
                }
                if (definition.hasDefinition()) {
                    if (!c.getPieces().isEmpty()) {
                        c.addPiece(gen.new Piece("br"));
                    }
                    c.getPieces().add(gen.new Piece(null, "Definition: ", null).addStyle("font-weight:bold"));
                    c.addPiece(gen.new Piece("br"));
                    c.addMarkdown(definition.getDefinition());
                // c.getPieces().add(checkForNoChange(definition.getCommentElement(), gen.new Piece(null, definition.getComment(), null)));
                }
                if (definition.getComment() != null) {
                    if (!c.getPieces().isEmpty()) {
                        c.addPiece(gen.new Piece("br"));
                    }
                    c.getPieces().add(gen.new Piece(null, "Comments: ", null).addStyle("font-weight:bold"));
                    c.addPiece(gen.new Piece("br"));
                    c.addMarkdown(definition.getComment());
                // c.getPieces().add(checkForNoChange(definition.getCommentElement(), gen.new Piece(null, definition.getComment(), null)));
                }
            }
        }
    }
    return c;
}
Also used : ElementDefinitionExampleComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionExampleComponent) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) BindingResolution(org.hl7.fhir.r5.conformance.ProfileUtilities.ProfileKnowledgeProvider.BindingResolution) StructureDefinitionMappingComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) ElementDefinitionBindingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent) ElementDefinitionMappingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionMappingComponent)

Aggregations

StructureDefinitionMappingComponent (org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent)14 Row (org.apache.poi.ss.usermodel.Row)10 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)10 StructureDefinitionMappingComponent (org.hl7.fhir.r4b.model.StructureDefinition.StructureDefinitionMappingComponent)8 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)8 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)8 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)6 ElementDefinitionMappingComponent (org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionMappingComponent)6 StructureDefinitionMappingComponent (org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionMappingComponent)5 ElementDefinitionMappingComponent (org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionMappingComponent)5 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)5 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 CellAddress (org.apache.poi.ss.util.CellAddress)4 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)4 ElementDefinitionMappingComponent (org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionMappingComponent)4 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)4 CTAutoFilter (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTAutoFilter)4