-
Notifications
You must be signed in to change notification settings - Fork 15
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 for resolve() #42
Comments
I haven't got the bandwidth to add resolve natively, but in case anyone is looking for a naive implementation to use externally, this works well: def evaluate_with_resolve(bundle, fhirpath):
if '.resolve()' not in fhirpath:
return evaluate(bundle, fhirpath)
path_segments = fhirpath.split('.resolve()')
current_result = evaluate(bundle, path_segments[0])
for segment in path_segments[1:]:
if not current_result:
return None
reference_id = current_result[0]
if not reference_id:
return None
# Find referenced resource in bundle
referenced_resource = next(
(entry['resource'] for entry in bundle['entry']
if entry.get('fullUrl') == reference_id),
None)
if not referenced_resource:
return None
current_result = evaluate(referenced_resource, segment.lstrip('.'))
return current_result |
Hi @vadi2, thanks for posting your solution, it's useful feature. The only addition from my side to this feature - it should follow the specification of resolving references, in that case reference 'Patient/123' should be also resolved into the entry with fullUrl http://example.com/fhir/Patient/123. |
The fhirpath specification says nothing about how exactly url's should be resolved. For me, it looks logical to have a Bundle as context, and use it like: |
FYI: we do this by patching the invocation table: from fhirpathpy.engine.invocations import invocation_registry
# add custom resolve fn to the invocations_register
invocation_registry["resolve"] = {"fn": resolve, "arity": {0: []}}
evaluate({...}, "Patient.subject.resolve()") But not sure if it's ok to use |
It would be nice if resolve() was supported for references that are within the Bundle you are operating on.
The text was updated successfully, but these errors were encountered: