@blackcode_sa/metaestetics-api 1.5.3 → 1.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/backoffice/index.d.mts +1306 -63
  2. package/dist/backoffice/index.d.ts +1306 -63
  3. package/dist/backoffice/index.js +35 -26
  4. package/dist/backoffice/index.mjs +35 -26
  5. package/dist/index.d.mts +165 -8
  6. package/dist/index.d.ts +165 -8
  7. package/dist/index.js +726 -414
  8. package/dist/index.mjs +772 -451
  9. package/package.json +1 -1
  10. package/src/backoffice/services/brand.service.ts +2 -4
  11. package/src/backoffice/services/category.service.ts +2 -7
  12. package/src/backoffice/services/product.service.ts +5 -7
  13. package/src/backoffice/services/requirement.service.ts +6 -7
  14. package/src/backoffice/services/subcategory.service.ts +11 -8
  15. package/src/backoffice/services/technology.service.ts +6 -11
  16. package/src/backoffice/types/brand.types.ts +5 -0
  17. package/src/backoffice/types/category.types.ts +5 -0
  18. package/src/backoffice/types/documentation-templates.types.ts +4 -0
  19. package/src/backoffice/types/product.types.ts +5 -0
  20. package/src/backoffice/types/requirement.types.ts +5 -0
  21. package/src/backoffice/types/subcategory.types.ts +5 -0
  22. package/src/backoffice/types/technology.types.ts +10 -0
  23. package/src/backoffice/validations/schemas.ts +2 -0
  24. package/src/errors/auth.errors.ts +7 -0
  25. package/src/index.ts +59 -70
  26. package/src/services/auth.service.ts +94 -0
  27. package/src/services/clinic/clinic.service.ts +6 -0
  28. package/src/services/documentation-templates/documentation-template.service.ts +4 -1
  29. package/src/services/procedure/procedure.service.ts +238 -0
  30. package/src/types/documentation-templates/index.ts +5 -0
  31. package/src/types/procedure/index.ts +104 -0
  32. package/src/validations/procedure.schema.ts +58 -0
package/dist/index.js CHANGED
@@ -75,6 +75,7 @@ __export(index_exports, {
75
75
  PractitionerTokenStatus: () => PractitionerTokenStatus,
76
76
  PricingMeasure: () => PricingMeasure,
77
77
  ProcedureFamily: () => ProcedureFamily,
78
+ ProcedureService: () => ProcedureService,
78
79
  REGISTER_TOKENS_COLLECTION: () => REGISTER_TOKENS_COLLECTION,
79
80
  SYNCED_CALENDARS_COLLECTION: () => SYNCED_CALENDARS_COLLECTION,
80
81
  SubscriptionModel: () => SubscriptionModel,
@@ -626,6 +627,12 @@ var AUTH_ERRORS = {
626
627
  "AUTH/INVALID_CREDENTIAL",
627
628
  401
628
629
  ),
630
+ // Resource not found
631
+ NOT_FOUND: new AuthError(
632
+ "The requested resource was not found",
633
+ "AUTH/NOT_FOUND",
634
+ 404
635
+ ),
629
636
  // Detailed password validation errors
630
637
  PASSWORD_LENGTH_ERROR: new AuthError(
631
638
  "Password must be at least 8 characters long",
@@ -1427,9 +1434,9 @@ var addAllergyUtil = async (db, patientId, data, userRef) => {
1427
1434
  var updateAllergyUtil = async (db, patientId, data, userRef) => {
1428
1435
  const validatedData = updateAllergySchema.parse(data);
1429
1436
  const { allergyIndex, ...updateData } = validatedData;
1430
- const doc20 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1431
- if (!doc20.exists()) throw new Error("Medical info not found");
1432
- const medicalInfo = doc20.data();
1437
+ const doc21 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1438
+ if (!doc21.exists()) throw new Error("Medical info not found");
1439
+ const medicalInfo = doc21.data();
1433
1440
  if (allergyIndex >= medicalInfo.allergies.length) {
1434
1441
  throw new Error("Invalid allergy index");
1435
1442
  }
@@ -1445,9 +1452,9 @@ var updateAllergyUtil = async (db, patientId, data, userRef) => {
1445
1452
  });
1446
1453
  };
1447
1454
  var removeAllergyUtil = async (db, patientId, allergyIndex, userRef) => {
1448
- const doc20 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1449
- if (!doc20.exists()) throw new Error("Medical info not found");
1450
- const medicalInfo = doc20.data();
1455
+ const doc21 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1456
+ if (!doc21.exists()) throw new Error("Medical info not found");
1457
+ const medicalInfo = doc21.data();
1451
1458
  if (allergyIndex >= medicalInfo.allergies.length) {
1452
1459
  throw new Error("Invalid allergy index");
1453
1460
  }
@@ -1472,9 +1479,9 @@ var addBlockingConditionUtil = async (db, patientId, data, userRef) => {
1472
1479
  var updateBlockingConditionUtil = async (db, patientId, data, userRef) => {
1473
1480
  const validatedData = updateBlockingConditionSchema.parse(data);
1474
1481
  const { conditionIndex, ...updateData } = validatedData;
1475
- const doc20 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1476
- if (!doc20.exists()) throw new Error("Medical info not found");
1477
- const medicalInfo = doc20.data();
1482
+ const doc21 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1483
+ if (!doc21.exists()) throw new Error("Medical info not found");
1484
+ const medicalInfo = doc21.data();
1478
1485
  if (conditionIndex >= medicalInfo.blockingConditions.length) {
1479
1486
  throw new Error("Invalid blocking condition index");
1480
1487
  }
@@ -1490,9 +1497,9 @@ var updateBlockingConditionUtil = async (db, patientId, data, userRef) => {
1490
1497
  });
1491
1498
  };
1492
1499
  var removeBlockingConditionUtil = async (db, patientId, conditionIndex, userRef) => {
1493
- const doc20 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1494
- if (!doc20.exists()) throw new Error("Medical info not found");
1495
- const medicalInfo = doc20.data();
1500
+ const doc21 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1501
+ if (!doc21.exists()) throw new Error("Medical info not found");
1502
+ const medicalInfo = doc21.data();
1496
1503
  if (conditionIndex >= medicalInfo.blockingConditions.length) {
1497
1504
  throw new Error("Invalid blocking condition index");
1498
1505
  }
@@ -1517,9 +1524,9 @@ var addContraindicationUtil = async (db, patientId, data, userRef) => {
1517
1524
  var updateContraindicationUtil = async (db, patientId, data, userRef) => {
1518
1525
  const validatedData = updateContraindicationSchema.parse(data);
1519
1526
  const { contraindicationIndex, ...updateData } = validatedData;
1520
- const doc20 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1521
- if (!doc20.exists()) throw new Error("Medical info not found");
1522
- const medicalInfo = doc20.data();
1527
+ const doc21 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1528
+ if (!doc21.exists()) throw new Error("Medical info not found");
1529
+ const medicalInfo = doc21.data();
1523
1530
  if (contraindicationIndex >= medicalInfo.contraindications.length) {
1524
1531
  throw new Error("Invalid contraindication index");
1525
1532
  }
@@ -1535,9 +1542,9 @@ var updateContraindicationUtil = async (db, patientId, data, userRef) => {
1535
1542
  });
1536
1543
  };
1537
1544
  var removeContraindicationUtil = async (db, patientId, contraindicationIndex, userRef) => {
1538
- const doc20 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1539
- if (!doc20.exists()) throw new Error("Medical info not found");
1540
- const medicalInfo = doc20.data();
1545
+ const doc21 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1546
+ if (!doc21.exists()) throw new Error("Medical info not found");
1547
+ const medicalInfo = doc21.data();
1541
1548
  if (contraindicationIndex >= medicalInfo.contraindications.length) {
1542
1549
  throw new Error("Invalid contraindication index");
1543
1550
  }
@@ -1562,9 +1569,9 @@ var addMedicationUtil = async (db, patientId, data, userRef) => {
1562
1569
  var updateMedicationUtil = async (db, patientId, data, userRef) => {
1563
1570
  const validatedData = updateMedicationSchema.parse(data);
1564
1571
  const { medicationIndex, ...updateData } = validatedData;
1565
- const doc20 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1566
- if (!doc20.exists()) throw new Error("Medical info not found");
1567
- const medicalInfo = doc20.data();
1572
+ const doc21 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1573
+ if (!doc21.exists()) throw new Error("Medical info not found");
1574
+ const medicalInfo = doc21.data();
1568
1575
  if (medicationIndex >= medicalInfo.currentMedications.length) {
1569
1576
  throw new Error("Invalid medication index");
1570
1577
  }
@@ -1580,9 +1587,9 @@ var updateMedicationUtil = async (db, patientId, data, userRef) => {
1580
1587
  });
1581
1588
  };
1582
1589
  var removeMedicationUtil = async (db, patientId, medicationIndex, userRef) => {
1583
- const doc20 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1584
- if (!doc20.exists()) throw new Error("Medical info not found");
1585
- const medicalInfo = doc20.data();
1590
+ const doc21 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1591
+ if (!doc21.exists()) throw new Error("Medical info not found");
1592
+ const medicalInfo = doc21.data();
1586
1593
  if (medicationIndex >= medicalInfo.currentMedications.length) {
1587
1594
  throw new Error("Invalid medication index");
1588
1595
  }
@@ -2876,7 +2883,7 @@ async function getClinicAdminsByGroup(db, clinicGroupId) {
2876
2883
  (0, import_firestore11.where)("clinicGroupId", "==", clinicGroupId)
2877
2884
  );
2878
2885
  const querySnapshot = await (0, import_firestore11.getDocs)(q);
2879
- return querySnapshot.docs.map((doc20) => doc20.data());
2886
+ return querySnapshot.docs.map((doc21) => doc21.data());
2880
2887
  }
2881
2888
  async function updateClinicAdmin(db, adminId, data) {
2882
2889
  const admin = await getClinicAdmin(db, adminId);
@@ -3531,7 +3538,7 @@ var PractitionerService = class extends BaseService {
3531
3538
  (0, import_firestore13.where)("expiresAt", ">", import_firestore13.Timestamp.now())
3532
3539
  );
3533
3540
  const querySnapshot = await (0, import_firestore13.getDocs)(q);
3534
- return querySnapshot.docs.map((doc20) => doc20.data());
3541
+ return querySnapshot.docs.map((doc21) => doc21.data());
3535
3542
  }
3536
3543
  /**
3537
3544
  * Gets a token by its string value and validates it
@@ -3614,7 +3621,7 @@ var PractitionerService = class extends BaseService {
3614
3621
  (0, import_firestore13.where)("status", "==", "active" /* ACTIVE */)
3615
3622
  );
3616
3623
  const querySnapshot = await (0, import_firestore13.getDocs)(q);
3617
- return querySnapshot.docs.map((doc20) => doc20.data());
3624
+ return querySnapshot.docs.map((doc21) => doc21.data());
3618
3625
  }
3619
3626
  /**
3620
3627
  * Dohvata sve draft zdravstvene radnike za određenu kliniku
@@ -3626,7 +3633,7 @@ var PractitionerService = class extends BaseService {
3626
3633
  (0, import_firestore13.where)("status", "==", "draft" /* DRAFT */)
3627
3634
  );
3628
3635
  const querySnapshot = await (0, import_firestore13.getDocs)(q);
3629
- return querySnapshot.docs.map((doc20) => doc20.data());
3636
+ return querySnapshot.docs.map((doc21) => doc21.data());
3630
3637
  }
3631
3638
  /**
3632
3639
  * Ažurira profil zdravstvenog radnika
@@ -3935,7 +3942,7 @@ var UserService = class extends BaseService {
3935
3942
  ];
3936
3943
  const q = (0, import_firestore14.query)((0, import_firestore14.collection)(this.db, USERS_COLLECTION), ...constraints);
3937
3944
  const querySnapshot = await (0, import_firestore14.getDocs)(q);
3938
- const users = querySnapshot.docs.map((doc20) => doc20.data());
3945
+ const users = querySnapshot.docs.map((doc21) => doc21.data());
3939
3946
  return Promise.all(users.map((userData) => userSchema.parse(userData)));
3940
3947
  }
3941
3948
  /**
@@ -4299,7 +4306,7 @@ async function getAllActiveGroups(db) {
4299
4306
  (0, import_firestore15.where)("isActive", "==", true)
4300
4307
  );
4301
4308
  const querySnapshot = await (0, import_firestore15.getDocs)(q);
4302
- return querySnapshot.docs.map((doc20) => doc20.data());
4309
+ return querySnapshot.docs.map((doc21) => doc21.data());
4303
4310
  }
4304
4311
  async function updateClinicGroup(db, groupId, data, app) {
4305
4312
  console.log("[CLINIC_GROUP] Updating clinic group", { groupId });
@@ -4959,7 +4966,7 @@ async function getClinicsByGroup(db, groupId) {
4959
4966
  (0, import_firestore16.where)("isActive", "==", true)
4960
4967
  );
4961
4968
  const querySnapshot = await (0, import_firestore16.getDocs)(q);
4962
- return querySnapshot.docs.map((doc20) => doc20.data());
4969
+ return querySnapshot.docs.map((doc21) => doc21.data());
4963
4970
  }
4964
4971
  async function updateClinic(db, clinicId, data, adminId, clinicAdminService, app) {
4965
4972
  console.log("[CLINIC] Starting clinic update", { clinicId, adminId });
@@ -5171,7 +5178,7 @@ async function getClinicsByAdmin(db, adminId, options = {}, clinicAdminService,
5171
5178
  }
5172
5179
  const q = (0, import_firestore16.query)((0, import_firestore16.collection)(db, CLINICS_COLLECTION), ...constraints);
5173
5180
  const querySnapshot = await (0, import_firestore16.getDocs)(q);
5174
- return querySnapshot.docs.map((doc20) => doc20.data());
5181
+ return querySnapshot.docs.map((doc21) => doc21.data());
5175
5182
  }
5176
5183
  async function getActiveClinicsByAdmin(db, adminId, clinicAdminService, clinicGroupService) {
5177
5184
  return getClinicsByAdmin(
@@ -5313,8 +5320,8 @@ async function findClinicsInRadius(db, center, radiusInKm, filters) {
5313
5320
  }
5314
5321
  const q = (0, import_firestore18.query)((0, import_firestore18.collection)(db, CLINICS_COLLECTION), ...constraints);
5315
5322
  const querySnapshot = await (0, import_firestore18.getDocs)(q);
5316
- for (const doc20 of querySnapshot.docs) {
5317
- const clinic = doc20.data();
5323
+ for (const doc21 of querySnapshot.docs) {
5324
+ const clinic = doc21.data();
5318
5325
  const distance = (0, import_geofire_common4.distanceBetween)(
5319
5326
  [center.latitude, center.longitude],
5320
5327
  [clinic.location.latitude, clinic.location.longitude]
@@ -5851,6 +5858,77 @@ var AuthService = class extends BaseService {
5851
5858
  );
5852
5859
  return this.userService.getOrCreateUser(firebaseUser);
5853
5860
  }
5861
+ /**
5862
+ * Prijavljuje korisnika sa email-om i lozinkom samo za clinic_admin role
5863
+ * @param email - Email korisnika
5864
+ * @param password - Lozinka korisnika
5865
+ * @returns Objekat koji sadrži korisnika, admin profil i grupu klinika
5866
+ * @throws {AUTH_ERRORS.INVALID_ROLE} Ako korisnik nema clinic_admin rolu
5867
+ * @throws {AUTH_ERRORS.NOT_FOUND} Ako admin profil nije pronađen
5868
+ */
5869
+ async signInClinicAdmin(email, password) {
5870
+ var _a;
5871
+ try {
5872
+ const clinicAdminService = new ClinicAdminService(
5873
+ this.db,
5874
+ this.auth,
5875
+ this.app
5876
+ );
5877
+ const clinicGroupService = new ClinicGroupService(
5878
+ this.db,
5879
+ this.auth,
5880
+ this.app,
5881
+ clinicAdminService
5882
+ );
5883
+ const clinicService = new ClinicService(
5884
+ this.db,
5885
+ this.auth,
5886
+ this.app,
5887
+ clinicGroupService,
5888
+ clinicAdminService
5889
+ );
5890
+ clinicAdminService.setServices(clinicGroupService, clinicService);
5891
+ const { user: firebaseUser } = await (0, import_auth5.signInWithEmailAndPassword)(
5892
+ this.auth,
5893
+ email,
5894
+ password
5895
+ );
5896
+ const user = await this.userService.getOrCreateUser(firebaseUser);
5897
+ if (!((_a = user.roles) == null ? void 0 : _a.includes("clinic_admin" /* CLINIC_ADMIN */))) {
5898
+ console.error("[AUTH] User is not a clinic admin:", user.uid);
5899
+ throw AUTH_ERRORS.INVALID_ROLE;
5900
+ }
5901
+ if (!user.adminProfile) {
5902
+ console.error("[AUTH] User has no admin profile:", user.uid);
5903
+ throw AUTH_ERRORS.NOT_FOUND;
5904
+ }
5905
+ const adminProfile = await clinicAdminService.getClinicAdmin(
5906
+ user.adminProfile
5907
+ );
5908
+ if (!adminProfile) {
5909
+ console.error("[AUTH] Admin profile not found:", user.adminProfile);
5910
+ throw AUTH_ERRORS.NOT_FOUND;
5911
+ }
5912
+ const clinicGroup = await clinicGroupService.getClinicGroup(
5913
+ adminProfile.clinicGroupId
5914
+ );
5915
+ if (!clinicGroup) {
5916
+ console.error(
5917
+ "[AUTH] Clinic group not found:",
5918
+ adminProfile.clinicGroupId
5919
+ );
5920
+ throw AUTH_ERRORS.NOT_FOUND;
5921
+ }
5922
+ return {
5923
+ user,
5924
+ clinicAdmin: adminProfile,
5925
+ clinicGroup
5926
+ };
5927
+ } catch (error) {
5928
+ console.error("[AUTH] Error in signInClinicAdmin:", error);
5929
+ throw error;
5930
+ }
5931
+ }
5854
5932
  /**
5855
5933
  * Prijavljuje korisnika sa Facebook-om
5856
5934
  */
@@ -6175,9 +6253,9 @@ var NotificationService = class extends BaseService {
6175
6253
  (0, import_firestore20.orderBy)("notificationTime", "desc")
6176
6254
  );
6177
6255
  const querySnapshot = await (0, import_firestore20.getDocs)(q);
6178
- return querySnapshot.docs.map((doc20) => ({
6179
- id: doc20.id,
6180
- ...doc20.data()
6256
+ return querySnapshot.docs.map((doc21) => ({
6257
+ id: doc21.id,
6258
+ ...doc21.data()
6181
6259
  }));
6182
6260
  }
6183
6261
  /**
@@ -6191,9 +6269,9 @@ var NotificationService = class extends BaseService {
6191
6269
  (0, import_firestore20.orderBy)("notificationTime", "desc")
6192
6270
  );
6193
6271
  const querySnapshot = await (0, import_firestore20.getDocs)(q);
6194
- return querySnapshot.docs.map((doc20) => ({
6195
- id: doc20.id,
6196
- ...doc20.data()
6272
+ return querySnapshot.docs.map((doc21) => ({
6273
+ id: doc21.id,
6274
+ ...doc21.data()
6197
6275
  }));
6198
6276
  }
6199
6277
  /**
@@ -6265,9 +6343,9 @@ var NotificationService = class extends BaseService {
6265
6343
  (0, import_firestore20.orderBy)("notificationTime", "desc")
6266
6344
  );
6267
6345
  const querySnapshot = await (0, import_firestore20.getDocs)(q);
6268
- return querySnapshot.docs.map((doc20) => ({
6269
- id: doc20.id,
6270
- ...doc20.data()
6346
+ return querySnapshot.docs.map((doc21) => ({
6347
+ id: doc21.id,
6348
+ ...doc21.data()
6271
6349
  }));
6272
6350
  }
6273
6351
  /**
@@ -6280,19 +6358,252 @@ var NotificationService = class extends BaseService {
6280
6358
  (0, import_firestore20.orderBy)("notificationTime", "desc")
6281
6359
  );
6282
6360
  const querySnapshot = await (0, import_firestore20.getDocs)(q);
6283
- return querySnapshot.docs.map((doc20) => ({
6284
- id: doc20.id,
6285
- ...doc20.data()
6361
+ return querySnapshot.docs.map((doc21) => ({
6362
+ id: doc21.id,
6363
+ ...doc21.data()
6286
6364
  }));
6287
6365
  }
6288
6366
  };
6289
6367
 
6290
- // src/services/documentation-templates/documentation-template.service.ts
6368
+ // src/services/procedure/procedure.service.ts
6291
6369
  var import_firestore21 = require("firebase/firestore");
6370
+
6371
+ // src/types/procedure/index.ts
6372
+ var PROCEDURES_COLLECTION = "procedures";
6373
+
6374
+ // src/validations/procedure.schema.ts
6375
+ var import_zod16 = require("zod");
6376
+ var createProcedureSchema = import_zod16.z.object({
6377
+ name: import_zod16.z.string().min(1).max(200),
6378
+ description: import_zod16.z.string().min(1).max(2e3),
6379
+ family: import_zod16.z.nativeEnum(ProcedureFamily),
6380
+ categoryId: import_zod16.z.string().min(1),
6381
+ subcategoryId: import_zod16.z.string().min(1),
6382
+ technologyId: import_zod16.z.string().min(1),
6383
+ productId: import_zod16.z.string().min(1),
6384
+ price: import_zod16.z.number().min(0),
6385
+ currency: import_zod16.z.nativeEnum(Currency),
6386
+ pricingMeasure: import_zod16.z.nativeEnum(PricingMeasure),
6387
+ duration: import_zod16.z.number().min(1).max(480),
6388
+ // Max 8 hours
6389
+ practitionerId: import_zod16.z.string().min(1),
6390
+ clinicBranchId: import_zod16.z.string().min(1)
6391
+ });
6392
+ var updateProcedureSchema = import_zod16.z.object({
6393
+ name: import_zod16.z.string().min(1).max(200).optional(),
6394
+ description: import_zod16.z.string().min(1).max(2e3).optional(),
6395
+ price: import_zod16.z.number().min(0).optional(),
6396
+ currency: import_zod16.z.nativeEnum(Currency).optional(),
6397
+ pricingMeasure: import_zod16.z.nativeEnum(PricingMeasure).optional(),
6398
+ duration: import_zod16.z.number().min(1).max(480).optional(),
6399
+ // Max 8 hours
6400
+ isActive: import_zod16.z.boolean().optional()
6401
+ });
6402
+ var procedureSchema = createProcedureSchema.extend({
6403
+ id: import_zod16.z.string().min(1),
6404
+ category: import_zod16.z.any(),
6405
+ // We'll validate the full category object separately
6406
+ subcategory: import_zod16.z.any(),
6407
+ // We'll validate the full subcategory object separately
6408
+ technology: import_zod16.z.any(),
6409
+ // We'll validate the full technology object separately
6410
+ product: import_zod16.z.any(),
6411
+ // We'll validate the full product object separately
6412
+ blockingConditions: import_zod16.z.array(import_zod16.z.any()),
6413
+ // We'll validate blocking conditions separately
6414
+ treatmentBenefits: import_zod16.z.array(import_zod16.z.any()),
6415
+ // We'll validate treatment benefits separately
6416
+ preRequirements: import_zod16.z.array(import_zod16.z.any()),
6417
+ // We'll validate requirements separately
6418
+ postRequirements: import_zod16.z.array(import_zod16.z.any()),
6419
+ // We'll validate requirements separately
6420
+ certificationRequirement: import_zod16.z.any(),
6421
+ // We'll validate certification requirement separately
6422
+ documentationTemplates: import_zod16.z.array(import_zod16.z.any()),
6423
+ // We'll validate documentation templates separately
6424
+ isActive: import_zod16.z.boolean(),
6425
+ createdAt: import_zod16.z.date(),
6426
+ updatedAt: import_zod16.z.date()
6427
+ });
6428
+
6429
+ // src/backoffice/types/category.types.ts
6430
+ var CATEGORIES_COLLECTION = "backoffice_categories";
6431
+
6432
+ // src/backoffice/types/subcategory.types.ts
6433
+ var SUBCATEGORIES_COLLECTION = "subcategories";
6434
+
6435
+ // src/backoffice/types/technology.types.ts
6436
+ var TECHNOLOGIES_COLLECTION = "technologies";
6437
+
6438
+ // src/backoffice/types/product.types.ts
6439
+ var PRODUCTS_COLLECTION = "products";
6440
+
6441
+ // src/services/procedure/procedure.service.ts
6442
+ var ProcedureService = class extends BaseService {
6443
+ constructor(db, auth, app) {
6444
+ super(db, auth, app);
6445
+ }
6446
+ /**
6447
+ * Creates a new procedure
6448
+ * @param data - The data for creating a new procedure
6449
+ * @returns The created procedure
6450
+ */
6451
+ async createProcedure(data) {
6452
+ const validatedData = createProcedureSchema.parse(data);
6453
+ const [category, subcategory, technology, product] = await Promise.all([
6454
+ this.getCategory(validatedData.categoryId),
6455
+ this.getSubcategory(validatedData.subcategoryId),
6456
+ this.getTechnology(validatedData.technologyId),
6457
+ this.getProduct(validatedData.productId)
6458
+ ]);
6459
+ if (!category || !subcategory || !technology || !product) {
6460
+ throw new Error("One or more required entities not found");
6461
+ }
6462
+ const procedure = {
6463
+ ...validatedData,
6464
+ category,
6465
+ subcategory,
6466
+ technology,
6467
+ product,
6468
+ blockingConditions: technology.blockingConditions,
6469
+ treatmentBenefits: technology.benefits,
6470
+ preRequirements: technology.requirements.pre,
6471
+ postRequirements: technology.requirements.post,
6472
+ certificationRequirement: technology.certificationRequirement,
6473
+ documentationTemplates: technology.documentationTemplates || [],
6474
+ isActive: true,
6475
+ createdAt: /* @__PURE__ */ new Date(),
6476
+ updatedAt: /* @__PURE__ */ new Date()
6477
+ };
6478
+ const id = this.generateId();
6479
+ const docRef = (0, import_firestore21.doc)(this.db, PROCEDURES_COLLECTION, id);
6480
+ await (0, import_firestore21.setDoc)(docRef, {
6481
+ ...procedure,
6482
+ id,
6483
+ createdAt: (0, import_firestore21.serverTimestamp)(),
6484
+ updatedAt: (0, import_firestore21.serverTimestamp)()
6485
+ });
6486
+ return { ...procedure, id };
6487
+ }
6488
+ /**
6489
+ * Gets a procedure by ID
6490
+ * @param id - The ID of the procedure to get
6491
+ * @returns The procedure if found, null otherwise
6492
+ */
6493
+ async getProcedure(id) {
6494
+ const docRef = (0, import_firestore21.doc)(this.db, PROCEDURES_COLLECTION, id);
6495
+ const docSnap = await (0, import_firestore21.getDoc)(docRef);
6496
+ if (!docSnap.exists()) {
6497
+ return null;
6498
+ }
6499
+ return docSnap.data();
6500
+ }
6501
+ /**
6502
+ * Gets all procedures for a clinic branch
6503
+ * @param clinicBranchId - The ID of the clinic branch
6504
+ * @returns List of procedures
6505
+ */
6506
+ async getProceduresByClinicBranch(clinicBranchId) {
6507
+ const q = (0, import_firestore21.query)(
6508
+ (0, import_firestore21.collection)(this.db, PROCEDURES_COLLECTION),
6509
+ (0, import_firestore21.where)("clinicBranchId", "==", clinicBranchId),
6510
+ (0, import_firestore21.where)("isActive", "==", true)
6511
+ );
6512
+ const snapshot = await (0, import_firestore21.getDocs)(q);
6513
+ return snapshot.docs.map((doc21) => doc21.data());
6514
+ }
6515
+ /**
6516
+ * Gets all procedures for a practitioner
6517
+ * @param practitionerId - The ID of the practitioner
6518
+ * @returns List of procedures
6519
+ */
6520
+ async getProceduresByPractitioner(practitionerId) {
6521
+ const q = (0, import_firestore21.query)(
6522
+ (0, import_firestore21.collection)(this.db, PROCEDURES_COLLECTION),
6523
+ (0, import_firestore21.where)("practitionerId", "==", practitionerId),
6524
+ (0, import_firestore21.where)("isActive", "==", true)
6525
+ );
6526
+ const snapshot = await (0, import_firestore21.getDocs)(q);
6527
+ return snapshot.docs.map((doc21) => doc21.data());
6528
+ }
6529
+ /**
6530
+ * Updates a procedure
6531
+ * @param id - The ID of the procedure to update
6532
+ * @param data - The data to update
6533
+ * @returns The updated procedure
6534
+ */
6535
+ async updateProcedure(id, data) {
6536
+ const validatedData = updateProcedureSchema.parse(data);
6537
+ const existingProcedure = await this.getProcedure(id);
6538
+ if (!existingProcedure) {
6539
+ throw new Error(`Procedure with ID ${id} not found`);
6540
+ }
6541
+ const docRef = (0, import_firestore21.doc)(this.db, PROCEDURES_COLLECTION, id);
6542
+ await (0, import_firestore21.updateDoc)(docRef, {
6543
+ ...validatedData,
6544
+ updatedAt: (0, import_firestore21.serverTimestamp)()
6545
+ });
6546
+ return {
6547
+ ...existingProcedure,
6548
+ ...validatedData,
6549
+ updatedAt: /* @__PURE__ */ new Date()
6550
+ };
6551
+ }
6552
+ /**
6553
+ * Deactivates a procedure
6554
+ * @param id - The ID of the procedure to deactivate
6555
+ */
6556
+ async deactivateProcedure(id) {
6557
+ const docRef = (0, import_firestore21.doc)(this.db, PROCEDURES_COLLECTION, id);
6558
+ await (0, import_firestore21.updateDoc)(docRef, {
6559
+ isActive: false,
6560
+ updatedAt: (0, import_firestore21.serverTimestamp)()
6561
+ });
6562
+ }
6563
+ /**
6564
+ * Gets a category by ID
6565
+ * @private
6566
+ */
6567
+ async getCategory(id) {
6568
+ const docRef = (0, import_firestore21.doc)(this.db, CATEGORIES_COLLECTION, id);
6569
+ const docSnap = await (0, import_firestore21.getDoc)(docRef);
6570
+ return docSnap.exists() ? docSnap.data() : null;
6571
+ }
6572
+ /**
6573
+ * Gets a subcategory by ID
6574
+ * @private
6575
+ */
6576
+ async getSubcategory(id) {
6577
+ const docRef = (0, import_firestore21.doc)(this.db, SUBCATEGORIES_COLLECTION, id);
6578
+ const docSnap = await (0, import_firestore21.getDoc)(docRef);
6579
+ return docSnap.exists() ? docSnap.data() : null;
6580
+ }
6581
+ /**
6582
+ * Gets a technology by ID
6583
+ * @private
6584
+ */
6585
+ async getTechnology(id) {
6586
+ const docRef = (0, import_firestore21.doc)(this.db, TECHNOLOGIES_COLLECTION, id);
6587
+ const docSnap = await (0, import_firestore21.getDoc)(docRef);
6588
+ return docSnap.exists() ? docSnap.data() : null;
6589
+ }
6590
+ /**
6591
+ * Gets a product by ID
6592
+ * @private
6593
+ */
6594
+ async getProduct(id) {
6595
+ const docRef = (0, import_firestore21.doc)(this.db, PRODUCTS_COLLECTION, id);
6596
+ const docSnap = await (0, import_firestore21.getDoc)(docRef);
6597
+ return docSnap.exists() ? docSnap.data() : null;
6598
+ }
6599
+ };
6600
+
6601
+ // src/services/documentation-templates/documentation-template.service.ts
6602
+ var import_firestore22 = require("firebase/firestore");
6292
6603
  var DocumentationTemplateService = class extends BaseService {
6293
6604
  constructor() {
6294
6605
  super(...arguments);
6295
- this.collectionRef = (0, import_firestore21.collection)(
6606
+ this.collectionRef = (0, import_firestore22.collection)(
6296
6607
  this.db,
6297
6608
  DOCUMENTATION_TEMPLATES_COLLECTION
6298
6609
  );
@@ -6323,8 +6634,8 @@ var DocumentationTemplateService = class extends BaseService {
6323
6634
  isActive: true,
6324
6635
  tags: validatedData.tags || []
6325
6636
  };
6326
- const docRef = (0, import_firestore21.doc)(this.collectionRef, templateId);
6327
- await (0, import_firestore21.setDoc)(docRef, template);
6637
+ const docRef = (0, import_firestore22.doc)(this.collectionRef, templateId);
6638
+ await (0, import_firestore22.setDoc)(docRef, template);
6328
6639
  return template;
6329
6640
  }
6330
6641
  /**
@@ -6333,8 +6644,8 @@ var DocumentationTemplateService = class extends BaseService {
6333
6644
  * @returns The template or null if not found
6334
6645
  */
6335
6646
  async getTemplateById(templateId) {
6336
- const docRef = (0, import_firestore21.doc)(this.collectionRef, templateId);
6337
- const docSnap = await (0, import_firestore21.getDoc)(docRef);
6647
+ const docRef = (0, import_firestore22.doc)(this.collectionRef, templateId);
6648
+ const docSnap = await (0, import_firestore22.getDoc)(docRef);
6338
6649
  if (!docSnap.exists()) {
6339
6650
  return null;
6340
6651
  }
@@ -6365,8 +6676,8 @@ var DocumentationTemplateService = class extends BaseService {
6365
6676
  updatedAt: Date.now(),
6366
6677
  version: template.version + 1
6367
6678
  };
6368
- const docRef = (0, import_firestore21.doc)(this.collectionRef, templateId);
6369
- await (0, import_firestore21.updateDoc)(docRef, updateData);
6679
+ const docRef = (0, import_firestore22.doc)(this.collectionRef, templateId);
6680
+ await (0, import_firestore22.updateDoc)(docRef, updateData);
6370
6681
  return {
6371
6682
  ...template,
6372
6683
  ...updateData
@@ -6377,8 +6688,8 @@ var DocumentationTemplateService = class extends BaseService {
6377
6688
  * @param templateId - ID of the template to delete
6378
6689
  */
6379
6690
  async deleteTemplate(templateId) {
6380
- const docRef = (0, import_firestore21.doc)(this.collectionRef, templateId);
6381
- await (0, import_firestore21.deleteDoc)(docRef);
6691
+ const docRef = (0, import_firestore22.doc)(this.collectionRef, templateId);
6692
+ await (0, import_firestore22.deleteDoc)(docRef);
6382
6693
  }
6383
6694
  /**
6384
6695
  * Get all active templates
@@ -6387,21 +6698,21 @@ var DocumentationTemplateService = class extends BaseService {
6387
6698
  * @returns Array of templates and the last document for pagination
6388
6699
  */
6389
6700
  async getActiveTemplates(pageSize = 20, lastDoc) {
6390
- let q = (0, import_firestore21.query)(
6701
+ let q = (0, import_firestore22.query)(
6391
6702
  this.collectionRef,
6392
- (0, import_firestore21.where)("isActive", "==", true),
6393
- (0, import_firestore21.orderBy)("updatedAt", "desc"),
6394
- (0, import_firestore21.limit)(pageSize)
6703
+ (0, import_firestore22.where)("isActive", "==", true),
6704
+ (0, import_firestore22.orderBy)("updatedAt", "desc"),
6705
+ (0, import_firestore22.limit)(pageSize)
6395
6706
  );
6396
6707
  if (lastDoc) {
6397
- q = (0, import_firestore21.query)(q, (0, import_firestore21.startAfter)(lastDoc));
6708
+ q = (0, import_firestore22.query)(q, (0, import_firestore22.startAfter)(lastDoc));
6398
6709
  }
6399
- const querySnapshot = await (0, import_firestore21.getDocs)(q);
6710
+ const querySnapshot = await (0, import_firestore22.getDocs)(q);
6400
6711
  const templates = [];
6401
6712
  let lastVisible = null;
6402
- querySnapshot.forEach((doc20) => {
6403
- templates.push(doc20.data());
6404
- lastVisible = doc20;
6713
+ querySnapshot.forEach((doc21) => {
6714
+ templates.push(doc21.data());
6715
+ lastVisible = doc21;
6405
6716
  });
6406
6717
  return {
6407
6718
  templates,
@@ -6416,22 +6727,22 @@ var DocumentationTemplateService = class extends BaseService {
6416
6727
  * @returns Array of templates and the last document for pagination
6417
6728
  */
6418
6729
  async getTemplatesByTags(tags, pageSize = 20, lastDoc) {
6419
- let q = (0, import_firestore21.query)(
6730
+ let q = (0, import_firestore22.query)(
6420
6731
  this.collectionRef,
6421
- (0, import_firestore21.where)("isActive", "==", true),
6422
- (0, import_firestore21.where)("tags", "array-contains-any", tags),
6423
- (0, import_firestore21.orderBy)("updatedAt", "desc"),
6424
- (0, import_firestore21.limit)(pageSize)
6732
+ (0, import_firestore22.where)("isActive", "==", true),
6733
+ (0, import_firestore22.where)("tags", "array-contains-any", tags),
6734
+ (0, import_firestore22.orderBy)("updatedAt", "desc"),
6735
+ (0, import_firestore22.limit)(pageSize)
6425
6736
  );
6426
6737
  if (lastDoc) {
6427
- q = (0, import_firestore21.query)(q, (0, import_firestore21.startAfter)(lastDoc));
6738
+ q = (0, import_firestore22.query)(q, (0, import_firestore22.startAfter)(lastDoc));
6428
6739
  }
6429
- const querySnapshot = await (0, import_firestore21.getDocs)(q);
6740
+ const querySnapshot = await (0, import_firestore22.getDocs)(q);
6430
6741
  const templates = [];
6431
6742
  let lastVisible = null;
6432
- querySnapshot.forEach((doc20) => {
6433
- templates.push(doc20.data());
6434
- lastVisible = doc20;
6743
+ querySnapshot.forEach((doc21) => {
6744
+ templates.push(doc21.data());
6745
+ lastVisible = doc21;
6435
6746
  });
6436
6747
  return {
6437
6748
  templates,
@@ -6446,21 +6757,21 @@ var DocumentationTemplateService = class extends BaseService {
6446
6757
  * @returns Array of templates and the last document for pagination
6447
6758
  */
6448
6759
  async getTemplatesByCreator(userId, pageSize = 20, lastDoc) {
6449
- let q = (0, import_firestore21.query)(
6760
+ let q = (0, import_firestore22.query)(
6450
6761
  this.collectionRef,
6451
- (0, import_firestore21.where)("createdBy", "==", userId),
6452
- (0, import_firestore21.orderBy)("updatedAt", "desc"),
6453
- (0, import_firestore21.limit)(pageSize)
6762
+ (0, import_firestore22.where)("createdBy", "==", userId),
6763
+ (0, import_firestore22.orderBy)("updatedAt", "desc"),
6764
+ (0, import_firestore22.limit)(pageSize)
6454
6765
  );
6455
6766
  if (lastDoc) {
6456
- q = (0, import_firestore21.query)(q, (0, import_firestore21.startAfter)(lastDoc));
6767
+ q = (0, import_firestore22.query)(q, (0, import_firestore22.startAfter)(lastDoc));
6457
6768
  }
6458
- const querySnapshot = await (0, import_firestore21.getDocs)(q);
6769
+ const querySnapshot = await (0, import_firestore22.getDocs)(q);
6459
6770
  const templates = [];
6460
6771
  let lastVisible = null;
6461
- querySnapshot.forEach((doc20) => {
6462
- templates.push(doc20.data());
6463
- lastVisible = doc20;
6772
+ querySnapshot.forEach((doc21) => {
6773
+ templates.push(doc21.data());
6774
+ lastVisible = doc21;
6464
6775
  });
6465
6776
  return {
6466
6777
  templates,
@@ -6470,11 +6781,11 @@ var DocumentationTemplateService = class extends BaseService {
6470
6781
  };
6471
6782
 
6472
6783
  // src/services/documentation-templates/filled-document.service.ts
6473
- var import_firestore22 = require("firebase/firestore");
6784
+ var import_firestore23 = require("firebase/firestore");
6474
6785
  var FilledDocumentService = class extends BaseService {
6475
6786
  constructor(...args) {
6476
6787
  super(...args);
6477
- this.collectionRef = (0, import_firestore22.collection)(
6788
+ this.collectionRef = (0, import_firestore23.collection)(
6478
6789
  this.db,
6479
6790
  FILLED_DOCUMENTS_COLLECTION
6480
6791
  );
@@ -6507,8 +6818,8 @@ var FilledDocumentService = class extends BaseService {
6507
6818
  values: {},
6508
6819
  status: "draft" /* DRAFT */
6509
6820
  };
6510
- const docRef = (0, import_firestore22.doc)(this.collectionRef, documentId);
6511
- await (0, import_firestore22.setDoc)(docRef, filledDocument);
6821
+ const docRef = (0, import_firestore23.doc)(this.collectionRef, documentId);
6822
+ await (0, import_firestore23.setDoc)(docRef, filledDocument);
6512
6823
  return filledDocument;
6513
6824
  }
6514
6825
  /**
@@ -6517,8 +6828,8 @@ var FilledDocumentService = class extends BaseService {
6517
6828
  * @returns The filled document or null if not found
6518
6829
  */
6519
6830
  async getFilledDocumentById(documentId) {
6520
- const docRef = (0, import_firestore22.doc)(this.collectionRef, documentId);
6521
- const docSnap = await (0, import_firestore22.getDoc)(docRef);
6831
+ const docRef = (0, import_firestore23.doc)(this.collectionRef, documentId);
6832
+ const docSnap = await (0, import_firestore23.getDoc)(docRef);
6522
6833
  if (!docSnap.exists()) {
6523
6834
  return null;
6524
6835
  }
@@ -6546,8 +6857,8 @@ var FilledDocumentService = class extends BaseService {
6546
6857
  if (status) {
6547
6858
  updateData.status = status;
6548
6859
  }
6549
- const docRef = (0, import_firestore22.doc)(this.collectionRef, documentId);
6550
- await (0, import_firestore22.updateDoc)(docRef, updateData);
6860
+ const docRef = (0, import_firestore23.doc)(this.collectionRef, documentId);
6861
+ await (0, import_firestore23.updateDoc)(docRef, updateData);
6551
6862
  return {
6552
6863
  ...filledDocument,
6553
6864
  ...updateData
@@ -6561,21 +6872,21 @@ var FilledDocumentService = class extends BaseService {
6561
6872
  * @returns Array of filled documents and the last document for pagination
6562
6873
  */
6563
6874
  async getFilledDocumentsByPatient(patientId, pageSize = 20, lastDoc) {
6564
- let q = (0, import_firestore22.query)(
6875
+ let q = (0, import_firestore23.query)(
6565
6876
  this.collectionRef,
6566
- (0, import_firestore22.where)("patientId", "==", patientId),
6567
- (0, import_firestore22.orderBy)("updatedAt", "desc"),
6568
- (0, import_firestore22.limit)(pageSize)
6877
+ (0, import_firestore23.where)("patientId", "==", patientId),
6878
+ (0, import_firestore23.orderBy)("updatedAt", "desc"),
6879
+ (0, import_firestore23.limit)(pageSize)
6569
6880
  );
6570
6881
  if (lastDoc) {
6571
- q = (0, import_firestore22.query)(q, (0, import_firestore22.startAfter)(lastDoc));
6882
+ q = (0, import_firestore23.query)(q, (0, import_firestore23.startAfter)(lastDoc));
6572
6883
  }
6573
- const querySnapshot = await (0, import_firestore22.getDocs)(q);
6884
+ const querySnapshot = await (0, import_firestore23.getDocs)(q);
6574
6885
  const documents = [];
6575
6886
  let lastVisible = null;
6576
- querySnapshot.forEach((doc20) => {
6577
- documents.push(doc20.data());
6578
- lastVisible = doc20;
6887
+ querySnapshot.forEach((doc21) => {
6888
+ documents.push(doc21.data());
6889
+ lastVisible = doc21;
6579
6890
  });
6580
6891
  return {
6581
6892
  documents,
@@ -6590,21 +6901,21 @@ var FilledDocumentService = class extends BaseService {
6590
6901
  * @returns Array of filled documents and the last document for pagination
6591
6902
  */
6592
6903
  async getFilledDocumentsByPractitioner(practitionerId, pageSize = 20, lastDoc) {
6593
- let q = (0, import_firestore22.query)(
6904
+ let q = (0, import_firestore23.query)(
6594
6905
  this.collectionRef,
6595
- (0, import_firestore22.where)("practitionerId", "==", practitionerId),
6596
- (0, import_firestore22.orderBy)("updatedAt", "desc"),
6597
- (0, import_firestore22.limit)(pageSize)
6906
+ (0, import_firestore23.where)("practitionerId", "==", practitionerId),
6907
+ (0, import_firestore23.orderBy)("updatedAt", "desc"),
6908
+ (0, import_firestore23.limit)(pageSize)
6598
6909
  );
6599
6910
  if (lastDoc) {
6600
- q = (0, import_firestore22.query)(q, (0, import_firestore22.startAfter)(lastDoc));
6911
+ q = (0, import_firestore23.query)(q, (0, import_firestore23.startAfter)(lastDoc));
6601
6912
  }
6602
- const querySnapshot = await (0, import_firestore22.getDocs)(q);
6913
+ const querySnapshot = await (0, import_firestore23.getDocs)(q);
6603
6914
  const documents = [];
6604
6915
  let lastVisible = null;
6605
- querySnapshot.forEach((doc20) => {
6606
- documents.push(doc20.data());
6607
- lastVisible = doc20;
6916
+ querySnapshot.forEach((doc21) => {
6917
+ documents.push(doc21.data());
6918
+ lastVisible = doc21;
6608
6919
  });
6609
6920
  return {
6610
6921
  documents,
@@ -6619,21 +6930,21 @@ var FilledDocumentService = class extends BaseService {
6619
6930
  * @returns Array of filled documents and the last document for pagination
6620
6931
  */
6621
6932
  async getFilledDocumentsByClinic(clinicId, pageSize = 20, lastDoc) {
6622
- let q = (0, import_firestore22.query)(
6933
+ let q = (0, import_firestore23.query)(
6623
6934
  this.collectionRef,
6624
- (0, import_firestore22.where)("clinicId", "==", clinicId),
6625
- (0, import_firestore22.orderBy)("updatedAt", "desc"),
6626
- (0, import_firestore22.limit)(pageSize)
6935
+ (0, import_firestore23.where)("clinicId", "==", clinicId),
6936
+ (0, import_firestore23.orderBy)("updatedAt", "desc"),
6937
+ (0, import_firestore23.limit)(pageSize)
6627
6938
  );
6628
6939
  if (lastDoc) {
6629
- q = (0, import_firestore22.query)(q, (0, import_firestore22.startAfter)(lastDoc));
6940
+ q = (0, import_firestore23.query)(q, (0, import_firestore23.startAfter)(lastDoc));
6630
6941
  }
6631
- const querySnapshot = await (0, import_firestore22.getDocs)(q);
6942
+ const querySnapshot = await (0, import_firestore23.getDocs)(q);
6632
6943
  const documents = [];
6633
6944
  let lastVisible = null;
6634
- querySnapshot.forEach((doc20) => {
6635
- documents.push(doc20.data());
6636
- lastVisible = doc20;
6945
+ querySnapshot.forEach((doc21) => {
6946
+ documents.push(doc21.data());
6947
+ lastVisible = doc21;
6637
6948
  });
6638
6949
  return {
6639
6950
  documents,
@@ -6648,21 +6959,21 @@ var FilledDocumentService = class extends BaseService {
6648
6959
  * @returns Array of filled documents and the last document for pagination
6649
6960
  */
6650
6961
  async getFilledDocumentsByTemplate(templateId, pageSize = 20, lastDoc) {
6651
- let q = (0, import_firestore22.query)(
6962
+ let q = (0, import_firestore23.query)(
6652
6963
  this.collectionRef,
6653
- (0, import_firestore22.where)("templateId", "==", templateId),
6654
- (0, import_firestore22.orderBy)("updatedAt", "desc"),
6655
- (0, import_firestore22.limit)(pageSize)
6964
+ (0, import_firestore23.where)("templateId", "==", templateId),
6965
+ (0, import_firestore23.orderBy)("updatedAt", "desc"),
6966
+ (0, import_firestore23.limit)(pageSize)
6656
6967
  );
6657
6968
  if (lastDoc) {
6658
- q = (0, import_firestore22.query)(q, (0, import_firestore22.startAfter)(lastDoc));
6969
+ q = (0, import_firestore23.query)(q, (0, import_firestore23.startAfter)(lastDoc));
6659
6970
  }
6660
- const querySnapshot = await (0, import_firestore22.getDocs)(q);
6971
+ const querySnapshot = await (0, import_firestore23.getDocs)(q);
6661
6972
  const documents = [];
6662
6973
  let lastVisible = null;
6663
- querySnapshot.forEach((doc20) => {
6664
- documents.push(doc20.data());
6665
- lastVisible = doc20;
6974
+ querySnapshot.forEach((doc21) => {
6975
+ documents.push(doc21.data());
6976
+ lastVisible = doc21;
6666
6977
  });
6667
6978
  return {
6668
6979
  documents,
@@ -6677,21 +6988,21 @@ var FilledDocumentService = class extends BaseService {
6677
6988
  * @returns Array of filled documents and the last document for pagination
6678
6989
  */
6679
6990
  async getFilledDocumentsByStatus(status, pageSize = 20, lastDoc) {
6680
- let q = (0, import_firestore22.query)(
6991
+ let q = (0, import_firestore23.query)(
6681
6992
  this.collectionRef,
6682
- (0, import_firestore22.where)("status", "==", status),
6683
- (0, import_firestore22.orderBy)("updatedAt", "desc"),
6684
- (0, import_firestore22.limit)(pageSize)
6993
+ (0, import_firestore23.where)("status", "==", status),
6994
+ (0, import_firestore23.orderBy)("updatedAt", "desc"),
6995
+ (0, import_firestore23.limit)(pageSize)
6685
6996
  );
6686
6997
  if (lastDoc) {
6687
- q = (0, import_firestore22.query)(q, (0, import_firestore22.startAfter)(lastDoc));
6998
+ q = (0, import_firestore23.query)(q, (0, import_firestore23.startAfter)(lastDoc));
6688
6999
  }
6689
- const querySnapshot = await (0, import_firestore22.getDocs)(q);
7000
+ const querySnapshot = await (0, import_firestore23.getDocs)(q);
6690
7001
  const documents = [];
6691
7002
  let lastVisible = null;
6692
- querySnapshot.forEach((doc20) => {
6693
- documents.push(doc20.data());
6694
- lastVisible = doc20;
7003
+ querySnapshot.forEach((doc21) => {
7004
+ documents.push(doc21.data());
7005
+ lastVisible = doc21;
6695
7006
  });
6696
7007
  return {
6697
7008
  documents,
@@ -6701,7 +7012,7 @@ var FilledDocumentService = class extends BaseService {
6701
7012
  };
6702
7013
 
6703
7014
  // src/services/calendar/calendar-refactored.service.ts
6704
- var import_firestore31 = require("firebase/firestore");
7015
+ var import_firestore32 = require("firebase/firestore");
6705
7016
 
6706
7017
  // src/types/calendar/synced-calendar.types.ts
6707
7018
  var SyncedCalendarProvider = /* @__PURE__ */ ((SyncedCalendarProvider3) => {
@@ -6713,49 +7024,49 @@ var SyncedCalendarProvider = /* @__PURE__ */ ((SyncedCalendarProvider3) => {
6713
7024
  var SYNCED_CALENDARS_COLLECTION = "syncedCalendars";
6714
7025
 
6715
7026
  // src/services/calendar/calendar-refactored.service.ts
6716
- var import_firestore32 = require("firebase/firestore");
7027
+ var import_firestore33 = require("firebase/firestore");
6717
7028
 
6718
7029
  // src/validations/calendar.schema.ts
6719
- var import_zod17 = require("zod");
6720
- var import_firestore24 = require("firebase/firestore");
7030
+ var import_zod18 = require("zod");
7031
+ var import_firestore25 = require("firebase/firestore");
6721
7032
 
6722
7033
  // src/validations/profile-info.schema.ts
6723
- var import_zod16 = require("zod");
6724
- var import_firestore23 = require("firebase/firestore");
6725
- var clinicInfoSchema2 = import_zod16.z.object({
6726
- id: import_zod16.z.string(),
6727
- featuredPhoto: import_zod16.z.string(),
6728
- name: import_zod16.z.string(),
6729
- description: import_zod16.z.string(),
7034
+ var import_zod17 = require("zod");
7035
+ var import_firestore24 = require("firebase/firestore");
7036
+ var clinicInfoSchema2 = import_zod17.z.object({
7037
+ id: import_zod17.z.string(),
7038
+ featuredPhoto: import_zod17.z.string(),
7039
+ name: import_zod17.z.string(),
7040
+ description: import_zod17.z.string(),
6730
7041
  location: clinicLocationSchema,
6731
7042
  contactInfo: clinicContactInfoSchema
6732
7043
  });
6733
- var practitionerProfileInfoSchema = import_zod16.z.object({
6734
- id: import_zod16.z.string(),
6735
- practitionerPhoto: import_zod16.z.string().nullable(),
6736
- name: import_zod16.z.string(),
6737
- email: import_zod16.z.string().email(),
6738
- phone: import_zod16.z.string().nullable(),
7044
+ var practitionerProfileInfoSchema = import_zod17.z.object({
7045
+ id: import_zod17.z.string(),
7046
+ practitionerPhoto: import_zod17.z.string().nullable(),
7047
+ name: import_zod17.z.string(),
7048
+ email: import_zod17.z.string().email(),
7049
+ phone: import_zod17.z.string().nullable(),
6739
7050
  certification: practitionerCertificationSchema
6740
7051
  });
6741
- var patientProfileInfoSchema = import_zod16.z.object({
6742
- id: import_zod16.z.string(),
6743
- fullName: import_zod16.z.string(),
6744
- email: import_zod16.z.string().email(),
6745
- phone: import_zod16.z.string().nullable(),
6746
- dateOfBirth: import_zod16.z.instanceof(import_firestore23.Timestamp),
6747
- gender: import_zod16.z.nativeEnum(Gender)
7052
+ var patientProfileInfoSchema = import_zod17.z.object({
7053
+ id: import_zod17.z.string(),
7054
+ fullName: import_zod17.z.string(),
7055
+ email: import_zod17.z.string().email(),
7056
+ phone: import_zod17.z.string().nullable(),
7057
+ dateOfBirth: import_zod17.z.instanceof(import_firestore24.Timestamp),
7058
+ gender: import_zod17.z.nativeEnum(Gender)
6748
7059
  });
6749
7060
 
6750
7061
  // src/validations/calendar.schema.ts
6751
7062
  var MIN_APPOINTMENT_DURATION = 15;
6752
- var calendarEventTimeSchema = import_zod17.z.object({
6753
- start: import_zod17.z.instanceof(Date).or(import_zod17.z.instanceof(import_firestore24.Timestamp)),
6754
- end: import_zod17.z.instanceof(Date).or(import_zod17.z.instanceof(import_firestore24.Timestamp))
7063
+ var calendarEventTimeSchema = import_zod18.z.object({
7064
+ start: import_zod18.z.instanceof(Date).or(import_zod18.z.instanceof(import_firestore25.Timestamp)),
7065
+ end: import_zod18.z.instanceof(Date).or(import_zod18.z.instanceof(import_firestore25.Timestamp))
6755
7066
  }).refine(
6756
7067
  (data) => {
6757
- const startDate = data.start instanceof import_firestore24.Timestamp ? data.start.toDate() : data.start;
6758
- const endDate = data.end instanceof import_firestore24.Timestamp ? data.end.toDate() : data.end;
7068
+ const startDate = data.start instanceof import_firestore25.Timestamp ? data.start.toDate() : data.start;
7069
+ const endDate = data.end instanceof import_firestore25.Timestamp ? data.end.toDate() : data.end;
6759
7070
  return startDate < endDate;
6760
7071
  },
6761
7072
  {
@@ -6764,7 +7075,7 @@ var calendarEventTimeSchema = import_zod17.z.object({
6764
7075
  }
6765
7076
  ).refine(
6766
7077
  (data) => {
6767
- const startDate = data.start instanceof import_firestore24.Timestamp ? data.start.toDate() : data.start;
7078
+ const startDate = data.start instanceof import_firestore25.Timestamp ? data.start.toDate() : data.start;
6768
7079
  return startDate > /* @__PURE__ */ new Date();
6769
7080
  },
6770
7081
  {
@@ -6772,46 +7083,46 @@ var calendarEventTimeSchema = import_zod17.z.object({
6772
7083
  path: ["start"]
6773
7084
  }
6774
7085
  );
6775
- var timeSlotSchema2 = import_zod17.z.object({
6776
- start: import_zod17.z.date(),
6777
- end: import_zod17.z.date(),
6778
- isAvailable: import_zod17.z.boolean()
7086
+ var timeSlotSchema2 = import_zod18.z.object({
7087
+ start: import_zod18.z.date(),
7088
+ end: import_zod18.z.date(),
7089
+ isAvailable: import_zod18.z.boolean()
6779
7090
  }).refine((data) => data.start < data.end, {
6780
7091
  message: "End time must be after start time",
6781
7092
  path: ["end"]
6782
7093
  });
6783
- var syncedCalendarEventSchema = import_zod17.z.object({
6784
- eventId: import_zod17.z.string(),
6785
- syncedCalendarProvider: import_zod17.z.nativeEnum(SyncedCalendarProvider),
6786
- syncedAt: import_zod17.z.instanceof(Date).or(import_zod17.z.instanceof(import_firestore24.Timestamp))
7094
+ var syncedCalendarEventSchema = import_zod18.z.object({
7095
+ eventId: import_zod18.z.string(),
7096
+ syncedCalendarProvider: import_zod18.z.nativeEnum(SyncedCalendarProvider),
7097
+ syncedAt: import_zod18.z.instanceof(Date).or(import_zod18.z.instanceof(import_firestore25.Timestamp))
6787
7098
  });
6788
- var procedureInfoSchema = import_zod17.z.object({
6789
- name: import_zod17.z.string(),
6790
- description: import_zod17.z.string(),
6791
- duration: import_zod17.z.number().min(MIN_APPOINTMENT_DURATION),
6792
- price: import_zod17.z.number().min(0),
6793
- currency: import_zod17.z.nativeEnum(Currency)
7099
+ var procedureInfoSchema = import_zod18.z.object({
7100
+ name: import_zod18.z.string(),
7101
+ description: import_zod18.z.string(),
7102
+ duration: import_zod18.z.number().min(MIN_APPOINTMENT_DURATION),
7103
+ price: import_zod18.z.number().min(0),
7104
+ currency: import_zod18.z.nativeEnum(Currency)
6794
7105
  });
6795
- var procedureCategorizationSchema = import_zod17.z.object({
6796
- procedureFamily: import_zod17.z.string(),
7106
+ var procedureCategorizationSchema = import_zod18.z.object({
7107
+ procedureFamily: import_zod18.z.string(),
6797
7108
  // Replace with proper enum when available
6798
- procedureCategory: import_zod17.z.string(),
7109
+ procedureCategory: import_zod18.z.string(),
6799
7110
  // Replace with proper enum when available
6800
- procedureSubcategory: import_zod17.z.string(),
7111
+ procedureSubcategory: import_zod18.z.string(),
6801
7112
  // Replace with proper enum when available
6802
- procedureTechnology: import_zod17.z.string(),
7113
+ procedureTechnology: import_zod18.z.string(),
6803
7114
  // Replace with proper enum when available
6804
- procedureProduct: import_zod17.z.string()
7115
+ procedureProduct: import_zod18.z.string()
6805
7116
  // Replace with proper enum when available
6806
7117
  });
6807
- var createAppointmentSchema = import_zod17.z.object({
6808
- clinicId: import_zod17.z.string().min(1, "Clinic ID is required"),
6809
- doctorId: import_zod17.z.string().min(1, "Doctor ID is required"),
6810
- patientId: import_zod17.z.string().min(1, "Patient ID is required"),
6811
- procedureId: import_zod17.z.string().min(1, "Procedure ID is required"),
7118
+ var createAppointmentSchema = import_zod18.z.object({
7119
+ clinicId: import_zod18.z.string().min(1, "Clinic ID is required"),
7120
+ doctorId: import_zod18.z.string().min(1, "Doctor ID is required"),
7121
+ patientId: import_zod18.z.string().min(1, "Patient ID is required"),
7122
+ procedureId: import_zod18.z.string().min(1, "Procedure ID is required"),
6812
7123
  eventLocation: clinicLocationSchema,
6813
7124
  eventTime: calendarEventTimeSchema,
6814
- description: import_zod17.z.string().optional()
7125
+ description: import_zod18.z.string().optional()
6815
7126
  }).refine(
6816
7127
  (data) => {
6817
7128
  return true;
@@ -6820,112 +7131,112 @@ var createAppointmentSchema = import_zod17.z.object({
6820
7131
  message: "Invalid appointment parameters"
6821
7132
  }
6822
7133
  );
6823
- var updateAppointmentSchema = import_zod17.z.object({
6824
- appointmentId: import_zod17.z.string().min(1, "Appointment ID is required"),
6825
- clinicId: import_zod17.z.string().min(1, "Clinic ID is required"),
6826
- doctorId: import_zod17.z.string().min(1, "Doctor ID is required"),
6827
- patientId: import_zod17.z.string().min(1, "Patient ID is required"),
7134
+ var updateAppointmentSchema = import_zod18.z.object({
7135
+ appointmentId: import_zod18.z.string().min(1, "Appointment ID is required"),
7136
+ clinicId: import_zod18.z.string().min(1, "Clinic ID is required"),
7137
+ doctorId: import_zod18.z.string().min(1, "Doctor ID is required"),
7138
+ patientId: import_zod18.z.string().min(1, "Patient ID is required"),
6828
7139
  eventTime: calendarEventTimeSchema.optional(),
6829
- description: import_zod17.z.string().optional(),
6830
- status: import_zod17.z.nativeEnum(CalendarEventStatus).optional()
7140
+ description: import_zod18.z.string().optional(),
7141
+ status: import_zod18.z.nativeEnum(CalendarEventStatus).optional()
6831
7142
  });
6832
- var createCalendarEventSchema = import_zod17.z.object({
6833
- id: import_zod17.z.string(),
6834
- clinicBranchId: import_zod17.z.string().nullable().optional(),
6835
- clinicBranchInfo: import_zod17.z.any().nullable().optional(),
6836
- practitionerProfileId: import_zod17.z.string().nullable().optional(),
7143
+ var createCalendarEventSchema = import_zod18.z.object({
7144
+ id: import_zod18.z.string(),
7145
+ clinicBranchId: import_zod18.z.string().nullable().optional(),
7146
+ clinicBranchInfo: import_zod18.z.any().nullable().optional(),
7147
+ practitionerProfileId: import_zod18.z.string().nullable().optional(),
6837
7148
  practitionerProfileInfo: practitionerProfileInfoSchema.nullable().optional(),
6838
- patientProfileId: import_zod17.z.string().nullable().optional(),
7149
+ patientProfileId: import_zod18.z.string().nullable().optional(),
6839
7150
  patientProfileInfo: patientProfileInfoSchema.nullable().optional(),
6840
- procedureId: import_zod17.z.string().nullable().optional(),
6841
- appointmentId: import_zod17.z.string().nullable().optional(),
6842
- syncedCalendarEventId: import_zod17.z.array(syncedCalendarEventSchema).nullable().optional(),
6843
- eventName: import_zod17.z.string().min(1, "Event name is required"),
7151
+ procedureId: import_zod18.z.string().nullable().optional(),
7152
+ appointmentId: import_zod18.z.string().nullable().optional(),
7153
+ syncedCalendarEventId: import_zod18.z.array(syncedCalendarEventSchema).nullable().optional(),
7154
+ eventName: import_zod18.z.string().min(1, "Event name is required"),
6844
7155
  eventLocation: clinicLocationSchema.optional(),
6845
7156
  eventTime: calendarEventTimeSchema,
6846
- description: import_zod17.z.string().optional(),
6847
- status: import_zod17.z.nativeEnum(CalendarEventStatus),
6848
- syncStatus: import_zod17.z.nativeEnum(CalendarSyncStatus),
6849
- eventType: import_zod17.z.nativeEnum(CalendarEventType),
6850
- createdAt: import_zod17.z.any(),
7157
+ description: import_zod18.z.string().optional(),
7158
+ status: import_zod18.z.nativeEnum(CalendarEventStatus),
7159
+ syncStatus: import_zod18.z.nativeEnum(CalendarSyncStatus),
7160
+ eventType: import_zod18.z.nativeEnum(CalendarEventType),
7161
+ createdAt: import_zod18.z.any(),
6851
7162
  // FieldValue for server timestamp
6852
- updatedAt: import_zod17.z.any()
7163
+ updatedAt: import_zod18.z.any()
6853
7164
  // FieldValue for server timestamp
6854
7165
  });
6855
- var updateCalendarEventSchema = import_zod17.z.object({
6856
- syncedCalendarEventId: import_zod17.z.array(syncedCalendarEventSchema).nullable().optional(),
6857
- appointmentId: import_zod17.z.string().nullable().optional(),
6858
- eventName: import_zod17.z.string().optional(),
7166
+ var updateCalendarEventSchema = import_zod18.z.object({
7167
+ syncedCalendarEventId: import_zod18.z.array(syncedCalendarEventSchema).nullable().optional(),
7168
+ appointmentId: import_zod18.z.string().nullable().optional(),
7169
+ eventName: import_zod18.z.string().optional(),
6859
7170
  eventTime: calendarEventTimeSchema.optional(),
6860
- description: import_zod17.z.string().optional(),
6861
- status: import_zod17.z.nativeEnum(CalendarEventStatus).optional(),
6862
- syncStatus: import_zod17.z.nativeEnum(CalendarSyncStatus).optional(),
6863
- eventType: import_zod17.z.nativeEnum(CalendarEventType).optional(),
6864
- updatedAt: import_zod17.z.any()
7171
+ description: import_zod18.z.string().optional(),
7172
+ status: import_zod18.z.nativeEnum(CalendarEventStatus).optional(),
7173
+ syncStatus: import_zod18.z.nativeEnum(CalendarSyncStatus).optional(),
7174
+ eventType: import_zod18.z.nativeEnum(CalendarEventType).optional(),
7175
+ updatedAt: import_zod18.z.any()
6865
7176
  // FieldValue for server timestamp
6866
7177
  });
6867
- var calendarEventSchema = import_zod17.z.object({
6868
- id: import_zod17.z.string(),
6869
- clinicBranchId: import_zod17.z.string().nullable().optional(),
6870
- clinicBranchInfo: import_zod17.z.any().nullable().optional(),
7178
+ var calendarEventSchema = import_zod18.z.object({
7179
+ id: import_zod18.z.string(),
7180
+ clinicBranchId: import_zod18.z.string().nullable().optional(),
7181
+ clinicBranchInfo: import_zod18.z.any().nullable().optional(),
6871
7182
  // Will be replaced with proper clinic info schema
6872
- practitionerProfileId: import_zod17.z.string().nullable().optional(),
7183
+ practitionerProfileId: import_zod18.z.string().nullable().optional(),
6873
7184
  practitionerProfileInfo: practitionerProfileInfoSchema.nullable().optional(),
6874
- patientProfileId: import_zod17.z.string().nullable().optional(),
7185
+ patientProfileId: import_zod18.z.string().nullable().optional(),
6875
7186
  patientProfileInfo: patientProfileInfoSchema.nullable().optional(),
6876
- procedureId: import_zod17.z.string().nullable().optional(),
7187
+ procedureId: import_zod18.z.string().nullable().optional(),
6877
7188
  procedureInfo: procedureInfoSchema.nullable().optional(),
6878
7189
  procedureCategorization: procedureCategorizationSchema.nullable().optional(),
6879
- appointmentId: import_zod17.z.string().nullable().optional(),
6880
- syncedCalendarEventId: import_zod17.z.array(syncedCalendarEventSchema).nullable().optional(),
6881
- eventName: import_zod17.z.string(),
7190
+ appointmentId: import_zod18.z.string().nullable().optional(),
7191
+ syncedCalendarEventId: import_zod18.z.array(syncedCalendarEventSchema).nullable().optional(),
7192
+ eventName: import_zod18.z.string(),
6882
7193
  eventLocation: clinicLocationSchema.optional(),
6883
7194
  eventTime: calendarEventTimeSchema,
6884
- description: import_zod17.z.string().optional(),
6885
- status: import_zod17.z.nativeEnum(CalendarEventStatus),
6886
- syncStatus: import_zod17.z.nativeEnum(CalendarSyncStatus),
6887
- eventType: import_zod17.z.nativeEnum(CalendarEventType),
6888
- createdAt: import_zod17.z.instanceof(Date).or(import_zod17.z.instanceof(import_firestore24.Timestamp)),
6889
- updatedAt: import_zod17.z.instanceof(Date).or(import_zod17.z.instanceof(import_firestore24.Timestamp))
7195
+ description: import_zod18.z.string().optional(),
7196
+ status: import_zod18.z.nativeEnum(CalendarEventStatus),
7197
+ syncStatus: import_zod18.z.nativeEnum(CalendarSyncStatus),
7198
+ eventType: import_zod18.z.nativeEnum(CalendarEventType),
7199
+ createdAt: import_zod18.z.instanceof(Date).or(import_zod18.z.instanceof(import_firestore25.Timestamp)),
7200
+ updatedAt: import_zod18.z.instanceof(Date).or(import_zod18.z.instanceof(import_firestore25.Timestamp))
6890
7201
  });
6891
7202
 
6892
7203
  // src/services/calendar/utils/clinic.utils.ts
6893
- var import_firestore26 = require("firebase/firestore");
7204
+ var import_firestore27 = require("firebase/firestore");
6894
7205
 
6895
7206
  // src/services/calendar/utils/docs.utils.ts
6896
- var import_firestore25 = require("firebase/firestore");
7207
+ var import_firestore26 = require("firebase/firestore");
6897
7208
  function getPractitionerCalendarEventDocRef(db, practitionerId, eventId) {
6898
- return (0, import_firestore25.doc)(
7209
+ return (0, import_firestore26.doc)(
6899
7210
  db,
6900
7211
  `${PRACTITIONERS_COLLECTION}/${practitionerId}/${CALENDAR_COLLECTION}/${eventId}`
6901
7212
  );
6902
7213
  }
6903
7214
  function getPatientCalendarEventDocRef(db, patientId, eventId) {
6904
- return (0, import_firestore25.doc)(
7215
+ return (0, import_firestore26.doc)(
6905
7216
  db,
6906
7217
  `${PATIENTS_COLLECTION}/${patientId}/${CALENDAR_COLLECTION}/${eventId}`
6907
7218
  );
6908
7219
  }
6909
7220
  function getClinicCalendarEventDocRef(db, clinicId, eventId) {
6910
- return (0, import_firestore25.doc)(
7221
+ return (0, import_firestore26.doc)(
6911
7222
  db,
6912
7223
  `${CLINICS_COLLECTION}/${clinicId}/${CALENDAR_COLLECTION}/${eventId}`
6913
7224
  );
6914
7225
  }
6915
7226
  function getPractitionerSyncedCalendarDocRef(db, practitionerId, syncedCalendarId) {
6916
- return (0, import_firestore25.doc)(
7227
+ return (0, import_firestore26.doc)(
6917
7228
  db,
6918
7229
  `${PRACTITIONERS_COLLECTION}/${practitionerId}/syncedCalendars/${syncedCalendarId}`
6919
7230
  );
6920
7231
  }
6921
7232
  function getPatientSyncedCalendarDocRef(db, patientId, syncedCalendarId) {
6922
- return (0, import_firestore25.doc)(
7233
+ return (0, import_firestore26.doc)(
6923
7234
  db,
6924
7235
  `${PATIENTS_COLLECTION}/${patientId}/syncedCalendars/${syncedCalendarId}`
6925
7236
  );
6926
7237
  }
6927
7238
  function getClinicSyncedCalendarDocRef(db, clinicId, syncedCalendarId) {
6928
- return (0, import_firestore25.doc)(
7239
+ return (0, import_firestore26.doc)(
6929
7240
  db,
6930
7241
  `${CLINICS_COLLECTION}/${clinicId}/syncedCalendars/${syncedCalendarId}`
6931
7242
  );
@@ -6938,31 +7249,31 @@ async function createClinicCalendarEventUtil(db, clinicId, eventData, generateId
6938
7249
  const newEvent = {
6939
7250
  id: eventId,
6940
7251
  ...eventData,
6941
- createdAt: (0, import_firestore26.serverTimestamp)(),
6942
- updatedAt: (0, import_firestore26.serverTimestamp)()
7252
+ createdAt: (0, import_firestore27.serverTimestamp)(),
7253
+ updatedAt: (0, import_firestore27.serverTimestamp)()
6943
7254
  };
6944
- await (0, import_firestore26.setDoc)(eventRef, newEvent);
7255
+ await (0, import_firestore27.setDoc)(eventRef, newEvent);
6945
7256
  return {
6946
7257
  ...newEvent,
6947
- createdAt: import_firestore26.Timestamp.now(),
6948
- updatedAt: import_firestore26.Timestamp.now()
7258
+ createdAt: import_firestore27.Timestamp.now(),
7259
+ updatedAt: import_firestore27.Timestamp.now()
6949
7260
  };
6950
7261
  }
6951
7262
  async function updateClinicCalendarEventUtil(db, clinicId, eventId, updateData) {
6952
7263
  const eventRef = getClinicCalendarEventDocRef(db, clinicId, eventId);
6953
7264
  const updates = {
6954
7265
  ...updateData,
6955
- updatedAt: (0, import_firestore26.serverTimestamp)()
7266
+ updatedAt: (0, import_firestore27.serverTimestamp)()
6956
7267
  };
6957
- await (0, import_firestore26.updateDoc)(eventRef, updates);
6958
- const updatedDoc = await (0, import_firestore26.getDoc)(eventRef);
7268
+ await (0, import_firestore27.updateDoc)(eventRef, updates);
7269
+ const updatedDoc = await (0, import_firestore27.getDoc)(eventRef);
6959
7270
  if (!updatedDoc.exists()) {
6960
7271
  throw new Error("Event not found after update");
6961
7272
  }
6962
7273
  return updatedDoc.data();
6963
7274
  }
6964
7275
  async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
6965
- const clinicDoc = await (0, import_firestore26.getDoc)((0, import_firestore26.doc)(db, `clinics/${clinicId}`));
7276
+ const clinicDoc = await (0, import_firestore27.getDoc)((0, import_firestore27.doc)(db, `clinics/${clinicId}`));
6966
7277
  if (!clinicDoc.exists()) {
6967
7278
  throw new Error(`Clinic with ID ${clinicId} not found`);
6968
7279
  }
@@ -6971,8 +7282,8 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
6971
7282
  if (!clinicGroupId) {
6972
7283
  return false;
6973
7284
  }
6974
- const clinicGroupDoc = await (0, import_firestore26.getDoc)(
6975
- (0, import_firestore26.doc)(db, `${CLINIC_GROUPS_COLLECTION}/${clinicGroupId}`)
7285
+ const clinicGroupDoc = await (0, import_firestore27.getDoc)(
7286
+ (0, import_firestore27.doc)(db, `${CLINIC_GROUPS_COLLECTION}/${clinicGroupId}`)
6976
7287
  );
6977
7288
  if (!clinicGroupDoc.exists()) {
6978
7289
  return false;
@@ -6982,31 +7293,31 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
6982
7293
  }
6983
7294
 
6984
7295
  // src/services/calendar/utils/patient.utils.ts
6985
- var import_firestore27 = require("firebase/firestore");
7296
+ var import_firestore28 = require("firebase/firestore");
6986
7297
  async function createPatientCalendarEventUtil(db, patientId, eventData, generateId2) {
6987
7298
  const eventId = generateId2();
6988
7299
  const eventRef = getPatientCalendarEventDocRef(db, patientId, eventId);
6989
7300
  const newEvent = {
6990
7301
  id: eventId,
6991
7302
  ...eventData,
6992
- createdAt: (0, import_firestore27.serverTimestamp)(),
6993
- updatedAt: (0, import_firestore27.serverTimestamp)()
7303
+ createdAt: (0, import_firestore28.serverTimestamp)(),
7304
+ updatedAt: (0, import_firestore28.serverTimestamp)()
6994
7305
  };
6995
- await (0, import_firestore27.setDoc)(eventRef, newEvent);
7306
+ await (0, import_firestore28.setDoc)(eventRef, newEvent);
6996
7307
  return {
6997
7308
  ...newEvent,
6998
- createdAt: import_firestore27.Timestamp.now(),
6999
- updatedAt: import_firestore27.Timestamp.now()
7309
+ createdAt: import_firestore28.Timestamp.now(),
7310
+ updatedAt: import_firestore28.Timestamp.now()
7000
7311
  };
7001
7312
  }
7002
7313
  async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData) {
7003
7314
  const eventRef = getPatientCalendarEventDocRef(db, patientId, eventId);
7004
7315
  const updates = {
7005
7316
  ...updateData,
7006
- updatedAt: (0, import_firestore27.serverTimestamp)()
7317
+ updatedAt: (0, import_firestore28.serverTimestamp)()
7007
7318
  };
7008
- await (0, import_firestore27.updateDoc)(eventRef, updates);
7009
- const updatedDoc = await (0, import_firestore27.getDoc)(eventRef);
7319
+ await (0, import_firestore28.updateDoc)(eventRef, updates);
7320
+ const updatedDoc = await (0, import_firestore28.getDoc)(eventRef);
7010
7321
  if (!updatedDoc.exists()) {
7011
7322
  throw new Error("Event not found after update");
7012
7323
  }
@@ -7014,7 +7325,7 @@ async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData
7014
7325
  }
7015
7326
 
7016
7327
  // src/services/calendar/utils/practitioner.utils.ts
7017
- var import_firestore28 = require("firebase/firestore");
7328
+ var import_firestore29 = require("firebase/firestore");
7018
7329
  async function createPractitionerCalendarEventUtil(db, practitionerId, eventData, generateId2) {
7019
7330
  const eventId = generateId2();
7020
7331
  const eventRef = getPractitionerCalendarEventDocRef(
@@ -7025,14 +7336,14 @@ async function createPractitionerCalendarEventUtil(db, practitionerId, eventData
7025
7336
  const newEvent = {
7026
7337
  id: eventId,
7027
7338
  ...eventData,
7028
- createdAt: (0, import_firestore28.serverTimestamp)(),
7029
- updatedAt: (0, import_firestore28.serverTimestamp)()
7339
+ createdAt: (0, import_firestore29.serverTimestamp)(),
7340
+ updatedAt: (0, import_firestore29.serverTimestamp)()
7030
7341
  };
7031
- await (0, import_firestore28.setDoc)(eventRef, newEvent);
7342
+ await (0, import_firestore29.setDoc)(eventRef, newEvent);
7032
7343
  return {
7033
7344
  ...newEvent,
7034
- createdAt: import_firestore28.Timestamp.now(),
7035
- updatedAt: import_firestore28.Timestamp.now()
7345
+ createdAt: import_firestore29.Timestamp.now(),
7346
+ updatedAt: import_firestore29.Timestamp.now()
7036
7347
  };
7037
7348
  }
7038
7349
  async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId, updateData) {
@@ -7043,10 +7354,10 @@ async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId,
7043
7354
  );
7044
7355
  const updates = {
7045
7356
  ...updateData,
7046
- updatedAt: (0, import_firestore28.serverTimestamp)()
7357
+ updatedAt: (0, import_firestore29.serverTimestamp)()
7047
7358
  };
7048
- await (0, import_firestore28.updateDoc)(eventRef, updates);
7049
- const updatedDoc = await (0, import_firestore28.getDoc)(eventRef);
7359
+ await (0, import_firestore29.updateDoc)(eventRef, updates);
7360
+ const updatedDoc = await (0, import_firestore29.getDoc)(eventRef);
7050
7361
  if (!updatedDoc.exists()) {
7051
7362
  throw new Error("Event not found after update");
7052
7363
  }
@@ -7122,7 +7433,7 @@ async function updateAppointmentUtil(db, clinicId, practitionerId, patientId, ev
7122
7433
  }
7123
7434
 
7124
7435
  // src/services/calendar/utils/synced-calendar.utils.ts
7125
- var import_firestore29 = require("firebase/firestore");
7436
+ var import_firestore30 = require("firebase/firestore");
7126
7437
  async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendarData, generateId2) {
7127
7438
  const calendarId = generateId2();
7128
7439
  const calendarRef = getPractitionerSyncedCalendarDocRef(
@@ -7133,14 +7444,14 @@ async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendar
7133
7444
  const newCalendar = {
7134
7445
  id: calendarId,
7135
7446
  ...calendarData,
7136
- createdAt: (0, import_firestore29.serverTimestamp)(),
7137
- updatedAt: (0, import_firestore29.serverTimestamp)()
7447
+ createdAt: (0, import_firestore30.serverTimestamp)(),
7448
+ updatedAt: (0, import_firestore30.serverTimestamp)()
7138
7449
  };
7139
- await (0, import_firestore29.setDoc)(calendarRef, newCalendar);
7450
+ await (0, import_firestore30.setDoc)(calendarRef, newCalendar);
7140
7451
  return {
7141
7452
  ...newCalendar,
7142
- createdAt: import_firestore29.Timestamp.now(),
7143
- updatedAt: import_firestore29.Timestamp.now()
7453
+ createdAt: import_firestore30.Timestamp.now(),
7454
+ updatedAt: import_firestore30.Timestamp.now()
7144
7455
  };
7145
7456
  }
7146
7457
  async function createPatientSyncedCalendarUtil(db, patientId, calendarData, generateId2) {
@@ -7149,14 +7460,14 @@ async function createPatientSyncedCalendarUtil(db, patientId, calendarData, gene
7149
7460
  const newCalendar = {
7150
7461
  id: calendarId,
7151
7462
  ...calendarData,
7152
- createdAt: (0, import_firestore29.serverTimestamp)(),
7153
- updatedAt: (0, import_firestore29.serverTimestamp)()
7463
+ createdAt: (0, import_firestore30.serverTimestamp)(),
7464
+ updatedAt: (0, import_firestore30.serverTimestamp)()
7154
7465
  };
7155
- await (0, import_firestore29.setDoc)(calendarRef, newCalendar);
7466
+ await (0, import_firestore30.setDoc)(calendarRef, newCalendar);
7156
7467
  return {
7157
7468
  ...newCalendar,
7158
- createdAt: import_firestore29.Timestamp.now(),
7159
- updatedAt: import_firestore29.Timestamp.now()
7469
+ createdAt: import_firestore30.Timestamp.now(),
7470
+ updatedAt: import_firestore30.Timestamp.now()
7160
7471
  };
7161
7472
  }
7162
7473
  async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, generateId2) {
@@ -7165,14 +7476,14 @@ async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, genera
7165
7476
  const newCalendar = {
7166
7477
  id: calendarId,
7167
7478
  ...calendarData,
7168
- createdAt: (0, import_firestore29.serverTimestamp)(),
7169
- updatedAt: (0, import_firestore29.serverTimestamp)()
7479
+ createdAt: (0, import_firestore30.serverTimestamp)(),
7480
+ updatedAt: (0, import_firestore30.serverTimestamp)()
7170
7481
  };
7171
- await (0, import_firestore29.setDoc)(calendarRef, newCalendar);
7482
+ await (0, import_firestore30.setDoc)(calendarRef, newCalendar);
7172
7483
  return {
7173
7484
  ...newCalendar,
7174
- createdAt: import_firestore29.Timestamp.now(),
7175
- updatedAt: import_firestore29.Timestamp.now()
7485
+ createdAt: import_firestore30.Timestamp.now(),
7486
+ updatedAt: import_firestore30.Timestamp.now()
7176
7487
  };
7177
7488
  }
7178
7489
  async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId) {
@@ -7181,54 +7492,54 @@ async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId)
7181
7492
  practitionerId,
7182
7493
  calendarId
7183
7494
  );
7184
- const calendarDoc = await (0, import_firestore29.getDoc)(calendarRef);
7495
+ const calendarDoc = await (0, import_firestore30.getDoc)(calendarRef);
7185
7496
  if (!calendarDoc.exists()) {
7186
7497
  return null;
7187
7498
  }
7188
7499
  return calendarDoc.data();
7189
7500
  }
7190
7501
  async function getPractitionerSyncedCalendarsUtil(db, practitionerId) {
7191
- const calendarsRef = (0, import_firestore29.collection)(
7502
+ const calendarsRef = (0, import_firestore30.collection)(
7192
7503
  db,
7193
7504
  `practitioners/${practitionerId}/${SYNCED_CALENDARS_COLLECTION}`
7194
7505
  );
7195
- const q = (0, import_firestore29.query)(calendarsRef, (0, import_firestore29.orderBy)("createdAt", "desc"));
7196
- const querySnapshot = await (0, import_firestore29.getDocs)(q);
7197
- return querySnapshot.docs.map((doc20) => doc20.data());
7506
+ const q = (0, import_firestore30.query)(calendarsRef, (0, import_firestore30.orderBy)("createdAt", "desc"));
7507
+ const querySnapshot = await (0, import_firestore30.getDocs)(q);
7508
+ return querySnapshot.docs.map((doc21) => doc21.data());
7198
7509
  }
7199
7510
  async function getPatientSyncedCalendarUtil(db, patientId, calendarId) {
7200
7511
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
7201
- const calendarDoc = await (0, import_firestore29.getDoc)(calendarRef);
7512
+ const calendarDoc = await (0, import_firestore30.getDoc)(calendarRef);
7202
7513
  if (!calendarDoc.exists()) {
7203
7514
  return null;
7204
7515
  }
7205
7516
  return calendarDoc.data();
7206
7517
  }
7207
7518
  async function getPatientSyncedCalendarsUtil(db, patientId) {
7208
- const calendarsRef = (0, import_firestore29.collection)(
7519
+ const calendarsRef = (0, import_firestore30.collection)(
7209
7520
  db,
7210
7521
  `patients/${patientId}/${SYNCED_CALENDARS_COLLECTION}`
7211
7522
  );
7212
- const q = (0, import_firestore29.query)(calendarsRef, (0, import_firestore29.orderBy)("createdAt", "desc"));
7213
- const querySnapshot = await (0, import_firestore29.getDocs)(q);
7214
- return querySnapshot.docs.map((doc20) => doc20.data());
7523
+ const q = (0, import_firestore30.query)(calendarsRef, (0, import_firestore30.orderBy)("createdAt", "desc"));
7524
+ const querySnapshot = await (0, import_firestore30.getDocs)(q);
7525
+ return querySnapshot.docs.map((doc21) => doc21.data());
7215
7526
  }
7216
7527
  async function getClinicSyncedCalendarUtil(db, clinicId, calendarId) {
7217
7528
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
7218
- const calendarDoc = await (0, import_firestore29.getDoc)(calendarRef);
7529
+ const calendarDoc = await (0, import_firestore30.getDoc)(calendarRef);
7219
7530
  if (!calendarDoc.exists()) {
7220
7531
  return null;
7221
7532
  }
7222
7533
  return calendarDoc.data();
7223
7534
  }
7224
7535
  async function getClinicSyncedCalendarsUtil(db, clinicId) {
7225
- const calendarsRef = (0, import_firestore29.collection)(
7536
+ const calendarsRef = (0, import_firestore30.collection)(
7226
7537
  db,
7227
7538
  `clinics/${clinicId}/${SYNCED_CALENDARS_COLLECTION}`
7228
7539
  );
7229
- const q = (0, import_firestore29.query)(calendarsRef, (0, import_firestore29.orderBy)("createdAt", "desc"));
7230
- const querySnapshot = await (0, import_firestore29.getDocs)(q);
7231
- return querySnapshot.docs.map((doc20) => doc20.data());
7540
+ const q = (0, import_firestore30.query)(calendarsRef, (0, import_firestore30.orderBy)("createdAt", "desc"));
7541
+ const querySnapshot = await (0, import_firestore30.getDocs)(q);
7542
+ return querySnapshot.docs.map((doc21) => doc21.data());
7232
7543
  }
7233
7544
  async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendarId, updateData) {
7234
7545
  const calendarRef = getPractitionerSyncedCalendarDocRef(
@@ -7238,10 +7549,10 @@ async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendar
7238
7549
  );
7239
7550
  const updates = {
7240
7551
  ...updateData,
7241
- updatedAt: (0, import_firestore29.serverTimestamp)()
7552
+ updatedAt: (0, import_firestore30.serverTimestamp)()
7242
7553
  };
7243
- await (0, import_firestore29.updateDoc)(calendarRef, updates);
7244
- const updatedDoc = await (0, import_firestore29.getDoc)(calendarRef);
7554
+ await (0, import_firestore30.updateDoc)(calendarRef, updates);
7555
+ const updatedDoc = await (0, import_firestore30.getDoc)(calendarRef);
7245
7556
  if (!updatedDoc.exists()) {
7246
7557
  throw new Error("Synced calendar not found after update");
7247
7558
  }
@@ -7251,10 +7562,10 @@ async function updatePatientSyncedCalendarUtil(db, patientId, calendarId, update
7251
7562
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
7252
7563
  const updates = {
7253
7564
  ...updateData,
7254
- updatedAt: (0, import_firestore29.serverTimestamp)()
7565
+ updatedAt: (0, import_firestore30.serverTimestamp)()
7255
7566
  };
7256
- await (0, import_firestore29.updateDoc)(calendarRef, updates);
7257
- const updatedDoc = await (0, import_firestore29.getDoc)(calendarRef);
7567
+ await (0, import_firestore30.updateDoc)(calendarRef, updates);
7568
+ const updatedDoc = await (0, import_firestore30.getDoc)(calendarRef);
7258
7569
  if (!updatedDoc.exists()) {
7259
7570
  throw new Error("Synced calendar not found after update");
7260
7571
  }
@@ -7264,10 +7575,10 @@ async function updateClinicSyncedCalendarUtil(db, clinicId, calendarId, updateDa
7264
7575
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
7265
7576
  const updates = {
7266
7577
  ...updateData,
7267
- updatedAt: (0, import_firestore29.serverTimestamp)()
7578
+ updatedAt: (0, import_firestore30.serverTimestamp)()
7268
7579
  };
7269
- await (0, import_firestore29.updateDoc)(calendarRef, updates);
7270
- const updatedDoc = await (0, import_firestore29.getDoc)(calendarRef);
7580
+ await (0, import_firestore30.updateDoc)(calendarRef, updates);
7581
+ const updatedDoc = await (0, import_firestore30.getDoc)(calendarRef);
7271
7582
  if (!updatedDoc.exists()) {
7272
7583
  throw new Error("Synced calendar not found after update");
7273
7584
  }
@@ -7279,19 +7590,19 @@ async function deletePractitionerSyncedCalendarUtil(db, practitionerId, calendar
7279
7590
  practitionerId,
7280
7591
  calendarId
7281
7592
  );
7282
- await (0, import_firestore29.deleteDoc)(calendarRef);
7593
+ await (0, import_firestore30.deleteDoc)(calendarRef);
7283
7594
  }
7284
7595
  async function deletePatientSyncedCalendarUtil(db, patientId, calendarId) {
7285
7596
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
7286
- await (0, import_firestore29.deleteDoc)(calendarRef);
7597
+ await (0, import_firestore30.deleteDoc)(calendarRef);
7287
7598
  }
7288
7599
  async function deleteClinicSyncedCalendarUtil(db, clinicId, calendarId) {
7289
7600
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
7290
- await (0, import_firestore29.deleteDoc)(calendarRef);
7601
+ await (0, import_firestore30.deleteDoc)(calendarRef);
7291
7602
  }
7292
7603
  async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarId) {
7293
7604
  const updateData = {
7294
- lastSyncedAt: import_firestore29.Timestamp.now()
7605
+ lastSyncedAt: import_firestore30.Timestamp.now()
7295
7606
  };
7296
7607
  switch (entityType) {
7297
7608
  case "practitioner":
@@ -7321,7 +7632,7 @@ async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarI
7321
7632
  }
7322
7633
 
7323
7634
  // src/services/calendar/utils/google-calendar.utils.ts
7324
- var import_firestore30 = require("firebase/firestore");
7635
+ var import_firestore31 = require("firebase/firestore");
7325
7636
  var GOOGLE_CALENDAR_API_URL = "https://www.googleapis.com/calendar/v3";
7326
7637
  var GOOGLE_OAUTH_URL = "https://oauth2.googleapis.com/token";
7327
7638
  var CLIENT_ID = "your-client-id";
@@ -7441,7 +7752,7 @@ async function ensureValidToken(db, entityType, entityId, syncedCalendar) {
7441
7752
  tokenExpiry.setSeconds(tokenExpiry.getSeconds() + expiresIn);
7442
7753
  const updateData = {
7443
7754
  accessToken,
7444
- tokenExpiry: import_firestore30.Timestamp.fromDate(tokenExpiry)
7755
+ tokenExpiry: import_firestore31.Timestamp.fromDate(tokenExpiry)
7445
7756
  };
7446
7757
  switch (entityType) {
7447
7758
  case "practitioner":
@@ -7616,8 +7927,8 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
7616
7927
  eventName: googleEvent.summary || "External Event",
7617
7928
  eventLocation: googleEvent.location,
7618
7929
  eventTime: {
7619
- start: import_firestore30.Timestamp.fromDate(start),
7620
- end: import_firestore30.Timestamp.fromDate(end)
7930
+ start: import_firestore31.Timestamp.fromDate(start),
7931
+ end: import_firestore31.Timestamp.fromDate(end)
7621
7932
  },
7622
7933
  description: googleEvent.description || "",
7623
7934
  // External events are always set as CONFIRMED - status updates will happen externally
@@ -7631,7 +7942,7 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
7631
7942
  {
7632
7943
  eventId: googleEvent.id,
7633
7944
  syncedCalendarProvider: "google" /* GOOGLE */,
7634
- syncedAt: import_firestore30.Timestamp.now()
7945
+ syncedAt: import_firestore31.Timestamp.now()
7635
7946
  }
7636
7947
  ]
7637
7948
  };
@@ -8409,7 +8720,7 @@ var CalendarServiceV2 = class extends BaseService {
8409
8720
  return 0;
8410
8721
  }
8411
8722
  let importedEventsCount = 0;
8412
- const currentTime = import_firestore31.Timestamp.now();
8723
+ const currentTime = import_firestore32.Timestamp.now();
8413
8724
  for (const calendar of activeCalendars) {
8414
8725
  try {
8415
8726
  let externalEvents = [];
@@ -8476,7 +8787,7 @@ var CalendarServiceV2 = class extends BaseService {
8476
8787
  async createDoctorBlockingEvent(doctorId, eventData) {
8477
8788
  try {
8478
8789
  const eventId = this.generateId();
8479
- const eventRef = (0, import_firestore32.doc)(
8790
+ const eventRef = (0, import_firestore33.doc)(
8480
8791
  this.db,
8481
8792
  PRACTITIONERS_COLLECTION,
8482
8793
  doctorId,
@@ -8486,14 +8797,14 @@ var CalendarServiceV2 = class extends BaseService {
8486
8797
  const newEvent = {
8487
8798
  id: eventId,
8488
8799
  ...eventData,
8489
- createdAt: (0, import_firestore31.serverTimestamp)(),
8490
- updatedAt: (0, import_firestore31.serverTimestamp)()
8800
+ createdAt: (0, import_firestore32.serverTimestamp)(),
8801
+ updatedAt: (0, import_firestore32.serverTimestamp)()
8491
8802
  };
8492
- await (0, import_firestore32.setDoc)(eventRef, newEvent);
8803
+ await (0, import_firestore33.setDoc)(eventRef, newEvent);
8493
8804
  return {
8494
8805
  ...newEvent,
8495
- createdAt: import_firestore31.Timestamp.now(),
8496
- updatedAt: import_firestore31.Timestamp.now()
8806
+ createdAt: import_firestore32.Timestamp.now(),
8807
+ updatedAt: import_firestore32.Timestamp.now()
8497
8808
  };
8498
8809
  } catch (error) {
8499
8810
  console.error(
@@ -8511,8 +8822,8 @@ var CalendarServiceV2 = class extends BaseService {
8511
8822
  */
8512
8823
  async synchronizeExternalCalendars(lookbackDays = 7, lookforwardDays = 30) {
8513
8824
  try {
8514
- const practitionersRef = (0, import_firestore32.collection)(this.db, PRACTITIONERS_COLLECTION);
8515
- const practitionersSnapshot = await (0, import_firestore32.getDocs)(practitionersRef);
8825
+ const practitionersRef = (0, import_firestore33.collection)(this.db, PRACTITIONERS_COLLECTION);
8826
+ const practitionersSnapshot = await (0, import_firestore33.getDocs)(practitionersRef);
8516
8827
  const startDate = /* @__PURE__ */ new Date();
8517
8828
  startDate.setDate(startDate.getDate() - lookbackDays);
8518
8829
  const endDate = /* @__PURE__ */ new Date();
@@ -8570,22 +8881,22 @@ var CalendarServiceV2 = class extends BaseService {
8570
8881
  async updateExistingEventsFromExternalCalendars(doctorId, startDate, endDate) {
8571
8882
  var _a;
8572
8883
  try {
8573
- const eventsRef = (0, import_firestore32.collection)(
8884
+ const eventsRef = (0, import_firestore33.collection)(
8574
8885
  this.db,
8575
8886
  PRACTITIONERS_COLLECTION,
8576
8887
  doctorId,
8577
8888
  CALENDAR_COLLECTION
8578
8889
  );
8579
- const q = (0, import_firestore32.query)(
8890
+ const q = (0, import_firestore33.query)(
8580
8891
  eventsRef,
8581
- (0, import_firestore32.where)("syncStatus", "==", "external" /* EXTERNAL */),
8582
- (0, import_firestore32.where)("eventTime.start", ">=", import_firestore31.Timestamp.fromDate(startDate)),
8583
- (0, import_firestore32.where)("eventTime.start", "<=", import_firestore31.Timestamp.fromDate(endDate))
8892
+ (0, import_firestore33.where)("syncStatus", "==", "external" /* EXTERNAL */),
8893
+ (0, import_firestore33.where)("eventTime.start", ">=", import_firestore32.Timestamp.fromDate(startDate)),
8894
+ (0, import_firestore33.where)("eventTime.start", "<=", import_firestore32.Timestamp.fromDate(endDate))
8584
8895
  );
8585
- const eventsSnapshot = await (0, import_firestore32.getDocs)(q);
8586
- const events = eventsSnapshot.docs.map((doc20) => ({
8587
- id: doc20.id,
8588
- ...doc20.data()
8896
+ const eventsSnapshot = await (0, import_firestore33.getDocs)(q);
8897
+ const events = eventsSnapshot.docs.map((doc21) => ({
8898
+ id: doc21.id,
8899
+ ...doc21.data()
8589
8900
  }));
8590
8901
  const calendars = await this.syncedCalendarsService.getPractitionerSyncedCalendars(
8591
8902
  doctorId
@@ -8689,21 +9000,21 @@ var CalendarServiceV2 = class extends BaseService {
8689
9000
  const endTime = new Date(
8690
9001
  externalEvent.end.dateTime || externalEvent.end.date
8691
9002
  );
8692
- const eventRef = (0, import_firestore32.doc)(
9003
+ const eventRef = (0, import_firestore33.doc)(
8693
9004
  this.db,
8694
9005
  PRACTITIONERS_COLLECTION,
8695
9006
  doctorId,
8696
9007
  CALENDAR_COLLECTION,
8697
9008
  eventId
8698
9009
  );
8699
- await (0, import_firestore32.updateDoc)(eventRef, {
9010
+ await (0, import_firestore33.updateDoc)(eventRef, {
8700
9011
  eventName: externalEvent.summary || "External Event",
8701
9012
  eventTime: {
8702
- start: import_firestore31.Timestamp.fromDate(startTime),
8703
- end: import_firestore31.Timestamp.fromDate(endTime)
9013
+ start: import_firestore32.Timestamp.fromDate(startTime),
9014
+ end: import_firestore32.Timestamp.fromDate(endTime)
8704
9015
  },
8705
9016
  description: externalEvent.description || "",
8706
- updatedAt: (0, import_firestore31.serverTimestamp)()
9017
+ updatedAt: (0, import_firestore32.serverTimestamp)()
8707
9018
  });
8708
9019
  console.log(`Updated local event ${eventId} from external event`);
8709
9020
  } catch (error) {
@@ -8721,16 +9032,16 @@ var CalendarServiceV2 = class extends BaseService {
8721
9032
  */
8722
9033
  async updateEventStatus(doctorId, eventId, status) {
8723
9034
  try {
8724
- const eventRef = (0, import_firestore32.doc)(
9035
+ const eventRef = (0, import_firestore33.doc)(
8725
9036
  this.db,
8726
9037
  PRACTITIONERS_COLLECTION,
8727
9038
  doctorId,
8728
9039
  CALENDAR_COLLECTION,
8729
9040
  eventId
8730
9041
  );
8731
- await (0, import_firestore32.updateDoc)(eventRef, {
9042
+ await (0, import_firestore33.updateDoc)(eventRef, {
8732
9043
  status,
8733
- updatedAt: (0, import_firestore31.serverTimestamp)()
9044
+ updatedAt: (0, import_firestore32.serverTimestamp)()
8734
9045
  });
8735
9046
  console.log(`Updated event ${eventId} status to ${status}`);
8736
9047
  } catch (error) {
@@ -8791,8 +9102,8 @@ var CalendarServiceV2 = class extends BaseService {
8791
9102
  const startDate = eventTime.start.toDate();
8792
9103
  const startTime = startDate;
8793
9104
  const endTime = eventTime.end.toDate();
8794
- const practitionerRef = (0, import_firestore32.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
8795
- const practitionerDoc = await (0, import_firestore32.getDoc)(practitionerRef);
9105
+ const practitionerRef = (0, import_firestore33.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
9106
+ const practitionerDoc = await (0, import_firestore33.getDoc)(practitionerRef);
8796
9107
  if (!practitionerDoc.exists()) {
8797
9108
  throw new Error(`Doctor with ID ${doctorId} not found`);
8798
9109
  }
@@ -8849,8 +9160,8 @@ var CalendarServiceV2 = class extends BaseService {
8849
9160
  * @returns Updated calendar event
8850
9161
  */
8851
9162
  async updateAppointmentStatus(appointmentId, clinicId, status) {
8852
- const appointmentRef = (0, import_firestore32.doc)(this.db, CALENDAR_COLLECTION, appointmentId);
8853
- const appointmentDoc = await (0, import_firestore32.getDoc)(appointmentRef);
9163
+ const appointmentRef = (0, import_firestore33.doc)(this.db, CALENDAR_COLLECTION, appointmentId);
9164
+ const appointmentDoc = await (0, import_firestore33.getDoc)(appointmentRef);
8854
9165
  if (!appointmentDoc.exists()) {
8855
9166
  throw new Error(`Appointment with ID ${appointmentId} not found`);
8856
9167
  }
@@ -8981,7 +9292,7 @@ var CalendarServiceV2 = class extends BaseService {
8981
9292
  const newSyncEvent = {
8982
9293
  eventId: result.eventIds[0],
8983
9294
  syncedCalendarProvider: calendar.provider,
8984
- syncedAt: import_firestore31.Timestamp.now()
9295
+ syncedAt: import_firestore32.Timestamp.now()
8985
9296
  };
8986
9297
  await this.updateEventWithSyncId(
8987
9298
  entityType === "doctor" ? appointment.practitionerProfileId : appointment.patientProfileId,
@@ -9005,8 +9316,8 @@ var CalendarServiceV2 = class extends BaseService {
9005
9316
  async updateEventWithSyncId(entityId, entityType, eventId, syncEvent) {
9006
9317
  try {
9007
9318
  const collectionPath = entityType === "doctor" ? `${PRACTITIONERS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}` : `${PATIENTS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
9008
- const eventRef = (0, import_firestore32.doc)(this.db, collectionPath, eventId);
9009
- const eventDoc = await (0, import_firestore32.getDoc)(eventRef);
9319
+ const eventRef = (0, import_firestore33.doc)(this.db, collectionPath, eventId);
9320
+ const eventDoc = await (0, import_firestore33.getDoc)(eventRef);
9010
9321
  if (eventDoc.exists()) {
9011
9322
  const event = eventDoc.data();
9012
9323
  const syncIds = [...event.syncedCalendarEventId || []];
@@ -9018,9 +9329,9 @@ var CalendarServiceV2 = class extends BaseService {
9018
9329
  } else {
9019
9330
  syncIds.push(syncEvent);
9020
9331
  }
9021
- await (0, import_firestore32.updateDoc)(eventRef, {
9332
+ await (0, import_firestore33.updateDoc)(eventRef, {
9022
9333
  syncedCalendarEventId: syncIds,
9023
- updatedAt: (0, import_firestore31.serverTimestamp)()
9334
+ updatedAt: (0, import_firestore32.serverTimestamp)()
9024
9335
  });
9025
9336
  console.log(
9026
9337
  `Updated event ${eventId} with sync ID ${syncEvent.eventId}`
@@ -9044,8 +9355,8 @@ var CalendarServiceV2 = class extends BaseService {
9044
9355
  * @returns Working hours for the clinic
9045
9356
  */
9046
9357
  async getClinicWorkingHours(clinicId, date) {
9047
- const clinicRef = (0, import_firestore32.doc)(this.db, CLINICS_COLLECTION, clinicId);
9048
- const clinicDoc = await (0, import_firestore32.getDoc)(clinicRef);
9358
+ const clinicRef = (0, import_firestore33.doc)(this.db, CLINICS_COLLECTION, clinicId);
9359
+ const clinicDoc = await (0, import_firestore33.getDoc)(clinicRef);
9049
9360
  if (!clinicDoc.exists()) {
9050
9361
  throw new Error(`Clinic with ID ${clinicId} not found`);
9051
9362
  }
@@ -9073,8 +9384,8 @@ var CalendarServiceV2 = class extends BaseService {
9073
9384
  * @returns Doctor's schedule
9074
9385
  */
9075
9386
  async getDoctorSchedule(doctorId, date) {
9076
- const practitionerRef = (0, import_firestore32.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
9077
- const practitionerDoc = await (0, import_firestore32.getDoc)(practitionerRef);
9387
+ const practitionerRef = (0, import_firestore33.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
9388
+ const practitionerDoc = await (0, import_firestore33.getDoc)(practitionerRef);
9078
9389
  if (!practitionerDoc.exists()) {
9079
9390
  throw new Error(`Doctor with ID ${doctorId} not found`);
9080
9391
  }
@@ -9106,19 +9417,19 @@ var CalendarServiceV2 = class extends BaseService {
9106
9417
  startOfDay.setHours(0, 0, 0, 0);
9107
9418
  const endOfDay = new Date(date);
9108
9419
  endOfDay.setHours(23, 59, 59, 999);
9109
- const appointmentsRef = (0, import_firestore32.collection)(this.db, CALENDAR_COLLECTION);
9110
- const q = (0, import_firestore32.query)(
9420
+ const appointmentsRef = (0, import_firestore33.collection)(this.db, CALENDAR_COLLECTION);
9421
+ const q = (0, import_firestore33.query)(
9111
9422
  appointmentsRef,
9112
- (0, import_firestore32.where)("practitionerProfileId", "==", doctorId),
9113
- (0, import_firestore32.where)("eventTime.start", ">=", import_firestore31.Timestamp.fromDate(startOfDay)),
9114
- (0, import_firestore32.where)("eventTime.start", "<=", import_firestore31.Timestamp.fromDate(endOfDay)),
9115
- (0, import_firestore32.where)("status", "in", [
9423
+ (0, import_firestore33.where)("practitionerProfileId", "==", doctorId),
9424
+ (0, import_firestore33.where)("eventTime.start", ">=", import_firestore32.Timestamp.fromDate(startOfDay)),
9425
+ (0, import_firestore33.where)("eventTime.start", "<=", import_firestore32.Timestamp.fromDate(endOfDay)),
9426
+ (0, import_firestore33.where)("status", "in", [
9116
9427
  "confirmed" /* CONFIRMED */,
9117
9428
  "pending" /* PENDING */
9118
9429
  ])
9119
9430
  );
9120
- const querySnapshot = await (0, import_firestore32.getDocs)(q);
9121
- return querySnapshot.docs.map((doc20) => doc20.data());
9431
+ const querySnapshot = await (0, import_firestore33.getDocs)(q);
9432
+ return querySnapshot.docs.map((doc21) => doc21.data());
9122
9433
  }
9123
9434
  /**
9124
9435
  * Calculates available time slots based on working hours, schedule and existing appointments
@@ -9175,11 +9486,11 @@ var CalendarServiceV2 = class extends BaseService {
9175
9486
  var _a;
9176
9487
  try {
9177
9488
  const [clinicDoc, practitionerDoc, patientDoc, patientSensitiveInfoDoc] = await Promise.all([
9178
- (0, import_firestore32.getDoc)((0, import_firestore32.doc)(this.db, CLINICS_COLLECTION, clinicId)),
9179
- (0, import_firestore32.getDoc)((0, import_firestore32.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId)),
9180
- (0, import_firestore32.getDoc)((0, import_firestore32.doc)(this.db, PATIENTS_COLLECTION, patientId)),
9181
- (0, import_firestore32.getDoc)(
9182
- (0, import_firestore32.doc)(
9489
+ (0, import_firestore33.getDoc)((0, import_firestore33.doc)(this.db, CLINICS_COLLECTION, clinicId)),
9490
+ (0, import_firestore33.getDoc)((0, import_firestore33.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId)),
9491
+ (0, import_firestore33.getDoc)((0, import_firestore33.doc)(this.db, PATIENTS_COLLECTION, patientId)),
9492
+ (0, import_firestore33.getDoc)(
9493
+ (0, import_firestore33.doc)(
9183
9494
  this.db,
9184
9495
  PATIENTS_COLLECTION,
9185
9496
  patientId,
@@ -9212,7 +9523,7 @@ var CalendarServiceV2 = class extends BaseService {
9212
9523
  fullName: `${sensitiveData.firstName} ${sensitiveData.lastName}`,
9213
9524
  email: sensitiveData.email || "",
9214
9525
  phone: sensitiveData.phoneNumber || null,
9215
- dateOfBirth: sensitiveData.dateOfBirth || import_firestore31.Timestamp.now(),
9526
+ dateOfBirth: sensitiveData.dateOfBirth || import_firestore32.Timestamp.now(),
9216
9527
  gender: sensitiveData.gender || "other" /* OTHER */
9217
9528
  };
9218
9529
  } else if (patientDoc.exists()) {
@@ -9221,7 +9532,7 @@ var CalendarServiceV2 = class extends BaseService {
9221
9532
  fullName: patientDoc.data().displayName,
9222
9533
  email: ((_a = patientDoc.data().contactInfo) == null ? void 0 : _a.email) || "",
9223
9534
  phone: patientDoc.data().phoneNumber || null,
9224
- dateOfBirth: patientDoc.data().dateOfBirth || import_firestore31.Timestamp.now(),
9535
+ dateOfBirth: patientDoc.data().dateOfBirth || import_firestore32.Timestamp.now(),
9225
9536
  gender: patientDoc.data().gender || "other" /* OTHER */
9226
9537
  };
9227
9538
  }
@@ -9243,54 +9554,54 @@ var CalendarServiceV2 = class extends BaseService {
9243
9554
  };
9244
9555
 
9245
9556
  // src/validations/notification.schema.ts
9246
- var import_zod18 = require("zod");
9247
- var baseNotificationSchema = import_zod18.z.object({
9248
- id: import_zod18.z.string().optional(),
9249
- userId: import_zod18.z.string(),
9250
- notificationTime: import_zod18.z.any(),
9557
+ var import_zod19 = require("zod");
9558
+ var baseNotificationSchema = import_zod19.z.object({
9559
+ id: import_zod19.z.string().optional(),
9560
+ userId: import_zod19.z.string(),
9561
+ notificationTime: import_zod19.z.any(),
9251
9562
  // Timestamp
9252
- notificationType: import_zod18.z.nativeEnum(NotificationType),
9253
- notificationTokens: import_zod18.z.array(import_zod18.z.string()),
9254
- status: import_zod18.z.nativeEnum(NotificationStatus),
9255
- createdAt: import_zod18.z.any().optional(),
9563
+ notificationType: import_zod19.z.nativeEnum(NotificationType),
9564
+ notificationTokens: import_zod19.z.array(import_zod19.z.string()),
9565
+ status: import_zod19.z.nativeEnum(NotificationStatus),
9566
+ createdAt: import_zod19.z.any().optional(),
9256
9567
  // Timestamp
9257
- updatedAt: import_zod18.z.any().optional(),
9568
+ updatedAt: import_zod19.z.any().optional(),
9258
9569
  // Timestamp
9259
- title: import_zod18.z.string(),
9260
- body: import_zod18.z.string(),
9261
- isRead: import_zod18.z.boolean(),
9262
- userRole: import_zod18.z.nativeEnum(UserRole)
9570
+ title: import_zod19.z.string(),
9571
+ body: import_zod19.z.string(),
9572
+ isRead: import_zod19.z.boolean(),
9573
+ userRole: import_zod19.z.nativeEnum(UserRole)
9263
9574
  });
9264
9575
  var preRequirementNotificationSchema = baseNotificationSchema.extend({
9265
- notificationType: import_zod18.z.literal("preRequirement" /* PRE_REQUIREMENT */),
9266
- treatmentId: import_zod18.z.string(),
9267
- requirements: import_zod18.z.array(import_zod18.z.string()),
9268
- deadline: import_zod18.z.any()
9576
+ notificationType: import_zod19.z.literal("preRequirement" /* PRE_REQUIREMENT */),
9577
+ treatmentId: import_zod19.z.string(),
9578
+ requirements: import_zod19.z.array(import_zod19.z.string()),
9579
+ deadline: import_zod19.z.any()
9269
9580
  // Timestamp
9270
9581
  });
9271
9582
  var postRequirementNotificationSchema = baseNotificationSchema.extend({
9272
- notificationType: import_zod18.z.literal("postRequirement" /* POST_REQUIREMENT */),
9273
- treatmentId: import_zod18.z.string(),
9274
- requirements: import_zod18.z.array(import_zod18.z.string()),
9275
- deadline: import_zod18.z.any()
9583
+ notificationType: import_zod19.z.literal("postRequirement" /* POST_REQUIREMENT */),
9584
+ treatmentId: import_zod19.z.string(),
9585
+ requirements: import_zod19.z.array(import_zod19.z.string()),
9586
+ deadline: import_zod19.z.any()
9276
9587
  // Timestamp
9277
9588
  });
9278
9589
  var appointmentReminderNotificationSchema = baseNotificationSchema.extend({
9279
- notificationType: import_zod18.z.literal("appointmentReminder" /* APPOINTMENT_REMINDER */),
9280
- appointmentId: import_zod18.z.string(),
9281
- appointmentTime: import_zod18.z.any(),
9590
+ notificationType: import_zod19.z.literal("appointmentReminder" /* APPOINTMENT_REMINDER */),
9591
+ appointmentId: import_zod19.z.string(),
9592
+ appointmentTime: import_zod19.z.any(),
9282
9593
  // Timestamp
9283
- treatmentType: import_zod18.z.string(),
9284
- doctorName: import_zod18.z.string()
9594
+ treatmentType: import_zod19.z.string(),
9595
+ doctorName: import_zod19.z.string()
9285
9596
  });
9286
9597
  var appointmentNotificationSchema = baseNotificationSchema.extend({
9287
- notificationType: import_zod18.z.literal("appointmentNotification" /* APPOINTMENT_NOTIFICATION */),
9288
- appointmentId: import_zod18.z.string(),
9289
- appointmentStatus: import_zod18.z.string(),
9290
- previousStatus: import_zod18.z.string(),
9291
- reason: import_zod18.z.string().optional()
9598
+ notificationType: import_zod19.z.literal("appointmentNotification" /* APPOINTMENT_NOTIFICATION */),
9599
+ appointmentId: import_zod19.z.string(),
9600
+ appointmentStatus: import_zod19.z.string(),
9601
+ previousStatus: import_zod19.z.string(),
9602
+ reason: import_zod19.z.string().optional()
9292
9603
  });
9293
- var notificationSchema = import_zod18.z.discriminatedUnion("notificationType", [
9604
+ var notificationSchema = import_zod19.z.discriminatedUnion("notificationType", [
9294
9605
  preRequirementNotificationSchema,
9295
9606
  postRequirementNotificationSchema,
9296
9607
  appointmentReminderNotificationSchema,
@@ -9353,6 +9664,7 @@ var notificationSchema = import_zod18.z.discriminatedUnion("notificationType", [
9353
9664
  PractitionerTokenStatus,
9354
9665
  PricingMeasure,
9355
9666
  ProcedureFamily,
9667
+ ProcedureService,
9356
9668
  REGISTER_TOKENS_COLLECTION,
9357
9669
  SYNCED_CALENDARS_COLLECTION,
9358
9670
  SubscriptionModel,