@blackcode_sa/metaestetics-api 1.6.16 → 1.6.18

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.
@@ -3383,10 +3383,8 @@ var AppointmentAggregationService = class {
3383
3383
  status: "pendingNotification" /* PENDING_NOTIFICATION */,
3384
3384
  originalNotifyAtValue: notifyAtValue,
3385
3385
  originalTimeframeUnit: template.timeframe.unit,
3386
- updatedAt: admin10.firestore.Timestamp.now(),
3386
+ updatedAt: admin10.firestore.Timestamp.now()
3387
3387
  // Use current server timestamp
3388
- notificationId: void 0,
3389
- actionTakenAt: void 0
3390
3388
  };
3391
3389
  return instructionObject;
3392
3390
  });
@@ -3328,10 +3328,8 @@ var AppointmentAggregationService = class {
3328
3328
  status: "pendingNotification" /* PENDING_NOTIFICATION */,
3329
3329
  originalNotifyAtValue: notifyAtValue,
3330
3330
  originalTimeframeUnit: template.timeframe.unit,
3331
- updatedAt: admin10.firestore.Timestamp.now(),
3331
+ updatedAt: admin10.firestore.Timestamp.now()
3332
3332
  // Use current server timestamp
3333
- notificationId: void 0,
3334
- actionTakenAt: void 0
3335
3333
  };
3336
3334
  return instructionObject;
3337
3335
  });
package/dist/index.d.mts CHANGED
@@ -5,6 +5,7 @@ import { FirebaseApp } from 'firebase/app';
5
5
  import { Auth, User as User$1 } from 'firebase/auth';
6
6
  import { Analytics } from 'firebase/analytics';
7
7
  import { FirebaseStorage } from 'firebase/storage';
8
+ import { Functions } from 'firebase/functions';
8
9
 
9
10
  /**
10
11
  * Review system type definitions
@@ -5042,6 +5043,8 @@ interface FirebaseInstance {
5042
5043
  db: Firestore;
5043
5044
  auth: Auth;
5044
5045
  analytics: Analytics | null;
5046
+ storage: FirebaseStorage;
5047
+ functions: Functions;
5045
5048
  }
5046
5049
  declare const initializeFirebase: (config: {
5047
5050
  apiKey: string;
@@ -7389,6 +7392,43 @@ declare class AppointmentService extends BaseService {
7389
7392
  * @returns The updated appointment
7390
7393
  */
7391
7394
  updateInternalNotes(appointmentId: string, notes: string | null): Promise<Appointment>;
7395
+ /**
7396
+ * Gets upcoming appointments for a specific patient.
7397
+ * These include appointments with statuses: PENDING, CONFIRMED, CHECKED_IN, IN_PROGRESS
7398
+ *
7399
+ * @param patientId ID of the patient
7400
+ * @param options Optional parameters for filtering and pagination
7401
+ * @returns Found appointments and the last document for pagination
7402
+ */
7403
+ getUpcomingPatientAppointments(patientId: string, options?: {
7404
+ startDate?: Date;
7405
+ endDate?: Date;
7406
+ limit?: number;
7407
+ startAfter?: DocumentSnapshot;
7408
+ }): Promise<{
7409
+ appointments: Appointment[];
7410
+ lastDoc: DocumentSnapshot | null;
7411
+ }>;
7412
+ /**
7413
+ * Gets past appointments for a specific patient.
7414
+ * These include appointments with statuses: COMPLETED, CANCELED_PATIENT,
7415
+ * CANCELED_PATIENT_RESCHEDULED, CANCELED_CLINIC, NO_SHOW
7416
+ *
7417
+ * @param patientId ID of the patient
7418
+ * @param options Optional parameters for filtering and pagination
7419
+ * @returns Found appointments and the last document for pagination
7420
+ */
7421
+ getPastPatientAppointments(patientId: string, options?: {
7422
+ startDate?: Date;
7423
+ endDate?: Date;
7424
+ showCanceled?: boolean;
7425
+ showNoShow?: boolean;
7426
+ limit?: number;
7427
+ startAfter?: DocumentSnapshot;
7428
+ }): Promise<{
7429
+ appointments: Appointment[];
7430
+ lastDoc: DocumentSnapshot | null;
7431
+ }>;
7392
7432
  }
