@blackcode_sa/metaestetics-api 1.5.16 → 1.5.17

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.mjs CHANGED
@@ -57,9 +57,9 @@ import {
57
57
  confirmPasswordReset
58
58
  } from "firebase/auth";
59
59
  import {
60
- collection as collection9,
61
- query as query8,
62
- getDocs as getDocs8
60
+ collection as collection10,
61
+ query as query9,
62
+ getDocs as getDocs9
63
63
  } from "firebase/firestore";
64
64
 
65
65
  // src/types/documentation-templates/index.ts
@@ -111,27 +111,27 @@ var FilledDocumentStatus = /* @__PURE__ */ ((FilledDocumentStatus2) => {
111
111
  })(FilledDocumentStatus || {});
112
112
 
113
113
  // src/types/calendar/index.ts
114
- var CalendarEventStatus = /* @__PURE__ */ ((CalendarEventStatus3) => {
115
- CalendarEventStatus3["PENDING"] = "pending";
116
- CalendarEventStatus3["CONFIRMED"] = "confirmed";
117
- CalendarEventStatus3["REJECTED"] = "rejected";
118
- CalendarEventStatus3["CANCELED"] = "canceled";
119
- CalendarEventStatus3["RESCHEDULED"] = "rescheduled";
120
- CalendarEventStatus3["COMPLETED"] = "completed";
121
- return CalendarEventStatus3;
114
+ var CalendarEventStatus = /* @__PURE__ */ ((CalendarEventStatus4) => {
115
+ CalendarEventStatus4["PENDING"] = "pending";
116
+ CalendarEventStatus4["CONFIRMED"] = "confirmed";
117
+ CalendarEventStatus4["REJECTED"] = "rejected";
118
+ CalendarEventStatus4["CANCELED"] = "canceled";
119
+ CalendarEventStatus4["RESCHEDULED"] = "rescheduled";
120
+ CalendarEventStatus4["COMPLETED"] = "completed";
121
+ return CalendarEventStatus4;
122
122
  })(CalendarEventStatus || {});
123
- var CalendarSyncStatus = /* @__PURE__ */ ((CalendarSyncStatus3) => {
124
- CalendarSyncStatus3["INTERNAL"] = "internal";
125
- CalendarSyncStatus3["EXTERNAL"] = "external";
126
- return CalendarSyncStatus3;
123
+ var CalendarSyncStatus = /* @__PURE__ */ ((CalendarSyncStatus4) => {
124
+ CalendarSyncStatus4["INTERNAL"] = "internal";
125
+ CalendarSyncStatus4["EXTERNAL"] = "external";
126
+ return CalendarSyncStatus4;
127
127
  })(CalendarSyncStatus || {});
128
- var CalendarEventType = /* @__PURE__ */ ((CalendarEventType2) => {
129
- CalendarEventType2["APPOINTMENT"] = "appointment";
130
- CalendarEventType2["BLOCKING"] = "blocking";
131
- CalendarEventType2["BREAK"] = "break";
132
- CalendarEventType2["FREE_DAY"] = "free_day";
133
- CalendarEventType2["OTHER"] = "other";
134
- return CalendarEventType2;
128
+ var CalendarEventType = /* @__PURE__ */ ((CalendarEventType3) => {
129
+ CalendarEventType3["APPOINTMENT"] = "appointment";
130
+ CalendarEventType3["BLOCKING"] = "blocking";
131
+ CalendarEventType3["BREAK"] = "break";
132
+ CalendarEventType3["FREE_DAY"] = "free_day";
133
+ CalendarEventType3["OTHER"] = "other";
134
+ return CalendarEventType3;
135
135
  })(CalendarEventType || {});
136
136
  var CALENDAR_COLLECTION = "calendar";
137
137
 
@@ -577,12 +577,12 @@ var BaseService = class {
577
577
 
578
578
  // src/services/user.service.ts
579
579
  import {
580
- collection as collection4,
580
+ collection as collection5,
581
581
  doc as doc6,
582
582
  getDoc as getDoc10,
583
- getDocs as getDocs4,
584
- query as query4,
585
- where as where4,
583
+ getDocs as getDocs5,
584
+ query as query5,
585
+ where as where5,
586
586
  updateDoc as updateDoc9,
587
587
  deleteDoc as deleteDoc3,
588
588
  Timestamp as Timestamp9,
@@ -701,7 +701,11 @@ import {
701
701
  arrayRemove as arrayRemove2,
702
702
  serverTimestamp as serverTimestamp4,
703
703
  increment,
704
- Timestamp as Timestamp3
704
+ Timestamp as Timestamp3,
705
+ collection as collection2,
706
+ query as query2,
707
+ where as where2,
708
+ getDocs as getDocs2
705
709
  } from "firebase/firestore";
706
710
  import {
707
711
  ref,
@@ -999,6 +1003,8 @@ var patientProfileSchema = z5.object({
999
1003
  isVerified: z5.boolean(),
1000
1004
  doctors: z5.array(patientDoctorSchema),
1001
1005
  clinics: z5.array(patientClinicSchema),
1006
+ doctorIds: z5.array(z5.string()),
1007
+ clinicIds: z5.array(z5.string()),
1002
1008
  createdAt: z5.instanceof(Timestamp),
1003
1009
  updatedAt: z5.instanceof(Timestamp)
1004
1010
  });
@@ -1011,7 +1017,9 @@ var createPatientProfileSchema = z5.object({
1011
1017
  isActive: z5.boolean(),
1012
1018
  isVerified: z5.boolean(),
1013
1019
  doctors: z5.array(patientDoctorSchema).optional(),
1014
- clinics: z5.array(patientClinicSchema).optional()
1020
+ clinics: z5.array(patientClinicSchema).optional(),
1021
+ doctorIds: z5.array(z5.string()).optional(),
1022
+ clinicIds: z5.array(z5.string()).optional()
1015
1023
  });
1016
1024
  var createPatientSensitiveInfoSchema = z5.object({
1017
1025
  patientId: z5.string(),
@@ -1027,6 +1035,33 @@ var createPatientSensitiveInfoSchema = z5.object({
1027
1035
  addressData: addressDataSchema.optional(),
1028
1036
  emergencyContacts: z5.array(emergencyContactSchema).optional()
1029
1037
  });
1038
+ var searchPatientsSchema = z5.object({
1039
+ clinicId: z5.string().optional(),
1040
+ practitionerId: z5.string().optional()
1041
+ }).refine((data) => data.clinicId || data.practitionerId, {
1042
+ message: "At least one of clinicId or practitionerId must be provided",
1043
+ path: []
1044
+ // Optional: specify a path like ['clinicId'] or ['practitionerId']
1045
+ });
1046
+ var requesterInfoSchema = z5.object({
1047
+ id: z5.string(),
1048
+ role: z5.enum(["clinic_admin", "practitioner"]),
1049
+ associatedClinicId: z5.string().optional(),
1050
+ associatedPractitionerId: z5.string().optional()
1051
+ }).refine(
1052
+ (data) => {
1053
+ if (data.role === "clinic_admin") {
1054
+ return !!data.associatedClinicId;
1055
+ } else if (data.role === "practitioner") {
1056
+ return !!data.associatedPractitionerId;
1057
+ }
1058
+ return false;
1059
+ },
1060
+ {
1061
+ message: "Associated ID (clinic or practitioner) is required based on role",
1062
+ path: ["associatedClinicId", "associatedPractitionerId"]
1063
+ }
1064
+ );
1030
1065
 
1031
1066
  // src/services/patient/utils/docs.utils.ts
1032
1067
  import {
@@ -1310,9 +1345,9 @@ var addAllergyUtil = async (db, patientId, data, userRef) => {
1310
1345
  var updateAllergyUtil = async (db, patientId, data, userRef) => {
1311
1346
  const validatedData = updateAllergySchema.parse(data);
1312
1347
  const { allergyIndex, ...updateData } = validatedData;
1313
- const doc26 = await getDoc3(getMedicalInfoDocRef(db, patientId));
1314
- if (!doc26.exists()) throw new Error("Medical info not found");
1315
- const medicalInfo = doc26.data();
1348
+ const doc27 = await getDoc3(getMedicalInfoDocRef(db, patientId));
1349
+ if (!doc27.exists()) throw new Error("Medical info not found");
1350
+ const medicalInfo = doc27.data();
1316
1351
  if (allergyIndex >= medicalInfo.allergies.length) {
1317
1352
  throw new Error("Invalid allergy index");
1318
1353
  }
@@ -1328,9 +1363,9 @@ var updateAllergyUtil = async (db, patientId, data, userRef) => {
1328
1363
  });
1329
1364
  };
1330
1365
  var removeAllergyUtil = async (db, patientId, allergyIndex, userRef) => {
1331
- const doc26 = await getDoc3(getMedicalInfoDocRef(db, patientId));
1332
- if (!doc26.exists()) throw new Error("Medical info not found");
1333
- const medicalInfo = doc26.data();
1366
+ const doc27 = await getDoc3(getMedicalInfoDocRef(db, patientId));
1367
+ if (!doc27.exists()) throw new Error("Medical info not found");
1368
+ const medicalInfo = doc27.data();
1334
1369
  if (allergyIndex >= medicalInfo.allergies.length) {
1335
1370
  throw new Error("Invalid allergy index");
1336
1371
  }
@@ -1355,9 +1390,9 @@ var addBlockingConditionUtil = async (db, patientId, data, userRef) => {
1355
1390
  var updateBlockingConditionUtil = async (db, patientId, data, userRef) => {
1356
1391
  const validatedData = updateBlockingConditionSchema.parse(data);
1357
1392
  const { conditionIndex, ...updateData } = validatedData;
1358
- const doc26 = await getDoc3(getMedicalInfoDocRef(db, patientId));
1359
- if (!doc26.exists()) throw new Error("Medical info not found");
1360
- const medicalInfo = doc26.data();
1393
+ const doc27 = await getDoc3(getMedicalInfoDocRef(db, patientId));
1394
+ if (!doc27.exists()) throw new Error("Medical info not found");
1395
+ const medicalInfo = doc27.data();
1361
1396
  if (conditionIndex >= medicalInfo.blockingConditions.length) {
1362
1397
  throw new Error("Invalid blocking condition index");
1363
1398
  }
@@ -1373,9 +1408,9 @@ var updateBlockingConditionUtil = async (db, patientId, data, userRef) => {
1373
1408
  });
1374
1409
  };
1375
1410
  var removeBlockingConditionUtil = async (db, patientId, conditionIndex, userRef) => {
1376
- const doc26 = await getDoc3(getMedicalInfoDocRef(db, patientId));
1377
- if (!doc26.exists()) throw new Error("Medical info not found");
1378
- const medicalInfo = doc26.data();
1411
+ const doc27 = await getDoc3(getMedicalInfoDocRef(db, patientId));
1412
+ if (!doc27.exists()) throw new Error("Medical info not found");
1413
+ const medicalInfo = doc27.data();
1379
1414
  if (conditionIndex >= medicalInfo.blockingConditions.length) {
1380
1415
  throw new Error("Invalid blocking condition index");
1381
1416
  }
@@ -1400,9 +1435,9 @@ var addContraindicationUtil = async (db, patientId, data, userRef) => {
1400
1435
  var updateContraindicationUtil = async (db, patientId, data, userRef) => {
1401
1436
  const validatedData = updateContraindicationSchema.parse(data);
1402
1437
  const { contraindicationIndex, ...updateData } = validatedData;
1403
- const doc26 = await getDoc3(getMedicalInfoDocRef(db, patientId));
1404
- if (!doc26.exists()) throw new Error("Medical info not found");
1405
- const medicalInfo = doc26.data();
1438
+ const doc27 = await getDoc3(getMedicalInfoDocRef(db, patientId));
1439
+ if (!doc27.exists()) throw new Error("Medical info not found");
1440
+ const medicalInfo = doc27.data();
1406
1441
  if (contraindicationIndex >= medicalInfo.contraindications.length) {
1407
1442
  throw new Error("Invalid contraindication index");
1408
1443
  }
@@ -1418,9 +1453,9 @@ var updateContraindicationUtil = async (db, patientId, data, userRef) => {
1418
1453
  });
1419
1454
  };
1420
1455
  var removeContraindicationUtil = async (db, patientId, contraindicationIndex, userRef) => {
1421
- const doc26 = await getDoc3(getMedicalInfoDocRef(db, patientId));
1422
- if (!doc26.exists()) throw new Error("Medical info not found");
1423
- const medicalInfo = doc26.data();
1456
+ const doc27 = await getDoc3(getMedicalInfoDocRef(db, patientId));
1457
+ if (!doc27.exists()) throw new Error("Medical info not found");
1458
+ const medicalInfo = doc27.data();
1424
1459
  if (contraindicationIndex >= medicalInfo.contraindications.length) {
1425
1460
  throw new Error("Invalid contraindication index");
1426
1461
  }
@@ -1445,9 +1480,9 @@ var addMedicationUtil = async (db, patientId, data, userRef) => {
1445
1480
  var updateMedicationUtil = async (db, patientId, data, userRef) => {
1446
1481
  const validatedData = updateMedicationSchema.parse(data);
1447
1482
  const { medicationIndex, ...updateData } = validatedData;
1448
- const doc26 = await getDoc3(getMedicalInfoDocRef(db, patientId));
1449
- if (!doc26.exists()) throw new Error("Medical info not found");
1450
- const medicalInfo = doc26.data();
1483
+ const doc27 = await getDoc3(getMedicalInfoDocRef(db, patientId));
1484
+ if (!doc27.exists()) throw new Error("Medical info not found");
1485
+ const medicalInfo = doc27.data();
1451
1486
  if (medicationIndex >= medicalInfo.currentMedications.length) {
1452
1487
  throw new Error("Invalid medication index");
1453
1488
  }
@@ -1463,9 +1498,9 @@ var updateMedicationUtil = async (db, patientId, data, userRef) => {
1463
1498
  });
1464
1499
  };
1465
1500
  var removeMedicationUtil = async (db, patientId, medicationIndex, userRef) => {
1466
- const doc26 = await getDoc3(getMedicalInfoDocRef(db, patientId));
1467
- if (!doc26.exists()) throw new Error("Medical info not found");
1468
- const medicalInfo = doc26.data();
1501
+ const doc27 = await getDoc3(getMedicalInfoDocRef(db, patientId));
1502
+ if (!doc27.exists()) throw new Error("Medical info not found");
1503
+ const medicalInfo = doc27.data();
1469
1504
  if (medicationIndex >= medicalInfo.currentMedications.length) {
1470
1505
  throw new Error("Invalid medication index");
1471
1506
  }
@@ -1481,6 +1516,7 @@ var removeMedicationUtil = async (db, patientId, medicationIndex, userRef) => {
1481
1516
 
1482
1517
  // src/services/patient/utils/profile.utils.ts
1483
1518
  var createPatientProfileUtil = async (db, data, generateId2) => {
1519
+ var _a, _b;
1484
1520
  try {
1485
1521
  console.log("[createPatientProfileUtil] Starting patient profile creation");
1486
1522
  const validatedData = createPatientProfileSchema.parse(data);
@@ -1500,6 +1536,8 @@ var createPatientProfileUtil = async (db, data, generateId2) => {
1500
1536
  isVerified: validatedData.isVerified,
1501
1537
  doctors: validatedData.doctors || [],
1502
1538
  clinics: validatedData.clinics || [],
1539
+ doctorIds: ((_a = validatedData.doctors) == null ? void 0 : _a.map((d) => d.userRef)) || [],
1540
+ clinicIds: ((_b = validatedData.clinics) == null ? void 0 : _b.map((c) => c.clinicId)) || [],
1503
1541
  createdAt: serverTimestamp4(),
1504
1542
  updatedAt: serverTimestamp4()
1505
1543
  };
@@ -1733,6 +1771,67 @@ var testCreateSubDocuments = async (db, patientId, userRef) => {
1733
1771
  throw error;
1734
1772
  }
1735
1773
  };
1774
+ var searchPatientsUtil = async (db, params, requester) => {
1775
+ searchPatientsSchema.parse(params);
1776
+ requesterInfoSchema.parse(requester);
1777
+ const constraints = [];
1778
+ const patientsCollectionRef = collection2(db, PATIENTS_COLLECTION);
1779
+ if (requester.role === "clinic_admin") {
1780
+ if (!requester.associatedClinicId) {
1781
+ throw new Error(
1782
+ "Associated clinic ID is required for clinic admin search."
1783
+ );
1784
+ }
1785
+ if (params.clinicId && params.clinicId !== requester.associatedClinicId) {
1786
+ console.warn(
1787
+ `Clinic admin (${requester.id}) attempted to search outside their associated clinic (${requester.associatedClinicId})`
1788
+ );
1789
+ return [];
1790
+ }
1791
+ constraints.push(
1792
+ where2("clinicIds", "array-contains", requester.associatedClinicId)
1793
+ );
1794
+ if (params.practitionerId) {
1795
+ constraints.push(
1796
+ where2("doctorIds", "array-contains", params.practitionerId)
1797
+ );
1798
+ }
1799
+ } else if (requester.role === "practitioner") {
1800
+ if (!requester.associatedPractitionerId) {
1801
+ throw new Error(
1802
+ "Associated practitioner ID is required for practitioner search."
1803
+ );
1804
+ }
1805
+ if (params.practitionerId && params.practitionerId !== requester.associatedPractitionerId) {
1806
+ console.warn(
1807
+ `Practitioner (${requester.id}) attempted to search for patients of another practitioner (${params.practitionerId})`
1808
+ );
1809
+ return [];
1810
+ }
1811
+ constraints.push(
1812
+ where2("doctorIds", "array-contains", requester.associatedPractitionerId)
1813
+ );
1814
+ if (params.clinicId) {
1815
+ constraints.push(where2("clinicIds", "array-contains", params.clinicId));
1816
+ }
1817
+ } else {
1818
+ throw new Error("Invalid requester role.");
1819
+ }
1820
+ try {
1821
+ const finalQuery = query2(patientsCollectionRef, ...constraints);
1822
+ const querySnapshot = await getDocs2(finalQuery);
1823
+ const patients = querySnapshot.docs.map(
1824
+ (doc27) => doc27.data()
1825
+ );
1826
+ console.log(
1827
+ `[searchPatientsUtil] Found ${patients.length} patients matching criteria.`
1828
+ );
1829
+ return patients;
1830
+ } catch (error) {
1831
+ console.error("[searchPatientsUtil] Error searching patients:", error);
1832
+ return [];
1833
+ }
1834
+ };
1736
1835
 
1737
1836
  // src/services/patient/utils/location.utils.ts
1738
1837
  import {
@@ -1821,54 +1920,101 @@ import {
1821
1920
  getDoc as getDoc6,
1822
1921
  updateDoc as updateDoc5,
1823
1922
  arrayUnion as arrayUnion3,
1923
+ arrayRemove as arrayRemove3,
1824
1924
  serverTimestamp as serverTimestamp6,
1825
1925
  Timestamp as Timestamp4
1826
1926
  } from "firebase/firestore";
1827
1927
  var addDoctorUtil = async (db, patientId, doctorRef, assignedBy) => {
1928
+ var _a;
1828
1929
  const newDoctor = {
1829
1930
  userRef: doctorRef,
1830
1931
  assignedAt: Timestamp4.now(),
1831
1932
  assignedBy,
1832
1933
  isActive: true
1833
1934
  };
1834
- await updateDoc5(getPatientDocRef(db, patientId), {
1835
- doctors: arrayUnion3(newDoctor),
1836
- updatedAt: serverTimestamp6()
1837
- });
1838
- };
1839
- var removeDoctorUtil = async (db, patientId, doctorRef) => {
1840
1935
  const patientDoc = await getDoc6(getPatientDocRef(db, patientId));
1841
1936
  if (!patientDoc.exists()) throw new Error("Patient profile not found");
1842
1937
  const patientData = patientDoc.data();
1843
- const updatedDoctors = patientData.doctors.map(
1844
- (doctor) => doctor.userRef === doctorRef ? { ...doctor, isActive: false } : doctor
1938
+ const existingDoctorIndex = (_a = patientData.doctors) == null ? void 0 : _a.findIndex(
1939
+ (d) => d.userRef === doctorRef
1845
1940
  );
1846
- await updateDoc5(getPatientDocRef(db, patientId), {
1941
+ const updates = {
1942
+ updatedAt: serverTimestamp6(),
1943
+ doctorIds: arrayUnion3(doctorRef)
1944
+ };
1945
+ if (existingDoctorIndex !== void 0 && existingDoctorIndex > -1) {
1946
+ const updatedDoctors = [...patientData.doctors];
1947
+ updatedDoctors[existingDoctorIndex] = {
1948
+ ...updatedDoctors[existingDoctorIndex],
1949
+ isActive: true,
1950
+ assignedAt: Timestamp4.now(),
1951
+ assignedBy
1952
+ };
1953
+ updates.doctors = updatedDoctors;
1954
+ } else {
1955
+ updates.doctors = arrayUnion3(newDoctor);
1956
+ }
1957
+ await updateDoc5(getPatientDocRef(db, patientId), updates);
1958
+ };
1959
+ var removeDoctorUtil = async (db, patientId, doctorRef) => {
1960
+ var _a;
1961
+ const patientDocRef = getPatientDocRef(db, patientId);
1962
+ const patientDoc = await getDoc6(patientDocRef);
1963
+ if (!patientDoc.exists()) throw new Error("Patient profile not found");
1964
+ const patientData = patientDoc.data();
1965
+ const updatedDoctors = ((_a = patientData.doctors) == null ? void 0 : _a.filter((doctor) => doctor.userRef !== doctorRef)) || [];
1966
+ await updateDoc5(patientDocRef, {
1847
1967
  doctors: updatedDoctors,
1968
+ // Set the filtered array
1969
+ doctorIds: arrayRemove3(doctorRef),
1970
+ // Remove ID from the denormalized list
1848
1971
  updatedAt: serverTimestamp6()
1849
1972
  });
1850
1973
  };
1851
1974
  var addClinicUtil = async (db, patientId, clinicId, assignedBy) => {
1975
+ var _a;
1852
1976
  const newClinic = {
1853
1977
  clinicId,
1854
1978
  assignedAt: Timestamp4.now(),
1855
1979
  assignedBy,
1856
1980
  isActive: true
1857
1981
  };
1858
- await updateDoc5(getPatientDocRef(db, patientId), {
1859
- clinics: arrayUnion3(newClinic),
1860
- updatedAt: serverTimestamp6()
1861
- });
1862
- };
1863
- var removeClinicUtil = async (db, patientId, clinicId) => {
1864
1982
  const patientDoc = await getDoc6(getPatientDocRef(db, patientId));
1865
1983
  if (!patientDoc.exists()) throw new Error("Patient profile not found");
1866
1984
  const patientData = patientDoc.data();
1867
- const updatedClinics = patientData.clinics.map(
1868
- (clinic) => clinic.clinicId === clinicId ? { ...clinic, isActive: false } : clinic
1985
+ const existingClinicIndex = (_a = patientData.clinics) == null ? void 0 : _a.findIndex(
1986
+ (c) => c.clinicId === clinicId
1869
1987
  );
1870
- await updateDoc5(getPatientDocRef(db, patientId), {
1988
+ const updates = {
1989
+ updatedAt: serverTimestamp6(),
1990
+ clinicIds: arrayUnion3(clinicId)
1991
+ };
1992
+ if (existingClinicIndex !== void 0 && existingClinicIndex > -1) {
1993
+ const updatedClinics = [...patientData.clinics];
1994
+ updatedClinics[existingClinicIndex] = {
1995
+ ...updatedClinics[existingClinicIndex],
1996
+ isActive: true,
1997
+ assignedAt: Timestamp4.now(),
1998
+ assignedBy
1999
+ };
2000
+ updates.clinics = updatedClinics;
2001
+ } else {
2002
+ updates.clinics = arrayUnion3(newClinic);
2003
+ }
2004
+ await updateDoc5(getPatientDocRef(db, patientId), updates);
2005
+ };
2006
+ var removeClinicUtil = async (db, patientId, clinicId) => {
2007
+ var _a;
2008
+ const patientDocRef = getPatientDocRef(db, patientId);
2009
+ const patientDoc = await getDoc6(patientDocRef);
2010
+ if (!patientDoc.exists()) throw new Error("Patient profile not found");
2011
+ const patientData = patientDoc.data();
2012
+ const updatedClinics = ((_a = patientData.clinics) == null ? void 0 : _a.filter((clinic) => clinic.clinicId !== clinicId)) || [];
2013
+ await updateDoc5(patientDocRef, {
1871
2014
  clinics: updatedClinics,
2015
+ // Set the filtered array
2016
+ clinicIds: arrayRemove3(clinicId),
2017
+ // Remove ID from the denormalized list
1872
2018
  updatedAt: serverTimestamp6()
1873
2019
  });
1874
2020
  };
@@ -2109,16 +2255,33 @@ var PatientService = class extends BaseService {
2109
2255
  async updatePatientProfileByUserRef(userRef, data) {
2110
2256
  return updatePatientProfileByUserRefUtil(this.db, userRef, data);
2111
2257
  }
2258
+ /**
2259
+ * Searches for patient profiles based on clinic/practitioner association.
2260
+ * Requires information about the requester for security checks.
2261
+ *
2262
+ * @param {SearchPatientsParams} params - The search criteria (clinicId, practitionerId).
2263
+ * @param {RequesterInfo} requester - Information about the user performing the search (ID, role, associated IDs).
2264
+ * @returns {Promise<PatientProfile[]>} A promise resolving to an array of matching patient profiles.
2265
+ */
2266
+ async searchPatients(params, requester) {
2267
+ console.log(
2268
+ `[PatientService.searchPatients] Initiating search with params:`,
2269
+ params,
2270
+ `by requester:`,
2271
+ requester
2272
+ );
2273
+ return searchPatientsUtil(this.db, params, requester);
2274
+ }
2112
2275
  };
2113
2276
 
2114
2277
  // src/services/clinic/utils/admin.utils.ts
2115
2278
  import {
2116
- collection as collection2,
2279
+ collection as collection3,
2117
2280
  doc as doc4,
2118
2281
  getDoc as getDoc8,
2119
- getDocs as getDocs2,
2120
- query as query2,
2121
- where as where2,
2282
+ getDocs as getDocs3,
2283
+ query as query3,
2284
+ where as where3,
2122
2285
  updateDoc as updateDoc7,
2123
2286
  setDoc as setDoc6,
2124
2287
  deleteDoc,
@@ -2676,7 +2839,7 @@ async function createClinicAdmin(db, data, clinicGroupService) {
2676
2839
  }
2677
2840
  console.log("[CLINIC_ADMIN] Preparing admin data object");
2678
2841
  const adminData = {
2679
- id: doc4(collection2(db, CLINIC_ADMINS_COLLECTION)).id,
2842
+ id: doc4(collection3(db, CLINIC_ADMINS_COLLECTION)).id,
2680
2843
  // Generate a new ID for the admin document
2681
2844
  userRef: validatedData.userRef,
2682
2845
  clinicGroupId: clinicGroupId || "",
@@ -2768,23 +2931,23 @@ async function getClinicAdmin(db, adminId) {
2768
2931
  return null;
2769
2932
  }
2770
2933
  async function getClinicAdminByUserRef(db, userRef) {
2771
- const q = query2(
2772
- collection2(db, CLINIC_ADMINS_COLLECTION),
2773
- where2("userRef", "==", userRef)
2934
+ const q = query3(
2935
+ collection3(db, CLINIC_ADMINS_COLLECTION),
2936
+ where3("userRef", "==", userRef)
2774
2937
  );
2775
- const querySnapshot = await getDocs2(q);
2938
+ const querySnapshot = await getDocs3(q);
2776
2939
  if (querySnapshot.empty) {
2777
2940
  return null;
2778
2941
  }
2779
2942
  return querySnapshot.docs[0].data();
2780
2943
  }
2781
2944
  async function getClinicAdminsByGroup(db, clinicGroupId) {
2782
- const q = query2(
2783
- collection2(db, CLINIC_ADMINS_COLLECTION),
2784
- where2("clinicGroupId", "==", clinicGroupId)
2945
+ const q = query3(
2946
+ collection3(db, CLINIC_ADMINS_COLLECTION),
2947
+ where3("clinicGroupId", "==", clinicGroupId)
2785
2948
  );
2786
- const querySnapshot = await getDocs2(q);
2787
- return querySnapshot.docs.map((doc26) => doc26.data());
2949
+ const querySnapshot = await getDocs3(q);
2950
+ return querySnapshot.docs.map((doc27) => doc27.data());
2788
2951
  }
2789
2952
  async function updateClinicAdmin(db, adminId, data) {
2790
2953
  const admin = await getClinicAdmin(db, adminId);
@@ -3049,12 +3212,12 @@ var ClinicAdminService = class extends BaseService {
3049
3212
 
3050
3213
  // src/services/practitioner/practitioner.service.ts
3051
3214
  import {
3052
- collection as collection3,
3215
+ collection as collection4,
3053
3216
  doc as doc5,
3054
3217
  getDoc as getDoc9,
3055
- getDocs as getDocs3,
3056
- query as query3,
3057
- where as where3,
3218
+ getDocs as getDocs4,
3219
+ query as query4,
3220
+ where as where4,
3058
3221
  updateDoc as updateDoc8,
3059
3222
  setDoc as setDoc7,
3060
3223
  deleteDoc as deleteDoc2,
@@ -3441,17 +3604,17 @@ var PractitionerService = class extends BaseService {
3441
3604
  * @returns Array of active tokens
3442
3605
  */
3443
3606
  async getPractitionerActiveTokens(practitionerId) {
3444
- const tokensRef = collection3(
3607
+ const tokensRef = collection4(
3445
3608
  this.db,
3446
3609
  `${PRACTITIONERS_COLLECTION}/${practitionerId}/${REGISTER_TOKENS_COLLECTION}`
3447
3610
  );
3448
- const q = query3(
3611
+ const q = query4(
3449
3612
  tokensRef,
3450
- where3("status", "==", "active" /* ACTIVE */),
3451
- where3("expiresAt", ">", Timestamp8.now())
3613
+ where4("status", "==", "active" /* ACTIVE */),
3614
+ where4("expiresAt", ">", Timestamp8.now())
3452
3615
  );
3453
- const querySnapshot = await getDocs3(q);
3454
- return querySnapshot.docs.map((doc26) => doc26.data());
3616
+ const querySnapshot = await getDocs4(q);
3617
+ return querySnapshot.docs.map((doc27) => doc27.data());
3455
3618
  }
3456
3619
  /**
3457
3620
  * Gets a token by its string value and validates it
@@ -3459,21 +3622,21 @@ var PractitionerService = class extends BaseService {
3459
3622
  * @returns The token if found and valid, null otherwise
3460
3623
  */
3461
3624
  async validateToken(tokenString) {
3462
- const practitionersRef = collection3(this.db, PRACTITIONERS_COLLECTION);
3463
- const practitionersSnapshot = await getDocs3(practitionersRef);
3625
+ const practitionersRef = collection4(this.db, PRACTITIONERS_COLLECTION);
3626
+ const practitionersSnapshot = await getDocs4(practitionersRef);
3464
3627
  for (const practitionerDoc of practitionersSnapshot.docs) {
3465
3628
  const practitionerId = practitionerDoc.id;
3466
- const tokensRef = collection3(
3629
+ const tokensRef = collection4(
3467
3630
  this.db,
3468
3631
  `${PRACTITIONERS_COLLECTION}/${practitionerId}/${REGISTER_TOKENS_COLLECTION}`
3469
3632
  );
3470
- const q = query3(
3633
+ const q = query4(
3471
3634
  tokensRef,
3472
- where3("token", "==", tokenString),
3473
- where3("status", "==", "active" /* ACTIVE */),
3474
- where3("expiresAt", ">", Timestamp8.now())
3635
+ where4("token", "==", tokenString),
3636
+ where4("status", "==", "active" /* ACTIVE */),
3637
+ where4("expiresAt", ">", Timestamp8.now())
3475
3638
  );
3476
- const tokenSnapshot = await getDocs3(q);
3639
+ const tokenSnapshot = await getDocs4(q);
3477
3640
  if (!tokenSnapshot.empty) {
3478
3641
  return tokenSnapshot.docs[0].data();
3479
3642
  }
@@ -3513,11 +3676,11 @@ var PractitionerService = class extends BaseService {
3513
3676
  * Dohvata zdravstvenog radnika po User ID-u
3514
3677
  */
3515
3678
  async getPractitionerByUserRef(userRef) {
3516
- const q = query3(
3517
- collection3(this.db, PRACTITIONERS_COLLECTION),
3518
- where3("userRef", "==", userRef)
3679
+ const q = query4(
3680
+ collection4(this.db, PRACTITIONERS_COLLECTION),
3681
+ where4("userRef", "==", userRef)
3519
3682
  );
3520
- const querySnapshot = await getDocs3(q);
3683
+ const querySnapshot = await getDocs4(q);
3521
3684
  if (querySnapshot.empty) {
3522
3685
  return null;
3523
3686
  }
@@ -3527,38 +3690,38 @@ var PractitionerService = class extends BaseService {
3527
3690
  * Dohvata sve zdravstvene radnike za određenu kliniku sa statusom ACTIVE
3528
3691
  */
3529
3692
  async getPractitionersByClinic(clinicId) {
3530
- const q = query3(
3531
- collection3(this.db, PRACTITIONERS_COLLECTION),
3532
- where3("clinics", "array-contains", clinicId),
3533
- where3("isActive", "==", true),
3534
- where3("status", "==", "active" /* ACTIVE */)
3693
+ const q = query4(
3694
+ collection4(this.db, PRACTITIONERS_COLLECTION),
3695
+ where4("clinics", "array-contains", clinicId),
3696
+ where4("isActive", "==", true),
3697
+ where4("status", "==", "active" /* ACTIVE */)
3535
3698
  );
3536
- const querySnapshot = await getDocs3(q);
3537
- return querySnapshot.docs.map((doc26) => doc26.data());
3699
+ const querySnapshot = await getDocs4(q);
3700
+ return querySnapshot.docs.map((doc27) => doc27.data());
3538
3701
  }
3539
3702
  /**
3540
3703
  * Dohvata sve zdravstvene radnike za određenu kliniku
3541
3704
  */
3542
3705
  async getAllPractitionersByClinic(clinicId) {
3543
- const q = query3(
3544
- collection3(this.db, PRACTITIONERS_COLLECTION),
3545
- where3("clinics", "array-contains", clinicId),
3546
- where3("isActive", "==", true)
3706
+ const q = query4(
3707
+ collection4(this.db, PRACTITIONERS_COLLECTION),
3708
+ where4("clinics", "array-contains", clinicId),
3709
+ where4("isActive", "==", true)
3547
3710
  );
3548
- const querySnapshot = await getDocs3(q);
3549
- return querySnapshot.docs.map((doc26) => doc26.data());
3711
+ const querySnapshot = await getDocs4(q);
3712
+ return querySnapshot.docs.map((doc27) => doc27.data());
3550
3713
  }
3551
3714
  /**
3552
3715
  * Dohvata sve draft zdravstvene radnike za određenu kliniku sa statusom DRAFT
3553
3716
  */
3554
3717
  async getDraftPractitionersByClinic(clinicId) {
3555
- const q = query3(
3556
- collection3(this.db, PRACTITIONERS_COLLECTION),
3557
- where3("clinics", "array-contains", clinicId),
3558
- where3("status", "==", "draft" /* DRAFT */)
3718
+ const q = query4(
3719
+ collection4(this.db, PRACTITIONERS_COLLECTION),
3720
+ where4("clinics", "array-contains", clinicId),
3721
+ where4("status", "==", "draft" /* DRAFT */)
3559
3722
  );
3560
- const querySnapshot = await getDocs3(q);
3561
- return querySnapshot.docs.map((doc26) => doc26.data());
3723
+ const querySnapshot = await getDocs4(q);
3724
+ return querySnapshot.docs.map((doc27) => doc27.data());
3562
3725
  }
3563
3726
  /**
3564
3727
  * Ažurira profil zdravstvenog radnika
@@ -3854,20 +4017,20 @@ var UserService = class extends BaseService {
3854
4017
  * Dohvata korisnika po email-u
3855
4018
  */
3856
4019
  async getUserByEmail(email) {
3857
- const usersRef = collection4(this.db, USERS_COLLECTION);
3858
- const q = query4(usersRef, where4("email", "==", email));
3859
- const querySnapshot = await getDocs4(q);
4020
+ const usersRef = collection5(this.db, USERS_COLLECTION);
4021
+ const q = query5(usersRef, where5("email", "==", email));
4022
+ const querySnapshot = await getDocs5(q);
3860
4023
  if (querySnapshot.empty) return null;
3861
4024
  const userData = querySnapshot.docs[0].data();
3862
4025
  return userSchema.parse(userData);
3863
4026
  }
3864
4027
  async getUsersByRole(role) {
3865
4028
  const constraints = [
3866
- where4("roles", "array-contains", role)
4029
+ where5("roles", "array-contains", role)
3867
4030
  ];
3868
- const q = query4(collection4(this.db, USERS_COLLECTION), ...constraints);
3869
- const querySnapshot = await getDocs4(q);
3870
- const users = querySnapshot.docs.map((doc26) => doc26.data());
4031
+ const q = query5(collection5(this.db, USERS_COLLECTION), ...constraints);
4032
+ const querySnapshot = await getDocs5(q);
4033
+ const users = querySnapshot.docs.map((doc27) => doc27.data());
3871
4034
  return Promise.all(users.map((userData) => userSchema.parse(userData)));
3872
4035
  }
3873
4036
  /**
@@ -4004,12 +4167,12 @@ var UserService = class extends BaseService {
4004
4167
 
4005
4168
  // src/services/clinic/utils/clinic-group.utils.ts
4006
4169
  import {
4007
- collection as collection5,
4170
+ collection as collection6,
4008
4171
  doc as doc7,
4009
4172
  getDoc as getDoc11,
4010
- getDocs as getDocs5,
4011
- query as query5,
4012
- where as where5,
4173
+ getDocs as getDocs6,
4174
+ query as query6,
4175
+ where as where6,
4013
4176
  updateDoc as updateDoc10,
4014
4177
  setDoc as setDoc9,
4015
4178
  Timestamp as Timestamp10
@@ -4138,7 +4301,7 @@ async function createClinicGroup(db, data, ownerId, isDefault = false, clinicAdm
4138
4301
  }
4139
4302
  const now = Timestamp10.now();
4140
4303
  console.log("[CLINIC_GROUP] Preparing clinic group data object");
4141
- const groupId = doc7(collection5(db, CLINIC_GROUPS_COLLECTION)).id;
4304
+ const groupId = doc7(collection6(db, CLINIC_GROUPS_COLLECTION)).id;
4142
4305
  console.log("[CLINIC_GROUP] Logo value:", {
4143
4306
  logoValue: validatedData.logo,
4144
4307
  logoType: validatedData.logo === null ? "null" : typeof validatedData.logo
@@ -4242,12 +4405,12 @@ async function getClinicGroup(db, groupId) {
4242
4405
  return null;
4243
4406
  }
4244
4407
  async function getAllActiveGroups(db) {
4245
- const q = query5(
4246
- collection5(db, CLINIC_GROUPS_COLLECTION),
4247
- where5("isActive", "==", true)
4408
+ const q = query6(
4409
+ collection6(db, CLINIC_GROUPS_COLLECTION),
4410
+ where6("isActive", "==", true)
4248
4411
  );
4249
- const querySnapshot = await getDocs5(q);
4250
- return querySnapshot.docs.map((doc26) => doc26.data());
4412
+ const querySnapshot = await getDocs6(q);
4413
+ return querySnapshot.docs.map((doc27) => doc27.data());
4251
4414
  }
4252
4415
  async function updateClinicGroup(db, groupId, data, app) {
4253
4416
  console.log("[CLINIC_GROUP] Updating clinic group", { groupId });
@@ -4623,12 +4786,12 @@ var ClinicGroupService = class extends BaseService {
4623
4786
 
4624
4787
  // src/services/clinic/utils/clinic.utils.ts
4625
4788
  import {
4626
- collection as collection6,
4789
+ collection as collection7,
4627
4790
  doc as doc8,
4628
4791
  getDoc as getDoc12,
4629
- getDocs as getDocs6,
4630
- query as query6,
4631
- where as where6,
4792
+ getDocs as getDocs7,
4793
+ query as query7,
4794
+ where as where7,
4632
4795
  updateDoc as updateDoc11,
4633
4796
  setDoc as setDoc10,
4634
4797
  Timestamp as Timestamp11
@@ -4697,7 +4860,7 @@ async function createClinic(db, data, creatorAdminId, clinicGroupService, clinic
4697
4860
  throw geohashError;
4698
4861
  }
4699
4862
  }
4700
- const clinicId = doc8(collection6(db, CLINICS_COLLECTION)).id;
4863
+ const clinicId = doc8(collection7(db, CLINICS_COLLECTION)).id;
4701
4864
  console.log("[CLINIC] Generated clinic ID:", clinicId);
4702
4865
  console.log("[CLINIC] Processing photos");
4703
4866
  let logoUrl = null;
@@ -4913,13 +5076,13 @@ async function getClinic(db, clinicId) {
4913
5076
  return null;
4914
5077
  }
4915
5078
  async function getClinicsByGroup(db, groupId) {
4916
- const q = query6(
4917
- collection6(db, CLINICS_COLLECTION),
4918
- where6("clinicGroupId", "==", groupId),
4919
- where6("isActive", "==", true)
5079
+ const q = query7(
5080
+ collection7(db, CLINICS_COLLECTION),
5081
+ where7("clinicGroupId", "==", groupId),
5082
+ where7("isActive", "==", true)
4920
5083
  );
4921
- const querySnapshot = await getDocs6(q);
4922
- return querySnapshot.docs.map((doc26) => doc26.data());
5084
+ const querySnapshot = await getDocs7(q);
5085
+ return querySnapshot.docs.map((doc27) => doc27.data());
4923
5086
  }
4924
5087
  async function updateClinic(db, clinicId, data, adminId, clinicAdminService, app) {
4925
5088
  console.log("[CLINIC] Starting clinic update", { clinicId, adminId });
@@ -5125,13 +5288,13 @@ async function getClinicsByAdmin(db, adminId, options = {}, clinicAdminService,
5125
5288
  if (clinicIds.length === 0) {
5126
5289
  return [];
5127
5290
  }
5128
- const constraints = [where6("id", "in", clinicIds)];
5291
+ const constraints = [where7("id", "in", clinicIds)];
5129
5292
  if (options.isActive !== void 0) {
5130
- constraints.push(where6("isActive", "==", options.isActive));
5293
+ constraints.push(where7("isActive", "==", options.isActive));
5131
5294
  }
5132
- const q = query6(collection6(db, CLINICS_COLLECTION), ...constraints);
5133
- const querySnapshot = await getDocs6(q);
5134
- return querySnapshot.docs.map((doc26) => doc26.data());
5295
+ const q = query7(collection7(db, CLINICS_COLLECTION), ...constraints);
5296
+ const querySnapshot = await getDocs7(q);
5297
+ return querySnapshot.docs.map((doc27) => doc27.data());
5135
5298
  }
5136
5299
  async function getActiveClinicsByAdmin(db, adminId, clinicAdminService, clinicGroupService) {
5137
5300
  return getClinicsByAdmin(
@@ -5145,7 +5308,7 @@ async function getActiveClinicsByAdmin(db, adminId, clinicAdminService, clinicGr
5145
5308
 
5146
5309
  // src/services/clinic/utils/review.utils.ts
5147
5310
  import {
5148
- collection as collection7,
5311
+ collection as collection8,
5149
5312
  doc as doc9,
5150
5313
  Timestamp as Timestamp12,
5151
5314
  getDoc as getDoc13,
@@ -5161,14 +5324,14 @@ async function addReview(db, clinicId, review, app) {
5161
5324
  const now = Timestamp12.now();
5162
5325
  const reviewData = {
5163
5326
  ...review,
5164
- id: doc9(collection7(db, "clinic_reviews")).id,
5327
+ id: doc9(collection8(db, "clinic_reviews")).id,
5165
5328
  clinicId,
5166
5329
  createdAt: now,
5167
5330
  updatedAt: now,
5168
5331
  isVerified: false
5169
5332
  };
5170
5333
  clinicReviewSchema.parse(reviewData);
5171
- await addDoc2(collection7(db, "clinic_reviews"), reviewData);
5334
+ await addDoc2(collection8(db, "clinic_reviews"), reviewData);
5172
5335
  const newRating = clinic.rating ? {
5173
5336
  average: (clinic.rating.average * clinic.rating.count + review.rating) / (clinic.rating.count + 1),
5174
5337
  count: clinic.rating.count + 1
@@ -5256,10 +5419,10 @@ async function removeTags(db, clinicId, adminId, tagsToRemove, clinicAdminServic
5256
5419
 
5257
5420
  // src/services/clinic/utils/search.utils.ts
5258
5421
  import {
5259
- collection as collection8,
5260
- query as query7,
5261
- where as where7,
5262
- getDocs as getDocs7
5422
+ collection as collection9,
5423
+ query as query8,
5424
+ where as where8,
5425
+ getDocs as getDocs8
5263
5426
  } from "firebase/firestore";
5264
5427
  import { geohashQueryBounds, distanceBetween } from "geofire-common";
5265
5428
  async function findClinicsInRadius(db, center, radiusInKm, filters) {
@@ -5270,22 +5433,22 @@ async function findClinicsInRadius(db, center, radiusInKm, filters) {
5270
5433
  const matchingDocs = [];
5271
5434
  for (const b of bounds) {
5272
5435
  const constraints = [
5273
- where7("location.geohash", ">=", b[0]),
5274
- where7("location.geohash", "<=", b[1]),
5275
- where7("isActive", "==", true)
5436
+ where8("location.geohash", ">=", b[0]),
5437
+ where8("location.geohash", "<=", b[1]),
5438
+ where8("isActive", "==", true)
5276
5439
  ];
5277
5440
  if (filters == null ? void 0 : filters.services) {
5278
5441
  constraints.push(
5279
- where7("services", "array-contains-any", filters.services)
5442
+ where8("services", "array-contains-any", filters.services)
5280
5443
  );
5281
5444
  }
5282
5445
  if ((filters == null ? void 0 : filters.tags) && filters.tags.length > 0) {
5283
- constraints.push(where7("tags", "array-contains-any", filters.tags));
5446
+ constraints.push(where8("tags", "array-contains-any", filters.tags));
5284
5447
  }
5285
- const q = query7(collection8(db, CLINICS_COLLECTION), ...constraints);
5286
- const querySnapshot = await getDocs7(q);
5287
- for (const doc26 of querySnapshot.docs) {
5288
- const clinic = doc26.data();
5448
+ const q = query8(collection9(db, CLINICS_COLLECTION), ...constraints);
5449
+ const querySnapshot = await getDocs8(q);
5450
+ for (const doc27 of querySnapshot.docs) {
5451
+ const clinic = doc27.data();
5289
5452
  const distance = distanceBetween(
5290
5453
  [center.latitude, center.longitude],
5291
5454
  [clinic.location.latitude, clinic.location.longitude]
@@ -5699,9 +5862,9 @@ var AuthService = class extends BaseService {
5699
5862
  token: data.inviteToken
5700
5863
  });
5701
5864
  console.log("[AUTH] Searching for token in clinic groups");
5702
- const groupsRef = collection9(this.db, CLINIC_GROUPS_COLLECTION);
5703
- const q = query8(groupsRef);
5704
- const querySnapshot = await getDocs8(q);
5865
+ const groupsRef = collection10(this.db, CLINIC_GROUPS_COLLECTION);
5866
+ const q = query9(groupsRef);
5867
+ const querySnapshot = await getDocs9(q);
5705
5868
  let foundGroup = null;
5706
5869
  let foundToken = null;
5707
5870
  console.log(
@@ -6148,12 +6311,12 @@ var AuthService = class extends BaseService {
6148
6311
 
6149
6312
  // src/services/notifications/notification.service.ts
6150
6313
  import {
6151
- collection as collection10,
6314
+ collection as collection11,
6152
6315
  doc as doc11,
6153
6316
  getDoc as getDoc15,
6154
- getDocs as getDocs9,
6155
- query as query9,
6156
- where as where9,
6317
+ getDocs as getDocs10,
6318
+ query as query10,
6319
+ where as where10,
6157
6320
  updateDoc as updateDoc13,
6158
6321
  deleteDoc as deleteDoc6,
6159
6322
  orderBy,
@@ -6186,7 +6349,7 @@ var NotificationService = class extends BaseService {
6186
6349
  * Kreira novu notifikaciju
6187
6350
  */
6188
6351
  async createNotification(notification) {
6189
- const notificationsRef = collection10(this.db, NOTIFICATIONS_COLLECTION);
6352
+ const notificationsRef = collection11(this.db, NOTIFICATIONS_COLLECTION);
6190
6353
  const now = Timestamp14.now();
6191
6354
  const notificationData = {
6192
6355
  ...notification,
@@ -6224,31 +6387,31 @@ var NotificationService = class extends BaseService {
6224
6387
  * Dohvata sve notifikacije za korisnika
6225
6388
  */
6226
6389
  async getUserNotifications(userId) {
6227
- const q = query9(
6228
- collection10(this.db, NOTIFICATIONS_COLLECTION),
6229
- where9("userId", "==", userId),
6390
+ const q = query10(
6391
+ collection11(this.db, NOTIFICATIONS_COLLECTION),
6392
+ where10("userId", "==", userId),
6230
6393
  orderBy("notificationTime", "desc")
6231
6394
  );
6232
- const querySnapshot = await getDocs9(q);
6233
- return querySnapshot.docs.map((doc26) => ({
6234
- id: doc26.id,
6235
- ...doc26.data()
6395
+ const querySnapshot = await getDocs10(q);
6396
+ return querySnapshot.docs.map((doc27) => ({
6397
+ id: doc27.id,
6398
+ ...doc27.data()
6236
6399
  }));
6237
6400
  }
6238
6401
  /**
6239
6402
  * Dohvata nepročitane notifikacije za korisnika
6240
6403
  */
6241
6404
  async getUnreadNotifications(userId) {
6242
- const q = query9(
6243
- collection10(this.db, NOTIFICATIONS_COLLECTION),
6244
- where9("userId", "==", userId),
6245
- where9("isRead", "==", false),
6405
+ const q = query10(
6406
+ collection11(this.db, NOTIFICATIONS_COLLECTION),
6407
+ where10("userId", "==", userId),
6408
+ where10("isRead", "==", false),
6246
6409
  orderBy("notificationTime", "desc")
6247
6410
  );
6248
- const querySnapshot = await getDocs9(q);
6249
- return querySnapshot.docs.map((doc26) => ({
6250
- id: doc26.id,
6251
- ...doc26.data()
6411
+ const querySnapshot = await getDocs10(q);
6412
+ return querySnapshot.docs.map((doc27) => ({
6413
+ id: doc27.id,
6414
+ ...doc27.data()
6252
6415
  }));
6253
6416
  }
6254
6417
  /**
@@ -6313,43 +6476,43 @@ var NotificationService = class extends BaseService {
6313
6476
  * Dohvata notifikacije po tipu
6314
6477
  */
6315
6478
  async getNotificationsByType(userId, type) {
6316
- const q = query9(
6317
- collection10(this.db, NOTIFICATIONS_COLLECTION),
6318
- where9("userId", "==", userId),
6319
- where9("notificationType", "==", type),
6479
+ const q = query10(
6480
+ collection11(this.db, NOTIFICATIONS_COLLECTION),
6481
+ where10("userId", "==", userId),
6482
+ where10("notificationType", "==", type),
6320
6483
  orderBy("notificationTime", "desc")
6321
6484
  );
6322
- const querySnapshot = await getDocs9(q);
6323
- return querySnapshot.docs.map((doc26) => ({
6324
- id: doc26.id,
6325
- ...doc26.data()
6485
+ const querySnapshot = await getDocs10(q);
6486
+ return querySnapshot.docs.map((doc27) => ({
6487
+ id: doc27.id,
6488
+ ...doc27.data()
6326
6489
  }));
6327
6490
  }
6328
6491
  /**
6329
6492
  * Dohvata notifikacije za određeni termin
6330
6493
  */
6331
6494
  async getAppointmentNotifications(appointmentId) {
6332
- const q = query9(
6333
- collection10(this.db, NOTIFICATIONS_COLLECTION),
6334
- where9("appointmentId", "==", appointmentId),
6495
+ const q = query10(
6496
+ collection11(this.db, NOTIFICATIONS_COLLECTION),
6497
+ where10("appointmentId", "==", appointmentId),
6335
6498
  orderBy("notificationTime", "desc")
6336
6499
  );
6337
- const querySnapshot = await getDocs9(q);
6338
- return querySnapshot.docs.map((doc26) => ({
6339
- id: doc26.id,
6340
- ...doc26.data()
6500
+ const querySnapshot = await getDocs10(q);
6501
+ return querySnapshot.docs.map((doc27) => ({
6502
+ id: doc27.id,
6503
+ ...doc27.data()
6341
6504
  }));
6342
6505
  }
6343
6506
  };
6344
6507
 
6345
6508
  // src/services/procedure/procedure.service.ts
6346
6509
  import {
6347
- collection as collection11,
6510
+ collection as collection12,
6348
6511
  doc as doc12,
6349
6512
  getDoc as getDoc16,
6350
- getDocs as getDocs10,
6351
- query as query10,
6352
- where as where10,
6513
+ getDocs as getDocs11,
6514
+ query as query11,
6515
+ where as where11,
6353
6516
  updateDoc as updateDoc14,
6354
6517
  setDoc as setDoc13,
6355
6518
  serverTimestamp as serverTimestamp13
@@ -6489,13 +6652,13 @@ var ProcedureService = class extends BaseService {
6489
6652
  * @returns List of procedures
6490
6653
  */
6491
6654
  async getProceduresByClinicBranch(clinicBranchId) {
6492
- const q = query10(
6493
- collection11(this.db, PROCEDURES_COLLECTION),
6494
- where10("clinicBranchId", "==", clinicBranchId),
6495
- where10("isActive", "==", true)
6655
+ const q = query11(
6656
+ collection12(this.db, PROCEDURES_COLLECTION),
6657
+ where11("clinicBranchId", "==", clinicBranchId),
6658
+ where11("isActive", "==", true)
6496
6659
  );
6497
- const snapshot = await getDocs10(q);
6498
- return snapshot.docs.map((doc26) => doc26.data());
6660
+ const snapshot = await getDocs11(q);
6661
+ return snapshot.docs.map((doc27) => doc27.data());
6499
6662
  }
6500
6663
  /**
6501
6664
  * Gets all procedures for a practitioner
@@ -6503,13 +6666,13 @@ var ProcedureService = class extends BaseService {
6503
6666
  * @returns List of procedures
6504
6667
  */
6505
6668
  async getProceduresByPractitioner(practitionerId) {
6506
- const q = query10(
6507
- collection11(this.db, PROCEDURES_COLLECTION),
6508
- where10("practitionerId", "==", practitionerId),
6509
- where10("isActive", "==", true)
6669
+ const q = query11(
6670
+ collection12(this.db, PROCEDURES_COLLECTION),
6671
+ where11("practitionerId", "==", practitionerId),
6672
+ where11("isActive", "==", true)
6510
6673
  );
6511
- const snapshot = await getDocs10(q);
6512
- return snapshot.docs.map((doc26) => doc26.data());
6674
+ const snapshot = await getDocs11(q);
6675
+ return snapshot.docs.map((doc27) => doc27.data());
6513
6676
  }
6514
6677
  /**
6515
6678
  * Updates a procedure
@@ -6579,15 +6742,15 @@ var ProcedureService = class extends BaseService {
6579
6742
 
6580
6743
  // src/services/documentation-templates/documentation-template.service.ts
6581
6744
  import {
6582
- collection as collection12,
6745
+ collection as collection13,
6583
6746
  doc as doc13,
6584
6747
  getDoc as getDoc17,
6585
- getDocs as getDocs11,
6748
+ getDocs as getDocs12,
6586
6749
  setDoc as setDoc14,
6587
6750
  updateDoc as updateDoc15,
6588
6751
  deleteDoc as deleteDoc8,
6589
- query as query11,
6590
- where as where11,
6752
+ query as query12,
6753
+ where as where12,
6591
6754
  orderBy as orderBy2,
6592
6755
  limit,
6593
6756
  startAfter
@@ -6595,7 +6758,7 @@ import {
6595
6758
  var DocumentationTemplateService = class extends BaseService {
6596
6759
  constructor() {
6597
6760
  super(...arguments);
6598
- this.collectionRef = collection12(
6761
+ this.collectionRef = collection13(
6599
6762
  this.db,
6600
6763
  DOCUMENTATION_TEMPLATES_COLLECTION
6601
6764
  );
@@ -6690,21 +6853,21 @@ var DocumentationTemplateService = class extends BaseService {
6690
6853
  * @returns Array of templates and the last document for pagination
6691
6854
  */
6692
6855
  async getActiveTemplates(pageSize = 20, lastDoc) {
6693
- let q = query11(
6856
+ let q = query12(
6694
6857
  this.collectionRef,
6695
- where11("isActive", "==", true),
6858
+ where12("isActive", "==", true),
6696
6859
  orderBy2("updatedAt", "desc"),
6697
6860
  limit(pageSize)
6698
6861
  );
6699
6862
  if (lastDoc) {
6700
- q = query11(q, startAfter(lastDoc));
6863
+ q = query12(q, startAfter(lastDoc));
6701
6864
  }
6702
- const querySnapshot = await getDocs11(q);
6865
+ const querySnapshot = await getDocs12(q);
6703
6866
  const templates = [];
6704
6867
  let lastVisible = null;
6705
- querySnapshot.forEach((doc26) => {
6706
- templates.push(doc26.data());
6707
- lastVisible = doc26;
6868
+ querySnapshot.forEach((doc27) => {
6869
+ templates.push(doc27.data());
6870
+ lastVisible = doc27;
6708
6871
  });
6709
6872
  return {
6710
6873
  templates,
@@ -6719,22 +6882,22 @@ var DocumentationTemplateService = class extends BaseService {
6719
6882
  * @returns Array of templates and the last document for pagination
6720
6883
  */
6721
6884
  async getTemplatesByTags(tags, pageSize = 20, lastDoc) {
6722
- let q = query11(
6885
+ let q = query12(
6723
6886
  this.collectionRef,
6724
- where11("isActive", "==", true),
6725
- where11("tags", "array-contains-any", tags),
6887
+ where12("isActive", "==", true),
6888
+ where12("tags", "array-contains-any", tags),
6726
6889
  orderBy2("updatedAt", "desc"),
6727
6890
  limit(pageSize)
6728
6891
  );
6729
6892
  if (lastDoc) {
6730
- q = query11(q, startAfter(lastDoc));
6893
+ q = query12(q, startAfter(lastDoc));
6731
6894
  }
6732
- const querySnapshot = await getDocs11(q);
6895
+ const querySnapshot = await getDocs12(q);
6733
6896
  const templates = [];
6734
6897
  let lastVisible = null;
6735
- querySnapshot.forEach((doc26) => {
6736
- templates.push(doc26.data());
6737
- lastVisible = doc26;
6898
+ querySnapshot.forEach((doc27) => {
6899
+ templates.push(doc27.data());
6900
+ lastVisible = doc27;
6738
6901
  });
6739
6902
  return {
6740
6903
  templates,
@@ -6749,21 +6912,21 @@ var DocumentationTemplateService = class extends BaseService {
6749
6912
  * @returns Array of templates and the last document for pagination
6750
6913
  */
6751
6914
  async getTemplatesByCreator(userId, pageSize = 20, lastDoc) {
6752
- let q = query11(
6915
+ let q = query12(
6753
6916
  this.collectionRef,
6754
- where11("createdBy", "==", userId),
6917
+ where12("createdBy", "==", userId),
6755
6918
  orderBy2("updatedAt", "desc"),
6756
6919
  limit(pageSize)
6757
6920
  );
6758
6921
  if (lastDoc) {
6759
- q = query11(q, startAfter(lastDoc));
6922
+ q = query12(q, startAfter(lastDoc));
6760
6923
  }
6761
- const querySnapshot = await getDocs11(q);
6924
+ const querySnapshot = await getDocs12(q);
6762
6925
  const templates = [];
6763
6926
  let lastVisible = null;
6764
- querySnapshot.forEach((doc26) => {
6765
- templates.push(doc26.data());
6766
- lastVisible = doc26;
6927
+ querySnapshot.forEach((doc27) => {
6928
+ templates.push(doc27.data());
6929
+ lastVisible = doc27;
6767
6930
  });
6768
6931
  return {
6769
6932
  templates,
@@ -6774,14 +6937,14 @@ var DocumentationTemplateService = class extends BaseService {
6774
6937
 
6775
6938
  // src/services/documentation-templates/filled-document.service.ts
6776
6939
  import {
6777
- collection as collection13,
6940
+ collection as collection14,
6778
6941
  doc as doc14,
6779
6942
  getDoc as getDoc18,
6780
- getDocs as getDocs12,
6943
+ getDocs as getDocs13,
6781
6944
  setDoc as setDoc15,
6782
6945
  updateDoc as updateDoc16,
6783
- query as query12,
6784
- where as where12,
6946
+ query as query13,
6947
+ where as where13,
6785
6948
  orderBy as orderBy3,
6786
6949
  limit as limit2,
6787
6950
  startAfter as startAfter2
@@ -6789,7 +6952,7 @@ import {
6789
6952
  var FilledDocumentService = class extends BaseService {
6790
6953
  constructor(...args) {
6791
6954
  super(...args);
6792
- this.collectionRef = collection13(
6955
+ this.collectionRef = collection14(
6793
6956
  this.db,
6794
6957
  FILLED_DOCUMENTS_COLLECTION
6795
6958
  );
@@ -6876,21 +7039,21 @@ var FilledDocumentService = class extends BaseService {
6876
7039
  * @returns Array of filled documents and the last document for pagination
6877
7040
  */
6878
7041
  async getFilledDocumentsByPatient(patientId, pageSize = 20, lastDoc) {
6879
- let q = query12(
7042
+ let q = query13(
6880
7043
  this.collectionRef,
6881
- where12("patientId", "==", patientId),
7044
+ where13("patientId", "==", patientId),
6882
7045
  orderBy3("updatedAt", "desc"),
6883
7046
  limit2(pageSize)
6884
7047
  );
6885
7048
  if (lastDoc) {
6886
- q = query12(q, startAfter2(lastDoc));
7049
+ q = query13(q, startAfter2(lastDoc));
6887
7050
  }
6888
- const querySnapshot = await getDocs12(q);
7051
+ const querySnapshot = await getDocs13(q);
6889
7052
  const documents = [];
6890
7053
  let lastVisible = null;
6891
- querySnapshot.forEach((doc26) => {
6892
- documents.push(doc26.data());
6893
- lastVisible = doc26;
7054
+ querySnapshot.forEach((doc27) => {
7055
+ documents.push(doc27.data());
7056
+ lastVisible = doc27;
6894
7057
  });
6895
7058
  return {
6896
7059
  documents,
@@ -6905,21 +7068,21 @@ var FilledDocumentService = class extends BaseService {
6905
7068
  * @returns Array of filled documents and the last document for pagination
6906
7069
  */
6907
7070
  async getFilledDocumentsByPractitioner(practitionerId, pageSize = 20, lastDoc) {
6908
- let q = query12(
7071
+ let q = query13(
6909
7072
  this.collectionRef,
6910
- where12("practitionerId", "==", practitionerId),
7073
+ where13("practitionerId", "==", practitionerId),
6911
7074
  orderBy3("updatedAt", "desc"),
6912
7075
  limit2(pageSize)
6913
7076
  );
6914
7077
  if (lastDoc) {
6915
- q = query12(q, startAfter2(lastDoc));
7078
+ q = query13(q, startAfter2(lastDoc));
6916
7079
  }
6917
- const querySnapshot = await getDocs12(q);
7080
+ const querySnapshot = await getDocs13(q);
6918
7081
  const documents = [];
6919
7082
  let lastVisible = null;
6920
- querySnapshot.forEach((doc26) => {
6921
- documents.push(doc26.data());
6922
- lastVisible = doc26;
7083
+ querySnapshot.forEach((doc27) => {
7084
+ documents.push(doc27.data());
7085
+ lastVisible = doc27;
6923
7086
  });
6924
7087
  return {
6925
7088
  documents,
@@ -6934,21 +7097,21 @@ var FilledDocumentService = class extends BaseService {
6934
7097
  * @returns Array of filled documents and the last document for pagination
6935
7098
  */
6936
7099
  async getFilledDocumentsByClinic(clinicId, pageSize = 20, lastDoc) {
6937
- let q = query12(
7100
+ let q = query13(
6938
7101
  this.collectionRef,
6939
- where12("clinicId", "==", clinicId),
7102
+ where13("clinicId", "==", clinicId),
6940
7103
  orderBy3("updatedAt", "desc"),
6941
7104
  limit2(pageSize)
6942
7105
  );
6943
7106
  if (lastDoc) {
6944
- q = query12(q, startAfter2(lastDoc));
7107
+ q = query13(q, startAfter2(lastDoc));
6945
7108
  }
6946
- const querySnapshot = await getDocs12(q);
7109
+ const querySnapshot = await getDocs13(q);
6947
7110
  const documents = [];
6948
7111
  let lastVisible = null;
6949
- querySnapshot.forEach((doc26) => {
6950
- documents.push(doc26.data());
6951
- lastVisible = doc26;
7112
+ querySnapshot.forEach((doc27) => {
7113
+ documents.push(doc27.data());
7114
+ lastVisible = doc27;
6952
7115
  });
6953
7116
  return {
6954
7117
  documents,
@@ -6963,21 +7126,21 @@ var FilledDocumentService = class extends BaseService {
6963
7126
  * @returns Array of filled documents and the last document for pagination
6964
7127
  */
6965
7128
  async getFilledDocumentsByTemplate(templateId, pageSize = 20, lastDoc) {
6966
- let q = query12(
7129
+ let q = query13(
6967
7130
  this.collectionRef,
6968
- where12("templateId", "==", templateId),
7131
+ where13("templateId", "==", templateId),
6969
7132
  orderBy3("updatedAt", "desc"),
6970
7133
  limit2(pageSize)
6971
7134
  );
6972
7135
  if (lastDoc) {
6973
- q = query12(q, startAfter2(lastDoc));
7136
+ q = query13(q, startAfter2(lastDoc));
6974
7137
  }
6975
- const querySnapshot = await getDocs12(q);
7138
+ const querySnapshot = await getDocs13(q);
6976
7139
  const documents = [];
6977
7140
  let lastVisible = null;
6978
- querySnapshot.forEach((doc26) => {
6979
- documents.push(doc26.data());
6980
- lastVisible = doc26;
7141
+ querySnapshot.forEach((doc27) => {
7142
+ documents.push(doc27.data());
7143
+ lastVisible = doc27;
6981
7144
  });
6982
7145
  return {
6983
7146
  documents,
@@ -6992,21 +7155,21 @@ var FilledDocumentService = class extends BaseService {
6992
7155
  * @returns Array of filled documents and the last document for pagination
6993
7156
  */
6994
7157
  async getFilledDocumentsByStatus(status, pageSize = 20, lastDoc) {
6995
- let q = query12(
7158
+ let q = query13(
6996
7159
  this.collectionRef,
6997
- where12("status", "==", status),
7160
+ where13("status", "==", status),
6998
7161
  orderBy3("updatedAt", "desc"),
6999
7162
  limit2(pageSize)
7000
7163
  );
7001
7164
  if (lastDoc) {
7002
- q = query12(q, startAfter2(lastDoc));
7165
+ q = query13(q, startAfter2(lastDoc));
7003
7166
  }
7004
- const querySnapshot = await getDocs12(q);
7167
+ const querySnapshot = await getDocs13(q);
7005
7168
  const documents = [];
7006
7169
  let lastVisible = null;
7007
- querySnapshot.forEach((doc26) => {
7008
- documents.push(doc26.data());
7009
- lastVisible = doc26;
7170
+ querySnapshot.forEach((doc27) => {
7171
+ documents.push(doc27.data());
7172
+ lastVisible = doc27;
7010
7173
  });
7011
7174
  return {
7012
7175
  documents,
@@ -7016,7 +7179,7 @@ var FilledDocumentService = class extends BaseService {
7016
7179
  };
7017
7180
 
7018
7181
  // src/services/calendar/calendar-refactored.service.ts
7019
- import { Timestamp as Timestamp24, serverTimestamp as serverTimestamp19 } from "firebase/firestore";
7182
+ import { Timestamp as Timestamp25, serverTimestamp as serverTimestamp20 } from "firebase/firestore";
7020
7183
 
7021
7184
  // src/types/calendar/synced-calendar.types.ts
7022
7185
  var SyncedCalendarProvider = /* @__PURE__ */ ((SyncedCalendarProvider3) => {
@@ -7029,14 +7192,14 @@ var SYNCED_CALENDARS_COLLECTION = "syncedCalendars";
7029
7192
 
7030
7193
  // src/services/calendar/calendar-refactored.service.ts
7031
7194
  import {
7032
- doc as doc20,
7033
- getDoc as getDoc23,
7034
- collection as collection18,
7035
- query as query17,
7036
- where as where17,
7037
- getDocs as getDocs17,
7038
- setDoc as setDoc20,
7039
- updateDoc as updateDoc21
7195
+ doc as doc21,
7196
+ getDoc as getDoc24,
7197
+ collection as collection20,
7198
+ query as query19,
7199
+ where as where19,
7200
+ getDocs as getDocs19,
7201
+ setDoc as setDoc21,
7202
+ updateDoc as updateDoc22
7040
7203
  } from "firebase/firestore";
7041
7204
 
7042
7205
  // src/validations/calendar.schema.ts
@@ -7215,15 +7378,15 @@ var calendarEventSchema = z18.object({
7215
7378
 
7216
7379
  // src/services/calendar/utils/clinic.utils.ts
7217
7380
  import {
7218
- collection as collection14,
7381
+ collection as collection15,
7219
7382
  doc as doc16,
7220
7383
  getDoc as getDoc19,
7221
- getDocs as getDocs13,
7384
+ getDocs as getDocs14,
7222
7385
  setDoc as setDoc16,
7223
7386
  updateDoc as updateDoc17,
7224
7387
  deleteDoc as deleteDoc9,
7225
- query as query13,
7226
- where as where13,
7388
+ query as query14,
7389
+ where as where14,
7227
7390
  orderBy as orderBy4,
7228
7391
  Timestamp as Timestamp19,
7229
7392
  serverTimestamp as serverTimestamp15
@@ -7320,14 +7483,14 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
7320
7483
 
7321
7484
  // src/services/calendar/utils/patient.utils.ts
7322
7485
  import {
7323
- collection as collection15,
7486
+ collection as collection16,
7324
7487
  getDoc as getDoc20,
7325
- getDocs as getDocs14,
7488
+ getDocs as getDocs15,
7326
7489
  setDoc as setDoc17,
7327
7490
  updateDoc as updateDoc18,
7328
7491
  deleteDoc as deleteDoc10,
7329
- query as query14,
7330
- where as where14,
7492
+ query as query15,
7493
+ where as where15,
7331
7494
  orderBy as orderBy5,
7332
7495
  Timestamp as Timestamp20,
7333
7496
  serverTimestamp as serverTimestamp16
@@ -7364,14 +7527,14 @@ async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData
7364
7527
 
7365
7528
  // src/services/calendar/utils/practitioner.utils.ts
7366
7529
  import {
7367
- collection as collection16,
7530
+ collection as collection17,
7368
7531
  getDoc as getDoc21,
7369
- getDocs as getDocs15,
7532
+ getDocs as getDocs16,
7370
7533
  setDoc as setDoc18,
7371
7534
  updateDoc as updateDoc19,
7372
7535
  deleteDoc as deleteDoc11,
7373
- query as query15,
7374
- where as where15,
7536
+ query as query16,
7537
+ where as where16,
7375
7538
  orderBy as orderBy6,
7376
7539
  Timestamp as Timestamp21,
7377
7540
  serverTimestamp as serverTimestamp17
@@ -7482,19 +7645,126 @@ async function updateAppointmentUtil(db, clinicId, practitionerId, patientId, ev
7482
7645
  return clinicEvent;
7483
7646
  }
7484
7647
 
7485
- // src/services/calendar/utils/synced-calendar.utils.ts
7648
+ // src/services/calendar/utils/calendar-event.utils.ts
7486
7649
  import {
7487
- collection as collection17,
7650
+ collection as collection18,
7651
+ doc as doc19,
7488
7652
  getDoc as getDoc22,
7489
- getDocs as getDocs16,
7653
+ getDocs as getDocs17,
7490
7654
  setDoc as setDoc19,
7491
7655
  updateDoc as updateDoc20,
7492
7656
  deleteDoc as deleteDoc12,
7493
- query as query16,
7657
+ query as query17,
7658
+ where as where17,
7494
7659
  orderBy as orderBy7,
7495
7660
  Timestamp as Timestamp22,
7496
7661
  serverTimestamp as serverTimestamp18
7497
7662
  } from "firebase/firestore";
7663
+ async function searchCalendarEventsUtil(db, params) {
7664
+ const { searchLocation, entityId, ...filters } = params;
7665
+ let baseCollectionPath;
7666
+ const constraints = [];
7667
+ switch (searchLocation) {
7668
+ case "practitioner" /* PRACTITIONER */:
7669
+ if (!entityId) {
7670
+ throw new Error(
7671
+ "Practitioner ID (entityId) is required when searching practitioner calendar."
7672
+ );
7673
+ }
7674
+ baseCollectionPath = `${PRACTITIONERS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
7675
+ if (filters.practitionerId && filters.practitionerId !== entityId) {
7676
+ console.warn(
7677
+ `Provided practitionerId filter (${filters.practitionerId}) does not match search entityId (${entityId}). Returning empty results.`
7678
+ );
7679
+ return [];
7680
+ }
7681
+ filters.practitionerId = void 0;
7682
+ break;
7683
+ case "patient" /* PATIENT */:
7684
+ if (!entityId) {
7685
+ throw new Error(
7686
+ "Patient ID (entityId) is required when searching patient calendar."
7687
+ );
7688
+ }
7689
+ baseCollectionPath = `${PATIENTS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
7690
+ if (filters.patientId && filters.patientId !== entityId) {
7691
+ console.warn(
7692
+ `Provided patientId filter (${filters.patientId}) does not match search entityId (${entityId}). Returning empty results.`
7693
+ );
7694
+ return [];
7695
+ }
7696
+ filters.patientId = void 0;
7697
+ break;
7698
+ case "clinic" /* CLINIC */:
7699
+ if (!entityId) {
7700
+ throw new Error(
7701
+ "Clinic ID (entityId) is required when searching clinic-related events."
7702
+ );
7703
+ }
7704
+ baseCollectionPath = CALENDAR_COLLECTION;
7705
+ constraints.push(where17("clinicBranchId", "==", entityId));
7706
+ if (filters.clinicId && filters.clinicId !== entityId) {
7707
+ console.warn(
7708
+ `Provided clinicId filter (${filters.clinicId}) does not match search entityId (${entityId}). Returning empty results.`
7709
+ );
7710
+ return [];
7711
+ }
7712
+ filters.clinicId = void 0;
7713
+ break;
7714
+ default:
7715
+ throw new Error(`Invalid search location: ${searchLocation}`);
7716
+ }
7717
+ const collectionRef = collection18(db, baseCollectionPath);
7718
+ if (filters.clinicId) {
7719
+ constraints.push(where17("clinicBranchId", "==", filters.clinicId));
7720
+ }
7721
+ if (filters.practitionerId) {
7722
+ constraints.push(
7723
+ where17("practitionerProfileId", "==", filters.practitionerId)
7724
+ );
7725
+ }
7726
+ if (filters.patientId) {
7727
+ constraints.push(where17("patientProfileId", "==", filters.patientId));
7728
+ }
7729
+ if (filters.procedureId) {
7730
+ constraints.push(where17("procedureId", "==", filters.procedureId));
7731
+ }
7732
+ if (filters.eventStatus) {
7733
+ constraints.push(where17("status", "==", filters.eventStatus));
7734
+ }
7735
+ if (filters.eventType) {
7736
+ constraints.push(where17("eventType", "==", filters.eventType));
7737
+ }
7738
+ if (filters.dateRange) {
7739
+ constraints.push(where17("eventTime.start", ">=", filters.dateRange.start));
7740
+ constraints.push(where17("eventTime.start", "<=", filters.dateRange.end));
7741
+ }
7742
+ try {
7743
+ const finalQuery = query17(collectionRef, ...constraints);
7744
+ const querySnapshot = await getDocs17(finalQuery);
7745
+ const events = querySnapshot.docs.map(
7746
+ (doc27) => ({ id: doc27.id, ...doc27.data() })
7747
+ );
7748
+ return events;
7749
+ } catch (error) {
7750
+ console.error("Error searching calendar events:", error);
7751
+ return [];
7752
+ }
7753
+ }
7754
+
7755
+ // src/services/calendar/utils/synced-calendar.utils.ts
7756
+ import {
7757
+ collection as collection19,
7758
+ getDoc as getDoc23,
7759
+ getDocs as getDocs18,
7760
+ setDoc as setDoc20,
7761
+ updateDoc as updateDoc21,
7762
+ deleteDoc as deleteDoc13,
7763
+ query as query18,
7764
+ orderBy as orderBy8,
7765
+ Timestamp as Timestamp23,
7766
+ serverTimestamp as serverTimestamp19
7767
+ } from "firebase/firestore";
7498
7768
  async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendarData, generateId2) {
7499
7769
  const calendarId = generateId2();
7500
7770
  const calendarRef = getPractitionerSyncedCalendarDocRef(
@@ -7505,14 +7775,14 @@ async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendar
7505
7775
  const newCalendar = {
7506
7776
  id: calendarId,
7507
7777
  ...calendarData,
7508
- createdAt: serverTimestamp18(),
7509
- updatedAt: serverTimestamp18()
7778
+ createdAt: serverTimestamp19(),
7779
+ updatedAt: serverTimestamp19()
7510
7780
  };
7511
- await setDoc19(calendarRef, newCalendar);
7781
+ await setDoc20(calendarRef, newCalendar);
7512
7782
  return {
7513
7783
  ...newCalendar,
7514
- createdAt: Timestamp22.now(),
7515
- updatedAt: Timestamp22.now()
7784
+ createdAt: Timestamp23.now(),
7785
+ updatedAt: Timestamp23.now()
7516
7786
  };
7517
7787
  }
7518
7788
  async function createPatientSyncedCalendarUtil(db, patientId, calendarData, generateId2) {
@@ -7521,14 +7791,14 @@ async function createPatientSyncedCalendarUtil(db, patientId, calendarData, gene
7521
7791
  const newCalendar = {
7522
7792
  id: calendarId,
7523
7793
  ...calendarData,
7524
- createdAt: serverTimestamp18(),
7525
- updatedAt: serverTimestamp18()
7794
+ createdAt: serverTimestamp19(),
7795
+ updatedAt: serverTimestamp19()
7526
7796
  };
7527
- await setDoc19(calendarRef, newCalendar);
7797
+ await setDoc20(calendarRef, newCalendar);
7528
7798
  return {
7529
7799
  ...newCalendar,
7530
- createdAt: Timestamp22.now(),
7531
- updatedAt: Timestamp22.now()
7800
+ createdAt: Timestamp23.now(),
7801
+ updatedAt: Timestamp23.now()
7532
7802
  };
7533
7803
  }
7534
7804
  async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, generateId2) {
@@ -7537,14 +7807,14 @@ async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, genera
7537
7807
  const newCalendar = {
7538
7808
  id: calendarId,
7539
7809
  ...calendarData,
7540
- createdAt: serverTimestamp18(),
7541
- updatedAt: serverTimestamp18()
7810
+ createdAt: serverTimestamp19(),
7811
+ updatedAt: serverTimestamp19()
7542
7812
  };
7543
- await setDoc19(calendarRef, newCalendar);
7813
+ await setDoc20(calendarRef, newCalendar);
7544
7814
  return {
7545
7815
  ...newCalendar,
7546
- createdAt: Timestamp22.now(),
7547
- updatedAt: Timestamp22.now()
7816
+ createdAt: Timestamp23.now(),
7817
+ updatedAt: Timestamp23.now()
7548
7818
  };
7549
7819
  }
7550
7820
  async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId) {
@@ -7553,54 +7823,54 @@ async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId)
7553
7823
  practitionerId,
7554
7824
  calendarId
7555
7825
  );
7556
- const calendarDoc = await getDoc22(calendarRef);
7826
+ const calendarDoc = await getDoc23(calendarRef);
7557
7827
  if (!calendarDoc.exists()) {
7558
7828
  return null;
7559
7829
  }
7560
7830
  return calendarDoc.data();
7561
7831
  }
7562
7832
  async function getPractitionerSyncedCalendarsUtil(db, practitionerId) {
7563
- const calendarsRef = collection17(
7833
+ const calendarsRef = collection19(
7564
7834
  db,
7565
7835
  `practitioners/${practitionerId}/${SYNCED_CALENDARS_COLLECTION}`
7566
7836
  );
7567
- const q = query16(calendarsRef, orderBy7("createdAt", "desc"));
7568
- const querySnapshot = await getDocs16(q);
7569
- return querySnapshot.docs.map((doc26) => doc26.data());
7837
+ const q = query18(calendarsRef, orderBy8("createdAt", "desc"));
7838
+ const querySnapshot = await getDocs18(q);
7839
+ return querySnapshot.docs.map((doc27) => doc27.data());
7570
7840
  }
7571
7841
  async function getPatientSyncedCalendarUtil(db, patientId, calendarId) {
7572
7842
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
7573
- const calendarDoc = await getDoc22(calendarRef);
7843
+ const calendarDoc = await getDoc23(calendarRef);
7574
7844
  if (!calendarDoc.exists()) {
7575
7845
  return null;
7576
7846
  }
7577
7847
  return calendarDoc.data();
7578
7848
  }
7579
7849
  async function getPatientSyncedCalendarsUtil(db, patientId) {
7580
- const calendarsRef = collection17(
7850
+ const calendarsRef = collection19(
7581
7851
  db,
7582
7852
  `patients/${patientId}/${SYNCED_CALENDARS_COLLECTION}`
7583
7853
  );
7584
- const q = query16(calendarsRef, orderBy7("createdAt", "desc"));
7585
- const querySnapshot = await getDocs16(q);
7586
- return querySnapshot.docs.map((doc26) => doc26.data());
7854
+ const q = query18(calendarsRef, orderBy8("createdAt", "desc"));
7855
+ const querySnapshot = await getDocs18(q);
7856
+ return querySnapshot.docs.map((doc27) => doc27.data());
7587
7857
  }
7588
7858
  async function getClinicSyncedCalendarUtil(db, clinicId, calendarId) {
7589
7859
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
7590
- const calendarDoc = await getDoc22(calendarRef);
7860
+ const calendarDoc = await getDoc23(calendarRef);
7591
7861
  if (!calendarDoc.exists()) {
7592
7862
  return null;
7593
7863
  }
7594
7864
  return calendarDoc.data();
7595
7865
  }
7596
7866
  async function getClinicSyncedCalendarsUtil(db, clinicId) {
7597
- const calendarsRef = collection17(
7867
+ const calendarsRef = collection19(
7598
7868
  db,
7599
7869
  `clinics/${clinicId}/${SYNCED_CALENDARS_COLLECTION}`
7600
7870
  );
7601
- const q = query16(calendarsRef, orderBy7("createdAt", "desc"));
7602
- const querySnapshot = await getDocs16(q);
7603
- return querySnapshot.docs.map((doc26) => doc26.data());
7871
+ const q = query18(calendarsRef, orderBy8("createdAt", "desc"));
7872
+ const querySnapshot = await getDocs18(q);
7873
+ return querySnapshot.docs.map((doc27) => doc27.data());
7604
7874
  }
7605
7875
  async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendarId, updateData) {
7606
7876
  const calendarRef = getPractitionerSyncedCalendarDocRef(
@@ -7610,10 +7880,10 @@ async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendar
7610
7880
  );
7611
7881
  const updates = {
7612
7882
  ...updateData,
7613
- updatedAt: serverTimestamp18()
7883
+ updatedAt: serverTimestamp19()
7614
7884
  };
7615
- await updateDoc20(calendarRef, updates);
7616
- const updatedDoc = await getDoc22(calendarRef);
7885
+ await updateDoc21(calendarRef, updates);
7886
+ const updatedDoc = await getDoc23(calendarRef);
7617
7887
  if (!updatedDoc.exists()) {
7618
7888
  throw new Error("Synced calendar not found after update");
7619
7889
  }
@@ -7623,10 +7893,10 @@ async function updatePatientSyncedCalendarUtil(db, patientId, calendarId, update
7623
7893
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
7624
7894
  const updates = {
7625
7895
  ...updateData,
7626
- updatedAt: serverTimestamp18()
7896
+ updatedAt: serverTimestamp19()
7627
7897
  };
7628
- await updateDoc20(calendarRef, updates);
7629
- const updatedDoc = await getDoc22(calendarRef);
7898
+ await updateDoc21(calendarRef, updates);
7899
+ const updatedDoc = await getDoc23(calendarRef);
7630
7900
  if (!updatedDoc.exists()) {
7631
7901
  throw new Error("Synced calendar not found after update");
7632
7902
  }
@@ -7636,10 +7906,10 @@ async function updateClinicSyncedCalendarUtil(db, clinicId, calendarId, updateDa
7636
7906
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
7637
7907
  const updates = {
7638
7908
  ...updateData,
7639
- updatedAt: serverTimestamp18()
7909
+ updatedAt: serverTimestamp19()
7640
7910
  };
7641
- await updateDoc20(calendarRef, updates);
7642
- const updatedDoc = await getDoc22(calendarRef);
7911
+ await updateDoc21(calendarRef, updates);
7912
+ const updatedDoc = await getDoc23(calendarRef);
7643
7913
  if (!updatedDoc.exists()) {
7644
7914
  throw new Error("Synced calendar not found after update");
7645
7915
  }
@@ -7651,19 +7921,19 @@ async function deletePractitionerSyncedCalendarUtil(db, practitionerId, calendar
7651
7921
  practitionerId,
7652
7922
  calendarId
7653
7923
  );
7654
- await deleteDoc12(calendarRef);
7924
+ await deleteDoc13(calendarRef);
7655
7925
  }
7656
7926
  async function deletePatientSyncedCalendarUtil(db, patientId, calendarId) {
7657
7927
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
7658
- await deleteDoc12(calendarRef);
7928
+ await deleteDoc13(calendarRef);
7659
7929
  }
7660
7930
  async function deleteClinicSyncedCalendarUtil(db, clinicId, calendarId) {
7661
7931
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
7662
- await deleteDoc12(calendarRef);
7932
+ await deleteDoc13(calendarRef);
7663
7933
  }
7664
7934
  async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarId) {
7665
7935
  const updateData = {
7666
- lastSyncedAt: Timestamp22.now()
7936
+ lastSyncedAt: Timestamp23.now()
7667
7937
  };
7668
7938
  switch (entityType) {
7669
7939
  case "practitioner":
@@ -7693,7 +7963,7 @@ async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarI
7693
7963
  }
7694
7964
 
7695
7965
  // src/services/calendar/utils/google-calendar.utils.ts
7696
- import { Timestamp as Timestamp23 } from "firebase/firestore";
7966
+ import { Timestamp as Timestamp24 } from "firebase/firestore";
7697
7967
  var GOOGLE_CALENDAR_API_URL = "https://www.googleapis.com/calendar/v3";
7698
7968
  var GOOGLE_OAUTH_URL = "https://oauth2.googleapis.com/token";
7699
7969
  var CLIENT_ID = "your-client-id";
@@ -7813,7 +8083,7 @@ async function ensureValidToken(db, entityType, entityId, syncedCalendar) {
7813
8083
  tokenExpiry.setSeconds(tokenExpiry.getSeconds() + expiresIn);
7814
8084
  const updateData = {
7815
8085
  accessToken,
7816
- tokenExpiry: Timestamp23.fromDate(tokenExpiry)
8086
+ tokenExpiry: Timestamp24.fromDate(tokenExpiry)
7817
8087
  };
7818
8088
  switch (entityType) {
7819
8089
  case "practitioner":
@@ -7988,8 +8258,8 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
7988
8258
  eventName: googleEvent.summary || "External Event",
7989
8259
  eventLocation: googleEvent.location,
7990
8260
  eventTime: {
7991
- start: Timestamp23.fromDate(start),
7992
- end: Timestamp23.fromDate(end)
8261
+ start: Timestamp24.fromDate(start),
8262
+ end: Timestamp24.fromDate(end)
7993
8263
  },
7994
8264
  description: googleEvent.description || "",
7995
8265
  // External events are always set as CONFIRMED - status updates will happen externally
@@ -8003,7 +8273,7 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
8003
8273
  {
8004
8274
  eventId: googleEvent.id,
8005
8275
  syncedCalendarProvider: "google" /* GOOGLE */,
8006
- syncedAt: Timestamp23.now()
8276
+ syncedAt: Timestamp24.now()
8007
8277
  }
8008
8278
  ]
8009
8279
  };
@@ -8781,7 +9051,7 @@ var CalendarServiceV2 = class extends BaseService {
8781
9051
  return 0;
8782
9052
  }
8783
9053
  let importedEventsCount = 0;
8784
- const currentTime = Timestamp24.now();
9054
+ const currentTime = Timestamp25.now();
8785
9055
  for (const calendar of activeCalendars) {
8786
9056
  try {
8787
9057
  let externalEvents = [];
@@ -8848,7 +9118,7 @@ var CalendarServiceV2 = class extends BaseService {
8848
9118
  async createDoctorBlockingEvent(doctorId, eventData) {
8849
9119
  try {
8850
9120
  const eventId = this.generateId();
8851
- const eventRef = doc20(
9121
+ const eventRef = doc21(
8852
9122
  this.db,
8853
9123
  PRACTITIONERS_COLLECTION,
8854
9124
  doctorId,
@@ -8858,14 +9128,14 @@ var CalendarServiceV2 = class extends BaseService {
8858
9128
  const newEvent = {
8859
9129
  id: eventId,
8860
9130
  ...eventData,
8861
- createdAt: serverTimestamp19(),
8862
- updatedAt: serverTimestamp19()
9131
+ createdAt: serverTimestamp20(),
9132
+ updatedAt: serverTimestamp20()
8863
9133
  };
8864
- await setDoc20(eventRef, newEvent);
9134
+ await setDoc21(eventRef, newEvent);
8865
9135
  return {
8866
9136
  ...newEvent,
8867
- createdAt: Timestamp24.now(),
8868
- updatedAt: Timestamp24.now()
9137
+ createdAt: Timestamp25.now(),
9138
+ updatedAt: Timestamp25.now()
8869
9139
  };
8870
9140
  } catch (error) {
8871
9141
  console.error(
@@ -8883,8 +9153,8 @@ var CalendarServiceV2 = class extends BaseService {
8883
9153
  */
8884
9154
  async synchronizeExternalCalendars(lookbackDays = 7, lookforwardDays = 30) {
8885
9155
  try {
8886
- const practitionersRef = collection18(this.db, PRACTITIONERS_COLLECTION);
8887
- const practitionersSnapshot = await getDocs17(practitionersRef);
9156
+ const practitionersRef = collection20(this.db, PRACTITIONERS_COLLECTION);
9157
+ const practitionersSnapshot = await getDocs19(practitionersRef);
8888
9158
  const startDate = /* @__PURE__ */ new Date();
8889
9159
  startDate.setDate(startDate.getDate() - lookbackDays);
8890
9160
  const endDate = /* @__PURE__ */ new Date();
@@ -8942,22 +9212,22 @@ var CalendarServiceV2 = class extends BaseService {
8942
9212
  async updateExistingEventsFromExternalCalendars(doctorId, startDate, endDate) {
8943
9213
  var _a;
8944
9214
  try {
8945
- const eventsRef = collection18(
9215
+ const eventsRef = collection20(
8946
9216
  this.db,
8947
9217
  PRACTITIONERS_COLLECTION,
8948
9218
  doctorId,
8949
9219
  CALENDAR_COLLECTION
8950
9220
  );
8951
- const q = query17(
9221
+ const q = query19(
8952
9222
  eventsRef,
8953
- where17("syncStatus", "==", "external" /* EXTERNAL */),
8954
- where17("eventTime.start", ">=", Timestamp24.fromDate(startDate)),
8955
- where17("eventTime.start", "<=", Timestamp24.fromDate(endDate))
9223
+ where19("syncStatus", "==", "external" /* EXTERNAL */),
9224
+ where19("eventTime.start", ">=", Timestamp25.fromDate(startDate)),
9225
+ where19("eventTime.start", "<=", Timestamp25.fromDate(endDate))
8956
9226
  );
8957
- const eventsSnapshot = await getDocs17(q);
8958
- const events = eventsSnapshot.docs.map((doc26) => ({
8959
- id: doc26.id,
8960
- ...doc26.data()
9227
+ const eventsSnapshot = await getDocs19(q);
9228
+ const events = eventsSnapshot.docs.map((doc27) => ({
9229
+ id: doc27.id,
9230
+ ...doc27.data()
8961
9231
  }));
8962
9232
  const calendars = await this.syncedCalendarsService.getPractitionerSyncedCalendars(
8963
9233
  doctorId
@@ -9061,21 +9331,21 @@ var CalendarServiceV2 = class extends BaseService {
9061
9331
  const endTime = new Date(
9062
9332
  externalEvent.end.dateTime || externalEvent.end.date
9063
9333
  );
9064
- const eventRef = doc20(
9334
+ const eventRef = doc21(
9065
9335
  this.db,
9066
9336
  PRACTITIONERS_COLLECTION,
9067
9337
  doctorId,
9068
9338
  CALENDAR_COLLECTION,
9069
9339
  eventId
9070
9340
  );
9071
- await updateDoc21(eventRef, {
9341
+ await updateDoc22(eventRef, {
9072
9342
  eventName: externalEvent.summary || "External Event",
9073
9343
  eventTime: {
9074
- start: Timestamp24.fromDate(startTime),
9075
- end: Timestamp24.fromDate(endTime)
9344
+ start: Timestamp25.fromDate(startTime),
9345
+ end: Timestamp25.fromDate(endTime)
9076
9346
  },
9077
9347
  description: externalEvent.description || "",
9078
- updatedAt: serverTimestamp19()
9348
+ updatedAt: serverTimestamp20()
9079
9349
  });
9080
9350
  console.log(`Updated local event ${eventId} from external event`);
9081
9351
  } catch (error) {
@@ -9093,16 +9363,16 @@ var CalendarServiceV2 = class extends BaseService {
9093
9363
  */
9094
9364
  async updateEventStatus(doctorId, eventId, status) {
9095
9365
  try {
9096
- const eventRef = doc20(
9366
+ const eventRef = doc21(
9097
9367
  this.db,
9098
9368
  PRACTITIONERS_COLLECTION,
9099
9369
  doctorId,
9100
9370
  CALENDAR_COLLECTION,
9101
9371
  eventId
9102
9372
  );
9103
- await updateDoc21(eventRef, {
9373
+ await updateDoc22(eventRef, {
9104
9374
  status,
9105
- updatedAt: serverTimestamp19()
9375
+ updatedAt: serverTimestamp20()
9106
9376
  });
9107
9377
  console.log(`Updated event ${eventId} status to ${status}`);
9108
9378
  } catch (error) {
@@ -9120,6 +9390,102 @@ var CalendarServiceV2 = class extends BaseService {
9120
9390
  `Setting up scheduled calendar sync job every ${interval} hours`
9121
9391
  );
9122
9392
  }
9393
+ /**
9394
+ * Searches for calendar events based on specified criteria.
9395
+ *
9396
+ * @param {SearchCalendarEventsParams} params - The search parameters.
9397
+ * @param {SearchLocationEnum} params.searchLocation - The primary location to search (practitioner, patient, or clinic).
9398
+ * @param {string} params.entityId - The ID of the entity (practitioner, patient, or clinic) to search within/for.
9399
+ * @param {string} [params.clinicId] - Optional clinic ID to filter by.
9400
+ * @param {string} [params.practitionerId] - Optional practitioner ID to filter by.
9401
+ * @param {string} [params.patientId] - Optional patient ID to filter by.
9402
+ * @param {string} [params.procedureId] - Optional procedure ID to filter by.
9403
+ * @param {DateRange} [params.dateRange] - Optional date range to filter by (event start time).
9404
+ * @param {CalendarEventStatus} [params.eventStatus] - Optional event status to filter by.
9405
+ * @param {CalendarEventType} [params.eventType] - Optional event type to filter by.
9406
+ * @returns {Promise<CalendarEvent[]>} A promise that resolves to an array of matching calendar events.
9407
+ * @throws {Error} If the search location requires an entity ID that is not provided.
9408
+ */
9409
+ async searchCalendarEvents(params) {
9410
+ return searchCalendarEventsUtil(this.db, params);
9411
+ }
9412
+ /**
9413
+ * Gets a doctor's upcoming appointments for a specific date range
9414
+ *
9415
+ * @param {string} doctorId - ID of the practitioner
9416
+ * @param {Date} startDate - Start date of the range
9417
+ * @param {Date} endDate - End date of the range
9418
+ * @param {CalendarEventStatus} [status] - Optional status filter (defaults to CONFIRMED)
9419
+ * @returns {Promise<CalendarEvent[]>} A promise that resolves to an array of appointments
9420
+ */
9421
+ async getPractitionerUpcomingAppointments(doctorId, startDate, endDate, status = "confirmed" /* CONFIRMED */) {
9422
+ const dateRange = {
9423
+ start: Timestamp25.fromDate(startDate),
9424
+ end: Timestamp25.fromDate(endDate)
9425
+ };
9426
+ const searchParams = {
9427
+ searchLocation: "practitioner" /* PRACTITIONER */,
9428
+ entityId: doctorId,
9429
+ dateRange,
9430
+ eventStatus: status,
9431
+ eventType: "appointment" /* APPOINTMENT */
9432
+ };
9433
+ return this.searchCalendarEvents(searchParams);
9434
+ }
9435
+ /**
9436
+ * Gets a patient's appointments for a specific date range
9437
+ *
9438
+ * @param {string} patientId - ID of the patient
9439
+ * @param {Date} startDate - Start date of the range
9440
+ * @param {Date} endDate - End date of the range
9441
+ * @param {CalendarEventStatus} [status] - Optional status filter (defaults to all non-canceled appointments)
9442
+ * @returns {Promise<CalendarEvent[]>} A promise that resolves to an array of appointments
9443
+ */
9444
+ async getPatientAppointments(patientId, startDate, endDate, status) {
9445
+ const dateRange = {
9446
+ start: Timestamp25.fromDate(startDate),
9447
+ end: Timestamp25.fromDate(endDate)
9448
+ };
9449
+ const searchParams = {
9450
+ searchLocation: "patient" /* PATIENT */,
9451
+ entityId: patientId,
9452
+ dateRange,
9453
+ eventType: "appointment" /* APPOINTMENT */
9454
+ };
9455
+ if (status) {
9456
+ searchParams.eventStatus = status;
9457
+ }
9458
+ return this.searchCalendarEvents(searchParams);
9459
+ }
9460
+ /**
9461
+ * Gets all appointments for a clinic within a specific date range
9462
+ *
9463
+ * @param {string} clinicId - ID of the clinic
9464
+ * @param {Date} startDate - Start date of the range
9465
+ * @param {Date} endDate - End date of the range
9466
+ * @param {string} [doctorId] - Optional doctor ID to filter by
9467
+ * @param {CalendarEventStatus} [status] - Optional status filter
9468
+ * @returns {Promise<CalendarEvent[]>} A promise that resolves to an array of appointments
9469
+ */
9470
+ async getClinicAppointments(clinicId, startDate, endDate, doctorId, status) {
9471
+ const dateRange = {
9472
+ start: Timestamp25.fromDate(startDate),
9473
+ end: Timestamp25.fromDate(endDate)
9474
+ };
9475
+ const searchParams = {
9476
+ searchLocation: "clinic" /* CLINIC */,
9477
+ entityId: clinicId,
9478
+ dateRange,
9479
+ eventType: "appointment" /* APPOINTMENT */
9480
+ };
9481
+ if (doctorId) {
9482
+ searchParams.practitionerId = doctorId;
9483
+ }
9484
+ if (status) {
9485
+ searchParams.eventStatus = status;
9486
+ }
9487
+ return this.searchCalendarEvents(searchParams);
9488
+ }
9123
9489
  // #endregion
9124
9490
  // #region Private Helper Methods
9125
9491
  /**
@@ -9163,8 +9529,8 @@ var CalendarServiceV2 = class extends BaseService {
9163
9529
  const startDate = eventTime.start.toDate();
9164
9530
  const startTime = startDate;
9165
9531
  const endTime = eventTime.end.toDate();
9166
- const practitionerRef = doc20(this.db, PRACTITIONERS_COLLECTION, doctorId);
9167
- const practitionerDoc = await getDoc23(practitionerRef);
9532
+ const practitionerRef = doc21(this.db, PRACTITIONERS_COLLECTION, doctorId);
9533
+ const practitionerDoc = await getDoc24(practitionerRef);
9168
9534
  if (!practitionerDoc.exists()) {
9169
9535
  throw new Error(`Doctor with ID ${doctorId} not found`);
9170
9536
  }
@@ -9221,8 +9587,8 @@ var CalendarServiceV2 = class extends BaseService {
9221
9587
  * @returns Updated calendar event
9222
9588
  */
9223
9589
  async updateAppointmentStatus(appointmentId, clinicId, status) {
9224
- const appointmentRef = doc20(this.db, CALENDAR_COLLECTION, appointmentId);
9225
- const appointmentDoc = await getDoc23(appointmentRef);
9590
+ const appointmentRef = doc21(this.db, CALENDAR_COLLECTION, appointmentId);
9591
+ const appointmentDoc = await getDoc24(appointmentRef);
9226
9592
  if (!appointmentDoc.exists()) {
9227
9593
  throw new Error(`Appointment with ID ${appointmentId} not found`);
9228
9594
  }
@@ -9353,7 +9719,7 @@ var CalendarServiceV2 = class extends BaseService {
9353
9719
  const newSyncEvent = {
9354
9720
  eventId: result.eventIds[0],
9355
9721
  syncedCalendarProvider: calendar.provider,
9356
- syncedAt: Timestamp24.now()
9722
+ syncedAt: Timestamp25.now()
9357
9723
  };
9358
9724
  await this.updateEventWithSyncId(
9359
9725
  entityType === "doctor" ? appointment.practitionerProfileId : appointment.patientProfileId,
@@ -9377,8 +9743,8 @@ var CalendarServiceV2 = class extends BaseService {
9377
9743
  async updateEventWithSyncId(entityId, entityType, eventId, syncEvent) {
9378
9744
  try {
9379
9745
  const collectionPath = entityType === "doctor" ? `${PRACTITIONERS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}` : `${PATIENTS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
9380
- const eventRef = doc20(this.db, collectionPath, eventId);
9381
- const eventDoc = await getDoc23(eventRef);
9746
+ const eventRef = doc21(this.db, collectionPath, eventId);
9747
+ const eventDoc = await getDoc24(eventRef);
9382
9748
  if (eventDoc.exists()) {
9383
9749
  const event = eventDoc.data();
9384
9750
  const syncIds = [...event.syncedCalendarEventId || []];
@@ -9390,9 +9756,9 @@ var CalendarServiceV2 = class extends BaseService {
9390
9756
  } else {
9391
9757
  syncIds.push(syncEvent);
9392
9758
  }
9393
- await updateDoc21(eventRef, {
9759
+ await updateDoc22(eventRef, {
9394
9760
  syncedCalendarEventId: syncIds,
9395
- updatedAt: serverTimestamp19()
9761
+ updatedAt: serverTimestamp20()
9396
9762
  });
9397
9763
  console.log(
9398
9764
  `Updated event ${eventId} with sync ID ${syncEvent.eventId}`
@@ -9416,8 +9782,8 @@ var CalendarServiceV2 = class extends BaseService {
9416
9782
  * @returns Working hours for the clinic
9417
9783
  */
9418
9784
  async getClinicWorkingHours(clinicId, date) {
9419
- const clinicRef = doc20(this.db, CLINICS_COLLECTION, clinicId);
9420
- const clinicDoc = await getDoc23(clinicRef);
9785
+ const clinicRef = doc21(this.db, CLINICS_COLLECTION, clinicId);
9786
+ const clinicDoc = await getDoc24(clinicRef);
9421
9787
  if (!clinicDoc.exists()) {
9422
9788
  throw new Error(`Clinic with ID ${clinicId} not found`);
9423
9789
  }
@@ -9445,8 +9811,8 @@ var CalendarServiceV2 = class extends BaseService {
9445
9811
  * @returns Doctor's schedule
9446
9812
  */
9447
9813
  async getDoctorSchedule(doctorId, date) {
9448
- const practitionerRef = doc20(this.db, PRACTITIONERS_COLLECTION, doctorId);
9449
- const practitionerDoc = await getDoc23(practitionerRef);
9814
+ const practitionerRef = doc21(this.db, PRACTITIONERS_COLLECTION, doctorId);
9815
+ const practitionerDoc = await getDoc24(practitionerRef);
9450
9816
  if (!practitionerDoc.exists()) {
9451
9817
  throw new Error(`Doctor with ID ${doctorId} not found`);
9452
9818
  }
@@ -9478,19 +9844,19 @@ var CalendarServiceV2 = class extends BaseService {
9478
9844
  startOfDay.setHours(0, 0, 0, 0);
9479
9845
  const endOfDay = new Date(date);
9480
9846
  endOfDay.setHours(23, 59, 59, 999);
9481
- const appointmentsRef = collection18(this.db, CALENDAR_COLLECTION);
9482
- const q = query17(
9847
+ const appointmentsRef = collection20(this.db, CALENDAR_COLLECTION);
9848
+ const q = query19(
9483
9849
  appointmentsRef,
9484
- where17("practitionerProfileId", "==", doctorId),
9485
- where17("eventTime.start", ">=", Timestamp24.fromDate(startOfDay)),
9486
- where17("eventTime.start", "<=", Timestamp24.fromDate(endOfDay)),
9487
- where17("status", "in", [
9850
+ where19("practitionerProfileId", "==", doctorId),
9851
+ where19("eventTime.start", ">=", Timestamp25.fromDate(startOfDay)),
9852
+ where19("eventTime.start", "<=", Timestamp25.fromDate(endOfDay)),
9853
+ where19("status", "in", [
9488
9854
  "confirmed" /* CONFIRMED */,
9489
9855
  "pending" /* PENDING */
9490
9856
  ])
9491
9857
  );
9492
- const querySnapshot = await getDocs17(q);
9493
- return querySnapshot.docs.map((doc26) => doc26.data());
9858
+ const querySnapshot = await getDocs19(q);
9859
+ return querySnapshot.docs.map((doc27) => doc27.data());
9494
9860
  }
9495
9861
  /**
9496
9862
  * Calculates available time slots based on working hours, schedule and existing appointments
@@ -9547,11 +9913,11 @@ var CalendarServiceV2 = class extends BaseService {
9547
9913
  var _a;
9548
9914
  try {
9549
9915
  const [clinicDoc, practitionerDoc, patientDoc, patientSensitiveInfoDoc] = await Promise.all([
9550
- getDoc23(doc20(this.db, CLINICS_COLLECTION, clinicId)),
9551
- getDoc23(doc20(this.db, PRACTITIONERS_COLLECTION, doctorId)),
9552
- getDoc23(doc20(this.db, PATIENTS_COLLECTION, patientId)),
9553
- getDoc23(
9554
- doc20(
9916
+ getDoc24(doc21(this.db, CLINICS_COLLECTION, clinicId)),
9917
+ getDoc24(doc21(this.db, PRACTITIONERS_COLLECTION, doctorId)),
9918
+ getDoc24(doc21(this.db, PATIENTS_COLLECTION, patientId)),
9919
+ getDoc24(
9920
+ doc21(
9555
9921
  this.db,
9556
9922
  PATIENTS_COLLECTION,
9557
9923
  patientId,
@@ -9584,7 +9950,7 @@ var CalendarServiceV2 = class extends BaseService {
9584
9950
  fullName: `${sensitiveData.firstName} ${sensitiveData.lastName}`,
9585
9951
  email: sensitiveData.email || "",
9586
9952
  phone: sensitiveData.phoneNumber || null,
9587
- dateOfBirth: sensitiveData.dateOfBirth || Timestamp24.now(),
9953
+ dateOfBirth: sensitiveData.dateOfBirth || Timestamp25.now(),
9588
9954
  gender: sensitiveData.gender || "other" /* OTHER */
9589
9955
  };
9590
9956
  } else if (patientDoc.exists()) {
@@ -9593,7 +9959,7 @@ var CalendarServiceV2 = class extends BaseService {
9593
9959
  fullName: patientDoc.data().displayName,
9594
9960
  email: ((_a = patientDoc.data().contactInfo) == null ? void 0 : _a.email) || "",
9595
9961
  phone: patientDoc.data().phoneNumber || null,
9596
- dateOfBirth: patientDoc.data().dateOfBirth || Timestamp24.now(),
9962
+ dateOfBirth: patientDoc.data().dateOfBirth || Timestamp25.now(),
9597
9963
  gender: patientDoc.data().gender || "other" /* OTHER */
9598
9964
  };
9599
9965
  }
@@ -9617,13 +9983,13 @@ var CalendarServiceV2 = class extends BaseService {
9617
9983
  // src/backoffice/services/brand.service.ts
9618
9984
  import {
9619
9985
  addDoc as addDoc4,
9620
- collection as collection19,
9621
- doc as doc21,
9622
- getDoc as getDoc24,
9623
- getDocs as getDocs18,
9624
- query as query18,
9625
- updateDoc as updateDoc22,
9626
- where as where18
9986
+ collection as collection21,
9987
+ doc as doc22,
9988
+ getDoc as getDoc25,
9989
+ getDocs as getDocs20,
9990
+ query as query20,
9991
+ updateDoc as updateDoc23,
9992
+ where as where20
9627
9993
  } from "firebase/firestore";
9628
9994
 
9629
9995
  // src/backoffice/types/brand.types.ts
@@ -9635,7 +10001,7 @@ var BrandService = class extends BaseService {
9635
10001
  * Gets reference to brands collection
9636
10002
  */
9637
10003
  getBrandsRef() {
9638
- return collection19(this.db, BRANDS_COLLECTION);
10004
+ return collection21(this.db, BRANDS_COLLECTION);
9639
10005
  }
9640
10006
  /**
9641
10007
  * Creates a new brand
@@ -9655,12 +10021,12 @@ var BrandService = class extends BaseService {
9655
10021
  * Gets all active brands
9656
10022
  */
9657
10023
  async getAll() {
9658
- const q = query18(this.getBrandsRef(), where18("isActive", "==", true));
9659
- const snapshot = await getDocs18(q);
10024
+ const q = query20(this.getBrandsRef(), where20("isActive", "==", true));
10025
+ const snapshot = await getDocs20(q);
9660
10026
  return snapshot.docs.map(
9661
- (doc26) => ({
9662
- id: doc26.id,
9663
- ...doc26.data()
10027
+ (doc27) => ({
10028
+ id: doc27.id,
10029
+ ...doc27.data()
9664
10030
  })
9665
10031
  );
9666
10032
  }
@@ -9672,8 +10038,8 @@ var BrandService = class extends BaseService {
9672
10038
  ...brand,
9673
10039
  updatedAt: /* @__PURE__ */ new Date()
9674
10040
  };
9675
- const docRef = doc21(this.getBrandsRef(), brandId);
9676
- await updateDoc22(docRef, updateData);
10041
+ const docRef = doc22(this.getBrandsRef(), brandId);
10042
+ await updateDoc23(docRef, updateData);
9677
10043
  return this.getById(brandId);
9678
10044
  }
9679
10045
  /**
@@ -9688,8 +10054,8 @@ var BrandService = class extends BaseService {
9688
10054
  * Gets a brand by ID
9689
10055
  */
9690
10056
  async getById(brandId) {
9691
- const docRef = doc21(this.getBrandsRef(), brandId);
9692
- const docSnap = await getDoc24(docRef);
10057
+ const docRef = doc22(this.getBrandsRef(), brandId);
10058
+ const docSnap = await getDoc25(docRef);
9693
10059
  if (!docSnap.exists()) return null;
9694
10060
  return {
9695
10061
  id: docSnap.id,
@@ -9701,13 +10067,13 @@ var BrandService = class extends BaseService {
9701
10067
  // src/backoffice/services/category.service.ts
9702
10068
  import {
9703
10069
  addDoc as addDoc5,
9704
- collection as collection20,
9705
- doc as doc22,
9706
- getDoc as getDoc25,
9707
- getDocs as getDocs19,
9708
- query as query19,
9709
- updateDoc as updateDoc23,
9710
- where as where19
10070
+ collection as collection22,
10071
+ doc as doc23,
10072
+ getDoc as getDoc26,
10073
+ getDocs as getDocs21,
10074
+ query as query21,
10075
+ updateDoc as updateDoc24,
10076
+ where as where21
9711
10077
  } from "firebase/firestore";
9712
10078
 
9713
10079
  // src/backoffice/types/category.types.ts
@@ -9719,7 +10085,7 @@ var CategoryService = class extends BaseService {
9719
10085
  * Referenca na Firestore kolekciju kategorija
9720
10086
  */
9721
10087
  get categoriesRef() {
9722
- return collection20(this.db, CATEGORIES_COLLECTION);
10088
+ return collection22(this.db, CATEGORIES_COLLECTION);
9723
10089
  }
9724
10090
  /**
9725
10091
  * Kreira novu kategoriju u sistemu
@@ -9742,12 +10108,12 @@ var CategoryService = class extends BaseService {
9742
10108
  * @returns Lista aktivnih kategorija
9743
10109
  */
9744
10110
  async getAll() {
9745
- const q = query19(this.categoriesRef, where19("isActive", "==", true));
9746
- const snapshot = await getDocs19(q);
10111
+ const q = query21(this.categoriesRef, where21("isActive", "==", true));
10112
+ const snapshot = await getDocs21(q);
9747
10113
  return snapshot.docs.map(
9748
- (doc26) => ({
9749
- id: doc26.id,
9750
- ...doc26.data()
10114
+ (doc27) => ({
10115
+ id: doc27.id,
10116
+ ...doc27.data()
9751
10117
  })
9752
10118
  );
9753
10119
  }
@@ -9757,16 +10123,16 @@ var CategoryService = class extends BaseService {
9757
10123
  * @returns Lista kategorija koje pripadaju traženoj familiji
9758
10124
  */
9759
10125
  async getAllByFamily(family) {
9760
- const q = query19(
10126
+ const q = query21(
9761
10127
  this.categoriesRef,
9762
- where19("family", "==", family),
9763
- where19("isActive", "==", true)
10128
+ where21("family", "==", family),
10129
+ where21("isActive", "==", true)
9764
10130
  );
9765
- const snapshot = await getDocs19(q);
10131
+ const snapshot = await getDocs21(q);
9766
10132
  return snapshot.docs.map(
9767
- (doc26) => ({
9768
- id: doc26.id,
9769
- ...doc26.data()
10133
+ (doc27) => ({
10134
+ id: doc27.id,
10135
+ ...doc27.data()
9770
10136
  })
9771
10137
  );
9772
10138
  }
@@ -9781,8 +10147,8 @@ var CategoryService = class extends BaseService {
9781
10147
  ...category,
9782
10148
  updatedAt: /* @__PURE__ */ new Date()
9783
10149
  };
9784
- const docRef = doc22(this.categoriesRef, id);
9785
- await updateDoc23(docRef, updateData);
10150
+ const docRef = doc23(this.categoriesRef, id);
10151
+ await updateDoc24(docRef, updateData);
9786
10152
  return this.getById(id);
9787
10153
  }
9788
10154
  /**
@@ -9798,8 +10164,8 @@ var CategoryService = class extends BaseService {
9798
10164
  * @returns Kategorija ili null ako ne postoji
9799
10165
  */
9800
10166
  async getById(id) {
9801
- const docRef = doc22(this.categoriesRef, id);
9802
- const docSnap = await getDoc25(docRef);
10167
+ const docRef = doc23(this.categoriesRef, id);
10168
+ const docSnap = await getDoc26(docRef);
9803
10169
  if (!docSnap.exists()) return null;
9804
10170
  return {
9805
10171
  id: docSnap.id,
@@ -9811,13 +10177,13 @@ var CategoryService = class extends BaseService {
9811
10177
  // src/backoffice/services/subcategory.service.ts
9812
10178
  import {
9813
10179
  addDoc as addDoc6,
9814
- collection as collection21,
9815
- doc as doc23,
9816
- getDoc as getDoc26,
9817
- getDocs as getDocs20,
9818
- query as query20,
9819
- updateDoc as updateDoc24,
9820
- where as where20
10180
+ collection as collection23,
10181
+ doc as doc24,
10182
+ getDoc as getDoc27,
10183
+ getDocs as getDocs22,
10184
+ query as query22,
10185
+ updateDoc as updateDoc25,
10186
+ where as where22
9821
10187
  } from "firebase/firestore";
9822
10188
 
9823
10189
  // src/backoffice/types/subcategory.types.ts
@@ -9830,7 +10196,7 @@ var SubcategoryService = class extends BaseService {
9830
10196
  * @param categoryId - ID roditeljske kategorije
9831
10197
  */
9832
10198
  getSubcategoriesRef(categoryId) {
9833
- return collection21(
10199
+ return collection23(
9834
10200
  this.db,
9835
10201
  CATEGORIES_COLLECTION,
9836
10202
  categoryId,
@@ -9864,15 +10230,15 @@ var SubcategoryService = class extends BaseService {
9864
10230
  * @returns Lista aktivnih podkategorija
9865
10231
  */
9866
10232
  async getAllByCategoryId(categoryId) {
9867
- const q = query20(
10233
+ const q = query22(
9868
10234
  this.getSubcategoriesRef(categoryId),
9869
- where20("isActive", "==", true)
10235
+ where22("isActive", "==", true)
9870
10236
  );
9871
- const snapshot = await getDocs20(q);
10237
+ const snapshot = await getDocs22(q);
9872
10238
  return snapshot.docs.map(
9873
- (doc26) => ({
9874
- id: doc26.id,
9875
- ...doc26.data()
10239
+ (doc27) => ({
10240
+ id: doc27.id,
10241
+ ...doc27.data()
9876
10242
  })
9877
10243
  );
9878
10244
  }
@@ -9888,8 +10254,8 @@ var SubcategoryService = class extends BaseService {
9888
10254
  ...subcategory,
9889
10255
  updatedAt: /* @__PURE__ */ new Date()
9890
10256
  };
9891
- const docRef = doc23(this.getSubcategoriesRef(categoryId), subcategoryId);
9892
- await updateDoc24(docRef, updateData);
10257
+ const docRef = doc24(this.getSubcategoriesRef(categoryId), subcategoryId);
10258
+ await updateDoc25(docRef, updateData);
9893
10259
  return this.getById(categoryId, subcategoryId);
9894
10260
  }
9895
10261
  /**
@@ -9907,8 +10273,8 @@ var SubcategoryService = class extends BaseService {
9907
10273
  * @returns Podkategorija ili null ako ne postoji
9908
10274
  */
9909
10275
  async getById(categoryId, subcategoryId) {
9910
- const docRef = doc23(this.getSubcategoriesRef(categoryId), subcategoryId);
9911
- const docSnap = await getDoc26(docRef);
10276
+ const docRef = doc24(this.getSubcategoriesRef(categoryId), subcategoryId);
10277
+ const docSnap = await getDoc27(docRef);
9912
10278
  if (!docSnap.exists()) return null;
9913
10279
  return {
9914
10280
  id: docSnap.id,
@@ -9920,15 +10286,15 @@ var SubcategoryService = class extends BaseService {
9920
10286
  // src/backoffice/services/technology.service.ts
9921
10287
  import {
9922
10288
  addDoc as addDoc7,
9923
- collection as collection22,
9924
- doc as doc24,
9925
- getDoc as getDoc27,
9926
- getDocs as getDocs21,
9927
- query as query21,
9928
- updateDoc as updateDoc25,
9929
- where as where21,
10289
+ collection as collection24,
10290
+ doc as doc25,
10291
+ getDoc as getDoc28,
10292
+ getDocs as getDocs23,
10293
+ query as query23,
10294
+ updateDoc as updateDoc26,
10295
+ where as where23,
9930
10296
  arrayUnion as arrayUnion5,
9931
- arrayRemove as arrayRemove3
10297
+ arrayRemove as arrayRemove4
9932
10298
  } from "firebase/firestore";
9933
10299
 
9934
10300
  // src/backoffice/types/technology.types.ts
@@ -9944,7 +10310,7 @@ var TechnologyService = class extends BaseService {
9944
10310
  * Vraća referencu na Firestore kolekciju tehnologija
9945
10311
  */
9946
10312
  getTechnologiesRef() {
9947
- return collection22(this.db, TECHNOLOGIES_COLLECTION);
10313
+ return collection24(this.db, TECHNOLOGIES_COLLECTION);
9948
10314
  }
9949
10315
  /**
9950
10316
  * Kreira novu tehnologiju
@@ -9975,12 +10341,12 @@ var TechnologyService = class extends BaseService {
9975
10341
  * @returns Lista aktivnih tehnologija
9976
10342
  */
9977
10343
  async getAll() {
9978
- const q = query21(this.getTechnologiesRef(), where21("isActive", "==", true));
9979
- const snapshot = await getDocs21(q);
10344
+ const q = query23(this.getTechnologiesRef(), where23("isActive", "==", true));
10345
+ const snapshot = await getDocs23(q);
9980
10346
  return snapshot.docs.map(
9981
- (doc26) => ({
9982
- id: doc26.id,
9983
- ...doc26.data()
10347
+ (doc27) => ({
10348
+ id: doc27.id,
10349
+ ...doc27.data()
9984
10350
  })
9985
10351
  );
9986
10352
  }
@@ -9990,16 +10356,16 @@ var TechnologyService = class extends BaseService {
9990
10356
  * @returns Lista aktivnih tehnologija
9991
10357
  */
9992
10358
  async getAllByFamily(family) {
9993
- const q = query21(
10359
+ const q = query23(
9994
10360
  this.getTechnologiesRef(),
9995
- where21("isActive", "==", true),
9996
- where21("family", "==", family)
10361
+ where23("isActive", "==", true),
10362
+ where23("family", "==", family)
9997
10363
  );
9998
- const snapshot = await getDocs21(q);
10364
+ const snapshot = await getDocs23(q);
9999
10365
  return snapshot.docs.map(
10000
- (doc26) => ({
10001
- id: doc26.id,
10002
- ...doc26.data()
10366
+ (doc27) => ({
10367
+ id: doc27.id,
10368
+ ...doc27.data()
10003
10369
  })
10004
10370
  );
10005
10371
  }
@@ -10009,16 +10375,16 @@ var TechnologyService = class extends BaseService {
10009
10375
  * @returns Lista aktivnih tehnologija
10010
10376
  */
10011
10377
  async getAllByCategoryId(categoryId) {
10012
- const q = query21(
10378
+ const q = query23(
10013
10379
  this.getTechnologiesRef(),
10014
- where21("isActive", "==", true),
10015
- where21("categoryId", "==", categoryId)
10380
+ where23("isActive", "==", true),
10381
+ where23("categoryId", "==", categoryId)
10016
10382
  );
10017
- const snapshot = await getDocs21(q);
10383
+ const snapshot = await getDocs23(q);
10018
10384
  return snapshot.docs.map(
10019
- (doc26) => ({
10020
- id: doc26.id,
10021
- ...doc26.data()
10385
+ (doc27) => ({
10386
+ id: doc27.id,
10387
+ ...doc27.data()
10022
10388
  })
10023
10389
  );
10024
10390
  }
@@ -10028,16 +10394,16 @@ var TechnologyService = class extends BaseService {
10028
10394
  * @returns Lista aktivnih tehnologija
10029
10395
  */
10030
10396
  async getAllBySubcategoryId(subcategoryId) {
10031
- const q = query21(
10397
+ const q = query23(
10032
10398
  this.getTechnologiesRef(),
10033
- where21("isActive", "==", true),
10034
- where21("subcategoryId", "==", subcategoryId)
10399
+ where23("isActive", "==", true),
10400
+ where23("subcategoryId", "==", subcategoryId)
10035
10401
  );
10036
- const snapshot = await getDocs21(q);
10402
+ const snapshot = await getDocs23(q);
10037
10403
  return snapshot.docs.map(
10038
- (doc26) => ({
10039
- id: doc26.id,
10040
- ...doc26.data()
10404
+ (doc27) => ({
10405
+ id: doc27.id,
10406
+ ...doc27.data()
10041
10407
  })
10042
10408
  );
10043
10409
  }
@@ -10052,8 +10418,8 @@ var TechnologyService = class extends BaseService {
10052
10418
  ...technology,
10053
10419
  updatedAt: /* @__PURE__ */ new Date()
10054
10420
  };
10055
- const docRef = doc24(this.getTechnologiesRef(), technologyId);
10056
- await updateDoc25(docRef, updateData);
10421
+ const docRef = doc25(this.getTechnologiesRef(), technologyId);
10422
+ await updateDoc26(docRef, updateData);
10057
10423
  return this.getById(technologyId);
10058
10424
  }
10059
10425
  /**
@@ -10071,8 +10437,8 @@ var TechnologyService = class extends BaseService {
10071
10437
  * @returns Tehnologija ili null ako ne postoji
10072
10438
  */
10073
10439
  async getById(technologyId) {
10074
- const docRef = doc24(this.getTechnologiesRef(), technologyId);
10075
- const docSnap = await getDoc27(docRef);
10440
+ const docRef = doc25(this.getTechnologiesRef(), technologyId);
10441
+ const docSnap = await getDoc28(docRef);
10076
10442
  if (!docSnap.exists()) return null;
10077
10443
  return {
10078
10444
  id: docSnap.id,
@@ -10086,9 +10452,9 @@ var TechnologyService = class extends BaseService {
10086
10452
  * @returns Ažurirana tehnologija sa novim zahtevom
10087
10453
  */
10088
10454
  async addRequirement(technologyId, requirement) {
10089
- const docRef = doc24(this.getTechnologiesRef(), technologyId);
10455
+ const docRef = doc25(this.getTechnologiesRef(), technologyId);
10090
10456
  const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
10091
- await updateDoc25(docRef, {
10457
+ await updateDoc26(docRef, {
10092
10458
  [requirementType]: arrayUnion5(requirement),
10093
10459
  updatedAt: /* @__PURE__ */ new Date()
10094
10460
  });
@@ -10101,10 +10467,10 @@ var TechnologyService = class extends BaseService {
10101
10467
  * @returns Ažurirana tehnologija bez uklonjenog zahteva
10102
10468
  */
10103
10469
  async removeRequirement(technologyId, requirement) {
10104
- const docRef = doc24(this.getTechnologiesRef(), technologyId);
10470
+ const docRef = doc25(this.getTechnologiesRef(), technologyId);
10105
10471
  const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
10106
- await updateDoc25(docRef, {
10107
- [requirementType]: arrayRemove3(requirement),
10472
+ await updateDoc26(docRef, {
10473
+ [requirementType]: arrayRemove4(requirement),
10108
10474
  updatedAt: /* @__PURE__ */ new Date()
10109
10475
  });
10110
10476
  return this.getById(technologyId);
@@ -10141,8 +10507,8 @@ var TechnologyService = class extends BaseService {
10141
10507
  * @returns Ažurirana tehnologija
10142
10508
  */
10143
10509
  async addBlockingCondition(technologyId, condition) {
10144
- const docRef = doc24(this.getTechnologiesRef(), technologyId);
10145
- await updateDoc25(docRef, {
10510
+ const docRef = doc25(this.getTechnologiesRef(), technologyId);
10511
+ await updateDoc26(docRef, {
10146
10512
  blockingConditions: arrayUnion5(condition),
10147
10513
  updatedAt: /* @__PURE__ */ new Date()
10148
10514
  });
@@ -10155,9 +10521,9 @@ var TechnologyService = class extends BaseService {
10155
10521
  * @returns Ažurirana tehnologija
10156
10522
  */
10157
10523
  async removeBlockingCondition(technologyId, condition) {
10158
- const docRef = doc24(this.getTechnologiesRef(), technologyId);
10159
- await updateDoc25(docRef, {
10160
- blockingConditions: arrayRemove3(condition),
10524
+ const docRef = doc25(this.getTechnologiesRef(), technologyId);
10525
+ await updateDoc26(docRef, {
10526
+ blockingConditions: arrayRemove4(condition),
10161
10527
  updatedAt: /* @__PURE__ */ new Date()
10162
10528
  });
10163
10529
  return this.getById(technologyId);
@@ -10169,8 +10535,8 @@ var TechnologyService = class extends BaseService {
10169
10535
  * @returns Ažurirana tehnologija
10170
10536
  */
10171
10537
  async addContraindication(technologyId, contraindication) {
10172
- const docRef = doc24(this.getTechnologiesRef(), technologyId);
10173
- await updateDoc25(docRef, {
10538
+ const docRef = doc25(this.getTechnologiesRef(), technologyId);
10539
+ await updateDoc26(docRef, {
10174
10540
  contraindications: arrayUnion5(contraindication),
10175
10541
  updatedAt: /* @__PURE__ */ new Date()
10176
10542
  });
@@ -10183,9 +10549,9 @@ var TechnologyService = class extends BaseService {
10183
10549
  * @returns Ažurirana tehnologija
10184
10550
  */
10185
10551
  async removeContraindication(technologyId, contraindication) {
10186
- const docRef = doc24(this.getTechnologiesRef(), technologyId);
10187
- await updateDoc25(docRef, {
10188
- contraindications: arrayRemove3(contraindication),
10552
+ const docRef = doc25(this.getTechnologiesRef(), technologyId);
10553
+ await updateDoc26(docRef, {
10554
+ contraindications: arrayRemove4(contraindication),
10189
10555
  updatedAt: /* @__PURE__ */ new Date()
10190
10556
  });
10191
10557
  return this.getById(technologyId);
@@ -10197,8 +10563,8 @@ var TechnologyService = class extends BaseService {
10197
10563
  * @returns Ažurirana tehnologija
10198
10564
  */
10199
10565
  async addBenefit(technologyId, benefit) {
10200
- const docRef = doc24(this.getTechnologiesRef(), technologyId);
10201
- await updateDoc25(docRef, {
10566
+ const docRef = doc25(this.getTechnologiesRef(), technologyId);
10567
+ await updateDoc26(docRef, {
10202
10568
  benefits: arrayUnion5(benefit),
10203
10569
  updatedAt: /* @__PURE__ */ new Date()
10204
10570
  });
@@ -10211,9 +10577,9 @@ var TechnologyService = class extends BaseService {
10211
10577
  * @returns Ažurirana tehnologija
10212
10578
  */
10213
10579
  async removeBenefit(technologyId, benefit) {
10214
- const docRef = doc24(this.getTechnologiesRef(), technologyId);
10215
- await updateDoc25(docRef, {
10216
- benefits: arrayRemove3(benefit),
10580
+ const docRef = doc25(this.getTechnologiesRef(), technologyId);
10581
+ await updateDoc26(docRef, {
10582
+ benefits: arrayRemove4(benefit),
10217
10583
  updatedAt: /* @__PURE__ */ new Date()
10218
10584
  });
10219
10585
  return this.getById(technologyId);
@@ -10252,8 +10618,8 @@ var TechnologyService = class extends BaseService {
10252
10618
  * @returns Ažurirana tehnologija
10253
10619
  */
10254
10620
  async updateCertificationRequirement(technologyId, certificationRequirement) {
10255
- const docRef = doc24(this.getTechnologiesRef(), technologyId);
10256
- await updateDoc25(docRef, {
10621
+ const docRef = doc25(this.getTechnologiesRef(), technologyId);
10622
+ await updateDoc26(docRef, {
10257
10623
  certificationRequirement,
10258
10624
  updatedAt: /* @__PURE__ */ new Date()
10259
10625
  });
@@ -10355,13 +10721,13 @@ var TechnologyService = class extends BaseService {
10355
10721
  // src/backoffice/services/product.service.ts
10356
10722
  import {
10357
10723
  addDoc as addDoc8,
10358
- collection as collection23,
10359
- doc as doc25,
10360
- getDoc as getDoc28,
10361
- getDocs as getDocs22,
10362
- query as query22,
10363
- updateDoc as updateDoc26,
10364
- where as where22
10724
+ collection as collection25,
10725
+ doc as doc26,
10726
+ getDoc as getDoc29,
10727
+ getDocs as getDocs24,
10728
+ query as query24,
10729
+ updateDoc as updateDoc27,
10730
+ where as where24
10365
10731
  } from "firebase/firestore";
10366
10732
 
10367
10733
  // src/backoffice/types/product.types.ts
@@ -10375,7 +10741,7 @@ var ProductService = class extends BaseService {
10375
10741
  * @returns Firestore collection reference
10376
10742
  */
10377
10743
  getProductsRef(technologyId) {
10378
- return collection23(
10744
+ return collection25(
10379
10745
  this.db,
10380
10746
  TECHNOLOGIES_COLLECTION,
10381
10747
  technologyId,
@@ -10405,15 +10771,15 @@ var ProductService = class extends BaseService {
10405
10771
  * Gets all products for a technology
10406
10772
  */
10407
10773
  async getAllByTechnology(technologyId) {
10408
- const q = query22(
10774
+ const q = query24(
10409
10775
  this.getProductsRef(technologyId),
10410
- where22("isActive", "==", true)
10776
+ where24("isActive", "==", true)
10411
10777
  );
10412
- const snapshot = await getDocs22(q);
10778
+ const snapshot = await getDocs24(q);
10413
10779
  return snapshot.docs.map(
10414
- (doc26) => ({
10415
- id: doc26.id,
10416
- ...doc26.data()
10780
+ (doc27) => ({
10781
+ id: doc27.id,
10782
+ ...doc27.data()
10417
10783
  })
10418
10784
  );
10419
10785
  }
@@ -10421,21 +10787,21 @@ var ProductService = class extends BaseService {
10421
10787
  * Gets all products for a brand by filtering through all technologies
10422
10788
  */
10423
10789
  async getAllByBrand(brandId) {
10424
- const allTechnologiesRef = collection23(this.db, TECHNOLOGIES_COLLECTION);
10425
- const technologiesSnapshot = await getDocs22(allTechnologiesRef);
10790
+ const allTechnologiesRef = collection25(this.db, TECHNOLOGIES_COLLECTION);
10791
+ const technologiesSnapshot = await getDocs24(allTechnologiesRef);
10426
10792
  const products = [];
10427
10793
  for (const techDoc of technologiesSnapshot.docs) {
10428
- const q = query22(
10794
+ const q = query24(
10429
10795
  this.getProductsRef(techDoc.id),
10430
- where22("brandId", "==", brandId),
10431
- where22("isActive", "==", true)
10796
+ where24("brandId", "==", brandId),
10797
+ where24("isActive", "==", true)
10432
10798
  );
10433
- const snapshot = await getDocs22(q);
10799
+ const snapshot = await getDocs24(q);
10434
10800
  products.push(
10435
10801
  ...snapshot.docs.map(
10436
- (doc26) => ({
10437
- id: doc26.id,
10438
- ...doc26.data()
10802
+ (doc27) => ({
10803
+ id: doc27.id,
10804
+ ...doc27.data()
10439
10805
  })
10440
10806
  )
10441
10807
  );
@@ -10450,8 +10816,8 @@ var ProductService = class extends BaseService {
10450
10816
  ...product,
10451
10817
  updatedAt: /* @__PURE__ */ new Date()
10452
10818
  };
10453
- const docRef = doc25(this.getProductsRef(technologyId), productId);
10454
- await updateDoc26(docRef, updateData);
10819
+ const docRef = doc26(this.getProductsRef(technologyId), productId);
10820
+ await updateDoc27(docRef, updateData);
10455
10821
  return this.getById(technologyId, productId);
10456
10822
  }
10457
10823
  /**
@@ -10466,8 +10832,8 @@ var ProductService = class extends BaseService {
10466
10832
  * Gets a product by ID
10467
10833
  */
10468
10834
  async getById(technologyId, productId) {
10469
- const docRef = doc25(this.getProductsRef(technologyId), productId);
10470
- const docSnap = await getDoc28(docRef);
10835
+ const docRef = doc26(this.getProductsRef(technologyId), productId);
10836
+ const docSnap = await getDoc29(docRef);
10471
10837
  if (!docSnap.exists()) return null;
10472
10838
  return {
10473
10839
  id: docSnap.id,
@@ -10682,7 +11048,9 @@ export {
10682
11048
  preRequirementNotificationSchema,
10683
11049
  procedureCategorizationSchema,
10684
11050
  procedureInfoSchema,
11051
+ requesterInfoSchema,
10685
11052
  reviewInfoSchema,
11053
+ searchPatientsSchema,
10686
11054
  serviceInfoSchema,
10687
11055
  syncedCalendarEventSchema,
10688
11056
  timeSlotSchema2 as timeSlotSchema,