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

FHIRPath ResolveFunction should work over a collections with multiple items #3475

Closed
lmsurpre opened this issue Mar 16, 2022 · 2 comments
Closed
Assignees
Labels
invalid This doesn't seem right

Comments

@lmsurpre
Copy link
Member

lmsurpre commented Mar 16, 2022

Describe the bug
US Core 4.0 defines the following contraint expression at http://hl7.org/fhir/us/core/STU4/StructureDefinition-us-core-provenance.html#constraints

((%resource.agent.who.resolve() is Practitioner) or (%resource.agent.who.resolve() is Device)) implies exists()

Currently, when our FHIRPath engine evaluates that against input with multiple agents, our resolve() function implementation rejects that:

java.lang.IllegalArgumentException: Input collection has 2 items, but only 1 is allowed

However, the definition at https://build.fhir.org/fhirpath.html#functions says that this should work over a collection:

resolve() : collection

For each item in the collection, if it is a string that is a uri (or canonical or url), locate the target of the reference, and add it to the resulting collection. If the item does not resolve to a resource, the item is ignored and nothing is added to the output collection.

The items in the collection may also represent a Reference, in which case the Reference.reference is resolved.

Environment
main

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Additional context
This particular constraint from US Core has other issues... https://hl7.org/fhirpath/#is-type-specifier says

If the input collections contains more than one item, the evaluator will throw an error.

So even if we fixed this issue in our resolve function, the constraint would still fail because we have a non-singleton collection on the lhs of the or operator.

I opened https://jira.hl7.org/browse/FHIR-36328 for this part of it, but we should consider patching this expression in our packaging of us core 4.0 when we fix this issue.

@lmsurpre lmsurpre added bug Something isn't working P2 Priority 2 - Should Have labels Mar 16, 2022
@lmsurpre
Copy link
Member Author

Opened #3490 for patching the fhirpath expression

@lmsurpre lmsurpre self-assigned this May 19, 2022
lmsurpre added a commit that referenced this issue May 19, 2022
technically we were already testing this under
testResolveBundleReference_HttpFullUrl, but having a dedicated test for
this case makes sense

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
@lmsurpre
Copy link
Member Author

lmsurpre commented May 19, 2022

I went to "fix" this and I found that our resolve function ALREADY supports multiple nodes in the input collection. The error from the description is actually coming from the is operator and this operator is correct to throw when there are multiple nodes as input.

I still opened a PR with the simple test I used to prove its working.

@lmsurpre lmsurpre added invalid This doesn't seem right and removed bug Something isn't working P2 Priority 2 - Should Have labels May 19, 2022
lmsurpre added a commit that referenced this issue Jun 9, 2022
issue #3475 - add test for multiple context nodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

1 participant