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

Fixes #4509 - Improve exact match search support for token parameters in matchesTokenFilter #4516

Merged
merged 5 commits into from
May 6, 2024

Conversation

pamella
Copy link
Collaborator

@pamella pamella commented May 6, 2024

Description

I opened this PR so you folks can have a closer look at the proposed partial solution mentioned in #4509.

Proposed solution

That being said, I thought about a partial solution that would allow us to support exact match searches for token parameters. I say partial because it would address the identifier and code types.

I was working on this solution, however I wonder if:

  • It would be enough to have a partial solution because I understand there are a lot of nuances in FHIR standards about search such as operators and modifiers.
  • It would be a overkill to implement a full solution considering (I suppose) that the main usage is for testing purposes.
  • It might be a breaking change to other matches* functions that are using the matchesStringFilter function. For example, matchesAccessPolicyResourcePolicy and matchesCriteria.
  • It might be a breaking change to customers that are already using the MockClient class.

So I would like to know your opinion about all of this.

Please let me know if you have any questions or need further information. I am looking forward to your feedback. Thank you!

Copy link

vercel bot commented May 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
medplum-provider ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 6, 2024 9:26pm
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
medplum-app ⬜️ Ignored (Inspect) Visit Preview May 6, 2024 9:26pm
medplum-storybook ⬜️ Ignored (Inspect) Visit Preview May 6, 2024 9:26pm
medplum-www ⬜️ Ignored (Inspect) Visit Preview May 6, 2024 9:26pm

Copy link

vercel bot commented May 6, 2024

@pamella is attempting to deploy a commit to the Medplum Team on Vercel.

A member of the Team first needs to authorize it.

@codyebberson
Copy link
Member

Hi @pamella - thank you for submitting!

It would be enough to have a partial solution because I understand there are a lot of nuances in FHIR standards about search such as operators and modifiers.
It would be a overkill to implement a full solution considering (I suppose) that the main usage is for testing purposes.

Yes, this is an inherent challenge with MockClient. Our general philosophy has been "do as good as we can with code, but accept data limits".

This draft PR definitely qualifies for "do as good as we can with code".

The "accept data limits" disclaimer refers to the impossibility of implementing everything without 100's of MB of StructureDefinition, SearchParameter, CodeSystem, and ValueSet resources.

It might be a breaking change to other matches* functions that are using the matchesStringFilter function. For example, matchesAccessPolicyResourcePolicy and matchesCriteria.
It might be a breaking change to customers that are already using the MockClient class.

This is a fair callout. We generally accept anything that moves us closer to spec compliance, and I believe this PR qualifies for that.

Thank you for your submission. Cursory review of the code looks good to me. I'll take another deeper look once all automated tests have passed. Please let us know if you have any questions.

@pamella
Copy link
Collaborator Author

pamella commented May 6, 2024

Hi @codyebberson, thank you for looking at this and sharing the context around the philosophy!


I noticed that a test failed but passed when I ran it locally. Would it be the case to rerun the related action job?

image

@pamella pamella changed the title [Draft] Proposed partial solution mentioned in #4509 Fixes #4509 - Improve exact match search support for token parameters in matchesTokenFilter May 6, 2024
@pamella pamella marked this pull request as ready for review May 6, 2024 20:15
@pamella pamella requested a review from a team as a code owner May 6, 2024 20:15
@pamella
Copy link
Collaborator Author

pamella commented May 6, 2024

I was able to reproduce the failing test locally after rerunning npm ci and npm run build:fast. But, curiously, it also fails in the main branch. Do you folks have an initial guess as to what could be causing this?

@codyebberson
Copy link
Member

Thanks @pamella - it looks like the test failure is consistent. We are investigating.

@pamella
Copy link
Collaborator Author

pamella commented May 6, 2024

Thank you, Cody! In case there is anything I should adjust in the PR, please let me know. Meanwhile, I'm looking here to see if there's anything I can solve on my end.

@pamella
Copy link
Collaborator Author

pamella commented May 6, 2024

Recent finding:

  • On main branch, the test passes after running npm ci and npm run build:fast.
  • On this PR branch, the test fails after running npm ci and npm run build:fast.

