case-editor-tools 1.7.2 → 1.8.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.
- package/expression-utils/studyEngineExpressions.d.ts +32 -0
- package/expression-utils/studyEngineExpressions.js +39 -0
- package/expression-utils/studyEngineExpressions.js.map +1 -1
- package/package.json +1 -1
- package/surveys/survey-engine-expressions.d.ts +8 -0
- package/surveys/survey-engine-expressions.js +55 -0
- package/surveys/survey-engine-expressions.js.map +1 -1
|
@@ -57,6 +57,13 @@ export declare const NativeStudyEngineExpressions: {
|
|
|
57
57
|
getMessageNextTime: (messageType: string) => Expression;
|
|
58
58
|
};
|
|
59
59
|
};
|
|
60
|
+
getStudyVariable: {
|
|
61
|
+
boolean: (key: string | Expression) => Expression;
|
|
62
|
+
string: (key: string | Expression) => Expression;
|
|
63
|
+
int: (key: string | Expression) => Expression;
|
|
64
|
+
float: (key: string | Expression) => Expression;
|
|
65
|
+
date: (key: string | Expression) => Expression;
|
|
66
|
+
};
|
|
60
67
|
eq: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
|
|
61
68
|
lt: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
|
|
62
69
|
lte: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
|
|
@@ -68,9 +75,11 @@ export declare const NativeStudyEngineExpressions: {
|
|
|
68
75
|
sum: (...values: (Expression | number)[]) => Expression;
|
|
69
76
|
neg: (value: Expression | number) => Expression;
|
|
70
77
|
timestampWithOffset: (delta: Duration, reference?: number | Expression) => Expression;
|
|
78
|
+
timestampDiff: (laterTimestamp: number | Expression, earlierTimestamp: number | Expression) => Expression;
|
|
71
79
|
getISOWeekForTs: (ts: number | Expression) => Expression;
|
|
72
80
|
getTsForNextStartOfMonth: (month: Month | Expression, reference?: number | Expression) => Expression;
|
|
73
81
|
getTsForNextISOWeek: (ISOWeek: number | Expression, reference?: number | Expression) => Expression;
|
|
82
|
+
getTsForStartOfISOWeek: (reference?: number | Expression) => Expression;
|
|
74
83
|
parseValueAsNum: (valueRef: Expression | string | number) => Expression;
|
|
75
84
|
generateRandomNumber: (min: number, max: number) => Expression;
|
|
76
85
|
externalEventEval: (serviceName: string, route?: string, expectFloat?: boolean) => Expression;
|
|
@@ -119,6 +128,13 @@ export declare const StudyEngineActions: {
|
|
|
119
128
|
stopParticipation: () => Expression;
|
|
120
129
|
finishParticipation: () => Expression;
|
|
121
130
|
};
|
|
131
|
+
updateStudyVariable: {
|
|
132
|
+
boolean: (key: string | Expression, value: Expression) => Expression;
|
|
133
|
+
string: (key: string | Expression, value: Expression | string) => Expression;
|
|
134
|
+
int: (key: string | Expression, value: number | Expression) => Expression;
|
|
135
|
+
float: (key: string | Expression, value: number | Expression) => Expression;
|
|
136
|
+
date: (key: string | Expression, value: number | Expression) => Expression;
|
|
137
|
+
};
|
|
122
138
|
removeStudyCode: (listKey: string | Expression, code: string | Expression) => Expression;
|
|
123
139
|
resetStudyCounter: (scopeKey: string | Expression) => Expression;
|
|
124
140
|
notifyResearcher: (messageType: string, ...payload: Expression[] | string[]) => Expression;
|
|
@@ -195,6 +211,13 @@ export declare const StudyEngine: {
|
|
|
195
211
|
stopParticipation: () => Expression;
|
|
196
212
|
finishParticipation: () => Expression;
|
|
197
213
|
};
|
|
214
|
+
updateStudyVariable: {
|
|
215
|
+
boolean: (key: string | Expression, value: Expression) => Expression;
|
|
216
|
+
string: (key: string | Expression, value: Expression | string) => Expression;
|
|
217
|
+
int: (key: string | Expression, value: number | Expression) => Expression;
|
|
218
|
+
float: (key: string | Expression, value: number | Expression) => Expression;
|
|
219
|
+
date: (key: string | Expression, value: number | Expression) => Expression;
|
|
220
|
+
};
|
|
198
221
|
removeStudyCode: (listKey: string | Expression, code: string | Expression) => Expression;
|
|
199
222
|
resetStudyCounter: (scopeKey: string | Expression) => Expression;
|
|
200
223
|
notifyResearcher: (messageType: string, ...payload: Expression[] | string[]) => Expression;
|
|
@@ -253,6 +276,13 @@ export declare const StudyEngine: {
|
|
|
253
276
|
getMessageNextTime: (messageType: string) => Expression;
|
|
254
277
|
};
|
|
255
278
|
};
|
|
279
|
+
getStudyVariable: {
|
|
280
|
+
boolean: (key: string | Expression) => Expression;
|
|
281
|
+
string: (key: string | Expression) => Expression;
|
|
282
|
+
int: (key: string | Expression) => Expression;
|
|
283
|
+
float: (key: string | Expression) => Expression;
|
|
284
|
+
date: (key: string | Expression) => Expression;
|
|
285
|
+
};
|
|
256
286
|
eq: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
|
|
257
287
|
lt: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
|
|
258
288
|
lte: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
|
|
@@ -264,9 +294,11 @@ export declare const StudyEngine: {
|
|
|
264
294
|
sum: (...values: (Expression | number)[]) => Expression;
|
|
265
295
|
neg: (value: Expression | number) => Expression;
|
|
266
296
|
timestampWithOffset: (delta: Duration, reference?: number | Expression) => Expression;
|
|
297
|
+
timestampDiff: (laterTimestamp: number | Expression, earlierTimestamp: number | Expression) => Expression;
|
|
267
298
|
getISOWeekForTs: (ts: number | Expression) => Expression;
|
|
268
299
|
getTsForNextStartOfMonth: (month: Month | Expression, reference?: number | Expression) => Expression;
|
|
269
300
|
getTsForNextISOWeek: (ISOWeek: number | Expression, reference?: number | Expression) => Expression;
|
|
301
|
+
getTsForStartOfISOWeek: (reference?: number | Expression) => Expression;
|
|
270
302
|
parseValueAsNum: (valueRef: Expression | string | number) => Expression;
|
|
271
303
|
generateRandomNumber: (min: number, max: number) => Expression;
|
|
272
304
|
externalEventEval: (serviceName: string, route?: string, expectFloat?: boolean) => Expression;
|
|
@@ -209,6 +209,16 @@ const getLastSubmissionDateForIncoming = (surveyKey) => expressionUtils_expressi
|
|
|
209
209
|
*/
|
|
210
210
|
const lastSubmissionDateOlderThan = (reference, surveyKey) => expressionUtils_expressionGen.generateExpression('lastSubmissionDateOlderThan', undefined, reference, surveyKey);
|
|
211
211
|
const lastSubmissionDateOlderThanForIncoming = (reference, surveyKey) => expressionUtils_expressionGen.generateExpression('incomingState:lastSubmissionDateOlderThan', undefined, reference, surveyKey);
|
|
212
|
+
const getStudyVariableBoolean = (key) => expressionUtils_expressionGen.generateExpression('getStudyVariableBoolean', undefined, key);
|
|
213
|
+
const getStudyVariableString = (key) => expressionUtils_expressionGen.generateExpression('getStudyVariableString', undefined, key);
|
|
214
|
+
const getStudyVariableInt = (key) => expressionUtils_expressionGen.generateExpression('getStudyVariableInt', undefined, key);
|
|
215
|
+
const getStudyVariableFloat = (key) => expressionUtils_expressionGen.generateExpression('getStudyVariableFloat', undefined, key);
|
|
216
|
+
const getStudyVariableDate = (key) => expressionUtils_expressionGen.generateExpression('getStudyVariableDate', undefined, key);
|
|
217
|
+
const UPDATE_STUDY_VARIABLE_BOOLEAN = (key, value) => expressionUtils_expressionGen.generateExpression('UPDATE_STUDY_VARIABLE_BOOLEAN', undefined, key, value);
|
|
218
|
+
const UPDATE_STUDY_VARIABLE_STRING = (key, value) => expressionUtils_expressionGen.generateExpression('UPDATE_STUDY_VARIABLE_STRING', undefined, key, value);
|
|
219
|
+
const UPDATE_STUDY_VARIABLE_INT = (key, value) => expressionUtils_expressionGen.generateExpression('UPDATE_STUDY_VARIABLE_INT', undefined, key, value);
|
|
220
|
+
const UPDATE_STUDY_VARIABLE_FLOAT = (key, value) => expressionUtils_expressionGen.generateExpression('UPDATE_STUDY_VARIABLE_FLOAT', undefined, key, value);
|
|
221
|
+
const UPDATE_STUDY_VARIABLE_DATE = (key, value) => expressionUtils_expressionGen.generateExpression('UPDATE_STUDY_VARIABLE_DATE', undefined, key, value);
|
|
212
222
|
const eq = (val1, val2) => expressionUtils_expressionGen.generateExpression('eq', undefined, val1, val2);
|
|
213
223
|
const lt = (val1, val2) => expressionUtils_expressionGen.generateExpression('lt', undefined, val1, val2);
|
|
214
224
|
const lte = (val1, val2) => expressionUtils_expressionGen.generateExpression('lte', undefined, val1, val2);
|
|
@@ -229,6 +239,13 @@ const timestampWithOffset = (delta, reference) => expressionUtils_expressionGen.
|
|
|
229
239
|
* @returns
|
|
230
240
|
*/
|
|
231
241
|
const getISOWeekForTs = (ts) => expressionUtils_expressionGen.generateExpression('getISOWeekForTs', undefined, ts);
|
|
242
|
+
/**
|
|
243
|
+
* Calculate the signed difference between two POSIX timestamps in seconds.
|
|
244
|
+
* @param laterTimestamp timestamp or expression returning a timestamp
|
|
245
|
+
* @param earlierTimestamp timestamp or expression returning a timestamp
|
|
246
|
+
* @returns laterTimestamp minus earlierTimestamp, which may be negative
|
|
247
|
+
*/
|
|
248
|
+
const timestampDiff = (laterTimestamp, earlierTimestamp) => expressionUtils_expressionGen.generateExpression('timestampDiff', 'float', laterTimestamp, earlierTimestamp);
|
|
232
249
|
/**
|
|
233
250
|
* Generate a timestamp value (POSIX timestamp) for the beginning of the month for the first time that is later than the reference
|
|
234
251
|
* @param month which ISO week should be used for the timestamp generation
|
|
@@ -243,6 +260,12 @@ const getTsForNextStartOfMonth = (month, reference) => expressionUtils_expressio
|
|
|
243
260
|
* @returns
|
|
244
261
|
*/
|
|
245
262
|
const getTsForNextISOWeek = (ISOWeek, reference) => expressionUtils_expressionGen.generateExpression('getTsForNextISOWeek', undefined, ISOWeek, reference ? reference : undefined);
|
|
263
|
+
/**
|
|
264
|
+
* Get the POSIX timestamp for Monday midnight of the ISO week containing the reference, using the backend's local timezone.
|
|
265
|
+
* @param reference optional timestamp or expression returning a timestamp; defaults to the current time
|
|
266
|
+
* @returns the start of the reference's ISO week in seconds
|
|
267
|
+
*/
|
|
268
|
+
const getTsForStartOfISOWeek = (reference) => expressionUtils_expressionGen.generateExpression('getTsForStartOfISOWeek', undefined, reference);
|
|
246
269
|
/**
|
|
247
270
|
* Attempt to parse the resolved argument's value as a number
|
|
248
271
|
* @param valueRef resolve this argument, and try to parse this as number. Boolean value will result in error.
|
|
@@ -608,6 +631,13 @@ const NativeStudyEngineExpressions = {
|
|
|
608
631
|
getMessageNextTime: getMessageNextTimeForIncoming,
|
|
609
632
|
}
|
|
610
633
|
},
|
|
634
|
+
getStudyVariable: {
|
|
635
|
+
boolean: getStudyVariableBoolean,
|
|
636
|
+
string: getStudyVariableString,
|
|
637
|
+
int: getStudyVariableInt,
|
|
638
|
+
float: getStudyVariableFloat,
|
|
639
|
+
date: getStudyVariableDate,
|
|
640
|
+
},
|
|
611
641
|
// logical and comparision
|
|
612
642
|
eq,
|
|
613
643
|
lt,
|
|
@@ -621,9 +651,11 @@ const NativeStudyEngineExpressions = {
|
|
|
621
651
|
neg,
|
|
622
652
|
// Other
|
|
623
653
|
timestampWithOffset,
|
|
654
|
+
timestampDiff,
|
|
624
655
|
getISOWeekForTs,
|
|
625
656
|
getTsForNextStartOfMonth,
|
|
626
657
|
getTsForNextISOWeek,
|
|
658
|
+
getTsForStartOfISOWeek,
|
|
627
659
|
parseValueAsNum,
|
|
628
660
|
generateRandomNumber: (min, max) => expressionUtils_expressionGen.generateExpression('generateRandomNumber', undefined, min, max),
|
|
629
661
|
externalEventEval,
|
|
@@ -674,6 +706,13 @@ const StudyEngineActions = {
|
|
|
674
706
|
stopParticipation,
|
|
675
707
|
finishParticipation,
|
|
676
708
|
},
|
|
709
|
+
updateStudyVariable: {
|
|
710
|
+
boolean: UPDATE_STUDY_VARIABLE_BOOLEAN,
|
|
711
|
+
string: UPDATE_STUDY_VARIABLE_STRING,
|
|
712
|
+
int: UPDATE_STUDY_VARIABLE_INT,
|
|
713
|
+
float: UPDATE_STUDY_VARIABLE_FLOAT,
|
|
714
|
+
date: UPDATE_STUDY_VARIABLE_DATE,
|
|
715
|
+
},
|
|
677
716
|
removeStudyCode: REMOVE_STUDY_CODE,
|
|
678
717
|
resetStudyCounter: RESET_STUDY_COUNTER,
|
|
679
718
|
notifyResearcher: NOTIFY_RESEARCHER,
|
|
@@ -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.
|
|
4
|
+
"version": "1.8.0",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": "github:case-framework/case-editor-tools",
|
|
@@ -81,6 +81,14 @@ export declare const SurveyEngine: {
|
|
|
81
81
|
hasKeyAndValue: (key: string, value: string | Expression) => Expression;
|
|
82
82
|
getAsNum: (key: string) => Expression;
|
|
83
83
|
};
|
|
84
|
+
studyVariables: {
|
|
85
|
+
hasKey: (key: string | Expression) => Expression;
|
|
86
|
+
getBoolean: (key: string | Expression) => Expression;
|
|
87
|
+
getString: (key: string | Expression) => Expression;
|
|
88
|
+
getInt: (key: string | Expression) => Expression;
|
|
89
|
+
getFloat: (key: string | Expression) => Expression;
|
|
90
|
+
getDate: (key: string | Expression) => Expression;
|
|
91
|
+
};
|
|
84
92
|
isLoggedIn: () => Expression;
|
|
85
93
|
getters: {
|
|
86
94
|
getContext: () => Expression;
|
|
@@ -321,6 +321,54 @@ const hasParticipantFlagKey = (key) => {
|
|
|
321
321
|
const hasParticipantFlagKeyAndValue = (key, value) => {
|
|
322
322
|
return expressionUtils_expressionGen.generateExpression('hasParticipantFlagKeyAndValue', undefined, key, value);
|
|
323
323
|
};
|
|
324
|
+
/**
|
|
325
|
+
* Check if a study variable is present
|
|
326
|
+
* @param key look up this study variable
|
|
327
|
+
* @returns return true if key is present. If any of the two is different, or study variables is empty, it returns false.
|
|
328
|
+
*/
|
|
329
|
+
const hasStudyVariableKey = (key) => {
|
|
330
|
+
return expressionUtils_expressionGen.generateExpression('hasStudyVariableKey', undefined, key);
|
|
331
|
+
};
|
|
332
|
+
/**
|
|
333
|
+
* Get a study variable value as a boolean
|
|
334
|
+
* @param key look up this study variable
|
|
335
|
+
* @returns return the value of the study variable
|
|
336
|
+
*/
|
|
337
|
+
const getStudyVariableBoolean = (key) => {
|
|
338
|
+
return expressionUtils_expressionGen.generateExpression('getStudyVariableBoolean', undefined, key);
|
|
339
|
+
};
|
|
340
|
+
/**
|
|
341
|
+
* Get a study variable value as a string
|
|
342
|
+
* @param key look up this study variable
|
|
343
|
+
* @returns return the value of the study variable
|
|
344
|
+
*/
|
|
345
|
+
const getStudyVariableString = (key) => {
|
|
346
|
+
return expressionUtils_expressionGen.generateExpression('getStudyVariableString', undefined, key);
|
|
347
|
+
};
|
|
348
|
+
/**
|
|
349
|
+
* Get a study variable value as an integer
|
|
350
|
+
* @param key look up this study variable
|
|
351
|
+
* @returns return the value of the study variable
|
|
352
|
+
*/
|
|
353
|
+
const getStudyVariableInt = (key) => {
|
|
354
|
+
return expressionUtils_expressionGen.generateExpression('getStudyVariableInt', undefined, key);
|
|
355
|
+
};
|
|
356
|
+
/**
|
|
357
|
+
* Get a study variable value as a float
|
|
358
|
+
* @param key look up this study variable
|
|
359
|
+
* @returns return the value of the study variable
|
|
360
|
+
*/
|
|
361
|
+
const getStudyVariableFloat = (key) => {
|
|
362
|
+
return expressionUtils_expressionGen.generateExpression('getStudyVariableFloat', undefined, key);
|
|
363
|
+
};
|
|
364
|
+
/**
|
|
365
|
+
* Get a study variable value as a date
|
|
366
|
+
* @param key look up this study variable
|
|
367
|
+
* @returns return the value of the study variable in posix timestamp format (seconds since 1970-01-01 00:00:00 UTC)
|
|
368
|
+
*/
|
|
369
|
+
const getStudyVariableDate = (key) => {
|
|
370
|
+
return expressionUtils_expressionGen.generateExpression('getStudyVariableDate', undefined, key);
|
|
371
|
+
};
|
|
324
372
|
/**
|
|
325
373
|
* Check if the participant is logged in currently.
|
|
326
374
|
* @returns true if context variable isLoggedIn is set and true
|
|
@@ -443,6 +491,13 @@ const SurveyEngine = Object.assign(Object.assign({}, NativeSurveyEngineExpressio
|
|
|
443
491
|
hasKey: hasParticipantFlagKey,
|
|
444
492
|
hasKeyAndValue: hasParticipantFlagKeyAndValue,
|
|
445
493
|
getAsNum: parseParticipantFlagAsNum,
|
|
494
|
+
}, studyVariables: {
|
|
495
|
+
hasKey: hasStudyVariableKey,
|
|
496
|
+
getBoolean: getStudyVariableBoolean,
|
|
497
|
+
getString: getStudyVariableString,
|
|
498
|
+
getInt: getStudyVariableInt,
|
|
499
|
+
getFloat: getStudyVariableFloat,
|
|
500
|
+
getDate: getStudyVariableDate,
|
|
446
501
|
}, isLoggedIn });
|
|
447
502
|
|
|
448
503
|
exports.NativeSurveyEngineExpressions = NativeSurveyEngineExpressions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"survey-engine-expressions.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"survey-engine-expressions.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|