@blackcode_sa/metaestetics-api 1.7.22 → 1.7.24
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.d.mts +200 -2
- package/dist/index.d.ts +200 -2
- package/dist/index.js +1036 -577
- package/dist/index.mjs +1167 -697
- package/package.json +1 -1
- package/src/index.ts +8 -0
- package/src/services/appointment/appointment.service.ts +72 -10
- package/src/services/clinic/README.md +117 -0
- package/src/services/clinic/practitioner-invite.service.ts +519 -0
- package/src/types/clinic/index.ts +3 -0
- package/src/types/clinic/practitioner-invite.types.ts +91 -0
- package/src/validations/appointment.schema.ts +33 -0
package/dist/index.mjs
CHANGED
|
@@ -464,6 +464,17 @@ var searchAppointmentsSchema = z2.object({
|
|
|
464
464
|
path: ["endDate"]
|
|
465
465
|
}
|
|
466
466
|
);
|
|
467
|
+
var rescheduleAppointmentSchema = z2.object({
|
|
468
|
+
appointmentId: z2.string().min(MIN_STRING_LENGTH, "Appointment ID is required"),
|
|
469
|
+
newStartTime: z2.any().refine(
|
|
470
|
+
(val) => val instanceof Date || (val == null ? void 0 : val._seconds) !== void 0 || (val == null ? void 0 : val.seconds) !== void 0 || typeof val === "number" || typeof val === "string" || val && typeof val.toMillis === "function",
|
|
471
|
+
"New start time must be a valid timestamp, Date object, number, or string"
|
|
472
|
+
),
|
|
473
|
+
newEndTime: z2.any().refine(
|
|
474
|
+
(val) => val instanceof Date || (val == null ? void 0 : val._seconds) !== void 0 || (val == null ? void 0 : val.seconds) !== void 0 || typeof val === "number" || typeof val === "string" || val && typeof val.toMillis === "function",
|
|
475
|
+
"New end time must be a valid timestamp, Date object, number, or string"
|
|
476
|
+
)
|
|
477
|
+
});
|
|
467
478
|
|
|
468
479
|
// src/config/firebase.ts
|
|
469
480
|
import { initializeApp } from "firebase/app";
|
|
@@ -1285,7 +1296,7 @@ var MediaService = class extends BaseService {
|
|
|
1285
1296
|
try {
|
|
1286
1297
|
const querySnapshot = await getDocs(finalQuery);
|
|
1287
1298
|
const mediaList = querySnapshot.docs.map(
|
|
1288
|
-
(
|
|
1299
|
+
(doc35) => doc35.data()
|
|
1289
1300
|
);
|
|
1290
1301
|
console.log(`[MediaService] Found ${mediaList.length} media items.`);
|
|
1291
1302
|
return mediaList;
|
|
@@ -1966,8 +1977,8 @@ var getPatientsByPractitionerUtil = async (db, practitionerId, options) => {
|
|
|
1966
1977
|
}
|
|
1967
1978
|
const patientsSnapshot = await getDocs3(q);
|
|
1968
1979
|
const patients = [];
|
|
1969
|
-
patientsSnapshot.forEach((
|
|
1970
|
-
patients.push(
|
|
1980
|
+
patientsSnapshot.forEach((doc35) => {
|
|
1981
|
+
patients.push(doc35.data());
|
|
1971
1982
|
});
|
|
1972
1983
|
console.log(
|
|
1973
1984
|
`[getPatientsByPractitionerUtil] Found ${patients.length} patients for practitioner ID: ${practitionerId}`
|
|
@@ -2197,9 +2208,9 @@ var updateAllergyUtil = async (db, patientId, data, userRef) => {
|
|
|
2197
2208
|
});
|
|
2198
2209
|
};
|
|
2199
2210
|
var removeAllergyUtil = async (db, patientId, allergyIndex, userRef) => {
|
|
2200
|
-
const
|
|
2201
|
-
if (!
|
|
2202
|
-
const medicalInfo =
|
|
2211
|
+
const doc35 = await getDoc5(getMedicalInfoDocRef(db, patientId));
|
|
2212
|
+
if (!doc35.exists()) throw new Error("Medical info not found");
|
|
2213
|
+
const medicalInfo = doc35.data();
|
|
2203
2214
|
if (allergyIndex >= medicalInfo.allergies.length) {
|
|
2204
2215
|
throw new Error("Invalid allergy index");
|
|
2205
2216
|
}
|
|
@@ -2224,9 +2235,9 @@ var addBlockingConditionUtil = async (db, patientId, data, userRef) => {
|
|
|
2224
2235
|
var updateBlockingConditionUtil = async (db, patientId, data, userRef) => {
|
|
2225
2236
|
const validatedData = updateBlockingConditionSchema.parse(data);
|
|
2226
2237
|
const { conditionIndex, ...updateData } = validatedData;
|
|
2227
|
-
const
|
|
2228
|
-
if (!
|
|
2229
|
-
const medicalInfo =
|
|
2238
|
+
const doc35 = await getDoc5(getMedicalInfoDocRef(db, patientId));
|
|
2239
|
+
if (!doc35.exists()) throw new Error("Medical info not found");
|
|
2240
|
+
const medicalInfo = doc35.data();
|
|
2230
2241
|
if (conditionIndex >= medicalInfo.blockingConditions.length) {
|
|
2231
2242
|
throw new Error("Invalid blocking condition index");
|
|
2232
2243
|
}
|
|
@@ -2242,9 +2253,9 @@ var updateBlockingConditionUtil = async (db, patientId, data, userRef) => {
|
|
|
2242
2253
|
});
|
|
2243
2254
|
};
|
|
2244
2255
|
var removeBlockingConditionUtil = async (db, patientId, conditionIndex, userRef) => {
|
|
2245
|
-
const
|
|
2246
|
-
if (!
|
|
2247
|
-
const medicalInfo =
|
|
2256
|
+
const doc35 = await getDoc5(getMedicalInfoDocRef(db, patientId));
|
|
2257
|
+
if (!doc35.exists()) throw new Error("Medical info not found");
|
|
2258
|
+
const medicalInfo = doc35.data();
|
|
2248
2259
|
if (conditionIndex >= medicalInfo.blockingConditions.length) {
|
|
2249
2260
|
throw new Error("Invalid blocking condition index");
|
|
2250
2261
|
}
|
|
@@ -2269,9 +2280,9 @@ var addContraindicationUtil = async (db, patientId, data, userRef) => {
|
|
|
2269
2280
|
var updateContraindicationUtil = async (db, patientId, data, userRef) => {
|
|
2270
2281
|
const validatedData = updateContraindicationSchema.parse(data);
|
|
2271
2282
|
const { contraindicationIndex, ...updateData } = validatedData;
|
|
2272
|
-
const
|
|
2273
|
-
if (!
|
|
2274
|
-
const medicalInfo =
|
|
2283
|
+
const doc35 = await getDoc5(getMedicalInfoDocRef(db, patientId));
|
|
2284
|
+
if (!doc35.exists()) throw new Error("Medical info not found");
|
|
2285
|
+
const medicalInfo = doc35.data();
|
|
2275
2286
|
if (contraindicationIndex >= medicalInfo.contraindications.length) {
|
|
2276
2287
|
throw new Error("Invalid contraindication index");
|
|
2277
2288
|
}
|
|
@@ -2287,9 +2298,9 @@ var updateContraindicationUtil = async (db, patientId, data, userRef) => {
|
|
|
2287
2298
|
});
|
|
2288
2299
|
};
|
|
2289
2300
|
var removeContraindicationUtil = async (db, patientId, contraindicationIndex, userRef) => {
|
|
2290
|
-
const
|
|
2291
|
-
if (!
|
|
2292
|
-
const medicalInfo =
|
|
2301
|
+
const doc35 = await getDoc5(getMedicalInfoDocRef(db, patientId));
|
|
2302
|
+
if (!doc35.exists()) throw new Error("Medical info not found");
|
|
2303
|
+
const medicalInfo = doc35.data();
|
|
2293
2304
|
if (contraindicationIndex >= medicalInfo.contraindications.length) {
|
|
2294
2305
|
throw new Error("Invalid contraindication index");
|
|
2295
2306
|
}
|
|
@@ -2314,9 +2325,9 @@ var addMedicationUtil = async (db, patientId, data, userRef) => {
|
|
|
2314
2325
|
var updateMedicationUtil = async (db, patientId, data, userRef) => {
|
|
2315
2326
|
const validatedData = updateMedicationSchema.parse(data);
|
|
2316
2327
|
const { medicationIndex, ...updateData } = validatedData;
|
|
2317
|
-
const
|
|
2318
|
-
if (!
|
|
2319
|
-
const medicalInfo =
|
|
2328
|
+
const doc35 = await getDoc5(getMedicalInfoDocRef(db, patientId));
|
|
2329
|
+
if (!doc35.exists()) throw new Error("Medical info not found");
|
|
2330
|
+
const medicalInfo = doc35.data();
|
|
2320
2331
|
if (medicationIndex >= medicalInfo.currentMedications.length) {
|
|
2321
2332
|
throw new Error("Invalid medication index");
|
|
2322
2333
|
}
|
|
@@ -2332,9 +2343,9 @@ var updateMedicationUtil = async (db, patientId, data, userRef) => {
|
|
|
2332
2343
|
});
|
|
2333
2344
|
};
|
|
2334
2345
|
var removeMedicationUtil = async (db, patientId, medicationIndex, userRef) => {
|
|
2335
|
-
const
|
|
2336
|
-
if (!
|
|
2337
|
-
const medicalInfo =
|
|
2346
|
+
const doc35 = await getDoc5(getMedicalInfoDocRef(db, patientId));
|
|
2347
|
+
if (!doc35.exists()) throw new Error("Medical info not found");
|
|
2348
|
+
const medicalInfo = doc35.data();
|
|
2338
2349
|
if (medicationIndex >= medicalInfo.currentMedications.length) {
|
|
2339
2350
|
throw new Error("Invalid medication index");
|
|
2340
2351
|
}
|
|
@@ -2613,7 +2624,7 @@ var searchPatientsUtil = async (db, params, requester) => {
|
|
|
2613
2624
|
const finalQuery = query4(patientsCollectionRef, ...constraints);
|
|
2614
2625
|
const querySnapshot = await getDocs4(finalQuery);
|
|
2615
2626
|
const patients = querySnapshot.docs.map(
|
|
2616
|
-
(
|
|
2627
|
+
(doc35) => doc35.data()
|
|
2617
2628
|
);
|
|
2618
2629
|
console.log(
|
|
2619
2630
|
`[searchPatientsUtil] Found ${patients.length} patients matching criteria.`
|
|
@@ -2645,8 +2656,8 @@ var getAllPatientsUtil = async (db, options) => {
|
|
|
2645
2656
|
}
|
|
2646
2657
|
const patientsSnapshot = await getDocs4(q);
|
|
2647
2658
|
const patients = [];
|
|
2648
|
-
patientsSnapshot.forEach((
|
|
2649
|
-
patients.push(
|
|
2659
|
+
patientsSnapshot.forEach((doc35) => {
|
|
2660
|
+
patients.push(doc35.data());
|
|
2650
2661
|
});
|
|
2651
2662
|
console.log(`[getAllPatientsUtil] Found ${patients.length} patients`);
|
|
2652
2663
|
return patients;
|
|
@@ -2879,8 +2890,8 @@ var getPatientsByClinicUtil = async (db, clinicId, options) => {
|
|
|
2879
2890
|
}
|
|
2880
2891
|
const patientsSnapshot = await getDocs5(q);
|
|
2881
2892
|
const patients = [];
|
|
2882
|
-
patientsSnapshot.forEach((
|
|
2883
|
-
patients.push(
|
|
2893
|
+
patientsSnapshot.forEach((doc35) => {
|
|
2894
|
+
patients.push(doc35.data());
|
|
2884
2895
|
});
|
|
2885
2896
|
console.log(
|
|
2886
2897
|
`[getPatientsByClinicUtil] Found ${patients.length} patients for clinic ID: ${clinicId}`
|
|
@@ -3447,6 +3458,16 @@ var ClinicPhotoTag = /* @__PURE__ */ ((ClinicPhotoTag2) => {
|
|
|
3447
3458
|
return ClinicPhotoTag2;
|
|
3448
3459
|
})(ClinicPhotoTag || {});
|
|
3449
3460
|
|
|
3461
|
+
// src/types/clinic/practitioner-invite.types.ts
|
|
3462
|
+
var PRACTITIONER_INVITES_COLLECTION = "practitioner-invites";
|
|
3463
|
+
var PractitionerInviteStatus = /* @__PURE__ */ ((PractitionerInviteStatus2) => {
|
|
3464
|
+
PractitionerInviteStatus2["PENDING"] = "pending";
|
|
3465
|
+
PractitionerInviteStatus2["ACCEPTED"] = "accepted";
|
|
3466
|
+
PractitionerInviteStatus2["REJECTED"] = "rejected";
|
|
3467
|
+
PractitionerInviteStatus2["CANCELLED"] = "cancelled";
|
|
3468
|
+
return PractitionerInviteStatus2;
|
|
3469
|
+
})(PractitionerInviteStatus || {});
|
|
3470
|
+
|
|
3450
3471
|
// src/types/clinic/index.ts
|
|
3451
3472
|
var CLINIC_GROUPS_COLLECTION = "clinic_groups";
|
|
3452
3473
|
var CLINIC_ADMINS_COLLECTION = "clinic_admins";
|
|
@@ -4150,7 +4171,7 @@ async function getClinicAdminsByGroup(db, clinicGroupId) {
|
|
|
4150
4171
|
where6("clinicGroupId", "==", clinicGroupId)
|
|
4151
4172
|
);
|
|
4152
4173
|
const querySnapshot = await getDocs6(q);
|
|
4153
|
-
return querySnapshot.docs.map((
|
|
4174
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
4154
4175
|
}
|
|
4155
4176
|
async function updateClinicAdmin(db, adminId, data) {
|
|
4156
4177
|
const admin = await getClinicAdmin(db, adminId);
|
|
@@ -4904,7 +4925,7 @@ var PractitionerService = class extends BaseService {
|
|
|
4904
4925
|
where7("expiresAt", ">", Timestamp10.now())
|
|
4905
4926
|
);
|
|
4906
4927
|
const querySnapshot = await getDocs7(q);
|
|
4907
|
-
return querySnapshot.docs.map((
|
|
4928
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
4908
4929
|
}
|
|
4909
4930
|
/**
|
|
4910
4931
|
* Gets a token by its string value and validates it
|
|
@@ -5014,7 +5035,7 @@ var PractitionerService = class extends BaseService {
|
|
|
5014
5035
|
where7("status", "==", "active" /* ACTIVE */)
|
|
5015
5036
|
);
|
|
5016
5037
|
const querySnapshot = await getDocs7(q);
|
|
5017
|
-
return querySnapshot.docs.map((
|
|
5038
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
5018
5039
|
}
|
|
5019
5040
|
/**
|
|
5020
5041
|
* Dohvata sve zdravstvene radnike za određenu kliniku
|
|
@@ -5026,7 +5047,7 @@ var PractitionerService = class extends BaseService {
|
|
|
5026
5047
|
where7("isActive", "==", true)
|
|
5027
5048
|
);
|
|
5028
5049
|
const querySnapshot = await getDocs7(q);
|
|
5029
|
-
return querySnapshot.docs.map((
|
|
5050
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
5030
5051
|
}
|
|
5031
5052
|
/**
|
|
5032
5053
|
* Dohvata sve draft zdravstvene radnike za određenu kliniku sa statusom DRAFT
|
|
@@ -5038,7 +5059,7 @@ var PractitionerService = class extends BaseService {
|
|
|
5038
5059
|
where7("status", "==", "draft" /* DRAFT */)
|
|
5039
5060
|
);
|
|
5040
5061
|
const querySnapshot = await getDocs7(q);
|
|
5041
|
-
return querySnapshot.docs.map((
|
|
5062
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
5042
5063
|
}
|
|
5043
5064
|
/**
|
|
5044
5065
|
* Updates a practitioner
|
|
@@ -5252,7 +5273,7 @@ var PractitionerService = class extends BaseService {
|
|
|
5252
5273
|
);
|
|
5253
5274
|
const querySnapshot = await getDocs7(q);
|
|
5254
5275
|
const practitioners = querySnapshot.docs.map(
|
|
5255
|
-
(
|
|
5276
|
+
(doc35) => doc35.data()
|
|
5256
5277
|
);
|
|
5257
5278
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
5258
5279
|
return {
|
|
@@ -5323,8 +5344,8 @@ var PractitionerService = class extends BaseService {
|
|
|
5323
5344
|
console.log(
|
|
5324
5345
|
`[PRACTITIONER_SERVICE] Found ${querySnapshot.docs.length} practitioners with base query`
|
|
5325
5346
|
);
|
|
5326
|
-
let practitioners = querySnapshot.docs.map((
|
|
5327
|
-
return { ...
|
|
5347
|
+
let practitioners = querySnapshot.docs.map((doc35) => {
|
|
5348
|
+
return { ...doc35.data(), id: doc35.id };
|
|
5328
5349
|
});
|
|
5329
5350
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
5330
5351
|
if (filters.nameSearch && filters.nameSearch.trim() !== "") {
|
|
@@ -5581,7 +5602,7 @@ var UserService = class extends BaseService {
|
|
|
5581
5602
|
];
|
|
5582
5603
|
const q = query8(collection8(this.db, USERS_COLLECTION), ...constraints);
|
|
5583
5604
|
const querySnapshot = await getDocs8(q);
|
|
5584
|
-
const users = querySnapshot.docs.map((
|
|
5605
|
+
const users = querySnapshot.docs.map((doc35) => doc35.data());
|
|
5585
5606
|
return Promise.all(users.map((userData) => userSchema.parse(userData)));
|
|
5586
5607
|
}
|
|
5587
5608
|
/**
|
|
@@ -5961,7 +5982,7 @@ async function getAllActiveGroups(db) {
|
|
|
5961
5982
|
where9("isActive", "==", true)
|
|
5962
5983
|
);
|
|
5963
5984
|
const querySnapshot = await getDocs9(q);
|
|
5964
|
-
return querySnapshot.docs.map((
|
|
5985
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
5965
5986
|
}
|
|
5966
5987
|
async function updateClinicGroup(db, groupId, data, app) {
|
|
5967
5988
|
console.log("[CLINIC_GROUP] Updating clinic group", { groupId });
|
|
@@ -6426,7 +6447,7 @@ async function getClinicsByGroup(db, groupId) {
|
|
|
6426
6447
|
where10("isActive", "==", true)
|
|
6427
6448
|
);
|
|
6428
6449
|
const querySnapshot = await getDocs10(q);
|
|
6429
|
-
return querySnapshot.docs.map((
|
|
6450
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
6430
6451
|
}
|
|
6431
6452
|
async function updateClinic(db, clinicId, data, adminId, clinicAdminService, app) {
|
|
6432
6453
|
console.log("[CLINIC] Starting clinic update", { clinicId, adminId });
|
|
@@ -6620,7 +6641,7 @@ async function getClinicsByAdmin(db, adminId, options = {}, clinicAdminService,
|
|
|
6620
6641
|
}
|
|
6621
6642
|
const q = query10(collection10(db, CLINICS_COLLECTION), ...constraints);
|
|
6622
6643
|
const querySnapshot = await getDocs10(q);
|
|
6623
|
-
return querySnapshot.docs.map((
|
|
6644
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
6624
6645
|
}
|
|
6625
6646
|
async function getActiveClinicsByAdmin(db, adminId, clinicAdminService, clinicGroupService) {
|
|
6626
6647
|
return getClinicsByAdmin(
|
|
@@ -6665,11 +6686,11 @@ async function getAllClinics(db, pagination, lastDoc) {
|
|
|
6665
6686
|
}
|
|
6666
6687
|
const clinicsSnapshot = await getDocs10(clinicsQuery);
|
|
6667
6688
|
const lastVisible = clinicsSnapshot.docs[clinicsSnapshot.docs.length - 1];
|
|
6668
|
-
const clinics = clinicsSnapshot.docs.map((
|
|
6669
|
-
const data =
|
|
6689
|
+
const clinics = clinicsSnapshot.docs.map((doc35) => {
|
|
6690
|
+
const data = doc35.data();
|
|
6670
6691
|
return {
|
|
6671
6692
|
...data,
|
|
6672
|
-
id:
|
|
6693
|
+
id: doc35.id
|
|
6673
6694
|
};
|
|
6674
6695
|
});
|
|
6675
6696
|
return {
|
|
@@ -6696,8 +6717,8 @@ async function getAllClinicsInRange(db, center, rangeInKm, pagination, lastDoc)
|
|
|
6696
6717
|
];
|
|
6697
6718
|
const q = query10(collection10(db, CLINICS_COLLECTION), ...constraints);
|
|
6698
6719
|
const querySnapshot = await getDocs10(q);
|
|
6699
|
-
for (const
|
|
6700
|
-
const clinic =
|
|
6720
|
+
for (const doc35 of querySnapshot.docs) {
|
|
6721
|
+
const clinic = doc35.data();
|
|
6701
6722
|
const distance = distanceBetween2(
|
|
6702
6723
|
[center.latitude, center.longitude],
|
|
6703
6724
|
[clinic.location.latitude, clinic.location.longitude]
|
|
@@ -6819,8 +6840,8 @@ async function findClinicsInRadius(db, center, radiusInKm, filters) {
|
|
|
6819
6840
|
}
|
|
6820
6841
|
const q = query11(collection11(db, CLINICS_COLLECTION), ...constraints);
|
|
6821
6842
|
const querySnapshot = await getDocs11(q);
|
|
6822
|
-
for (const
|
|
6823
|
-
const clinic =
|
|
6843
|
+
for (const doc35 of querySnapshot.docs) {
|
|
6844
|
+
const clinic = doc35.data();
|
|
6824
6845
|
const distance = distanceBetween3(
|
|
6825
6846
|
[center.latitude, center.longitude],
|
|
6826
6847
|
[clinic.location.latitude, clinic.location.longitude]
|
|
@@ -6916,8 +6937,8 @@ async function getClinicsByFilters(db, filters) {
|
|
|
6916
6937
|
console.log(
|
|
6917
6938
|
`[FILTER_UTILS] Found ${querySnapshot.docs.length} clinics in geo bound`
|
|
6918
6939
|
);
|
|
6919
|
-
for (const
|
|
6920
|
-
const clinic = { ...
|
|
6940
|
+
for (const doc35 of querySnapshot.docs) {
|
|
6941
|
+
const clinic = { ...doc35.data(), id: doc35.id };
|
|
6921
6942
|
const distance = distanceBetween4(
|
|
6922
6943
|
[center.latitude, center.longitude],
|
|
6923
6944
|
[clinic.location.latitude, clinic.location.longitude]
|
|
@@ -6973,8 +6994,8 @@ async function getClinicsByFilters(db, filters) {
|
|
|
6973
6994
|
console.log(
|
|
6974
6995
|
`[FILTER_UTILS] Found ${querySnapshot.docs.length} clinics with regular query`
|
|
6975
6996
|
);
|
|
6976
|
-
const clinics = querySnapshot.docs.map((
|
|
6977
|
-
return { ...
|
|
6997
|
+
const clinics = querySnapshot.docs.map((doc35) => {
|
|
6998
|
+
return { ...doc35.data(), id: doc35.id };
|
|
6978
6999
|
});
|
|
6979
7000
|
let filteredClinics = clinics;
|
|
6980
7001
|
if (filters.center) {
|
|
@@ -8421,9 +8442,9 @@ var NotificationService = class extends BaseService {
|
|
|
8421
8442
|
orderBy4("notificationTime", "desc")
|
|
8422
8443
|
);
|
|
8423
8444
|
const querySnapshot = await getDocs15(q);
|
|
8424
|
-
return querySnapshot.docs.map((
|
|
8425
|
-
id:
|
|
8426
|
-
...
|
|
8445
|
+
return querySnapshot.docs.map((doc35) => ({
|
|
8446
|
+
id: doc35.id,
|
|
8447
|
+
...doc35.data()
|
|
8427
8448
|
}));
|
|
8428
8449
|
}
|
|
8429
8450
|
/**
|
|
@@ -8437,9 +8458,9 @@ var NotificationService = class extends BaseService {
|
|
|
8437
8458
|
orderBy4("notificationTime", "desc")
|
|
8438
8459
|
);
|
|
8439
8460
|
const querySnapshot = await getDocs15(q);
|
|
8440
|
-
return querySnapshot.docs.map((
|
|
8441
|
-
id:
|
|
8442
|
-
...
|
|
8461
|
+
return querySnapshot.docs.map((doc35) => ({
|
|
8462
|
+
id: doc35.id,
|
|
8463
|
+
...doc35.data()
|
|
8443
8464
|
}));
|
|
8444
8465
|
}
|
|
8445
8466
|
/**
|
|
@@ -8511,9 +8532,9 @@ var NotificationService = class extends BaseService {
|
|
|
8511
8532
|
orderBy4("notificationTime", "desc")
|
|
8512
8533
|
);
|
|
8513
8534
|
const querySnapshot = await getDocs15(q);
|
|
8514
|
-
return querySnapshot.docs.map((
|
|
8515
|
-
id:
|
|
8516
|
-
...
|
|
8535
|
+
return querySnapshot.docs.map((doc35) => ({
|
|
8536
|
+
id: doc35.id,
|
|
8537
|
+
...doc35.data()
|
|
8517
8538
|
}));
|
|
8518
8539
|
}
|
|
8519
8540
|
/**
|
|
@@ -8526,9 +8547,9 @@ var NotificationService = class extends BaseService {
|
|
|
8526
8547
|
orderBy4("notificationTime", "desc")
|
|
8527
8548
|
);
|
|
8528
8549
|
const querySnapshot = await getDocs15(q);
|
|
8529
|
-
return querySnapshot.docs.map((
|
|
8530
|
-
id:
|
|
8531
|
-
...
|
|
8550
|
+
return querySnapshot.docs.map((doc35) => ({
|
|
8551
|
+
id: doc35.id,
|
|
8552
|
+
...doc35.data()
|
|
8532
8553
|
}));
|
|
8533
8554
|
}
|
|
8534
8555
|
};
|
|
@@ -8823,7 +8844,7 @@ var ProcedureService = class extends BaseService {
|
|
|
8823
8844
|
where16("isActive", "==", true)
|
|
8824
8845
|
);
|
|
8825
8846
|
const snapshot = await getDocs16(q);
|
|
8826
|
-
return snapshot.docs.map((
|
|
8847
|
+
return snapshot.docs.map((doc35) => doc35.data());
|
|
8827
8848
|
}
|
|
8828
8849
|
/**
|
|
8829
8850
|
* Gets all procedures for a practitioner
|
|
@@ -8837,7 +8858,7 @@ var ProcedureService = class extends BaseService {
|
|
|
8837
8858
|
where16("isActive", "==", true)
|
|
8838
8859
|
);
|
|
8839
8860
|
const snapshot = await getDocs16(q);
|
|
8840
|
-
return snapshot.docs.map((
|
|
8861
|
+
return snapshot.docs.map((doc35) => doc35.data());
|
|
8841
8862
|
}
|
|
8842
8863
|
/**
|
|
8843
8864
|
* Updates a procedure
|
|
@@ -9028,20 +9049,20 @@ var ProcedureService = class extends BaseService {
|
|
|
9028
9049
|
const proceduresCollection = collection16(this.db, PROCEDURES_COLLECTION);
|
|
9029
9050
|
let proceduresQuery = query16(proceduresCollection);
|
|
9030
9051
|
if (pagination && pagination > 0) {
|
|
9031
|
-
const { limit:
|
|
9052
|
+
const { limit: limit15, startAfter: startAfter13 } = await import("firebase/firestore");
|
|
9032
9053
|
if (lastDoc) {
|
|
9033
9054
|
proceduresQuery = query16(
|
|
9034
9055
|
proceduresCollection,
|
|
9035
9056
|
orderBy5("name"),
|
|
9036
9057
|
// Use imported orderBy
|
|
9037
9058
|
startAfter13(lastDoc),
|
|
9038
|
-
|
|
9059
|
+
limit15(pagination)
|
|
9039
9060
|
);
|
|
9040
9061
|
} else {
|
|
9041
9062
|
proceduresQuery = query16(
|
|
9042
9063
|
proceduresCollection,
|
|
9043
9064
|
orderBy5("name"),
|
|
9044
|
-
|
|
9065
|
+
limit15(pagination)
|
|
9045
9066
|
);
|
|
9046
9067
|
}
|
|
9047
9068
|
} else {
|
|
@@ -9049,11 +9070,11 @@ var ProcedureService = class extends BaseService {
|
|
|
9049
9070
|
}
|
|
9050
9071
|
const proceduresSnapshot = await getDocs16(proceduresQuery);
|
|
9051
9072
|
const lastVisible = proceduresSnapshot.docs[proceduresSnapshot.docs.length - 1];
|
|
9052
|
-
const procedures = proceduresSnapshot.docs.map((
|
|
9053
|
-
const data =
|
|
9073
|
+
const procedures = proceduresSnapshot.docs.map((doc35) => {
|
|
9074
|
+
const data = doc35.data();
|
|
9054
9075
|
return {
|
|
9055
9076
|
...data,
|
|
9056
|
-
id:
|
|
9077
|
+
id: doc35.id
|
|
9057
9078
|
// Ensure ID is present
|
|
9058
9079
|
};
|
|
9059
9080
|
});
|
|
@@ -9135,8 +9156,8 @@ var ProcedureService = class extends BaseService {
|
|
|
9135
9156
|
console.log(
|
|
9136
9157
|
`[PROCEDURE_SERVICE] Found ${querySnapshot.docs.length} procedures in geo bound`
|
|
9137
9158
|
);
|
|
9138
|
-
for (const
|
|
9139
|
-
const procedure = { ...
|
|
9159
|
+
for (const doc35 of querySnapshot.docs) {
|
|
9160
|
+
const procedure = { ...doc35.data(), id: doc35.id };
|
|
9140
9161
|
const distance = distanceBetween6(
|
|
9141
9162
|
[center.latitude, center.longitude],
|
|
9142
9163
|
[
|
|
@@ -9187,8 +9208,8 @@ var ProcedureService = class extends BaseService {
|
|
|
9187
9208
|
console.log(
|
|
9188
9209
|
`[PROCEDURE_SERVICE] Found ${querySnapshot.docs.length} procedures with regular query`
|
|
9189
9210
|
);
|
|
9190
|
-
const procedures = querySnapshot.docs.map((
|
|
9191
|
-
return { ...
|
|
9211
|
+
const procedures = querySnapshot.docs.map((doc35) => {
|
|
9212
|
+
return { ...doc35.data(), id: doc35.id };
|
|
9192
9213
|
});
|
|
9193
9214
|
if (filters.location) {
|
|
9194
9215
|
const center = filters.location;
|
|
@@ -9294,25 +9315,430 @@ var ProcedureService = class extends BaseService {
|
|
|
9294
9315
|
}
|
|
9295
9316
|
};
|
|
9296
9317
|
|
|
9297
|
-
// src/services/
|
|
9318
|
+
// src/services/clinic/practitioner-invite.service.ts
|
|
9298
9319
|
import {
|
|
9299
9320
|
collection as collection17,
|
|
9300
9321
|
doc as doc17,
|
|
9301
9322
|
getDoc as getDoc20,
|
|
9302
9323
|
getDocs as getDocs17,
|
|
9303
|
-
setDoc as setDoc15,
|
|
9304
|
-
updateDoc as updateDoc17,
|
|
9305
|
-
deleteDoc as deleteDoc10,
|
|
9306
9324
|
query as query17,
|
|
9307
9325
|
where as where17,
|
|
9326
|
+
updateDoc as updateDoc17,
|
|
9327
|
+
setDoc as setDoc15,
|
|
9328
|
+
deleteDoc as deleteDoc10,
|
|
9329
|
+
Timestamp as Timestamp18,
|
|
9330
|
+
serverTimestamp as serverTimestamp15,
|
|
9308
9331
|
orderBy as orderBy6,
|
|
9309
|
-
limit as limit9
|
|
9332
|
+
limit as limit9
|
|
9333
|
+
} from "firebase/firestore";
|
|
9334
|
+
var PractitionerInviteService = class extends BaseService {
|
|
9335
|
+
constructor(db, auth, app) {
|
|
9336
|
+
super(db, auth, app);
|
|
9337
|
+
}
|
|
9338
|
+
/**
|
|
9339
|
+
* Creates a new practitioner invite
|
|
9340
|
+
* @param practitionerId - Practitioner ID
|
|
9341
|
+
* @param clinicId - Clinic ID
|
|
9342
|
+
* @param proposedWorkingHours - Proposed working hours
|
|
9343
|
+
* @param invitedBy - Admin ID who creates the invite
|
|
9344
|
+
* @param message - Optional message
|
|
9345
|
+
* @returns Created invite
|
|
9346
|
+
*/
|
|
9347
|
+
async createInviteAdmin(practitionerId, clinicId, proposedWorkingHours, invitedBy, message) {
|
|
9348
|
+
try {
|
|
9349
|
+
const inviteId = this.generateId();
|
|
9350
|
+
const [practitioner, clinic] = await Promise.all([
|
|
9351
|
+
this.getPractitionerById(practitionerId),
|
|
9352
|
+
this.getClinicById(clinicId)
|
|
9353
|
+
]);
|
|
9354
|
+
if (!practitioner) {
|
|
9355
|
+
throw new Error(`Practitioner with ID ${practitionerId} not found`);
|
|
9356
|
+
}
|
|
9357
|
+
if (!clinic) {
|
|
9358
|
+
throw new Error(`Clinic with ID ${clinicId} not found`);
|
|
9359
|
+
}
|
|
9360
|
+
const existingInvite = await this.findExistingInvite(
|
|
9361
|
+
practitionerId,
|
|
9362
|
+
clinicId
|
|
9363
|
+
);
|
|
9364
|
+
if (existingInvite && existingInvite.status === "pending" /* PENDING */) {
|
|
9365
|
+
throw new Error(
|
|
9366
|
+
"There's already a pending invite for this practitioner at this clinic"
|
|
9367
|
+
);
|
|
9368
|
+
}
|
|
9369
|
+
const practitionerInfo = {
|
|
9370
|
+
id: practitioner.id,
|
|
9371
|
+
practitionerPhoto: typeof practitioner.basicInfo.profileImageUrl === "string" ? practitioner.basicInfo.profileImageUrl : null,
|
|
9372
|
+
name: `${practitioner.basicInfo.firstName} ${practitioner.basicInfo.lastName}`,
|
|
9373
|
+
email: practitioner.basicInfo.email,
|
|
9374
|
+
phone: practitioner.basicInfo.phoneNumber || null,
|
|
9375
|
+
certification: practitioner.certification
|
|
9376
|
+
};
|
|
9377
|
+
const clinicInfo = {
|
|
9378
|
+
id: clinic.id,
|
|
9379
|
+
featuredPhoto: typeof clinic.coverPhoto === "string" ? clinic.coverPhoto : "",
|
|
9380
|
+
name: clinic.name,
|
|
9381
|
+
description: clinic.description || null,
|
|
9382
|
+
location: clinic.location,
|
|
9383
|
+
contactInfo: clinic.contactInfo
|
|
9384
|
+
};
|
|
9385
|
+
const inviteData = {
|
|
9386
|
+
practitionerId,
|
|
9387
|
+
clinicId,
|
|
9388
|
+
practitionerInfo,
|
|
9389
|
+
clinicInfo,
|
|
9390
|
+
proposedWorkingHours,
|
|
9391
|
+
invitedBy,
|
|
9392
|
+
message: message || null,
|
|
9393
|
+
status: "pending" /* PENDING */
|
|
9394
|
+
};
|
|
9395
|
+
const now = Timestamp18.now();
|
|
9396
|
+
const invite = {
|
|
9397
|
+
id: inviteId,
|
|
9398
|
+
...inviteData,
|
|
9399
|
+
status: "pending" /* PENDING */,
|
|
9400
|
+
createdAt: now,
|
|
9401
|
+
updatedAt: now,
|
|
9402
|
+
acceptedAt: null,
|
|
9403
|
+
rejectedAt: null,
|
|
9404
|
+
cancelledAt: null
|
|
9405
|
+
};
|
|
9406
|
+
const docRef = doc17(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
9407
|
+
await setDoc15(docRef, invite);
|
|
9408
|
+
return invite;
|
|
9409
|
+
} catch (error) {
|
|
9410
|
+
console.error(
|
|
9411
|
+
"[PractitionerInviteService] Error creating invite:",
|
|
9412
|
+
error
|
|
9413
|
+
);
|
|
9414
|
+
throw error;
|
|
9415
|
+
}
|
|
9416
|
+
}
|
|
9417
|
+
/**
|
|
9418
|
+
* Gets all invites for a specific doctor/practitioner
|
|
9419
|
+
* @param practitionerId - Practitioner ID
|
|
9420
|
+
* @param statusFilter - Optional status filter
|
|
9421
|
+
* @returns Array of invites
|
|
9422
|
+
*/
|
|
9423
|
+
async getAllInvitesDoctor(practitionerId, statusFilter) {
|
|
9424
|
+
try {
|
|
9425
|
+
const constraints = [
|
|
9426
|
+
where17("practitionerId", "==", practitionerId),
|
|
9427
|
+
orderBy6("createdAt", "desc")
|
|
9428
|
+
];
|
|
9429
|
+
if (statusFilter && statusFilter.length > 0) {
|
|
9430
|
+
constraints.push(where17("status", "in", statusFilter));
|
|
9431
|
+
}
|
|
9432
|
+
const q = query17(
|
|
9433
|
+
collection17(this.db, PRACTITIONER_INVITES_COLLECTION),
|
|
9434
|
+
...constraints
|
|
9435
|
+
);
|
|
9436
|
+
const querySnapshot = await getDocs17(q);
|
|
9437
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
9438
|
+
} catch (error) {
|
|
9439
|
+
console.error(
|
|
9440
|
+
"[PractitionerInviteService] Error getting doctor invites:",
|
|
9441
|
+
error
|
|
9442
|
+
);
|
|
9443
|
+
throw error;
|
|
9444
|
+
}
|
|
9445
|
+
}
|
|
9446
|
+
/**
|
|
9447
|
+
* Gets all invites for a specific clinic
|
|
9448
|
+
* @param clinicId - Clinic ID
|
|
9449
|
+
* @param statusFilter - Optional status filter
|
|
9450
|
+
* @returns Array of invites
|
|
9451
|
+
*/
|
|
9452
|
+
async getAllInvitesClinic(clinicId, statusFilter) {
|
|
9453
|
+
try {
|
|
9454
|
+
const constraints = [
|
|
9455
|
+
where17("clinicId", "==", clinicId),
|
|
9456
|
+
orderBy6("createdAt", "desc")
|
|
9457
|
+
];
|
|
9458
|
+
if (statusFilter && statusFilter.length > 0) {
|
|
9459
|
+
constraints.push(where17("status", "in", statusFilter));
|
|
9460
|
+
}
|
|
9461
|
+
const q = query17(
|
|
9462
|
+
collection17(this.db, PRACTITIONER_INVITES_COLLECTION),
|
|
9463
|
+
...constraints
|
|
9464
|
+
);
|
|
9465
|
+
const querySnapshot = await getDocs17(q);
|
|
9466
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
9467
|
+
} catch (error) {
|
|
9468
|
+
console.error(
|
|
9469
|
+
"[PractitionerInviteService] Error getting clinic invites:",
|
|
9470
|
+
error
|
|
9471
|
+
);
|
|
9472
|
+
throw error;
|
|
9473
|
+
}
|
|
9474
|
+
}
|
|
9475
|
+
/**
|
|
9476
|
+
* Doctor accepts an invite
|
|
9477
|
+
* @param inviteId - Invite ID
|
|
9478
|
+
* @returns Updated invite
|
|
9479
|
+
*/
|
|
9480
|
+
async acceptInviteDoctor(inviteId) {
|
|
9481
|
+
try {
|
|
9482
|
+
const invite = await this.getInviteById(inviteId);
|
|
9483
|
+
if (!invite) {
|
|
9484
|
+
throw new Error(`Invite with ID ${inviteId} not found`);
|
|
9485
|
+
}
|
|
9486
|
+
if (invite.status !== "pending" /* PENDING */) {
|
|
9487
|
+
throw new Error("Only pending invites can be accepted");
|
|
9488
|
+
}
|
|
9489
|
+
const updateData = {
|
|
9490
|
+
status: "accepted" /* ACCEPTED */,
|
|
9491
|
+
acceptedAt: Timestamp18.now(),
|
|
9492
|
+
updatedAt: serverTimestamp15()
|
|
9493
|
+
};
|
|
9494
|
+
const docRef = doc17(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
9495
|
+
await updateDoc17(docRef, updateData);
|
|
9496
|
+
return await this.getInviteById(inviteId);
|
|
9497
|
+
} catch (error) {
|
|
9498
|
+
console.error(
|
|
9499
|
+
"[PractitionerInviteService] Error accepting invite:",
|
|
9500
|
+
error
|
|
9501
|
+
);
|
|
9502
|
+
throw error;
|
|
9503
|
+
}
|
|
9504
|
+
}
|
|
9505
|
+
/**
|
|
9506
|
+
* Doctor rejects an invite
|
|
9507
|
+
* @param inviteId - Invite ID
|
|
9508
|
+
* @param rejectionReason - Optional reason for rejection
|
|
9509
|
+
* @returns Updated invite
|
|
9510
|
+
*/
|
|
9511
|
+
async rejectInviteDoctor(inviteId, rejectionReason) {
|
|
9512
|
+
try {
|
|
9513
|
+
const invite = await this.getInviteById(inviteId);
|
|
9514
|
+
if (!invite) {
|
|
9515
|
+
throw new Error(`Invite with ID ${inviteId} not found`);
|
|
9516
|
+
}
|
|
9517
|
+
if (invite.status !== "pending" /* PENDING */) {
|
|
9518
|
+
throw new Error("Only pending invites can be rejected");
|
|
9519
|
+
}
|
|
9520
|
+
const updateData = {
|
|
9521
|
+
status: "rejected" /* REJECTED */,
|
|
9522
|
+
rejectionReason: rejectionReason || null,
|
|
9523
|
+
rejectedAt: Timestamp18.now(),
|
|
9524
|
+
updatedAt: serverTimestamp15()
|
|
9525
|
+
};
|
|
9526
|
+
const docRef = doc17(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
9527
|
+
await updateDoc17(docRef, updateData);
|
|
9528
|
+
return await this.getInviteById(inviteId);
|
|
9529
|
+
} catch (error) {
|
|
9530
|
+
console.error(
|
|
9531
|
+
"[PractitionerInviteService] Error rejecting invite:",
|
|
9532
|
+
error
|
|
9533
|
+
);
|
|
9534
|
+
throw error;
|
|
9535
|
+
}
|
|
9536
|
+
}
|
|
9537
|
+
/**
|
|
9538
|
+
* Admin cancels an invite
|
|
9539
|
+
* @param inviteId - Invite ID
|
|
9540
|
+
* @param cancelReason - Optional reason for cancellation
|
|
9541
|
+
* @returns Updated invite
|
|
9542
|
+
*/
|
|
9543
|
+
async cancelInviteAdmin(inviteId, cancelReason) {
|
|
9544
|
+
try {
|
|
9545
|
+
const invite = await this.getInviteById(inviteId);
|
|
9546
|
+
if (!invite) {
|
|
9547
|
+
throw new Error(`Invite with ID ${inviteId} not found`);
|
|
9548
|
+
}
|
|
9549
|
+
if (invite.status !== "pending" /* PENDING */) {
|
|
9550
|
+
throw new Error("Only pending invites can be cancelled");
|
|
9551
|
+
}
|
|
9552
|
+
const updateData = {
|
|
9553
|
+
status: "cancelled" /* CANCELLED */,
|
|
9554
|
+
cancelReason: cancelReason || null,
|
|
9555
|
+
cancelledAt: Timestamp18.now(),
|
|
9556
|
+
updatedAt: serverTimestamp15()
|
|
9557
|
+
};
|
|
9558
|
+
const docRef = doc17(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
9559
|
+
await updateDoc17(docRef, updateData);
|
|
9560
|
+
return await this.getInviteById(inviteId);
|
|
9561
|
+
} catch (error) {
|
|
9562
|
+
console.error(
|
|
9563
|
+
"[PractitionerInviteService] Error cancelling invite:",
|
|
9564
|
+
error
|
|
9565
|
+
);
|
|
9566
|
+
throw error;
|
|
9567
|
+
}
|
|
9568
|
+
}
|
|
9569
|
+
/**
|
|
9570
|
+
* Gets an invite by ID
|
|
9571
|
+
* @param inviteId - Invite ID
|
|
9572
|
+
* @returns Invite or null if not found
|
|
9573
|
+
*/
|
|
9574
|
+
async getInviteById(inviteId) {
|
|
9575
|
+
try {
|
|
9576
|
+
const docRef = doc17(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
9577
|
+
const docSnap = await getDoc20(docRef);
|
|
9578
|
+
if (docSnap.exists()) {
|
|
9579
|
+
return docSnap.data();
|
|
9580
|
+
}
|
|
9581
|
+
return null;
|
|
9582
|
+
} catch (error) {
|
|
9583
|
+
console.error(
|
|
9584
|
+
"[PractitionerInviteService] Error getting invite by ID:",
|
|
9585
|
+
error
|
|
9586
|
+
);
|
|
9587
|
+
throw error;
|
|
9588
|
+
}
|
|
9589
|
+
}
|
|
9590
|
+
/**
|
|
9591
|
+
* Gets invites with advanced filtering options
|
|
9592
|
+
* @param filters - Filter options
|
|
9593
|
+
* @returns Array of filtered invites
|
|
9594
|
+
*/
|
|
9595
|
+
async getInvitesWithFilters(filters) {
|
|
9596
|
+
try {
|
|
9597
|
+
const constraints = [];
|
|
9598
|
+
if (filters.practitionerId) {
|
|
9599
|
+
constraints.push(where17("practitionerId", "==", filters.practitionerId));
|
|
9600
|
+
}
|
|
9601
|
+
if (filters.clinicId) {
|
|
9602
|
+
constraints.push(where17("clinicId", "==", filters.clinicId));
|
|
9603
|
+
}
|
|
9604
|
+
if (filters.invitedBy) {
|
|
9605
|
+
constraints.push(where17("invitedBy", "==", filters.invitedBy));
|
|
9606
|
+
}
|
|
9607
|
+
if (filters.status && filters.status.length > 0) {
|
|
9608
|
+
constraints.push(where17("status", "in", filters.status));
|
|
9609
|
+
}
|
|
9610
|
+
const orderField = filters.orderBy || "createdAt";
|
|
9611
|
+
const orderDirection = filters.orderDirection || "desc";
|
|
9612
|
+
constraints.push(orderBy6(orderField, orderDirection));
|
|
9613
|
+
if (filters.limit) {
|
|
9614
|
+
constraints.push(limit9(filters.limit));
|
|
9615
|
+
}
|
|
9616
|
+
const q = query17(
|
|
9617
|
+
collection17(this.db, PRACTITIONER_INVITES_COLLECTION),
|
|
9618
|
+
...constraints
|
|
9619
|
+
);
|
|
9620
|
+
const querySnapshot = await getDocs17(q);
|
|
9621
|
+
let invites = querySnapshot.docs.map(
|
|
9622
|
+
(doc35) => doc35.data()
|
|
9623
|
+
);
|
|
9624
|
+
if (filters.fromDate) {
|
|
9625
|
+
invites = invites.filter(
|
|
9626
|
+
(invite) => invite.createdAt >= filters.fromDate
|
|
9627
|
+
);
|
|
9628
|
+
}
|
|
9629
|
+
if (filters.toDate) {
|
|
9630
|
+
invites = invites.filter(
|
|
9631
|
+
(invite) => invite.createdAt <= filters.toDate
|
|
9632
|
+
);
|
|
9633
|
+
}
|
|
9634
|
+
return invites;
|
|
9635
|
+
} catch (error) {
|
|
9636
|
+
console.error(
|
|
9637
|
+
"[PractitionerInviteService] Error getting invites with filters:",
|
|
9638
|
+
error
|
|
9639
|
+
);
|
|
9640
|
+
throw error;
|
|
9641
|
+
}
|
|
9642
|
+
}
|
|
9643
|
+
/**
|
|
9644
|
+
* Deletes an invite (admin only)
|
|
9645
|
+
* @param inviteId - Invite ID
|
|
9646
|
+
*/
|
|
9647
|
+
async deleteInvite(inviteId) {
|
|
9648
|
+
try {
|
|
9649
|
+
const docRef = doc17(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
9650
|
+
await deleteDoc10(docRef);
|
|
9651
|
+
} catch (error) {
|
|
9652
|
+
console.error(
|
|
9653
|
+
"[PractitionerInviteService] Error deleting invite:",
|
|
9654
|
+
error
|
|
9655
|
+
);
|
|
9656
|
+
throw error;
|
|
9657
|
+
}
|
|
9658
|
+
}
|
|
9659
|
+
// Private helper methods
|
|
9660
|
+
/**
|
|
9661
|
+
* Gets practitioner by ID
|
|
9662
|
+
* @param practitionerId - Practitioner ID
|
|
9663
|
+
* @returns Practitioner or null
|
|
9664
|
+
*/
|
|
9665
|
+
async getPractitionerById(practitionerId) {
|
|
9666
|
+
try {
|
|
9667
|
+
const docRef = doc17(this.db, PRACTITIONERS_COLLECTION, practitionerId);
|
|
9668
|
+
const docSnap = await getDoc20(docRef);
|
|
9669
|
+
return docSnap.exists() ? docSnap.data() : null;
|
|
9670
|
+
} catch (error) {
|
|
9671
|
+
console.error(
|
|
9672
|
+
"[PractitionerInviteService] Error getting practitioner:",
|
|
9673
|
+
error
|
|
9674
|
+
);
|
|
9675
|
+
return null;
|
|
9676
|
+
}
|
|
9677
|
+
}
|
|
9678
|
+
/**
|
|
9679
|
+
* Gets clinic by ID
|
|
9680
|
+
* @param clinicId - Clinic ID
|
|
9681
|
+
* @returns Clinic or null
|
|
9682
|
+
*/
|
|
9683
|
+
async getClinicById(clinicId) {
|
|
9684
|
+
try {
|
|
9685
|
+
const docRef = doc17(this.db, CLINICS_COLLECTION, clinicId);
|
|
9686
|
+
const docSnap = await getDoc20(docRef);
|
|
9687
|
+
return docSnap.exists() ? docSnap.data() : null;
|
|
9688
|
+
} catch (error) {
|
|
9689
|
+
console.error("[PractitionerInviteService] Error getting clinic:", error);
|
|
9690
|
+
return null;
|
|
9691
|
+
}
|
|
9692
|
+
}
|
|
9693
|
+
/**
|
|
9694
|
+
* Finds existing invite between practitioner and clinic
|
|
9695
|
+
* @param practitionerId - Practitioner ID
|
|
9696
|
+
* @param clinicId - Clinic ID
|
|
9697
|
+
* @returns Existing invite or null
|
|
9698
|
+
*/
|
|
9699
|
+
async findExistingInvite(practitionerId, clinicId) {
|
|
9700
|
+
try {
|
|
9701
|
+
const q = query17(
|
|
9702
|
+
collection17(this.db, PRACTITIONER_INVITES_COLLECTION),
|
|
9703
|
+
where17("practitionerId", "==", practitionerId),
|
|
9704
|
+
where17("clinicId", "==", clinicId),
|
|
9705
|
+
orderBy6("createdAt", "desc"),
|
|
9706
|
+
limit9(1)
|
|
9707
|
+
);
|
|
9708
|
+
const querySnapshot = await getDocs17(q);
|
|
9709
|
+
if (querySnapshot.empty) {
|
|
9710
|
+
return null;
|
|
9711
|
+
}
|
|
9712
|
+
return querySnapshot.docs[0].data();
|
|
9713
|
+
} catch (error) {
|
|
9714
|
+
console.error(
|
|
9715
|
+
"[PractitionerInviteService] Error finding existing invite:",
|
|
9716
|
+
error
|
|
9717
|
+
);
|
|
9718
|
+
return null;
|
|
9719
|
+
}
|
|
9720
|
+
}
|
|
9721
|
+
};
|
|
9722
|
+
|
|
9723
|
+
// src/services/documentation-templates/documentation-template.service.ts
|
|
9724
|
+
import {
|
|
9725
|
+
collection as collection18,
|
|
9726
|
+
doc as doc18,
|
|
9727
|
+
getDoc as getDoc21,
|
|
9728
|
+
getDocs as getDocs18,
|
|
9729
|
+
setDoc as setDoc16,
|
|
9730
|
+
updateDoc as updateDoc18,
|
|
9731
|
+
deleteDoc as deleteDoc11,
|
|
9732
|
+
query as query18,
|
|
9733
|
+
where as where18,
|
|
9734
|
+
orderBy as orderBy7,
|
|
9735
|
+
limit as limit10,
|
|
9310
9736
|
startAfter as startAfter8
|
|
9311
9737
|
} from "firebase/firestore";
|
|
9312
9738
|
var DocumentationTemplateService = class extends BaseService {
|
|
9313
9739
|
constructor() {
|
|
9314
9740
|
super(...arguments);
|
|
9315
|
-
this.collectionRef =
|
|
9741
|
+
this.collectionRef = collection18(
|
|
9316
9742
|
this.db,
|
|
9317
9743
|
DOCUMENTATION_TEMPLATES_COLLECTION
|
|
9318
9744
|
);
|
|
@@ -9346,8 +9772,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9346
9772
|
isRequired: validatedData.isRequired || false,
|
|
9347
9773
|
sortingOrder: validatedData.sortingOrder || 0
|
|
9348
9774
|
};
|
|
9349
|
-
const docRef =
|
|
9350
|
-
await
|
|
9775
|
+
const docRef = doc18(this.collectionRef, templateId);
|
|
9776
|
+
await setDoc16(docRef, template);
|
|
9351
9777
|
return template;
|
|
9352
9778
|
}
|
|
9353
9779
|
/**
|
|
@@ -9357,8 +9783,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9357
9783
|
* @returns The template or null if not found
|
|
9358
9784
|
*/
|
|
9359
9785
|
async getTemplateById(templateId, version) {
|
|
9360
|
-
const docRef =
|
|
9361
|
-
const docSnap = await
|
|
9786
|
+
const docRef = doc18(this.collectionRef, templateId);
|
|
9787
|
+
const docSnap = await getDoc21(docRef);
|
|
9362
9788
|
if (!docSnap.exists()) {
|
|
9363
9789
|
return null;
|
|
9364
9790
|
}
|
|
@@ -9396,15 +9822,15 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9396
9822
|
if (!template) {
|
|
9397
9823
|
throw new Error(`Template with ID ${templateId} not found`);
|
|
9398
9824
|
}
|
|
9399
|
-
const versionsCollectionRef =
|
|
9825
|
+
const versionsCollectionRef = collection18(
|
|
9400
9826
|
this.db,
|
|
9401
9827
|
`${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
|
|
9402
9828
|
);
|
|
9403
|
-
const versionDocRef =
|
|
9829
|
+
const versionDocRef = doc18(
|
|
9404
9830
|
versionsCollectionRef,
|
|
9405
9831
|
template.version.toString()
|
|
9406
9832
|
);
|
|
9407
|
-
await
|
|
9833
|
+
await setDoc16(versionDocRef, template);
|
|
9408
9834
|
let updatedElements = template.elements;
|
|
9409
9835
|
if (validatedData.elements) {
|
|
9410
9836
|
updatedElements = validatedData.elements.map((element) => ({
|
|
@@ -9428,9 +9854,9 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9428
9854
|
updatePayload.isUserForm = (_a = validatedData.isUserForm) != null ? _a : false;
|
|
9429
9855
|
updatePayload.isRequired = (_b = validatedData.isRequired) != null ? _b : false;
|
|
9430
9856
|
updatePayload.sortingOrder = (_c = validatedData.sortingOrder) != null ? _c : 0;
|
|
9431
|
-
const docRef =
|
|
9857
|
+
const docRef = doc18(this.collectionRef, templateId);
|
|
9432
9858
|
console.log("Update payload", updatePayload);
|
|
9433
|
-
await
|
|
9859
|
+
await updateDoc18(docRef, updatePayload);
|
|
9434
9860
|
return { ...template, ...updatePayload };
|
|
9435
9861
|
}
|
|
9436
9862
|
/**
|
|
@@ -9440,11 +9866,11 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9440
9866
|
* @returns The template version or null if not found
|
|
9441
9867
|
*/
|
|
9442
9868
|
async getTemplateVersion(templateId, versionNumber) {
|
|
9443
|
-
const versionDocRef =
|
|
9869
|
+
const versionDocRef = doc18(
|
|
9444
9870
|
this.db,
|
|
9445
9871
|
`${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions/${versionNumber}`
|
|
9446
9872
|
);
|
|
9447
|
-
const versionDocSnap = await
|
|
9873
|
+
const versionDocSnap = await getDoc21(versionDocRef);
|
|
9448
9874
|
if (!versionDocSnap.exists()) {
|
|
9449
9875
|
return null;
|
|
9450
9876
|
}
|
|
@@ -9456,15 +9882,15 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9456
9882
|
* @returns Array of template versions
|
|
9457
9883
|
*/
|
|
9458
9884
|
async getTemplateOldVersions(templateId) {
|
|
9459
|
-
const versionsCollectionRef =
|
|
9885
|
+
const versionsCollectionRef = collection18(
|
|
9460
9886
|
this.db,
|
|
9461
9887
|
`${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
|
|
9462
9888
|
);
|
|
9463
|
-
const q =
|
|
9464
|
-
const querySnapshot = await
|
|
9889
|
+
const q = query18(versionsCollectionRef, orderBy7("version", "desc"));
|
|
9890
|
+
const querySnapshot = await getDocs18(q);
|
|
9465
9891
|
const versions = [];
|
|
9466
|
-
querySnapshot.forEach((
|
|
9467
|
-
versions.push(
|
|
9892
|
+
querySnapshot.forEach((doc35) => {
|
|
9893
|
+
versions.push(doc35.data());
|
|
9468
9894
|
});
|
|
9469
9895
|
return versions;
|
|
9470
9896
|
}
|
|
@@ -9473,8 +9899,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9473
9899
|
* @param templateId - ID of the template to delete
|
|
9474
9900
|
*/
|
|
9475
9901
|
async deleteTemplate(templateId) {
|
|
9476
|
-
const docRef =
|
|
9477
|
-
await
|
|
9902
|
+
const docRef = doc18(this.collectionRef, templateId);
|
|
9903
|
+
await deleteDoc11(docRef);
|
|
9478
9904
|
}
|
|
9479
9905
|
/**
|
|
9480
9906
|
* Get all active templates
|
|
@@ -9483,21 +9909,21 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9483
9909
|
* @returns Array of templates and the last document for pagination
|
|
9484
9910
|
*/
|
|
9485
9911
|
async getActiveTemplates(pageSize = 20, lastDoc) {
|
|
9486
|
-
let q =
|
|
9912
|
+
let q = query18(
|
|
9487
9913
|
this.collectionRef,
|
|
9488
|
-
|
|
9489
|
-
|
|
9490
|
-
|
|
9914
|
+
where18("isActive", "==", true),
|
|
9915
|
+
orderBy7("updatedAt", "desc"),
|
|
9916
|
+
limit10(pageSize)
|
|
9491
9917
|
);
|
|
9492
9918
|
if (lastDoc) {
|
|
9493
|
-
q =
|
|
9919
|
+
q = query18(q, startAfter8(lastDoc));
|
|
9494
9920
|
}
|
|
9495
|
-
const querySnapshot = await
|
|
9921
|
+
const querySnapshot = await getDocs18(q);
|
|
9496
9922
|
const templates = [];
|
|
9497
9923
|
let lastVisible = null;
|
|
9498
|
-
querySnapshot.forEach((
|
|
9499
|
-
templates.push(
|
|
9500
|
-
lastVisible =
|
|
9924
|
+
querySnapshot.forEach((doc35) => {
|
|
9925
|
+
templates.push(doc35.data());
|
|
9926
|
+
lastVisible = doc35;
|
|
9501
9927
|
});
|
|
9502
9928
|
return {
|
|
9503
9929
|
templates,
|
|
@@ -9512,22 +9938,22 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9512
9938
|
* @returns Array of templates and the last document for pagination
|
|
9513
9939
|
*/
|
|
9514
9940
|
async getTemplatesByTags(tags, pageSize = 20, lastDoc) {
|
|
9515
|
-
let q =
|
|
9941
|
+
let q = query18(
|
|
9516
9942
|
this.collectionRef,
|
|
9517
|
-
|
|
9518
|
-
|
|
9519
|
-
|
|
9520
|
-
|
|
9943
|
+
where18("isActive", "==", true),
|
|
9944
|
+
where18("tags", "array-contains-any", tags),
|
|
9945
|
+
orderBy7("updatedAt", "desc"),
|
|
9946
|
+
limit10(pageSize)
|
|
9521
9947
|
);
|
|
9522
9948
|
if (lastDoc) {
|
|
9523
|
-
q =
|
|
9949
|
+
q = query18(q, startAfter8(lastDoc));
|
|
9524
9950
|
}
|
|
9525
|
-
const querySnapshot = await
|
|
9951
|
+
const querySnapshot = await getDocs18(q);
|
|
9526
9952
|
const templates = [];
|
|
9527
9953
|
let lastVisible = null;
|
|
9528
|
-
querySnapshot.forEach((
|
|
9529
|
-
templates.push(
|
|
9530
|
-
lastVisible =
|
|
9954
|
+
querySnapshot.forEach((doc35) => {
|
|
9955
|
+
templates.push(doc35.data());
|
|
9956
|
+
lastVisible = doc35;
|
|
9531
9957
|
});
|
|
9532
9958
|
return {
|
|
9533
9959
|
templates,
|
|
@@ -9542,21 +9968,21 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9542
9968
|
* @returns Array of templates and the last document for pagination
|
|
9543
9969
|
*/
|
|
9544
9970
|
async getTemplatesByCreator(userId, pageSize = 20, lastDoc) {
|
|
9545
|
-
let q =
|
|
9971
|
+
let q = query18(
|
|
9546
9972
|
this.collectionRef,
|
|
9547
|
-
|
|
9548
|
-
|
|
9549
|
-
|
|
9973
|
+
where18("createdBy", "==", userId),
|
|
9974
|
+
orderBy7("updatedAt", "desc"),
|
|
9975
|
+
limit10(pageSize)
|
|
9550
9976
|
);
|
|
9551
9977
|
if (lastDoc) {
|
|
9552
|
-
q =
|
|
9978
|
+
q = query18(q, startAfter8(lastDoc));
|
|
9553
9979
|
}
|
|
9554
|
-
const querySnapshot = await
|
|
9980
|
+
const querySnapshot = await getDocs18(q);
|
|
9555
9981
|
const templates = [];
|
|
9556
9982
|
let lastVisible = null;
|
|
9557
|
-
querySnapshot.forEach((
|
|
9558
|
-
templates.push(
|
|
9559
|
-
lastVisible =
|
|
9983
|
+
querySnapshot.forEach((doc35) => {
|
|
9984
|
+
templates.push(doc35.data());
|
|
9985
|
+
lastVisible = doc35;
|
|
9560
9986
|
});
|
|
9561
9987
|
return {
|
|
9562
9988
|
templates,
|
|
@@ -9569,21 +9995,21 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9569
9995
|
* @returns Array of templates
|
|
9570
9996
|
*/
|
|
9571
9997
|
async getAllTemplatesForSelection(options) {
|
|
9572
|
-
let q =
|
|
9998
|
+
let q = query18(
|
|
9573
9999
|
this.collectionRef,
|
|
9574
|
-
|
|
9575
|
-
|
|
10000
|
+
where18("isActive", "==", true),
|
|
10001
|
+
orderBy7("updatedAt", "desc")
|
|
9576
10002
|
);
|
|
9577
10003
|
if ((options == null ? void 0 : options.isUserForm) !== void 0) {
|
|
9578
|
-
q =
|
|
10004
|
+
q = query18(q, where18("isUserForm", "==", options.isUserForm));
|
|
9579
10005
|
}
|
|
9580
10006
|
if ((options == null ? void 0 : options.isRequired) !== void 0) {
|
|
9581
|
-
q =
|
|
10007
|
+
q = query18(q, where18("isRequired", "==", options.isRequired));
|
|
9582
10008
|
}
|
|
9583
|
-
const querySnapshot = await
|
|
10009
|
+
const querySnapshot = await getDocs18(q);
|
|
9584
10010
|
const templates = [];
|
|
9585
|
-
querySnapshot.forEach((
|
|
9586
|
-
templates.push(
|
|
10011
|
+
querySnapshot.forEach((doc35) => {
|
|
10012
|
+
templates.push(doc35.data());
|
|
9587
10013
|
});
|
|
9588
10014
|
return templates;
|
|
9589
10015
|
}
|
|
@@ -9591,15 +10017,15 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9591
10017
|
|
|
9592
10018
|
// src/services/documentation-templates/filled-document.service.ts
|
|
9593
10019
|
import {
|
|
9594
|
-
collection as
|
|
9595
|
-
doc as
|
|
9596
|
-
getDoc as
|
|
9597
|
-
getDocs as
|
|
9598
|
-
setDoc as
|
|
9599
|
-
updateDoc as
|
|
9600
|
-
query as
|
|
9601
|
-
orderBy as
|
|
9602
|
-
limit as
|
|
10020
|
+
collection as collection19,
|
|
10021
|
+
doc as doc19,
|
|
10022
|
+
getDoc as getDoc22,
|
|
10023
|
+
getDocs as getDocs19,
|
|
10024
|
+
setDoc as setDoc17,
|
|
10025
|
+
updateDoc as updateDoc19,
|
|
10026
|
+
query as query19,
|
|
10027
|
+
orderBy as orderBy8,
|
|
10028
|
+
limit as limit11,
|
|
9603
10029
|
startAfter as startAfter9
|
|
9604
10030
|
} from "firebase/firestore";
|
|
9605
10031
|
var FilledDocumentService = class extends BaseService {
|
|
@@ -9656,7 +10082,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9656
10082
|
values: initialValues,
|
|
9657
10083
|
status: initialStatus
|
|
9658
10084
|
};
|
|
9659
|
-
const docRef =
|
|
10085
|
+
const docRef = doc19(
|
|
9660
10086
|
this.db,
|
|
9661
10087
|
APPOINTMENTS_COLLECTION,
|
|
9662
10088
|
// Replaced "appointments"
|
|
@@ -9664,7 +10090,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9664
10090
|
formSubcollection,
|
|
9665
10091
|
documentId3
|
|
9666
10092
|
);
|
|
9667
|
-
await
|
|
10093
|
+
await setDoc17(docRef, filledDocument);
|
|
9668
10094
|
return filledDocument;
|
|
9669
10095
|
}
|
|
9670
10096
|
/**
|
|
@@ -9676,7 +10102,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9676
10102
|
*/
|
|
9677
10103
|
async getFilledDocumentFromAppointmentById(appointmentId, formId, isUserForm) {
|
|
9678
10104
|
const formSubcollection = this.getFormSubcollectionPath(isUserForm);
|
|
9679
|
-
const docRef =
|
|
10105
|
+
const docRef = doc19(
|
|
9680
10106
|
this.db,
|
|
9681
10107
|
APPOINTMENTS_COLLECTION,
|
|
9682
10108
|
// Replaced "appointments"
|
|
@@ -9684,7 +10110,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9684
10110
|
formSubcollection,
|
|
9685
10111
|
formId
|
|
9686
10112
|
);
|
|
9687
|
-
const docSnap = await
|
|
10113
|
+
const docSnap = await getDoc22(docRef);
|
|
9688
10114
|
if (!docSnap.exists()) {
|
|
9689
10115
|
return null;
|
|
9690
10116
|
}
|
|
@@ -9701,7 +10127,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9701
10127
|
*/
|
|
9702
10128
|
async updateFilledDocumentInAppointment(appointmentId, formId, isUserForm, values, status) {
|
|
9703
10129
|
const formSubcollection = this.getFormSubcollectionPath(isUserForm);
|
|
9704
|
-
const docRef =
|
|
10130
|
+
const docRef = doc19(
|
|
9705
10131
|
this.db,
|
|
9706
10132
|
APPOINTMENTS_COLLECTION,
|
|
9707
10133
|
// Replaced "appointments"
|
|
@@ -9733,7 +10159,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9733
10159
|
}
|
|
9734
10160
|
if (Object.keys(updatePayload).length === 1 && "updatedAt" in updatePayload) {
|
|
9735
10161
|
}
|
|
9736
|
-
await
|
|
10162
|
+
await updateDoc19(docRef, updatePayload);
|
|
9737
10163
|
return { ...existingDoc, ...updatePayload };
|
|
9738
10164
|
}
|
|
9739
10165
|
/**
|
|
@@ -9743,20 +10169,20 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9743
10169
|
* @param lastDoc Last document from previous page for pagination.
|
|
9744
10170
|
*/
|
|
9745
10171
|
async getFilledUserFormsForAppointment(appointmentId, pageSize = 20, lastDoc) {
|
|
9746
|
-
const subcollectionRef =
|
|
10172
|
+
const subcollectionRef = collection19(
|
|
9747
10173
|
this.db,
|
|
9748
10174
|
APPOINTMENTS_COLLECTION,
|
|
9749
10175
|
// Replaced "appointments"
|
|
9750
10176
|
appointmentId,
|
|
9751
10177
|
USER_FORMS_SUBCOLLECTION
|
|
9752
10178
|
);
|
|
9753
|
-
let q =
|
|
10179
|
+
let q = query19(
|
|
9754
10180
|
subcollectionRef,
|
|
9755
|
-
|
|
9756
|
-
|
|
10181
|
+
orderBy8("updatedAt", "desc"),
|
|
10182
|
+
limit11(pageSize)
|
|
9757
10183
|
);
|
|
9758
10184
|
if (lastDoc) {
|
|
9759
|
-
q =
|
|
10185
|
+
q = query19(q, startAfter9(lastDoc));
|
|
9760
10186
|
}
|
|
9761
10187
|
return this.executeQuery(q);
|
|
9762
10188
|
}
|
|
@@ -9767,31 +10193,31 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9767
10193
|
* @param lastDoc Last document from previous page for pagination.
|
|
9768
10194
|
*/
|
|
9769
10195
|
async getFilledDoctorFormsForAppointment(appointmentId, pageSize = 20, lastDoc) {
|
|
9770
|
-
const subcollectionRef =
|
|
10196
|
+
const subcollectionRef = collection19(
|
|
9771
10197
|
this.db,
|
|
9772
10198
|
APPOINTMENTS_COLLECTION,
|
|
9773
10199
|
// Replaced "appointments"
|
|
9774
10200
|
appointmentId,
|
|
9775
10201
|
DOCTOR_FORMS_SUBCOLLECTION
|
|
9776
10202
|
);
|
|
9777
|
-
let q =
|
|
10203
|
+
let q = query19(
|
|
9778
10204
|
subcollectionRef,
|
|
9779
|
-
|
|
9780
|
-
|
|
10205
|
+
orderBy8("updatedAt", "desc"),
|
|
10206
|
+
limit11(pageSize)
|
|
9781
10207
|
);
|
|
9782
10208
|
if (lastDoc) {
|
|
9783
|
-
q =
|
|
10209
|
+
q = query19(q, startAfter9(lastDoc));
|
|
9784
10210
|
}
|
|
9785
10211
|
return this.executeQuery(q);
|
|
9786
10212
|
}
|
|
9787
10213
|
// Helper to execute query and return documents + lastDoc
|
|
9788
10214
|
async executeQuery(q) {
|
|
9789
|
-
const querySnapshot = await
|
|
10215
|
+
const querySnapshot = await getDocs19(q);
|
|
9790
10216
|
const documents = [];
|
|
9791
10217
|
let lastVisible = null;
|
|
9792
|
-
querySnapshot.forEach((
|
|
9793
|
-
documents.push(
|
|
9794
|
-
lastVisible =
|
|
10218
|
+
querySnapshot.forEach((doc35) => {
|
|
10219
|
+
documents.push(doc35.data());
|
|
10220
|
+
lastVisible = doc35;
|
|
9795
10221
|
});
|
|
9796
10222
|
return {
|
|
9797
10223
|
documents,
|
|
@@ -9950,7 +10376,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9950
10376
|
};
|
|
9951
10377
|
|
|
9952
10378
|
// src/services/calendar/calendar-refactored.service.ts
|
|
9953
|
-
import { Timestamp as
|
|
10379
|
+
import { Timestamp as Timestamp28, serverTimestamp as serverTimestamp22 } from "firebase/firestore";
|
|
9954
10380
|
|
|
9955
10381
|
// src/types/calendar/synced-calendar.types.ts
|
|
9956
10382
|
var SyncedCalendarProvider = /* @__PURE__ */ ((SyncedCalendarProvider3) => {
|
|
@@ -9963,23 +10389,23 @@ var SYNCED_CALENDARS_COLLECTION = "syncedCalendars";
|
|
|
9963
10389
|
|
|
9964
10390
|
// src/services/calendar/calendar-refactored.service.ts
|
|
9965
10391
|
import {
|
|
9966
|
-
doc as
|
|
9967
|
-
getDoc as
|
|
9968
|
-
collection as
|
|
9969
|
-
query as
|
|
9970
|
-
where as
|
|
9971
|
-
getDocs as
|
|
9972
|
-
setDoc as
|
|
9973
|
-
updateDoc as
|
|
9974
|
-
} from "firebase/firestore";
|
|
9975
|
-
|
|
9976
|
-
// src/validations/calendar.schema.ts
|
|
9977
|
-
import { z as z23 } from "zod";
|
|
9978
|
-
import { Timestamp as
|
|
10392
|
+
doc as doc26,
|
|
10393
|
+
getDoc as getDoc28,
|
|
10394
|
+
collection as collection25,
|
|
10395
|
+
query as query25,
|
|
10396
|
+
where as where25,
|
|
10397
|
+
getDocs as getDocs25,
|
|
10398
|
+
setDoc as setDoc23,
|
|
10399
|
+
updateDoc as updateDoc25
|
|
10400
|
+
} from "firebase/firestore";
|
|
10401
|
+
|
|
10402
|
+
// src/validations/calendar.schema.ts
|
|
10403
|
+
import { z as z23 } from "zod";
|
|
10404
|
+
import { Timestamp as Timestamp21 } from "firebase/firestore";
|
|
9979
10405
|
|
|
9980
10406
|
// src/validations/profile-info.schema.ts
|
|
9981
10407
|
import { z as z22 } from "zod";
|
|
9982
|
-
import { Timestamp as
|
|
10408
|
+
import { Timestamp as Timestamp20 } from "firebase/firestore";
|
|
9983
10409
|
var clinicInfoSchema2 = z22.object({
|
|
9984
10410
|
id: z22.string(),
|
|
9985
10411
|
featuredPhoto: z22.string(),
|
|
@@ -10001,19 +10427,19 @@ var patientProfileInfoSchema = z22.object({
|
|
|
10001
10427
|
fullName: z22.string(),
|
|
10002
10428
|
email: z22.string().email(),
|
|
10003
10429
|
phone: z22.string().nullable(),
|
|
10004
|
-
dateOfBirth: z22.instanceof(
|
|
10430
|
+
dateOfBirth: z22.instanceof(Timestamp20),
|
|
10005
10431
|
gender: z22.nativeEnum(Gender)
|
|
10006
10432
|
});
|
|
10007
10433
|
|
|
10008
10434
|
// src/validations/calendar.schema.ts
|
|
10009
10435
|
var MIN_APPOINTMENT_DURATION = 15;
|
|
10010
10436
|
var calendarEventTimeSchema = z23.object({
|
|
10011
|
-
start: z23.instanceof(Date).or(z23.instanceof(
|
|
10012
|
-
end: z23.instanceof(Date).or(z23.instanceof(
|
|
10437
|
+
start: z23.instanceof(Date).or(z23.instanceof(Timestamp21)),
|
|
10438
|
+
end: z23.instanceof(Date).or(z23.instanceof(Timestamp21))
|
|
10013
10439
|
}).refine(
|
|
10014
10440
|
(data) => {
|
|
10015
|
-
const startDate = data.start instanceof
|
|
10016
|
-
const endDate = data.end instanceof
|
|
10441
|
+
const startDate = data.start instanceof Timestamp21 ? data.start.toDate() : data.start;
|
|
10442
|
+
const endDate = data.end instanceof Timestamp21 ? data.end.toDate() : data.end;
|
|
10017
10443
|
return startDate < endDate;
|
|
10018
10444
|
},
|
|
10019
10445
|
{
|
|
@@ -10022,7 +10448,7 @@ var calendarEventTimeSchema = z23.object({
|
|
|
10022
10448
|
}
|
|
10023
10449
|
).refine(
|
|
10024
10450
|
(data) => {
|
|
10025
|
-
const startDate = data.start instanceof
|
|
10451
|
+
const startDate = data.start instanceof Timestamp21 ? data.start.toDate() : data.start;
|
|
10026
10452
|
return startDate > /* @__PURE__ */ new Date();
|
|
10027
10453
|
},
|
|
10028
10454
|
{
|
|
@@ -10041,7 +10467,7 @@ var timeSlotSchema2 = z23.object({
|
|
|
10041
10467
|
var syncedCalendarEventSchema = z23.object({
|
|
10042
10468
|
eventId: z23.string(),
|
|
10043
10469
|
syncedCalendarProvider: z23.nativeEnum(SyncedCalendarProvider),
|
|
10044
|
-
syncedAt: z23.instanceof(Date).or(z23.instanceof(
|
|
10470
|
+
syncedAt: z23.instanceof(Date).or(z23.instanceof(Timestamp21))
|
|
10045
10471
|
});
|
|
10046
10472
|
var procedureInfoSchema = z23.object({
|
|
10047
10473
|
name: z23.string(),
|
|
@@ -10143,60 +10569,60 @@ var calendarEventSchema = z23.object({
|
|
|
10143
10569
|
status: z23.nativeEnum(CalendarEventStatus),
|
|
10144
10570
|
syncStatus: z23.nativeEnum(CalendarSyncStatus),
|
|
10145
10571
|
eventType: z23.nativeEnum(CalendarEventType),
|
|
10146
|
-
createdAt: z23.instanceof(Date).or(z23.instanceof(
|
|
10147
|
-
updatedAt: z23.instanceof(Date).or(z23.instanceof(
|
|
10572
|
+
createdAt: z23.instanceof(Date).or(z23.instanceof(Timestamp21)),
|
|
10573
|
+
updatedAt: z23.instanceof(Date).or(z23.instanceof(Timestamp21))
|
|
10148
10574
|
});
|
|
10149
10575
|
|
|
10150
10576
|
// src/services/calendar/utils/clinic.utils.ts
|
|
10151
10577
|
import {
|
|
10152
|
-
collection as
|
|
10153
|
-
doc as
|
|
10154
|
-
getDoc as
|
|
10155
|
-
getDocs as
|
|
10156
|
-
setDoc as
|
|
10157
|
-
updateDoc as
|
|
10158
|
-
deleteDoc as
|
|
10159
|
-
query as
|
|
10160
|
-
where as
|
|
10161
|
-
orderBy as
|
|
10162
|
-
Timestamp as
|
|
10163
|
-
serverTimestamp as
|
|
10578
|
+
collection as collection20,
|
|
10579
|
+
doc as doc21,
|
|
10580
|
+
getDoc as getDoc23,
|
|
10581
|
+
getDocs as getDocs20,
|
|
10582
|
+
setDoc as setDoc18,
|
|
10583
|
+
updateDoc as updateDoc20,
|
|
10584
|
+
deleteDoc as deleteDoc12,
|
|
10585
|
+
query as query20,
|
|
10586
|
+
where as where20,
|
|
10587
|
+
orderBy as orderBy9,
|
|
10588
|
+
Timestamp as Timestamp22,
|
|
10589
|
+
serverTimestamp as serverTimestamp17
|
|
10164
10590
|
} from "firebase/firestore";
|
|
10165
10591
|
|
|
10166
10592
|
// src/services/calendar/utils/docs.utils.ts
|
|
10167
|
-
import { doc as
|
|
10593
|
+
import { doc as doc20 } from "firebase/firestore";
|
|
10168
10594
|
function getPractitionerCalendarEventDocRef(db, practitionerId, eventId) {
|
|
10169
|
-
return
|
|
10595
|
+
return doc20(
|
|
10170
10596
|
db,
|
|
10171
10597
|
`${PRACTITIONERS_COLLECTION}/${practitionerId}/${CALENDAR_COLLECTION}/${eventId}`
|
|
10172
10598
|
);
|
|
10173
10599
|
}
|
|
10174
10600
|
function getPatientCalendarEventDocRef(db, patientId, eventId) {
|
|
10175
|
-
return
|
|
10601
|
+
return doc20(
|
|
10176
10602
|
db,
|
|
10177
10603
|
`${PATIENTS_COLLECTION}/${patientId}/${CALENDAR_COLLECTION}/${eventId}`
|
|
10178
10604
|
);
|
|
10179
10605
|
}
|
|
10180
10606
|
function getClinicCalendarEventDocRef(db, clinicId, eventId) {
|
|
10181
|
-
return
|
|
10607
|
+
return doc20(
|
|
10182
10608
|
db,
|
|
10183
10609
|
`${CLINICS_COLLECTION}/${clinicId}/${CALENDAR_COLLECTION}/${eventId}`
|
|
10184
10610
|
);
|
|
10185
10611
|
}
|
|
10186
10612
|
function getPractitionerSyncedCalendarDocRef(db, practitionerId, syncedCalendarId) {
|
|
10187
|
-
return
|
|
10613
|
+
return doc20(
|
|
10188
10614
|
db,
|
|
10189
10615
|
`${PRACTITIONERS_COLLECTION}/${practitionerId}/syncedCalendars/${syncedCalendarId}`
|
|
10190
10616
|
);
|
|
10191
10617
|
}
|
|
10192
10618
|
function getPatientSyncedCalendarDocRef(db, patientId, syncedCalendarId) {
|
|
10193
|
-
return
|
|
10619
|
+
return doc20(
|
|
10194
10620
|
db,
|
|
10195
10621
|
`${PATIENTS_COLLECTION}/${patientId}/syncedCalendars/${syncedCalendarId}`
|
|
10196
10622
|
);
|
|
10197
10623
|
}
|
|
10198
10624
|
function getClinicSyncedCalendarDocRef(db, clinicId, syncedCalendarId) {
|
|
10199
|
-
return
|
|
10625
|
+
return doc20(
|
|
10200
10626
|
db,
|
|
10201
10627
|
`${CLINICS_COLLECTION}/${clinicId}/syncedCalendars/${syncedCalendarId}`
|
|
10202
10628
|
);
|
|
@@ -10209,31 +10635,31 @@ async function createClinicCalendarEventUtil(db, clinicId, eventData, generateId
|
|
|
10209
10635
|
const newEvent = {
|
|
10210
10636
|
id: eventId,
|
|
10211
10637
|
...eventData,
|
|
10212
|
-
createdAt:
|
|
10213
|
-
updatedAt:
|
|
10638
|
+
createdAt: serverTimestamp17(),
|
|
10639
|
+
updatedAt: serverTimestamp17()
|
|
10214
10640
|
};
|
|
10215
|
-
await
|
|
10641
|
+
await setDoc18(eventRef, newEvent);
|
|
10216
10642
|
return {
|
|
10217
10643
|
...newEvent,
|
|
10218
|
-
createdAt:
|
|
10219
|
-
updatedAt:
|
|
10644
|
+
createdAt: Timestamp22.now(),
|
|
10645
|
+
updatedAt: Timestamp22.now()
|
|
10220
10646
|
};
|
|
10221
10647
|
}
|
|
10222
10648
|
async function updateClinicCalendarEventUtil(db, clinicId, eventId, updateData) {
|
|
10223
10649
|
const eventRef = getClinicCalendarEventDocRef(db, clinicId, eventId);
|
|
10224
10650
|
const updates = {
|
|
10225
10651
|
...updateData,
|
|
10226
|
-
updatedAt:
|
|
10652
|
+
updatedAt: serverTimestamp17()
|
|
10227
10653
|
};
|
|
10228
|
-
await
|
|
10229
|
-
const updatedDoc = await
|
|
10654
|
+
await updateDoc20(eventRef, updates);
|
|
10655
|
+
const updatedDoc = await getDoc23(eventRef);
|
|
10230
10656
|
if (!updatedDoc.exists()) {
|
|
10231
10657
|
throw new Error("Event not found after update");
|
|
10232
10658
|
}
|
|
10233
10659
|
return updatedDoc.data();
|
|
10234
10660
|
}
|
|
10235
10661
|
async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
|
|
10236
|
-
const clinicDoc = await
|
|
10662
|
+
const clinicDoc = await getDoc23(doc21(db, `clinics/${clinicId}`));
|
|
10237
10663
|
if (!clinicDoc.exists()) {
|
|
10238
10664
|
throw new Error(`Clinic with ID ${clinicId} not found`);
|
|
10239
10665
|
}
|
|
@@ -10242,8 +10668,8 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
|
|
|
10242
10668
|
if (!clinicGroupId) {
|
|
10243
10669
|
return false;
|
|
10244
10670
|
}
|
|
10245
|
-
const clinicGroupDoc = await
|
|
10246
|
-
|
|
10671
|
+
const clinicGroupDoc = await getDoc23(
|
|
10672
|
+
doc21(db, `${CLINIC_GROUPS_COLLECTION}/${clinicGroupId}`)
|
|
10247
10673
|
);
|
|
10248
10674
|
if (!clinicGroupDoc.exists()) {
|
|
10249
10675
|
return false;
|
|
@@ -10254,17 +10680,17 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
|
|
|
10254
10680
|
|
|
10255
10681
|
// src/services/calendar/utils/patient.utils.ts
|
|
10256
10682
|
import {
|
|
10257
|
-
collection as
|
|
10258
|
-
getDoc as
|
|
10259
|
-
getDocs as
|
|
10260
|
-
setDoc as
|
|
10261
|
-
updateDoc as
|
|
10262
|
-
deleteDoc as
|
|
10263
|
-
query as
|
|
10264
|
-
where as
|
|
10265
|
-
orderBy as
|
|
10266
|
-
Timestamp as
|
|
10267
|
-
serverTimestamp as
|
|
10683
|
+
collection as collection21,
|
|
10684
|
+
getDoc as getDoc24,
|
|
10685
|
+
getDocs as getDocs21,
|
|
10686
|
+
setDoc as setDoc19,
|
|
10687
|
+
updateDoc as updateDoc21,
|
|
10688
|
+
deleteDoc as deleteDoc13,
|
|
10689
|
+
query as query21,
|
|
10690
|
+
where as where21,
|
|
10691
|
+
orderBy as orderBy10,
|
|
10692
|
+
Timestamp as Timestamp23,
|
|
10693
|
+
serverTimestamp as serverTimestamp18
|
|
10268
10694
|
} from "firebase/firestore";
|
|
10269
10695
|
async function createPatientCalendarEventUtil(db, patientId, eventData, generateId2) {
|
|
10270
10696
|
const eventId = generateId2();
|
|
@@ -10272,24 +10698,24 @@ async function createPatientCalendarEventUtil(db, patientId, eventData, generate
|
|
|
10272
10698
|
const newEvent = {
|
|
10273
10699
|
id: eventId,
|
|
10274
10700
|
...eventData,
|
|
10275
|
-
createdAt:
|
|
10276
|
-
updatedAt:
|
|
10701
|
+
createdAt: serverTimestamp18(),
|
|
10702
|
+
updatedAt: serverTimestamp18()
|
|
10277
10703
|
};
|
|
10278
|
-
await
|
|
10704
|
+
await setDoc19(eventRef, newEvent);
|
|
10279
10705
|
return {
|
|
10280
10706
|
...newEvent,
|
|
10281
|
-
createdAt:
|
|
10282
|
-
updatedAt:
|
|
10707
|
+
createdAt: Timestamp23.now(),
|
|
10708
|
+
updatedAt: Timestamp23.now()
|
|
10283
10709
|
};
|
|
10284
10710
|
}
|
|
10285
10711
|
async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData) {
|
|
10286
10712
|
const eventRef = getPatientCalendarEventDocRef(db, patientId, eventId);
|
|
10287
10713
|
const updates = {
|
|
10288
10714
|
...updateData,
|
|
10289
|
-
updatedAt:
|
|
10715
|
+
updatedAt: serverTimestamp18()
|
|
10290
10716
|
};
|
|
10291
|
-
await
|
|
10292
|
-
const updatedDoc = await
|
|
10717
|
+
await updateDoc21(eventRef, updates);
|
|
10718
|
+
const updatedDoc = await getDoc24(eventRef);
|
|
10293
10719
|
if (!updatedDoc.exists()) {
|
|
10294
10720
|
throw new Error("Event not found after update");
|
|
10295
10721
|
}
|
|
@@ -10298,17 +10724,17 @@ async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData
|
|
|
10298
10724
|
|
|
10299
10725
|
// src/services/calendar/utils/practitioner.utils.ts
|
|
10300
10726
|
import {
|
|
10301
|
-
collection as
|
|
10302
|
-
getDoc as
|
|
10303
|
-
getDocs as
|
|
10304
|
-
setDoc as
|
|
10305
|
-
updateDoc as
|
|
10306
|
-
deleteDoc as
|
|
10307
|
-
query as
|
|
10308
|
-
where as
|
|
10309
|
-
orderBy as
|
|
10310
|
-
Timestamp as
|
|
10311
|
-
serverTimestamp as
|
|
10727
|
+
collection as collection22,
|
|
10728
|
+
getDoc as getDoc25,
|
|
10729
|
+
getDocs as getDocs22,
|
|
10730
|
+
setDoc as setDoc20,
|
|
10731
|
+
updateDoc as updateDoc22,
|
|
10732
|
+
deleteDoc as deleteDoc14,
|
|
10733
|
+
query as query22,
|
|
10734
|
+
where as where22,
|
|
10735
|
+
orderBy as orderBy11,
|
|
10736
|
+
Timestamp as Timestamp24,
|
|
10737
|
+
serverTimestamp as serverTimestamp19
|
|
10312
10738
|
} from "firebase/firestore";
|
|
10313
10739
|
async function createPractitionerCalendarEventUtil(db, practitionerId, eventData, generateId2) {
|
|
10314
10740
|
const eventId = generateId2();
|
|
@@ -10320,14 +10746,14 @@ async function createPractitionerCalendarEventUtil(db, practitionerId, eventData
|
|
|
10320
10746
|
const newEvent = {
|
|
10321
10747
|
id: eventId,
|
|
10322
10748
|
...eventData,
|
|
10323
|
-
createdAt:
|
|
10324
|
-
updatedAt:
|
|
10749
|
+
createdAt: serverTimestamp19(),
|
|
10750
|
+
updatedAt: serverTimestamp19()
|
|
10325
10751
|
};
|
|
10326
|
-
await
|
|
10752
|
+
await setDoc20(eventRef, newEvent);
|
|
10327
10753
|
return {
|
|
10328
10754
|
...newEvent,
|
|
10329
|
-
createdAt:
|
|
10330
|
-
updatedAt:
|
|
10755
|
+
createdAt: Timestamp24.now(),
|
|
10756
|
+
updatedAt: Timestamp24.now()
|
|
10331
10757
|
};
|
|
10332
10758
|
}
|
|
10333
10759
|
async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId, updateData) {
|
|
@@ -10338,10 +10764,10 @@ async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId,
|
|
|
10338
10764
|
);
|
|
10339
10765
|
const updates = {
|
|
10340
10766
|
...updateData,
|
|
10341
|
-
updatedAt:
|
|
10767
|
+
updatedAt: serverTimestamp19()
|
|
10342
10768
|
};
|
|
10343
|
-
await
|
|
10344
|
-
const updatedDoc = await
|
|
10769
|
+
await updateDoc22(eventRef, updates);
|
|
10770
|
+
const updatedDoc = await getDoc25(eventRef);
|
|
10345
10771
|
if (!updatedDoc.exists()) {
|
|
10346
10772
|
throw new Error("Event not found after update");
|
|
10347
10773
|
}
|
|
@@ -10400,18 +10826,18 @@ async function updateAppointmentUtil(db, clinicId, practitionerId, patientId, ev
|
|
|
10400
10826
|
|
|
10401
10827
|
// src/services/calendar/utils/calendar-event.utils.ts
|
|
10402
10828
|
import {
|
|
10403
|
-
collection as
|
|
10404
|
-
doc as
|
|
10405
|
-
getDoc as
|
|
10406
|
-
getDocs as
|
|
10407
|
-
setDoc as
|
|
10408
|
-
updateDoc as
|
|
10409
|
-
deleteDoc as
|
|
10410
|
-
query as
|
|
10411
|
-
where as
|
|
10412
|
-
orderBy as
|
|
10413
|
-
Timestamp as
|
|
10414
|
-
serverTimestamp as
|
|
10829
|
+
collection as collection23,
|
|
10830
|
+
doc as doc24,
|
|
10831
|
+
getDoc as getDoc26,
|
|
10832
|
+
getDocs as getDocs23,
|
|
10833
|
+
setDoc as setDoc21,
|
|
10834
|
+
updateDoc as updateDoc23,
|
|
10835
|
+
deleteDoc as deleteDoc15,
|
|
10836
|
+
query as query23,
|
|
10837
|
+
where as where23,
|
|
10838
|
+
orderBy as orderBy12,
|
|
10839
|
+
Timestamp as Timestamp25,
|
|
10840
|
+
serverTimestamp as serverTimestamp20
|
|
10415
10841
|
} from "firebase/firestore";
|
|
10416
10842
|
async function searchCalendarEventsUtil(db, params) {
|
|
10417
10843
|
const { searchLocation, entityId, ...filters } = params;
|
|
@@ -10455,7 +10881,7 @@ async function searchCalendarEventsUtil(db, params) {
|
|
|
10455
10881
|
);
|
|
10456
10882
|
}
|
|
10457
10883
|
baseCollectionPath = `${CLINICS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
|
|
10458
|
-
constraints.push(
|
|
10884
|
+
constraints.push(where23("clinicBranchId", "==", entityId));
|
|
10459
10885
|
if (filters.clinicId && filters.clinicId !== entityId) {
|
|
10460
10886
|
console.warn(
|
|
10461
10887
|
`Provided clinicId filter (${filters.clinicId}) does not match search entityId (${entityId}). Returning empty results.`
|
|
@@ -10467,36 +10893,36 @@ async function searchCalendarEventsUtil(db, params) {
|
|
|
10467
10893
|
default:
|
|
10468
10894
|
throw new Error(`Invalid search location: ${searchLocation}`);
|
|
10469
10895
|
}
|
|
10470
|
-
const collectionRef =
|
|
10896
|
+
const collectionRef = collection23(db, baseCollectionPath);
|
|
10471
10897
|
if (filters.clinicId) {
|
|
10472
|
-
constraints.push(
|
|
10898
|
+
constraints.push(where23("clinicBranchId", "==", filters.clinicId));
|
|
10473
10899
|
}
|
|
10474
10900
|
if (filters.practitionerId) {
|
|
10475
10901
|
constraints.push(
|
|
10476
|
-
|
|
10902
|
+
where23("practitionerProfileId", "==", filters.practitionerId)
|
|
10477
10903
|
);
|
|
10478
10904
|
}
|
|
10479
10905
|
if (filters.patientId) {
|
|
10480
|
-
constraints.push(
|
|
10906
|
+
constraints.push(where23("patientProfileId", "==", filters.patientId));
|
|
10481
10907
|
}
|
|
10482
10908
|
if (filters.procedureId) {
|
|
10483
|
-
constraints.push(
|
|
10909
|
+
constraints.push(where23("procedureId", "==", filters.procedureId));
|
|
10484
10910
|
}
|
|
10485
10911
|
if (filters.eventStatus) {
|
|
10486
|
-
constraints.push(
|
|
10912
|
+
constraints.push(where23("status", "==", filters.eventStatus));
|
|
10487
10913
|
}
|
|
10488
10914
|
if (filters.eventType) {
|
|
10489
|
-
constraints.push(
|
|
10915
|
+
constraints.push(where23("eventType", "==", filters.eventType));
|
|
10490
10916
|
}
|
|
10491
10917
|
if (filters.dateRange) {
|
|
10492
|
-
constraints.push(
|
|
10493
|
-
constraints.push(
|
|
10918
|
+
constraints.push(where23("eventTime.start", ">=", filters.dateRange.start));
|
|
10919
|
+
constraints.push(where23("eventTime.start", "<=", filters.dateRange.end));
|
|
10494
10920
|
}
|
|
10495
10921
|
try {
|
|
10496
|
-
const finalQuery =
|
|
10497
|
-
const querySnapshot = await
|
|
10922
|
+
const finalQuery = query23(collectionRef, ...constraints);
|
|
10923
|
+
const querySnapshot = await getDocs23(finalQuery);
|
|
10498
10924
|
const events = querySnapshot.docs.map(
|
|
10499
|
-
(
|
|
10925
|
+
(doc35) => ({ id: doc35.id, ...doc35.data() })
|
|
10500
10926
|
);
|
|
10501
10927
|
return events;
|
|
10502
10928
|
} catch (error) {
|
|
@@ -10507,16 +10933,16 @@ async function searchCalendarEventsUtil(db, params) {
|
|
|
10507
10933
|
|
|
10508
10934
|
// src/services/calendar/utils/synced-calendar.utils.ts
|
|
10509
10935
|
import {
|
|
10510
|
-
collection as
|
|
10511
|
-
getDoc as
|
|
10512
|
-
getDocs as
|
|
10513
|
-
setDoc as
|
|
10514
|
-
updateDoc as
|
|
10515
|
-
deleteDoc as
|
|
10516
|
-
query as
|
|
10517
|
-
orderBy as
|
|
10518
|
-
Timestamp as
|
|
10519
|
-
serverTimestamp as
|
|
10936
|
+
collection as collection24,
|
|
10937
|
+
getDoc as getDoc27,
|
|
10938
|
+
getDocs as getDocs24,
|
|
10939
|
+
setDoc as setDoc22,
|
|
10940
|
+
updateDoc as updateDoc24,
|
|
10941
|
+
deleteDoc as deleteDoc16,
|
|
10942
|
+
query as query24,
|
|
10943
|
+
orderBy as orderBy13,
|
|
10944
|
+
Timestamp as Timestamp26,
|
|
10945
|
+
serverTimestamp as serverTimestamp21
|
|
10520
10946
|
} from "firebase/firestore";
|
|
10521
10947
|
async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendarData, generateId2) {
|
|
10522
10948
|
const calendarId = generateId2();
|
|
@@ -10528,14 +10954,14 @@ async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendar
|
|
|
10528
10954
|
const newCalendar = {
|
|
10529
10955
|
id: calendarId,
|
|
10530
10956
|
...calendarData,
|
|
10531
|
-
createdAt:
|
|
10532
|
-
updatedAt:
|
|
10957
|
+
createdAt: serverTimestamp21(),
|
|
10958
|
+
updatedAt: serverTimestamp21()
|
|
10533
10959
|
};
|
|
10534
|
-
await
|
|
10960
|
+
await setDoc22(calendarRef, newCalendar);
|
|
10535
10961
|
return {
|
|
10536
10962
|
...newCalendar,
|
|
10537
|
-
createdAt:
|
|
10538
|
-
updatedAt:
|
|
10963
|
+
createdAt: Timestamp26.now(),
|
|
10964
|
+
updatedAt: Timestamp26.now()
|
|
10539
10965
|
};
|
|
10540
10966
|
}
|
|
10541
10967
|
async function createPatientSyncedCalendarUtil(db, patientId, calendarData, generateId2) {
|
|
@@ -10544,14 +10970,14 @@ async function createPatientSyncedCalendarUtil(db, patientId, calendarData, gene
|
|
|
10544
10970
|
const newCalendar = {
|
|
10545
10971
|
id: calendarId,
|
|
10546
10972
|
...calendarData,
|
|
10547
|
-
createdAt:
|
|
10548
|
-
updatedAt:
|
|
10973
|
+
createdAt: serverTimestamp21(),
|
|
10974
|
+
updatedAt: serverTimestamp21()
|
|
10549
10975
|
};
|
|
10550
|
-
await
|
|
10976
|
+
await setDoc22(calendarRef, newCalendar);
|
|
10551
10977
|
return {
|
|
10552
10978
|
...newCalendar,
|
|
10553
|
-
createdAt:
|
|
10554
|
-
updatedAt:
|
|
10979
|
+
createdAt: Timestamp26.now(),
|
|
10980
|
+
updatedAt: Timestamp26.now()
|
|
10555
10981
|
};
|
|
10556
10982
|
}
|
|
10557
10983
|
async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, generateId2) {
|
|
@@ -10560,14 +10986,14 @@ async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, genera
|
|
|
10560
10986
|
const newCalendar = {
|
|
10561
10987
|
id: calendarId,
|
|
10562
10988
|
...calendarData,
|
|
10563
|
-
createdAt:
|
|
10564
|
-
updatedAt:
|
|
10989
|
+
createdAt: serverTimestamp21(),
|
|
10990
|
+
updatedAt: serverTimestamp21()
|
|
10565
10991
|
};
|
|
10566
|
-
await
|
|
10992
|
+
await setDoc22(calendarRef, newCalendar);
|
|
10567
10993
|
return {
|
|
10568
10994
|
...newCalendar,
|
|
10569
|
-
createdAt:
|
|
10570
|
-
updatedAt:
|
|
10995
|
+
createdAt: Timestamp26.now(),
|
|
10996
|
+
updatedAt: Timestamp26.now()
|
|
10571
10997
|
};
|
|
10572
10998
|
}
|
|
10573
10999
|
async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId) {
|
|
@@ -10576,54 +11002,54 @@ async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId)
|
|
|
10576
11002
|
practitionerId,
|
|
10577
11003
|
calendarId
|
|
10578
11004
|
);
|
|
10579
|
-
const calendarDoc = await
|
|
11005
|
+
const calendarDoc = await getDoc27(calendarRef);
|
|
10580
11006
|
if (!calendarDoc.exists()) {
|
|
10581
11007
|
return null;
|
|
10582
11008
|
}
|
|
10583
11009
|
return calendarDoc.data();
|
|
10584
11010
|
}
|
|
10585
11011
|
async function getPractitionerSyncedCalendarsUtil(db, practitionerId) {
|
|
10586
|
-
const calendarsRef =
|
|
11012
|
+
const calendarsRef = collection24(
|
|
10587
11013
|
db,
|
|
10588
11014
|
`practitioners/${practitionerId}/${SYNCED_CALENDARS_COLLECTION}`
|
|
10589
11015
|
);
|
|
10590
|
-
const q =
|
|
10591
|
-
const querySnapshot = await
|
|
10592
|
-
return querySnapshot.docs.map((
|
|
11016
|
+
const q = query24(calendarsRef, orderBy13("createdAt", "desc"));
|
|
11017
|
+
const querySnapshot = await getDocs24(q);
|
|
11018
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
10593
11019
|
}
|
|
10594
11020
|
async function getPatientSyncedCalendarUtil(db, patientId, calendarId) {
|
|
10595
11021
|
const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
|
|
10596
|
-
const calendarDoc = await
|
|
11022
|
+
const calendarDoc = await getDoc27(calendarRef);
|
|
10597
11023
|
if (!calendarDoc.exists()) {
|
|
10598
11024
|
return null;
|
|
10599
11025
|
}
|
|
10600
11026
|
return calendarDoc.data();
|
|
10601
11027
|
}
|
|
10602
11028
|
async function getPatientSyncedCalendarsUtil(db, patientId) {
|
|
10603
|
-
const calendarsRef =
|
|
11029
|
+
const calendarsRef = collection24(
|
|
10604
11030
|
db,
|
|
10605
11031
|
`patients/${patientId}/${SYNCED_CALENDARS_COLLECTION}`
|
|
10606
11032
|
);
|
|
10607
|
-
const q =
|
|
10608
|
-
const querySnapshot = await
|
|
10609
|
-
return querySnapshot.docs.map((
|
|
11033
|
+
const q = query24(calendarsRef, orderBy13("createdAt", "desc"));
|
|
11034
|
+
const querySnapshot = await getDocs24(q);
|
|
11035
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
10610
11036
|
}
|
|
10611
11037
|
async function getClinicSyncedCalendarUtil(db, clinicId, calendarId) {
|
|
10612
11038
|
const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
|
|
10613
|
-
const calendarDoc = await
|
|
11039
|
+
const calendarDoc = await getDoc27(calendarRef);
|
|
10614
11040
|
if (!calendarDoc.exists()) {
|
|
10615
11041
|
return null;
|
|
10616
11042
|
}
|
|
10617
11043
|
return calendarDoc.data();
|
|
10618
11044
|
}
|
|
10619
11045
|
async function getClinicSyncedCalendarsUtil(db, clinicId) {
|
|
10620
|
-
const calendarsRef =
|
|
11046
|
+
const calendarsRef = collection24(
|
|
10621
11047
|
db,
|
|
10622
11048
|
`clinics/${clinicId}/${SYNCED_CALENDARS_COLLECTION}`
|
|
10623
11049
|
);
|
|
10624
|
-
const q =
|
|
10625
|
-
const querySnapshot = await
|
|
10626
|
-
return querySnapshot.docs.map((
|
|
11050
|
+
const q = query24(calendarsRef, orderBy13("createdAt", "desc"));
|
|
11051
|
+
const querySnapshot = await getDocs24(q);
|
|
11052
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
10627
11053
|
}
|
|
10628
11054
|
async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendarId, updateData) {
|
|
10629
11055
|
const calendarRef = getPractitionerSyncedCalendarDocRef(
|
|
@@ -10633,10 +11059,10 @@ async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendar
|
|
|
10633
11059
|
);
|
|
10634
11060
|
const updates = {
|
|
10635
11061
|
...updateData,
|
|
10636
|
-
updatedAt:
|
|
11062
|
+
updatedAt: serverTimestamp21()
|
|
10637
11063
|
};
|
|
10638
|
-
await
|
|
10639
|
-
const updatedDoc = await
|
|
11064
|
+
await updateDoc24(calendarRef, updates);
|
|
11065
|
+
const updatedDoc = await getDoc27(calendarRef);
|
|
10640
11066
|
if (!updatedDoc.exists()) {
|
|
10641
11067
|
throw new Error("Synced calendar not found after update");
|
|
10642
11068
|
}
|
|
@@ -10646,10 +11072,10 @@ async function updatePatientSyncedCalendarUtil(db, patientId, calendarId, update
|
|
|
10646
11072
|
const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
|
|
10647
11073
|
const updates = {
|
|
10648
11074
|
...updateData,
|
|
10649
|
-
updatedAt:
|
|
11075
|
+
updatedAt: serverTimestamp21()
|
|
10650
11076
|
};
|
|
10651
|
-
await
|
|
10652
|
-
const updatedDoc = await
|
|
11077
|
+
await updateDoc24(calendarRef, updates);
|
|
11078
|
+
const updatedDoc = await getDoc27(calendarRef);
|
|
10653
11079
|
if (!updatedDoc.exists()) {
|
|
10654
11080
|
throw new Error("Synced calendar not found after update");
|
|
10655
11081
|
}
|
|
@@ -10659,10 +11085,10 @@ async function updateClinicSyncedCalendarUtil(db, clinicId, calendarId, updateDa
|
|
|
10659
11085
|
const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
|
|
10660
11086
|
const updates = {
|
|
10661
11087
|
...updateData,
|
|
10662
|
-
updatedAt:
|
|
11088
|
+
updatedAt: serverTimestamp21()
|
|
10663
11089
|
};
|
|
10664
|
-
await
|
|
10665
|
-
const updatedDoc = await
|
|
11090
|
+
await updateDoc24(calendarRef, updates);
|
|
11091
|
+
const updatedDoc = await getDoc27(calendarRef);
|
|
10666
11092
|
if (!updatedDoc.exists()) {
|
|
10667
11093
|
throw new Error("Synced calendar not found after update");
|
|
10668
11094
|
}
|
|
@@ -10674,19 +11100,19 @@ async function deletePractitionerSyncedCalendarUtil(db, practitionerId, calendar
|
|
|
10674
11100
|
practitionerId,
|
|
10675
11101
|
calendarId
|
|
10676
11102
|
);
|
|
10677
|
-
await
|
|
11103
|
+
await deleteDoc16(calendarRef);
|
|
10678
11104
|
}
|
|
10679
11105
|
async function deletePatientSyncedCalendarUtil(db, patientId, calendarId) {
|
|
10680
11106
|
const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
|
|
10681
|
-
await
|
|
11107
|
+
await deleteDoc16(calendarRef);
|
|
10682
11108
|
}
|
|
10683
11109
|
async function deleteClinicSyncedCalendarUtil(db, clinicId, calendarId) {
|
|
10684
11110
|
const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
|
|
10685
|
-
await
|
|
11111
|
+
await deleteDoc16(calendarRef);
|
|
10686
11112
|
}
|
|
10687
11113
|
async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarId) {
|
|
10688
11114
|
const updateData = {
|
|
10689
|
-
lastSyncedAt:
|
|
11115
|
+
lastSyncedAt: Timestamp26.now()
|
|
10690
11116
|
};
|
|
10691
11117
|
switch (entityType) {
|
|
10692
11118
|
case "practitioner":
|
|
@@ -10716,7 +11142,7 @@ async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarI
|
|
|
10716
11142
|
}
|
|
10717
11143
|
|
|
10718
11144
|
// src/services/calendar/utils/google-calendar.utils.ts
|
|
10719
|
-
import { Timestamp as
|
|
11145
|
+
import { Timestamp as Timestamp27 } from "firebase/firestore";
|
|
10720
11146
|
var GOOGLE_CALENDAR_API_URL = "https://www.googleapis.com/calendar/v3";
|
|
10721
11147
|
var GOOGLE_OAUTH_URL = "https://oauth2.googleapis.com/token";
|
|
10722
11148
|
var CLIENT_ID = "your-client-id";
|
|
@@ -10836,7 +11262,7 @@ async function ensureValidToken(db, entityType, entityId, syncedCalendar) {
|
|
|
10836
11262
|
tokenExpiry.setSeconds(tokenExpiry.getSeconds() + expiresIn);
|
|
10837
11263
|
const updateData = {
|
|
10838
11264
|
accessToken,
|
|
10839
|
-
tokenExpiry:
|
|
11265
|
+
tokenExpiry: Timestamp27.fromDate(tokenExpiry)
|
|
10840
11266
|
};
|
|
10841
11267
|
switch (entityType) {
|
|
10842
11268
|
case "practitioner":
|
|
@@ -11011,8 +11437,8 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
|
|
|
11011
11437
|
eventName: googleEvent.summary || "External Event",
|
|
11012
11438
|
eventLocation: googleEvent.location,
|
|
11013
11439
|
eventTime: {
|
|
11014
|
-
start:
|
|
11015
|
-
end:
|
|
11440
|
+
start: Timestamp27.fromDate(start),
|
|
11441
|
+
end: Timestamp27.fromDate(end)
|
|
11016
11442
|
},
|
|
11017
11443
|
description: googleEvent.description || "",
|
|
11018
11444
|
// External events are always set as CONFIRMED - status updates will happen externally
|
|
@@ -11026,7 +11452,7 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
|
|
|
11026
11452
|
{
|
|
11027
11453
|
eventId: googleEvent.id,
|
|
11028
11454
|
syncedCalendarProvider: "google" /* GOOGLE */,
|
|
11029
|
-
syncedAt:
|
|
11455
|
+
syncedAt: Timestamp27.now()
|
|
11030
11456
|
}
|
|
11031
11457
|
]
|
|
11032
11458
|
};
|
|
@@ -11804,7 +12230,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
11804
12230
|
return 0;
|
|
11805
12231
|
}
|
|
11806
12232
|
let importedEventsCount = 0;
|
|
11807
|
-
const currentTime =
|
|
12233
|
+
const currentTime = Timestamp28.now();
|
|
11808
12234
|
for (const calendar of activeCalendars) {
|
|
11809
12235
|
try {
|
|
11810
12236
|
let externalEvents = [];
|
|
@@ -11871,7 +12297,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
11871
12297
|
async createDoctorBlockingEvent(doctorId, eventData) {
|
|
11872
12298
|
try {
|
|
11873
12299
|
const eventId = this.generateId();
|
|
11874
|
-
const eventRef =
|
|
12300
|
+
const eventRef = doc26(
|
|
11875
12301
|
this.db,
|
|
11876
12302
|
PRACTITIONERS_COLLECTION,
|
|
11877
12303
|
doctorId,
|
|
@@ -11881,14 +12307,14 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
11881
12307
|
const newEvent = {
|
|
11882
12308
|
id: eventId,
|
|
11883
12309
|
...eventData,
|
|
11884
|
-
createdAt:
|
|
11885
|
-
updatedAt:
|
|
12310
|
+
createdAt: serverTimestamp22(),
|
|
12311
|
+
updatedAt: serverTimestamp22()
|
|
11886
12312
|
};
|
|
11887
|
-
await
|
|
12313
|
+
await setDoc23(eventRef, newEvent);
|
|
11888
12314
|
return {
|
|
11889
12315
|
...newEvent,
|
|
11890
|
-
createdAt:
|
|
11891
|
-
updatedAt:
|
|
12316
|
+
createdAt: Timestamp28.now(),
|
|
12317
|
+
updatedAt: Timestamp28.now()
|
|
11892
12318
|
};
|
|
11893
12319
|
} catch (error) {
|
|
11894
12320
|
console.error(
|
|
@@ -11906,8 +12332,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
11906
12332
|
*/
|
|
11907
12333
|
async synchronizeExternalCalendars(lookbackDays = 7, lookforwardDays = 30) {
|
|
11908
12334
|
try {
|
|
11909
|
-
const practitionersRef =
|
|
11910
|
-
const practitionersSnapshot = await
|
|
12335
|
+
const practitionersRef = collection25(this.db, PRACTITIONERS_COLLECTION);
|
|
12336
|
+
const practitionersSnapshot = await getDocs25(practitionersRef);
|
|
11911
12337
|
const startDate = /* @__PURE__ */ new Date();
|
|
11912
12338
|
startDate.setDate(startDate.getDate() - lookbackDays);
|
|
11913
12339
|
const endDate = /* @__PURE__ */ new Date();
|
|
@@ -11965,22 +12391,22 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
11965
12391
|
async updateExistingEventsFromExternalCalendars(doctorId, startDate, endDate) {
|
|
11966
12392
|
var _a;
|
|
11967
12393
|
try {
|
|
11968
|
-
const eventsRef =
|
|
12394
|
+
const eventsRef = collection25(
|
|
11969
12395
|
this.db,
|
|
11970
12396
|
PRACTITIONERS_COLLECTION,
|
|
11971
12397
|
doctorId,
|
|
11972
12398
|
CALENDAR_COLLECTION
|
|
11973
12399
|
);
|
|
11974
|
-
const q =
|
|
12400
|
+
const q = query25(
|
|
11975
12401
|
eventsRef,
|
|
11976
|
-
|
|
11977
|
-
|
|
11978
|
-
|
|
11979
|
-
);
|
|
11980
|
-
const eventsSnapshot = await
|
|
11981
|
-
const events = eventsSnapshot.docs.map((
|
|
11982
|
-
id:
|
|
11983
|
-
...
|
|
12402
|
+
where25("syncStatus", "==", "external" /* EXTERNAL */),
|
|
12403
|
+
where25("eventTime.start", ">=", Timestamp28.fromDate(startDate)),
|
|
12404
|
+
where25("eventTime.start", "<=", Timestamp28.fromDate(endDate))
|
|
12405
|
+
);
|
|
12406
|
+
const eventsSnapshot = await getDocs25(q);
|
|
12407
|
+
const events = eventsSnapshot.docs.map((doc35) => ({
|
|
12408
|
+
id: doc35.id,
|
|
12409
|
+
...doc35.data()
|
|
11984
12410
|
}));
|
|
11985
12411
|
const calendars = await this.syncedCalendarsService.getPractitionerSyncedCalendars(
|
|
11986
12412
|
doctorId
|
|
@@ -12084,21 +12510,21 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12084
12510
|
const endTime = new Date(
|
|
12085
12511
|
externalEvent.end.dateTime || externalEvent.end.date
|
|
12086
12512
|
);
|
|
12087
|
-
const eventRef =
|
|
12513
|
+
const eventRef = doc26(
|
|
12088
12514
|
this.db,
|
|
12089
12515
|
PRACTITIONERS_COLLECTION,
|
|
12090
12516
|
doctorId,
|
|
12091
12517
|
CALENDAR_COLLECTION,
|
|
12092
12518
|
eventId
|
|
12093
12519
|
);
|
|
12094
|
-
await
|
|
12520
|
+
await updateDoc25(eventRef, {
|
|
12095
12521
|
eventName: externalEvent.summary || "External Event",
|
|
12096
12522
|
eventTime: {
|
|
12097
|
-
start:
|
|
12098
|
-
end:
|
|
12523
|
+
start: Timestamp28.fromDate(startTime),
|
|
12524
|
+
end: Timestamp28.fromDate(endTime)
|
|
12099
12525
|
},
|
|
12100
12526
|
description: externalEvent.description || "",
|
|
12101
|
-
updatedAt:
|
|
12527
|
+
updatedAt: serverTimestamp22()
|
|
12102
12528
|
});
|
|
12103
12529
|
console.log(`Updated local event ${eventId} from external event`);
|
|
12104
12530
|
} catch (error) {
|
|
@@ -12116,16 +12542,16 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12116
12542
|
*/
|
|
12117
12543
|
async updateEventStatus(doctorId, eventId, status) {
|
|
12118
12544
|
try {
|
|
12119
|
-
const eventRef =
|
|
12545
|
+
const eventRef = doc26(
|
|
12120
12546
|
this.db,
|
|
12121
12547
|
PRACTITIONERS_COLLECTION,
|
|
12122
12548
|
doctorId,
|
|
12123
12549
|
CALENDAR_COLLECTION,
|
|
12124
12550
|
eventId
|
|
12125
12551
|
);
|
|
12126
|
-
await
|
|
12552
|
+
await updateDoc25(eventRef, {
|
|
12127
12553
|
status,
|
|
12128
|
-
updatedAt:
|
|
12554
|
+
updatedAt: serverTimestamp22()
|
|
12129
12555
|
});
|
|
12130
12556
|
console.log(`Updated event ${eventId} status to ${status}`);
|
|
12131
12557
|
} catch (error) {
|
|
@@ -12173,8 +12599,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12173
12599
|
*/
|
|
12174
12600
|
async getPractitionerUpcomingAppointments(doctorId, startDate, endDate, status = "confirmed" /* CONFIRMED */) {
|
|
12175
12601
|
const dateRange = {
|
|
12176
|
-
start:
|
|
12177
|
-
end:
|
|
12602
|
+
start: Timestamp28.fromDate(startDate),
|
|
12603
|
+
end: Timestamp28.fromDate(endDate)
|
|
12178
12604
|
};
|
|
12179
12605
|
const searchParams = {
|
|
12180
12606
|
searchLocation: "practitioner" /* PRACTITIONER */,
|
|
@@ -12196,8 +12622,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12196
12622
|
*/
|
|
12197
12623
|
async getPatientAppointments(patientId, startDate, endDate, status) {
|
|
12198
12624
|
const dateRange = {
|
|
12199
|
-
start:
|
|
12200
|
-
end:
|
|
12625
|
+
start: Timestamp28.fromDate(startDate),
|
|
12626
|
+
end: Timestamp28.fromDate(endDate)
|
|
12201
12627
|
};
|
|
12202
12628
|
const searchParams = {
|
|
12203
12629
|
searchLocation: "patient" /* PATIENT */,
|
|
@@ -12222,8 +12648,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12222
12648
|
*/
|
|
12223
12649
|
async getClinicAppointments(clinicId, startDate, endDate, doctorId, status) {
|
|
12224
12650
|
const dateRange = {
|
|
12225
|
-
start:
|
|
12226
|
-
end:
|
|
12651
|
+
start: Timestamp28.fromDate(startDate),
|
|
12652
|
+
end: Timestamp28.fromDate(endDate)
|
|
12227
12653
|
};
|
|
12228
12654
|
const searchParams = {
|
|
12229
12655
|
searchLocation: "clinic" /* CLINIC */,
|
|
@@ -12282,8 +12708,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12282
12708
|
const startDate = eventTime.start.toDate();
|
|
12283
12709
|
const startTime = startDate;
|
|
12284
12710
|
const endTime = eventTime.end.toDate();
|
|
12285
|
-
const practitionerRef =
|
|
12286
|
-
const practitionerDoc = await
|
|
12711
|
+
const practitionerRef = doc26(this.db, PRACTITIONERS_COLLECTION, doctorId);
|
|
12712
|
+
const practitionerDoc = await getDoc28(practitionerRef);
|
|
12287
12713
|
if (!practitionerDoc.exists()) {
|
|
12288
12714
|
throw new Error(`Doctor with ID ${doctorId} not found`);
|
|
12289
12715
|
}
|
|
@@ -12341,8 +12767,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12341
12767
|
*/
|
|
12342
12768
|
async updateAppointmentStatus(appointmentId, clinicId, status) {
|
|
12343
12769
|
const baseCollectionPath = `${CLINICS_COLLECTION}/${clinicId}/${CALENDAR_COLLECTION}`;
|
|
12344
|
-
const appointmentRef =
|
|
12345
|
-
const appointmentDoc = await
|
|
12770
|
+
const appointmentRef = doc26(this.db, baseCollectionPath, appointmentId);
|
|
12771
|
+
const appointmentDoc = await getDoc28(appointmentRef);
|
|
12346
12772
|
if (!appointmentDoc.exists()) {
|
|
12347
12773
|
throw new Error(`Appointment with ID ${appointmentId} not found`);
|
|
12348
12774
|
}
|
|
@@ -12477,7 +12903,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12477
12903
|
const newSyncEvent = {
|
|
12478
12904
|
eventId: result.eventIds[0],
|
|
12479
12905
|
syncedCalendarProvider: calendar.provider,
|
|
12480
|
-
syncedAt:
|
|
12906
|
+
syncedAt: Timestamp28.now()
|
|
12481
12907
|
};
|
|
12482
12908
|
await this.updateEventWithSyncId(
|
|
12483
12909
|
entityType === "doctor" ? appointment.practitionerProfileId : appointment.patientProfileId,
|
|
@@ -12501,8 +12927,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12501
12927
|
async updateEventWithSyncId(entityId, entityType, eventId, syncEvent) {
|
|
12502
12928
|
try {
|
|
12503
12929
|
const collectionPath = entityType === "doctor" ? `${PRACTITIONERS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}` : `${PATIENTS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
|
|
12504
|
-
const eventRef =
|
|
12505
|
-
const eventDoc = await
|
|
12930
|
+
const eventRef = doc26(this.db, collectionPath, eventId);
|
|
12931
|
+
const eventDoc = await getDoc28(eventRef);
|
|
12506
12932
|
if (eventDoc.exists()) {
|
|
12507
12933
|
const event = eventDoc.data();
|
|
12508
12934
|
const syncIds = [...event.syncedCalendarEventId || []];
|
|
@@ -12514,9 +12940,9 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12514
12940
|
} else {
|
|
12515
12941
|
syncIds.push(syncEvent);
|
|
12516
12942
|
}
|
|
12517
|
-
await
|
|
12943
|
+
await updateDoc25(eventRef, {
|
|
12518
12944
|
syncedCalendarEventId: syncIds,
|
|
12519
|
-
updatedAt:
|
|
12945
|
+
updatedAt: serverTimestamp22()
|
|
12520
12946
|
});
|
|
12521
12947
|
console.log(
|
|
12522
12948
|
`Updated event ${eventId} with sync ID ${syncEvent.eventId}`
|
|
@@ -12540,8 +12966,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12540
12966
|
* @returns Working hours for the clinic
|
|
12541
12967
|
*/
|
|
12542
12968
|
async getClinicWorkingHours(clinicId, date) {
|
|
12543
|
-
const clinicRef =
|
|
12544
|
-
const clinicDoc = await
|
|
12969
|
+
const clinicRef = doc26(this.db, CLINICS_COLLECTION, clinicId);
|
|
12970
|
+
const clinicDoc = await getDoc28(clinicRef);
|
|
12545
12971
|
if (!clinicDoc.exists()) {
|
|
12546
12972
|
throw new Error(`Clinic with ID ${clinicId} not found`);
|
|
12547
12973
|
}
|
|
@@ -12569,8 +12995,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12569
12995
|
* @returns Doctor's schedule
|
|
12570
12996
|
*/
|
|
12571
12997
|
async getDoctorSchedule(doctorId, date) {
|
|
12572
|
-
const practitionerRef =
|
|
12573
|
-
const practitionerDoc = await
|
|
12998
|
+
const practitionerRef = doc26(this.db, PRACTITIONERS_COLLECTION, doctorId);
|
|
12999
|
+
const practitionerDoc = await getDoc28(practitionerRef);
|
|
12574
13000
|
if (!practitionerDoc.exists()) {
|
|
12575
13001
|
throw new Error(`Doctor with ID ${doctorId} not found`);
|
|
12576
13002
|
}
|
|
@@ -12602,19 +13028,19 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12602
13028
|
startOfDay.setHours(0, 0, 0, 0);
|
|
12603
13029
|
const endOfDay = new Date(date);
|
|
12604
13030
|
endOfDay.setHours(23, 59, 59, 999);
|
|
12605
|
-
const appointmentsRef =
|
|
12606
|
-
const q =
|
|
13031
|
+
const appointmentsRef = collection25(this.db, CALENDAR_COLLECTION);
|
|
13032
|
+
const q = query25(
|
|
12607
13033
|
appointmentsRef,
|
|
12608
|
-
|
|
12609
|
-
|
|
12610
|
-
|
|
12611
|
-
|
|
13034
|
+
where25("practitionerProfileId", "==", doctorId),
|
|
13035
|
+
where25("eventTime.start", ">=", Timestamp28.fromDate(startOfDay)),
|
|
13036
|
+
where25("eventTime.start", "<=", Timestamp28.fromDate(endOfDay)),
|
|
13037
|
+
where25("status", "in", [
|
|
12612
13038
|
"confirmed" /* CONFIRMED */,
|
|
12613
13039
|
"pending" /* PENDING */
|
|
12614
13040
|
])
|
|
12615
13041
|
);
|
|
12616
|
-
const querySnapshot = await
|
|
12617
|
-
return querySnapshot.docs.map((
|
|
13042
|
+
const querySnapshot = await getDocs25(q);
|
|
13043
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
12618
13044
|
}
|
|
12619
13045
|
/**
|
|
12620
13046
|
* Calculates available time slots based on working hours, schedule and existing appointments
|
|
@@ -12671,11 +13097,11 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12671
13097
|
var _a;
|
|
12672
13098
|
try {
|
|
12673
13099
|
const [clinicDoc, practitionerDoc, patientDoc, patientSensitiveInfoDoc] = await Promise.all([
|
|
12674
|
-
|
|
12675
|
-
|
|
12676
|
-
|
|
12677
|
-
|
|
12678
|
-
|
|
13100
|
+
getDoc28(doc26(this.db, CLINICS_COLLECTION, clinicId)),
|
|
13101
|
+
getDoc28(doc26(this.db, PRACTITIONERS_COLLECTION, doctorId)),
|
|
13102
|
+
getDoc28(doc26(this.db, PATIENTS_COLLECTION, patientId)),
|
|
13103
|
+
getDoc28(
|
|
13104
|
+
doc26(
|
|
12679
13105
|
this.db,
|
|
12680
13106
|
PATIENTS_COLLECTION,
|
|
12681
13107
|
patientId,
|
|
@@ -12708,7 +13134,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12708
13134
|
fullName: `${sensitiveData.firstName} ${sensitiveData.lastName}`,
|
|
12709
13135
|
email: sensitiveData.email || "",
|
|
12710
13136
|
phone: sensitiveData.phoneNumber || null,
|
|
12711
|
-
dateOfBirth: sensitiveData.dateOfBirth ||
|
|
13137
|
+
dateOfBirth: sensitiveData.dateOfBirth || Timestamp28.now(),
|
|
12712
13138
|
gender: sensitiveData.gender || "other" /* OTHER */
|
|
12713
13139
|
};
|
|
12714
13140
|
} else if (patientDoc.exists()) {
|
|
@@ -12717,7 +13143,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12717
13143
|
fullName: patientDoc.data().displayName,
|
|
12718
13144
|
email: ((_a = patientDoc.data().contactInfo) == null ? void 0 : _a.email) || "",
|
|
12719
13145
|
phone: patientDoc.data().phoneNumber || null,
|
|
12720
|
-
dateOfBirth: patientDoc.data().dateOfBirth ||
|
|
13146
|
+
dateOfBirth: patientDoc.data().dateOfBirth || Timestamp28.now(),
|
|
12721
13147
|
gender: patientDoc.data().gender || "other" /* OTHER */
|
|
12722
13148
|
};
|
|
12723
13149
|
}
|
|
@@ -12740,15 +13166,15 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12740
13166
|
|
|
12741
13167
|
// src/services/reviews/reviews.service.ts
|
|
12742
13168
|
import {
|
|
12743
|
-
collection as
|
|
12744
|
-
doc as
|
|
12745
|
-
getDoc as
|
|
12746
|
-
getDocs as
|
|
12747
|
-
query as
|
|
12748
|
-
where as
|
|
12749
|
-
setDoc as
|
|
12750
|
-
deleteDoc as
|
|
12751
|
-
serverTimestamp as
|
|
13169
|
+
collection as collection26,
|
|
13170
|
+
doc as doc27,
|
|
13171
|
+
getDoc as getDoc29,
|
|
13172
|
+
getDocs as getDocs26,
|
|
13173
|
+
query as query26,
|
|
13174
|
+
where as where26,
|
|
13175
|
+
setDoc as setDoc24,
|
|
13176
|
+
deleteDoc as deleteDoc17,
|
|
13177
|
+
serverTimestamp as serverTimestamp23
|
|
12752
13178
|
} from "firebase/firestore";
|
|
12753
13179
|
|
|
12754
13180
|
// src/types/reviews/index.ts
|
|
@@ -12834,11 +13260,11 @@ var ReviewService = class extends BaseService {
|
|
|
12834
13260
|
updatedAt: now
|
|
12835
13261
|
};
|
|
12836
13262
|
reviewSchema.parse(review);
|
|
12837
|
-
const docRef =
|
|
12838
|
-
await
|
|
13263
|
+
const docRef = doc27(this.db, REVIEWS_COLLECTION, reviewId);
|
|
13264
|
+
await setDoc24(docRef, {
|
|
12839
13265
|
...review,
|
|
12840
|
-
createdAt:
|
|
12841
|
-
updatedAt:
|
|
13266
|
+
createdAt: serverTimestamp23(),
|
|
13267
|
+
updatedAt: serverTimestamp23()
|
|
12842
13268
|
});
|
|
12843
13269
|
return review;
|
|
12844
13270
|
} catch (error) {
|
|
@@ -12854,8 +13280,8 @@ var ReviewService = class extends BaseService {
|
|
|
12854
13280
|
* @returns The review if found, null otherwise
|
|
12855
13281
|
*/
|
|
12856
13282
|
async getReview(reviewId) {
|
|
12857
|
-
const docRef =
|
|
12858
|
-
const docSnap = await
|
|
13283
|
+
const docRef = doc27(this.db, REVIEWS_COLLECTION, reviewId);
|
|
13284
|
+
const docSnap = await getDoc29(docRef);
|
|
12859
13285
|
if (!docSnap.exists()) {
|
|
12860
13286
|
return null;
|
|
12861
13287
|
}
|
|
@@ -12867,12 +13293,12 @@ var ReviewService = class extends BaseService {
|
|
|
12867
13293
|
* @returns Array of reviews for the patient
|
|
12868
13294
|
*/
|
|
12869
13295
|
async getReviewsByPatient(patientId) {
|
|
12870
|
-
const q =
|
|
12871
|
-
|
|
12872
|
-
|
|
13296
|
+
const q = query26(
|
|
13297
|
+
collection26(this.db, REVIEWS_COLLECTION),
|
|
13298
|
+
where26("patientId", "==", patientId)
|
|
12873
13299
|
);
|
|
12874
|
-
const snapshot = await
|
|
12875
|
-
return snapshot.docs.map((
|
|
13300
|
+
const snapshot = await getDocs26(q);
|
|
13301
|
+
return snapshot.docs.map((doc35) => doc35.data());
|
|
12876
13302
|
}
|
|
12877
13303
|
/**
|
|
12878
13304
|
* Gets all reviews for a specific clinic
|
|
@@ -12880,12 +13306,12 @@ var ReviewService = class extends BaseService {
|
|
|
12880
13306
|
* @returns Array of reviews containing clinic reviews
|
|
12881
13307
|
*/
|
|
12882
13308
|
async getReviewsByClinic(clinicId) {
|
|
12883
|
-
const q =
|
|
12884
|
-
|
|
12885
|
-
|
|
13309
|
+
const q = query26(
|
|
13310
|
+
collection26(this.db, REVIEWS_COLLECTION),
|
|
13311
|
+
where26("clinicReview.clinicId", "==", clinicId)
|
|
12886
13312
|
);
|
|
12887
|
-
const snapshot = await
|
|
12888
|
-
return snapshot.docs.map((
|
|
13313
|
+
const snapshot = await getDocs26(q);
|
|
13314
|
+
return snapshot.docs.map((doc35) => doc35.data());
|
|
12889
13315
|
}
|
|
12890
13316
|
/**
|
|
12891
13317
|
* Gets all reviews for a specific practitioner
|
|
@@ -12893,12 +13319,12 @@ var ReviewService = class extends BaseService {
|
|
|
12893
13319
|
* @returns Array of reviews containing practitioner reviews
|
|
12894
13320
|
*/
|
|
12895
13321
|
async getReviewsByPractitioner(practitionerId) {
|
|
12896
|
-
const q =
|
|
12897
|
-
|
|
12898
|
-
|
|
13322
|
+
const q = query26(
|
|
13323
|
+
collection26(this.db, REVIEWS_COLLECTION),
|
|
13324
|
+
where26("practitionerReview.practitionerId", "==", practitionerId)
|
|
12899
13325
|
);
|
|
12900
|
-
const snapshot = await
|
|
12901
|
-
return snapshot.docs.map((
|
|
13326
|
+
const snapshot = await getDocs26(q);
|
|
13327
|
+
return snapshot.docs.map((doc35) => doc35.data());
|
|
12902
13328
|
}
|
|
12903
13329
|
/**
|
|
12904
13330
|
* Gets all reviews for a specific procedure
|
|
@@ -12906,12 +13332,12 @@ var ReviewService = class extends BaseService {
|
|
|
12906
13332
|
* @returns Array of reviews containing procedure reviews
|
|
12907
13333
|
*/
|
|
12908
13334
|
async getReviewsByProcedure(procedureId) {
|
|
12909
|
-
const q =
|
|
12910
|
-
|
|
12911
|
-
|
|
13335
|
+
const q = query26(
|
|
13336
|
+
collection26(this.db, REVIEWS_COLLECTION),
|
|
13337
|
+
where26("procedureReview.procedureId", "==", procedureId)
|
|
12912
13338
|
);
|
|
12913
|
-
const snapshot = await
|
|
12914
|
-
return snapshot.docs.map((
|
|
13339
|
+
const snapshot = await getDocs26(q);
|
|
13340
|
+
return snapshot.docs.map((doc35) => doc35.data());
|
|
12915
13341
|
}
|
|
12916
13342
|
/**
|
|
12917
13343
|
* Gets all reviews for a specific appointment
|
|
@@ -12919,11 +13345,11 @@ var ReviewService = class extends BaseService {
|
|
|
12919
13345
|
* @returns The review for the appointment if found, null otherwise
|
|
12920
13346
|
*/
|
|
12921
13347
|
async getReviewByAppointment(appointmentId) {
|
|
12922
|
-
const q =
|
|
12923
|
-
|
|
12924
|
-
|
|
13348
|
+
const q = query26(
|
|
13349
|
+
collection26(this.db, REVIEWS_COLLECTION),
|
|
13350
|
+
where26("appointmentId", "==", appointmentId)
|
|
12925
13351
|
);
|
|
12926
|
-
const snapshot = await
|
|
13352
|
+
const snapshot = await getDocs26(q);
|
|
12927
13353
|
if (snapshot.empty) {
|
|
12928
13354
|
return null;
|
|
12929
13355
|
}
|
|
@@ -12938,7 +13364,7 @@ var ReviewService = class extends BaseService {
|
|
|
12938
13364
|
if (!review) {
|
|
12939
13365
|
throw new Error(`Review with ID ${reviewId} not found`);
|
|
12940
13366
|
}
|
|
12941
|
-
await
|
|
13367
|
+
await deleteDoc17(doc27(this.db, REVIEWS_COLLECTION, reviewId));
|
|
12942
13368
|
}
|
|
12943
13369
|
/**
|
|
12944
13370
|
* Calculates the average of an array of numbers
|
|
@@ -12957,34 +13383,34 @@ var ReviewService = class extends BaseService {
|
|
|
12957
13383
|
|
|
12958
13384
|
// src/services/appointment/appointment.service.ts
|
|
12959
13385
|
import {
|
|
12960
|
-
Timestamp as
|
|
12961
|
-
serverTimestamp as
|
|
13386
|
+
Timestamp as Timestamp30,
|
|
13387
|
+
serverTimestamp as serverTimestamp25,
|
|
12962
13388
|
arrayUnion as arrayUnion8,
|
|
12963
13389
|
arrayRemove as arrayRemove7,
|
|
12964
|
-
where as
|
|
12965
|
-
orderBy as
|
|
12966
|
-
collection as
|
|
12967
|
-
query as
|
|
12968
|
-
limit as
|
|
13390
|
+
where as where28,
|
|
13391
|
+
orderBy as orderBy15,
|
|
13392
|
+
collection as collection28,
|
|
13393
|
+
query as query28,
|
|
13394
|
+
limit as limit13,
|
|
12969
13395
|
startAfter as startAfter11,
|
|
12970
|
-
getDocs as
|
|
13396
|
+
getDocs as getDocs28
|
|
12971
13397
|
} from "firebase/firestore";
|
|
12972
13398
|
import { getFunctions as getFunctions2 } from "firebase/functions";
|
|
12973
13399
|
|
|
12974
13400
|
// src/services/appointment/utils/appointment.utils.ts
|
|
12975
13401
|
import {
|
|
12976
|
-
collection as
|
|
12977
|
-
doc as
|
|
12978
|
-
getDoc as
|
|
12979
|
-
getDocs as
|
|
12980
|
-
query as
|
|
12981
|
-
where as
|
|
12982
|
-
setDoc as
|
|
12983
|
-
updateDoc as
|
|
12984
|
-
serverTimestamp as
|
|
12985
|
-
Timestamp as
|
|
12986
|
-
orderBy as
|
|
12987
|
-
limit as
|
|
13402
|
+
collection as collection27,
|
|
13403
|
+
doc as doc28,
|
|
13404
|
+
getDoc as getDoc30,
|
|
13405
|
+
getDocs as getDocs27,
|
|
13406
|
+
query as query27,
|
|
13407
|
+
where as where27,
|
|
13408
|
+
setDoc as setDoc25,
|
|
13409
|
+
updateDoc as updateDoc26,
|
|
13410
|
+
serverTimestamp as serverTimestamp24,
|
|
13411
|
+
Timestamp as Timestamp29,
|
|
13412
|
+
orderBy as orderBy14,
|
|
13413
|
+
limit as limit12,
|
|
12988
13414
|
startAfter as startAfter10
|
|
12989
13415
|
} from "firebase/firestore";
|
|
12990
13416
|
|
|
@@ -12994,8 +13420,8 @@ var TECHNOLOGIES_COLLECTION = "technologies";
|
|
|
12994
13420
|
// src/services/appointment/utils/appointment.utils.ts
|
|
12995
13421
|
async function updateAppointmentUtil2(db, appointmentId, data) {
|
|
12996
13422
|
try {
|
|
12997
|
-
const appointmentRef =
|
|
12998
|
-
const appointmentDoc = await
|
|
13423
|
+
const appointmentRef = doc28(db, APPOINTMENTS_COLLECTION, appointmentId);
|
|
13424
|
+
const appointmentDoc = await getDoc30(appointmentRef);
|
|
12999
13425
|
if (!appointmentDoc.exists()) {
|
|
13000
13426
|
throw new Error(`Appointment with ID ${appointmentId} not found`);
|
|
13001
13427
|
}
|
|
@@ -13044,7 +13470,7 @@ async function updateAppointmentUtil2(db, appointmentId, data) {
|
|
|
13044
13470
|
...data,
|
|
13045
13471
|
completedPreRequirements,
|
|
13046
13472
|
completedPostRequirements,
|
|
13047
|
-
updatedAt:
|
|
13473
|
+
updatedAt: serverTimestamp24()
|
|
13048
13474
|
};
|
|
13049
13475
|
Object.keys(updateData).forEach((key) => {
|
|
13050
13476
|
if (updateData[key] === void 0) {
|
|
@@ -13053,7 +13479,7 @@ async function updateAppointmentUtil2(db, appointmentId, data) {
|
|
|
13053
13479
|
});
|
|
13054
13480
|
if (data.status && data.status !== currentAppointment.status) {
|
|
13055
13481
|
if (data.status === "confirmed" /* CONFIRMED */ && !updateData.confirmationTime) {
|
|
13056
|
-
updateData.confirmationTime =
|
|
13482
|
+
updateData.confirmationTime = Timestamp29.now();
|
|
13057
13483
|
}
|
|
13058
13484
|
if (currentAppointment.calendarEventId) {
|
|
13059
13485
|
await updateCalendarEventStatus(
|
|
@@ -13063,8 +13489,8 @@ async function updateAppointmentUtil2(db, appointmentId, data) {
|
|
|
13063
13489
|
);
|
|
13064
13490
|
}
|
|
13065
13491
|
}
|
|
13066
|
-
await
|
|
13067
|
-
const updatedAppointmentDoc = await
|
|
13492
|
+
await updateDoc26(appointmentRef, updateData);
|
|
13493
|
+
const updatedAppointmentDoc = await getDoc30(appointmentRef);
|
|
13068
13494
|
if (!updatedAppointmentDoc.exists()) {
|
|
13069
13495
|
throw new Error(
|
|
13070
13496
|
`Failed to retrieve updated appointment ${appointmentId}`
|
|
@@ -13078,8 +13504,8 @@ async function updateAppointmentUtil2(db, appointmentId, data) {
|
|
|
13078
13504
|
}
|
|
13079
13505
|
async function updateCalendarEventStatus(db, calendarEventId, appointmentStatus) {
|
|
13080
13506
|
try {
|
|
13081
|
-
const calendarEventRef =
|
|
13082
|
-
const calendarEventDoc = await
|
|
13507
|
+
const calendarEventRef = doc28(db, CALENDAR_COLLECTION, calendarEventId);
|
|
13508
|
+
const calendarEventDoc = await getDoc30(calendarEventRef);
|
|
13083
13509
|
if (!calendarEventDoc.exists()) {
|
|
13084
13510
|
console.warn(`Calendar event with ID ${calendarEventId} not found`);
|
|
13085
13511
|
return;
|
|
@@ -13102,9 +13528,9 @@ async function updateCalendarEventStatus(db, calendarEventId, appointmentStatus)
|
|
|
13102
13528
|
default:
|
|
13103
13529
|
return;
|
|
13104
13530
|
}
|
|
13105
|
-
await
|
|
13531
|
+
await updateDoc26(calendarEventRef, {
|
|
13106
13532
|
status: calendarStatus,
|
|
13107
|
-
updatedAt:
|
|
13533
|
+
updatedAt: serverTimestamp24()
|
|
13108
13534
|
});
|
|
13109
13535
|
} catch (error) {
|
|
13110
13536
|
console.error(`Error updating calendar event ${calendarEventId}:`, error);
|
|
@@ -13112,8 +13538,8 @@ async function updateCalendarEventStatus(db, calendarEventId, appointmentStatus)
|
|
|
13112
13538
|
}
|
|
13113
13539
|
async function getAppointmentByIdUtil(db, appointmentId) {
|
|
13114
13540
|
try {
|
|
13115
|
-
const appointmentDoc = await
|
|
13116
|
-
|
|
13541
|
+
const appointmentDoc = await getDoc30(
|
|
13542
|
+
doc28(db, APPOINTMENTS_COLLECTION, appointmentId)
|
|
13117
13543
|
);
|
|
13118
13544
|
if (!appointmentDoc.exists()) {
|
|
13119
13545
|
return null;
|
|
@@ -13128,46 +13554,46 @@ async function searchAppointmentsUtil(db, params) {
|
|
|
13128
13554
|
try {
|
|
13129
13555
|
const constraints = [];
|
|
13130
13556
|
if (params.patientId) {
|
|
13131
|
-
constraints.push(
|
|
13557
|
+
constraints.push(where27("patientId", "==", params.patientId));
|
|
13132
13558
|
}
|
|
13133
13559
|
if (params.practitionerId) {
|
|
13134
|
-
constraints.push(
|
|
13560
|
+
constraints.push(where27("practitionerId", "==", params.practitionerId));
|
|
13135
13561
|
}
|
|
13136
13562
|
if (params.clinicBranchId) {
|
|
13137
|
-
constraints.push(
|
|
13563
|
+
constraints.push(where27("clinicBranchId", "==", params.clinicBranchId));
|
|
13138
13564
|
}
|
|
13139
13565
|
if (params.startDate) {
|
|
13140
13566
|
constraints.push(
|
|
13141
|
-
|
|
13567
|
+
where27(
|
|
13142
13568
|
"appointmentStartTime",
|
|
13143
13569
|
">=",
|
|
13144
|
-
|
|
13570
|
+
Timestamp29.fromDate(params.startDate)
|
|
13145
13571
|
)
|
|
13146
13572
|
);
|
|
13147
13573
|
}
|
|
13148
13574
|
if (params.endDate) {
|
|
13149
13575
|
constraints.push(
|
|
13150
|
-
|
|
13576
|
+
where27("appointmentStartTime", "<=", Timestamp29.fromDate(params.endDate))
|
|
13151
13577
|
);
|
|
13152
13578
|
}
|
|
13153
13579
|
if (params.status) {
|
|
13154
13580
|
if (Array.isArray(params.status)) {
|
|
13155
|
-
constraints.push(
|
|
13581
|
+
constraints.push(where27("status", "in", params.status));
|
|
13156
13582
|
} else {
|
|
13157
|
-
constraints.push(
|
|
13583
|
+
constraints.push(where27("status", "==", params.status));
|
|
13158
13584
|
}
|
|
13159
13585
|
}
|
|
13160
|
-
constraints.push(
|
|
13586
|
+
constraints.push(orderBy14("appointmentStartTime", "asc"));
|
|
13161
13587
|
if (params.limit) {
|
|
13162
|
-
constraints.push(
|
|
13588
|
+
constraints.push(limit12(params.limit));
|
|
13163
13589
|
}
|
|
13164
13590
|
if (params.startAfter) {
|
|
13165
13591
|
constraints.push(startAfter10(params.startAfter));
|
|
13166
13592
|
}
|
|
13167
|
-
const q =
|
|
13168
|
-
const querySnapshot = await
|
|
13593
|
+
const q = query27(collection27(db, APPOINTMENTS_COLLECTION), ...constraints);
|
|
13594
|
+
const querySnapshot = await getDocs27(q);
|
|
13169
13595
|
const appointments = querySnapshot.docs.map(
|
|
13170
|
-
(
|
|
13596
|
+
(doc35) => doc35.data()
|
|
13171
13597
|
);
|
|
13172
13598
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
13173
13599
|
return { appointments, lastDoc };
|
|
@@ -13536,7 +13962,7 @@ var AppointmentService = class extends BaseService {
|
|
|
13536
13962
|
);
|
|
13537
13963
|
const updateData = {
|
|
13538
13964
|
status: newStatus,
|
|
13539
|
-
updatedAt:
|
|
13965
|
+
updatedAt: serverTimestamp25()
|
|
13540
13966
|
};
|
|
13541
13967
|
if (newStatus === "canceled_clinic" /* CANCELED_CLINIC */ || newStatus === "canceled_patient" /* CANCELED_PATIENT */ || newStatus === "canceled_patient_rescheduled" /* CANCELED_PATIENT_RESCHEDULED */) {
|
|
13542
13968
|
if (!(details == null ? void 0 : details.cancellationReason)) {
|
|
@@ -13547,13 +13973,13 @@ var AppointmentService = class extends BaseService {
|
|
|
13547
13973
|
}
|
|
13548
13974
|
updateData.cancellationReason = details.cancellationReason;
|
|
13549
13975
|
updateData.canceledBy = details.canceledBy;
|
|
13550
|
-
updateData.cancellationTime =
|
|
13976
|
+
updateData.cancellationTime = Timestamp30.now();
|
|
13551
13977
|
}
|
|
13552
13978
|
if (newStatus === "confirmed" /* CONFIRMED */) {
|
|
13553
|
-
updateData.confirmationTime =
|
|
13979
|
+
updateData.confirmationTime = Timestamp30.now();
|
|
13554
13980
|
}
|
|
13555
13981
|
if (newStatus === "rescheduled_by_clinic" /* RESCHEDULED_BY_CLINIC */) {
|
|
13556
|
-
updateData.rescheduleTime =
|
|
13982
|
+
updateData.rescheduleTime = Timestamp30.now();
|
|
13557
13983
|
}
|
|
13558
13984
|
return this.updateAppointment(appointmentId, updateData);
|
|
13559
13985
|
}
|
|
@@ -13613,22 +14039,63 @@ var AppointmentService = class extends BaseService {
|
|
|
13613
14039
|
* Admin proposes to reschedule an appointment.
|
|
13614
14040
|
* Sets status to RESCHEDULED_BY_CLINIC and updates times.
|
|
13615
14041
|
*/
|
|
13616
|
-
async rescheduleAppointmentAdmin(
|
|
14042
|
+
async rescheduleAppointmentAdmin(params) {
|
|
13617
14043
|
console.log(
|
|
13618
|
-
`[APPOINTMENT_SERVICE] Admin rescheduling appointment: ${appointmentId}`
|
|
14044
|
+
`[APPOINTMENT_SERVICE] Admin rescheduling appointment: ${params.appointmentId}`
|
|
14045
|
+
);
|
|
14046
|
+
const validatedParams = await rescheduleAppointmentSchema.parseAsync(
|
|
14047
|
+
params
|
|
13619
14048
|
);
|
|
13620
|
-
|
|
14049
|
+
const startTimestamp = this.convertToTimestamp(
|
|
14050
|
+
validatedParams.newStartTime
|
|
14051
|
+
);
|
|
14052
|
+
const endTimestamp = this.convertToTimestamp(validatedParams.newEndTime);
|
|
14053
|
+
if (endTimestamp.toMillis() <= startTimestamp.toMillis()) {
|
|
13621
14054
|
throw new Error("New end time must be after new start time.");
|
|
13622
14055
|
}
|
|
13623
14056
|
const updateData = {
|
|
13624
14057
|
status: "rescheduled_by_clinic" /* RESCHEDULED_BY_CLINIC */,
|
|
13625
|
-
appointmentStartTime:
|
|
13626
|
-
appointmentEndTime:
|
|
13627
|
-
rescheduleTime:
|
|
14058
|
+
appointmentStartTime: startTimestamp,
|
|
14059
|
+
appointmentEndTime: endTimestamp,
|
|
14060
|
+
rescheduleTime: Timestamp30.now(),
|
|
13628
14061
|
confirmationTime: null,
|
|
13629
|
-
updatedAt:
|
|
14062
|
+
updatedAt: serverTimestamp25()
|
|
13630
14063
|
};
|
|
13631
|
-
return this.updateAppointment(appointmentId, updateData);
|
|
14064
|
+
return this.updateAppointment(validatedParams.appointmentId, updateData);
|
|
14065
|
+
}
|
|
14066
|
+
/**
|
|
14067
|
+
* Helper method to convert various timestamp formats to Firestore Timestamp
|
|
14068
|
+
* @param value - Any timestamp format (Timestamp, number, string, Date, serialized Timestamp)
|
|
14069
|
+
* @returns Firestore Timestamp object
|
|
14070
|
+
*/
|
|
14071
|
+
convertToTimestamp(value) {
|
|
14072
|
+
console.log(`[APPOINTMENT_SERVICE] Converting timestamp:`, {
|
|
14073
|
+
value,
|
|
14074
|
+
type: typeof value
|
|
14075
|
+
});
|
|
14076
|
+
if (value && typeof value.toMillis === "function") {
|
|
14077
|
+
return value;
|
|
14078
|
+
}
|
|
14079
|
+
if (typeof value === "number") {
|
|
14080
|
+
return Timestamp30.fromMillis(value);
|
|
14081
|
+
}
|
|
14082
|
+
if (typeof value === "string") {
|
|
14083
|
+
return Timestamp30.fromDate(new Date(value));
|
|
14084
|
+
}
|
|
14085
|
+
if (value instanceof Date) {
|
|
14086
|
+
return Timestamp30.fromDate(value);
|
|
14087
|
+
}
|
|
14088
|
+
if (value && typeof value._seconds === "number") {
|
|
14089
|
+
return new Timestamp30(value._seconds, value._nanoseconds || 0);
|
|
14090
|
+
}
|
|
14091
|
+
if (value && typeof value.seconds === "number") {
|
|
14092
|
+
return new Timestamp30(value.seconds, value.nanoseconds || 0);
|
|
14093
|
+
}
|
|
14094
|
+
throw new Error(
|
|
14095
|
+
`Invalid timestamp format: ${typeof value}, value: ${JSON.stringify(
|
|
14096
|
+
value
|
|
14097
|
+
)}`
|
|
14098
|
+
);
|
|
13632
14099
|
}
|
|
13633
14100
|
/**
|
|
13634
14101
|
* User confirms a reschedule proposed by the clinic.
|
|
@@ -13721,9 +14188,9 @@ var AppointmentService = class extends BaseService {
|
|
|
13721
14188
|
}
|
|
13722
14189
|
const updateData = {
|
|
13723
14190
|
status: "in_progress" /* IN_PROGRESS */,
|
|
13724
|
-
procedureActualStartTime:
|
|
14191
|
+
procedureActualStartTime: Timestamp30.now(),
|
|
13725
14192
|
// Set actual start time
|
|
13726
|
-
updatedAt:
|
|
14193
|
+
updatedAt: serverTimestamp25()
|
|
13727
14194
|
};
|
|
13728
14195
|
return this.updateAppointment(appointmentId, updateData);
|
|
13729
14196
|
}
|
|
@@ -13741,7 +14208,7 @@ var AppointmentService = class extends BaseService {
|
|
|
13741
14208
|
if (!appointment)
|
|
13742
14209
|
throw new Error(`Appointment ${appointmentId} not found.`);
|
|
13743
14210
|
let calculatedDurationMinutes = actualDurationMinutesInput;
|
|
13744
|
-
const procedureCompletionTime =
|
|
14211
|
+
const procedureCompletionTime = Timestamp30.now();
|
|
13745
14212
|
if (calculatedDurationMinutes === void 0 && appointment.procedureActualStartTime) {
|
|
13746
14213
|
const startTimeMillis = appointment.procedureActualStartTime.toMillis();
|
|
13747
14214
|
const endTimeMillis = procedureCompletionTime.toMillis();
|
|
@@ -13764,7 +14231,7 @@ var AppointmentService = class extends BaseService {
|
|
|
13764
14231
|
},
|
|
13765
14232
|
// Optionally update appointmentEndTime to the actual completion time
|
|
13766
14233
|
// appointmentEndTime: procedureCompletionTime,
|
|
13767
|
-
updatedAt:
|
|
14234
|
+
updatedAt: serverTimestamp25()
|
|
13768
14235
|
};
|
|
13769
14236
|
return this.updateAppointment(appointmentId, updateData);
|
|
13770
14237
|
}
|
|
@@ -13778,7 +14245,7 @@ var AppointmentService = class extends BaseService {
|
|
|
13778
14245
|
const appointment = await this.getAppointmentById(appointmentId);
|
|
13779
14246
|
if (!appointment)
|
|
13780
14247
|
throw new Error(`Appointment ${appointmentId} not found.`);
|
|
13781
|
-
if (
|
|
14248
|
+
if (Timestamp30.now().toMillis() < appointment.appointmentStartTime.toMillis()) {
|
|
13782
14249
|
throw new Error("Cannot mark no-show before appointment start time.");
|
|
13783
14250
|
}
|
|
13784
14251
|
return this.updateAppointmentStatus(
|
|
@@ -13802,12 +14269,12 @@ var AppointmentService = class extends BaseService {
|
|
|
13802
14269
|
const newMediaItem = {
|
|
13803
14270
|
...mediaItemData,
|
|
13804
14271
|
id: this.generateId(),
|
|
13805
|
-
uploadedAt:
|
|
14272
|
+
uploadedAt: Timestamp30.now(),
|
|
13806
14273
|
uploadedBy: currentUser.uid
|
|
13807
14274
|
};
|
|
13808
14275
|
const updateData = {
|
|
13809
14276
|
media: arrayUnion8(newMediaItem),
|
|
13810
|
-
updatedAt:
|
|
14277
|
+
updatedAt: serverTimestamp25()
|
|
13811
14278
|
};
|
|
13812
14279
|
return this.updateAppointment(appointmentId, updateData);
|
|
13813
14280
|
}
|
|
@@ -13828,7 +14295,7 @@ var AppointmentService = class extends BaseService {
|
|
|
13828
14295
|
}
|
|
13829
14296
|
const updateData = {
|
|
13830
14297
|
media: arrayRemove7(mediaToRemove),
|
|
13831
|
-
updatedAt:
|
|
14298
|
+
updatedAt: serverTimestamp25()
|
|
13832
14299
|
};
|
|
13833
14300
|
return this.updateAppointment(appointmentId, updateData);
|
|
13834
14301
|
}
|
|
@@ -13842,11 +14309,11 @@ var AppointmentService = class extends BaseService {
|
|
|
13842
14309
|
const newReviewInfo = {
|
|
13843
14310
|
...reviewData,
|
|
13844
14311
|
reviewId: this.generateId(),
|
|
13845
|
-
reviewedAt:
|
|
14312
|
+
reviewedAt: Timestamp30.now()
|
|
13846
14313
|
};
|
|
13847
14314
|
const updateData = {
|
|
13848
14315
|
reviewInfo: newReviewInfo,
|
|
13849
|
-
updatedAt:
|
|
14316
|
+
updatedAt: serverTimestamp25()
|
|
13850
14317
|
};
|
|
13851
14318
|
return this.updateAppointment(appointmentId, updateData);
|
|
13852
14319
|
}
|
|
@@ -13860,7 +14327,7 @@ var AppointmentService = class extends BaseService {
|
|
|
13860
14327
|
const updateData = {
|
|
13861
14328
|
paymentStatus,
|
|
13862
14329
|
paymentTransactionId: paymentTransactionId || null,
|
|
13863
|
-
updatedAt:
|
|
14330
|
+
updatedAt: serverTimestamp25()
|
|
13864
14331
|
};
|
|
13865
14332
|
return this.updateAppointment(appointmentId, updateData);
|
|
13866
14333
|
}
|
|
@@ -13902,38 +14369,38 @@ var AppointmentService = class extends BaseService {
|
|
|
13902
14369
|
"rescheduled_by_clinic" /* RESCHEDULED_BY_CLINIC */
|
|
13903
14370
|
];
|
|
13904
14371
|
const constraints = [];
|
|
13905
|
-
constraints.push(
|
|
13906
|
-
constraints.push(
|
|
14372
|
+
constraints.push(where28("patientId", "==", patientId));
|
|
14373
|
+
constraints.push(where28("status", "in", upcomingStatuses));
|
|
13907
14374
|
constraints.push(
|
|
13908
|
-
|
|
14375
|
+
where28(
|
|
13909
14376
|
"appointmentStartTime",
|
|
13910
14377
|
">=",
|
|
13911
|
-
|
|
14378
|
+
Timestamp30.fromDate(effectiveStartDate)
|
|
13912
14379
|
)
|
|
13913
14380
|
);
|
|
13914
14381
|
if (options == null ? void 0 : options.endDate) {
|
|
13915
14382
|
constraints.push(
|
|
13916
|
-
|
|
14383
|
+
where28(
|
|
13917
14384
|
"appointmentStartTime",
|
|
13918
14385
|
"<=",
|
|
13919
|
-
|
|
14386
|
+
Timestamp30.fromDate(options.endDate)
|
|
13920
14387
|
)
|
|
13921
14388
|
);
|
|
13922
14389
|
}
|
|
13923
|
-
constraints.push(
|
|
14390
|
+
constraints.push(orderBy15("appointmentStartTime", "asc"));
|
|
13924
14391
|
if (options == null ? void 0 : options.limit) {
|
|
13925
|
-
constraints.push(
|
|
14392
|
+
constraints.push(limit13(options.limit));
|
|
13926
14393
|
}
|
|
13927
14394
|
if (options == null ? void 0 : options.startAfter) {
|
|
13928
14395
|
constraints.push(startAfter11(options.startAfter));
|
|
13929
14396
|
}
|
|
13930
|
-
const q =
|
|
13931
|
-
|
|
14397
|
+
const q = query28(
|
|
14398
|
+
collection28(this.db, APPOINTMENTS_COLLECTION),
|
|
13932
14399
|
...constraints
|
|
13933
14400
|
);
|
|
13934
|
-
const querySnapshot = await
|
|
14401
|
+
const querySnapshot = await getDocs28(q);
|
|
13935
14402
|
const appointments = querySnapshot.docs.map(
|
|
13936
|
-
(
|
|
14403
|
+
(doc35) => doc35.data()
|
|
13937
14404
|
);
|
|
13938
14405
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
13939
14406
|
console.log(
|
|
@@ -13975,38 +14442,38 @@ var AppointmentService = class extends BaseService {
|
|
|
13975
14442
|
pastStatuses.push("no_show" /* NO_SHOW */);
|
|
13976
14443
|
}
|
|
13977
14444
|
const constraints = [];
|
|
13978
|
-
constraints.push(
|
|
13979
|
-
constraints.push(
|
|
14445
|
+
constraints.push(where28("patientId", "==", patientId));
|
|
14446
|
+
constraints.push(where28("status", "in", pastStatuses));
|
|
13980
14447
|
if (options == null ? void 0 : options.startDate) {
|
|
13981
14448
|
constraints.push(
|
|
13982
|
-
|
|
14449
|
+
where28(
|
|
13983
14450
|
"appointmentStartTime",
|
|
13984
14451
|
">=",
|
|
13985
|
-
|
|
14452
|
+
Timestamp30.fromDate(options.startDate)
|
|
13986
14453
|
)
|
|
13987
14454
|
);
|
|
13988
14455
|
}
|
|
13989
14456
|
constraints.push(
|
|
13990
|
-
|
|
14457
|
+
where28(
|
|
13991
14458
|
"appointmentStartTime",
|
|
13992
14459
|
"<=",
|
|
13993
|
-
|
|
14460
|
+
Timestamp30.fromDate(effectiveEndDate)
|
|
13994
14461
|
)
|
|
13995
14462
|
);
|
|
13996
|
-
constraints.push(
|
|
14463
|
+
constraints.push(orderBy15("appointmentStartTime", "desc"));
|
|
13997
14464
|
if (options == null ? void 0 : options.limit) {
|
|
13998
|
-
constraints.push(
|
|
14465
|
+
constraints.push(limit13(options.limit));
|
|
13999
14466
|
}
|
|
14000
14467
|
if (options == null ? void 0 : options.startAfter) {
|
|
14001
14468
|
constraints.push(startAfter11(options.startAfter));
|
|
14002
14469
|
}
|
|
14003
|
-
const q =
|
|
14004
|
-
|
|
14470
|
+
const q = query28(
|
|
14471
|
+
collection28(this.db, APPOINTMENTS_COLLECTION),
|
|
14005
14472
|
...constraints
|
|
14006
14473
|
);
|
|
14007
|
-
const querySnapshot = await
|
|
14474
|
+
const querySnapshot = await getDocs28(q);
|
|
14008
14475
|
const appointments = querySnapshot.docs.map(
|
|
14009
|
-
(
|
|
14476
|
+
(doc35) => doc35.data()
|
|
14010
14477
|
);
|
|
14011
14478
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
14012
14479
|
console.log(
|
|
@@ -14025,17 +14492,17 @@ var AppointmentService = class extends BaseService {
|
|
|
14025
14492
|
|
|
14026
14493
|
// src/services/patient/patientRequirements.service.ts
|
|
14027
14494
|
import {
|
|
14028
|
-
collection as
|
|
14029
|
-
getDocs as
|
|
14030
|
-
query as
|
|
14031
|
-
where as
|
|
14032
|
-
doc as
|
|
14033
|
-
updateDoc as
|
|
14034
|
-
Timestamp as
|
|
14035
|
-
orderBy as
|
|
14036
|
-
limit as
|
|
14495
|
+
collection as collection29,
|
|
14496
|
+
getDocs as getDocs29,
|
|
14497
|
+
query as query29,
|
|
14498
|
+
where as where29,
|
|
14499
|
+
doc as doc29,
|
|
14500
|
+
updateDoc as updateDoc27,
|
|
14501
|
+
Timestamp as Timestamp31,
|
|
14502
|
+
orderBy as orderBy16,
|
|
14503
|
+
limit as limit14,
|
|
14037
14504
|
startAfter as startAfter12,
|
|
14038
|
-
getDoc as
|
|
14505
|
+
getDoc as getDoc31
|
|
14039
14506
|
} from "firebase/firestore";
|
|
14040
14507
|
|
|
14041
14508
|
// src/types/patient/patient-requirements.ts
|
|
@@ -14066,13 +14533,13 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
14066
14533
|
super(db, auth, app);
|
|
14067
14534
|
}
|
|
14068
14535
|
getPatientRequirementsCollectionRef(patientId) {
|
|
14069
|
-
return
|
|
14536
|
+
return collection29(
|
|
14070
14537
|
this.db,
|
|
14071
14538
|
`patients/${patientId}/${PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME}`
|
|
14072
14539
|
);
|
|
14073
14540
|
}
|
|
14074
14541
|
getPatientRequirementDocRef(patientId, instanceId) {
|
|
14075
|
-
return
|
|
14542
|
+
return doc29(
|
|
14076
14543
|
this.getPatientRequirementsCollectionRef(patientId),
|
|
14077
14544
|
instanceId
|
|
14078
14545
|
);
|
|
@@ -14085,7 +14552,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
14085
14552
|
*/
|
|
14086
14553
|
async getPatientRequirementInstance(patientId, instanceId) {
|
|
14087
14554
|
const docRef = this.getPatientRequirementDocRef(patientId, instanceId);
|
|
14088
|
-
const docSnap = await
|
|
14555
|
+
const docSnap = await getDoc31(docRef);
|
|
14089
14556
|
if (!docSnap.exists()) {
|
|
14090
14557
|
return null;
|
|
14091
14558
|
}
|
|
@@ -14104,22 +14571,22 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
14104
14571
|
*/
|
|
14105
14572
|
async getAllPatientRequirementInstances(patientId, filters, pageLimit = 20, lastVisible) {
|
|
14106
14573
|
const collRef = this.getPatientRequirementsCollectionRef(patientId);
|
|
14107
|
-
let q =
|
|
14574
|
+
let q = query29(collRef, orderBy16("createdAt", "desc"));
|
|
14108
14575
|
const queryConstraints = [];
|
|
14109
14576
|
if ((filters == null ? void 0 : filters.appointmentId) && filters.appointmentId !== "all") {
|
|
14110
14577
|
queryConstraints.push(
|
|
14111
|
-
|
|
14578
|
+
where29("appointmentId", "==", filters.appointmentId)
|
|
14112
14579
|
);
|
|
14113
14580
|
}
|
|
14114
14581
|
if ((filters == null ? void 0 : filters.statuses) && filters.statuses.length > 0) {
|
|
14115
|
-
queryConstraints.push(
|
|
14582
|
+
queryConstraints.push(where29("overallStatus", "in", filters.statuses));
|
|
14116
14583
|
}
|
|
14117
14584
|
if (lastVisible) {
|
|
14118
14585
|
queryConstraints.push(startAfter12(lastVisible));
|
|
14119
14586
|
}
|
|
14120
|
-
queryConstraints.push(
|
|
14121
|
-
q =
|
|
14122
|
-
const snapshot = await
|
|
14587
|
+
queryConstraints.push(limit14(pageLimit));
|
|
14588
|
+
q = query29(collRef, ...queryConstraints);
|
|
14589
|
+
const snapshot = await getDocs29(q);
|
|
14123
14590
|
let requirements = snapshot.docs.map((docSnap) => {
|
|
14124
14591
|
const data = docSnap.data();
|
|
14125
14592
|
return { id: docSnap.id, ...data };
|
|
@@ -14162,7 +14629,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
14162
14629
|
*/
|
|
14163
14630
|
async completeInstruction(patientId, instanceId, instructionId) {
|
|
14164
14631
|
const instanceRef = this.getPatientRequirementDocRef(patientId, instanceId);
|
|
14165
|
-
const instanceSnap = await
|
|
14632
|
+
const instanceSnap = await getDoc31(instanceRef);
|
|
14166
14633
|
if (!instanceSnap.exists()) {
|
|
14167
14634
|
throw new Error(
|
|
14168
14635
|
`PatientRequirementInstance ${instanceId} not found for patient ${patientId}.`
|
|
@@ -14190,7 +14657,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
14190
14657
|
`Instruction ${instructionId} is in status ${instructionToUpdate.status} and cannot be marked as completed.`
|
|
14191
14658
|
);
|
|
14192
14659
|
}
|
|
14193
|
-
const now =
|
|
14660
|
+
const now = Timestamp31.now();
|
|
14194
14661
|
const updatedInstructions = [...instance.instructions];
|
|
14195
14662
|
updatedInstructions[instructionIndex] = {
|
|
14196
14663
|
...instructionToUpdate,
|
|
@@ -14217,7 +14684,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
14217
14684
|
if (newOverallStatus !== instance.overallStatus) {
|
|
14218
14685
|
updatePayload.overallStatus = newOverallStatus;
|
|
14219
14686
|
}
|
|
14220
|
-
await
|
|
14687
|
+
await updateDoc27(instanceRef, updatePayload);
|
|
14221
14688
|
return {
|
|
14222
14689
|
...instance,
|
|
14223
14690
|
instructions: updatedInstructions,
|
|
@@ -14232,13 +14699,13 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
14232
14699
|
// src/backoffice/services/brand.service.ts
|
|
14233
14700
|
import {
|
|
14234
14701
|
addDoc as addDoc3,
|
|
14235
|
-
collection as
|
|
14236
|
-
doc as
|
|
14237
|
-
getDoc as
|
|
14238
|
-
getDocs as
|
|
14239
|
-
query as
|
|
14240
|
-
updateDoc as
|
|
14241
|
-
where as
|
|
14702
|
+
collection as collection30,
|
|
14703
|
+
doc as doc30,
|
|
14704
|
+
getDoc as getDoc32,
|
|
14705
|
+
getDocs as getDocs30,
|
|
14706
|
+
query as query30,
|
|
14707
|
+
updateDoc as updateDoc28,
|
|
14708
|
+
where as where30
|
|
14242
14709
|
} from "firebase/firestore";
|
|
14243
14710
|
|
|
14244
14711
|
// src/backoffice/types/brand.types.ts
|
|
@@ -14250,7 +14717,7 @@ var BrandService = class extends BaseService {
|
|
|
14250
14717
|
* Gets reference to brands collection
|
|
14251
14718
|
*/
|
|
14252
14719
|
getBrandsRef() {
|
|
14253
|
-
return
|
|
14720
|
+
return collection30(this.db, BRANDS_COLLECTION);
|
|
14254
14721
|
}
|
|
14255
14722
|
/**
|
|
14256
14723
|
* Creates a new brand
|
|
@@ -14270,12 +14737,12 @@ var BrandService = class extends BaseService {
|
|
|
14270
14737
|
* Gets all active brands
|
|
14271
14738
|
*/
|
|
14272
14739
|
async getAll() {
|
|
14273
|
-
const q =
|
|
14274
|
-
const snapshot = await
|
|
14740
|
+
const q = query30(this.getBrandsRef(), where30("isActive", "==", true));
|
|
14741
|
+
const snapshot = await getDocs30(q);
|
|
14275
14742
|
return snapshot.docs.map(
|
|
14276
|
-
(
|
|
14277
|
-
id:
|
|
14278
|
-
...
|
|
14743
|
+
(doc35) => ({
|
|
14744
|
+
id: doc35.id,
|
|
14745
|
+
...doc35.data()
|
|
14279
14746
|
})
|
|
14280
14747
|
);
|
|
14281
14748
|
}
|
|
@@ -14287,8 +14754,8 @@ var BrandService = class extends BaseService {
|
|
|
14287
14754
|
...brand,
|
|
14288
14755
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14289
14756
|
};
|
|
14290
|
-
const docRef =
|
|
14291
|
-
await
|
|
14757
|
+
const docRef = doc30(this.getBrandsRef(), brandId);
|
|
14758
|
+
await updateDoc28(docRef, updateData);
|
|
14292
14759
|
return this.getById(brandId);
|
|
14293
14760
|
}
|
|
14294
14761
|
/**
|
|
@@ -14303,8 +14770,8 @@ var BrandService = class extends BaseService {
|
|
|
14303
14770
|
* Gets a brand by ID
|
|
14304
14771
|
*/
|
|
14305
14772
|
async getById(brandId) {
|
|
14306
|
-
const docRef =
|
|
14307
|
-
const docSnap = await
|
|
14773
|
+
const docRef = doc30(this.getBrandsRef(), brandId);
|
|
14774
|
+
const docSnap = await getDoc32(docRef);
|
|
14308
14775
|
if (!docSnap.exists()) return null;
|
|
14309
14776
|
return {
|
|
14310
14777
|
id: docSnap.id,
|
|
@@ -14316,13 +14783,13 @@ var BrandService = class extends BaseService {
|
|
|
14316
14783
|
// src/backoffice/services/category.service.ts
|
|
14317
14784
|
import {
|
|
14318
14785
|
addDoc as addDoc4,
|
|
14319
|
-
collection as
|
|
14320
|
-
doc as
|
|
14321
|
-
getDoc as
|
|
14322
|
-
getDocs as
|
|
14323
|
-
query as
|
|
14324
|
-
updateDoc as
|
|
14325
|
-
where as
|
|
14786
|
+
collection as collection31,
|
|
14787
|
+
doc as doc31,
|
|
14788
|
+
getDoc as getDoc33,
|
|
14789
|
+
getDocs as getDocs31,
|
|
14790
|
+
query as query31,
|
|
14791
|
+
updateDoc as updateDoc29,
|
|
14792
|
+
where as where31
|
|
14326
14793
|
} from "firebase/firestore";
|
|
14327
14794
|
|
|
14328
14795
|
// src/backoffice/types/category.types.ts
|
|
@@ -14334,7 +14801,7 @@ var CategoryService = class extends BaseService {
|
|
|
14334
14801
|
* Referenca na Firestore kolekciju kategorija
|
|
14335
14802
|
*/
|
|
14336
14803
|
get categoriesRef() {
|
|
14337
|
-
return
|
|
14804
|
+
return collection31(this.db, CATEGORIES_COLLECTION);
|
|
14338
14805
|
}
|
|
14339
14806
|
/**
|
|
14340
14807
|
* Kreira novu kategoriju u sistemu
|
|
@@ -14357,12 +14824,12 @@ var CategoryService = class extends BaseService {
|
|
|
14357
14824
|
* @returns Lista aktivnih kategorija
|
|
14358
14825
|
*/
|
|
14359
14826
|
async getAll() {
|
|
14360
|
-
const q =
|
|
14361
|
-
const snapshot = await
|
|
14827
|
+
const q = query31(this.categoriesRef, where31("isActive", "==", true));
|
|
14828
|
+
const snapshot = await getDocs31(q);
|
|
14362
14829
|
return snapshot.docs.map(
|
|
14363
|
-
(
|
|
14364
|
-
id:
|
|
14365
|
-
...
|
|
14830
|
+
(doc35) => ({
|
|
14831
|
+
id: doc35.id,
|
|
14832
|
+
...doc35.data()
|
|
14366
14833
|
})
|
|
14367
14834
|
);
|
|
14368
14835
|
}
|
|
@@ -14372,16 +14839,16 @@ var CategoryService = class extends BaseService {
|
|
|
14372
14839
|
* @returns Lista kategorija koje pripadaju traženoj familiji
|
|
14373
14840
|
*/
|
|
14374
14841
|
async getAllByFamily(family) {
|
|
14375
|
-
const q =
|
|
14842
|
+
const q = query31(
|
|
14376
14843
|
this.categoriesRef,
|
|
14377
|
-
|
|
14378
|
-
|
|
14844
|
+
where31("family", "==", family),
|
|
14845
|
+
where31("isActive", "==", true)
|
|
14379
14846
|
);
|
|
14380
|
-
const snapshot = await
|
|
14847
|
+
const snapshot = await getDocs31(q);
|
|
14381
14848
|
return snapshot.docs.map(
|
|
14382
|
-
(
|
|
14383
|
-
id:
|
|
14384
|
-
...
|
|
14849
|
+
(doc35) => ({
|
|
14850
|
+
id: doc35.id,
|
|
14851
|
+
...doc35.data()
|
|
14385
14852
|
})
|
|
14386
14853
|
);
|
|
14387
14854
|
}
|
|
@@ -14396,8 +14863,8 @@ var CategoryService = class extends BaseService {
|
|
|
14396
14863
|
...category,
|
|
14397
14864
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14398
14865
|
};
|
|
14399
|
-
const docRef =
|
|
14400
|
-
await
|
|
14866
|
+
const docRef = doc31(this.categoriesRef, id);
|
|
14867
|
+
await updateDoc29(docRef, updateData);
|
|
14401
14868
|
return this.getById(id);
|
|
14402
14869
|
}
|
|
14403
14870
|
/**
|
|
@@ -14413,8 +14880,8 @@ var CategoryService = class extends BaseService {
|
|
|
14413
14880
|
* @returns Kategorija ili null ako ne postoji
|
|
14414
14881
|
*/
|
|
14415
14882
|
async getById(id) {
|
|
14416
|
-
const docRef =
|
|
14417
|
-
const docSnap = await
|
|
14883
|
+
const docRef = doc31(this.categoriesRef, id);
|
|
14884
|
+
const docSnap = await getDoc33(docRef);
|
|
14418
14885
|
if (!docSnap.exists()) return null;
|
|
14419
14886
|
return {
|
|
14420
14887
|
id: docSnap.id,
|
|
@@ -14426,13 +14893,13 @@ var CategoryService = class extends BaseService {
|
|
|
14426
14893
|
// src/backoffice/services/subcategory.service.ts
|
|
14427
14894
|
import {
|
|
14428
14895
|
addDoc as addDoc5,
|
|
14429
|
-
collection as
|
|
14430
|
-
doc as
|
|
14431
|
-
getDoc as
|
|
14432
|
-
getDocs as
|
|
14433
|
-
query as
|
|
14434
|
-
updateDoc as
|
|
14435
|
-
where as
|
|
14896
|
+
collection as collection32,
|
|
14897
|
+
doc as doc32,
|
|
14898
|
+
getDoc as getDoc34,
|
|
14899
|
+
getDocs as getDocs32,
|
|
14900
|
+
query as query32,
|
|
14901
|
+
updateDoc as updateDoc30,
|
|
14902
|
+
where as where32
|
|
14436
14903
|
} from "firebase/firestore";
|
|
14437
14904
|
|
|
14438
14905
|
// src/backoffice/types/subcategory.types.ts
|
|
@@ -14445,7 +14912,7 @@ var SubcategoryService = class extends BaseService {
|
|
|
14445
14912
|
* @param categoryId - ID roditeljske kategorije
|
|
14446
14913
|
*/
|
|
14447
14914
|
getSubcategoriesRef(categoryId) {
|
|
14448
|
-
return
|
|
14915
|
+
return collection32(
|
|
14449
14916
|
this.db,
|
|
14450
14917
|
CATEGORIES_COLLECTION,
|
|
14451
14918
|
categoryId,
|
|
@@ -14479,15 +14946,15 @@ var SubcategoryService = class extends BaseService {
|
|
|
14479
14946
|
* @returns Lista aktivnih podkategorija
|
|
14480
14947
|
*/
|
|
14481
14948
|
async getAllByCategoryId(categoryId) {
|
|
14482
|
-
const q =
|
|
14949
|
+
const q = query32(
|
|
14483
14950
|
this.getSubcategoriesRef(categoryId),
|
|
14484
|
-
|
|
14951
|
+
where32("isActive", "==", true)
|
|
14485
14952
|
);
|
|
14486
|
-
const snapshot = await
|
|
14953
|
+
const snapshot = await getDocs32(q);
|
|
14487
14954
|
return snapshot.docs.map(
|
|
14488
|
-
(
|
|
14489
|
-
id:
|
|
14490
|
-
...
|
|
14955
|
+
(doc35) => ({
|
|
14956
|
+
id: doc35.id,
|
|
14957
|
+
...doc35.data()
|
|
14491
14958
|
})
|
|
14492
14959
|
);
|
|
14493
14960
|
}
|
|
@@ -14503,8 +14970,8 @@ var SubcategoryService = class extends BaseService {
|
|
|
14503
14970
|
...subcategory,
|
|
14504
14971
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14505
14972
|
};
|
|
14506
|
-
const docRef =
|
|
14507
|
-
await
|
|
14973
|
+
const docRef = doc32(this.getSubcategoriesRef(categoryId), subcategoryId);
|
|
14974
|
+
await updateDoc30(docRef, updateData);
|
|
14508
14975
|
return this.getById(categoryId, subcategoryId);
|
|
14509
14976
|
}
|
|
14510
14977
|
/**
|
|
@@ -14522,8 +14989,8 @@ var SubcategoryService = class extends BaseService {
|
|
|
14522
14989
|
* @returns Podkategorija ili null ako ne postoji
|
|
14523
14990
|
*/
|
|
14524
14991
|
async getById(categoryId, subcategoryId) {
|
|
14525
|
-
const docRef =
|
|
14526
|
-
const docSnap = await
|
|
14992
|
+
const docRef = doc32(this.getSubcategoriesRef(categoryId), subcategoryId);
|
|
14993
|
+
const docSnap = await getDoc34(docRef);
|
|
14527
14994
|
if (!docSnap.exists()) return null;
|
|
14528
14995
|
return {
|
|
14529
14996
|
id: docSnap.id,
|
|
@@ -14535,13 +15002,13 @@ var SubcategoryService = class extends BaseService {
|
|
|
14535
15002
|
// src/backoffice/services/technology.service.ts
|
|
14536
15003
|
import {
|
|
14537
15004
|
addDoc as addDoc6,
|
|
14538
|
-
collection as
|
|
14539
|
-
doc as
|
|
14540
|
-
getDoc as
|
|
14541
|
-
getDocs as
|
|
14542
|
-
query as
|
|
14543
|
-
updateDoc as
|
|
14544
|
-
where as
|
|
15005
|
+
collection as collection33,
|
|
15006
|
+
doc as doc33,
|
|
15007
|
+
getDoc as getDoc35,
|
|
15008
|
+
getDocs as getDocs33,
|
|
15009
|
+
query as query33,
|
|
15010
|
+
updateDoc as updateDoc31,
|
|
15011
|
+
where as where33,
|
|
14545
15012
|
arrayUnion as arrayUnion9,
|
|
14546
15013
|
arrayRemove as arrayRemove8
|
|
14547
15014
|
} from "firebase/firestore";
|
|
@@ -14554,7 +15021,7 @@ var TechnologyService = class extends BaseService {
|
|
|
14554
15021
|
* Vraća referencu na Firestore kolekciju tehnologija
|
|
14555
15022
|
*/
|
|
14556
15023
|
getTechnologiesRef() {
|
|
14557
|
-
return
|
|
15024
|
+
return collection33(this.db, TECHNOLOGIES_COLLECTION);
|
|
14558
15025
|
}
|
|
14559
15026
|
/**
|
|
14560
15027
|
* Kreira novu tehnologiju
|
|
@@ -14585,12 +15052,12 @@ var TechnologyService = class extends BaseService {
|
|
|
14585
15052
|
* @returns Lista aktivnih tehnologija
|
|
14586
15053
|
*/
|
|
14587
15054
|
async getAll() {
|
|
14588
|
-
const q =
|
|
14589
|
-
const snapshot = await
|
|
15055
|
+
const q = query33(this.getTechnologiesRef(), where33("isActive", "==", true));
|
|
15056
|
+
const snapshot = await getDocs33(q);
|
|
14590
15057
|
return snapshot.docs.map(
|
|
14591
|
-
(
|
|
14592
|
-
id:
|
|
14593
|
-
...
|
|
15058
|
+
(doc35) => ({
|
|
15059
|
+
id: doc35.id,
|
|
15060
|
+
...doc35.data()
|
|
14594
15061
|
})
|
|
14595
15062
|
);
|
|
14596
15063
|
}
|
|
@@ -14600,16 +15067,16 @@ var TechnologyService = class extends BaseService {
|
|
|
14600
15067
|
* @returns Lista aktivnih tehnologija
|
|
14601
15068
|
*/
|
|
14602
15069
|
async getAllByFamily(family) {
|
|
14603
|
-
const q =
|
|
15070
|
+
const q = query33(
|
|
14604
15071
|
this.getTechnologiesRef(),
|
|
14605
|
-
|
|
14606
|
-
|
|
15072
|
+
where33("isActive", "==", true),
|
|
15073
|
+
where33("family", "==", family)
|
|
14607
15074
|
);
|
|
14608
|
-
const snapshot = await
|
|
15075
|
+
const snapshot = await getDocs33(q);
|
|
14609
15076
|
return snapshot.docs.map(
|
|
14610
|
-
(
|
|
14611
|
-
id:
|
|
14612
|
-
...
|
|
15077
|
+
(doc35) => ({
|
|
15078
|
+
id: doc35.id,
|
|
15079
|
+
...doc35.data()
|
|
14613
15080
|
})
|
|
14614
15081
|
);
|
|
14615
15082
|
}
|
|
@@ -14619,16 +15086,16 @@ var TechnologyService = class extends BaseService {
|
|
|
14619
15086
|
* @returns Lista aktivnih tehnologija
|
|
14620
15087
|
*/
|
|
14621
15088
|
async getAllByCategoryId(categoryId) {
|
|
14622
|
-
const q =
|
|
15089
|
+
const q = query33(
|
|
14623
15090
|
this.getTechnologiesRef(),
|
|
14624
|
-
|
|
14625
|
-
|
|
15091
|
+
where33("isActive", "==", true),
|
|
15092
|
+
where33("categoryId", "==", categoryId)
|
|
14626
15093
|
);
|
|
14627
|
-
const snapshot = await
|
|
15094
|
+
const snapshot = await getDocs33(q);
|
|
14628
15095
|
return snapshot.docs.map(
|
|
14629
|
-
(
|
|
14630
|
-
id:
|
|
14631
|
-
...
|
|
15096
|
+
(doc35) => ({
|
|
15097
|
+
id: doc35.id,
|
|
15098
|
+
...doc35.data()
|
|
14632
15099
|
})
|
|
14633
15100
|
);
|
|
14634
15101
|
}
|
|
@@ -14638,16 +15105,16 @@ var TechnologyService = class extends BaseService {
|
|
|
14638
15105
|
* @returns Lista aktivnih tehnologija
|
|
14639
15106
|
*/
|
|
14640
15107
|
async getAllBySubcategoryId(subcategoryId) {
|
|
14641
|
-
const q =
|
|
15108
|
+
const q = query33(
|
|
14642
15109
|
this.getTechnologiesRef(),
|
|
14643
|
-
|
|
14644
|
-
|
|
15110
|
+
where33("isActive", "==", true),
|
|
15111
|
+
where33("subcategoryId", "==", subcategoryId)
|
|
14645
15112
|
);
|
|
14646
|
-
const snapshot = await
|
|
15113
|
+
const snapshot = await getDocs33(q);
|
|
14647
15114
|
return snapshot.docs.map(
|
|
14648
|
-
(
|
|
14649
|
-
id:
|
|
14650
|
-
...
|
|
15115
|
+
(doc35) => ({
|
|
15116
|
+
id: doc35.id,
|
|
15117
|
+
...doc35.data()
|
|
14651
15118
|
})
|
|
14652
15119
|
);
|
|
14653
15120
|
}
|
|
@@ -14662,8 +15129,8 @@ var TechnologyService = class extends BaseService {
|
|
|
14662
15129
|
...technology,
|
|
14663
15130
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14664
15131
|
};
|
|
14665
|
-
const docRef =
|
|
14666
|
-
await
|
|
15132
|
+
const docRef = doc33(this.getTechnologiesRef(), technologyId);
|
|
15133
|
+
await updateDoc31(docRef, updateData);
|
|
14667
15134
|
return this.getById(technologyId);
|
|
14668
15135
|
}
|
|
14669
15136
|
/**
|
|
@@ -14681,8 +15148,8 @@ var TechnologyService = class extends BaseService {
|
|
|
14681
15148
|
* @returns Tehnologija ili null ako ne postoji
|
|
14682
15149
|
*/
|
|
14683
15150
|
async getById(technologyId) {
|
|
14684
|
-
const docRef =
|
|
14685
|
-
const docSnap = await
|
|
15151
|
+
const docRef = doc33(this.getTechnologiesRef(), technologyId);
|
|
15152
|
+
const docSnap = await getDoc35(docRef);
|
|
14686
15153
|
if (!docSnap.exists()) return null;
|
|
14687
15154
|
return {
|
|
14688
15155
|
id: docSnap.id,
|
|
@@ -14696,9 +15163,9 @@ var TechnologyService = class extends BaseService {
|
|
|
14696
15163
|
* @returns Ažurirana tehnologija sa novim zahtevom
|
|
14697
15164
|
*/
|
|
14698
15165
|
async addRequirement(technologyId, requirement) {
|
|
14699
|
-
const docRef =
|
|
15166
|
+
const docRef = doc33(this.getTechnologiesRef(), technologyId);
|
|
14700
15167
|
const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
|
|
14701
|
-
await
|
|
15168
|
+
await updateDoc31(docRef, {
|
|
14702
15169
|
[requirementType]: arrayUnion9(requirement),
|
|
14703
15170
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14704
15171
|
});
|
|
@@ -14711,9 +15178,9 @@ var TechnologyService = class extends BaseService {
|
|
|
14711
15178
|
* @returns Ažurirana tehnologija bez uklonjenog zahteva
|
|
14712
15179
|
*/
|
|
14713
15180
|
async removeRequirement(technologyId, requirement) {
|
|
14714
|
-
const docRef =
|
|
15181
|
+
const docRef = doc33(this.getTechnologiesRef(), technologyId);
|
|
14715
15182
|
const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
|
|
14716
|
-
await
|
|
15183
|
+
await updateDoc31(docRef, {
|
|
14717
15184
|
[requirementType]: arrayRemove8(requirement),
|
|
14718
15185
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14719
15186
|
});
|
|
@@ -14751,8 +15218,8 @@ var TechnologyService = class extends BaseService {
|
|
|
14751
15218
|
* @returns Ažurirana tehnologija
|
|
14752
15219
|
*/
|
|
14753
15220
|
async addBlockingCondition(technologyId, condition) {
|
|
14754
|
-
const docRef =
|
|
14755
|
-
await
|
|
15221
|
+
const docRef = doc33(this.getTechnologiesRef(), technologyId);
|
|
15222
|
+
await updateDoc31(docRef, {
|
|
14756
15223
|
blockingConditions: arrayUnion9(condition),
|
|
14757
15224
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14758
15225
|
});
|
|
@@ -14765,8 +15232,8 @@ var TechnologyService = class extends BaseService {
|
|
|
14765
15232
|
* @returns Ažurirana tehnologija
|
|
14766
15233
|
*/
|
|
14767
15234
|
async removeBlockingCondition(technologyId, condition) {
|
|
14768
|
-
const docRef =
|
|
14769
|
-
await
|
|
15235
|
+
const docRef = doc33(this.getTechnologiesRef(), technologyId);
|
|
15236
|
+
await updateDoc31(docRef, {
|
|
14770
15237
|
blockingConditions: arrayRemove8(condition),
|
|
14771
15238
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14772
15239
|
});
|
|
@@ -14779,8 +15246,8 @@ var TechnologyService = class extends BaseService {
|
|
|
14779
15246
|
* @returns Ažurirana tehnologija
|
|
14780
15247
|
*/
|
|
14781
15248
|
async addContraindication(technologyId, contraindication) {
|
|
14782
|
-
const docRef =
|
|
14783
|
-
await
|
|
15249
|
+
const docRef = doc33(this.getTechnologiesRef(), technologyId);
|
|
15250
|
+
await updateDoc31(docRef, {
|
|
14784
15251
|
contraindications: arrayUnion9(contraindication),
|
|
14785
15252
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14786
15253
|
});
|
|
@@ -14793,8 +15260,8 @@ var TechnologyService = class extends BaseService {
|
|
|
14793
15260
|
* @returns Ažurirana tehnologija
|
|
14794
15261
|
*/
|
|
14795
15262
|
async removeContraindication(technologyId, contraindication) {
|
|
14796
|
-
const docRef =
|
|
14797
|
-
await
|
|
15263
|
+
const docRef = doc33(this.getTechnologiesRef(), technologyId);
|
|
15264
|
+
await updateDoc31(docRef, {
|
|
14798
15265
|
contraindications: arrayRemove8(contraindication),
|
|
14799
15266
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14800
15267
|
});
|
|
@@ -14807,8 +15274,8 @@ var TechnologyService = class extends BaseService {
|
|
|
14807
15274
|
* @returns Ažurirana tehnologija
|
|
14808
15275
|
*/
|
|
14809
15276
|
async addBenefit(technologyId, benefit) {
|
|
14810
|
-
const docRef =
|
|
14811
|
-
await
|
|
15277
|
+
const docRef = doc33(this.getTechnologiesRef(), technologyId);
|
|
15278
|
+
await updateDoc31(docRef, {
|
|
14812
15279
|
benefits: arrayUnion9(benefit),
|
|
14813
15280
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14814
15281
|
});
|
|
@@ -14821,8 +15288,8 @@ var TechnologyService = class extends BaseService {
|
|
|
14821
15288
|
* @returns Ažurirana tehnologija
|
|
14822
15289
|
*/
|
|
14823
15290
|
async removeBenefit(technologyId, benefit) {
|
|
14824
|
-
const docRef =
|
|
14825
|
-
await
|
|
15291
|
+
const docRef = doc33(this.getTechnologiesRef(), technologyId);
|
|
15292
|
+
await updateDoc31(docRef, {
|
|
14826
15293
|
benefits: arrayRemove8(benefit),
|
|
14827
15294
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14828
15295
|
});
|
|
@@ -14862,8 +15329,8 @@ var TechnologyService = class extends BaseService {
|
|
|
14862
15329
|
* @returns Ažurirana tehnologija
|
|
14863
15330
|
*/
|
|
14864
15331
|
async updateCertificationRequirement(technologyId, certificationRequirement) {
|
|
14865
|
-
const docRef =
|
|
14866
|
-
await
|
|
15332
|
+
const docRef = doc33(this.getTechnologiesRef(), technologyId);
|
|
15333
|
+
await updateDoc31(docRef, {
|
|
14867
15334
|
certificationRequirement,
|
|
14868
15335
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14869
15336
|
});
|
|
@@ -14965,13 +15432,13 @@ var TechnologyService = class extends BaseService {
|
|
|
14965
15432
|
// src/backoffice/services/product.service.ts
|
|
14966
15433
|
import {
|
|
14967
15434
|
addDoc as addDoc7,
|
|
14968
|
-
collection as
|
|
14969
|
-
doc as
|
|
14970
|
-
getDoc as
|
|
14971
|
-
getDocs as
|
|
14972
|
-
query as
|
|
14973
|
-
updateDoc as
|
|
14974
|
-
where as
|
|
15435
|
+
collection as collection34,
|
|
15436
|
+
doc as doc34,
|
|
15437
|
+
getDoc as getDoc36,
|
|
15438
|
+
getDocs as getDocs34,
|
|
15439
|
+
query as query34,
|
|
15440
|
+
updateDoc as updateDoc32,
|
|
15441
|
+
where as where34
|
|
14975
15442
|
} from "firebase/firestore";
|
|
14976
15443
|
|
|
14977
15444
|
// src/backoffice/types/product.types.ts
|
|
@@ -14985,7 +15452,7 @@ var ProductService = class extends BaseService {
|
|
|
14985
15452
|
* @returns Firestore collection reference
|
|
14986
15453
|
*/
|
|
14987
15454
|
getProductsRef(technologyId) {
|
|
14988
|
-
return
|
|
15455
|
+
return collection34(
|
|
14989
15456
|
this.db,
|
|
14990
15457
|
TECHNOLOGIES_COLLECTION,
|
|
14991
15458
|
technologyId,
|
|
@@ -15015,15 +15482,15 @@ var ProductService = class extends BaseService {
|
|
|
15015
15482
|
* Gets all products for a technology
|
|
15016
15483
|
*/
|
|
15017
15484
|
async getAllByTechnology(technologyId) {
|
|
15018
|
-
const q =
|
|
15485
|
+
const q = query34(
|
|
15019
15486
|
this.getProductsRef(technologyId),
|
|
15020
|
-
|
|
15487
|
+
where34("isActive", "==", true)
|
|
15021
15488
|
);
|
|
15022
|
-
const snapshot = await
|
|
15489
|
+
const snapshot = await getDocs34(q);
|
|
15023
15490
|
return snapshot.docs.map(
|
|
15024
|
-
(
|
|
15025
|
-
id:
|
|
15026
|
-
...
|
|
15491
|
+
(doc35) => ({
|
|
15492
|
+
id: doc35.id,
|
|
15493
|
+
...doc35.data()
|
|
15027
15494
|
})
|
|
15028
15495
|
);
|
|
15029
15496
|
}
|
|
@@ -15031,21 +15498,21 @@ var ProductService = class extends BaseService {
|
|
|
15031
15498
|
* Gets all products for a brand by filtering through all technologies
|
|
15032
15499
|
*/
|
|
15033
15500
|
async getAllByBrand(brandId) {
|
|
15034
|
-
const allTechnologiesRef =
|
|
15035
|
-
const technologiesSnapshot = await
|
|
15501
|
+
const allTechnologiesRef = collection34(this.db, TECHNOLOGIES_COLLECTION);
|
|
15502
|
+
const technologiesSnapshot = await getDocs34(allTechnologiesRef);
|
|
15036
15503
|
const products = [];
|
|
15037
15504
|
for (const techDoc of technologiesSnapshot.docs) {
|
|
15038
|
-
const q =
|
|
15505
|
+
const q = query34(
|
|
15039
15506
|
this.getProductsRef(techDoc.id),
|
|
15040
|
-
|
|
15041
|
-
|
|
15507
|
+
where34("brandId", "==", brandId),
|
|
15508
|
+
where34("isActive", "==", true)
|
|
15042
15509
|
);
|
|
15043
|
-
const snapshot = await
|
|
15510
|
+
const snapshot = await getDocs34(q);
|
|
15044
15511
|
products.push(
|
|
15045
15512
|
...snapshot.docs.map(
|
|
15046
|
-
(
|
|
15047
|
-
id:
|
|
15048
|
-
...
|
|
15513
|
+
(doc35) => ({
|
|
15514
|
+
id: doc35.id,
|
|
15515
|
+
...doc35.data()
|
|
15049
15516
|
})
|
|
15050
15517
|
)
|
|
15051
15518
|
);
|
|
@@ -15060,8 +15527,8 @@ var ProductService = class extends BaseService {
|
|
|
15060
15527
|
...product,
|
|
15061
15528
|
updatedAt: /* @__PURE__ */ new Date()
|
|
15062
15529
|
};
|
|
15063
|
-
const docRef =
|
|
15064
|
-
await
|
|
15530
|
+
const docRef = doc34(this.getProductsRef(technologyId), productId);
|
|
15531
|
+
await updateDoc32(docRef, updateData);
|
|
15065
15532
|
return this.getById(technologyId, productId);
|
|
15066
15533
|
}
|
|
15067
15534
|
/**
|
|
@@ -15076,8 +15543,8 @@ var ProductService = class extends BaseService {
|
|
|
15076
15543
|
* Gets a product by ID
|
|
15077
15544
|
*/
|
|
15078
15545
|
async getById(technologyId, productId) {
|
|
15079
|
-
const docRef =
|
|
15080
|
-
const docSnap = await
|
|
15546
|
+
const docRef = doc34(this.getProductsRef(technologyId), productId);
|
|
15547
|
+
const docSnap = await getDoc36(docRef);
|
|
15081
15548
|
if (!docSnap.exists()) return null;
|
|
15082
15549
|
return {
|
|
15083
15550
|
id: docSnap.id,
|
|
@@ -15241,6 +15708,7 @@ export {
|
|
|
15241
15708
|
PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME,
|
|
15242
15709
|
PATIENT_SENSITIVE_INFO_COLLECTION,
|
|
15243
15710
|
PRACTITIONERS_COLLECTION,
|
|
15711
|
+
PRACTITIONER_INVITES_COLLECTION,
|
|
15244
15712
|
PROCEDURES_COLLECTION,
|
|
15245
15713
|
PatientInstructionStatus,
|
|
15246
15714
|
PatientRequirementOverallStatus,
|
|
@@ -15248,6 +15716,8 @@ export {
|
|
|
15248
15716
|
PatientService,
|
|
15249
15717
|
PaymentStatus,
|
|
15250
15718
|
PracticeType,
|
|
15719
|
+
PractitionerInviteService,
|
|
15720
|
+
PractitionerInviteStatus,
|
|
15251
15721
|
PractitionerService,
|
|
15252
15722
|
PractitionerStatus,
|
|
15253
15723
|
PractitionerTokenStatus,
|