@blackcode_sa/metaestetics-api 1.5.4 → 1.5.7
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/backoffice/index.js +2 -6
- package/dist/backoffice/index.mjs +2 -6
- package/dist/index.d.mts +156 -8
- package/dist/index.d.ts +156 -8
- package/dist/index.js +651 -416
- package/dist/index.mjs +697 -453
- package/package.json +1 -1
- package/src/index.ts +59 -70
- package/src/services/clinic/clinic.service.ts +6 -0
- package/src/types/index.ts +0 -3
package/dist/index.mjs
CHANGED
|
@@ -63,6 +63,8 @@ import {
|
|
|
63
63
|
} from "firebase/firestore";
|
|
64
64
|
|
|
65
65
|
// src/types/documentation-templates/index.ts
|
|
66
|
+
var DOCUMENTATION_TEMPLATES_COLLECTION = "documentation-templates";
|
|
67
|
+
var FILLED_DOCUMENTS_COLLECTION = "filled-documents";
|
|
66
68
|
var DocumentElementType = /* @__PURE__ */ ((DocumentElementType2) => {
|
|
67
69
|
DocumentElementType2["HEADING"] = "heading";
|
|
68
70
|
DocumentElementType2["PARAGRAPH"] = "paragraph";
|
|
@@ -142,8 +144,6 @@ var UserRole = /* @__PURE__ */ ((UserRole2) => {
|
|
|
142
144
|
return UserRole2;
|
|
143
145
|
})(UserRole || {});
|
|
144
146
|
var USERS_COLLECTION = "users";
|
|
145
|
-
var DOCUMENTATION_TEMPLATES_COLLECTION = "documentation-templates";
|
|
146
|
-
var FILLED_DOCUMENTS_COLLECTION = "filled-documents";
|
|
147
147
|
|
|
148
148
|
// src/services/auth.service.ts
|
|
149
149
|
import { z as z15 } from "zod";
|
|
@@ -1310,9 +1310,9 @@ var addAllergyUtil = async (db, patientId, data, userRef) => {
|
|
|
1310
1310
|
var updateAllergyUtil = async (db, patientId, data, userRef) => {
|
|
1311
1311
|
const validatedData = updateAllergySchema.parse(data);
|
|
1312
1312
|
const { allergyIndex, ...updateData } = validatedData;
|
|
1313
|
-
const
|
|
1314
|
-
if (!
|
|
1315
|
-
const medicalInfo =
|
|
1313
|
+
const doc21 = await getDoc3(getMedicalInfoDocRef(db, patientId));
|
|
1314
|
+
if (!doc21.exists()) throw new Error("Medical info not found");
|
|
1315
|
+
const medicalInfo = doc21.data();
|
|
1316
1316
|
if (allergyIndex >= medicalInfo.allergies.length) {
|
|
1317
1317
|
throw new Error("Invalid allergy index");
|
|
1318
1318
|
}
|
|
@@ -1328,9 +1328,9 @@ var updateAllergyUtil = async (db, patientId, data, userRef) => {
|
|
|
1328
1328
|
});
|
|
1329
1329
|
};
|
|
1330
1330
|
var removeAllergyUtil = async (db, patientId, allergyIndex, userRef) => {
|
|
1331
|
-
const
|
|
1332
|
-
if (!
|
|
1333
|
-
const medicalInfo =
|
|
1331
|
+
const doc21 = await getDoc3(getMedicalInfoDocRef(db, patientId));
|
|
1332
|
+
if (!doc21.exists()) throw new Error("Medical info not found");
|
|
1333
|
+
const medicalInfo = doc21.data();
|
|
1334
1334
|
if (allergyIndex >= medicalInfo.allergies.length) {
|
|
1335
1335
|
throw new Error("Invalid allergy index");
|
|
1336
1336
|
}
|
|
@@ -1355,9 +1355,9 @@ var addBlockingConditionUtil = async (db, patientId, data, userRef) => {
|
|
|
1355
1355
|
var updateBlockingConditionUtil = async (db, patientId, data, userRef) => {
|
|
1356
1356
|
const validatedData = updateBlockingConditionSchema.parse(data);
|
|
1357
1357
|
const { conditionIndex, ...updateData } = validatedData;
|
|
1358
|
-
const
|
|
1359
|
-
if (!
|
|
1360
|
-
const medicalInfo =
|
|
1358
|
+
const doc21 = await getDoc3(getMedicalInfoDocRef(db, patientId));
|
|
1359
|
+
if (!doc21.exists()) throw new Error("Medical info not found");
|
|
1360
|
+
const medicalInfo = doc21.data();
|
|
1361
1361
|
if (conditionIndex >= medicalInfo.blockingConditions.length) {
|
|
1362
1362
|
throw new Error("Invalid blocking condition index");
|
|
1363
1363
|
}
|
|
@@ -1373,9 +1373,9 @@ var updateBlockingConditionUtil = async (db, patientId, data, userRef) => {
|
|
|
1373
1373
|
});
|
|
1374
1374
|
};
|
|
1375
1375
|
var removeBlockingConditionUtil = async (db, patientId, conditionIndex, userRef) => {
|
|
1376
|
-
const
|
|
1377
|
-
if (!
|
|
1378
|
-
const medicalInfo =
|
|
1376
|
+
const doc21 = await getDoc3(getMedicalInfoDocRef(db, patientId));
|
|
1377
|
+
if (!doc21.exists()) throw new Error("Medical info not found");
|
|
1378
|
+
const medicalInfo = doc21.data();
|
|
1379
1379
|
if (conditionIndex >= medicalInfo.blockingConditions.length) {
|
|
1380
1380
|
throw new Error("Invalid blocking condition index");
|
|
1381
1381
|
}
|
|
@@ -1400,9 +1400,9 @@ var addContraindicationUtil = async (db, patientId, data, userRef) => {
|
|
|
1400
1400
|
var updateContraindicationUtil = async (db, patientId, data, userRef) => {
|
|
1401
1401
|
const validatedData = updateContraindicationSchema.parse(data);
|
|
1402
1402
|
const { contraindicationIndex, ...updateData } = validatedData;
|
|
1403
|
-
const
|
|
1404
|
-
if (!
|
|
1405
|
-
const medicalInfo =
|
|
1403
|
+
const doc21 = await getDoc3(getMedicalInfoDocRef(db, patientId));
|
|
1404
|
+
if (!doc21.exists()) throw new Error("Medical info not found");
|
|
1405
|
+
const medicalInfo = doc21.data();
|
|
1406
1406
|
if (contraindicationIndex >= medicalInfo.contraindications.length) {
|
|
1407
1407
|
throw new Error("Invalid contraindication index");
|
|
1408
1408
|
}
|
|
@@ -1418,9 +1418,9 @@ var updateContraindicationUtil = async (db, patientId, data, userRef) => {
|
|
|
1418
1418
|
});
|
|
1419
1419
|
};
|
|
1420
1420
|
var removeContraindicationUtil = async (db, patientId, contraindicationIndex, userRef) => {
|
|
1421
|
-
const
|
|
1422
|
-
if (!
|
|
1423
|
-
const medicalInfo =
|
|
1421
|
+
const doc21 = await getDoc3(getMedicalInfoDocRef(db, patientId));
|
|
1422
|
+
if (!doc21.exists()) throw new Error("Medical info not found");
|
|
1423
|
+
const medicalInfo = doc21.data();
|
|
1424
1424
|
if (contraindicationIndex >= medicalInfo.contraindications.length) {
|
|
1425
1425
|
throw new Error("Invalid contraindication index");
|
|
1426
1426
|
}
|
|
@@ -1445,9 +1445,9 @@ var addMedicationUtil = async (db, patientId, data, userRef) => {
|
|
|
1445
1445
|
var updateMedicationUtil = async (db, patientId, data, userRef) => {
|
|
1446
1446
|
const validatedData = updateMedicationSchema.parse(data);
|
|
1447
1447
|
const { medicationIndex, ...updateData } = validatedData;
|
|
1448
|
-
const
|
|
1449
|
-
if (!
|
|
1450
|
-
const medicalInfo =
|
|
1448
|
+
const doc21 = await getDoc3(getMedicalInfoDocRef(db, patientId));
|
|
1449
|
+
if (!doc21.exists()) throw new Error("Medical info not found");
|
|
1450
|
+
const medicalInfo = doc21.data();
|
|
1451
1451
|
if (medicationIndex >= medicalInfo.currentMedications.length) {
|
|
1452
1452
|
throw new Error("Invalid medication index");
|
|
1453
1453
|
}
|
|
@@ -1463,9 +1463,9 @@ var updateMedicationUtil = async (db, patientId, data, userRef) => {
|
|
|
1463
1463
|
});
|
|
1464
1464
|
};
|
|
1465
1465
|
var removeMedicationUtil = async (db, patientId, medicationIndex, userRef) => {
|
|
1466
|
-
const
|
|
1467
|
-
if (!
|
|
1468
|
-
const medicalInfo =
|
|
1466
|
+
const doc21 = await getDoc3(getMedicalInfoDocRef(db, patientId));
|
|
1467
|
+
if (!doc21.exists()) throw new Error("Medical info not found");
|
|
1468
|
+
const medicalInfo = doc21.data();
|
|
1469
1469
|
if (medicationIndex >= medicalInfo.currentMedications.length) {
|
|
1470
1470
|
throw new Error("Invalid medication index");
|
|
1471
1471
|
}
|
|
@@ -2782,7 +2782,7 @@ async function getClinicAdminsByGroup(db, clinicGroupId) {
|
|
|
2782
2782
|
where2("clinicGroupId", "==", clinicGroupId)
|
|
2783
2783
|
);
|
|
2784
2784
|
const querySnapshot = await getDocs2(q);
|
|
2785
|
-
return querySnapshot.docs.map((
|
|
2785
|
+
return querySnapshot.docs.map((doc21) => doc21.data());
|
|
2786
2786
|
}
|
|
2787
2787
|
async function updateClinicAdmin(db, adminId, data) {
|
|
2788
2788
|
const admin = await getClinicAdmin(db, adminId);
|
|
@@ -3449,7 +3449,7 @@ var PractitionerService = class extends BaseService {
|
|
|
3449
3449
|
where3("expiresAt", ">", Timestamp8.now())
|
|
3450
3450
|
);
|
|
3451
3451
|
const querySnapshot = await getDocs3(q);
|
|
3452
|
-
return querySnapshot.docs.map((
|
|
3452
|
+
return querySnapshot.docs.map((doc21) => doc21.data());
|
|
3453
3453
|
}
|
|
3454
3454
|
/**
|
|
3455
3455
|
* Gets a token by its string value and validates it
|
|
@@ -3532,7 +3532,7 @@ var PractitionerService = class extends BaseService {
|
|
|
3532
3532
|
where3("status", "==", "active" /* ACTIVE */)
|
|
3533
3533
|
);
|
|
3534
3534
|
const querySnapshot = await getDocs3(q);
|
|
3535
|
-
return querySnapshot.docs.map((
|
|
3535
|
+
return querySnapshot.docs.map((doc21) => doc21.data());
|
|
3536
3536
|
}
|
|
3537
3537
|
/**
|
|
3538
3538
|
* Dohvata sve draft zdravstvene radnike za određenu kliniku
|
|
@@ -3544,7 +3544,7 @@ var PractitionerService = class extends BaseService {
|
|
|
3544
3544
|
where3("status", "==", "draft" /* DRAFT */)
|
|
3545
3545
|
);
|
|
3546
3546
|
const querySnapshot = await getDocs3(q);
|
|
3547
|
-
return querySnapshot.docs.map((
|
|
3547
|
+
return querySnapshot.docs.map((doc21) => doc21.data());
|
|
3548
3548
|
}
|
|
3549
3549
|
/**
|
|
3550
3550
|
* Ažurira profil zdravstvenog radnika
|
|
@@ -3853,7 +3853,7 @@ var UserService = class extends BaseService {
|
|
|
3853
3853
|
];
|
|
3854
3854
|
const q = query4(collection4(this.db, USERS_COLLECTION), ...constraints);
|
|
3855
3855
|
const querySnapshot = await getDocs4(q);
|
|
3856
|
-
const users = querySnapshot.docs.map((
|
|
3856
|
+
const users = querySnapshot.docs.map((doc21) => doc21.data());
|
|
3857
3857
|
return Promise.all(users.map((userData) => userSchema.parse(userData)));
|
|
3858
3858
|
}
|
|
3859
3859
|
/**
|
|
@@ -4233,7 +4233,7 @@ async function getAllActiveGroups(db) {
|
|
|
4233
4233
|
where5("isActive", "==", true)
|
|
4234
4234
|
);
|
|
4235
4235
|
const querySnapshot = await getDocs5(q);
|
|
4236
|
-
return querySnapshot.docs.map((
|
|
4236
|
+
return querySnapshot.docs.map((doc21) => doc21.data());
|
|
4237
4237
|
}
|
|
4238
4238
|
async function updateClinicGroup(db, groupId, data, app) {
|
|
4239
4239
|
console.log("[CLINIC_GROUP] Updating clinic group", { groupId });
|
|
@@ -4903,7 +4903,7 @@ async function getClinicsByGroup(db, groupId) {
|
|
|
4903
4903
|
where6("isActive", "==", true)
|
|
4904
4904
|
);
|
|
4905
4905
|
const querySnapshot = await getDocs6(q);
|
|
4906
|
-
return querySnapshot.docs.map((
|
|
4906
|
+
return querySnapshot.docs.map((doc21) => doc21.data());
|
|
4907
4907
|
}
|
|
4908
4908
|
async function updateClinic(db, clinicId, data, adminId, clinicAdminService, app) {
|
|
4909
4909
|
console.log("[CLINIC] Starting clinic update", { clinicId, adminId });
|
|
@@ -5115,7 +5115,7 @@ async function getClinicsByAdmin(db, adminId, options = {}, clinicAdminService,
|
|
|
5115
5115
|
}
|
|
5116
5116
|
const q = query6(collection6(db, CLINICS_COLLECTION), ...constraints);
|
|
5117
5117
|
const querySnapshot = await getDocs6(q);
|
|
5118
|
-
return querySnapshot.docs.map((
|
|
5118
|
+
return querySnapshot.docs.map((doc21) => doc21.data());
|
|
5119
5119
|
}
|
|
5120
5120
|
async function getActiveClinicsByAdmin(db, adminId, clinicAdminService, clinicGroupService) {
|
|
5121
5121
|
return getClinicsByAdmin(
|
|
@@ -5268,8 +5268,8 @@ async function findClinicsInRadius(db, center, radiusInKm, filters) {
|
|
|
5268
5268
|
}
|
|
5269
5269
|
const q = query7(collection8(db, CLINICS_COLLECTION), ...constraints);
|
|
5270
5270
|
const querySnapshot = await getDocs7(q);
|
|
5271
|
-
for (const
|
|
5272
|
-
const clinic =
|
|
5271
|
+
for (const doc21 of querySnapshot.docs) {
|
|
5272
|
+
const clinic = doc21.data();
|
|
5273
5273
|
const distance = distanceBetween(
|
|
5274
5274
|
[center.latitude, center.longitude],
|
|
5275
5275
|
[clinic.location.latitude, clinic.location.longitude]
|
|
@@ -6214,9 +6214,9 @@ var NotificationService = class extends BaseService {
|
|
|
6214
6214
|
orderBy("notificationTime", "desc")
|
|
6215
6215
|
);
|
|
6216
6216
|
const querySnapshot = await getDocs9(q);
|
|
6217
|
-
return querySnapshot.docs.map((
|
|
6218
|
-
id:
|
|
6219
|
-
...
|
|
6217
|
+
return querySnapshot.docs.map((doc21) => ({
|
|
6218
|
+
id: doc21.id,
|
|
6219
|
+
...doc21.data()
|
|
6220
6220
|
}));
|
|
6221
6221
|
}
|
|
6222
6222
|
/**
|
|
@@ -6230,9 +6230,9 @@ var NotificationService = class extends BaseService {
|
|
|
6230
6230
|
orderBy("notificationTime", "desc")
|
|
6231
6231
|
);
|
|
6232
6232
|
const querySnapshot = await getDocs9(q);
|
|
6233
|
-
return querySnapshot.docs.map((
|
|
6234
|
-
id:
|
|
6235
|
-
...
|
|
6233
|
+
return querySnapshot.docs.map((doc21) => ({
|
|
6234
|
+
id: doc21.id,
|
|
6235
|
+
...doc21.data()
|
|
6236
6236
|
}));
|
|
6237
6237
|
}
|
|
6238
6238
|
/**
|
|
@@ -6304,9 +6304,9 @@ var NotificationService = class extends BaseService {
|
|
|
6304
6304
|
orderBy("notificationTime", "desc")
|
|
6305
6305
|
);
|
|
6306
6306
|
const querySnapshot = await getDocs9(q);
|
|
6307
|
-
return querySnapshot.docs.map((
|
|
6308
|
-
id:
|
|
6309
|
-
...
|
|
6307
|
+
return querySnapshot.docs.map((doc21) => ({
|
|
6308
|
+
id: doc21.id,
|
|
6309
|
+
...doc21.data()
|
|
6310
6310
|
}));
|
|
6311
6311
|
}
|
|
6312
6312
|
/**
|
|
@@ -6319,24 +6319,267 @@ var NotificationService = class extends BaseService {
|
|
|
6319
6319
|
orderBy("notificationTime", "desc")
|
|
6320
6320
|
);
|
|
6321
6321
|
const querySnapshot = await getDocs9(q);
|
|
6322
|
-
return querySnapshot.docs.map((
|
|
6323
|
-
id:
|
|
6324
|
-
...
|
|
6322
|
+
return querySnapshot.docs.map((doc21) => ({
|
|
6323
|
+
id: doc21.id,
|
|
6324
|
+
...doc21.data()
|
|
6325
6325
|
}));
|
|
6326
6326
|
}
|
|
6327
6327
|
};
|
|
6328
6328
|
|
|
6329
|
-
// src/services/
|
|
6329
|
+
// src/services/procedure/procedure.service.ts
|
|
6330
6330
|
import {
|
|
6331
6331
|
collection as collection11,
|
|
6332
6332
|
doc as doc12,
|
|
6333
6333
|
getDoc as getDoc16,
|
|
6334
6334
|
getDocs as getDocs10,
|
|
6335
|
-
setDoc as setDoc13,
|
|
6336
|
-
updateDoc as updateDoc14,
|
|
6337
|
-
deleteDoc as deleteDoc7,
|
|
6338
6335
|
query as query10,
|
|
6339
6336
|
where as where10,
|
|
6337
|
+
updateDoc as updateDoc14,
|
|
6338
|
+
setDoc as setDoc13,
|
|
6339
|
+
serverTimestamp as serverTimestamp13
|
|
6340
|
+
} from "firebase/firestore";
|
|
6341
|
+
|
|
6342
|
+
// src/types/procedure/index.ts
|
|
6343
|
+
var PROCEDURES_COLLECTION = "procedures";
|
|
6344
|
+
|
|
6345
|
+
// src/validations/procedure.schema.ts
|
|
6346
|
+
import { z as z16 } from "zod";
|
|
6347
|
+
var createProcedureSchema = z16.object({
|
|
6348
|
+
name: z16.string().min(1).max(200),
|
|
6349
|
+
description: z16.string().min(1).max(2e3),
|
|
6350
|
+
family: z16.nativeEnum(ProcedureFamily),
|
|
6351
|
+
categoryId: z16.string().min(1),
|
|
6352
|
+
subcategoryId: z16.string().min(1),
|
|
6353
|
+
technologyId: z16.string().min(1),
|
|
6354
|
+
productId: z16.string().min(1),
|
|
6355
|
+
price: z16.number().min(0),
|
|
6356
|
+
currency: z16.nativeEnum(Currency),
|
|
6357
|
+
pricingMeasure: z16.nativeEnum(PricingMeasure),
|
|
6358
|
+
duration: z16.number().min(1).max(480),
|
|
6359
|
+
// Max 8 hours
|
|
6360
|
+
practitionerId: z16.string().min(1),
|
|
6361
|
+
clinicBranchId: z16.string().min(1)
|
|
6362
|
+
});
|
|
6363
|
+
var updateProcedureSchema = z16.object({
|
|
6364
|
+
name: z16.string().min(1).max(200).optional(),
|
|
6365
|
+
description: z16.string().min(1).max(2e3).optional(),
|
|
6366
|
+
price: z16.number().min(0).optional(),
|
|
6367
|
+
currency: z16.nativeEnum(Currency).optional(),
|
|
6368
|
+
pricingMeasure: z16.nativeEnum(PricingMeasure).optional(),
|
|
6369
|
+
duration: z16.number().min(1).max(480).optional(),
|
|
6370
|
+
// Max 8 hours
|
|
6371
|
+
isActive: z16.boolean().optional()
|
|
6372
|
+
});
|
|
6373
|
+
var procedureSchema = createProcedureSchema.extend({
|
|
6374
|
+
id: z16.string().min(1),
|
|
6375
|
+
category: z16.any(),
|
|
6376
|
+
// We'll validate the full category object separately
|
|
6377
|
+
subcategory: z16.any(),
|
|
6378
|
+
// We'll validate the full subcategory object separately
|
|
6379
|
+
technology: z16.any(),
|
|
6380
|
+
// We'll validate the full technology object separately
|
|
6381
|
+
product: z16.any(),
|
|
6382
|
+
// We'll validate the full product object separately
|
|
6383
|
+
blockingConditions: z16.array(z16.any()),
|
|
6384
|
+
// We'll validate blocking conditions separately
|
|
6385
|
+
treatmentBenefits: z16.array(z16.any()),
|
|
6386
|
+
// We'll validate treatment benefits separately
|
|
6387
|
+
preRequirements: z16.array(z16.any()),
|
|
6388
|
+
// We'll validate requirements separately
|
|
6389
|
+
postRequirements: z16.array(z16.any()),
|
|
6390
|
+
// We'll validate requirements separately
|
|
6391
|
+
certificationRequirement: z16.any(),
|
|
6392
|
+
// We'll validate certification requirement separately
|
|
6393
|
+
documentationTemplates: z16.array(z16.any()),
|
|
6394
|
+
// We'll validate documentation templates separately
|
|
6395
|
+
isActive: z16.boolean(),
|
|
6396
|
+
createdAt: z16.date(),
|
|
6397
|
+
updatedAt: z16.date()
|
|
6398
|
+
});
|
|
6399
|
+
|
|
6400
|
+
// src/backoffice/types/category.types.ts
|
|
6401
|
+
var CATEGORIES_COLLECTION = "backoffice_categories";
|
|
6402
|
+
|
|
6403
|
+
// src/backoffice/types/subcategory.types.ts
|
|
6404
|
+
var SUBCATEGORIES_COLLECTION = "subcategories";
|
|
6405
|
+
|
|
6406
|
+
// src/backoffice/types/technology.types.ts
|
|
6407
|
+
var TECHNOLOGIES_COLLECTION = "technologies";
|
|
6408
|
+
|
|
6409
|
+
// src/backoffice/types/product.types.ts
|
|
6410
|
+
var PRODUCTS_COLLECTION = "products";
|
|
6411
|
+
|
|
6412
|
+
// src/services/procedure/procedure.service.ts
|
|
6413
|
+
var ProcedureService = class extends BaseService {
|
|
6414
|
+
constructor(db, auth, app) {
|
|
6415
|
+
super(db, auth, app);
|
|
6416
|
+
}
|
|
6417
|
+
/**
|
|
6418
|
+
* Creates a new procedure
|
|
6419
|
+
* @param data - The data for creating a new procedure
|
|
6420
|
+
* @returns The created procedure
|
|
6421
|
+
*/
|
|
6422
|
+
async createProcedure(data) {
|
|
6423
|
+
const validatedData = createProcedureSchema.parse(data);
|
|
6424
|
+
const [category, subcategory, technology, product] = await Promise.all([
|
|
6425
|
+
this.getCategory(validatedData.categoryId),
|
|
6426
|
+
this.getSubcategory(validatedData.subcategoryId),
|
|
6427
|
+
this.getTechnology(validatedData.technologyId),
|
|
6428
|
+
this.getProduct(validatedData.productId)
|
|
6429
|
+
]);
|
|
6430
|
+
if (!category || !subcategory || !technology || !product) {
|
|
6431
|
+
throw new Error("One or more required entities not found");
|
|
6432
|
+
}
|
|
6433
|
+
const procedure = {
|
|
6434
|
+
...validatedData,
|
|
6435
|
+
category,
|
|
6436
|
+
subcategory,
|
|
6437
|
+
technology,
|
|
6438
|
+
product,
|
|
6439
|
+
blockingConditions: technology.blockingConditions,
|
|
6440
|
+
treatmentBenefits: technology.benefits,
|
|
6441
|
+
preRequirements: technology.requirements.pre,
|
|
6442
|
+
postRequirements: technology.requirements.post,
|
|
6443
|
+
certificationRequirement: technology.certificationRequirement,
|
|
6444
|
+
documentationTemplates: technology.documentationTemplates || [],
|
|
6445
|
+
isActive: true,
|
|
6446
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
6447
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
6448
|
+
};
|
|
6449
|
+
const id = this.generateId();
|
|
6450
|
+
const docRef = doc12(this.db, PROCEDURES_COLLECTION, id);
|
|
6451
|
+
await setDoc13(docRef, {
|
|
6452
|
+
...procedure,
|
|
6453
|
+
id,
|
|
6454
|
+
createdAt: serverTimestamp13(),
|
|
6455
|
+
updatedAt: serverTimestamp13()
|
|
6456
|
+
});
|
|
6457
|
+
return { ...procedure, id };
|
|
6458
|
+
}
|
|
6459
|
+
/**
|
|
6460
|
+
* Gets a procedure by ID
|
|
6461
|
+
* @param id - The ID of the procedure to get
|
|
6462
|
+
* @returns The procedure if found, null otherwise
|
|
6463
|
+
*/
|
|
6464
|
+
async getProcedure(id) {
|
|
6465
|
+
const docRef = doc12(this.db, PROCEDURES_COLLECTION, id);
|
|
6466
|
+
const docSnap = await getDoc16(docRef);
|
|
6467
|
+
if (!docSnap.exists()) {
|
|
6468
|
+
return null;
|
|
6469
|
+
}
|
|
6470
|
+
return docSnap.data();
|
|
6471
|
+
}
|
|
6472
|
+
/**
|
|
6473
|
+
* Gets all procedures for a clinic branch
|
|
6474
|
+
* @param clinicBranchId - The ID of the clinic branch
|
|
6475
|
+
* @returns List of procedures
|
|
6476
|
+
*/
|
|
6477
|
+
async getProceduresByClinicBranch(clinicBranchId) {
|
|
6478
|
+
const q = query10(
|
|
6479
|
+
collection11(this.db, PROCEDURES_COLLECTION),
|
|
6480
|
+
where10("clinicBranchId", "==", clinicBranchId),
|
|
6481
|
+
where10("isActive", "==", true)
|
|
6482
|
+
);
|
|
6483
|
+
const snapshot = await getDocs10(q);
|
|
6484
|
+
return snapshot.docs.map((doc21) => doc21.data());
|
|
6485
|
+
}
|
|
6486
|
+
/**
|
|
6487
|
+
* Gets all procedures for a practitioner
|
|
6488
|
+
* @param practitionerId - The ID of the practitioner
|
|
6489
|
+
* @returns List of procedures
|
|
6490
|
+
*/
|
|
6491
|
+
async getProceduresByPractitioner(practitionerId) {
|
|
6492
|
+
const q = query10(
|
|
6493
|
+
collection11(this.db, PROCEDURES_COLLECTION),
|
|
6494
|
+
where10("practitionerId", "==", practitionerId),
|
|
6495
|
+
where10("isActive", "==", true)
|
|
6496
|
+
);
|
|
6497
|
+
const snapshot = await getDocs10(q);
|
|
6498
|
+
return snapshot.docs.map((doc21) => doc21.data());
|
|
6499
|
+
}
|
|
6500
|
+
/**
|
|
6501
|
+
* Updates a procedure
|
|
6502
|
+
* @param id - The ID of the procedure to update
|
|
6503
|
+
* @param data - The data to update
|
|
6504
|
+
* @returns The updated procedure
|
|
6505
|
+
*/
|
|
6506
|
+
async updateProcedure(id, data) {
|
|
6507
|
+
const validatedData = updateProcedureSchema.parse(data);
|
|
6508
|
+
const existingProcedure = await this.getProcedure(id);
|
|
6509
|
+
if (!existingProcedure) {
|
|
6510
|
+
throw new Error(`Procedure with ID ${id} not found`);
|
|
6511
|
+
}
|
|
6512
|
+
const docRef = doc12(this.db, PROCEDURES_COLLECTION, id);
|
|
6513
|
+
await updateDoc14(docRef, {
|
|
6514
|
+
...validatedData,
|
|
6515
|
+
updatedAt: serverTimestamp13()
|
|
6516
|
+
});
|
|
6517
|
+
return {
|
|
6518
|
+
...existingProcedure,
|
|
6519
|
+
...validatedData,
|
|
6520
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
6521
|
+
};
|
|
6522
|
+
}
|
|
6523
|
+
/**
|
|
6524
|
+
* Deactivates a procedure
|
|
6525
|
+
* @param id - The ID of the procedure to deactivate
|
|
6526
|
+
*/
|
|
6527
|
+
async deactivateProcedure(id) {
|
|
6528
|
+
const docRef = doc12(this.db, PROCEDURES_COLLECTION, id);
|
|
6529
|
+
await updateDoc14(docRef, {
|
|
6530
|
+
isActive: false,
|
|
6531
|
+
updatedAt: serverTimestamp13()
|
|
6532
|
+
});
|
|
6533
|
+
}
|
|
6534
|
+
/**
|
|
6535
|
+
* Gets a category by ID
|
|
6536
|
+
* @private
|
|
6537
|
+
*/
|
|
6538
|
+
async getCategory(id) {
|
|
6539
|
+
const docRef = doc12(this.db, CATEGORIES_COLLECTION, id);
|
|
6540
|
+
const docSnap = await getDoc16(docRef);
|
|
6541
|
+
return docSnap.exists() ? docSnap.data() : null;
|
|
6542
|
+
}
|
|
6543
|
+
/**
|
|
6544
|
+
* Gets a subcategory by ID
|
|
6545
|
+
* @private
|
|
6546
|
+
*/
|
|
6547
|
+
async getSubcategory(id) {
|
|
6548
|
+
const docRef = doc12(this.db, SUBCATEGORIES_COLLECTION, id);
|
|
6549
|
+
const docSnap = await getDoc16(docRef);
|
|
6550
|
+
return docSnap.exists() ? docSnap.data() : null;
|
|
6551
|
+
}
|
|
6552
|
+
/**
|
|
6553
|
+
* Gets a technology by ID
|
|
6554
|
+
* @private
|
|
6555
|
+
*/
|
|
6556
|
+
async getTechnology(id) {
|
|
6557
|
+
const docRef = doc12(this.db, TECHNOLOGIES_COLLECTION, id);
|
|
6558
|
+
const docSnap = await getDoc16(docRef);
|
|
6559
|
+
return docSnap.exists() ? docSnap.data() : null;
|
|
6560
|
+
}
|
|
6561
|
+
/**
|
|
6562
|
+
* Gets a product by ID
|
|
6563
|
+
* @private
|
|
6564
|
+
*/
|
|
6565
|
+
async getProduct(id) {
|
|
6566
|
+
const docRef = doc12(this.db, PRODUCTS_COLLECTION, id);
|
|
6567
|
+
const docSnap = await getDoc16(docRef);
|
|
6568
|
+
return docSnap.exists() ? docSnap.data() : null;
|
|
6569
|
+
}
|
|
6570
|
+
};
|
|
6571
|
+
|
|
6572
|
+
// src/services/documentation-templates/documentation-template.service.ts
|
|
6573
|
+
import {
|
|
6574
|
+
collection as collection12,
|
|
6575
|
+
doc as doc13,
|
|
6576
|
+
getDoc as getDoc17,
|
|
6577
|
+
getDocs as getDocs11,
|
|
6578
|
+
setDoc as setDoc14,
|
|
6579
|
+
updateDoc as updateDoc15,
|
|
6580
|
+
deleteDoc as deleteDoc8,
|
|
6581
|
+
query as query11,
|
|
6582
|
+
where as where11,
|
|
6340
6583
|
orderBy as orderBy2,
|
|
6341
6584
|
limit,
|
|
6342
6585
|
startAfter
|
|
@@ -6344,7 +6587,7 @@ import {
|
|
|
6344
6587
|
var DocumentationTemplateService = class extends BaseService {
|
|
6345
6588
|
constructor() {
|
|
6346
6589
|
super(...arguments);
|
|
6347
|
-
this.collectionRef =
|
|
6590
|
+
this.collectionRef = collection12(
|
|
6348
6591
|
this.db,
|
|
6349
6592
|
DOCUMENTATION_TEMPLATES_COLLECTION
|
|
6350
6593
|
);
|
|
@@ -6375,8 +6618,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
6375
6618
|
isActive: true,
|
|
6376
6619
|
tags: validatedData.tags || []
|
|
6377
6620
|
};
|
|
6378
|
-
const docRef =
|
|
6379
|
-
await
|
|
6621
|
+
const docRef = doc13(this.collectionRef, templateId);
|
|
6622
|
+
await setDoc14(docRef, template);
|
|
6380
6623
|
return template;
|
|
6381
6624
|
}
|
|
6382
6625
|
/**
|
|
@@ -6385,8 +6628,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
6385
6628
|
* @returns The template or null if not found
|
|
6386
6629
|
*/
|
|
6387
6630
|
async getTemplateById(templateId) {
|
|
6388
|
-
const docRef =
|
|
6389
|
-
const docSnap = await
|
|
6631
|
+
const docRef = doc13(this.collectionRef, templateId);
|
|
6632
|
+
const docSnap = await getDoc17(docRef);
|
|
6390
6633
|
if (!docSnap.exists()) {
|
|
6391
6634
|
return null;
|
|
6392
6635
|
}
|
|
@@ -6417,8 +6660,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
6417
6660
|
updatedAt: Date.now(),
|
|
6418
6661
|
version: template.version + 1
|
|
6419
6662
|
};
|
|
6420
|
-
const docRef =
|
|
6421
|
-
await
|
|
6663
|
+
const docRef = doc13(this.collectionRef, templateId);
|
|
6664
|
+
await updateDoc15(docRef, updateData);
|
|
6422
6665
|
return {
|
|
6423
6666
|
...template,
|
|
6424
6667
|
...updateData
|
|
@@ -6429,8 +6672,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
6429
6672
|
* @param templateId - ID of the template to delete
|
|
6430
6673
|
*/
|
|
6431
6674
|
async deleteTemplate(templateId) {
|
|
6432
|
-
const docRef =
|
|
6433
|
-
await
|
|
6675
|
+
const docRef = doc13(this.collectionRef, templateId);
|
|
6676
|
+
await deleteDoc8(docRef);
|
|
6434
6677
|
}
|
|
6435
6678
|
/**
|
|
6436
6679
|
* Get all active templates
|
|
@@ -6439,21 +6682,21 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
6439
6682
|
* @returns Array of templates and the last document for pagination
|
|
6440
6683
|
*/
|
|
6441
6684
|
async getActiveTemplates(pageSize = 20, lastDoc) {
|
|
6442
|
-
let q =
|
|
6685
|
+
let q = query11(
|
|
6443
6686
|
this.collectionRef,
|
|
6444
|
-
|
|
6687
|
+
where11("isActive", "==", true),
|
|
6445
6688
|
orderBy2("updatedAt", "desc"),
|
|
6446
6689
|
limit(pageSize)
|
|
6447
6690
|
);
|
|
6448
6691
|
if (lastDoc) {
|
|
6449
|
-
q =
|
|
6692
|
+
q = query11(q, startAfter(lastDoc));
|
|
6450
6693
|
}
|
|
6451
|
-
const querySnapshot = await
|
|
6694
|
+
const querySnapshot = await getDocs11(q);
|
|
6452
6695
|
const templates = [];
|
|
6453
6696
|
let lastVisible = null;
|
|
6454
|
-
querySnapshot.forEach((
|
|
6455
|
-
templates.push(
|
|
6456
|
-
lastVisible =
|
|
6697
|
+
querySnapshot.forEach((doc21) => {
|
|
6698
|
+
templates.push(doc21.data());
|
|
6699
|
+
lastVisible = doc21;
|
|
6457
6700
|
});
|
|
6458
6701
|
return {
|
|
6459
6702
|
templates,
|
|
@@ -6468,22 +6711,22 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
6468
6711
|
* @returns Array of templates and the last document for pagination
|
|
6469
6712
|
*/
|
|
6470
6713
|
async getTemplatesByTags(tags, pageSize = 20, lastDoc) {
|
|
6471
|
-
let q =
|
|
6714
|
+
let q = query11(
|
|
6472
6715
|
this.collectionRef,
|
|
6473
|
-
|
|
6474
|
-
|
|
6716
|
+
where11("isActive", "==", true),
|
|
6717
|
+
where11("tags", "array-contains-any", tags),
|
|
6475
6718
|
orderBy2("updatedAt", "desc"),
|
|
6476
6719
|
limit(pageSize)
|
|
6477
6720
|
);
|
|
6478
6721
|
if (lastDoc) {
|
|
6479
|
-
q =
|
|
6722
|
+
q = query11(q, startAfter(lastDoc));
|
|
6480
6723
|
}
|
|
6481
|
-
const querySnapshot = await
|
|
6724
|
+
const querySnapshot = await getDocs11(q);
|
|
6482
6725
|
const templates = [];
|
|
6483
6726
|
let lastVisible = null;
|
|
6484
|
-
querySnapshot.forEach((
|
|
6485
|
-
templates.push(
|
|
6486
|
-
lastVisible =
|
|
6727
|
+
querySnapshot.forEach((doc21) => {
|
|
6728
|
+
templates.push(doc21.data());
|
|
6729
|
+
lastVisible = doc21;
|
|
6487
6730
|
});
|
|
6488
6731
|
return {
|
|
6489
6732
|
templates,
|
|
@@ -6498,21 +6741,21 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
6498
6741
|
* @returns Array of templates and the last document for pagination
|
|
6499
6742
|
*/
|
|
6500
6743
|
async getTemplatesByCreator(userId, pageSize = 20, lastDoc) {
|
|
6501
|
-
let q =
|
|
6744
|
+
let q = query11(
|
|
6502
6745
|
this.collectionRef,
|
|
6503
|
-
|
|
6746
|
+
where11("createdBy", "==", userId),
|
|
6504
6747
|
orderBy2("updatedAt", "desc"),
|
|
6505
6748
|
limit(pageSize)
|
|
6506
6749
|
);
|
|
6507
6750
|
if (lastDoc) {
|
|
6508
|
-
q =
|
|
6751
|
+
q = query11(q, startAfter(lastDoc));
|
|
6509
6752
|
}
|
|
6510
|
-
const querySnapshot = await
|
|
6753
|
+
const querySnapshot = await getDocs11(q);
|
|
6511
6754
|
const templates = [];
|
|
6512
6755
|
let lastVisible = null;
|
|
6513
|
-
querySnapshot.forEach((
|
|
6514
|
-
templates.push(
|
|
6515
|
-
lastVisible =
|
|
6756
|
+
querySnapshot.forEach((doc21) => {
|
|
6757
|
+
templates.push(doc21.data());
|
|
6758
|
+
lastVisible = doc21;
|
|
6516
6759
|
});
|
|
6517
6760
|
return {
|
|
6518
6761
|
templates,
|
|
@@ -6523,14 +6766,14 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
6523
6766
|
|
|
6524
6767
|
// src/services/documentation-templates/filled-document.service.ts
|
|
6525
6768
|
import {
|
|
6526
|
-
collection as
|
|
6527
|
-
doc as
|
|
6528
|
-
getDoc as
|
|
6529
|
-
getDocs as
|
|
6530
|
-
setDoc as
|
|
6531
|
-
updateDoc as
|
|
6532
|
-
query as
|
|
6533
|
-
where as
|
|
6769
|
+
collection as collection13,
|
|
6770
|
+
doc as doc14,
|
|
6771
|
+
getDoc as getDoc18,
|
|
6772
|
+
getDocs as getDocs12,
|
|
6773
|
+
setDoc as setDoc15,
|
|
6774
|
+
updateDoc as updateDoc16,
|
|
6775
|
+
query as query12,
|
|
6776
|
+
where as where12,
|
|
6534
6777
|
orderBy as orderBy3,
|
|
6535
6778
|
limit as limit2,
|
|
6536
6779
|
startAfter as startAfter2
|
|
@@ -6538,7 +6781,7 @@ import {
|
|
|
6538
6781
|
var FilledDocumentService = class extends BaseService {
|
|
6539
6782
|
constructor(...args) {
|
|
6540
6783
|
super(...args);
|
|
6541
|
-
this.collectionRef =
|
|
6784
|
+
this.collectionRef = collection13(
|
|
6542
6785
|
this.db,
|
|
6543
6786
|
FILLED_DOCUMENTS_COLLECTION
|
|
6544
6787
|
);
|
|
@@ -6571,8 +6814,8 @@ var FilledDocumentService = class extends BaseService {
|
|
|
6571
6814
|
values: {},
|
|
6572
6815
|
status: "draft" /* DRAFT */
|
|
6573
6816
|
};
|
|
6574
|
-
const docRef =
|
|
6575
|
-
await
|
|
6817
|
+
const docRef = doc14(this.collectionRef, documentId);
|
|
6818
|
+
await setDoc15(docRef, filledDocument);
|
|
6576
6819
|
return filledDocument;
|
|
6577
6820
|
}
|
|
6578
6821
|
/**
|
|
@@ -6581,8 +6824,8 @@ var FilledDocumentService = class extends BaseService {
|
|
|
6581
6824
|
* @returns The filled document or null if not found
|
|
6582
6825
|
*/
|
|
6583
6826
|
async getFilledDocumentById(documentId) {
|
|
6584
|
-
const docRef =
|
|
6585
|
-
const docSnap = await
|
|
6827
|
+
const docRef = doc14(this.collectionRef, documentId);
|
|
6828
|
+
const docSnap = await getDoc18(docRef);
|
|
6586
6829
|
if (!docSnap.exists()) {
|
|
6587
6830
|
return null;
|
|
6588
6831
|
}
|
|
@@ -6610,8 +6853,8 @@ var FilledDocumentService = class extends BaseService {
|
|
|
6610
6853
|
if (status) {
|
|
6611
6854
|
updateData.status = status;
|
|
6612
6855
|
}
|
|
6613
|
-
const docRef =
|
|
6614
|
-
await
|
|
6856
|
+
const docRef = doc14(this.collectionRef, documentId);
|
|
6857
|
+
await updateDoc16(docRef, updateData);
|
|
6615
6858
|
return {
|
|
6616
6859
|
...filledDocument,
|
|
6617
6860
|
...updateData
|
|
@@ -6625,21 +6868,21 @@ var FilledDocumentService = class extends BaseService {
|
|
|
6625
6868
|
* @returns Array of filled documents and the last document for pagination
|
|
6626
6869
|
*/
|
|
6627
6870
|
async getFilledDocumentsByPatient(patientId, pageSize = 20, lastDoc) {
|
|
6628
|
-
let q =
|
|
6871
|
+
let q = query12(
|
|
6629
6872
|
this.collectionRef,
|
|
6630
|
-
|
|
6873
|
+
where12("patientId", "==", patientId),
|
|
6631
6874
|
orderBy3("updatedAt", "desc"),
|
|
6632
6875
|
limit2(pageSize)
|
|
6633
6876
|
);
|
|
6634
6877
|
if (lastDoc) {
|
|
6635
|
-
q =
|
|
6878
|
+
q = query12(q, startAfter2(lastDoc));
|
|
6636
6879
|
}
|
|
6637
|
-
const querySnapshot = await
|
|
6880
|
+
const querySnapshot = await getDocs12(q);
|
|
6638
6881
|
const documents = [];
|
|
6639
6882
|
let lastVisible = null;
|
|
6640
|
-
querySnapshot.forEach((
|
|
6641
|
-
documents.push(
|
|
6642
|
-
lastVisible =
|
|
6883
|
+
querySnapshot.forEach((doc21) => {
|
|
6884
|
+
documents.push(doc21.data());
|
|
6885
|
+
lastVisible = doc21;
|
|
6643
6886
|
});
|
|
6644
6887
|
return {
|
|
6645
6888
|
documents,
|
|
@@ -6654,21 +6897,21 @@ var FilledDocumentService = class extends BaseService {
|
|
|
6654
6897
|
* @returns Array of filled documents and the last document for pagination
|
|
6655
6898
|
*/
|
|
6656
6899
|
async getFilledDocumentsByPractitioner(practitionerId, pageSize = 20, lastDoc) {
|
|
6657
|
-
let q =
|
|
6900
|
+
let q = query12(
|
|
6658
6901
|
this.collectionRef,
|
|
6659
|
-
|
|
6902
|
+
where12("practitionerId", "==", practitionerId),
|
|
6660
6903
|
orderBy3("updatedAt", "desc"),
|
|
6661
6904
|
limit2(pageSize)
|
|
6662
6905
|
);
|
|
6663
6906
|
if (lastDoc) {
|
|
6664
|
-
q =
|
|
6907
|
+
q = query12(q, startAfter2(lastDoc));
|
|
6665
6908
|
}
|
|
6666
|
-
const querySnapshot = await
|
|
6909
|
+
const querySnapshot = await getDocs12(q);
|
|
6667
6910
|
const documents = [];
|
|
6668
6911
|
let lastVisible = null;
|
|
6669
|
-
querySnapshot.forEach((
|
|
6670
|
-
documents.push(
|
|
6671
|
-
lastVisible =
|
|
6912
|
+
querySnapshot.forEach((doc21) => {
|
|
6913
|
+
documents.push(doc21.data());
|
|
6914
|
+
lastVisible = doc21;
|
|
6672
6915
|
});
|
|
6673
6916
|
return {
|
|
6674
6917
|
documents,
|
|
@@ -6683,21 +6926,21 @@ var FilledDocumentService = class extends BaseService {
|
|
|
6683
6926
|
* @returns Array of filled documents and the last document for pagination
|
|
6684
6927
|
*/
|
|
6685
6928
|
async getFilledDocumentsByClinic(clinicId, pageSize = 20, lastDoc) {
|
|
6686
|
-
let q =
|
|
6929
|
+
let q = query12(
|
|
6687
6930
|
this.collectionRef,
|
|
6688
|
-
|
|
6931
|
+
where12("clinicId", "==", clinicId),
|
|
6689
6932
|
orderBy3("updatedAt", "desc"),
|
|
6690
6933
|
limit2(pageSize)
|
|
6691
6934
|
);
|
|
6692
6935
|
if (lastDoc) {
|
|
6693
|
-
q =
|
|
6936
|
+
q = query12(q, startAfter2(lastDoc));
|
|
6694
6937
|
}
|
|
6695
|
-
const querySnapshot = await
|
|
6938
|
+
const querySnapshot = await getDocs12(q);
|
|
6696
6939
|
const documents = [];
|
|
6697
6940
|
let lastVisible = null;
|
|
6698
|
-
querySnapshot.forEach((
|
|
6699
|
-
documents.push(
|
|
6700
|
-
lastVisible =
|
|
6941
|
+
querySnapshot.forEach((doc21) => {
|
|
6942
|
+
documents.push(doc21.data());
|
|
6943
|
+
lastVisible = doc21;
|
|
6701
6944
|
});
|
|
6702
6945
|
return {
|
|
6703
6946
|
documents,
|
|
@@ -6712,21 +6955,21 @@ var FilledDocumentService = class extends BaseService {
|
|
|
6712
6955
|
* @returns Array of filled documents and the last document for pagination
|
|
6713
6956
|
*/
|
|
6714
6957
|
async getFilledDocumentsByTemplate(templateId, pageSize = 20, lastDoc) {
|
|
6715
|
-
let q =
|
|
6958
|
+
let q = query12(
|
|
6716
6959
|
this.collectionRef,
|
|
6717
|
-
|
|
6960
|
+
where12("templateId", "==", templateId),
|
|
6718
6961
|
orderBy3("updatedAt", "desc"),
|
|
6719
6962
|
limit2(pageSize)
|
|
6720
6963
|
);
|
|
6721
6964
|
if (lastDoc) {
|
|
6722
|
-
q =
|
|
6965
|
+
q = query12(q, startAfter2(lastDoc));
|
|
6723
6966
|
}
|
|
6724
|
-
const querySnapshot = await
|
|
6967
|
+
const querySnapshot = await getDocs12(q);
|
|
6725
6968
|
const documents = [];
|
|
6726
6969
|
let lastVisible = null;
|
|
6727
|
-
querySnapshot.forEach((
|
|
6728
|
-
documents.push(
|
|
6729
|
-
lastVisible =
|
|
6970
|
+
querySnapshot.forEach((doc21) => {
|
|
6971
|
+
documents.push(doc21.data());
|
|
6972
|
+
lastVisible = doc21;
|
|
6730
6973
|
});
|
|
6731
6974
|
return {
|
|
6732
6975
|
documents,
|
|
@@ -6741,21 +6984,21 @@ var FilledDocumentService = class extends BaseService {
|
|
|
6741
6984
|
* @returns Array of filled documents and the last document for pagination
|
|
6742
6985
|
*/
|
|
6743
6986
|
async getFilledDocumentsByStatus(status, pageSize = 20, lastDoc) {
|
|
6744
|
-
let q =
|
|
6987
|
+
let q = query12(
|
|
6745
6988
|
this.collectionRef,
|
|
6746
|
-
|
|
6989
|
+
where12("status", "==", status),
|
|
6747
6990
|
orderBy3("updatedAt", "desc"),
|
|
6748
6991
|
limit2(pageSize)
|
|
6749
6992
|
);
|
|
6750
6993
|
if (lastDoc) {
|
|
6751
|
-
q =
|
|
6994
|
+
q = query12(q, startAfter2(lastDoc));
|
|
6752
6995
|
}
|
|
6753
|
-
const querySnapshot = await
|
|
6996
|
+
const querySnapshot = await getDocs12(q);
|
|
6754
6997
|
const documents = [];
|
|
6755
6998
|
let lastVisible = null;
|
|
6756
|
-
querySnapshot.forEach((
|
|
6757
|
-
documents.push(
|
|
6758
|
-
lastVisible =
|
|
6999
|
+
querySnapshot.forEach((doc21) => {
|
|
7000
|
+
documents.push(doc21.data());
|
|
7001
|
+
lastVisible = doc21;
|
|
6759
7002
|
});
|
|
6760
7003
|
return {
|
|
6761
7004
|
documents,
|
|
@@ -6765,7 +7008,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
6765
7008
|
};
|
|
6766
7009
|
|
|
6767
7010
|
// src/services/calendar/calendar-refactored.service.ts
|
|
6768
|
-
import { Timestamp as
|
|
7011
|
+
import { Timestamp as Timestamp24, serverTimestamp as serverTimestamp19 } from "firebase/firestore";
|
|
6769
7012
|
|
|
6770
7013
|
// src/types/calendar/synced-calendar.types.ts
|
|
6771
7014
|
var SyncedCalendarProvider = /* @__PURE__ */ ((SyncedCalendarProvider3) => {
|
|
@@ -6778,57 +7021,57 @@ var SYNCED_CALENDARS_COLLECTION = "syncedCalendars";
|
|
|
6778
7021
|
|
|
6779
7022
|
// src/services/calendar/calendar-refactored.service.ts
|
|
6780
7023
|
import {
|
|
6781
|
-
doc as
|
|
6782
|
-
getDoc as
|
|
6783
|
-
collection as
|
|
6784
|
-
query as
|
|
6785
|
-
where as
|
|
6786
|
-
getDocs as
|
|
6787
|
-
setDoc as
|
|
6788
|
-
updateDoc as
|
|
7024
|
+
doc as doc20,
|
|
7025
|
+
getDoc as getDoc23,
|
|
7026
|
+
collection as collection18,
|
|
7027
|
+
query as query17,
|
|
7028
|
+
where as where17,
|
|
7029
|
+
getDocs as getDocs17,
|
|
7030
|
+
setDoc as setDoc20,
|
|
7031
|
+
updateDoc as updateDoc21
|
|
6789
7032
|
} from "firebase/firestore";
|
|
6790
7033
|
|
|
6791
7034
|
// src/validations/calendar.schema.ts
|
|
6792
|
-
import { z as
|
|
6793
|
-
import { Timestamp as
|
|
7035
|
+
import { z as z18 } from "zod";
|
|
7036
|
+
import { Timestamp as Timestamp18 } from "firebase/firestore";
|
|
6794
7037
|
|
|
6795
7038
|
// src/validations/profile-info.schema.ts
|
|
6796
|
-
import { z as
|
|
6797
|
-
import { Timestamp as
|
|
6798
|
-
var clinicInfoSchema2 =
|
|
6799
|
-
id:
|
|
6800
|
-
featuredPhoto:
|
|
6801
|
-
name:
|
|
6802
|
-
description:
|
|
7039
|
+
import { z as z17 } from "zod";
|
|
7040
|
+
import { Timestamp as Timestamp17 } from "firebase/firestore";
|
|
7041
|
+
var clinicInfoSchema2 = z17.object({
|
|
7042
|
+
id: z17.string(),
|
|
7043
|
+
featuredPhoto: z17.string(),
|
|
7044
|
+
name: z17.string(),
|
|
7045
|
+
description: z17.string(),
|
|
6803
7046
|
location: clinicLocationSchema,
|
|
6804
7047
|
contactInfo: clinicContactInfoSchema
|
|
6805
7048
|
});
|
|
6806
|
-
var practitionerProfileInfoSchema =
|
|
6807
|
-
id:
|
|
6808
|
-
practitionerPhoto:
|
|
6809
|
-
name:
|
|
6810
|
-
email:
|
|
6811
|
-
phone:
|
|
7049
|
+
var practitionerProfileInfoSchema = z17.object({
|
|
7050
|
+
id: z17.string(),
|
|
7051
|
+
practitionerPhoto: z17.string().nullable(),
|
|
7052
|
+
name: z17.string(),
|
|
7053
|
+
email: z17.string().email(),
|
|
7054
|
+
phone: z17.string().nullable(),
|
|
6812
7055
|
certification: practitionerCertificationSchema
|
|
6813
7056
|
});
|
|
6814
|
-
var patientProfileInfoSchema =
|
|
6815
|
-
id:
|
|
6816
|
-
fullName:
|
|
6817
|
-
email:
|
|
6818
|
-
phone:
|
|
6819
|
-
dateOfBirth:
|
|
6820
|
-
gender:
|
|
7057
|
+
var patientProfileInfoSchema = z17.object({
|
|
7058
|
+
id: z17.string(),
|
|
7059
|
+
fullName: z17.string(),
|
|
7060
|
+
email: z17.string().email(),
|
|
7061
|
+
phone: z17.string().nullable(),
|
|
7062
|
+
dateOfBirth: z17.instanceof(Timestamp17),
|
|
7063
|
+
gender: z17.nativeEnum(Gender)
|
|
6821
7064
|
});
|
|
6822
7065
|
|
|
6823
7066
|
// src/validations/calendar.schema.ts
|
|
6824
7067
|
var MIN_APPOINTMENT_DURATION = 15;
|
|
6825
|
-
var calendarEventTimeSchema =
|
|
6826
|
-
start:
|
|
6827
|
-
end:
|
|
7068
|
+
var calendarEventTimeSchema = z18.object({
|
|
7069
|
+
start: z18.instanceof(Date).or(z18.instanceof(Timestamp18)),
|
|
7070
|
+
end: z18.instanceof(Date).or(z18.instanceof(Timestamp18))
|
|
6828
7071
|
}).refine(
|
|
6829
7072
|
(data) => {
|
|
6830
|
-
const startDate = data.start instanceof
|
|
6831
|
-
const endDate = data.end instanceof
|
|
7073
|
+
const startDate = data.start instanceof Timestamp18 ? data.start.toDate() : data.start;
|
|
7074
|
+
const endDate = data.end instanceof Timestamp18 ? data.end.toDate() : data.end;
|
|
6832
7075
|
return startDate < endDate;
|
|
6833
7076
|
},
|
|
6834
7077
|
{
|
|
@@ -6837,7 +7080,7 @@ var calendarEventTimeSchema = z17.object({
|
|
|
6837
7080
|
}
|
|
6838
7081
|
).refine(
|
|
6839
7082
|
(data) => {
|
|
6840
|
-
const startDate = data.start instanceof
|
|
7083
|
+
const startDate = data.start instanceof Timestamp18 ? data.start.toDate() : data.start;
|
|
6841
7084
|
return startDate > /* @__PURE__ */ new Date();
|
|
6842
7085
|
},
|
|
6843
7086
|
{
|
|
@@ -6845,46 +7088,46 @@ var calendarEventTimeSchema = z17.object({
|
|
|
6845
7088
|
path: ["start"]
|
|
6846
7089
|
}
|
|
6847
7090
|
);
|
|
6848
|
-
var timeSlotSchema2 =
|
|
6849
|
-
start:
|
|
6850
|
-
end:
|
|
6851
|
-
isAvailable:
|
|
7091
|
+
var timeSlotSchema2 = z18.object({
|
|
7092
|
+
start: z18.date(),
|
|
7093
|
+
end: z18.date(),
|
|
7094
|
+
isAvailable: z18.boolean()
|
|
6852
7095
|
}).refine((data) => data.start < data.end, {
|
|
6853
7096
|
message: "End time must be after start time",
|
|
6854
7097
|
path: ["end"]
|
|
6855
7098
|
});
|
|
6856
|
-
var syncedCalendarEventSchema =
|
|
6857
|
-
eventId:
|
|
6858
|
-
syncedCalendarProvider:
|
|
6859
|
-
syncedAt:
|
|
7099
|
+
var syncedCalendarEventSchema = z18.object({
|
|
7100
|
+
eventId: z18.string(),
|
|
7101
|
+
syncedCalendarProvider: z18.nativeEnum(SyncedCalendarProvider),
|
|
7102
|
+
syncedAt: z18.instanceof(Date).or(z18.instanceof(Timestamp18))
|
|
6860
7103
|
});
|
|
6861
|
-
var procedureInfoSchema =
|
|
6862
|
-
name:
|
|
6863
|
-
description:
|
|
6864
|
-
duration:
|
|
6865
|
-
price:
|
|
6866
|
-
currency:
|
|
7104
|
+
var procedureInfoSchema = z18.object({
|
|
7105
|
+
name: z18.string(),
|
|
7106
|
+
description: z18.string(),
|
|
7107
|
+
duration: z18.number().min(MIN_APPOINTMENT_DURATION),
|
|
7108
|
+
price: z18.number().min(0),
|
|
7109
|
+
currency: z18.nativeEnum(Currency)
|
|
6867
7110
|
});
|
|
6868
|
-
var procedureCategorizationSchema =
|
|
6869
|
-
procedureFamily:
|
|
7111
|
+
var procedureCategorizationSchema = z18.object({
|
|
7112
|
+
procedureFamily: z18.string(),
|
|
6870
7113
|
// Replace with proper enum when available
|
|
6871
|
-
procedureCategory:
|
|
7114
|
+
procedureCategory: z18.string(),
|
|
6872
7115
|
// Replace with proper enum when available
|
|
6873
|
-
procedureSubcategory:
|
|
7116
|
+
procedureSubcategory: z18.string(),
|
|
6874
7117
|
// Replace with proper enum when available
|
|
6875
|
-
procedureTechnology:
|
|
7118
|
+
procedureTechnology: z18.string(),
|
|
6876
7119
|
// Replace with proper enum when available
|
|
6877
|
-
procedureProduct:
|
|
7120
|
+
procedureProduct: z18.string()
|
|
6878
7121
|
// Replace with proper enum when available
|
|
6879
7122
|
});
|
|
6880
|
-
var createAppointmentSchema =
|
|
6881
|
-
clinicId:
|
|
6882
|
-
doctorId:
|
|
6883
|
-
patientId:
|
|
6884
|
-
procedureId:
|
|
7123
|
+
var createAppointmentSchema = z18.object({
|
|
7124
|
+
clinicId: z18.string().min(1, "Clinic ID is required"),
|
|
7125
|
+
doctorId: z18.string().min(1, "Doctor ID is required"),
|
|
7126
|
+
patientId: z18.string().min(1, "Patient ID is required"),
|
|
7127
|
+
procedureId: z18.string().min(1, "Procedure ID is required"),
|
|
6885
7128
|
eventLocation: clinicLocationSchema,
|
|
6886
7129
|
eventTime: calendarEventTimeSchema,
|
|
6887
|
-
description:
|
|
7130
|
+
description: z18.string().optional()
|
|
6888
7131
|
}).refine(
|
|
6889
7132
|
(data) => {
|
|
6890
7133
|
return true;
|
|
@@ -6893,125 +7136,125 @@ var createAppointmentSchema = z17.object({
|
|
|
6893
7136
|
message: "Invalid appointment parameters"
|
|
6894
7137
|
}
|
|
6895
7138
|
);
|
|
6896
|
-
var updateAppointmentSchema =
|
|
6897
|
-
appointmentId:
|
|
6898
|
-
clinicId:
|
|
6899
|
-
doctorId:
|
|
6900
|
-
patientId:
|
|
7139
|
+
var updateAppointmentSchema = z18.object({
|
|
7140
|
+
appointmentId: z18.string().min(1, "Appointment ID is required"),
|
|
7141
|
+
clinicId: z18.string().min(1, "Clinic ID is required"),
|
|
7142
|
+
doctorId: z18.string().min(1, "Doctor ID is required"),
|
|
7143
|
+
patientId: z18.string().min(1, "Patient ID is required"),
|
|
6901
7144
|
eventTime: calendarEventTimeSchema.optional(),
|
|
6902
|
-
description:
|
|
6903
|
-
status:
|
|
7145
|
+
description: z18.string().optional(),
|
|
7146
|
+
status: z18.nativeEnum(CalendarEventStatus).optional()
|
|
6904
7147
|
});
|
|
6905
|
-
var createCalendarEventSchema =
|
|
6906
|
-
id:
|
|
6907
|
-
clinicBranchId:
|
|
6908
|
-
clinicBranchInfo:
|
|
6909
|
-
practitionerProfileId:
|
|
7148
|
+
var createCalendarEventSchema = z18.object({
|
|
7149
|
+
id: z18.string(),
|
|
7150
|
+
clinicBranchId: z18.string().nullable().optional(),
|
|
7151
|
+
clinicBranchInfo: z18.any().nullable().optional(),
|
|
7152
|
+
practitionerProfileId: z18.string().nullable().optional(),
|
|
6910
7153
|
practitionerProfileInfo: practitionerProfileInfoSchema.nullable().optional(),
|
|
6911
|
-
patientProfileId:
|
|
7154
|
+
patientProfileId: z18.string().nullable().optional(),
|
|
6912
7155
|
patientProfileInfo: patientProfileInfoSchema.nullable().optional(),
|
|
6913
|
-
procedureId:
|
|
6914
|
-
appointmentId:
|
|
6915
|
-
syncedCalendarEventId:
|
|
6916
|
-
eventName:
|
|
7156
|
+
procedureId: z18.string().nullable().optional(),
|
|
7157
|
+
appointmentId: z18.string().nullable().optional(),
|
|
7158
|
+
syncedCalendarEventId: z18.array(syncedCalendarEventSchema).nullable().optional(),
|
|
7159
|
+
eventName: z18.string().min(1, "Event name is required"),
|
|
6917
7160
|
eventLocation: clinicLocationSchema.optional(),
|
|
6918
7161
|
eventTime: calendarEventTimeSchema,
|
|
6919
|
-
description:
|
|
6920
|
-
status:
|
|
6921
|
-
syncStatus:
|
|
6922
|
-
eventType:
|
|
6923
|
-
createdAt:
|
|
7162
|
+
description: z18.string().optional(),
|
|
7163
|
+
status: z18.nativeEnum(CalendarEventStatus),
|
|
7164
|
+
syncStatus: z18.nativeEnum(CalendarSyncStatus),
|
|
7165
|
+
eventType: z18.nativeEnum(CalendarEventType),
|
|
7166
|
+
createdAt: z18.any(),
|
|
6924
7167
|
// FieldValue for server timestamp
|
|
6925
|
-
updatedAt:
|
|
7168
|
+
updatedAt: z18.any()
|
|
6926
7169
|
// FieldValue for server timestamp
|
|
6927
7170
|
});
|
|
6928
|
-
var updateCalendarEventSchema =
|
|
6929
|
-
syncedCalendarEventId:
|
|
6930
|
-
appointmentId:
|
|
6931
|
-
eventName:
|
|
7171
|
+
var updateCalendarEventSchema = z18.object({
|
|
7172
|
+
syncedCalendarEventId: z18.array(syncedCalendarEventSchema).nullable().optional(),
|
|
7173
|
+
appointmentId: z18.string().nullable().optional(),
|
|
7174
|
+
eventName: z18.string().optional(),
|
|
6932
7175
|
eventTime: calendarEventTimeSchema.optional(),
|
|
6933
|
-
description:
|
|
6934
|
-
status:
|
|
6935
|
-
syncStatus:
|
|
6936
|
-
eventType:
|
|
6937
|
-
updatedAt:
|
|
7176
|
+
description: z18.string().optional(),
|
|
7177
|
+
status: z18.nativeEnum(CalendarEventStatus).optional(),
|
|
7178
|
+
syncStatus: z18.nativeEnum(CalendarSyncStatus).optional(),
|
|
7179
|
+
eventType: z18.nativeEnum(CalendarEventType).optional(),
|
|
7180
|
+
updatedAt: z18.any()
|
|
6938
7181
|
// FieldValue for server timestamp
|
|
6939
7182
|
});
|
|
6940
|
-
var calendarEventSchema =
|
|
6941
|
-
id:
|
|
6942
|
-
clinicBranchId:
|
|
6943
|
-
clinicBranchInfo:
|
|
7183
|
+
var calendarEventSchema = z18.object({
|
|
7184
|
+
id: z18.string(),
|
|
7185
|
+
clinicBranchId: z18.string().nullable().optional(),
|
|
7186
|
+
clinicBranchInfo: z18.any().nullable().optional(),
|
|
6944
7187
|
// Will be replaced with proper clinic info schema
|
|
6945
|
-
practitionerProfileId:
|
|
7188
|
+
practitionerProfileId: z18.string().nullable().optional(),
|
|
6946
7189
|
practitionerProfileInfo: practitionerProfileInfoSchema.nullable().optional(),
|
|
6947
|
-
patientProfileId:
|
|
7190
|
+
patientProfileId: z18.string().nullable().optional(),
|
|
6948
7191
|
patientProfileInfo: patientProfileInfoSchema.nullable().optional(),
|
|
6949
|
-
procedureId:
|
|
7192
|
+
procedureId: z18.string().nullable().optional(),
|
|
6950
7193
|
procedureInfo: procedureInfoSchema.nullable().optional(),
|
|
6951
7194
|
procedureCategorization: procedureCategorizationSchema.nullable().optional(),
|
|
6952
|
-
appointmentId:
|
|
6953
|
-
syncedCalendarEventId:
|
|
6954
|
-
eventName:
|
|
7195
|
+
appointmentId: z18.string().nullable().optional(),
|
|
7196
|
+
syncedCalendarEventId: z18.array(syncedCalendarEventSchema).nullable().optional(),
|
|
7197
|
+
eventName: z18.string(),
|
|
6955
7198
|
eventLocation: clinicLocationSchema.optional(),
|
|
6956
7199
|
eventTime: calendarEventTimeSchema,
|
|
6957
|
-
description:
|
|
6958
|
-
status:
|
|
6959
|
-
syncStatus:
|
|
6960
|
-
eventType:
|
|
6961
|
-
createdAt:
|
|
6962
|
-
updatedAt:
|
|
7200
|
+
description: z18.string().optional(),
|
|
7201
|
+
status: z18.nativeEnum(CalendarEventStatus),
|
|
7202
|
+
syncStatus: z18.nativeEnum(CalendarSyncStatus),
|
|
7203
|
+
eventType: z18.nativeEnum(CalendarEventType),
|
|
7204
|
+
createdAt: z18.instanceof(Date).or(z18.instanceof(Timestamp18)),
|
|
7205
|
+
updatedAt: z18.instanceof(Date).or(z18.instanceof(Timestamp18))
|
|
6963
7206
|
});
|
|
6964
7207
|
|
|
6965
7208
|
// src/services/calendar/utils/clinic.utils.ts
|
|
6966
7209
|
import {
|
|
6967
|
-
collection as
|
|
6968
|
-
doc as
|
|
6969
|
-
getDoc as
|
|
6970
|
-
getDocs as
|
|
6971
|
-
setDoc as
|
|
6972
|
-
updateDoc as
|
|
6973
|
-
deleteDoc as
|
|
6974
|
-
query as
|
|
6975
|
-
where as
|
|
7210
|
+
collection as collection14,
|
|
7211
|
+
doc as doc16,
|
|
7212
|
+
getDoc as getDoc19,
|
|
7213
|
+
getDocs as getDocs13,
|
|
7214
|
+
setDoc as setDoc16,
|
|
7215
|
+
updateDoc as updateDoc17,
|
|
7216
|
+
deleteDoc as deleteDoc9,
|
|
7217
|
+
query as query13,
|
|
7218
|
+
where as where13,
|
|
6976
7219
|
orderBy as orderBy4,
|
|
6977
|
-
Timestamp as
|
|
6978
|
-
serverTimestamp as
|
|
7220
|
+
Timestamp as Timestamp19,
|
|
7221
|
+
serverTimestamp as serverTimestamp15
|
|
6979
7222
|
} from "firebase/firestore";
|
|
6980
7223
|
|
|
6981
7224
|
// src/services/calendar/utils/docs.utils.ts
|
|
6982
|
-
import { doc as
|
|
7225
|
+
import { doc as doc15 } from "firebase/firestore";
|
|
6983
7226
|
function getPractitionerCalendarEventDocRef(db, practitionerId, eventId) {
|
|
6984
|
-
return
|
|
7227
|
+
return doc15(
|
|
6985
7228
|
db,
|
|
6986
7229
|
`${PRACTITIONERS_COLLECTION}/${practitionerId}/${CALENDAR_COLLECTION}/${eventId}`
|
|
6987
7230
|
);
|
|
6988
7231
|
}
|
|
6989
7232
|
function getPatientCalendarEventDocRef(db, patientId, eventId) {
|
|
6990
|
-
return
|
|
7233
|
+
return doc15(
|
|
6991
7234
|
db,
|
|
6992
7235
|
`${PATIENTS_COLLECTION}/${patientId}/${CALENDAR_COLLECTION}/${eventId}`
|
|
6993
7236
|
);
|
|
6994
7237
|
}
|
|
6995
7238
|
function getClinicCalendarEventDocRef(db, clinicId, eventId) {
|
|
6996
|
-
return
|
|
7239
|
+
return doc15(
|
|
6997
7240
|
db,
|
|
6998
7241
|
`${CLINICS_COLLECTION}/${clinicId}/${CALENDAR_COLLECTION}/${eventId}`
|
|
6999
7242
|
);
|
|
7000
7243
|
}
|
|
7001
7244
|
function getPractitionerSyncedCalendarDocRef(db, practitionerId, syncedCalendarId) {
|
|
7002
|
-
return
|
|
7245
|
+
return doc15(
|
|
7003
7246
|
db,
|
|
7004
7247
|
`${PRACTITIONERS_COLLECTION}/${practitionerId}/syncedCalendars/${syncedCalendarId}`
|
|
7005
7248
|
);
|
|
7006
7249
|
}
|
|
7007
7250
|
function getPatientSyncedCalendarDocRef(db, patientId, syncedCalendarId) {
|
|
7008
|
-
return
|
|
7251
|
+
return doc15(
|
|
7009
7252
|
db,
|
|
7010
7253
|
`${PATIENTS_COLLECTION}/${patientId}/syncedCalendars/${syncedCalendarId}`
|
|
7011
7254
|
);
|
|
7012
7255
|
}
|
|
7013
7256
|
function getClinicSyncedCalendarDocRef(db, clinicId, syncedCalendarId) {
|
|
7014
|
-
return
|
|
7257
|
+
return doc15(
|
|
7015
7258
|
db,
|
|
7016
7259
|
`${CLINICS_COLLECTION}/${clinicId}/syncedCalendars/${syncedCalendarId}`
|
|
7017
7260
|
);
|
|
@@ -7024,31 +7267,31 @@ async function createClinicCalendarEventUtil(db, clinicId, eventData, generateId
|
|
|
7024
7267
|
const newEvent = {
|
|
7025
7268
|
id: eventId,
|
|
7026
7269
|
...eventData,
|
|
7027
|
-
createdAt:
|
|
7028
|
-
updatedAt:
|
|
7270
|
+
createdAt: serverTimestamp15(),
|
|
7271
|
+
updatedAt: serverTimestamp15()
|
|
7029
7272
|
};
|
|
7030
|
-
await
|
|
7273
|
+
await setDoc16(eventRef, newEvent);
|
|
7031
7274
|
return {
|
|
7032
7275
|
...newEvent,
|
|
7033
|
-
createdAt:
|
|
7034
|
-
updatedAt:
|
|
7276
|
+
createdAt: Timestamp19.now(),
|
|
7277
|
+
updatedAt: Timestamp19.now()
|
|
7035
7278
|
};
|
|
7036
7279
|
}
|
|
7037
7280
|
async function updateClinicCalendarEventUtil(db, clinicId, eventId, updateData) {
|
|
7038
7281
|
const eventRef = getClinicCalendarEventDocRef(db, clinicId, eventId);
|
|
7039
7282
|
const updates = {
|
|
7040
7283
|
...updateData,
|
|
7041
|
-
updatedAt:
|
|
7284
|
+
updatedAt: serverTimestamp15()
|
|
7042
7285
|
};
|
|
7043
|
-
await
|
|
7044
|
-
const updatedDoc = await
|
|
7286
|
+
await updateDoc17(eventRef, updates);
|
|
7287
|
+
const updatedDoc = await getDoc19(eventRef);
|
|
7045
7288
|
if (!updatedDoc.exists()) {
|
|
7046
7289
|
throw new Error("Event not found after update");
|
|
7047
7290
|
}
|
|
7048
7291
|
return updatedDoc.data();
|
|
7049
7292
|
}
|
|
7050
7293
|
async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
|
|
7051
|
-
const clinicDoc = await
|
|
7294
|
+
const clinicDoc = await getDoc19(doc16(db, `clinics/${clinicId}`));
|
|
7052
7295
|
if (!clinicDoc.exists()) {
|
|
7053
7296
|
throw new Error(`Clinic with ID ${clinicId} not found`);
|
|
7054
7297
|
}
|
|
@@ -7057,8 +7300,8 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
|
|
|
7057
7300
|
if (!clinicGroupId) {
|
|
7058
7301
|
return false;
|
|
7059
7302
|
}
|
|
7060
|
-
const clinicGroupDoc = await
|
|
7061
|
-
|
|
7303
|
+
const clinicGroupDoc = await getDoc19(
|
|
7304
|
+
doc16(db, `${CLINIC_GROUPS_COLLECTION}/${clinicGroupId}`)
|
|
7062
7305
|
);
|
|
7063
7306
|
if (!clinicGroupDoc.exists()) {
|
|
7064
7307
|
return false;
|
|
@@ -7069,17 +7312,17 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
|
|
|
7069
7312
|
|
|
7070
7313
|
// src/services/calendar/utils/patient.utils.ts
|
|
7071
7314
|
import {
|
|
7072
|
-
collection as
|
|
7073
|
-
getDoc as
|
|
7074
|
-
getDocs as
|
|
7075
|
-
setDoc as
|
|
7076
|
-
updateDoc as
|
|
7077
|
-
deleteDoc as
|
|
7078
|
-
query as
|
|
7079
|
-
where as
|
|
7315
|
+
collection as collection15,
|
|
7316
|
+
getDoc as getDoc20,
|
|
7317
|
+
getDocs as getDocs14,
|
|
7318
|
+
setDoc as setDoc17,
|
|
7319
|
+
updateDoc as updateDoc18,
|
|
7320
|
+
deleteDoc as deleteDoc10,
|
|
7321
|
+
query as query14,
|
|
7322
|
+
where as where14,
|
|
7080
7323
|
orderBy as orderBy5,
|
|
7081
|
-
Timestamp as
|
|
7082
|
-
serverTimestamp as
|
|
7324
|
+
Timestamp as Timestamp20,
|
|
7325
|
+
serverTimestamp as serverTimestamp16
|
|
7083
7326
|
} from "firebase/firestore";
|
|
7084
7327
|
async function createPatientCalendarEventUtil(db, patientId, eventData, generateId2) {
|
|
7085
7328
|
const eventId = generateId2();
|
|
@@ -7087,24 +7330,24 @@ async function createPatientCalendarEventUtil(db, patientId, eventData, generate
|
|
|
7087
7330
|
const newEvent = {
|
|
7088
7331
|
id: eventId,
|
|
7089
7332
|
...eventData,
|
|
7090
|
-
createdAt:
|
|
7091
|
-
updatedAt:
|
|
7333
|
+
createdAt: serverTimestamp16(),
|
|
7334
|
+
updatedAt: serverTimestamp16()
|
|
7092
7335
|
};
|
|
7093
|
-
await
|
|
7336
|
+
await setDoc17(eventRef, newEvent);
|
|
7094
7337
|
return {
|
|
7095
7338
|
...newEvent,
|
|
7096
|
-
createdAt:
|
|
7097
|
-
updatedAt:
|
|
7339
|
+
createdAt: Timestamp20.now(),
|
|
7340
|
+
updatedAt: Timestamp20.now()
|
|
7098
7341
|
};
|
|
7099
7342
|
}
|
|
7100
7343
|
async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData) {
|
|
7101
7344
|
const eventRef = getPatientCalendarEventDocRef(db, patientId, eventId);
|
|
7102
7345
|
const updates = {
|
|
7103
7346
|
...updateData,
|
|
7104
|
-
updatedAt:
|
|
7347
|
+
updatedAt: serverTimestamp16()
|
|
7105
7348
|
};
|
|
7106
|
-
await
|
|
7107
|
-
const updatedDoc = await
|
|
7349
|
+
await updateDoc18(eventRef, updates);
|
|
7350
|
+
const updatedDoc = await getDoc20(eventRef);
|
|
7108
7351
|
if (!updatedDoc.exists()) {
|
|
7109
7352
|
throw new Error("Event not found after update");
|
|
7110
7353
|
}
|
|
@@ -7113,17 +7356,17 @@ async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData
|
|
|
7113
7356
|
|
|
7114
7357
|
// src/services/calendar/utils/practitioner.utils.ts
|
|
7115
7358
|
import {
|
|
7116
|
-
collection as
|
|
7117
|
-
getDoc as
|
|
7118
|
-
getDocs as
|
|
7119
|
-
setDoc as
|
|
7120
|
-
updateDoc as
|
|
7121
|
-
deleteDoc as
|
|
7122
|
-
query as
|
|
7123
|
-
where as
|
|
7359
|
+
collection as collection16,
|
|
7360
|
+
getDoc as getDoc21,
|
|
7361
|
+
getDocs as getDocs15,
|
|
7362
|
+
setDoc as setDoc18,
|
|
7363
|
+
updateDoc as updateDoc19,
|
|
7364
|
+
deleteDoc as deleteDoc11,
|
|
7365
|
+
query as query15,
|
|
7366
|
+
where as where15,
|
|
7124
7367
|
orderBy as orderBy6,
|
|
7125
|
-
Timestamp as
|
|
7126
|
-
serverTimestamp as
|
|
7368
|
+
Timestamp as Timestamp21,
|
|
7369
|
+
serverTimestamp as serverTimestamp17
|
|
7127
7370
|
} from "firebase/firestore";
|
|
7128
7371
|
async function createPractitionerCalendarEventUtil(db, practitionerId, eventData, generateId2) {
|
|
7129
7372
|
const eventId = generateId2();
|
|
@@ -7135,14 +7378,14 @@ async function createPractitionerCalendarEventUtil(db, practitionerId, eventData
|
|
|
7135
7378
|
const newEvent = {
|
|
7136
7379
|
id: eventId,
|
|
7137
7380
|
...eventData,
|
|
7138
|
-
createdAt:
|
|
7139
|
-
updatedAt:
|
|
7381
|
+
createdAt: serverTimestamp17(),
|
|
7382
|
+
updatedAt: serverTimestamp17()
|
|
7140
7383
|
};
|
|
7141
|
-
await
|
|
7384
|
+
await setDoc18(eventRef, newEvent);
|
|
7142
7385
|
return {
|
|
7143
7386
|
...newEvent,
|
|
7144
|
-
createdAt:
|
|
7145
|
-
updatedAt:
|
|
7387
|
+
createdAt: Timestamp21.now(),
|
|
7388
|
+
updatedAt: Timestamp21.now()
|
|
7146
7389
|
};
|
|
7147
7390
|
}
|
|
7148
7391
|
async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId, updateData) {
|
|
@@ -7153,10 +7396,10 @@ async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId,
|
|
|
7153
7396
|
);
|
|
7154
7397
|
const updates = {
|
|
7155
7398
|
...updateData,
|
|
7156
|
-
updatedAt:
|
|
7399
|
+
updatedAt: serverTimestamp17()
|
|
7157
7400
|
};
|
|
7158
|
-
await
|
|
7159
|
-
const updatedDoc = await
|
|
7401
|
+
await updateDoc19(eventRef, updates);
|
|
7402
|
+
const updatedDoc = await getDoc21(eventRef);
|
|
7160
7403
|
if (!updatedDoc.exists()) {
|
|
7161
7404
|
throw new Error("Event not found after update");
|
|
7162
7405
|
}
|
|
@@ -7233,16 +7476,16 @@ async function updateAppointmentUtil(db, clinicId, practitionerId, patientId, ev
|
|
|
7233
7476
|
|
|
7234
7477
|
// src/services/calendar/utils/synced-calendar.utils.ts
|
|
7235
7478
|
import {
|
|
7236
|
-
collection as
|
|
7237
|
-
getDoc as
|
|
7238
|
-
getDocs as
|
|
7239
|
-
setDoc as
|
|
7240
|
-
updateDoc as
|
|
7241
|
-
deleteDoc as
|
|
7242
|
-
query as
|
|
7479
|
+
collection as collection17,
|
|
7480
|
+
getDoc as getDoc22,
|
|
7481
|
+
getDocs as getDocs16,
|
|
7482
|
+
setDoc as setDoc19,
|
|
7483
|
+
updateDoc as updateDoc20,
|
|
7484
|
+
deleteDoc as deleteDoc12,
|
|
7485
|
+
query as query16,
|
|
7243
7486
|
orderBy as orderBy7,
|
|
7244
|
-
Timestamp as
|
|
7245
|
-
serverTimestamp as
|
|
7487
|
+
Timestamp as Timestamp22,
|
|
7488
|
+
serverTimestamp as serverTimestamp18
|
|
7246
7489
|
} from "firebase/firestore";
|
|
7247
7490
|
async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendarData, generateId2) {
|
|
7248
7491
|
const calendarId = generateId2();
|
|
@@ -7254,14 +7497,14 @@ async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendar
|
|
|
7254
7497
|
const newCalendar = {
|
|
7255
7498
|
id: calendarId,
|
|
7256
7499
|
...calendarData,
|
|
7257
|
-
createdAt:
|
|
7258
|
-
updatedAt:
|
|
7500
|
+
createdAt: serverTimestamp18(),
|
|
7501
|
+
updatedAt: serverTimestamp18()
|
|
7259
7502
|
};
|
|
7260
|
-
await
|
|
7503
|
+
await setDoc19(calendarRef, newCalendar);
|
|
7261
7504
|
return {
|
|
7262
7505
|
...newCalendar,
|
|
7263
|
-
createdAt:
|
|
7264
|
-
updatedAt:
|
|
7506
|
+
createdAt: Timestamp22.now(),
|
|
7507
|
+
updatedAt: Timestamp22.now()
|
|
7265
7508
|
};
|
|
7266
7509
|
}
|
|
7267
7510
|
async function createPatientSyncedCalendarUtil(db, patientId, calendarData, generateId2) {
|
|
@@ -7270,14 +7513,14 @@ async function createPatientSyncedCalendarUtil(db, patientId, calendarData, gene
|
|
|
7270
7513
|
const newCalendar = {
|
|
7271
7514
|
id: calendarId,
|
|
7272
7515
|
...calendarData,
|
|
7273
|
-
createdAt:
|
|
7274
|
-
updatedAt:
|
|
7516
|
+
createdAt: serverTimestamp18(),
|
|
7517
|
+
updatedAt: serverTimestamp18()
|
|
7275
7518
|
};
|
|
7276
|
-
await
|
|
7519
|
+
await setDoc19(calendarRef, newCalendar);
|
|
7277
7520
|
return {
|
|
7278
7521
|
...newCalendar,
|
|
7279
|
-
createdAt:
|
|
7280
|
-
updatedAt:
|
|
7522
|
+
createdAt: Timestamp22.now(),
|
|
7523
|
+
updatedAt: Timestamp22.now()
|
|
7281
7524
|
};
|
|
7282
7525
|
}
|
|
7283
7526
|
async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, generateId2) {
|
|
@@ -7286,14 +7529,14 @@ async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, genera
|
|
|
7286
7529
|
const newCalendar = {
|
|
7287
7530
|
id: calendarId,
|
|
7288
7531
|
...calendarData,
|
|
7289
|
-
createdAt:
|
|
7290
|
-
updatedAt:
|
|
7532
|
+
createdAt: serverTimestamp18(),
|
|
7533
|
+
updatedAt: serverTimestamp18()
|
|
7291
7534
|
};
|
|
7292
|
-
await
|
|
7535
|
+
await setDoc19(calendarRef, newCalendar);
|
|
7293
7536
|
return {
|
|
7294
7537
|
...newCalendar,
|
|
7295
|
-
createdAt:
|
|
7296
|
-
updatedAt:
|
|
7538
|
+
createdAt: Timestamp22.now(),
|
|
7539
|
+
updatedAt: Timestamp22.now()
|
|
7297
7540
|
};
|
|
7298
7541
|
}
|
|
7299
7542
|
async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId) {
|
|
@@ -7302,54 +7545,54 @@ async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId)
|
|
|
7302
7545
|
practitionerId,
|
|
7303
7546
|
calendarId
|
|
7304
7547
|
);
|
|
7305
|
-
const calendarDoc = await
|
|
7548
|
+
const calendarDoc = await getDoc22(calendarRef);
|
|
7306
7549
|
if (!calendarDoc.exists()) {
|
|
7307
7550
|
return null;
|
|
7308
7551
|
}
|
|
7309
7552
|
return calendarDoc.data();
|
|
7310
7553
|
}
|
|
7311
7554
|
async function getPractitionerSyncedCalendarsUtil(db, practitionerId) {
|
|
7312
|
-
const calendarsRef =
|
|
7555
|
+
const calendarsRef = collection17(
|
|
7313
7556
|
db,
|
|
7314
7557
|
`practitioners/${practitionerId}/${SYNCED_CALENDARS_COLLECTION}`
|
|
7315
7558
|
);
|
|
7316
|
-
const q =
|
|
7317
|
-
const querySnapshot = await
|
|
7318
|
-
return querySnapshot.docs.map((
|
|
7559
|
+
const q = query16(calendarsRef, orderBy7("createdAt", "desc"));
|
|
7560
|
+
const querySnapshot = await getDocs16(q);
|
|
7561
|
+
return querySnapshot.docs.map((doc21) => doc21.data());
|
|
7319
7562
|
}
|
|
7320
7563
|
async function getPatientSyncedCalendarUtil(db, patientId, calendarId) {
|
|
7321
7564
|
const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
|
|
7322
|
-
const calendarDoc = await
|
|
7565
|
+
const calendarDoc = await getDoc22(calendarRef);
|
|
7323
7566
|
if (!calendarDoc.exists()) {
|
|
7324
7567
|
return null;
|
|
7325
7568
|
}
|
|
7326
7569
|
return calendarDoc.data();
|
|
7327
7570
|
}
|
|
7328
7571
|
async function getPatientSyncedCalendarsUtil(db, patientId) {
|
|
7329
|
-
const calendarsRef =
|
|
7572
|
+
const calendarsRef = collection17(
|
|
7330
7573
|
db,
|
|
7331
7574
|
`patients/${patientId}/${SYNCED_CALENDARS_COLLECTION}`
|
|
7332
7575
|
);
|
|
7333
|
-
const q =
|
|
7334
|
-
const querySnapshot = await
|
|
7335
|
-
return querySnapshot.docs.map((
|
|
7576
|
+
const q = query16(calendarsRef, orderBy7("createdAt", "desc"));
|
|
7577
|
+
const querySnapshot = await getDocs16(q);
|
|
7578
|
+
return querySnapshot.docs.map((doc21) => doc21.data());
|
|
7336
7579
|
}
|
|
7337
7580
|
async function getClinicSyncedCalendarUtil(db, clinicId, calendarId) {
|
|
7338
7581
|
const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
|
|
7339
|
-
const calendarDoc = await
|
|
7582
|
+
const calendarDoc = await getDoc22(calendarRef);
|
|
7340
7583
|
if (!calendarDoc.exists()) {
|
|
7341
7584
|
return null;
|
|
7342
7585
|
}
|
|
7343
7586
|
return calendarDoc.data();
|
|
7344
7587
|
}
|
|
7345
7588
|
async function getClinicSyncedCalendarsUtil(db, clinicId) {
|
|
7346
|
-
const calendarsRef =
|
|
7589
|
+
const calendarsRef = collection17(
|
|
7347
7590
|
db,
|
|
7348
7591
|
`clinics/${clinicId}/${SYNCED_CALENDARS_COLLECTION}`
|
|
7349
7592
|
);
|
|
7350
|
-
const q =
|
|
7351
|
-
const querySnapshot = await
|
|
7352
|
-
return querySnapshot.docs.map((
|
|
7593
|
+
const q = query16(calendarsRef, orderBy7("createdAt", "desc"));
|
|
7594
|
+
const querySnapshot = await getDocs16(q);
|
|
7595
|
+
return querySnapshot.docs.map((doc21) => doc21.data());
|
|
7353
7596
|
}
|
|
7354
7597
|
async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendarId, updateData) {
|
|
7355
7598
|
const calendarRef = getPractitionerSyncedCalendarDocRef(
|
|
@@ -7359,10 +7602,10 @@ async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendar
|
|
|
7359
7602
|
);
|
|
7360
7603
|
const updates = {
|
|
7361
7604
|
...updateData,
|
|
7362
|
-
updatedAt:
|
|
7605
|
+
updatedAt: serverTimestamp18()
|
|
7363
7606
|
};
|
|
7364
|
-
await
|
|
7365
|
-
const updatedDoc = await
|
|
7607
|
+
await updateDoc20(calendarRef, updates);
|
|
7608
|
+
const updatedDoc = await getDoc22(calendarRef);
|
|
7366
7609
|
if (!updatedDoc.exists()) {
|
|
7367
7610
|
throw new Error("Synced calendar not found after update");
|
|
7368
7611
|
}
|
|
@@ -7372,10 +7615,10 @@ async function updatePatientSyncedCalendarUtil(db, patientId, calendarId, update
|
|
|
7372
7615
|
const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
|
|
7373
7616
|
const updates = {
|
|
7374
7617
|
...updateData,
|
|
7375
|
-
updatedAt:
|
|
7618
|
+
updatedAt: serverTimestamp18()
|
|
7376
7619
|
};
|
|
7377
|
-
await
|
|
7378
|
-
const updatedDoc = await
|
|
7620
|
+
await updateDoc20(calendarRef, updates);
|
|
7621
|
+
const updatedDoc = await getDoc22(calendarRef);
|
|
7379
7622
|
if (!updatedDoc.exists()) {
|
|
7380
7623
|
throw new Error("Synced calendar not found after update");
|
|
7381
7624
|
}
|
|
@@ -7385,10 +7628,10 @@ async function updateClinicSyncedCalendarUtil(db, clinicId, calendarId, updateDa
|
|
|
7385
7628
|
const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
|
|
7386
7629
|
const updates = {
|
|
7387
7630
|
...updateData,
|
|
7388
|
-
updatedAt:
|
|
7631
|
+
updatedAt: serverTimestamp18()
|
|
7389
7632
|
};
|
|
7390
|
-
await
|
|
7391
|
-
const updatedDoc = await
|
|
7633
|
+
await updateDoc20(calendarRef, updates);
|
|
7634
|
+
const updatedDoc = await getDoc22(calendarRef);
|
|
7392
7635
|
if (!updatedDoc.exists()) {
|
|
7393
7636
|
throw new Error("Synced calendar not found after update");
|
|
7394
7637
|
}
|
|
@@ -7400,19 +7643,19 @@ async function deletePractitionerSyncedCalendarUtil(db, practitionerId, calendar
|
|
|
7400
7643
|
practitionerId,
|
|
7401
7644
|
calendarId
|
|
7402
7645
|
);
|
|
7403
|
-
await
|
|
7646
|
+
await deleteDoc12(calendarRef);
|
|
7404
7647
|
}
|
|
7405
7648
|
async function deletePatientSyncedCalendarUtil(db, patientId, calendarId) {
|
|
7406
7649
|
const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
|
|
7407
|
-
await
|
|
7650
|
+
await deleteDoc12(calendarRef);
|
|
7408
7651
|
}
|
|
7409
7652
|
async function deleteClinicSyncedCalendarUtil(db, clinicId, calendarId) {
|
|
7410
7653
|
const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
|
|
7411
|
-
await
|
|
7654
|
+
await deleteDoc12(calendarRef);
|
|
7412
7655
|
}
|
|
7413
7656
|
async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarId) {
|
|
7414
7657
|
const updateData = {
|
|
7415
|
-
lastSyncedAt:
|
|
7658
|
+
lastSyncedAt: Timestamp22.now()
|
|
7416
7659
|
};
|
|
7417
7660
|
switch (entityType) {
|
|
7418
7661
|
case "practitioner":
|
|
@@ -7442,7 +7685,7 @@ async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarI
|
|
|
7442
7685
|
}
|
|
7443
7686
|
|
|
7444
7687
|
// src/services/calendar/utils/google-calendar.utils.ts
|
|
7445
|
-
import { Timestamp as
|
|
7688
|
+
import { Timestamp as Timestamp23 } from "firebase/firestore";
|
|
7446
7689
|
var GOOGLE_CALENDAR_API_URL = "https://www.googleapis.com/calendar/v3";
|
|
7447
7690
|
var GOOGLE_OAUTH_URL = "https://oauth2.googleapis.com/token";
|
|
7448
7691
|
var CLIENT_ID = "your-client-id";
|
|
@@ -7562,7 +7805,7 @@ async function ensureValidToken(db, entityType, entityId, syncedCalendar) {
|
|
|
7562
7805
|
tokenExpiry.setSeconds(tokenExpiry.getSeconds() + expiresIn);
|
|
7563
7806
|
const updateData = {
|
|
7564
7807
|
accessToken,
|
|
7565
|
-
tokenExpiry:
|
|
7808
|
+
tokenExpiry: Timestamp23.fromDate(tokenExpiry)
|
|
7566
7809
|
};
|
|
7567
7810
|
switch (entityType) {
|
|
7568
7811
|
case "practitioner":
|
|
@@ -7737,8 +7980,8 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
|
|
|
7737
7980
|
eventName: googleEvent.summary || "External Event",
|
|
7738
7981
|
eventLocation: googleEvent.location,
|
|
7739
7982
|
eventTime: {
|
|
7740
|
-
start:
|
|
7741
|
-
end:
|
|
7983
|
+
start: Timestamp23.fromDate(start),
|
|
7984
|
+
end: Timestamp23.fromDate(end)
|
|
7742
7985
|
},
|
|
7743
7986
|
description: googleEvent.description || "",
|
|
7744
7987
|
// External events are always set as CONFIRMED - status updates will happen externally
|
|
@@ -7752,7 +7995,7 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
|
|
|
7752
7995
|
{
|
|
7753
7996
|
eventId: googleEvent.id,
|
|
7754
7997
|
syncedCalendarProvider: "google" /* GOOGLE */,
|
|
7755
|
-
syncedAt:
|
|
7998
|
+
syncedAt: Timestamp23.now()
|
|
7756
7999
|
}
|
|
7757
8000
|
]
|
|
7758
8001
|
};
|
|
@@ -8530,7 +8773,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
8530
8773
|
return 0;
|
|
8531
8774
|
}
|
|
8532
8775
|
let importedEventsCount = 0;
|
|
8533
|
-
const currentTime =
|
|
8776
|
+
const currentTime = Timestamp24.now();
|
|
8534
8777
|
for (const calendar of activeCalendars) {
|
|
8535
8778
|
try {
|
|
8536
8779
|
let externalEvents = [];
|
|
@@ -8597,7 +8840,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
8597
8840
|
async createDoctorBlockingEvent(doctorId, eventData) {
|
|
8598
8841
|
try {
|
|
8599
8842
|
const eventId = this.generateId();
|
|
8600
|
-
const eventRef =
|
|
8843
|
+
const eventRef = doc20(
|
|
8601
8844
|
this.db,
|
|
8602
8845
|
PRACTITIONERS_COLLECTION,
|
|
8603
8846
|
doctorId,
|
|
@@ -8607,14 +8850,14 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
8607
8850
|
const newEvent = {
|
|
8608
8851
|
id: eventId,
|
|
8609
8852
|
...eventData,
|
|
8610
|
-
createdAt:
|
|
8611
|
-
updatedAt:
|
|
8853
|
+
createdAt: serverTimestamp19(),
|
|
8854
|
+
updatedAt: serverTimestamp19()
|
|
8612
8855
|
};
|
|
8613
|
-
await
|
|
8856
|
+
await setDoc20(eventRef, newEvent);
|
|
8614
8857
|
return {
|
|
8615
8858
|
...newEvent,
|
|
8616
|
-
createdAt:
|
|
8617
|
-
updatedAt:
|
|
8859
|
+
createdAt: Timestamp24.now(),
|
|
8860
|
+
updatedAt: Timestamp24.now()
|
|
8618
8861
|
};
|
|
8619
8862
|
} catch (error) {
|
|
8620
8863
|
console.error(
|
|
@@ -8632,8 +8875,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
8632
8875
|
*/
|
|
8633
8876
|
async synchronizeExternalCalendars(lookbackDays = 7, lookforwardDays = 30) {
|
|
8634
8877
|
try {
|
|
8635
|
-
const practitionersRef =
|
|
8636
|
-
const practitionersSnapshot = await
|
|
8878
|
+
const practitionersRef = collection18(this.db, PRACTITIONERS_COLLECTION);
|
|
8879
|
+
const practitionersSnapshot = await getDocs17(practitionersRef);
|
|
8637
8880
|
const startDate = /* @__PURE__ */ new Date();
|
|
8638
8881
|
startDate.setDate(startDate.getDate() - lookbackDays);
|
|
8639
8882
|
const endDate = /* @__PURE__ */ new Date();
|
|
@@ -8691,22 +8934,22 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
8691
8934
|
async updateExistingEventsFromExternalCalendars(doctorId, startDate, endDate) {
|
|
8692
8935
|
var _a;
|
|
8693
8936
|
try {
|
|
8694
|
-
const eventsRef =
|
|
8937
|
+
const eventsRef = collection18(
|
|
8695
8938
|
this.db,
|
|
8696
8939
|
PRACTITIONERS_COLLECTION,
|
|
8697
8940
|
doctorId,
|
|
8698
8941
|
CALENDAR_COLLECTION
|
|
8699
8942
|
);
|
|
8700
|
-
const q =
|
|
8943
|
+
const q = query17(
|
|
8701
8944
|
eventsRef,
|
|
8702
|
-
|
|
8703
|
-
|
|
8704
|
-
|
|
8945
|
+
where17("syncStatus", "==", "external" /* EXTERNAL */),
|
|
8946
|
+
where17("eventTime.start", ">=", Timestamp24.fromDate(startDate)),
|
|
8947
|
+
where17("eventTime.start", "<=", Timestamp24.fromDate(endDate))
|
|
8705
8948
|
);
|
|
8706
|
-
const eventsSnapshot = await
|
|
8707
|
-
const events = eventsSnapshot.docs.map((
|
|
8708
|
-
id:
|
|
8709
|
-
...
|
|
8949
|
+
const eventsSnapshot = await getDocs17(q);
|
|
8950
|
+
const events = eventsSnapshot.docs.map((doc21) => ({
|
|
8951
|
+
id: doc21.id,
|
|
8952
|
+
...doc21.data()
|
|
8710
8953
|
}));
|
|
8711
8954
|
const calendars = await this.syncedCalendarsService.getPractitionerSyncedCalendars(
|
|
8712
8955
|
doctorId
|
|
@@ -8810,21 +9053,21 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
8810
9053
|
const endTime = new Date(
|
|
8811
9054
|
externalEvent.end.dateTime || externalEvent.end.date
|
|
8812
9055
|
);
|
|
8813
|
-
const eventRef =
|
|
9056
|
+
const eventRef = doc20(
|
|
8814
9057
|
this.db,
|
|
8815
9058
|
PRACTITIONERS_COLLECTION,
|
|
8816
9059
|
doctorId,
|
|
8817
9060
|
CALENDAR_COLLECTION,
|
|
8818
9061
|
eventId
|
|
8819
9062
|
);
|
|
8820
|
-
await
|
|
9063
|
+
await updateDoc21(eventRef, {
|
|
8821
9064
|
eventName: externalEvent.summary || "External Event",
|
|
8822
9065
|
eventTime: {
|
|
8823
|
-
start:
|
|
8824
|
-
end:
|
|
9066
|
+
start: Timestamp24.fromDate(startTime),
|
|
9067
|
+
end: Timestamp24.fromDate(endTime)
|
|
8825
9068
|
},
|
|
8826
9069
|
description: externalEvent.description || "",
|
|
8827
|
-
updatedAt:
|
|
9070
|
+
updatedAt: serverTimestamp19()
|
|
8828
9071
|
});
|
|
8829
9072
|
console.log(`Updated local event ${eventId} from external event`);
|
|
8830
9073
|
} catch (error) {
|
|
@@ -8842,16 +9085,16 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
8842
9085
|
*/
|
|
8843
9086
|
async updateEventStatus(doctorId, eventId, status) {
|
|
8844
9087
|
try {
|
|
8845
|
-
const eventRef =
|
|
9088
|
+
const eventRef = doc20(
|
|
8846
9089
|
this.db,
|
|
8847
9090
|
PRACTITIONERS_COLLECTION,
|
|
8848
9091
|
doctorId,
|
|
8849
9092
|
CALENDAR_COLLECTION,
|
|
8850
9093
|
eventId
|
|
8851
9094
|
);
|
|
8852
|
-
await
|
|
9095
|
+
await updateDoc21(eventRef, {
|
|
8853
9096
|
status,
|
|
8854
|
-
updatedAt:
|
|
9097
|
+
updatedAt: serverTimestamp19()
|
|
8855
9098
|
});
|
|
8856
9099
|
console.log(`Updated event ${eventId} status to ${status}`);
|
|
8857
9100
|
} catch (error) {
|
|
@@ -8912,8 +9155,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
8912
9155
|
const startDate = eventTime.start.toDate();
|
|
8913
9156
|
const startTime = startDate;
|
|
8914
9157
|
const endTime = eventTime.end.toDate();
|
|
8915
|
-
const practitionerRef =
|
|
8916
|
-
const practitionerDoc = await
|
|
9158
|
+
const practitionerRef = doc20(this.db, PRACTITIONERS_COLLECTION, doctorId);
|
|
9159
|
+
const practitionerDoc = await getDoc23(practitionerRef);
|
|
8917
9160
|
if (!practitionerDoc.exists()) {
|
|
8918
9161
|
throw new Error(`Doctor with ID ${doctorId} not found`);
|
|
8919
9162
|
}
|
|
@@ -8970,8 +9213,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
8970
9213
|
* @returns Updated calendar event
|
|
8971
9214
|
*/
|
|
8972
9215
|
async updateAppointmentStatus(appointmentId, clinicId, status) {
|
|
8973
|
-
const appointmentRef =
|
|
8974
|
-
const appointmentDoc = await
|
|
9216
|
+
const appointmentRef = doc20(this.db, CALENDAR_COLLECTION, appointmentId);
|
|
9217
|
+
const appointmentDoc = await getDoc23(appointmentRef);
|
|
8975
9218
|
if (!appointmentDoc.exists()) {
|
|
8976
9219
|
throw new Error(`Appointment with ID ${appointmentId} not found`);
|
|
8977
9220
|
}
|
|
@@ -9102,7 +9345,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
9102
9345
|
const newSyncEvent = {
|
|
9103
9346
|
eventId: result.eventIds[0],
|
|
9104
9347
|
syncedCalendarProvider: calendar.provider,
|
|
9105
|
-
syncedAt:
|
|
9348
|
+
syncedAt: Timestamp24.now()
|
|
9106
9349
|
};
|
|
9107
9350
|
await this.updateEventWithSyncId(
|
|
9108
9351
|
entityType === "doctor" ? appointment.practitionerProfileId : appointment.patientProfileId,
|
|
@@ -9126,8 +9369,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
9126
9369
|
async updateEventWithSyncId(entityId, entityType, eventId, syncEvent) {
|
|
9127
9370
|
try {
|
|
9128
9371
|
const collectionPath = entityType === "doctor" ? `${PRACTITIONERS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}` : `${PATIENTS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
|
|
9129
|
-
const eventRef =
|
|
9130
|
-
const eventDoc = await
|
|
9372
|
+
const eventRef = doc20(this.db, collectionPath, eventId);
|
|
9373
|
+
const eventDoc = await getDoc23(eventRef);
|
|
9131
9374
|
if (eventDoc.exists()) {
|
|
9132
9375
|
const event = eventDoc.data();
|
|
9133
9376
|
const syncIds = [...event.syncedCalendarEventId || []];
|
|
@@ -9139,9 +9382,9 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
9139
9382
|
} else {
|
|
9140
9383
|
syncIds.push(syncEvent);
|
|
9141
9384
|
}
|
|
9142
|
-
await
|
|
9385
|
+
await updateDoc21(eventRef, {
|
|
9143
9386
|
syncedCalendarEventId: syncIds,
|
|
9144
|
-
updatedAt:
|
|
9387
|
+
updatedAt: serverTimestamp19()
|
|
9145
9388
|
});
|
|
9146
9389
|
console.log(
|
|
9147
9390
|
`Updated event ${eventId} with sync ID ${syncEvent.eventId}`
|
|
@@ -9165,8 +9408,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
9165
9408
|
* @returns Working hours for the clinic
|
|
9166
9409
|
*/
|
|
9167
9410
|
async getClinicWorkingHours(clinicId, date) {
|
|
9168
|
-
const clinicRef =
|
|
9169
|
-
const clinicDoc = await
|
|
9411
|
+
const clinicRef = doc20(this.db, CLINICS_COLLECTION, clinicId);
|
|
9412
|
+
const clinicDoc = await getDoc23(clinicRef);
|
|
9170
9413
|
if (!clinicDoc.exists()) {
|
|
9171
9414
|
throw new Error(`Clinic with ID ${clinicId} not found`);
|
|
9172
9415
|
}
|
|
@@ -9194,8 +9437,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
9194
9437
|
* @returns Doctor's schedule
|
|
9195
9438
|
*/
|
|
9196
9439
|
async getDoctorSchedule(doctorId, date) {
|
|
9197
|
-
const practitionerRef =
|
|
9198
|
-
const practitionerDoc = await
|
|
9440
|
+
const practitionerRef = doc20(this.db, PRACTITIONERS_COLLECTION, doctorId);
|
|
9441
|
+
const practitionerDoc = await getDoc23(practitionerRef);
|
|
9199
9442
|
if (!practitionerDoc.exists()) {
|
|
9200
9443
|
throw new Error(`Doctor with ID ${doctorId} not found`);
|
|
9201
9444
|
}
|
|
@@ -9227,19 +9470,19 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
9227
9470
|
startOfDay.setHours(0, 0, 0, 0);
|
|
9228
9471
|
const endOfDay = new Date(date);
|
|
9229
9472
|
endOfDay.setHours(23, 59, 59, 999);
|
|
9230
|
-
const appointmentsRef =
|
|
9231
|
-
const q =
|
|
9473
|
+
const appointmentsRef = collection18(this.db, CALENDAR_COLLECTION);
|
|
9474
|
+
const q = query17(
|
|
9232
9475
|
appointmentsRef,
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9476
|
+
where17("practitionerProfileId", "==", doctorId),
|
|
9477
|
+
where17("eventTime.start", ">=", Timestamp24.fromDate(startOfDay)),
|
|
9478
|
+
where17("eventTime.start", "<=", Timestamp24.fromDate(endOfDay)),
|
|
9479
|
+
where17("status", "in", [
|
|
9237
9480
|
"confirmed" /* CONFIRMED */,
|
|
9238
9481
|
"pending" /* PENDING */
|
|
9239
9482
|
])
|
|
9240
9483
|
);
|
|
9241
|
-
const querySnapshot = await
|
|
9242
|
-
return querySnapshot.docs.map((
|
|
9484
|
+
const querySnapshot = await getDocs17(q);
|
|
9485
|
+
return querySnapshot.docs.map((doc21) => doc21.data());
|
|
9243
9486
|
}
|
|
9244
9487
|
/**
|
|
9245
9488
|
* Calculates available time slots based on working hours, schedule and existing appointments
|
|
@@ -9296,11 +9539,11 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
9296
9539
|
var _a;
|
|
9297
9540
|
try {
|
|
9298
9541
|
const [clinicDoc, practitionerDoc, patientDoc, patientSensitiveInfoDoc] = await Promise.all([
|
|
9299
|
-
|
|
9300
|
-
|
|
9301
|
-
|
|
9302
|
-
|
|
9303
|
-
|
|
9542
|
+
getDoc23(doc20(this.db, CLINICS_COLLECTION, clinicId)),
|
|
9543
|
+
getDoc23(doc20(this.db, PRACTITIONERS_COLLECTION, doctorId)),
|
|
9544
|
+
getDoc23(doc20(this.db, PATIENTS_COLLECTION, patientId)),
|
|
9545
|
+
getDoc23(
|
|
9546
|
+
doc20(
|
|
9304
9547
|
this.db,
|
|
9305
9548
|
PATIENTS_COLLECTION,
|
|
9306
9549
|
patientId,
|
|
@@ -9333,7 +9576,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
9333
9576
|
fullName: `${sensitiveData.firstName} ${sensitiveData.lastName}`,
|
|
9334
9577
|
email: sensitiveData.email || "",
|
|
9335
9578
|
phone: sensitiveData.phoneNumber || null,
|
|
9336
|
-
dateOfBirth: sensitiveData.dateOfBirth ||
|
|
9579
|
+
dateOfBirth: sensitiveData.dateOfBirth || Timestamp24.now(),
|
|
9337
9580
|
gender: sensitiveData.gender || "other" /* OTHER */
|
|
9338
9581
|
};
|
|
9339
9582
|
} else if (patientDoc.exists()) {
|
|
@@ -9342,7 +9585,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
9342
9585
|
fullName: patientDoc.data().displayName,
|
|
9343
9586
|
email: ((_a = patientDoc.data().contactInfo) == null ? void 0 : _a.email) || "",
|
|
9344
9587
|
phone: patientDoc.data().phoneNumber || null,
|
|
9345
|
-
dateOfBirth: patientDoc.data().dateOfBirth ||
|
|
9588
|
+
dateOfBirth: patientDoc.data().dateOfBirth || Timestamp24.now(),
|
|
9346
9589
|
gender: patientDoc.data().gender || "other" /* OTHER */
|
|
9347
9590
|
};
|
|
9348
9591
|
}
|
|
@@ -9364,54 +9607,54 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
9364
9607
|
};
|
|
9365
9608
|
|
|
9366
9609
|
// src/validations/notification.schema.ts
|
|
9367
|
-
import { z as
|
|
9368
|
-
var baseNotificationSchema =
|
|
9369
|
-
id:
|
|
9370
|
-
userId:
|
|
9371
|
-
notificationTime:
|
|
9610
|
+
import { z as z19 } from "zod";
|
|
9611
|
+
var baseNotificationSchema = z19.object({
|
|
9612
|
+
id: z19.string().optional(),
|
|
9613
|
+
userId: z19.string(),
|
|
9614
|
+
notificationTime: z19.any(),
|
|
9372
9615
|
// Timestamp
|
|
9373
|
-
notificationType:
|
|
9374
|
-
notificationTokens:
|
|
9375
|
-
status:
|
|
9376
|
-
createdAt:
|
|
9616
|
+
notificationType: z19.nativeEnum(NotificationType),
|
|
9617
|
+
notificationTokens: z19.array(z19.string()),
|
|
9618
|
+
status: z19.nativeEnum(NotificationStatus),
|
|
9619
|
+
createdAt: z19.any().optional(),
|
|
9377
9620
|
// Timestamp
|
|
9378
|
-
updatedAt:
|
|
9621
|
+
updatedAt: z19.any().optional(),
|
|
9379
9622
|
// Timestamp
|
|
9380
|
-
title:
|
|
9381
|
-
body:
|
|
9382
|
-
isRead:
|
|
9383
|
-
userRole:
|
|
9623
|
+
title: z19.string(),
|
|
9624
|
+
body: z19.string(),
|
|
9625
|
+
isRead: z19.boolean(),
|
|
9626
|
+
userRole: z19.nativeEnum(UserRole)
|
|
9384
9627
|
});
|
|
9385
9628
|
var preRequirementNotificationSchema = baseNotificationSchema.extend({
|
|
9386
|
-
notificationType:
|
|
9387
|
-
treatmentId:
|
|
9388
|
-
requirements:
|
|
9389
|
-
deadline:
|
|
9629
|
+
notificationType: z19.literal("preRequirement" /* PRE_REQUIREMENT */),
|
|
9630
|
+
treatmentId: z19.string(),
|
|
9631
|
+
requirements: z19.array(z19.string()),
|
|
9632
|
+
deadline: z19.any()
|
|
9390
9633
|
// Timestamp
|
|
9391
9634
|
});
|
|
9392
9635
|
var postRequirementNotificationSchema = baseNotificationSchema.extend({
|
|
9393
|
-
notificationType:
|
|
9394
|
-
treatmentId:
|
|
9395
|
-
requirements:
|
|
9396
|
-
deadline:
|
|
9636
|
+
notificationType: z19.literal("postRequirement" /* POST_REQUIREMENT */),
|
|
9637
|
+
treatmentId: z19.string(),
|
|
9638
|
+
requirements: z19.array(z19.string()),
|
|
9639
|
+
deadline: z19.any()
|
|
9397
9640
|
// Timestamp
|
|
9398
9641
|
});
|
|
9399
9642
|
var appointmentReminderNotificationSchema = baseNotificationSchema.extend({
|
|
9400
|
-
notificationType:
|
|
9401
|
-
appointmentId:
|
|
9402
|
-
appointmentTime:
|
|
9643
|
+
notificationType: z19.literal("appointmentReminder" /* APPOINTMENT_REMINDER */),
|
|
9644
|
+
appointmentId: z19.string(),
|
|
9645
|
+
appointmentTime: z19.any(),
|
|
9403
9646
|
// Timestamp
|
|
9404
|
-
treatmentType:
|
|
9405
|
-
doctorName:
|
|
9647
|
+
treatmentType: z19.string(),
|
|
9648
|
+
doctorName: z19.string()
|
|
9406
9649
|
});
|
|
9407
9650
|
var appointmentNotificationSchema = baseNotificationSchema.extend({
|
|
9408
|
-
notificationType:
|
|
9409
|
-
appointmentId:
|
|
9410
|
-
appointmentStatus:
|
|
9411
|
-
previousStatus:
|
|
9412
|
-
reason:
|
|
9651
|
+
notificationType: z19.literal("appointmentNotification" /* APPOINTMENT_NOTIFICATION */),
|
|
9652
|
+
appointmentId: z19.string(),
|
|
9653
|
+
appointmentStatus: z19.string(),
|
|
9654
|
+
previousStatus: z19.string(),
|
|
9655
|
+
reason: z19.string().optional()
|
|
9413
9656
|
});
|
|
9414
|
-
var notificationSchema =
|
|
9657
|
+
var notificationSchema = z19.discriminatedUnion("notificationType", [
|
|
9415
9658
|
preRequirementNotificationSchema,
|
|
9416
9659
|
postRequirementNotificationSchema,
|
|
9417
9660
|
appointmentReminderNotificationSchema,
|
|
@@ -9473,6 +9716,7 @@ export {
|
|
|
9473
9716
|
PractitionerTokenStatus,
|
|
9474
9717
|
PricingMeasure,
|
|
9475
9718
|
ProcedureFamily,
|
|
9719
|
+
ProcedureService,
|
|
9476
9720
|
REGISTER_TOKENS_COLLECTION,
|
|
9477
9721
|
SYNCED_CALENDARS_COLLECTION,
|
|
9478
9722
|
SubscriptionModel,
|