fhir_scorecard 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,52 @@
1
+ require_relative '../test_helper'
2
+
3
+ class BasicTest < Minitest::Test
4
+
5
+ # turn off the ridiculous warnings
6
+ $VERBOSE=nil
7
+
8
+ def test_bundle
9
+ bundle = FHIR::Bundle.new
10
+ scorecard = FHIR::Scorecard.new
11
+ report = scorecard.score(bundle.to_json)
12
+
13
+ assert (report[:points]), 'Scorecard should report points.'
14
+ assert (report[:bundle]), 'Scorecard should report Bundle section.'
15
+ assert (report[:patient]), 'Scorecard should report Patient section.'
16
+ assert (report[:points]==10), 'Scorecard points incorrect.'
17
+ assert (report[:bundle][:points]), 'Bundle section should report points.'
18
+ assert (report[:bundle][:points]==10), 'Bundle section points incorrect.'
19
+ assert (report[:patient][:points]), 'Patient section should report points.'
20
+ assert (report[:patient][:points]==0), 'Patient section points incorrect.'
21
+ end
22
+
23
+ def test_not_bundle
24
+ basic = FHIR::Basic.new
25
+ scorecard = FHIR::Scorecard.new
26
+ report = scorecard.score(basic.to_json)
27
+
28
+ assert (report[:points]), 'Scorecard should report points.'
29
+ assert (report[:bundle]), 'Scorecard should report Bundle section.'
30
+ assert (report[:points]==0), 'Scorecard points incorrect.'
31
+ assert (report[:bundle][:points]), 'Bundle section should report points.'
32
+ assert (report[:bundle][:points]==0), 'Bundle section points incorrect.'
33
+ end
34
+
35
+ def test_bundle_with_patient
36
+ patient = FHIR::Patient.new
37
+ bundle = FHIR::Bundle.new({'entry'=>[ {} ]})
38
+ bundle.entry.first.resource = patient
39
+ scorecard = FHIR::Scorecard.new
40
+ report = scorecard.score(bundle.to_json)
41
+
42
+ assert (report[:points]), 'Scorecard should report points.'
43
+ assert (report[:bundle]), 'Scorecard should report Bundle section.'
44
+ assert (report[:patient]), 'Scorecard should report Patient section.'
45
+ assert (report[:points]==20), 'Scorecard points incorrect.'
46
+ assert (report[:bundle][:points]), 'Bundle section should report points.'
47
+ assert (report[:bundle][:points]==10), 'Bundle section points incorrect.'
48
+ assert (report[:patient][:points]), 'Patient section should report points.'
49
+ assert (report[:patient][:points]==10), 'Patient section points incorrect.'
50
+ end
51
+
52
+ end
@@ -0,0 +1,169 @@
1
+ require_relative '../test_helper'
2
+
3
+ class CodesExistTest < Minitest::Test
4
+
5
+ # turn off the ridiculous warnings
6
+ $VERBOSE=nil
7
+
8
+ def test_codes_exist_none
9
+ patient = FHIR::Patient.new
10
+ bundle = FHIR::Bundle.new({ 'entry'=>[ { 'resource' => patient.to_hash } ] })
11
+ scorecard = FHIR::Scorecard.new
12
+ report = scorecard.score(bundle.to_json)
13
+ assert (report[:points]), 'Scorecard should report points.'
14
+ assert (report[:bundle]), 'Scorecard should report Bundle section.'
15
+ assert (report[:patient]), 'Scorecard should report Patient section.'
16
+ assert (report[:codes_exist]), 'Scorecard should report Codes Exist section.'
17
+ assert (report[:codes_exist][:points]==0), "Codes Exist section points incorrect (#{report[:codes_exist][:points]}!=0)."
18
+ end
19
+
20
+ def test_codes_exist_1of3
21
+ patient = FHIR::Patient.new({ 'gender'=>'male' })
22
+ bundle = FHIR::Bundle.new({ 'entry'=>[ { 'resource' => patient.to_hash } ] })
23
+ scorecard = FHIR::Scorecard.new
24
+ report = scorecard.score(bundle.to_json)
25
+ assert (report[:points]), 'Scorecard should report points.'
26
+ assert (report[:bundle]), 'Scorecard should report Bundle section.'
27
+ assert (report[:patient]), 'Scorecard should report Patient section.'
28
+ assert (report[:codes_exist]), 'Scorecard should report Codes Exist section.'
29
+ assert (report[:codes_exist][:points]==3), "Codes Exist section points incorrect (#{report[:codes_exist][:points]}!=3)."
30
+ end
31
+
32
+ def test_codes_exist_1of3_wrongtype
33
+ patient = FHIR::Patient.new({ 'gender'=>0 })
34
+ bundle = FHIR::Bundle.new({ 'entry'=>[ { 'resource' => patient.to_hash } ] })
35
+ scorecard = FHIR::Scorecard.new
36
+ report = scorecard.score(bundle.to_json)
37
+ assert (report[:points]), 'Scorecard should report points.'
38
+ assert (report[:bundle]), 'Scorecard should report Bundle section.'
39
+ assert (report[:patient]), 'Scorecard should report Patient section.'
40
+ assert (report[:codes_exist]), 'Scorecard should report Codes Exist section.'
41
+ assert (report[:codes_exist][:points]==0), "Codes Exist section points incorrect (#{report[:codes_exist][:points]}!=0)."
42
+ end
43
+
44
+ def test_codes_exist_2of3
45
+ patient = FHIR::Patient.new({
46
+ 'gender'=>'male',
47
+ 'maritalStatus'=> {
48
+ 'coding'=>[ {'code'=>'S','system'=>'http://hl7.org/fhir/v3/MaritalStatus'} ]
49
+ }
50
+ })
51
+ bundle = FHIR::Bundle.new({ 'entry'=>[ { 'resource' => patient.to_hash } ] })
52
+ scorecard = FHIR::Scorecard.new
53
+ report = scorecard.score(bundle.to_json)
54
+ assert (report[:points]), 'Scorecard should report points.'
55
+ assert (report[:bundle]), 'Scorecard should report Bundle section.'
56
+ assert (report[:patient]), 'Scorecard should report Patient section.'
57
+ assert (report[:codes_exist]), 'Scorecard should report Codes Exist section.'
58
+ assert (report[:codes_exist][:points]==6), "Codes Exist section points incorrect (#{report[:codes_exist][:points]}!=6)."
59
+ end
60
+
61
+ def test_codes_exist_2of3_textonly
62
+ patient = FHIR::Patient.new({
63
+ 'gender'=>'male',
64
+ 'maritalStatus'=> {
65
+ 'text'=>'Single'
66
+ }
67
+ })
68
+ bundle = FHIR::Bundle.new({ 'entry'=>[ { 'resource' => patient.to_hash } ] })
69
+ scorecard = FHIR::Scorecard.new
70
+ report = scorecard.score(bundle.to_json)
71
+ assert (report[:points]), 'Scorecard should report points.'
72
+ assert (report[:bundle]), 'Scorecard should report Bundle section.'
73
+ assert (report[:patient]), 'Scorecard should report Patient section.'
74
+ assert (report[:codes_exist]), 'Scorecard should report Codes Exist section.'
75
+ assert (report[:codes_exist][:points]==3), "Codes Exist section points incorrect (#{report[:codes_exist][:points]}!=3)."
76
+ end
77
+
78
+ def test_codes_exist_3of3
79
+ patient = FHIR::Patient.new({
80
+ 'language'=>'en-US',
81
+ 'gender'=>'male',
82
+ 'maritalStatus'=> {
83
+ 'coding'=>[ {'code'=>'S','system'=>'http://hl7.org/fhir/v3/MaritalStatus'} ]
84
+ }
85
+ })
86
+ bundle = FHIR::Bundle.new({ 'entry'=>[ { 'resource' => patient.to_hash } ] })
87
+ scorecard = FHIR::Scorecard.new
88
+ report = scorecard.score(bundle.to_json)
89
+ assert (report[:points]), 'Scorecard should report points.'
90
+ assert (report[:bundle]), 'Scorecard should report Bundle section.'
91
+ assert (report[:patient]), 'Scorecard should report Patient section.'
92
+ assert (report[:codes_exist]), 'Scorecard should report Codes Exist section.'
93
+ assert (report[:codes_exist][:points]==10), "Codes Exist section points incorrect (#{report[:codes_exist][:points]}!=10)."
94
+ end
95
+
96
+ def test_codes_exist_with_backbone_elements
97
+ patient = FHIR::Patient.new({
98
+ 'language'=>'en-US',
99
+ 'gender'=>'male',
100
+ 'maritalStatus'=> {
101
+ 'coding'=>[ {'code'=>'S','system'=>'http://hl7.org/fhir/v3/MaritalStatus'} ]
102
+ },
103
+ 'communication'=> [
104
+ { 'language'=> {
105
+ 'coding'=>[ {'code'=>'en-US','system'=>'urn:ietf:bcp:47'} ]
106
+ },
107
+ 'preferred'=> true },
108
+ { 'language'=> {
109
+ 'coding'=>[ {'code'=>'es','system'=>'urn:ietf:bcp:47'} ]
110
+ }
111
+ }
112
+ ]
113
+ })
114
+ bundle = FHIR::Bundle.new({ 'entry'=>[ { 'resource' => patient.to_hash } ] })
115
+ scorecard = FHIR::Scorecard.new
116
+ report = scorecard.score(bundle.to_json)
117
+ assert (report[:points]), 'Scorecard should report points.'
118
+ assert (report[:bundle]), 'Scorecard should report Bundle section.'
119
+ assert (report[:patient]), 'Scorecard should report Patient section.'
120
+ assert (report[:codes_exist]), 'Scorecard should report Codes Exist section.'
121
+ assert (report[:codes_exist][:points]==10), "Codes Exist section points incorrect (#{report[:codes_exist][:points]}!=10)."
122
+ end
123
+
124
+ def test_codes_exist_with_backbone_elements_and_array
125
+ patient = FHIR::Patient.new({
126
+ 'language'=>'en-US',
127
+ 'gender'=>'male',
128
+ 'maritalStatus'=> {
129
+ 'coding'=>[ {'code'=>'S','system'=>'http://hl7.org/fhir/v3/MaritalStatus'} ]
130
+ },
131
+ 'contact'=> [
132
+ { 'gender'=>'male',
133
+ 'relationship'=> [
134
+ { 'coding'=>[ {'code'=>'c','system'=>'http://hl7.org/fhir/v2/0131'} ] }
135
+ ]
136
+ },{ 'gender'=>'female',
137
+ 'relationship'=> [
138
+ { 'coding'=>[ {'code'=>'n','system'=>'http://hl7.org/fhir/v2/0131'} ] }
139
+ ]
140
+ }
141
+ ]
142
+ })
143
+ bundle = FHIR::Bundle.new({ 'entry'=>[ { 'resource' => patient.to_hash } ] })
144
+ scorecard = FHIR::Scorecard.new
145
+ report = scorecard.score(bundle.to_json)
146
+ assert (report[:points]), 'Scorecard should report points.'
147
+ assert (report[:bundle]), 'Scorecard should report Bundle section.'
148
+ assert (report[:patient]), 'Scorecard should report Patient section.'
149
+ assert (report[:codes_exist]), 'Scorecard should report Codes Exist section.'
150
+ assert (report[:codes_exist][:points]==10), "Codes Exist section points incorrect (#{report[:codes_exist][:points]}!=10)."
151
+ end
152
+
153
+ def test_codes_exist_with_coding
154
+ encounter = FHIR::Encounter.new({
155
+ 'language'=>'en-US',
156
+ 'status'=>'planned',
157
+ 'class'=>{'code'=>'AMB','system'=>'http://hl7.org/fhir/v3/ActCode'}
158
+ })
159
+ bundle = FHIR::Bundle.new({ 'entry'=>[ { 'resource' => encounter.to_hash } ] })
160
+ scorecard = FHIR::Scorecard.new
161
+ report = scorecard.score(bundle.to_json)
162
+ assert (report[:points]), 'Scorecard should report points.'
163
+ assert (report[:bundle]), 'Scorecard should report Bundle section.'
164
+ assert (report[:patient]), 'Scorecard should report Patient section.'
165
+ assert (report[:codes_exist]), 'Scorecard should report Codes Exist section.'
166
+ assert (report[:codes_exist][:points]==5), "Codes Exist section points incorrect (#{report[:codes_exist][:points]}!=5)."
167
+ end
168
+
169
+ end
@@ -0,0 +1,91 @@
1
+ require_relative '../test_helper'
2
+
3
+ class TerminologyTest < Minitest::Test
4
+
5
+ # turn off the ridiculous warnings
6
+ $VERBOSE=nil
7
+
8
+ @@term_root = File.expand_path '../../terminology',File.dirname(File.absolute_path(__FILE__))
9
+
10
+ def setup
11
+ loinc_file = File.join(@@term_root,'scorecard_loinc_2000.txt')
12
+ umls_file = File.join(@@term_root,'scorecard_umls.txt')
13
+ snomed_file = File.join(@@term_root,'scorecard_snomed_core.txt')
14
+ FileUtils.mv(loinc_file, "#{loinc_file}.bak", :force=>true)
15
+ FileUtils.mv(umls_file, "#{umls_file}.bak", :force=>true)
16
+ FileUtils.mv(snomed_file, "#{snomed_file}.bak", :force=>true)
17
+ file = File.open(loinc_file,'w:UTF-8')
18
+ file.write('foo|Foo Description|mg')
19
+ file.close
20
+ file = File.open(umls_file,'w:UTF-8')
21
+ file.write("LOINC|foo|Foo Description\n")
22
+ file.write("RXNORM|placebo|Placebo Description\n")
23
+ file.write("LOINC|bar|Bar Description\n")
24
+ file.close
25
+ file = File.open(snomed_file,'w:UTF-8')
26
+ file.write("baz|Baz Description\n")
27
+ file.close
28
+ end
29
+
30
+ def teardown
31
+ loinc_file = File.join(@@term_root,'scorecard_loinc_2000.txt')
32
+ umls_file = File.join(@@term_root,'scorecard_umls.txt')
33
+ snomed_file = File.join(@@term_root,'scorecard_snomed_core.txt')
34
+ FileUtils.rm(loinc_file, :force=>true)
35
+ FileUtils.rm(umls_file, :force=>true)
36
+ FileUtils.rm(snomed_file, :force=>true)
37
+ FileUtils.mv("#{loinc_file}.bak",loinc_file, :force=>true)
38
+ FileUtils.mv("#{umls_file}.bak",umls_file, :force=>true)
39
+ FileUtils.mv("#{snomed_file}.bak",snomed_file, :force=>true)
40
+ end
41
+
42
+ def test_get_description_foo
43
+ description = FHIR::Terminology.get_description('LOINC','foo')
44
+ assert description=='Foo Description', "Incorrect description: #{description}"
45
+ end
46
+
47
+ def test_get_description_placebo
48
+ description = FHIR::Terminology.get_description('RXNORM','placebo')
49
+ assert description=='Placebo Description', "Incorrect description: #{description}"
50
+ end
51
+
52
+ def test_get_description_bar
53
+ description = FHIR::Terminology.get_description('LOINC','bar')
54
+ assert description=='Bar Description', "Incorrect description: #{description}"
55
+ end
56
+
57
+ def test_get_description_negative
58
+ description = FHIR::Terminology.get_description('LOINC','baz')
59
+ assert description.nil?, 'Expected nil description.'
60
+ end
61
+
62
+ def test_get_description_negative_unknown_system
63
+ description = FHIR::Terminology.get_description('FAKE','fake')
64
+ assert description.nil?, 'Expected nil description.'
65
+ end
66
+
67
+ def test_is_top_lab_code_true
68
+ assert FHIR::Terminology.is_top_lab_code?('foo'), 'Top lab code not found.'
69
+ end
70
+
71
+ def test_is_top_lab_code_false
72
+ assert !FHIR::Terminology.is_top_lab_code?('bar'), 'Lab code should not have been found.'
73
+ end
74
+
75
+ def test_lab_units_foo
76
+ assert FHIR::Terminology.lab_units('foo')=='mg', 'Incorrect units returned.'
77
+ end
78
+
79
+ def test_lab_units_bar
80
+ assert FHIR::Terminology.lab_units('bar').nil?, 'Units were unexpectedly returned (should be nil).'
81
+ end
82
+
83
+ def test_lab_description_foo
84
+ assert FHIR::Terminology.lab_description('foo')=='Foo Description', 'Incorrect description returned.'
85
+ end
86
+
87
+ def test_lab_description_bar
88
+ assert FHIR::Terminology.lab_description('bar').nil?, 'Description was unexpectedly returned (should be nil).'
89
+ end
90
+
91
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fhir_scorecard
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Jason Walonoski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fhir_models
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A Gem for scoring FHIR Patient Records (as Bundles)
28
+ email: jwalonoski@mitre.org
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".gitignore"
34
+ - ".simplecov"
35
+ - ".travis.yml"
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - LICENSE
39
+ - README.md
40
+ - Rakefile
41
+ - fhir_scorecard.gemspec
42
+ - lib/fhir_scorecard.rb
43
+ - lib/rubrics.rb
44
+ - lib/rubrics/codes_exist.rb
45
+ - lib/rubrics/codes_umls.rb
46
+ - lib/rubrics/codes_umls_preferred_descriptions.rb
47
+ - lib/rubrics/completeness.rb
48
+ - lib/rubrics/cvx_immunizations.rb
49
+ - lib/rubrics/cvx_meds.rb
50
+ - lib/rubrics/datetimes_iso8601.rb
51
+ - lib/rubrics/labs_loinc.rb
52
+ - lib/rubrics/quantities_ucum.rb
53
+ - lib/rubrics/references_resolve.rb
54
+ - lib/rubrics/rxnorm_meds.rb
55
+ - lib/rubrics/smoking_status.rb
56
+ - lib/rubrics/snomed_conditions.rb
57
+ - lib/rubrics/vital_signs.rb
58
+ - lib/scorecard.rb
59
+ - lib/tasks/tasks.rake
60
+ - lib/terminology.rb
61
+ - logs/.keep
62
+ - terminology/.keep
63
+ - test/test_helper.rb
64
+ - test/unit/basic_test.rb
65
+ - test/unit/codes_exist_test.rb
66
+ - test/unit/terminology_test.rb
67
+ homepage: https://github.com/fhir-crucible/fhir_scorecard
68
+ licenses: []
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.6.7
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Scorecard for a FHIR Patient Record (as Bundle)
90
+ test_files: []