Fix handling of hintAboutNonMustSupport to actually be useful. Specifically:

- don't yell about missing mustSupport if differential element is setting max to 0, is just declaring slicing, or has a fixed or pattern value
- make clear *what* element doesn't have a mustSupport element in a profile that should
This commit is contained in:
Lloyd McKenzie 2024-05-22 11:34:43 -05:00
parent dd608c5708
commit addc88bd20
2 changed files with 161 additions and 147 deletions

View File

@ -1025,7 +1025,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
validateResource(new ValidationContext(appContext, element), errors, element, element, defn, resourceIdRule, stack.resetIds(), null, new ValidationMode(ValidationReason.Validation, ProfileSource.ConfigProfile), false, false);
}
}
if (hintAboutNonMustSupport) {
if (hintAboutNonMustSupport && !profiles.isEmpty()) {
checkElementUsage(errors, element, stack);
}
codingObserver.finish(errors, stack);
@ -1038,10 +1038,19 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
private void checkElementUsage(List<ValidationMessage> errors, Element element, NodeStack stack) {
if (element.getPath()==null
|| (element.getName().equals("id") && !element.getPath().substring(0, element.getPath().length()-3).contains("."))
|| (element.getName().equals("text") && !element.getPath().substring(0, element.getPath().length()-5).contains(".")))
return;
String hasFixed = element.getUserString("hasFixed");
if (element.getPath().contains(".") && (hasFixed== null || !hasFixed.equals("Y"))) {
String elementUsage = element.getUserString("elementSupported");
hint(errors, NO_RULE_DATE, IssueType.INFORMATIONAL, element.line(), element.col(), stack.getLiteralPath(), elementUsage == null || elementUsage.equals("Y"), I18nConstants.MUSTSUPPORT_VAL_MUSTSUPPORT, element.getName(), element.getProperty().getStructure().getVersionedUrl());
hint(errors, NO_RULE_DATE, IssueType.INFORMATIONAL, element.line(), element.col(), stack.getLiteralPath(), elementUsage != null && (elementUsage.equals("Y") || elementUsage.equals("NA")), I18nConstants.MUSTSUPPORT_VAL_MUSTSUPPORT, element.getName(), element.getProperty().getStructure().getVersionedUrl());
if (elementUsage==null || !elementUsage.equals("Y"))
return;
}
if (element.hasChildren()) {
if (element.hasChildren() && (hasFixed== null || !hasFixed.equals("Y"))) {
String prevName = "";
int elementCount = 0;
for (Element ce : element.getChildren()) {
@ -6721,13 +6730,16 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
}
profile.setUserData("usesMustSupport", usesMustSupport);
}
if (usesMustSupport.equals("Y")) {
String elementSupported = ei.getElement().getUserString("elementSupported");
if (elementSupported == null || ei.definition.getMustSupport())
String fixedValue = ei.getElement().getUserString("hasFixed");
if ((elementSupported == null || !elementSupported.equals("Y")) && ei.definition.getMustSupport()) {
if (ei.definition.getMustSupport()) {
ei.getElement().setUserData("elementSupported", "Y");
}
}
} else if (elementSupported == null && !usesMustSupport.equals("Y"))
ei.getElement().setUserData("elementSupported", "NA");
if (fixedValue==null && (ei.definition.hasFixed() || ei.definition.hasPattern()))
ei.getElement().setUserData("hasFixed", "Y");
}
public boolean checkCardinalities(List<ValidationMessage> errors, StructureDefinition profile, Element element, NodeStack stack,

View File

@ -128,7 +128,9 @@ public class ProfileValidator extends BaseValidator {
throw new Error("Diff Element is null - this is not an expected thing");
ElementDefinition snapElement = snapshotElements.get(diffElement.getId());
if (snapElement!=null) { // Happens with profiles in the main build - should be able to fix once snapshot generation is fixed - Lloyd
warning(errors, NO_RULE_DATE, IssueType.BUSINESSRULE, diffElement.getId(), !checkMustSupport || snapElement.hasMustSupport(), "Elements included in the differential should declare mustSupport");
// We don't care about mustSupport for the root element, if the element is just declaring slicing, if there's a pattern or fixed value, or if the element is being prohibited.
boolean noMustSupport = !checkMustSupport || !snapElement.getPath().contains(".") || snapElement.hasSlicing() || snapElement.hasPattern() || snapElement.hasFixed() || snapElement.getMax().equals("0") || snapElement.hasMustSupport();
warning(errors, NO_RULE_DATE, IssueType.BUSINESSRULE, diffElement.getId(), noMustSupport, "Elements included in the differential that aren't prohibited and don't have fixed values or patterns should declare mustSupport: " + snapElement.getPath());
if (checkAggregation) {
for (TypeRefComponent type : snapElement.getType()) {
if ("http://hl7.org/fhir/Reference".equals(type.getWorkingCode()) || "http://hl7.org/fhir/canonical".equals(type.getWorkingCode())) {