Skip to content

Commit b91f180

Browse files
Merge pull request #11 from KainosSoftwareLtd/VEL-1258-tests-and-rename-of-param-arguments
Vel 1258 tests and rename of param arguments
2 parents 488c2fd + 645e132 commit b91f180

File tree

5 files changed

+59
-21
lines changed

5 files changed

+59
-21
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,19 @@ SELECT fhir_valueset_expand('{"id": "issue-types", "filter": "err"}');
196196

197197
SELECT fhir_conformance('{"default": "values"}');
198198
-- return simple Conformance resource, based on created stores
199+
200+
---
201+
202+
-- use different methods to calculate total elements to improve performance: no _totalMethod or _totalMethod=exact uses standard approach
203+
SELECT fhir_search('{"resourceType": "Patient", "queryString": "name=smith"}');
204+
SELECT fhir_search('{"resourceType": "Patient", "queryString": "name=smith&_totalMethod=exact"}');
205+
206+
-- _totalMethod=extimated - faster but 'total' is estimated.
207+
SELECT fhir_search('{"resourceType": "Patient", "queryString": "name=smith&_totalMethod=estimated"}');
208+
209+
-- _totalMethod=no - fastest but no 'total' is returned.
210+
SELECT fhir_search('{"resourceType": "Patient", "queryString": "name=smith&_totalMethod=no"}');
211+
199212
```
200213

201214
## Contribution

src/fhir/search.litcoffee

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,10 @@ To build search query we need to
247247
if expr.count != null || expr.page != null
248248
hsql.limit = expr.count || DEFAULT_RESOURCES_PER_PAGE
249249
250-
if expr.page != null
250+
if expr.page?
251251
hsql.offset = (expr.count || DEFAULT_RESOURCES_PER_PAGE) * expr.page
252252
253-
if expr.offset != null
253+
if expr.offset?
254254
hsql.offset = expr.offset
255255
256256
if expr.joins
@@ -397,11 +397,11 @@ we just strip limit, offset, order and rewrite select clause:
397397
q
398398
399399
get_count = (plv8, honey, query_obj) ->
400-
if !query_obj.total_method || query_obj.total_method is "std"
401-
query_obj.total_method = "std"
400+
if !query_obj.total_method || query_obj.total_method is "exact"
401+
query_obj.total_method = "exact"
402402
403403
utils.exec(plv8, countize_query(honey))[0].count
404-
else if query_obj.total_method is "improved"
404+
else if query_obj.total_method is "estimated"
405405
sql_query= sql(honey)
406406
query = sql_query[0].replace /\$(\d+)/g, (match, number) ->
407407
if typeof sql_query[number] is "string"
@@ -416,7 +416,7 @@ we just strip limit, offset, order and rewrite select clause:
416416
tmp = plv8.execute(query)
417417
tmp[0].count_estimate
418418
else
419-
throw new Error("Invalid value of totalMethod. only 'std', 'improved' and 'no' allowed.")
419+
throw new Error("Invalid value of totalMethod. only 'exact', 'estimated' and 'no' allowed.")
420420
421421
We cache FHIR meta-data index per connection using plv8 object:
422422

test/fhir/query_string_spec.edn

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
[["Patient" "_count=11"]
2727
{:query "Patient" :count 11}]
2828

29+
[["Patient" "_totalMethod=exact"]
30+
{:query "Patient" :total_method "exact"}]
31+
32+
[["Patient" "_totalMethod=no"]
33+
{:query "Patient" :total_method "no"}]
34+
35+
[["Patient" "_totalMethod=estimated"]
36+
{:query "Patient" :total_method "estimated"}]
37+
2938
[["Patient" "_page=12"]
3039
{:query "Patient" :page 12}]
3140

@@ -34,7 +43,7 @@
3443
:joins [(chained
3544
(param {:resourceType "Patient" :name "careprovider" :join "Practitioner"} {:value "$id"})
3645
(param {:resourceType "Practitioner" :name "name"} {:value "igor"}))]}]
37-
46+
3847
[["Patient" "careprovider:Practitioner.organization:Organization.name=hl7"]
3948
{:query "Patient"
4049
:joins [(chained

test/fhir/search/pagination_search.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,23 @@ queries:
6363
result: "Encounter/search?patient=Patient/nicola&_sort=patient&_page=0&_count=1"
6464
- path: ['link', 3, 'url']
6565
result: "Encounter/search?patient=Patient/nicola&_sort=patient&_page=3&_count=1"
66+
67+
- query: {resourceType: 'Encounter', queryString: 'patient=Patient/nicola&_sort=patient&_page=1&_count=1&_totalMethod=exact'}
68+
total: 3
69+
probes:
70+
- path: ['entry', 'length']
71+
result: 1
72+
- path: ['link', 0, 'url']
73+
result: "Encounter/search?patient=Patient/nicola&_sort=patient&_page=1&_count=1&_totalMethod=exact"
74+
- path: ['link', 1, 'url']
75+
result: "Encounter/search?patient=Patient/nicola&_sort=patient&_page=2&_count=1&_totalMethod=exact"
76+
- path: ['link', 2, 'url']
77+
result: "Encounter/search?patient=Patient/nicola&_sort=patient&_page=0&_count=1&_totalMethod=exact"
78+
- path: ['link', 3, 'url']
79+
result: "Encounter/search?patient=Patient/nicola&_sort=patient&_page=3&_count=1&_totalMethod=exact"
80+
81+
- query: {resourceType: 'Encounter', queryString: 'patient=Patient/nicola&_sort=patient&_page=1&_count=1&_totalMethod=no'}
82+
total: _undefined
83+
probes:
84+
- path: ['link']
85+
result: '_undefined'

test/fhir/search_spec.coffee

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,13 @@ test = require('../helpers.coffee')
88

99
assert = require('assert')
1010

11-
# plv8.debug = true
1211
get_in = (obj, path)->
1312
cur = obj
1413
cur = cur[item] for item in path when cur
1514
cur
1615

1716
match = (x)-> (y)-> y.indexOf(x) > -1
1817

19-
# plv8.debug = true
20-
21-
# console.log plv8.execute("SET search_path='user1';")
22-
# console.log plv8.execute("SHOW search_path;")
23-
2418
FILTER = 'uri'
2519
FILTER = 'incl'
2620
FILTER = 'search'
@@ -30,7 +24,6 @@ fs.readdirSync("#{__dirname}/search").filter(match(FILTER)).forEach (yml)->
3024
describe spec.title, ->
3125
before ->
3226
plv8.execute("SET plv8.start_proc = 'plv8_init'")
33-
# plv8.debug = true
3427

3528
for res in spec.resources
3629
schema.fhir_create_storage(plv8, resourceType: res)
@@ -56,18 +49,21 @@ fs.readdirSync("#{__dirname}/search").filter(match(FILTER)).forEach (yml)->
5649
plv8.execute "SET enable_seqscan = OFF;" if (q.indexed or q.indexed_order)
5750

5851
res = search.fhir_search(plv8, q.query)
59-
# console.log(JSON.stringify(res))
6052
explain = JSON.stringify(search.fhir_explain_search(plv8, q.query))
61-
# console.log(JSON.stringify(search.fhir_search_sql(plv8, q.query)))
6253

6354
plv8.execute "SET enable_seqscan = ON;" if (q.indexed or q.indexed_order)
6455

6556
if q.total || q.total == 0
66-
assert.equal(res.total, q.total)
67-
68-
(q.probes || []).forEach (probe)-> assert.equal(get_in(res, probe.path), probe.result)
69-
70-
# console.log(explain)
57+
if q.total == "_undefined"
58+
assert.equal(res.total, undefined)
59+
else
60+
assert.equal(res.total, q.total)
61+
62+
(q.probes || []).forEach (probe)->
63+
if probe.result == "_undefined"
64+
assert.equal(get_in(res, probe.path), undefined)
65+
else
66+
assert.equal(get_in(res, probe.path), probe.result)
7167

7268
if q.indexed
7369
assert(explain.indexOf("Index Cond") > -1, "Should be indexed but #{explain}")

0 commit comments

Comments
 (0)