@blackcode_sa/metaestetics-api 1.7.22 → 1.7.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -88,6 +88,7 @@ __export(index_exports, {
88
88
  PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME: () => PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME,
89
89
  PATIENT_SENSITIVE_INFO_COLLECTION: () => PATIENT_SENSITIVE_INFO_COLLECTION,
90
90
  PRACTITIONERS_COLLECTION: () => PRACTITIONERS_COLLECTION,
91
+ PRACTITIONER_INVITES_COLLECTION: () => PRACTITIONER_INVITES_COLLECTION,
91
92
  PROCEDURES_COLLECTION: () => PROCEDURES_COLLECTION,
92
93
  PatientInstructionStatus: () => PatientInstructionStatus,
93
94
  PatientRequirementOverallStatus: () => PatientRequirementOverallStatus,
@@ -95,6 +96,8 @@ __export(index_exports, {
95
96
  PatientService: () => PatientService,
96
97
  PaymentStatus: () => PaymentStatus,
97
98
  PracticeType: () => PracticeType,
99
+ PractitionerInviteService: () => PractitionerInviteService,
100
+ PractitionerInviteStatus: () => PractitionerInviteStatus,
98
101
  PractitionerService: () => PractitionerService,
99
102
  PractitionerStatus: () => PractitionerStatus,
100
103
  PractitionerTokenStatus: () => PractitionerTokenStatus,
@@ -703,6 +706,17 @@ var searchAppointmentsSchema = import_zod2.z.object({
703
706
  path: ["endDate"]
704
707
  }
705
708
  );
709
+ var rescheduleAppointmentSchema = import_zod2.z.object({
710
+ appointmentId: import_zod2.z.string().min(MIN_STRING_LENGTH, "Appointment ID is required"),
711
+ newStartTime: import_zod2.z.any().refine(
712
+ (val) => val instanceof Date || (val == null ? void 0 : val._seconds) !== void 0 || (val == null ? void 0 : val.seconds) !== void 0 || typeof val === "number" || typeof val === "string" || val && typeof val.toMillis === "function",
713
+ "New start time must be a valid timestamp, Date object, number, or string"
714
+ ),
715
+ newEndTime: import_zod2.z.any().refine(
716
+ (val) => val instanceof Date || (val == null ? void 0 : val._seconds) !== void 0 || (val == null ? void 0 : val.seconds) !== void 0 || typeof val === "number" || typeof val === "string" || val && typeof val.toMillis === "function",
717
+ "New end time must be a valid timestamp, Date object, number, or string"
718
+ )
719
+ });
706
720
 
707
721
  // src/config/firebase.ts
708
722
  var import_app = require("firebase/app");
@@ -1469,7 +1483,7 @@ var MediaService = class extends BaseService {
1469
1483
  try {
1470
1484
  const querySnapshot = await (0, import_firestore3.getDocs)(finalQuery);
1471
1485
  const mediaList = querySnapshot.docs.map(
1472
- (doc34) => doc34.data()
1486
+ (doc35) => doc35.data()
1473
1487
  );
1474
1488
  console.log(`[MediaService] Found ${mediaList.length} media items.`);
1475
1489
  return mediaList;
@@ -2106,8 +2120,8 @@ var getPatientsByPractitionerUtil = async (db, practitionerId, options) => {
2106
2120
  }
2107
2121
  const patientsSnapshot = await (0, import_firestore8.getDocs)(q);
2108
2122
  const patients = [];
2109
- patientsSnapshot.forEach((doc34) => {
2110
- patients.push(doc34.data());
2123
+ patientsSnapshot.forEach((doc35) => {
2124
+ patients.push(doc35.data());
2111
2125
  });
2112
2126
  console.log(
2113
2127
  `[getPatientsByPractitionerUtil] Found ${patients.length} patients for practitioner ID: ${practitionerId}`
@@ -2337,9 +2351,9 @@ var updateAllergyUtil = async (db, patientId, data, userRef) => {
2337
2351
  });
2338
2352
  };
2339
2353
  var removeAllergyUtil = async (db, patientId, allergyIndex, userRef) => {
2340
- const doc34 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
2341
- if (!doc34.exists()) throw new Error("Medical info not found");
2342
- const medicalInfo = doc34.data();
2354
+ const doc35 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
2355
+ if (!doc35.exists()) throw new Error("Medical info not found");
2356
+ const medicalInfo = doc35.data();
2343
2357
  if (allergyIndex >= medicalInfo.allergies.length) {
2344
2358
  throw new Error("Invalid allergy index");
2345
2359
  }
@@ -2364,9 +2378,9 @@ var addBlockingConditionUtil = async (db, patientId, data, userRef) => {
2364
2378
  var updateBlockingConditionUtil = async (db, patientId, data, userRef) => {
2365
2379
  const validatedData = updateBlockingConditionSchema.parse(data);
2366
2380
  const { conditionIndex, ...updateData } = validatedData;
2367
- const doc34 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
2368
- if (!doc34.exists()) throw new Error("Medical info not found");
2369
- const medicalInfo = doc34.data();
2381
+ const doc35 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
2382
+ if (!doc35.exists()) throw new Error("Medical info not found");
2383
+ const medicalInfo = doc35.data();
2370
2384
  if (conditionIndex >= medicalInfo.blockingConditions.length) {
2371
2385
  throw new Error("Invalid blocking condition index");
2372
2386
  }
@@ -2382,9 +2396,9 @@ var updateBlockingConditionUtil = async (db, patientId, data, userRef) => {
2382
2396
  });
2383
2397
  };
2384
2398
  var removeBlockingConditionUtil = async (db, patientId, conditionIndex, userRef) => {
2385
- const doc34 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
2386
- if (!doc34.exists()) throw new Error("Medical info not found");
2387
- const medicalInfo = doc34.data();
2399
+ const doc35 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
2400
+ if (!doc35.exists()) throw new Error("Medical info not found");
2401
+ const medicalInfo = doc35.data();
2388
2402
  if (conditionIndex >= medicalInfo.blockingConditions.length) {
2389
2403
  throw new Error("Invalid blocking condition index");
2390
2404
  }
@@ -2409,9 +2423,9 @@ var addContraindicationUtil = async (db, patientId, data, userRef) => {
2409
2423
  var updateContraindicationUtil = async (db, patientId, data, userRef) => {
2410
2424
  const validatedData = updateContraindicationSchema.parse(data);
2411
2425
  const { contraindicationIndex, ...updateData } = validatedData;
2412
- const doc34 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
2413
- if (!doc34.exists()) throw new Error("Medical info not found");
2414
- const medicalInfo = doc34.data();
2426
+ const doc35 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
2427
+ if (!doc35.exists()) throw new Error("Medical info not found");
2428
+ const medicalInfo = doc35.data();
2415
2429
  if (contraindicationIndex >= medicalInfo.contraindications.length) {
2416
2430
  throw new Error("Invalid contraindication index");
2417
2431
  }
@@ -2427,9 +2441,9 @@ var updateContraindicationUtil = async (db, patientId, data, userRef) => {
2427
2441
  });
2428
2442
  };
2429
2443
  var removeContraindicationUtil = async (db, patientId, contraindicationIndex, userRef) => {
2430
- const doc34 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
2431
- if (!doc34.exists()) throw new Error("Medical info not found");
2432
- const medicalInfo = doc34.data();
2444
+ const doc35 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
2445
+ if (!doc35.exists()) throw new Error("Medical info not found");
2446
+ const medicalInfo = doc35.data();
2433
2447
  if (contraindicationIndex >= medicalInfo.contraindications.length) {
2434
2448
  throw new Error("Invalid contraindication index");
2435
2449
  }
@@ -2454,9 +2468,9 @@ var addMedicationUtil = async (db, patientId, data, userRef) => {
2454
2468
  var updateMedicationUtil = async (db, patientId, data, userRef) => {
2455
2469
  const validatedData = updateMedicationSchema.parse(data);
2456
2470
  const { medicationIndex, ...updateData } = validatedData;
2457
- const doc34 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
2458
- if (!doc34.exists()) throw new Error("Medical info not found");
2459
- const medicalInfo = doc34.data();
2471
+ const doc35 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
2472
+ if (!doc35.exists()) throw new Error("Medical info not found");
2473
+ const medicalInfo = doc35.data();
2460
2474
  if (medicationIndex >= medicalInfo.currentMedications.length) {
2461
2475
  throw new Error("Invalid medication index");
2462
2476
  }
@@ -2472,9 +2486,9 @@ var updateMedicationUtil = async (db, patientId, data, userRef) => {
2472
2486
  });
2473
2487
  };
2474
2488
  var removeMedicationUtil = async (db, patientId, medicationIndex, userRef) => {
2475
- const doc34 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
2476
- if (!doc34.exists()) throw new Error("Medical info not found");
2477
- const medicalInfo = doc34.data();
2489
+ const doc35 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
2490
+ if (!doc35.exists()) throw new Error("Medical info not found");
2491
+ const medicalInfo = doc35.data();
2478
2492
  if (medicationIndex >= medicalInfo.currentMedications.length) {
2479
2493
  throw new Error("Invalid medication index");
2480
2494
  }
@@ -2753,7 +2767,7 @@ var searchPatientsUtil = async (db, params, requester) => {
2753
2767
  const finalQuery = (0, import_firestore10.query)(patientsCollectionRef, ...constraints);
2754
2768
  const querySnapshot = await (0, import_firestore10.getDocs)(finalQuery);
2755
2769
  const patients = querySnapshot.docs.map(
2756
- (doc34) => doc34.data()
2770
+ (doc35) => doc35.data()
2757
2771
  );
2758
2772
  console.log(
2759
2773
  `[searchPatientsUtil] Found ${patients.length} patients matching criteria.`
@@ -2785,8 +2799,8 @@ var getAllPatientsUtil = async (db, options) => {
2785
2799
  }
2786
2800
  const patientsSnapshot = await (0, import_firestore10.getDocs)(q);
2787
2801
  const patients = [];
2788
- patientsSnapshot.forEach((doc34) => {
2789
- patients.push(doc34.data());
2802
+ patientsSnapshot.forEach((doc35) => {
2803
+ patients.push(doc35.data());
2790
2804
  });
2791
2805
  console.log(`[getAllPatientsUtil] Found ${patients.length} patients`);
2792
2806
  return patients;
@@ -2998,8 +3012,8 @@ var getPatientsByClinicUtil = async (db, clinicId, options) => {
2998
3012
  }
2999
3013
  const patientsSnapshot = await (0, import_firestore13.getDocs)(q);
3000
3014
  const patients = [];
3001
- patientsSnapshot.forEach((doc34) => {
3002
- patients.push(doc34.data());
3015
+ patientsSnapshot.forEach((doc35) => {
3016
+ patients.push(doc35.data());
3003
3017
  });
3004
3018
  console.log(
3005
3019
  `[getPatientsByClinicUtil] Found ${patients.length} patients for clinic ID: ${clinicId}`
@@ -3554,6 +3568,16 @@ var ClinicPhotoTag = /* @__PURE__ */ ((ClinicPhotoTag2) => {
3554
3568
  return ClinicPhotoTag2;
3555
3569
  })(ClinicPhotoTag || {});
3556
3570
 
3571
+ // src/types/clinic/practitioner-invite.types.ts
3572
+ var PRACTITIONER_INVITES_COLLECTION = "practitioner-invites";
3573
+ var PractitionerInviteStatus = /* @__PURE__ */ ((PractitionerInviteStatus2) => {
3574
+ PractitionerInviteStatus2["PENDING"] = "pending";
3575
+ PractitionerInviteStatus2["ACCEPTED"] = "accepted";
3576
+ PractitionerInviteStatus2["REJECTED"] = "rejected";
3577
+ PractitionerInviteStatus2["CANCELLED"] = "cancelled";
3578
+ return PractitionerInviteStatus2;
3579
+ })(PractitionerInviteStatus || {});
3580
+
3557
3581
  // src/types/clinic/index.ts
3558
3582
  var CLINIC_GROUPS_COLLECTION = "clinic_groups";
3559
3583
  var CLINIC_ADMINS_COLLECTION = "clinic_admins";
@@ -4257,7 +4281,7 @@ async function getClinicAdminsByGroup(db, clinicGroupId) {
4257
4281
  (0, import_firestore16.where)("clinicGroupId", "==", clinicGroupId)
4258
4282
  );
4259
4283
  const querySnapshot = await (0, import_firestore16.getDocs)(q);
4260
- return querySnapshot.docs.map((doc34) => doc34.data());
4284
+ return querySnapshot.docs.map((doc35) => doc35.data());
4261
4285
  }
4262
4286
  async function updateClinicAdmin(db, adminId, data) {
4263
4287
  const admin = await getClinicAdmin(db, adminId);
@@ -4994,7 +5018,7 @@ var PractitionerService = class extends BaseService {
4994
5018
  (0, import_firestore18.where)("expiresAt", ">", import_firestore18.Timestamp.now())
4995
5019
  );
4996
5020
  const querySnapshot = await (0, import_firestore18.getDocs)(q);
4997
- return querySnapshot.docs.map((doc34) => doc34.data());
5021
+ return querySnapshot.docs.map((doc35) => doc35.data());
4998
5022
  }
4999
5023
  /**
5000
5024
  * Gets a token by its string value and validates it
@@ -5104,7 +5128,7 @@ var PractitionerService = class extends BaseService {
5104
5128
  (0, import_firestore18.where)("status", "==", "active" /* ACTIVE */)
5105
5129
  );
5106
5130
  const querySnapshot = await (0, import_firestore18.getDocs)(q);
5107
- return querySnapshot.docs.map((doc34) => doc34.data());
5131
+ return querySnapshot.docs.map((doc35) => doc35.data());
5108
5132
  }
5109
5133
  /**
5110
5134
  * Dohvata sve zdravstvene radnike za određenu kliniku
@@ -5116,7 +5140,7 @@ var PractitionerService = class extends BaseService {
5116
5140
  (0, import_firestore18.where)("isActive", "==", true)
5117
5141
  );
5118
5142
  const querySnapshot = await (0, import_firestore18.getDocs)(q);
5119
- return querySnapshot.docs.map((doc34) => doc34.data());
5143
+ return querySnapshot.docs.map((doc35) => doc35.data());
5120
5144
  }
5121
5145
  /**
5122
5146
  * Dohvata sve draft zdravstvene radnike za određenu kliniku sa statusom DRAFT
@@ -5128,7 +5152,7 @@ var PractitionerService = class extends BaseService {
5128
5152
  (0, import_firestore18.where)("status", "==", "draft" /* DRAFT */)
5129
5153
  );
5130
5154
  const querySnapshot = await (0, import_firestore18.getDocs)(q);
5131
- return querySnapshot.docs.map((doc34) => doc34.data());
5155
+ return querySnapshot.docs.map((doc35) => doc35.data());
5132
5156
  }
5133
5157
  /**
5134
5158
  * Updates a practitioner
@@ -5342,7 +5366,7 @@ var PractitionerService = class extends BaseService {
5342
5366
  );
5343
5367
  const querySnapshot = await (0, import_firestore18.getDocs)(q);
5344
5368
  const practitioners = querySnapshot.docs.map(
5345
- (doc34) => doc34.data()
5369
+ (doc35) => doc35.data()
5346
5370
  );
5347
5371
  const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
5348
5372
  return {
@@ -5413,8 +5437,8 @@ var PractitionerService = class extends BaseService {
5413
5437
  console.log(
5414
5438
  `[PRACTITIONER_SERVICE] Found ${querySnapshot.docs.length} practitioners with base query`
5415
5439
  );
5416
- let practitioners = querySnapshot.docs.map((doc34) => {
5417
- return { ...doc34.data(), id: doc34.id };
5440
+ let practitioners = querySnapshot.docs.map((doc35) => {
5441
+ return { ...doc35.data(), id: doc35.id };
5418
5442
  });
5419
5443
  const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
5420
5444
  if (filters.nameSearch && filters.nameSearch.trim() !== "") {
@@ -5671,7 +5695,7 @@ var UserService = class extends BaseService {
5671
5695
  ];
5672
5696
  const q = (0, import_firestore19.query)((0, import_firestore19.collection)(this.db, USERS_COLLECTION), ...constraints);
5673
5697
  const querySnapshot = await (0, import_firestore19.getDocs)(q);
5674
- const users = querySnapshot.docs.map((doc34) => doc34.data());
5698
+ const users = querySnapshot.docs.map((doc35) => doc35.data());
5675
5699
  return Promise.all(users.map((userData) => userSchema.parse(userData)));
5676
5700
  }
5677
5701
  /**
@@ -6035,7 +6059,7 @@ async function getAllActiveGroups(db) {
6035
6059
  (0, import_firestore20.where)("isActive", "==", true)
6036
6060
  );
6037
6061
  const querySnapshot = await (0, import_firestore20.getDocs)(q);
6038
- return querySnapshot.docs.map((doc34) => doc34.data());
6062
+ return querySnapshot.docs.map((doc35) => doc35.data());
6039
6063
  }
6040
6064
  async function updateClinicGroup(db, groupId, data, app) {
6041
6065
  console.log("[CLINIC_GROUP] Updating clinic group", { groupId });
@@ -6475,7 +6499,7 @@ async function getClinicsByGroup(db, groupId) {
6475
6499
  (0, import_firestore21.where)("isActive", "==", true)
6476
6500
  );
6477
6501
  const querySnapshot = await (0, import_firestore21.getDocs)(q);
6478
- return querySnapshot.docs.map((doc34) => doc34.data());
6502
+ return querySnapshot.docs.map((doc35) => doc35.data());
6479
6503
  }
6480
6504
  async function updateClinic(db, clinicId, data, adminId, clinicAdminService, app) {
6481
6505
  console.log("[CLINIC] Starting clinic update", { clinicId, adminId });
@@ -6669,7 +6693,7 @@ async function getClinicsByAdmin(db, adminId, options = {}, clinicAdminService,
6669
6693
  }
6670
6694
  const q = (0, import_firestore21.query)((0, import_firestore21.collection)(db, CLINICS_COLLECTION), ...constraints);
6671
6695
  const querySnapshot = await (0, import_firestore21.getDocs)(q);
6672
- return querySnapshot.docs.map((doc34) => doc34.data());
6696
+ return querySnapshot.docs.map((doc35) => doc35.data());
6673
6697
  }
6674
6698
  async function getActiveClinicsByAdmin(db, adminId, clinicAdminService, clinicGroupService) {
6675
6699
  return getClinicsByAdmin(
@@ -6714,11 +6738,11 @@ async function getAllClinics(db, pagination, lastDoc) {
6714
6738
  }
6715
6739
  const clinicsSnapshot = await (0, import_firestore21.getDocs)(clinicsQuery);
6716
6740
  const lastVisible = clinicsSnapshot.docs[clinicsSnapshot.docs.length - 1];
6717
- const clinics = clinicsSnapshot.docs.map((doc34) => {
6718
- const data = doc34.data();
6741
+ const clinics = clinicsSnapshot.docs.map((doc35) => {
6742
+ const data = doc35.data();
6719
6743
  return {
6720
6744
  ...data,
6721
- id: doc34.id
6745
+ id: doc35.id
6722
6746
  };
6723
6747
  });
6724
6748
  return {
@@ -6745,8 +6769,8 @@ async function getAllClinicsInRange(db, center, rangeInKm, pagination, lastDoc)
6745
6769
  ];
6746
6770
  const q = (0, import_firestore21.query)((0, import_firestore21.collection)(db, CLINICS_COLLECTION), ...constraints);
6747
6771
  const querySnapshot = await (0, import_firestore21.getDocs)(q);
6748
- for (const doc34 of querySnapshot.docs) {
6749
- const clinic = doc34.data();
6772
+ for (const doc35 of querySnapshot.docs) {
6773
+ const clinic = doc35.data();
6750
6774
  const distance = (0, import_geofire_common4.distanceBetween)(
6751
6775
  [center.latitude, center.longitude],
6752
6776
  [clinic.location.latitude, clinic.location.longitude]
@@ -6863,8 +6887,8 @@ async function findClinicsInRadius(db, center, radiusInKm, filters) {
6863
6887
  }
6864
6888
  const q = (0, import_firestore22.query)((0, import_firestore22.collection)(db, CLINICS_COLLECTION), ...constraints);
6865
6889
  const querySnapshot = await (0, import_firestore22.getDocs)(q);
6866
- for (const doc34 of querySnapshot.docs) {
6867
- const clinic = doc34.data();
6890
+ for (const doc35 of querySnapshot.docs) {
6891
+ const clinic = doc35.data();
6868
6892
  const distance = (0, import_geofire_common5.distanceBetween)(
6869
6893
  [center.latitude, center.longitude],
6870
6894
  [clinic.location.latitude, clinic.location.longitude]
@@ -6952,8 +6976,8 @@ async function getClinicsByFilters(db, filters) {
6952
6976
  console.log(
6953
6977
  `[FILTER_UTILS] Found ${querySnapshot.docs.length} clinics in geo bound`
6954
6978
  );
6955
- for (const doc34 of querySnapshot.docs) {
6956
- const clinic = { ...doc34.data(), id: doc34.id };
6979
+ for (const doc35 of querySnapshot.docs) {
6980
+ const clinic = { ...doc35.data(), id: doc35.id };
6957
6981
  const distance = (0, import_geofire_common6.distanceBetween)(
6958
6982
  [center.latitude, center.longitude],
6959
6983
  [clinic.location.latitude, clinic.location.longitude]
@@ -7009,8 +7033,8 @@ async function getClinicsByFilters(db, filters) {
7009
7033
  console.log(
7010
7034
  `[FILTER_UTILS] Found ${querySnapshot.docs.length} clinics with regular query`
7011
7035
  );
7012
- const clinics = querySnapshot.docs.map((doc34) => {
7013
- return { ...doc34.data(), id: doc34.id };
7036
+ const clinics = querySnapshot.docs.map((doc35) => {
7037
+ return { ...doc35.data(), id: doc35.id };
7014
7038
  });
7015
7039
  let filteredClinics = clinics;
7016
7040
  if (filters.center) {
@@ -8444,9 +8468,9 @@ var NotificationService = class extends BaseService {
8444
8468
  (0, import_firestore26.orderBy)("notificationTime", "desc")
8445
8469
  );
8446
8470
  const querySnapshot = await (0, import_firestore26.getDocs)(q);
8447
- return querySnapshot.docs.map((doc34) => ({
8448
- id: doc34.id,
8449
- ...doc34.data()
8471
+ return querySnapshot.docs.map((doc35) => ({
8472
+ id: doc35.id,
8473
+ ...doc35.data()
8450
8474
  }));
8451
8475
  }
8452
8476
  /**
@@ -8460,9 +8484,9 @@ var NotificationService = class extends BaseService {
8460
8484
  (0, import_firestore26.orderBy)("notificationTime", "desc")
8461
8485
  );
8462
8486
  const querySnapshot = await (0, import_firestore26.getDocs)(q);
8463
- return querySnapshot.docs.map((doc34) => ({
8464
- id: doc34.id,
8465
- ...doc34.data()
8487
+ return querySnapshot.docs.map((doc35) => ({
8488
+ id: doc35.id,
8489
+ ...doc35.data()
8466
8490
  }));
8467
8491
  }
8468
8492
  /**
@@ -8534,9 +8558,9 @@ var NotificationService = class extends BaseService {
8534
8558
  (0, import_firestore26.orderBy)("notificationTime", "desc")
8535
8559
  );
8536
8560
  const querySnapshot = await (0, import_firestore26.getDocs)(q);
8537
- return querySnapshot.docs.map((doc34) => ({
8538
- id: doc34.id,
8539
- ...doc34.data()
8561
+ return querySnapshot.docs.map((doc35) => ({
8562
+ id: doc35.id,
8563
+ ...doc35.data()
8540
8564
  }));
8541
8565
  }
8542
8566
  /**
@@ -8549,9 +8573,9 @@ var NotificationService = class extends BaseService {
8549
8573
  (0, import_firestore26.orderBy)("notificationTime", "desc")
8550
8574
  );
8551
8575
  const querySnapshot = await (0, import_firestore26.getDocs)(q);
8552
- return querySnapshot.docs.map((doc34) => ({
8553
- id: doc34.id,
8554
- ...doc34.data()
8576
+ return querySnapshot.docs.map((doc35) => ({
8577
+ id: doc35.id,
8578
+ ...doc35.data()
8555
8579
  }));
8556
8580
  }
8557
8581
  };
@@ -8832,7 +8856,7 @@ var ProcedureService = class extends BaseService {
8832
8856
  (0, import_firestore27.where)("isActive", "==", true)
8833
8857
  );
8834
8858
  const snapshot = await (0, import_firestore27.getDocs)(q);
8835
- return snapshot.docs.map((doc34) => doc34.data());
8859
+ return snapshot.docs.map((doc35) => doc35.data());
8836
8860
  }
8837
8861
  /**
8838
8862
  * Gets all procedures for a practitioner
@@ -8846,7 +8870,7 @@ var ProcedureService = class extends BaseService {
8846
8870
  (0, import_firestore27.where)("isActive", "==", true)
8847
8871
  );
8848
8872
  const snapshot = await (0, import_firestore27.getDocs)(q);
8849
- return snapshot.docs.map((doc34) => doc34.data());
8873
+ return snapshot.docs.map((doc35) => doc35.data());
8850
8874
  }
8851
8875
  /**
8852
8876
  * Updates a procedure
@@ -9037,20 +9061,20 @@ var ProcedureService = class extends BaseService {
9037
9061
  const proceduresCollection = (0, import_firestore27.collection)(this.db, PROCEDURES_COLLECTION);
9038
9062
  let proceduresQuery = (0, import_firestore27.query)(proceduresCollection);
9039
9063
  if (pagination && pagination > 0) {
9040
- const { limit: limit14, startAfter: startAfter13 } = await import("firebase/firestore");
9064
+ const { limit: limit15, startAfter: startAfter13 } = await import("firebase/firestore");
9041
9065
  if (lastDoc) {
9042
9066
  proceduresQuery = (0, import_firestore27.query)(
9043
9067
  proceduresCollection,
9044
9068
  (0, import_firestore27.orderBy)("name"),
9045
9069
  // Use imported orderBy
9046
9070
  startAfter13(lastDoc),
9047
- limit14(pagination)
9071
+ limit15(pagination)
9048
9072
  );
9049
9073
  } else {
9050
9074
  proceduresQuery = (0, import_firestore27.query)(
9051
9075
  proceduresCollection,
9052
9076
  (0, import_firestore27.orderBy)("name"),
9053
- limit14(pagination)
9077
+ limit15(pagination)
9054
9078
  );
9055
9079
  }
9056
9080
  } else {
@@ -9058,11 +9082,11 @@ var ProcedureService = class extends BaseService {
9058
9082
  }
9059
9083
  const proceduresSnapshot = await (0, import_firestore27.getDocs)(proceduresQuery);
9060
9084
  const lastVisible = proceduresSnapshot.docs[proceduresSnapshot.docs.length - 1];
9061
- const procedures = proceduresSnapshot.docs.map((doc34) => {
9062
- const data = doc34.data();
9085
+ const procedures = proceduresSnapshot.docs.map((doc35) => {
9086
+ const data = doc35.data();
9063
9087
  return {
9064
9088
  ...data,
9065
- id: doc34.id
9089
+ id: doc35.id
9066
9090
  // Ensure ID is present
9067
9091
  };
9068
9092
  });
@@ -9144,8 +9168,8 @@ var ProcedureService = class extends BaseService {
9144
9168
  console.log(
9145
9169
  `[PROCEDURE_SERVICE] Found ${querySnapshot.docs.length} procedures in geo bound`
9146
9170
  );
9147
- for (const doc34 of querySnapshot.docs) {
9148
- const procedure = { ...doc34.data(), id: doc34.id };
9171
+ for (const doc35 of querySnapshot.docs) {
9172
+ const procedure = { ...doc35.data(), id: doc35.id };
9149
9173
  const distance = (0, import_geofire_common8.distanceBetween)(
9150
9174
  [center.latitude, center.longitude],
9151
9175
  [
@@ -9196,8 +9220,8 @@ var ProcedureService = class extends BaseService {
9196
9220
  console.log(
9197
9221
  `[PROCEDURE_SERVICE] Found ${querySnapshot.docs.length} procedures with regular query`
9198
9222
  );
9199
- const procedures = querySnapshot.docs.map((doc34) => {
9200
- return { ...doc34.data(), id: doc34.id };
9223
+ const procedures = querySnapshot.docs.map((doc35) => {
9224
+ return { ...doc35.data(), id: doc35.id };
9201
9225
  });
9202
9226
  if (filters.location) {
9203
9227
  const center = filters.location;
@@ -9303,12 +9327,403 @@ var ProcedureService = class extends BaseService {
9303
9327
  }
9304
9328
  };
9305
9329
 
9306
- // src/services/documentation-templates/documentation-template.service.ts
9330
+ // src/services/clinic/practitioner-invite.service.ts
9307
9331
  var import_firestore28 = require("firebase/firestore");
9332
+ var PractitionerInviteService = class extends BaseService {
9333
+ constructor(db, auth, app) {
9334
+ super(db, auth, app);
9335
+ }
9336
+ /**
9337
+ * Creates a new practitioner invite
9338
+ * @param practitionerId - Practitioner ID
9339
+ * @param clinicId - Clinic ID
9340
+ * @param proposedWorkingHours - Proposed working hours
9341
+ * @param invitedBy - Admin ID who creates the invite
9342
+ * @param message - Optional message
9343
+ * @returns Created invite
9344
+ */
9345
+ async createInviteAdmin(practitionerId, clinicId, proposedWorkingHours, invitedBy, message) {
9346
+ try {
9347
+ const inviteId = this.generateId();
9348
+ const [practitioner, clinic] = await Promise.all([
9349
+ this.getPractitionerById(practitionerId),
9350
+ this.getClinicById(clinicId)
9351
+ ]);
9352
+ if (!practitioner) {
9353
+ throw new Error(`Practitioner with ID ${practitionerId} not found`);
9354
+ }
9355
+ if (!clinic) {
9356
+ throw new Error(`Clinic with ID ${clinicId} not found`);
9357
+ }
9358
+ const existingInvite = await this.findExistingInvite(
9359
+ practitionerId,
9360
+ clinicId
9361
+ );
9362
+ if (existingInvite && existingInvite.status === "pending" /* PENDING */) {
9363
+ throw new Error(
9364
+ "There's already a pending invite for this practitioner at this clinic"
9365
+ );
9366
+ }
9367
+ const practitionerInfo = {
9368
+ id: practitioner.id,
9369
+ practitionerPhoto: typeof practitioner.basicInfo.profileImageUrl === "string" ? practitioner.basicInfo.profileImageUrl : null,
9370
+ name: `${practitioner.basicInfo.firstName} ${practitioner.basicInfo.lastName}`,
9371
+ email: practitioner.basicInfo.email,
9372
+ phone: practitioner.basicInfo.phoneNumber || null,
9373
+ certification: practitioner.certification
9374
+ };
9375
+ const clinicInfo = {
9376
+ id: clinic.id,
9377
+ featuredPhoto: typeof clinic.coverPhoto === "string" ? clinic.coverPhoto : "",
9378
+ name: clinic.name,
9379
+ description: clinic.description || null,
9380
+ location: clinic.location,
9381
+ contactInfo: clinic.contactInfo
9382
+ };
9383
+ const inviteData = {
9384
+ practitionerId,
9385
+ clinicId,
9386
+ practitionerInfo,
9387
+ clinicInfo,
9388
+ proposedWorkingHours,
9389
+ invitedBy,
9390
+ message: message || null,
9391
+ status: "pending" /* PENDING */
9392
+ };
9393
+ const now = import_firestore28.Timestamp.now();
9394
+ const invite = {
9395
+ id: inviteId,
9396
+ ...inviteData,
9397
+ status: "pending" /* PENDING */,
9398
+ createdAt: now,
9399
+ updatedAt: now,
9400
+ acceptedAt: null,
9401
+ rejectedAt: null,
9402
+ cancelledAt: null
9403
+ };
9404
+ const docRef = (0, import_firestore28.doc)(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
9405
+ await (0, import_firestore28.setDoc)(docRef, invite);
9406
+ return invite;
9407
+ } catch (error) {
9408
+ console.error(
9409
+ "[PractitionerInviteService] Error creating invite:",
9410
+ error
9411
+ );
9412
+ throw error;
9413
+ }
9414
+ }
9415
+ /**
9416
+ * Gets all invites for a specific doctor/practitioner
9417
+ * @param practitionerId - Practitioner ID
9418
+ * @param statusFilter - Optional status filter
9419
+ * @returns Array of invites
9420
+ */
9421
+ async getAllInvitesDoctor(practitionerId, statusFilter) {
9422
+ try {
9423
+ const constraints = [
9424
+ (0, import_firestore28.where)("practitionerId", "==", practitionerId),
9425
+ (0, import_firestore28.orderBy)("createdAt", "desc")
9426
+ ];
9427
+ if (statusFilter && statusFilter.length > 0) {
9428
+ constraints.push((0, import_firestore28.where)("status", "in", statusFilter));
9429
+ }
9430
+ const q = (0, import_firestore28.query)(
9431
+ (0, import_firestore28.collection)(this.db, PRACTITIONER_INVITES_COLLECTION),
9432
+ ...constraints
9433
+ );
9434
+ const querySnapshot = await (0, import_firestore28.getDocs)(q);
9435
+ return querySnapshot.docs.map((doc35) => doc35.data());
9436
+ } catch (error) {
9437
+ console.error(
9438
+ "[PractitionerInviteService] Error getting doctor invites:",
9439
+ error
9440
+ );
9441
+ throw error;
9442
+ }
9443
+ }
9444
+ /**
9445
+ * Gets all invites for a specific clinic
9446
+ * @param clinicId - Clinic ID
9447
+ * @param statusFilter - Optional status filter
9448
+ * @returns Array of invites
9449
+ */
9450
+ async getAllInvitesClinic(clinicId, statusFilter) {
9451
+ try {
9452
+ const constraints = [
9453
+ (0, import_firestore28.where)("clinicId", "==", clinicId),
9454
+ (0, import_firestore28.orderBy)("createdAt", "desc")
9455
+ ];
9456
+ if (statusFilter && statusFilter.length > 0) {
9457
+ constraints.push((0, import_firestore28.where)("status", "in", statusFilter));
9458
+ }
9459
+ const q = (0, import_firestore28.query)(
9460
+ (0, import_firestore28.collection)(this.db, PRACTITIONER_INVITES_COLLECTION),
9461
+ ...constraints
9462
+ );
9463
+ const querySnapshot = await (0, import_firestore28.getDocs)(q);
9464
+ return querySnapshot.docs.map((doc35) => doc35.data());
9465
+ } catch (error) {
9466
+ console.error(
9467
+ "[PractitionerInviteService] Error getting clinic invites:",
9468
+ error
9469
+ );
9470
+ throw error;
9471
+ }
9472
+ }
9473
+ /**
9474
+ * Doctor accepts an invite
9475
+ * @param inviteId - Invite ID
9476
+ * @returns Updated invite
9477
+ */
9478
+ async acceptInviteDoctor(inviteId) {
9479
+ try {
9480
+ const invite = await this.getInviteById(inviteId);
9481
+ if (!invite) {
9482
+ throw new Error(`Invite with ID ${inviteId} not found`);
9483
+ }
9484
+ if (invite.status !== "pending" /* PENDING */) {
9485
+ throw new Error("Only pending invites can be accepted");
9486
+ }
9487
+ const updateData = {
9488
+ status: "accepted" /* ACCEPTED */,
9489
+ acceptedAt: import_firestore28.Timestamp.now(),
9490
+ updatedAt: (0, import_firestore28.serverTimestamp)()
9491
+ };
9492
+ const docRef = (0, import_firestore28.doc)(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
9493
+ await (0, import_firestore28.updateDoc)(docRef, updateData);
9494
+ return await this.getInviteById(inviteId);
9495
+ } catch (error) {
9496
+ console.error(
9497
+ "[PractitionerInviteService] Error accepting invite:",
9498
+ error
9499
+ );
9500
+ throw error;
9501
+ }
9502
+ }
9503
+ /**
9504
+ * Doctor rejects an invite
9505
+ * @param inviteId - Invite ID
9506
+ * @param rejectionReason - Optional reason for rejection
9507
+ * @returns Updated invite
9508
+ */
9509
+ async rejectInviteDoctor(inviteId, rejectionReason) {
9510
+ try {
9511
+ const invite = await this.getInviteById(inviteId);
9512
+ if (!invite) {
9513
+ throw new Error(`Invite with ID ${inviteId} not found`);
9514
+ }
9515
+ if (invite.status !== "pending" /* PENDING */) {
9516
+ throw new Error("Only pending invites can be rejected");
9517
+ }
9518
+ const updateData = {
9519
+ status: "rejected" /* REJECTED */,
9520
+ rejectionReason: rejectionReason || null,
9521
+ rejectedAt: import_firestore28.Timestamp.now(),
9522
+ updatedAt: (0, import_firestore28.serverTimestamp)()
9523
+ };
9524
+ const docRef = (0, import_firestore28.doc)(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
9525
+ await (0, import_firestore28.updateDoc)(docRef, updateData);
9526
+ return await this.getInviteById(inviteId);
9527
+ } catch (error) {
9528
+ console.error(
9529
+ "[PractitionerInviteService] Error rejecting invite:",
9530
+ error
9531
+ );
9532
+ throw error;
9533
+ }
9534
+ }
9535
+ /**
9536
+ * Admin cancels an invite
9537
+ * @param inviteId - Invite ID
9538
+ * @param cancelReason - Optional reason for cancellation
9539
+ * @returns Updated invite
9540
+ */
9541
+ async cancelInviteAdmin(inviteId, cancelReason) {
9542
+ try {
9543
+ const invite = await this.getInviteById(inviteId);
9544
+ if (!invite) {
9545
+ throw new Error(`Invite with ID ${inviteId} not found`);
9546
+ }
9547
+ if (invite.status !== "pending" /* PENDING */) {
9548
+ throw new Error("Only pending invites can be cancelled");
9549
+ }
9550
+ const updateData = {
9551
+ status: "cancelled" /* CANCELLED */,
9552
+ cancelReason: cancelReason || null,
9553
+ cancelledAt: import_firestore28.Timestamp.now(),
9554
+ updatedAt: (0, import_firestore28.serverTimestamp)()
9555
+ };
9556
+ const docRef = (0, import_firestore28.doc)(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
9557
+ await (0, import_firestore28.updateDoc)(docRef, updateData);
9558
+ return await this.getInviteById(inviteId);
9559
+ } catch (error) {
9560
+ console.error(
9561
+ "[PractitionerInviteService] Error cancelling invite:",
9562
+ error
9563
+ );
9564
+ throw error;
9565
+ }
9566
+ }
9567
+ /**
9568
+ * Gets an invite by ID
9569
+ * @param inviteId - Invite ID
9570
+ * @returns Invite or null if not found
9571
+ */
9572
+ async getInviteById(inviteId) {
9573
+ try {
9574
+ const docRef = (0, import_firestore28.doc)(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
9575
+ const docSnap = await (0, import_firestore28.getDoc)(docRef);
9576
+ if (docSnap.exists()) {
9577
+ return docSnap.data();
9578
+ }
9579
+ return null;
9580
+ } catch (error) {
9581
+ console.error(
9582
+ "[PractitionerInviteService] Error getting invite by ID:",
9583
+ error
9584
+ );
9585
+ throw error;
9586
+ }
9587
+ }
9588
+ /**
9589
+ * Gets invites with advanced filtering options
9590
+ * @param filters - Filter options
9591
+ * @returns Array of filtered invites
9592
+ */
9593
+ async getInvitesWithFilters(filters) {
9594
+ try {
9595
+ const constraints = [];
9596
+ if (filters.practitionerId) {
9597
+ constraints.push((0, import_firestore28.where)("practitionerId", "==", filters.practitionerId));
9598
+ }
9599
+ if (filters.clinicId) {
9600
+ constraints.push((0, import_firestore28.where)("clinicId", "==", filters.clinicId));
9601
+ }
9602
+ if (filters.invitedBy) {
9603
+ constraints.push((0, import_firestore28.where)("invitedBy", "==", filters.invitedBy));
9604
+ }
9605
+ if (filters.status && filters.status.length > 0) {
9606
+ constraints.push((0, import_firestore28.where)("status", "in", filters.status));
9607
+ }
9608
+ const orderField = filters.orderBy || "createdAt";
9609
+ const orderDirection = filters.orderDirection || "desc";
9610
+ constraints.push((0, import_firestore28.orderBy)(orderField, orderDirection));
9611
+ if (filters.limit) {
9612
+ constraints.push((0, import_firestore28.limit)(filters.limit));
9613
+ }
9614
+ const q = (0, import_firestore28.query)(
9615
+ (0, import_firestore28.collection)(this.db, PRACTITIONER_INVITES_COLLECTION),
9616
+ ...constraints
9617
+ );
9618
+ const querySnapshot = await (0, import_firestore28.getDocs)(q);
9619
+ let invites = querySnapshot.docs.map(
9620
+ (doc35) => doc35.data()
9621
+ );
9622
+ if (filters.fromDate) {
9623
+ invites = invites.filter(
9624
+ (invite) => invite.createdAt >= filters.fromDate
9625
+ );
9626
+ }
9627
+ if (filters.toDate) {
9628
+ invites = invites.filter(
9629
+ (invite) => invite.createdAt <= filters.toDate
9630
+ );
9631
+ }
9632
+ return invites;
9633
+ } catch (error) {
9634
+ console.error(
9635
+ "[PractitionerInviteService] Error getting invites with filters:",
9636
+ error
9637
+ );
9638
+ throw error;
9639
+ }
9640
+ }
9641
+ /**
9642
+ * Deletes an invite (admin only)
9643
+ * @param inviteId - Invite ID
9644
+ */
9645
+ async deleteInvite(inviteId) {
9646
+ try {
9647
+ const docRef = (0, import_firestore28.doc)(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
9648
+ await (0, import_firestore28.deleteDoc)(docRef);
9649
+ } catch (error) {
9650
+ console.error(
9651
+ "[PractitionerInviteService] Error deleting invite:",
9652
+ error
9653
+ );
9654
+ throw error;
9655
+ }
9656
+ }
9657
+ // Private helper methods
9658
+ /**
9659
+ * Gets practitioner by ID
9660
+ * @param practitionerId - Practitioner ID
9661
+ * @returns Practitioner or null
9662
+ */
9663
+ async getPractitionerById(practitionerId) {
9664
+ try {
9665
+ const docRef = (0, import_firestore28.doc)(this.db, PRACTITIONERS_COLLECTION, practitionerId);
9666
+ const docSnap = await (0, import_firestore28.getDoc)(docRef);
9667
+ return docSnap.exists() ? docSnap.data() : null;
9668
+ } catch (error) {
9669
+ console.error(
9670
+ "[PractitionerInviteService] Error getting practitioner:",
9671
+ error
9672
+ );
9673
+ return null;
9674
+ }
9675
+ }
9676
+ /**
9677
+ * Gets clinic by ID
9678
+ * @param clinicId - Clinic ID
9679
+ * @returns Clinic or null
9680
+ */
9681
+ async getClinicById(clinicId) {
9682
+ try {
9683
+ const docRef = (0, import_firestore28.doc)(this.db, CLINICS_COLLECTION, clinicId);
9684
+ const docSnap = await (0, import_firestore28.getDoc)(docRef);
9685
+ return docSnap.exists() ? docSnap.data() : null;
9686
+ } catch (error) {
9687
+ console.error("[PractitionerInviteService] Error getting clinic:", error);
9688
+ return null;
9689
+ }
9690
+ }
9691
+ /**
9692
+ * Finds existing invite between practitioner and clinic
9693
+ * @param practitionerId - Practitioner ID
9694
+ * @param clinicId - Clinic ID
9695
+ * @returns Existing invite or null
9696
+ */
9697
+ async findExistingInvite(practitionerId, clinicId) {
9698
+ try {
9699
+ const q = (0, import_firestore28.query)(
9700
+ (0, import_firestore28.collection)(this.db, PRACTITIONER_INVITES_COLLECTION),
9701
+ (0, import_firestore28.where)("practitionerId", "==", practitionerId),
9702
+ (0, import_firestore28.where)("clinicId", "==", clinicId),
9703
+ (0, import_firestore28.orderBy)("createdAt", "desc"),
9704
+ (0, import_firestore28.limit)(1)
9705
+ );
9706
+ const querySnapshot = await (0, import_firestore28.getDocs)(q);
9707
+ if (querySnapshot.empty) {
9708
+ return null;
9709
+ }
9710
+ return querySnapshot.docs[0].data();
9711
+ } catch (error) {
9712
+ console.error(
9713
+ "[PractitionerInviteService] Error finding existing invite:",
9714
+ error
9715
+ );
9716
+ return null;
9717
+ }
9718
+ }
9719
+ };
9720
+
9721
+ // src/services/documentation-templates/documentation-template.service.ts
9722
+ var import_firestore29 = require("firebase/firestore");
9308
9723
  var DocumentationTemplateService = class extends BaseService {
9309
9724
  constructor() {
9310
9725
  super(...arguments);
9311
- this.collectionRef = (0, import_firestore28.collection)(
9726
+ this.collectionRef = (0, import_firestore29.collection)(
9312
9727
  this.db,
9313
9728
  DOCUMENTATION_TEMPLATES_COLLECTION
9314
9729
  );
@@ -9342,8 +9757,8 @@ var DocumentationTemplateService = class extends BaseService {
9342
9757
  isRequired: validatedData.isRequired || false,
9343
9758
  sortingOrder: validatedData.sortingOrder || 0
9344
9759
  };
9345
- const docRef = (0, import_firestore28.doc)(this.collectionRef, templateId);
9346
- await (0, import_firestore28.setDoc)(docRef, template);
9760
+ const docRef = (0, import_firestore29.doc)(this.collectionRef, templateId);
9761
+ await (0, import_firestore29.setDoc)(docRef, template);
9347
9762
  return template;
9348
9763
  }
9349
9764
  /**
@@ -9353,8 +9768,8 @@ var DocumentationTemplateService = class extends BaseService {
9353
9768
  * @returns The template or null if not found
9354
9769
  */
9355
9770
  async getTemplateById(templateId, version) {
9356
- const docRef = (0, import_firestore28.doc)(this.collectionRef, templateId);
9357
- const docSnap = await (0, import_firestore28.getDoc)(docRef);
9771
+ const docRef = (0, import_firestore29.doc)(this.collectionRef, templateId);
9772
+ const docSnap = await (0, import_firestore29.getDoc)(docRef);
9358
9773
  if (!docSnap.exists()) {
9359
9774
  return null;
9360
9775
  }
@@ -9392,15 +9807,15 @@ var DocumentationTemplateService = class extends BaseService {
9392
9807
  if (!template) {
9393
9808
  throw new Error(`Template with ID ${templateId} not found`);
9394
9809
  }
9395
- const versionsCollectionRef = (0, import_firestore28.collection)(
9810
+ const versionsCollectionRef = (0, import_firestore29.collection)(
9396
9811
  this.db,
9397
9812
  `${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
9398
9813
  );
9399
- const versionDocRef = (0, import_firestore28.doc)(
9814
+ const versionDocRef = (0, import_firestore29.doc)(
9400
9815
  versionsCollectionRef,
9401
9816
  template.version.toString()
9402
9817
  );
9403
- await (0, import_firestore28.setDoc)(versionDocRef, template);
9818
+ await (0, import_firestore29.setDoc)(versionDocRef, template);
9404
9819
  let updatedElements = template.elements;
9405
9820
  if (validatedData.elements) {
9406
9821
  updatedElements = validatedData.elements.map((element) => ({
@@ -9424,9 +9839,9 @@ var DocumentationTemplateService = class extends BaseService {
9424
9839
  updatePayload.isUserForm = (_a = validatedData.isUserForm) != null ? _a : false;
9425
9840
  updatePayload.isRequired = (_b = validatedData.isRequired) != null ? _b : false;
9426
9841
  updatePayload.sortingOrder = (_c = validatedData.sortingOrder) != null ? _c : 0;
9427
- const docRef = (0, import_firestore28.doc)(this.collectionRef, templateId);
9842
+ const docRef = (0, import_firestore29.doc)(this.collectionRef, templateId);
9428
9843
  console.log("Update payload", updatePayload);
9429
- await (0, import_firestore28.updateDoc)(docRef, updatePayload);
9844
+ await (0, import_firestore29.updateDoc)(docRef, updatePayload);
9430
9845
  return { ...template, ...updatePayload };
9431
9846
  }
9432
9847
  /**
@@ -9436,11 +9851,11 @@ var DocumentationTemplateService = class extends BaseService {
9436
9851
  * @returns The template version or null if not found
9437
9852
  */
9438
9853
  async getTemplateVersion(templateId, versionNumber) {
9439
- const versionDocRef = (0, import_firestore28.doc)(
9854
+ const versionDocRef = (0, import_firestore29.doc)(
9440
9855
  this.db,
9441
9856
  `${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions/${versionNumber}`
9442
9857
  );
9443
- const versionDocSnap = await (0, import_firestore28.getDoc)(versionDocRef);
9858
+ const versionDocSnap = await (0, import_firestore29.getDoc)(versionDocRef);
9444
9859
  if (!versionDocSnap.exists()) {
9445
9860
  return null;
9446
9861
  }
@@ -9452,15 +9867,15 @@ var DocumentationTemplateService = class extends BaseService {
9452
9867
  * @returns Array of template versions
9453
9868
  */
9454
9869
  async getTemplateOldVersions(templateId) {
9455
- const versionsCollectionRef = (0, import_firestore28.collection)(
9870
+ const versionsCollectionRef = (0, import_firestore29.collection)(
9456
9871
  this.db,
9457
9872
  `${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
9458
9873
  );
9459
- const q = (0, import_firestore28.query)(versionsCollectionRef, (0, import_firestore28.orderBy)("version", "desc"));
9460
- const querySnapshot = await (0, import_firestore28.getDocs)(q);
9874
+ const q = (0, import_firestore29.query)(versionsCollectionRef, (0, import_firestore29.orderBy)("version", "desc"));
9875
+ const querySnapshot = await (0, import_firestore29.getDocs)(q);
9461
9876
  const versions = [];
9462
- querySnapshot.forEach((doc34) => {
9463
- versions.push(doc34.data());
9877
+ querySnapshot.forEach((doc35) => {
9878
+ versions.push(doc35.data());
9464
9879
  });
9465
9880
  return versions;
9466
9881
  }
@@ -9469,8 +9884,8 @@ var DocumentationTemplateService = class extends BaseService {
9469
9884
  * @param templateId - ID of the template to delete
9470
9885
  */
9471
9886
  async deleteTemplate(templateId) {
9472
- const docRef = (0, import_firestore28.doc)(this.collectionRef, templateId);
9473
- await (0, import_firestore28.deleteDoc)(docRef);
9887
+ const docRef = (0, import_firestore29.doc)(this.collectionRef, templateId);
9888
+ await (0, import_firestore29.deleteDoc)(docRef);
9474
9889
  }
9475
9890
  /**
9476
9891
  * Get all active templates
@@ -9479,21 +9894,21 @@ var DocumentationTemplateService = class extends BaseService {
9479
9894
  * @returns Array of templates and the last document for pagination
9480
9895
  */
9481
9896
  async getActiveTemplates(pageSize = 20, lastDoc) {
9482
- let q = (0, import_firestore28.query)(
9897
+ let q = (0, import_firestore29.query)(
9483
9898
  this.collectionRef,
9484
- (0, import_firestore28.where)("isActive", "==", true),
9485
- (0, import_firestore28.orderBy)("updatedAt", "desc"),
9486
- (0, import_firestore28.limit)(pageSize)
9899
+ (0, import_firestore29.where)("isActive", "==", true),
9900
+ (0, import_firestore29.orderBy)("updatedAt", "desc"),
9901
+ (0, import_firestore29.limit)(pageSize)
9487
9902
  );
9488
9903
  if (lastDoc) {
9489
- q = (0, import_firestore28.query)(q, (0, import_firestore28.startAfter)(lastDoc));
9904
+ q = (0, import_firestore29.query)(q, (0, import_firestore29.startAfter)(lastDoc));
9490
9905
  }
9491
- const querySnapshot = await (0, import_firestore28.getDocs)(q);
9906
+ const querySnapshot = await (0, import_firestore29.getDocs)(q);
9492
9907
  const templates = [];
9493
9908
  let lastVisible = null;
9494
- querySnapshot.forEach((doc34) => {
9495
- templates.push(doc34.data());
9496
- lastVisible = doc34;
9909
+ querySnapshot.forEach((doc35) => {
9910
+ templates.push(doc35.data());
9911
+ lastVisible = doc35;
9497
9912
  });
9498
9913
  return {
9499
9914
  templates,
@@ -9508,22 +9923,22 @@ var DocumentationTemplateService = class extends BaseService {
9508
9923
  * @returns Array of templates and the last document for pagination
9509
9924
  */
9510
9925
  async getTemplatesByTags(tags, pageSize = 20, lastDoc) {
9511
- let q = (0, import_firestore28.query)(
9926
+ let q = (0, import_firestore29.query)(
9512
9927
  this.collectionRef,
9513
- (0, import_firestore28.where)("isActive", "==", true),
9514
- (0, import_firestore28.where)("tags", "array-contains-any", tags),
9515
- (0, import_firestore28.orderBy)("updatedAt", "desc"),
9516
- (0, import_firestore28.limit)(pageSize)
9928
+ (0, import_firestore29.where)("isActive", "==", true),
9929
+ (0, import_firestore29.where)("tags", "array-contains-any", tags),
9930
+ (0, import_firestore29.orderBy)("updatedAt", "desc"),
9931
+ (0, import_firestore29.limit)(pageSize)
9517
9932
  );
9518
9933
  if (lastDoc) {
9519
- q = (0, import_firestore28.query)(q, (0, import_firestore28.startAfter)(lastDoc));
9934
+ q = (0, import_firestore29.query)(q, (0, import_firestore29.startAfter)(lastDoc));
9520
9935
  }
9521
- const querySnapshot = await (0, import_firestore28.getDocs)(q);
9936
+ const querySnapshot = await (0, import_firestore29.getDocs)(q);
9522
9937
  const templates = [];
9523
9938
  let lastVisible = null;
9524
- querySnapshot.forEach((doc34) => {
9525
- templates.push(doc34.data());
9526
- lastVisible = doc34;
9939
+ querySnapshot.forEach((doc35) => {
9940
+ templates.push(doc35.data());
9941
+ lastVisible = doc35;
9527
9942
  });
9528
9943
  return {
9529
9944
  templates,
@@ -9538,21 +9953,21 @@ var DocumentationTemplateService = class extends BaseService {
9538
9953
  * @returns Array of templates and the last document for pagination
9539
9954
  */
9540
9955
  async getTemplatesByCreator(userId, pageSize = 20, lastDoc) {
9541
- let q = (0, import_firestore28.query)(
9956
+ let q = (0, import_firestore29.query)(
9542
9957
  this.collectionRef,
9543
- (0, import_firestore28.where)("createdBy", "==", userId),
9544
- (0, import_firestore28.orderBy)("updatedAt", "desc"),
9545
- (0, import_firestore28.limit)(pageSize)
9958
+ (0, import_firestore29.where)("createdBy", "==", userId),
9959
+ (0, import_firestore29.orderBy)("updatedAt", "desc"),
9960
+ (0, import_firestore29.limit)(pageSize)
9546
9961
  );
9547
9962
  if (lastDoc) {
9548
- q = (0, import_firestore28.query)(q, (0, import_firestore28.startAfter)(lastDoc));
9963
+ q = (0, import_firestore29.query)(q, (0, import_firestore29.startAfter)(lastDoc));
9549
9964
  }
9550
- const querySnapshot = await (0, import_firestore28.getDocs)(q);
9965
+ const querySnapshot = await (0, import_firestore29.getDocs)(q);
9551
9966
  const templates = [];
9552
9967
  let lastVisible = null;
9553
- querySnapshot.forEach((doc34) => {
9554
- templates.push(doc34.data());
9555
- lastVisible = doc34;
9968
+ querySnapshot.forEach((doc35) => {
9969
+ templates.push(doc35.data());
9970
+ lastVisible = doc35;
9556
9971
  });
9557
9972
  return {
9558
9973
  templates,
@@ -9565,28 +9980,28 @@ var DocumentationTemplateService = class extends BaseService {
9565
9980
  * @returns Array of templates
9566
9981
  */
9567
9982
  async getAllTemplatesForSelection(options) {
9568
- let q = (0, import_firestore28.query)(
9983
+ let q = (0, import_firestore29.query)(
9569
9984
  this.collectionRef,
9570
- (0, import_firestore28.where)("isActive", "==", true),
9571
- (0, import_firestore28.orderBy)("updatedAt", "desc")
9985
+ (0, import_firestore29.where)("isActive", "==", true),
9986
+ (0, import_firestore29.orderBy)("updatedAt", "desc")
9572
9987
  );
9573
9988
  if ((options == null ? void 0 : options.isUserForm) !== void 0) {
9574
- q = (0, import_firestore28.query)(q, (0, import_firestore28.where)("isUserForm", "==", options.isUserForm));
9989
+ q = (0, import_firestore29.query)(q, (0, import_firestore29.where)("isUserForm", "==", options.isUserForm));
9575
9990
  }
9576
9991
  if ((options == null ? void 0 : options.isRequired) !== void 0) {
9577
- q = (0, import_firestore28.query)(q, (0, import_firestore28.where)("isRequired", "==", options.isRequired));
9992
+ q = (0, import_firestore29.query)(q, (0, import_firestore29.where)("isRequired", "==", options.isRequired));
9578
9993
  }
9579
- const querySnapshot = await (0, import_firestore28.getDocs)(q);
9994
+ const querySnapshot = await (0, import_firestore29.getDocs)(q);
9580
9995
  const templates = [];
9581
- querySnapshot.forEach((doc34) => {
9582
- templates.push(doc34.data());
9996
+ querySnapshot.forEach((doc35) => {
9997
+ templates.push(doc35.data());
9583
9998
  });
9584
9999
  return templates;
9585
10000
  }
9586
10001
  };
9587
10002
 
9588
10003
  // src/services/documentation-templates/filled-document.service.ts
9589
- var import_firestore29 = require("firebase/firestore");
10004
+ var import_firestore30 = require("firebase/firestore");
9590
10005
  var FilledDocumentService = class extends BaseService {
9591
10006
  constructor(...args) {
9592
10007
  super(...args);
@@ -9641,7 +10056,7 @@ var FilledDocumentService = class extends BaseService {
9641
10056
  values: initialValues,
9642
10057
  status: initialStatus
9643
10058
  };
9644
- const docRef = (0, import_firestore29.doc)(
10059
+ const docRef = (0, import_firestore30.doc)(
9645
10060
  this.db,
9646
10061
  APPOINTMENTS_COLLECTION,
9647
10062
  // Replaced "appointments"
@@ -9649,7 +10064,7 @@ var FilledDocumentService = class extends BaseService {
9649
10064
  formSubcollection,
9650
10065
  documentId3
9651
10066
  );
9652
- await (0, import_firestore29.setDoc)(docRef, filledDocument);
10067
+ await (0, import_firestore30.setDoc)(docRef, filledDocument);
9653
10068
  return filledDocument;
9654
10069
  }
9655
10070
  /**
@@ -9661,7 +10076,7 @@ var FilledDocumentService = class extends BaseService {
9661
10076
  */
9662
10077
  async getFilledDocumentFromAppointmentById(appointmentId, formId, isUserForm) {
9663
10078
  const formSubcollection = this.getFormSubcollectionPath(isUserForm);
9664
- const docRef = (0, import_firestore29.doc)(
10079
+ const docRef = (0, import_firestore30.doc)(
9665
10080
  this.db,
9666
10081
  APPOINTMENTS_COLLECTION,
9667
10082
  // Replaced "appointments"
@@ -9669,7 +10084,7 @@ var FilledDocumentService = class extends BaseService {
9669
10084
  formSubcollection,
9670
10085
  formId
9671
10086
  );
9672
- const docSnap = await (0, import_firestore29.getDoc)(docRef);
10087
+ const docSnap = await (0, import_firestore30.getDoc)(docRef);
9673
10088
  if (!docSnap.exists()) {
9674
10089
  return null;
9675
10090
  }
@@ -9686,7 +10101,7 @@ var FilledDocumentService = class extends BaseService {
9686
10101
  */
9687
10102
  async updateFilledDocumentInAppointment(appointmentId, formId, isUserForm, values, status) {
9688
10103
  const formSubcollection = this.getFormSubcollectionPath(isUserForm);
9689
- const docRef = (0, import_firestore29.doc)(
10104
+ const docRef = (0, import_firestore30.doc)(
9690
10105
  this.db,
9691
10106
  APPOINTMENTS_COLLECTION,
9692
10107
  // Replaced "appointments"
@@ -9718,7 +10133,7 @@ var FilledDocumentService = class extends BaseService {
9718
10133
  }
9719
10134
  if (Object.keys(updatePayload).length === 1 && "updatedAt" in updatePayload) {
9720
10135
  }
9721
- await (0, import_firestore29.updateDoc)(docRef, updatePayload);
10136
+ await (0, import_firestore30.updateDoc)(docRef, updatePayload);
9722
10137
  return { ...existingDoc, ...updatePayload };
9723
10138
  }
9724
10139
  /**
@@ -9728,20 +10143,20 @@ var FilledDocumentService = class extends BaseService {
9728
10143
  * @param lastDoc Last document from previous page for pagination.
9729
10144
  */
9730
10145
  async getFilledUserFormsForAppointment(appointmentId, pageSize = 20, lastDoc) {
9731
- const subcollectionRef = (0, import_firestore29.collection)(
10146
+ const subcollectionRef = (0, import_firestore30.collection)(
9732
10147
  this.db,
9733
10148
  APPOINTMENTS_COLLECTION,
9734
10149
  // Replaced "appointments"
9735
10150
  appointmentId,
9736
10151
  USER_FORMS_SUBCOLLECTION
9737
10152
  );
9738
- let q = (0, import_firestore29.query)(
10153
+ let q = (0, import_firestore30.query)(
9739
10154
  subcollectionRef,
9740
- (0, import_firestore29.orderBy)("updatedAt", "desc"),
9741
- (0, import_firestore29.limit)(pageSize)
10155
+ (0, import_firestore30.orderBy)("updatedAt", "desc"),
10156
+ (0, import_firestore30.limit)(pageSize)
9742
10157
  );
9743
10158
  if (lastDoc) {
9744
- q = (0, import_firestore29.query)(q, (0, import_firestore29.startAfter)(lastDoc));
10159
+ q = (0, import_firestore30.query)(q, (0, import_firestore30.startAfter)(lastDoc));
9745
10160
  }
9746
10161
  return this.executeQuery(q);
9747
10162
  }
@@ -9752,31 +10167,31 @@ var FilledDocumentService = class extends BaseService {
9752
10167
  * @param lastDoc Last document from previous page for pagination.
9753
10168
  */
9754
10169
  async getFilledDoctorFormsForAppointment(appointmentId, pageSize = 20, lastDoc) {
9755
- const subcollectionRef = (0, import_firestore29.collection)(
10170
+ const subcollectionRef = (0, import_firestore30.collection)(
9756
10171
  this.db,
9757
10172
  APPOINTMENTS_COLLECTION,
9758
10173
  // Replaced "appointments"
9759
10174
  appointmentId,
9760
10175
  DOCTOR_FORMS_SUBCOLLECTION
9761
10176
  );
9762
- let q = (0, import_firestore29.query)(
10177
+ let q = (0, import_firestore30.query)(
9763
10178
  subcollectionRef,
9764
- (0, import_firestore29.orderBy)("updatedAt", "desc"),
9765
- (0, import_firestore29.limit)(pageSize)
10179
+ (0, import_firestore30.orderBy)("updatedAt", "desc"),
10180
+ (0, import_firestore30.limit)(pageSize)
9766
10181
  );
9767
10182
  if (lastDoc) {
9768
- q = (0, import_firestore29.query)(q, (0, import_firestore29.startAfter)(lastDoc));
10183
+ q = (0, import_firestore30.query)(q, (0, import_firestore30.startAfter)(lastDoc));
9769
10184
  }
9770
10185
  return this.executeQuery(q);
9771
10186
  }
9772
10187
  // Helper to execute query and return documents + lastDoc
9773
10188
  async executeQuery(q) {
9774
- const querySnapshot = await (0, import_firestore29.getDocs)(q);
10189
+ const querySnapshot = await (0, import_firestore30.getDocs)(q);
9775
10190
  const documents = [];
9776
10191
  let lastVisible = null;
9777
- querySnapshot.forEach((doc34) => {
9778
- documents.push(doc34.data());
9779
- lastVisible = doc34;
10192
+ querySnapshot.forEach((doc35) => {
10193
+ documents.push(doc35.data());
10194
+ lastVisible = doc35;
9780
10195
  });
9781
10196
  return {
9782
10197
  documents,
@@ -9935,7 +10350,7 @@ var FilledDocumentService = class extends BaseService {
9935
10350
  };
9936
10351
 
9937
10352
  // src/services/calendar/calendar-refactored.service.ts
9938
- var import_firestore39 = require("firebase/firestore");
10353
+ var import_firestore40 = require("firebase/firestore");
9939
10354
 
9940
10355
  // src/types/calendar/synced-calendar.types.ts
9941
10356
  var SyncedCalendarProvider = /* @__PURE__ */ ((SyncedCalendarProvider3) => {
@@ -9947,15 +10362,15 @@ var SyncedCalendarProvider = /* @__PURE__ */ ((SyncedCalendarProvider3) => {
9947
10362
  var SYNCED_CALENDARS_COLLECTION = "syncedCalendars";
9948
10363
 
9949
10364
  // src/services/calendar/calendar-refactored.service.ts
9950
- var import_firestore40 = require("firebase/firestore");
10365
+ var import_firestore41 = require("firebase/firestore");
9951
10366
 
9952
10367
  // src/validations/calendar.schema.ts
9953
10368
  var import_zod23 = require("zod");
9954
- var import_firestore31 = require("firebase/firestore");
10369
+ var import_firestore32 = require("firebase/firestore");
9955
10370
 
9956
10371
  // src/validations/profile-info.schema.ts
9957
10372
  var import_zod22 = require("zod");
9958
- var import_firestore30 = require("firebase/firestore");
10373
+ var import_firestore31 = require("firebase/firestore");
9959
10374
  var clinicInfoSchema2 = import_zod22.z.object({
9960
10375
  id: import_zod22.z.string(),
9961
10376
  featuredPhoto: import_zod22.z.string(),
@@ -9977,19 +10392,19 @@ var patientProfileInfoSchema = import_zod22.z.object({
9977
10392
  fullName: import_zod22.z.string(),
9978
10393
  email: import_zod22.z.string().email(),
9979
10394
  phone: import_zod22.z.string().nullable(),
9980
- dateOfBirth: import_zod22.z.instanceof(import_firestore30.Timestamp),
10395
+ dateOfBirth: import_zod22.z.instanceof(import_firestore31.Timestamp),
9981
10396
  gender: import_zod22.z.nativeEnum(Gender)
9982
10397
  });
9983
10398
 
9984
10399
  // src/validations/calendar.schema.ts
9985
10400
  var MIN_APPOINTMENT_DURATION = 15;
9986
10401
  var calendarEventTimeSchema = import_zod23.z.object({
9987
- start: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(import_firestore31.Timestamp)),
9988
- end: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(import_firestore31.Timestamp))
10402
+ start: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(import_firestore32.Timestamp)),
10403
+ end: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(import_firestore32.Timestamp))
9989
10404
  }).refine(
9990
10405
  (data) => {
9991
- const startDate = data.start instanceof import_firestore31.Timestamp ? data.start.toDate() : data.start;
9992
- const endDate = data.end instanceof import_firestore31.Timestamp ? data.end.toDate() : data.end;
10406
+ const startDate = data.start instanceof import_firestore32.Timestamp ? data.start.toDate() : data.start;
10407
+ const endDate = data.end instanceof import_firestore32.Timestamp ? data.end.toDate() : data.end;
9993
10408
  return startDate < endDate;
9994
10409
  },
9995
10410
  {
@@ -9998,7 +10413,7 @@ var calendarEventTimeSchema = import_zod23.z.object({
9998
10413
  }
9999
10414
  ).refine(
10000
10415
  (data) => {
10001
- const startDate = data.start instanceof import_firestore31.Timestamp ? data.start.toDate() : data.start;
10416
+ const startDate = data.start instanceof import_firestore32.Timestamp ? data.start.toDate() : data.start;
10002
10417
  return startDate > /* @__PURE__ */ new Date();
10003
10418
  },
10004
10419
  {
@@ -10017,7 +10432,7 @@ var timeSlotSchema2 = import_zod23.z.object({
10017
10432
  var syncedCalendarEventSchema = import_zod23.z.object({
10018
10433
  eventId: import_zod23.z.string(),
10019
10434
  syncedCalendarProvider: import_zod23.z.nativeEnum(SyncedCalendarProvider),
10020
- syncedAt: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(import_firestore31.Timestamp))
10435
+ syncedAt: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(import_firestore32.Timestamp))
10021
10436
  });
10022
10437
  var procedureInfoSchema = import_zod23.z.object({
10023
10438
  name: import_zod23.z.string(),
@@ -10119,47 +10534,47 @@ var calendarEventSchema = import_zod23.z.object({
10119
10534
  status: import_zod23.z.nativeEnum(CalendarEventStatus),
10120
10535
  syncStatus: import_zod23.z.nativeEnum(CalendarSyncStatus),
10121
10536
  eventType: import_zod23.z.nativeEnum(CalendarEventType),
10122
- createdAt: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(import_firestore31.Timestamp)),
10123
- updatedAt: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(import_firestore31.Timestamp))
10537
+ createdAt: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(import_firestore32.Timestamp)),
10538
+ updatedAt: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(import_firestore32.Timestamp))
10124
10539
  });
10125
10540
 
10126
10541
  // src/services/calendar/utils/clinic.utils.ts
10127
- var import_firestore33 = require("firebase/firestore");
10542
+ var import_firestore34 = require("firebase/firestore");
10128
10543
 
10129
10544
  // src/services/calendar/utils/docs.utils.ts
10130
- var import_firestore32 = require("firebase/firestore");
10545
+ var import_firestore33 = require("firebase/firestore");
10131
10546
  function getPractitionerCalendarEventDocRef(db, practitionerId, eventId) {
10132
- return (0, import_firestore32.doc)(
10547
+ return (0, import_firestore33.doc)(
10133
10548
  db,
10134
10549
  `${PRACTITIONERS_COLLECTION}/${practitionerId}/${CALENDAR_COLLECTION}/${eventId}`
10135
10550
  );
10136
10551
  }
10137
10552
  function getPatientCalendarEventDocRef(db, patientId, eventId) {
10138
- return (0, import_firestore32.doc)(
10553
+ return (0, import_firestore33.doc)(
10139
10554
  db,
10140
10555
  `${PATIENTS_COLLECTION}/${patientId}/${CALENDAR_COLLECTION}/${eventId}`
10141
10556
  );
10142
10557
  }
10143
10558
  function getClinicCalendarEventDocRef(db, clinicId, eventId) {
10144
- return (0, import_firestore32.doc)(
10559
+ return (0, import_firestore33.doc)(
10145
10560
  db,
10146
10561
  `${CLINICS_COLLECTION}/${clinicId}/${CALENDAR_COLLECTION}/${eventId}`
10147
10562
  );
10148
10563
  }
10149
10564
  function getPractitionerSyncedCalendarDocRef(db, practitionerId, syncedCalendarId) {
10150
- return (0, import_firestore32.doc)(
10565
+ return (0, import_firestore33.doc)(
10151
10566
  db,
10152
10567
  `${PRACTITIONERS_COLLECTION}/${practitionerId}/syncedCalendars/${syncedCalendarId}`
10153
10568
  );
10154
10569
  }
10155
10570
  function getPatientSyncedCalendarDocRef(db, patientId, syncedCalendarId) {
10156
- return (0, import_firestore32.doc)(
10571
+ return (0, import_firestore33.doc)(
10157
10572
  db,
10158
10573
  `${PATIENTS_COLLECTION}/${patientId}/syncedCalendars/${syncedCalendarId}`
10159
10574
  );
10160
10575
  }
10161
10576
  function getClinicSyncedCalendarDocRef(db, clinicId, syncedCalendarId) {
10162
- return (0, import_firestore32.doc)(
10577
+ return (0, import_firestore33.doc)(
10163
10578
  db,
10164
10579
  `${CLINICS_COLLECTION}/${clinicId}/syncedCalendars/${syncedCalendarId}`
10165
10580
  );
@@ -10172,31 +10587,31 @@ async function createClinicCalendarEventUtil(db, clinicId, eventData, generateId
10172
10587
  const newEvent = {
10173
10588
  id: eventId,
10174
10589
  ...eventData,
10175
- createdAt: (0, import_firestore33.serverTimestamp)(),
10176
- updatedAt: (0, import_firestore33.serverTimestamp)()
10590
+ createdAt: (0, import_firestore34.serverTimestamp)(),
10591
+ updatedAt: (0, import_firestore34.serverTimestamp)()
10177
10592
  };
10178
- await (0, import_firestore33.setDoc)(eventRef, newEvent);
10593
+ await (0, import_firestore34.setDoc)(eventRef, newEvent);
10179
10594
  return {
10180
10595
  ...newEvent,
10181
- createdAt: import_firestore33.Timestamp.now(),
10182
- updatedAt: import_firestore33.Timestamp.now()
10596
+ createdAt: import_firestore34.Timestamp.now(),
10597
+ updatedAt: import_firestore34.Timestamp.now()
10183
10598
  };
10184
10599
  }
10185
10600
  async function updateClinicCalendarEventUtil(db, clinicId, eventId, updateData) {
10186
10601
  const eventRef = getClinicCalendarEventDocRef(db, clinicId, eventId);
10187
10602
  const updates = {
10188
10603
  ...updateData,
10189
- updatedAt: (0, import_firestore33.serverTimestamp)()
10604
+ updatedAt: (0, import_firestore34.serverTimestamp)()
10190
10605
  };
10191
- await (0, import_firestore33.updateDoc)(eventRef, updates);
10192
- const updatedDoc = await (0, import_firestore33.getDoc)(eventRef);
10606
+ await (0, import_firestore34.updateDoc)(eventRef, updates);
10607
+ const updatedDoc = await (0, import_firestore34.getDoc)(eventRef);
10193
10608
  if (!updatedDoc.exists()) {
10194
10609
  throw new Error("Event not found after update");
10195
10610
  }
10196
10611
  return updatedDoc.data();
10197
10612
  }
10198
10613
  async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
10199
- const clinicDoc = await (0, import_firestore33.getDoc)((0, import_firestore33.doc)(db, `clinics/${clinicId}`));
10614
+ const clinicDoc = await (0, import_firestore34.getDoc)((0, import_firestore34.doc)(db, `clinics/${clinicId}`));
10200
10615
  if (!clinicDoc.exists()) {
10201
10616
  throw new Error(`Clinic with ID ${clinicId} not found`);
10202
10617
  }
@@ -10205,8 +10620,8 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
10205
10620
  if (!clinicGroupId) {
10206
10621
  return false;
10207
10622
  }
10208
- const clinicGroupDoc = await (0, import_firestore33.getDoc)(
10209
- (0, import_firestore33.doc)(db, `${CLINIC_GROUPS_COLLECTION}/${clinicGroupId}`)
10623
+ const clinicGroupDoc = await (0, import_firestore34.getDoc)(
10624
+ (0, import_firestore34.doc)(db, `${CLINIC_GROUPS_COLLECTION}/${clinicGroupId}`)
10210
10625
  );
10211
10626
  if (!clinicGroupDoc.exists()) {
10212
10627
  return false;
@@ -10216,31 +10631,31 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
10216
10631
  }
10217
10632
 
10218
10633
  // src/services/calendar/utils/patient.utils.ts
10219
- var import_firestore34 = require("firebase/firestore");
10634
+ var import_firestore35 = require("firebase/firestore");
10220
10635
  async function createPatientCalendarEventUtil(db, patientId, eventData, generateId2) {
10221
10636
  const eventId = generateId2();
10222
10637
  const eventRef = getPatientCalendarEventDocRef(db, patientId, eventId);
10223
10638
  const newEvent = {
10224
10639
  id: eventId,
10225
10640
  ...eventData,
10226
- createdAt: (0, import_firestore34.serverTimestamp)(),
10227
- updatedAt: (0, import_firestore34.serverTimestamp)()
10641
+ createdAt: (0, import_firestore35.serverTimestamp)(),
10642
+ updatedAt: (0, import_firestore35.serverTimestamp)()
10228
10643
  };
10229
- await (0, import_firestore34.setDoc)(eventRef, newEvent);
10644
+ await (0, import_firestore35.setDoc)(eventRef, newEvent);
10230
10645
  return {
10231
10646
  ...newEvent,
10232
- createdAt: import_firestore34.Timestamp.now(),
10233
- updatedAt: import_firestore34.Timestamp.now()
10647
+ createdAt: import_firestore35.Timestamp.now(),
10648
+ updatedAt: import_firestore35.Timestamp.now()
10234
10649
  };
10235
10650
  }
10236
10651
  async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData) {
10237
10652
  const eventRef = getPatientCalendarEventDocRef(db, patientId, eventId);
10238
10653
  const updates = {
10239
10654
  ...updateData,
10240
- updatedAt: (0, import_firestore34.serverTimestamp)()
10655
+ updatedAt: (0, import_firestore35.serverTimestamp)()
10241
10656
  };
10242
- await (0, import_firestore34.updateDoc)(eventRef, updates);
10243
- const updatedDoc = await (0, import_firestore34.getDoc)(eventRef);
10657
+ await (0, import_firestore35.updateDoc)(eventRef, updates);
10658
+ const updatedDoc = await (0, import_firestore35.getDoc)(eventRef);
10244
10659
  if (!updatedDoc.exists()) {
10245
10660
  throw new Error("Event not found after update");
10246
10661
  }
@@ -10248,7 +10663,7 @@ async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData
10248
10663
  }
10249
10664
 
10250
10665
  // src/services/calendar/utils/practitioner.utils.ts
10251
- var import_firestore35 = require("firebase/firestore");
10666
+ var import_firestore36 = require("firebase/firestore");
10252
10667
  async function createPractitionerCalendarEventUtil(db, practitionerId, eventData, generateId2) {
10253
10668
  const eventId = generateId2();
10254
10669
  const eventRef = getPractitionerCalendarEventDocRef(
@@ -10259,14 +10674,14 @@ async function createPractitionerCalendarEventUtil(db, practitionerId, eventData
10259
10674
  const newEvent = {
10260
10675
  id: eventId,
10261
10676
  ...eventData,
10262
- createdAt: (0, import_firestore35.serverTimestamp)(),
10263
- updatedAt: (0, import_firestore35.serverTimestamp)()
10677
+ createdAt: (0, import_firestore36.serverTimestamp)(),
10678
+ updatedAt: (0, import_firestore36.serverTimestamp)()
10264
10679
  };
10265
- await (0, import_firestore35.setDoc)(eventRef, newEvent);
10680
+ await (0, import_firestore36.setDoc)(eventRef, newEvent);
10266
10681
  return {
10267
10682
  ...newEvent,
10268
- createdAt: import_firestore35.Timestamp.now(),
10269
- updatedAt: import_firestore35.Timestamp.now()
10683
+ createdAt: import_firestore36.Timestamp.now(),
10684
+ updatedAt: import_firestore36.Timestamp.now()
10270
10685
  };
10271
10686
  }
10272
10687
  async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId, updateData) {
@@ -10277,10 +10692,10 @@ async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId,
10277
10692
  );
10278
10693
  const updates = {
10279
10694
  ...updateData,
10280
- updatedAt: (0, import_firestore35.serverTimestamp)()
10695
+ updatedAt: (0, import_firestore36.serverTimestamp)()
10281
10696
  };
10282
- await (0, import_firestore35.updateDoc)(eventRef, updates);
10283
- const updatedDoc = await (0, import_firestore35.getDoc)(eventRef);
10697
+ await (0, import_firestore36.updateDoc)(eventRef, updates);
10698
+ const updatedDoc = await (0, import_firestore36.getDoc)(eventRef);
10284
10699
  if (!updatedDoc.exists()) {
10285
10700
  throw new Error("Event not found after update");
10286
10701
  }
@@ -10338,7 +10753,7 @@ async function updateAppointmentUtil(db, clinicId, practitionerId, patientId, ev
10338
10753
  }
10339
10754
 
10340
10755
  // src/services/calendar/utils/calendar-event.utils.ts
10341
- var import_firestore36 = require("firebase/firestore");
10756
+ var import_firestore37 = require("firebase/firestore");
10342
10757
  async function searchCalendarEventsUtil(db, params) {
10343
10758
  const { searchLocation, entityId, ...filters } = params;
10344
10759
  let baseCollectionPath;
@@ -10381,7 +10796,7 @@ async function searchCalendarEventsUtil(db, params) {
10381
10796
  );
10382
10797
  }
10383
10798
  baseCollectionPath = `${CLINICS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
10384
- constraints.push((0, import_firestore36.where)("clinicBranchId", "==", entityId));
10799
+ constraints.push((0, import_firestore37.where)("clinicBranchId", "==", entityId));
10385
10800
  if (filters.clinicId && filters.clinicId !== entityId) {
10386
10801
  console.warn(
10387
10802
  `Provided clinicId filter (${filters.clinicId}) does not match search entityId (${entityId}). Returning empty results.`
@@ -10393,36 +10808,36 @@ async function searchCalendarEventsUtil(db, params) {
10393
10808
  default:
10394
10809
  throw new Error(`Invalid search location: ${searchLocation}`);
10395
10810
  }
10396
- const collectionRef = (0, import_firestore36.collection)(db, baseCollectionPath);
10811
+ const collectionRef = (0, import_firestore37.collection)(db, baseCollectionPath);
10397
10812
  if (filters.clinicId) {
10398
- constraints.push((0, import_firestore36.where)("clinicBranchId", "==", filters.clinicId));
10813
+ constraints.push((0, import_firestore37.where)("clinicBranchId", "==", filters.clinicId));
10399
10814
  }
10400
10815
  if (filters.practitionerId) {
10401
10816
  constraints.push(
10402
- (0, import_firestore36.where)("practitionerProfileId", "==", filters.practitionerId)
10817
+ (0, import_firestore37.where)("practitionerProfileId", "==", filters.practitionerId)
10403
10818
  );
10404
10819
  }
10405
10820
  if (filters.patientId) {
10406
- constraints.push((0, import_firestore36.where)("patientProfileId", "==", filters.patientId));
10821
+ constraints.push((0, import_firestore37.where)("patientProfileId", "==", filters.patientId));
10407
10822
  }
10408
10823
  if (filters.procedureId) {
10409
- constraints.push((0, import_firestore36.where)("procedureId", "==", filters.procedureId));
10824
+ constraints.push((0, import_firestore37.where)("procedureId", "==", filters.procedureId));
10410
10825
  }
10411
10826
  if (filters.eventStatus) {
10412
- constraints.push((0, import_firestore36.where)("status", "==", filters.eventStatus));
10827
+ constraints.push((0, import_firestore37.where)("status", "==", filters.eventStatus));
10413
10828
  }
10414
10829
  if (filters.eventType) {
10415
- constraints.push((0, import_firestore36.where)("eventType", "==", filters.eventType));
10830
+ constraints.push((0, import_firestore37.where)("eventType", "==", filters.eventType));
10416
10831
  }
10417
10832
  if (filters.dateRange) {
10418
- constraints.push((0, import_firestore36.where)("eventTime.start", ">=", filters.dateRange.start));
10419
- constraints.push((0, import_firestore36.where)("eventTime.start", "<=", filters.dateRange.end));
10833
+ constraints.push((0, import_firestore37.where)("eventTime.start", ">=", filters.dateRange.start));
10834
+ constraints.push((0, import_firestore37.where)("eventTime.start", "<=", filters.dateRange.end));
10420
10835
  }
10421
10836
  try {
10422
- const finalQuery = (0, import_firestore36.query)(collectionRef, ...constraints);
10423
- const querySnapshot = await (0, import_firestore36.getDocs)(finalQuery);
10837
+ const finalQuery = (0, import_firestore37.query)(collectionRef, ...constraints);
10838
+ const querySnapshot = await (0, import_firestore37.getDocs)(finalQuery);
10424
10839
  const events = querySnapshot.docs.map(
10425
- (doc34) => ({ id: doc34.id, ...doc34.data() })
10840
+ (doc35) => ({ id: doc35.id, ...doc35.data() })
10426
10841
  );
10427
10842
  return events;
10428
10843
  } catch (error) {
@@ -10432,7 +10847,7 @@ async function searchCalendarEventsUtil(db, params) {
10432
10847
  }
10433
10848
 
10434
10849
  // src/services/calendar/utils/synced-calendar.utils.ts
10435
- var import_firestore37 = require("firebase/firestore");
10850
+ var import_firestore38 = require("firebase/firestore");
10436
10851
  async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendarData, generateId2) {
10437
10852
  const calendarId = generateId2();
10438
10853
  const calendarRef = getPractitionerSyncedCalendarDocRef(
@@ -10443,14 +10858,14 @@ async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendar
10443
10858
  const newCalendar = {
10444
10859
  id: calendarId,
10445
10860
  ...calendarData,
10446
- createdAt: (0, import_firestore37.serverTimestamp)(),
10447
- updatedAt: (0, import_firestore37.serverTimestamp)()
10861
+ createdAt: (0, import_firestore38.serverTimestamp)(),
10862
+ updatedAt: (0, import_firestore38.serverTimestamp)()
10448
10863
  };
10449
- await (0, import_firestore37.setDoc)(calendarRef, newCalendar);
10864
+ await (0, import_firestore38.setDoc)(calendarRef, newCalendar);
10450
10865
  return {
10451
10866
  ...newCalendar,
10452
- createdAt: import_firestore37.Timestamp.now(),
10453
- updatedAt: import_firestore37.Timestamp.now()
10867
+ createdAt: import_firestore38.Timestamp.now(),
10868
+ updatedAt: import_firestore38.Timestamp.now()
10454
10869
  };
10455
10870
  }
10456
10871
  async function createPatientSyncedCalendarUtil(db, patientId, calendarData, generateId2) {
@@ -10459,14 +10874,14 @@ async function createPatientSyncedCalendarUtil(db, patientId, calendarData, gene
10459
10874
  const newCalendar = {
10460
10875
  id: calendarId,
10461
10876
  ...calendarData,
10462
- createdAt: (0, import_firestore37.serverTimestamp)(),
10463
- updatedAt: (0, import_firestore37.serverTimestamp)()
10877
+ createdAt: (0, import_firestore38.serverTimestamp)(),
10878
+ updatedAt: (0, import_firestore38.serverTimestamp)()
10464
10879
  };
10465
- await (0, import_firestore37.setDoc)(calendarRef, newCalendar);
10880
+ await (0, import_firestore38.setDoc)(calendarRef, newCalendar);
10466
10881
  return {
10467
10882
  ...newCalendar,
10468
- createdAt: import_firestore37.Timestamp.now(),
10469
- updatedAt: import_firestore37.Timestamp.now()
10883
+ createdAt: import_firestore38.Timestamp.now(),
10884
+ updatedAt: import_firestore38.Timestamp.now()
10470
10885
  };
10471
10886
  }
10472
10887
  async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, generateId2) {
@@ -10475,14 +10890,14 @@ async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, genera
10475
10890
  const newCalendar = {
10476
10891
  id: calendarId,
10477
10892
  ...calendarData,
10478
- createdAt: (0, import_firestore37.serverTimestamp)(),
10479
- updatedAt: (0, import_firestore37.serverTimestamp)()
10893
+ createdAt: (0, import_firestore38.serverTimestamp)(),
10894
+ updatedAt: (0, import_firestore38.serverTimestamp)()
10480
10895
  };
10481
- await (0, import_firestore37.setDoc)(calendarRef, newCalendar);
10896
+ await (0, import_firestore38.setDoc)(calendarRef, newCalendar);
10482
10897
  return {
10483
10898
  ...newCalendar,
10484
- createdAt: import_firestore37.Timestamp.now(),
10485
- updatedAt: import_firestore37.Timestamp.now()
10899
+ createdAt: import_firestore38.Timestamp.now(),
10900
+ updatedAt: import_firestore38.Timestamp.now()
10486
10901
  };
10487
10902
  }
10488
10903
  async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId) {
@@ -10491,54 +10906,54 @@ async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId)
10491
10906
  practitionerId,
10492
10907
  calendarId
10493
10908
  );
10494
- const calendarDoc = await (0, import_firestore37.getDoc)(calendarRef);
10909
+ const calendarDoc = await (0, import_firestore38.getDoc)(calendarRef);
10495
10910
  if (!calendarDoc.exists()) {
10496
10911
  return null;
10497
10912
  }
10498
10913
  return calendarDoc.data();
10499
10914
  }
10500
10915
  async function getPractitionerSyncedCalendarsUtil(db, practitionerId) {
10501
- const calendarsRef = (0, import_firestore37.collection)(
10916
+ const calendarsRef = (0, import_firestore38.collection)(
10502
10917
  db,
10503
10918
  `practitioners/${practitionerId}/${SYNCED_CALENDARS_COLLECTION}`
10504
10919
  );
10505
- const q = (0, import_firestore37.query)(calendarsRef, (0, import_firestore37.orderBy)("createdAt", "desc"));
10506
- const querySnapshot = await (0, import_firestore37.getDocs)(q);
10507
- return querySnapshot.docs.map((doc34) => doc34.data());
10920
+ const q = (0, import_firestore38.query)(calendarsRef, (0, import_firestore38.orderBy)("createdAt", "desc"));
10921
+ const querySnapshot = await (0, import_firestore38.getDocs)(q);
10922
+ return querySnapshot.docs.map((doc35) => doc35.data());
10508
10923
  }
10509
10924
  async function getPatientSyncedCalendarUtil(db, patientId, calendarId) {
10510
10925
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
10511
- const calendarDoc = await (0, import_firestore37.getDoc)(calendarRef);
10926
+ const calendarDoc = await (0, import_firestore38.getDoc)(calendarRef);
10512
10927
  if (!calendarDoc.exists()) {
10513
10928
  return null;
10514
10929
  }
10515
10930
  return calendarDoc.data();
10516
10931
  }
10517
10932
  async function getPatientSyncedCalendarsUtil(db, patientId) {
10518
- const calendarsRef = (0, import_firestore37.collection)(
10933
+ const calendarsRef = (0, import_firestore38.collection)(
10519
10934
  db,
10520
10935
  `patients/${patientId}/${SYNCED_CALENDARS_COLLECTION}`
10521
10936
  );
10522
- const q = (0, import_firestore37.query)(calendarsRef, (0, import_firestore37.orderBy)("createdAt", "desc"));
10523
- const querySnapshot = await (0, import_firestore37.getDocs)(q);
10524
- return querySnapshot.docs.map((doc34) => doc34.data());
10937
+ const q = (0, import_firestore38.query)(calendarsRef, (0, import_firestore38.orderBy)("createdAt", "desc"));
10938
+ const querySnapshot = await (0, import_firestore38.getDocs)(q);
10939
+ return querySnapshot.docs.map((doc35) => doc35.data());
10525
10940
  }
10526
10941
  async function getClinicSyncedCalendarUtil(db, clinicId, calendarId) {
10527
10942
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
10528
- const calendarDoc = await (0, import_firestore37.getDoc)(calendarRef);
10943
+ const calendarDoc = await (0, import_firestore38.getDoc)(calendarRef);
10529
10944
  if (!calendarDoc.exists()) {
10530
10945
  return null;
10531
10946
  }
10532
10947
  return calendarDoc.data();
10533
10948
  }
10534
10949
  async function getClinicSyncedCalendarsUtil(db, clinicId) {
10535
- const calendarsRef = (0, import_firestore37.collection)(
10950
+ const calendarsRef = (0, import_firestore38.collection)(
10536
10951
  db,
10537
10952
  `clinics/${clinicId}/${SYNCED_CALENDARS_COLLECTION}`
10538
10953
  );
10539
- const q = (0, import_firestore37.query)(calendarsRef, (0, import_firestore37.orderBy)("createdAt", "desc"));
10540
- const querySnapshot = await (0, import_firestore37.getDocs)(q);
10541
- return querySnapshot.docs.map((doc34) => doc34.data());
10954
+ const q = (0, import_firestore38.query)(calendarsRef, (0, import_firestore38.orderBy)("createdAt", "desc"));
10955
+ const querySnapshot = await (0, import_firestore38.getDocs)(q);
10956
+ return querySnapshot.docs.map((doc35) => doc35.data());
10542
10957
  }
10543
10958
  async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendarId, updateData) {
10544
10959
  const calendarRef = getPractitionerSyncedCalendarDocRef(
@@ -10548,10 +10963,10 @@ async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendar
10548
10963
  );
10549
10964
  const updates = {
10550
10965
  ...updateData,
10551
- updatedAt: (0, import_firestore37.serverTimestamp)()
10966
+ updatedAt: (0, import_firestore38.serverTimestamp)()
10552
10967
  };
10553
- await (0, import_firestore37.updateDoc)(calendarRef, updates);
10554
- const updatedDoc = await (0, import_firestore37.getDoc)(calendarRef);
10968
+ await (0, import_firestore38.updateDoc)(calendarRef, updates);
10969
+ const updatedDoc = await (0, import_firestore38.getDoc)(calendarRef);
10555
10970
  if (!updatedDoc.exists()) {
10556
10971
  throw new Error("Synced calendar not found after update");
10557
10972
  }
@@ -10561,10 +10976,10 @@ async function updatePatientSyncedCalendarUtil(db, patientId, calendarId, update
10561
10976
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
10562
10977
  const updates = {
10563
10978
  ...updateData,
10564
- updatedAt: (0, import_firestore37.serverTimestamp)()
10979
+ updatedAt: (0, import_firestore38.serverTimestamp)()
10565
10980
  };
10566
- await (0, import_firestore37.updateDoc)(calendarRef, updates);
10567
- const updatedDoc = await (0, import_firestore37.getDoc)(calendarRef);
10981
+ await (0, import_firestore38.updateDoc)(calendarRef, updates);
10982
+ const updatedDoc = await (0, import_firestore38.getDoc)(calendarRef);
10568
10983
  if (!updatedDoc.exists()) {
10569
10984
  throw new Error("Synced calendar not found after update");
10570
10985
  }
@@ -10574,10 +10989,10 @@ async function updateClinicSyncedCalendarUtil(db, clinicId, calendarId, updateDa
10574
10989
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
10575
10990
  const updates = {
10576
10991
  ...updateData,
10577
- updatedAt: (0, import_firestore37.serverTimestamp)()
10992
+ updatedAt: (0, import_firestore38.serverTimestamp)()
10578
10993
  };
10579
- await (0, import_firestore37.updateDoc)(calendarRef, updates);
10580
- const updatedDoc = await (0, import_firestore37.getDoc)(calendarRef);
10994
+ await (0, import_firestore38.updateDoc)(calendarRef, updates);
10995
+ const updatedDoc = await (0, import_firestore38.getDoc)(calendarRef);
10581
10996
  if (!updatedDoc.exists()) {
10582
10997
  throw new Error("Synced calendar not found after update");
10583
10998
  }
@@ -10589,19 +11004,19 @@ async function deletePractitionerSyncedCalendarUtil(db, practitionerId, calendar
10589
11004
  practitionerId,
10590
11005
  calendarId
10591
11006
  );
10592
- await (0, import_firestore37.deleteDoc)(calendarRef);
11007
+ await (0, import_firestore38.deleteDoc)(calendarRef);
10593
11008
  }
10594
11009
  async function deletePatientSyncedCalendarUtil(db, patientId, calendarId) {
10595
11010
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
10596
- await (0, import_firestore37.deleteDoc)(calendarRef);
11011
+ await (0, import_firestore38.deleteDoc)(calendarRef);
10597
11012
  }
10598
11013
  async function deleteClinicSyncedCalendarUtil(db, clinicId, calendarId) {
10599
11014
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
10600
- await (0, import_firestore37.deleteDoc)(calendarRef);
11015
+ await (0, import_firestore38.deleteDoc)(calendarRef);
10601
11016
  }
10602
11017
  async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarId) {
10603
11018
  const updateData = {
10604
- lastSyncedAt: import_firestore37.Timestamp.now()
11019
+ lastSyncedAt: import_firestore38.Timestamp.now()
10605
11020
  };
10606
11021
  switch (entityType) {
10607
11022
  case "practitioner":
@@ -10631,7 +11046,7 @@ async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarI
10631
11046
  }
10632
11047
 
10633
11048
  // src/services/calendar/utils/google-calendar.utils.ts
10634
- var import_firestore38 = require("firebase/firestore");
11049
+ var import_firestore39 = require("firebase/firestore");
10635
11050
  var GOOGLE_CALENDAR_API_URL = "https://www.googleapis.com/calendar/v3";
10636
11051
  var GOOGLE_OAUTH_URL = "https://oauth2.googleapis.com/token";
10637
11052
  var CLIENT_ID = "your-client-id";
@@ -10751,7 +11166,7 @@ async function ensureValidToken(db, entityType, entityId, syncedCalendar) {
10751
11166
  tokenExpiry.setSeconds(tokenExpiry.getSeconds() + expiresIn);
10752
11167
  const updateData = {
10753
11168
  accessToken,
10754
- tokenExpiry: import_firestore38.Timestamp.fromDate(tokenExpiry)
11169
+ tokenExpiry: import_firestore39.Timestamp.fromDate(tokenExpiry)
10755
11170
  };
10756
11171
  switch (entityType) {
10757
11172
  case "practitioner":
@@ -10926,8 +11341,8 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
10926
11341
  eventName: googleEvent.summary || "External Event",
10927
11342
  eventLocation: googleEvent.location,
10928
11343
  eventTime: {
10929
- start: import_firestore38.Timestamp.fromDate(start),
10930
- end: import_firestore38.Timestamp.fromDate(end)
11344
+ start: import_firestore39.Timestamp.fromDate(start),
11345
+ end: import_firestore39.Timestamp.fromDate(end)
10931
11346
  },
10932
11347
  description: googleEvent.description || "",
10933
11348
  // External events are always set as CONFIRMED - status updates will happen externally
@@ -10941,7 +11356,7 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
10941
11356
  {
10942
11357
  eventId: googleEvent.id,
10943
11358
  syncedCalendarProvider: "google" /* GOOGLE */,
10944
- syncedAt: import_firestore38.Timestamp.now()
11359
+ syncedAt: import_firestore39.Timestamp.now()
10945
11360
  }
10946
11361
  ]
10947
11362
  };
@@ -11719,7 +12134,7 @@ var CalendarServiceV2 = class extends BaseService {
11719
12134
  return 0;
11720
12135
  }
11721
12136
  let importedEventsCount = 0;
11722
- const currentTime = import_firestore39.Timestamp.now();
12137
+ const currentTime = import_firestore40.Timestamp.now();
11723
12138
  for (const calendar of activeCalendars) {
11724
12139
  try {
11725
12140
  let externalEvents = [];
@@ -11786,7 +12201,7 @@ var CalendarServiceV2 = class extends BaseService {
11786
12201
  async createDoctorBlockingEvent(doctorId, eventData) {
11787
12202
  try {
11788
12203
  const eventId = this.generateId();
11789
- const eventRef = (0, import_firestore40.doc)(
12204
+ const eventRef = (0, import_firestore41.doc)(
11790
12205
  this.db,
11791
12206
  PRACTITIONERS_COLLECTION,
11792
12207
  doctorId,
@@ -11796,14 +12211,14 @@ var CalendarServiceV2 = class extends BaseService {
11796
12211
  const newEvent = {
11797
12212
  id: eventId,
11798
12213
  ...eventData,
11799
- createdAt: (0, import_firestore39.serverTimestamp)(),
11800
- updatedAt: (0, import_firestore39.serverTimestamp)()
12214
+ createdAt: (0, import_firestore40.serverTimestamp)(),
12215
+ updatedAt: (0, import_firestore40.serverTimestamp)()
11801
12216
  };
11802
- await (0, import_firestore40.setDoc)(eventRef, newEvent);
12217
+ await (0, import_firestore41.setDoc)(eventRef, newEvent);
11803
12218
  return {
11804
12219
  ...newEvent,
11805
- createdAt: import_firestore39.Timestamp.now(),
11806
- updatedAt: import_firestore39.Timestamp.now()
12220
+ createdAt: import_firestore40.Timestamp.now(),
12221
+ updatedAt: import_firestore40.Timestamp.now()
11807
12222
  };
11808
12223
  } catch (error) {
11809
12224
  console.error(
@@ -11821,8 +12236,8 @@ var CalendarServiceV2 = class extends BaseService {
11821
12236
  */
11822
12237
  async synchronizeExternalCalendars(lookbackDays = 7, lookforwardDays = 30) {
11823
12238
  try {
11824
- const practitionersRef = (0, import_firestore40.collection)(this.db, PRACTITIONERS_COLLECTION);
11825
- const practitionersSnapshot = await (0, import_firestore40.getDocs)(practitionersRef);
12239
+ const practitionersRef = (0, import_firestore41.collection)(this.db, PRACTITIONERS_COLLECTION);
12240
+ const practitionersSnapshot = await (0, import_firestore41.getDocs)(practitionersRef);
11826
12241
  const startDate = /* @__PURE__ */ new Date();
11827
12242
  startDate.setDate(startDate.getDate() - lookbackDays);
11828
12243
  const endDate = /* @__PURE__ */ new Date();
@@ -11880,22 +12295,22 @@ var CalendarServiceV2 = class extends BaseService {
11880
12295
  async updateExistingEventsFromExternalCalendars(doctorId, startDate, endDate) {
11881
12296
  var _a;
11882
12297
  try {
11883
- const eventsRef = (0, import_firestore40.collection)(
12298
+ const eventsRef = (0, import_firestore41.collection)(
11884
12299
  this.db,
11885
12300
  PRACTITIONERS_COLLECTION,
11886
12301
  doctorId,
11887
12302
  CALENDAR_COLLECTION
11888
12303
  );
11889
- const q = (0, import_firestore40.query)(
12304
+ const q = (0, import_firestore41.query)(
11890
12305
  eventsRef,
11891
- (0, import_firestore40.where)("syncStatus", "==", "external" /* EXTERNAL */),
11892
- (0, import_firestore40.where)("eventTime.start", ">=", import_firestore39.Timestamp.fromDate(startDate)),
11893
- (0, import_firestore40.where)("eventTime.start", "<=", import_firestore39.Timestamp.fromDate(endDate))
11894
- );
11895
- const eventsSnapshot = await (0, import_firestore40.getDocs)(q);
11896
- const events = eventsSnapshot.docs.map((doc34) => ({
11897
- id: doc34.id,
11898
- ...doc34.data()
12306
+ (0, import_firestore41.where)("syncStatus", "==", "external" /* EXTERNAL */),
12307
+ (0, import_firestore41.where)("eventTime.start", ">=", import_firestore40.Timestamp.fromDate(startDate)),
12308
+ (0, import_firestore41.where)("eventTime.start", "<=", import_firestore40.Timestamp.fromDate(endDate))
12309
+ );
12310
+ const eventsSnapshot = await (0, import_firestore41.getDocs)(q);
12311
+ const events = eventsSnapshot.docs.map((doc35) => ({
12312
+ id: doc35.id,
12313
+ ...doc35.data()
11899
12314
  }));
11900
12315
  const calendars = await this.syncedCalendarsService.getPractitionerSyncedCalendars(
11901
12316
  doctorId
@@ -11999,21 +12414,21 @@ var CalendarServiceV2 = class extends BaseService {
11999
12414
  const endTime = new Date(
12000
12415
  externalEvent.end.dateTime || externalEvent.end.date
12001
12416
  );
12002
- const eventRef = (0, import_firestore40.doc)(
12417
+ const eventRef = (0, import_firestore41.doc)(
12003
12418
  this.db,
12004
12419
  PRACTITIONERS_COLLECTION,
12005
12420
  doctorId,
12006
12421
  CALENDAR_COLLECTION,
12007
12422
  eventId
12008
12423
  );
12009
- await (0, import_firestore40.updateDoc)(eventRef, {
12424
+ await (0, import_firestore41.updateDoc)(eventRef, {
12010
12425
  eventName: externalEvent.summary || "External Event",
12011
12426
  eventTime: {
12012
- start: import_firestore39.Timestamp.fromDate(startTime),
12013
- end: import_firestore39.Timestamp.fromDate(endTime)
12427
+ start: import_firestore40.Timestamp.fromDate(startTime),
12428
+ end: import_firestore40.Timestamp.fromDate(endTime)
12014
12429
  },
12015
12430
  description: externalEvent.description || "",
12016
- updatedAt: (0, import_firestore39.serverTimestamp)()
12431
+ updatedAt: (0, import_firestore40.serverTimestamp)()
12017
12432
  });
12018
12433
  console.log(`Updated local event ${eventId} from external event`);
12019
12434
  } catch (error) {
@@ -12031,16 +12446,16 @@ var CalendarServiceV2 = class extends BaseService {
12031
12446
  */
12032
12447
  async updateEventStatus(doctorId, eventId, status) {
12033
12448
  try {
12034
- const eventRef = (0, import_firestore40.doc)(
12449
+ const eventRef = (0, import_firestore41.doc)(
12035
12450
  this.db,
12036
12451
  PRACTITIONERS_COLLECTION,
12037
12452
  doctorId,
12038
12453
  CALENDAR_COLLECTION,
12039
12454
  eventId
12040
12455
  );
12041
- await (0, import_firestore40.updateDoc)(eventRef, {
12456
+ await (0, import_firestore41.updateDoc)(eventRef, {
12042
12457
  status,
12043
- updatedAt: (0, import_firestore39.serverTimestamp)()
12458
+ updatedAt: (0, import_firestore40.serverTimestamp)()
12044
12459
  });
12045
12460
  console.log(`Updated event ${eventId} status to ${status}`);
12046
12461
  } catch (error) {
@@ -12088,8 +12503,8 @@ var CalendarServiceV2 = class extends BaseService {
12088
12503
  */
12089
12504
  async getPractitionerUpcomingAppointments(doctorId, startDate, endDate, status = "confirmed" /* CONFIRMED */) {
12090
12505
  const dateRange = {
12091
- start: import_firestore39.Timestamp.fromDate(startDate),
12092
- end: import_firestore39.Timestamp.fromDate(endDate)
12506
+ start: import_firestore40.Timestamp.fromDate(startDate),
12507
+ end: import_firestore40.Timestamp.fromDate(endDate)
12093
12508
  };
12094
12509
  const searchParams = {
12095
12510
  searchLocation: "practitioner" /* PRACTITIONER */,
@@ -12111,8 +12526,8 @@ var CalendarServiceV2 = class extends BaseService {
12111
12526
  */
12112
12527
  async getPatientAppointments(patientId, startDate, endDate, status) {
12113
12528
  const dateRange = {
12114
- start: import_firestore39.Timestamp.fromDate(startDate),
12115
- end: import_firestore39.Timestamp.fromDate(endDate)
12529
+ start: import_firestore40.Timestamp.fromDate(startDate),
12530
+ end: import_firestore40.Timestamp.fromDate(endDate)
12116
12531
  };
12117
12532
  const searchParams = {
12118
12533
  searchLocation: "patient" /* PATIENT */,
@@ -12137,8 +12552,8 @@ var CalendarServiceV2 = class extends BaseService {
12137
12552
  */
12138
12553
  async getClinicAppointments(clinicId, startDate, endDate, doctorId, status) {
12139
12554
  const dateRange = {
12140
- start: import_firestore39.Timestamp.fromDate(startDate),
12141
- end: import_firestore39.Timestamp.fromDate(endDate)
12555
+ start: import_firestore40.Timestamp.fromDate(startDate),
12556
+ end: import_firestore40.Timestamp.fromDate(endDate)
12142
12557
  };
12143
12558
  const searchParams = {
12144
12559
  searchLocation: "clinic" /* CLINIC */,
@@ -12197,8 +12612,8 @@ var CalendarServiceV2 = class extends BaseService {
12197
12612
  const startDate = eventTime.start.toDate();
12198
12613
  const startTime = startDate;
12199
12614
  const endTime = eventTime.end.toDate();
12200
- const practitionerRef = (0, import_firestore40.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
12201
- const practitionerDoc = await (0, import_firestore40.getDoc)(practitionerRef);
12615
+ const practitionerRef = (0, import_firestore41.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
12616
+ const practitionerDoc = await (0, import_firestore41.getDoc)(practitionerRef);
12202
12617
  if (!practitionerDoc.exists()) {
12203
12618
  throw new Error(`Doctor with ID ${doctorId} not found`);
12204
12619
  }
@@ -12256,8 +12671,8 @@ var CalendarServiceV2 = class extends BaseService {
12256
12671
  */
12257
12672
  async updateAppointmentStatus(appointmentId, clinicId, status) {
12258
12673
  const baseCollectionPath = `${CLINICS_COLLECTION}/${clinicId}/${CALENDAR_COLLECTION}`;
12259
- const appointmentRef = (0, import_firestore40.doc)(this.db, baseCollectionPath, appointmentId);
12260
- const appointmentDoc = await (0, import_firestore40.getDoc)(appointmentRef);
12674
+ const appointmentRef = (0, import_firestore41.doc)(this.db, baseCollectionPath, appointmentId);
12675
+ const appointmentDoc = await (0, import_firestore41.getDoc)(appointmentRef);
12261
12676
  if (!appointmentDoc.exists()) {
12262
12677
  throw new Error(`Appointment with ID ${appointmentId} not found`);
12263
12678
  }
@@ -12392,7 +12807,7 @@ var CalendarServiceV2 = class extends BaseService {
12392
12807
  const newSyncEvent = {
12393
12808
  eventId: result.eventIds[0],
12394
12809
  syncedCalendarProvider: calendar.provider,
12395
- syncedAt: import_firestore39.Timestamp.now()
12810
+ syncedAt: import_firestore40.Timestamp.now()
12396
12811
  };
12397
12812
  await this.updateEventWithSyncId(
12398
12813
  entityType === "doctor" ? appointment.practitionerProfileId : appointment.patientProfileId,
@@ -12416,8 +12831,8 @@ var CalendarServiceV2 = class extends BaseService {
12416
12831
  async updateEventWithSyncId(entityId, entityType, eventId, syncEvent) {
12417
12832
  try {
12418
12833
  const collectionPath = entityType === "doctor" ? `${PRACTITIONERS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}` : `${PATIENTS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
12419
- const eventRef = (0, import_firestore40.doc)(this.db, collectionPath, eventId);
12420
- const eventDoc = await (0, import_firestore40.getDoc)(eventRef);
12834
+ const eventRef = (0, import_firestore41.doc)(this.db, collectionPath, eventId);
12835
+ const eventDoc = await (0, import_firestore41.getDoc)(eventRef);
12421
12836
  if (eventDoc.exists()) {
12422
12837
  const event = eventDoc.data();
12423
12838
  const syncIds = [...event.syncedCalendarEventId || []];
@@ -12429,9 +12844,9 @@ var CalendarServiceV2 = class extends BaseService {
12429
12844
  } else {
12430
12845
  syncIds.push(syncEvent);
12431
12846
  }
12432
- await (0, import_firestore40.updateDoc)(eventRef, {
12847
+ await (0, import_firestore41.updateDoc)(eventRef, {
12433
12848
  syncedCalendarEventId: syncIds,
12434
- updatedAt: (0, import_firestore39.serverTimestamp)()
12849
+ updatedAt: (0, import_firestore40.serverTimestamp)()
12435
12850
  });
12436
12851
  console.log(
12437
12852
  `Updated event ${eventId} with sync ID ${syncEvent.eventId}`
@@ -12455,8 +12870,8 @@ var CalendarServiceV2 = class extends BaseService {
12455
12870
  * @returns Working hours for the clinic
12456
12871
  */
12457
12872
  async getClinicWorkingHours(clinicId, date) {
12458
- const clinicRef = (0, import_firestore40.doc)(this.db, CLINICS_COLLECTION, clinicId);
12459
- const clinicDoc = await (0, import_firestore40.getDoc)(clinicRef);
12873
+ const clinicRef = (0, import_firestore41.doc)(this.db, CLINICS_COLLECTION, clinicId);
12874
+ const clinicDoc = await (0, import_firestore41.getDoc)(clinicRef);
12460
12875
  if (!clinicDoc.exists()) {
12461
12876
  throw new Error(`Clinic with ID ${clinicId} not found`);
12462
12877
  }
@@ -12484,8 +12899,8 @@ var CalendarServiceV2 = class extends BaseService {
12484
12899
  * @returns Doctor's schedule
12485
12900
  */
12486
12901
  async getDoctorSchedule(doctorId, date) {
12487
- const practitionerRef = (0, import_firestore40.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
12488
- const practitionerDoc = await (0, import_firestore40.getDoc)(practitionerRef);
12902
+ const practitionerRef = (0, import_firestore41.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
12903
+ const practitionerDoc = await (0, import_firestore41.getDoc)(practitionerRef);
12489
12904
  if (!practitionerDoc.exists()) {
12490
12905
  throw new Error(`Doctor with ID ${doctorId} not found`);
12491
12906
  }
@@ -12517,19 +12932,19 @@ var CalendarServiceV2 = class extends BaseService {
12517
12932
  startOfDay.setHours(0, 0, 0, 0);
12518
12933
  const endOfDay = new Date(date);
12519
12934
  endOfDay.setHours(23, 59, 59, 999);
12520
- const appointmentsRef = (0, import_firestore40.collection)(this.db, CALENDAR_COLLECTION);
12521
- const q = (0, import_firestore40.query)(
12935
+ const appointmentsRef = (0, import_firestore41.collection)(this.db, CALENDAR_COLLECTION);
12936
+ const q = (0, import_firestore41.query)(
12522
12937
  appointmentsRef,
12523
- (0, import_firestore40.where)("practitionerProfileId", "==", doctorId),
12524
- (0, import_firestore40.where)("eventTime.start", ">=", import_firestore39.Timestamp.fromDate(startOfDay)),
12525
- (0, import_firestore40.where)("eventTime.start", "<=", import_firestore39.Timestamp.fromDate(endOfDay)),
12526
- (0, import_firestore40.where)("status", "in", [
12938
+ (0, import_firestore41.where)("practitionerProfileId", "==", doctorId),
12939
+ (0, import_firestore41.where)("eventTime.start", ">=", import_firestore40.Timestamp.fromDate(startOfDay)),
12940
+ (0, import_firestore41.where)("eventTime.start", "<=", import_firestore40.Timestamp.fromDate(endOfDay)),
12941
+ (0, import_firestore41.where)("status", "in", [
12527
12942
  "confirmed" /* CONFIRMED */,
12528
12943
  "pending" /* PENDING */
12529
12944
  ])
12530
12945
  );
12531
- const querySnapshot = await (0, import_firestore40.getDocs)(q);
12532
- return querySnapshot.docs.map((doc34) => doc34.data());
12946
+ const querySnapshot = await (0, import_firestore41.getDocs)(q);
12947
+ return querySnapshot.docs.map((doc35) => doc35.data());
12533
12948
  }
12534
12949
  /**
12535
12950
  * Calculates available time slots based on working hours, schedule and existing appointments
@@ -12586,11 +13001,11 @@ var CalendarServiceV2 = class extends BaseService {
12586
13001
  var _a;
12587
13002
  try {
12588
13003
  const [clinicDoc, practitionerDoc, patientDoc, patientSensitiveInfoDoc] = await Promise.all([
12589
- (0, import_firestore40.getDoc)((0, import_firestore40.doc)(this.db, CLINICS_COLLECTION, clinicId)),
12590
- (0, import_firestore40.getDoc)((0, import_firestore40.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId)),
12591
- (0, import_firestore40.getDoc)((0, import_firestore40.doc)(this.db, PATIENTS_COLLECTION, patientId)),
12592
- (0, import_firestore40.getDoc)(
12593
- (0, import_firestore40.doc)(
13004
+ (0, import_firestore41.getDoc)((0, import_firestore41.doc)(this.db, CLINICS_COLLECTION, clinicId)),
13005
+ (0, import_firestore41.getDoc)((0, import_firestore41.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId)),
13006
+ (0, import_firestore41.getDoc)((0, import_firestore41.doc)(this.db, PATIENTS_COLLECTION, patientId)),
13007
+ (0, import_firestore41.getDoc)(
13008
+ (0, import_firestore41.doc)(
12594
13009
  this.db,
12595
13010
  PATIENTS_COLLECTION,
12596
13011
  patientId,
@@ -12623,7 +13038,7 @@ var CalendarServiceV2 = class extends BaseService {
12623
13038
  fullName: `${sensitiveData.firstName} ${sensitiveData.lastName}`,
12624
13039
  email: sensitiveData.email || "",
12625
13040
  phone: sensitiveData.phoneNumber || null,
12626
- dateOfBirth: sensitiveData.dateOfBirth || import_firestore39.Timestamp.now(),
13041
+ dateOfBirth: sensitiveData.dateOfBirth || import_firestore40.Timestamp.now(),
12627
13042
  gender: sensitiveData.gender || "other" /* OTHER */
12628
13043
  };
12629
13044
  } else if (patientDoc.exists()) {
@@ -12632,7 +13047,7 @@ var CalendarServiceV2 = class extends BaseService {
12632
13047
  fullName: patientDoc.data().displayName,
12633
13048
  email: ((_a = patientDoc.data().contactInfo) == null ? void 0 : _a.email) || "",
12634
13049
  phone: patientDoc.data().phoneNumber || null,
12635
- dateOfBirth: patientDoc.data().dateOfBirth || import_firestore39.Timestamp.now(),
13050
+ dateOfBirth: patientDoc.data().dateOfBirth || import_firestore40.Timestamp.now(),
12636
13051
  gender: patientDoc.data().gender || "other" /* OTHER */
12637
13052
  };
12638
13053
  }
@@ -12654,7 +13069,7 @@ var CalendarServiceV2 = class extends BaseService {
12654
13069
  };
12655
13070
 
12656
13071
  // src/services/reviews/reviews.service.ts
12657
- var import_firestore41 = require("firebase/firestore");
13072
+ var import_firestore42 = require("firebase/firestore");
12658
13073
 
12659
13074
  // src/types/reviews/index.ts
12660
13075
  var REVIEWS_COLLECTION = "reviews";
@@ -12739,11 +13154,11 @@ var ReviewService = class extends BaseService {
12739
13154
  updatedAt: now
12740
13155
  };
12741
13156
  reviewSchema.parse(review);
12742
- const docRef = (0, import_firestore41.doc)(this.db, REVIEWS_COLLECTION, reviewId);
12743
- await (0, import_firestore41.setDoc)(docRef, {
13157
+ const docRef = (0, import_firestore42.doc)(this.db, REVIEWS_COLLECTION, reviewId);
13158
+ await (0, import_firestore42.setDoc)(docRef, {
12744
13159
  ...review,
12745
- createdAt: (0, import_firestore41.serverTimestamp)(),
12746
- updatedAt: (0, import_firestore41.serverTimestamp)()
13160
+ createdAt: (0, import_firestore42.serverTimestamp)(),
13161
+ updatedAt: (0, import_firestore42.serverTimestamp)()
12747
13162
  });
12748
13163
  return review;
12749
13164
  } catch (error) {
@@ -12759,8 +13174,8 @@ var ReviewService = class extends BaseService {
12759
13174
  * @returns The review if found, null otherwise
12760
13175
  */
12761
13176
  async getReview(reviewId) {
12762
- const docRef = (0, import_firestore41.doc)(this.db, REVIEWS_COLLECTION, reviewId);
12763
- const docSnap = await (0, import_firestore41.getDoc)(docRef);
13177
+ const docRef = (0, import_firestore42.doc)(this.db, REVIEWS_COLLECTION, reviewId);
13178
+ const docSnap = await (0, import_firestore42.getDoc)(docRef);
12764
13179
  if (!docSnap.exists()) {
12765
13180
  return null;
12766
13181
  }
@@ -12772,12 +13187,12 @@ var ReviewService = class extends BaseService {
12772
13187
  * @returns Array of reviews for the patient
12773
13188
  */
12774
13189
  async getReviewsByPatient(patientId) {
12775
- const q = (0, import_firestore41.query)(
12776
- (0, import_firestore41.collection)(this.db, REVIEWS_COLLECTION),
12777
- (0, import_firestore41.where)("patientId", "==", patientId)
13190
+ const q = (0, import_firestore42.query)(
13191
+ (0, import_firestore42.collection)(this.db, REVIEWS_COLLECTION),
13192
+ (0, import_firestore42.where)("patientId", "==", patientId)
12778
13193
  );
12779
- const snapshot = await (0, import_firestore41.getDocs)(q);
12780
- return snapshot.docs.map((doc34) => doc34.data());
13194
+ const snapshot = await (0, import_firestore42.getDocs)(q);
13195
+ return snapshot.docs.map((doc35) => doc35.data());
12781
13196
  }
12782
13197
  /**
12783
13198
  * Gets all reviews for a specific clinic
@@ -12785,12 +13200,12 @@ var ReviewService = class extends BaseService {
12785
13200
  * @returns Array of reviews containing clinic reviews
12786
13201
  */
12787
13202
  async getReviewsByClinic(clinicId) {
12788
- const q = (0, import_firestore41.query)(
12789
- (0, import_firestore41.collection)(this.db, REVIEWS_COLLECTION),
12790
- (0, import_firestore41.where)("clinicReview.clinicId", "==", clinicId)
13203
+ const q = (0, import_firestore42.query)(
13204
+ (0, import_firestore42.collection)(this.db, REVIEWS_COLLECTION),
13205
+ (0, import_firestore42.where)("clinicReview.clinicId", "==", clinicId)
12791
13206
  );
12792
- const snapshot = await (0, import_firestore41.getDocs)(q);
12793
- return snapshot.docs.map((doc34) => doc34.data());
13207
+ const snapshot = await (0, import_firestore42.getDocs)(q);
13208
+ return snapshot.docs.map((doc35) => doc35.data());
12794
13209
  }
12795
13210
  /**
12796
13211
  * Gets all reviews for a specific practitioner
@@ -12798,12 +13213,12 @@ var ReviewService = class extends BaseService {
12798
13213
  * @returns Array of reviews containing practitioner reviews
12799
13214
  */
12800
13215
  async getReviewsByPractitioner(practitionerId) {
12801
- const q = (0, import_firestore41.query)(
12802
- (0, import_firestore41.collection)(this.db, REVIEWS_COLLECTION),
12803
- (0, import_firestore41.where)("practitionerReview.practitionerId", "==", practitionerId)
13216
+ const q = (0, import_firestore42.query)(
13217
+ (0, import_firestore42.collection)(this.db, REVIEWS_COLLECTION),
13218
+ (0, import_firestore42.where)("practitionerReview.practitionerId", "==", practitionerId)
12804
13219
  );
12805
- const snapshot = await (0, import_firestore41.getDocs)(q);
12806
- return snapshot.docs.map((doc34) => doc34.data());
13220
+ const snapshot = await (0, import_firestore42.getDocs)(q);
13221
+ return snapshot.docs.map((doc35) => doc35.data());
12807
13222
  }
12808
13223
  /**
12809
13224
  * Gets all reviews for a specific procedure
@@ -12811,12 +13226,12 @@ var ReviewService = class extends BaseService {
12811
13226
  * @returns Array of reviews containing procedure reviews
12812
13227
  */
12813
13228
  async getReviewsByProcedure(procedureId) {
12814
- const q = (0, import_firestore41.query)(
12815
- (0, import_firestore41.collection)(this.db, REVIEWS_COLLECTION),
12816
- (0, import_firestore41.where)("procedureReview.procedureId", "==", procedureId)
13229
+ const q = (0, import_firestore42.query)(
13230
+ (0, import_firestore42.collection)(this.db, REVIEWS_COLLECTION),
13231
+ (0, import_firestore42.where)("procedureReview.procedureId", "==", procedureId)
12817
13232
  );
12818
- const snapshot = await (0, import_firestore41.getDocs)(q);
12819
- return snapshot.docs.map((doc34) => doc34.data());
13233
+ const snapshot = await (0, import_firestore42.getDocs)(q);
13234
+ return snapshot.docs.map((doc35) => doc35.data());
12820
13235
  }
12821
13236
  /**
12822
13237
  * Gets all reviews for a specific appointment
@@ -12824,11 +13239,11 @@ var ReviewService = class extends BaseService {
12824
13239
  * @returns The review for the appointment if found, null otherwise
12825
13240
  */
12826
13241
  async getReviewByAppointment(appointmentId) {
12827
- const q = (0, import_firestore41.query)(
12828
- (0, import_firestore41.collection)(this.db, REVIEWS_COLLECTION),
12829
- (0, import_firestore41.where)("appointmentId", "==", appointmentId)
13242
+ const q = (0, import_firestore42.query)(
13243
+ (0, import_firestore42.collection)(this.db, REVIEWS_COLLECTION),
13244
+ (0, import_firestore42.where)("appointmentId", "==", appointmentId)
12830
13245
  );
12831
- const snapshot = await (0, import_firestore41.getDocs)(q);
13246
+ const snapshot = await (0, import_firestore42.getDocs)(q);
12832
13247
  if (snapshot.empty) {
12833
13248
  return null;
12834
13249
  }
@@ -12843,7 +13258,7 @@ var ReviewService = class extends BaseService {
12843
13258
  if (!review) {
12844
13259
  throw new Error(`Review with ID ${reviewId} not found`);
12845
13260
  }
12846
- await (0, import_firestore41.deleteDoc)((0, import_firestore41.doc)(this.db, REVIEWS_COLLECTION, reviewId));
13261
+ await (0, import_firestore42.deleteDoc)((0, import_firestore42.doc)(this.db, REVIEWS_COLLECTION, reviewId));
12847
13262
  }
12848
13263
  /**
12849
13264
  * Calculates the average of an array of numbers
@@ -12861,11 +13276,11 @@ var ReviewService = class extends BaseService {
12861
13276
  };
12862
13277
 
12863
13278
  // src/services/appointment/appointment.service.ts
12864
- var import_firestore43 = require("firebase/firestore");
13279
+ var import_firestore44 = require("firebase/firestore");
12865
13280
  var import_functions2 = require("firebase/functions");
12866
13281
 
12867
13282
  // src/services/appointment/utils/appointment.utils.ts
12868
- var import_firestore42 = require("firebase/firestore");
13283
+ var import_firestore43 = require("firebase/firestore");
12869
13284
 
12870
13285
  // src/backoffice/types/technology.types.ts
12871
13286
  var TECHNOLOGIES_COLLECTION = "technologies";
@@ -12873,8 +13288,8 @@ var TECHNOLOGIES_COLLECTION = "technologies";
12873
13288
  // src/services/appointment/utils/appointment.utils.ts
12874
13289
  async function updateAppointmentUtil2(db, appointmentId, data) {
12875
13290
  try {
12876
- const appointmentRef = (0, import_firestore42.doc)(db, APPOINTMENTS_COLLECTION, appointmentId);
12877
- const appointmentDoc = await (0, import_firestore42.getDoc)(appointmentRef);
13291
+ const appointmentRef = (0, import_firestore43.doc)(db, APPOINTMENTS_COLLECTION, appointmentId);
13292
+ const appointmentDoc = await (0, import_firestore43.getDoc)(appointmentRef);
12878
13293
  if (!appointmentDoc.exists()) {
12879
13294
  throw new Error(`Appointment with ID ${appointmentId} not found`);
12880
13295
  }
@@ -12923,7 +13338,7 @@ async function updateAppointmentUtil2(db, appointmentId, data) {
12923
13338
  ...data,
12924
13339
  completedPreRequirements,
12925
13340
  completedPostRequirements,
12926
- updatedAt: (0, import_firestore42.serverTimestamp)()
13341
+ updatedAt: (0, import_firestore43.serverTimestamp)()
12927
13342
  };
12928
13343
  Object.keys(updateData).forEach((key) => {
12929
13344
  if (updateData[key] === void 0) {
@@ -12932,7 +13347,7 @@ async function updateAppointmentUtil2(db, appointmentId, data) {
12932
13347
  });
12933
13348
  if (data.status && data.status !== currentAppointment.status) {
12934
13349
  if (data.status === "confirmed" /* CONFIRMED */ && !updateData.confirmationTime) {
12935
- updateData.confirmationTime = import_firestore42.Timestamp.now();
13350
+ updateData.confirmationTime = import_firestore43.Timestamp.now();
12936
13351
  }
12937
13352
  if (currentAppointment.calendarEventId) {
12938
13353
  await updateCalendarEventStatus(
@@ -12942,8 +13357,8 @@ async function updateAppointmentUtil2(db, appointmentId, data) {
12942
13357
  );
12943
13358
  }
12944
13359
  }
12945
- await (0, import_firestore42.updateDoc)(appointmentRef, updateData);
12946
- const updatedAppointmentDoc = await (0, import_firestore42.getDoc)(appointmentRef);
13360
+ await (0, import_firestore43.updateDoc)(appointmentRef, updateData);
13361
+ const updatedAppointmentDoc = await (0, import_firestore43.getDoc)(appointmentRef);
12947
13362
  if (!updatedAppointmentDoc.exists()) {
12948
13363
  throw new Error(
12949
13364
  `Failed to retrieve updated appointment ${appointmentId}`
@@ -12957,8 +13372,8 @@ async function updateAppointmentUtil2(db, appointmentId, data) {
12957
13372
  }
12958
13373
  async function updateCalendarEventStatus(db, calendarEventId, appointmentStatus) {
12959
13374
  try {
12960
- const calendarEventRef = (0, import_firestore42.doc)(db, CALENDAR_COLLECTION, calendarEventId);
12961
- const calendarEventDoc = await (0, import_firestore42.getDoc)(calendarEventRef);
13375
+ const calendarEventRef = (0, import_firestore43.doc)(db, CALENDAR_COLLECTION, calendarEventId);
13376
+ const calendarEventDoc = await (0, import_firestore43.getDoc)(calendarEventRef);
12962
13377
  if (!calendarEventDoc.exists()) {
12963
13378
  console.warn(`Calendar event with ID ${calendarEventId} not found`);
12964
13379
  return;
@@ -12981,9 +13396,9 @@ async function updateCalendarEventStatus(db, calendarEventId, appointmentStatus)
12981
13396
  default:
12982
13397
  return;
12983
13398
  }
12984
- await (0, import_firestore42.updateDoc)(calendarEventRef, {
13399
+ await (0, import_firestore43.updateDoc)(calendarEventRef, {
12985
13400
  status: calendarStatus,
12986
- updatedAt: (0, import_firestore42.serverTimestamp)()
13401
+ updatedAt: (0, import_firestore43.serverTimestamp)()
12987
13402
  });
12988
13403
  } catch (error) {
12989
13404
  console.error(`Error updating calendar event ${calendarEventId}:`, error);
@@ -12991,8 +13406,8 @@ async function updateCalendarEventStatus(db, calendarEventId, appointmentStatus)
12991
13406
  }
12992
13407
  async function getAppointmentByIdUtil(db, appointmentId) {
12993
13408
  try {
12994
- const appointmentDoc = await (0, import_firestore42.getDoc)(
12995
- (0, import_firestore42.doc)(db, APPOINTMENTS_COLLECTION, appointmentId)
13409
+ const appointmentDoc = await (0, import_firestore43.getDoc)(
13410
+ (0, import_firestore43.doc)(db, APPOINTMENTS_COLLECTION, appointmentId)
12996
13411
  );
12997
13412
  if (!appointmentDoc.exists()) {
12998
13413
  return null;
@@ -13007,46 +13422,46 @@ async function searchAppointmentsUtil(db, params) {
13007
13422
  try {
13008
13423
  const constraints = [];
13009
13424
  if (params.patientId) {
13010
- constraints.push((0, import_firestore42.where)("patientId", "==", params.patientId));
13425
+ constraints.push((0, import_firestore43.where)("patientId", "==", params.patientId));
13011
13426
  }
13012
13427
  if (params.practitionerId) {
13013
- constraints.push((0, import_firestore42.where)("practitionerId", "==", params.practitionerId));
13428
+ constraints.push((0, import_firestore43.where)("practitionerId", "==", params.practitionerId));
13014
13429
  }
13015
13430
  if (params.clinicBranchId) {
13016
- constraints.push((0, import_firestore42.where)("clinicBranchId", "==", params.clinicBranchId));
13431
+ constraints.push((0, import_firestore43.where)("clinicBranchId", "==", params.clinicBranchId));
13017
13432
  }
13018
13433
  if (params.startDate) {
13019
13434
  constraints.push(
13020
- (0, import_firestore42.where)(
13435
+ (0, import_firestore43.where)(
13021
13436
  "appointmentStartTime",
13022
13437
  ">=",
13023
- import_firestore42.Timestamp.fromDate(params.startDate)
13438
+ import_firestore43.Timestamp.fromDate(params.startDate)
13024
13439
  )
13025
13440
  );
13026
13441
  }
13027
13442
  if (params.endDate) {
13028
13443
  constraints.push(
13029
- (0, import_firestore42.where)("appointmentStartTime", "<=", import_firestore42.Timestamp.fromDate(params.endDate))
13444
+ (0, import_firestore43.where)("appointmentStartTime", "<=", import_firestore43.Timestamp.fromDate(params.endDate))
13030
13445
  );
13031
13446
  }
13032
13447
  if (params.status) {
13033
13448
  if (Array.isArray(params.status)) {
13034
- constraints.push((0, import_firestore42.where)("status", "in", params.status));
13449
+ constraints.push((0, import_firestore43.where)("status", "in", params.status));
13035
13450
  } else {
13036
- constraints.push((0, import_firestore42.where)("status", "==", params.status));
13451
+ constraints.push((0, import_firestore43.where)("status", "==", params.status));
13037
13452
  }
13038
13453
  }
13039
- constraints.push((0, import_firestore42.orderBy)("appointmentStartTime", "asc"));
13454
+ constraints.push((0, import_firestore43.orderBy)("appointmentStartTime", "asc"));
13040
13455
  if (params.limit) {
13041
- constraints.push((0, import_firestore42.limit)(params.limit));
13456
+ constraints.push((0, import_firestore43.limit)(params.limit));
13042
13457
  }
13043
13458
  if (params.startAfter) {
13044
- constraints.push((0, import_firestore42.startAfter)(params.startAfter));
13459
+ constraints.push((0, import_firestore43.startAfter)(params.startAfter));
13045
13460
  }
13046
- const q = (0, import_firestore42.query)((0, import_firestore42.collection)(db, APPOINTMENTS_COLLECTION), ...constraints);
13047
- const querySnapshot = await (0, import_firestore42.getDocs)(q);
13461
+ const q = (0, import_firestore43.query)((0, import_firestore43.collection)(db, APPOINTMENTS_COLLECTION), ...constraints);
13462
+ const querySnapshot = await (0, import_firestore43.getDocs)(q);
13048
13463
  const appointments = querySnapshot.docs.map(
13049
- (doc34) => doc34.data()
13464
+ (doc35) => doc35.data()
13050
13465
  );
13051
13466
  const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
13052
13467
  return { appointments, lastDoc };
@@ -13415,7 +13830,7 @@ var AppointmentService = class extends BaseService {
13415
13830
  );
13416
13831
  const updateData = {
13417
13832
  status: newStatus,
13418
- updatedAt: (0, import_firestore43.serverTimestamp)()
13833
+ updatedAt: (0, import_firestore44.serverTimestamp)()
13419
13834
  };
13420
13835
  if (newStatus === "canceled_clinic" /* CANCELED_CLINIC */ || newStatus === "canceled_patient" /* CANCELED_PATIENT */ || newStatus === "canceled_patient_rescheduled" /* CANCELED_PATIENT_RESCHEDULED */) {
13421
13836
  if (!(details == null ? void 0 : details.cancellationReason)) {
@@ -13426,13 +13841,13 @@ var AppointmentService = class extends BaseService {
13426
13841
  }
13427
13842
  updateData.cancellationReason = details.cancellationReason;
13428
13843
  updateData.canceledBy = details.canceledBy;
13429
- updateData.cancellationTime = import_firestore43.Timestamp.now();
13844
+ updateData.cancellationTime = import_firestore44.Timestamp.now();
13430
13845
  }
13431
13846
  if (newStatus === "confirmed" /* CONFIRMED */) {
13432
- updateData.confirmationTime = import_firestore43.Timestamp.now();
13847
+ updateData.confirmationTime = import_firestore44.Timestamp.now();
13433
13848
  }
13434
13849
  if (newStatus === "rescheduled_by_clinic" /* RESCHEDULED_BY_CLINIC */) {
13435
- updateData.rescheduleTime = import_firestore43.Timestamp.now();
13850
+ updateData.rescheduleTime = import_firestore44.Timestamp.now();
13436
13851
  }
13437
13852
  return this.updateAppointment(appointmentId, updateData);
13438
13853
  }
@@ -13492,22 +13907,63 @@ var AppointmentService = class extends BaseService {
13492
13907
  * Admin proposes to reschedule an appointment.
13493
13908
  * Sets status to RESCHEDULED_BY_CLINIC and updates times.
13494
13909
  */
13495
- async rescheduleAppointmentAdmin(appointmentId, newStartTime, newEndTime) {
13910
+ async rescheduleAppointmentAdmin(params) {
13496
13911
  console.log(
13497
- `[APPOINTMENT_SERVICE] Admin rescheduling appointment: ${appointmentId}`
13912
+ `[APPOINTMENT_SERVICE] Admin rescheduling appointment: ${params.appointmentId}`
13913
+ );
13914
+ const validatedParams = await rescheduleAppointmentSchema.parseAsync(
13915
+ params
13916
+ );
13917
+ const startTimestamp = this.convertToTimestamp(
13918
+ validatedParams.newStartTime
13498
13919
  );
13499
- if (newEndTime.toMillis() <= newStartTime.toMillis()) {
13920
+ const endTimestamp = this.convertToTimestamp(validatedParams.newEndTime);
13921
+ if (endTimestamp.toMillis() <= startTimestamp.toMillis()) {
13500
13922
  throw new Error("New end time must be after new start time.");
13501
13923
  }
13502
13924
  const updateData = {
13503
13925
  status: "rescheduled_by_clinic" /* RESCHEDULED_BY_CLINIC */,
13504
- appointmentStartTime: newStartTime,
13505
- appointmentEndTime: newEndTime,
13506
- rescheduleTime: import_firestore43.Timestamp.now(),
13926
+ appointmentStartTime: startTimestamp,
13927
+ appointmentEndTime: endTimestamp,
13928
+ rescheduleTime: import_firestore44.Timestamp.now(),
13507
13929
  confirmationTime: null,
13508
- updatedAt: (0, import_firestore43.serverTimestamp)()
13930
+ updatedAt: (0, import_firestore44.serverTimestamp)()
13509
13931
  };
13510
- return this.updateAppointment(appointmentId, updateData);
13932
+ return this.updateAppointment(validatedParams.appointmentId, updateData);
13933
+ }
13934
+ /**
13935
+ * Helper method to convert various timestamp formats to Firestore Timestamp
13936
+ * @param value - Any timestamp format (Timestamp, number, string, Date, serialized Timestamp)
13937
+ * @returns Firestore Timestamp object
13938
+ */
13939
+ convertToTimestamp(value) {
13940
+ console.log(`[APPOINTMENT_SERVICE] Converting timestamp:`, {
13941
+ value,
13942
+ type: typeof value
13943
+ });
13944
+ if (value && typeof value.toMillis === "function") {
13945
+ return value;
13946
+ }
13947
+ if (typeof value === "number") {
13948
+ return import_firestore44.Timestamp.fromMillis(value);
13949
+ }
13950
+ if (typeof value === "string") {
13951
+ return import_firestore44.Timestamp.fromDate(new Date(value));
13952
+ }
13953
+ if (value instanceof Date) {
13954
+ return import_firestore44.Timestamp.fromDate(value);
13955
+ }
13956
+ if (value && typeof value._seconds === "number") {
13957
+ return new import_firestore44.Timestamp(value._seconds, value._nanoseconds || 0);
13958
+ }
13959
+ if (value && typeof value.seconds === "number") {
13960
+ return new import_firestore44.Timestamp(value.seconds, value.nanoseconds || 0);
13961
+ }
13962
+ throw new Error(
13963
+ `Invalid timestamp format: ${typeof value}, value: ${JSON.stringify(
13964
+ value
13965
+ )}`
13966
+ );
13511
13967
  }
13512
13968
  /**
13513
13969
  * User confirms a reschedule proposed by the clinic.
@@ -13600,9 +14056,9 @@ var AppointmentService = class extends BaseService {
13600
14056
  }
13601
14057
  const updateData = {
13602
14058
  status: "in_progress" /* IN_PROGRESS */,
13603
- procedureActualStartTime: import_firestore43.Timestamp.now(),
14059
+ procedureActualStartTime: import_firestore44.Timestamp.now(),
13604
14060
  // Set actual start time
13605
- updatedAt: (0, import_firestore43.serverTimestamp)()
14061
+ updatedAt: (0, import_firestore44.serverTimestamp)()
13606
14062
  };
13607
14063
  return this.updateAppointment(appointmentId, updateData);
13608
14064
  }
@@ -13620,7 +14076,7 @@ var AppointmentService = class extends BaseService {
13620
14076
  if (!appointment)
13621
14077
  throw new Error(`Appointment ${appointmentId} not found.`);
13622
14078
  let calculatedDurationMinutes = actualDurationMinutesInput;
13623
- const procedureCompletionTime = import_firestore43.Timestamp.now();
14079
+ const procedureCompletionTime = import_firestore44.Timestamp.now();
13624
14080
  if (calculatedDurationMinutes === void 0 && appointment.procedureActualStartTime) {
13625
14081
  const startTimeMillis = appointment.procedureActualStartTime.toMillis();
13626
14082
  const endTimeMillis = procedureCompletionTime.toMillis();
@@ -13643,7 +14099,7 @@ var AppointmentService = class extends BaseService {
13643
14099
  },
13644
14100
  // Optionally update appointmentEndTime to the actual completion time
13645
14101
  // appointmentEndTime: procedureCompletionTime,
13646
- updatedAt: (0, import_firestore43.serverTimestamp)()
14102
+ updatedAt: (0, import_firestore44.serverTimestamp)()
13647
14103
  };
13648
14104
  return this.updateAppointment(appointmentId, updateData);
13649
14105
  }
@@ -13657,7 +14113,7 @@ var AppointmentService = class extends BaseService {
13657
14113
  const appointment = await this.getAppointmentById(appointmentId);
13658
14114
  if (!appointment)
13659
14115
  throw new Error(`Appointment ${appointmentId} not found.`);
13660
- if (import_firestore43.Timestamp.now().toMillis() < appointment.appointmentStartTime.toMillis()) {
14116
+ if (import_firestore44.Timestamp.now().toMillis() < appointment.appointmentStartTime.toMillis()) {
13661
14117
  throw new Error("Cannot mark no-show before appointment start time.");
13662
14118
  }
13663
14119
  return this.updateAppointmentStatus(
@@ -13681,12 +14137,12 @@ var AppointmentService = class extends BaseService {
13681
14137
  const newMediaItem = {
13682
14138
  ...mediaItemData,
13683
14139
  id: this.generateId(),
13684
- uploadedAt: import_firestore43.Timestamp.now(),
14140
+ uploadedAt: import_firestore44.Timestamp.now(),
13685
14141
  uploadedBy: currentUser.uid
13686
14142
  };
13687
14143
  const updateData = {
13688
- media: (0, import_firestore43.arrayUnion)(newMediaItem),
13689
- updatedAt: (0, import_firestore43.serverTimestamp)()
14144
+ media: (0, import_firestore44.arrayUnion)(newMediaItem),
14145
+ updatedAt: (0, import_firestore44.serverTimestamp)()
13690
14146
  };
13691
14147
  return this.updateAppointment(appointmentId, updateData);
13692
14148
  }
@@ -13706,8 +14162,8 @@ var AppointmentService = class extends BaseService {
13706
14162
  throw new Error(`Media item ${mediaItemId} not found in appointment.`);
13707
14163
  }
13708
14164
  const updateData = {
13709
- media: (0, import_firestore43.arrayRemove)(mediaToRemove),
13710
- updatedAt: (0, import_firestore43.serverTimestamp)()
14165
+ media: (0, import_firestore44.arrayRemove)(mediaToRemove),
14166
+ updatedAt: (0, import_firestore44.serverTimestamp)()
13711
14167
  };
13712
14168
  return this.updateAppointment(appointmentId, updateData);
13713
14169
  }
@@ -13721,11 +14177,11 @@ var AppointmentService = class extends BaseService {
13721
14177
  const newReviewInfo = {
13722
14178
  ...reviewData,
13723
14179
  reviewId: this.generateId(),
13724
- reviewedAt: import_firestore43.Timestamp.now()
14180
+ reviewedAt: import_firestore44.Timestamp.now()
13725
14181
  };
13726
14182
  const updateData = {
13727
14183
  reviewInfo: newReviewInfo,
13728
- updatedAt: (0, import_firestore43.serverTimestamp)()
14184
+ updatedAt: (0, import_firestore44.serverTimestamp)()
13729
14185
  };
13730
14186
  return this.updateAppointment(appointmentId, updateData);
13731
14187
  }
@@ -13739,7 +14195,7 @@ var AppointmentService = class extends BaseService {
13739
14195
  const updateData = {
13740
14196
  paymentStatus,
13741
14197
  paymentTransactionId: paymentTransactionId || null,
13742
- updatedAt: (0, import_firestore43.serverTimestamp)()
14198
+ updatedAt: (0, import_firestore44.serverTimestamp)()
13743
14199
  };
13744
14200
  return this.updateAppointment(appointmentId, updateData);
13745
14201
  }
@@ -13781,38 +14237,38 @@ var AppointmentService = class extends BaseService {
13781
14237
  "rescheduled_by_clinic" /* RESCHEDULED_BY_CLINIC */
13782
14238
  ];
13783
14239
  const constraints = [];
13784
- constraints.push((0, import_firestore43.where)("patientId", "==", patientId));
13785
- constraints.push((0, import_firestore43.where)("status", "in", upcomingStatuses));
14240
+ constraints.push((0, import_firestore44.where)("patientId", "==", patientId));
14241
+ constraints.push((0, import_firestore44.where)("status", "in", upcomingStatuses));
13786
14242
  constraints.push(
13787
- (0, import_firestore43.where)(
14243
+ (0, import_firestore44.where)(
13788
14244
  "appointmentStartTime",
13789
14245
  ">=",
13790
- import_firestore43.Timestamp.fromDate(effectiveStartDate)
14246
+ import_firestore44.Timestamp.fromDate(effectiveStartDate)
13791
14247
  )
13792
14248
  );
13793
14249
  if (options == null ? void 0 : options.endDate) {
13794
14250
  constraints.push(
13795
- (0, import_firestore43.where)(
14251
+ (0, import_firestore44.where)(
13796
14252
  "appointmentStartTime",
13797
14253
  "<=",
13798
- import_firestore43.Timestamp.fromDate(options.endDate)
14254
+ import_firestore44.Timestamp.fromDate(options.endDate)
13799
14255
  )
13800
14256
  );
13801
14257
  }
13802
- constraints.push((0, import_firestore43.orderBy)("appointmentStartTime", "asc"));
14258
+ constraints.push((0, import_firestore44.orderBy)("appointmentStartTime", "asc"));
13803
14259
  if (options == null ? void 0 : options.limit) {
13804
- constraints.push((0, import_firestore43.limit)(options.limit));
14260
+ constraints.push((0, import_firestore44.limit)(options.limit));
13805
14261
  }
13806
14262
  if (options == null ? void 0 : options.startAfter) {
13807
- constraints.push((0, import_firestore43.startAfter)(options.startAfter));
14263
+ constraints.push((0, import_firestore44.startAfter)(options.startAfter));
13808
14264
  }
13809
- const q = (0, import_firestore43.query)(
13810
- (0, import_firestore43.collection)(this.db, APPOINTMENTS_COLLECTION),
14265
+ const q = (0, import_firestore44.query)(
14266
+ (0, import_firestore44.collection)(this.db, APPOINTMENTS_COLLECTION),
13811
14267
  ...constraints
13812
14268
  );
13813
- const querySnapshot = await (0, import_firestore43.getDocs)(q);
14269
+ const querySnapshot = await (0, import_firestore44.getDocs)(q);
13814
14270
  const appointments = querySnapshot.docs.map(
13815
- (doc34) => doc34.data()
14271
+ (doc35) => doc35.data()
13816
14272
  );
13817
14273
  const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
13818
14274
  console.log(
@@ -13854,38 +14310,38 @@ var AppointmentService = class extends BaseService {
13854
14310
  pastStatuses.push("no_show" /* NO_SHOW */);
13855
14311
  }
13856
14312
  const constraints = [];
13857
- constraints.push((0, import_firestore43.where)("patientId", "==", patientId));
13858
- constraints.push((0, import_firestore43.where)("status", "in", pastStatuses));
14313
+ constraints.push((0, import_firestore44.where)("patientId", "==", patientId));
14314
+ constraints.push((0, import_firestore44.where)("status", "in", pastStatuses));
13859
14315
  if (options == null ? void 0 : options.startDate) {
13860
14316
  constraints.push(
13861
- (0, import_firestore43.where)(
14317
+ (0, import_firestore44.where)(
13862
14318
  "appointmentStartTime",
13863
14319
  ">=",
13864
- import_firestore43.Timestamp.fromDate(options.startDate)
14320
+ import_firestore44.Timestamp.fromDate(options.startDate)
13865
14321
  )
13866
14322
  );
13867
14323
  }
13868
14324
  constraints.push(
13869
- (0, import_firestore43.where)(
14325
+ (0, import_firestore44.where)(
13870
14326
  "appointmentStartTime",
13871
14327
  "<=",
13872
- import_firestore43.Timestamp.fromDate(effectiveEndDate)
14328
+ import_firestore44.Timestamp.fromDate(effectiveEndDate)
13873
14329
  )
13874
14330
  );
13875
- constraints.push((0, import_firestore43.orderBy)("appointmentStartTime", "desc"));
14331
+ constraints.push((0, import_firestore44.orderBy)("appointmentStartTime", "desc"));
13876
14332
  if (options == null ? void 0 : options.limit) {
13877
- constraints.push((0, import_firestore43.limit)(options.limit));
14333
+ constraints.push((0, import_firestore44.limit)(options.limit));
13878
14334
  }
13879
14335
  if (options == null ? void 0 : options.startAfter) {
13880
- constraints.push((0, import_firestore43.startAfter)(options.startAfter));
14336
+ constraints.push((0, import_firestore44.startAfter)(options.startAfter));
13881
14337
  }
13882
- const q = (0, import_firestore43.query)(
13883
- (0, import_firestore43.collection)(this.db, APPOINTMENTS_COLLECTION),
14338
+ const q = (0, import_firestore44.query)(
14339
+ (0, import_firestore44.collection)(this.db, APPOINTMENTS_COLLECTION),
13884
14340
  ...constraints
13885
14341
  );
13886
- const querySnapshot = await (0, import_firestore43.getDocs)(q);
14342
+ const querySnapshot = await (0, import_firestore44.getDocs)(q);
13887
14343
  const appointments = querySnapshot.docs.map(
13888
- (doc34) => doc34.data()
14344
+ (doc35) => doc35.data()
13889
14345
  );
13890
14346
  const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
13891
14347
  console.log(
@@ -13903,7 +14359,7 @@ var AppointmentService = class extends BaseService {
13903
14359
  };
13904
14360
 
13905
14361
  // src/services/patient/patientRequirements.service.ts
13906
- var import_firestore44 = require("firebase/firestore");
14362
+ var import_firestore45 = require("firebase/firestore");
13907
14363
 
13908
14364
  // src/types/patient/patient-requirements.ts
13909
14365
  var PatientInstructionStatus = /* @__PURE__ */ ((PatientInstructionStatus2) => {
@@ -13933,13 +14389,13 @@ var PatientRequirementsService = class extends BaseService {
13933
14389
  super(db, auth, app);
13934
14390
  }
13935
14391
  getPatientRequirementsCollectionRef(patientId) {
13936
- return (0, import_firestore44.collection)(
14392
+ return (0, import_firestore45.collection)(
13937
14393
  this.db,
13938
14394
  `patients/${patientId}/${PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME}`
13939
14395
  );
13940
14396
  }
13941
14397
  getPatientRequirementDocRef(patientId, instanceId) {
13942
- return (0, import_firestore44.doc)(
14398
+ return (0, import_firestore45.doc)(
13943
14399
  this.getPatientRequirementsCollectionRef(patientId),
13944
14400
  instanceId
13945
14401
  );
@@ -13952,7 +14408,7 @@ var PatientRequirementsService = class extends BaseService {
13952
14408
  */
13953
14409
  async getPatientRequirementInstance(patientId, instanceId) {
13954
14410
  const docRef = this.getPatientRequirementDocRef(patientId, instanceId);
13955
- const docSnap = await (0, import_firestore44.getDoc)(docRef);
14411
+ const docSnap = await (0, import_firestore45.getDoc)(docRef);
13956
14412
  if (!docSnap.exists()) {
13957
14413
  return null;
13958
14414
  }
@@ -13971,22 +14427,22 @@ var PatientRequirementsService = class extends BaseService {
13971
14427
  */
13972
14428
  async getAllPatientRequirementInstances(patientId, filters, pageLimit = 20, lastVisible) {
13973
14429
  const collRef = this.getPatientRequirementsCollectionRef(patientId);
13974
- let q = (0, import_firestore44.query)(collRef, (0, import_firestore44.orderBy)("createdAt", "desc"));
14430
+ let q = (0, import_firestore45.query)(collRef, (0, import_firestore45.orderBy)("createdAt", "desc"));
13975
14431
  const queryConstraints = [];
13976
14432
  if ((filters == null ? void 0 : filters.appointmentId) && filters.appointmentId !== "all") {
13977
14433
  queryConstraints.push(
13978
- (0, import_firestore44.where)("appointmentId", "==", filters.appointmentId)
14434
+ (0, import_firestore45.where)("appointmentId", "==", filters.appointmentId)
13979
14435
  );
13980
14436
  }
13981
14437
  if ((filters == null ? void 0 : filters.statuses) && filters.statuses.length > 0) {
13982
- queryConstraints.push((0, import_firestore44.where)("overallStatus", "in", filters.statuses));
14438
+ queryConstraints.push((0, import_firestore45.where)("overallStatus", "in", filters.statuses));
13983
14439
  }
13984
14440
  if (lastVisible) {
13985
- queryConstraints.push((0, import_firestore44.startAfter)(lastVisible));
14441
+ queryConstraints.push((0, import_firestore45.startAfter)(lastVisible));
13986
14442
  }
13987
- queryConstraints.push((0, import_firestore44.limit)(pageLimit));
13988
- q = (0, import_firestore44.query)(collRef, ...queryConstraints);
13989
- const snapshot = await (0, import_firestore44.getDocs)(q);
14443
+ queryConstraints.push((0, import_firestore45.limit)(pageLimit));
14444
+ q = (0, import_firestore45.query)(collRef, ...queryConstraints);
14445
+ const snapshot = await (0, import_firestore45.getDocs)(q);
13990
14446
  let requirements = snapshot.docs.map((docSnap) => {
13991
14447
  const data = docSnap.data();
13992
14448
  return { id: docSnap.id, ...data };
@@ -14029,7 +14485,7 @@ var PatientRequirementsService = class extends BaseService {
14029
14485
  */
14030
14486
  async completeInstruction(patientId, instanceId, instructionId) {
14031
14487
  const instanceRef = this.getPatientRequirementDocRef(patientId, instanceId);
14032
- const instanceSnap = await (0, import_firestore44.getDoc)(instanceRef);
14488
+ const instanceSnap = await (0, import_firestore45.getDoc)(instanceRef);
14033
14489
  if (!instanceSnap.exists()) {
14034
14490
  throw new Error(
14035
14491
  `PatientRequirementInstance ${instanceId} not found for patient ${patientId}.`
@@ -14057,7 +14513,7 @@ var PatientRequirementsService = class extends BaseService {
14057
14513
  `Instruction ${instructionId} is in status ${instructionToUpdate.status} and cannot be marked as completed.`
14058
14514
  );
14059
14515
  }
14060
- const now = import_firestore44.Timestamp.now();
14516
+ const now = import_firestore45.Timestamp.now();
14061
14517
  const updatedInstructions = [...instance.instructions];
14062
14518
  updatedInstructions[instructionIndex] = {
14063
14519
  ...instructionToUpdate,
@@ -14084,7 +14540,7 @@ var PatientRequirementsService = class extends BaseService {
14084
14540
  if (newOverallStatus !== instance.overallStatus) {
14085
14541
  updatePayload.overallStatus = newOverallStatus;
14086
14542
  }
14087
- await (0, import_firestore44.updateDoc)(instanceRef, updatePayload);
14543
+ await (0, import_firestore45.updateDoc)(instanceRef, updatePayload);
14088
14544
  return {
14089
14545
  ...instance,
14090
14546
  instructions: updatedInstructions,
@@ -14097,7 +14553,7 @@ var PatientRequirementsService = class extends BaseService {
14097
14553
  };
14098
14554
 
14099
14555
  // src/backoffice/services/brand.service.ts
14100
- var import_firestore45 = require("firebase/firestore");
14556
+ var import_firestore46 = require("firebase/firestore");
14101
14557
 
14102
14558
  // src/backoffice/types/brand.types.ts
14103
14559
  var BRANDS_COLLECTION = "brands";
@@ -14108,7 +14564,7 @@ var BrandService = class extends BaseService {
14108
14564
  * Gets reference to brands collection
14109
14565
  */
14110
14566
  getBrandsRef() {
14111
- return (0, import_firestore45.collection)(this.db, BRANDS_COLLECTION);
14567
+ return (0, import_firestore46.collection)(this.db, BRANDS_COLLECTION);
14112
14568
  }
14113
14569
  /**
14114
14570
  * Creates a new brand
@@ -14121,19 +14577,19 @@ var BrandService = class extends BaseService {
14121
14577
  updatedAt: now,
14122
14578
  isActive: true
14123
14579
  };
14124
- const docRef = await (0, import_firestore45.addDoc)(this.getBrandsRef(), newBrand);
14580
+ const docRef = await (0, import_firestore46.addDoc)(this.getBrandsRef(), newBrand);
14125
14581
  return { id: docRef.id, ...newBrand };
14126
14582
  }
14127
14583
  /**
14128
14584
  * Gets all active brands
14129
14585
  */
14130
14586
  async getAll() {
14131
- const q = (0, import_firestore45.query)(this.getBrandsRef(), (0, import_firestore45.where)("isActive", "==", true));
14132
- const snapshot = await (0, import_firestore45.getDocs)(q);
14587
+ const q = (0, import_firestore46.query)(this.getBrandsRef(), (0, import_firestore46.where)("isActive", "==", true));
14588
+ const snapshot = await (0, import_firestore46.getDocs)(q);
14133
14589
  return snapshot.docs.map(
14134
- (doc34) => ({
14135
- id: doc34.id,
14136
- ...doc34.data()
14590
+ (doc35) => ({
14591
+ id: doc35.id,
14592
+ ...doc35.data()
14137
14593
  })
14138
14594
  );
14139
14595
  }
@@ -14145,8 +14601,8 @@ var BrandService = class extends BaseService {
14145
14601
  ...brand,
14146
14602
  updatedAt: /* @__PURE__ */ new Date()
14147
14603
  };
14148
- const docRef = (0, import_firestore45.doc)(this.getBrandsRef(), brandId);
14149
- await (0, import_firestore45.updateDoc)(docRef, updateData);
14604
+ const docRef = (0, import_firestore46.doc)(this.getBrandsRef(), brandId);
14605
+ await (0, import_firestore46.updateDoc)(docRef, updateData);
14150
14606
  return this.getById(brandId);
14151
14607
  }
14152
14608
  /**
@@ -14161,8 +14617,8 @@ var BrandService = class extends BaseService {
14161
14617
  * Gets a brand by ID
14162
14618
  */
14163
14619
  async getById(brandId) {
14164
- const docRef = (0, import_firestore45.doc)(this.getBrandsRef(), brandId);
14165
- const docSnap = await (0, import_firestore45.getDoc)(docRef);
14620
+ const docRef = (0, import_firestore46.doc)(this.getBrandsRef(), brandId);
14621
+ const docSnap = await (0, import_firestore46.getDoc)(docRef);
14166
14622
  if (!docSnap.exists()) return null;
14167
14623
  return {
14168
14624
  id: docSnap.id,
@@ -14172,7 +14628,7 @@ var BrandService = class extends BaseService {
14172
14628
  };
14173
14629
 
14174
14630
  // src/backoffice/services/category.service.ts
14175
- var import_firestore46 = require("firebase/firestore");
14631
+ var import_firestore47 = require("firebase/firestore");
14176
14632
 
14177
14633
  // src/backoffice/types/category.types.ts
14178
14634
  var CATEGORIES_COLLECTION = "backoffice_categories";
@@ -14183,7 +14639,7 @@ var CategoryService = class extends BaseService {
14183
14639
  * Referenca na Firestore kolekciju kategorija
14184
14640
  */
14185
14641
  get categoriesRef() {
14186
- return (0, import_firestore46.collection)(this.db, CATEGORIES_COLLECTION);
14642
+ return (0, import_firestore47.collection)(this.db, CATEGORIES_COLLECTION);
14187
14643
  }
14188
14644
  /**
14189
14645
  * Kreira novu kategoriju u sistemu
@@ -14198,7 +14654,7 @@ var CategoryService = class extends BaseService {
14198
14654
  updatedAt: now,
14199
14655
  isActive: true
14200
14656
  };
14201
- const docRef = await (0, import_firestore46.addDoc)(this.categoriesRef, newCategory);
14657
+ const docRef = await (0, import_firestore47.addDoc)(this.categoriesRef, newCategory);
14202
14658
  return { id: docRef.id, ...newCategory };
14203
14659
  }
14204
14660
  /**
@@ -14206,12 +14662,12 @@ var CategoryService = class extends BaseService {
14206
14662
  * @returns Lista aktivnih kategorija
14207
14663
  */
14208
14664
  async getAll() {
14209
- const q = (0, import_firestore46.query)(this.categoriesRef, (0, import_firestore46.where)("isActive", "==", true));
14210
- const snapshot = await (0, import_firestore46.getDocs)(q);
14665
+ const q = (0, import_firestore47.query)(this.categoriesRef, (0, import_firestore47.where)("isActive", "==", true));
14666
+ const snapshot = await (0, import_firestore47.getDocs)(q);
14211
14667
  return snapshot.docs.map(
14212
- (doc34) => ({
14213
- id: doc34.id,
14214
- ...doc34.data()
14668
+ (doc35) => ({
14669
+ id: doc35.id,
14670
+ ...doc35.data()
14215
14671
  })
14216
14672
  );
14217
14673
  }
@@ -14221,16 +14677,16 @@ var CategoryService = class extends BaseService {
14221
14677
  * @returns Lista kategorija koje pripadaju traženoj familiji
14222
14678
  */
14223
14679
  async getAllByFamily(family) {
14224
- const q = (0, import_firestore46.query)(
14680
+ const q = (0, import_firestore47.query)(
14225
14681
  this.categoriesRef,
14226
- (0, import_firestore46.where)("family", "==", family),
14227
- (0, import_firestore46.where)("isActive", "==", true)
14682
+ (0, import_firestore47.where)("family", "==", family),
14683
+ (0, import_firestore47.where)("isActive", "==", true)
14228
14684
  );
14229
- const snapshot = await (0, import_firestore46.getDocs)(q);
14685
+ const snapshot = await (0, import_firestore47.getDocs)(q);
14230
14686
  return snapshot.docs.map(
14231
- (doc34) => ({
14232
- id: doc34.id,
14233
- ...doc34.data()
14687
+ (doc35) => ({
14688
+ id: doc35.id,
14689
+ ...doc35.data()
14234
14690
  })
14235
14691
  );
14236
14692
  }
@@ -14245,8 +14701,8 @@ var CategoryService = class extends BaseService {
14245
14701
  ...category,
14246
14702
  updatedAt: /* @__PURE__ */ new Date()
14247
14703
  };
14248
- const docRef = (0, import_firestore46.doc)(this.categoriesRef, id);
14249
- await (0, import_firestore46.updateDoc)(docRef, updateData);
14704
+ const docRef = (0, import_firestore47.doc)(this.categoriesRef, id);
14705
+ await (0, import_firestore47.updateDoc)(docRef, updateData);
14250
14706
  return this.getById(id);
14251
14707
  }
14252
14708
  /**
@@ -14262,8 +14718,8 @@ var CategoryService = class extends BaseService {
14262
14718
  * @returns Kategorija ili null ako ne postoji
14263
14719
  */
14264
14720
  async getById(id) {
14265
- const docRef = (0, import_firestore46.doc)(this.categoriesRef, id);
14266
- const docSnap = await (0, import_firestore46.getDoc)(docRef);
14721
+ const docRef = (0, import_firestore47.doc)(this.categoriesRef, id);
14722
+ const docSnap = await (0, import_firestore47.getDoc)(docRef);
14267
14723
  if (!docSnap.exists()) return null;
14268
14724
  return {
14269
14725
  id: docSnap.id,
@@ -14273,7 +14729,7 @@ var CategoryService = class extends BaseService {
14273
14729
  };
14274
14730
 
14275
14731
  // src/backoffice/services/subcategory.service.ts
14276
- var import_firestore47 = require("firebase/firestore");
14732
+ var import_firestore48 = require("firebase/firestore");
14277
14733
 
14278
14734
  // src/backoffice/types/subcategory.types.ts
14279
14735
  var SUBCATEGORIES_COLLECTION = "subcategories";
@@ -14285,7 +14741,7 @@ var SubcategoryService = class extends BaseService {
14285
14741
  * @param categoryId - ID roditeljske kategorije
14286
14742
  */
14287
14743
  getSubcategoriesRef(categoryId) {
14288
- return (0, import_firestore47.collection)(
14744
+ return (0, import_firestore48.collection)(
14289
14745
  this.db,
14290
14746
  CATEGORIES_COLLECTION,
14291
14747
  categoryId,
@@ -14307,7 +14763,7 @@ var SubcategoryService = class extends BaseService {
14307
14763
  updatedAt: now,
14308
14764
  isActive: true
14309
14765
  };
14310
- const docRef = await (0, import_firestore47.addDoc)(
14766
+ const docRef = await (0, import_firestore48.addDoc)(
14311
14767
  this.getSubcategoriesRef(categoryId),
14312
14768
  newSubcategory
14313
14769
  );
@@ -14319,15 +14775,15 @@ var SubcategoryService = class extends BaseService {
14319
14775
  * @returns Lista aktivnih podkategorija
14320
14776
  */
14321
14777
  async getAllByCategoryId(categoryId) {
14322
- const q = (0, import_firestore47.query)(
14778
+ const q = (0, import_firestore48.query)(
14323
14779
  this.getSubcategoriesRef(categoryId),
14324
- (0, import_firestore47.where)("isActive", "==", true)
14780
+ (0, import_firestore48.where)("isActive", "==", true)
14325
14781
  );
14326
- const snapshot = await (0, import_firestore47.getDocs)(q);
14782
+ const snapshot = await (0, import_firestore48.getDocs)(q);
14327
14783
  return snapshot.docs.map(
14328
- (doc34) => ({
14329
- id: doc34.id,
14330
- ...doc34.data()
14784
+ (doc35) => ({
14785
+ id: doc35.id,
14786
+ ...doc35.data()
14331
14787
  })
14332
14788
  );
14333
14789
  }
@@ -14343,8 +14799,8 @@ var SubcategoryService = class extends BaseService {
14343
14799
  ...subcategory,
14344
14800
  updatedAt: /* @__PURE__ */ new Date()
14345
14801
  };
14346
- const docRef = (0, import_firestore47.doc)(this.getSubcategoriesRef(categoryId), subcategoryId);
14347
- await (0, import_firestore47.updateDoc)(docRef, updateData);
14802
+ const docRef = (0, import_firestore48.doc)(this.getSubcategoriesRef(categoryId), subcategoryId);
14803
+ await (0, import_firestore48.updateDoc)(docRef, updateData);
14348
14804
  return this.getById(categoryId, subcategoryId);
14349
14805
  }
14350
14806
  /**
@@ -14362,8 +14818,8 @@ var SubcategoryService = class extends BaseService {
14362
14818
  * @returns Podkategorija ili null ako ne postoji
14363
14819
  */
14364
14820
  async getById(categoryId, subcategoryId) {
14365
- const docRef = (0, import_firestore47.doc)(this.getSubcategoriesRef(categoryId), subcategoryId);
14366
- const docSnap = await (0, import_firestore47.getDoc)(docRef);
14821
+ const docRef = (0, import_firestore48.doc)(this.getSubcategoriesRef(categoryId), subcategoryId);
14822
+ const docSnap = await (0, import_firestore48.getDoc)(docRef);
14367
14823
  if (!docSnap.exists()) return null;
14368
14824
  return {
14369
14825
  id: docSnap.id,
@@ -14373,7 +14829,7 @@ var SubcategoryService = class extends BaseService {
14373
14829
  };
14374
14830
 
14375
14831
  // src/backoffice/services/technology.service.ts
14376
- var import_firestore48 = require("firebase/firestore");
14832
+ var import_firestore49 = require("firebase/firestore");
14377
14833
  var DEFAULT_CERTIFICATION_REQUIREMENT = {
14378
14834
  minimumLevel: "aesthetician" /* AESTHETICIAN */,
14379
14835
  requiredSpecialties: []
@@ -14383,7 +14839,7 @@ var TechnologyService = class extends BaseService {
14383
14839
  * Vraća referencu na Firestore kolekciju tehnologija
14384
14840
  */
14385
14841
  getTechnologiesRef() {
14386
- return (0, import_firestore48.collection)(this.db, TECHNOLOGIES_COLLECTION);
14842
+ return (0, import_firestore49.collection)(this.db, TECHNOLOGIES_COLLECTION);
14387
14843
  }
14388
14844
  /**
14389
14845
  * Kreira novu tehnologiju
@@ -14406,7 +14862,7 @@ var TechnologyService = class extends BaseService {
14406
14862
  benefits: technology.benefits || [],
14407
14863
  certificationRequirement: technology.certificationRequirement || DEFAULT_CERTIFICATION_REQUIREMENT
14408
14864
  };
14409
- const docRef = await (0, import_firestore48.addDoc)(this.getTechnologiesRef(), newTechnology);
14865
+ const docRef = await (0, import_firestore49.addDoc)(this.getTechnologiesRef(), newTechnology);
14410
14866
  return { id: docRef.id, ...newTechnology };
14411
14867
  }
14412
14868
  /**
@@ -14414,12 +14870,12 @@ var TechnologyService = class extends BaseService {
14414
14870
  * @returns Lista aktivnih tehnologija
14415
14871
  */
14416
14872
  async getAll() {
14417
- const q = (0, import_firestore48.query)(this.getTechnologiesRef(), (0, import_firestore48.where)("isActive", "==", true));
14418
- const snapshot = await (0, import_firestore48.getDocs)(q);
14873
+ const q = (0, import_firestore49.query)(this.getTechnologiesRef(), (0, import_firestore49.where)("isActive", "==", true));
14874
+ const snapshot = await (0, import_firestore49.getDocs)(q);
14419
14875
  return snapshot.docs.map(
14420
- (doc34) => ({
14421
- id: doc34.id,
14422
- ...doc34.data()
14876
+ (doc35) => ({
14877
+ id: doc35.id,
14878
+ ...doc35.data()
14423
14879
  })
14424
14880
  );
14425
14881
  }
@@ -14429,16 +14885,16 @@ var TechnologyService = class extends BaseService {
14429
14885
  * @returns Lista aktivnih tehnologija
14430
14886
  */
14431
14887
  async getAllByFamily(family) {
14432
- const q = (0, import_firestore48.query)(
14888
+ const q = (0, import_firestore49.query)(
14433
14889
  this.getTechnologiesRef(),
14434
- (0, import_firestore48.where)("isActive", "==", true),
14435
- (0, import_firestore48.where)("family", "==", family)
14890
+ (0, import_firestore49.where)("isActive", "==", true),
14891
+ (0, import_firestore49.where)("family", "==", family)
14436
14892
  );
14437
- const snapshot = await (0, import_firestore48.getDocs)(q);
14893
+ const snapshot = await (0, import_firestore49.getDocs)(q);
14438
14894
  return snapshot.docs.map(
14439
- (doc34) => ({
14440
- id: doc34.id,
14441
- ...doc34.data()
14895
+ (doc35) => ({
14896
+ id: doc35.id,
14897
+ ...doc35.data()
14442
14898
  })
14443
14899
  );
14444
14900
  }
@@ -14448,16 +14904,16 @@ var TechnologyService = class extends BaseService {
14448
14904
  * @returns Lista aktivnih tehnologija
14449
14905
  */
14450
14906
  async getAllByCategoryId(categoryId) {
14451
- const q = (0, import_firestore48.query)(
14907
+ const q = (0, import_firestore49.query)(
14452
14908
  this.getTechnologiesRef(),
14453
- (0, import_firestore48.where)("isActive", "==", true),
14454
- (0, import_firestore48.where)("categoryId", "==", categoryId)
14909
+ (0, import_firestore49.where)("isActive", "==", true),
14910
+ (0, import_firestore49.where)("categoryId", "==", categoryId)
14455
14911
  );
14456
- const snapshot = await (0, import_firestore48.getDocs)(q);
14912
+ const snapshot = await (0, import_firestore49.getDocs)(q);
14457
14913
  return snapshot.docs.map(
14458
- (doc34) => ({
14459
- id: doc34.id,
14460
- ...doc34.data()
14914
+ (doc35) => ({
14915
+ id: doc35.id,
14916
+ ...doc35.data()
14461
14917
  })
14462
14918
  );
14463
14919
  }
@@ -14467,16 +14923,16 @@ var TechnologyService = class extends BaseService {
14467
14923
  * @returns Lista aktivnih tehnologija
14468
14924
  */
14469
14925
  async getAllBySubcategoryId(subcategoryId) {
14470
- const q = (0, import_firestore48.query)(
14926
+ const q = (0, import_firestore49.query)(
14471
14927
  this.getTechnologiesRef(),
14472
- (0, import_firestore48.where)("isActive", "==", true),
14473
- (0, import_firestore48.where)("subcategoryId", "==", subcategoryId)
14928
+ (0, import_firestore49.where)("isActive", "==", true),
14929
+ (0, import_firestore49.where)("subcategoryId", "==", subcategoryId)
14474
14930
  );
14475
- const snapshot = await (0, import_firestore48.getDocs)(q);
14931
+ const snapshot = await (0, import_firestore49.getDocs)(q);
14476
14932
  return snapshot.docs.map(
14477
- (doc34) => ({
14478
- id: doc34.id,
14479
- ...doc34.data()
14933
+ (doc35) => ({
14934
+ id: doc35.id,
14935
+ ...doc35.data()
14480
14936
  })
14481
14937
  );
14482
14938
  }
@@ -14491,8 +14947,8 @@ var TechnologyService = class extends BaseService {
14491
14947
  ...technology,
14492
14948
  updatedAt: /* @__PURE__ */ new Date()
14493
14949
  };
14494
- const docRef = (0, import_firestore48.doc)(this.getTechnologiesRef(), technologyId);
14495
- await (0, import_firestore48.updateDoc)(docRef, updateData);
14950
+ const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
14951
+ await (0, import_firestore49.updateDoc)(docRef, updateData);
14496
14952
  return this.getById(technologyId);
14497
14953
  }
14498
14954
  /**
@@ -14510,8 +14966,8 @@ var TechnologyService = class extends BaseService {
14510
14966
  * @returns Tehnologija ili null ako ne postoji
14511
14967
  */
14512
14968
  async getById(technologyId) {
14513
- const docRef = (0, import_firestore48.doc)(this.getTechnologiesRef(), technologyId);
14514
- const docSnap = await (0, import_firestore48.getDoc)(docRef);
14969
+ const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
14970
+ const docSnap = await (0, import_firestore49.getDoc)(docRef);
14515
14971
  if (!docSnap.exists()) return null;
14516
14972
  return {
14517
14973
  id: docSnap.id,
@@ -14525,10 +14981,10 @@ var TechnologyService = class extends BaseService {
14525
14981
  * @returns Ažurirana tehnologija sa novim zahtevom
14526
14982
  */
14527
14983
  async addRequirement(technologyId, requirement) {
14528
- const docRef = (0, import_firestore48.doc)(this.getTechnologiesRef(), technologyId);
14984
+ const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
14529
14985
  const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
14530
- await (0, import_firestore48.updateDoc)(docRef, {
14531
- [requirementType]: (0, import_firestore48.arrayUnion)(requirement),
14986
+ await (0, import_firestore49.updateDoc)(docRef, {
14987
+ [requirementType]: (0, import_firestore49.arrayUnion)(requirement),
14532
14988
  updatedAt: /* @__PURE__ */ new Date()
14533
14989
  });
14534
14990
  return this.getById(technologyId);
@@ -14540,10 +14996,10 @@ var TechnologyService = class extends BaseService {
14540
14996
  * @returns Ažurirana tehnologija bez uklonjenog zahteva
14541
14997
  */
14542
14998
  async removeRequirement(technologyId, requirement) {
14543
- const docRef = (0, import_firestore48.doc)(this.getTechnologiesRef(), technologyId);
14999
+ const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
14544
15000
  const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
14545
- await (0, import_firestore48.updateDoc)(docRef, {
14546
- [requirementType]: (0, import_firestore48.arrayRemove)(requirement),
15001
+ await (0, import_firestore49.updateDoc)(docRef, {
15002
+ [requirementType]: (0, import_firestore49.arrayRemove)(requirement),
14547
15003
  updatedAt: /* @__PURE__ */ new Date()
14548
15004
  });
14549
15005
  return this.getById(technologyId);
@@ -14580,9 +15036,9 @@ var TechnologyService = class extends BaseService {
14580
15036
  * @returns Ažurirana tehnologija
14581
15037
  */
14582
15038
  async addBlockingCondition(technologyId, condition) {
14583
- const docRef = (0, import_firestore48.doc)(this.getTechnologiesRef(), technologyId);
14584
- await (0, import_firestore48.updateDoc)(docRef, {
14585
- blockingConditions: (0, import_firestore48.arrayUnion)(condition),
15039
+ const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
15040
+ await (0, import_firestore49.updateDoc)(docRef, {
15041
+ blockingConditions: (0, import_firestore49.arrayUnion)(condition),
14586
15042
  updatedAt: /* @__PURE__ */ new Date()
14587
15043
  });
14588
15044
  return this.getById(technologyId);
@@ -14594,9 +15050,9 @@ var TechnologyService = class extends BaseService {
14594
15050
  * @returns Ažurirana tehnologija
14595
15051
  */
14596
15052
  async removeBlockingCondition(technologyId, condition) {
14597
- const docRef = (0, import_firestore48.doc)(this.getTechnologiesRef(), technologyId);
14598
- await (0, import_firestore48.updateDoc)(docRef, {
14599
- blockingConditions: (0, import_firestore48.arrayRemove)(condition),
15053
+ const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
15054
+ await (0, import_firestore49.updateDoc)(docRef, {
15055
+ blockingConditions: (0, import_firestore49.arrayRemove)(condition),
14600
15056
  updatedAt: /* @__PURE__ */ new Date()
14601
15057
  });
14602
15058
  return this.getById(technologyId);
@@ -14608,9 +15064,9 @@ var TechnologyService = class extends BaseService {
14608
15064
  * @returns Ažurirana tehnologija
14609
15065
  */
14610
15066
  async addContraindication(technologyId, contraindication) {
14611
- const docRef = (0, import_firestore48.doc)(this.getTechnologiesRef(), technologyId);
14612
- await (0, import_firestore48.updateDoc)(docRef, {
14613
- contraindications: (0, import_firestore48.arrayUnion)(contraindication),
15067
+ const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
15068
+ await (0, import_firestore49.updateDoc)(docRef, {
15069
+ contraindications: (0, import_firestore49.arrayUnion)(contraindication),
14614
15070
  updatedAt: /* @__PURE__ */ new Date()
14615
15071
  });
14616
15072
  return this.getById(technologyId);
@@ -14622,9 +15078,9 @@ var TechnologyService = class extends BaseService {
14622
15078
  * @returns Ažurirana tehnologija
14623
15079
  */
14624
15080
  async removeContraindication(technologyId, contraindication) {
14625
- const docRef = (0, import_firestore48.doc)(this.getTechnologiesRef(), technologyId);
14626
- await (0, import_firestore48.updateDoc)(docRef, {
14627
- contraindications: (0, import_firestore48.arrayRemove)(contraindication),
15081
+ const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
15082
+ await (0, import_firestore49.updateDoc)(docRef, {
15083
+ contraindications: (0, import_firestore49.arrayRemove)(contraindication),
14628
15084
  updatedAt: /* @__PURE__ */ new Date()
14629
15085
  });
14630
15086
  return this.getById(technologyId);
@@ -14636,9 +15092,9 @@ var TechnologyService = class extends BaseService {
14636
15092
  * @returns Ažurirana tehnologija
14637
15093
  */
14638
15094
  async addBenefit(technologyId, benefit) {
14639
- const docRef = (0, import_firestore48.doc)(this.getTechnologiesRef(), technologyId);
14640
- await (0, import_firestore48.updateDoc)(docRef, {
14641
- benefits: (0, import_firestore48.arrayUnion)(benefit),
15095
+ const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
15096
+ await (0, import_firestore49.updateDoc)(docRef, {
15097
+ benefits: (0, import_firestore49.arrayUnion)(benefit),
14642
15098
  updatedAt: /* @__PURE__ */ new Date()
14643
15099
  });
14644
15100
  return this.getById(technologyId);
@@ -14650,9 +15106,9 @@ var TechnologyService = class extends BaseService {
14650
15106
  * @returns Ažurirana tehnologija
14651
15107
  */
14652
15108
  async removeBenefit(technologyId, benefit) {
14653
- const docRef = (0, import_firestore48.doc)(this.getTechnologiesRef(), technologyId);
14654
- await (0, import_firestore48.updateDoc)(docRef, {
14655
- benefits: (0, import_firestore48.arrayRemove)(benefit),
15109
+ const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
15110
+ await (0, import_firestore49.updateDoc)(docRef, {
15111
+ benefits: (0, import_firestore49.arrayRemove)(benefit),
14656
15112
  updatedAt: /* @__PURE__ */ new Date()
14657
15113
  });
14658
15114
  return this.getById(technologyId);
@@ -14691,8 +15147,8 @@ var TechnologyService = class extends BaseService {
14691
15147
  * @returns Ažurirana tehnologija
14692
15148
  */
14693
15149
  async updateCertificationRequirement(technologyId, certificationRequirement) {
14694
- const docRef = (0, import_firestore48.doc)(this.getTechnologiesRef(), technologyId);
14695
- await (0, import_firestore48.updateDoc)(docRef, {
15150
+ const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
15151
+ await (0, import_firestore49.updateDoc)(docRef, {
14696
15152
  certificationRequirement,
14697
15153
  updatedAt: /* @__PURE__ */ new Date()
14698
15154
  });
@@ -14792,7 +15248,7 @@ var TechnologyService = class extends BaseService {
14792
15248
  };
14793
15249
 
14794
15250
  // src/backoffice/services/product.service.ts
14795
- var import_firestore49 = require("firebase/firestore");
15251
+ var import_firestore50 = require("firebase/firestore");
14796
15252
 
14797
15253
  // src/backoffice/types/product.types.ts
14798
15254
  var PRODUCTS_COLLECTION = "products";
@@ -14805,7 +15261,7 @@ var ProductService = class extends BaseService {
14805
15261
  * @returns Firestore collection reference
14806
15262
  */
14807
15263
  getProductsRef(technologyId) {
14808
- return (0, import_firestore49.collection)(
15264
+ return (0, import_firestore50.collection)(
14809
15265
  this.db,
14810
15266
  TECHNOLOGIES_COLLECTION,
14811
15267
  technologyId,
@@ -14825,7 +15281,7 @@ var ProductService = class extends BaseService {
14825
15281
  updatedAt: now,
14826
15282
  isActive: true
14827
15283
  };
14828
- const productRef = await (0, import_firestore49.addDoc)(
15284
+ const productRef = await (0, import_firestore50.addDoc)(
14829
15285
  this.getProductsRef(technologyId),
14830
15286
  newProduct
14831
15287
  );
@@ -14835,15 +15291,15 @@ var ProductService = class extends BaseService {
14835
15291
  * Gets all products for a technology
14836
15292
  */
14837
15293
  async getAllByTechnology(technologyId) {
14838
- const q = (0, import_firestore49.query)(
15294
+ const q = (0, import_firestore50.query)(
14839
15295
  this.getProductsRef(technologyId),
14840
- (0, import_firestore49.where)("isActive", "==", true)
15296
+ (0, import_firestore50.where)("isActive", "==", true)
14841
15297
  );
14842
- const snapshot = await (0, import_firestore49.getDocs)(q);
15298
+ const snapshot = await (0, import_firestore50.getDocs)(q);
14843
15299
  return snapshot.docs.map(
14844
- (doc34) => ({
14845
- id: doc34.id,
14846
- ...doc34.data()
15300
+ (doc35) => ({
15301
+ id: doc35.id,
15302
+ ...doc35.data()
14847
15303
  })
14848
15304
  );
14849
15305
  }
@@ -14851,21 +15307,21 @@ var ProductService = class extends BaseService {
14851
15307
  * Gets all products for a brand by filtering through all technologies
14852
15308
  */
14853
15309
  async getAllByBrand(brandId) {
14854
- const allTechnologiesRef = (0, import_firestore49.collection)(this.db, TECHNOLOGIES_COLLECTION);
14855
- const technologiesSnapshot = await (0, import_firestore49.getDocs)(allTechnologiesRef);
15310
+ const allTechnologiesRef = (0, import_firestore50.collection)(this.db, TECHNOLOGIES_COLLECTION);
15311
+ const technologiesSnapshot = await (0, import_firestore50.getDocs)(allTechnologiesRef);
14856
15312
  const products = [];
14857
15313
  for (const techDoc of technologiesSnapshot.docs) {
14858
- const q = (0, import_firestore49.query)(
15314
+ const q = (0, import_firestore50.query)(
14859
15315
  this.getProductsRef(techDoc.id),
14860
- (0, import_firestore49.where)("brandId", "==", brandId),
14861
- (0, import_firestore49.where)("isActive", "==", true)
15316
+ (0, import_firestore50.where)("brandId", "==", brandId),
15317
+ (0, import_firestore50.where)("isActive", "==", true)
14862
15318
  );
14863
- const snapshot = await (0, import_firestore49.getDocs)(q);
15319
+ const snapshot = await (0, import_firestore50.getDocs)(q);
14864
15320
  products.push(
14865
15321
  ...snapshot.docs.map(
14866
- (doc34) => ({
14867
- id: doc34.id,
14868
- ...doc34.data()
15322
+ (doc35) => ({
15323
+ id: doc35.id,
15324
+ ...doc35.data()
14869
15325
  })
14870
15326
  )
14871
15327
  );
@@ -14880,8 +15336,8 @@ var ProductService = class extends BaseService {
14880
15336
  ...product,
14881
15337
  updatedAt: /* @__PURE__ */ new Date()
14882
15338
  };
14883
- const docRef = (0, import_firestore49.doc)(this.getProductsRef(technologyId), productId);
14884
- await (0, import_firestore49.updateDoc)(docRef, updateData);
15339
+ const docRef = (0, import_firestore50.doc)(this.getProductsRef(technologyId), productId);
15340
+ await (0, import_firestore50.updateDoc)(docRef, updateData);
14885
15341
  return this.getById(technologyId, productId);
14886
15342
  }
14887
15343
  /**
@@ -14896,8 +15352,8 @@ var ProductService = class extends BaseService {
14896
15352
  * Gets a product by ID
14897
15353
  */
14898
15354
  async getById(technologyId, productId) {
14899
- const docRef = (0, import_firestore49.doc)(this.getProductsRef(technologyId), productId);
14900
- const docSnap = await (0, import_firestore49.getDoc)(docRef);
15355
+ const docRef = (0, import_firestore50.doc)(this.getProductsRef(technologyId), productId);
15356
+ const docSnap = await (0, import_firestore50.getDoc)(docRef);
14901
15357
  if (!docSnap.exists()) return null;
14902
15358
  return {
14903
15359
  id: docSnap.id,
@@ -15062,6 +15518,7 @@ var RequirementType = /* @__PURE__ */ ((RequirementType2) => {
15062
15518
  PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME,
15063
15519
  PATIENT_SENSITIVE_INFO_COLLECTION,
15064
15520
  PRACTITIONERS_COLLECTION,
15521
+ PRACTITIONER_INVITES_COLLECTION,
15065
15522
  PROCEDURES_COLLECTION,
15066
15523
  PatientInstructionStatus,
15067
15524
  PatientRequirementOverallStatus,
@@ -15069,6 +15526,8 @@ var RequirementType = /* @__PURE__ */ ((RequirementType2) => {
15069
15526
  PatientService,
15070
15527
  PaymentStatus,
15071
15528
  PracticeType,
15529
+ PractitionerInviteService,
15530
+ PractitionerInviteStatus,
15072
15531
  PractitionerService,
15073
15532
  PractitionerStatus,
15074
15533
  PractitionerTokenStatus,