@blackcode_sa/metaestetics-api 1.11.0 → 1.11.1

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.
Files changed (35) hide show
  1. package/dist/admin/index.d.mts +328 -319
  2. package/dist/admin/index.d.ts +328 -319
  3. package/dist/backoffice/index.d.mts +283 -67
  4. package/dist/backoffice/index.d.ts +283 -67
  5. package/dist/backoffice/index.js +114 -6
  6. package/dist/backoffice/index.mjs +112 -6
  7. package/dist/index.d.mts +3872 -3806
  8. package/dist/index.d.ts +3872 -3806
  9. package/dist/index.js +369 -123
  10. package/dist/index.mjs +369 -124
  11. package/package.json +1 -1
  12. package/src/backoffice/expo-safe/index.ts +2 -0
  13. package/src/backoffice/services/README.md +40 -0
  14. package/src/backoffice/services/constants.service.ts +268 -0
  15. package/src/backoffice/services/technology.service.ts +122 -10
  16. package/src/backoffice/types/admin-constants.types.ts +69 -0
  17. package/src/backoffice/types/index.ts +1 -0
  18. package/src/backoffice/types/product.types.ts +3 -1
  19. package/src/backoffice/types/technology.types.ts +4 -4
  20. package/src/backoffice/validations/schemas.ts +35 -9
  21. package/src/services/appointment/appointment.service.ts +0 -5
  22. package/src/services/appointment/utils/appointment.utils.ts +124 -113
  23. package/src/services/procedure/procedure.service.ts +434 -234
  24. package/src/types/appointment/index.ts +5 -3
  25. package/src/types/clinic/index.ts +1 -6
  26. package/src/types/patient/medical-info.types.ts +3 -3
  27. package/src/types/procedure/index.ts +20 -17
  28. package/src/validations/clinic.schema.ts +1 -6
  29. package/src/validations/patient/medical-info.schema.ts +7 -2
  30. package/src/backoffice/services/__tests__/brand.service.test.ts +0 -196
  31. package/src/backoffice/services/__tests__/category.service.test.ts +0 -201
  32. package/src/backoffice/services/__tests__/product.service.test.ts +0 -358
  33. package/src/backoffice/services/__tests__/requirement.service.test.ts +0 -226
  34. package/src/backoffice/services/__tests__/subcategory.service.test.ts +0 -181
  35. package/src/backoffice/services/__tests__/technology.service.test.ts +0 -1097
@@ -21,18 +21,15 @@ import { BaseService } from "../base.service";
21
21
  import {
22
22
  Appointment,
23
23
  AppointmentStatus,
24
- CreateAppointmentData,
25
24
  UpdateAppointmentData,
26
25
  SearchAppointmentsParams,
27
26
  PaymentStatus,
28
27
  AppointmentMediaItem,
29
28
  PatientReviewInfo,
30
- LinkedFormInfo,
31
29
  type CreateAppointmentHttpData,
32
30
  APPOINTMENTS_COLLECTION,
33
31
  } from "../../types/appointment";
