@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.js CHANGED
@@ -171,7 +171,9 @@ __export(index_exports, {
171
171
  preRequirementNotificationSchema: () => preRequirementNotificationSchema,
172
172
  procedureCategorizationSchema: () => procedureCategorizationSchema,
173
173
  procedureInfoSchema: () => procedureInfoSchema,
174
+ requesterInfoSchema: () => requesterInfoSchema,
174
175
  reviewInfoSchema: () => reviewInfoSchema,
176
+ searchPatientsSchema: () => searchPatientsSchema,
175
177
  serviceInfoSchema: () => serviceInfoSchema,
176
178
  syncedCalendarEventSchema: () => syncedCalendarEventSchema,
177
179
  timeSlotSchema: () => timeSlotSchema2,
@@ -290,27 +292,27 @@ var FilledDocumentStatus = /* @__PURE__ */ ((FilledDocumentStatus2) => {
290
292
  })(FilledDocumentStatus || {});
291
293
 
292
294
  // src/types/calendar/index.ts
293
- var CalendarEventStatus = /* @__PURE__ */ ((CalendarEventStatus3) => {
294
- CalendarEventStatus3["PENDING"] = "pending";
295
- CalendarEventStatus3["CONFIRMED"] = "confirmed";
296
- CalendarEventStatus3["REJECTED"] = "rejected";
297
- CalendarEventStatus3["CANCELED"] = "canceled";
298
- CalendarEventStatus3["RESCHEDULED"] = "rescheduled";
299
- CalendarEventStatus3["COMPLETED"] = "completed";
300
- return CalendarEventStatus3;
295
+ var CalendarEventStatus = /* @__PURE__ */ ((CalendarEventStatus4) => {
296
+ CalendarEventStatus4["PENDING"] = "pending";
297
+ CalendarEventStatus4["CONFIRMED"] = "confirmed";
298
+ CalendarEventStatus4["REJECTED"] = "rejected";
299
+ CalendarEventStatus4["CANCELED"] = "canceled";
300
+ CalendarEventStatus4["RESCHEDULED"] = "rescheduled";
301
+ CalendarEventStatus4["COMPLETED"] = "completed";
302
+ return CalendarEventStatus4;
301
303
  })(CalendarEventStatus || {});
302
- var CalendarSyncStatus = /* @__PURE__ */ ((CalendarSyncStatus3) => {
303
- CalendarSyncStatus3["INTERNAL"] = "internal";
304
- CalendarSyncStatus3["EXTERNAL"] = "external";
305
- return CalendarSyncStatus3;
304
+ var CalendarSyncStatus = /* @__PURE__ */ ((CalendarSyncStatus4) => {
305
+ CalendarSyncStatus4["INTERNAL"] = "internal";
306
+ CalendarSyncStatus4["EXTERNAL"] = "external";
307
+ return CalendarSyncStatus4;
306
308
  })(CalendarSyncStatus || {});
307
- var CalendarEventType = /* @__PURE__ */ ((CalendarEventType2) => {
308
- CalendarEventType2["APPOINTMENT"] = "appointment";
309
- CalendarEventType2["BLOCKING"] = "blocking";
310
- CalendarEventType2["BREAK"] = "break";
311
- CalendarEventType2["FREE_DAY"] = "free_day";
312
- CalendarEventType2["OTHER"] = "other";
313
- return CalendarEventType2;
309
+ var CalendarEventType = /* @__PURE__ */ ((CalendarEventType3) => {
310
+ CalendarEventType3["APPOINTMENT"] = "appointment";
311
+ CalendarEventType3["BLOCKING"] = "blocking";
312
+ CalendarEventType3["BREAK"] = "break";
313
+ CalendarEventType3["FREE_DAY"] = "free_day";
314
+ CalendarEventType3["OTHER"] = "other";
315
+ return CalendarEventType3;
314
316
  })(CalendarEventType || {});
315
317
  var CALENDAR_COLLECTION = "calendar";
316
318
 
@@ -1148,6 +1150,8 @@ var patientProfileSchema = import_zod5.z.object({
1148
1150
  isVerified: import_zod5.z.boolean(),
1149
1151
  doctors: import_zod5.z.array(patientDoctorSchema),
1150
1152
  clinics: import_zod5.z.array(patientClinicSchema),
1153
+ doctorIds: import_zod5.z.array(import_zod5.z.string()),
1154
+ clinicIds: import_zod5.z.array(import_zod5.z.string()),
1151
1155
  createdAt: import_zod5.z.instanceof(import_firestore2.Timestamp),
1152
1156
  updatedAt: import_zod5.z.instanceof(import_firestore2.Timestamp)
1153
1157
  });
@@ -1160,7 +1164,9 @@ var createPatientProfileSchema = import_zod5.z.object({
1160
1164
  isActive: import_zod5.z.boolean(),
1161
1165
  isVerified: import_zod5.z.boolean(),
1162
1166
  doctors: import_zod5.z.array(patientDoctorSchema).optional(),
1163
- clinics: import_zod5.z.array(patientClinicSchema).optional()
1167
+ clinics: import_zod5.z.array(patientClinicSchema).optional(),
1168
+ doctorIds: import_zod5.z.array(import_zod5.z.string()).optional(),
1169
+ clinicIds: import_zod5.z.array(import_zod5.z.string()).optional()
1164
1170
  });
1165
1171
  var createPatientSensitiveInfoSchema = import_zod5.z.object({
1166
1172
  patientId: import_zod5.z.string(),
@@ -1176,6 +1182,33 @@ var createPatientSensitiveInfoSchema = import_zod5.z.object({
1176
1182
  addressData: addressDataSchema.optional(),
1177
1183
  emergencyContacts: import_zod5.z.array(emergencyContactSchema).optional()
1178
1184
  });
1185
+ var searchPatientsSchema = import_zod5.z.object({
1186
+ clinicId: import_zod5.z.string().optional(),
1187
+ practitionerId: import_zod5.z.string().optional()
1188
+ }).refine((data) => data.clinicId || data.practitionerId, {
1189
+ message: "At least one of clinicId or practitionerId must be provided",
1190
+ path: []
1191
+ // Optional: specify a path like ['clinicId'] or ['practitionerId']
1192
+ });
1193
+ var requesterInfoSchema = import_zod5.z.object({
1194
+ id: import_zod5.z.string(),
1195
+ role: import_zod5.z.enum(["clinic_admin", "practitioner"]),
1196
+ associatedClinicId: import_zod5.z.string().optional(),
1197
+ associatedPractitionerId: import_zod5.z.string().optional()
1198
+ }).refine(
1199
+ (data) => {
1200
+ if (data.role === "clinic_admin") {
1201
+ return !!data.associatedClinicId;
1202
+ } else if (data.role === "practitioner") {
1203
+ return !!data.associatedPractitionerId;
1204
+ }
1205
+ return false;
1206
+ },
1207
+ {
1208
+ message: "Associated ID (clinic or practitioner) is required based on role",
1209
+ path: ["associatedClinicId", "associatedPractitionerId"]
1210
+ }
1211
+ );
1179
1212
 
1180
1213
  // src/services/patient/utils/docs.utils.ts
1181
1214
  var import_firestore4 = require("firebase/firestore");
@@ -1440,9 +1473,9 @@ var addAllergyUtil = async (db, patientId, data, userRef) => {
1440
1473
  var updateAllergyUtil = async (db, patientId, data, userRef) => {
1441
1474
  const validatedData = updateAllergySchema.parse(data);
1442
1475
  const { allergyIndex, ...updateData } = validatedData;
1443
- const doc26 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1444
- if (!doc26.exists()) throw new Error("Medical info not found");
1445
- const medicalInfo = doc26.data();
1476
+ const doc27 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1477
+ if (!doc27.exists()) throw new Error("Medical info not found");
1478
+ const medicalInfo = doc27.data();
1446
1479
  if (allergyIndex >= medicalInfo.allergies.length) {
1447
1480
  throw new Error("Invalid allergy index");
1448
1481
  }
@@ -1458,9 +1491,9 @@ var updateAllergyUtil = async (db, patientId, data, userRef) => {
1458
1491
  });
1459
1492
  };
1460
1493
  var removeAllergyUtil = async (db, patientId, allergyIndex, userRef) => {
1461
- const doc26 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1462
- if (!doc26.exists()) throw new Error("Medical info not found");
1463
- const medicalInfo = doc26.data();
1494
+ const doc27 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1495
+ if (!doc27.exists()) throw new Error("Medical info not found");
1496
+ const medicalInfo = doc27.data();
1464
1497
  if (allergyIndex >= medicalInfo.allergies.length) {
1465
1498
  throw new Error("Invalid allergy index");
1466
1499
  }
@@ -1485,9 +1518,9 @@ var addBlockingConditionUtil = async (db, patientId, data, userRef) => {
1485
1518
  var updateBlockingConditionUtil = async (db, patientId, data, userRef) => {
1486
1519
  const validatedData = updateBlockingConditionSchema.parse(data);
1487
1520
  const { conditionIndex, ...updateData } = validatedData;
1488
- const doc26 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1489
- if (!doc26.exists()) throw new Error("Medical info not found");
1490
- const medicalInfo = doc26.data();
1521
+ const doc27 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1522
+ if (!doc27.exists()) throw new Error("Medical info not found");
1523
+ const medicalInfo = doc27.data();
1491
1524
  if (conditionIndex >= medicalInfo.blockingConditions.length) {
1492
1525
  throw new Error("Invalid blocking condition index");
1493
1526
  }
@@ -1503,9 +1536,9 @@ var updateBlockingConditionUtil = async (db, patientId, data, userRef) => {
1503
1536
  });
1504
1537
  };
1505
1538
  var removeBlockingConditionUtil = async (db, patientId, conditionIndex, userRef) => {
1506
- const doc26 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1507
- if (!doc26.exists()) throw new Error("Medical info not found");
1508
- const medicalInfo = doc26.data();
1539
+ const doc27 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1540
+ if (!doc27.exists()) throw new Error("Medical info not found");
1541
+ const medicalInfo = doc27.data();
1509
1542
  if (conditionIndex >= medicalInfo.blockingConditions.length) {
1510
1543
  throw new Error("Invalid blocking condition index");
1511
1544
  }
@@ -1530,9 +1563,9 @@ var addContraindicationUtil = async (db, patientId, data, userRef) => {
1530
1563
  var updateContraindicationUtil = async (db, patientId, data, userRef) => {
1531
1564
  const validatedData = updateContraindicationSchema.parse(data);
1532
1565
  const { contraindicationIndex, ...updateData } = validatedData;
1533
- const doc26 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1534
- if (!doc26.exists()) throw new Error("Medical info not found");
1535
- const medicalInfo = doc26.data();
1566
+ const doc27 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1567
+ if (!doc27.exists()) throw new Error("Medical info not found");
1568
+ const medicalInfo = doc27.data();
1536
1569
  if (contraindicationIndex >= medicalInfo.contraindications.length) {
1537
1570
  throw new Error("Invalid contraindication index");
1538
1571
  }
@@ -1548,9 +1581,9 @@ var updateContraindicationUtil = async (db, patientId, data, userRef) => {
1548
1581
  });
1549
1582
  };
1550
1583
  var removeContraindicationUtil = async (db, patientId, contraindicationIndex, userRef) => {
1551
- const doc26 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1552
- if (!doc26.exists()) throw new Error("Medical info not found");
1553
- const medicalInfo = doc26.data();
1584
+ const doc27 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1585
+ if (!doc27.exists()) throw new Error("Medical info not found");
1586
+ const medicalInfo = doc27.data();
1554
1587
  if (contraindicationIndex >= medicalInfo.contraindications.length) {
1555
1588
  throw new Error("Invalid contraindication index");
1556
1589
  }
@@ -1575,9 +1608,9 @@ var addMedicationUtil = async (db, patientId, data, userRef) => {
1575
1608
  var updateMedicationUtil = async (db, patientId, data, userRef) => {
1576
1609
  const validatedData = updateMedicationSchema.parse(data);
1577
1610
  const { medicationIndex, ...updateData } = validatedData;
1578
- const doc26 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1579
- if (!doc26.exists()) throw new Error("Medical info not found");
1580
- const medicalInfo = doc26.data();
1611
+ const doc27 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1612
+ if (!doc27.exists()) throw new Error("Medical info not found");
1613
+ const medicalInfo = doc27.data();
1581
1614
  if (medicationIndex >= medicalInfo.currentMedications.length) {
1582
1615
  throw new Error("Invalid medication index");
1583
1616
  }
@@ -1593,9 +1626,9 @@ var updateMedicationUtil = async (db, patientId, data, userRef) => {
1593
1626
  });
1594
1627
  };
1595
1628
  var removeMedicationUtil = async (db, patientId, medicationIndex, userRef) => {
1596
- const doc26 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1597
- if (!doc26.exists()) throw new Error("Medical info not found");
1598
- const medicalInfo = doc26.data();
1629
+ const doc27 = await (0, import_firestore5.getDoc)(getMedicalInfoDocRef(db, patientId));
1630
+ if (!doc27.exists()) throw new Error("Medical info not found");
1631
+ const medicalInfo = doc27.data();
1599
1632
  if (medicationIndex >= medicalInfo.currentMedications.length) {
1600
1633
  throw new Error("Invalid medication index");
1601
1634
  }
@@ -1611,6 +1644,7 @@ var removeMedicationUtil = async (db, patientId, medicationIndex, userRef) => {
1611
1644
 
1612
1645
  // src/services/patient/utils/profile.utils.ts
1613
1646
  var createPatientProfileUtil = async (db, data, generateId2) => {
1647
+ var _a, _b;
1614
1648
  try {
1615
1649
  console.log("[createPatientProfileUtil] Starting patient profile creation");
1616
1650
  const validatedData = createPatientProfileSchema.parse(data);
@@ -1630,6 +1664,8 @@ var createPatientProfileUtil = async (db, data, generateId2) => {
1630
1664
  isVerified: validatedData.isVerified,
1631
1665
  doctors: validatedData.doctors || [],
1632
1666
  clinics: validatedData.clinics || [],
1667
+ doctorIds: ((_a = validatedData.doctors) == null ? void 0 : _a.map((d) => d.userRef)) || [],
1668
+ clinicIds: ((_b = validatedData.clinics) == null ? void 0 : _b.map((c) => c.clinicId)) || [],
1633
1669
  createdAt: (0, import_firestore6.serverTimestamp)(),
1634
1670
  updatedAt: (0, import_firestore6.serverTimestamp)()
1635
1671
  };
@@ -1863,6 +1899,67 @@ var testCreateSubDocuments = async (db, patientId, userRef) => {
1863
1899
  throw error;
1864
1900
  }
1865
1901
  };
1902
+ var searchPatientsUtil = async (db, params, requester) => {
1903
+ searchPatientsSchema.parse(params);
1904
+ requesterInfoSchema.parse(requester);
1905
+ const constraints = [];
1906
+ const patientsCollectionRef = (0, import_firestore6.collection)(db, PATIENTS_COLLECTION);
1907
+ if (requester.role === "clinic_admin") {
1908
+ if (!requester.associatedClinicId) {
1909
+ throw new Error(
1910
+ "Associated clinic ID is required for clinic admin search."
1911
+ );
1912
+ }
1913
+ if (params.clinicId && params.clinicId !== requester.associatedClinicId) {
1914
+ console.warn(
1915
+ `Clinic admin (${requester.id}) attempted to search outside their associated clinic (${requester.associatedClinicId})`
1916
+ );
1917
+ return [];
1918
+ }
1919
+ constraints.push(
1920
+ (0, import_firestore6.where)("clinicIds", "array-contains", requester.associatedClinicId)
1921
+ );
1922
+ if (params.practitionerId) {
1923
+ constraints.push(
1924
+ (0, import_firestore6.where)("doctorIds", "array-contains", params.practitionerId)
1925
+ );
1926
+ }
1927
+ } else if (requester.role === "practitioner") {
1928
+ if (!requester.associatedPractitionerId) {
1929
+ throw new Error(
1930
+ "Associated practitioner ID is required for practitioner search."
1931
+ );
1932
+ }
1933
+ if (params.practitionerId && params.practitionerId !== requester.associatedPractitionerId) {
1934
+ console.warn(
1935
+ `Practitioner (${requester.id}) attempted to search for patients of another practitioner (${params.practitionerId})`
1936
+ );
1937
+ return [];
1938
+ }
1939
+ constraints.push(
1940
+ (0, import_firestore6.where)("doctorIds", "array-contains", requester.associatedPractitionerId)
1941
+ );
1942
+ if (params.clinicId) {
1943
+ constraints.push((0, import_firestore6.where)("clinicIds", "array-contains", params.clinicId));
1944
+ }
1945
+ } else {
1946
+ throw new Error("Invalid requester role.");
1947
+ }
1948
+ try {
1949
+ const finalQuery = (0, import_firestore6.query)(patientsCollectionRef, ...constraints);
1950
+ const querySnapshot = await (0, import_firestore6.getDocs)(finalQuery);
1951
+ const patients = querySnapshot.docs.map(
1952
+ (doc27) => doc27.data()
1953
+ );
1954
+ console.log(
1955
+ `[searchPatientsUtil] Found ${patients.length} patients matching criteria.`
1956
+ );
1957
+ return patients;
1958
+ } catch (error) {
1959
+ console.error("[searchPatientsUtil] Error searching patients:", error);
1960
+ return [];
1961
+ }
1962
+ };
1866
1963
 
1867
1964
  // src/services/patient/utils/location.utils.ts
1868
1965
  var import_firestore7 = require("firebase/firestore");
@@ -1944,50 +2041,96 @@ var updateLocationInfoUtil = async (db, patientId, data, requesterId) => {
1944
2041
  // src/services/patient/utils/medical-stuff.utils.ts
1945
2042
  var import_firestore8 = require("firebase/firestore");
1946
2043
  var addDoctorUtil = async (db, patientId, doctorRef, assignedBy) => {
2044
+ var _a;
1947
2045
  const newDoctor = {
1948
2046
  userRef: doctorRef,
1949
2047
  assignedAt: import_firestore8.Timestamp.now(),
1950
2048
  assignedBy,
1951
2049
  isActive: true
1952
2050
  };
1953
- await (0, import_firestore8.updateDoc)(getPatientDocRef(db, patientId), {
1954
- doctors: (0, import_firestore8.arrayUnion)(newDoctor),
1955
- updatedAt: (0, import_firestore8.serverTimestamp)()
1956
- });
1957
- };
1958
- var removeDoctorUtil = async (db, patientId, doctorRef) => {
1959
2051
  const patientDoc = await (0, import_firestore8.getDoc)(getPatientDocRef(db, patientId));
1960
2052
  if (!patientDoc.exists()) throw new Error("Patient profile not found");
1961
2053
  const patientData = patientDoc.data();
1962
- const updatedDoctors = patientData.doctors.map(
1963
- (doctor) => doctor.userRef === doctorRef ? { ...doctor, isActive: false } : doctor
2054
+ const existingDoctorIndex = (_a = patientData.doctors) == null ? void 0 : _a.findIndex(
2055
+ (d) => d.userRef === doctorRef
1964
2056
  );
1965
- await (0, import_firestore8.updateDoc)(getPatientDocRef(db, patientId), {
2057
+ const updates = {
2058
+ updatedAt: (0, import_firestore8.serverTimestamp)(),
2059
+ doctorIds: (0, import_firestore8.arrayUnion)(doctorRef)
2060
+ };
2061
+ if (existingDoctorIndex !== void 0 && existingDoctorIndex > -1) {
2062
+ const updatedDoctors = [...patientData.doctors];
2063
+ updatedDoctors[existingDoctorIndex] = {
2064
+ ...updatedDoctors[existingDoctorIndex],
2065
+ isActive: true,
2066
+ assignedAt: import_firestore8.Timestamp.now(),
2067
+ assignedBy
2068
+ };
2069
+ updates.doctors = updatedDoctors;
2070
+ } else {
2071
+ updates.doctors = (0, import_firestore8.arrayUnion)(newDoctor);
2072
+ }
2073
+ await (0, import_firestore8.updateDoc)(getPatientDocRef(db, patientId), updates);
2074
+ };
2075
+ var removeDoctorUtil = async (db, patientId, doctorRef) => {
2076
+ var _a;
2077
+ const patientDocRef = getPatientDocRef(db, patientId);
2078
+ const patientDoc = await (0, import_firestore8.getDoc)(patientDocRef);
2079
+ if (!patientDoc.exists()) throw new Error("Patient profile not found");
2080
+ const patientData = patientDoc.data();
2081
+ const updatedDoctors = ((_a = patientData.doctors) == null ? void 0 : _a.filter((doctor) => doctor.userRef !== doctorRef)) || [];
2082
+ await (0, import_firestore8.updateDoc)(patientDocRef, {
1966
2083
  doctors: updatedDoctors,
2084
+ // Set the filtered array
2085
+ doctorIds: (0, import_firestore8.arrayRemove)(doctorRef),
2086
+ // Remove ID from the denormalized list
1967
2087
  updatedAt: (0, import_firestore8.serverTimestamp)()
1968
2088
  });
1969
2089
  };
1970
2090
  var addClinicUtil = async (db, patientId, clinicId, assignedBy) => {
2091
+ var _a;
1971
2092
  const newClinic = {
1972
2093
  clinicId,
1973
2094
  assignedAt: import_firestore8.Timestamp.now(),
1974
2095
  assignedBy,
1975
2096
  isActive: true
1976
2097
  };
1977
- await (0, import_firestore8.updateDoc)(getPatientDocRef(db, patientId), {
1978
- clinics: (0, import_firestore8.arrayUnion)(newClinic),
1979
- updatedAt: (0, import_firestore8.serverTimestamp)()
1980
- });
1981
- };
1982
- var removeClinicUtil = async (db, patientId, clinicId) => {
1983
2098
  const patientDoc = await (0, import_firestore8.getDoc)(getPatientDocRef(db, patientId));
1984
2099
  if (!patientDoc.exists()) throw new Error("Patient profile not found");
1985
2100
  const patientData = patientDoc.data();
1986
- const updatedClinics = patientData.clinics.map(
1987
- (clinic) => clinic.clinicId === clinicId ? { ...clinic, isActive: false } : clinic
2101
+ const existingClinicIndex = (_a = patientData.clinics) == null ? void 0 : _a.findIndex(
2102
+ (c) => c.clinicId === clinicId
1988
2103
  );
1989
- await (0, import_firestore8.updateDoc)(getPatientDocRef(db, patientId), {
2104
+ const updates = {
2105
+ updatedAt: (0, import_firestore8.serverTimestamp)(),
2106
+ clinicIds: (0, import_firestore8.arrayUnion)(clinicId)
2107
+ };
2108
+ if (existingClinicIndex !== void 0 && existingClinicIndex > -1) {
2109
+ const updatedClinics = [...patientData.clinics];
2110
+ updatedClinics[existingClinicIndex] = {
2111
+ ...updatedClinics[existingClinicIndex],
2112
+ isActive: true,
2113
+ assignedAt: import_firestore8.Timestamp.now(),
2114
+ assignedBy
2115
+ };
2116
+ updates.clinics = updatedClinics;
2117
+ } else {
2118
+ updates.clinics = (0, import_firestore8.arrayUnion)(newClinic);
2119
+ }
2120
+ await (0, import_firestore8.updateDoc)(getPatientDocRef(db, patientId), updates);
2121
+ };
2122
+ var removeClinicUtil = async (db, patientId, clinicId) => {
2123
+ var _a;
2124
+ const patientDocRef = getPatientDocRef(db, patientId);
2125
+ const patientDoc = await (0, import_firestore8.getDoc)(patientDocRef);
2126
+ if (!patientDoc.exists()) throw new Error("Patient profile not found");
2127
+ const patientData = patientDoc.data();
2128
+ const updatedClinics = ((_a = patientData.clinics) == null ? void 0 : _a.filter((clinic) => clinic.clinicId !== clinicId)) || [];
2129
+ await (0, import_firestore8.updateDoc)(patientDocRef, {
1990
2130
  clinics: updatedClinics,
2131
+ // Set the filtered array
2132
+ clinicIds: (0, import_firestore8.arrayRemove)(clinicId),
2133
+ // Remove ID from the denormalized list
1991
2134
  updatedAt: (0, import_firestore8.serverTimestamp)()
1992
2135
  });
1993
2136
  };
@@ -2228,6 +2371,23 @@ var PatientService = class extends BaseService {
2228
2371
  async updatePatientProfileByUserRef(userRef, data) {
2229
2372
  return updatePatientProfileByUserRefUtil(this.db, userRef, data);
2230
2373
  }
2374
+ /**
2375
+ * Searches for patient profiles based on clinic/practitioner association.
2376
+ * Requires information about the requester for security checks.
2377
+ *
2378
+ * @param {SearchPatientsParams} params - The search criteria (clinicId, practitionerId).
2379
+ * @param {RequesterInfo} requester - Information about the user performing the search (ID, role, associated IDs).
2380
+ * @returns {Promise<PatientProfile[]>} A promise resolving to an array of matching patient profiles.
2381
+ */
2382
+ async searchPatients(params, requester) {
2383
+ console.log(
2384
+ `[PatientService.searchPatients] Initiating search with params:`,
2385
+ params,
2386
+ `by requester:`,
2387
+ requester
2388
+ );
2389
+ return searchPatientsUtil(this.db, params, requester);
2390
+ }
2231
2391
  };
2232
2392
 
2233
2393
  // src/services/clinic/utils/admin.utils.ts
@@ -2891,7 +3051,7 @@ async function getClinicAdminsByGroup(db, clinicGroupId) {
2891
3051
  (0, import_firestore11.where)("clinicGroupId", "==", clinicGroupId)
2892
3052
  );
2893
3053
  const querySnapshot = await (0, import_firestore11.getDocs)(q);
2894
- return querySnapshot.docs.map((doc26) => doc26.data());
3054
+ return querySnapshot.docs.map((doc27) => doc27.data());
2895
3055
  }
2896
3056
  async function updateClinicAdmin(db, adminId, data) {
2897
3057
  const admin = await getClinicAdmin(db, adminId);
@@ -3546,7 +3706,7 @@ var PractitionerService = class extends BaseService {
3546
3706
  (0, import_firestore13.where)("expiresAt", ">", import_firestore13.Timestamp.now())
3547
3707
  );
3548
3708
  const querySnapshot = await (0, import_firestore13.getDocs)(q);
3549
- return querySnapshot.docs.map((doc26) => doc26.data());
3709
+ return querySnapshot.docs.map((doc27) => doc27.data());
3550
3710
  }
3551
3711
  /**
3552
3712
  * Gets a token by its string value and validates it
@@ -3629,7 +3789,7 @@ var PractitionerService = class extends BaseService {
3629
3789
  (0, import_firestore13.where)("status", "==", "active" /* ACTIVE */)
3630
3790
  );
3631
3791
  const querySnapshot = await (0, import_firestore13.getDocs)(q);
3632
- return querySnapshot.docs.map((doc26) => doc26.data());
3792
+ return querySnapshot.docs.map((doc27) => doc27.data());
3633
3793
  }
3634
3794
  /**
3635
3795
  * Dohvata sve zdravstvene radnike za određenu kliniku
@@ -3641,7 +3801,7 @@ var PractitionerService = class extends BaseService {
3641
3801
  (0, import_firestore13.where)("isActive", "==", true)
3642
3802
  );
3643
3803
  const querySnapshot = await (0, import_firestore13.getDocs)(q);
3644
- return querySnapshot.docs.map((doc26) => doc26.data());
3804
+ return querySnapshot.docs.map((doc27) => doc27.data());
3645
3805
  }
3646
3806
  /**
3647
3807
  * Dohvata sve draft zdravstvene radnike za određenu kliniku sa statusom DRAFT
@@ -3653,7 +3813,7 @@ var PractitionerService = class extends BaseService {
3653
3813
  (0, import_firestore13.where)("status", "==", "draft" /* DRAFT */)
3654
3814
  );
3655
3815
  const querySnapshot = await (0, import_firestore13.getDocs)(q);
3656
- return querySnapshot.docs.map((doc26) => doc26.data());
3816
+ return querySnapshot.docs.map((doc27) => doc27.data());
3657
3817
  }
3658
3818
  /**
3659
3819
  * Ažurira profil zdravstvenog radnika
@@ -3962,7 +4122,7 @@ var UserService = class extends BaseService {
3962
4122
  ];
3963
4123
  const q = (0, import_firestore14.query)((0, import_firestore14.collection)(this.db, USERS_COLLECTION), ...constraints);
3964
4124
  const querySnapshot = await (0, import_firestore14.getDocs)(q);
3965
- const users = querySnapshot.docs.map((doc26) => doc26.data());
4125
+ const users = querySnapshot.docs.map((doc27) => doc27.data());
3966
4126
  return Promise.all(users.map((userData) => userSchema.parse(userData)));
3967
4127
  }
3968
4128
  /**
@@ -4326,7 +4486,7 @@ async function getAllActiveGroups(db) {
4326
4486
  (0, import_firestore15.where)("isActive", "==", true)
4327
4487
  );
4328
4488
  const querySnapshot = await (0, import_firestore15.getDocs)(q);
4329
- return querySnapshot.docs.map((doc26) => doc26.data());
4489
+ return querySnapshot.docs.map((doc27) => doc27.data());
4330
4490
  }
4331
4491
  async function updateClinicGroup(db, groupId, data, app) {
4332
4492
  console.log("[CLINIC_GROUP] Updating clinic group", { groupId });
@@ -4988,7 +5148,7 @@ async function getClinicsByGroup(db, groupId) {
4988
5148
  (0, import_firestore16.where)("isActive", "==", true)
4989
5149
  );
4990
5150
  const querySnapshot = await (0, import_firestore16.getDocs)(q);
4991
- return querySnapshot.docs.map((doc26) => doc26.data());
5151
+ return querySnapshot.docs.map((doc27) => doc27.data());
4992
5152
  }
4993
5153
  async function updateClinic(db, clinicId, data, adminId, clinicAdminService, app) {
4994
5154
  console.log("[CLINIC] Starting clinic update", { clinicId, adminId });
@@ -5200,7 +5360,7 @@ async function getClinicsByAdmin(db, adminId, options = {}, clinicAdminService,
5200
5360
  }
5201
5361
  const q = (0, import_firestore16.query)((0, import_firestore16.collection)(db, CLINICS_COLLECTION), ...constraints);
5202
5362
  const querySnapshot = await (0, import_firestore16.getDocs)(q);
5203
- return querySnapshot.docs.map((doc26) => doc26.data());
5363
+ return querySnapshot.docs.map((doc27) => doc27.data());
5204
5364
  }
5205
5365
  async function getActiveClinicsByAdmin(db, adminId, clinicAdminService, clinicGroupService) {
5206
5366
  return getClinicsByAdmin(
@@ -5342,8 +5502,8 @@ async function findClinicsInRadius(db, center, radiusInKm, filters) {
5342
5502
  }
5343
5503
  const q = (0, import_firestore18.query)((0, import_firestore18.collection)(db, CLINICS_COLLECTION), ...constraints);
5344
5504
  const querySnapshot = await (0, import_firestore18.getDocs)(q);
5345
- for (const doc26 of querySnapshot.docs) {
5346
- const clinic = doc26.data();
5505
+ for (const doc27 of querySnapshot.docs) {
5506
+ const clinic = doc27.data();
5347
5507
  const distance = (0, import_geofire_common4.distanceBetween)(
5348
5508
  [center.latitude, center.longitude],
5349
5509
  [clinic.location.latitude, clinic.location.longitude]
@@ -6275,9 +6435,9 @@ var NotificationService = class extends BaseService {
6275
6435
  (0, import_firestore20.orderBy)("notificationTime", "desc")
6276
6436
  );
6277
6437
  const querySnapshot = await (0, import_firestore20.getDocs)(q);
6278
- return querySnapshot.docs.map((doc26) => ({
6279
- id: doc26.id,
6280
- ...doc26.data()
6438
+ return querySnapshot.docs.map((doc27) => ({
6439
+ id: doc27.id,
6440
+ ...doc27.data()
6281
6441
  }));
6282
6442
  }
6283
6443
  /**
@@ -6291,9 +6451,9 @@ var NotificationService = class extends BaseService {
6291
6451
  (0, import_firestore20.orderBy)("notificationTime", "desc")
6292
6452
  );
6293
6453
  const querySnapshot = await (0, import_firestore20.getDocs)(q);
6294
- return querySnapshot.docs.map((doc26) => ({
6295
- id: doc26.id,
6296
- ...doc26.data()
6454
+ return querySnapshot.docs.map((doc27) => ({
6455
+ id: doc27.id,
6456
+ ...doc27.data()
6297
6457
  }));
6298
6458
  }
6299
6459
  /**
@@ -6365,9 +6525,9 @@ var NotificationService = class extends BaseService {
6365
6525
  (0, import_firestore20.orderBy)("notificationTime", "desc")
6366
6526
  );
6367
6527
  const querySnapshot = await (0, import_firestore20.getDocs)(q);
6368
- return querySnapshot.docs.map((doc26) => ({
6369
- id: doc26.id,
6370
- ...doc26.data()
6528
+ return querySnapshot.docs.map((doc27) => ({
6529
+ id: doc27.id,
6530
+ ...doc27.data()
6371
6531
  }));
6372
6532
  }
6373
6533
  /**
@@ -6380,9 +6540,9 @@ var NotificationService = class extends BaseService {
6380
6540
  (0, import_firestore20.orderBy)("notificationTime", "desc")
6381
6541
  );
6382
6542
  const querySnapshot = await (0, import_firestore20.getDocs)(q);
6383
- return querySnapshot.docs.map((doc26) => ({
6384
- id: doc26.id,
6385
- ...doc26.data()
6543
+ return querySnapshot.docs.map((doc27) => ({
6544
+ id: doc27.id,
6545
+ ...doc27.data()
6386
6546
  }));
6387
6547
  }
6388
6548
  };
@@ -6530,7 +6690,7 @@ var ProcedureService = class extends BaseService {
6530
6690
  (0, import_firestore21.where)("isActive", "==", true)
6531
6691
  );
6532
6692
  const snapshot = await (0, import_firestore21.getDocs)(q);
6533
- return snapshot.docs.map((doc26) => doc26.data());
6693
+ return snapshot.docs.map((doc27) => doc27.data());
6534
6694
  }
6535
6695
  /**
6536
6696
  * Gets all procedures for a practitioner
@@ -6544,7 +6704,7 @@ var ProcedureService = class extends BaseService {
6544
6704
  (0, import_firestore21.where)("isActive", "==", true)
6545
6705
  );
6546
6706
  const snapshot = await (0, import_firestore21.getDocs)(q);
6547
- return snapshot.docs.map((doc26) => doc26.data());
6707
+ return snapshot.docs.map((doc27) => doc27.data());
6548
6708
  }
6549
6709
  /**
6550
6710
  * Updates a procedure
@@ -6724,9 +6884,9 @@ var DocumentationTemplateService = class extends BaseService {
6724
6884
  const querySnapshot = await (0, import_firestore22.getDocs)(q);
6725
6885
  const templates = [];
6726
6886
  let lastVisible = null;
6727
- querySnapshot.forEach((doc26) => {
6728
- templates.push(doc26.data());
6729
- lastVisible = doc26;
6887
+ querySnapshot.forEach((doc27) => {
6888
+ templates.push(doc27.data());
6889
+ lastVisible = doc27;
6730
6890
  });
6731
6891
  return {
6732
6892
  templates,
@@ -6754,9 +6914,9 @@ var DocumentationTemplateService = class extends BaseService {
6754
6914
  const querySnapshot = await (0, import_firestore22.getDocs)(q);
6755
6915
  const templates = [];
6756
6916
  let lastVisible = null;
6757
- querySnapshot.forEach((doc26) => {
6758
- templates.push(doc26.data());
6759
- lastVisible = doc26;
6917
+ querySnapshot.forEach((doc27) => {
6918
+ templates.push(doc27.data());
6919
+ lastVisible = doc27;
6760
6920
  });
6761
6921
  return {
6762
6922
  templates,
@@ -6783,9 +6943,9 @@ var DocumentationTemplateService = class extends BaseService {
6783
6943
  const querySnapshot = await (0, import_firestore22.getDocs)(q);
6784
6944
  const templates = [];
6785
6945
  let lastVisible = null;
6786
- querySnapshot.forEach((doc26) => {
6787
- templates.push(doc26.data());
6788
- lastVisible = doc26;
6946
+ querySnapshot.forEach((doc27) => {
6947
+ templates.push(doc27.data());
6948
+ lastVisible = doc27;
6789
6949
  });
6790
6950
  return {
6791
6951
  templates,
@@ -6898,9 +7058,9 @@ var FilledDocumentService = class extends BaseService {
6898
7058
  const querySnapshot = await (0, import_firestore23.getDocs)(q);
6899
7059
  const documents = [];
6900
7060
  let lastVisible = null;
6901
- querySnapshot.forEach((doc26) => {
6902
- documents.push(doc26.data());
6903
- lastVisible = doc26;
7061
+ querySnapshot.forEach((doc27) => {
7062
+ documents.push(doc27.data());
7063
+ lastVisible = doc27;
6904
7064
  });
6905
7065
  return {
6906
7066
  documents,
@@ -6927,9 +7087,9 @@ var FilledDocumentService = class extends BaseService {
6927
7087
  const querySnapshot = await (0, import_firestore23.getDocs)(q);
6928
7088
  const documents = [];
6929
7089
  let lastVisible = null;
6930
- querySnapshot.forEach((doc26) => {
6931
- documents.push(doc26.data());
6932
- lastVisible = doc26;
7090
+ querySnapshot.forEach((doc27) => {
7091
+ documents.push(doc27.data());
7092
+ lastVisible = doc27;
6933
7093
  });
6934
7094
  return {
6935
7095
  documents,
@@ -6956,9 +7116,9 @@ var FilledDocumentService = class extends BaseService {
6956
7116
  const querySnapshot = await (0, import_firestore23.getDocs)(q);
6957
7117
  const documents = [];
6958
7118
  let lastVisible = null;
6959
- querySnapshot.forEach((doc26) => {
6960
- documents.push(doc26.data());
6961
- lastVisible = doc26;
7119
+ querySnapshot.forEach((doc27) => {
7120
+ documents.push(doc27.data());
7121
+ lastVisible = doc27;
6962
7122
  });
6963
7123
  return {
6964
7124
  documents,
@@ -6985,9 +7145,9 @@ var FilledDocumentService = class extends BaseService {
6985
7145
  const querySnapshot = await (0, import_firestore23.getDocs)(q);
6986
7146
  const documents = [];
6987
7147
  let lastVisible = null;
6988
- querySnapshot.forEach((doc26) => {
6989
- documents.push(doc26.data());
6990
- lastVisible = doc26;
7148
+ querySnapshot.forEach((doc27) => {
7149
+ documents.push(doc27.data());
7150
+ lastVisible = doc27;
6991
7151
  });
6992
7152
  return {
6993
7153
  documents,
@@ -7014,9 +7174,9 @@ var FilledDocumentService = class extends BaseService {
7014
7174
  const querySnapshot = await (0, import_firestore23.getDocs)(q);
7015
7175
  const documents = [];
7016
7176
  let lastVisible = null;
7017
- querySnapshot.forEach((doc26) => {
7018
- documents.push(doc26.data());
7019
- lastVisible = doc26;
7177
+ querySnapshot.forEach((doc27) => {
7178
+ documents.push(doc27.data());
7179
+ lastVisible = doc27;
7020
7180
  });
7021
7181
  return {
7022
7182
  documents,
@@ -7026,7 +7186,7 @@ var FilledDocumentService = class extends BaseService {
7026
7186
  };
7027
7187
 
7028
7188
  // src/services/calendar/calendar-refactored.service.ts
7029
- var import_firestore32 = require("firebase/firestore");
7189
+ var import_firestore33 = require("firebase/firestore");
7030
7190
 
7031
7191
  // src/types/calendar/synced-calendar.types.ts
7032
7192
  var SyncedCalendarProvider = /* @__PURE__ */ ((SyncedCalendarProvider3) => {
@@ -7038,7 +7198,7 @@ var SyncedCalendarProvider = /* @__PURE__ */ ((SyncedCalendarProvider3) => {
7038
7198
  var SYNCED_CALENDARS_COLLECTION = "syncedCalendars";
7039
7199
 
7040
7200
  // src/services/calendar/calendar-refactored.service.ts
7041
- var import_firestore33 = require("firebase/firestore");
7201
+ var import_firestore34 = require("firebase/firestore");
7042
7202
 
7043
7203
  // src/validations/calendar.schema.ts
7044
7204
  var import_zod18 = require("zod");
@@ -7446,8 +7606,102 @@ async function updateAppointmentUtil(db, clinicId, practitionerId, patientId, ev
7446
7606
  return clinicEvent;
7447
7607
  }
7448
7608
 
7449
- // src/services/calendar/utils/synced-calendar.utils.ts
7609
+ // src/services/calendar/utils/calendar-event.utils.ts
7450
7610
  var import_firestore30 = require("firebase/firestore");
7611
+ async function searchCalendarEventsUtil(db, params) {
7612
+ const { searchLocation, entityId, ...filters } = params;
7613
+ let baseCollectionPath;
7614
+ const constraints = [];
7615
+ switch (searchLocation) {
7616
+ case "practitioner" /* PRACTITIONER */:
7617
+ if (!entityId) {
7618
+ throw new Error(
7619
+ "Practitioner ID (entityId) is required when searching practitioner calendar."
7620
+ );
7621
+ }
7622
+ baseCollectionPath = `${PRACTITIONERS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
7623
+ if (filters.practitionerId && filters.practitionerId !== entityId) {
7624
+ console.warn(
7625
+ `Provided practitionerId filter (${filters.practitionerId}) does not match search entityId (${entityId}). Returning empty results.`
7626
+ );
7627
+ return [];
7628
+ }
7629
+ filters.practitionerId = void 0;
7630
+ break;
7631
+ case "patient" /* PATIENT */:
7632
+ if (!entityId) {
7633
+ throw new Error(
7634
+ "Patient ID (entityId) is required when searching patient calendar."
7635
+ );
7636
+ }
7637
+ baseCollectionPath = `${PATIENTS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
7638
+ if (filters.patientId && filters.patientId !== entityId) {
7639
+ console.warn(
7640
+ `Provided patientId filter (${filters.patientId}) does not match search entityId (${entityId}). Returning empty results.`
7641
+ );
7642
+ return [];
7643
+ }
7644
+ filters.patientId = void 0;
7645
+ break;
7646
+ case "clinic" /* CLINIC */:
7647
+ if (!entityId) {
7648
+ throw new Error(
7649
+ "Clinic ID (entityId) is required when searching clinic-related events."
7650
+ );
7651
+ }
7652
+ baseCollectionPath = CALENDAR_COLLECTION;
7653
+ constraints.push((0, import_firestore30.where)("clinicBranchId", "==", entityId));
7654
+ if (filters.clinicId && filters.clinicId !== entityId) {
7655
+ console.warn(
7656
+ `Provided clinicId filter (${filters.clinicId}) does not match search entityId (${entityId}). Returning empty results.`
7657
+ );
7658
+ return [];
7659
+ }
7660
+ filters.clinicId = void 0;
7661
+ break;
7662
+ default:
7663
+ throw new Error(`Invalid search location: ${searchLocation}`);
7664
+ }
7665
+ const collectionRef = (0, import_firestore30.collection)(db, baseCollectionPath);
7666
+ if (filters.clinicId) {
7667
+ constraints.push((0, import_firestore30.where)("clinicBranchId", "==", filters.clinicId));
7668
+ }
7669
+ if (filters.practitionerId) {
7670
+ constraints.push(
7671
+ (0, import_firestore30.where)("practitionerProfileId", "==", filters.practitionerId)
7672
+ );
7673
+ }
7674
+ if (filters.patientId) {
7675
+ constraints.push((0, import_firestore30.where)("patientProfileId", "==", filters.patientId));
7676
+ }
7677
+ if (filters.procedureId) {
7678
+ constraints.push((0, import_firestore30.where)("procedureId", "==", filters.procedureId));
7679
+ }
7680
+ if (filters.eventStatus) {
7681
+ constraints.push((0, import_firestore30.where)("status", "==", filters.eventStatus));
7682
+ }
7683
+ if (filters.eventType) {
7684
+ constraints.push((0, import_firestore30.where)("eventType", "==", filters.eventType));
7685
+ }
7686
+ if (filters.dateRange) {
7687
+ constraints.push((0, import_firestore30.where)("eventTime.start", ">=", filters.dateRange.start));
7688
+ constraints.push((0, import_firestore30.where)("eventTime.start", "<=", filters.dateRange.end));
7689
+ }
7690
+ try {
7691
+ const finalQuery = (0, import_firestore30.query)(collectionRef, ...constraints);
7692
+ const querySnapshot = await (0, import_firestore30.getDocs)(finalQuery);
7693
+ const events = querySnapshot.docs.map(
7694
+ (doc27) => ({ id: doc27.id, ...doc27.data() })
7695
+ );
7696
+ return events;
7697
+ } catch (error) {
7698
+ console.error("Error searching calendar events:", error);
7699
+ return [];
7700
+ }
7701
+ }
7702
+
7703
+ // src/services/calendar/utils/synced-calendar.utils.ts
7704
+ var import_firestore31 = require("firebase/firestore");
7451
7705
  async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendarData, generateId2) {
7452
7706
  const calendarId = generateId2();
7453
7707
  const calendarRef = getPractitionerSyncedCalendarDocRef(
@@ -7458,14 +7712,14 @@ async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendar
7458
7712
  const newCalendar = {
7459
7713
  id: calendarId,
7460
7714
  ...calendarData,
7461
- createdAt: (0, import_firestore30.serverTimestamp)(),
7462
- updatedAt: (0, import_firestore30.serverTimestamp)()
7715
+ createdAt: (0, import_firestore31.serverTimestamp)(),
7716
+ updatedAt: (0, import_firestore31.serverTimestamp)()
7463
7717
  };
7464
- await (0, import_firestore30.setDoc)(calendarRef, newCalendar);
7718
+ await (0, import_firestore31.setDoc)(calendarRef, newCalendar);
7465
7719
  return {
7466
7720
  ...newCalendar,
7467
- createdAt: import_firestore30.Timestamp.now(),
7468
- updatedAt: import_firestore30.Timestamp.now()
7721
+ createdAt: import_firestore31.Timestamp.now(),
7722
+ updatedAt: import_firestore31.Timestamp.now()
7469
7723
  };
7470
7724
  }
7471
7725
  async function createPatientSyncedCalendarUtil(db, patientId, calendarData, generateId2) {
@@ -7474,14 +7728,14 @@ async function createPatientSyncedCalendarUtil(db, patientId, calendarData, gene
7474
7728
  const newCalendar = {
7475
7729
  id: calendarId,
7476
7730
  ...calendarData,
7477
- createdAt: (0, import_firestore30.serverTimestamp)(),
7478
- updatedAt: (0, import_firestore30.serverTimestamp)()
7731
+ createdAt: (0, import_firestore31.serverTimestamp)(),
7732
+ updatedAt: (0, import_firestore31.serverTimestamp)()
7479
7733
  };
7480
- await (0, import_firestore30.setDoc)(calendarRef, newCalendar);
7734
+ await (0, import_firestore31.setDoc)(calendarRef, newCalendar);
7481
7735
  return {
7482
7736
  ...newCalendar,
7483
- createdAt: import_firestore30.Timestamp.now(),
7484
- updatedAt: import_firestore30.Timestamp.now()
7737
+ createdAt: import_firestore31.Timestamp.now(),
7738
+ updatedAt: import_firestore31.Timestamp.now()
7485
7739
  };
7486
7740
  }
7487
7741
  async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, generateId2) {
@@ -7490,14 +7744,14 @@ async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, genera
7490
7744
  const newCalendar = {
7491
7745
  id: calendarId,
7492
7746
  ...calendarData,
7493
- createdAt: (0, import_firestore30.serverTimestamp)(),
7494
- updatedAt: (0, import_firestore30.serverTimestamp)()
7747
+ createdAt: (0, import_firestore31.serverTimestamp)(),
7748
+ updatedAt: (0, import_firestore31.serverTimestamp)()
7495
7749
  };
7496
- await (0, import_firestore30.setDoc)(calendarRef, newCalendar);
7750
+ await (0, import_firestore31.setDoc)(calendarRef, newCalendar);
7497
7751
  return {
7498
7752
  ...newCalendar,
7499
- createdAt: import_firestore30.Timestamp.now(),
7500
- updatedAt: import_firestore30.Timestamp.now()
7753
+ createdAt: import_firestore31.Timestamp.now(),
7754
+ updatedAt: import_firestore31.Timestamp.now()
7501
7755
  };
7502
7756
  }
7503
7757
  async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId) {
@@ -7506,54 +7760,54 @@ async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId)
7506
7760
  practitionerId,
7507
7761
  calendarId
7508
7762
  );
7509
- const calendarDoc = await (0, import_firestore30.getDoc)(calendarRef);
7763
+ const calendarDoc = await (0, import_firestore31.getDoc)(calendarRef);
7510
7764
  if (!calendarDoc.exists()) {
7511
7765
  return null;
7512
7766
  }
7513
7767
  return calendarDoc.data();
7514
7768
  }
7515
7769
  async function getPractitionerSyncedCalendarsUtil(db, practitionerId) {
7516
- const calendarsRef = (0, import_firestore30.collection)(
7770
+ const calendarsRef = (0, import_firestore31.collection)(
7517
7771
  db,
7518
7772
  `practitioners/${practitionerId}/${SYNCED_CALENDARS_COLLECTION}`
7519
7773
  );
7520
- const q = (0, import_firestore30.query)(calendarsRef, (0, import_firestore30.orderBy)("createdAt", "desc"));
7521
- const querySnapshot = await (0, import_firestore30.getDocs)(q);
7522
- return querySnapshot.docs.map((doc26) => doc26.data());
7774
+ const q = (0, import_firestore31.query)(calendarsRef, (0, import_firestore31.orderBy)("createdAt", "desc"));
7775
+ const querySnapshot = await (0, import_firestore31.getDocs)(q);
7776
+ return querySnapshot.docs.map((doc27) => doc27.data());
7523
7777
  }
7524
7778
  async function getPatientSyncedCalendarUtil(db, patientId, calendarId) {
7525
7779
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
7526
- const calendarDoc = await (0, import_firestore30.getDoc)(calendarRef);
7780
+ const calendarDoc = await (0, import_firestore31.getDoc)(calendarRef);
7527
7781
  if (!calendarDoc.exists()) {
7528
7782
  return null;
7529
7783
  }
7530
7784
  return calendarDoc.data();
7531
7785
  }
7532
7786
  async function getPatientSyncedCalendarsUtil(db, patientId) {
7533
- const calendarsRef = (0, import_firestore30.collection)(
7787
+ const calendarsRef = (0, import_firestore31.collection)(
7534
7788
  db,
7535
7789
  `patients/${patientId}/${SYNCED_CALENDARS_COLLECTION}`
7536
7790
  );
7537
- const q = (0, import_firestore30.query)(calendarsRef, (0, import_firestore30.orderBy)("createdAt", "desc"));
7538
- const querySnapshot = await (0, import_firestore30.getDocs)(q);
7539
- return querySnapshot.docs.map((doc26) => doc26.data());
7791
+ const q = (0, import_firestore31.query)(calendarsRef, (0, import_firestore31.orderBy)("createdAt", "desc"));
7792
+ const querySnapshot = await (0, import_firestore31.getDocs)(q);
7793
+ return querySnapshot.docs.map((doc27) => doc27.data());
7540
7794
  }
7541
7795
  async function getClinicSyncedCalendarUtil(db, clinicId, calendarId) {
7542
7796
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
7543
- const calendarDoc = await (0, import_firestore30.getDoc)(calendarRef);
7797
+ const calendarDoc = await (0, import_firestore31.getDoc)(calendarRef);
7544
7798
  if (!calendarDoc.exists()) {
7545
7799
  return null;
7546
7800
  }
7547
7801
  return calendarDoc.data();
7548
7802
  }
7549
7803
  async function getClinicSyncedCalendarsUtil(db, clinicId) {
7550
- const calendarsRef = (0, import_firestore30.collection)(
7804
+ const calendarsRef = (0, import_firestore31.collection)(
7551
7805
  db,
7552
7806
  `clinics/${clinicId}/${SYNCED_CALENDARS_COLLECTION}`
7553
7807
  );
7554
- const q = (0, import_firestore30.query)(calendarsRef, (0, import_firestore30.orderBy)("createdAt", "desc"));
7555
- const querySnapshot = await (0, import_firestore30.getDocs)(q);
7556
- return querySnapshot.docs.map((doc26) => doc26.data());
7808
+ const q = (0, import_firestore31.query)(calendarsRef, (0, import_firestore31.orderBy)("createdAt", "desc"));
7809
+ const querySnapshot = await (0, import_firestore31.getDocs)(q);
7810
+ return querySnapshot.docs.map((doc27) => doc27.data());
7557
7811
  }
7558
7812
  async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendarId, updateData) {
7559
7813
  const calendarRef = getPractitionerSyncedCalendarDocRef(
@@ -7563,10 +7817,10 @@ async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendar
7563
7817
  );
7564
7818
  const updates = {
7565
7819
  ...updateData,
7566
- updatedAt: (0, import_firestore30.serverTimestamp)()
7820
+ updatedAt: (0, import_firestore31.serverTimestamp)()
7567
7821
  };
7568
- await (0, import_firestore30.updateDoc)(calendarRef, updates);
7569
- const updatedDoc = await (0, import_firestore30.getDoc)(calendarRef);
7822
+ await (0, import_firestore31.updateDoc)(calendarRef, updates);
7823
+ const updatedDoc = await (0, import_firestore31.getDoc)(calendarRef);
7570
7824
  if (!updatedDoc.exists()) {
7571
7825
  throw new Error("Synced calendar not found after update");
7572
7826
  }
@@ -7576,10 +7830,10 @@ async function updatePatientSyncedCalendarUtil(db, patientId, calendarId, update
7576
7830
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
7577
7831
  const updates = {
7578
7832
  ...updateData,
7579
- updatedAt: (0, import_firestore30.serverTimestamp)()
7833
+ updatedAt: (0, import_firestore31.serverTimestamp)()
7580
7834
  };
7581
- await (0, import_firestore30.updateDoc)(calendarRef, updates);
7582
- const updatedDoc = await (0, import_firestore30.getDoc)(calendarRef);
7835
+ await (0, import_firestore31.updateDoc)(calendarRef, updates);
7836
+ const updatedDoc = await (0, import_firestore31.getDoc)(calendarRef);
7583
7837
  if (!updatedDoc.exists()) {
7584
7838
  throw new Error("Synced calendar not found after update");
7585
7839
  }
@@ -7589,10 +7843,10 @@ async function updateClinicSyncedCalendarUtil(db, clinicId, calendarId, updateDa
7589
7843
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
7590
7844
  const updates = {
7591
7845
  ...updateData,
7592
- updatedAt: (0, import_firestore30.serverTimestamp)()
7846
+ updatedAt: (0, import_firestore31.serverTimestamp)()
7593
7847
  };
7594
- await (0, import_firestore30.updateDoc)(calendarRef, updates);
7595
- const updatedDoc = await (0, import_firestore30.getDoc)(calendarRef);
7848
+ await (0, import_firestore31.updateDoc)(calendarRef, updates);
7849
+ const updatedDoc = await (0, import_firestore31.getDoc)(calendarRef);
7596
7850
  if (!updatedDoc.exists()) {
7597
7851
  throw new Error("Synced calendar not found after update");
7598
7852
  }
@@ -7604,19 +7858,19 @@ async function deletePractitionerSyncedCalendarUtil(db, practitionerId, calendar
7604
7858
  practitionerId,
7605
7859
  calendarId
7606
7860
  );
7607
- await (0, import_firestore30.deleteDoc)(calendarRef);
7861
+ await (0, import_firestore31.deleteDoc)(calendarRef);
7608
7862
  }
7609
7863
  async function deletePatientSyncedCalendarUtil(db, patientId, calendarId) {
7610
7864
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
7611
- await (0, import_firestore30.deleteDoc)(calendarRef);
7865
+ await (0, import_firestore31.deleteDoc)(calendarRef);
7612
7866
  }
7613
7867
  async function deleteClinicSyncedCalendarUtil(db, clinicId, calendarId) {
7614
7868
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
7615
- await (0, import_firestore30.deleteDoc)(calendarRef);
7869
+ await (0, import_firestore31.deleteDoc)(calendarRef);
7616
7870
  }
7617
7871
  async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarId) {
7618
7872
  const updateData = {
7619
- lastSyncedAt: import_firestore30.Timestamp.now()
7873
+ lastSyncedAt: import_firestore31.Timestamp.now()
7620
7874
  };
7621
7875
  switch (entityType) {
7622
7876
  case "practitioner":
@@ -7646,7 +7900,7 @@ async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarI
7646
7900
  }
7647
7901
 
7648
7902
  // src/services/calendar/utils/google-calendar.utils.ts
7649
- var import_firestore31 = require("firebase/firestore");
7903
+ var import_firestore32 = require("firebase/firestore");
7650
7904
  var GOOGLE_CALENDAR_API_URL = "https://www.googleapis.com/calendar/v3";
7651
7905
  var GOOGLE_OAUTH_URL = "https://oauth2.googleapis.com/token";
7652
7906
  var CLIENT_ID = "your-client-id";
@@ -7766,7 +8020,7 @@ async function ensureValidToken(db, entityType, entityId, syncedCalendar) {
7766
8020
  tokenExpiry.setSeconds(tokenExpiry.getSeconds() + expiresIn);
7767
8021
  const updateData = {
7768
8022
  accessToken,
7769
- tokenExpiry: import_firestore31.Timestamp.fromDate(tokenExpiry)
8023
+ tokenExpiry: import_firestore32.Timestamp.fromDate(tokenExpiry)
7770
8024
  };
7771
8025
  switch (entityType) {
7772
8026
  case "practitioner":
@@ -7941,8 +8195,8 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
7941
8195
  eventName: googleEvent.summary || "External Event",
7942
8196
  eventLocation: googleEvent.location,
7943
8197
  eventTime: {
7944
- start: import_firestore31.Timestamp.fromDate(start),
7945
- end: import_firestore31.Timestamp.fromDate(end)
8198
+ start: import_firestore32.Timestamp.fromDate(start),
8199
+ end: import_firestore32.Timestamp.fromDate(end)
7946
8200
  },
7947
8201
  description: googleEvent.description || "",
7948
8202
  // External events are always set as CONFIRMED - status updates will happen externally
@@ -7956,7 +8210,7 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
7956
8210
  {
7957
8211
  eventId: googleEvent.id,
7958
8212
  syncedCalendarProvider: "google" /* GOOGLE */,
7959
- syncedAt: import_firestore31.Timestamp.now()
8213
+ syncedAt: import_firestore32.Timestamp.now()
7960
8214
  }
7961
8215
  ]
7962
8216
  };
@@ -8734,7 +8988,7 @@ var CalendarServiceV2 = class extends BaseService {
8734
8988
  return 0;
8735
8989
  }
8736
8990
  let importedEventsCount = 0;
8737
- const currentTime = import_firestore32.Timestamp.now();
8991
+ const currentTime = import_firestore33.Timestamp.now();
8738
8992
  for (const calendar of activeCalendars) {
8739
8993
  try {
8740
8994
  let externalEvents = [];
@@ -8801,7 +9055,7 @@ var CalendarServiceV2 = class extends BaseService {
8801
9055
  async createDoctorBlockingEvent(doctorId, eventData) {
8802
9056
  try {
8803
9057
  const eventId = this.generateId();
8804
- const eventRef = (0, import_firestore33.doc)(
9058
+ const eventRef = (0, import_firestore34.doc)(
8805
9059
  this.db,
8806
9060
  PRACTITIONERS_COLLECTION,
8807
9061
  doctorId,
@@ -8811,14 +9065,14 @@ var CalendarServiceV2 = class extends BaseService {
8811
9065
  const newEvent = {
8812
9066
  id: eventId,
8813
9067
  ...eventData,
8814
- createdAt: (0, import_firestore32.serverTimestamp)(),
8815
- updatedAt: (0, import_firestore32.serverTimestamp)()
9068
+ createdAt: (0, import_firestore33.serverTimestamp)(),
9069
+ updatedAt: (0, import_firestore33.serverTimestamp)()
8816
9070
  };
8817
- await (0, import_firestore33.setDoc)(eventRef, newEvent);
9071
+ await (0, import_firestore34.setDoc)(eventRef, newEvent);
8818
9072
  return {
8819
9073
  ...newEvent,
8820
- createdAt: import_firestore32.Timestamp.now(),
8821
- updatedAt: import_firestore32.Timestamp.now()
9074
+ createdAt: import_firestore33.Timestamp.now(),
9075
+ updatedAt: import_firestore33.Timestamp.now()
8822
9076
  };
8823
9077
  } catch (error) {
8824
9078
  console.error(
@@ -8836,8 +9090,8 @@ var CalendarServiceV2 = class extends BaseService {
8836
9090
  */
8837
9091
  async synchronizeExternalCalendars(lookbackDays = 7, lookforwardDays = 30) {
8838
9092
  try {
8839
- const practitionersRef = (0, import_firestore33.collection)(this.db, PRACTITIONERS_COLLECTION);
8840
- const practitionersSnapshot = await (0, import_firestore33.getDocs)(practitionersRef);
9093
+ const practitionersRef = (0, import_firestore34.collection)(this.db, PRACTITIONERS_COLLECTION);
9094
+ const practitionersSnapshot = await (0, import_firestore34.getDocs)(practitionersRef);
8841
9095
  const startDate = /* @__PURE__ */ new Date();
8842
9096
  startDate.setDate(startDate.getDate() - lookbackDays);
8843
9097
  const endDate = /* @__PURE__ */ new Date();
@@ -8895,22 +9149,22 @@ var CalendarServiceV2 = class extends BaseService {
8895
9149
  async updateExistingEventsFromExternalCalendars(doctorId, startDate, endDate) {
8896
9150
  var _a;
8897
9151
  try {
8898
- const eventsRef = (0, import_firestore33.collection)(
9152
+ const eventsRef = (0, import_firestore34.collection)(
8899
9153
  this.db,
8900
9154
  PRACTITIONERS_COLLECTION,
8901
9155
  doctorId,
8902
9156
  CALENDAR_COLLECTION
8903
9157
  );
8904
- const q = (0, import_firestore33.query)(
9158
+ const q = (0, import_firestore34.query)(
8905
9159
  eventsRef,
8906
- (0, import_firestore33.where)("syncStatus", "==", "external" /* EXTERNAL */),
8907
- (0, import_firestore33.where)("eventTime.start", ">=", import_firestore32.Timestamp.fromDate(startDate)),
8908
- (0, import_firestore33.where)("eventTime.start", "<=", import_firestore32.Timestamp.fromDate(endDate))
9160
+ (0, import_firestore34.where)("syncStatus", "==", "external" /* EXTERNAL */),
9161
+ (0, import_firestore34.where)("eventTime.start", ">=", import_firestore33.Timestamp.fromDate(startDate)),
9162
+ (0, import_firestore34.where)("eventTime.start", "<=", import_firestore33.Timestamp.fromDate(endDate))
8909
9163
  );
8910
- const eventsSnapshot = await (0, import_firestore33.getDocs)(q);
8911
- const events = eventsSnapshot.docs.map((doc26) => ({
8912
- id: doc26.id,
8913
- ...doc26.data()
9164
+ const eventsSnapshot = await (0, import_firestore34.getDocs)(q);
9165
+ const events = eventsSnapshot.docs.map((doc27) => ({
9166
+ id: doc27.id,
9167
+ ...doc27.data()
8914
9168
  }));
8915
9169
  const calendars = await this.syncedCalendarsService.getPractitionerSyncedCalendars(
8916
9170
  doctorId
@@ -9014,21 +9268,21 @@ var CalendarServiceV2 = class extends BaseService {
9014
9268
  const endTime = new Date(
9015
9269
  externalEvent.end.dateTime || externalEvent.end.date
9016
9270
  );
9017
- const eventRef = (0, import_firestore33.doc)(
9271
+ const eventRef = (0, import_firestore34.doc)(
9018
9272
  this.db,
9019
9273
  PRACTITIONERS_COLLECTION,
9020
9274
  doctorId,
9021
9275
  CALENDAR_COLLECTION,
9022
9276
  eventId
9023
9277
  );
9024
- await (0, import_firestore33.updateDoc)(eventRef, {
9278
+ await (0, import_firestore34.updateDoc)(eventRef, {
9025
9279
  eventName: externalEvent.summary || "External Event",
9026
9280
  eventTime: {
9027
- start: import_firestore32.Timestamp.fromDate(startTime),
9028
- end: import_firestore32.Timestamp.fromDate(endTime)
9281
+ start: import_firestore33.Timestamp.fromDate(startTime),
9282
+ end: import_firestore33.Timestamp.fromDate(endTime)
9029
9283
  },
9030
9284
  description: externalEvent.description || "",
9031
- updatedAt: (0, import_firestore32.serverTimestamp)()
9285
+ updatedAt: (0, import_firestore33.serverTimestamp)()
9032
9286
  });
9033
9287
  console.log(`Updated local event ${eventId} from external event`);
9034
9288
  } catch (error) {
@@ -9046,16 +9300,16 @@ var CalendarServiceV2 = class extends BaseService {
9046
9300
  */
9047
9301
  async updateEventStatus(doctorId, eventId, status) {
9048
9302
  try {
9049
- const eventRef = (0, import_firestore33.doc)(
9303
+ const eventRef = (0, import_firestore34.doc)(
9050
9304
  this.db,
9051
9305
  PRACTITIONERS_COLLECTION,
9052
9306
  doctorId,
9053
9307
  CALENDAR_COLLECTION,
9054
9308
  eventId
9055
9309
  );
9056
- await (0, import_firestore33.updateDoc)(eventRef, {
9310
+ await (0, import_firestore34.updateDoc)(eventRef, {
9057
9311
  status,
9058
- updatedAt: (0, import_firestore32.serverTimestamp)()
9312
+ updatedAt: (0, import_firestore33.serverTimestamp)()
9059
9313
  });
9060
9314
  console.log(`Updated event ${eventId} status to ${status}`);
9061
9315
  } catch (error) {
@@ -9073,6 +9327,102 @@ var CalendarServiceV2 = class extends BaseService {
9073
9327
  `Setting up scheduled calendar sync job every ${interval} hours`
9074
9328
  );
9075
9329
  }
9330
+ /**
9331
+ * Searches for calendar events based on specified criteria.
9332
+ *
9333
+ * @param {SearchCalendarEventsParams} params - The search parameters.
9334
+ * @param {SearchLocationEnum} params.searchLocation - The primary location to search (practitioner, patient, or clinic).
9335
+ * @param {string} params.entityId - The ID of the entity (practitioner, patient, or clinic) to search within/for.
9336
+ * @param {string} [params.clinicId] - Optional clinic ID to filter by.
9337
+ * @param {string} [params.practitionerId] - Optional practitioner ID to filter by.
9338
+ * @param {string} [params.patientId] - Optional patient ID to filter by.
9339
+ * @param {string} [params.procedureId] - Optional procedure ID to filter by.
9340
+ * @param {DateRange} [params.dateRange] - Optional date range to filter by (event start time).
9341
+ * @param {CalendarEventStatus} [params.eventStatus] - Optional event status to filter by.
9342
+ * @param {CalendarEventType} [params.eventType] - Optional event type to filter by.
9343
+ * @returns {Promise<CalendarEvent[]>} A promise that resolves to an array of matching calendar events.
9344
+ * @throws {Error} If the search location requires an entity ID that is not provided.
9345
+ */
9346
+ async searchCalendarEvents(params) {
9347
+ return searchCalendarEventsUtil(this.db, params);
9348
+ }
9349
+ /**
9350
+ * Gets a doctor's upcoming appointments for a specific date range
9351
+ *
9352
+ * @param {string} doctorId - ID of the practitioner
9353
+ * @param {Date} startDate - Start date of the range
9354
+ * @param {Date} endDate - End date of the range
9355
+ * @param {CalendarEventStatus} [status] - Optional status filter (defaults to CONFIRMED)
9356
+ * @returns {Promise<CalendarEvent[]>} A promise that resolves to an array of appointments
9357
+ */
9358
+ async getPractitionerUpcomingAppointments(doctorId, startDate, endDate, status = "confirmed" /* CONFIRMED */) {
9359
+ const dateRange = {
9360
+ start: import_firestore33.Timestamp.fromDate(startDate),
9361
+ end: import_firestore33.Timestamp.fromDate(endDate)
9362
+ };
9363
+ const searchParams = {
9364
+ searchLocation: "practitioner" /* PRACTITIONER */,
9365
+ entityId: doctorId,
9366
+ dateRange,
9367
+ eventStatus: status,
9368
+ eventType: "appointment" /* APPOINTMENT */
9369
+ };
9370
+ return this.searchCalendarEvents(searchParams);
9371
+ }
9372
+ /**
9373
+ * Gets a patient's appointments for a specific date range
9374
+ *
9375
+ * @param {string} patientId - ID of the patient
9376
+ * @param {Date} startDate - Start date of the range
9377
+ * @param {Date} endDate - End date of the range
9378
+ * @param {CalendarEventStatus} [status] - Optional status filter (defaults to all non-canceled appointments)
9379
+ * @returns {Promise<CalendarEvent[]>} A promise that resolves to an array of appointments
9380
+ */
9381
+ async getPatientAppointments(patientId, startDate, endDate, status) {
9382
+ const dateRange = {
9383
+ start: import_firestore33.Timestamp.fromDate(startDate),
9384
+ end: import_firestore33.Timestamp.fromDate(endDate)
9385
+ };
9386
+ const searchParams = {
9387
+ searchLocation: "patient" /* PATIENT */,
9388
+ entityId: patientId,
9389
+ dateRange,
9390
+ eventType: "appointment" /* APPOINTMENT */
9391
+ };
9392
+ if (status) {
9393
+ searchParams.eventStatus = status;
9394
+ }
9395
+ return this.searchCalendarEvents(searchParams);
9396
+ }
9397
+ /**
9398
+ * Gets all appointments for a clinic within a specific date range
9399
+ *
9400
+ * @param {string} clinicId - ID of the clinic
9401
+ * @param {Date} startDate - Start date of the range
9402
+ * @param {Date} endDate - End date of the range
9403
+ * @param {string} [doctorId] - Optional doctor ID to filter by
9404
+ * @param {CalendarEventStatus} [status] - Optional status filter
9405
+ * @returns {Promise<CalendarEvent[]>} A promise that resolves to an array of appointments
9406
+ */
9407
+ async getClinicAppointments(clinicId, startDate, endDate, doctorId, status) {
9408
+ const dateRange = {
9409
+ start: import_firestore33.Timestamp.fromDate(startDate),
9410
+ end: import_firestore33.Timestamp.fromDate(endDate)
9411
+ };
9412
+ const searchParams = {
9413
+ searchLocation: "clinic" /* CLINIC */,
9414
+ entityId: clinicId,
9415
+ dateRange,
9416
+ eventType: "appointment" /* APPOINTMENT */
9417
+ };
9418
+ if (doctorId) {
9419
+ searchParams.practitionerId = doctorId;
9420
+ }
9421
+ if (status) {
9422
+ searchParams.eventStatus = status;
9423
+ }
9424
+ return this.searchCalendarEvents(searchParams);
9425
+ }
9076
9426
  // #endregion
9077
9427
  // #region Private Helper Methods
9078
9428
  /**
@@ -9116,8 +9466,8 @@ var CalendarServiceV2 = class extends BaseService {
9116
9466
  const startDate = eventTime.start.toDate();
9117
9467
  const startTime = startDate;
9118
9468
  const endTime = eventTime.end.toDate();
9119
- const practitionerRef = (0, import_firestore33.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
9120
- const practitionerDoc = await (0, import_firestore33.getDoc)(practitionerRef);
9469
+ const practitionerRef = (0, import_firestore34.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
9470
+ const practitionerDoc = await (0, import_firestore34.getDoc)(practitionerRef);
9121
9471
  if (!practitionerDoc.exists()) {
9122
9472
  throw new Error(`Doctor with ID ${doctorId} not found`);
9123
9473
  }
@@ -9174,8 +9524,8 @@ var CalendarServiceV2 = class extends BaseService {
9174
9524
  * @returns Updated calendar event
9175
9525
  */
9176
9526
  async updateAppointmentStatus(appointmentId, clinicId, status) {
9177
- const appointmentRef = (0, import_firestore33.doc)(this.db, CALENDAR_COLLECTION, appointmentId);
9178
- const appointmentDoc = await (0, import_firestore33.getDoc)(appointmentRef);
9527
+ const appointmentRef = (0, import_firestore34.doc)(this.db, CALENDAR_COLLECTION, appointmentId);
9528
+ const appointmentDoc = await (0, import_firestore34.getDoc)(appointmentRef);
9179
9529
  if (!appointmentDoc.exists()) {
9180
9530
  throw new Error(`Appointment with ID ${appointmentId} not found`);
9181
9531
  }
@@ -9306,7 +9656,7 @@ var CalendarServiceV2 = class extends BaseService {
9306
9656
  const newSyncEvent = {
9307
9657
  eventId: result.eventIds[0],
9308
9658
  syncedCalendarProvider: calendar.provider,
9309
- syncedAt: import_firestore32.Timestamp.now()
9659
+ syncedAt: import_firestore33.Timestamp.now()
9310
9660
  };
9311
9661
  await this.updateEventWithSyncId(
9312
9662
  entityType === "doctor" ? appointment.practitionerProfileId : appointment.patientProfileId,
@@ -9330,8 +9680,8 @@ var CalendarServiceV2 = class extends BaseService {
9330
9680
  async updateEventWithSyncId(entityId, entityType, eventId, syncEvent) {
9331
9681
  try {
9332
9682
  const collectionPath = entityType === "doctor" ? `${PRACTITIONERS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}` : `${PATIENTS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
9333
- const eventRef = (0, import_firestore33.doc)(this.db, collectionPath, eventId);
9334
- const eventDoc = await (0, import_firestore33.getDoc)(eventRef);
9683
+ const eventRef = (0, import_firestore34.doc)(this.db, collectionPath, eventId);
9684
+ const eventDoc = await (0, import_firestore34.getDoc)(eventRef);
9335
9685
  if (eventDoc.exists()) {
9336
9686
  const event = eventDoc.data();
9337
9687
  const syncIds = [...event.syncedCalendarEventId || []];
@@ -9343,9 +9693,9 @@ var CalendarServiceV2 = class extends BaseService {
9343
9693
  } else {
9344
9694
  syncIds.push(syncEvent);
9345
9695
  }
9346
- await (0, import_firestore33.updateDoc)(eventRef, {
9696
+ await (0, import_firestore34.updateDoc)(eventRef, {
9347
9697
  syncedCalendarEventId: syncIds,
9348
- updatedAt: (0, import_firestore32.serverTimestamp)()
9698
+ updatedAt: (0, import_firestore33.serverTimestamp)()
9349
9699
  });
9350
9700
  console.log(
9351
9701
  `Updated event ${eventId} with sync ID ${syncEvent.eventId}`
@@ -9369,8 +9719,8 @@ var CalendarServiceV2 = class extends BaseService {
9369
9719
  * @returns Working hours for the clinic
9370
9720
  */
9371
9721
  async getClinicWorkingHours(clinicId, date) {
9372
- const clinicRef = (0, import_firestore33.doc)(this.db, CLINICS_COLLECTION, clinicId);
9373
- const clinicDoc = await (0, import_firestore33.getDoc)(clinicRef);
9722
+ const clinicRef = (0, import_firestore34.doc)(this.db, CLINICS_COLLECTION, clinicId);
9723
+ const clinicDoc = await (0, import_firestore34.getDoc)(clinicRef);
9374
9724
  if (!clinicDoc.exists()) {
9375
9725
  throw new Error(`Clinic with ID ${clinicId} not found`);
9376
9726
  }
@@ -9398,8 +9748,8 @@ var CalendarServiceV2 = class extends BaseService {
9398
9748
  * @returns Doctor's schedule
9399
9749
  */
9400
9750
  async getDoctorSchedule(doctorId, date) {
9401
- const practitionerRef = (0, import_firestore33.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
9402
- const practitionerDoc = await (0, import_firestore33.getDoc)(practitionerRef);
9751
+ const practitionerRef = (0, import_firestore34.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
9752
+ const practitionerDoc = await (0, import_firestore34.getDoc)(practitionerRef);
9403
9753
  if (!practitionerDoc.exists()) {
9404
9754
  throw new Error(`Doctor with ID ${doctorId} not found`);
9405
9755
  }
@@ -9431,19 +9781,19 @@ var CalendarServiceV2 = class extends BaseService {
9431
9781
  startOfDay.setHours(0, 0, 0, 0);
9432
9782
  const endOfDay = new Date(date);
9433
9783
  endOfDay.setHours(23, 59, 59, 999);
9434
- const appointmentsRef = (0, import_firestore33.collection)(this.db, CALENDAR_COLLECTION);
9435
- const q = (0, import_firestore33.query)(
9784
+ const appointmentsRef = (0, import_firestore34.collection)(this.db, CALENDAR_COLLECTION);
9785
+ const q = (0, import_firestore34.query)(
9436
9786
  appointmentsRef,
9437
- (0, import_firestore33.where)("practitionerProfileId", "==", doctorId),
9438
- (0, import_firestore33.where)("eventTime.start", ">=", import_firestore32.Timestamp.fromDate(startOfDay)),
9439
- (0, import_firestore33.where)("eventTime.start", "<=", import_firestore32.Timestamp.fromDate(endOfDay)),
9440
- (0, import_firestore33.where)("status", "in", [
9787
+ (0, import_firestore34.where)("practitionerProfileId", "==", doctorId),
9788
+ (0, import_firestore34.where)("eventTime.start", ">=", import_firestore33.Timestamp.fromDate(startOfDay)),
9789
+ (0, import_firestore34.where)("eventTime.start", "<=", import_firestore33.Timestamp.fromDate(endOfDay)),
9790
+ (0, import_firestore34.where)("status", "in", [
9441
9791
  "confirmed" /* CONFIRMED */,
9442
9792
  "pending" /* PENDING */
9443
9793
  ])
9444
9794
  );
9445
- const querySnapshot = await (0, import_firestore33.getDocs)(q);
9446
- return querySnapshot.docs.map((doc26) => doc26.data());
9795
+ const querySnapshot = await (0, import_firestore34.getDocs)(q);
9796
+ return querySnapshot.docs.map((doc27) => doc27.data());
9447
9797
  }
9448
9798
  /**
9449
9799
  * Calculates available time slots based on working hours, schedule and existing appointments
@@ -9500,11 +9850,11 @@ var CalendarServiceV2 = class extends BaseService {
9500
9850
  var _a;
9501
9851
  try {
9502
9852
  const [clinicDoc, practitionerDoc, patientDoc, patientSensitiveInfoDoc] = await Promise.all([
9503
- (0, import_firestore33.getDoc)((0, import_firestore33.doc)(this.db, CLINICS_COLLECTION, clinicId)),
9504
- (0, import_firestore33.getDoc)((0, import_firestore33.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId)),
9505
- (0, import_firestore33.getDoc)((0, import_firestore33.doc)(this.db, PATIENTS_COLLECTION, patientId)),
9506
- (0, import_firestore33.getDoc)(
9507
- (0, import_firestore33.doc)(
9853
+ (0, import_firestore34.getDoc)((0, import_firestore34.doc)(this.db, CLINICS_COLLECTION, clinicId)),
9854
+ (0, import_firestore34.getDoc)((0, import_firestore34.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId)),
9855
+ (0, import_firestore34.getDoc)((0, import_firestore34.doc)(this.db, PATIENTS_COLLECTION, patientId)),
9856
+ (0, import_firestore34.getDoc)(
9857
+ (0, import_firestore34.doc)(
9508
9858
  this.db,
9509
9859
  PATIENTS_COLLECTION,
9510
9860
  patientId,
@@ -9537,7 +9887,7 @@ var CalendarServiceV2 = class extends BaseService {
9537
9887
  fullName: `${sensitiveData.firstName} ${sensitiveData.lastName}`,
9538
9888
  email: sensitiveData.email || "",
9539
9889
  phone: sensitiveData.phoneNumber || null,
9540
- dateOfBirth: sensitiveData.dateOfBirth || import_firestore32.Timestamp.now(),
9890
+ dateOfBirth: sensitiveData.dateOfBirth || import_firestore33.Timestamp.now(),
9541
9891
  gender: sensitiveData.gender || "other" /* OTHER */
9542
9892
  };
9543
9893
  } else if (patientDoc.exists()) {
@@ -9546,7 +9896,7 @@ var CalendarServiceV2 = class extends BaseService {
9546
9896
  fullName: patientDoc.data().displayName,
9547
9897
  email: ((_a = patientDoc.data().contactInfo) == null ? void 0 : _a.email) || "",
9548
9898
  phone: patientDoc.data().phoneNumber || null,
9549
- dateOfBirth: patientDoc.data().dateOfBirth || import_firestore32.Timestamp.now(),
9899
+ dateOfBirth: patientDoc.data().dateOfBirth || import_firestore33.Timestamp.now(),
9550
9900
  gender: patientDoc.data().gender || "other" /* OTHER */
9551
9901
  };
9552
9902
  }
@@ -9568,7 +9918,7 @@ var CalendarServiceV2 = class extends BaseService {
9568
9918
  };
9569
9919
 
9570
9920
  // src/backoffice/services/brand.service.ts
9571
- var import_firestore34 = require("firebase/firestore");
9921
+ var import_firestore35 = require("firebase/firestore");
9572
9922
 
9573
9923
  // src/backoffice/types/brand.types.ts
9574
9924
  var BRANDS_COLLECTION = "brands";
@@ -9579,7 +9929,7 @@ var BrandService = class extends BaseService {
9579
9929
  * Gets reference to brands collection
9580
9930
  */
9581
9931
  getBrandsRef() {
9582
- return (0, import_firestore34.collection)(this.db, BRANDS_COLLECTION);
9932
+ return (0, import_firestore35.collection)(this.db, BRANDS_COLLECTION);
9583
9933
  }
9584
9934
  /**
9585
9935
  * Creates a new brand
@@ -9592,19 +9942,19 @@ var BrandService = class extends BaseService {
9592
9942
  updatedAt: now,
9593
9943
  isActive: true
9594
9944
  };
9595
- const docRef = await (0, import_firestore34.addDoc)(this.getBrandsRef(), newBrand);
9945
+ const docRef = await (0, import_firestore35.addDoc)(this.getBrandsRef(), newBrand);
9596
9946
  return { id: docRef.id, ...newBrand };
9597
9947
  }
9598
9948
  /**
9599
9949
  * Gets all active brands
9600
9950
  */
9601
9951
  async getAll() {
9602
- const q = (0, import_firestore34.query)(this.getBrandsRef(), (0, import_firestore34.where)("isActive", "==", true));
9603
- const snapshot = await (0, import_firestore34.getDocs)(q);
9952
+ const q = (0, import_firestore35.query)(this.getBrandsRef(), (0, import_firestore35.where)("isActive", "==", true));
9953
+ const snapshot = await (0, import_firestore35.getDocs)(q);
9604
9954
  return snapshot.docs.map(
9605
- (doc26) => ({
9606
- id: doc26.id,
9607
- ...doc26.data()
9955
+ (doc27) => ({
9956
+ id: doc27.id,
9957
+ ...doc27.data()
9608
9958
  })
9609
9959
  );
9610
9960
  }
@@ -9616,8 +9966,8 @@ var BrandService = class extends BaseService {
9616
9966
  ...brand,
9617
9967
  updatedAt: /* @__PURE__ */ new Date()
9618
9968
  };
9619
- const docRef = (0, import_firestore34.doc)(this.getBrandsRef(), brandId);
9620
- await (0, import_firestore34.updateDoc)(docRef, updateData);
9969
+ const docRef = (0, import_firestore35.doc)(this.getBrandsRef(), brandId);
9970
+ await (0, import_firestore35.updateDoc)(docRef, updateData);
9621
9971
  return this.getById(brandId);
9622
9972
  }
9623
9973
  /**
@@ -9632,8 +9982,8 @@ var BrandService = class extends BaseService {
9632
9982
  * Gets a brand by ID
9633
9983
  */
9634
9984
  async getById(brandId) {
9635
- const docRef = (0, import_firestore34.doc)(this.getBrandsRef(), brandId);
9636
- const docSnap = await (0, import_firestore34.getDoc)(docRef);
9985
+ const docRef = (0, import_firestore35.doc)(this.getBrandsRef(), brandId);
9986
+ const docSnap = await (0, import_firestore35.getDoc)(docRef);
9637
9987
  if (!docSnap.exists()) return null;
9638
9988
  return {
9639
9989
  id: docSnap.id,
@@ -9643,7 +9993,7 @@ var BrandService = class extends BaseService {
9643
9993
  };
9644
9994
 
9645
9995
  // src/backoffice/services/category.service.ts
9646
- var import_firestore35 = require("firebase/firestore");
9996
+ var import_firestore36 = require("firebase/firestore");
9647
9997
 
9648
9998
  // src/backoffice/types/category.types.ts
9649
9999
  var CATEGORIES_COLLECTION = "backoffice_categories";
@@ -9654,7 +10004,7 @@ var CategoryService = class extends BaseService {
9654
10004
  * Referenca na Firestore kolekciju kategorija
9655
10005
  */
9656
10006
  get categoriesRef() {
9657
- return (0, import_firestore35.collection)(this.db, CATEGORIES_COLLECTION);
10007
+ return (0, import_firestore36.collection)(this.db, CATEGORIES_COLLECTION);
9658
10008
  }
9659
10009
  /**
9660
10010
  * Kreira novu kategoriju u sistemu
@@ -9669,7 +10019,7 @@ var CategoryService = class extends BaseService {
9669
10019
  updatedAt: now,
9670
10020
  isActive: true
9671
10021
  };
9672
- const docRef = await (0, import_firestore35.addDoc)(this.categoriesRef, newCategory);
10022
+ const docRef = await (0, import_firestore36.addDoc)(this.categoriesRef, newCategory);
9673
10023
  return { id: docRef.id, ...newCategory };
9674
10024
  }
9675
10025
  /**
@@ -9677,12 +10027,12 @@ var CategoryService = class extends BaseService {
9677
10027
  * @returns Lista aktivnih kategorija
9678
10028
  */
9679
10029
  async getAll() {
9680
- const q = (0, import_firestore35.query)(this.categoriesRef, (0, import_firestore35.where)("isActive", "==", true));
9681
- const snapshot = await (0, import_firestore35.getDocs)(q);
10030
+ const q = (0, import_firestore36.query)(this.categoriesRef, (0, import_firestore36.where)("isActive", "==", true));
10031
+ const snapshot = await (0, import_firestore36.getDocs)(q);
9682
10032
  return snapshot.docs.map(
9683
- (doc26) => ({
9684
- id: doc26.id,
9685
- ...doc26.data()
10033
+ (doc27) => ({
10034
+ id: doc27.id,
10035
+ ...doc27.data()
9686
10036
  })
9687
10037
  );
9688
10038
  }
@@ -9692,16 +10042,16 @@ var CategoryService = class extends BaseService {
9692
10042
  * @returns Lista kategorija koje pripadaju traženoj familiji
9693
10043
  */
9694
10044
  async getAllByFamily(family) {
9695
- const q = (0, import_firestore35.query)(
10045
+ const q = (0, import_firestore36.query)(
9696
10046
  this.categoriesRef,
9697
- (0, import_firestore35.where)("family", "==", family),
9698
- (0, import_firestore35.where)("isActive", "==", true)
10047
+ (0, import_firestore36.where)("family", "==", family),
10048
+ (0, import_firestore36.where)("isActive", "==", true)
9699
10049
  );
9700
- const snapshot = await (0, import_firestore35.getDocs)(q);
10050
+ const snapshot = await (0, import_firestore36.getDocs)(q);
9701
10051
  return snapshot.docs.map(
9702
- (doc26) => ({
9703
- id: doc26.id,
9704
- ...doc26.data()
10052
+ (doc27) => ({
10053
+ id: doc27.id,
10054
+ ...doc27.data()
9705
10055
  })
9706
10056
  );
9707
10057
  }
@@ -9716,8 +10066,8 @@ var CategoryService = class extends BaseService {
9716
10066
  ...category,
9717
10067
  updatedAt: /* @__PURE__ */ new Date()
9718
10068
  };
9719
- const docRef = (0, import_firestore35.doc)(this.categoriesRef, id);
9720
- await (0, import_firestore35.updateDoc)(docRef, updateData);
10069
+ const docRef = (0, import_firestore36.doc)(this.categoriesRef, id);
10070
+ await (0, import_firestore36.updateDoc)(docRef, updateData);
9721
10071
  return this.getById(id);
9722
10072
  }
9723
10073
  /**
@@ -9733,8 +10083,8 @@ var CategoryService = class extends BaseService {
9733
10083
  * @returns Kategorija ili null ako ne postoji
9734
10084
  */
9735
10085
  async getById(id) {
9736
- const docRef = (0, import_firestore35.doc)(this.categoriesRef, id);
9737
- const docSnap = await (0, import_firestore35.getDoc)(docRef);
10086
+ const docRef = (0, import_firestore36.doc)(this.categoriesRef, id);
10087
+ const docSnap = await (0, import_firestore36.getDoc)(docRef);
9738
10088
  if (!docSnap.exists()) return null;
9739
10089
  return {
9740
10090
  id: docSnap.id,
@@ -9744,7 +10094,7 @@ var CategoryService = class extends BaseService {
9744
10094
  };
9745
10095
 
9746
10096
  // src/backoffice/services/subcategory.service.ts
9747
- var import_firestore36 = require("firebase/firestore");
10097
+ var import_firestore37 = require("firebase/firestore");
9748
10098
 
9749
10099
  // src/backoffice/types/subcategory.types.ts
9750
10100
  var SUBCATEGORIES_COLLECTION = "subcategories";
@@ -9756,7 +10106,7 @@ var SubcategoryService = class extends BaseService {
9756
10106
  * @param categoryId - ID roditeljske kategorije
9757
10107
  */
9758
10108
  getSubcategoriesRef(categoryId) {
9759
- return (0, import_firestore36.collection)(
10109
+ return (0, import_firestore37.collection)(
9760
10110
  this.db,
9761
10111
  CATEGORIES_COLLECTION,
9762
10112
  categoryId,
@@ -9778,7 +10128,7 @@ var SubcategoryService = class extends BaseService {
9778
10128
  updatedAt: now,
9779
10129
  isActive: true
9780
10130
  };
9781
- const docRef = await (0, import_firestore36.addDoc)(
10131
+ const docRef = await (0, import_firestore37.addDoc)(
9782
10132
  this.getSubcategoriesRef(categoryId),
9783
10133
  newSubcategory
9784
10134
  );
@@ -9790,15 +10140,15 @@ var SubcategoryService = class extends BaseService {
9790
10140
  * @returns Lista aktivnih podkategorija
9791
10141
  */
9792
10142
  async getAllByCategoryId(categoryId) {
9793
- const q = (0, import_firestore36.query)(
10143
+ const q = (0, import_firestore37.query)(
9794
10144
  this.getSubcategoriesRef(categoryId),
9795
- (0, import_firestore36.where)("isActive", "==", true)
10145
+ (0, import_firestore37.where)("isActive", "==", true)
9796
10146
  );
9797
- const snapshot = await (0, import_firestore36.getDocs)(q);
10147
+ const snapshot = await (0, import_firestore37.getDocs)(q);
9798
10148
  return snapshot.docs.map(
9799
- (doc26) => ({
9800
- id: doc26.id,
9801
- ...doc26.data()
10149
+ (doc27) => ({
10150
+ id: doc27.id,
10151
+ ...doc27.data()
9802
10152
  })
9803
10153
  );
9804
10154
  }
@@ -9814,8 +10164,8 @@ var SubcategoryService = class extends BaseService {
9814
10164
  ...subcategory,
9815
10165
  updatedAt: /* @__PURE__ */ new Date()
9816
10166
  };
9817
- const docRef = (0, import_firestore36.doc)(this.getSubcategoriesRef(categoryId), subcategoryId);
9818
- await (0, import_firestore36.updateDoc)(docRef, updateData);
10167
+ const docRef = (0, import_firestore37.doc)(this.getSubcategoriesRef(categoryId), subcategoryId);
10168
+ await (0, import_firestore37.updateDoc)(docRef, updateData);
9819
10169
  return this.getById(categoryId, subcategoryId);
9820
10170
  }
9821
10171
  /**
@@ -9833,8 +10183,8 @@ var SubcategoryService = class extends BaseService {
9833
10183
  * @returns Podkategorija ili null ako ne postoji
9834
10184
  */
9835
10185
  async getById(categoryId, subcategoryId) {
9836
- const docRef = (0, import_firestore36.doc)(this.getSubcategoriesRef(categoryId), subcategoryId);
9837
- const docSnap = await (0, import_firestore36.getDoc)(docRef);
10186
+ const docRef = (0, import_firestore37.doc)(this.getSubcategoriesRef(categoryId), subcategoryId);
10187
+ const docSnap = await (0, import_firestore37.getDoc)(docRef);
9838
10188
  if (!docSnap.exists()) return null;
9839
10189
  return {
9840
10190
  id: docSnap.id,
@@ -9844,7 +10194,7 @@ var SubcategoryService = class extends BaseService {
9844
10194
  };
9845
10195
 
9846
10196
  // src/backoffice/services/technology.service.ts
9847
- var import_firestore37 = require("firebase/firestore");
10197
+ var import_firestore38 = require("firebase/firestore");
9848
10198
 
9849
10199
  // src/backoffice/types/technology.types.ts
9850
10200
  var TECHNOLOGIES_COLLECTION = "technologies";
@@ -9859,7 +10209,7 @@ var TechnologyService = class extends BaseService {
9859
10209
  * Vraća referencu na Firestore kolekciju tehnologija
9860
10210
  */
9861
10211
  getTechnologiesRef() {
9862
- return (0, import_firestore37.collection)(this.db, TECHNOLOGIES_COLLECTION);
10212
+ return (0, import_firestore38.collection)(this.db, TECHNOLOGIES_COLLECTION);
9863
10213
  }
9864
10214
  /**
9865
10215
  * Kreira novu tehnologiju
@@ -9882,7 +10232,7 @@ var TechnologyService = class extends BaseService {
9882
10232
  benefits: technology.benefits || [],
9883
10233
  certificationRequirement: technology.certificationRequirement || DEFAULT_CERTIFICATION_REQUIREMENT
9884
10234
  };
9885
- const docRef = await (0, import_firestore37.addDoc)(this.getTechnologiesRef(), newTechnology);
10235
+ const docRef = await (0, import_firestore38.addDoc)(this.getTechnologiesRef(), newTechnology);
9886
10236
  return { id: docRef.id, ...newTechnology };
9887
10237
  }
9888
10238
  /**
@@ -9890,12 +10240,12 @@ var TechnologyService = class extends BaseService {
9890
10240
  * @returns Lista aktivnih tehnologija
9891
10241
  */
9892
10242
  async getAll() {
9893
- const q = (0, import_firestore37.query)(this.getTechnologiesRef(), (0, import_firestore37.where)("isActive", "==", true));
9894
- const snapshot = await (0, import_firestore37.getDocs)(q);
10243
+ const q = (0, import_firestore38.query)(this.getTechnologiesRef(), (0, import_firestore38.where)("isActive", "==", true));
10244
+ const snapshot = await (0, import_firestore38.getDocs)(q);
9895
10245
  return snapshot.docs.map(
9896
- (doc26) => ({
9897
- id: doc26.id,
9898
- ...doc26.data()
10246
+ (doc27) => ({
10247
+ id: doc27.id,
10248
+ ...doc27.data()
9899
10249
  })
9900
10250
  );
9901
10251
  }
@@ -9905,16 +10255,16 @@ var TechnologyService = class extends BaseService {
9905
10255
  * @returns Lista aktivnih tehnologija
9906
10256
  */
9907
10257
  async getAllByFamily(family) {
9908
- const q = (0, import_firestore37.query)(
10258
+ const q = (0, import_firestore38.query)(
9909
10259
  this.getTechnologiesRef(),
9910
- (0, import_firestore37.where)("isActive", "==", true),
9911
- (0, import_firestore37.where)("family", "==", family)
10260
+ (0, import_firestore38.where)("isActive", "==", true),
10261
+ (0, import_firestore38.where)("family", "==", family)
9912
10262
  );
9913
- const snapshot = await (0, import_firestore37.getDocs)(q);
10263
+ const snapshot = await (0, import_firestore38.getDocs)(q);
9914
10264
  return snapshot.docs.map(
9915
- (doc26) => ({
9916
- id: doc26.id,
9917
- ...doc26.data()
10265
+ (doc27) => ({
10266
+ id: doc27.id,
10267
+ ...doc27.data()
9918
10268
  })
9919
10269
  );
9920
10270
  }
@@ -9924,16 +10274,16 @@ var TechnologyService = class extends BaseService {
9924
10274
  * @returns Lista aktivnih tehnologija
9925
10275
  */
9926
10276
  async getAllByCategoryId(categoryId) {
9927
- const q = (0, import_firestore37.query)(
10277
+ const q = (0, import_firestore38.query)(
9928
10278
  this.getTechnologiesRef(),
9929
- (0, import_firestore37.where)("isActive", "==", true),
9930
- (0, import_firestore37.where)("categoryId", "==", categoryId)
10279
+ (0, import_firestore38.where)("isActive", "==", true),
10280
+ (0, import_firestore38.where)("categoryId", "==", categoryId)
9931
10281
  );
9932
- const snapshot = await (0, import_firestore37.getDocs)(q);
10282
+ const snapshot = await (0, import_firestore38.getDocs)(q);
9933
10283
  return snapshot.docs.map(
9934
- (doc26) => ({
9935
- id: doc26.id,
9936
- ...doc26.data()
10284
+ (doc27) => ({
10285
+ id: doc27.id,
10286
+ ...doc27.data()
9937
10287
  })
9938
10288
  );
9939
10289
  }
@@ -9943,16 +10293,16 @@ var TechnologyService = class extends BaseService {
9943
10293
  * @returns Lista aktivnih tehnologija
9944
10294
  */
9945
10295
  async getAllBySubcategoryId(subcategoryId) {
9946
- const q = (0, import_firestore37.query)(
10296
+ const q = (0, import_firestore38.query)(
9947
10297
  this.getTechnologiesRef(),
9948
- (0, import_firestore37.where)("isActive", "==", true),
9949
- (0, import_firestore37.where)("subcategoryId", "==", subcategoryId)
10298
+ (0, import_firestore38.where)("isActive", "==", true),
10299
+ (0, import_firestore38.where)("subcategoryId", "==", subcategoryId)
9950
10300
  );
9951
- const snapshot = await (0, import_firestore37.getDocs)(q);
10301
+ const snapshot = await (0, import_firestore38.getDocs)(q);
9952
10302
  return snapshot.docs.map(
9953
- (doc26) => ({
9954
- id: doc26.id,
9955
- ...doc26.data()
10303
+ (doc27) => ({
10304
+ id: doc27.id,
10305
+ ...doc27.data()
9956
10306
  })
9957
10307
  );
9958
10308
  }
@@ -9967,8 +10317,8 @@ var TechnologyService = class extends BaseService {
9967
10317
  ...technology,
9968
10318
  updatedAt: /* @__PURE__ */ new Date()
9969
10319
  };
9970
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
9971
- await (0, import_firestore37.updateDoc)(docRef, updateData);
10320
+ const docRef = (0, import_firestore38.doc)(this.getTechnologiesRef(), technologyId);
10321
+ await (0, import_firestore38.updateDoc)(docRef, updateData);
9972
10322
  return this.getById(technologyId);
9973
10323
  }
9974
10324
  /**
@@ -9986,8 +10336,8 @@ var TechnologyService = class extends BaseService {
9986
10336
  * @returns Tehnologija ili null ako ne postoji
9987
10337
  */
9988
10338
  async getById(technologyId) {
9989
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
9990
- const docSnap = await (0, import_firestore37.getDoc)(docRef);
10339
+ const docRef = (0, import_firestore38.doc)(this.getTechnologiesRef(), technologyId);
10340
+ const docSnap = await (0, import_firestore38.getDoc)(docRef);
9991
10341
  if (!docSnap.exists()) return null;
9992
10342
  return {
9993
10343
  id: docSnap.id,
@@ -10001,10 +10351,10 @@ var TechnologyService = class extends BaseService {
10001
10351
  * @returns Ažurirana tehnologija sa novim zahtevom
10002
10352
  */
10003
10353
  async addRequirement(technologyId, requirement) {
10004
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10354
+ const docRef = (0, import_firestore38.doc)(this.getTechnologiesRef(), technologyId);
10005
10355
  const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
10006
- await (0, import_firestore37.updateDoc)(docRef, {
10007
- [requirementType]: (0, import_firestore37.arrayUnion)(requirement),
10356
+ await (0, import_firestore38.updateDoc)(docRef, {
10357
+ [requirementType]: (0, import_firestore38.arrayUnion)(requirement),
10008
10358
  updatedAt: /* @__PURE__ */ new Date()
10009
10359
  });
10010
10360
  return this.getById(technologyId);
@@ -10016,10 +10366,10 @@ var TechnologyService = class extends BaseService {
10016
10366
  * @returns Ažurirana tehnologija bez uklonjenog zahteva
10017
10367
  */
10018
10368
  async removeRequirement(technologyId, requirement) {
10019
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10369
+ const docRef = (0, import_firestore38.doc)(this.getTechnologiesRef(), technologyId);
10020
10370
  const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
10021
- await (0, import_firestore37.updateDoc)(docRef, {
10022
- [requirementType]: (0, import_firestore37.arrayRemove)(requirement),
10371
+ await (0, import_firestore38.updateDoc)(docRef, {
10372
+ [requirementType]: (0, import_firestore38.arrayRemove)(requirement),
10023
10373
  updatedAt: /* @__PURE__ */ new Date()
10024
10374
  });
10025
10375
  return this.getById(technologyId);
@@ -10056,9 +10406,9 @@ var TechnologyService = class extends BaseService {
10056
10406
  * @returns Ažurirana tehnologija
10057
10407
  */
10058
10408
  async addBlockingCondition(technologyId, condition) {
10059
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10060
- await (0, import_firestore37.updateDoc)(docRef, {
10061
- blockingConditions: (0, import_firestore37.arrayUnion)(condition),
10409
+ const docRef = (0, import_firestore38.doc)(this.getTechnologiesRef(), technologyId);
10410
+ await (0, import_firestore38.updateDoc)(docRef, {
10411
+ blockingConditions: (0, import_firestore38.arrayUnion)(condition),
10062
10412
  updatedAt: /* @__PURE__ */ new Date()
10063
10413
  });
10064
10414
  return this.getById(technologyId);
@@ -10070,9 +10420,9 @@ var TechnologyService = class extends BaseService {
10070
10420
  * @returns Ažurirana tehnologija
10071
10421
  */
10072
10422
  async removeBlockingCondition(technologyId, condition) {
10073
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10074
- await (0, import_firestore37.updateDoc)(docRef, {
10075
- blockingConditions: (0, import_firestore37.arrayRemove)(condition),
10423
+ const docRef = (0, import_firestore38.doc)(this.getTechnologiesRef(), technologyId);
10424
+ await (0, import_firestore38.updateDoc)(docRef, {
10425
+ blockingConditions: (0, import_firestore38.arrayRemove)(condition),
10076
10426
  updatedAt: /* @__PURE__ */ new Date()
10077
10427
  });
10078
10428
  return this.getById(technologyId);
@@ -10084,9 +10434,9 @@ var TechnologyService = class extends BaseService {
10084
10434
  * @returns Ažurirana tehnologija
10085
10435
  */
10086
10436
  async addContraindication(technologyId, contraindication) {
10087
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10088
- await (0, import_firestore37.updateDoc)(docRef, {
10089
- contraindications: (0, import_firestore37.arrayUnion)(contraindication),
10437
+ const docRef = (0, import_firestore38.doc)(this.getTechnologiesRef(), technologyId);
10438
+ await (0, import_firestore38.updateDoc)(docRef, {
10439
+ contraindications: (0, import_firestore38.arrayUnion)(contraindication),
10090
10440
  updatedAt: /* @__PURE__ */ new Date()
10091
10441
  });
10092
10442
  return this.getById(technologyId);
@@ -10098,9 +10448,9 @@ var TechnologyService = class extends BaseService {
10098
10448
  * @returns Ažurirana tehnologija
10099
10449
  */
10100
10450
  async removeContraindication(technologyId, contraindication) {
10101
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10102
- await (0, import_firestore37.updateDoc)(docRef, {
10103
- contraindications: (0, import_firestore37.arrayRemove)(contraindication),
10451
+ const docRef = (0, import_firestore38.doc)(this.getTechnologiesRef(), technologyId);
10452
+ await (0, import_firestore38.updateDoc)(docRef, {
10453
+ contraindications: (0, import_firestore38.arrayRemove)(contraindication),
10104
10454
  updatedAt: /* @__PURE__ */ new Date()
10105
10455
  });
10106
10456
  return this.getById(technologyId);
@@ -10112,9 +10462,9 @@ var TechnologyService = class extends BaseService {
10112
10462
  * @returns Ažurirana tehnologija
10113
10463
  */
10114
10464
  async addBenefit(technologyId, benefit) {
10115
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10116
- await (0, import_firestore37.updateDoc)(docRef, {
10117
- benefits: (0, import_firestore37.arrayUnion)(benefit),
10465
+ const docRef = (0, import_firestore38.doc)(this.getTechnologiesRef(), technologyId);
10466
+ await (0, import_firestore38.updateDoc)(docRef, {
10467
+ benefits: (0, import_firestore38.arrayUnion)(benefit),
10118
10468
  updatedAt: /* @__PURE__ */ new Date()
10119
10469
  });
10120
10470
  return this.getById(technologyId);
@@ -10126,9 +10476,9 @@ var TechnologyService = class extends BaseService {
10126
10476
  * @returns Ažurirana tehnologija
10127
10477
  */
10128
10478
  async removeBenefit(technologyId, benefit) {
10129
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10130
- await (0, import_firestore37.updateDoc)(docRef, {
10131
- benefits: (0, import_firestore37.arrayRemove)(benefit),
10479
+ const docRef = (0, import_firestore38.doc)(this.getTechnologiesRef(), technologyId);
10480
+ await (0, import_firestore38.updateDoc)(docRef, {
10481
+ benefits: (0, import_firestore38.arrayRemove)(benefit),
10132
10482
  updatedAt: /* @__PURE__ */ new Date()
10133
10483
  });
10134
10484
  return this.getById(technologyId);
@@ -10167,8 +10517,8 @@ var TechnologyService = class extends BaseService {
10167
10517
  * @returns Ažurirana tehnologija
10168
10518
  */
10169
10519
  async updateCertificationRequirement(technologyId, certificationRequirement) {
10170
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10171
- await (0, import_firestore37.updateDoc)(docRef, {
10520
+ const docRef = (0, import_firestore38.doc)(this.getTechnologiesRef(), technologyId);
10521
+ await (0, import_firestore38.updateDoc)(docRef, {
10172
10522
  certificationRequirement,
10173
10523
  updatedAt: /* @__PURE__ */ new Date()
10174
10524
  });
@@ -10268,7 +10618,7 @@ var TechnologyService = class extends BaseService {
10268
10618
  };
10269
10619
 
10270
10620
  // src/backoffice/services/product.service.ts
10271
- var import_firestore38 = require("firebase/firestore");
10621
+ var import_firestore39 = require("firebase/firestore");
10272
10622
 
10273
10623
  // src/backoffice/types/product.types.ts
10274
10624
  var PRODUCTS_COLLECTION = "products";
@@ -10281,7 +10631,7 @@ var ProductService = class extends BaseService {
10281
10631
  * @returns Firestore collection reference
10282
10632
  */
10283
10633
  getProductsRef(technologyId) {
10284
- return (0, import_firestore38.collection)(
10634
+ return (0, import_firestore39.collection)(
10285
10635
  this.db,
10286
10636
  TECHNOLOGIES_COLLECTION,
10287
10637
  technologyId,
@@ -10301,7 +10651,7 @@ var ProductService = class extends BaseService {
10301
10651
  updatedAt: now,
10302
10652
  isActive: true
10303
10653
  };
10304
- const productRef = await (0, import_firestore38.addDoc)(
10654
+ const productRef = await (0, import_firestore39.addDoc)(
10305
10655
  this.getProductsRef(technologyId),
10306
10656
  newProduct
10307
10657
  );
@@ -10311,15 +10661,15 @@ var ProductService = class extends BaseService {
10311
10661
  * Gets all products for a technology
10312
10662
  */
10313
10663
  async getAllByTechnology(technologyId) {
10314
- const q = (0, import_firestore38.query)(
10664
+ const q = (0, import_firestore39.query)(
10315
10665
  this.getProductsRef(technologyId),
10316
- (0, import_firestore38.where)("isActive", "==", true)
10666
+ (0, import_firestore39.where)("isActive", "==", true)
10317
10667
  );
10318
- const snapshot = await (0, import_firestore38.getDocs)(q);
10668
+ const snapshot = await (0, import_firestore39.getDocs)(q);
10319
10669
  return snapshot.docs.map(
10320
- (doc26) => ({
10321
- id: doc26.id,
10322
- ...doc26.data()
10670
+ (doc27) => ({
10671
+ id: doc27.id,
10672
+ ...doc27.data()
10323
10673
  })
10324
10674
  );
10325
10675
  }
@@ -10327,21 +10677,21 @@ var ProductService = class extends BaseService {
10327
10677
  * Gets all products for a brand by filtering through all technologies
10328
10678
  */
10329
10679
  async getAllByBrand(brandId) {
10330
- const allTechnologiesRef = (0, import_firestore38.collection)(this.db, TECHNOLOGIES_COLLECTION);
10331
- const technologiesSnapshot = await (0, import_firestore38.getDocs)(allTechnologiesRef);
10680
+ const allTechnologiesRef = (0, import_firestore39.collection)(this.db, TECHNOLOGIES_COLLECTION);
10681
+ const technologiesSnapshot = await (0, import_firestore39.getDocs)(allTechnologiesRef);
10332
10682
  const products = [];
10333
10683
  for (const techDoc of technologiesSnapshot.docs) {
10334
- const q = (0, import_firestore38.query)(
10684
+ const q = (0, import_firestore39.query)(
10335
10685
  this.getProductsRef(techDoc.id),
10336
- (0, import_firestore38.where)("brandId", "==", brandId),
10337
- (0, import_firestore38.where)("isActive", "==", true)
10686
+ (0, import_firestore39.where)("brandId", "==", brandId),
10687
+ (0, import_firestore39.where)("isActive", "==", true)
10338
10688
  );
10339
- const snapshot = await (0, import_firestore38.getDocs)(q);
10689
+ const snapshot = await (0, import_firestore39.getDocs)(q);
10340
10690
  products.push(
10341
10691
  ...snapshot.docs.map(
10342
- (doc26) => ({
10343
- id: doc26.id,
10344
- ...doc26.data()
10692
+ (doc27) => ({
10693
+ id: doc27.id,
10694
+ ...doc27.data()
10345
10695
  })
10346
10696
  )
10347
10697
  );
@@ -10356,8 +10706,8 @@ var ProductService = class extends BaseService {
10356
10706
  ...product,
10357
10707
  updatedAt: /* @__PURE__ */ new Date()
10358
10708
  };
10359
- const docRef = (0, import_firestore38.doc)(this.getProductsRef(technologyId), productId);
10360
- await (0, import_firestore38.updateDoc)(docRef, updateData);
10709
+ const docRef = (0, import_firestore39.doc)(this.getProductsRef(technologyId), productId);
10710
+ await (0, import_firestore39.updateDoc)(docRef, updateData);
10361
10711
  return this.getById(technologyId, productId);
10362
10712
  }
10363
10713
  /**
@@ -10372,8 +10722,8 @@ var ProductService = class extends BaseService {
10372
10722
  * Gets a product by ID
10373
10723
  */
10374
10724
  async getById(technologyId, productId) {
10375
- const docRef = (0, import_firestore38.doc)(this.getProductsRef(technologyId), productId);
10376
- const docSnap = await (0, import_firestore38.getDoc)(docRef);
10725
+ const docRef = (0, import_firestore39.doc)(this.getProductsRef(technologyId), productId);
10726
+ const docSnap = await (0, import_firestore39.getDoc)(docRef);
10377
10727
  if (!docSnap.exists()) return null;
10378
10728
  return {
10379
10729
  id: docSnap.id,
@@ -10589,7 +10939,9 @@ var notificationSchema = import_zod19.z.discriminatedUnion("notificationType", [
10589
10939
  preRequirementNotificationSchema,
10590
10940
  procedureCategorizationSchema,
10591
10941
  procedureInfoSchema,
10942
+ requesterInfoSchema,
10592
10943
  reviewInfoSchema,
10944
+ searchPatientsSchema,
10593
10945
  serviceInfoSchema,
10594
10946
  syncedCalendarEventSchema,
10595
10947
  timeSlotSchema,