fhirbase / fhirbase-plv8

[DEPRECATED] Fhirbase 2.0 is an FHIR relational storage
https://health-samurai.io/fhirbase
Other
105 stars 39 forks source link

Search modification prefixes applied on wrong types #172

Open Andrzej-Pietrzak opened 7 years ago

Andrzej-Pietrzak commented 7 years ago

When running code and reference searches the search prefixes are actually applied and that will cause search errors depending on data. Fhir user would expect these to be applied only for numbers, dates and quantities: http://hl7.org/fhir/2017Jan/search.html#prefix

References: Currently when searching for observations assigned to patient eb038cc0-920b-4bca-b938-9c49f0fbc163

SELECT fhir_create_resource('{"allowId": true, "resource": {"id":"eb038cc0-920b-4bca-b938-9c49f0fbc163","name":[{"use":"official","given":["Peyton"],"family":["O''Reilly"]}],"active":true,"gender":"female","address":[{"use":"home","city":"Reilly Stadtt","line":["6385 Barney Branch"],"type":"both","country":"United Kingdom","district":"Berkshire","postalCode":"03539"}],"telecom":[{"use":"home","value":"(558) 317-1070","system":"phone"},{"use":"work","value":"1-576-209-7995","system":"phone"},{"use":"mobile","value":"(811) 678-1351 x8769","system":"phone"},{"use":"home","value":"fake-Peyton-O'Reilly-velocity@example.com","system":"email"}],"birthDate":"1984-05-21","identifier":[{"use":"official","value":"787418","system":"Hospital Number"},{"use":"official","value":"6340121235","system":"NHS Number"}],"resourceType":"Patient","managingOrganization":{"display":"sapiente ex","reference":"Organization/7ffa9ca8-2221-4733-a4e9-1f0b9ea7eb23"}}}');
SELECT fhir_create_resource('{"allowId": true, "resource": {"id":"2124bdea-d0b0-4673-9f26-d0d5574ed278","code":{"coding":[{"code":"eb1234","system":"CUSTOM1","display":"Testing codings with operators handling"}]},"status":"final","subject":{"reference":"Patient/eb038cc0-920b-4bca-b938-9c49f0fbc163"},"component":[{"code":{"coding":[{"code":"8480-6","system":"MiG2","display":"Systolic blood pressure"}]},"valueQuantity":{"unit":"mm[Hg]","value":154}},{"code":{"coding":[{"code":"8462-4","system":"MiG2","display":"Diastolic blood pressure"}]},"valueQuantity":{"unit":"mm[Hg]","value":76}}],"resourceType":"Observation","effectiveDateTime":"2008-12-05T19:54:07.848Z"}}');

Using 'patient' search parameter might be confusing as it points to a single resource type and accepts queries with id only yet for a search for certain id's (and notice this one is a valid uuid) we'll get no results because of the pre processing:

SELECT fhir_search_sql('{"resourceType": "Observation", "queryString": "patient=eb038cc0-920b-4bca-b938-9c49f0fbc163"}');
---
["SELECT * FROM \"observation\" tbl1 WHERE ( fhir_extract_as_reference( ( \"tbl1\".\"resource\" )::json , ( '[\"Observation\",\"subject\"]' )::json , 'Reference' ) )::text[] && ( ARRAY[ $1 ] )::text[] LIMIT $2","038cc0-920b-4bca-b938-9c49f0fbc163",10]

It would be best to either not apply the modification at all to reference type or force the users to set the whole reference in search as Type/id. There already has been a similar issue: #162

Code: Same processing is done, this on the other hand will cause certain code searches to fail. What is the reason to actually apply this modification on codes ?

SELECT fhir_search('{"resourceType": "Observation", "queryString": "code=eb-123"}'); --ok
SELECT fhir_search('{"resourceType": "Observation", "queryString": "code=ebtest1"}'); --ok
SELECT fhir_search('{"resourceType": "Observation", "queryString": "code=eb123"}'); --error