34
32
  import {
35
- createAppointmentSchema,
36
33
  updateAppointmentSchema,
37
34
  searchAppointmentsSchema,
38
35
  rescheduleAppointmentSchema,
@@ -47,8 +44,6 @@ import { FilledDocumentService } from "../documentation-templates/filled-documen
47
44
 
48
45
  // Import utility functions
49
46
  import {
50
- fetchAggregatedInfoUtil,
51
- createAppointmentUtil,
52
47
  updateAppointmentUtil,
53
48
  getAppointmentByIdUtil,
54
49
  searchAppointmentsUtil,
@@ -33,7 +33,6 @@ import {
33
33
  PractitionerProfileInfo,
34
34
  } from "../../../types/profile";
35
35
  import { BlockingCondition } from "../../../backoffice/types/static/blocking-condition.types";
36
- import { Contraindication } from "../../../backoffice/types/static/contraindication.types";
37
36
  import { Requirement } from "../../../backoffice/types/requirement.types";
38
37
  import { PRACTITIONERS_COLLECTION } from "../../../types/practitioner";
39
38
  import { CLINICS_COLLECTION } from "../../../types/clinic";
@@ -43,6 +42,7 @@ import {
43
42
  Technology,
44
43
  TECHNOLOGIES_COLLECTION,
45
44
  } from "../../../backoffice/types/technology.types";
45
+ import type { ContraindicationDynamic } from "../../../backoffice";
46
46
 
47
47
  /**
48
48
  * Fetches all the necessary information for an appointment by IDs.
@@ -66,7 +66,7 @@ export async function fetchAggregatedInfoUtil(
66
66
  patientInfo: PatientProfileInfo;
67
67
  procedureInfo: ProcedureSummaryInfo;
68
68
  blockingConditions: BlockingCondition[];
69
- contraindications: Contraindication[];
69
+ contraindications: ContraindicationDynamic[];
70
70
  preProcedureRequirements: Requirement[];
71
71
  postProcedureRequirements: Requirement[];
72
72
  }> {
@@ -162,7 +162,7 @@ export async function fetchAggregatedInfoUtil(
162
162
  }
163
163
 
164
164
  let blockingConditions: BlockingCondition[] = [];
165
- let contraindications: Contraindication[] = [];
165
+ let contraindications: ContraindicationDynamic[] = [];
166
166
  let preProcedureRequirements: Requirement[] = [];
167
167
  let postProcedureRequirements: Requirement[] = [];
168
168
 
@@ -213,85 +213,85 @@ export async function fetchAggregatedInfoUtil(
213
213
  * @param generateId Function to generate a unique ID
214
214
  * @returns The created Appointment
215
215
  */
216
- export async function createAppointmentUtil(
217
- db: Firestore,
218
- data: CreateAppointmentData,
219
- aggregatedInfo: {
220
- clinicInfo: ClinicInfo;
221
- practitionerInfo: PractitionerProfileInfo;
222
- patientInfo: PatientProfileInfo;
223
- procedureInfo: ProcedureSummaryInfo;
224
- blockingConditions: BlockingCondition[];
225
- contraindications: Contraindication[];
226
- preProcedureRequirements: Requirement[];
227
- postProcedureRequirements: Requirement[];
228
- },
229
- generateId: () => string
230
- ): Promise<Appointment> {
231
- try {
232
- const appointmentId = generateId();
233
-
234
- // Create appointment object
235
- const appointment: Omit<Appointment, "createdAt" | "updatedAt"> & {
236
- createdAt: any;
237
- updatedAt: any;
238
- } = {
239
- id: appointmentId,
240
- calendarEventId: data.calendarEventId,
241
- clinicBranchId: data.clinicBranchId,
242
- clinicInfo: aggregatedInfo.clinicInfo,
243
- practitionerId: data.practitionerId,
244
- practitionerInfo: aggregatedInfo.practitionerInfo,
245
- patientId: data.patientId,
246
- patientInfo: aggregatedInfo.patientInfo,
247
- procedureId: data.procedureId,
248
- procedureInfo: aggregatedInfo.procedureInfo,
249
- status: data.initialStatus,
250
- bookingTime: Timestamp.now(),
251
- appointmentStartTime: data.appointmentStartTime,
252
- appointmentEndTime: data.appointmentEndTime,
253
- patientNotes: data.patientNotes || null,
254
- cost: data.cost,
255
- currency: data.currency,
256
- paymentStatus: data.initialPaymentStatus || PaymentStatus.UNPAID,
257
- blockingConditions: aggregatedInfo.blockingConditions,
258
- contraindications: aggregatedInfo.contraindications,
259
- preProcedureRequirements: aggregatedInfo.preProcedureRequirements,
260
- postProcedureRequirements: aggregatedInfo.postProcedureRequirements,
261
- completedPreRequirements: [],
262
- completedPostRequirements: [],
263
- createdAt: serverTimestamp(),
264
- updatedAt: serverTimestamp(),
265
- };
266
-
267
- // Add additional fields for confirmation if appointment is already confirmed
268
- if (data.initialStatus === AppointmentStatus.CONFIRMED) {
269
- appointment.confirmationTime = Timestamp.now();
270
- }
271
-
272
- // Save to Firestore
273
- await setDoc(doc(db, APPOINTMENTS_COLLECTION, appointmentId), appointment);
274
-
275
- // Update the calendar event with the appointment ID
276
- const calendarEventRef = doc(db, CALENDAR_COLLECTION, data.calendarEventId);
277
- await updateDoc(calendarEventRef, {
278
- appointmentId: appointmentId,
279
- updatedAt: serverTimestamp(),
280
- });
281
-
282
- // Return the created appointment
283
- // Convert serverTimestamp to regular Timestamp for immediate use
284
- const now = Timestamp.now();
285
- return {
286
- ...appointment,
287
- createdAt: now,
288
- updatedAt: now,
289
- } as Appointment;
290
- } catch (error) {
291
- console.error("Error creating appointment:", error);
292
- throw error;
293
- }
294
- }
216
+ // export async function createAppointmentUtil(
217
+ // db: Firestore,
218
+ // data: CreateAppointmentData,
219
+ // aggregatedInfo: {
220
+ // clinicInfo: ClinicInfo;
221
+ // practitionerInfo: PractitionerProfileInfo;
222
+ // patientInfo: PatientProfileInfo;
223
+ // procedureInfo: ProcedureSummaryInfo;
224
+ // blockingConditions: BlockingCondition[];
225
+ // contraindications: ContraindicationDynamic[];
226
+ // preProcedureRequirements: Requirement[];
227
+ // postProcedureRequirements: Requirement[];
228
+ // },
229
+ // generateId: () => string
230
+ // ): Promise<Appointment> {
231
+ // try {
232
+ // const appointmentId = generateId();
233
+
234
+ // // Create appointment object
235
+ // const appointment: Omit<Appointment, "createdAt" | "updatedAt"> & {
236
+ // createdAt: any;
237
+ // updatedAt: any;
238
+ // } = {
239
+ // id: appointmentId,
240
+ // calendarEventId: data.calendarEventId,
241
+ // clinicBranchId: data.clinicBranchId,
242
+ // clinicInfo: aggregatedInfo.clinicInfo,
243
+ // practitionerId: data.practitionerId,
244
+ // practitionerInfo: aggregatedInfo.practitionerInfo,
245
+ // patientId: data.patientId,
246
+ // patientInfo: aggregatedInfo.patientInfo,
247
+ // procedureId: data.procedureId,
248
+ // procedureInfo: aggregatedInfo.procedureInfo,
249
+ // status: data.initialStatus,
250
+ // bookingTime: Timestamp.now(),
251
+ // appointmentStartTime: data.appointmentStartTime,
252
+ // appointmentEndTime: data.appointmentEndTime,
253
+ // patientNotes: data.patientNotes || null,
254
+ // cost: data.cost,
255
+ // currency: data.currency,
256
+ // paymentStatus: data.initialPaymentStatus || PaymentStatus.UNPAID,
257
+ // blockingConditions: aggregatedInfo.blockingConditions,
258
+ // contraindications: aggregatedInfo.contraindications,
259
+ // preProcedureRequirements: aggregatedInfo.preProcedureRequirements,
260
+ // postProcedureRequirements: aggregatedInfo.postProcedureRequirements,
261
+ // completedPreRequirements: [],
262
+ // completedPostRequirements: [],
263
+ // createdAt: serverTimestamp(),
264
+ // updatedAt: serverTimestamp(),
265
+ // };
266
+
267
+ // // Add additional fields for confirmation if appointment is already confirmed
268
+ // if (data.initialStatus === AppointmentStatus.CONFIRMED) {
269
+ // appointment.confirmationTime = Timestamp.now();
270
+ // }
271
+
272
+ // // Save to Firestore
273
+ // await setDoc(doc(db, APPOINTMENTS_COLLECTION, appointmentId), appointment);
274
+
275
+ // // Update the calendar event with the appointment ID
276
+ // const calendarEventRef = doc(db, CALENDAR_COLLECTION, data.calendarEventId);
277
+ // await updateDoc(calendarEventRef, {
278
+ // appointmentId: appointmentId,
279
+ // updatedAt: serverTimestamp(),
280
+ // });
281
+
282
+ // // Return the created appointment
283
+ // // Convert serverTimestamp to regular Timestamp for immediate use
284
+ // const now = Timestamp.now();
285
+ // return {
286
+ // ...appointment,
287
+ // createdAt: now,
288
+ // updatedAt: now,
289
+ // } as Appointment;
290
+ // } catch (error) {
291
+ // console.error("Error creating appointment:", error);
292
+ // throw error;
293
+ // }
294
+ // }
295
295
 
296
296
  /**
297
297
  * Updates an existing appointment in Firestore.
@@ -327,23 +327,27 @@ export async function updateAppointmentUtil(
327
327
  const validPreReqIds = currentAppointment.preProcedureRequirements.map(
328
328
  (req) => req.id
329
329
  );
330
- const invalidPreReqIds = data.completedPreRequirements.filter(
331
- (id) => !validPreReqIds.includes(id)
332
- );
333
330
 
334
- if (invalidPreReqIds.length > 0) {
335
- throw new Error(
336
- `Invalid pre-requirement IDs: ${invalidPreReqIds.join(", ")}`
331
+ // Only perform validation and merging if the input is an array
332
+ if (Array.isArray(data.completedPreRequirements)) {
333
+ const invalidPreReqIds = data.completedPreRequirements.filter(
334
+ (id) => !validPreReqIds.includes(id)
337
335
  );
338
- }
339
336
 
340
- // Update the completed pre-requirements
341
- completedPreRequirements = [
342
- ...new Set([
343
- ...completedPreRequirements,
344
- ...data.completedPreRequirements,
345
- ]),
346
- ];
337
+ if (invalidPreReqIds.length > 0) {
338
+ throw new Error(
339
+ `Invalid pre-requirement IDs: ${invalidPreReqIds.join(", ")}`
340
+ );
341
+ }
342
+
343
+ // Update the completed pre-requirements
344
+ completedPreRequirements = [
345
+ ...new Set([
346
+ ...completedPreRequirements,
347
+ ...data.completedPreRequirements,
348
+ ]),
349
+ ];
350
+ }
347
351
  }
348
352
 
349
353
  if (data.completedPostRequirements) {
@@ -351,30 +355,37 @@ export async function updateAppointmentUtil(
351
355
  const validPostReqIds = currentAppointment.postProcedureRequirements.map(
352
356
  (req) => req.id
353
357
  );
354
- const invalidPostReqIds = data.completedPostRequirements.filter(
355
- (id) => !validPostReqIds.includes(id)
356
- );
357
358
 
358
- if (invalidPostReqIds.length > 0) {
359
- throw new Error(
360
- `Invalid post-requirement IDs: ${invalidPostReqIds.join(", ")}`
359
+ if (Array.isArray(data.completedPostRequirements)) {
360
+ const invalidPostReqIds = data.completedPostRequirements.filter(
361
+ (id) => !validPostReqIds.includes(id)
361
362
  );
362
- }
363
363
 
364
- // Update the completed post-requirements
365
- completedPostRequirements = [
366
- ...new Set([
367
- ...completedPostRequirements,
368
- ...data.completedPostRequirements,
369
- ]),
370
- ];
364
+ if (invalidPostReqIds.length > 0) {
365
+ throw new Error(
366
+ `Invalid post-requirement IDs: ${invalidPostReqIds.join(", ")}`
367
+ );
368
+ }
369
+
370
+ // Update the completed post-requirements
371
+ completedPostRequirements = [
372
+ ...new Set([
373
+ ...completedPostRequirements,
374
+ ...data.completedPostRequirements,
375
+ ]),
376
+ ];
377
+ }
371
378
  }
372
379
 
373
380
  // Prepare update data
374
381
  const updateData: any = {
375
382
  ...data,
376
- completedPreRequirements,
377
- completedPostRequirements,
383
+ completedPreRequirements: Array.isArray(data.completedPreRequirements)
384
+ ? completedPreRequirements
385
+ : data.completedPreRequirements,
386
+ completedPostRequirements: Array.isArray(data.completedPostRequirements)
387
+ ? completedPostRequirements
388
+ : data.completedPostRequirements,
378
389
  updatedAt: serverTimestamp(),
379
390
  };
380
391
 
@@ -454,7 +465,7 @@ async function updateCalendarEventStatus(
454
465
  case AppointmentStatus.CANCELED_CLINIC:
455
466
  calendarStatus = "canceled";
456
467
  break;
457
- case AppointmentStatus.RESCHEDULED:
468
+ case AppointmentStatus.RESCHEDULED_BY_CLINIC:
458
469
  calendarStatus = "rescheduled";
459
470
  break;
460
471
  case AppointmentStatus.COMPLETED: