canql 5.0.0 → 5.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99a2f7ebbb5ae3c1cbdd8368b020f8eb7c54d969278db3bdd90277f113095ce9
4
- data.tar.gz: fb4f6561d61cc9da30dd9a30562c7374a95e52d615b014bc16e5e282529c4975
3
+ metadata.gz: 6f1406cd4a6e0b0e9f66ef6386f0356b8b60e7c9ed6300ac8366a3e6b65aad4c
4
+ data.tar.gz: 6933617a2d3b293fa5c844d4885ee2e0b005cb5ba4596de4699fcaf3254faff5
5
5
  SHA512:
6
- metadata.gz: 93cc26e76a35a5b47600368d7208f81c6cd6457c416f942be852536952d54b9a1bbcb49df7c17f95fb09b5bdaa4581fda91b70e36ad229aae5213914d9d7db39
7
- data.tar.gz: 2a8bf966e8a0b93411117a09f790f20825c6b27850f1903cea53fd636855d920ec4fdc5dc9bb903b11ec0c2e34275af88ca2e49e4c09b3ea206a6ff2620d626b
6
+ metadata.gz: 458ad85cf4588bde403a34ec3721a5e6f22b2a7242029f9d21b4f9f4fa1264355c408e8ba84f8cb280023b5fff5ab480ba5a29d163e62030e7b2b3354d1b301d
7
+ data.tar.gz: dd916f281f0d531b84ac6e6ff696d28761d92915e70eca5266bfdd4c5ea3f93daaa1dbb246e9482e47b6e6a6b9907f6d1fdca8ac2e8e47f69ea1da1a1ff5b359
@@ -1,6 +1,6 @@
1
1
  name: Test
2
2
 
3
- on: [push, pull_request]
3
+ on: [push]
4
4
 
5
5
  jobs:
6
6
  test:
data/CHANGELOG.md CHANGED
@@ -1,8 +1,27 @@
1
1
  ## [Unreleased]
2
- *no unreleased changes*
2
+ * no relevant changes
3
3
 
