use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project kindling by HL7.
the class CDAGenerator method processAttribute.
private void processAttribute(List<Element> classes, List<ElementDefinition> diff, List<ElementDefinition> snapshot, Element cclss, String path, Element attr) throws FHIRFormatError {
String n = attr.getAttribute("name");
ElementDefinition ed = new ElementDefinition();
ed.setPath(path + "." + n);
ed.setMin(Integer.parseInt(attr.getAttribute("minimumMultiplicity")));
ed.setMax(attr.getAttribute("maximumMultiplicity"));
if (ed.getMax().equals("0"))
return;
seePath(ed);
if (!Utilities.noString(attr.getAttribute("namespace")))
ed.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType(attr.getAttribute("namespace")));
String type = getType(attr);
if ("true".equals(attr.getAttribute("isImmutable"))) {
if (primitiveTypes.containsKey(type))
type = primitiveTypes.get(type);
else
throw new Error("Immutable attribute that is not a primitive type");
ed.addRepresentation(PropertyRepresentation.XMLATTR);
}
if ("GTS".equals(type)) {
ed.setMax("*");
ed.addRepresentation(PropertyRepresentation.TYPEATTR);
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/IVL_TS");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/EIVL_TS");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/PIVL_TS");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/SXPR_TS");
ed.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-defaulttype").setValue(new StringType("SXPR_TS"));
} else if ("ANY".equals(type)) {
ed.addRepresentation(PropertyRepresentation.TYPEATTR);
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/BL");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/ED");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/ST");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/CD");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/CV");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/CE");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/SC");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/II");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/TEL");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/AD");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/EN");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/INT");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/REAL");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/PQ");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/MO");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/TS");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/IVL_PQ");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/IVL_TS");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/PIVL_TS");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/EIVL_TS");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/SXPR_TS");
} else if (isPrimitive(type))
ed.addType().setCode(type);
else if (Utilities.existsInList(type, "PN"))
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/EN");
else if (Utilities.existsInList(type, "ON"))
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/ST");
else if (Utilities.existsInList(type, "NARRATIVE")) {
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/StrucDoc.Text");
ed.addRepresentation(PropertyRepresentation.CDATEXT);
} else
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/" + type);
if ("R".equals(attr.getAttribute("conformance")))
ed.setMustSupport(true);
if (attr.hasAttribute("defaultValue"))
ed.setDefaultValue(buildValue(attr.getAttribute("defaultValue"), type, ed.getPath()));
List<Element> enums = new ArrayList<Element>();
XMLUtil.getNamedChildren(attr, "enumerationValue", enums);
if (enums.size() == 1)
ed.setFixed(buildValue(enums.get(0).getTextContent(), type, ed.getPath()));
if (enums.size() > 1) {
// throw new Error("todo: enums on "+ed.getPath());
} else if (XMLUtil.getNamedChild(attr, "vocabulary") != null) {
// <vocabulary codingStrength="CWE"><conceptDomain name="ActClass"/></vocabulary>
Element vocab = XMLUtil.getNamedChild(attr, "vocabulary");
String cs = vocab.getAttribute("codingStrength");
String cd = XMLUtil.getNamedChildAttribute(vocab, "conceptDomain", "name");
ElementDefinitionBindingComponent bd = ed.getBinding();
bd.setStrength(cs.equals("CNE") ? BindingStrength.REQUIRED : BindingStrength.EXTENSIBLE);
bd.setValueSet("http://terminology.hl7.org/ValueSet/v3-" + cd);
v3vs.add(cd);
}
diff.add(ed);
snapshot.add(popBase(ed));
}
use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project kindling by HL7.
the class SpreadSheetCreator method bind.
private String bind(ElementDefinition ed, XSSFSheet bindings) {
if (ed.hasBinding()) {
Row row = bindings.createRow(bindingRowCount++);
int columnCount = 0;
String name;
ElementDefinitionBindingComponent bs = ed.getBinding();
if (bs.hasExtension(BuildExtensions.EXT_NAME) && bs.hasExtension(BuildExtensions.EXT_BINDING_NAME)) {
bs.removeExtension(BuildExtensions.EXT_NAME);
}
sortExtensions(bs);
if (bs.hasExtension(BuildExtensions.EXT_BINDING_NAME)) {
name = bs.getExtensionString(BuildExtensions.EXT_BINDING_NAME);
} else {
name = "??";
}
addCell(name, row, columnCount++);
addCell(ext(bs, BuildExtensions.EXT_DEFINITION), row, columnCount++);
addCell(bs.getStrength().toCode(), row, columnCount++);
addCell(bs.getValueSet(), row, columnCount++);
addCell(bs.getDescription(), row, columnCount++);
addCell(ext(bs, BuildExtensions.EXT_VS_OID), row, columnCount++);
addCell(ext(bs, BuildExtensions.EXT_URI), row, columnCount++);
addCell(ext(bs, BuildExtensions.EXT_WEBSITE), row, columnCount++);
addCell(ext(bs, BuildExtensions.EXT_V2_MAP), row, columnCount++);
addCell(ext(bs, BuildExtensions.EXT_V3_MAP), row, columnCount++);
addCell(ext(bs, BuildExtensions.EXT_COPYRIGHT), row, columnCount++);
addCell(ext(bs, BuildExtensions.EXT_COMMITTEE_NOTES), row, columnCount++);
return name;
}
return null;
}
use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project kindling by HL7.
the class PageProcessor method txItem.
public void txItem(int level, Map<String, ElementDefinitionBindingComponent> txmap, StringBuilder b, String path) throws FHIRException {
ElementDefinitionBindingComponent tx = txmap.get(path);
String vss = "";
String vsn = "?ext";
if (tx.hasValueSet()) {
if (tx.hasValueSet()) {
String uri = tx.getValueSet();
if (uri.contains("|"))
uri = uri.substring(0, uri.indexOf("|"));
ValueSet vs = definitions.getValuesets().get(uri);
if (vs == null) {
if (uri.startsWith("http://hl7.org/fhir/ValueSet/")) {
vss = "<a href=\"" + genlevel(level) + "valueset-" + uri.substring(29) + ".html\">" + Utilities.escapeXml(uri.substring(29)) + "</a><!-- b -->";
} else {
vss = "<a href=\"" + genlevel(level) + uri + "\">" + Utilities.escapeXml(uri) + "</a><!-- c -->";
}
} else {
vss = "<a href=\"" + (Utilities.isAbsoluteUrl(vs.getUserString("path")) ? "" : genlevel(level)) + vs.getUserData("path") + "\">" + Utilities.escapeXml(vs.present()) + "</a><!-- d -->";
vsn = vs.present();
}
}
}
if (vsn.equals("?ext"))
System.out.println("No value set at " + path);
b.append("<tr><td>").append(path).append("</td><td>").append(Utilities.escapeXml(vsn)).append("</td><td><a href=\"").append(genlevel(level)).append("terminologies.html#").append(tx.getStrength() == null ? "" : tx.getStrength().toCode()).append("\">").append(tx.getStrength() == null ? "" : tx.getStrength().toCode()).append("</a></td><td>").append(vss).append("</td></tr>\r\n");
}
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, boolean snapshot) throws IOException, FHIRException {
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;
String ref2 = null;
String fixedUrl = null;
if (ed != null) {
String p = ed.getUserString("path");
if (p != null) {
ref = p.startsWith("http:") || igmode ? p : Utilities.pathURL(corePath, p);
}
fixedUrl = getFixedUrl(ed);
if (fixedUrl != null) {
// if its null, we guess that it's not a profiled extension?
if (fixedUrl.equals(url))
fixedUrl = null;
else {
StructureDefinition ed2 = context.fetchResource(StructureDefinition.class, fixedUrl);
if (ed2 != null) {
String p2 = ed2.getUserString("path");
if (p2 != null) {
ref2 = p2.startsWith("http:") || igmode ? p2 : Utilities.pathURL(corePath, p2);
}
}
}
}
}
if (fixedUrl == null) {
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));
} else {
// reference to a profile take on the extension show the base URL
c.getPieces().add(gen.new Piece(null, translate("sd.table", "URL") + ": ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(ref2, fixedUrl, null));
c.getPieces().add(gen.new Piece(null, translate("sd.table", " profiled by ") + " ", 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));
}
if (binding.hasExtension(ToolingExtensions.EXT_MAX_VALUESET)) {
br = pkp.resolveBinding(profile, ToolingExtensions.readStringExtension(binding, ToolingExtensions.EXT_MAX_VALUESET), definition.getPath());
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(binding, gen.new Piece(corePath + "extension-elementdefinition-maxvalueset.html", translate("sd.table", "Max Binding") + ": ", "Max Value Set Extension").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.hasExtension(ToolingExtensions.EXT_MIN_VALUESET)) {
br = pkp.resolveBinding(profile, ToolingExtensions.readStringExtension(binding, ToolingExtensions.EXT_MIN_VALUESET), definition.getPath());
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(binding, gen.new Piece(corePath + "extension-elementdefinition-minvalueset.html", translate("sd.table", "Min Binding") + ": ", "Min Value Set Extension").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)));
}
}
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")));
if (!useTableForFixedValues || definition.getFixed().isPrimitive()) {
String s = buildJson(definition.getFixed());
String link = null;
if (Utilities.isAbsoluteUrl(s))
link = pkp.getLinkForUrl(corePath, s);
c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(link, s, null).addStyle("color: darkgreen")));
} else {
c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "As shown", null).addStyle("color: darkgreen")));
genFixedValue(gen, row, definition.getFixed(), snapshot, false, corePath);
}
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")));
if (!useTableForFixedValues || definition.getPattern().isPrimitive())
c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, buildJson(definition.getPattern()), null).addStyle("color: darkgreen")));
else {
c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, "At least the following", null).addStyle("color: darkgreen")));
genFixedValue(gen, row, definition.getPattern(), snapshot, true, corePath);
}
} 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 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("#" + addValueSet(cvs));
superBinding.setValueSet("#" + addValueSet(unite(superset, outcome, path, lvs, rvs)));
}
}
return false;
}
Aggregations