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,38 @@
1
+ require_relative '../test_helper'
2
+
3
+ class CodesToJsonTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+
9
+ def test_parsing_from_xml
10
+
11
+ codes_file_path = File.expand_path("../../fixtures/codes/codes.xml", __FILE__)
12
+ # Parse the code systems that are mapped to the OIDs we support
13
+ codes_json = HQMF2JS::Generator::CodesToJson.hash_to_js(HQMF2JS::Generator::CodesToJson.from_xml(codes_file_path))
14
+
15
+ @context = get_js_context("var dictionary = #{codes_json}")
16
+
17
+ @context.eval("dictionary").entries.length.must_equal 18
18
+ @context.eval("dictionary['2.16.840.1.113883.3.464.1.42']").entries.first[0].must_equal "CPT"
19
+ @context.eval("dictionary['2.16.840.1.113883.3.464.1.42']").entries.first[1].length.must_equal 19
20
+
21
+ end
22
+
23
+ def test_parsing_from_xls
24
+
25
+ codes_file_path = File.expand_path("../../fixtures/codes/codes.xls", __FILE__)
26
+ # Parse the code systems that are mapped to the OIDs we support
27
+ codes_json = HQMF2JS::Generator::CodesToJson.hash_to_js(HQMF2JS::Generator::CodesToJson.from_xls(codes_file_path))
28
+
29
+ @context = get_js_context("var dictionary = #{codes_json}")
30
+ @context.eval("dictionary").entries.length.must_equal 12
31
+ @context.eval("dictionary['2.16.840.1.113883.3.464.0001.430']").entries.first[0].must_equal "RxNorm"
32
+ @context.eval("dictionary['2.16.840.1.113883.3.464.0001.430']").entries.first[1].length.must_equal 25
33
+
34
+ end
35
+
36
+
37
+
38
+ end
@@ -0,0 +1,48 @@
1
+ require_relative '../test_helper'
2
+
3
+ class EffectiveDateTest < Test::Unit::TestCase
4
+ def setup
5
+ # Open a path to all of our fixtures
6
+ hqmf_contents = File.open("test/fixtures/NQF59New.xml").read
7
+
8
+ doc = HQMF::Parser.parse(hqmf_contents, HQMF::Parser::HQMF_VERSION_2)
9
+
10
+ # First compile the CoffeeScript that enables our converted HQMF JavaScript
11
+ ctx = Sprockets::Environment.new(File.expand_path("../../..", __FILE__))
12
+ Tilt::CoffeeScriptTemplate.default_bare = true
13
+ ctx.append_path "app/assets/javascripts"
14
+ hqmf_utils = HQMF2JS::Generator::JS.library_functions
15
+
16
+ # Convert the HQMF document included as a fixture into JavaScript
17
+ @converter = HQMF2JS::Generator::JS.new(doc)
18
+ converted_hqmf = "var effective_date = 1277870400; // June 30th 2010
19
+ #{@converter.js_for_data_criteria}
20
+ #{@converter.js_for('IPP')}
21
+ #{@converter.js_for('DENOM')}
22
+ #{@converter.js_for('NUMER')}
23
+ #{@converter.js_for('EXCEP')}
24
+ #{@converter.js_for('DUMMY')}"
25
+
26
+ # Now we can wrap and compile all of our code as one little JavaScript context for all of the tests below
27
+ if RUBY_PLATFORM=='java'
28
+ @context = Rhino::Context.new
29
+ else
30
+ @context = V8::Context.new
31
+ end
32
+ @context.eval("#{hqmf_utils}
33
+ #{converted_hqmf}")
34
+ end
35
+
36
+ def test_override_hqmf_measure_period
37
+ # Measure variables
38
+ assert_equal 2009, @context.eval("MeasurePeriod.low.asDate().getFullYear()")
39
+ assert_equal 5, @context.eval("MeasurePeriod.low.asDate().getMonth()")
40
+ assert_equal 2010, @context.eval("MeasurePeriod.high.asDate().getFullYear()")
41
+ assert_equal 5, @context.eval("MeasurePeriod.high.asDate().getMonth()")
42
+ assert_equal 2009, @context.eval("hqmfjs.MeasurePeriod()[0].asIVL_TS().low.asDate().getFullYear()")
43
+ assert_equal 5, @context.eval("hqmfjs.MeasurePeriod()[0].asIVL_TS().low.asDate().getMonth()")
44
+ assert_equal 2010, @context.eval("hqmfjs.MeasurePeriod()[0].asIVL_TS().high.asDate().getFullYear()")
45
+ assert_equal 5, @context.eval("hqmfjs.MeasurePeriod()[0].asIVL_TS().high.asDate().getMonth()")
46
+ end
47
+
48
+ end
@@ -0,0 +1,108 @@
1
+ require_relative '../test_helper'
2
+
3
+ class HqmfFromJsonJavascriptTest < Test::Unit::TestCase
4
+ def setup
5
+ json_measure = File.open("test/fixtures/json/59New.json").read
6
+ measure_hash = JSON.parse(json_measure)
7
+
8
+ doc = HQMF::Document.from_json(measure_hash)
9
+
10
+ codes_file_path = File.expand_path("../../fixtures/codes/codes.xml", __FILE__)
11
+ # This patient is identified from Cypress as in the denominator and numerator for NQF59
12
+ numerator_patient_json = File.read('test/fixtures/patients/larry_vanderman.json')
13
+
14
+ # First compile the CoffeeScript that enables our converted HQMF JavaScript
15
+ hqmf_utils = compile_coffee_script
16
+
17
+ # Parse the code systems that are mapped to the OIDs we support
18
+ @codes_hash = HQMF2JS::Generator::CodesToJson.from_xml(codes_file_path)
19
+ codes_json = HQMF2JS::Generator::CodesToJson.hash_to_js(@codes_hash)
20
+
21
+ # Convert the HQMF document included as a fixture into JavaScript
22
+ @converter = HQMF2JS::Generator::JS.new(doc)
23
+ converted_hqmf = "#{@converter.js_for_data_criteria}
24
+ #{@converter.js_for('IPP')}
25
+ #{@converter.js_for('DENOM')}
26
+ #{@converter.js_for('NUMER')}
27
+ #{@converter.js_for('EXCEP')}
28
+ #{@converter.js_for('DUMMY')}"
29
+
30
+ initialize_javascript_context(hqmf_utils, codes_json, converted_hqmf)
31
+ end
32
+
33
+ def test_converted_hqmf
34
+ # Unspecified time bounds should be nil
35
+ assert_equal nil, @context.eval("numeratorPatient.encounters()[0].asIVL_TS().low.asDate()")
36
+ assert_equal 2010, @context.eval("numeratorPatient.encounters()[0].asIVL_TS().high.asDate().getFullYear()")
37
+
38
+ # Measure variables
39
+ assert_equal 2011, @context.eval("MeasurePeriod.low.asDate().getFullYear()")
40
+ assert_equal 0, @context.eval("MeasurePeriod.low.asDate().getMonth()")
41
+ assert_equal 2011, @context.eval("MeasurePeriod.high.asDate().getFullYear()")
42
+ assert_equal 11, @context.eval("MeasurePeriod.high.asDate().getMonth()")
43
+ assert_equal 2011, @context.eval("hqmfjs.MeasurePeriod()[0].asIVL_TS().low.asDate().getFullYear()")
44
+ assert_equal 0, @context.eval("hqmfjs.MeasurePeriod()[0].asIVL_TS().low.asDate().getMonth()")
45
+ assert_equal 2011, @context.eval("hqmfjs.MeasurePeriod()[0].asIVL_TS().high.asDate().getFullYear()")
46
+ assert_equal 11, @context.eval("hqmfjs.MeasurePeriod()[0].asIVL_TS().high.asDate().getMonth()")
47
+
48
+ # Age functions - Fixture is 37.1
49
+ assert @context.eval("hqmfjs.ageBetween17and64(numeratorPatient).isTrue()")
50
+ assert @context.eval("hqmfjs.ageBetween30and39(numeratorPatient).isTrue()")
51
+ assert !@context.eval("hqmfjs.ageBetween17and21(numeratorPatient).isTrue()")
52
+ assert !@context.eval("hqmfjs.ageBetween22and29(numeratorPatient).isTrue()")
53
+ assert !@context.eval("hqmfjs.ageBetween40and49(numeratorPatient).isTrue()")
54
+ assert !@context.eval("hqmfjs.ageBetween50and59(numeratorPatient).isTrue()")
55
+ assert !@context.eval("hqmfjs.ageBetween60and64(numeratorPatient).isTrue()")
56
+
57
+ # Birthdate function
58
+ assert_equal 1, @context.eval("hqmfjs.birthdateThirtyYearsBeforeMeasurementPeriod(numeratorPatient)").count
59
+ assert_equal 0, @context.eval("hqmfjs.birthdateFiftyYearsBeforeMeasurementPeriod(numeratorPatient)").count
60
+
61
+ # Gender functions - Fixture is male
62
+ assert @context.eval("hqmfjs.genderMale(numeratorPatient).isTrue()")
63
+ assert !@context.eval("hqmfjs.genderFemale(numeratorPatient).isTrue()")
64
+
65
+ # Be sure the actual mechanic of code lists being returned works correctly - Using HasDiabetes as an example
66
+ results = @context.eval("hqmfjs.HasDiabetes(numeratorPatient)[0]")['json']
67
+ assert_equal 3, results['codes'].count
68
+ assert_equal '250', results['codes']['ICD-9-CM'].first
69
+ assert_equal 1270094400, results['time']
70
+
71
+ # Encounters
72
+ assert_equal 0, @context.eval("hqmfjs.EDorInpatientEncounter(numeratorPatient).length")
73
+ assert_equal 0, @context.eval("hqmfjs.AmbulatoryEncounter(numeratorPatient).length")
74
+
75
+ # Conditions
76
+ assert_equal 1, @context.eval("hqmfjs.HasDiabetes(numeratorPatient).length")
77
+ assert_equal 0, @context.eval("hqmfjs.HasGestationalDiabetes(numeratorPatient).length")
78
+ assert_equal 0, @context.eval("hqmfjs.HasPolycysticOvaries(numeratorPatient).length")
79
+ assert_equal 0, @context.eval("hqmfjs.HasSteroidInducedDiabetes(numeratorPatient).length")
80
+
81
+ # Results
82
+ assert_equal 2, @context.eval("hqmfjs.HbA1C(numeratorPatient).length")
83
+
84
+ # Medications
85
+ assert_equal 1, @context.eval("hqmfjs.DiabetesMedAdministered(numeratorPatient).length")
86
+ assert_equal 1, @context.eval("hqmfjs.DiabetesMedAdministeredFor7Days(numeratorPatient).length")
87
+ assert_equal 0, @context.eval("hqmfjs.DiabetesMedAdministeredFor9Days(numeratorPatient).length")
88
+ assert_equal 0, @context.eval("hqmfjs.DiabetesMedIntended(numeratorPatient).length")
89
+ assert_equal 0, @context.eval("hqmfjs.DiabetesMedSupplied(numeratorPatient).length")
90
+ assert_equal 0, @context.eval("hqmfjs.DiabetesMedOrdered(numeratorPatient).length")
91
+
92
+ # Standard population health query buckets
93
+ assert @context.eval("hqmfjs.IPP(numeratorPatient).isTrue()")
94
+ assert @context.eval("hqmfjs.DENOM(numeratorPatient).isTrue()")
95
+ assert @context.eval("hqmfjs.NUMER(numeratorPatient).isTrue()")
96
+ assert !@context.eval("hqmfjs.EXCEP(numeratorPatient).isTrue()")
97
+
98
+ # COUNTing
99
+ assert @context.eval("hqmfjs.moreThanTwoHbA1CTests(numeratorPatient).isTrue()")
100
+ assert !@context.eval("hqmfjs.moreThanFourHbA1CTests(numeratorPatient).isTrue()")
101
+
102
+ # UNIONing
103
+ assert_equal 1, @context.eval("hqmfjs.anyDiabetes(numeratorPatient).length")
104
+
105
+ # XPRODUCTing
106
+ assert_equal 1, @context.eval("hqmfjs.allDiabetes(numeratorPatient).length")
107
+ end
108
+ end
@@ -0,0 +1,175 @@
1
+ require_relative '../test_helper'
2
+
3
+ class HqmfJavascriptTest < Test::Unit::TestCase
4
+ def setup
5
+ # Open a path to all of our fixtures
6
+ hqmf_contents = File.open("test/fixtures/NQF59New.xml").read
7
+
8
+ doc = HQMF::Parser.parse(hqmf_contents, HQMF::Parser::HQMF_VERSION_2)
9
+
10
+ codes_file_path = File.expand_path("../../fixtures/codes/codes.xml", __FILE__)
11
+ # This patient is identified from Cypress as in the denominator and numerator for NQF59
12
+ numerator_patient_json = File.read('test/fixtures/patients/larry_vanderman.json')
13
+
14
+ # First compile the CoffeeScript that enables our converted HQMF JavaScript
15
+ hqmf_utils = compile_coffee_script
16
+
17
+ # Parse the code systems that are mapped to the OIDs we support
18
+ @codes_hash = HQMF2JS::Generator::CodesToJson.from_xml(codes_file_path)
19
+ codes_json = HQMF2JS::Generator::CodesToJson.hash_to_js(@codes_hash)
20
+
21
+ # Convert the HQMF document included as a fixture into JavaScript
22
+ @converter = HQMF2JS::Generator::JS.new(doc)
23
+ converted_hqmf = "#{@converter.js_for_data_criteria}
24
+ #{@converter.js_for('IPP')}
25
+ #{@converter.js_for('DENOM')}
26
+ #{@converter.js_for('NUMER')}
27
+ #{@converter.js_for('EXCEP')}
28
+ #{@converter.js_for('DUMMY')}"
29
+
30
+ initialize_javascript_context(hqmf_utils, codes_json, converted_hqmf)
31
+ end
32
+
33
+ def test_codes
34
+ # Make sure we're recalling entries correctly
35
+ assert_equal 1, @context.eval('OidDictionary["2.16.840.1.113883.3.464.1.14"]').count
36
+ assert_equal "00110", @context.eval('OidDictionary["2.16.840.1.113883.3.464.1.14"]["HL7"][0]')
37
+
38
+ # OIDs that are matched to multiple code systems should also work correctly
39
+ # The list of supported OIDs will eventually be long, so this won't be an exhaustive test, just want to be sure the functionality is right
40
+ assert_equal 3, @context.eval('OidDictionary["2.16.840.1.113883.3.464.1.72"]').count
41
+ assert_equal 2, @context.eval('OidDictionary["2.16.840.1.113883.3.464.1.72"]["CPT"]').count
42
+ assert_equal 3, @context.eval('OidDictionary["2.16.840.1.113883.3.464.1.72"]["LOINC"]').count
43
+ assert_equal 9, @context.eval('OidDictionary["2.16.840.1.113883.3.464.1.72"]["SNOMED-CT"]').count
44
+ end
45
+
46
+ def test_to_js_method
47
+ value = @converter.to_js(0,@codes_hash)
48
+ local_context = V8::Context.new
49
+ patient_api = File.open('test/fixtures/patient_api.js').read
50
+ hqmf_utils = HQMF2JS::Generator::JS.library_functions
51
+ local_context.eval("#{patient_api}
52
+ #{hqmf_utils}
53
+ #{value}")
54
+
55
+ local_context.eval('typeof hqmfjs != undefined').must_equal true
56
+ local_context.eval('typeof OidDictionary != undefined').must_equal true
57
+ local_context.eval('typeof hqmfjs.IPP != undefined').must_equal true
58
+ local_context.eval('typeof hqmfjs.NUMER != undefined').must_equal true
59
+ local_context.eval('typeof hqmfjs.DENOM != undefined').must_equal true
60
+ end
61
+
62
+ def test_converted_hqmf
63
+ # Unspecified time bounds should be nil
64
+ assert_equal nil, @context.eval("numeratorPatient.encounters()[0].asIVL_TS().low.asDate()")
65
+ assert_equal 2010, @context.eval("numeratorPatient.encounters()[0].asIVL_TS().high.asDate().getFullYear()")
66
+
67
+ # Measure variables
68
+ assert_equal 2011, @context.eval("MeasurePeriod.low.asDate().getFullYear()")
69
+ assert_equal 0, @context.eval("MeasurePeriod.low.asDate().getMonth()")
70
+ assert_equal 2011, @context.eval("MeasurePeriod.high.asDate().getFullYear()")
71
+ assert_equal 11, @context.eval("MeasurePeriod.high.asDate().getMonth()")
72
+ assert_equal 2011, @context.eval("hqmfjs.MeasurePeriod()[0].asIVL_TS().low.asDate().getFullYear()")
73
+ assert_equal 0, @context.eval("hqmfjs.MeasurePeriod()[0].asIVL_TS().low.asDate().getMonth()")
74
+ assert_equal 2011, @context.eval("hqmfjs.MeasurePeriod()[0].asIVL_TS().high.asDate().getFullYear()")
75
+ assert_equal 11, @context.eval("hqmfjs.MeasurePeriod()[0].asIVL_TS().high.asDate().getMonth()")
76
+
77
+ # Age functions - Fixture is 37.1
78
+ assert @context.eval("hqmfjs.ageBetween17and64(numeratorPatient).isTrue()")
79
+ assert @context.eval("hqmfjs.ageBetween30and39(numeratorPatient).isTrue()")
80
+ assert !@context.eval("hqmfjs.ageBetween17and21(numeratorPatient).isTrue()")
81
+ assert !@context.eval("hqmfjs.ageBetween22and29(numeratorPatient).isTrue()")
82
+ assert !@context.eval("hqmfjs.ageBetween40and49(numeratorPatient).isTrue()")
83
+ assert !@context.eval("hqmfjs.ageBetween50and59(numeratorPatient).isTrue()")
84
+ assert !@context.eval("hqmfjs.ageBetween60and64(numeratorPatient).isTrue()")
85
+
86
+ # Birthdate function
87
+ assert_equal 1, @context.eval("hqmfjs.birthdateThirtyYearsBeforeMeasurementPeriod(numeratorPatient)").count
88
+ assert_equal 0, @context.eval("hqmfjs.birthdateFiftyYearsBeforeMeasurementPeriod(numeratorPatient)").count
89
+
90
+ # Gender functions - Fixture is male
91
+ assert @context.eval("hqmfjs.genderMale(numeratorPatient).isTrue()")
92
+ assert !@context.eval("hqmfjs.genderFemale(numeratorPatient).isTrue()")
93
+
94
+ # Be sure the actual mechanic of code lists being returned works correctly - Using HasDiabetes as an example
95
+ results = @context.eval("hqmfjs.HasDiabetes(numeratorPatient)[0]")['json']
96
+ assert_equal 3, results['codes'].count
97
+ assert_equal '250', results['codes']['ICD-9-CM'].first
98
+ assert_equal 1270094400, results['time']
99
+
100
+ # Encounters
101
+ assert_equal 0, @context.eval("hqmfjs.EDorInpatientEncounter(numeratorPatient).length")
102
+ assert_equal 0, @context.eval("hqmfjs.AmbulatoryEncounter(numeratorPatient).length")
103
+
104
+ # Conditions
105
+ assert_equal 1, @context.eval("hqmfjs.HasDiabetes(numeratorPatient).length")
106
+ assert_equal 0, @context.eval("hqmfjs.HasGestationalDiabetes(numeratorPatient).length")
107
+ assert_equal 0, @context.eval("hqmfjs.HasPolycysticOvaries(numeratorPatient).length")
108
+ assert_equal 0, @context.eval("hqmfjs.HasSteroidInducedDiabetes(numeratorPatient).length")
109
+
110
+ # Results
111
+ assert_equal 2, @context.eval("hqmfjs.HbA1C(numeratorPatient).length")
112
+
113
+ # Medications
114
+ assert_equal 1, @context.eval("hqmfjs.DiabetesMedAdministered(numeratorPatient).length")
115
+ assert_equal 0, @context.eval("hqmfjs.DiabetesMedIntended(numeratorPatient).length")
116
+ assert_equal 0, @context.eval("hqmfjs.DiabetesMedSupplied(numeratorPatient).length")
117
+ assert_equal 0, @context.eval("hqmfjs.DiabetesMedOrdered(numeratorPatient).length")
118
+
119
+ # Standard population health query buckets
120
+ assert @context.eval("hqmfjs.IPP(numeratorPatient).isTrue()")
121
+ assert @context.eval("hqmfjs.DENOM(numeratorPatient).isTrue()")
122
+ assert @context.eval("hqmfjs.NUMER(numeratorPatient).isTrue()")
123
+ assert !@context.eval("hqmfjs.EXCEP(numeratorPatient).isTrue()")
124
+
125
+ # COUNTing
126
+ assert @context.eval("hqmfjs.moreThanTwoHbA1CTests(numeratorPatient).isTrue()")
127
+ assert !@context.eval("hqmfjs.moreThanFourHbA1CTests(numeratorPatient).isTrue()")
128
+
129
+ # UNIONing
130
+ assert_equal 1, @context.eval("hqmfjs.anyDiabetes(numeratorPatient).length")
131
+
132
+ # XPRODUCTing
133
+ assert_equal 1, @context.eval("hqmfjs.allDiabetes(numeratorPatient).length")
134
+ end
135
+
136
+ def test_converted_utils
137
+ # Filter events by value - HbA1C as an example
138
+ events = 'numeratorPatient.results().match(getCodes("2.16.840.1.113883.3.464.1.72"))'
139
+ assert_equal 2, @context.eval("filterEventsByValue(#{events}, new IVL_PQ(new PQ(9, '%'), null))").count
140
+ assert_equal 0, @context.eval("filterEventsByValue(#{events}, new IVL_PQ(new PQ(10, '%'), null))").count
141
+
142
+ # getCode
143
+ assert_equal 1, @context.eval('getCodes("2.16.840.1.113883.3.464.1.14")').count
144
+ assert_equal "00110", @context.eval('getCodes("2.16.840.1.113883.3.464.1.14")["HL7"][0]')
145
+ end
146
+
147
+ def test_map_reduce_generation
148
+ hqmf_contents = File.open("test/fixtures/NQF59New.xml").read
149
+ doc = HQMF::Parser.parse(hqmf_contents, HQMF::Parser::HQMF_VERSION_2)
150
+
151
+ map_reduce = HQMF2JS::Converter.generate_map_reduce(doc)
152
+
153
+ # Extremely loose testing here. Just want to be sure for now that we're getting results of some kind.
154
+ # We'll test for validity over on the hQuery Gateway side of things.
155
+ assert map_reduce[:map].include? 'map'
156
+ assert map_reduce[:reduce].include? 'reduce'
157
+ # Check functions to include actual HQMF converted function, HQMF utility function, and OID dictionary
158
+ assert map_reduce[:functions].include? 'IPP'
159
+ assert map_reduce[:functions].include? 'atLeastOneTrue'
160
+ assert map_reduce[:functions].include? 'OidDictionary'
161
+ end
162
+
163
+
164
+ def test_missing_id
165
+
166
+ context = HQMF2JS::Generator::ErbContext.new({})
167
+ criteria = HQMF::DataCriteria.new(nil,nil,nil,nil,nil,nil,nil,'patient_characteristic',nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil)
168
+
169
+ exception = assert_raise RuntimeError do
170
+ n = context.js_name(criteria)
171
+ end
172
+ assert exception.message.match(/^No identifier for .*/)
173
+ end
174
+
175
+ end