quby-compiler 0.4.8 → 0.4.11

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: 886ce60c1b1c37de0dfdbb8d0b14b4c2ed2574f873a2230ff50e80413e50c031
4
- data.tar.gz: ee12f0733d624ffea8061b4f9f7bcbcdea9c904eb05d9b1e426b9f646bae91da
3
+ metadata.gz: 8b2f73a073de0f20b5dfd57b8e8c3b65c1878abce2cb109e67fe1cc302900b02
4
+ data.tar.gz: fec490f89c77a497fbac304a381e150aec1fc8e8e4e06950aff20424561fb69c
5
5
  SHA512:
6
- metadata.gz: d24325dcee35fafd2d99d65bc6761eb7fa764efe2c5b549208e5130b3b0218bdc2dbf9e932886f1f05a8ac9461236dd398e9d8d733a4a715c2a62fddeb768da0
7
- data.tar.gz: 0d45e85ea11b5c03710011aff584bf6df363f140184519e6a5c374651e516599a7667921560b41d3870b4c3ef98a55cfc097550aba39199f4be233001453e0fc
6
+ metadata.gz: 70bbcf09fa8b4d789ec22eaebb06b46a10bbdfcf5a5125f205f26307cceb471aef5c1e5e30a5b7ea510f64a304a59e21a40c64b3c40dde6935f291f04237e6de
7
+ data.tar.gz: 887f84082878e3a49dda34d8c92f62db3849e5ee716e0a69f9d1b92c1543cc1a3fe21fd65c5603c7703ce4168404dab75fc191f4999bd0aeeb032137d41e50e4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ # 0.4.11
2
+
3
+ * roqua.json: Baseline for a chart now always exports as a hash of gender/age => value
4
+
5
+ # 0.4.10
6
+
7
+ * quby2.json: Fix validations json (regex-serialization and key-capitalization)
8
+ * roqua.json: Change questions, options, date_parts, scores, subscores and outcome_tables from hash to array, since ordering is important and not all systems preserve the order of hashes (like pg's jsonb)
9
+
10
+ # 0.4.9
11
+
12
+ * roqua.json: Fix html stripping for string with no whitespace
13
+
1
14
  # 0.4.8
2
15
 
3
16
  * roqua.json:
@@ -209,7 +209,6 @@ module Quby
209
209
  fields: fields.as_json,
210
210
  flags: flags,
211
211
  textvars: textvars,
212
- validations: validations,
213
212
  visibilityRules: visibility_rules
214
213
  }
215
214
  end
@@ -6,10 +6,23 @@ module Quby
6
6
  @questionnaire = questionnaire
7
7
  end
8
8
 
9
+ # TODO: Move all attributes here from Questionnaire#as_json
9
10
  def as_json(options = {})
10
- @questionnaire.as_json
11
+ @questionnaire.as_json.merge \
12
+ validations: validations
13
+ end
14
+
15
+ def validations
16
+ @questionnaire.validations.map do |validation|
17
+ validation.config.compact
18
+ .transform_keys{ _1.to_s.camelize(:lower) }
19
+ .tap do |validation_hsh|
20
+ # otherwise ruby will put a (?-mix around the regex, which js errors on.
21
+ validation_hsh['matcher'] = validation_hsh['matcher'].source.to_s if validation_hsh['matcher']
22
+ end.as_json
23
+ end
11
24
  end
12
25
  end
13
26
  end
14
27
  end
15
- end
28
+ end
@@ -60,9 +60,8 @@ module Quby
60
60
  case chart
61
61
  when Quby::Compiler::Entities::Charting::LineChart
62
62
  {
63
- y_label: chart.y_label,
64
63
  tonality: chart.tonality,
65
- baseline: YAML.dump(chart.baseline),
64
+ baseline: chart_baseline(chart.baseline),
66
65
  clinically_relevant_change: chart.clinically_relevant_change,
67
66
  }
68
67
  when Quby::Compiler::Entities::Charting::OverviewChart
@@ -89,6 +88,17 @@ module Quby
89
88
  }
