Skip to content

Commit 311d10d

Browse files
committed
update tests and dispatcher for DifferenceBetween
1 parent ddef172 commit 311d10d

3 files changed

Lines changed: 10 additions & 118 deletions

File tree

interpreter/operator_dispatcher.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,14 @@ func (i *interpreter) binaryOverloads(m model.IBinaryExpression) ([]convert.Over
10321032
Operands: []types.IType{types.DateTime, types.DateTime},
10331033
Result: evalDifferenceBetweenDateTime,
10341034
},
1035+
{
1036+
Operands: []types.IType{types.DateTime, types.Date},
1037+
Result: evalDifferenceBetweenDateTime,
1038+
},
1039+
{
1040+
Operands: []types.IType{types.Date, types.DateTime},
1041+
Result: evalDifferenceBetweenDateTime,
1042+
},
10351043
}, nil
10361044
case *model.In:
10371045
// TODO(b/301606416): Support all other In operator overloads.

tests/enginetests/operator_clinical_test.go

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -29,122 +29,6 @@ import (
2929
"google.golang.org/protobuf/testing/protocmp"
3030
)
3131

32-
func TestCalculateAge(t *testing.T) {
33-
tests := []struct {
34-
name string
35-
cql string
36-
wantModel model.IExpression
37-
wantResult result.Value
38-
}{
39-
// Age calculation functions - Note that these use the default evaluation timestamp
40-
{
41-
name: "AgeInYears Date",
42-
cql: "AgeInYears()",
43-
wantModel: &model.CalculateAge{
44-
Precision: model.YEAR,
45-
UnaryExpression: &model.UnaryExpression{
46-
Expression: model.ResultType(types.Integer),
47-
Operand: &model.ToDateTime{
48-
UnaryExpression: &model.UnaryExpression{
49-
Expression: model.ResultType(types.DateTime),
50-
Operand: &model.Property{
51-
Expression: model.ResultType(types.Date),
52-
Source: &model.Property{
53-
Expression: model.ResultType(&types.Named{TypeName: "FHIR.date"}),
54-
Source: &model.ExpressionRef{
55-
Expression: model.ResultType(&types.Named{TypeName: "FHIR.Patient"}),
56-
Name: "Patient",
57-
},
58-
Path: "birthDate",
59-
},
60-
Path: "value",
61-
},
62-
},
63-
},
64-
},
65-
},
66-
wantResult: newOrFatal(t, 75), // The test patient birthday is 1950-01-01
67-
},
68-
{
69-
name: "AgeInMonths Date",
70-
cql: "AgeInMonths()",
71-
wantResult: newOrFatal(t, 903), // 75 years * 12 months/year, approximately
72-
},
73-
{
74-
name: "AgeInWeeks Date",
75-
cql: "AgeInWeeks()",
76-
wantResult: newOrFatal(t, 3928), // 75 years * 52 weeks/year, approximately
77-
},
78-
{
79-
name: "AgeInDays Date",
80-
cql: "AgeInDays()",
81-
wantResult: newOrFatal(t, 27500), // 75 years * 365.25 days/year, approximately
82-
},
83-
{
84-
name: "AgeInHours Date",
85-
cql: "AgeInHours()",
86-
wantResult: newOrFatal(t, 660000), // 75 years * 365.25 days/year * 24 hours/day, approximately
87-
},
88-
{
89-
name: "AgeInMinutes Date",
90-
cql: "AgeInMinutes()",
91-
wantResult: newOrFatal(t, 39600000), // 75 years * 365.25 days/year * 24 hours/day * 60 minutes/hour, approximately
92-
},
93-
{
94-
name: "AgeInSeconds Date",
95-
cql: "AgeInSeconds()",
96-
wantResult: newOrFatal(t, 2376000000), // 75 years * 365.25 days/year * 24 hours/day * 60 minutes/hour * 60 seconds/minute, approximately
97-
},
98-
// Custom birth date tests (using the evaluation time of 2025-04-16)
99-
{
100-
name: "AgeInYears with explicit Date",
101-
cql: "CalculateAgeInYears(@1981-06-15)",
102-
wantResult: newOrFatal(t, 43), // Age from 1981-06-15 to test time (2025-04-16)
103-
},
104-
{
105-
name: "AgeInMonths with explicit Date",
106-
cql: "CalculateAgeInMonths(@2022-06-15)",
107-
wantResult: newOrFatal(t, 34), // Age from 2022-06-15 to test time (2025-04-16)
108-
},
109-
{
110-
name: "AgeInDays with explicit DateTime",
111-
cql: "CalculateAgeInDays(@2023-06-15T10:01:01.000Z)",
112-
wantResult: newOrFatal(t, 671), // Days from 2023-06-15 to test time (2025-04-16)
113-
},
114-
{
115-
name: "AgeInHours with explicit DateTime",
116-
cql: "CalculateAgeInHours(@2025-04-15T10:01:01.000Z)",
117-
wantResult: newOrFatal(t, 24), // Hours from 2025-04-15 to test time (2025-04-16)
118-
},
119-
// Null input
120-
{
121-
name: "CalculateAgeInYears with null",
122-
cql: "CalculateAgeInYears(null as Date)",
123-
wantResult: newOrFatal(t, nil),
124-
},
125-
}
126-
127-
for _, tc := range tests {
128-
t.Run(tc.name, func(t *testing.T) {
129-
p := newFHIRParser(t)
130-
parsedLibs, err := p.Libraries(context.Background(), wrapInLib(t, tc.cql), parser.Config{})
131-
if err != nil {
132-
t.Fatalf("Parse returned unexpected error: %v", err)
133-
}
134-
if diff := cmp.Diff(tc.wantModel, getTESTRESULTModel(t, parsedLibs)); tc.wantModel != nil && diff != "" {
135-
t.Errorf("Parse diff (-want +got):\n%s", diff)
136-
}
137-
138-
results, err := interpreter.Eval(context.Background(), parsedLibs, defaultInterpreterConfig(t, p))
139-
if err != nil {
140-
t.Fatalf("Eval returned unexpected error: %v", err)
141-
}
142-
if diff := cmp.Diff(tc.wantResult, getTESTRESULT(t, results), protocmp.Transform()); diff != "" {
143-
t.Errorf("Eval diff (-want +got)\n%v", diff)
144-
}
145-
})
146-
}
147-
}
14832

14933
func TestCalculateAgeAt(t *testing.T) {
15034
tests := []struct {

tests/enginetests/operator_datetime_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,12 @@ func TestDateTimeOperatorDifferenceBetween(t *testing.T) {
379379
},
380380
{
381381
name: "difference in years between null and @2022 returns null",
382-
cql: "difference in years between null and @2022",
382+
cql: "difference in years between (null as Date) and @2022",
383383
wantResult: newOrFatal(t, nil),
384384
},
385385
{
386386
name: "difference in years between @2020 and null returns null",
387-
cql: "difference in years between @2020 and null",
387+
cql: "difference in years between @2020 and (null as Date)",
388388
wantResult: newOrFatal(t, nil),
389389
},
390390
{

0 commit comments

Comments
 (0)