use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method makeNullBr.
private BindingResolution makeNullBr(ElementDefinitionBindingComponent binding) {
BindingResolution br = new BindingResolution();
br.url = "http://none.none/none";
br.display = "todo";
return br;
}
use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent 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;
}
use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method generateDescription.
private Cell generateDescription(HierarchicalTableGenerator gen, Row row, ElementDefinition definition, ElementDefinition fallback, boolean used, String baseURL, String url, StructureDefinition profile, String corePath, String imagePath, boolean root, boolean logicalModel, boolean allInvariants, ElementDefinition valueDefn) throws IOException {
Cell c = gen.new Cell();
row.getCells().add(c);
if (used) {
if (logicalModel && ToolingExtensions.hasExtension(profile, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace")) {
if (root) {
c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML Namespace") + ": ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(profile, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"), null));
} else if (!root && ToolingExtensions.hasExtension(definition, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace") && !ToolingExtensions.readStringExtension(definition, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").equals(ToolingExtensions.readStringExtension(profile, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"))) {
c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML Namespace") + ": ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(definition, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"), null));
}
}
if (definition.hasContentReference()) {
ElementDefinition ed = getElementByName(profile.getSnapshot().getElement(), definition.getContentReference());
if (ed == null)
c.getPieces().add(gen.new Piece(null, translate("sd.table", "Unknown reference to %s", definition.getContentReference()), null));
else
c.getPieces().add(gen.new Piece("#" + ed.getPath(), translate("sd.table", "See %s", ed.getPath()), null));
}
if (definition.getPath().endsWith("url") && definition.hasFixed()) {
c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "\"" + buildJson(definition.getFixed()) + "\"", null).addStyle("color: darkgreen")));
} else {
if (definition != null && definition.hasShort()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.addPiece(checkForNoChange(definition.getShortElement(), gen.new Piece(null, gt(definition.getShortElement()), null)));
} else if (fallback != null && fallback.hasShort()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.addPiece(checkForNoChange(fallback.getShortElement(), gen.new Piece(null, gt(fallback.getShortElement()), null)));
}
if (url != null) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
String fullUrl = url.startsWith("#") ? baseURL + url : url;
StructureDefinition ed = context.fetchResource(StructureDefinition.class, url);
String ref = null;
if (ed != null) {
String p = ed.getUserString("path");
if (p != null) {
ref = p.startsWith("http:") || igmode ? p : Utilities.pathURL(corePath, p);
}
}
c.getPieces().add(gen.new Piece(null, translate("sd.table", "URL") + ": ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(ref, fullUrl, null));
}
if (definition.hasSlicing()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(gen.new Piece(null, translate("sd.table", "Slice") + ": ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(null, describeSlice(definition.getSlicing()), null));
}
if (definition != null) {
ElementDefinitionBindingComponent binding = null;
if (valueDefn != null && valueDefn.hasBinding() && !valueDefn.getBinding().isEmpty())
binding = valueDefn.getBinding();
else if (definition.hasBinding())
binding = definition.getBinding();
if (binding != null && !binding.isEmpty()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
BindingResolution br = pkp.resolveBinding(profile, binding, definition.getPath());
c.getPieces().add(checkForNoChange(binding, gen.new Piece(null, translate("sd.table", "Binding") + ": ", null).addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(binding, gen.new Piece(br.url == null ? null : Utilities.isAbsoluteUrl(br.url) || !pkp.prependLinks() ? br.url : corePath + br.url, br.display, null)));
if (binding.hasStrength()) {
c.getPieces().add(checkForNoChange(binding, gen.new Piece(null, " (", null)));
c.getPieces().add(checkForNoChange(binding, gen.new Piece(corePath + "terminologies.html#" + binding.getStrength().toCode(), egt(binding.getStrengthElement()), binding.getStrength().getDefinition())));
c.getPieces().add(gen.new Piece(null, ")", null));
}
}
for (ElementDefinitionConstraintComponent inv : definition.getConstraint()) {
if (!inv.hasSource() || allInvariants) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, inv.getKey() + ": ", null).addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, gt(inv.getHumanElement()), null)));
}
}
if ((definition.hasBase() && definition.getBase().getMax().equals("*")) || (definition.hasMax() && definition.getMax().equals("*"))) {
if (c.getPieces().size() > 0)
c.addPiece(gen.new Piece("br"));
if (definition.hasOrderMeaning()) {
c.getPieces().add(gen.new Piece(null, "This repeating element order: " + definition.getOrderMeaning(), null));
} else {
// don't show this, this it's important: c.getPieces().add(gen.new Piece(null, "This repeating element has no defined order", null));
}
}
if (definition.hasFixed()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, translate("sd.table", "Fixed Value") + ": ", null).addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, buildJson(definition.getFixed()), null).addStyle("color: darkgreen")));
if (isCoded(definition.getFixed()) && !hasDescription(definition.getFixed())) {
Piece p = describeCoded(gen, definition.getFixed());
if (p != null)
c.getPieces().add(p);
}
} else if (definition.hasPattern()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, translate("sd.table", "Required Pattern") + ": ", null).addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, buildJson(definition.getPattern()), null).addStyle("color: darkgreen")));
} else if (definition.hasExample()) {
for (ElementDefinitionExampleComponent ex : definition.getExample()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(ex, gen.new Piece(null, translate("sd.table", "Example") + ("".equals("General") ? "" : " " + ex.getLabel() + "'") + ": ", null).addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(ex, gen.new Piece(null, buildJson(ex.getValue()), null).addStyle("color: darkgreen")));
}
}
if (definition.hasMaxLength() && definition.getMaxLength() != 0) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(definition.getMaxLengthElement(), gen.new Piece(null, "Max Length: ", null).addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(definition.getMaxLengthElement(), gen.new Piece(null, Integer.toString(definition.getMaxLength()), null).addStyle("color: darkgreen")));
}
if (profile != null) {
for (StructureDefinitionMappingComponent md : profile.getMapping()) {
if (md.hasExtension(ToolingExtensions.EXT_TABLE_NAME)) {
ElementDefinitionMappingComponent map = null;
for (ElementDefinitionMappingComponent m : definition.getMapping()) if (m.getIdentity().equals(md.getIdentity()))
map = m;
if (map != null) {
for (int i = 0; i < definition.getMapping().size(); i++) {
c.addPiece(gen.new Piece("br"));
c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(md, ToolingExtensions.EXT_TABLE_NAME) + ": " + map.getMap(), null));
}
}
}
}
}
}
}
}
return c;
}
use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project org.hl7.fhir.core by hapifhir.
the class ProfileComparer method unionBindings.
private ElementDefinitionBindingComponent unionBindings(ElementDefinition ed, ProfileComparison outcome, String path, ElementDefinitionBindingComponent left, ElementDefinitionBindingComponent right) throws FHIRFormatError {
ElementDefinitionBindingComponent union = new ElementDefinitionBindingComponent();
if (left.getStrength().compareTo(right.getStrength()) < 0)
union.setStrength(left.getStrength());
else
union.setStrength(right.getStrength());
union.setDescription(mergeText(ed, outcome, path, "binding.description", left.getDescription(), right.getDescription()));
if (Base.compareDeep(left.getValueSet(), right.getValueSet(), false))
union.setValueSet(left.getValueSet());
else {
ValueSet lvs = resolveVS(outcome.left, left.getValueSet());
ValueSet rvs = resolveVS(outcome.left, right.getValueSet());
if (lvs != null && rvs != null)
union.setValueSet(new Reference().setReference("#" + addValueSet(unite(ed, outcome, path, lvs, rvs))));
else if (lvs != null)
union.setValueSet(new Reference().setReference("#" + addValueSet(lvs)));
else if (rvs != null)
union.setValueSet(new Reference().setReference("#" + addValueSet(rvs)));
}
return union;
}
use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project org.hl7.fhir.core by hapifhir.
the class ProfileComparer method compareBindings.
private boolean compareBindings(ProfileComparison outcome, ElementDefinition subset, ElementDefinition superset, String path, ElementDefinition lDef, ElementDefinition rDef) throws FHIRFormatError {
assert (lDef.hasBinding() || rDef.hasBinding());
if (!lDef.hasBinding()) {
subset.setBinding(rDef.getBinding());
// technically, the super set is unbound, but that's not very useful - so we use the provided on as an example
superset.setBinding(rDef.getBinding().copy());
superset.getBinding().setStrength(BindingStrength.EXAMPLE);
return true;
}
if (!rDef.hasBinding()) {
subset.setBinding(lDef.getBinding());
superset.setBinding(lDef.getBinding().copy());
superset.getBinding().setStrength(BindingStrength.EXAMPLE);
return true;
}
ElementDefinitionBindingComponent left = lDef.getBinding();
ElementDefinitionBindingComponent right = rDef.getBinding();
if (Base.compareDeep(left, right, false)) {
subset.setBinding(left);
superset.setBinding(right);
}
// superset:
if (isPreferredOrExample(left) && isPreferredOrExample(right)) {
if (right.getStrength() == BindingStrength.PREFERRED && left.getStrength() == BindingStrength.EXAMPLE && !Base.compareDeep(left.getValueSet(), right.getValueSet(), false)) {
outcome.messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "Example/preferred bindings differ at " + path + " using binding from " + outcome.rightName(), ValidationMessage.IssueSeverity.INFORMATION));
status(subset, ProfileUtilities.STATUS_HINT);
subset.setBinding(right);
superset.setBinding(unionBindings(superset, outcome, path, left, right));
} else {
if ((right.getStrength() != BindingStrength.EXAMPLE || left.getStrength() != BindingStrength.EXAMPLE) && !Base.compareDeep(left.getValueSet(), right.getValueSet(), false)) {
outcome.messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "Example/preferred bindings differ at " + path + " using binding from " + outcome.leftName(), ValidationMessage.IssueSeverity.INFORMATION));
status(subset, ProfileUtilities.STATUS_HINT);
}
subset.setBinding(left);
superset.setBinding(unionBindings(superset, outcome, path, left, right));
}
return true;
}
// if either of them are extensible/required, then it wins
if (isPreferredOrExample(left)) {
subset.setBinding(right);
superset.setBinding(unionBindings(superset, outcome, path, left, right));
return true;
}
if (isPreferredOrExample(right)) {
subset.setBinding(left);
superset.setBinding(unionBindings(superset, outcome, path, left, right));
return true;
}
// ok, both are extensible or required.
ElementDefinitionBindingComponent subBinding = new ElementDefinitionBindingComponent();
subset.setBinding(subBinding);
ElementDefinitionBindingComponent superBinding = new ElementDefinitionBindingComponent();
superset.setBinding(superBinding);
subBinding.setDescription(mergeText(subset, outcome, path, "description", left.getDescription(), right.getDescription()));
superBinding.setDescription(mergeText(subset, outcome, null, "description", left.getDescription(), right.getDescription()));
if (left.getStrength() == BindingStrength.REQUIRED || right.getStrength() == BindingStrength.REQUIRED)
subBinding.setStrength(BindingStrength.REQUIRED);
else
subBinding.setStrength(BindingStrength.EXTENSIBLE);
if (left.getStrength() == BindingStrength.EXTENSIBLE || right.getStrength() == BindingStrength.EXTENSIBLE)
superBinding.setStrength(BindingStrength.EXTENSIBLE);
else
superBinding.setStrength(BindingStrength.REQUIRED);
if (Base.compareDeep(left.getValueSet(), right.getValueSet(), false)) {
subBinding.setValueSet(left.getValueSet());
superBinding.setValueSet(left.getValueSet());
return true;
} else if (!left.hasValueSet()) {
outcome.messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "No left Value set at " + path, ValidationMessage.IssueSeverity.ERROR));
return true;
} else if (!right.hasValueSet()) {
outcome.messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "No right Value set at " + path, ValidationMessage.IssueSeverity.ERROR));
return true;
} else {
// ok, now we compare the value sets. This may be unresolvable.
ValueSet lvs = resolveVS(outcome.left, left.getValueSet());
ValueSet rvs = resolveVS(outcome.right, right.getValueSet());
if (lvs == null) {
outcome.messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "Unable to resolve left value set " + left.getValueSet().toString() + " at " + path, ValidationMessage.IssueSeverity.ERROR));
return true;
} else if (rvs == null) {
outcome.messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "Unable to resolve right value set " + right.getValueSet().toString() + " at " + path, ValidationMessage.IssueSeverity.ERROR));
return true;
} else {
// first, we'll try to do it by definition
ValueSet cvs = intersectByDefinition(lvs, rvs);
if (cvs == null) {
// if that didn't work, we'll do it by expansion
ValueSetExpansionOutcome le;
ValueSetExpansionOutcome re;
try {
le = context.expandVS(lvs, true, false);
re = context.expandVS(rvs, true, false);
if (!closed(le.getValueset()) || !closed(re.getValueset()))
throw new DefinitionException("unclosed value sets are not handled yet");
cvs = intersectByExpansion(lvs, rvs);
if (!cvs.getCompose().hasInclude()) {
outcome.messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "The value sets " + lvs.getUrl() + " and " + rvs.getUrl() + " do not intersect", ValidationMessage.IssueSeverity.ERROR));
status(subset, ProfileUtilities.STATUS_ERROR);
return false;
}
} catch (Exception e) {
outcome.messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "Unable to expand or process value sets " + lvs.getUrl() + " and " + rvs.getUrl() + ": " + e.getMessage(), ValidationMessage.IssueSeverity.ERROR));
status(subset, ProfileUtilities.STATUS_ERROR);
return false;
}
}
subBinding.setValueSet(new Reference().setReference("#" + addValueSet(cvs)));
superBinding.setValueSet(new Reference().setReference("#" + addValueSet(unite(superset, outcome, path, lvs, rvs))));
}
}
return false;
}
Aggregations