@blackcode_sa/metaestetics-api 1.7.11 → 1.7.13

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.
@@ -0,0 +1,641 @@
1
+ import * as admin from "firebase-admin";
2
+ import {
3
+ Review,
4
+ ClinicReview,
5
+ PractitionerReview,
6
+ ProcedureReview,
7
+ REVIEWS_COLLECTION,
8
+ ClinicReviewInfo,
9
+ PractitionerReviewInfo,
10
+ ProcedureReviewInfo,
11
+ } from "../../../types/reviews";
12
+ import { CLINICS_COLLECTION } from "../../../types/clinic";
13
+ import { PRACTITIONERS_COLLECTION } from "../../../types/practitioner";
14
+ import { PROCEDURES_COLLECTION } from "../../../types/procedure";
15
+
16
+ /**
17
+ * @class ReviewsAggregationService
18
+ * @description Handles aggregation tasks related to review data updates.
19
+ * This service is intended to be used primarily by background functions (e.g., Cloud Functions)
20
+ * triggered by changes in the reviews collection.
21
+ */
22
+ export class ReviewsAggregationService {
23
+ private db: admin.firestore.Firestore;
24
+
25
+ /**
26
+ * Constructor for ReviewsAggregationService.
27
+ * @param firestore Optional Firestore instance. If not provided, it uses the default admin SDK instance.
28
+ */
29
+ constructor(firestore?: admin.firestore.Firestore) {
30
+ this.db = firestore || admin.firestore();
31
+ }
32
+
33
+ /**
34
+ * Process a newly created review and update all related entities
35
+ * @param review The newly created review
36
+ * @returns Promise resolving when all updates are complete
37
+ */
38
+ async processNewReview(review: Review): Promise<void> {
39
+ console.log(
40
+ `[ReviewsAggregationService] Processing new review: ${review.id}`
41
+ );
42
+
43
+ const updatePromises: Promise<any>[] = [];
44
+
45
+ // Update clinic if clinic review exists
46
+ if (review.clinicReview) {
47
+ updatePromises.push(
48
+ this.updateClinicReviewInfo(review.clinicReview.clinicId)
49
+ );
50
+ }
51
+
52
+ // Update practitioner if practitioner review exists
53
+ if (review.practitionerReview) {
54
+ updatePromises.push(
55
+ this.updatePractitionerReviewInfo(
56
+ review.practitionerReview.practitionerId
57
+ )
58
+ );
59
+ }
60
+
61
+ // Update procedure if procedure review exists
62
+ if (review.procedureReview) {
63
+ updatePromises.push(
64
+ this.updateProcedureReviewInfo(review.procedureReview.procedureId)
65
+ );
66
+ }
67
+
68
+ // Wait for all updates to complete
69
+ await Promise.all(updatePromises);
70
+ console.log(
71
+ `[ReviewsAggregationService] Successfully processed review: ${review.id}`
72
+ );
73
+ }
74
+
75
+ /**
76
+ * Process a deleted review and update all related entities
77
+ * @param review The deleted review
78
+ * @returns Promise resolving when all updates are complete
79
+ */
80
+ async processDeletedReview(review: Review): Promise<void> {
81
+ console.log(
82
+ `[ReviewsAggregationService] Processing deleted review: ${review.id}`
83
+ );
84
+
85
+ const updatePromises: Promise<any>[] = [];
86
+
87
+ // Update clinic if clinic review exists
88
+ if (review.clinicReview) {
89
+ updatePromises.push(
90
+ this.updateClinicReviewInfo(
91
+ review.clinicReview.clinicId,
92
+ review.clinicReview,
93
+ true
94
+ )
95
+ );
96
+ }
97
+
98
+ // Update practitioner if practitioner review exists
99
+ if (review.practitionerReview) {
100
+ updatePromises.push(
101
+ this.updatePractitionerReviewInfo(
102
+ review.practitionerReview.practitionerId,
103
+ review.practitionerReview,
104
+ true
105
+ )
106
+ );
107
+ }
108
+
109
+ // Update procedure if procedure review exists
110
+ if (review.procedureReview) {
111
+ updatePromises.push(
112
+ this.updateProcedureReviewInfo(
113
+ review.procedureReview.procedureId,
114
+ review.procedureReview,
115
+ true
116
+ )
117
+ );
118
+ }
119
+
120
+ // Wait for all updates to complete
121
+ await Promise.all(updatePromises);
122
+ console.log(
123
+ `[ReviewsAggregationService] Successfully processed deleted review: ${review.id}`
124
+ );
125
+ }
126
+
127
+ /**
128
+ * Updates the review info for a clinic
129
+ * @param clinicId The ID of the clinic to update
130
+ * @param removedReview Optional review being removed
131
+ * @param isRemoval Whether this update is for a review removal
132
+ * @returns The updated clinic review info
133
+ */
134
+ async updateClinicReviewInfo(
135
+ clinicId: string,
136
+ removedReview?: ClinicReview,
137
+ isRemoval: boolean = false
138
+ ): Promise<ClinicReviewInfo> {
139
+ console.log(
140
+ `[ReviewsAggregationService] Updating review info for clinic: ${clinicId}`
141
+ );
142
+
143
+ // Get the current clinic document
144
+ const clinicDoc = await this.db
145
+ .collection(CLINICS_COLLECTION)
146
+ .doc(clinicId)
147
+ .get();
148
+
149
+ if (!clinicDoc.exists) {
150
+ console.error(
151
+ `[ReviewsAggregationService] Clinic with ID ${clinicId} not found`
152
+ );
153
+ throw new Error(`Clinic with ID ${clinicId} not found`);
154
+ }
155
+
156
+ const clinicData = clinicDoc.data();
157
+ const currentReviewInfo = (clinicData?.reviewInfo as ClinicReviewInfo) || {
158
+ totalReviews: 0,
159
+ averageRating: 0,
160
+ cleanliness: 0,
161
+ facilities: 0,
162
+ staffFriendliness: 0,
163
+ waitingTime: 0,
164
+ accessibility: 0,
165
+ recommendationPercentage: 0,
166
+ };
167
+
168
+ // Get all reviews for this clinic
169
+ const reviewsQuery = await this.db
170
+ .collection(REVIEWS_COLLECTION)
171
+ .where("clinicReview.clinicId", "==", clinicId)
172
+ .get();
173
+
174
+ // If we're removing the last review or there are no reviews, set default values
175
+ if ((isRemoval && reviewsQuery.size <= 1) || reviewsQuery.empty) {
176
+ const updatedReviewInfo: ClinicReviewInfo = {
177
+ totalReviews: 0,
178
+ averageRating: 0,
179
+ cleanliness: 0,
180
+ facilities: 0,
181
+ staffFriendliness: 0,
182
+ waitingTime: 0,
183
+ accessibility: 0,
184
+ recommendationPercentage: 0,
185
+ };
186
+
187
+ await this.db.collection(CLINICS_COLLECTION).doc(clinicId).update({
188
+ reviewInfo: updatedReviewInfo,
189
+ updatedAt: admin.firestore.FieldValue.serverTimestamp(),
190
+ });
191
+
192
+ console.log(
193
+ `[ReviewsAggregationService] Reset review info for clinic: ${clinicId}`
194
+ );
195
+ return updatedReviewInfo;
196
+ }
197
+
198
+ // Calculate new averages from all reviews
199
+ const reviews = reviewsQuery.docs.map((doc) => doc.data() as Review);
200
+ const clinicReviews = reviews
201
+ .map((review) => review.clinicReview)
202
+ .filter((review): review is ClinicReview => review !== undefined);
203
+
204
+ // Calculate averages
205
+ let totalRating = 0;
206
+ let totalCleanliness = 0;
207
+ let totalFacilities = 0;
208
+ let totalStaffFriendliness = 0;
209
+ let totalWaitingTime = 0;
210
+ let totalAccessibility = 0;
211
+ let totalRecommendations = 0;
212
+
213
+ clinicReviews.forEach((review) => {
214
+ totalRating += review.overallRating;
215
+ totalCleanliness += review.cleanliness;
216
+ totalFacilities += review.facilities;
217
+ totalStaffFriendliness += review.staffFriendliness;
218
+ totalWaitingTime += review.waitingTime;
219
+ totalAccessibility += review.accessibility;
220
+ if (review.wouldRecommend) totalRecommendations++;
221
+ });
222
+
223
+ const count = clinicReviews.length;
224
+ const roundToOneDecimal = (value: number): number =>
225
+ Math.round((value / count) * 10) / 10;
226
+
227
+ const updatedReviewInfo: ClinicReviewInfo = {
228
+ totalReviews: count,
229
+ averageRating: roundToOneDecimal(totalRating),
230
+ cleanliness: roundToOneDecimal(totalCleanliness),
231
+ facilities: roundToOneDecimal(totalFacilities),
232
+ staffFriendliness: roundToOneDecimal(totalStaffFriendliness),
233
+ waitingTime: roundToOneDecimal(totalWaitingTime),
234
+ accessibility: roundToOneDecimal(totalAccessibility),
235
+ recommendationPercentage:
236
+ Math.round((totalRecommendations / count) * 1000) / 10,
237
+ };
238
+
239
+ // Update the clinic with the new review info
240
+ await this.db.collection(CLINICS_COLLECTION).doc(clinicId).update({
241
+ reviewInfo: updatedReviewInfo,
242
+ updatedAt: admin.firestore.FieldValue.serverTimestamp(),
243
+ });
244
+
245
+ console.log(
246
+ `[ReviewsAggregationService] Updated review info for clinic: ${clinicId}`
247
+ );
248
+ return updatedReviewInfo;
249
+ }
250
+
251
+ /**
252
+ * Updates the review info for a practitioner
253
+ * @param practitionerId The ID of the practitioner to update
254
+ * @param removedReview Optional review being removed
255
+ * @param isRemoval Whether this update is for a review removal
256
+ * @returns The updated practitioner review info
257
+ */
258
+ async updatePractitionerReviewInfo(
259
+ practitionerId: string,
260
+ removedReview?: PractitionerReview,
261
+ isRemoval: boolean = false
262
+ ): Promise<PractitionerReviewInfo> {
263
+ console.log(
264
+ `[ReviewsAggregationService] Updating review info for practitioner: ${practitionerId}`
265
+ );
266
+
267
+ // Get the current practitioner document
268
+ const practitionerDoc = await this.db
269
+ .collection(PRACTITIONERS_COLLECTION)
270
+ .doc(practitionerId)
271
+ .get();
272
+
273
+ if (!practitionerDoc.exists) {
274
+ console.error(
275
+ `[ReviewsAggregationService] Practitioner with ID ${practitionerId} not found`
276
+ );
277
+ throw new Error(`Practitioner with ID ${practitionerId} not found`);
278
+ }
279
+
280
+ const practitionerData = practitionerDoc.data();
281
+ const currentReviewInfo =
282
+ (practitionerData?.reviewInfo as PractitionerReviewInfo) || {
283
+ totalReviews: 0,
284
+ averageRating: 0,
285
+ knowledgeAndExpertise: 0,
286
+ communicationSkills: 0,
287
+ bedSideManner: 0,
288
+ thoroughness: 0,
289
+ trustworthiness: 0,
290
+ recommendationPercentage: 0,
291
+ };
292
+
293
+ // Get all reviews for this practitioner
294
+ const reviewsQuery = await this.db
295
+ .collection(REVIEWS_COLLECTION)
296
+ .where("practitionerReview.practitionerId", "==", practitionerId)
297
+ .get();
298
+
299
+ // If we're removing the last review or there are no reviews, set default values
300
+ if ((isRemoval && reviewsQuery.size <= 1) || reviewsQuery.empty) {
301
+ const updatedReviewInfo: PractitionerReviewInfo = {
302
+ totalReviews: 0,
303
+ averageRating: 0,
304
+ knowledgeAndExpertise: 0,
305
+ communicationSkills: 0,
306
+ bedSideManner: 0,
307
+ thoroughness: 0,
308
+ trustworthiness: 0,
309
+ recommendationPercentage: 0,
310
+ };
311
+
312
+ await this.db
313
+ .collection(PRACTITIONERS_COLLECTION)
314
+ .doc(practitionerId)
315
+ .update({
316
+ reviewInfo: updatedReviewInfo,
317
+ updatedAt: admin.firestore.FieldValue.serverTimestamp(),
318
+ });
319
+
320
+ // Also update doctor info in procedures with the new rating
321
+ await this.updateDoctorInfoInProcedures(practitionerId, 0);
322
+
323
+ console.log(
324
+ `[ReviewsAggregationService] Reset review info for practitioner: ${practitionerId}`
325
+ );
326
+ return updatedReviewInfo;
327
+ }
328
+
329
+ // Calculate new averages from all reviews
330
+ const reviews = reviewsQuery.docs.map((doc) => doc.data() as Review);
331
+ const practitionerReviews = reviews
332
+ .map((review) => review.practitionerReview)
333
+ .filter((review): review is PractitionerReview => review !== undefined);
334
+
335
+ // Calculate averages
336
+ let totalRating = 0;
337
+ let totalKnowledgeAndExpertise = 0;
338
+ let totalCommunicationSkills = 0;
339
+ let totalBedSideManner = 0;
340
+ let totalThoroughness = 0;
341
+ let totalTrustworthiness = 0;
342
+ let totalRecommendations = 0;
343
+
344
+ practitionerReviews.forEach((review) => {
345
+ totalRating += review.overallRating;
346
+ totalKnowledgeAndExpertise += review.knowledgeAndExpertise;
347
+ totalCommunicationSkills += review.communicationSkills;
348
+ totalBedSideManner += review.bedSideManner;
349
+ totalThoroughness += review.thoroughness;
350
+ totalTrustworthiness += review.trustworthiness;
351
+ if (review.wouldRecommend) totalRecommendations++;
352
+ });
353
+
354
+ const count = practitionerReviews.length;
355
+ const roundToOneDecimal = (value: number): number =>
356
+ Math.round((value / count) * 10) / 10;
357
+
358
+ const updatedReviewInfo: PractitionerReviewInfo = {
359
+ totalReviews: count,
360
+ averageRating: roundToOneDecimal(totalRating),
361
+ knowledgeAndExpertise: roundToOneDecimal(totalKnowledgeAndExpertise),
362
+ communicationSkills: roundToOneDecimal(totalCommunicationSkills),
363
+ bedSideManner: roundToOneDecimal(totalBedSideManner),
364
+ thoroughness: roundToOneDecimal(totalThoroughness),
365
+ trustworthiness: roundToOneDecimal(totalTrustworthiness),
366
+ recommendationPercentage:
367
+ Math.round((totalRecommendations / count) * 1000) / 10,
368
+ };
369
+
370
+ // Update the practitioner with the new review info
371
+ await this.db
372
+ .collection(PRACTITIONERS_COLLECTION)
373
+ .doc(practitionerId)
374
+ .update({
375
+ reviewInfo: updatedReviewInfo,
376
+ updatedAt: admin.firestore.FieldValue.serverTimestamp(),
377
+ });
378
+
379
+ // Also update doctor info in procedures with the new rating
380
+ await this.updateDoctorInfoInProcedures(
381
+ practitionerId,
382
+ updatedReviewInfo.averageRating
383
+ );
384
+
385
+ console.log(
386
+ `[ReviewsAggregationService] Updated review info for practitioner: ${practitionerId}`
387
+ );
388
+ return updatedReviewInfo;
389
+ }
390
+
391
+ /**
392
+ * Updates the review info for a procedure
393
+ * @param procedureId The ID of the procedure to update
394
+ * @param removedReview Optional review being removed
395
+ * @param isRemoval Whether this update is for a review removal
396
+ * @returns The updated procedure review info
397
+ */
398
+ async updateProcedureReviewInfo(
399
+ procedureId: string,
400
+ removedReview?: ProcedureReview,
401
+ isRemoval: boolean = false
402
+ ): Promise<ProcedureReviewInfo> {
403
+ console.log(
404
+ `[ReviewsAggregationService] Updating review info for procedure: ${procedureId}`
405
+ );
406
+
407
+ // Get the current procedure document
408
+ const procedureDoc = await this.db
409
+ .collection(PROCEDURES_COLLECTION)
410
+ .doc(procedureId)
411
+ .get();
412
+
413
+ if (!procedureDoc.exists) {
414
+ console.error(
415
+ `[ReviewsAggregationService] Procedure with ID ${procedureId} not found`
416
+ );
417
+ throw new Error(`Procedure with ID ${procedureId} not found`);
418
+ }
419
+
420
+ const procedureData = procedureDoc.data();
421
+ const currentReviewInfo =
422
+ (procedureData?.reviewInfo as ProcedureReviewInfo) || {
423
+ totalReviews: 0,
424
+ averageRating: 0,
425
+ effectivenessOfTreatment: 0,
426
+ outcomeExplanation: 0,
427
+ painManagement: 0,
428
+ followUpCare: 0,
429
+ valueForMoney: 0,
430
+ recommendationPercentage: 0,
431
+ };
432
+
433
+ // Get all reviews for this procedure
434
+ const reviewsQuery = await this.db
435
+ .collection(REVIEWS_COLLECTION)
436
+ .where("procedureReview.procedureId", "==", procedureId)
437
+ .get();
438
+
439
+ // If we're removing the last review or there are no reviews, set default values
440
+ if ((isRemoval && reviewsQuery.size <= 1) || reviewsQuery.empty) {
441
+ const updatedReviewInfo: ProcedureReviewInfo = {
442
+ totalReviews: 0,
443
+ averageRating: 0,
444
+ effectivenessOfTreatment: 0,
445
+ outcomeExplanation: 0,
446
+ painManagement: 0,
447
+ followUpCare: 0,
448
+ valueForMoney: 0,
449
+ recommendationPercentage: 0,
450
+ };
451
+
452
+ await this.db.collection(PROCEDURES_COLLECTION).doc(procedureId).update({
453
+ reviewInfo: updatedReviewInfo,
454
+ updatedAt: admin.firestore.FieldValue.serverTimestamp(),
455
+ });
456
+
457
+ console.log(
458
+ `[ReviewsAggregationService] Reset review info for procedure: ${procedureId}`
459
+ );
460
+ return updatedReviewInfo;
461
+ }
462
+
463
+ // Calculate new averages from all reviews
464
+ const reviews = reviewsQuery.docs.map((doc) => doc.data() as Review);
465
+ const procedureReviews = reviews
466
+ .map((review) => review.procedureReview)
467
+ .filter((review): review is ProcedureReview => review !== undefined);
468
+
469
+ // Calculate averages
470
+ let totalRating = 0;
471
+ let totalEffectivenessOfTreatment = 0;
472
+ let totalOutcomeExplanation = 0;
473
+ let totalPainManagement = 0;
474
+ let totalFollowUpCare = 0;
475
+ let totalValueForMoney = 0;
476
+ let totalRecommendations = 0;
477
+
478
+ procedureReviews.forEach((review) => {
479
+ totalRating += review.overallRating;
480
+ totalEffectivenessOfTreatment += review.effectivenessOfTreatment;
481
+ totalOutcomeExplanation += review.outcomeExplanation;
482
+ totalPainManagement += review.painManagement;
483
+ totalFollowUpCare += review.followUpCare;
484
+ totalValueForMoney += review.valueForMoney;
485
+ if (review.wouldRecommend) totalRecommendations++;
486
+ });
487
+
488
+ const count = procedureReviews.length;
489
+ const roundToOneDecimal = (value: number): number =>
490
+ Math.round((value / count) * 10) / 10;
491
+
492
+ const updatedReviewInfo: ProcedureReviewInfo = {
493
+ totalReviews: count,
494
+ averageRating: roundToOneDecimal(totalRating),
495
+ effectivenessOfTreatment: roundToOneDecimal(
496
+ totalEffectivenessOfTreatment
497
+ ),
498
+ outcomeExplanation: roundToOneDecimal(totalOutcomeExplanation),
499
+ painManagement: roundToOneDecimal(totalPainManagement),
500
+ followUpCare: roundToOneDecimal(totalFollowUpCare),
501
+ valueForMoney: roundToOneDecimal(totalValueForMoney),
502
+ recommendationPercentage:
503
+ Math.round((totalRecommendations / count) * 1000) / 10,
504
+ };
505
+
506
+ // Update the procedure with the new review info
507
+ await this.db.collection(PROCEDURES_COLLECTION).doc(procedureId).update({
508
+ reviewInfo: updatedReviewInfo,
509
+ updatedAt: admin.firestore.FieldValue.serverTimestamp(),
510
+ });
511
+
512
+ console.log(
513
+ `[ReviewsAggregationService] Updated review info for procedure: ${procedureId}`
514
+ );
515
+ return updatedReviewInfo;
516
+ }
517
+
518
+ /**
519
+ * Updates doctorInfo rating in all procedures for a practitioner
520
+ * @param practitionerId The ID of the practitioner
521
+ * @param rating The new rating to set
522
+ */
523
+ private async updateDoctorInfoInProcedures(
524
+ practitionerId: string,
525
+ rating: number
526
+ ): Promise<void> {
527
+ console.log(
528
+ `[ReviewsAggregationService] Updating doctor info in procedures for practitioner: ${practitionerId}`
529
+ );
530
+
531
+ // Find all procedures for this practitioner
532
+ const proceduresQuery = await this.db
533
+ .collection(PROCEDURES_COLLECTION)
534
+ .where("practitionerId", "==", practitionerId)
535
+ .get();
536
+
537
+ if (proceduresQuery.empty) {
538
+ console.log(
539
+ `[ReviewsAggregationService] No procedures found for practitioner: ${practitionerId}`
540
+ );
541
+ return;
542
+ }
543
+
544
+ // Batch update all procedures
545
+ const batch = this.db.batch();
546
+
547
+ proceduresQuery.docs.forEach((docSnapshot) => {
548
+ const procedureRef = this.db
549
+ .collection(PROCEDURES_COLLECTION)
550
+ .doc(docSnapshot.id);
551
+ batch.update(procedureRef, {
552
+ "doctorInfo.rating": rating,
553
+ updatedAt: admin.firestore.FieldValue.serverTimestamp(),
554
+ });
555
+ });
556
+
557
+ await batch.commit();
558
+ console.log(
559
+ `[ReviewsAggregationService] Updated doctor info in ${proceduresQuery.size} procedures for practitioner: ${practitionerId}`
560
+ );
561
+ }
562
+
563
+ /**
564
+ * Verifies a review as checked by admin/staff
565
+ * @param reviewId The ID of the review to verify
566
+ */
567
+ async verifyReview(reviewId: string): Promise<void> {
568
+ console.log(`[ReviewsAggregationService] Verifying review: ${reviewId}`);
569
+
570
+ // Get the review
571
+ const reviewDoc = await this.db
572
+ .collection(REVIEWS_COLLECTION)
573
+ .doc(reviewId)
574
+ .get();
575
+
576
+ if (!reviewDoc.exists) {
577
+ console.error(
578
+ `[ReviewsAggregationService] Review with ID ${reviewId} not found`
579
+ );
580
+ throw new Error(`Review with ID ${reviewId} not found`);
581
+ }
582
+
583
+ const review = reviewDoc.data() as Review;
584
+ const batch = this.db.batch();
585
+ const reviewRef = this.db.collection(REVIEWS_COLLECTION).doc(reviewId);
586
+
587
+ // Update clinic review if it exists
588
+ if (review.clinicReview) {
589
+ review.clinicReview.isVerified = true;
590
+ }
591
+
592
+ // Update practitioner review if it exists
593
+ if (review.practitionerReview) {
594
+ review.practitionerReview.isVerified = true;
595
+ }
596
+
597
+ // Update procedure review if it exists
598
+ if (review.procedureReview) {
599
+ review.procedureReview.isVerified = true;
600
+ }
601
+
602
+ // Update the review
603
+ batch.update(reviewRef, {
604
+ clinicReview: review.clinicReview,
605
+ practitionerReview: review.practitionerReview,
606
+ procedureReview: review.procedureReview,
607
+ updatedAt: admin.firestore.FieldValue.serverTimestamp(),
608
+ });
609
+
610
+ await batch.commit();
611
+ console.log(
612
+ `[ReviewsAggregationService] Successfully verified review: ${reviewId}`
613
+ );
614
+ }
615
+
616
+ /**
617
+ * Calculate the average of all reviews for an entity
618
+ * @param entityId The entity ID
619
+ * @param entityType The type of entity ('clinic', 'practitioner', or 'procedure')
620
+ * @returns Promise that resolves to the calculated review info
621
+ */
622
+ async calculateEntityReviewInfo(
623
+ entityId: string,
624
+ entityType: "clinic" | "practitioner" | "procedure"
625
+ ): Promise<ClinicReviewInfo | PractitionerReviewInfo | ProcedureReviewInfo> {
626
+ console.log(
627
+ `[ReviewsAggregationService] Calculating review info for ${entityType}: ${entityId}`
628
+ );
629
+
630
+ switch (entityType) {
631
+ case "clinic":
632
+ return this.updateClinicReviewInfo(entityId);
633
+ case "practitioner":
634
+ return this.updatePractitionerReviewInfo(entityId);
635
+ case "procedure":
636
+ return this.updateProcedureReviewInfo(entityId);
637
+ default:
638
+ throw new Error(`Invalid entity type: ${entityType}`);
639
+ }
640
+ }
641
+ }
@@ -22,6 +22,8 @@ import { PractitionerAggregationService } from "./aggregation/practitioner/pract
22
22
  import { ProcedureAggregationService } from "./aggregation/procedure/procedure.aggregation.service";
