Search in sources :

Example 6 with ValueSetComparison

use of org.hl7.fhir.r4b.comparison.ValueSetComparer.ValueSetComparison in project org.hl7.fhir.core by hapifhir.

the class ProfileComparer method unionBindings.

private ElementDefinitionBindingComponent unionBindings(ProfileComparison comp, StructuralMatch<ElementDefinitionNode> res, String path, ElementDefinitionBindingComponent left, ElementDefinitionBindingComponent right) throws FHIRFormatError, DefinitionException, IOException {
    ElementDefinitionBindingComponent union = new ElementDefinitionBindingComponent();
    if (left.getStrength().compareTo(right.getStrength()) < 0)
        union.setStrength(left.getStrength());
    else
        union.setStrength(right.getStrength());
    union.setDescription(mergeText(comp, res, path, "binding.description", left.getDescription(), right.getDescription(), false));
    if (Base.compareDeep(left.getValueSet(), right.getValueSet(), false))
        union.setValueSet(left.getValueSet());
    else {
        ValueSet lvs = resolveVS(comp.getLeft(), left.getValueSet(), session.getContextLeft());
        ValueSet rvs = resolveVS(comp.getRight(), right.getValueSet(), session.getContextRight());
        if (lvs != null && rvs != null) {
            ValueSetComparison compP = (ValueSetComparison) session.compare(lvs, rvs);
            if (compP != null) {
                union.setValueSet(compP.getUnion().getUrl());
            }
        } else if (lvs != null) {
            union.setValueSet(lvs.getUrl());
        } else if (rvs != null) {
            union.setValueSet(rvs.getUrl());
        }
    }
    return union;
}
Also used : ValueSetComparison(org.hl7.fhir.r5.comparison.ValueSetComparer.ValueSetComparison) ElementDefinitionBindingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 7 with ValueSetComparison

use of org.hl7.fhir.r4b.comparison.ValueSetComparer.ValueSetComparison in project org.hl7.fhir.core by hapifhir.

the class ValueSetComparer method renderCompose.

public XhtmlNode renderCompose(ValueSetComparison csc, String id, String prefix) throws FHIRException, IOException {
    HierarchicalTableGenerator gen = new HierarchicalTableGenerator(Utilities.path("[tmp]", "comparison"), false);
    TableModel model = gen.new TableModel(id, true);
    model.setAlternating(true);
    model.getTitles().add(gen.new Title(null, null, "Item", "The type of item being compared", null, 100));
    model.getTitles().add(gen.new Title(null, null, "Property", "The system for the concept", null, 100, 2));
    model.getTitles().add(gen.new Title(null, null, "Value", "The display for the concept", null, 200, 2));
    model.getTitles().add(gen.new Title(null, null, "Comments", "Additional information about the comparison", null, 200));
    for (StructuralMatch<Element> t : csc.getIncludes().getChildren()) {
        addComposeRow(gen, model.getRows(), t, "include");
    }
    for (StructuralMatch<Element> t : csc.getExcludes().getChildren()) {
        addComposeRow(gen, model.getRows(), t, "exclude");
    }
    return gen.generate(model, prefix, 0, null);
}
Also used : Element(org.hl7.fhir.r5.model.Element) HierarchicalTableGenerator(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator) TableModel(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel)

Example 8 with ValueSetComparison

use of org.hl7.fhir.r4b.comparison.ValueSetComparer.ValueSetComparison in project org.hl7.fhir.core by hapifhir.

the class ValueSetComparer method renderExpansion.

public XhtmlNode renderExpansion(ValueSetComparison csc, String id, String prefix) throws IOException {
    if (csc.getExpansion() == null) {
        XhtmlNode p = new XhtmlNode(NodeType.Element, "p");
        p.tx("Unable to generate expansion - see errors");
        return p;
    }
    if (csc.getExpansion().getChildren().isEmpty()) {
        XhtmlNode p = new XhtmlNode(NodeType.Element, "p");
        p.tx("Expansion is empty");
        return p;
    }
    // columns: code(+system), version, display , abstract, inactive,
    boolean hasSystem = csc.getExpansion().getChildren().isEmpty() ? false : getSystemVaries(csc.getExpansion(), csc.getExpansion().getChildren().get(0).either().getSystem());
    boolean hasVersion = findVersion(csc.getExpansion());
    boolean hasAbstract = findAbstract(csc.getExpansion());
    boolean hasInactive = findInactive(csc.getExpansion());
    HierarchicalTableGenerator gen = new HierarchicalTableGenerator(Utilities.path("[tmp]", "comparison"), false);
    TableModel model = gen.new TableModel(id, true);
    model.setAlternating(true);
    if (hasSystem) {
        model.getTitles().add(gen.new Title(null, null, "System", "The code for the concept", null, 100));
    }
    model.getTitles().add(gen.new Title(null, null, "Code", "The system for the concept", null, 100));
    model.getTitles().add(gen.new Title(null, null, "Display", "The display for the concept", null, 200, 2));
    // if (hasVersion) {
    // model.getTitles().add(gen.new Title(null, null, "Version", "The version for the concept", null, 200, 2));
    // }
    // if (hasAbstract) {
    // model.getTitles().add(gen.new Title(null, null, "Abstract", "The abstract flag for the concept", null, 200, 2));
    // }
    // if (hasInactive) {
    // model.getTitles().add(gen.new Title(null, null, "Inactive", "The inactive flag for the concept", null, 200, 2));
    // }
    model.getTitles().add(gen.new Title(null, null, "Comments", "Additional information about the comparison", null, 200));
    for (StructuralMatch<ValueSetExpansionContainsComponent> t : csc.getExpansion().getChildren()) {
        addExpansionRow(gen, model.getRows(), t, hasSystem, hasVersion, hasAbstract, hasInactive);
    }
    return gen.generate(model, prefix, 0, null);
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) HierarchicalTableGenerator(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator) TableModel(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 9 with ValueSetComparison

use of org.hl7.fhir.r4b.comparison.ValueSetComparer.ValueSetComparison in project org.hl7.fhir.core by hapifhir.

the class ValueSetComparer method compareCompose.

private void compareCompose(ValueSetComposeComponent left, ValueSetComposeComponent right, ValueSetComparison res, ValueSetComposeComponent union, ValueSetComposeComponent intersection) {
    // first, the includes
    List<ConceptSetComponent> matchR = new ArrayList<>();
    for (ConceptSetComponent l : left.getInclude()) {
        ConceptSetComponent r = findInList(right.getInclude(), l, left.getInclude());
        if (r == null) {
            union.getInclude().add(l);
            res.getIncludes().getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed Include", "ValueSet.compose.include")));
        } else {
            matchR.add(r);
            ConceptSetComponent csM = new ConceptSetComponent();
            ConceptSetComponent csI = new ConceptSetComponent();
            union.getInclude().add(csM);
            intersection.getInclude().add(csI);
            StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r);
            res.getIncludes().getChildren().add(sm);
            compareDefinitions(l, r, sm, csM, csI);
        }
    }
    for (ConceptSetComponent r : right.getInclude()) {
        if (!matchR.contains(r)) {
            union.getInclude().add(r);
            res.getIncludes().getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Added Include", "ValueSet.compose.include"), r));
        }
    }
    // now. the excludes
    matchR.clear();
    for (ConceptSetComponent l : left.getExclude()) {
        ConceptSetComponent r = findInList(right.getExclude(), l, left.getExclude());
        if (r == null) {
            union.getExclude().add(l);
            res.getExcludes().getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed Exclude", "ValueSet.compose.exclude")));
        } else {
            matchR.add(r);
            ConceptSetComponent csM = new ConceptSetComponent();
            ConceptSetComponent csI = new ConceptSetComponent();
            union.getExclude().add(csM);
            intersection.getExclude().add(csI);
            StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r);
            res.getExcludes().getChildren().add(sm);
            compareDefinitions(l, r, sm, csM, csI);
        }
    }
    for (ConceptSetComponent r : right.getExclude()) {
        if (!matchR.contains(r)) {
            union.getExclude().add(r);
            res.getExcludes().getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Added Exclude", "ValueSet.compose.exclude"), r));
        }
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) Element(org.hl7.fhir.r5.model.Element) ArrayList(java.util.ArrayList)

Example 10 with ValueSetComparison

use of org.hl7.fhir.r4b.comparison.ValueSetComparer.ValueSetComparison in project org.hl7.fhir.core by hapifhir.

the class ComparisonRenderer method renderValueSet.

private void renderValueSet(String id, ValueSetComparison comp) throws FHIRException, IOException {
    String template = templates.get("ValueSet");
    Map<String, Base> vars = new HashMap<>();
    ValueSetComparer cs = new ValueSetComparer(session);
    vars.put("left", new StringType(comp.getLeft().present()));
    vars.put("right", new StringType(comp.getRight().present()));
    vars.put("leftId", new StringType(comp.getLeft().getId()));
    vars.put("rightId", new StringType(comp.getRight().getId()));
    vars.put("leftUrl", new StringType(comp.getLeft().getUrl()));
    vars.put("rightUrl", new StringType(comp.getRight().getUrl()));
    vars.put("errors", new StringType(new XhtmlComposer(true).compose(cs.renderErrors(comp))));
    vars.put("metadata", new StringType(new XhtmlComposer(true).compose(cs.renderMetadata(comp, "", ""))));
    vars.put("compose", new StringType(new XhtmlComposer(true).compose(cs.renderCompose(comp, "", ""))));
    vars.put("expansion", new StringType(new XhtmlComposer(true).compose(cs.renderExpansion(comp, "", ""))));
    String cnt = processTemplate(template, "ValueSet", vars);
    TextFile.stringToFile(cnt, file(comp.getId() + ".html"));
    new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(folder, comp.getId() + "-union.json")), comp.getUnion());
    new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(folder, comp.getId() + "-intersection.json")), comp.getIntersection());
}
Also used : HashMap(java.util.HashMap) StringType(org.hl7.fhir.r5.model.StringType) FileOutputStream(java.io.FileOutputStream) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) Base(org.hl7.fhir.r5.model.Base)

Aggregations

ValueSet (org.hl7.fhir.r5.model.ValueSet)6 ValueSet (org.hl7.fhir.r4b.model.ValueSet)5 ArrayList (java.util.ArrayList)4 ValueSetComparison (org.hl7.fhir.r5.comparison.ValueSetComparer.ValueSetComparison)4 HierarchicalTableGenerator (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator)4 TableModel (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel)4 FileOutputStream (java.io.FileOutputStream)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 ValueSetComparison (org.hl7.fhir.r4b.comparison.ValueSetComparer.ValueSetComparison)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 Element (org.hl7.fhir.r4b.model.Element)2 ElementDefinitionBindingComponent (org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent)2 ValueSetExpansionContainsComponent (org.hl7.fhir.r4b.model.ValueSet.ValueSetExpansionContainsComponent)2 CodeSystemComparison (org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison)2 ProfileComparison (org.hl7.fhir.r5.comparison.ProfileComparer.ProfileComparison)2 ProfileUtilities (org.hl7.fhir.r5.conformance.ProfileUtilities)2 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)2