use of org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison in project org.hl7.fhir.core by hapifhir.
the class CodeSystemComparer method compare.
public CodeSystemComparison compare(CodeSystem left, CodeSystem right) {
if (left == null)
throw new DefinitionException("No CodeSystem provided (left)");
if (right == null)
throw new DefinitionException("No CodeSystem provided (right)");
CodeSystemComparison res = new CodeSystemComparison(left, right);
session.identify(res);
CodeSystem cs = new CodeSystem();
res.setUnion(cs);
session.identify(cs);
cs.setName("Union" + left.getName() + "And" + right.getName());
cs.setTitle("Union of " + left.getTitle() + " And " + right.getTitle());
cs.setStatus(left.getStatus());
cs.setDate(new Date());
for (PropertyComponent pL : left.getProperty()) {
cs.addProperty(pL.copy());
}
for (PropertyComponent pR : left.getProperty()) {
PropertyComponent pL = findProperty(left, pR);
if (pL == null) {
String code = getUniqued(pR.getCode(), cs.getProperty());
cs.addProperty(pR.copy().setCode(code));
} else {
res.getPropMap().put(pR.getCode(), pL.getCode());
}
}
CodeSystem cs1 = new CodeSystem();
res.setIntersection(cs1);
session.identify(cs1);
cs1.setName("Intersection" + left.getName() + "And" + right.getName());
cs1.setTitle("Intersection of " + left.getTitle() + " And " + right.getTitle());
cs1.setStatus(left.getStatus());
cs1.setDate(new Date());
cs1.getProperty().addAll(cs.getProperty());
compareMetadata(left, right, res.getMetadata(), res);
comparePrimitives("caseSensitive", left.getCaseSensitiveElement(), right.getCaseSensitiveElement(), res.getMetadata(), IssueSeverity.ERROR, res);
comparePrimitives("hierarchyMeaning", left.getHierarchyMeaningElement(), right.getHierarchyMeaningElement(), res.getMetadata(), IssueSeverity.ERROR, res);
comparePrimitives("compositional", left.getCompositionalElement(), right.getCompositionalElement(), res.getMetadata(), IssueSeverity.WARNING, res);
comparePrimitives("versionNeeded", left.getVersionNeededElement(), right.getVersionNeededElement(), res.getMetadata(), IssueSeverity.INFORMATION, res);
comparePrimitives("content", left.getContentElement(), right.getContentElement(), res.getMetadata(), IssueSeverity.WARNING, res);
compareConcepts(left.getConcept(), right.getConcept(), res.getCombined(), res.getUnion().getConcept(), res.getIntersection().getConcept(), res.getUnion(), res.getIntersection(), res, "CodeSystem.concept");
return res;
}
use of org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison in project org.hl7.fhir.core by hapifhir.
the class ComparisonSession method compare.
public ResourceComparison compare(CanonicalResource left, CanonicalResource right) throws DefinitionException, FHIRFormatError, IOException {
if (left != null && right != null) {
String key = key(left.getUrl(), left.getVersion(), right.getUrl(), right.getVersion());
if (compares.containsKey(key)) {
// this can happen when profiles refer to each other
return compares.get(key);
}
compares.put(key, null);
try {
if (left instanceof CodeSystem && right instanceof CodeSystem) {
CodeSystemComparer cs = new CodeSystemComparer(this);
CodeSystemComparison csc = cs.compare((CodeSystem) left, (CodeSystem) right);
compares.put(key, csc);
return csc;
} else if (left instanceof ValueSet && right instanceof ValueSet) {
ValueSetComparer cs = new ValueSetComparer(this);
ValueSetComparison csc = cs.compare((ValueSet) left, (ValueSet) right);
compares.put(key, csc);
return csc;
} else if (left instanceof StructureDefinition && right instanceof StructureDefinition) {
ProfileComparer cs = new ProfileComparer(this, new ProfileUtilities(contextLeft, null, pkp), new ProfileUtilities(contextRight, null, pkp));
ProfileComparison csc = cs.compare((StructureDefinition) left, (StructureDefinition) right);
compares.put(key, csc);
return csc;
} else {
throw new FHIRException("Unable to compare resources of type " + left.fhirType() + " and " + right.fhirType());
}
} catch (Throwable e) {
ResourceComparer.PlaceHolderComparison csc = new ResourceComparer.PlaceHolderComparison(left, right, e);
compares.put(key, csc);
return csc;
}
} else if (left != null) {
String key = key(left.getUrl(), left.getVersion(), left.getUrl(), left.getVersion());
if (compares.containsKey(key)) {
return compares.get(key);
}
ResourceComparer.PlaceHolderComparison csc = new ResourceComparer.PlaceHolderComparison(left, right);
compares.put(key, csc);
return csc;
} else {
String key = key(right.getUrl(), right.getVersion(), right.getUrl(), right.getVersion());
if (compares.containsKey(key)) {
return compares.get(key);
}
ResourceComparer.PlaceHolderComparison csc = new ResourceComparer.PlaceHolderComparison(left, right);
compares.put(key, csc);
return csc;
}
}
use of org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison in project org.hl7.fhir.core by hapifhir.
the class ComparisonRenderer method renderCodeSystem.
private void renderCodeSystem(String id, CodeSystemComparison comp) throws IOException {
String template = templates.get("CodeSystem");
Map<String, Base> vars = new HashMap<>();
CodeSystemComparer cs = new CodeSystemComparer(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("concepts", new StringType(new XhtmlComposer(true).compose(cs.renderConcepts(comp, "", ""))));
String cnt = processTemplate(template, "CodeSystem", 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());
}
use of org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison in project org.hl7.fhir.core by hapifhir.
the class CodeSystemComparer method compare.
public CodeSystemComparison compare(CodeSystem left, CodeSystem right) {
if (left == null)
throw new DefinitionException("No CodeSystem provided (left)");
if (right == null)
throw new DefinitionException("No CodeSystem provided (right)");
CodeSystemComparison res = new CodeSystemComparison(left, right);
session.identify(res);
CodeSystem cs = new CodeSystem();
res.setUnion(cs);
session.identify(cs);
cs.setName("Union" + left.getName() + "And" + right.getName());
cs.setTitle("Union of " + left.getTitle() + " And " + right.getTitle());
cs.setStatus(left.getStatus());
cs.setDate(new Date());
for (PropertyComponent pL : left.getProperty()) {
cs.addProperty(pL.copy());
}
for (PropertyComponent pR : left.getProperty()) {
PropertyComponent pL = findProperty(left, pR);
if (pL == null) {
String code = getUniqued(pR.getCode(), cs.getProperty());
cs.addProperty(pR.copy().setCode(code));
} else {
res.getPropMap().put(pR.getCode(), pL.getCode());
}
}
CodeSystem cs1 = new CodeSystem();
res.setIntersection(cs1);
session.identify(cs1);
cs1.setName("Intersection" + left.getName() + "And" + right.getName());
cs1.setTitle("Intersection of " + left.getTitle() + " And " + right.getTitle());
cs1.setStatus(left.getStatus());
cs1.setDate(new Date());
cs1.getProperty().addAll(cs.getProperty());
compareMetadata(left, right, res.getMetadata(), res);
comparePrimitives("caseSensitive", left.getCaseSensitiveElement(), right.getCaseSensitiveElement(), res.getMetadata(), IssueSeverity.ERROR, res);
comparePrimitives("hierarchyMeaning", left.getHierarchyMeaningElement(), right.getHierarchyMeaningElement(), res.getMetadata(), IssueSeverity.ERROR, res);
comparePrimitives("compositional", left.getCompositionalElement(), right.getCompositionalElement(), res.getMetadata(), IssueSeverity.WARNING, res);
comparePrimitives("versionNeeded", left.getVersionNeededElement(), right.getVersionNeededElement(), res.getMetadata(), IssueSeverity.INFORMATION, res);
comparePrimitives("content", left.getContentElement(), right.getContentElement(), res.getMetadata(), IssueSeverity.WARNING, res);
compareConcepts(left.getConcept(), right.getConcept(), res.getCombined(), res.getUnion().getConcept(), res.getIntersection().getConcept(), res.getUnion(), res.getIntersection(), res, "CodeSystem.concept");
return res;
}
use of org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison in project org.hl7.fhir.core by hapifhir.
the class CodeSystemComparer method intersect.
private ConceptDefinitionComponent intersect(ConceptDefinitionComponent l, ConceptDefinitionComponent r, CodeSystemComparison res) {
ConceptDefinitionComponent cd = l.copy();
if (l.hasDisplay() && !r.hasDisplay()) {
cd.setDisplay(null);
}
if (l.hasDefinition() && !r.hasDefinition()) {
cd.setDefinition(null);
}
intersectProps(cd, l, r, res);
// mergeDesignations(cd, l, r);
return cd;
}
Aggregations