case-editor-tools 1.0.0-beta.3 → 1.0.0-beta.30

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 (130) hide show
  1. package/{build/constants → constants}/key-definitions.d.ts +1 -0
  2. package/{build/constants → constants}/key-definitions.js +3 -1
  3. package/{build/constants → constants}/key-definitions.js.map +1 -1
  4. package/exporter/index.d.ts +2 -0
  5. package/exporter/index.js +99 -0
  6. package/exporter/index.js.map +1 -0
  7. package/{build/expression-utils → expression-utils}/expressionGen.d.ts +1 -1
  8. package/{build/expression-utils → expression-utils}/expressionGen.js +0 -0
  9. package/{build/expression-utils → expression-utils}/expressionGen.js.map +0 -0
  10. package/{build/expression-utils → expression-utils}/studyEngineExpressions.d.ts +37 -7
  11. package/{build/expression-utils → expression-utils}/studyEngineExpressions.js +93 -4
  12. package/{build/expression-utils → expression-utils}/studyEngineExpressions.js.map +1 -1
  13. package/{build/index.d.ts → index.d.ts} +0 -0
  14. package/{build/index.js → index.js} +0 -0
  15. package/{build/index.js.map → index.js.map} +0 -0
  16. package/{build/item-editor-8fd24b61.js → item-editor-c6933791.js} +69 -51
  17. package/item-editor-c6933791.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/{build/logger → logger}/logger.d.ts +0 -0
  22. package/{build/logger → logger}/logger.js +0 -0
  23. package/{build/logger → logger}/logger.js.map +0 -0
  24. package/package.json +7 -8
  25. package/surveys/index.d.ts +3 -0
  26. package/surveys/index.js +28 -0
  27. package/surveys/index.js.map +1 -0
  28. package/surveys/responseTypeGenerators/likertGroupComponents.d.ts +27 -0
  29. package/surveys/responseTypeGenerators/likertGroupComponents.js +347 -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 +99 -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 +125 -0
  36. package/surveys/responseTypeGenerators/optionGroupComponents.js.map +1 -0
  37. package/{build → surveys}/survey-editor/component-editor.d.ts +1 -1
  38. package/{build → surveys}/survey-editor/component-editor.js +0 -0
  39. package/{build → surveys}/survey-editor/component-editor.js.map +0 -0
  40. package/{build → surveys}/survey-editor/data-types.d.ts +1 -1
  41. package/{build → surveys}/survey-editor/data-types.js +0 -0
  42. package/{build → surveys}/survey-editor/data-types.js.map +0 -0
  43. package/{build → surveys}/survey-editor/item-editor.d.ts +1 -1
  44. package/{build → surveys}/survey-editor/item-editor.js +3 -2
  45. package/{build → surveys}/survey-editor/item-editor.js.map +1 -1
  46. package/{build → surveys}/survey-editor/survey-editor.d.ts +6 -1
  47. package/{build → surveys}/survey-editor/survey-editor.js +15 -8
  48. package/{build → surveys}/survey-editor/survey-editor.js.map +1 -1
  49. package/{build/expression-utils/surveyEngineExpressions.d.ts → surveys/survey-engine-expressions.d.ts} +9 -2
  50. package/{build/expression-utils/surveyEngineExpressions.js → surveys/survey-engine-expressions.js} +36 -4
  51. package/{build/expression-utils/surveyEngineExpressions.js.map → surveys/survey-engine-expressions.js.map} +1 -1
  52. package/surveys/survey-items.d.ts +66 -0
  53. package/surveys/survey-items.js +302 -0
  54. package/surveys/survey-items.js.map +1 -0
  55. package/{build → surveys}/types/group.d.ts +1 -1
  56. package/{build → surveys}/types/group.js +5 -5
  57. package/{build → surveys}/types/group.js.map +0 -0
  58. package/surveys/types/index.d.ts +4 -0
  59. package/surveys/types/index.js +20 -0
  60. package/surveys/types/index.js.map +1 -0
  61. package/surveys/types/item-properties.d.ts +189 -0
  62. package/surveys/types/item-properties.js +3 -0
  63. package/surveys/types/item-properties.js.map +1 -0
  64. package/{build → surveys}/types/item.d.ts +1 -1
  65. package/{build → surveys}/types/item.js +0 -0
  66. package/{build → surveys}/types/item.js.map +0 -0
  67. package/{build/types/surveyDefinition.d.ts → surveys/types/survey-definition.d.ts} +7 -3
  68. package/{build/types/surveyDefinition.js → surveys/types/survey-definition.js} +19 -11
  69. package/surveys/types/survey-definition.js.map +1 -0
  70. package/{build → surveys}/utils/componentGenerators.d.ts +2 -13
  71. package/surveys/utils/componentGenerators.js +58 -0
  72. package/{build → surveys}/utils/componentGenerators.js.map +1 -1
  73. package/surveys/utils/optionDefGenerators.d.ts +69 -0
  74. package/surveys/utils/optionDefGenerators.js +169 -0
  75. package/surveys/utils/optionDefGenerators.js.map +1 -0
  76. package/{build → surveys}/utils/randomKeyGenerator.d.ts +0 -0
  77. package/{build → surveys}/utils/randomKeyGenerator.js +0 -0
  78. package/{build → surveys}/utils/randomKeyGenerator.js.map +0 -0
  79. package/{build → surveys}/utils/simple-generators.d.ts +2 -2
  80. package/{build → surveys}/utils/simple-generators.js +5 -5
  81. package/{build → surveys}/utils/simple-generators.js.map +0 -0
  82. package/{build → surveys}/utils/simple-question-editor.d.ts +3 -3
  83. package/{build → surveys}/utils/simple-question-editor.js +7 -6
  84. package/{build → surveys}/utils/simple-question-editor.js.map +1 -1
  85. package/{build/types → types}/duration.d.ts +0 -0
  86. package/{build/types → types}/duration.js +0 -0
  87. package/{build/types → types}/duration.js.map +0 -0
  88. package/{build/types → types}/expression.d.ts +1 -1
  89. package/{build/types → types}/expression.js +0 -0
  90. package/{build/types → types}/expression.js.map +0 -0
  91. package/{build/types → types}/study.d.ts +2 -2
  92. package/{build/types → types}/study.js +0 -0
  93. package/{build/types → types}/study.js.map +0 -0
  94. package/{build/types → types}/studyRules.d.ts +1 -1
  95. package/{build/types → types}/studyRules.js +0 -0
  96. package/{build/types → types}/studyRules.js.map +0 -0
  97. package/.babelrc.js +0 -7
  98. package/.editorconfig +0 -13
  99. package/LICENSE +0 -202
  100. package/build/item-editor-8fd24b61.js.map +0 -1
  101. package/build/package.json +0 -26
  102. package/build/types/surveyDefinition.js.map +0 -1
  103. package/build/utils/componentGenerators.js +0 -92
  104. package/build/utils/question-type-generator.d.ts +0 -283
  105. package/build/utils/question-type-generator.js +0 -949
  106. package/build/utils/question-type-generator.js.map +0 -1
  107. package/rollup.config.js +0 -53
  108. package/src/constants/key-definitions.ts +0 -13
  109. package/src/expression-utils/expressionGen.ts +0 -28
  110. package/src/expression-utils/studyEngineExpressions.ts +0 -359
  111. package/src/expression-utils/surveyEngineExpressions.ts +0 -483
  112. package/src/index.ts +0 -1
  113. package/src/logger/logger.ts +0 -31
  114. package/src/survey-editor/component-editor.ts +0 -133
  115. package/src/survey-editor/data-types.ts +0 -18
  116. package/src/survey-editor/item-editor.ts +0 -528
  117. package/src/survey-editor/survey-editor.ts +0 -260
  118. package/src/types/duration.ts +0 -32
  119. package/src/types/expression.ts +0 -22
  120. package/src/types/group.ts +0 -73
  121. package/src/types/item.ts +0 -42
  122. package/src/types/study.ts +0 -17
  123. package/src/types/studyRules.ts +0 -39
  124. package/src/types/surveyDefinition.ts +0 -83
  125. package/src/utils/componentGenerators.ts +0 -122
  126. package/src/utils/question-type-generator.ts +0 -1516
  127. package/src/utils/randomKeyGenerator.ts +0 -11
  128. package/src/utils/simple-generators.ts +0 -106
  129. package/src/utils/simple-question-editor.ts +0 -52
  130. package/tsconfig.json +0 -100
