Merge pull request #1632 from hapifhir/Fix_hintAboutNonMustSupport

Fix handling of hintAboutNonMustSupport to actually be useful.  Speci…
This commit is contained in:
Grahame Grieve 2024-06-06 09:38:16 +10:00 committed by GitHub
commit d556db6dad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 161 additions and 147 deletions

View File

@ -1029,7 +1029,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);
@ -1042,10 +1042,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()) {
@ -6745,13 +6754,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())) {