quby-compiler 0.4.9 → 0.4.12

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8adddc572c511a6145f59379fa1c54d49f53fcd3487a3d9a5026fb0634b54c54
4
- data.tar.gz: 5b173fb296fd7a7b88d9d60eb2357117c6f9f80eb1c800a5fe781a427d359efa
3
+ metadata.gz: a9f80c06ecab5163ba31ba68e5548ec4e53211b4d327d738b07947578409afed
4
+ data.tar.gz: a56fa925a142ec55eb909e33257c3f399d8990c79ace266e6ebc7687cefb49cc
5
5
  SHA512:
6
- metadata.gz: 6e23e0347aa449053801f045533b26d10108d8f4a62783a71a121b9cc41215dab348ca3da8e8acf528a58e4689f05219c96237218478c2368acbfcff07c220ce
7
- data.tar.gz: 47e5d45f09c1452db50e29e3933967256b890090991ed715f91003b7622076aafa0adbe0d0f414506b79707187c03bc37c7217c94bad39bfd5f3a2d681dec72d
6
+ metadata.gz: 3aa823181f25722654444f7ad79e8922b59f6cb93463e12e61abef7ead8a391695156fcb4cb8f4551ad115b6a710ab2e5d81138575d7fce05d442db1e86dd809
7
+ data.tar.gz: 89376384e57965c290e667984fd98605668ef2a832a87d78215e6c0435379bd6ce4b4cf994091bcc9975554fb05e7ed3f6bfbf4beab6af13115fb3489cd87a94
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # 0.4.12
2
+
3
+ * roqua.json: Add questionnaire license
4
+ * roqua.json: Add `unchecks_all_others` for radio/checkbox question options
5
+
6
+ # 0.4.11
7
+
8
+ * roqua.json: Baseline for a chart now always exports as a hash of gender/age => value
9
+
10
+ # 0.4.10
11
+
12
+ * quby2.json: Fix validations json (regex-serialization and key-capitalization)
13
+ * 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)
14
+
1
15
  # 0.4.9
2
16
 
3
17
  * roqua.json: Fix html stripping for string with no whitespace
@@ -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
@@ -36,6 +36,8 @@ module Quby
36
36
  outcome_tables_schema: outcome_tables_schema,
37
37
  questions: questions,
38
38
  scores: scores,
39
+ license: questionnaire.license,
40
+ licensor: questionnaire.licensor,
39
41
  }
40
42
  end
41
43
 
@@ -60,9 +62,8 @@ module Quby
60
62
  case chart
61
63
  when Quby::Compiler::Entities::Charting::LineChart
62
64
  {
63
- y_label: chart.y_label,
64
65
  tonality: chart.tonality,
65
- baseline: YAML.dump(chart.baseline),
66
+ baseline: chart_baseline(chart.baseline),
66
67
  clinically_relevant_change: chart.clinically_relevant_change,
67
68
  }
68
69
  when Quby::Compiler::Entities::Charting::OverviewChart
@@ -89,6 +90,17 @@ module Quby
89
90
  }
90
91
  end
91
92
 
93
+ def chart_baseline(baseline)
94
+ case baseline
95
+ when nil
96
+ nil
97
+ when Float, Integer
98
+ {default: {default: baseline}}
99
+ when Hash
100
+ baseline
101
+ end
102
+ end
103
+
92
104
  # configuration for outcome tables.
93
105
  # tables:
94
106
  # <outcome_table_name:Symbol>: # each entry is a table.
@@ -107,15 +119,18 @@ module Quby
107
119
 
108
120
  def outcome_tables_from_definition
109
121
  # hash of tables, with the score keys (rows) and subscore keys (columns) used for each
110
- tables = {}
122
+ tables = []
111
123
  # hash of `subscore_key: subscore_label` pairs used in tables
112
124
  headers = {}
113
125
 
114
126
  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
127
+ tables << {
128
+ key: table.key,
129
+ name: table.name,
130
+ default_collapsed: table.default_collapsed,
131
+ score_keys: table.score_keys,
132
+ subscore_keys: table.subscore_keys
133
+ }.compact
119
134
 