@@ -1 +0,0 @@
1
- {"version":3,"file":"question-type-generator.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/rollup.config.js DELETED
@@ -1,53 +0,0 @@
1
- import peerDepsExternal from "rollup-plugin-peer-deps-external";
2
- import resolve from "@rollup/plugin-node-resolve";
3
- import commonjs from "@rollup/plugin-commonjs";
4
- import typescript from "rollup-plugin-typescript2";
5
- import del from 'rollup-plugin-delete';
6
- import multiInput from 'rollup-plugin-multi-input';
7
- import copy from 'rollup-plugin-copy';
8
-
9
- const packageJson = require("./package.json");
10
-
11
- const config = {
12
- input: [
13
- // "src/index.ts",
14
- "src/**/*.ts"
15
- ],
16
- output: [
17
- {
18
- //file: packageJson.main,
19
- dir: 'build',
20
- format: "cjs",
21
- // exports: 'auto',
22
- //preserveModules: true,
23
- //preserveModulesRoot: 'src',
24
- sourcemap: true
25
- },
26
- /*{
27
- // file: packageJson.module,
28
- dir: 'build',
29
- format: "esm",
30
- sourcemap: true
31
- }*/
32
- ],
33
- plugins: [
34
- del({
35
- targets: 'build/*'
36
- }),
37
- multiInput({ relative: 'src/' }),
38
- peerDepsExternal(),
39
- resolve(),
40
- commonjs(),
41
- typescript({
42
- tsconfig: './tsconfig.json',
43
- useTsconfigDeclarationDir: true
44
- }),
45
- copy({
46
- targets: [
47
- { src: 'package.json', dest: 'build' }
48
- ]
49
- })
50
- ]
51
- };
52
-
53
- export default config;
@@ -1,13 +0,0 @@
1
- export const responseGroupKey = 'rg';
2
- export const singleChoiceKey = 'scg';
3
- export const likertScaleGroupKey = 'lg';
4
- export const responsiveSingleChoiceArrayKey = 'rsca';
5
- export const responsiveBipolarLikertArrayKey = 'rsbla';
6
- export const likertScaleKey = 'likert';
7
- export const multipleChoiceKey = 'mcg';
8
- export const dropDownKey = 'ddg';
9
- export const sliderCategoricalKey = "scc";
10
- export const inputKey = "ic";
11
- export const numericInputKey = "num";
12
- export const datePickerKey = "date";
13
- export const matrixKey = "mat";
@@ -1,28 +0,0 @@
1
- import { Expression, ExpressionName } from "survey-engine/lib/data_types"
2
-
3
-
4
- export const generateExpression = (name: ExpressionName,
5
- returnType?: 'string' | 'float',
6
- ...args: any[]): Expression => {
7
- return {
8
- name: name,
9
- returnType: returnType,
10
- data: args.filter(a => a !== undefined).map(arg => {
11
- if (typeof (arg) === 'string') {
12
- return {
13
- dtype: 'str',
14
- str: arg
15
- }
16
- } else if (typeof (arg) === 'number') {
17
- return {
18
- dtype: 'num',
19
- num: arg
20
- }
21
- }
22
- return {
23
- dtype: 'exp',
24
- exp: arg as Expression
25
- }
26
- })
27
- }
28
- }
@@ -1,359 +0,0 @@
1
- import { Expression } from "survey-engine/lib/data_types"
2
- import { multipleChoiceKey, responseGroupKey, singleChoiceKey } from "../constants/key-definitions"
3
- import { Duration, durationObjectToSeconds } from "../types/duration"
4
- import { generateExpression } from "./expressionGen"
5
-
6
- const or = (...args: Expression[]): Expression => generateExpression('or', undefined, ...args)
7
- const and = (...args: Expression[]): Expression => generateExpression('and', undefined, ...args)
8
- const not = (arg: Expression): Expression => generateExpression('not', undefined, arg)
9
-
10
- /**
11
- * Check if the current event has the given type
12
- * @param equalsType string with the possible values: 'ENTER', 'SUBMIT', 'TIMER
13
- * @returns if event type matches the argument, return true otherwise false
14
- */
15
- const checkEventType = (equalsType: 'ENTER' | 'SUBMIT' | 'TIMER') => generateExpression('checkEventType', undefined, equalsType)
16
-
17
- /**
18
- * Check if the submitted survey has a specific key
19
- * @param surveyKey string to check for
20
- * @returns true, if the survey has the key, false otherwise
21
- */
22
- const checkSurveyResponseKey = (surveyKey: string) => generateExpression('checkSurveyResponseKey', undefined, surveyKey);
23
-
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: string, responseSlotKey: string, ...optionKeys: string[]) => generateExpression('responseHasKeysAny', undefined, itemKey, responseSlotKey, ...optionKeys);
32
-
33
- /**
34
- * Check survey response item, if only other keys have been selected
35
- * @param itemKey full key to the survey item, in the form, e.g., <surveyKey>.<groupKey>.<itemKey>
36
- * @param responseSlotKey full key to the response group, e.g., 'rg.mcg'
37
- * @param optionKeys list of option keys to be checked for.
38
- * @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.
39
- */
40
- const responseHasOnlyKeysOtherThan = (itemKey: string, responseSlotKey: string, ...optionKeys: string[]) => generateExpression('responseHasOnlyKeysOtherThan', undefined, itemKey, responseSlotKey, ...optionKeys)
41
-
42
- const getResponseValueAsNum = (itemKey: string, responseKey: string): Expression => {
43
- return generateExpression('getResponseValueAsNum', 'float', itemKey, responseKey);
44
- }
45
-
46
- const getResponseValueAsStr = (itemKey: string, responseKey: string): Expression => {
47
- return generateExpression('getResponseValueAsStr', 'string', itemKey, responseKey);
48
- }
49
-
50
- const countResponseItems = (itemKey: string, responseKey: string): Expression => {
51
- return generateExpression('countResponseItems', undefined, itemKey, responseKey);
52
- }
53
-
54
- /**
55
- * Method to run a check on previous responses of the participant.
56
- * @param condition expression that will be evaluated on each retrieved response
57
- * @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.
58
- * @param surveyKey - optional - filter for responses of this survey.
59
- * @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.
60
- * @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.
61
- * @returns true/false
62
- */
63
- const checkConditionForOldResponses = (
64
- condition: Expression,
65
- checkType?: number | 'all' | 'any',
66
- surveyKey?: string,
67
- querySince?: number | Expression,
68
- queryUntil?: number | Expression,
69
- ): Expression => generateExpression('checkConditionForOldResponses', undefined, condition, checkType, surveyKey, querySince, queryUntil)
70
-
71
- /**
72
- * Method to access the timestamp for when the participant entered the study
73
- * @returns timestamp
74
- */
75
- const getStudyEntryTime = () => generateExpression('getStudyEntryTime');
76
-
77
- /**
78
- * Determines if a specific survey key is currently assigned to the participant.
79
- * @param surveyKey - string - key of the survey to check for.
80
- * @returns true if the participant has a survey with this surveyKey assigned, otherwise false.
81
- */
82
- const hasSurveyKeyAssigned = (surveyKey: string) => generateExpression('hasSurveyKeyAssigned', undefined, surveyKey);
83
-
84
- /**
85
- * Method to access the timestamp for a surveyKey is assigned from
86
- * @param surveyKey - string - key of the survey to check for.
87
- * @returns timestamp
88
- */
89
- const getSurveyKeyAssignedFrom = (surveyKey: string) => generateExpression('getSurveyKeyAssignedFrom', undefined, surveyKey);
90
-
91
- /**
92
- * Method to access the timestamp for a surveyKey is assigned until
93
- * @param surveyKey - string - key of the survey to check for.
94
- * @returns timestamp
95
- */
96
- const getSurveyKeyAssignedUntil = (surveyKey: string) => generateExpression('getSurveyKeyAssignedUntil', undefined, surveyKey);
97
-
98
- /**
99
- * Check if a participant has a specific study status
100
- * @param status - string
101
- * @returns true/false
102
- */
103
- const hasStudyStatus = (status: string) => generateExpression('getSurveyKeyAssignedUntil', undefined, status);
104
-
105
- /**
106
- * Check if a participant flag is present
107
- * @param key look up this flag
108
- * @param value and for this value
109
- * @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.
110
- */
111
- const hasParticipantFlag = (key: string, value: string) => generateExpression('hasParticipantFlag', undefined, key, value);
112
-
113
- /**
114
- * Check if the last submission is older than the reference timestamp
115
- * @param reference look up this flag
116
- * @param surveyKey - optional - check for this specific survey key. If empty, it would check for all the submissions.
117
- * @returns boolean
118
- */
119
- const lastSubmissionDateOlderThan = (reference: number | Expression, surveyKey?: string) => generateExpression('lastSubmissionDateOlderThan', undefined, reference, surveyKey);
120
-
121
- const eq = (val1: Expression | string | number, val2: Expression | string | number) => generateExpression('eq', undefined, val1, val2);
122
- const lt = (val1: Expression | string | number, val2: Expression | string | number) => generateExpression('lt', undefined, val1, val2);
123
- const lte = (val1: Expression | string | number, val2: Expression | string | number) => generateExpression('lte', undefined, val1, val2);
124
- const gt = (val1: Expression | string | number, val2: Expression | string | number) => generateExpression('gt', undefined, val1, val2);
125
- const gte = (val1: Expression | string | number, val2: Expression | string | number) => generateExpression('gte', undefined, val1, val2);
126
-
127
- /**
128
- * Generate a timestamp value (POSIX timestamp). T = T_ref + delta. If 'reference' is not defined, the current time will be used as a reference.
129
- * @param delta offset for the timestamp generation
130
- * @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)
131
- * @returns
132
- */
133
- const timestampWithOffset = (delta: Duration, reference?: number | Expression) => generateExpression(
134
- 'timestampWithOffset',
135
- undefined,
136
- durationObjectToSeconds(delta),
137
- reference ? reference : undefined
138
- )
139
-
140
- /**
141
- * Control flow method to use an if-else like structure
142
- * @param condition expression, return value interpreted as boolean
143
- * @param actionIfTrue if condition evaluates to true, this action will be performed.
144
- * @param actionIfFalse optional, if defined and the condition returns false, this action will be performed.
145
- * @returns
146
- */
147
- const IF = (condition: Expression, actionIfTrue: Expression, actionIfFalse?: Expression): Expression => generateExpression('IF', undefined, condition, actionIfTrue, actionIfFalse)
148
-
149
- /**
150
- * Perform a list of expressions / actions
151
- * @param args: list of expressions to be evaluated
152
- * @returns
153
- */
154
- const DO = (...args: Expression[]): Expression => generateExpression('DO', undefined, ...args)
155
-
156
- /**
157
- * Simple if statement (without else), that checks for the condition and executes the list of actions.
158
- * @param condition condition to check, return value interpreted as boolean
159
- * @param args list of actions to be performed if condition evaluates to true, otherwise they are ignored
160
- * @returns
161
- */
162
- const IFTHEN = (condition: Expression, ...args: Expression[]): Expression => generateExpression('IFTHEN', undefined, condition, ...args)
163
-
164
- /**
165
- * Update the participant's study status
166
- * @param status new status value
167
- * @returns
168
- */
169
- const UPDATE_STUDY_STATUS = (status: string): Expression => generateExpression('UPDATE_STUDY_STATUS', undefined, status)
170
-
171
- /**
172
- * Add or update a participant flag
173
- * @param key
174
- * @param newValue
175
- * @returns
176
- */
177
- const UPDATE_FLAG = (key: string, newValue: string) => generateExpression('UPDATE_FLAG', undefined, key, newValue)
178
-
179
- const REMOVE_FLAG = (key: string) => generateExpression('REMOVE_FLAG', undefined, key);
180
-
181
- const ADD_NEW_SURVEY = (surveyKey: string,
182
- category: 'prio' | 'normal' | 'optional',
183
- activeFrom?: number | Expression,
184
- activeUntil?: number | Expression) => generateExpression('ADD_NEW_SURVEY', undefined, surveyKey, activeFrom !== undefined ? activeFrom : 0, activeUntil !== undefined ? activeUntil : 0, category)
185
-
186
- const REMOVE_ALL_SURVEYS = () => generateExpression('REMOVE_ALL_SURVEYS')
187
-
188
- /**
189
- * When submitting the response, item response with the given key would be added to the report array
190
- * @param itemKey find and add this item to the report array
191
- * @returns
192
- */
193
- const ADD_REPORT = (itemKey: string) => generateExpression('ADD_REPORT', undefined, itemKey);
194
-
195
- const REMOVE_SURVEY_BY_KEY = (
196
- surveyKey: string,
197
- selector: 'first' | 'last' | 'all'
198
- ) => {
199
- if (selector === 'all') {
200
- return generateExpression('REMOVE_SURVEYS_BY_KEY', undefined, surveyKey);
201
- } else {
202
- return generateExpression('REMOVE_SURVEY_BY_KEY', undefined, surveyKey, selector);
203
- }
204
- }
205
-
206
- const REMOVE_ALL_REPORTS = () => generateExpression('REMOVE_ALL_REPORTS')
207
-
208
- const REMOVE_REPORT_BY_KEY = (
209
- surveyKey: string,
210
- selector: 'first' | 'last' | 'all'
211
- ) => {
212
- if (selector === 'all') {
213
- return generateExpression('REMOVE_REPORTS_BY_KEY', undefined, surveyKey);
214
- } else {
215
- return generateExpression('REMOVE_REPORT_BY_KEY', undefined, surveyKey, selector);
216
- }
217
- }
218
-
219
- // ##################
220
- // Extra methods:
221
-
222
- const singleChoiceOptionsSelected = (itemKey: string, ...optionKeys: string[]) => generateExpression('responseHasKeysAny', undefined, itemKey, [responseGroupKey, singleChoiceKey].join('.'), ...optionKeys)
223
- const multipleChoiceOptionsSelected = (itemKey: string, ...optionKeys: string[]) => generateExpression('responseHasKeysAny', undefined, itemKey, [responseGroupKey, multipleChoiceKey].join('.'), ...optionKeys)
224
-
225
- const multipleChoiceAllOfTheseSelected = (itemKey: string, ...optionKeys: string[]) => and(
226
- ...optionKeys.map(option => generateExpression('responseHasKeysAny', undefined, itemKey, [responseGroupKey, multipleChoiceKey].join('.'), option))
227
- );
228
-
229
-
230
- const multipleChoiceOnlyOtherKeysSelected = (itemKey: string, ...optionKeys: string[]) => generateExpression('responseHasOnlyKeysOtherThan', undefined, itemKey, [responseGroupKey, multipleChoiceKey].join('.'), ...optionKeys)
231
- const singleChoiceOnlyOtherOptionSelected = (itemKey: string, ...optionKeys: string[]) => generateExpression('responseHasOnlyKeysOtherThan', undefined, itemKey, [responseGroupKey, singleChoiceKey].join('.'), ...optionKeys)
232
-
233
- const stopParticipation = () => UPDATE_STUDY_STATUS('inactive');
234
- const finishParticipation = () => UPDATE_STUDY_STATUS('finished');
235
-
236
- /**
237
- * If a survey is assigned with validFrom <= now and validUnil >= now
238
- * @param surveyKey which survey it should check for
239
- * @returns
240
- */
241
- const hasSurveyKeyActive = (surveyKey: string) => {
242
- return and(
243
- lte(
244
- getSurveyKeyAssignedFrom(surveyKey),
245
- timestampWithOffset({ seconds: 1 })
246
- ),
247
- gte(
248
- getSurveyKeyAssignedUntil(surveyKey),
249
- timestampWithOffset({ seconds: -1 })
250
- ),
251
- )
252
- }
253
-
254
- /**
255
- * Results of "T_ref = reference + delta" will be checked against "validFrom" of the assinged survey (if present). True T_ref > T_validFrom.
256
- * @param surveyKey which survey it should check for
257
- * @param delta delta time to the reference time (by default current time).
258
- * @param reference optional reference time. If undefined it will take the current time.
259
- * @returns
260
- */
261
- const hasSurveyKeyValidFromOlderThan = (surveyKey: string, delta: Duration, reference?: number | Expression) => {
262
- return lt(
263
- getSurveyKeyAssignedFrom(surveyKey),
264
- timestampWithOffset(delta, reference)
265
- );
266
- }
267
-
268
- /**
269
- * Results of "T_ref = reference + delta" will be checked against "validUntil" of the assinged survey (if present). True T_ref < T_validUntil.
270
- * @param surveyKey which survey it should check for
271
- * @param delta delta time to the reference time (by default current time).
272
- * @param reference optional reference time. If undefined it will take the current time.
273
- * @returns
274
- */
275
- const hasSurveyKeyValidUntilSoonerThan = (surveyKey: string, delta: Duration, reference?: number | Expression) => {
276
- return gt(
277
- timestampWithOffset(delta, reference),
278
- getSurveyKeyAssignedUntil(surveyKey)
279
- );
280
- }
281
-
282
- export const NativeStudyEngineExpressions = {
283
- checkEventType,
284
- // Response checkers
285
- checkSurveyResponseKey,
286
- responseHasKeysAny,
287
- responseHasOnlyKeysOtherThan,
288
- getResponseValueAsNum,
289
- getResponseValueAsStr,
290
- countResponseItems,
291
- // Old responses
292
- checkConditionForOldResponses,
293
- // Participant state:
294
- participantState: {
295
- getStudyEntryTime,
296
- hasSurveyKeyAssigned,
297
- getSurveyKeyAssignedFrom,
298
- getSurveyKeyAssignedUntil,
299
- hasStudyStatus,
300
- hasParticipantFlag,
301
- lastSubmissionDateOlderThan,
302
- },
303
- // logical and comparision
304
- eq,
305
- lt,
306
- lte,
307
- gt,
308
- gte,
309
- or,
310
- and,
311
- not,
312
-
313
- // Other
314
- timestampWithOffset,
315
- }
316
-
317
- export const StudyEngineActions = {
318
- if: IF,
319
- do: DO,
320
- ifThen: IFTHEN,
321
- participantActions: {
322
- updateStudyStatus: UPDATE_STUDY_STATUS,
323
- updateFlag: UPDATE_FLAG,
324
- removeFlag: REMOVE_FLAG,
325
- assignedSurveys: {
326
- add: ADD_NEW_SURVEY,
327
- removeAll: REMOVE_ALL_SURVEYS,
328
- remove: REMOVE_SURVEY_BY_KEY,
329
- },
330
- reports: {
331
- add: ADD_REPORT,
332
- removeAll: REMOVE_ALL_REPORTS,
333
- remove: REMOVE_REPORT_BY_KEY,
334
- },
335
-
336
- // Extra methods:
337
- stopParticipation,
338
- finishParticipation,
339
- }
340
- }
341
-
342
- export const StudyEngine = {
343
- ...NativeStudyEngineExpressions,
344
- ...StudyEngineActions,
345
- singleChoice: {
346
- any: singleChoiceOptionsSelected,
347
- none: singleChoiceOnlyOtherOptionSelected
348
- },
349
- multipleChoice: {
350
- any: multipleChoiceOptionsSelected,
351
- none: multipleChoiceOnlyOtherKeysSelected,
352
- all: multipleChoiceAllOfTheseSelected,
353
- },
354
- survey: {
355
- isActive: hasSurveyKeyActive,
356
- validFromOlderThan: hasSurveyKeyValidFromOlderThan,
357
- validUntilSoonerThan: hasSurveyKeyValidUntilSoonerThan,
358
- }
359
- }