@blackcode_sa/metaestetics-api 1.13.5 → 1.13.6
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/admin/index.d.mts +20 -1
- package/dist/admin/index.d.ts +20 -1
- package/dist/admin/index.js +217 -1
- package/dist/admin/index.mjs +217 -1
- package/package.json +121 -121
- package/src/__mocks__/firstore.ts +10 -10
- package/src/admin/aggregation/README.md +79 -79
- package/src/admin/aggregation/appointment/README.md +128 -128
- package/src/admin/aggregation/appointment/appointment.aggregation.service.ts +1984 -1984
- package/src/admin/aggregation/appointment/index.ts +1 -1
- package/src/admin/aggregation/clinic/README.md +52 -52
- package/src/admin/aggregation/clinic/clinic.aggregation.service.ts +966 -703
- package/src/admin/aggregation/clinic/index.ts +1 -1
- package/src/admin/aggregation/forms/README.md +13 -13
- package/src/admin/aggregation/forms/filled-forms.aggregation.service.ts +322 -322
- package/src/admin/aggregation/forms/index.ts +1 -1
- package/src/admin/aggregation/index.ts +8 -8
- package/src/admin/aggregation/patient/README.md +27 -27
- package/src/admin/aggregation/patient/index.ts +1 -1
- package/src/admin/aggregation/patient/patient.aggregation.service.ts +141 -141
- package/src/admin/aggregation/practitioner/README.md +42 -42
- package/src/admin/aggregation/practitioner/index.ts +1 -1
- package/src/admin/aggregation/practitioner/practitioner.aggregation.service.ts +433 -433
- package/src/admin/aggregation/practitioner-invite/index.ts +1 -1
- package/src/admin/aggregation/practitioner-invite/practitioner-invite.aggregation.service.ts +961 -961
- package/src/admin/aggregation/procedure/README.md +43 -43
- package/src/admin/aggregation/procedure/index.ts +1 -1
- package/src/admin/aggregation/procedure/procedure.aggregation.service.ts +702 -702
- package/src/admin/aggregation/reviews/index.ts +1 -1
- package/src/admin/aggregation/reviews/reviews.aggregation.service.ts +689 -689
- package/src/admin/analytics/analytics.admin.service.ts +278 -278
- package/src/admin/analytics/index.ts +2 -2
- package/src/admin/booking/README.md +125 -125
- package/src/admin/booking/booking.admin.ts +1037 -1037
- package/src/admin/booking/booking.calculator.ts +712 -712
- package/src/admin/booking/booking.types.ts +59 -59
- package/src/admin/booking/index.ts +3 -3
- package/src/admin/booking/timezones-problem.md +185 -185
- package/src/admin/calendar/README.md +7 -7
- package/src/admin/calendar/calendar.admin.service.ts +345 -345
- package/src/admin/calendar/index.ts +1 -1
- package/src/admin/documentation-templates/document-manager.admin.ts +260 -260
- package/src/admin/documentation-templates/index.ts +1 -1
- package/src/admin/free-consultation/free-consultation-utils.admin.ts +148 -148
- package/src/admin/free-consultation/index.ts +1 -1
- package/src/admin/index.ts +81 -81
- package/src/admin/logger/index.ts +78 -78
- package/src/admin/mailing/README.md +95 -95
- package/src/admin/mailing/appointment/appointment.mailing.service.ts +732 -732
- package/src/admin/mailing/appointment/index.ts +1 -1
- package/src/admin/mailing/appointment/templates/patient/appointment-confirmed.html +40 -40
- package/src/admin/mailing/base.mailing.service.ts +208 -208
- package/src/admin/mailing/index.ts +3 -3
- package/src/admin/mailing/practitionerInvite/existing-practitioner-invite.mailing.ts +611 -611
- package/src/admin/mailing/practitionerInvite/index.ts +2 -2
- package/src/admin/mailing/practitionerInvite/practitionerInvite.mailing.ts +395 -395
- package/src/admin/mailing/practitionerInvite/templates/existing-practitioner-invitation.template.ts +155 -155
- package/src/admin/mailing/practitionerInvite/templates/invitation.template.ts +101 -101
- package/src/admin/mailing/practitionerInvite/templates/invite-accepted-notification.template.ts +228 -228
- package/src/admin/mailing/practitionerInvite/templates/invite-rejected-notification.template.ts +242 -242
- package/src/admin/notifications/index.ts +1 -1
- package/src/admin/notifications/notifications.admin.ts +710 -710
- package/src/admin/requirements/README.md +128 -128
- package/src/admin/requirements/index.ts +1 -1
- package/src/admin/requirements/patient-requirements.admin.service.ts +475 -475
- package/src/admin/users/index.ts +1 -1
- package/src/admin/users/user-profile.admin.ts +405 -405
- package/src/backoffice/constants/certification.constants.ts +13 -13
- package/src/backoffice/constants/index.ts +1 -1
- package/src/backoffice/errors/backoffice.errors.ts +181 -181
- package/src/backoffice/errors/index.ts +1 -1
- package/src/backoffice/expo-safe/README.md +26 -26
- package/src/backoffice/expo-safe/index.ts +41 -41
- package/src/backoffice/index.ts +5 -5
- package/src/backoffice/services/FIXES_README.md +102 -102
- package/src/backoffice/services/README.md +57 -57
- package/src/backoffice/services/analytics.service.proposal.md +863 -863
- package/src/backoffice/services/analytics.service.summary.md +143 -143
- package/src/backoffice/services/brand.service.ts +256 -256
- package/src/backoffice/services/category.service.ts +384 -384
- package/src/backoffice/services/constants.service.ts +385 -385
- package/src/backoffice/services/documentation-template.service.ts +202 -202
- package/src/backoffice/services/index.ts +10 -10
- package/src/backoffice/services/migrate-products.ts +116 -116
- package/src/backoffice/services/product.service.ts +553 -553
- package/src/backoffice/services/requirement.service.ts +235 -235
- package/src/backoffice/services/subcategory.service.ts +461 -461
- package/src/backoffice/services/technology.service.ts +1151 -1151
- package/src/backoffice/types/README.md +12 -12
- package/src/backoffice/types/admin-constants.types.ts +69 -69
- package/src/backoffice/types/brand.types.ts +29 -29
- package/src/backoffice/types/category.types.ts +67 -67
- package/src/backoffice/types/documentation-templates.types.ts +28 -28
- package/src/backoffice/types/index.ts +10 -10
- package/src/backoffice/types/procedure-product.types.ts +38 -38
- package/src/backoffice/types/product.types.ts +240 -240
- package/src/backoffice/types/requirement.types.ts +63 -63
- package/src/backoffice/types/static/README.md +18 -18
- package/src/backoffice/types/static/blocking-condition.types.ts +21 -21
- package/src/backoffice/types/static/certification.types.ts +37 -37
- package/src/backoffice/types/static/contraindication.types.ts +19 -19
- package/src/backoffice/types/static/index.ts +6 -6
- package/src/backoffice/types/static/pricing.types.ts +16 -16
- package/src/backoffice/types/static/procedure-family.types.ts +14 -14
- package/src/backoffice/types/static/treatment-benefit.types.ts +22 -22
- package/src/backoffice/types/subcategory.types.ts +34 -34
- package/src/backoffice/types/technology.types.ts +168 -168
- package/src/backoffice/validations/index.ts +1 -1
- package/src/backoffice/validations/schemas.ts +164 -164
- package/src/config/__mocks__/firebase.ts +99 -99
- package/src/config/firebase.ts +78 -78
- package/src/config/index.ts +9 -9
- package/src/errors/auth.error.ts +6 -6
- package/src/errors/auth.errors.ts +200 -200
- package/src/errors/clinic.errors.ts +32 -32
- package/src/errors/firebase.errors.ts +47 -47
- package/src/errors/user.errors.ts +99 -99
- package/src/index.backup.ts +407 -407
- package/src/index.ts +6 -6
- package/src/locales/en.ts +31 -31
- package/src/recommender/admin/index.ts +1 -1
- package/src/recommender/admin/services/recommender.service.admin.ts +5 -5
- package/src/recommender/front/index.ts +1 -1
- package/src/recommender/front/services/onboarding.service.ts +5 -5
- package/src/recommender/front/services/recommender.service.ts +3 -3
- package/src/recommender/index.ts +1 -1
- package/src/services/PATIENTAUTH.MD +197 -197
- package/src/services/README.md +106 -106
- package/src/services/__tests__/auth/auth.mock.test.ts +17 -17
- package/src/services/__tests__/auth/auth.setup.ts +293 -293
- package/src/services/__tests__/auth.service.test.ts +346 -346
- package/src/services/__tests__/base.service.test.ts +77 -77
- package/src/services/__tests__/user.service.test.ts +528 -528
- package/src/services/analytics/ARCHITECTURE.md +199 -199
- package/src/services/analytics/CLOUD_FUNCTIONS.md +225 -225
- package/src/services/analytics/GROUPED_ANALYTICS.md +501 -501
- package/src/services/analytics/QUICK_START.md +393 -393
- package/src/services/analytics/README.md +304 -304
- package/src/services/analytics/SUMMARY.md +141 -141
- package/src/services/analytics/TRENDS.md +380 -380
- package/src/services/analytics/USAGE_GUIDE.md +518 -518
- package/src/services/analytics/analytics-cloud.service.ts +222 -222
- package/src/services/analytics/analytics.service.ts +2142 -2142
- package/src/services/analytics/index.ts +4 -4
- package/src/services/analytics/review-analytics.service.ts +941 -941
- package/src/services/analytics/utils/appointment-filtering.utils.ts +138 -138
- package/src/services/analytics/utils/cost-calculation.utils.ts +182 -182
- package/src/services/analytics/utils/grouping.utils.ts +434 -434
- package/src/services/analytics/utils/stored-analytics.utils.ts +347 -347
- package/src/services/analytics/utils/time-calculation.utils.ts +186 -186
- package/src/services/analytics/utils/trend-calculation.utils.ts +200 -200
- package/src/services/appointment/README.md +17 -17
- package/src/services/appointment/appointment.service.ts +2558 -2558
- package/src/services/appointment/index.ts +1 -1
- package/src/services/appointment/utils/appointment.utils.ts +552 -552
- package/src/services/appointment/utils/extended-procedure.utils.ts +314 -314
- package/src/services/appointment/utils/form-initialization.utils.ts +225 -225
- package/src/services/appointment/utils/recommended-procedure.utils.ts +195 -195
- package/src/services/appointment/utils/zone-management.utils.ts +353 -353
- package/src/services/appointment/utils/zone-photo.utils.ts +152 -152
- package/src/services/auth/auth.service.ts +989 -989
- package/src/services/auth/auth.v2.service.ts +961 -961
- package/src/services/auth/index.ts +7 -7
- package/src/services/auth/utils/error.utils.ts +90 -90
- package/src/services/auth/utils/firebase.utils.ts +49 -49
- package/src/services/auth/utils/index.ts +21 -21
- package/src/services/auth/utils/practitioner.utils.ts +125 -125
- package/src/services/base.service.ts +41 -41
- package/src/services/calendar/calendar.service.ts +1077 -1077
- package/src/services/calendar/calendar.v2.service.ts +1683 -1683
- package/src/services/calendar/calendar.v3.service.ts +313 -313
- package/src/services/calendar/externalCalendar.service.ts +178 -178
- package/src/services/calendar/index.ts +5 -5
- package/src/services/calendar/synced-calendars.service.ts +743 -743
- package/src/services/calendar/utils/appointment.utils.ts +265 -265
- package/src/services/calendar/utils/calendar-event.utils.ts +646 -646
- package/src/services/calendar/utils/clinic.utils.ts +237 -237
- package/src/services/calendar/utils/docs.utils.ts +157 -157
- package/src/services/calendar/utils/google-calendar.utils.ts +697 -697
- package/src/services/calendar/utils/index.ts +8 -8
- package/src/services/calendar/utils/patient.utils.ts +198 -198
- package/src/services/calendar/utils/practitioner.utils.ts +221 -221
- package/src/services/calendar/utils/synced-calendar.utils.ts +472 -472
- package/src/services/clinic/README.md +204 -204
- package/src/services/clinic/__tests__/clinic-admin.service.test.ts +287 -287
- package/src/services/clinic/__tests__/clinic-group.service.test.ts +352 -352
- package/src/services/clinic/__tests__/clinic.service.test.ts +354 -354
- package/src/services/clinic/billing-transactions.service.ts +217 -217
- package/src/services/clinic/clinic-admin.service.ts +202 -202
- package/src/services/clinic/clinic-group.service.ts +310 -310
- package/src/services/clinic/clinic.service.ts +708 -708
- package/src/services/clinic/index.ts +5 -5
- package/src/services/clinic/practitioner-invite.service.ts +519 -519
- package/src/services/clinic/utils/admin.utils.ts +551 -551
- package/src/services/clinic/utils/clinic-group.utils.ts +646 -646
- package/src/services/clinic/utils/clinic.utils.ts +949 -949
- package/src/services/clinic/utils/filter.utils.d.ts +23 -23
- package/src/services/clinic/utils/filter.utils.ts +446 -446
- package/src/services/clinic/utils/index.ts +11 -11
- package/src/services/clinic/utils/photos.utils.ts +188 -188
- package/src/services/clinic/utils/search.utils.ts +84 -84
- package/src/services/clinic/utils/tag.utils.ts +124 -124
- package/src/services/documentation-templates/documentation-template.service.ts +537 -537
- package/src/services/documentation-templates/filled-document.service.ts +587 -587
- package/src/services/documentation-templates/index.ts +2 -2
- package/src/services/index.ts +14 -14
- package/src/services/media/index.ts +1 -1
- package/src/services/media/media.service.ts +418 -418
- package/src/services/notifications/__tests__/notification.service.test.ts +242 -242
- package/src/services/notifications/index.ts +1 -1
- package/src/services/notifications/notification.service.ts +215 -215
- package/src/services/patient/README.md +48 -48
- package/src/services/patient/To-Do.md +43 -43
- package/src/services/patient/__tests__/patient.service.test.ts +294 -294
- package/src/services/patient/index.ts +2 -2
- package/src/services/patient/patient.service.ts +883 -883
- package/src/services/patient/patientRequirements.service.ts +285 -285
- package/src/services/patient/utils/aesthetic-analysis.utils.ts +176 -176
- package/src/services/patient/utils/clinic.utils.ts +80 -80
- package/src/services/patient/utils/docs.utils.ts +142 -142
- package/src/services/patient/utils/index.ts +9 -9
- package/src/services/patient/utils/location.utils.ts +126 -126
- package/src/services/patient/utils/medical-stuff.utils.ts +143 -143
- package/src/services/patient/utils/medical.utils.ts +458 -458
- package/src/services/patient/utils/practitioner.utils.ts +260 -260
- package/src/services/patient/utils/profile.utils.ts +510 -510
- package/src/services/patient/utils/sensitive.utils.ts +260 -260
- package/src/services/patient/utils/token.utils.ts +211 -211
- package/src/services/practitioner/README.md +145 -145
- package/src/services/practitioner/index.ts +1 -1
- package/src/services/practitioner/practitioner.service.ts +1742 -1742
- package/src/services/procedure/README.md +163 -163
- package/src/services/procedure/index.ts +1 -1
- package/src/services/procedure/procedure.service.ts +2200 -2200
- package/src/services/reviews/index.ts +1 -1
- package/src/services/reviews/reviews.service.ts +734 -734
- package/src/services/user/index.ts +1 -1
- package/src/services/user/user.service.ts +489 -489
- package/src/services/user/user.v2.service.ts +466 -466
- package/src/types/analytics/analytics.types.ts +597 -597
- package/src/types/analytics/grouped-analytics.types.ts +173 -173
- package/src/types/analytics/index.ts +4 -4
- package/src/types/analytics/stored-analytics.types.ts +137 -137
- package/src/types/appointment/index.ts +480 -480
- package/src/types/calendar/index.ts +258 -258
- package/src/types/calendar/synced-calendar.types.ts +66 -66
- package/src/types/clinic/index.ts +498 -498
- package/src/types/clinic/practitioner-invite.types.ts +91 -91
- package/src/types/clinic/preferences.types.ts +159 -159
- package/src/types/clinic/to-do +3 -3
- package/src/types/documentation-templates/index.ts +308 -308
- package/src/types/index.ts +47 -47
- package/src/types/notifications/README.md +77 -77
- package/src/types/notifications/index.ts +286 -286
- package/src/types/patient/aesthetic-analysis.types.ts +66 -66
- package/src/types/patient/allergies.ts +58 -58
- package/src/types/patient/index.ts +275 -275
- package/src/types/patient/medical-info.types.ts +152 -152
- package/src/types/patient/patient-requirements.ts +92 -92
- package/src/types/patient/token.types.ts +61 -61
- package/src/types/practitioner/index.ts +206 -206
- package/src/types/procedure/index.ts +181 -181
- package/src/types/profile/index.ts +39 -39
- package/src/types/reviews/index.ts +132 -132
- package/src/types/tz-lookup.d.ts +4 -4
- package/src/types/user/index.ts +38 -38
- package/src/utils/TIMESTAMPS.md +176 -176
- package/src/utils/TimestampUtils.ts +241 -241
- package/src/utils/index.ts +1 -1
- package/src/validations/appointment.schema.ts +574 -574
- package/src/validations/calendar.schema.ts +225 -225
- package/src/validations/clinic.schema.ts +494 -494
- package/src/validations/common.schema.ts +25 -25
- package/src/validations/documentation-templates/index.ts +1 -1
- package/src/validations/documentation-templates/template.schema.ts +220 -220
- package/src/validations/documentation-templates.schema.ts +10 -10
- package/src/validations/index.ts +20 -20
- package/src/validations/media.schema.ts +10 -10
- package/src/validations/notification.schema.ts +90 -90
- package/src/validations/patient/aesthetic-analysis.schema.ts +55 -55
- package/src/validations/patient/medical-info.schema.ts +125 -125
- package/src/validations/patient/patient-requirements.schema.ts +84 -84
- package/src/validations/patient/token.schema.ts +29 -29
- package/src/validations/patient.schema.ts +217 -217
- package/src/validations/practitioner.schema.ts +222 -222
- package/src/validations/procedure-product.schema.ts +41 -41
- package/src/validations/procedure.schema.ts +124 -124
- package/src/validations/profile-info.schema.ts +41 -41
- package/src/validations/reviews.schema.ts +195 -195
- package/src/validations/schemas.ts +104 -104
- package/src/validations/shared.schema.ts +78 -78
package/dist/admin/index.d.mts
CHANGED
|
@@ -3603,13 +3603,32 @@ declare class ClinicAggregationService {
|
|
|
3603
3603
|
* Removes clinic from practitioners when a clinic is deleted.
|
|
3604
3604
|
* @param practitionerIds IDs of practitioners associated with the clinic.
|
|
3605
3605
|
* @param clinicId The ID of the deleted clinic.
|
|
3606
|
+
* @param checkAndDeactivateDoctors If true, checks if doctors have remaining active clinics and deactivates them if not.
|
|
3606
3607
|
*/
|
|
3607
|
-
removeClinicFromPractitioners(practitionerIds: string[], clinicId: string): Promise<void>;
|
|
3608
|
+
removeClinicFromPractitioners(practitionerIds: string[], clinicId: string, checkAndDeactivateDoctors?: boolean): Promise<void>;
|
|
3609
|
+
/**
|
|
3610
|
+
* Checks if practitioners have any remaining active clinics and deactivates them if not.
|
|
3611
|
+
* @param practitionerIds IDs of practitioners to check
|
|
3612
|
+
*/
|
|
3613
|
+
checkAndDeactivateDoctorsWithNoActiveClinics(practitionerIds: string[]): Promise<void>;
|
|
3614
|
+
/**
|
|
3615
|
+
* Checks if practitioners were deactivated because they had no active clinics,
|
|
3616
|
+
* and reactivates them if this clinic was their only clinic.
|
|
3617
|
+
* @param practitionerIds IDs of practitioners associated with the reactivated clinic
|
|
3618
|
+
* @param clinicId ID of the reactivated clinic
|
|
3619
|
+
*/
|
|
3620
|
+
checkAndReactivateDoctorsForClinic(practitionerIds: string[], clinicId: string): Promise<void>;
|
|
3608
3621
|
/**
|
|
3609
3622
|
* Inactivates all procedures associated with a deleted clinic
|
|
3610
3623
|
* @param procedureIds IDs of procedures associated with the clinic
|
|
3611
3624
|
*/
|
|
3612
3625
|
inactivateProceduresForClinic(procedureIds: string[]): Promise<void>;
|
|
3626
|
+
/**
|
|
3627
|
+
* Reactivates all procedures associated with a reactivated clinic
|
|
3628
|
+
* Only reactivates procedures that still exist (haven't been deleted)
|
|
3629
|
+
* @param procedureIds IDs of procedures associated with the clinic
|
|
3630
|
+
*/
|
|
3631
|
+
reactivateProceduresForClinic(procedureIds: string[]): Promise<void>;
|
|
3613
3632
|
/**
|
|
3614
3633
|
* Removes clinic from clinic group when a clinic is deleted
|
|
3615
3634
|
* @param clinicGroupId ID of the parent clinic group
|
package/dist/admin/index.d.ts
CHANGED
|
@@ -3603,13 +3603,32 @@ declare class ClinicAggregationService {
|
|
|
3603
3603
|
* Removes clinic from practitioners when a clinic is deleted.
|
|
3604
3604
|
* @param practitionerIds IDs of practitioners associated with the clinic.
|
|
3605
3605
|
* @param clinicId The ID of the deleted clinic.
|
|
3606
|
+
* @param checkAndDeactivateDoctors If true, checks if doctors have remaining active clinics and deactivates them if not.
|
|
3606
3607
|
*/
|
|
3607
|
-
removeClinicFromPractitioners(practitionerIds: string[], clinicId: string): Promise<void>;
|
|
3608
|
+
removeClinicFromPractitioners(practitionerIds: string[], clinicId: string, checkAndDeactivateDoctors?: boolean): Promise<void>;
|
|
3609
|
+
/**
|
|
3610
|
+
* Checks if practitioners have any remaining active clinics and deactivates them if not.
|
|
3611
|
+
* @param practitionerIds IDs of practitioners to check
|
|
3612
|
+
*/
|
|
3613
|
+
checkAndDeactivateDoctorsWithNoActiveClinics(practitionerIds: string[]): Promise<void>;
|
|
3614
|
+
/**
|
|
3615
|
+
* Checks if practitioners were deactivated because they had no active clinics,
|
|
3616
|
+
* and reactivates them if this clinic was their only clinic.
|
|
3617
|
+
* @param practitionerIds IDs of practitioners associated with the reactivated clinic
|
|
3618
|
+
* @param clinicId ID of the reactivated clinic
|
|
3619
|
+
*/
|
|
3620
|
+
checkAndReactivateDoctorsForClinic(practitionerIds: string[], clinicId: string): Promise<void>;
|
|
3608
3621
|
/**
|
|
3609
3622
|
* Inactivates all procedures associated with a deleted clinic
|
|
3610
3623
|
* @param procedureIds IDs of procedures associated with the clinic
|
|
3611
3624
|
*/
|
|
3612
3625
|
inactivateProceduresForClinic(procedureIds: string[]): Promise<void>;
|
|
3626
|
+
/**
|
|
3627
|
+
* Reactivates all procedures associated with a reactivated clinic
|
|
3628
|
+
* Only reactivates procedures that still exist (haven't been deleted)
|
|
3629
|
+
* @param procedureIds IDs of procedures associated with the clinic
|
|
3630
|
+
*/
|
|
3631
|
+
reactivateProceduresForClinic(procedureIds: string[]): Promise<void>;
|
|
3613
3632
|
/**
|
|
3614
3633
|
* Removes clinic from clinic group when a clinic is deleted
|
|
3615
3634
|
* @param clinicGroupId ID of the parent clinic group
|
package/dist/admin/index.js
CHANGED
|
@@ -4399,8 +4399,9 @@ var ClinicAggregationService = class {
|
|
|
4399
4399
|
* Removes clinic from practitioners when a clinic is deleted.
|
|
4400
4400
|
* @param practitionerIds IDs of practitioners associated with the clinic.
|
|
4401
4401
|
* @param clinicId The ID of the deleted clinic.
|
|
4402
|
+
* @param checkAndDeactivateDoctors If true, checks if doctors have remaining active clinics and deactivates them if not.
|
|
4402
4403
|
*/
|
|
4403
|
-
async removeClinicFromPractitioners(practitionerIds, clinicId) {
|
|
4404
|
+
async removeClinicFromPractitioners(practitionerIds, clinicId, checkAndDeactivateDoctors = false) {
|
|
4404
4405
|
if (!practitionerIds || practitionerIds.length === 0) {
|
|
4405
4406
|
console.log(
|
|
4406
4407
|
"[ClinicAggregationService] No practitioner IDs provided for clinic removal. Skipping."
|
|
@@ -4408,6 +4409,7 @@ var ClinicAggregationService = class {
|
|
|
4408
4409
|
return;
|
|
4409
4410
|
}
|
|
4410
4411
|
const batch = this.db.batch();
|
|
4412
|
+
const practitionersToCheck = [];
|
|
4411
4413
|
console.log(
|
|
4412
4414
|
`[ClinicAggregationService] Starting batch removal of Clinic (ID: ${clinicId}) from ${practitionerIds.length} practitioners.`
|
|
4413
4415
|
);
|
|
@@ -4429,6 +4431,9 @@ var ClinicAggregationService = class {
|
|
|
4429
4431
|
clinicsInfo: filteredClinicsInfo,
|
|
4430
4432
|
updatedAt: admin7.firestore.FieldValue.serverTimestamp()
|
|
4431
4433
|
});
|
|
4434
|
+
if (checkAndDeactivateDoctors) {
|
|
4435
|
+
practitionersToCheck.push(practitionerId);
|
|
4436
|
+
}
|
|
4432
4437
|
}
|
|
4433
4438
|
}
|
|
4434
4439
|
try {
|
|
@@ -4436,6 +4441,11 @@ var ClinicAggregationService = class {
|
|
|
4436
4441
|
console.log(
|
|
4437
4442
|
`[ClinicAggregationService] Successfully removed Clinic (ID: ${clinicId}) from ${practitionerIds.length} practitioners.`
|
|
4438
4443
|
);
|
|
4444
|
+
if (checkAndDeactivateDoctors && practitionersToCheck.length > 0) {
|
|
4445
|
+
await this.checkAndDeactivateDoctorsWithNoActiveClinics(
|
|
4446
|
+
practitionersToCheck
|
|
4447
|
+
);
|
|
4448
|
+
}
|
|
4439
4449
|
} catch (error) {
|
|
4440
4450
|
console.error(
|
|
4441
4451
|
`[ClinicAggregationService] Error committing batch removal for Clinic (ID: ${clinicId}) from practitioners:`,
|
|
@@ -4444,6 +4454,161 @@ var ClinicAggregationService = class {
|
|
|
4444
4454
|
throw error;
|
|
4445
4455
|
}
|
|
4446
4456
|
}
|
|
4457
|
+
/**
|
|
4458
|
+
* Checks if practitioners have any remaining active clinics and deactivates them if not.
|
|
4459
|
+
* @param practitionerIds IDs of practitioners to check
|
|
4460
|
+
*/
|
|
4461
|
+
async checkAndDeactivateDoctorsWithNoActiveClinics(practitionerIds) {
|
|
4462
|
+
if (!practitionerIds || practitionerIds.length === 0) {
|
|
4463
|
+
return;
|
|
4464
|
+
}
|
|
4465
|
+
console.log(
|
|
4466
|
+
`[ClinicAggregationService] Checking ${practitionerIds.length} practitioners for remaining active clinics.`
|
|
4467
|
+
);
|
|
4468
|
+
const batch = this.db.batch();
|
|
4469
|
+
let deactivationCount = 0;
|
|
4470
|
+
for (const practitionerId of practitionerIds) {
|
|
4471
|
+
const practitionerRef = this.db.collection(PRACTITIONERS_COLLECTION).doc(practitionerId);
|
|
4472
|
+
const practitionerDoc = await practitionerRef.get();
|
|
4473
|
+
if (!practitionerDoc.exists) {
|
|
4474
|
+
continue;
|
|
4475
|
+
}
|
|
4476
|
+
const practitionerData = practitionerDoc.data();
|
|
4477
|
+
const clinicIds = (practitionerData == null ? void 0 : practitionerData.clinics) || [];
|
|
4478
|
+
if (clinicIds.length === 0) {
|
|
4479
|
+
console.log(
|
|
4480
|
+
`[ClinicAggregationService] Practitioner ${practitionerId} has no remaining clinics. Deactivating.`
|
|
4481
|
+
);
|
|
4482
|
+
batch.update(practitionerRef, {
|
|
4483
|
+
isActive: false,
|
|
4484
|
+
updatedAt: admin7.firestore.FieldValue.serverTimestamp()
|
|
4485
|
+
});
|
|
4486
|
+
deactivationCount++;
|
|
4487
|
+
} else {
|
|
4488
|
+
const clinicRefs = clinicIds.map(
|
|
4489
|
+
(id) => this.db.collection(CLINICS_COLLECTION).doc(id)
|
|
4490
|
+
);
|
|
4491
|
+
const clinicDocs = await Promise.all(
|
|
4492
|
+
clinicRefs.map((ref) => ref.get())
|
|
4493
|
+
);
|
|
4494
|
+
const hasActiveClinic = clinicDocs.some(
|
|
4495
|
+
(doc3) => {
|
|
4496
|
+
var _a;
|
|
4497
|
+
return doc3.exists && ((_a = doc3.data()) == null ? void 0 : _a.isActive) === true;
|
|
4498
|
+
}
|
|
4499
|
+
);
|
|
4500
|
+
if (!hasActiveClinic) {
|
|
4501
|
+
console.log(
|
|
4502
|
+
`[ClinicAggregationService] Practitioner ${practitionerId} has no remaining active clinics. Deactivating.`
|
|
4503
|
+
);
|
|
4504
|
+
batch.update(practitionerRef, {
|
|
4505
|
+
isActive: false,
|
|
4506
|
+
updatedAt: admin7.firestore.FieldValue.serverTimestamp()
|
|
4507
|
+
});
|
|
4508
|
+
deactivationCount++;
|
|
4509
|
+
}
|
|
4510
|
+
}
|
|
4511
|
+
}
|
|
4512
|
+
if (deactivationCount > 0) {
|
|
4513
|
+
try {
|
|
4514
|
+
await batch.commit();
|
|
4515
|
+
console.log(
|
|
4516
|
+
`[ClinicAggregationService] Successfully deactivated ${deactivationCount} practitioners with no remaining active clinics.`
|
|
4517
|
+
);
|
|
4518
|
+
} catch (error) {
|
|
4519
|
+
console.error(
|
|
4520
|
+
`[ClinicAggregationService] Error deactivating practitioners:`,
|
|
4521
|
+
error
|
|
4522
|
+
);
|
|
4523
|
+
throw error;
|
|
4524
|
+
}
|
|
4525
|
+
} else {
|
|
4526
|
+
console.log(
|
|
4527
|
+
`[ClinicAggregationService] All practitioners have remaining active clinics. No deactivations needed.`
|
|
4528
|
+
);
|
|
4529
|
+
}
|
|
4530
|
+
}
|
|
4531
|
+
/**
|
|
4532
|
+
* Checks if practitioners were deactivated because they had no active clinics,
|
|
4533
|
+
* and reactivates them if this clinic was their only clinic.
|
|
4534
|
+
* @param practitionerIds IDs of practitioners associated with the reactivated clinic
|
|
4535
|
+
* @param clinicId ID of the reactivated clinic
|
|
4536
|
+
*/
|
|
4537
|
+
async checkAndReactivateDoctorsForClinic(practitionerIds, clinicId) {
|
|
4538
|
+
if (!practitionerIds || practitionerIds.length === 0) {
|
|
4539
|
+
return;
|
|
4540
|
+
}
|
|
4541
|
+
console.log(
|
|
4542
|
+
`[ClinicAggregationService] Checking ${practitionerIds.length} practitioners for reactivation after clinic ${clinicId} was reactivated.`
|
|
4543
|
+
);
|
|
4544
|
+
const batch = this.db.batch();
|
|
4545
|
+
let reactivationCount = 0;
|
|
4546
|
+
for (const practitionerId of practitionerIds) {
|
|
4547
|
+
const practitionerRef = this.db.collection(PRACTITIONERS_COLLECTION).doc(practitionerId);
|
|
4548
|
+
const practitionerDoc = await practitionerRef.get();
|
|
4549
|
+
if (!practitionerDoc.exists) {
|
|
4550
|
+
continue;
|
|
4551
|
+
}
|
|
4552
|
+
const practitionerData = practitionerDoc.data();
|
|
4553
|
+
if ((practitionerData == null ? void 0 : practitionerData.isActive) === false) {
|
|
4554
|
+
const clinicIds = (practitionerData == null ? void 0 : practitionerData.clinics) || [];
|
|
4555
|
+
if (clinicIds.includes(clinicId)) {
|
|
4556
|
+
const otherClinicIds = clinicIds.filter((id) => id !== clinicId);
|
|
4557
|
+
if (otherClinicIds.length === 0) {
|
|
4558
|
+
console.log(
|
|
4559
|
+
`[ClinicAggregationService] Practitioner ${practitionerId} was deactivated because clinic ${clinicId} was their only clinic. Reactivating.`
|
|
4560
|
+
);
|
|
4561
|
+
batch.update(practitionerRef, {
|
|
4562
|
+
isActive: true,
|
|
4563
|
+
updatedAt: admin7.firestore.FieldValue.serverTimestamp()
|
|
4564
|
+
});
|
|
4565
|
+
reactivationCount++;
|
|
4566
|
+
} else {
|
|
4567
|
+
const otherClinicRefs = otherClinicIds.map(
|
|
4568
|
+
(id) => this.db.collection(CLINICS_COLLECTION).doc(id)
|
|
4569
|
+
);
|
|
4570
|
+
const otherClinicDocs = await Promise.all(
|
|
4571
|
+
otherClinicRefs.map((ref) => ref.get())
|
|
4572
|
+
);
|
|
4573
|
+
const hasOtherActiveClinic = otherClinicDocs.some(
|
|
4574
|
+
(doc3) => {
|
|
4575
|
+
var _a;
|
|
4576
|
+
return doc3.exists && ((_a = doc3.data()) == null ? void 0 : _a.isActive) === true;
|
|
4577
|
+
}
|
|
4578
|
+
);
|
|
4579
|
+
if (!hasOtherActiveClinic) {
|
|
4580
|
+
console.log(
|
|
4581
|
+
`[ClinicAggregationService] Practitioner ${practitionerId} has no other active clinics. Reactivating because clinic ${clinicId} was reactivated.`
|
|
4582
|
+
);
|
|
4583
|
+
batch.update(practitionerRef, {
|
|
4584
|
+
isActive: true,
|
|
4585
|
+
updatedAt: admin7.firestore.FieldValue.serverTimestamp()
|
|
4586
|
+
});
|
|
4587
|
+
reactivationCount++;
|
|
4588
|
+
}
|
|
4589
|
+
}
|
|
4590
|
+
}
|
|
4591
|
+
}
|
|
4592
|
+
}
|
|
4593
|
+
if (reactivationCount > 0) {
|
|
4594
|
+
try {
|
|
4595
|
+
await batch.commit();
|
|
4596
|
+
console.log(
|
|
4597
|
+
`[ClinicAggregationService] Successfully reactivated ${reactivationCount} practitioners.`
|
|
4598
|
+
);
|
|
4599
|
+
} catch (error) {
|
|
4600
|
+
console.error(
|
|
4601
|
+
`[ClinicAggregationService] Error reactivating practitioners:`,
|
|
4602
|
+
error
|
|
4603
|
+
);
|
|
4604
|
+
throw error;
|
|
4605
|
+
}
|
|
4606
|
+
} else {
|
|
4607
|
+
console.log(
|
|
4608
|
+
`[ClinicAggregationService] No practitioners needed reactivation.`
|
|
4609
|
+
);
|
|
4610
|
+
}
|
|
4611
|
+
}
|
|
4447
4612
|
/**
|
|
4448
4613
|
* Inactivates all procedures associated with a deleted clinic
|
|
4449
4614
|
* @param procedureIds IDs of procedures associated with the clinic
|
|
@@ -4479,6 +4644,57 @@ var ClinicAggregationService = class {
|
|
|
4479
4644
|
throw error;
|
|
4480
4645
|
}
|
|
4481
4646
|
}
|
|
4647
|
+
/**
|
|
4648
|
+
* Reactivates all procedures associated with a reactivated clinic
|
|
4649
|
+
* Only reactivates procedures that still exist (haven't been deleted)
|
|
4650
|
+
* @param procedureIds IDs of procedures associated with the clinic
|
|
4651
|
+
*/
|
|
4652
|
+
async reactivateProceduresForClinic(procedureIds) {
|
|
4653
|
+
if (!procedureIds || procedureIds.length === 0) {
|
|
4654
|
+
console.log(
|
|
4655
|
+
"[ClinicAggregationService] No procedure IDs provided for reactivation. Skipping."
|
|
4656
|
+
);
|
|
4657
|
+
return;
|
|
4658
|
+
}
|
|
4659
|
+
const batch = this.db.batch();
|
|
4660
|
+
let reactivationCount = 0;
|
|
4661
|
+
console.log(
|
|
4662
|
+
`[ClinicAggregationService] Starting reactivation of ${procedureIds.length} procedures.`
|
|
4663
|
+
);
|
|
4664
|
+
for (const procedureId of procedureIds) {
|
|
4665
|
+
const procedureRef = this.db.collection(PROCEDURES_COLLECTION).doc(procedureId);
|
|
4666
|
+
const procedureDoc = await procedureRef.get();
|
|
4667
|
+
if (procedureDoc.exists) {
|
|
4668
|
+
batch.update(procedureRef, {
|
|
4669
|
+
isActive: true,
|
|
4670
|
+
updatedAt: admin7.firestore.FieldValue.serverTimestamp()
|
|
4671
|
+
});
|
|
4672
|
+
reactivationCount++;
|
|
4673
|
+
} else {
|
|
4674
|
+
console.log(
|
|
4675
|
+
`[ClinicAggregationService] Procedure ${procedureId} no longer exists. Skipping reactivation.`
|
|
4676
|
+
);
|
|
4677
|
+
}
|
|
4678
|
+
}
|
|
4679
|
+
if (reactivationCount > 0) {
|
|
4680
|
+
try {
|
|
4681
|
+
await batch.commit();
|
|
4682
|
+
console.log(
|
|
4683
|
+
`[ClinicAggregationService] Successfully reactivated ${reactivationCount} procedures.`
|
|
4684
|
+
);
|
|
4685
|
+
} catch (error) {
|
|
4686
|
+
console.error(
|
|
4687
|
+
`[ClinicAggregationService] Error committing batch reactivation of procedures:`,
|
|
4688
|
+
error
|
|
4689
|
+
);
|
|
4690
|
+
throw error;
|
|
4691
|
+
}
|
|
4692
|
+
} else {
|
|
4693
|
+
console.log(
|
|
4694
|
+
`[ClinicAggregationService] No procedures to reactivate (all may have been deleted).`
|
|
4695
|
+
);
|
|
4696
|
+
}
|
|
4697
|
+
}
|
|
4482
4698
|
/**
|
|
4483
4699
|
* Removes clinic from clinic group when a clinic is deleted
|
|
4484
4700
|
* @param clinicGroupId ID of the parent clinic group
|
package/dist/admin/index.mjs
CHANGED
|
@@ -4326,8 +4326,9 @@ var ClinicAggregationService = class {
|
|
|
4326
4326
|
* Removes clinic from practitioners when a clinic is deleted.
|
|
4327
4327
|
* @param practitionerIds IDs of practitioners associated with the clinic.
|
|
4328
4328
|
* @param clinicId The ID of the deleted clinic.
|
|
4329
|
+
* @param checkAndDeactivateDoctors If true, checks if doctors have remaining active clinics and deactivates them if not.
|
|
4329
4330
|
*/
|
|
4330
|
-
async removeClinicFromPractitioners(practitionerIds, clinicId) {
|
|
4331
|
+
async removeClinicFromPractitioners(practitionerIds, clinicId, checkAndDeactivateDoctors = false) {
|
|
4331
4332
|
if (!practitionerIds || practitionerIds.length === 0) {
|
|
4332
4333
|
console.log(
|
|
4333
4334
|
"[ClinicAggregationService] No practitioner IDs provided for clinic removal. Skipping."
|
|
@@ -4335,6 +4336,7 @@ var ClinicAggregationService = class {
|
|
|
4335
4336
|
return;
|
|
4336
4337
|
}
|
|
4337
4338
|
const batch = this.db.batch();
|
|
4339
|
+
const practitionersToCheck = [];
|
|
4338
4340
|
console.log(
|
|
4339
4341
|
`[ClinicAggregationService] Starting batch removal of Clinic (ID: ${clinicId}) from ${practitionerIds.length} practitioners.`
|
|
4340
4342
|
);
|
|
@@ -4356,6 +4358,9 @@ var ClinicAggregationService = class {
|
|
|
4356
4358
|
clinicsInfo: filteredClinicsInfo,
|
|
4357
4359
|
updatedAt: admin7.firestore.FieldValue.serverTimestamp()
|
|
4358
4360
|
});
|
|
4361
|
+
if (checkAndDeactivateDoctors) {
|
|
4362
|
+
practitionersToCheck.push(practitionerId);
|
|
4363
|
+
}
|
|
4359
4364
|
}
|
|
4360
4365
|
}
|
|
4361
4366
|
try {
|
|
@@ -4363,6 +4368,11 @@ var ClinicAggregationService = class {
|
|
|
4363
4368
|
console.log(
|
|
4364
4369
|
`[ClinicAggregationService] Successfully removed Clinic (ID: ${clinicId}) from ${practitionerIds.length} practitioners.`
|
|
4365
4370
|
);
|
|
4371
|
+
if (checkAndDeactivateDoctors && practitionersToCheck.length > 0) {
|
|
4372
|
+
await this.checkAndDeactivateDoctorsWithNoActiveClinics(
|
|
4373
|
+
practitionersToCheck
|
|
4374
|
+
);
|
|
4375
|
+
}
|
|
4366
4376
|
} catch (error) {
|
|
4367
4377
|
console.error(
|
|
4368
4378
|
`[ClinicAggregationService] Error committing batch removal for Clinic (ID: ${clinicId}) from practitioners:`,
|
|
@@ -4371,6 +4381,161 @@ var ClinicAggregationService = class {
|
|
|
4371
4381
|
throw error;
|
|
4372
4382
|
}
|
|
4373
4383
|
}
|
|
4384
|
+
/**
|
|
4385
|
+
* Checks if practitioners have any remaining active clinics and deactivates them if not.
|
|
4386
|
+
* @param practitionerIds IDs of practitioners to check
|
|
4387
|
+
*/
|
|
4388
|
+
async checkAndDeactivateDoctorsWithNoActiveClinics(practitionerIds) {
|
|
4389
|
+
if (!practitionerIds || practitionerIds.length === 0) {
|
|
4390
|
+
return;
|
|
4391
|
+
}
|
|
4392
|
+
console.log(
|
|
4393
|
+
`[ClinicAggregationService] Checking ${practitionerIds.length} practitioners for remaining active clinics.`
|
|
4394
|
+
);
|
|
4395
|
+
const batch = this.db.batch();
|
|
4396
|
+
let deactivationCount = 0;
|
|
4397
|
+
for (const practitionerId of practitionerIds) {
|
|
4398
|
+
const practitionerRef = this.db.collection(PRACTITIONERS_COLLECTION).doc(practitionerId);
|
|
4399
|
+
const practitionerDoc = await practitionerRef.get();
|
|
4400
|
+
if (!practitionerDoc.exists) {
|
|
4401
|
+
continue;
|
|
4402
|
+
}
|
|
4403
|
+
const practitionerData = practitionerDoc.data();
|
|
4404
|
+
const clinicIds = (practitionerData == null ? void 0 : practitionerData.clinics) || [];
|
|
4405
|
+
if (clinicIds.length === 0) {
|
|
4406
|
+
console.log(
|
|
4407
|
+
`[ClinicAggregationService] Practitioner ${practitionerId} has no remaining clinics. Deactivating.`
|
|
4408
|
+
);
|
|
4409
|
+
batch.update(practitionerRef, {
|
|
4410
|
+
isActive: false,
|
|
4411
|
+
updatedAt: admin7.firestore.FieldValue.serverTimestamp()
|
|
4412
|
+
});
|
|
4413
|
+
deactivationCount++;
|
|
4414
|
+
} else {
|
|
4415
|
+
const clinicRefs = clinicIds.map(
|
|
4416
|
+
(id) => this.db.collection(CLINICS_COLLECTION).doc(id)
|
|
4417
|
+
);
|
|
4418
|
+
const clinicDocs = await Promise.all(
|
|
4419
|
+
clinicRefs.map((ref) => ref.get())
|
|
4420
|
+
);
|
|
4421
|
+
const hasActiveClinic = clinicDocs.some(
|
|
4422
|
+
(doc3) => {
|
|
4423
|
+
var _a;
|
|
4424
|
+
return doc3.exists && ((_a = doc3.data()) == null ? void 0 : _a.isActive) === true;
|
|
4425
|
+
}
|
|
4426
|
+
);
|
|
4427
|
+
if (!hasActiveClinic) {
|
|
4428
|
+
console.log(
|
|
4429
|
+
`[ClinicAggregationService] Practitioner ${practitionerId} has no remaining active clinics. Deactivating.`
|
|
4430
|
+
);
|
|
4431
|
+
batch.update(practitionerRef, {
|
|
4432
|
+
isActive: false,
|
|
4433
|
+
updatedAt: admin7.firestore.FieldValue.serverTimestamp()
|
|
4434
|
+
});
|
|
4435
|
+
deactivationCount++;
|
|
4436
|
+
}
|
|
4437
|
+
}
|
|
4438
|
+
}
|
|
4439
|
+
if (deactivationCount > 0) {
|
|
4440
|
+
try {
|
|
4441
|
+
await batch.commit();
|
|
4442
|
+
console.log(
|
|
4443
|
+
`[ClinicAggregationService] Successfully deactivated ${deactivationCount} practitioners with no remaining active clinics.`
|
|
4444
|
+
);
|
|
4445
|
+
} catch (error) {
|
|
4446
|
+
console.error(
|
|
4447
|
+
`[ClinicAggregationService] Error deactivating practitioners:`,
|
|
4448
|
+
error
|
|
4449
|
+
);
|
|
4450
|
+
throw error;
|
|
4451
|
+
}
|
|
4452
|
+
} else {
|
|
4453
|
+
console.log(
|
|
4454
|
+
`[ClinicAggregationService] All practitioners have remaining active clinics. No deactivations needed.`
|
|
4455
|
+
);
|
|
4456
|
+
}
|
|
4457
|
+
}
|
|
4458
|
+
/**
|
|
4459
|
+
* Checks if practitioners were deactivated because they had no active clinics,
|
|
4460
|
+
* and reactivates them if this clinic was their only clinic.
|
|
4461
|
+
* @param practitionerIds IDs of practitioners associated with the reactivated clinic
|
|
4462
|
+
* @param clinicId ID of the reactivated clinic
|
|
4463
|
+
*/
|
|
4464
|
+
async checkAndReactivateDoctorsForClinic(practitionerIds, clinicId) {
|
|
4465
|
+
if (!practitionerIds || practitionerIds.length === 0) {
|
|
4466
|
+
return;
|
|
4467
|
+
}
|
|
4468
|
+
console.log(
|
|
4469
|
+
`[ClinicAggregationService] Checking ${practitionerIds.length} practitioners for reactivation after clinic ${clinicId} was reactivated.`
|
|
4470
|
+
);
|
|
4471
|
+
const batch = this.db.batch();
|
|
4472
|
+
let reactivationCount = 0;
|
|
4473
|
+
for (const practitionerId of practitionerIds) {
|
|
4474
|
+
const practitionerRef = this.db.collection(PRACTITIONERS_COLLECTION).doc(practitionerId);
|
|
4475
|
+
const practitionerDoc = await practitionerRef.get();
|
|
4476
|
+
if (!practitionerDoc.exists) {
|
|
4477
|
+
continue;
|
|
4478
|
+
}
|
|
4479
|
+
const practitionerData = practitionerDoc.data();
|
|
4480
|
+
if ((practitionerData == null ? void 0 : practitionerData.isActive) === false) {
|
|
4481
|
+
const clinicIds = (practitionerData == null ? void 0 : practitionerData.clinics) || [];
|
|
4482
|
+
if (clinicIds.includes(clinicId)) {
|
|
4483
|
+
const otherClinicIds = clinicIds.filter((id) => id !== clinicId);
|
|
4484
|
+
if (otherClinicIds.length === 0) {
|
|
4485
|
+
console.log(
|
|
4486
|
+
`[ClinicAggregationService] Practitioner ${practitionerId} was deactivated because clinic ${clinicId} was their only clinic. Reactivating.`
|
|
4487
|
+
);
|
|
4488
|
+
batch.update(practitionerRef, {
|
|
4489
|
+
isActive: true,
|
|
4490
|
+
updatedAt: admin7.firestore.FieldValue.serverTimestamp()
|
|
4491
|
+
});
|
|
4492
|
+
reactivationCount++;
|
|
4493
|
+
} else {
|
|
4494
|
+
const otherClinicRefs = otherClinicIds.map(
|
|
4495
|
+
(id) => this.db.collection(CLINICS_COLLECTION).doc(id)
|
|
4496
|
+
);
|
|
4497
|
+
const otherClinicDocs = await Promise.all(
|
|
4498
|
+
otherClinicRefs.map((ref) => ref.get())
|
|
4499
|
+
);
|
|
4500
|
+
const hasOtherActiveClinic = otherClinicDocs.some(
|
|
4501
|
+
(doc3) => {
|
|
4502
|
+
var _a;
|
|
4503
|
+
return doc3.exists && ((_a = doc3.data()) == null ? void 0 : _a.isActive) === true;
|
|
4504
|
+
}
|
|
4505
|
+
);
|
|
4506
|
+
if (!hasOtherActiveClinic) {
|
|
4507
|
+
console.log(
|
|
4508
|
+
`[ClinicAggregationService] Practitioner ${practitionerId} has no other active clinics. Reactivating because clinic ${clinicId} was reactivated.`
|
|
4509
|
+
);
|
|
4510
|
+
batch.update(practitionerRef, {
|
|
4511
|
+
isActive: true,
|
|
4512
|
+
updatedAt: admin7.firestore.FieldValue.serverTimestamp()
|
|
4513
|
+
});
|
|
4514
|
+
reactivationCount++;
|
|
4515
|
+
}
|
|
4516
|
+
}
|
|
4517
|
+
}
|
|
4518
|
+
}
|
|
4519
|
+
}
|
|
4520
|
+
if (reactivationCount > 0) {
|
|
4521
|
+
try {
|
|
4522
|
+
await batch.commit();
|
|
4523
|
+
console.log(
|
|
4524
|
+
`[ClinicAggregationService] Successfully reactivated ${reactivationCount} practitioners.`
|
|
4525
|
+
);
|
|
4526
|
+
} catch (error) {
|
|
4527
|
+
console.error(
|
|
4528
|
+
`[ClinicAggregationService] Error reactivating practitioners:`,
|
|
4529
|
+
error
|
|
4530
|
+
);
|
|
4531
|
+
throw error;
|
|
4532
|
+
}
|
|
4533
|
+
} else {
|
|
4534
|
+
console.log(
|
|
4535
|
+
`[ClinicAggregationService] No practitioners needed reactivation.`
|
|
4536
|
+
);
|
|
4537
|
+
}
|
|
4538
|
+
}
|
|
4374
4539
|
/**
|
|
4375
4540
|
* Inactivates all procedures associated with a deleted clinic
|
|
4376
4541
|
* @param procedureIds IDs of procedures associated with the clinic
|
|
@@ -4406,6 +4571,57 @@ var ClinicAggregationService = class {
|
|
|
4406
4571
|
throw error;
|
|
4407
4572
|
}
|
|
4408
4573
|
}
|
|
4574
|
+
/**
|
|
4575
|
+
* Reactivates all procedures associated with a reactivated clinic
|
|
4576
|
+
* Only reactivates procedures that still exist (haven't been deleted)
|
|
4577
|
+
* @param procedureIds IDs of procedures associated with the clinic
|
|
4578
|
+
*/
|
|
4579
|
+
async reactivateProceduresForClinic(procedureIds) {
|
|
4580
|
+
if (!procedureIds || procedureIds.length === 0) {
|
|
4581
|
+
console.log(
|
|
4582
|
+
"[ClinicAggregationService] No procedure IDs provided for reactivation. Skipping."
|
|
4583
|
+
);
|
|
4584
|
+
return;
|
|
4585
|
+
}
|
|
4586
|
+
const batch = this.db.batch();
|
|
4587
|
+
let reactivationCount = 0;
|
|
4588
|
+
console.log(
|
|
4589
|
+
`[ClinicAggregationService] Starting reactivation of ${procedureIds.length} procedures.`
|
|
4590
|
+
);
|
|
4591
|
+
for (const procedureId of procedureIds) {
|
|
4592
|
+
const procedureRef = this.db.collection(PROCEDURES_COLLECTION).doc(procedureId);
|
|
4593
|
+
const procedureDoc = await procedureRef.get();
|
|
4594
|
+
if (procedureDoc.exists) {
|
|
4595
|
+
batch.update(procedureRef, {
|
|
4596
|
+
isActive: true,
|
|
4597
|
+
updatedAt: admin7.firestore.FieldValue.serverTimestamp()
|
|
4598
|
+
});
|
|
4599
|
+
reactivationCount++;
|
|
4600
|
+
} else {
|
|
4601
|
+
console.log(
|
|
4602
|
+
`[ClinicAggregationService] Procedure ${procedureId} no longer exists. Skipping reactivation.`
|
|
4603
|
+
);
|
|
4604
|
+
}
|
|
4605
|
+
}
|
|
4606
|
+
if (reactivationCount > 0) {
|
|
4607
|
+
try {
|
|
4608
|
+
await batch.commit();
|
|
4609
|
+
console.log(
|
|
4610
|
+
`[ClinicAggregationService] Successfully reactivated ${reactivationCount} procedures.`
|
|
4611
|
+
);
|
|
4612
|
+
} catch (error) {
|
|
4613
|
+
console.error(
|
|
4614
|
+
`[ClinicAggregationService] Error committing batch reactivation of procedures:`,
|
|
4615
|
+
error
|
|
4616
|
+
);
|
|
4617
|
+
throw error;
|
|
4618
|
+
}
|
|
4619
|
+
} else {
|
|
4620
|
+
console.log(
|
|
4621
|
+
`[ClinicAggregationService] No procedures to reactivate (all may have been deleted).`
|
|
4622
|
+
);
|
|
4623
|
+
}
|
|
4624
|
+
}
|
|
4409
4625
|
/**
|
|
4410
4626
|
* Removes clinic from clinic group when a clinic is deleted
|
|
4411
4627
|
* @param clinicGroupId ID of the parent clinic group
|