Auto update minimum slicing cardinality when slicer is assumed (extensions)

This commit is contained in:
Grahame Grieve 2023-06-05 21:16:14 +02:00
parent 1c4ef1fa00
commit fd346cc67b
2 changed files with 16 additions and 12 deletions

View File

@ -157,8 +157,7 @@ public class ProfilePathProcessor {
* @throws DefinitionException, FHIRException * @throws DefinitionException, FHIRException
* @throws Exception * @throws Exception
*/ */
private ElementDefinition processPaths( private ElementDefinition processPaths(final ProfilePathProcessorState cursors) throws FHIRException {
final ProfilePathProcessorState cursors) throws FHIRException {
debugProcessPathsEntry(cursors); debugProcessPathsEntry(cursors);
ElementDefinition res = null; ElementDefinition res = null;
List<TypeSlice> typeList = new ArrayList<>(); List<TypeSlice> typeList = new ArrayList<>();
@ -253,9 +252,8 @@ public class ProfilePathProcessor {
.incrementDebugIndent() .incrementDebugIndent()
.withBaseLimit(newBaseLimit) .withBaseLimit(newBaseLimit)
.withDiffLimit(newDiffLimit) .withDiffLimit(newDiffLimit)
.withProfileName(getProfileName() + profileUtilities.pathTail(diffMatches, 0)).withSlicing(new PathSlicingParams(true, null, null)). .withProfileName(getProfileName() + profileUtilities.pathTail(diffMatches, 0)).withSlicing(new PathSlicingParams(true, null, null))
processPaths(new ProfilePathProcessorState(cursors.base, cursors.baseCursor, newDiffCursor, .processPaths(new ProfilePathProcessorState(cursors.base, cursors.baseCursor, newDiffCursor, cursors.contextName, cursors.resultPathBase));
cursors.contextName, cursors.resultPathBase));
if (e == null) if (e == null)
throw new FHIRException(profileUtilities.getContext().formatMessage(I18nConstants.DID_NOT_FIND_SINGLE_SLICE_, diffMatches.get(0).getPath())); throw new FHIRException(profileUtilities.getContext().formatMessage(I18nConstants.DID_NOT_FIND_SINGLE_SLICE_, diffMatches.get(0).getPath()));
e.setSlicing(diffMatches.get(0).getSlicing()); e.setSlicing(diffMatches.get(0).getSlicing());
@ -267,9 +265,10 @@ public class ProfilePathProcessor {
outcome.setPath(profileUtilities.fixedPathDest(getContextPathTarget(), outcome.getPath(), getRedirector(), getContextPathSource())); outcome.setPath(profileUtilities.fixedPathDest(getContextPathTarget(), outcome.getPath(), getRedirector(), getContextPathSource()));
profileUtilities.updateFromBase(outcome, currentBase, getSourceStructureDefinition().getUrl()); profileUtilities.updateFromBase(outcome, currentBase, getSourceStructureDefinition().getUrl());
if (!diffMatches.get(0).hasSlicing()) if (!diffMatches.get(0).hasSlicing()) {
outcome.setSlicing(profileUtilities.makeExtensionSlicing()); outcome.setSlicing(profileUtilities.makeExtensionSlicing());
else { outcome.setUserData("auto-added-slicing", true);
} else {
outcome.setSlicing(diffMatches.get(0).getSlicing().copy()); outcome.setSlicing(diffMatches.get(0).getSlicing().copy());
for (int i = 1; i < diffMatches.size(); i++) { for (int i = 1; i < diffMatches.size(); i++) {
if (diffMatches.get(i).hasSlicing()) { if (diffMatches.get(i).hasSlicing()) {
@ -348,7 +347,8 @@ public class ProfilePathProcessor {
.withBaseLimit(newBaseLimit) .withBaseLimit(newBaseLimit)
.withDiffLimit(newDiffLimit) .withDiffLimit(newDiffLimit)
.withProfileName(getProfileName() + profileUtilities.pathTail(diffMatches, i)) .withProfileName(getProfileName() + profileUtilities.pathTail(diffMatches, i))
.withSlicing(new PathSlicingParams(true, slicerElement, null)).processPaths(new ProfilePathProcessorState(cursors.base, cursors.baseCursor, newDiffCursor, cursors.contextName, cursors.resultPathBase)); .withSlicing(new PathSlicingParams(true, slicerElement, null))
.processPaths(new ProfilePathProcessorState(cursors.base, cursors.baseCursor, newDiffCursor, cursors.contextName, cursors.resultPathBase));
} }
// ok, done with that - next in the base list // ok, done with that - next in the base list
cursors.baseCursor = newBaseLimit + 1; cursors.baseCursor = newBaseLimit + 1;

View File

@ -777,17 +777,21 @@ public class ProfileUtilities extends TranslatingUtilities {
int count = slice.checkMin(); int count = slice.checkMin();
boolean repeats = !"1".equals(slice.getFocus().getBase().getMax()); // type slicing if repeats = 1 boolean repeats = !"1".equals(slice.getFocus().getBase().getMax()); // type slicing if repeats = 1
if (count > -1 && repeats) { if (count > -1 && repeats) {
String msg = "The slice definition for "+slice.getFocus().getId()+" has a minimum of "+slice.getFocus().getMin()+" but the slices add up to a minimum of "+count; if (slice.getFocus().hasUserData("auto-added-slicing")) {
messages.add(new ValidationMessage(Source.ProfileValidator, ValidationMessage.IssueType.VALUE, url+"#"+ed.getId(), msg, forPublication ? ValidationMessage.IssueSeverity.ERROR : ValidationMessage.IssueSeverity.INFORMATION)); slice.getFocus().setMin(count);
} else {
String msg = "The slice definition for "+slice.getFocus().getId()+" has a minimum of "+slice.getFocus().getMin()+" but the slices add up to a minimum of "+count;
messages.add(new ValidationMessage(Source.ProfileValidator, ValidationMessage.IssueType.VALUE, url+"#"+slice.getFocus().getId(), msg, forPublication ? ValidationMessage.IssueSeverity.ERROR : ValidationMessage.IssueSeverity.INFORMATION));
}
} }
count = slice.checkMax(); count = slice.checkMax();
if (count > -1 && repeats) { if (count > -1 && repeats) {
String msg = "The slice definition for "+slice.getFocus().getId()+" has a maximum of "+slice.getFocus().getMax()+" but the slices add up to a maximum of "+count+". Check that this is what is intended"; String msg = "The slice definition for "+slice.getFocus().getId()+" has a maximum of "+slice.getFocus().getMax()+" but the slices add up to a maximum of "+count+". Check that this is what is intended";
messages.add(new ValidationMessage(Source.ProfileValidator, ValidationMessage.IssueType.VALUE, url+"#"+ed.getId(), msg, ValidationMessage.IssueSeverity.INFORMATION)); messages.add(new ValidationMessage(Source.ProfileValidator, ValidationMessage.IssueType.VALUE, url+"#"+slice.getFocus().getId(), msg, ValidationMessage.IssueSeverity.INFORMATION));
} }
if (!slice.checkMinMax()) { if (!slice.checkMinMax()) {
String msg = "The slice definition for "+slice.getFocus().getId()+" has a maximum of "+slice.getFocus().getMax()+" which is less than the minimum of "+slice.getFocus().getMin(); String msg = "The slice definition for "+slice.getFocus().getId()+" has a maximum of "+slice.getFocus().getMax()+" which is less than the minimum of "+slice.getFocus().getMin();
messages.add(new ValidationMessage(Source.ProfileValidator, ValidationMessage.IssueType.VALUE, url+"#"+ed.getId(), msg, ValidationMessage.IssueSeverity.WARNING)); messages.add(new ValidationMessage(Source.ProfileValidator, ValidationMessage.IssueType.VALUE, url+"#"+slice.getFocus().getId(), msg, ValidationMessage.IssueSeverity.WARNING));
} }
slices.remove(s); slices.remove(s);
} }