lamp-core-lst 2026.1.1-4.2 → 2026.1.19

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/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import "isomorphic-fetch";
2
2
  import { Researcher, Participant } from "./model/index";
3
- import { APIService, ActivityService, ActivityEventService, ActivitySpecService, CredentialService, ParticipantService, ResearcherService, SensorService, SensorEventService, SensorSpecService, StudyService, TypeService, ResearcherSettingsService, ImageUploadService } from "./service/index";
3
+ import { APIService, ActivityService, ActivityEventService, ActivitySpecService, CredentialService, ParticipantService, ResearcherService, SensorService, SensorEventService, SensorSpecService, StudyService, TypeService, ResearcherSettingsService, ImageUploadService, SurveyResponseService } from "./service/index";
4
4
  export * from "./service/index";
5
5
  export * from "./model/index";
6
6
  /**
@@ -30,6 +30,7 @@ export default class LAMP {
30
30
  static SensorSpec: SensorSpecService;
31
31
  static ResearcherSettings: ResearcherSettingsService;
32
32
  static ImageUpload: ImageUploadService;
33
+ static SurveyResponse: SurveyResponseService;
33
34
  private static get configuration();
34
35
  private static set configuration(value);
35
36
  private static protocol;
package/dist/index.js CHANGED
@@ -91,6 +91,7 @@ var LAMP = /** @class */ (function () {
91
91
  LAMP.Type.configuration = configuration;
92
92
  LAMP.ResearcherSettings.configuration = configuration;
93
93
  LAMP.ImageUpload.configuration = configuration;
94
+ LAMP.SurveyResponse.configuration = configuration;
94
95
  },
95
96
  enumerable: false,
96
97
  configurable: true
@@ -204,6 +205,7 @@ var LAMP = /** @class */ (function () {
204
205
  LAMP.SensorSpec = new index_1.SensorSpecService();
205
206
  LAMP.ResearcherSettings = new index_1.ResearcherSettingsService();
206
207
  LAMP.ImageUpload = new index_1.ImageUploadService();
208
+ LAMP.SurveyResponse = new index_1.SurveyResponseService();
207
209
  LAMP.protocol = "https://";
208
210
  LAMP.Auth = (_b = /** @class */ (function () {
209
211
  function class_1() {
@@ -0,0 +1,142 @@
1
+ import { Configuration } from "./Fetch";
2
+ import { Identifier } from "../model/Type";
3
+ export interface SurveyResponse {
4
+ date: number;
5
+ timestamp: number;
6
+ firstAnswer: any;
7
+ isPinned?: boolean;
8
+ }
9
+ export interface SurveyItem {
10
+ id: string;
11
+ title: string;
12
+ binName?: string;
13
+ responses: SurveyResponse[];
14
+ }
15
+ export interface SurveyGroup {
16
+ id: string;
17
+ label: string;
18
+ surveys: SurveyItem[];
19
+ }
20
+ export interface GroupedSurveyResponse {
21
+ groups: SurveyGroup[];
22
+ ungroupedSurveys: SurveyItem[];
23
+ }
24
+ export declare type FilterType = "weekly" | "daily" | "monthly" | "all" | "pinned";
25
+ export interface FilterParams {
26
+ filterType: FilterType;
27
+ date?: number;
28
+ fromDate?: number;
29
+ toDate?: number;
30
+ month?: number;
31
+ year?: number;
32
+ }
33
+ export interface PinSurveyResponseParams {
34
+ activity_id: string;
35
+ timestamp: number;
36
+ }
37
+ export interface PinSurveyResponseResult {
38
+ success: boolean;
39
+ message: string;
40
+ }
41
+ export declare class SurveyResponseService {
42
+ configuration?: Configuration;
43
+ /**
44
+ * Get survey responses for a participant grouped by survey groups from researcher settings
45
+ * @param participantId - The participant ID
46
+ * @param filterParams - Filter parameters for the query
47
+ * @returns Promise<GroupedSurveyResponse>
48
+ *
49
+ * @example
50
+ * // Get weekly responses (last 7 days)
51
+ * const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'weekly' });
52
+ *
53
+ * @example
54
+ * // Get weekly responses with custom date range
55
+ * const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', {
56
+ * filterType: 'weekly',
57
+ * fromDate: 1700000000000,
58
+ * toDate: 1700604800000
59
+ * });
60
+ *
61
+ * @example
62
+ * // Get daily responses for a specific date
63
+ * const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', {
64
+ * filterType: 'daily',
65
+ * date: 1700000000000
66
+ * });
67
+ *
68
+ * @example
69
+ * // Get monthly responses
70
+ * const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', {
71
+ * filterType: 'monthly',
72
+ * month: 12,
73
+ * year: 2025
74
+ * });
75
+ *
76
+ * @example
77
+ * // Get all responses
78
+ * const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'all' });
79
+ *
80
+ * @example
81
+ * // Get pinned responses only
82
+ * const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'pinned' });
83
+ */
84
+ getSurveyResponses(participantId: Identifier, filterParams?: FilterParams): Promise<GroupedSurveyResponse>;
85
+ /**
86
+ * Get weekly survey responses for a participant (last 7 days including today)
87
+ * @param participantId - The participant ID
88
+ * @param fromDate - Optional custom start date (timestamp)
89
+ * @param toDate - Optional custom end date (timestamp)
90
+ * @returns Promise<GroupedSurveyResponse>
91
+ */
92
+ getWeeklySurveyResponses(participantId: Identifier, fromDate?: number, toDate?: number): Promise<GroupedSurveyResponse>;
93
+ /**
94
+ * Get daily survey responses for a participant
95
+ * @param participantId - The participant ID
96
+ * @param date - Optional specific date (timestamp). Defaults to today.
97
+ * @returns Promise<GroupedSurveyResponse>
98
+ */
99
+ getDailySurveyResponses(participantId: Identifier, date?: number): Promise<GroupedSurveyResponse>;
100
+ /**
101
+ * Get monthly survey responses for a participant
102
+ * @param participantId - The participant ID
103
+ * @param month - Month number (1-12). Defaults to current month.
104
+ * @param year - Year. Defaults to current year.
105
+ * @returns Promise<GroupedSurveyResponse>
106
+ */
107
+ getMonthlySurveyResponses(participantId: Identifier, month?: number, year?: number): Promise<GroupedSurveyResponse>;
108
+ /**
109
+ * Get all survey responses for a participant
110
+ * @param participantId - The participant ID
111
+ * @returns Promise<GroupedSurveyResponse>
112
+ */
113
+ getAllSurveyResponses(participantId: Identifier): Promise<GroupedSurveyResponse>;
114
+ /**
115
+ * Get only pinned survey responses for a participant
116
+ * @param participantId - The participant ID
117
+ * @returns Promise<GroupedSurveyResponse>
118
+ */
119
+ getPinnedSurveyResponses(participantId: Identifier): Promise<GroupedSurveyResponse>;
120
+ /**
121
+ * Pin a survey response for a participant
122
+ * @param participantId - The participant ID
123
+ * @param activityId - The survey activity ID
124
+ * @param timestamp - The timestamp of the response to pin
125
+ * @returns Promise<PinSurveyResponseResult>
126
+ *
127
+ * @example
128
+ * const result = await LAMP.SurveyResponse.pinSurveyResponse('participant_id', 'activity_id', 1700000000000);
129
+ */
130
+ pinSurveyResponse(participantId: Identifier, activityId: string, timestamp: number): Promise<PinSurveyResponseResult>;
131
+ /**
132
+ * Unpin a survey response for a participant
133
+ * @param participantId - The participant ID
134
+ * @param activityId - The survey activity ID
135
+ * @param timestamp - The timestamp of the response to unpin
136
+ * @returns Promise<PinSurveyResponseResult>
137
+ *
138
+ * @example
139
+ * const result = await LAMP.SurveyResponse.unpinSurveyResponse('participant_id', 'activity_id', 1700000000000);
140
+ */
141
+ unpinSurveyResponse(participantId: Identifier, activityId: string, timestamp: number): Promise<PinSurveyResponseResult>;
142
+ }
@@ -0,0 +1,292 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.SurveyResponseService = void 0;
40
+ var Fetch_1 = require("./Fetch");
41
+ var SurveyResponseService = /** @class */ (function () {
42
+ function SurveyResponseService() {
43
+ }
44
+ /**
45
+ * Get survey responses for a participant grouped by survey groups from researcher settings
46
+ * @param participantId - The participant ID
47
+ * @param filterParams - Filter parameters for the query
48
+ * @returns Promise<GroupedSurveyResponse>
49
+ *
50
+ * @example
51
+ * // Get weekly responses (last 7 days)
52
+ * const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'weekly' });
53
+ *
54
+ * @example
55
+ * // Get weekly responses with custom date range
56
+ * const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', {
57
+ * filterType: 'weekly',
58
+ * fromDate: 1700000000000,
59
+ * toDate: 1700604800000
60
+ * });
61
+ *
62
+ * @example
63
+ * // Get daily responses for a specific date
64
+ * const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', {
65
+ * filterType: 'daily',
66
+ * date: 1700000000000
67
+ * });
68
+ *
69
+ * @example
70
+ * // Get monthly responses
71
+ * const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', {
72
+ * filterType: 'monthly',
73
+ * month: 12,
74
+ * year: 2025
75
+ * });
76
+ *
77
+ * @example
78
+ * // Get all responses
79
+ * const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'all' });
80
+ *
81
+ * @example
82
+ * // Get pinned responses only
83
+ * const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'pinned' });
84
+ */
85
+ SurveyResponseService.prototype.getSurveyResponses = function (participantId, filterParams) {
86
+ var _a;
87
+ if (filterParams === void 0) { filterParams = { filterType: "weekly" }; }
88
+ return __awaiter(this, void 0, void 0, function () {
89
+ var queryParams, result;
90
+ return __generator(this, function (_b) {
91
+ switch (_b.label) {
92
+ case 0:
93
+ if (participantId === null || participantId === undefined) {
94
+ throw new Error("Required parameter participantId was null or undefined when calling getSurveyResponses.");
95
+ }
96
+ if (((_a = this.configuration) === null || _a === void 0 ? void 0 : _a.base) === "https://demo.lamp.digital") {
97
+ // DEMO - return empty structure for demo mode
98
+ return [2 /*return*/, Promise.resolve({
99
+ groups: [],
100
+ ungroupedSurveys: [],
101
+ })];
102
+ }
103
+ queryParams = new URLSearchParams();
104
+ queryParams.set("filterType", filterParams.filterType);
105
+ if (filterParams.date !== undefined) {
106
+ queryParams.set("date", String(filterParams.date));
107
+ }
108
+ if (filterParams.fromDate !== undefined) {
109
+ queryParams.set("fromDate", String(filterParams.fromDate));
110
+ }
111
+ if (filterParams.toDate !== undefined) {
112
+ queryParams.set("toDate", String(filterParams.toDate));
113
+ }
114
+ if (filterParams.month !== undefined) {
115
+ queryParams.set("month", String(filterParams.month));
116
+ }
117
+ if (filterParams.year !== undefined) {
118
+ queryParams.set("year", String(filterParams.year));
119
+ }
120
+ return [4 /*yield*/, Fetch_1.Fetch.get("/participant/" + participantId + "/survey_responses?" + queryParams.toString(), this.configuration)];
121
+ case 1:
122
+ result = _b.sent();
123
+ return [2 /*return*/, result.data || { groups: [], ungroupedSurveys: [] }];
124
+ }
125
+ });
126
+ });
127
+ };
128
+ /**
129
+ * Get weekly survey responses for a participant (last 7 days including today)
130
+ * @param participantId - The participant ID
131
+ * @param fromDate - Optional custom start date (timestamp)
132
+ * @param toDate - Optional custom end date (timestamp)
133
+ * @returns Promise<GroupedSurveyResponse>
134
+ */
135
+ SurveyResponseService.prototype.getWeeklySurveyResponses = function (participantId, fromDate, toDate) {
136
+ return __awaiter(this, void 0, void 0, function () {
137
+ return __generator(this, function (_a) {
138
+ return [2 /*return*/, this.getSurveyResponses(participantId, {
139
+ filterType: "weekly",
140
+ fromDate: fromDate,
141
+ toDate: toDate,
142
+ })];
143
+ });
144
+ });
145
+ };
146
+ /**
147
+ * Get daily survey responses for a participant
148
+ * @param participantId - The participant ID
149
+ * @param date - Optional specific date (timestamp). Defaults to today.
150
+ * @returns Promise<GroupedSurveyResponse>
151
+ */
152
+ SurveyResponseService.prototype.getDailySurveyResponses = function (participantId, date) {
153
+ return __awaiter(this, void 0, void 0, function () {
154
+ return __generator(this, function (_a) {
155
+ return [2 /*return*/, this.getSurveyResponses(participantId, {
156
+ filterType: "daily",
157
+ date: date,
158
+ })];
159
+ });
160
+ });
161
+ };
162
+ /**
163
+ * Get monthly survey responses for a participant
164
+ * @param participantId - The participant ID
165
+ * @param month - Month number (1-12). Defaults to current month.
166
+ * @param year - Year. Defaults to current year.
167
+ * @returns Promise<GroupedSurveyResponse>
168
+ */
169
+ SurveyResponseService.prototype.getMonthlySurveyResponses = function (participantId, month, year) {
170
+ return __awaiter(this, void 0, void 0, function () {
171
+ return __generator(this, function (_a) {
172
+ return [2 /*return*/, this.getSurveyResponses(participantId, {
173
+ filterType: "monthly",
174
+ month: month,
175
+ year: year,
176
+ })];
177
+ });
178
+ });
179
+ };
180
+ /**
181
+ * Get all survey responses for a participant
182
+ * @param participantId - The participant ID
183
+ * @returns Promise<GroupedSurveyResponse>
184
+ */
185
+ SurveyResponseService.prototype.getAllSurveyResponses = function (participantId) {
186
+ return __awaiter(this, void 0, void 0, function () {
187
+ return __generator(this, function (_a) {
188
+ return [2 /*return*/, this.getSurveyResponses(participantId, {
189
+ filterType: "all",
190
+ })];
191
+ });
192
+ });
193
+ };
194
+ /**
195
+ * Get only pinned survey responses for a participant
196
+ * @param participantId - The participant ID
197
+ * @returns Promise<GroupedSurveyResponse>
198
+ */
199
+ SurveyResponseService.prototype.getPinnedSurveyResponses = function (participantId) {
200
+ return __awaiter(this, void 0, void 0, function () {
201
+ return __generator(this, function (_a) {
202
+ return [2 /*return*/, this.getSurveyResponses(participantId, {
203
+ filterType: "pinned",
204
+ })];
205
+ });
206
+ });
207
+ };
208
+ /**
209
+ * Pin a survey response for a participant
210
+ * @param participantId - The participant ID
211
+ * @param activityId - The survey activity ID
212
+ * @param timestamp - The timestamp of the response to pin
213
+ * @returns Promise<PinSurveyResponseResult>
214
+ *
215
+ * @example
216
+ * const result = await LAMP.SurveyResponse.pinSurveyResponse('participant_id', 'activity_id', 1700000000000);
217
+ */
218
+ SurveyResponseService.prototype.pinSurveyResponse = function (participantId, activityId, timestamp) {
219
+ var _a;
220
+ return __awaiter(this, void 0, void 0, function () {
221
+ var result;
222
+ return __generator(this, function (_b) {
223
+ switch (_b.label) {
224
+ case 0:
225
+ if (participantId === null || participantId === undefined) {
226
+ throw new Error("Required parameter participantId was null or undefined when calling pinSurveyResponse.");
227
+ }
228
+ if (!activityId) {
229
+ throw new Error("Required parameter activityId was null or undefined when calling pinSurveyResponse.");
230
+ }
231
+ if (timestamp === null || timestamp === undefined) {
232
+ throw new Error("Required parameter timestamp was null or undefined when calling pinSurveyResponse.");
233
+ }
234
+ if (((_a = this.configuration) === null || _a === void 0 ? void 0 : _a.base) === "https://demo.lamp.digital") {
235
+ // DEMO
236
+ return [2 /*return*/, Promise.resolve({ error: "500.demo-restriction" })];
237
+ }
238
+ return [4 /*yield*/, Fetch_1.Fetch.post("/participant/" + participantId + "/survey_responses/pin", {
239
+ activity_id: activityId,
240
+ timestamp: timestamp,
241
+ }, this.configuration)];
242
+ case 1:
243
+ result = _b.sent();
244
+ return [2 /*return*/, result.data || { success: false, message: "Unknown error" }];
245
+ }
246
+ });
247
+ });
248
+ };
249
+ /**
250
+ * Unpin a survey response for a participant
251
+ * @param participantId - The participant ID
252
+ * @param activityId - The survey activity ID
253
+ * @param timestamp - The timestamp of the response to unpin
254
+ * @returns Promise<PinSurveyResponseResult>
255
+ *
256
+ * @example
257
+ * const result = await LAMP.SurveyResponse.unpinSurveyResponse('participant_id', 'activity_id', 1700000000000);
258
+ */
259
+ SurveyResponseService.prototype.unpinSurveyResponse = function (participantId, activityId, timestamp) {
260
+ var _a;
261
+ return __awaiter(this, void 0, void 0, function () {
262
+ var result;
263
+ return __generator(this, function (_b) {
264
+ switch (_b.label) {
265
+ case 0:
266
+ if (participantId === null || participantId === undefined) {
267
+ throw new Error("Required parameter participantId was null or undefined when calling unpinSurveyResponse.");
268
+ }
269
+ if (!activityId) {
270
+ throw new Error("Required parameter activityId was null or undefined when calling unpinSurveyResponse.");
271
+ }
272
+ if (timestamp === null || timestamp === undefined) {
273
+ throw new Error("Required parameter timestamp was null or undefined when calling unpinSurveyResponse.");
274
+ }
275
+ if (((_a = this.configuration) === null || _a === void 0 ? void 0 : _a.base) === "https://demo.lamp.digital") {
276
+ // DEMO
277
+ return [2 /*return*/, Promise.resolve({ error: "500.demo-restriction" })];
278
+ }
279
+ return [4 /*yield*/, Fetch_1.Fetch.delete("/participant/" + participantId + "/survey_responses/pin", this.configuration, {
280
+ activity_id: activityId,
281
+ timestamp: timestamp,
282
+ })];
283
+ case 1:
284
+ result = _b.sent();
285
+ return [2 /*return*/, result.data || { success: false, message: "Unknown error" }];
286
+ }
287
+ });
288
+ });
289
+ };
290
+ return SurveyResponseService;
291
+ }());
292
+ exports.SurveyResponseService = SurveyResponseService;
@@ -12,3 +12,4 @@ export * from "./Study.service";
12
12
  export * from "./Type.service";
13
13
  export * from "./API.service";
14
14
  export * from "./ImageUpload.service";
15
+ export * from "./SurveyResponse.service";
@@ -24,3 +24,4 @@ __exportStar(require("./Study.service"), exports);
24
24
  __exportStar(require("./Type.service"), exports);
25
25
  __exportStar(require("./API.service"), exports);
26
26
  __exportStar(require("./ImageUpload.service"), exports);
27
+ __exportStar(require("./SurveyResponse.service"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lamp-core-lst",
3
- "version": "2026.1.1-4.2",
3
+ "version": "2026.1.19",
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/",
package/src/index.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  TypeService,
16
16
  ResearcherSettingsService,
17
17
  ImageUploadService,
18
+ SurveyResponseService,
18
19
  } from "./service/index"
19
20
  import { Configuration } from "./service/Fetch"
20
21
  import { Demo } from "./service/Demo"
@@ -53,6 +54,7 @@ export default class LAMP {
53
54
  public static SensorSpec = new SensorSpecService()
54
55
  public static ResearcherSettings = new ResearcherSettingsService()
55
56
  public static ImageUpload = new ImageUploadService()
57
+ public static SurveyResponse = new SurveyResponseService()
56
58
  private static get configuration(): Configuration | undefined {
57
59
  return LAMP.API.configuration
58
60
  }
@@ -71,6 +73,7 @@ export default class LAMP {
71
73
  LAMP.Type.configuration = configuration
72
74
  LAMP.ResearcherSettings.configuration = configuration
73
75
  LAMP.ImageUpload.configuration = configuration
76
+ LAMP.SurveyResponse.configuration = configuration
74
77
  }
75
78
  private static protocol = "https://"
76
79
 
@@ -0,0 +1,306 @@
1
+ import { Fetch, Configuration } from "./Fetch"
2
+ import { Identifier } from "../model/Type"
3
+
4
+ // Types for survey response structure
5
+ export interface SurveyResponse {
6
+ date: number
7
+ timestamp: number
8
+ firstAnswer: any
9
+ isPinned?: boolean
10
+ }
11
+
12
+ export interface SurveyItem {
13
+ id: string
14
+ title: string
15
+ binName?: string
16
+ responses: SurveyResponse[]
17
+ }
18
+
19
+ export interface SurveyGroup {
20
+ id: string
21
+ label: string
22
+ surveys: SurveyItem[]
23
+ }
24
+
25
+ export interface GroupedSurveyResponse {
26
+ groups: SurveyGroup[]
27
+ ungroupedSurveys: SurveyItem[]
28
+ }
29
+
30
+ // Filter types for survey responses
31
+ export type FilterType = "weekly" | "daily" | "monthly" | "all" | "pinned"
32
+
33
+ export interface FilterParams {
34
+ filterType: FilterType
35
+ date?: number // For daily filter - specific date timestamp
36
+ fromDate?: number // For weekly custom range
37
+ toDate?: number // For weekly custom range
38
+ month?: number // For monthly filter (1-12)
39
+ year?: number // For monthly filter
40
+ }
41
+
42
+ export interface PinSurveyResponseParams {
43
+ activity_id: string
44
+ timestamp: number
45
+ }
46
+
47
+ export interface PinSurveyResponseResult {
48
+ success: boolean
49
+ message: string
50
+ }
51
+
52
+ export class SurveyResponseService {
53
+ public configuration?: Configuration
54
+
55
+ /**
56
+ * Get survey responses for a participant grouped by survey groups from researcher settings
57
+ * @param participantId - The participant ID
58
+ * @param filterParams - Filter parameters for the query
59
+ * @returns Promise<GroupedSurveyResponse>
60
+ *
61
+ * @example
62
+ * // Get weekly responses (last 7 days)
63
+ * const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'weekly' });
64
+ *
65
+ * @example
66
+ * // Get weekly responses with custom date range
67
+ * const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', {
68
+ * filterType: 'weekly',
69
+ * fromDate: 1700000000000,
70
+ * toDate: 1700604800000
71
+ * });
72
+ *
73
+ * @example
74
+ * // Get daily responses for a specific date
75
+ * const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', {
76
+ * filterType: 'daily',
77
+ * date: 1700000000000
78
+ * });
79
+ *
80
+ * @example
81
+ * // Get monthly responses
82
+ * const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', {
83
+ * filterType: 'monthly',
84
+ * month: 12,
85
+ * year: 2025
86
+ * });
87
+ *
88
+ * @example
89
+ * // Get all responses
90
+ * const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'all' });
91
+ *
92
+ * @example
93
+ * // Get pinned responses only
94
+ * const result = await LAMP.SurveyResponse.getSurveyResponses('participant_id', { filterType: 'pinned' });
95
+ */
96
+ public async getSurveyResponses(
97
+ participantId: Identifier,
98
+ filterParams: FilterParams = { filterType: "weekly" }
99
+ ): Promise<GroupedSurveyResponse> {
100
+ if (participantId === null || participantId === undefined) {
101
+ throw new Error(
102
+ "Required parameter participantId was null or undefined when calling getSurveyResponses."
103
+ )
104
+ }
105
+
106
+ if (this.configuration?.base === "https://demo.lamp.digital") {
107
+ // DEMO - return empty structure for demo mode
108
+ return Promise.resolve({
109
+ groups: [],
110
+ ungroupedSurveys: [],
111
+ })
112
+ }
113
+
114
+ // Build query parameters
115
+ const queryParams = new URLSearchParams()
116
+ queryParams.set("filterType", filterParams.filterType)
117
+
118
+ if (filterParams.date !== undefined) {
119
+ queryParams.set("date", String(filterParams.date))
120
+ }
121
+ if (filterParams.fromDate !== undefined) {
122
+ queryParams.set("fromDate", String(filterParams.fromDate))
123
+ }
124
+ if (filterParams.toDate !== undefined) {
125
+ queryParams.set("toDate", String(filterParams.toDate))
126
+ }
127
+ if (filterParams.month !== undefined) {
128
+ queryParams.set("month", String(filterParams.month))
129
+ }
130
+ if (filterParams.year !== undefined) {
131
+ queryParams.set("year", String(filterParams.year))
132
+ }
133
+
134
+ const result = await Fetch.get<{ data: GroupedSurveyResponse }>(
135
+ `/participant/${participantId}/survey_responses?${queryParams.toString()}`,
136
+ this.configuration
137
+ )
138
+
139
+ return result.data || { groups: [], ungroupedSurveys: [] }
140
+ }
141
+
142
+ /**
143
+ * Get weekly survey responses for a participant (last 7 days including today)
144
+ * @param participantId - The participant ID
145
+ * @param fromDate - Optional custom start date (timestamp)
146
+ * @param toDate - Optional custom end date (timestamp)
147
+ * @returns Promise<GroupedSurveyResponse>
148
+ */
149
+ public async getWeeklySurveyResponses(
150
+ participantId: Identifier,
151
+ fromDate?: number,
152
+ toDate?: number
153
+ ): Promise<GroupedSurveyResponse> {
154
+ return this.getSurveyResponses(participantId, {
155
+ filterType: "weekly",
156
+ fromDate,
157
+ toDate,
158
+ })
159
+ }
160
+
161
+ /**
162
+ * Get daily survey responses for a participant
163
+ * @param participantId - The participant ID
164
+ * @param date - Optional specific date (timestamp). Defaults to today.
165
+ * @returns Promise<GroupedSurveyResponse>
166
+ */
167
+ public async getDailySurveyResponses(
168
+ participantId: Identifier,
169
+ date?: number
170
+ ): Promise<GroupedSurveyResponse> {
171
+ return this.getSurveyResponses(participantId, {
172
+ filterType: "daily",
173
+ date,
174
+ })
175
+ }
176
+
177
+ /**
178
+ * Get monthly survey responses for a participant
179
+ * @param participantId - The participant ID
180
+ * @param month - Month number (1-12). Defaults to current month.
181
+ * @param year - Year. Defaults to current year.
182
+ * @returns Promise<GroupedSurveyResponse>
183
+ */
184
+ public async getMonthlySurveyResponses(
185
+ participantId: Identifier,
186
+ month?: number,
187
+ year?: number
188
+ ): Promise<GroupedSurveyResponse> {
189
+ return this.getSurveyResponses(participantId, {
190
+ filterType: "monthly",
191
+ month,
192
+ year,
193
+ })
194
+ }
195
+
196
+ /**
197
+ * Get all survey responses for a participant
198
+ * @param participantId - The participant ID
199
+ * @returns Promise<GroupedSurveyResponse>
200
+ */
201
+ public async getAllSurveyResponses(participantId: Identifier): Promise<GroupedSurveyResponse> {
202
+ return this.getSurveyResponses(participantId, {
203
+ filterType: "all",
204
+ })
205
+ }
206
+
207
+ /**
208
+ * Get only pinned survey responses for a participant
209
+ * @param participantId - The participant ID
210
+ * @returns Promise<GroupedSurveyResponse>
211
+ */
212
+ public async getPinnedSurveyResponses(participantId: Identifier): Promise<GroupedSurveyResponse> {
213
+ return this.getSurveyResponses(participantId, {
214
+ filterType: "pinned",
215
+ })
216
+ }
217
+
218
+ /**
219
+ * Pin a survey response for a participant
220
+ * @param participantId - The participant ID
221
+ * @param activityId - The survey activity ID
222
+ * @param timestamp - The timestamp of the response to pin
223
+ * @returns Promise<PinSurveyResponseResult>
224
+ *
225
+ * @example
226
+ * const result = await LAMP.SurveyResponse.pinSurveyResponse('participant_id', 'activity_id', 1700000000000);
227
+ */
228
+ public async pinSurveyResponse(
229
+ participantId: Identifier,
230
+ activityId: string,
231
+ timestamp: number
232
+ ): Promise<PinSurveyResponseResult> {
233
+ if (participantId === null || participantId === undefined) {
234
+ throw new Error(
235
+ "Required parameter participantId was null or undefined when calling pinSurveyResponse."
236
+ )
237
+ }
238
+ if (!activityId) {
239
+ throw new Error("Required parameter activityId was null or undefined when calling pinSurveyResponse.")
240
+ }
241
+ if (timestamp === null || timestamp === undefined) {
242
+ throw new Error("Required parameter timestamp was null or undefined when calling pinSurveyResponse.")
243
+ }
244
+
245
+ if (this.configuration?.base === "https://demo.lamp.digital") {
246
+ // DEMO
247
+ return Promise.resolve({ error: "500.demo-restriction" } as any)
248
+ }
249
+
250
+ const result = await Fetch.post<{ data: PinSurveyResponseResult }>(
251
+ `/participant/${participantId}/survey_responses/pin`,
252
+ {
253
+ activity_id: activityId,
254
+ timestamp: timestamp,
255
+ },
256
+ this.configuration
257
+ )
258
+
259
+ return result.data || { success: false, message: "Unknown error" }
260
+ }
261
+
262
+ /**
263
+ * Unpin a survey response for a participant
264
+ * @param participantId - The participant ID
265
+ * @param activityId - The survey activity ID
266
+ * @param timestamp - The timestamp of the response to unpin
267
+ * @returns Promise<PinSurveyResponseResult>
268
+ *
269
+ * @example
270
+ * const result = await LAMP.SurveyResponse.unpinSurveyResponse('participant_id', 'activity_id', 1700000000000);
271
+ */
272
+ public async unpinSurveyResponse(
273
+ participantId: Identifier,
274
+ activityId: string,
275
+ timestamp: number
276
+ ): Promise<PinSurveyResponseResult> {
277
+ if (participantId === null || participantId === undefined) {
278
+ throw new Error(
279
+ "Required parameter participantId was null or undefined when calling unpinSurveyResponse."
280
+ )
281
+ }
282
+ if (!activityId) {
283
+ throw new Error("Required parameter activityId was null or undefined when calling unpinSurveyResponse.")
284
+ }
285
+ if (timestamp === null || timestamp === undefined) {
286
+ throw new Error("Required parameter timestamp was null or undefined when calling unpinSurveyResponse.")
287
+ }
288
+
289
+ if (this.configuration?.base === "https://demo.lamp.digital") {
290
+ // DEMO
291
+ return Promise.resolve({ error: "500.demo-restriction" } as any)
292
+ }
293
+
294
+ const result = await Fetch.delete<{ data: PinSurveyResponseResult }>(
295
+ `/participant/${participantId}/survey_responses/pin`,
296
+ this.configuration,
297
+ {
298
+ activity_id: activityId,
299
+ timestamp: timestamp,
300
+ }
301
+ )
302
+
303
+ return result.data || { success: false, message: "Unknown error" }
304
+ }
305
+ }
306
+
@@ -12,3 +12,4 @@ export * from "./Study.service"
12
12
  export * from "./Type.service"
13
13
  export * from "./API.service"
14
14
  export * from "./ImageUpload.service"
15
+ export * from "./SurveyResponse.service"