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

issues #3216 and #2512 - support for alternative reference schemes and bundle ref resolution from FHIRPath ResolveFunction #3335

Merged
merged 3 commits into from
Feb 15, 2022

Conversation

lmsurpre
Copy link
Member

@lmsurpre lmsurpre commented Feb 11, 2022

This PR adds support for alternative schemes, like resource:, in our
Reference type checking / reference value validation.
Previously, we required reference values to use the http:, https:, or urn: schemes,
but that prevented us from supporting alternative schemes like resource: which is
used in the SMART health cards spec.

I thought that I would need to do additional logic for supporting
reference rewriting for this scheme but, based on the tests I added in
FHIRRestHelperTest and ReferenceMappingVisitorTest, apparently not
...we just needed to let it past our parser.

I also included updates to our FHIRPath ResolveFunction implementation so that we can more easily
resolve local bundle references from FHIRPath.

Signed-off-by: Lee Surprenant lmsurpre@us.ibm.com

@lmsurpre lmsurpre force-pushed the issue-3216 branch 2 times, most recently from 7873aea to 5903ddc Compare February 11, 2022 21:42
In addition, this commit adds support for the `resource:` scheme in our
Reference type checking / reference value validation. This scheme is
used in the SMART health cards spec and so I think it makes sense to
explicitly allow it.

I thought that I would need to do additional logic for supporting
reference rewriting for this scheme but, based on the test I added to
FHIRRestHelperTest, apparently not...we just needed to let it past our
parser.

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
@lmsurpre lmsurpre changed the title issue #3216 - support bundle reference resolution from FHIRPathResolve issues #3216 and #2512 - support for resource: scheme and bundle ref resolution from FHIRPathResolve Feb 11, 2022
bundleResources.put(e.getFullUrl().getValue(), e.getResource());
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

While this is rare, what happens in a bundle contained in a bundle

Bundle.Entry.Resource.contained.Resource

or

Bundle.Entry.Resource where that is a Bundle

My suspicion is that it could end up processing them as bundled elements.

Is that OK?

Copy link
Member Author

@lmsurpre lmsurpre Feb 14, 2022

Choose a reason for hiding this comment

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

my assumption is that we set the rootResource to the outermost bundle (the one we're evaluating against).
i tried to account for the "bundle-in-a-bundle" case in the algorithm below by continuing to loop until we've reached the top of the tree. I'll add a single test case to double-check it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We have some helper functions (in FHIRPathUtil) that get the right resource depending on how it might be nested. These are typically stashed in the EvaluationContext.

Copy link
Member Author

@lmsurpre lmsurpre Feb 14, 2022

Choose a reason for hiding this comment

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

I added the test. I can think of a couple "interesting edge cases" but they seem so edge to me that I don't care so much about what our behavior is there.

  1. what to do if we have a Bundle thats contained within some other resource that is not a bundle (and that outer resource is the root/context). With the current impl, we will not do local bundle resolution in that case, which seems fine to me.

  2. what to do if we have a relative literal reference (e.g. Patient/1) in a Bundle.entry where that Bundle is inside another Bundle but the outer Bundle has no fullUrl for this entry. in this scenario, I think the current algorithm will use the fullUrl from the inner bundle's entry to convert the relative URL into an absolute one. I don't know if that behavior is desired or not, but again it seems like such an edge case that the impl seems ok to me

if (isBundleContext) {
// we know the root of the tree is a Bundle and the current node is of type Reference,
// so walk up the tree until we get to highest Bundle.entry.fullUrl in the tree
// and save the value of its fullUrl
Copy link
Contributor

Choose a reason for hiding this comment

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

While the comment really does help... .

Could you layout a small example? or link to a test example?

If I have to maintain it, it'd help to laser focus on the 'aaah-ha' that's what it does.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added some examples to this comment (and also a test case for the Bundle-in-Bundle case)

// relative reference
resource = resolveRelativeReference(evaluationContext, node, resourceType, matcher.group(LOGICAL_ID_GROUP), matcher.group(VERSION_ID_GROUP));

String bundleReference = FHIRUtil.buildBundleReference(reference, fullUrl);
Copy link
Contributor

Choose a reason for hiding this comment

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

Note for others reviewing... when fuller is null, it'll return the referenceUriString = ref.getReference().getValue();

when this condition is true (ref.getReference() != null && ref.getReference().getValue() != null)

Copy link
Member Author

Choose a reason for hiding this comment

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

I assume fuller is a typo and should be fullUrl, but yes that sounds right. FHIRUtil.buildBundleReference wasn't well-documented and so I included some javadoc updates for that method as part of this one

Copy link
Contributor

@prb112 prb112 left a comment

Choose a reason for hiding this comment

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

Left comments for clarification.

LGTM

@lmsurpre lmsurpre requested a review from JohnTimm February 14, 2022 17:11
Copy link
Collaborator

@JohnTimm JohnTimm left a comment

Choose a reason for hiding this comment

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

LGTM

Per discussion at
https://chat.fhir.org/#narrow/stream/179166-implementers/topic/Allowed.20uri.20schemes.20for.20Bundle.2Eentry.2EfullUrl.20and.20referenc.2E.2E.2E/near/271636029

We'll still reject literal reference values that begin or end with `:`
and anything that looks like a "relative" URL path but doesn't follow
the FHIR REST URL Pattern (e.g. a literal value like "123" with no
scheme prefix).

I also provided some algorithm examples in a comment and added a single
local Bundle reference resolution test for the Bundle-in-a-Bundle case.

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
@lmsurpre lmsurpre added the removal this change involves removal of a component, class, method, etc label Feb 15, 2022
Copy link
Collaborator

@punktilious punktilious left a comment

Choose a reason for hiding this comment

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

LGTM

@lmsurpre lmsurpre changed the title issues #3216 and #2512 - support for resource: scheme and bundle ref resolution from FHIRPathResolve issues #3216 and #2512 - support for alternative reference schemes and bundle ref resolution from FHIRPath ResolveFunction Feb 15, 2022
I also added some comments to ResolveFunctionTest to address PR feedback

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
@lmsurpre lmsurpre added the ci-skip Skips the CI Build label Feb 15, 2022
@lmsurpre lmsurpre merged commit c5f0e9d into main Feb 15, 2022
@lmsurpre lmsurpre deleted the issue-3216 branch February 15, 2022 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-skip Skips the CI Build removal this change involves removal of a component, class, method, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants