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.r4b.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(folder, comp.getId() + "-union.json")), comp.getUnion());
new org.hl7.fhir.r4b.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(folder, comp.getId() + "-intersection.json")), comp.getIntersection());
}
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);
}
use of org.hl7.fhir.r4b.comparison.ValueSetComparer.ValueSetComparison in project org.hl7.fhir.core by hapifhir.
the class ValueSetComparer method compareConcepts.
private void compareConcepts(List<ValueSetExpansionContainsComponent> left, List<ValueSetExpansionContainsComponent> right, StructuralMatch<ValueSetExpansionContainsComponent> combined, List<ValueSetExpansionContainsComponent> union, List<ValueSetExpansionContainsComponent> intersection, String path, ValueSetComparison res) {
List<ValueSetExpansionContainsComponent> matchR = new ArrayList<>();
for (ValueSetExpansionContainsComponent l : left) {
ValueSetExpansionContainsComponent r = findInList(right, l);
if (r == null) {
union.add(l);
combined.getChildren().add(new StructuralMatch<ValueSetExpansionContainsComponent>(l, vmI(IssueSeverity.INFORMATION, "Removed from expansion", path)));
} else {
matchR.add(r);
ValueSetExpansionContainsComponent ccU = merge(l, r);
ValueSetExpansionContainsComponent ccI = intersect(l, r);
union.add(ccU);
intersection.add(ccI);
StructuralMatch<ValueSetExpansionContainsComponent> sm = new StructuralMatch<ValueSetExpansionContainsComponent>(l, r);
compareItem(sm.getMessages(), path, l, r, res);
combined.getChildren().add(sm);
compareConcepts(l.getContains(), r.getContains(), sm, ccU.getContains(), ccI.getContains(), path + ".where(code = '" + l.getCode() + "').contains", res);
}
}
for (ValueSetExpansionContainsComponent r : right) {
if (!matchR.contains(r)) {
union.add(r);
combined.getChildren().add(new StructuralMatch<ValueSetExpansionContainsComponent>(vmI(IssueSeverity.INFORMATION, "Added to expansion", path), r));
}
}
}
use of org.hl7.fhir.r4b.comparison.ValueSetComparer.ValueSetComparison in project org.hl7.fhir.core by hapifhir.
the class ValueSetComparer method compare.
public ValueSetComparison compare(ValueSet left, ValueSet right) {
if (left == null)
throw new DefinitionException("No ValueSet provided (left)");
if (right == null)
throw new DefinitionException("No ValueSet provided (right)");
ValueSetComparison res = new ValueSetComparison(left, right);
session.identify(res);
ValueSet vs = new ValueSet();
res.setUnion(vs);
session.identify(vs);
vs.setName("Union" + left.getName() + "And" + right.getName());
vs.setTitle("Union of " + left.getTitle() + " And " + right.getTitle());
vs.setStatus(left.getStatus());
vs.setDate(new Date());
ValueSet vs1 = new ValueSet();
res.setIntersection(vs1);
session.identify(vs1);
vs1.setName("Intersection" + left.getName() + "And" + right.getName());
vs1.setTitle("Intersection of " + left.getTitle() + " And " + right.getTitle());
vs1.setStatus(left.getStatus());
vs1.setDate(new Date());
compareMetadata(left, right, res.getMetadata(), res);
comparePrimitives("immutable", left.getImmutableElement(), right.getImmutableElement(), res.getMetadata(), IssueSeverity.WARNING, res);
if (left.hasCompose() || right.hasCompose()) {
comparePrimitives("compose.lockedDate", left.getCompose().getLockedDateElement(), right.getCompose().getLockedDateElement(), res.getMetadata(), IssueSeverity.WARNING, res);
comparePrimitives("compose.inactive", left.getCompose().getInactiveElement(), right.getCompose().getInactiveElement(), res.getMetadata(), IssueSeverity.WARNING, res);
}
compareCompose(left.getCompose(), right.getCompose(), res, res.getUnion().getCompose(), res.getIntersection().getCompose());
compareExpansions(left, right, res);
return res;
}
use of org.hl7.fhir.r4b.comparison.ValueSetComparer.ValueSetComparison in project org.hl7.fhir.core by hapifhir.
the class ValueSetComparer method compareExpansions.
private void compareExpansions(ValueSet left, ValueSet right, ValueSetComparison res) {
ValueSet expL = left.hasExpansion() ? left : expand(left, res, "left", session.getContextLeft());
ValueSet expR = right.hasExpansion() ? right : expand(right, res, "right", session.getContextRight());
if (expL != null && expR != null) {
// ignore the parameters for now
compareConcepts(expL.getExpansion().getContains(), expR.getExpansion().getContains(), res.forceExpansion(), res.getUnion().getExpansion().getContains(), res.getIntersection().getExpansion().getContains(), "ValueSet.expansion.contains", res);
}
}
Aggregations