-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add support for the _elements param #39
Conversation
Coverage report
Show files with reduced coverage 🔻
Test suite run success78 tests passing in 7 suites. Report generated by 🧪jest coverage report action from 3ea331f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial code changes make sense, though understood we're still waiting on implementation details. I think it makes sense to do a README update to the server endpoints section for this PR as well. (When you do, there are a couple of deqm-test-server references that might be nice to cleanup to reference bulk-export-server instead)
Implementation question 1: Implementation question 2: |
@lmd59 thank you for your thoughtful responses to the implementation questions! I have decided to go with the following, please let me know if that doesn't make sense or if I should change anything: Update: I have decided to get those mandatory elements for each of the resource types that our server supports by downloading the StructureDefinition.json for each of those resource types (using FHIR v4.0.1) and running the Finally, these mandatory elements are utilized in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a couple of general comments and questions in code and then I'll also add:
- It seems like
resourceType
is implicitly mandatory on the base resource element, but the structure definition itself doesn't indicate that - https://hl7.org/fhir/R4/resource.html . Do you think we would consider that mandatory for all resources? - I would add a description of the _elements param to the README
Good question about |
https://hl7.org/fhir/R4/json.html#resources says "A resource is a JSON object with a property resourceType which informs the parser which resource type this is" . The json schema http://hl7.org/fhir/R4/fhir.schema.json.zip has resourceType as required for all of the (duh) resources. |
060df2e
to
8d13fdd
Compare
Huge thank you for the guidance as well as Karl's! Looks like our current implementation makes the most sense although it certainly can be subject to change. For testing now, please refer to Karl's guidance and make sure this functionality aligns with his suggestions. Also please check that my README explanation makes sense and if there should be anything else added. I have an updated Insomnia testing collection attached! Please use this one now that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some recommendations for the README. Otherwise, looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it works well for the most part, but if you reference a choice type parameter such as DiagnosticReport.effective
you do not get the FHIR JSON effectiveDateTime
and effectivePeriod
choice elements. The spec isn't clear if it should reference the choice types by the name of the element or the element and the specific type.
Good call! I reached out to Karl and confirmed that this is indeed the functionality that we want for our current interpretation of the spec. I added two files: New behavior for the server now includes the following: for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More null checks on the choice type stuff is needed.
src/util/exportToNDJson.js
Outdated
Object.keys(choiceTypeElements[resourceType]).includes(`${elementName}[x]`) | ||
) { | ||
const rootElem = elementName.split('[x]')[0]; | ||
choiceTypeElements[resourceType][rootElem].forEach(e => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't carefully check the choice type element structure exists before doing the forEach
.
It blows up on the following request
http://localhost:3000/$export?_type=DiagnosticReport&_elements=DiagnosticReport.effective
Additionally this area of the code could use a bit more explanation of what it is doing. If possible, unit tests too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! I think I have a fix that I will push up. The issue was it wasn't finding the key with just the elementName in the lookup object (needed the [x] as well). I will add more documentation but will push that fix for now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it also needs to be a bit more resilient to garbage being passed in. Like a Resource or element that doesn't exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How so? Should I check every resourceType and element that is passed in to make sure it's valid FHIR? If so, how does that work for elements passed in without resourceType (i.e. just id
rather than Conditiion.id
)? Would I have to check that it's valid on every single resourceType (often not the case)? These are things I have brought up but it seemed like the server should not error out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you wanted to do a base check that something of the form Condition.id
has id as a valid property on Condition, you could use the propertyPaths file/script here: projecttacoma/fqm-testify@815c4fc
Hasn't been pulled into fqm-testify because it's mostly just been used for the data requirements work so far.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have an idea of the expected error output according to the spec if there is malformed parameters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hossenlopp @lmd59 also keep in mind that we don't do any sort of checks for inputs passed into _typeFilter
. For example, a GET request to $export?_typeFilter=Condition?invalid=invalid
does not return any errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe some of this validation is out of scope for this tasking, but if we're not responding with the correct errors, we should know what the spec indicates we need and use that for potential follow-up tasking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably just 400 Bad Request, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works well!
Summary
This PR adds support for the _elements query parameter as defined by the Bulk Data Access IG. Some inspiration for this parameter's implementation was taken from the implementation of the
_elements
FHIR search parameter implementation in the measure-respository-service in this PR.New behavior
Functionality for the
_elements
query parameter is now available! When the_elements
query parameter is used, the server will return resources with only the elements specified in the parameter and the SUBSETTED tag (see the Bulk Data Access IG for more info).Code changes
exportWorker.js
- addelements
as a parameter to call toexportToNDJson
export.service.js
- add_elements
parameter validation tovalidateExportParams
function and add_elements
as a recognized parameterexportToNDJson.js
- add a try/catch to thebuildSearchParamList
function so that it doesn't error out on some resources that the server supports but for some reason do not exist in the node-fhir-server-core parameters (ex.BiologicallyDerivedProduct
), add_elements
parameter handling toexportToNDJson
andgetDocuments
mongo.controller.js
- add projection functionality tofindResourcesWithAggregation
so that we can use the_elements
parameter with the_typeFilter
parameterexportToNDJson.test.js
- adds two tests- one for_elements
handling ingetDocuments
and the other to make sure thatbuildSearchParamList
doesn't error out on one of thesupportResources
Implementation Questions
_elements
parameter to include the following SHOULD functionality: "A server is not obliged to return just the requested elements. A server SHOULD always return mandatory elements whether they are requested or not." I do not have this implemented currently. I feel like it is something I should implement; however, it is an interesting question of how useful that may be (and potentially something we suggest in the IG?). I think it's interesting because in my opinion, if we defined mandatory elements to be elements that have a cardinality of 1..1, then there are quite a few and it may defeat the purpose of a potential use case of the_elements
parameter (i.e., if a user just wanted the ids of all of the Condition resources).Testing guidance
npm run check
npm start
to spin up the server atlocalhost:3001
_elements
parameter with other query parameters (_type
,patient
,_typeFilter
, etc.).ElementsParamTesting.json