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

FI-2750: Add FHIRPath Support #520

Merged
merged 19 commits into from
Sep 10, 2024
Merged

FI-2750: Add FHIRPath Support #520

merged 19 commits into from
Sep 10, 2024

Conversation

vanessuniq
Copy link
Contributor

@vanessuniq vanessuniq commented Aug 21, 2024

Summary

This PR introduces FHIRPath support, enabling evaluation of FHIRPath expressions on FHIR resources using an external FHIRPath service. The new functionality allows tests to evaluate expressions and receive results from a configurable FHIRPath evaluator.

Copy link

codecov bot commented Aug 21, 2024

Codecov Report

Attention: Patch coverage is 89.13043% with 5 lines in your changes missing coverage. Please review.

Project coverage is 79.86%. Comparing base (586d3b8) to head (c5d67dc).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
lib/inferno/dsl/fhirpath_evaluation.rb 91.89% 3 Missing ⚠️
lib/inferno/exceptions.rb 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #520      +/-   ##
==========================================
+ Coverage   79.83%   79.86%   +0.03%     
==========================================
  Files         252      253       +1     
  Lines       13305    13351      +46     
  Branches     1289     1290       +1     
==========================================
+ Hits        10622    10663      +41     
- Misses       1934     1939       +5     
  Partials      749      749              
Flag Coverage Δ
backend 91.84% <89.13%> (-0.04%) ⬇️
frontend 74.54% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vanessuniq vanessuniq changed the title Fi 2750 add fhirpath support FI-2750: Add FHIRPath Support Aug 21, 2024
@vanessuniq vanessuniq marked this pull request as ready for review August 21, 2024 16:26
Copy link
Collaborator

@Jammjammjamm Jammjammjamm left a comment

Choose a reason for hiding this comment

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

This PR shouldn't be updating package-lock.json since it doesn't include any front end changes.

docker-compose.background.yml Outdated Show resolved Hide resolved
# @param resource [FHIR::Model] the root FHIR resource to use when evaluating the fhirpath expression.
# @param path [String] The FHIRPath expression to evaluate.
# @param fhirpath_evaluator [Symbol] the name of the evaluator to use.
# @return [Array] An array representing the result of evaluating the given expression against
Copy link
Collaborator

Choose a reason for hiding this comment

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

An array of what?

# @param name [Symbol] the name of the fhirpath evaluator, only needed if you are
# using multiple evaluators
# @param url [String] the url of the fhirpath service
def fhirpath_evaluator(name: :default, url: nil)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason why test writers would need to have multiple fhirpath services? I was really hoping this would just work out of the box without having to define fhirpath services.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

#
# results will be an array representing the result of evaluating the given
# expression against the given root element. Each "result" in the returned
# array will be in the form `{ "type": "[FHIR datatype name]", "element": [JSON representation of element] }`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be possible/desireable to instantiate the element from FHIR::Models rather than than using the JSON representation of the element?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The result types of a FHIRPath expression are unpredictable as they depend on the specific query or expression being evaluated. The element value can be anything from a primitive type to a complex FHIR data type. element is either a primitive value or a JSON representation of a FHIR element. Transforming element into a FHIR::Model only makes sense when the returned value is consistently a FHIR element, which is not always the case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But why doesn't representing that value as a FHIR model make sense, while representing it as JSON does make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The value of element is not always a json. I should update the description of the element key because it is confusing. The description should be something like primitive value or JSON representation of FHIR element or simply the result value of the FHIRPath expression.

These are the examples of results depending on the expression we are evaluating:

path = Patient.gender='female'
result =  [ {"type": "boolean", "element": true }]

path = Patient.name.given
result = [
    {
        "type": "string",
        "element": "patient"
    },
    {
        "type": "string",
        "element": "sample"
    }
]

path = Patient.name
result = [
    {
        "type": "HumanName",
        "element": {
            "use": "official",
            "family": "Chalmers",
            "given": [
                "patient",
                "sample"
            ]
        }
    }
]

I am not sure if you want to add condition handling to transform to FHIR model when the value is a fhir element.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, it isn't always JSON. You always have to check the type.

We use fhir_models widely throughout Inferno, so given these two options:

  • Return a primitive or a Hash for complex types
  • Return a primitive or a FHIR model instance for complex types

I'm wondering if there are technical reasons not to return a FHIR models instance here.

We generally expect (and encourage) test authors to use FHIR models to represent resources (e.g. in the first parameter of evaluate_fhirpath), so why not use them here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@vanessuniq vanessuniq requested review from Jammjammjamm and dehall and removed request for dehall September 9, 2024 14:10
lib/inferno/dsl/fhirpath_evaluation.rb Outdated Show resolved Hide resolved
@vanessuniq vanessuniq merged commit 4e356cc into main Sep 10, 2024
10 checks passed
@rpassas rpassas mentioned this pull request Sep 11, 2024
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