120
135
  table.subscore_keys.each do |subscore_key|
121
136
  table.score_keys.find do |score_key|
@@ -142,6 +157,7 @@ module Quby
142
157
  questionnaire.score_schemas.values.each do |schema|
143
158
  schema.subscore_schemas.each do |subschema|
144
159
  next if subschema.outcome_table.blank?
160
+ tables[subschema.outcome_table][:key] = subschema.outcome_table
145
161
  tables[subschema.outcome_table][:subscore_keys] << subschema.key
146
162
  tables[subschema.outcome_table][:score_keys] << schema.key
147
163
  headers[subschema.key] = subschema.label
@@ -150,7 +166,7 @@ module Quby
150
166
 
151
167
  {
152
168
  headers: headers,
153
- tables: tables,
169
+ tables: tables.values,
154
170
  }
155
171
  end
156
172
 
@@ -170,25 +186,22 @@ module Quby
170
186
  # date_parts [nil/{..}]
171
187
  # options: [nil/{..}]
172
188
  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
- ]
189
+ questionnaire.sorted_questions.reject{_1.type == :hidden}.map { |question|
190
+ {
191
+ key: question.key,
192
+ sbg_key: question.sbg_key,
193
+ type: QUBY_TYPE_TO_ROQUA_TYPE.fetch(question.type),
194
+ title: parse_markdown_and_strip_tags(question.title),
195
+ context_free_title: question.context_free_title,
196
+ unit: question.unit,
197
+ deprecated: question.hidden.presence,
198
+ default_invisible: question.default_invisible.presence,
199
+ parent_question_key: question.parent&.key,
200
+ parent_option_key: question.parent_option_key,
201
+ title_question_key: question.title_question&.key,
202
+ date_parts: date_parts_for(question),
203
+ options: options_for(question)
204
+ }.compact
192
205
  }
193
206
  end
194
207
 
@@ -197,13 +210,11 @@ module Quby
197
210
  def date_parts_for(question)
198
211
  return nil unless question.type == :date
199
212
 
200
- question.components.to_h { |component|
201
- [
202
- component,
203
- {
204
- key: question.send("#{component}_key")
205
- }
206
- ]
213
+ question.components.map { |component|
214
+ {
215
+ part: component,
216
+ key: question.send("#{component}_key")
217
+ }
207
218
  }
208
219
  end
209
220
 
@@ -216,22 +227,20 @@ module Quby
216
227
  return nil if question.options.empty?
217
228
 
218
229
  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
- ]
230
+ .map { |option|
231
+ {
232
+ key: option.key,
233
+ value: (option.value.to_s unless question.type == :check_box),
234
+ description: option.context_free_description || parse_markdown_and_strip_tags(option.description),
235
+ child_question_keys: option.questions.map(&:key).presence,
236
+ unchecks_all_others: question.try(:uncheck_all_option) && question.uncheck_all_option == option.key
237
+ }.compact
229
238
  }
230
239
  end
231
240
 
232
241
  # [{ key: { .., subscores: { subkey: {..} } } }]
233
242
  def scores
234
- questionnaire.score_schemas.transform_values { |score|
243
+ questionnaire.score_schemas.values.map { |score|
235
244
  {
236
245
  key: score.key,
237
246
  label: score.label,
@@ -242,16 +251,13 @@ module Quby
242
251
 
243
252
  # { subkey: {..} }
244
253
  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
- ]
254
+ score.subscore_schemas.map { |subscore|
255
+ {
256
+ key: subscore.key,
257
+ label: subscore.label,
258
+ export_key: subscore.export_key,
259
+ only_for_export: subscore.only_for_export.presence
260
+ }.compact
255
261
  }
256
262
  end
257
263
 
@@ -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.9"
3
+ VERSION = "0.4.12"
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.9
4
+ version: 0.4.12
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-17 00:00:00.000000000 Z
11
+ date: 2022-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel