-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluate_test.go
122 lines (88 loc) · 3.28 KB
/
evaluate_test.go
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package fhirpath
import (
_ "embed"
"github.com/halprin/fhirpath/context"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
//go:embed sample/patient.json
var fhirPatient string
func TestEvaluate_Value(t *testing.T) {
result, err := Evaluate[string](fhirPatient, "Patient.gender")
assert.NoError(t, err)
assert.Contains(t, result, "female")
}
func TestEvaluate_ParseError(t *testing.T) {
_, err := Evaluate[string](fhirPatient, "Patient..gender")
assert.Error(t, err)
}
func TestEvaluate_Where_Equal(t *testing.T) {
result, err := Evaluate[string](fhirPatient, "Patient.identifier.where(system='http://new-republic.gov/galactic-citizen-identifier').value")
assert.NoError(t, err)
assert.Contains(t, result, "b531d827-de9a-4e2e-a53b-8621bd29f656")
}
func TestEvaluate_Where_NotEqual(t *testing.T) {
result, err := Evaluate[string](fhirPatient, "Patient.identifier.where(system!='http://new-republic.gov/galactic-citizen-identifier').value")
assert.NoError(t, err)
assert.Contains(t, result, "S99955754")
}
func TestEvaluate_Where_Other(t *testing.T) {
result, err := Evaluate[string](fhirBundleOrder, "Bundle.entry.where(resource.resourceType='ServiceRequest').resource.code.coding.code")
assert.NoError(t, err)
assert.Contains(t, result, "54089-8")
assert.Contains(t, result, "57717-1")
}
func TestEvaluate_Index(t *testing.T) {
result, err := Evaluate[string](fhirPatient, "Patient.identifier[1].value")
assert.NoError(t, err)
assert.Contains(t, result, "b531d827-de9a-4e2e-a53b-8621bd29f656")
}
func TestEvaluate_Index_NotInteger(t *testing.T) {
_, err := Evaluate[string](fhirPatient, "Patient.identifier[2.6].value")
assert.Error(t, err)
}
func TestEvaluate_Index_AboveSizeBecomesEmptyResult(t *testing.T) {
result, err := Evaluate[string](fhirPatient, "Patient.identifier[2].value")
assert.NoError(t, err)
assert.Len(t, result, 0)
}
func TestEvaluate_Exists(t *testing.T) {
result, err := Evaluate[bool](fhirPatient, "Patient.name.exists()")
assert.NoError(t, err)
assert.Contains(t, result, true)
}
func TestEvaluate_Exists_False(t *testing.T) {
result, err := Evaluate[bool](fhirPatient, "Patient.deceased.exists()")
assert.NoError(t, err)
assert.Contains(t, result, false)
}
func TestEvaluate_Exists_InnerWhere(t *testing.T) {
result, err := Evaluate[bool](fhirPatient, "Patient.name.exists(use = 'official')")
assert.NoError(t, err)
assert.Contains(t, result, true)
}
func TestEvaluate_Equality_Boolean(t *testing.T) {
result, err := Evaluate[bool](fhirPatient, "Patient.name.exists() = true")
assert.NoError(t, err)
assert.Contains(t, result, true)
}
func TestEvaluate_Polymorphism_Exact(t *testing.T) {
result, err := Evaluate[bool](fhirPatient, "Patient.multipleBirthInteger = 1")
assert.NoError(t, err)
assert.Contains(t, result, true)
}
func TestEvaluate_Polymorphism_Imprecise(t *testing.T) {
result, err := EvaluateWithContext[bool](fhirPatient, "Patient.multipleBirth = 1", context.R4())
assert.NoError(t, err)
assert.Contains(t, result, true)
}
func TestOfficial_testSliceOfBool(t *testing.T) {
booleans := []bool{true, false, true}
var obfuscatedBooleans interface{}
obfuscatedBooleans = booleans
reflectedSlice := reflect.ValueOf(obfuscatedBooleans)
for i := 0; i < reflectedSlice.Len(); i++ {
t.Log(reflectedSlice.Index(i).Interface())
}
}