Aidbox / Issues

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

[BUG] Patient deceased or living query returns both. #517

Closed rmhayek closed 2 years ago

rmhayek commented 2 years ago

Describe the bug Testing if a patient is deceased or living returns both deceasedBoolean and deceasedDateTime.

Severity Major

Steps to reproduce the behavior: Here is a notebook https://aidbox.app/ExportedNotebook/a891e6e6-b988-420e-b127-bb9fc0a7d443

Expected behavior

Versions: devbox:edge v:2206.4c06e7e9

KGOH commented 2 years ago

@rmhayek fixed on the :edge. Please pull the newest image and check if the fox works for you

rmhayek commented 2 years ago

@KGOH - It works to retrieve deceased=false, but does not retrieve patient that has deceasedDateTime in resource and in query we pass deceased=true parameter.

krevedkokun commented 2 years ago

@rmhayek you can use following Search resource instead of Patient.deceased search parameter

resourceType: Search
id: Patient.deceased
name: deceased
resource:
  id: Patient
  resourceType: Entity
where: "{{table}}.resource ?? 'deceased' AND NOT {{table}}.resource @> '{\"deceased\": {\"boolean\": false}}'"
rmhayek commented 2 years ago

@krevedkokun With the Search resource, the REST API only returns resources that have { "deceased" : {"dateTime": "xyz"}. So GET /fhir/Patient?deceased=false always returned deceased patients.

I tested this with HAPI FHIR test server, if I specify: GET /fhir/Patient?deceased=false : it returns all patients that don't have deceased.boolean field and deceased.boolean=false. GET /fhir/Patient?deceased=true : it returns all patients that have deceased.dateTime and deceased.boolean=true.

spicyfalafel commented 2 years ago

@rmhayek With following Search resource: GET /fhir/Patient?deceased=false returns all patients that don't have deceased field (boolean or dateTime) or patients with deceased.boolean=false. GET /fhir/Patient?deceased=true returns all patients that have deceased.dateTime and deceased.boolean=true.

resourceType: Search
id: Patient.deceased
name: deceased
resource:
  id: Patient
  resourceType: Entity
where: "coalesce((resource#>>'{deceased,boolean}')::boolean, resource ?? 'deceased', false) = {{param}}"
rmhayek commented 2 years ago

Thanks @spicyfalafel - this works very well! Would that be part of a future product release or do I have to create the Search resource in every environment?