@blackcode_sa/metaestetics-api 1.7.23 → 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 +189 -1
- package/dist/index.d.ts +189 -1
- package/dist/index.js +983 -576
- package/dist/index.mjs +1110 -692
- package/package.json +1 -1
- package/src/index.ts +8 -0
- 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/dist/index.js
CHANGED
|
@@ -88,6 +88,7 @@ __export(index_exports, {
|
|
|
88
88
|
PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME: () => PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME,
|
|
89
89
|
PATIENT_SENSITIVE_INFO_COLLECTION: () => PATIENT_SENSITIVE_INFO_COLLECTION,
|
|
90
90
|
PRACTITIONERS_COLLECTION: () => PRACTITIONERS_COLLECTION,
|
|
91
|
+
PRACTITIONER_INVITES_COLLECTION: () => PRACTITIONER_INVITES_COLLECTION,
|
|
91
92
|
PROCEDURES_COLLECTION: () => PROCEDURES_COLLECTION,
|
|
92
93
|
PatientInstructionStatus: () => PatientInstructionStatus,
|
|
93
94
|
PatientRequirementOverallStatus: () => PatientRequirementOverallStatus,
|
|
@@ -95,6 +96,8 @@ __export(index_exports, {
|
|
|
95
96
|
PatientService: () => PatientService,
|
|
96
97
|
PaymentStatus: () => PaymentStatus,
|
|
97
98
|
PracticeType: () => PracticeType,
|
|
99
|
+
PractitionerInviteService: () => PractitionerInviteService,
|
|
100
|
+
PractitionerInviteStatus: () => PractitionerInviteStatus,
|
|
98
101
|
PractitionerService: () => PractitionerService,
|
|
99
102
|
PractitionerStatus: () => PractitionerStatus,
|
|
100
103
|
PractitionerTokenStatus: () => PractitionerTokenStatus,
|
|
@@ -1480,7 +1483,7 @@ var MediaService = class extends BaseService {
|
|
|
1480
1483
|
try {
|
|
1481
1484
|
const querySnapshot = await (0, import_firestore3.getDocs)(finalQuery);
|
|
1482
1485
|
const mediaList = querySnapshot.docs.map(
|
|
1483
|
-
(
|
|
1486
|
+
(doc35) => doc35.data()
|
|
1484
1487
|
);
|
|
1485
1488
|
console.log(`[MediaService] Found ${mediaList.length} media items.`);
|
|
1486
1489
|
return mediaList;
|
|
@@ -2117,8 +2120,8 @@ var getPatientsByPractitionerUtil = async (db, practitionerId, options) => {
|
|
|
2117
2120
|
}
|
|
2118
2121
|
const patientsSnapshot = await (0, import_firestore8.getDocs)(q);
|
|
2119
2122
|
const patients = [];
|
|
2120
|
-
patientsSnapshot.forEach((
|
|
2121
|
-
patients.push(
|
|
2123
|
+
patientsSnapshot.forEach((doc35) => {
|
|
2124
|
+
patients.push(doc35.data());
|
|
2122
2125
|
});
|
|
2123
2126
|
console.log(
|
|
2124
2127
|
`[getPatientsByPractitionerUtil] Found ${patients.length} patients for practitioner ID: ${practitionerId}`
|
|
@@ -2348,9 +2351,9 @@ var updateAllergyUtil = async (db, patientId, data, userRef) => {
|
|
|
2348
2351
|
});
|
|
2349
2352
|
};
|
|
2350
2353
|
var removeAllergyUtil = async (db, patientId, allergyIndex, userRef) => {
|
|
2351
|
-
const
|
|
2352
|
-
if (!
|
|
2353
|
-
const medicalInfo =
|
|
2354
|
+
const doc35 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
|
|
2355
|
+
if (!doc35.exists()) throw new Error("Medical info not found");
|
|
2356
|
+
const medicalInfo = doc35.data();
|
|
2354
2357
|
if (allergyIndex >= medicalInfo.allergies.length) {
|
|
2355
2358
|
throw new Error("Invalid allergy index");
|
|
2356
2359
|
}
|
|
@@ -2375,9 +2378,9 @@ var addBlockingConditionUtil = async (db, patientId, data, userRef) => {
|
|
|
2375
2378
|
var updateBlockingConditionUtil = async (db, patientId, data, userRef) => {
|
|
2376
2379
|
const validatedData = updateBlockingConditionSchema.parse(data);
|
|
2377
2380
|
const { conditionIndex, ...updateData } = validatedData;
|
|
2378
|
-
const
|
|
2379
|
-
if (!
|
|
2380
|
-
const medicalInfo =
|
|
2381
|
+
const doc35 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
|
|
2382
|
+
if (!doc35.exists()) throw new Error("Medical info not found");
|
|
2383
|
+
const medicalInfo = doc35.data();
|
|
2381
2384
|
if (conditionIndex >= medicalInfo.blockingConditions.length) {
|
|
2382
2385
|
throw new Error("Invalid blocking condition index");
|
|
2383
2386
|
}
|
|
@@ -2393,9 +2396,9 @@ var updateBlockingConditionUtil = async (db, patientId, data, userRef) => {
|
|
|
2393
2396
|
});
|
|
2394
2397
|
};
|
|
2395
2398
|
var removeBlockingConditionUtil = async (db, patientId, conditionIndex, userRef) => {
|
|
2396
|
-
const
|
|
2397
|
-
if (!
|
|
2398
|
-
const medicalInfo =
|
|
2399
|
+
const doc35 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
|
|
2400
|
+
if (!doc35.exists()) throw new Error("Medical info not found");
|
|
2401
|
+
const medicalInfo = doc35.data();
|
|
2399
2402
|
if (conditionIndex >= medicalInfo.blockingConditions.length) {
|
|
2400
2403
|
throw new Error("Invalid blocking condition index");
|
|
2401
2404
|
}
|
|
@@ -2420,9 +2423,9 @@ var addContraindicationUtil = async (db, patientId, data, userRef) => {
|
|
|
2420
2423
|
var updateContraindicationUtil = async (db, patientId, data, userRef) => {
|
|
2421
2424
|
const validatedData = updateContraindicationSchema.parse(data);
|
|
2422
2425
|
const { contraindicationIndex, ...updateData } = validatedData;
|
|
2423
|
-
const
|
|
2424
|
-
if (!
|
|
2425
|
-
const medicalInfo =
|
|
2426
|
+
const doc35 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
|
|
2427
|
+
if (!doc35.exists()) throw new Error("Medical info not found");
|
|
2428
|
+
const medicalInfo = doc35.data();
|
|
2426
2429
|
if (contraindicationIndex >= medicalInfo.contraindications.length) {
|
|
2427
2430
|
throw new Error("Invalid contraindication index");
|
|
2428
2431
|
}
|
|
@@ -2438,9 +2441,9 @@ var updateContraindicationUtil = async (db, patientId, data, userRef) => {
|
|
|
2438
2441
|
});
|
|
2439
2442
|
};
|
|
2440
2443
|
var removeContraindicationUtil = async (db, patientId, contraindicationIndex, userRef) => {
|
|
2441
|
-
const
|
|
2442
|
-
if (!
|
|
2443
|
-
const medicalInfo =
|
|
2444
|
+
const doc35 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
|
|
2445
|
+
if (!doc35.exists()) throw new Error("Medical info not found");
|
|
2446
|
+
const medicalInfo = doc35.data();
|
|
2444
2447
|
if (contraindicationIndex >= medicalInfo.contraindications.length) {
|
|
2445
2448
|
throw new Error("Invalid contraindication index");
|
|
2446
2449
|
}
|
|
@@ -2465,9 +2468,9 @@ var addMedicationUtil = async (db, patientId, data, userRef) => {
|
|
|
2465
2468
|
var updateMedicationUtil = async (db, patientId, data, userRef) => {
|
|
2466
2469
|
const validatedData = updateMedicationSchema.parse(data);
|
|
2467
2470
|
const { medicationIndex, ...updateData } = validatedData;
|
|
2468
|
-
const
|
|
2469
|
-
if (!
|
|
2470
|
-
const medicalInfo =
|
|
2471
|
+
const doc35 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
|
|
2472
|
+
if (!doc35.exists()) throw new Error("Medical info not found");
|
|
2473
|
+
const medicalInfo = doc35.data();
|
|
2471
2474
|
if (medicationIndex >= medicalInfo.currentMedications.length) {
|
|
2472
2475
|
throw new Error("Invalid medication index");
|
|
2473
2476
|
}
|
|
@@ -2483,9 +2486,9 @@ var updateMedicationUtil = async (db, patientId, data, userRef) => {
|
|
|
2483
2486
|
});
|
|
2484
2487
|
};
|
|
2485
2488
|
var removeMedicationUtil = async (db, patientId, medicationIndex, userRef) => {
|
|
2486
|
-
const
|
|
2487
|
-
if (!
|
|
2488
|
-
const medicalInfo =
|
|
2489
|
+
const doc35 = await (0, import_firestore9.getDoc)(getMedicalInfoDocRef(db, patientId));
|
|
2490
|
+
if (!doc35.exists()) throw new Error("Medical info not found");
|
|
2491
|
+
const medicalInfo = doc35.data();
|
|
2489
2492
|
if (medicationIndex >= medicalInfo.currentMedications.length) {
|
|
2490
2493
|
throw new Error("Invalid medication index");
|
|
2491
2494
|
}
|
|
@@ -2764,7 +2767,7 @@ var searchPatientsUtil = async (db, params, requester) => {
|
|
|
2764
2767
|
const finalQuery = (0, import_firestore10.query)(patientsCollectionRef, ...constraints);
|
|
2765
2768
|
const querySnapshot = await (0, import_firestore10.getDocs)(finalQuery);
|
|
2766
2769
|
const patients = querySnapshot.docs.map(
|
|
2767
|
-
(
|
|
2770
|
+
(doc35) => doc35.data()
|
|
2768
2771
|
);
|
|
2769
2772
|
console.log(
|
|
2770
2773
|
`[searchPatientsUtil] Found ${patients.length} patients matching criteria.`
|
|
@@ -2796,8 +2799,8 @@ var getAllPatientsUtil = async (db, options) => {
|
|
|
2796
2799
|
}
|
|
2797
2800
|
const patientsSnapshot = await (0, import_firestore10.getDocs)(q);
|
|
2798
2801
|
const patients = [];
|
|
2799
|
-
patientsSnapshot.forEach((
|
|
2800
|
-
patients.push(
|
|
2802
|
+
patientsSnapshot.forEach((doc35) => {
|
|
2803
|
+
patients.push(doc35.data());
|
|
2801
2804
|
});
|
|
2802
2805
|
console.log(`[getAllPatientsUtil] Found ${patients.length} patients`);
|
|
2803
2806
|
return patients;
|
|
@@ -3009,8 +3012,8 @@ var getPatientsByClinicUtil = async (db, clinicId, options) => {
|
|
|
3009
3012
|
}
|
|
3010
3013
|
const patientsSnapshot = await (0, import_firestore13.getDocs)(q);
|
|
3011
3014
|
const patients = [];
|
|
3012
|
-
patientsSnapshot.forEach((
|
|
3013
|
-
patients.push(
|
|
3015
|
+
patientsSnapshot.forEach((doc35) => {
|
|
3016
|
+
patients.push(doc35.data());
|
|
3014
3017
|
});
|
|
3015
3018
|
console.log(
|
|
3016
3019
|
`[getPatientsByClinicUtil] Found ${patients.length} patients for clinic ID: ${clinicId}`
|
|
@@ -3565,6 +3568,16 @@ var ClinicPhotoTag = /* @__PURE__ */ ((ClinicPhotoTag2) => {
|
|
|
3565
3568
|
return ClinicPhotoTag2;
|
|
3566
3569
|
})(ClinicPhotoTag || {});
|
|
3567
3570
|
|
|
3571
|
+
// src/types/clinic/practitioner-invite.types.ts
|
|
3572
|
+
var PRACTITIONER_INVITES_COLLECTION = "practitioner-invites";
|
|
3573
|
+
var PractitionerInviteStatus = /* @__PURE__ */ ((PractitionerInviteStatus2) => {
|
|
3574
|
+
PractitionerInviteStatus2["PENDING"] = "pending";
|
|
3575
|
+
PractitionerInviteStatus2["ACCEPTED"] = "accepted";
|
|
3576
|
+
PractitionerInviteStatus2["REJECTED"] = "rejected";
|
|
3577
|
+
PractitionerInviteStatus2["CANCELLED"] = "cancelled";
|
|
3578
|
+
return PractitionerInviteStatus2;
|
|
3579
|
+
})(PractitionerInviteStatus || {});
|
|
3580
|
+
|
|
3568
3581
|
// src/types/clinic/index.ts
|
|
3569
3582
|
var CLINIC_GROUPS_COLLECTION = "clinic_groups";
|
|
3570
3583
|
var CLINIC_ADMINS_COLLECTION = "clinic_admins";
|
|
@@ -4268,7 +4281,7 @@ async function getClinicAdminsByGroup(db, clinicGroupId) {
|
|
|
4268
4281
|
(0, import_firestore16.where)("clinicGroupId", "==", clinicGroupId)
|
|
4269
4282
|
);
|
|
4270
4283
|
const querySnapshot = await (0, import_firestore16.getDocs)(q);
|
|
4271
|
-
return querySnapshot.docs.map((
|
|
4284
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
4272
4285
|
}
|
|
4273
4286
|
async function updateClinicAdmin(db, adminId, data) {
|
|
4274
4287
|
const admin = await getClinicAdmin(db, adminId);
|
|
@@ -5005,7 +5018,7 @@ var PractitionerService = class extends BaseService {
|
|
|
5005
5018
|
(0, import_firestore18.where)("expiresAt", ">", import_firestore18.Timestamp.now())
|
|
5006
5019
|
);
|
|
5007
5020
|
const querySnapshot = await (0, import_firestore18.getDocs)(q);
|
|
5008
|
-
return querySnapshot.docs.map((
|
|
5021
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
5009
5022
|
}
|
|
5010
5023
|
/**
|
|
5011
5024
|
* Gets a token by its string value and validates it
|
|
@@ -5115,7 +5128,7 @@ var PractitionerService = class extends BaseService {
|
|
|
5115
5128
|
(0, import_firestore18.where)("status", "==", "active" /* ACTIVE */)
|
|
5116
5129
|
);
|
|
5117
5130
|
const querySnapshot = await (0, import_firestore18.getDocs)(q);
|
|
5118
|
-
return querySnapshot.docs.map((
|
|
5131
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
5119
5132
|
}
|
|
5120
5133
|
/**
|
|
5121
5134
|
* Dohvata sve zdravstvene radnike za određenu kliniku
|
|
@@ -5127,7 +5140,7 @@ var PractitionerService = class extends BaseService {
|
|
|
5127
5140
|
(0, import_firestore18.where)("isActive", "==", true)
|
|
5128
5141
|
);
|
|
5129
5142
|
const querySnapshot = await (0, import_firestore18.getDocs)(q);
|
|
5130
|
-
return querySnapshot.docs.map((
|
|
5143
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
5131
5144
|
}
|
|
5132
5145
|
/**
|
|
5133
5146
|
* Dohvata sve draft zdravstvene radnike za određenu kliniku sa statusom DRAFT
|
|
@@ -5139,7 +5152,7 @@ var PractitionerService = class extends BaseService {
|
|
|
5139
5152
|
(0, import_firestore18.where)("status", "==", "draft" /* DRAFT */)
|
|
5140
5153
|
);
|
|
5141
5154
|
const querySnapshot = await (0, import_firestore18.getDocs)(q);
|
|
5142
|
-
return querySnapshot.docs.map((
|
|
5155
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
5143
5156
|
}
|
|
5144
5157
|
/**
|
|
5145
5158
|
* Updates a practitioner
|
|
@@ -5353,7 +5366,7 @@ var PractitionerService = class extends BaseService {
|
|
|
5353
5366
|
);
|
|
5354
5367
|
const querySnapshot = await (0, import_firestore18.getDocs)(q);
|
|
5355
5368
|
const practitioners = querySnapshot.docs.map(
|
|
5356
|
-
(
|
|
5369
|
+
(doc35) => doc35.data()
|
|
5357
5370
|
);
|
|
5358
5371
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
5359
5372
|
return {
|
|
@@ -5424,8 +5437,8 @@ var PractitionerService = class extends BaseService {
|
|
|
5424
5437
|
console.log(
|
|
5425
5438
|
`[PRACTITIONER_SERVICE] Found ${querySnapshot.docs.length} practitioners with base query`
|
|
5426
5439
|
);
|
|
5427
|
-
let practitioners = querySnapshot.docs.map((
|
|
5428
|
-
return { ...
|
|
5440
|
+
let practitioners = querySnapshot.docs.map((doc35) => {
|
|
5441
|
+
return { ...doc35.data(), id: doc35.id };
|
|
5429
5442
|
});
|
|
5430
5443
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
5431
5444
|
if (filters.nameSearch && filters.nameSearch.trim() !== "") {
|
|
@@ -5682,7 +5695,7 @@ var UserService = class extends BaseService {
|
|
|
5682
5695
|
];
|
|
5683
5696
|
const q = (0, import_firestore19.query)((0, import_firestore19.collection)(this.db, USERS_COLLECTION), ...constraints);
|
|
5684
5697
|
const querySnapshot = await (0, import_firestore19.getDocs)(q);
|
|
5685
|
-
const users = querySnapshot.docs.map((
|
|
5698
|
+
const users = querySnapshot.docs.map((doc35) => doc35.data());
|
|
5686
5699
|
return Promise.all(users.map((userData) => userSchema.parse(userData)));
|
|
5687
5700
|
}
|
|
5688
5701
|
/**
|
|
@@ -6046,7 +6059,7 @@ async function getAllActiveGroups(db) {
|
|
|
6046
6059
|
(0, import_firestore20.where)("isActive", "==", true)
|
|
6047
6060
|
);
|
|
6048
6061
|
const querySnapshot = await (0, import_firestore20.getDocs)(q);
|
|
6049
|
-
return querySnapshot.docs.map((
|
|
6062
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
6050
6063
|
}
|
|
6051
6064
|
async function updateClinicGroup(db, groupId, data, app) {
|
|
6052
6065
|
console.log("[CLINIC_GROUP] Updating clinic group", { groupId });
|
|
@@ -6486,7 +6499,7 @@ async function getClinicsByGroup(db, groupId) {
|
|
|
6486
6499
|
(0, import_firestore21.where)("isActive", "==", true)
|
|
6487
6500
|
);
|
|
6488
6501
|
const querySnapshot = await (0, import_firestore21.getDocs)(q);
|
|
6489
|
-
return querySnapshot.docs.map((
|
|
6502
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
6490
6503
|
}
|
|
6491
6504
|
async function updateClinic(db, clinicId, data, adminId, clinicAdminService, app) {
|
|
6492
6505
|
console.log("[CLINIC] Starting clinic update", { clinicId, adminId });
|
|
@@ -6680,7 +6693,7 @@ async function getClinicsByAdmin(db, adminId, options = {}, clinicAdminService,
|
|
|
6680
6693
|
}
|
|
6681
6694
|
const q = (0, import_firestore21.query)((0, import_firestore21.collection)(db, CLINICS_COLLECTION), ...constraints);
|
|
6682
6695
|
const querySnapshot = await (0, import_firestore21.getDocs)(q);
|
|
6683
|
-
return querySnapshot.docs.map((
|
|
6696
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
6684
6697
|
}
|
|
6685
6698
|
async function getActiveClinicsByAdmin(db, adminId, clinicAdminService, clinicGroupService) {
|
|
6686
6699
|
return getClinicsByAdmin(
|
|
@@ -6725,11 +6738,11 @@ async function getAllClinics(db, pagination, lastDoc) {
|
|
|
6725
6738
|
}
|
|
6726
6739
|
const clinicsSnapshot = await (0, import_firestore21.getDocs)(clinicsQuery);
|
|
6727
6740
|
const lastVisible = clinicsSnapshot.docs[clinicsSnapshot.docs.length - 1];
|
|
6728
|
-
const clinics = clinicsSnapshot.docs.map((
|
|
6729
|
-
const data =
|
|
6741
|
+
const clinics = clinicsSnapshot.docs.map((doc35) => {
|
|
6742
|
+
const data = doc35.data();
|
|
6730
6743
|
return {
|
|
6731
6744
|
...data,
|
|
6732
|
-
id:
|
|
6745
|
+
id: doc35.id
|
|
6733
6746
|
};
|
|
6734
6747
|
});
|
|
6735
6748
|
return {
|
|
@@ -6756,8 +6769,8 @@ async function getAllClinicsInRange(db, center, rangeInKm, pagination, lastDoc)
|
|
|
6756
6769
|
];
|
|
6757
6770
|
const q = (0, import_firestore21.query)((0, import_firestore21.collection)(db, CLINICS_COLLECTION), ...constraints);
|
|
6758
6771
|
const querySnapshot = await (0, import_firestore21.getDocs)(q);
|
|
6759
|
-
for (const
|
|
6760
|
-
const clinic =
|
|
6772
|
+
for (const doc35 of querySnapshot.docs) {
|
|
6773
|
+
const clinic = doc35.data();
|
|
6761
6774
|
const distance = (0, import_geofire_common4.distanceBetween)(
|
|
6762
6775
|
[center.latitude, center.longitude],
|
|
6763
6776
|
[clinic.location.latitude, clinic.location.longitude]
|
|
@@ -6874,8 +6887,8 @@ async function findClinicsInRadius(db, center, radiusInKm, filters) {
|
|
|
6874
6887
|
}
|
|
6875
6888
|
const q = (0, import_firestore22.query)((0, import_firestore22.collection)(db, CLINICS_COLLECTION), ...constraints);
|
|
6876
6889
|
const querySnapshot = await (0, import_firestore22.getDocs)(q);
|
|
6877
|
-
for (const
|
|
6878
|
-
const clinic =
|
|
6890
|
+
for (const doc35 of querySnapshot.docs) {
|
|
6891
|
+
const clinic = doc35.data();
|
|
6879
6892
|
const distance = (0, import_geofire_common5.distanceBetween)(
|
|
6880
6893
|
[center.latitude, center.longitude],
|
|
6881
6894
|
[clinic.location.latitude, clinic.location.longitude]
|
|
@@ -6963,8 +6976,8 @@ async function getClinicsByFilters(db, filters) {
|
|
|
6963
6976
|
console.log(
|
|
6964
6977
|
`[FILTER_UTILS] Found ${querySnapshot.docs.length} clinics in geo bound`
|
|
6965
6978
|
);
|
|
6966
|
-
for (const
|
|
6967
|
-
const clinic = { ...
|
|
6979
|
+
for (const doc35 of querySnapshot.docs) {
|
|
6980
|
+
const clinic = { ...doc35.data(), id: doc35.id };
|
|
6968
6981
|
const distance = (0, import_geofire_common6.distanceBetween)(
|
|
6969
6982
|
[center.latitude, center.longitude],
|
|
6970
6983
|
[clinic.location.latitude, clinic.location.longitude]
|
|
@@ -7020,8 +7033,8 @@ async function getClinicsByFilters(db, filters) {
|
|
|
7020
7033
|
console.log(
|
|
7021
7034
|
`[FILTER_UTILS] Found ${querySnapshot.docs.length} clinics with regular query`
|
|
7022
7035
|
);
|
|
7023
|
-
const clinics = querySnapshot.docs.map((
|
|
7024
|
-
return { ...
|
|
7036
|
+
const clinics = querySnapshot.docs.map((doc35) => {
|
|
7037
|
+
return { ...doc35.data(), id: doc35.id };
|
|
7025
7038
|
});
|
|
7026
7039
|
let filteredClinics = clinics;
|
|
7027
7040
|
if (filters.center) {
|
|
@@ -8455,9 +8468,9 @@ var NotificationService = class extends BaseService {
|
|
|
8455
8468
|
(0, import_firestore26.orderBy)("notificationTime", "desc")
|
|
8456
8469
|
);
|
|
8457
8470
|
const querySnapshot = await (0, import_firestore26.getDocs)(q);
|
|
8458
|
-
return querySnapshot.docs.map((
|
|
8459
|
-
id:
|
|
8460
|
-
...
|
|
8471
|
+
return querySnapshot.docs.map((doc35) => ({
|
|
8472
|
+
id: doc35.id,
|
|
8473
|
+
...doc35.data()
|
|
8461
8474
|
}));
|
|
8462
8475
|
}
|
|
8463
8476
|
/**
|
|
@@ -8471,9 +8484,9 @@ var NotificationService = class extends BaseService {
|
|
|
8471
8484
|
(0, import_firestore26.orderBy)("notificationTime", "desc")
|
|
8472
8485
|
);
|
|
8473
8486
|
const querySnapshot = await (0, import_firestore26.getDocs)(q);
|
|
8474
|
-
return querySnapshot.docs.map((
|
|
8475
|
-
id:
|
|
8476
|
-
...
|
|
8487
|
+
return querySnapshot.docs.map((doc35) => ({
|
|
8488
|
+
id: doc35.id,
|
|
8489
|
+
...doc35.data()
|
|
8477
8490
|
}));
|
|
8478
8491
|
}
|
|
8479
8492
|
/**
|
|
@@ -8545,9 +8558,9 @@ var NotificationService = class extends BaseService {
|
|
|
8545
8558
|
(0, import_firestore26.orderBy)("notificationTime", "desc")
|
|
8546
8559
|
);
|
|
8547
8560
|
const querySnapshot = await (0, import_firestore26.getDocs)(q);
|
|
8548
|
-
return querySnapshot.docs.map((
|
|
8549
|
-
id:
|
|
8550
|
-
...
|
|
8561
|
+
return querySnapshot.docs.map((doc35) => ({
|
|
8562
|
+
id: doc35.id,
|
|
8563
|
+
...doc35.data()
|
|
8551
8564
|
}));
|
|
8552
8565
|
}
|
|
8553
8566
|
/**
|
|
@@ -8560,9 +8573,9 @@ var NotificationService = class extends BaseService {
|
|
|
8560
8573
|
(0, import_firestore26.orderBy)("notificationTime", "desc")
|
|
8561
8574
|
);
|
|
8562
8575
|
const querySnapshot = await (0, import_firestore26.getDocs)(q);
|
|
8563
|
-
return querySnapshot.docs.map((
|
|
8564
|
-
id:
|
|
8565
|
-
...
|
|
8576
|
+
return querySnapshot.docs.map((doc35) => ({
|
|
8577
|
+
id: doc35.id,
|
|
8578
|
+
...doc35.data()
|
|
8566
8579
|
}));
|
|
8567
8580
|
}
|
|
8568
8581
|
};
|
|
@@ -8843,7 +8856,7 @@ var ProcedureService = class extends BaseService {
|
|
|
8843
8856
|
(0, import_firestore27.where)("isActive", "==", true)
|
|
8844
8857
|
);
|
|
8845
8858
|
const snapshot = await (0, import_firestore27.getDocs)(q);
|
|
8846
|
-
return snapshot.docs.map((
|
|
8859
|
+
return snapshot.docs.map((doc35) => doc35.data());
|
|
8847
8860
|
}
|
|
8848
8861
|
/**
|
|
8849
8862
|
* Gets all procedures for a practitioner
|
|
@@ -8857,7 +8870,7 @@ var ProcedureService = class extends BaseService {
|
|
|
8857
8870
|
(0, import_firestore27.where)("isActive", "==", true)
|
|
8858
8871
|
);
|
|
8859
8872
|
const snapshot = await (0, import_firestore27.getDocs)(q);
|
|
8860
|
-
return snapshot.docs.map((
|
|
8873
|
+
return snapshot.docs.map((doc35) => doc35.data());
|
|
8861
8874
|
}
|
|
8862
8875
|
/**
|
|
8863
8876
|
* Updates a procedure
|
|
@@ -9048,20 +9061,20 @@ var ProcedureService = class extends BaseService {
|
|
|
9048
9061
|
const proceduresCollection = (0, import_firestore27.collection)(this.db, PROCEDURES_COLLECTION);
|
|
9049
9062
|
let proceduresQuery = (0, import_firestore27.query)(proceduresCollection);
|
|
9050
9063
|
if (pagination && pagination > 0) {
|
|
9051
|
-
const { limit:
|
|
9064
|
+
const { limit: limit15, startAfter: startAfter13 } = await import("firebase/firestore");
|
|
9052
9065
|
if (lastDoc) {
|
|
9053
9066
|
proceduresQuery = (0, import_firestore27.query)(
|
|
9054
9067
|
proceduresCollection,
|
|
9055
9068
|
(0, import_firestore27.orderBy)("name"),
|
|
9056
9069
|
// Use imported orderBy
|
|
9057
9070
|
startAfter13(lastDoc),
|
|
9058
|
-
|
|
9071
|
+
limit15(pagination)
|
|
9059
9072
|
);
|
|
9060
9073
|
} else {
|
|
9061
9074
|
proceduresQuery = (0, import_firestore27.query)(
|
|
9062
9075
|
proceduresCollection,
|
|
9063
9076
|
(0, import_firestore27.orderBy)("name"),
|
|
9064
|
-
|
|
9077
|
+
limit15(pagination)
|
|
9065
9078
|
);
|
|
9066
9079
|
}
|
|
9067
9080
|
} else {
|
|
@@ -9069,11 +9082,11 @@ var ProcedureService = class extends BaseService {
|
|
|
9069
9082
|
}
|
|
9070
9083
|
const proceduresSnapshot = await (0, import_firestore27.getDocs)(proceduresQuery);
|
|
9071
9084
|
const lastVisible = proceduresSnapshot.docs[proceduresSnapshot.docs.length - 1];
|
|
9072
|
-
const procedures = proceduresSnapshot.docs.map((
|
|
9073
|
-
const data =
|
|
9085
|
+
const procedures = proceduresSnapshot.docs.map((doc35) => {
|
|
9086
|
+
const data = doc35.data();
|
|
9074
9087
|
return {
|
|
9075
9088
|
...data,
|
|
9076
|
-
id:
|
|
9089
|
+
id: doc35.id
|
|
9077
9090
|
// Ensure ID is present
|
|
9078
9091
|
};
|
|
9079
9092
|
});
|
|
@@ -9155,8 +9168,8 @@ var ProcedureService = class extends BaseService {
|
|
|
9155
9168
|
console.log(
|
|
9156
9169
|
`[PROCEDURE_SERVICE] Found ${querySnapshot.docs.length} procedures in geo bound`
|
|
9157
9170
|
);
|
|
9158
|
-
for (const
|
|
9159
|
-
const procedure = { ...
|
|
9171
|
+
for (const doc35 of querySnapshot.docs) {
|
|
9172
|
+
const procedure = { ...doc35.data(), id: doc35.id };
|
|
9160
9173
|
const distance = (0, import_geofire_common8.distanceBetween)(
|
|
9161
9174
|
[center.latitude, center.longitude],
|
|
9162
9175
|
[
|
|
@@ -9207,8 +9220,8 @@ var ProcedureService = class extends BaseService {
|
|
|
9207
9220
|
console.log(
|
|
9208
9221
|
`[PROCEDURE_SERVICE] Found ${querySnapshot.docs.length} procedures with regular query`
|
|
9209
9222
|
);
|
|
9210
|
-
const procedures = querySnapshot.docs.map((
|
|
9211
|
-
return { ...
|
|
9223
|
+
const procedures = querySnapshot.docs.map((doc35) => {
|
|
9224
|
+
return { ...doc35.data(), id: doc35.id };
|
|
9212
9225
|
});
|
|
9213
9226
|
if (filters.location) {
|
|
9214
9227
|
const center = filters.location;
|
|
@@ -9314,12 +9327,403 @@ var ProcedureService = class extends BaseService {
|
|
|
9314
9327
|
}
|
|
9315
9328
|
};
|
|
9316
9329
|
|
|
9317
|
-
// src/services/
|
|
9330
|
+
// src/services/clinic/practitioner-invite.service.ts
|
|
9318
9331
|
var import_firestore28 = require("firebase/firestore");
|
|
9332
|
+
var PractitionerInviteService = class extends BaseService {
|
|
9333
|
+
constructor(db, auth, app) {
|
|
9334
|
+
super(db, auth, app);
|
|
9335
|
+
}
|
|
9336
|
+
/**
|
|
9337
|
+
* Creates a new practitioner invite
|
|
9338
|
+
* @param practitionerId - Practitioner ID
|
|
9339
|
+
* @param clinicId - Clinic ID
|
|
9340
|
+
* @param proposedWorkingHours - Proposed working hours
|
|
9341
|
+
* @param invitedBy - Admin ID who creates the invite
|
|
9342
|
+
* @param message - Optional message
|
|
9343
|
+
* @returns Created invite
|
|
9344
|
+
*/
|
|
9345
|
+
async createInviteAdmin(practitionerId, clinicId, proposedWorkingHours, invitedBy, message) {
|
|
9346
|
+
try {
|
|
9347
|
+
const inviteId = this.generateId();
|
|
9348
|
+
const [practitioner, clinic] = await Promise.all([
|
|
9349
|
+
this.getPractitionerById(practitionerId),
|
|
9350
|
+
this.getClinicById(clinicId)
|
|
9351
|
+
]);
|
|
9352
|
+
if (!practitioner) {
|
|
9353
|
+
throw new Error(`Practitioner with ID ${practitionerId} not found`);
|
|
9354
|
+
}
|
|
9355
|
+
if (!clinic) {
|
|
9356
|
+
throw new Error(`Clinic with ID ${clinicId} not found`);
|
|
9357
|
+
}
|
|
9358
|
+
const existingInvite = await this.findExistingInvite(
|
|
9359
|
+
practitionerId,
|
|
9360
|
+
clinicId
|
|
9361
|
+
);
|
|
9362
|
+
if (existingInvite && existingInvite.status === "pending" /* PENDING */) {
|
|
9363
|
+
throw new Error(
|
|
9364
|
+
"There's already a pending invite for this practitioner at this clinic"
|
|
9365
|
+
);
|
|
9366
|
+
}
|
|
9367
|
+
const practitionerInfo = {
|
|
9368
|
+
id: practitioner.id,
|
|
9369
|
+
practitionerPhoto: typeof practitioner.basicInfo.profileImageUrl === "string" ? practitioner.basicInfo.profileImageUrl : null,
|
|
9370
|
+
name: `${practitioner.basicInfo.firstName} ${practitioner.basicInfo.lastName}`,
|
|
9371
|
+
email: practitioner.basicInfo.email,
|
|
9372
|
+
phone: practitioner.basicInfo.phoneNumber || null,
|
|
9373
|
+
certification: practitioner.certification
|
|
9374
|
+
};
|
|
9375
|
+
const clinicInfo = {
|
|
9376
|
+
id: clinic.id,
|
|
9377
|
+
featuredPhoto: typeof clinic.coverPhoto === "string" ? clinic.coverPhoto : "",
|
|
9378
|
+
name: clinic.name,
|
|
9379
|
+
description: clinic.description || null,
|
|
9380
|
+
location: clinic.location,
|
|
9381
|
+
contactInfo: clinic.contactInfo
|
|
9382
|
+
};
|
|
9383
|
+
const inviteData = {
|
|
9384
|
+
practitionerId,
|
|
9385
|
+
clinicId,
|
|
9386
|
+
practitionerInfo,
|
|
9387
|
+
clinicInfo,
|
|
9388
|
+
proposedWorkingHours,
|
|
9389
|
+
invitedBy,
|
|
9390
|
+
message: message || null,
|
|
9391
|
+
status: "pending" /* PENDING */
|
|
9392
|
+
};
|
|
9393
|
+
const now = import_firestore28.Timestamp.now();
|
|
9394
|
+
const invite = {
|
|
9395
|
+
id: inviteId,
|
|
9396
|
+
...inviteData,
|
|
9397
|
+
status: "pending" /* PENDING */,
|
|
9398
|
+
createdAt: now,
|
|
9399
|
+
updatedAt: now,
|
|
9400
|
+
acceptedAt: null,
|
|
9401
|
+
rejectedAt: null,
|
|
9402
|
+
cancelledAt: null
|
|
9403
|
+
};
|
|
9404
|
+
const docRef = (0, import_firestore28.doc)(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
9405
|
+
await (0, import_firestore28.setDoc)(docRef, invite);
|
|
9406
|
+
return invite;
|
|
9407
|
+
} catch (error) {
|
|
9408
|
+
console.error(
|
|
9409
|
+
"[PractitionerInviteService] Error creating invite:",
|
|
9410
|
+
error
|
|
9411
|
+
);
|
|
9412
|
+
throw error;
|
|
9413
|
+
}
|
|
9414
|
+
}
|
|
9415
|
+
/**
|
|
9416
|
+
* Gets all invites for a specific doctor/practitioner
|
|
9417
|
+
* @param practitionerId - Practitioner ID
|
|
9418
|
+
* @param statusFilter - Optional status filter
|
|
9419
|
+
* @returns Array of invites
|
|
9420
|
+
*/
|
|
9421
|
+
async getAllInvitesDoctor(practitionerId, statusFilter) {
|
|
9422
|
+
try {
|
|
9423
|
+
const constraints = [
|
|
9424
|
+
(0, import_firestore28.where)("practitionerId", "==", practitionerId),
|
|
9425
|
+
(0, import_firestore28.orderBy)("createdAt", "desc")
|
|
9426
|
+
];
|
|
9427
|
+
if (statusFilter && statusFilter.length > 0) {
|
|
9428
|
+
constraints.push((0, import_firestore28.where)("status", "in", statusFilter));
|
|
9429
|
+
}
|
|
9430
|
+
const q = (0, import_firestore28.query)(
|
|
9431
|
+
(0, import_firestore28.collection)(this.db, PRACTITIONER_INVITES_COLLECTION),
|
|
9432
|
+
...constraints
|
|
9433
|
+
);
|
|
9434
|
+
const querySnapshot = await (0, import_firestore28.getDocs)(q);
|
|
9435
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
9436
|
+
} catch (error) {
|
|
9437
|
+
console.error(
|
|
9438
|
+
"[PractitionerInviteService] Error getting doctor invites:",
|
|
9439
|
+
error
|
|
9440
|
+
);
|
|
9441
|
+
throw error;
|
|
9442
|
+
}
|
|
9443
|
+
}
|
|
9444
|
+
/**
|
|
9445
|
+
* Gets all invites for a specific clinic
|
|
9446
|
+
* @param clinicId - Clinic ID
|
|
9447
|
+
* @param statusFilter - Optional status filter
|
|
9448
|
+
* @returns Array of invites
|
|
9449
|
+
*/
|
|
9450
|
+
async getAllInvitesClinic(clinicId, statusFilter) {
|
|
9451
|
+
try {
|
|
9452
|
+
const constraints = [
|
|
9453
|
+
(0, import_firestore28.where)("clinicId", "==", clinicId),
|
|
9454
|
+
(0, import_firestore28.orderBy)("createdAt", "desc")
|
|
9455
|
+
];
|
|
9456
|
+
if (statusFilter && statusFilter.length > 0) {
|
|
9457
|
+
constraints.push((0, import_firestore28.where)("status", "in", statusFilter));
|
|
9458
|
+
}
|
|
9459
|
+
const q = (0, import_firestore28.query)(
|
|
9460
|
+
(0, import_firestore28.collection)(this.db, PRACTITIONER_INVITES_COLLECTION),
|
|
9461
|
+
...constraints
|
|
9462
|
+
);
|
|
9463
|
+
const querySnapshot = await (0, import_firestore28.getDocs)(q);
|
|
9464
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
9465
|
+
} catch (error) {
|
|
9466
|
+
console.error(
|
|
9467
|
+
"[PractitionerInviteService] Error getting clinic invites:",
|
|
9468
|
+
error
|
|
9469
|
+
);
|
|
9470
|
+
throw error;
|
|
9471
|
+
}
|
|
9472
|
+
}
|
|
9473
|
+
/**
|
|
9474
|
+
* Doctor accepts an invite
|
|
9475
|
+
* @param inviteId - Invite ID
|
|
9476
|
+
* @returns Updated invite
|
|
9477
|
+
*/
|
|
9478
|
+
async acceptInviteDoctor(inviteId) {
|
|
9479
|
+
try {
|
|
9480
|
+
const invite = await this.getInviteById(inviteId);
|
|
9481
|
+
if (!invite) {
|
|
9482
|
+
throw new Error(`Invite with ID ${inviteId} not found`);
|
|
9483
|
+
}
|
|
9484
|
+
if (invite.status !== "pending" /* PENDING */) {
|
|
9485
|
+
throw new Error("Only pending invites can be accepted");
|
|
9486
|
+
}
|
|
9487
|
+
const updateData = {
|
|
9488
|
+
status: "accepted" /* ACCEPTED */,
|
|
9489
|
+
acceptedAt: import_firestore28.Timestamp.now(),
|
|
9490
|
+
updatedAt: (0, import_firestore28.serverTimestamp)()
|
|
9491
|
+
};
|
|
9492
|
+
const docRef = (0, import_firestore28.doc)(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
9493
|
+
await (0, import_firestore28.updateDoc)(docRef, updateData);
|
|
9494
|
+
return await this.getInviteById(inviteId);
|
|
9495
|
+
} catch (error) {
|
|
9496
|
+
console.error(
|
|
9497
|
+
"[PractitionerInviteService] Error accepting invite:",
|
|
9498
|
+
error
|
|
9499
|
+
);
|
|
9500
|
+
throw error;
|
|
9501
|
+
}
|
|
9502
|
+
}
|
|
9503
|
+
/**
|
|
9504
|
+
* Doctor rejects an invite
|
|
9505
|
+
* @param inviteId - Invite ID
|
|
9506
|
+
* @param rejectionReason - Optional reason for rejection
|
|
9507
|
+
* @returns Updated invite
|
|
9508
|
+
*/
|
|
9509
|
+
async rejectInviteDoctor(inviteId, rejectionReason) {
|
|
9510
|
+
try {
|
|
9511
|
+
const invite = await this.getInviteById(inviteId);
|
|
9512
|
+
if (!invite) {
|
|
9513
|
+
throw new Error(`Invite with ID ${inviteId} not found`);
|
|
9514
|
+
}
|
|
9515
|
+
if (invite.status !== "pending" /* PENDING */) {
|
|
9516
|
+
throw new Error("Only pending invites can be rejected");
|
|
9517
|
+
}
|
|
9518
|
+
const updateData = {
|
|
9519
|
+
status: "rejected" /* REJECTED */,
|
|
9520
|
+
rejectionReason: rejectionReason || null,
|
|
9521
|
+
rejectedAt: import_firestore28.Timestamp.now(),
|
|
9522
|
+
updatedAt: (0, import_firestore28.serverTimestamp)()
|
|
9523
|
+
};
|
|
9524
|
+
const docRef = (0, import_firestore28.doc)(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
9525
|
+
await (0, import_firestore28.updateDoc)(docRef, updateData);
|
|
9526
|
+
return await this.getInviteById(inviteId);
|
|
9527
|
+
} catch (error) {
|
|
9528
|
+
console.error(
|
|
9529
|
+
"[PractitionerInviteService] Error rejecting invite:",
|
|
9530
|
+
error
|
|
9531
|
+
);
|
|
9532
|
+
throw error;
|
|
9533
|
+
}
|
|
9534
|
+
}
|
|
9535
|
+
/**
|
|
9536
|
+
* Admin cancels an invite
|
|
9537
|
+
* @param inviteId - Invite ID
|
|
9538
|
+
* @param cancelReason - Optional reason for cancellation
|
|
9539
|
+
* @returns Updated invite
|
|
9540
|
+
*/
|
|
9541
|
+
async cancelInviteAdmin(inviteId, cancelReason) {
|
|
9542
|
+
try {
|
|
9543
|
+
const invite = await this.getInviteById(inviteId);
|
|
9544
|
+
if (!invite) {
|
|
9545
|
+
throw new Error(`Invite with ID ${inviteId} not found`);
|
|
9546
|
+
}
|
|
9547
|
+
if (invite.status !== "pending" /* PENDING */) {
|
|
9548
|
+
throw new Error("Only pending invites can be cancelled");
|
|
9549
|
+
}
|
|
9550
|
+
const updateData = {
|
|
9551
|
+
status: "cancelled" /* CANCELLED */,
|
|
9552
|
+
cancelReason: cancelReason || null,
|
|
9553
|
+
cancelledAt: import_firestore28.Timestamp.now(),
|
|
9554
|
+
updatedAt: (0, import_firestore28.serverTimestamp)()
|
|
9555
|
+
};
|
|
9556
|
+
const docRef = (0, import_firestore28.doc)(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
9557
|
+
await (0, import_firestore28.updateDoc)(docRef, updateData);
|
|
9558
|
+
return await this.getInviteById(inviteId);
|
|
9559
|
+
} catch (error) {
|
|
9560
|
+
console.error(
|
|
9561
|
+
"[PractitionerInviteService] Error cancelling invite:",
|
|
9562
|
+
error
|
|
9563
|
+
);
|
|
9564
|
+
throw error;
|
|
9565
|
+
}
|
|
9566
|
+
}
|
|
9567
|
+
/**
|
|
9568
|
+
* Gets an invite by ID
|
|
9569
|
+
* @param inviteId - Invite ID
|
|
9570
|
+
* @returns Invite or null if not found
|
|
9571
|
+
*/
|
|
9572
|
+
async getInviteById(inviteId) {
|
|
9573
|
+
try {
|
|
9574
|
+
const docRef = (0, import_firestore28.doc)(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
9575
|
+
const docSnap = await (0, import_firestore28.getDoc)(docRef);
|
|
9576
|
+
if (docSnap.exists()) {
|
|
9577
|
+
return docSnap.data();
|
|
9578
|
+
}
|
|
9579
|
+
return null;
|
|
9580
|
+
} catch (error) {
|
|
9581
|
+
console.error(
|
|
9582
|
+
"[PractitionerInviteService] Error getting invite by ID:",
|
|
9583
|
+
error
|
|
9584
|
+
);
|
|
9585
|
+
throw error;
|
|
9586
|
+
}
|
|
9587
|
+
}
|
|
9588
|
+
/**
|
|
9589
|
+
* Gets invites with advanced filtering options
|
|
9590
|
+
* @param filters - Filter options
|
|
9591
|
+
* @returns Array of filtered invites
|
|
9592
|
+
*/
|
|
9593
|
+
async getInvitesWithFilters(filters) {
|
|
9594
|
+
try {
|
|
9595
|
+
const constraints = [];
|
|
9596
|
+
if (filters.practitionerId) {
|
|
9597
|
+
constraints.push((0, import_firestore28.where)("practitionerId", "==", filters.practitionerId));
|
|
9598
|
+
}
|
|
9599
|
+
if (filters.clinicId) {
|
|
9600
|
+
constraints.push((0, import_firestore28.where)("clinicId", "==", filters.clinicId));
|
|
9601
|
+
}
|
|
9602
|
+
if (filters.invitedBy) {
|
|
9603
|
+
constraints.push((0, import_firestore28.where)("invitedBy", "==", filters.invitedBy));
|
|
9604
|
+
}
|
|
9605
|
+
if (filters.status && filters.status.length > 0) {
|
|
9606
|
+
constraints.push((0, import_firestore28.where)("status", "in", filters.status));
|
|
9607
|
+
}
|
|
9608
|
+
const orderField = filters.orderBy || "createdAt";
|
|
9609
|
+
const orderDirection = filters.orderDirection || "desc";
|
|
9610
|
+
constraints.push((0, import_firestore28.orderBy)(orderField, orderDirection));
|
|
9611
|
+
if (filters.limit) {
|
|
9612
|
+
constraints.push((0, import_firestore28.limit)(filters.limit));
|
|
9613
|
+
}
|
|
9614
|
+
const q = (0, import_firestore28.query)(
|
|
9615
|
+
(0, import_firestore28.collection)(this.db, PRACTITIONER_INVITES_COLLECTION),
|
|
9616
|
+
...constraints
|
|
9617
|
+
);
|
|
9618
|
+
const querySnapshot = await (0, import_firestore28.getDocs)(q);
|
|
9619
|
+
let invites = querySnapshot.docs.map(
|
|
9620
|
+
(doc35) => doc35.data()
|
|
9621
|
+
);
|
|
9622
|
+
if (filters.fromDate) {
|
|
9623
|
+
invites = invites.filter(
|
|
9624
|
+
(invite) => invite.createdAt >= filters.fromDate
|
|
9625
|
+
);
|
|
9626
|
+
}
|
|
9627
|
+
if (filters.toDate) {
|
|
9628
|
+
invites = invites.filter(
|
|
9629
|
+
(invite) => invite.createdAt <= filters.toDate
|
|
9630
|
+
);
|
|
9631
|
+
}
|
|
9632
|
+
return invites;
|
|
9633
|
+
} catch (error) {
|
|
9634
|
+
console.error(
|
|
9635
|
+
"[PractitionerInviteService] Error getting invites with filters:",
|
|
9636
|
+
error
|
|
9637
|
+
);
|
|
9638
|
+
throw error;
|
|
9639
|
+
}
|
|
9640
|
+
}
|
|
9641
|
+
/**
|
|
9642
|
+
* Deletes an invite (admin only)
|
|
9643
|
+
* @param inviteId - Invite ID
|
|
9644
|
+
*/
|
|
9645
|
+
async deleteInvite(inviteId) {
|
|
9646
|
+
try {
|
|
9647
|
+
const docRef = (0, import_firestore28.doc)(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
9648
|
+
await (0, import_firestore28.deleteDoc)(docRef);
|
|
9649
|
+
} catch (error) {
|
|
9650
|
+
console.error(
|
|
9651
|
+
"[PractitionerInviteService] Error deleting invite:",
|
|
9652
|
+
error
|
|
9653
|
+
);
|
|
9654
|
+
throw error;
|
|
9655
|
+
}
|
|
9656
|
+
}
|
|
9657
|
+
// Private helper methods
|
|
9658
|
+
/**
|
|
9659
|
+
* Gets practitioner by ID
|
|
9660
|
+
* @param practitionerId - Practitioner ID
|
|
9661
|
+
* @returns Practitioner or null
|
|
9662
|
+
*/
|
|
9663
|
+
async getPractitionerById(practitionerId) {
|
|
9664
|
+
try {
|
|
9665
|
+
const docRef = (0, import_firestore28.doc)(this.db, PRACTITIONERS_COLLECTION, practitionerId);
|
|
9666
|
+
const docSnap = await (0, import_firestore28.getDoc)(docRef);
|
|
9667
|
+
return docSnap.exists() ? docSnap.data() : null;
|
|
9668
|
+
} catch (error) {
|
|
9669
|
+
console.error(
|
|
9670
|
+
"[PractitionerInviteService] Error getting practitioner:",
|
|
9671
|
+
error
|
|
9672
|
+
);
|
|
9673
|
+
return null;
|
|
9674
|
+
}
|
|
9675
|
+
}
|
|
9676
|
+
/**
|
|
9677
|
+
* Gets clinic by ID
|
|
9678
|
+
* @param clinicId - Clinic ID
|
|
9679
|
+
* @returns Clinic or null
|
|
9680
|
+
*/
|
|
9681
|
+
async getClinicById(clinicId) {
|
|
9682
|
+
try {
|
|
9683
|
+
const docRef = (0, import_firestore28.doc)(this.db, CLINICS_COLLECTION, clinicId);
|
|
9684
|
+
const docSnap = await (0, import_firestore28.getDoc)(docRef);
|
|
9685
|
+
return docSnap.exists() ? docSnap.data() : null;
|
|
9686
|
+
} catch (error) {
|
|
9687
|
+
console.error("[PractitionerInviteService] Error getting clinic:", error);
|
|
9688
|
+
return null;
|
|
9689
|
+
}
|
|
9690
|
+
}
|
|
9691
|
+
/**
|
|
9692
|
+
* Finds existing invite between practitioner and clinic
|
|
9693
|
+
* @param practitionerId - Practitioner ID
|
|
9694
|
+
* @param clinicId - Clinic ID
|
|
9695
|
+
* @returns Existing invite or null
|
|
9696
|
+
*/
|
|
9697
|
+
async findExistingInvite(practitionerId, clinicId) {
|
|
9698
|
+
try {
|
|
9699
|
+
const q = (0, import_firestore28.query)(
|
|
9700
|
+
(0, import_firestore28.collection)(this.db, PRACTITIONER_INVITES_COLLECTION),
|
|
9701
|
+
(0, import_firestore28.where)("practitionerId", "==", practitionerId),
|
|
9702
|
+
(0, import_firestore28.where)("clinicId", "==", clinicId),
|
|
9703
|
+
(0, import_firestore28.orderBy)("createdAt", "desc"),
|
|
9704
|
+
(0, import_firestore28.limit)(1)
|
|
9705
|
+
);
|
|
9706
|
+
const querySnapshot = await (0, import_firestore28.getDocs)(q);
|
|
9707
|
+
if (querySnapshot.empty) {
|
|
9708
|
+
return null;
|
|
9709
|
+
}
|
|
9710
|
+
return querySnapshot.docs[0].data();
|
|
9711
|
+
} catch (error) {
|
|
9712
|
+
console.error(
|
|
9713
|
+
"[PractitionerInviteService] Error finding existing invite:",
|
|
9714
|
+
error
|
|
9715
|
+
);
|
|
9716
|
+
return null;
|
|
9717
|
+
}
|
|
9718
|
+
}
|
|
9719
|
+
};
|
|
9720
|
+
|
|
9721
|
+
// src/services/documentation-templates/documentation-template.service.ts
|
|
9722
|
+
var import_firestore29 = require("firebase/firestore");
|
|
9319
9723
|
var DocumentationTemplateService = class extends BaseService {
|
|
9320
9724
|
constructor() {
|
|
9321
9725
|
super(...arguments);
|
|
9322
|
-
this.collectionRef = (0,
|
|
9726
|
+
this.collectionRef = (0, import_firestore29.collection)(
|
|
9323
9727
|
this.db,
|
|
9324
9728
|
DOCUMENTATION_TEMPLATES_COLLECTION
|
|
9325
9729
|
);
|
|
@@ -9353,8 +9757,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9353
9757
|
isRequired: validatedData.isRequired || false,
|
|
9354
9758
|
sortingOrder: validatedData.sortingOrder || 0
|
|
9355
9759
|
};
|
|
9356
|
-
const docRef = (0,
|
|
9357
|
-
await (0,
|
|
9760
|
+
const docRef = (0, import_firestore29.doc)(this.collectionRef, templateId);
|
|
9761
|
+
await (0, import_firestore29.setDoc)(docRef, template);
|
|
9358
9762
|
return template;
|
|
9359
9763
|
}
|
|
9360
9764
|
/**
|
|
@@ -9364,8 +9768,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9364
9768
|
* @returns The template or null if not found
|
|
9365
9769
|
*/
|
|
9366
9770
|
async getTemplateById(templateId, version) {
|
|
9367
|
-
const docRef = (0,
|
|
9368
|
-
const docSnap = await (0,
|
|
9771
|
+
const docRef = (0, import_firestore29.doc)(this.collectionRef, templateId);
|
|
9772
|
+
const docSnap = await (0, import_firestore29.getDoc)(docRef);
|
|
9369
9773
|
if (!docSnap.exists()) {
|
|
9370
9774
|
return null;
|
|
9371
9775
|
}
|
|
@@ -9403,15 +9807,15 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9403
9807
|
if (!template) {
|
|
9404
9808
|
throw new Error(`Template with ID ${templateId} not found`);
|
|
9405
9809
|
}
|
|
9406
|
-
const versionsCollectionRef = (0,
|
|
9810
|
+
const versionsCollectionRef = (0, import_firestore29.collection)(
|
|
9407
9811
|
this.db,
|
|
9408
9812
|
`${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
|
|
9409
9813
|
);
|
|
9410
|
-
const versionDocRef = (0,
|
|
9814
|
+
const versionDocRef = (0, import_firestore29.doc)(
|
|
9411
9815
|
versionsCollectionRef,
|
|
9412
9816
|
template.version.toString()
|
|
9413
9817
|
);
|
|
9414
|
-
await (0,
|
|
9818
|
+
await (0, import_firestore29.setDoc)(versionDocRef, template);
|
|
9415
9819
|
let updatedElements = template.elements;
|
|
9416
9820
|
if (validatedData.elements) {
|
|
9417
9821
|
updatedElements = validatedData.elements.map((element) => ({
|
|
@@ -9435,9 +9839,9 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9435
9839
|
updatePayload.isUserForm = (_a = validatedData.isUserForm) != null ? _a : false;
|
|
9436
9840
|
updatePayload.isRequired = (_b = validatedData.isRequired) != null ? _b : false;
|
|
9437
9841
|
updatePayload.sortingOrder = (_c = validatedData.sortingOrder) != null ? _c : 0;
|
|
9438
|
-
const docRef = (0,
|
|
9842
|
+
const docRef = (0, import_firestore29.doc)(this.collectionRef, templateId);
|
|
9439
9843
|
console.log("Update payload", updatePayload);
|
|
9440
|
-
await (0,
|
|
9844
|
+
await (0, import_firestore29.updateDoc)(docRef, updatePayload);
|
|
9441
9845
|
return { ...template, ...updatePayload };
|
|
9442
9846
|
}
|
|
9443
9847
|
/**
|
|
@@ -9447,11 +9851,11 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9447
9851
|
* @returns The template version or null if not found
|
|
9448
9852
|
*/
|
|
9449
9853
|
async getTemplateVersion(templateId, versionNumber) {
|
|
9450
|
-
const versionDocRef = (0,
|
|
9854
|
+
const versionDocRef = (0, import_firestore29.doc)(
|
|
9451
9855
|
this.db,
|
|
9452
9856
|
`${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions/${versionNumber}`
|
|
9453
9857
|
);
|
|
9454
|
-
const versionDocSnap = await (0,
|
|
9858
|
+
const versionDocSnap = await (0, import_firestore29.getDoc)(versionDocRef);
|
|
9455
9859
|
if (!versionDocSnap.exists()) {
|
|
9456
9860
|
return null;
|
|
9457
9861
|
}
|
|
@@ -9463,15 +9867,15 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9463
9867
|
* @returns Array of template versions
|
|
9464
9868
|
*/
|
|
9465
9869
|
async getTemplateOldVersions(templateId) {
|
|
9466
|
-
const versionsCollectionRef = (0,
|
|
9870
|
+
const versionsCollectionRef = (0, import_firestore29.collection)(
|
|
9467
9871
|
this.db,
|
|
9468
9872
|
`${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
|
|
9469
9873
|
);
|
|
9470
|
-
const q = (0,
|
|
9471
|
-
const querySnapshot = await (0,
|
|
9874
|
+
const q = (0, import_firestore29.query)(versionsCollectionRef, (0, import_firestore29.orderBy)("version", "desc"));
|
|
9875
|
+
const querySnapshot = await (0, import_firestore29.getDocs)(q);
|
|
9472
9876
|
const versions = [];
|
|
9473
|
-
querySnapshot.forEach((
|
|
9474
|
-
versions.push(
|
|
9877
|
+
querySnapshot.forEach((doc35) => {
|
|
9878
|
+
versions.push(doc35.data());
|
|
9475
9879
|
});
|
|
9476
9880
|
return versions;
|
|
9477
9881
|
}
|
|
@@ -9480,8 +9884,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9480
9884
|
* @param templateId - ID of the template to delete
|
|
9481
9885
|
*/
|
|
9482
9886
|
async deleteTemplate(templateId) {
|
|
9483
|
-
const docRef = (0,
|
|
9484
|
-
await (0,
|
|
9887
|
+
const docRef = (0, import_firestore29.doc)(this.collectionRef, templateId);
|
|
9888
|
+
await (0, import_firestore29.deleteDoc)(docRef);
|
|
9485
9889
|
}
|
|
9486
9890
|
/**
|
|
9487
9891
|
* Get all active templates
|
|
@@ -9490,21 +9894,21 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9490
9894
|
* @returns Array of templates and the last document for pagination
|
|
9491
9895
|
*/
|
|
9492
9896
|
async getActiveTemplates(pageSize = 20, lastDoc) {
|
|
9493
|
-
let q = (0,
|
|
9897
|
+
let q = (0, import_firestore29.query)(
|
|
9494
9898
|
this.collectionRef,
|
|
9495
|
-
(0,
|
|
9496
|
-
(0,
|
|
9497
|
-
(0,
|
|
9899
|
+
(0, import_firestore29.where)("isActive", "==", true),
|
|
9900
|
+
(0, import_firestore29.orderBy)("updatedAt", "desc"),
|
|
9901
|
+
(0, import_firestore29.limit)(pageSize)
|
|
9498
9902
|
);
|
|
9499
9903
|
if (lastDoc) {
|
|
9500
|
-
q = (0,
|
|
9904
|
+
q = (0, import_firestore29.query)(q, (0, import_firestore29.startAfter)(lastDoc));
|
|
9501
9905
|
}
|
|
9502
|
-
const querySnapshot = await (0,
|
|
9906
|
+
const querySnapshot = await (0, import_firestore29.getDocs)(q);
|
|
9503
9907
|
const templates = [];
|
|
9504
9908
|
let lastVisible = null;
|
|
9505
|
-
querySnapshot.forEach((
|
|
9506
|
-
templates.push(
|
|
9507
|
-
lastVisible =
|
|
9909
|
+
querySnapshot.forEach((doc35) => {
|
|
9910
|
+
templates.push(doc35.data());
|
|
9911
|
+
lastVisible = doc35;
|
|
9508
9912
|
});
|
|
9509
9913
|
return {
|
|
9510
9914
|
templates,
|
|
@@ -9519,22 +9923,22 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9519
9923
|
* @returns Array of templates and the last document for pagination
|
|
9520
9924
|
*/
|
|
9521
9925
|
async getTemplatesByTags(tags, pageSize = 20, lastDoc) {
|
|
9522
|
-
let q = (0,
|
|
9926
|
+
let q = (0, import_firestore29.query)(
|
|
9523
9927
|
this.collectionRef,
|
|
9524
|
-
(0,
|
|
9525
|
-
(0,
|
|
9526
|
-
(0,
|
|
9527
|
-
(0,
|
|
9928
|
+
(0, import_firestore29.where)("isActive", "==", true),
|
|
9929
|
+
(0, import_firestore29.where)("tags", "array-contains-any", tags),
|
|
9930
|
+
(0, import_firestore29.orderBy)("updatedAt", "desc"),
|
|
9931
|
+
(0, import_firestore29.limit)(pageSize)
|
|
9528
9932
|
);
|
|
9529
9933
|
if (lastDoc) {
|
|
9530
|
-
q = (0,
|
|
9934
|
+
q = (0, import_firestore29.query)(q, (0, import_firestore29.startAfter)(lastDoc));
|
|
9531
9935
|
}
|
|
9532
|
-
const querySnapshot = await (0,
|
|
9936
|
+
const querySnapshot = await (0, import_firestore29.getDocs)(q);
|
|
9533
9937
|
const templates = [];
|
|
9534
9938
|
let lastVisible = null;
|
|
9535
|
-
querySnapshot.forEach((
|
|
9536
|
-
templates.push(
|
|
9537
|
-
lastVisible =
|
|
9939
|
+
querySnapshot.forEach((doc35) => {
|
|
9940
|
+
templates.push(doc35.data());
|
|
9941
|
+
lastVisible = doc35;
|
|
9538
9942
|
});
|
|
9539
9943
|
return {
|
|
9540
9944
|
templates,
|
|
@@ -9549,21 +9953,21 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9549
9953
|
* @returns Array of templates and the last document for pagination
|
|
9550
9954
|
*/
|
|
9551
9955
|
async getTemplatesByCreator(userId, pageSize = 20, lastDoc) {
|
|
9552
|
-
let q = (0,
|
|
9956
|
+
let q = (0, import_firestore29.query)(
|
|
9553
9957
|
this.collectionRef,
|
|
9554
|
-
(0,
|
|
9555
|
-
(0,
|
|
9556
|
-
(0,
|
|
9958
|
+
(0, import_firestore29.where)("createdBy", "==", userId),
|
|
9959
|
+
(0, import_firestore29.orderBy)("updatedAt", "desc"),
|
|
9960
|
+
(0, import_firestore29.limit)(pageSize)
|
|
9557
9961
|
);
|
|
9558
9962
|
if (lastDoc) {
|
|
9559
|
-
q = (0,
|
|
9963
|
+
q = (0, import_firestore29.query)(q, (0, import_firestore29.startAfter)(lastDoc));
|
|
9560
9964
|
}
|
|
9561
|
-
const querySnapshot = await (0,
|
|
9965
|
+
const querySnapshot = await (0, import_firestore29.getDocs)(q);
|
|
9562
9966
|
const templates = [];
|
|
9563
9967
|
let lastVisible = null;
|
|
9564
|
-
querySnapshot.forEach((
|
|
9565
|
-
templates.push(
|
|
9566
|
-
lastVisible =
|
|
9968
|
+
querySnapshot.forEach((doc35) => {
|
|
9969
|
+
templates.push(doc35.data());
|
|
9970
|
+
lastVisible = doc35;
|
|
9567
9971
|
});
|
|
9568
9972
|
return {
|
|
9569
9973
|
templates,
|
|
@@ -9576,28 +9980,28 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
9576
9980
|
* @returns Array of templates
|
|
9577
9981
|
*/
|
|
9578
9982
|
async getAllTemplatesForSelection(options) {
|
|
9579
|
-
let q = (0,
|
|
9983
|
+
let q = (0, import_firestore29.query)(
|
|
9580
9984
|
this.collectionRef,
|
|
9581
|
-
(0,
|
|
9582
|
-
(0,
|
|
9985
|
+
(0, import_firestore29.where)("isActive", "==", true),
|
|
9986
|
+
(0, import_firestore29.orderBy)("updatedAt", "desc")
|
|
9583
9987
|
);
|
|
9584
9988
|
if ((options == null ? void 0 : options.isUserForm) !== void 0) {
|
|
9585
|
-
q = (0,
|
|
9989
|
+
q = (0, import_firestore29.query)(q, (0, import_firestore29.where)("isUserForm", "==", options.isUserForm));
|
|
9586
9990
|
}
|
|
9587
9991
|
if ((options == null ? void 0 : options.isRequired) !== void 0) {
|
|
9588
|
-
q = (0,
|
|
9992
|
+
q = (0, import_firestore29.query)(q, (0, import_firestore29.where)("isRequired", "==", options.isRequired));
|
|
9589
9993
|
}
|
|
9590
|
-
const querySnapshot = await (0,
|
|
9994
|
+
const querySnapshot = await (0, import_firestore29.getDocs)(q);
|
|
9591
9995
|
const templates = [];
|
|
9592
|
-
querySnapshot.forEach((
|
|
9593
|
-
templates.push(
|
|
9996
|
+
querySnapshot.forEach((doc35) => {
|
|
9997
|
+
templates.push(doc35.data());
|
|
9594
9998
|
});
|
|
9595
9999
|
return templates;
|
|
9596
10000
|
}
|
|
9597
10001
|
};
|
|
9598
10002
|
|
|
9599
10003
|
// src/services/documentation-templates/filled-document.service.ts
|
|
9600
|
-
var
|
|
10004
|
+
var import_firestore30 = require("firebase/firestore");
|
|
9601
10005
|
var FilledDocumentService = class extends BaseService {
|
|
9602
10006
|
constructor(...args) {
|
|
9603
10007
|
super(...args);
|
|
@@ -9652,7 +10056,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9652
10056
|
values: initialValues,
|
|
9653
10057
|
status: initialStatus
|
|
9654
10058
|
};
|
|
9655
|
-
const docRef = (0,
|
|
10059
|
+
const docRef = (0, import_firestore30.doc)(
|
|
9656
10060
|
this.db,
|
|
9657
10061
|
APPOINTMENTS_COLLECTION,
|
|
9658
10062
|
// Replaced "appointments"
|
|
@@ -9660,7 +10064,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9660
10064
|
formSubcollection,
|
|
9661
10065
|
documentId3
|
|
9662
10066
|
);
|
|
9663
|
-
await (0,
|
|
10067
|
+
await (0, import_firestore30.setDoc)(docRef, filledDocument);
|
|
9664
10068
|
return filledDocument;
|
|
9665
10069
|
}
|
|
9666
10070
|
/**
|
|
@@ -9672,7 +10076,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9672
10076
|
*/
|
|
9673
10077
|
async getFilledDocumentFromAppointmentById(appointmentId, formId, isUserForm) {
|
|
9674
10078
|
const formSubcollection = this.getFormSubcollectionPath(isUserForm);
|
|
9675
|
-
const docRef = (0,
|
|
10079
|
+
const docRef = (0, import_firestore30.doc)(
|
|
9676
10080
|
this.db,
|
|
9677
10081
|
APPOINTMENTS_COLLECTION,
|
|
9678
10082
|
// Replaced "appointments"
|
|
@@ -9680,7 +10084,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9680
10084
|
formSubcollection,
|
|
9681
10085
|
formId
|
|
9682
10086
|
);
|
|
9683
|
-
const docSnap = await (0,
|
|
10087
|
+
const docSnap = await (0, import_firestore30.getDoc)(docRef);
|
|
9684
10088
|
if (!docSnap.exists()) {
|
|
9685
10089
|
return null;
|
|
9686
10090
|
}
|
|
@@ -9697,7 +10101,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9697
10101
|
*/
|
|
9698
10102
|
async updateFilledDocumentInAppointment(appointmentId, formId, isUserForm, values, status) {
|
|
9699
10103
|
const formSubcollection = this.getFormSubcollectionPath(isUserForm);
|
|
9700
|
-
const docRef = (0,
|
|
10104
|
+
const docRef = (0, import_firestore30.doc)(
|
|
9701
10105
|
this.db,
|
|
9702
10106
|
APPOINTMENTS_COLLECTION,
|
|
9703
10107
|
// Replaced "appointments"
|
|
@@ -9729,7 +10133,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9729
10133
|
}
|
|
9730
10134
|
if (Object.keys(updatePayload).length === 1 && "updatedAt" in updatePayload) {
|
|
9731
10135
|
}
|
|
9732
|
-
await (0,
|
|
10136
|
+
await (0, import_firestore30.updateDoc)(docRef, updatePayload);
|
|
9733
10137
|
return { ...existingDoc, ...updatePayload };
|
|
9734
10138
|
}
|
|
9735
10139
|
/**
|
|
@@ -9739,20 +10143,20 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9739
10143
|
* @param lastDoc Last document from previous page for pagination.
|
|
9740
10144
|
*/
|
|
9741
10145
|
async getFilledUserFormsForAppointment(appointmentId, pageSize = 20, lastDoc) {
|
|
9742
|
-
const subcollectionRef = (0,
|
|
10146
|
+
const subcollectionRef = (0, import_firestore30.collection)(
|
|
9743
10147
|
this.db,
|
|
9744
10148
|
APPOINTMENTS_COLLECTION,
|
|
9745
10149
|
// Replaced "appointments"
|
|
9746
10150
|
appointmentId,
|
|
9747
10151
|
USER_FORMS_SUBCOLLECTION
|
|
9748
10152
|
);
|
|
9749
|
-
let q = (0,
|
|
10153
|
+
let q = (0, import_firestore30.query)(
|
|
9750
10154
|
subcollectionRef,
|
|
9751
|
-
(0,
|
|
9752
|
-
(0,
|
|
10155
|
+
(0, import_firestore30.orderBy)("updatedAt", "desc"),
|
|
10156
|
+
(0, import_firestore30.limit)(pageSize)
|
|
9753
10157
|
);
|
|
9754
10158
|
if (lastDoc) {
|
|
9755
|
-
q = (0,
|
|
10159
|
+
q = (0, import_firestore30.query)(q, (0, import_firestore30.startAfter)(lastDoc));
|
|
9756
10160
|
}
|
|
9757
10161
|
return this.executeQuery(q);
|
|
9758
10162
|
}
|
|
@@ -9763,31 +10167,31 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9763
10167
|
* @param lastDoc Last document from previous page for pagination.
|
|
9764
10168
|
*/
|
|
9765
10169
|
async getFilledDoctorFormsForAppointment(appointmentId, pageSize = 20, lastDoc) {
|
|
9766
|
-
const subcollectionRef = (0,
|
|
10170
|
+
const subcollectionRef = (0, import_firestore30.collection)(
|
|
9767
10171
|
this.db,
|
|
9768
10172
|
APPOINTMENTS_COLLECTION,
|
|
9769
10173
|
// Replaced "appointments"
|
|
9770
10174
|
appointmentId,
|
|
9771
10175
|
DOCTOR_FORMS_SUBCOLLECTION
|
|
9772
10176
|
);
|
|
9773
|
-
let q = (0,
|
|
10177
|
+
let q = (0, import_firestore30.query)(
|
|
9774
10178
|
subcollectionRef,
|
|
9775
|
-
(0,
|
|
9776
|
-
(0,
|
|
10179
|
+
(0, import_firestore30.orderBy)("updatedAt", "desc"),
|
|
10180
|
+
(0, import_firestore30.limit)(pageSize)
|
|
9777
10181
|
);
|
|
9778
10182
|
if (lastDoc) {
|
|
9779
|
-
q = (0,
|
|
10183
|
+
q = (0, import_firestore30.query)(q, (0, import_firestore30.startAfter)(lastDoc));
|
|
9780
10184
|
}
|
|
9781
10185
|
return this.executeQuery(q);
|
|
9782
10186
|
}
|
|
9783
10187
|
// Helper to execute query and return documents + lastDoc
|
|
9784
10188
|
async executeQuery(q) {
|
|
9785
|
-
const querySnapshot = await (0,
|
|
10189
|
+
const querySnapshot = await (0, import_firestore30.getDocs)(q);
|
|
9786
10190
|
const documents = [];
|
|
9787
10191
|
let lastVisible = null;
|
|
9788
|
-
querySnapshot.forEach((
|
|
9789
|
-
documents.push(
|
|
9790
|
-
lastVisible =
|
|
10192
|
+
querySnapshot.forEach((doc35) => {
|
|
10193
|
+
documents.push(doc35.data());
|
|
10194
|
+
lastVisible = doc35;
|
|
9791
10195
|
});
|
|
9792
10196
|
return {
|
|
9793
10197
|
documents,
|
|
@@ -9946,7 +10350,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9946
10350
|
};
|
|
9947
10351
|
|
|
9948
10352
|
// src/services/calendar/calendar-refactored.service.ts
|
|
9949
|
-
var
|
|
10353
|
+
var import_firestore40 = require("firebase/firestore");
|
|
9950
10354
|
|
|
9951
10355
|
// src/types/calendar/synced-calendar.types.ts
|
|
9952
10356
|
var SyncedCalendarProvider = /* @__PURE__ */ ((SyncedCalendarProvider3) => {
|
|
@@ -9958,15 +10362,15 @@ var SyncedCalendarProvider = /* @__PURE__ */ ((SyncedCalendarProvider3) => {
|
|
|
9958
10362
|
var SYNCED_CALENDARS_COLLECTION = "syncedCalendars";
|
|
9959
10363
|
|
|
9960
10364
|
// src/services/calendar/calendar-refactored.service.ts
|
|
9961
|
-
var
|
|
10365
|
+
var import_firestore41 = require("firebase/firestore");
|
|
9962
10366
|
|
|
9963
10367
|
// src/validations/calendar.schema.ts
|
|
9964
10368
|
var import_zod23 = require("zod");
|
|
9965
|
-
var
|
|
10369
|
+
var import_firestore32 = require("firebase/firestore");
|
|
9966
10370
|
|
|
9967
10371
|
// src/validations/profile-info.schema.ts
|
|
9968
10372
|
var import_zod22 = require("zod");
|
|
9969
|
-
var
|
|
10373
|
+
var import_firestore31 = require("firebase/firestore");
|
|
9970
10374
|
var clinicInfoSchema2 = import_zod22.z.object({
|
|
9971
10375
|
id: import_zod22.z.string(),
|
|
9972
10376
|
featuredPhoto: import_zod22.z.string(),
|
|
@@ -9988,19 +10392,19 @@ var patientProfileInfoSchema = import_zod22.z.object({
|
|
|
9988
10392
|
fullName: import_zod22.z.string(),
|
|
9989
10393
|
email: import_zod22.z.string().email(),
|
|
9990
10394
|
phone: import_zod22.z.string().nullable(),
|
|
9991
|
-
dateOfBirth: import_zod22.z.instanceof(
|
|
10395
|
+
dateOfBirth: import_zod22.z.instanceof(import_firestore31.Timestamp),
|
|
9992
10396
|
gender: import_zod22.z.nativeEnum(Gender)
|
|
9993
10397
|
});
|
|
9994
10398
|
|
|
9995
10399
|
// src/validations/calendar.schema.ts
|
|
9996
10400
|
var MIN_APPOINTMENT_DURATION = 15;
|
|
9997
10401
|
var calendarEventTimeSchema = import_zod23.z.object({
|
|
9998
|
-
start: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(
|
|
9999
|
-
end: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(
|
|
10402
|
+
start: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(import_firestore32.Timestamp)),
|
|
10403
|
+
end: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(import_firestore32.Timestamp))
|
|
10000
10404
|
}).refine(
|
|
10001
10405
|
(data) => {
|
|
10002
|
-
const startDate = data.start instanceof
|
|
10003
|
-
const endDate = data.end instanceof
|
|
10406
|
+
const startDate = data.start instanceof import_firestore32.Timestamp ? data.start.toDate() : data.start;
|
|
10407
|
+
const endDate = data.end instanceof import_firestore32.Timestamp ? data.end.toDate() : data.end;
|
|
10004
10408
|
return startDate < endDate;
|
|
10005
10409
|
},
|
|
10006
10410
|
{
|
|
@@ -10009,7 +10413,7 @@ var calendarEventTimeSchema = import_zod23.z.object({
|
|
|
10009
10413
|
}
|
|
10010
10414
|
).refine(
|
|
10011
10415
|
(data) => {
|
|
10012
|
-
const startDate = data.start instanceof
|
|
10416
|
+
const startDate = data.start instanceof import_firestore32.Timestamp ? data.start.toDate() : data.start;
|
|
10013
10417
|
return startDate > /* @__PURE__ */ new Date();
|
|
10014
10418
|
},
|
|
10015
10419
|
{
|
|
@@ -10028,7 +10432,7 @@ var timeSlotSchema2 = import_zod23.z.object({
|
|
|
10028
10432
|
var syncedCalendarEventSchema = import_zod23.z.object({
|
|
10029
10433
|
eventId: import_zod23.z.string(),
|
|
10030
10434
|
syncedCalendarProvider: import_zod23.z.nativeEnum(SyncedCalendarProvider),
|
|
10031
|
-
syncedAt: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(
|
|
10435
|
+
syncedAt: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(import_firestore32.Timestamp))
|
|
10032
10436
|
});
|
|
10033
10437
|
var procedureInfoSchema = import_zod23.z.object({
|
|
10034
10438
|
name: import_zod23.z.string(),
|
|
@@ -10130,47 +10534,47 @@ var calendarEventSchema = import_zod23.z.object({
|
|
|
10130
10534
|
status: import_zod23.z.nativeEnum(CalendarEventStatus),
|
|
10131
10535
|
syncStatus: import_zod23.z.nativeEnum(CalendarSyncStatus),
|
|
10132
10536
|
eventType: import_zod23.z.nativeEnum(CalendarEventType),
|
|
10133
|
-
createdAt: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(
|
|
10134
|
-
updatedAt: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(
|
|
10537
|
+
createdAt: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(import_firestore32.Timestamp)),
|
|
10538
|
+
updatedAt: import_zod23.z.instanceof(Date).or(import_zod23.z.instanceof(import_firestore32.Timestamp))
|
|
10135
10539
|
});
|
|
10136
10540
|
|
|
10137
10541
|
// src/services/calendar/utils/clinic.utils.ts
|
|
10138
|
-
var
|
|
10542
|
+
var import_firestore34 = require("firebase/firestore");
|
|
10139
10543
|
|
|
10140
10544
|
// src/services/calendar/utils/docs.utils.ts
|
|
10141
|
-
var
|
|
10545
|
+
var import_firestore33 = require("firebase/firestore");
|
|
10142
10546
|
function getPractitionerCalendarEventDocRef(db, practitionerId, eventId) {
|
|
10143
|
-
return (0,
|
|
10547
|
+
return (0, import_firestore33.doc)(
|
|
10144
10548
|
db,
|
|
10145
10549
|
`${PRACTITIONERS_COLLECTION}/${practitionerId}/${CALENDAR_COLLECTION}/${eventId}`
|
|
10146
10550
|
);
|
|
10147
10551
|
}
|
|
10148
10552
|
function getPatientCalendarEventDocRef(db, patientId, eventId) {
|
|
10149
|
-
return (0,
|
|
10553
|
+
return (0, import_firestore33.doc)(
|
|
10150
10554
|
db,
|
|
10151
10555
|
`${PATIENTS_COLLECTION}/${patientId}/${CALENDAR_COLLECTION}/${eventId}`
|
|
10152
10556
|
);
|
|
10153
10557
|
}
|
|
10154
10558
|
function getClinicCalendarEventDocRef(db, clinicId, eventId) {
|
|
10155
|
-
return (0,
|
|
10559
|
+
return (0, import_firestore33.doc)(
|
|
10156
10560
|
db,
|
|
10157
10561
|
`${CLINICS_COLLECTION}/${clinicId}/${CALENDAR_COLLECTION}/${eventId}`
|
|
10158
10562
|
);
|
|
10159
10563
|
}
|
|
10160
10564
|
function getPractitionerSyncedCalendarDocRef(db, practitionerId, syncedCalendarId) {
|
|
10161
|
-
return (0,
|
|
10565
|
+
return (0, import_firestore33.doc)(
|
|
10162
10566
|
db,
|
|
10163
10567
|
`${PRACTITIONERS_COLLECTION}/${practitionerId}/syncedCalendars/${syncedCalendarId}`
|
|
10164
10568
|
);
|
|
10165
10569
|
}
|
|
10166
10570
|
function getPatientSyncedCalendarDocRef(db, patientId, syncedCalendarId) {
|
|
10167
|
-
return (0,
|
|
10571
|
+
return (0, import_firestore33.doc)(
|
|
10168
10572
|
db,
|
|
10169
10573
|
`${PATIENTS_COLLECTION}/${patientId}/syncedCalendars/${syncedCalendarId}`
|
|
10170
10574
|
);
|
|
10171
10575
|
}
|
|
10172
10576
|
function getClinicSyncedCalendarDocRef(db, clinicId, syncedCalendarId) {
|
|
10173
|
-
return (0,
|
|
10577
|
+
return (0, import_firestore33.doc)(
|
|
10174
10578
|
db,
|
|
10175
10579
|
`${CLINICS_COLLECTION}/${clinicId}/syncedCalendars/${syncedCalendarId}`
|
|
10176
10580
|
);
|
|
@@ -10183,31 +10587,31 @@ async function createClinicCalendarEventUtil(db, clinicId, eventData, generateId
|
|
|
10183
10587
|
const newEvent = {
|
|
10184
10588
|
id: eventId,
|
|
10185
10589
|
...eventData,
|
|
10186
|
-
createdAt: (0,
|
|
10187
|
-
updatedAt: (0,
|
|
10590
|
+
createdAt: (0, import_firestore34.serverTimestamp)(),
|
|
10591
|
+
updatedAt: (0, import_firestore34.serverTimestamp)()
|
|
10188
10592
|
};
|
|
10189
|
-
await (0,
|
|
10593
|
+
await (0, import_firestore34.setDoc)(eventRef, newEvent);
|
|
10190
10594
|
return {
|
|
10191
10595
|
...newEvent,
|
|
10192
|
-
createdAt:
|
|
10193
|
-
updatedAt:
|
|
10596
|
+
createdAt: import_firestore34.Timestamp.now(),
|
|
10597
|
+
updatedAt: import_firestore34.Timestamp.now()
|
|
10194
10598
|
};
|
|
10195
10599
|
}
|
|
10196
10600
|
async function updateClinicCalendarEventUtil(db, clinicId, eventId, updateData) {
|
|
10197
10601
|
const eventRef = getClinicCalendarEventDocRef(db, clinicId, eventId);
|
|
10198
10602
|
const updates = {
|
|
10199
10603
|
...updateData,
|
|
10200
|
-
updatedAt: (0,
|
|
10604
|
+
updatedAt: (0, import_firestore34.serverTimestamp)()
|
|
10201
10605
|
};
|
|
10202
|
-
await (0,
|
|
10203
|
-
const updatedDoc = await (0,
|
|
10606
|
+
await (0, import_firestore34.updateDoc)(eventRef, updates);
|
|
10607
|
+
const updatedDoc = await (0, import_firestore34.getDoc)(eventRef);
|
|
10204
10608
|
if (!updatedDoc.exists()) {
|
|
10205
10609
|
throw new Error("Event not found after update");
|
|
10206
10610
|
}
|
|
10207
10611
|
return updatedDoc.data();
|
|
10208
10612
|
}
|
|
10209
10613
|
async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
|
|
10210
|
-
const clinicDoc = await (0,
|
|
10614
|
+
const clinicDoc = await (0, import_firestore34.getDoc)((0, import_firestore34.doc)(db, `clinics/${clinicId}`));
|
|
10211
10615
|
if (!clinicDoc.exists()) {
|
|
10212
10616
|
throw new Error(`Clinic with ID ${clinicId} not found`);
|
|
10213
10617
|
}
|
|
@@ -10216,8 +10620,8 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
|
|
|
10216
10620
|
if (!clinicGroupId) {
|
|
10217
10621
|
return false;
|
|
10218
10622
|
}
|
|
10219
|
-
const clinicGroupDoc = await (0,
|
|
10220
|
-
(0,
|
|
10623
|
+
const clinicGroupDoc = await (0, import_firestore34.getDoc)(
|
|
10624
|
+
(0, import_firestore34.doc)(db, `${CLINIC_GROUPS_COLLECTION}/${clinicGroupId}`)
|
|
10221
10625
|
);
|
|
10222
10626
|
if (!clinicGroupDoc.exists()) {
|
|
10223
10627
|
return false;
|
|
@@ -10227,31 +10631,31 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
|
|
|
10227
10631
|
}
|
|
10228
10632
|
|
|
10229
10633
|
// src/services/calendar/utils/patient.utils.ts
|
|
10230
|
-
var
|
|
10634
|
+
var import_firestore35 = require("firebase/firestore");
|
|
10231
10635
|
async function createPatientCalendarEventUtil(db, patientId, eventData, generateId2) {
|
|
10232
10636
|
const eventId = generateId2();
|
|
10233
10637
|
const eventRef = getPatientCalendarEventDocRef(db, patientId, eventId);
|
|
10234
10638
|
const newEvent = {
|
|
10235
10639
|
id: eventId,
|
|
10236
10640
|
...eventData,
|
|
10237
|
-
createdAt: (0,
|
|
10238
|
-
updatedAt: (0,
|
|
10641
|
+
createdAt: (0, import_firestore35.serverTimestamp)(),
|
|
10642
|
+
updatedAt: (0, import_firestore35.serverTimestamp)()
|
|
10239
10643
|
};
|
|
10240
|
-
await (0,
|
|
10644
|
+
await (0, import_firestore35.setDoc)(eventRef, newEvent);
|
|
10241
10645
|
return {
|
|
10242
10646
|
...newEvent,
|
|
10243
|
-
createdAt:
|
|
10244
|
-
updatedAt:
|
|
10647
|
+
createdAt: import_firestore35.Timestamp.now(),
|
|
10648
|
+
updatedAt: import_firestore35.Timestamp.now()
|
|
10245
10649
|
};
|
|
10246
10650
|
}
|
|
10247
10651
|
async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData) {
|
|
10248
10652
|
const eventRef = getPatientCalendarEventDocRef(db, patientId, eventId);
|
|
10249
10653
|
const updates = {
|
|
10250
10654
|
...updateData,
|
|
10251
|
-
updatedAt: (0,
|
|
10655
|
+
updatedAt: (0, import_firestore35.serverTimestamp)()
|
|
10252
10656
|
};
|
|
10253
|
-
await (0,
|
|
10254
|
-
const updatedDoc = await (0,
|
|
10657
|
+
await (0, import_firestore35.updateDoc)(eventRef, updates);
|
|
10658
|
+
const updatedDoc = await (0, import_firestore35.getDoc)(eventRef);
|
|
10255
10659
|
if (!updatedDoc.exists()) {
|
|
10256
10660
|
throw new Error("Event not found after update");
|
|
10257
10661
|
}
|
|
@@ -10259,7 +10663,7 @@ async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData
|
|
|
10259
10663
|
}
|
|
10260
10664
|
|
|
10261
10665
|
// src/services/calendar/utils/practitioner.utils.ts
|
|
10262
|
-
var
|
|
10666
|
+
var import_firestore36 = require("firebase/firestore");
|
|
10263
10667
|
async function createPractitionerCalendarEventUtil(db, practitionerId, eventData, generateId2) {
|
|
10264
10668
|
const eventId = generateId2();
|
|
10265
10669
|
const eventRef = getPractitionerCalendarEventDocRef(
|
|
@@ -10270,14 +10674,14 @@ async function createPractitionerCalendarEventUtil(db, practitionerId, eventData
|
|
|
10270
10674
|
const newEvent = {
|
|
10271
10675
|
id: eventId,
|
|
10272
10676
|
...eventData,
|
|
10273
|
-
createdAt: (0,
|
|
10274
|
-
updatedAt: (0,
|
|
10677
|
+
createdAt: (0, import_firestore36.serverTimestamp)(),
|
|
10678
|
+
updatedAt: (0, import_firestore36.serverTimestamp)()
|
|
10275
10679
|
};
|
|
10276
|
-
await (0,
|
|
10680
|
+
await (0, import_firestore36.setDoc)(eventRef, newEvent);
|
|
10277
10681
|
return {
|
|
10278
10682
|
...newEvent,
|
|
10279
|
-
createdAt:
|
|
10280
|
-
updatedAt:
|
|
10683
|
+
createdAt: import_firestore36.Timestamp.now(),
|
|
10684
|
+
updatedAt: import_firestore36.Timestamp.now()
|
|
10281
10685
|
};
|
|
10282
10686
|
}
|
|
10283
10687
|
async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId, updateData) {
|
|
@@ -10288,10 +10692,10 @@ async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId,
|
|
|
10288
10692
|
);
|
|
10289
10693
|
const updates = {
|
|
10290
10694
|
...updateData,
|
|
10291
|
-
updatedAt: (0,
|
|
10695
|
+
updatedAt: (0, import_firestore36.serverTimestamp)()
|
|
10292
10696
|
};
|
|
10293
|
-
await (0,
|
|
10294
|
-
const updatedDoc = await (0,
|
|
10697
|
+
await (0, import_firestore36.updateDoc)(eventRef, updates);
|
|
10698
|
+
const updatedDoc = await (0, import_firestore36.getDoc)(eventRef);
|
|
10295
10699
|
if (!updatedDoc.exists()) {
|
|
10296
10700
|
throw new Error("Event not found after update");
|
|
10297
10701
|
}
|
|
@@ -10349,7 +10753,7 @@ async function updateAppointmentUtil(db, clinicId, practitionerId, patientId, ev
|
|
|
10349
10753
|
}
|
|
10350
10754
|
|
|
10351
10755
|
// src/services/calendar/utils/calendar-event.utils.ts
|
|
10352
|
-
var
|
|
10756
|
+
var import_firestore37 = require("firebase/firestore");
|
|
10353
10757
|
async function searchCalendarEventsUtil(db, params) {
|
|
10354
10758
|
const { searchLocation, entityId, ...filters } = params;
|
|
10355
10759
|
let baseCollectionPath;
|
|
@@ -10392,7 +10796,7 @@ async function searchCalendarEventsUtil(db, params) {
|
|
|
10392
10796
|
);
|
|
10393
10797
|
}
|
|
10394
10798
|
baseCollectionPath = `${CLINICS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
|
|
10395
|
-
constraints.push((0,
|
|
10799
|
+
constraints.push((0, import_firestore37.where)("clinicBranchId", "==", entityId));
|
|
10396
10800
|
if (filters.clinicId && filters.clinicId !== entityId) {
|
|
10397
10801
|
console.warn(
|
|
10398
10802
|
`Provided clinicId filter (${filters.clinicId}) does not match search entityId (${entityId}). Returning empty results.`
|
|
@@ -10404,36 +10808,36 @@ async function searchCalendarEventsUtil(db, params) {
|
|
|
10404
10808
|
default:
|
|
10405
10809
|
throw new Error(`Invalid search location: ${searchLocation}`);
|
|
10406
10810
|
}
|
|
10407
|
-
const collectionRef = (0,
|
|
10811
|
+
const collectionRef = (0, import_firestore37.collection)(db, baseCollectionPath);
|
|
10408
10812
|
if (filters.clinicId) {
|
|
10409
|
-
constraints.push((0,
|
|
10813
|
+
constraints.push((0, import_firestore37.where)("clinicBranchId", "==", filters.clinicId));
|
|
10410
10814
|
}
|
|
10411
10815
|
if (filters.practitionerId) {
|
|
10412
10816
|
constraints.push(
|
|
10413
|
-
(0,
|
|
10817
|
+
(0, import_firestore37.where)("practitionerProfileId", "==", filters.practitionerId)
|
|
10414
10818
|
);
|
|
10415
10819
|
}
|
|
10416
10820
|
if (filters.patientId) {
|
|
10417
|
-
constraints.push((0,
|
|
10821
|
+
constraints.push((0, import_firestore37.where)("patientProfileId", "==", filters.patientId));
|
|
10418
10822
|
}
|
|
10419
10823
|
if (filters.procedureId) {
|
|
10420
|
-
constraints.push((0,
|
|
10824
|
+
constraints.push((0, import_firestore37.where)("procedureId", "==", filters.procedureId));
|
|
10421
10825
|
}
|
|
10422
10826
|
if (filters.eventStatus) {
|
|
10423
|
-
constraints.push((0,
|
|
10827
|
+
constraints.push((0, import_firestore37.where)("status", "==", filters.eventStatus));
|
|
10424
10828
|
}
|
|
10425
10829
|
if (filters.eventType) {
|
|
10426
|
-
constraints.push((0,
|
|
10830
|
+
constraints.push((0, import_firestore37.where)("eventType", "==", filters.eventType));
|
|
10427
10831
|
}
|
|
10428
10832
|
if (filters.dateRange) {
|
|
10429
|
-
constraints.push((0,
|
|
10430
|
-
constraints.push((0,
|
|
10833
|
+
constraints.push((0, import_firestore37.where)("eventTime.start", ">=", filters.dateRange.start));
|
|
10834
|
+
constraints.push((0, import_firestore37.where)("eventTime.start", "<=", filters.dateRange.end));
|
|
10431
10835
|
}
|
|
10432
10836
|
try {
|
|
10433
|
-
const finalQuery = (0,
|
|
10434
|
-
const querySnapshot = await (0,
|
|
10837
|
+
const finalQuery = (0, import_firestore37.query)(collectionRef, ...constraints);
|
|
10838
|
+
const querySnapshot = await (0, import_firestore37.getDocs)(finalQuery);
|
|
10435
10839
|
const events = querySnapshot.docs.map(
|
|
10436
|
-
(
|
|
10840
|
+
(doc35) => ({ id: doc35.id, ...doc35.data() })
|
|
10437
10841
|
);
|
|
10438
10842
|
return events;
|
|
10439
10843
|
} catch (error) {
|
|
@@ -10443,7 +10847,7 @@ async function searchCalendarEventsUtil(db, params) {
|
|
|
10443
10847
|
}
|
|
10444
10848
|
|
|
10445
10849
|
// src/services/calendar/utils/synced-calendar.utils.ts
|
|
10446
|
-
var
|
|
10850
|
+
var import_firestore38 = require("firebase/firestore");
|
|
10447
10851
|
async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendarData, generateId2) {
|
|
10448
10852
|
const calendarId = generateId2();
|
|
10449
10853
|
const calendarRef = getPractitionerSyncedCalendarDocRef(
|
|
@@ -10454,14 +10858,14 @@ async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendar
|
|
|
10454
10858
|
const newCalendar = {
|
|
10455
10859
|
id: calendarId,
|
|
10456
10860
|
...calendarData,
|
|
10457
|
-
createdAt: (0,
|
|
10458
|
-
updatedAt: (0,
|
|
10861
|
+
createdAt: (0, import_firestore38.serverTimestamp)(),
|
|
10862
|
+
updatedAt: (0, import_firestore38.serverTimestamp)()
|
|
10459
10863
|
};
|
|
10460
|
-
await (0,
|
|
10864
|
+
await (0, import_firestore38.setDoc)(calendarRef, newCalendar);
|
|
10461
10865
|
return {
|
|
10462
10866
|
...newCalendar,
|
|
10463
|
-
createdAt:
|
|
10464
|
-
updatedAt:
|
|
10867
|
+
createdAt: import_firestore38.Timestamp.now(),
|
|
10868
|
+
updatedAt: import_firestore38.Timestamp.now()
|
|
10465
10869
|
};
|
|
10466
10870
|
}
|
|
10467
10871
|
async function createPatientSyncedCalendarUtil(db, patientId, calendarData, generateId2) {
|
|
@@ -10470,14 +10874,14 @@ async function createPatientSyncedCalendarUtil(db, patientId, calendarData, gene
|
|
|
10470
10874
|
const newCalendar = {
|
|
10471
10875
|
id: calendarId,
|
|
10472
10876
|
...calendarData,
|
|
10473
|
-
createdAt: (0,
|
|
10474
|
-
updatedAt: (0,
|
|
10877
|
+
createdAt: (0, import_firestore38.serverTimestamp)(),
|
|
10878
|
+
updatedAt: (0, import_firestore38.serverTimestamp)()
|
|
10475
10879
|
};
|
|
10476
|
-
await (0,
|
|
10880
|
+
await (0, import_firestore38.setDoc)(calendarRef, newCalendar);
|
|
10477
10881
|
return {
|
|
10478
10882
|
...newCalendar,
|
|
10479
|
-
createdAt:
|
|
10480
|
-
updatedAt:
|
|
10883
|
+
createdAt: import_firestore38.Timestamp.now(),
|
|
10884
|
+
updatedAt: import_firestore38.Timestamp.now()
|
|
10481
10885
|
};
|
|
10482
10886
|
}
|
|
10483
10887
|
async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, generateId2) {
|
|
@@ -10486,14 +10890,14 @@ async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, genera
|
|
|
10486
10890
|
const newCalendar = {
|
|
10487
10891
|
id: calendarId,
|
|
10488
10892
|
...calendarData,
|
|
10489
|
-
createdAt: (0,
|
|
10490
|
-
updatedAt: (0,
|
|
10893
|
+
createdAt: (0, import_firestore38.serverTimestamp)(),
|
|
10894
|
+
updatedAt: (0, import_firestore38.serverTimestamp)()
|
|
10491
10895
|
};
|
|
10492
|
-
await (0,
|
|
10896
|
+
await (0, import_firestore38.setDoc)(calendarRef, newCalendar);
|
|
10493
10897
|
return {
|
|
10494
10898
|
...newCalendar,
|
|
10495
|
-
createdAt:
|
|
10496
|
-
updatedAt:
|
|
10899
|
+
createdAt: import_firestore38.Timestamp.now(),
|
|
10900
|
+
updatedAt: import_firestore38.Timestamp.now()
|
|
10497
10901
|
};
|
|
10498
10902
|
}
|
|
10499
10903
|
async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId) {
|
|
@@ -10502,54 +10906,54 @@ async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId)
|
|
|
10502
10906
|
practitionerId,
|
|
10503
10907
|
calendarId
|
|
10504
10908
|
);
|
|
10505
|
-
const calendarDoc = await (0,
|
|
10909
|
+
const calendarDoc = await (0, import_firestore38.getDoc)(calendarRef);
|
|
10506
10910
|
if (!calendarDoc.exists()) {
|
|
10507
10911
|
return null;
|
|
10508
10912
|
}
|
|
10509
10913
|
return calendarDoc.data();
|
|
10510
10914
|
}
|
|
10511
10915
|
async function getPractitionerSyncedCalendarsUtil(db, practitionerId) {
|
|
10512
|
-
const calendarsRef = (0,
|
|
10916
|
+
const calendarsRef = (0, import_firestore38.collection)(
|
|
10513
10917
|
db,
|
|
10514
10918
|
`practitioners/${practitionerId}/${SYNCED_CALENDARS_COLLECTION}`
|
|
10515
10919
|
);
|
|
10516
|
-
const q = (0,
|
|
10517
|
-
const querySnapshot = await (0,
|
|
10518
|
-
return querySnapshot.docs.map((
|
|
10920
|
+
const q = (0, import_firestore38.query)(calendarsRef, (0, import_firestore38.orderBy)("createdAt", "desc"));
|
|
10921
|
+
const querySnapshot = await (0, import_firestore38.getDocs)(q);
|
|
10922
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
10519
10923
|
}
|
|
10520
10924
|
async function getPatientSyncedCalendarUtil(db, patientId, calendarId) {
|
|
10521
10925
|
const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
|
|
10522
|
-
const calendarDoc = await (0,
|
|
10926
|
+
const calendarDoc = await (0, import_firestore38.getDoc)(calendarRef);
|
|
10523
10927
|
if (!calendarDoc.exists()) {
|
|
10524
10928
|
return null;
|
|
10525
10929
|
}
|
|
10526
10930
|
return calendarDoc.data();
|
|
10527
10931
|
}
|
|
10528
10932
|
async function getPatientSyncedCalendarsUtil(db, patientId) {
|
|
10529
|
-
const calendarsRef = (0,
|
|
10933
|
+
const calendarsRef = (0, import_firestore38.collection)(
|
|
10530
10934
|
db,
|
|
10531
10935
|
`patients/${patientId}/${SYNCED_CALENDARS_COLLECTION}`
|
|
10532
10936
|
);
|
|
10533
|
-
const q = (0,
|
|
10534
|
-
const querySnapshot = await (0,
|
|
10535
|
-
return querySnapshot.docs.map((
|
|
10937
|
+
const q = (0, import_firestore38.query)(calendarsRef, (0, import_firestore38.orderBy)("createdAt", "desc"));
|
|
10938
|
+
const querySnapshot = await (0, import_firestore38.getDocs)(q);
|
|
10939
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
10536
10940
|
}
|
|
10537
10941
|
async function getClinicSyncedCalendarUtil(db, clinicId, calendarId) {
|
|
10538
10942
|
const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
|
|
10539
|
-
const calendarDoc = await (0,
|
|
10943
|
+
const calendarDoc = await (0, import_firestore38.getDoc)(calendarRef);
|
|
10540
10944
|
if (!calendarDoc.exists()) {
|
|
10541
10945
|
return null;
|
|
10542
10946
|
}
|
|
10543
10947
|
return calendarDoc.data();
|
|
10544
10948
|
}
|
|
10545
10949
|
async function getClinicSyncedCalendarsUtil(db, clinicId) {
|
|
10546
|
-
const calendarsRef = (0,
|
|
10950
|
+
const calendarsRef = (0, import_firestore38.collection)(
|
|
10547
10951
|
db,
|
|
10548
10952
|
`clinics/${clinicId}/${SYNCED_CALENDARS_COLLECTION}`
|
|
10549
10953
|
);
|
|
10550
|
-
const q = (0,
|
|
10551
|
-
const querySnapshot = await (0,
|
|
10552
|
-
return querySnapshot.docs.map((
|
|
10954
|
+
const q = (0, import_firestore38.query)(calendarsRef, (0, import_firestore38.orderBy)("createdAt", "desc"));
|
|
10955
|
+
const querySnapshot = await (0, import_firestore38.getDocs)(q);
|
|
10956
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
10553
10957
|
}
|
|
10554
10958
|
async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendarId, updateData) {
|
|
10555
10959
|
const calendarRef = getPractitionerSyncedCalendarDocRef(
|
|
@@ -10559,10 +10963,10 @@ async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendar
|
|
|
10559
10963
|
);
|
|
10560
10964
|
const updates = {
|
|
10561
10965
|
...updateData,
|
|
10562
|
-
updatedAt: (0,
|
|
10966
|
+
updatedAt: (0, import_firestore38.serverTimestamp)()
|
|
10563
10967
|
};
|
|
10564
|
-
await (0,
|
|
10565
|
-
const updatedDoc = await (0,
|
|
10968
|
+
await (0, import_firestore38.updateDoc)(calendarRef, updates);
|
|
10969
|
+
const updatedDoc = await (0, import_firestore38.getDoc)(calendarRef);
|
|
10566
10970
|
if (!updatedDoc.exists()) {
|
|
10567
10971
|
throw new Error("Synced calendar not found after update");
|
|
10568
10972
|
}
|
|
@@ -10572,10 +10976,10 @@ async function updatePatientSyncedCalendarUtil(db, patientId, calendarId, update
|
|
|
10572
10976
|
const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
|
|
10573
10977
|
const updates = {
|
|
10574
10978
|
...updateData,
|
|
10575
|
-
updatedAt: (0,
|
|
10979
|
+
updatedAt: (0, import_firestore38.serverTimestamp)()
|
|
10576
10980
|
};
|
|
10577
|
-
await (0,
|
|
10578
|
-
const updatedDoc = await (0,
|
|
10981
|
+
await (0, import_firestore38.updateDoc)(calendarRef, updates);
|
|
10982
|
+
const updatedDoc = await (0, import_firestore38.getDoc)(calendarRef);
|
|
10579
10983
|
if (!updatedDoc.exists()) {
|
|
10580
10984
|
throw new Error("Synced calendar not found after update");
|
|
10581
10985
|
}
|
|
@@ -10585,10 +10989,10 @@ async function updateClinicSyncedCalendarUtil(db, clinicId, calendarId, updateDa
|
|
|
10585
10989
|
const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
|
|
10586
10990
|
const updates = {
|
|
10587
10991
|
...updateData,
|
|
10588
|
-
updatedAt: (0,
|
|
10992
|
+
updatedAt: (0, import_firestore38.serverTimestamp)()
|
|
10589
10993
|
};
|
|
10590
|
-
await (0,
|
|
10591
|
-
const updatedDoc = await (0,
|
|
10994
|
+
await (0, import_firestore38.updateDoc)(calendarRef, updates);
|
|
10995
|
+
const updatedDoc = await (0, import_firestore38.getDoc)(calendarRef);
|
|
10592
10996
|
if (!updatedDoc.exists()) {
|
|
10593
10997
|
throw new Error("Synced calendar not found after update");
|
|
10594
10998
|
}
|
|
@@ -10600,19 +11004,19 @@ async function deletePractitionerSyncedCalendarUtil(db, practitionerId, calendar
|
|
|
10600
11004
|
practitionerId,
|
|
10601
11005
|
calendarId
|
|
10602
11006
|
);
|
|
10603
|
-
await (0,
|
|
11007
|
+
await (0, import_firestore38.deleteDoc)(calendarRef);
|
|
10604
11008
|
}
|
|
10605
11009
|
async function deletePatientSyncedCalendarUtil(db, patientId, calendarId) {
|
|
10606
11010
|
const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
|
|
10607
|
-
await (0,
|
|
11011
|
+
await (0, import_firestore38.deleteDoc)(calendarRef);
|
|
10608
11012
|
}
|
|
10609
11013
|
async function deleteClinicSyncedCalendarUtil(db, clinicId, calendarId) {
|
|
10610
11014
|
const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
|
|
10611
|
-
await (0,
|
|
11015
|
+
await (0, import_firestore38.deleteDoc)(calendarRef);
|
|
10612
11016
|
}
|
|
10613
11017
|
async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarId) {
|
|
10614
11018
|
const updateData = {
|
|
10615
|
-
lastSyncedAt:
|
|
11019
|
+
lastSyncedAt: import_firestore38.Timestamp.now()
|
|
10616
11020
|
};
|
|
10617
11021
|
switch (entityType) {
|
|
10618
11022
|
case "practitioner":
|
|
@@ -10642,7 +11046,7 @@ async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarI
|
|
|
10642
11046
|
}
|
|
10643
11047
|
|
|
10644
11048
|
// src/services/calendar/utils/google-calendar.utils.ts
|
|
10645
|
-
var
|
|
11049
|
+
var import_firestore39 = require("firebase/firestore");
|
|
10646
11050
|
var GOOGLE_CALENDAR_API_URL = "https://www.googleapis.com/calendar/v3";
|
|
10647
11051
|
var GOOGLE_OAUTH_URL = "https://oauth2.googleapis.com/token";
|
|
10648
11052
|
var CLIENT_ID = "your-client-id";
|
|
@@ -10762,7 +11166,7 @@ async function ensureValidToken(db, entityType, entityId, syncedCalendar) {
|
|
|
10762
11166
|
tokenExpiry.setSeconds(tokenExpiry.getSeconds() + expiresIn);
|
|
10763
11167
|
const updateData = {
|
|
10764
11168
|
accessToken,
|
|
10765
|
-
tokenExpiry:
|
|
11169
|
+
tokenExpiry: import_firestore39.Timestamp.fromDate(tokenExpiry)
|
|
10766
11170
|
};
|
|
10767
11171
|
switch (entityType) {
|
|
10768
11172
|
case "practitioner":
|
|
@@ -10937,8 +11341,8 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
|
|
|
10937
11341
|
eventName: googleEvent.summary || "External Event",
|
|
10938
11342
|
eventLocation: googleEvent.location,
|
|
10939
11343
|
eventTime: {
|
|
10940
|
-
start:
|
|
10941
|
-
end:
|
|
11344
|
+
start: import_firestore39.Timestamp.fromDate(start),
|
|
11345
|
+
end: import_firestore39.Timestamp.fromDate(end)
|
|
10942
11346
|
},
|
|
10943
11347
|
description: googleEvent.description || "",
|
|
10944
11348
|
// External events are always set as CONFIRMED - status updates will happen externally
|
|
@@ -10952,7 +11356,7 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
|
|
|
10952
11356
|
{
|
|
10953
11357
|
eventId: googleEvent.id,
|
|
10954
11358
|
syncedCalendarProvider: "google" /* GOOGLE */,
|
|
10955
|
-
syncedAt:
|
|
11359
|
+
syncedAt: import_firestore39.Timestamp.now()
|
|
10956
11360
|
}
|
|
10957
11361
|
]
|
|
10958
11362
|
};
|
|
@@ -11730,7 +12134,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
11730
12134
|
return 0;
|
|
11731
12135
|
}
|
|
11732
12136
|
let importedEventsCount = 0;
|
|
11733
|
-
const currentTime =
|
|
12137
|
+
const currentTime = import_firestore40.Timestamp.now();
|
|
11734
12138
|
for (const calendar of activeCalendars) {
|
|
11735
12139
|
try {
|
|
11736
12140
|
let externalEvents = [];
|
|
@@ -11797,7 +12201,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
11797
12201
|
async createDoctorBlockingEvent(doctorId, eventData) {
|
|
11798
12202
|
try {
|
|
11799
12203
|
const eventId = this.generateId();
|
|
11800
|
-
const eventRef = (0,
|
|
12204
|
+
const eventRef = (0, import_firestore41.doc)(
|
|
11801
12205
|
this.db,
|
|
11802
12206
|
PRACTITIONERS_COLLECTION,
|
|
11803
12207
|
doctorId,
|
|
@@ -11807,14 +12211,14 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
11807
12211
|
const newEvent = {
|
|
11808
12212
|
id: eventId,
|
|
11809
12213
|
...eventData,
|
|
11810
|
-
createdAt: (0,
|
|
11811
|
-
updatedAt: (0,
|
|
12214
|
+
createdAt: (0, import_firestore40.serverTimestamp)(),
|
|
12215
|
+
updatedAt: (0, import_firestore40.serverTimestamp)()
|
|
11812
12216
|
};
|
|
11813
|
-
await (0,
|
|
12217
|
+
await (0, import_firestore41.setDoc)(eventRef, newEvent);
|
|
11814
12218
|
return {
|
|
11815
12219
|
...newEvent,
|
|
11816
|
-
createdAt:
|
|
11817
|
-
updatedAt:
|
|
12220
|
+
createdAt: import_firestore40.Timestamp.now(),
|
|
12221
|
+
updatedAt: import_firestore40.Timestamp.now()
|
|
11818
12222
|
};
|
|
11819
12223
|
} catch (error) {
|
|
11820
12224
|
console.error(
|
|
@@ -11832,8 +12236,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
11832
12236
|
*/
|
|
11833
12237
|
async synchronizeExternalCalendars(lookbackDays = 7, lookforwardDays = 30) {
|
|
11834
12238
|
try {
|
|
11835
|
-
const practitionersRef = (0,
|
|
11836
|
-
const practitionersSnapshot = await (0,
|
|
12239
|
+
const practitionersRef = (0, import_firestore41.collection)(this.db, PRACTITIONERS_COLLECTION);
|
|
12240
|
+
const practitionersSnapshot = await (0, import_firestore41.getDocs)(practitionersRef);
|
|
11837
12241
|
const startDate = /* @__PURE__ */ new Date();
|
|
11838
12242
|
startDate.setDate(startDate.getDate() - lookbackDays);
|
|
11839
12243
|
const endDate = /* @__PURE__ */ new Date();
|
|
@@ -11891,22 +12295,22 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
11891
12295
|
async updateExistingEventsFromExternalCalendars(doctorId, startDate, endDate) {
|
|
11892
12296
|
var _a;
|
|
11893
12297
|
try {
|
|
11894
|
-
const eventsRef = (0,
|
|
12298
|
+
const eventsRef = (0, import_firestore41.collection)(
|
|
11895
12299
|
this.db,
|
|
11896
12300
|
PRACTITIONERS_COLLECTION,
|
|
11897
12301
|
doctorId,
|
|
11898
12302
|
CALENDAR_COLLECTION
|
|
11899
12303
|
);
|
|
11900
|
-
const q = (0,
|
|
12304
|
+
const q = (0, import_firestore41.query)(
|
|
11901
12305
|
eventsRef,
|
|
11902
|
-
(0,
|
|
11903
|
-
(0,
|
|
11904
|
-
(0,
|
|
11905
|
-
);
|
|
11906
|
-
const eventsSnapshot = await (0,
|
|
11907
|
-
const events = eventsSnapshot.docs.map((
|
|
11908
|
-
id:
|
|
11909
|
-
...
|
|
12306
|
+
(0, import_firestore41.where)("syncStatus", "==", "external" /* EXTERNAL */),
|
|
12307
|
+
(0, import_firestore41.where)("eventTime.start", ">=", import_firestore40.Timestamp.fromDate(startDate)),
|
|
12308
|
+
(0, import_firestore41.where)("eventTime.start", "<=", import_firestore40.Timestamp.fromDate(endDate))
|
|
12309
|
+
);
|
|
12310
|
+
const eventsSnapshot = await (0, import_firestore41.getDocs)(q);
|
|
12311
|
+
const events = eventsSnapshot.docs.map((doc35) => ({
|
|
12312
|
+
id: doc35.id,
|
|
12313
|
+
...doc35.data()
|
|
11910
12314
|
}));
|
|
11911
12315
|
const calendars = await this.syncedCalendarsService.getPractitionerSyncedCalendars(
|
|
11912
12316
|
doctorId
|
|
@@ -12010,21 +12414,21 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12010
12414
|
const endTime = new Date(
|
|
12011
12415
|
externalEvent.end.dateTime || externalEvent.end.date
|
|
12012
12416
|
);
|
|
12013
|
-
const eventRef = (0,
|
|
12417
|
+
const eventRef = (0, import_firestore41.doc)(
|
|
12014
12418
|
this.db,
|
|
12015
12419
|
PRACTITIONERS_COLLECTION,
|
|
12016
12420
|
doctorId,
|
|
12017
12421
|
CALENDAR_COLLECTION,
|
|
12018
12422
|
eventId
|
|
12019
12423
|
);
|
|
12020
|
-
await (0,
|
|
12424
|
+
await (0, import_firestore41.updateDoc)(eventRef, {
|
|
12021
12425
|
eventName: externalEvent.summary || "External Event",
|
|
12022
12426
|
eventTime: {
|
|
12023
|
-
start:
|
|
12024
|
-
end:
|
|
12427
|
+
start: import_firestore40.Timestamp.fromDate(startTime),
|
|
12428
|
+
end: import_firestore40.Timestamp.fromDate(endTime)
|
|
12025
12429
|
},
|
|
12026
12430
|
description: externalEvent.description || "",
|
|
12027
|
-
updatedAt: (0,
|
|
12431
|
+
updatedAt: (0, import_firestore40.serverTimestamp)()
|
|
12028
12432
|
});
|
|
12029
12433
|
console.log(`Updated local event ${eventId} from external event`);
|
|
12030
12434
|
} catch (error) {
|
|
@@ -12042,16 +12446,16 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12042
12446
|
*/
|
|
12043
12447
|
async updateEventStatus(doctorId, eventId, status) {
|
|
12044
12448
|
try {
|
|
12045
|
-
const eventRef = (0,
|
|
12449
|
+
const eventRef = (0, import_firestore41.doc)(
|
|
12046
12450
|
this.db,
|
|
12047
12451
|
PRACTITIONERS_COLLECTION,
|
|
12048
12452
|
doctorId,
|
|
12049
12453
|
CALENDAR_COLLECTION,
|
|
12050
12454
|
eventId
|
|
12051
12455
|
);
|
|
12052
|
-
await (0,
|
|
12456
|
+
await (0, import_firestore41.updateDoc)(eventRef, {
|
|
12053
12457
|
status,
|
|
12054
|
-
updatedAt: (0,
|
|
12458
|
+
updatedAt: (0, import_firestore40.serverTimestamp)()
|
|
12055
12459
|
});
|
|
12056
12460
|
console.log(`Updated event ${eventId} status to ${status}`);
|
|
12057
12461
|
} catch (error) {
|
|
@@ -12099,8 +12503,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12099
12503
|
*/
|
|
12100
12504
|
async getPractitionerUpcomingAppointments(doctorId, startDate, endDate, status = "confirmed" /* CONFIRMED */) {
|
|
12101
12505
|
const dateRange = {
|
|
12102
|
-
start:
|
|
12103
|
-
end:
|
|
12506
|
+
start: import_firestore40.Timestamp.fromDate(startDate),
|
|
12507
|
+
end: import_firestore40.Timestamp.fromDate(endDate)
|
|
12104
12508
|
};
|
|
12105
12509
|
const searchParams = {
|
|
12106
12510
|
searchLocation: "practitioner" /* PRACTITIONER */,
|
|
@@ -12122,8 +12526,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12122
12526
|
*/
|
|
12123
12527
|
async getPatientAppointments(patientId, startDate, endDate, status) {
|
|
12124
12528
|
const dateRange = {
|
|
12125
|
-
start:
|
|
12126
|
-
end:
|
|
12529
|
+
start: import_firestore40.Timestamp.fromDate(startDate),
|
|
12530
|
+
end: import_firestore40.Timestamp.fromDate(endDate)
|
|
12127
12531
|
};
|
|
12128
12532
|
const searchParams = {
|
|
12129
12533
|
searchLocation: "patient" /* PATIENT */,
|
|
@@ -12148,8 +12552,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12148
12552
|
*/
|
|
12149
12553
|
async getClinicAppointments(clinicId, startDate, endDate, doctorId, status) {
|
|
12150
12554
|
const dateRange = {
|
|
12151
|
-
start:
|
|
12152
|
-
end:
|
|
12555
|
+
start: import_firestore40.Timestamp.fromDate(startDate),
|
|
12556
|
+
end: import_firestore40.Timestamp.fromDate(endDate)
|
|
12153
12557
|
};
|
|
12154
12558
|
const searchParams = {
|
|
12155
12559
|
searchLocation: "clinic" /* CLINIC */,
|
|
@@ -12208,8 +12612,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12208
12612
|
const startDate = eventTime.start.toDate();
|
|
12209
12613
|
const startTime = startDate;
|
|
12210
12614
|
const endTime = eventTime.end.toDate();
|
|
12211
|
-
const practitionerRef = (0,
|
|
12212
|
-
const practitionerDoc = await (0,
|
|
12615
|
+
const practitionerRef = (0, import_firestore41.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
|
|
12616
|
+
const practitionerDoc = await (0, import_firestore41.getDoc)(practitionerRef);
|
|
12213
12617
|
if (!practitionerDoc.exists()) {
|
|
12214
12618
|
throw new Error(`Doctor with ID ${doctorId} not found`);
|
|
12215
12619
|
}
|
|
@@ -12267,8 +12671,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12267
12671
|
*/
|
|
12268
12672
|
async updateAppointmentStatus(appointmentId, clinicId, status) {
|
|
12269
12673
|
const baseCollectionPath = `${CLINICS_COLLECTION}/${clinicId}/${CALENDAR_COLLECTION}`;
|
|
12270
|
-
const appointmentRef = (0,
|
|
12271
|
-
const appointmentDoc = await (0,
|
|
12674
|
+
const appointmentRef = (0, import_firestore41.doc)(this.db, baseCollectionPath, appointmentId);
|
|
12675
|
+
const appointmentDoc = await (0, import_firestore41.getDoc)(appointmentRef);
|
|
12272
12676
|
if (!appointmentDoc.exists()) {
|
|
12273
12677
|
throw new Error(`Appointment with ID ${appointmentId} not found`);
|
|
12274
12678
|
}
|
|
@@ -12403,7 +12807,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12403
12807
|
const newSyncEvent = {
|
|
12404
12808
|
eventId: result.eventIds[0],
|
|
12405
12809
|
syncedCalendarProvider: calendar.provider,
|
|
12406
|
-
syncedAt:
|
|
12810
|
+
syncedAt: import_firestore40.Timestamp.now()
|
|
12407
12811
|
};
|
|
12408
12812
|
await this.updateEventWithSyncId(
|
|
12409
12813
|
entityType === "doctor" ? appointment.practitionerProfileId : appointment.patientProfileId,
|
|
@@ -12427,8 +12831,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12427
12831
|
async updateEventWithSyncId(entityId, entityType, eventId, syncEvent) {
|
|
12428
12832
|
try {
|
|
12429
12833
|
const collectionPath = entityType === "doctor" ? `${PRACTITIONERS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}` : `${PATIENTS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
|
|
12430
|
-
const eventRef = (0,
|
|
12431
|
-
const eventDoc = await (0,
|
|
12834
|
+
const eventRef = (0, import_firestore41.doc)(this.db, collectionPath, eventId);
|
|
12835
|
+
const eventDoc = await (0, import_firestore41.getDoc)(eventRef);
|
|
12432
12836
|
if (eventDoc.exists()) {
|
|
12433
12837
|
const event = eventDoc.data();
|
|
12434
12838
|
const syncIds = [...event.syncedCalendarEventId || []];
|
|
@@ -12440,9 +12844,9 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12440
12844
|
} else {
|
|
12441
12845
|
syncIds.push(syncEvent);
|
|
12442
12846
|
}
|
|
12443
|
-
await (0,
|
|
12847
|
+
await (0, import_firestore41.updateDoc)(eventRef, {
|
|
12444
12848
|
syncedCalendarEventId: syncIds,
|
|
12445
|
-
updatedAt: (0,
|
|
12849
|
+
updatedAt: (0, import_firestore40.serverTimestamp)()
|
|
12446
12850
|
});
|
|
12447
12851
|
console.log(
|
|
12448
12852
|
`Updated event ${eventId} with sync ID ${syncEvent.eventId}`
|
|
@@ -12466,8 +12870,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12466
12870
|
* @returns Working hours for the clinic
|
|
12467
12871
|
*/
|
|
12468
12872
|
async getClinicWorkingHours(clinicId, date) {
|
|
12469
|
-
const clinicRef = (0,
|
|
12470
|
-
const clinicDoc = await (0,
|
|
12873
|
+
const clinicRef = (0, import_firestore41.doc)(this.db, CLINICS_COLLECTION, clinicId);
|
|
12874
|
+
const clinicDoc = await (0, import_firestore41.getDoc)(clinicRef);
|
|
12471
12875
|
if (!clinicDoc.exists()) {
|
|
12472
12876
|
throw new Error(`Clinic with ID ${clinicId} not found`);
|
|
12473
12877
|
}
|
|
@@ -12495,8 +12899,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12495
12899
|
* @returns Doctor's schedule
|
|
12496
12900
|
*/
|
|
12497
12901
|
async getDoctorSchedule(doctorId, date) {
|
|
12498
|
-
const practitionerRef = (0,
|
|
12499
|
-
const practitionerDoc = await (0,
|
|
12902
|
+
const practitionerRef = (0, import_firestore41.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
|
|
12903
|
+
const practitionerDoc = await (0, import_firestore41.getDoc)(practitionerRef);
|
|
12500
12904
|
if (!practitionerDoc.exists()) {
|
|
12501
12905
|
throw new Error(`Doctor with ID ${doctorId} not found`);
|
|
12502
12906
|
}
|
|
@@ -12528,19 +12932,19 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12528
12932
|
startOfDay.setHours(0, 0, 0, 0);
|
|
12529
12933
|
const endOfDay = new Date(date);
|
|
12530
12934
|
endOfDay.setHours(23, 59, 59, 999);
|
|
12531
|
-
const appointmentsRef = (0,
|
|
12532
|
-
const q = (0,
|
|
12935
|
+
const appointmentsRef = (0, import_firestore41.collection)(this.db, CALENDAR_COLLECTION);
|
|
12936
|
+
const q = (0, import_firestore41.query)(
|
|
12533
12937
|
appointmentsRef,
|
|
12534
|
-
(0,
|
|
12535
|
-
(0,
|
|
12536
|
-
(0,
|
|
12537
|
-
(0,
|
|
12938
|
+
(0, import_firestore41.where)("practitionerProfileId", "==", doctorId),
|
|
12939
|
+
(0, import_firestore41.where)("eventTime.start", ">=", import_firestore40.Timestamp.fromDate(startOfDay)),
|
|
12940
|
+
(0, import_firestore41.where)("eventTime.start", "<=", import_firestore40.Timestamp.fromDate(endOfDay)),
|
|
12941
|
+
(0, import_firestore41.where)("status", "in", [
|
|
12538
12942
|
"confirmed" /* CONFIRMED */,
|
|
12539
12943
|
"pending" /* PENDING */
|
|
12540
12944
|
])
|
|
12541
12945
|
);
|
|
12542
|
-
const querySnapshot = await (0,
|
|
12543
|
-
return querySnapshot.docs.map((
|
|
12946
|
+
const querySnapshot = await (0, import_firestore41.getDocs)(q);
|
|
12947
|
+
return querySnapshot.docs.map((doc35) => doc35.data());
|
|
12544
12948
|
}
|
|
12545
12949
|
/**
|
|
12546
12950
|
* Calculates available time slots based on working hours, schedule and existing appointments
|
|
@@ -12597,11 +13001,11 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12597
13001
|
var _a;
|
|
12598
13002
|
try {
|
|
12599
13003
|
const [clinicDoc, practitionerDoc, patientDoc, patientSensitiveInfoDoc] = await Promise.all([
|
|
12600
|
-
(0,
|
|
12601
|
-
(0,
|
|
12602
|
-
(0,
|
|
12603
|
-
(0,
|
|
12604
|
-
(0,
|
|
13004
|
+
(0, import_firestore41.getDoc)((0, import_firestore41.doc)(this.db, CLINICS_COLLECTION, clinicId)),
|
|
13005
|
+
(0, import_firestore41.getDoc)((0, import_firestore41.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId)),
|
|
13006
|
+
(0, import_firestore41.getDoc)((0, import_firestore41.doc)(this.db, PATIENTS_COLLECTION, patientId)),
|
|
13007
|
+
(0, import_firestore41.getDoc)(
|
|
13008
|
+
(0, import_firestore41.doc)(
|
|
12605
13009
|
this.db,
|
|
12606
13010
|
PATIENTS_COLLECTION,
|
|
12607
13011
|
patientId,
|
|
@@ -12634,7 +13038,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12634
13038
|
fullName: `${sensitiveData.firstName} ${sensitiveData.lastName}`,
|
|
12635
13039
|
email: sensitiveData.email || "",
|
|
12636
13040
|
phone: sensitiveData.phoneNumber || null,
|
|
12637
|
-
dateOfBirth: sensitiveData.dateOfBirth ||
|
|
13041
|
+
dateOfBirth: sensitiveData.dateOfBirth || import_firestore40.Timestamp.now(),
|
|
12638
13042
|
gender: sensitiveData.gender || "other" /* OTHER */
|
|
12639
13043
|
};
|
|
12640
13044
|
} else if (patientDoc.exists()) {
|
|
@@ -12643,7 +13047,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12643
13047
|
fullName: patientDoc.data().displayName,
|
|
12644
13048
|
email: ((_a = patientDoc.data().contactInfo) == null ? void 0 : _a.email) || "",
|
|
12645
13049
|
phone: patientDoc.data().phoneNumber || null,
|
|
12646
|
-
dateOfBirth: patientDoc.data().dateOfBirth ||
|
|
13050
|
+
dateOfBirth: patientDoc.data().dateOfBirth || import_firestore40.Timestamp.now(),
|
|
12647
13051
|
gender: patientDoc.data().gender || "other" /* OTHER */
|
|
12648
13052
|
};
|
|
12649
13053
|
}
|
|
@@ -12665,7 +13069,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12665
13069
|
};
|
|
12666
13070
|
|
|
12667
13071
|
// src/services/reviews/reviews.service.ts
|
|
12668
|
-
var
|
|
13072
|
+
var import_firestore42 = require("firebase/firestore");
|
|
12669
13073
|
|
|
12670
13074
|
// src/types/reviews/index.ts
|
|
12671
13075
|
var REVIEWS_COLLECTION = "reviews";
|
|
@@ -12750,11 +13154,11 @@ var ReviewService = class extends BaseService {
|
|
|
12750
13154
|
updatedAt: now
|
|
12751
13155
|
};
|
|
12752
13156
|
reviewSchema.parse(review);
|
|
12753
|
-
const docRef = (0,
|
|
12754
|
-
await (0,
|
|
13157
|
+
const docRef = (0, import_firestore42.doc)(this.db, REVIEWS_COLLECTION, reviewId);
|
|
13158
|
+
await (0, import_firestore42.setDoc)(docRef, {
|
|
12755
13159
|
...review,
|
|
12756
|
-
createdAt: (0,
|
|
12757
|
-
updatedAt: (0,
|
|
13160
|
+
createdAt: (0, import_firestore42.serverTimestamp)(),
|
|
13161
|
+
updatedAt: (0, import_firestore42.serverTimestamp)()
|
|
12758
13162
|
});
|
|
12759
13163
|
return review;
|
|
12760
13164
|
} catch (error) {
|
|
@@ -12770,8 +13174,8 @@ var ReviewService = class extends BaseService {
|
|
|
12770
13174
|
* @returns The review if found, null otherwise
|
|
12771
13175
|
*/
|
|
12772
13176
|
async getReview(reviewId) {
|
|
12773
|
-
const docRef = (0,
|
|
12774
|
-
const docSnap = await (0,
|
|
13177
|
+
const docRef = (0, import_firestore42.doc)(this.db, REVIEWS_COLLECTION, reviewId);
|
|
13178
|
+
const docSnap = await (0, import_firestore42.getDoc)(docRef);
|
|
12775
13179
|
if (!docSnap.exists()) {
|
|
12776
13180
|
return null;
|
|
12777
13181
|
}
|
|
@@ -12783,12 +13187,12 @@ var ReviewService = class extends BaseService {
|
|
|
12783
13187
|
* @returns Array of reviews for the patient
|
|
12784
13188
|
*/
|
|
12785
13189
|
async getReviewsByPatient(patientId) {
|
|
12786
|
-
const q = (0,
|
|
12787
|
-
(0,
|
|
12788
|
-
(0,
|
|
13190
|
+
const q = (0, import_firestore42.query)(
|
|
13191
|
+
(0, import_firestore42.collection)(this.db, REVIEWS_COLLECTION),
|
|
13192
|
+
(0, import_firestore42.where)("patientId", "==", patientId)
|
|
12789
13193
|
);
|
|
12790
|
-
const snapshot = await (0,
|
|
12791
|
-
return snapshot.docs.map((
|
|
13194
|
+
const snapshot = await (0, import_firestore42.getDocs)(q);
|
|
13195
|
+
return snapshot.docs.map((doc35) => doc35.data());
|
|
12792
13196
|
}
|
|
12793
13197
|
/**
|
|
12794
13198
|
* Gets all reviews for a specific clinic
|
|
@@ -12796,12 +13200,12 @@ var ReviewService = class extends BaseService {
|
|
|
12796
13200
|
* @returns Array of reviews containing clinic reviews
|
|
12797
13201
|
*/
|
|
12798
13202
|
async getReviewsByClinic(clinicId) {
|
|
12799
|
-
const q = (0,
|
|
12800
|
-
(0,
|
|
12801
|
-
(0,
|
|
13203
|
+
const q = (0, import_firestore42.query)(
|
|
13204
|
+
(0, import_firestore42.collection)(this.db, REVIEWS_COLLECTION),
|
|
13205
|
+
(0, import_firestore42.where)("clinicReview.clinicId", "==", clinicId)
|
|
12802
13206
|
);
|
|
12803
|
-
const snapshot = await (0,
|
|
12804
|
-
return snapshot.docs.map((
|
|
13207
|
+
const snapshot = await (0, import_firestore42.getDocs)(q);
|
|
13208
|
+
return snapshot.docs.map((doc35) => doc35.data());
|
|
12805
13209
|
}
|
|
12806
13210
|
/**
|
|
12807
13211
|
* Gets all reviews for a specific practitioner
|
|
@@ -12809,12 +13213,12 @@ var ReviewService = class extends BaseService {
|
|
|
12809
13213
|
* @returns Array of reviews containing practitioner reviews
|
|
12810
13214
|
*/
|
|
12811
13215
|
async getReviewsByPractitioner(practitionerId) {
|
|
12812
|
-
const q = (0,
|
|
12813
|
-
(0,
|
|
12814
|
-
(0,
|
|
13216
|
+
const q = (0, import_firestore42.query)(
|
|
13217
|
+
(0, import_firestore42.collection)(this.db, REVIEWS_COLLECTION),
|
|
13218
|
+
(0, import_firestore42.where)("practitionerReview.practitionerId", "==", practitionerId)
|
|
12815
13219
|
);
|
|
12816
|
-
const snapshot = await (0,
|
|
12817
|
-
return snapshot.docs.map((
|
|
13220
|
+
const snapshot = await (0, import_firestore42.getDocs)(q);
|
|
13221
|
+
return snapshot.docs.map((doc35) => doc35.data());
|
|
12818
13222
|
}
|
|
12819
13223
|
/**
|
|
12820
13224
|
* Gets all reviews for a specific procedure
|
|
@@ -12822,12 +13226,12 @@ var ReviewService = class extends BaseService {
|
|
|
12822
13226
|
* @returns Array of reviews containing procedure reviews
|
|
12823
13227
|
*/
|
|
12824
13228
|
async getReviewsByProcedure(procedureId) {
|
|
12825
|
-
const q = (0,
|
|
12826
|
-
(0,
|
|
12827
|
-
(0,
|
|
13229
|
+
const q = (0, import_firestore42.query)(
|
|
13230
|
+
(0, import_firestore42.collection)(this.db, REVIEWS_COLLECTION),
|
|
13231
|
+
(0, import_firestore42.where)("procedureReview.procedureId", "==", procedureId)
|
|
12828
13232
|
);
|
|
12829
|
-
const snapshot = await (0,
|
|
12830
|
-
return snapshot.docs.map((
|
|
13233
|
+
const snapshot = await (0, import_firestore42.getDocs)(q);
|
|
13234
|
+
return snapshot.docs.map((doc35) => doc35.data());
|
|
12831
13235
|
}
|
|
12832
13236
|
/**
|
|
12833
13237
|
* Gets all reviews for a specific appointment
|
|
@@ -12835,11 +13239,11 @@ var ReviewService = class extends BaseService {
|
|
|
12835
13239
|
* @returns The review for the appointment if found, null otherwise
|
|
12836
13240
|
*/
|
|
12837
13241
|
async getReviewByAppointment(appointmentId) {
|
|
12838
|
-
const q = (0,
|
|
12839
|
-
(0,
|
|
12840
|
-
(0,
|
|
13242
|
+
const q = (0, import_firestore42.query)(
|
|
13243
|
+
(0, import_firestore42.collection)(this.db, REVIEWS_COLLECTION),
|
|
13244
|
+
(0, import_firestore42.where)("appointmentId", "==", appointmentId)
|
|
12841
13245
|
);
|
|
12842
|
-
const snapshot = await (0,
|
|
13246
|
+
const snapshot = await (0, import_firestore42.getDocs)(q);
|
|
12843
13247
|
if (snapshot.empty) {
|
|
12844
13248
|
return null;
|
|
12845
13249
|
}
|
|
@@ -12854,7 +13258,7 @@ var ReviewService = class extends BaseService {
|
|
|
12854
13258
|
if (!review) {
|
|
12855
13259
|
throw new Error(`Review with ID ${reviewId} not found`);
|
|
12856
13260
|
}
|
|
12857
|
-
await (0,
|
|
13261
|
+
await (0, import_firestore42.deleteDoc)((0, import_firestore42.doc)(this.db, REVIEWS_COLLECTION, reviewId));
|
|
12858
13262
|
}
|
|
12859
13263
|
/**
|
|
12860
13264
|
* Calculates the average of an array of numbers
|
|
@@ -12872,11 +13276,11 @@ var ReviewService = class extends BaseService {
|
|
|
12872
13276
|
};
|
|
12873
13277
|
|
|
12874
13278
|
// src/services/appointment/appointment.service.ts
|
|
12875
|
-
var
|
|
13279
|
+
var import_firestore44 = require("firebase/firestore");
|
|
12876
13280
|
var import_functions2 = require("firebase/functions");
|
|
12877
13281
|
|
|
12878
13282
|
// src/services/appointment/utils/appointment.utils.ts
|
|
12879
|
-
var
|
|
13283
|
+
var import_firestore43 = require("firebase/firestore");
|
|
12880
13284
|
|
|
12881
13285
|
// src/backoffice/types/technology.types.ts
|
|
12882
13286
|
var TECHNOLOGIES_COLLECTION = "technologies";
|
|
@@ -12884,8 +13288,8 @@ var TECHNOLOGIES_COLLECTION = "technologies";
|
|
|
12884
13288
|
// src/services/appointment/utils/appointment.utils.ts
|
|
12885
13289
|
async function updateAppointmentUtil2(db, appointmentId, data) {
|
|
12886
13290
|
try {
|
|
12887
|
-
const appointmentRef = (0,
|
|
12888
|
-
const appointmentDoc = await (0,
|
|
13291
|
+
const appointmentRef = (0, import_firestore43.doc)(db, APPOINTMENTS_COLLECTION, appointmentId);
|
|
13292
|
+
const appointmentDoc = await (0, import_firestore43.getDoc)(appointmentRef);
|
|
12889
13293
|
if (!appointmentDoc.exists()) {
|
|
12890
13294
|
throw new Error(`Appointment with ID ${appointmentId} not found`);
|
|
12891
13295
|
}
|
|
@@ -12934,7 +13338,7 @@ async function updateAppointmentUtil2(db, appointmentId, data) {
|
|
|
12934
13338
|
...data,
|
|
12935
13339
|
completedPreRequirements,
|
|
12936
13340
|
completedPostRequirements,
|
|
12937
|
-
updatedAt: (0,
|
|
13341
|
+
updatedAt: (0, import_firestore43.serverTimestamp)()
|
|
12938
13342
|
};
|
|
12939
13343
|
Object.keys(updateData).forEach((key) => {
|
|
12940
13344
|
if (updateData[key] === void 0) {
|
|
@@ -12943,7 +13347,7 @@ async function updateAppointmentUtil2(db, appointmentId, data) {
|
|
|
12943
13347
|
});
|
|
12944
13348
|
if (data.status && data.status !== currentAppointment.status) {
|
|
12945
13349
|
if (data.status === "confirmed" /* CONFIRMED */ && !updateData.confirmationTime) {
|
|
12946
|
-
updateData.confirmationTime =
|
|
13350
|
+
updateData.confirmationTime = import_firestore43.Timestamp.now();
|
|
12947
13351
|
}
|
|
12948
13352
|
if (currentAppointment.calendarEventId) {
|
|
12949
13353
|
await updateCalendarEventStatus(
|
|
@@ -12953,8 +13357,8 @@ async function updateAppointmentUtil2(db, appointmentId, data) {
|
|
|
12953
13357
|
);
|
|
12954
13358
|
}
|
|
12955
13359
|
}
|
|
12956
|
-
await (0,
|
|
12957
|
-
const updatedAppointmentDoc = await (0,
|
|
13360
|
+
await (0, import_firestore43.updateDoc)(appointmentRef, updateData);
|
|
13361
|
+
const updatedAppointmentDoc = await (0, import_firestore43.getDoc)(appointmentRef);
|
|
12958
13362
|
if (!updatedAppointmentDoc.exists()) {
|
|
12959
13363
|
throw new Error(
|
|
12960
13364
|
`Failed to retrieve updated appointment ${appointmentId}`
|
|
@@ -12968,8 +13372,8 @@ async function updateAppointmentUtil2(db, appointmentId, data) {
|
|
|
12968
13372
|
}
|
|
12969
13373
|
async function updateCalendarEventStatus(db, calendarEventId, appointmentStatus) {
|
|
12970
13374
|
try {
|
|
12971
|
-
const calendarEventRef = (0,
|
|
12972
|
-
const calendarEventDoc = await (0,
|
|
13375
|
+
const calendarEventRef = (0, import_firestore43.doc)(db, CALENDAR_COLLECTION, calendarEventId);
|
|
13376
|
+
const calendarEventDoc = await (0, import_firestore43.getDoc)(calendarEventRef);
|
|
12973
13377
|
if (!calendarEventDoc.exists()) {
|
|
12974
13378
|
console.warn(`Calendar event with ID ${calendarEventId} not found`);
|
|
12975
13379
|
return;
|
|
@@ -12992,9 +13396,9 @@ async function updateCalendarEventStatus(db, calendarEventId, appointmentStatus)
|
|
|
12992
13396
|
default:
|
|
12993
13397
|
return;
|
|
12994
13398
|
}
|
|
12995
|
-
await (0,
|
|
13399
|
+
await (0, import_firestore43.updateDoc)(calendarEventRef, {
|
|
12996
13400
|
status: calendarStatus,
|
|
12997
|
-
updatedAt: (0,
|
|
13401
|
+
updatedAt: (0, import_firestore43.serverTimestamp)()
|
|
12998
13402
|
});
|
|
12999
13403
|
} catch (error) {
|
|
13000
13404
|
console.error(`Error updating calendar event ${calendarEventId}:`, error);
|
|
@@ -13002,8 +13406,8 @@ async function updateCalendarEventStatus(db, calendarEventId, appointmentStatus)
|
|
|
13002
13406
|
}
|
|
13003
13407
|
async function getAppointmentByIdUtil(db, appointmentId) {
|
|
13004
13408
|
try {
|
|
13005
|
-
const appointmentDoc = await (0,
|
|
13006
|
-
(0,
|
|
13409
|
+
const appointmentDoc = await (0, import_firestore43.getDoc)(
|
|
13410
|
+
(0, import_firestore43.doc)(db, APPOINTMENTS_COLLECTION, appointmentId)
|
|
13007
13411
|
);
|
|
13008
13412
|
if (!appointmentDoc.exists()) {
|
|
13009
13413
|
return null;
|
|
@@ -13018,46 +13422,46 @@ async function searchAppointmentsUtil(db, params) {
|
|
|
13018
13422
|
try {
|
|
13019
13423
|
const constraints = [];
|
|
13020
13424
|
if (params.patientId) {
|
|
13021
|
-
constraints.push((0,
|
|
13425
|
+
constraints.push((0, import_firestore43.where)("patientId", "==", params.patientId));
|
|
13022
13426
|
}
|
|
13023
13427
|
if (params.practitionerId) {
|
|
13024
|
-
constraints.push((0,
|
|
13428
|
+
constraints.push((0, import_firestore43.where)("practitionerId", "==", params.practitionerId));
|
|
13025
13429
|
}
|
|
13026
13430
|
if (params.clinicBranchId) {
|
|
13027
|
-
constraints.push((0,
|
|
13431
|
+
constraints.push((0, import_firestore43.where)("clinicBranchId", "==", params.clinicBranchId));
|
|
13028
13432
|
}
|
|
13029
13433
|
if (params.startDate) {
|
|
13030
13434
|
constraints.push(
|
|
13031
|
-
(0,
|
|
13435
|
+
(0, import_firestore43.where)(
|
|
13032
13436
|
"appointmentStartTime",
|
|
13033
13437
|
">=",
|
|
13034
|
-
|
|
13438
|
+
import_firestore43.Timestamp.fromDate(params.startDate)
|
|
13035
13439
|
)
|
|
13036
13440
|
);
|
|
13037
13441
|
}
|
|
13038
13442
|
if (params.endDate) {
|
|
13039
13443
|
constraints.push(
|
|
13040
|
-
(0,
|
|
13444
|
+
(0, import_firestore43.where)("appointmentStartTime", "<=", import_firestore43.Timestamp.fromDate(params.endDate))
|
|
13041
13445
|
);
|
|
13042
13446
|
}
|
|
13043
13447
|
if (params.status) {
|
|
13044
13448
|
if (Array.isArray(params.status)) {
|
|
13045
|
-
constraints.push((0,
|
|
13449
|
+
constraints.push((0, import_firestore43.where)("status", "in", params.status));
|
|
13046
13450
|
} else {
|
|
13047
|
-
constraints.push((0,
|
|
13451
|
+
constraints.push((0, import_firestore43.where)("status", "==", params.status));
|
|
13048
13452
|
}
|
|
13049
13453
|
}
|
|
13050
|
-
constraints.push((0,
|
|
13454
|
+
constraints.push((0, import_firestore43.orderBy)("appointmentStartTime", "asc"));
|
|
13051
13455
|
if (params.limit) {
|
|
13052
|
-
constraints.push((0,
|
|
13456
|
+
constraints.push((0, import_firestore43.limit)(params.limit));
|
|
13053
13457
|
}
|
|
13054
13458
|
if (params.startAfter) {
|
|
13055
|
-
constraints.push((0,
|
|
13459
|
+
constraints.push((0, import_firestore43.startAfter)(params.startAfter));
|
|
13056
13460
|
}
|
|
13057
|
-
const q = (0,
|
|
13058
|
-
const querySnapshot = await (0,
|
|
13461
|
+
const q = (0, import_firestore43.query)((0, import_firestore43.collection)(db, APPOINTMENTS_COLLECTION), ...constraints);
|
|
13462
|
+
const querySnapshot = await (0, import_firestore43.getDocs)(q);
|
|
13059
13463
|
const appointments = querySnapshot.docs.map(
|
|
13060
|
-
(
|
|
13464
|
+
(doc35) => doc35.data()
|
|
13061
13465
|
);
|
|
13062
13466
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
13063
13467
|
return { appointments, lastDoc };
|
|
@@ -13426,7 +13830,7 @@ var AppointmentService = class extends BaseService {
|
|
|
13426
13830
|
);
|
|
13427
13831
|
const updateData = {
|
|
13428
13832
|
status: newStatus,
|
|
13429
|
-
updatedAt: (0,
|
|
13833
|
+
updatedAt: (0, import_firestore44.serverTimestamp)()
|
|
13430
13834
|
};
|
|
13431
13835
|
if (newStatus === "canceled_clinic" /* CANCELED_CLINIC */ || newStatus === "canceled_patient" /* CANCELED_PATIENT */ || newStatus === "canceled_patient_rescheduled" /* CANCELED_PATIENT_RESCHEDULED */) {
|
|
13432
13836
|
if (!(details == null ? void 0 : details.cancellationReason)) {
|
|
@@ -13437,13 +13841,13 @@ var AppointmentService = class extends BaseService {
|
|
|
13437
13841
|
}
|
|
13438
13842
|
updateData.cancellationReason = details.cancellationReason;
|
|
13439
13843
|
updateData.canceledBy = details.canceledBy;
|
|
13440
|
-
updateData.cancellationTime =
|
|
13844
|
+
updateData.cancellationTime = import_firestore44.Timestamp.now();
|
|
13441
13845
|
}
|
|
13442
13846
|
if (newStatus === "confirmed" /* CONFIRMED */) {
|
|
13443
|
-
updateData.confirmationTime =
|
|
13847
|
+
updateData.confirmationTime = import_firestore44.Timestamp.now();
|
|
13444
13848
|
}
|
|
13445
13849
|
if (newStatus === "rescheduled_by_clinic" /* RESCHEDULED_BY_CLINIC */) {
|
|
13446
|
-
updateData.rescheduleTime =
|
|
13850
|
+
updateData.rescheduleTime = import_firestore44.Timestamp.now();
|
|
13447
13851
|
}
|
|
13448
13852
|
return this.updateAppointment(appointmentId, updateData);
|
|
13449
13853
|
}
|
|
@@ -13521,9 +13925,9 @@ var AppointmentService = class extends BaseService {
|
|
|
13521
13925
|
status: "rescheduled_by_clinic" /* RESCHEDULED_BY_CLINIC */,
|
|
13522
13926
|
appointmentStartTime: startTimestamp,
|
|
13523
13927
|
appointmentEndTime: endTimestamp,
|
|
13524
|
-
rescheduleTime:
|
|
13928
|
+
rescheduleTime: import_firestore44.Timestamp.now(),
|
|
13525
13929
|
confirmationTime: null,
|
|
13526
|
-
updatedAt: (0,
|
|
13930
|
+
updatedAt: (0, import_firestore44.serverTimestamp)()
|
|
13527
13931
|
};
|
|
13528
13932
|
return this.updateAppointment(validatedParams.appointmentId, updateData);
|
|
13529
13933
|
}
|
|
@@ -13541,19 +13945,19 @@ var AppointmentService = class extends BaseService {
|
|
|
13541
13945
|
return value;
|
|
13542
13946
|
}
|
|
13543
13947
|
if (typeof value === "number") {
|
|
13544
|
-
return
|
|
13948
|
+
return import_firestore44.Timestamp.fromMillis(value);
|
|
13545
13949
|
}
|
|
13546
13950
|
if (typeof value === "string") {
|
|
13547
|
-
return
|
|
13951
|
+
return import_firestore44.Timestamp.fromDate(new Date(value));
|
|
13548
13952
|
}
|
|
13549
13953
|
if (value instanceof Date) {
|
|
13550
|
-
return
|
|
13954
|
+
return import_firestore44.Timestamp.fromDate(value);
|
|
13551
13955
|
}
|
|
13552
13956
|
if (value && typeof value._seconds === "number") {
|
|
13553
|
-
return new
|
|
13957
|
+
return new import_firestore44.Timestamp(value._seconds, value._nanoseconds || 0);
|
|
13554
13958
|
}
|
|
13555
13959
|
if (value && typeof value.seconds === "number") {
|
|
13556
|
-
return new
|
|
13960
|
+
return new import_firestore44.Timestamp(value.seconds, value.nanoseconds || 0);
|
|
13557
13961
|
}
|
|
13558
13962
|
throw new Error(
|
|
13559
13963
|
`Invalid timestamp format: ${typeof value}, value: ${JSON.stringify(
|
|
@@ -13652,9 +14056,9 @@ var AppointmentService = class extends BaseService {
|
|
|
13652
14056
|
}
|
|
13653
14057
|
const updateData = {
|
|
13654
14058
|
status: "in_progress" /* IN_PROGRESS */,
|
|
13655
|
-
procedureActualStartTime:
|
|
14059
|
+
procedureActualStartTime: import_firestore44.Timestamp.now(),
|
|
13656
14060
|
// Set actual start time
|
|
13657
|
-
updatedAt: (0,
|
|
14061
|
+
updatedAt: (0, import_firestore44.serverTimestamp)()
|
|
13658
14062
|
};
|
|
13659
14063
|
return this.updateAppointment(appointmentId, updateData);
|
|
13660
14064
|
}
|
|
@@ -13672,7 +14076,7 @@ var AppointmentService = class extends BaseService {
|
|
|
13672
14076
|
if (!appointment)
|
|
13673
14077
|
throw new Error(`Appointment ${appointmentId} not found.`);
|
|
13674
14078
|
let calculatedDurationMinutes = actualDurationMinutesInput;
|
|
13675
|
-
const procedureCompletionTime =
|
|
14079
|
+
const procedureCompletionTime = import_firestore44.Timestamp.now();
|
|
13676
14080
|
if (calculatedDurationMinutes === void 0 && appointment.procedureActualStartTime) {
|
|
13677
14081
|
const startTimeMillis = appointment.procedureActualStartTime.toMillis();
|
|
13678
14082
|
const endTimeMillis = procedureCompletionTime.toMillis();
|
|
@@ -13695,7 +14099,7 @@ var AppointmentService = class extends BaseService {
|
|
|
13695
14099
|
},
|
|
13696
14100
|
// Optionally update appointmentEndTime to the actual completion time
|
|
13697
14101
|
// appointmentEndTime: procedureCompletionTime,
|
|
13698
|
-
updatedAt: (0,
|
|
14102
|
+
updatedAt: (0, import_firestore44.serverTimestamp)()
|
|
13699
14103
|
};
|
|
13700
14104
|
return this.updateAppointment(appointmentId, updateData);
|
|
13701
14105
|
}
|
|
@@ -13709,7 +14113,7 @@ var AppointmentService = class extends BaseService {
|
|
|
13709
14113
|
const appointment = await this.getAppointmentById(appointmentId);
|
|
13710
14114
|
if (!appointment)
|
|
13711
14115
|
throw new Error(`Appointment ${appointmentId} not found.`);
|
|
13712
|
-
if (
|
|
14116
|
+
if (import_firestore44.Timestamp.now().toMillis() < appointment.appointmentStartTime.toMillis()) {
|
|
13713
14117
|
throw new Error("Cannot mark no-show before appointment start time.");
|
|
13714
14118
|
}
|
|
13715
14119
|
return this.updateAppointmentStatus(
|
|
@@ -13733,12 +14137,12 @@ var AppointmentService = class extends BaseService {
|
|
|
13733
14137
|
const newMediaItem = {
|
|
13734
14138
|
...mediaItemData,
|
|
13735
14139
|
id: this.generateId(),
|
|
13736
|
-
uploadedAt:
|
|
14140
|
+
uploadedAt: import_firestore44.Timestamp.now(),
|
|
13737
14141
|
uploadedBy: currentUser.uid
|
|
13738
14142
|
};
|
|
13739
14143
|
const updateData = {
|
|
13740
|
-
media: (0,
|
|
13741
|
-
updatedAt: (0,
|
|
14144
|
+
media: (0, import_firestore44.arrayUnion)(newMediaItem),
|
|
14145
|
+
updatedAt: (0, import_firestore44.serverTimestamp)()
|
|
13742
14146
|
};
|
|
13743
14147
|
return this.updateAppointment(appointmentId, updateData);
|
|
13744
14148
|
}
|
|
@@ -13758,8 +14162,8 @@ var AppointmentService = class extends BaseService {
|
|
|
13758
14162
|
throw new Error(`Media item ${mediaItemId} not found in appointment.`);
|
|
13759
14163
|
}
|
|
13760
14164
|
const updateData = {
|
|
13761
|
-
media: (0,
|
|
13762
|
-
updatedAt: (0,
|
|
14165
|
+
media: (0, import_firestore44.arrayRemove)(mediaToRemove),
|
|
14166
|
+
updatedAt: (0, import_firestore44.serverTimestamp)()
|
|
13763
14167
|
};
|
|
13764
14168
|
return this.updateAppointment(appointmentId, updateData);
|
|
13765
14169
|
}
|
|
@@ -13773,11 +14177,11 @@ var AppointmentService = class extends BaseService {
|
|
|
13773
14177
|
const newReviewInfo = {
|
|
13774
14178
|
...reviewData,
|
|
13775
14179
|
reviewId: this.generateId(),
|
|
13776
|
-
reviewedAt:
|
|
14180
|
+
reviewedAt: import_firestore44.Timestamp.now()
|
|
13777
14181
|
};
|
|
13778
14182
|
const updateData = {
|
|
13779
14183
|
reviewInfo: newReviewInfo,
|
|
13780
|
-
updatedAt: (0,
|
|
14184
|
+
updatedAt: (0, import_firestore44.serverTimestamp)()
|
|
13781
14185
|
};
|
|
13782
14186
|
return this.updateAppointment(appointmentId, updateData);
|
|
13783
14187
|
}
|
|
@@ -13791,7 +14195,7 @@ var AppointmentService = class extends BaseService {
|
|
|
13791
14195
|
const updateData = {
|
|
13792
14196
|
paymentStatus,
|
|
13793
14197
|
paymentTransactionId: paymentTransactionId || null,
|
|
13794
|
-
updatedAt: (0,
|
|
14198
|
+
updatedAt: (0, import_firestore44.serverTimestamp)()
|
|
13795
14199
|
};
|
|
13796
14200
|
return this.updateAppointment(appointmentId, updateData);
|
|
13797
14201
|
}
|
|
@@ -13833,38 +14237,38 @@ var AppointmentService = class extends BaseService {
|
|
|
13833
14237
|
"rescheduled_by_clinic" /* RESCHEDULED_BY_CLINIC */
|
|
13834
14238
|
];
|
|
13835
14239
|
const constraints = [];
|
|
13836
|
-
constraints.push((0,
|
|
13837
|
-
constraints.push((0,
|
|
14240
|
+
constraints.push((0, import_firestore44.where)("patientId", "==", patientId));
|
|
14241
|
+
constraints.push((0, import_firestore44.where)("status", "in", upcomingStatuses));
|
|
13838
14242
|
constraints.push(
|
|
13839
|
-
(0,
|
|
14243
|
+
(0, import_firestore44.where)(
|
|
13840
14244
|
"appointmentStartTime",
|
|
13841
14245
|
">=",
|
|
13842
|
-
|
|
14246
|
+
import_firestore44.Timestamp.fromDate(effectiveStartDate)
|
|
13843
14247
|
)
|
|
13844
14248
|
);
|
|
13845
14249
|
if (options == null ? void 0 : options.endDate) {
|
|
13846
14250
|
constraints.push(
|
|
13847
|
-
(0,
|
|
14251
|
+
(0, import_firestore44.where)(
|
|
13848
14252
|
"appointmentStartTime",
|
|
13849
14253
|
"<=",
|
|
13850
|
-
|
|
14254
|
+
import_firestore44.Timestamp.fromDate(options.endDate)
|
|
13851
14255
|
)
|
|
13852
14256
|
);
|
|
13853
14257
|
}
|
|
13854
|
-
constraints.push((0,
|
|
14258
|
+
constraints.push((0, import_firestore44.orderBy)("appointmentStartTime", "asc"));
|
|
13855
14259
|
if (options == null ? void 0 : options.limit) {
|
|
13856
|
-
constraints.push((0,
|
|
14260
|
+
constraints.push((0, import_firestore44.limit)(options.limit));
|
|
13857
14261
|
}
|
|
13858
14262
|
if (options == null ? void 0 : options.startAfter) {
|
|
13859
|
-
constraints.push((0,
|
|
14263
|
+
constraints.push((0, import_firestore44.startAfter)(options.startAfter));
|
|
13860
14264
|
}
|
|
13861
|
-
const q = (0,
|
|
13862
|
-
(0,
|
|
14265
|
+
const q = (0, import_firestore44.query)(
|
|
14266
|
+
(0, import_firestore44.collection)(this.db, APPOINTMENTS_COLLECTION),
|
|
13863
14267
|
...constraints
|
|
13864
14268
|
);
|
|
13865
|
-
const querySnapshot = await (0,
|
|
14269
|
+
const querySnapshot = await (0, import_firestore44.getDocs)(q);
|
|
13866
14270
|
const appointments = querySnapshot.docs.map(
|
|
13867
|
-
(
|
|
14271
|
+
(doc35) => doc35.data()
|
|
13868
14272
|
);
|
|
13869
14273
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
13870
14274
|
console.log(
|
|
@@ -13906,38 +14310,38 @@ var AppointmentService = class extends BaseService {
|
|
|
13906
14310
|
pastStatuses.push("no_show" /* NO_SHOW */);
|
|
13907
14311
|
}
|
|
13908
14312
|
const constraints = [];
|
|
13909
|
-
constraints.push((0,
|
|
13910
|
-
constraints.push((0,
|
|
14313
|
+
constraints.push((0, import_firestore44.where)("patientId", "==", patientId));
|
|
14314
|
+
constraints.push((0, import_firestore44.where)("status", "in", pastStatuses));
|
|
13911
14315
|
if (options == null ? void 0 : options.startDate) {
|
|
13912
14316
|
constraints.push(
|
|
13913
|
-
(0,
|
|
14317
|
+
(0, import_firestore44.where)(
|
|
13914
14318
|
"appointmentStartTime",
|
|
13915
14319
|
">=",
|
|
13916
|
-
|
|
14320
|
+
import_firestore44.Timestamp.fromDate(options.startDate)
|
|
13917
14321
|
)
|
|
13918
14322
|
);
|
|
13919
14323
|
}
|
|
13920
14324
|
constraints.push(
|
|
13921
|
-
(0,
|
|
14325
|
+
(0, import_firestore44.where)(
|
|
13922
14326
|
"appointmentStartTime",
|
|
13923
14327
|
"<=",
|
|
13924
|
-
|
|
14328
|
+
import_firestore44.Timestamp.fromDate(effectiveEndDate)
|
|
13925
14329
|
)
|
|
13926
14330
|
);
|
|
13927
|
-
constraints.push((0,
|
|
14331
|
+
constraints.push((0, import_firestore44.orderBy)("appointmentStartTime", "desc"));
|
|
13928
14332
|
if (options == null ? void 0 : options.limit) {
|
|
13929
|
-
constraints.push((0,
|
|
14333
|
+
constraints.push((0, import_firestore44.limit)(options.limit));
|
|
13930
14334
|
}
|
|
13931
14335
|
if (options == null ? void 0 : options.startAfter) {
|
|
13932
|
-
constraints.push((0,
|
|
14336
|
+
constraints.push((0, import_firestore44.startAfter)(options.startAfter));
|
|
13933
14337
|
}
|
|
13934
|
-
const q = (0,
|
|
13935
|
-
(0,
|
|
14338
|
+
const q = (0, import_firestore44.query)(
|
|
14339
|
+
(0, import_firestore44.collection)(this.db, APPOINTMENTS_COLLECTION),
|
|
13936
14340
|
...constraints
|
|
13937
14341
|
);
|
|
13938
|
-
const querySnapshot = await (0,
|
|
14342
|
+
const querySnapshot = await (0, import_firestore44.getDocs)(q);
|
|
13939
14343
|
const appointments = querySnapshot.docs.map(
|
|
13940
|
-
(
|
|
14344
|
+
(doc35) => doc35.data()
|
|
13941
14345
|
);
|
|
13942
14346
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
13943
14347
|
console.log(
|
|
@@ -13955,7 +14359,7 @@ var AppointmentService = class extends BaseService {
|
|
|
13955
14359
|
};
|
|
13956
14360
|
|
|
13957
14361
|
// src/services/patient/patientRequirements.service.ts
|
|
13958
|
-
var
|
|
14362
|
+
var import_firestore45 = require("firebase/firestore");
|
|
13959
14363
|
|
|
13960
14364
|
// src/types/patient/patient-requirements.ts
|
|
13961
14365
|
var PatientInstructionStatus = /* @__PURE__ */ ((PatientInstructionStatus2) => {
|
|
@@ -13985,13 +14389,13 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
13985
14389
|
super(db, auth, app);
|
|
13986
14390
|
}
|
|
13987
14391
|
getPatientRequirementsCollectionRef(patientId) {
|
|
13988
|
-
return (0,
|
|
14392
|
+
return (0, import_firestore45.collection)(
|
|
13989
14393
|
this.db,
|
|
13990
14394
|
`patients/${patientId}/${PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME}`
|
|
13991
14395
|
);
|
|
13992
14396
|
}
|
|
13993
14397
|
getPatientRequirementDocRef(patientId, instanceId) {
|
|
13994
|
-
return (0,
|
|
14398
|
+
return (0, import_firestore45.doc)(
|
|
13995
14399
|
this.getPatientRequirementsCollectionRef(patientId),
|
|
13996
14400
|
instanceId
|
|
13997
14401
|
);
|
|
@@ -14004,7 +14408,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
14004
14408
|
*/
|
|
14005
14409
|
async getPatientRequirementInstance(patientId, instanceId) {
|
|
14006
14410
|
const docRef = this.getPatientRequirementDocRef(patientId, instanceId);
|
|
14007
|
-
const docSnap = await (0,
|
|
14411
|
+
const docSnap = await (0, import_firestore45.getDoc)(docRef);
|
|
14008
14412
|
if (!docSnap.exists()) {
|
|
14009
14413
|
return null;
|
|
14010
14414
|
}
|
|
@@ -14023,22 +14427,22 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
14023
14427
|
*/
|
|
14024
14428
|
async getAllPatientRequirementInstances(patientId, filters, pageLimit = 20, lastVisible) {
|
|
14025
14429
|
const collRef = this.getPatientRequirementsCollectionRef(patientId);
|
|
14026
|
-
let q = (0,
|
|
14430
|
+
let q = (0, import_firestore45.query)(collRef, (0, import_firestore45.orderBy)("createdAt", "desc"));
|
|
14027
14431
|
const queryConstraints = [];
|
|
14028
14432
|
if ((filters == null ? void 0 : filters.appointmentId) && filters.appointmentId !== "all") {
|
|
14029
14433
|
queryConstraints.push(
|
|
14030
|
-
(0,
|
|
14434
|
+
(0, import_firestore45.where)("appointmentId", "==", filters.appointmentId)
|
|
14031
14435
|
);
|
|
14032
14436
|
}
|
|
14033
14437
|
if ((filters == null ? void 0 : filters.statuses) && filters.statuses.length > 0) {
|
|
14034
|
-
queryConstraints.push((0,
|
|
14438
|
+
queryConstraints.push((0, import_firestore45.where)("overallStatus", "in", filters.statuses));
|
|
14035
14439
|
}
|
|
14036
14440
|
if (lastVisible) {
|
|
14037
|
-
queryConstraints.push((0,
|
|
14441
|
+
queryConstraints.push((0, import_firestore45.startAfter)(lastVisible));
|
|
14038
14442
|
}
|
|
14039
|
-
queryConstraints.push((0,
|
|
14040
|
-
q = (0,
|
|
14041
|
-
const snapshot = await (0,
|
|
14443
|
+
queryConstraints.push((0, import_firestore45.limit)(pageLimit));
|
|
14444
|
+
q = (0, import_firestore45.query)(collRef, ...queryConstraints);
|
|
14445
|
+
const snapshot = await (0, import_firestore45.getDocs)(q);
|
|
14042
14446
|
let requirements = snapshot.docs.map((docSnap) => {
|
|
14043
14447
|
const data = docSnap.data();
|
|
14044
14448
|
return { id: docSnap.id, ...data };
|
|
@@ -14081,7 +14485,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
14081
14485
|
*/
|
|
14082
14486
|
async completeInstruction(patientId, instanceId, instructionId) {
|
|
14083
14487
|
const instanceRef = this.getPatientRequirementDocRef(patientId, instanceId);
|
|
14084
|
-
const instanceSnap = await (0,
|
|
14488
|
+
const instanceSnap = await (0, import_firestore45.getDoc)(instanceRef);
|
|
14085
14489
|
if (!instanceSnap.exists()) {
|
|
14086
14490
|
throw new Error(
|
|
14087
14491
|
`PatientRequirementInstance ${instanceId} not found for patient ${patientId}.`
|
|
@@ -14109,7 +14513,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
14109
14513
|
`Instruction ${instructionId} is in status ${instructionToUpdate.status} and cannot be marked as completed.`
|
|
14110
14514
|
);
|
|
14111
14515
|
}
|
|
14112
|
-
const now =
|
|
14516
|
+
const now = import_firestore45.Timestamp.now();
|
|
14113
14517
|
const updatedInstructions = [...instance.instructions];
|
|
14114
14518
|
updatedInstructions[instructionIndex] = {
|
|
14115
14519
|
...instructionToUpdate,
|
|
@@ -14136,7 +14540,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
14136
14540
|
if (newOverallStatus !== instance.overallStatus) {
|
|
14137
14541
|
updatePayload.overallStatus = newOverallStatus;
|
|
14138
14542
|
}
|
|
14139
|
-
await (0,
|
|
14543
|
+
await (0, import_firestore45.updateDoc)(instanceRef, updatePayload);
|
|
14140
14544
|
return {
|
|
14141
14545
|
...instance,
|
|
14142
14546
|
instructions: updatedInstructions,
|
|
@@ -14149,7 +14553,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
14149
14553
|
};
|
|
14150
14554
|
|
|
14151
14555
|
// src/backoffice/services/brand.service.ts
|
|
14152
|
-
var
|
|
14556
|
+
var import_firestore46 = require("firebase/firestore");
|
|
14153
14557
|
|
|
14154
14558
|
// src/backoffice/types/brand.types.ts
|
|
14155
14559
|
var BRANDS_COLLECTION = "brands";
|
|
@@ -14160,7 +14564,7 @@ var BrandService = class extends BaseService {
|
|
|
14160
14564
|
* Gets reference to brands collection
|
|
14161
14565
|
*/
|
|
14162
14566
|
getBrandsRef() {
|
|
14163
|
-
return (0,
|
|
14567
|
+
return (0, import_firestore46.collection)(this.db, BRANDS_COLLECTION);
|
|
14164
14568
|
}
|
|
14165
14569
|
/**
|
|
14166
14570
|
* Creates a new brand
|
|
@@ -14173,19 +14577,19 @@ var BrandService = class extends BaseService {
|
|
|
14173
14577
|
updatedAt: now,
|
|
14174
14578
|
isActive: true
|
|
14175
14579
|
};
|
|
14176
|
-
const docRef = await (0,
|
|
14580
|
+
const docRef = await (0, import_firestore46.addDoc)(this.getBrandsRef(), newBrand);
|
|
14177
14581
|
return { id: docRef.id, ...newBrand };
|
|
14178
14582
|
}
|
|
14179
14583
|
/**
|
|
14180
14584
|
* Gets all active brands
|
|
14181
14585
|
*/
|
|
14182
14586
|
async getAll() {
|
|
14183
|
-
const q = (0,
|
|
14184
|
-
const snapshot = await (0,
|
|
14587
|
+
const q = (0, import_firestore46.query)(this.getBrandsRef(), (0, import_firestore46.where)("isActive", "==", true));
|
|
14588
|
+
const snapshot = await (0, import_firestore46.getDocs)(q);
|
|
14185
14589
|
return snapshot.docs.map(
|
|
14186
|
-
(
|
|
14187
|
-
id:
|
|
14188
|
-
...
|
|
14590
|
+
(doc35) => ({
|
|
14591
|
+
id: doc35.id,
|
|
14592
|
+
...doc35.data()
|
|
14189
14593
|
})
|
|
14190
14594
|
);
|
|
14191
14595
|
}
|
|
@@ -14197,8 +14601,8 @@ var BrandService = class extends BaseService {
|
|
|
14197
14601
|
...brand,
|
|
14198
14602
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14199
14603
|
};
|
|
14200
|
-
const docRef = (0,
|
|
14201
|
-
await (0,
|
|
14604
|
+
const docRef = (0, import_firestore46.doc)(this.getBrandsRef(), brandId);
|
|
14605
|
+
await (0, import_firestore46.updateDoc)(docRef, updateData);
|
|
14202
14606
|
return this.getById(brandId);
|
|
14203
14607
|
}
|
|
14204
14608
|
/**
|
|
@@ -14213,8 +14617,8 @@ var BrandService = class extends BaseService {
|
|
|
14213
14617
|
* Gets a brand by ID
|
|
14214
14618
|
*/
|
|
14215
14619
|
async getById(brandId) {
|
|
14216
|
-
const docRef = (0,
|
|
14217
|
-
const docSnap = await (0,
|
|
14620
|
+
const docRef = (0, import_firestore46.doc)(this.getBrandsRef(), brandId);
|
|
14621
|
+
const docSnap = await (0, import_firestore46.getDoc)(docRef);
|
|
14218
14622
|
if (!docSnap.exists()) return null;
|
|
14219
14623
|
return {
|
|
14220
14624
|
id: docSnap.id,
|
|
@@ -14224,7 +14628,7 @@ var BrandService = class extends BaseService {
|
|
|
14224
14628
|
};
|
|
14225
14629
|
|
|
14226
14630
|
// src/backoffice/services/category.service.ts
|
|
14227
|
-
var
|
|
14631
|
+
var import_firestore47 = require("firebase/firestore");
|
|
14228
14632
|
|
|
14229
14633
|
// src/backoffice/types/category.types.ts
|
|
14230
14634
|
var CATEGORIES_COLLECTION = "backoffice_categories";
|
|
@@ -14235,7 +14639,7 @@ var CategoryService = class extends BaseService {
|
|
|
14235
14639
|
* Referenca na Firestore kolekciju kategorija
|
|
14236
14640
|
*/
|
|
14237
14641
|
get categoriesRef() {
|
|
14238
|
-
return (0,
|
|
14642
|
+
return (0, import_firestore47.collection)(this.db, CATEGORIES_COLLECTION);
|
|
14239
14643
|
}
|
|
14240
14644
|
/**
|
|
14241
14645
|
* Kreira novu kategoriju u sistemu
|
|
@@ -14250,7 +14654,7 @@ var CategoryService = class extends BaseService {
|
|
|
14250
14654
|
updatedAt: now,
|
|
14251
14655
|
isActive: true
|
|
14252
14656
|
};
|
|
14253
|
-
const docRef = await (0,
|
|
14657
|
+
const docRef = await (0, import_firestore47.addDoc)(this.categoriesRef, newCategory);
|
|
14254
14658
|
return { id: docRef.id, ...newCategory };
|
|
14255
14659
|
}
|
|
14256
14660
|
/**
|
|
@@ -14258,12 +14662,12 @@ var CategoryService = class extends BaseService {
|
|
|
14258
14662
|
* @returns Lista aktivnih kategorija
|
|
14259
14663
|
*/
|
|
14260
14664
|
async getAll() {
|
|
14261
|
-
const q = (0,
|
|
14262
|
-
const snapshot = await (0,
|
|
14665
|
+
const q = (0, import_firestore47.query)(this.categoriesRef, (0, import_firestore47.where)("isActive", "==", true));
|
|
14666
|
+
const snapshot = await (0, import_firestore47.getDocs)(q);
|
|
14263
14667
|
return snapshot.docs.map(
|
|
14264
|
-
(
|
|
14265
|
-
id:
|
|
14266
|
-
...
|
|
14668
|
+
(doc35) => ({
|
|
14669
|
+
id: doc35.id,
|
|
14670
|
+
...doc35.data()
|
|
14267
14671
|
})
|
|
14268
14672
|
);
|
|
14269
14673
|
}
|
|
@@ -14273,16 +14677,16 @@ var CategoryService = class extends BaseService {
|
|
|
14273
14677
|
* @returns Lista kategorija koje pripadaju traženoj familiji
|
|
14274
14678
|
*/
|
|
14275
14679
|
async getAllByFamily(family) {
|
|
14276
|
-
const q = (0,
|
|
14680
|
+
const q = (0, import_firestore47.query)(
|
|
14277
14681
|
this.categoriesRef,
|
|
14278
|
-
(0,
|
|
14279
|
-
(0,
|
|
14682
|
+
(0, import_firestore47.where)("family", "==", family),
|
|
14683
|
+
(0, import_firestore47.where)("isActive", "==", true)
|
|
14280
14684
|
);
|
|
14281
|
-
const snapshot = await (0,
|
|
14685
|
+
const snapshot = await (0, import_firestore47.getDocs)(q);
|
|
14282
14686
|
return snapshot.docs.map(
|
|
14283
|
-
(
|
|
14284
|
-
id:
|
|
14285
|
-
...
|
|
14687
|
+
(doc35) => ({
|
|
14688
|
+
id: doc35.id,
|
|
14689
|
+
...doc35.data()
|
|
14286
14690
|
})
|
|
14287
14691
|
);
|
|
14288
14692
|
}
|
|
@@ -14297,8 +14701,8 @@ var CategoryService = class extends BaseService {
|
|
|
14297
14701
|
...category,
|
|
14298
14702
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14299
14703
|
};
|
|
14300
|
-
const docRef = (0,
|
|
14301
|
-
await (0,
|
|
14704
|
+
const docRef = (0, import_firestore47.doc)(this.categoriesRef, id);
|
|
14705
|
+
await (0, import_firestore47.updateDoc)(docRef, updateData);
|
|
14302
14706
|
return this.getById(id);
|
|
14303
14707
|
}
|
|
14304
14708
|
/**
|
|
@@ -14314,8 +14718,8 @@ var CategoryService = class extends BaseService {
|
|
|
14314
14718
|
* @returns Kategorija ili null ako ne postoji
|
|
14315
14719
|
*/
|
|
14316
14720
|
async getById(id) {
|
|
14317
|
-
const docRef = (0,
|
|
14318
|
-
const docSnap = await (0,
|
|
14721
|
+
const docRef = (0, import_firestore47.doc)(this.categoriesRef, id);
|
|
14722
|
+
const docSnap = await (0, import_firestore47.getDoc)(docRef);
|
|
14319
14723
|
if (!docSnap.exists()) return null;
|
|
14320
14724
|
return {
|
|
14321
14725
|
id: docSnap.id,
|
|
@@ -14325,7 +14729,7 @@ var CategoryService = class extends BaseService {
|
|
|
14325
14729
|
};
|
|
14326
14730
|
|
|
14327
14731
|
// src/backoffice/services/subcategory.service.ts
|
|
14328
|
-
var
|
|
14732
|
+
var import_firestore48 = require("firebase/firestore");
|
|
14329
14733
|
|
|
14330
14734
|
// src/backoffice/types/subcategory.types.ts
|
|
14331
14735
|
var SUBCATEGORIES_COLLECTION = "subcategories";
|
|
@@ -14337,7 +14741,7 @@ var SubcategoryService = class extends BaseService {
|
|
|
14337
14741
|
* @param categoryId - ID roditeljske kategorije
|
|
14338
14742
|
*/
|
|
14339
14743
|
getSubcategoriesRef(categoryId) {
|
|
14340
|
-
return (0,
|
|
14744
|
+
return (0, import_firestore48.collection)(
|
|
14341
14745
|
this.db,
|
|
14342
14746
|
CATEGORIES_COLLECTION,
|
|
14343
14747
|
categoryId,
|
|
@@ -14359,7 +14763,7 @@ var SubcategoryService = class extends BaseService {
|
|
|
14359
14763
|
updatedAt: now,
|
|
14360
14764
|
isActive: true
|
|
14361
14765
|
};
|
|
14362
|
-
const docRef = await (0,
|
|
14766
|
+
const docRef = await (0, import_firestore48.addDoc)(
|
|
14363
14767
|
this.getSubcategoriesRef(categoryId),
|
|
14364
14768
|
newSubcategory
|
|
14365
14769
|
);
|
|
@@ -14371,15 +14775,15 @@ var SubcategoryService = class extends BaseService {
|
|
|
14371
14775
|
* @returns Lista aktivnih podkategorija
|
|
14372
14776
|
*/
|
|
14373
14777
|
async getAllByCategoryId(categoryId) {
|
|
14374
|
-
const q = (0,
|
|
14778
|
+
const q = (0, import_firestore48.query)(
|
|
14375
14779
|
this.getSubcategoriesRef(categoryId),
|
|
14376
|
-
(0,
|
|
14780
|
+
(0, import_firestore48.where)("isActive", "==", true)
|
|
14377
14781
|
);
|
|
14378
|
-
const snapshot = await (0,
|
|
14782
|
+
const snapshot = await (0, import_firestore48.getDocs)(q);
|
|
14379
14783
|
return snapshot.docs.map(
|
|
14380
|
-
(
|
|
14381
|
-
id:
|
|
14382
|
-
...
|
|
14784
|
+
(doc35) => ({
|
|
14785
|
+
id: doc35.id,
|
|
14786
|
+
...doc35.data()
|
|
14383
14787
|
})
|
|
14384
14788
|
);
|
|
14385
14789
|
}
|
|
@@ -14395,8 +14799,8 @@ var SubcategoryService = class extends BaseService {
|
|
|
14395
14799
|
...subcategory,
|
|
14396
14800
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14397
14801
|
};
|
|
14398
|
-
const docRef = (0,
|
|
14399
|
-
await (0,
|
|
14802
|
+
const docRef = (0, import_firestore48.doc)(this.getSubcategoriesRef(categoryId), subcategoryId);
|
|
14803
|
+
await (0, import_firestore48.updateDoc)(docRef, updateData);
|
|
14400
14804
|
return this.getById(categoryId, subcategoryId);
|
|
14401
14805
|
}
|
|
14402
14806
|
/**
|
|
@@ -14414,8 +14818,8 @@ var SubcategoryService = class extends BaseService {
|
|
|
14414
14818
|
* @returns Podkategorija ili null ako ne postoji
|
|
14415
14819
|
*/
|
|
14416
14820
|
async getById(categoryId, subcategoryId) {
|
|
14417
|
-
const docRef = (0,
|
|
14418
|
-
const docSnap = await (0,
|
|
14821
|
+
const docRef = (0, import_firestore48.doc)(this.getSubcategoriesRef(categoryId), subcategoryId);
|
|
14822
|
+
const docSnap = await (0, import_firestore48.getDoc)(docRef);
|
|
14419
14823
|
if (!docSnap.exists()) return null;
|
|
14420
14824
|
return {
|
|
14421
14825
|
id: docSnap.id,
|
|
@@ -14425,7 +14829,7 @@ var SubcategoryService = class extends BaseService {
|
|
|
14425
14829
|
};
|
|
14426
14830
|
|
|
14427
14831
|
// src/backoffice/services/technology.service.ts
|
|
14428
|
-
var
|
|
14832
|
+
var import_firestore49 = require("firebase/firestore");
|
|
14429
14833
|
var DEFAULT_CERTIFICATION_REQUIREMENT = {
|
|
14430
14834
|
minimumLevel: "aesthetician" /* AESTHETICIAN */,
|
|
14431
14835
|
requiredSpecialties: []
|
|
@@ -14435,7 +14839,7 @@ var TechnologyService = class extends BaseService {
|
|
|
14435
14839
|
* Vraća referencu na Firestore kolekciju tehnologija
|
|
14436
14840
|
*/
|
|
14437
14841
|
getTechnologiesRef() {
|
|
14438
|
-
return (0,
|
|
14842
|
+
return (0, import_firestore49.collection)(this.db, TECHNOLOGIES_COLLECTION);
|
|
14439
14843
|
}
|
|
14440
14844
|
/**
|
|
14441
14845
|
* Kreira novu tehnologiju
|
|
@@ -14458,7 +14862,7 @@ var TechnologyService = class extends BaseService {
|
|
|
14458
14862
|
benefits: technology.benefits || [],
|
|
14459
14863
|
certificationRequirement: technology.certificationRequirement || DEFAULT_CERTIFICATION_REQUIREMENT
|
|
14460
14864
|
};
|
|
14461
|
-
const docRef = await (0,
|
|
14865
|
+
const docRef = await (0, import_firestore49.addDoc)(this.getTechnologiesRef(), newTechnology);
|
|
14462
14866
|
return { id: docRef.id, ...newTechnology };
|
|
14463
14867
|
}
|
|
14464
14868
|
/**
|
|
@@ -14466,12 +14870,12 @@ var TechnologyService = class extends BaseService {
|
|
|
14466
14870
|
* @returns Lista aktivnih tehnologija
|
|
14467
14871
|
*/
|
|
14468
14872
|
async getAll() {
|
|
14469
|
-
const q = (0,
|
|
14470
|
-
const snapshot = await (0,
|
|
14873
|
+
const q = (0, import_firestore49.query)(this.getTechnologiesRef(), (0, import_firestore49.where)("isActive", "==", true));
|
|
14874
|
+
const snapshot = await (0, import_firestore49.getDocs)(q);
|
|
14471
14875
|
return snapshot.docs.map(
|
|
14472
|
-
(
|
|
14473
|
-
id:
|
|
14474
|
-
...
|
|
14876
|
+
(doc35) => ({
|
|
14877
|
+
id: doc35.id,
|
|
14878
|
+
...doc35.data()
|
|
14475
14879
|
})
|
|
14476
14880
|
);
|
|
14477
14881
|
}
|
|
@@ -14481,16 +14885,16 @@ var TechnologyService = class extends BaseService {
|
|
|
14481
14885
|
* @returns Lista aktivnih tehnologija
|
|
14482
14886
|
*/
|
|
14483
14887
|
async getAllByFamily(family) {
|
|
14484
|
-
const q = (0,
|
|
14888
|
+
const q = (0, import_firestore49.query)(
|
|
14485
14889
|
this.getTechnologiesRef(),
|
|
14486
|
-
(0,
|
|
14487
|
-
(0,
|
|
14890
|
+
(0, import_firestore49.where)("isActive", "==", true),
|
|
14891
|
+
(0, import_firestore49.where)("family", "==", family)
|
|
14488
14892
|
);
|
|
14489
|
-
const snapshot = await (0,
|
|
14893
|
+
const snapshot = await (0, import_firestore49.getDocs)(q);
|
|
14490
14894
|
return snapshot.docs.map(
|
|
14491
|
-
(
|
|
14492
|
-
id:
|
|
14493
|
-
...
|
|
14895
|
+
(doc35) => ({
|
|
14896
|
+
id: doc35.id,
|
|
14897
|
+
...doc35.data()
|
|
14494
14898
|
})
|
|
14495
14899
|
);
|
|
14496
14900
|
}
|
|
@@ -14500,16 +14904,16 @@ var TechnologyService = class extends BaseService {
|
|
|
14500
14904
|
* @returns Lista aktivnih tehnologija
|
|
14501
14905
|
*/
|
|
14502
14906
|
async getAllByCategoryId(categoryId) {
|
|
14503
|
-
const q = (0,
|
|
14907
|
+
const q = (0, import_firestore49.query)(
|
|
14504
14908
|
this.getTechnologiesRef(),
|
|
14505
|
-
(0,
|
|
14506
|
-
(0,
|
|
14909
|
+
(0, import_firestore49.where)("isActive", "==", true),
|
|
14910
|
+
(0, import_firestore49.where)("categoryId", "==", categoryId)
|
|
14507
14911
|
);
|
|
14508
|
-
const snapshot = await (0,
|
|
14912
|
+
const snapshot = await (0, import_firestore49.getDocs)(q);
|
|
14509
14913
|
return snapshot.docs.map(
|
|
14510
|
-
(
|
|
14511
|
-
id:
|
|
14512
|
-
...
|
|
14914
|
+
(doc35) => ({
|
|
14915
|
+
id: doc35.id,
|
|
14916
|
+
...doc35.data()
|
|
14513
14917
|
})
|
|
14514
14918
|
);
|
|
14515
14919
|
}
|
|
@@ -14519,16 +14923,16 @@ var TechnologyService = class extends BaseService {
|
|
|
14519
14923
|
* @returns Lista aktivnih tehnologija
|
|
14520
14924
|
*/
|
|
14521
14925
|
async getAllBySubcategoryId(subcategoryId) {
|
|
14522
|
-
const q = (0,
|
|
14926
|
+
const q = (0, import_firestore49.query)(
|
|
14523
14927
|
this.getTechnologiesRef(),
|
|
14524
|
-
(0,
|
|
14525
|
-
(0,
|
|
14928
|
+
(0, import_firestore49.where)("isActive", "==", true),
|
|
14929
|
+
(0, import_firestore49.where)("subcategoryId", "==", subcategoryId)
|
|
14526
14930
|
);
|
|
14527
|
-
const snapshot = await (0,
|
|
14931
|
+
const snapshot = await (0, import_firestore49.getDocs)(q);
|
|
14528
14932
|
return snapshot.docs.map(
|
|
14529
|
-
(
|
|
14530
|
-
id:
|
|
14531
|
-
...
|
|
14933
|
+
(doc35) => ({
|
|
14934
|
+
id: doc35.id,
|
|
14935
|
+
...doc35.data()
|
|
14532
14936
|
})
|
|
14533
14937
|
);
|
|
14534
14938
|
}
|
|
@@ -14543,8 +14947,8 @@ var TechnologyService = class extends BaseService {
|
|
|
14543
14947
|
...technology,
|
|
14544
14948
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14545
14949
|
};
|
|
14546
|
-
const docRef = (0,
|
|
14547
|
-
await (0,
|
|
14950
|
+
const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
|
|
14951
|
+
await (0, import_firestore49.updateDoc)(docRef, updateData);
|
|
14548
14952
|
return this.getById(technologyId);
|
|
14549
14953
|
}
|
|
14550
14954
|
/**
|
|
@@ -14562,8 +14966,8 @@ var TechnologyService = class extends BaseService {
|
|
|
14562
14966
|
* @returns Tehnologija ili null ako ne postoji
|
|
14563
14967
|
*/
|
|
14564
14968
|
async getById(technologyId) {
|
|
14565
|
-
const docRef = (0,
|
|
14566
|
-
const docSnap = await (0,
|
|
14969
|
+
const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
|
|
14970
|
+
const docSnap = await (0, import_firestore49.getDoc)(docRef);
|
|
14567
14971
|
if (!docSnap.exists()) return null;
|
|
14568
14972
|
return {
|
|
14569
14973
|
id: docSnap.id,
|
|
@@ -14577,10 +14981,10 @@ var TechnologyService = class extends BaseService {
|
|
|
14577
14981
|
* @returns Ažurirana tehnologija sa novim zahtevom
|
|
14578
14982
|
*/
|
|
14579
14983
|
async addRequirement(technologyId, requirement) {
|
|
14580
|
-
const docRef = (0,
|
|
14984
|
+
const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
|
|
14581
14985
|
const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
|
|
14582
|
-
await (0,
|
|
14583
|
-
[requirementType]: (0,
|
|
14986
|
+
await (0, import_firestore49.updateDoc)(docRef, {
|
|
14987
|
+
[requirementType]: (0, import_firestore49.arrayUnion)(requirement),
|
|
14584
14988
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14585
14989
|
});
|
|
14586
14990
|
return this.getById(technologyId);
|
|
@@ -14592,10 +14996,10 @@ var TechnologyService = class extends BaseService {
|
|
|
14592
14996
|
* @returns Ažurirana tehnologija bez uklonjenog zahteva
|
|
14593
14997
|
*/
|
|
14594
14998
|
async removeRequirement(technologyId, requirement) {
|
|
14595
|
-
const docRef = (0,
|
|
14999
|
+
const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
|
|
14596
15000
|
const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
|
|
14597
|
-
await (0,
|
|
14598
|
-
[requirementType]: (0,
|
|
15001
|
+
await (0, import_firestore49.updateDoc)(docRef, {
|
|
15002
|
+
[requirementType]: (0, import_firestore49.arrayRemove)(requirement),
|
|
14599
15003
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14600
15004
|
});
|
|
14601
15005
|
return this.getById(technologyId);
|
|
@@ -14632,9 +15036,9 @@ var TechnologyService = class extends BaseService {
|
|
|
14632
15036
|
* @returns Ažurirana tehnologija
|
|
14633
15037
|
*/
|
|
14634
15038
|
async addBlockingCondition(technologyId, condition) {
|
|
14635
|
-
const docRef = (0,
|
|
14636
|
-
await (0,
|
|
14637
|
-
blockingConditions: (0,
|
|
15039
|
+
const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
|
|
15040
|
+
await (0, import_firestore49.updateDoc)(docRef, {
|
|
15041
|
+
blockingConditions: (0, import_firestore49.arrayUnion)(condition),
|
|
14638
15042
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14639
15043
|
});
|
|
14640
15044
|
return this.getById(technologyId);
|
|
@@ -14646,9 +15050,9 @@ var TechnologyService = class extends BaseService {
|
|
|
14646
15050
|
* @returns Ažurirana tehnologija
|
|
14647
15051
|
*/
|
|
14648
15052
|
async removeBlockingCondition(technologyId, condition) {
|
|
14649
|
-
const docRef = (0,
|
|
14650
|
-
await (0,
|
|
14651
|
-
blockingConditions: (0,
|
|
15053
|
+
const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
|
|
15054
|
+
await (0, import_firestore49.updateDoc)(docRef, {
|
|
15055
|
+
blockingConditions: (0, import_firestore49.arrayRemove)(condition),
|
|
14652
15056
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14653
15057
|
});
|
|
14654
15058
|
return this.getById(technologyId);
|
|
@@ -14660,9 +15064,9 @@ var TechnologyService = class extends BaseService {
|
|
|
14660
15064
|
* @returns Ažurirana tehnologija
|
|
14661
15065
|
*/
|
|
14662
15066
|
async addContraindication(technologyId, contraindication) {
|
|
14663
|
-
const docRef = (0,
|
|
14664
|
-
await (0,
|
|
14665
|
-
contraindications: (0,
|
|
15067
|
+
const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
|
|
15068
|
+
await (0, import_firestore49.updateDoc)(docRef, {
|
|
15069
|
+
contraindications: (0, import_firestore49.arrayUnion)(contraindication),
|
|
14666
15070
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14667
15071
|
});
|
|
14668
15072
|
return this.getById(technologyId);
|
|
@@ -14674,9 +15078,9 @@ var TechnologyService = class extends BaseService {
|
|
|
14674
15078
|
* @returns Ažurirana tehnologija
|
|
14675
15079
|
*/
|
|
14676
15080
|
async removeContraindication(technologyId, contraindication) {
|
|
14677
|
-
const docRef = (0,
|
|
14678
|
-
await (0,
|
|
14679
|
-
contraindications: (0,
|
|
15081
|
+
const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
|
|
15082
|
+
await (0, import_firestore49.updateDoc)(docRef, {
|
|
15083
|
+
contraindications: (0, import_firestore49.arrayRemove)(contraindication),
|
|
14680
15084
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14681
15085
|
});
|
|
14682
15086
|
return this.getById(technologyId);
|
|
@@ -14688,9 +15092,9 @@ var TechnologyService = class extends BaseService {
|
|
|
14688
15092
|
* @returns Ažurirana tehnologija
|
|
14689
15093
|
*/
|
|
14690
15094
|
async addBenefit(technologyId, benefit) {
|
|
14691
|
-
const docRef = (0,
|
|
14692
|
-
await (0,
|
|
14693
|
-
benefits: (0,
|
|
15095
|
+
const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
|
|
15096
|
+
await (0, import_firestore49.updateDoc)(docRef, {
|
|
15097
|
+
benefits: (0, import_firestore49.arrayUnion)(benefit),
|
|
14694
15098
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14695
15099
|
});
|
|
14696
15100
|
return this.getById(technologyId);
|
|
@@ -14702,9 +15106,9 @@ var TechnologyService = class extends BaseService {
|
|
|
14702
15106
|
* @returns Ažurirana tehnologija
|
|
14703
15107
|
*/
|
|
14704
15108
|
async removeBenefit(technologyId, benefit) {
|
|
14705
|
-
const docRef = (0,
|
|
14706
|
-
await (0,
|
|
14707
|
-
benefits: (0,
|
|
15109
|
+
const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
|
|
15110
|
+
await (0, import_firestore49.updateDoc)(docRef, {
|
|
15111
|
+
benefits: (0, import_firestore49.arrayRemove)(benefit),
|
|
14708
15112
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14709
15113
|
});
|
|
14710
15114
|
return this.getById(technologyId);
|
|
@@ -14743,8 +15147,8 @@ var TechnologyService = class extends BaseService {
|
|
|
14743
15147
|
* @returns Ažurirana tehnologija
|
|
14744
15148
|
*/
|
|
14745
15149
|
async updateCertificationRequirement(technologyId, certificationRequirement) {
|
|
14746
|
-
const docRef = (0,
|
|
14747
|
-
await (0,
|
|
15150
|
+
const docRef = (0, import_firestore49.doc)(this.getTechnologiesRef(), technologyId);
|
|
15151
|
+
await (0, import_firestore49.updateDoc)(docRef, {
|
|
14748
15152
|
certificationRequirement,
|
|
14749
15153
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14750
15154
|
});
|
|
@@ -14844,7 +15248,7 @@ var TechnologyService = class extends BaseService {
|
|
|
14844
15248
|
};
|
|
14845
15249
|
|
|
14846
15250
|
// src/backoffice/services/product.service.ts
|
|
14847
|
-
var
|
|
15251
|
+
var import_firestore50 = require("firebase/firestore");
|
|
14848
15252
|
|
|
14849
15253
|
// src/backoffice/types/product.types.ts
|
|
14850
15254
|
var PRODUCTS_COLLECTION = "products";
|
|
@@ -14857,7 +15261,7 @@ var ProductService = class extends BaseService {
|
|
|
14857
15261
|
* @returns Firestore collection reference
|
|
14858
15262
|
*/
|
|
14859
15263
|
getProductsRef(technologyId) {
|
|
14860
|
-
return (0,
|
|
15264
|
+
return (0, import_firestore50.collection)(
|
|
14861
15265
|
this.db,
|
|
14862
15266
|
TECHNOLOGIES_COLLECTION,
|
|
14863
15267
|
technologyId,
|
|
@@ -14877,7 +15281,7 @@ var ProductService = class extends BaseService {
|
|
|
14877
15281
|
updatedAt: now,
|
|
14878
15282
|
isActive: true
|
|
14879
15283
|
};
|
|
14880
|
-
const productRef = await (0,
|
|
15284
|
+
const productRef = await (0, import_firestore50.addDoc)(
|
|
14881
15285
|
this.getProductsRef(technologyId),
|
|
14882
15286
|
newProduct
|
|
14883
15287
|
);
|
|
@@ -14887,15 +15291,15 @@ var ProductService = class extends BaseService {
|
|
|
14887
15291
|
* Gets all products for a technology
|
|
14888
15292
|
*/
|
|
14889
15293
|
async getAllByTechnology(technologyId) {
|
|
14890
|
-
const q = (0,
|
|
15294
|
+
const q = (0, import_firestore50.query)(
|
|
14891
15295
|
this.getProductsRef(technologyId),
|
|
14892
|
-
(0,
|
|
15296
|
+
(0, import_firestore50.where)("isActive", "==", true)
|
|
14893
15297
|
);
|
|
14894
|
-
const snapshot = await (0,
|
|
15298
|
+
const snapshot = await (0, import_firestore50.getDocs)(q);
|
|
14895
15299
|
return snapshot.docs.map(
|
|
14896
|
-
(
|
|
14897
|
-
id:
|
|
14898
|
-
...
|
|
15300
|
+
(doc35) => ({
|
|
15301
|
+
id: doc35.id,
|
|
15302
|
+
...doc35.data()
|
|
14899
15303
|
})
|
|
14900
15304
|
);
|
|
14901
15305
|
}
|
|
@@ -14903,21 +15307,21 @@ var ProductService = class extends BaseService {
|
|
|
14903
15307
|
* Gets all products for a brand by filtering through all technologies
|
|
14904
15308
|
*/
|
|
14905
15309
|
async getAllByBrand(brandId) {
|
|
14906
|
-
const allTechnologiesRef = (0,
|
|
14907
|
-
const technologiesSnapshot = await (0,
|
|
15310
|
+
const allTechnologiesRef = (0, import_firestore50.collection)(this.db, TECHNOLOGIES_COLLECTION);
|
|
15311
|
+
const technologiesSnapshot = await (0, import_firestore50.getDocs)(allTechnologiesRef);
|
|
14908
15312
|
const products = [];
|
|
14909
15313
|
for (const techDoc of technologiesSnapshot.docs) {
|
|
14910
|
-
const q = (0,
|
|
15314
|
+
const q = (0, import_firestore50.query)(
|
|
14911
15315
|
this.getProductsRef(techDoc.id),
|
|
14912
|
-
(0,
|
|
14913
|
-
(0,
|
|
15316
|
+
(0, import_firestore50.where)("brandId", "==", brandId),
|
|
15317
|
+
(0, import_firestore50.where)("isActive", "==", true)
|
|
14914
15318
|
);
|
|
14915
|
-
const snapshot = await (0,
|
|
15319
|
+
const snapshot = await (0, import_firestore50.getDocs)(q);
|
|
14916
15320
|
products.push(
|
|
14917
15321
|
...snapshot.docs.map(
|
|
14918
|
-
(
|
|
14919
|
-
id:
|
|
14920
|
-
...
|
|
15322
|
+
(doc35) => ({
|
|
15323
|
+
id: doc35.id,
|
|
15324
|
+
...doc35.data()
|
|
14921
15325
|
})
|
|
14922
15326
|
)
|
|
14923
15327
|
);
|
|
@@ -14932,8 +15336,8 @@ var ProductService = class extends BaseService {
|
|
|
14932
15336
|
...product,
|
|
14933
15337
|
updatedAt: /* @__PURE__ */ new Date()
|
|
14934
15338
|
};
|
|
14935
|
-
const docRef = (0,
|
|
14936
|
-
await (0,
|
|
15339
|
+
const docRef = (0, import_firestore50.doc)(this.getProductsRef(technologyId), productId);
|
|
15340
|
+
await (0, import_firestore50.updateDoc)(docRef, updateData);
|
|
14937
15341
|
return this.getById(technologyId, productId);
|
|
14938
15342
|
}
|
|
14939
15343
|
/**
|
|
@@ -14948,8 +15352,8 @@ var ProductService = class extends BaseService {
|
|
|
14948
15352
|
* Gets a product by ID
|
|
14949
15353
|
*/
|
|
14950
15354
|
async getById(technologyId, productId) {
|
|
14951
|
-
const docRef = (0,
|
|
14952
|
-
const docSnap = await (0,
|
|
15355
|
+
const docRef = (0, import_firestore50.doc)(this.getProductsRef(technologyId), productId);
|
|
15356
|
+
const docSnap = await (0, import_firestore50.getDoc)(docRef);
|
|
14953
15357
|
if (!docSnap.exists()) return null;
|
|
14954
15358
|
return {
|
|
14955
15359
|
id: docSnap.id,
|
|
@@ -15114,6 +15518,7 @@ var RequirementType = /* @__PURE__ */ ((RequirementType2) => {
|
|
|
15114
15518
|
PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME,
|
|
15115
15519
|
PATIENT_SENSITIVE_INFO_COLLECTION,
|
|
15116
15520
|
PRACTITIONERS_COLLECTION,
|
|
15521
|
+
PRACTITIONER_INVITES_COLLECTION,
|
|
15117
15522
|
PROCEDURES_COLLECTION,
|
|
15118
15523
|
PatientInstructionStatus,
|
|
15119
15524
|
PatientRequirementOverallStatus,
|
|
@@ -15121,6 +15526,8 @@ var RequirementType = /* @__PURE__ */ ((RequirementType2) => {
|
|
|
15121
15526
|
PatientService,
|
|
15122
15527
|
PaymentStatus,
|
|
15123
15528
|
PracticeType,
|
|
15529
|
+
PractitionerInviteService,
|
|
15530
|
+
PractitionerInviteStatus,
|
|
15124
15531
|
PractitionerService,
|
|
15125
15532
|
PractitionerStatus,
|
|
15126
15533
|
PractitionerTokenStatus,
|