hqmf2js 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +17 -0
  3. data/Gemfile +41 -0
  4. data/Gemfile.lock +202 -0
  5. data/README.md +7 -0
  6. data/Rakefile +22 -0
  7. data/VERSION +1 -0
  8. data/app/assets/javascripts/hqmf_util.js.coffee +776 -0
  9. data/app/assets/javascripts/logging_utils.js.coffee +150 -0
  10. data/app/assets/javascripts/patient_api_extension.js.coffee +36 -0
  11. data/app/assets/javascripts/specifics.js.coffee +462 -0
  12. data/bin/hqmf2js.rb +25 -0
  13. data/config/warble.rb +144 -0
  14. data/hqmf2js.gemspec +20 -0
  15. data/lib/config/codes.xml +1935 -0
  16. data/lib/generator/characteristic.js.erb +19 -0
  17. data/lib/generator/codes_to_json.rb +81 -0
  18. data/lib/generator/converter.rb +60 -0
  19. data/lib/generator/data_criteria.js.erb +47 -0
  20. data/lib/generator/derived_data.js.erb +5 -0
  21. data/lib/generator/js.rb +263 -0
  22. data/lib/generator/measure_period.js.erb +18 -0
  23. data/lib/generator/patient_data.js.erb +22 -0
  24. data/lib/generator/population_criteria.js.erb +4 -0
  25. data/lib/generator/precondition.js.erb +14 -0
  26. data/lib/hqmf2js.rb +20 -0
  27. data/lib/hquery/engine.rb +4 -0
  28. data/lib/tasks/codes.rake +12 -0
  29. data/lib/tasks/coffee.rake +15 -0
  30. data/lib/tasks/convert.rake +47 -0
  31. data/lib/tasks/cover_me.rake +8 -0
  32. data/test/fixtures/NQF59New.xml +1047 -0
  33. data/test/fixtures/codes/codes.xls +0 -0
  34. data/test/fixtures/codes/codes.xml +1941 -0
  35. data/test/fixtures/i2b2.xml +305 -0
  36. data/test/fixtures/invalid/missing_id.xml +18 -0
  37. data/test/fixtures/invalid/unknown_criteria_type.xml +16 -0
  38. data/test/fixtures/invalid/unknown_demographic_entry.xml +16 -0
  39. data/test/fixtures/invalid/unknown_population_type.xml +9 -0
  40. data/test/fixtures/invalid/unknown_value_type.xml +18 -0
  41. data/test/fixtures/js/59New.js +366 -0
  42. data/test/fixtures/js/test1.js +356 -0
  43. data/test/fixtures/js/test2.js +366 -0
  44. data/test/fixtures/json/0043.json +6 -0
  45. data/test/fixtures/json/0043_hqmf1.json +1 -0
  46. data/test/fixtures/json/0043_hqmf2.json +172 -0
  47. data/test/fixtures/json/59New.json +1352 -0
  48. data/test/fixtures/patient_api.js +2823 -0
  49. data/test/fixtures/patients/francis_drake.json +1180 -0
  50. data/test/fixtures/patients/larry_vanderman.json +645 -0
  51. data/test/test_helper.rb +58 -0
  52. data/test/unit/codes_to_json_test.rb +38 -0
  53. data/test/unit/effective_date_test.rb +48 -0
  54. data/test/unit/hqmf_from_json_javascript_test.rb +108 -0
  55. data/test/unit/hqmf_javascript_test.rb +175 -0
  56. data/test/unit/library_function_test.rb +553 -0
  57. data/test/unit/specifics_test.rb +757 -0
  58. metadata +183 -0
