Support for Obligation Profiles

This commit is contained in:
Grahame Grieve 2023-05-29 01:12:46 +03:00
parent ece4a44ff2
commit 783a8cf28b
12 changed files with 383 additions and 26 deletions

View File

@ -304,7 +304,7 @@ public class ProfilePathProcessor {
if (profileUtilities.hasInnerDiffMatches(getDifferential(), currentBasePath, cursors.diffCursor, getDiffLimit(), cursors.base.getElement(), false)) {
if (baseHasChildren(cursors.base, currentBase)) { // not a new type here
if (cursors.diffCursor == 0) {
throw new DefinitionException("Error: The profile has slicing at the root, which is illegal");
throw new DefinitionException("Error: The profile has slicing at the root ('"+currentBase.getPath()+"'), which is illegal");
} else {
throw new Error("This situation is not yet handled (constrain slicing to 1..1 and fix base slice for inline structure - please report issue to grahame@fhir.org along with a test case that reproduces this error (@ " + currentBasePath + " | " + currentBase.getPath() + ")");
}
@ -766,6 +766,7 @@ public class ProfilePathProcessor {
outcome.setPath(profileUtilities.fixedPathDest(getContextPathTarget(), outcome.getPath(), getRedirector(), getContextPathSource()));
profileUtilities.updateFromBase(outcome, currentBase, getSourceStructureDefinition().getUrl());
profileUtilities.updateConstraintSources(outcome, getSourceStructureDefinition().getUrl());
profileUtilities.updateFromObligationProfiles(outcome);
profileUtilities.updateURLs(url, webUrl, outcome);
profileUtilities.markDerived(outcome);
if (cursors.resultPathBase == null)

View File

@ -61,6 +61,7 @@ import org.hl7.fhir.r5.model.Element;
import org.hl7.fhir.r5.model.ElementDefinition;
import org.hl7.fhir.r5.model.ElementDefinition.DiscriminatorType;
import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBaseComponent;
import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingAdditionalComponent;
import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent;
import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent;
import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionExampleComponent;
@ -349,7 +350,8 @@ public class ProfileUtilities extends TranslatingUtilities {
private AllowUnknownProfile allowUnknownProfile = AllowUnknownProfile.ALL_TYPES;
private MappingMergeModeOption mappingMergeMode = MappingMergeModeOption.APPEND;
private boolean forPublication;
private List<StructureDefinition> obligationProfiles = new ArrayList<>();
public ProfileUtilities(IWorkerContext context, List<ValidationMessage> messages, ProfileKnowledgeProvider pkp, FHIRPathEngine fpe) {
super();
this.context = context;
@ -627,6 +629,8 @@ public class ProfileUtilities extends TranslatingUtilities {
checkDifferentialBaseType(derived);
copyInheritedExtensions(base, derived);
findInheritedObligationProfiles(derived);
// so we have two lists - the base list, and the differential list
// the differential list is only allowed to include things that are in the base list, but
// is allowed to include them multiple times - thereby slicing them
@ -853,6 +857,17 @@ public class ProfileUtilities extends TranslatingUtilities {
}
}
private void findInheritedObligationProfiles(StructureDefinition derived) {
for (Extension ext : derived.getExtensionsByUrl(ToolingExtensions.EXT_OBLIGATION_INHERITS)) {
StructureDefinition op = context.fetchResource(StructureDefinition.class, ext.getValueCanonicalType().primitiveValue());
if (op != null && ToolingExtensions.readBoolExtension(op, ToolingExtensions.EXT_OBLIGATION_PROFILE_FLAG)) {
if (derived.getBaseDefinition().equals(op.getBaseDefinition())) {
obligationProfiles.add(op);
}
}
}
}
private void handleError(String url, String msg) {
if (exception)
throw new DefinitionException(msg);
@ -2065,6 +2080,63 @@ public class ProfileUtilities extends TranslatingUtilities {
return true;
}
public void updateFromObligationProfiles(ElementDefinition base) {
List<ElementDefinition> obligationProfileElements = new ArrayList<>();
for (StructureDefinition sd : obligationProfiles) {
ElementDefinition ed = sd.getSnapshot().getElementById(base.getId());
if (ed != null) {
obligationProfileElements.add(ed);
}
}
for (ElementDefinition ed : obligationProfileElements) {
for (Extension ext : ed.getExtension()) {
if (ToolingExtensions.EXT_OBLIGATION.equals(ext.getUrl())) {
base.getExtension().add(ext.copy());
}
}
}
boolean hasMustSupport = false;
for (ElementDefinition ed : obligationProfileElements) {
hasMustSupport = hasMustSupport || ed.hasMustSupportElement();
}
if (hasMustSupport) {
for (ElementDefinition ed : obligationProfileElements) {
mergeExtensions(base.getMustSupportElement(), ed.getMustSupportElement());
if (ed.getMustSupport()) {
base.setMustSupport(true);
}
}
}
boolean hasBinding = false;
for (ElementDefinition ed : obligationProfileElements) {
hasBinding = hasBinding || ed.hasBinding();
}
if (hasBinding) {
ElementDefinitionBindingComponent binding = base.getBinding();
for (ElementDefinition ed : obligationProfileElements) {
for (Extension ext : ed.getBinding().getExtension()) {
if (ToolingExtensions.EXT_BINDING_ADDITIONAL.equals(ext.getUrl())) {
String p = ext.getExtensionString("purpose");
if (!Utilities.existsInList(p, "maximum", "required", "extensible")) {
if (!binding.hasExtension(ext)) {
binding.getExtension().add(ext.copy());
}
}
}
}
for (ElementDefinitionBindingAdditionalComponent ab : ed.getBinding().getAdditional()) {
if (!Utilities.existsInList(ab.getPurpose().toCode(), "maximum", "required", "extensible")) {
if (!binding.hasAdditional(ab)) {
binding.getAdditional().add(ab.copy());
}
}
}
}
}
}
protected void updateFromDefinition(ElementDefinition dest, ElementDefinition source, String pn, boolean trimDifferential, String purl, StructureDefinition srcSD, StructureDefinition derivedSrc) throws DefinitionException, FHIRException {
source.setUserData(UD_GENERATED_IN_SNAPSHOT, dest);
// we start with a clone of the base profile ('dest') and we copy from the profile ('source')
@ -2073,11 +2145,29 @@ public class ProfileUtilities extends TranslatingUtilities {
ElementDefinition derived = source;
derived.setUserData(UD_DERIVATION_POINTER, base);
boolean isExtension = checkExtensionDoco(base);
List<ElementDefinition> obligationProfileElements = new ArrayList<>();
for (StructureDefinition sd : obligationProfiles) {
ElementDefinition ed = sd.getSnapshot().getElementById(base.getId());
if (ed != null) {
obligationProfileElements.add(ed);
}
}
for (Extension ext : source.getExtension()) {
if (Utilities.existsInList(ext.getUrl(), INHERITED_ED_URLS) && !dest.hasExtension(ext.getUrl())) {
dest.getExtension().add(ext.copy());
}
}
for (Extension ext : source.getExtension()) {
if (ToolingExtensions.EXT_OBLIGATION.equals(ext.getUrl())) {
dest.getExtension().add(ext.copy());
}
}
for (ElementDefinition ed : obligationProfileElements) {
for (Extension ext : ed.getExtension()) {
if (ToolingExtensions.EXT_OBLIGATION.equals(ext.getUrl())) {
dest.getExtension().add(ext.copy());
}
}
}
// Before applying changes, apply them to what's in the profile
@ -2282,12 +2372,23 @@ public class ProfileUtilities extends TranslatingUtilities {
// todo: what to do about conditions?
// condition : id 0..*
if (derived.hasMustSupportElement()) {
if (!(base.hasMustSupportElement() && Base.compareDeep(derived.getMustSupportElement(), base.getMustSupportElement(), false))) {
boolean hasMustSupport = derived.hasMustSupportElement();
for (ElementDefinition ed : obligationProfileElements) {
hasMustSupport = hasMustSupport || ed.hasMustSupportElement();
}
if (hasMustSupport) {
BooleanType mse = derived.getMustSupportElement().copy();
for (ElementDefinition ed : obligationProfileElements) {
mergeExtensions(mse, ed.getMustSupportElement());
if (ed.getMustSupport()) {
mse.setValue(true);
}
}
if (!(base.hasMustSupportElement() && Base.compareDeep(base.getMustSupportElement(), mse, false))) {
if (base.hasMustSupport() && base.getMustSupport() && !derived.getMustSupport()) {
messages.add(new ValidationMessage(Source.ProfileValidator, ValidationMessage.IssueType.BUSINESSRULE, pn+"."+derived.getPath(), "Illegal constraint [must-support = false] when [must-support = true] in the base profile", ValidationMessage.IssueSeverity.ERROR));
}
base.setMustSupportElement(derived.getMustSupportElement().copy());
base.setMustSupportElement(mse);
} else if (trimDifferential)
derived.setMustSupportElement(null);
else
@ -2324,7 +2425,32 @@ public class ProfileUtilities extends TranslatingUtilities {
derived.getIsModifierReasonElement().setUserData(UD_DERIVATION_EQUALS, true);
}
if (derived.hasBinding()) {
boolean hasBinding = derived.hasBinding();
for (ElementDefinition ed : obligationProfileElements) {
hasBinding = hasBinding || ed.hasBinding();
}
if (hasBinding) {
ElementDefinitionBindingComponent binding = derived.getBinding();
for (ElementDefinition ed : obligationProfileElements) {
for (Extension ext : ed.getBinding().getExtension()) {
if (ToolingExtensions.EXT_BINDING_ADDITIONAL.equals(ext.getUrl())) {
String p = ext.getExtensionString("purpose");
if (!Utilities.existsInList(p, "maximum", "required", "extensible")) {
if (!binding.hasExtension(ext)) {
binding.getExtension().add(ext.copy());
}
}
}
}
for (ElementDefinitionBindingAdditionalComponent ab : ed.getBinding().getAdditional()) {
if (!Utilities.existsInList(ab.getPurpose().toCode(), "maximum", "required", "extensible")) {
if (binding.hasAdditional(ab)) {
binding.getAdditional().add(ab.copy());
}
}
}
}
if (!base.hasBinding() || !Base.compareDeep(derived.getBinding(), base.getBinding(), false)) {
if (base.hasBinding() && base.getBinding().getStrength() == BindingStrength.REQUIRED && derived.getBinding().getStrength() != BindingStrength.REQUIRED)
messages.add(new ValidationMessage(Source.ProfileValidator, ValidationMessage.IssueType.BUSINESSRULE, pn+"."+derived.getPath(), "illegal attempt to change the binding on "+derived.getPath()+" from "+base.getBinding().getStrength().toCode()+" to "+derived.getBinding().getStrength().toCode(), ValidationMessage.IssueSeverity.ERROR));
@ -2365,7 +2491,7 @@ public class ProfileUtilities extends TranslatingUtilities {
if (d.hasValueSet()) {
nb.setValueSet(d.getValueSet());
}
base.setBinding(nb);
base.setBinding(nb);
} else if (trimDifferential)
derived.setBinding(null);
else
@ -2462,6 +2588,10 @@ public class ProfileUtilities extends TranslatingUtilities {
//updateURLs(url, webUrl, dest);
}
private void mergeExtensions(Element tgt, Element src) {
tgt.getExtension().addAll(src.getExtension());
}
private void addMappings(List<ElementDefinitionMappingComponent> destination, List<ElementDefinitionMappingComponent> source) {
for (ElementDefinitionMappingComponent s : source) {
boolean found = false;

View File

@ -304,6 +304,17 @@ public interface IWorkerContext {
return this;
}
public String unknownSystems() {
if (unknownSystems == null) {
return null;
}
if (unknownSystems.size() == 1) {
return unknownSystems.iterator().next();
} else {
return String.join(",", unknownSystems);
}
}
}
public class CodingValidationRequest {

View File

@ -441,8 +441,9 @@ public class XmlParser extends ParserBase {
parseChildren(npath, (org.w3c.dom.Element) child, n);
}
}
} else
} else {
logError(ValidationMessage.NO_RULE_DATE, line(child, false), col(child, false), path, IssueType.STRUCTURE, context.formatMessage(I18nConstants.UNDEFINED_ELEMENT_, child.getLocalName(), path), IssueSeverity.ERROR);
}
} else if (child.getNodeType() == Node.CDATA_SECTION_NODE){
logError(ValidationMessage.NO_RULE_DATE, line(child, false), col(child, false), path, IssueType.STRUCTURE, context.formatMessage(I18nConstants.CDATA_IS_NOT_ALLOWED), IssueSeverity.ERROR);
} else if (!Utilities.existsInList(child.getNodeType(), 3, 8)) {

View File

@ -457,6 +457,17 @@ public abstract class Element extends Base implements IBaseHasExtensions, IBaseE
ToolingExtensions.setStandardsStatus(this, status, null);
}
public boolean hasExtension(Extension ext) {
if (hasExtension()) {
for (Extension t : getExtension()) {
if (Base.compareDeep(t, ext, false)) {
return true;
}
}
}
return false;
}
// end addition
}

View File

@ -4919,6 +4919,17 @@ public boolean hasTarget() {
}
public boolean hasAdditional(ElementDefinitionBindingAdditionalComponent ab) {
if (hasAdditional()) {
for (ElementDefinitionBindingAdditionalComponent t : getAdditional()) {
if (Base.compareDeep(t, ab, false)) {
return true;
}
}
}
return false;
}
}
@Block()

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.terminologies.ValueSetUtilities;
import org.hl7.fhir.r5.terminologies.utilities.TerminologyServiceErrorClass;
/**
@ -74,4 +75,10 @@ public class ValueSetExpansionOutcome {
public boolean isOk() {
return (allErrors.isEmpty() || (allErrors.size() == 1 && allErrors.get(0) == null)) && error == null;
}
public int count() {
if (valueset == null) {
return 0;
}
return ValueSetUtilities.countExpansion(valueset);
}
}

View File

@ -1067,4 +1067,7 @@ public class ToolingExtensions {
return res;
}
public static final String EXT_OBLIGATION_PROFILE_FLAG = "http://hl7.org/fhir/tools/StructureDefinition/obligation-profile";
public static final String EXT_OBLIGATION_INHERITS = "http://hl7.org/fhir/tools/StructureDefinition/inherit-obligations";
}

View File

@ -439,6 +439,7 @@ public class I18nConstants {
public static final String TERMINOLOGY_TX_NOVALID_13 = "Terminology_TX_NoValid_13";
public static final String TERMINOLOGY_TX_NOVALID_14 = "Terminology_TX_NoValid_14";
public static final String TERMINOLOGY_TX_NOVALID_15 = "Terminology_TX_NoValid_15";
public static final String TERMINOLOGY_TX_NOVALID_15A = "Terminology_TX_NoValid_15A";
public static final String TERMINOLOGY_TX_NOVALID_16 = "Terminology_TX_NoValid_16";
public static final String TERMINOLOGY_TX_NOVALID_17 = "Terminology_TX_NoValid_17";
public static final String TERMINOLOGY_TX_NOVALID_18 = "Terminology_TX_NoValid_18";
@ -870,6 +871,19 @@ public class I18nConstants {
public static final String ATTEMPT_TO_CHANGE_SLICING = "ATTEMPT_TO_CHANGE_SLICING";
public static final String REPEAT_SLICING_IGNORED = "REPEAT_SLICING_IGNORED";
public static final String SD_ELEMENT_NOT_IN_CONSTRAINT = "SD_ELEMENT_NOT_IN_CONSTRAINT";
public static final String SD_OBGLIGATION_PROFILE_UKNOWN = "SD_OBGLIGATION_PROFILE_UKNOWN";
public static final String SD_OBGLIGATION_PROFILE_DERIVATION = "SD_OBGLIGATION_PROFILE_DERIVATION";
public static final String SD_OBGLIGATION_PROFILE_UNMATCHED = "SD_OBGLIGATION_PROFILE_UNMATCHED";
public static final String SD_OBGLIGATION_PROFILE_PATH_WRONG = "SD_OBGLIGATION_PROFILE_PATH_WRONG";
public static final String SD_OBGLIGATION_PROFILE_ILLEGAL = "SD_OBGLIGATION_PROFILE_ILLEGAL";
public static final String SD_OBGLIGATION_PROFILE_ILLEGAL_ON_BINDING = "SD_OBGLIGATION_PROFILE_ILLEGAL_ON_BINDING";
public static final String SD_OBGLIGATION_PROFILE_INVALID_BINDING_CODE = "SD_OBGLIGATION_PROFILE_INVALID_BINDING_CODE";
public static final String SD_OBGLIGATION_PROFILE_INVALID_BINDING_STRENGTH = "SD_OBGLIGATION_PROFILE_INVALID_BINDING_STRENGTH";
public static final String SD_OBGLIGATION_PROFILE_ILLEGAL_BINDING = "SD_OBGLIGATION_PROFILE_ILLEGAL_BINDING";
public static final String SD_OBGLIGATION_INHERITS_PROFILE_NO_TARGET = "SD_OBGLIGATION_INHERITS_PROFILE_NO_TARGET";
public static final String SD_OBGLIGATION_INHERITS_PROFILE_TARGET_NOT_FOUND = "SD_OBGLIGATION_INHERITS_PROFILE_TARGET_NOT_FOUND";
public static final String SD_OBGLIGATION_INHERITS_PROFILE_NOT_RIGHT_TYPE = "SD_OBGLIGATION_INHERITS_PROFILE_NOT_RIGHT_TYPE";
public static final String SD_OBGLIGATION_INHERITS_PROFILE_NOT_RIGHT_BASE = "SD_OBGLIGATION_INHERITS_PROFILE_NOT_RIGHT_BASE";
}

View File

@ -139,7 +139,7 @@ Terminology_PassThrough_TX_Message = {0} for ''{1}#{2}''
Terminology_TX_Binding_CantCheck = Binding by URI reference cannot be checked
Terminology_TX_Binding_Missing = Binding for CodeableConcept {0} missing
Terminology_TX_Binding_Missing2 = Binding for Coding {0} missing
Terminology_TX_Binding_NoServer = The value provided could not be validated in the absence of a terminology server
Terminology_TX_Binding_NoServer = The value provided ([{0}]) could not be validated in the absence of a terminology server
Terminology_TX_Binding_NoSource = Binding for path {0} has no source, so can''t be checked
Terminology_TX_Binding_NoSource2 = Binding has no source, so can''t be checked
Terminology_TX_Code_NotValid = Code {0} is not a valid code in code system {1}
@ -168,6 +168,7 @@ Terminology_TX_NoValid_12 = The Coding provided ({2}) is not in the value set {0
Terminology_TX_NoValid_13 = The Coding provided ({2}) is not in the value set {0}, and a code should come from this value set unless it has no suitable code (note that the validator cannot judge what is suitable). {1}
Terminology_TX_NoValid_14 = The Coding provided ({2}) is not in the value set {0}, and a code is recommended to come from this value set. {1}
Terminology_TX_NoValid_15 = The value provided (''{0}'') could not be validated in the absence of a terminology server
Terminology_TX_NoValid_15A = The value provided (''{0}'') could not be validated because the code system {1} is not known
Terminology_TX_NoValid_16 = The value provided (''{0}'') is not in the value set {1}, and a code is required from this value set){2}
Terminology_TX_NoValid_17 = The value provided (''{0}'') is not in the value set {1}, and a code should come from this value set unless it has no suitable code (note that the validator cannot judge what is suitable) {2}
Terminology_TX_NoValid_18 = The value provided (''{0}'') is not in the value set {1}, and a code is recommended to come from this value set){2}
@ -178,7 +179,7 @@ Terminology_TX_NoValid_5 = The Coding provided ({2}) is not in the value set {0}
Terminology_TX_NoValid_6 = The Coding provided ({2}) is not in the value set {0}, and a code is recommended to come from this value set {1}
Terminology_TX_NoValid_7 = None of the codes provided could be validated against the maximum value set {0}, (error = {2})
Terminology_TX_NoValid_8 = None of the codes provided are in the maximum value set {0}, and a code from this value set is required) (codes = {1})
Terminology_TX_NoValid_9 = The code provided could not be validated against the maximum value set {0}, (error = {1})
Terminology_TX_NoValid_9 = The code provided ({2}) could not be validated against the maximum value set {0}, (error = {1})
Terminology_TX_System_Invalid = Invalid System URI: {0}
Terminology_TX_System_NotKnown = Code System URI ''{0}'' is unknown so the code cannot be validated
Terminology_TX_System_Relative = Coding.system must be an absolute reference, not a local reference
@ -560,8 +561,8 @@ SEARCHPARAMETER_BASE_WRONG = The resource type {1} is not listed as a base in th
SEARCHPARAMETER_TYPE_WRONG = The type {1} is different to the type {0} in the derivedFrom SearchParameter
SEARCHPARAMETER_EXP_WRONG = The expression ''{2}'' is not compatible with the expression ''{1}'' in the derivedFrom SearchParameter {0}, and this likely indicates that the derivation relationship is not valid
VALUESET_NO_SYSTEM_WARNING = No System specified, so Concepts and Filters can't be checked
VALUESET_INCLUDE_INVALID_CONCEPT_CODE = The code {1} is not valid in the system {0}
VALUESET_INCLUDE_INVALID_CONCEPT_CODE_VER = The code {2} is not valid in the system {0} version {1}
VALUESET_INCLUDE_INVALID_CONCEPT_CODE = The code ''{1}'' is not valid in the system {0}
VALUESET_INCLUDE_INVALID_CONCEPT_CODE_VER = The code ''{2}'' is not valid in the system {0} version {1}
VALUESET_EXAMPLE_SYSTEM_HINT = Example System ''{0}'' specified, so Concepts and Filters can''t be checked
VALUESET_EXAMPLE_SYSTEM_ERROR = Example System ''{0}'' specified, which is illegal. Concepts and Filters can''t be checked
VALUESET_UNC_SYSTEM_WARNING = Unknown System ''{0}'' specified, so Concepts and Filters can''t be checked (Details: {1})
@ -924,3 +925,17 @@ ED_PATH_WRONG_TYPE_MATCH = The path must be ''{0}'' not ''{1}'' when the type li
ATTEMPT_TO_CHANGE_SLICING = The element at {0} defines the slicing {1} but then an element in the slicing {2} tries to redefine the slicing to {3}
REPEAT_SLICING_IGNORED = The element at {0} defines the slicing but then an element in the slicing {2} repeats it, which is ignored
SD_ELEMENT_NOT_IN_CONSTRAINT = The element definition for {1} has a property {0} which is not allowed in a profile
SD_OBGLIGATION_PROFILE_UKNOWN = The profile is marked as an obligation profile, but it's correctness cannot be checked since the base profile ''{0}'' is not known
SD_OBGLIGATION_PROFILE_DERIVATION = Only profiles that constrain another profile can be marked as an obligation profile
SD_OBGLIGATION_PROFILE_UNMATCHED = The element ''{0}'' has no equivalent in the profile ''{1}'' on which this Obligation Profile is based
SD_OBGLIGATION_PROFILE_PATH_WRONG = The element ''{0}'' path value of ''{1}'' doesn't match the base path ''{2}''
SD_OBGLIGATION_PROFILE_ILLEGAL = The element ''{0}'' has a property ''{1}'' which is not allowed in Obligation profiles
SD_OBGLIGATION_PROFILE_ILLEGAL_ON_BINDING = The element ''{0}'' has a binding property ''{1}'' which is not allowed in Obligation profiles
SD_OBGLIGATION_PROFILE_ILLEGAL_BINDING = The element ''{0}'' has a binding when the base element does not, and this is not allowed in Obligation profiles
SD_OBGLIGATION_PROFILE_INVALID_BINDING_CODE = The element ''{0}'' has an additional binding purpose of ''{1}'' which is not allowed in Obligation profiles
SD_OBGLIGATION_PROFILE_INVALID_BINDING_STRENGTH =The element ''{0}'' has a different binding strength (''{1}'') from the base (''{2}'') which is not allowed in Obligation profiles
SD_OBGLIGATION_INHERITS_PROFILE_NO_TARGET = Unable to read a value from this extension
SD_OBGLIGATION_INHERITS_PROFILE_TARGET_NOT_FOUND = The profile ''{0}'' could not be found
SD_OBGLIGATION_INHERITS_PROFILE_NOT_RIGHT_TYPE = The profile ''{0}'' is not marked as an obligation profile
SD_OBGLIGATION_INHERITS_PROFILE_NOT_RIGHT_BASE = The profile ''{0}'' has a different base ''{1}'' from that expected ''{2}''

View File

@ -123,24 +123,178 @@ public class StructureDefinitionValidator extends BaseValidator {
I18nConstants.SD_DERIVATION_KIND_MISMATCH, base.getKindElement().primitiveValue(), src.getChildValue("kind")) && ok;
}
}
List<Element> differentials = src.getChildrenByName("differential");
List<Element> snapshots = src.getChildrenByName("snapshot");
boolean logical = "logical".equals(src.getNamedChildValue("kind"));
boolean constraint = "constraint".equals(src.getNamedChildValue("derivation"));
for (Element differential : differentials) {
ok = validateElementList(errors, differential, stack.push(differential, -1, null, null), false, snapshots.size() > 0, sd, typeName, logical, constraint) && ok;
}
for (Element snapshotE : snapshots) {
ok = validateElementList(errors, snapshotE, stack.push(snapshotE, -1, null, null), true, true, sd, typeName, logical, constraint) && ok;
}
// obligation profile support
if (src.hasExtension(ToolingExtensions.EXT_OBLIGATION_PROFILE_FLAG)) {
Element ext = src.getExtension(ToolingExtensions.EXT_OBLIGATION_PROFILE_FLAG);
Element value = ext.getNamedChild("value");
if (value != null && "true".equals(value.primitiveValue())) {
if (rule(errors, "2023-05-27", IssueType.INVALID, stack.getLiteralPath(), "constraint".equals(src.getNamedChildValue("derivation")), I18nConstants.SD_OBGLIGATION_PROFILE_DERIVATION)) {
if (warning(errors, "2023-05-27", IssueType.NOTFOUND, stack.getLiteralPath(), base != null, I18nConstants.SD_OBGLIGATION_PROFILE_UKNOWN, src.getNamedChildValue("baseDefinition"))) {
for (Element differential : differentials) {
ok = validateObligationProfile(errors, differential, stack.push(differential, -1, null, null), base) && ok;
}
}
}
}
}
List<Element> extensions = src.getChildren("extension");
int c = 0;
for (Element extension : extensions) {
if (ToolingExtensions.EXT_OBLIGATION_INHERITS.equals(extension.getNamedChildValue("url"))) {
ok = validateInheritsObligationProfile(errors, extension, stack.push(extension, c, null, null), src) && ok;
}
c++;
}
} catch (Exception e) {
rule(errors, NO_RULE_DATE, IssueType.EXCEPTION, stack.getLiteralPath(), false, I18nConstants.ERROR_GENERATING_SNAPSHOT, e.getMessage());
ok = false;
}
List<Element> differentials = src.getChildrenByName("differential");
List<Element> snapshots = src.getChildrenByName("snapshot");
boolean logical = "logical".equals(src.getNamedChildValue("kind"));
boolean constraint = "constraint".equals(src.getNamedChildValue("derivation"));
for (Element differential : differentials) {
ok = validateElementList(errors, differential, stack.push(differential, -1, null, null), false, snapshots.size() > 0, sd, typeName, logical, constraint) && ok;
}
for (Element snapshot : snapshots) {
ok = validateElementList(errors, snapshot, stack.push(snapshot, -1, null, null), true, true, sd, typeName, logical, constraint) && ok;
}
return ok;
}
private boolean validateInheritsObligationProfile(List<ValidationMessage> errors, Element extension, NodeStack stack, Element src) {
String tgt = extension.getNamedChildValue("value");
if (rule(errors, "2023-05-27", IssueType.INVALID, stack.getLiteralPath(), tgt != null,
I18nConstants.SD_OBGLIGATION_INHERITS_PROFILE_NO_TARGET)) {
StructureDefinition sd = context.fetchResource(StructureDefinition.class, tgt);
if (rule(errors, "2023-05-27", IssueType.INVALID, stack.getLiteralPath(), src != null,
I18nConstants.SD_OBGLIGATION_INHERITS_PROFILE_TARGET_NOT_FOUND, tgt)) {
if (rule(errors, "2023-05-27", IssueType.INVALID, stack.getLiteralPath(), ToolingExtensions.readBoolExtension(sd, ToolingExtensions.EXT_OBLIGATION_PROFILE_FLAG),
I18nConstants.SD_OBGLIGATION_INHERITS_PROFILE_NOT_RIGHT_TYPE, tgt)) {
String base = src.getNamedChildValue("baseDefinition");
if (rule(errors, "2023-05-27", IssueType.INVALID, stack.getLiteralPath(), base != null && base.equals(sd.getBaseDefinition()),
I18nConstants.SD_OBGLIGATION_INHERITS_PROFILE_NOT_RIGHT_BASE, tgt, sd.getBaseDefinition(), base)) {
return true;
}
}
}
}
return false;
}
private boolean validateObligationProfile(List<ValidationMessage> errors, Element elementList, NodeStack stack, StructureDefinition base) {
boolean ok = true;
List<Element> elements = elementList.getChildrenByName("element");
int cc = 0;
for (Element element : elements) {
ok = validateObligationProfileElement(errors, element, stack.push(element, cc, null, null), base) && ok;
cc++;
}
return ok;
}
private boolean validateObligationProfileElement(List<ValidationMessage> errors, Element element, NodeStack push, StructureDefinition base) {
// rules: it must exist in the base snapshot
// it must only add must-support, obligations and extra bindings
String id = element.getNamedChildValue("id");
ElementDefinition bd = base.getSnapshot().getElementById(id);
if (rule(errors, "2023-05-27", IssueType.INVALID, push.getLiteralPath(), bd != null, I18nConstants.SD_OBGLIGATION_PROFILE_UNMATCHED, id, base.getVersionedUrl())) {
boolean ok = true;
String name = null;
int c = 0;
for (Element child : element.getChildren()) {
if (child.getName().equals(name)) {
c++;
} else {
name = child.getName();
c = 0;
}
NodeStack stack = push.push(child, c, null, null);
if (child.getName().equals("extension")) {
String url = child.getNamedChildValue("url");
if ("http://hl7.org/fhir/tools/StructureDefinition/obligation".equals(url)) {
// this is ok, and it doesn't matter what's in the obligation
} else {
ok = false;
rule(errors, "2023-05-27", IssueType.INVALID, stack.getLiteralPath(), false,
I18nConstants.SD_OBGLIGATION_PROFILE_ILLEGAL, id, child.getName()+"#"+url);
}
} else if (child.getName().equals("mustSupport")) {
// this is ok, and there's nothing to check
} else if (child.getName().equals("id")) {
// this is ok (it must have this), and there's nothing to check
} else if (child.getName().equals("binding")) {
if (rule(errors, "2023-05-27", IssueType.INVALID, stack.getLiteralPath(), bd.hasBinding(),
I18nConstants.SD_OBGLIGATION_PROFILE_ILLEGAL_BINDING, id)) {
ok = validateObligationProfileElementBinding(errors, child, stack, id, bd) && ok;
} else {
ok = false;
}
} else if (child.getName().equals("path")) {
ok = rule(errors, "2023-05-27", IssueType.INVALID, stack.getLiteralPath(), child.primitiveValue().equals(bd.getPath()),
I18nConstants.SD_OBGLIGATION_PROFILE_PATH_WRONG, id, child.primitiveValue(), bd.getPath()) && ok;
} else {
ok = false;
rule(errors, "2023-05-27", IssueType.INVALID, stack.getLiteralPath(), false,
I18nConstants.SD_OBGLIGATION_PROFILE_ILLEGAL, id, child.getName());
}
}
return ok;
} else {
return false;
}
}
private boolean validateObligationProfileElementBinding(List<ValidationMessage> errors, Element element, NodeStack nstack, String id, ElementDefinition bd) {
// rules can only have additional bindings
boolean ok = true;
String name = null;
int c = 0;
for (Element child : element.getChildren()) {
if (child.getName().equals(name)) {
c++;
} else {
name = child.getName();
c = 0;
}
NodeStack stack = nstack.push(child, c, null, null);
if (child.getName().equals("extension")) {
String url = child.getNamedChildValue("url");
if ("http://hl7.org/fhir/tools/StructureDefinition/additional-binding".equals(url) && !VersionUtilities.isR5Plus(context.getVersion())) {
Element purpose = child.getExtension("purpose");
if (purpose != null) { // should be an error elsewhere
String code = purpose.getNamedChildValue("value");
ok = rule(errors, "2023-05-27", IssueType.INVALID, stack.getLiteralPath(), !Utilities.existsInList(code, "maximum", "required", "extensible"),
I18nConstants.SD_OBGLIGATION_PROFILE_INVALID_BINDING_CODE, id, code) && ok;
}
} else {
ok = false;
rule(errors, "2023-05-27", IssueType.INVALID, stack.getLiteralPath(), false,
I18nConstants.SD_OBGLIGATION_PROFILE_ILLEGAL, id, child.getName()+"#"+url);
}
} else if (child.getName().equals("additional") && VersionUtilities.isR5Plus(context.getVersion())) {
String code = child.getNamedChildValue("purpose");
ok = rule(errors, "2023-05-27", IssueType.INVALID, stack.getLiteralPath(), !Utilities.existsInList(code, "maximum", "required", "extensible"),
I18nConstants.SD_OBGLIGATION_PROFILE_INVALID_BINDING_CODE, id, code) && ok;
} else if (child.getName().equals("strength")) {
// this has to be repeated, and has to be the same as the derivation
String strengthBase = bd.getBinding().getStrengthElement().asStringValue();
String strengthDerived = child.primitiveValue();
ok = rule(errors, "2023-05-27", IssueType.INVALID, stack.getLiteralPath(), strengthBase != null && strengthBase.equals(strengthDerived),
I18nConstants.SD_OBGLIGATION_PROFILE_INVALID_BINDING_STRENGTH, id, strengthDerived, strengthBase) && ok;
} else {
ok = false;
rule(errors, "2023-05-27", IssueType.INVALID, stack.getLiteralPath(), false,
I18nConstants.SD_OBGLIGATION_PROFILE_ILLEGAL_ON_BINDING, id, child.getName());
}
}
return ok;
}
private void checkExtensionContext(List<ValidationMessage> errors, Element src, NodeStack stack) {
String type = src.getNamedChildValue("type");
List<Element> eclist = src.getChildren("context");
@ -194,7 +348,6 @@ public class StructureDefinitionValidator extends BaseValidator {
rule(errors, "2022-11-02", IssueType.NOTFOUND, stack.getLiteralPath(), typeName == null || path == null || path.equals(typeName) || path.startsWith(typeName+"."), I18nConstants.SD_PATH_TYPE_MISMATCH, typeName, path);
if (!snapshot) {
rule(errors, "2023-01-17", IssueType.INVALID, stack.getLiteralPath(), path.contains(".") || !element.hasChild("slicing"), I18nConstants.SD_NO_SLICING_ON_ROOT, path);
}
rule(errors, "2023-05-22", IssueType.NOTFOUND, stack.getLiteralPath(), snapshot || !constraint || !element.hasChild("meaningWhenMissing") || meaningWhenMissingAllowed(element), I18nConstants.SD_ELEMENT_NOT_IN_CONSTRAINT, "meaningWhenMissing", path);

View File

@ -19,7 +19,7 @@
<properties>
<hapi_fhir_version>6.4.1</hapi_fhir_version>
<validator_test_case_version>1.3.7</validator_test_case_version>
<validator_test_case_version>1.3.8-SNAPSHOT</validator_test_case_version>
<jackson_version>2.14.0</jackson_version>
<junit_jupiter_version>5.9.2</junit_jupiter_version>
<junit_platform_launcher_version>1.8.2</junit_platform_launcher_version>