@blackcode_sa/metaestetics-api 1.6.13 → 1.6.15

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.
@@ -1,4 +1,4 @@
1
- import { Timestamp } from 'firebase/firestore';
1
+ import { Timestamp, FieldValue } from 'firebase/firestore';
2
2
  import * as admin from 'firebase-admin';
3
3
  import { Timestamp as Timestamp$1 } from 'firebase-admin/firestore';
4
4
 
@@ -1505,6 +1505,88 @@ interface Appointment {
1505
1505
  /** NEW: Flag for soft deletion or archiving */
1506
1506
  isArchived?: boolean;
1507
1507
  }
1508
+ /**
1509
+ * Data needed to create a new Appointment
1510
+ */
1511
+ interface CreateAppointmentData {
1512
+ clinicBranchId: string;
1513
+ practitionerId: string;
1514
+ patientId: string;
1515
+ procedureId: string;
1516
+ appointmentStartTime: Timestamp;
1517
+ appointmentEndTime: Timestamp;
1518
+ cost: number;
1519
+ currency: Currency;
1520
+ patientNotes?: string | null;
1521
+ initialStatus: AppointmentStatus;
1522
+ initialPaymentStatus?: PaymentStatus;
1523
+ }
1524
+ /**
1525
+ * Data needed to create a new Appointment via CreateAppointmentHttp method
1526
+ */
1527
+ interface CreateAppointmentHttpData {
1528
+ patientId: string;
1529
+ procedureId: string;
1530
+ appointmentStartTime: Timestamp;
1531
+ appointmentEndTime: Timestamp;
1532
+ patientNotes?: string | null;
1533
+ }
1534
+ /**
1535
+ * Data allowed for updating an Appointment
1536
+ */
1537
+ interface UpdateAppointmentData {
1538
+ status?: AppointmentStatus;
1539
+ confirmationTime?: Timestamp | FieldValue | null;
1540
+ cancellationTime?: Timestamp | FieldValue | null;
1541
+ rescheduleTime?: Timestamp | FieldValue | null;
1542
+ procedureActualStartTime?: Timestamp | FieldValue | null;
1543
+ actualDurationMinutes?: number;
1544
+ cancellationReason?: string | null;
1545
+ canceledBy?: "patient" | "clinic" | "practitioner" | "system";
1546
+ internalNotes?: string | null;
1547
+ patientNotes?: string | FieldValue | null;
1548
+ paymentStatus?: PaymentStatus;
1549
+ paymentTransactionId?: string | FieldValue | null;
1550
+ completedPreRequirements?: string[] | FieldValue;
1551
+ completedPostRequirements?: string[] | FieldValue;
1552
+ appointmentStartTime?: Timestamp;
1553
+ appointmentEndTime?: Timestamp;
1554
+ calendarEventId?: string;
1555
+ cost?: number;
1556
+ clinicBranchId?: string;
1557
+ practitionerId?: string;
1558
+ /** NEW: For updating linked forms - typically managed by dedicated methods */
1559
+ linkedFormIds?: string[] | FieldValue;
1560
+ linkedForms?: LinkedFormInfo[] | FieldValue;
1561
+ /** NEW: For updating media items - typically managed by dedicated methods */
1562
+ media?: AppointmentMediaItem[] | FieldValue;
1563
+ /** NEW: For adding/updating review information */
1564
+ reviewInfo?: PatientReviewInfo | FieldValue | null;
1565
+ /** NEW: For setting practitioner finalization details */
1566
+ finalizedDetails?: {
1567
+ by: string;
1568
+ at: Timestamp;
1569
+ notes?: string;
1570
+ } | FieldValue;
1571
+ /** NEW: For archiving/unarchiving */
1572
+ isArchived?: boolean;
1573
+ updatedAt?: FieldValue;
1574
+ }
1575
+ /**
1576
+ * Parameters for searching appointments
1577
+ */
1578
+ interface SearchAppointmentsParams {
1579
+ patientId?: string;
1580
+ practitionerId?: string;
1581
+ clinicBranchId?: string;
1582
+ startDate?: Date;
1583
+ endDate?: Date;
1584
+ status?: AppointmentStatus | AppointmentStatus[];
1585
+ limit?: number;
1586
+ startAfter?: any;
1587
+ }
1588
+ /** Firestore collection name */
1589
+ declare const APPOINTMENTS_COLLECTION = "appointments";
1508
1590
 
