@blackcode_sa/metaestetics-api 1.6.15 → 1.6.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -7389,6 +7389,43 @@ declare class AppointmentService extends BaseService {
7389
7389
  * @returns The updated appointment
7390
7390
  */
7391
7391
  updateInternalNotes(appointmentId: string, notes: string | null): Promise<Appointment>;
7392
+ /**
7393
+ * Gets upcoming appointments for a specific patient.
7394
+ * These include appointments with statuses: PENDING, CONFIRMED, CHECKED_IN, IN_PROGRESS
7395
+ *
7396
+ * @param patientId ID of the patient
7397
+ * @param options Optional parameters for filtering and pagination
7398
+ * @returns Found appointments and the last document for pagination
7399
+ */
7400
+ getUpcomingPatientAppointments(patientId: string, options?: {
7401
+ startDate?: Date;
7402
+ endDate?: Date;
7403
+ limit?: number;
7404
+ startAfter?: DocumentSnapshot;
7405
+ }): Promise<{
7406
+ appointments: Appointment[];
7407
+ lastDoc: DocumentSnapshot | null;
7408
+ }>;
7409
+ /**
7410
+ * Gets past appointments for a specific patient.
7411
+ * These include appointments with statuses: COMPLETED, CANCELED_PATIENT,
7412
+ * CANCELED_PATIENT_RESCHEDULED, CANCELED_CLINIC, NO_SHOW
7413
+ *
7414
+ * @param patientId ID of the patient
7415
+ * @param options Optional parameters for filtering and pagination
7416
+ * @returns Found appointments and the last document for pagination
7417
+ */
7418
+ getPastPatientAppointments(patientId: string, options?: {
7419
+ startDate?: Date;
7420
+ endDate?: Date;
7421
+ showCanceled?: boolean;
7422
+ showNoShow?: boolean;
7423
+ limit?: number;
7424
+ startAfter?: DocumentSnapshot;
7425
+ }): Promise<{
7426
+ appointments: Appointment[];
7427
+ lastDoc: DocumentSnapshot | null;
7428
+ }>;
7392
7429
  }
7393
7430
 
7394
7431
  /**
package/dist/index.d.ts CHANGED
@@ -7389,6 +7389,43 @@ declare class AppointmentService extends BaseService {
7389
7389
  * @returns The updated appointment
7390
7390
  */
7391
7391
  updateInternalNotes(appointmentId: string, notes: string | null): Promise<Appointment>;
7392
+ /**
7393
+ * Gets upcoming appointments for a specific patient.
7394
+ * These include appointments with statuses: PENDING, CONFIRMED, CHECKED_IN, IN_PROGRESS
7395
+ *
7396
+ * @param patientId ID of the patient
7397
+ * @param options Optional parameters for filtering and pagination
7398
+ * @returns Found appointments and the last document for pagination
7399
+ */
7400
+ getUpcomingPatientAppointments(patientId: string, options?: {
7401
+ startDate?: Date;
7402
+ endDate?: Date;
7403
+ limit?: number;
7404
+ startAfter?: DocumentSnapshot;
7405
+ }): Promise<{
7406
+ appointments: Appointment[];
7407
+ lastDoc: DocumentSnapshot | null;
7408
+ }>;
7409
+ /**
7410
+ * Gets past appointments for a specific patient.
7411
+ * These include appointments with statuses: COMPLETED, CANCELED_PATIENT,
7412
+ * CANCELED_PATIENT_RESCHEDULED, CANCELED_CLINIC, NO_SHOW
7413
+ *
7414
+ * @param patientId ID of the patient
7415
+ * @param options Optional parameters for filtering and pagination
7416
+ * @returns Found appointments and the last document for pagination
7417
+ */
7418
+ getPastPatientAppointments(patientId: string, options?: {
7419
+ startDate?: Date;
7420
+ endDate?: Date;
7421
+ showCanceled?: boolean;
7422
+ showNoShow?: boolean;
7423
+ limit?: number;
7424
+ startAfter?: DocumentSnapshot;
7425
+ }): Promise<{
7426
+ appointments: Appointment[];
7427
+ lastDoc: DocumentSnapshot | null;
7428
+ }>;
7392
7429
  }
7393
7430
 
