case-editor-tools 1.0.0-beta.7 → 1.0.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 (99) hide show
  1. package/constants/key-definitions.d.ts +16 -0
  2. package/constants/key-definitions.js +38 -0
  3. package/constants/key-definitions.js.map +1 -0
  4. package/exporter/index.d.ts +2 -0
  5. package/exporter/index.js +128 -0
  6. package/exporter/index.js.map +1 -0
  7. package/expression-utils/expressionGen.d.ts +2 -0
  8. package/expression-utils/expressionGen.js +31 -0
  9. package/expression-utils/expressionGen.js.map +1 -0
  10. package/expression-utils/studyEngineExpressions.d.ts +195 -0
  11. package/expression-utils/studyEngineExpressions.js +479 -0
  12. package/expression-utils/studyEngineExpressions.js.map +1 -0
  13. package/index.d.ts +0 -0
  14. package/index.js +3 -0
  15. package/index.js.map +1 -0
  16. package/item-editor-59f51ecc.js +542 -0
  17. package/item-editor-59f51ecc.js.map +1 -0
  18. package/logger/index.d.ts +1 -0
  19. package/logger/index.js +10 -0
  20. package/logger/index.js.map +1 -0
  21. package/logger/logger.d.ts +9 -0
  22. package/logger/logger.js +31 -0
  23. package/logger/logger.js.map +1 -0
  24. package/package.json +5 -5
  25. package/surveys/index.d.ts +3 -0
  26. package/surveys/index.js +29 -0
  27. package/surveys/index.js.map +1 -0
  28. package/surveys/responseTypeGenerators/likertGroupComponents.d.ts +27 -0
  29. package/surveys/responseTypeGenerators/likertGroupComponents.js +350 -0
  30. package/surveys/responseTypeGenerators/likertGroupComponents.js.map +1 -0
  31. package/surveys/responseTypeGenerators/matrixGroupComponent.d.ts +49 -0
  32. package/surveys/responseTypeGenerators/matrixGroupComponent.js +100 -0
  33. package/surveys/responseTypeGenerators/matrixGroupComponent.js.map +1 -0
  34. package/surveys/responseTypeGenerators/optionGroupComponents.d.ts +7 -0
  35. package/surveys/responseTypeGenerators/optionGroupComponents.js +129 -0
  36. package/surveys/responseTypeGenerators/optionGroupComponents.js.map +1 -0
  37. package/surveys/survey-editor/component-editor.d.ts +84 -0
  38. package/surveys/survey-editor/component-editor.js +112 -0
  39. package/surveys/survey-editor/component-editor.js.map +1 -0
  40. package/surveys/survey-editor/data-types.d.ts +13 -0
  41. package/surveys/survey-editor/data-types.js +3 -0
  42. package/surveys/survey-editor/data-types.js.map +1 -0
  43. package/surveys/survey-editor/item-editor.d.ts +66 -0
  44. package/surveys/survey-editor/item-editor.js +13 -0
  45. package/surveys/survey-editor/item-editor.js.map +1 -0
  46. package/surveys/survey-editor/survey-editor.d.ts +48 -0
  47. package/surveys/survey-editor/survey-editor.js +237 -0
  48. package/surveys/survey-editor/survey-editor.js.map +1 -0
  49. package/surveys/survey-engine-expressions.d.ts +130 -0
  50. package/surveys/survey-engine-expressions.js +448 -0
  51. package/surveys/survey-engine-expressions.js.map +1 -0
  52. package/surveys/survey-items.d.ts +72 -0
  53. package/surveys/survey-items.js +384 -0
  54. package/surveys/survey-items.js.map +1 -0
  55. package/surveys/types/group.d.ts +23 -0
  56. package/surveys/types/group.js +72 -0
  57. package/surveys/types/group.js.map +1 -0
  58. package/surveys/types/index.d.ts +4 -0
  59. package/surveys/types/index.js +22 -0
  60. package/surveys/types/index.js.map +1 -0
  61. package/surveys/types/item-properties.d.ts +223 -0
  62. package/surveys/types/item-properties.js +10 -0
  63. package/surveys/types/item-properties.js.map +1 -0
  64. package/surveys/types/item.d.ts +22 -0
  65. package/surveys/types/item.js +34 -0
  66. package/surveys/types/item.js.map +1 -0
  67. package/surveys/types/survey-definition.d.ts +23 -0
  68. package/surveys/types/survey-definition.js +69 -0
  69. package/surveys/types/survey-definition.js.map +1 -0
  70. package/surveys/utils/componentGenerators.d.ts +24 -0
  71. package/surveys/utils/componentGenerators.js +59 -0
  72. package/surveys/utils/componentGenerators.js.map +1 -0
  73. package/surveys/utils/optionDefGenerators.d.ts +84 -0
  74. package/surveys/utils/optionDefGenerators.js +211 -0
  75. package/surveys/utils/optionDefGenerators.js.map +1 -0
  76. package/surveys/utils/randomKeyGenerator.d.ts +1 -0
  77. package/surveys/utils/randomKeyGenerator.js +16 -0
  78. package/surveys/utils/randomKeyGenerator.js.map +1 -0
  79. package/surveys/utils/simple-generators.d.ts +14 -0
  80. package/surveys/utils/simple-generators.js +131 -0
  81. package/surveys/utils/simple-generators.js.map +1 -0
  82. package/surveys/utils/simple-question-editor.d.ts +14 -0
  83. package/surveys/utils/simple-question-editor.js +47 -0
  84. package/surveys/utils/simple-question-editor.js.map +1 -0
  85. package/types/duration.d.ts +9 -0
  86. package/types/duration.js +29 -0
  87. package/types/duration.js.map +1 -0
  88. package/types/expression.d.ts +4 -0
  89. package/types/expression.js +23 -0
  90. package/types/expression.js.map +1 -0
  91. package/types/messageConfig.d.ts +49 -0
  92. package/types/messageConfig.js +23 -0
  93. package/types/messageConfig.js.map +1 -0
  94. package/types/study.d.ts +15 -0
  95. package/types/study.js +3 -0
  96. package/types/study.js.map +1 -0
  97. package/types/studyRules.d.ts +9 -0
  98. package/types/studyRules.js +36 -0
  99. package/types/studyRules.js.map +1 -0
@@ -0,0 +1,479 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var constants_keyDefinitions = require('../constants/key-definitions.js');
6
+ var types_duration = require('../types/duration.js');
7
+ var expressionUtils_expressionGen = require('./expressionGen.js');
8
+
9
+ const or = (...args) => expressionUtils_expressionGen.generateExpression('or', undefined, ...args);
10
+ const and = (...args) => expressionUtils_expressionGen.generateExpression('and', undefined, ...args);
11
+ const not = (arg) => expressionUtils_expressionGen.generateExpression('not', undefined, arg);
12
+ /**
13
+ * Check if the current event has the given type
14
+ * @param equalsType string with the possible values: 'ENTER', 'SUBMIT', 'TIMER', 'MERGE'
15
+ * @returns if event type matches the argument, return true otherwise false
16
+ */
17
+ const checkEventType = (equalsType) => expressionUtils_expressionGen.generateExpression('checkEventType', undefined, equalsType);
18
+ /**
19
+ * Check if the submitted survey has a specific key
20
+ * @param surveyKey string to check for
21
+ * @returns true, if the survey has the key, false otherwise
22
+ */
23
+ const checkSurveyResponseKey = (surveyKey) => expressionUtils_expressionGen.generateExpression('checkSurveyResponseKey', undefined, surveyKey);
24
+ /**
25
+ * Check survey response item, if any of the defined option keys is present in the given response group
26
+ * @param itemKey full key to the survey item, in the form, e.g., <surveyKey>.<groupKey>.<itemKey>
27
+ * @param responseSlotKey full key to the response group, e.g., 'rg.scg'
28
+ * @param optionKeys list of option keys to be checked for.
29
+ * @returns true if any of the option keys are present in the item's response. If item or the response group is not found, return false.
30
+ */
31
+ const responseHasKeysAny = (itemKey, responseSlotKey, ...optionKeys) => expressionUtils_expressionGen.generateExpression('responseHasKeysAny', undefined, itemKey, responseSlotKey, ...optionKeys);
32
+ /**
33
+ * Check survey response item, if only other keys have been selected
34
+ * @param itemKey full key to the survey item, in the form, e.g., <surveyKey>.<groupKey>.<itemKey>
35
+ * @param responseSlotKey full key to the response group, e.g., 'rg.mcg'
36
+ * @param optionKeys list of option keys to be checked for.
37
+ * @returns true if a response key is present, but is not in the list defined by optionKeys. If item or the response group is not found, returns false.
38
+ */
39
+ const responseHasOnlyKeysOtherThan = (itemKey, responseSlotKey, ...optionKeys) => expressionUtils_expressionGen.generateExpression('responseHasOnlyKeysOtherThan', undefined, itemKey, responseSlotKey, ...optionKeys);
40
+ /**
41
+ *
42
+ * @param itemKey full key to the survey item, in the form, e.g., <surveyKey>.<groupKey>.<itemKey>
43
+ * @param responseKey full key to the response that should exists
44
+ * @returns if item contains responseKey return true
45
+ */
46
+ const hasResponseKey = (itemKey, responseKey) => {
47
+ return expressionUtils_expressionGen.generateExpression('hasResponseKey', undefined, itemKey, responseKey);
48
+ };
49
+ /**
50
+ *
51
+ * @param itemKey full key to the survey item, in the form, e.g., <surveyKey>.<groupKey>.<itemKey>
52
+ * @param responseKey full key to the response that should exists
53
+ * @param value the response object with the above key should have this value
54
+ * @returns if the response object exists and has the value return true
55
+ */
56
+ const hasResponseKeyWithValue = (itemKey, responseKey, value) => {
57
+ return expressionUtils_expressionGen.generateExpression('hasResponseKeyWithValue', undefined, itemKey, responseKey, value);
58
+ };
59
+ const getResponseValueAsNum = (itemKey, responseKey) => {
60
+ return expressionUtils_expressionGen.generateExpression('getResponseValueAsNum', 'float', itemKey, responseKey);
61
+ };
62
+ const getResponseValueAsStr = (itemKey, responseKey) => {
63
+ return expressionUtils_expressionGen.generateExpression('getResponseValueAsStr', 'string', itemKey, responseKey);
64
+ };
65
+ /**
66
+ * Retrieve the selected keys from a response slot
67
+ * @param itemKey full key to the survey item, in the form, e.g., <surveyKey>.<groupKey>.<itemKey>
68
+ * @param responseKey key of the response slot, where keys should be retrieved from
69
+ * @returns
70
+ */
71
+ const getSelectedKeys = (itemKey, responseKey) => {
72
+ return expressionUtils_expressionGen.generateExpression('getSelectedKeys', 'string', itemKey, responseKey);
73
+ };
74
+ const countResponseItems = (itemKey, responseKey) => {
75
+ return expressionUtils_expressionGen.generateExpression('countResponseItems', undefined, itemKey, responseKey);
76
+ };
77
+ /**
78
+ * Method to run a check on previous responses of the participant.
79
+ * @param condition expression that will be evaluated on each retrieved response
80
+ * @param checkType - optional - 'all'/'any'/<number>: determines how to calculate the final value of the check. Default: 'all'. 'all' means, all the retrieved responses need to fulfil the condition, otherwise the methods returns false. 'any' means at least one retrieved response needs to fulfil the condtion. In both cases, if there were no responses retrieved, returns false. If a number is given here, it means, at least this many response need to fulfil the condition.
81
+ * @param surveyKey - optional - filter for responses of this survey.
82
+ * @param querySince - optional - retrieve responses that were submitted later than this timestamp. Expressions need to return a timestamp, or hard coded numbers can be used as well.
83
+ * @param queryUntil - optional - retrieve responses that were submitted before this timestamp. Expressions need to return a timestamp, or hard coded numbers can be used as well.
84
+ * @returns true/false
85
+ */
86
+ const checkConditionForOldResponses = (condition, checkType, surveyKey, querySince, queryUntil) => expressionUtils_expressionGen.generateExpression('checkConditionForOldResponses', undefined, condition, checkType, surveyKey, querySince, queryUntil);
87
+ /**
88
+ * Method to access the timestamp for when the participant entered the study
89
+ * @returns timestamp
90
+ */
91
+ const getStudyEntryTime = () => expressionUtils_expressionGen.generateExpression('getStudyEntryTime');
92
+ const getStudyEntryTimeForIncoming = () => expressionUtils_expressionGen.generateExpression('incomingState:getStudyEntryTime');
93
+ /**
94
+ * Determines if a specific survey key is currently assigned to the participant.
95
+ * @param surveyKey - string - key of the survey to check for.
96
+ * @returns true if the participant has a survey with this surveyKey assigned, otherwise false.
97
+ */
98
+ const hasSurveyKeyAssigned = (surveyKey) => expressionUtils_expressionGen.generateExpression('hasSurveyKeyAssigned', undefined, surveyKey);
99
+ const hasSurveyKeyAssignedForIncoming = (surveyKey) => expressionUtils_expressionGen.generateExpression('incomingState:hasSurveyKeyAssigned', undefined, surveyKey);
100
+ /**
101
+ * Method to access the timestamp for a surveyKey is assigned from
102
+ * @param surveyKey - string - key of the survey to check for.
103
+ * @returns timestamp
104
+ */
105
+ const getSurveyKeyAssignedFrom = (surveyKey) => expressionUtils_expressionGen.generateExpression('getSurveyKeyAssignedFrom', undefined, surveyKey);
106
+ const getSurveyKeyAssignedFromForIncoming = (surveyKey) => expressionUtils_expressionGen.generateExpression('incomingState:getSurveyKeyAssignedFrom', undefined, surveyKey);
107
+ /**
108
+ * Method to access the timestamp for a surveyKey is assigned until
109
+ * @param surveyKey - string - key of the survey to check for.
110
+ * @returns timestamp
111
+ */
112
+ const getSurveyKeyAssignedUntil = (surveyKey) => expressionUtils_expressionGen.generateExpression('getSurveyKeyAssignedUntil', undefined, surveyKey);
113
+ const getSurveyKeyAssignedUntilForIncoming = (surveyKey) => expressionUtils_expressionGen.generateExpression('incomingState:getSurveyKeyAssignedUntil', undefined, surveyKey);
114
+ /**
115
+ * Check if a participant has a specific study status
116
+ * @param status - string
117
+ * @returns true/false
118
+ */
119
+ const hasStudyStatus = (status) => expressionUtils_expressionGen.generateExpression('getSurveyKeyAssignedUntil', undefined, status);
120
+ const hasStudyStatusForIncoming = (status) => expressionUtils_expressionGen.generateExpression('incomingState:getSurveyKeyAssignedUntil', undefined, status);
121
+ /**
122
+ * Check if a participant flag with specific value is present
123
+ * @param key look up this flag
124
+ * @param value and for this value
125
+ * @returns return true if key - value pair (with case sensitive matching for both key and value) is present. If any of the two is different, or participant flags is empty, it returns false.
126
+ */
127
+ const hasParticipantFlagKeyAndValue = (key, value) => expressionUtils_expressionGen.generateExpression('hasParticipantFlag', undefined, key, value);
128
+ const hasParticipantFlagKeyAndValueForIncoming = (key, value) => expressionUtils_expressionGen.generateExpression('incomingState:hasParticipantFlag', undefined, key, value);
129
+ /**
130
+ * Check if a participant flag is present
131
+ * @param key look up this flag
132
+ * @returns return true if key is present. If any of the two is different, or participant flags is empty, it returns false.
133
+ */
134
+ const hasParticipantFlagKey = (key) => expressionUtils_expressionGen.generateExpression('hasParticipantFlagKey', undefined, key);
135
+ const hasParticipantFlagKeyForIncoming = (key) => expressionUtils_expressionGen.generateExpression('incomingState:hasParticipantFlagKey', undefined, key);
136
+ /**
137
+ * Retrieve the value of a participant flag
138
+ * @param key look up this flag
139
+ * @returns return the value or an empty string if not present
140
+ */
141
+ const getParticipantFlagValue = (key) => expressionUtils_expressionGen.generateExpression('getParticipantFlagValue', undefined, key);
142
+ const getParticipantFlagValueForIncoming = (key) => expressionUtils_expressionGen.generateExpression('incomingState:getParticipantFlagValue', undefined, key);
143
+ /**
144
+ * Checks if the participant has a message type assigned (at least one)
145
+ * @param messageType
146
+ * @returns return true if a message with the given message type is assigned
147
+ */
148
+ const hasMessageTypeAssigned = (messageType) => expressionUtils_expressionGen.generateExpression('hasMessageTypeAssigned', undefined, messageType);
149
+ const hasMessageTypeAssignedForIncoming = (messageType) => expressionUtils_expressionGen.generateExpression('incomingState:hasMessageTypeAssigned', undefined, messageType);
150
+ /**
151
+ * Retrieve the timestamp (scheduledFor) for a particular message type. Return 0 if not assigned.
152
+ * @param messageType
153
+ * @returns timestamp value or zero
154
+ */
155
+ const getMessageNextTime = (messageType) => expressionUtils_expressionGen.generateExpression('getMessageNextTime', undefined, messageType);
156
+ const getMessageNextTimeForIncoming = (messageType) => expressionUtils_expressionGen.generateExpression('incomingState:getMessageNextTime', undefined, messageType);
157
+ /**
158
+ * Check if the last submission is older than the reference timestamp
159
+ * @param reference look up this flag
160
+ * @param surveyKey - optional - check for this specific survey key. If empty, it would check for all the submissions.
161
+ * @returns boolean
162
+ */
163
+ const lastSubmissionDateOlderThan = (reference, surveyKey) => expressionUtils_expressionGen.generateExpression('lastSubmissionDateOlderThan', undefined, reference, surveyKey);
164
+ const lastSubmissionDateOlderThanForIncoming = (reference, surveyKey) => expressionUtils_expressionGen.generateExpression('incomingState:lastSubmissionDateOlderThan', undefined, reference, surveyKey);
165
+ const eq = (val1, val2) => expressionUtils_expressionGen.generateExpression('eq', undefined, val1, val2);
166
+ const lt = (val1, val2) => expressionUtils_expressionGen.generateExpression('lt', undefined, val1, val2);
167
+ const lte = (val1, val2) => expressionUtils_expressionGen.generateExpression('lte', undefined, val1, val2);
168
+ const gt = (val1, val2) => expressionUtils_expressionGen.generateExpression('gt', undefined, val1, val2);
169
+ const gte = (val1, val2) => expressionUtils_expressionGen.generateExpression('gte', undefined, val1, val2);
170
+ /**
171
+ * Generate a timestamp value (POSIX timestamp). T = T_ref + delta. If 'reference' is not defined, the current time will be used as a reference.
172
+ * @param delta offset for the timestamp generation
173
+ * @param reference optional - a hard coded number, or an expression that should retrieve a timestamp (e.g., surveys assigned from, or response to a date question)
174
+ * @returns
175
+ */
176
+ const timestampWithOffset = (delta, reference) => expressionUtils_expressionGen.generateExpression('timestampWithOffset', undefined, types_duration.durationObjectToSeconds(delta), reference ? reference : undefined);
177
+ /**
178
+ * Control flow method to use an if-else like structure
179
+ * @param condition expression, return value interpreted as boolean
180
+ * @param actionIfTrue if condition evaluates to true, this action will be performed.
181
+ * @param actionIfFalse optional, if defined and the condition returns false, this action will be performed.
182
+ * @returns
183
+ */
184
+ const IF = (condition, actionIfTrue, actionIfFalse) => expressionUtils_expressionGen.generateExpression('IF', undefined, condition, actionIfTrue, actionIfFalse);
185
+ /**
186
+ * Perform a list of expressions / actions
187
+ * @param args: list of expressions to be evaluated
188
+ * @returns
189
+ */
190
+ const DO = (...args) => expressionUtils_expressionGen.generateExpression('DO', undefined, ...args);
191
+ /**
192
+ * Simple if statement (without else), that checks for the condition and executes the list of actions.
193
+ * @param condition condition to check, return value interpreted as boolean
194
+ * @param args list of actions to be performed if condition evaluates to true, otherwise they are ignored
195
+ * @returns
196
+ */
197
+ const IFTHEN = (condition, ...args) => expressionUtils_expressionGen.generateExpression('IFTHEN', undefined, condition, ...args);
198
+ /**
199
+ * Update the participant's study status
200
+ * @param status new status value
201
+ * @returns
202
+ */
203
+ const UPDATE_STUDY_STATUS = (status) => expressionUtils_expressionGen.generateExpression('UPDATE_STUDY_STATUS', undefined, status);
204
+ /**
205
+ * Generate and store a new session id to the participant's state
206
+ * @param status new status value
207
+ * @returns
208
+ */
209
+ const START_NEW_STUDY_SESSION = () => expressionUtils_expressionGen.generateExpression('START_NEW_STUDY_SESSION', undefined);
210
+ /**
211
+ * Add or update a participant flag
212
+ * @param key
213
+ * @param newValue: string, number or expression where result should be written in the flag's value
214
+ * @returns
215
+ */
216
+ const UPDATE_FLAG = (key, newValue) => expressionUtils_expressionGen.generateExpression('UPDATE_FLAG', undefined, key, newValue);
217
+ const REMOVE_FLAG = (key) => expressionUtils_expressionGen.generateExpression('REMOVE_FLAG', undefined, key);
218
+ const ADD_NEW_SURVEY = (surveyKey, category, activeFrom, activeUntil) => expressionUtils_expressionGen.generateExpression('ADD_NEW_SURVEY', undefined, surveyKey, activeFrom !== undefined ? activeFrom : 0, activeUntil !== undefined ? activeUntil : 0, category);
219
+ const REMOVE_ALL_SURVEYS = () => expressionUtils_expressionGen.generateExpression('REMOVE_ALL_SURVEYS');
220
+ /**
221
+ * Add participant message
222
+ * @param messageType message type
223
+ * @param scheduledFor timestamp or expression returning a timestamp
224
+ * @returns
225
+ */
226
+ const ADD_MESSAGE = (messageType, scheduledFor) => expressionUtils_expressionGen.generateExpression('ADD_MESSAGE', undefined, messageType, scheduledFor);
227
+ /**
228
+ * Remove all messages scheduled for the participant
229
+ * @returns
230
+ */
231
+ const REMOVE_ALL_MESSAGES = () => expressionUtils_expressionGen.generateExpression('REMOVE_ALL_MESSAGES', undefined);
232
+ /**
233
+ * Remove all messages with this message type
234
+ * @param messageType message type
235
+ * @returns
236
+ */
237
+ const REMOVE_MESSAGES_BY_TYPE = (messageType) => expressionUtils_expressionGen.generateExpression('REMOVE_MESSAGES_BY_TYPE', undefined, messageType);
238
+ const REMOVE_SURVEY_BY_KEY = (surveyKey, selector) => {
239
+ if (selector === 'all') {
240
+ return expressionUtils_expressionGen.generateExpression('REMOVE_SURVEYS_BY_KEY', undefined, surveyKey);
241
+ }
242
+ else {
243
+ return expressionUtils_expressionGen.generateExpression('REMOVE_SURVEY_BY_KEY', undefined, surveyKey, selector);
244
+ }
245
+ };
246
+ /**
247
+ * Initialises or resets a report for the current event
248
+ * @param reportKey key to be used for the report
249
+ */
250
+ const INIT_REPORT = (reportKey) => {
251
+ return expressionUtils_expressionGen.generateExpression('INIT_REPORT', undefined, reportKey);
252
+ };
253
+ /**
254
+ * Remove the report from the list of reports to be added at the end of the event
255
+ * @param reportKey key of the report that should be removed
256
+ * @returns
257
+ */
258
+ const CANCEL_REPORT = (reportKey) => {
259
+ return expressionUtils_expressionGen.generateExpression('CANCEL_REPORT', undefined, reportKey);
260
+ };
261
+ /**
262
+ * Remove the confidential responses with this key for the participant
263
+ * @param key key of the confidential responses that should be removed
264
+ * @returns
265
+ */
266
+ const REMOVE_CONFIDENTIAL_RESPONSE_BY_KEY = (key) => {
267
+ return expressionUtils_expressionGen.generateExpression('REMOVE_CONFIDENTIAL_RESPONSE_BY_KEY', undefined, key);
268
+ };
269
+ /**
270
+ * Remove all confidential responses for the participant
271
+ * @returns
272
+ */
273
+ const REMOVE_ALL_CONFIDENTIAL_RESPONSES = () => {
274
+ return expressionUtils_expressionGen.generateExpression('REMOVE_ALL_CONFIDENTIAL_RESPONSES', undefined);
275
+ };
276
+ /**
277
+ * Update one value attribute in a report. If report was not initialized, one will be added to the list.
278
+ * @param reportKey
279
+ * @param attributeKey update / create this attribute in the report
280
+ * @param value this should be the value for the given attribute
281
+ * @param dtype optional dtype to set info for the app how to render this data.
282
+ * @returns
283
+ */
284
+ const UPDATE_REPORT_DATA = (reportKey, attributeKey, value, dtype) => {
285
+ return expressionUtils_expressionGen.generateExpression('UPDATE_REPORT_DATA', undefined, reportKey, attributeKey, value, dtype);
286
+ };
287
+ /**
288
+ * Method to remove one attribute (key and value) from the report
289
+ * @param reportKey
290
+ * @param attributeKey
291
+ * @returns
292
+ */
293
+ const REMOVE_REPORT_DATA = (reportKey, attributeKey) => {
294
+ return expressionUtils_expressionGen.generateExpression('REMOVE_REPORT_DATA', undefined, reportKey, attributeKey);
295
+ };
296
+ const setReportIcon = (reportKey, icon) => {
297
+ return UPDATE_REPORT_DATA(reportKey, 'icon', icon);
298
+ };
299
+ const setReportMessage = (reportKey, content, asTranslationKey) => {
300
+ return UPDATE_REPORT_DATA(reportKey, 'message', content, asTranslationKey ? undefined : 'rawMessage');
301
+ };
302
+ const setReportSummary = (reportKey, content, asTranslationKey) => {
303
+ return UPDATE_REPORT_DATA(reportKey, 'summary', content, asTranslationKey ? undefined : 'rawMessage');
304
+ };
305
+ // ##################
306
+ // Prefill rule methods:
307
+ const GET_LAST_SURVEY_ITEM = (surveyKey, itemKey, submittedLaterThan) => {
308
+ return expressionUtils_expressionGen.generateExpression('GET_LAST_SURVEY_ITEM', undefined, surveyKey, itemKey, submittedLaterThan ? types_duration.durationObjectToSeconds(submittedLaterThan) : undefined);
309
+ };
310
+ // ##################
311
+ // Context previous responses methods:
312
+ const LAST_RESPONSES_BY_KEY = (surveyKey, limit) => {
313
+ return expressionUtils_expressionGen.generateExpression('LAST_RESPONSES_BY_KEY', undefined, surveyKey, limit);
314
+ };
315
+ const ALL_RESPONSES_SINCE = (sinceTimestamp) => {
316
+ return expressionUtils_expressionGen.generateExpression('ALL_RESPONSES_SINCE', undefined, sinceTimestamp);
317
+ };
318
+ const RESPONSES_SINCE_BY_KEY = (sinceTimestamp, surveyKey) => {
319
+ return expressionUtils_expressionGen.generateExpression('RESPONSES_SINCE_BY_KEY', undefined, sinceTimestamp, surveyKey);
320
+ };
321
+ // ##################
322
+ // Extra methods:
323
+ const singleChoiceOptionsSelected = (itemKey, ...optionKeys) => expressionUtils_expressionGen.generateExpression('responseHasKeysAny', undefined, itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.singleChoiceKey].join('.'), ...optionKeys);
324
+ const multipleChoiceOptionsSelected = (itemKey, ...optionKeys) => expressionUtils_expressionGen.generateExpression('responseHasKeysAny', undefined, itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.multipleChoiceKey].join('.'), ...optionKeys);
325
+ const multipleChoiceAllOfTheseSelected = (itemKey, ...optionKeys) => and(...optionKeys.map(option => expressionUtils_expressionGen.generateExpression('responseHasKeysAny', undefined, itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.multipleChoiceKey].join('.'), option)));
326
+ const multipleChoiceOnlyOtherKeysSelected = (itemKey, ...optionKeys) => expressionUtils_expressionGen.generateExpression('responseHasOnlyKeysOtherThan', undefined, itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.multipleChoiceKey].join('.'), ...optionKeys);
327
+ const singleChoiceOnlyOtherOptionSelected = (itemKey, ...optionKeys) => expressionUtils_expressionGen.generateExpression('responseHasOnlyKeysOtherThan', undefined, itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.singleChoiceKey].join('.'), ...optionKeys);
328
+ const consentAcceptedCondition = (itemKey) => {
329
+ return hasResponseKey(itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.consentKey].join('.'));
330
+ };
331
+ const stopParticipation = () => UPDATE_STUDY_STATUS('inactive');
332
+ const finishParticipation = () => UPDATE_STUDY_STATUS('finished');
333
+ /**
334
+ * If a survey is assigned with validFrom <= now and validUnil >= now
335
+ * @param surveyKey which survey it should check for
336
+ * @returns
337
+ */
338
+ const hasSurveyKeyActive = (surveyKey) => {
339
+ return and(lte(getSurveyKeyAssignedFrom(surveyKey), timestampWithOffset({ seconds: 1 })), gte(getSurveyKeyAssignedUntil(surveyKey), timestampWithOffset({ seconds: -1 })));
340
+ };
341
+ /**
342
+ * Results of "T_ref = reference + delta" will be checked against "validFrom" of the assinged survey (if present). True T_ref > T_validFrom.
343
+ * @param surveyKey which survey it should check for
344
+ * @param delta delta time to the reference time (by default current time).
345
+ * @param reference optional reference time. If undefined it will take the current time.
346
+ * @returns
347
+ */
348
+ const hasSurveyKeyValidFromOlderThan = (surveyKey, delta, reference) => {
349
+ return lt(getSurveyKeyAssignedFrom(surveyKey), timestampWithOffset(delta, reference));
350
+ };
351
+ /**
352
+ * Results of "T_ref = reference + delta" will be checked against "validUntil" of the assinged survey (if present). True T_ref < T_validUntil.
353
+ * @param surveyKey which survey it should check for
354
+ * @param delta delta time to the reference time (by default current time).
355
+ * @param reference optional reference time. If undefined it will take the current time.
356
+ * @returns
357
+ */
358
+ const hasSurveyKeyValidUntilSoonerThan = (surveyKey, delta, reference) => {
359
+ return gt(timestampWithOffset(delta, reference), getSurveyKeyAssignedUntil(surveyKey));
360
+ };
361
+ const NativeStudyEngineExpressions = {
362
+ checkEventType,
363
+ // Response checkers
364
+ checkSurveyResponseKey,
365
+ responseHasKeysAny,
366
+ responseHasOnlyKeysOtherThan,
367
+ getResponseValueAsNum,
368
+ getResponseValueAsStr,
369
+ getSelectedKeys,
370
+ hasResponseKey,
371
+ hasResponseKeyWithValue,
372
+ countResponseItems,
373
+ // Old responses
374
+ checkConditionForOldResponses,
375
+ // Participant state:
376
+ participantState: {
377
+ getStudyEntryTime,
378
+ hasSurveyKeyAssigned,
379
+ getSurveyKeyAssignedFrom,
380
+ getSurveyKeyAssignedUntil,
381
+ hasStudyStatus,
382
+ hasParticipantFlagKeyAndValue,
383
+ hasParticipantFlagKey,
384
+ getParticipantFlagValue,
385
+ lastSubmissionDateOlderThan,
386
+ hasMessageTypeAssigned,
387
+ getMessageNextTime,
388
+ incomingParticipantState: {
389
+ // for merge event
390
+ getStudyEntryTime: getStudyEntryTimeForIncoming,
391
+ hasSurveyKeyAssigned: hasSurveyKeyAssignedForIncoming,
392
+ getSurveyKeyAssignedFrom: getSurveyKeyAssignedFromForIncoming,
393
+ getSurveyKeyAssignedUntil: getSurveyKeyAssignedUntilForIncoming,
394
+ hasStudyStatus: hasStudyStatusForIncoming,
395
+ hasParticipantFlagKeyAndValue: hasParticipantFlagKeyAndValueForIncoming,
396
+ hasParticipantFlagKey: hasParticipantFlagKeyForIncoming,
397
+ getParticipantFlagValue: getParticipantFlagValueForIncoming,
398
+ lastSubmissionDateOlderThan: lastSubmissionDateOlderThanForIncoming,
399
+ hasMessageTypeAssigned: hasMessageTypeAssignedForIncoming,
400
+ getMessageNextTime: getMessageNextTimeForIncoming,
401
+ }
402
+ },
403
+ // logical and comparision
404
+ eq,
405
+ lt,
406
+ lte,
407
+ gt,
408
+ gte,
409
+ or,
410
+ and,
411
+ not,
412
+ // Other
413
+ timestampWithOffset,
414
+ };
415
+ const StudyEngineActions = {
416
+ if: IF,
417
+ do: DO,
418
+ ifThen: IFTHEN,
419
+ participantActions: {
420
+ updateStudyStatus: UPDATE_STUDY_STATUS,
421
+ startNewStudySession: START_NEW_STUDY_SESSION,
422
+ updateFlag: UPDATE_FLAG,
423
+ removeFlag: REMOVE_FLAG,
424
+ assignedSurveys: {
425
+ add: ADD_NEW_SURVEY,
426
+ removeAll: REMOVE_ALL_SURVEYS,
427
+ remove: REMOVE_SURVEY_BY_KEY,
428
+ },
429
+ reports: {
430
+ init: INIT_REPORT,
431
+ cancel: CANCEL_REPORT,
432
+ updateData: UPDATE_REPORT_DATA,
433
+ removeData: REMOVE_REPORT_DATA,
434
+ // Extra methods:
435
+ setReportIcon,
436
+ setReportMessage,
437
+ setReportSummary,
438
+ },
439
+ messages: {
440
+ add: ADD_MESSAGE,
441
+ removeAll: REMOVE_ALL_MESSAGES,
442
+ remove: REMOVE_MESSAGES_BY_TYPE,
443
+ },
444
+ confidentialResponses: {
445
+ removeByKey: REMOVE_CONFIDENTIAL_RESPONSE_BY_KEY,
446
+ removeAll: REMOVE_ALL_CONFIDENTIAL_RESPONSES,
447
+ },
448
+ // Extra methods:
449
+ stopParticipation,
450
+ finishParticipation,
451
+ }
452
+ };
453
+ const StudyEngine = Object.assign(Object.assign(Object.assign({}, NativeStudyEngineExpressions), StudyEngineActions), { singleChoice: {
454
+ any: singleChoiceOptionsSelected,
455
+ none: singleChoiceOnlyOtherOptionSelected
456
+ }, multipleChoice: {
457
+ any: multipleChoiceOptionsSelected,
458
+ none: multipleChoiceOnlyOtherKeysSelected,
459
+ all: multipleChoiceAllOfTheseSelected,
460
+ }, consent: {
461
+ accepted: consentAcceptedCondition,
462
+ }, survey: {
463
+ isActive: hasSurveyKeyActive,
464
+ validFromOlderThan: hasSurveyKeyValidFromOlderThan,
465
+ validUntilSoonerThan: hasSurveyKeyValidUntilSoonerThan,
466
+ }, prefillRules: {
467
+ GET_LAST_SURVEY_ITEM,
468
+ }, contextRules: {
469
+ previousResponses: {
470
+ LAST_RESPONSES_BY_KEY,
471
+ ALL_RESPONSES_SINCE,
472
+ RESPONSES_SINCE_BY_KEY,
473
+ }
474
+ } });
475
+
476
+ exports.NativeStudyEngineExpressions = NativeStudyEngineExpressions;
477
+ exports.StudyEngine = StudyEngine;
478
+ exports.StudyEngineActions = StudyEngineActions;
479
+ //# sourceMappingURL=studyEngineExpressions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"studyEngineExpressions.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/index.d.ts ADDED
File without changes
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ 'use strict';
2
+
3
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}