conceptql 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +226 -117
  3. data/LICENSE +21 -0
  4. data/README.md +35 -83
  5. data/bin/conceptql +2 -1
  6. data/bin/conceptql_utils +6 -0
  7. data/config/multiple_vocabularies.csv +4 -0
  8. data/config/provenance.yml +489 -0
  9. data/config/race.yml +50 -0
  10. data/config/vocabularies.csv +87 -0
  11. data/lib/conceptql/behaviors/code_lister.rb +23 -0
  12. data/lib/conceptql/behaviors/drugish.rb +17 -0
  13. data/lib/conceptql/behaviors/labish.rb +19 -0
  14. data/lib/conceptql/behaviors/metadatable.rb +226 -73
  15. data/lib/conceptql/behaviors/provenanceable.rb +26 -0
  16. data/lib/conceptql/behaviors/single_event.rb +11 -0
  17. data/lib/conceptql/behaviors/timeless.rb +11 -0
  18. data/lib/conceptql/behaviors/utilizable.rb +206 -0
  19. data/lib/conceptql/behaviors/windowable.rb +27 -0
  20. data/lib/conceptql/cli.rb +117 -108
  21. data/lib/conceptql/columnizer.rb +75 -0
  22. data/lib/conceptql/data_model/base.rb +462 -0
  23. data/lib/conceptql/data_model/gdm.rb +155 -0
  24. data/lib/conceptql/data_model/gdm_wide.rb +42 -0
  25. data/lib/conceptql/data_model/omopv4_plus.rb +12 -0
  26. data/lib/conceptql/data_model.rb +30 -0
  27. data/lib/conceptql/database.rb +214 -0
  28. data/lib/conceptql/date_adjuster.rb +66 -18
  29. data/lib/conceptql/diagram.rb +243 -0
  30. data/lib/conceptql/lexicon/lexicon_gdm.rb +47 -0
  31. data/lib/conceptql/lexicon/lexicon_no_db.rb +49 -0
  32. data/lib/conceptql/lexicon/lexicon_ohdsi.rb +63 -0
  33. data/lib/conceptql/lexicon/lexicon_strategy.rb +116 -0
  34. data/lib/conceptql/lexicon.rb +111 -0
  35. data/lib/conceptql/nodifier.rb +65 -24
  36. data/lib/conceptql/operators/after.rb +34 -14
  37. data/lib/conceptql/operators/any_overlap.rb +8 -6
  38. data/lib/conceptql/operators/before.rb +34 -10
  39. data/lib/conceptql/operators/binary_operator_operator.rb +66 -23
  40. data/lib/conceptql/operators/casting_operator.rb +51 -36
  41. data/lib/conceptql/operators/co_reported.rb +111 -0
  42. data/lib/conceptql/operators/concurrent_within.rb +69 -0
  43. data/lib/conceptql/operators/contains.rb +12 -8
  44. data/lib/conceptql/operators/count.rb +17 -9
  45. data/lib/conceptql/operators/date_range.rb +48 -14
  46. data/lib/conceptql/operators/death.rb +14 -4
  47. data/lib/conceptql/operators/dedup.rb +31 -0
  48. data/lib/conceptql/operators/during.rb +7 -12
  49. data/lib/conceptql/operators/episode.rb +146 -0
  50. data/lib/conceptql/operators/equal.rb +9 -3
  51. data/lib/conceptql/operators/ethnicity.rb +49 -0
  52. data/lib/conceptql/operators/except.rb +19 -12
  53. data/lib/conceptql/operators/filter.rb +23 -8
  54. data/lib/conceptql/operators/first.rb +16 -3
  55. data/lib/conceptql/operators/from.rb +52 -4
  56. data/lib/conceptql/operators/gender.rb +34 -11
  57. data/lib/conceptql/operators/hospice.rb +19 -0
  58. data/lib/conceptql/operators/hospitalization.rb +19 -0
  59. data/lib/conceptql/operators/information_periods.rb +36 -0
  60. data/lib/conceptql/operators/invalid.rb +35 -0
  61. data/lib/conceptql/operators/last.rb +16 -3
  62. data/lib/conceptql/operators/match.rb +91 -0
  63. data/lib/conceptql/operators/multiple_vocabularies.rb +172 -0
  64. data/lib/conceptql/operators/numeric.rb +65 -23
  65. data/lib/conceptql/operators/numeric_filter.rb +68 -0
  66. data/lib/conceptql/operators/occurrence.rb +153 -32
  67. data/lib/conceptql/operators/one_in_two_out.rb +237 -38
  68. data/lib/conceptql/operators/operator.rb +624 -178
  69. data/lib/conceptql/operators/pass_thru.rb +17 -3
  70. data/lib/conceptql/operators/person.rb +18 -6
  71. data/lib/conceptql/operators/person_filter.rb +9 -3
  72. data/lib/conceptql/operators/place_of_service_filter.rb +43 -0
  73. data/lib/conceptql/operators/provenance.rb +55 -0
  74. data/lib/conceptql/operators/provider_filter.rb +62 -0
  75. data/lib/conceptql/operators/race.rb +55 -7
  76. data/lib/conceptql/operators/read.rb +168 -0
  77. data/lib/conceptql/operators/recall.rb +49 -14
  78. data/lib/conceptql/operators/snf.rb +19 -0
  79. data/lib/conceptql/operators/sum.rb +29 -12
  80. data/lib/conceptql/operators/temporal_operator.rb +108 -16
  81. data/lib/conceptql/operators/time_window.rb +20 -32
  82. data/lib/conceptql/operators/trim_date.rb +71 -0
  83. data/lib/conceptql/operators/trim_date_end.rb +28 -40
  84. data/lib/conceptql/operators/trim_date_start.rb +28 -41
  85. data/lib/conceptql/operators/union.rb +67 -6
  86. data/lib/conceptql/operators/vocabulary.rb +151 -0
  87. data/lib/conceptql/paths.rb +41 -0
  88. data/lib/conceptql/query.rb +191 -26
  89. data/lib/conceptql/query_modifiers/gdm/admission_date_query_modifier.rb +46 -0
  90. data/lib/conceptql/query_modifiers/gdm/drug_query_modifier.rb +54 -0
  91. data/lib/conceptql/query_modifiers/gdm/lab_query_modifier.rb +57 -0
  92. data/lib/conceptql/query_modifiers/gdm/pos_query_modifier.rb +46 -0
  93. data/lib/conceptql/query_modifiers/gdm/provenance_query_modifier.rb +45 -0
  94. data/lib/conceptql/query_modifiers/gdm/provider_query_modifier.rb +53 -0
  95. data/lib/conceptql/query_modifiers/gdm_wide/admission_date_query_modifier.rb +42 -0
  96. data/lib/conceptql/query_modifiers/gdm_wide/drug_query_modifier.rb +52 -0
  97. data/lib/conceptql/query_modifiers/gdm_wide/lab_query_modifier.rb +55 -0
  98. data/lib/conceptql/query_modifiers/gdm_wide/pos_query_modifier.rb +37 -0
  99. data/lib/conceptql/query_modifiers/gdm_wide/provenance_query_modifier.rb +38 -0
  100. data/lib/conceptql/query_modifiers/omopv4_plus/admission_date_query_modifier.rb +45 -0
  101. data/lib/conceptql/query_modifiers/omopv4_plus/drug_query_modifier.rb +80 -0
  102. data/lib/conceptql/query_modifiers/omopv4_plus/pos_query_modifier.rb +47 -0
  103. data/lib/conceptql/query_modifiers/omopv4_plus/provenance_query_modifier.rb +45 -0
  104. data/lib/conceptql/query_modifiers/omopv4_plus/provider_query_modifier.rb +26 -0
  105. data/lib/conceptql/query_modifiers/query_modifier.rb +20 -0
  106. data/lib/conceptql/rdbms/duckdb.rb +25 -0
  107. data/lib/conceptql/rdbms/generic.rb +120 -0
  108. data/lib/conceptql/rdbms/postgres.rb +51 -0
  109. data/lib/conceptql/rdbms/spark.rb +22 -0
  110. data/lib/conceptql/rdbms.rb +22 -0
  111. data/lib/conceptql/scope.rb +481 -31
  112. data/lib/conceptql/sql_formatters/formatter.rb +25 -0
  113. data/lib/conceptql/sql_formatters.rb +22 -0
  114. data/lib/conceptql/utils.rb +113 -0
  115. data/lib/conceptql/utils_cli.rb +17 -0
  116. data/lib/conceptql/version.rb +3 -1
  117. data/lib/conceptql/visitors/metadata_extractor.rb +54 -0
  118. data/lib/conceptql/vocabularies/behaviors/costish.rb +24 -0
  119. data/lib/conceptql/vocabularies/behaviors/gdmish.rb +19 -0
  120. data/lib/conceptql/vocabularies/behaviors/omopish.rb +32 -0
  121. data/lib/conceptql/vocabularies/dynamic_vocabularies.rb +63 -0
  122. data/lib/conceptql/vocabularies/entry.rb +138 -0
  123. data/lib/conceptql/vocabularies/vocabulary_class_factory.rb +85 -0
  124. data/lib/conceptql/window/base.rb +26 -0
  125. data/lib/conceptql/window/date_range.rb +25 -0
  126. data/lib/conceptql/window/table.rb +116 -0
  127. data/lib/conceptql/window.rb +72 -0
  128. data/lib/conceptql.rb +65 -2
  129. data/lib/sequel/extensions/pg_ctas_explain.rb +22 -0
  130. data/lib/sequel/extensions/pg_vacuum_table.rb +23 -0
  131. data/schemas/gdm.yml +882 -0
  132. data/schemas/gdm_wide.yml +757 -0
  133. data/schemas/ohdsi_vocabs.yml +143 -0
  134. data/schemas/omopv4_plus.yml +729 -0
  135. data/schemas/omopv4_plus_more_ignorables.tsv +13 -0
  136. metadata +267 -207
  137. data/.gitignore +0 -23
  138. data/Gemfile +0 -4
  139. data/Guardfile +0 -56
  140. data/LICENSE.txt +0 -22
  141. data/Rakefile +0 -1
  142. data/conceptql.gemspec +0 -32
  143. data/doc/ConceptQL Specification (alpha).pdf +0 -0
  144. data/doc/diagram_0.png +0 -0
  145. data/doc/implementation_notes.md +0 -39
  146. data/doc/spec.md +0 -1344
  147. data/lib/conceptql/behaviors/debuggable.rb +0 -70
  148. data/lib/conceptql/behaviors/dottable.rb +0 -103
  149. data/lib/conceptql/behaviors/preppable.rb +0 -20
  150. data/lib/conceptql/converter.rb +0 -65
  151. data/lib/conceptql/debugger.rb +0 -48
  152. data/lib/conceptql/fake_grapher.rb +0 -20
  153. data/lib/conceptql/graph.rb +0 -52
  154. data/lib/conceptql/graph_nodifier.rb +0 -203
  155. data/lib/conceptql/logger.rb +0 -10
  156. data/lib/conceptql/operators/complement.rb +0 -38
  157. data/lib/conceptql/operators/concept.rb +0 -70
  158. data/lib/conceptql/operators/condition_type.rb +0 -71
  159. data/lib/conceptql/operators/cpt.rb +0 -25
  160. data/lib/conceptql/operators/drug_type_concept.rb +0 -21
  161. data/lib/conceptql/operators/from_seer_visits.rb +0 -23
  162. data/lib/conceptql/operators/hcpcs.rb +0 -25
  163. data/lib/conceptql/operators/icd10.rb +0 -28
  164. data/lib/conceptql/operators/icd9.rb +0 -28
  165. data/lib/conceptql/operators/icd9_procedure.rb +0 -25
  166. data/lib/conceptql/operators/intersect.rb +0 -34
  167. data/lib/conceptql/operators/loinc.rb +0 -25
  168. data/lib/conceptql/operators/medcode.rb +0 -28
  169. data/lib/conceptql/operators/medcode_procedure.rb +0 -27
  170. data/lib/conceptql/operators/ndc.rb +0 -29
  171. data/lib/conceptql/operators/observation_by_enttype.rb +0 -29
  172. data/lib/conceptql/operators/observation_period.rb +0 -30
  173. data/lib/conceptql/operators/overlapped_by.rb +0 -23
  174. data/lib/conceptql/operators/overlaps.rb +0 -19
  175. data/lib/conceptql/operators/place_of_service_code.rb +0 -24
  176. data/lib/conceptql/operators/procedure_occurrence.rb +0 -25
  177. data/lib/conceptql/operators/prodcode.rb +0 -29
  178. data/lib/conceptql/operators/rxnorm.rb +0 -24
  179. data/lib/conceptql/operators/snomed.rb +0 -24
  180. data/lib/conceptql/operators/snomed_condition.rb +0 -26
  181. data/lib/conceptql/operators/source_vocabulary_operator.rb +0 -58
  182. data/lib/conceptql/operators/standard_vocabulary_operator.rb +0 -45
  183. data/lib/conceptql/operators/started_by.rb +0 -22
  184. data/lib/conceptql/operators/to_seer_visits.rb +0 -24
  185. data/lib/conceptql/operators/visit.rb +0 -15
  186. data/lib/conceptql/operators/visit_occurrence.rb +0 -30
  187. data/lib/conceptql/tree.rb +0 -53
  188. data/lib/conceptql/utils/temp_table.rb +0 -72
  189. data/spec/conceptql/behaviors/dottable_spec.rb +0 -99
  190. data/spec/conceptql/converter_spec.rb +0 -51
  191. data/spec/conceptql/date_adjuster_spec.rb +0 -68
  192. data/spec/conceptql/operators/after_spec.rb +0 -16
  193. data/spec/conceptql/operators/before_spec.rb +0 -16
  194. data/spec/conceptql/operators/casting_operator_spec.rb +0 -68
  195. data/spec/conceptql/operators/complement_spec.rb +0 -15
  196. data/spec/conceptql/operators/concept_spec.rb +0 -40
  197. data/spec/conceptql/operators/condition_type_spec.rb +0 -128
  198. data/spec/conceptql/operators/contains_spec.rb +0 -19
  199. data/spec/conceptql/operators/cpt_spec.rb +0 -29
  200. data/spec/conceptql/operators/date_range_spec.rb +0 -33
  201. data/spec/conceptql/operators/death_spec.rb +0 -10
  202. data/spec/conceptql/operators/during_spec.rb +0 -30
  203. data/spec/conceptql/operators/except_spec.rb +0 -15
  204. data/spec/conceptql/operators/first_spec.rb +0 -35
  205. data/spec/conceptql/operators/from_spec.rb +0 -13
  206. data/spec/conceptql/operators/gender_spec.rb +0 -27
  207. data/spec/conceptql/operators/hcpcs_spec.rb +0 -29
  208. data/spec/conceptql/operators/icd10_spec.rb +0 -34
  209. data/spec/conceptql/operators/icd9_procedure_spec.rb +0 -29
  210. data/spec/conceptql/operators/icd9_spec.rb +0 -34
  211. data/spec/conceptql/operators/intersect_spec.rb +0 -28
  212. data/spec/conceptql/operators/last_spec.rb +0 -36
  213. data/spec/conceptql/operators/loinc_spec.rb +0 -29
  214. data/spec/conceptql/operators/medcode_procedure_spec.rb +0 -34
  215. data/spec/conceptql/operators/medcode_spec.rb +0 -34
  216. data/spec/conceptql/operators/observation_period_spec.rb +0 -10
  217. data/spec/conceptql/operators/occurrence_spec.rb +0 -87
  218. data/spec/conceptql/operators/overlapped_by_spec.rb +0 -32
  219. data/spec/conceptql/operators/overlaps_spec.rb +0 -21
  220. data/spec/conceptql/operators/person_filter_spec.rb +0 -15
  221. data/spec/conceptql/operators/person_spec.rb +0 -10
  222. data/spec/conceptql/operators/place_of_service_code_spec.rb +0 -24
  223. data/spec/conceptql/operators/procedure_occurrence_spec.rb +0 -10
  224. data/spec/conceptql/operators/prodcode_spec.rb +0 -35
  225. data/spec/conceptql/operators/query_double.rb +0 -20
  226. data/spec/conceptql/operators/query_double_spec.rb +0 -7
  227. data/spec/conceptql/operators/race_spec.rb +0 -21
  228. data/spec/conceptql/operators/rxnorm_spec.rb +0 -29
  229. data/spec/conceptql/operators/snomed_spec.rb +0 -29
  230. data/spec/conceptql/operators/source_vocabulary_operator_spec.rb +0 -35
  231. data/spec/conceptql/operators/standard_vocabulary_operator_spec.rb +0 -35
  232. data/spec/conceptql/operators/started_by_spec.rb +0 -22
  233. data/spec/conceptql/operators/temporal_operator_spec.rb +0 -51
  234. data/spec/conceptql/operators/time_window_spec.rb +0 -77
  235. data/spec/conceptql/operators/union_spec.rb +0 -21
  236. data/spec/conceptql/operators/visit_occurrence_spec.rb +0 -10
  237. data/spec/conceptql/query_spec.rb +0 -22
  238. data/spec/conceptql/tree_spec.rb +0 -50
  239. data/spec/doubles/stream_for_casting_double.rb +0 -9
  240. data/spec/doubles/stream_for_occurrence_double.rb +0 -25
  241. data/spec/doubles/stream_for_temporal_double.rb +0 -6
  242. data/spec/spec_helper.rb +0 -102
