@blackcode_sa/metaestetics-api 1.12.61 → 1.12.63
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 +4 -0
- package/dist/admin/index.d.ts +4 -0
- package/dist/backoffice/index.d.mts +9 -0
- package/dist/backoffice/index.d.ts +9 -0
- package/dist/backoffice/index.js +11 -0
- package/dist/backoffice/index.mjs +11 -0
- package/dist/index.d.mts +99 -1
- package/dist/index.d.ts +99 -1
- package/dist/index.js +534 -228
- package/dist/index.mjs +856 -550
- package/package.json +1 -1
- package/src/backoffice/services/technology.service.ts +13 -0
- package/src/backoffice/types/technology.types.ts +2 -0
- package/src/backoffice/validations/schemas.ts +1 -0
- package/src/services/appointment/appointment.service.ts +423 -0
- package/src/types/appointment/index.ts +28 -0
- package/src/types/patient/index.ts +2 -0
- package/src/validations/patient.schema.ts +1 -0
package/dist/index.mjs
CHANGED
|
@@ -73,6 +73,9 @@ var MediaType = /* @__PURE__ */ ((MediaType2) => {
|
|
|
73
73
|
})(MediaType || {});
|
|
74
74
|
var APPOINTMENTS_COLLECTION = "appointments";
|
|
75
75
|
|
|
76
|
+
// src/types/procedure/index.ts
|
|
77
|
+
var PROCEDURES_COLLECTION = "procedures";
|
|
78
|
+
|
|
76
79
|
// src/validations/appointment.schema.ts
|
|
77
80
|
import { z as z3 } from "zod";
|
|
78
81
|
|
|
@@ -979,7 +982,7 @@ var MediaService = class extends BaseService {
|
|
|
979
982
|
try {
|
|
980
983
|
const querySnapshot = await getDocs(finalQuery);
|
|
981
984
|
const mediaList = querySnapshot.docs.map(
|
|
982
|
-
(
|
|
985
|
+
(doc45) => doc45.data()
|
|
983
986
|
);
|
|
984
987
|
console.log(`[MediaService] Found ${mediaList.length} media items.`);
|
|
985
988
|
return mediaList;
|
|
@@ -1267,9 +1270,6 @@ var Gender = /* @__PURE__ */ ((Gender2) => {
|
|
|
1267
1270
|
return Gender2;
|
|
1268
1271
|
})(Gender || {});
|
|
1269
1272
|
|
|
1270
|
-
// src/types/procedure/index.ts
|
|
1271
|
-
var PROCEDURES_COLLECTION = "procedures";
|
|
1272
|
-
|
|
1273
1273
|
// src/backoffice/types/technology.types.ts
|
|
1274
1274
|
var TECHNOLOGIES_COLLECTION = "technologies";
|
|
1275
1275
|
|
|
@@ -1422,7 +1422,7 @@ async function searchAppointmentsUtil(db, params) {
|
|
|
1422
1422
|
}
|
|
1423
1423
|
const q = query2(collection2(db, APPOINTMENTS_COLLECTION), ...constraints);
|
|
1424
1424
|
const querySnapshot = await getDocs2(q);
|
|
1425
|
-
const appointments = querySnapshot.docs.map((
|
|
1425
|
+
const appointments = querySnapshot.docs.map((doc45) => doc45.data());
|
|
1426
1426
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
1427
1427
|
return { appointments, lastDoc };
|
|
1428
1428
|
} catch (error) {
|
|
@@ -2756,7 +2756,7 @@ var AppointmentService = class extends BaseService {
|
|
|
2756
2756
|
}
|
|
2757
2757
|
const q = query4(collection4(this.db, APPOINTMENTS_COLLECTION), ...constraints);
|
|
2758
2758
|
const querySnapshot = await getDocs4(q);
|
|
2759
|
-
const appointments = querySnapshot.docs.map((
|
|
2759
|
+
const appointments = querySnapshot.docs.map((doc45) => doc45.data());
|
|
2760
2760
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
2761
2761
|
console.log(
|
|
2762
2762
|
`[APPOINTMENT_SERVICE] Found ${appointments.length} upcoming appointments for patient ${patientId}`
|
|
@@ -2812,7 +2812,7 @@ var AppointmentService = class extends BaseService {
|
|
|
2812
2812
|
}
|
|
2813
2813
|
const q = query4(collection4(this.db, APPOINTMENTS_COLLECTION), ...constraints);
|
|
2814
2814
|
const querySnapshot = await getDocs4(q);
|
|
2815
|
-
const appointments = querySnapshot.docs.map((
|
|
2815
|
+
const appointments = querySnapshot.docs.map((doc45) => doc45.data());
|
|
2816
2816
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
2817
2817
|
console.log(
|
|
2818
2818
|
`[APPOINTMENT_SERVICE] Found ${appointments.length} past appointments for patient ${patientId}`
|
|
@@ -3534,6 +3534,301 @@ var AppointmentService = class extends BaseService {
|
|
|
3534
3534
|
throw error;
|
|
3535
3535
|
}
|
|
3536
3536
|
}
|
|
3537
|
+
/**
|
|
3538
|
+
* Gets all next steps recommendations for a patient from their past appointments.
|
|
3539
|
+
* Returns recommendations with context about which appointment, practitioner, and clinic suggested them.
|
|
3540
|
+
*
|
|
3541
|
+
* @param patientId ID of the patient
|
|
3542
|
+
* @param options Optional parameters for filtering
|
|
3543
|
+
* @returns Array of next steps recommendations with context
|
|
3544
|
+
*/
|
|
3545
|
+
async getPatientNextStepsRecommendations(patientId, options) {
|
|
3546
|
+
var _a, _b, _c;
|
|
3547
|
+
try {
|
|
3548
|
+
console.log(
|
|
3549
|
+
`[APPOINTMENT_SERVICE] Getting next steps recommendations for patient: ${patientId}`,
|
|
3550
|
+
options
|
|
3551
|
+
);
|
|
3552
|
+
const patientProfile = await this.patientService.getPatientProfile(patientId);
|
|
3553
|
+
const dismissedIds = new Set(
|
|
3554
|
+
(patientProfile == null ? void 0 : patientProfile.dismissedNextStepsRecommendations) || []
|
|
3555
|
+
);
|
|
3556
|
+
const pastAppointments = await this.getPastPatientAppointments(patientId, {
|
|
3557
|
+
showCanceled: false,
|
|
3558
|
+
showNoShow: false
|
|
3559
|
+
});
|
|
3560
|
+
const recommendations = [];
|
|
3561
|
+
for (const appointment of pastAppointments.appointments) {
|
|
3562
|
+
if ((options == null ? void 0 : options.clinicBranchId) && appointment.clinicBranchId !== options.clinicBranchId) {
|
|
3563
|
+
continue;
|
|
3564
|
+
}
|
|
3565
|
+
if ((options == null ? void 0 : options.practitionerId) && appointment.practitionerId !== options.practitionerId) {
|
|
3566
|
+
continue;
|
|
3567
|
+
}
|
|
3568
|
+
const recommendedProcedures = ((_a = appointment.metadata) == null ? void 0 : _a.recommendedProcedures) || [];
|
|
3569
|
+
for (let index = 0; index < recommendedProcedures.length; index++) {
|
|
3570
|
+
const recommendedProcedure = recommendedProcedures[index];
|
|
3571
|
+
const recommendationId = `${appointment.id}:${index}`;
|
|
3572
|
+
if (!(options == null ? void 0 : options.includeDismissed) && dismissedIds.has(recommendationId)) {
|
|
3573
|
+
continue;
|
|
3574
|
+
}
|
|
3575
|
+
const nextStepsRecommendation = {
|
|
3576
|
+
id: recommendationId,
|
|
3577
|
+
recommendedProcedure,
|
|
3578
|
+
appointmentId: appointment.id,
|
|
3579
|
+
appointmentDate: appointment.appointmentStartTime,
|
|
3580
|
+
practitionerId: appointment.practitionerId,
|
|
3581
|
+
practitionerName: ((_b = appointment.practitionerInfo) == null ? void 0 : _b.name) || "Unknown Practitioner",
|
|
3582
|
+
clinicBranchId: appointment.clinicBranchId,
|
|
3583
|
+
clinicName: ((_c = appointment.clinicInfo) == null ? void 0 : _c.name) || "Unknown Clinic",
|
|
3584
|
+
appointmentStatus: appointment.status,
|
|
3585
|
+
isDismissed: dismissedIds.has(recommendationId),
|
|
3586
|
+
dismissedAt: null
|
|
3587
|
+
// We don't track when it was dismissed, just that it was
|
|
3588
|
+
};
|
|
3589
|
+
recommendations.push(nextStepsRecommendation);
|
|
3590
|
+
}
|
|
3591
|
+
}
|
|
3592
|
+
recommendations.sort((a, b) => {
|
|
3593
|
+
const dateA = a.appointmentDate.toMillis();
|
|
3594
|
+
const dateB = b.appointmentDate.toMillis();
|
|
3595
|
+
return dateB - dateA;
|
|
3596
|
+
});
|
|
3597
|
+
const limitedRecommendations = (options == null ? void 0 : options.limit) ? recommendations.slice(0, options.limit) : recommendations;
|
|
3598
|
+
console.log(
|
|
3599
|
+
`[APPOINTMENT_SERVICE] Found ${limitedRecommendations.length} next steps recommendations for patient ${patientId}`
|
|
3600
|
+
);
|
|
3601
|
+
return limitedRecommendations;
|
|
3602
|
+
} catch (error) {
|
|
3603
|
+
console.error(
|
|
3604
|
+
`[APPOINTMENT_SERVICE] Error getting next steps recommendations for patient ${patientId}:`,
|
|
3605
|
+
error
|
|
3606
|
+
);
|
|
3607
|
+
throw error;
|
|
3608
|
+
}
|
|
3609
|
+
}
|
|
3610
|
+
/**
|
|
3611
|
+
* Dismisses a next steps recommendation for a patient.
|
|
3612
|
+
* This prevents the recommendation from showing up in the default view.
|
|
3613
|
+
*
|
|
3614
|
+
* @param patientId ID of the patient
|
|
3615
|
+
* @param recommendationId ID of the recommendation to dismiss (format: appointmentId:recommendationIndex)
|
|
3616
|
+
* @returns Updated patient profile
|
|
3617
|
+
*/
|
|
3618
|
+
async dismissNextStepsRecommendation(patientId, recommendationId) {
|
|
3619
|
+
try {
|
|
3620
|
+
console.log(
|
|
3621
|
+
`[APPOINTMENT_SERVICE] Dismissing recommendation ${recommendationId} for patient ${patientId}`
|
|
3622
|
+
);
|
|
3623
|
+
const patientProfile = await this.patientService.getPatientProfile(patientId);
|
|
3624
|
+
if (!patientProfile) {
|
|
3625
|
+
throw new Error(`Patient profile not found for patient ${patientId}`);
|
|
3626
|
+
}
|
|
3627
|
+
const dismissedRecommendations = patientProfile.dismissedNextStepsRecommendations || [];
|
|
3628
|
+
if (dismissedRecommendations.includes(recommendationId)) {
|
|
3629
|
+
console.log(
|
|
3630
|
+
`[APPOINTMENT_SERVICE] Recommendation ${recommendationId} already dismissed`
|
|
3631
|
+
);
|
|
3632
|
+
return;
|
|
3633
|
+
}
|
|
3634
|
+
const updatedDismissed = [...dismissedRecommendations, recommendationId];
|
|
3635
|
+
await this.patientService.updatePatientProfile(patientId, {
|
|
3636
|
+
dismissedNextStepsRecommendations: updatedDismissed
|
|
3637
|
+
});
|
|
3638
|
+
console.log(
|
|
3639
|
+
`[APPOINTMENT_SERVICE] Successfully dismissed recommendation ${recommendationId} for patient ${patientId}`
|
|
3640
|
+
);
|
|
3641
|
+
} catch (error) {
|
|
3642
|
+
console.error(
|
|
3643
|
+
`[APPOINTMENT_SERVICE] Error dismissing recommendation for patient ${patientId}:`,
|
|
3644
|
+
error
|
|
3645
|
+
);
|
|
3646
|
+
throw error;
|
|
3647
|
+
}
|
|
3648
|
+
}
|
|
3649
|
+
/**
|
|
3650
|
+
* Undismisses a next steps recommendation for a patient.
|
|
3651
|
+
* This makes the recommendation visible again in the default view.
|
|
3652
|
+
*
|
|
3653
|
+
* @param patientId ID of the patient
|
|
3654
|
+
* @param recommendationId ID of the recommendation to undismiss (format: appointmentId:recommendationIndex)
|
|
3655
|
+
* @returns Updated patient profile
|
|
3656
|
+
*/
|
|
3657
|
+
async undismissNextStepsRecommendation(patientId, recommendationId) {
|
|
3658
|
+
try {
|
|
3659
|
+
console.log(
|
|
3660
|
+
`[APPOINTMENT_SERVICE] Undismissing recommendation ${recommendationId} for patient ${patientId}`
|
|
3661
|
+
);
|
|
3662
|
+
const patientProfile = await this.patientService.getPatientProfile(patientId);
|
|
3663
|
+
if (!patientProfile) {
|
|
3664
|
+
throw new Error(`Patient profile not found for patient ${patientId}`);
|
|
3665
|
+
}
|
|
3666
|
+
const dismissedRecommendations = patientProfile.dismissedNextStepsRecommendations || [];
|
|
3667
|
+
if (!dismissedRecommendations.includes(recommendationId)) {
|
|
3668
|
+
console.log(
|
|
3669
|
+
`[APPOINTMENT_SERVICE] Recommendation ${recommendationId} is not dismissed`
|
|
3670
|
+
);
|
|
3671
|
+
return;
|
|
3672
|
+
}
|
|
3673
|
+
const updatedDismissed = dismissedRecommendations.filter(
|
|
3674
|
+
(id) => id !== recommendationId
|
|
3675
|
+
);
|
|
3676
|
+
await this.patientService.updatePatientProfile(patientId, {
|
|
3677
|
+
dismissedNextStepsRecommendations: updatedDismissed
|
|
3678
|
+
});
|
|
3679
|
+
console.log(
|
|
3680
|
+
`[APPOINTMENT_SERVICE] Successfully undismissed recommendation ${recommendationId} for patient ${patientId}`
|
|
3681
|
+
);
|
|
3682
|
+
} catch (error) {
|
|
3683
|
+
console.error(
|
|
3684
|
+
`[APPOINTMENT_SERVICE] Error undismissing recommendation for patient ${patientId}:`,
|
|
3685
|
+
error
|
|
3686
|
+
);
|
|
3687
|
+
throw error;
|
|
3688
|
+
}
|
|
3689
|
+
}
|
|
3690
|
+
/**
|
|
3691
|
+
* Gets next steps recommendations for a clinic.
|
|
3692
|
+
* Returns all recommendations from appointments at the specified clinic.
|
|
3693
|
+
* This is useful for clinic admins to see what treatments have been recommended to their patients.
|
|
3694
|
+
*
|
|
3695
|
+
* @param clinicBranchId ID of the clinic branch
|
|
3696
|
+
* @param options Optional parameters for filtering
|
|
3697
|
+
* @returns Array of next steps recommendations with context
|
|
3698
|
+
*/
|
|
3699
|
+
async getClinicNextStepsRecommendations(clinicBranchId, options) {
|
|
3700
|
+
var _a, _b, _c;
|
|
3701
|
+
try {
|
|
3702
|
+
console.log(
|
|
3703
|
+
`[APPOINTMENT_SERVICE] Getting next steps recommendations for clinic: ${clinicBranchId}`,
|
|
3704
|
+
options
|
|
3705
|
+
);
|
|
3706
|
+
const searchParams = {
|
|
3707
|
+
clinicBranchId,
|
|
3708
|
+
patientId: options == null ? void 0 : options.patientId,
|
|
3709
|
+
practitionerId: options == null ? void 0 : options.practitionerId,
|
|
3710
|
+
status: "completed" /* COMPLETED */
|
|
3711
|
+
};
|
|
3712
|
+
const { appointments } = await this.searchAppointments(searchParams);
|
|
3713
|
+
const recommendations = [];
|
|
3714
|
+
for (const appointment of appointments) {
|
|
3715
|
+
const recommendedProcedures = ((_a = appointment.metadata) == null ? void 0 : _a.recommendedProcedures) || [];
|
|
3716
|
+
for (let index = 0; index < recommendedProcedures.length; index++) {
|
|
3717
|
+
const recommendedProcedure = recommendedProcedures[index];
|
|
3718
|
+
const recommendationId = `${appointment.id}:${index}`;
|
|
3719
|
+
const nextStepsRecommendation = {
|
|
3720
|
+
id: recommendationId,
|
|
3721
|
+
recommendedProcedure,
|
|
3722
|
+
appointmentId: appointment.id,
|
|
3723
|
+
appointmentDate: appointment.appointmentStartTime,
|
|
3724
|
+
practitionerId: appointment.practitionerId,
|
|
3725
|
+
practitionerName: ((_b = appointment.practitionerInfo) == null ? void 0 : _b.name) || "Unknown Practitioner",
|
|
3726
|
+
clinicBranchId: appointment.clinicBranchId,
|
|
3727
|
+
clinicName: ((_c = appointment.clinicInfo) == null ? void 0 : _c.name) || "Unknown Clinic",
|
|
3728
|
+
appointmentStatus: appointment.status,
|
|
3729
|
+
isDismissed: false,
|
|
3730
|
+
// Clinic view doesn't track dismissals
|
|
3731
|
+
dismissedAt: null
|
|
3732
|
+
};
|
|
3733
|
+
recommendations.push(nextStepsRecommendation);
|
|
3734
|
+
}
|
|
3735
|
+
}
|
|
3736
|
+
recommendations.sort((a, b) => {
|
|
3737
|
+
const dateA = a.appointmentDate.toMillis();
|
|
3738
|
+
const dateB = b.appointmentDate.toMillis();
|
|
3739
|
+
return dateB - dateA;
|
|
3740
|
+
});
|
|
3741
|
+
const limitedRecommendations = (options == null ? void 0 : options.limit) ? recommendations.slice(0, options.limit) : recommendations;
|
|
3742
|
+
console.log(
|
|
3743
|
+
`[APPOINTMENT_SERVICE] Found ${limitedRecommendations.length} next steps recommendations for clinic ${clinicBranchId}`
|
|
3744
|
+
);
|
|
3745
|
+
return limitedRecommendations;
|
|
3746
|
+
} catch (error) {
|
|
3747
|
+
console.error(
|
|
3748
|
+
`[APPOINTMENT_SERVICE] Error getting next steps recommendations for clinic ${clinicBranchId}:`,
|
|
3749
|
+
error
|
|
3750
|
+
);
|
|
3751
|
+
throw error;
|
|
3752
|
+
}
|
|
3753
|
+
}
|
|
3754
|
+
/**
|
|
3755
|
+
* Gets next steps recommendations from a specific appointment.
|
|
3756
|
+
* This is useful when viewing an appointment detail page in the clinic app
|
|
3757
|
+
* to see what procedures were recommended during that appointment.
|
|
3758
|
+
*
|
|
3759
|
+
* @param appointmentId ID of the appointment
|
|
3760
|
+
* @param options Optional parameters for filtering
|
|
3761
|
+
* @returns Array of next steps recommendations from that appointment
|
|
3762
|
+
*/
|
|
3763
|
+
async getAppointmentNextStepsRecommendations(appointmentId, options) {
|
|
3764
|
+
var _a, _b, _c;
|
|
3765
|
+
try {
|
|
3766
|
+
console.log(
|
|
3767
|
+
`[APPOINTMENT_SERVICE] Getting next steps recommendations for appointment: ${appointmentId}`,
|
|
3768
|
+
options
|
|
3769
|
+
);
|
|
3770
|
+
const appointment = await this.getAppointmentById(appointmentId);
|
|
3771
|
+
if (!appointment) {
|
|
3772
|
+
throw new Error(`Appointment with ID ${appointmentId} not found`);
|
|
3773
|
+
}
|
|
3774
|
+
const recommendedProcedures = ((_a = appointment.metadata) == null ? void 0 : _a.recommendedProcedures) || [];
|
|
3775
|
+
const recommendations = [];
|
|
3776
|
+
let availableProcedureIds = null;
|
|
3777
|
+
if (options == null ? void 0 : options.clinicBranchId) {
|
|
3778
|
+
const proceduresQuery = query4(
|
|
3779
|
+
collection4(this.db, PROCEDURES_COLLECTION),
|
|
3780
|
+
where4("clinicBranchId", "==", options.clinicBranchId),
|
|
3781
|
+
where4("isActive", "==", true)
|
|
3782
|
+
);
|
|
3783
|
+
const proceduresSnapshot = await getDocs4(proceduresQuery);
|
|
3784
|
+
availableProcedureIds = new Set(
|
|
3785
|
+
proceduresSnapshot.docs.map((doc45) => doc45.id)
|
|
3786
|
+
);
|
|
3787
|
+
console.log(
|
|
3788
|
+
`[APPOINTMENT_SERVICE] Found ${availableProcedureIds.size} procedures available at clinic ${options.clinicBranchId}`
|
|
3789
|
+
);
|
|
3790
|
+
}
|
|
3791
|
+
for (let index = 0; index < recommendedProcedures.length; index++) {
|
|
3792
|
+
const recommendedProcedure = recommendedProcedures[index];
|
|
3793
|
+
const procedureId = recommendedProcedure.procedure.procedureId;
|
|
3794
|
+
if ((options == null ? void 0 : options.clinicBranchId) && availableProcedureIds) {
|
|
3795
|
+
if (!availableProcedureIds.has(procedureId)) {
|
|
3796
|
+
console.log(
|
|
3797
|
+
`[APPOINTMENT_SERVICE] Skipping recommendation for procedure ${procedureId} - not available at clinic ${options.clinicBranchId}`
|
|
3798
|
+
);
|
|
3799
|
+
continue;
|
|
3800
|
+
}
|
|
3801
|
+
}
|
|
3802
|
+
const recommendationId = `${appointment.id}:${index}`;
|
|
3803
|
+
const nextStepsRecommendation = {
|
|
3804
|
+
id: recommendationId,
|
|
3805
|
+
recommendedProcedure,
|
|
3806
|
+
appointmentId: appointment.id,
|
|
3807
|
+
appointmentDate: appointment.appointmentStartTime,
|
|
3808
|
+
practitionerId: appointment.practitionerId,
|
|
3809
|
+
practitionerName: ((_b = appointment.practitionerInfo) == null ? void 0 : _b.name) || "Unknown Practitioner",
|
|
3810
|
+
clinicBranchId: appointment.clinicBranchId,
|
|
3811
|
+
clinicName: ((_c = appointment.clinicInfo) == null ? void 0 : _c.name) || "Unknown Clinic",
|
|
3812
|
+
appointmentStatus: appointment.status,
|
|
3813
|
+
isDismissed: false,
|
|
3814
|
+
// Clinic view doesn't track dismissals
|
|
3815
|
+
dismissedAt: null
|
|
3816
|
+
};
|
|
3817
|
+
recommendations.push(nextStepsRecommendation);
|
|
3818
|
+
}
|
|
3819
|
+
console.log(
|
|
3820
|
+
`[APPOINTMENT_SERVICE] Found ${recommendations.length} next steps recommendations for appointment ${appointmentId}`,
|
|
3821
|
+
(options == null ? void 0 : options.clinicBranchId) ? `(filtered to procedures available at clinic ${options.clinicBranchId})` : ""
|
|
3822
|
+
);
|
|
3823
|
+
return recommendations;
|
|
3824
|
+
} catch (error) {
|
|
3825
|
+
console.error(
|
|
3826
|
+
`[APPOINTMENT_SERVICE] Error getting next steps recommendations for appointment ${appointmentId}:`,
|
|
3827
|
+
error
|
|
3828
|
+
);
|
|
3829
|
+
throw error;
|
|
3830
|
+
}
|
|
3831
|
+
}
|
|
3537
3832
|
};
|
|
3538
3833
|
|
|
3539
3834
|
// src/services/auth/auth.service.ts
|
|
@@ -3929,8 +4224,8 @@ var AUTH_ERRORS = {
|
|
|
3929
4224
|
// src/services/user/user.service.ts
|
|
3930
4225
|
import {
|
|
3931
4226
|
collection as collection12,
|
|
3932
|
-
doc as
|
|
3933
|
-
getDoc as
|
|
4227
|
+
doc as doc19,
|
|
4228
|
+
getDoc as getDoc21,
|
|
3934
4229
|
getDocs as getDocs12,
|
|
3935
4230
|
query as query12,
|
|
3936
4231
|
where as where12,
|
|
@@ -4038,8 +4333,8 @@ import { z as z18 } from "zod";
|
|
|
4038
4333
|
|
|
4039
4334
|
// src/services/patient/patient.service.ts
|
|
4040
4335
|
import {
|
|
4041
|
-
doc as
|
|
4042
|
-
getDoc as
|
|
4336
|
+
doc as doc17,
|
|
4337
|
+
getDoc as getDoc19,
|
|
4043
4338
|
writeBatch,
|
|
4044
4339
|
updateDoc as updateDoc15,
|
|
4045
4340
|
serverTimestamp as serverTimestamp16
|
|
@@ -4054,8 +4349,8 @@ import {
|
|
|
4054
4349
|
getDocs as getDocs5,
|
|
4055
4350
|
limit as limit4,
|
|
4056
4351
|
startAfter as startAfter3,
|
|
4057
|
-
doc as
|
|
4058
|
-
getDoc as
|
|
4352
|
+
doc as doc9,
|
|
4353
|
+
getDoc as getDoc8
|
|
4059
4354
|
} from "firebase/firestore";
|
|
4060
4355
|
var getPatientsByClinicUtil = async (db, clinicId, options) => {
|
|
4061
4356
|
try {
|
|
@@ -4072,8 +4367,8 @@ var getPatientsByClinicUtil = async (db, clinicId, options) => {
|
|
|
4072
4367
|
q = query5(q, limit4(options.limit));
|
|
4073
4368
|
}
|
|
4074
4369
|
if (options == null ? void 0 : options.startAfter) {
|
|
4075
|
-
const startAfterDoc = await
|
|
4076
|
-
|
|
4370
|
+
const startAfterDoc = await getDoc8(
|
|
4371
|
+
doc9(db, PATIENTS_COLLECTION, options.startAfter)
|
|
4077
4372
|
);
|
|
4078
4373
|
if (startAfterDoc.exists()) {
|
|
4079
4374
|
q = query5(q, startAfter3(startAfterDoc));
|
|
@@ -4081,8 +4376,8 @@ var getPatientsByClinicUtil = async (db, clinicId, options) => {
|
|
|
4081
4376
|
}
|
|
4082
4377
|
const patientsSnapshot = await getDocs5(q);
|
|
4083
4378
|
const patients = [];
|
|
4084
|
-
patientsSnapshot.forEach((
|
|
4085
|
-
patients.push(
|
|
4379
|
+
patientsSnapshot.forEach((doc45) => {
|
|
4380
|
+
patients.push(doc45.data());
|
|
4086
4381
|
});
|
|
4087
4382
|
console.log(
|
|
4088
4383
|
`[getPatientsByClinicUtil] Found ${patients.length} patients for clinic ID: ${clinicId}`
|
|
@@ -4101,16 +4396,16 @@ var getPatientsByClinicUtil = async (db, clinicId, options) => {
|
|
|
4101
4396
|
|
|
4102
4397
|
// src/services/patient/utils/docs.utils.ts
|
|
4103
4398
|
import {
|
|
4104
|
-
doc as
|
|
4399
|
+
doc as doc12,
|
|
4105
4400
|
collection as collection8,
|
|
4106
4401
|
query as query8,
|
|
4107
4402
|
where as where8,
|
|
4108
4403
|
getDocs as getDocs8,
|
|
4109
|
-
getDoc as
|
|
4404
|
+
getDoc as getDoc12
|
|
4110
4405
|
} from "firebase/firestore";
|
|
4111
4406
|
|
|
4112
4407
|
// src/services/patient/utils/sensitive.utils.ts
|
|
4113
|
-
import { getDoc as
|
|
4408
|
+
import { getDoc as getDoc11, updateDoc as updateDoc8, setDoc as setDoc4, serverTimestamp as serverTimestamp9 } from "firebase/firestore";
|
|
4114
4409
|
|
|
4115
4410
|
// src/validations/patient.schema.ts
|
|
4116
4411
|
import { z as z7 } from "zod";
|
|
@@ -4332,6 +4627,7 @@ var patientProfileSchema = z7.object({
|
|
|
4332
4627
|
clinics: z7.array(patientClinicSchema),
|
|
4333
4628
|
doctorIds: z7.array(z7.string()),
|
|
4334
4629
|
clinicIds: z7.array(z7.string()),
|
|
4630
|
+
dismissedNextStepsRecommendations: z7.array(z7.string()).optional(),
|
|
4335
4631
|
createdAt: z7.instanceof(Timestamp5),
|
|
4336
4632
|
updatedAt: z7.instanceof(Timestamp5)
|
|
4337
4633
|
});
|
|
@@ -4412,8 +4708,8 @@ import {
|
|
|
4412
4708
|
getDocs as getDocs6,
|
|
4413
4709
|
limit as limit5,
|
|
4414
4710
|
startAfter as startAfter4,
|
|
4415
|
-
doc as
|
|
4416
|
-
getDoc as
|
|
4711
|
+
doc as doc10,
|
|
4712
|
+
getDoc as getDoc9
|
|
4417
4713
|
} from "firebase/firestore";
|
|
4418
4714
|
var getPatientsByPractitionerUtil = async (db, practitionerId, options) => {
|
|
4419
4715
|
try {
|
|
@@ -4430,8 +4726,8 @@ var getPatientsByPractitionerUtil = async (db, practitionerId, options) => {
|
|
|
4430
4726
|
q = query6(q, limit5(options.limit));
|
|
4431
4727
|
}
|
|
4432
4728
|
if (options == null ? void 0 : options.startAfter) {
|
|
4433
|
-
const startAfterDoc = await
|
|
4434
|
-
|
|
4729
|
+
const startAfterDoc = await getDoc9(
|
|
4730
|
+
doc10(db, PATIENTS_COLLECTION, options.startAfter)
|
|
4435
4731
|
);
|
|
4436
4732
|
if (startAfterDoc.exists()) {
|
|
4437
4733
|
q = query6(q, startAfter4(startAfterDoc));
|
|
@@ -4439,8 +4735,8 @@ var getPatientsByPractitionerUtil = async (db, practitionerId, options) => {
|
|
|
4439
4735
|
}
|
|
4440
4736
|
const patientsSnapshot = await getDocs6(q);
|
|
4441
4737
|
const patients = [];
|
|
4442
|
-
patientsSnapshot.forEach((
|
|
4443
|
-
patients.push(
|
|
4738
|
+
patientsSnapshot.forEach((doc45) => {
|
|
4739
|
+
patients.push(doc45.data());
|
|
4444
4740
|
});
|
|
4445
4741
|
console.log(
|
|
4446
4742
|
`[getPatientsByPractitionerUtil] Found ${patients.length} patients for practitioner ID: ${practitionerId}`
|
|
@@ -4470,7 +4766,7 @@ var getPatientsByPractitionerWithDetailsUtil = async (db, practitionerId, option
|
|
|
4470
4766
|
const patientProfilesWithDetails = await Promise.all(
|
|
4471
4767
|
patientProfiles.map(async (profile) => {
|
|
4472
4768
|
try {
|
|
4473
|
-
const sensitiveInfoDoc = await
|
|
4769
|
+
const sensitiveInfoDoc = await getDoc9(
|
|
4474
4770
|
getSensitiveInfoDocRef(db, profile.id)
|
|
4475
4771
|
);
|
|
4476
4772
|
const sensitiveInfo = sensitiveInfoDoc.exists() ? sensitiveInfoDoc.data() : void 0;
|
|
@@ -4539,8 +4835,8 @@ var getPractitionerProfileByUserRef = async (db, userRef) => {
|
|
|
4539
4835
|
// src/services/clinic/utils/admin.utils.ts
|
|
4540
4836
|
import {
|
|
4541
4837
|
collection as collection7,
|
|
4542
|
-
doc as
|
|
4543
|
-
getDoc as
|
|
4838
|
+
doc as doc11,
|
|
4839
|
+
getDoc as getDoc10,
|
|
4544
4840
|
getDocs as getDocs7,
|
|
4545
4841
|
query as query7,
|
|
4546
4842
|
where as where7,
|
|
@@ -5157,7 +5453,7 @@ async function createClinicAdmin(db, data, clinicGroupService) {
|
|
|
5157
5453
|
}
|
|
5158
5454
|
console.log("[CLINIC_ADMIN] Preparing admin data object");
|
|
5159
5455
|
const adminData = {
|
|
5160
|
-
id:
|
|
5456
|
+
id: doc11(collection7(db, CLINIC_ADMINS_COLLECTION)).id,
|
|
5161
5457
|
// Generate a new ID for the admin document
|
|
5162
5458
|
userRef: validatedData.userRef,
|
|
5163
5459
|
clinicGroupId: clinicGroupId || "",
|
|
@@ -5192,7 +5488,7 @@ async function createClinicAdmin(db, data, clinicGroupService) {
|
|
|
5192
5488
|
adminId: adminData.id
|
|
5193
5489
|
});
|
|
5194
5490
|
try {
|
|
5195
|
-
await setDoc3(
|
|
5491
|
+
await setDoc3(doc11(db, CLINIC_ADMINS_COLLECTION, adminData.id), adminData);
|
|
5196
5492
|
console.log("[CLINIC_ADMIN] Admin saved successfully");
|
|
5197
5493
|
} catch (firestoreError) {
|
|
5198
5494
|
console.error(
|
|
@@ -5241,8 +5537,8 @@ async function checkClinicGroupExists(db, groupId, clinicGroupService) {
|
|
|
5241
5537
|
return !!group;
|
|
5242
5538
|
}
|
|
5243
5539
|
async function getClinicAdmin(db, adminId) {
|
|
5244
|
-
const docRef =
|
|
5245
|
-
const docSnap = await
|
|
5540
|
+
const docRef = doc11(db, CLINIC_ADMINS_COLLECTION, adminId);
|
|
5541
|
+
const docSnap = await getDoc10(docRef);
|
|
5246
5542
|
if (docSnap.exists()) {
|
|
5247
5543
|
return docSnap.data();
|
|
5248
5544
|
}
|
|
@@ -5265,7 +5561,7 @@ async function getClinicAdminsByGroup(db, clinicGroupId) {
|
|
|
5265
5561
|
where7("clinicGroupId", "==", clinicGroupId)
|
|
5266
5562
|
);
|
|
5267
5563
|
const querySnapshot = await getDocs7(q);
|
|
5268
|
-
return querySnapshot.docs.map((
|
|
5564
|
+
return querySnapshot.docs.map((doc45) => doc45.data());
|
|
5269
5565
|
}
|
|
5270
5566
|
async function updateClinicAdmin(db, adminId, data) {
|
|
5271
5567
|
const admin = await getClinicAdmin(db, adminId);
|
|
@@ -5276,7 +5572,7 @@ async function updateClinicAdmin(db, adminId, data) {
|
|
|
5276
5572
|
...data,
|
|
5277
5573
|
updatedAt: serverTimestamp8()
|
|
5278
5574
|
};
|
|
5279
|
-
await updateDoc7(
|
|
5575
|
+
await updateDoc7(doc11(db, CLINIC_ADMINS_COLLECTION, adminId), updatedData);
|
|
5280
5576
|
const updatedAdmin = await getClinicAdmin(db, adminId);
|
|
5281
5577
|
if (!updatedAdmin) {
|
|
5282
5578
|
throw new Error("Failed to retrieve updated admin");
|
|
@@ -5288,7 +5584,7 @@ async function deleteClinicAdmin(db, adminId) {
|
|
|
5288
5584
|
if (!admin) {
|
|
5289
5585
|
throw new Error("Clinic admin not found");
|
|
5290
5586
|
}
|
|
5291
|
-
await deleteDoc3(
|
|
5587
|
+
await deleteDoc3(doc11(db, CLINIC_ADMINS_COLLECTION, adminId));
|
|
5292
5588
|
}
|
|
5293
5589
|
async function addClinicToManaged(db, adminId, clinicId, requesterId, clinicService) {
|
|
5294
5590
|
const admin = await getClinicAdmin(db, adminId);
|
|
@@ -5402,7 +5698,7 @@ async function syncOwnerClinics(db, adminId, clinicService, clinicGroupService)
|
|
|
5402
5698
|
// src/services/patient/utils/sensitive.utils.ts
|
|
5403
5699
|
var checkSensitiveAccessUtil = async (db, patientId, requesterId, requesterRoles) => {
|
|
5404
5700
|
var _a;
|
|
5405
|
-
const patientDoc = await
|
|
5701
|
+
const patientDoc = await getDoc11(getPatientDocRef(db, patientId));
|
|
5406
5702
|
if (!patientDoc.exists()) {
|
|
5407
5703
|
throw new Error("Patient profile not found");
|
|
5408
5704
|
}
|
|
@@ -5461,7 +5757,7 @@ var createSensitiveInfoUtil = async (db, data, requesterId, requesterRoles, medi
|
|
|
5461
5757
|
try {
|
|
5462
5758
|
await checkSensitiveAccessUtil(db, data.patientId, requesterId, requesterRoles);
|
|
5463
5759
|
const validatedData = createPatientSensitiveInfoSchema.parse(data);
|
|
5464
|
-
const sensitiveDoc = await
|
|
5760
|
+
const sensitiveDoc = await getDoc11(getSensitiveInfoDocRef(db, data.patientId));
|
|
5465
5761
|
if (sensitiveDoc.exists()) {
|
|
5466
5762
|
throw new Error("Sensitive information already exists for this patient");
|
|
5467
5763
|
}
|
|
@@ -5482,7 +5778,7 @@ var createSensitiveInfoUtil = async (db, data, requesterId, requesterRoles, medi
|
|
|
5482
5778
|
updatedAt: serverTimestamp9()
|
|
5483
5779
|
};
|
|
5484
5780
|
await setDoc4(getSensitiveInfoDocRef(db, data.patientId), sensitiveInfoData);
|
|
5485
|
-
const createdDoc = await
|
|
5781
|
+
const createdDoc = await getDoc11(getSensitiveInfoDocRef(db, data.patientId));
|
|
5486
5782
|
if (!createdDoc.exists()) {
|
|
5487
5783
|
throw new Error("Failed to create sensitive information");
|
|
5488
5784
|
}
|
|
@@ -5497,7 +5793,7 @@ var createSensitiveInfoUtil = async (db, data, requesterId, requesterRoles, medi
|
|
|
5497
5793
|
var getSensitiveInfoUtil = async (db, patientId, requesterId, requesterRoles) => {
|
|
5498
5794
|
await checkSensitiveAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5499
5795
|
await initSensitiveInfoDocIfNotExists(db, patientId, requesterId);
|
|
5500
|
-
const sensitiveDoc = await
|
|
5796
|
+
const sensitiveDoc = await getDoc11(getSensitiveInfoDocRef(db, patientId));
|
|
5501
5797
|
return sensitiveDoc.exists() ? sensitiveDoc.data() : null;
|
|
5502
5798
|
};
|
|
5503
5799
|
var updateSensitiveInfoUtil = async (db, patientId, data, requesterId, requesterRoles, mediaService) => {
|
|
@@ -5519,14 +5815,14 @@ var updateSensitiveInfoUtil = async (db, patientId, data, requesterId, requester
|
|
|
5519
5815
|
updatedAt: serverTimestamp9()
|
|
5520
5816
|
};
|
|
5521
5817
|
await updateDoc8(getSensitiveInfoDocRef(db, patientId), updateData);
|
|
5522
|
-
const updatedDoc = await
|
|
5818
|
+
const updatedDoc = await getDoc11(getSensitiveInfoDocRef(db, patientId));
|
|
5523
5819
|
if (!updatedDoc.exists()) {
|
|
5524
5820
|
throw new Error("Failed to retrieve updated sensitive information");
|
|
5525
5821
|
}
|
|
5526
5822
|
return updatedDoc.data();
|
|
5527
5823
|
};
|
|
5528
5824
|
var claimPatientSensitiveInfoUtil = async (db, patientId, userId) => {
|
|
5529
|
-
const patientDoc = await
|
|
5825
|
+
const patientDoc = await getDoc11(getPatientDocRef(db, patientId));
|
|
5530
5826
|
if (!patientDoc.exists()) {
|
|
5531
5827
|
throw new Error("Patient profile not found");
|
|
5532
5828
|
}
|
|
@@ -5537,7 +5833,7 @@ var claimPatientSensitiveInfoUtil = async (db, patientId, userId) => {
|
|
|
5537
5833
|
if (patientData.userRef) {
|
|
5538
5834
|
throw new Error("Patient profile has already been claimed");
|
|
5539
5835
|
}
|
|
5540
|
-
const sensitiveDoc = await
|
|
5836
|
+
const sensitiveDoc = await getDoc11(getSensitiveInfoDocRef(db, patientId));
|
|
5541
5837
|
if (!sensitiveDoc.exists()) {
|
|
5542
5838
|
throw new Error("Patient sensitive information not found");
|
|
5543
5839
|
}
|
|
@@ -5549,7 +5845,7 @@ var claimPatientSensitiveInfoUtil = async (db, patientId, userId) => {
|
|
|
5549
5845
|
userRef: userId,
|
|
5550
5846
|
updatedAt: serverTimestamp9()
|
|
5551
5847
|
});
|
|
5552
|
-
const updatedDoc = await
|
|
5848
|
+
const updatedDoc = await getDoc11(getSensitiveInfoDocRef(db, patientId));
|
|
5553
5849
|
if (!updatedDoc.exists()) {
|
|
5554
5850
|
throw new Error("Failed to retrieve updated sensitive information");
|
|
5555
5851
|
}
|
|
@@ -5558,7 +5854,7 @@ var claimPatientSensitiveInfoUtil = async (db, patientId, userId) => {
|
|
|
5558
5854
|
|
|
5559
5855
|
// src/services/patient/utils/docs.utils.ts
|
|
5560
5856
|
var getPatientDocRef = (db, patientId) => {
|
|
5561
|
-
return
|
|
5857
|
+
return doc12(db, PATIENTS_COLLECTION, patientId);
|
|
5562
5858
|
};
|
|
5563
5859
|
var getPatientDocRefByUserRef = async (db, userRef) => {
|
|
5564
5860
|
const patientsRef = collection8(db, PATIENTS_COLLECTION);
|
|
@@ -5567,12 +5863,12 @@ var getPatientDocRefByUserRef = async (db, userRef) => {
|
|
|
5567
5863
|
if (querySnapshot.empty) {
|
|
5568
5864
|
throw new Error("Patient profile not found");
|
|
5569
5865
|
}
|
|
5570
|
-
return
|
|
5866
|
+
return doc12(db, PATIENTS_COLLECTION, querySnapshot.docs[0].id);
|
|
5571
5867
|
};
|
|
5572
5868
|
var getSensitiveInfoDocRef = (db, patientId) => {
|
|
5573
5869
|
const path = `${PATIENTS_COLLECTION}/${patientId}/${PATIENT_SENSITIVE_INFO_COLLECTION}/${patientId}`;
|
|
5574
5870
|
console.log(`[getSensitiveInfoDocRef] Creating reference with path: ${path}`);
|
|
5575
|
-
return
|
|
5871
|
+
return doc12(
|
|
5576
5872
|
db,
|
|
5577
5873
|
PATIENTS_COLLECTION,
|
|
5578
5874
|
patientId,
|
|
@@ -5583,7 +5879,7 @@ var getSensitiveInfoDocRef = (db, patientId) => {
|
|
|
5583
5879
|
var getLocationInfoDocRef = (db, patientId) => {
|
|
5584
5880
|
const path = `${PATIENTS_COLLECTION}/${patientId}/${PATIENT_LOCATION_INFO_COLLECTION}/${patientId}`;
|
|
5585
5881
|
console.log(`[getLocationInfoDocRef] Creating reference with path: ${path}`);
|
|
5586
|
-
return
|
|
5882
|
+
return doc12(
|
|
5587
5883
|
db,
|
|
5588
5884
|
PATIENTS_COLLECTION,
|
|
5589
5885
|
patientId,
|
|
@@ -5594,7 +5890,7 @@ var getLocationInfoDocRef = (db, patientId) => {
|
|
|
5594
5890
|
var getMedicalInfoDocRef = (db, patientId) => {
|
|
5595
5891
|
const path = `${PATIENTS_COLLECTION}/${patientId}/${PATIENT_MEDICAL_INFO_COLLECTION}/${patientId}`;
|
|
5596
5892
|
console.log(`[getMedicalInfoDocRef] Creating reference with path: ${path}`);
|
|
5597
|
-
return
|
|
5893
|
+
return doc12(
|
|
5598
5894
|
db,
|
|
5599
5895
|
PATIENTS_COLLECTION,
|
|
5600
5896
|
patientId,
|
|
@@ -5611,7 +5907,7 @@ var initSensitiveInfoDocIfNotExists = async (db, patientId, userRef) => {
|
|
|
5611
5907
|
console.log(
|
|
5612
5908
|
`[initSensitiveInfoDocIfNotExists] Got document reference: ${sensitiveInfoRef.path}`
|
|
5613
5909
|
);
|
|
5614
|
-
const sensitiveDoc = await
|
|
5910
|
+
const sensitiveDoc = await getDoc12(sensitiveInfoRef);
|
|
5615
5911
|
console.log(
|
|
5616
5912
|
`[initSensitiveInfoDocIfNotExists] Document exists: ${sensitiveDoc.exists()}`
|
|
5617
5913
|
);
|
|
@@ -5635,7 +5931,7 @@ var initSensitiveInfoDocIfNotExists = async (db, patientId, userRef) => {
|
|
|
5635
5931
|
)
|
|
5636
5932
|
);
|
|
5637
5933
|
await createSensitiveInfoUtil(db, defaultSensitiveInfo, userRef);
|
|
5638
|
-
const verifyDoc = await
|
|
5934
|
+
const verifyDoc = await getDoc12(sensitiveInfoRef);
|
|
5639
5935
|
console.log(
|
|
5640
5936
|
`[initSensitiveInfoDocIfNotExists] Verification - document exists: ${verifyDoc.exists()}`
|
|
5641
5937
|
);
|
|
@@ -5653,7 +5949,7 @@ var initSensitiveInfoDocIfNotExists = async (db, patientId, userRef) => {
|
|
|
5653
5949
|
|
|
5654
5950
|
// src/services/patient/utils/location.utils.ts
|
|
5655
5951
|
import {
|
|
5656
|
-
getDoc as
|
|
5952
|
+
getDoc as getDoc13,
|
|
5657
5953
|
updateDoc as updateDoc9,
|
|
5658
5954
|
setDoc as setDoc6,
|
|
5659
5955
|
serverTimestamp as serverTimestamp11
|
|
@@ -5691,7 +5987,7 @@ var createLocationInfoUtil = async (db, data, requesterId) => {
|
|
|
5691
5987
|
updatedAt: serverTimestamp11()
|
|
5692
5988
|
};
|
|
5693
5989
|
await setDoc6(getLocationInfoDocRef(db, data.patientId), locationData);
|
|
5694
|
-
const locationDoc = await
|
|
5990
|
+
const locationDoc = await getDoc13(getLocationInfoDocRef(db, data.patientId));
|
|
5695
5991
|
if (!locationDoc.exists()) {
|
|
5696
5992
|
throw new Error("Failed to create location information");
|
|
5697
5993
|
}
|
|
@@ -5707,7 +6003,7 @@ var getLocationInfoUtil = async (db, patientId, requesterId) => {
|
|
|
5707
6003
|
if (patientId !== requesterId) {
|
|
5708
6004
|
throw new Error("Unauthorized access to location information");
|
|
5709
6005
|
}
|
|
5710
|
-
const locationDoc = await
|
|
6006
|
+
const locationDoc = await getDoc13(getLocationInfoDocRef(db, patientId));
|
|
5711
6007
|
return locationDoc.exists() ? locationDoc.data() : null;
|
|
5712
6008
|
};
|
|
5713
6009
|
var updateLocationInfoUtil = async (db, patientId, data, requesterId) => {
|
|
@@ -5735,7 +6031,7 @@ var updateLocationInfoUtil = async (db, patientId, data, requesterId) => {
|
|
|
5735
6031
|
|
|
5736
6032
|
// src/services/patient/utils/medical-stuff.utils.ts
|
|
5737
6033
|
import {
|
|
5738
|
-
getDoc as
|
|
6034
|
+
getDoc as getDoc14,
|
|
5739
6035
|
updateDoc as updateDoc10,
|
|
5740
6036
|
arrayUnion as arrayUnion2,
|
|
5741
6037
|
arrayRemove as arrayRemove2,
|
|
@@ -5750,7 +6046,7 @@ var addDoctorUtil = async (db, patientId, doctorRef, assignedBy) => {
|
|
|
5750
6046
|
assignedBy,
|
|
5751
6047
|
isActive: true
|
|
5752
6048
|
};
|
|
5753
|
-
const patientDoc = await
|
|
6049
|
+
const patientDoc = await getDoc14(getPatientDocRef(db, patientId));
|
|
5754
6050
|
if (!patientDoc.exists()) throw new Error("Patient profile not found");
|
|
5755
6051
|
const patientData = patientDoc.data();
|
|
5756
6052
|
const existingDoctorIndex = (_a = patientData.doctors) == null ? void 0 : _a.findIndex(
|
|
@@ -5777,7 +6073,7 @@ var addDoctorUtil = async (db, patientId, doctorRef, assignedBy) => {
|
|
|
5777
6073
|
var removeDoctorUtil = async (db, patientId, doctorRef) => {
|
|
5778
6074
|
var _a;
|
|
5779
6075
|
const patientDocRef = getPatientDocRef(db, patientId);
|
|
5780
|
-
const patientDoc = await
|
|
6076
|
+
const patientDoc = await getDoc14(patientDocRef);
|
|
5781
6077
|
if (!patientDoc.exists()) throw new Error("Patient profile not found");
|
|
5782
6078
|
const patientData = patientDoc.data();
|
|
5783
6079
|
const updatedDoctors = ((_a = patientData.doctors) == null ? void 0 : _a.filter((doctor) => doctor.userRef !== doctorRef)) || [];
|
|
@@ -5797,7 +6093,7 @@ var addClinicUtil = async (db, patientId, clinicId, assignedBy) => {
|
|
|
5797
6093
|
assignedBy,
|
|
5798
6094
|
isActive: true
|
|
5799
6095
|
};
|
|
5800
|
-
const patientDoc = await
|
|
6096
|
+
const patientDoc = await getDoc14(getPatientDocRef(db, patientId));
|
|
5801
6097
|
if (!patientDoc.exists()) throw new Error("Patient profile not found");
|
|
5802
6098
|
const patientData = patientDoc.data();
|
|
5803
6099
|
const existingClinicIndex = (_a = patientData.clinics) == null ? void 0 : _a.findIndex(
|
|
@@ -5824,7 +6120,7 @@ var addClinicUtil = async (db, patientId, clinicId, assignedBy) => {
|
|
|
5824
6120
|
var removeClinicUtil = async (db, patientId, clinicId) => {
|
|
5825
6121
|
var _a;
|
|
5826
6122
|
const patientDocRef = getPatientDocRef(db, patientId);
|
|
5827
|
-
const patientDoc = await
|
|
6123
|
+
const patientDoc = await getDoc14(patientDocRef);
|
|
5828
6124
|
if (!patientDoc.exists()) throw new Error("Patient profile not found");
|
|
5829
6125
|
const patientData = patientDoc.data();
|
|
5830
6126
|
const updatedClinics = ((_a = patientData.clinics) == null ? void 0 : _a.filter((clinic) => clinic.clinicId !== clinicId)) || [];
|
|
@@ -5839,7 +6135,7 @@ var removeClinicUtil = async (db, patientId, clinicId) => {
|
|
|
5839
6135
|
|
|
5840
6136
|
// src/services/patient/utils/medical.utils.ts
|
|
5841
6137
|
import {
|
|
5842
|
-
getDoc as
|
|
6138
|
+
getDoc as getDoc15,
|
|
5843
6139
|
updateDoc as updateDoc11,
|
|
5844
6140
|
setDoc as setDoc7,
|
|
5845
6141
|
serverTimestamp as serverTimestamp13,
|
|
@@ -5847,7 +6143,7 @@ import {
|
|
|
5847
6143
|
} from "firebase/firestore";
|
|
5848
6144
|
var ensureMedicalInfoExists = async (db, patientId, requesterId) => {
|
|
5849
6145
|
const medicalInfoRef = getMedicalInfoDocRef(db, patientId);
|
|
5850
|
-
const medicalInfoDoc = await
|
|
6146
|
+
const medicalInfoDoc = await getDoc15(medicalInfoRef);
|
|
5851
6147
|
if (!medicalInfoDoc.exists()) {
|
|
5852
6148
|
const defaultData = {
|
|
5853
6149
|
...DEFAULT_MEDICAL_INFO,
|
|
@@ -5861,7 +6157,7 @@ var ensureMedicalInfoExists = async (db, patientId, requesterId) => {
|
|
|
5861
6157
|
};
|
|
5862
6158
|
var checkMedicalAccessUtil = async (db, patientId, requesterId, requesterRoles) => {
|
|
5863
6159
|
var _a;
|
|
5864
|
-
const patientDoc = await
|
|
6160
|
+
const patientDoc = await getDoc15(getPatientDocRef(db, patientId));
|
|
5865
6161
|
if (!patientDoc.exists()) {
|
|
5866
6162
|
throw new Error("Patient profile not found");
|
|
5867
6163
|
}
|
|
@@ -5911,10 +6207,10 @@ var createMedicalInfoUtil = async (db, patientId, data, requesterId, requesterRo
|
|
|
5911
6207
|
var getMedicalInfoUtil = async (db, patientId, requesterId, requesterRoles) => {
|
|
5912
6208
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5913
6209
|
const docRef = getMedicalInfoDocRef(db, patientId);
|
|
5914
|
-
const snapshot = await
|
|
6210
|
+
const snapshot = await getDoc15(docRef);
|
|
5915
6211
|
if (!snapshot.exists()) {
|
|
5916
6212
|
await ensureMedicalInfoExists(db, patientId, requesterId);
|
|
5917
|
-
const newSnapshot = await
|
|
6213
|
+
const newSnapshot = await getDoc15(docRef);
|
|
5918
6214
|
return patientMedicalInfoSchema.parse(newSnapshot.data());
|
|
5919
6215
|
}
|
|
5920
6216
|
return patientMedicalInfoSchema.parse(snapshot.data());
|
|
@@ -5943,7 +6239,7 @@ var updateAllergyUtil = async (db, patientId, data, requesterId, requesterRoles)
|
|
|
5943
6239
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5944
6240
|
const validatedData = updateAllergySchema.parse(data);
|
|
5945
6241
|
const { allergyIndex, ...updateData } = validatedData;
|
|
5946
|
-
const docSnapshot = await
|
|
6242
|
+
const docSnapshot = await getDoc15(getMedicalInfoDocRef(db, patientId));
|
|
5947
6243
|
if (!docSnapshot.exists()) throw new Error("Medical info not found");
|
|
5948
6244
|
const medicalInfo = patientMedicalInfoSchema.parse(docSnapshot.data());
|
|
5949
6245
|
if (allergyIndex >= medicalInfo.allergies.length) {
|
|
@@ -5962,9 +6258,9 @@ var updateAllergyUtil = async (db, patientId, data, requesterId, requesterRoles)
|
|
|
5962
6258
|
};
|
|
5963
6259
|
var removeAllergyUtil = async (db, patientId, allergyIndex, requesterId, requesterRoles) => {
|
|
5964
6260
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5965
|
-
const
|
|
5966
|
-
if (!
|
|
5967
|
-
const medicalInfo =
|
|
6261
|
+
const doc45 = await getDoc15(getMedicalInfoDocRef(db, patientId));
|
|
6262
|
+
if (!doc45.exists()) throw new Error("Medical info not found");
|
|
6263
|
+
const medicalInfo = doc45.data();
|
|
5968
6264
|
if (allergyIndex >= medicalInfo.allergies.length) {
|
|
5969
6265
|
throw new Error("Invalid allergy index");
|
|
5970
6266
|
}
|
|
@@ -5991,9 +6287,9 @@ var updateBlockingConditionUtil = async (db, patientId, data, requesterId, reque
|
|
|
5991
6287
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5992
6288
|
const validatedData = updateBlockingConditionSchema.parse(data);
|
|
5993
6289
|
const { conditionIndex, ...updateData } = validatedData;
|
|
5994
|
-
const
|
|
5995
|
-
if (!
|
|
5996
|
-
const medicalInfo =
|
|
6290
|
+
const doc45 = await getDoc15(getMedicalInfoDocRef(db, patientId));
|
|
6291
|
+
if (!doc45.exists()) throw new Error("Medical info not found");
|
|
6292
|
+
const medicalInfo = doc45.data();
|
|
5997
6293
|
if (conditionIndex >= medicalInfo.blockingConditions.length) {
|
|
5998
6294
|
throw new Error("Invalid blocking condition index");
|
|
5999
6295
|
}
|
|
@@ -6010,9 +6306,9 @@ var updateBlockingConditionUtil = async (db, patientId, data, requesterId, reque
|
|
|
6010
6306
|
};
|
|
6011
6307
|
var removeBlockingConditionUtil = async (db, patientId, conditionIndex, requesterId, requesterRoles) => {
|
|
6012
6308
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
6013
|
-
const
|
|
6014
|
-
if (!
|
|
6015
|
-
const medicalInfo =
|
|
6309
|
+
const doc45 = await getDoc15(getMedicalInfoDocRef(db, patientId));
|
|
6310
|
+
if (!doc45.exists()) throw new Error("Medical info not found");
|
|
6311
|
+
const medicalInfo = doc45.data();
|
|
6016
6312
|
if (conditionIndex >= medicalInfo.blockingConditions.length) {
|
|
6017
6313
|
throw new Error("Invalid blocking condition index");
|
|
6018
6314
|
}
|
|
@@ -6039,9 +6335,9 @@ var updateContraindicationUtil = async (db, patientId, data, requesterId, reques
|
|
|
6039
6335
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
6040
6336
|
const validatedData = updateContraindicationSchema.parse(data);
|
|
6041
6337
|
const { contraindicationIndex, ...updateData } = validatedData;
|
|
6042
|
-
const
|
|
6043
|
-
if (!
|
|
6044
|
-
const medicalInfo =
|
|
6338
|
+
const doc45 = await getDoc15(getMedicalInfoDocRef(db, patientId));
|
|
6339
|
+
if (!doc45.exists()) throw new Error("Medical info not found");
|
|
6340
|
+
const medicalInfo = doc45.data();
|
|
6045
6341
|
if (contraindicationIndex >= medicalInfo.contraindications.length) {
|
|
6046
6342
|
throw new Error("Invalid contraindication index");
|
|
6047
6343
|
}
|
|
@@ -6058,9 +6354,9 @@ var updateContraindicationUtil = async (db, patientId, data, requesterId, reques
|
|
|
6058
6354
|
};
|
|
6059
6355
|
var removeContraindicationUtil = async (db, patientId, contraindicationIndex, requesterId, requesterRoles) => {
|
|
6060
6356
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
6061
|
-
const
|
|
6062
|
-
if (!
|
|
6063
|
-
const medicalInfo =
|
|
6357
|
+
const doc45 = await getDoc15(getMedicalInfoDocRef(db, patientId));
|
|
6358
|
+
if (!doc45.exists()) throw new Error("Medical info not found");
|
|
6359
|
+
const medicalInfo = doc45.data();
|
|
6064
6360
|
if (contraindicationIndex >= medicalInfo.contraindications.length) {
|
|
6065
6361
|
throw new Error("Invalid contraindication index");
|
|
6066
6362
|
}
|
|
@@ -6087,9 +6383,9 @@ var updateMedicationUtil = async (db, patientId, data, requesterId, requesterRol
|
|
|
6087
6383
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
6088
6384
|
const validatedData = updateMedicationSchema.parse(data);
|
|
6089
6385
|
const { medicationIndex, ...updateData } = validatedData;
|
|
6090
|
-
const
|
|
6091
|
-
if (!
|
|
6092
|
-
const medicalInfo =
|
|
6386
|
+
const doc45 = await getDoc15(getMedicalInfoDocRef(db, patientId));
|
|
6387
|
+
if (!doc45.exists()) throw new Error("Medical info not found");
|
|
6388
|
+
const medicalInfo = doc45.data();
|
|
6093
6389
|
if (medicationIndex >= medicalInfo.currentMedications.length) {
|
|
6094
6390
|
throw new Error("Invalid medication index");
|
|
6095
6391
|
}
|
|
@@ -6106,9 +6402,9 @@ var updateMedicationUtil = async (db, patientId, data, requesterId, requesterRol
|
|
|
6106
6402
|
};
|
|
6107
6403
|
var removeMedicationUtil = async (db, patientId, medicationIndex, requesterId, requesterRoles) => {
|
|
6108
6404
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
6109
|
-
const
|
|
6110
|
-
if (!
|
|
6111
|
-
const medicalInfo =
|
|
6405
|
+
const doc45 = await getDoc15(getMedicalInfoDocRef(db, patientId));
|
|
6406
|
+
if (!doc45.exists()) throw new Error("Medical info not found");
|
|
6407
|
+
const medicalInfo = doc45.data();
|
|
6112
6408
|
if (medicationIndex >= medicalInfo.currentMedications.length) {
|
|
6113
6409
|
throw new Error("Invalid medication index");
|
|
6114
6410
|
}
|
|
@@ -6124,7 +6420,7 @@ var removeMedicationUtil = async (db, patientId, medicationIndex, requesterId, r
|
|
|
6124
6420
|
|
|
6125
6421
|
// src/services/patient/utils/profile.utils.ts
|
|
6126
6422
|
import {
|
|
6127
|
-
getDoc as
|
|
6423
|
+
getDoc as getDoc16,
|
|
6128
6424
|
setDoc as setDoc8,
|
|
6129
6425
|
updateDoc as updateDoc12,
|
|
6130
6426
|
arrayUnion as arrayUnion4,
|
|
@@ -6138,7 +6434,7 @@ import {
|
|
|
6138
6434
|
getDocs as getDocs9,
|
|
6139
6435
|
limit as limit6,
|
|
6140
6436
|
startAfter as startAfter5,
|
|
6141
|
-
doc as
|
|
6437
|
+
doc as doc14
|
|
6142
6438
|
} from "firebase/firestore";
|
|
6143
6439
|
import { z as z13 } from "zod";
|
|
6144
6440
|
var createPatientProfileUtil = async (db, data, generateId2) => {
|
|
@@ -6227,7 +6523,7 @@ var createPatientProfileUtil = async (db, data, generateId2) => {
|
|
|
6227
6523
|
}
|
|
6228
6524
|
}
|
|
6229
6525
|
console.log(`[createPatientProfileUtil] Verifying patient document exists`);
|
|
6230
|
-
const patientDoc = await
|
|
6526
|
+
const patientDoc = await getDoc16(getPatientDocRef(db, patientId));
|
|
6231
6527
|
if (!patientDoc.exists()) {
|
|
6232
6528
|
console.error(
|
|
6233
6529
|
`[createPatientProfileUtil] Patient document not found after creation`
|
|
@@ -6250,13 +6546,13 @@ var createPatientProfileUtil = async (db, data, generateId2) => {
|
|
|
6250
6546
|
}
|
|
6251
6547
|
};
|
|
6252
6548
|
var getPatientProfileUtil = async (db, patientId) => {
|
|
6253
|
-
const patientDoc = await
|
|
6549
|
+
const patientDoc = await getDoc16(getPatientDocRef(db, patientId));
|
|
6254
6550
|
return patientDoc.exists() ? patientDoc.data() : null;
|
|
6255
6551
|
};
|
|
6256
6552
|
var getPatientProfileByUserRefUtil = async (db, userRef) => {
|
|
6257
6553
|
try {
|
|
6258
6554
|
const docRef = await getPatientDocRefByUserRef(db, userRef);
|
|
6259
|
-
const patientDoc = await
|
|
6555
|
+
const patientDoc = await getDoc16(docRef);
|
|
6260
6556
|
return patientDoc.exists() ? patientDoc.data() : null;
|
|
6261
6557
|
} catch (error) {
|
|
6262
6558
|
return null;
|
|
@@ -6287,7 +6583,7 @@ var updatePatientProfileUtil = async (db, patientId, data) => {
|
|
|
6287
6583
|
updatedAt: serverTimestamp14()
|
|
6288
6584
|
};
|
|
6289
6585
|
await updateDoc12(getPatientDocRef(db, patientId), updateData);
|
|
6290
|
-
const updatedDoc = await
|
|
6586
|
+
const updatedDoc = await getDoc16(getPatientDocRef(db, patientId));
|
|
6291
6587
|
if (!updatedDoc.exists()) {
|
|
6292
6588
|
throw new Error("Patient profile not found after update");
|
|
6293
6589
|
}
|
|
@@ -6300,7 +6596,7 @@ var updatePatientProfileUtil = async (db, patientId, data) => {
|
|
|
6300
6596
|
var updatePatientProfileByUserRefUtil = async (db, userRef, data) => {
|
|
6301
6597
|
try {
|
|
6302
6598
|
const docRef = await getPatientDocRefByUserRef(db, userRef);
|
|
6303
|
-
const patientDoc = await
|
|
6599
|
+
const patientDoc = await getDoc16(docRef);
|
|
6304
6600
|
if (!patientDoc.exists()) {
|
|
6305
6601
|
throw new Error("Patient profile not found");
|
|
6306
6602
|
}
|
|
@@ -6411,7 +6707,7 @@ var searchPatientsUtil = async (db, params, requester) => {
|
|
|
6411
6707
|
const finalQuery = query9(patientsCollectionRef, ...constraints);
|
|
6412
6708
|
const querySnapshot = await getDocs9(finalQuery);
|
|
6413
6709
|
const patients = querySnapshot.docs.map(
|
|
6414
|
-
(
|
|
6710
|
+
(doc45) => doc45.data()
|
|
6415
6711
|
);
|
|
6416
6712
|
console.log(
|
|
6417
6713
|
`[searchPatientsUtil] Found ${patients.length} patients matching criteria.`
|
|
@@ -6434,8 +6730,8 @@ var getAllPatientsUtil = async (db, options) => {
|
|
|
6434
6730
|
q = query9(q, limit6(options.limit));
|
|
6435
6731
|
}
|
|
6436
6732
|
if (options == null ? void 0 : options.startAfter) {
|
|
6437
|
-
const startAfterDoc = await
|
|
6438
|
-
|
|
6733
|
+
const startAfterDoc = await getDoc16(
|
|
6734
|
+
doc14(db, PATIENTS_COLLECTION, options.startAfter)
|
|
6439
6735
|
);
|
|
6440
6736
|
if (startAfterDoc.exists()) {
|
|
6441
6737
|
q = query9(q, startAfter5(startAfterDoc));
|
|
@@ -6443,8 +6739,8 @@ var getAllPatientsUtil = async (db, options) => {
|
|
|
6443
6739
|
}
|
|
6444
6740
|
const patientsSnapshot = await getDocs9(q);
|
|
6445
6741
|
const patients = [];
|
|
6446
|
-
patientsSnapshot.forEach((
|
|
6447
|
-
patients.push(
|
|
6742
|
+
patientsSnapshot.forEach((doc45) => {
|
|
6743
|
+
patients.push(doc45.data());
|
|
6448
6744
|
});
|
|
6449
6745
|
console.log(`[getAllPatientsUtil] Found ${patients.length} patients`);
|
|
6450
6746
|
return patients;
|
|
@@ -6459,8 +6755,8 @@ var getAllPatientsUtil = async (db, options) => {
|
|
|
6459
6755
|
// src/services/patient/utils/token.utils.ts
|
|
6460
6756
|
import {
|
|
6461
6757
|
collection as collection10,
|
|
6462
|
-
doc as
|
|
6463
|
-
getDoc as
|
|
6758
|
+
doc as doc15,
|
|
6759
|
+
getDoc as getDoc17,
|
|
6464
6760
|
getDocs as getDocs10,
|
|
6465
6761
|
query as query10,
|
|
6466
6762
|
where as where10,
|
|
@@ -6500,7 +6796,7 @@ var createPatientTokenUtil = async (db, data, createdBy, generateId2) => {
|
|
|
6500
6796
|
var _a;
|
|
6501
6797
|
const validatedData = createPatientTokenSchema.parse(data);
|
|
6502
6798
|
const patientRef = getPatientDocRef(db, validatedData.patientId);
|
|
6503
|
-
const patientDoc = await
|
|
6799
|
+
const patientDoc = await getDoc17(patientRef);
|
|
6504
6800
|
if (!patientDoc.exists() || !((_a = patientDoc.data()) == null ? void 0 : _a.isManual)) {
|
|
6505
6801
|
throw new Error(
|
|
6506
6802
|
"Patient profile not found or is not a manually created profile."
|
|
@@ -6520,7 +6816,7 @@ var createPatientTokenUtil = async (db, data, createdBy, generateId2) => {
|
|
|
6520
6816
|
expiresAt: Timestamp11.fromDate(expiration)
|
|
6521
6817
|
};
|
|
6522
6818
|
patientTokenSchema.parse(token);
|
|
6523
|
-
const tokenRef =
|
|
6819
|
+
const tokenRef = doc15(
|
|
6524
6820
|
db,
|
|
6525
6821
|
PATIENTS_COLLECTION,
|
|
6526
6822
|
validatedData.patientId,
|
|
@@ -6553,7 +6849,7 @@ var validatePatientTokenUtil = async (db, tokenString) => {
|
|
|
6553
6849
|
return null;
|
|
6554
6850
|
};
|
|
6555
6851
|
var markPatientTokenAsUsedUtil = async (db, tokenId, patientId, userId) => {
|
|
6556
|
-
const tokenRef =
|
|
6852
|
+
const tokenRef = doc15(
|
|
6557
6853
|
db,
|
|
6558
6854
|
PATIENTS_COLLECTION,
|
|
6559
6855
|
patientId,
|
|
@@ -6577,7 +6873,7 @@ var getActiveInviteTokensByClinicUtil = async (db, clinicId) => {
|
|
|
6577
6873
|
if (querySnapshot.empty) {
|
|
6578
6874
|
return [];
|
|
6579
6875
|
}
|
|
6580
|
-
return querySnapshot.docs.map((
|
|
6876
|
+
return querySnapshot.docs.map((doc45) => doc45.data());
|
|
6581
6877
|
};
|
|
6582
6878
|
var getActiveInviteTokensByPatientUtil = async (db, patientId) => {
|
|
6583
6879
|
const tokensRef = collection10(
|
|
@@ -6595,11 +6891,11 @@ var getActiveInviteTokensByPatientUtil = async (db, patientId) => {
|
|
|
6595
6891
|
if (querySnapshot.empty) {
|
|
6596
6892
|
return [];
|
|
6597
6893
|
}
|
|
6598
|
-
return querySnapshot.docs.map((
|
|
6894
|
+
return querySnapshot.docs.map((doc45) => doc45.data());
|
|
6599
6895
|
};
|
|
6600
6896
|
|
|
6601
6897
|
// src/services/patient/utils/aesthetic-analysis.utils.ts
|
|
6602
|
-
import { getDoc as
|
|
6898
|
+
import { getDoc as getDoc18, updateDoc as updateDoc14, setDoc as setDoc10, serverTimestamp as serverTimestamp15, doc as doc16 } from "firebase/firestore";
|
|
6603
6899
|
|
|
6604
6900
|
// src/validations/patient/aesthetic-analysis.schema.ts
|
|
6605
6901
|
import { z as z15 } from "zod";
|
|
@@ -6653,11 +6949,11 @@ var aestheticAnalysisSchema = z15.object({
|
|
|
6653
6949
|
|
|
6654
6950
|
// src/services/patient/utils/aesthetic-analysis.utils.ts
|
|
6655
6951
|
var getAestheticAnalysisDocRef = (db, patientId) => {
|
|
6656
|
-
return
|
|
6952
|
+
return doc16(db, PATIENTS_COLLECTION, patientId, AESTHETIC_ANALYSIS_COLLECTION, patientId);
|
|
6657
6953
|
};
|
|
6658
6954
|
var checkAestheticAnalysisAccessUtil = async (db, patientId, requesterId, requesterRoles) => {
|
|
6659
6955
|
var _a;
|
|
6660
|
-
const patientDoc = await
|
|
6956
|
+
const patientDoc = await getDoc18(getPatientDocRef(db, patientId));
|
|
6661
6957
|
if (!patientDoc.exists()) {
|
|
6662
6958
|
throw new Error("Patient profile not found");
|
|
6663
6959
|
}
|
|
@@ -6712,7 +7008,7 @@ var determineStatus = (completionPercentage, selectedConcerns) => {
|
|
|
6712
7008
|
var getAestheticAnalysisUtil = async (db, patientId, requesterId, requesterRoles) => {
|
|
6713
7009
|
await checkAestheticAnalysisAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
6714
7010
|
const docRef = getAestheticAnalysisDocRef(db, patientId);
|
|
6715
|
-
const snapshot = await
|
|
7011
|
+
const snapshot = await getDoc18(docRef);
|
|
6716
7012
|
if (!snapshot.exists()) {
|
|
6717
7013
|
return null;
|
|
6718
7014
|
}
|
|
@@ -6726,7 +7022,7 @@ var createOrUpdateAestheticAnalysisUtil = async (db, patientId, data, requesterI
|
|
|
6726
7022
|
await checkAestheticAnalysisAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
6727
7023
|
const validatedData = isUpdate ? updateAestheticAnalysisSchema.parse(data) : createAestheticAnalysisSchema.parse(data);
|
|
6728
7024
|
const docRef = getAestheticAnalysisDocRef(db, patientId);
|
|
6729
|
-
const snapshot = await
|
|
7025
|
+
const snapshot = await getDoc18(docRef);
|
|
6730
7026
|
const requesterRole = requesterRoles.includes("practitioner" /* PRACTITIONER */) ? "PRACTITIONER" : "PATIENT";
|
|
6731
7027
|
const existingData = snapshot.exists() ? snapshot.data() : null;
|
|
6732
7028
|
const mergedData = {
|
|
@@ -7049,7 +7345,7 @@ var PatientService = class extends BaseService {
|
|
|
7049
7345
|
if (!this.auth.currentUser) {
|
|
7050
7346
|
throw new Error("No authenticated user");
|
|
7051
7347
|
}
|
|
7052
|
-
const userDoc = await
|
|
7348
|
+
const userDoc = await getDoc19(doc17(this.db, "users", this.auth.currentUser.uid));
|
|
7053
7349
|
if (!userDoc.exists()) {
|
|
7054
7350
|
throw new Error("User not found");
|
|
7055
7351
|
}
|
|
@@ -7476,8 +7772,8 @@ var ClinicAdminService = class extends BaseService {
|
|
|
7476
7772
|
// src/services/practitioner/practitioner.service.ts
|
|
7477
7773
|
import {
|
|
7478
7774
|
collection as collection11,
|
|
7479
|
-
doc as
|
|
7480
|
-
getDoc as
|
|
7775
|
+
doc as doc18,
|
|
7776
|
+
getDoc as getDoc20,
|
|
7481
7777
|
getDocs as getDocs11,
|
|
7482
7778
|
query as query11,
|
|
7483
7779
|
where as where11,
|
|
@@ -7773,7 +8069,7 @@ var PractitionerService = class extends BaseService {
|
|
|
7773
8069
|
createdAt: Timestamp14.now(),
|
|
7774
8070
|
updatedAt: Timestamp14.now()
|
|
7775
8071
|
});
|
|
7776
|
-
const practitionerRef =
|
|
8072
|
+
const practitionerRef = doc18(
|
|
7777
8073
|
this.db,
|
|
7778
8074
|
PRACTITIONERS_COLLECTION,
|
|
7779
8075
|
practitionerId
|
|
@@ -7881,7 +8177,7 @@ var PractitionerService = class extends BaseService {
|
|
|
7881
8177
|
updatedAt: Timestamp14.now()
|
|
7882
8178
|
});
|
|
7883
8179
|
await setDoc11(
|
|
7884
|
-
|
|
8180
|
+
doc18(this.db, PRACTITIONERS_COLLECTION, practitionerData.id),
|
|
7885
8181
|
practitionerData
|
|
7886
8182
|
);
|
|
7887
8183
|
const savedPractitioner = await this.getPractitioner(practitionerData.id);
|
|
@@ -7903,7 +8199,7 @@ var PractitionerService = class extends BaseService {
|
|
|
7903
8199
|
};
|
|
7904
8200
|
practitionerTokenSchema.parse(token);
|
|
7905
8201
|
const tokenPath = `${PRACTITIONERS_COLLECTION}/${practitionerId}/${REGISTER_TOKENS_COLLECTION}/${token.id}`;
|
|
7906
|
-
await setDoc11(
|
|
8202
|
+
await setDoc11(doc18(this.db, tokenPath), token);
|
|
7907
8203
|
return { practitioner: savedPractitioner, token };
|
|
7908
8204
|
} catch (error) {
|
|
7909
8205
|
if (error instanceof z17.ZodError) {
|
|
@@ -7956,7 +8252,7 @@ var PractitionerService = class extends BaseService {
|
|
|
7956
8252
|
};
|
|
7957
8253
|
practitionerTokenSchema.parse(token);
|
|
7958
8254
|
const tokenPath = `${PRACTITIONERS_COLLECTION}/${validatedData.practitionerId}/${REGISTER_TOKENS_COLLECTION}/${token.id}`;
|
|
7959
|
-
await setDoc11(
|
|
8255
|
+
await setDoc11(doc18(this.db, tokenPath), token);
|
|
7960
8256
|
return token;
|
|
7961
8257
|
} catch (error) {
|
|
7962
8258
|
if (error instanceof z17.ZodError) {
|
|
@@ -7981,7 +8277,7 @@ var PractitionerService = class extends BaseService {
|
|
|
7981
8277
|
where11("expiresAt", ">", Timestamp14.now())
|
|
7982
8278
|
);
|
|
7983
8279
|
const querySnapshot = await getDocs11(q);
|
|
7984
|
-
return querySnapshot.docs.map((
|
|
8280
|
+
return querySnapshot.docs.map((doc45) => doc45.data());
|
|
7985
8281
|
}
|
|
7986
8282
|
/**
|
|
7987
8283
|
* Gets a token by its string value and validates it
|
|
@@ -8044,7 +8340,7 @@ var PractitionerService = class extends BaseService {
|
|
|
8044
8340
|
* @param userId ID of the user using the token
|
|
8045
8341
|
*/
|
|
8046
8342
|
async markTokenAsUsed(tokenId, practitionerId, userId) {
|
|
8047
|
-
const tokenRef =
|
|
8343
|
+
const tokenRef = doc18(
|
|
8048
8344
|
this.db,
|
|
8049
8345
|
`${PRACTITIONERS_COLLECTION}/${practitionerId}/${REGISTER_TOKENS_COLLECTION}/${tokenId}`
|
|
8050
8346
|
);
|
|
@@ -8058,8 +8354,8 @@ var PractitionerService = class extends BaseService {
|
|
|
8058
8354
|
* Dohvata zdravstvenog radnika po ID-u
|
|
8059
8355
|
*/
|
|
8060
8356
|
async getPractitioner(practitionerId) {
|
|
8061
|
-
const practitionerDoc = await
|
|
8062
|
-
|
|
8357
|
+
const practitionerDoc = await getDoc20(
|
|
8358
|
+
doc18(this.db, PRACTITIONERS_COLLECTION, practitionerId)
|
|
8063
8359
|
);
|
|
8064
8360
|
if (!practitionerDoc.exists()) {
|
|
8065
8361
|
return null;
|
|
@@ -8091,7 +8387,7 @@ var PractitionerService = class extends BaseService {
|
|
|
8091
8387
|
where11("status", "==", "active" /* ACTIVE */)
|
|
8092
8388
|
);
|
|
8093
8389
|
const querySnapshot = await getDocs11(q);
|
|
8094
|
-
return querySnapshot.docs.map((
|
|
8390
|
+
return querySnapshot.docs.map((doc45) => doc45.data());
|
|
8095
8391
|
}
|
|
8096
8392
|
/**
|
|
8097
8393
|
* Dohvata sve zdravstvene radnike za određenu kliniku
|
|
@@ -8103,7 +8399,7 @@ var PractitionerService = class extends BaseService {
|
|
|
8103
8399
|
where11("isActive", "==", true)
|
|
8104
8400
|
);
|
|
8105
8401
|
const querySnapshot = await getDocs11(q);
|
|
8106
|
-
return querySnapshot.docs.map((
|
|
8402
|
+
return querySnapshot.docs.map((doc45) => doc45.data());
|
|
8107
8403
|
}
|
|
8108
8404
|
/**
|
|
8109
8405
|
* Dohvata sve draft zdravstvene radnike za određenu kliniku sa statusom DRAFT
|
|
@@ -8115,7 +8411,7 @@ var PractitionerService = class extends BaseService {
|
|
|
8115
8411
|
where11("status", "==", "draft" /* DRAFT */)
|
|
8116
8412
|
);
|
|
8117
8413
|
const querySnapshot = await getDocs11(q);
|
|
8118
|
-
return querySnapshot.docs.map((
|
|
8414
|
+
return querySnapshot.docs.map((doc45) => doc45.data());
|
|
8119
8415
|
}
|
|
8120
8416
|
/**
|
|
8121
8417
|
* Updates a practitioner
|
|
@@ -8123,12 +8419,12 @@ var PractitionerService = class extends BaseService {
|
|
|
8123
8419
|
async updatePractitioner(practitionerId, data) {
|
|
8124
8420
|
try {
|
|
8125
8421
|
const validData = data;
|
|
8126
|
-
const practitionerRef =
|
|
8422
|
+
const practitionerRef = doc18(
|
|
8127
8423
|
this.db,
|
|
8128
8424
|
PRACTITIONERS_COLLECTION,
|
|
8129
8425
|
practitionerId
|
|
8130
8426
|
);
|
|
8131
|
-
const practitionerDoc = await
|
|
8427
|
+
const practitionerDoc = await getDoc20(practitionerRef);
|
|
8132
8428
|
if (!practitionerDoc.exists()) {
|
|
8133
8429
|
throw new Error(`Practitioner ${practitionerId} not found`);
|
|
8134
8430
|
}
|
|
@@ -8169,12 +8465,12 @@ var PractitionerService = class extends BaseService {
|
|
|
8169
8465
|
async addClinic(practitionerId, clinicId) {
|
|
8170
8466
|
var _a;
|
|
8171
8467
|
try {
|
|
8172
|
-
const practitionerRef =
|
|
8468
|
+
const practitionerRef = doc18(
|
|
8173
8469
|
this.db,
|
|
8174
8470
|
PRACTITIONERS_COLLECTION,
|
|
8175
8471
|
practitionerId
|
|
8176
8472
|
);
|
|
8177
|
-
const practitionerDoc = await
|
|
8473
|
+
const practitionerDoc = await getDoc20(practitionerRef);
|
|
8178
8474
|
if (!practitionerDoc.exists()) {
|
|
8179
8475
|
throw new Error(`Practitioner ${practitionerId} not found`);
|
|
8180
8476
|
}
|
|
@@ -8202,12 +8498,12 @@ var PractitionerService = class extends BaseService {
|
|
|
8202
8498
|
*/
|
|
8203
8499
|
async removeClinic(practitionerId, clinicId) {
|
|
8204
8500
|
try {
|
|
8205
|
-
const practitionerRef =
|
|
8501
|
+
const practitionerRef = doc18(
|
|
8206
8502
|
this.db,
|
|
8207
8503
|
PRACTITIONERS_COLLECTION,
|
|
8208
8504
|
practitionerId
|
|
8209
8505
|
);
|
|
8210
|
-
const practitionerDoc = await
|
|
8506
|
+
const practitionerDoc = await getDoc20(practitionerRef);
|
|
8211
8507
|
if (!practitionerDoc.exists()) {
|
|
8212
8508
|
throw new Error(`Practitioner ${practitionerId} not found`);
|
|
8213
8509
|
}
|
|
@@ -8247,7 +8543,7 @@ var PractitionerService = class extends BaseService {
|
|
|
8247
8543
|
if (!practitioner) {
|
|
8248
8544
|
throw new Error("Practitioner not found");
|
|
8249
8545
|
}
|
|
8250
|
-
await deleteDoc4(
|
|
8546
|
+
await deleteDoc4(doc18(this.db, PRACTITIONERS_COLLECTION, practitionerId));
|
|
8251
8547
|
}
|
|
8252
8548
|
/**
|
|
8253
8549
|
* Validates a registration token and claims the associated draft practitioner profile
|
|
@@ -8332,7 +8628,7 @@ var PractitionerService = class extends BaseService {
|
|
|
8332
8628
|
);
|
|
8333
8629
|
const querySnapshot = await getDocs11(q);
|
|
8334
8630
|
const practitioners = querySnapshot.docs.map(
|
|
8335
|
-
(
|
|
8631
|
+
(doc45) => doc45.data()
|
|
8336
8632
|
);
|
|
8337
8633
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
8338
8634
|
return {
|
|
@@ -8417,7 +8713,7 @@ var PractitionerService = class extends BaseService {
|
|
|
8417
8713
|
);
|
|
8418
8714
|
const querySnapshot = await getDocs11(q);
|
|
8419
8715
|
const practitioners = querySnapshot.docs.map(
|
|
8420
|
-
(
|
|
8716
|
+
(doc45) => ({ ...doc45.data(), id: doc45.id })
|
|
8421
8717
|
);
|
|
8422
8718
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
8423
8719
|
console.log(
|
|
@@ -8481,7 +8777,7 @@ var PractitionerService = class extends BaseService {
|
|
|
8481
8777
|
);
|
|
8482
8778
|
const querySnapshot = await getDocs11(q);
|
|
8483
8779
|
let practitioners = querySnapshot.docs.map(
|
|
8484
|
-
(
|
|
8780
|
+
(doc45) => ({ ...doc45.data(), id: doc45.id })
|
|
8485
8781
|
);
|
|
8486
8782
|
if (filters.location && filters.radiusInKm && filters.radiusInKm > 0) {
|
|
8487
8783
|
const location = filters.location;
|
|
@@ -8526,7 +8822,7 @@ var PractitionerService = class extends BaseService {
|
|
|
8526
8822
|
);
|
|
8527
8823
|
const querySnapshot = await getDocs11(q);
|
|
8528
8824
|
let practitioners = querySnapshot.docs.map(
|
|
8529
|
-
(
|
|
8825
|
+
(doc45) => ({ ...doc45.data(), id: doc45.id })
|
|
8530
8826
|
);
|
|
8531
8827
|
practitioners = this.applyInMemoryFilters(practitioners, filters);
|
|
8532
8828
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
@@ -8556,7 +8852,7 @@ var PractitionerService = class extends BaseService {
|
|
|
8556
8852
|
);
|
|
8557
8853
|
const querySnapshot = await getDocs11(q);
|
|
8558
8854
|
let practitioners = querySnapshot.docs.map(
|
|
8559
|
-
(
|
|
8855
|
+
(doc45) => ({ ...doc45.data(), id: doc45.id })
|
|
8560
8856
|
);
|
|
8561
8857
|
practitioners = this.applyInMemoryFilters(practitioners, filters);
|
|
8562
8858
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
@@ -8943,12 +9239,12 @@ var UserService = class extends BaseService {
|
|
|
8943
9239
|
updatedAt: serverTimestamp18(),
|
|
8944
9240
|
lastLoginAt: serverTimestamp18()
|
|
8945
9241
|
};
|
|
8946
|
-
await setDoc12(
|
|
9242
|
+
await setDoc12(doc19(this.db, USERS_COLLECTION, userData.uid), userData);
|
|
8947
9243
|
if (options == null ? void 0 : options.skipProfileCreation) {
|
|
8948
9244
|
return this.getUserById(userData.uid);
|
|
8949
9245
|
}
|
|
8950
9246
|
const profiles = await this.createProfilesForRoles(userData.uid, roles, options);
|
|
8951
|
-
await updateDoc17(
|
|
9247
|
+
await updateDoc17(doc19(this.db, USERS_COLLECTION, userData.uid), profiles);
|
|
8952
9248
|
return this.getUserById(userData.uid);
|
|
8953
9249
|
}
|
|
8954
9250
|
/**
|
|
@@ -9081,7 +9377,7 @@ var UserService = class extends BaseService {
|
|
|
9081
9377
|
* Dohvata korisnika po ID-u
|
|
9082
9378
|
*/
|
|
9083
9379
|
async getUserById(uid) {
|
|
9084
|
-
const userDoc = await
|
|
9380
|
+
const userDoc = await getDoc21(doc19(this.db, USERS_COLLECTION, uid));
|
|
9085
9381
|
if (!userDoc.exists()) {
|
|
9086
9382
|
throw USER_ERRORS.NOT_FOUND;
|
|
9087
9383
|
}
|
|
@@ -9103,15 +9399,15 @@ var UserService = class extends BaseService {
|
|
|
9103
9399
|
const constraints = [where12("roles", "array-contains", role)];
|
|
9104
9400
|
const q = query12(collection12(this.db, USERS_COLLECTION), ...constraints);
|
|
9105
9401
|
const querySnapshot = await getDocs12(q);
|
|
9106
|
-
const users = querySnapshot.docs.map((
|
|
9402
|
+
const users = querySnapshot.docs.map((doc45) => doc45.data());
|
|
9107
9403
|
return users.map((userData) => userSchema.parse(userData));
|
|
9108
9404
|
}
|
|
9109
9405
|
/**
|
|
9110
9406
|
* Ažurira timestamp poslednjeg logovanja
|
|
9111
9407
|
*/
|
|
9112
9408
|
async updateUserLoginTimestamp(uid) {
|
|
9113
|
-
const userRef =
|
|
9114
|
-
const userDoc = await
|
|
9409
|
+
const userRef = doc19(this.db, USERS_COLLECTION, uid);
|
|
9410
|
+
const userDoc = await getDoc21(userRef);
|
|
9115
9411
|
if (!userDoc.exists()) {
|
|
9116
9412
|
throw AUTH_ERRORS.USER_NOT_FOUND;
|
|
9117
9413
|
}
|
|
@@ -9122,8 +9418,8 @@ var UserService = class extends BaseService {
|
|
|
9122
9418
|
return this.getUserById(uid);
|
|
9123
9419
|
}
|
|
9124
9420
|
async upgradeAnonymousUser(uid, email) {
|
|
9125
|
-
const userRef =
|
|
9126
|
-
const userDoc = await
|
|
9421
|
+
const userRef = doc19(this.db, USERS_COLLECTION, uid);
|
|
9422
|
+
const userDoc = await getDoc21(userRef);
|
|
9127
9423
|
if (!userDoc.exists()) {
|
|
9128
9424
|
throw USER_ERRORS.NOT_FOUND;
|
|
9129
9425
|
}
|
|
@@ -9135,8 +9431,8 @@ var UserService = class extends BaseService {
|
|
|
9135
9431
|
return this.getUserById(uid);
|
|
9136
9432
|
}
|
|
9137
9433
|
async updateUser(uid, updates) {
|
|
9138
|
-
const userRef =
|
|
9139
|
-
const userDoc = await
|
|
9434
|
+
const userRef = doc19(this.db, USERS_COLLECTION, uid);
|
|
9435
|
+
const userDoc = await getDoc21(userRef);
|
|
9140
9436
|
if (!userDoc.exists()) {
|
|
9141
9437
|
throw USER_ERRORS.NOT_FOUND;
|
|
9142
9438
|
}
|
|
@@ -9167,7 +9463,7 @@ var UserService = class extends BaseService {
|
|
|
9167
9463
|
const user = await this.getUserById(uid);
|
|
9168
9464
|
if (user.roles.includes(role)) return;
|
|
9169
9465
|
const profiles = await this.createProfilesForRoles(uid, [role], options);
|
|
9170
|
-
await updateDoc17(
|
|
9466
|
+
await updateDoc17(doc19(this.db, USERS_COLLECTION, uid), {
|
|
9171
9467
|
roles: [...user.roles, role],
|
|
9172
9468
|
...profiles,
|
|
9173
9469
|
updatedAt: serverTimestamp18()
|
|
@@ -9196,15 +9492,15 @@ var UserService = class extends BaseService {
|
|
|
9196
9492
|
}
|
|
9197
9493
|
break;
|
|
9198
9494
|
}
|
|
9199
|
-
await updateDoc17(
|
|
9495
|
+
await updateDoc17(doc19(this.db, USERS_COLLECTION, uid), {
|
|
9200
9496
|
roles: user.roles.filter((r) => r !== role),
|
|
9201
9497
|
updatedAt: serverTimestamp18()
|
|
9202
9498
|
});
|
|
9203
9499
|
}
|
|
9204
9500
|
// Delete operations
|
|
9205
9501
|
async deleteUser(uid) {
|
|
9206
|
-
const userRef =
|
|
9207
|
-
const userDoc = await
|
|
9502
|
+
const userRef = doc19(this.db, USERS_COLLECTION, uid);
|
|
9503
|
+
const userDoc = await getDoc21(userRef);
|
|
9208
9504
|
if (!userDoc.exists()) {
|
|
9209
9505
|
throw USER_ERRORS.NOT_FOUND;
|
|
9210
9506
|
}
|
|
@@ -9269,9 +9565,9 @@ var BillingTransactionsService = class extends BaseService {
|
|
|
9269
9565
|
const querySnapshot = await getDocs13(q);
|
|
9270
9566
|
const docs = querySnapshot.docs;
|
|
9271
9567
|
const hasMore = docs.length > queryLimit;
|
|
9272
|
-
const transactions = docs.slice(0, queryLimit).map((
|
|
9273
|
-
id:
|
|
9274
|
-
...
|
|
9568
|
+
const transactions = docs.slice(0, queryLimit).map((doc45) => ({
|
|
9569
|
+
id: doc45.id,
|
|
9570
|
+
...doc45.data()
|
|
9275
9571
|
}));
|
|
9276
9572
|
const lastDoc = transactions.length > 0 ? docs[transactions.length - 1] : null;
|
|
9277
9573
|
return {
|
|
@@ -9347,9 +9643,9 @@ var BillingTransactionsService = class extends BaseService {
|
|
|
9347
9643
|
const querySnapshot = await getDocs13(q);
|
|
9348
9644
|
const docs = querySnapshot.docs;
|
|
9349
9645
|
const hasMore = docs.length > queryLimit;
|
|
9350
|
-
const transactions = docs.slice(0, queryLimit).map((
|
|
9351
|
-
id:
|
|
9352
|
-
...
|
|
9646
|
+
const transactions = docs.slice(0, queryLimit).map((doc45) => ({
|
|
9647
|
+
id: doc45.id,
|
|
9648
|
+
...doc45.data()
|
|
9353
9649
|
}));
|
|
9354
9650
|
const lastDoc = transactions.length > 0 ? docs[transactions.length - 1] : null;
|
|
9355
9651
|
return {
|
|
@@ -9372,8 +9668,8 @@ var BillingTransactionsService = class extends BaseService {
|
|
|
9372
9668
|
// src/services/clinic/utils/clinic-group.utils.ts
|
|
9373
9669
|
import {
|
|
9374
9670
|
collection as collection14,
|
|
9375
|
-
doc as
|
|
9376
|
-
getDoc as
|
|
9671
|
+
doc as doc20,
|
|
9672
|
+
getDoc as getDoc22,
|
|
9377
9673
|
getDocs as getDocs14,
|
|
9378
9674
|
query as query14,
|
|
9379
9675
|
where as where14,
|
|
@@ -9505,7 +9801,7 @@ async function createClinicGroup(db, data, ownerId, isDefault = false, clinicAdm
|
|
|
9505
9801
|
}
|
|
9506
9802
|
const now = Timestamp16.now();
|
|
9507
9803
|
console.log("[CLINIC_GROUP] Preparing clinic group data object");
|
|
9508
|
-
const groupId =
|
|
9804
|
+
const groupId = doc20(collection14(db, CLINIC_GROUPS_COLLECTION)).id;
|
|
9509
9805
|
console.log("[CLINIC_GROUP] Logo value:", {
|
|
9510
9806
|
logoValue: validatedData.logo,
|
|
9511
9807
|
logoType: validatedData.logo === null ? "null" : typeof validatedData.logo
|
|
@@ -9555,7 +9851,7 @@ async function createClinicGroup(db, data, ownerId, isDefault = false, clinicAdm
|
|
|
9555
9851
|
groupId: groupData.id
|
|
9556
9852
|
});
|
|
9557
9853
|
try {
|
|
9558
|
-
await setDoc13(
|
|
9854
|
+
await setDoc13(doc20(db, CLINIC_GROUPS_COLLECTION, groupData.id), groupData);
|
|
9559
9855
|
console.log("[CLINIC_GROUP] Clinic group saved successfully");
|
|
9560
9856
|
} catch (firestoreError) {
|
|
9561
9857
|
console.error(
|
|
@@ -9601,8 +9897,8 @@ async function createClinicGroup(db, data, ownerId, isDefault = false, clinicAdm
|
|
|
9601
9897
|
}
|
|
9602
9898
|
}
|
|
9603
9899
|
async function getClinicGroup(db, groupId) {
|
|
9604
|
-
const docRef =
|
|
9605
|
-
const docSnap = await
|
|
9900
|
+
const docRef = doc20(db, CLINIC_GROUPS_COLLECTION, groupId);
|
|
9901
|
+
const docSnap = await getDoc22(docRef);
|
|
9606
9902
|
if (docSnap.exists()) {
|
|
9607
9903
|
return docSnap.data();
|
|
9608
9904
|
}
|
|
@@ -9614,7 +9910,7 @@ async function getAllActiveGroups(db) {
|
|
|
9614
9910
|
where14("isActive", "==", true)
|
|
9615
9911
|
);
|
|
9616
9912
|
const querySnapshot = await getDocs14(q);
|
|
9617
|
-
return querySnapshot.docs.map((
|
|
9913
|
+
return querySnapshot.docs.map((doc45) => doc45.data());
|
|
9618
9914
|
}
|
|
9619
9915
|
async function updateClinicGroup(db, groupId, data, app) {
|
|
9620
9916
|
console.log("[CLINIC_GROUP] Updating clinic group", { groupId });
|
|
@@ -9645,7 +9941,7 @@ async function updateClinicGroup(db, groupId, data, app) {
|
|
|
9645
9941
|
updatedAt: Timestamp16.now()
|
|
9646
9942
|
};
|
|
9647
9943
|
console.log("[CLINIC_GROUP] Updating clinic group in Firestore");
|
|
9648
|
-
await updateDoc18(
|
|
9944
|
+
await updateDoc18(doc20(db, CLINIC_GROUPS_COLLECTION, groupId), updatedData);
|
|
9649
9945
|
console.log("[CLINIC_GROUP] Clinic group updated successfully");
|
|
9650
9946
|
const updatedGroup = await getClinicGroup(db, groupId);
|
|
9651
9947
|
if (!updatedGroup) {
|
|
@@ -10027,8 +10323,8 @@ var ClinicGroupService = class extends BaseService {
|
|
|
10027
10323
|
// src/services/clinic/clinic.service.ts
|
|
10028
10324
|
import {
|
|
10029
10325
|
collection as collection18,
|
|
10030
|
-
doc as
|
|
10031
|
-
getDoc as
|
|
10326
|
+
doc as doc22,
|
|
10327
|
+
getDoc as getDoc24,
|
|
10032
10328
|
getDocs as getDocs18,
|
|
10033
10329
|
updateDoc as updateDoc20,
|
|
10034
10330
|
serverTimestamp as serverTimestamp20,
|
|
@@ -10045,8 +10341,8 @@ import { z as z21 } from "zod";
|
|
|
10045
10341
|
// src/services/clinic/utils/clinic.utils.ts
|
|
10046
10342
|
import {
|
|
10047
10343
|
collection as collection15,
|
|
10048
|
-
doc as
|
|
10049
|
-
getDoc as
|
|
10344
|
+
doc as doc21,
|
|
10345
|
+
getDoc as getDoc23,
|
|
10050
10346
|
getDocs as getDocs15,
|
|
10051
10347
|
query as query15,
|
|
10052
10348
|
where as where15,
|
|
@@ -10063,8 +10359,8 @@ import {
|
|
|
10063
10359
|
} from "geofire-common";
|
|
10064
10360
|
import { z as z20 } from "zod";
|
|
10065
10361
|
async function getClinic(db, clinicId) {
|
|
10066
|
-
const docRef =
|
|
10067
|
-
const docSnap = await
|
|
10362
|
+
const docRef = doc21(db, CLINICS_COLLECTION, clinicId);
|
|
10363
|
+
const docSnap = await getDoc23(docRef);
|
|
10068
10364
|
if (docSnap.exists()) {
|
|
10069
10365
|
return docSnap.data();
|
|
10070
10366
|
}
|
|
@@ -10077,7 +10373,7 @@ async function getClinicsByGroup(db, groupId) {
|
|
|
10077
10373
|
where15("isActive", "==", true)
|
|
10078
10374
|
);
|
|
10079
10375
|
const querySnapshot = await getDocs15(q);
|
|
10080
|
-
return querySnapshot.docs.map((
|
|
10376
|
+
return querySnapshot.docs.map((doc45) => doc45.data());
|
|
10081
10377
|
}
|
|
10082
10378
|
async function updateClinic(db, clinicId, data, adminId, clinicAdminService, app) {
|
|
10083
10379
|
console.log("[CLINIC] Starting clinic update", { clinicId, adminId });
|
|
@@ -10236,7 +10532,7 @@ async function updateClinic(db, clinicId, data, adminId, clinicAdminService, app
|
|
|
10236
10532
|
};
|
|
10237
10533
|
console.log("[CLINIC] Updating clinic in Firestore");
|
|
10238
10534
|
try {
|
|
10239
|
-
await updateDoc19(
|
|
10535
|
+
await updateDoc19(doc21(db, CLINICS_COLLECTION, clinicId), updatedData);
|
|
10240
10536
|
console.log("[CLINIC] Clinic updated successfully");
|
|
10241
10537
|
} catch (updateError) {
|
|
10242
10538
|
console.error("[CLINIC] Error updating clinic in Firestore:", updateError);
|
|
@@ -10271,7 +10567,7 @@ async function getClinicsByAdmin(db, adminId, options = {}, clinicAdminService,
|
|
|
10271
10567
|
}
|
|
10272
10568
|
const q = query15(collection15(db, CLINICS_COLLECTION), ...constraints);
|
|
10273
10569
|
const querySnapshot = await getDocs15(q);
|
|
10274
|
-
return querySnapshot.docs.map((
|
|
10570
|
+
return querySnapshot.docs.map((doc45) => doc45.data());
|
|
10275
10571
|
}
|
|
10276
10572
|
async function getActiveClinicsByAdmin(db, adminId, clinicAdminService, clinicGroupService) {
|
|
10277
10573
|
return getClinicsByAdmin(
|
|
@@ -10284,8 +10580,8 @@ async function getActiveClinicsByAdmin(db, adminId, clinicAdminService, clinicGr
|
|
|
10284
10580
|
}
|
|
10285
10581
|
async function getClinicById(db, clinicId) {
|
|
10286
10582
|
try {
|
|
10287
|
-
const clinicRef =
|
|
10288
|
-
const clinicSnapshot = await
|
|
10583
|
+
const clinicRef = doc21(db, CLINICS_COLLECTION, clinicId);
|
|
10584
|
+
const clinicSnapshot = await getDoc23(clinicRef);
|
|
10289
10585
|
if (!clinicSnapshot.exists()) {
|
|
10290
10586
|
return null;
|
|
10291
10587
|
}
|
|
@@ -10316,11 +10612,11 @@ async function getAllClinics(db, pagination, lastDoc) {
|
|
|
10316
10612
|
}
|
|
10317
10613
|
const clinicsSnapshot = await getDocs15(clinicsQuery);
|
|
10318
10614
|
const lastVisible = clinicsSnapshot.docs[clinicsSnapshot.docs.length - 1];
|
|
10319
|
-
const clinics = clinicsSnapshot.docs.map((
|
|
10320
|
-
const data =
|
|
10615
|
+
const clinics = clinicsSnapshot.docs.map((doc45) => {
|
|
10616
|
+
const data = doc45.data();
|
|
10321
10617
|
return {
|
|
10322
10618
|
...data,
|
|
10323
|
-
id:
|
|
10619
|
+
id: doc45.id
|
|
10324
10620
|
};
|
|
10325
10621
|
});
|
|
10326
10622
|
return {
|
|
@@ -10347,8 +10643,8 @@ async function getAllClinicsInRange(db, center, rangeInKm, pagination, lastDoc)
|
|
|
10347
10643
|
];
|
|
10348
10644
|
const q = query15(collection15(db, CLINICS_COLLECTION), ...constraints);
|
|
10349
10645
|
const querySnapshot = await getDocs15(q);
|
|
10350
|
-
for (const
|
|
10351
|
-
const clinic =
|
|
10646
|
+
for (const doc45 of querySnapshot.docs) {
|
|
10647
|
+
const clinic = doc45.data();
|
|
10352
10648
|
const distance = distanceBetween2(
|
|
10353
10649
|
[center.latitude, center.longitude],
|
|
10354
10650
|
[clinic.location.latitude, clinic.location.longitude]
|
|
@@ -10470,8 +10766,8 @@ async function findClinicsInRadius(db, center, radiusInKm, filters) {
|
|
|
10470
10766
|
}
|
|
10471
10767
|
const q = query16(collection16(db, CLINICS_COLLECTION), ...constraints);
|
|
10472
10768
|
const querySnapshot = await getDocs16(q);
|
|
10473
|
-
for (const
|
|
10474
|
-
const clinic =
|
|
10769
|
+
for (const doc45 of querySnapshot.docs) {
|
|
10770
|
+
const clinic = doc45.data();
|
|
10475
10771
|
const distance = distanceBetween3(
|
|
10476
10772
|
[center.latitude, center.longitude],
|
|
10477
10773
|
[clinic.location.latitude, clinic.location.longitude]
|
|
@@ -10600,7 +10896,7 @@ async function getClinicsByFilters(db, filters) {
|
|
|
10600
10896
|
constraints.push(limit10(filters.pagination || 5));
|
|
10601
10897
|
const q = query17(collection17(db, CLINICS_COLLECTION), ...constraints);
|
|
10602
10898
|
const querySnapshot = await getDocs17(q);
|
|
10603
|
-
let clinics = querySnapshot.docs.map((
|
|
10899
|
+
let clinics = querySnapshot.docs.map((doc45) => ({ ...doc45.data(), id: doc45.id }));
|
|
10604
10900
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
10605
10901
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
10606
10902
|
console.log(`[CLINIC_SERVICE] Strategy 1 success: ${clinics.length} clinics`);
|
|
@@ -10632,7 +10928,7 @@ async function getClinicsByFilters(db, filters) {
|
|
|
10632
10928
|
constraints.push(limit10(filters.pagination || 5));
|
|
10633
10929
|
const q = query17(collection17(db, CLINICS_COLLECTION), ...constraints);
|
|
10634
10930
|
const querySnapshot = await getDocs17(q);
|
|
10635
|
-
let clinics = querySnapshot.docs.map((
|
|
10931
|
+
let clinics = querySnapshot.docs.map((doc45) => ({ ...doc45.data(), id: doc45.id }));
|
|
10636
10932
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
10637
10933
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
10638
10934
|
console.log(`[CLINIC_SERVICE] Strategy 2 success: ${clinics.length} clinics`);
|
|
@@ -10662,7 +10958,7 @@ async function getClinicsByFilters(db, filters) {
|
|
|
10662
10958
|
constraints.push(limit10(filters.pagination || 5));
|
|
10663
10959
|
const q = query17(collection17(db, CLINICS_COLLECTION), ...constraints);
|
|
10664
10960
|
const querySnapshot = await getDocs17(q);
|
|
10665
|
-
let clinics = querySnapshot.docs.map((
|
|
10961
|
+
let clinics = querySnapshot.docs.map((doc45) => ({ ...doc45.data(), id: doc45.id }));
|
|
10666
10962
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
10667
10963
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
10668
10964
|
console.log(`[CLINIC_SERVICE] Strategy 3 success: ${clinics.length} clinics`);
|
|
@@ -10682,7 +10978,7 @@ async function getClinicsByFilters(db, filters) {
|
|
|
10682
10978
|
];
|
|
10683
10979
|
const q = query17(collection17(db, CLINICS_COLLECTION), ...constraints);
|
|
10684
10980
|
const querySnapshot = await getDocs17(q);
|
|
10685
|
-
let clinics = querySnapshot.docs.map((
|
|
10981
|
+
let clinics = querySnapshot.docs.map((doc45) => ({ ...doc45.data(), id: doc45.id }));
|
|
10686
10982
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
10687
10983
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
10688
10984
|
console.log(`[CLINIC_SERVICE] Strategy 4 success: ${clinics.length} clinics`);
|
|
@@ -10987,9 +11283,9 @@ var ClinicService = class extends BaseService {
|
|
|
10987
11283
|
updatedAt: serverTimestamp20()
|
|
10988
11284
|
};
|
|
10989
11285
|
const batch = writeBatch4(this.db);
|
|
10990
|
-
const clinicRef =
|
|
11286
|
+
const clinicRef = doc22(this.db, CLINICS_COLLECTION, clinicId);
|
|
10991
11287
|
batch.set(clinicRef, clinicData);
|
|
10992
|
-
const adminRef =
|
|
11288
|
+
const adminRef = doc22(this.db, CLINIC_ADMINS_COLLECTION, creatorAdminId);
|
|
10993
11289
|
batch.update(adminRef, {
|
|
10994
11290
|
clinicsManaged: arrayUnion7(clinicId),
|
|
10995
11291
|
updatedAt: serverTimestamp20()
|
|
@@ -11013,8 +11309,8 @@ var ClinicService = class extends BaseService {
|
|
|
11013
11309
|
*/
|
|
11014
11310
|
async updateClinic(clinicId, data, adminId) {
|
|
11015
11311
|
try {
|
|
11016
|
-
const clinicRef =
|
|
11017
|
-
const clinicDoc = await
|
|
11312
|
+
const clinicRef = doc22(this.db, CLINICS_COLLECTION, clinicId);
|
|
11313
|
+
const clinicDoc = await getDoc24(clinicRef);
|
|
11018
11314
|
if (!clinicDoc.exists()) {
|
|
11019
11315
|
throw new Error(`Clinic ${clinicId} not found`);
|
|
11020
11316
|
}
|
|
@@ -11096,7 +11392,7 @@ var ClinicService = class extends BaseService {
|
|
|
11096
11392
|
* Deactivates a clinic.
|
|
11097
11393
|
*/
|
|
11098
11394
|
async deactivateClinic(clinicId, adminId) {
|
|
11099
|
-
const clinicRef =
|
|
11395
|
+
const clinicRef = doc22(this.db, CLINICS_COLLECTION, clinicId);
|
|
11100
11396
|
await updateDoc20(clinicRef, {
|
|
11101
11397
|
isActive: false,
|
|
11102
11398
|
updatedAt: serverTimestamp20()
|
|
@@ -11106,7 +11402,7 @@ var ClinicService = class extends BaseService {
|
|
|
11106
11402
|
* Activates a clinic.
|
|
11107
11403
|
*/
|
|
11108
11404
|
async activateClinic(clinicId, adminId) {
|
|
11109
|
-
const clinicRef =
|
|
11405
|
+
const clinicRef = doc22(this.db, CLINICS_COLLECTION, clinicId);
|
|
11110
11406
|
await updateDoc20(clinicRef, {
|
|
11111
11407
|
isActive: true,
|
|
11112
11408
|
updatedAt: serverTimestamp20()
|
|
@@ -11254,11 +11550,11 @@ var ClinicService = class extends BaseService {
|
|
|
11254
11550
|
async getClinicsForMap() {
|
|
11255
11551
|
const clinicsRef = collection18(this.db, CLINICS_COLLECTION);
|
|
11256
11552
|
const snapshot = await getDocs18(clinicsRef);
|
|
11257
|
-
const clinicsForMap = snapshot.docs.map((
|
|
11553
|
+
const clinicsForMap = snapshot.docs.map((doc45) => {
|
|
11258
11554
|
var _a, _b, _c;
|
|
11259
|
-
const data =
|
|
11555
|
+
const data = doc45.data();
|
|
11260
11556
|
return {
|
|
11261
|
-
id:
|
|
11557
|
+
id: doc45.id,
|
|
11262
11558
|
name: data.name,
|
|
11263
11559
|
address: ((_a = data.location) == null ? void 0 : _a.address) || "",
|
|
11264
11560
|
latitude: (_b = data.location) == null ? void 0 : _b.latitude,
|
|
@@ -12086,8 +12382,8 @@ var AuthService = class extends BaseService {
|
|
|
12086
12382
|
// src/services/calendar/calendar.v2.service.ts
|
|
12087
12383
|
import { Timestamp as Timestamp26, serverTimestamp as serverTimestamp26 } from "firebase/firestore";
|
|
12088
12384
|
import {
|
|
12089
|
-
doc as
|
|
12090
|
-
getDoc as
|
|
12385
|
+
doc as doc30,
|
|
12386
|
+
getDoc as getDoc31,
|
|
12091
12387
|
collection as collection25,
|
|
12092
12388
|
query as query25,
|
|
12093
12389
|
where as where25,
|
|
@@ -12099,8 +12395,8 @@ import {
|
|
|
12099
12395
|
// src/services/calendar/utils/clinic.utils.ts
|
|
12100
12396
|
import {
|
|
12101
12397
|
collection as collection20,
|
|
12102
|
-
doc as
|
|
12103
|
-
getDoc as
|
|
12398
|
+
doc as doc25,
|
|
12399
|
+
getDoc as getDoc26,
|
|
12104
12400
|
getDocs as getDocs20,
|
|
12105
12401
|
setDoc as setDoc17,
|
|
12106
12402
|
updateDoc as updateDoc22,
|
|
@@ -12113,39 +12409,39 @@ import {
|
|
|
12113
12409
|
} from "firebase/firestore";
|
|
12114
12410
|
|
|
12115
12411
|
// src/services/calendar/utils/docs.utils.ts
|
|
12116
|
-
import { doc as
|
|
12412
|
+
import { doc as doc24 } from "firebase/firestore";
|
|
12117
12413
|
function getPractitionerCalendarEventDocRef(db, practitionerId, eventId) {
|
|
12118
|
-
return
|
|
12414
|
+
return doc24(
|
|
12119
12415
|
db,
|
|
12120
12416
|
`${PRACTITIONERS_COLLECTION}/${practitionerId}/${CALENDAR_COLLECTION}/${eventId}`
|
|
12121
12417
|
);
|
|
12122
12418
|
}
|
|
12123
12419
|
function getPatientCalendarEventDocRef(db, patientId, eventId) {
|
|
12124
|
-
return
|
|
12420
|
+
return doc24(
|
|
12125
12421
|
db,
|
|
12126
12422
|
`${PATIENTS_COLLECTION}/${patientId}/${CALENDAR_COLLECTION}/${eventId}`
|
|
12127
12423
|
);
|
|
12128
12424
|
}
|
|
12129
12425
|
function getClinicCalendarEventDocRef(db, clinicId, eventId) {
|
|
12130
|
-
return
|
|
12426
|
+
return doc24(
|
|
12131
12427
|
db,
|
|
12132
12428
|
`${CLINICS_COLLECTION}/${clinicId}/${CALENDAR_COLLECTION}/${eventId}`
|
|
12133
12429
|
);
|
|
12134
12430
|
}
|
|
12135
12431
|
function getPractitionerSyncedCalendarDocRef(db, practitionerId, syncedCalendarId) {
|
|
12136
|
-
return
|
|
12432
|
+
return doc24(
|
|
12137
12433
|
db,
|
|
12138
12434
|
`${PRACTITIONERS_COLLECTION}/${practitionerId}/syncedCalendars/${syncedCalendarId}`
|
|
12139
12435
|
);
|
|
12140
12436
|
}
|
|
12141
12437
|
function getPatientSyncedCalendarDocRef(db, patientId, syncedCalendarId) {
|
|
12142
|
-
return
|
|
12438
|
+
return doc24(
|
|
12143
12439
|
db,
|
|
12144
12440
|
`${PATIENTS_COLLECTION}/${patientId}/syncedCalendars/${syncedCalendarId}`
|
|
12145
12441
|
);
|
|
12146
12442
|
}
|
|
12147
12443
|
function getClinicSyncedCalendarDocRef(db, clinicId, syncedCalendarId) {
|
|
12148
|
-
return
|
|
12444
|
+
return doc24(
|
|
12149
12445
|
db,
|
|
12150
12446
|
`${CLINICS_COLLECTION}/${clinicId}/syncedCalendars/${syncedCalendarId}`
|
|
12151
12447
|
);
|
|
@@ -12175,14 +12471,14 @@ async function updateClinicCalendarEventUtil(db, clinicId, eventId, updateData)
|
|
|
12175
12471
|
updatedAt: serverTimestamp21()
|
|
12176
12472
|
};
|
|
12177
12473
|
await updateDoc22(eventRef, updates);
|
|
12178
|
-
const updatedDoc = await
|
|
12474
|
+
const updatedDoc = await getDoc26(eventRef);
|
|
12179
12475
|
if (!updatedDoc.exists()) {
|
|
12180
12476
|
throw new Error("Event not found after update");
|
|
12181
12477
|
}
|
|
12182
12478
|
return updatedDoc.data();
|
|
12183
12479
|
}
|
|
12184
12480
|
async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
|
|
12185
|
-
const clinicDoc = await
|
|
12481
|
+
const clinicDoc = await getDoc26(doc25(db, `clinics/${clinicId}`));
|
|
12186
12482
|
if (!clinicDoc.exists()) {
|
|
12187
12483
|
throw new Error(`Clinic with ID ${clinicId} not found`);
|
|
12188
12484
|
}
|
|
@@ -12191,8 +12487,8 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
|
|
|
12191
12487
|
if (!clinicGroupId) {
|
|
12192
12488
|
return false;
|
|
12193
12489
|
}
|
|
12194
|
-
const clinicGroupDoc = await
|
|
12195
|
-
|
|
12490
|
+
const clinicGroupDoc = await getDoc26(
|
|
12491
|
+
doc25(db, `${CLINIC_GROUPS_COLLECTION}/${clinicGroupId}`)
|
|
12196
12492
|
);
|
|
12197
12493
|
if (!clinicGroupDoc.exists()) {
|
|
12198
12494
|
return false;
|
|
@@ -12204,7 +12500,7 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
|
|
|
12204
12500
|
// src/services/calendar/utils/patient.utils.ts
|
|
12205
12501
|
import {
|
|
12206
12502
|
collection as collection21,
|
|
12207
|
-
getDoc as
|
|
12503
|
+
getDoc as getDoc27,
|
|
12208
12504
|
getDocs as getDocs21,
|
|
12209
12505
|
setDoc as setDoc18,
|
|
12210
12506
|
updateDoc as updateDoc23,
|
|
@@ -12238,7 +12534,7 @@ async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData
|
|
|
12238
12534
|
updatedAt: serverTimestamp22()
|
|
12239
12535
|
};
|
|
12240
12536
|
await updateDoc23(eventRef, updates);
|
|
12241
|
-
const updatedDoc = await
|
|
12537
|
+
const updatedDoc = await getDoc27(eventRef);
|
|
12242
12538
|
if (!updatedDoc.exists()) {
|
|
12243
12539
|
throw new Error("Event not found after update");
|
|
12244
12540
|
}
|
|
@@ -12248,7 +12544,7 @@ async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData
|
|
|
12248
12544
|
// src/services/calendar/utils/practitioner.utils.ts
|
|
12249
12545
|
import {
|
|
12250
12546
|
collection as collection22,
|
|
12251
|
-
getDoc as
|
|
12547
|
+
getDoc as getDoc28,
|
|
12252
12548
|
getDocs as getDocs22,
|
|
12253
12549
|
setDoc as setDoc19,
|
|
12254
12550
|
updateDoc as updateDoc24,
|
|
@@ -12290,7 +12586,7 @@ async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId,
|
|
|
12290
12586
|
updatedAt: serverTimestamp23()
|
|
12291
12587
|
};
|
|
12292
12588
|
await updateDoc24(eventRef, updates);
|
|
12293
|
-
const updatedDoc = await
|
|
12589
|
+
const updatedDoc = await getDoc28(eventRef);
|
|
12294
12590
|
if (!updatedDoc.exists()) {
|
|
12295
12591
|
throw new Error("Event not found after update");
|
|
12296
12592
|
}
|
|
@@ -12350,8 +12646,8 @@ async function updateAppointmentUtil2(db, clinicId, practitionerId, patientId, e
|
|
|
12350
12646
|
// src/services/calendar/utils/calendar-event.utils.ts
|
|
12351
12647
|
import {
|
|
12352
12648
|
collection as collection23,
|
|
12353
|
-
doc as
|
|
12354
|
-
getDoc as
|
|
12649
|
+
doc as doc28,
|
|
12650
|
+
getDoc as getDoc29,
|
|
12355
12651
|
getDocs as getDocs23,
|
|
12356
12652
|
setDoc as setDoc20,
|
|
12357
12653
|
updateDoc as updateDoc25,
|
|
@@ -12445,7 +12741,7 @@ async function searchCalendarEventsUtil(db, params) {
|
|
|
12445
12741
|
const finalQuery = query23(collectionRef, ...constraints);
|
|
12446
12742
|
const querySnapshot = await getDocs23(finalQuery);
|
|
12447
12743
|
const events = querySnapshot.docs.map(
|
|
12448
|
-
(
|
|
12744
|
+
(doc45) => ({ id: doc45.id, ...doc45.data() })
|
|
12449
12745
|
);
|
|
12450
12746
|
return events;
|
|
12451
12747
|
} catch (error) {
|
|
@@ -12457,7 +12753,7 @@ async function searchCalendarEventsUtil(db, params) {
|
|
|
12457
12753
|
// src/services/calendar/utils/synced-calendar.utils.ts
|
|
12458
12754
|
import {
|
|
12459
12755
|
collection as collection24,
|
|
12460
|
-
getDoc as
|
|
12756
|
+
getDoc as getDoc30,
|
|
12461
12757
|
getDocs as getDocs24,
|
|
12462
12758
|
setDoc as setDoc21,
|
|
12463
12759
|
updateDoc as updateDoc26,
|
|
@@ -12525,7 +12821,7 @@ async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId)
|
|
|
12525
12821
|
practitionerId,
|
|
12526
12822
|
calendarId
|
|
12527
12823
|
);
|
|
12528
|
-
const calendarDoc = await
|
|
12824
|
+
const calendarDoc = await getDoc30(calendarRef);
|
|
12529
12825
|
if (!calendarDoc.exists()) {
|
|
12530
12826
|
return null;
|
|
12531
12827
|
}
|
|
@@ -12538,11 +12834,11 @@ async function getPractitionerSyncedCalendarsUtil(db, practitionerId) {
|
|
|
12538
12834
|
);
|
|
12539
12835
|
const q = query24(calendarsRef, orderBy12("createdAt", "desc"));
|
|
12540
12836
|
const querySnapshot = await getDocs24(q);
|
|
12541
|
-
return querySnapshot.docs.map((
|
|
12837
|
+
return querySnapshot.docs.map((doc45) => doc45.data());
|
|
12542
12838
|
}
|
|
12543
12839
|
async function getPatientSyncedCalendarUtil(db, patientId, calendarId) {
|
|
12544
12840
|
const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
|
|
12545
|
-
const calendarDoc = await
|
|
12841
|
+
const calendarDoc = await getDoc30(calendarRef);
|
|
12546
12842
|
if (!calendarDoc.exists()) {
|
|
12547
12843
|
return null;
|
|
12548
12844
|
}
|
|
@@ -12555,11 +12851,11 @@ async function getPatientSyncedCalendarsUtil(db, patientId) {
|
|
|
12555
12851
|
);
|
|
12556
12852
|
const q = query24(calendarsRef, orderBy12("createdAt", "desc"));
|
|
12557
12853
|
const querySnapshot = await getDocs24(q);
|
|
12558
|
-
return querySnapshot.docs.map((
|
|
12854
|
+
return querySnapshot.docs.map((doc45) => doc45.data());
|
|
12559
12855
|
}
|
|
12560
12856
|
async function getClinicSyncedCalendarUtil(db, clinicId, calendarId) {
|
|
12561
12857
|
const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
|
|
12562
|
-
const calendarDoc = await
|
|
12858
|
+
const calendarDoc = await getDoc30(calendarRef);
|
|
12563
12859
|
if (!calendarDoc.exists()) {
|
|
12564
12860
|
return null;
|
|
12565
12861
|
}
|
|
@@ -12572,7 +12868,7 @@ async function getClinicSyncedCalendarsUtil(db, clinicId) {
|
|
|
12572
12868
|
);
|
|
12573
12869
|
const q = query24(calendarsRef, orderBy12("createdAt", "desc"));
|
|
12574
12870
|
const querySnapshot = await getDocs24(q);
|
|
12575
|
-
return querySnapshot.docs.map((
|
|
12871
|
+
return querySnapshot.docs.map((doc45) => doc45.data());
|
|
12576
12872
|
}
|
|
12577
12873
|
async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendarId, updateData) {
|
|
12578
12874
|
const calendarRef = getPractitionerSyncedCalendarDocRef(
|
|
@@ -12585,7 +12881,7 @@ async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendar
|
|
|
12585
12881
|
updatedAt: serverTimestamp25()
|
|
12586
12882
|
};
|
|
12587
12883
|
await updateDoc26(calendarRef, updates);
|
|
12588
|
-
const updatedDoc = await
|
|
12884
|
+
const updatedDoc = await getDoc30(calendarRef);
|
|
12589
12885
|
if (!updatedDoc.exists()) {
|
|
12590
12886
|
throw new Error("Synced calendar not found after update");
|
|
12591
12887
|
}
|
|
@@ -12598,7 +12894,7 @@ async function updatePatientSyncedCalendarUtil(db, patientId, calendarId, update
|
|
|
12598
12894
|
updatedAt: serverTimestamp25()
|
|
12599
12895
|
};
|
|
12600
12896
|
await updateDoc26(calendarRef, updates);
|
|
12601
|
-
const updatedDoc = await
|
|
12897
|
+
const updatedDoc = await getDoc30(calendarRef);
|
|
12602
12898
|
if (!updatedDoc.exists()) {
|
|
12603
12899
|
throw new Error("Synced calendar not found after update");
|
|
12604
12900
|
}
|
|
@@ -12611,7 +12907,7 @@ async function updateClinicSyncedCalendarUtil(db, clinicId, calendarId, updateDa
|
|
|
12611
12907
|
updatedAt: serverTimestamp25()
|
|
12612
12908
|
};
|
|
12613
12909
|
await updateDoc26(calendarRef, updates);
|
|
12614
|
-
const updatedDoc = await
|
|
12910
|
+
const updatedDoc = await getDoc30(calendarRef);
|
|
12615
12911
|
if (!updatedDoc.exists()) {
|
|
12616
12912
|
throw new Error("Synced calendar not found after update");
|
|
12617
12913
|
}
|
|
@@ -13820,7 +14116,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
13820
14116
|
async createDoctorBlockingEvent(doctorId, eventData) {
|
|
13821
14117
|
try {
|
|
13822
14118
|
const eventId = this.generateId();
|
|
13823
|
-
const eventRef =
|
|
14119
|
+
const eventRef = doc30(
|
|
13824
14120
|
this.db,
|
|
13825
14121
|
PRACTITIONERS_COLLECTION,
|
|
13826
14122
|
doctorId,
|
|
@@ -13927,9 +14223,9 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
13927
14223
|
where25("eventTime.start", "<=", Timestamp26.fromDate(endDate))
|
|
13928
14224
|
);
|
|
13929
14225
|
const eventsSnapshot = await getDocs25(q);
|
|
13930
|
-
const events = eventsSnapshot.docs.map((
|
|
13931
|
-
id:
|
|
13932
|
-
...
|
|
14226
|
+
const events = eventsSnapshot.docs.map((doc45) => ({
|
|
14227
|
+
id: doc45.id,
|
|
14228
|
+
...doc45.data()
|
|
13933
14229
|
}));
|
|
13934
14230
|
const calendars = await this.syncedCalendarsService.getPractitionerSyncedCalendars(
|
|
13935
14231
|
doctorId
|
|
@@ -14033,7 +14329,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
14033
14329
|
const endTime = new Date(
|
|
14034
14330
|
externalEvent.end.dateTime || externalEvent.end.date
|
|
14035
14331
|
);
|
|
14036
|
-
const eventRef =
|
|
14332
|
+
const eventRef = doc30(
|
|
14037
14333
|
this.db,
|
|
14038
14334
|
PRACTITIONERS_COLLECTION,
|
|
14039
14335
|
doctorId,
|
|
@@ -14065,7 +14361,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
14065
14361
|
*/
|
|
14066
14362
|
async updateEventStatus(doctorId, eventId, status) {
|
|
14067
14363
|
try {
|
|
14068
|
-
const eventRef =
|
|
14364
|
+
const eventRef = doc30(
|
|
14069
14365
|
this.db,
|
|
14070
14366
|
PRACTITIONERS_COLLECTION,
|
|
14071
14367
|
doctorId,
|
|
@@ -14231,8 +14527,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
14231
14527
|
const startDate = eventTime.start.toDate();
|
|
14232
14528
|
const startTime = startDate;
|
|
14233
14529
|
const endTime = eventTime.end.toDate();
|
|
14234
|
-
const practitionerRef =
|
|
14235
|
-
const practitionerDoc = await
|
|
14530
|
+
const practitionerRef = doc30(this.db, PRACTITIONERS_COLLECTION, doctorId);
|
|
14531
|
+
const practitionerDoc = await getDoc31(practitionerRef);
|
|
14236
14532
|
if (!practitionerDoc.exists()) {
|
|
14237
14533
|
throw new Error(`Doctor with ID ${doctorId} not found`);
|
|
14238
14534
|
}
|
|
@@ -14290,8 +14586,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
14290
14586
|
*/
|
|
14291
14587
|
async updateAppointmentStatus(appointmentId, clinicId, status) {
|
|
14292
14588
|
const baseCollectionPath = `${CLINICS_COLLECTION}/${clinicId}/${CALENDAR_COLLECTION}`;
|
|
14293
|
-
const appointmentRef =
|
|
14294
|
-
const appointmentDoc = await
|
|
14589
|
+
const appointmentRef = doc30(this.db, baseCollectionPath, appointmentId);
|
|
14590
|
+
const appointmentDoc = await getDoc31(appointmentRef);
|
|
14295
14591
|
if (!appointmentDoc.exists()) {
|
|
14296
14592
|
throw new Error(`Appointment with ID ${appointmentId} not found`);
|
|
14297
14593
|
}
|
|
@@ -14450,8 +14746,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
14450
14746
|
async updateEventWithSyncId(entityId, entityType, eventId, syncEvent) {
|
|
14451
14747
|
try {
|
|
14452
14748
|
const collectionPath = entityType === "doctor" ? `${PRACTITIONERS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}` : `${PATIENTS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
|
|
14453
|
-
const eventRef =
|
|
14454
|
-
const eventDoc = await
|
|
14749
|
+
const eventRef = doc30(this.db, collectionPath, eventId);
|
|
14750
|
+
const eventDoc = await getDoc31(eventRef);
|
|
14455
14751
|
if (eventDoc.exists()) {
|
|
14456
14752
|
const event = eventDoc.data();
|
|
14457
14753
|
const syncIds = [...event.syncedCalendarEventId || []];
|
|
@@ -14489,8 +14785,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
14489
14785
|
* @returns Working hours for the clinic
|
|
14490
14786
|
*/
|
|
14491
14787
|
async getClinicWorkingHours(clinicId, date) {
|
|
14492
|
-
const clinicRef =
|
|
14493
|
-
const clinicDoc = await
|
|
14788
|
+
const clinicRef = doc30(this.db, CLINICS_COLLECTION, clinicId);
|
|
14789
|
+
const clinicDoc = await getDoc31(clinicRef);
|
|
14494
14790
|
if (!clinicDoc.exists()) {
|
|
14495
14791
|
throw new Error(`Clinic with ID ${clinicId} not found`);
|
|
14496
14792
|
}
|
|
@@ -14518,8 +14814,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
14518
14814
|
* @returns Doctor's schedule
|
|
14519
14815
|
*/
|
|
14520
14816
|
async getDoctorSchedule(doctorId, date) {
|
|
14521
|
-
const practitionerRef =
|
|
14522
|
-
const practitionerDoc = await
|
|
14817
|
+
const practitionerRef = doc30(this.db, PRACTITIONERS_COLLECTION, doctorId);
|
|
14818
|
+
const practitionerDoc = await getDoc31(practitionerRef);
|
|
14523
14819
|
if (!practitionerDoc.exists()) {
|
|
14524
14820
|
throw new Error(`Doctor with ID ${doctorId} not found`);
|
|
14525
14821
|
}
|
|
@@ -14563,7 +14859,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
14563
14859
|
])
|
|
14564
14860
|
);
|
|
14565
14861
|
const querySnapshot = await getDocs25(q);
|
|
14566
|
-
return querySnapshot.docs.map((
|
|
14862
|
+
return querySnapshot.docs.map((doc45) => doc45.data());
|
|
14567
14863
|
}
|
|
14568
14864
|
/**
|
|
14569
14865
|
* Calculates available time slots based on working hours, schedule and existing appointments
|
|
@@ -14620,11 +14916,11 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
14620
14916
|
var _a;
|
|
14621
14917
|
try {
|
|
14622
14918
|
const [clinicDoc, practitionerDoc, patientDoc, patientSensitiveInfoDoc] = await Promise.all([
|
|
14623
|
-
|
|
14624
|
-
|
|
14625
|
-
|
|
14626
|
-
|
|
14627
|
-
|
|
14919
|
+
getDoc31(doc30(this.db, CLINICS_COLLECTION, clinicId)),
|
|
14920
|
+
getDoc31(doc30(this.db, PRACTITIONERS_COLLECTION, doctorId)),
|
|
14921
|
+
getDoc31(doc30(this.db, PATIENTS_COLLECTION, patientId)),
|
|
14922
|
+
getDoc31(
|
|
14923
|
+
doc30(
|
|
14628
14924
|
this.db,
|
|
14629
14925
|
PATIENTS_COLLECTION,
|
|
14630
14926
|
patientId,
|
|
@@ -14689,7 +14985,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
14689
14985
|
|
|
14690
14986
|
// src/services/calendar/calendar.v3.service.ts
|
|
14691
14987
|
import { Timestamp as Timestamp27, serverTimestamp as serverTimestamp27 } from "firebase/firestore";
|
|
14692
|
-
import { doc as
|
|
14988
|
+
import { doc as doc31, getDoc as getDoc32, setDoc as setDoc23, updateDoc as updateDoc28, deleteDoc as deleteDoc15 } from "firebase/firestore";
|
|
14693
14989
|
var CalendarServiceV3 = class extends BaseService {
|
|
14694
14990
|
/**
|
|
14695
14991
|
* Creates a new CalendarServiceV3 instance
|
|
@@ -14713,7 +15009,7 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
14713
15009
|
params.entityType,
|
|
14714
15010
|
params.entityId
|
|
14715
15011
|
);
|
|
14716
|
-
const eventRef =
|
|
15012
|
+
const eventRef = doc31(this.db, collectionPath, eventId);
|
|
14717
15013
|
const eventData = {
|
|
14718
15014
|
id: eventId,
|
|
14719
15015
|
eventName: params.eventName,
|
|
@@ -14748,8 +15044,8 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
14748
15044
|
params.entityType,
|
|
14749
15045
|
params.entityId
|
|
14750
15046
|
);
|
|
14751
|
-
const eventRef =
|
|
14752
|
-
const eventDoc = await
|
|
15047
|
+
const eventRef = doc31(this.db, collectionPath, params.eventId);
|
|
15048
|
+
const eventDoc = await getDoc32(eventRef);
|
|
14753
15049
|
if (!eventDoc.exists()) {
|
|
14754
15050
|
throw new Error(`Blocking event with ID ${params.eventId} not found`);
|
|
14755
15051
|
}
|
|
@@ -14769,7 +15065,7 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
14769
15065
|
updateData.status = params.status;
|
|
14770
15066
|
}
|
|
14771
15067
|
await updateDoc28(eventRef, updateData);
|
|
14772
|
-
const updatedEventDoc = await
|
|
15068
|
+
const updatedEventDoc = await getDoc32(eventRef);
|
|
14773
15069
|
return updatedEventDoc.data();
|
|
14774
15070
|
}
|
|
14775
15071
|
/**
|
|
@@ -14780,8 +15076,8 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
14780
15076
|
*/
|
|
14781
15077
|
async deleteBlockingEvent(entityType, entityId, eventId) {
|
|
14782
15078
|
const collectionPath = this.getEntityCalendarPath(entityType, entityId);
|
|
14783
|
-
const eventRef =
|
|
14784
|
-
const eventDoc = await
|
|
15079
|
+
const eventRef = doc31(this.db, collectionPath, eventId);
|
|
15080
|
+
const eventDoc = await getDoc32(eventRef);
|
|
14785
15081
|
if (!eventDoc.exists()) {
|
|
14786
15082
|
throw new Error(`Blocking event with ID ${eventId} not found`);
|
|
14787
15083
|
}
|
|
@@ -14796,8 +15092,8 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
14796
15092
|
*/
|
|
14797
15093
|
async getBlockingEvent(entityType, entityId, eventId) {
|
|
14798
15094
|
const collectionPath = this.getEntityCalendarPath(entityType, entityId);
|
|
14799
|
-
const eventRef =
|
|
14800
|
-
const eventDoc = await
|
|
15095
|
+
const eventRef = doc31(this.db, collectionPath, eventId);
|
|
15096
|
+
const eventDoc = await getDoc32(eventRef);
|
|
14801
15097
|
if (!eventDoc.exists()) {
|
|
14802
15098
|
return null;
|
|
14803
15099
|
}
|
|
@@ -14992,8 +15288,8 @@ var ExternalCalendarService = class extends BaseService {
|
|
|
14992
15288
|
// src/services/clinic/practitioner-invite.service.ts
|
|
14993
15289
|
import {
|
|
14994
15290
|
collection as collection26,
|
|
14995
|
-
doc as
|
|
14996
|
-
getDoc as
|
|
15291
|
+
doc as doc32,
|
|
15292
|
+
getDoc as getDoc33,
|
|
14997
15293
|
getDocs as getDocs26,
|
|
14998
15294
|
query as query26,
|
|
14999
15295
|
where as where26,
|
|
@@ -15077,7 +15373,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
15077
15373
|
rejectedAt: null,
|
|
15078
15374
|
cancelledAt: null
|
|
15079
15375
|
};
|
|
15080
|
-
const docRef =
|
|
15376
|
+
const docRef = doc32(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
15081
15377
|
await setDoc24(docRef, invite);
|
|
15082
15378
|
return invite;
|
|
15083
15379
|
} catch (error) {
|
|
@@ -15108,7 +15404,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
15108
15404
|
...constraints
|
|
15109
15405
|
);
|
|
15110
15406
|
const querySnapshot = await getDocs26(q);
|
|
15111
|
-
return querySnapshot.docs.map((
|
|
15407
|
+
return querySnapshot.docs.map((doc45) => doc45.data());
|
|
15112
15408
|
} catch (error) {
|
|
15113
15409
|
console.error(
|
|
15114
15410
|
"[PractitionerInviteService] Error getting doctor invites:",
|
|
@@ -15137,7 +15433,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
15137
15433
|
...constraints
|
|
15138
15434
|
);
|
|
15139
15435
|
const querySnapshot = await getDocs26(q);
|
|
15140
|
-
return querySnapshot.docs.map((
|
|
15436
|
+
return querySnapshot.docs.map((doc45) => doc45.data());
|
|
15141
15437
|
} catch (error) {
|
|
15142
15438
|
console.error(
|
|
15143
15439
|
"[PractitionerInviteService] Error getting clinic invites:",
|
|
@@ -15165,7 +15461,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
15165
15461
|
acceptedAt: Timestamp28.now(),
|
|
15166
15462
|
updatedAt: serverTimestamp28()
|
|
15167
15463
|
};
|
|
15168
|
-
const docRef =
|
|
15464
|
+
const docRef = doc32(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
15169
15465
|
await updateDoc29(docRef, updateData);
|
|
15170
15466
|
return await this.getInviteById(inviteId);
|
|
15171
15467
|
} catch (error) {
|
|
@@ -15197,7 +15493,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
15197
15493
|
rejectedAt: Timestamp28.now(),
|
|
15198
15494
|
updatedAt: serverTimestamp28()
|
|
15199
15495
|
};
|
|
15200
|
-
const docRef =
|
|
15496
|
+
const docRef = doc32(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
15201
15497
|
await updateDoc29(docRef, updateData);
|
|
15202
15498
|
return await this.getInviteById(inviteId);
|
|
15203
15499
|
} catch (error) {
|
|
@@ -15229,7 +15525,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
15229
15525
|
cancelledAt: Timestamp28.now(),
|
|
15230
15526
|
updatedAt: serverTimestamp28()
|
|
15231
15527
|
};
|
|
15232
|
-
const docRef =
|
|
15528
|
+
const docRef = doc32(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
15233
15529
|
await updateDoc29(docRef, updateData);
|
|
15234
15530
|
return await this.getInviteById(inviteId);
|
|
15235
15531
|
} catch (error) {
|
|
@@ -15247,8 +15543,8 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
15247
15543
|
*/
|
|
15248
15544
|
async getInviteById(inviteId) {
|
|
15249
15545
|
try {
|
|
15250
|
-
const docRef =
|
|
15251
|
-
const docSnap = await
|
|
15546
|
+
const docRef = doc32(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
15547
|
+
const docSnap = await getDoc33(docRef);
|
|
15252
15548
|
if (docSnap.exists()) {
|
|
15253
15549
|
return docSnap.data();
|
|
15254
15550
|
}
|
|
@@ -15293,7 +15589,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
15293
15589
|
);
|
|
15294
15590
|
const querySnapshot = await getDocs26(q);
|
|
15295
15591
|
let invites = querySnapshot.docs.map(
|
|
15296
|
-
(
|
|
15592
|
+
(doc45) => doc45.data()
|
|
15297
15593
|
);
|
|
15298
15594
|
if (filters.fromDate) {
|
|
15299
15595
|
invites = invites.filter(
|
|
@@ -15320,7 +15616,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
15320
15616
|
*/
|
|
15321
15617
|
async deleteInvite(inviteId) {
|
|
15322
15618
|
try {
|
|
15323
|
-
const docRef =
|
|
15619
|
+
const docRef = doc32(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
15324
15620
|
await deleteDoc16(docRef);
|
|
15325
15621
|
} catch (error) {
|
|
15326
15622
|
console.error(
|
|
@@ -15338,8 +15634,8 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
15338
15634
|
*/
|
|
15339
15635
|
async getPractitionerById(practitionerId) {
|
|
15340
15636
|
try {
|
|
15341
|
-
const docRef =
|
|
15342
|
-
const docSnap = await
|
|
15637
|
+
const docRef = doc32(this.db, PRACTITIONERS_COLLECTION, practitionerId);
|
|
15638
|
+
const docSnap = await getDoc33(docRef);
|
|
15343
15639
|
return docSnap.exists() ? docSnap.data() : null;
|
|
15344
15640
|
} catch (error) {
|
|
15345
15641
|
console.error(
|
|
@@ -15356,8 +15652,8 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
15356
15652
|
*/
|
|
15357
15653
|
async getClinicById(clinicId) {
|
|
15358
15654
|
try {
|
|
15359
|
-
const docRef =
|
|
15360
|
-
const docSnap = await
|
|
15655
|
+
const docRef = doc32(this.db, CLINICS_COLLECTION, clinicId);
|
|
15656
|
+
const docSnap = await getDoc33(docRef);
|
|
15361
15657
|
return docSnap.exists() ? docSnap.data() : null;
|
|
15362
15658
|
} catch (error) {
|
|
15363
15659
|
console.error("[PractitionerInviteService] Error getting clinic:", error);
|
|
@@ -15397,8 +15693,8 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
15397
15693
|
// src/services/documentation-templates/documentation-template.service.ts
|
|
15398
15694
|
import {
|
|
15399
15695
|
collection as collection27,
|
|
15400
|
-
doc as
|
|
15401
|
-
getDoc as
|
|
15696
|
+
doc as doc33,
|
|
15697
|
+
getDoc as getDoc34,
|
|
15402
15698
|
getDocs as getDocs27,
|
|
15403
15699
|
setDoc as setDoc25,
|
|
15404
15700
|
updateDoc as updateDoc30,
|
|
@@ -15447,7 +15743,7 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15447
15743
|
isRequired: validatedData.isRequired || false,
|
|
15448
15744
|
sortingOrder: validatedData.sortingOrder || 0
|
|
15449
15745
|
};
|
|
15450
|
-
const docRef =
|
|
15746
|
+
const docRef = doc33(this.collectionRef, templateId);
|
|
15451
15747
|
await setDoc25(docRef, template);
|
|
15452
15748
|
return template;
|
|
15453
15749
|
}
|
|
@@ -15458,8 +15754,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15458
15754
|
* @returns The template or null if not found
|
|
15459
15755
|
*/
|
|
15460
15756
|
async getTemplateById(templateId, version) {
|
|
15461
|
-
const docRef =
|
|
15462
|
-
const docSnap = await
|
|
15757
|
+
const docRef = doc33(this.collectionRef, templateId);
|
|
15758
|
+
const docSnap = await getDoc34(docRef);
|
|
15463
15759
|
if (!docSnap.exists()) {
|
|
15464
15760
|
return null;
|
|
15465
15761
|
}
|
|
@@ -15501,7 +15797,7 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15501
15797
|
this.db,
|
|
15502
15798
|
`${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
|
|
15503
15799
|
);
|
|
15504
|
-
const versionDocRef =
|
|
15800
|
+
const versionDocRef = doc33(
|
|
15505
15801
|
versionsCollectionRef,
|
|
15506
15802
|
template.version.toString()
|
|
15507
15803
|
);
|
|
@@ -15529,7 +15825,7 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15529
15825
|
updatePayload.isUserForm = (_a = validatedData.isUserForm) != null ? _a : false;
|
|
15530
15826
|
updatePayload.isRequired = (_b = validatedData.isRequired) != null ? _b : false;
|
|
15531
15827
|
updatePayload.sortingOrder = (_c = validatedData.sortingOrder) != null ? _c : 0;
|
|
15532
|
-
const docRef =
|
|
15828
|
+
const docRef = doc33(this.collectionRef, templateId);
|
|
15533
15829
|
console.log("Update payload", updatePayload);
|
|
15534
15830
|
await updateDoc30(docRef, updatePayload);
|
|
15535
15831
|
return { ...template, ...updatePayload };
|
|
@@ -15541,11 +15837,11 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15541
15837
|
* @returns The template version or null if not found
|
|
15542
15838
|
*/
|
|
15543
15839
|
async getTemplateVersion(templateId, versionNumber) {
|
|
15544
|
-
const versionDocRef =
|
|
15840
|
+
const versionDocRef = doc33(
|
|
15545
15841
|
this.db,
|
|
15546
15842
|
`${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions/${versionNumber}`
|
|
15547
15843
|
);
|
|
15548
|
-
const versionDocSnap = await
|
|
15844
|
+
const versionDocSnap = await getDoc34(versionDocRef);
|
|
15549
15845
|
if (!versionDocSnap.exists()) {
|
|
15550
15846
|
return null;
|
|
15551
15847
|
}
|
|
@@ -15564,8 +15860,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15564
15860
|
const q = query27(versionsCollectionRef, orderBy14("version", "desc"));
|
|
15565
15861
|
const querySnapshot = await getDocs27(q);
|
|
15566
15862
|
const versions = [];
|
|
15567
|
-
querySnapshot.forEach((
|
|
15568
|
-
versions.push(
|
|
15863
|
+
querySnapshot.forEach((doc45) => {
|
|
15864
|
+
versions.push(doc45.data());
|
|
15569
15865
|
});
|
|
15570
15866
|
return versions;
|
|
15571
15867
|
}
|
|
@@ -15574,7 +15870,7 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15574
15870
|
* @param templateId - ID of the template to delete
|
|
15575
15871
|
*/
|
|
15576
15872
|
async deleteTemplate(templateId) {
|
|
15577
|
-
const docRef =
|
|
15873
|
+
const docRef = doc33(this.collectionRef, templateId);
|
|
15578
15874
|
await deleteDoc17(docRef);
|
|
15579
15875
|
}
|
|
15580
15876
|
/**
|
|
@@ -15596,9 +15892,9 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15596
15892
|
const querySnapshot = await getDocs27(q);
|
|
15597
15893
|
const templates = [];
|
|
15598
15894
|
let lastVisible = null;
|
|
15599
|
-
querySnapshot.forEach((
|
|
15600
|
-
templates.push(
|
|
15601
|
-
lastVisible =
|
|
15895
|
+
querySnapshot.forEach((doc45) => {
|
|
15896
|
+
templates.push(doc45.data());
|
|
15897
|
+
lastVisible = doc45;
|
|
15602
15898
|
});
|
|
15603
15899
|
return {
|
|
15604
15900
|
templates,
|
|
@@ -15640,9 +15936,9 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15640
15936
|
const querySnapshot = await getDocs27(q);
|
|
15641
15937
|
const templates = [];
|
|
15642
15938
|
let lastVisible = null;
|
|
15643
|
-
querySnapshot.forEach((
|
|
15644
|
-
templates.push(
|
|
15645
|
-
lastVisible =
|
|
15939
|
+
querySnapshot.forEach((doc45) => {
|
|
15940
|
+
templates.push(doc45.data());
|
|
15941
|
+
lastVisible = doc45;
|
|
15646
15942
|
});
|
|
15647
15943
|
return {
|
|
15648
15944
|
templates,
|
|
@@ -15682,8 +15978,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15682
15978
|
);
|
|
15683
15979
|
const querySnapshot = await getDocs27(q);
|
|
15684
15980
|
const templates = [];
|
|
15685
|
-
querySnapshot.forEach((
|
|
15686
|
-
templates.push(
|
|
15981
|
+
querySnapshot.forEach((doc45) => {
|
|
15982
|
+
templates.push(doc45.data());
|
|
15687
15983
|
});
|
|
15688
15984
|
return templates;
|
|
15689
15985
|
}
|
|
@@ -15708,9 +16004,9 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15708
16004
|
const querySnapshot = await getDocs27(q);
|
|
15709
16005
|
const templates = [];
|
|
15710
16006
|
let lastVisible = null;
|
|
15711
|
-
querySnapshot.forEach((
|
|
15712
|
-
templates.push(
|
|
15713
|
-
lastVisible =
|
|
16007
|
+
querySnapshot.forEach((doc45) => {
|
|
16008
|
+
templates.push(doc45.data());
|
|
16009
|
+
lastVisible = doc45;
|
|
15714
16010
|
});
|
|
15715
16011
|
return {
|
|
15716
16012
|
templates,
|
|
@@ -15737,9 +16033,9 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15737
16033
|
const querySnapshot = await getDocs27(q);
|
|
15738
16034
|
const templates = [];
|
|
15739
16035
|
let lastVisible = null;
|
|
15740
|
-
querySnapshot.forEach((
|
|
15741
|
-
templates.push(
|
|
15742
|
-
lastVisible =
|
|
16036
|
+
querySnapshot.forEach((doc45) => {
|
|
16037
|
+
templates.push(doc45.data());
|
|
16038
|
+
lastVisible = doc45;
|
|
15743
16039
|
});
|
|
15744
16040
|
return {
|
|
15745
16041
|
templates,
|
|
@@ -15765,8 +16061,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15765
16061
|
}
|
|
15766
16062
|
const querySnapshot = await getDocs27(q);
|
|
15767
16063
|
const templates = [];
|
|
15768
|
-
querySnapshot.forEach((
|
|
15769
|
-
templates.push(
|
|
16064
|
+
querySnapshot.forEach((doc45) => {
|
|
16065
|
+
templates.push(doc45.data());
|
|
15770
16066
|
});
|
|
15771
16067
|
return templates;
|
|
15772
16068
|
}
|
|
@@ -15775,8 +16071,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15775
16071
|
// src/services/documentation-templates/filled-document.service.ts
|
|
15776
16072
|
import {
|
|
15777
16073
|
collection as collection28,
|
|
15778
|
-
doc as
|
|
15779
|
-
getDoc as
|
|
16074
|
+
doc as doc34,
|
|
16075
|
+
getDoc as getDoc35,
|
|
15780
16076
|
getDocs as getDocs28,
|
|
15781
16077
|
setDoc as setDoc26,
|
|
15782
16078
|
updateDoc as updateDoc31,
|
|
@@ -15839,7 +16135,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
15839
16135
|
values: initialValues,
|
|
15840
16136
|
status: initialStatus
|
|
15841
16137
|
};
|
|
15842
|
-
const docRef =
|
|
16138
|
+
const docRef = doc34(
|
|
15843
16139
|
this.db,
|
|
15844
16140
|
APPOINTMENTS_COLLECTION,
|
|
15845
16141
|
// Replaced "appointments"
|
|
@@ -15859,7 +16155,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
15859
16155
|
*/
|
|
15860
16156
|
async getFilledDocumentFromAppointmentById(appointmentId, formId, isUserForm) {
|
|
15861
16157
|
const formSubcollection = this.getFormSubcollectionPath(isUserForm);
|
|
15862
|
-
const docRef =
|
|
16158
|
+
const docRef = doc34(
|
|
15863
16159
|
this.db,
|
|
15864
16160
|
APPOINTMENTS_COLLECTION,
|
|
15865
16161
|
// Replaced "appointments"
|
|
@@ -15867,7 +16163,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
15867
16163
|
formSubcollection,
|
|
15868
16164
|
formId
|
|
15869
16165
|
);
|
|
15870
|
-
const docSnap = await
|
|
16166
|
+
const docSnap = await getDoc35(docRef);
|
|
15871
16167
|
if (!docSnap.exists()) {
|
|
15872
16168
|
return null;
|
|
15873
16169
|
}
|
|
@@ -15884,7 +16180,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
15884
16180
|
*/
|
|
15885
16181
|
async updateFilledDocumentInAppointment(appointmentId, formId, isUserForm, values, status) {
|
|
15886
16182
|
const formSubcollection = this.getFormSubcollectionPath(isUserForm);
|
|
15887
|
-
const docRef =
|
|
16183
|
+
const docRef = doc34(
|
|
15888
16184
|
this.db,
|
|
15889
16185
|
APPOINTMENTS_COLLECTION,
|
|
15890
16186
|
// Replaced "appointments"
|
|
@@ -15972,9 +16268,9 @@ var FilledDocumentService = class extends BaseService {
|
|
|
15972
16268
|
const querySnapshot = await getDocs28(q);
|
|
15973
16269
|
const documents = [];
|
|
15974
16270
|
let lastVisible = null;
|
|
15975
|
-
querySnapshot.forEach((
|
|
15976
|
-
documents.push(
|
|
15977
|
-
lastVisible =
|
|
16271
|
+
querySnapshot.forEach((doc45) => {
|
|
16272
|
+
documents.push(doc45.data());
|
|
16273
|
+
lastVisible = doc45;
|
|
15978
16274
|
});
|
|
15979
16275
|
return {
|
|
15980
16276
|
documents,
|
|
@@ -16135,8 +16431,8 @@ var FilledDocumentService = class extends BaseService {
|
|
|
16135
16431
|
// src/services/notifications/notification.service.ts
|
|
16136
16432
|
import {
|
|
16137
16433
|
collection as collection29,
|
|
16138
|
-
doc as
|
|
16139
|
-
getDoc as
|
|
16434
|
+
doc as doc35,
|
|
16435
|
+
getDoc as getDoc36,
|
|
16140
16436
|
getDocs as getDocs29,
|
|
16141
16437
|
query as query29,
|
|
16142
16438
|
where as where29,
|
|
@@ -16172,12 +16468,12 @@ var NotificationService = class extends BaseService {
|
|
|
16172
16468
|
* Dohvata notifikaciju po ID-u
|
|
16173
16469
|
*/
|
|
16174
16470
|
async getNotification(notificationId) {
|
|
16175
|
-
const notificationRef =
|
|
16471
|
+
const notificationRef = doc35(
|
|
16176
16472
|
this.db,
|
|
16177
16473
|
NOTIFICATIONS_COLLECTION,
|
|
16178
16474
|
notificationId
|
|
16179
16475
|
);
|
|
16180
|
-
const notificationDoc = await
|
|
16476
|
+
const notificationDoc = await getDoc36(notificationRef);
|
|
16181
16477
|
if (!notificationDoc.exists()) {
|
|
16182
16478
|
return null;
|
|
16183
16479
|
}
|
|
@@ -16196,9 +16492,9 @@ var NotificationService = class extends BaseService {
|
|
|
16196
16492
|
orderBy16("notificationTime", "desc")
|
|
16197
16493
|
);
|
|
16198
16494
|
const querySnapshot = await getDocs29(q);
|
|
16199
|
-
return querySnapshot.docs.map((
|
|
16200
|
-
id:
|
|
16201
|
-
...
|
|
16495
|
+
return querySnapshot.docs.map((doc45) => ({
|
|
16496
|
+
id: doc45.id,
|
|
16497
|
+
...doc45.data()
|
|
16202
16498
|
}));
|
|
16203
16499
|
}
|
|
16204
16500
|
/**
|
|
@@ -16212,16 +16508,16 @@ var NotificationService = class extends BaseService {
|
|
|
16212
16508
|
orderBy16("notificationTime", "desc")
|
|
16213
16509
|
);
|
|
16214
16510
|
const querySnapshot = await getDocs29(q);
|
|
16215
|
-
return querySnapshot.docs.map((
|
|
16216
|
-
id:
|
|
16217
|
-
...
|
|
16511
|
+
return querySnapshot.docs.map((doc45) => ({
|
|
16512
|
+
id: doc45.id,
|
|
16513
|
+
...doc45.data()
|
|
16218
16514
|
}));
|
|
16219
16515
|
}
|
|
16220
16516
|
/**
|
|
16221
16517
|
* Označava notifikaciju kao pročitanu
|
|
16222
16518
|
*/
|
|
16223
16519
|
async markAsRead(notificationId) {
|
|
16224
|
-
const notificationRef =
|
|
16520
|
+
const notificationRef = doc35(
|
|
16225
16521
|
this.db,
|
|
16226
16522
|
NOTIFICATIONS_COLLECTION,
|
|
16227
16523
|
notificationId
|
|
@@ -16238,7 +16534,7 @@ var NotificationService = class extends BaseService {
|
|
|
16238
16534
|
const notifications = await this.getUnreadNotifications(userId);
|
|
16239
16535
|
const batch = writeBatch5(this.db);
|
|
16240
16536
|
notifications.forEach((notification) => {
|
|
16241
|
-
const notificationRef =
|
|
16537
|
+
const notificationRef = doc35(
|
|
16242
16538
|
this.db,
|
|
16243
16539
|
NOTIFICATIONS_COLLECTION,
|
|
16244
16540
|
notification.id
|
|
@@ -16254,7 +16550,7 @@ var NotificationService = class extends BaseService {
|
|
|
16254
16550
|
* Ažurira status notifikacije
|
|
16255
16551
|
*/
|
|
16256
16552
|
async updateNotificationStatus(notificationId, status) {
|
|
16257
|
-
const notificationRef =
|
|
16553
|
+
const notificationRef = doc35(
|
|
16258
16554
|
this.db,
|
|
16259
16555
|
NOTIFICATIONS_COLLECTION,
|
|
16260
16556
|
notificationId
|
|
@@ -16268,7 +16564,7 @@ var NotificationService = class extends BaseService {
|
|
|
16268
16564
|
* Briše notifikaciju
|
|
16269
16565
|
*/
|
|
16270
16566
|
async deleteNotification(notificationId) {
|
|
16271
|
-
const notificationRef =
|
|
16567
|
+
const notificationRef = doc35(
|
|
16272
16568
|
this.db,
|
|
16273
16569
|
NOTIFICATIONS_COLLECTION,
|
|
16274
16570
|
notificationId
|
|
@@ -16286,9 +16582,9 @@ var NotificationService = class extends BaseService {
|
|
|
16286
16582
|
orderBy16("notificationTime", "desc")
|
|
16287
16583
|
);
|
|
16288
16584
|
const querySnapshot = await getDocs29(q);
|
|
16289
|
-
return querySnapshot.docs.map((
|
|
16290
|
-
id:
|
|
16291
|
-
...
|
|
16585
|
+
return querySnapshot.docs.map((doc45) => ({
|
|
16586
|
+
id: doc45.id,
|
|
16587
|
+
...doc45.data()
|
|
16292
16588
|
}));
|
|
16293
16589
|
}
|
|
16294
16590
|
/**
|
|
@@ -16301,9 +16597,9 @@ var NotificationService = class extends BaseService {
|
|
|
16301
16597
|
orderBy16("notificationTime", "desc")
|
|
16302
16598
|
);
|
|
16303
16599
|
const querySnapshot = await getDocs29(q);
|
|
16304
|
-
return querySnapshot.docs.map((
|
|
16305
|
-
id:
|
|
16306
|
-
...
|
|
16600
|
+
return querySnapshot.docs.map((doc45) => ({
|
|
16601
|
+
id: doc45.id,
|
|
16602
|
+
...doc45.data()
|
|
16307
16603
|
}));
|
|
16308
16604
|
}
|
|
16309
16605
|
};
|
|
@@ -16314,13 +16610,13 @@ import {
|
|
|
16314
16610
|
getDocs as getDocs30,
|
|
16315
16611
|
query as query30,
|
|
16316
16612
|
where as where30,
|
|
16317
|
-
doc as
|
|
16613
|
+
doc as doc36,
|
|
16318
16614
|
updateDoc as updateDoc33,
|
|
16319
16615
|
Timestamp as Timestamp31,
|
|
16320
16616
|
orderBy as orderBy17,
|
|
16321
16617
|
limit as limit15,
|
|
16322
16618
|
startAfter as startAfter13,
|
|
16323
|
-
getDoc as
|
|
16619
|
+
getDoc as getDoc37
|
|
16324
16620
|
} from "firebase/firestore";
|
|
16325
16621
|
var PatientRequirementsService = class extends BaseService {
|
|
16326
16622
|
constructor(db, auth, app) {
|
|
@@ -16333,7 +16629,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
16333
16629
|
);
|
|
16334
16630
|
}
|
|
16335
16631
|
getPatientRequirementDocRef(patientId, instanceId) {
|
|
16336
|
-
return
|
|
16632
|
+
return doc36(
|
|
16337
16633
|
this.getPatientRequirementsCollectionRef(patientId),
|
|
16338
16634
|
instanceId
|
|
16339
16635
|
);
|
|
@@ -16346,7 +16642,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
16346
16642
|
*/
|
|
16347
16643
|
async getPatientRequirementInstance(patientId, instanceId) {
|
|
16348
16644
|
const docRef = this.getPatientRequirementDocRef(patientId, instanceId);
|
|
16349
|
-
const docSnap = await
|
|
16645
|
+
const docSnap = await getDoc37(docRef);
|
|
16350
16646
|
if (!docSnap.exists()) {
|
|
16351
16647
|
return null;
|
|
16352
16648
|
}
|
|
@@ -16423,7 +16719,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
16423
16719
|
*/
|
|
16424
16720
|
async completeInstruction(patientId, instanceId, instructionId) {
|
|
16425
16721
|
const instanceRef = this.getPatientRequirementDocRef(patientId, instanceId);
|
|
16426
|
-
const instanceSnap = await
|
|
16722
|
+
const instanceSnap = await getDoc37(instanceRef);
|
|
16427
16723
|
if (!instanceSnap.exists()) {
|
|
16428
16724
|
throw new Error(
|
|
16429
16725
|
`PatientRequirementInstance ${instanceId} not found for patient ${patientId}.`
|
|
@@ -16493,8 +16789,8 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
16493
16789
|
// src/services/procedure/procedure.service.ts
|
|
16494
16790
|
import {
|
|
16495
16791
|
collection as collection31,
|
|
16496
|
-
doc as
|
|
16497
|
-
getDoc as
|
|
16792
|
+
doc as doc37,
|
|
16793
|
+
getDoc as getDoc38,
|
|
16498
16794
|
getDocs as getDocs31,
|
|
16499
16795
|
query as query31,
|
|
16500
16796
|
where as where31,
|
|
@@ -16771,14 +17067,14 @@ var ProcedureService = class extends BaseService {
|
|
|
16771
17067
|
if (!isProductFree && !product) {
|
|
16772
17068
|
throw new Error("Product not found for regular procedure");
|
|
16773
17069
|
}
|
|
16774
|
-
const clinicRef =
|
|
16775
|
-
const clinicSnapshot = await
|
|
17070
|
+
const clinicRef = doc37(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId);
|
|
17071
|
+
const clinicSnapshot = await getDoc38(clinicRef);
|
|
16776
17072
|
if (!clinicSnapshot.exists()) {
|
|
16777
17073
|
throw new Error(`Clinic with ID ${validatedData.clinicBranchId} not found`);
|
|
16778
17074
|
}
|
|
16779
17075
|
const clinic = clinicSnapshot.data();
|
|
16780
|
-
const practitionerRef =
|
|
16781
|
-
const practitionerSnapshot = await
|
|
17076
|
+
const practitionerRef = doc37(this.db, PRACTITIONERS_COLLECTION, validatedData.practitionerId);
|
|
17077
|
+
const practitionerSnapshot = await getDoc38(practitionerRef);
|
|
16782
17078
|
if (!practitionerSnapshot.exists()) {
|
|
16783
17079
|
throw new Error(`Practitioner with ID ${validatedData.practitionerId} not found`);
|
|
16784
17080
|
}
|
|
@@ -16867,13 +17163,13 @@ var ProcedureService = class extends BaseService {
|
|
|
16867
17163
|
throw new Error(`Cannot write procedure with undefined fields: ${undefinedFields.join(", ")}`);
|
|
16868
17164
|
}
|
|
16869
17165
|
console.log("\u{1F525}\u{1F525}\u{1F525} NO UNDEFINED FIELDS - Proceeding with setDoc");
|
|
16870
|
-
const procedureRef =
|
|
17166
|
+
const procedureRef = doc37(this.db, PROCEDURES_COLLECTION, procedureId);
|
|
16871
17167
|
await setDoc27(procedureRef, {
|
|
16872
17168
|
...newProcedure,
|
|
16873
17169
|
createdAt: serverTimestamp31(),
|
|
16874
17170
|
updatedAt: serverTimestamp31()
|
|
16875
17171
|
});
|
|
16876
|
-
const savedDoc = await
|
|
17172
|
+
const savedDoc = await getDoc38(procedureRef);
|
|
16877
17173
|
return savedDoc.data();
|
|
16878
17174
|
}
|
|
16879
17175
|
/**
|
|
@@ -16902,7 +17198,7 @@ var ProcedureService = class extends BaseService {
|
|
|
16902
17198
|
this.productService.getById(validatedData.technologyId, validatedData.productId)
|
|
16903
17199
|
);
|
|
16904
17200
|
}
|
|
16905
|
-
const clinicSnapshotPromise =
|
|
17201
|
+
const clinicSnapshotPromise = getDoc38(doc37(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId));
|
|
16906
17202
|
const [baseResults, clinicSnapshot] = await Promise.all([
|
|
16907
17203
|
Promise.all(baseEntitiesPromises),
|
|
16908
17204
|
clinicSnapshotPromise
|
|
@@ -16942,8 +17238,8 @@ var ProcedureService = class extends BaseService {
|
|
|
16942
17238
|
where31(documentId2(), "in", chunk)
|
|
16943
17239
|
);
|
|
16944
17240
|
const practitionersSnapshot = await getDocs31(practitionersQuery);
|
|
16945
|
-
practitionersSnapshot.docs.forEach((
|
|
16946
|
-
practitionersMap.set(
|
|
17241
|
+
practitionersSnapshot.docs.forEach((doc45) => {
|
|
17242
|
+
practitionersMap.set(doc45.id, doc45.data());
|
|
16947
17243
|
});
|
|
16948
17244
|
}
|
|
16949
17245
|
if (practitionersMap.size !== practitionerIds.length) {
|
|
@@ -16973,7 +17269,7 @@ var ProcedureService = class extends BaseService {
|
|
|
16973
17269
|
};
|
|
16974
17270
|
const procedureId = this.generateId();
|
|
16975
17271
|
createdProcedureIds.push(procedureId);
|
|
16976
|
-
const procedureRef =
|
|
17272
|
+
const procedureRef = doc37(this.db, PROCEDURES_COLLECTION, procedureId);
|
|
16977
17273
|
const { productsMetadata: _, productId: __, photos: ___, ...validatedDataWithoutProductsMetadata } = validatedData;
|
|
16978
17274
|
const newProcedure = {
|
|
16979
17275
|
id: procedureId,
|
|
@@ -17038,8 +17334,8 @@ var ProcedureService = class extends BaseService {
|
|
|
17038
17334
|
const chunk = createdProcedureIds.slice(i, i + 30);
|
|
17039
17335
|
const q = query31(collection31(this.db, PROCEDURES_COLLECTION), where31(documentId2(), "in", chunk));
|
|
17040
17336
|
const snapshot = await getDocs31(q);
|
|
17041
|
-
snapshot.forEach((
|
|
17042
|
-
fetchedProcedures.push(
|
|
17337
|
+
snapshot.forEach((doc45) => {
|
|
17338
|
+
fetchedProcedures.push(doc45.data());
|
|
17043
17339
|
});
|
|
17044
17340
|
}
|
|
17045
17341
|
return fetchedProcedures;
|
|
@@ -17050,8 +17346,8 @@ var ProcedureService = class extends BaseService {
|
|
|
17050
17346
|
* @returns The procedure if found, null otherwise
|
|
17051
17347
|
*/
|
|
17052
17348
|
async getProcedure(id) {
|
|
17053
|
-
const docRef =
|
|
17054
|
-
const docSnap = await
|
|
17349
|
+
const docRef = doc37(this.db, PROCEDURES_COLLECTION, id);
|
|
17350
|
+
const docSnap = await getDoc38(docRef);
|
|
17055
17351
|
if (!docSnap.exists()) {
|
|
17056
17352
|
return null;
|
|
17057
17353
|
}
|
|
@@ -17069,7 +17365,7 @@ var ProcedureService = class extends BaseService {
|
|
|
17069
17365
|
where31("isActive", "==", true)
|
|
17070
17366
|
);
|
|
17071
17367
|
const snapshot = await getDocs31(q);
|
|
17072
|
-
return snapshot.docs.map((
|
|
17368
|
+
return snapshot.docs.map((doc45) => doc45.data());
|
|
17073
17369
|
}
|
|
17074
17370
|
/**
|
|
17075
17371
|
* Gets all procedures for a practitioner
|
|
@@ -17083,7 +17379,7 @@ var ProcedureService = class extends BaseService {
|
|
|
17083
17379
|
where31("isActive", "==", true)
|
|
17084
17380
|
);
|
|
17085
17381
|
const snapshot = await getDocs31(q);
|
|
17086
|
-
return snapshot.docs.map((
|
|
17382
|
+
return snapshot.docs.map((doc45) => doc45.data());
|
|
17087
17383
|
}
|
|
17088
17384
|
/**
|
|
17089
17385
|
* Gets all inactive procedures for a practitioner
|
|
@@ -17097,7 +17393,7 @@ var ProcedureService = class extends BaseService {
|
|
|
17097
17393
|
where31("isActive", "==", false)
|
|
17098
17394
|
);
|
|
17099
17395
|
const snapshot = await getDocs31(q);
|
|
17100
|
-
return snapshot.docs.map((
|
|
17396
|
+
return snapshot.docs.map((doc45) => doc45.data());
|
|
17101
17397
|
}
|
|
17102
17398
|
/**
|
|
17103
17399
|
* Updates a procedure
|
|
@@ -17108,8 +17404,8 @@ var ProcedureService = class extends BaseService {
|
|
|
17108
17404
|
async updateProcedure(id, data) {
|
|
17109
17405
|
var _a, _b, _c;
|
|
17110
17406
|
const validatedData = updateProcedureSchema.parse(data);
|
|
17111
|
-
const procedureRef =
|
|
17112
|
-
const procedureSnapshot = await
|
|
17407
|
+
const procedureRef = doc37(this.db, PROCEDURES_COLLECTION, id);
|
|
17408
|
+
const procedureSnapshot = await getDoc38(procedureRef);
|
|
17113
17409
|
if (!procedureSnapshot.exists()) {
|
|
17114
17410
|
throw new Error(`Procedure with ID ${id} not found`);
|
|
17115
17411
|
}
|
|
@@ -17152,12 +17448,12 @@ var ProcedureService = class extends BaseService {
|
|
|
17152
17448
|
}
|
|
17153
17449
|
if (validatedData.practitionerId && validatedData.practitionerId !== oldPractitionerId) {
|
|
17154
17450
|
practitionerChanged = true;
|
|
17155
|
-
const newPractitionerRef =
|
|
17451
|
+
const newPractitionerRef = doc37(
|
|
17156
17452
|
this.db,
|
|
17157
17453
|
PRACTITIONERS_COLLECTION,
|
|
17158
17454
|
validatedData.practitionerId
|
|
17159
17455
|
);
|
|
17160
|
-
const newPractitionerSnap = await
|
|
17456
|
+
const newPractitionerSnap = await getDoc38(newPractitionerRef);
|
|
17161
17457
|
if (!newPractitionerSnap.exists())
|
|
17162
17458
|
throw new Error(`New Practitioner ${validatedData.practitionerId} not found`);
|
|
17163
17459
|
newPractitioner = newPractitionerSnap.data();
|
|
@@ -17173,8 +17469,8 @@ var ProcedureService = class extends BaseService {
|
|
|
17173
17469
|
}
|
|
17174
17470
|
if (validatedData.clinicBranchId && validatedData.clinicBranchId !== oldClinicId) {
|
|
17175
17471
|
clinicChanged = true;
|
|
17176
|
-
const newClinicRef =
|
|
17177
|
-
const newClinicSnap = await
|
|
17472
|
+
const newClinicRef = doc37(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId);
|
|
17473
|
+
const newClinicSnap = await getDoc38(newClinicRef);
|
|
17178
17474
|
if (!newClinicSnap.exists())
|
|
17179
17475
|
throw new Error(`New Clinic ${validatedData.clinicBranchId} not found`);
|
|
17180
17476
|
newClinic = newClinicSnap.data();
|
|
@@ -17240,7 +17536,7 @@ var ProcedureService = class extends BaseService {
|
|
|
17240
17536
|
...updatedProcedureData,
|
|
17241
17537
|
updatedAt: serverTimestamp31()
|
|
17242
17538
|
});
|
|
17243
|
-
const updatedSnapshot = await
|
|
17539
|
+
const updatedSnapshot = await getDoc38(procedureRef);
|
|
17244
17540
|
return updatedSnapshot.data();
|
|
17245
17541
|
}
|
|
17246
17542
|
/**
|
|
@@ -17248,8 +17544,8 @@ var ProcedureService = class extends BaseService {
|
|
|
17248
17544
|
* @param id - The ID of the procedure to deactivate
|
|
17249
17545
|
*/
|
|
17250
17546
|
async deactivateProcedure(id) {
|
|
17251
|
-
const procedureRef =
|
|
17252
|
-
const procedureSnap = await
|
|
17547
|
+
const procedureRef = doc37(this.db, PROCEDURES_COLLECTION, id);
|
|
17548
|
+
const procedureSnap = await getDoc38(procedureRef);
|
|
17253
17549
|
if (!procedureSnap.exists()) {
|
|
17254
17550
|
console.warn(`Procedure ${id} not found for deactivation.`);
|
|
17255
17551
|
return;
|
|
@@ -17265,8 +17561,8 @@ var ProcedureService = class extends BaseService {
|
|
|
17265
17561
|
* @returns A boolean indicating if the deletion was successful
|
|
17266
17562
|
*/
|
|
17267
17563
|
async deleteProcedure(id) {
|
|
17268
|
-
const procedureRef =
|
|
17269
|
-
const procedureSnapshot = await
|
|
17564
|
+
const procedureRef = doc37(this.db, PROCEDURES_COLLECTION, id);
|
|
17565
|
+
const procedureSnapshot = await getDoc38(procedureRef);
|
|
17270
17566
|
if (!procedureSnapshot.exists()) {
|
|
17271
17567
|
return false;
|
|
17272
17568
|
}
|
|
@@ -17316,11 +17612,11 @@ var ProcedureService = class extends BaseService {
|
|
|
17316
17612
|
}
|
|
17317
17613
|
const proceduresSnapshot = await getDocs31(proceduresQuery);
|
|
17318
17614
|
const lastVisible = proceduresSnapshot.docs[proceduresSnapshot.docs.length - 1];
|
|
17319
|
-
const procedures = proceduresSnapshot.docs.map((
|
|
17320
|
-
const data =
|
|
17615
|
+
const procedures = proceduresSnapshot.docs.map((doc45) => {
|
|
17616
|
+
const data = doc45.data();
|
|
17321
17617
|
return {
|
|
17322
17618
|
...data,
|
|
17323
|
-
id:
|
|
17619
|
+
id: doc45.id
|
|
17324
17620
|
// Ensure ID is present
|
|
17325
17621
|
};
|
|
17326
17622
|
});
|
|
@@ -17439,7 +17735,7 @@ var ProcedureService = class extends BaseService {
|
|
|
17439
17735
|
const q = query31(collection31(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
17440
17736
|
const querySnapshot = await getDocs31(q);
|
|
17441
17737
|
const procedures = querySnapshot.docs.map(
|
|
17442
|
-
(
|
|
17738
|
+
(doc45) => ({ ...doc45.data(), id: doc45.id })
|
|
17443
17739
|
);
|
|
17444
17740
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
17445
17741
|
console.log(`[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures`);
|
|
@@ -17472,7 +17768,7 @@ var ProcedureService = class extends BaseService {
|
|
|
17472
17768
|
const q = query31(collection31(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
17473
17769
|
const querySnapshot = await getDocs31(q);
|
|
17474
17770
|
const procedures = querySnapshot.docs.map(
|
|
17475
|
-
(
|
|
17771
|
+
(doc45) => ({ ...doc45.data(), id: doc45.id })
|
|
17476
17772
|
);
|
|
17477
17773
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
17478
17774
|
console.log(`[PROCEDURE_SERVICE] Strategy 2 success: ${procedures.length} procedures`);
|
|
@@ -17503,7 +17799,7 @@ var ProcedureService = class extends BaseService {
|
|
|
17503
17799
|
const q = query31(collection31(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
17504
17800
|
const querySnapshot = await getDocs31(q);
|
|
17505
17801
|
let procedures = querySnapshot.docs.map(
|
|
17506
|
-
(
|
|
17802
|
+
(doc45) => ({ ...doc45.data(), id: doc45.id })
|
|
17507
17803
|
);
|
|
17508
17804
|
procedures = this.applyInMemoryFilters(procedures, filters);
|
|
17509
17805
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
@@ -17531,7 +17827,7 @@ var ProcedureService = class extends BaseService {
|
|
|
17531
17827
|
const q = query31(collection31(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
17532
17828
|
const querySnapshot = await getDocs31(q);
|
|
17533
17829
|
let procedures = querySnapshot.docs.map(
|
|
17534
|
-
(
|
|
17830
|
+
(doc45) => ({ ...doc45.data(), id: doc45.id })
|
|
17535
17831
|
);
|
|
17536
17832
|
procedures = this.applyInMemoryFilters(procedures, filters);
|
|
17537
17833
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
@@ -17750,14 +18046,14 @@ var ProcedureService = class extends BaseService {
|
|
|
17750
18046
|
if (!category || !subcategory || !technology) {
|
|
17751
18047
|
throw new Error("One or more required base entities not found");
|
|
17752
18048
|
}
|
|
17753
|
-
const clinicRef =
|
|
17754
|
-
const clinicSnapshot = await
|
|
18049
|
+
const clinicRef = doc37(this.db, CLINICS_COLLECTION, data.clinicBranchId);
|
|
18050
|
+
const clinicSnapshot = await getDoc38(clinicRef);
|
|
17755
18051
|
if (!clinicSnapshot.exists()) {
|
|
17756
18052
|
throw new Error(`Clinic with ID ${data.clinicBranchId} not found`);
|
|
17757
18053
|
}
|
|
17758
18054
|
const clinic = clinicSnapshot.data();
|
|
17759
|
-
const practitionerRef =
|
|
17760
|
-
const practitionerSnapshot = await
|
|
18055
|
+
const practitionerRef = doc37(this.db, PRACTITIONERS_COLLECTION, data.practitionerId);
|
|
18056
|
+
const practitionerSnapshot = await getDoc38(practitionerRef);
|
|
17761
18057
|
if (!practitionerSnapshot.exists()) {
|
|
17762
18058
|
throw new Error(`Practitioner with ID ${data.practitionerId} not found`);
|
|
17763
18059
|
}
|
|
@@ -17821,13 +18117,13 @@ var ProcedureService = class extends BaseService {
|
|
|
17821
18117
|
},
|
|
17822
18118
|
isActive: true
|
|
17823
18119
|
};
|
|
17824
|
-
const procedureRef =
|
|
18120
|
+
const procedureRef = doc37(this.db, PROCEDURES_COLLECTION, procedureId);
|
|
17825
18121
|
await setDoc27(procedureRef, {
|
|
17826
18122
|
...newProcedure,
|
|
17827
18123
|
createdAt: serverTimestamp31(),
|
|
17828
18124
|
updatedAt: serverTimestamp31()
|
|
17829
18125
|
});
|
|
17830
|
-
const savedDoc = await
|
|
18126
|
+
const savedDoc = await getDoc38(procedureRef);
|
|
17831
18127
|
return savedDoc.data();
|
|
17832
18128
|
}
|
|
17833
18129
|
/**
|
|
@@ -17838,11 +18134,11 @@ var ProcedureService = class extends BaseService {
|
|
|
17838
18134
|
async getProceduresForMap() {
|
|
17839
18135
|
const proceduresRef = collection31(this.db, PROCEDURES_COLLECTION);
|
|
17840
18136
|
const snapshot = await getDocs31(proceduresRef);
|
|
17841
|
-
const proceduresForMap = snapshot.docs.map((
|
|
18137
|
+
const proceduresForMap = snapshot.docs.map((doc45) => {
|
|
17842
18138
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
17843
|
-
const data =
|
|
18139
|
+
const data = doc45.data();
|
|
17844
18140
|
return {
|
|
17845
|
-
id:
|
|
18141
|
+
id: doc45.id,
|
|
17846
18142
|
name: data.name,
|
|
17847
18143
|
clinicId: (_a = data.clinicInfo) == null ? void 0 : _a.id,
|
|
17848
18144
|
clinicName: (_b = data.clinicInfo) == null ? void 0 : _b.name,
|
|
@@ -17864,8 +18160,8 @@ var ProcedureService = class extends BaseService {
|
|
|
17864
18160
|
async getProceduresForConsultation(clinicBranchId, practitionerId, filterByFamily = true, defaultProcedureId) {
|
|
17865
18161
|
let familyToFilter = null;
|
|
17866
18162
|
if (filterByFamily && defaultProcedureId) {
|
|
17867
|
-
const defaultProcedureRef =
|
|
17868
|
-
const defaultProcedureSnap = await
|
|
18163
|
+
const defaultProcedureRef = doc37(this.db, PROCEDURES_COLLECTION, defaultProcedureId);
|
|
18164
|
+
const defaultProcedureSnap = await getDoc38(defaultProcedureRef);
|
|
17869
18165
|
if (defaultProcedureSnap.exists()) {
|
|
17870
18166
|
const defaultProcedure = defaultProcedureSnap.data();
|
|
17871
18167
|
familyToFilter = defaultProcedure.family;
|
|
@@ -17885,9 +18181,9 @@ var ProcedureService = class extends BaseService {
|
|
|
17885
18181
|
orderBy18("name", "asc")
|
|
17886
18182
|
);
|
|
17887
18183
|
const querySnapshot = await getDocs31(proceduresQuery);
|
|
17888
|
-
return querySnapshot.docs.map((
|
|
17889
|
-
id:
|
|
17890
|
-
...
|
|
18184
|
+
return querySnapshot.docs.map((doc45) => ({
|
|
18185
|
+
id: doc45.id,
|
|
18186
|
+
...doc45.data()
|
|
17891
18187
|
}));
|
|
17892
18188
|
}
|
|
17893
18189
|
};
|
|
@@ -17895,8 +18191,8 @@ var ProcedureService = class extends BaseService {
|
|
|
17895
18191
|
// src/services/reviews/reviews.service.ts
|
|
17896
18192
|
import {
|
|
17897
18193
|
collection as collection32,
|
|
17898
|
-
doc as
|
|
17899
|
-
getDoc as
|
|
18194
|
+
doc as doc38,
|
|
18195
|
+
getDoc as getDoc39,
|
|
17900
18196
|
getDocs as getDocs32,
|
|
17901
18197
|
query as query32,
|
|
17902
18198
|
where as where32,
|
|
@@ -17993,7 +18289,7 @@ var ReviewService = class extends BaseService {
|
|
|
17993
18289
|
updatedAt: now
|
|
17994
18290
|
};
|
|
17995
18291
|
reviewSchema.parse(review);
|
|
17996
|
-
const docRef =
|
|
18292
|
+
const docRef = doc38(this.db, REVIEWS_COLLECTION, reviewId);
|
|
17997
18293
|
await setDoc28(docRef, {
|
|
17998
18294
|
...review,
|
|
17999
18295
|
createdAt: serverTimestamp32(),
|
|
@@ -18021,16 +18317,16 @@ var ReviewService = class extends BaseService {
|
|
|
18021
18317
|
async getReview(reviewId) {
|
|
18022
18318
|
var _a, _b, _c;
|
|
18023
18319
|
console.log("\u{1F50D} ReviewService.getReview - Getting review:", reviewId);
|
|
18024
|
-
const docRef =
|
|
18025
|
-
const docSnap = await
|
|
18320
|
+
const docRef = doc38(this.db, REVIEWS_COLLECTION, reviewId);
|
|
18321
|
+
const docSnap = await getDoc39(docRef);
|
|
18026
18322
|
if (!docSnap.exists()) {
|
|
18027
18323
|
console.log("\u274C ReviewService.getReview - Review not found:", reviewId);
|
|
18028
18324
|
return null;
|
|
18029
18325
|
}
|
|
18030
18326
|
const review = { ...docSnap.data(), id: reviewId };
|
|
18031
18327
|
try {
|
|
18032
|
-
const appointmentDoc = await
|
|
18033
|
-
|
|
18328
|
+
const appointmentDoc = await getDoc39(
|
|
18329
|
+
doc38(this.db, APPOINTMENTS_COLLECTION, review.appointmentId)
|
|
18034
18330
|
);
|
|
18035
18331
|
if (appointmentDoc.exists()) {
|
|
18036
18332
|
const appointment = appointmentDoc.data();
|
|
@@ -18077,12 +18373,12 @@ var ReviewService = class extends BaseService {
|
|
|
18077
18373
|
async getReviewsByPatient(patientId) {
|
|
18078
18374
|
const q = query32(collection32(this.db, REVIEWS_COLLECTION), where32("patientId", "==", patientId));
|
|
18079
18375
|
const snapshot = await getDocs32(q);
|
|
18080
|
-
const reviews = snapshot.docs.map((
|
|
18376
|
+
const reviews = snapshot.docs.map((doc45) => doc45.data());
|
|
18081
18377
|
const enhancedReviews = await Promise.all(
|
|
18082
18378
|
reviews.map(async (review) => {
|
|
18083
18379
|
try {
|
|
18084
|
-
const appointmentDoc = await
|
|
18085
|
-
|
|
18380
|
+
const appointmentDoc = await getDoc39(
|
|
18381
|
+
doc38(this.db, APPOINTMENTS_COLLECTION, review.appointmentId)
|
|
18086
18382
|
);
|
|
18087
18383
|
if (appointmentDoc.exists()) {
|
|
18088
18384
|
const appointment = appointmentDoc.data();
|
|
@@ -18131,9 +18427,9 @@ var ReviewService = class extends BaseService {
|
|
|
18131
18427
|
where32("clinicReview.clinicId", "==", clinicId)
|
|
18132
18428
|
);
|
|
18133
18429
|
const snapshot = await getDocs32(q);
|
|
18134
|
-
const reviews = snapshot.docs.map((
|
|
18135
|
-
const data =
|
|
18136
|
-
return { ...data, id:
|
|
18430
|
+
const reviews = snapshot.docs.map((doc45) => {
|
|
18431
|
+
const data = doc45.data();
|
|
18432
|
+
return { ...data, id: doc45.id };
|
|
18137
18433
|
});
|
|
18138
18434
|
console.log("\u{1F50D} ReviewService.getReviewsByClinic - Found reviews before enhancement:", {
|
|
18139
18435
|
clinicId,
|
|
@@ -18143,8 +18439,8 @@ var ReviewService = class extends BaseService {
|
|
|
18143
18439
|
const enhancedReviews = await Promise.all(
|
|
18144
18440
|
reviews.map(async (review) => {
|
|
18145
18441
|
try {
|
|
18146
|
-
const appointmentDoc = await
|
|
18147
|
-
|
|
18442
|
+
const appointmentDoc = await getDoc39(
|
|
18443
|
+
doc38(this.db, APPOINTMENTS_COLLECTION, review.appointmentId)
|
|
18148
18444
|
);
|
|
18149
18445
|
if (appointmentDoc.exists()) {
|
|
18150
18446
|
const appointment = appointmentDoc.data();
|
|
@@ -18207,9 +18503,9 @@ var ReviewService = class extends BaseService {
|
|
|
18207
18503
|
where32("practitionerReview.practitionerId", "==", practitionerId)
|
|
18208
18504
|
);
|
|
18209
18505
|
const snapshot = await getDocs32(q);
|
|
18210
|
-
const reviews = snapshot.docs.map((
|
|
18211
|
-
const data =
|
|
18212
|
-
return { ...data, id:
|
|
18506
|
+
const reviews = snapshot.docs.map((doc45) => {
|
|
18507
|
+
const data = doc45.data();
|
|
18508
|
+
return { ...data, id: doc45.id };
|
|
18213
18509
|
});
|
|
18214
18510
|
console.log("\u{1F50D} ReviewService.getReviewsByPractitioner - Found reviews before enhancement:", {
|
|
18215
18511
|
practitionerId,
|
|
@@ -18219,8 +18515,8 @@ var ReviewService = class extends BaseService {
|
|
|
18219
18515
|
const enhancedReviews = await Promise.all(
|
|
18220
18516
|
reviews.map(async (review) => {
|
|
18221
18517
|
try {
|
|
18222
|
-
const appointmentDoc = await
|
|
18223
|
-
|
|
18518
|
+
const appointmentDoc = await getDoc39(
|
|
18519
|
+
doc38(this.db, APPOINTMENTS_COLLECTION, review.appointmentId)
|
|
18224
18520
|
);
|
|
18225
18521
|
if (appointmentDoc.exists()) {
|
|
18226
18522
|
const appointment = appointmentDoc.data();
|
|
@@ -18280,9 +18576,9 @@ var ReviewService = class extends BaseService {
|
|
|
18280
18576
|
where32("procedureReview.procedureId", "==", procedureId)
|
|
18281
18577
|
);
|
|
18282
18578
|
const snapshot = await getDocs32(q);
|
|
18283
|
-
const reviews = snapshot.docs.map((
|
|
18284
|
-
const data =
|
|
18285
|
-
return { ...data, id:
|
|
18579
|
+
const reviews = snapshot.docs.map((doc45) => {
|
|
18580
|
+
const data = doc45.data();
|
|
18581
|
+
return { ...data, id: doc45.id };
|
|
18286
18582
|
});
|
|
18287
18583
|
console.log("\u{1F50D} ReviewService.getReviewsByProcedure - Found reviews before enhancement:", {
|
|
18288
18584
|
procedureId,
|
|
@@ -18292,8 +18588,8 @@ var ReviewService = class extends BaseService {
|
|
|
18292
18588
|
const enhancedReviews = await Promise.all(
|
|
18293
18589
|
reviews.map(async (review) => {
|
|
18294
18590
|
try {
|
|
18295
|
-
const appointmentDoc = await
|
|
18296
|
-
|
|
18591
|
+
const appointmentDoc = await getDoc39(
|
|
18592
|
+
doc38(this.db, APPOINTMENTS_COLLECTION, review.appointmentId)
|
|
18297
18593
|
);
|
|
18298
18594
|
if (appointmentDoc.exists()) {
|
|
18299
18595
|
const appointment = appointmentDoc.data();
|
|
@@ -18366,7 +18662,7 @@ var ReviewService = class extends BaseService {
|
|
|
18366
18662
|
if (!review) {
|
|
18367
18663
|
throw new Error(`Review with ID ${reviewId} not found`);
|
|
18368
18664
|
}
|
|
18369
|
-
await deleteDoc20(
|
|
18665
|
+
await deleteDoc20(doc38(this.db, REVIEWS_COLLECTION, reviewId));
|
|
18370
18666
|
}
|
|
18371
18667
|
/**
|
|
18372
18668
|
* Calculates the average of an array of numbers
|
|
@@ -18440,8 +18736,8 @@ var getFirebaseFunctions = async () => {
|
|
|
18440
18736
|
import {
|
|
18441
18737
|
addDoc as addDoc4,
|
|
18442
18738
|
collection as collection33,
|
|
18443
|
-
doc as
|
|
18444
|
-
getDoc as
|
|
18739
|
+
doc as doc39,
|
|
18740
|
+
getDoc as getDoc40,
|
|
18445
18741
|
getDocs as getDocs33,
|
|
18446
18742
|
query as query33,
|
|
18447
18743
|
updateDoc as updateDoc35,
|
|
@@ -18503,9 +18799,9 @@ var BrandService = class extends BaseService {
|
|
|
18503
18799
|
const q = query33(this.getBrandsRef(), ...constraints);
|
|
18504
18800
|
const snapshot = await getDocs33(q);
|
|
18505
18801
|
const brands = snapshot.docs.map(
|
|
18506
|
-
(
|
|
18507
|
-
id:
|
|
18508
|
-
...
|
|
18802
|
+
(doc45) => ({
|
|
18803
|
+
id: doc45.id,
|
|
18804
|
+
...doc45.data()
|
|
18509
18805
|
})
|
|
18510
18806
|
);
|
|
18511
18807
|
const newLastVisible = snapshot.docs[snapshot.docs.length - 1];
|
|
@@ -18539,9 +18835,9 @@ var BrandService = class extends BaseService {
|
|
|
18539
18835
|
);
|
|
18540
18836
|
const snapshot = await getDocs33(q);
|
|
18541
18837
|
return snapshot.docs.map(
|
|
18542
|
-
(
|
|
18543
|
-
id:
|
|
18544
|
-
...
|
|
18838
|
+
(doc45) => ({
|
|
18839
|
+
id: doc45.id,
|
|
18840
|
+
...doc45.data()
|
|
18545
18841
|
})
|
|
18546
18842
|
);
|
|
18547
18843
|
}
|
|
@@ -18556,7 +18852,7 @@ var BrandService = class extends BaseService {
|
|
|
18556
18852
|
if (brand.name) {
|
|
18557
18853
|
updateData.name_lowercase = brand.name.toLowerCase();
|
|
18558
18854
|
}
|
|
18559
|
-
const docRef =
|
|
18855
|
+
const docRef = doc39(this.getBrandsRef(), brandId);
|
|
18560
18856
|
await updateDoc35(docRef, updateData);
|
|
18561
18857
|
return this.getById(brandId);
|
|
18562
18858
|
}
|
|
@@ -18572,8 +18868,8 @@ var BrandService = class extends BaseService {
|
|
|
18572
18868
|
* Gets a brand by ID
|
|
18573
18869
|
*/
|
|
18574
18870
|
async getById(brandId) {
|
|
18575
|
-
const docRef =
|
|
18576
|
-
const docSnap = await
|
|
18871
|
+
const docRef = doc39(this.getBrandsRef(), brandId);
|
|
18872
|
+
const docSnap = await getDoc40(docRef);
|
|
18577
18873
|
if (!docSnap.exists()) return null;
|
|
18578
18874
|
return {
|
|
18579
18875
|
id: docSnap.id,
|
|
@@ -18653,9 +18949,9 @@ var BrandService = class extends BaseService {
|
|
|
18653
18949
|
import {
|
|
18654
18950
|
addDoc as addDoc5,
|
|
18655
18951
|
collection as collection34,
|
|
18656
|
-
doc as
|
|
18952
|
+
doc as doc40,
|
|
18657
18953
|
getCountFromServer as getCountFromServer4,
|
|
18658
|
-
getDoc as
|
|
18954
|
+
getDoc as getDoc41,
|
|
18659
18955
|
getDocs as getDocs34,
|
|
18660
18956
|
limit as limit18,
|
|
18661
18957
|
orderBy as orderBy20,
|
|
@@ -18719,9 +19015,9 @@ var CategoryService = class extends BaseService {
|
|
|
18719
19015
|
const q = query34(this.categoriesRef, where34("isActive", "==", true));
|
|
18720
19016
|
const snapshot = await getDocs34(q);
|
|
18721
19017
|
return snapshot.docs.map(
|
|
18722
|
-
(
|
|
18723
|
-
id:
|
|
18724
|
-
...
|
|
19018
|
+
(doc45) => ({
|
|
19019
|
+
id: doc45.id,
|
|
19020
|
+
...doc45.data()
|
|
18725
19021
|
})
|
|
18726
19022
|
);
|
|
18727
19023
|
}
|
|
@@ -18739,9 +19035,9 @@ var CategoryService = class extends BaseService {
|
|
|
18739
19035
|
);
|
|
18740
19036
|
const snapshot = await getDocs34(q);
|
|
18741
19037
|
return snapshot.docs.map(
|
|
18742
|
-
(
|
|
18743
|
-
id:
|
|
18744
|
-
...
|
|
19038
|
+
(doc45) => ({
|
|
19039
|
+
id: doc45.id,
|
|
19040
|
+
...doc45.data()
|
|
18745
19041
|
})
|
|
18746
19042
|
);
|
|
18747
19043
|
}
|
|
@@ -18761,9 +19057,9 @@ var CategoryService = class extends BaseService {
|
|
|
18761
19057
|
const q = query34(this.categoriesRef, ...constraints);
|
|
18762
19058
|
const snapshot = await getDocs34(q);
|
|
18763
19059
|
const categories = snapshot.docs.map(
|
|
18764
|
-
(
|
|
18765
|
-
id:
|
|
18766
|
-
...
|
|
19060
|
+
(doc45) => ({
|
|
19061
|
+
id: doc45.id,
|
|
19062
|
+
...doc45.data()
|
|
18767
19063
|
})
|
|
18768
19064
|
);
|
|
18769
19065
|
const newLastVisible = snapshot.docs[snapshot.docs.length - 1];
|
|
@@ -18787,9 +19083,9 @@ var CategoryService = class extends BaseService {
|
|
|
18787
19083
|
const q = query34(this.categoriesRef, ...constraints);
|
|
18788
19084
|
const snapshot = await getDocs34(q);
|
|
18789
19085
|
const categories = snapshot.docs.map(
|
|
18790
|
-
(
|
|
18791
|
-
id:
|
|
18792
|
-
...
|
|
19086
|
+
(doc45) => ({
|
|
19087
|
+
id: doc45.id,
|
|
19088
|
+
...doc45.data()
|
|
18793
19089
|
})
|
|
18794
19090
|
);
|
|
18795
19091
|
const newLastVisible = snapshot.docs[snapshot.docs.length - 1];
|
|
@@ -18806,7 +19102,7 @@ var CategoryService = class extends BaseService {
|
|
|
18806
19102
|
...category,
|
|
18807
19103
|
updatedAt: /* @__PURE__ */ new Date()
|
|
18808
19104
|
};
|
|
18809
|
-
const docRef =
|
|
19105
|
+
const docRef = doc40(this.categoriesRef, id);
|
|
18810
19106
|
await updateDoc36(docRef, updateData);
|
|
18811
19107
|
return this.getById(id);
|
|
18812
19108
|
}
|
|
@@ -18830,8 +19126,8 @@ var CategoryService = class extends BaseService {
|
|
|
18830
19126
|
* @returns Kategorija ili null ako ne postoji
|
|
18831
19127
|
*/
|
|
18832
19128
|
async getById(id) {
|
|
18833
|
-
const docRef =
|
|
18834
|
-
const docSnap = await
|
|
19129
|
+
const docRef = doc40(this.categoriesRef, id);
|
|
19130
|
+
const docSnap = await getDoc41(docRef);
|
|
18835
19131
|
if (!docSnap.exists()) return null;
|
|
18836
19132
|
return {
|
|
18837
19133
|
id: docSnap.id,
|
|
@@ -18911,9 +19207,9 @@ import {
|
|
|
18911
19207
|
collection as collection35,
|
|
18912
19208
|
collectionGroup as collectionGroup2,
|
|
18913
19209
|
deleteDoc as deleteDoc21,
|
|
18914
|
-
doc as
|
|
19210
|
+
doc as doc41,
|
|
18915
19211
|
getCountFromServer as getCountFromServer5,
|
|
18916
|
-
getDoc as
|
|
19212
|
+
getDoc as getDoc42,
|
|
18917
19213
|
getDocs as getDocs35,
|
|
18918
19214
|
limit as limit19,
|
|
18919
19215
|
orderBy as orderBy21,
|
|
@@ -18997,9 +19293,9 @@ var SubcategoryService = class extends BaseService {
|
|
|
18997
19293
|
const q = query35(this.getSubcategoriesRef(categoryId), ...constraints);
|
|
18998
19294
|
const querySnapshot = await getDocs35(q);
|
|
18999
19295
|
const subcategories = querySnapshot.docs.map(
|
|
19000
|
-
(
|
|
19001
|
-
id:
|
|
19002
|
-
...
|
|
19296
|
+
(doc45) => ({
|
|
19297
|
+
id: doc45.id,
|
|
19298
|
+
...doc45.data()
|
|
19003
19299
|
})
|
|
19004
19300
|
);
|
|
19005
19301
|
const newLastVisible = querySnapshot.docs[querySnapshot.docs.length - 1];
|
|
@@ -19027,9 +19323,9 @@ var SubcategoryService = class extends BaseService {
|
|
|
19027
19323
|
);
|
|
19028
19324
|
const querySnapshot = await getDocs35(q);
|
|
19029
19325
|
const subcategories = querySnapshot.docs.map(
|
|
19030
|
-
(
|
|
19031
|
-
id:
|
|
19032
|
-
...
|
|
19326
|
+
(doc45) => ({
|
|
19327
|
+
id: doc45.id,
|
|
19328
|
+
...doc45.data()
|
|
19033
19329
|
})
|
|
19034
19330
|
);
|
|
19035
19331
|
const newLastVisible = querySnapshot.docs[querySnapshot.docs.length - 1];
|
|
@@ -19047,9 +19343,9 @@ var SubcategoryService = class extends BaseService {
|
|
|
19047
19343
|
);
|
|
19048
19344
|
const querySnapshot = await getDocs35(q);
|
|
19049
19345
|
return querySnapshot.docs.map(
|
|
19050
|
-
(
|
|
19051
|
-
id:
|
|
19052
|
-
...
|
|
19346
|
+
(doc45) => ({
|
|
19347
|
+
id: doc45.id,
|
|
19348
|
+
...doc45.data()
|
|
19053
19349
|
})
|
|
19054
19350
|
);
|
|
19055
19351
|
}
|
|
@@ -19064,9 +19360,9 @@ var SubcategoryService = class extends BaseService {
|
|
|
19064
19360
|
);
|
|
19065
19361
|
const querySnapshot = await getDocs35(q);
|
|
19066
19362
|
return querySnapshot.docs.map(
|
|
19067
|
-
(
|
|
19068
|
-
id:
|
|
19069
|
-
...
|
|
19363
|
+
(doc45) => ({
|
|
19364
|
+
id: doc45.id,
|
|
19365
|
+
...doc45.data()
|
|
19070
19366
|
})
|
|
19071
19367
|
);
|
|
19072
19368
|
}
|
|
@@ -19080,11 +19376,11 @@ var SubcategoryService = class extends BaseService {
|
|
|
19080
19376
|
async update(categoryId, subcategoryId, subcategory) {
|
|
19081
19377
|
const newCategoryId = subcategory.categoryId;
|
|
19082
19378
|
if (newCategoryId && newCategoryId !== categoryId) {
|
|
19083
|
-
const oldDocRef =
|
|
19379
|
+
const oldDocRef = doc41(
|
|
19084
19380
|
this.getSubcategoriesRef(categoryId),
|
|
19085
19381
|
subcategoryId
|
|
19086
19382
|
);
|
|
19087
|
-
const docSnap = await
|
|
19383
|
+
const docSnap = await getDoc42(oldDocRef);
|
|
19088
19384
|
if (!docSnap.exists()) {
|
|
19089
19385
|
throw new Error("Subcategory to update does not exist.");
|
|
19090
19386
|
}
|
|
@@ -19098,7 +19394,7 @@ var SubcategoryService = class extends BaseService {
|
|
|
19098
19394
|
// Preserve original creation date
|
|
19099
19395
|
updatedAt: /* @__PURE__ */ new Date()
|
|
19100
19396
|
};
|
|
19101
|
-
const newDocRef =
|
|
19397
|
+
const newDocRef = doc41(
|
|
19102
19398
|
this.getSubcategoriesRef(newCategoryId),
|
|
19103
19399
|
subcategoryId
|
|
19104
19400
|
);
|
|
@@ -19110,7 +19406,7 @@ var SubcategoryService = class extends BaseService {
|
|
|
19110
19406
|
...subcategory,
|
|
19111
19407
|
updatedAt: /* @__PURE__ */ new Date()
|
|
19112
19408
|
};
|
|
19113
|
-
const docRef =
|
|
19409
|
+
const docRef = doc41(this.getSubcategoriesRef(categoryId), subcategoryId);
|
|
19114
19410
|
await updateDoc37(docRef, updateData);
|
|
19115
19411
|
return this.getById(categoryId, subcategoryId);
|
|
19116
19412
|
}
|
|
@@ -19138,8 +19434,8 @@ var SubcategoryService = class extends BaseService {
|
|
|
19138
19434
|
* @returns Podkategorija ili null ako ne postoji
|
|
19139
19435
|
*/
|
|
19140
19436
|
async getById(categoryId, subcategoryId) {
|
|
19141
|
-
const docRef =
|
|
19142
|
-
const docSnap = await
|
|
19437
|
+
const docRef = doc41(this.getSubcategoriesRef(categoryId), subcategoryId);
|
|
19438
|
+
const docSnap = await getDoc42(docRef);
|
|
19143
19439
|
if (!docSnap.exists()) return null;
|
|
19144
19440
|
return {
|
|
19145
19441
|
id: docSnap.id,
|
|
@@ -19220,8 +19516,8 @@ var SubcategoryService = class extends BaseService {
|
|
|
19220
19516
|
import {
|
|
19221
19517
|
addDoc as addDoc7,
|
|
19222
19518
|
collection as collection36,
|
|
19223
|
-
doc as
|
|
19224
|
-
getDoc as
|
|
19519
|
+
doc as doc42,
|
|
19520
|
+
getDoc as getDoc43,
|
|
19225
19521
|
getDocs as getDocs36,
|
|
19226
19522
|
limit as limit20,
|
|
19227
19523
|
orderBy as orderBy22,
|
|
@@ -19275,6 +19571,9 @@ var TechnologyService = class extends BaseService {
|
|
|
19275
19571
|
if (technology.technicalDetails) {
|
|
19276
19572
|
newTechnology.technicalDetails = technology.technicalDetails;
|
|
19277
19573
|
}
|
|
19574
|
+
if (technology.photoTemplate) {
|
|
19575
|
+
newTechnology.photoTemplate = technology.photoTemplate;
|
|
19576
|
+
}
|
|
19278
19577
|
const docRef = await addDoc7(this.technologiesRef, newTechnology);
|
|
19279
19578
|
return { id: docRef.id, ...newTechnology };
|
|
19280
19579
|
}
|
|
@@ -19287,8 +19586,8 @@ var TechnologyService = class extends BaseService {
|
|
|
19287
19586
|
const q = query36(this.technologiesRef, where36("isActive", "==", active));
|
|
19288
19587
|
const snapshot = await getDocs36(q);
|
|
19289
19588
|
const counts = {};
|
|
19290
|
-
snapshot.docs.forEach((
|
|
19291
|
-
const tech =
|
|
19589
|
+
snapshot.docs.forEach((doc45) => {
|
|
19590
|
+
const tech = doc45.data();
|
|
19292
19591
|
counts[tech.subcategoryId] = (counts[tech.subcategoryId] || 0) + 1;
|
|
19293
19592
|
});
|
|
19294
19593
|
return counts;
|
|
@@ -19302,8 +19601,8 @@ var TechnologyService = class extends BaseService {
|
|
|
19302
19601
|
const q = query36(this.technologiesRef, where36("isActive", "==", active));
|
|
19303
19602
|
const snapshot = await getDocs36(q);
|
|
19304
19603
|
const counts = {};
|
|
19305
|
-
snapshot.docs.forEach((
|
|
19306
|
-
const tech =
|
|
19604
|
+
snapshot.docs.forEach((doc45) => {
|
|
19605
|
+
const tech = doc45.data();
|
|
19307
19606
|
counts[tech.categoryId] = (counts[tech.categoryId] || 0) + 1;
|
|
19308
19607
|
});
|
|
19309
19608
|
return counts;
|
|
@@ -19324,9 +19623,9 @@ var TechnologyService = class extends BaseService {
|
|
|
19324
19623
|
const q = query36(this.technologiesRef, ...constraints);
|
|
19325
19624
|
const snapshot = await getDocs36(q);
|
|
19326
19625
|
const technologies = snapshot.docs.map(
|
|
19327
|
-
(
|
|
19328
|
-
id:
|
|
19329
|
-
...
|
|
19626
|
+
(doc45) => ({
|
|
19627
|
+
id: doc45.id,
|
|
19628
|
+
...doc45.data()
|
|
19330
19629
|
})
|
|
19331
19630
|
);
|
|
19332
19631
|
const newLastVisible = snapshot.docs[snapshot.docs.length - 1];
|
|
@@ -19350,9 +19649,9 @@ var TechnologyService = class extends BaseService {
|
|
|
19350
19649
|
const q = query36(this.technologiesRef, ...constraints);
|
|
19351
19650
|
const snapshot = await getDocs36(q);
|
|
19352
19651
|
const technologies = snapshot.docs.map(
|
|
19353
|
-
(
|
|
19354
|
-
id:
|
|
19355
|
-
...
|
|
19652
|
+
(doc45) => ({
|
|
19653
|
+
id: doc45.id,
|
|
19654
|
+
...doc45.data()
|
|
19356
19655
|
})
|
|
19357
19656
|
);
|
|
19358
19657
|
const newLastVisible = snapshot.docs[snapshot.docs.length - 1];
|
|
@@ -19376,9 +19675,9 @@ var TechnologyService = class extends BaseService {
|
|
|
19376
19675
|
const q = query36(this.technologiesRef, ...constraints);
|
|
19377
19676
|
const snapshot = await getDocs36(q);
|
|
19378
19677
|
const technologies = snapshot.docs.map(
|
|
19379
|
-
(
|
|
19380
|
-
id:
|
|
19381
|
-
...
|
|
19678
|
+
(doc45) => ({
|
|
19679
|
+
id: doc45.id,
|
|
19680
|
+
...doc45.data()
|
|
19382
19681
|
})
|
|
19383
19682
|
);
|
|
19384
19683
|
const newLastVisible = snapshot.docs[snapshot.docs.length - 1];
|
|
@@ -19397,8 +19696,15 @@ var TechnologyService = class extends BaseService {
|
|
|
19397
19696
|
delete updateData[key];
|
|
19398
19697
|
}
|
|
19399
19698
|
});
|
|
19699
|
+
if ("photoTemplate" in technology) {
|
|
19700
|
+
if (technology.photoTemplate === null || technology.photoTemplate === "") {
|
|
19701
|
+
updateData.photoTemplate = null;
|
|
19702
|
+
} else if (technology.photoTemplate !== void 0) {
|
|
19703
|
+
updateData.photoTemplate = technology.photoTemplate;
|
|
19704
|
+
}
|
|
19705
|
+
}
|
|
19400
19706
|
updateData.updatedAt = /* @__PURE__ */ new Date();
|
|
19401
|
-
const docRef =
|
|
19707
|
+
const docRef = doc42(this.technologiesRef, id);
|
|
19402
19708
|
const beforeTech = await this.getById(id);
|
|
19403
19709
|
await updateDoc38(docRef, updateData);
|
|
19404
19710
|
const categoryChanged = beforeTech && updateData.categoryId && beforeTech.categoryId !== updateData.categoryId;
|
|
@@ -19433,8 +19739,8 @@ var TechnologyService = class extends BaseService {
|
|
|
19433
19739
|
* @returns The technology or null if it doesn't exist.
|
|
19434
19740
|
*/
|
|
19435
19741
|
async getById(id) {
|
|
19436
|
-
const docRef =
|
|
19437
|
-
const docSnap = await
|
|
19742
|
+
const docRef = doc42(this.technologiesRef, id);
|
|
19743
|
+
const docSnap = await getDoc43(docRef);
|
|
19438
19744
|
if (!docSnap.exists()) return null;
|
|
19439
19745
|
return {
|
|
19440
19746
|
id: docSnap.id,
|
|
@@ -19448,7 +19754,7 @@ var TechnologyService = class extends BaseService {
|
|
|
19448
19754
|
* @returns Ažurirana tehnologija sa novim zahtevom
|
|
19449
19755
|
*/
|
|
19450
19756
|
async addRequirement(technologyId, requirement) {
|
|
19451
|
-
const docRef =
|
|
19757
|
+
const docRef = doc42(this.technologiesRef, technologyId);
|
|
19452
19758
|
const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
|
|
19453
19759
|
await updateDoc38(docRef, {
|
|
19454
19760
|
[requirementType]: arrayUnion9(requirement),
|
|
@@ -19463,7 +19769,7 @@ var TechnologyService = class extends BaseService {
|
|
|
19463
19769
|
* @returns Ažurirana tehnologija bez uklonjenog zahteva
|
|
19464
19770
|
*/
|
|
19465
19771
|
async removeRequirement(technologyId, requirement) {
|
|
19466
|
-
const docRef =
|
|
19772
|
+
const docRef = doc42(this.technologiesRef, technologyId);
|
|
19467
19773
|
const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
|
|
19468
19774
|
await updateDoc38(docRef, {
|
|
19469
19775
|
[requirementType]: arrayRemove8(requirement),
|
|
@@ -19503,7 +19809,7 @@ var TechnologyService = class extends BaseService {
|
|
|
19503
19809
|
* @returns Ažurirana tehnologija
|
|
19504
19810
|
*/
|
|
19505
19811
|
async addBlockingCondition(technologyId, condition) {
|
|
19506
|
-
const docRef =
|
|
19812
|
+
const docRef = doc42(this.technologiesRef, technologyId);
|
|
19507
19813
|
await updateDoc38(docRef, {
|
|
19508
19814
|
blockingConditions: arrayUnion9(condition),
|
|
19509
19815
|
updatedAt: /* @__PURE__ */ new Date()
|
|
@@ -19517,7 +19823,7 @@ var TechnologyService = class extends BaseService {
|
|
|
19517
19823
|
* @returns Ažurirana tehnologija
|
|
19518
19824
|
*/
|
|
19519
19825
|
async removeBlockingCondition(technologyId, condition) {
|
|
19520
|
-
const docRef =
|
|
19826
|
+
const docRef = doc42(this.technologiesRef, technologyId);
|
|
19521
19827
|
await updateDoc38(docRef, {
|
|
19522
19828
|
blockingConditions: arrayRemove8(condition),
|
|
19523
19829
|
updatedAt: /* @__PURE__ */ new Date()
|
|
@@ -19531,7 +19837,7 @@ var TechnologyService = class extends BaseService {
|
|
|
19531
19837
|
* @returns Ažurirana tehnologija
|
|
19532
19838
|
*/
|
|
19533
19839
|
async addContraindication(technologyId, contraindication) {
|
|
19534
|
-
const docRef =
|
|
19840
|
+
const docRef = doc42(this.technologiesRef, technologyId);
|
|
19535
19841
|
const technology = await this.getById(technologyId);
|
|
19536
19842
|
if (!technology) {
|
|
19537
19843
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
@@ -19553,7 +19859,7 @@ var TechnologyService = class extends BaseService {
|
|
|
19553
19859
|
* @returns Ažurirana tehnologija
|
|
19554
19860
|
*/
|
|
19555
19861
|
async removeContraindication(technologyId, contraindication) {
|
|
19556
|
-
const docRef =
|
|
19862
|
+
const docRef = doc42(this.technologiesRef, technologyId);
|
|
19557
19863
|
const technology = await this.getById(technologyId);
|
|
19558
19864
|
if (!technology) {
|
|
19559
19865
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
@@ -19575,7 +19881,7 @@ var TechnologyService = class extends BaseService {
|
|
|
19575
19881
|
* @returns The updated technology
|
|
19576
19882
|
*/
|
|
19577
19883
|
async updateContraindication(technologyId, contraindication) {
|
|
19578
|
-
const docRef =
|
|
19884
|
+
const docRef = doc42(this.technologiesRef, technologyId);
|
|
19579
19885
|
const technology = await this.getById(technologyId);
|
|
19580
19886
|
if (!technology) {
|
|
19581
19887
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
@@ -19603,7 +19909,7 @@ var TechnologyService = class extends BaseService {
|
|
|
19603
19909
|
* @returns Ažurirana tehnologija
|
|
19604
19910
|
*/
|
|
19605
19911
|
async addBenefit(technologyId, benefit) {
|
|
19606
|
-
const docRef =
|
|
19912
|
+
const docRef = doc42(this.technologiesRef, technologyId);
|
|
19607
19913
|
const technology = await this.getById(technologyId);
|
|
19608
19914
|
if (!technology) {
|
|
19609
19915
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
@@ -19625,7 +19931,7 @@ var TechnologyService = class extends BaseService {
|
|
|
19625
19931
|
* @returns Ažurirana tehnologija
|
|
19626
19932
|
*/
|
|
19627
19933
|
async removeBenefit(technologyId, benefit) {
|
|
19628
|
-
const docRef =
|
|
19934
|
+
const docRef = doc42(this.technologiesRef, technologyId);
|
|
19629
19935
|
const technology = await this.getById(technologyId);
|
|
19630
19936
|
if (!technology) {
|
|
19631
19937
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
@@ -19645,7 +19951,7 @@ var TechnologyService = class extends BaseService {
|
|
|
19645
19951
|
* @returns The updated technology
|
|
19646
19952
|
*/
|
|
19647
19953
|
async updateBenefit(technologyId, benefit) {
|
|
19648
|
-
const docRef =
|
|
19954
|
+
const docRef = doc42(this.technologiesRef, technologyId);
|
|
19649
19955
|
const technology = await this.getById(technologyId);
|
|
19650
19956
|
if (!technology) {
|
|
19651
19957
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
@@ -19700,7 +20006,7 @@ var TechnologyService = class extends BaseService {
|
|
|
19700
20006
|
* @returns Ažurirana tehnologija
|
|
19701
20007
|
*/
|
|
19702
20008
|
async updateCertificationRequirement(technologyId, certificationRequirement) {
|
|
19703
|
-
const docRef =
|
|
20009
|
+
const docRef = doc42(this.technologiesRef, technologyId);
|
|
19704
20010
|
await updateDoc38(docRef, {
|
|
19705
20011
|
certificationRequirement,
|
|
19706
20012
|
updatedAt: /* @__PURE__ */ new Date()
|
|
@@ -19802,9 +20108,9 @@ var TechnologyService = class extends BaseService {
|
|
|
19802
20108
|
);
|
|
19803
20109
|
const snapshot = await getDocs36(q);
|
|
19804
20110
|
return snapshot.docs.map(
|
|
19805
|
-
(
|
|
19806
|
-
id:
|
|
19807
|
-
...
|
|
20111
|
+
(doc45) => ({
|
|
20112
|
+
id: doc45.id,
|
|
20113
|
+
...doc45.data()
|
|
19808
20114
|
})
|
|
19809
20115
|
);
|
|
19810
20116
|
}
|
|
@@ -19823,9 +20129,9 @@ var TechnologyService = class extends BaseService {
|
|
|
19823
20129
|
);
|
|
19824
20130
|
const snapshot = await getDocs36(q);
|
|
19825
20131
|
return snapshot.docs.map(
|
|
19826
|
-
(
|
|
19827
|
-
id:
|
|
19828
|
-
...
|
|
20132
|
+
(doc45) => ({
|
|
20133
|
+
id: doc45.id,
|
|
20134
|
+
...doc45.data()
|
|
19829
20135
|
})
|
|
19830
20136
|
);
|
|
19831
20137
|
}
|
|
@@ -19840,9 +20146,9 @@ var TechnologyService = class extends BaseService {
|
|
|
19840
20146
|
);
|
|
19841
20147
|
const snapshot = await getDocs36(q);
|
|
19842
20148
|
return snapshot.docs.map(
|
|
19843
|
-
(
|
|
19844
|
-
id:
|
|
19845
|
-
...
|
|
20149
|
+
(doc45) => ({
|
|
20150
|
+
id: doc45.id,
|
|
20151
|
+
...doc45.data()
|
|
19846
20152
|
})
|
|
19847
20153
|
);
|
|
19848
20154
|
}
|
|
@@ -19856,7 +20162,7 @@ var TechnologyService = class extends BaseService {
|
|
|
19856
20162
|
async assignProducts(technologyId, productIds) {
|
|
19857
20163
|
const batch = writeBatch7(this.db);
|
|
19858
20164
|
for (const productId of productIds) {
|
|
19859
|
-
const productRef =
|
|
20165
|
+
const productRef = doc42(this.db, PRODUCTS_COLLECTION, productId);
|
|
19860
20166
|
batch.update(productRef, {
|
|
19861
20167
|
assignedTechnologyIds: arrayUnion9(technologyId),
|
|
19862
20168
|
updatedAt: /* @__PURE__ */ new Date()
|
|
@@ -19871,7 +20177,7 @@ var TechnologyService = class extends BaseService {
|
|
|
19871
20177
|
async unassignProducts(technologyId, productIds) {
|
|
19872
20178
|
const batch = writeBatch7(this.db);
|
|
19873
20179
|
for (const productId of productIds) {
|
|
19874
|
-
const productRef =
|
|
20180
|
+
const productRef = doc42(this.db, PRODUCTS_COLLECTION, productId);
|
|
19875
20181
|
batch.update(productRef, {
|
|
19876
20182
|
assignedTechnologyIds: arrayRemove8(technologyId),
|
|
19877
20183
|
updatedAt: /* @__PURE__ */ new Date()
|
|
@@ -19892,9 +20198,9 @@ var TechnologyService = class extends BaseService {
|
|
|
19892
20198
|
);
|
|
19893
20199
|
const snapshot = await getDocs36(q);
|
|
19894
20200
|
return snapshot.docs.map(
|
|
19895
|
-
(
|
|
19896
|
-
id:
|
|
19897
|
-
...
|
|
20201
|
+
(doc45) => ({
|
|
20202
|
+
id: doc45.id,
|
|
20203
|
+
...doc45.data()
|
|
19898
20204
|
})
|
|
19899
20205
|
);
|
|
19900
20206
|
}
|
|
@@ -19909,9 +20215,9 @@ var TechnologyService = class extends BaseService {
|
|
|
19909
20215
|
);
|
|
19910
20216
|
const snapshot = await getDocs36(q);
|
|
19911
20217
|
const allProducts = snapshot.docs.map(
|
|
19912
|
-
(
|
|
19913
|
-
id:
|
|
19914
|
-
...
|
|
20218
|
+
(doc45) => ({
|
|
20219
|
+
id: doc45.id,
|
|
20220
|
+
...doc45.data()
|
|
19915
20221
|
})
|
|
19916
20222
|
);
|
|
19917
20223
|
return allProducts.filter(
|
|
@@ -20028,8 +20334,8 @@ var TechnologyService = class extends BaseService {
|
|
|
20028
20334
|
const productsRef = collection36(this.db, TECHNOLOGIES_COLLECTION, technologyId, PRODUCTS_COLLECTION);
|
|
20029
20335
|
const q = query36(productsRef, where36("isActive", "==", true));
|
|
20030
20336
|
const snapshot = await getDocs36(q);
|
|
20031
|
-
return snapshot.docs.map((
|
|
20032
|
-
const product =
|
|
20337
|
+
return snapshot.docs.map((doc45) => {
|
|
20338
|
+
const product = doc45.data();
|
|
20033
20339
|
return product.name || "";
|
|
20034
20340
|
}).filter((name) => name);
|
|
20035
20341
|
} catch (error) {
|
|
@@ -20072,8 +20378,8 @@ import {
|
|
|
20072
20378
|
addDoc as addDoc8,
|
|
20073
20379
|
collection as collection37,
|
|
20074
20380
|
collectionGroup as collectionGroup3,
|
|
20075
|
-
doc as
|
|
20076
|
-
getDoc as
|
|
20381
|
+
doc as doc43,
|
|
20382
|
+
getDoc as getDoc44,
|
|
20077
20383
|
getDocs as getDocs37,
|
|
20078
20384
|
query as query37,
|
|
20079
20385
|
updateDoc as updateDoc39,
|
|
@@ -20141,9 +20447,9 @@ var ProductService = class extends BaseService {
|
|
|
20141
20447
|
const q = query37(collectionGroup3(this.db, PRODUCTS_COLLECTION), ...constraints);
|
|
20142
20448
|
const snapshot = await getDocs37(q);
|
|
20143
20449
|
const products = snapshot.docs.map(
|
|
20144
|
-
(
|
|
20145
|
-
id:
|
|
20146
|
-
...
|
|
20450
|
+
(doc45) => ({
|
|
20451
|
+
id: doc45.id,
|
|
20452
|
+
...doc45.data()
|
|
20147
20453
|
})
|
|
20148
20454
|
);
|
|
20149
20455
|
const newLastVisible = snapshot.docs[snapshot.docs.length - 1];
|
|
@@ -20180,8 +20486,8 @@ var ProductService = class extends BaseService {
|
|
|
20180
20486
|
};
|
|
20181
20487
|
const q = query37(collectionGroup3(this.db, PRODUCTS_COLLECTION), where37("isActive", "==", true));
|
|
20182
20488
|
const snapshot = await getDocs37(q);
|
|
20183
|
-
snapshot.docs.forEach((
|
|
20184
|
-
const product =
|
|
20489
|
+
snapshot.docs.forEach((doc45) => {
|
|
20490
|
+
const product = doc45.data();
|
|
20185
20491
|
if (product.categoryId) {
|
|
20186
20492
|
counts.byCategory[product.categoryId] = (counts.byCategory[product.categoryId] || 0) + 1;
|
|
20187
20493
|
}
|
|
@@ -20205,9 +20511,9 @@ var ProductService = class extends BaseService {
|
|
|
20205
20511
|
);
|
|
20206
20512
|
const snapshot = await getDocs37(q);
|
|
20207
20513
|
return snapshot.docs.map(
|
|
20208
|
-
(
|
|
20209
|
-
id:
|
|
20210
|
-
...
|
|
20514
|
+
(doc45) => ({
|
|
20515
|
+
id: doc45.id,
|
|
20516
|
+
...doc45.data()
|
|
20211
20517
|
})
|
|
20212
20518
|
);
|
|
20213
20519
|
}
|
|
@@ -20227,9 +20533,9 @@ var ProductService = class extends BaseService {
|
|
|
20227
20533
|
const snapshot = await getDocs37(q);
|
|
20228
20534
|
products.push(
|
|
20229
20535
|
...snapshot.docs.map(
|
|
20230
|
-
(
|
|
20231
|
-
id:
|
|
20232
|
-
...
|
|
20536
|
+
(doc45) => ({
|
|
20537
|
+
id: doc45.id,
|
|
20538
|
+
...doc45.data()
|
|
20233
20539
|
})
|
|
20234
20540
|
)
|
|
20235
20541
|
);
|
|
@@ -20244,7 +20550,7 @@ var ProductService = class extends BaseService {
|
|
|
20244
20550
|
...product,
|
|
20245
20551
|
updatedAt: /* @__PURE__ */ new Date()
|
|
20246
20552
|
};
|
|
20247
|
-
const docRef =
|
|
20553
|
+
const docRef = doc43(this.getProductsRef(technologyId), productId);
|
|
20248
20554
|
await updateDoc39(docRef, updateData);
|
|
20249
20555
|
return this.getById(technologyId, productId);
|
|
20250
20556
|
}
|
|
@@ -20260,8 +20566,8 @@ var ProductService = class extends BaseService {
|
|
|
20260
20566
|
* Gets a product by ID
|
|
20261
20567
|
*/
|
|
20262
20568
|
async getById(technologyId, productId) {
|
|
20263
|
-
const docRef =
|
|
20264
|
-
const docSnap = await
|
|
20569
|
+
const docRef = doc43(this.getProductsRef(technologyId), productId);
|
|
20570
|
+
const docSnap = await getDoc44(docRef);
|
|
20265
20571
|
if (!docSnap.exists()) return null;
|
|
20266
20572
|
return {
|
|
20267
20573
|
id: docSnap.id,
|
|
@@ -20303,9 +20609,9 @@ var ProductService = class extends BaseService {
|
|
|
20303
20609
|
const q = query37(this.getTopLevelProductsRef(), ...constraints);
|
|
20304
20610
|
const snapshot = await getDocs37(q);
|
|
20305
20611
|
const products = snapshot.docs.map(
|
|
20306
|
-
(
|
|
20307
|
-
id:
|
|
20308
|
-
...
|
|
20612
|
+
(doc45) => ({
|
|
20613
|
+
id: doc45.id,
|
|
20614
|
+
...doc45.data()
|
|
20309
20615
|
})
|
|
20310
20616
|
);
|
|
20311
20617
|
const newLastVisible = snapshot.docs[snapshot.docs.length - 1];
|
|
@@ -20315,8 +20621,8 @@ var ProductService = class extends BaseService {
|
|
|
20315
20621
|
* Gets a product by ID from the top-level collection
|
|
20316
20622
|
*/
|
|
20317
20623
|
async getByIdTopLevel(productId) {
|
|
20318
|
-
const docRef =
|
|
20319
|
-
const docSnap = await
|
|
20624
|
+
const docRef = doc43(this.getTopLevelProductsRef(), productId);
|
|
20625
|
+
const docSnap = await getDoc44(docRef);
|
|
20320
20626
|
if (!docSnap.exists()) return null;
|
|
20321
20627
|
return {
|
|
20322
20628
|
id: docSnap.id,
|
|
@@ -20331,7 +20637,7 @@ var ProductService = class extends BaseService {
|
|
|
20331
20637
|
...product,
|
|
20332
20638
|
updatedAt: /* @__PURE__ */ new Date()
|
|
20333
20639
|
};
|
|
20334
|
-
const docRef =
|
|
20640
|
+
const docRef = doc43(this.getTopLevelProductsRef(), productId);
|
|
20335
20641
|
await updateDoc39(docRef, updateData);
|
|
20336
20642
|
return this.getByIdTopLevel(productId);
|
|
20337
20643
|
}
|
|
@@ -20347,7 +20653,7 @@ var ProductService = class extends BaseService {
|
|
|
20347
20653
|
* Assigns a product to a technology
|
|
20348
20654
|
*/
|
|
20349
20655
|
async assignToTechnology(productId, technologyId) {
|
|
20350
|
-
const docRef =
|
|
20656
|
+
const docRef = doc43(this.getTopLevelProductsRef(), productId);
|
|
20351
20657
|
await updateDoc39(docRef, {
|
|
20352
20658
|
assignedTechnologyIds: arrayUnion10(technologyId),
|
|
20353
20659
|
updatedAt: /* @__PURE__ */ new Date()
|
|
@@ -20357,7 +20663,7 @@ var ProductService = class extends BaseService {
|
|
|
20357
20663
|
* Unassigns a product from a technology
|
|
20358
20664
|
*/
|
|
20359
20665
|
async unassignFromTechnology(productId, technologyId) {
|
|
20360
|
-
const docRef =
|
|
20666
|
+
const docRef = doc43(this.getTopLevelProductsRef(), productId);
|
|
20361
20667
|
await updateDoc39(docRef, {
|
|
20362
20668
|
assignedTechnologyIds: arrayRemove9(technologyId),
|
|
20363
20669
|
updatedAt: /* @__PURE__ */ new Date()
|
|
@@ -20375,9 +20681,9 @@ var ProductService = class extends BaseService {
|
|
|
20375
20681
|
);
|
|
20376
20682
|
const snapshot = await getDocs37(q);
|
|
20377
20683
|
return snapshot.docs.map(
|
|
20378
|
-
(
|
|
20379
|
-
id:
|
|
20380
|
-
...
|
|
20684
|
+
(doc45) => ({
|
|
20685
|
+
id: doc45.id,
|
|
20686
|
+
...doc45.data()
|
|
20381
20687
|
})
|
|
20382
20688
|
);
|
|
20383
20689
|
}
|
|
@@ -20392,9 +20698,9 @@ var ProductService = class extends BaseService {
|
|
|
20392
20698
|
);
|
|
20393
20699
|
const snapshot = await getDocs37(q);
|
|
20394
20700
|
const allProducts = snapshot.docs.map(
|
|
20395
|
-
(
|
|
20396
|
-
id:
|
|
20397
|
-
...
|
|
20701
|
+
(doc45) => ({
|
|
20702
|
+
id: doc45.id,
|
|
20703
|
+
...doc45.data()
|
|
20398
20704
|
})
|
|
20399
20705
|
);
|
|
20400
20706
|
return allProducts.filter(
|
|
@@ -20416,9 +20722,9 @@ var ProductService = class extends BaseService {
|
|
|
20416
20722
|
);
|
|
20417
20723
|
const snapshot = await getDocs37(q);
|
|
20418
20724
|
return snapshot.docs.map(
|
|
20419
|
-
(
|
|
20420
|
-
id:
|
|
20421
|
-
...
|
|
20725
|
+
(doc45) => ({
|
|
20726
|
+
id: doc45.id,
|
|
20727
|
+
...doc45.data()
|
|
20422
20728
|
})
|
|
20423
20729
|
);
|
|
20424
20730
|
}
|
|
@@ -20509,8 +20815,8 @@ var ProductService = class extends BaseService {
|
|
|
20509
20815
|
import {
|
|
20510
20816
|
arrayRemove as arrayRemove10,
|
|
20511
20817
|
arrayUnion as arrayUnion11,
|
|
20512
|
-
doc as
|
|
20513
|
-
getDoc as
|
|
20818
|
+
doc as doc44,
|
|
20819
|
+
getDoc as getDoc45,
|
|
20514
20820
|
setDoc as setDoc30,
|
|
20515
20821
|
updateDoc as updateDoc40
|
|
20516
20822
|
} from "firebase/firestore";
|
|
@@ -20524,7 +20830,7 @@ var ConstantsService = class extends BaseService {
|
|
|
20524
20830
|
* @type {DocumentReference}
|
|
20525
20831
|
*/
|
|
20526
20832
|
get treatmentBenefitsDocRef() {
|
|
20527
|
-
return
|
|
20833
|
+
return doc44(this.db, ADMIN_CONSTANTS_COLLECTION, TREATMENT_BENEFITS_DOC);
|
|
20528
20834
|
}
|
|
20529
20835
|
/**
|
|
20530
20836
|
* @description Gets the reference to the document holding contraindications.
|
|
@@ -20532,7 +20838,7 @@ var ConstantsService = class extends BaseService {
|
|
|
20532
20838
|
* @type {DocumentReference}
|
|
20533
20839
|
*/
|
|
20534
20840
|
get contraindicationsDocRef() {
|
|
20535
|
-
return
|
|
20841
|
+
return doc44(this.db, ADMIN_CONSTANTS_COLLECTION, CONTRAINDICATIONS_DOC);
|
|
20536
20842
|
}
|
|
20537
20843
|
// =================================================================
|
|
20538
20844
|
// Treatment Benefits
|
|
@@ -20542,7 +20848,7 @@ var ConstantsService = class extends BaseService {
|
|
|
20542
20848
|
* @returns {Promise<TreatmentBenefitDynamic[]>} An array of all treatment benefits.
|
|
20543
20849
|
*/
|
|
20544
20850
|
async getAllBenefitsForFilter() {
|
|
20545
|
-
const docSnap = await
|
|
20851
|
+
const docSnap = await getDoc45(this.treatmentBenefitsDocRef);
|
|
20546
20852
|
if (!docSnap.exists()) {
|
|
20547
20853
|
return [];
|
|
20548
20854
|
}
|
|
@@ -20571,7 +20877,7 @@ var ConstantsService = class extends BaseService {
|
|
|
20571
20877
|
id: this.generateId(),
|
|
20572
20878
|
...benefit
|
|
20573
20879
|
};
|
|
20574
|
-
const docSnap = await
|
|
20880
|
+
const docSnap = await getDoc45(this.treatmentBenefitsDocRef);
|
|
20575
20881
|
if (!docSnap.exists()) {
|
|
20576
20882
|
await setDoc30(this.treatmentBenefitsDocRef, { benefits: [newBenefit] });
|
|
20577
20883
|
} else {
|
|
@@ -20641,7 +20947,7 @@ var ConstantsService = class extends BaseService {
|
|
|
20641
20947
|
* @returns {Promise<ContraindicationDynamic[]>} An array of all contraindications.
|
|
20642
20948
|
*/
|
|
20643
20949
|
async getAllContraindicationsForFilter() {
|
|
20644
|
-
const docSnap = await
|
|
20950
|
+
const docSnap = await getDoc45(this.contraindicationsDocRef);
|
|
20645
20951
|
if (!docSnap.exists()) {
|
|
20646
20952
|
return [];
|
|
20647
20953
|
}
|
|
@@ -20676,7 +20982,7 @@ var ConstantsService = class extends BaseService {
|
|
|
20676
20982
|
id: this.generateId(),
|
|
20677
20983
|
...contraindication
|
|
20678
20984
|
};
|
|
20679
|
-
const docSnap = await
|
|
20985
|
+
const docSnap = await getDoc45(this.contraindicationsDocRef);
|
|
20680
20986
|
if (!docSnap.exists()) {
|
|
20681
20987
|
await setDoc30(this.contraindicationsDocRef, {
|
|
20682
20988
|
contraindications: [newContraindication]
|