@blackcode_sa/metaestetics-api 1.11.1 → 1.11.2

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 (36) hide show
  1. package/dist/admin/index.d.mts +324 -330
  2. package/dist/admin/index.d.ts +324 -330
  3. package/dist/backoffice/index.d.mts +67 -283
  4. package/dist/backoffice/index.d.ts +67 -283
  5. package/dist/backoffice/index.js +6 -114
  6. package/dist/backoffice/index.mjs +6 -112
  7. package/dist/index.d.mts +3037 -3100
  8. package/dist/index.d.ts +3037 -3100
  9. package/dist/index.js +129 -379
  10. package/dist/index.mjs +130 -379
  11. package/package.json +1 -1
  12. package/src/backoffice/expo-safe/index.ts +0 -2
  13. package/src/backoffice/services/__tests__/brand.service.test.ts +196 -0
  14. package/src/backoffice/services/__tests__/category.service.test.ts +201 -0
  15. package/src/backoffice/services/__tests__/product.service.test.ts +358 -0
  16. package/src/backoffice/services/__tests__/requirement.service.test.ts +226 -0
  17. package/src/backoffice/services/__tests__/subcategory.service.test.ts +181 -0
  18. package/src/backoffice/services/__tests__/technology.service.test.ts +1097 -0
  19. package/src/backoffice/services/technology.service.ts +10 -122
  20. package/src/backoffice/types/index.ts +0 -1
  21. package/src/backoffice/types/product.types.ts +1 -3
  22. package/src/backoffice/types/technology.types.ts +4 -4
  23. package/src/backoffice/validations/schemas.ts +9 -35
  24. package/src/services/appointment/appointment.service.ts +5 -0
  25. package/src/services/appointment/utils/appointment.utils.ts +113 -124
  26. package/src/services/procedure/procedure.service.ts +234 -434
  27. package/src/types/appointment/index.ts +37 -43
  28. package/src/types/clinic/index.ts +6 -1
  29. package/src/types/patient/medical-info.types.ts +3 -3
  30. package/src/types/procedure/index.ts +17 -20
  31. package/src/validations/appointment.schema.ts +118 -170
  32. package/src/validations/clinic.schema.ts +6 -1
  33. package/src/validations/patient/medical-info.schema.ts +2 -7
  34. package/src/backoffice/services/README.md +0 -40
  35. package/src/backoffice/services/constants.service.ts +0 -268
  36. package/src/backoffice/types/admin-constants.types.ts +0 -69
package/dist/index.mjs CHANGED
@@ -53,13 +53,13 @@ var AppointmentStatus = /* @__PURE__ */ ((AppointmentStatus2) => {
53
53
  AppointmentStatus2["RESCHEDULED_BY_CLINIC"] = "rescheduled_by_clinic";
54
54
  return AppointmentStatus2;
55
55
  })(AppointmentStatus || {});
