@blackcode_sa/metaestetics-api 1.5.17 → 1.5.18

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.5.17",
4
+ "version": "1.5.18",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
package/src/index.ts CHANGED
@@ -210,6 +210,9 @@ export {
210
210
  CalendarEventStatus,
211
211
  CalendarEventType,
212
212
  CalendarSyncStatus,
213
+ SearchLocationEnum,
214
+ DateRange,
215
+ SearchCalendarEventsParams,
213
216
  CALENDAR_COLLECTION,
214
217
  } from "./types/calendar";
215
218
 
@@ -5,8 +5,8 @@ import {
5
5
  updateDoc,
6
6
  arrayUnion,
7
7
  serverTimestamp,
8
- } from "firebase/firestore";
9
- import { BaseService } from "../base.service";
8
+ } from 'firebase/firestore';
9
+ import { BaseService } from '../base.service';
10
10
  import {
11
11
  PatientProfile,
12
12
  PatientSensitiveInfo,
@@ -31,11 +31,11 @@ import {
31
31
  PatientClinic,
32
32
  SearchPatientsParams,
33
33
  RequesterInfo,
34
- } from "../../types/patient";
35
- import { Auth } from "firebase/auth";
36
- import { Firestore } from "firebase/firestore";
37
- import { FirebaseApp } from "firebase/app";
38
- import { Timestamp } from "firebase/firestore";
34
+ } from '../../types/patient';
35
+ import { Auth } from 'firebase/auth';
36
+ import { Firestore } from 'firebase/firestore';
37
+ import { FirebaseApp } from 'firebase/app';
38
+ import { Timestamp } from 'firebase/firestore';
39
39
 
40
40
  // Importujemo utility funkcije
41
41
  import {
@@ -51,20 +51,21 @@ import {
51
51
  updatePatientProfileUtil,
52
52
  updatePatientProfileByUserRefUtil,
53
53
  searchPatientsUtil,
54
- } from "./utils/profile.utils";
54
+ getAllPatientsUtil,
55
+ } from './utils/profile.utils';
55
56
 
56
57
  import {
57
58
  updatePatientLocationUtil,
58
59
  createLocationInfoUtil,
59
60
  getLocationInfoUtil,
60
61
  updateLocationInfoUtil,
61
- } from "./utils/location.utils";
62
+ } from './utils/location.utils';
62
63
 
63
64
  import {
64
65
  createSensitiveInfoUtil,
65
66
  getSensitiveInfoUtil,
66
67
  updateSensitiveInfoUtil,
67
- } from "./utils/sensitive.utils";
68
+ } from './utils/sensitive.utils';
68
69
 
69
70
  import {
70
71
  createMedicalInfoUtil,
@@ -82,21 +83,21 @@ import {
82
83
  addMedicationUtil,
83
84
  updateMedicationUtil,
84
85
  removeMedicationUtil,
85
- } from "./utils/medical.utils";
86
+ } from './utils/medical.utils';
86
87
 
87
88
  import {
88
89
  getPatientDocRef,
89
90
  getSensitiveInfoDocRef,
90
91
  getLocationInfoDocRef,
91
92
  getMedicalInfoDocRef,
92
- } from "./utils/docs.utils";
93
+ } from './utils/docs.utils';
93
94
 
94
95
  import {
95
96
  addDoctorUtil,
96
97
  removeDoctorUtil,
97
98
  addClinicUtil,
98
99
  removeClinicUtil,
99
- } from "./utils/medical-stuff.utils";
100
+ } from './utils/medical-stuff.utils';
100
101
 
