inferno-framework / davinci-us-drug-formulary-test-kit

Inferno Test Kit for the Da Vinci PDEX US Drug Formulary IG
Apache License 2.0
0 stars 0 forks source link

Fi 2718 _include search parameter fix. #12

Closed edeyoung closed 4 months ago

edeyoung commented 4 months ago

Summary

The issue

The tests were expecting _include parameters to be formatted as _include=searchParam. Instead, they should be formatted as _include=SourceType:searchParam(:targetType).

The packaged Implementation Guide (package.tgz) was incorrect, which led to the generated tests being incorrect.

The fix

Patch the Implementation Guide

The Capability Statement required updates to include the correct _include syntax.

I wanted to ensure it was clear that we were doing a patch to the implementation guide and why we were doing the patch, so I did not change the Implementation Guide directly. Instead, I put the updated Capability Statement in a folder called "package_supersede". Any files in this folder will supersede files in the Implementation Guide (package.tgz).

There was a similar existing patch for r4_search-parameters. I moved this file into "package_supplement", because we do not want this file to supersede existing files, we just want it to add in missing information.

The load order determines what files "supersede" and what files "supplement".

IGResources accesses resources by grabbing the first matching resource it finds for a request. Files that are loaded first take precedence.

So the load order is:

Accessing search definitions for the _include parameters

For both test generation and in the tests themselves, the code needs to access search definitions for the _include parameters:

lib/davinci_us_drug_formulary_test_kit/generator/include_search_test_generator.rb:

res_type = group_metadata.search_definitions[:"#{include_param}"][:type]
res_type = group_metadata.search_definitions[:"#{include_param}"][:target] if res_type == 'Reference'

lib/davinci_us_drug_formulary_test_kit/search_test.rb

search_param_paths(include_param).each do |include_ref_path|

However, the dictionaries that use include_param as a key are generated from the searchParams in the Capability Statement, which do not include the sourceType. For example, in the Capability Statement, if the searchInclude is Basic:subject, the searchParam is just subject.

So we need to strip off the sourceType from include_param in order to access the search definitions.

There are multiple ways to do this, which include:

  1. strip the sourceType from the include_param inline where necessary
  2. create a helper function and call that where necessary
  3. create a new generated variable to store the stripped parameter

I chose 3.

For 1, I wanted more error handling than inline code provided, and felt it was done enough times it deserved to be broken out.

For 2, the scopes of use are different: one is in the generator, and one is in the search itself. So figuring out where to place the helper function in a way that was logical for both scopes was challenging.

I don't love 3, but it allows the stripping to only occur in the generator, and treats this step as native / necessary rather than as a workaround.

For the reviewer

Please come up with a better name than include_param_search_param.

Testing Guidance

Delete the generated folder. Call rake usdf:generate Confirm there are no differences in the generated files (git diff)

Confirm that the testing metadata.yml files match the generated metadata.yml files:

Run rake to run the tests.