Search in sources :

Example 16 with CodeSystemComparison

use of org.hl7.fhir.r4b.comparison.CodeSystemComparer.CodeSystemComparison in project org.hl7.fhir.core by hapifhir.

the class CodeSystemComparer method compareConcepts.

private void compareConcepts(List<ConceptDefinitionComponent> left, List<ConceptDefinitionComponent> right, StructuralMatch<ConceptDefinitionComponent> combined, List<ConceptDefinitionComponent> union, List<ConceptDefinitionComponent> intersection, CodeSystem csU, CodeSystem csI, CodeSystemComparison res, String path) {
    List<ConceptDefinitionComponent> matchR = new ArrayList<>();
    for (ConceptDefinitionComponent l : left) {
        ConceptDefinitionComponent r = findInList(right, l);
        if (r == null) {
            union.add(l);
            combined.getChildren().add(new StructuralMatch<CodeSystem.ConceptDefinitionComponent>(l, vmI(IssueSeverity.INFORMATION, "Removed this concept", path)));
        } else {
            matchR.add(r);
            ConceptDefinitionComponent cdM = merge(l, r, csU.getProperty(), res);
            ConceptDefinitionComponent cdI = intersect(l, r, res);
            union.add(cdM);
            intersection.add(cdI);
            StructuralMatch<ConceptDefinitionComponent> sm = new StructuralMatch<CodeSystem.ConceptDefinitionComponent>(l, r);
            compare(sm.getMessages(), l, r, path + ".where(code='" + l.getCode() + "')", res);
            combined.getChildren().add(sm);
            compareConcepts(l.getConcept(), r.getConcept(), sm, cdM.getConcept(), cdI.getConcept(), csU, csI, res, path + ".where(code='" + l.getCode() + "').concept");
        }
    }
    for (ConceptDefinitionComponent r : right) {
        if (!matchR.contains(r)) {
            union.add(r);
            combined.getChildren().add(new StructuralMatch<CodeSystem.ConceptDefinitionComponent>(vmI(IssueSeverity.INFORMATION, "Added this concept", path), r));
        }
    }
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent) ArrayList(java.util.ArrayList) CodeSystem(org.hl7.fhir.r4b.model.CodeSystem)

Example 17 with CodeSystemComparison

use of org.hl7.fhir.r4b.comparison.CodeSystemComparer.CodeSystemComparison in project org.hl7.fhir.core by hapifhir.

the class CodeSystemComparer method renderConcepts.

public XhtmlNode renderConcepts(CodeSystemComparison comparison, String id, String prefix) throws FHIRException, IOException {
    // columns: code, display (left|right), properties (left|right)
    HierarchicalTableGenerator gen = new HierarchicalTableGenerator(Utilities.path("[tmp]", "compare"), false);
    TableModel model = gen.new TableModel(id, true);
    model.setAlternating(true);
    model.getTitles().add(gen.new Title(null, null, "Code", "The code for the concept", null, 100));
    model.getTitles().add(gen.new Title(null, null, "Display", "The display for the concept", null, 200, 2));
    for (PropertyComponent p : comparison.getUnion().getProperty()) {
        model.getTitles().add(gen.new Title(null, null, p.getCode(), p.getDescription(), null, 100, 2));
    }
    model.getTitles().add(gen.new Title(null, null, "Comments", "Additional information about the comparison", null, 200));
    for (StructuralMatch<ConceptDefinitionComponent> t : comparison.getCombined().getChildren()) {
        addRow(gen, model.getRows(), t, comparison);
    }
    return gen.generate(model, prefix, 0, null);
}
Also used : PropertyComponent(org.hl7.fhir.r5.model.CodeSystem.PropertyComponent) ConceptPropertyComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptPropertyComponent) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) HierarchicalTableGenerator(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator) TableModel(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel)

Example 18 with CodeSystemComparison

use of org.hl7.fhir.r4b.comparison.CodeSystemComparer.CodeSystemComparison in project org.hl7.fhir.core by hapifhir.

the class CodeSystemComparer method getProp.

public ConceptPropertyComponent getProp(ConceptDefinitionComponent cd, PropertyComponent p, boolean right, CodeSystemComparison comp) {
    String c = p.getCode();
    if (right) {
        c = comp.getPropMap().get(c);
    }
    ConceptPropertyComponent cp = null;
    if (cd != null) {
        for (ConceptPropertyComponent t : cd.getProperty()) {
            if (t.hasCode() && t.getCode().equals(c)) {
                cp = t;
            }
        }
    }
    return cp;
}
Also used : ConceptPropertyComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptPropertyComponent)

Example 19 with CodeSystemComparison

use of org.hl7.fhir.r4b.comparison.CodeSystemComparer.CodeSystemComparison in project org.hl7.fhir.core by hapifhir.

the class CodeSystemComparer method mergeProps.

private void mergeProps(ConceptDefinitionComponent cd, ConceptDefinitionComponent l, ConceptDefinitionComponent r, List<PropertyComponent> destProps, CodeSystemComparison res) {
    List<ConceptPropertyComponent> matchR = new ArrayList<>();
    for (ConceptPropertyComponent lp : l.getProperty()) {
        ConceptPropertyComponent rp = findRightProp(r.getProperty(), lp, res);
        if (rp == null) {
            cd.getProperty().add(lp);
        } else {
            matchR.add(rp);
            cd.getProperty().add(lp);
            if (lp.getValue().equalsDeep(rp.getValue())) {
                cd.getProperty().add(rp.setCode(res.getPropMap().get(rp.getCode())));
            }
        }
    }
    for (ConceptPropertyComponent rp : r.getProperty()) {
        if (!matchR.contains(rp)) {
            cd.getProperty().add(rp.setCode(res.getPropMap().get(rp.getCode())));
        }
    }
}
Also used : ConceptPropertyComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptPropertyComponent) ArrayList(java.util.ArrayList)

