Aidbox / Issues

Issue tracker for Aidbox FHIR backend by Health Samurai
7 stars 0 forks source link

[BUG] The search parameter "name" for the Patient resource works incorrectly #570

Closed projkov closed 8 months ago

projkov commented 10 months ago

Describe the bug Search parameter "name" should check suffixes and prefixes in the HumanName, according to the specification. But it does not.

A server defined search that may match any of the string fields in the HumanName, including family, give, prefix, suffix, suffix, and/or text

Severity Minor

Steps to reproduce the behavior:

  1. Create a patient resource with a name that includes any suffix, in our case, it will be Ms.
    {
    "resourceType": "Patient",
    "name": [
    {
    "use": "usual",
    "given": [
    "Test"
    ],
    "family": "Patient",
    "prefix": [
    "Ms."
    ]
    }
    ],
    }
  2. Send get request with ?name=Mr
    GET /fhir/Patient?name=Ms

    Expected behavior You get this patient resource in the response.

Versions:

Additional context I made a request with an explanation. Looks like the main problem is: that Aidbox doesn't check the string in the suffix and in the prefix

GET /fhir/Patient?name=Ms&_explain=analyze
query:
  - >-
    SELECT "patient".* FROM "patient" WHERE
    aidbox_text_search(knife_extract_text("patient".resource,
    $JSON$[["name","family"],["name","given"],["name","middle"],["name","text"]]$JSON$))
    ilike unaccent(?) LIMIT ? OFFSET ? 
  - '% Ms%'
  - 100
  - 0
plan: >-
  Limit  (cost=0.00..53.47 rows=2 width=1950) (actual time=0.217..0.672 rows=2
  loops=1)
    ->  Seq Scan on patient  (cost=0.00..53.47 rows=2 width=1950) (actual time=0.215..0.669 rows=2 loops=1)
          Filter: (immutable_wrap_ws(immutable_unaccent(immutable_array_to_string(knife_extract_text(resource, '[["name", "family"], ["name", "given"], ["name", "middle"], ["name", "text"]]'::jsonb), ' '::text))) ~~* unaccent('% Ms%'::text))
          Rows Removed by Filter: 50
  Planning Time: 1.480 ms

  Execution Time: 0.842 ms
Gorovoi commented 10 months ago

Hello @projkov, a fix is already in edge channel. Please let us know if something is wrong!