case-editor-tools 1.0.0-beta.21 → 1.0.0-beta.25

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.
@@ -17,6 +17,8 @@ export declare const NativeStudyEngineExpressions: {
17
17
  hasStudyStatus: (status: string) => Expression;
18
18
  hasParticipantFlag: (key: string, value: string) => Expression;
19
19
  lastSubmissionDateOlderThan: (reference: number | Expression, surveyKey?: string | undefined) => Expression;
20
+ hasMessageTypeAssigned: (messageType: string) => Expression;
21
+ getMessageNextTime: (messageType: string) => Expression;
20
22
  };
21
23
  eq: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
22
24
  lt: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
@@ -46,6 +48,11 @@ export declare const StudyEngineActions: {
46
48
  removeAll: () => Expression;
47
49
  remove: (surveyKey: string, selector: 'first' | 'last' | 'all') => Expression;
48
50
  };
51
+ messages: {
52
+ add: (messageType: string, scheduledFor: number | Expression) => Expression;
53
+ removeAll: () => Expression;
54
+ remove: (messageType: string) => Expression;
55
+ };
49
56
  stopParticipation: () => Expression;
50
57
  finishParticipation: () => Expression;
51
58
  };
@@ -65,6 +72,16 @@ export declare const StudyEngine: {
65
72
  validFromOlderThan: (surveyKey: string, delta: Duration, reference?: number | Expression | undefined) => Expression;
66
73
  validUntilSoonerThan: (surveyKey: string, delta: Duration, reference?: number | Expression | undefined) => Expression;
67
74
  };
75
+ prefillRules: {
76
+ GET_LAST_SURVEY_ITEM: (surveyKey: string, itemKey: string, submittedLaterThan?: Duration | undefined) => Expression;
77
+ };
78
+ contextRules: {
79
+ previousResponses: {
80
+ LAST_RESPONSES_BY_KEY: (surveyKey: string, limit: number) => Expression;
81
+ ALL_RESPONSES_SINCE: (sinceTimestamp: number) => Expression;
82
+ RESPONSES_SINCE_BY_KEY: (sinceTimestamp: number, surveyKey: string) => Expression;
83
+ };
84
+ };
68
85
  if: (condition: Expression, actionIfTrue: Expression, actionIfFalse?: Expression | undefined) => Expression;
69
86
  do: (...args: Expression[]) => Expression;
70
87
  ifThen: (condition: Expression, ...args: Expression[]) => Expression;
@@ -82,6 +99,11 @@ export declare const StudyEngine: {
82
99
  removeAll: () => Expression;
83
100
  remove: (surveyKey: string, selector: 'first' | 'last' | 'all') => Expression;
84
101
  };
102
+ messages: {
103
+ add: (messageType: string, scheduledFor: number | Expression) => Expression;
104
+ removeAll: () => Expression;
105
+ remove: (messageType: string) => Expression;
106
+ };
85
107
  stopParticipation: () => Expression;
86
108
  finishParticipation: () => Expression;
87
109
  };
@@ -101,6 +123,8 @@ export declare const StudyEngine: {
101
123
  hasStudyStatus: (status: string) => Expression;
102
124
  hasParticipantFlag: (key: string, value: string) => Expression;
103
125
  lastSubmissionDateOlderThan: (reference: number | Expression, surveyKey?: string | undefined) => Expression;
126
+ hasMessageTypeAssigned: (messageType: string) => Expression;
127
+ getMessageNextTime: (messageType: string) => Expression;
104
128
  };
105
129
  eq: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
106
130
  lt: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
@@ -92,6 +92,18 @@ const hasStudyStatus = (status) => expressionUtils_expressionGen.generateExpress
92
92
  * @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.
93
93
  */
94
94
  const hasParticipantFlag = (key, value) => expressionUtils_expressionGen.generateExpression('hasParticipantFlag', undefined, key, value);