7393
7433
 
7394
7434
  /**
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ import { FirebaseApp } from 'firebase/app';
5
5
  import { Auth, User as User$1 } from 'firebase/auth';
6
6
  import { Analytics } from 'firebase/analytics';
7
7
  import { FirebaseStorage } from 'firebase/storage';
8
+ import { Functions } from 'firebase/functions';
8
9
 
9
10
  /**
10
11
  * Review system type definitions
@@ -5042,6 +5043,8 @@ interface FirebaseInstance {
5042
5043
  db: Firestore;
5043
5044
  auth: Auth;
5044
5045
  analytics: Analytics | null;
5046
+ storage: FirebaseStorage;
5047
+ functions: Functions;
5045
5048
  }
5046
5049
  declare const initializeFirebase: (config: {
5047
5050
  apiKey: string;
@@ -7389,6 +7392,43 @@ declare class AppointmentService extends BaseService {
7389
7392
  * @returns The updated appointment
7390
7393
  */
7391
7394
  updateInternalNotes(appointmentId: string, notes: string | null): Promise<Appointment>;
7395
+ /**
7396
+ * Gets upcoming appointments for a specific patient.
7397
+ * These include appointments with statuses: PENDING, CONFIRMED, CHECKED_IN, IN_PROGRESS
7398
+ *
7399
+ * @param patientId ID of the patient
7400
+ * @param options Optional parameters for filtering and pagination
7401
+ * @returns Found appointments and the last document for pagination
7402
+ */
7403
+ getUpcomingPatientAppointments(patientId: string, options?: {
7404
+ startDate?: Date;
7405
+ endDate?: Date;
7406
+ limit?: number;
7407
+ startAfter?: DocumentSnapshot;
7408
+ }): Promise<{
7409
+ appointments: Appointment[];
7410
+ lastDoc: DocumentSnapshot | null;
7411
+ }>;
7412
+ /**
7413
+ * Gets past appointments for a specific patient.
7414
+ * These include appointments with statuses: COMPLETED, CANCELED_PATIENT,
7415
+ * CANCELED_PATIENT_RESCHEDULED, CANCELED_CLINIC, NO_SHOW
7416
+ *
7417
+ * @param patientId ID of the patient
7418
+ * @param options Optional parameters for filtering and pagination
7419
+ * @returns Found appointments and the last document for pagination
7420
+ */
7421
+ getPastPatientAppointments(patientId: string, options?: {
7422
+ startDate?: Date;
7423
+ endDate?: Date;
7424
+ showCanceled?: boolean;
7425
+ showNoShow?: boolean;
7426
+ limit?: number;
7427
+ startAfter?: DocumentSnapshot;
7428
+ }): Promise<{
7429
+ appointments: Appointment[];
7430
+ lastDoc: DocumentSnapshot | null;
7431
+ }>;
7392
7432
  }
7393
7433
 
7394
7434
  /**
package/dist/index.js CHANGED
@@ -705,17 +705,21 @@ var import_firestore = require("firebase/firestore");
705
705
  var import_auth = require("firebase/auth");
706
706
  var import_analytics = require("firebase/analytics");
707
707
  var import_react_native = require("react-native");
708
+ var import_storage = require("firebase/storage");
709
+ var import_functions = require("firebase/functions");
708
710
  var firebaseInstance = null;
709
711
  var initializeFirebase = (config) => {
710
712
  if (!firebaseInstance) {
711
713
  const app = (0, import_app.initializeApp)(config);
712
714
  const db = (0, import_firestore.getFirestore)(app);
713
715
  const auth = (0, import_auth.getAuth)(app);
716
+ const storage = (0, import_storage.getStorage)(app);
717
+ const functions = (0, import_functions.getFunctions)(app);
714
718
  let analytics = null;
715
719
  if (typeof window !== "undefined" && import_react_native.Platform.OS === "web") {
716
720
  analytics = (0, import_analytics.getAnalytics)(app);
717
721
  }
718
- firebaseInstance = { app, db, auth, analytics };
722
+ firebaseInstance = { app, db, auth, analytics, storage, functions };
719
723
  }
720
724
  return firebaseInstance;
721
725
  };
@@ -1061,13 +1065,13 @@ var FirebaseErrorCode = /* @__PURE__ */ ((FirebaseErrorCode2) => {
1061
1065
  })(FirebaseErrorCode || {});