1509
1591
  declare class NotificationsAdmin {
1510
1592
  private expo;
@@ -2266,4 +2348,263 @@ interface TimeInterval {
2266
2348
  end: Timestamp;
2267
2349
  }
2268
2350
 
2269
- export { type Appointment, AppointmentAggregationService, type AppointmentReminderNotification, AppointmentStatus, type AvailableSlot, BaseMailingService, type BaseNotification, BookingAdmin, type BookingAvailabilityRequest, type BookingAvailabilityResponse, type Clinic, ClinicAggregationService, type ClinicInfo, type ClinicLocation, type DoctorInfo, NOTIFICATIONS_COLLECTION, type Notification, NotificationStatus, NotificationType, NotificationsAdmin, PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME, type PatientProfile as Patient, PatientAggregationService, PatientInstructionStatus, type PatientRequirementInstance, type PatientRequirementInstruction, PatientRequirementOverallStatus, PatientRequirementsAdminService, type PostRequirementNotification, type Practitioner, PractitionerAggregationService, PractitionerInviteMailingService, type PractitionerToken, PractitionerTokenStatus, type PreRequirementNotification, type Procedure, ProcedureAggregationService, type ProcedureSummaryInfo, type TimeInterval, UserRole };
2351
+ /**
2352
+ * Calculator for determining available booking slots
2353
+ * This class handles the complex logic of determining when appointments can be scheduled
2354
+ * based on clinic working hours, practitioner availability, and existing calendar events.
2355
+ */
2356
+ declare class BookingAvailabilityCalculator {
2357
+ /** Default scheduling interval in minutes if not specified by the clinic */
2358
+ private static readonly DEFAULT_INTERVAL_MINUTES;
2359
+ /**
2360
+ * Calculate available booking slots based on the provided data
2361
+ *
2362
+ * @param request - The request containing all necessary data for calculation
2363
+ * @returns Response with available booking slots
2364
+ */
2365
+ static calculateSlots(request: BookingAvailabilityRequest): BookingAvailabilityResponse;
2366
+ /**
2367
+ * Apply clinic working hours to available intervals
2368
+ *
2369
+ * @param intervals - Current available intervals
2370
+ * @param workingHours - Clinic working hours
2371
+ * @param timeframe - Overall timeframe being considered
2372
+ * @returns Intervals filtered by clinic working hours
2373
+ */
2374
+ private static applyClinicWorkingHours;
2375
+ /**
2376
+ * Create time intervals for working hours across multiple days
2377
+ *
2378
+ * @param workingHours - Working hours definition
2379
+ * @param startDate - Start date of the overall timeframe
2380
+ * @param endDate - End date of the overall timeframe
2381
+ * @returns Array of time intervals representing working hours
2382
+ */
2383
+ private static createWorkingHoursIntervals;
2384
+ /**
2385
+ * Subtract blocking events from available intervals
2386
+ *
2387
+ * @param intervals - Current available intervals
2388
+ * @param events - Calendar events to subtract
2389
+ * @returns Available intervals after removing blocking events
2390
+ */
2391
+ private static subtractBlockingEvents;
2392
+ /**
2393
+ * Apply practitioner's specific working hours for the given clinic
2394
+ *
2395
+ * @param intervals - Current available intervals
2396
+ * @param practitioner - Practitioner object
2397
+ * @param clinicId - ID of the clinic
2398
+ * @param timeframe - Overall timeframe being considered
2399
+ * @returns Intervals filtered by practitioner's working hours
2400
+ */
2401
+ private static applyPractitionerWorkingHours;
2402
+ /**
2403
+ * Create time intervals for practitioner's working hours across multiple days
2404
+ *
2405
+ * @param workingHours - Practitioner's working hours definition
2406
+ * @param startDate - Start date of the overall timeframe
2407
+ * @param endDate - End date of the overall timeframe
2408
+ * @returns Array of time intervals representing practitioner's working hours
2409
+ */
2410
+ private static createPractitionerWorkingHoursIntervals;
2411
+ /**
2412
+ * Subtract practitioner's busy times from available intervals
2413
+ *
2414
+ * @param intervals - Current available intervals
2415
+ * @param events - Practitioner's calendar events
2416
+ * @returns Available intervals after removing busy times
2417
+ */
2418
+ private static subtractPractitionerBusyTimes;
2419
+ /**
2420
+ * Generate available booking slots based on the final available intervals
2421
+ *
2422
+ * @param intervals - Final available intervals
2423
+ * @param intervalMinutes - Scheduling interval in minutes
2424
+ * @param durationMinutes - Procedure duration in minutes
2425
+ * @returns Array of available booking slots
2426
+ */
2427
+ private static generateAvailableSlots;
2428
+ /**
2429
+ * Check if a time slot is fully available within the given intervals
2430
+ *
2431
+ * @param slotStart - Start time of the slot
2432
+ * @param slotEnd - End time of the slot
2433
+ * @param intervals - Available intervals
2434
+ * @returns True if the slot is fully contained within an available interval
2435
+ */
2436
+ private static isSlotFullyAvailable;
2437
+ /**
2438
+ * Intersect two sets of time intervals
2439
+ *
2440
+ * @param intervalsA - First set of intervals
2441
+ * @param intervalsB - Second set of intervals
2442
+ * @returns Intersection of the two sets of intervals
2443
+ */
2444
+ private static intersectIntervals;
2445
+ /**
2446
+ * Subtract one interval from another, potentially resulting in 0, 1, or 2 intervals
2447
+ *
2448
+ * @param interval - Interval to subtract from
2449
+ * @param subtrahend - Interval to subtract
2450
+ * @returns Array of remaining intervals after subtraction
2451
+ */
2452
+ private static subtractInterval;
2453
+ /**
2454
+ * Merge overlapping intervals to simplify the result
2455
+ *
2456
+ * @param intervals - Intervals to merge
2457
+ * @returns Merged intervals
2458
+ */
2459
+ private static mergeOverlappingIntervals;
2460
+ }
2461
+
2462
+ /**
2463
+ * @class CalendarAdminService
2464
+ * @description Handles administrative tasks for calendar events linked to appointments,
2465
+ * such as status updates, time changes, or deletions, subsequent to their initial creation.
2466
+ */
2467
+ declare class CalendarAdminService {
2468
+ private db;
2469
+ constructor(firestore?: admin.firestore.Firestore);
2470
+ /**
2471
+ * Updates the status of all three calendar events (practitioner, patient, clinic)
2472
+ * associated with a given appointment.
2473
+ *
2474
+ * @param appointment - The appointment object containing references to its calendar events.
2475
+ * @param newStatus - The new CalendarEventStatus to set.
2476
+ * @returns {Promise<void>} A promise that resolves when all updates are attempted.
2477
+ */
2478
+ updateAppointmentCalendarEventsStatus(appointment: Appointment, newStatus: CalendarEventStatus): Promise<void>;
2479
+ /**
2480
+ * Updates the eventTime (start and end) of all three calendar events
2481
+ * associated with a given appointment.
2482
+ *
2483
+ * @param appointment - The appointment object.
2484
+ * @param newEventTime - The new CalendarEventTime object (using FirebaseClientTimestamp).
2485
+ * @returns {Promise<void>} A promise that resolves when all updates are attempted.
2486
+ */
2487
+ updateAppointmentCalendarEventsTime(appointment: Appointment, newEventTime: CalendarEventTime): Promise<void>;
2488
+ /**
2489
+ * Deletes all three calendar events associated with a given appointment.
2490
+ * Note: This is a hard delete. Consider marking as CANCELLED instead if soft delete is preferred.
2491
+ *
2492
+ * @param appointment - The appointment object.
2493
+ * @returns {Promise<void>} A promise that resolves when all deletions are attempted.
2494
+ */
2495
+ deleteAppointmentCalendarEvents(appointment: Appointment): Promise<void>;
2496
+ }
2497
+
2498
+ interface InitializeAppointmentFormsResult {
2499
+ initializedFormsInfo: LinkedFormInfo[];
2500
+ pendingUserFormsIds: string[];
2501
+ allLinkedTemplateIds: string[];
2502
+ }
2503
+ declare class DocumentManagerAdminService {
2504
+ private db;
2505
+ constructor(firestore: admin.firestore.Firestore);
2506
+ /**
2507
+ * Adds operations to a Firestore batch to initialize all linked forms for a new appointment
2508
+ * and returns an array of LinkedFormInfo objects, pendingUserFormsIds, and allLinkedTemplateIds.
2509
+ *
2510
+ * @param dbBatch - The Firestore batch to add operations to.
2511
+ * @param appointmentId - The ID of the newly created appointment.
2512
+ * @param procedureIdForForms - The ID of the procedure associated with this appointment.
2513
+ * @param procedureTemplates - Array of document templates linked to the procedure.
2514
+ * @param patientId - ID of the patient.
2515
+ * @param practitionerId - ID of the practitioner associated with the procedure.
2516
+ * @param clinicId - ID of the clinic where the procedure is performed.
2517
+ * @param nowMillis - Current timestamp in milliseconds for createdAt/updatedAt.
2518
+ * @returns An object containing initializedFormsInfo, pendingUserFormsIds, and allLinkedTemplateIds.
2519
+ */
2520
+ batchInitializeAppointmentForms(dbBatch: admin.firestore.WriteBatch, appointmentId: string, procedureIdForForms: string, procedureTemplates: DocumentTemplate[], patientId: string, practitionerId: string, clinicId: string, nowMillis: number): InitializeAppointmentFormsResult;
2521
+ }
2522
+
2523
+ /**
2524
+ * Cloud Functions-compatible logger with fallback for other environments
2525
+ *
2526
+ * This logger automatically detects if it's running in a Cloud Functions environment
2527
+ * and uses the appropriate logging method. It falls back to console methods in other environments.
2528
+ */
2529
+ /**
2530
+ * Logger class that uses Firebase Functions logger when available
2531
+ * with fallback to console methods when not in a Cloud Functions environment
2532
+ */
2533
+ declare class Logger {
2534
+ /**
2535
+ * Log an error message
2536
+ * @param message Message to log
2537
+ * @param data Optional data to include
2538
+ */
2539
+ static error(message: string, data?: any): void;
2540
+ /**
2541
+ * Log a warning message
2542
+ * @param message Message to log
2543
+ * @param data Optional data to include
2544
+ */
2545
+ static warn(message: string, data?: any): void;
2546
+ /**
2547
+ * Log an info message
2548
+ * @param message Message to log
2549
+ * @param data Optional data to include
2550
+ */
2551
+ static info(message: string, data?: any): void;
2552
+ /**
2553
+ * Log a debug message
2554
+ * @param message Message to log
2555
+ * @param data Optional data to include
2556
+ */
2557
+ static debug(message: string, data?: any): void;
2558
+ }
2559
+
2560
+ interface AppointmentEmailDataBase {
2561
+ appointment: Appointment;
2562
+ options?: {
2563
+ customSubject?: string;
2564
+ fromAddress?: string;
2565
+ mailgunDomain?: string;
2566
+ };
2567
+ }
2568
+ interface AppointmentConfirmationEmailData extends AppointmentEmailDataBase {
2569
+ recipientProfile: PatientProfileInfo | PractitionerProfileInfo;
2570
+ recipientRole: "patient" | "practitioner";
2571
+ }
2572
+ interface AppointmentRequestedEmailData extends AppointmentEmailDataBase {
2573
+ clinicProfile: ClinicInfo;
2574
+ }
2575
+ interface AppointmentCancellationEmailData extends AppointmentEmailDataBase {
2576
+ recipientProfile: PatientProfileInfo | PractitionerProfileInfo;
2577
+ recipientRole: "patient" | "practitioner";
2578
+ cancellationReason?: string;
2579
+ }
2580
+ interface AppointmentRescheduledProposalEmailData extends AppointmentEmailDataBase {
2581
+ patientProfile: PatientProfileInfo;
2582
+ previousStartTime: admin.firestore.Timestamp;
2583
+ previousEndTime: admin.firestore.Timestamp;
2584
+ }
2585
+ interface ReviewRequestEmailData extends AppointmentEmailDataBase {
2586
+ patientProfile: PatientProfileInfo;
2587
+ reviewLink: string;
2588
+ }
2589
+ interface ReviewAddedEmailData extends AppointmentEmailDataBase {
2590
+ recipientProfile: PractitionerProfileInfo | ClinicInfo;
2591
+ recipientRole: "practitioner" | "clinic";
2592
+ reviewerName: string;
2593
+ reviewRating: number;
2594
+ reviewComment?: string;
2595
+ }
2596
+ /**
2597
+ * Service for sending appointment-related emails.
2598
+ */
2599
+ declare class AppointmentMailingService extends BaseMailingService {
2600
+ private readonly DEFAULT_MAILGUN_DOMAIN;
2601
+ constructor(firestore: admin.firestore.Firestore, mailgunClient: NewMailgunClient$1);
2602
+ sendAppointmentConfirmedEmail(data: AppointmentConfirmationEmailData): Promise<any>;
2603
+ sendAppointmentRequestedEmailToClinic(data: AppointmentRequestedEmailData): Promise<any>;
2604
+ sendAppointmentCancelledEmail(data: AppointmentCancellationEmailData): Promise<any>;
2605
+ sendAppointmentRescheduledProposalEmail(data: AppointmentRescheduledProposalEmailData): Promise<any>;
2606
+ sendReviewRequestEmail(data: ReviewRequestEmailData): Promise<any>;
2607
+ sendReviewAddedEmail(data: ReviewAddedEmailData): Promise<any>;
2608
+ }
2609
+
2610
+ export { APPOINTMENTS_COLLECTION, type Appointment, AppointmentAggregationService, type AppointmentCancellationEmailData, type AppointmentConfirmationEmailData, type AppointmentEmailDataBase, AppointmentMailingService, type AppointmentMediaItem, type AppointmentReminderNotification, type AppointmentRequestedEmailData, type AppointmentRescheduledProposalEmailData, AppointmentStatus, type AvailableSlot, BaseMailingService, type BaseNotification, BookingAdmin, BookingAvailabilityCalculator, type BookingAvailabilityRequest, type BookingAvailabilityResponse, CalendarAdminService, type Clinic, ClinicAggregationService, type ClinicInfo, type ClinicLocation, type CreateAppointmentData, type CreateAppointmentHttpData, type DoctorInfo, DocumentManagerAdminService, type InitializeAppointmentFormsResult, type LinkedFormInfo, Logger, MediaType, NOTIFICATIONS_COLLECTION, type Notification, NotificationStatus, NotificationType, NotificationsAdmin, type OrchestrateAppointmentCreationData, PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME, type PatientProfile as Patient, PatientAggregationService, PatientInstructionStatus, type PatientRequirementInstance, type PatientRequirementInstruction, PatientRequirementOverallStatus, PatientRequirementsAdminService, type PatientReviewInfo, PaymentStatus, type PostRequirementNotification, type Practitioner, PractitionerAggregationService, PractitionerInviteMailingService, type PractitionerToken, PractitionerTokenStatus, type PreRequirementNotification, type Procedure, ProcedureAggregationService, type ProcedureExtendedInfo, type ProcedureSummaryInfo, type ReviewAddedEmailData, type ReviewRequestEmailData, type SearchAppointmentsParams, type TimeInterval, type UpdateAppointmentData, UserRole };