Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support "position" slicing discriminator #1538

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mint-thompson
Copy link
Collaborator

Description:
FHIR R5 added "position" as an allowed slice discriminator, where slices are differentiated by their order within a list element. Because a consistent order is necessary for this slicing to be meaningful, emit an error if "ordered" is not set to true for the slicing. Previous versions of FHIR may not use this discriminator.

Minor changes to npm-shrinkwrap.json due to issues detected by npm audit.

Testing Instructions:
Confirm that new tests adequately cover this new feature. Try building projects with R4 and R5 resources using SUSHI, observing that the "position" discriminator can't be used with R4, but can be used with R5. There is also a new error message, so please let me know if you have suggestions for its wording.

Related Issue:
Partially addresses #1391, but does not validate Instances to confirm that slices are provided in the required order when position-based slicing is used.

FHIR R5 added "position" as an allowed slice discriminator, where slices
are differentiated by their order within a list element. Because a
consistent order is necessary for this slicing to be meaningful, emit an
error if "ordered" is not set to true for the slicing. Previous versions
of FHIR may not use this discriminator.

Minor changes to npm-shrinkwrap.json due to issues detected by `npm
audit`.
Copy link
Collaborator

@jafeltra jafeltra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense! I tested out the new slicing discriminator in R4 and R5, and it worked as expected!

Copy link
Member

@cmoesel cmoesel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm approving this, but I did make a minor suggestion that you can take or leave. And I also started a discussion on an alternate approach to ordered -- but I'm comfortable with it as-is if that's what other think is best.

Comment on lines +401 to +408
if (d.type === 'position' && slicing.ordered !== true) {
validationErrors.push(
new ValidationError(
'Slicing ordering must be true when a position discriminator is used.',
'slicing.ordered'
)
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's something to think about: If the user uses a position discriminator type, should we just set ordered to true for them? I.e., we know what it should be, so... just do it? Putting the "short" in "shorthand"?

I'm torn on it. I feel like if they don't set the ordered property themself using a caret rule, then it makes sense to set it for them. But if they had set it themself to the wrong value (false), then I'm not sure if silently setting it to true is the right thing to do...

Comment on lines +3094 to +3101
const ALLOWED_DISCRIMINATOR_TYPES_R5 = [
'value',
'exists',
'pattern',
'type',
'profile',
'position'
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion on this, but... it could be:

Suggested change
const ALLOWED_DISCRIMINATOR_TYPES_R5 = [
'value',
'exists',
'pattern',
'type',
'profile',
'position'
];
const ALLOWED_DISCRIMINATOR_TYPES_R5 = [...ALLOWED_DISCRIMINATOR_TYPES, 'position'];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants