Search in sources :

Example 51 with ElementDefinition

use of org.hl7.fhir.r4b.model.ElementDefinition in project kindling by HL7.

the class DictHTMLGenerator method invariants.

// 
// 
// for (String id : ids) {
// ElementDefinitionConstraintComponent inv = getConstraint(constraints, id);
// s.append("<tr><td><b title=\"Formal Invariant Identifier\">"+inv.getId()+"</b></td><td>"+presentLevel(inv)+"</td><td>(base)</td><td>"+Utilities.escapeXml(inv.getHuman())+"</td><td><span style=\"font-family: Courier New, monospace\">"+Utilities.escapeXml(inv.getExpression())+"</span>");
// if (inv.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-bestpractice"))
// s.append("<br/>This is (only) a best practice guideline because: <blockquote>"+page.processMarkdown("best practice guideline", inv.getExtensionString("http://hl7.org/fhir/StructureDefinition/elementdefinition-bestpractice-explanation"), prefix)+"</blockquote>");
// s.append("</td></tr>");
// }
// }
private String invariants(Map<String, Invariant> invariants, List<Invariant> stated) throws Exception {
    List<String> done = new ArrayList<String>();
    StringBuilder s = new StringBuilder();
    if (invariants.size() + stated.size() > 0) {
        s.append("<table class=\"dict\">\r\n");
        if (invariants.size() > 0) {
            s.append("<tr><td colspan=\"4\"><b>Defined on this element</b></td></tr>\r\n");
            List<String> ids = new ArrayList<String>();
            for (String id : invariants.keySet()) ids.add(id);
            Collections.sort(ids, new ConstraintsSorter());
            for (String i : ids) {
                Invariant inv = invariants.get(i);
                done.add(inv.getId());
                s.append("<tr><td width=\"60px\"><b title=\"Formal Invariant Identifier\">" + inv.getId() + "</b></td><td>" + presentLevel(inv) + "</td><td>" + Utilities.escapeXml(inv.getEnglish()) + "</td><td><span style=\"font-family: Courier New, monospace\">" + Utilities.escapeXml(inv.getExpression()) + "</span>");
                if (!Utilities.noString(inv.getExplanation()))
                    s.append("<br/>This is (only) a best practice guideline because: <blockquote>" + page.processMarkdown("best practice guideline", inv.getExplanation(), prefix) + "</blockquote>");
                s.append("</td></tr>");
            }
        }
        if (stated.size() > 0) {
            s.append("<tr><td colspan=\"4\"><b>Affect this element</b></td></tr>\r\n");
            boolean b = false;
            for (Invariant id : stated) {
                if (!done.contains(id.getId())) {
                    s.append("<tr><td width=\"60px\"><b title=\"Formal Invariant Identifier\">" + id.getId() + "</b></td><td>" + presentLevel(id) + "</td><td>" + Utilities.escapeXml(id.getEnglish()) + "</td><td><span style=\"font-family: Courier New, monospace\">" + Utilities.escapeXml(id.getExpression()) + "</span>");
                    if (!Utilities.noString(id.getExplanation()))
                        s.append("<br/>This is (only) a best practice guideline because: <blockquote>" + page.processMarkdown("best practice guideline", id.getExplanation(), prefix) + "</blockquote>");
                    s.append("</td></tr>");
                }
            }
        }
        s.append("</table>\r\n");
    }
    return s.toString();
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ArrayList(java.util.ArrayList)

Example 52 with ElementDefinition

use of org.hl7.fhir.r4b.model.ElementDefinition 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 53 with ElementDefinition

use of org.hl7.fhir.r4b.model.ElementDefinition in project org.hl7.fhir.core by hapifhir.

the class SpecDifferenceEvaluator method analyseTypes.

private void analyseTypes(JsonObject element, ElementDefinition rev, ElementDefinition orig) {
    JsonArray oa = new JsonArray();
    JsonArray ra = new JsonArray();
    if (rev.getType().size() == 1 && orig.getType().size() == 1) {
        String r = describeType(rev.getType().get(0));
        if (Utilities.noString(r) && Utilities.existsInList(rev.getId(), "Element.id", "Extension.url"))
            r = "string";
        String o = describeType(orig.getType().get(0));
        if (Utilities.noString(o) && Utilities.existsInList(orig.getId(), "Element.id", "Extension.url"))
            o = "string";
        if (!o.equals(r)) {
            oa.add(new JsonPrimitive(o));
            ra.add(new JsonPrimitive(r));
        }
    } else {
        for (TypeRefComponent tr : orig.getType()) {
            if (!hasType(rev.getType(), tr))
                oa.add(new JsonPrimitive(describeType(tr)));
        }
        for (TypeRefComponent tr : rev.getType()) {
            if (!hasType(orig.getType(), tr) && !isAbstractType(tr.getWorkingCode()))
                ra.add(new JsonPrimitive(describeType(tr)));
        }
        for (TypeRefComponent tr : rev.getType()) {
            TypeRefComponent tm = getType(rev.getType(), tr);
            if (tm != null) {
                compareParameters(element, tr, tm);
            }
        }
    }
    if (oa.size() > 0)
        element.add("removed-types", oa);
    if (ra.size() > 0)
        element.add("added-types", ra);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)

Example 54 with ElementDefinition

use of org.hl7.fhir.r4b.model.ElementDefinition in project org.hl7.fhir.core by hapifhir.

the class ExtensionDefinitionGenerator method buildExtensions.

private void buildExtensions(StructureDefinition type, List<StructureDefinition> list) throws FHIRException {
    for (ElementDefinition ed : type.getDifferential().getElement()) {
        if (ed.getPath().contains(".")) {
            if (!ed.getPath().endsWith(".extension") && !ed.getPath().endsWith(".modifierExtension")) {
                StructureDefinition ext = generateExtension(type, ed);
                if (ext != null) {
                    list.add(ext);
                    context.cacheResource(ext);
                }
            }
        }
    }
}
Also used : StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) ElementDefinition(org.hl7.fhir.r4.model.ElementDefinition)

