conceptql 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +53 -1
  4. data/Guardfile +52 -24
  5. data/conceptql.gemspec +5 -3
  6. data/doc/spec.md +2 -2
  7. data/lib/conceptql/behaviors/debuggable.rb +70 -0
  8. data/lib/conceptql/behaviors/dottable.rb +28 -14
  9. data/lib/conceptql/behaviors/metadatable.rb +97 -0
  10. data/lib/conceptql/behaviors/preppable.rb +20 -0
  11. data/lib/conceptql/cli.rb +31 -5
  12. data/lib/conceptql/converter.rb +65 -0
  13. data/lib/conceptql/debugger.rb +48 -0
  14. data/lib/conceptql/graph.rb +14 -13
  15. data/lib/conceptql/graph_nodifier.rb +49 -17
  16. data/lib/conceptql/nodifier.rb +31 -6
  17. data/lib/conceptql/operators/after.rb +25 -0
  18. data/lib/conceptql/operators/any_overlap.rb +15 -0
  19. data/lib/conceptql/operators/before.rb +21 -0
  20. data/lib/conceptql/{nodes/binary_operator_node.rb → operators/binary_operator_operator.rb} +12 -8
  21. data/lib/conceptql/{nodes/casting_node.rb → operators/casting_operator.rb} +8 -7
  22. data/lib/conceptql/{nodes → operators}/complement.rb +14 -11
  23. data/lib/conceptql/operators/concept.rb +70 -0
  24. data/lib/conceptql/{nodes → operators}/condition_type.rb +13 -5
  25. data/lib/conceptql/operators/contains.rb +17 -0
  26. data/lib/conceptql/operators/count.rb +26 -0
  27. data/lib/conceptql/operators/cpt.rb +25 -0
  28. data/lib/conceptql/{nodes → operators}/date_range.rb +11 -6
  29. data/lib/conceptql/operators/death.rb +23 -0
  30. data/lib/conceptql/operators/drug_type_concept.rb +21 -0
  31. data/lib/conceptql/{nodes → operators}/during.rb +9 -3
  32. data/lib/conceptql/operators/equal.rb +13 -0
  33. data/lib/conceptql/operators/except.rb +28 -0
  34. data/lib/conceptql/operators/filter.rb +21 -0
  35. data/lib/conceptql/{nodes → operators}/first.rb +7 -5
  36. data/lib/conceptql/{nodes → operators}/from.rb +2 -2
  37. data/lib/conceptql/operators/from_seer_visits.rb +23 -0
  38. data/lib/conceptql/{nodes → operators}/gender.rb +6 -6
  39. data/lib/conceptql/operators/hcpcs.rb +25 -0
  40. data/lib/conceptql/operators/icd10.rb +28 -0
  41. data/lib/conceptql/operators/icd9.rb +28 -0
  42. data/lib/conceptql/operators/icd9_procedure.rb +25 -0
  43. data/lib/conceptql/{nodes → operators}/intersect.rb +7 -3
  44. data/lib/conceptql/{nodes → operators}/last.rb +7 -5
  45. data/lib/conceptql/operators/loinc.rb +25 -0
  46. data/lib/conceptql/operators/medcode.rb +28 -0
  47. data/lib/conceptql/operators/medcode_procedure.rb +27 -0
  48. data/lib/conceptql/operators/ndc.rb +29 -0
  49. data/lib/conceptql/operators/numeric.rb +54 -0
  50. data/lib/conceptql/operators/observation_by_enttype.rb +29 -0
  51. data/lib/conceptql/operators/observation_period.rb +30 -0
  52. data/lib/conceptql/operators/occurrence.rb +70 -0
  53. data/lib/conceptql/operators/one_in_two_out.rb +62 -0
  54. data/lib/conceptql/{nodes/node.rb → operators/operator.rb} +84 -52
  55. data/lib/conceptql/operators/overlapped_by.rb +23 -0
  56. data/lib/conceptql/operators/overlaps.rb +19 -0
  57. data/lib/conceptql/operators/pass_thru.rb +11 -0
  58. data/lib/conceptql/{nodes → operators}/person.rb +8 -4
  59. data/lib/conceptql/operators/person_filter.rb +13 -0
  60. data/lib/conceptql/{nodes → operators}/place_of_service_code.rb +7 -7
  61. data/lib/conceptql/operators/procedure_occurrence.rb +25 -0
  62. data/lib/conceptql/operators/prodcode.rb +29 -0
  63. data/lib/conceptql/{nodes → operators}/race.rb +7 -7
  64. data/lib/conceptql/operators/recall.rb +38 -0
  65. data/lib/conceptql/operators/rxnorm.rb +24 -0
  66. data/lib/conceptql/operators/snomed.rb +24 -0
  67. data/lib/conceptql/operators/snomed_condition.rb +26 -0
  68. data/lib/conceptql/{nodes/source_vocabulary_node.rb → operators/source_vocabulary_operator.rb} +7 -4
  69. data/lib/conceptql/{nodes/standard_vocabulary_node.rb → operators/standard_vocabulary_operator.rb} +6 -4
  70. data/lib/conceptql/{nodes → operators}/started_by.rb +9 -3
  71. data/lib/conceptql/{nodes → operators}/sum.rb +9 -4
  72. data/lib/conceptql/{nodes/temporal_node.rb → operators/temporal_operator.rb} +7 -4
  73. data/lib/conceptql/{nodes → operators}/time_window.rb +19 -7
  74. data/lib/conceptql/operators/to_seer_visits.rb +24 -0
  75. data/lib/conceptql/operators/trim_date_end.rb +55 -0
  76. data/lib/conceptql/operators/trim_date_start.rb +56 -0
  77. data/lib/conceptql/{nodes → operators}/union.rb +6 -2
  78. data/lib/conceptql/operators/visit.rb +15 -0
  79. data/lib/conceptql/{nodes → operators}/visit_occurrence.rb +7 -3
  80. data/lib/conceptql/query.rb +19 -17
  81. data/lib/conceptql/scope.rb +69 -0
  82. data/lib/conceptql/tree.rb +33 -18
  83. data/lib/conceptql/utils/temp_table.rb +72 -0
  84. data/lib/conceptql/version.rb +1 -1
  85. data/spec/conceptql/behaviors/dottable_spec.rb +39 -51
  86. data/spec/conceptql/converter_spec.rb +51 -0
  87. data/spec/conceptql/date_adjuster_spec.rb +15 -15
  88. data/spec/conceptql/operators/after_spec.rb +16 -0
  89. data/spec/conceptql/operators/before_spec.rb +16 -0
  90. data/spec/conceptql/{nodes/casting_node_spec.rb → operators/casting_operator_spec.rb} +16 -20
  91. data/spec/conceptql/operators/complement_spec.rb +15 -0
  92. data/spec/conceptql/operators/concept_spec.rb +40 -0
  93. data/spec/conceptql/{nodes → operators}/condition_type_spec.rb +39 -24
  94. data/spec/conceptql/operators/contains_spec.rb +19 -0
  95. data/spec/conceptql/operators/cpt_spec.rb +29 -0
  96. data/spec/conceptql/operators/date_range_spec.rb +33 -0
  97. data/spec/conceptql/operators/death_spec.rb +10 -0
  98. data/spec/conceptql/operators/during_spec.rb +30 -0
  99. data/spec/conceptql/operators/except_spec.rb +15 -0
  100. data/spec/conceptql/operators/first_spec.rb +35 -0
  101. data/spec/conceptql/operators/from_spec.rb +13 -0
  102. data/spec/conceptql/operators/gender_spec.rb +27 -0
  103. data/spec/conceptql/operators/hcpcs_spec.rb +29 -0
  104. data/spec/conceptql/operators/icd10_spec.rb +34 -0
  105. data/spec/conceptql/operators/icd9_procedure_spec.rb +29 -0
  106. data/spec/conceptql/operators/icd9_spec.rb +34 -0
  107. data/spec/conceptql/operators/intersect_spec.rb +28 -0
  108. data/spec/conceptql/operators/last_spec.rb +36 -0
  109. data/spec/conceptql/operators/loinc_spec.rb +29 -0
  110. data/spec/conceptql/operators/medcode_procedure_spec.rb +34 -0
  111. data/spec/conceptql/operators/medcode_spec.rb +34 -0
  112. data/spec/conceptql/operators/observation_period_spec.rb +10 -0
  113. data/spec/conceptql/operators/occurrence_spec.rb +87 -0
  114. data/spec/conceptql/operators/overlapped_by_spec.rb +32 -0
  115. data/spec/conceptql/operators/overlaps_spec.rb +21 -0
  116. data/spec/conceptql/operators/person_filter_spec.rb +15 -0
  117. data/spec/conceptql/operators/person_spec.rb +10 -0
  118. data/spec/conceptql/{nodes → operators}/place_of_service_code_spec.rb +6 -8
  119. data/spec/conceptql/operators/procedure_occurrence_spec.rb +10 -0
  120. data/spec/conceptql/operators/prodcode_spec.rb +35 -0
  121. data/spec/conceptql/operators/query_double.rb +20 -0
  122. data/spec/conceptql/operators/query_double_spec.rb +7 -0
  123. data/spec/conceptql/operators/race_spec.rb +21 -0
  124. data/spec/conceptql/operators/rxnorm_spec.rb +29 -0
  125. data/spec/conceptql/operators/snomed_spec.rb +29 -0
  126. data/spec/conceptql/operators/source_vocabulary_operator_spec.rb +35 -0
  127. data/spec/conceptql/operators/standard_vocabulary_operator_spec.rb +35 -0
  128. data/spec/conceptql/operators/started_by_spec.rb +22 -0
  129. data/spec/conceptql/{nodes/temporal_node_spec.rb → operators/temporal_operator_spec.rb} +11 -17
  130. data/spec/conceptql/operators/time_window_spec.rb +77 -0
  131. data/spec/conceptql/operators/union_spec.rb +21 -0
  132. data/spec/conceptql/operators/visit_occurrence_spec.rb +10 -0
  133. data/spec/conceptql/query_spec.rb +10 -9
  134. data/spec/conceptql/tree_spec.rb +24 -28
  135. data/spec/doubles/stream_for_casting_double.rb +1 -1
  136. data/spec/doubles/stream_for_occurrence_double.rb +1 -1
  137. data/spec/doubles/stream_for_temporal_double.rb +1 -1
  138. data/spec/spec_helper.rb +74 -58
  139. metadata +202 -133
  140. data/lib/conceptql/nodes/after.rb +0 -12
  141. data/lib/conceptql/nodes/before.rb +0 -11
  142. data/lib/conceptql/nodes/concept.rb +0 -38
  143. data/lib/conceptql/nodes/count.rb +0 -23
  144. data/lib/conceptql/nodes/cpt.rb +0 -20
  145. data/lib/conceptql/nodes/death.rb +0 -19
  146. data/lib/conceptql/nodes/define.rb +0 -96
  147. data/lib/conceptql/nodes/drug_type_concept.rb +0 -18
  148. data/lib/conceptql/nodes/equal.rb +0 -11
  149. data/lib/conceptql/nodes/except.rb +0 -11
  150. data/lib/conceptql/nodes/hcpcs.rb +0 -20
  151. data/lib/conceptql/nodes/icd10.rb +0 -23
  152. data/lib/conceptql/nodes/icd9.rb +0 -23
  153. data/lib/conceptql/nodes/icd9_procedure.rb +0 -20
  154. data/lib/conceptql/nodes/loinc.rb +0 -20
  155. data/lib/conceptql/nodes/numeric.rb +0 -40
  156. data/lib/conceptql/nodes/occurrence.rb +0 -49
  157. data/lib/conceptql/nodes/pass_thru.rb +0 -11
  158. data/lib/conceptql/nodes/person_filter.rb +0 -12
  159. data/lib/conceptql/nodes/procedure_occurrence.rb +0 -21
  160. data/lib/conceptql/nodes/recall.rb +0 -50
  161. data/lib/conceptql/nodes/rxnorm.rb +0 -20
  162. data/lib/conceptql/nodes/snomed.rb +0 -19
  163. data/lib/conceptql/nodes/visit.rb +0 -11
  164. data/spec/conceptql/nodes/after_spec.rb +0 -18
  165. data/spec/conceptql/nodes/before_spec.rb +0 -18
  166. data/spec/conceptql/nodes/complement_spec.rb +0 -15
  167. data/spec/conceptql/nodes/concept_spec.rb +0 -34
  168. data/spec/conceptql/nodes/cpt_spec.rb +0 -31
  169. data/spec/conceptql/nodes/date_range_spec.rb +0 -35
  170. data/spec/conceptql/nodes/death_spec.rb +0 -12
  171. data/spec/conceptql/nodes/during_spec.rb +0 -32
  172. data/spec/conceptql/nodes/except_spec.rb +0 -18
  173. data/spec/conceptql/nodes/first_spec.rb +0 -37
  174. data/spec/conceptql/nodes/from_spec.rb +0 -15
  175. data/spec/conceptql/nodes/gender_spec.rb +0 -29
  176. data/spec/conceptql/nodes/hcpcs_spec.rb +0 -31
  177. data/spec/conceptql/nodes/icd10_spec.rb +0 -36
  178. data/spec/conceptql/nodes/icd9_procedure_spec.rb +0 -31
  179. data/spec/conceptql/nodes/icd9_spec.rb +0 -36
  180. data/spec/conceptql/nodes/intersect_spec.rb +0 -33
  181. data/spec/conceptql/nodes/last_spec.rb +0 -38
  182. data/spec/conceptql/nodes/loinc_spec.rb +0 -31
  183. data/spec/conceptql/nodes/occurrence_spec.rb +0 -89
  184. data/spec/conceptql/nodes/person_filter_spec.rb +0 -18
  185. data/spec/conceptql/nodes/person_spec.rb +0 -12
  186. data/spec/conceptql/nodes/procedure_occurrence_spec.rb +0 -12
  187. data/spec/conceptql/nodes/query_double.rb +0 -19
  188. data/spec/conceptql/nodes/race_spec.rb +0 -23
  189. data/spec/conceptql/nodes/rxnorm_spec.rb +0 -31
  190. data/spec/conceptql/nodes/snomed_spec.rb +0 -31
  191. data/spec/conceptql/nodes/source_vocabulary_node_spec.rb +0 -37
  192. data/spec/conceptql/nodes/standard_vocabulary_node_spec.rb +0 -40
  193. data/spec/conceptql/nodes/started_by_spec.rb +0 -25
  194. data/spec/conceptql/nodes/time_window_spec.rb +0 -85
  195. data/spec/conceptql/nodes/union_spec.rb +0 -25
  196. data/spec/conceptql/nodes/visit_occurrence_spec.rb +0 -12
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/date_range'
3
-
4
- describe ConceptQL::Nodes::DateRange do
5
- it 'behaves itself' do
6
- ConceptQL::Nodes::DateRange.new.must_behave_like(:evaluator)
7
- end
8
-
9
- describe '#types' do
10
- it 'should be [:date]' do
11
- ConceptQL::Nodes::DateRange.new(start: '2004-12-13', end: '2010-03-20').types.must_equal([:person])
12
- end
13
- end
14
-
15
- describe '#query' do
16
- it 'should be dates specified assigned to all persons' do
17
- ConceptQL::Nodes::DateRange.new(start: '2004-12-13', end: '2010-03-20').query(Sequel.mock).sql.must_equal("SELECT * FROM (SELECT *, CAST('person' AS varchar(255)) AS criterion_type, person_id AS criterion_id, date '2004-12-13' AS start_date, date '2010-03-20' AS end_date FROM person) AS t1")
18
- end
19
-
20
- it 'should handle strings for option keys' do
21
- ConceptQL::Nodes::DateRange.new('start' => '2004-12-13', 'end' => '2010-03-20').query(Sequel.mock).sql.must_equal("SELECT * FROM (SELECT *, CAST('person' AS varchar(255)) AS criterion_type, person_id AS criterion_id, date '2004-12-13' AS start_date, date '2010-03-20' AS end_date FROM person) AS t1")
22
- end
23
-
24
- it 'handles START as day before first recorded visit_occurrence' do
25
- ConceptQL::Nodes::DateRange.new(start: 'START', end: '2010-03-20').query(Sequel.mock).sql.must_equal("SELECT * FROM (SELECT *, CAST('person' AS varchar(255)) AS criterion_type, person_id AS criterion_id, (SELECT min(start_date) FROM visit_occurrence) AS start_date, date '2010-03-20' AS end_date FROM person) AS t1")
26
- end
27
-
28
- it 'handles END as 2010-12-31' do
29
- ConceptQL::Nodes::DateRange.new(start: '2004-12-13', end: 'END').query(Sequel.mock).sql.must_equal("SELECT * FROM (SELECT *, CAST('person' AS varchar(255)) AS criterion_type, person_id AS criterion_id, date '2004-12-13' AS start_date, (SELECT max(end_date) FROM visit_occurrence) AS end_date FROM person) AS t1")
30
- end
31
- end
32
-
33
- end
34
-
35
-
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/death'
3
- require_double('stream_for_casting')
4
-
5
- describe ConceptQL::Nodes::CastingNode do
6
- it 'behaves itself' do
7
- ConceptQL::Nodes::Death.new.must_behave_like(:casting_node)
8
- end
9
- end
10
-
11
-
12
-
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/during'
3
- require_double('stream_for_temporal')
4
-
5
- describe ConceptQL::Nodes::During do
6
- it 'behaves itself' do
7
- ConceptQL::Nodes::During.new.must_behave_like(:temporal_node)
8
- end
9
-
10
- describe 'when not inclusive' do
11
- subject do
12
- ConceptQL::Nodes::During.new(left: StreamForTemporalDouble.new, right: StreamForTemporalDouble.new)
13
- end
14
-
15
- it 'should use proper where clause' do
16
- subject.query(Sequel.mock).sql.must_match 'l.end_date <= r.end_date'
17
- subject.query(Sequel.mock).sql.must_match 'r.start_date <= l.start_date'
18
- end
19
- end
20
-
21
- describe 'when inclusive' do
22
- subject do
23
- ConceptQL::Nodes::During.new(left: StreamForTemporalDouble.new, right: StreamForTemporalDouble.new, inclusive: true)
24
- end
25
-
26
- it 'should use proper where clause' do
27
- subject.query(Sequel.mock).sql.must_match '(r.start_date <= l.end_date) AND (l.end_date <= r.end_date)'
28
- subject.query(Sequel.mock).sql.must_match '(r.start_date <= l.start_date) AND (l.start_date <= r.end_date)'
29
- end
30
- end
31
- end
32
-
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/except'
3
- require_relative 'query_double'
4
-
5
- describe ConceptQL::Nodes::Except do
6
- it 'behaves itself' do
7
- ConceptQL::Nodes::Except.new.must_behave_like(:evaluator)
8
- end
9
-
10
- describe '#query' do
11
- it 'uses right stream as argument to EXCEPT against left stream' do
12
- double1 = QueryDouble.new(1)
13
- double2 = QueryDouble.new(2)
14
- double1.must_behave_like(:evaluator)
15
- ConceptQL::Nodes::Except.new(left: double1, right: double2).query(Sequel.mock).sql.must_equal "SELECT * FROM (SELECT * FROM table1 EXCEPT SELECT * FROM table2) AS t1"
16
- end
17
- end
18
- end
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/first'
3
- require_double('stream_for_occurrence')
4
-
5
- describe ConceptQL::Nodes::First do
6
- it 'behaves itself' do
7
- ConceptQL::Nodes::First.new.must_behave_like(:evaluator)
8
- end
9
-
10
- it 'should have occurrence pegged at 1' do
11
- ConceptQL::Nodes::First.new.occurrence.must_equal(1)
12
- end
13
-
14
- describe 'occurrence set to 1' do
15
- subject do
16
- ConceptQL::Nodes::First.new(StreamForOccurrenceDouble.new).query(Sequel.mock).sql
17
- end
18
-
19
- it 'should order by ascending start_date' do
20
- subject.must_match 'ORDER BY start_date ASC'
21
- end
22
-
23
- it 'should partition by person_id' do
24
- subject.must_match 'PARTITION BY person_id'
25
- end
26
-
27
- it 'should assign a row number' do
28
- subject.must_match 'row_number()'
29
- end
30
-
31
- it 'should find the all rows with rn = 1' do
32
- subject.must_match 'rn = 1'
33
- end
34
- end
35
- end
36
-
37
-
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/from'
3
- require_relative 'query_double'
4
-
5
- describe ConceptQL::Nodes::From do
6
- it 'behaves itself' do
7
- ConceptQL::Nodes::From.new.must_behave_like(:evaluator)
8
- end
9
-
10
- describe '#query' do
11
- it 'works for single criteria' do
12
- ConceptQL::Nodes::From.new(:table1).query(Sequel.mock).sql.must_equal "SELECT * FROM table1"
13
- end
14
- end
15
- end
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/gender'
3
-
4
- describe ConceptQL::Nodes::Gender do
5
- it 'behaves itself' do
6
- ConceptQL::Nodes::Gender.new.must_behave_like(:evaluator)
7
- end
8
-
9
- describe '#query' do
10
- it 'works for male/MALE/Male/M/m' do
11
- correct_query = "SELECT * FROM person WHERE (gender_concept_id IN (8507))"
12
- ConceptQL::Nodes::Gender.new('male').query(Sequel.mock).sql.must_equal correct_query
13
- ConceptQL::Nodes::Gender.new('Male').query(Sequel.mock).sql.must_equal correct_query
14
- ConceptQL::Nodes::Gender.new('MALE').query(Sequel.mock).sql.must_equal correct_query
15
- ConceptQL::Nodes::Gender.new('M').query(Sequel.mock).sql.must_equal correct_query
16
- ConceptQL::Nodes::Gender.new('m').query(Sequel.mock).sql.must_equal correct_query
17
- end
18
-
19
- it 'works for Female/FEMALE/female/F/f' do
20
- correct_query = "SELECT * FROM person WHERE (gender_concept_id IN (8532))"
21
- ConceptQL::Nodes::Gender.new('female').query(Sequel.mock).sql.must_equal correct_query
22
- ConceptQL::Nodes::Gender.new('Female').query(Sequel.mock).sql.must_equal correct_query
23
- ConceptQL::Nodes::Gender.new('FEMALE').query(Sequel.mock).sql.must_equal correct_query
24
- ConceptQL::Nodes::Gender.new('F').query(Sequel.mock).sql.must_equal correct_query
25
- ConceptQL::Nodes::Gender.new('f').query(Sequel.mock).sql.must_equal correct_query
26
- end
27
- end
28
- end
29
-
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/hcpcs'
3
-
4
- describe ConceptQL::Nodes::Hcpcs do
5
- it 'behaves itself' do
6
- ConceptQL::Nodes::Hcpcs.new.must_behave_like(:standard_vocabulary_node)
7
- end
8
-
9
- subject do
10
- ConceptQL::Nodes::Hcpcs.new
11
- end
12
-
13
- describe '#table' do
14
- it 'should be procedure_occurrence' do
15
- subject.table.must_equal :procedure_occurrence
16
- end
17
- end
18
-
19
- describe '#concept_column' do
20
- it 'should be procedure_concept_id' do
21
- subject.concept_column.must_equal :procedure_concept_id
22
- end
23
- end
24
-
25
- describe '#vocabulary_id' do
26
- it 'should be 5' do
27
- subject.vocabulary_id.must_equal 5
28
- end
29
- end
30
- end
31
-
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/icd10'
3
-
4
- describe ConceptQL::Nodes::Icd10 do
5
- it 'behaves itself' do
6
- ConceptQL::Nodes::Icd10.new.must_behave_like(:source_vocabulary_node)
7
- end
8
-
9
- subject do
10
- ConceptQL::Nodes::Icd10.new
11
- end
12
-
13
- describe '#table' do
14
- it 'should be condition_occurrence' do
15
- subject.table.must_equal :condition_occurrence
16
- end
17
- end
18
-
19
- describe '#concept_column' do
20
- it 'should be condition_concept_id' do
21
- subject.concept_column.must_equal :condition_concept_id
22
- end
23
- end
24
-
25
- describe '#source_column' do
26
- it 'should be condition_source_valuej' do
27
- subject.source_column.must_equal :condition_source_value
28
- end
29
- end
30
-
31
- describe '#vocabulary_id' do
32
- it 'should be 34' do
33
- subject.vocabulary_id.must_equal 34
34
- end
35
- end
36
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/icd9_procedure'
3
-
4
- describe ConceptQL::Nodes::Icd9Procedure do
5
- it 'behaves itself' do
6
- ConceptQL::Nodes::Icd9Procedure.new.must_behave_like(:standard_vocabulary_node)
7
- end
8
-
9
- subject do
10
- ConceptQL::Nodes::Icd9Procedure.new
11
- end
12
-
13
- describe '#table' do
14
- it 'should be procedure_occurrence' do
15
- subject.table.must_equal :procedure_occurrence
16
- end
17
- end
18
-
19
- describe '#concept_column' do
20
- it 'should be procedure_concept_id' do
21
- subject.concept_column.must_equal :procedure_concept_id
22
- end
23
- end
24
-
25
- describe '#vocabulary_id' do
26
- it 'should be 3' do
27
- subject.vocabulary_id.must_equal 3
28
- end
29
- end
30
- end
31
-
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/icd9'
3
-
4
- describe ConceptQL::Nodes::Icd9 do
5
- it 'behaves itself' do
6
- ConceptQL::Nodes::Icd9.new.must_behave_like(:source_vocabulary_node)
7
- end
8
-
9
- subject do
10
- ConceptQL::Nodes::Icd9.new
11
- end
12
-
13
- describe '#table' do
14
- it 'should be condition_occurrence' do
15
- subject.table.must_equal :condition_occurrence
16
- end
17
- end
18
-
19
- describe '#concept_column' do
20
- it 'should be condition_concept_id' do
21
- subject.concept_column.must_equal :condition_concept_id
22
- end
23
- end
24
-
25
- describe '#source_column' do
26
- it 'should be condition_source_valuej' do
27
- subject.source_column.must_equal :condition_source_value
28
- end
29
- end
30
-
31
- describe '#vocabulary_id' do
32
- it 'should be 2' do
33
- subject.vocabulary_id.must_equal 2
34
- end
35
- end
36
- end
@@ -1,33 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/intersect'
3
- require_relative 'query_double'
4
-
5
- describe ConceptQL::Nodes::Intersect do
6
- it 'behaves itself' do
7
- ConceptQL::Nodes::Intersect.new.must_behave_like(:evaluator)
8
- end
9
-
10
- describe '#query' do
11
- it 'works for multiple criteria of same type' do
12
- double1 = QueryDouble.new(1)
13
- double2 = QueryDouble.new(2)
14
- double3 = QueryDouble.new(3)
15
- double1.must_behave_like(:evaluator)
16
- ConceptQL::Nodes::Intersect.new(double1, double2, double3).query(Sequel.mock).sql.must_equal "SELECT * FROM (SELECT * FROM (SELECT * FROM table1 INTERSECT SELECT * FROM table2) AS t1 INTERSECT SELECT * FROM table3) AS t1"
17
- end
18
-
19
- it 'works for multiple criteria of different type' do
20
- double1 = QueryDouble.new(1)
21
- double2 = QueryDouble.new(2, :person)
22
- double3 = QueryDouble.new(3)
23
- double1.must_behave_like(:evaluator)
24
- ConceptQL::Nodes::Intersect.new(double1, double2, double3).query(Sequel.mock).sql.must_equal "SELECT * FROM (SELECT * FROM (SELECT * FROM table1 INTERSECT SELECT * FROM table3) AS t1 UNION ALL SELECT * FROM table2) AS t1"
25
- end
26
-
27
- it 'works for single criteria' do
28
- double1 = QueryDouble.new(1)
29
- double1.must_behave_like(:evaluator)
30
- ConceptQL::Nodes::Intersect.new(double1).query(Sequel.mock).sql.must_equal "SELECT * FROM table1"
31
- end
32
- end
33
- end
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/last'
3
- require_double('stream_for_occurrence')
4
-
5
- describe ConceptQL::Nodes::Last do
6
- it 'behaves itself' do
7
- ConceptQL::Nodes::Last.new.must_behave_like(:evaluator)
8
- end
9
-
10
- it 'should have occurrence pegged at -1' do
11
- ConceptQL::Nodes::Last.new.occurrence.must_equal(-1)
12
- end
13
-
14
- describe 'occurrence set to -1' do
15
- subject do
16
- ConceptQL::Nodes::Last.new(StreamForOccurrenceDouble.new).query(Sequel.mock).sql
17
- end
18
-
19
-
20
- it 'should order by descending start_date' do
21
- subject.must_match 'ORDER BY start_date DESC'
22
- end
23
-
24
- it 'should partition by person_id' do
25
- subject.must_match 'PARTITION BY person_id'
26
- end
27
-
28
- it 'should assign a row number' do
29
- subject.must_match 'row_number()'
30
- end
31
-
32
- it 'should find the all rows with rn = 1' do
33
- subject.must_match 'rn = 1'
34
- end
35
- end
36
- end
37
-
38
-
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/loinc'
3
-
4
- describe ConceptQL::Nodes::Loinc do
5
- it 'behaves itself' do
6
- ConceptQL::Nodes::Loinc.new.must_behave_like(:standard_vocabulary_node)
7
- end
8
-
9
- subject do
10
- ConceptQL::Nodes::Loinc.new
11
- end
12
-
13
- describe '#table' do
14
- it 'should be observation' do
15
- subject.table.must_equal :observation
16
- end
17
- end
18
-
19
- describe '#concept_column' do
20
- it 'should be procedure_concept_id' do
21
- subject.concept_column.must_equal :observation_concept_id
22
- end
23
- end
24
-
25
- describe '#vocabulary_id' do
26
- it 'should be 6' do
27
- subject.vocabulary_id.must_equal 6
28
- end
29
- end
30
- end
31
-
@@ -1,89 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/occurrence'
3
- require_double('stream_for_occurrence')
4
-
5
- describe ConceptQL::Nodes::Occurrence do
6
- it 'behaves itself' do
7
- ConceptQL::Nodes::Occurrence.new.must_behave_like(:evaluator)
8
- end
9
-
10
- describe 'occurrence set to 1' do
11
- subject do
12
- ConceptQL::Nodes::Occurrence.new(1, StreamForOccurrenceDouble.new).query(Sequel.mock).sql
13
- end
14
-
15
- it 'should order by ascending start_date' do
16
- subject.must_match 'ORDER BY start_date ASC'
17
- end
18
-
19
- it 'should partition by person_id' do
20
- subject.must_match 'PARTITION BY person_id'
21
- end
22
-
23
- it 'should assign a row number' do
24
- subject.must_match 'row_number()'
25
- end
26
-
27
- it 'should find the all rows with rn = 1' do
28
- subject.must_match 'rn = 1'
29
- end
30
- end
31
-
32
- describe 'occurrence set to 2' do
33
- subject do
34
- ConceptQL::Nodes::Occurrence.new(2, StreamForOccurrenceDouble.new).query(Sequel.mock).sql
35
- end
36
-
37
- it 'should order by ascending start_date' do
38
- subject.must_match 'ORDER BY start_date ASC'
39
- end
40
-
41
- it 'should find the all rows with rn = 2' do
42
- subject.must_match 'rn = 2'
43
- end
44
- end
45
-
46
- describe 'occurrence set to -1' do
47
- subject do
48
- ConceptQL::Nodes::Occurrence.new(-1, StreamForOccurrenceDouble.new).query(Sequel.mock).sql
49
- end
50
-
51
- it 'should order by ascending start_date' do
52
- subject.must_match 'ORDER BY start_date DESC'
53
- end
54
-
55
- it 'should find the all rows with rn = 1' do
56
- subject.must_match 'rn = 1'
57
- end
58
- end
59
-
60
- describe 'occurrence set to -2' do
61
- subject do
62
- ConceptQL::Nodes::Occurrence.new(-2, StreamForOccurrenceDouble.new).query(Sequel.mock).sql
63
- end
64
-
65
- it 'should order by ascending start_date' do
66
- subject.must_match 'ORDER BY start_date DESC'
67
- end
68
-
69
- it 'should find the all rows with rn = 2' do
70
- subject.must_match 'rn = 2'
71
- end
72
- end
73
-
74
- describe 'occurrence respects types' do
75
- subject do
76
- dub = StreamForOccurrenceDouble.new
77
- def dub.types
78
- [:condition_occurrence]
79
- end
80
- ConceptQL::Nodes::Occurrence.new(-2, dub).query(Sequel.mock).sql
81
- end
82
-
83
- it 'should order by ascending start_date' do
84
- subject.must_match ', criterion_type, criterion_id'
85
- end
86
- end
87
- end
88
-
89
-
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/person_filter'
3
- require_relative 'query_double'
4
-
5
- describe ConceptQL::Nodes::PersonFilter do
6
- it 'behaves itself' do
7
- ConceptQL::Nodes::PersonFilter.new.must_behave_like(:evaluator)
8
- end
9
-
10
- describe '#query' do
11
- it 'uses right stream as argument to PERSON_FILTER against left stream' do
12
- double1 = QueryDouble.new(1)
13
- double2 = QueryDouble.new(2)
14
- double1.must_behave_like(:evaluator)
15
- ConceptQL::Nodes::PersonFilter.new(left: double1, right: double2).query(Sequel.mock).sql.must_equal "SELECT * FROM (SELECT * FROM table1) AS t1 WHERE (person_id IN (SELECT person_id FROM table2 GROUP BY person_id))"
16
- end
17
- end
18
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/person'
3
- require_double('stream_for_casting')
4
-
5
- describe ConceptQL::Nodes::CastingNode do
6
- it 'behaves itself' do
7
- ConceptQL::Nodes::Person.new.must_behave_like(:casting_node)
8
- end
9
- end
10
-
11
-
12
-
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/procedure_occurrence'
3
- require_double('stream_for_casting')
4
-
5
- describe ConceptQL::Nodes::CastingNode do
6
- it 'behaves itself' do
7
- ConceptQL::Nodes::ProcedureOccurrence.new.must_behave_like(:casting_node)
8
- end
9
- end
10
-
11
-
12
-
@@ -1,19 +0,0 @@
1
- require 'conceptql/nodes/node'
2
- class QueryDouble < ConceptQL::Nodes::Node
3
- def initialize(num, type = :visit_occurrence)
4
- @num = num
5
- @type = type
6
- end
7
-
8
- def types
9
- [@type]
10
- end
11
-
12
- def evaluate(db)
13
- query(db)
14
- end
15
-
16
- def query(db)
17
- db["table#{@num}".to_sym]
18
- end
19
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/race'
3
-
4
- describe ConceptQL::Nodes::Race do
5
- it 'behaves itself' do
6
- ConceptQL::Nodes::Race.new.must_behave_like(:evaluator)
7
- end
8
-
9
- describe '#query' do
10
- it 'works for white' do
11
- correct_query = "SELECT * FROM person AS p INNER JOIN vocabulary.concept AS vc ON (vc.concept_id = p.race_concept_id) WHERE (lower(vc.concept_name) IN ('white'))"
12
- ConceptQL::Nodes::Race.new('White').query(Sequel.mock).sql.must_equal correct_query
13
- ConceptQL::Nodes::Race.new('white').query(Sequel.mock).sql.must_equal correct_query
14
- end
15
-
16
- it 'works for multiple values' do
17
- correct_query = "SELECT * FROM person AS p INNER JOIN vocabulary.concept AS vc ON (vc.concept_id = p.race_concept_id) WHERE (lower(vc.concept_name) IN ('white', 'other'))"
18
- ConceptQL::Nodes::Race.new('White', 'Other').query(Sequel.mock).sql.must_equal correct_query
19
- ConceptQL::Nodes::Race.new('white', 'other').query(Sequel.mock).sql.must_equal correct_query
20
- end
21
- end
22
- end
23
-
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/rxnorm'
3
-
4
- describe ConceptQL::Nodes::Rxnorm do
5
- it 'behaves itself' do
6
- ConceptQL::Nodes::Rxnorm.new.must_behave_like(:standard_vocabulary_node)
7
- end
8
-
9
- subject do
10
- ConceptQL::Nodes::Rxnorm.new
11
- end
12
-
13
- describe '#table' do
14
- it 'should be drug_exposure' do
15
- subject.table.must_equal :drug_exposure
16
- end
17
- end
18
-
19
- describe '#concept_column' do
20
- it 'should be drug_concept_id' do
21
- subject.concept_column.must_equal :drug_concept_id
22
- end
23
- end
24
-
25
- describe '#vocabulary_id' do
26
- it 'should be 8' do
27
- subject.vocabulary_id.must_equal 8
28
- end
29
- end
30
- end
31
-
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
- require 'conceptql/nodes/snomed'
3
-
4
- describe ConceptQL::Nodes::Snomed do
5
- it 'behaves itself' do
6
- ConceptQL::Nodes::Snomed.new.must_behave_like(:standard_vocabulary_node)
7
- end
8
-
9
- subject do
10
- ConceptQL::Nodes::Snomed.new
11
- end
12
-
13
- describe '#table' do
14
- it 'should be condition_occurrence' do
15
- subject.table.must_equal :condition_occurrence
16
- end
17
- end
18
-
19
- describe '#concept_column' do
20
- it 'should be condition_concept_id' do
21
- subject.concept_column.must_equal :condition_concept_id
22
- end
23
- end
24
-
25
- describe '#vocabulary_id' do
26
- it 'should be 1' do
27
- subject.vocabulary_id.must_equal 1
28
- end
29
- end
30
- end
31
-