@blackcode_sa/metaestetics-api 1.5.4 → 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.
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,
@@ -1433,9 +1434,9 @@ var addAllergyUtil = async (db, patientId, data, userRef) => {
1433
1434
  var updateAllergyUtil = async (db, patientId, data, userRef) => {
1434
1435
  const validatedData = updateAllergySchema.parse(data);
1435
1436
  const { allergyIndex, ...updateData } = validatedData;
1436
- const doc20 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1437
- if (!doc20.exists()) throw new Error("Medical info not found");
1438
- 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();
1439
1440
  if (allergyIndex >= medicalInfo.allergies.length) {
1440
1441
  throw new Error("Invalid allergy index");
1441
1442
  }
@@ -1451,9 +1452,9 @@ var updateAllergyUtil = async (db, patientId, data, userRef) => {
1451
1452
  });
1452
1453
  };
1453
1454
  var removeAllergyUtil = async (db, patientId, allergyIndex, userRef) => {
1454
- const doc20 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1455
- if (!doc20.exists()) throw new Error("Medical info not found");
1456
- 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();
1457
1458
  if (allergyIndex >= medicalInfo.allergies.length) {
1458
1459
  throw new Error("Invalid allergy index");
1459
1460
  }
@@ -1478,9 +1479,9 @@ var addBlockingConditionUtil = async (db, patientId, data, userRef) => {
1478
1479
  var updateBlockingConditionUtil = async (db, patientId, data, userRef) => {
1479
1480
  const validatedData = updateBlockingConditionSchema.parse(data);
1480
1481
  const { conditionIndex, ...updateData } = validatedData;
1481
- const doc20 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1482
- if (!doc20.exists()) throw new Error("Medical info not found");
1483
- 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();
1484
1485
  if (conditionIndex >= medicalInfo.blockingConditions.length) {
1485
1486
  throw new Error("Invalid blocking condition index");
1486
1487
  }
@@ -1496,9 +1497,9 @@ var updateBlockingConditionUtil = async (db, patientId, data, userRef) => {
1496
1497
  });
1497
1498
  };
1498
1499
  var removeBlockingConditionUtil = async (db, patientId, conditionIndex, userRef) => {
1499
- const doc20 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1500
- if (!doc20.exists()) throw new Error("Medical info not found");
1501
- 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();
1502
1503
  if (conditionIndex >= medicalInfo.blockingConditions.length) {
1503
1504
  throw new Error("Invalid blocking condition index");
1504
1505
  }
@@ -1523,9 +1524,9 @@ var addContraindicationUtil = async (db, patientId, data, userRef) => {
1523
1524
  var updateContraindicationUtil = async (db, patientId, data, userRef) => {
1524
1525
  const validatedData = updateContraindicationSchema.parse(data);
1525
1526
  const { contraindicationIndex, ...updateData } = validatedData;
1526
- const doc20 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1527
- if (!doc20.exists()) throw new Error("Medical info not found");
1528
- 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();
1529
1530
  if (contraindicationIndex >= medicalInfo.contraindications.length) {
1530
1531
  throw new Error("Invalid contraindication index");
1531
1532
  }
@@ -1541,9 +1542,9 @@ var updateContraindicationUtil = async (db, patientId, data, userRef) => {
1541
1542
  });
1542
1543
  };
1543
1544
  var removeContraindicationUtil = async (db, patientId, contraindicationIndex, userRef) => {
1544
- const doc20 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1545
- if (!doc20.exists()) throw new Error("Medical info not found");
1546
- 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();
1547
1548
  if (contraindicationIndex >= medicalInfo.contraindications.length) {
1548
1549
  throw new Error("Invalid contraindication index");
1549
1550
  }
@@ -1568,9 +1569,9 @@ var addMedicationUtil = async (db, patientId, data, userRef) => {
1568
1569
  var updateMedicationUtil = async (db, patientId, data, userRef) => {
1569
1570
  const validatedData = updateMedicationSchema.parse(data);
1570
1571
  const { medicationIndex, ...updateData } = validatedData;
1571
- const doc20 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1572
- if (!doc20.exists()) throw new Error("Medical info not found");
1573
- 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();
1574
1575
  if (medicationIndex >= medicalInfo.currentMedications.length) {
1575
1576
  throw new Error("Invalid medication index");
1576
1577
  }
@@ -1586,9 +1587,9 @@ var updateMedicationUtil = async (db, patientId, data, userRef) => {
1586
1587
  });
1587
1588
  };
1588
1589
  var removeMedicationUtil = async (db, patientId, medicationIndex, userRef) => {
1589
- const doc20 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1590
- if (!doc20.exists()) throw new Error("Medical info not found");
1591
- 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();
1592
1593
  if (medicationIndex >= medicalInfo.currentMedications.length) {
1593
1594
  throw new Error("Invalid medication index");
1594
1595
  }
@@ -2882,7 +2883,7 @@ async function getClinicAdminsByGroup(db, clinicGroupId) {
2882
2883
  (0, import_firestore11.where)("clinicGroupId", "==", clinicGroupId)
2883
2884
  );
2884
2885
  const querySnapshot = await (0, import_firestore11.getDocs)(q);
2885
- return querySnapshot.docs.map((doc20) => doc20.data());
2886
+ return querySnapshot.docs.map((doc21) => doc21.data());
2886
2887
  }
2887
2888
  async function updateClinicAdmin(db, adminId, data) {
2888
2889
  const admin = await getClinicAdmin(db, adminId);
@@ -3537,7 +3538,7 @@ var PractitionerService = class extends BaseService {
3537
3538
  (0, import_firestore13.where)("expiresAt", ">", import_firestore13.Timestamp.now())
3538
3539
  );
3539
3540
  const querySnapshot = await (0, import_firestore13.getDocs)(q);
3540
- return querySnapshot.docs.map((doc20) => doc20.data());
3541
+ return querySnapshot.docs.map((doc21) => doc21.data());
3541
3542
  }
3542
3543
  /**
3543
3544
  * Gets a token by its string value and validates it
@@ -3620,7 +3621,7 @@ var PractitionerService = class extends BaseService {
3620
3621
  (0, import_firestore13.where)("status", "==", "active" /* ACTIVE */)
3621
3622
  );
3622
3623
  const querySnapshot = await (0, import_firestore13.getDocs)(q);
3623
- return querySnapshot.docs.map((doc20) => doc20.data());
3624
+ return querySnapshot.docs.map((doc21) => doc21.data());
3624
3625
  }
3625
3626
  /**
3626
3627
  * Dohvata sve draft zdravstvene radnike za određenu kliniku
@@ -3632,7 +3633,7 @@ var PractitionerService = class extends BaseService {
3632
3633
  (0, import_firestore13.where)("status", "==", "draft" /* DRAFT */)
3633
3634
  );
3634
3635
  const querySnapshot = await (0, import_firestore13.getDocs)(q);
3635
- return querySnapshot.docs.map((doc20) => doc20.data());
3636
+ return querySnapshot.docs.map((doc21) => doc21.data());
3636
3637
  }