So indeed the changes seem to have had an impact on the test case.

If I make the following changes to the test (see lines with // Before: 'Test'), it passes, but I am not sure if that's the right move here.

➡️ Click here to expand and see the code
test('Reference filter', async () => {
  await setup({
    questionnaire: {
      resourceType: 'Questionnaire',
      status: 'active',
      id: 'reference-filter',
      item: [
        {
          linkId: 'q1',
          type: 'reference',
          text: 'Question',
          extension: [
            {
              url: 'http://hl7.org/fhir/StructureDefinition/questionnaire-referenceResource',
              valueCode: 'Observation',
            },
            {
              url: 'http://hl7.org/fhir/StructureDefinition/questionnaire-referenceFilter',
              valueString: 'subject=$subj',
            },
          ],
        },
      ],
    },
    subject: { reference: 'Patient/123' },
    onSubmit: jest.fn(),
  });

  // Add a spy on medplum.searchResources
  const searchResources = jest.spyOn(medplum, 'searchResources');

  // Get the search input
  const input = screen.getByRole('searchbox') as HTMLInputElement;

  // Enter "Simpson"
  await act(async () => {
    fireEvent.change(input, { target: { value: 'Test 1' } }); // Before: 'Test'
  });

  // Wait for the drop down
  await act(async () => {
    jest.advanceTimersByTime(1000);
  });

  expect(screen.getByText('Test 1')).toBeDefined();
  expect(searchResources).toHaveBeenCalledTimes(1);
  expect(searchResources.mock.calls[0][0]).toBe('Observation');
  expect(searchResources.mock.calls[0][1]).toBeInstanceOf(URLSearchParams);

  const params = searchResources.mock.calls[0][1] as URLSearchParams;
  expect(params.get('subject')).toBe('Patient/123');
  expect(params.get('code')).toBe('Test 1'); // Before: 'Test'
});

@codyebberson
Copy link
Member

It looks like that test was relying on the incorrect behavior. Fix here: e9c122b

@pamella
Copy link
Collaborator Author

pamella commented May 6, 2024

Thank you for the fix!

@codyebberson codyebberson added this pull request to the merge queue May 6, 2024
@codyebberson
Copy link
Member

Thanks @pamella !

Merged via the queue into medplum:main with commit d022296 May 6, 2024
31 checks passed
@reshmakh reshmakh added this to the May 31st, 2024 milestone May 7, 2024
@reshmakh reshmakh added the search Features and fixes related to search label May 12, 2024
medplumbot added a commit that referenced this pull request May 25, 2024
Fix age display in PatientSummary (#4484)Fixes #4471 - DetectedIssue.status valueset and search param (#4483)
Qualify columns with table name in generated SQL (#4487)
fix(migrations): only take lock if migrating (#4490)
Document updating profiles (#4402)
Run expand tests against old and new (#4503)
Adding OpenCareHub support post (#4504)
[Medplum Provider app] Various fixes and touchups (#4500)
ci(agent): add workflow for building agent outside of a release (#4512)
feat(agent): `Agent/$reload-config` operation (#4457)
Remove broken links to Foo Provider (#4518)
Dependency upgrades 2024-05-06 (#4515)
PatientSummary and provider app tweaks (#4521)
Fixes #4509 - Improve exact match search support for token parameters in `matchesTokenFilter` (#4516)
Link to new Demo Applications (#4514)
Clarify that autobatching only applies to `GET` requests (#4479)
Added missing useEffect dependency in chat demo (#4527)
fix: allows CORS for `keyvalue` API (#4476)
Fixes #4508 - MeasureReport-subject search param backport (#4530)
Fix CLI update-server version flag (#4534)
Patient summary appointments and encounters links (#4524)
Remove unused DB columns (#4532)
fix(agent): unwrap response for `$reload-config` by id (#4542)
`PatientSummary` Problem List uses US Core profile (#4535)
fix(cli): always exit with exit code 1 after error occurs during command (#4536)
Add failing test about validating nested extensions (#4548)
Add error message when `cli` fails on login (#4507)
Remove functions moved to core (#4547)
fix: AttachmentDisplay use uncached url for download link (#4501)
feat(agent): respect `Agent.status` and `Agent.channel.endpoint.status` being `off` (#4523)
CMS 1500 and Superbill (#4543)
Demo Bot: Agent Setup (#4555)
feat(Subscription): add `author` as a `SearchParameter` (#4540)
Dependency upgrades 2024-05-13 (#4544)
Full linked Project ordering in CodeSystem lookup (#4522)
Disable super admin refresh tokens (#4492)
Minor fixes for the agent setup bot (#4560)
docs(agent): document how logging works with `Bot` and `Agent` (#4563)
Split rate limits into two buckets (#4568)
Properly detect array elements (#4569)
Apply filter to ValueSet with expansion.contains (#4570)
More efficiently validate included concepts (#4573)
Dependency upgrades 2024-05-20 (#4574)
tweak(agent): add timezone in status `lastUpdated` time (#4564)
fix(client/keyvalue): set keyvalue content-type text (#4575)
Allow configuring server default rate limits (#4491)
feat(cli): add `token` command to get access token (#4579)
Updating device resources and videos (#4578)
fix(subscriptions): don't retry ws subs if sub is deleted (#4577)
Add support for 'pr' filter operation (#4584)
Super admin endpoint for database stats (#4443)
github-merge-queue bot pushed a commit that referenced this pull request May 25, 2024
Fix age display in PatientSummary (#4484)Fixes #4471 - DetectedIssue.status valueset and search param (#4483)
Qualify columns with table name in generated SQL (#4487)
fix(migrations): only take lock if migrating (#4490)
Document updating profiles (#4402)
Run expand tests against old and new (#4503)
Adding OpenCareHub support post (#4504)
[Medplum Provider app] Various fixes and touchups (#4500)
ci(agent): add workflow for building agent outside of a release (#4512)
feat(agent): `Agent/$reload-config` operation (#4457)
Remove broken links to Foo Provider (#4518)
Dependency upgrades 2024-05-06 (#4515)
PatientSummary and provider app tweaks (#4521)
Fixes #4509 - Improve exact match search support for token parameters in `matchesTokenFilter` (#4516)
Link to new Demo Applications (#4514)
Clarify that autobatching only applies to `GET` requests (#4479)
Added missing useEffect dependency in chat demo (#4527)
fix: allows CORS for `keyvalue` API (#4476)
Fixes #4508 - MeasureReport-subject search param backport (#4530)
Fix CLI update-server version flag (#4534)
Patient summary appointments and encounters links (#4524)
Remove unused DB columns (#4532)
fix(agent): unwrap response for `$reload-config` by id (#4542)
`PatientSummary` Problem List uses US Core profile (#4535)
fix(cli): always exit with exit code 1 after error occurs during command (#4536)
Add failing test about validating nested extensions (#4548)
Add error message when `cli` fails on login (#4507)
Remove functions moved to core (#4547)
fix: AttachmentDisplay use uncached url for download link (#4501)
feat(agent): respect `Agent.status` and `Agent.channel.endpoint.status` being `off` (#4523)
CMS 1500 and Superbill (#4543)
Demo Bot: Agent Setup (#4555)
feat(Subscription): add `author` as a `SearchParameter` (#4540)
Dependency upgrades 2024-05-13 (#4544)
Full linked Project ordering in CodeSystem lookup (#4522)
Disable super admin refresh tokens (#4492)
Minor fixes for the agent setup bot (#4560)
docs(agent): document how logging works with `Bot` and `Agent` (#4563)
Split rate limits into two buckets (#4568)
Properly detect array elements (#4569)
Apply filter to ValueSet with expansion.contains (#4570)
More efficiently validate included concepts (#4573)
Dependency upgrades 2024-05-20 (#4574)
tweak(agent): add timezone in status `lastUpdated` time (#4564)
fix(client/keyvalue): set keyvalue content-type text (#4575)
Allow configuring server default rate limits (#4491)
feat(cli): add `token` command to get access token (#4579)
Updating device resources and videos (#4578)
fix(subscriptions): don't retry ws subs if sub is deleted (#4577)
Add support for 'pr' filter operation (#4584)
Super admin endpoint for database stats (#4443)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
search Features and fixes related to search
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants