@blackcode_sa/metaestetics-api 1.11.1 → 1.11.3

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 +326 -330
  2. package/dist/admin/index.d.ts +326 -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 +3039 -3100
  8. package/dist/index.d.ts +3039 -3100
  9. package/dist/index.js +131 -380
  10. package/dist/index.mjs +132 -380
  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 +39 -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 +119 -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.js CHANGED
@@ -181,13 +181,13 @@ var AppointmentStatus = /* @__PURE__ */ ((AppointmentStatus2) => {
181
181
  AppointmentStatus2["RESCHEDULED_BY_CLINIC"] = "rescheduled_by_clinic";
182
182
  return AppointmentStatus2;
183
183
  })(AppointmentStatus || {});
184
- var PaymentStatus = /* @__PURE__ */ ((PaymentStatus4) => {
185
- PaymentStatus4["UNPAID"] = "unpaid";
186
- PaymentStatus4["PAID"] = "paid";
187
- PaymentStatus4["PARTIALLY_PAID"] = "partially_paid";
188
- PaymentStatus4["REFUNDED"] = "refunded";
189
- PaymentStatus4["NOT_APPLICABLE"] = "not_applicable";
190
- return PaymentStatus4;
184
+ var PaymentStatus = /* @__PURE__ */ ((PaymentStatus3) => {
185
+ PaymentStatus3["UNPAID"] = "unpaid";
186
+ PaymentStatus3["PAID"] = "paid";
187
+ PaymentStatus3["PARTIALLY_PAID"] = "partially_paid";
188
+ PaymentStatus3["REFUNDED"] = "refunded";
189
+ PaymentStatus3["NOT_APPLICABLE"] = "not_applicable";
190
+ return PaymentStatus3;
191
191
  })(PaymentStatus || {});
192
192
  var MediaType = /* @__PURE__ */ ((MediaType2) => {
193
193
  MediaType2["BEFORE_PHOTO"] = "before_photo";
@@ -539,7 +539,8 @@ var finalizedDetailsSchema = import_zod3.z.object({
539
539
  var beforeAfterPerZoneSchema = import_zod3.z.object({
540
540
  before: mediaResourceSchema.nullable(),
541
541
  after: mediaResourceSchema.nullable(),
542
- note: import_zod3.z.string().nullable()
542
+ afterNote: import_zod3.z.string().nullable().optional(),
543
+ beforeNote: import_zod3.z.string().nullable().optional()
543
544
  });
544
545
  var billingPerZoneSchema = import_zod3.z.object({
545
546
  Product: import_zod3.z.string().min(MIN_STRING_LENGTH, "Product name is required"),
@@ -549,7 +550,8 @@ var billingPerZoneSchema = import_zod3.z.object({
549
550
  UnitPrice: import_zod3.z.number().min(0, "Unit price must be non-negative"),
550
551
  UnitCurency: import_zod3.z.nativeEnum(Currency),
551
552
  Subtotal: import_zod3.z.number().min(0, "Subtotal must be non-negative"),
552
- Note: import_zod3.z.string().nullable()
553
+ Note: import_zod3.z.string().nullable(),
554
+ IonNumber: import_zod3.z.string().nullable()
553
555
  });
554
556
  var finalBillingSchema = import_zod3.z.object({
555
557
  subtotalAll: import_zod3.z.number().min(0, "Subtotal all must be non-negative"),
@@ -564,7 +566,8 @@ var appointmentMetadataSchema = import_zod3.z.object({
564
566
  selectedZones: import_zod3.z.array(import_zod3.z.string()).nullable(),
565
567
  zonePhotos: import_zod3.z.record(import_zod3.z.string(), beforeAfterPerZoneSchema).nullable(),
566
568
  zoneBilling: import_zod3.z.record(import_zod3.z.string(), billingPerZoneSchema).nullable(),
567
- finalbilling: finalBillingSchema.nullable()
569
+ finalbilling: finalBillingSchema.nullable(),
570
+ finalizationNotes: import_zod3.z.string().nullable()
568
571
  });
569
572
  var createAppointmentSchema = import_zod3.z.object({
570
573
  clinicBranchId: import_zod3.z.string().min(MIN_STRING_LENGTH, "Clinic branch ID is required"),
@@ -620,10 +623,7 @@ var updateAppointmentSchema = import_zod3.z.object({
620
623
  practitionerId: import_zod3.z.string().min(MIN_STRING_LENGTH).optional(),
621
624
  clinic_tz: import_zod3.z.string().min(MIN_STRING_LENGTH).optional(),
622
625
  linkedForms: import_zod3.z.union([import_zod3.z.array(linkedFormInfoSchema).max(MAX_ARRAY_LENGTH), import_zod3.z.any()]).optional(),
623
- media: import_zod3.z.union([
624
- import_zod3.z.array(appointmentMediaItemSchema).max(MAX_ARRAY_LENGTH),
625
- import_zod3.z.any()
626
- ]).optional(),
626
+ media: import_zod3.z.union([import_zod3.z.array(appointmentMediaItemSchema).max(MAX_ARRAY_LENGTH), import_zod3.z.any()]).optional(),
627
627
  reviewInfo: import_zod3.z.union([patientReviewInfoSchema.nullable(), import_zod3.z.any()]).optional(),
628
628
  finalizedDetails: import_zod3.z.union([finalizedDetailsSchema.nullable(), import_zod3.z.any()]).optional(),
629
629
  isArchived: import_zod3.z.boolean().optional(),
@@ -664,10 +664,7 @@ var searchAppointmentsSchema = import_zod3.z.object({
664
664
  (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",
665
665
  "End date must be a valid timestamp or Date object"
666
666
  ).optional(),
667
- status: import_zod3.z.union([
668
- appointmentStatusSchema,
669
- import_zod3.z.array(appointmentStatusSchema).nonempty()
670
- ]).optional(),
667
+ status: import_zod3.z.union([appointmentStatusSchema, import_zod3.z.array(appointmentStatusSchema).nonempty()]).optional(),
671
668
  limit: import_zod3.z.number().positive().int().optional().default(20),
672
669
  startAfter: import_zod3.z.any().optional()
673
670
  }).refine(
@@ -936,48 +933,44 @@ async function updateAppointmentUtil(db, appointmentId, data) {
936
933
  const validPreReqIds = currentAppointment.preProcedureRequirements.map(
937
934
  (req) => req.id
938
935
  );
939
- if (Array.isArray(data.completedPreRequirements)) {
940
- const invalidPreReqIds = data.completedPreRequirements.filter(
941
- (id) => !validPreReqIds.includes(id)
936
+ const invalidPreReqIds = data.completedPreRequirements.filter(
937
+ (id) => !validPreReqIds.includes(id)
938
+ );
939
+ if (invalidPreReqIds.length > 0) {
940
+ throw new Error(
941
+ `Invalid pre-requirement IDs: ${invalidPreReqIds.join(", ")}`
942
942
  );
943
- if (invalidPreReqIds.length > 0) {
944
- throw new Error(
945
- `Invalid pre-requirement IDs: ${invalidPreReqIds.join(", ")}`
946
- );
947
- }
948
- completedPreRequirements = [
949
- .../* @__PURE__ */ new Set([
950
- ...completedPreRequirements,
951
- ...data.completedPreRequirements
952
- ])
953
- ];
954
943
  }
944
+ completedPreRequirements = [
945
+ .../* @__PURE__ */ new Set([
946
+ ...completedPreRequirements,
947
+ ...data.completedPreRequirements
948
+ ])
949
+ ];
955
950
  }
956
951
  if (data.completedPostRequirements) {
957
952
  const validPostReqIds = currentAppointment.postProcedureRequirements.map(
958
953
  (req) => req.id
959
954
  );
960
- if (Array.isArray(data.completedPostRequirements)) {
961
- const invalidPostReqIds = data.completedPostRequirements.filter(
962
- (id) => !validPostReqIds.includes(id)
955
+ const invalidPostReqIds = data.completedPostRequirements.filter(
956
+ (id) => !validPostReqIds.includes(id)
957
+ );
958
+ if (invalidPostReqIds.length > 0) {
959
+ throw new Error(
960
+ `Invalid post-requirement IDs: ${invalidPostReqIds.join(", ")}`
963
961
  );
964
- if (invalidPostReqIds.length > 0) {
965
- throw new Error(
966
- `Invalid post-requirement IDs: ${invalidPostReqIds.join(", ")}`
967
- );
968
- }
969
- completedPostRequirements = [
970
- .../* @__PURE__ */ new Set([
971
- ...completedPostRequirements,
972
- ...data.completedPostRequirements
973
- ])
974
- ];
975
962
  }
963
+ completedPostRequirements = [
964
+ .../* @__PURE__ */ new Set([
965
+ ...completedPostRequirements,
966
+ ...data.completedPostRequirements
967
+ ])
968
+ ];
976
969
  }
977
970
  const updateData = {
978
971
  ...data,
979
- completedPreRequirements: Array.isArray(data.completedPreRequirements) ? completedPreRequirements : data.completedPreRequirements,
980
- completedPostRequirements: Array.isArray(data.completedPostRequirements) ? completedPostRequirements : data.completedPostRequirements,
972
+ completedPreRequirements,
973
+ completedPostRequirements,
981
974
  updatedAt: (0, import_firestore.serverTimestamp)()
982
975
  };
983
976
  Object.keys(updateData).forEach((key) => {
@@ -1027,7 +1020,7 @@ async function updateCalendarEventStatus(db, calendarEventId, appointmentStatus)
1027
1020
  case "canceled_clinic" /* CANCELED_CLINIC */:
1028
1021
  calendarStatus = "canceled";
1029
1022
  break;
1030
- case "rescheduled_by_clinic" /* RESCHEDULED_BY_CLINIC */:
1023
+ case AppointmentStatus.RESCHEDULED:
1031
1024
  calendarStatus = "rescheduled";
1032
1025
  break;
1033
1026
  case "completed" /* COMPLETED */:
@@ -2843,6 +2836,23 @@ var BlockingCondition = /* @__PURE__ */ ((BlockingCondition2) => {
2843
2836
  return BlockingCondition2;
2844
2837
  })(BlockingCondition || {});
2845
2838
 
2839
+ // src/backoffice/types/static/contraindication.types.ts
2840
+ var Contraindication = /* @__PURE__ */ ((Contraindication2) => {
2841
+ Contraindication2["SENSITIVE_SKIN"] = "sensitive_skin";
2842
+ Contraindication2["RECENT_TANNING"] = "recent_tanning";
2843
+ Contraindication2["RECENT_BOTOX"] = "recent_botox";
2844
+ Contraindication2["RECENT_FILLERS"] = "recent_fillers";
2845
+ Contraindication2["SKIN_ALLERGIES"] = "skin_allergies";
2846
+ Contraindication2["MEDICATIONS"] = "medications";
2847
+ Contraindication2["RECENT_CHEMICAL_PEEL"] = "recent_chemical_peel";
2848
+ Contraindication2["RECENT_LASER"] = "recent_laser";
2849
+ Contraindication2["SKIN_INFLAMMATION"] = "skin_inflammation";
2850
+ Contraindication2["OPEN_WOUNDS"] = "open_wounds";
2851
+ Contraindication2["HERPES_SIMPLEX"] = "herpes_simplex";
2852
+ Contraindication2["COLD_SORES"] = "cold_sores";
2853
+ return Contraindication2;
2854
+ })(Contraindication || {});
2855
+
2846
2856
  // src/validations/common.schema.ts
2847
2857
  var import_zod5 = require("zod");
2848
2858
  var import_firestore6 = require("firebase/firestore");
@@ -2897,13 +2907,8 @@ var blockingConditionSchema = import_zod6.z.object({
2897
2907
  notes: import_zod6.z.string().optional().nullable(),
2898
2908
  isActive: import_zod6.z.boolean()
2899
2909
  });
2900
- var contraindicationDynamicSchema = import_zod6.z.object({
2901
- id: import_zod6.z.string(),
2902
- name: import_zod6.z.string(),
2903
- description: import_zod6.z.string().optional()
2904
- });
2905
2910
  var contraindicationSchema = import_zod6.z.object({
2906
- condition: contraindicationDynamicSchema,
2911
+ condition: import_zod6.z.nativeEnum(Contraindication),
2907
2912
  lastOccurrence: timestampSchema,
2908
2913
  frequency: import_zod6.z.enum(["rare", "occasional", "frequent"]),
2909
2914
  notes: import_zod6.z.string().optional().nullable(),
@@ -10623,7 +10628,7 @@ async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId,
10623
10628
  }
10624
10629
 
10625
10630
  // src/services/calendar/utils/appointment.utils.ts
10626
- async function createAppointmentUtil(db, clinicId, practitionerId, patientId, eventData, generateId2) {
10631
+ async function createAppointmentUtil2(db, clinicId, practitionerId, patientId, eventData, generateId2) {
10627
10632
  const eventId = generateId2();
10628
10633
  const autoConfirm = await checkAutoConfirmAppointmentsUtil(db, clinicId);
10629
10634
  const initialStatus = autoConfirm ? "confirmed" /* CONFIRMED */ : "pending" /* PENDING */;
@@ -11941,7 +11946,7 @@ var CalendarServiceV2 = class extends BaseService {
11941
11946
  syncStatus: "internal" /* INTERNAL */,
11942
11947
  eventType: "appointment" /* APPOINTMENT */
11943
11948
  };
11944
- const appointment = await createAppointmentUtil(
11949
+ const appointment = await createAppointmentUtil2(
11945
11950
  this.db,
11946
11951
  params.clinicId,
11947
11952
  params.doctorId,
@@ -14746,9 +14751,7 @@ var ProcedureService = class extends BaseService {
14746
14751
  return media;
14747
14752
  }
14748
14753
  if (media instanceof File || media instanceof Blob) {
14749
- console.log(
14750
- `[ProcedureService] Uploading ${collectionName} media for ${ownerId}`
14751
- );
14754
+ console.log(`[ProcedureService] Uploading ${collectionName} media for ${ownerId}`);
14752
14755
  const metadata = await this.mediaService.uploadMedia(
14753
14756
  media,
14754
14757
  ownerId,
@@ -14770,11 +14773,7 @@ var ProcedureService = class extends BaseService {
14770
14773
  if (!mediaArray || mediaArray.length === 0) return [];
14771
14774
  const result = [];
14772
14775
  for (const media of mediaArray) {
14773
- const processedUrl = await this.processMedia(
14774
- media,
14775
- ownerId,
14776
- collectionName
14777
- );
14776
+ const processedUrl = await this.processMedia(media, ownerId, collectionName);
14778
14777
  if (processedUrl) {
14779
14778
  result.push(processedUrl);
14780
14779
  }
@@ -14787,46 +14786,28 @@ var ProcedureService = class extends BaseService {
14787
14786
  * @returns The created procedure
14788
14787
  */
14789
14788
  async createProcedure(data) {
14790
- var _a, _b, _c;
14789
+ var _a;
14791
14790
  const validatedData = createProcedureSchema.parse(data);
14792
14791
  const procedureId = this.generateId();
14793
14792
  const [category, subcategory, technology, product] = await Promise.all([
14794
14793
  this.categoryService.getById(validatedData.categoryId),
14795
- this.subcategoryService.getById(
14796
- validatedData.categoryId,
14797
- validatedData.subcategoryId
14798
- ),
14794
+ this.subcategoryService.getById(validatedData.categoryId, validatedData.subcategoryId),
14799
14795
  this.technologyService.getById(validatedData.technologyId),
14800
- this.productService.getById(
14801
- validatedData.technologyId,
14802
- validatedData.productId
14803
- )
14796
+ this.productService.getById(validatedData.technologyId, validatedData.productId)
14804
14797
  ]);
14805
14798
  if (!category || !subcategory || !technology || !product) {
14806
14799
  throw new Error("One or more required base entities not found");
14807
14800
  }
14808
- const clinicRef = (0, import_firestore45.doc)(
14809
- this.db,
14810
- CLINICS_COLLECTION,
14811
- validatedData.clinicBranchId
14812
- );
14801
+ const clinicRef = (0, import_firestore45.doc)(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId);
14813
14802
  const clinicSnapshot = await (0, import_firestore45.getDoc)(clinicRef);
14814
14803
  if (!clinicSnapshot.exists()) {
14815
- throw new Error(
14816
- `Clinic with ID ${validatedData.clinicBranchId} not found`
14817
- );
14804
+ throw new Error(`Clinic with ID ${validatedData.clinicBranchId} not found`);
14818
14805
  }
14819
14806
  const clinic = clinicSnapshot.data();
14820
- const practitionerRef = (0, import_firestore45.doc)(
14821
- this.db,
14822
- PRACTITIONERS_COLLECTION,
14823
- validatedData.practitionerId
14824
- );
14807
+ const practitionerRef = (0, import_firestore45.doc)(this.db, PRACTITIONERS_COLLECTION, validatedData.practitionerId);
14825
14808
  const practitionerSnapshot = await (0, import_firestore45.getDoc)(practitionerRef);
14826
14809
  if (!practitionerSnapshot.exists()) {
14827
- throw new Error(
14828
- `Practitioner with ID ${validatedData.practitionerId} not found`
14829
- );
14810
+ throw new Error(`Practitioner with ID ${validatedData.practitionerId} not found`);
14830
14811
  }
14831
14812
  const practitioner = practitionerSnapshot.data();
14832
14813
  let processedPhotos = [];
@@ -14867,9 +14848,7 @@ var ProcedureService = class extends BaseService {
14867
14848
  product,
14868
14849
  blockingConditions: technology.blockingConditions,
14869
14850
  contraindications: technology.contraindications || [],
14870
- contraindicationIds: ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [],
14871
14851
  treatmentBenefits: technology.benefits,
14872
- treatmentBenefitIds: ((_c = technology.benefits) == null ? void 0 : _c.map((b) => b.id)) || [],
14873
14852
  preRequirements: technology.requirements.pre,
14874
14853
  postRequirements: technology.requirements.post,
14875
14854
  certificationRequirement: technology.certificationRequirement,
@@ -14910,7 +14889,7 @@ var ProcedureService = class extends BaseService {
14910
14889
  * @returns A promise that resolves to an array of the newly created procedures.
14911
14890
  */
14912
14891
  async bulkCreateProcedures(baseData, practitionerIds) {
14913
- var _a, _b, _c;
14892
+ var _a;
14914
14893
  if (!practitionerIds || practitionerIds.length === 0) {
14915
14894
  throw new Error("Practitioner IDs array cannot be empty.");
14916
14895
  }
@@ -14918,24 +14897,16 @@ var ProcedureService = class extends BaseService {
14918
14897
  const validatedData = createProcedureSchema.parse(validationData);
14919
14898
  const [category, subcategory, technology, product, clinicSnapshot] = await Promise.all([
14920
14899
  this.categoryService.getById(validatedData.categoryId),
14921
- this.subcategoryService.getById(
14922
- validatedData.categoryId,
14923
- validatedData.subcategoryId
14924
- ),
14900
+ this.subcategoryService.getById(validatedData.categoryId, validatedData.subcategoryId),
14925
14901
  this.technologyService.getById(validatedData.technologyId),
14926
- this.productService.getById(
14927
- validatedData.technologyId,
14928
- validatedData.productId
14929
- ),
14902
+ this.productService.getById(validatedData.technologyId, validatedData.productId),
14930
14903
  (0, import_firestore45.getDoc)((0, import_firestore45.doc)(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId))
14931
14904
  ]);
14932
14905
  if (!category || !subcategory || !technology || !product) {
14933
14906
  throw new Error("One or more required base entities not found");
14934
14907
  }
14935
14908
  if (!clinicSnapshot.exists()) {
14936
- throw new Error(
14937
- `Clinic with ID ${validatedData.clinicBranchId} not found`
14938
- );
14909
+ throw new Error(`Clinic with ID ${validatedData.clinicBranchId} not found`);
14939
14910
  }
14940
14911
  const clinic = clinicSnapshot.data();
14941
14912
  let processedPhotos = [];
@@ -14961,12 +14932,8 @@ var ProcedureService = class extends BaseService {
14961
14932
  }
14962
14933
  if (practitionersMap.size !== practitionerIds.length) {
14963
14934
  const foundIds = Array.from(practitionersMap.keys());
14964
- const notFoundIds = practitionerIds.filter(
14965
- (id) => !foundIds.includes(id)
14966
- );
14967
- throw new Error(
14968
- `The following practitioners were not found: ${notFoundIds.join(", ")}`
14969
- );
14935
+ const notFoundIds = practitionerIds.filter((id) => !foundIds.includes(id));
14936
+ throw new Error(`The following practitioners were not found: ${notFoundIds.join(", ")}`);
14970
14937
  }
14971
14938
  const batch = (0, import_firestore45.writeBatch)(this.db);
14972
14939
  const createdProcedureIds = [];
@@ -15004,9 +14971,7 @@ var ProcedureService = class extends BaseService {
15004
14971
  product,
15005
14972
  blockingConditions: technology.blockingConditions,
15006
14973
  contraindications: technology.contraindications || [],
15007
- contraindicationIds: ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [],
15008
14974
  treatmentBenefits: technology.benefits,
15009
- treatmentBenefitIds: ((_c = technology.benefits) == null ? void 0 : _c.map((b) => b.id)) || [],
15010
14975
  preRequirements: technology.requirements.pre,
15011
14976
  postRequirements: technology.requirements.post,
15012
14977
  certificationRequirement: technology.certificationRequirement,
@@ -15036,10 +15001,7 @@ var ProcedureService = class extends BaseService {
15036
15001
  const fetchedProcedures = [];
15037
15002
  for (let i = 0; i < createdProcedureIds.length; i += 30) {
15038
15003
  const chunk = createdProcedureIds.slice(i, i + 30);
15039
- const q = (0, import_firestore45.query)(
15040
- (0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION),
15041
- (0, import_firestore45.where)((0, import_firestore45.documentId)(), "in", chunk)
15042
- );
15004
+ const q = (0, import_firestore45.query)((0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION), (0, import_firestore45.where)((0, import_firestore45.documentId)(), "in", chunk));
15043
15005
  const snapshot = await (0, import_firestore45.getDocs)(q);
15044
15006
  snapshot.forEach((doc37) => {
15045
15007
  fetchedProcedures.push(doc37.data());
@@ -15109,7 +15071,7 @@ var ProcedureService = class extends BaseService {
15109
15071
  * @returns The updated procedure
15110
15072
  */
15111
15073
  async updateProcedure(id, data) {
15112
- var _a, _b, _c;
15074
+ var _a;
15113
15075
  const validatedData = updateProcedureSchema.parse(data);
15114
15076
  const procedureRef = (0, import_firestore45.doc)(this.db, PROCEDURES_COLLECTION, id);
15115
15077
  const procedureSnapshot = await (0, import_firestore45.getDoc)(procedureRef);
@@ -15140,9 +15102,7 @@ var ProcedureService = class extends BaseService {
15140
15102
  );
15141
15103
  const newPractitionerSnap = await (0, import_firestore45.getDoc)(newPractitionerRef);
15142
15104
  if (!newPractitionerSnap.exists())
15143
- throw new Error(
15144
- `New Practitioner ${validatedData.practitionerId} not found`
15145
- );
15105
+ throw new Error(`New Practitioner ${validatedData.practitionerId} not found`);
15146
15106
  newPractitioner = newPractitionerSnap.data();
15147
15107
  updatedProcedureData.doctorInfo = {
15148
15108
  id: newPractitioner.id,
@@ -15156,11 +15116,7 @@ var ProcedureService = class extends BaseService {
15156
15116
  }
15157
15117
  if (validatedData.clinicBranchId && validatedData.clinicBranchId !== oldClinicId) {
15158
15118
  clinicChanged = true;
15159
- const newClinicRef = (0, import_firestore45.doc)(
15160
- this.db,
15161
- CLINICS_COLLECTION,
15162
- validatedData.clinicBranchId
15163
- );
15119
+ const newClinicRef = (0, import_firestore45.doc)(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId);
15164
15120
  const newClinicSnap = await (0, import_firestore45.getDoc)(newClinicRef);
15165
15121
  if (!newClinicSnap.exists())
15166
15122
  throw new Error(`New Clinic ${validatedData.clinicBranchId} not found`);
@@ -15179,11 +15135,8 @@ var ProcedureService = class extends BaseService {
15179
15135
  updatedProcedureData.nameLower = validatedData.name.toLowerCase();
15180
15136
  }
15181
15137
  if (validatedData.categoryId) {
15182
- const category = await this.categoryService.getById(
15183
- validatedData.categoryId
15184
- );
15185
- if (!category)
15186
- throw new Error(`Category ${validatedData.categoryId} not found`);
15138
+ const category = await this.categoryService.getById(validatedData.categoryId);
15139
+ if (!category) throw new Error(`Category ${validatedData.categoryId} not found`);
15187
15140
  updatedProcedureData.category = category;
15188
15141
  finalCategoryId = category.id;
15189
15142
  }
@@ -15198,34 +15151,23 @@ var ProcedureService = class extends BaseService {
15198
15151
  );
15199
15152
  updatedProcedureData.subcategory = subcategory;
15200
15153
  } else if (validatedData.subcategoryId) {
15201
- console.warn(
15202
- "Attempted to update subcategory without a valid categoryId"
15203
- );
15154
+ console.warn("Attempted to update subcategory without a valid categoryId");
15204
15155
  }
15205
15156
  let finalTechnologyId = existingProcedure.technology.id;
15206
15157
  if (validatedData.technologyId) {
15207
- const technology = await this.technologyService.getById(
15208
- validatedData.technologyId
15209
- );
15210
- if (!technology)
15211
- throw new Error(`Technology ${validatedData.technologyId} not found`);
15158
+ const technology = await this.technologyService.getById(validatedData.technologyId);
15159
+ if (!technology) throw new Error(`Technology ${validatedData.technologyId} not found`);
15212
15160
  updatedProcedureData.technology = technology;
15213
15161
  finalTechnologyId = technology.id;
15214
15162
  updatedProcedureData.blockingConditions = technology.blockingConditions;
15215
- updatedProcedureData.contraindications = technology.contraindications || [];
15216
- updatedProcedureData.contraindicationIds = ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [];
15217
15163
  updatedProcedureData.treatmentBenefits = technology.benefits;
15218
- updatedProcedureData.treatmentBenefitIds = ((_c = technology.benefits) == null ? void 0 : _c.map((b) => b.id)) || [];
15219
15164
  updatedProcedureData.preRequirements = technology.requirements.pre;
15220
15165
  updatedProcedureData.postRequirements = technology.requirements.post;
15221
15166
  updatedProcedureData.certificationRequirement = technology.certificationRequirement;
15222
15167
  updatedProcedureData.documentationTemplates = technology.documentationTemplates || [];
15223
15168
  }
15224
15169
  if (validatedData.productId && finalTechnologyId) {
15225
- const product = await this.productService.getById(
15226
- finalTechnologyId,
15227
- validatedData.productId
15228
- );
15170
+ const product = await this.productService.getById(finalTechnologyId, validatedData.productId);
15229
15171
  if (!product)
15230
15172
  throw new Error(
15231
15173
  `Product ${validatedData.productId} not found for technology ${finalTechnologyId}`
@@ -15307,11 +15249,7 @@ var ProcedureService = class extends BaseService {
15307
15249
  limit16(pagination)
15308
15250
  );
15309
15251
  } else {
15310
- proceduresQuery = (0, import_firestore45.query)(
15311
- proceduresCollection,
15312
- (0, import_firestore45.orderBy)("name"),
15313
- limit16(pagination)
15314
- );
15252
+ proceduresQuery = (0, import_firestore45.query)(proceduresCollection, (0, import_firestore45.orderBy)("name"), limit16(pagination));
15315
15253
  }
15316
15254
  } else {
15317
15255
  proceduresQuery = (0, import_firestore45.query)(proceduresCollection, (0, import_firestore45.orderBy)("name"));
@@ -15342,7 +15280,7 @@ var ProcedureService = class extends BaseService {
15342
15280
  *
15343
15281
  * @param filters - Various filters to apply
15344
15282
  * @param filters.nameSearch - Optional search text for procedure name
15345
- * @param filters.treatmentBenefitIds - Optional array of treatment benefits to filter by
15283
+ * @param filters.treatmentBenefits - Optional array of treatment benefits to filter by
15346
15284
  * @param filters.procedureFamily - Optional procedure family to filter by
15347
15285
  * @param filters.procedureCategory - Optional procedure category to filter by
15348
15286
  * @param filters.procedureSubcategory - Optional procedure subcategory to filter by
@@ -15360,9 +15298,7 @@ var ProcedureService = class extends BaseService {
15360
15298
  */
15361
15299
  async getProceduresByFilters(filters) {
15362
15300
  try {
15363
- console.log(
15364
- "[PROCEDURE_SERVICE] Starting procedure filtering with multiple strategies"
15365
- );
15301
+ console.log("[PROCEDURE_SERVICE] Starting procedure filtering with multiple strategies");
15366
15302
  if (filters.location && filters.radiusInKm) {
15367
15303
  console.log("[PROCEDURE_SERVICE] Executing geo query:", {
15368
15304
  location: filters.location,
@@ -15370,10 +15306,7 @@ var ProcedureService = class extends BaseService {
15370
15306
  serviceName: "ProcedureService"
15371
15307
  });
15372
15308
  if (!filters.location.latitude || !filters.location.longitude) {
15373
- console.warn(
15374
- "[PROCEDURE_SERVICE] Invalid location data:",
15375
- filters.location
15376
- );
15309
+ console.warn("[PROCEDURE_SERVICE] Invalid location data:", filters.location);
15377
15310
  filters.location = void 0;
15378
15311
  filters.radiusInKm = void 0;
15379
15312
  }
@@ -15393,19 +15326,13 @@ var ProcedureService = class extends BaseService {
15393
15326
  constraints.push((0, import_firestore45.where)("family", "==", filters.procedureFamily));
15394
15327
  }
15395
15328
  if (filters.procedureCategory) {
15396
- constraints.push(
15397
- (0, import_firestore45.where)("category.id", "==", filters.procedureCategory)
15398
- );
15329
+ constraints.push((0, import_firestore45.where)("category.id", "==", filters.procedureCategory));
15399
15330
  }
15400
15331
  if (filters.procedureSubcategory) {
15401
- constraints.push(
15402
- (0, import_firestore45.where)("subcategory.id", "==", filters.procedureSubcategory)
15403
- );
15332
+ constraints.push((0, import_firestore45.where)("subcategory.id", "==", filters.procedureSubcategory));
15404
15333
  }
15405
15334
  if (filters.procedureTechnology) {
15406
- constraints.push(
15407
- (0, import_firestore45.where)("technology.id", "==", filters.procedureTechnology)
15408
- );
15335
+ constraints.push((0, import_firestore45.where)("technology.id", "==", filters.procedureTechnology));
15409
15336
  }
15410
15337
  if (filters.minPrice !== void 0) {
15411
15338
  constraints.push((0, import_firestore45.where)("price", ">=", filters.minPrice));
@@ -15414,32 +15341,20 @@ var ProcedureService = class extends BaseService {
15414
15341
  constraints.push((0, import_firestore45.where)("price", "<=", filters.maxPrice));
15415
15342
  }
15416
15343
  if (filters.minRating !== void 0) {
15417
- constraints.push(
15418
- (0, import_firestore45.where)("reviewInfo.averageRating", ">=", filters.minRating)
15419
- );
15344
+ constraints.push((0, import_firestore45.where)("reviewInfo.averageRating", ">=", filters.minRating));
15420
15345
  }
15421
15346
  if (filters.maxRating !== void 0) {
15422
- constraints.push(
15423
- (0, import_firestore45.where)("reviewInfo.averageRating", "<=", filters.maxRating)
15424
- );
15347
+ constraints.push((0, import_firestore45.where)("reviewInfo.averageRating", "<=", filters.maxRating));
15425
15348
  }
15426
15349
  if (filters.treatmentBenefits && filters.treatmentBenefits.length > 0) {
15427
- const benefitIdsToMatch = filters.treatmentBenefits;
15428
- constraints.push(
15429
- (0, import_firestore45.where)(
15430
- "treatmentBenefitIds",
15431
- "array-contains-any",
15432
- benefitIdsToMatch
15433
- )
15434
- );
15350
+ const benefitsToMatch = filters.treatmentBenefits;
15351
+ constraints.push((0, import_firestore45.where)("treatmentBenefits", "array-contains-any", benefitsToMatch));
15435
15352
  }
15436
15353
  return constraints;
15437
15354
  };
15438
15355
  if (filters.nameSearch && filters.nameSearch.trim()) {
15439
15356
  try {
15440
- console.log(
15441
- "[PROCEDURE_SERVICE] Strategy 1: Trying nameLower search"
15442
- );
15357
+ console.log("[PROCEDURE_SERVICE] Strategy 1: Trying nameLower search");
15443
15358
  const searchTerm = filters.nameSearch.trim().toLowerCase();
15444
15359
  const constraints = getBaseConstraints();
15445
15360
  constraints.push((0, import_firestore45.where)("nameLower", ">=", searchTerm));
@@ -15455,18 +15370,13 @@ var ProcedureService = class extends BaseService {
15455
15370
  }
15456
15371
  }
15457
15372
  constraints.push((0, import_firestore45.limit)(filters.pagination || 10));
15458
- const q = (0, import_firestore45.query)(
15459
- (0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION),
15460
- ...constraints
15461
- );
15373
+ const q = (0, import_firestore45.query)((0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
15462
15374
  const querySnapshot = await (0, import_firestore45.getDocs)(q);
15463
15375
  const procedures = querySnapshot.docs.map(
15464
15376
  (doc37) => ({ ...doc37.data(), id: doc37.id })
15465
15377
  );
15466
15378
  const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
15467
- console.log(
15468
- `[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures`
15469
- );
15379
+ console.log(`[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures`);
15470
15380
  if (procedures.length < (filters.pagination || 10)) {
15471
15381
  return { procedures, lastDoc: null };
15472
15382
  }
@@ -15477,9 +15387,7 @@ var ProcedureService = class extends BaseService {
15477
15387
  }
15478
15388
  if (filters.nameSearch && filters.nameSearch.trim()) {
15479
15389
  try {
15480
- console.log(
15481
- "[PROCEDURE_SERVICE] Strategy 2: Trying name field search"
15482
- );
15390
+ console.log("[PROCEDURE_SERVICE] Strategy 2: Trying name field search");
15483
15391
  const searchTerm = filters.nameSearch.trim().toLowerCase();
15484
15392
  const constraints = getBaseConstraints();
15485
15393
  constraints.push((0, import_firestore45.where)("name", ">=", searchTerm));
@@ -15495,18 +15403,13 @@ var ProcedureService = class extends BaseService {
15495
15403
  }
15496
15404
  }
15497
15405
  constraints.push((0, import_firestore45.limit)(filters.pagination || 10));
15498
- const q = (0, import_firestore45.query)(
15499
- (0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION),
15500
- ...constraints
15501
- );
15406
+ const q = (0, import_firestore45.query)((0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
15502
15407
  const querySnapshot = await (0, import_firestore45.getDocs)(q);
15503
15408
  const procedures = querySnapshot.docs.map(
15504
15409
  (doc37) => ({ ...doc37.data(), id: doc37.id })
15505
15410
  );
15506
15411
  const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
15507
- console.log(
15508
- `[PROCEDURE_SERVICE] Strategy 2 success: ${procedures.length} procedures`
15509
- );
15412
+ console.log(`[PROCEDURE_SERVICE] Strategy 2 success: ${procedures.length} procedures`);
15510
15413
  if (procedures.length < (filters.pagination || 10)) {
15511
15414
  return { procedures, lastDoc: null };
15512
15415
  }
@@ -15531,19 +15434,14 @@ var ProcedureService = class extends BaseService {
15531
15434
  }
15532
15435
  }
15533
15436
  constraints.push((0, import_firestore45.limit)(filters.pagination || 10));
15534
- const q = (0, import_firestore45.query)(
15535
- (0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION),
15536
- ...constraints
15537
- );
15437
+ const q = (0, import_firestore45.query)((0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
15538
15438
  const querySnapshot = await (0, import_firestore45.getDocs)(q);
15539
15439
  let procedures = querySnapshot.docs.map(
15540
15440
  (doc37) => ({ ...doc37.data(), id: doc37.id })
15541
15441
  );
15542
15442
  procedures = this.applyInMemoryFilters(procedures, filters);
15543
15443
  const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
15544
- console.log(
15545
- `[PROCEDURE_SERVICE] Strategy 3 success: ${procedures.length} procedures`
15546
- );
15444
+ console.log(`[PROCEDURE_SERVICE] Strategy 3 success: ${procedures.length} procedures`);
15547
15445
  if (procedures.length < (filters.pagination || 10)) {
15548
15446
  return { procedures, lastDoc: null };
15549
15447
  }
@@ -15558,19 +15456,14 @@ var ProcedureService = class extends BaseService {
15558
15456
  (0, import_firestore45.orderBy)("createdAt", "desc"),
15559
15457
  (0, import_firestore45.limit)(filters.pagination || 10)
15560
15458
  ];
15561
- const q = (0, import_firestore45.query)(
15562
- (0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION),
15563
- ...constraints
15564
- );
15459
+ const q = (0, import_firestore45.query)((0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
15565
15460
  const querySnapshot = await (0, import_firestore45.getDocs)(q);
15566
15461
  let procedures = querySnapshot.docs.map(
15567
15462
  (doc37) => ({ ...doc37.data(), id: doc37.id })
15568
15463
  );
15569
15464
  procedures = this.applyInMemoryFilters(procedures, filters);
15570
15465
  const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
15571
- console.log(
15572
- `[PROCEDURE_SERVICE] Strategy 4 success: ${procedures.length} procedures`
15573
- );
15466
+ console.log(`[PROCEDURE_SERVICE] Strategy 4 success: ${procedures.length} procedures`);
15574
15467
  if (procedures.length < (filters.pagination || 10)) {
15575
15468
  return { procedures, lastDoc: null };
15576
15469
  }
@@ -15578,9 +15471,7 @@ var ProcedureService = class extends BaseService {
15578
15471
  } catch (error) {
15579
15472
  console.log("[PROCEDURE_SERVICE] Strategy 4 failed:", error);
15580
15473
  }
15581
- console.log(
15582
- "[PROCEDURE_SERVICE] All strategies failed, returning empty result"
15583
- );
15474
+ console.log("[PROCEDURE_SERVICE] All strategies failed, returning empty result");
15584
15475
  return { procedures: [], lastDoc: null };
15585
15476
  } catch (error) {
15586
15477
  console.error("[PROCEDURE_SERVICE] Error filtering procedures:", error);
@@ -15600,17 +15491,13 @@ var ProcedureService = class extends BaseService {
15600
15491
  const nameLower = procedure.nameLower || "";
15601
15492
  return name.includes(searchTerm) || nameLower.includes(searchTerm);
15602
15493
  });
15603
- console.log(
15604
- `[PROCEDURE_SERVICE] Applied name filter, results: ${filteredProcedures.length}`
15605
- );
15494
+ console.log(`[PROCEDURE_SERVICE] Applied name filter, results: ${filteredProcedures.length}`);
15606
15495
  }
15607
15496
  if (filters.minPrice !== void 0 || filters.maxPrice !== void 0) {
15608
15497
  filteredProcedures = filteredProcedures.filter((procedure) => {
15609
15498
  const price = procedure.price || 0;
15610
- if (filters.minPrice !== void 0 && price < filters.minPrice)
15611
- return false;
15612
- if (filters.maxPrice !== void 0 && price > filters.maxPrice)
15613
- return false;
15499
+ if (filters.minPrice !== void 0 && price < filters.minPrice) return false;
15500
+ if (filters.maxPrice !== void 0 && price > filters.maxPrice) return false;
15614
15501
  return true;
15615
15502
  });
15616
15503
  console.log(
@@ -15621,10 +15508,8 @@ var ProcedureService = class extends BaseService {
15621
15508
  filteredProcedures = filteredProcedures.filter((procedure) => {
15622
15509
  var _a;
15623
15510
  const rating = ((_a = procedure.reviewInfo) == null ? void 0 : _a.averageRating) || 0;
15624
- if (filters.minRating !== void 0 && rating < filters.minRating)
15625
- return false;
15626
- if (filters.maxRating !== void 0 && rating > filters.maxRating)
15627
- return false;
15511
+ if (filters.minRating !== void 0 && rating < filters.minRating) return false;
15512
+ if (filters.maxRating !== void 0 && rating > filters.maxRating) return false;
15628
15513
  return true;
15629
15514
  });
15630
15515
  console.log(
@@ -15632,12 +15517,10 @@ var ProcedureService = class extends BaseService {
15632
15517
  );
15633
15518
  }
15634
15519
  if (filters.treatmentBenefits && filters.treatmentBenefits.length > 0) {
15635
- const benefitIdsToMatch = filters.treatmentBenefits;
15520
+ const benefitsToMatch = filters.treatmentBenefits;
15636
15521
  filteredProcedures = filteredProcedures.filter((procedure) => {
15637
- const procedureBenefitIds = procedure.treatmentBenefitIds || [];
15638
- return benefitIdsToMatch.some(
15639
- (benefitId) => procedureBenefitIds.includes(benefitId)
15640
- );
15522
+ const procedureBenefits = procedure.treatmentBenefits || [];
15523
+ return benefitsToMatch.some((benefit) => procedureBenefits.includes(benefit));
15641
15524
  });
15642
15525
  console.log(
15643
15526
  `[PROCEDURE_SERVICE] Applied benefits filter, results: ${filteredProcedures.length}`
@@ -15700,12 +15583,8 @@ var ProcedureService = class extends BaseService {
15700
15583
  procedure.distance = distance;
15701
15584
  return distance <= radiusInKm;
15702
15585
  });
15703
- console.log(
15704
- `[PROCEDURE_SERVICE] Applied geo filter, results: ${filteredProcedures.length}`
15705
- );
15706
- filteredProcedures.sort(
15707
- (a, b) => (a.distance || 0) - (b.distance || 0)
15708
- );
15586
+ console.log(`[PROCEDURE_SERVICE] Applied geo filter, results: ${filteredProcedures.length}`);
15587
+ filteredProcedures.sort((a, b) => (a.distance || 0) - (b.distance || 0));
15709
15588
  }
15710
15589
  return filteredProcedures;
15711
15590
  }
@@ -15717,30 +15596,19 @@ var ProcedureService = class extends BaseService {
15717
15596
  if (!location || !radiusInKm) {
15718
15597
  return Promise.resolve({ procedures: [], lastDoc: null });
15719
15598
  }
15720
- const bounds = (0, import_geofire_common8.geohashQueryBounds)(
15721
- [location.latitude, location.longitude],
15722
- radiusInKm * 1e3
15723
- );
15599
+ const bounds = (0, import_geofire_common8.geohashQueryBounds)([location.latitude, location.longitude], radiusInKm * 1e3);
15724
15600
  const fetches = bounds.map((b) => {
15725
15601
  const constraints = [
15726
15602
  (0, import_firestore45.where)("clinicInfo.location.geohash", ">=", b[0]),
15727
15603
  (0, import_firestore45.where)("clinicInfo.location.geohash", "<=", b[1]),
15728
- (0, import_firestore45.where)(
15729
- "isActive",
15730
- "==",
15731
- filters.isActive !== void 0 ? filters.isActive : true
15732
- )
15604
+ (0, import_firestore45.where)("isActive", "==", filters.isActive !== void 0 ? filters.isActive : true)
15733
15605
  ];
15734
- return (0, import_firestore45.getDocs)(
15735
- (0, import_firestore45.query)((0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION), ...constraints)
15736
- );
15606
+ return (0, import_firestore45.getDocs)((0, import_firestore45.query)((0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION), ...constraints));
15737
15607
  });
15738
15608
  return Promise.all(fetches).then((snaps) => {
15739
15609
  const collected = [];
15740
15610
  snaps.forEach((snap) => {
15741
- snap.docs.forEach(
15742
- (d) => collected.push({ ...d.data(), id: d.id })
15743
- );
15611
+ snap.docs.forEach((d) => collected.push({ ...d.data(), id: d.id }));
15744
15612
  });
15745
15613
  const uniqueMap = /* @__PURE__ */ new Map();
15746
15614
  for (const p of collected) {
@@ -15751,9 +15619,7 @@ var ProcedureService = class extends BaseService {
15751
15619
  const pageSize = filters.pagination || 10;
15752
15620
  let startIndex = 0;
15753
15621
  if (filters.lastDoc && typeof filters.lastDoc === "object" && filters.lastDoc.id) {
15754
- const idx = procedures.findIndex(
15755
- (p) => p.id === filters.lastDoc.id
15756
- );
15622
+ const idx = procedures.findIndex((p) => p.id === filters.lastDoc.id);
15757
15623
  if (idx >= 0) startIndex = idx + 1;
15758
15624
  }
15759
15625
  const page = procedures.slice(startIndex, startIndex + pageSize);
@@ -15778,7 +15644,7 @@ var ProcedureService = class extends BaseService {
15778
15644
  * @returns The created procedure
15779
15645
  */
15780
15646
  async createConsultationProcedure(data) {
15781
- var _a, _b, _c;
15647
+ var _a;
15782
15648
  const procedureId = this.generateId();
15783
15649
  const [category, subcategory, technology] = await Promise.all([
15784
15650
  this.categoryService.getById(data.categoryId),
@@ -15794,11 +15660,7 @@ var ProcedureService = class extends BaseService {
15794
15660
  throw new Error(`Clinic with ID ${data.clinicBranchId} not found`);
15795
15661
  }
15796
15662
  const clinic = clinicSnapshot.data();
15797
- const practitionerRef = (0, import_firestore45.doc)(
15798
- this.db,
15799
- PRACTITIONERS_COLLECTION,
15800
- data.practitionerId
15801
- );
15663
+ const practitionerRef = (0, import_firestore45.doc)(this.db, PRACTITIONERS_COLLECTION, data.practitionerId);
15802
15664
  const practitionerSnapshot = await (0, import_firestore45.getDoc)(practitionerRef);
15803
15665
  if (!practitionerSnapshot.exists()) {
15804
15666
  throw new Error(`Practitioner with ID ${data.practitionerId} not found`);
@@ -15806,11 +15668,7 @@ var ProcedureService = class extends BaseService {
15806
15668
  const practitioner = practitionerSnapshot.data();
15807
15669
  let processedPhotos = [];
15808
15670
  if (data.photos && data.photos.length > 0) {
15809
- processedPhotos = await this.processMediaArray(
15810
- data.photos,
15811
- procedureId,
15812
- "procedure-photos"
15813
- );
15671
+ processedPhotos = await this.processMediaArray(data.photos, procedureId, "procedure-photos");
15814
15672
  }
15815
15673
  const clinicInfo = {
15816
15674
  id: clinicSnapshot.id,
@@ -15852,9 +15710,7 @@ var ProcedureService = class extends BaseService {
15852
15710
  // Use placeholder product
15853
15711
  blockingConditions: technology.blockingConditions,
15854
15712
  contraindications: technology.contraindications || [],
15855
- contraindicationIds: ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [],
15856
15713
  treatmentBenefits: technology.benefits,
15857
- treatmentBenefitIds: ((_c = technology.benefits) == null ? void 0 : _c.map((b) => b.id)) || [],
15858
15714
  preRequirements: technology.requirements.pre,
15859
15715
  postRequirements: technology.requirements.post,
15860
15716
  certificationRequirement: technology.certificationRequirement,
@@ -16675,16 +16531,8 @@ var TechnologyService = class extends BaseService {
16675
16531
  */
16676
16532
  async addContraindication(technologyId, contraindication) {
16677
16533
  const docRef = (0, import_firestore51.doc)(this.getTechnologiesRef(), technologyId);
16678
- const technology = await this.getById(technologyId);
16679
- if (!technology) {
16680
- throw new Error(`Technology with id ${technologyId} not found`);
16681
- }
16682
- const existingContraindications = technology.contraindications || [];
16683
- if (existingContraindications.some((c) => c.id === contraindication.id)) {
16684
- return technology;
16685
- }
16686
16534
  await (0, import_firestore51.updateDoc)(docRef, {
16687
- contraindications: [...existingContraindications, contraindication],
16535
+ contraindications: (0, import_firestore51.arrayUnion)(contraindication),
16688
16536
  updatedAt: /* @__PURE__ */ new Date()
16689
16537
  });
16690
16538
  return this.getById(technologyId);
@@ -16697,44 +16545,8 @@ var TechnologyService = class extends BaseService {
16697
16545
  */
16698
16546
  async removeContraindication(technologyId, contraindication) {
16699
16547
  const docRef = (0, import_firestore51.doc)(this.getTechnologiesRef(), technologyId);
16700
- const technology = await this.getById(technologyId);
16701
- if (!technology) {
16702
- throw new Error(`Technology with id ${technologyId} not found`);
16703
- }
16704
- const updatedContraindications = (technology.contraindications || []).filter((c) => c.id !== contraindication.id);
16705
- await (0, import_firestore51.updateDoc)(docRef, {
16706
- contraindications: updatedContraindications,
16707
- updatedAt: /* @__PURE__ */ new Date()
16708
- });
16709
- return this.getById(technologyId);
16710
- }
16711
- /**
16712
- * Updates an existing contraindication in a technology's list.
16713
- * If the contraindication does not exist, it will not be added.
16714
- * @param technologyId - ID of the technology
16715
- * @param contraindication - The updated contraindication object
16716
- * @returns The updated technology
16717
- */
16718
- async updateContraindication(technologyId, contraindication) {
16719
- const docRef = (0, import_firestore51.doc)(this.getTechnologiesRef(), technologyId);
16720
- const technology = await this.getById(technologyId);
16721
- if (!technology) {
16722
- throw new Error(`Technology with id ${technologyId} not found`);
16723
- }
16724
- const contraindications = technology.contraindications || [];
16725
- const index = contraindications.findIndex(
16726
- (c) => c.id === contraindication.id
16727
- );
16728
- if (index === -1) {
16729
- console.warn(
16730
- `Contraindication with id ${contraindication.id} not found for technology ${technologyId}. No update performed.`
16731
- );
16732
- return technology;
16733
- }
16734
- const updatedContraindications = [...contraindications];
16735
- updatedContraindications[index] = contraindication;
16736
16548
  await (0, import_firestore51.updateDoc)(docRef, {
16737
- contraindications: updatedContraindications,
16549
+ contraindications: (0, import_firestore51.arrayRemove)(contraindication),
16738
16550
  updatedAt: /* @__PURE__ */ new Date()
16739
16551
  });
16740
16552
  return this.getById(technologyId);
@@ -16747,16 +16559,8 @@ var TechnologyService = class extends BaseService {
16747
16559
  */
16748
16560
  async addBenefit(technologyId, benefit) {
16749
16561
  const docRef = (0, import_firestore51.doc)(this.getTechnologiesRef(), technologyId);
16750
- const technology = await this.getById(technologyId);
16751
- if (!technology) {
16752
- throw new Error(`Technology with id ${technologyId} not found`);
16753
- }
16754
- const existingBenefits = technology.benefits || [];
16755
- if (existingBenefits.some((b) => b.id === benefit.id)) {
16756
- return technology;
16757
- }
16758
16562
  await (0, import_firestore51.updateDoc)(docRef, {
16759
- benefits: [...existingBenefits, benefit],
16563
+ benefits: (0, import_firestore51.arrayUnion)(benefit),
16760
16564
  updatedAt: /* @__PURE__ */ new Date()
16761
16565
  });
16762
16566
  return this.getById(technologyId);
@@ -16769,44 +16573,8 @@ var TechnologyService = class extends BaseService {
16769
16573
  */
16770
16574
  async removeBenefit(technologyId, benefit) {
16771
16575
  const docRef = (0, import_firestore51.doc)(this.getTechnologiesRef(), technologyId);
16772
- const technology = await this.getById(technologyId);
16773
- if (!technology) {
16774
- throw new Error(`Technology with id ${technologyId} not found`);
16775
- }
16776
- const updatedBenefits = (technology.benefits || []).filter(
16777
- (b) => b.id !== benefit.id
16778
- );
16779
16576
  await (0, import_firestore51.updateDoc)(docRef, {
16780
- benefits: updatedBenefits,
16781
- updatedAt: /* @__PURE__ */ new Date()
16782
- });
16783
- return this.getById(technologyId);
16784
- }
16785
- /**
16786
- * Updates an existing benefit in a technology's list.
16787
- * If the benefit does not exist, it will not be added.
16788
- * @param technologyId - ID of the technology
16789
- * @param benefit - The updated benefit object
16790
- * @returns The updated technology
16791
- */
16792
- async updateBenefit(technologyId, benefit) {
16793
- const docRef = (0, import_firestore51.doc)(this.getTechnologiesRef(), technologyId);
16794
- const technology = await this.getById(technologyId);
16795
- if (!technology) {
16796
- throw new Error(`Technology with id ${technologyId} not found`);
16797
- }
16798
- const benefits = technology.benefits || [];
16799
- const index = benefits.findIndex((b) => b.id === benefit.id);
16800
- if (index === -1) {
16801
- console.warn(
16802
- `Benefit with id ${benefit.id} not found for technology ${technologyId}. No update performed.`
16803
- );
16804
- return technology;
16805
- }
16806
- const updatedBenefits = [...benefits];
16807
- updatedBenefits[index] = benefit;
16808
- await (0, import_firestore51.updateDoc)(docRef, {
16809
- benefits: updatedBenefits,
16577
+ benefits: (0, import_firestore51.arrayRemove)(benefit),
16810
16578
  updatedAt: /* @__PURE__ */ new Date()
16811
16579
  });
16812
16580
  return this.getById(technologyId);
@@ -17060,23 +16828,6 @@ var ProductService = class extends BaseService {
17060
16828
  }
17061
16829
  };
17062
16830
 
17063
- // src/backoffice/types/static/contraindication.types.ts
17064
- var Contraindication = /* @__PURE__ */ ((Contraindication2) => {
17065
- Contraindication2["SENSITIVE_SKIN"] = "sensitive_skin";
17066
- Contraindication2["RECENT_TANNING"] = "recent_tanning";
17067
- Contraindication2["RECENT_BOTOX"] = "recent_botox";
17068
- Contraindication2["RECENT_FILLERS"] = "recent_fillers";
17069
- Contraindication2["SKIN_ALLERGIES"] = "skin_allergies";
17070
- Contraindication2["MEDICATIONS"] = "medications";
17071
- Contraindication2["RECENT_CHEMICAL_PEEL"] = "recent_chemical_peel";
17072
- Contraindication2["RECENT_LASER"] = "recent_laser";
17073
- Contraindication2["SKIN_INFLAMMATION"] = "skin_inflammation";
17074
- Contraindication2["OPEN_WOUNDS"] = "open_wounds";
17075
- Contraindication2["HERPES_SIMPLEX"] = "herpes_simplex";
17076
- Contraindication2["COLD_SORES"] = "cold_sores";
17077
- return Contraindication2;
17078
- })(Contraindication || {});
17079
-
17080
16831
  // src/backoffice/types/static/treatment-benefit.types.ts
17081
16832
  var TreatmentBenefit = /* @__PURE__ */ ((TreatmentBenefit2) => {
17082
16833
  TreatmentBenefit2["WRINKLE_REDUCTION"] = "wrinkle_reduction";