1062
1066
 
1063
1067
  // src/services/base.service.ts
1064
- var import_storage = require("firebase/storage");
1068
+ var import_storage2 = require("firebase/storage");
1065
1069
  var BaseService = class {
1066
1070
  constructor(db, auth, app) {
1067
1071
  this.db = db;
1068
1072
  this.auth = auth;
1069
1073
  this.app = app;
1070
- this.storage = (0, import_storage.getStorage)(app);
1074
+ this.storage = (0, import_storage2.getStorage)(app);
1071
1075
  }
1072
1076
  /**
1073
1077
  * Generiše jedinstveni ID za dokumente
@@ -1188,7 +1192,7 @@ var import_firestore11 = require("firebase/firestore");
1188
1192
 
1189
1193
  // src/services/patient/utils/profile.utils.ts
1190
1194
  var import_firestore6 = require("firebase/firestore");
1191
- var import_storage2 = require("firebase/storage");
1195
+ var import_storage3 = require("firebase/storage");
1192
1196
  var import_zod8 = require("zod");
1193
1197
 
1194
1198
  // src/types/patient/medical-info.types.ts
@@ -2116,9 +2120,9 @@ var updatePatientProfileByUserRefUtil = async (db, userRef, data) => {
2116
2120
  }
2117
2121
  };
2118
2122
  var uploadProfilePhotoUtil = async (storage, patientId, file) => {
2119
- const photoRef = (0, import_storage2.ref)(storage, `patient-photos/${patientId}/profile-photo`);
2120
- await (0, import_storage2.uploadBytes)(photoRef, file);
2121
- return (0, import_storage2.getDownloadURL)(photoRef);
2123
+ const photoRef = (0, import_storage3.ref)(storage, `patient-photos/${patientId}/profile-photo`);
2124
+ await (0, import_storage3.uploadBytes)(photoRef, file);
2125
+ return (0, import_storage3.getDownloadURL)(photoRef);
2122
2126
  };
2123
2127
  var updateProfilePhotoUtil = async (storage, db, patientId, file) => {
2124
2128
  const patientDoc = await (0, import_firestore6.getDoc)(getPatientDocRef(db, patientId));
@@ -2126,8 +2130,8 @@ var updateProfilePhotoUtil = async (storage, db, patientId, file) => {
2126
2130
  const patientData = patientDoc.data();
2127
2131
  if (patientData.profilePhoto) {
2128
2132
  try {
2129
- const oldPhotoRef = (0, import_storage2.ref)(storage, patientData.profilePhoto);
2130
- await (0, import_storage2.deleteObject)(oldPhotoRef);
2133
+ const oldPhotoRef = (0, import_storage3.ref)(storage, patientData.profilePhoto);
2134
+ await (0, import_storage3.deleteObject)(oldPhotoRef);
2131
2135
  } catch (error) {
2132
2136
  console.warn("Failed to delete old profile photo:", error);
2133
2137
  }
@@ -2145,8 +2149,8 @@ var deleteProfilePhotoUtil = async (storage, db, patientId) => {
2145
2149
  const patientData = patientDoc.data();
2146
2150
  if (patientData.profilePhoto) {
2147
2151
  try {
2148
- const photoRef = (0, import_storage2.ref)(storage, patientData.profilePhoto);
2149
- await (0, import_storage2.deleteObject)(photoRef);
2152
+ const photoRef = (0, import_storage3.ref)(storage, patientData.profilePhoto);
2153
+ await (0, import_storage3.deleteObject)(photoRef);
2150
2154
  } catch (error) {
2151
2155
  console.warn("Failed to delete profile photo:", error);
2152
2156
  }
@@ -5130,7 +5134,7 @@ var import_geofire_common3 = require("geofire-common");
5130
5134
  var import_zod16 = require("zod");
5131
5135
 
5132
5136
  // src/services/clinic/utils/photos.utils.ts
5133
- var import_storage3 = require("firebase/storage");
5137
+ var import_storage4 = require("firebase/storage");
5134
5138
  async function uploadPhoto(photo, entityType, entityId, photoType, app, fileName) {
5135
5139
  if (!photo || typeof photo !== "string" || !photo.startsWith("data:")) {
5136
5140
  return photo;
@@ -5139,9 +5143,9 @@ async function uploadPhoto(photo, entityType, entityId, photoType, app, fileName
5139
5143
  console.log(
5140
5144
  `[PHOTO_UTILS] Uploading ${photoType} for ${entityType}/${entityId}`
5141
5145
  );
5142
- const storage = (0, import_storage3.getStorage)(app);
5146
+ const storage = (0, import_storage4.getStorage)(app);
5143
5147
  const storageFileName = fileName || `${photoType}-${Date.now()}`;
5144
- const storageRef = (0, import_storage3.ref)(
5148
+ const storageRef = (0, import_storage4.ref)(
5145
5149
  storage,
5146
5150
  `${entityType}/${entityId}/${storageFileName}`
5147
5151
  );
@@ -5153,8 +5157,8 @@ async function uploadPhoto(photo, entityType, entityId, photoType, app, fileName
5153
5157
  byteArrays.push(byteCharacters.charCodeAt(i));
5154
5158
  }
5155
5159
  const blob = new Blob([new Uint8Array(byteArrays)], { type: contentType });
5156
- await (0, import_storage3.uploadBytes)(storageRef, blob, { contentType });
5157
- const downloadUrl = await (0, import_storage3.getDownloadURL)(storageRef);
5160
+ await (0, import_storage4.uploadBytes)(storageRef, blob, { contentType });
5161
+ const downloadUrl = await (0, import_storage4.getDownloadURL)(storageRef);
5158
5162
  console.log(`[PHOTO_UTILS] ${photoType} uploaded successfully`, {
5159
5163
  downloadUrl
5160
5164
  });
@@ -8108,20 +8112,20 @@ var ProcedureService = class extends BaseService {
8108
8112
  const proceduresCollection = (0, import_firestore24.collection)(this.db, PROCEDURES_COLLECTION);
8109
8113
  let proceduresQuery = (0, import_firestore24.query)(proceduresCollection);
8110
8114
  if (pagination && pagination > 0) {
8111
- const { limit: limit12, startAfter: startAfter12 } = await import("firebase/firestore");
8115
+ const { limit: limit13, startAfter: startAfter13 } = await import("firebase/firestore");
8112
8116
  if (lastDoc) {
8113
8117
  proceduresQuery = (0, import_firestore24.query)(
8114
8118
  proceduresCollection,
8115
8119
  (0, import_firestore24.orderBy)("name"),
8116
8120
  // Use imported orderBy
8117
- startAfter12(lastDoc),
8118
- limit12(pagination)
8121
+ startAfter13(lastDoc),
8122
+ limit13(pagination)
8119
8123
  );
8120
8124
  } else {
8121
8125
  proceduresQuery = (0, import_firestore24.query)(
8122
8126
  proceduresCollection,
8123
8127
  (0, import_firestore24.orderBy)("name"),
8124
- limit12(pagination)
8128
+ limit13(pagination)
8125
8129
  );
8126
8130
  }
8127
8131
  } else {
@@ -12163,7 +12167,7 @@ var ReviewService = class extends BaseService {
12163
12167
 
12164
12168
  // src/services/appointment/appointment.service.ts
12165
12169
  var import_firestore40 = require("firebase/firestore");
12166
- var import_functions = require("firebase/functions");
12170
+ var import_functions2 = require("firebase/functions");
12167
12171
 
12168
12172
  // src/services/appointment/utils/appointment.utils.ts
12169
12173
  var import_firestore39 = require("firebase/firestore");
@@ -12377,7 +12381,7 @@ var AppointmentService = class extends BaseService {
12377
12381
  this.practitionerService = practitionerService;
12378
12382
  this.clinicService = clinicService;
12379
12383
  this.filledDocumentService = filledDocumentService;
12380
- this.functions = (0, import_functions.getFunctions)(app, "europe-west6");
12384
+ this.functions = (0, import_functions2.getFunctions)(app, "europe-west6");
12381
12385
  }
12382
12386
  /**
12383
12387
  * Gets available booking slots for a specific clinic, practitioner, and procedure using HTTP request.
@@ -13060,6 +13064,147 @@ var AppointmentService = class extends BaseService {
13060
13064
  };
13061
13065
  return this.updateAppointment(appointmentId, updateData);
13062
13066
  }
13067
+ /**
13068
+ * Gets upcoming appointments for a specific patient.
13069
+ * These include appointments with statuses: PENDING, CONFIRMED, CHECKED_IN, IN_PROGRESS
13070
+ *
13071
+ * @param patientId ID of the patient
13072
+ * @param options Optional parameters for filtering and pagination
13073
+ * @returns Found appointments and the last document for pagination
13074
+ */
13075
+ async getUpcomingPatientAppointments(patientId, options) {
13076
+ try {
13077
+ console.log(
13078
+ `[APPOINTMENT_SERVICE] Getting upcoming appointments for patient: ${patientId}`
13079
+ );
13080
+ const effectiveStartDate = (options == null ? void 0 : options.startDate) || /* @__PURE__ */ new Date();
13081
+ const upcomingStatuses = [
13082
+ "pending" /* PENDING */,
13083
+ "confirmed" /* CONFIRMED */,
13084
+ "checked_in" /* CHECKED_IN */,
13085
+ "in_progress" /* IN_PROGRESS */,
13086
+ "rescheduled_by_clinic" /* RESCHEDULED_BY_CLINIC */
13087
+ ];
13088
+ const constraints = [];
13089
+ constraints.push((0, import_firestore40.where)("patientId", "==", patientId));
13090
+ constraints.push((0, import_firestore40.where)("status", "in", upcomingStatuses));
13091
+ constraints.push(
13092
+ (0, import_firestore40.where)(
13093
+ "appointmentStartTime",
13094
+ ">=",
13095
+ import_firestore40.Timestamp.fromDate(effectiveStartDate)
13096
+ )
13097
+ );
13098
+ if (options == null ? void 0 : options.endDate) {
13099
+ constraints.push(
13100
+ (0, import_firestore40.where)(
13101
+ "appointmentStartTime",
13102
+ "<=",
13103
+ import_firestore40.Timestamp.fromDate(options.endDate)
13104
+ )
13105
+ );
13106
+ }
13107
+ constraints.push((0, import_firestore40.orderBy)("appointmentStartTime", "asc"));
13108
+ if (options == null ? void 0 : options.limit) {
13109
+ constraints.push((0, import_firestore40.limit)(options.limit));
13110
+ }
13111
+ if (options == null ? void 0 : options.startAfter) {
13112
+ constraints.push((0, import_firestore40.startAfter)(options.startAfter));
13113
+ }
13114
+ const q = (0, import_firestore40.query)(
13115
+ (0, import_firestore40.collection)(this.db, APPOINTMENTS_COLLECTION),
13116
+ ...constraints
13117
+ );
13118
+ const querySnapshot = await (0, import_firestore40.getDocs)(q);
13119
+ const appointments = querySnapshot.docs.map(
13120
+ (doc33) => doc33.data()
13121
+ );
13122
+ const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
13123
+ console.log(
13124
+ `[APPOINTMENT_SERVICE] Found ${appointments.length} upcoming appointments for patient ${patientId}`
13125
+ );
13126
+ return { appointments, lastDoc };
13127
+ } catch (error) {
13128
+ console.error(
13129
+ `[APPOINTMENT_SERVICE] Error getting upcoming appointments for patient ${patientId}:`,
13130
+ error
13131
+ );
13132
+ throw error;
13133
+ }
13134
+ }
13135
+ /**
13136
+ * Gets past appointments for a specific patient.
13137
+ * These include appointments with statuses: COMPLETED, CANCELED_PATIENT,
13138
+ * CANCELED_PATIENT_RESCHEDULED, CANCELED_CLINIC, NO_SHOW
13139
+ *
13140
+ * @param patientId ID of the patient
13141
+ * @param options Optional parameters for filtering and pagination
13142
+ * @returns Found appointments and the last document for pagination
13143
+ */
13144
+ async getPastPatientAppointments(patientId, options) {
13145
+ try {
13146
+ console.log(
13147
+ `[APPOINTMENT_SERVICE] Getting past appointments for patient: ${patientId}`
13148
+ );
13149
+ const effectiveEndDate = (options == null ? void 0 : options.endDate) || /* @__PURE__ */ new Date();
13150
+ const pastStatuses = ["completed" /* COMPLETED */];
13151
+ if (options == null ? void 0 : options.showCanceled) {
13152
+ pastStatuses.push(
13153
+ "canceled_patient" /* CANCELED_PATIENT */,
13154
+ "canceled_patient_rescheduled" /* CANCELED_PATIENT_RESCHEDULED */,
13155
+ "canceled_clinic" /* CANCELED_CLINIC */
13156
+ );
13157
+ }
13158
+ if (options == null ? void 0 : options.showNoShow) {
13159
+ pastStatuses.push("no_show" /* NO_SHOW */);
13160
+ }
13161
+ const constraints = [];
13162
+ constraints.push((0, import_firestore40.where)("patientId", "==", patientId));
13163
+ constraints.push((0, import_firestore40.where)("status", "in", pastStatuses));
13164
+ if (options == null ? void 0 : options.startDate) {
13165
+ constraints.push(
13166
+ (0, import_firestore40.where)(
13167
+ "appointmentStartTime",
13168
+ ">=",
13169
+ import_firestore40.Timestamp.fromDate(options.startDate)
13170
+ )
13171
+ );
13172
+ }
13173
+ constraints.push(
13174
+ (0, import_firestore40.where)(
13175
+ "appointmentStartTime",
13176
+ "<=",
13177
+ import_firestore40.Timestamp.fromDate(effectiveEndDate)
13178
+ )
13179
+ );
13180
+ constraints.push((0, import_firestore40.orderBy)("appointmentStartTime", "desc"));
13181
+ if (options == null ? void 0 : options.limit) {
13182
+ constraints.push((0, import_firestore40.limit)(options.limit));
13183
+ }
13184
+ if (options == null ? void 0 : options.startAfter) {
13185
+ constraints.push((0, import_firestore40.startAfter)(options.startAfter));
13186
+ }
13187
+ const q = (0, import_firestore40.query)(
13188
+ (0, import_firestore40.collection)(this.db, APPOINTMENTS_COLLECTION),
13189
+ ...constraints
13190
+ );
13191
+ const querySnapshot = await (0, import_firestore40.getDocs)(q);
13192
+ const appointments = querySnapshot.docs.map(
13193
+ (doc33) => doc33.data()
13194
+ );
13195
+ const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
13196
+ console.log(
13197
+ `[APPOINTMENT_SERVICE] Found ${appointments.length} past appointments for patient ${patientId}`
13198
+ );
13199
+ return { appointments, lastDoc };
13200
+ } catch (error) {
13201
+ console.error(
13202
+ `[APPOINTMENT_SERVICE] Error getting past appointments for patient ${patientId}:`,
13203
+ error
13204
+ );
13205
+ throw error;
13206
+ }
13207
+ }
13063
13208
  };
13064
13209
 
13065
13210
  // src/services/patient/patientRequirements.service.ts