101
102
  export class PatientService extends BaseService {
102
103
  constructor(db: Firestore, auth: Auth, app: FirebaseApp) {
@@ -104,9 +105,7 @@ export class PatientService extends BaseService {
104
105
  }
105
106
 
106
107
  // Metode za rad sa profilom pacijenta
107
- async createPatientProfile(
108
- data: CreatePatientProfileData
109
- ): Promise<PatientProfile> {
108
+ async createPatientProfile(data: CreatePatientProfileData): Promise<PatientProfile> {
110
109
  return createPatientProfileUtil(this.db, data, () => this.generateId());
111
110
  }
112
111
 
@@ -114,9 +113,7 @@ export class PatientService extends BaseService {
114
113
  return getPatientProfileUtil(this.db, patientId);
115
114
  }
116
115
 
117
- async getPatientProfileByUserRef(
118
- userRef: string
119
- ): Promise<PatientProfile | null> {
116
+ async getPatientProfileByUserRef(userRef: string): Promise<PatientProfile | null> {
120
117
  return getPatientProfileByUserRefUtil(this.db, userRef);
121
118
  }
122
119
 
@@ -124,7 +121,7 @@ export class PatientService extends BaseService {
124
121
  async updatePatientLocation(
125
122
  patientId: string,
126
123
  latitude: number,
127
- longitude: number
124
+ longitude: number,
128
125
  ): Promise<void> {
129
126
  await updatePatientLocationUtil(this.db, patientId, latitude, longitude);
130
127
  }
@@ -132,30 +129,30 @@ export class PatientService extends BaseService {
132
129
  async updatePatientLocationByUserRef(
133
130
  userRef: string,
134
131
  latitude: number,
135
- longitude: number
132
+ longitude: number,
136
133
  ): Promise<void> {
137
134
  const profile = await this.getPatientProfileByUserRef(userRef);
138
- if (!profile) throw new Error("Patient profile not found");
135
+ if (!profile) throw new Error('Patient profile not found');
139
136
  await this.updatePatientLocation(profile.id, latitude, longitude);
140
137
  }
141
138
 
142
139
  async createLocationInfo(
143
140
  data: CreatePatientLocationInfoData,
144
- requesterId: string
141
+ requesterId: string,
145
142
  ): Promise<PatientLocationInfo> {
146
143
  return createLocationInfoUtil(this.db, data, requesterId);
147
144
  }
148
145
 
149
146
  async getLocationInfo(
150
147
  patientId: string,
151
- requesterId: string
148
+ requesterId: string,
152
149
  ): Promise<PatientLocationInfo | null> {
153
150
  return getLocationInfoUtil(this.db, patientId, requesterId);
154
151
  }
155
152
 
156
153
  async getLocationInfoByUserRef(
157
154
  userRef: string,
158
- requesterId: string
155
+ requesterId: string,
159
156
  ): Promise<PatientLocationInfo | null> {
160
157
  const profile = await this.getPatientProfileByUserRef(userRef);
161
158
  if (!profile) return null;
@@ -165,7 +162,7 @@ export class PatientService extends BaseService {
165
162
  async updateLocationInfo(
166
163
  patientId: string,
167
164
  data: UpdatePatientLocationInfoData,
168
- requesterId: string
165
+ requesterId: string,
169
166
  ): Promise<PatientLocationInfo> {
170
167
  return updateLocationInfoUtil(this.db, patientId, data, requesterId);
171
168
  }
@@ -173,21 +170,21 @@ export class PatientService extends BaseService {
173
170
  // Metode za rad sa osetljivim informacijama
174
171
  async createSensitiveInfo(
175
172
  data: CreatePatientSensitiveInfoData,
176
- requesterUserId: string
173
+ requesterUserId: string,
177
174
  ): Promise<PatientSensitiveInfo> {
178
175
  return createSensitiveInfoUtil(this.db, data, requesterUserId);
179
176
  }
180
177
 
181
178
  async getSensitiveInfo(
182
179
  patientId: string,
183
- requesterUserId: string
180
+ requesterUserId: string,
184
181
  ): Promise<PatientSensitiveInfo | null> {
185
182
  return getSensitiveInfoUtil(this.db, patientId, requesterUserId);
186
183
  }
187
184
 
188
185
  async getSensitiveInfoByUserRef(
189
186
  userRef: string,
190
- requesterUserId: string
187
+ requesterUserId: string,
191
188
  ): Promise<PatientSensitiveInfo | null> {
192
189
  const profile = await this.getPatientProfileByUserRef(userRef);
193
190
  if (!profile) return null;
@@ -197,47 +194,30 @@ export class PatientService extends BaseService {
197
194
  async updateSensitiveInfo(
198
195
  patientId: string,
199
196
  data: UpdatePatientSensitiveInfoData,
200
- requesterUserId: string
197
+ requesterUserId: string,
201
198
  ): Promise<PatientSensitiveInfo> {
202
199
  return updateSensitiveInfoUtil(this.db, patientId, data, requesterUserId);
203
200
  }
204
201
 
205
202
  // Metode za rad sa medicinskim informacijama
206
- async createMedicalInfo(
207
- patientId: string,
208
- data: CreatePatientMedicalInfoData
209
- ): Promise<void> {
203
+ async createMedicalInfo(patientId: string, data: CreatePatientMedicalInfoData): Promise<void> {
210
204
  const currentUser = await this.getCurrentUser();
211
- await createMedicalInfoUtil(
212
- this.db,
213
- patientId,
214
- data,
215
- currentUser.uid,
216
- currentUser.roles
217
- );
205
+ await createMedicalInfoUtil(this.db, patientId, data, currentUser.uid, currentUser.roles);
218
206
  }
219
207
 
220
208
  async getMedicalInfo(patientId: string): Promise<PatientMedicalInfo> {
221
209
  const currentUser = await this.getCurrentUser();
222
- return getMedicalInfoUtil(
223
- this.db,
224
- patientId,
225
- currentUser.uid,
226
- currentUser.roles
227
- );
210
+ return getMedicalInfoUtil(this.db, patientId, currentUser.uid, currentUser.roles);
228
211
  }
229
212
 
230
213
  async getMedicalInfoByUserRef(userRef: string): Promise<PatientMedicalInfo> {
231
214
  const profile = await this.getPatientProfileByUserRef(userRef);
232
- if (!profile) throw new Error("Patient profile not found");
215
+ if (!profile) throw new Error('Patient profile not found');
233
216
  return this.getMedicalInfo(profile.id);
234
217
  }
235
218
 
236
219
  // Metode za rad sa vitalnim statistikama
237
- async updateVitalStats(
238
- patientId: string,
239
- data: UpdateVitalStatsData
240
- ): Promise<void> {
220
+ async updateVitalStats(patientId: string, data: UpdateVitalStatsData): Promise<void> {
241
221
  const currentUser = await this.getCurrentUser();
242
222
  await updateVitalStatsUtil(this.db, patientId, data, currentUser.uid);
243
223
  }
@@ -248,10 +228,7 @@ export class PatientService extends BaseService {
248
228
  await addAllergyUtil(this.db, patientId, data, currentUser.uid);
249
229
  }
250
230
 
251
- async updateAllergy(
252
- patientId: string,
253
- data: UpdateAllergyData
254
- ): Promise<void> {
231
+ async updateAllergy(patientId: string, data: UpdateAllergyData): Promise<void> {
255
232
  const currentUser = await this.getCurrentUser();
256
233
  await updateAllergyUtil(this.db, patientId, data, currentUser.uid);
257
234
  }
@@ -262,98 +239,54 @@ export class PatientService extends BaseService {
262
239
  }
263
240
 
264
241
  // Metode za rad sa blocking conditions
265
- async addBlockingCondition(
266
- patientId: string,
267
- data: AddBlockingConditionData
268
- ): Promise<void> {
242
+ async addBlockingCondition(patientId: string, data: AddBlockingConditionData): Promise<void> {
269
243
  const currentUser = await this.getCurrentUser();
270
244
  await addBlockingConditionUtil(this.db, patientId, data, currentUser.uid);
271
245
  }
272
246
 
273
247
  async updateBlockingCondition(
274
248
  patientId: string,
275
- data: UpdateBlockingConditionData
249
+ data: UpdateBlockingConditionData,
276
250
  ): Promise<void> {
277
251
  const currentUser = await this.getCurrentUser();
278
- await updateBlockingConditionUtil(
279
- this.db,
280
- patientId,
281
- data,
282
- currentUser.uid
283
- );
252
+ await updateBlockingConditionUtil(this.db, patientId, data, currentUser.uid);
284
253
  }
285
254
 
286
- async removeBlockingCondition(
287
- patientId: string,
288
- conditionIndex: number
289
- ): Promise<void> {
255
+ async removeBlockingCondition(patientId: string, conditionIndex: number): Promise<void> {
290
256
  const currentUser = await this.getCurrentUser();
291
- await removeBlockingConditionUtil(
292
- this.db,
293
- patientId,
294
- conditionIndex,
295
- currentUser.uid
296
- );
257
+ await removeBlockingConditionUtil(this.db, patientId, conditionIndex, currentUser.uid);
297
258
  }
298
259
 
299
260
  // Metode za rad sa kontraindikacijama
300
- async addContraindication(
301
- patientId: string,
302
- data: AddContraindicationData
303
- ): Promise<void> {
261
+ async addContraindication(patientId: string, data: AddContraindicationData): Promise<void> {
304
262
  const currentUser = await this.getCurrentUser();
305
263
  await addContraindicationUtil(this.db, patientId, data, currentUser.uid);
306
264
  }
307
265
 
308
- async updateContraindication(
309
- patientId: string,
310
- data: UpdateContraindicationData
311
- ): Promise<void> {
266
+ async updateContraindication(patientId: string, data: UpdateContraindicationData): Promise<void> {
312
267
  const currentUser = await this.getCurrentUser();
313
268
  await updateContraindicationUtil(this.db, patientId, data, currentUser.uid);
314
269
  }
315
270
 
316
- async removeContraindication(
317
- patientId: string,
318
- contraindicationIndex: number
319
- ): Promise<void> {
271
+ async removeContraindication(patientId: string, contraindicationIndex: number): Promise<void> {
320
272
  const currentUser = await this.getCurrentUser();
321
- await removeContraindicationUtil(
322
- this.db,
323
- patientId,
324
- contraindicationIndex,
325
- currentUser.uid
326
- );
273
+ await removeContraindicationUtil(this.db, patientId, contraindicationIndex, currentUser.uid);
327
274
  }
328
275
 
329
276
  // Metode za rad sa medikacijama
330
- async addMedication(
331
- patientId: string,
332
- data: AddMedicationData
333
- ): Promise<void> {
277
+ async addMedication(patientId: string, data: AddMedicationData): Promise<void> {
334
278
  const currentUser = await this.getCurrentUser();
335
279
  await addMedicationUtil(this.db, patientId, data, currentUser.uid);
336
280
  }
337
281
 
338
- async updateMedication(
339
- patientId: string,
340
- data: UpdateMedicationData
341
- ): Promise<void> {
282
+ async updateMedication(patientId: string, data: UpdateMedicationData): Promise<void> {
342
283
  const currentUser = await this.getCurrentUser();
343
284
  await updateMedicationUtil(this.db, patientId, data, currentUser.uid);
344
285
  }
345
286
 
346
- async removeMedication(
347
- patientId: string,
348
- medicationIndex: number
349
- ): Promise<void> {
287
+ async removeMedication(patientId: string, medicationIndex: number): Promise<void> {
350
288
  const currentUser = await this.getCurrentUser();
351
- await removeMedicationUtil(
352
- this.db,
353
- patientId,
354
- medicationIndex,
355
- currentUser.uid
356
- );
289
+ await removeMedicationUtil(this.db, patientId, medicationIndex, currentUser.uid);
357
290
  }
358
291
 
359
292
  // Pomoćne metode
@@ -363,7 +296,7 @@ export class PatientService extends BaseService {
363
296
 
364
297
  async addExpoTokenByUserRef(userRef: string, token: string): Promise<void> {
365
298
  const profile = await this.getPatientProfileByUserRef(userRef);
366
- if (!profile) throw new Error("Patient profile not found");
299
+ if (!profile) throw new Error('Patient profile not found');
367
300
  await this.addExpoToken(profile.id, token);
368
301
  }
369
302
 
@@ -371,12 +304,9 @@ export class PatientService extends BaseService {
371
304
  await removeExpoTokenUtil(this.db, patientId, token);
372
305
  }
373
306
 
374
- async removeExpoTokenByUserRef(
375
- userRef: string,
376
- token: string
377
- ): Promise<void> {
307
+ async removeExpoTokenByUserRef(userRef: string, token: string): Promise<void> {
378
308
  const profile = await this.getPatientProfileByUserRef(userRef);
379
- if (!profile) throw new Error("Patient profile not found");
309
+ if (!profile) throw new Error('Patient profile not found');
380
310
  await this.removeExpoToken(profile.id, token);
381
311
  }
382
312
 
@@ -386,19 +316,17 @@ export class PatientService extends BaseService {
386
316
 
387
317
  async addPointsByUserRef(userRef: string, points: number): Promise<void> {
388
318
  const profile = await this.getPatientProfileByUserRef(userRef);
389
- if (!profile) throw new Error("Patient profile not found");
319
+ if (!profile) throw new Error('Patient profile not found');
390
320
  await this.addPoints(profile.id, points);
391
321
  }
392
322
 
393
323
  private async getCurrentUser(): Promise<any> {
394
324
  if (!this.auth.currentUser) {
395
- throw new Error("No authenticated user");
325
+ throw new Error('No authenticated user');
396
326
  }
397
- const userDoc = await getDoc(
398
- doc(this.db, "users", this.auth.currentUser.uid)
399
- );
327
+ const userDoc = await getDoc(doc(this.db, 'users', this.auth.currentUser.uid));
400
328
  if (!userDoc.exists()) {
401
- throw new Error("User not found");
329
+ throw new Error('User not found');
402
330
  }
403
331
  return userDoc.data();
404
332
  }
@@ -460,14 +388,14 @@ export class PatientService extends BaseService {
460
388
  // Metode za ažuriranje profila
461
389
  async updatePatientProfile(
462
390
  patientId: string,
463
- data: Partial<Omit<PatientProfile, "id" | "createdAt" | "updatedAt">>
391
+ data: Partial<Omit<PatientProfile, 'id' | 'createdAt' | 'updatedAt'>>,
464
392
  ): Promise<PatientProfile> {
465
393
  return updatePatientProfileUtil(this.db, patientId, data);
466
394
  }
467
395
 
468
396
  async updatePatientProfileByUserRef(
469
397
  userRef: string,
470
- data: Partial<Omit<PatientProfile, "id" | "createdAt" | "updatedAt">>
398
+ data: Partial<Omit<PatientProfile, 'id' | 'createdAt' | 'updatedAt'>>,
471
399
  ): Promise<PatientProfile> {
472
400
  return updatePatientProfileByUserRefUtil(this.db, userRef, data);
473
401
  }
@@ -482,7 +410,7 @@ export class PatientService extends BaseService {
482
410
  */
483
411
  async searchPatients(
484
412
  params: SearchPatientsParams,
485
- requester: RequesterInfo
413
+ requester: RequesterInfo,
486
414
  ): Promise<PatientProfile[]> {
487
415
  // We can potentially add more service-level logic here in the future,
488
416
  // like fetching additional data or enriching the results.
@@ -491,10 +419,26 @@ export class PatientService extends BaseService {
491
419
  `[PatientService.searchPatients] Initiating search with params:`,
492
420
  params,
493
421
  `by requester:`,
494
- requester
422
+ requester,
495
423
  );
496
424
 
497
425
  // The utility function already handles validation and security checks.
498
426
  return searchPatientsUtil(this.db, params, requester);
499
427
  }
428
+
429
+ /**
430
+ * Gets all patient profiles.
431
+ *
432
+ * @param {Object} options - Optional parameters for pagination
433
+ * @param {number} options.limit - Maximum number of profiles to return
434
+ * @param {string} options.startAfter - The ID of the document to start after (for pagination)
435
+ * @returns {Promise<PatientProfile[]>} A promise resolving to an array of all patient profiles.
436
+ */
437
+ async getAllPatients(options?: {
438
+ limit?: number;
439
+ startAfter?: string;
440
+ }): Promise<PatientProfile[]> {
441
+ console.log(`[PatientService.getAllPatients] Fetching patients with options:`, options);
442
+ return getAllPatientsUtil(this.db, options);
443
+ }
500
444
  }