4
- ## 5.0.0 / 2021-01-19
4
+ ## 5.5.0 / 2021-03-16
5
+ ### Added
6
+ * Add HES event filter (#72)
7
+
8
+ ## 5.4.0 / 2021-03-08
9
+ ### Added
10
+ * Add 'pending data' option to the anomaly screening status filter (#69)
11
+
12
+ ## 5.3.0 / 2021-03-05
13
+ ### Added
14
+ * Added new FASP case RAG rating filters (#66)
5
15
 
16
+ ## 5.2.0 / 2021-03-04
17
+ ### Added
18
+ * Added new FASP anomaly RAG rating filters (#63)
19
+
20
+ ## 5.1.0 / 2021-01-25
21
+ ### Added
22
+ * Added new filters for test acceptance requirments (#59)
23
+
24
+ ## 5.0.0 / 2021-01-19
6
25
  ### Changed
7
26
  * Changed the values of registry to use registry name rather than codes and added new supra-region options (#54)
8
27
 
data/README.md CHANGED
@@ -50,7 +50,7 @@ would output:
50
50
  and booking at hospital RGT01 and delivery at addenbrookes trust
51
51
  The parser is case insensitive. An example of an almost fully involved CANQL query is:
52
52
 
53
- > First 27 Male Liveborn Thames Primary Cases Due between 20/06/2015 and 25/06/2015 and Born on 22/06/2015 and that Died on 07/07/2015 with Suspected Prenatal Q20 Anomalies and Booking at hospital RGT01 and Delivery at addenbrookes trust and Postnatal Tests and Missing Postcode and Date of Birth and QA Action and Unprocessed paediatric records and Mother Born between 01/10/1990 and 10/01/1999 and who Died on 01/08/2015 with Populated Postcode and NHS Number
53
+ > First 27 Male Liveborn Thames Primary Cases Due between 20/06/2015 and 25/06/2015 and Born on 22/06/2015 and that Died on 07/07/2015 with Suspected Prenatal Q20 Anomalies and Booking at hospital RGT01 and Delivery at addenbrookes trust and Postnatal Tests and Missing Postcode and Date of Birth and QA Action and Unprocessed paediatric records and hes records and Mother Born between 01/10/1990 and 10/01/1999 and who Died on 01/08/2015 with Populated Postcode and NHS Number
54
54
 
55
55
  Please see the tests for many more examples.
56
56
 
data/code_safety.yml CHANGED
@@ -11,7 +11,7 @@ file safety:
11
11
  ".github/workflows/test.yml":
12
12
  comments:
13
13
  reviewed_by: josh.pencheon
14
- safe_revision: 865fc970554fee9207f8e3cd0247133c6a849b24
14
+ safe_revision: a3f5265f1d20a6dcb8c45ab5f09207ca7d1e255c
15
15
  ".gitignore":
16
16
  comments:
17
17
  reviewed_by: timgentry
@@ -27,7 +27,7 @@ file safety:
27
27
  CHANGELOG.md:
28
28
  comments:
29
29
  reviewed_by: josh.pencheon
30
- safe_revision: f84cb2190f46ee550db796a17455980ab00d3187
30
+ safe_revision: 154d287a89e13c77b34642ffb33eb4c07953aa1b
31
31
  CODE_OF_CONDUCT.md:
32
32
  comments:
33
33
  reviewed_by: drewthorp
@@ -43,7 +43,7 @@ file safety:
43
43
  README.md:
44
44
  comments:
45
45
  reviewed_by: josh.pencheon
46
- safe_revision: 8c07968aa84db92b6f1cc528180f73530ddc6ff5
46
+ safe_revision: 3ace8794c1c545b47898da1fbee49af8afdbf521
47
47
  Rakefile:
48
48
  comments:
49
49
  reviewed_by: timgentry
@@ -71,7 +71,7 @@ file safety:
71
71
  lib/canql/grammars.rb:
72
72
  comments:
73
73
  reviewed_by: josh.pencheon
74
- safe_revision: c5f8f76b2c335a8554f39a14d6165bf5cd8f9b67
74
+ safe_revision: 3ace8794c1c545b47898da1fbee49af8afdbf521
75
75
  lib/canql/grammars/age.treetop:
76
76
  comments: It is a known issue that this is potentially susceptible to certain
77
77
  kinds of DoS attack
@@ -80,8 +80,8 @@ file safety:
80
80
  lib/canql/grammars/anomaly.treetop:
81
81
  comments: It is a known issue that this is potentially susceptible to certain
82
82
  kinds of DoS attack
83
- reviewed_by: josh.pencheon
84
- safe_revision: b7778ca1d536022a807420cc9fe0f1c2df7f73ef
83
+ reviewed_by: ollietulloch
84
+ safe_revision: b0b092613c94a8c2f04191dbe2a1a347c8e14d16
85
85
  lib/canql/grammars/batch_types.treetop:
86
86
  comments:
87
87
  reviewed_by: josh.pencheon
@@ -99,16 +99,20 @@ file safety:
99
99
  comments:
100
100
  reviewed_by: josh.pencheon
101
101
  safe_revision: 526dbe8a3dc3334b4174928e6f51d07e48ed9247
102
+ lib/canql/grammars/hes_event.treetop:
103
+ comments:
104
+ reviewed_by: josh.pencheon
105
+ safe_revision: 3ace8794c1c545b47898da1fbee49af8afdbf521
102
106
  lib/canql/grammars/main.treetop:
103
107
  comments: It is a known issue that this is potentially susceptible to certain
104
108
  kinds of DoS attack
105
109
  reviewed_by: josh.pencheon
106
- safe_revision: 42bb9bd177a761b9d04d728e53fcf0ebd0083ae4
110
+ safe_revision: 3ace8794c1c545b47898da1fbee49af8afdbf521
107
111
  lib/canql/grammars/patient.treetop:
108
112
  comments: It is a known issue that this is potentially susceptible to certain
109
113
  kinds of DoS attack
110
- reviewed_by: josh.pencheon
111
- safe_revision: 7490099869e368dcd5c26ded11eb90229baf4cae
114
+ reviewed_by: ollietulloch
115
+ safe_revision: 481194575c30b48987f957a9cc5535d604ea0117
112
116
  lib/canql/grammars/perinatal_hospital.treetop:
113
117
  comments:
114
118
  reviewed_by: josh.pencheon
@@ -130,19 +134,19 @@ file safety:
130
134
  lib/canql/grammars/test_result_group.treetop:
131
135
  comments:
132
136
  reviewed_by: josh.pencheon
133
- safe_revision: 8ea906ca663b98edee2592fc5b0731881573f06b
137
+ safe_revision: 9bb663b220e76e78f3f0f48e4bc6334fe9451925
134
138
  lib/canql/nodes.rb:
135
139
  comments:
136
140
  reviewed_by: josh.pencheon
137
- safe_revision: c5f8f76b2c335a8554f39a14d6165bf5cd8f9b67
141
+ safe_revision: 3ace8794c1c545b47898da1fbee49af8afdbf521
138
142
  lib/canql/nodes/age.rb:
139
143
  comments:
140
144
  reviewed_by: timgentry
141
145
  safe_revision: 6932d590299ad4a9d2ba24b425b158c67142bf74
142
146
  lib/canql/nodes/anomaly.rb:
143
147
  comments:
144
- reviewed_by: josh.pencheon
145
- safe_revision: b7778ca1d536022a807420cc9fe0f1c2df7f73ef
148
+ reviewed_by: ollietulloch
149
+ safe_revision: e549c0dcafdd6004ec279bd256fae8b9964c9629
146
150
  lib/canql/nodes/batch_types.rb:
147
151
  comments:
148
152
  reviewed_by: josh.pencheon
@@ -159,14 +163,18 @@ file safety:
159
163
  comments:
160
164
  reviewed_by: josh.pencheon
161
165
  safe_revision: 526dbe8a3dc3334b4174928e6f51d07e48ed9247
166
+ lib/canql/nodes/hes_event.rb:
167
+ comments:
168
+ reviewed_by: josh.pencheon
169
+ safe_revision: 3ace8794c1c545b47898da1fbee49af8afdbf521
162
170
  lib/canql/nodes/main.rb:
163
171
  comments:
164
172
  reviewed_by: josh.pencheon
165
- safe_revision: c5f8f76b2c335a8554f39a14d6165bf5cd8f9b67
173
+ safe_revision: 3ace8794c1c545b47898da1fbee49af8afdbf521
166
174
  lib/canql/nodes/patient.rb:
167
175
  comments:
168
- reviewed_by: josh.pencheon
169
- safe_revision: 7490099869e368dcd5c26ded11eb90229baf4cae
176
+ reviewed_by: ollietulloch
177
+ safe_revision: 481194575c30b48987f957a9cc5535d604ea0117
170
178
  lib/canql/nodes/perinatal_hospital.rb:
171
179
  comments:
172
180
  reviewed_by: josh.pencheon
@@ -182,7 +190,7 @@ file safety:
182
190
  lib/canql/nodes/test_result_group.rb:
183
191
  comments:
184
192
  reviewed_by: josh.pencheon
185
- safe_revision: 42bb9bd177a761b9d04d728e53fcf0ebd0083ae4
193
+ safe_revision: 9bb663b220e76e78f3f0f48e4bc6334fe9451925
186
194
  lib/canql/parser.rb:
187
195
  comments:
188
196
  reviewed_by: timgentry
@@ -194,23 +202,27 @@ file safety:
194
202
  lib/canql/version.rb:
195
203
  comments:
196
204
  reviewed_by: josh.pencheon
197
- safe_revision: cfe2f76a07880e268e1f29fbac5f6cd380202ce3
205
+ safe_revision: 154d287a89e13c77b34642ffb33eb4c07953aa1b
198
206
  test/anomaly_test_helper.rb:
199
207
  comments:
200
- reviewed_by: josh.pencheon
201
- safe_revision: 73a7dac17b20fcc77bcbd9d38777c8aa4d524816
208
+ reviewed_by: ollietulloch
209
+ safe_revision: e549c0dcafdd6004ec279bd256fae8b9964c9629
202
210
  test/canql_test.rb:
203
211
  comments:
204
212
  reviewed_by: timgentry
205
213
  safe_revision: 6932d590299ad4a9d2ba24b425b158c67142bf74
214
+ test/hes_event_test_helper.rb:
215
+ comments:
216
+ reviewed_by: josh.pencheon
217
+ safe_revision: 3ace8794c1c545b47898da1fbee49af8afdbf521
206
218
  test/minitest_helper.rb:
207
219
  comments:
208
220
  reviewed_by: timgentry
209
221
  safe_revision: 6932d590299ad4a9d2ba24b425b158c67142bf74
210
222
  test/nodes/anomaly_test.rb:
211
223
  comments:
212
- reviewed_by: josh.pencheon
213
- safe_revision: 511e4238f83eb5b32839c25d94ec2a59145539bb
224
+ reviewed_by: ollietulloch
225
+ safe_revision: b0b092613c94a8c2f04191dbe2a1a347c8e14d16
214
226
  test/nodes/case_age_test.rb:
215
227
  comments:
216
228
  reviewed_by: josh.pencheon
@@ -221,8 +233,8 @@ file safety:
221
233
  safe_revision: 7490099869e368dcd5c26ded11eb90229baf4cae
222
234
  test/nodes/code_test.rb:
223
235
  comments:
224
- reviewed_by: josh.pencheon
225
- safe_revision: b7778ca1d536022a807420cc9fe0f1c2df7f73ef
236
+ reviewed_by: ollietulloch
237
+ safe_revision: e549c0dcafdd6004ec279bd256fae8b9964c9629
226
238
  test/nodes/e_base_records_test.rb:
227
239
  comments:
228
240
  reviewed_by: josh.pencheon
@@ -231,6 +243,10 @@ file safety:
231
243
  comments:
232
244
  reviewed_by: josh.pencheon
233
245
  safe_revision: 511e4238f83eb5b32839c25d94ec2a59145539bb
246
+ test/nodes/hes_event_test.rb:
247
+ comments:
248
+ reviewed_by: josh.pencheon
249
+ safe_revision: 3ace8794c1c545b47898da1fbee49af8afdbf521
234
250
  test/nodes/main_case_test.rb:
235
251
  comments:
236
252
  reviewed_by: josh.pencheon
@@ -249,8 +265,8 @@ file safety:
249
265
  safe_revision: 511e4238f83eb5b32839c25d94ec2a59145539bb
250
266
  test/nodes/patient_test.rb:
251
267
  comments:
252
- reviewed_by: josh.pencheon
253
- safe_revision: 43425805d9ad4a99e63eeb5d50495fa14eaa053b
268
+ reviewed_by: ollietulloch
269
+ safe_revision: 481194575c30b48987f957a9cc5535d604ea0117
254
270
  test/nodes/perinatal_hospital_test.rb:
255
271
  comments:
256
272
  reviewed_by: josh.pencheon
@@ -262,7 +278,7 @@ file safety:
262
278
  test/nodes/test_result_groups_test.rb:
263
279
  comments:
264
280
  reviewed_by: josh.pencheon
265
- safe_revision: 8ea906ca663b98edee2592fc5b0731881573f06b
281
+ safe_revision: 9bb663b220e76e78f3f0f48e4bc6334fe9451925
266
282
  test/nodes/test_results_test.rb:
267
283
  comments:
268
284
  reviewed_by: josh.pencheon
@@ -270,7 +286,7 @@ file safety:
270
286
  test/parser_test.rb:
271
287
  comments:
272
288
  reviewed_by: josh.pencheon
273
- safe_revision: 293248a17d087d7557a6aacdcb5bf3fbec946b87
289
+ safe_revision: 3ace8794c1c545b47898da1fbee49af8afdbf521
274
290
  test/test_helper.rb:
275
291
  comments:
276
292
  reviewed_by: josh.pencheon
@@ -14,4 +14,5 @@ Treetop.load File.expand_path('grammars/patient', File.dirname(__FILE__))
14
14
  Treetop.load File.expand_path('grammars/registry', File.dirname(__FILE__))
15
15
  Treetop.load File.expand_path('grammars/provider', File.dirname(__FILE__))
16
16
  Treetop.load File.expand_path('grammars/perinatal_hospital', File.dirname(__FILE__))
17
+ Treetop.load File.expand_path('grammars/hes_event', File.dirname(__FILE__))
17
18
  Treetop.load File.expand_path('grammars/main', File.dirname(__FILE__))
@@ -23,7 +23,7 @@ module Canql
23
23
  'ics' / 'ineligible unbooked' / 'inb' / 'early detected' / 'ied' /
24
24
  'screen declined' / 'sd' / 'ineligible early loss' / 'iefl' / 'ineligible top' /
25
25
  'itop' / 'missed screen' / 'ms' / 'excluded' / 'exc' / 'detected' /
26
- 'undetected' / 'ineligible') word_break
26
+ 'undetected' / 'ineligible' / 'pending data') word_break
27
27
  end
28
28
 
29
29
  rule anomalies_keyword
@@ -35,7 +35,7 @@ module Canql
35
35
  end
36
36
 
37
37
  rule anomalies_icd_code
38
- (icd_code_name / code_group)
38
+ (fasp_rating / icd_code_name / code_group)
39
39
  end
40
40
 
41
41
  rule icd_code_name
@@ -45,5 +45,9 @@ module Canql
45
45
  rule code_group
46
46
  ('fasp plus' / 'plus' / 'fasp' / 'structural' / 'trisomy') <Nodes::Anomaly::SingleCodeGroupNode>
47
47
  end
48
+
49
+ rule fasp_rating
50
+ ('fasp red and amber' / 'fasp amber and red' / 'fasp red' / 'fasp amber' / 'fasp green') <Nodes::Anomaly::SingleFaspRatingNode>
51
+ end
48
52
  end
49
53
  end
@@ -0,0 +1,15 @@
1
+ module Canql
2
+ grammar HesEvent
3
+ rule hes_events
4
+ and_keyword? existance_modifier:hes_no_keyword? hes_keyword <Nodes::HesEvent::WithCondition>
5
+ end
6
+
7
+ rule hes_no_keyword
8
+ space ('no' / 'some') word_break
9
+ end
10
+
11
+ rule hes_keyword
12
+ space ('hes events' / 'hes records') word_break
13
+ end
14
+ end
15
+ end
@@ -6,6 +6,7 @@ grammar Canql
6
6
  include GeneticTest
7
7
  include TestResult
8
8
  include TestResultGroup
9
+ include HesEvent
9
10
  include Dates
10
11
  include EBaseRecords
11
12
  include BatchTypes
@@ -129,11 +130,12 @@ grammar Canql
129
130
 
130
131
  rule case_with_conditions
131
132
  anomalies / genetic_tests / test_results / perinatal_hospital /
132
- case_field_existance / test_result_groups / mother_conditions /
133
- action_or_ebr
133
+ case_field_existance / test_acceptance_existance / test_result_groups /
134
+ mother_conditions / action_or_ebr / hes_events
134
135
  end
135
136
 
136
137
  rule patient_with_conditions
137
- anomalies / genetic_tests / test_results / patient_field_existance / action_or_ebr
138
+ anomalies / genetic_tests / test_results / patient_field_existance /
139
+ action_or_ebr / hes_events
138
140
  end
139
141
  end
@@ -13,7 +13,12 @@ module Canql
13
13
  end
14
14
 
15
15
  rule category
16
- space category:('eurocat amber and green' / 'eurocat red and amber' / 'eurocat red' / 'eurocat amber' / 'eurocat green' / 'eurocat') word_break <Nodes::Patient::CategoryNode>
16
+ space category:('eurocat amber and green' /
17
+ 'eurocat red and amber' / 'eurocat red' / 'eurocat amber' /
18
+ 'eurocat green' / 'eurocat' /
19
+ 'fasp red and amber' / 'fasp amber and red' / 'fasp red' /
20
+ 'fasp amber' / 'fasp green' / 'fasp excluded'
21
+ ) word_break <Nodes::Patient::CategoryNode>
17
22
  end
18
23
 
19
24
  rule expected_keyword
@@ -12,5 +12,17 @@ module Canql
12
12
  rule test_result_group_names
13
13
  space ('screening' / 'anomaly scan' / 'fetal medicine' / 'dating') word_break
14
14
  end
15
+
16
+ rule test_acceptance_existance
17
+ and_keyword? existance_modifier:test_acceptance_existance_keyword acceptance:test_acceptance_names <Nodes::TestAcceptanceExistamce::WithCondition>
18
+ end
19
+
20
+ rule test_acceptance_existance_keyword
21
+ space ('missing required' / 'missing' ) word_break
22
+ end
23
+
24
+ rule test_acceptance_names
25
+ space ('screening acceptance status' / 'anomaly scan acceptance status' ) word_break
26
+ end
15
27
  end
16
28
  end
data/lib/canql/nodes.rb CHANGED
@@ -22,3 +22,4 @@ require 'canql/nodes/patient'
22
22
  require 'canql/nodes/main'
23
23
  require 'canql/nodes/registry'
24
24
  require 'canql/nodes/perinatal_hospital'
25
+ require 'canql/nodes/hes_event'
@@ -23,13 +23,21 @@ module Canql #:nodoc: all
23
23
  if anomaly_screening_status_type.present?
24
24
  anomaly_hash['screening_status'] = anomaly_screening_status_type_filter
25
25
  end
26
- anomaly_hash['icd_codes'] = code_filter[:icd_code] if code_filter[:icd_code].present?
27
- return anomaly_hash if code_filter[:code_group].blank?
26
+ code_filters(anomaly_hash)
28
27
 
29
- anomaly_hash['code_groups'] = code_filter[:code_group]
30
28
  anomaly_hash
31
29
  end
32
30
 
31
+ def code_filters(anomaly_hash)
32
+ anomaly_hash['icd_codes'] = code_filter[:icd_code] if code_filter[:icd_code].present?
33
+ if code_filter[:code_group].present?
34
+ anomaly_hash['code_groups'] = code_filter[:code_group]
35
+ end
36
+ return if code_filter[:fasp_rating].blank?
37
+
38
+ anomaly_hash['fasp_rating'] = code_filter[:fasp_rating]
39
+ end
40
+
33
41
  def existance_filter
34
42
  { Canql::EQUALS => existance_modifier.text_value.strip != 'no' }
35
43
  end
@@ -49,36 +57,50 @@ module Canql #:nodoc: all
49
57
  def code_type(code)
50
58
  return :icd_code if code.respond_to?(:to_code) && code.to_code.present?
51
59
  return :code_group if code.respond_to?(:to_code_group) && code.to_code_group.present?
60
+ return :fasp_rating if code.respond_to?(:to_fasp_rating) && code.to_fasp_rating.present?
52
61
 
53
62
  raise 'Unable to find code type'
54
63
  end
55
64
 
56
65
  def code_value(code)
57
66
  return code.to_code if :icd_code == code_type(code)
67
+ return code.to_code_group if :code_group == code_type(code)
58
68
 
59
- code.to_code_group
69
+ code.to_fasp_rating
60
70
  end
61
71
 
62
72
  def prepare_code_filters(code_array)
63
- code_array[:icd_code].flatten!
64
- code_array[:icd_code].delete_if(&:blank?)
65
- code_array[:code_group].flatten!
66
- code_array[:code_group].delete_if(&:blank?)
73
+ clean_code_array(code_array)
67
74
 
68
75
  code_filters = {}
69
76
  if code_array[:icd_code].any?
70
77
  code_filters[:icd_code] = { Canql::BEGINS => code_array[:icd_code] }
71
78
  end
72
- return code_filters if code_array[:code_group].blank?
73
79
 
74
- code_filters[:code_group] = { Canql::EQUALS => code_array[:code_group] }
80
+ if code_array[:code_group].any?
81
+ code_filters[:code_group] = { Canql::EQUALS => code_array[:code_group] }
82
+ end
83
+
84
+ if code_array[:fasp_rating].any?
85
+ code_filters[:fasp_rating] = { Canql::EQUALS => code_array[:fasp_rating] }
86
+ end
87
+
75
88
  code_filters
76
89
  end
77
90
 
91
+ def clean_code_array(code_array)
92
+ code_array[:icd_code].flatten!
93
+ code_array[:icd_code].delete_if(&:blank?)
94
+ code_array[:code_group].flatten!
95
+ code_array[:code_group].delete_if(&:blank?)
96
+ code_array[:fasp_rating].flatten!
97
+ code_array[:fasp_rating].delete_if(&:blank?)
98
+ end
99
+
78
100
  def code_filter
79
101
  return {} if code_data.text_value.blank?
80
102
 
81
- code_arrays = { icd_code: [], code_group: [] }
103
+ code_arrays = { icd_code: [], code_group: [], fasp_rating: [] }
82
104
  code_arrays[code_type(code_data.first)] << code_value(code_data.first)
83
105
  code_data.rest.elements.each do |code|
84
106
  code_arrays[code_type(code)] << code_value(code)
@@ -90,8 +112,9 @@ module Canql #:nodoc: all
90
112
  module AdditionalCodeNode
91
113
  def code_type
92
114
  return :icd_code if anomalies_icd_code.respond_to?(:to_code)
115
+ return :code_group if anomalies_icd_code.respond_to?(:to_code_group)
93
116
 
94
- :code_group
117
+ :fasp_rating
95
118
  end
96
119
 
97
120
  def to_code
@@ -101,6 +124,10 @@ module Canql #:nodoc: all
101
124
  def to_code_group
102
125
  anomalies_icd_code.to_code_group if :code_group == code_type
103
126
  end
127
+
128
+ def to_fasp_rating
129
+ anomalies_icd_code.to_fasp_rating if :fasp_rating == code_type
130
+ end
104
131
  end
105
132
 
106
133
  module SingleIcdCodeNode
@@ -114,6 +141,14 @@ module Canql #:nodoc: all
114
141
  text_value.gsub(/( )/, '_').upcase
115
142
  end
116
143
  end
144
+
145
+ module SingleFaspRatingNode
146
+ def to_fasp_rating
147
+ text_value.gsub(/( )/, '_').upcase.split('_AND_').map do |value|
148
+ value.start_with?('FASP_') ? value : "FASP_#{value}"
149
+ end
150
+ end
151
+ end
117
152
  end
118
153
  end
119
154
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Canql #:nodoc: all
4
+ module Nodes
5
+ module HesEvent
6
+ module WithCondition
7
+ def to_hes
8
+ { 'exists' => existance_filter }
9
+ end
10
+
11
+ def existance_filter
12
+ { Canql::EQUALS => existance_modifier.text_value.strip != 'no' }
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -29,27 +29,39 @@ module Canql #:nodoc: all
29
29
  module WithConditions
30
30
  def meta_data_item
31
31
  conditions = {}
32
- anomalies = []
33
- genetic_tests = []
34
- test_results = []
35
- test_result_groups = []
32
+ sub_clauses = build_sub_clauses
36
33
 
37
- post.elements.each do |element|
38
- anomalies << element.to_anomaly if element.respond_to?(:to_anomaly)
39
- genetic_tests << element.to_genetic_test if element.respond_to?(:to_genetic_test)
40
- test_results << element.to_test_result if element.respond_to?(:to_test_result)
41
- if element.respond_to?(:to_test_result_group)
42
- test_result_groups << element.to_test_result_group
34
+ %i[
35
+ anomalies genetic_tests test_results test_result_groups test_acceptances hes_events
36
+ ].each do |condition_key|
37
+ if sub_clauses[condition_key].present?
38
+ conditions[condition_key.to_s] = { Canql::ALL => sub_clauses[condition_key] }
43
39
  end
44
40
  end
41
+ conditions
42
+ end
45
43
 
46
- conditions['anomalies'] = { Canql::ALL => anomalies } if anomalies.any?
47
- conditions['genetic_tests'] = { Canql::ALL => genetic_tests } if genetic_tests.any?
48
- conditions['test_results'] = { Canql::ALL => test_results } if test_results.any?
49
- if test_result_groups.any?
50
- conditions['test_result_groups'] = { Canql::ALL => test_result_groups }
44
+ def build_sub_clauses
45
+ sub_clauses = {}
46
+
47
+ post.elements.each do |element|
48
+ add_sub_clause(sub_clauses, element, :anomalies, :to_anomaly)
49
+ add_sub_clause(sub_clauses, element, :genetic_tests, :to_genetic_test)
50
+ add_sub_clause(sub_clauses, element, :test_results, :to_test_result)
51
+ add_sub_clause(
52
+ sub_clauses, element, :test_result_groups, :to_test_result_group
53
+ )
54
+ add_sub_clause(sub_clauses, element, :test_acceptances, :to_test_acceptance)
55
+ add_sub_clause(sub_clauses, element, :hes_events, :to_hes)
51
56
  end
52
- conditions
57
+ sub_clauses
58
+ end
59
+
60
+ def add_sub_clause(sub_clauses, element, key, condition)
61
+ return sub_clauses unless element.respond_to?(condition)
62
+
63
+ sub_clauses[key] ||= []
64
+ sub_clauses[key] << element.send(condition)
53
65
  end
54
66
  end
55
67
  end
@@ -27,11 +27,11 @@ module Canql #:nodoc: all
27
27
  end
28
28
 
29
29
  def clean_category
30
- return 'eurocat_red' if 'eurocat red' == category.text_value
31
- return 'eurocat_amber' if 'eurocat amber' == category.text_value
32
- return 'eurocat_green' if 'eurocat green' == category.text_value
33
- return 'eurocat_amber_green' if 'eurocat amber and green' == category.text_value
34
- return 'eurocat_red_amber' if 'eurocat red and amber' == category.text_value
30
+ if category.text_value.start_with?('eurocat ') || category.text_value.start_with?('fasp ')
31
+ filter_value = category.text_value.gsub(/( )/, '_').downcase.gsub(/(_and_)/, '_')
32
+ filter_value = 'fasp_red_amber' if filter_value == 'fasp_amber_red'
33
+ return filter_value
34
+ end
35
35
 
36
36
  category.text_value
37
37
  end
@@ -36,5 +36,40 @@ module Canql #:nodoc: all
36
36
  end
37
37
  end
38
38
  end
39
+
40
+ module TestAcceptanceExistamce
41
+ module WithCondition
42
+ def test_acceptance
43
+ acceptance.text_value.strip.parameterize.underscore
44
+ end
45
+
46
+ def to_test_acceptance
47
+ test_acceptance_hash = { 'exists' => existance_filter }
48
+ test_acceptance_hash['required'] = requirement_filter
49
+ test_acceptance_hash['acceptance'] = test_acceptance_filter if test_acceptance.present?
50
+ test_acceptance_hash
51
+ end
52
+
53
+ def existance_filter
54
+ {
55
+ Canql::EQUALS => ['supplied required', 'supplied'].include?(
56
+ existance_modifier.text_value.strip
57
+ )
58
+ }
59
+ end
60
+
61
+ def requirement_filter
62
+ {
63
+ Canql::EQUALS => ['supplied required', 'missing required'].include?(
64
+ existance_modifier.text_value.strip
65
+ )
66
+ }
67
+ end
68
+
69
+ def test_acceptance_filter
70
+ { Canql::EQUALS => test_acceptance }
71
+ end
72
+ end
73
+ end
39
74
  end
40
75
  end
data/lib/canql/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  # This stores the current version of the Canql gem
4
4
  module Canql
5
- VERSION = '5.0.0'
5
+ VERSION = '5.5.0'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canql
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - PHE NDR Development Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-19 00:00:00.000000000 Z
11
+ date: 2021-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chronic
@@ -235,6 +235,7 @@ files:
235
235
  - lib/canql/grammars/dates.treetop
236
236
  - lib/canql/grammars/e_base_records.treetop
237
237
  - lib/canql/grammars/genetic_test.treetop
238
+ - lib/canql/grammars/hes_event.treetop
238
239
  - lib/canql/grammars/main.treetop
239
240
  - lib/canql/grammars/patient.treetop
240
241
  - lib/canql/grammars/perinatal_hospital.treetop
@@ -249,6 +250,7 @@ files:
249
250
  - lib/canql/nodes/dates.rb
250
251
  - lib/canql/nodes/e_base_records.rb
251
252
  - lib/canql/nodes/genetic_test.rb
253
+ - lib/canql/nodes/hes_event.rb
252
254
  - lib/canql/nodes/main.rb
253
255
  - lib/canql/nodes/patient.rb
254
256
  - lib/canql/nodes/perinatal_hospital.rb