Example 20 with CodeSystemComparison

use of org.hl7.fhir.r4b.comparison.CodeSystemComparer.CodeSystemComparison in project org.hl7.fhir.core by hapifhir.

the class CodeSystemComparer method addRow.

private void addRow(HierarchicalTableGenerator gen, List<Row> rows, StructuralMatch<ConceptDefinitionComponent> t, CodeSystemComparison comparison) {
    Row r = gen.new Row();
    rows.add(r);
    r.getCells().add(gen.new Cell(null, null, t.either().getCode(), null, null));
    if (t.hasLeft() && t.hasRight()) {
        if (t.getLeft().hasDisplay() && t.getRight().hasDisplay()) {
            if (t.getLeft().getDisplay().equals(t.getRight().getDisplay())) {
                r.getCells().add(gen.new Cell(null, null, t.getLeft().getDisplay(), null, null).span(2));
            } else {
                r.getCells().add(gen.new Cell(null, null, t.getLeft().getDisplay(), null, null).setStyle("background-color: " + COLOR_DIFFERENT));
                r.getCells().add(gen.new Cell(null, null, t.getRight().getDisplay(), null, null).setStyle("background-color: " + COLOR_DIFFERENT));
            }
        } else if (t.getLeft().hasDisplay()) {
            r.getCells().add(gen.new Cell(null, null, t.getLeft().getDisplay(), null, null));
            r.getCells().add(missingCell(gen, COLOR_NO_CELL_RIGHT));
        } else if (t.getRight().hasDisplay()) {
            r.getCells().add(missingCell(gen, COLOR_NO_CELL_LEFT));
            r.getCells().add(gen.new Cell(null, null, t.getRight().getDisplay(), null, null));
        } else {
            r.getCells().add(missingCell(gen).span(2));
        }
        for (PropertyComponent p : comparison.getUnion().getProperty()) {
            ConceptPropertyComponent lp = getProp(t.getLeft(), p, false, comparison);
            ConceptPropertyComponent rp = getProp(t.getRight(), p, true, comparison);
            if (lp != null && rp != null) {
                if (lp.getValue().equals(rp.getValue())) {
                    r.getCells().add(gen.new Cell(null, null, t.getLeft().getDisplay(), null, null).span(2));
                } else {
                    r.getCells().add(gen.new Cell(null, null, lp.getValue().toString(), null, null));
                    r.getCells().add(gen.new Cell(null, null, rp.getValue().toString(), null, null));
                }
            } else if (lp != null) {
                r.getCells().add(gen.new Cell(null, null, lp.getValue().toString(), null, null));
                r.getCells().add(missingCell(gen, COLOR_NO_CELL_RIGHT));
            } else if (rp != null) {
                r.getCells().add(missingCell(gen, COLOR_NO_CELL_LEFT));
                r.getCells().add(gen.new Cell(null, null, rp.getValue().toString(), null, null));
            } else {
                r.getCells().add(missingCell(gen).span(2));
            }
        }
    } else if (t.hasLeft()) {
        r.setColor(COLOR_NO_ROW_RIGHT);
        r.getCells().add(gen.new Cell(null, null, t.either().getDisplay(), null, null));
        r.getCells().add(missingCell(gen));
        for (PropertyComponent p : comparison.getUnion().getProperty()) {
            r.getCells().add(propertyCell(gen, t.getLeft(), p, false, comparison));
            r.getCells().add(missingCell(gen));
        }
    } else {
        r.setColor(COLOR_NO_ROW_LEFT);
        r.getCells().add(missingCell(gen));
        r.getCells().add(gen.new Cell(null, null, t.either().getDisplay(), null, null));
        for (PropertyComponent p : comparison.getUnion().getProperty()) {
            r.getCells().add(missingCell(gen));
            r.getCells().add(propertyCell(gen, t.getLeft(), p, true, comparison));
        }
    }
    r.getCells().add(cellForMessages(gen, t.getMessages()));
}
Also used : ConceptPropertyComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptPropertyComponent) PropertyComponent(org.hl7.fhir.r5.model.CodeSystem.PropertyComponent) ConceptPropertyComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptPropertyComponent) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)

Aggregations

ConceptPropertyComponent (org.hl7.fhir.r4b.model.CodeSystem.ConceptPropertyComponent)5 ConceptPropertyComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptPropertyComponent)5 ArrayList (java.util.ArrayList)4 ConceptDefinitionComponent (org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent)4 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)4 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)4 FileOutputStream (java.io.FileOutputStream)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 CodeSystem (org.hl7.fhir.r4b.model.CodeSystem)3 PropertyComponent (org.hl7.fhir.r4b.model.CodeSystem.PropertyComponent)3 PropertyComponent (org.hl7.fhir.r5.model.CodeSystem.PropertyComponent)3 XhtmlComposer (org.hl7.fhir.utilities.xhtml.XhtmlComposer)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)2 CodeSystemComparison (org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison)2 ProfileComparison (org.hl7.fhir.r5.comparison.ProfileComparer.ProfileComparison)2 ValueSetComparison (org.hl7.fhir.r5.comparison.ValueSetComparer.ValueSetComparison)2 ProfileUtilities (org.hl7.fhir.r5.conformance.ProfileUtilities)2 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)2