56
- var PaymentStatus = /* @__PURE__ */ ((PaymentStatus4) => {
57
- PaymentStatus4["UNPAID"] = "unpaid";
58
- PaymentStatus4["PAID"] = "paid";
59
- PaymentStatus4["PARTIALLY_PAID"] = "partially_paid";
60
- PaymentStatus4["REFUNDED"] = "refunded";
61
- PaymentStatus4["NOT_APPLICABLE"] = "not_applicable";
62
- return PaymentStatus4;
56
+ var PaymentStatus = /* @__PURE__ */ ((PaymentStatus3) => {
57
+ PaymentStatus3["UNPAID"] = "unpaid";
58
+ PaymentStatus3["PAID"] = "paid";
59
+ PaymentStatus3["PARTIALLY_PAID"] = "partially_paid";
60
+ PaymentStatus3["REFUNDED"] = "refunded";
61
+ PaymentStatus3["NOT_APPLICABLE"] = "not_applicable";
62
+ return PaymentStatus3;
63
63
  })(PaymentStatus || {});
64
64
  var MediaType = /* @__PURE__ */ ((MediaType2) => {
65
65
  MediaType2["BEFORE_PHOTO"] = "before_photo";
@@ -411,7 +411,8 @@ var finalizedDetailsSchema = z3.object({
411
411
  var beforeAfterPerZoneSchema = z3.object({
412
412
  before: mediaResourceSchema.nullable(),
413
413
  after: mediaResourceSchema.nullable(),
414
- note: z3.string().nullable()
414
+ afterNote: z3.string().nullable().optional(),
415
+ beforeNote: z3.string().nullable().optional()
415
416
  });
416
417
  var billingPerZoneSchema = z3.object({
417
418
  Product: z3.string().min(MIN_STRING_LENGTH, "Product name is required"),
@@ -421,7 +422,8 @@ var billingPerZoneSchema = z3.object({
421
422
  UnitPrice: z3.number().min(0, "Unit price must be non-negative"),
422
423
  UnitCurency: z3.nativeEnum(Currency),
423
424
  Subtotal: z3.number().min(0, "Subtotal must be non-negative"),
424
- Note: z3.string().nullable()
425
+ Note: z3.string().nullable(),
426
+ IonNumber: z3.string().nullable()
425
427
  });
426
428
  var finalBillingSchema = z3.object({
427
429
  subtotalAll: z3.number().min(0, "Subtotal all must be non-negative"),
@@ -492,10 +494,7 @@ var updateAppointmentSchema = z3.object({
492
494
  practitionerId: z3.string().min(MIN_STRING_LENGTH).optional(),
493
495
  clinic_tz: z3.string().min(MIN_STRING_LENGTH).optional(),
494
496
  linkedForms: z3.union([z3.array(linkedFormInfoSchema).max(MAX_ARRAY_LENGTH), z3.any()]).optional(),
495
- media: z3.union([
496
- z3.array(appointmentMediaItemSchema).max(MAX_ARRAY_LENGTH),
497
- z3.any()
498
- ]).optional(),
497
+ media: z3.union([z3.array(appointmentMediaItemSchema).max(MAX_ARRAY_LENGTH), z3.any()]).optional(),
499
498
  reviewInfo: z3.union([patientReviewInfoSchema.nullable(), z3.any()]).optional(),
500
499
  finalizedDetails: z3.union([finalizedDetailsSchema.nullable(), z3.any()]).optional(),
501
500
  isArchived: z3.boolean().optional(),
@@ -536,10 +535,7 @@ var searchAppointmentsSchema = z3.object({
536
535
  (val) => val === void 0 || val instanceof Date || (val == null ? void 0 : val._seconds) !== void 0 || (val == null ? void 0 : val.seconds) !== void 0 || typeof val === "number" || typeof val === "string" || val && typeof val.toMillis === "function",
537
536
  "End date must be a valid timestamp or Date object"
538
537
  ).optional(),
539
- status: z3.union([
540
- appointmentStatusSchema,
541
- z3.array(appointmentStatusSchema).nonempty()
542
- ]).optional(),
538
+ status: z3.union([appointmentStatusSchema, z3.array(appointmentStatusSchema).nonempty()]).optional(),
543
539
  limit: z3.number().positive().int().optional().default(20),
544
540
  startAfter: z3.any().optional()
545
541
  }).refine(
@@ -585,6 +581,7 @@ import {
585
581
  getDocs,
586
582
  query,
587
583
  where,
584
+ setDoc,
588
585
  updateDoc,
589
586
  serverTimestamp,
590
587
  Timestamp,
@@ -821,48 +818,44 @@ async function updateAppointmentUtil(db, appointmentId, data) {
821
818
  const validPreReqIds = currentAppointment.preProcedureRequirements.map(
822
819
  (req) => req.id
823
820
  );
824
- if (Array.isArray(data.completedPreRequirements)) {
825
- const invalidPreReqIds = data.completedPreRequirements.filter(
826
- (id) => !validPreReqIds.includes(id)
821
+ const invalidPreReqIds = data.completedPreRequirements.filter(
822
+ (id) => !validPreReqIds.includes(id)
823
+ );
824
+ if (invalidPreReqIds.length > 0) {
825
+ throw new Error(
826
+ `Invalid pre-requirement IDs: ${invalidPreReqIds.join(", ")}`
827
827
  );
828
- if (invalidPreReqIds.length > 0) {
829
- throw new Error(
830
- `Invalid pre-requirement IDs: ${invalidPreReqIds.join(", ")}`
831
- );
832
- }
833
- completedPreRequirements = [
834
- .../* @__PURE__ */ new Set([
835
- ...completedPreRequirements,
836
- ...data.completedPreRequirements
837
- ])
838
- ];
839
828
  }
829
+ completedPreRequirements = [
830
+ .../* @__PURE__ */ new Set([
831
+ ...completedPreRequirements,
832
+ ...data.completedPreRequirements
833
+ ])
834
+ ];
840
835
  }
841
836
  if (data.completedPostRequirements) {
842
837
  const validPostReqIds = currentAppointment.postProcedureRequirements.map(
843
838
  (req) => req.id
844
839
  );
845
- if (Array.isArray(data.completedPostRequirements)) {
846
- const invalidPostReqIds = data.completedPostRequirements.filter(
847
- (id) => !validPostReqIds.includes(id)
840
+ const invalidPostReqIds = data.completedPostRequirements.filter(
841
+ (id) => !validPostReqIds.includes(id)
842
+ );
843
+ if (invalidPostReqIds.length > 0) {
844
+ throw new Error(
845
+ `Invalid post-requirement IDs: ${invalidPostReqIds.join(", ")}`
848
846
  );
849
- if (invalidPostReqIds.length > 0) {
850
- throw new Error(
851
- `Invalid post-requirement IDs: ${invalidPostReqIds.join(", ")}`
852
- );
853
- }
854
- completedPostRequirements = [
855
- .../* @__PURE__ */ new Set([
856
- ...completedPostRequirements,
857
- ...data.completedPostRequirements
858
- ])
859
- ];
860
847
  }
848
+ completedPostRequirements = [
849
+ .../* @__PURE__ */ new Set([
850
+ ...completedPostRequirements,
851
+ ...data.completedPostRequirements
852
+ ])
853
+ ];
861
854
  }
862
855
  const updateData = {
863
856
  ...data,
864
- completedPreRequirements: Array.isArray(data.completedPreRequirements) ? completedPreRequirements : data.completedPreRequirements,
865
- completedPostRequirements: Array.isArray(data.completedPostRequirements) ? completedPostRequirements : data.completedPostRequirements,
857
+ completedPreRequirements,
858
+ completedPostRequirements,
866
859
  updatedAt: serverTimestamp()
867
860
  };
868
861
  Object.keys(updateData).forEach((key) => {
@@ -912,7 +905,7 @@ async function updateCalendarEventStatus(db, calendarEventId, appointmentStatus)
912
905
  case "canceled_clinic" /* CANCELED_CLINIC */:
913
906
  calendarStatus = "canceled";
914
907
  break;
915
- case "rescheduled_by_clinic" /* RESCHEDULED_BY_CLINIC */:
908
+ case AppointmentStatus.RESCHEDULED:
916
909
  calendarStatus = "rescheduled";
917
910
  break;
918
911
  case "completed" /* COMPLETED */:
@@ -2805,6 +2798,23 @@ var BlockingCondition = /* @__PURE__ */ ((BlockingCondition2) => {
2805
2798
  return BlockingCondition2;
2806
2799
  })(BlockingCondition || {});
2807
2800
 
2801
+ // src/backoffice/types/static/contraindication.types.ts
2802
+ var Contraindication = /* @__PURE__ */ ((Contraindication2) => {
2803
+ Contraindication2["SENSITIVE_SKIN"] = "sensitive_skin";
2804
+ Contraindication2["RECENT_TANNING"] = "recent_tanning";
2805
+ Contraindication2["RECENT_BOTOX"] = "recent_botox";
2806
+ Contraindication2["RECENT_FILLERS"] = "recent_fillers";
2807
+ Contraindication2["SKIN_ALLERGIES"] = "skin_allergies";
2808
+ Contraindication2["MEDICATIONS"] = "medications";
2809
+ Contraindication2["RECENT_CHEMICAL_PEEL"] = "recent_chemical_peel";
2810
+ Contraindication2["RECENT_LASER"] = "recent_laser";
2811
+ Contraindication2["SKIN_INFLAMMATION"] = "skin_inflammation";
2812
+ Contraindication2["OPEN_WOUNDS"] = "open_wounds";
2813
+ Contraindication2["HERPES_SIMPLEX"] = "herpes_simplex";
2814
+ Contraindication2["COLD_SORES"] = "cold_sores";
2815
+ return Contraindication2;
2816
+ })(Contraindication || {});
2817
+
2808
2818
  // src/validations/common.schema.ts
2809
2819
  import { z as z5 } from "zod";
2810
2820
  import { Timestamp as Timestamp4 } from "firebase/firestore";
@@ -2859,13 +2869,8 @@ var blockingConditionSchema = z6.object({
2859
2869
  notes: z6.string().optional().nullable(),
2860
2870
  isActive: z6.boolean()
2861
2871
  });
2862
- var contraindicationDynamicSchema = z6.object({
2863
- id: z6.string(),
2864
- name: z6.string(),
2865
- description: z6.string().optional()
2866
- });
2867
2872
  var contraindicationSchema = z6.object({
2868
- condition: contraindicationDynamicSchema,
2873
+ condition: z6.nativeEnum(Contraindication),
2869
2874
  lastOccurrence: timestampSchema,
2870
2875
  frequency: z6.enum(["rare", "occasional", "frequent"]),
2871
2876
  notes: z6.string().optional().nullable(),
@@ -10770,7 +10775,7 @@ async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId,
10770
10775
  }
10771
10776
 
10772
10777
  // src/services/calendar/utils/appointment.utils.ts
10773
- async function createAppointmentUtil(db, clinicId, practitionerId, patientId, eventData, generateId2) {
10778
+ async function createAppointmentUtil2(db, clinicId, practitionerId, patientId, eventData, generateId2) {
10774
10779
  const eventId = generateId2();
10775
10780
  const autoConfirm = await checkAutoConfirmAppointmentsUtil(db, clinicId);
10776
10781
  const initialStatus = autoConfirm ? "confirmed" /* CONFIRMED */ : "pending" /* PENDING */;
@@ -12112,7 +12117,7 @@ var CalendarServiceV2 = class extends BaseService {
12112
12117
  syncStatus: "internal" /* INTERNAL */,
12113
12118
  eventType: "appointment" /* APPOINTMENT */
12114
12119
  };
12115
- const appointment = await createAppointmentUtil(
12120
+ const appointment = await createAppointmentUtil2(
12116
12121
  this.db,
12117
12122
  params.clinicId,
12118
12123
  params.doctorId,
@@ -14996,9 +15001,7 @@ var ProcedureService = class extends BaseService {
14996
15001
  return media;
14997
15002
  }
14998
15003
  if (media instanceof File || media instanceof Blob) {
14999
- console.log(
15000
- `[ProcedureService] Uploading ${collectionName} media for ${ownerId}`
15001
- );
15004
+ console.log(`[ProcedureService] Uploading ${collectionName} media for ${ownerId}`);
15002
15005
  const metadata = await this.mediaService.uploadMedia(
15003
15006
  media,
15004
15007
  ownerId,
@@ -15020,11 +15023,7 @@ var ProcedureService = class extends BaseService {
15020
15023
  if (!mediaArray || mediaArray.length === 0) return [];
15021
15024
  const result = [];
15022
15025
  for (const media of mediaArray) {
15023
- const processedUrl = await this.processMedia(
15024
- media,
15025
- ownerId,
15026
- collectionName
15027
- );
15026
+ const processedUrl = await this.processMedia(media, ownerId, collectionName);
15028
15027
  if (processedUrl) {
15029
15028
  result.push(processedUrl);
15030
15029
  }
@@ -15037,46 +15036,28 @@ var ProcedureService = class extends BaseService {
15037
15036
  * @returns The created procedure
15038
15037
  */
15039
15038
  async createProcedure(data) {
15040
- var _a, _b, _c;
15039
+ var _a;
15041
15040
  const validatedData = createProcedureSchema.parse(data);
15042
15041
  const procedureId = this.generateId();
15043
15042
  const [category, subcategory, technology, product] = await Promise.all([
15044
15043
  this.categoryService.getById(validatedData.categoryId),
15045
- this.subcategoryService.getById(
15046
- validatedData.categoryId,
15047
- validatedData.subcategoryId
15048
- ),
15044
+ this.subcategoryService.getById(validatedData.categoryId, validatedData.subcategoryId),
15049
15045
  this.technologyService.getById(validatedData.technologyId),
15050
- this.productService.getById(
15051
- validatedData.technologyId,
15052
- validatedData.productId
15053
- )
15046
+ this.productService.getById(validatedData.technologyId, validatedData.productId)
15054
15047
  ]);
15055
15048
  if (!category || !subcategory || !technology || !product) {
15056
15049
  throw new Error("One or more required base entities not found");
15057
15050
  }
15058
- const clinicRef = doc30(
15059
- this.db,
15060
- CLINICS_COLLECTION,
15061
- validatedData.clinicBranchId
15062
- );
15051
+ const clinicRef = doc30(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId);
15063
15052
  const clinicSnapshot = await getDoc32(clinicRef);
15064
15053
  if (!clinicSnapshot.exists()) {
15065
- throw new Error(
15066
- `Clinic with ID ${validatedData.clinicBranchId} not found`
15067
- );
15054
+ throw new Error(`Clinic with ID ${validatedData.clinicBranchId} not found`);
15068
15055
  }
15069
15056
  const clinic = clinicSnapshot.data();
15070
- const practitionerRef = doc30(
15071
- this.db,
15072
- PRACTITIONERS_COLLECTION,
15073
- validatedData.practitionerId
15074
- );
15057
+ const practitionerRef = doc30(this.db, PRACTITIONERS_COLLECTION, validatedData.practitionerId);
15075
15058
  const practitionerSnapshot = await getDoc32(practitionerRef);
15076
15059
  if (!practitionerSnapshot.exists()) {
15077
- throw new Error(
15078
- `Practitioner with ID ${validatedData.practitionerId} not found`
15079
- );
15060
+ throw new Error(`Practitioner with ID ${validatedData.practitionerId} not found`);
15080
15061
  }
15081
15062
  const practitioner = practitionerSnapshot.data();
15082
15063
  let processedPhotos = [];
@@ -15117,9 +15098,7 @@ var ProcedureService = class extends BaseService {
15117
15098
  product,
15118
15099
  blockingConditions: technology.blockingConditions,
15119
15100
  contraindications: technology.contraindications || [],
15120
- contraindicationIds: ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [],
15121
15101
  treatmentBenefits: technology.benefits,
15122
- treatmentBenefitIds: ((_c = technology.benefits) == null ? void 0 : _c.map((b) => b.id)) || [],
15123
15102
  preRequirements: technology.requirements.pre,
15124
15103
  postRequirements: technology.requirements.post,
15125
15104
  certificationRequirement: technology.certificationRequirement,
@@ -15160,7 +15139,7 @@ var ProcedureService = class extends BaseService {
15160
15139
  * @returns A promise that resolves to an array of the newly created procedures.
15161
15140
  */
15162
15141
  async bulkCreateProcedures(baseData, practitionerIds) {
15163
- var _a, _b, _c;
15142
+ var _a;
15164
15143
  if (!practitionerIds || practitionerIds.length === 0) {
15165
15144
  throw new Error("Practitioner IDs array cannot be empty.");
15166
15145
  }
@@ -15168,24 +15147,16 @@ var ProcedureService = class extends BaseService {
15168
15147
  const validatedData = createProcedureSchema.parse(validationData);
15169
15148
  const [category, subcategory, technology, product, clinicSnapshot] = await Promise.all([
15170
15149
  this.categoryService.getById(validatedData.categoryId),
15171
- this.subcategoryService.getById(
15172
- validatedData.categoryId,
15173
- validatedData.subcategoryId
15174
- ),
15150
+ this.subcategoryService.getById(validatedData.categoryId, validatedData.subcategoryId),
15175
15151
  this.technologyService.getById(validatedData.technologyId),
15176
- this.productService.getById(
15177
- validatedData.technologyId,
15178
- validatedData.productId
15179
- ),
15152
+ this.productService.getById(validatedData.technologyId, validatedData.productId),
15180
15153
  getDoc32(doc30(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId))
15181
15154
  ]);
15182
15155
  if (!category || !subcategory || !technology || !product) {
15183
15156
  throw new Error("One or more required base entities not found");
15184
15157
  }
15185
15158
  if (!clinicSnapshot.exists()) {
15186
- throw new Error(
15187
- `Clinic with ID ${validatedData.clinicBranchId} not found`
15188
- );
15159
+ throw new Error(`Clinic with ID ${validatedData.clinicBranchId} not found`);
15189
15160
  }
15190
15161
  const clinic = clinicSnapshot.data();
15191
15162
  let processedPhotos = [];
@@ -15211,12 +15182,8 @@ var ProcedureService = class extends BaseService {
15211
15182
  }
15212
15183
  if (practitionersMap.size !== practitionerIds.length) {
15213
15184
  const foundIds = Array.from(practitionersMap.keys());
15214
- const notFoundIds = practitionerIds.filter(
15215
- (id) => !foundIds.includes(id)
15216
- );
15217
- throw new Error(
15218
- `The following practitioners were not found: ${notFoundIds.join(", ")}`
15219
- );
15185
+ const notFoundIds = practitionerIds.filter((id) => !foundIds.includes(id));
15186
+ throw new Error(`The following practitioners were not found: ${notFoundIds.join(", ")}`);
15220
15187
  }
15221
15188
  const batch = writeBatch6(this.db);
15222
15189
  const createdProcedureIds = [];
@@ -15254,9 +15221,7 @@ var ProcedureService = class extends BaseService {
15254
15221
  product,
15255
15222
  blockingConditions: technology.blockingConditions,
15256
15223
  contraindications: technology.contraindications || [],
15257
- contraindicationIds: ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [],
15258
15224
  treatmentBenefits: technology.benefits,
15259
- treatmentBenefitIds: ((_c = technology.benefits) == null ? void 0 : _c.map((b) => b.id)) || [],
15260
15225
  preRequirements: technology.requirements.pre,
15261
15226
  postRequirements: technology.requirements.post,
15262
15227
  certificationRequirement: technology.certificationRequirement,
@@ -15286,10 +15251,7 @@ var ProcedureService = class extends BaseService {
15286
15251
  const fetchedProcedures = [];
15287
15252
  for (let i = 0; i < createdProcedureIds.length; i += 30) {
15288
15253
  const chunk = createdProcedureIds.slice(i, i + 30);
15289
- const q = query29(
15290
- collection29(this.db, PROCEDURES_COLLECTION),
15291
- where29(documentId2(), "in", chunk)
15292
- );
15254
+ const q = query29(collection29(this.db, PROCEDURES_COLLECTION), where29(documentId2(), "in", chunk));
15293
15255
  const snapshot = await getDocs29(q);
15294
15256
  snapshot.forEach((doc37) => {
15295
15257
  fetchedProcedures.push(doc37.data());
@@ -15359,7 +15321,7 @@ var ProcedureService = class extends BaseService {
15359
15321
  * @returns The updated procedure
15360
15322
  */
15361
15323
  async updateProcedure(id, data) {
15362
- var _a, _b, _c;
15324
+ var _a;
15363
15325
  const validatedData = updateProcedureSchema.parse(data);
15364
15326
  const procedureRef = doc30(this.db, PROCEDURES_COLLECTION, id);
15365
15327
  const procedureSnapshot = await getDoc32(procedureRef);
@@ -15390,9 +15352,7 @@ var ProcedureService = class extends BaseService {
15390
15352
  );
15391
15353
  const newPractitionerSnap = await getDoc32(newPractitionerRef);
15392
15354
  if (!newPractitionerSnap.exists())
15393
- throw new Error(
15394
- `New Practitioner ${validatedData.practitionerId} not found`
15395
- );
15355
+ throw new Error(`New Practitioner ${validatedData.practitionerId} not found`);
15396
15356
  newPractitioner = newPractitionerSnap.data();
15397
15357
  updatedProcedureData.doctorInfo = {
15398
15358
  id: newPractitioner.id,
@@ -15406,11 +15366,7 @@ var ProcedureService = class extends BaseService {
15406
15366
  }
15407
15367
  if (validatedData.clinicBranchId && validatedData.clinicBranchId !== oldClinicId) {
15408
15368
  clinicChanged = true;
15409
- const newClinicRef = doc30(
15410
- this.db,
15411
- CLINICS_COLLECTION,
15412
- validatedData.clinicBranchId
15413
- );
15369
+ const newClinicRef = doc30(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId);
15414
15370
  const newClinicSnap = await getDoc32(newClinicRef);
15415
15371
  if (!newClinicSnap.exists())
15416
15372
  throw new Error(`New Clinic ${validatedData.clinicBranchId} not found`);
@@ -15429,11 +15385,8 @@ var ProcedureService = class extends BaseService {
15429
15385
  updatedProcedureData.nameLower = validatedData.name.toLowerCase();
15430
15386
  }
15431
15387
  if (validatedData.categoryId) {
15432
- const category = await this.categoryService.getById(
15433
- validatedData.categoryId
15434
- );
15435
- if (!category)
15436
- throw new Error(`Category ${validatedData.categoryId} not found`);
15388
+ const category = await this.categoryService.getById(validatedData.categoryId);
15389
+ if (!category) throw new Error(`Category ${validatedData.categoryId} not found`);
15437
15390
  updatedProcedureData.category = category;
15438
15391
  finalCategoryId = category.id;
15439
15392
  }
@@ -15448,34 +15401,23 @@ var ProcedureService = class extends BaseService {
15448
15401
  );
15449
15402
  updatedProcedureData.subcategory = subcategory;
15450
15403
  } else if (validatedData.subcategoryId) {
15451
- console.warn(
15452
- "Attempted to update subcategory without a valid categoryId"
15453
- );
15404
+ console.warn("Attempted to update subcategory without a valid categoryId");
15454
15405
  }
15455
15406
  let finalTechnologyId = existingProcedure.technology.id;
15456
15407
  if (validatedData.technologyId) {
15457
- const technology = await this.technologyService.getById(
15458
- validatedData.technologyId
15459
- );
15460
- if (!technology)
15461
- throw new Error(`Technology ${validatedData.technologyId} not found`);
15408
+ const technology = await this.technologyService.getById(validatedData.technologyId);
15409
+ if (!technology) throw new Error(`Technology ${validatedData.technologyId} not found`);
15462
15410
  updatedProcedureData.technology = technology;
15463
15411
  finalTechnologyId = technology.id;
15464
15412
  updatedProcedureData.blockingConditions = technology.blockingConditions;
15465
- updatedProcedureData.contraindications = technology.contraindications || [];
15466
- updatedProcedureData.contraindicationIds = ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [];
15467
15413
  updatedProcedureData.treatmentBenefits = technology.benefits;
15468
- updatedProcedureData.treatmentBenefitIds = ((_c = technology.benefits) == null ? void 0 : _c.map((b) => b.id)) || [];
15469
15414
  updatedProcedureData.preRequirements = technology.requirements.pre;
15470
15415
  updatedProcedureData.postRequirements = technology.requirements.post;
15471
15416
  updatedProcedureData.certificationRequirement = technology.certificationRequirement;
15472
15417
  updatedProcedureData.documentationTemplates = technology.documentationTemplates || [];
15473
15418
  }
15474
15419
  if (validatedData.productId && finalTechnologyId) {
15475
- const product = await this.productService.getById(
15476
- finalTechnologyId,
15477
- validatedData.productId
15478
- );
15420
+ const product = await this.productService.getById(finalTechnologyId, validatedData.productId);
15479
15421
  if (!product)
15480
15422
  throw new Error(
15481
15423
  `Product ${validatedData.productId} not found for technology ${finalTechnologyId}`
@@ -15557,11 +15499,7 @@ var ProcedureService = class extends BaseService {
15557
15499
  limit16(pagination)
15558
15500
  );
15559
15501
  } else {
15560
- proceduresQuery = query29(
15561
- proceduresCollection,
15562
- orderBy17("name"),
15563
- limit16(pagination)
15564
- );
15502
+ proceduresQuery = query29(proceduresCollection, orderBy17("name"), limit16(pagination));
15565
15503
  }
15566
15504
  } else {
15567
15505
  proceduresQuery = query29(proceduresCollection, orderBy17("name"));
@@ -15592,7 +15530,7 @@ var ProcedureService = class extends BaseService {
15592
15530
  *
15593
15531
  * @param filters - Various filters to apply
15594
15532
  * @param filters.nameSearch - Optional search text for procedure name
15595
- * @param filters.treatmentBenefitIds - Optional array of treatment benefits to filter by
15533
+ * @param filters.treatmentBenefits - Optional array of treatment benefits to filter by
15596
15534
  * @param filters.procedureFamily - Optional procedure family to filter by
15597
15535
  * @param filters.procedureCategory - Optional procedure category to filter by
15598
15536
  * @param filters.procedureSubcategory - Optional procedure subcategory to filter by
@@ -15610,9 +15548,7 @@ var ProcedureService = class extends BaseService {
15610
15548
  */
15611
15549
  async getProceduresByFilters(filters) {
15612
15550
  try {
15613
- console.log(
15614
- "[PROCEDURE_SERVICE] Starting procedure filtering with multiple strategies"
15615
- );
15551
+ console.log("[PROCEDURE_SERVICE] Starting procedure filtering with multiple strategies");
15616
15552
  if (filters.location && filters.radiusInKm) {
15617
15553
  console.log("[PROCEDURE_SERVICE] Executing geo query:", {
15618
15554
  location: filters.location,
@@ -15620,10 +15556,7 @@ var ProcedureService = class extends BaseService {
15620
15556
  serviceName: "ProcedureService"
15621
15557
  });
15622
15558
  if (!filters.location.latitude || !filters.location.longitude) {
15623
- console.warn(
15624
- "[PROCEDURE_SERVICE] Invalid location data:",
15625
- filters.location
15626
- );
15559
+ console.warn("[PROCEDURE_SERVICE] Invalid location data:", filters.location);
15627
15560
  filters.location = void 0;
15628
15561
  filters.radiusInKm = void 0;
15629
15562
  }
@@ -15643,19 +15576,13 @@ var ProcedureService = class extends BaseService {
15643
15576
  constraints.push(where29("family", "==", filters.procedureFamily));
15644
15577
  }
15645
15578
  if (filters.procedureCategory) {
15646
- constraints.push(
15647
- where29("category.id", "==", filters.procedureCategory)
15648
- );
15579
+ constraints.push(where29("category.id", "==", filters.procedureCategory));
15649
15580
  }
15650
15581
  if (filters.procedureSubcategory) {
15651
- constraints.push(
15652
- where29("subcategory.id", "==", filters.procedureSubcategory)
15653
- );
15582
+ constraints.push(where29("subcategory.id", "==", filters.procedureSubcategory));
15654
15583
  }
15655
15584
  if (filters.procedureTechnology) {
15656
- constraints.push(
15657
- where29("technology.id", "==", filters.procedureTechnology)
15658
- );
15585
+ constraints.push(where29("technology.id", "==", filters.procedureTechnology));
15659
15586
  }
15660
15587
  if (filters.minPrice !== void 0) {
15661
15588
  constraints.push(where29("price", ">=", filters.minPrice));
@@ -15664,32 +15591,20 @@ var ProcedureService = class extends BaseService {
15664
15591
  constraints.push(where29("price", "<=", filters.maxPrice));
15665
15592
  }
15666
15593
  if (filters.minRating !== void 0) {
15667
- constraints.push(
15668
- where29("reviewInfo.averageRating", ">=", filters.minRating)
15669
- );
15594
+ constraints.push(where29("reviewInfo.averageRating", ">=", filters.minRating));
15670
15595
  }
15671
15596
  if (filters.maxRating !== void 0) {
15672
- constraints.push(
15673
- where29("reviewInfo.averageRating", "<=", filters.maxRating)
15674
- );
15597
+ constraints.push(where29("reviewInfo.averageRating", "<=", filters.maxRating));
15675
15598
  }
15676
15599
  if (filters.treatmentBenefits && filters.treatmentBenefits.length > 0) {
15677
- const benefitIdsToMatch = filters.treatmentBenefits;
15678
- constraints.push(
15679
- where29(
15680
- "treatmentBenefitIds",
15681
- "array-contains-any",
15682
- benefitIdsToMatch
15683
- )
15684
- );
15600
+ const benefitsToMatch = filters.treatmentBenefits;
15601
+ constraints.push(where29("treatmentBenefits", "array-contains-any", benefitsToMatch));
15685
15602
  }
15686
15603
  return constraints;
15687
15604
  };
15688
15605
  if (filters.nameSearch && filters.nameSearch.trim()) {
15689
15606
  try {
15690
- console.log(
15691
- "[PROCEDURE_SERVICE] Strategy 1: Trying nameLower search"
15692
- );
15607
+ console.log("[PROCEDURE_SERVICE] Strategy 1: Trying nameLower search");
15693
15608
  const searchTerm = filters.nameSearch.trim().toLowerCase();
15694
15609
  const constraints = getBaseConstraints();
15695
15610
  constraints.push(where29("nameLower", ">=", searchTerm));
@@ -15705,18 +15620,13 @@ var ProcedureService = class extends BaseService {
15705
15620
  }
15706
15621
  }
15707
15622
  constraints.push(limit15(filters.pagination || 10));
15708
- const q = query29(
15709
- collection29(this.db, PROCEDURES_COLLECTION),
15710
- ...constraints
15711
- );
15623
+ const q = query29(collection29(this.db, PROCEDURES_COLLECTION), ...constraints);
15712
15624
  const querySnapshot = await getDocs29(q);
15713
15625
  const procedures = querySnapshot.docs.map(
15714
15626
  (doc37) => ({ ...doc37.data(), id: doc37.id })
15715
15627
  );
15716
15628
  const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
15717
- console.log(
15718
- `[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures`
15719
- );
15629
+ console.log(`[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures`);
15720
15630
  if (procedures.length < (filters.pagination || 10)) {
15721
15631
  return { procedures, lastDoc: null };
15722
15632
  }
@@ -15727,9 +15637,7 @@ var ProcedureService = class extends BaseService {
15727
15637
  }
15728
15638
  if (filters.nameSearch && filters.nameSearch.trim()) {
15729
15639
  try {
15730
- console.log(
15731
- "[PROCEDURE_SERVICE] Strategy 2: Trying name field search"
15732
- );
15640
+ console.log("[PROCEDURE_SERVICE] Strategy 2: Trying name field search");
15733
15641
  const searchTerm = filters.nameSearch.trim().toLowerCase();
15734
15642
  const constraints = getBaseConstraints();
15735
15643
  constraints.push(where29("name", ">=", searchTerm));
@@ -15745,18 +15653,13 @@ var ProcedureService = class extends BaseService {
15745
15653
  }
15746
15654
  }
15747
15655
  constraints.push(limit15(filters.pagination || 10));
15748
- const q = query29(
15749
- collection29(this.db, PROCEDURES_COLLECTION),
15750
- ...constraints
15751
- );
15656
+ const q = query29(collection29(this.db, PROCEDURES_COLLECTION), ...constraints);
15752
15657
  const querySnapshot = await getDocs29(q);
15753
15658
  const procedures = querySnapshot.docs.map(
15754
15659
  (doc37) => ({ ...doc37.data(), id: doc37.id })
15755
15660
  );
15756
15661
  const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
15757
- console.log(
15758
- `[PROCEDURE_SERVICE] Strategy 2 success: ${procedures.length} procedures`
15759
- );
15662
+ console.log(`[PROCEDURE_SERVICE] Strategy 2 success: ${procedures.length} procedures`);
15760
15663
  if (procedures.length < (filters.pagination || 10)) {
15761
15664
  return { procedures, lastDoc: null };
15762
15665
  }
@@ -15781,19 +15684,14 @@ var ProcedureService = class extends BaseService {
15781
15684
  }
15782
15685
  }
15783
15686
  constraints.push(limit15(filters.pagination || 10));
15784
- const q = query29(
15785
- collection29(this.db, PROCEDURES_COLLECTION),
15786
- ...constraints
15787
- );
15687
+ const q = query29(collection29(this.db, PROCEDURES_COLLECTION), ...constraints);
15788
15688
  const querySnapshot = await getDocs29(q);
15789
15689
  let procedures = querySnapshot.docs.map(
15790
15690
  (doc37) => ({ ...doc37.data(), id: doc37.id })
15791
15691
  );
15792
15692
  procedures = this.applyInMemoryFilters(procedures, filters);
15793
15693
  const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
15794
- console.log(
15795
- `[PROCEDURE_SERVICE] Strategy 3 success: ${procedures.length} procedures`
15796
- );
15694
+ console.log(`[PROCEDURE_SERVICE] Strategy 3 success: ${procedures.length} procedures`);
15797
15695
  if (procedures.length < (filters.pagination || 10)) {
15798
15696
  return { procedures, lastDoc: null };
15799
15697
  }
@@ -15808,19 +15706,14 @@ var ProcedureService = class extends BaseService {
15808
15706
  orderBy17("createdAt", "desc"),
15809
15707
  limit15(filters.pagination || 10)
15810
15708
  ];
15811
- const q = query29(
15812
- collection29(this.db, PROCEDURES_COLLECTION),
15813
- ...constraints
15814
- );
15709
+ const q = query29(collection29(this.db, PROCEDURES_COLLECTION), ...constraints);
15815
15710
  const querySnapshot = await getDocs29(q);
15816
15711
  let procedures = querySnapshot.docs.map(
15817
15712
  (doc37) => ({ ...doc37.data(), id: doc37.id })
15818
15713
  );
15819
15714
  procedures = this.applyInMemoryFilters(procedures, filters);
15820
15715
  const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
15821
- console.log(
15822
- `[PROCEDURE_SERVICE] Strategy 4 success: ${procedures.length} procedures`
15823
- );
15716
+ console.log(`[PROCEDURE_SERVICE] Strategy 4 success: ${procedures.length} procedures`);
15824
15717
  if (procedures.length < (filters.pagination || 10)) {
15825
15718
  return { procedures, lastDoc: null };
15826
15719
  }
@@ -15828,9 +15721,7 @@ var ProcedureService = class extends BaseService {
15828
15721
  } catch (error) {
15829
15722
  console.log("[PROCEDURE_SERVICE] Strategy 4 failed:", error);
15830
15723
  }
15831
- console.log(
15832
- "[PROCEDURE_SERVICE] All strategies failed, returning empty result"
15833
- );
15724
+ console.log("[PROCEDURE_SERVICE] All strategies failed, returning empty result");
15834
15725
  return { procedures: [], lastDoc: null };
15835
15726
  } catch (error) {
15836
15727
  console.error("[PROCEDURE_SERVICE] Error filtering procedures:", error);
@@ -15850,17 +15741,13 @@ var ProcedureService = class extends BaseService {
15850
15741
  const nameLower = procedure.nameLower || "";
15851
15742
  return name.includes(searchTerm) || nameLower.includes(searchTerm);
15852
15743
  });
15853
- console.log(
15854
- `[PROCEDURE_SERVICE] Applied name filter, results: ${filteredProcedures.length}`
15855
- );
15744
+ console.log(`[PROCEDURE_SERVICE] Applied name filter, results: ${filteredProcedures.length}`);
15856
15745
  }
15857
15746
  if (filters.minPrice !== void 0 || filters.maxPrice !== void 0) {
15858
15747
  filteredProcedures = filteredProcedures.filter((procedure) => {
15859
15748
  const price = procedure.price || 0;
15860
- if (filters.minPrice !== void 0 && price < filters.minPrice)
15861
- return false;
15862
- if (filters.maxPrice !== void 0 && price > filters.maxPrice)
15863
- return false;
15749
+ if (filters.minPrice !== void 0 && price < filters.minPrice) return false;
15750
+ if (filters.maxPrice !== void 0 && price > filters.maxPrice) return false;
15864
15751
  return true;
15865
15752
  });
15866
15753
  console.log(
@@ -15871,10 +15758,8 @@ var ProcedureService = class extends BaseService {
15871
15758
  filteredProcedures = filteredProcedures.filter((procedure) => {
15872
15759
  var _a;
15873
15760
  const rating = ((_a = procedure.reviewInfo) == null ? void 0 : _a.averageRating) || 0;
15874
- if (filters.minRating !== void 0 && rating < filters.minRating)
15875
- return false;
15876
- if (filters.maxRating !== void 0 && rating > filters.maxRating)
15877
- return false;
15761
+ if (filters.minRating !== void 0 && rating < filters.minRating) return false;
15762
+ if (filters.maxRating !== void 0 && rating > filters.maxRating) return false;
15878
15763
  return true;
15879
15764
  });
15880
15765
  console.log(
@@ -15882,12 +15767,10 @@ var ProcedureService = class extends BaseService {
15882
15767
  );
15883
15768
  }
15884
15769
  if (filters.treatmentBenefits && filters.treatmentBenefits.length > 0) {
15885
- const benefitIdsToMatch = filters.treatmentBenefits;
15770
+ const benefitsToMatch = filters.treatmentBenefits;
15886
15771
  filteredProcedures = filteredProcedures.filter((procedure) => {
15887
- const procedureBenefitIds = procedure.treatmentBenefitIds || [];
15888
- return benefitIdsToMatch.some(
15889
- (benefitId) => procedureBenefitIds.includes(benefitId)
15890
- );
15772
+ const procedureBenefits = procedure.treatmentBenefits || [];
15773
+ return benefitsToMatch.some((benefit) => procedureBenefits.includes(benefit));
15891
15774
  });
15892
15775
  console.log(
15893
15776
  `[PROCEDURE_SERVICE] Applied benefits filter, results: ${filteredProcedures.length}`
@@ -15950,12 +15833,8 @@ var ProcedureService = class extends BaseService {
15950
15833
  procedure.distance = distance;
15951
15834
  return distance <= radiusInKm;
15952
15835
  });
15953
- console.log(
15954
- `[PROCEDURE_SERVICE] Applied geo filter, results: ${filteredProcedures.length}`
15955
- );
15956
- filteredProcedures.sort(
15957
- (a, b) => (a.distance || 0) - (b.distance || 0)
15958
- );
15836
+ console.log(`[PROCEDURE_SERVICE] Applied geo filter, results: ${filteredProcedures.length}`);
15837
+ filteredProcedures.sort((a, b) => (a.distance || 0) - (b.distance || 0));
15959
15838
  }
15960
15839
  return filteredProcedures;
15961
15840
  }
@@ -15967,30 +15846,19 @@ var ProcedureService = class extends BaseService {
15967
15846
  if (!location || !radiusInKm) {
15968
15847
  return Promise.resolve({ procedures: [], lastDoc: null });
15969
15848
  }
15970
- const bounds = geohashQueryBounds5(
15971
- [location.latitude, location.longitude],
15972
- radiusInKm * 1e3
15973
- );
15849
+ const bounds = geohashQueryBounds5([location.latitude, location.longitude], radiusInKm * 1e3);
15974
15850
  const fetches = bounds.map((b) => {
15975
15851
  const constraints = [
15976
15852
  where29("clinicInfo.location.geohash", ">=", b[0]),
15977
15853
  where29("clinicInfo.location.geohash", "<=", b[1]),
15978
- where29(
15979
- "isActive",
15980
- "==",
15981
- filters.isActive !== void 0 ? filters.isActive : true
15982
- )
15854
+ where29("isActive", "==", filters.isActive !== void 0 ? filters.isActive : true)
15983
15855
  ];
15984
- return getDocs29(
15985
- query29(collection29(this.db, PROCEDURES_COLLECTION), ...constraints)
15986
- );
15856
+ return getDocs29(query29(collection29(this.db, PROCEDURES_COLLECTION), ...constraints));
15987
15857
  });
15988
15858
  return Promise.all(fetches).then((snaps) => {
15989
15859
  const collected = [];
15990
15860
  snaps.forEach((snap) => {
15991
- snap.docs.forEach(
15992
- (d) => collected.push({ ...d.data(), id: d.id })
15993
- );
15861
+ snap.docs.forEach((d) => collected.push({ ...d.data(), id: d.id }));
15994
15862
  });
15995
15863
  const uniqueMap = /* @__PURE__ */ new Map();
15996
15864
  for (const p of collected) {
@@ -16001,9 +15869,7 @@ var ProcedureService = class extends BaseService {
16001
15869
  const pageSize = filters.pagination || 10;
16002
15870
  let startIndex = 0;
16003
15871
  if (filters.lastDoc && typeof filters.lastDoc === "object" && filters.lastDoc.id) {
16004
- const idx = procedures.findIndex(
16005
- (p) => p.id === filters.lastDoc.id
16006
- );
15872
+ const idx = procedures.findIndex((p) => p.id === filters.lastDoc.id);
16007
15873
  if (idx >= 0) startIndex = idx + 1;
16008
15874
  }
16009
15875
  const page = procedures.slice(startIndex, startIndex + pageSize);
@@ -16028,7 +15894,7 @@ var ProcedureService = class extends BaseService {
16028
15894
  * @returns The created procedure
16029
15895
  */
16030
15896
  async createConsultationProcedure(data) {
16031
- var _a, _b, _c;
15897
+ var _a;
16032
15898
  const procedureId = this.generateId();
16033
15899
  const [category, subcategory, technology] = await Promise.all([
16034
15900
  this.categoryService.getById(data.categoryId),
@@ -16044,11 +15910,7 @@ var ProcedureService = class extends BaseService {
16044
15910
  throw new Error(`Clinic with ID ${data.clinicBranchId} not found`);
16045
15911
  }
16046
15912
  const clinic = clinicSnapshot.data();
16047
- const practitionerRef = doc30(
16048
- this.db,
16049
- PRACTITIONERS_COLLECTION,
16050
- data.practitionerId
16051
- );
15913
+ const practitionerRef = doc30(this.db, PRACTITIONERS_COLLECTION, data.practitionerId);
16052
15914
  const practitionerSnapshot = await getDoc32(practitionerRef);
16053
15915
  if (!practitionerSnapshot.exists()) {
16054
15916
  throw new Error(`Practitioner with ID ${data.practitionerId} not found`);
@@ -16056,11 +15918,7 @@ var ProcedureService = class extends BaseService {
16056
15918
  const practitioner = practitionerSnapshot.data();
16057
15919
  let processedPhotos = [];
16058
15920
  if (data.photos && data.photos.length > 0) {
16059
- processedPhotos = await this.processMediaArray(
16060
- data.photos,
16061
- procedureId,
16062
- "procedure-photos"
16063
- );
15921
+ processedPhotos = await this.processMediaArray(data.photos, procedureId, "procedure-photos");
16064
15922
  }
16065
15923
  const clinicInfo = {
16066
15924
  id: clinicSnapshot.id,
@@ -16102,9 +15960,7 @@ var ProcedureService = class extends BaseService {
16102
15960
  // Use placeholder product
16103
15961
  blockingConditions: technology.blockingConditions,
16104
15962
  contraindications: technology.contraindications || [],
16105
- contraindicationIds: ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [],
16106
15963
  treatmentBenefits: technology.benefits,
16107
- treatmentBenefitIds: ((_c = technology.benefits) == null ? void 0 : _c.map((b) => b.id)) || [],
16108
15964
  preRequirements: technology.requirements.pre,
16109
15965
  postRequirements: technology.requirements.post,
16110
15966
  certificationRequirement: technology.certificationRequirement,
@@ -16973,16 +16829,8 @@ var TechnologyService = class extends BaseService {
16973
16829
  */
16974
16830
  async addContraindication(technologyId, contraindication) {
16975
16831
  const docRef = doc35(this.getTechnologiesRef(), technologyId);
16976
- const technology = await this.getById(technologyId);
16977
- if (!technology) {
16978
- throw new Error(`Technology with id ${technologyId} not found`);
16979
- }
16980
- const existingContraindications = technology.contraindications || [];
16981
- if (existingContraindications.some((c) => c.id === contraindication.id)) {
16982
- return technology;
16983
- }
16984
16832
  await updateDoc33(docRef, {
16985
- contraindications: [...existingContraindications, contraindication],
16833
+ contraindications: arrayUnion9(contraindication),
16986
16834
  updatedAt: /* @__PURE__ */ new Date()
16987
16835
  });
16988
16836
  return this.getById(technologyId);
@@ -16995,44 +16843,8 @@ var TechnologyService = class extends BaseService {
16995
16843
  */
16996
16844
  async removeContraindication(technologyId, contraindication) {
16997
16845
  const docRef = doc35(this.getTechnologiesRef(), technologyId);
16998
- const technology = await this.getById(technologyId);
16999
- if (!technology) {
17000
- throw new Error(`Technology with id ${technologyId} not found`);
17001
- }
17002
- const updatedContraindications = (technology.contraindications || []).filter((c) => c.id !== contraindication.id);
17003
- await updateDoc33(docRef, {
17004
- contraindications: updatedContraindications,
17005
- updatedAt: /* @__PURE__ */ new Date()
17006
- });
17007
- return this.getById(technologyId);
17008
- }
17009
- /**
17010
- * Updates an existing contraindication in a technology's list.
17011
- * If the contraindication does not exist, it will not be added.
17012
- * @param technologyId - ID of the technology
17013
- * @param contraindication - The updated contraindication object
17014
- * @returns The updated technology
17015
- */
17016
- async updateContraindication(technologyId, contraindication) {
17017
- const docRef = doc35(this.getTechnologiesRef(), technologyId);
17018
- const technology = await this.getById(technologyId);
17019
- if (!technology) {
17020
- throw new Error(`Technology with id ${technologyId} not found`);
17021
- }
17022
- const contraindications = technology.contraindications || [];
17023
- const index = contraindications.findIndex(
17024
- (c) => c.id === contraindication.id
17025
- );
17026
- if (index === -1) {
17027
- console.warn(
17028
- `Contraindication with id ${contraindication.id} not found for technology ${technologyId}. No update performed.`
17029
- );
17030
- return technology;
17031
- }
17032
- const updatedContraindications = [...contraindications];
17033
- updatedContraindications[index] = contraindication;
17034
16846
  await updateDoc33(docRef, {
17035
- contraindications: updatedContraindications,
16847
+ contraindications: arrayRemove8(contraindication),
17036
16848
  updatedAt: /* @__PURE__ */ new Date()
17037
16849
  });
17038
16850
  return this.getById(technologyId);
@@ -17045,16 +16857,8 @@ var TechnologyService = class extends BaseService {
17045
16857
  */
17046
16858
  async addBenefit(technologyId, benefit) {
17047
16859
  const docRef = doc35(this.getTechnologiesRef(), technologyId);
17048
- const technology = await this.getById(technologyId);
17049
- if (!technology) {
17050
- throw new Error(`Technology with id ${technologyId} not found`);
17051
- }
17052
- const existingBenefits = technology.benefits || [];
17053
- if (existingBenefits.some((b) => b.id === benefit.id)) {
17054
- return technology;
17055
- }
17056
16860
  await updateDoc33(docRef, {
17057
- benefits: [...existingBenefits, benefit],
16861
+ benefits: arrayUnion9(benefit),
17058
16862
  updatedAt: /* @__PURE__ */ new Date()
17059
16863
  });
17060
16864
  return this.getById(technologyId);
@@ -17067,44 +16871,8 @@ var TechnologyService = class extends BaseService {
17067
16871
  */
17068
16872
  async removeBenefit(technologyId, benefit) {
17069
16873
  const docRef = doc35(this.getTechnologiesRef(), technologyId);
17070
- const technology = await this.getById(technologyId);
17071
- if (!technology) {
17072
- throw new Error(`Technology with id ${technologyId} not found`);
17073
- }
17074
- const updatedBenefits = (technology.benefits || []).filter(
17075
- (b) => b.id !== benefit.id
17076
- );
17077
16874
  await updateDoc33(docRef, {
17078
- benefits: updatedBenefits,
17079
- updatedAt: /* @__PURE__ */ new Date()
17080
- });
17081
- return this.getById(technologyId);
17082
- }
17083
- /**
17084
- * Updates an existing benefit in a technology's list.
17085
- * If the benefit does not exist, it will not be added.
17086
- * @param technologyId - ID of the technology
17087
- * @param benefit - The updated benefit object
17088
- * @returns The updated technology
17089
- */
17090
- async updateBenefit(technologyId, benefit) {
17091
- const docRef = doc35(this.getTechnologiesRef(), technologyId);
17092
- const technology = await this.getById(technologyId);
17093
- if (!technology) {
17094
- throw new Error(`Technology with id ${technologyId} not found`);
17095
- }
17096
- const benefits = technology.benefits || [];
17097
- const index = benefits.findIndex((b) => b.id === benefit.id);
17098
- if (index === -1) {
17099
- console.warn(
17100
- `Benefit with id ${benefit.id} not found for technology ${technologyId}. No update performed.`
17101
- );
17102
- return technology;
17103
- }
17104
- const updatedBenefits = [...benefits];
17105
- updatedBenefits[index] = benefit;
17106
- await updateDoc33(docRef, {
17107
- benefits: updatedBenefits,
16875
+ benefits: arrayRemove8(benefit),
17108
16876
  updatedAt: /* @__PURE__ */ new Date()
17109
16877
  });
17110
16878
  return this.getById(technologyId);
@@ -17367,23 +17135,6 @@ var ProductService = class extends BaseService {
17367
17135
  }
17368
17136
  };
17369
17137
 
17370
- // src/backoffice/types/static/contraindication.types.ts
17371
- var Contraindication = /* @__PURE__ */ ((Contraindication2) => {
17372
- Contraindication2["SENSITIVE_SKIN"] = "sensitive_skin";
17373
- Contraindication2["RECENT_TANNING"] = "recent_tanning";
17374
- Contraindication2["RECENT_BOTOX"] = "recent_botox";
17375
- Contraindication2["RECENT_FILLERS"] = "recent_fillers";
17376
- Contraindication2["SKIN_ALLERGIES"] = "skin_allergies";
17377
- Contraindication2["MEDICATIONS"] = "medications";
17378
- Contraindication2["RECENT_CHEMICAL_PEEL"] = "recent_chemical_peel";
17379
- Contraindication2["RECENT_LASER"] = "recent_laser";
17380
- Contraindication2["SKIN_INFLAMMATION"] = "skin_inflammation";
17381
- Contraindication2["OPEN_WOUNDS"] = "open_wounds";
17382
- Contraindication2["HERPES_SIMPLEX"] = "herpes_simplex";
17383
- Contraindication2["COLD_SORES"] = "cold_sores";
17384
- return Contraindication2;
17385
- })(Contraindication || {});
17386
-
17387
17138
  // src/backoffice/types/static/treatment-benefit.types.ts
17388
17139
  var TreatmentBenefit = /* @__PURE__ */ ((TreatmentBenefit2) => {
17389
17140
  TreatmentBenefit2["WRINKLE_REDUCTION"] = "wrinkle_reduction";