@@ -1,71 +0,0 @@
1
- require_relative 'operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- # Represents a operator that will grab all conditions that match the
6
- # condition type passed in
7
- #
8
- # Condition Type represents which position the condition held in
9
- # the raw data, e.g. primary inpatient header or 15th outpatient detail
10
- #
11
- # Multiple types can be specified at once
12
- class ConditionType < Operator
13
- desc 'Searches for conditions that match the given set of Condition Types'
14
- argument :condition_types, type: :codelist, vocab: 'Condition Type'
15
- category %(Occurrence Type)
16
- predominant_types :condition_occurrence
17
-
18
- def type
19
- :condition_occurrence
20
- end
21
-
22
- def query(db)
23
- db.from(:condition_occurrence)
24
- .where(condition_type_concept_id: condition_occurrence_type_concept_ids)
25
- end
26
-
27
- private
28
- def condition_occurrence_type_concept_ids
29
- arguments.map do |arg|
30
- to_concept_id(arg.to_s)
31
- end.flatten
32
- end
33
-
34
- def to_concept_id(ctype)
35
- ctype = ctype.to_s.downcase
36
- position = nil
37
- if ctype =~ /(\d|_primary)$/ && ctype.count('_') > 1
38
- parts = ctype.split('_')
39
- position = parts.pop.to_i
40
- position -= 1 if ctype =~ /^outpatient/
41
- ctype = parts.join('_')
42
- end
43
- retval = concept_ids[ctype.to_sym]
44
- return retval[position] if position
45
- return retval
46
- end
47
-
48
- def concept_ids
49
- @concept_ids ||= begin
50
- hash = {
51
- inpatient_detail: (38000183..38000198).to_a,
52
- inpatient_header: (38000199..38000214).to_a,
53
- outpatient_detail: (38000215..38000229).to_a,
54
- outpatient_header: (38000230..38000244).to_a,
55
- ehr_problem_list: [38000245],
56
- condition_era_0_day_window: [38000246],
57
- condition_era_30_day_window: [38000247]
58
- }
59
- hash[:primary] = %w(inpatient_detail inpatient_header outpatient_detail outpatient_header).map { |w| hash[w.to_sym].first }
60
- hash[:outpatient_primary] = %w(outpatient_detail outpatient_header).map { |w| hash[w.to_sym].first }
61
- hash[:inpatient_primary] = %w(inpatient_detail inpatient_header).map { |w| hash[w.to_sym].first }
62
- hash[:inpatient] = hash[:inpatient_detail] + hash[:inpatient_header]
63
- hash[:outpatient] = hash[:outpatient_detail] + hash[:outpatient_header]
64
- hash[:condition_era] = hash[:condition_era_0_day_window] + hash[:condition_era_30_day_window]
65
- hash
66
- end
67
- end
68
- end
69
- end
70
- end
71
-
@@ -1,25 +0,0 @@
1
- require_relative 'standard_vocabulary_operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class Cpt < StandardVocabularyOperator
6
- preferred_name 'CPT'
7
- desc 'Searches the procedure_occurrence table for all procedures with matching CPT codes'
8
- argument :cpts, type: :codelist, vocab: 'CPT4'
9
- predominant_types :procedure_occurrence
10
-
11
- def table
12
- :procedure_occurrence
13
- end
14
-
15
- def vocabulary_id
16
- 4
17
- end
18
-
19
- def concept_column
20
- :procedure_concept_id
21
- end
22
- end
23
- end
24
- end
25
-
@@ -1,21 +0,0 @@
1
- require_relative 'operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class DrugTypeConcept < Operator
6
- desc 'Given a set of concept IDs in RxNorm, returns that set of drug exposures'
7
- argument :concept_ids, type: :codelist, vocab: 'RxNorm'
8
-
9
- def type
10
- :drug_exposure
11
- end
12
-
13
- def query(db)
14
- db.from(:drug_exposure)
15
- .where(drug_type_concept_id: arguments)
16
- end
17
- end
18
- end
19
- end
20
-
21
-
@@ -1,23 +0,0 @@
1
- require_relative 'operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class FromSeerVisits < Operator
6
- def type
7
- :observation
8
- end
9
- def query(db)
10
- visit_ids = stream.evaluate(db)
11
- .from_self
12
- .where(criterion_type: 'visit_occurrence')
13
- query = db[:observation].where(visit_occurrence_id: visit_ids.select(:criterion_id))
14
- arguments.inject(query) do |q, key|
15
- q.where(observation_source_value: key.to_s.upcase)
16
- end
17
- end
18
- end
19
- end
20
- end
21
-
22
-
23
-
@@ -1,25 +0,0 @@
1
- require_relative 'standard_vocabulary_operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class Hcpcs < StandardVocabularyOperator
6
- preferred_name 'HCPCS'
7
- desc 'Searches the procedure_occurrence table for all procedures with matching HCPCS codes'
8
- argument :hcpcs, type: :codelist, vocab: 'HCPCS'
9
- predominant_types :procedure_occurrence
10
-
11
- def table
12
- :procedure_occurrence
13
- end
14
-
15
- def vocabulary_id
16
- 5
17
- end
18
-
19
- def concept_column
20
- :procedure_concept_id
21
- end
22
- end
23
- end
24
- end
25
-
@@ -1,28 +0,0 @@
1
- require_relative 'source_vocabulary_operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class Icd10 < SourceVocabularyOperator
6
- preferred_name 'ICD-10 CM'
7
- desc 'Searches the condition_occurrence table for the given set of ICD-10 codes.'
8
- argument :icd10s, type: :codelist, vocab: 'ICD10CM'
9
- predominant_types :condition_occurrence
10
-
11
- def table
12
- :condition_occurrence
13
- end
14
-
15
- def vocabulary_id
16
- 34
17
- end
18
-
19
- def source_column
20
- :condition_source_value
21
- end
22
-
23
- def concept_column
24
- :condition_concept_id
25
- end
26
- end
27
- end
28
- end
@@ -1,28 +0,0 @@
1
- require_relative 'source_vocabulary_operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class Icd9 < SourceVocabularyOperator
6
- preferred_name 'ICD-9 CM'
7
- desc 'Searches the condition_occurrence table for the given set of ICD-9 codes.'
8
- argument :icd9s, type: :codelist, vocab: 'ICD9CM'
9
- predominant_types :condition_occurrence
10
-
11
- def table
12
- :condition_occurrence
13
- end
14
-
15
- def vocabulary_id
16
- 2
17
- end
18
-
19
- def source_column
20
- :condition_source_value
21
- end
22
-
23
- def concept_column
24
- :condition_concept_id
25
- end
26
- end
27
- end
28
- end
@@ -1,25 +0,0 @@
1
- require_relative 'standard_vocabulary_operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class Icd9Procedure < StandardVocabularyOperator
6
- preferred_name 'ICD-9 Proc'
7
- desc 'Searches the procedure_occurrence table for the given set of ICD-9 codes.'
8
- argument :icd9s, type: :codelist, vocab: 'ICD9Proc'
9
- predominant_types :procedure_occurrence
10
-
11
- def table
12
- :procedure_occurrence
13
- end
14
-
15
- def vocabulary_id
16
- 3
17
- end
18
-
19
- def concept_column
20
- :procedure_concept_id
21
- end
22
- end
23
- end
24
- end
25
-
@@ -1,34 +0,0 @@
1
- require_relative 'pass_thru'
2
-
3
- module ConceptQL
4
- module Operators
5
- class Intersect < PassThru
6
- desc 'Passes thru any result row that appears in all incoming result sets.'
7
- allows_many_upstreams
8
- category 'Set Logic'
9
-
10
- def types
11
- upstreams.map(&:types).flatten.uniq
12
- end
13
-
14
- def query(db)
15
- exprs = {}
16
- upstreams.each do |expression|
17
- evaled = expression.evaluate(db)
18
- expression.types.each do |type|
19
- (exprs[type] ||= []) << evaled
20
- end
21
- end
22
- typed_queries = exprs.map do |type, queries|
23
- queries.inject do |q, query|
24
- q.intersect(query)
25
- end
26
- end
27
-
28
- typed_queries.inject do |q, query|
29
- q.union(query, all: true)
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,25 +0,0 @@
1
- require_relative 'standard_vocabulary_operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class Loinc < StandardVocabularyOperator
6
- preferred_name 'LOINC'
7
- desc 'Searches the observation table for all observations with matching LOINC codes'
8
- argument :loincs, type: :codelist, vocab: 'LOINC'
9
- predominant_types :observation
10
-
11
- def table
12
- :observation
13
- end
14
-
15
- def vocabulary_id
16
- 6
17
- end
18
-
19
- def concept_column
20
- :observation_concept_id
21
- end
22
- end
23
- end
24
- end
25
-
@@ -1,28 +0,0 @@
1
- require_relative 'source_vocabulary_operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class Medcode < SourceVocabularyOperator
6
- desc 'Searches the condition_occurrence table for all conditions with matching Medcodes'
7
- argument :medcodes, type: :codelist, vocab_id: '203'
8
- predominant_types :condition_occurrence
9
-
10
- def table
11
- :condition_occurrence
12
- end
13
-
14
- def vocabulary_id
15
- 203
16
- end
17
-
18
- def source_column
19
- :condition_source_value
20
- end
21
-
22
- def concept_column
23
- :condition_concept_id
24
- end
25
- end
26
- end
27
- end
28
-
@@ -1,27 +0,0 @@
1
- require_relative 'source_vocabulary_operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class MedcodeProcedure < SourceVocabularyOperator
6
- desc 'Searches the procedure_occurrence table for all procedures with matching Medcodes'
7
- argument :medcodes, type: :codelist, vocab: '204'
8
- predominant_types :procedure_occurrence
9
-
10
- def table
11
- :procedure_occurrence
12
- end
13
-
14
- def vocabulary_id
15
- 204
16
- end
17
-
18
- def source_column
19
- :procedure_source_value
20
- end
21
-
22
- def concept_column
23
- :procedure_concept_id
24
- end
25
- end
26
- end
27
- end
@@ -1,29 +0,0 @@
1
- require_relative 'source_vocabulary_operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class Ndc < SourceVocabularyOperator
6
- preferred_name 'NDC'
7
- desc 'Searches the drug_exposure table for all procedures with matching NDC codes'
8
- argument :ndcs, type: :codelist, vocab: 'NDC'
9
- predominant_types :drug_exposure
10
-
11
- def table
12
- :drug_exposure
13
- end
14
-
15
- def vocabulary_id
16
- 9
17
- end
18
-
19
- def source_column
20
- :drug_source_value
21
- end
22
-
23
- def concept_column
24
- :drug_concept_id
25
- end
26
- end
27
- end
28
- end
29
-
@@ -1,29 +0,0 @@
1
- require_relative 'source_vocabulary_operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class ObservationByEnttype < SourceVocabularyOperator
6
- desc 'Searches the observation table for all observations with matching Enttype'
7
- argument :enttypes, type: :codelist, vocab_id: [206, 207]
8
- predominant_types :observation
9
-
10
- def table
11
- :observation
12
- end
13
-
14
- def vocabulary_id
15
- [206, 207]
16
- end
17
-
18
- def source_column
19
- :observation_source_value
20
- end
21
-
22
- def concept_column
23
- :observation_concept_id
24
- end
25
- end
26
- end
27
- end
28
-
29
-
@@ -1,30 +0,0 @@
1
- require_relative 'casting_operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class ObservationPeriod < CastingOperator
6
- desc 'Generates all observation_period records, or, if fed a stream, fetches all observation_period records for the people represented in the incoming result set.'
7
- types :observation_period
8
- allows_one_upstream
9
-
10
- def my_type
11
- :observation_period
12
- end
13
-
14
- def i_point_at
15
- []
16
- end
17
-
18
- def these_point_at_me
19
- # I could list ALL the types we use, but the default behavior of casting,
20
- # when there is no explicit casting defined, is to convert everything to
21
- # person IDs
22
- #
23
- # So by defining no known castable relationships in this operator, all
24
- # types will be converted to person
25
- []
26
- end
27
- end
28
- end
29
- end
30
-
@@ -1,23 +0,0 @@
1
- require_relative 'temporal_operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class OverlappedBy < TemporalOperator
6
- desc <<-EOF
7
- Compares all results on a person-by-person basis between the left hand results (LHR) and the right hand resuls (RHR).
8
- For any result in the LHR whose start_date occurs between the start_date and end_date of a result from the RHR, that result is passed through.
9
- All other results are discarded, including all results in the RHR.
10
- L-------N-------L
11
- R-----R
12
- L-----Y----L
13
- EOF
14
- def where_clause
15
- if inclusive?
16
- [Proc.new { r__start_date <= l__start_date}, Proc.new { l__start_date <= r__end_date }]
17
- else
18
- [Proc.new { r__start_date <= l__start_date}, Proc.new { l__start_date <= r__end_date }, Proc.new { r__end_date <= l__end_date }]
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,19 +0,0 @@
1
- require_relative 'temporal_operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class Overlaps < TemporalOperator
6
- desc <<-EOF
7
- Compares all results on a person-by-person basis between the left hand results (LHR) and the right hand resuls (RHR).
8
- For any result in the LHR whose end_date occurs between the start_date and end_date of a result from the RHR, that result is passed through.
9
- All other results are discarded, including all results in the RHR.
10
- L-------Y-------L
11
- R-----R
12
- L-----N----L
13
- EOF
14
- def where_clause
15
- [Proc.new { l__start_date <= r__start_date}, Proc.new { r__start_date <= l__end_date }, Proc.new { l__end_date <= r__end_date }]
16
- end
17
- end
18
- end
19
- end
@@ -1,24 +0,0 @@
1
- require_relative 'operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- # Represents a operator that will grab all person rows that match the given place_of_service_codes
6
- #
7
- # PlaceOfServiceCode parameters are passed in as a set of strings. Each string represents
8
- # a single place_of_service_code. The place_of_service_code string must match one of the values in the
9
- # concept_name column of the concept table. If you misspell the place_of_service_code name
10
- # you won't get any matches
11
- class PlaceOfServiceCode < Operator
12
- desc 'Finds all visit_occurrences that match the Place of Service codes'
13
- argument :places_of_service, type: :codelist, vocab: 'Place of Service'
14
- types :visit_occurrence
15
-
16
- def query(db)
17
- db.from(:visit_occurrence___v)
18
- .join(:vocabulary__concept___vc, { vc__concept_id: :v__place_of_service_concept_id })
19
- .where(vc__concept_code: arguments.map(&:to_s))
20
- .where(vc__vocabulary_id: 14)
21
- end
22
- end
23
- end
24
- end
@@ -1,25 +0,0 @@
1
- require_relative 'casting_operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class ProcedureOccurrence < CastingOperator
6
- desc 'Generates all procedure_occurrence records, or, if fed a stream, fetches all procedure_occurrence records for the people represented in the incoming result set.'
7
- types :procedure_occurrence
8
- allows_one_upstream
9
-
10
- def my_type
11
- :procedure_occurrence
12
- end
13
-
14
- def i_point_at
15
- [ :person ]
16
- end
17
-
18
- def these_point_at_me
19
- %i[
20
- procedure_cost
21
- ]
22
- end
23
- end
24
- end
25
- end
@@ -1,29 +0,0 @@
1
- require_relative 'source_vocabulary_operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class Prodcode < SourceVocabularyOperator
6
- desc 'Searches the drug_exposure table for all conditions with matching Prodcodes'
7
- argument :prodcodes, type: :codelist, vocab_id: '203'
8
- predominant_types :drug_exposure
9
-
10
- def table
11
- :drug_exposure
12
- end
13
-
14
- def vocabulary_id
15
- 200
16
- end
17
-
18
- def source_column
19
- :drug_source_value
20
- end
21
-
22
- def concept_column
23
- :drug_concept_id
24
- end
25
- end
26
- end
27
- end
28
-
29
-
@@ -1,24 +0,0 @@
1
- require_relative 'standard_vocabulary_operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class Rxnorm < StandardVocabularyOperator
6
- preferred_name 'RxNorm'
7
- desc 'Finds all drug_exposures by RxNorm codes'
8
- argument :rxnorms, type: :codelist, vocab: 'RxNorm'
9
-
10
- def table
11
- :drug_exposure
12
- end
13
-
14
- def vocabulary_id
15
- 8
16
- end
17
-
18
- def concept_column
19
- :drug_concept_id
20
- end
21
- end
22
- end
23
- end
24
-
@@ -1,24 +0,0 @@
1
- require_relative 'standard_vocabulary_operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class Snomed < StandardVocabularyOperator
6
- preferred_name 'SNOMED'
7
- desc 'Find all condition_occurrences by SNOMED codes'
8
- argument :snomeds, type: :codelist, vocab: 'SNOMED'
9
- predominant_types :condition_occurrence
10
-
11
- def table
12
- :condition_occurrence
13
- end
14
-
15
- def vocabulary_id
16
- 1
17
- end
18
-
19
- def concept_column
20
- :condition_concept_id
21
- end
22
- end
23
- end
24
- end
@@ -1,26 +0,0 @@
1
- require_relative 'standard_vocabulary_operator'
2
-
3
- module ConceptQL
4
- module Operators
5
- class SnomedCondition < StandardVocabularyOperator
6
- preferred_name 'SNOMED'
7
- desc 'Find all condition_occurrences by SNOMED codes'
8
- argument :snomeds, type: :codelist, vocab: 'SNOMED'
9
- predominant_types :condition_occurrence
10
-
11
- def table
12
- :condition_occurrence
13
- end
14
-
15
- def vocabulary_id
16
- 1
17
- end
18
-
19
- def concept_column
20
- :condition_concept_id
21
- end
22
- end
23
- end
24
- end
25
-
26
-