23
23
  import { PatientAggregationService } from "./aggregation/patient/patient.aggregation.service";
24
24
  import { AppointmentAggregationService } from "./aggregation/appointment/appointment.aggregation.service";
25
+ import { FilledFormsAggregationService } from "./aggregation/forms/filled-forms.aggregation.service";
26
+ import { ReviewsAggregationService } from "./aggregation/reviews/reviews.aggregation.service";
25
27
 
26
28
  // Import mailing services
27
29
  import { BaseMailingService } from "./mailing/base.mailing.service";
@@ -50,6 +52,8 @@ export type { DoctorInfo } from "../types/clinic";
50
52
  export type { Procedure, ProcedureSummaryInfo } from "../types/procedure";
51
53
  export type { PatientProfile as Patient } from "../types/patient";
52
54
  export type { Appointment } from "../types/appointment";
55
+ export type { FilledDocument } from "../types/documentation-templates";
56
+ export type { Review } from "../types/reviews";
53
57
 
54
58
  // Re-export enums/consts
55
59
  export {
@@ -70,6 +74,8 @@ export {
70
74
  PatientAggregationService,
71
75
  AppointmentAggregationService,
72
76
  PatientRequirementsAdminService,
77
+ FilledFormsAggregationService,
78
+ ReviewsAggregationService,
73
79
  };
74
80
 
75
81
  // Export mailing services
@@ -128,7 +134,8 @@ export * from "./mailing/appointment/appointment.mailing.service";
128
134
  export * from "./notifications/notifications.admin";
129
135
  export * from "./requirements/patient-requirements.admin.service";
130
136
  export * from "./aggregation/appointment/appointment.aggregation.service";
131
-
137
+ export * from "./aggregation/forms/filled-forms.aggregation.service";
138
+ export * from "./aggregation/reviews/reviews.aggregation.service";
132
139
  // Re-export types that Cloud Functions might need direct access to
133
140
  export * from "../types/appointment";
134
141
  // Add other types as needed
@@ -285,6 +285,10 @@ export class AuthService extends BaseService {
285
285
  subscriptionModel:
286
286
  data.clinicGroupData.subscriptionModel ||
287
287
  SubscriptionModel.NO_SUBSCRIPTION,
288
+ onboarding: {
289
+ completed: false,
290
+ step: 1,
291
+ },
288
292
  };
289
293
  console.log("[AUTH] Clinic group data prepared", {
290
294
  groupName: createClinicGroupData.name,