3637
3638
  /**
3638
3639
  * Ažurira profil zdravstvenog radnika
@@ -3941,7 +3942,7 @@ var UserService = class extends BaseService {
3941
3942
  ];
3942
3943
  const q = (0, import_firestore14.query)((0, import_firestore14.collection)(this.db, USERS_COLLECTION), ...constraints);
3943
3944
  const querySnapshot = await (0, import_firestore14.getDocs)(q);
3944
- const users = querySnapshot.docs.map((doc20) => doc20.data());
3945
+ const users = querySnapshot.docs.map((doc21) => doc21.data());
3945
3946
  return Promise.all(users.map((userData) => userSchema.parse(userData)));
3946
3947
  }
3947
3948
  /**
@@ -4305,7 +4306,7 @@ async function getAllActiveGroups(db) {
4305
4306
  (0, import_firestore15.where)("isActive", "==", true)
4306
4307
  );
4307
4308
  const querySnapshot = await (0, import_firestore15.getDocs)(q);
4308
- return querySnapshot.docs.map((doc20) => doc20.data());
4309
+ return querySnapshot.docs.map((doc21) => doc21.data());
4309
4310
  }
4310
4311
  async function updateClinicGroup(db, groupId, data, app) {
4311
4312
  console.log("[CLINIC_GROUP] Updating clinic group", { groupId });
@@ -4965,7 +4966,7 @@ async function getClinicsByGroup(db, groupId) {
4965
4966
  (0, import_firestore16.where)("isActive", "==", true)
4966
4967
  );
4967
4968
  const querySnapshot = await (0, import_firestore16.getDocs)(q);
4968
- return querySnapshot.docs.map((doc20) => doc20.data());
4969
+ return querySnapshot.docs.map((doc21) => doc21.data());
4969
4970
  }
4970
4971
  async function updateClinic(db, clinicId, data, adminId, clinicAdminService, app) {
4971
4972
  console.log("[CLINIC] Starting clinic update", { clinicId, adminId });
@@ -5177,7 +5178,7 @@ async function getClinicsByAdmin(db, adminId, options = {}, clinicAdminService,
5177
5178
  }
5178
5179
  const q = (0, import_firestore16.query)((0, import_firestore16.collection)(db, CLINICS_COLLECTION), ...constraints);
5179
5180
  const querySnapshot = await (0, import_firestore16.getDocs)(q);
5180
- return querySnapshot.docs.map((doc20) => doc20.data());
5181
+ return querySnapshot.docs.map((doc21) => doc21.data());
5181
5182
  }
5182
5183
  async function getActiveClinicsByAdmin(db, adminId, clinicAdminService, clinicGroupService) {
5183
5184
  return getClinicsByAdmin(
@@ -5319,8 +5320,8 @@ async function findClinicsInRadius(db, center, radiusInKm, filters) {
5319
5320
  }
5320
5321
  const q = (0, import_firestore18.query)((0, import_firestore18.collection)(db, CLINICS_COLLECTION), ...constraints);
5321
5322
  const querySnapshot = await (0, import_firestore18.getDocs)(q);
5322
- for (const doc20 of querySnapshot.docs) {
5323
- const clinic = doc20.data();
5323
+ for (const doc21 of querySnapshot.docs) {
5324
+ const clinic = doc21.data();
5324
5325
  const distance = (0, import_geofire_common4.distanceBetween)(
5325
5326
  [center.latitude, center.longitude],
5326
5327
  [clinic.location.latitude, clinic.location.longitude]
@@ -6252,9 +6253,9 @@ var NotificationService = class extends BaseService {
6252
6253
  (0, import_firestore20.orderBy)("notificationTime", "desc")
6253
6254
  );
6254
6255
  const querySnapshot = await (0, import_firestore20.getDocs)(q);
6255
- return querySnapshot.docs.map((doc20) => ({
6256
- id: doc20.id,
6257
- ...doc20.data()
6256
+ return querySnapshot.docs.map((doc21) => ({
6257
+ id: doc21.id,
6258
+ ...doc21.data()
6258
6259
  }));
6259
6260
  }
6260
6261
  /**
@@ -6268,9 +6269,9 @@ var NotificationService = class extends BaseService {
6268
6269
  (0, import_firestore20.orderBy)("notificationTime", "desc")
6269
6270
  );
6270
6271
  const querySnapshot = await (0, import_firestore20.getDocs)(q);
6271
- return querySnapshot.docs.map((doc20) => ({
6272
- id: doc20.id,
6273
- ...doc20.data()
6272
+ return querySnapshot.docs.map((doc21) => ({
6273
+ id: doc21.id,
6274
+ ...doc21.data()
6274
6275
  }));
6275
6276
  }
6276
6277
  /**
@@ -6342,9 +6343,9 @@ var NotificationService = class extends BaseService {
6342
6343
  (0, import_firestore20.orderBy)("notificationTime", "desc")
6343
6344
  );
6344
6345
  const querySnapshot = await (0, import_firestore20.getDocs)(q);
6345
- return querySnapshot.docs.map((doc20) => ({
6346
- id: doc20.id,
6347
- ...doc20.data()
6346
+ return querySnapshot.docs.map((doc21) => ({
6347
+ id: doc21.id,
6348
+ ...doc21.data()
6348
6349
  }));
6349
6350
  }
6350
6351
  /**
@@ -6357,19 +6358,252 @@ var NotificationService = class extends BaseService {
6357
6358
  (0, import_firestore20.orderBy)("notificationTime", "desc")
6358
6359
  );
6359
6360
  const querySnapshot = await (0, import_firestore20.getDocs)(q);
6360
- return querySnapshot.docs.map((doc20) => ({
6361
- id: doc20.id,
6362
- ...doc20.data()
6361
+ return querySnapshot.docs.map((doc21) => ({
6362
+ id: doc21.id,
6363
+ ...doc21.data()
6363
6364
  }));
6364
6365
  }
6365
6366
  };
6366
6367
 
6367
- // src/services/documentation-templates/documentation-template.service.ts
6368
+ // src/services/procedure/procedure.service.ts
6368
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");
6369
6603
  var DocumentationTemplateService = class extends BaseService {
6370
6604
  constructor() {
6371
6605
  super(...arguments);
6372
- this.collectionRef = (0, import_firestore21.collection)(
6606
+ this.collectionRef = (0, import_firestore22.collection)(
6373
6607
  this.db,
6374
6608
  DOCUMENTATION_TEMPLATES_COLLECTION
6375
6609
  );
@@ -6400,8 +6634,8 @@ var DocumentationTemplateService = class extends BaseService {
6400
6634
  isActive: true,
6401
6635
  tags: validatedData.tags || []
6402
6636
  };
6403
- const docRef = (0, import_firestore21.doc)(this.collectionRef, templateId);
6404
- 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);
6405
6639
  return template;
6406
6640
  }
6407
6641
  /**
@@ -6410,8 +6644,8 @@ var DocumentationTemplateService = class extends BaseService {
6410
6644
  * @returns The template or null if not found
6411
6645
  */
6412
6646
  async getTemplateById(templateId) {
6413
- const docRef = (0, import_firestore21.doc)(this.collectionRef, templateId);
6414
- 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);
6415
6649
  if (!docSnap.exists()) {
6416
6650
  return null;
6417
6651
  }
@@ -6442,8 +6676,8 @@ var DocumentationTemplateService = class extends BaseService {
6442
6676
  updatedAt: Date.now(),
6443
6677
  version: template.version + 1
6444
6678
  };
