@blackcode_sa/metaestetics-api 1.13.19 → 1.13.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +44 -9
- package/dist/index.mjs +44 -9
- package/package.json +1 -1
- package/src/services/appointment/utils/appointment.utils.ts +61 -13
package/dist/index.js
CHANGED
|
@@ -4606,7 +4606,7 @@ async function updateAppointmentUtil(db, appointmentId, data) {
|
|
|
4606
4606
|
updateData.confirmationTime = import_firestore6.Timestamp.now();
|
|
4607
4607
|
}
|
|
4608
4608
|
if (currentAppointment.calendarEventId) {
|
|
4609
|
-
await updateCalendarEventStatus(db, currentAppointment
|
|
4609
|
+
await updateCalendarEventStatus(db, currentAppointment, data.status);
|
|
4610
4610
|
}
|
|
4611
4611
|
}
|
|
4612
4612
|
await (0, import_firestore6.updateDoc)(appointmentRef, updateData);
|
|
@@ -4620,12 +4620,11 @@ async function updateAppointmentUtil(db, appointmentId, data) {
|
|
|
4620
4620
|
throw error;
|
|
4621
4621
|
}
|
|
4622
4622
|
}
|
|
4623
|
-
async function updateCalendarEventStatus(db,
|
|
4623
|
+
async function updateCalendarEventStatus(db, appointment, appointmentStatus) {
|
|
4624
4624
|
try {
|
|
4625
|
-
const
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
console.warn(`Calendar event with ID ${calendarEventId} not found`);
|
|
4625
|
+
const calendarEventId = appointment.calendarEventId;
|
|
4626
|
+
if (!calendarEventId) {
|
|
4627
|
+
console.warn(`Appointment ${appointment.id} has no calendarEventId, skipping calendar event update`);
|
|
4629
4628
|
return;
|
|
4630
4629
|
}
|
|
4631
4630
|
let calendarStatus;
|
|
@@ -4660,12 +4659,48 @@ async function updateCalendarEventStatus(db, calendarEventId, appointmentStatus)
|
|
|
4660
4659
|
console.warn(`Unknown appointment status: ${appointmentStatus}, not updating calendar event`);
|
|
4661
4660
|
return;
|
|
4662
4661
|
}
|
|
4663
|
-
|
|
4662
|
+
const updateData = {
|
|
4664
4663
|
status: calendarStatus,
|
|
4665
4664
|
updatedAt: (0, import_firestore6.serverTimestamp)()
|
|
4666
|
-
}
|
|
4665
|
+
};
|
|
4666
|
+
const updatePromises = [];
|
|
4667
|
+
if (appointment.practitionerId) {
|
|
4668
|
+
const practitionerEventRef = (0, import_firestore6.doc)(
|
|
4669
|
+
db,
|
|
4670
|
+
`${PRACTITIONERS_COLLECTION}/${appointment.practitionerId}/${CALENDAR_COLLECTION}/${calendarEventId}`
|
|
4671
|
+
);
|
|
4672
|
+
updatePromises.push(
|
|
4673
|
+
(0, import_firestore6.updateDoc)(practitionerEventRef, updateData).catch((error) => {
|
|
4674
|
+
console.error(`Error updating practitioner calendar event ${calendarEventId}:`, error);
|
|
4675
|
+
})
|
|
4676
|
+
);
|
|
4677
|
+
}
|
|
4678
|
+
if (appointment.patientId) {
|
|
4679
|
+
const patientEventRef = (0, import_firestore6.doc)(
|
|
4680
|
+
db,
|
|
4681
|
+
`${PATIENTS_COLLECTION}/${appointment.patientId}/${CALENDAR_COLLECTION}/${calendarEventId}`
|
|
4682
|
+
);
|
|
4683
|
+
updatePromises.push(
|
|
4684
|
+
(0, import_firestore6.updateDoc)(patientEventRef, updateData).catch((error) => {
|
|
4685
|
+
console.error(`Error updating patient calendar event ${calendarEventId}:`, error);
|
|
4686
|
+
})
|
|
4687
|
+
);
|
|
4688
|
+
}
|
|
4689
|
+
if (appointment.clinicBranchId) {
|
|
4690
|
+
const clinicEventRef = (0, import_firestore6.doc)(
|
|
4691
|
+
db,
|
|
4692
|
+
`${CLINICS_COLLECTION}/${appointment.clinicBranchId}/${CALENDAR_COLLECTION}/${calendarEventId}`
|
|
4693
|
+
);
|
|
4694
|
+
updatePromises.push(
|
|
4695
|
+
(0, import_firestore6.updateDoc)(clinicEventRef, updateData).catch((error) => {
|
|
4696
|
+
console.error(`Error updating clinic calendar event ${calendarEventId}:`, error);
|
|
4697
|
+
})
|
|
4698
|
+
);
|
|
4699
|
+
}
|
|
4700
|
+
await Promise.all(updatePromises);
|
|
4701
|
+
console.log(`Successfully updated calendar event ${calendarEventId} status to ${calendarStatus} across all collections`);
|
|
4667
4702
|
} catch (error) {
|
|
4668
|
-
console.error(`Error updating calendar
|
|
4703
|
+
console.error(`Error updating calendar events for appointment ${appointment.id}:`, error);
|
|
4669
4704
|
}
|
|
4670
4705
|
}
|
|
4671
4706
|
async function getAppointmentByIdUtil(db, appointmentId) {
|
package/dist/index.mjs
CHANGED
|
@@ -4493,7 +4493,7 @@ async function updateAppointmentUtil(db, appointmentId, data) {
|
|
|
4493
4493
|
updateData.confirmationTime = Timestamp5.now();
|
|
4494
4494
|
}
|
|
4495
4495
|
if (currentAppointment.calendarEventId) {
|
|
4496
|
-
await updateCalendarEventStatus(db, currentAppointment
|
|
4496
|
+
await updateCalendarEventStatus(db, currentAppointment, data.status);
|
|
4497
4497
|
}
|
|
4498
4498
|
}
|
|
4499
4499
|
await updateDoc2(appointmentRef, updateData);
|
|
@@ -4507,12 +4507,11 @@ async function updateAppointmentUtil(db, appointmentId, data) {
|
|
|
4507
4507
|
throw error;
|
|
4508
4508
|
}
|
|
4509
4509
|
}
|
|
4510
|
-
async function updateCalendarEventStatus(db,
|
|
4510
|
+
async function updateCalendarEventStatus(db, appointment, appointmentStatus) {
|
|
4511
4511
|
try {
|
|
4512
|
-
const
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
console.warn(`Calendar event with ID ${calendarEventId} not found`);
|
|
4512
|
+
const calendarEventId = appointment.calendarEventId;
|
|
4513
|
+
if (!calendarEventId) {
|
|
4514
|
+
console.warn(`Appointment ${appointment.id} has no calendarEventId, skipping calendar event update`);
|
|
4516
4515
|
return;
|
|
4517
4516
|
}
|
|
4518
4517
|
let calendarStatus;
|
|
@@ -4547,12 +4546,48 @@ async function updateCalendarEventStatus(db, calendarEventId, appointmentStatus)
|
|
|
4547
4546
|
console.warn(`Unknown appointment status: ${appointmentStatus}, not updating calendar event`);
|
|
4548
4547
|
return;
|
|
4549
4548
|
}
|
|
4550
|
-
|
|
4549
|
+
const updateData = {
|
|
4551
4550
|
status: calendarStatus,
|
|
4552
4551
|
updatedAt: serverTimestamp()
|
|
4553
|
-
}
|
|
4552
|
+
};
|
|
4553
|
+
const updatePromises = [];
|
|
4554
|
+
if (appointment.practitionerId) {
|
|
4555
|
+
const practitionerEventRef = doc4(
|
|
4556
|
+
db,
|
|
4557
|
+
`${PRACTITIONERS_COLLECTION}/${appointment.practitionerId}/${CALENDAR_COLLECTION}/${calendarEventId}`
|
|
4558
|
+
);
|
|
4559
|
+
updatePromises.push(
|
|
4560
|
+
updateDoc2(practitionerEventRef, updateData).catch((error) => {
|
|
4561
|
+
console.error(`Error updating practitioner calendar event ${calendarEventId}:`, error);
|
|
4562
|
+
})
|
|
4563
|
+
);
|
|
4564
|
+
}
|
|
4565
|
+
if (appointment.patientId) {
|
|
4566
|
+
const patientEventRef = doc4(
|
|
4567
|
+
db,
|
|
4568
|
+
`${PATIENTS_COLLECTION}/${appointment.patientId}/${CALENDAR_COLLECTION}/${calendarEventId}`
|
|
4569
|
+
);
|
|
4570
|
+
updatePromises.push(
|
|
4571
|
+
updateDoc2(patientEventRef, updateData).catch((error) => {
|
|
4572
|
+
console.error(`Error updating patient calendar event ${calendarEventId}:`, error);
|
|
4573
|
+
})
|
|
4574
|
+
);
|
|
4575
|
+
}
|
|
4576
|
+
if (appointment.clinicBranchId) {
|
|
4577
|
+
const clinicEventRef = doc4(
|
|
4578
|
+
db,
|
|
4579
|
+
`${CLINICS_COLLECTION}/${appointment.clinicBranchId}/${CALENDAR_COLLECTION}/${calendarEventId}`
|
|
4580
|
+
);
|
|
4581
|
+
updatePromises.push(
|
|
4582
|
+
updateDoc2(clinicEventRef, updateData).catch((error) => {
|
|
4583
|
+
console.error(`Error updating clinic calendar event ${calendarEventId}:`, error);
|
|
4584
|
+
})
|
|
4585
|
+
);
|
|
4586
|
+
}
|
|
4587
|
+
await Promise.all(updatePromises);
|
|
4588
|
+
console.log(`Successfully updated calendar event ${calendarEventId} status to ${calendarStatus} across all collections`);
|
|
4554
4589
|
} catch (error) {
|
|
4555
|
-
console.error(`Error updating calendar
|
|
4590
|
+
console.error(`Error updating calendar events for appointment ${appointment.id}:`, error);
|
|
4556
4591
|
}
|
|
4557
4592
|
}
|
|
4558
4593
|
async function getAppointmentByIdUtil(db, appointmentId) {
|
package/package.json
CHANGED
|
@@ -28,6 +28,9 @@ import {
|
|
|
28
28
|
import { CalendarEvent, CALENDAR_COLLECTION } from '../../../types/calendar';
|
|
29
29
|
import { ProcedureSummaryInfo } from '../../../types/procedure';
|
|
30
30
|
import { ClinicInfo, PatientProfileInfo, PractitionerProfileInfo } from '../../../types/profile';
|
|
31
|
+
import { PRACTITIONERS_COLLECTION } from '../../../types/practitioner';
|
|
32
|
+
import { PATIENTS_COLLECTION } from '../../../types/patient';
|
|
33
|
+
import { CLINICS_COLLECTION } from '../../../types/clinic';
|
|
31
34
|
import { BlockingCondition } from '../../../backoffice/types/static/blocking-condition.types';
|
|
32
35
|
import { Requirement } from '../../../backoffice/types/requirement.types';
|
|
33
36
|
import { PRACTITIONERS_COLLECTION } from '../../../types/practitioner';
|
|
@@ -379,7 +382,7 @@ export async function updateAppointmentUtil(
|
|
|
379
382
|
|
|
380
383
|
// Update the related calendar event status if needed
|
|
381
384
|
if (currentAppointment.calendarEventId) {
|
|
382
|
-
await updateCalendarEventStatus(db, currentAppointment
|
|
385
|
+
await updateCalendarEventStatus(db, currentAppointment, data.status);
|
|
383
386
|
}
|
|
384
387
|
}
|
|
385
388
|
|
|
@@ -400,28 +403,27 @@ export async function updateAppointmentUtil(
|
|
|
400
403
|
}
|
|
401
404
|
|
|
402
405
|
/**
|
|
403
|
-
* Updates the status of
|
|
406
|
+
* Updates the status of calendar events across all collections (practitioner, patient, clinic)
|
|
407
|
+
* based on appointment status changes.
|
|
404
408
|
*
|
|
405
409
|
* @param db Firestore instance
|
|
406
|
-
* @param
|
|
410
|
+
* @param appointment The appointment object containing calendar event references
|
|
407
411
|
* @param appointmentStatus New appointment status
|
|
408
412
|
*/
|
|
409
413
|
async function updateCalendarEventStatus(
|
|
410
414
|
db: Firestore,
|
|
411
|
-
|
|
415
|
+
appointment: Appointment,
|
|
412
416
|
appointmentStatus: AppointmentStatus,
|
|
413
417
|
): Promise<void> {
|
|
414
418
|
try {
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
if (!calendarEventDoc.exists()) {
|
|
419
|
-
console.warn(`Calendar event with ID ${calendarEventId} not found`);
|
|
419
|
+
const calendarEventId = appointment.calendarEventId;
|
|
420
|
+
if (!calendarEventId) {
|
|
421
|
+
console.warn(`Appointment ${appointment.id} has no calendarEventId, skipping calendar event update`);
|
|
420
422
|
return;
|
|
421
423
|
}
|
|
422
424
|
|
|
423
425
|
// Map appointment status to calendar event status
|
|
424
|
-
let calendarStatus;
|
|
426
|
+
let calendarStatus: string;
|
|
425
427
|
switch (appointmentStatus) {
|
|
426
428
|
case AppointmentStatus.PENDING:
|
|
427
429
|
calendarStatus = 'pending';
|
|
@@ -455,12 +457,58 @@ async function updateCalendarEventStatus(
|
|
|
455
457
|
return;
|
|
456
458
|
}
|
|
457
459
|
|
|
458
|
-
|
|
460
|
+
const updateData = {
|
|
459
461
|
status: calendarStatus,
|
|
460
462
|
updatedAt: serverTimestamp(),
|
|
461
|
-
}
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
// Update all three calendar event collections in parallel
|
|
466
|
+
const updatePromises: Promise<void>[] = [];
|
|
467
|
+
|
|
468
|
+
// Update practitioner calendar event
|
|
469
|
+
if (appointment.practitionerId) {
|
|
470
|
+
const practitionerEventRef = doc(
|
|
471
|
+
db,
|
|
472
|
+
`${PRACTITIONERS_COLLECTION}/${appointment.practitionerId}/${CALENDAR_COLLECTION}/${calendarEventId}`
|
|
473
|
+
);
|
|
474
|
+
updatePromises.push(
|
|
475
|
+
updateDoc(practitionerEventRef, updateData).catch(error => {
|
|
476
|
+
console.error(`Error updating practitioner calendar event ${calendarEventId}:`, error);
|
|
477
|
+
})
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// Update patient calendar event
|
|
482
|
+
if (appointment.patientId) {
|
|
483
|
+
const patientEventRef = doc(
|
|
484
|
+
db,
|
|
485
|
+
`${PATIENTS_COLLECTION}/${appointment.patientId}/${CALENDAR_COLLECTION}/${calendarEventId}`
|
|
486
|
+
);
|
|
487
|
+
updatePromises.push(
|
|
488
|
+
updateDoc(patientEventRef, updateData).catch(error => {
|
|
489
|
+
console.error(`Error updating patient calendar event ${calendarEventId}:`, error);
|
|
490
|
+
})
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// Update clinic calendar event
|
|
495
|
+
if (appointment.clinicBranchId) {
|
|
496
|
+
const clinicEventRef = doc(
|
|
497
|
+
db,
|
|
498
|
+
`${CLINICS_COLLECTION}/${appointment.clinicBranchId}/${CALENDAR_COLLECTION}/${calendarEventId}`
|
|
499
|
+
);
|
|
500
|
+
updatePromises.push(
|
|
501
|
+
updateDoc(clinicEventRef, updateData).catch(error => {
|
|
502
|
+
console.error(`Error updating clinic calendar event ${calendarEventId}:`, error);
|
|
503
|
+
})
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// Wait for all updates to complete
|
|
508
|
+
await Promise.all(updatePromises);
|
|
509
|
+
console.log(`Successfully updated calendar event ${calendarEventId} status to ${calendarStatus} across all collections`);
|
|
462
510
|
} catch (error) {
|
|
463
|
-
console.error(`Error updating calendar
|
|
511
|
+
console.error(`Error updating calendar events for appointment ${appointment.id}:`, error);
|
|
464
512
|
// Don't throw error to avoid failing the appointment update
|
|
465
513
|
}
|
|
466
514
|
}
|