95
+ /**
96
+ * Checks if the participant has a message type assigned (at least one)
97
+ * @param messageType
98
+ * @returns return true if a message with the given message type is assigned
99
+ */
100
+ const hasMessageTypeAssigned = (messageType) => expressionUtils_expressionGen.generateExpression('hasMessageTypeAssigned', undefined, messageType);
101
+ /**
102
+ * Retrieve the timestamp (scheduledFor) for a particular message type. Return 0 if not assigned.
103
+ * @param messageType
104
+ * @returns timestamp value or zero
105
+ */
106
+ const getMessageNextTime = (messageType) => expressionUtils_expressionGen.generateExpression('getMessageNextTime', undefined, messageType);
95
107
  /**
96
108
  * Check if the last submission is older than the reference timestamp
97
109
  * @param reference look up this flag
@@ -148,6 +160,24 @@ const UPDATE_FLAG = (key, newValue) => expressionUtils_expressionGen.generateExp
148
160
  const REMOVE_FLAG = (key) => expressionUtils_expressionGen.generateExpression('REMOVE_FLAG', undefined, key);
149
161
  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);
150
162
  const REMOVE_ALL_SURVEYS = () => expressionUtils_expressionGen.generateExpression('REMOVE_ALL_SURVEYS');
163
+ /**
164
+ * Add participant message
165
+ * @param messageType message type
166
+ * @param scheduledFor timestamp or expression returning a timestamp
167
+ * @returns
168
+ */
169
+ const ADD_MESSAGE = (messageType, scheduledFor) => expressionUtils_expressionGen.generateExpression('ADD_MESSAGE', undefined, messageType, scheduledFor);
170
+ /**
171
+ * Remove all messages scheduled for the participant
172
+ * @returns
173
+ */
174
+ const REMOVE_ALL_MESSAGES = () => expressionUtils_expressionGen.generateExpression('REMOVE_ALL_MESSAGES', undefined);
175
+ /**
176
+ * Remove all messages with this message type
177
+ * @param messageType message type
178
+ * @returns
179
+ */
180
+ const REMOVE_MESSAGES_BY_TYPE = (messageType) => expressionUtils_expressionGen.generateExpression('REMOVE_MESSAGES_BY_TYPE', undefined, messageType);
151
181
  /**
152
182
  * When submitting the response, item response with the given key would be added to the report array
153
183
  * @param itemKey find and add this item to the report array
@@ -172,6 +202,22 @@ const REMOVE_REPORT_BY_KEY = (surveyKey, selector) => {
172
202
  }
173
203
  };
174
204
  // ##################
205
+ // Prefill rule methods:
206
+ const GET_LAST_SURVEY_ITEM = (surveyKey, itemKey, submittedLaterThan) => {
207
+ return expressionUtils_expressionGen.generateExpression('GET_LAST_SURVEY_ITEM', undefined, surveyKey, itemKey, submittedLaterThan ? types_duration.durationObjectToSeconds(submittedLaterThan) : undefined);
208
+ };
209
+ // ##################
210
+ // Context previous responses methods:
211
+ const LAST_RESPONSES_BY_KEY = (surveyKey, limit) => {
212
+ return expressionUtils_expressionGen.generateExpression('LAST_RESPONSES_BY_KEY', undefined, surveyKey, limit);
213
+ };
214
+ const ALL_RESPONSES_SINCE = (sinceTimestamp) => {
215
+ return expressionUtils_expressionGen.generateExpression('ALL_RESPONSES_SINCE', undefined, sinceTimestamp);
216
+ };
217
+ const RESPONSES_SINCE_BY_KEY = (sinceTimestamp, surveyKey) => {
218
+ return expressionUtils_expressionGen.generateExpression('RESPONSES_SINCE_BY_KEY', undefined, sinceTimestamp, surveyKey);
219
+ };
220
+ // ##################
175
221
  // Extra methods:
176
222
  const singleChoiceOptionsSelected = (itemKey, ...optionKeys) => expressionUtils_expressionGen.generateExpression('responseHasKeysAny', undefined, itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.singleChoiceKey].join('.'), ...optionKeys);
177
223
  const multipleChoiceOptionsSelected = (itemKey, ...optionKeys) => expressionUtils_expressionGen.generateExpression('responseHasKeysAny', undefined, itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.multipleChoiceKey].join('.'), ...optionKeys);
@@ -228,6 +274,8 @@ const NativeStudyEngineExpressions = {
228
274
  hasStudyStatus,
229
275
  hasParticipantFlag,
230
276
  lastSubmissionDateOlderThan,
277
+ hasMessageTypeAssigned,
278
+ getMessageNextTime,
231
279
  },
232
280
  // logical and comparision
233
281
  eq,
@@ -259,6 +307,11 @@ const StudyEngineActions = {
259
307
  removeAll: REMOVE_ALL_REPORTS,
260
308
  remove: REMOVE_REPORT_BY_KEY,
261
309
  },
310
+ messages: {
311
+ add: ADD_MESSAGE,
312
+ removeAll: REMOVE_ALL_MESSAGES,
313
+ remove: REMOVE_MESSAGES_BY_TYPE,
314
+ },
262
315
  // Extra methods:
263
316
  stopParticipation,
264
317
  finishParticipation,
@@ -275,6 +328,14 @@ const StudyEngine = Object.assign(Object.assign(Object.assign({}, NativeStudyEng
275
328
  isActive: hasSurveyKeyActive,
276
329
  validFromOlderThan: hasSurveyKeyValidFromOlderThan,
277
330
  validUntilSoonerThan: hasSurveyKeyValidUntilSoonerThan,
331
+ }, prefillRules: {
332
+ GET_LAST_SURVEY_ITEM,
333
+ }, contextRules: {
334
+ previousResponses: {
335
+ LAST_RESPONSES_BY_KEY,
336
+ ALL_RESPONSES_SINCE,
337
+ RESPONSES_SINCE_BY_KEY,
338
+ }
278
339
  } });
279
340
 
280
341
  exports.NativeStudyEngineExpressions = NativeStudyEngineExpressions;
@@ -1 +1 @@
1
- {"version":3,"file":"studyEngineExpressions.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"studyEngineExpressions.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "case-editor-tools",
3
3
  "description": "Javascript tools to simplify survey and study coding for CASE.",
4
- "version": "1.0.0-beta.21",
4
+ "version": "1.0.0-beta.25",
5
5
  "main": "index.js",
6
6
  "license": "Apache-2.0",
7
7
  "repository": "github:case-framework/case-editor-tools",
@@ -22,9 +22,10 @@ interface NumericSliderProps extends GenericQuestionProps {
22
22
  }
23
23
  interface CustomResponseItem extends ResponseComponent {
24
24
  mapToRole?: 'singleChoiceGroup' | 'multipleChoiceGroup' | 'input';
25
+ items?: ItemComponent[];
25
26
  }
26
27
  interface CustomQuestionProps extends GenericQuestionProps {
27
- responseItemDef: CustomResponseItem;
28
+ responseItemDefs: CustomResponseItem[];
28
29
  }
29
30
  interface DisplayProps {
30
31
  parentKey: string;
@@ -199,10 +199,44 @@ const generateClozeQuestion = (props) => {
199
199
  return commonQuestionGenerator(props, rg_inner);
200
200
  };
201
201
  const generateCustomQuestion = (props) => {
202
- const rolePrefix = props.responseItemDef.mapToRole !== undefined ? `${props.responseItemDef.mapToRole}` : '';
203
- const role = `${rolePrefix}:${props.responseItemDef.role}`;
204
- const rg_inner = Object.assign(Object.assign({}, props.responseItemDef), { role: role });
205
- return commonQuestionGenerator(props, rg_inner);
202
+ const items = [];
203
+ props.responseItemDefs.forEach(item => {
204
+ const rolePrefix = item.mapToRole !== undefined ? `${item.mapToRole}` : '';
205
+ const role = `${rolePrefix}:${item.role}`;
206
+ delete item['mapToRole'];
207
+ const rg_inner = Object.assign(Object.assign({}, item), { role: role });
208
+ items.push(rg_inner);
209
+ });
210
+ const simpleEditor = new surveys_utils_simpleQuestionEditor.SimpleQuestionEditor(props.parentKey, props.itemKey, props.version ? props.version : 1);
211
+ // QUESTION TEXT
212
+ simpleEditor.setTitle(props.questionText, props.questionSubText, props.titleClassName);
213
+ if (props.condition) {
214
+ simpleEditor.setCondition(props.condition);
215
+ }
216
+ if (props.helpGroupContent) {
217
+ simpleEditor.editor.setHelpGroupComponent(surveys_utils_simpleGenerators.generateHelpGroupComponent(props.helpGroupContent));
218
+ }
219
+ if (props.topDisplayCompoments) {
220
+ props.topDisplayCompoments.forEach(comp => simpleEditor.addDisplayComponent(comp));
221
+ }
222
+ simpleEditor.editor.addExistingResponseComponent({
223
+ key: constants_keyDefinitions.responseGroupKey,
224
+ role: 'responseGroup',
225
+ items,
226
+ });
227
+ if (props.bottomDisplayCompoments) {
228
+ props.bottomDisplayCompoments.forEach(comp => simpleEditor.addDisplayComponent(comp));
229
+ }
230
+ if (props.isRequired) {
231
+ simpleEditor.addHasResponseValidation();
232
+ }
233
+ if (props.customValidations) {
234
+ props.customValidations.forEach(v => simpleEditor.editor.addValidation(v));
235
+ }
236
+ if (props.footnoteText) {
237
+ simpleEditor.addDisplayComponent(surveys_utils_componentGenerators.ComponentGenerators.footnote({ content: props.footnoteText }));
238
+ }
239
+ return simpleEditor.getItem();
206
240
  };
207
241
  const generateDisplay = (props) => {
208
242
  const simpleEditor = new surveys_utils_simpleQuestionEditor.SimpleQuestionEditor(props.parentKey, props.itemKey, 1);
@@ -1 +1 @@
1
- {"version":3,"file":"survey-items.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"survey-items.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}