This repository has been archived by the owner on Oct 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 136
/
querySpec.coffee
78 lines (53 loc) · 2.94 KB
/
querySpec.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
fhir = require('../src/middlewares/search')
assert = require('assert')
describe "linearizeParams:", ->
subject = fhir._query
it "simplest", ->
assert.deepEqual(subject(a:1,b:2) , [{param: 'a', value: [1]},{param: 'b',value: [2]}])
it "modifier", ->
assert.deepEqual(subject(a: {$exact: 2}) , [{param: 'a', modifier: ':exact', value: [2]}])
it "operator", ->
assert.deepEqual(subject(a: {$lt: 2}) , [{param: 'a', operator: 'lt', value: [2]}])
it "and", ->
assert.deepEqual(subject(a: {$and: [1, 2]}) , [{param: 'a', value: [1]}, {param: 'a',value: [2]}])
it "compound", ->
assert.deepEqual(subject(a: [1, 2]) , [{param: 'a', value: ['1|2']}])
it "or", ->
assert.deepEqual(subject(a: {$or: [1, 2]}) , [{param: 'a', value: [1,2]}])
it "operator & or", ->
assert.deepEqual(subject(a: {$exact: {$or: [1,2]}}) , [{param: 'a', modifier: ':exact', value: [1,2]}])
it "chained params", ->
assert.deepEqual(subject(subject: {name: {$exact: 'abu'}, birthDate: {$gt: '2000'}}), [
{param: 'subject.name', modifier: ':exact', value: ['abu']}
{param: 'subject.birthDate', operator: 'gt', value: ['2000']}
])
describe "test params builder", ->
subject = fhir.query
it "simple cases", ->
assert.deepEqual(subject(name: 'buka'), 'name=buka')
assert.deepEqual(subject(name: {$exact: 'buka'}), 'name:exact=buka')
assert.deepEqual(subject(birthDate: {$gt: '2011'}), 'birthDate=gt2011')
assert.deepEqual(subject(birthDate: {$gt: '2011', $lt: '2014'}), 'birthDate=gt2011&birthDate=lt2014')
assert.deepEqual(subject('subject.name': {$exact: 'maud'}), 'subject.name:exact=maud')
assert.deepEqual(subject(subject: {$type: 'Patient', name: 'maud',
birthDate: {$gt: '1970'}}), 'subject:Patient.name=maud&subject:Patient.birthDate=gt1970')
assert.deepEqual(subject('uri': 'http://test'), 'uri=http%3A%2F%2Ftest')
it "sort", ->
assert.deepEqual(subject(
$sort: [['name','asc'],['birthDate','desc'], 'vip']),
'_sort:asc=name&_sort:desc=birthDate&_sort=vip')
assert.deepEqual(
subject(subject: "id", questionnaire: "Allergies", _count: 1, $sort: [["authored", "desc"]]),
'subject=id&questionnaire=Allergies&_count=1&_sort:desc=authored')
it "include", ->
assert.deepEqual(subject($include: {Observation: "related.component", Patient: ["link.other", "careProvider"]}),
'_include=Observation:related.component&_include=Patient:link.other&_include=Patient:careProvider')
it "revinclude", ->
assert.deepEqual(subject($revInclude: {Observation: "related.component", Patient: ["link.other", "careProvider"]}),
'_revinclude=Observation:related.component&_revinclude=Patient:link.other&_revinclude=Patient:careProvider')
it "or", ->
assert.deepEqual(subject(name: {$or: ['bill', 'ted']}),
'name=bill%2Cted')
it "has", ->
assert.deepEqual(subject($has: {"Observation:patient:code": "1234-5"}),
'_has:Observation:patient:code=1234-5')