90
89
  end
91
90
 
91
+ def chart_baseline(baseline)
92
+ case baseline
93
+ when nil
94
+ nil
95
+ when Float, Integer
96
+ {default: {default: baseline}}
97
+ when Hash
98
+ baseline
99
+ end
100
+ end
101
+
92
102
  # configuration for outcome tables.
93
103
  # tables:
94
104
  # <outcome_table_name:Symbol>: # each entry is a table.
@@ -107,15 +117,18 @@ module Quby
107
117
 
108
118
  def outcome_tables_from_definition
109
119
  # hash of tables, with the score keys (rows) and subscore keys (columns) used for each
110
- tables = {}
120
+ tables = []
111
121
  # hash of `subscore_key: subscore_label` pairs used in tables
112
122
  headers = {}
113
123
 
114
124
  questionnaire.outcome_tables.each do |table|
115
- tables[table.key] = {name: table.name,
116
- default_collapsed: table.default_collapsed,
117
- score_keys: table.score_keys,
118
- subscore_keys: table.subscore_keys}.compact
125
+ tables << {
126
+ key: table.key,
127
+ name: table.name,
128
+ default_collapsed: table.default_collapsed,
129
+ score_keys: table.score_keys,
130
+ subscore_keys: table.subscore_keys
131
+ }.compact
119
132
 
120
133
  table.subscore_keys.each do |subscore_key|
121
134
  table.score_keys.find do |score_key|
@@ -142,6 +155,7 @@ module Quby
142
155
  questionnaire.score_schemas.values.each do |schema|
143
156
  schema.subscore_schemas.each do |subschema|
144
157
  next if subschema.outcome_table.blank?
158
+ tables[subschema.outcome_table][:key] = subschema.outcome_table
145
159
  tables[subschema.outcome_table][:subscore_keys] << subschema.key
146
160
  tables[subschema.outcome_table][:score_keys] << schema.key
147
161
  headers[subschema.key] = subschema.label
@@ -150,7 +164,7 @@ module Quby
150
164
 
151
165
  {
152
166
  headers: headers,
153
- tables: tables,
167
+ tables: tables.values,
154
168
  }
155
169
  end
156
170
 
@@ -170,25 +184,22 @@ module Quby
170
184
  # date_parts [nil/{..}]
171
185
  # options: [nil/{..}]
172
186
  def questions