6445
- const docRef = (0, import_firestore21.doc)(this.collectionRef, templateId);
6446
- 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);
6447
6681
  return {
6448
6682
  ...template,
6449
6683
  ...updateData
@@ -6454,8 +6688,8 @@ var DocumentationTemplateService = class extends BaseService {
6454
6688
  * @param templateId - ID of the template to delete
6455
6689
  */
6456
6690
  async deleteTemplate(templateId) {
6457
- const docRef = (0, import_firestore21.doc)(this.collectionRef, templateId);
6458
- await (0, import_firestore21.deleteDoc)(docRef);
6691
+ const docRef = (0, import_firestore22.doc)(this.collectionRef, templateId);
6692
+ await (0, import_firestore22.deleteDoc)(docRef);
6459
6693
  }
6460
6694
  /**
6461
6695
  * Get all active templates
@@ -6464,21 +6698,21 @@ var DocumentationTemplateService = class extends BaseService {
6464
6698
  * @returns Array of templates and the last document for pagination
6465
6699
  */
6466
6700
  async getActiveTemplates(pageSize = 20, lastDoc) {
6467
- let q = (0, import_firestore21.query)(
6701
+ let q = (0, import_firestore22.query)(
6468
6702
  this.collectionRef,
6469
- (0, import_firestore21.where)("isActive", "==", true),
6470
- (0, import_firestore21.orderBy)("updatedAt", "desc"),
6471
- (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)
6472
6706
  );
6473
6707
  if (lastDoc) {
6474
- q = (0, import_firestore21.query)(q, (0, import_firestore21.startAfter)(lastDoc));
6708
+ q = (0, import_firestore22.query)(q, (0, import_firestore22.startAfter)(lastDoc));
6475
6709
  }
6476
- const querySnapshot = await (0, import_firestore21.getDocs)(q);
6710
+ const querySnapshot = await (0, import_firestore22.getDocs)(q);
6477
6711
  const templates = [];
6478
6712
  let lastVisible = null;
6479
- querySnapshot.forEach((doc20) => {
6480
- templates.push(doc20.data());
6481
- lastVisible = doc20;
6713
+ querySnapshot.forEach((doc21) => {
6714
+ templates.push(doc21.data());
6715
+ lastVisible = doc21;
6482
6716
  });
6483
6717
  return {
6484
6718
  templates,
@@ -6493,22 +6727,22 @@ var DocumentationTemplateService = class extends BaseService {
6493
6727
  * @returns Array of templates and the last document for pagination
6494
6728
  */
6495
6729
  async getTemplatesByTags(tags, pageSize = 20, lastDoc) {
6496
- let q = (0, import_firestore21.query)(
6730
+ let q = (0, import_firestore22.query)(
6497
6731
  this.collectionRef,
6498
- (0, import_firestore21.where)("isActive", "==", true),
6499
- (0, import_firestore21.where)("tags", "array-contains-any", tags),
6500
- (0, import_firestore21.orderBy)("updatedAt", "desc"),
6501
- (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)
6502
6736
  );
6503
6737
  if (lastDoc) {
6504
- q = (0, import_firestore21.query)(q, (0, import_firestore21.startAfter)(lastDoc));
6738
+ q = (0, import_firestore22.query)(q, (0, import_firestore22.startAfter)(lastDoc));
6505
6739
  }
6506
- const querySnapshot = await (0, import_firestore21.getDocs)(q);
6740
+ const querySnapshot = await (0, import_firestore22.getDocs)(q);
6507
6741
  const templates = [];
6508
6742
  let lastVisible = null;
6509
- querySnapshot.forEach((doc20) => {
6510
- templates.push(doc20.data());
6511
- lastVisible = doc20;
6743
+ querySnapshot.forEach((doc21) => {
6744
+ templates.push(doc21.data());
6745
+ lastVisible = doc21;
6512
6746
  });
6513
6747
  return {
6514
6748
  templates,
@@ -6523,21 +6757,21 @@ var DocumentationTemplateService = class extends BaseService {
6523
6757
  * @returns Array of templates and the last document for pagination
6524
6758
  */
6525
6759
  async getTemplatesByCreator(userId, pageSize = 20, lastDoc) {
6526
- let q = (0, import_firestore21.query)(
6760
+ let q = (0, import_firestore22.query)(
6527
6761
  this.collectionRef,
6528
- (0, import_firestore21.where)("createdBy", "==", userId),
6529
- (0, import_firestore21.orderBy)("updatedAt", "desc"),
6530
- (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)
6531
6765
  );
6532
6766
  if (lastDoc) {
6533
- q = (0, import_firestore21.query)(q, (0, import_firestore21.startAfter)(lastDoc));
6767
+ q = (0, import_firestore22.query)(q, (0, import_firestore22.startAfter)(lastDoc));
6534
6768
  }
6535
- const querySnapshot = await (0, import_firestore21.getDocs)(q);
6769
+ const querySnapshot = await (0, import_firestore22.getDocs)(q);
6536
6770
  const templates = [];
6537
6771
  let lastVisible = null;
6538
- querySnapshot.forEach((doc20) => {
6539
- templates.push(doc20.data());
6540
- lastVisible = doc20;
6772
+ querySnapshot.forEach((doc21) => {
6773
+ templates.push(doc21.data());
6774
+ lastVisible = doc21;
6541
6775
  });
6542
6776
  return {
6543
6777
  templates,
@@ -6547,11 +6781,11 @@ var DocumentationTemplateService = class extends BaseService {
6547
6781
  };
6548
6782
 
6549
6783
  // src/services/documentation-templates/filled-document.service.ts
6550
- var import_firestore22 = require("firebase/firestore");
6784
+ var import_firestore23 = require("firebase/firestore");
6551
6785
  var FilledDocumentService = class extends BaseService {
6552
6786
  constructor(...args) {
6553
6787
  super(...args);
6554
- this.collectionRef = (0, import_firestore22.collection)(
6788
+ this.collectionRef = (0, import_firestore23.collection)(
6555
6789
  this.db,
6556
6790
  FILLED_DOCUMENTS_COLLECTION
6557
6791
  );
@@ -6584,8 +6818,8 @@ var FilledDocumentService = class extends BaseService {
6584
6818
  values: {},
6585
6819
  status: "draft" /* DRAFT */
6586
6820
  };
6587
- const docRef = (0, import_firestore22.doc)(this.collectionRef, documentId);
6588
- 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);
6589
6823
  return filledDocument;
6590
6824
  }
6591
6825
  /**
@@ -6594,8 +6828,8 @@ var FilledDocumentService = class extends BaseService {
6594
6828
  * @returns The filled document or null if not found
6595
6829
  */
6596
6830
  async getFilledDocumentById(documentId) {
6597
- const docRef = (0, import_firestore22.doc)(this.collectionRef, documentId);
6598
- 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);
6599
6833
  if (!docSnap.exists()) {
6600
6834
  return null;
6601
6835
  }
@@ -6623,8 +6857,8 @@ var FilledDocumentService = class extends BaseService {
6623
6857
  if (status) {
6624
6858
  updateData.status = status;
6625
6859
  }
6626
- const docRef = (0, import_firestore22.doc)(this.collectionRef, documentId);
6627
- 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);
6628
6862
  return {
6629
6863
  ...filledDocument,
6630
6864
  ...updateData
@@ -6638,21 +6872,21 @@ var FilledDocumentService = class extends BaseService {
6638
6872
  * @returns Array of filled documents and the last document for pagination
6639
6873
  */
6640
6874
  async getFilledDocumentsByPatient(patientId, pageSize = 20, lastDoc) {
6641
- let q = (0, import_firestore22.query)(
6875
+ let q = (0, import_firestore23.query)(
6642
6876
  this.collectionRef,
6643
- (0, import_firestore22.where)("patientId", "==", patientId),
6644
- (0, import_firestore22.orderBy)("updatedAt", "desc"),
6645
- (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)
6646
6880
  );
6647
6881
  if (lastDoc) {
6648
- q = (0, import_firestore22.query)(q, (0, import_firestore22.startAfter)(lastDoc));
6882
+ q = (0, import_firestore23.query)(q, (0, import_firestore23.startAfter)(lastDoc));
6649
6883
  }
6650
- const querySnapshot = await (0, import_firestore22.getDocs)(q);
6884
+ const querySnapshot = await (0, import_firestore23.getDocs)(q);
6651
6885
  const documents = [];
6652
6886
  let lastVisible = null;
6653
- querySnapshot.forEach((doc20) => {
6654
- documents.push(doc20.data());
6655
- lastVisible = doc20;
6887
+ querySnapshot.forEach((doc21) => {
6888
+ documents.push(doc21.data());
6889
+ lastVisible = doc21;
6656
6890
  });
6657
6891
  return {
6658
6892
  documents,
@@ -6667,21 +6901,21 @@ var FilledDocumentService = class extends BaseService {
6667
6901
  * @returns Array of filled documents and the last document for pagination
6668
6902
  */
6669
6903
  async getFilledDocumentsByPractitioner(practitionerId, pageSize = 20, lastDoc) {
6670
- let q = (0, import_firestore22.query)(
6904
+ let q = (0, import_firestore23.query)(
6671
6905
  this.collectionRef,
6672
- (0, import_firestore22.where)("practitionerId", "==", practitionerId),
6673
- (0, import_firestore22.orderBy)("updatedAt", "desc"),
6674
- (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)
6675
6909
  );
6676
6910
  if (lastDoc) {
6677
- q = (0, import_firestore22.query)(q, (0, import_firestore22.startAfter)(lastDoc));
6911
+ q = (0, import_firestore23.query)(q, (0, import_firestore23.startAfter)(lastDoc));
6678
6912
  }
6679
- const querySnapshot = await (0, import_firestore22.getDocs)(q);
6913
+ const querySnapshot = await (0, import_firestore23.getDocs)(q);
6680
6914
  const documents = [];
6681
6915
  let lastVisible = null;
6682
- querySnapshot.forEach((doc20) => {
6683
- documents.push(doc20.data());
6684
- lastVisible = doc20;
6916
+ querySnapshot.forEach((doc21) => {
6917
+ documents.push(doc21.data());
6918
+ lastVisible = doc21;
6685
6919
  });
6686
6920
  return {
6687
6921
  documents,
@@ -6696,21 +6930,21 @@ var FilledDocumentService = class extends BaseService {
6696
6930
  * @returns Array of filled documents and the last document for pagination
6697
6931
  */
6698
6932
  async getFilledDocumentsByClinic(clinicId, pageSize = 20, lastDoc) {
6699
- let q = (0, import_firestore22.query)(
6933
+ let q = (0, import_firestore23.query)(
6700
6934
  this.collectionRef,
6701
- (0, import_firestore22.where)("clinicId", "==", clinicId),
6702
- (0, import_firestore22.orderBy)("updatedAt", "desc"),
6703
- (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)
6704
6938
  );
6705
6939
  if (lastDoc) {
6706
- q = (0, import_firestore22.query)(q, (0, import_firestore22.startAfter)(lastDoc));
6940
+ q = (0, import_firestore23.query)(q, (0, import_firestore23.startAfter)(lastDoc));
6707
6941
  }
6708
- const querySnapshot = await (0, import_firestore22.getDocs)(q);
6942
+ const querySnapshot = await (0, import_firestore23.getDocs)(q);
6709
6943
  const documents = [];
6710
6944
  let lastVisible = null;
6711
- querySnapshot.forEach((doc20) => {
6712
- documents.push(doc20.data());
6713
- lastVisible = doc20;
6945
+ querySnapshot.forEach((doc21) => {
6946
+ documents.push(doc21.data());
6947
+ lastVisible = doc21;
6714
6948
  });
6715
6949
  return {
6716
6950
  documents,
@@ -6725,21 +6959,21 @@ var FilledDocumentService = class extends BaseService {
6725
6959
  * @returns Array of filled documents and the last document for pagination
6726
6960
  */
6727
6961
  async getFilledDocumentsByTemplate(templateId, pageSize = 20, lastDoc) {
6728
- let q = (0, import_firestore22.query)(
6962
+ let q = (0, import_firestore23.query)(
6729
6963
  this.collectionRef,
6730
- (0, import_firestore22.where)("templateId", "==", templateId),
6731
- (0, import_firestore22.orderBy)("updatedAt", "desc"),
6732
- (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)
6733
6967
  );
6734
6968
  if (lastDoc) {
6735
- q = (0, import_firestore22.query)(q, (0, import_firestore22.startAfter)(lastDoc));
6969
+ q = (0, import_firestore23.query)(q, (0, import_firestore23.startAfter)(lastDoc));
6736
6970
  }
6737
- const querySnapshot = await (0, import_firestore22.getDocs)(q);
6971
+ const querySnapshot = await (0, import_firestore23.getDocs)(q);
6738
6972
  const documents = [];
6739
6973
  let lastVisible = null;
6740
- querySnapshot.forEach((doc20) => {
6741
- documents.push(doc20.data());
6742
- lastVisible = doc20;
6974
+ querySnapshot.forEach((doc21) => {
6975
+ documents.push(doc21.data());
6976
+ lastVisible = doc21;
6743
6977
  });
6744
6978
  return {
6745
6979
  documents,
@@ -6754,21 +6988,21 @@ var FilledDocumentService = class extends BaseService {
6754
6988
  * @returns Array of filled documents and the last document for pagination
6755
6989
  */
6756
6990
  async getFilledDocumentsByStatus(status, pageSize = 20, lastDoc) {
6757
- let q = (0, import_firestore22.query)(
6991
+ let q = (0, import_firestore23.query)(
6758
6992
  this.collectionRef,
6759
- (0, import_firestore22.where)("status", "==", status),
6760
- (0, import_firestore22.orderBy)("updatedAt", "desc"),
6761
- (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)
6762
6996
  );
6763
6997
  if (lastDoc) {
6764
- q = (0, import_firestore22.query)(q, (0, import_firestore22.startAfter)(lastDoc));
6998
+ q = (0, import_firestore23.query)(q, (0, import_firestore23.startAfter)(lastDoc));
6765
6999
  }
6766
- const querySnapshot = await (0, import_firestore22.getDocs)(q);
7000
+ const querySnapshot = await (0, import_firestore23.getDocs)(q);
6767
7001
  const documents = [];
6768
7002
  let lastVisible = null;
6769
- querySnapshot.forEach((doc20) => {
6770
- documents.push(doc20.data());
6771
- lastVisible = doc20;
7003
+ querySnapshot.forEach((doc21) => {
7004
+ documents.push(doc21.data());
7005
+ lastVisible = doc21;
6772
7006
  });
6773
7007
  return {
6774
7008
  documents,
@@ -6778,7 +7012,7 @@ var FilledDocumentService = class extends BaseService {
6778
7012
  };
6779
7013
 
6780
7014
  // src/services/calendar/calendar-refactored.service.ts
6781
- var import_firestore31 = require("firebase/firestore");
7015
+ var import_firestore32 = require("firebase/firestore");
6782
7016
 
6783
7017
  // src/types/calendar/synced-calendar.types.ts
6784
7018
  var SyncedCalendarProvider = /* @__PURE__ */ ((SyncedCalendarProvider3) => {
@@ -6790,49 +7024,49 @@ var SyncedCalendarProvider = /* @__PURE__ */ ((SyncedCalendarProvider3) => {
6790
7024
  var SYNCED_CALENDARS_COLLECTION = "syncedCalendars";
6791
7025
 
6792
7026
  // src/services/calendar/calendar-refactored.service.ts
6793
- var import_firestore32 = require("firebase/firestore");
7027
+ var import_firestore33 = require("firebase/firestore");
6794
7028
 
6795
7029
  // src/validations/calendar.schema.ts
6796
- var import_zod17 = require("zod");
6797
- var import_firestore24 = require("firebase/firestore");
7030
+ var import_zod18 = require("zod");
7031
+ var import_firestore25 = require("firebase/firestore");
6798
7032
 
6799
7033
  // src/validations/profile-info.schema.ts
6800
- var import_zod16 = require("zod");
6801
- var import_firestore23 = require("firebase/firestore");
6802
- var clinicInfoSchema2 = import_zod16.z.object({
6803
- id: import_zod16.z.string(),
6804
- featuredPhoto: import_zod16.z.string(),
6805
- name: import_zod16.z.string(),
6806
- 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(),
6807
7041
  location: clinicLocationSchema,
6808
7042
  contactInfo: clinicContactInfoSchema
6809
7043
  });
6810
- var practitionerProfileInfoSchema = import_zod16.z.object({
6811
- id: import_zod16.z.string(),
6812
- practitionerPhoto: import_zod16.z.string().nullable(),
6813
- name: import_zod16.z.string(),
6814
- email: import_zod16.z.string().email(),
6815
- 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(),
6816
7050
  certification: practitionerCertificationSchema
6817
7051
  });
6818
- var patientProfileInfoSchema = import_zod16.z.object({
6819
- id: import_zod16.z.string(),
6820
- fullName: import_zod16.z.string(),
6821
- email: import_zod16.z.string().email(),
6822
- phone: import_zod16.z.string().nullable(),
6823
- dateOfBirth: import_zod16.z.instanceof(import_firestore23.Timestamp),
6824
- 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)
6825
7059
  });
6826
7060
 
6827
7061
  // src/validations/calendar.schema.ts
6828
7062
  var MIN_APPOINTMENT_DURATION = 15;
6829
- var calendarEventTimeSchema = import_zod17.z.object({
6830
- start: import_zod17.z.instanceof(Date).or(import_zod17.z.instanceof(import_firestore24.Timestamp)),
6831
- 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))
6832
7066
  }).refine(
6833
7067
  (data) => {
6834
- const startDate = data.start instanceof import_firestore24.Timestamp ? data.start.toDate() : data.start;
6835
- 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;
6836
7070
  return startDate < endDate;
6837
7071
  },
6838
7072
  {
@@ -6841,7 +7075,7 @@ var calendarEventTimeSchema = import_zod17.z.object({
6841
7075
  }
6842
7076
  ).refine(
6843
7077
  (data) => {
6844
- 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;
6845
7079
  return startDate > /* @__PURE__ */ new Date();
6846
7080
  },
6847
7081
  {
@@ -6849,46 +7083,46 @@ var calendarEventTimeSchema = import_zod17.z.object({
6849
7083
  path: ["start"]
6850
7084
  }
6851
7085
  );
6852
- var timeSlotSchema2 = import_zod17.z.object({
6853
- start: import_zod17.z.date(),
6854
- end: import_zod17.z.date(),
6855
- 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()
6856
7090
  }).refine((data) => data.start < data.end, {
6857
7091
  message: "End time must be after start time",
6858
7092
  path: ["end"]
6859
7093
  });
6860
- var syncedCalendarEventSchema = import_zod17.z.object({
6861
- eventId: import_zod17.z.string(),
6862
- syncedCalendarProvider: import_zod17.z.nativeEnum(SyncedCalendarProvider),
6863
- 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))
6864
7098
  });
6865
- var procedureInfoSchema = import_zod17.z.object({
6866
- name: import_zod17.z.string(),
6867
- description: import_zod17.z.string(),
6868
- duration: import_zod17.z.number().min(MIN_APPOINTMENT_DURATION),
6869
- price: import_zod17.z.number().min(0),
6870
- 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)
6871
7105
  });
6872
- var procedureCategorizationSchema = import_zod17.z.object({
6873
- procedureFamily: import_zod17.z.string(),
7106
+ var procedureCategorizationSchema = import_zod18.z.object({
7107
+ procedureFamily: import_zod18.z.string(),
6874
7108
  // Replace with proper enum when available
6875
- procedureCategory: import_zod17.z.string(),
7109
+ procedureCategory: import_zod18.z.string(),
6876
7110
  // Replace with proper enum when available
6877
- procedureSubcategory: import_zod17.z.string(),
7111
+ procedureSubcategory: import_zod18.z.string(),
6878
7112
  // Replace with proper enum when available
6879
- procedureTechnology: import_zod17.z.string(),
7113
+ procedureTechnology: import_zod18.z.string(),
6880
7114
  // Replace with proper enum when available
6881
- procedureProduct: import_zod17.z.string()
7115
+ procedureProduct: import_zod18.z.string()
6882
7116
  // Replace with proper enum when available
6883
7117
  });
6884
- var createAppointmentSchema = import_zod17.z.object({
6885
- clinicId: import_zod17.z.string().min(1, "Clinic ID is required"),
6886
- doctorId: import_zod17.z.string().min(1, "Doctor ID is required"),
6887
- patientId: import_zod17.z.string().min(1, "Patient ID is required"),
6888
- 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"),
6889
7123
  eventLocation: clinicLocationSchema,
6890
7124
  eventTime: calendarEventTimeSchema,
6891
- description: import_zod17.z.string().optional()
7125
+ description: import_zod18.z.string().optional()
6892
7126
  }).refine(
6893
7127
  (data) => {
6894
7128
  return true;
@@ -6897,112 +7131,112 @@ var createAppointmentSchema = import_zod17.z.object({
6897
7131
  message: "Invalid appointment parameters"
6898
7132
  }
6899
7133
  );
6900
- var updateAppointmentSchema = import_zod17.z.object({
6901
- appointmentId: import_zod17.z.string().min(1, "Appointment ID is required"),
6902
- clinicId: import_zod17.z.string().min(1, "Clinic ID is required"),
6903
- doctorId: import_zod17.z.string().min(1, "Doctor ID is required"),
6904
- 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"),
6905
7139
  eventTime: calendarEventTimeSchema.optional(),
6906
- description: import_zod17.z.string().optional(),
6907
- status: import_zod17.z.nativeEnum(CalendarEventStatus).optional()
7140
+ description: import_zod18.z.string().optional(),
7141
+ status: import_zod18.z.nativeEnum(CalendarEventStatus).optional()
6908
7142
  });
6909
- var createCalendarEventSchema = import_zod17.z.object({
6910
- id: import_zod17.z.string(),
6911
- clinicBranchId: import_zod17.z.string().nullable().optional(),
6912
- clinicBranchInfo: import_zod17.z.any().nullable().optional(),
6913
- 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(),
6914
7148
  practitionerProfileInfo: practitionerProfileInfoSchema.nullable().optional(),
6915
- patientProfileId: import_zod17.z.string().nullable().optional(),
7149
+ patientProfileId: import_zod18.z.string().nullable().optional(),
6916
7150
  patientProfileInfo: patientProfileInfoSchema.nullable().optional(),
6917
- procedureId: import_zod17.z.string().nullable().optional(),
6918
- appointmentId: import_zod17.z.string().nullable().optional(),
6919
- syncedCalendarEventId: import_zod17.z.array(syncedCalendarEventSchema).nullable().optional(),
6920
- 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"),
6921
7155
  eventLocation: clinicLocationSchema.optional(),
6922
7156
  eventTime: calendarEventTimeSchema,
6923
- description: import_zod17.z.string().optional(),
6924
- status: import_zod17.z.nativeEnum(CalendarEventStatus),
6925
- syncStatus: import_zod17.z.nativeEnum(CalendarSyncStatus),
6926
- eventType: import_zod17.z.nativeEnum(CalendarEventType),
6927
- 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(),
6928
7162
  // FieldValue for server timestamp
6929
- updatedAt: import_zod17.z.any()
7163
+ updatedAt: import_zod18.z.any()
6930
7164
  // FieldValue for server timestamp
6931
7165
  });
6932
- var updateCalendarEventSchema = import_zod17.z.object({
6933
- syncedCalendarEventId: import_zod17.z.array(syncedCalendarEventSchema).nullable().optional(),
6934
- appointmentId: import_zod17.z.string().nullable().optional(),
6935
- 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(),
6936
7170
  eventTime: calendarEventTimeSchema.optional(),
6937
- description: import_zod17.z.string().optional(),
6938
- status: import_zod17.z.nativeEnum(CalendarEventStatus).optional(),
6939
- syncStatus: import_zod17.z.nativeEnum(CalendarSyncStatus).optional(),
6940
- eventType: import_zod17.z.nativeEnum(CalendarEventType).optional(),
6941
- 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()
6942
7176
  // FieldValue for server timestamp
6943
7177
  });
6944
- var calendarEventSchema = import_zod17.z.object({
6945
- id: import_zod17.z.string(),
6946
- clinicBranchId: import_zod17.z.string().nullable().optional(),
6947
- 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(),
6948
7182
  // Will be replaced with proper clinic info schema
6949
- practitionerProfileId: import_zod17.z.string().nullable().optional(),
7183
+ practitionerProfileId: import_zod18.z.string().nullable().optional(),
6950
7184
  practitionerProfileInfo: practitionerProfileInfoSchema.nullable().optional(),
6951
- patientProfileId: import_zod17.z.string().nullable().optional(),
7185
+ patientProfileId: import_zod18.z.string().nullable().optional(),
6952
7186
  patientProfileInfo: patientProfileInfoSchema.nullable().optional(),
6953
- procedureId: import_zod17.z.string().nullable().optional(),
7187
+ procedureId: import_zod18.z.string().nullable().optional(),
6954
7188
  procedureInfo: procedureInfoSchema.nullable().optional(),
6955
7189
  procedureCategorization: procedureCategorizationSchema.nullable().optional(),
6956
- appointmentId: import_zod17.z.string().nullable().optional(),
6957
- syncedCalendarEventId: import_zod17.z.array(syncedCalendarEventSchema).nullable().optional(),
6958
- 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(),
6959
7193
  eventLocation: clinicLocationSchema.optional(),
6960
7194
  eventTime: calendarEventTimeSchema,
6961
- description: import_zod17.z.string().optional(),
6962
- status: import_zod17.z.nativeEnum(CalendarEventStatus),
6963
- syncStatus: import_zod17.z.nativeEnum(CalendarSyncStatus),
6964
- eventType: import_zod17.z.nativeEnum(CalendarEventType),
6965
- createdAt: import_zod17.z.instanceof(Date).or(import_zod17.z.instanceof(import_firestore24.Timestamp)),
6966
- 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))
6967
7201
  });
6968
7202
 
6969
7203
  // src/services/calendar/utils/clinic.utils.ts
6970
- var import_firestore26 = require("firebase/firestore");
7204
+ var import_firestore27 = require("firebase/firestore");
6971
7205
 
6972
7206
  // src/services/calendar/utils/docs.utils.ts
6973
- var import_firestore25 = require("firebase/firestore");
7207
+ var import_firestore26 = require("firebase/firestore");
6974
7208
  function getPractitionerCalendarEventDocRef(db, practitionerId, eventId) {
6975
- return (0, import_firestore25.doc)(
7209
+ return (0, import_firestore26.doc)(
6976
7210
  db,
6977
7211
  `${PRACTITIONERS_COLLECTION}/${practitionerId}/${CALENDAR_COLLECTION}/${eventId}`
6978
7212
  );
6979
7213
  }
6980
7214
  function getPatientCalendarEventDocRef(db, patientId, eventId) {
6981
- return (0, import_firestore25.doc)(
7215
+ return (0, import_firestore26.doc)(
6982
7216
  db,
6983
7217
  `${PATIENTS_COLLECTION}/${patientId}/${CALENDAR_COLLECTION}/${eventId}`
6984
7218
  );
6985
7219
  }
6986
7220
  function getClinicCalendarEventDocRef(db, clinicId, eventId) {
6987
- return (0, import_firestore25.doc)(
7221
+ return (0, import_firestore26.doc)(
6988
7222
  db,
6989
7223
  `${CLINICS_COLLECTION}/${clinicId}/${CALENDAR_COLLECTION}/${eventId}`
6990
7224
  );
6991
7225
  }
6992
7226
  function getPractitionerSyncedCalendarDocRef(db, practitionerId, syncedCalendarId) {
6993
- return (0, import_firestore25.doc)(
7227
+ return (0, import_firestore26.doc)(
6994
7228
  db,
6995
7229
  `${PRACTITIONERS_COLLECTION}/${practitionerId}/syncedCalendars/${syncedCalendarId}`
6996
7230
  );
6997
7231
  }
6998
7232
  function getPatientSyncedCalendarDocRef(db, patientId, syncedCalendarId) {
6999
- return (0, import_firestore25.doc)(
7233
+ return (0, import_firestore26.doc)(
7000
7234
  db,
7001
7235
  `${PATIENTS_COLLECTION}/${patientId}/syncedCalendars/${syncedCalendarId}`
7002
7236
  );
7003
7237
  }
7004
7238
  function getClinicSyncedCalendarDocRef(db, clinicId, syncedCalendarId) {
7005
- return (0, import_firestore25.doc)(
7239
+ return (0, import_firestore26.doc)(
7006
7240
  db,
7007
7241
  `${CLINICS_COLLECTION}/${clinicId}/syncedCalendars/${syncedCalendarId}`
7008
7242
  );
@@ -7015,31 +7249,31 @@ async function createClinicCalendarEventUtil(db, clinicId, eventData, generateId
7015
7249
  const newEvent = {
7016
7250
  id: eventId,
7017
7251
  ...eventData,
7018
- createdAt: (0, import_firestore26.serverTimestamp)(),
7019
- updatedAt: (0, import_firestore26.serverTimestamp)()
7252
+ createdAt: (0, import_firestore27.serverTimestamp)(),
7253
+ updatedAt: (0, import_firestore27.serverTimestamp)()
7020
7254
  };
7021
- await (0, import_firestore26.setDoc)(eventRef, newEvent);
7255
+ await (0, import_firestore27.setDoc)(eventRef, newEvent);
7022
7256
  return {
7023
7257
  ...newEvent,
7024
- createdAt: import_firestore26.Timestamp.now(),
7025
- updatedAt: import_firestore26.Timestamp.now()
7258
+ createdAt: import_firestore27.Timestamp.now(),
7259
+ updatedAt: import_firestore27.Timestamp.now()
7026
7260
  };
7027
7261
  }
7028
7262
  async function updateClinicCalendarEventUtil(db, clinicId, eventId, updateData) {
7029
7263
  const eventRef = getClinicCalendarEventDocRef(db, clinicId, eventId);
7030
7264
  const updates = {
7031
7265
  ...updateData,
7032
- updatedAt: (0, import_firestore26.serverTimestamp)()
7266
+ updatedAt: (0, import_firestore27.serverTimestamp)()
7033
7267
  };
7034
- await (0, import_firestore26.updateDoc)(eventRef, updates);
7035
- 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);
7036
7270
  if (!updatedDoc.exists()) {
7037
7271
  throw new Error("Event not found after update");
7038
7272
  }
7039
7273
  return updatedDoc.data();
7040
7274
  }
7041
7275
  async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
7042
- 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}`));
7043
7277
  if (!clinicDoc.exists()) {
7044
7278
  throw new Error(`Clinic with ID ${clinicId} not found`);
7045
7279
  }
@@ -7048,8 +7282,8 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
7048
7282
  if (!clinicGroupId) {
7049
7283
  return false;
7050
7284
  }
7051
- const clinicGroupDoc = await (0, import_firestore26.getDoc)(
7052
- (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}`)
7053
7287
  );
7054
7288
  if (!clinicGroupDoc.exists()) {
7055
7289
  return false;
@@ -7059,31 +7293,31 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
7059
7293
  }
7060
7294
 
7061
7295
  // src/services/calendar/utils/patient.utils.ts
7062
- var import_firestore27 = require("firebase/firestore");
7296
+ var import_firestore28 = require("firebase/firestore");
7063
7297
  async function createPatientCalendarEventUtil(db, patientId, eventData, generateId2) {
7064
7298
  const eventId = generateId2();
7065
7299
  const eventRef = getPatientCalendarEventDocRef(db, patientId, eventId);
7066
7300
  const newEvent = {
7067
7301
  id: eventId,
7068
7302
  ...eventData,
7069
- createdAt: (0, import_firestore27.serverTimestamp)(),
7070
- updatedAt: (0, import_firestore27.serverTimestamp)()
7303
+ createdAt: (0, import_firestore28.serverTimestamp)(),
7304
+ updatedAt: (0, import_firestore28.serverTimestamp)()
7071
7305
  };
7072
- await (0, import_firestore27.setDoc)(eventRef, newEvent);
7306
+ await (0, import_firestore28.setDoc)(eventRef, newEvent);
7073
7307
  return {
7074
7308
  ...newEvent,
7075
- createdAt: import_firestore27.Timestamp.now(),
7076
- updatedAt: import_firestore27.Timestamp.now()
7309
+ createdAt: import_firestore28.Timestamp.now(),
7310
+ updatedAt: import_firestore28.Timestamp.now()
7077
7311
  };
7078
7312
  }
7079
7313
  async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData) {
7080
7314
  const eventRef = getPatientCalendarEventDocRef(db, patientId, eventId);
7081
7315
  const updates = {
7082
7316
  ...updateData,
7083
- updatedAt: (0, import_firestore27.serverTimestamp)()
7317
+ updatedAt: (0, import_firestore28.serverTimestamp)()
7084
7318
  };
7085
- await (0, import_firestore27.updateDoc)(eventRef, updates);
7086
- 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);
7087
7321
  if (!updatedDoc.exists()) {
7088
7322
  throw new Error("Event not found after update");
7089
7323
  }
@@ -7091,7 +7325,7 @@ async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData
7091
7325
  }
7092
7326
 
7093
7327
  // src/services/calendar/utils/practitioner.utils.ts
7094
- var import_firestore28 = require("firebase/firestore");
7328
+ var import_firestore29 = require("firebase/firestore");
7095
7329
  async function createPractitionerCalendarEventUtil(db, practitionerId, eventData, generateId2) {
7096
7330
  const eventId = generateId2();
7097
7331
  const eventRef = getPractitionerCalendarEventDocRef(
@@ -7102,14 +7336,14 @@ async function createPractitionerCalendarEventUtil(db, practitionerId, eventData
7102
7336
  const newEvent = {
7103
7337
  id: eventId,
7104
7338
  ...eventData,
7105
- createdAt: (0, import_firestore28.serverTimestamp)(),
7106
- updatedAt: (0, import_firestore28.serverTimestamp)()
7339
+ createdAt: (0, import_firestore29.serverTimestamp)(),
7340
+ updatedAt: (0, import_firestore29.serverTimestamp)()
7107
7341
  };
7108
- await (0, import_firestore28.setDoc)(eventRef, newEvent);
7342
+ await (0, import_firestore29.setDoc)(eventRef, newEvent);
7109
7343
  return {
7110
7344
  ...newEvent,
7111
- createdAt: import_firestore28.Timestamp.now(),
7112
- updatedAt: import_firestore28.Timestamp.now()
7345
+ createdAt: import_firestore29.Timestamp.now(),
7346
+ updatedAt: import_firestore29.Timestamp.now()
7113
7347
  };
7114
7348
  }
7115
7349
  async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId, updateData) {
@@ -7120,10 +7354,10 @@ async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId,
7120
7354
  );
7121
7355
  const updates = {
7122
7356
  ...updateData,
7123
- updatedAt: (0, import_firestore28.serverTimestamp)()
7357
+ updatedAt: (0, import_firestore29.serverTimestamp)()
7124
7358
  };
7125
- await (0, import_firestore28.updateDoc)(eventRef, updates);
7126
- 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);
7127
7361
  if (!updatedDoc.exists()) {
7128
7362
  throw new Error("Event not found after update");
7129
7363
  }
@@ -7199,7 +7433,7 @@ async function updateAppointmentUtil(db, clinicId, practitionerId, patientId, ev
7199
7433
  }
7200
7434
 
7201
7435
  // src/services/calendar/utils/synced-calendar.utils.ts
7202
- var import_firestore29 = require("firebase/firestore");
7436
+ var import_firestore30 = require("firebase/firestore");
7203
7437
  async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendarData, generateId2) {
7204
7438
  const calendarId = generateId2();
7205
7439
  const calendarRef = getPractitionerSyncedCalendarDocRef(
@@ -7210,14 +7444,14 @@ async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendar
7210
7444
  const newCalendar = {
7211
7445
  id: calendarId,
7212
7446
  ...calendarData,
7213
- createdAt: (0, import_firestore29.serverTimestamp)(),
7214
- updatedAt: (0, import_firestore29.serverTimestamp)()
7447
+ createdAt: (0, import_firestore30.serverTimestamp)(),
7448
+ updatedAt: (0, import_firestore30.serverTimestamp)()
7215
7449
  };
7216
- await (0, import_firestore29.setDoc)(calendarRef, newCalendar);
7450
+ await (0, import_firestore30.setDoc)(calendarRef, newCalendar);
7217
7451
  return {
7218
7452
  ...newCalendar,
7219
- createdAt: import_firestore29.Timestamp.now(),
7220
- updatedAt: import_firestore29.Timestamp.now()
7453
+ createdAt: import_firestore30.Timestamp.now(),
7454
+ updatedAt: import_firestore30.Timestamp.now()
7221
7455
  };
7222
7456
  }
7223
7457
  async function createPatientSyncedCalendarUtil(db, patientId, calendarData, generateId2) {
@@ -7226,14 +7460,14 @@ async function createPatientSyncedCalendarUtil(db, patientId, calendarData, gene
7226
7460
  const newCalendar = {
7227
7461
  id: calendarId,
7228
7462
  ...calendarData,
7229
- createdAt: (0, import_firestore29.serverTimestamp)(),
7230
- updatedAt: (0, import_firestore29.serverTimestamp)()
7463
+ createdAt: (0, import_firestore30.serverTimestamp)(),
7464
+ updatedAt: (0, import_firestore30.serverTimestamp)()
7231
7465
  };
7232
- await (0, import_firestore29.setDoc)(calendarRef, newCalendar);
7466
+ await (0, import_firestore30.setDoc)(calendarRef, newCalendar);
7233
7467
  return {
7234
7468
  ...newCalendar,
7235
- createdAt: import_firestore29.Timestamp.now(),
7236
- updatedAt: import_firestore29.Timestamp.now()
7469
+ createdAt: import_firestore30.Timestamp.now(),
7470
+ updatedAt: import_firestore30.Timestamp.now()
7237
7471
  };
7238
7472
  }
7239
7473
  async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, generateId2) {
@@ -7242,14 +7476,14 @@ async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, genera
7242
7476
  const newCalendar = {
7243
7477
  id: calendarId,
7244
7478
  ...calendarData,
7245
- createdAt: (0, import_firestore29.serverTimestamp)(),
7246
- updatedAt: (0, import_firestore29.serverTimestamp)()
7479
+ createdAt: (0, import_firestore30.serverTimestamp)(),
7480
+ updatedAt: (0, import_firestore30.serverTimestamp)()
7247
7481
  };
7248
- await (0, import_firestore29.setDoc)(calendarRef, newCalendar);
7482
+ await (0, import_firestore30.setDoc)(calendarRef, newCalendar);
7249
7483
  return {
7250
7484
  ...newCalendar,
7251
- createdAt: import_firestore29.Timestamp.now(),
7252
- updatedAt: import_firestore29.Timestamp.now()
7485
+ createdAt: import_firestore30.Timestamp.now(),
7486
+ updatedAt: import_firestore30.Timestamp.now()
7253
7487
  };
7254
7488
  }
7255
7489
  async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId) {
@@ -7258,54 +7492,54 @@ async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId)
7258
7492
  practitionerId,
7259
7493
  calendarId
7260
7494
  );
7261
- const calendarDoc = await (0, import_firestore29.getDoc)(calendarRef);
7495
+ const calendarDoc = await (0, import_firestore30.getDoc)(calendarRef);
7262
7496
  if (!calendarDoc.exists()) {
7263
7497
  return null;
7264
7498
  }
7265
7499
  return calendarDoc.data();
7266
7500
  }
7267
7501
  async function getPractitionerSyncedCalendarsUtil(db, practitionerId) {
7268
- const calendarsRef = (0, import_firestore29.collection)(
7502
+ const calendarsRef = (0, import_firestore30.collection)(
7269
7503
  db,
7270
7504
  `practitioners/${practitionerId}/${SYNCED_CALENDARS_COLLECTION}`
7271
7505
  );
7272
- const q = (0, import_firestore29.query)(calendarsRef, (0, import_firestore29.orderBy)("createdAt", "desc"));
7273
- const querySnapshot = await (0, import_firestore29.getDocs)(q);
7274
- 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());
7275
7509
  }
7276
7510
  async function getPatientSyncedCalendarUtil(db, patientId, calendarId) {
7277
7511
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
7278
- const calendarDoc = await (0, import_firestore29.getDoc)(calendarRef);
7512
+ const calendarDoc = await (0, import_firestore30.getDoc)(calendarRef);
7279
7513
  if (!calendarDoc.exists()) {
7280
7514
  return null;
7281
7515
  }
7282
7516
  return calendarDoc.data();
7283
7517
  }
7284
7518
  async function getPatientSyncedCalendarsUtil(db, patientId) {
7285
- const calendarsRef = (0, import_firestore29.collection)(
7519
+ const calendarsRef = (0, import_firestore30.collection)(
7286
7520
  db,
7287
7521
  `patients/${patientId}/${SYNCED_CALENDARS_COLLECTION}`
7288
7522
  );
7289
- const q = (0, import_firestore29.query)(calendarsRef, (0, import_firestore29.orderBy)("createdAt", "desc"));
7290
- const querySnapshot = await (0, import_firestore29.getDocs)(q);
7291
- 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());
7292
7526
  }
7293
7527
  async function getClinicSyncedCalendarUtil(db, clinicId, calendarId) {
7294
7528
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
7295
- const calendarDoc = await (0, import_firestore29.getDoc)(calendarRef);
7529
+ const calendarDoc = await (0, import_firestore30.getDoc)(calendarRef);
7296
7530
  if (!calendarDoc.exists()) {
7297
7531
  return null;
7298
7532
  }
7299
7533
  return calendarDoc.data();
7300
7534
  }
7301
7535
  async function getClinicSyncedCalendarsUtil(db, clinicId) {
7302
- const calendarsRef = (0, import_firestore29.collection)(
7536
+ const calendarsRef = (0, import_firestore30.collection)(
7303
7537
  db,
7304
7538
  `clinics/${clinicId}/${SYNCED_CALENDARS_COLLECTION}`
7305
7539
  );
7306
- const q = (0, import_firestore29.query)(calendarsRef, (0, import_firestore29.orderBy)("createdAt", "desc"));
7307
- const querySnapshot = await (0, import_firestore29.getDocs)(q);
7308
- 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());
7309
7543
  }
7310
7544
  async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendarId, updateData) {
7311
7545
  const calendarRef = getPractitionerSyncedCalendarDocRef(
@@ -7315,10 +7549,10 @@ async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendar
7315
7549
  );
7316
7550
  const updates = {
7317
7551
  ...updateData,
7318
- updatedAt: (0, import_firestore29.serverTimestamp)()
7552
+ updatedAt: (0, import_firestore30.serverTimestamp)()
7319
7553
  };
7320
- await (0, import_firestore29.updateDoc)(calendarRef, updates);
7321
- 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);
7322
7556
  if (!updatedDoc.exists()) {
7323
7557
  throw new Error("Synced calendar not found after update");
7324
7558
  }
@@ -7328,10 +7562,10 @@ async function updatePatientSyncedCalendarUtil(db, patientId, calendarId, update
7328
7562
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
7329
7563
  const updates = {
7330
7564
  ...updateData,
7331
- updatedAt: (0, import_firestore29.serverTimestamp)()
7565
+ updatedAt: (0, import_firestore30.serverTimestamp)()
7332
7566
  };
7333
- await (0, import_firestore29.updateDoc)(calendarRef, updates);
7334
- 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);
7335
7569
  if (!updatedDoc.exists()) {
7336
7570
  throw new Error("Synced calendar not found after update");
7337
7571
  }
@@ -7341,10 +7575,10 @@ async function updateClinicSyncedCalendarUtil(db, clinicId, calendarId, updateDa
7341
7575
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
7342
7576
  const updates = {
7343
7577
  ...updateData,
7344
- updatedAt: (0, import_firestore29.serverTimestamp)()
7578
+ updatedAt: (0, import_firestore30.serverTimestamp)()
7345
7579
  };
7346
- await (0, import_firestore29.updateDoc)(calendarRef, updates);
7347
- 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);
7348
7582
  if (!updatedDoc.exists()) {
7349
7583
  throw new Error("Synced calendar not found after update");
7350
7584
  }
@@ -7356,19 +7590,19 @@ async function deletePractitionerSyncedCalendarUtil(db, practitionerId, calendar
7356
7590
  practitionerId,
7357
7591
  calendarId
7358
7592
  );
7359
- await (0, import_firestore29.deleteDoc)(calendarRef);
7593
+ await (0, import_firestore30.deleteDoc)(calendarRef);
7360
7594
  }
7361
7595
  async function deletePatientSyncedCalendarUtil(db, patientId, calendarId) {
7362
7596
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
7363
- await (0, import_firestore29.deleteDoc)(calendarRef);
7597
+ await (0, import_firestore30.deleteDoc)(calendarRef);
7364
7598
  }
7365
7599
  async function deleteClinicSyncedCalendarUtil(db, clinicId, calendarId) {
7366
7600
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
7367
- await (0, import_firestore29.deleteDoc)(calendarRef);
7601
+ await (0, import_firestore30.deleteDoc)(calendarRef);
7368
7602
  }
7369
7603
  async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarId) {
7370
7604
  const updateData = {
7371
- lastSyncedAt: import_firestore29.Timestamp.now()
7605
+ lastSyncedAt: import_firestore30.Timestamp.now()
7372
7606
  };
7373
7607
  switch (entityType) {
7374
7608
  case "practitioner":
@@ -7398,7 +7632,7 @@ async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarI
7398
7632
  }
7399
7633
 
7400
7634
  // src/services/calendar/utils/google-calendar.utils.ts
7401
- var import_firestore30 = require("firebase/firestore");
7635
+ var import_firestore31 = require("firebase/firestore");
7402
7636
  var GOOGLE_CALENDAR_API_URL = "https://www.googleapis.com/calendar/v3";
7403
7637
  var GOOGLE_OAUTH_URL = "https://oauth2.googleapis.com/token";
7404
7638
  var CLIENT_ID = "your-client-id";
@@ -7518,7 +7752,7 @@ async function ensureValidToken(db, entityType, entityId, syncedCalendar) {
7518
7752
  tokenExpiry.setSeconds(tokenExpiry.getSeconds() + expiresIn);
7519
7753
  const updateData = {
7520
7754
  accessToken,
7521
- tokenExpiry: import_firestore30.Timestamp.fromDate(tokenExpiry)
7755
+ tokenExpiry: import_firestore31.Timestamp.fromDate(tokenExpiry)
7522
7756
  };
7523
7757
  switch (entityType) {
7524
7758
  case "practitioner":
@@ -7693,8 +7927,8 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
7693
7927
  eventName: googleEvent.summary || "External Event",
7694
7928
  eventLocation: googleEvent.location,
7695
7929
  eventTime: {
7696
- start: import_firestore30.Timestamp.fromDate(start),
7697
- end: import_firestore30.Timestamp.fromDate(end)
7930
+ start: import_firestore31.Timestamp.fromDate(start),
7931
+ end: import_firestore31.Timestamp.fromDate(end)
7698
7932
  },
7699
7933
  description: googleEvent.description || "",
7700
7934
  // External events are always set as CONFIRMED - status updates will happen externally
@@ -7708,7 +7942,7 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
7708
7942
  {
7709
7943
  eventId: googleEvent.id,
7710
7944
  syncedCalendarProvider: "google" /* GOOGLE */,
7711
- syncedAt: import_firestore30.Timestamp.now()
7945
+ syncedAt: import_firestore31.Timestamp.now()
7712
7946
  }
7713
7947
  ]
7714
7948
  };
@@ -8486,7 +8720,7 @@ var CalendarServiceV2 = class extends BaseService {
8486
8720
  return 0;
8487
8721
  }
8488
8722
  let importedEventsCount = 0;
8489
- const currentTime = import_firestore31.Timestamp.now();
8723
+ const currentTime = import_firestore32.Timestamp.now();
8490
8724
  for (const calendar of activeCalendars) {
8491
8725
  try {
8492
8726
  let externalEvents = [];
@@ -8553,7 +8787,7 @@ var CalendarServiceV2 = class extends BaseService {
8553
8787
  async createDoctorBlockingEvent(doctorId, eventData) {
8554
8788
  try {
8555
8789
  const eventId = this.generateId();
8556
- const eventRef = (0, import_firestore32.doc)(
8790
+ const eventRef = (0, import_firestore33.doc)(
8557
8791
  this.db,
8558
8792
  PRACTITIONERS_COLLECTION,
8559
8793
  doctorId,
@@ -8563,14 +8797,14 @@ var CalendarServiceV2 = class extends BaseService {
8563
8797
  const newEvent = {
8564
8798
  id: eventId,
8565
8799
  ...eventData,
8566
- createdAt: (0, import_firestore31.serverTimestamp)(),
8567
- updatedAt: (0, import_firestore31.serverTimestamp)()
8800
+ createdAt: (0, import_firestore32.serverTimestamp)(),
8801
+ updatedAt: (0, import_firestore32.serverTimestamp)()
8568
8802
  };
8569
- await (0, import_firestore32.setDoc)(eventRef, newEvent);
8803
+ await (0, import_firestore33.setDoc)(eventRef, newEvent);
8570
8804
  return {
8571
8805
  ...newEvent,
8572
- createdAt: import_firestore31.Timestamp.now(),
8573
- updatedAt: import_firestore31.Timestamp.now()
8806
+ createdAt: import_firestore32.Timestamp.now(),
8807
+ updatedAt: import_firestore32.Timestamp.now()
8574
8808
  };
8575
8809
  } catch (error) {
8576
8810
  console.error(
@@ -8588,8 +8822,8 @@ var CalendarServiceV2 = class extends BaseService {
8588
8822
  */
8589
8823
  async synchronizeExternalCalendars(lookbackDays = 7, lookforwardDays = 30) {
8590
8824
  try {
8591
- const practitionersRef = (0, import_firestore32.collection)(this.db, PRACTITIONERS_COLLECTION);
8592
- 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);
8593
8827
  const startDate = /* @__PURE__ */ new Date();
8594
8828
  startDate.setDate(startDate.getDate() - lookbackDays);
8595
8829
  const endDate = /* @__PURE__ */ new Date();
@@ -8647,22 +8881,22 @@ var CalendarServiceV2 = class extends BaseService {
8647
8881
  async updateExistingEventsFromExternalCalendars(doctorId, startDate, endDate) {
8648
8882
  var _a;
8649
8883
  try {
8650
- const eventsRef = (0, import_firestore32.collection)(
8884
+ const eventsRef = (0, import_firestore33.collection)(
8651
8885
  this.db,
8652
8886
  PRACTITIONERS_COLLECTION,
8653
8887
  doctorId,
8654
8888
  CALENDAR_COLLECTION
8655
8889
  );
8656
- const q = (0, import_firestore32.query)(
8890
+ const q = (0, import_firestore33.query)(
8657
8891
  eventsRef,
8658
- (0, import_firestore32.where)("syncStatus", "==", "external" /* EXTERNAL */),
8659
- (0, import_firestore32.where)("eventTime.start", ">=", import_firestore31.Timestamp.fromDate(startDate)),
8660
- (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))
8661
8895
  );
8662
- const eventsSnapshot = await (0, import_firestore32.getDocs)(q);
8663
- const events = eventsSnapshot.docs.map((doc20) => ({
8664
- id: doc20.id,
8665
- ...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()
8666
8900
  }));
8667
8901
  const calendars = await this.syncedCalendarsService.getPractitionerSyncedCalendars(
8668
8902
  doctorId
@@ -8766,21 +9000,21 @@ var CalendarServiceV2 = class extends BaseService {
8766
9000
  const endTime = new Date(
8767
9001
  externalEvent.end.dateTime || externalEvent.end.date
8768
9002
  );
8769
- const eventRef = (0, import_firestore32.doc)(
9003
+ const eventRef = (0, import_firestore33.doc)(
8770
9004
  this.db,
8771
9005
  PRACTITIONERS_COLLECTION,
8772
9006
  doctorId,
8773
9007
  CALENDAR_COLLECTION,
8774
9008
  eventId
8775
9009
  );
8776
- await (0, import_firestore32.updateDoc)(eventRef, {
9010
+ await (0, import_firestore33.updateDoc)(eventRef, {
8777
9011
  eventName: externalEvent.summary || "External Event",
8778
9012
  eventTime: {
8779
- start: import_firestore31.Timestamp.fromDate(startTime),
8780
- end: import_firestore31.Timestamp.fromDate(endTime)
9013
+ start: import_firestore32.Timestamp.fromDate(startTime),
9014
+ end: import_firestore32.Timestamp.fromDate(endTime)
8781
9015
  },
8782
9016
  description: externalEvent.description || "",
8783
- updatedAt: (0, import_firestore31.serverTimestamp)()
9017
+ updatedAt: (0, import_firestore32.serverTimestamp)()
8784
9018
  });
8785
9019
  console.log(`Updated local event ${eventId} from external event`);
8786
9020
  } catch (error) {
@@ -8798,16 +9032,16 @@ var CalendarServiceV2 = class extends BaseService {
8798
9032
  */
8799
9033
  async updateEventStatus(doctorId, eventId, status) {
8800
9034
  try {
8801
- const eventRef = (0, import_firestore32.doc)(
9035
+ const eventRef = (0, import_firestore33.doc)(
8802
9036
  this.db,
8803
9037
  PRACTITIONERS_COLLECTION,
8804
9038
  doctorId,
8805
9039
  CALENDAR_COLLECTION,
8806
9040
  eventId
8807
9041
  );
8808
- await (0, import_firestore32.updateDoc)(eventRef, {
9042
+ await (0, import_firestore33.updateDoc)(eventRef, {
8809
9043
  status,
8810
- updatedAt: (0, import_firestore31.serverTimestamp)()
9044
+ updatedAt: (0, import_firestore32.serverTimestamp)()
8811
9045
  });
8812
9046
  console.log(`Updated event ${eventId} status to ${status}`);
8813
9047
  } catch (error) {
@@ -8868,8 +9102,8 @@ var CalendarServiceV2 = class extends BaseService {
8868
9102
  const startDate = eventTime.start.toDate();
8869
9103
  const startTime = startDate;
8870
9104
  const endTime = eventTime.end.toDate();
8871
- const practitionerRef = (0, import_firestore32.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
8872
- 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);
8873
9107
  if (!practitionerDoc.exists()) {
8874
9108
  throw new Error(`Doctor with ID ${doctorId} not found`);
8875
9109
  }
@@ -8926,8 +9160,8 @@ var CalendarServiceV2 = class extends BaseService {
8926
9160
  * @returns Updated calendar event
8927
9161
  */
8928
9162
  async updateAppointmentStatus(appointmentId, clinicId, status) {
8929
- const appointmentRef = (0, import_firestore32.doc)(this.db, CALENDAR_COLLECTION, appointmentId);
8930
- 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);
8931
9165
  if (!appointmentDoc.exists()) {
8932
9166
  throw new Error(`Appointment with ID ${appointmentId} not found`);
8933
9167
  }
@@ -9058,7 +9292,7 @@ var CalendarServiceV2 = class extends BaseService {
9058
9292
  const newSyncEvent = {
9059
9293
  eventId: result.eventIds[0],
9060
9294
  syncedCalendarProvider: calendar.provider,
9061
- syncedAt: import_firestore31.Timestamp.now()
9295
+ syncedAt: import_firestore32.Timestamp.now()
9062
9296
  };
9063
9297
  await this.updateEventWithSyncId(
9064
9298
  entityType === "doctor" ? appointment.practitionerProfileId : appointment.patientProfileId,
@@ -9082,8 +9316,8 @@ var CalendarServiceV2 = class extends BaseService {
9082
9316
  async updateEventWithSyncId(entityId, entityType, eventId, syncEvent) {
9083
9317
  try {
9084
9318
  const collectionPath = entityType === "doctor" ? `${PRACTITIONERS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}` : `${PATIENTS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
9085
- const eventRef = (0, import_firestore32.doc)(this.db, collectionPath, eventId);
9086
- 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);
9087
9321
  if (eventDoc.exists()) {
9088
9322
  const event = eventDoc.data();
9089
9323
  const syncIds = [...event.syncedCalendarEventId || []];
@@ -9095,9 +9329,9 @@ var CalendarServiceV2 = class extends BaseService {
9095
9329
  } else {
9096
9330
  syncIds.push(syncEvent);
9097
9331
  }
9098
- await (0, import_firestore32.updateDoc)(eventRef, {
9332
+ await (0, import_firestore33.updateDoc)(eventRef, {
9099
9333
  syncedCalendarEventId: syncIds,
9100
- updatedAt: (0, import_firestore31.serverTimestamp)()
9334
+ updatedAt: (0, import_firestore32.serverTimestamp)()
9101
9335
  });
9102
9336
  console.log(
9103
9337
  `Updated event ${eventId} with sync ID ${syncEvent.eventId}`
@@ -9121,8 +9355,8 @@ var CalendarServiceV2 = class extends BaseService {
9121
9355
  * @returns Working hours for the clinic
9122
9356
  */
9123
9357
  async getClinicWorkingHours(clinicId, date) {
9124
- const clinicRef = (0, import_firestore32.doc)(this.db, CLINICS_COLLECTION, clinicId);
9125
- 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);
9126
9360
  if (!clinicDoc.exists()) {
9127
9361
  throw new Error(`Clinic with ID ${clinicId} not found`);
9128
9362
  }
@@ -9150,8 +9384,8 @@ var CalendarServiceV2 = class extends BaseService {
9150
9384
  * @returns Doctor's schedule
9151
9385
  */
9152
9386
  async getDoctorSchedule(doctorId, date) {
9153
- const practitionerRef = (0, import_firestore32.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
9154
- 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);
9155
9389
  if (!practitionerDoc.exists()) {
9156
9390
  throw new Error(`Doctor with ID ${doctorId} not found`);
9157
9391
  }
@@ -9183,19 +9417,19 @@ var CalendarServiceV2 = class extends BaseService {
9183
9417
  startOfDay.setHours(0, 0, 0, 0);
9184
9418
  const endOfDay = new Date(date);
9185
9419
  endOfDay.setHours(23, 59, 59, 999);
9186
- const appointmentsRef = (0, import_firestore32.collection)(this.db, CALENDAR_COLLECTION);
9187
- const q = (0, import_firestore32.query)(
9420
+ const appointmentsRef = (0, import_firestore33.collection)(this.db, CALENDAR_COLLECTION);
9421
+ const q = (0, import_firestore33.query)(
9188
9422
  appointmentsRef,
9189
- (0, import_firestore32.where)("practitionerProfileId", "==", doctorId),
9190
- (0, import_firestore32.where)("eventTime.start", ">=", import_firestore31.Timestamp.fromDate(startOfDay)),
9191
- (0, import_firestore32.where)("eventTime.start", "<=", import_firestore31.Timestamp.fromDate(endOfDay)),
9192
- (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", [
9193
9427
  "confirmed" /* CONFIRMED */,
9194
9428
  "pending" /* PENDING */
9195
9429
  ])
9196
9430
  );
9197
- const querySnapshot = await (0, import_firestore32.getDocs)(q);
9198
- return querySnapshot.docs.map((doc20) => doc20.data());
9431
+ const querySnapshot = await (0, import_firestore33.getDocs)(q);
9432
+ return querySnapshot.docs.map((doc21) => doc21.data());
9199
9433
  }
9200
9434
  /**
9201
9435
  * Calculates available time slots based on working hours, schedule and existing appointments
@@ -9252,11 +9486,11 @@ var CalendarServiceV2 = class extends BaseService {
9252
9486
  var _a;
9253
9487
  try {
9254
9488
  const [clinicDoc, practitionerDoc, patientDoc, patientSensitiveInfoDoc] = await Promise.all([
9255
- (0, import_firestore32.getDoc)((0, import_firestore32.doc)(this.db, CLINICS_COLLECTION, clinicId)),
9256
- (0, import_firestore32.getDoc)((0, import_firestore32.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId)),
9257
- (0, import_firestore32.getDoc)((0, import_firestore32.doc)(this.db, PATIENTS_COLLECTION, patientId)),
9258
- (0, import_firestore32.getDoc)(
9259
- (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)(
9260
9494
  this.db,
9261
9495
  PATIENTS_COLLECTION,
9262
9496
  patientId,
@@ -9289,7 +9523,7 @@ var CalendarServiceV2 = class extends BaseService {
9289
9523
  fullName: `${sensitiveData.firstName} ${sensitiveData.lastName}`,
9290
9524
  email: sensitiveData.email || "",
9291
9525
  phone: sensitiveData.phoneNumber || null,
9292
- dateOfBirth: sensitiveData.dateOfBirth || import_firestore31.Timestamp.now(),
9526
+ dateOfBirth: sensitiveData.dateOfBirth || import_firestore32.Timestamp.now(),
9293
9527
  gender: sensitiveData.gender || "other" /* OTHER */
9294
9528
  };
9295
9529
  } else if (patientDoc.exists()) {
@@ -9298,7 +9532,7 @@ var CalendarServiceV2 = class extends BaseService {
9298
9532
  fullName: patientDoc.data().displayName,
9299
9533
  email: ((_a = patientDoc.data().contactInfo) == null ? void 0 : _a.email) || "",
9300
9534
  phone: patientDoc.data().phoneNumber || null,
9301
- dateOfBirth: patientDoc.data().dateOfBirth || import_firestore31.Timestamp.now(),
9535
+ dateOfBirth: patientDoc.data().dateOfBirth || import_firestore32.Timestamp.now(),
9302
9536
  gender: patientDoc.data().gender || "other" /* OTHER */
9303
9537
  };
9304
9538
  }
@@ -9320,54 +9554,54 @@ var CalendarServiceV2 = class extends BaseService {
9320
9554
  };
9321
9555
 
9322
9556
  // src/validations/notification.schema.ts
9323
- var import_zod18 = require("zod");
9324
- var baseNotificationSchema = import_zod18.z.object({
9325
- id: import_zod18.z.string().optional(),
9326
- userId: import_zod18.z.string(),
9327
- 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(),
9328
9562
  // Timestamp
9329
- notificationType: import_zod18.z.nativeEnum(NotificationType),
9330
- notificationTokens: import_zod18.z.array(import_zod18.z.string()),
9331
- status: import_zod18.z.nativeEnum(NotificationStatus),
9332
- 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(),
9333
9567
  // Timestamp
9334
- updatedAt: import_zod18.z.any().optional(),
9568
+ updatedAt: import_zod19.z.any().optional(),
9335
9569
  // Timestamp
9336
- title: import_zod18.z.string(),
9337
- body: import_zod18.z.string(),
9338
- isRead: import_zod18.z.boolean(),
9339
- 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)
9340
9574
  });
9341
9575
  var preRequirementNotificationSchema = baseNotificationSchema.extend({
9342
- notificationType: import_zod18.z.literal("preRequirement" /* PRE_REQUIREMENT */),
9343
- treatmentId: import_zod18.z.string(),
9344
- requirements: import_zod18.z.array(import_zod18.z.string()),
9345
- 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()
9346
9580
  // Timestamp
9347
9581
  });
9348
9582
  var postRequirementNotificationSchema = baseNotificationSchema.extend({
9349
- notificationType: import_zod18.z.literal("postRequirement" /* POST_REQUIREMENT */),
9350
- treatmentId: import_zod18.z.string(),
9351
- requirements: import_zod18.z.array(import_zod18.z.string()),
9352
- 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()
9353
9587
  // Timestamp
9354
9588
  });
9355
9589
  var appointmentReminderNotificationSchema = baseNotificationSchema.extend({
9356
- notificationType: import_zod18.z.literal("appointmentReminder" /* APPOINTMENT_REMINDER */),
9357
- appointmentId: import_zod18.z.string(),
9358
- 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(),
9359
9593
  // Timestamp
9360
- treatmentType: import_zod18.z.string(),
9361
- doctorName: import_zod18.z.string()
9594
+ treatmentType: import_zod19.z.string(),
9595
+ doctorName: import_zod19.z.string()
9362
9596
  });
9363
9597
  var appointmentNotificationSchema = baseNotificationSchema.extend({
9364
- notificationType: import_zod18.z.literal("appointmentNotification" /* APPOINTMENT_NOTIFICATION */),
9365
- appointmentId: import_zod18.z.string(),
9366
- appointmentStatus: import_zod18.z.string(),
9367
- previousStatus: import_zod18.z.string(),
9368
- 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()
9369
9603
  });
9370
- var notificationSchema = import_zod18.z.discriminatedUnion("notificationType", [
9604
+ var notificationSchema = import_zod19.z.discriminatedUnion("notificationType", [
9371
9605
  preRequirementNotificationSchema,
9372
9606
  postRequirementNotificationSchema,
9373
9607
  appointmentReminderNotificationSchema,
@@ -9430,6 +9664,7 @@ var notificationSchema = import_zod18.z.discriminatedUnion("notificationType", [
9430
9664
  PractitionerTokenStatus,
9431
9665
  PricingMeasure,
9432
9666
  ProcedureFamily,
9667
+ ProcedureService,
9433
9668
  REGISTER_TOKENS_COLLECTION,
9434
9669
  SYNCED_CALENDARS_COLLECTION,
9435
9670
  SubscriptionModel,