lamp-core-lst 2026.1.21 → 2026.2.4
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/dist/service/Activity.service.d.ts +6 -0
- package/dist/service/Activity.service.js +18 -0
- package/dist/service/SurveyResponse.service.d.ts +86 -3
- package/dist/service/SurveyResponse.service.js +214 -2
- package/package.json +1 -1
- package/src/service/Activity.service.ts +39 -30
- package/src/service/SurveyResponse.service.ts +231 -10
|
@@ -134,6 +134,12 @@ export declare class ActivityService {
|
|
|
134
134
|
* @param binId
|
|
135
135
|
*/
|
|
136
136
|
deleteActivityBin(parentId: Identifier, binId: Identifier, isGlobalDelete?: boolean, isEdit?: boolean): Promise<Identifier>;
|
|
137
|
+
/**
|
|
138
|
+
* Edit Global bin.
|
|
139
|
+
*/
|
|
140
|
+
editBin(studyId: Identifier, binId: Identifier, body: {
|
|
141
|
+
label: string;
|
|
142
|
+
}): Promise<Identifier>;
|
|
137
143
|
}
|
|
138
144
|
/**
|
|
139
145
|
* Result of activity export
|
|
@@ -999,6 +999,24 @@ var ActivityService = /** @class */ (function () {
|
|
|
999
999
|
});
|
|
1000
1000
|
});
|
|
1001
1001
|
};
|
|
1002
|
+
/**
|
|
1003
|
+
* Edit Global bin.
|
|
1004
|
+
*/
|
|
1005
|
+
ActivityService.prototype.editBin = function (studyId, binId, body) {
|
|
1006
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1007
|
+
return __generator(this, function (_a) {
|
|
1008
|
+
switch (_a.label) {
|
|
1009
|
+
case 0:
|
|
1010
|
+
if (studyId === null || studyId === undefined)
|
|
1011
|
+
throw new Error("Required parameter studyId was null or undefined.");
|
|
1012
|
+
if (binId === null || binId === undefined)
|
|
1013
|
+
throw new Error("Required parameter binId was null or undefined.");
|
|
1014
|
+
return [4 /*yield*/, Fetch_1.Fetch.put("/activity/bin/" + studyId + "/" + binId, body, this.configuration)];
|
|
1015
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1016
|
+
}
|
|
1017
|
+
});
|
|
1018
|
+
});
|
|
1019
|
+
};
|
|
1002
1020
|
return ActivityService;
|
|
1003
1021
|
}());
|
|
1004
1022
|
exports.ActivityService = ActivityService;
|
|
@@ -7,7 +7,6 @@ export interface QuestionAnswer {
|
|
|
7
7
|
questionText?: string;
|
|
8
8
|
}
|
|
9
9
|
export interface SurveyResponse {
|
|
10
|
-
date: number;
|
|
11
10
|
timestamp: number;
|
|
12
11
|
displayableAnswers: QuestionAnswer[];
|
|
13
12
|
isPinned?: boolean;
|
|
@@ -28,7 +27,15 @@ export interface GroupedSurveyResponse {
|
|
|
28
27
|
groups: SurveyGroup[];
|
|
29
28
|
ungroupedSurveys: SurveyItem[];
|
|
30
29
|
}
|
|
30
|
+
export interface SingleActivitySurveyResponse {
|
|
31
|
+
id: string;
|
|
32
|
+
title: string;
|
|
33
|
+
binName?: string;
|
|
34
|
+
description?: string;
|
|
35
|
+
responses: SurveyResponse[];
|
|
36
|
+
}
|
|
31
37
|
export declare type FilterType = "weekly" | "daily" | "monthly" | "all" | "pinned";
|
|
38
|
+
export declare type SurveyFilter = "pinned" | "all";
|
|
32
39
|
export interface FilterParams {
|
|
33
40
|
filterType: FilterType;
|
|
34
41
|
date?: number;
|
|
@@ -37,6 +44,8 @@ export interface FilterParams {
|
|
|
37
44
|
month?: number;
|
|
38
45
|
year?: number;
|
|
39
46
|
limit?: number;
|
|
47
|
+
activityId?: string;
|
|
48
|
+
surveyFilter?: SurveyFilter;
|
|
40
49
|
}
|
|
41
50
|
export interface PinSurveyResponseParams {
|
|
42
51
|
activity_id: string;
|
|
@@ -57,13 +66,17 @@ export interface PinSurveyResponseResult {
|
|
|
57
66
|
success: boolean;
|
|
58
67
|
message: string;
|
|
59
68
|
}
|
|
69
|
+
export interface PinnedSurveyActivitiesResult {
|
|
70
|
+
activityIds: string[];
|
|
71
|
+
}
|
|
60
72
|
export declare class SurveyResponseService {
|
|
61
73
|
configuration?: Configuration;
|
|
62
74
|
/**
|
|
63
75
|
* Get survey responses for a participant grouped by survey groups from researcher settings
|
|
76
|
+
* If activityId is provided, returns only that activity's data in a simplified format (SingleActivitySurveyResponse)
|
|
64
77
|
* @param participantId - The participant ID
|
|
65
78
|
* @param filterParams - Filter parameters for the query
|
|
66
|
-
* @returns Promise<GroupedSurveyResponse>
|
|
79
|
+
* @returns Promise<GroupedSurveyResponse | SingleActivitySurveyResponse>
|
|
67
80
|
*
|
|
68
81
|
* @example
|
|
69
82
|
* // Get weekly responses (last 7 days)
|
|
@@ -103,8 +116,37 @@ export declare class SurveyResponseService {
|
|
|
103
116
|
* @example
|
|
104
117
|
* // Get latest 5 responses per survey
|
|
105
118
|
* const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'all', limit: 5 });
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* // Get responses for a specific activity only (returns SingleActivitySurveyResponse)
|
|
122
|
+
* const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'all', activityId: 'activity_id' });
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* // Get only pinned surveys
|
|
126
|
+
* const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'all', surveyFilter: 'pinned' });
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* // Get all surveys (default)
|
|
130
|
+
* const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'all', surveyFilter: 'all' });
|
|
131
|
+
*/
|
|
132
|
+
getSurveyResponses(participantId: Identifier, filterParams?: FilterParams): Promise<GroupedSurveyResponse | SingleActivitySurveyResponse>;
|
|
133
|
+
/**
|
|
134
|
+
* Get survey responses for a specific activity only
|
|
135
|
+
* Returns simplified format without groups structure
|
|
136
|
+
* @param participantId - The participant ID
|
|
137
|
+
* @param activityId - The activity ID to filter by
|
|
138
|
+
* @param filterParams - Optional additional filter parameters (excluding activityId)
|
|
139
|
+
* @returns Promise<SingleActivitySurveyResponse>
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* // Get all responses for a specific survey
|
|
143
|
+
* const result = await LAMP.SurveyResponse.getActivitySurveyResponses('participant_id', 'activity_id');
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* // Get latest 5 responses for a specific survey
|
|
147
|
+
* const result = await LAMP.SurveyResponse.getActivitySurveyResponses('participant_id', 'activity_id', { filterType: 'all', limit: 5 });
|
|
106
148
|
*/
|
|
107
|
-
|
|
149
|
+
getActivitySurveyResponses(participantId: Identifier, activityId: string, filterParams?: Omit<FilterParams, 'activityId'>): Promise<SingleActivitySurveyResponse>;
|
|
108
150
|
/**
|
|
109
151
|
* Get weekly survey responses for a participant (last 7 days including today)
|
|
110
152
|
* @param participantId - The participant ID
|
|
@@ -186,4 +228,45 @@ export declare class SurveyResponseService {
|
|
|
186
228
|
* const result = await LAMP.SurveyResponse.unpinSurveyResponse('participant_id', 'activity_id', 1700000000000);
|
|
187
229
|
*/
|
|
188
230
|
unpinSurveyResponse(participantId: Identifier, activityId: string, timestamp: number): Promise<PinSurveyResponseResult>;
|
|
231
|
+
/**
|
|
232
|
+
* Pin a survey activity for a study
|
|
233
|
+
* @param studyId - The study ID
|
|
234
|
+
* @param activityId - The survey activity ID to pin
|
|
235
|
+
* @returns Promise<PinSurveyResponseResult>
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* const result = await LAMP.SurveyResponse.pinSurveyActivity('study_id', 'activity_id');
|
|
239
|
+
*/
|
|
240
|
+
pinSurveyActivity(studyId: Identifier, activityId: string): Promise<PinSurveyResponseResult>;
|
|
241
|
+
/**
|
|
242
|
+
* Unpin a survey activity for a study
|
|
243
|
+
* @param studyId - The study ID
|
|
244
|
+
* @param activityId - The survey activity ID to unpin
|
|
245
|
+
* @returns Promise<PinSurveyResponseResult>
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* const result = await LAMP.SurveyResponse.unpinSurveyActivity('study_id', 'activity_id');
|
|
249
|
+
*/
|
|
250
|
+
unpinSurveyActivity(studyId: Identifier, activityId: string): Promise<PinSurveyResponseResult>;
|
|
251
|
+
/**
|
|
252
|
+
* Get all pinned survey activities for a study
|
|
253
|
+
* @param studyId - The study ID
|
|
254
|
+
* @returns Promise<PinnedSurveyActivitiesResult>
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* const result = await LAMP.SurveyResponse.getPinnedSurveyActivities('study_id');
|
|
258
|
+
* console.log(result.activityIds); // ['activity_id_1', 'activity_id_2']
|
|
259
|
+
*/
|
|
260
|
+
getPinnedSurveyActivities(studyId: Identifier): Promise<PinnedSurveyActivitiesResult>;
|
|
261
|
+
/**
|
|
262
|
+
* Get only pinned survey responses for pinned surveys only
|
|
263
|
+
* Combines surveyFilter: 'pinned' with filterType: 'all'
|
|
264
|
+
* @param participantId - The participant ID
|
|
265
|
+
* @returns Promise<GroupedSurveyResponse>
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* // Get responses only from pinned surveys
|
|
269
|
+
* const result = await LAMP.SurveyResponse.getPinnedSurveysResponses('participant_id');
|
|
270
|
+
*/
|
|
271
|
+
getPinnedSurveysResponses(participantId: Identifier): Promise<GroupedSurveyResponse>;
|
|
189
272
|
}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -43,9 +54,10 @@ var SurveyResponseService = /** @class */ (function () {
|
|
|
43
54
|
}
|
|
44
55
|
/**
|
|
45
56
|
* Get survey responses for a participant grouped by survey groups from researcher settings
|
|
57
|
+
* If activityId is provided, returns only that activity's data in a simplified format (SingleActivitySurveyResponse)
|
|
46
58
|
* @param participantId - The participant ID
|
|
47
59
|
* @param filterParams - Filter parameters for the query
|
|
48
|
-
* @returns Promise<GroupedSurveyResponse>
|
|
60
|
+
* @returns Promise<GroupedSurveyResponse | SingleActivitySurveyResponse>
|
|
49
61
|
*
|
|
50
62
|
* @example
|
|
51
63
|
* // Get weekly responses (last 7 days)
|
|
@@ -85,6 +97,18 @@ var SurveyResponseService = /** @class */ (function () {
|
|
|
85
97
|
* @example
|
|
86
98
|
* // Get latest 5 responses per survey
|
|
87
99
|
* const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'all', limit: 5 });
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* // Get responses for a specific activity only (returns SingleActivitySurveyResponse)
|
|
103
|
+
* const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'all', activityId: 'activity_id' });
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* // Get only pinned surveys
|
|
107
|
+
* const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'all', surveyFilter: 'pinned' });
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* // Get all surveys (default)
|
|
111
|
+
* const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'all', surveyFilter: 'all' });
|
|
88
112
|
*/
|
|
89
113
|
SurveyResponseService.prototype.getSurveyResponses = function (participantId, filterParams) {
|
|
90
114
|
var _a;
|
|
@@ -99,6 +123,15 @@ var SurveyResponseService = /** @class */ (function () {
|
|
|
99
123
|
}
|
|
100
124
|
if (((_a = this.configuration) === null || _a === void 0 ? void 0 : _a.base) === "https://demo.lamp.digital") {
|
|
101
125
|
// DEMO - return empty structure for demo mode
|
|
126
|
+
if (filterParams.activityId) {
|
|
127
|
+
return [2 /*return*/, Promise.resolve({
|
|
128
|
+
id: filterParams.activityId,
|
|
129
|
+
title: "",
|
|
130
|
+
binName: undefined,
|
|
131
|
+
description: undefined,
|
|
132
|
+
responses: [],
|
|
133
|
+
})];
|
|
134
|
+
}
|
|
102
135
|
return [2 /*return*/, Promise.resolve({
|
|
103
136
|
groups: [],
|
|
104
137
|
ungroupedSurveys: [],
|
|
@@ -124,14 +157,69 @@ var SurveyResponseService = /** @class */ (function () {
|
|
|
124
157
|
if (filterParams.limit !== undefined) {
|
|
125
158
|
queryParams.set("limit", String(filterParams.limit));
|
|
126
159
|
}
|
|
127
|
-
|
|
160
|
+
if (filterParams.activityId !== undefined) {
|
|
161
|
+
queryParams.set("activityId", filterParams.activityId);
|
|
162
|
+
}
|
|
163
|
+
if (filterParams.surveyFilter !== undefined) {
|
|
164
|
+
queryParams.set("surveyFilter", filterParams.surveyFilter);
|
|
165
|
+
}
|
|
166
|
+
return [4 /*yield*/, Fetch_1.Fetch.get("/participant/" + participantId + "/survey_responses?" + queryParams.toString(), this.configuration)
|
|
167
|
+
// Return appropriate default based on whether activityId was provided
|
|
168
|
+
];
|
|
128
169
|
case 1:
|
|
129
170
|
result = _b.sent();
|
|
171
|
+
// Return appropriate default based on whether activityId was provided
|
|
172
|
+
if (filterParams.activityId) {
|
|
173
|
+
return [2 /*return*/, result.data || {
|
|
174
|
+
id: filterParams.activityId,
|
|
175
|
+
title: "",
|
|
176
|
+
binName: undefined,
|
|
177
|
+
description: undefined,
|
|
178
|
+
responses: []
|
|
179
|
+
}];
|
|
180
|
+
}
|
|
130
181
|
return [2 /*return*/, result.data || { groups: [], ungroupedSurveys: [] }];
|
|
131
182
|
}
|
|
132
183
|
});
|
|
133
184
|
});
|
|
134
185
|
};
|
|
186
|
+
/**
|
|
187
|
+
* Get survey responses for a specific activity only
|
|
188
|
+
* Returns simplified format without groups structure
|
|
189
|
+
* @param participantId - The participant ID
|
|
190
|
+
* @param activityId - The activity ID to filter by
|
|
191
|
+
* @param filterParams - Optional additional filter parameters (excluding activityId)
|
|
192
|
+
* @returns Promise<SingleActivitySurveyResponse>
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* // Get all responses for a specific survey
|
|
196
|
+
* const result = await LAMP.SurveyResponse.getActivitySurveyResponses('participant_id', 'activity_id');
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* // Get latest 5 responses for a specific survey
|
|
200
|
+
* const result = await LAMP.SurveyResponse.getActivitySurveyResponses('participant_id', 'activity_id', { filterType: 'all', limit: 5 });
|
|
201
|
+
*/
|
|
202
|
+
SurveyResponseService.prototype.getActivitySurveyResponses = function (participantId, activityId, filterParams) {
|
|
203
|
+
if (filterParams === void 0) { filterParams = { filterType: "all" }; }
|
|
204
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
205
|
+
var result;
|
|
206
|
+
return __generator(this, function (_a) {
|
|
207
|
+
switch (_a.label) {
|
|
208
|
+
case 0:
|
|
209
|
+
if (participantId === null || participantId === undefined) {
|
|
210
|
+
throw new Error("Required parameter participantId was null or undefined when calling getActivitySurveyResponses.");
|
|
211
|
+
}
|
|
212
|
+
if (!activityId) {
|
|
213
|
+
throw new Error("Required parameter activityId was null or undefined when calling getActivitySurveyResponses.");
|
|
214
|
+
}
|
|
215
|
+
return [4 /*yield*/, this.getSurveyResponses(participantId, __assign(__assign({}, filterParams), { activityId: activityId }))];
|
|
216
|
+
case 1:
|
|
217
|
+
result = _a.sent();
|
|
218
|
+
return [2 /*return*/, result];
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
};
|
|
135
223
|
/**
|
|
136
224
|
* Get weekly survey responses for a participant (last 7 days including today)
|
|
137
225
|
* @param participantId - The participant ID
|
|
@@ -366,6 +454,130 @@ var SurveyResponseService = /** @class */ (function () {
|
|
|
366
454
|
});
|
|
367
455
|
});
|
|
368
456
|
};
|
|
457
|
+
// ==================== SURVEY ACTIVITY PIN METHODS ====================
|
|
458
|
+
/**
|
|
459
|
+
* Pin a survey activity for a study
|
|
460
|
+
* @param studyId - The study ID
|
|
461
|
+
* @param activityId - The survey activity ID to pin
|
|
462
|
+
* @returns Promise<PinSurveyResponseResult>
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* const result = await LAMP.SurveyResponse.pinSurveyActivity('study_id', 'activity_id');
|
|
466
|
+
*/
|
|
467
|
+
SurveyResponseService.prototype.pinSurveyActivity = function (studyId, activityId) {
|
|
468
|
+
var _a;
|
|
469
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
470
|
+
var result;
|
|
471
|
+
return __generator(this, function (_b) {
|
|
472
|
+
switch (_b.label) {
|
|
473
|
+
case 0:
|
|
474
|
+
if (studyId === null || studyId === undefined) {
|
|
475
|
+
throw new Error("Required parameter studyId was null or undefined when calling pinSurveyActivity.");
|
|
476
|
+
}
|
|
477
|
+
if (!activityId) {
|
|
478
|
+
throw new Error("Required parameter activityId was null or undefined when calling pinSurveyActivity.");
|
|
479
|
+
}
|
|
480
|
+
if (((_a = this.configuration) === null || _a === void 0 ? void 0 : _a.base) === "https://demo.lamp.digital") {
|
|
481
|
+
// DEMO
|
|
482
|
+
return [2 /*return*/, Promise.resolve({ error: "500.demo-restriction" })];
|
|
483
|
+
}
|
|
484
|
+
return [4 /*yield*/, Fetch_1.Fetch.post("/study/" + studyId + "/survey_activities/pin", {
|
|
485
|
+
activity_id: activityId,
|
|
486
|
+
}, this.configuration)];
|
|
487
|
+
case 1:
|
|
488
|
+
result = _b.sent();
|
|
489
|
+
return [2 /*return*/, result.data || { success: false, message: "Unknown error" }];
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
});
|
|
493
|
+
};
|
|
494
|
+
/**
|
|
495
|
+
* Unpin a survey activity for a study
|
|
496
|
+
* @param studyId - The study ID
|
|
497
|
+
* @param activityId - The survey activity ID to unpin
|
|
498
|
+
* @returns Promise<PinSurveyResponseResult>
|
|
499
|
+
*
|
|
500
|
+
* @example
|
|
501
|
+
* const result = await LAMP.SurveyResponse.unpinSurveyActivity('study_id', 'activity_id');
|
|
502
|
+
*/
|
|
503
|
+
SurveyResponseService.prototype.unpinSurveyActivity = function (studyId, activityId) {
|
|
504
|
+
var _a;
|
|
505
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
506
|
+
var result;
|
|
507
|
+
return __generator(this, function (_b) {
|
|
508
|
+
switch (_b.label) {
|
|
509
|
+
case 0:
|
|
510
|
+
if (studyId === null || studyId === undefined) {
|
|
511
|
+
throw new Error("Required parameter studyId was null or undefined when calling unpinSurveyActivity.");
|
|
512
|
+
}
|
|
513
|
+
if (!activityId) {
|
|
514
|
+
throw new Error("Required parameter activityId was null or undefined when calling unpinSurveyActivity.");
|
|
515
|
+
}
|
|
516
|
+
if (((_a = this.configuration) === null || _a === void 0 ? void 0 : _a.base) === "https://demo.lamp.digital") {
|
|
517
|
+
// DEMO
|
|
518
|
+
return [2 /*return*/, Promise.resolve({ error: "500.demo-restriction" })];
|
|
519
|
+
}
|
|
520
|
+
return [4 /*yield*/, Fetch_1.Fetch.delete("/study/" + studyId + "/survey_activities/pin", this.configuration, {
|
|
521
|
+
activity_id: activityId,
|
|
522
|
+
})];
|
|
523
|
+
case 1:
|
|
524
|
+
result = _b.sent();
|
|
525
|
+
return [2 /*return*/, result.data || { success: false, message: "Unknown error" }];
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
});
|
|
529
|
+
};
|
|
530
|
+
/**
|
|
531
|
+
* Get all pinned survey activities for a study
|
|
532
|
+
* @param studyId - The study ID
|
|
533
|
+
* @returns Promise<PinnedSurveyActivitiesResult>
|
|
534
|
+
*
|
|
535
|
+
* @example
|
|
536
|
+
* const result = await LAMP.SurveyResponse.getPinnedSurveyActivities('study_id');
|
|
537
|
+
* console.log(result.activityIds); // ['activity_id_1', 'activity_id_2']
|
|
538
|
+
*/
|
|
539
|
+
SurveyResponseService.prototype.getPinnedSurveyActivities = function (studyId) {
|
|
540
|
+
var _a;
|
|
541
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
542
|
+
var result;
|
|
543
|
+
return __generator(this, function (_b) {
|
|
544
|
+
switch (_b.label) {
|
|
545
|
+
case 0:
|
|
546
|
+
if (studyId === null || studyId === undefined) {
|
|
547
|
+
throw new Error("Required parameter studyId was null or undefined when calling getPinnedSurveyActivities.");
|
|
548
|
+
}
|
|
549
|
+
if (((_a = this.configuration) === null || _a === void 0 ? void 0 : _a.base) === "https://demo.lamp.digital") {
|
|
550
|
+
// DEMO
|
|
551
|
+
return [2 /*return*/, Promise.resolve({ activityIds: [] })];
|
|
552
|
+
}
|
|
553
|
+
return [4 /*yield*/, Fetch_1.Fetch.get("/study/" + studyId + "/survey_activities/pinned", this.configuration)];
|
|
554
|
+
case 1:
|
|
555
|
+
result = _b.sent();
|
|
556
|
+
return [2 /*return*/, result.data || { activityIds: [] }];
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
});
|
|
560
|
+
};
|
|
561
|
+
/**
|
|
562
|
+
* Get only pinned survey responses for pinned surveys only
|
|
563
|
+
* Combines surveyFilter: 'pinned' with filterType: 'all'
|
|
564
|
+
* @param participantId - The participant ID
|
|
565
|
+
* @returns Promise<GroupedSurveyResponse>
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* // Get responses only from pinned surveys
|
|
569
|
+
* const result = await LAMP.SurveyResponse.getPinnedSurveysResponses('participant_id');
|
|
570
|
+
*/
|
|
571
|
+
SurveyResponseService.prototype.getPinnedSurveysResponses = function (participantId) {
|
|
572
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
573
|
+
return __generator(this, function (_a) {
|
|
574
|
+
return [2 /*return*/, this.getSurveyResponses(participantId, {
|
|
575
|
+
filterType: "all",
|
|
576
|
+
surveyFilter: "pinned",
|
|
577
|
+
})];
|
|
578
|
+
});
|
|
579
|
+
});
|
|
580
|
+
};
|
|
369
581
|
return SurveyResponseService;
|
|
370
582
|
}());
|
|
371
583
|
exports.SurveyResponseService = SurveyResponseService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lamp-core-lst",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.2.4",
|
|
4
4
|
"author": "BIDMC Division of Digital Psychiatry <team@digitalpsych.org>",
|
|
5
5
|
"description": "The JavaScript and TypeScript API client for the LAMP Platform.",
|
|
6
6
|
"homepage": "https://docs.lamp.digital/",
|
|
@@ -22,7 +22,7 @@ export class ActivityService {
|
|
|
22
22
|
return Promise.resolve(output)
|
|
23
23
|
}
|
|
24
24
|
return (await Fetch.get<{ data: any[] }>(`/activity`, this.configuration)).data?.map((x) =>
|
|
25
|
-
Object.assign(new Activity(), x)
|
|
25
|
+
Object.assign(new Activity(), x),
|
|
26
26
|
)
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -35,7 +35,7 @@ export class ActivityService {
|
|
|
35
35
|
transform?: string,
|
|
36
36
|
ignore_binary?: boolean,
|
|
37
37
|
limit?: number,
|
|
38
|
-
offset?: number
|
|
38
|
+
offset?: number,
|
|
39
39
|
): Promise<{ data: Activity[]; total: number }> {
|
|
40
40
|
if (participantId === null || participantId === undefined)
|
|
41
41
|
throw new Error("Required parameter participantId was null or undefined when calling activityAllByParticipant.")
|
|
@@ -51,7 +51,7 @@ export class ActivityService {
|
|
|
51
51
|
let output = Demo.Activity.filter((x) =>
|
|
52
52
|
Demo.Participant.filter((y) => y["id"] === participantId)
|
|
53
53
|
?.map((y) => y["#parent"])
|
|
54
|
-
.includes(x["#parent"])
|
|
54
|
+
.includes(x["#parent"]),
|
|
55
55
|
)?.map((x) => Object.assign(new Activity(), x))
|
|
56
56
|
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
57
57
|
// For demo, return all data with total count
|
|
@@ -74,7 +74,7 @@ export class ActivityService {
|
|
|
74
74
|
const queryString = params.toString()
|
|
75
75
|
const result: any = await Fetch.get<{ data: Activity[]; total?: number }>(
|
|
76
76
|
`/participant/${participantId}/activity?${queryString}`,
|
|
77
|
-
this.configuration
|
|
77
|
+
this.configuration,
|
|
78
78
|
)
|
|
79
79
|
|
|
80
80
|
// Handle the response structure based on _select function behavior:
|
|
@@ -125,7 +125,7 @@ export class ActivityService {
|
|
|
125
125
|
let output = Demo.Activity.filter((x) =>
|
|
126
126
|
Demo.Study.filter((y) => y["#parent"] === researcherId)
|
|
127
127
|
?.map((y) => y["id"])
|
|
128
|
-
.includes(x["#parent"])
|
|
128
|
+
.includes(x["#parent"]),
|
|
129
129
|
)?.map((x) => Object.assign(new Activity(), x))
|
|
130
130
|
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
131
131
|
return Promise.resolve(output)
|
|
@@ -134,7 +134,7 @@ export class ActivityService {
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
return (await Fetch.get<{ data: any[] }>(`/researcher/${researcherId}/activity`, this.configuration)).data?.map(
|
|
137
|
-
(x) => Object.assign(new Activity(), x)
|
|
137
|
+
(x) => Object.assign(new Activity(), x),
|
|
138
138
|
)
|
|
139
139
|
}
|
|
140
140
|
|
|
@@ -151,7 +151,7 @@ export class ActivityService {
|
|
|
151
151
|
transform?: string,
|
|
152
152
|
ignore_binary?: boolean,
|
|
153
153
|
limit?: number,
|
|
154
|
-
offset?: number
|
|
154
|
+
offset?: number,
|
|
155
155
|
): Promise<Activity[] | { data: Activity[]; total: number }> {
|
|
156
156
|
if (studyId === null || studyId === undefined)
|
|
157
157
|
throw new Error("Required parameter studyId was null or undefined when calling activityAllByStudy.")
|
|
@@ -192,7 +192,7 @@ export class ActivityService {
|
|
|
192
192
|
|
|
193
193
|
const result: any = await Fetch.get<{ data: Activity[]; total?: number }>(
|
|
194
194
|
`/study/${studyId}/activity?${queryString}`,
|
|
195
|
-
this.configuration
|
|
195
|
+
this.configuration,
|
|
196
196
|
)
|
|
197
197
|
|
|
198
198
|
// Handle the response structure based on _select function behavior:
|
|
@@ -227,7 +227,7 @@ export class ActivityService {
|
|
|
227
227
|
tab?: string,
|
|
228
228
|
transform?: string,
|
|
229
229
|
limit?: number,
|
|
230
|
-
offset?: number
|
|
230
|
+
offset?: number,
|
|
231
231
|
): Promise<{ data: any; total: number }> {
|
|
232
232
|
if (participantId === null || participantId === undefined)
|
|
233
233
|
throw new Error("Required parameter participantId was null or undefined when calling listActivities.")
|
|
@@ -241,7 +241,7 @@ export class ActivityService {
|
|
|
241
241
|
|
|
242
242
|
if (Demo.Participant.filter((x) => x["id"] === participantId).length > 0) {
|
|
243
243
|
let output = Demo.Activity.filter((x) => x["#parent"] === participantId)?.map((x) =>
|
|
244
|
-
Object.assign(new Activity(), x)
|
|
244
|
+
Object.assign(new Activity(), x),
|
|
245
245
|
)
|
|
246
246
|
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
247
247
|
return Promise.resolve({ data: output, total: output.length } as any)
|
|
@@ -259,7 +259,7 @@ export class ActivityService {
|
|
|
259
259
|
|
|
260
260
|
const result: any = await Fetch.get<{ data: any; total: number }>(
|
|
261
261
|
`/activity/${participantId}/activity${queryString ? `?${queryString}` : ""}`,
|
|
262
|
-
this.configuration
|
|
262
|
+
this.configuration,
|
|
263
263
|
)
|
|
264
264
|
|
|
265
265
|
// Handle different response structures
|
|
@@ -400,7 +400,7 @@ export class ActivityService {
|
|
|
400
400
|
}
|
|
401
401
|
const result: any = await Fetch.get<{ data: Activity }>(
|
|
402
402
|
`/activity/${activityId}?ignore_binary=${ignore_binary}`,
|
|
403
|
-
this.configuration
|
|
403
|
+
this.configuration,
|
|
404
404
|
)
|
|
405
405
|
// API returns { data: Activity } (single object, not array)
|
|
406
406
|
if (result && result.data) {
|
|
@@ -418,7 +418,7 @@ export class ActivityService {
|
|
|
418
418
|
moduleId: Identifier,
|
|
419
419
|
participantId: Identifier,
|
|
420
420
|
startTime?: number,
|
|
421
|
-
endTime?: number
|
|
421
|
+
endTime?: number,
|
|
422
422
|
): Promise<any[]> {
|
|
423
423
|
if (participantId === null || participantId === undefined)
|
|
424
424
|
throw new Error("Required parameter participantId was null or undefined when calling moduleByParticipant.")
|
|
@@ -434,7 +434,7 @@ export class ActivityService {
|
|
|
434
434
|
|
|
435
435
|
if (Demo.Activity.filter((x) => x["id"] === moduleId).length > 0) {
|
|
436
436
|
let output = Demo.Activity.filter((x) => x["#parent"] === moduleId)?.map((x) =>
|
|
437
|
-
Object.assign(new Activity(), x)
|
|
437
|
+
Object.assign(new Activity(), x),
|
|
438
438
|
)
|
|
439
439
|
|
|
440
440
|
return Promise.resolve(output)
|
|
@@ -452,7 +452,7 @@ export class ActivityService {
|
|
|
452
452
|
const queryString = params.toString()
|
|
453
453
|
const url = `/module/${moduleId}/${participantId}${queryString ? `?${queryString}` : ""}`
|
|
454
454
|
return (await Fetch.get<{ data: any[] }>(url, this.configuration)).data?.map((x) =>
|
|
455
|
-
Object.assign(new Activity(), x)
|
|
455
|
+
Object.assign(new Activity(), x),
|
|
456
456
|
)
|
|
457
457
|
}
|
|
458
458
|
|
|
@@ -463,7 +463,7 @@ export class ActivityService {
|
|
|
463
463
|
public async scheduledActivities(
|
|
464
464
|
participantId: Identifier,
|
|
465
465
|
transform?: string,
|
|
466
|
-
ignore_binary?: boolean
|
|
466
|
+
ignore_binary?: boolean,
|
|
467
467
|
): Promise<Activity[]> {
|
|
468
468
|
if (participantId === null || participantId === undefined)
|
|
469
469
|
throw new Error("Required parameter participantId was null or undefined when calling activityAllByParticipant.")
|
|
@@ -479,7 +479,7 @@ export class ActivityService {
|
|
|
479
479
|
let output = Demo.Activity.filter((x) =>
|
|
480
480
|
Demo.Participant.filter((y) => y["id"] === participantId)
|
|
481
481
|
?.map((y) => y["#parent"])
|
|
482
|
-
.includes(x["#parent"])
|
|
482
|
+
.includes(x["#parent"]),
|
|
483
483
|
)?.map((x) => Object.assign(new Activity(), x))
|
|
484
484
|
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
485
485
|
return Promise.resolve(output)
|
|
@@ -490,7 +490,7 @@ export class ActivityService {
|
|
|
490
490
|
|
|
491
491
|
const result = (await Fetch.get<{ data: any[] }>(
|
|
492
492
|
`/participant/${participantId}/activitySchedule?ignore_binary=${ignore_binary}`,
|
|
493
|
-
this.configuration
|
|
493
|
+
this.configuration,
|
|
494
494
|
)) as any
|
|
495
495
|
return result
|
|
496
496
|
}
|
|
@@ -513,7 +513,7 @@ export class ActivityService {
|
|
|
513
513
|
let output = Demo.Activity.filter((x) =>
|
|
514
514
|
Demo.Participant.filter((y) => y["id"] === participantId)
|
|
515
515
|
?.map((y) => y["#parent"])
|
|
516
|
-
.includes(x["#parent"])
|
|
516
|
+
.includes(x["#parent"]),
|
|
517
517
|
)?.map((x) => Object.assign(new Activity(), x))
|
|
518
518
|
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
519
519
|
return Promise.resolve(output)
|
|
@@ -524,7 +524,7 @@ export class ActivityService {
|
|
|
524
524
|
|
|
525
525
|
const result = (await Fetch.get<{ data: any[] }>(
|
|
526
526
|
`/participant/${participantId}/emptyTab`,
|
|
527
|
-
this.configuration
|
|
527
|
+
this.configuration,
|
|
528
528
|
)) as any
|
|
529
529
|
return result
|
|
530
530
|
}
|
|
@@ -553,7 +553,7 @@ export class ActivityService {
|
|
|
553
553
|
|
|
554
554
|
// Map "me" to the credential's origin if present
|
|
555
555
|
const resolvedActivities = activities.map((id) =>
|
|
556
|
-
id === "me" && credential[0]["origin"] ? credential[0]["origin"] : id
|
|
556
|
+
id === "me" && credential[0]["origin"] ? credential[0]["origin"] : id,
|
|
557
557
|
)
|
|
558
558
|
|
|
559
559
|
// Track deleted and not-found IDs (for debugging or reporting)
|
|
@@ -604,7 +604,7 @@ export class ActivityService {
|
|
|
604
604
|
let output = Demo.Activity.filter((x) =>
|
|
605
605
|
Demo.Participant.filter((y) => y["id"] === participantId)
|
|
606
606
|
?.map((y) => y["#parent"])
|
|
607
|
-
.includes(x["#parent"])
|
|
607
|
+
.includes(x["#parent"]),
|
|
608
608
|
)?.map((x) => Object.assign(new Activity(), x))
|
|
609
609
|
|
|
610
610
|
return Promise.resolve(output)
|
|
@@ -613,7 +613,7 @@ export class ActivityService {
|
|
|
613
613
|
}
|
|
614
614
|
}
|
|
615
615
|
return (await Fetch.post<{ data: any[] }>(`/feed/module/${participantId}`, this.configuration)).data?.map((x) =>
|
|
616
|
-
Object.assign(new Activity(), x)
|
|
616
|
+
Object.assign(new Activity(), x),
|
|
617
617
|
)
|
|
618
618
|
}
|
|
619
619
|
|
|
@@ -647,7 +647,7 @@ export class ActivityService {
|
|
|
647
647
|
|
|
648
648
|
const result = await Fetch.get<{ data: string[] }>(
|
|
649
649
|
`/participant/${participantId}/favorite_activities`,
|
|
650
|
-
this.configuration
|
|
650
|
+
this.configuration,
|
|
651
651
|
)
|
|
652
652
|
let output = result.data || []
|
|
653
653
|
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
@@ -730,7 +730,7 @@ export class ActivityService {
|
|
|
730
730
|
const result = await Fetch.post<{ data: ActivityExportResult[] }>(
|
|
731
731
|
`/activity/export`,
|
|
732
732
|
activityIds,
|
|
733
|
-
this.configuration
|
|
733
|
+
this.configuration,
|
|
734
734
|
)
|
|
735
735
|
return result.data || []
|
|
736
736
|
}
|
|
@@ -746,7 +746,7 @@ export class ActivityService {
|
|
|
746
746
|
public async importActivities(
|
|
747
747
|
studyId: Identifier,
|
|
748
748
|
activitiesWithAttachments: ActivityExportResult[],
|
|
749
|
-
options?: ActivityImportOptions
|
|
749
|
+
options?: ActivityImportOptions,
|
|
750
750
|
): Promise<ActivityImportResult> {
|
|
751
751
|
if (studyId === null || studyId === undefined) {
|
|
752
752
|
throw new Error("Required parameter studyId was null or undefined when calling importActivities.")
|
|
@@ -773,8 +773,8 @@ export class ActivityService {
|
|
|
773
773
|
const name = options?.namePrefix
|
|
774
774
|
? `${options.namePrefix}${item.activity.name}`
|
|
775
775
|
: options?.nameSuffix
|
|
776
|
-
|
|
777
|
-
|
|
776
|
+
? `${item.activity.name}${options.nameSuffix}`
|
|
777
|
+
: item.activity.name
|
|
778
778
|
|
|
779
779
|
Demo.Activity.push({
|
|
780
780
|
"#type": "Activity",
|
|
@@ -808,7 +808,7 @@ export class ActivityService {
|
|
|
808
808
|
const result = await Fetch.post<{ data: ActivityImportResult }>(
|
|
809
809
|
`/study/${studyId}/activity/import`,
|
|
810
810
|
{ activities: activitiesWithAttachments, options },
|
|
811
|
-
this.configuration
|
|
811
|
+
this.configuration,
|
|
812
812
|
)
|
|
813
813
|
return (
|
|
814
814
|
result.data || {
|
|
@@ -829,7 +829,7 @@ export class ActivityService {
|
|
|
829
829
|
parentId: Identifier,
|
|
830
830
|
binId: Identifier,
|
|
831
831
|
isGlobalDelete: boolean = false,
|
|
832
|
-
isEdit: boolean = false
|
|
832
|
+
isEdit: boolean = false,
|
|
833
833
|
): Promise<Identifier> {
|
|
834
834
|
if (parentId === null || parentId === undefined)
|
|
835
835
|
throw new Error("Required parameter parentId was null or undefined.")
|
|
@@ -884,6 +884,15 @@ export class ActivityService {
|
|
|
884
884
|
: `/activity/bin/${parentId}/${binId}`
|
|
885
885
|
return await Fetch.delete(route, this.configuration)
|
|
886
886
|
}
|
|
887
|
+
|
|
888
|
+
/**
|
|
889
|
+
* Edit Global bin.
|
|
890
|
+
*/
|
|
891
|
+
public async editBin(studyId: Identifier, binId: Identifier, body: { label: string }): Promise<Identifier> {
|
|
892
|
+
if (studyId === null || studyId === undefined) throw new Error("Required parameter studyId was null or undefined.")
|
|
893
|
+
if (binId === null || binId === undefined) throw new Error("Required parameter binId was null or undefined.")
|
|
894
|
+
return await Fetch.put(`/activity/bin/${studyId}/${binId}`, body, this.configuration)
|
|
895
|
+
}
|
|
887
896
|
}
|
|
888
897
|
|
|
889
898
|
/**
|
|
@@ -10,7 +10,6 @@ export interface QuestionAnswer {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface SurveyResponse {
|
|
13
|
-
date: number
|
|
14
13
|
timestamp: number
|
|
15
14
|
displayableAnswers: QuestionAnswer[] // Only answers from questions with displayInSurveyResponses: true
|
|
16
15
|
isPinned?: boolean
|
|
@@ -35,9 +34,21 @@ export interface GroupedSurveyResponse {
|
|
|
35
34
|
ungroupedSurveys: SurveyItem[]
|
|
36
35
|
}
|
|
37
36
|
|
|
37
|
+
// Single activity response when activityId filter is provided
|
|
38
|
+
export interface SingleActivitySurveyResponse {
|
|
39
|
+
id: string
|
|
40
|
+
title: string
|
|
41
|
+
binName?: string
|
|
42
|
+
description?: string
|
|
43
|
+
responses: SurveyResponse[]
|
|
44
|
+
}
|
|
45
|
+
|
|
38
46
|
// Filter types for survey responses
|
|
39
47
|
export type FilterType = "weekly" | "daily" | "monthly" | "all" | "pinned"
|
|
40
48
|
|
|
49
|
+
// Filter for survey activities (pinned vs all)
|
|
50
|
+
export type SurveyFilter = "pinned" | "all"
|
|
51
|
+
|
|
41
52
|
export interface FilterParams {
|
|
42
53
|
filterType: FilterType
|
|
43
54
|
date?: number // For daily filter - specific date timestamp
|
|
@@ -46,6 +57,8 @@ export interface FilterParams {
|
|
|
46
57
|
month?: number // For monthly filter (1-12)
|
|
47
58
|
year?: number // For monthly filter
|
|
48
59
|
limit?: number // Limit number of responses per survey (e.g., 5 for latest 5)
|
|
60
|
+
activityId?: string // Filter by specific survey activity ID
|
|
61
|
+
surveyFilter?: SurveyFilter // Filter surveys by pinned status (default: "all")
|
|
49
62
|
}
|
|
50
63
|
|
|
51
64
|
export interface PinSurveyResponseParams {
|
|
@@ -72,14 +85,19 @@ export interface PinSurveyResponseResult {
|
|
|
72
85
|
message: string
|
|
73
86
|
}
|
|
74
87
|
|
|
88
|
+
export interface PinnedSurveyActivitiesResult {
|
|
89
|
+
activityIds: string[]
|
|
90
|
+
}
|
|
91
|
+
|
|
75
92
|
export class SurveyResponseService {
|
|
76
93
|
public configuration?: Configuration
|
|
77
94
|
|
|
78
95
|
/**
|
|
79
96
|
* Get survey responses for a participant grouped by survey groups from researcher settings
|
|
97
|
+
* If activityId is provided, returns only that activity's data in a simplified format (SingleActivitySurveyResponse)
|
|
80
98
|
* @param participantId - The participant ID
|
|
81
99
|
* @param filterParams - Filter parameters for the query
|
|
82
|
-
* @returns Promise<GroupedSurveyResponse>
|
|
100
|
+
* @returns Promise<GroupedSurveyResponse | SingleActivitySurveyResponse>
|
|
83
101
|
*
|
|
84
102
|
* @example
|
|
85
103
|
* // Get weekly responses (last 7 days)
|
|
@@ -119,11 +137,23 @@ export class SurveyResponseService {
|
|
|
119
137
|
* @example
|
|
120
138
|
* // Get latest 5 responses per survey
|
|
121
139
|
* const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'all', limit: 5 });
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* // Get responses for a specific activity only (returns SingleActivitySurveyResponse)
|
|
143
|
+
* const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'all', activityId: 'activity_id' });
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* // Get only pinned surveys
|
|
147
|
+
* const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'all', surveyFilter: 'pinned' });
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* // Get all surveys (default)
|
|
151
|
+
* const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'all', surveyFilter: 'all' });
|
|
122
152
|
*/
|
|
123
153
|
public async getSurveyResponses(
|
|
124
154
|
participantId: Identifier,
|
|
125
155
|
filterParams: FilterParams = { filterType: "weekly" }
|
|
126
|
-
): Promise<GroupedSurveyResponse> {
|
|
156
|
+
): Promise<GroupedSurveyResponse | SingleActivitySurveyResponse> {
|
|
127
157
|
if (participantId === null || participantId === undefined) {
|
|
128
158
|
throw new Error(
|
|
129
159
|
"Required parameter participantId was null or undefined when calling getSurveyResponses."
|
|
@@ -132,6 +162,15 @@ export class SurveyResponseService {
|
|
|
132
162
|
|
|
133
163
|
if (this.configuration?.base === "https://demo.lamp.digital") {
|
|
134
164
|
// DEMO - return empty structure for demo mode
|
|
165
|
+
if (filterParams.activityId) {
|
|
166
|
+
return Promise.resolve({
|
|
167
|
+
id: filterParams.activityId,
|
|
168
|
+
title: "",
|
|
169
|
+
binName: undefined,
|
|
170
|
+
description: undefined,
|
|
171
|
+
responses: [],
|
|
172
|
+
})
|
|
173
|
+
}
|
|
135
174
|
return Promise.resolve({
|
|
136
175
|
groups: [],
|
|
137
176
|
ungroupedSurveys: [],
|
|
@@ -160,15 +199,71 @@ export class SurveyResponseService {
|
|
|
160
199
|
if (filterParams.limit !== undefined) {
|
|
161
200
|
queryParams.set("limit", String(filterParams.limit))
|
|
162
201
|
}
|
|
202
|
+
if (filterParams.activityId !== undefined) {
|
|
203
|
+
queryParams.set("activityId", filterParams.activityId)
|
|
204
|
+
}
|
|
205
|
+
if (filterParams.surveyFilter !== undefined) {
|
|
206
|
+
queryParams.set("surveyFilter", filterParams.surveyFilter)
|
|
207
|
+
}
|
|
163
208
|
|
|
164
|
-
const result = await Fetch.get<{ data: GroupedSurveyResponse }>(
|
|
209
|
+
const result = await Fetch.get<{ data: GroupedSurveyResponse | SingleActivitySurveyResponse }>(
|
|
165
210
|
`/participant/${participantId}/survey_responses?${queryParams.toString()}`,
|
|
166
211
|
this.configuration
|
|
167
212
|
)
|
|
168
213
|
|
|
214
|
+
// Return appropriate default based on whether activityId was provided
|
|
215
|
+
if (filterParams.activityId) {
|
|
216
|
+
return result.data || {
|
|
217
|
+
id: filterParams.activityId,
|
|
218
|
+
title: "",
|
|
219
|
+
binName: undefined,
|
|
220
|
+
description: undefined,
|
|
221
|
+
responses: []
|
|
222
|
+
}
|
|
223
|
+
}
|
|
169
224
|
return result.data || { groups: [], ungroupedSurveys: [] }
|
|
170
225
|
}
|
|
171
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Get survey responses for a specific activity only
|
|
229
|
+
* Returns simplified format without groups structure
|
|
230
|
+
* @param participantId - The participant ID
|
|
231
|
+
* @param activityId - The activity ID to filter by
|
|
232
|
+
* @param filterParams - Optional additional filter parameters (excluding activityId)
|
|
233
|
+
* @returns Promise<SingleActivitySurveyResponse>
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* // Get all responses for a specific survey
|
|
237
|
+
* const result = await LAMP.SurveyResponse.getActivitySurveyResponses('participant_id', 'activity_id');
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* // Get latest 5 responses for a specific survey
|
|
241
|
+
* const result = await LAMP.SurveyResponse.getActivitySurveyResponses('participant_id', 'activity_id', { filterType: 'all', limit: 5 });
|
|
242
|
+
*/
|
|
243
|
+
public async getActivitySurveyResponses(
|
|
244
|
+
participantId: Identifier,
|
|
245
|
+
activityId: string,
|
|
246
|
+
filterParams: Omit<FilterParams, 'activityId'> = { filterType: "all" }
|
|
247
|
+
): Promise<SingleActivitySurveyResponse> {
|
|
248
|
+
if (participantId === null || participantId === undefined) {
|
|
249
|
+
throw new Error(
|
|
250
|
+
"Required parameter participantId was null or undefined when calling getActivitySurveyResponses."
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
if (!activityId) {
|
|
254
|
+
throw new Error(
|
|
255
|
+
"Required parameter activityId was null or undefined when calling getActivitySurveyResponses."
|
|
256
|
+
)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const result = await this.getSurveyResponses(participantId, {
|
|
260
|
+
...filterParams,
|
|
261
|
+
activityId,
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
return result as SingleActivitySurveyResponse
|
|
265
|
+
}
|
|
266
|
+
|
|
172
267
|
/**
|
|
173
268
|
* Get weekly survey responses for a participant (last 7 days including today)
|
|
174
269
|
* @param participantId - The participant ID
|
|
@@ -185,7 +280,7 @@ export class SurveyResponseService {
|
|
|
185
280
|
filterType: "weekly",
|
|
186
281
|
fromDate,
|
|
187
282
|
toDate,
|
|
188
|
-
})
|
|
283
|
+
}) as Promise<GroupedSurveyResponse>
|
|
189
284
|
}
|
|
190
285
|
|
|
191
286
|
/**
|
|
@@ -201,7 +296,7 @@ export class SurveyResponseService {
|
|
|
201
296
|
return this.getSurveyResponses(participantId, {
|
|
202
297
|
filterType: "daily",
|
|
203
298
|
date,
|
|
204
|
-
})
|
|
299
|
+
}) as Promise<GroupedSurveyResponse>
|
|
205
300
|
}
|
|
206
301
|
|
|
207
302
|
/**
|
|
@@ -220,7 +315,7 @@ export class SurveyResponseService {
|
|
|
220
315
|
filterType: "monthly",
|
|
221
316
|
month,
|
|
222
317
|
year,
|
|
223
|
-
})
|
|
318
|
+
}) as Promise<GroupedSurveyResponse>
|
|
224
319
|
}
|
|
225
320
|
|
|
226
321
|
/**
|
|
@@ -231,7 +326,7 @@ export class SurveyResponseService {
|
|
|
231
326
|
public async getAllSurveyResponses(participantId: Identifier): Promise<GroupedSurveyResponse> {
|
|
232
327
|
return this.getSurveyResponses(participantId, {
|
|
233
328
|
filterType: "all",
|
|
234
|
-
})
|
|
329
|
+
}) as Promise<GroupedSurveyResponse>
|
|
235
330
|
}
|
|
236
331
|
|
|
237
332
|
/**
|
|
@@ -242,7 +337,7 @@ export class SurveyResponseService {
|
|
|
242
337
|
public async getPinnedSurveyResponses(participantId: Identifier): Promise<GroupedSurveyResponse> {
|
|
243
338
|
return this.getSurveyResponses(participantId, {
|
|
244
339
|
filterType: "pinned",
|
|
245
|
-
})
|
|
340
|
+
}) as Promise<GroupedSurveyResponse>
|
|
246
341
|
}
|
|
247
342
|
|
|
248
343
|
/**
|
|
@@ -262,7 +357,7 @@ export class SurveyResponseService {
|
|
|
262
357
|
return this.getSurveyResponses(participantId, {
|
|
263
358
|
filterType: "all",
|
|
264
359
|
limit,
|
|
265
|
-
})
|
|
360
|
+
}) as Promise<GroupedSurveyResponse>
|
|
266
361
|
}
|
|
267
362
|
|
|
268
363
|
/**
|
|
@@ -410,5 +505,131 @@ export class SurveyResponseService {
|
|
|
410
505
|
|
|
411
506
|
return result.data || { success: false, message: "Unknown error" }
|
|
412
507
|
}
|
|
508
|
+
|
|
509
|
+
// ==================== SURVEY ACTIVITY PIN METHODS ====================
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Pin a survey activity for a study
|
|
513
|
+
* @param studyId - The study ID
|
|
514
|
+
* @param activityId - The survey activity ID to pin
|
|
515
|
+
* @returns Promise<PinSurveyResponseResult>
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
518
|
+
* const result = await LAMP.SurveyResponse.pinSurveyActivity('study_id', 'activity_id');
|
|
519
|
+
*/
|
|
520
|
+
public async pinSurveyActivity(
|
|
521
|
+
studyId: Identifier,
|
|
522
|
+
activityId: string
|
|
523
|
+
): Promise<PinSurveyResponseResult> {
|
|
524
|
+
if (studyId === null || studyId === undefined) {
|
|
525
|
+
throw new Error(
|
|
526
|
+
"Required parameter studyId was null or undefined when calling pinSurveyActivity."
|
|
527
|
+
)
|
|
528
|
+
}
|
|
529
|
+
if (!activityId) {
|
|
530
|
+
throw new Error("Required parameter activityId was null or undefined when calling pinSurveyActivity.")
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
if (this.configuration?.base === "https://demo.lamp.digital") {
|
|
534
|
+
// DEMO
|
|
535
|
+
return Promise.resolve({ error: "500.demo-restriction" } as any)
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
const result = await Fetch.post<{ data: PinSurveyResponseResult }>(
|
|
539
|
+
`/study/${studyId}/survey_activities/pin`,
|
|
540
|
+
{
|
|
541
|
+
activity_id: activityId,
|
|
542
|
+
},
|
|
543
|
+
this.configuration
|
|
544
|
+
)
|
|
545
|
+
|
|
546
|
+
return result.data || { success: false, message: "Unknown error" }
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Unpin a survey activity for a study
|
|
551
|
+
* @param studyId - The study ID
|
|
552
|
+
* @param activityId - The survey activity ID to unpin
|
|
553
|
+
* @returns Promise<PinSurveyResponseResult>
|
|
554
|
+
*
|
|
555
|
+
* @example
|
|
556
|
+
* const result = await LAMP.SurveyResponse.unpinSurveyActivity('study_id', 'activity_id');
|
|
557
|
+
*/
|
|
558
|
+
public async unpinSurveyActivity(
|
|
559
|
+
studyId: Identifier,
|
|
560
|
+
activityId: string
|
|
561
|
+
): Promise<PinSurveyResponseResult> {
|
|
562
|
+
if (studyId === null || studyId === undefined) {
|
|
563
|
+
throw new Error(
|
|
564
|
+
"Required parameter studyId was null or undefined when calling unpinSurveyActivity."
|
|
565
|
+
)
|
|
566
|
+
}
|
|
567
|
+
if (!activityId) {
|
|
568
|
+
throw new Error("Required parameter activityId was null or undefined when calling unpinSurveyActivity.")
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
if (this.configuration?.base === "https://demo.lamp.digital") {
|
|
572
|
+
// DEMO
|
|
573
|
+
return Promise.resolve({ error: "500.demo-restriction" } as any)
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
const result = await Fetch.delete<{ data: PinSurveyResponseResult }>(
|
|
577
|
+
`/study/${studyId}/survey_activities/pin`,
|
|
578
|
+
this.configuration,
|
|
579
|
+
{
|
|
580
|
+
activity_id: activityId,
|
|
581
|
+
}
|
|
582
|
+
)
|
|
583
|
+
|
|
584
|
+
return result.data || { success: false, message: "Unknown error" }
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Get all pinned survey activities for a study
|
|
589
|
+
* @param studyId - The study ID
|
|
590
|
+
* @returns Promise<PinnedSurveyActivitiesResult>
|
|
591
|
+
*
|
|
592
|
+
* @example
|
|
593
|
+
* const result = await LAMP.SurveyResponse.getPinnedSurveyActivities('study_id');
|
|
594
|
+
* console.log(result.activityIds); // ['activity_id_1', 'activity_id_2']
|
|
595
|
+
*/
|
|
596
|
+
public async getPinnedSurveyActivities(
|
|
597
|
+
studyId: Identifier
|
|
598
|
+
): Promise<PinnedSurveyActivitiesResult> {
|
|
599
|
+
if (studyId === null || studyId === undefined) {
|
|
600
|
+
throw new Error(
|
|
601
|
+
"Required parameter studyId was null or undefined when calling getPinnedSurveyActivities."
|
|
602
|
+
)
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
if (this.configuration?.base === "https://demo.lamp.digital") {
|
|
606
|
+
// DEMO
|
|
607
|
+
return Promise.resolve({ activityIds: [] })
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
const result = await Fetch.get<{ data: PinnedSurveyActivitiesResult }>(
|
|
611
|
+
`/study/${studyId}/survey_activities/pinned`,
|
|
612
|
+
this.configuration
|
|
613
|
+
)
|
|
614
|
+
|
|
615
|
+
return result.data || { activityIds: [] }
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Get only pinned survey responses for pinned surveys only
|
|
620
|
+
* Combines surveyFilter: 'pinned' with filterType: 'all'
|
|
621
|
+
* @param participantId - The participant ID
|
|
622
|
+
* @returns Promise<GroupedSurveyResponse>
|
|
623
|
+
*
|
|
624
|
+
* @example
|
|
625
|
+
* // Get responses only from pinned surveys
|
|
626
|
+
* const result = await LAMP.SurveyResponse.getPinnedSurveysResponses('participant_id');
|
|
627
|
+
*/
|
|
628
|
+
public async getPinnedSurveysResponses(participantId: Identifier): Promise<GroupedSurveyResponse> {
|
|
629
|
+
return this.getSurveyResponses(participantId, {
|
|
630
|
+
filterType: "all",
|
|
631
|
+
surveyFilter: "pinned",
|
|
632
|
+
}) as Promise<GroupedSurveyResponse>
|
|
633
|
+
}
|
|
413
634
|
}
|
|
414
635
|
|