173
- questionnaire.sorted_questions.reject{_1.type == :hidden}.to_h { |question|
174
- [
175
- question.key,
176
- {
177
- key: question.key,
178
- sbg_key: question.sbg_key,
179
- type: QUBY_TYPE_TO_ROQUA_TYPE.fetch(question.type),
180
- title: parse_markdown_and_strip_tags(question.title),
181
- context_free_title: question.context_free_title,
182
- unit: question.unit,
183
- deprecated: question.hidden.presence,
184
- default_invisible: question.default_invisible.presence,
185
- parent_question_key: question.parent&.key,
186
- parent_option_key: question.parent_option_key,
187
- title_question_key: question.title_question&.key,
188
- date_parts: date_parts_for(question),
189
- options: options_for(question)
190
- }.compact
191
- ]
187
+ questionnaire.sorted_questions.reject{_1.type == :hidden}.map { |question|
188
+ {
189
+ key: question.key,
190
+ sbg_key: question.sbg_key,
191
+ type: QUBY_TYPE_TO_ROQUA_TYPE.fetch(question.type),
192
+ title: parse_markdown_and_strip_tags(question.title),
193
+ context_free_title: question.context_free_title,
194
+ unit: question.unit,
195
+ deprecated: question.hidden.presence,
196
+ default_invisible: question.default_invisible.presence,
197
+ parent_question_key: question.parent&.key,
198
+ parent_option_key: question.parent_option_key,
199
+ title_question_key: question.title_question&.key,
200
+ date_parts: date_parts_for(question),
201
+ options: options_for(question)
202
+ }.compact
192
203
  }
193
204
  end
194
205
 
@@ -197,13 +208,11 @@ module Quby
197
208
  def date_parts_for(question)
198
209
  return nil unless question.type == :date
199
210
 
200
- question.components.to_h { |component|
201
- [
202
- component,
203
- {
204
- key: question.send("#{component}_key")
205
- }
206
- ]
211
+ question.components.map { |component|
212
+ {
213
+ part: component,
214
+ key: question.send("#{component}_key")
215
+ }
207
216
  }
208
217
  end
209
218
 
@@ -216,22 +225,19 @@ module Quby
216
225
  return nil if question.options.empty?
217
226
 
218
227
  question.options.reject { |option| option.inner_title || option.placeholder }
219
- .to_h { |option|
220
- [
221
- option.key,
222
- {
223
- key: option.key,
224
- value: (option.value.to_s unless question.type == :check_box),
225
- description: option.context_free_description || parse_markdown_and_strip_tags(option.description),
226
- child_question_keys: option.questions.map(&:key).presence
227
- }.compact
228
- ]
228
+ .map { |option|
229
+ {
230
+ key: option.key,
231
+ value: (option.value.to_s unless question.type == :check_box),
232
+ description: option.context_free_description || parse_markdown_and_strip_tags(option.description),
233
+ child_question_keys: option.questions.map(&:key).presence
234
+ }.compact
229
235
  }
230
236
  end
231
237
 
232
238
  # [{ key: { .., subscores: { subkey: {..} } } }]
233
239
  def scores
234
- questionnaire.score_schemas.transform_values { |score|
240
+ questionnaire.score_schemas.values.map { |score|
235
241
  {
236
242
  key: score.key,
237
243
  label: score.label,
@@ -242,16 +248,13 @@ module Quby
242
248
 
243
249
  # { subkey: {..} }
244
250
  def subscores_for(score)
245
- score.subscore_schemas.to_h { |subscore|
246
- [
247
- subscore.key,
248
- {
249
- key: subscore.key,
250
- label: subscore.label,
251
- export_key: subscore.export_key,
252
- only_for_export: subscore.only_for_export.presence
253
- }.compact
254
- ]
251
+ score.subscore_schemas.map { |subscore|
252
+ {
253
+ key: subscore.key,
254
+ label: subscore.label,
255
+ export_key: subscore.export_key,
256
+ only_for_export: subscore.only_for_export.presence
257
+ }.compact
255
258
  }
256
259
  end
257
260
 
@@ -264,7 +267,7 @@ module Quby
264
267
  doc.css('br, hr, img').each { |node| node.replace(' ') }
265
268
  end \
266
269
  .text
267
- .gsub!(/\s+/, ' ')
270
+ .gsub(/\s+/, ' ')
268
271
  .presence
269
272
  end
270
273
  end
@@ -137,14 +137,14 @@ module Quby
137
137
  unknown_questions = flag.shows_questions.select { |key| !questionnaire.key_in_use?(key) }
138
138
  return if unknown_questions.blank?
139
139
 
140
- fail ArgumentError, "Flag '#{key}' has unknown shows_questions keys #{unknown_questions}"
140
+ fail ArgumentError, "Flag '#{flag.key}' has unknown shows_questions keys #{unknown_questions}"
141
141
  end
142
142
 
143
143
  def validate_flag_hides(questionnaire, flag)
144
144
  unknown_questions = flag.hides_questions.select { |key| !questionnaire.key_in_use?(key) }
145
145
  return if unknown_questions.blank?
146
146
 
147
- fail ArgumentError, "Flag '#{key}' has unknown hides_questions keys #{unknown_questions}"
147
+ fail ArgumentError, "Flag '#{flag.key}' has unknown hides_questions keys #{unknown_questions}"
148
148
  end
149
149
 
150
150
  def validate_flag_depends_on(questionnaire, flag)
@@ -1,5 +1,5 @@
1
1
  module Quby
2
2
  module Compiler
3
- VERSION = "0.4.8"
3
+ VERSION = "0.4.11"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quby-compiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marten Veldthuis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-16 00:00:00.000000000 Z
11
+ date: 2022-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel