@blackcode_sa/metaestetics-api 1.12.36 → 1.12.37
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/admin/index.d.mts +13 -1
- package/dist/admin/index.d.ts +13 -1
- package/dist/admin/index.js +45 -18
- package/dist/admin/index.mjs +45 -18
- package/dist/index.d.mts +106 -6
- package/dist/index.d.ts +106 -6
- package/dist/index.js +1989 -1615
- package/dist/index.mjs +1185 -811
- package/package.json +1 -1
- package/src/admin/aggregation/appointment/appointment.aggregation.service.ts +56 -25
- package/src/admin/booking/booking.admin.ts +1 -0
- package/src/services/appointment/appointment.service.ts +279 -45
- package/src/services/appointment/utils/recommended-procedure.utils.ts +193 -0
- package/src/services/appointment/utils/zone-management.utils.ts +27 -23
- package/src/services/appointment/utils/zone-photo.utils.ts +152 -0
- package/src/services/procedure/procedure.service.ts +42 -2
- package/src/types/appointment/index.ts +16 -2
- package/src/validations/appointment.schema.ts +24 -4
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/services/appointment/appointment.service.ts
|
|
2
2
|
import {
|
|
3
3
|
Timestamp as Timestamp3,
|
|
4
|
-
serverTimestamp as
|
|
4
|
+
serverTimestamp as serverTimestamp7,
|
|
5
5
|
arrayUnion,
|
|
6
6
|
arrayRemove,
|
|
7
7
|
where as where4,
|
|
@@ -450,6 +450,9 @@ var zoneItemDataSchema = z3.object({
|
|
|
450
450
|
type: z3.enum(["item", "note"], {
|
|
451
451
|
required_error: 'Type must be either "item" or "note"'
|
|
452
452
|
}),
|
|
453
|
+
stage: z3.enum(["before", "after"], {
|
|
454
|
+
required_error: 'Stage must be either "before" or "after"'
|
|
455
|
+
}).optional(),
|
|
453
456
|
price: z3.number().min(0, "Price must be non-negative").optional(),
|
|
454
457
|
currency: z3.nativeEnum(Currency).optional(),
|
|
455
458
|
unitOfMeasurement: z3.nativeEnum(PricingMeasure).optional(),
|
|
@@ -477,7 +480,9 @@ var zoneItemDataSchema = z3.object({
|
|
|
477
480
|
),
|
|
478
481
|
notes: z3.string().max(MAX_STRING_LENGTH_LONG, "Notes too long").optional(),
|
|
479
482
|
subtotal: z3.number().min(0, "Subtotal must be non-negative").optional(),
|
|
480
|
-
ionNumber: z3.string().optional()
|
|
483
|
+
ionNumber: z3.string().optional(),
|
|
484
|
+
createdAt: z3.string().optional(),
|
|
485
|
+
updatedAt: z3.string().optional()
|
|
481
486
|
}).refine(
|
|
482
487
|
(data) => {
|
|
483
488
|
if (data.type === "item") {
|
|
@@ -518,12 +523,22 @@ var extendedProcedureInfoSchema = z3.object({
|
|
|
518
523
|
})
|
|
519
524
|
)
|
|
520
525
|
});
|
|
526
|
+
var recommendedProcedureTimeframeSchema = z3.object({
|
|
527
|
+
value: z3.number().int().positive("Timeframe value must be a positive integer"),
|
|
528
|
+
unit: z3.enum(["day", "week", "month", "year"])
|
|
529
|
+
});
|
|
530
|
+
var recommendedProcedureSchema = z3.object({
|
|
531
|
+
procedure: extendedProcedureInfoSchema,
|
|
532
|
+
note: z3.string().min(1, "Note is required").max(MAX_STRING_LENGTH_LONG, "Note too long"),
|
|
533
|
+
timeframe: recommendedProcedureTimeframeSchema
|
|
534
|
+
});
|
|
521
535
|
var appointmentMetadataSchema = z3.object({
|
|
522
536
|
selectedZones: z3.array(z3.string()).nullable(),
|
|
523
|
-
zonePhotos: z3.record(z3.string(), beforeAfterPerZoneSchema).nullable(),
|
|
524
|
-
zonesData: z3.record(z3.string(), z3.array(zoneItemDataSchema)).nullable(),
|
|
525
|
-
appointmentProducts: z3.array(appointmentProductMetadataSchema),
|
|
526
|
-
extendedProcedures: z3.array(extendedProcedureInfoSchema),
|
|
537
|
+
zonePhotos: z3.record(z3.string(), z3.array(beforeAfterPerZoneSchema).max(10)).nullable(),
|
|
538
|
+
zonesData: z3.record(z3.string(), z3.array(zoneItemDataSchema)).nullable().optional(),
|
|
539
|
+
appointmentProducts: z3.array(appointmentProductMetadataSchema).optional().default([]),
|
|
540
|
+
extendedProcedures: z3.array(extendedProcedureInfoSchema).optional().default([]),
|
|
541
|
+
recommendedProcedures: z3.array(recommendedProcedureSchema).optional().default([]),
|
|
527
542
|
zoneBilling: z3.record(z3.string(), billingPerZoneSchema).nullable().optional(),
|
|
528
543
|
finalbilling: finalBillingSchema.nullable(),
|
|
529
544
|
finalizationNotes: z3.string().nullable()
|
|
@@ -963,7 +978,7 @@ var MediaService = class extends BaseService {
|
|
|
963
978
|
try {
|
|
964
979
|
const querySnapshot = await getDocs(finalQuery);
|
|
965
980
|
const mediaList = querySnapshot.docs.map(
|
|
966
|
-
(
|
|
981
|
+
(doc44) => doc44.data()
|
|
967
982
|
);
|
|
968
983
|
console.log(`[MediaService] Found ${mediaList.length} media items.`);
|
|
969
984
|
return mediaList;
|
|
@@ -1406,7 +1421,7 @@ async function searchAppointmentsUtil(db, params) {
|
|
|
1406
1421
|
}
|
|
1407
1422
|
const q = query2(collection2(db, APPOINTMENTS_COLLECTION), ...constraints);
|
|
1408
1423
|
const querySnapshot = await getDocs2(q);
|
|
1409
|
-
const appointments = querySnapshot.docs.map((
|
|
1424
|
+
const appointments = querySnapshot.docs.map((doc44) => doc44.data());
|
|
1410
1425
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
1411
1426
|
return { appointments, lastDoc };
|
|
1412
1427
|
} catch (error) {
|
|
@@ -1478,6 +1493,7 @@ function initializeMetadata(appointment) {
|
|
|
1478
1493
|
zonesData: null,
|
|
1479
1494
|
appointmentProducts: [],
|
|
1480
1495
|
extendedProcedures: [],
|
|
1496
|
+
recommendedProcedures: [],
|
|
1481
1497
|
finalbilling: null,
|
|
1482
1498
|
finalizationNotes: null
|
|
1483
1499
|
};
|
|
@@ -1490,11 +1506,14 @@ async function addItemToZoneUtil(db, appointmentId, zoneId, item) {
|
|
|
1490
1506
|
if (!zonesData[zoneId]) {
|
|
1491
1507
|
zonesData[zoneId] = [];
|
|
1492
1508
|
}
|
|
1509
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1493
1510
|
const itemWithSubtotal = {
|
|
1494
1511
|
...item,
|
|
1495
1512
|
parentZone: zoneId,
|
|
1496
1513
|
// Set parentZone to the zone key
|
|
1497
|
-
subtotal: calculateItemSubtotal(item)
|
|
1514
|
+
subtotal: calculateItemSubtotal(item),
|
|
1515
|
+
createdAt: now,
|
|
1516
|
+
updatedAt: now
|
|
1498
1517
|
};
|
|
1499
1518
|
zonesData[zoneId].push(itemWithSubtotal);
|
|
1500
1519
|
const finalbilling = calculateFinalBilling(zonesData);
|
|
@@ -1543,7 +1562,8 @@ async function updateZoneItemUtil(db, appointmentId, zoneId, itemIndex, updates)
|
|
|
1543
1562
|
}
|
|
1544
1563
|
items[itemIndex] = {
|
|
1545
1564
|
...items[itemIndex],
|
|
1546
|
-
...updates
|
|
1565
|
+
...updates,
|
|
1566
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1547
1567
|
};
|
|
1548
1568
|
items[itemIndex].subtotal = calculateItemSubtotal(items[itemIndex]);
|
|
1549
1569
|
const finalbilling = calculateFinalBilling(metadata.zonesData);
|
|
@@ -1872,6 +1892,154 @@ async function getAppointmentProductsUtil(db, appointmentId) {
|
|
|
1872
1892
|
return ((_a = appointment.metadata) == null ? void 0 : _a.appointmentProducts) || [];
|
|
1873
1893
|
}
|
|
1874
1894
|
|
|
1895
|
+
// src/services/appointment/utils/recommended-procedure.utils.ts
|
|
1896
|
+
import { updateDoc as updateDoc5, serverTimestamp as serverTimestamp5, doc as doc6 } from "firebase/firestore";
|
|
1897
|
+
import { getDoc as getDoc6 } from "firebase/firestore";
|
|
1898
|
+
async function createExtendedProcedureInfoForRecommended(db, procedureId) {
|
|
1899
|
+
const procedureRef = doc6(db, PROCEDURES_COLLECTION, procedureId);
|
|
1900
|
+
const procedureSnap = await getDoc6(procedureRef);
|
|
1901
|
+
if (!procedureSnap.exists()) {
|
|
1902
|
+
throw new Error(`Procedure with ID ${procedureId} not found`);
|
|
1903
|
+
}
|
|
1904
|
+
const data = procedureSnap.data();
|
|
1905
|
+
return {
|
|
1906
|
+
procedureId,
|
|
1907
|
+
procedureName: data.name,
|
|
1908
|
+
procedureFamily: data.family,
|
|
1909
|
+
procedureCategoryId: data.category.id,
|
|
1910
|
+
procedureCategoryName: data.category.name,
|
|
1911
|
+
procedureSubCategoryId: data.subcategory.id,
|
|
1912
|
+
procedureSubCategoryName: data.subcategory.name,
|
|
1913
|
+
procedureTechnologyId: data.technology.id,
|
|
1914
|
+
procedureTechnologyName: data.technology.name,
|
|
1915
|
+
procedureProducts: (data.productsMetadata || []).map((pp) => ({
|
|
1916
|
+
productId: pp.product.id,
|
|
1917
|
+
productName: pp.product.name,
|
|
1918
|
+
brandId: pp.product.brandId,
|
|
1919
|
+
brandName: pp.product.brandName
|
|
1920
|
+
}))
|
|
1921
|
+
};
|
|
1922
|
+
}
|
|
1923
|
+
async function addRecommendedProcedureUtil(db, appointmentId, procedureId, note, timeframe) {
|
|
1924
|
+
const appointment = await getAppointmentOrThrow(db, appointmentId);
|
|
1925
|
+
const metadata = initializeMetadata(appointment);
|
|
1926
|
+
const procedureInfo = await createExtendedProcedureInfoForRecommended(db, procedureId);
|
|
1927
|
+
const recommendedProcedure = {
|
|
1928
|
+
procedure: procedureInfo,
|
|
1929
|
+
note,
|
|
1930
|
+
timeframe
|
|
1931
|
+
};
|
|
1932
|
+
const recommendedProcedures = [...metadata.recommendedProcedures || [], recommendedProcedure];
|
|
1933
|
+
const appointmentRef = doc6(db, APPOINTMENTS_COLLECTION, appointmentId);
|
|
1934
|
+
await updateDoc5(appointmentRef, {
|
|
1935
|
+
"metadata.recommendedProcedures": recommendedProcedures,
|
|
1936
|
+
updatedAt: serverTimestamp5()
|
|
1937
|
+
});
|
|
1938
|
+
return getAppointmentOrThrow(db, appointmentId);
|
|
1939
|
+
}
|
|
1940
|
+
async function removeRecommendedProcedureUtil(db, appointmentId, recommendationIndex) {
|
|
1941
|
+
const appointment = await getAppointmentOrThrow(db, appointmentId);
|
|
1942
|
+
const metadata = initializeMetadata(appointment);
|
|
1943
|
+
if (!metadata.recommendedProcedures || metadata.recommendedProcedures.length === 0) {
|
|
1944
|
+
throw new Error("No recommended procedures found for this appointment");
|
|
1945
|
+
}
|
|
1946
|
+
if (recommendationIndex < 0 || recommendationIndex >= metadata.recommendedProcedures.length) {
|
|
1947
|
+
throw new Error(`Invalid recommendation index ${recommendationIndex}. Must be between 0 and ${metadata.recommendedProcedures.length - 1}`);
|
|
1948
|
+
}
|
|
1949
|
+
const updatedRecommendedProcedures = [...metadata.recommendedProcedures];
|
|
1950
|
+
updatedRecommendedProcedures.splice(recommendationIndex, 1);
|
|
1951
|
+
const appointmentRef = doc6(db, APPOINTMENTS_COLLECTION, appointmentId);
|
|
1952
|
+
await updateDoc5(appointmentRef, {
|
|
1953
|
+
"metadata.recommendedProcedures": updatedRecommendedProcedures,
|
|
1954
|
+
updatedAt: serverTimestamp5()
|
|
1955
|
+
});
|
|
1956
|
+
return getAppointmentOrThrow(db, appointmentId);
|
|
1957
|
+
}
|
|
1958
|
+
async function updateRecommendedProcedureUtil(db, appointmentId, recommendationIndex, updates) {
|
|
1959
|
+
const appointment = await getAppointmentOrThrow(db, appointmentId);
|
|
1960
|
+
const metadata = initializeMetadata(appointment);
|
|
1961
|
+
if (!metadata.recommendedProcedures || metadata.recommendedProcedures.length === 0) {
|
|
1962
|
+
throw new Error("No recommended procedures found for this appointment");
|
|
1963
|
+
}
|
|
1964
|
+
if (recommendationIndex < 0 || recommendationIndex >= metadata.recommendedProcedures.length) {
|
|
1965
|
+
throw new Error(`Invalid recommendation index ${recommendationIndex}. Must be between 0 and ${metadata.recommendedProcedures.length - 1}`);
|
|
1966
|
+
}
|
|
1967
|
+
const updatedRecommendedProcedures = [...metadata.recommendedProcedures];
|
|
1968
|
+
const existingRecommendation = updatedRecommendedProcedures[recommendationIndex];
|
|
1969
|
+
updatedRecommendedProcedures[recommendationIndex] = {
|
|
1970
|
+
...existingRecommendation,
|
|
1971
|
+
...updates.note !== void 0 && { note: updates.note },
|
|
1972
|
+
...updates.timeframe !== void 0 && { timeframe: updates.timeframe }
|
|
1973
|
+
};
|
|
1974
|
+
const appointmentRef = doc6(db, APPOINTMENTS_COLLECTION, appointmentId);
|
|
1975
|
+
await updateDoc5(appointmentRef, {
|
|
1976
|
+
"metadata.recommendedProcedures": updatedRecommendedProcedures,
|
|
1977
|
+
updatedAt: serverTimestamp5()
|
|
1978
|
+
});
|
|
1979
|
+
return getAppointmentOrThrow(db, appointmentId);
|
|
1980
|
+
}
|
|
1981
|
+
async function getRecommendedProceduresUtil(db, appointmentId) {
|
|
1982
|
+
var _a;
|
|
1983
|
+
const appointment = await getAppointmentOrThrow(db, appointmentId);
|
|
1984
|
+
return ((_a = appointment.metadata) == null ? void 0 : _a.recommendedProcedures) || [];
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1987
|
+
// src/services/appointment/utils/zone-photo.utils.ts
|
|
1988
|
+
import { updateDoc as updateDoc6, serverTimestamp as serverTimestamp6, doc as doc7 } from "firebase/firestore";
|
|
1989
|
+
async function updateZonePhotoEntryUtil(db, appointmentId, zoneId, photoIndex, updates) {
|
|
1990
|
+
var _a;
|
|
1991
|
+
const appointment = await getAppointmentOrThrow(db, appointmentId);
|
|
1992
|
+
const zonePhotos = (_a = appointment.metadata) == null ? void 0 : _a.zonePhotos;
|
|
1993
|
+
if (!zonePhotos || !zonePhotos[zoneId] || !Array.isArray(zonePhotos[zoneId])) {
|
|
1994
|
+
throw new Error(`No photos found for zone ${zoneId} in appointment ${appointmentId}`);
|
|
1995
|
+
}
|
|
1996
|
+
const zoneArray = zonePhotos[zoneId];
|
|
1997
|
+
if (photoIndex < 0 || photoIndex >= zoneArray.length) {
|
|
1998
|
+
throw new Error(`Invalid photo index ${photoIndex} for zone ${zoneId}. Must be between 0 and ${zoneArray.length - 1}`);
|
|
1999
|
+
}
|
|
2000
|
+
const updatedZonePhotos = { ...zonePhotos };
|
|
2001
|
+
updatedZonePhotos[zoneId] = [...zoneArray];
|
|
2002
|
+
updatedZonePhotos[zoneId][photoIndex] = {
|
|
2003
|
+
...zoneArray[photoIndex],
|
|
2004
|
+
...updates
|
|
2005
|
+
};
|
|
2006
|
+
const appointmentRef = doc7(db, APPOINTMENTS_COLLECTION, appointmentId);
|
|
2007
|
+
await updateDoc6(appointmentRef, {
|
|
2008
|
+
"metadata.zonePhotos": updatedZonePhotos,
|
|
2009
|
+
updatedAt: serverTimestamp6()
|
|
2010
|
+
});
|
|
2011
|
+
return getAppointmentOrThrow(db, appointmentId);
|
|
2012
|
+
}
|
|
2013
|
+
async function addAfterPhotoToEntryUtil(db, appointmentId, zoneId, photoIndex, afterPhotoUrl, afterNote) {
|
|
2014
|
+
return updateZonePhotoEntryUtil(db, appointmentId, zoneId, photoIndex, {
|
|
2015
|
+
after: afterPhotoUrl,
|
|
2016
|
+
afterNote: afterNote || null
|
|
2017
|
+
});
|
|
2018
|
+
}
|
|
2019
|
+
async function updateZonePhotoNotesUtil(db, appointmentId, zoneId, photoIndex, beforeNote, afterNote) {
|
|
2020
|
+
const updates = {};
|
|
2021
|
+
if (beforeNote !== void 0) {
|
|
2022
|
+
updates.beforeNote = beforeNote || null;
|
|
2023
|
+
}
|
|
2024
|
+
if (afterNote !== void 0) {
|
|
2025
|
+
updates.afterNote = afterNote || null;
|
|
2026
|
+
}
|
|
2027
|
+
return updateZonePhotoEntryUtil(db, appointmentId, zoneId, photoIndex, updates);
|
|
2028
|
+
}
|
|
2029
|
+
async function getZonePhotoEntryUtil(db, appointmentId, zoneId, photoIndex) {
|
|
2030
|
+
var _a;
|
|
2031
|
+
const appointment = await getAppointmentOrThrow(db, appointmentId);
|
|
2032
|
+
const zonePhotos = (_a = appointment.metadata) == null ? void 0 : _a.zonePhotos;
|
|
2033
|
+
if (!zonePhotos || !zonePhotos[zoneId] || !Array.isArray(zonePhotos[zoneId])) {
|
|
2034
|
+
throw new Error(`No photos found for zone ${zoneId} in appointment ${appointmentId}`);
|
|
2035
|
+
}
|
|
2036
|
+
const zoneArray = zonePhotos[zoneId];
|
|
2037
|
+
if (photoIndex < 0 || photoIndex >= zoneArray.length) {
|
|
2038
|
+
throw new Error(`Invalid photo index ${photoIndex} for zone ${zoneId}`);
|
|
2039
|
+
}
|
|
2040
|
+
return zoneArray[photoIndex];
|
|
2041
|
+
}
|
|
2042
|
+
|
|
1875
2043
|
// src/services/appointment/appointment.service.ts
|
|
1876
2044
|
var AppointmentService = class extends BaseService {
|
|
1877
2045
|
/**
|
|
@@ -2169,7 +2337,7 @@ var AppointmentService = class extends BaseService {
|
|
|
2169
2337
|
);
|
|
2170
2338
|
const updateData = {
|
|
2171
2339
|
status: newStatus,
|
|
2172
|
-
updatedAt:
|
|
2340
|
+
updatedAt: serverTimestamp7()
|
|
2173
2341
|
};
|
|
2174
2342
|
if (newStatus === "canceled_clinic" /* CANCELED_CLINIC */ || newStatus === "canceled_patient" /* CANCELED_PATIENT */ || newStatus === "canceled_patient_rescheduled" /* CANCELED_PATIENT_RESCHEDULED */) {
|
|
2175
2343
|
if (!(details == null ? void 0 : details.cancellationReason)) {
|
|
@@ -2240,7 +2408,7 @@ var AppointmentService = class extends BaseService {
|
|
|
2240
2408
|
appointmentEndTime: endTimestamp,
|
|
2241
2409
|
rescheduleTime: Timestamp3.now(),
|
|
2242
2410
|
confirmationTime: null,
|
|
2243
|
-
updatedAt:
|
|
2411
|
+
updatedAt: serverTimestamp7()
|
|
2244
2412
|
};
|
|
2245
2413
|
return this.updateAppointment(validatedParams.appointmentId, updateData);
|
|
2246
2414
|
}
|
|
@@ -2341,7 +2509,7 @@ var AppointmentService = class extends BaseService {
|
|
|
2341
2509
|
status: "in_progress" /* IN_PROGRESS */,
|
|
2342
2510
|
procedureActualStartTime: Timestamp3.now(),
|
|
2343
2511
|
// Set actual start time
|
|
2344
|
-
updatedAt:
|
|
2512
|
+
updatedAt: serverTimestamp7()
|
|
2345
2513
|
};
|
|
2346
2514
|
return this.updateAppointment(appointmentId, updateData);
|
|
2347
2515
|
}
|
|
@@ -2376,7 +2544,7 @@ var AppointmentService = class extends BaseService {
|
|
|
2376
2544
|
},
|
|
2377
2545
|
// Optionally update appointmentEndTime to the actual completion time
|
|
2378
2546
|
// appointmentEndTime: procedureCompletionTime,
|
|
2379
|
-
updatedAt:
|
|
2547
|
+
updatedAt: serverTimestamp7()
|
|
2380
2548
|
};
|
|
2381
2549
|
return this.updateAppointment(appointmentId, updateData);
|
|
2382
2550
|
}
|
|
@@ -2410,7 +2578,7 @@ var AppointmentService = class extends BaseService {
|
|
|
2410
2578
|
};
|
|
2411
2579
|
const updateData = {
|
|
2412
2580
|
media: arrayUnion(newMediaItem),
|
|
2413
|
-
updatedAt:
|
|
2581
|
+
updatedAt: serverTimestamp7()
|
|
2414
2582
|
};
|
|
2415
2583
|
return this.updateAppointment(appointmentId, updateData);
|
|
2416
2584
|
}
|
|
@@ -2431,7 +2599,7 @@ var AppointmentService = class extends BaseService {
|
|
|
2431
2599
|
}
|
|
2432
2600
|
const updateData = {
|
|
2433
2601
|
media: arrayRemove(mediaToRemove),
|
|
2434
|
-
updatedAt:
|
|
2602
|
+
updatedAt: serverTimestamp7()
|
|
2435
2603
|
};
|
|
2436
2604
|
return this.updateAppointment(appointmentId, updateData);
|
|
2437
2605
|
}
|
|
@@ -2447,7 +2615,7 @@ var AppointmentService = class extends BaseService {
|
|
|
2447
2615
|
};
|
|
2448
2616
|
const updateData = {
|
|
2449
2617
|
reviewInfo: newReviewInfo,
|
|
2450
|
-
updatedAt:
|
|
2618
|
+
updatedAt: serverTimestamp7()
|
|
2451
2619
|
};
|
|
2452
2620
|
return this.updateAppointment(appointmentId, updateData);
|
|
2453
2621
|
}
|
|
@@ -2461,7 +2629,7 @@ var AppointmentService = class extends BaseService {
|
|
|
2461
2629
|
const updateData = {
|
|
2462
2630
|
paymentStatus,
|
|
2463
2631
|
paymentTransactionId: paymentTransactionId || null,
|
|
2464
|
-
updatedAt:
|
|
2632
|
+
updatedAt: serverTimestamp7()
|
|
2465
2633
|
};
|
|
2466
2634
|
return this.updateAppointment(appointmentId, updateData);
|
|
2467
2635
|
}
|
|
@@ -2514,7 +2682,7 @@ var AppointmentService = class extends BaseService {
|
|
|
2514
2682
|
}
|
|
2515
2683
|
const q = query4(collection4(this.db, APPOINTMENTS_COLLECTION), ...constraints);
|
|
2516
2684
|
const querySnapshot = await getDocs4(q);
|
|
2517
|
-
const appointments = querySnapshot.docs.map((
|
|
2685
|
+
const appointments = querySnapshot.docs.map((doc44) => doc44.data());
|
|
2518
2686
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
2519
2687
|
console.log(
|
|
2520
2688
|
`[APPOINTMENT_SERVICE] Found ${appointments.length} upcoming appointments for patient ${patientId}`
|
|
@@ -2570,7 +2738,7 @@ var AppointmentService = class extends BaseService {
|
|
|
2570
2738
|
}
|
|
2571
2739
|
const q = query4(collection4(this.db, APPOINTMENTS_COLLECTION), ...constraints);
|
|
2572
2740
|
const querySnapshot = await getDocs4(q);
|
|
2573
|
-
const appointments = querySnapshot.docs.map((
|
|
2741
|
+
const appointments = querySnapshot.docs.map((doc44) => doc44.data());
|
|
2574
2742
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
2575
2743
|
console.log(
|
|
2576
2744
|
`[APPOINTMENT_SERVICE] Found ${appointments.length} past appointments for patient ${patientId}`
|
|
@@ -2703,29 +2871,24 @@ var AppointmentService = class extends BaseService {
|
|
|
2703
2871
|
zonesData: null,
|
|
2704
2872
|
appointmentProducts: [],
|
|
2705
2873
|
extendedProcedures: [],
|
|
2874
|
+
recommendedProcedures: [],
|
|
2706
2875
|
zoneBilling: null,
|
|
2707
2876
|
finalbilling: null,
|
|
2708
2877
|
finalizationNotes: null
|
|
2709
2878
|
};
|
|
2710
2879
|
const currentZonePhotos = currentMetadata.zonePhotos || {};
|
|
2711
2880
|
if (!currentZonePhotos[zoneId]) {
|
|
2712
|
-
currentZonePhotos[zoneId] =
|
|
2713
|
-
before: null,
|
|
2714
|
-
after: null,
|
|
2715
|
-
beforeNote: null,
|
|
2716
|
-
afterNote: null
|
|
2717
|
-
};
|
|
2881
|
+
currentZonePhotos[zoneId] = [];
|
|
2718
2882
|
}
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
}
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
}
|
|
2883
|
+
const newEntry = {
|
|
2884
|
+
before: photoType === "before" ? mediaMetadata.url : null,
|
|
2885
|
+
after: photoType === "after" ? mediaMetadata.url : null,
|
|
2886
|
+
beforeNote: photoType === "before" ? notes || null : null,
|
|
2887
|
+
afterNote: photoType === "after" ? notes || null : null
|
|
2888
|
+
};
|
|
2889
|
+
currentZonePhotos[zoneId] = [...currentZonePhotos[zoneId], newEntry];
|
|
2890
|
+
if (currentZonePhotos[zoneId].length > 10) {
|
|
2891
|
+
currentZonePhotos[zoneId] = currentZonePhotos[zoneId].slice(-10);
|
|
2729
2892
|
}
|
|
2730
2893
|
const updateData = {
|
|
2731
2894
|
metadata: {
|
|
@@ -2734,6 +2897,7 @@ var AppointmentService = class extends BaseService {
|
|
|
2734
2897
|
zonesData: currentMetadata.zonesData || null,
|
|
2735
2898
|
appointmentProducts: currentMetadata.appointmentProducts || [],
|
|
2736
2899
|
extendedProcedures: currentMetadata.extendedProcedures || [],
|
|
2900
|
+
recommendedProcedures: currentMetadata.recommendedProcedures || [],
|
|
2737
2901
|
// Only include zoneBilling if it exists (avoid undefined values in Firestore)
|
|
2738
2902
|
...currentMetadata.zoneBilling !== void 0 && {
|
|
2739
2903
|
zoneBilling: currentMetadata.zoneBilling
|
|
@@ -2741,7 +2905,7 @@ var AppointmentService = class extends BaseService {
|
|
|
2741
2905
|
finalbilling: currentMetadata.finalbilling,
|
|
2742
2906
|
finalizationNotes: currentMetadata.finalizationNotes
|
|
2743
2907
|
},
|
|
2744
|
-
updatedAt:
|
|
2908
|
+
updatedAt: serverTimestamp7()
|
|
2745
2909
|
};
|
|
2746
2910
|
const updatedAppointment = await this.updateAppointment(appointmentId, updateData);
|
|
2747
2911
|
console.log(
|
|
@@ -2785,30 +2949,35 @@ var AppointmentService = class extends BaseService {
|
|
|
2785
2949
|
}
|
|
2786
2950
|
}
|
|
2787
2951
|
/**
|
|
2788
|
-
* Deletes a zone photo and updates appointment metadata
|
|
2952
|
+
* Deletes a zone photo entry (by index) and updates appointment metadata
|
|
2789
2953
|
*
|
|
2790
2954
|
* @param appointmentId ID of the appointment
|
|
2791
2955
|
* @param zoneId ID of the zone
|
|
2792
|
-
* @param
|
|
2956
|
+
* @param photoIndex Index of the photo entry to delete in the zone array
|
|
2793
2957
|
* @returns The updated appointment
|
|
2794
2958
|
*/
|
|
2795
|
-
async deleteZonePhoto(appointmentId, zoneId,
|
|
2796
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2959
|
+
async deleteZonePhoto(appointmentId, zoneId, photoIndex) {
|
|
2960
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2797
2961
|
try {
|
|
2798
2962
|
console.log(
|
|
2799
|
-
`[APPOINTMENT_SERVICE] Deleting ${
|
|
2963
|
+
`[APPOINTMENT_SERVICE] Deleting zone photo index ${photoIndex} for zone ${zoneId} in appointment ${appointmentId}`
|
|
2800
2964
|
);
|
|
2801
2965
|
const appointment = await this.getAppointmentById(appointmentId);
|
|
2802
2966
|
if (!appointment) {
|
|
2803
2967
|
throw new Error(`Appointment with ID ${appointmentId} not found`);
|
|
2804
2968
|
}
|
|
2805
2969
|
const zonePhotos = (_a = appointment.metadata) == null ? void 0 : _a.zonePhotos;
|
|
2806
|
-
if (!zonePhotos || !zonePhotos[zoneId]) {
|
|
2970
|
+
if (!zonePhotos || !zonePhotos[zoneId] || !Array.isArray(zonePhotos[zoneId])) {
|
|
2807
2971
|
throw new Error(`No photos found for zone ${zoneId} in appointment ${appointmentId}`);
|
|
2808
2972
|
}
|
|
2809
|
-
const
|
|
2973
|
+
const zoneArray = [...zonePhotos[zoneId]];
|
|
2974
|
+
if (photoIndex < 0 || photoIndex >= zoneArray.length) {
|
|
2975
|
+
throw new Error(`Invalid photo index ${photoIndex} for zone ${zoneId}`);
|
|
2976
|
+
}
|
|
2977
|
+
const entry = zoneArray[photoIndex];
|
|
2978
|
+
const photoUrl = entry.before || entry.after;
|
|
2810
2979
|
if (!photoUrl) {
|
|
2811
|
-
throw new Error(`No
|
|
2980
|
+
throw new Error(`No photo URL found for index ${photoIndex} in zone ${zoneId}`);
|
|
2812
2981
|
}
|
|
2813
2982
|
try {
|
|
2814
2983
|
if (typeof photoUrl === "string") {
|
|
@@ -2825,15 +2994,12 @@ var AppointmentService = class extends BaseService {
|
|
|
2825
2994
|
);
|
|
2826
2995
|
}
|
|
2827
2996
|
const updatedZonePhotos = { ...zonePhotos };
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
} else {
|
|
2832
|
-
updatedZonePhotos[zoneId].after = null;
|
|
2833
|
-
updatedZonePhotos[zoneId].afterNote = null;
|
|
2834
|
-
}
|
|
2835
|
-
if (!updatedZonePhotos[zoneId].before && !updatedZonePhotos[zoneId].after) {
|
|
2997
|
+
const updatedZoneArray = [...zoneArray];
|
|
2998
|
+
updatedZoneArray.splice(photoIndex, 1);
|
|
2999
|
+
if (updatedZoneArray.length === 0) {
|
|
2836
3000
|
delete updatedZonePhotos[zoneId];
|
|
3001
|
+
} else {
|
|
3002
|
+
updatedZonePhotos[zoneId] = updatedZoneArray;
|
|
2837
3003
|
}
|
|
2838
3004
|
const updateData = {
|
|
2839
3005
|
metadata: {
|
|
@@ -2842,18 +3008,19 @@ var AppointmentService = class extends BaseService {
|
|
|
2842
3008
|
zonesData: ((_c = appointment.metadata) == null ? void 0 : _c.zonesData) || null,
|
|
2843
3009
|
appointmentProducts: ((_d = appointment.metadata) == null ? void 0 : _d.appointmentProducts) || [],
|
|
2844
3010
|
extendedProcedures: ((_e = appointment.metadata) == null ? void 0 : _e.extendedProcedures) || [],
|
|
3011
|
+
recommendedProcedures: ((_f = appointment.metadata) == null ? void 0 : _f.recommendedProcedures) || [],
|
|
2845
3012
|
// Only include zoneBilling if it exists (avoid undefined values in Firestore)
|
|
2846
|
-
...((
|
|
3013
|
+
...((_g = appointment.metadata) == null ? void 0 : _g.zoneBilling) !== void 0 && {
|
|
2847
3014
|
zoneBilling: appointment.metadata.zoneBilling
|
|
2848
3015
|
},
|
|
2849
|
-
finalbilling: ((
|
|
2850
|
-
finalizationNotes: ((
|
|
3016
|
+
finalbilling: ((_h = appointment.metadata) == null ? void 0 : _h.finalbilling) || null,
|
|
3017
|
+
finalizationNotes: ((_i = appointment.metadata) == null ? void 0 : _i.finalizationNotes) || null
|
|
2851
3018
|
},
|
|
2852
|
-
updatedAt:
|
|
3019
|
+
updatedAt: serverTimestamp7()
|
|
2853
3020
|
};
|
|
2854
3021
|
const updatedAppointment = await this.updateAppointment(appointmentId, updateData);
|
|
2855
3022
|
console.log(
|
|
2856
|
-
`[APPOINTMENT_SERVICE] Successfully deleted ${
|
|
3023
|
+
`[APPOINTMENT_SERVICE] Successfully deleted photo index ${photoIndex} for zone ${zoneId}`
|
|
2857
3024
|
);
|
|
2858
3025
|
return updatedAppointment;
|
|
2859
3026
|
} catch (error) {
|
|
@@ -3066,6 +3233,7 @@ var AppointmentService = class extends BaseService {
|
|
|
3066
3233
|
zonesData: null,
|
|
3067
3234
|
appointmentProducts: [],
|
|
3068
3235
|
extendedProcedures: [],
|
|
3236
|
+
recommendedProcedures: [],
|
|
3069
3237
|
finalbilling: null,
|
|
3070
3238
|
finalizationNotes: null
|
|
3071
3239
|
};
|
|
@@ -3076,6 +3244,7 @@ var AppointmentService = class extends BaseService {
|
|
|
3076
3244
|
zonesData: currentMetadata.zonesData,
|
|
3077
3245
|
appointmentProducts: currentMetadata.appointmentProducts || [],
|
|
3078
3246
|
extendedProcedures: currentMetadata.extendedProcedures || [],
|
|
3247
|
+
recommendedProcedures: currentMetadata.recommendedProcedures || [],
|
|
3079
3248
|
// Only include zoneBilling if it exists (avoid undefined values in Firestore)
|
|
3080
3249
|
...currentMetadata.zoneBilling !== void 0 && {
|
|
3081
3250
|
zoneBilling: currentMetadata.zoneBilling
|
|
@@ -3083,7 +3252,7 @@ var AppointmentService = class extends BaseService {
|
|
|
3083
3252
|
finalbilling,
|
|
3084
3253
|
finalizationNotes: currentMetadata.finalizationNotes
|
|
3085
3254
|
},
|
|
3086
|
-
updatedAt:
|
|
3255
|
+
updatedAt: serverTimestamp7()
|
|
3087
3256
|
};
|
|
3088
3257
|
return await this.updateAppointment(appointmentId, updateData);
|
|
3089
3258
|
} catch (error) {
|
|
@@ -3091,6 +3260,177 @@ var AppointmentService = class extends BaseService {
|
|
|
3091
3260
|
throw error;
|
|
3092
3261
|
}
|
|
3093
3262
|
}
|
|
3263
|
+
/**
|
|
3264
|
+
* Adds a recommended procedure to an appointment
|
|
3265
|
+
* Multiple recommendations of the same procedure are allowed (e.g., touch-up in 2 weeks, full treatment in 3 months)
|
|
3266
|
+
*
|
|
3267
|
+
* @param appointmentId ID of the appointment
|
|
3268
|
+
* @param procedureId ID of the procedure to recommend
|
|
3269
|
+
* @param note Note explaining the recommendation
|
|
3270
|
+
* @param timeframe Suggested timeframe for the procedure
|
|
3271
|
+
* @returns The updated appointment
|
|
3272
|
+
*/
|
|
3273
|
+
async addRecommendedProcedure(appointmentId, procedureId, note, timeframe) {
|
|
3274
|
+
try {
|
|
3275
|
+
console.log(
|
|
3276
|
+
`[APPOINTMENT_SERVICE] Adding recommended procedure ${procedureId} to appointment ${appointmentId}`
|
|
3277
|
+
);
|
|
3278
|
+
return await addRecommendedProcedureUtil(this.db, appointmentId, procedureId, note, timeframe);
|
|
3279
|
+
} catch (error) {
|
|
3280
|
+
console.error(`[APPOINTMENT_SERVICE] Error adding recommended procedure:`, error);
|
|
3281
|
+
throw error;
|
|
3282
|
+
}
|
|
3283
|
+
}
|
|
3284
|
+
/**
|
|
3285
|
+
* Removes a recommended procedure from an appointment by index
|
|
3286
|
+
*
|
|
3287
|
+
* @param appointmentId ID of the appointment
|
|
3288
|
+
* @param recommendationIndex Index of the recommendation to remove
|
|
3289
|
+
* @returns The updated appointment
|
|
3290
|
+
*/
|
|
3291
|
+
async removeRecommendedProcedure(appointmentId, recommendationIndex) {
|
|
3292
|
+
try {
|
|
3293
|
+
console.log(
|
|
3294
|
+
`[APPOINTMENT_SERVICE] Removing recommended procedure at index ${recommendationIndex} from appointment ${appointmentId}`
|
|
3295
|
+
);
|
|
3296
|
+
return await removeRecommendedProcedureUtil(this.db, appointmentId, recommendationIndex);
|
|
3297
|
+
} catch (error) {
|
|
3298
|
+
console.error(`[APPOINTMENT_SERVICE] Error removing recommended procedure:`, error);
|
|
3299
|
+
throw error;
|
|
3300
|
+
}
|
|
3301
|
+
}
|
|
3302
|
+
/**
|
|
3303
|
+
* Updates a recommended procedure in an appointment by index
|
|
3304
|
+
*
|
|
3305
|
+
* @param appointmentId ID of the appointment
|
|
3306
|
+
* @param recommendationIndex Index of the recommendation to update
|
|
3307
|
+
* @param updates Partial updates (note and/or timeframe)
|
|
3308
|
+
* @returns The updated appointment
|
|
3309
|
+
*/
|
|
3310
|
+
async updateRecommendedProcedure(appointmentId, recommendationIndex, updates) {
|
|
3311
|
+
try {
|
|
3312
|
+
console.log(
|
|
3313
|
+
`[APPOINTMENT_SERVICE] Updating recommended procedure at index ${recommendationIndex} in appointment ${appointmentId}`
|
|
3314
|
+
);
|
|
3315
|
+
return await updateRecommendedProcedureUtil(this.db, appointmentId, recommendationIndex, updates);
|
|
3316
|
+
} catch (error) {
|
|
3317
|
+
console.error(`[APPOINTMENT_SERVICE] Error updating recommended procedure:`, error);
|
|
3318
|
+
throw error;
|
|
3319
|
+
}
|
|
3320
|
+
}
|
|
3321
|
+
/**
|
|
3322
|
+
* Gets all recommended procedures for an appointment
|
|
3323
|
+
*
|
|
3324
|
+
* @param appointmentId ID of the appointment
|
|
3325
|
+
* @returns Array of recommended procedures
|
|
3326
|
+
*/
|
|
3327
|
+
async getRecommendedProcedures(appointmentId) {
|
|
3328
|
+
try {
|
|
3329
|
+
console.log(
|
|
3330
|
+
`[APPOINTMENT_SERVICE] Getting recommended procedures for appointment ${appointmentId}`
|
|
3331
|
+
);
|
|
3332
|
+
return await getRecommendedProceduresUtil(this.db, appointmentId);
|
|
3333
|
+
} catch (error) {
|
|
3334
|
+
console.error(`[APPOINTMENT_SERVICE] Error getting recommended procedures:`, error);
|
|
3335
|
+
throw error;
|
|
3336
|
+
}
|
|
3337
|
+
}
|
|
3338
|
+
/**
|
|
3339
|
+
* Updates a specific photo entry in a zone by index
|
|
3340
|
+
* Can update before/after photos and their notes
|
|
3341
|
+
*
|
|
3342
|
+
* @param appointmentId ID of the appointment
|
|
3343
|
+
* @param zoneId Zone ID
|
|
3344
|
+
* @param photoIndex Index of the photo entry to update
|
|
3345
|
+
* @param updates Partial updates to apply (before, after, beforeNote, afterNote)
|
|
3346
|
+
* @returns The updated appointment
|
|
3347
|
+
*/
|
|
3348
|
+
async updateZonePhotoEntry(appointmentId, zoneId, photoIndex, updates) {
|
|
3349
|
+
try {
|
|
3350
|
+
console.log(
|
|
3351
|
+
`[APPOINTMENT_SERVICE] Updating photo entry at index ${photoIndex} for zone ${zoneId} in appointment ${appointmentId}`
|
|
3352
|
+
);
|
|
3353
|
+
return await updateZonePhotoEntryUtil(this.db, appointmentId, zoneId, photoIndex, updates);
|
|
3354
|
+
} catch (error) {
|
|
3355
|
+
console.error(`[APPOINTMENT_SERVICE] Error updating zone photo entry:`, error);
|
|
3356
|
+
throw error;
|
|
3357
|
+
}
|
|
3358
|
+
}
|
|
3359
|
+
/**
|
|
3360
|
+
* Adds an after photo to an existing before photo entry
|
|
3361
|
+
*
|
|
3362
|
+
* @param appointmentId ID of the appointment
|
|
3363
|
+
* @param zoneId Zone ID
|
|
3364
|
+
* @param photoIndex Index of the entry to add after photo to
|
|
3365
|
+
* @param afterPhotoUrl URL of the after photo
|
|
3366
|
+
* @param afterNote Optional note for the after photo
|
|
3367
|
+
* @returns The updated appointment
|
|
3368
|
+
*/
|
|
3369
|
+
async addAfterPhotoToEntry(appointmentId, zoneId, photoIndex, afterPhotoUrl, afterNote) {
|
|
3370
|
+
try {
|
|
3371
|
+
console.log(
|
|
3372
|
+
`[APPOINTMENT_SERVICE] Adding after photo to entry at index ${photoIndex} for zone ${zoneId}`
|
|
3373
|
+
);
|
|
3374
|
+
return await addAfterPhotoToEntryUtil(
|
|
3375
|
+
this.db,
|
|
3376
|
+
appointmentId,
|
|
3377
|
+
zoneId,
|
|
3378
|
+
photoIndex,
|
|
3379
|
+
afterPhotoUrl,
|
|
3380
|
+
afterNote
|
|
3381
|
+
);
|
|
3382
|
+
} catch (error) {
|
|
3383
|
+
console.error(`[APPOINTMENT_SERVICE] Error adding after photo to entry:`, error);
|
|
3384
|
+
throw error;
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
3387
|
+
/**
|
|
3388
|
+
* Updates notes for a photo entry
|
|
3389
|
+
*
|
|
3390
|
+
* @param appointmentId ID of the appointment
|
|
3391
|
+
* @param zoneId Zone ID
|
|
3392
|
+
* @param photoIndex Index of the entry
|
|
3393
|
+
* @param beforeNote Optional note for before photo
|
|
3394
|
+
* @param afterNote Optional note for after photo
|
|
3395
|
+
* @returns The updated appointment
|
|
3396
|
+
*/
|
|
3397
|
+
async updateZonePhotoNotes(appointmentId, zoneId, photoIndex, beforeNote, afterNote) {
|
|
3398
|
+
try {
|
|
3399
|
+
console.log(
|
|
3400
|
+
`[APPOINTMENT_SERVICE] Updating notes for photo entry at index ${photoIndex} for zone ${zoneId}`
|
|
3401
|
+
);
|
|
3402
|
+
return await updateZonePhotoNotesUtil(
|
|
3403
|
+
this.db,
|
|
3404
|
+
appointmentId,
|
|
3405
|
+
zoneId,
|
|
3406
|
+
photoIndex,
|
|
3407
|
+
beforeNote,
|
|
3408
|
+
afterNote
|
|
3409
|
+
);
|
|
3410
|
+
} catch (error) {
|
|
3411
|
+
console.error(`[APPOINTMENT_SERVICE] Error updating zone photo notes:`, error);
|
|
3412
|
+
throw error;
|
|
3413
|
+
}
|
|
3414
|
+
}
|
|
3415
|
+
/**
|
|
3416
|
+
* Gets a specific photo entry from a zone
|
|
3417
|
+
*
|
|
3418
|
+
* @param appointmentId ID of the appointment
|
|
3419
|
+
* @param zoneId Zone ID
|
|
3420
|
+
* @param photoIndex Index of the entry
|
|
3421
|
+
* @returns Photo entry
|
|
3422
|
+
*/
|
|
3423
|
+
async getZonePhotoEntry(appointmentId, zoneId, photoIndex) {
|
|
3424
|
+
try {
|
|
3425
|
+
console.log(
|
|
3426
|
+
`[APPOINTMENT_SERVICE] Getting photo entry at index ${photoIndex} for zone ${zoneId}`
|
|
3427
|
+
);
|
|
3428
|
+
return await getZonePhotoEntryUtil(this.db, appointmentId, zoneId, photoIndex);
|
|
3429
|
+
} catch (error) {
|
|
3430
|
+
console.error(`[APPOINTMENT_SERVICE] Error getting zone photo entry:`, error);
|
|
3431
|
+
throw error;
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3094
3434
|
};
|
|
3095
3435
|
|
|
3096
3436
|
// src/services/auth/auth.service.ts
|
|
@@ -3481,16 +3821,16 @@ var AUTH_ERRORS = {
|
|
|
3481
3821
|
// src/services/user/user.service.ts
|
|
3482
3822
|
import {
|
|
3483
3823
|
collection as collection12,
|
|
3484
|
-
doc as
|
|
3485
|
-
getDoc as
|
|
3824
|
+
doc as doc18,
|
|
3825
|
+
getDoc as getDoc20,
|
|
3486
3826
|
getDocs as getDocs12,
|
|
3487
3827
|
query as query12,
|
|
3488
3828
|
where as where12,
|
|
3489
|
-
updateDoc as
|
|
3829
|
+
updateDoc as updateDoc17,
|
|
3490
3830
|
deleteDoc as deleteDoc5,
|
|
3491
3831
|
Timestamp as Timestamp15,
|
|
3492
3832
|
setDoc as setDoc12,
|
|
3493
|
-
serverTimestamp as
|
|
3833
|
+
serverTimestamp as serverTimestamp18
|
|
3494
3834
|
} from "firebase/firestore";
|
|
3495
3835
|
|
|
3496
3836
|
// src/errors/user.errors.ts
|
|
@@ -3590,11 +3930,11 @@ import { z as z18 } from "zod";
|
|
|
3590
3930
|
|
|
3591
3931
|
// src/services/patient/patient.service.ts
|
|
3592
3932
|
import {
|
|
3593
|
-
doc as
|
|
3594
|
-
getDoc as
|
|
3933
|
+
doc as doc16,
|
|
3934
|
+
getDoc as getDoc18,
|
|
3595
3935
|
writeBatch,
|
|
3596
|
-
updateDoc as
|
|
3597
|
-
serverTimestamp as
|
|
3936
|
+
updateDoc as updateDoc15,
|
|
3937
|
+
serverTimestamp as serverTimestamp16
|
|
3598
3938
|
} from "firebase/firestore";
|
|
3599
3939
|
import { Timestamp as Timestamp12 } from "firebase/firestore";
|
|
3600
3940
|
|
|
@@ -3606,8 +3946,8 @@ import {
|
|
|
3606
3946
|
getDocs as getDocs5,
|
|
3607
3947
|
limit as limit4,
|
|
3608
3948
|
startAfter as startAfter3,
|
|
3609
|
-
doc as
|
|
3610
|
-
getDoc as
|
|
3949
|
+
doc as doc8,
|
|
3950
|
+
getDoc as getDoc7
|
|
3611
3951
|
} from "firebase/firestore";
|
|
3612
3952
|
var getPatientsByClinicUtil = async (db, clinicId, options) => {
|
|
3613
3953
|
try {
|
|
@@ -3624,8 +3964,8 @@ var getPatientsByClinicUtil = async (db, clinicId, options) => {
|
|
|
3624
3964
|
q = query5(q, limit4(options.limit));
|
|
3625
3965
|
}
|
|
3626
3966
|
if (options == null ? void 0 : options.startAfter) {
|
|
3627
|
-
const startAfterDoc = await
|
|
3628
|
-
|
|
3967
|
+
const startAfterDoc = await getDoc7(
|
|
3968
|
+
doc8(db, PATIENTS_COLLECTION, options.startAfter)
|
|
3629
3969
|
);
|
|
3630
3970
|
if (startAfterDoc.exists()) {
|
|
3631
3971
|
q = query5(q, startAfter3(startAfterDoc));
|
|
@@ -3633,8 +3973,8 @@ var getPatientsByClinicUtil = async (db, clinicId, options) => {
|
|
|
3633
3973
|
}
|
|
3634
3974
|
const patientsSnapshot = await getDocs5(q);
|
|
3635
3975
|
const patients = [];
|
|
3636
|
-
patientsSnapshot.forEach((
|
|
3637
|
-
patients.push(
|
|
3976
|
+
patientsSnapshot.forEach((doc44) => {
|
|
3977
|
+
patients.push(doc44.data());
|
|
3638
3978
|
});
|
|
3639
3979
|
console.log(
|
|
3640
3980
|
`[getPatientsByClinicUtil] Found ${patients.length} patients for clinic ID: ${clinicId}`
|
|
@@ -3653,16 +3993,16 @@ var getPatientsByClinicUtil = async (db, clinicId, options) => {
|
|
|
3653
3993
|
|
|
3654
3994
|
// src/services/patient/utils/docs.utils.ts
|
|
3655
3995
|
import {
|
|
3656
|
-
doc as
|
|
3996
|
+
doc as doc11,
|
|
3657
3997
|
collection as collection8,
|
|
3658
3998
|
query as query8,
|
|
3659
3999
|
where as where8,
|
|
3660
4000
|
getDocs as getDocs8,
|
|
3661
|
-
getDoc as
|
|
4001
|
+
getDoc as getDoc11
|
|
3662
4002
|
} from "firebase/firestore";
|
|
3663
4003
|
|
|
3664
4004
|
// src/services/patient/utils/sensitive.utils.ts
|
|
3665
|
-
import { getDoc as
|
|
4005
|
+
import { getDoc as getDoc10, updateDoc as updateDoc8, setDoc as setDoc4, serverTimestamp as serverTimestamp9 } from "firebase/firestore";
|
|
3666
4006
|
|
|
3667
4007
|
// src/validations/patient.schema.ts
|
|
3668
4008
|
import { z as z7 } from "zod";
|
|
@@ -3964,8 +4304,8 @@ import {
|
|
|
3964
4304
|
getDocs as getDocs6,
|
|
3965
4305
|
limit as limit5,
|
|
3966
4306
|
startAfter as startAfter4,
|
|
3967
|
-
doc as
|
|
3968
|
-
getDoc as
|
|
4307
|
+
doc as doc9,
|
|
4308
|
+
getDoc as getDoc8
|
|
3969
4309
|
} from "firebase/firestore";
|
|
3970
4310
|
var getPatientsByPractitionerUtil = async (db, practitionerId, options) => {
|
|
3971
4311
|
try {
|
|
@@ -3982,8 +4322,8 @@ var getPatientsByPractitionerUtil = async (db, practitionerId, options) => {
|
|
|
3982
4322
|
q = query6(q, limit5(options.limit));
|
|
3983
4323
|
}
|
|
3984
4324
|
if (options == null ? void 0 : options.startAfter) {
|
|
3985
|
-
const startAfterDoc = await
|
|
3986
|
-
|
|
4325
|
+
const startAfterDoc = await getDoc8(
|
|
4326
|
+
doc9(db, PATIENTS_COLLECTION, options.startAfter)
|
|
3987
4327
|
);
|
|
3988
4328
|
if (startAfterDoc.exists()) {
|
|
3989
4329
|
q = query6(q, startAfter4(startAfterDoc));
|
|
@@ -3991,8 +4331,8 @@ var getPatientsByPractitionerUtil = async (db, practitionerId, options) => {
|
|
|
3991
4331
|
}
|
|
3992
4332
|
const patientsSnapshot = await getDocs6(q);
|
|
3993
4333
|
const patients = [];
|
|
3994
|
-
patientsSnapshot.forEach((
|
|
3995
|
-
patients.push(
|
|
4334
|
+
patientsSnapshot.forEach((doc44) => {
|
|
4335
|
+
patients.push(doc44.data());
|
|
3996
4336
|
});
|
|
3997
4337
|
console.log(
|
|
3998
4338
|
`[getPatientsByPractitionerUtil] Found ${patients.length} patients for practitioner ID: ${practitionerId}`
|
|
@@ -4022,7 +4362,7 @@ var getPatientsByPractitionerWithDetailsUtil = async (db, practitionerId, option
|
|
|
4022
4362
|
const patientProfilesWithDetails = await Promise.all(
|
|
4023
4363
|
patientProfiles.map(async (profile) => {
|
|
4024
4364
|
try {
|
|
4025
|
-
const sensitiveInfoDoc = await
|
|
4365
|
+
const sensitiveInfoDoc = await getDoc8(
|
|
4026
4366
|
getSensitiveInfoDocRef(db, profile.id)
|
|
4027
4367
|
);
|
|
4028
4368
|
const sensitiveInfo = sensitiveInfoDoc.exists() ? sensitiveInfoDoc.data() : void 0;
|
|
@@ -4091,16 +4431,16 @@ var getPractitionerProfileByUserRef = async (db, userRef) => {
|
|
|
4091
4431
|
// src/services/clinic/utils/admin.utils.ts
|
|
4092
4432
|
import {
|
|
4093
4433
|
collection as collection7,
|
|
4094
|
-
doc as
|
|
4095
|
-
getDoc as
|
|
4434
|
+
doc as doc10,
|
|
4435
|
+
getDoc as getDoc9,
|
|
4096
4436
|
getDocs as getDocs7,
|
|
4097
4437
|
query as query7,
|
|
4098
4438
|
where as where7,
|
|
4099
|
-
updateDoc as
|
|
4439
|
+
updateDoc as updateDoc7,
|
|
4100
4440
|
setDoc as setDoc3,
|
|
4101
4441
|
deleteDoc as deleteDoc3,
|
|
4102
4442
|
Timestamp as Timestamp7,
|
|
4103
|
-
serverTimestamp as
|
|
4443
|
+
serverTimestamp as serverTimestamp8
|
|
4104
4444
|
} from "firebase/firestore";
|
|
4105
4445
|
|
|
4106
4446
|
// src/validations/clinic.schema.ts
|
|
@@ -4709,7 +5049,7 @@ async function createClinicAdmin(db, data, clinicGroupService) {
|
|
|
4709
5049
|
}
|
|
4710
5050
|
console.log("[CLINIC_ADMIN] Preparing admin data object");
|
|
4711
5051
|
const adminData = {
|
|
4712
|
-
id:
|
|
5052
|
+
id: doc10(collection7(db, CLINIC_ADMINS_COLLECTION)).id,
|
|
4713
5053
|
// Generate a new ID for the admin document
|
|
4714
5054
|
userRef: validatedData.userRef,
|
|
4715
5055
|
clinicGroupId: clinicGroupId || "",
|
|
@@ -4722,8 +5062,8 @@ async function createClinicAdmin(db, data, clinicGroupService) {
|
|
|
4722
5062
|
contactInfo: validatedData.contactInfo,
|
|
4723
5063
|
roleTitle: validatedData.roleTitle,
|
|
4724
5064
|
isActive: validatedData.isActive,
|
|
4725
|
-
createdAt:
|
|
4726
|
-
updatedAt:
|
|
5065
|
+
createdAt: serverTimestamp8(),
|
|
5066
|
+
updatedAt: serverTimestamp8()
|
|
4727
5067
|
};
|
|
4728
5068
|
console.log("[CLINIC_ADMIN] Validating complete admin object");
|
|
4729
5069
|
try {
|
|
@@ -4744,7 +5084,7 @@ async function createClinicAdmin(db, data, clinicGroupService) {
|
|
|
4744
5084
|
adminId: adminData.id
|
|
4745
5085
|
});
|
|
4746
5086
|
try {
|
|
4747
|
-
await setDoc3(
|
|
5087
|
+
await setDoc3(doc10(db, CLINIC_ADMINS_COLLECTION, adminData.id), adminData);
|
|
4748
5088
|
console.log("[CLINIC_ADMIN] Admin saved successfully");
|
|
4749
5089
|
} catch (firestoreError) {
|
|
4750
5090
|
console.error(
|
|
@@ -4793,8 +5133,8 @@ async function checkClinicGroupExists(db, groupId, clinicGroupService) {
|
|
|
4793
5133
|
return !!group;
|
|
4794
5134
|
}
|
|
4795
5135
|
async function getClinicAdmin(db, adminId) {
|
|
4796
|
-
const docRef =
|
|
4797
|
-
const docSnap = await
|
|
5136
|
+
const docRef = doc10(db, CLINIC_ADMINS_COLLECTION, adminId);
|
|
5137
|
+
const docSnap = await getDoc9(docRef);
|
|
4798
5138
|
if (docSnap.exists()) {
|
|
4799
5139
|
return docSnap.data();
|
|
4800
5140
|
}
|
|
@@ -4817,7 +5157,7 @@ async function getClinicAdminsByGroup(db, clinicGroupId) {
|
|
|
4817
5157
|
where7("clinicGroupId", "==", clinicGroupId)
|
|
4818
5158
|
);
|
|
4819
5159
|
const querySnapshot = await getDocs7(q);
|
|
4820
|
-
return querySnapshot.docs.map((
|
|
5160
|
+
return querySnapshot.docs.map((doc44) => doc44.data());
|
|
4821
5161
|
}
|
|
4822
5162
|
async function updateClinicAdmin(db, adminId, data) {
|
|
4823
5163
|
const admin = await getClinicAdmin(db, adminId);
|
|
@@ -4826,9 +5166,9 @@ async function updateClinicAdmin(db, adminId, data) {
|
|
|
4826
5166
|
}
|
|
4827
5167
|
const updatedData = {
|
|
4828
5168
|
...data,
|
|
4829
|
-
updatedAt:
|
|
5169
|
+
updatedAt: serverTimestamp8()
|
|
4830
5170
|
};
|
|
4831
|
-
await
|
|
5171
|
+
await updateDoc7(doc10(db, CLINIC_ADMINS_COLLECTION, adminId), updatedData);
|
|
4832
5172
|
const updatedAdmin = await getClinicAdmin(db, adminId);
|
|
4833
5173
|
if (!updatedAdmin) {
|
|
4834
5174
|
throw new Error("Failed to retrieve updated admin");
|
|
@@ -4840,7 +5180,7 @@ async function deleteClinicAdmin(db, adminId) {
|
|
|
4840
5180
|
if (!admin) {
|
|
4841
5181
|
throw new Error("Clinic admin not found");
|
|
4842
5182
|
}
|
|
4843
|
-
await deleteDoc3(
|
|
5183
|
+
await deleteDoc3(doc10(db, CLINIC_ADMINS_COLLECTION, adminId));
|
|
4844
5184
|
}
|
|
4845
5185
|
async function addClinicToManaged(db, adminId, clinicId, requesterId, clinicService) {
|
|
4846
5186
|
const admin = await getClinicAdmin(db, adminId);
|
|
@@ -4954,7 +5294,7 @@ async function syncOwnerClinics(db, adminId, clinicService, clinicGroupService)
|
|
|
4954
5294
|
// src/services/patient/utils/sensitive.utils.ts
|
|
4955
5295
|
var checkSensitiveAccessUtil = async (db, patientId, requesterId, requesterRoles) => {
|
|
4956
5296
|
var _a;
|
|
4957
|
-
const patientDoc = await
|
|
5297
|
+
const patientDoc = await getDoc10(getPatientDocRef(db, patientId));
|
|
4958
5298
|
if (!patientDoc.exists()) {
|
|
4959
5299
|
throw new Error("Patient profile not found");
|
|
4960
5300
|
}
|
|
@@ -5013,7 +5353,7 @@ var createSensitiveInfoUtil = async (db, data, requesterId, requesterRoles, medi
|
|
|
5013
5353
|
try {
|
|
5014
5354
|
await checkSensitiveAccessUtil(db, data.patientId, requesterId, requesterRoles);
|
|
5015
5355
|
const validatedData = createPatientSensitiveInfoSchema.parse(data);
|
|
5016
|
-
const sensitiveDoc = await
|
|
5356
|
+
const sensitiveDoc = await getDoc10(getSensitiveInfoDocRef(db, data.patientId));
|
|
5017
5357
|
if (sensitiveDoc.exists()) {
|
|
5018
5358
|
throw new Error("Sensitive information already exists for this patient");
|
|
5019
5359
|
}
|
|
@@ -5030,11 +5370,11 @@ var createSensitiveInfoUtil = async (db, data, requesterId, requesterRoles, medi
|
|
|
5030
5370
|
const sensitiveInfoData = {
|
|
5031
5371
|
...validatedData,
|
|
5032
5372
|
photoUrl: processedPhotoUrl,
|
|
5033
|
-
createdAt:
|
|
5034
|
-
updatedAt:
|
|
5373
|
+
createdAt: serverTimestamp9(),
|
|
5374
|
+
updatedAt: serverTimestamp9()
|
|
5035
5375
|
};
|
|
5036
5376
|
await setDoc4(getSensitiveInfoDocRef(db, data.patientId), sensitiveInfoData);
|
|
5037
|
-
const createdDoc = await
|
|
5377
|
+
const createdDoc = await getDoc10(getSensitiveInfoDocRef(db, data.patientId));
|
|
5038
5378
|
if (!createdDoc.exists()) {
|
|
5039
5379
|
throw new Error("Failed to create sensitive information");
|
|
5040
5380
|
}
|
|
@@ -5049,7 +5389,7 @@ var createSensitiveInfoUtil = async (db, data, requesterId, requesterRoles, medi
|
|
|
5049
5389
|
var getSensitiveInfoUtil = async (db, patientId, requesterId, requesterRoles) => {
|
|
5050
5390
|
await checkSensitiveAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5051
5391
|
await initSensitiveInfoDocIfNotExists(db, patientId, requesterId);
|
|
5052
|
-
const sensitiveDoc = await
|
|
5392
|
+
const sensitiveDoc = await getDoc10(getSensitiveInfoDocRef(db, patientId));
|
|
5053
5393
|
return sensitiveDoc.exists() ? sensitiveDoc.data() : null;
|
|
5054
5394
|
};
|
|
5055
5395
|
var updateSensitiveInfoUtil = async (db, patientId, data, requesterId, requesterRoles, mediaService) => {
|
|
@@ -5068,17 +5408,17 @@ var updateSensitiveInfoUtil = async (db, patientId, data, requesterId, requester
|
|
|
5068
5408
|
const updateData = {
|
|
5069
5409
|
...data,
|
|
5070
5410
|
photoUrl: processedPhotoUrl,
|
|
5071
|
-
updatedAt:
|
|
5411
|
+
updatedAt: serverTimestamp9()
|
|
5072
5412
|
};
|
|
5073
|
-
await
|
|
5074
|
-
const updatedDoc = await
|
|
5413
|
+
await updateDoc8(getSensitiveInfoDocRef(db, patientId), updateData);
|
|
5414
|
+
const updatedDoc = await getDoc10(getSensitiveInfoDocRef(db, patientId));
|
|
5075
5415
|
if (!updatedDoc.exists()) {
|
|
5076
5416
|
throw new Error("Failed to retrieve updated sensitive information");
|
|
5077
5417
|
}
|
|
5078
5418
|
return updatedDoc.data();
|
|
5079
5419
|
};
|
|
5080
5420
|
var claimPatientSensitiveInfoUtil = async (db, patientId, userId) => {
|
|
5081
|
-
const patientDoc = await
|
|
5421
|
+
const patientDoc = await getDoc10(getPatientDocRef(db, patientId));
|
|
5082
5422
|
if (!patientDoc.exists()) {
|
|
5083
5423
|
throw new Error("Patient profile not found");
|
|
5084
5424
|
}
|
|
@@ -5089,7 +5429,7 @@ var claimPatientSensitiveInfoUtil = async (db, patientId, userId) => {
|
|
|
5089
5429
|
if (patientData.userRef) {
|
|
5090
5430
|
throw new Error("Patient profile has already been claimed");
|
|
5091
5431
|
}
|
|
5092
|
-
const sensitiveDoc = await
|
|
5432
|
+
const sensitiveDoc = await getDoc10(getSensitiveInfoDocRef(db, patientId));
|
|
5093
5433
|
if (!sensitiveDoc.exists()) {
|
|
5094
5434
|
throw new Error("Patient sensitive information not found");
|
|
5095
5435
|
}
|
|
@@ -5097,11 +5437,11 @@ var claimPatientSensitiveInfoUtil = async (db, patientId, userId) => {
|
|
|
5097
5437
|
if (sensitiveData.userRef) {
|
|
5098
5438
|
throw new Error("Patient sensitive information has already been claimed");
|
|
5099
5439
|
}
|
|
5100
|
-
await
|
|
5440
|
+
await updateDoc8(getSensitiveInfoDocRef(db, patientId), {
|
|
5101
5441
|
userRef: userId,
|
|
5102
|
-
updatedAt:
|
|
5442
|
+
updatedAt: serverTimestamp9()
|
|
5103
5443
|
});
|
|
5104
|
-
const updatedDoc = await
|
|
5444
|
+
const updatedDoc = await getDoc10(getSensitiveInfoDocRef(db, patientId));
|
|
5105
5445
|
if (!updatedDoc.exists()) {
|
|
5106
5446
|
throw new Error("Failed to retrieve updated sensitive information");
|
|
5107
5447
|
}
|
|
@@ -5110,7 +5450,7 @@ var claimPatientSensitiveInfoUtil = async (db, patientId, userId) => {
|
|
|
5110
5450
|
|
|
5111
5451
|
// src/services/patient/utils/docs.utils.ts
|
|
5112
5452
|
var getPatientDocRef = (db, patientId) => {
|
|
5113
|
-
return
|
|
5453
|
+
return doc11(db, PATIENTS_COLLECTION, patientId);
|
|
5114
5454
|
};
|
|
5115
5455
|
var getPatientDocRefByUserRef = async (db, userRef) => {
|
|
5116
5456
|
const patientsRef = collection8(db, PATIENTS_COLLECTION);
|
|
@@ -5119,12 +5459,12 @@ var getPatientDocRefByUserRef = async (db, userRef) => {
|
|
|
5119
5459
|
if (querySnapshot.empty) {
|
|
5120
5460
|
throw new Error("Patient profile not found");
|
|
5121
5461
|
}
|
|
5122
|
-
return
|
|
5462
|
+
return doc11(db, PATIENTS_COLLECTION, querySnapshot.docs[0].id);
|
|
5123
5463
|
};
|
|
5124
5464
|
var getSensitiveInfoDocRef = (db, patientId) => {
|
|
5125
5465
|
const path = `${PATIENTS_COLLECTION}/${patientId}/${PATIENT_SENSITIVE_INFO_COLLECTION}/${patientId}`;
|
|
5126
5466
|
console.log(`[getSensitiveInfoDocRef] Creating reference with path: ${path}`);
|
|
5127
|
-
return
|
|
5467
|
+
return doc11(
|
|
5128
5468
|
db,
|
|
5129
5469
|
PATIENTS_COLLECTION,
|
|
5130
5470
|
patientId,
|
|
@@ -5135,7 +5475,7 @@ var getSensitiveInfoDocRef = (db, patientId) => {
|
|
|
5135
5475
|
var getLocationInfoDocRef = (db, patientId) => {
|
|
5136
5476
|
const path = `${PATIENTS_COLLECTION}/${patientId}/${PATIENT_LOCATION_INFO_COLLECTION}/${patientId}`;
|
|
5137
5477
|
console.log(`[getLocationInfoDocRef] Creating reference with path: ${path}`);
|
|
5138
|
-
return
|
|
5478
|
+
return doc11(
|
|
5139
5479
|
db,
|
|
5140
5480
|
PATIENTS_COLLECTION,
|
|
5141
5481
|
patientId,
|
|
@@ -5146,7 +5486,7 @@ var getLocationInfoDocRef = (db, patientId) => {
|
|
|
5146
5486
|
var getMedicalInfoDocRef = (db, patientId) => {
|
|
5147
5487
|
const path = `${PATIENTS_COLLECTION}/${patientId}/${PATIENT_MEDICAL_INFO_COLLECTION}/${patientId}`;
|
|
5148
5488
|
console.log(`[getMedicalInfoDocRef] Creating reference with path: ${path}`);
|
|
5149
|
-
return
|
|
5489
|
+
return doc11(
|
|
5150
5490
|
db,
|
|
5151
5491
|
PATIENTS_COLLECTION,
|
|
5152
5492
|
patientId,
|
|
@@ -5163,7 +5503,7 @@ var initSensitiveInfoDocIfNotExists = async (db, patientId, userRef) => {
|
|
|
5163
5503
|
console.log(
|
|
5164
5504
|
`[initSensitiveInfoDocIfNotExists] Got document reference: ${sensitiveInfoRef.path}`
|
|
5165
5505
|
);
|
|
5166
|
-
const sensitiveDoc = await
|
|
5506
|
+
const sensitiveDoc = await getDoc11(sensitiveInfoRef);
|
|
5167
5507
|
console.log(
|
|
5168
5508
|
`[initSensitiveInfoDocIfNotExists] Document exists: ${sensitiveDoc.exists()}`
|
|
5169
5509
|
);
|
|
@@ -5187,7 +5527,7 @@ var initSensitiveInfoDocIfNotExists = async (db, patientId, userRef) => {
|
|
|
5187
5527
|
)
|
|
5188
5528
|
);
|
|
5189
5529
|
await createSensitiveInfoUtil(db, defaultSensitiveInfo, userRef);
|
|
5190
|
-
const verifyDoc = await
|
|
5530
|
+
const verifyDoc = await getDoc11(sensitiveInfoRef);
|
|
5191
5531
|
console.log(
|
|
5192
5532
|
`[initSensitiveInfoDocIfNotExists] Verification - document exists: ${verifyDoc.exists()}`
|
|
5193
5533
|
);
|
|
@@ -5205,10 +5545,10 @@ var initSensitiveInfoDocIfNotExists = async (db, patientId, userRef) => {
|
|
|
5205
5545
|
|
|
5206
5546
|
// src/services/patient/utils/location.utils.ts
|
|
5207
5547
|
import {
|
|
5208
|
-
getDoc as
|
|
5209
|
-
updateDoc as
|
|
5548
|
+
getDoc as getDoc12,
|
|
5549
|
+
updateDoc as updateDoc9,
|
|
5210
5550
|
setDoc as setDoc6,
|
|
5211
|
-
serverTimestamp as
|
|
5551
|
+
serverTimestamp as serverTimestamp11
|
|
5212
5552
|
} from "firebase/firestore";
|
|
5213
5553
|
import { z as z12 } from "zod";
|
|
5214
5554
|
import { geohashForLocation } from "geofire-common";
|
|
@@ -5220,9 +5560,9 @@ var updatePatientLocationUtil = async (db, patientId, latitude, longitude) => {
|
|
|
5220
5560
|
};
|
|
5221
5561
|
const updateData = {
|
|
5222
5562
|
locationData,
|
|
5223
|
-
updatedAt:
|
|
5563
|
+
updatedAt: serverTimestamp11()
|
|
5224
5564
|
};
|
|
5225
|
-
await
|
|
5565
|
+
await updateDoc9(getLocationInfoDocRef(db, patientId), updateData);
|
|
5226
5566
|
};
|
|
5227
5567
|
var createLocationInfoUtil = async (db, data, requesterId) => {
|
|
5228
5568
|
try {
|
|
@@ -5239,11 +5579,11 @@ var createLocationInfoUtil = async (db, data, requesterId) => {
|
|
|
5239
5579
|
validatedData.locationData.longitude
|
|
5240
5580
|
])
|
|
5241
5581
|
},
|
|
5242
|
-
createdAt:
|
|
5243
|
-
updatedAt:
|
|
5582
|
+
createdAt: serverTimestamp11(),
|
|
5583
|
+
updatedAt: serverTimestamp11()
|
|
5244
5584
|
};
|
|
5245
5585
|
await setDoc6(getLocationInfoDocRef(db, data.patientId), locationData);
|
|
5246
|
-
const locationDoc = await
|
|
5586
|
+
const locationDoc = await getDoc12(getLocationInfoDocRef(db, data.patientId));
|
|
5247
5587
|
if (!locationDoc.exists()) {
|
|
5248
5588
|
throw new Error("Failed to create location information");
|
|
5249
5589
|
}
|
|
@@ -5259,7 +5599,7 @@ var getLocationInfoUtil = async (db, patientId, requesterId) => {
|
|
|
5259
5599
|
if (patientId !== requesterId) {
|
|
5260
5600
|
throw new Error("Unauthorized access to location information");
|
|
5261
5601
|
}
|
|
5262
|
-
const locationDoc = await
|
|
5602
|
+
const locationDoc = await getDoc12(getLocationInfoDocRef(db, patientId));
|
|
5263
5603
|
return locationDoc.exists() ? locationDoc.data() : null;
|
|
5264
5604
|
};
|
|
5265
5605
|
var updateLocationInfoUtil = async (db, patientId, data, requesterId) => {
|
|
@@ -5276,8 +5616,8 @@ var updateLocationInfoUtil = async (db, patientId, data, requesterId) => {
|
|
|
5276
5616
|
])
|
|
5277
5617
|
};
|
|
5278
5618
|
}
|
|
5279
|
-
updateData.updatedAt =
|
|
5280
|
-
await
|
|
5619
|
+
updateData.updatedAt = serverTimestamp11();
|
|
5620
|
+
await updateDoc9(getLocationInfoDocRef(db, patientId), updateData);
|
|
5281
5621
|
const updatedInfo = await getLocationInfoUtil(db, patientId, requesterId);
|
|
5282
5622
|
if (!updatedInfo) {
|
|
5283
5623
|
throw new Error("Failed to retrieve updated location information");
|
|
@@ -5287,11 +5627,11 @@ var updateLocationInfoUtil = async (db, patientId, data, requesterId) => {
|
|
|
5287
5627
|
|
|
5288
5628
|
// src/services/patient/utils/medical-stuff.utils.ts
|
|
5289
5629
|
import {
|
|
5290
|
-
getDoc as
|
|
5291
|
-
updateDoc as
|
|
5630
|
+
getDoc as getDoc13,
|
|
5631
|
+
updateDoc as updateDoc10,
|
|
5292
5632
|
arrayUnion as arrayUnion2,
|
|
5293
5633
|
arrayRemove as arrayRemove2,
|
|
5294
|
-
serverTimestamp as
|
|
5634
|
+
serverTimestamp as serverTimestamp12,
|
|
5295
5635
|
Timestamp as Timestamp8
|
|
5296
5636
|
} from "firebase/firestore";
|
|
5297
5637
|
var addDoctorUtil = async (db, patientId, doctorRef, assignedBy) => {
|
|
@@ -5302,14 +5642,14 @@ var addDoctorUtil = async (db, patientId, doctorRef, assignedBy) => {
|
|
|
5302
5642
|
assignedBy,
|
|
5303
5643
|
isActive: true
|
|
5304
5644
|
};
|
|
5305
|
-
const patientDoc = await
|
|
5645
|
+
const patientDoc = await getDoc13(getPatientDocRef(db, patientId));
|
|
5306
5646
|
if (!patientDoc.exists()) throw new Error("Patient profile not found");
|
|
5307
5647
|
const patientData = patientDoc.data();
|
|
5308
5648
|
const existingDoctorIndex = (_a = patientData.doctors) == null ? void 0 : _a.findIndex(
|
|
5309
5649
|
(d) => d.userRef === doctorRef
|
|
5310
5650
|
);
|
|
5311
5651
|
const updates = {
|
|
5312
|
-
updatedAt:
|
|
5652
|
+
updatedAt: serverTimestamp12(),
|
|
5313
5653
|
doctorIds: arrayUnion2(doctorRef)
|
|
5314
5654
|
};
|
|
5315
5655
|
if (existingDoctorIndex !== void 0 && existingDoctorIndex > -1) {
|
|
@@ -5324,21 +5664,21 @@ var addDoctorUtil = async (db, patientId, doctorRef, assignedBy) => {
|
|
|
5324
5664
|
} else {
|
|
5325
5665
|
updates.doctors = arrayUnion2(newDoctor);
|
|
5326
5666
|
}
|
|
5327
|
-
await
|
|
5667
|
+
await updateDoc10(getPatientDocRef(db, patientId), updates);
|
|
5328
5668
|
};
|
|
5329
5669
|
var removeDoctorUtil = async (db, patientId, doctorRef) => {
|
|
5330
5670
|
var _a;
|
|
5331
5671
|
const patientDocRef = getPatientDocRef(db, patientId);
|
|
5332
|
-
const patientDoc = await
|
|
5672
|
+
const patientDoc = await getDoc13(patientDocRef);
|
|
5333
5673
|
if (!patientDoc.exists()) throw new Error("Patient profile not found");
|
|
5334
5674
|
const patientData = patientDoc.data();
|
|
5335
5675
|
const updatedDoctors = ((_a = patientData.doctors) == null ? void 0 : _a.filter((doctor) => doctor.userRef !== doctorRef)) || [];
|
|
5336
|
-
await
|
|
5676
|
+
await updateDoc10(patientDocRef, {
|
|
5337
5677
|
doctors: updatedDoctors,
|
|
5338
5678
|
// Set the filtered array
|
|
5339
5679
|
doctorIds: arrayRemove2(doctorRef),
|
|
5340
5680
|
// Remove ID from the denormalized list
|
|
5341
|
-
updatedAt:
|
|
5681
|
+
updatedAt: serverTimestamp12()
|
|
5342
5682
|
});
|
|
5343
5683
|
};
|
|
5344
5684
|
var addClinicUtil = async (db, patientId, clinicId, assignedBy) => {
|
|
@@ -5349,14 +5689,14 @@ var addClinicUtil = async (db, patientId, clinicId, assignedBy) => {
|
|
|
5349
5689
|
assignedBy,
|
|
5350
5690
|
isActive: true
|
|
5351
5691
|
};
|
|
5352
|
-
const patientDoc = await
|
|
5692
|
+
const patientDoc = await getDoc13(getPatientDocRef(db, patientId));
|
|
5353
5693
|
if (!patientDoc.exists()) throw new Error("Patient profile not found");
|
|
5354
5694
|
const patientData = patientDoc.data();
|
|
5355
5695
|
const existingClinicIndex = (_a = patientData.clinics) == null ? void 0 : _a.findIndex(
|
|
5356
5696
|
(c) => c.clinicId === clinicId
|
|
5357
5697
|
);
|
|
5358
5698
|
const updates = {
|
|
5359
|
-
updatedAt:
|
|
5699
|
+
updatedAt: serverTimestamp12(),
|
|
5360
5700
|
clinicIds: arrayUnion2(clinicId)
|
|
5361
5701
|
};
|
|
5362
5702
|
if (existingClinicIndex !== void 0 && existingClinicIndex > -1) {
|
|
@@ -5371,40 +5711,40 @@ var addClinicUtil = async (db, patientId, clinicId, assignedBy) => {
|
|
|
5371
5711
|
} else {
|
|
5372
5712
|
updates.clinics = arrayUnion2(newClinic);
|
|
5373
5713
|
}
|
|
5374
|
-
await
|
|
5714
|
+
await updateDoc10(getPatientDocRef(db, patientId), updates);
|
|
5375
5715
|
};
|
|
5376
5716
|
var removeClinicUtil = async (db, patientId, clinicId) => {
|
|
5377
5717
|
var _a;
|
|
5378
5718
|
const patientDocRef = getPatientDocRef(db, patientId);
|
|
5379
|
-
const patientDoc = await
|
|
5719
|
+
const patientDoc = await getDoc13(patientDocRef);
|
|
5380
5720
|
if (!patientDoc.exists()) throw new Error("Patient profile not found");
|
|
5381
5721
|
const patientData = patientDoc.data();
|
|
5382
5722
|
const updatedClinics = ((_a = patientData.clinics) == null ? void 0 : _a.filter((clinic) => clinic.clinicId !== clinicId)) || [];
|
|
5383
|
-
await
|
|
5723
|
+
await updateDoc10(patientDocRef, {
|
|
5384
5724
|
clinics: updatedClinics,
|
|
5385
5725
|
// Set the filtered array
|
|
5386
5726
|
clinicIds: arrayRemove2(clinicId),
|
|
5387
5727
|
// Remove ID from the denormalized list
|
|
5388
|
-
updatedAt:
|
|
5728
|
+
updatedAt: serverTimestamp12()
|
|
5389
5729
|
});
|
|
5390
5730
|
};
|
|
5391
5731
|
|
|
5392
5732
|
// src/services/patient/utils/medical.utils.ts
|
|
5393
5733
|
import {
|
|
5394
|
-
getDoc as
|
|
5395
|
-
updateDoc as
|
|
5734
|
+
getDoc as getDoc14,
|
|
5735
|
+
updateDoc as updateDoc11,
|
|
5396
5736
|
setDoc as setDoc7,
|
|
5397
|
-
serverTimestamp as
|
|
5737
|
+
serverTimestamp as serverTimestamp13,
|
|
5398
5738
|
arrayUnion as arrayUnion3
|
|
5399
5739
|
} from "firebase/firestore";
|
|
5400
5740
|
var ensureMedicalInfoExists = async (db, patientId, requesterId) => {
|
|
5401
5741
|
const medicalInfoRef = getMedicalInfoDocRef(db, patientId);
|
|
5402
|
-
const medicalInfoDoc = await
|
|
5742
|
+
const medicalInfoDoc = await getDoc14(medicalInfoRef);
|
|
5403
5743
|
if (!medicalInfoDoc.exists()) {
|
|
5404
5744
|
const defaultData = {
|
|
5405
5745
|
...DEFAULT_MEDICAL_INFO,
|
|
5406
5746
|
patientId,
|
|
5407
|
-
lastUpdated:
|
|
5747
|
+
lastUpdated: serverTimestamp13(),
|
|
5408
5748
|
updatedBy: requesterId
|
|
5409
5749
|
// Koristimo ID onoga ko zahteva akciju
|
|
5410
5750
|
};
|
|
@@ -5413,7 +5753,7 @@ var ensureMedicalInfoExists = async (db, patientId, requesterId) => {
|
|
|
5413
5753
|
};
|
|
5414
5754
|
var checkMedicalAccessUtil = async (db, patientId, requesterId, requesterRoles) => {
|
|
5415
5755
|
var _a;
|
|
5416
|
-
const patientDoc = await
|
|
5756
|
+
const patientDoc = await getDoc14(getPatientDocRef(db, patientId));
|
|
5417
5757
|
if (!patientDoc.exists()) {
|
|
5418
5758
|
throw new Error("Patient profile not found");
|
|
5419
5759
|
}
|
|
@@ -5456,17 +5796,17 @@ var createMedicalInfoUtil = async (db, patientId, data, requesterId, requesterRo
|
|
|
5456
5796
|
await setDoc7(getMedicalInfoDocRef(db, patientId), {
|
|
5457
5797
|
...validatedData,
|
|
5458
5798
|
patientId,
|
|
5459
|
-
lastUpdated:
|
|
5799
|
+
lastUpdated: serverTimestamp13(),
|
|
5460
5800
|
updatedBy: requesterId
|
|
5461
5801
|
});
|
|
5462
5802
|
};
|
|
5463
5803
|
var getMedicalInfoUtil = async (db, patientId, requesterId, requesterRoles) => {
|
|
5464
5804
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5465
5805
|
const docRef = getMedicalInfoDocRef(db, patientId);
|
|
5466
|
-
const snapshot = await
|
|
5806
|
+
const snapshot = await getDoc14(docRef);
|
|
5467
5807
|
if (!snapshot.exists()) {
|
|
5468
5808
|
await ensureMedicalInfoExists(db, patientId, requesterId);
|
|
5469
|
-
const newSnapshot = await
|
|
5809
|
+
const newSnapshot = await getDoc14(docRef);
|
|
5470
5810
|
return patientMedicalInfoSchema.parse(newSnapshot.data());
|
|
5471
5811
|
}
|
|
5472
5812
|
return patientMedicalInfoSchema.parse(snapshot.data());
|
|
@@ -5475,9 +5815,9 @@ var updateVitalStatsUtil = async (db, patientId, data, requesterId, requesterRol
|
|
|
5475
5815
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5476
5816
|
await ensureMedicalInfoExists(db, patientId, requesterId);
|
|
5477
5817
|
const validatedData = updateVitalStatsSchema.parse(data);
|
|
5478
|
-
await
|
|
5818
|
+
await updateDoc11(getMedicalInfoDocRef(db, patientId), {
|
|
5479
5819
|
vitalStats: validatedData,
|
|
5480
|
-
lastUpdated:
|
|
5820
|
+
lastUpdated: serverTimestamp13(),
|
|
5481
5821
|
updatedBy: requesterId
|
|
5482
5822
|
});
|
|
5483
5823
|
};
|
|
@@ -5485,9 +5825,9 @@ var addAllergyUtil = async (db, patientId, data, requesterId, requesterRoles) =>
|
|
|
5485
5825
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5486
5826
|
await ensureMedicalInfoExists(db, patientId, requesterId);
|
|
5487
5827
|
const validatedData = addAllergySchema.parse(data);
|
|
5488
|
-
await
|
|
5828
|
+
await updateDoc11(getMedicalInfoDocRef(db, patientId), {
|
|
5489
5829
|
allergies: arrayUnion3(validatedData),
|
|
5490
|
-
lastUpdated:
|
|
5830
|
+
lastUpdated: serverTimestamp13(),
|
|
5491
5831
|
updatedBy: requesterId
|
|
5492
5832
|
});
|
|
5493
5833
|
};
|
|
@@ -5495,7 +5835,7 @@ var updateAllergyUtil = async (db, patientId, data, requesterId, requesterRoles)
|
|
|
5495
5835
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5496
5836
|
const validatedData = updateAllergySchema.parse(data);
|
|
5497
5837
|
const { allergyIndex, ...updateData } = validatedData;
|
|
5498
|
-
const docSnapshot = await
|
|
5838
|
+
const docSnapshot = await getDoc14(getMedicalInfoDocRef(db, patientId));
|
|
5499
5839
|
if (!docSnapshot.exists()) throw new Error("Medical info not found");
|
|
5500
5840
|
const medicalInfo = patientMedicalInfoSchema.parse(docSnapshot.data());
|
|
5501
5841
|
if (allergyIndex >= medicalInfo.allergies.length) {
|
|
@@ -5506,26 +5846,26 @@ var updateAllergyUtil = async (db, patientId, data, requesterId, requesterRoles)
|
|
|
5506
5846
|
...updatedAllergies[allergyIndex],
|
|
5507
5847
|
...updateData
|
|
5508
5848
|
};
|
|
5509
|
-
await
|
|
5849
|
+
await updateDoc11(getMedicalInfoDocRef(db, patientId), {
|
|
5510
5850
|
allergies: updatedAllergies,
|
|
5511
|
-
lastUpdated:
|
|
5851
|
+
lastUpdated: serverTimestamp13(),
|
|
5512
5852
|
updatedBy: requesterId
|
|
5513
5853
|
});
|
|
5514
5854
|
};
|
|
5515
5855
|
var removeAllergyUtil = async (db, patientId, allergyIndex, requesterId, requesterRoles) => {
|
|
5516
5856
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5517
|
-
const
|
|
5518
|
-
if (!
|
|
5519
|
-
const medicalInfo =
|
|
5857
|
+
const doc44 = await getDoc14(getMedicalInfoDocRef(db, patientId));
|
|
5858
|
+
if (!doc44.exists()) throw new Error("Medical info not found");
|
|
5859
|
+
const medicalInfo = doc44.data();
|
|
5520
5860
|
if (allergyIndex >= medicalInfo.allergies.length) {
|
|
5521
5861
|
throw new Error("Invalid allergy index");
|
|
5522
5862
|
}
|
|
5523
5863
|
const updatedAllergies = medicalInfo.allergies.filter(
|
|
5524
5864
|
(_, index) => index !== allergyIndex
|
|
5525
5865
|
);
|
|
5526
|
-
await
|
|
5866
|
+
await updateDoc11(getMedicalInfoDocRef(db, patientId), {
|
|
5527
5867
|
allergies: updatedAllergies,
|
|
5528
|
-
lastUpdated:
|
|
5868
|
+
lastUpdated: serverTimestamp13(),
|
|
5529
5869
|
updatedBy: requesterId
|
|
5530
5870
|
});
|
|
5531
5871
|
};
|
|
@@ -5533,9 +5873,9 @@ var addBlockingConditionUtil = async (db, patientId, data, requesterId, requeste
|
|
|
5533
5873
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5534
5874
|
await ensureMedicalInfoExists(db, patientId, requesterId);
|
|
5535
5875
|
const validatedData = addBlockingConditionSchema.parse(data);
|
|
5536
|
-
await
|
|
5876
|
+
await updateDoc11(getMedicalInfoDocRef(db, patientId), {
|
|
5537
5877
|
blockingConditions: arrayUnion3(validatedData),
|
|
5538
|
-
lastUpdated:
|
|
5878
|
+
lastUpdated: serverTimestamp13(),
|
|
5539
5879
|
updatedBy: requesterId
|
|
5540
5880
|
});
|
|
5541
5881
|
};
|
|
@@ -5543,9 +5883,9 @@ var updateBlockingConditionUtil = async (db, patientId, data, requesterId, reque
|
|
|
5543
5883
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5544
5884
|
const validatedData = updateBlockingConditionSchema.parse(data);
|
|
5545
5885
|
const { conditionIndex, ...updateData } = validatedData;
|
|
5546
|
-
const
|
|
5547
|
-
if (!
|
|
5548
|
-
const medicalInfo =
|
|
5886
|
+
const doc44 = await getDoc14(getMedicalInfoDocRef(db, patientId));
|
|
5887
|
+
if (!doc44.exists()) throw new Error("Medical info not found");
|
|
5888
|
+
const medicalInfo = doc44.data();
|
|
5549
5889
|
if (conditionIndex >= medicalInfo.blockingConditions.length) {
|
|
5550
5890
|
throw new Error("Invalid blocking condition index");
|
|
5551
5891
|
}
|
|
@@ -5554,26 +5894,26 @@ var updateBlockingConditionUtil = async (db, patientId, data, requesterId, reque
|
|
|
5554
5894
|
...updatedConditions[conditionIndex],
|
|
5555
5895
|
...updateData
|
|
5556
5896
|
};
|
|
5557
|
-
await
|
|
5897
|
+
await updateDoc11(getMedicalInfoDocRef(db, patientId), {
|
|
5558
5898
|
blockingConditions: updatedConditions,
|
|
5559
|
-
lastUpdated:
|
|
5899
|
+
lastUpdated: serverTimestamp13(),
|
|
5560
5900
|
updatedBy: requesterId
|
|
5561
5901
|
});
|
|
5562
5902
|
};
|
|
5563
5903
|
var removeBlockingConditionUtil = async (db, patientId, conditionIndex, requesterId, requesterRoles) => {
|
|
5564
5904
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5565
|
-
const
|
|
5566
|
-
if (!
|
|
5567
|
-
const medicalInfo =
|
|
5905
|
+
const doc44 = await getDoc14(getMedicalInfoDocRef(db, patientId));
|
|
5906
|
+
if (!doc44.exists()) throw new Error("Medical info not found");
|
|
5907
|
+
const medicalInfo = doc44.data();
|
|
5568
5908
|
if (conditionIndex >= medicalInfo.blockingConditions.length) {
|
|
5569
5909
|
throw new Error("Invalid blocking condition index");
|
|
5570
5910
|
}
|
|
5571
5911
|
const updatedConditions = medicalInfo.blockingConditions.filter(
|
|
5572
5912
|
(_, index) => index !== conditionIndex
|
|
5573
5913
|
);
|
|
5574
|
-
await
|
|
5914
|
+
await updateDoc11(getMedicalInfoDocRef(db, patientId), {
|
|
5575
5915
|
blockingConditions: updatedConditions,
|
|
5576
|
-
lastUpdated:
|
|
5916
|
+
lastUpdated: serverTimestamp13(),
|
|
5577
5917
|
updatedBy: requesterId
|
|
5578
5918
|
});
|
|
5579
5919
|
};
|
|
@@ -5581,9 +5921,9 @@ var addContraindicationUtil = async (db, patientId, data, requesterId, requester
|
|
|
5581
5921
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5582
5922
|
await ensureMedicalInfoExists(db, patientId, requesterId);
|
|
5583
5923
|
const validatedData = addContraindicationSchema.parse(data);
|
|
5584
|
-
await
|
|
5924
|
+
await updateDoc11(getMedicalInfoDocRef(db, patientId), {
|
|
5585
5925
|
contraindications: arrayUnion3(validatedData),
|
|
5586
|
-
lastUpdated:
|
|
5926
|
+
lastUpdated: serverTimestamp13(),
|
|
5587
5927
|
updatedBy: requesterId
|
|
5588
5928
|
});
|
|
5589
5929
|
};
|
|
@@ -5591,9 +5931,9 @@ var updateContraindicationUtil = async (db, patientId, data, requesterId, reques
|
|
|
5591
5931
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5592
5932
|
const validatedData = updateContraindicationSchema.parse(data);
|
|
5593
5933
|
const { contraindicationIndex, ...updateData } = validatedData;
|
|
5594
|
-
const
|
|
5595
|
-
if (!
|
|
5596
|
-
const medicalInfo =
|
|
5934
|
+
const doc44 = await getDoc14(getMedicalInfoDocRef(db, patientId));
|
|
5935
|
+
if (!doc44.exists()) throw new Error("Medical info not found");
|
|
5936
|
+
const medicalInfo = doc44.data();
|
|
5597
5937
|
if (contraindicationIndex >= medicalInfo.contraindications.length) {
|
|
5598
5938
|
throw new Error("Invalid contraindication index");
|
|
5599
5939
|
}
|
|
@@ -5602,26 +5942,26 @@ var updateContraindicationUtil = async (db, patientId, data, requesterId, reques
|
|
|
5602
5942
|
...updatedContraindications[contraindicationIndex],
|
|
5603
5943
|
...updateData
|
|
5604
5944
|
};
|
|
5605
|
-
await
|
|
5945
|
+
await updateDoc11(getMedicalInfoDocRef(db, patientId), {
|
|
5606
5946
|
contraindications: updatedContraindications,
|
|
5607
|
-
lastUpdated:
|
|
5947
|
+
lastUpdated: serverTimestamp13(),
|
|
5608
5948
|
updatedBy: requesterId
|
|
5609
5949
|
});
|
|
5610
5950
|
};
|
|
5611
5951
|
var removeContraindicationUtil = async (db, patientId, contraindicationIndex, requesterId, requesterRoles) => {
|
|
5612
5952
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5613
|
-
const
|
|
5614
|
-
if (!
|
|
5615
|
-
const medicalInfo =
|
|
5953
|
+
const doc44 = await getDoc14(getMedicalInfoDocRef(db, patientId));
|
|
5954
|
+
if (!doc44.exists()) throw new Error("Medical info not found");
|
|
5955
|
+
const medicalInfo = doc44.data();
|
|
5616
5956
|
if (contraindicationIndex >= medicalInfo.contraindications.length) {
|
|
5617
5957
|
throw new Error("Invalid contraindication index");
|
|
5618
5958
|
}
|
|
5619
5959
|
const updatedContraindications = medicalInfo.contraindications.filter(
|
|
5620
5960
|
(_, index) => index !== contraindicationIndex
|
|
5621
5961
|
);
|
|
5622
|
-
await
|
|
5962
|
+
await updateDoc11(getMedicalInfoDocRef(db, patientId), {
|
|
5623
5963
|
contraindications: updatedContraindications,
|
|
5624
|
-
lastUpdated:
|
|
5964
|
+
lastUpdated: serverTimestamp13(),
|
|
5625
5965
|
updatedBy: requesterId
|
|
5626
5966
|
});
|
|
5627
5967
|
};
|
|
@@ -5629,9 +5969,9 @@ var addMedicationUtil = async (db, patientId, data, requesterId, requesterRoles)
|
|
|
5629
5969
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5630
5970
|
await ensureMedicalInfoExists(db, patientId, requesterId);
|
|
5631
5971
|
const validatedData = addMedicationSchema.parse(data);
|
|
5632
|
-
await
|
|
5972
|
+
await updateDoc11(getMedicalInfoDocRef(db, patientId), {
|
|
5633
5973
|
currentMedications: arrayUnion3(validatedData),
|
|
5634
|
-
lastUpdated:
|
|
5974
|
+
lastUpdated: serverTimestamp13(),
|
|
5635
5975
|
updatedBy: requesterId
|
|
5636
5976
|
});
|
|
5637
5977
|
};
|
|
@@ -5639,9 +5979,9 @@ var updateMedicationUtil = async (db, patientId, data, requesterId, requesterRol
|
|
|
5639
5979
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5640
5980
|
const validatedData = updateMedicationSchema.parse(data);
|
|
5641
5981
|
const { medicationIndex, ...updateData } = validatedData;
|
|
5642
|
-
const
|
|
5643
|
-
if (!
|
|
5644
|
-
const medicalInfo =
|
|
5982
|
+
const doc44 = await getDoc14(getMedicalInfoDocRef(db, patientId));
|
|
5983
|
+
if (!doc44.exists()) throw new Error("Medical info not found");
|
|
5984
|
+
const medicalInfo = doc44.data();
|
|
5645
5985
|
if (medicationIndex >= medicalInfo.currentMedications.length) {
|
|
5646
5986
|
throw new Error("Invalid medication index");
|
|
5647
5987
|
}
|
|
@@ -5650,38 +5990,38 @@ var updateMedicationUtil = async (db, patientId, data, requesterId, requesterRol
|
|
|
5650
5990
|
...updatedMedications[medicationIndex],
|
|
5651
5991
|
...updateData
|
|
5652
5992
|
};
|
|
5653
|
-
await
|
|
5993
|
+
await updateDoc11(getMedicalInfoDocRef(db, patientId), {
|
|
5654
5994
|
currentMedications: updatedMedications,
|
|
5655
|
-
lastUpdated:
|
|
5995
|
+
lastUpdated: serverTimestamp13(),
|
|
5656
5996
|
updatedBy: requesterId
|
|
5657
5997
|
});
|
|
5658
5998
|
};
|
|
5659
5999
|
var removeMedicationUtil = async (db, patientId, medicationIndex, requesterId, requesterRoles) => {
|
|
5660
6000
|
await checkMedicalAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
5661
|
-
const
|
|
5662
|
-
if (!
|
|
5663
|
-
const medicalInfo =
|
|
6001
|
+
const doc44 = await getDoc14(getMedicalInfoDocRef(db, patientId));
|
|
6002
|
+
if (!doc44.exists()) throw new Error("Medical info not found");
|
|
6003
|
+
const medicalInfo = doc44.data();
|
|
5664
6004
|
if (medicationIndex >= medicalInfo.currentMedications.length) {
|
|
5665
6005
|
throw new Error("Invalid medication index");
|
|
5666
6006
|
}
|
|
5667
6007
|
const updatedMedications = medicalInfo.currentMedications.filter(
|
|
5668
6008
|
(_, index) => index !== medicationIndex
|
|
5669
6009
|
);
|
|
5670
|
-
await
|
|
6010
|
+
await updateDoc11(getMedicalInfoDocRef(db, patientId), {
|
|
5671
6011
|
currentMedications: updatedMedications,
|
|
5672
|
-
lastUpdated:
|
|
6012
|
+
lastUpdated: serverTimestamp13(),
|
|
5673
6013
|
updatedBy: requesterId
|
|
5674
6014
|
});
|
|
5675
6015
|
};
|
|
5676
6016
|
|
|
5677
6017
|
// src/services/patient/utils/profile.utils.ts
|
|
5678
6018
|
import {
|
|
5679
|
-
getDoc as
|
|
6019
|
+
getDoc as getDoc15,
|
|
5680
6020
|
setDoc as setDoc8,
|
|
5681
|
-
updateDoc as
|
|
6021
|
+
updateDoc as updateDoc12,
|
|
5682
6022
|
arrayUnion as arrayUnion4,
|
|
5683
6023
|
arrayRemove as arrayRemove4,
|
|
5684
|
-
serverTimestamp as
|
|
6024
|
+
serverTimestamp as serverTimestamp14,
|
|
5685
6025
|
increment,
|
|
5686
6026
|
Timestamp as Timestamp10,
|
|
5687
6027
|
collection as collection9,
|
|
@@ -5690,7 +6030,7 @@ import {
|
|
|
5690
6030
|
getDocs as getDocs9,
|
|
5691
6031
|
limit as limit6,
|
|
5692
6032
|
startAfter as startAfter5,
|
|
5693
|
-
doc as
|
|
6033
|
+
doc as doc13
|
|
5694
6034
|
} from "firebase/firestore";
|
|
5695
6035
|
import { z as z13 } from "zod";
|
|
5696
6036
|
var createPatientProfileUtil = async (db, data, generateId2) => {
|
|
@@ -5721,8 +6061,8 @@ var createPatientProfileUtil = async (db, data, generateId2) => {
|
|
|
5721
6061
|
clinics: validatedData.clinics || [],
|
|
5722
6062
|
doctorIds: ((_a = validatedData.doctors) == null ? void 0 : _a.map((d) => d.userRef)) || [],
|
|
5723
6063
|
clinicIds: ((_b = validatedData.clinics) == null ? void 0 : _b.map((c) => c.clinicId)) || [],
|
|
5724
|
-
createdAt:
|
|
5725
|
-
updatedAt:
|
|
6064
|
+
createdAt: serverTimestamp14(),
|
|
6065
|
+
updatedAt: serverTimestamp14()
|
|
5726
6066
|
};
|
|
5727
6067
|
patientProfileSchema.parse({
|
|
5728
6068
|
...patientData,
|
|
@@ -5779,7 +6119,7 @@ var createPatientProfileUtil = async (db, data, generateId2) => {
|
|
|
5779
6119
|
}
|
|
5780
6120
|
}
|
|
5781
6121
|
console.log(`[createPatientProfileUtil] Verifying patient document exists`);
|
|
5782
|
-
const patientDoc = await
|
|
6122
|
+
const patientDoc = await getDoc15(getPatientDocRef(db, patientId));
|
|
5783
6123
|
if (!patientDoc.exists()) {
|
|
5784
6124
|
console.error(
|
|
5785
6125
|
`[createPatientProfileUtil] Patient document not found after creation`
|
|
@@ -5802,44 +6142,44 @@ var createPatientProfileUtil = async (db, data, generateId2) => {
|
|
|
5802
6142
|
}
|
|
5803
6143
|
};
|
|
5804
6144
|
var getPatientProfileUtil = async (db, patientId) => {
|
|
5805
|
-
const patientDoc = await
|
|
6145
|
+
const patientDoc = await getDoc15(getPatientDocRef(db, patientId));
|
|
5806
6146
|
return patientDoc.exists() ? patientDoc.data() : null;
|
|
5807
6147
|
};
|
|
5808
6148
|
var getPatientProfileByUserRefUtil = async (db, userRef) => {
|
|
5809
6149
|
try {
|
|
5810
6150
|
const docRef = await getPatientDocRefByUserRef(db, userRef);
|
|
5811
|
-
const patientDoc = await
|
|
6151
|
+
const patientDoc = await getDoc15(docRef);
|
|
5812
6152
|
return patientDoc.exists() ? patientDoc.data() : null;
|
|
5813
6153
|
} catch (error) {
|
|
5814
6154
|
return null;
|
|
5815
6155
|
}
|
|
5816
6156
|
};
|
|
5817
6157
|
var addExpoTokenUtil = async (db, patientId, token) => {
|
|
5818
|
-
await
|
|
6158
|
+
await updateDoc12(getPatientDocRef(db, patientId), {
|
|
5819
6159
|
expoTokens: arrayUnion4(token),
|
|
5820
|
-
updatedAt:
|
|
6160
|
+
updatedAt: serverTimestamp14()
|
|
5821
6161
|
});
|
|
5822
6162
|
};
|
|
5823
6163
|
var removeExpoTokenUtil = async (db, patientId, token) => {
|
|
5824
|
-
await
|
|
6164
|
+
await updateDoc12(getPatientDocRef(db, patientId), {
|
|
5825
6165
|
expoTokens: arrayRemove4(token),
|
|
5826
|
-
updatedAt:
|
|
6166
|
+
updatedAt: serverTimestamp14()
|
|
5827
6167
|
});
|
|
5828
6168
|
};
|
|
5829
6169
|
var addPointsUtil = async (db, patientId, points) => {
|
|
5830
|
-
await
|
|
6170
|
+
await updateDoc12(getPatientDocRef(db, patientId), {
|
|
5831
6171
|
"gamification.points": increment(points),
|
|
5832
|
-
updatedAt:
|
|
6172
|
+
updatedAt: serverTimestamp14()
|
|
5833
6173
|
});
|
|
5834
6174
|
};
|
|
5835
6175
|
var updatePatientProfileUtil = async (db, patientId, data) => {
|
|
5836
6176
|
try {
|
|
5837
6177
|
const updateData = {
|
|
5838
6178
|
...data,
|
|
5839
|
-
updatedAt:
|
|
6179
|
+
updatedAt: serverTimestamp14()
|
|
5840
6180
|
};
|
|
5841
|
-
await
|
|
5842
|
-
const updatedDoc = await
|
|
6181
|
+
await updateDoc12(getPatientDocRef(db, patientId), updateData);
|
|
6182
|
+
const updatedDoc = await getDoc15(getPatientDocRef(db, patientId));
|
|
5843
6183
|
if (!updatedDoc.exists()) {
|
|
5844
6184
|
throw new Error("Patient profile not found after update");
|
|
5845
6185
|
}
|
|
@@ -5852,7 +6192,7 @@ var updatePatientProfileUtil = async (db, patientId, data) => {
|
|
|
5852
6192
|
var updatePatientProfileByUserRefUtil = async (db, userRef, data) => {
|
|
5853
6193
|
try {
|
|
5854
6194
|
const docRef = await getPatientDocRefByUserRef(db, userRef);
|
|
5855
|
-
const patientDoc = await
|
|
6195
|
+
const patientDoc = await getDoc15(docRef);
|
|
5856
6196
|
if (!patientDoc.exists()) {
|
|
5857
6197
|
throw new Error("Patient profile not found");
|
|
5858
6198
|
}
|
|
@@ -5963,7 +6303,7 @@ var searchPatientsUtil = async (db, params, requester) => {
|
|
|
5963
6303
|
const finalQuery = query9(patientsCollectionRef, ...constraints);
|
|
5964
6304
|
const querySnapshot = await getDocs9(finalQuery);
|
|
5965
6305
|
const patients = querySnapshot.docs.map(
|
|
5966
|
-
(
|
|
6306
|
+
(doc44) => doc44.data()
|
|
5967
6307
|
);
|
|
5968
6308
|
console.log(
|
|
5969
6309
|
`[searchPatientsUtil] Found ${patients.length} patients matching criteria.`
|
|
@@ -5986,8 +6326,8 @@ var getAllPatientsUtil = async (db, options) => {
|
|
|
5986
6326
|
q = query9(q, limit6(options.limit));
|
|
5987
6327
|
}
|
|
5988
6328
|
if (options == null ? void 0 : options.startAfter) {
|
|
5989
|
-
const startAfterDoc = await
|
|
5990
|
-
|
|
6329
|
+
const startAfterDoc = await getDoc15(
|
|
6330
|
+
doc13(db, PATIENTS_COLLECTION, options.startAfter)
|
|
5991
6331
|
);
|
|
5992
6332
|
if (startAfterDoc.exists()) {
|
|
5993
6333
|
q = query9(q, startAfter5(startAfterDoc));
|
|
@@ -5995,8 +6335,8 @@ var getAllPatientsUtil = async (db, options) => {
|
|
|
5995
6335
|
}
|
|
5996
6336
|
const patientsSnapshot = await getDocs9(q);
|
|
5997
6337
|
const patients = [];
|
|
5998
|
-
patientsSnapshot.forEach((
|
|
5999
|
-
patients.push(
|
|
6338
|
+
patientsSnapshot.forEach((doc44) => {
|
|
6339
|
+
patients.push(doc44.data());
|
|
6000
6340
|
});
|
|
6001
6341
|
console.log(`[getAllPatientsUtil] Found ${patients.length} patients`);
|
|
6002
6342
|
return patients;
|
|
@@ -6011,13 +6351,13 @@ var getAllPatientsUtil = async (db, options) => {
|
|
|
6011
6351
|
// src/services/patient/utils/token.utils.ts
|
|
6012
6352
|
import {
|
|
6013
6353
|
collection as collection10,
|
|
6014
|
-
doc as
|
|
6015
|
-
getDoc as
|
|
6354
|
+
doc as doc14,
|
|
6355
|
+
getDoc as getDoc16,
|
|
6016
6356
|
getDocs as getDocs10,
|
|
6017
6357
|
query as query10,
|
|
6018
6358
|
where as where10,
|
|
6019
6359
|
setDoc as setDoc9,
|
|
6020
|
-
updateDoc as
|
|
6360
|
+
updateDoc as updateDoc13,
|
|
6021
6361
|
Timestamp as Timestamp11,
|
|
6022
6362
|
collectionGroup
|
|
6023
6363
|
} from "firebase/firestore";
|
|
@@ -6052,7 +6392,7 @@ var createPatientTokenUtil = async (db, data, createdBy, generateId2) => {
|
|
|
6052
6392
|
var _a;
|
|
6053
6393
|
const validatedData = createPatientTokenSchema.parse(data);
|
|
6054
6394
|
const patientRef = getPatientDocRef(db, validatedData.patientId);
|
|
6055
|
-
const patientDoc = await
|
|
6395
|
+
const patientDoc = await getDoc16(patientRef);
|
|
6056
6396
|
if (!patientDoc.exists() || !((_a = patientDoc.data()) == null ? void 0 : _a.isManual)) {
|
|
6057
6397
|
throw new Error(
|
|
6058
6398
|
"Patient profile not found or is not a manually created profile."
|
|
@@ -6072,7 +6412,7 @@ var createPatientTokenUtil = async (db, data, createdBy, generateId2) => {
|
|
|
6072
6412
|
expiresAt: Timestamp11.fromDate(expiration)
|
|
6073
6413
|
};
|
|
6074
6414
|
patientTokenSchema.parse(token);
|
|
6075
|
-
const tokenRef =
|
|
6415
|
+
const tokenRef = doc14(
|
|
6076
6416
|
db,
|
|
6077
6417
|
PATIENTS_COLLECTION,
|
|
6078
6418
|
validatedData.patientId,
|
|
@@ -6105,14 +6445,14 @@ var validatePatientTokenUtil = async (db, tokenString) => {
|
|
|
6105
6445
|
return null;
|
|
6106
6446
|
};
|
|
6107
6447
|
var markPatientTokenAsUsedUtil = async (db, tokenId, patientId, userId) => {
|
|
6108
|
-
const tokenRef =
|
|
6448
|
+
const tokenRef = doc14(
|
|
6109
6449
|
db,
|
|
6110
6450
|
PATIENTS_COLLECTION,
|
|
6111
6451
|
patientId,
|
|
6112
6452
|
INVITE_TOKENS_COLLECTION,
|
|
6113
6453
|
tokenId
|
|
6114
6454
|
);
|
|
6115
|
-
await
|
|
6455
|
+
await updateDoc13(tokenRef, {
|
|
6116
6456
|
status: "used" /* USED */,
|
|
6117
6457
|
usedBy: userId,
|
|
6118
6458
|
usedAt: Timestamp11.now()
|
|
@@ -6129,7 +6469,7 @@ var getActiveInviteTokensByClinicUtil = async (db, clinicId) => {
|
|
|
6129
6469
|
if (querySnapshot.empty) {
|
|
6130
6470
|
return [];
|
|
6131
6471
|
}
|
|
6132
|
-
return querySnapshot.docs.map((
|
|
6472
|
+
return querySnapshot.docs.map((doc44) => doc44.data());
|
|
6133
6473
|
};
|
|
6134
6474
|
var getActiveInviteTokensByPatientUtil = async (db, patientId) => {
|
|
6135
6475
|
const tokensRef = collection10(
|
|
@@ -6147,11 +6487,11 @@ var getActiveInviteTokensByPatientUtil = async (db, patientId) => {
|
|
|
6147
6487
|
if (querySnapshot.empty) {
|
|
6148
6488
|
return [];
|
|
6149
6489
|
}
|
|
6150
|
-
return querySnapshot.docs.map((
|
|
6490
|
+
return querySnapshot.docs.map((doc44) => doc44.data());
|
|
6151
6491
|
};
|
|
6152
6492
|
|
|
6153
6493
|
// src/services/patient/utils/aesthetic-analysis.utils.ts
|
|
6154
|
-
import { getDoc as
|
|
6494
|
+
import { getDoc as getDoc17, updateDoc as updateDoc14, setDoc as setDoc10, serverTimestamp as serverTimestamp15, doc as doc15 } from "firebase/firestore";
|
|
6155
6495
|
|
|
6156
6496
|
// src/validations/patient/aesthetic-analysis.schema.ts
|
|
6157
6497
|
import { z as z15 } from "zod";
|
|
@@ -6205,11 +6545,11 @@ var aestheticAnalysisSchema = z15.object({
|
|
|
6205
6545
|
|
|
6206
6546
|
// src/services/patient/utils/aesthetic-analysis.utils.ts
|
|
6207
6547
|
var getAestheticAnalysisDocRef = (db, patientId) => {
|
|
6208
|
-
return
|
|
6548
|
+
return doc15(db, PATIENTS_COLLECTION, patientId, AESTHETIC_ANALYSIS_COLLECTION, patientId);
|
|
6209
6549
|
};
|
|
6210
6550
|
var checkAestheticAnalysisAccessUtil = async (db, patientId, requesterId, requesterRoles) => {
|
|
6211
6551
|
var _a;
|
|
6212
|
-
const patientDoc = await
|
|
6552
|
+
const patientDoc = await getDoc17(getPatientDocRef(db, patientId));
|
|
6213
6553
|
if (!patientDoc.exists()) {
|
|
6214
6554
|
throw new Error("Patient profile not found");
|
|
6215
6555
|
}
|
|
@@ -6264,7 +6604,7 @@ var determineStatus = (completionPercentage, selectedConcerns) => {
|
|
|
6264
6604
|
var getAestheticAnalysisUtil = async (db, patientId, requesterId, requesterRoles) => {
|
|
6265
6605
|
await checkAestheticAnalysisAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
6266
6606
|
const docRef = getAestheticAnalysisDocRef(db, patientId);
|
|
6267
|
-
const snapshot = await
|
|
6607
|
+
const snapshot = await getDoc17(docRef);
|
|
6268
6608
|
if (!snapshot.exists()) {
|
|
6269
6609
|
return null;
|
|
6270
6610
|
}
|
|
@@ -6278,7 +6618,7 @@ var createOrUpdateAestheticAnalysisUtil = async (db, patientId, data, requesterI
|
|
|
6278
6618
|
await checkAestheticAnalysisAccessUtil(db, patientId, requesterId, requesterRoles);
|
|
6279
6619
|
const validatedData = isUpdate ? updateAestheticAnalysisSchema.parse(data) : createAestheticAnalysisSchema.parse(data);
|
|
6280
6620
|
const docRef = getAestheticAnalysisDocRef(db, patientId);
|
|
6281
|
-
const snapshot = await
|
|
6621
|
+
const snapshot = await getDoc17(docRef);
|
|
6282
6622
|
const requesterRole = requesterRoles.includes("practitioner" /* PRACTITIONER */) ? "PRACTITIONER" : "PATIENT";
|
|
6283
6623
|
const existingData = snapshot.exists() ? snapshot.data() : null;
|
|
6284
6624
|
const mergedData = {
|
|
@@ -6302,17 +6642,17 @@ var createOrUpdateAestheticAnalysisUtil = async (db, patientId, data, requesterI
|
|
|
6302
6642
|
status,
|
|
6303
6643
|
lastUpdatedBy: requesterId,
|
|
6304
6644
|
lastUpdatedByRole: requesterRole,
|
|
6305
|
-
createdAt:
|
|
6306
|
-
updatedAt:
|
|
6645
|
+
createdAt: serverTimestamp15(),
|
|
6646
|
+
updatedAt: serverTimestamp15()
|
|
6307
6647
|
});
|
|
6308
6648
|
} else {
|
|
6309
|
-
await
|
|
6649
|
+
await updateDoc14(docRef, {
|
|
6310
6650
|
...validatedData,
|
|
6311
6651
|
completionPercentage,
|
|
6312
6652
|
status,
|
|
6313
6653
|
lastUpdatedBy: requesterId,
|
|
6314
6654
|
lastUpdatedByRole: requesterRole,
|
|
6315
|
-
updatedAt:
|
|
6655
|
+
updatedAt: serverTimestamp15()
|
|
6316
6656
|
});
|
|
6317
6657
|
}
|
|
6318
6658
|
};
|
|
@@ -6601,7 +6941,7 @@ var PatientService = class extends BaseService {
|
|
|
6601
6941
|
if (!this.auth.currentUser) {
|
|
6602
6942
|
throw new Error("No authenticated user");
|
|
6603
6943
|
}
|
|
6604
|
-
const userDoc = await
|
|
6944
|
+
const userDoc = await getDoc18(doc16(this.db, "users", this.auth.currentUser.uid));
|
|
6605
6945
|
if (!userDoc.exists()) {
|
|
6606
6946
|
throw new Error("User not found");
|
|
6607
6947
|
}
|
|
@@ -6652,9 +6992,9 @@ var PatientService = class extends BaseService {
|
|
|
6652
6992
|
"patient_profile_photos",
|
|
6653
6993
|
file instanceof File ? file.name : `profile_photo_${patientId}`
|
|
6654
6994
|
);
|
|
6655
|
-
await
|
|
6995
|
+
await updateDoc15(getSensitiveInfoDocRef(this.db, patientId), {
|
|
6656
6996
|
photoUrl: mediaMetadata.url,
|
|
6657
|
-
updatedAt:
|
|
6997
|
+
updatedAt: serverTimestamp16()
|
|
6658
6998
|
});
|
|
6659
6999
|
return mediaMetadata.url;
|
|
6660
7000
|
}
|
|
@@ -6707,9 +7047,9 @@ var PatientService = class extends BaseService {
|
|
|
6707
7047
|
error
|
|
6708
7048
|
);
|
|
6709
7049
|
}
|
|
6710
|
-
await
|
|
7050
|
+
await updateDoc15(getSensitiveInfoDocRef(this.db, patientId), {
|
|
6711
7051
|
photoUrl: null,
|
|
6712
|
-
updatedAt:
|
|
7052
|
+
updatedAt: serverTimestamp16()
|
|
6713
7053
|
});
|
|
6714
7054
|
}
|
|
6715
7055
|
}
|
|
@@ -7028,16 +7368,16 @@ var ClinicAdminService = class extends BaseService {
|
|
|
7028
7368
|
// src/services/practitioner/practitioner.service.ts
|
|
7029
7369
|
import {
|
|
7030
7370
|
collection as collection11,
|
|
7031
|
-
doc as
|
|
7032
|
-
getDoc as
|
|
7371
|
+
doc as doc17,
|
|
7372
|
+
getDoc as getDoc19,
|
|
7033
7373
|
getDocs as getDocs11,
|
|
7034
7374
|
query as query11,
|
|
7035
7375
|
where as where11,
|
|
7036
|
-
updateDoc as
|
|
7376
|
+
updateDoc as updateDoc16,
|
|
7037
7377
|
setDoc as setDoc11,
|
|
7038
7378
|
deleteDoc as deleteDoc4,
|
|
7039
7379
|
Timestamp as Timestamp14,
|
|
7040
|
-
serverTimestamp as
|
|
7380
|
+
serverTimestamp as serverTimestamp17,
|
|
7041
7381
|
limit as limit7,
|
|
7042
7382
|
startAfter as startAfter6,
|
|
7043
7383
|
orderBy as orderBy4,
|
|
@@ -7317,15 +7657,15 @@ var PractitionerService = class extends BaseService {
|
|
|
7317
7657
|
isActive: validData.isActive !== void 0 ? validData.isActive : true,
|
|
7318
7658
|
isVerified: validData.isVerified !== void 0 ? validData.isVerified : false,
|
|
7319
7659
|
status: validData.status || "active" /* ACTIVE */,
|
|
7320
|
-
createdAt:
|
|
7321
|
-
updatedAt:
|
|
7660
|
+
createdAt: serverTimestamp17(),
|
|
7661
|
+
updatedAt: serverTimestamp17()
|
|
7322
7662
|
};
|
|
7323
7663
|
practitionerSchema.parse({
|
|
7324
7664
|
...practitioner,
|
|
7325
7665
|
createdAt: Timestamp14.now(),
|
|
7326
7666
|
updatedAt: Timestamp14.now()
|
|
7327
7667
|
});
|
|
7328
|
-
const practitionerRef =
|
|
7668
|
+
const practitionerRef = doc17(
|
|
7329
7669
|
this.db,
|
|
7330
7670
|
PRACTITIONERS_COLLECTION,
|
|
7331
7671
|
practitionerId
|
|
@@ -7423,8 +7763,8 @@ var PractitionerService = class extends BaseService {
|
|
|
7423
7763
|
isActive: validatedData.isActive !== void 0 ? validatedData.isActive : false,
|
|
7424
7764
|
isVerified: validatedData.isVerified !== void 0 ? validatedData.isVerified : false,
|
|
7425
7765
|
status: "draft" /* DRAFT */,
|
|
7426
|
-
createdAt:
|
|
7427
|
-
updatedAt:
|
|
7766
|
+
createdAt: serverTimestamp17(),
|
|
7767
|
+
updatedAt: serverTimestamp17()
|
|
7428
7768
|
};
|
|
7429
7769
|
practitionerSchema.parse({
|
|
7430
7770
|
...practitionerData,
|
|
@@ -7433,7 +7773,7 @@ var PractitionerService = class extends BaseService {
|
|
|
7433
7773
|
updatedAt: Timestamp14.now()
|
|
7434
7774
|
});
|
|
7435
7775
|
await setDoc11(
|
|
7436
|
-
|
|
7776
|
+
doc17(this.db, PRACTITIONERS_COLLECTION, practitionerData.id),
|
|
7437
7777
|
practitionerData
|
|
7438
7778
|
);
|
|
7439
7779
|
const savedPractitioner = await this.getPractitioner(practitionerData.id);
|
|
@@ -7455,7 +7795,7 @@ var PractitionerService = class extends BaseService {
|
|
|
7455
7795
|
};
|
|
7456
7796
|
practitionerTokenSchema.parse(token);
|
|
7457
7797
|
const tokenPath = `${PRACTITIONERS_COLLECTION}/${practitionerId}/${REGISTER_TOKENS_COLLECTION}/${token.id}`;
|
|
7458
|
-
await setDoc11(
|
|
7798
|
+
await setDoc11(doc17(this.db, tokenPath), token);
|
|
7459
7799
|
return { practitioner: savedPractitioner, token };
|
|
7460
7800
|
} catch (error) {
|
|
7461
7801
|
if (error instanceof z17.ZodError) {
|
|
@@ -7508,7 +7848,7 @@ var PractitionerService = class extends BaseService {
|
|
|
7508
7848
|
};
|
|
7509
7849
|
practitionerTokenSchema.parse(token);
|
|
7510
7850
|
const tokenPath = `${PRACTITIONERS_COLLECTION}/${validatedData.practitionerId}/${REGISTER_TOKENS_COLLECTION}/${token.id}`;
|
|
7511
|
-
await setDoc11(
|
|
7851
|
+
await setDoc11(doc17(this.db, tokenPath), token);
|
|
7512
7852
|
return token;
|
|
7513
7853
|
} catch (error) {
|
|
7514
7854
|
if (error instanceof z17.ZodError) {
|
|
@@ -7533,7 +7873,7 @@ var PractitionerService = class extends BaseService {
|
|
|
7533
7873
|
where11("expiresAt", ">", Timestamp14.now())
|
|
7534
7874
|
);
|
|
7535
7875
|
const querySnapshot = await getDocs11(q);
|
|
7536
|
-
return querySnapshot.docs.map((
|
|
7876
|
+
return querySnapshot.docs.map((doc44) => doc44.data());
|
|
7537
7877
|
}
|
|
7538
7878
|
/**
|
|
7539
7879
|
* Gets a token by its string value and validates it
|
|
@@ -7596,11 +7936,11 @@ var PractitionerService = class extends BaseService {
|
|
|
7596
7936
|
* @param userId ID of the user using the token
|
|
7597
7937
|
*/
|
|
7598
7938
|
async markTokenAsUsed(tokenId, practitionerId, userId) {
|
|
7599
|
-
const tokenRef =
|
|
7939
|
+
const tokenRef = doc17(
|
|
7600
7940
|
this.db,
|
|
7601
7941
|
`${PRACTITIONERS_COLLECTION}/${practitionerId}/${REGISTER_TOKENS_COLLECTION}/${tokenId}`
|
|
7602
7942
|
);
|
|
7603
|
-
await
|
|
7943
|
+
await updateDoc16(tokenRef, {
|
|
7604
7944
|
status: "used" /* USED */,
|
|
7605
7945
|
usedBy: userId,
|
|
7606
7946
|
usedAt: Timestamp14.now()
|
|
@@ -7610,8 +7950,8 @@ var PractitionerService = class extends BaseService {
|
|
|
7610
7950
|
* Dohvata zdravstvenog radnika po ID-u
|
|
7611
7951
|
*/
|
|
7612
7952
|
async getPractitioner(practitionerId) {
|
|
7613
|
-
const practitionerDoc = await
|
|
7614
|
-
|
|
7953
|
+
const practitionerDoc = await getDoc19(
|
|
7954
|
+
doc17(this.db, PRACTITIONERS_COLLECTION, practitionerId)
|
|
7615
7955
|
);
|
|
7616
7956
|
if (!practitionerDoc.exists()) {
|
|
7617
7957
|
return null;
|
|
@@ -7643,7 +7983,7 @@ var PractitionerService = class extends BaseService {
|
|
|
7643
7983
|
where11("status", "==", "active" /* ACTIVE */)
|
|
7644
7984
|
);
|
|
7645
7985
|
const querySnapshot = await getDocs11(q);
|
|
7646
|
-
return querySnapshot.docs.map((
|
|
7986
|
+
return querySnapshot.docs.map((doc44) => doc44.data());
|
|
7647
7987
|
}
|
|
7648
7988
|
/**
|
|
7649
7989
|
* Dohvata sve zdravstvene radnike za određenu kliniku
|
|
@@ -7655,7 +7995,7 @@ var PractitionerService = class extends BaseService {
|
|
|
7655
7995
|
where11("isActive", "==", true)
|
|
7656
7996
|
);
|
|
7657
7997
|
const querySnapshot = await getDocs11(q);
|
|
7658
|
-
return querySnapshot.docs.map((
|
|
7998
|
+
return querySnapshot.docs.map((doc44) => doc44.data());
|
|
7659
7999
|
}
|
|
7660
8000
|
/**
|
|
7661
8001
|
* Dohvata sve draft zdravstvene radnike za određenu kliniku sa statusom DRAFT
|
|
@@ -7667,7 +8007,7 @@ var PractitionerService = class extends BaseService {
|
|
|
7667
8007
|
where11("status", "==", "draft" /* DRAFT */)
|
|
7668
8008
|
);
|
|
7669
8009
|
const querySnapshot = await getDocs11(q);
|
|
7670
|
-
return querySnapshot.docs.map((
|
|
8010
|
+
return querySnapshot.docs.map((doc44) => doc44.data());
|
|
7671
8011
|
}
|
|
7672
8012
|
/**
|
|
7673
8013
|
* Updates a practitioner
|
|
@@ -7675,12 +8015,12 @@ var PractitionerService = class extends BaseService {
|
|
|
7675
8015
|
async updatePractitioner(practitionerId, data) {
|
|
7676
8016
|
try {
|
|
7677
8017
|
const validData = data;
|
|
7678
|
-
const practitionerRef =
|
|
8018
|
+
const practitionerRef = doc17(
|
|
7679
8019
|
this.db,
|
|
7680
8020
|
PRACTITIONERS_COLLECTION,
|
|
7681
8021
|
practitionerId
|
|
7682
8022
|
);
|
|
7683
|
-
const practitionerDoc = await
|
|
8023
|
+
const practitionerDoc = await getDoc19(practitionerRef);
|
|
7684
8024
|
if (!practitionerDoc.exists()) {
|
|
7685
8025
|
throw new Error(`Practitioner ${practitionerId} not found`);
|
|
7686
8026
|
}
|
|
@@ -7697,9 +8037,9 @@ var PractitionerService = class extends BaseService {
|
|
|
7697
8037
|
}
|
|
7698
8038
|
const updateData = {
|
|
7699
8039
|
...processedData,
|
|
7700
|
-
updatedAt:
|
|
8040
|
+
updatedAt: serverTimestamp17()
|
|
7701
8041
|
};
|
|
7702
|
-
await
|
|
8042
|
+
await updateDoc16(practitionerRef, updateData);
|
|
7703
8043
|
const updatedPractitioner = await this.getPractitioner(practitionerId);
|
|
7704
8044
|
if (!updatedPractitioner) {
|
|
7705
8045
|
throw new Error(
|
|
@@ -7721,12 +8061,12 @@ var PractitionerService = class extends BaseService {
|
|
|
7721
8061
|
async addClinic(practitionerId, clinicId) {
|
|
7722
8062
|
var _a;
|
|
7723
8063
|
try {
|
|
7724
|
-
const practitionerRef =
|
|
8064
|
+
const practitionerRef = doc17(
|
|
7725
8065
|
this.db,
|
|
7726
8066
|
PRACTITIONERS_COLLECTION,
|
|
7727
8067
|
practitionerId
|
|
7728
8068
|
);
|
|
7729
|
-
const practitionerDoc = await
|
|
8069
|
+
const practitionerDoc = await getDoc19(practitionerRef);
|
|
7730
8070
|
if (!practitionerDoc.exists()) {
|
|
7731
8071
|
throw new Error(`Practitioner ${practitionerId} not found`);
|
|
7732
8072
|
}
|
|
@@ -7737,9 +8077,9 @@ var PractitionerService = class extends BaseService {
|
|
|
7737
8077
|
);
|
|
7738
8078
|
return;
|
|
7739
8079
|
}
|
|
7740
|
-
await
|
|
8080
|
+
await updateDoc16(practitionerRef, {
|
|
7741
8081
|
clinics: arrayUnion6(clinicId),
|
|
7742
|
-
updatedAt:
|
|
8082
|
+
updatedAt: serverTimestamp17()
|
|
7743
8083
|
});
|
|
7744
8084
|
} catch (error) {
|
|
7745
8085
|
console.error(
|
|
@@ -7754,18 +8094,18 @@ var PractitionerService = class extends BaseService {
|
|
|
7754
8094
|
*/
|
|
7755
8095
|
async removeClinic(practitionerId, clinicId) {
|
|
7756
8096
|
try {
|
|
7757
|
-
const practitionerRef =
|
|
8097
|
+
const practitionerRef = doc17(
|
|
7758
8098
|
this.db,
|
|
7759
8099
|
PRACTITIONERS_COLLECTION,
|
|
7760
8100
|
practitionerId
|
|
7761
8101
|
);
|
|
7762
|
-
const practitionerDoc = await
|
|
8102
|
+
const practitionerDoc = await getDoc19(practitionerRef);
|
|
7763
8103
|
if (!practitionerDoc.exists()) {
|
|
7764
8104
|
throw new Error(`Practitioner ${practitionerId} not found`);
|
|
7765
8105
|
}
|
|
7766
|
-
await
|
|
8106
|
+
await updateDoc16(practitionerRef, {
|
|
7767
8107
|
clinics: arrayRemove5(clinicId),
|
|
7768
|
-
updatedAt:
|
|
8108
|
+
updatedAt: serverTimestamp17()
|
|
7769
8109
|
});
|
|
7770
8110
|
} catch (error) {
|
|
7771
8111
|
console.error(
|
|
@@ -7799,7 +8139,7 @@ var PractitionerService = class extends BaseService {
|
|
|
7799
8139
|
if (!practitioner) {
|
|
7800
8140
|
throw new Error("Practitioner not found");
|
|
7801
8141
|
}
|
|
7802
|
-
await deleteDoc4(
|
|
8142
|
+
await deleteDoc4(doc17(this.db, PRACTITIONERS_COLLECTION, practitionerId));
|
|
7803
8143
|
}
|
|
7804
8144
|
/**
|
|
7805
8145
|
* Validates a registration token and claims the associated draft practitioner profile
|
|
@@ -7884,7 +8224,7 @@ var PractitionerService = class extends BaseService {
|
|
|
7884
8224
|
);
|
|
7885
8225
|
const querySnapshot = await getDocs11(q);
|
|
7886
8226
|
const practitioners = querySnapshot.docs.map(
|
|
7887
|
-
(
|
|
8227
|
+
(doc44) => doc44.data()
|
|
7888
8228
|
);
|
|
7889
8229
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
7890
8230
|
return {
|
|
@@ -7969,7 +8309,7 @@ var PractitionerService = class extends BaseService {
|
|
|
7969
8309
|
);
|
|
7970
8310
|
const querySnapshot = await getDocs11(q);
|
|
7971
8311
|
const practitioners = querySnapshot.docs.map(
|
|
7972
|
-
(
|
|
8312
|
+
(doc44) => ({ ...doc44.data(), id: doc44.id })
|
|
7973
8313
|
);
|
|
7974
8314
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
7975
8315
|
console.log(
|
|
@@ -8033,7 +8373,7 @@ var PractitionerService = class extends BaseService {
|
|
|
8033
8373
|
);
|
|
8034
8374
|
const querySnapshot = await getDocs11(q);
|
|
8035
8375
|
let practitioners = querySnapshot.docs.map(
|
|
8036
|
-
(
|
|
8376
|
+
(doc44) => ({ ...doc44.data(), id: doc44.id })
|
|
8037
8377
|
);
|
|
8038
8378
|
if (filters.location && filters.radiusInKm && filters.radiusInKm > 0) {
|
|
8039
8379
|
const location = filters.location;
|
|
@@ -8078,7 +8418,7 @@ var PractitionerService = class extends BaseService {
|
|
|
8078
8418
|
);
|
|
8079
8419
|
const querySnapshot = await getDocs11(q);
|
|
8080
8420
|
let practitioners = querySnapshot.docs.map(
|
|
8081
|
-
(
|
|
8421
|
+
(doc44) => ({ ...doc44.data(), id: doc44.id })
|
|
8082
8422
|
);
|
|
8083
8423
|
practitioners = this.applyInMemoryFilters(practitioners, filters);
|
|
8084
8424
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
@@ -8108,7 +8448,7 @@ var PractitionerService = class extends BaseService {
|
|
|
8108
8448
|
);
|
|
8109
8449
|
const querySnapshot = await getDocs11(q);
|
|
8110
8450
|
let practitioners = querySnapshot.docs.map(
|
|
8111
|
-
(
|
|
8451
|
+
(doc44) => ({ ...doc44.data(), id: doc44.id })
|
|
8112
8452
|
);
|
|
8113
8453
|
practitioners = this.applyInMemoryFilters(practitioners, filters);
|
|
8114
8454
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
@@ -8499,16 +8839,16 @@ var UserService = class extends BaseService {
|
|
|
8499
8839
|
email: firebaseUser.email,
|
|
8500
8840
|
roles: roles.length > 0 ? roles : ["patient" /* PATIENT */],
|
|
8501
8841
|
isAnonymous: firebaseUser.isAnonymous,
|
|
8502
|
-
createdAt:
|
|
8503
|
-
updatedAt:
|
|
8504
|
-
lastLoginAt:
|
|
8842
|
+
createdAt: serverTimestamp18(),
|
|
8843
|
+
updatedAt: serverTimestamp18(),
|
|
8844
|
+
lastLoginAt: serverTimestamp18()
|
|
8505
8845
|
};
|
|
8506
|
-
await setDoc12(
|
|
8846
|
+
await setDoc12(doc18(this.db, USERS_COLLECTION, userData.uid), userData);
|
|
8507
8847
|
if (options == null ? void 0 : options.skipProfileCreation) {
|
|
8508
8848
|
return this.getUserById(userData.uid);
|
|
8509
8849
|
}
|
|
8510
8850
|
const profiles = await this.createProfilesForRoles(userData.uid, roles, options);
|
|
8511
|
-
await
|
|
8851
|
+
await updateDoc17(doc18(this.db, USERS_COLLECTION, userData.uid), profiles);
|
|
8512
8852
|
return this.getUserById(userData.uid);
|
|
8513
8853
|
}
|
|
8514
8854
|
/**
|
|
@@ -8641,7 +8981,7 @@ var UserService = class extends BaseService {
|
|
|
8641
8981
|
* Dohvata korisnika po ID-u
|
|
8642
8982
|
*/
|
|
8643
8983
|
async getUserById(uid) {
|
|
8644
|
-
const userDoc = await
|
|
8984
|
+
const userDoc = await getDoc20(doc18(this.db, USERS_COLLECTION, uid));
|
|
8645
8985
|
if (!userDoc.exists()) {
|
|
8646
8986
|
throw USER_ERRORS.NOT_FOUND;
|
|
8647
8987
|
}
|
|
@@ -8663,40 +9003,40 @@ var UserService = class extends BaseService {
|
|
|
8663
9003
|
const constraints = [where12("roles", "array-contains", role)];
|
|
8664
9004
|
const q = query12(collection12(this.db, USERS_COLLECTION), ...constraints);
|
|
8665
9005
|
const querySnapshot = await getDocs12(q);
|
|
8666
|
-
const users = querySnapshot.docs.map((
|
|
9006
|
+
const users = querySnapshot.docs.map((doc44) => doc44.data());
|
|
8667
9007
|
return users.map((userData) => userSchema.parse(userData));
|
|
8668
9008
|
}
|
|
8669
9009
|
/**
|
|
8670
9010
|
* Ažurira timestamp poslednjeg logovanja
|
|
8671
9011
|
*/
|
|
8672
9012
|
async updateUserLoginTimestamp(uid) {
|
|
8673
|
-
const userRef =
|
|
8674
|
-
const userDoc = await
|
|
9013
|
+
const userRef = doc18(this.db, USERS_COLLECTION, uid);
|
|
9014
|
+
const userDoc = await getDoc20(userRef);
|
|
8675
9015
|
if (!userDoc.exists()) {
|
|
8676
9016
|
throw AUTH_ERRORS.USER_NOT_FOUND;
|
|
8677
9017
|
}
|
|
8678
|
-
await
|
|
8679
|
-
lastLoginAt:
|
|
8680
|
-
updatedAt:
|
|
9018
|
+
await updateDoc17(userRef, {
|
|
9019
|
+
lastLoginAt: serverTimestamp18(),
|
|
9020
|
+
updatedAt: serverTimestamp18()
|
|
8681
9021
|
});
|
|
8682
9022
|
return this.getUserById(uid);
|
|
8683
9023
|
}
|
|
8684
9024
|
async upgradeAnonymousUser(uid, email) {
|
|
8685
|
-
const userRef =
|
|
8686
|
-
const userDoc = await
|
|
9025
|
+
const userRef = doc18(this.db, USERS_COLLECTION, uid);
|
|
9026
|
+
const userDoc = await getDoc20(userRef);
|
|
8687
9027
|
if (!userDoc.exists()) {
|
|
8688
9028
|
throw USER_ERRORS.NOT_FOUND;
|
|
8689
9029
|
}
|
|
8690
|
-
await
|
|
9030
|
+
await updateDoc17(userRef, {
|
|
8691
9031
|
email,
|
|
8692
9032
|
isAnonymous: false,
|
|
8693
|
-
updatedAt:
|
|
9033
|
+
updatedAt: serverTimestamp18()
|
|
8694
9034
|
});
|
|
8695
9035
|
return this.getUserById(uid);
|
|
8696
9036
|
}
|
|
8697
9037
|
async updateUser(uid, updates) {
|
|
8698
|
-
const userRef =
|
|
8699
|
-
const userDoc = await
|
|
9038
|
+
const userRef = doc18(this.db, USERS_COLLECTION, uid);
|
|
9039
|
+
const userDoc = await getDoc20(userRef);
|
|
8700
9040
|
if (!userDoc.exists()) {
|
|
8701
9041
|
throw USER_ERRORS.NOT_FOUND;
|
|
8702
9042
|
}
|
|
@@ -8705,12 +9045,12 @@ var UserService = class extends BaseService {
|
|
|
8705
9045
|
const updatedUser = {
|
|
8706
9046
|
...currentUser,
|
|
8707
9047
|
...updates,
|
|
8708
|
-
updatedAt:
|
|
9048
|
+
updatedAt: serverTimestamp18()
|
|
8709
9049
|
};
|
|
8710
9050
|
userSchema.parse(updatedUser);
|
|
8711
|
-
await
|
|
9051
|
+
await updateDoc17(userRef, {
|
|
8712
9052
|
...updates,
|
|
8713
|
-
updatedAt:
|
|
9053
|
+
updatedAt: serverTimestamp18()
|
|
8714
9054
|
});
|
|
8715
9055
|
return this.getUserById(uid);
|
|
8716
9056
|
} catch (error) {
|
|
@@ -8727,10 +9067,10 @@ var UserService = class extends BaseService {
|
|
|
8727
9067
|
const user = await this.getUserById(uid);
|
|
8728
9068
|
if (user.roles.includes(role)) return;
|
|
8729
9069
|
const profiles = await this.createProfilesForRoles(uid, [role], options);
|
|
8730
|
-
await
|
|
9070
|
+
await updateDoc17(doc18(this.db, USERS_COLLECTION, uid), {
|
|
8731
9071
|
roles: [...user.roles, role],
|
|
8732
9072
|
...profiles,
|
|
8733
|
-
updatedAt:
|
|
9073
|
+
updatedAt: serverTimestamp18()
|
|
8734
9074
|
});
|
|
8735
9075
|
}
|
|
8736
9076
|
/**
|
|
@@ -8756,15 +9096,15 @@ var UserService = class extends BaseService {
|
|
|
8756
9096
|
}
|
|
8757
9097
|
break;
|
|
8758
9098
|
}
|
|
8759
|
-
await
|
|
9099
|
+
await updateDoc17(doc18(this.db, USERS_COLLECTION, uid), {
|
|
8760
9100
|
roles: user.roles.filter((r) => r !== role),
|
|
8761
|
-
updatedAt:
|
|
9101
|
+
updatedAt: serverTimestamp18()
|
|
8762
9102
|
});
|
|
8763
9103
|
}
|
|
8764
9104
|
// Delete operations
|
|
8765
9105
|
async deleteUser(uid) {
|
|
8766
|
-
const userRef =
|
|
8767
|
-
const userDoc = await
|
|
9106
|
+
const userRef = doc18(this.db, USERS_COLLECTION, uid);
|
|
9107
|
+
const userDoc = await getDoc20(userRef);
|
|
8768
9108
|
if (!userDoc.exists()) {
|
|
8769
9109
|
throw USER_ERRORS.NOT_FOUND;
|
|
8770
9110
|
}
|
|
@@ -8829,9 +9169,9 @@ var BillingTransactionsService = class extends BaseService {
|
|
|
8829
9169
|
const querySnapshot = await getDocs13(q);
|
|
8830
9170
|
const docs = querySnapshot.docs;
|
|
8831
9171
|
const hasMore = docs.length > queryLimit;
|
|
8832
|
-
const transactions = docs.slice(0, queryLimit).map((
|
|
8833
|
-
id:
|
|
8834
|
-
...
|
|
9172
|
+
const transactions = docs.slice(0, queryLimit).map((doc44) => ({
|
|
9173
|
+
id: doc44.id,
|
|
9174
|
+
...doc44.data()
|
|
8835
9175
|
}));
|
|
8836
9176
|
const lastDoc = transactions.length > 0 ? docs[transactions.length - 1] : null;
|
|
8837
9177
|
return {
|
|
@@ -8907,9 +9247,9 @@ var BillingTransactionsService = class extends BaseService {
|
|
|
8907
9247
|
const querySnapshot = await getDocs13(q);
|
|
8908
9248
|
const docs = querySnapshot.docs;
|
|
8909
9249
|
const hasMore = docs.length > queryLimit;
|
|
8910
|
-
const transactions = docs.slice(0, queryLimit).map((
|
|
8911
|
-
id:
|
|
8912
|
-
...
|
|
9250
|
+
const transactions = docs.slice(0, queryLimit).map((doc44) => ({
|
|
9251
|
+
id: doc44.id,
|
|
9252
|
+
...doc44.data()
|
|
8913
9253
|
}));
|
|
8914
9254
|
const lastDoc = transactions.length > 0 ? docs[transactions.length - 1] : null;
|
|
8915
9255
|
return {
|
|
@@ -8932,12 +9272,12 @@ var BillingTransactionsService = class extends BaseService {
|
|
|
8932
9272
|
// src/services/clinic/utils/clinic-group.utils.ts
|
|
8933
9273
|
import {
|
|
8934
9274
|
collection as collection14,
|
|
8935
|
-
doc as
|
|
8936
|
-
getDoc as
|
|
9275
|
+
doc as doc19,
|
|
9276
|
+
getDoc as getDoc21,
|
|
8937
9277
|
getDocs as getDocs14,
|
|
8938
9278
|
query as query14,
|
|
8939
9279
|
where as where14,
|
|
8940
|
-
updateDoc as
|
|
9280
|
+
updateDoc as updateDoc18,
|
|
8941
9281
|
setDoc as setDoc13,
|
|
8942
9282
|
Timestamp as Timestamp16
|
|
8943
9283
|
} from "firebase/firestore";
|
|
@@ -9065,7 +9405,7 @@ async function createClinicGroup(db, data, ownerId, isDefault = false, clinicAdm
|
|
|
9065
9405
|
}
|
|
9066
9406
|
const now = Timestamp16.now();
|
|
9067
9407
|
console.log("[CLINIC_GROUP] Preparing clinic group data object");
|
|
9068
|
-
const groupId =
|
|
9408
|
+
const groupId = doc19(collection14(db, CLINIC_GROUPS_COLLECTION)).id;
|
|
9069
9409
|
console.log("[CLINIC_GROUP] Logo value:", {
|
|
9070
9410
|
logoValue: validatedData.logo,
|
|
9071
9411
|
logoType: validatedData.logo === null ? "null" : typeof validatedData.logo
|
|
@@ -9115,7 +9455,7 @@ async function createClinicGroup(db, data, ownerId, isDefault = false, clinicAdm
|
|
|
9115
9455
|
groupId: groupData.id
|
|
9116
9456
|
});
|
|
9117
9457
|
try {
|
|
9118
|
-
await setDoc13(
|
|
9458
|
+
await setDoc13(doc19(db, CLINIC_GROUPS_COLLECTION, groupData.id), groupData);
|
|
9119
9459
|
console.log("[CLINIC_GROUP] Clinic group saved successfully");
|
|
9120
9460
|
} catch (firestoreError) {
|
|
9121
9461
|
console.error(
|
|
@@ -9161,8 +9501,8 @@ async function createClinicGroup(db, data, ownerId, isDefault = false, clinicAdm
|
|
|
9161
9501
|
}
|
|
9162
9502
|
}
|
|
9163
9503
|
async function getClinicGroup(db, groupId) {
|
|
9164
|
-
const docRef =
|
|
9165
|
-
const docSnap = await
|
|
9504
|
+
const docRef = doc19(db, CLINIC_GROUPS_COLLECTION, groupId);
|
|
9505
|
+
const docSnap = await getDoc21(docRef);
|
|
9166
9506
|
if (docSnap.exists()) {
|
|
9167
9507
|
return docSnap.data();
|
|
9168
9508
|
}
|
|
@@ -9174,7 +9514,7 @@ async function getAllActiveGroups(db) {
|
|
|
9174
9514
|
where14("isActive", "==", true)
|
|
9175
9515
|
);
|
|
9176
9516
|
const querySnapshot = await getDocs14(q);
|
|
9177
|
-
return querySnapshot.docs.map((
|
|
9517
|
+
return querySnapshot.docs.map((doc44) => doc44.data());
|
|
9178
9518
|
}
|
|
9179
9519
|
async function updateClinicGroup(db, groupId, data, app) {
|
|
9180
9520
|
console.log("[CLINIC_GROUP] Updating clinic group", { groupId });
|
|
@@ -9205,7 +9545,7 @@ async function updateClinicGroup(db, groupId, data, app) {
|
|
|
9205
9545
|
updatedAt: Timestamp16.now()
|
|
9206
9546
|
};
|
|
9207
9547
|
console.log("[CLINIC_GROUP] Updating clinic group in Firestore");
|
|
9208
|
-
await
|
|
9548
|
+
await updateDoc18(doc19(db, CLINIC_GROUPS_COLLECTION, groupId), updatedData);
|
|
9209
9549
|
console.log("[CLINIC_GROUP] Clinic group updated successfully");
|
|
9210
9550
|
const updatedGroup = await getClinicGroup(db, groupId);
|
|
9211
9551
|
if (!updatedGroup) {
|
|
@@ -9587,11 +9927,11 @@ var ClinicGroupService = class extends BaseService {
|
|
|
9587
9927
|
// src/services/clinic/clinic.service.ts
|
|
9588
9928
|
import {
|
|
9589
9929
|
collection as collection18,
|
|
9590
|
-
doc as
|
|
9591
|
-
getDoc as
|
|
9930
|
+
doc as doc21,
|
|
9931
|
+
getDoc as getDoc23,
|
|
9592
9932
|
getDocs as getDocs18,
|
|
9593
|
-
updateDoc as
|
|
9594
|
-
serverTimestamp as
|
|
9933
|
+
updateDoc as updateDoc20,
|
|
9934
|
+
serverTimestamp as serverTimestamp20,
|
|
9595
9935
|
writeBatch as writeBatch4,
|
|
9596
9936
|
arrayUnion as arrayUnion7
|
|
9597
9937
|
} from "firebase/firestore";
|
|
@@ -9605,12 +9945,12 @@ import { z as z21 } from "zod";
|
|
|
9605
9945
|
// src/services/clinic/utils/clinic.utils.ts
|
|
9606
9946
|
import {
|
|
9607
9947
|
collection as collection15,
|
|
9608
|
-
doc as
|
|
9609
|
-
getDoc as
|
|
9948
|
+
doc as doc20,
|
|
9949
|
+
getDoc as getDoc22,
|
|
9610
9950
|
getDocs as getDocs15,
|
|
9611
9951
|
query as query15,
|
|
9612
9952
|
where as where15,
|
|
9613
|
-
updateDoc as
|
|
9953
|
+
updateDoc as updateDoc19,
|
|
9614
9954
|
setDoc as setDoc14,
|
|
9615
9955
|
Timestamp as Timestamp17,
|
|
9616
9956
|
limit as limit9,
|
|
@@ -9623,8 +9963,8 @@ import {
|
|
|
9623
9963
|
} from "geofire-common";
|
|
9624
9964
|
import { z as z20 } from "zod";
|
|
9625
9965
|
async function getClinic(db, clinicId) {
|
|
9626
|
-
const docRef =
|
|
9627
|
-
const docSnap = await
|
|
9966
|
+
const docRef = doc20(db, CLINICS_COLLECTION, clinicId);
|
|
9967
|
+
const docSnap = await getDoc22(docRef);
|
|
9628
9968
|
if (docSnap.exists()) {
|
|
9629
9969
|
return docSnap.data();
|
|
9630
9970
|
}
|
|
@@ -9637,7 +9977,7 @@ async function getClinicsByGroup(db, groupId) {
|
|
|
9637
9977
|
where15("isActive", "==", true)
|
|
9638
9978
|
);
|
|
9639
9979
|
const querySnapshot = await getDocs15(q);
|
|
9640
|
-
return querySnapshot.docs.map((
|
|
9980
|
+
return querySnapshot.docs.map((doc44) => doc44.data());
|
|
9641
9981
|
}
|
|
9642
9982
|
async function updateClinic(db, clinicId, data, adminId, clinicAdminService, app) {
|
|
9643
9983
|
console.log("[CLINIC] Starting clinic update", { clinicId, adminId });
|
|
@@ -9796,7 +10136,7 @@ async function updateClinic(db, clinicId, data, adminId, clinicAdminService, app
|
|
|
9796
10136
|
};
|
|
9797
10137
|
console.log("[CLINIC] Updating clinic in Firestore");
|
|
9798
10138
|
try {
|
|
9799
|
-
await
|
|
10139
|
+
await updateDoc19(doc20(db, CLINICS_COLLECTION, clinicId), updatedData);
|
|
9800
10140
|
console.log("[CLINIC] Clinic updated successfully");
|
|
9801
10141
|
} catch (updateError) {
|
|
9802
10142
|
console.error("[CLINIC] Error updating clinic in Firestore:", updateError);
|
|
@@ -9831,7 +10171,7 @@ async function getClinicsByAdmin(db, adminId, options = {}, clinicAdminService,
|
|
|
9831
10171
|
}
|
|
9832
10172
|
const q = query15(collection15(db, CLINICS_COLLECTION), ...constraints);
|
|
9833
10173
|
const querySnapshot = await getDocs15(q);
|
|
9834
|
-
return querySnapshot.docs.map((
|
|
10174
|
+
return querySnapshot.docs.map((doc44) => doc44.data());
|
|
9835
10175
|
}
|
|
9836
10176
|
async function getActiveClinicsByAdmin(db, adminId, clinicAdminService, clinicGroupService) {
|
|
9837
10177
|
return getClinicsByAdmin(
|
|
@@ -9844,8 +10184,8 @@ async function getActiveClinicsByAdmin(db, adminId, clinicAdminService, clinicGr
|
|
|
9844
10184
|
}
|
|
9845
10185
|
async function getClinicById(db, clinicId) {
|
|
9846
10186
|
try {
|
|
9847
|
-
const clinicRef =
|
|
9848
|
-
const clinicSnapshot = await
|
|
10187
|
+
const clinicRef = doc20(db, CLINICS_COLLECTION, clinicId);
|
|
10188
|
+
const clinicSnapshot = await getDoc22(clinicRef);
|
|
9849
10189
|
if (!clinicSnapshot.exists()) {
|
|
9850
10190
|
return null;
|
|
9851
10191
|
}
|
|
@@ -9876,11 +10216,11 @@ async function getAllClinics(db, pagination, lastDoc) {
|
|
|
9876
10216
|
}
|
|
9877
10217
|
const clinicsSnapshot = await getDocs15(clinicsQuery);
|
|
9878
10218
|
const lastVisible = clinicsSnapshot.docs[clinicsSnapshot.docs.length - 1];
|
|
9879
|
-
const clinics = clinicsSnapshot.docs.map((
|
|
9880
|
-
const data =
|
|
10219
|
+
const clinics = clinicsSnapshot.docs.map((doc44) => {
|
|
10220
|
+
const data = doc44.data();
|
|
9881
10221
|
return {
|
|
9882
10222
|
...data,
|
|
9883
|
-
id:
|
|
10223
|
+
id: doc44.id
|
|
9884
10224
|
};
|
|
9885
10225
|
});
|
|
9886
10226
|
return {
|
|
@@ -9907,8 +10247,8 @@ async function getAllClinicsInRange(db, center, rangeInKm, pagination, lastDoc)
|
|
|
9907
10247
|
];
|
|
9908
10248
|
const q = query15(collection15(db, CLINICS_COLLECTION), ...constraints);
|
|
9909
10249
|
const querySnapshot = await getDocs15(q);
|
|
9910
|
-
for (const
|
|
9911
|
-
const clinic =
|
|
10250
|
+
for (const doc44 of querySnapshot.docs) {
|
|
10251
|
+
const clinic = doc44.data();
|
|
9912
10252
|
const distance = distanceBetween2(
|
|
9913
10253
|
[center.latitude, center.longitude],
|
|
9914
10254
|
[clinic.location.latitude, clinic.location.longitude]
|
|
@@ -10030,8 +10370,8 @@ async function findClinicsInRadius(db, center, radiusInKm, filters) {
|
|
|
10030
10370
|
}
|
|
10031
10371
|
const q = query16(collection16(db, CLINICS_COLLECTION), ...constraints);
|
|
10032
10372
|
const querySnapshot = await getDocs16(q);
|
|
10033
|
-
for (const
|
|
10034
|
-
const clinic =
|
|
10373
|
+
for (const doc44 of querySnapshot.docs) {
|
|
10374
|
+
const clinic = doc44.data();
|
|
10035
10375
|
const distance = distanceBetween3(
|
|
10036
10376
|
[center.latitude, center.longitude],
|
|
10037
10377
|
[clinic.location.latitude, clinic.location.longitude]
|
|
@@ -10160,7 +10500,7 @@ async function getClinicsByFilters(db, filters) {
|
|
|
10160
10500
|
constraints.push(limit10(filters.pagination || 5));
|
|
10161
10501
|
const q = query17(collection17(db, CLINICS_COLLECTION), ...constraints);
|
|
10162
10502
|
const querySnapshot = await getDocs17(q);
|
|
10163
|
-
let clinics = querySnapshot.docs.map((
|
|
10503
|
+
let clinics = querySnapshot.docs.map((doc44) => ({ ...doc44.data(), id: doc44.id }));
|
|
10164
10504
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
10165
10505
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
10166
10506
|
console.log(`[CLINIC_SERVICE] Strategy 1 success: ${clinics.length} clinics`);
|
|
@@ -10192,7 +10532,7 @@ async function getClinicsByFilters(db, filters) {
|
|
|
10192
10532
|
constraints.push(limit10(filters.pagination || 5));
|
|
10193
10533
|
const q = query17(collection17(db, CLINICS_COLLECTION), ...constraints);
|
|
10194
10534
|
const querySnapshot = await getDocs17(q);
|
|
10195
|
-
let clinics = querySnapshot.docs.map((
|
|
10535
|
+
let clinics = querySnapshot.docs.map((doc44) => ({ ...doc44.data(), id: doc44.id }));
|
|
10196
10536
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
10197
10537
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
10198
10538
|
console.log(`[CLINIC_SERVICE] Strategy 2 success: ${clinics.length} clinics`);
|
|
@@ -10222,7 +10562,7 @@ async function getClinicsByFilters(db, filters) {
|
|
|
10222
10562
|
constraints.push(limit10(filters.pagination || 5));
|
|
10223
10563
|
const q = query17(collection17(db, CLINICS_COLLECTION), ...constraints);
|
|
10224
10564
|
const querySnapshot = await getDocs17(q);
|
|
10225
|
-
let clinics = querySnapshot.docs.map((
|
|
10565
|
+
let clinics = querySnapshot.docs.map((doc44) => ({ ...doc44.data(), id: doc44.id }));
|
|
10226
10566
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
10227
10567
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
10228
10568
|
console.log(`[CLINIC_SERVICE] Strategy 3 success: ${clinics.length} clinics`);
|
|
@@ -10242,7 +10582,7 @@ async function getClinicsByFilters(db, filters) {
|
|
|
10242
10582
|
];
|
|
10243
10583
|
const q = query17(collection17(db, CLINICS_COLLECTION), ...constraints);
|
|
10244
10584
|
const querySnapshot = await getDocs17(q);
|
|
10245
|
-
let clinics = querySnapshot.docs.map((
|
|
10585
|
+
let clinics = querySnapshot.docs.map((doc44) => ({ ...doc44.data(), id: doc44.id }));
|
|
10246
10586
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
10247
10587
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
10248
10588
|
console.log(`[CLINIC_SERVICE] Strategy 4 success: ${clinics.length} clinics`);
|
|
@@ -10543,16 +10883,16 @@ var ClinicService = class extends BaseService {
|
|
|
10543
10883
|
isActive: validatedData.isActive !== void 0 ? validatedData.isActive : true,
|
|
10544
10884
|
isVerified: validatedData.isVerified !== void 0 ? validatedData.isVerified : false,
|
|
10545
10885
|
logo: logoUrl,
|
|
10546
|
-
createdAt:
|
|
10547
|
-
updatedAt:
|
|
10886
|
+
createdAt: serverTimestamp20(),
|
|
10887
|
+
updatedAt: serverTimestamp20()
|
|
10548
10888
|
};
|
|
10549
10889
|
const batch = writeBatch4(this.db);
|
|
10550
|
-
const clinicRef =
|
|
10890
|
+
const clinicRef = doc21(this.db, CLINICS_COLLECTION, clinicId);
|
|
10551
10891
|
batch.set(clinicRef, clinicData);
|
|
10552
|
-
const adminRef =
|
|
10892
|
+
const adminRef = doc21(this.db, CLINIC_ADMINS_COLLECTION, creatorAdminId);
|
|
10553
10893
|
batch.update(adminRef, {
|
|
10554
10894
|
clinicsManaged: arrayUnion7(clinicId),
|
|
10555
|
-
updatedAt:
|
|
10895
|
+
updatedAt: serverTimestamp20()
|
|
10556
10896
|
});
|
|
10557
10897
|
await batch.commit();
|
|
10558
10898
|
console.log(`[ClinicService] Clinic created successfully: ${clinicId}`);
|
|
@@ -10573,8 +10913,8 @@ var ClinicService = class extends BaseService {
|
|
|
10573
10913
|
*/
|
|
10574
10914
|
async updateClinic(clinicId, data, adminId) {
|
|
10575
10915
|
try {
|
|
10576
|
-
const clinicRef =
|
|
10577
|
-
const clinicDoc = await
|
|
10916
|
+
const clinicRef = doc21(this.db, CLINICS_COLLECTION, clinicId);
|
|
10917
|
+
const clinicDoc = await getDoc23(clinicRef);
|
|
10578
10918
|
if (!clinicDoc.exists()) {
|
|
10579
10919
|
throw new Error(`Clinic ${clinicId} not found`);
|
|
10580
10920
|
}
|
|
@@ -10638,8 +10978,8 @@ var ClinicService = class extends BaseService {
|
|
|
10638
10978
|
tz
|
|
10639
10979
|
};
|
|
10640
10980
|
}
|
|
10641
|
-
updatePayload.updatedAt =
|
|
10642
|
-
await
|
|
10981
|
+
updatePayload.updatedAt = serverTimestamp20();
|
|
10982
|
+
await updateDoc20(clinicRef, updatePayload);
|
|
10643
10983
|
console.log(`[ClinicService] Clinic ${clinicId} updated successfully`);
|
|
10644
10984
|
const updatedClinic = await this.getClinic(clinicId);
|
|
10645
10985
|
if (!updatedClinic) throw new Error("Failed to retrieve updated clinic");
|
|
@@ -10656,20 +10996,20 @@ var ClinicService = class extends BaseService {
|
|
|
10656
10996
|
* Deactivates a clinic.
|
|
10657
10997
|
*/
|
|
10658
10998
|
async deactivateClinic(clinicId, adminId) {
|
|
10659
|
-
const clinicRef =
|
|
10660
|
-
await
|
|
10999
|
+
const clinicRef = doc21(this.db, CLINICS_COLLECTION, clinicId);
|
|
11000
|
+
await updateDoc20(clinicRef, {
|
|
10661
11001
|
isActive: false,
|
|
10662
|
-
updatedAt:
|
|
11002
|
+
updatedAt: serverTimestamp20()
|
|
10663
11003
|
});
|
|
10664
11004
|
}
|
|
10665
11005
|
/**
|
|
10666
11006
|
* Activates a clinic.
|
|
10667
11007
|
*/
|
|
10668
11008
|
async activateClinic(clinicId, adminId) {
|
|
10669
|
-
const clinicRef =
|
|
10670
|
-
await
|
|
11009
|
+
const clinicRef = doc21(this.db, CLINICS_COLLECTION, clinicId);
|
|
11010
|
+
await updateDoc20(clinicRef, {
|
|
10671
11011
|
isActive: true,
|
|
10672
|
-
updatedAt:
|
|
11012
|
+
updatedAt: serverTimestamp20()
|
|
10673
11013
|
});
|
|
10674
11014
|
}
|
|
10675
11015
|
/**
|
|
@@ -10814,11 +11154,11 @@ var ClinicService = class extends BaseService {
|
|
|
10814
11154
|
async getClinicsForMap() {
|
|
10815
11155
|
const clinicsRef = collection18(this.db, CLINICS_COLLECTION);
|
|
10816
11156
|
const snapshot = await getDocs18(clinicsRef);
|
|
10817
|
-
const clinicsForMap = snapshot.docs.map((
|
|
11157
|
+
const clinicsForMap = snapshot.docs.map((doc44) => {
|
|
10818
11158
|
var _a, _b, _c;
|
|
10819
|
-
const data =
|
|
11159
|
+
const data = doc44.data();
|
|
10820
11160
|
return {
|
|
10821
|
-
id:
|
|
11161
|
+
id: doc44.id,
|
|
10822
11162
|
name: data.name,
|
|
10823
11163
|
address: ((_a = data.location) == null ? void 0 : _a.address) || "",
|
|
10824
11164
|
latitude: (_b = data.location) == null ? void 0 : _b.latitude,
|
|
@@ -11643,68 +11983,68 @@ var AuthService = class extends BaseService {
|
|
|
11643
11983
|
};
|
|
11644
11984
|
|
|
11645
11985
|
// src/services/calendar/calendar.v2.service.ts
|
|
11646
|
-
import { Timestamp as Timestamp26, serverTimestamp as
|
|
11986
|
+
import { Timestamp as Timestamp26, serverTimestamp as serverTimestamp26 } from "firebase/firestore";
|
|
11647
11987
|
import {
|
|
11648
|
-
doc as
|
|
11649
|
-
getDoc as
|
|
11988
|
+
doc as doc29,
|
|
11989
|
+
getDoc as getDoc30,
|
|
11650
11990
|
collection as collection25,
|
|
11651
11991
|
query as query25,
|
|
11652
11992
|
where as where25,
|
|
11653
11993
|
getDocs as getDocs25,
|
|
11654
11994
|
setDoc as setDoc22,
|
|
11655
|
-
updateDoc as
|
|
11995
|
+
updateDoc as updateDoc27
|
|
11656
11996
|
} from "firebase/firestore";
|
|
11657
11997
|
|
|
11658
11998
|
// src/services/calendar/utils/clinic.utils.ts
|
|
11659
11999
|
import {
|
|
11660
12000
|
collection as collection20,
|
|
11661
|
-
doc as
|
|
11662
|
-
getDoc as
|
|
12001
|
+
doc as doc24,
|
|
12002
|
+
getDoc as getDoc25,
|
|
11663
12003
|
getDocs as getDocs20,
|
|
11664
12004
|
setDoc as setDoc17,
|
|
11665
|
-
updateDoc as
|
|
12005
|
+
updateDoc as updateDoc22,
|
|
11666
12006
|
deleteDoc as deleteDoc10,
|
|
11667
12007
|
query as query20,
|
|
11668
12008
|
where as where20,
|
|
11669
12009
|
orderBy as orderBy8,
|
|
11670
12010
|
Timestamp as Timestamp20,
|
|
11671
|
-
serverTimestamp as
|
|
12011
|
+
serverTimestamp as serverTimestamp21
|
|
11672
12012
|
} from "firebase/firestore";
|
|
11673
12013
|
|
|
11674
12014
|
// src/services/calendar/utils/docs.utils.ts
|
|
11675
|
-
import { doc as
|
|
12015
|
+
import { doc as doc23 } from "firebase/firestore";
|
|
11676
12016
|
function getPractitionerCalendarEventDocRef(db, practitionerId, eventId) {
|
|
11677
|
-
return
|
|
12017
|
+
return doc23(
|
|
11678
12018
|
db,
|
|
11679
12019
|
`${PRACTITIONERS_COLLECTION}/${practitionerId}/${CALENDAR_COLLECTION}/${eventId}`
|
|
11680
12020
|
);
|
|
11681
12021
|
}
|
|
11682
12022
|
function getPatientCalendarEventDocRef(db, patientId, eventId) {
|
|
11683
|
-
return
|
|
12023
|
+
return doc23(
|
|
11684
12024
|
db,
|
|
11685
12025
|
`${PATIENTS_COLLECTION}/${patientId}/${CALENDAR_COLLECTION}/${eventId}`
|
|
11686
12026
|
);
|
|
11687
12027
|
}
|
|
11688
12028
|
function getClinicCalendarEventDocRef(db, clinicId, eventId) {
|
|
11689
|
-
return
|
|
12029
|
+
return doc23(
|
|
11690
12030
|
db,
|
|
11691
12031
|
`${CLINICS_COLLECTION}/${clinicId}/${CALENDAR_COLLECTION}/${eventId}`
|
|
11692
12032
|
);
|
|
11693
12033
|
}
|
|
11694
12034
|
function getPractitionerSyncedCalendarDocRef(db, practitionerId, syncedCalendarId) {
|
|
11695
|
-
return
|
|
12035
|
+
return doc23(
|
|
11696
12036
|
db,
|
|
11697
12037
|
`${PRACTITIONERS_COLLECTION}/${practitionerId}/syncedCalendars/${syncedCalendarId}`
|
|
11698
12038
|
);
|
|
11699
12039
|
}
|
|
11700
12040
|
function getPatientSyncedCalendarDocRef(db, patientId, syncedCalendarId) {
|
|
11701
|
-
return
|
|
12041
|
+
return doc23(
|
|
11702
12042
|
db,
|
|
11703
12043
|
`${PATIENTS_COLLECTION}/${patientId}/syncedCalendars/${syncedCalendarId}`
|
|
11704
12044
|
);
|
|
11705
12045
|
}
|
|
11706
12046
|
function getClinicSyncedCalendarDocRef(db, clinicId, syncedCalendarId) {
|
|
11707
|
-
return
|
|
12047
|
+
return doc23(
|
|
11708
12048
|
db,
|
|
11709
12049
|
`${CLINICS_COLLECTION}/${clinicId}/syncedCalendars/${syncedCalendarId}`
|
|
11710
12050
|
);
|
|
@@ -11717,8 +12057,8 @@ async function createClinicCalendarEventUtil(db, clinicId, eventData, generateId
|
|
|
11717
12057
|
const newEvent = {
|
|
11718
12058
|
id: eventId,
|
|
11719
12059
|
...eventData,
|
|
11720
|
-
createdAt:
|
|
11721
|
-
updatedAt:
|
|
12060
|
+
createdAt: serverTimestamp21(),
|
|
12061
|
+
updatedAt: serverTimestamp21()
|
|
11722
12062
|
};
|
|
11723
12063
|
await setDoc17(eventRef, newEvent);
|
|
11724
12064
|
return {
|
|
@@ -11731,17 +12071,17 @@ async function updateClinicCalendarEventUtil(db, clinicId, eventId, updateData)
|
|
|
11731
12071
|
const eventRef = getClinicCalendarEventDocRef(db, clinicId, eventId);
|
|
11732
12072
|
const updates = {
|
|
11733
12073
|
...updateData,
|
|
11734
|
-
updatedAt:
|
|
12074
|
+
updatedAt: serverTimestamp21()
|
|
11735
12075
|
};
|
|
11736
|
-
await
|
|
11737
|
-
const updatedDoc = await
|
|
12076
|
+
await updateDoc22(eventRef, updates);
|
|
12077
|
+
const updatedDoc = await getDoc25(eventRef);
|
|
11738
12078
|
if (!updatedDoc.exists()) {
|
|
11739
12079
|
throw new Error("Event not found after update");
|
|
11740
12080
|
}
|
|
11741
12081
|
return updatedDoc.data();
|
|
11742
12082
|
}
|
|
11743
12083
|
async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
|
|
11744
|
-
const clinicDoc = await
|
|
12084
|
+
const clinicDoc = await getDoc25(doc24(db, `clinics/${clinicId}`));
|
|
11745
12085
|
if (!clinicDoc.exists()) {
|
|
11746
12086
|
throw new Error(`Clinic with ID ${clinicId} not found`);
|
|
11747
12087
|
}
|
|
@@ -11750,8 +12090,8 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
|
|
|
11750
12090
|
if (!clinicGroupId) {
|
|
11751
12091
|
return false;
|
|
11752
12092
|
}
|
|
11753
|
-
const clinicGroupDoc = await
|
|
11754
|
-
|
|
12093
|
+
const clinicGroupDoc = await getDoc25(
|
|
12094
|
+
doc24(db, `${CLINIC_GROUPS_COLLECTION}/${clinicGroupId}`)
|
|
11755
12095
|
);
|
|
11756
12096
|
if (!clinicGroupDoc.exists()) {
|
|
11757
12097
|
return false;
|
|
@@ -11763,16 +12103,16 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
|
|
|
11763
12103
|
// src/services/calendar/utils/patient.utils.ts
|
|
11764
12104
|
import {
|
|
11765
12105
|
collection as collection21,
|
|
11766
|
-
getDoc as
|
|
12106
|
+
getDoc as getDoc26,
|
|
11767
12107
|
getDocs as getDocs21,
|
|
11768
12108
|
setDoc as setDoc18,
|
|
11769
|
-
updateDoc as
|
|
12109
|
+
updateDoc as updateDoc23,
|
|
11770
12110
|
deleteDoc as deleteDoc11,
|
|
11771
12111
|
query as query21,
|
|
11772
12112
|
where as where21,
|
|
11773
12113
|
orderBy as orderBy9,
|
|
11774
12114
|
Timestamp as Timestamp21,
|
|
11775
|
-
serverTimestamp as
|
|
12115
|
+
serverTimestamp as serverTimestamp22
|
|
11776
12116
|
} from "firebase/firestore";
|
|
11777
12117
|
async function createPatientCalendarEventUtil(db, patientId, eventData, generateId2) {
|
|
11778
12118
|
const eventId = generateId2();
|
|
@@ -11780,8 +12120,8 @@ async function createPatientCalendarEventUtil(db, patientId, eventData, generate
|
|
|
11780
12120
|
const newEvent = {
|
|
11781
12121
|
id: eventId,
|
|
11782
12122
|
...eventData,
|
|
11783
|
-
createdAt:
|
|
11784
|
-
updatedAt:
|
|
12123
|
+
createdAt: serverTimestamp22(),
|
|
12124
|
+
updatedAt: serverTimestamp22()
|
|
11785
12125
|
};
|
|
11786
12126
|
await setDoc18(eventRef, newEvent);
|
|
11787
12127
|
return {
|
|
@@ -11794,10 +12134,10 @@ async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData
|
|
|
11794
12134
|
const eventRef = getPatientCalendarEventDocRef(db, patientId, eventId);
|
|
11795
12135
|
const updates = {
|
|
11796
12136
|
...updateData,
|
|
11797
|
-
updatedAt:
|
|
12137
|
+
updatedAt: serverTimestamp22()
|
|
11798
12138
|
};
|
|
11799
|
-
await
|
|
11800
|
-
const updatedDoc = await
|
|
12139
|
+
await updateDoc23(eventRef, updates);
|
|
12140
|
+
const updatedDoc = await getDoc26(eventRef);
|
|
11801
12141
|
if (!updatedDoc.exists()) {
|
|
11802
12142
|
throw new Error("Event not found after update");
|
|
11803
12143
|
}
|
|
@@ -11807,16 +12147,16 @@ async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData
|
|
|
11807
12147
|
// src/services/calendar/utils/practitioner.utils.ts
|
|
11808
12148
|
import {
|
|
11809
12149
|
collection as collection22,
|
|
11810
|
-
getDoc as
|
|
12150
|
+
getDoc as getDoc27,
|
|
11811
12151
|
getDocs as getDocs22,
|
|
11812
12152
|
setDoc as setDoc19,
|
|
11813
|
-
updateDoc as
|
|
12153
|
+
updateDoc as updateDoc24,
|
|
11814
12154
|
deleteDoc as deleteDoc12,
|
|
11815
12155
|
query as query22,
|
|
11816
12156
|
where as where22,
|
|
11817
12157
|
orderBy as orderBy10,
|
|
11818
12158
|
Timestamp as Timestamp22,
|
|
11819
|
-
serverTimestamp as
|
|
12159
|
+
serverTimestamp as serverTimestamp23
|
|
11820
12160
|
} from "firebase/firestore";
|
|
11821
12161
|
async function createPractitionerCalendarEventUtil(db, practitionerId, eventData, generateId2) {
|
|
11822
12162
|
const eventId = generateId2();
|
|
@@ -11828,8 +12168,8 @@ async function createPractitionerCalendarEventUtil(db, practitionerId, eventData
|
|
|
11828
12168
|
const newEvent = {
|
|
11829
12169
|
id: eventId,
|
|
11830
12170
|
...eventData,
|
|
11831
|
-
createdAt:
|
|
11832
|
-
updatedAt:
|
|
12171
|
+
createdAt: serverTimestamp23(),
|
|
12172
|
+
updatedAt: serverTimestamp23()
|
|
11833
12173
|
};
|
|
11834
12174
|
await setDoc19(eventRef, newEvent);
|
|
11835
12175
|
return {
|
|
@@ -11846,10 +12186,10 @@ async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId,
|
|
|
11846
12186
|
);
|
|
11847
12187
|
const updates = {
|
|
11848
12188
|
...updateData,
|
|
11849
|
-
updatedAt:
|
|
12189
|
+
updatedAt: serverTimestamp23()
|
|
11850
12190
|
};
|
|
11851
|
-
await
|
|
11852
|
-
const updatedDoc = await
|
|
12191
|
+
await updateDoc24(eventRef, updates);
|
|
12192
|
+
const updatedDoc = await getDoc27(eventRef);
|
|
11853
12193
|
if (!updatedDoc.exists()) {
|
|
11854
12194
|
throw new Error("Event not found after update");
|
|
11855
12195
|
}
|
|
@@ -11909,17 +12249,17 @@ async function updateAppointmentUtil2(db, clinicId, practitionerId, patientId, e
|
|
|
11909
12249
|
// src/services/calendar/utils/calendar-event.utils.ts
|
|
11910
12250
|
import {
|
|
11911
12251
|
collection as collection23,
|
|
11912
|
-
doc as
|
|
11913
|
-
getDoc as
|
|
12252
|
+
doc as doc27,
|
|
12253
|
+
getDoc as getDoc28,
|
|
11914
12254
|
getDocs as getDocs23,
|
|
11915
12255
|
setDoc as setDoc20,
|
|
11916
|
-
updateDoc as
|
|
12256
|
+
updateDoc as updateDoc25,
|
|
11917
12257
|
deleteDoc as deleteDoc13,
|
|
11918
12258
|
query as query23,
|
|
11919
12259
|
where as where23,
|
|
11920
12260
|
orderBy as orderBy11,
|
|
11921
12261
|
Timestamp as Timestamp23,
|
|
11922
|
-
serverTimestamp as
|
|
12262
|
+
serverTimestamp as serverTimestamp24
|
|
11923
12263
|
} from "firebase/firestore";
|
|
11924
12264
|
async function searchCalendarEventsUtil(db, params) {
|
|
11925
12265
|
const { searchLocation, entityId, ...filters } = params;
|
|
@@ -12004,7 +12344,7 @@ async function searchCalendarEventsUtil(db, params) {
|
|
|
12004
12344
|
const finalQuery = query23(collectionRef, ...constraints);
|
|
12005
12345
|
const querySnapshot = await getDocs23(finalQuery);
|
|
12006
12346
|
const events = querySnapshot.docs.map(
|
|
12007
|
-
(
|
|
12347
|
+
(doc44) => ({ id: doc44.id, ...doc44.data() })
|
|
12008
12348
|
);
|
|
12009
12349
|
return events;
|
|
12010
12350
|
} catch (error) {
|
|
@@ -12016,15 +12356,15 @@ async function searchCalendarEventsUtil(db, params) {
|
|
|
12016
12356
|
// src/services/calendar/utils/synced-calendar.utils.ts
|
|
12017
12357
|
import {
|
|
12018
12358
|
collection as collection24,
|
|
12019
|
-
getDoc as
|
|
12359
|
+
getDoc as getDoc29,
|
|
12020
12360
|
getDocs as getDocs24,
|
|
12021
12361
|
setDoc as setDoc21,
|
|
12022
|
-
updateDoc as
|
|
12362
|
+
updateDoc as updateDoc26,
|
|
12023
12363
|
deleteDoc as deleteDoc14,
|
|
12024
12364
|
query as query24,
|
|
12025
12365
|
orderBy as orderBy12,
|
|
12026
12366
|
Timestamp as Timestamp24,
|
|
12027
|
-
serverTimestamp as
|
|
12367
|
+
serverTimestamp as serverTimestamp25
|
|
12028
12368
|
} from "firebase/firestore";
|
|
12029
12369
|
async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendarData, generateId2) {
|
|
12030
12370
|
const calendarId = generateId2();
|
|
@@ -12036,8 +12376,8 @@ async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendar
|
|
|
12036
12376
|
const newCalendar = {
|
|
12037
12377
|
id: calendarId,
|
|
12038
12378
|
...calendarData,
|
|
12039
|
-
createdAt:
|
|
12040
|
-
updatedAt:
|
|
12379
|
+
createdAt: serverTimestamp25(),
|
|
12380
|
+
updatedAt: serverTimestamp25()
|
|
12041
12381
|
};
|
|
12042
12382
|
await setDoc21(calendarRef, newCalendar);
|
|
12043
12383
|
return {
|
|
@@ -12052,8 +12392,8 @@ async function createPatientSyncedCalendarUtil(db, patientId, calendarData, gene
|
|
|
12052
12392
|
const newCalendar = {
|
|
12053
12393
|
id: calendarId,
|
|
12054
12394
|
...calendarData,
|
|
12055
|
-
createdAt:
|
|
12056
|
-
updatedAt:
|
|
12395
|
+
createdAt: serverTimestamp25(),
|
|
12396
|
+
updatedAt: serverTimestamp25()
|
|
12057
12397
|
};
|
|
12058
12398
|
await setDoc21(calendarRef, newCalendar);
|
|
12059
12399
|
return {
|
|
@@ -12068,8 +12408,8 @@ async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, genera
|
|
|
12068
12408
|
const newCalendar = {
|
|
12069
12409
|
id: calendarId,
|
|
12070
12410
|
...calendarData,
|
|
12071
|
-
createdAt:
|
|
12072
|
-
updatedAt:
|
|
12411
|
+
createdAt: serverTimestamp25(),
|
|
12412
|
+
updatedAt: serverTimestamp25()
|
|
12073
12413
|
};
|
|
12074
12414
|
await setDoc21(calendarRef, newCalendar);
|
|
12075
12415
|
return {
|
|
@@ -12084,7 +12424,7 @@ async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId)
|
|
|
12084
12424
|
practitionerId,
|
|
12085
12425
|
calendarId
|
|
12086
12426
|
);
|
|
12087
|
-
const calendarDoc = await
|
|
12427
|
+
const calendarDoc = await getDoc29(calendarRef);
|
|
12088
12428
|
if (!calendarDoc.exists()) {
|
|
12089
12429
|
return null;
|
|
12090
12430
|
}
|
|
@@ -12097,11 +12437,11 @@ async function getPractitionerSyncedCalendarsUtil(db, practitionerId) {
|
|
|
12097
12437
|
);
|
|
12098
12438
|
const q = query24(calendarsRef, orderBy12("createdAt", "desc"));
|
|
12099
12439
|
const querySnapshot = await getDocs24(q);
|
|
12100
|
-
return querySnapshot.docs.map((
|
|
12440
|
+
return querySnapshot.docs.map((doc44) => doc44.data());
|
|
12101
12441
|
}
|
|
12102
12442
|
async function getPatientSyncedCalendarUtil(db, patientId, calendarId) {
|
|
12103
12443
|
const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
|
|
12104
|
-
const calendarDoc = await
|
|
12444
|
+
const calendarDoc = await getDoc29(calendarRef);
|
|
12105
12445
|
if (!calendarDoc.exists()) {
|
|
12106
12446
|
return null;
|
|
12107
12447
|
}
|
|
@@ -12114,11 +12454,11 @@ async function getPatientSyncedCalendarsUtil(db, patientId) {
|
|
|
12114
12454
|
);
|
|
12115
12455
|
const q = query24(calendarsRef, orderBy12("createdAt", "desc"));
|
|
12116
12456
|
const querySnapshot = await getDocs24(q);
|
|
12117
|
-
return querySnapshot.docs.map((
|
|
12457
|
+
return querySnapshot.docs.map((doc44) => doc44.data());
|
|
12118
12458
|
}
|
|
12119
12459
|
async function getClinicSyncedCalendarUtil(db, clinicId, calendarId) {
|
|
12120
12460
|
const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
|
|
12121
|
-
const calendarDoc = await
|
|
12461
|
+
const calendarDoc = await getDoc29(calendarRef);
|
|
12122
12462
|
if (!calendarDoc.exists()) {
|
|
12123
12463
|
return null;
|
|
12124
12464
|
}
|
|
@@ -12131,7 +12471,7 @@ async function getClinicSyncedCalendarsUtil(db, clinicId) {
|
|
|
12131
12471
|
);
|
|
12132
12472
|
const q = query24(calendarsRef, orderBy12("createdAt", "desc"));
|
|
12133
12473
|
const querySnapshot = await getDocs24(q);
|
|
12134
|
-
return querySnapshot.docs.map((
|
|
12474
|
+
return querySnapshot.docs.map((doc44) => doc44.data());
|
|
12135
12475
|
}
|
|
12136
12476
|
async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendarId, updateData) {
|
|
12137
12477
|
const calendarRef = getPractitionerSyncedCalendarDocRef(
|
|
@@ -12141,10 +12481,10 @@ async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendar
|
|
|
12141
12481
|
);
|
|
12142
12482
|
const updates = {
|
|
12143
12483
|
...updateData,
|
|
12144
|
-
updatedAt:
|
|
12484
|
+
updatedAt: serverTimestamp25()
|
|
12145
12485
|
};
|
|
12146
|
-
await
|
|
12147
|
-
const updatedDoc = await
|
|
12486
|
+
await updateDoc26(calendarRef, updates);
|
|
12487
|
+
const updatedDoc = await getDoc29(calendarRef);
|
|
12148
12488
|
if (!updatedDoc.exists()) {
|
|
12149
12489
|
throw new Error("Synced calendar not found after update");
|
|
12150
12490
|
}
|
|
@@ -12154,10 +12494,10 @@ async function updatePatientSyncedCalendarUtil(db, patientId, calendarId, update
|
|
|
12154
12494
|
const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
|
|
12155
12495
|
const updates = {
|
|
12156
12496
|
...updateData,
|
|
12157
|
-
updatedAt:
|
|
12497
|
+
updatedAt: serverTimestamp25()
|
|
12158
12498
|
};
|
|
12159
|
-
await
|
|
12160
|
-
const updatedDoc = await
|
|
12499
|
+
await updateDoc26(calendarRef, updates);
|
|
12500
|
+
const updatedDoc = await getDoc29(calendarRef);
|
|
12161
12501
|
if (!updatedDoc.exists()) {
|
|
12162
12502
|
throw new Error("Synced calendar not found after update");
|
|
12163
12503
|
}
|
|
@@ -12167,10 +12507,10 @@ async function updateClinicSyncedCalendarUtil(db, clinicId, calendarId, updateDa
|
|
|
12167
12507
|
const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
|
|
12168
12508
|
const updates = {
|
|
12169
12509
|
...updateData,
|
|
12170
|
-
updatedAt:
|
|
12510
|
+
updatedAt: serverTimestamp25()
|
|
12171
12511
|
};
|
|
12172
|
-
await
|
|
12173
|
-
const updatedDoc = await
|
|
12512
|
+
await updateDoc26(calendarRef, updates);
|
|
12513
|
+
const updatedDoc = await getDoc29(calendarRef);
|
|
12174
12514
|
if (!updatedDoc.exists()) {
|
|
12175
12515
|
throw new Error("Synced calendar not found after update");
|
|
12176
12516
|
}
|
|
@@ -13379,7 +13719,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
13379
13719
|
async createDoctorBlockingEvent(doctorId, eventData) {
|
|
13380
13720
|
try {
|
|
13381
13721
|
const eventId = this.generateId();
|
|
13382
|
-
const eventRef =
|
|
13722
|
+
const eventRef = doc29(
|
|
13383
13723
|
this.db,
|
|
13384
13724
|
PRACTITIONERS_COLLECTION,
|
|
13385
13725
|
doctorId,
|
|
@@ -13389,8 +13729,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
13389
13729
|
const newEvent = {
|
|
13390
13730
|
id: eventId,
|
|
13391
13731
|
...eventData,
|
|
13392
|
-
createdAt:
|
|
13393
|
-
updatedAt:
|
|
13732
|
+
createdAt: serverTimestamp26(),
|
|
13733
|
+
updatedAt: serverTimestamp26()
|
|
13394
13734
|
};
|
|
13395
13735
|
await setDoc22(eventRef, newEvent);
|
|
13396
13736
|
return {
|
|
@@ -13486,9 +13826,9 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
13486
13826
|
where25("eventTime.start", "<=", Timestamp26.fromDate(endDate))
|
|
13487
13827
|
);
|
|
13488
13828
|
const eventsSnapshot = await getDocs25(q);
|
|
13489
|
-
const events = eventsSnapshot.docs.map((
|
|
13490
|
-
id:
|
|
13491
|
-
...
|
|
13829
|
+
const events = eventsSnapshot.docs.map((doc44) => ({
|
|
13830
|
+
id: doc44.id,
|
|
13831
|
+
...doc44.data()
|
|
13492
13832
|
}));
|
|
13493
13833
|
const calendars = await this.syncedCalendarsService.getPractitionerSyncedCalendars(
|
|
13494
13834
|
doctorId
|
|
@@ -13592,21 +13932,21 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
13592
13932
|
const endTime = new Date(
|
|
13593
13933
|
externalEvent.end.dateTime || externalEvent.end.date
|
|
13594
13934
|
);
|
|
13595
|
-
const eventRef =
|
|
13935
|
+
const eventRef = doc29(
|
|
13596
13936
|
this.db,
|
|
13597
13937
|
PRACTITIONERS_COLLECTION,
|
|
13598
13938
|
doctorId,
|
|
13599
13939
|
CALENDAR_COLLECTION,
|
|
13600
13940
|
eventId
|
|
13601
13941
|
);
|
|
13602
|
-
await
|
|
13942
|
+
await updateDoc27(eventRef, {
|
|
13603
13943
|
eventName: externalEvent.summary || "External Event",
|
|
13604
13944
|
eventTime: {
|
|
13605
13945
|
start: Timestamp26.fromDate(startTime),
|
|
13606
13946
|
end: Timestamp26.fromDate(endTime)
|
|
13607
13947
|
},
|
|
13608
13948
|
description: externalEvent.description || "",
|
|
13609
|
-
updatedAt:
|
|
13949
|
+
updatedAt: serverTimestamp26()
|
|
13610
13950
|
});
|
|
13611
13951
|
console.log(`Updated local event ${eventId} from external event`);
|
|
13612
13952
|
} catch (error) {
|
|
@@ -13624,16 +13964,16 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
13624
13964
|
*/
|
|
13625
13965
|
async updateEventStatus(doctorId, eventId, status) {
|
|
13626
13966
|
try {
|
|
13627
|
-
const eventRef =
|
|
13967
|
+
const eventRef = doc29(
|
|
13628
13968
|
this.db,
|
|
13629
13969
|
PRACTITIONERS_COLLECTION,
|
|
13630
13970
|
doctorId,
|
|
13631
13971
|
CALENDAR_COLLECTION,
|
|
13632
13972
|
eventId
|
|
13633
13973
|
);
|
|
13634
|
-
await
|
|
13974
|
+
await updateDoc27(eventRef, {
|
|
13635
13975
|
status,
|
|
13636
|
-
updatedAt:
|
|
13976
|
+
updatedAt: serverTimestamp26()
|
|
13637
13977
|
});
|
|
13638
13978
|
console.log(`Updated event ${eventId} status to ${status}`);
|
|
13639
13979
|
} catch (error) {
|
|
@@ -13790,8 +14130,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
13790
14130
|
const startDate = eventTime.start.toDate();
|
|
13791
14131
|
const startTime = startDate;
|
|
13792
14132
|
const endTime = eventTime.end.toDate();
|
|
13793
|
-
const practitionerRef =
|
|
13794
|
-
const practitionerDoc = await
|
|
14133
|
+
const practitionerRef = doc29(this.db, PRACTITIONERS_COLLECTION, doctorId);
|
|
14134
|
+
const practitionerDoc = await getDoc30(practitionerRef);
|
|
13795
14135
|
if (!practitionerDoc.exists()) {
|
|
13796
14136
|
throw new Error(`Doctor with ID ${doctorId} not found`);
|
|
13797
14137
|
}
|
|
@@ -13849,8 +14189,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
13849
14189
|
*/
|
|
13850
14190
|
async updateAppointmentStatus(appointmentId, clinicId, status) {
|
|
13851
14191
|
const baseCollectionPath = `${CLINICS_COLLECTION}/${clinicId}/${CALENDAR_COLLECTION}`;
|
|
13852
|
-
const appointmentRef =
|
|
13853
|
-
const appointmentDoc = await
|
|
14192
|
+
const appointmentRef = doc29(this.db, baseCollectionPath, appointmentId);
|
|
14193
|
+
const appointmentDoc = await getDoc30(appointmentRef);
|
|
13854
14194
|
if (!appointmentDoc.exists()) {
|
|
13855
14195
|
throw new Error(`Appointment with ID ${appointmentId} not found`);
|
|
13856
14196
|
}
|
|
@@ -14009,8 +14349,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
14009
14349
|
async updateEventWithSyncId(entityId, entityType, eventId, syncEvent) {
|
|
14010
14350
|
try {
|
|
14011
14351
|
const collectionPath = entityType === "doctor" ? `${PRACTITIONERS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}` : `${PATIENTS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
|
|
14012
|
-
const eventRef =
|
|
14013
|
-
const eventDoc = await
|
|
14352
|
+
const eventRef = doc29(this.db, collectionPath, eventId);
|
|
14353
|
+
const eventDoc = await getDoc30(eventRef);
|
|
14014
14354
|
if (eventDoc.exists()) {
|
|
14015
14355
|
const event = eventDoc.data();
|
|
14016
14356
|
const syncIds = [...event.syncedCalendarEventId || []];
|
|
@@ -14022,9 +14362,9 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
14022
14362
|
} else {
|
|
14023
14363
|
syncIds.push(syncEvent);
|
|
14024
14364
|
}
|
|
14025
|
-
await
|
|
14365
|
+
await updateDoc27(eventRef, {
|
|
14026
14366
|
syncedCalendarEventId: syncIds,
|
|
14027
|
-
updatedAt:
|
|
14367
|
+
updatedAt: serverTimestamp26()
|
|
14028
14368
|
});
|
|
14029
14369
|
console.log(
|
|
14030
14370
|
`Updated event ${eventId} with sync ID ${syncEvent.eventId}`
|
|
@@ -14048,8 +14388,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
14048
14388
|
* @returns Working hours for the clinic
|
|
14049
14389
|
*/
|
|
14050
14390
|
async getClinicWorkingHours(clinicId, date) {
|
|
14051
|
-
const clinicRef =
|
|
14052
|
-
const clinicDoc = await
|
|
14391
|
+
const clinicRef = doc29(this.db, CLINICS_COLLECTION, clinicId);
|
|
14392
|
+
const clinicDoc = await getDoc30(clinicRef);
|
|
14053
14393
|
if (!clinicDoc.exists()) {
|
|
14054
14394
|
throw new Error(`Clinic with ID ${clinicId} not found`);
|
|
14055
14395
|
}
|
|
@@ -14077,8 +14417,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
14077
14417
|
* @returns Doctor's schedule
|
|
14078
14418
|
*/
|
|
14079
14419
|
async getDoctorSchedule(doctorId, date) {
|
|
14080
|
-
const practitionerRef =
|
|
14081
|
-
const practitionerDoc = await
|
|
14420
|
+
const practitionerRef = doc29(this.db, PRACTITIONERS_COLLECTION, doctorId);
|
|
14421
|
+
const practitionerDoc = await getDoc30(practitionerRef);
|
|
14082
14422
|
if (!practitionerDoc.exists()) {
|
|
14083
14423
|
throw new Error(`Doctor with ID ${doctorId} not found`);
|
|
14084
14424
|
}
|
|
@@ -14122,7 +14462,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
14122
14462
|
])
|
|
14123
14463
|
);
|
|
14124
14464
|
const querySnapshot = await getDocs25(q);
|
|
14125
|
-
return querySnapshot.docs.map((
|
|
14465
|
+
return querySnapshot.docs.map((doc44) => doc44.data());
|
|
14126
14466
|
}
|
|
14127
14467
|
/**
|
|
14128
14468
|
* Calculates available time slots based on working hours, schedule and existing appointments
|
|
@@ -14179,11 +14519,11 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
14179
14519
|
var _a;
|
|
14180
14520
|
try {
|
|
14181
14521
|
const [clinicDoc, practitionerDoc, patientDoc, patientSensitiveInfoDoc] = await Promise.all([
|
|
14182
|
-
|
|
14183
|
-
|
|
14184
|
-
|
|
14185
|
-
|
|
14186
|
-
|
|
14522
|
+
getDoc30(doc29(this.db, CLINICS_COLLECTION, clinicId)),
|
|
14523
|
+
getDoc30(doc29(this.db, PRACTITIONERS_COLLECTION, doctorId)),
|
|
14524
|
+
getDoc30(doc29(this.db, PATIENTS_COLLECTION, patientId)),
|
|
14525
|
+
getDoc30(
|
|
14526
|
+
doc29(
|
|
14187
14527
|
this.db,
|
|
14188
14528
|
PATIENTS_COLLECTION,
|
|
14189
14529
|
patientId,
|
|
@@ -14247,8 +14587,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
14247
14587
|
};
|
|
14248
14588
|
|
|
14249
14589
|
// src/services/calendar/calendar.v3.service.ts
|
|
14250
|
-
import { Timestamp as Timestamp27, serverTimestamp as
|
|
14251
|
-
import { doc as
|
|
14590
|
+
import { Timestamp as Timestamp27, serverTimestamp as serverTimestamp27 } from "firebase/firestore";
|
|
14591
|
+
import { doc as doc30, getDoc as getDoc31, setDoc as setDoc23, updateDoc as updateDoc28, deleteDoc as deleteDoc15 } from "firebase/firestore";
|
|
14252
14592
|
var CalendarServiceV3 = class extends BaseService {
|
|
14253
14593
|
/**
|
|
14254
14594
|
* Creates a new CalendarServiceV3 instance
|
|
@@ -14272,7 +14612,7 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
14272
14612
|
params.entityType,
|
|
14273
14613
|
params.entityId
|
|
14274
14614
|
);
|
|
14275
|
-
const eventRef =
|
|
14615
|
+
const eventRef = doc30(this.db, collectionPath, eventId);
|
|
14276
14616
|
const eventData = {
|
|
14277
14617
|
id: eventId,
|
|
14278
14618
|
eventName: params.eventName,
|
|
@@ -14282,8 +14622,8 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
14282
14622
|
status: "confirmed" /* CONFIRMED */,
|
|
14283
14623
|
// Blocking events are always confirmed
|
|
14284
14624
|
syncStatus: "internal" /* INTERNAL */,
|
|
14285
|
-
createdAt:
|
|
14286
|
-
updatedAt:
|
|
14625
|
+
createdAt: serverTimestamp27(),
|
|
14626
|
+
updatedAt: serverTimestamp27()
|
|
14287
14627
|
};
|
|
14288
14628
|
if (params.entityType === "practitioner") {
|
|
14289
14629
|
eventData.practitionerProfileId = params.entityId;
|
|
@@ -14307,13 +14647,13 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
14307
14647
|
params.entityType,
|
|
14308
14648
|
params.entityId
|
|
14309
14649
|
);
|
|
14310
|
-
const eventRef =
|
|
14311
|
-
const eventDoc = await
|
|
14650
|
+
const eventRef = doc30(this.db, collectionPath, params.eventId);
|
|
14651
|
+
const eventDoc = await getDoc31(eventRef);
|
|
14312
14652
|
if (!eventDoc.exists()) {
|
|
14313
14653
|
throw new Error(`Blocking event with ID ${params.eventId} not found`);
|
|
14314
14654
|
}
|
|
14315
14655
|
const updateData = {
|
|
14316
|
-
updatedAt:
|
|
14656
|
+
updatedAt: serverTimestamp27()
|
|
14317
14657
|
};
|
|
14318
14658
|
if (params.eventName !== void 0) {
|
|
14319
14659
|
updateData.eventName = params.eventName;
|
|
@@ -14327,8 +14667,8 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
14327
14667
|
if (params.status !== void 0) {
|
|
14328
14668
|
updateData.status = params.status;
|
|
14329
14669
|
}
|
|
14330
|
-
await
|
|
14331
|
-
const updatedEventDoc = await
|
|
14670
|
+
await updateDoc28(eventRef, updateData);
|
|
14671
|
+
const updatedEventDoc = await getDoc31(eventRef);
|
|
14332
14672
|
return updatedEventDoc.data();
|
|
14333
14673
|
}
|
|
14334
14674
|
/**
|
|
@@ -14339,8 +14679,8 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
14339
14679
|
*/
|
|
14340
14680
|
async deleteBlockingEvent(entityType, entityId, eventId) {
|
|
14341
14681
|
const collectionPath = this.getEntityCalendarPath(entityType, entityId);
|
|
14342
|
-
const eventRef =
|
|
14343
|
-
const eventDoc = await
|
|
14682
|
+
const eventRef = doc30(this.db, collectionPath, eventId);
|
|
14683
|
+
const eventDoc = await getDoc31(eventRef);
|
|
14344
14684
|
if (!eventDoc.exists()) {
|
|
14345
14685
|
throw new Error(`Blocking event with ID ${eventId} not found`);
|
|
14346
14686
|
}
|
|
@@ -14355,8 +14695,8 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
14355
14695
|
*/
|
|
14356
14696
|
async getBlockingEvent(entityType, entityId, eventId) {
|
|
14357
14697
|
const collectionPath = this.getEntityCalendarPath(entityType, entityId);
|
|
14358
|
-
const eventRef =
|
|
14359
|
-
const eventDoc = await
|
|
14698
|
+
const eventRef = doc30(this.db, collectionPath, eventId);
|
|
14699
|
+
const eventDoc = await getDoc31(eventRef);
|
|
14360
14700
|
if (!eventDoc.exists()) {
|
|
14361
14701
|
return null;
|
|
14362
14702
|
}
|
|
@@ -14551,16 +14891,16 @@ var ExternalCalendarService = class extends BaseService {
|
|
|
14551
14891
|
// src/services/clinic/practitioner-invite.service.ts
|
|
14552
14892
|
import {
|
|
14553
14893
|
collection as collection26,
|
|
14554
|
-
doc as
|
|
14555
|
-
getDoc as
|
|
14894
|
+
doc as doc31,
|
|
14895
|
+
getDoc as getDoc32,
|
|
14556
14896
|
getDocs as getDocs26,
|
|
14557
14897
|
query as query26,
|
|
14558
14898
|
where as where26,
|
|
14559
|
-
updateDoc as
|
|
14899
|
+
updateDoc as updateDoc29,
|
|
14560
14900
|
setDoc as setDoc24,
|
|
14561
14901
|
deleteDoc as deleteDoc16,
|
|
14562
14902
|
Timestamp as Timestamp28,
|
|
14563
|
-
serverTimestamp as
|
|
14903
|
+
serverTimestamp as serverTimestamp28,
|
|
14564
14904
|
orderBy as orderBy13,
|
|
14565
14905
|
limit as limit12
|
|
14566
14906
|
} from "firebase/firestore";
|
|
@@ -14636,7 +14976,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
14636
14976
|
rejectedAt: null,
|
|
14637
14977
|
cancelledAt: null
|
|
14638
14978
|
};
|
|
14639
|
-
const docRef =
|
|
14979
|
+
const docRef = doc31(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
14640
14980
|
await setDoc24(docRef, invite);
|
|
14641
14981
|
return invite;
|
|
14642
14982
|
} catch (error) {
|
|
@@ -14667,7 +15007,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
14667
15007
|
...constraints
|
|
14668
15008
|
);
|
|
14669
15009
|
const querySnapshot = await getDocs26(q);
|
|
14670
|
-
return querySnapshot.docs.map((
|
|
15010
|
+
return querySnapshot.docs.map((doc44) => doc44.data());
|
|
14671
15011
|
} catch (error) {
|
|
14672
15012
|
console.error(
|
|
14673
15013
|
"[PractitionerInviteService] Error getting doctor invites:",
|
|
@@ -14696,7 +15036,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
14696
15036
|
...constraints
|
|
14697
15037
|
);
|
|
14698
15038
|
const querySnapshot = await getDocs26(q);
|
|
14699
|
-
return querySnapshot.docs.map((
|
|
15039
|
+
return querySnapshot.docs.map((doc44) => doc44.data());
|
|
14700
15040
|
} catch (error) {
|
|
14701
15041
|
console.error(
|
|
14702
15042
|
"[PractitionerInviteService] Error getting clinic invites:",
|
|
@@ -14722,10 +15062,10 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
14722
15062
|
const updateData = {
|
|
14723
15063
|
status: "accepted" /* ACCEPTED */,
|
|
14724
15064
|
acceptedAt: Timestamp28.now(),
|
|
14725
|
-
updatedAt:
|
|
15065
|
+
updatedAt: serverTimestamp28()
|
|
14726
15066
|
};
|
|
14727
|
-
const docRef =
|
|
14728
|
-
await
|
|
15067
|
+
const docRef = doc31(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
15068
|
+
await updateDoc29(docRef, updateData);
|
|
14729
15069
|
return await this.getInviteById(inviteId);
|
|
14730
15070
|
} catch (error) {
|
|
14731
15071
|
console.error(
|
|
@@ -14754,10 +15094,10 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
14754
15094
|
status: "rejected" /* REJECTED */,
|
|
14755
15095
|
rejectionReason: rejectionReason || null,
|
|
14756
15096
|
rejectedAt: Timestamp28.now(),
|
|
14757
|
-
updatedAt:
|
|
15097
|
+
updatedAt: serverTimestamp28()
|
|
14758
15098
|
};
|
|
14759
|
-
const docRef =
|
|
14760
|
-
await
|
|
15099
|
+
const docRef = doc31(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
15100
|
+
await updateDoc29(docRef, updateData);
|
|
14761
15101
|
return await this.getInviteById(inviteId);
|
|
14762
15102
|
} catch (error) {
|
|
14763
15103
|
console.error(
|
|
@@ -14786,10 +15126,10 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
14786
15126
|
status: "cancelled" /* CANCELLED */,
|
|
14787
15127
|
cancelReason: cancelReason || null,
|
|
14788
15128
|
cancelledAt: Timestamp28.now(),
|
|
14789
|
-
updatedAt:
|
|
15129
|
+
updatedAt: serverTimestamp28()
|
|
14790
15130
|
};
|
|
14791
|
-
const docRef =
|
|
14792
|
-
await
|
|
15131
|
+
const docRef = doc31(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
15132
|
+
await updateDoc29(docRef, updateData);
|
|
14793
15133
|
return await this.getInviteById(inviteId);
|
|
14794
15134
|
} catch (error) {
|
|
14795
15135
|
console.error(
|
|
@@ -14806,8 +15146,8 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
14806
15146
|
*/
|
|
14807
15147
|
async getInviteById(inviteId) {
|
|
14808
15148
|
try {
|
|
14809
|
-
const docRef =
|
|
14810
|
-
const docSnap = await
|
|
15149
|
+
const docRef = doc31(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
15150
|
+
const docSnap = await getDoc32(docRef);
|
|
14811
15151
|
if (docSnap.exists()) {
|
|
14812
15152
|
return docSnap.data();
|
|
14813
15153
|
}
|
|
@@ -14852,7 +15192,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
14852
15192
|
);
|
|
14853
15193
|
const querySnapshot = await getDocs26(q);
|
|
14854
15194
|
let invites = querySnapshot.docs.map(
|
|
14855
|
-
(
|
|
15195
|
+
(doc44) => doc44.data()
|
|
14856
15196
|
);
|
|
14857
15197
|
if (filters.fromDate) {
|
|
14858
15198
|
invites = invites.filter(
|
|
@@ -14879,7 +15219,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
14879
15219
|
*/
|
|
14880
15220
|
async deleteInvite(inviteId) {
|
|
14881
15221
|
try {
|
|
14882
|
-
const docRef =
|
|
15222
|
+
const docRef = doc31(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
14883
15223
|
await deleteDoc16(docRef);
|
|
14884
15224
|
} catch (error) {
|
|
14885
15225
|
console.error(
|
|
@@ -14897,8 +15237,8 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
14897
15237
|
*/
|
|
14898
15238
|
async getPractitionerById(practitionerId) {
|
|
14899
15239
|
try {
|
|
14900
|
-
const docRef =
|
|
14901
|
-
const docSnap = await
|
|
15240
|
+
const docRef = doc31(this.db, PRACTITIONERS_COLLECTION, practitionerId);
|
|
15241
|
+
const docSnap = await getDoc32(docRef);
|
|
14902
15242
|
return docSnap.exists() ? docSnap.data() : null;
|
|
14903
15243
|
} catch (error) {
|
|
14904
15244
|
console.error(
|
|
@@ -14915,8 +15255,8 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
14915
15255
|
*/
|
|
14916
15256
|
async getClinicById(clinicId) {
|
|
14917
15257
|
try {
|
|
14918
|
-
const docRef =
|
|
14919
|
-
const docSnap = await
|
|
15258
|
+
const docRef = doc31(this.db, CLINICS_COLLECTION, clinicId);
|
|
15259
|
+
const docSnap = await getDoc32(docRef);
|
|
14920
15260
|
return docSnap.exists() ? docSnap.data() : null;
|
|
14921
15261
|
} catch (error) {
|
|
14922
15262
|
console.error("[PractitionerInviteService] Error getting clinic:", error);
|
|
@@ -14956,11 +15296,11 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
14956
15296
|
// src/services/documentation-templates/documentation-template.service.ts
|
|
14957
15297
|
import {
|
|
14958
15298
|
collection as collection27,
|
|
14959
|
-
doc as
|
|
14960
|
-
getDoc as
|
|
15299
|
+
doc as doc32,
|
|
15300
|
+
getDoc as getDoc33,
|
|
14961
15301
|
getDocs as getDocs27,
|
|
14962
15302
|
setDoc as setDoc25,
|
|
14963
|
-
updateDoc as
|
|
15303
|
+
updateDoc as updateDoc30,
|
|
14964
15304
|
deleteDoc as deleteDoc17,
|
|
14965
15305
|
query as query27,
|
|
14966
15306
|
where as where27,
|
|
@@ -15006,7 +15346,7 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15006
15346
|
isRequired: validatedData.isRequired || false,
|
|
15007
15347
|
sortingOrder: validatedData.sortingOrder || 0
|
|
15008
15348
|
};
|
|
15009
|
-
const docRef =
|
|
15349
|
+
const docRef = doc32(this.collectionRef, templateId);
|
|
15010
15350
|
await setDoc25(docRef, template);
|
|
15011
15351
|
return template;
|
|
15012
15352
|
}
|
|
@@ -15017,8 +15357,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15017
15357
|
* @returns The template or null if not found
|
|
15018
15358
|
*/
|
|
15019
15359
|
async getTemplateById(templateId, version) {
|
|
15020
|
-
const docRef =
|
|
15021
|
-
const docSnap = await
|
|
15360
|
+
const docRef = doc32(this.collectionRef, templateId);
|
|
15361
|
+
const docSnap = await getDoc33(docRef);
|
|
15022
15362
|
if (!docSnap.exists()) {
|
|
15023
15363
|
return null;
|
|
15024
15364
|
}
|
|
@@ -15060,7 +15400,7 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15060
15400
|
this.db,
|
|
15061
15401
|
`${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
|
|
15062
15402
|
);
|
|
15063
|
-
const versionDocRef =
|
|
15403
|
+
const versionDocRef = doc32(
|
|
15064
15404
|
versionsCollectionRef,
|
|
15065
15405
|
template.version.toString()
|
|
15066
15406
|
);
|
|
@@ -15088,9 +15428,9 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15088
15428
|
updatePayload.isUserForm = (_a = validatedData.isUserForm) != null ? _a : false;
|
|
15089
15429
|
updatePayload.isRequired = (_b = validatedData.isRequired) != null ? _b : false;
|
|
15090
15430
|
updatePayload.sortingOrder = (_c = validatedData.sortingOrder) != null ? _c : 0;
|
|
15091
|
-
const docRef =
|
|
15431
|
+
const docRef = doc32(this.collectionRef, templateId);
|
|
15092
15432
|
console.log("Update payload", updatePayload);
|
|
15093
|
-
await
|
|
15433
|
+
await updateDoc30(docRef, updatePayload);
|
|
15094
15434
|
return { ...template, ...updatePayload };
|
|
15095
15435
|
}
|
|
15096
15436
|
/**
|
|
@@ -15100,11 +15440,11 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15100
15440
|
* @returns The template version or null if not found
|
|
15101
15441
|
*/
|
|
15102
15442
|
async getTemplateVersion(templateId, versionNumber) {
|
|
15103
|
-
const versionDocRef =
|
|
15443
|
+
const versionDocRef = doc32(
|
|
15104
15444
|
this.db,
|
|
15105
15445
|
`${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions/${versionNumber}`
|
|
15106
15446
|
);
|
|
15107
|
-
const versionDocSnap = await
|
|
15447
|
+
const versionDocSnap = await getDoc33(versionDocRef);
|
|
15108
15448
|
if (!versionDocSnap.exists()) {
|
|
15109
15449
|
return null;
|
|
15110
15450
|
}
|
|
@@ -15123,8 +15463,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15123
15463
|
const q = query27(versionsCollectionRef, orderBy14("version", "desc"));
|
|
15124
15464
|
const querySnapshot = await getDocs27(q);
|
|
15125
15465
|
const versions = [];
|
|
15126
|
-
querySnapshot.forEach((
|
|
15127
|
-
versions.push(
|
|
15466
|
+
querySnapshot.forEach((doc44) => {
|
|
15467
|
+
versions.push(doc44.data());
|
|
15128
15468
|
});
|
|
15129
15469
|
return versions;
|
|
15130
15470
|
}
|
|
@@ -15133,7 +15473,7 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15133
15473
|
* @param templateId - ID of the template to delete
|
|
15134
15474
|
*/
|
|
15135
15475
|
async deleteTemplate(templateId) {
|
|
15136
|
-
const docRef =
|
|
15476
|
+
const docRef = doc32(this.collectionRef, templateId);
|
|
15137
15477
|
await deleteDoc17(docRef);
|
|
15138
15478
|
}
|
|
15139
15479
|
/**
|
|
@@ -15155,9 +15495,9 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15155
15495
|
const querySnapshot = await getDocs27(q);
|
|
15156
15496
|
const templates = [];
|
|
15157
15497
|
let lastVisible = null;
|
|
15158
|
-
querySnapshot.forEach((
|
|
15159
|
-
templates.push(
|
|
15160
|
-
lastVisible =
|
|
15498
|
+
querySnapshot.forEach((doc44) => {
|
|
15499
|
+
templates.push(doc44.data());
|
|
15500
|
+
lastVisible = doc44;
|
|
15161
15501
|
});
|
|
15162
15502
|
return {
|
|
15163
15503
|
templates,
|
|
@@ -15199,9 +15539,9 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15199
15539
|
const querySnapshot = await getDocs27(q);
|
|
15200
15540
|
const templates = [];
|
|
15201
15541
|
let lastVisible = null;
|
|
15202
|
-
querySnapshot.forEach((
|
|
15203
|
-
templates.push(
|
|
15204
|
-
lastVisible =
|
|
15542
|
+
querySnapshot.forEach((doc44) => {
|
|
15543
|
+
templates.push(doc44.data());
|
|
15544
|
+
lastVisible = doc44;
|
|
15205
15545
|
});
|
|
15206
15546
|
return {
|
|
15207
15547
|
templates,
|
|
@@ -15241,8 +15581,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15241
15581
|
);
|
|
15242
15582
|
const querySnapshot = await getDocs27(q);
|
|
15243
15583
|
const templates = [];
|
|
15244
|
-
querySnapshot.forEach((
|
|
15245
|
-
templates.push(
|
|
15584
|
+
querySnapshot.forEach((doc44) => {
|
|
15585
|
+
templates.push(doc44.data());
|
|
15246
15586
|
});
|
|
15247
15587
|
return templates;
|
|
15248
15588
|
}
|
|
@@ -15267,9 +15607,9 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15267
15607
|
const querySnapshot = await getDocs27(q);
|
|
15268
15608
|
const templates = [];
|
|
15269
15609
|
let lastVisible = null;
|
|
15270
|
-
querySnapshot.forEach((
|
|
15271
|
-
templates.push(
|
|
15272
|
-
lastVisible =
|
|
15610
|
+
querySnapshot.forEach((doc44) => {
|
|
15611
|
+
templates.push(doc44.data());
|
|
15612
|
+
lastVisible = doc44;
|
|
15273
15613
|
});
|
|
15274
15614
|
return {
|
|
15275
15615
|
templates,
|
|
@@ -15296,9 +15636,9 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15296
15636
|
const querySnapshot = await getDocs27(q);
|
|
15297
15637
|
const templates = [];
|
|
15298
15638
|
let lastVisible = null;
|
|
15299
|
-
querySnapshot.forEach((
|
|
15300
|
-
templates.push(
|
|
15301
|
-
lastVisible =
|
|
15639
|
+
querySnapshot.forEach((doc44) => {
|
|
15640
|
+
templates.push(doc44.data());
|
|
15641
|
+
lastVisible = doc44;
|
|
15302
15642
|
});
|
|
15303
15643
|
return {
|
|
15304
15644
|
templates,
|
|
@@ -15324,8 +15664,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15324
15664
|
}
|
|
15325
15665
|
const querySnapshot = await getDocs27(q);
|
|
15326
15666
|
const templates = [];
|
|
15327
|
-
querySnapshot.forEach((
|
|
15328
|
-
templates.push(
|
|
15667
|
+
querySnapshot.forEach((doc44) => {
|
|
15668
|
+
templates.push(doc44.data());
|
|
15329
15669
|
});
|
|
15330
15670
|
return templates;
|
|
15331
15671
|
}
|
|
@@ -15334,11 +15674,11 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
15334
15674
|
// src/services/documentation-templates/filled-document.service.ts
|
|
15335
15675
|
import {
|
|
15336
15676
|
collection as collection28,
|
|
15337
|
-
doc as
|
|
15338
|
-
getDoc as
|
|
15677
|
+
doc as doc33,
|
|
15678
|
+
getDoc as getDoc34,
|
|
15339
15679
|
getDocs as getDocs28,
|
|
15340
15680
|
setDoc as setDoc26,
|
|
15341
|
-
updateDoc as
|
|
15681
|
+
updateDoc as updateDoc31,
|
|
15342
15682
|
query as query28,
|
|
15343
15683
|
orderBy as orderBy15,
|
|
15344
15684
|
limit as limit14,
|
|
@@ -15398,7 +15738,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
15398
15738
|
values: initialValues,
|
|
15399
15739
|
status: initialStatus
|
|
15400
15740
|
};
|
|
15401
|
-
const docRef =
|
|
15741
|
+
const docRef = doc33(
|
|
15402
15742
|
this.db,
|
|
15403
15743
|
APPOINTMENTS_COLLECTION,
|
|
15404
15744
|
// Replaced "appointments"
|
|
@@ -15418,7 +15758,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
15418
15758
|
*/
|
|
15419
15759
|
async getFilledDocumentFromAppointmentById(appointmentId, formId, isUserForm) {
|
|
15420
15760
|
const formSubcollection = this.getFormSubcollectionPath(isUserForm);
|
|
15421
|
-
const docRef =
|
|
15761
|
+
const docRef = doc33(
|
|
15422
15762
|
this.db,
|
|
15423
15763
|
APPOINTMENTS_COLLECTION,
|
|
15424
15764
|
// Replaced "appointments"
|
|
@@ -15426,7 +15766,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
15426
15766
|
formSubcollection,
|
|
15427
15767
|
formId
|
|
15428
15768
|
);
|
|
15429
|
-
const docSnap = await
|
|
15769
|
+
const docSnap = await getDoc34(docRef);
|
|
15430
15770
|
if (!docSnap.exists()) {
|
|
15431
15771
|
return null;
|
|
15432
15772
|
}
|
|
@@ -15443,7 +15783,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
15443
15783
|
*/
|
|
15444
15784
|
async updateFilledDocumentInAppointment(appointmentId, formId, isUserForm, values, status) {
|
|
15445
15785
|
const formSubcollection = this.getFormSubcollectionPath(isUserForm);
|
|
15446
|
-
const docRef =
|
|
15786
|
+
const docRef = doc33(
|
|
15447
15787
|
this.db,
|
|
15448
15788
|
APPOINTMENTS_COLLECTION,
|
|
15449
15789
|
// Replaced "appointments"
|
|
@@ -15475,7 +15815,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
15475
15815
|
}
|
|
15476
15816
|
if (Object.keys(updatePayload).length === 1 && "updatedAt" in updatePayload) {
|
|
15477
15817
|
}
|
|
15478
|
-
await
|
|
15818
|
+
await updateDoc31(docRef, updatePayload);
|
|
15479
15819
|
return { ...existingDoc, ...updatePayload };
|
|
15480
15820
|
}
|
|
15481
15821
|
/**
|
|
@@ -15531,9 +15871,9 @@ var FilledDocumentService = class extends BaseService {
|
|
|
15531
15871
|
const querySnapshot = await getDocs28(q);
|
|
15532
15872
|
const documents = [];
|
|
15533
15873
|
let lastVisible = null;
|
|
15534
|
-
querySnapshot.forEach((
|
|
15535
|
-
documents.push(
|
|
15536
|
-
lastVisible =
|
|
15874
|
+
querySnapshot.forEach((doc44) => {
|
|
15875
|
+
documents.push(doc44.data());
|
|
15876
|
+
lastVisible = doc44;
|
|
15537
15877
|
});
|
|
15538
15878
|
return {
|
|
15539
15879
|
documents,
|
|
@@ -15694,12 +16034,12 @@ var FilledDocumentService = class extends BaseService {
|
|
|
15694
16034
|
// src/services/notifications/notification.service.ts
|
|
15695
16035
|
import {
|
|
15696
16036
|
collection as collection29,
|
|
15697
|
-
doc as
|
|
15698
|
-
getDoc as
|
|
16037
|
+
doc as doc34,
|
|
16038
|
+
getDoc as getDoc35,
|
|
15699
16039
|
getDocs as getDocs29,
|
|
15700
16040
|
query as query29,
|
|
15701
16041
|
where as where29,
|
|
15702
|
-
updateDoc as
|
|
16042
|
+
updateDoc as updateDoc32,
|
|
15703
16043
|
deleteDoc as deleteDoc18,
|
|
15704
16044
|
orderBy as orderBy16,
|
|
15705
16045
|
Timestamp as Timestamp30,
|
|
@@ -15731,12 +16071,12 @@ var NotificationService = class extends BaseService {
|
|
|
15731
16071
|
* Dohvata notifikaciju po ID-u
|
|
15732
16072
|
*/
|
|
15733
16073
|
async getNotification(notificationId) {
|
|
15734
|
-
const notificationRef =
|
|
16074
|
+
const notificationRef = doc34(
|
|
15735
16075
|
this.db,
|
|
15736
16076
|
NOTIFICATIONS_COLLECTION,
|
|
15737
16077
|
notificationId
|
|
15738
16078
|
);
|
|
15739
|
-
const notificationDoc = await
|
|
16079
|
+
const notificationDoc = await getDoc35(notificationRef);
|
|
15740
16080
|
if (!notificationDoc.exists()) {
|
|
15741
16081
|
return null;
|
|
15742
16082
|
}
|
|
@@ -15755,9 +16095,9 @@ var NotificationService = class extends BaseService {
|
|
|
15755
16095
|
orderBy16("notificationTime", "desc")
|
|
15756
16096
|
);
|
|
15757
16097
|
const querySnapshot = await getDocs29(q);
|
|
15758
|
-
return querySnapshot.docs.map((
|
|
15759
|
-
id:
|
|
15760
|
-
...
|
|
16098
|
+
return querySnapshot.docs.map((doc44) => ({
|
|
16099
|
+
id: doc44.id,
|
|
16100
|
+
...doc44.data()
|
|
15761
16101
|
}));
|
|
15762
16102
|
}
|
|
15763
16103
|
/**
|
|
@@ -15771,21 +16111,21 @@ var NotificationService = class extends BaseService {
|
|
|
15771
16111
|
orderBy16("notificationTime", "desc")
|
|
15772
16112
|
);
|
|
15773
16113
|
const querySnapshot = await getDocs29(q);
|
|
15774
|
-
return querySnapshot.docs.map((
|
|
15775
|
-
id:
|
|
15776
|
-
...
|
|
16114
|
+
return querySnapshot.docs.map((doc44) => ({
|
|
16115
|
+
id: doc44.id,
|
|
16116
|
+
...doc44.data()
|
|
15777
16117
|
}));
|
|
15778
16118
|
}
|
|
15779
16119
|
/**
|
|
15780
16120
|
* Označava notifikaciju kao pročitanu
|
|
15781
16121
|
*/
|
|
15782
16122
|
async markAsRead(notificationId) {
|
|
15783
|
-
const notificationRef =
|
|
16123
|
+
const notificationRef = doc34(
|
|
15784
16124
|
this.db,
|
|
15785
16125
|
NOTIFICATIONS_COLLECTION,
|
|
15786
16126
|
notificationId
|
|
15787
16127
|
);
|
|
15788
|
-
await
|
|
16128
|
+
await updateDoc32(notificationRef, {
|
|
15789
16129
|
isRead: true,
|
|
15790
16130
|
updatedAt: Timestamp30.now()
|
|
15791
16131
|
});
|
|
@@ -15797,7 +16137,7 @@ var NotificationService = class extends BaseService {
|
|
|
15797
16137
|
const notifications = await this.getUnreadNotifications(userId);
|
|
15798
16138
|
const batch = writeBatch5(this.db);
|
|
15799
16139
|
notifications.forEach((notification) => {
|
|
15800
|
-
const notificationRef =
|
|
16140
|
+
const notificationRef = doc34(
|
|
15801
16141
|
this.db,
|
|
15802
16142
|
NOTIFICATIONS_COLLECTION,
|
|
15803
16143
|
notification.id
|
|
@@ -15813,12 +16153,12 @@ var NotificationService = class extends BaseService {
|
|
|
15813
16153
|
* Ažurira status notifikacije
|
|
15814
16154
|
*/
|
|
15815
16155
|
async updateNotificationStatus(notificationId, status) {
|
|
15816
|
-
const notificationRef =
|
|
16156
|
+
const notificationRef = doc34(
|
|
15817
16157
|
this.db,
|
|
15818
16158
|
NOTIFICATIONS_COLLECTION,
|
|
15819
16159
|
notificationId
|
|
15820
16160
|
);
|
|
15821
|
-
await
|
|
16161
|
+
await updateDoc32(notificationRef, {
|
|
15822
16162
|
status,
|
|
15823
16163
|
updatedAt: Timestamp30.now()
|
|
15824
16164
|
});
|
|
@@ -15827,7 +16167,7 @@ var NotificationService = class extends BaseService {
|
|
|
15827
16167
|
* Briše notifikaciju
|
|
15828
16168
|
*/
|
|
15829
16169
|
async deleteNotification(notificationId) {
|
|
15830
|
-
const notificationRef =
|
|
16170
|
+
const notificationRef = doc34(
|
|
15831
16171
|
this.db,
|
|
15832
16172
|
NOTIFICATIONS_COLLECTION,
|
|
15833
16173
|
notificationId
|
|
@@ -15845,9 +16185,9 @@ var NotificationService = class extends BaseService {
|
|
|
15845
16185
|
orderBy16("notificationTime", "desc")
|
|
15846
16186
|
);
|
|
15847
16187
|
const querySnapshot = await getDocs29(q);
|
|
15848
|
-
return querySnapshot.docs.map((
|
|
15849
|
-
id:
|
|
15850
|
-
...
|
|
16188
|
+
return querySnapshot.docs.map((doc44) => ({
|
|
16189
|
+
id: doc44.id,
|
|
16190
|
+
...doc44.data()
|
|
15851
16191
|
}));
|
|
15852
16192
|
}
|
|
15853
16193
|
/**
|
|
@@ -15860,9 +16200,9 @@ var NotificationService = class extends BaseService {
|
|
|
15860
16200
|
orderBy16("notificationTime", "desc")
|
|
15861
16201
|
);
|
|
15862
16202
|
const querySnapshot = await getDocs29(q);
|
|
15863
|
-
return querySnapshot.docs.map((
|
|
15864
|
-
id:
|
|
15865
|
-
...
|
|
16203
|
+
return querySnapshot.docs.map((doc44) => ({
|
|
16204
|
+
id: doc44.id,
|
|
16205
|
+
...doc44.data()
|
|
15866
16206
|
}));
|
|
15867
16207
|
}
|
|
15868
16208
|
};
|
|
@@ -15873,13 +16213,13 @@ import {
|
|
|
15873
16213
|
getDocs as getDocs30,
|
|
15874
16214
|
query as query30,
|
|
15875
16215
|
where as where30,
|
|
15876
|
-
doc as
|
|
15877
|
-
updateDoc as
|
|
16216
|
+
doc as doc35,
|
|
16217
|
+
updateDoc as updateDoc33,
|
|
15878
16218
|
Timestamp as Timestamp31,
|
|
15879
16219
|
orderBy as orderBy17,
|
|
15880
16220
|
limit as limit15,
|
|
15881
16221
|
startAfter as startAfter13,
|
|
15882
|
-
getDoc as
|
|
16222
|
+
getDoc as getDoc36
|
|
15883
16223
|
} from "firebase/firestore";
|
|
15884
16224
|
var PatientRequirementsService = class extends BaseService {
|
|
15885
16225
|
constructor(db, auth, app) {
|
|
@@ -15892,7 +16232,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
15892
16232
|
);
|
|
15893
16233
|
}
|
|
15894
16234
|
getPatientRequirementDocRef(patientId, instanceId) {
|
|
15895
|
-
return
|
|
16235
|
+
return doc35(
|
|
15896
16236
|
this.getPatientRequirementsCollectionRef(patientId),
|
|
15897
16237
|
instanceId
|
|
15898
16238
|
);
|
|
@@ -15905,7 +16245,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
15905
16245
|
*/
|
|
15906
16246
|
async getPatientRequirementInstance(patientId, instanceId) {
|
|
15907
16247
|
const docRef = this.getPatientRequirementDocRef(patientId, instanceId);
|
|
15908
|
-
const docSnap = await
|
|
16248
|
+
const docSnap = await getDoc36(docRef);
|
|
15909
16249
|
if (!docSnap.exists()) {
|
|
15910
16250
|
return null;
|
|
15911
16251
|
}
|
|
@@ -15982,7 +16322,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
15982
16322
|
*/
|
|
15983
16323
|
async completeInstruction(patientId, instanceId, instructionId) {
|
|
15984
16324
|
const instanceRef = this.getPatientRequirementDocRef(patientId, instanceId);
|
|
15985
|
-
const instanceSnap = await
|
|
16325
|
+
const instanceSnap = await getDoc36(instanceRef);
|
|
15986
16326
|
if (!instanceSnap.exists()) {
|
|
15987
16327
|
throw new Error(
|
|
15988
16328
|
`PatientRequirementInstance ${instanceId} not found for patient ${patientId}.`
|
|
@@ -16037,7 +16377,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
16037
16377
|
if (newOverallStatus !== instance.overallStatus) {
|
|
16038
16378
|
updatePayload.overallStatus = newOverallStatus;
|
|
16039
16379
|
}
|
|
16040
|
-
await
|
|
16380
|
+
await updateDoc33(instanceRef, updatePayload);
|
|
16041
16381
|
return {
|
|
16042
16382
|
...instance,
|
|
16043
16383
|
instructions: updatedInstructions,
|
|
@@ -16052,15 +16392,15 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
16052
16392
|
// src/services/procedure/procedure.service.ts
|
|
16053
16393
|
import {
|
|
16054
16394
|
collection as collection31,
|
|
16055
|
-
doc as
|
|
16056
|
-
getDoc as
|
|
16395
|
+
doc as doc36,
|
|
16396
|
+
getDoc as getDoc37,
|
|
16057
16397
|
getDocs as getDocs31,
|
|
16058
16398
|
query as query31,
|
|
16059
16399
|
where as where31,
|
|
16060
|
-
updateDoc as
|
|
16400
|
+
updateDoc as updateDoc34,
|
|
16061
16401
|
setDoc as setDoc27,
|
|
16062
16402
|
deleteDoc as deleteDoc19,
|
|
16063
|
-
serverTimestamp as
|
|
16403
|
+
serverTimestamp as serverTimestamp31,
|
|
16064
16404
|
writeBatch as writeBatch6,
|
|
16065
16405
|
orderBy as orderBy18,
|
|
16066
16406
|
limit as limit16,
|
|
@@ -16312,14 +16652,14 @@ var ProcedureService = class extends BaseService {
|
|
|
16312
16652
|
if (!category || !subcategory || !technology || !product) {
|
|
16313
16653
|
throw new Error("One or more required base entities not found");
|
|
16314
16654
|
}
|
|
16315
|
-
const clinicRef =
|
|
16316
|
-
const clinicSnapshot = await
|
|
16655
|
+
const clinicRef = doc36(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId);
|
|
16656
|
+
const clinicSnapshot = await getDoc37(clinicRef);
|
|
16317
16657
|
if (!clinicSnapshot.exists()) {
|
|
16318
16658
|
throw new Error(`Clinic with ID ${validatedData.clinicBranchId} not found`);
|
|
16319
16659
|
}
|
|
16320
16660
|
const clinic = clinicSnapshot.data();
|
|
16321
|
-
const practitionerRef =
|
|
16322
|
-
const practitionerSnapshot = await
|
|
16661
|
+
const practitionerRef = doc36(this.db, PRACTITIONERS_COLLECTION, validatedData.practitionerId);
|
|
16662
|
+
const practitionerSnapshot = await getDoc37(practitionerRef);
|
|
16323
16663
|
if (!practitionerSnapshot.exists()) {
|
|
16324
16664
|
throw new Error(`Practitioner with ID ${validatedData.practitionerId} not found`);
|
|
16325
16665
|
}
|
|
@@ -16394,13 +16734,13 @@ var ProcedureService = class extends BaseService {
|
|
|
16394
16734
|
isActive: true
|
|
16395
16735
|
// Default to active
|
|
16396
16736
|
};
|
|
16397
|
-
const procedureRef =
|
|
16737
|
+
const procedureRef = doc36(this.db, PROCEDURES_COLLECTION, procedureId);
|
|
16398
16738
|
await setDoc27(procedureRef, {
|
|
16399
16739
|
...newProcedure,
|
|
16400
|
-
createdAt:
|
|
16401
|
-
updatedAt:
|
|
16740
|
+
createdAt: serverTimestamp31(),
|
|
16741
|
+
updatedAt: serverTimestamp31()
|
|
16402
16742
|
});
|
|
16403
|
-
const savedDoc = await
|
|
16743
|
+
const savedDoc = await getDoc37(procedureRef);
|
|
16404
16744
|
return savedDoc.data();
|
|
16405
16745
|
}
|
|
16406
16746
|
/**
|
|
@@ -16423,7 +16763,7 @@ var ProcedureService = class extends BaseService {
|
|
|
16423
16763
|
this.subcategoryService.getById(validatedData.categoryId, validatedData.subcategoryId),
|
|
16424
16764
|
this.technologyService.getById(validatedData.technologyId),
|
|
16425
16765
|
this.productService.getById(validatedData.technologyId, validatedData.productId),
|
|
16426
|
-
|
|
16766
|
+
getDoc37(doc36(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId))
|
|
16427
16767
|
]);
|
|
16428
16768
|
if (!category || !subcategory || !technology || !product) {
|
|
16429
16769
|
throw new Error("One or more required base entities not found");
|
|
@@ -16453,8 +16793,8 @@ var ProcedureService = class extends BaseService {
|
|
|
16453
16793
|
where31(documentId2(), "in", chunk)
|
|
16454
16794
|
);
|
|
16455
16795
|
const practitionersSnapshot = await getDocs31(practitionersQuery);
|
|
16456
|
-
practitionersSnapshot.docs.forEach((
|
|
16457
|
-
practitionersMap.set(
|
|
16796
|
+
practitionersSnapshot.docs.forEach((doc44) => {
|
|
16797
|
+
practitionersMap.set(doc44.id, doc44.data());
|
|
16458
16798
|
});
|
|
16459
16799
|
}
|
|
16460
16800
|
if (practitionersMap.size !== practitionerIds.length) {
|
|
@@ -16484,7 +16824,7 @@ var ProcedureService = class extends BaseService {
|
|
|
16484
16824
|
};
|
|
16485
16825
|
const procedureId = this.generateId();
|
|
16486
16826
|
createdProcedureIds.push(procedureId);
|
|
16487
|
-
const procedureRef =
|
|
16827
|
+
const procedureRef = doc36(this.db, PROCEDURES_COLLECTION, procedureId);
|
|
16488
16828
|
const { productsMetadata: _, ...validatedDataWithoutProductsMetadata } = validatedData;
|
|
16489
16829
|
const newProcedure = {
|
|
16490
16830
|
id: procedureId,
|
|
@@ -16525,8 +16865,8 @@ var ProcedureService = class extends BaseService {
|
|
|
16525
16865
|
};
|
|
16526
16866
|
batch.set(procedureRef, {
|
|
16527
16867
|
...newProcedure,
|
|
16528
|
-
createdAt:
|
|
16529
|
-
updatedAt:
|
|
16868
|
+
createdAt: serverTimestamp31(),
|
|
16869
|
+
updatedAt: serverTimestamp31()
|
|
16530
16870
|
});
|
|
16531
16871
|
}
|
|
16532
16872
|
await batch.commit();
|
|
@@ -16535,8 +16875,8 @@ var ProcedureService = class extends BaseService {
|
|
|
16535
16875
|
const chunk = createdProcedureIds.slice(i, i + 30);
|
|
16536
16876
|
const q = query31(collection31(this.db, PROCEDURES_COLLECTION), where31(documentId2(), "in", chunk));
|
|
16537
16877
|
const snapshot = await getDocs31(q);
|
|
16538
|
-
snapshot.forEach((
|
|
16539
|
-
fetchedProcedures.push(
|
|
16878
|
+
snapshot.forEach((doc44) => {
|
|
16879
|
+
fetchedProcedures.push(doc44.data());
|
|
16540
16880
|
});
|
|
16541
16881
|
}
|
|
16542
16882
|
return fetchedProcedures;
|
|
@@ -16547,8 +16887,8 @@ var ProcedureService = class extends BaseService {
|
|
|
16547
16887
|
* @returns The procedure if found, null otherwise
|
|
16548
16888
|
*/
|
|
16549
16889
|
async getProcedure(id) {
|
|
16550
|
-
const docRef =
|
|
16551
|
-
const docSnap = await
|
|
16890
|
+
const docRef = doc36(this.db, PROCEDURES_COLLECTION, id);
|
|
16891
|
+
const docSnap = await getDoc37(docRef);
|
|
16552
16892
|
if (!docSnap.exists()) {
|
|
16553
16893
|
return null;
|
|
16554
16894
|
}
|
|
@@ -16566,7 +16906,7 @@ var ProcedureService = class extends BaseService {
|
|
|
16566
16906
|
where31("isActive", "==", true)
|
|
16567
16907
|
);
|
|
16568
16908
|
const snapshot = await getDocs31(q);
|
|
16569
|
-
return snapshot.docs.map((
|
|
16909
|
+
return snapshot.docs.map((doc44) => doc44.data());
|
|
16570
16910
|
}
|
|
16571
16911
|
/**
|
|
16572
16912
|
* Gets all procedures for a practitioner
|
|
@@ -16580,7 +16920,7 @@ var ProcedureService = class extends BaseService {
|
|
|
16580
16920
|
where31("isActive", "==", true)
|
|
16581
16921
|
);
|
|
16582
16922
|
const snapshot = await getDocs31(q);
|
|
16583
|
-
return snapshot.docs.map((
|
|
16923
|
+
return snapshot.docs.map((doc44) => doc44.data());
|
|
16584
16924
|
}
|
|
16585
16925
|
/**
|
|
16586
16926
|
* Gets all inactive procedures for a practitioner
|
|
@@ -16594,7 +16934,7 @@ var ProcedureService = class extends BaseService {
|
|
|
16594
16934
|
where31("isActive", "==", false)
|
|
16595
16935
|
);
|
|
16596
16936
|
const snapshot = await getDocs31(q);
|
|
16597
|
-
return snapshot.docs.map((
|
|
16937
|
+
return snapshot.docs.map((doc44) => doc44.data());
|
|
16598
16938
|
}
|
|
16599
16939
|
/**
|
|
16600
16940
|
* Updates a procedure
|
|
@@ -16605,8 +16945,8 @@ var ProcedureService = class extends BaseService {
|
|
|
16605
16945
|
async updateProcedure(id, data) {
|
|
16606
16946
|
var _a, _b, _c, _d;
|
|
16607
16947
|
const validatedData = updateProcedureSchema.parse(data);
|
|
16608
|
-
const procedureRef =
|
|
16609
|
-
const procedureSnapshot = await
|
|
16948
|
+
const procedureRef = doc36(this.db, PROCEDURES_COLLECTION, id);
|
|
16949
|
+
const procedureSnapshot = await getDoc37(procedureRef);
|
|
16610
16950
|
if (!procedureSnapshot.exists()) {
|
|
16611
16951
|
throw new Error(`Procedure with ID ${id} not found`);
|
|
16612
16952
|
}
|
|
@@ -16649,12 +16989,12 @@ var ProcedureService = class extends BaseService {
|
|
|
16649
16989
|
}
|
|
16650
16990
|
if (validatedData.practitionerId && validatedData.practitionerId !== oldPractitionerId) {
|
|
16651
16991
|
practitionerChanged = true;
|
|
16652
|
-
const newPractitionerRef =
|
|
16992
|
+
const newPractitionerRef = doc36(
|
|
16653
16993
|
this.db,
|
|
16654
16994
|
PRACTITIONERS_COLLECTION,
|
|
16655
16995
|
validatedData.practitionerId
|
|
16656
16996
|
);
|
|
16657
|
-
const newPractitionerSnap = await
|
|
16997
|
+
const newPractitionerSnap = await getDoc37(newPractitionerRef);
|
|
16658
16998
|
if (!newPractitionerSnap.exists())
|
|
16659
16999
|
throw new Error(`New Practitioner ${validatedData.practitionerId} not found`);
|
|
16660
17000
|
newPractitioner = newPractitionerSnap.data();
|
|
@@ -16670,8 +17010,8 @@ var ProcedureService = class extends BaseService {
|
|
|
16670
17010
|
}
|
|
16671
17011
|
if (validatedData.clinicBranchId && validatedData.clinicBranchId !== oldClinicId) {
|
|
16672
17012
|
clinicChanged = true;
|
|
16673
|
-
const newClinicRef =
|
|
16674
|
-
const newClinicSnap = await
|
|
17013
|
+
const newClinicRef = doc36(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId);
|
|
17014
|
+
const newClinicSnap = await getDoc37(newClinicRef);
|
|
16675
17015
|
if (!newClinicSnap.exists())
|
|
16676
17016
|
throw new Error(`New Clinic ${validatedData.clinicBranchId} not found`);
|
|
16677
17017
|
newClinic = newClinicSnap.data();
|
|
@@ -16733,11 +17073,11 @@ var ProcedureService = class extends BaseService {
|
|
|
16733
17073
|
} else if (validatedData.productId) {
|
|
16734
17074
|
console.warn("Attempted to update product without a valid technologyId");
|
|
16735
17075
|
}
|
|
16736
|
-
await
|
|
17076
|
+
await updateDoc34(procedureRef, {
|
|
16737
17077
|
...updatedProcedureData,
|
|
16738
|
-
updatedAt:
|
|
17078
|
+
updatedAt: serverTimestamp31()
|
|
16739
17079
|
});
|
|
16740
|
-
const updatedSnapshot = await
|
|
17080
|
+
const updatedSnapshot = await getDoc37(procedureRef);
|
|
16741
17081
|
return updatedSnapshot.data();
|
|
16742
17082
|
}
|
|
16743
17083
|
/**
|
|
@@ -16745,15 +17085,15 @@ var ProcedureService = class extends BaseService {
|
|
|
16745
17085
|
* @param id - The ID of the procedure to deactivate
|
|
16746
17086
|
*/
|
|
16747
17087
|
async deactivateProcedure(id) {
|
|
16748
|
-
const procedureRef =
|
|
16749
|
-
const procedureSnap = await
|
|
17088
|
+
const procedureRef = doc36(this.db, PROCEDURES_COLLECTION, id);
|
|
17089
|
+
const procedureSnap = await getDoc37(procedureRef);
|
|
16750
17090
|
if (!procedureSnap.exists()) {
|
|
16751
17091
|
console.warn(`Procedure ${id} not found for deactivation.`);
|
|
16752
17092
|
return;
|
|
16753
17093
|
}
|
|
16754
|
-
await
|
|
17094
|
+
await updateDoc34(procedureRef, {
|
|
16755
17095
|
isActive: false,
|
|
16756
|
-
updatedAt:
|
|
17096
|
+
updatedAt: serverTimestamp31()
|
|
16757
17097
|
});
|
|
16758
17098
|
}
|
|
16759
17099
|
/**
|
|
@@ -16762,8 +17102,8 @@ var ProcedureService = class extends BaseService {
|
|
|
16762
17102
|
* @returns A boolean indicating if the deletion was successful
|
|
16763
17103
|
*/
|
|
16764
17104
|
async deleteProcedure(id) {
|
|
16765
|
-
const procedureRef =
|
|
16766
|
-
const procedureSnapshot = await
|
|
17105
|
+
const procedureRef = doc36(this.db, PROCEDURES_COLLECTION, id);
|
|
17106
|
+
const procedureSnapshot = await getDoc37(procedureRef);
|
|
16767
17107
|
if (!procedureSnapshot.exists()) {
|
|
16768
17108
|
return false;
|
|
16769
17109
|
}
|
|
@@ -16813,11 +17153,11 @@ var ProcedureService = class extends BaseService {
|
|
|
16813
17153
|
}
|
|
16814
17154
|
const proceduresSnapshot = await getDocs31(proceduresQuery);
|
|
16815
17155
|
const lastVisible = proceduresSnapshot.docs[proceduresSnapshot.docs.length - 1];
|
|
16816
|
-
const procedures = proceduresSnapshot.docs.map((
|
|
16817
|
-
const data =
|
|
17156
|
+
const procedures = proceduresSnapshot.docs.map((doc44) => {
|
|
17157
|
+
const data = doc44.data();
|
|
16818
17158
|
return {
|
|
16819
17159
|
...data,
|
|
16820
|
-
id:
|
|
17160
|
+
id: doc44.id
|
|
16821
17161
|
// Ensure ID is present
|
|
16822
17162
|
};
|
|
16823
17163
|
});
|
|
@@ -16891,6 +17231,12 @@ var ProcedureService = class extends BaseService {
|
|
|
16891
17231
|
if (filters.procedureTechnology) {
|
|
16892
17232
|
constraints.push(where31("technology.id", "==", filters.procedureTechnology));
|
|
16893
17233
|
}
|
|
17234
|
+
if (filters.practitionerId) {
|
|
17235
|
+
constraints.push(where31("practitionerId", "==", filters.practitionerId));
|
|
17236
|
+
}
|
|
17237
|
+
if (filters.clinicId) {
|
|
17238
|
+
constraints.push(where31("clinicBranchId", "==", filters.clinicId));
|
|
17239
|
+
}
|
|
16894
17240
|
if (filters.minPrice !== void 0) {
|
|
16895
17241
|
constraints.push(where31("price", ">=", filters.minPrice));
|
|
16896
17242
|
}
|
|
@@ -16930,7 +17276,7 @@ var ProcedureService = class extends BaseService {
|
|
|
16930
17276
|
const q = query31(collection31(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
16931
17277
|
const querySnapshot = await getDocs31(q);
|
|
16932
17278
|
const procedures = querySnapshot.docs.map(
|
|
16933
|
-
(
|
|
17279
|
+
(doc44) => ({ ...doc44.data(), id: doc44.id })
|
|
16934
17280
|
);
|
|
16935
17281
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
16936
17282
|
console.log(`[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures`);
|
|
@@ -16963,7 +17309,7 @@ var ProcedureService = class extends BaseService {
|
|
|
16963
17309
|
const q = query31(collection31(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
16964
17310
|
const querySnapshot = await getDocs31(q);
|
|
16965
17311
|
const procedures = querySnapshot.docs.map(
|
|
16966
|
-
(
|
|
17312
|
+
(doc44) => ({ ...doc44.data(), id: doc44.id })
|
|
16967
17313
|
);
|
|
16968
17314
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
16969
17315
|
console.log(`[PROCEDURE_SERVICE] Strategy 2 success: ${procedures.length} procedures`);
|
|
@@ -16994,7 +17340,7 @@ var ProcedureService = class extends BaseService {
|
|
|
16994
17340
|
const q = query31(collection31(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
16995
17341
|
const querySnapshot = await getDocs31(q);
|
|
16996
17342
|
let procedures = querySnapshot.docs.map(
|
|
16997
|
-
(
|
|
17343
|
+
(doc44) => ({ ...doc44.data(), id: doc44.id })
|
|
16998
17344
|
);
|
|
16999
17345
|
procedures = this.applyInMemoryFilters(procedures, filters);
|
|
17000
17346
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
@@ -17009,14 +17355,20 @@ var ProcedureService = class extends BaseService {
|
|
|
17009
17355
|
try {
|
|
17010
17356
|
console.log("[PROCEDURE_SERVICE] Strategy 4: Minimal query fallback");
|
|
17011
17357
|
const constraints = [
|
|
17012
|
-
where31("isActive", "==", true),
|
|
17013
|
-
orderBy18("createdAt", "desc")
|
|
17014
|
-
limit16(filters.pagination || 10)
|
|
17358
|
+
where31("isActive", "==", filters.isActive !== void 0 ? filters.isActive : true),
|
|
17359
|
+
orderBy18("createdAt", "desc")
|
|
17015
17360
|
];
|
|
17361
|
+
if (filters.practitionerId) {
|
|
17362
|
+
constraints.push(where31("practitionerId", "==", filters.practitionerId));
|
|
17363
|
+
}
|
|
17364
|
+
if (filters.clinicId) {
|
|
17365
|
+
constraints.push(where31("clinicBranchId", "==", filters.clinicId));
|
|
17366
|
+
}
|
|
17367
|
+
constraints.push(limit16(filters.pagination || 10));
|
|
17016
17368
|
const q = query31(collection31(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
17017
17369
|
const querySnapshot = await getDocs31(q);
|
|
17018
17370
|
let procedures = querySnapshot.docs.map(
|
|
17019
|
-
(
|
|
17371
|
+
(doc44) => ({ ...doc44.data(), id: doc44.id })
|
|
17020
17372
|
);
|
|
17021
17373
|
procedures = this.applyInMemoryFilters(procedures, filters);
|
|
17022
17374
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
@@ -17126,6 +17478,22 @@ var ProcedureService = class extends BaseService {
|
|
|
17126
17478
|
`[PROCEDURE_SERVICE] Applied technology filter, results: ${filteredProcedures.length}`
|
|
17127
17479
|
);
|
|
17128
17480
|
}
|
|
17481
|
+
if (filters.practitionerId) {
|
|
17482
|
+
filteredProcedures = filteredProcedures.filter(
|
|
17483
|
+
(procedure) => procedure.practitionerId === filters.practitionerId
|
|
17484
|
+
);
|
|
17485
|
+
console.log(
|
|
17486
|
+
`[PROCEDURE_SERVICE] Applied practitioner filter, results: ${filteredProcedures.length}`
|
|
17487
|
+
);
|
|
17488
|
+
}
|
|
17489
|
+
if (filters.clinicId) {
|
|
17490
|
+
filteredProcedures = filteredProcedures.filter(
|
|
17491
|
+
(procedure) => procedure.clinicBranchId === filters.clinicId
|
|
17492
|
+
);
|
|
17493
|
+
console.log(
|
|
17494
|
+
`[PROCEDURE_SERVICE] Applied clinic filter, results: ${filteredProcedures.length}`
|
|
17495
|
+
);
|
|
17496
|
+
}
|
|
17129
17497
|
if (filters.location && filters.radiusInKm && filters.radiusInKm > 0) {
|
|
17130
17498
|
const location = filters.location;
|
|
17131
17499
|
const radiusInKm = filters.radiusInKm;
|
|
@@ -17162,6 +17530,12 @@ var ProcedureService = class extends BaseService {
|
|
|
17162
17530
|
where31("clinicInfo.location.geohash", "<=", b[1]),
|
|
17163
17531
|
where31("isActive", "==", filters.isActive !== void 0 ? filters.isActive : true)
|
|
17164
17532
|
];
|
|
17533
|
+
if (filters.practitionerId) {
|
|
17534
|
+
constraints.push(where31("practitionerId", "==", filters.practitionerId));
|
|
17535
|
+
}
|
|
17536
|
+
if (filters.clinicId) {
|
|
17537
|
+
constraints.push(where31("clinicBranchId", "==", filters.clinicId));
|
|
17538
|
+
}
|
|
17165
17539
|
return getDocs31(query31(collection31(this.db, PROCEDURES_COLLECTION), ...constraints));
|
|
17166
17540
|
});
|
|
17167
17541
|
return Promise.all(fetches).then((snaps) => {
|
|
@@ -17213,14 +17587,14 @@ var ProcedureService = class extends BaseService {
|
|
|
17213
17587
|
if (!category || !subcategory || !technology) {
|
|
17214
17588
|
throw new Error("One or more required base entities not found");
|
|
17215
17589
|
}
|
|
17216
|
-
const clinicRef =
|
|
17217
|
-
const clinicSnapshot = await
|
|
17590
|
+
const clinicRef = doc36(this.db, CLINICS_COLLECTION, data.clinicBranchId);
|
|
17591
|
+
const clinicSnapshot = await getDoc37(clinicRef);
|
|
17218
17592
|
if (!clinicSnapshot.exists()) {
|
|
17219
17593
|
throw new Error(`Clinic with ID ${data.clinicBranchId} not found`);
|
|
17220
17594
|
}
|
|
17221
17595
|
const clinic = clinicSnapshot.data();
|
|
17222
|
-
const practitionerRef =
|
|
17223
|
-
const practitionerSnapshot = await
|
|
17596
|
+
const practitionerRef = doc36(this.db, PRACTITIONERS_COLLECTION, data.practitionerId);
|
|
17597
|
+
const practitionerSnapshot = await getDoc37(practitionerRef);
|
|
17224
17598
|
if (!practitionerSnapshot.exists()) {
|
|
17225
17599
|
throw new Error(`Practitioner with ID ${data.practitionerId} not found`);
|
|
17226
17600
|
}
|
|
@@ -17299,13 +17673,13 @@ var ProcedureService = class extends BaseService {
|
|
|
17299
17673
|
},
|
|
17300
17674
|
isActive: true
|
|
17301
17675
|
};
|
|
17302
|
-
const procedureRef =
|
|
17676
|
+
const procedureRef = doc36(this.db, PROCEDURES_COLLECTION, procedureId);
|
|
17303
17677
|
await setDoc27(procedureRef, {
|
|
17304
17678
|
...newProcedure,
|
|
17305
|
-
createdAt:
|
|
17306
|
-
updatedAt:
|
|
17679
|
+
createdAt: serverTimestamp31(),
|
|
17680
|
+
updatedAt: serverTimestamp31()
|
|
17307
17681
|
});
|
|
17308
|
-
const savedDoc = await
|
|
17682
|
+
const savedDoc = await getDoc37(procedureRef);
|
|
17309
17683
|
return savedDoc.data();
|
|
17310
17684
|
}
|
|
17311
17685
|
/**
|
|
@@ -17316,11 +17690,11 @@ var ProcedureService = class extends BaseService {
|
|
|
17316
17690
|
async getProceduresForMap() {
|
|
17317
17691
|
const proceduresRef = collection31(this.db, PROCEDURES_COLLECTION);
|
|
17318
17692
|
const snapshot = await getDocs31(proceduresRef);
|
|
17319
|
-
const proceduresForMap = snapshot.docs.map((
|
|
17693
|
+
const proceduresForMap = snapshot.docs.map((doc44) => {
|
|
17320
17694
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
17321
|
-
const data =
|
|
17695
|
+
const data = doc44.data();
|
|
17322
17696
|
return {
|
|
17323
|
-
id:
|
|
17697
|
+
id: doc44.id,
|
|
17324
17698
|
name: data.name,
|
|
17325
17699
|
clinicId: (_a = data.clinicInfo) == null ? void 0 : _a.id,
|
|
17326
17700
|
clinicName: (_b = data.clinicInfo) == null ? void 0 : _b.name,
|
|
@@ -17342,8 +17716,8 @@ var ProcedureService = class extends BaseService {
|
|
|
17342
17716
|
async getProceduresForConsultation(clinicBranchId, practitionerId, filterByFamily = true, defaultProcedureId) {
|
|
17343
17717
|
let familyToFilter = null;
|
|
17344
17718
|
if (filterByFamily && defaultProcedureId) {
|
|
17345
|
-
const defaultProcedureRef =
|
|
17346
|
-
const defaultProcedureSnap = await
|
|
17719
|
+
const defaultProcedureRef = doc36(this.db, PROCEDURES_COLLECTION, defaultProcedureId);
|
|
17720
|
+
const defaultProcedureSnap = await getDoc37(defaultProcedureRef);
|
|
17347
17721
|
if (defaultProcedureSnap.exists()) {
|
|
17348
17722
|
const defaultProcedure = defaultProcedureSnap.data();
|
|
17349
17723
|
familyToFilter = defaultProcedure.family;
|
|
@@ -17363,9 +17737,9 @@ var ProcedureService = class extends BaseService {
|
|
|
17363
17737
|
orderBy18("name", "asc")
|
|
17364
17738
|
);
|
|
17365
17739
|
const querySnapshot = await getDocs31(proceduresQuery);
|
|
17366
|
-
return querySnapshot.docs.map((
|
|
17367
|
-
id:
|
|
17368
|
-
...
|
|
17740
|
+
return querySnapshot.docs.map((doc44) => ({
|
|
17741
|
+
id: doc44.id,
|
|
17742
|
+
...doc44.data()
|
|
17369
17743
|
}));
|
|
17370
17744
|
}
|
|
17371
17745
|
};
|
|
@@ -17373,14 +17747,14 @@ var ProcedureService = class extends BaseService {
|
|
|
17373
17747
|
// src/services/reviews/reviews.service.ts
|
|
17374
17748
|
import {
|
|
17375
17749
|
collection as collection32,
|
|
17376
|
-
doc as
|
|
17377
|
-
getDoc as
|
|
17750
|
+
doc as doc37,
|
|
17751
|
+
getDoc as getDoc38,
|
|
17378
17752
|
getDocs as getDocs32,
|
|
17379
17753
|
query as query32,
|
|
17380
17754
|
where as where32,
|
|
17381
17755
|
setDoc as setDoc28,
|
|
17382
17756
|
deleteDoc as deleteDoc20,
|
|
17383
|
-
serverTimestamp as
|
|
17757
|
+
serverTimestamp as serverTimestamp32
|
|
17384
17758
|
} from "firebase/firestore";
|
|
17385
17759
|
import { z as z27 } from "zod";
|
|
17386
17760
|
var ReviewService = class extends BaseService {
|
|
@@ -17471,11 +17845,11 @@ var ReviewService = class extends BaseService {
|
|
|
17471
17845
|
updatedAt: now
|
|
17472
17846
|
};
|
|
17473
17847
|
reviewSchema.parse(review);
|
|
17474
|
-
const docRef =
|
|
17848
|
+
const docRef = doc37(this.db, REVIEWS_COLLECTION, reviewId);
|
|
17475
17849
|
await setDoc28(docRef, {
|
|
17476
17850
|
...review,
|
|
17477
|
-
createdAt:
|
|
17478
|
-
updatedAt:
|
|
17851
|
+
createdAt: serverTimestamp32(),
|
|
17852
|
+
updatedAt: serverTimestamp32()
|
|
17479
17853
|
});
|
|
17480
17854
|
console.log("\u2705 ReviewService.createReview - Review saved to Firestore:", {
|
|
17481
17855
|
reviewId,
|
|
@@ -17499,16 +17873,16 @@ var ReviewService = class extends BaseService {
|
|
|
17499
17873
|
async getReview(reviewId) {
|
|
17500
17874
|
var _a, _b, _c;
|
|
17501
17875
|
console.log("\u{1F50D} ReviewService.getReview - Getting review:", reviewId);
|
|
17502
|
-
const docRef =
|
|
17503
|
-
const docSnap = await
|
|
17876
|
+
const docRef = doc37(this.db, REVIEWS_COLLECTION, reviewId);
|
|
17877
|
+
const docSnap = await getDoc38(docRef);
|
|
17504
17878
|
if (!docSnap.exists()) {
|
|
17505
17879
|
console.log("\u274C ReviewService.getReview - Review not found:", reviewId);
|
|
17506
17880
|
return null;
|
|
17507
17881
|
}
|
|
17508
17882
|
const review = { ...docSnap.data(), id: reviewId };
|
|
17509
17883
|
try {
|
|
17510
|
-
const appointmentDoc = await
|
|
17511
|
-
|
|
17884
|
+
const appointmentDoc = await getDoc38(
|
|
17885
|
+
doc37(this.db, APPOINTMENTS_COLLECTION, review.appointmentId)
|
|
17512
17886
|
);
|
|
17513
17887
|
if (appointmentDoc.exists()) {
|
|
17514
17888
|
const appointment = appointmentDoc.data();
|
|
@@ -17555,12 +17929,12 @@ var ReviewService = class extends BaseService {
|
|
|
17555
17929
|
async getReviewsByPatient(patientId) {
|
|
17556
17930
|
const q = query32(collection32(this.db, REVIEWS_COLLECTION), where32("patientId", "==", patientId));
|
|
17557
17931
|
const snapshot = await getDocs32(q);
|
|
17558
|
-
const reviews = snapshot.docs.map((
|
|
17932
|
+
const reviews = snapshot.docs.map((doc44) => doc44.data());
|
|
17559
17933
|
const enhancedReviews = await Promise.all(
|
|
17560
17934
|
reviews.map(async (review) => {
|
|
17561
17935
|
try {
|
|
17562
|
-
const appointmentDoc = await
|
|
17563
|
-
|
|
17936
|
+
const appointmentDoc = await getDoc38(
|
|
17937
|
+
doc37(this.db, APPOINTMENTS_COLLECTION, review.appointmentId)
|
|
17564
17938
|
);
|
|
17565
17939
|
if (appointmentDoc.exists()) {
|
|
17566
17940
|
const appointment = appointmentDoc.data();
|
|
@@ -17609,9 +17983,9 @@ var ReviewService = class extends BaseService {
|
|
|
17609
17983
|
where32("clinicReview.clinicId", "==", clinicId)
|
|
17610
17984
|
);
|
|
17611
17985
|
const snapshot = await getDocs32(q);
|
|
17612
|
-
const reviews = snapshot.docs.map((
|
|
17613
|
-
const data =
|
|
17614
|
-
return { ...data, id:
|
|
17986
|
+
const reviews = snapshot.docs.map((doc44) => {
|
|
17987
|
+
const data = doc44.data();
|
|
17988
|
+
return { ...data, id: doc44.id };
|
|
17615
17989
|
});
|
|
17616
17990
|
console.log("\u{1F50D} ReviewService.getReviewsByClinic - Found reviews before enhancement:", {
|
|
17617
17991
|
clinicId,
|
|
@@ -17621,8 +17995,8 @@ var ReviewService = class extends BaseService {
|
|
|
17621
17995
|
const enhancedReviews = await Promise.all(
|
|
17622
17996
|
reviews.map(async (review) => {
|
|
17623
17997
|
try {
|
|
17624
|
-
const appointmentDoc = await
|
|
17625
|
-
|
|
17998
|
+
const appointmentDoc = await getDoc38(
|
|
17999
|
+
doc37(this.db, APPOINTMENTS_COLLECTION, review.appointmentId)
|
|
17626
18000
|
);
|
|
17627
18001
|
if (appointmentDoc.exists()) {
|
|
17628
18002
|
const appointment = appointmentDoc.data();
|
|
@@ -17685,9 +18059,9 @@ var ReviewService = class extends BaseService {
|
|
|
17685
18059
|
where32("practitionerReview.practitionerId", "==", practitionerId)
|
|
17686
18060
|
);
|
|
17687
18061
|
const snapshot = await getDocs32(q);
|
|
17688
|
-
const reviews = snapshot.docs.map((
|
|
17689
|
-
const data =
|
|
17690
|
-
return { ...data, id:
|
|
18062
|
+
const reviews = snapshot.docs.map((doc44) => {
|
|
18063
|
+
const data = doc44.data();
|
|
18064
|
+
return { ...data, id: doc44.id };
|
|
17691
18065
|
});
|
|
17692
18066
|
console.log("\u{1F50D} ReviewService.getReviewsByPractitioner - Found reviews before enhancement:", {
|
|
17693
18067
|
practitionerId,
|
|
@@ -17697,8 +18071,8 @@ var ReviewService = class extends BaseService {
|
|
|
17697
18071
|
const enhancedReviews = await Promise.all(
|
|
17698
18072
|
reviews.map(async (review) => {
|
|
17699
18073
|
try {
|
|
17700
|
-
const appointmentDoc = await
|
|
17701
|
-
|
|
18074
|
+
const appointmentDoc = await getDoc38(
|
|
18075
|
+
doc37(this.db, APPOINTMENTS_COLLECTION, review.appointmentId)
|
|
17702
18076
|
);
|
|
17703
18077
|
if (appointmentDoc.exists()) {
|
|
17704
18078
|
const appointment = appointmentDoc.data();
|
|
@@ -17758,9 +18132,9 @@ var ReviewService = class extends BaseService {
|
|
|
17758
18132
|
where32("procedureReview.procedureId", "==", procedureId)
|
|
17759
18133
|
);
|
|
17760
18134
|
const snapshot = await getDocs32(q);
|
|
17761
|
-
const reviews = snapshot.docs.map((
|
|
17762
|
-
const data =
|
|
17763
|
-
return { ...data, id:
|
|
18135
|
+
const reviews = snapshot.docs.map((doc44) => {
|
|
18136
|
+
const data = doc44.data();
|
|
18137
|
+
return { ...data, id: doc44.id };
|
|
17764
18138
|
});
|
|
17765
18139
|
console.log("\u{1F50D} ReviewService.getReviewsByProcedure - Found reviews before enhancement:", {
|
|
17766
18140
|
procedureId,
|
|
@@ -17770,8 +18144,8 @@ var ReviewService = class extends BaseService {
|
|
|
17770
18144
|
const enhancedReviews = await Promise.all(
|
|
17771
18145
|
reviews.map(async (review) => {
|
|
17772
18146
|
try {
|
|
17773
|
-
const appointmentDoc = await
|
|
17774
|
-
|
|
18147
|
+
const appointmentDoc = await getDoc38(
|
|
18148
|
+
doc37(this.db, APPOINTMENTS_COLLECTION, review.appointmentId)
|
|
17775
18149
|
);
|
|
17776
18150
|
if (appointmentDoc.exists()) {
|
|
17777
18151
|
const appointment = appointmentDoc.data();
|
|
@@ -17844,7 +18218,7 @@ var ReviewService = class extends BaseService {
|
|
|
17844
18218
|
if (!review) {
|
|
17845
18219
|
throw new Error(`Review with ID ${reviewId} not found`);
|
|
17846
18220
|
}
|
|
17847
|
-
await deleteDoc20(
|
|
18221
|
+
await deleteDoc20(doc37(this.db, REVIEWS_COLLECTION, reviewId));
|
|
17848
18222
|
}
|
|
17849
18223
|
/**
|
|
17850
18224
|
* Calculates the average of an array of numbers
|
|
@@ -17918,11 +18292,11 @@ var getFirebaseFunctions = async () => {
|
|
|
17918
18292
|
import {
|
|
17919
18293
|
addDoc as addDoc4,
|
|
17920
18294
|
collection as collection33,
|
|
17921
|
-
doc as
|
|
17922
|
-
getDoc as
|
|
18295
|
+
doc as doc38,
|
|
18296
|
+
getDoc as getDoc39,
|
|
17923
18297
|
getDocs as getDocs33,
|
|
17924
18298
|
query as query33,
|
|
17925
|
-
updateDoc as
|
|
18299
|
+
updateDoc as updateDoc35,
|
|
17926
18300
|
where as where33,
|
|
17927
18301
|
limit as limit17,
|
|
17928
18302
|
orderBy as orderBy19,
|
|
@@ -17981,9 +18355,9 @@ var BrandService = class extends BaseService {
|
|
|
17981
18355
|
const q = query33(this.getBrandsRef(), ...constraints);
|
|
17982
18356
|
const snapshot = await getDocs33(q);
|
|
17983
18357
|
const brands = snapshot.docs.map(
|
|
17984
|
-
(
|
|
17985
|
-
id:
|
|
17986
|
-
...
|
|
18358
|
+
(doc44) => ({
|
|
18359
|
+
id: doc44.id,
|
|
18360
|
+
...doc44.data()
|
|
17987
18361
|
})
|
|
17988
18362
|
);
|
|
17989
18363
|
const newLastVisible = snapshot.docs[snapshot.docs.length - 1];
|
|
@@ -18017,9 +18391,9 @@ var BrandService = class extends BaseService {
|
|
|
18017
18391
|
);
|
|
18018
18392
|
const snapshot = await getDocs33(q);
|
|
18019
18393
|
return snapshot.docs.map(
|
|
18020
|
-
(
|
|
18021
|
-
id:
|
|
18022
|
-
...
|
|
18394
|
+
(doc44) => ({
|
|
18395
|
+
id: doc44.id,
|
|
18396
|
+
...doc44.data()
|
|
18023
18397
|
})
|
|
18024
18398
|
);
|
|
18025
18399
|
}
|
|
@@ -18034,8 +18408,8 @@ var BrandService = class extends BaseService {
|
|
|
18034
18408
|
if (brand.name) {
|
|
18035
18409
|
updateData.name_lowercase = brand.name.toLowerCase();
|
|
18036
18410
|
}
|
|
18037
|
-
const docRef =
|
|
18038
|
-
await
|
|
18411
|
+
const docRef = doc38(this.getBrandsRef(), brandId);
|
|
18412
|
+
await updateDoc35(docRef, updateData);
|
|
18039
18413
|
return this.getById(brandId);
|
|
18040
18414
|
}
|
|
18041
18415
|
/**
|
|
@@ -18050,8 +18424,8 @@ var BrandService = class extends BaseService {
|
|
|
18050
18424
|
* Gets a brand by ID
|
|
18051
18425
|
*/
|
|
18052
18426
|
async getById(brandId) {
|
|
18053
|
-
const docRef =
|
|
18054
|
-
const docSnap = await
|
|
18427
|
+
const docRef = doc38(this.getBrandsRef(), brandId);
|
|
18428
|
+
const docSnap = await getDoc39(docRef);
|
|
18055
18429
|
if (!docSnap.exists()) return null;
|
|
18056
18430
|
return {
|
|
18057
18431
|
id: docSnap.id,
|
|
@@ -18064,15 +18438,15 @@ var BrandService = class extends BaseService {
|
|
|
18064
18438
|
import {
|
|
18065
18439
|
addDoc as addDoc5,
|
|
18066
18440
|
collection as collection34,
|
|
18067
|
-
doc as
|
|
18441
|
+
doc as doc39,
|
|
18068
18442
|
getCountFromServer as getCountFromServer4,
|
|
18069
|
-
getDoc as
|
|
18443
|
+
getDoc as getDoc40,
|
|
18070
18444
|
getDocs as getDocs34,
|
|
18071
18445
|
limit as limit18,
|
|
18072
18446
|
orderBy as orderBy20,
|
|
18073
18447
|
query as query34,
|
|
18074
18448
|
startAfter as startAfter16,
|
|
18075
|
-
updateDoc as
|
|
18449
|
+
updateDoc as updateDoc36,
|
|
18076
18450
|
where as where34
|
|
18077
18451
|
} from "firebase/firestore";
|
|
18078
18452
|
|
|
@@ -18130,9 +18504,9 @@ var CategoryService = class extends BaseService {
|
|
|
18130
18504
|
const q = query34(this.categoriesRef, where34("isActive", "==", true));
|
|
18131
18505
|
const snapshot = await getDocs34(q);
|
|
18132
18506
|
return snapshot.docs.map(
|
|
18133
|
-
(
|
|
18134
|
-
id:
|
|
18135
|
-
...
|
|
18507
|
+
(doc44) => ({
|
|
18508
|
+
id: doc44.id,
|
|
18509
|
+
...doc44.data()
|
|
18136
18510
|
})
|
|
18137
18511
|
);
|
|
18138
18512
|
}
|
|
@@ -18150,9 +18524,9 @@ var CategoryService = class extends BaseService {
|
|
|
18150
18524
|
);
|
|
18151
18525
|
const snapshot = await getDocs34(q);
|
|
18152
18526
|
return snapshot.docs.map(
|
|
18153
|
-
(
|
|
18154
|
-
id:
|
|
18155
|
-
...
|
|
18527
|
+
(doc44) => ({
|
|
18528
|
+
id: doc44.id,
|
|
18529
|
+
...doc44.data()
|
|
18156
18530
|
})
|
|
18157
18531
|
);
|
|
18158
18532
|
}
|
|
@@ -18172,9 +18546,9 @@ var CategoryService = class extends BaseService {
|
|
|
18172
18546
|
const q = query34(this.categoriesRef, ...constraints);
|
|
18173
18547
|
const snapshot = await getDocs34(q);
|
|
18174
18548
|
const categories = snapshot.docs.map(
|
|
18175
|
-
(
|
|
18176
|
-
id:
|
|
18177
|
-
...
|
|
18549
|
+
(doc44) => ({
|
|
18550
|
+
id: doc44.id,
|
|
18551
|
+
...doc44.data()
|
|
18178
18552
|
})
|
|
18179
18553
|
);
|
|
18180
18554
|
const newLastVisible = snapshot.docs[snapshot.docs.length - 1];
|
|
@@ -18198,9 +18572,9 @@ var CategoryService = class extends BaseService {
|
|
|
18198
18572
|
const q = query34(this.categoriesRef, ...constraints);
|
|
18199
18573
|
const snapshot = await getDocs34(q);
|
|
18200
18574
|
const categories = snapshot.docs.map(
|
|
18201
|
-
(
|
|
18202
|
-
id:
|
|
18203
|
-
...
|
|
18575
|
+
(doc44) => ({
|
|
18576
|
+
id: doc44.id,
|
|
18577
|
+
...doc44.data()
|
|
18204
18578
|
})
|
|
18205
18579
|
);
|
|
18206
18580
|
const newLastVisible = snapshot.docs[snapshot.docs.length - 1];
|
|
@@ -18217,8 +18591,8 @@ var CategoryService = class extends BaseService {
|
|
|
18217
18591
|
...category,
|
|
18218
18592
|
updatedAt: /* @__PURE__ */ new Date()
|
|
18219
18593
|
};
|
|
18220
|
-
const docRef =
|
|
18221
|
-
await
|
|
18594
|
+
const docRef = doc39(this.categoriesRef, id);
|
|
18595
|
+
await updateDoc36(docRef, updateData);
|
|
18222
18596
|
return this.getById(id);
|
|
18223
18597
|
}
|
|
18224
18598
|
/**
|
|
@@ -18241,8 +18615,8 @@ var CategoryService = class extends BaseService {
|
|
|
18241
18615
|
* @returns Kategorija ili null ako ne postoji
|
|
18242
18616
|
*/
|
|
18243
18617
|
async getById(id) {
|
|
18244
|
-
const docRef =
|
|
18245
|
-
const docSnap = await
|
|
18618
|
+
const docRef = doc39(this.categoriesRef, id);
|
|
18619
|
+
const docSnap = await getDoc40(docRef);
|
|
18246
18620
|
if (!docSnap.exists()) return null;
|
|
18247
18621
|
return {
|
|
18248
18622
|
id: docSnap.id,
|
|
@@ -18257,16 +18631,16 @@ import {
|
|
|
18257
18631
|
collection as collection35,
|
|
18258
18632
|
collectionGroup as collectionGroup2,
|
|
18259
18633
|
deleteDoc as deleteDoc21,
|
|
18260
|
-
doc as
|
|
18634
|
+
doc as doc40,
|
|
18261
18635
|
getCountFromServer as getCountFromServer5,
|
|
18262
|
-
getDoc as
|
|
18636
|
+
getDoc as getDoc41,
|
|
18263
18637
|
getDocs as getDocs35,
|
|
18264
18638
|
limit as limit19,
|
|
18265
18639
|
orderBy as orderBy21,
|
|
18266
18640
|
query as query35,
|
|
18267
18641
|
setDoc as setDoc29,
|
|
18268
18642
|
startAfter as startAfter17,
|
|
18269
|
-
updateDoc as
|
|
18643
|
+
updateDoc as updateDoc37,
|
|
18270
18644
|
where as where35
|
|
18271
18645
|
} from "firebase/firestore";
|
|
18272
18646
|
|
|
@@ -18343,9 +18717,9 @@ var SubcategoryService = class extends BaseService {
|
|
|
18343
18717
|
const q = query35(this.getSubcategoriesRef(categoryId), ...constraints);
|
|
18344
18718
|
const querySnapshot = await getDocs35(q);
|
|
18345
18719
|
const subcategories = querySnapshot.docs.map(
|
|
18346
|
-
(
|
|
18347
|
-
id:
|
|
18348
|
-
...
|
|
18720
|
+
(doc44) => ({
|
|
18721
|
+
id: doc44.id,
|
|
18722
|
+
...doc44.data()
|
|
18349
18723
|
})
|
|
18350
18724
|
);
|
|
18351
18725
|
const newLastVisible = querySnapshot.docs[querySnapshot.docs.length - 1];
|
|
@@ -18373,9 +18747,9 @@ var SubcategoryService = class extends BaseService {
|
|
|
18373
18747
|
);
|
|
18374
18748
|
const querySnapshot = await getDocs35(q);
|
|
18375
18749
|
const subcategories = querySnapshot.docs.map(
|
|
18376
|
-
(
|
|
18377
|
-
id:
|
|
18378
|
-
...
|
|
18750
|
+
(doc44) => ({
|
|
18751
|
+
id: doc44.id,
|
|
18752
|
+
...doc44.data()
|
|
18379
18753
|
})
|
|
18380
18754
|
);
|
|
18381
18755
|
const newLastVisible = querySnapshot.docs[querySnapshot.docs.length - 1];
|
|
@@ -18393,9 +18767,9 @@ var SubcategoryService = class extends BaseService {
|
|
|
18393
18767
|
);
|
|
18394
18768
|
const querySnapshot = await getDocs35(q);
|
|
18395
18769
|
return querySnapshot.docs.map(
|
|
18396
|
-
(
|
|
18397
|
-
id:
|
|
18398
|
-
...
|
|
18770
|
+
(doc44) => ({
|
|
18771
|
+
id: doc44.id,
|
|
18772
|
+
...doc44.data()
|
|
18399
18773
|
})
|
|
18400
18774
|
);
|
|
18401
18775
|
}
|
|
@@ -18410,9 +18784,9 @@ var SubcategoryService = class extends BaseService {
|
|
|
18410
18784
|
);
|
|
18411
18785
|
const querySnapshot = await getDocs35(q);
|
|
18412
18786
|
return querySnapshot.docs.map(
|
|
18413
|
-
(
|
|
18414
|
-
id:
|
|
18415
|
-
...
|
|
18787
|
+
(doc44) => ({
|
|
18788
|
+
id: doc44.id,
|
|
18789
|
+
...doc44.data()
|
|
18416
18790
|
})
|
|
18417
18791
|
);
|
|
18418
18792
|
}
|
|
@@ -18426,11 +18800,11 @@ var SubcategoryService = class extends BaseService {
|
|
|
18426
18800
|
async update(categoryId, subcategoryId, subcategory) {
|
|
18427
18801
|
const newCategoryId = subcategory.categoryId;
|
|
18428
18802
|
if (newCategoryId && newCategoryId !== categoryId) {
|
|
18429
|
-
const oldDocRef =
|
|
18803
|
+
const oldDocRef = doc40(
|
|
18430
18804
|
this.getSubcategoriesRef(categoryId),
|
|
18431
18805
|
subcategoryId
|
|
18432
18806
|
);
|
|
18433
|
-
const docSnap = await
|
|
18807
|
+
const docSnap = await getDoc41(oldDocRef);
|
|
18434
18808
|
if (!docSnap.exists()) {
|
|
18435
18809
|
throw new Error("Subcategory to update does not exist.");
|
|
18436
18810
|
}
|
|
@@ -18444,7 +18818,7 @@ var SubcategoryService = class extends BaseService {
|
|
|
18444
18818
|
// Preserve original creation date
|
|
18445
18819
|
updatedAt: /* @__PURE__ */ new Date()
|
|
18446
18820
|
};
|
|
18447
|
-
const newDocRef =
|
|
18821
|
+
const newDocRef = doc40(
|
|
18448
18822
|
this.getSubcategoriesRef(newCategoryId),
|
|
18449
18823
|
subcategoryId
|
|
18450
18824
|
);
|
|
@@ -18456,8 +18830,8 @@ var SubcategoryService = class extends BaseService {
|
|
|
18456
18830
|
...subcategory,
|
|
18457
18831
|
updatedAt: /* @__PURE__ */ new Date()
|
|
18458
18832
|
};
|
|
18459
|
-
const docRef =
|
|
18460
|
-
await
|
|
18833
|
+
const docRef = doc40(this.getSubcategoriesRef(categoryId), subcategoryId);
|
|
18834
|
+
await updateDoc37(docRef, updateData);
|
|
18461
18835
|
return this.getById(categoryId, subcategoryId);
|
|
18462
18836
|
}
|
|
18463
18837
|
}
|
|
@@ -18484,8 +18858,8 @@ var SubcategoryService = class extends BaseService {
|
|
|
18484
18858
|
* @returns Podkategorija ili null ako ne postoji
|
|
18485
18859
|
*/
|
|
18486
18860
|
async getById(categoryId, subcategoryId) {
|
|
18487
|
-
const docRef =
|
|
18488
|
-
const docSnap = await
|
|
18861
|
+
const docRef = doc40(this.getSubcategoriesRef(categoryId), subcategoryId);
|
|
18862
|
+
const docSnap = await getDoc41(docRef);
|
|
18489
18863
|
if (!docSnap.exists()) return null;
|
|
18490
18864
|
return {
|
|
18491
18865
|
id: docSnap.id,
|
|
@@ -18498,14 +18872,14 @@ var SubcategoryService = class extends BaseService {
|
|
|
18498
18872
|
import {
|
|
18499
18873
|
addDoc as addDoc7,
|
|
18500
18874
|
collection as collection36,
|
|
18501
|
-
doc as
|
|
18502
|
-
getDoc as
|
|
18875
|
+
doc as doc41,
|
|
18876
|
+
getDoc as getDoc42,
|
|
18503
18877
|
getDocs as getDocs36,
|
|
18504
18878
|
limit as limit20,
|
|
18505
18879
|
orderBy as orderBy22,
|
|
18506
18880
|
query as query36,
|
|
18507
18881
|
startAfter as startAfter18,
|
|
18508
|
-
updateDoc as
|
|
18882
|
+
updateDoc as updateDoc38,
|
|
18509
18883
|
where as where36,
|
|
18510
18884
|
arrayUnion as arrayUnion9,
|
|
18511
18885
|
arrayRemove as arrayRemove8
|
|
@@ -18559,8 +18933,8 @@ var TechnologyService = class extends BaseService {
|
|
|
18559
18933
|
const q = query36(this.technologiesRef, where36("isActive", "==", active));
|
|
18560
18934
|
const snapshot = await getDocs36(q);
|
|
18561
18935
|
const counts = {};
|
|
18562
|
-
snapshot.docs.forEach((
|
|
18563
|
-
const tech =
|
|
18936
|
+
snapshot.docs.forEach((doc44) => {
|
|
18937
|
+
const tech = doc44.data();
|
|
18564
18938
|
counts[tech.subcategoryId] = (counts[tech.subcategoryId] || 0) + 1;
|
|
18565
18939
|
});
|
|
18566
18940
|
return counts;
|
|
@@ -18574,8 +18948,8 @@ var TechnologyService = class extends BaseService {
|
|
|
18574
18948
|
const q = query36(this.technologiesRef, where36("isActive", "==", active));
|
|
18575
18949
|
const snapshot = await getDocs36(q);
|
|
18576
18950
|
const counts = {};
|
|
18577
|
-
snapshot.docs.forEach((
|
|
18578
|
-
const tech =
|
|
18951
|
+
snapshot.docs.forEach((doc44) => {
|
|
18952
|
+
const tech = doc44.data();
|
|
18579
18953
|
counts[tech.categoryId] = (counts[tech.categoryId] || 0) + 1;
|
|
18580
18954
|
});
|
|
18581
18955
|
return counts;
|
|
@@ -18596,9 +18970,9 @@ var TechnologyService = class extends BaseService {
|
|
|
18596
18970
|
const q = query36(this.technologiesRef, ...constraints);
|
|
18597
18971
|
const snapshot = await getDocs36(q);
|
|
18598
18972
|
const technologies = snapshot.docs.map(
|
|
18599
|
-
(
|
|
18600
|
-
id:
|
|
18601
|
-
...
|
|
18973
|
+
(doc44) => ({
|
|
18974
|
+
id: doc44.id,
|
|
18975
|
+
...doc44.data()
|
|
18602
18976
|
})
|
|
18603
18977
|
);
|
|
18604
18978
|
const newLastVisible = snapshot.docs[snapshot.docs.length - 1];
|
|
@@ -18622,9 +18996,9 @@ var TechnologyService = class extends BaseService {
|
|
|
18622
18996
|
const q = query36(this.technologiesRef, ...constraints);
|
|
18623
18997
|
const snapshot = await getDocs36(q);
|
|
18624
18998
|
const technologies = snapshot.docs.map(
|
|
18625
|
-
(
|
|
18626
|
-
id:
|
|
18627
|
-
...
|
|
18999
|
+
(doc44) => ({
|
|
19000
|
+
id: doc44.id,
|
|
19001
|
+
...doc44.data()
|
|
18628
19002
|
})
|
|
18629
19003
|
);
|
|
18630
19004
|
const newLastVisible = snapshot.docs[snapshot.docs.length - 1];
|
|
@@ -18648,9 +19022,9 @@ var TechnologyService = class extends BaseService {
|
|
|
18648
19022
|
const q = query36(this.technologiesRef, ...constraints);
|
|
18649
19023
|
const snapshot = await getDocs36(q);
|
|
18650
19024
|
const technologies = snapshot.docs.map(
|
|
18651
|
-
(
|
|
18652
|
-
id:
|
|
18653
|
-
...
|
|
19025
|
+
(doc44) => ({
|
|
19026
|
+
id: doc44.id,
|
|
19027
|
+
...doc44.data()
|
|
18654
19028
|
})
|
|
18655
19029
|
);
|
|
18656
19030
|
const newLastVisible = snapshot.docs[snapshot.docs.length - 1];
|
|
@@ -18670,8 +19044,8 @@ var TechnologyService = class extends BaseService {
|
|
|
18670
19044
|
}
|
|
18671
19045
|
});
|
|
18672
19046
|
updateData.updatedAt = /* @__PURE__ */ new Date();
|
|
18673
|
-
const docRef =
|
|
18674
|
-
await
|
|
19047
|
+
const docRef = doc41(this.technologiesRef, id);
|
|
19048
|
+
await updateDoc38(docRef, updateData);
|
|
18675
19049
|
return this.getById(id);
|
|
18676
19050
|
}
|
|
18677
19051
|
/**
|
|
@@ -18694,8 +19068,8 @@ var TechnologyService = class extends BaseService {
|
|
|
18694
19068
|
* @returns The technology or null if it doesn't exist.
|
|
18695
19069
|
*/
|
|
18696
19070
|
async getById(id) {
|
|
18697
|
-
const docRef =
|
|
18698
|
-
const docSnap = await
|
|
19071
|
+
const docRef = doc41(this.technologiesRef, id);
|
|
19072
|
+
const docSnap = await getDoc42(docRef);
|
|
18699
19073
|
if (!docSnap.exists()) return null;
|
|
18700
19074
|
return {
|
|
18701
19075
|
id: docSnap.id,
|
|
@@ -18709,9 +19083,9 @@ var TechnologyService = class extends BaseService {
|
|
|
18709
19083
|
* @returns Ažurirana tehnologija sa novim zahtevom
|
|
18710
19084
|
*/
|
|
18711
19085
|
async addRequirement(technologyId, requirement) {
|
|
18712
|
-
const docRef =
|
|
19086
|
+
const docRef = doc41(this.technologiesRef, technologyId);
|
|
18713
19087
|
const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
|
|
18714
|
-
await
|
|
19088
|
+
await updateDoc38(docRef, {
|
|
18715
19089
|
[requirementType]: arrayUnion9(requirement),
|
|
18716
19090
|
updatedAt: /* @__PURE__ */ new Date()
|
|
18717
19091
|
});
|
|
@@ -18724,9 +19098,9 @@ var TechnologyService = class extends BaseService {
|
|
|
18724
19098
|
* @returns Ažurirana tehnologija bez uklonjenog zahteva
|
|
18725
19099
|
*/
|
|
18726
19100
|
async removeRequirement(technologyId, requirement) {
|
|
18727
|
-
const docRef =
|
|
19101
|
+
const docRef = doc41(this.technologiesRef, technologyId);
|
|
18728
19102
|
const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
|
|
18729
|
-
await
|
|
19103
|
+
await updateDoc38(docRef, {
|
|
18730
19104
|
[requirementType]: arrayRemove8(requirement),
|
|
18731
19105
|
updatedAt: /* @__PURE__ */ new Date()
|
|
18732
19106
|
});
|
|
@@ -18764,8 +19138,8 @@ var TechnologyService = class extends BaseService {
|
|
|
18764
19138
|
* @returns Ažurirana tehnologija
|
|
18765
19139
|
*/
|
|
18766
19140
|
async addBlockingCondition(technologyId, condition) {
|
|
18767
|
-
const docRef =
|
|
18768
|
-
await
|
|
19141
|
+
const docRef = doc41(this.technologiesRef, technologyId);
|
|
19142
|
+
await updateDoc38(docRef, {
|
|
18769
19143
|
blockingConditions: arrayUnion9(condition),
|
|
18770
19144
|
updatedAt: /* @__PURE__ */ new Date()
|
|
18771
19145
|
});
|
|
@@ -18778,8 +19152,8 @@ var TechnologyService = class extends BaseService {
|
|
|
18778
19152
|
* @returns Ažurirana tehnologija
|
|
18779
19153
|
*/
|
|
18780
19154
|
async removeBlockingCondition(technologyId, condition) {
|
|
18781
|
-
const docRef =
|
|
18782
|
-
await
|
|
19155
|
+
const docRef = doc41(this.technologiesRef, technologyId);
|
|
19156
|
+
await updateDoc38(docRef, {
|
|
18783
19157
|
blockingConditions: arrayRemove8(condition),
|
|
18784
19158
|
updatedAt: /* @__PURE__ */ new Date()
|
|
18785
19159
|
});
|
|
@@ -18792,7 +19166,7 @@ var TechnologyService = class extends BaseService {
|
|
|
18792
19166
|
* @returns Ažurirana tehnologija
|
|
18793
19167
|
*/
|
|
18794
19168
|
async addContraindication(technologyId, contraindication) {
|
|
18795
|
-
const docRef =
|
|
19169
|
+
const docRef = doc41(this.technologiesRef, technologyId);
|
|
18796
19170
|
const technology = await this.getById(technologyId);
|
|
18797
19171
|
if (!technology) {
|
|
18798
19172
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
@@ -18801,7 +19175,7 @@ var TechnologyService = class extends BaseService {
|
|
|
18801
19175
|
if (existingContraindications.some((c) => c.id === contraindication.id)) {
|
|
18802
19176
|
return technology;
|
|
18803
19177
|
}
|
|
18804
|
-
await
|
|
19178
|
+
await updateDoc38(docRef, {
|
|
18805
19179
|
contraindications: [...existingContraindications, contraindication],
|
|
18806
19180
|
updatedAt: /* @__PURE__ */ new Date()
|
|
18807
19181
|
});
|
|
@@ -18814,7 +19188,7 @@ var TechnologyService = class extends BaseService {
|
|
|
18814
19188
|
* @returns Ažurirana tehnologija
|
|
18815
19189
|
*/
|
|
18816
19190
|
async removeContraindication(technologyId, contraindication) {
|
|
18817
|
-
const docRef =
|
|
19191
|
+
const docRef = doc41(this.technologiesRef, technologyId);
|
|
18818
19192
|
const technology = await this.getById(technologyId);
|
|
18819
19193
|
if (!technology) {
|
|
18820
19194
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
@@ -18822,7 +19196,7 @@ var TechnologyService = class extends BaseService {
|
|
|
18822
19196
|
const updatedContraindications = (technology.contraindications || []).filter(
|
|
18823
19197
|
(c) => c.id !== contraindication.id
|
|
18824
19198
|
);
|
|
18825
|
-
await
|
|
19199
|
+
await updateDoc38(docRef, {
|
|
18826
19200
|
contraindications: updatedContraindications,
|
|
18827
19201
|
updatedAt: /* @__PURE__ */ new Date()
|
|
18828
19202
|
});
|
|
@@ -18836,7 +19210,7 @@ var TechnologyService = class extends BaseService {
|
|
|
18836
19210
|
* @returns The updated technology
|
|
18837
19211
|
*/
|
|
18838
19212
|
async updateContraindication(technologyId, contraindication) {
|
|
18839
|
-
const docRef =
|
|
19213
|
+
const docRef = doc41(this.technologiesRef, technologyId);
|
|
18840
19214
|
const technology = await this.getById(technologyId);
|
|
18841
19215
|
if (!technology) {
|
|
18842
19216
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
@@ -18851,7 +19225,7 @@ var TechnologyService = class extends BaseService {
|
|
|
18851
19225
|
}
|
|
18852
19226
|
const updatedContraindications = [...contraindications];
|
|
18853
19227
|
updatedContraindications[index] = contraindication;
|
|
18854
|
-
await
|
|
19228
|
+
await updateDoc38(docRef, {
|
|
18855
19229
|
contraindications: updatedContraindications,
|
|
18856
19230
|
updatedAt: /* @__PURE__ */ new Date()
|
|
18857
19231
|
});
|
|
@@ -18864,7 +19238,7 @@ var TechnologyService = class extends BaseService {
|
|
|
18864
19238
|
* @returns Ažurirana tehnologija
|
|
18865
19239
|
*/
|
|
18866
19240
|
async addBenefit(technologyId, benefit) {
|
|
18867
|
-
const docRef =
|
|
19241
|
+
const docRef = doc41(this.technologiesRef, technologyId);
|
|
18868
19242
|
const technology = await this.getById(technologyId);
|
|
18869
19243
|
if (!technology) {
|
|
18870
19244
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
@@ -18873,7 +19247,7 @@ var TechnologyService = class extends BaseService {
|
|
|
18873
19247
|
if (existingBenefits.some((b) => b.id === benefit.id)) {
|
|
18874
19248
|
return technology;
|
|
18875
19249
|
}
|
|
18876
|
-
await
|
|
19250
|
+
await updateDoc38(docRef, {
|
|
18877
19251
|
benefits: [...existingBenefits, benefit],
|
|
18878
19252
|
updatedAt: /* @__PURE__ */ new Date()
|
|
18879
19253
|
});
|
|
@@ -18886,13 +19260,13 @@ var TechnologyService = class extends BaseService {
|
|
|
18886
19260
|
* @returns Ažurirana tehnologija
|
|
18887
19261
|
*/
|
|
18888
19262
|
async removeBenefit(technologyId, benefit) {
|
|
18889
|
-
const docRef =
|
|
19263
|
+
const docRef = doc41(this.technologiesRef, technologyId);
|
|
18890
19264
|
const technology = await this.getById(technologyId);
|
|
18891
19265
|
if (!technology) {
|
|
18892
19266
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
18893
19267
|
}
|
|
18894
19268
|
const updatedBenefits = (technology.benefits || []).filter((b) => b.id !== benefit.id);
|
|
18895
|
-
await
|
|
19269
|
+
await updateDoc38(docRef, {
|
|
18896
19270
|
benefits: updatedBenefits,
|
|
18897
19271
|
updatedAt: /* @__PURE__ */ new Date()
|
|
18898
19272
|
});
|
|
@@ -18906,7 +19280,7 @@ var TechnologyService = class extends BaseService {
|
|
|
18906
19280
|
* @returns The updated technology
|
|
18907
19281
|
*/
|
|
18908
19282
|
async updateBenefit(technologyId, benefit) {
|
|
18909
|
-
const docRef =
|
|
19283
|
+
const docRef = doc41(this.technologiesRef, technologyId);
|
|
18910
19284
|
const technology = await this.getById(technologyId);
|
|
18911
19285
|
if (!technology) {
|
|
18912
19286
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
@@ -18921,7 +19295,7 @@ var TechnologyService = class extends BaseService {
|
|
|
18921
19295
|
}
|
|
18922
19296
|
const updatedBenefits = [...benefits];
|
|
18923
19297
|
updatedBenefits[index] = benefit;
|
|
18924
|
-
await
|
|
19298
|
+
await updateDoc38(docRef, {
|
|
18925
19299
|
benefits: updatedBenefits,
|
|
18926
19300
|
updatedAt: /* @__PURE__ */ new Date()
|
|
18927
19301
|
});
|
|
@@ -18961,8 +19335,8 @@ var TechnologyService = class extends BaseService {
|
|
|
18961
19335
|
* @returns Ažurirana tehnologija
|
|
18962
19336
|
*/
|
|
18963
19337
|
async updateCertificationRequirement(technologyId, certificationRequirement) {
|
|
18964
|
-
const docRef =
|
|
18965
|
-
await
|
|
19338
|
+
const docRef = doc41(this.technologiesRef, technologyId);
|
|
19339
|
+
await updateDoc38(docRef, {
|
|
18966
19340
|
certificationRequirement,
|
|
18967
19341
|
updatedAt: /* @__PURE__ */ new Date()
|
|
18968
19342
|
});
|
|
@@ -19063,9 +19437,9 @@ var TechnologyService = class extends BaseService {
|
|
|
19063
19437
|
);
|
|
19064
19438
|
const snapshot = await getDocs36(q);
|
|
19065
19439
|
return snapshot.docs.map(
|
|
19066
|
-
(
|
|
19067
|
-
id:
|
|
19068
|
-
...
|
|
19440
|
+
(doc44) => ({
|
|
19441
|
+
id: doc44.id,
|
|
19442
|
+
...doc44.data()
|
|
19069
19443
|
})
|
|
19070
19444
|
);
|
|
19071
19445
|
}
|
|
@@ -19084,9 +19458,9 @@ var TechnologyService = class extends BaseService {
|
|
|
19084
19458
|
);
|
|
19085
19459
|
const snapshot = await getDocs36(q);
|
|
19086
19460
|
return snapshot.docs.map(
|
|
19087
|
-
(
|
|
19088
|
-
id:
|
|
19089
|
-
...
|
|
19461
|
+
(doc44) => ({
|
|
19462
|
+
id: doc44.id,
|
|
19463
|
+
...doc44.data()
|
|
19090
19464
|
})
|
|
19091
19465
|
);
|
|
19092
19466
|
}
|
|
@@ -19101,9 +19475,9 @@ var TechnologyService = class extends BaseService {
|
|
|
19101
19475
|
);
|
|
19102
19476
|
const snapshot = await getDocs36(q);
|
|
19103
19477
|
return snapshot.docs.map(
|
|
19104
|
-
(
|
|
19105
|
-
id:
|
|
19106
|
-
...
|
|
19478
|
+
(doc44) => ({
|
|
19479
|
+
id: doc44.id,
|
|
19480
|
+
...doc44.data()
|
|
19107
19481
|
})
|
|
19108
19482
|
);
|
|
19109
19483
|
}
|
|
@@ -19114,11 +19488,11 @@ import {
|
|
|
19114
19488
|
addDoc as addDoc8,
|
|
19115
19489
|
collection as collection37,
|
|
19116
19490
|
collectionGroup as collectionGroup3,
|
|
19117
|
-
doc as
|
|
19118
|
-
getDoc as
|
|
19491
|
+
doc as doc42,
|
|
19492
|
+
getDoc as getDoc43,
|
|
19119
19493
|
getDocs as getDocs37,
|
|
19120
19494
|
query as query37,
|
|
19121
|
-
updateDoc as
|
|
19495
|
+
updateDoc as updateDoc39,
|
|
19122
19496
|
where as where37,
|
|
19123
19497
|
limit as limit21,
|
|
19124
19498
|
orderBy as orderBy23,
|
|
@@ -19178,9 +19552,9 @@ var ProductService = class extends BaseService {
|
|
|
19178
19552
|
const q = query37(collectionGroup3(this.db, PRODUCTS_COLLECTION), ...constraints);
|
|
19179
19553
|
const snapshot = await getDocs37(q);
|
|
19180
19554
|
const products = snapshot.docs.map(
|
|
19181
|
-
(
|
|
19182
|
-
id:
|
|
19183
|
-
...
|
|
19555
|
+
(doc44) => ({
|
|
19556
|
+
id: doc44.id,
|
|
19557
|
+
...doc44.data()
|
|
19184
19558
|
})
|
|
19185
19559
|
);
|
|
19186
19560
|
const newLastVisible = snapshot.docs[snapshot.docs.length - 1];
|
|
@@ -19220,8 +19594,8 @@ var ProductService = class extends BaseService {
|
|
|
19220
19594
|
if (snapshot.empty) {
|
|
19221
19595
|
return counts;
|
|
19222
19596
|
}
|
|
19223
|
-
snapshot.docs.forEach((
|
|
19224
|
-
const product =
|
|
19597
|
+
snapshot.docs.forEach((doc44) => {
|
|
19598
|
+
const product = doc44.data();
|
|
19225
19599
|
const { categoryId, subcategoryId, technologyId } = product;
|
|
19226
19600
|
if (categoryId) {
|
|
19227
19601
|
counts.byCategory[categoryId] = (counts.byCategory[categoryId] || 0) + 1;
|
|
@@ -19246,9 +19620,9 @@ var ProductService = class extends BaseService {
|
|
|
19246
19620
|
);
|
|
19247
19621
|
const snapshot = await getDocs37(q);
|
|
19248
19622
|
return snapshot.docs.map(
|
|
19249
|
-
(
|
|
19250
|
-
id:
|
|
19251
|
-
...
|
|
19623
|
+
(doc44) => ({
|
|
19624
|
+
id: doc44.id,
|
|
19625
|
+
...doc44.data()
|
|
19252
19626
|
})
|
|
19253
19627
|
);
|
|
19254
19628
|
}
|
|
@@ -19268,9 +19642,9 @@ var ProductService = class extends BaseService {
|
|
|
19268
19642
|
const snapshot = await getDocs37(q);
|
|
19269
19643
|
products.push(
|
|
19270
19644
|
...snapshot.docs.map(
|
|
19271
|
-
(
|
|
19272
|
-
id:
|
|
19273
|
-
...
|
|
19645
|
+
(doc44) => ({
|
|
19646
|
+
id: doc44.id,
|
|
19647
|
+
...doc44.data()
|
|
19274
19648
|
})
|
|
19275
19649
|
)
|
|
19276
19650
|
);
|
|
@@ -19285,8 +19659,8 @@ var ProductService = class extends BaseService {
|
|
|
19285
19659
|
...product,
|
|
19286
19660
|
updatedAt: /* @__PURE__ */ new Date()
|
|
19287
19661
|
};
|
|
19288
|
-
const docRef =
|
|
19289
|
-
await
|
|
19662
|
+
const docRef = doc42(this.getProductsRef(technologyId), productId);
|
|
19663
|
+
await updateDoc39(docRef, updateData);
|
|
19290
19664
|
return this.getById(technologyId, productId);
|
|
19291
19665
|
}
|
|
19292
19666
|
/**
|
|
@@ -19301,8 +19675,8 @@ var ProductService = class extends BaseService {
|
|
|
19301
19675
|
* Gets a product by ID
|
|
19302
19676
|
*/
|
|
19303
19677
|
async getById(technologyId, productId) {
|
|
19304
|
-
const docRef =
|
|
19305
|
-
const docSnap = await
|
|
19678
|
+
const docRef = doc42(this.getProductsRef(technologyId), productId);
|
|
19679
|
+
const docSnap = await getDoc43(docRef);
|
|
19306
19680
|
if (!docSnap.exists()) return null;
|
|
19307
19681
|
return {
|
|
19308
19682
|
id: docSnap.id,
|
|
@@ -19315,10 +19689,10 @@ var ProductService = class extends BaseService {
|
|
|
19315
19689
|
import {
|
|
19316
19690
|
arrayRemove as arrayRemove9,
|
|
19317
19691
|
arrayUnion as arrayUnion10,
|
|
19318
|
-
doc as
|
|
19319
|
-
getDoc as
|
|
19692
|
+
doc as doc43,
|
|
19693
|
+
getDoc as getDoc44,
|
|
19320
19694
|
setDoc as setDoc30,
|
|
19321
|
-
updateDoc as
|
|
19695
|
+
updateDoc as updateDoc40
|
|
19322
19696
|
} from "firebase/firestore";
|
|
19323
19697
|
var ADMIN_CONSTANTS_COLLECTION = "admin-constants";
|
|
19324
19698
|
var TREATMENT_BENEFITS_DOC = "treatment-benefits";
|
|
@@ -19330,7 +19704,7 @@ var ConstantsService = class extends BaseService {
|
|
|
19330
19704
|
* @type {DocumentReference}
|
|
19331
19705
|
*/
|
|
19332
19706
|
get treatmentBenefitsDocRef() {
|
|
19333
|
-
return
|
|
19707
|
+
return doc43(this.db, ADMIN_CONSTANTS_COLLECTION, TREATMENT_BENEFITS_DOC);
|
|
19334
19708
|
}
|
|
19335
19709
|
/**
|
|
19336
19710
|
* @description Gets the reference to the document holding contraindications.
|
|
@@ -19338,7 +19712,7 @@ var ConstantsService = class extends BaseService {
|
|
|
19338
19712
|
* @type {DocumentReference}
|
|
19339
19713
|
*/
|
|
19340
19714
|
get contraindicationsDocRef() {
|
|
19341
|
-
return
|
|
19715
|
+
return doc43(this.db, ADMIN_CONSTANTS_COLLECTION, CONTRAINDICATIONS_DOC);
|
|
19342
19716
|
}
|
|
19343
19717
|
// =================================================================
|
|
19344
19718
|
// Treatment Benefits
|
|
@@ -19348,7 +19722,7 @@ var ConstantsService = class extends BaseService {
|
|
|
19348
19722
|
* @returns {Promise<TreatmentBenefitDynamic[]>} An array of all treatment benefits.
|
|
19349
19723
|
*/
|
|
19350
19724
|
async getAllBenefitsForFilter() {
|
|
19351
|
-
const docSnap = await
|
|
19725
|
+
const docSnap = await getDoc44(this.treatmentBenefitsDocRef);
|
|
19352
19726
|
if (!docSnap.exists()) {
|
|
19353
19727
|
return [];
|
|
19354
19728
|
}
|
|
@@ -19377,11 +19751,11 @@ var ConstantsService = class extends BaseService {
|
|
|
19377
19751
|
id: this.generateId(),
|
|
19378
19752
|
...benefit
|
|
19379
19753
|
};
|
|
19380
|
-
const docSnap = await
|
|
19754
|
+
const docSnap = await getDoc44(this.treatmentBenefitsDocRef);
|
|
19381
19755
|
if (!docSnap.exists()) {
|
|
19382
19756
|
await setDoc30(this.treatmentBenefitsDocRef, { benefits: [newBenefit] });
|
|
19383
19757
|
} else {
|
|
19384
|
-
await
|
|
19758
|
+
await updateDoc40(this.treatmentBenefitsDocRef, {
|
|
19385
19759
|
benefits: arrayUnion10(newBenefit)
|
|
19386
19760
|
});
|
|
19387
19761
|
}
|
|
@@ -19421,7 +19795,7 @@ var ConstantsService = class extends BaseService {
|
|
|
19421
19795
|
throw new Error("Treatment benefit not found.");
|
|
19422
19796
|
}
|
|
19423
19797
|
benefits[benefitIndex] = benefit;
|
|
19424
|
-
await
|
|
19798
|
+
await updateDoc40(this.treatmentBenefitsDocRef, { benefits });
|
|
19425
19799
|
return benefit;
|
|
19426
19800
|
}
|
|
19427
19801
|
/**
|
|
@@ -19435,7 +19809,7 @@ var ConstantsService = class extends BaseService {
|
|
|
19435
19809
|
if (!benefitToRemove) {
|
|
19436
19810
|
return;
|
|
19437
19811
|
}
|
|
19438
|
-
await
|
|
19812
|
+
await updateDoc40(this.treatmentBenefitsDocRef, {
|
|
19439
19813
|
benefits: arrayRemove9(benefitToRemove)
|
|
19440
19814
|
});
|
|
19441
19815
|
}
|
|
@@ -19447,7 +19821,7 @@ var ConstantsService = class extends BaseService {
|
|
|
19447
19821
|
* @returns {Promise<ContraindicationDynamic[]>} An array of all contraindications.
|
|
19448
19822
|
*/
|
|
19449
19823
|
async getAllContraindicationsForFilter() {
|
|
19450
|
-
const docSnap = await
|
|
19824
|
+
const docSnap = await getDoc44(this.contraindicationsDocRef);
|
|
19451
19825
|
if (!docSnap.exists()) {
|
|
19452
19826
|
return [];
|
|
19453
19827
|
}
|
|
@@ -19482,13 +19856,13 @@ var ConstantsService = class extends BaseService {
|
|
|
19482
19856
|
id: this.generateId(),
|
|
19483
19857
|
...contraindication
|
|
19484
19858
|
};
|
|
19485
|
-
const docSnap = await
|
|
19859
|
+
const docSnap = await getDoc44(this.contraindicationsDocRef);
|
|
19486
19860
|
if (!docSnap.exists()) {
|
|
19487
19861
|
await setDoc30(this.contraindicationsDocRef, {
|
|
19488
19862
|
contraindications: [newContraindication]
|
|
19489
19863
|
});
|
|
19490
19864
|
} else {
|
|
19491
|
-
await
|
|
19865
|
+
await updateDoc40(this.contraindicationsDocRef, {
|
|
19492
19866
|
contraindications: arrayUnion10(newContraindication)
|
|
19493
19867
|
});
|
|
19494
19868
|
}
|
|
@@ -19530,7 +19904,7 @@ var ConstantsService = class extends BaseService {
|
|
|
19530
19904
|
throw new Error("Contraindication not found.");
|
|
19531
19905
|
}
|
|
19532
19906
|
contraindications[index] = contraindication;
|
|
19533
|
-
await
|
|
19907
|
+
await updateDoc40(this.contraindicationsDocRef, { contraindications });
|
|
19534
19908
|
return contraindication;
|
|
19535
19909
|
}
|
|
19536
19910
|
/**
|
|
@@ -19544,7 +19918,7 @@ var ConstantsService = class extends BaseService {
|
|
|
19544
19918
|
if (!toRemove) {
|
|
19545
19919
|
return;
|
|
19546
19920
|
}
|
|
19547
|
-
await
|
|
19921
|
+
await updateDoc40(this.contraindicationsDocRef, {
|
|
19548
19922
|
contraindications: arrayRemove9(toRemove)
|
|
19549
19923
|
});
|
|
19550
19924
|
}
|