Example 55 with ElementDefinition

use of org.hl7.fhir.r4b.model.ElementDefinition in project org.hl7.fhir.core by hapifhir.

the class SpecDifferenceEvaluator method compare.

private void compare(StructureDefinition orig, StructureDefinition rev) {
    moves.clear();
    XhtmlNode tr = tbl.addTag("tr").setAttribute("class", "diff-item");
    XhtmlNode left = tr.addTag("td").setAttribute("class", "diff-left");
    String link = linker == null ? null : linker.getLink(rev.getName());
    if (link != null)
        left.addTag("a").setAttribute("href", link).addText(rev.getName());
    else
        left.addText(rev.getName());
    XhtmlNode right = tr.addTag("td").setAttribute("class", "diff-right");
    // first, we must match revision elements to old elements
    boolean changed = false;
    if (!orig.getName().equals(rev.getName())) {
        changed = true;
        right.ul().li().addText("Name Changed from " + orig.getName() + " to " + rev.getName());
    }
    for (ElementDefinition ed : rev.getDifferential().getElement()) {
        ElementDefinition oed = getMatchingElement(rev.getName(), orig.getDifferential().getElement(), ed);
        if (oed != null) {
            ed.setUserData("match", oed);
            oed.setUserData("match", ed);
        }
    }
    for (ElementDefinition ed : rev.getDifferential().getElement()) {
        ElementDefinition oed = (ElementDefinition) ed.getUserData("match");
        if (oed == null) {
            changed = true;
            markNew(ed.getPath(), false, false, ed.getMin() > 0);
        } else
            changed = compareElement(ed, oed) || changed;
    }
    List<String> dels = new ArrayList<String>();
    for (ElementDefinition ed : orig.getDifferential().getElement()) {
        if (ed.getUserData("match") == null) {
            changed = true;
            boolean marked = false;
            for (String s : dels) if (ed.getPath().startsWith(s + "."))
                marked = true;
            if (!marked) {
                dels.add(ed.getPath());
                markDeleted(ed.getPath(), false);
            }
        }
    }
    if (!changed)
        right.ul().li().addText("No Changes");
    for (ElementDefinition ed : rev.getDifferential().getElement()) ed.clearUserData("match");
    for (ElementDefinition ed : orig.getDifferential().getElement()) ed.clearUserData("match");
}
Also used : XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

ArrayList (java.util.ArrayList)226 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)199 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)120 FHIRException (org.hl7.fhir.exceptions.FHIRException)116 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)92 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)91 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)85 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)82 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)68 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)60 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)57 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)51 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)50 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)46 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)44 ElementDefinition (org.hl7.fhir.dstu2016may.model.ElementDefinition)42 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)41 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)41 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)38 List (java.util.List)37