@blackcode_sa/metaestetics-api 1.5.15 → 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
@@ -2517,6 +2677,7 @@ var clinicAdminSchema = import_zod9.z.object({
2517
2677
  var adminTokenSchema = import_zod9.z.object({
2518
2678
  id: import_zod9.z.string(),
2519
2679
  token: import_zod9.z.string(),
2680
+ email: import_zod9.z.string().email().optional().nullable(),
2520
2681
  status: import_zod9.z.nativeEnum(AdminTokenStatus),
2521
2682
  usedByUserRef: import_zod9.z.string().optional(),
2522
2683
  createdAt: import_zod9.z.instanceof(Date).or(import_zod9.z.instanceof(import_firestore10.Timestamp)),
@@ -2525,7 +2686,8 @@ var adminTokenSchema = import_zod9.z.object({
2525
2686
  // Timestamp
2526
2687
  });
2527
2688
  var createAdminTokenSchema = import_zod9.z.object({
2528
- expiresInDays: import_zod9.z.number().min(1).max(30).optional()
2689
+ expiresInDays: import_zod9.z.number().min(1).max(30).optional(),
2690
+ email: import_zod9.z.string().email().optional().nullable()
2529
2691
  });
2530
2692
  var clinicGroupSchema = import_zod9.z.object({
2531
2693
  id: import_zod9.z.string(),
@@ -2889,7 +3051,7 @@ async function getClinicAdminsByGroup(db, clinicGroupId) {
2889
3051
  (0, import_firestore11.where)("clinicGroupId", "==", clinicGroupId)
2890
3052
  );
2891
3053
  const querySnapshot = await (0, import_firestore11.getDocs)(q);
2892
- return querySnapshot.docs.map((doc26) => doc26.data());
3054
+ return querySnapshot.docs.map((doc27) => doc27.data());
2893
3055
  }
2894
3056
  async function updateClinicAdmin(db, adminId, data) {
2895
3057
  const admin = await getClinicAdmin(db, adminId);
@@ -3544,7 +3706,7 @@ var PractitionerService = class extends BaseService {
3544
3706
  (0, import_firestore13.where)("expiresAt", ">", import_firestore13.Timestamp.now())
3545
3707
  );
3546
3708
  const querySnapshot = await (0, import_firestore13.getDocs)(q);
3547
- return querySnapshot.docs.map((doc26) => doc26.data());
3709
+ return querySnapshot.docs.map((doc27) => doc27.data());
3548
3710
  }
3549
3711
  /**
3550
3712
  * Gets a token by its string value and validates it
@@ -3627,7 +3789,7 @@ var PractitionerService = class extends BaseService {
3627
3789
  (0, import_firestore13.where)("status", "==", "active" /* ACTIVE */)
3628
3790
  );
3629
3791
  const querySnapshot = await (0, import_firestore13.getDocs)(q);
3630
- return querySnapshot.docs.map((doc26) => doc26.data());
3792
+ return querySnapshot.docs.map((doc27) => doc27.data());
3631
3793
  }
3632
3794
  /**
3633
3795
  * Dohvata sve zdravstvene radnike za određenu kliniku
@@ -3639,7 +3801,7 @@ var PractitionerService = class extends BaseService {
3639
3801
  (0, import_firestore13.where)("isActive", "==", true)
3640
3802
  );
3641
3803
  const querySnapshot = await (0, import_firestore13.getDocs)(q);
3642
- return querySnapshot.docs.map((doc26) => doc26.data());
3804
+ return querySnapshot.docs.map((doc27) => doc27.data());
3643
3805
  }
3644
3806
  /**
3645
3807
  * Dohvata sve draft zdravstvene radnike za određenu kliniku sa statusom DRAFT
@@ -3651,7 +3813,7 @@ var PractitionerService = class extends BaseService {
3651
3813
  (0, import_firestore13.where)("status", "==", "draft" /* DRAFT */)
3652
3814
  );
3653
3815
  const querySnapshot = await (0, import_firestore13.getDocs)(q);
3654
- return querySnapshot.docs.map((doc26) => doc26.data());
3816
+ return querySnapshot.docs.map((doc27) => doc27.data());
3655
3817
  }
3656
3818
  /**
3657
3819
  * Ažurira profil zdravstvenog radnika
@@ -3960,7 +4122,7 @@ var UserService = class extends BaseService {
3960
4122
  ];
3961
4123
  const q = (0, import_firestore14.query)((0, import_firestore14.collection)(this.db, USERS_COLLECTION), ...constraints);
3962
4124
  const querySnapshot = await (0, import_firestore14.getDocs)(q);
3963
- const users = querySnapshot.docs.map((doc26) => doc26.data());
4125
+ const users = querySnapshot.docs.map((doc27) => doc27.data());
3964
4126
  return Promise.all(users.map((userData) => userSchema.parse(userData)));
3965
4127
  }
3966
4128
  /**
@@ -4324,7 +4486,7 @@ async function getAllActiveGroups(db) {
4324
4486
  (0, import_firestore15.where)("isActive", "==", true)
4325
4487
  );
4326
4488
  const querySnapshot = await (0, import_firestore15.getDocs)(q);
4327
- return querySnapshot.docs.map((doc26) => doc26.data());
4489
+ return querySnapshot.docs.map((doc27) => doc27.data());
4328
4490
  }
4329
4491
  async function updateClinicGroup(db, groupId, data, app) {
4330
4492
  console.log("[CLINIC_GROUP] Updating clinic group", { groupId });
@@ -4438,6 +4600,7 @@ async function createAdminToken(db, groupId, creatorAdminId, app, data) {
4438
4600
  }
4439
4601
  const now = import_firestore15.Timestamp.now();
4440
4602
  const expiresInDays = (data == null ? void 0 : data.expiresInDays) || 7;
4603
+ const email = (data == null ? void 0 : data.email) || null;
4441
4604
  const expiresAt = new import_firestore15.Timestamp(
4442
4605
  now.seconds + expiresInDays * 24 * 60 * 60,
4443
4606
  now.nanoseconds
@@ -4446,6 +4609,7 @@ async function createAdminToken(db, groupId, creatorAdminId, app, data) {
4446
4609
  id: generateId(),
4447
4610
  token: generateId(),
4448
4611
  status: "active" /* ACTIVE */,
4612
+ email,
4449
4613
  createdAt: now,
4450
4614
  expiresAt
4451
4615
  };
@@ -4984,7 +5148,7 @@ async function getClinicsByGroup(db, groupId) {
4984
5148
  (0, import_firestore16.where)("isActive", "==", true)
4985
5149
  );
4986
5150
  const querySnapshot = await (0, import_firestore16.getDocs)(q);
4987
- return querySnapshot.docs.map((doc26) => doc26.data());
5151
+ return querySnapshot.docs.map((doc27) => doc27.data());
4988
5152
  }
4989
5153
  async function updateClinic(db, clinicId, data, adminId, clinicAdminService, app) {
4990
5154
  console.log("[CLINIC] Starting clinic update", { clinicId, adminId });
@@ -5196,7 +5360,7 @@ async function getClinicsByAdmin(db, adminId, options = {}, clinicAdminService,
5196
5360
  }
5197
5361
  const q = (0, import_firestore16.query)((0, import_firestore16.collection)(db, CLINICS_COLLECTION), ...constraints);
5198
5362
  const querySnapshot = await (0, import_firestore16.getDocs)(q);
5199
- return querySnapshot.docs.map((doc26) => doc26.data());
5363
+ return querySnapshot.docs.map((doc27) => doc27.data());
5200
5364
  }
5201
5365
  async function getActiveClinicsByAdmin(db, adminId, clinicAdminService, clinicGroupService) {
5202
5366
  return getClinicsByAdmin(
@@ -5338,8 +5502,8 @@ async function findClinicsInRadius(db, center, radiusInKm, filters) {
5338
5502
  }
5339
5503
  const q = (0, import_firestore18.query)((0, import_firestore18.collection)(db, CLINICS_COLLECTION), ...constraints);
5340
5504
  const querySnapshot = await (0, import_firestore18.getDocs)(q);
5341
- for (const doc26 of querySnapshot.docs) {
5342
- const clinic = doc26.data();
5505
+ for (const doc27 of querySnapshot.docs) {
5506
+ const clinic = doc27.data();
5343
5507
  const distance = (0, import_geofire_common4.distanceBetween)(
5344
5508
  [center.latitude, center.longitude],
5345
5509
  [clinic.location.latitude, clinic.location.longitude]
@@ -6271,9 +6435,9 @@ var NotificationService = class extends BaseService {
6271
6435
  (0, import_firestore20.orderBy)("notificationTime", "desc")
6272
6436
  );
6273
6437
  const querySnapshot = await (0, import_firestore20.getDocs)(q);
6274
- return querySnapshot.docs.map((doc26) => ({
6275
- id: doc26.id,
6276
- ...doc26.data()
6438
+ return querySnapshot.docs.map((doc27) => ({
6439
+ id: doc27.id,
6440
+ ...doc27.data()
6277
6441
  }));
6278
6442
  }
6279
6443
  /**
@@ -6287,9 +6451,9 @@ var NotificationService = class extends BaseService {
6287
6451
  (0, import_firestore20.orderBy)("notificationTime", "desc")
6288
6452
  );
6289
6453
  const querySnapshot = await (0, import_firestore20.getDocs)(q);
6290
- return querySnapshot.docs.map((doc26) => ({
6291
- id: doc26.id,
6292
- ...doc26.data()
6454
+ return querySnapshot.docs.map((doc27) => ({
6455
+ id: doc27.id,
6456
+ ...doc27.data()
6293
6457
  }));
6294
6458
  }
6295
6459
  /**
@@ -6361,9 +6525,9 @@ var NotificationService = class extends BaseService {
6361
6525
  (0, import_firestore20.orderBy)("notificationTime", "desc")
6362
6526
  );
6363
6527
  const querySnapshot = await (0, import_firestore20.getDocs)(q);
6364
- return querySnapshot.docs.map((doc26) => ({
6365
- id: doc26.id,
6366
- ...doc26.data()
6528
+ return querySnapshot.docs.map((doc27) => ({
6529
+ id: doc27.id,
6530
+ ...doc27.data()
6367
6531
  }));
6368
6532
  }
6369
6533
  /**
@@ -6376,9 +6540,9 @@ var NotificationService = class extends BaseService {
6376
6540
  (0, import_firestore20.orderBy)("notificationTime", "desc")
6377
6541
  );
6378
6542
  const querySnapshot = await (0, import_firestore20.getDocs)(q);
6379
- return querySnapshot.docs.map((doc26) => ({
6380
- id: doc26.id,
6381
- ...doc26.data()
6543
+ return querySnapshot.docs.map((doc27) => ({
6544
+ id: doc27.id,
6545
+ ...doc27.data()
6382
6546
  }));
6383
6547
  }
6384
6548
  };
@@ -6526,7 +6690,7 @@ var ProcedureService = class extends BaseService {
6526
6690
  (0, import_firestore21.where)("isActive", "==", true)
6527
6691
  );
6528
6692
  const snapshot = await (0, import_firestore21.getDocs)(q);
6529
- return snapshot.docs.map((doc26) => doc26.data());
6693
+ return snapshot.docs.map((doc27) => doc27.data());
6530
6694
  }
6531
6695
  /**
6532
6696
  * Gets all procedures for a practitioner
@@ -6540,7 +6704,7 @@ var ProcedureService = class extends BaseService {
6540
6704
  (0, import_firestore21.where)("isActive", "==", true)
6541
6705
  );
6542
6706
  const snapshot = await (0, import_firestore21.getDocs)(q);
6543
- return snapshot.docs.map((doc26) => doc26.data());
6707
+ return snapshot.docs.map((doc27) => doc27.data());
6544
6708
  }
6545
6709
  /**
6546
6710
  * Updates a procedure
@@ -6720,9 +6884,9 @@ var DocumentationTemplateService = class extends BaseService {
6720
6884
  const querySnapshot = await (0, import_firestore22.getDocs)(q);
6721
6885
  const templates = [];
6722
6886
  let lastVisible = null;
6723
- querySnapshot.forEach((doc26) => {
6724
- templates.push(doc26.data());
6725
- lastVisible = doc26;
6887
+ querySnapshot.forEach((doc27) => {
6888
+ templates.push(doc27.data());
6889
+ lastVisible = doc27;
6726
6890
  });
6727
6891
  return {
6728
6892
  templates,
@@ -6750,9 +6914,9 @@ var DocumentationTemplateService = class extends BaseService {
6750
6914
  const querySnapshot = await (0, import_firestore22.getDocs)(q);
6751
6915
  const templates = [];
6752
6916
  let lastVisible = null;
6753
- querySnapshot.forEach((doc26) => {
6754
- templates.push(doc26.data());
6755
- lastVisible = doc26;
6917
+ querySnapshot.forEach((doc27) => {
6918
+ templates.push(doc27.data());
6919
+ lastVisible = doc27;
6756
6920
  });
6757
6921
  return {
6758
6922
  templates,
@@ -6779,9 +6943,9 @@ var DocumentationTemplateService = class extends BaseService {
6779
6943
  const querySnapshot = await (0, import_firestore22.getDocs)(q);
6780
6944
  const templates = [];
6781
6945
  let lastVisible = null;
6782
- querySnapshot.forEach((doc26) => {
6783
- templates.push(doc26.data());
6784
- lastVisible = doc26;
6946
+ querySnapshot.forEach((doc27) => {
6947
+ templates.push(doc27.data());
6948
+ lastVisible = doc27;
6785
6949
  });
6786
6950
  return {
6787
6951
  templates,
@@ -6894,9 +7058,9 @@ var FilledDocumentService = class extends BaseService {
6894
7058
  const querySnapshot = await (0, import_firestore23.getDocs)(q);
6895
7059
  const documents = [];
6896
7060
  let lastVisible = null;
6897
- querySnapshot.forEach((doc26) => {
6898
- documents.push(doc26.data());
6899
- lastVisible = doc26;
7061
+ querySnapshot.forEach((doc27) => {
7062
+ documents.push(doc27.data());
7063
+ lastVisible = doc27;
6900
7064
  });
6901
7065
  return {
6902
7066
  documents,
@@ -6923,9 +7087,9 @@ var FilledDocumentService = class extends BaseService {
6923
7087
  const querySnapshot = await (0, import_firestore23.getDocs)(q);
6924
7088
  const documents = [];
6925
7089
  let lastVisible = null;
6926
- querySnapshot.forEach((doc26) => {
6927
- documents.push(doc26.data());
6928
- lastVisible = doc26;
7090
+ querySnapshot.forEach((doc27) => {
7091
+ documents.push(doc27.data());
7092
+ lastVisible = doc27;
6929
7093
  });
6930
7094
  return {
6931
7095
  documents,
@@ -6952,9 +7116,9 @@ var FilledDocumentService = class extends BaseService {
6952
7116
  const querySnapshot = await (0, import_firestore23.getDocs)(q);
6953
7117
  const documents = [];
6954
7118
  let lastVisible = null;
6955
- querySnapshot.forEach((doc26) => {
6956
- documents.push(doc26.data());
6957
- lastVisible = doc26;
7119
+ querySnapshot.forEach((doc27) => {
7120
+ documents.push(doc27.data());
7121
+ lastVisible = doc27;
6958
7122
  });
6959
7123
  return {
6960
7124
  documents,
@@ -6981,9 +7145,9 @@ var FilledDocumentService = class extends BaseService {
6981
7145
  const querySnapshot = await (0, import_firestore23.getDocs)(q);
6982
7146
  const documents = [];
6983
7147
  let lastVisible = null;
6984
- querySnapshot.forEach((doc26) => {
6985
- documents.push(doc26.data());
6986
- lastVisible = doc26;
7148
+ querySnapshot.forEach((doc27) => {
7149
+ documents.push(doc27.data());
7150
+ lastVisible = doc27;
6987
7151
  });
6988
7152
  return {
6989
7153
  documents,
@@ -7010,9 +7174,9 @@ var FilledDocumentService = class extends BaseService {
7010
7174
  const querySnapshot = await (0, import_firestore23.getDocs)(q);
7011
7175
  const documents = [];
7012
7176
  let lastVisible = null;
7013
- querySnapshot.forEach((doc26) => {
7014
- documents.push(doc26.data());
7015
- lastVisible = doc26;
7177
+ querySnapshot.forEach((doc27) => {
7178
+ documents.push(doc27.data());
7179
+ lastVisible = doc27;
7016
7180
  });
7017
7181
  return {
7018
7182
  documents,
@@ -7022,7 +7186,7 @@ var FilledDocumentService = class extends BaseService {
7022
7186
  };
7023
7187
 
7024
7188
  // src/services/calendar/calendar-refactored.service.ts
7025
- var import_firestore32 = require("firebase/firestore");
7189
+ var import_firestore33 = require("firebase/firestore");
7026
7190
 
7027
7191
  // src/types/calendar/synced-calendar.types.ts
7028
7192
  var SyncedCalendarProvider = /* @__PURE__ */ ((SyncedCalendarProvider3) => {
@@ -7034,7 +7198,7 @@ var SyncedCalendarProvider = /* @__PURE__ */ ((SyncedCalendarProvider3) => {
7034
7198
  var SYNCED_CALENDARS_COLLECTION = "syncedCalendars";
7035
7199
 
7036
7200
  // src/services/calendar/calendar-refactored.service.ts
7037
- var import_firestore33 = require("firebase/firestore");
7201
+ var import_firestore34 = require("firebase/firestore");
7038
7202
 
7039
7203
  // src/validations/calendar.schema.ts
7040
7204
  var import_zod18 = require("zod");
@@ -7442,8 +7606,102 @@ async function updateAppointmentUtil(db, clinicId, practitionerId, patientId, ev
7442
7606
  return clinicEvent;
7443
7607
  }
7444
7608
 
7445
- // src/services/calendar/utils/synced-calendar.utils.ts
7609
+ // src/services/calendar/utils/calendar-event.utils.ts
7446
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");
7447
7705
  async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendarData, generateId2) {
7448
7706
  const calendarId = generateId2();
7449
7707
  const calendarRef = getPractitionerSyncedCalendarDocRef(
@@ -7454,14 +7712,14 @@ async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendar
7454
7712
  const newCalendar = {
7455
7713
  id: calendarId,
7456
7714
  ...calendarData,
7457
- createdAt: (0, import_firestore30.serverTimestamp)(),
7458
- updatedAt: (0, import_firestore30.serverTimestamp)()
7715
+ createdAt: (0, import_firestore31.serverTimestamp)(),
7716
+ updatedAt: (0, import_firestore31.serverTimestamp)()
7459
7717
  };
7460
- await (0, import_firestore30.setDoc)(calendarRef, newCalendar);
7718
+ await (0, import_firestore31.setDoc)(calendarRef, newCalendar);
7461
7719
  return {
7462
7720
  ...newCalendar,
7463
- createdAt: import_firestore30.Timestamp.now(),
7464
- updatedAt: import_firestore30.Timestamp.now()
7721
+ createdAt: import_firestore31.Timestamp.now(),
7722
+ updatedAt: import_firestore31.Timestamp.now()
7465
7723
  };
7466
7724
  }
7467
7725
  async function createPatientSyncedCalendarUtil(db, patientId, calendarData, generateId2) {
@@ -7470,14 +7728,14 @@ async function createPatientSyncedCalendarUtil(db, patientId, calendarData, gene
7470
7728
  const newCalendar = {
7471
7729
  id: calendarId,
7472
7730
  ...calendarData,
7473
- createdAt: (0, import_firestore30.serverTimestamp)(),
7474
- updatedAt: (0, import_firestore30.serverTimestamp)()
7731
+ createdAt: (0, import_firestore31.serverTimestamp)(),
7732
+ updatedAt: (0, import_firestore31.serverTimestamp)()
7475
7733
  };
7476
- await (0, import_firestore30.setDoc)(calendarRef, newCalendar);
7734
+ await (0, import_firestore31.setDoc)(calendarRef, newCalendar);
7477
7735
  return {
7478
7736
  ...newCalendar,
7479
- createdAt: import_firestore30.Timestamp.now(),
7480
- updatedAt: import_firestore30.Timestamp.now()
7737
+ createdAt: import_firestore31.Timestamp.now(),
7738
+ updatedAt: import_firestore31.Timestamp.now()
7481
7739
  };
7482
7740
  }
7483
7741
  async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, generateId2) {
@@ -7486,14 +7744,14 @@ async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, genera
7486
7744
  const newCalendar = {
7487
7745
  id: calendarId,
7488
7746
  ...calendarData,
7489
- createdAt: (0, import_firestore30.serverTimestamp)(),
7490
- updatedAt: (0, import_firestore30.serverTimestamp)()
7747
+ createdAt: (0, import_firestore31.serverTimestamp)(),
7748
+ updatedAt: (0, import_firestore31.serverTimestamp)()
7491
7749
  };
7492
- await (0, import_firestore30.setDoc)(calendarRef, newCalendar);
7750
+ await (0, import_firestore31.setDoc)(calendarRef, newCalendar);
7493
7751
  return {
7494
7752
  ...newCalendar,
7495
- createdAt: import_firestore30.Timestamp.now(),
7496
- updatedAt: import_firestore30.Timestamp.now()
7753
+ createdAt: import_firestore31.Timestamp.now(),
7754
+ updatedAt: import_firestore31.Timestamp.now()
7497
7755
  };
7498
7756
  }
7499
7757
  async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId) {
@@ -7502,54 +7760,54 @@ async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId)
7502
7760
  practitionerId,
7503
7761
  calendarId
7504
7762
  );
7505
- const calendarDoc = await (0, import_firestore30.getDoc)(calendarRef);
7763
+ const calendarDoc = await (0, import_firestore31.getDoc)(calendarRef);
7506
7764
  if (!calendarDoc.exists()) {
7507
7765
  return null;
7508
7766
  }
7509
7767
  return calendarDoc.data();
7510
7768
  }
7511
7769
  async function getPractitionerSyncedCalendarsUtil(db, practitionerId) {
7512
- const calendarsRef = (0, import_firestore30.collection)(
7770
+ const calendarsRef = (0, import_firestore31.collection)(
7513
7771
  db,
7514
7772
  `practitioners/${practitionerId}/${SYNCED_CALENDARS_COLLECTION}`
7515
7773
  );
7516
- const q = (0, import_firestore30.query)(calendarsRef, (0, import_firestore30.orderBy)("createdAt", "desc"));
7517
- const querySnapshot = await (0, import_firestore30.getDocs)(q);
7518
- 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());
7519
7777
  }
7520
7778
  async function getPatientSyncedCalendarUtil(db, patientId, calendarId) {
7521
7779
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
7522
- const calendarDoc = await (0, import_firestore30.getDoc)(calendarRef);
7780
+ const calendarDoc = await (0, import_firestore31.getDoc)(calendarRef);
7523
7781
  if (!calendarDoc.exists()) {
7524
7782
  return null;
7525
7783
  }
7526
7784
  return calendarDoc.data();
7527
7785
  }
7528
7786
  async function getPatientSyncedCalendarsUtil(db, patientId) {
7529
- const calendarsRef = (0, import_firestore30.collection)(
7787
+ const calendarsRef = (0, import_firestore31.collection)(
7530
7788
  db,
7531
7789
  `patients/${patientId}/${SYNCED_CALENDARS_COLLECTION}`
7532
7790
  );
7533
- const q = (0, import_firestore30.query)(calendarsRef, (0, import_firestore30.orderBy)("createdAt", "desc"));
7534
- const querySnapshot = await (0, import_firestore30.getDocs)(q);
7535
- 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());
7536
7794
  }
7537
7795
  async function getClinicSyncedCalendarUtil(db, clinicId, calendarId) {
7538
7796
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
7539
- const calendarDoc = await (0, import_firestore30.getDoc)(calendarRef);
7797
+ const calendarDoc = await (0, import_firestore31.getDoc)(calendarRef);
7540
7798
  if (!calendarDoc.exists()) {
7541
7799
  return null;
7542
7800
  }
7543
7801
  return calendarDoc.data();
7544
7802
  }
7545
7803
  async function getClinicSyncedCalendarsUtil(db, clinicId) {
7546
- const calendarsRef = (0, import_firestore30.collection)(
7804
+ const calendarsRef = (0, import_firestore31.collection)(
7547
7805
  db,
7548
7806
  `clinics/${clinicId}/${SYNCED_CALENDARS_COLLECTION}`
7549
7807
  );
7550
- const q = (0, import_firestore30.query)(calendarsRef, (0, import_firestore30.orderBy)("createdAt", "desc"));
7551
- const querySnapshot = await (0, import_firestore30.getDocs)(q);
7552
- 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());
7553
7811
  }
7554
7812
  async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendarId, updateData) {
7555
7813
  const calendarRef = getPractitionerSyncedCalendarDocRef(
@@ -7559,10 +7817,10 @@ async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendar
7559
7817
  );
7560
7818
  const updates = {
7561
7819
  ...updateData,
7562
- updatedAt: (0, import_firestore30.serverTimestamp)()
7820
+ updatedAt: (0, import_firestore31.serverTimestamp)()
7563
7821
  };
7564
- await (0, import_firestore30.updateDoc)(calendarRef, updates);
7565
- 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);
7566
7824
  if (!updatedDoc.exists()) {
7567
7825
  throw new Error("Synced calendar not found after update");
7568
7826
  }
@@ -7572,10 +7830,10 @@ async function updatePatientSyncedCalendarUtil(db, patientId, calendarId, update
7572
7830
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
7573
7831
  const updates = {
7574
7832
  ...updateData,
7575
- updatedAt: (0, import_firestore30.serverTimestamp)()
7833
+ updatedAt: (0, import_firestore31.serverTimestamp)()
7576
7834
  };
7577
- await (0, import_firestore30.updateDoc)(calendarRef, updates);
7578
- 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);
7579
7837
  if (!updatedDoc.exists()) {
7580
7838
  throw new Error("Synced calendar not found after update");
7581
7839
  }
@@ -7585,10 +7843,10 @@ async function updateClinicSyncedCalendarUtil(db, clinicId, calendarId, updateDa
7585
7843
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
7586
7844
  const updates = {
7587
7845
  ...updateData,
7588
- updatedAt: (0, import_firestore30.serverTimestamp)()
7846
+ updatedAt: (0, import_firestore31.serverTimestamp)()
7589
7847
  };
7590
- await (0, import_firestore30.updateDoc)(calendarRef, updates);
7591
- 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);
7592
7850
  if (!updatedDoc.exists()) {
7593
7851
  throw new Error("Synced calendar not found after update");
7594
7852
  }
@@ -7600,19 +7858,19 @@ async function deletePractitionerSyncedCalendarUtil(db, practitionerId, calendar
7600
7858
  practitionerId,
7601
7859
  calendarId
7602
7860
  );
7603
- await (0, import_firestore30.deleteDoc)(calendarRef);
7861
+ await (0, import_firestore31.deleteDoc)(calendarRef);
7604
7862
  }
7605
7863
  async function deletePatientSyncedCalendarUtil(db, patientId, calendarId) {
7606
7864
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
7607
- await (0, import_firestore30.deleteDoc)(calendarRef);
7865
+ await (0, import_firestore31.deleteDoc)(calendarRef);
7608
7866
  }
7609
7867
  async function deleteClinicSyncedCalendarUtil(db, clinicId, calendarId) {
7610
7868
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
7611
- await (0, import_firestore30.deleteDoc)(calendarRef);
7869
+ await (0, import_firestore31.deleteDoc)(calendarRef);
7612
7870
  }
7613
7871
  async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarId) {
7614
7872
  const updateData = {
7615
- lastSyncedAt: import_firestore30.Timestamp.now()
7873
+ lastSyncedAt: import_firestore31.Timestamp.now()
7616
7874
  };
7617
7875
  switch (entityType) {
7618
7876
  case "practitioner":
@@ -7642,7 +7900,7 @@ async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarI
7642
7900
  }
7643
7901
 
7644
7902
  // src/services/calendar/utils/google-calendar.utils.ts
7645
- var import_firestore31 = require("firebase/firestore");
7903
+ var import_firestore32 = require("firebase/firestore");
7646
7904
  var GOOGLE_CALENDAR_API_URL = "https://www.googleapis.com/calendar/v3";
7647
7905
  var GOOGLE_OAUTH_URL = "https://oauth2.googleapis.com/token";
7648
7906
  var CLIENT_ID = "your-client-id";
@@ -7762,7 +8020,7 @@ async function ensureValidToken(db, entityType, entityId, syncedCalendar) {
7762
8020
  tokenExpiry.setSeconds(tokenExpiry.getSeconds() + expiresIn);
7763
8021
  const updateData = {
7764
8022
  accessToken,
7765
- tokenExpiry: import_firestore31.Timestamp.fromDate(tokenExpiry)
8023
+ tokenExpiry: import_firestore32.Timestamp.fromDate(tokenExpiry)
7766
8024
  };
7767
8025
  switch (entityType) {
7768
8026
  case "practitioner":
@@ -7937,8 +8195,8 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
7937
8195
  eventName: googleEvent.summary || "External Event",
7938
8196
  eventLocation: googleEvent.location,
7939
8197
  eventTime: {
7940
- start: import_firestore31.Timestamp.fromDate(start),
7941
- end: import_firestore31.Timestamp.fromDate(end)
8198
+ start: import_firestore32.Timestamp.fromDate(start),
8199
+ end: import_firestore32.Timestamp.fromDate(end)
7942
8200
  },
7943
8201
  description: googleEvent.description || "",
7944
8202
  // External events are always set as CONFIRMED - status updates will happen externally
@@ -7952,7 +8210,7 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
7952
8210
  {
7953
8211
  eventId: googleEvent.id,
7954
8212
  syncedCalendarProvider: "google" /* GOOGLE */,
7955
- syncedAt: import_firestore31.Timestamp.now()
8213
+ syncedAt: import_firestore32.Timestamp.now()
7956
8214
  }
7957
8215
  ]
7958
8216
  };
@@ -8730,7 +8988,7 @@ var CalendarServiceV2 = class extends BaseService {
8730
8988
  return 0;
8731
8989
  }
8732
8990
  let importedEventsCount = 0;
8733
- const currentTime = import_firestore32.Timestamp.now();
8991
+ const currentTime = import_firestore33.Timestamp.now();
8734
8992
  for (const calendar of activeCalendars) {
8735
8993
  try {
8736
8994
  let externalEvents = [];
@@ -8797,7 +9055,7 @@ var CalendarServiceV2 = class extends BaseService {
8797
9055
  async createDoctorBlockingEvent(doctorId, eventData) {
8798
9056
  try {
8799
9057
  const eventId = this.generateId();
8800
- const eventRef = (0, import_firestore33.doc)(
9058
+ const eventRef = (0, import_firestore34.doc)(
8801
9059
  this.db,
8802
9060
  PRACTITIONERS_COLLECTION,
8803
9061
  doctorId,
@@ -8807,14 +9065,14 @@ var CalendarServiceV2 = class extends BaseService {
8807
9065
  const newEvent = {
8808
9066
  id: eventId,
8809
9067
  ...eventData,
8810
- createdAt: (0, import_firestore32.serverTimestamp)(),
8811
- updatedAt: (0, import_firestore32.serverTimestamp)()
9068
+ createdAt: (0, import_firestore33.serverTimestamp)(),
9069
+ updatedAt: (0, import_firestore33.serverTimestamp)()
8812
9070
  };
8813
- await (0, import_firestore33.setDoc)(eventRef, newEvent);
9071
+ await (0, import_firestore34.setDoc)(eventRef, newEvent);
8814
9072
  return {
8815
9073
  ...newEvent,
8816
- createdAt: import_firestore32.Timestamp.now(),
8817
- updatedAt: import_firestore32.Timestamp.now()
9074
+ createdAt: import_firestore33.Timestamp.now(),
9075
+ updatedAt: import_firestore33.Timestamp.now()
8818
9076
  };
8819
9077
  } catch (error) {
8820
9078
  console.error(
@@ -8832,8 +9090,8 @@ var CalendarServiceV2 = class extends BaseService {
8832
9090
  */
8833
9091
  async synchronizeExternalCalendars(lookbackDays = 7, lookforwardDays = 30) {
8834
9092
  try {
8835
- const practitionersRef = (0, import_firestore33.collection)(this.db, PRACTITIONERS_COLLECTION);
8836
- 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);
8837
9095
  const startDate = /* @__PURE__ */ new Date();
8838
9096
  startDate.setDate(startDate.getDate() - lookbackDays);
8839
9097
  const endDate = /* @__PURE__ */ new Date();
@@ -8891,22 +9149,22 @@ var CalendarServiceV2 = class extends BaseService {
8891
9149
  async updateExistingEventsFromExternalCalendars(doctorId, startDate, endDate) {
8892
9150
  var _a;
8893
9151
  try {
8894
- const eventsRef = (0, import_firestore33.collection)(
9152
+ const eventsRef = (0, import_firestore34.collection)(
8895
9153
  this.db,
8896
9154
  PRACTITIONERS_COLLECTION,
8897
9155
  doctorId,
8898
9156
  CALENDAR_COLLECTION
8899
9157
  );
8900
- const q = (0, import_firestore33.query)(
9158
+ const q = (0, import_firestore34.query)(
8901
9159
  eventsRef,
8902
- (0, import_firestore33.where)("syncStatus", "==", "external" /* EXTERNAL */),
8903
- (0, import_firestore33.where)("eventTime.start", ">=", import_firestore32.Timestamp.fromDate(startDate)),
8904
- (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))
8905
9163
  );
8906
- const eventsSnapshot = await (0, import_firestore33.getDocs)(q);
8907
- const events = eventsSnapshot.docs.map((doc26) => ({
8908
- id: doc26.id,
8909
- ...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()
8910
9168
  }));
8911
9169
  const calendars = await this.syncedCalendarsService.getPractitionerSyncedCalendars(
8912
9170
  doctorId
@@ -9010,21 +9268,21 @@ var CalendarServiceV2 = class extends BaseService {
9010
9268
  const endTime = new Date(
9011
9269
  externalEvent.end.dateTime || externalEvent.end.date
9012
9270
  );
9013
- const eventRef = (0, import_firestore33.doc)(
9271
+ const eventRef = (0, import_firestore34.doc)(
9014
9272
  this.db,
9015
9273
  PRACTITIONERS_COLLECTION,
9016
9274
  doctorId,
9017
9275
  CALENDAR_COLLECTION,
9018
9276
  eventId
9019
9277
  );
9020
- await (0, import_firestore33.updateDoc)(eventRef, {
9278
+ await (0, import_firestore34.updateDoc)(eventRef, {
9021
9279
  eventName: externalEvent.summary || "External Event",
9022
9280
  eventTime: {
9023
- start: import_firestore32.Timestamp.fromDate(startTime),
9024
- end: import_firestore32.Timestamp.fromDate(endTime)
9281
+ start: import_firestore33.Timestamp.fromDate(startTime),
9282
+ end: import_firestore33.Timestamp.fromDate(endTime)
9025
9283
  },
9026
9284
  description: externalEvent.description || "",
9027
- updatedAt: (0, import_firestore32.serverTimestamp)()
9285
+ updatedAt: (0, import_firestore33.serverTimestamp)()
9028
9286
  });
9029
9287
  console.log(`Updated local event ${eventId} from external event`);
9030
9288
  } catch (error) {
@@ -9042,16 +9300,16 @@ var CalendarServiceV2 = class extends BaseService {
9042
9300
  */
9043
9301
  async updateEventStatus(doctorId, eventId, status) {
9044
9302
  try {
9045
- const eventRef = (0, import_firestore33.doc)(
9303
+ const eventRef = (0, import_firestore34.doc)(
9046
9304
  this.db,
9047
9305
  PRACTITIONERS_COLLECTION,
9048
9306
  doctorId,
9049
9307
  CALENDAR_COLLECTION,
9050
9308
  eventId
9051
9309
  );
9052
- await (0, import_firestore33.updateDoc)(eventRef, {
9310
+ await (0, import_firestore34.updateDoc)(eventRef, {
9053
9311
  status,
9054
- updatedAt: (0, import_firestore32.serverTimestamp)()
9312
+ updatedAt: (0, import_firestore33.serverTimestamp)()
9055
9313
  });
9056
9314
  console.log(`Updated event ${eventId} status to ${status}`);
9057
9315
  } catch (error) {
@@ -9069,6 +9327,102 @@ var CalendarServiceV2 = class extends BaseService {
9069
9327
  `Setting up scheduled calendar sync job every ${interval} hours`
9070
9328
  );
9071
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
+ }
9072
9426
  // #endregion
9073
9427
  // #region Private Helper Methods
9074
9428
  /**
@@ -9112,8 +9466,8 @@ var CalendarServiceV2 = class extends BaseService {
9112
9466
  const startDate = eventTime.start.toDate();
9113
9467
  const startTime = startDate;
9114
9468
  const endTime = eventTime.end.toDate();
9115
- const practitionerRef = (0, import_firestore33.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
9116
- 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);
9117
9471
  if (!practitionerDoc.exists()) {
9118
9472
  throw new Error(`Doctor with ID ${doctorId} not found`);
9119
9473
  }
@@ -9170,8 +9524,8 @@ var CalendarServiceV2 = class extends BaseService {
9170
9524
  * @returns Updated calendar event
9171
9525
  */
9172
9526
  async updateAppointmentStatus(appointmentId, clinicId, status) {
9173
- const appointmentRef = (0, import_firestore33.doc)(this.db, CALENDAR_COLLECTION, appointmentId);
9174
- 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);
9175
9529
  if (!appointmentDoc.exists()) {
9176
9530
  throw new Error(`Appointment with ID ${appointmentId} not found`);
9177
9531
  }
@@ -9302,7 +9656,7 @@ var CalendarServiceV2 = class extends BaseService {
9302
9656
  const newSyncEvent = {
9303
9657
  eventId: result.eventIds[0],
9304
9658
  syncedCalendarProvider: calendar.provider,
9305
- syncedAt: import_firestore32.Timestamp.now()
9659
+ syncedAt: import_firestore33.Timestamp.now()
9306
9660
  };
9307
9661
  await this.updateEventWithSyncId(
9308
9662
  entityType === "doctor" ? appointment.practitionerProfileId : appointment.patientProfileId,
@@ -9326,8 +9680,8 @@ var CalendarServiceV2 = class extends BaseService {
9326
9680
  async updateEventWithSyncId(entityId, entityType, eventId, syncEvent) {
9327
9681
  try {
9328
9682
  const collectionPath = entityType === "doctor" ? `${PRACTITIONERS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}` : `${PATIENTS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
9329
- const eventRef = (0, import_firestore33.doc)(this.db, collectionPath, eventId);
9330
- 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);
9331
9685
  if (eventDoc.exists()) {
9332
9686
  const event = eventDoc.data();
9333
9687
  const syncIds = [...event.syncedCalendarEventId || []];
@@ -9339,9 +9693,9 @@ var CalendarServiceV2 = class extends BaseService {
9339
9693
  } else {
9340
9694
  syncIds.push(syncEvent);
9341
9695
  }
9342
- await (0, import_firestore33.updateDoc)(eventRef, {
9696
+ await (0, import_firestore34.updateDoc)(eventRef, {
9343
9697
  syncedCalendarEventId: syncIds,
9344
- updatedAt: (0, import_firestore32.serverTimestamp)()
9698
+ updatedAt: (0, import_firestore33.serverTimestamp)()
9345
9699
  });
9346
9700
  console.log(
9347
9701
  `Updated event ${eventId} with sync ID ${syncEvent.eventId}`
@@ -9365,8 +9719,8 @@ var CalendarServiceV2 = class extends BaseService {
9365
9719
  * @returns Working hours for the clinic
9366
9720
  */
9367
9721
  async getClinicWorkingHours(clinicId, date) {
9368
- const clinicRef = (0, import_firestore33.doc)(this.db, CLINICS_COLLECTION, clinicId);
9369
- 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);
9370
9724
  if (!clinicDoc.exists()) {
9371
9725
  throw new Error(`Clinic with ID ${clinicId} not found`);
9372
9726
  }
@@ -9394,8 +9748,8 @@ var CalendarServiceV2 = class extends BaseService {
9394
9748
  * @returns Doctor's schedule
9395
9749
  */
9396
9750
  async getDoctorSchedule(doctorId, date) {
9397
- const practitionerRef = (0, import_firestore33.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
9398
- 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);
9399
9753
  if (!practitionerDoc.exists()) {
9400
9754
  throw new Error(`Doctor with ID ${doctorId} not found`);
9401
9755
  }
@@ -9427,19 +9781,19 @@ var CalendarServiceV2 = class extends BaseService {
9427
9781
  startOfDay.setHours(0, 0, 0, 0);
9428
9782
  const endOfDay = new Date(date);
9429
9783
  endOfDay.setHours(23, 59, 59, 999);
9430
- const appointmentsRef = (0, import_firestore33.collection)(this.db, CALENDAR_COLLECTION);
9431
- const q = (0, import_firestore33.query)(
9784
+ const appointmentsRef = (0, import_firestore34.collection)(this.db, CALENDAR_COLLECTION);
9785
+ const q = (0, import_firestore34.query)(
9432
9786
  appointmentsRef,
9433
- (0, import_firestore33.where)("practitionerProfileId", "==", doctorId),
9434
- (0, import_firestore33.where)("eventTime.start", ">=", import_firestore32.Timestamp.fromDate(startOfDay)),
9435
- (0, import_firestore33.where)("eventTime.start", "<=", import_firestore32.Timestamp.fromDate(endOfDay)),
9436
- (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", [
9437
9791
  "confirmed" /* CONFIRMED */,
9438
9792
  "pending" /* PENDING */
9439
9793
  ])
9440
9794
  );
9441
- const querySnapshot = await (0, import_firestore33.getDocs)(q);
9442
- return querySnapshot.docs.map((doc26) => doc26.data());
9795
+ const querySnapshot = await (0, import_firestore34.getDocs)(q);
9796
+ return querySnapshot.docs.map((doc27) => doc27.data());
9443
9797
  }
9444
9798
  /**
9445
9799
  * Calculates available time slots based on working hours, schedule and existing appointments
@@ -9496,11 +9850,11 @@ var CalendarServiceV2 = class extends BaseService {
9496
9850
  var _a;
9497
9851
  try {
9498
9852
  const [clinicDoc, practitionerDoc, patientDoc, patientSensitiveInfoDoc] = await Promise.all([
9499
- (0, import_firestore33.getDoc)((0, import_firestore33.doc)(this.db, CLINICS_COLLECTION, clinicId)),
9500
- (0, import_firestore33.getDoc)((0, import_firestore33.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId)),
9501
- (0, import_firestore33.getDoc)((0, import_firestore33.doc)(this.db, PATIENTS_COLLECTION, patientId)),
9502
- (0, import_firestore33.getDoc)(
9503
- (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)(
9504
9858
  this.db,
9505
9859
  PATIENTS_COLLECTION,
9506
9860
  patientId,
@@ -9533,7 +9887,7 @@ var CalendarServiceV2 = class extends BaseService {
9533
9887
  fullName: `${sensitiveData.firstName} ${sensitiveData.lastName}`,
9534
9888
  email: sensitiveData.email || "",
9535
9889
  phone: sensitiveData.phoneNumber || null,
9536
- dateOfBirth: sensitiveData.dateOfBirth || import_firestore32.Timestamp.now(),
9890
+ dateOfBirth: sensitiveData.dateOfBirth || import_firestore33.Timestamp.now(),
9537
9891
  gender: sensitiveData.gender || "other" /* OTHER */
9538
9892
  };
9539
9893
  } else if (patientDoc.exists()) {
@@ -9542,7 +9896,7 @@ var CalendarServiceV2 = class extends BaseService {
9542
9896
  fullName: patientDoc.data().displayName,
9543
9897
  email: ((_a = patientDoc.data().contactInfo) == null ? void 0 : _a.email) || "",
9544
9898
  phone: patientDoc.data().phoneNumber || null,
9545
- dateOfBirth: patientDoc.data().dateOfBirth || import_firestore32.Timestamp.now(),
9899
+ dateOfBirth: patientDoc.data().dateOfBirth || import_firestore33.Timestamp.now(),
9546
9900
  gender: patientDoc.data().gender || "other" /* OTHER */
9547
9901
  };
9548
9902
  }
@@ -9564,7 +9918,7 @@ var CalendarServiceV2 = class extends BaseService {
9564
9918
  };
9565
9919
 
9566
9920
  // src/backoffice/services/brand.service.ts
9567
- var import_firestore34 = require("firebase/firestore");
9921
+ var import_firestore35 = require("firebase/firestore");
9568
9922
 
9569
9923
  // src/backoffice/types/brand.types.ts
9570
9924
  var BRANDS_COLLECTION = "brands";
@@ -9575,7 +9929,7 @@ var BrandService = class extends BaseService {
9575
9929
  * Gets reference to brands collection
9576
9930
  */
9577
9931
  getBrandsRef() {
9578
- return (0, import_firestore34.collection)(this.db, BRANDS_COLLECTION);
9932
+ return (0, import_firestore35.collection)(this.db, BRANDS_COLLECTION);
9579
9933
  }
9580
9934
  /**
9581
9935
  * Creates a new brand
@@ -9588,19 +9942,19 @@ var BrandService = class extends BaseService {
9588
9942
  updatedAt: now,
9589
9943
  isActive: true
9590
9944
  };
9591
- const docRef = await (0, import_firestore34.addDoc)(this.getBrandsRef(), newBrand);
9945
+ const docRef = await (0, import_firestore35.addDoc)(this.getBrandsRef(), newBrand);
9592
9946
  return { id: docRef.id, ...newBrand };
9593
9947
  }
9594
9948
  /**
9595
9949
  * Gets all active brands
9596
9950
  */
9597
9951
  async getAll() {
9598
- const q = (0, import_firestore34.query)(this.getBrandsRef(), (0, import_firestore34.where)("isActive", "==", true));
9599
- 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);
9600
9954
  return snapshot.docs.map(
9601
- (doc26) => ({
9602
- id: doc26.id,
9603
- ...doc26.data()
9955
+ (doc27) => ({
9956
+ id: doc27.id,
9957
+ ...doc27.data()
9604
9958
  })
9605
9959
  );
9606
9960
  }
@@ -9612,8 +9966,8 @@ var BrandService = class extends BaseService {
9612
9966
  ...brand,
9613
9967
  updatedAt: /* @__PURE__ */ new Date()
9614
9968
  };
9615
- const docRef = (0, import_firestore34.doc)(this.getBrandsRef(), brandId);
9616
- 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);
9617
9971
  return this.getById(brandId);
9618
9972
  }
9619
9973
  /**
@@ -9628,8 +9982,8 @@ var BrandService = class extends BaseService {
9628
9982
  * Gets a brand by ID
9629
9983
  */
9630
9984
  async getById(brandId) {
9631
- const docRef = (0, import_firestore34.doc)(this.getBrandsRef(), brandId);
9632
- 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);
9633
9987
  if (!docSnap.exists()) return null;
9634
9988
  return {
9635
9989
  id: docSnap.id,
@@ -9639,7 +9993,7 @@ var BrandService = class extends BaseService {
9639
9993
  };
9640
9994
 
9641
9995
  // src/backoffice/services/category.service.ts
9642
- var import_firestore35 = require("firebase/firestore");
9996
+ var import_firestore36 = require("firebase/firestore");
9643
9997
 
9644
9998
  // src/backoffice/types/category.types.ts
9645
9999
  var CATEGORIES_COLLECTION = "backoffice_categories";
@@ -9650,7 +10004,7 @@ var CategoryService = class extends BaseService {
9650
10004
  * Referenca na Firestore kolekciju kategorija
9651
10005
  */
9652
10006
  get categoriesRef() {
9653
- return (0, import_firestore35.collection)(this.db, CATEGORIES_COLLECTION);
10007
+ return (0, import_firestore36.collection)(this.db, CATEGORIES_COLLECTION);
9654
10008
  }
9655
10009
  /**
9656
10010
  * Kreira novu kategoriju u sistemu
@@ -9665,7 +10019,7 @@ var CategoryService = class extends BaseService {
9665
10019
  updatedAt: now,
9666
10020
  isActive: true
9667
10021
  };
9668
- const docRef = await (0, import_firestore35.addDoc)(this.categoriesRef, newCategory);
10022
+ const docRef = await (0, import_firestore36.addDoc)(this.categoriesRef, newCategory);
9669
10023
  return { id: docRef.id, ...newCategory };
9670
10024
  }
9671
10025
  /**
@@ -9673,12 +10027,12 @@ var CategoryService = class extends BaseService {
9673
10027
  * @returns Lista aktivnih kategorija
9674
10028
  */
9675
10029
  async getAll() {
9676
- const q = (0, import_firestore35.query)(this.categoriesRef, (0, import_firestore35.where)("isActive", "==", true));
9677
- 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);
9678
10032
  return snapshot.docs.map(
9679
- (doc26) => ({
9680
- id: doc26.id,
9681
- ...doc26.data()
10033
+ (doc27) => ({
10034
+ id: doc27.id,
10035
+ ...doc27.data()
9682
10036
  })
9683
10037
  );
9684
10038
  }
@@ -9688,16 +10042,16 @@ var CategoryService = class extends BaseService {
9688
10042
  * @returns Lista kategorija koje pripadaju traženoj familiji
9689
10043
  */
9690
10044
  async getAllByFamily(family) {
9691
- const q = (0, import_firestore35.query)(
10045
+ const q = (0, import_firestore36.query)(
9692
10046
  this.categoriesRef,
9693
- (0, import_firestore35.where)("family", "==", family),
9694
- (0, import_firestore35.where)("isActive", "==", true)
10047
+ (0, import_firestore36.where)("family", "==", family),
10048
+ (0, import_firestore36.where)("isActive", "==", true)
9695
10049
  );
9696
- const snapshot = await (0, import_firestore35.getDocs)(q);
10050
+ const snapshot = await (0, import_firestore36.getDocs)(q);
9697
10051
  return snapshot.docs.map(
9698
- (doc26) => ({
9699
- id: doc26.id,
9700
- ...doc26.data()
10052
+ (doc27) => ({
10053
+ id: doc27.id,
10054
+ ...doc27.data()
9701
10055
  })
9702
10056
  );
9703
10057
  }
@@ -9712,8 +10066,8 @@ var CategoryService = class extends BaseService {
9712
10066
  ...category,
9713
10067
  updatedAt: /* @__PURE__ */ new Date()
9714
10068
  };
9715
- const docRef = (0, import_firestore35.doc)(this.categoriesRef, id);
9716
- 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);
9717
10071
  return this.getById(id);
9718
10072
  }
9719
10073
  /**
@@ -9729,8 +10083,8 @@ var CategoryService = class extends BaseService {
9729
10083
  * @returns Kategorija ili null ako ne postoji
9730
10084
  */
9731
10085
  async getById(id) {
9732
- const docRef = (0, import_firestore35.doc)(this.categoriesRef, id);
9733
- 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);
9734
10088
  if (!docSnap.exists()) return null;
9735
10089
  return {
9736
10090
  id: docSnap.id,
@@ -9740,7 +10094,7 @@ var CategoryService = class extends BaseService {
9740
10094
  };
9741
10095
 
9742
10096
  // src/backoffice/services/subcategory.service.ts
9743
- var import_firestore36 = require("firebase/firestore");
10097
+ var import_firestore37 = require("firebase/firestore");
9744
10098
 
9745
10099
  // src/backoffice/types/subcategory.types.ts
9746
10100
  var SUBCATEGORIES_COLLECTION = "subcategories";
@@ -9752,7 +10106,7 @@ var SubcategoryService = class extends BaseService {
9752
10106
  * @param categoryId - ID roditeljske kategorije
9753
10107
  */
9754
10108
  getSubcategoriesRef(categoryId) {
9755
- return (0, import_firestore36.collection)(
10109
+ return (0, import_firestore37.collection)(
9756
10110
  this.db,
9757
10111
  CATEGORIES_COLLECTION,
9758
10112
  categoryId,
@@ -9774,7 +10128,7 @@ var SubcategoryService = class extends BaseService {
9774
10128
  updatedAt: now,
9775
10129
  isActive: true
9776
10130
  };
9777
- const docRef = await (0, import_firestore36.addDoc)(
10131
+ const docRef = await (0, import_firestore37.addDoc)(
9778
10132
  this.getSubcategoriesRef(categoryId),
9779
10133
  newSubcategory
9780
10134
  );
@@ -9786,15 +10140,15 @@ var SubcategoryService = class extends BaseService {
9786
10140
  * @returns Lista aktivnih podkategorija
9787
10141
  */
9788
10142
  async getAllByCategoryId(categoryId) {
9789
- const q = (0, import_firestore36.query)(
10143
+ const q = (0, import_firestore37.query)(
9790
10144
  this.getSubcategoriesRef(categoryId),
9791
- (0, import_firestore36.where)("isActive", "==", true)
10145
+ (0, import_firestore37.where)("isActive", "==", true)
9792
10146
  );
9793
- const snapshot = await (0, import_firestore36.getDocs)(q);
10147
+ const snapshot = await (0, import_firestore37.getDocs)(q);
9794
10148
  return snapshot.docs.map(
9795
- (doc26) => ({
9796
- id: doc26.id,
9797
- ...doc26.data()
10149
+ (doc27) => ({
10150
+ id: doc27.id,
10151
+ ...doc27.data()
9798
10152
  })
9799
10153
  );
9800
10154
  }
@@ -9810,8 +10164,8 @@ var SubcategoryService = class extends BaseService {
9810
10164
  ...subcategory,
9811
10165
  updatedAt: /* @__PURE__ */ new Date()
9812
10166
  };
9813
- const docRef = (0, import_firestore36.doc)(this.getSubcategoriesRef(categoryId), subcategoryId);
9814
- 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);
9815
10169
  return this.getById(categoryId, subcategoryId);
9816
10170
  }
9817
10171
  /**
@@ -9829,8 +10183,8 @@ var SubcategoryService = class extends BaseService {
9829
10183
  * @returns Podkategorija ili null ako ne postoji
9830
10184
  */
9831
10185
  async getById(categoryId, subcategoryId) {
9832
- const docRef = (0, import_firestore36.doc)(this.getSubcategoriesRef(categoryId), subcategoryId);
9833
- 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);
9834
10188
  if (!docSnap.exists()) return null;
9835
10189
  return {
9836
10190
  id: docSnap.id,
@@ -9840,7 +10194,7 @@ var SubcategoryService = class extends BaseService {
9840
10194
  };
9841
10195
 
9842
10196
  // src/backoffice/services/technology.service.ts
9843
- var import_firestore37 = require("firebase/firestore");
10197
+ var import_firestore38 = require("firebase/firestore");
9844
10198
 
9845
10199
  // src/backoffice/types/technology.types.ts
9846
10200
  var TECHNOLOGIES_COLLECTION = "technologies";
@@ -9855,7 +10209,7 @@ var TechnologyService = class extends BaseService {
9855
10209
  * Vraća referencu na Firestore kolekciju tehnologija
9856
10210
  */
9857
10211
  getTechnologiesRef() {
9858
- return (0, import_firestore37.collection)(this.db, TECHNOLOGIES_COLLECTION);
10212
+ return (0, import_firestore38.collection)(this.db, TECHNOLOGIES_COLLECTION);
9859
10213
  }
9860
10214
  /**
9861
10215
  * Kreira novu tehnologiju
@@ -9878,7 +10232,7 @@ var TechnologyService = class extends BaseService {
9878
10232
  benefits: technology.benefits || [],
9879
10233
  certificationRequirement: technology.certificationRequirement || DEFAULT_CERTIFICATION_REQUIREMENT
9880
10234
  };
9881
- const docRef = await (0, import_firestore37.addDoc)(this.getTechnologiesRef(), newTechnology);
10235
+ const docRef = await (0, import_firestore38.addDoc)(this.getTechnologiesRef(), newTechnology);
9882
10236
  return { id: docRef.id, ...newTechnology };
9883
10237
  }
9884
10238
  /**
@@ -9886,12 +10240,12 @@ var TechnologyService = class extends BaseService {
9886
10240
  * @returns Lista aktivnih tehnologija
9887
10241
  */
9888
10242
  async getAll() {
9889
- const q = (0, import_firestore37.query)(this.getTechnologiesRef(), (0, import_firestore37.where)("isActive", "==", true));
9890
- 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);
9891
10245
  return snapshot.docs.map(
9892
- (doc26) => ({
9893
- id: doc26.id,
9894
- ...doc26.data()
10246
+ (doc27) => ({
10247
+ id: doc27.id,
10248
+ ...doc27.data()
9895
10249
  })
9896
10250
  );
9897
10251
  }
@@ -9901,16 +10255,16 @@ var TechnologyService = class extends BaseService {
9901
10255
  * @returns Lista aktivnih tehnologija
9902
10256
  */
9903
10257
  async getAllByFamily(family) {
9904
- const q = (0, import_firestore37.query)(
10258
+ const q = (0, import_firestore38.query)(
9905
10259
  this.getTechnologiesRef(),
9906
- (0, import_firestore37.where)("isActive", "==", true),
9907
- (0, import_firestore37.where)("family", "==", family)
10260
+ (0, import_firestore38.where)("isActive", "==", true),
10261
+ (0, import_firestore38.where)("family", "==", family)
9908
10262
  );
9909
- const snapshot = await (0, import_firestore37.getDocs)(q);
10263
+ const snapshot = await (0, import_firestore38.getDocs)(q);
9910
10264
  return snapshot.docs.map(
9911
- (doc26) => ({
9912
- id: doc26.id,
9913
- ...doc26.data()
10265
+ (doc27) => ({
10266
+ id: doc27.id,
10267
+ ...doc27.data()
9914
10268
  })
9915
10269
  );
9916
10270
  }
@@ -9920,16 +10274,16 @@ var TechnologyService = class extends BaseService {
9920
10274
  * @returns Lista aktivnih tehnologija
9921
10275
  */
9922
10276
  async getAllByCategoryId(categoryId) {
9923
- const q = (0, import_firestore37.query)(
10277
+ const q = (0, import_firestore38.query)(
9924
10278
  this.getTechnologiesRef(),
9925
- (0, import_firestore37.where)("isActive", "==", true),
9926
- (0, import_firestore37.where)("categoryId", "==", categoryId)
10279
+ (0, import_firestore38.where)("isActive", "==", true),
10280
+ (0, import_firestore38.where)("categoryId", "==", categoryId)
9927
10281
  );
9928
- const snapshot = await (0, import_firestore37.getDocs)(q);
10282
+ const snapshot = await (0, import_firestore38.getDocs)(q);
9929
10283
  return snapshot.docs.map(
9930
- (doc26) => ({
9931
- id: doc26.id,
9932
- ...doc26.data()
10284
+ (doc27) => ({
10285
+ id: doc27.id,
10286
+ ...doc27.data()
9933
10287
  })
9934
10288
  );
9935
10289
  }
@@ -9939,16 +10293,16 @@ var TechnologyService = class extends BaseService {
9939
10293
  * @returns Lista aktivnih tehnologija
9940
10294
  */
9941
10295
  async getAllBySubcategoryId(subcategoryId) {
9942
- const q = (0, import_firestore37.query)(
10296
+ const q = (0, import_firestore38.query)(
9943
10297
  this.getTechnologiesRef(),
9944
- (0, import_firestore37.where)("isActive", "==", true),
9945
- (0, import_firestore37.where)("subcategoryId", "==", subcategoryId)
10298
+ (0, import_firestore38.where)("isActive", "==", true),
10299
+ (0, import_firestore38.where)("subcategoryId", "==", subcategoryId)
9946
10300
  );
9947
- const snapshot = await (0, import_firestore37.getDocs)(q);
10301
+ const snapshot = await (0, import_firestore38.getDocs)(q);
9948
10302
  return snapshot.docs.map(
9949
- (doc26) => ({
9950
- id: doc26.id,
9951
- ...doc26.data()
10303
+ (doc27) => ({
10304
+ id: doc27.id,
10305
+ ...doc27.data()
9952
10306
  })
9953
10307
  );
9954
10308
  }
@@ -9963,8 +10317,8 @@ var TechnologyService = class extends BaseService {
9963
10317
  ...technology,
9964
10318
  updatedAt: /* @__PURE__ */ new Date()
9965
10319
  };
9966
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
9967
- 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);
9968
10322
  return this.getById(technologyId);
9969
10323
  }
9970
10324
  /**
@@ -9982,8 +10336,8 @@ var TechnologyService = class extends BaseService {
9982
10336
  * @returns Tehnologija ili null ako ne postoji
9983
10337
  */
9984
10338
  async getById(technologyId) {
9985
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
9986
- 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);
9987
10341
  if (!docSnap.exists()) return null;
9988
10342
  return {
9989
10343
  id: docSnap.id,
@@ -9997,10 +10351,10 @@ var TechnologyService = class extends BaseService {
9997
10351
  * @returns Ažurirana tehnologija sa novim zahtevom
9998
10352
  */
9999
10353
  async addRequirement(technologyId, requirement) {
10000
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10354
+ const docRef = (0, import_firestore38.doc)(this.getTechnologiesRef(), technologyId);
10001
10355
  const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
10002
- await (0, import_firestore37.updateDoc)(docRef, {
10003
- [requirementType]: (0, import_firestore37.arrayUnion)(requirement),
10356
+ await (0, import_firestore38.updateDoc)(docRef, {
10357
+ [requirementType]: (0, import_firestore38.arrayUnion)(requirement),
10004
10358
  updatedAt: /* @__PURE__ */ new Date()
10005
10359
  });
10006
10360
  return this.getById(technologyId);
@@ -10012,10 +10366,10 @@ var TechnologyService = class extends BaseService {
10012
10366
  * @returns Ažurirana tehnologija bez uklonjenog zahteva
10013
10367
  */
10014
10368
  async removeRequirement(technologyId, requirement) {
10015
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10369
+ const docRef = (0, import_firestore38.doc)(this.getTechnologiesRef(), technologyId);
10016
10370
  const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
10017
- await (0, import_firestore37.updateDoc)(docRef, {
10018
- [requirementType]: (0, import_firestore37.arrayRemove)(requirement),
10371
+ await (0, import_firestore38.updateDoc)(docRef, {
10372
+ [requirementType]: (0, import_firestore38.arrayRemove)(requirement),
10019
10373
  updatedAt: /* @__PURE__ */ new Date()
10020
10374
  });
10021
10375
  return this.getById(technologyId);
@@ -10052,9 +10406,9 @@ var TechnologyService = class extends BaseService {
10052
10406
  * @returns Ažurirana tehnologija
10053
10407
  */
10054
10408
  async addBlockingCondition(technologyId, condition) {
10055
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10056
- await (0, import_firestore37.updateDoc)(docRef, {
10057
- 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),
10058
10412
  updatedAt: /* @__PURE__ */ new Date()
10059
10413
  });
10060
10414
  return this.getById(technologyId);
@@ -10066,9 +10420,9 @@ var TechnologyService = class extends BaseService {
10066
10420
  * @returns Ažurirana tehnologija
10067
10421
  */
10068
10422
  async removeBlockingCondition(technologyId, condition) {
10069
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10070
- await (0, import_firestore37.updateDoc)(docRef, {
10071
- 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),
10072
10426
  updatedAt: /* @__PURE__ */ new Date()
10073
10427
  });
10074
10428
  return this.getById(technologyId);
@@ -10080,9 +10434,9 @@ var TechnologyService = class extends BaseService {
10080
10434
  * @returns Ažurirana tehnologija
10081
10435
  */
10082
10436
  async addContraindication(technologyId, contraindication) {
10083
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10084
- await (0, import_firestore37.updateDoc)(docRef, {
10085
- 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),
10086
10440
  updatedAt: /* @__PURE__ */ new Date()
10087
10441
  });
10088
10442
  return this.getById(technologyId);
@@ -10094,9 +10448,9 @@ var TechnologyService = class extends BaseService {
10094
10448
  * @returns Ažurirana tehnologija
10095
10449
  */
10096
10450
  async removeContraindication(technologyId, contraindication) {
10097
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10098
- await (0, import_firestore37.updateDoc)(docRef, {
10099
- 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),
10100
10454
  updatedAt: /* @__PURE__ */ new Date()
10101
10455
  });
10102
10456
  return this.getById(technologyId);
@@ -10108,9 +10462,9 @@ var TechnologyService = class extends BaseService {
10108
10462
  * @returns Ažurirana tehnologija
10109
10463
  */
10110
10464
  async addBenefit(technologyId, benefit) {
10111
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10112
- await (0, import_firestore37.updateDoc)(docRef, {
10113
- 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),
10114
10468
  updatedAt: /* @__PURE__ */ new Date()
10115
10469
  });
10116
10470
  return this.getById(technologyId);
@@ -10122,9 +10476,9 @@ var TechnologyService = class extends BaseService {
10122
10476
  * @returns Ažurirana tehnologija
10123
10477
  */
10124
10478
  async removeBenefit(technologyId, benefit) {
10125
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10126
- await (0, import_firestore37.updateDoc)(docRef, {
10127
- 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),
10128
10482
  updatedAt: /* @__PURE__ */ new Date()
10129
10483
  });
10130
10484
  return this.getById(technologyId);
@@ -10163,8 +10517,8 @@ var TechnologyService = class extends BaseService {
10163
10517
  * @returns Ažurirana tehnologija
10164
10518
  */
10165
10519
  async updateCertificationRequirement(technologyId, certificationRequirement) {
10166
- const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10167
- await (0, import_firestore37.updateDoc)(docRef, {
10520
+ const docRef = (0, import_firestore38.doc)(this.getTechnologiesRef(), technologyId);
10521
+ await (0, import_firestore38.updateDoc)(docRef, {
10168
10522
  certificationRequirement,
10169
10523
  updatedAt: /* @__PURE__ */ new Date()
10170
10524
  });
@@ -10264,7 +10618,7 @@ var TechnologyService = class extends BaseService {
10264
10618
  };
10265
10619
 
10266
10620
  // src/backoffice/services/product.service.ts
10267
- var import_firestore38 = require("firebase/firestore");
10621
+ var import_firestore39 = require("firebase/firestore");
10268
10622
 
10269
10623
  // src/backoffice/types/product.types.ts
10270
10624
  var PRODUCTS_COLLECTION = "products";
@@ -10277,7 +10631,7 @@ var ProductService = class extends BaseService {
10277
10631
  * @returns Firestore collection reference
10278
10632
  */
10279
10633
  getProductsRef(technologyId) {
10280
- return (0, import_firestore38.collection)(
10634
+ return (0, import_firestore39.collection)(
10281
10635
  this.db,
10282
10636
  TECHNOLOGIES_COLLECTION,
10283
10637
  technologyId,
@@ -10297,7 +10651,7 @@ var ProductService = class extends BaseService {
10297
10651
  updatedAt: now,
10298
10652
  isActive: true
10299
10653
  };
10300
- const productRef = await (0, import_firestore38.addDoc)(
10654
+ const productRef = await (0, import_firestore39.addDoc)(
10301
10655
  this.getProductsRef(technologyId),
10302
10656
  newProduct
10303
10657
  );
@@ -10307,15 +10661,15 @@ var ProductService = class extends BaseService {
10307
10661
  * Gets all products for a technology
10308
10662
  */
10309
10663
  async getAllByTechnology(technologyId) {
10310
- const q = (0, import_firestore38.query)(
10664
+ const q = (0, import_firestore39.query)(
10311
10665
  this.getProductsRef(technologyId),
10312
- (0, import_firestore38.where)("isActive", "==", true)
10666
+ (0, import_firestore39.where)("isActive", "==", true)
10313
10667
  );
10314
- const snapshot = await (0, import_firestore38.getDocs)(q);
10668
+ const snapshot = await (0, import_firestore39.getDocs)(q);
10315
10669
  return snapshot.docs.map(
10316
- (doc26) => ({
10317
- id: doc26.id,
10318
- ...doc26.data()
10670
+ (doc27) => ({
10671
+ id: doc27.id,
10672
+ ...doc27.data()
10319
10673
  })
10320
10674
  );
10321
10675
  }
@@ -10323,21 +10677,21 @@ var ProductService = class extends BaseService {
10323
10677
  * Gets all products for a brand by filtering through all technologies
10324
10678
  */
10325
10679
  async getAllByBrand(brandId) {
10326
- const allTechnologiesRef = (0, import_firestore38.collection)(this.db, TECHNOLOGIES_COLLECTION);
10327
- 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);
10328
10682
  const products = [];
10329
10683
  for (const techDoc of technologiesSnapshot.docs) {
10330
- const q = (0, import_firestore38.query)(
10684
+ const q = (0, import_firestore39.query)(
10331
10685
  this.getProductsRef(techDoc.id),
10332
- (0, import_firestore38.where)("brandId", "==", brandId),
10333
- (0, import_firestore38.where)("isActive", "==", true)
10686
+ (0, import_firestore39.where)("brandId", "==", brandId),
10687
+ (0, import_firestore39.where)("isActive", "==", true)
10334
10688
  );
10335
- const snapshot = await (0, import_firestore38.getDocs)(q);
10689
+ const snapshot = await (0, import_firestore39.getDocs)(q);
10336
10690
  products.push(
10337
10691
  ...snapshot.docs.map(
10338
- (doc26) => ({
10339
- id: doc26.id,
10340
- ...doc26.data()
10692
+ (doc27) => ({
10693
+ id: doc27.id,
10694
+ ...doc27.data()
10341
10695
  })
10342
10696
  )
10343
10697
  );
@@ -10352,8 +10706,8 @@ var ProductService = class extends BaseService {
10352
10706
  ...product,
10353
10707
  updatedAt: /* @__PURE__ */ new Date()
10354
10708
  };
10355
- const docRef = (0, import_firestore38.doc)(this.getProductsRef(technologyId), productId);
10356
- 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);
10357
10711
  return this.getById(technologyId, productId);
10358
10712
  }
10359
10713
  /**
@@ -10368,8 +10722,8 @@ var ProductService = class extends BaseService {
10368
10722
  * Gets a product by ID
10369
10723
  */
10370
10724
  async getById(technologyId, productId) {
10371
- const docRef = (0, import_firestore38.doc)(this.getProductsRef(technologyId), productId);
10372
- 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);
10373
10727
  if (!docSnap.exists()) return null;
10374
10728
  return {
10375
10729
  id: docSnap.id,
@@ -10585,7 +10939,9 @@ var notificationSchema = import_zod19.z.discriminatedUnion("notificationType", [
10585
10939
  preRequirementNotificationSchema,
10586
10940
  procedureCategorizationSchema,
10587
10941
  procedureInfoSchema,
10942
+ requesterInfoSchema,
10588
10943
  reviewInfoSchema,
10944
+ searchPatientsSchema,
10589
10945
  serviceInfoSchema,
10590
10946
  syncedCalendarEventSchema,
10591
10947
  timeSlotSchema,