7394
7431
  /**
package/dist/index.js CHANGED
@@ -8108,20 +8108,20 @@ var ProcedureService = class extends BaseService {
8108
8108
  const proceduresCollection = (0, import_firestore24.collection)(this.db, PROCEDURES_COLLECTION);
8109
8109
  let proceduresQuery = (0, import_firestore24.query)(proceduresCollection);
8110
8110
  if (pagination && pagination > 0) {
8111
- const { limit: limit12, startAfter: startAfter12 } = await import("firebase/firestore");
8111
+ const { limit: limit13, startAfter: startAfter13 } = await import("firebase/firestore");
8112
8112
  if (lastDoc) {
8113
8113
  proceduresQuery = (0, import_firestore24.query)(
8114
8114
  proceduresCollection,
8115
8115
  (0, import_firestore24.orderBy)("name"),
8116
8116
  // Use imported orderBy
8117
- startAfter12(lastDoc),
8118
- limit12(pagination)
8117
+ startAfter13(lastDoc),
8118
+ limit13(pagination)
8119
8119
  );
8120
8120
  } else {
8121
8121
  proceduresQuery = (0, import_firestore24.query)(
8122
8122
  proceduresCollection,
8123
8123
  (0, import_firestore24.orderBy)("name"),
8124
- limit12(pagination)
8124
+ limit13(pagination)
8125
8125
  );
8126
8126
  }
8127
8127
  } else {
@@ -13060,6 +13060,147 @@ var AppointmentService = class extends BaseService {
13060
13060
  };
13061
13061
  return this.updateAppointment(appointmentId, updateData);
13062
13062
  }
13063
+ /**
13064
+ * Gets upcoming appointments for a specific patient.
13065
+ * These include appointments with statuses: PENDING, CONFIRMED, CHECKED_IN, IN_PROGRESS
13066
+ *
13067
+ * @param patientId ID of the patient
13068
+ * @param options Optional parameters for filtering and pagination
13069
+ * @returns Found appointments and the last document for pagination
13070
+ */
13071
+ async getUpcomingPatientAppointments(patientId, options) {
13072
+ try {
13073
+ console.log(
13074
+ `[APPOINTMENT_SERVICE] Getting upcoming appointments for patient: ${patientId}`
13075
+ );
13076
+ const effectiveStartDate = (options == null ? void 0 : options.startDate) || /* @__PURE__ */ new Date();
13077
+ const upcomingStatuses = [
13078
+ "pending" /* PENDING */,
13079
+ "confirmed" /* CONFIRMED */,
13080
+ "checked_in" /* CHECKED_IN */,
13081
+ "in_progress" /* IN_PROGRESS */,
13082
+ "rescheduled_by_clinic" /* RESCHEDULED_BY_CLINIC */
13083
+ ];
13084
+ const constraints = [];
13085
+ constraints.push((0, import_firestore40.where)("patientId", "==", patientId));
13086
+ constraints.push((0, import_firestore40.where)("status", "in", upcomingStatuses));
13087
+ constraints.push(
13088
+ (0, import_firestore40.where)(
13089
+ "appointmentStartTime",
13090
+ ">=",
13091
+ import_firestore40.Timestamp.fromDate(effectiveStartDate)
13092
+ )
13093
+ );
13094
+ if (options == null ? void 0 : options.endDate) {
13095
+ constraints.push(
13096
+ (0, import_firestore40.where)(
13097
+ "appointmentStartTime",
13098
+ "<=",
13099
+ import_firestore40.Timestamp.fromDate(options.endDate)
13100
+ )
13101
+ );
13102
+ }
13103
+ constraints.push((0, import_firestore40.orderBy)("appointmentStartTime", "asc"));
13104
+ if (options == null ? void 0 : options.limit) {
13105
+ constraints.push((0, import_firestore40.limit)(options.limit));
13106
+ }
13107
+ if (options == null ? void 0 : options.startAfter) {
13108
+ constraints.push((0, import_firestore40.startAfter)(options.startAfter));
13109
+ }
13110
+ const q = (0, import_firestore40.query)(
13111
+ (0, import_firestore40.collection)(this.db, APPOINTMENTS_COLLECTION),
13112
+ ...constraints
13113
+ );
13114
+ const querySnapshot = await (0, import_firestore40.getDocs)(q);
13115
+ const appointments = querySnapshot.docs.map(
13116
+ (doc33) => doc33.data()
13117
+ );
13118
+ const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
13119
+ console.log(
13120
+ `[APPOINTMENT_SERVICE] Found ${appointments.length} upcoming appointments for patient ${patientId}`
13121
+ );
13122
+ return { appointments, lastDoc };
13123
+ } catch (error) {
13124
+ console.error(
13125
+ `[APPOINTMENT_SERVICE] Error getting upcoming appointments for patient ${patientId}:`,
13126
+ error
13127
+ );
13128
+ throw error;
13129
+ }
13130
+ }
13131
+ /**
13132
+ * Gets past appointments for a specific patient.
13133
+ * These include appointments with statuses: COMPLETED, CANCELED_PATIENT,
13134
+ * CANCELED_PATIENT_RESCHEDULED, CANCELED_CLINIC, NO_SHOW
13135
+ *
13136
+ * @param patientId ID of the patient
13137
+ * @param options Optional parameters for filtering and pagination
13138
+ * @returns Found appointments and the last document for pagination
13139
+ */
13140
+ async getPastPatientAppointments(patientId, options) {
13141
+ try {
13142
+ console.log(
13143
+ `[APPOINTMENT_SERVICE] Getting past appointments for patient: ${patientId}`
13144
+ );
13145
+ const effectiveEndDate = (options == null ? void 0 : options.endDate) || /* @__PURE__ */ new Date();
13146
+ const pastStatuses = ["completed" /* COMPLETED */];
13147
+ if (options == null ? void 0 : options.showCanceled) {
13148
+ pastStatuses.push(
13149
+ "canceled_patient" /* CANCELED_PATIENT */,
13150
+ "canceled_patient_rescheduled" /* CANCELED_PATIENT_RESCHEDULED */,
13151
+ "canceled_clinic" /* CANCELED_CLINIC */
13152
+ );
13153
+ }
13154
+ if (options == null ? void 0 : options.showNoShow) {
13155
+ pastStatuses.push("no_show" /* NO_SHOW */);
13156
+ }
13157
+ const constraints = [];
13158
+ constraints.push((0, import_firestore40.where)("patientId", "==", patientId));
13159
+ constraints.push((0, import_firestore40.where)("status", "in", pastStatuses));
13160
+ if (options == null ? void 0 : options.startDate) {
13161
+ constraints.push(
13162
+ (0, import_firestore40.where)(
13163
+ "appointmentStartTime",
13164
+ ">=",
13165
+ import_firestore40.Timestamp.fromDate(options.startDate)
13166
+ )
13167
+ );
13168
+ }
13169
+ constraints.push(
13170
+ (0, import_firestore40.where)(
13171
+ "appointmentStartTime",
13172
+ "<=",
13173
+ import_firestore40.Timestamp.fromDate(effectiveEndDate)
13174
+ )
13175
+ );
13176
+ constraints.push((0, import_firestore40.orderBy)("appointmentStartTime", "desc"));
13177
+ if (options == null ? void 0 : options.limit) {
13178
+ constraints.push((0, import_firestore40.limit)(options.limit));
13179
+ }
13180
+ if (options == null ? void 0 : options.startAfter) {
13181
+ constraints.push((0, import_firestore40.startAfter)(options.startAfter));
13182
+ }
13183
+ const q = (0, import_firestore40.query)(
13184
+ (0, import_firestore40.collection)(this.db, APPOINTMENTS_COLLECTION),
13185
+ ...constraints
13186
+ );
13187
+ const querySnapshot = await (0, import_firestore40.getDocs)(q);
13188
+ const appointments = querySnapshot.docs.map(
13189
+ (doc33) => doc33.data()
13190
+ );
13191
+ const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
13192
+ console.log(
13193
+ `[APPOINTMENT_SERVICE] Found ${appointments.length} past appointments for patient ${patientId}`
13194
+ );
13195
+ return { appointments, lastDoc };
13196
+ } catch (error) {
13197
+ console.error(
13198
+ `[APPOINTMENT_SERVICE] Error getting past appointments for patient ${patientId}:`,
13199
+ error
13200
+ );
13201
+ throw error;
13202
+ }
13203
+ }
13063
13204
  };
13064
13205
 
13065
13206
  // src/services/patient/patientRequirements.service.ts