@@ -0,0 +1,757 @@
1
+ require_relative '../test_helper'
2
+ require 'hquery-patient-api'
3
+
4
+ class SpecificsTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @context = get_js_context(HQMF2JS::Generator::JS.library_functions)
8
+ test_initialize_js =
9
+ "
10
+ Specifics.initialize({},hqmfjs, {'id':'OccurrenceAEncounter', 'type':'Encounter', 'function':'SourceOccurrenceAEncounter'},{'id':'OccurrenceBEncounter', 'type':'Encounter', 'function':'SourceOccurrenceBEncounter'})
11
+ hqmfjs.SourceOccurrenceAEncounter = function(patient) {
12
+ return [{'id':1},{'id':2},{'id':3},{'id':4},{'id':5}]
13
+ }
14
+ hqmfjs.SourceOccurrenceBEncounter = function(patient) {
15
+ return [{'id':1},{'id':2},{'id':3},{'id':4},{'id':5}]
16
+ }
17
+ "
18
+ @context.eval(test_initialize_js)
19
+ end
20
+
21
+
22
+ def test_specifics_initialized_proper
23
+
24
+ @context.eval('Specifics.KEY_LOOKUP[0]').must_equal 'OccurrenceAEncounter'
25
+ @context.eval('Specifics.KEY_LOOKUP[1]').must_equal 'OccurrenceBEncounter'
26
+ @context.eval("Specifics.INDEX_LOOKUP['OccurrenceAEncounter']").must_equal 0
27
+ @context.eval("Specifics.INDEX_LOOKUP['OccurrenceBEncounter']").must_equal 1
28
+ @context.eval('Specifics.FUNCTION_LOOKUP[0]').must_equal 'SourceOccurrenceAEncounter'
29
+ @context.eval('Specifics.FUNCTION_LOOKUP[1]').must_equal 'SourceOccurrenceBEncounter'
30
+ @context.eval("Specifics.TYPE_LOOKUP['Encounter'].length").must_equal 2
31
+ @context.eval("Specifics.TYPE_LOOKUP['Encounter'][0]").must_equal 0
32
+ @context.eval("Specifics.TYPE_LOOKUP['Encounter'][1]").must_equal 1
33
+ end
34
+
35
+ def test_specifics_row_union
36
+
37
+ union_rows = "
38
+ var row1 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1}});
39
+ var specific1 = new Specifics([row1]);
40
+ var row2 = new Row('OccurrenceAEncounter',{'OccurrenceBEncounter':{'id':2}});
41
+ var specific2 = new Specifics([row2]);
42
+ result = specific1.union(specific2);
43
+ result.rows.length;
44
+ "
45
+
46
+ @context.eval(union_rows).must_equal 2
47
+ @context.eval("result.rows[0].values[0].id").must_equal 1
48
+ @context.eval("result.rows[0].values[1]").must_equal '*'
49
+ @context.eval("result.rows[1].values[0]").must_equal '*'
50
+ @context.eval("result.rows[1].values[1].id").must_equal 2
51
+
52
+ end
53
+
54
+ def test_row_creation
55
+
56
+ rows = "
57
+ var row1 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1}});
58
+ var row2 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':2}});
59
+ var row3 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':2}});
60
+ var row4 = new Row(undefined, {});
61
+ "
62
+
63
+ @context.eval(rows)
64
+ @context.eval("row1.values[0].id").must_equal 1
65
+ @context.eval("row1.values[1]").must_equal '*'
66
+ @context.eval("row2.values[0]").must_equal '*'
67
+ @context.eval("row2.values[1].id").must_equal 2
68
+ @context.eval("row3.values[0].id").must_equal 1
69
+ @context.eval("row3.values[1].id").must_equal 2
70
+ @context.eval("row4.values[0]").must_equal '*'
71
+ @context.eval("row4.values[1]").must_equal '*'
72
+ end
73
+
74
+
75
+ def test_row_match
76
+ rows = "
77
+ var row1 = new Row(undefined, {});
78
+ "
79
+ @context.eval(rows)
80
+ @context.eval("Row.match('*', {'id':1}).id").must_equal 1
81
+ @context.eval("Row.match({'id':2}, '*').id").must_equal 2
82
+ @context.eval("Row.match({'id':1}, {'id':1}).id").must_equal 1
83
+ @context.eval("Row.match('*', '*')").must_equal '*'
84
+ @context.eval("typeof(Row.match({'id':3}, {'id':2})) === 'undefined'").must_equal true
85
+
86
+ end
87
+
88
+
89
+ def test_row_equal
90
+
91
+ rows = "
92
+ var row1 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1}});
93
+ var row2 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':2}});
94
+ var row3 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':2}});
95
+ var row4 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':2},'OccurrenceBEncounter':{'id':3}});
96
+ var row5 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':2},'OccurrenceBEncounter':{'id':3}});
97
+ var row6 = new Row(undefined,{});
98
+ "
99
+
100
+ @context.eval(rows)
101
+ @context.eval("row1.equals(row1)").must_equal true
102
+ @context.eval("row1.equals(row2)").must_equal false
103
+ @context.eval("row2.equals(row2)").must_equal true
104
+ @context.eval("row3.equals(row4)").must_equal false
105
+ @context.eval("row4.equals(row5)").must_equal true
106
+ @context.eval("row6.equals(row6)").must_equal true
107
+
108
+ end
109
+
110
+
111
+ def test_row_intersect
112
+
113
+ rows = "
114
+ var row1 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1}});
115
+ var row2 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':2}});
116
+ var row3 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':2}});
117
+ var row4 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':2},'OccurrenceBEncounter':{'id':2}});
118
+ var row5 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':3},'OccurrenceBEncounter':{'id':3}});
119
+ var row6 = new Row(undefined,{});
120
+ "
121
+
122
+ @context.eval(rows)
123
+ @context.eval("row1.intersect(row2).values[0].id").must_equal 1
124
+ @context.eval("row1.intersect(row2).values[1].id").must_equal 2
125
+ @context.eval("row2.intersect(row1).values[0].id").must_equal 1
126
+ @context.eval("row2.intersect(row1).values[1].id").must_equal 2
127
+ @context.eval("row1.intersect(row3).values[0].id").must_equal 1
128
+ @context.eval("row1.intersect(row3).values[1].id").must_equal 2
129
+ @context.eval("row2.intersect(row3).values[0].id").must_equal 1
130
+ @context.eval("row2.intersect(row3).values[1].id").must_equal 2
131
+ @context.eval("typeof(row1.intersect(row4)) === 'undefined'").must_equal true
132
+ @context.eval("row2.intersect(row4).values[0].id").must_equal 2
133
+ @context.eval("row2.intersect(row4).values[1].id").must_equal 2
134
+ @context.eval("typeof(row1.intersect(row5)) === 'undefined'").must_equal true
135
+ @context.eval("typeof(row2.intersect(row5)) === 'undefined'").must_equal true
136
+ @context.eval("typeof(row3.intersect(row4)) === 'undefined'").must_equal true
137
+ @context.eval("row1.intersect(row6).values[0].id").must_equal 1
138
+ @context.eval("row1.intersect(row6).values[1]").must_equal '*'
139
+ @context.eval("row2.intersect(row6).values[0]").must_equal '*'
140
+ @context.eval("row2.intersect(row6).values[1].id").must_equal 2
141
+ @context.eval("row6.intersect(row6).values[0]").must_equal '*'
142
+ @context.eval("row6.intersect(row6).values[1]").must_equal '*'
143
+
144
+ end
145
+
146
+ def test_specifics_row_intersection
147
+
148
+ intersect_rows = "
149
+ var row1 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1}});
150
+ var row2 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':2}});
151
+ var row3 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':2}});
152
+ var row4 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':2},'OccurrenceBEncounter':{'id':2}});
153
+ var row5 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':3},'OccurrenceBEncounter':{'id':3}});
154
+ var row6 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':3}});
155
+
156
+ var specific1 = new Specifics([row1]);
157
+ var specific2 = new Specifics([row2]);
158
+ var specific3 = new Specifics([row3,row4]);
159
+ var specific4 = new Specifics([row3,row6]);
160
+ var specific5 = new Specifics([row5,row6]);
161
+
162
+ var allSpecific1 = new Specifics();
163
+ allSpecific1.addIdentityRow();
164
+ allSpecific1.addIdentityRow();
165
+ allSpecific1.addIdentityRow();
166
+ var allSpecific2 = new Specifics();
167
+ allSpecific2.addIdentityRow();
168
+ allSpecific2.addIdentityRow();
169
+ allSpecific2.addIdentityRow();
170
+
171
+ "
172
+
173
+ @context.eval(intersect_rows)
174
+ @context.eval("specific1.intersect(specific2).rows.length").must_equal 1
175
+ @context.eval("specific1.intersect(specific2).rows[0].values[0].id").must_equal 1
176
+ @context.eval("specific1.intersect(specific2).rows[0].values[1].id").must_equal 2
177
+
178
+ @context.eval("specific1.intersect(specific3).rows.length").must_equal 1
179
+ @context.eval("specific1.intersect(specific3).rows[0].values[0].id").must_equal 1
180
+ @context.eval("specific1.intersect(specific3).rows[0].values[1].id").must_equal 2
181
+
182
+ @context.eval("specific1.intersect(specific4).rows.length").must_equal 2
183
+ @context.eval("specific1.intersect(specific4).rows[0].values[0].id").must_equal 1
184
+ @context.eval("specific1.intersect(specific4).rows[0].values[1].id").must_equal 2
185
+ @context.eval("specific1.intersect(specific4).rows[1].values[0].id").must_equal 1
186
+ @context.eval("specific1.intersect(specific4).rows[1].values[1].id").must_equal 3
187
+
188
+ @context.eval("specific2.intersect(specific3).rows.length").must_equal 2
189
+ @context.eval("specific2.intersect(specific3).rows[0].values[0].id").must_equal 1
190
+ @context.eval("specific2.intersect(specific3).rows[0].values[1].id").must_equal 2
191
+ @context.eval("specific2.intersect(specific3).rows[1].values[0].id").must_equal 2
192
+ @context.eval("specific2.intersect(specific3).rows[1].values[1].id").must_equal 2
193
+
194
+ @context.eval("specific2.intersect(specific5).rows.length").must_equal 0
195
+
196
+ @context.eval("specific4.intersect(specific5).rows.length").must_equal 1
197
+ @context.eval("specific4.intersect(specific5).rows[0].values[0].id").must_equal 1
198
+ @context.eval("specific4.intersect(specific5).rows[0].values[1].id").must_equal 3
199
+
200
+
201
+ @context.eval("allSpecific1.intersect(allSpecific2).rows.length").must_equal 1
202
+
203
+ end
204
+
205
+ def test_negation
206
+ rows = "
207
+ var row1 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1}});
208
+ var row2 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':2}});
209
+ var row3 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':2}});
210
+ var row4 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':2},'OccurrenceBEncounter':{'id':3}});
211
+ var row5 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':3},'OccurrenceBEncounter':{'id':4}});
212
+ var row6 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':3}});
213
+
214
+ var specific1 = new Specifics([row1]);
215
+ var specific2 = new Specifics([row2]);
216
+ var specific3 = new Specifics([row3,row4]);
217
+ var specific4 = new Specifics([row3,row6]);
218
+ var specific5 = new Specifics([row5,row6]);
219
+ var specific6 = new Specifics([row1,row2])
220
+ "
221
+
222
+ # test negation single specific
223
+ # test negation multiple specifics
224
+
225
+ @context.eval(rows)
226
+
227
+ # has row checks
228
+ @context.eval('specific1.hasRow(row1)').must_equal true
229
+ @context.eval('specific1.hasRow(row2)').must_equal true
230
+ @context.eval('specific1.hasRow(row3)').must_equal true
231
+ @context.eval('specific1.hasRow(row4)').must_equal false
232
+ @context.eval('specific1.hasRow(row5)').must_equal false
233
+
234
+ # cartesian checks
235
+ @context.eval('Specifics._generateCartisian([[1,2,3]]).length').must_equal 3
236
+ @context.eval('Specifics._generateCartisian([[1,2,3],[5,6]]).length').must_equal 6
237
+ @context.eval('Specifics._generateCartisian([[1,2,3],[5,6]])[0][0]').must_equal 1
238
+ @context.eval('Specifics._generateCartisian([[1,2,3],[5,6]])[0][1]').must_equal 5
239
+ @context.eval('Specifics._generateCartisian([[1,2,3],[5,6]])[1][0]').must_equal 1
240
+ @context.eval('Specifics._generateCartisian([[1,2,3],[5,6]])[1][1]').must_equal 6
241
+ @context.eval('Specifics._generateCartisian([[1,2,3],[5,6]])[2][0]').must_equal 2
242
+ @context.eval('Specifics._generateCartisian([[1,2,3],[5,6]])[2][1]').must_equal 5
243
+
244
+ # specificsWithValue on Row
245
+ @context.eval('row1.specificsWithValues()[0]').must_equal 0
246
+ @context.eval('row2.specificsWithValues()[0]').must_equal 1
247
+ @context.eval('row3.specificsWithValues()[0]').must_equal 0
248
+ @context.eval('row3.specificsWithValues()[1]').must_equal 1
249
+
250
+ # specificsWithValue on Specific
251
+ @context.eval('specific1.specificsWithValues()[0]').must_equal 0
252
+ @context.eval('specific2.specificsWithValues()[0]').must_equal 1
253
+ @context.eval('specific3.specificsWithValues()[0]').must_equal 0
254
+ @context.eval('specific3.specificsWithValues()[1]').must_equal 1
255
+ @context.eval('specific6.specificsWithValues()[0]').must_equal 0
256
+ @context.eval('specific6.specificsWithValues()[1]').must_equal 1
257
+
258
+ @context.eval('specific1.negate().rows.length').must_equal 4
259
+ @context.eval('specific1.negate().rows[0].values[0].id').must_equal 2
260
+ @context.eval('specific1.negate().rows[1].values[0].id').must_equal 3
261
+ @context.eval('specific1.negate().rows[2].values[0].id').must_equal 4
262
+ @context.eval('specific1.negate().rows[3].values[0].id').must_equal 5
263
+
264
+ # 5*5 values = 25 in the cartesian - 2 in the non-negated = 23 negated - 5 rows with OccurrA and OccurrB equal = 18!
265
+ @context.eval('specific5.negate().rows.length').must_equal 18
266
+
267
+ end
268
+
269
+ def test_add_rows_has_rows_has_specifics
270
+ rows = "
271
+ var row1 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1}});
272
+ var row2 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':2}});
273
+ var row3 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':2}});
274
+ var row3 = new Row(undefined, {});
275
+
276
+ var specific1 = new Specifics();
277
+ var specific2 = new Specifics([row2]);
278
+ "
279
+
280
+ # test negation single specific
281
+ # test negation multiple specifics
282
+
283
+ @context.eval(rows)
284
+
285
+ @context.eval('specific1.hasRows()').must_equal false
286
+ @context.eval('specific2.hasRows()').must_equal true
287
+ @context.eval('specific1.hasSpecifics()').must_equal false
288
+ @context.eval('specific2.hasSpecifics()').must_equal true
289
+ @context.eval('row3.hasSpecifics()').must_equal false
290
+ @context.eval('row2.hasSpecifics()').must_equal true
291
+
292
+ @context.eval('specific1.rows.length').must_equal 0
293
+ @context.eval('specific1.addRows([row2])')
294
+ @context.eval('specific1.rows.length').must_equal 1
295
+ @context.eval('specific2.rows.length').must_equal 1
296
+ @context.eval('specific2.addRows([row3])')
297
+ @context.eval('specific2.rows.length').must_equal 2
298
+
299
+ end
300
+
301
+ def test_maintain_specfics
302
+ @context.eval('var x = new Boolean(true)')
303
+ @context.eval("x.specificContext = 'specificContext'")
304
+ @context.eval("x.specific_occurrence = 'specific_occurrence'")
305
+ @context.eval('var a = new Boolean(true)')
306
+ @context.eval("a = Specifics.maintainSpecifics(a,x)")
307
+ @context.eval("typeof(a.specificContext) != 'undefined'").must_equal true
308
+ @context.eval("typeof(a.specific_occurrence) != 'undefined'").must_equal true
309
+
310
+ end
311
+
312
+ def test_compact_reused_events
313
+ rows = "
314
+ var row1 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1}});
315
+ var row2 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':2}});
316
+ var row3 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':2}});
317
+ var row4 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':2},'OccurrenceBEncounter':{'id':2}});
318
+ var row5 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':3},'OccurrenceBEncounter':{'id':3}});
319
+ var row6 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':3}});
320
+
321
+ var specific1 = new Specifics([row1,row2,row3,row4,row5,row6]);
322
+ "
323
+
324
+ @context.eval(rows)
325
+
326
+ @context.eval('specific1.rows.length').must_equal 6
327
+ @context.eval('specific1.compactReusedEvents().rows.length').must_equal 4
328
+
329
+ end
330
+
331
+ def test_row_build_rows_for_matching
332
+
333
+ events = "
334
+ var entryKey = 'OccurrenceAEncounter';
335
+ var boundsKey = 'OccurrenceBEncounter';
336
+ var entry = {'id':3};
337
+ var bounds = [{'id':1},{'id':2},{'id':3},{'id':4},{'id':5},{'id':6},{'id':7},{'id':8}];
338
+ "
339
+
340
+ @context.eval(events)
341
+ @context.eval('var rows = Row.buildRowsForMatching(entryKey,entry,boundsKey,bounds)')
342
+ @context.eval('rows.length').must_equal 8
343
+ @context.eval('rows[0].values.length').must_equal 2
344
+ @context.eval('rows[0].values[0].id').must_equal 3
345
+ @context.eval('rows[0].values[1].id').must_equal 1
346
+ @context.eval('rows[7].values[0].id').must_equal 3
347
+ @context.eval('rows[7].values[1].id').must_equal 8
348
+ @context.eval('var specific = new Specifics(rows)')
349
+ @context.eval('specific.rows.length').must_equal 8
350
+ @context.eval('specific.compactReusedEvents().rows.length').must_equal 7
351
+ @context.eval('var rows = Row.buildRowsForMatching(undefined,entry,boundsKey,bounds)')
352
+ @context.eval('rows.length').must_equal 8
353
+ @context.eval("rows[0].tempValue.id").must_equal 3
354
+ @context.eval("rows[5].tempValue.id").must_equal 3
355
+ @context.eval("rows[0].tempValue.id").must_equal 3
356
+ @context.eval("rows[0].values[1].id").must_equal 1
357
+ @context.eval("rows[5].values[1].id").must_equal 6
358
+ end
359
+
360
+ def test_row_build_for_data_criteria
361
+
362
+ events = "
363
+ var entryKey = 'OccurrenceAEncounter';
364
+ var entries = [{'id':1},{'id':2},{'id':3},{'id':4},{'id':5},{'id':6},{'id':7},{'id':8}];
365
+ "
366
+
367
+ @context.eval(events)
368
+ @context.eval('var rows = Row.buildForDataCriteria(entryKey,entries)')
369
+ @context.eval('rows.length').must_equal 8
370
+ @context.eval('rows[0].values.length').must_equal 2
371
+ @context.eval('rows[0].values[0].id').must_equal 1
372
+ @context.eval('rows[0].values[1]').must_equal '*'
373
+ @context.eval('rows[7].values[0].id').must_equal 8
374
+ @context.eval('rows[7].values[1]').must_equal '*'
375
+
376
+ end
377
+
378
+ def test_finalize_events
379
+ rows = "
380
+ var row1 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1}});
381
+ var row2 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':2}});
382
+ var row3 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':2}});
383
+ var row4 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':4}});
384
+ var row5 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':5}});
385
+ var row6 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':4}});
386
+ var row7 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':5}});
387
+ var row8 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':2},'OccurrenceBEncounter':{'id':4}});
388
+
389
+ var specific1 = new Specifics([row1,row2]);
390
+ var specific2 = new Specifics([row3,row4,row5]);
391
+ var specific3 = new Specifics([row6,row7,row8]);
392
+ "
393
+ @context.eval(rows)
394
+ @context.eval('var result = specific1.finalizeEvents(specific2,specific3)')
395
+ @context.eval('result.rows.length').must_equal 3
396
+ @context.eval('result.rows[0].values[0].id').must_equal 1
397
+ @context.eval('result.rows[0].values[1].id').must_equal 4
398
+ @context.eval('result.rows[1].values[0].id').must_equal 1
399
+ @context.eval('result.rows[1].values[1].id').must_equal 5
400
+ @context.eval('result.rows[2].values[0].id').must_equal 2
401
+ @context.eval('result.rows[2].values[1].id').must_equal 4
402
+
403
+ @context.eval('var result = specific2.finalizeEvents(specific1,specific3)')
404
+ @context.eval('result.rows.length').must_equal 3
405
+
406
+ @context.eval('var result = specific1.finalizeEvents(null,specific3)')
407
+ @context.eval('result.rows.length').must_equal 3
408
+
409
+ # result if 5 and not 6 becasue the 2/2 row gets dropped
410
+ @context.eval('var result = specific1.finalizeEvents(specific2, null)')
411
+ @context.eval('result.rows.length').must_equal 5
412
+
413
+ end
414
+
415
+ def test_validate
416
+ rows = "
417
+ var row1 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1}});
418
+ var row2 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':2}});
419
+ var row3 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':2}});
420
+ var row4 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':4}});
421
+ var row5 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':5}});
422
+ var row6 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':4}});
423
+ var row7 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':5}});
424
+ var row8 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':2},'OccurrenceBEncounter':{'id':4}});
425
+
426
+ var row9 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':6}});
427
+
428
+ var specific1 = new Specifics([row1,row2]);
429
+ var specific2 = new Specifics([row3,row4,row5]);
430
+ var specific3 = new Specifics([row6,row7,row8]);
431
+ var specific4 = new Specifics([row9]);
432
+ var specific5 = new Specifics();
433
+
434
+ var pop1 = new Boolean(true)
435
+ pop1.specificContext = specific1
436
+
437
+ var pop2 = new Boolean(true)
438
+ pop2.specificContext = specific2
439
+
440
+ var pop3 = new Boolean(true)
441
+ pop3.specificContext = specific3
442
+
443
+ var pop4 = new Boolean(true)
444
+ pop4.specificContext = specific4
445
+
446
+ var pop5 = new Boolean(true)
447
+ pop5.specificContext = specific5
448
+
449
+ var pop3f = new Boolean(false)
450
+ pop3f.specificContext = specific3
451
+
452
+ "
453
+ @context.eval(rows)
454
+
455
+ @context.eval('Specifics.validate(pop1,pop2,pop3)').must_equal true
456
+ @context.eval('Specifics.validate(pop1,pop2,pop4)').must_equal false
457
+ @context.eval('Specifics.validate(pop1,pop2,pop5)').must_equal false
458
+ @context.eval('Specifics.validate(pop3f,pop1,pop2)').must_equal false
459
+
460
+ end
461
+
462
+ def test_intersect_all
463
+
464
+ rows = "
465
+ var row1 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1}});
466
+ var row2 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':2}});
467
+ var row3 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':2}});
468
+ var row4 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':4}});
469
+ var row5 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':5}});
470
+ var row6 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':4}});
471
+ var row7 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':5}});
472
+ var row8 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':2},'OccurrenceBEncounter':{'id':4}});
473
+
474
+ var specific1 = new Specifics([row1,row2]);
475
+ var specific2 = new Specifics([row3,row4,row5]);
476
+ var specific3 = new Specifics([row6,row7,row8]);
477
+
478
+ var pop1 = new Boolean(true)
479
+ pop1.specificContext = specific1
480
+
481
+ var pop2 = new Boolean(true)
482
+ pop2.specificContext = specific2
483
+
484
+ var pop3 = new Boolean(true)
485
+ pop3.specificContext = specific3
486
+
487
+
488
+ "
489
+ @context.eval(rows)
490
+
491
+ @context.eval('var intersection = Specifics.intersectAll(new Boolean(true), [pop1,pop2,pop3])')
492
+ assert @context.eval('intersection.isTrue()')
493
+ @context.eval('var result = intersection.specificContext')
494
+
495
+ @context.eval('result.rows.length').must_equal 3
496
+
497
+ @context.eval('result.rows[0].values[0].id').must_equal 1
498
+ @context.eval('result.rows[0].values[1].id').must_equal 4
499
+ @context.eval('result.rows[1].values[0].id').must_equal 1
500
+ @context.eval('result.rows[1].values[1].id').must_equal 5
501
+ @context.eval('result.rows[2].values[0].id').must_equal 2
502
+ @context.eval('result.rows[2].values[1].id').must_equal 4
503
+
504
+ @context.eval('var intersection = Specifics.intersectAll(new Boolean(true), [pop1,pop2,pop3], true)')
505
+ @context.eval('var result = intersection.specificContext')
506
+
507
+ # 5*5 = 25 - 5 equal rows - 3 non-negated = 17
508
+ @context.eval('result.rows.length').must_equal 17
509
+
510
+ end
511
+
512
+ def test_union_all
513
+
514
+ rows = "
515
+ var row1 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1}});
516
+ var row2 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':2}});
517
+ var row3 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':2}});
518
+ var row4 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':4}});
519
+ var row5 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':5}});
520
+ var row6 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':4}});
521
+ var row7 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':5}});
522
+ var row8 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':2},'OccurrenceBEncounter':{'id':4}});
523
+
524
+ var specific1 = new Specifics([row1,row2]);
525
+ var specific2 = new Specifics([row3,row4,row5]);
526
+ var specific3 = new Specifics([row6,row7,row8]);
527
+
528
+ var pop1 = new Boolean(true)
529
+ pop1.specificContext = specific1
530
+
531
+ var pop2 = new Boolean(true)
532
+ pop2.specificContext = specific2
533
+
534
+ var pop3 = new Boolean(true)
535
+ pop3.specificContext = specific3
536
+
537
+
538
+ "
539
+ @context.eval(rows)
540
+
541
+ @context.eval('var union = Specifics.unionAll(new Boolean(true), [pop1,pop2,pop3])')
542
+ assert @context.eval('union.isTrue()')
543
+ @context.eval('var result = union.specificContext')
544
+
545
+ @context.eval('result.rows.length').must_equal 8
546
+
547
+ @context.eval('var union = Specifics.unionAll(new Boolean(true), [pop1,pop2,pop3], true)')
548
+ assert @context.eval('union.isTrue()')
549
+ @context.eval('var result = union.specificContext')
550
+
551
+ # originally 5*5, but we remove 1,2 from the left and 2,4,5 from the right
552
+ # that leaves [3,4,5] x [1,3] which is 6 rows... minus the 3,3 row we get 5 rows
553
+
554
+ @context.eval('result.rows.length').must_equal 5
555
+
556
+ end
557
+
558
+ def test_row_grouping_key
559
+
560
+ rows = "
561
+ Specifics.initialize({},hqmfjs, {'id':'OccurrenceAEncounter', 'type':'Encounter', 'function':'SourceOccurrenceAEncounter'},{'id':'OccurrenceBEncounter', 'type':'Encounter', 'function':'SourceOccurrenceBEncounter'},{'id':'OccurrenceAProcedure', 'type':'Procedure', 'function':'SourceOccurrenceAProcedure'})
562
+
563
+ var row1 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1}});
564
+ var row2 = new Row('OccurrenceBEncounter',{'OccurrenceBEncounter':{'id':2}});
565
+ var row3 = new Row('OccurrenceAEncounter',{'OccurrenceAEncounter':{'id':1},'OccurrenceBEncounter':{'id':4}});
566
+ var row4 = new Row(undefined, {});
567
+
568
+ "
569
+ @context.eval(rows)
570
+
571
+ @context.eval("row1.groupKey()").must_equal "1_*_*_"
572
+ @context.eval("row1.groupKey('OccurrenceAEncounter')").must_equal "X_*_*_"
573
+ @context.eval("row1.groupKey('OccurrenceAProcedure')").must_equal "1_*_X_"
574
+ @context.eval("row2.groupKey()").must_equal "*_2_*_"
575
+ @context.eval("row2.groupKey('OccurrenceAProcedure')").must_equal "*_2_X_"
576
+ @context.eval("row3.groupKey()").must_equal "1_4_*_"
577
+ @context.eval("row3.groupKey('OccurrenceAEncounter')").must_equal "X_4_*_"
578
+ @context.eval("row3.groupKey('OccurrenceBEncounter')").must_equal "1_X_*_"
579
+ @context.eval("row3.groupKey('OccurrenceAProcedure')").must_equal "1_4_X_"
580
+ @context.eval("row4.groupKey()").must_equal "*_*_*_"
581
+ @context.eval("row4.groupKey('OccurrenceBEncounter')").must_equal "*_X_*_"
582
+
583
+ end
584
+
585
+ def test_group_specifics
586
+
587
+ rows = "
588
+ var non_specific_rows = [new Row(undefined, {undefined: {id:10}, 'OccurrenceAEncounter':{'id':1}}),
589
+ new Row(undefined, {undefined: {id:11}, 'OccurrenceAEncounter':{'id':1}}),
590
+ new Row(undefined, {undefined: {id:12}, 'OccurrenceAEncounter':{'id':2}}),
591
+ new Row(undefined, {undefined: {id:13}, 'OccurrenceAEncounter':{'id':2}}),
592
+ new Row(undefined, {undefined: {id:14}, 'OccurrenceAEncounter':{'id':2}}),
593
+ new Row(undefined, {undefined: {id:15}, 'OccurrenceAEncounter':{'id':3}})]
594
+
595
+ var specific_rows = [new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': {id:10}, 'OccurrenceBEncounter':{'id':1}}),
596
+ new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': {id:11}, 'OccurrenceBEncounter':{'id':1}}),
597
+ new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': {id:12}, 'OccurrenceBEncounter':{'id':2}}),
598
+ new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': {id:13}, 'OccurrenceBEncounter':{'id':2}}),
599
+ new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': {id:14}, 'OccurrenceBEncounter':{'id':2}}),
600
+ new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': {id:15}, 'OccurrenceBEncounter':{'id':3}})]
601
+
602
+ var specific1 = new Specifics(non_specific_rows);
603
+ var specific2 = new Specifics(specific_rows);
604
+
605
+ "
606
+ @context.eval(rows)
607
+
608
+ @context.eval("specific1.group()['1_*_'].length").must_equal 2
609
+ @context.eval("specific1.group()['2_*_'].length").must_equal 3
610
+ @context.eval("specific1.group()['3_*_'].length").must_equal 1
611
+
612
+ @context.eval("specific2.group('OccurrenceAEncounter')['X_1_'].length").must_equal 2
613
+ @context.eval("specific2.group('OccurrenceAEncounter')['X_2_'].length").must_equal 3
614
+ @context.eval("specific2.group('OccurrenceAEncounter')['X_3_'].length").must_equal 1
615
+
616
+ end
617
+
618
+ def test_extract_events
619
+ rows = "
620
+ var non_specific_rows = [new Row(undefined, {undefined: new hQuery.CodedEntry({_id:10}), 'OccurrenceAEncounter':new hQuery.CodedEntry({'_id':1})}),
621
+ new Row(undefined, {undefined: new hQuery.CodedEntry({_id:11}), 'OccurrenceAEncounter':new hQuery.CodedEntry({'_id':1})}),
622
+ new Row(undefined, {undefined: new hQuery.CodedEntry({_id:12}), 'OccurrenceAEncounter':new hQuery.CodedEntry({'_id':2})}),
623
+ new Row(undefined, {undefined: new hQuery.CodedEntry({_id:13}), 'OccurrenceAEncounter':new hQuery.CodedEntry({'_id':2})}),
624
+ new Row(undefined, {undefined: new hQuery.CodedEntry({_id:14}), 'OccurrenceAEncounter':new hQuery.CodedEntry({'_id':2})}),
625
+ new Row(undefined, {undefined: new hQuery.CodedEntry({_id:15}), 'OccurrenceAEncounter':new hQuery.CodedEntry({'_id':3})})]
626
+
627
+ var specific_rows = [new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': new hQuery.CodedEntry({_id:10}), 'OccurrenceBEncounter':new hQuery.CodedEntry({'_id':1})}),
628
+ new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': new hQuery.CodedEntry({_id:11}), 'OccurrenceBEncounter':new hQuery.CodedEntry({'_id':1})}),
629
+ new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': new hQuery.CodedEntry({_id:12}), 'OccurrenceBEncounter':new hQuery.CodedEntry({'_id':2})}),
630
+ new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': new hQuery.CodedEntry({_id:13}), 'OccurrenceBEncounter':new hQuery.CodedEntry({'_id':2})}),
631
+ new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': new hQuery.CodedEntry({_id:14}), 'OccurrenceBEncounter':new hQuery.CodedEntry({'_id':2})}),
632
+ new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': new hQuery.CodedEntry({_id:15}), 'OccurrenceBEncounter':new hQuery.CodedEntry({'_id':3})})]
633
+ "
634
+ @context.eval(rows)
635
+ @context.eval('Specifics.extractEvents(undefined, non_specific_rows).length').must_equal 6
636
+ @context.eval('Specifics.extractEvents(undefined, non_specific_rows)[0].id').must_equal 10
637
+ @context.eval('Specifics.extractEvents(undefined, non_specific_rows)[1].id').must_equal 11
638
+ @context.eval('Specifics.extractEvents(undefined, non_specific_rows)[2].id').must_equal 12
639
+ @context.eval('Specifics.extractEvents(undefined, non_specific_rows)[3].id').must_equal 13
640
+ @context.eval('Specifics.extractEvents(undefined, non_specific_rows)[4].id').must_equal 14
641
+ @context.eval('Specifics.extractEvents(undefined, non_specific_rows)[5].id').must_equal 15
642
+
643
+ @context.eval("Specifics.extractEvents('OccurrenceAEncounter', specific_rows).length").must_equal 6
644
+ @context.eval("Specifics.extractEvents('OccurrenceAEncounter', specific_rows)[0].id").must_equal 10
645
+ @context.eval("Specifics.extractEvents('OccurrenceAEncounter', specific_rows)[1].id").must_equal 11
646
+ @context.eval("Specifics.extractEvents('OccurrenceAEncounter', specific_rows)[2].id").must_equal 12
647
+ @context.eval("Specifics.extractEvents('OccurrenceAEncounter', specific_rows)[3].id").must_equal 13
648
+ @context.eval("Specifics.extractEvents('OccurrenceAEncounter', specific_rows)[4].id").must_equal 14
649
+ @context.eval("Specifics.extractEvents('OccurrenceAEncounter', specific_rows)[5].id").must_equal 15
650
+
651
+ end
652
+
653
+ def test_specifics_subset_operators
654
+
655
+ rows = "
656
+
657
+ getTime = function(year,month,day) {
658
+ return (new Date(year,month,day)).getTime()/1000
659
+ }
660
+
661
+ var non_specific_rows = [new Row(undefined, {undefined: new hQuery.CodedEntry({_id:10,time:getTime(2010,0,5)}), 'OccurrenceAEncounter':new hQuery.CodedEntry({'_id':1})}),
662
+ new Row(undefined, {undefined: new hQuery.CodedEntry({_id:11,time:getTime(2010,0,1)}), 'OccurrenceAEncounter':new hQuery.CodedEntry({'_id':1})}),
663
+ new Row(undefined, {undefined: new hQuery.CodedEntry({_id:12,time:getTime(2010,0,1)}), 'OccurrenceAEncounter':new hQuery.CodedEntry({'_id':2})}),
664
+ new Row(undefined, {undefined: new hQuery.CodedEntry({_id:13,time:getTime(2010,0,5)}), 'OccurrenceAEncounter':new hQuery.CodedEntry({'_id':2})}),
665
+ new Row(undefined, {undefined: new hQuery.CodedEntry({_id:14,time:getTime(2010,0,2)}), 'OccurrenceAEncounter':new hQuery.CodedEntry({'_id':2})}),
666
+ new Row(undefined, {undefined: new hQuery.CodedEntry({_id:15,time:getTime(2010,0,2)}), 'OccurrenceAEncounter':new hQuery.CodedEntry({'_id':3})})]
667
+
668
+ var specific_rows = [new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': new hQuery.CodedEntry({_id:10,time:getTime(2010,0,5)}), 'OccurrenceBEncounter':new hQuery.CodedEntry({'_id':1})}),
669
+ new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': new hQuery.CodedEntry({_id:11,time:getTime(2010,0,1)}), 'OccurrenceBEncounter':new hQuery.CodedEntry({'_id':1})}),
670
+ new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': new hQuery.CodedEntry({_id:12,time:getTime(2010,0,1)}), 'OccurrenceBEncounter':new hQuery.CodedEntry({'_id':2})}),
671
+ new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': new hQuery.CodedEntry({_id:13,time:getTime(2010,0,5)}), 'OccurrenceBEncounter':new hQuery.CodedEntry({'_id':2})}),
672
+ new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': new hQuery.CodedEntry({_id:14,time:getTime(2010,0,2)}), 'OccurrenceBEncounter':new hQuery.CodedEntry({'_id':2})}),
673
+ new Row('OccurrenceAEncounter',{'OccurrenceAEncounter': new hQuery.CodedEntry({_id:15,time:getTime(2010,0,2)}), 'OccurrenceBEncounter':new hQuery.CodedEntry({'_id':3})})]
674
+
675
+ var specific1 = new Specifics(non_specific_rows);
676
+ var specific2 = new Specifics(specific_rows);
677
+ var specific3 = new Specifics([new Row(undefined)]);
678
+ var specific4 = new Specifics()
679
+
680
+ "
681
+ @context.eval(rows)
682
+
683
+ ###
684
+ ##### COUNT
685
+ ###
686
+
687
+ moreThanOne = 'new IVL_PQ(new PQ(2))'
688
+ lessThanThree = 'new IVL_PQ(null, new PQ(2))'
689
+ exactly1 = 'new IVL_PQ(new PQ(1), new PQ(1))'
690
+
691
+ @context.eval("specific1.COUNT(#{moreThanOne}).rows.length").must_equal 5
692
+ @context.eval("specific1.COUNT(#{moreThanOne}).rows[0].tempValue.id").must_equal 10
693
+ @context.eval("specific1.COUNT(#{moreThanOne}).rows[1].tempValue.id").must_equal 11
694
+ @context.eval("specific1.COUNT(#{moreThanOne}).rows[2].tempValue.id").must_equal 12
695
+ @context.eval("specific1.COUNT(#{moreThanOne}).rows[3].tempValue.id").must_equal 13
696
+ @context.eval("specific1.COUNT(#{moreThanOne}).rows[4].tempValue.id").must_equal 14
697
+ @context.eval("specific1.COUNT(#{lessThanThree}).rows.length").must_equal 3
698
+ @context.eval("specific1.COUNT(#{lessThanThree}).rows[0].tempValue.id").must_equal 10
699
+ @context.eval("specific1.COUNT(#{lessThanThree}).rows[1].tempValue.id").must_equal 11
700
+ @context.eval("specific1.COUNT(#{lessThanThree}).rows[2].tempValue.id").must_equal 15
701
+ @context.eval("specific1.COUNT(#{exactly1}).rows.length").must_equal 1
702
+ @context.eval("specific1.COUNT(#{exactly1}).rows[0].tempValue.id").must_equal 15
703
+
704
+ @context.eval("specific2.COUNT(#{moreThanOne}).rows.length").must_equal 5
705
+ @context.eval("specific2.COUNT(#{moreThanOne}).rows[0].values[0].id").must_equal 10
706
+ @context.eval("specific2.COUNT(#{moreThanOne}).rows[1].values[0].id").must_equal 11
707
+ @context.eval("specific2.COUNT(#{moreThanOne}).rows[2].values[0].id").must_equal 12
708
+ @context.eval("specific2.COUNT(#{moreThanOne}).rows[3].values[0].id").must_equal 13
709
+ @context.eval("specific2.COUNT(#{moreThanOne}).rows[4].values[0].id").must_equal 14
710
+ @context.eval("specific2.COUNT(#{lessThanThree}).rows.length").must_equal 3
711
+ @context.eval("specific2.COUNT(#{lessThanThree}).rows[0].values[0].id").must_equal 10
712
+ @context.eval("specific2.COUNT(#{lessThanThree}).rows[1].values[0].id").must_equal 11
713
+ @context.eval("specific2.COUNT(#{lessThanThree}).rows[2].values[0].id").must_equal 15
714
+ @context.eval("specific2.COUNT(#{exactly1}).rows.length").must_equal 1
715
+ @context.eval("specific2.COUNT(#{exactly1}).rows[0].values[0].id").must_equal 15
716
+
717
+ @context.eval("specific3.COUNT(#{exactly1}).rows.length").must_equal 1
718
+ @context.eval("specific4.COUNT(#{moreThanOne}).rows.length").must_equal 0
719
+
720
+
721
+ ###
722
+ ##### FIRST
723
+ ###
724
+ @context.eval("specific1.FIRST().rows.length").must_equal 3
725
+ @context.eval("specific1.FIRST().rows[0].tempValue.id").must_equal 11
726
+ @context.eval("specific1.FIRST().rows[1].tempValue.id").must_equal 12
727
+ @context.eval("specific1.FIRST().rows[2].tempValue.id").must_equal 15
728
+
729
+ @context.eval("specific2.FIRST().rows.length").must_equal 3
730
+ @context.eval("specific2.FIRST().rows[0].values[0].id").must_equal 11
731
+ @context.eval("specific2.FIRST().rows[1].values[0].id").must_equal 12
732
+ @context.eval("specific2.FIRST().rows[2].values[0].id").must_equal 15
733
+
734
+ @context.eval("specific3.FIRST().rows.length").must_equal 1
735
+ @context.eval("specific4.FIRST().rows.length").must_equal 0
736
+
737
+ ###
738
+ ##### MOST RECENT
739
+ ###
740
+
741
+ @context.eval("specific1.RECENT().rows.length").must_equal 3
742
+ @context.eval("specific1.RECENT().rows[0].tempValue.id").must_equal 10
743
+ @context.eval("specific1.RECENT().rows[1].tempValue.id").must_equal 13
744
+ @context.eval("specific1.RECENT().rows[2].tempValue.id").must_equal 15
745
+
746
+ @context.eval("specific2.RECENT().rows.length").must_equal 3
747
+ @context.eval("specific2.RECENT().rows[0].values[0].id").must_equal 10
748
+ @context.eval("specific2.RECENT().rows[1].values[0].id").must_equal 13
749
+ @context.eval("specific2.RECENT().rows[2].values[0].id").must_equal 15
750
+
751
+ @context.eval("specific3.RECENT().rows.length").must_equal 1
752
+ @context.eval("specific4.RECENT().rows.length").must_equal 0
753
+
754
+
755
+ end
756
+
757
+ end