@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.
- package/dist/admin/index.d.mts +324 -330
- package/dist/admin/index.d.ts +324 -330
- package/dist/backoffice/index.d.mts +67 -283
- package/dist/backoffice/index.d.ts +67 -283
- package/dist/backoffice/index.js +6 -114
- package/dist/backoffice/index.mjs +6 -112
- package/dist/index.d.mts +3037 -3100
- package/dist/index.d.ts +3037 -3100
- package/dist/index.js +129 -379
- package/dist/index.mjs +130 -379
- package/package.json +1 -1
- package/src/backoffice/expo-safe/index.ts +0 -2
- package/src/backoffice/services/__tests__/brand.service.test.ts +196 -0
- package/src/backoffice/services/__tests__/category.service.test.ts +201 -0
- package/src/backoffice/services/__tests__/product.service.test.ts +358 -0
- package/src/backoffice/services/__tests__/requirement.service.test.ts +226 -0
- package/src/backoffice/services/__tests__/subcategory.service.test.ts +181 -0
- package/src/backoffice/services/__tests__/technology.service.test.ts +1097 -0
- package/src/backoffice/services/technology.service.ts +10 -122
- package/src/backoffice/types/index.ts +0 -1
- package/src/backoffice/types/product.types.ts +1 -3
- package/src/backoffice/types/technology.types.ts +4 -4
- package/src/backoffice/validations/schemas.ts +9 -35
- package/src/services/appointment/appointment.service.ts +5 -0
- package/src/services/appointment/utils/appointment.utils.ts +113 -124
- package/src/services/procedure/procedure.service.ts +234 -434
- package/src/types/appointment/index.ts +37 -43
- package/src/types/clinic/index.ts +6 -1
- package/src/types/patient/medical-info.types.ts +3 -3
- package/src/types/procedure/index.ts +17 -20
- package/src/validations/appointment.schema.ts +118 -170
- package/src/validations/clinic.schema.ts +6 -1
- package/src/validations/patient/medical-info.schema.ts +2 -7
- package/src/backoffice/services/README.md +0 -40
- package/src/backoffice/services/constants.service.ts +0 -268
- 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__ */ ((
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return
|
|
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
|
-
|
|
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"),
|
|
@@ -620,10 +622,7 @@ var updateAppointmentSchema = import_zod3.z.object({
|
|
|
620
622
|
practitionerId: import_zod3.z.string().min(MIN_STRING_LENGTH).optional(),
|
|
621
623
|
clinic_tz: import_zod3.z.string().min(MIN_STRING_LENGTH).optional(),
|
|
622
624
|
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(),
|
|
625
|
+
media: import_zod3.z.union([import_zod3.z.array(appointmentMediaItemSchema).max(MAX_ARRAY_LENGTH), import_zod3.z.any()]).optional(),
|
|
627
626
|
reviewInfo: import_zod3.z.union([patientReviewInfoSchema.nullable(), import_zod3.z.any()]).optional(),
|
|
628
627
|
finalizedDetails: import_zod3.z.union([finalizedDetailsSchema.nullable(), import_zod3.z.any()]).optional(),
|
|
629
628
|
isArchived: import_zod3.z.boolean().optional(),
|
|
@@ -664,10 +663,7 @@ var searchAppointmentsSchema = import_zod3.z.object({
|
|
|
664
663
|
(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
664
|
"End date must be a valid timestamp or Date object"
|
|
666
665
|
).optional(),
|
|
667
|
-
status: import_zod3.z.union([
|
|
668
|
-
appointmentStatusSchema,
|
|
669
|
-
import_zod3.z.array(appointmentStatusSchema).nonempty()
|
|
670
|
-
]).optional(),
|
|
666
|
+
status: import_zod3.z.union([appointmentStatusSchema, import_zod3.z.array(appointmentStatusSchema).nonempty()]).optional(),
|
|
671
667
|
limit: import_zod3.z.number().positive().int().optional().default(20),
|
|
672
668
|
startAfter: import_zod3.z.any().optional()
|
|
673
669
|
}).refine(
|
|
@@ -936,48 +932,44 @@ async function updateAppointmentUtil(db, appointmentId, data) {
|
|
|
936
932
|
const validPreReqIds = currentAppointment.preProcedureRequirements.map(
|
|
937
933
|
(req) => req.id
|
|
938
934
|
);
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
935
|
+
const invalidPreReqIds = data.completedPreRequirements.filter(
|
|
936
|
+
(id) => !validPreReqIds.includes(id)
|
|
937
|
+
);
|
|
938
|
+
if (invalidPreReqIds.length > 0) {
|
|
939
|
+
throw new Error(
|
|
940
|
+
`Invalid pre-requirement IDs: ${invalidPreReqIds.join(", ")}`
|
|
942
941
|
);
|
|
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
942
|
}
|
|
943
|
+
completedPreRequirements = [
|
|
944
|
+
.../* @__PURE__ */ new Set([
|
|
945
|
+
...completedPreRequirements,
|
|
946
|
+
...data.completedPreRequirements
|
|
947
|
+
])
|
|
948
|
+
];
|
|
955
949
|
}
|
|
956
950
|
if (data.completedPostRequirements) {
|
|
957
951
|
const validPostReqIds = currentAppointment.postProcedureRequirements.map(
|
|
958
952
|
(req) => req.id
|
|
959
953
|
);
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
954
|
+
const invalidPostReqIds = data.completedPostRequirements.filter(
|
|
955
|
+
(id) => !validPostReqIds.includes(id)
|
|
956
|
+
);
|
|
957
|
+
if (invalidPostReqIds.length > 0) {
|
|
958
|
+
throw new Error(
|
|
959
|
+
`Invalid post-requirement IDs: ${invalidPostReqIds.join(", ")}`
|
|
963
960
|
);
|
|
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
961
|
}
|
|
962
|
+
completedPostRequirements = [
|
|
963
|
+
.../* @__PURE__ */ new Set([
|
|
964
|
+
...completedPostRequirements,
|
|
965
|
+
...data.completedPostRequirements
|
|
966
|
+
])
|
|
967
|
+
];
|
|
976
968
|
}
|
|
977
969
|
const updateData = {
|
|
978
970
|
...data,
|
|
979
|
-
completedPreRequirements
|
|
980
|
-
completedPostRequirements
|
|
971
|
+
completedPreRequirements,
|
|
972
|
+
completedPostRequirements,
|
|
981
973
|
updatedAt: (0, import_firestore.serverTimestamp)()
|
|
982
974
|
};
|
|
983
975
|
Object.keys(updateData).forEach((key) => {
|
|
@@ -1027,7 +1019,7 @@ async function updateCalendarEventStatus(db, calendarEventId, appointmentStatus)
|
|
|
1027
1019
|
case "canceled_clinic" /* CANCELED_CLINIC */:
|
|
1028
1020
|
calendarStatus = "canceled";
|
|
1029
1021
|
break;
|
|
1030
|
-
case
|
|
1022
|
+
case AppointmentStatus.RESCHEDULED:
|
|
1031
1023
|
calendarStatus = "rescheduled";
|
|
1032
1024
|
break;
|
|
1033
1025
|
case "completed" /* COMPLETED */:
|
|
@@ -2843,6 +2835,23 @@ var BlockingCondition = /* @__PURE__ */ ((BlockingCondition2) => {
|
|
|
2843
2835
|
return BlockingCondition2;
|
|
2844
2836
|
})(BlockingCondition || {});
|
|
2845
2837
|
|
|
2838
|
+
// src/backoffice/types/static/contraindication.types.ts
|
|
2839
|
+
var Contraindication = /* @__PURE__ */ ((Contraindication2) => {
|
|
2840
|
+
Contraindication2["SENSITIVE_SKIN"] = "sensitive_skin";
|
|
2841
|
+
Contraindication2["RECENT_TANNING"] = "recent_tanning";
|
|
2842
|
+
Contraindication2["RECENT_BOTOX"] = "recent_botox";
|
|
2843
|
+
Contraindication2["RECENT_FILLERS"] = "recent_fillers";
|
|
2844
|
+
Contraindication2["SKIN_ALLERGIES"] = "skin_allergies";
|
|
2845
|
+
Contraindication2["MEDICATIONS"] = "medications";
|
|
2846
|
+
Contraindication2["RECENT_CHEMICAL_PEEL"] = "recent_chemical_peel";
|
|
2847
|
+
Contraindication2["RECENT_LASER"] = "recent_laser";
|
|
2848
|
+
Contraindication2["SKIN_INFLAMMATION"] = "skin_inflammation";
|
|
2849
|
+
Contraindication2["OPEN_WOUNDS"] = "open_wounds";
|
|
2850
|
+
Contraindication2["HERPES_SIMPLEX"] = "herpes_simplex";
|
|
2851
|
+
Contraindication2["COLD_SORES"] = "cold_sores";
|
|
2852
|
+
return Contraindication2;
|
|
2853
|
+
})(Contraindication || {});
|
|
2854
|
+
|
|
2846
2855
|
// src/validations/common.schema.ts
|
|
2847
2856
|
var import_zod5 = require("zod");
|
|
2848
2857
|
var import_firestore6 = require("firebase/firestore");
|
|
@@ -2897,13 +2906,8 @@ var blockingConditionSchema = import_zod6.z.object({
|
|
|
2897
2906
|
notes: import_zod6.z.string().optional().nullable(),
|
|
2898
2907
|
isActive: import_zod6.z.boolean()
|
|
2899
2908
|
});
|
|
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
2909
|
var contraindicationSchema = import_zod6.z.object({
|
|
2906
|
-
condition:
|
|
2910
|
+
condition: import_zod6.z.nativeEnum(Contraindication),
|
|
2907
2911
|
lastOccurrence: timestampSchema,
|
|
2908
2912
|
frequency: import_zod6.z.enum(["rare", "occasional", "frequent"]),
|
|
2909
2913
|
notes: import_zod6.z.string().optional().nullable(),
|
|
@@ -10623,7 +10627,7 @@ async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId,
|
|
|
10623
10627
|
}
|
|
10624
10628
|
|
|
10625
10629
|
// src/services/calendar/utils/appointment.utils.ts
|
|
10626
|
-
async function
|
|
10630
|
+
async function createAppointmentUtil2(db, clinicId, practitionerId, patientId, eventData, generateId2) {
|
|
10627
10631
|
const eventId = generateId2();
|
|
10628
10632
|
const autoConfirm = await checkAutoConfirmAppointmentsUtil(db, clinicId);
|
|
10629
10633
|
const initialStatus = autoConfirm ? "confirmed" /* CONFIRMED */ : "pending" /* PENDING */;
|
|
@@ -11941,7 +11945,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
11941
11945
|
syncStatus: "internal" /* INTERNAL */,
|
|
11942
11946
|
eventType: "appointment" /* APPOINTMENT */
|
|
11943
11947
|
};
|
|
11944
|
-
const appointment = await
|
|
11948
|
+
const appointment = await createAppointmentUtil2(
|
|
11945
11949
|
this.db,
|
|
11946
11950
|
params.clinicId,
|
|
11947
11951
|
params.doctorId,
|
|
@@ -14746,9 +14750,7 @@ var ProcedureService = class extends BaseService {
|
|
|
14746
14750
|
return media;
|
|
14747
14751
|
}
|
|
14748
14752
|
if (media instanceof File || media instanceof Blob) {
|
|
14749
|
-
console.log(
|
|
14750
|
-
`[ProcedureService] Uploading ${collectionName} media for ${ownerId}`
|
|
14751
|
-
);
|
|
14753
|
+
console.log(`[ProcedureService] Uploading ${collectionName} media for ${ownerId}`);
|
|
14752
14754
|
const metadata = await this.mediaService.uploadMedia(
|
|
14753
14755
|
media,
|
|
14754
14756
|
ownerId,
|
|
@@ -14770,11 +14772,7 @@ var ProcedureService = class extends BaseService {
|
|
|
14770
14772
|
if (!mediaArray || mediaArray.length === 0) return [];
|
|
14771
14773
|
const result = [];
|
|
14772
14774
|
for (const media of mediaArray) {
|
|
14773
|
-
const processedUrl = await this.processMedia(
|
|
14774
|
-
media,
|
|
14775
|
-
ownerId,
|
|
14776
|
-
collectionName
|
|
14777
|
-
);
|
|
14775
|
+
const processedUrl = await this.processMedia(media, ownerId, collectionName);
|
|
14778
14776
|
if (processedUrl) {
|
|
14779
14777
|
result.push(processedUrl);
|
|
14780
14778
|
}
|
|
@@ -14787,46 +14785,28 @@ var ProcedureService = class extends BaseService {
|
|
|
14787
14785
|
* @returns The created procedure
|
|
14788
14786
|
*/
|
|
14789
14787
|
async createProcedure(data) {
|
|
14790
|
-
var _a
|
|
14788
|
+
var _a;
|
|
14791
14789
|
const validatedData = createProcedureSchema.parse(data);
|
|
14792
14790
|
const procedureId = this.generateId();
|
|
14793
14791
|
const [category, subcategory, technology, product] = await Promise.all([
|
|
14794
14792
|
this.categoryService.getById(validatedData.categoryId),
|
|
14795
|
-
this.subcategoryService.getById(
|
|
14796
|
-
validatedData.categoryId,
|
|
14797
|
-
validatedData.subcategoryId
|
|
14798
|
-
),
|
|
14793
|
+
this.subcategoryService.getById(validatedData.categoryId, validatedData.subcategoryId),
|
|
14799
14794
|
this.technologyService.getById(validatedData.technologyId),
|
|
14800
|
-
this.productService.getById(
|
|
14801
|
-
validatedData.technologyId,
|
|
14802
|
-
validatedData.productId
|
|
14803
|
-
)
|
|
14795
|
+
this.productService.getById(validatedData.technologyId, validatedData.productId)
|
|
14804
14796
|
]);
|
|
14805
14797
|
if (!category || !subcategory || !technology || !product) {
|
|
14806
14798
|
throw new Error("One or more required base entities not found");
|
|
14807
14799
|
}
|
|
14808
|
-
const clinicRef = (0, import_firestore45.doc)(
|
|
14809
|
-
this.db,
|
|
14810
|
-
CLINICS_COLLECTION,
|
|
14811
|
-
validatedData.clinicBranchId
|
|
14812
|
-
);
|
|
14800
|
+
const clinicRef = (0, import_firestore45.doc)(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId);
|
|
14813
14801
|
const clinicSnapshot = await (0, import_firestore45.getDoc)(clinicRef);
|
|
14814
14802
|
if (!clinicSnapshot.exists()) {
|
|
14815
|
-
throw new Error(
|
|
14816
|
-
`Clinic with ID ${validatedData.clinicBranchId} not found`
|
|
14817
|
-
);
|
|
14803
|
+
throw new Error(`Clinic with ID ${validatedData.clinicBranchId} not found`);
|
|
14818
14804
|
}
|
|
14819
14805
|
const clinic = clinicSnapshot.data();
|
|
14820
|
-
const practitionerRef = (0, import_firestore45.doc)(
|
|
14821
|
-
this.db,
|
|
14822
|
-
PRACTITIONERS_COLLECTION,
|
|
14823
|
-
validatedData.practitionerId
|
|
14824
|
-
);
|
|
14806
|
+
const practitionerRef = (0, import_firestore45.doc)(this.db, PRACTITIONERS_COLLECTION, validatedData.practitionerId);
|
|
14825
14807
|
const practitionerSnapshot = await (0, import_firestore45.getDoc)(practitionerRef);
|
|
14826
14808
|
if (!practitionerSnapshot.exists()) {
|
|
14827
|
-
throw new Error(
|
|
14828
|
-
`Practitioner with ID ${validatedData.practitionerId} not found`
|
|
14829
|
-
);
|
|
14809
|
+
throw new Error(`Practitioner with ID ${validatedData.practitionerId} not found`);
|
|
14830
14810
|
}
|
|
14831
14811
|
const practitioner = practitionerSnapshot.data();
|
|
14832
14812
|
let processedPhotos = [];
|
|
@@ -14867,9 +14847,7 @@ var ProcedureService = class extends BaseService {
|
|
|
14867
14847
|
product,
|
|
14868
14848
|
blockingConditions: technology.blockingConditions,
|
|
14869
14849
|
contraindications: technology.contraindications || [],
|
|
14870
|
-
contraindicationIds: ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [],
|
|
14871
14850
|
treatmentBenefits: technology.benefits,
|
|
14872
|
-
treatmentBenefitIds: ((_c = technology.benefits) == null ? void 0 : _c.map((b) => b.id)) || [],
|
|
14873
14851
|
preRequirements: technology.requirements.pre,
|
|
14874
14852
|
postRequirements: technology.requirements.post,
|
|
14875
14853
|
certificationRequirement: technology.certificationRequirement,
|
|
@@ -14910,7 +14888,7 @@ var ProcedureService = class extends BaseService {
|
|
|
14910
14888
|
* @returns A promise that resolves to an array of the newly created procedures.
|
|
14911
14889
|
*/
|
|
14912
14890
|
async bulkCreateProcedures(baseData, practitionerIds) {
|
|
14913
|
-
var _a
|
|
14891
|
+
var _a;
|
|
14914
14892
|
if (!practitionerIds || practitionerIds.length === 0) {
|
|
14915
14893
|
throw new Error("Practitioner IDs array cannot be empty.");
|
|
14916
14894
|
}
|
|
@@ -14918,24 +14896,16 @@ var ProcedureService = class extends BaseService {
|
|
|
14918
14896
|
const validatedData = createProcedureSchema.parse(validationData);
|
|
14919
14897
|
const [category, subcategory, technology, product, clinicSnapshot] = await Promise.all([
|
|
14920
14898
|
this.categoryService.getById(validatedData.categoryId),
|
|
14921
|
-
this.subcategoryService.getById(
|
|
14922
|
-
validatedData.categoryId,
|
|
14923
|
-
validatedData.subcategoryId
|
|
14924
|
-
),
|
|
14899
|
+
this.subcategoryService.getById(validatedData.categoryId, validatedData.subcategoryId),
|
|
14925
14900
|
this.technologyService.getById(validatedData.technologyId),
|
|
14926
|
-
this.productService.getById(
|
|
14927
|
-
validatedData.technologyId,
|
|
14928
|
-
validatedData.productId
|
|
14929
|
-
),
|
|
14901
|
+
this.productService.getById(validatedData.technologyId, validatedData.productId),
|
|
14930
14902
|
(0, import_firestore45.getDoc)((0, import_firestore45.doc)(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId))
|
|
14931
14903
|
]);
|
|
14932
14904
|
if (!category || !subcategory || !technology || !product) {
|
|
14933
14905
|
throw new Error("One or more required base entities not found");
|
|
14934
14906
|
}
|
|
14935
14907
|
if (!clinicSnapshot.exists()) {
|
|
14936
|
-
throw new Error(
|
|
14937
|
-
`Clinic with ID ${validatedData.clinicBranchId} not found`
|
|
14938
|
-
);
|
|
14908
|
+
throw new Error(`Clinic with ID ${validatedData.clinicBranchId} not found`);
|
|
14939
14909
|
}
|
|
14940
14910
|
const clinic = clinicSnapshot.data();
|
|
14941
14911
|
let processedPhotos = [];
|
|
@@ -14961,12 +14931,8 @@ var ProcedureService = class extends BaseService {
|
|
|
14961
14931
|
}
|
|
14962
14932
|
if (practitionersMap.size !== practitionerIds.length) {
|
|
14963
14933
|
const foundIds = Array.from(practitionersMap.keys());
|
|
14964
|
-
const notFoundIds = practitionerIds.filter(
|
|
14965
|
-
|
|
14966
|
-
);
|
|
14967
|
-
throw new Error(
|
|
14968
|
-
`The following practitioners were not found: ${notFoundIds.join(", ")}`
|
|
14969
|
-
);
|
|
14934
|
+
const notFoundIds = practitionerIds.filter((id) => !foundIds.includes(id));
|
|
14935
|
+
throw new Error(`The following practitioners were not found: ${notFoundIds.join(", ")}`);
|
|
14970
14936
|
}
|
|
14971
14937
|
const batch = (0, import_firestore45.writeBatch)(this.db);
|
|
14972
14938
|
const createdProcedureIds = [];
|
|
@@ -15004,9 +14970,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15004
14970
|
product,
|
|
15005
14971
|
blockingConditions: technology.blockingConditions,
|
|
15006
14972
|
contraindications: technology.contraindications || [],
|
|
15007
|
-
contraindicationIds: ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [],
|
|
15008
14973
|
treatmentBenefits: technology.benefits,
|
|
15009
|
-
treatmentBenefitIds: ((_c = technology.benefits) == null ? void 0 : _c.map((b) => b.id)) || [],
|
|
15010
14974
|
preRequirements: technology.requirements.pre,
|
|
15011
14975
|
postRequirements: technology.requirements.post,
|
|
15012
14976
|
certificationRequirement: technology.certificationRequirement,
|
|
@@ -15036,10 +15000,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15036
15000
|
const fetchedProcedures = [];
|
|
15037
15001
|
for (let i = 0; i < createdProcedureIds.length; i += 30) {
|
|
15038
15002
|
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
|
-
);
|
|
15003
|
+
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
15004
|
const snapshot = await (0, import_firestore45.getDocs)(q);
|
|
15044
15005
|
snapshot.forEach((doc37) => {
|
|
15045
15006
|
fetchedProcedures.push(doc37.data());
|
|
@@ -15109,7 +15070,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15109
15070
|
* @returns The updated procedure
|
|
15110
15071
|
*/
|
|
15111
15072
|
async updateProcedure(id, data) {
|
|
15112
|
-
var _a
|
|
15073
|
+
var _a;
|
|
15113
15074
|
const validatedData = updateProcedureSchema.parse(data);
|
|
15114
15075
|
const procedureRef = (0, import_firestore45.doc)(this.db, PROCEDURES_COLLECTION, id);
|
|
15115
15076
|
const procedureSnapshot = await (0, import_firestore45.getDoc)(procedureRef);
|
|
@@ -15140,9 +15101,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15140
15101
|
);
|
|
15141
15102
|
const newPractitionerSnap = await (0, import_firestore45.getDoc)(newPractitionerRef);
|
|
15142
15103
|
if (!newPractitionerSnap.exists())
|
|
15143
|
-
throw new Error(
|
|
15144
|
-
`New Practitioner ${validatedData.practitionerId} not found`
|
|
15145
|
-
);
|
|
15104
|
+
throw new Error(`New Practitioner ${validatedData.practitionerId} not found`);
|
|
15146
15105
|
newPractitioner = newPractitionerSnap.data();
|
|
15147
15106
|
updatedProcedureData.doctorInfo = {
|
|
15148
15107
|
id: newPractitioner.id,
|
|
@@ -15156,11 +15115,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15156
15115
|
}
|
|
15157
15116
|
if (validatedData.clinicBranchId && validatedData.clinicBranchId !== oldClinicId) {
|
|
15158
15117
|
clinicChanged = true;
|
|
15159
|
-
const newClinicRef = (0, import_firestore45.doc)(
|
|
15160
|
-
this.db,
|
|
15161
|
-
CLINICS_COLLECTION,
|
|
15162
|
-
validatedData.clinicBranchId
|
|
15163
|
-
);
|
|
15118
|
+
const newClinicRef = (0, import_firestore45.doc)(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId);
|
|
15164
15119
|
const newClinicSnap = await (0, import_firestore45.getDoc)(newClinicRef);
|
|
15165
15120
|
if (!newClinicSnap.exists())
|
|
15166
15121
|
throw new Error(`New Clinic ${validatedData.clinicBranchId} not found`);
|
|
@@ -15179,11 +15134,8 @@ var ProcedureService = class extends BaseService {
|
|
|
15179
15134
|
updatedProcedureData.nameLower = validatedData.name.toLowerCase();
|
|
15180
15135
|
}
|
|
15181
15136
|
if (validatedData.categoryId) {
|
|
15182
|
-
const category = await this.categoryService.getById(
|
|
15183
|
-
|
|
15184
|
-
);
|
|
15185
|
-
if (!category)
|
|
15186
|
-
throw new Error(`Category ${validatedData.categoryId} not found`);
|
|
15137
|
+
const category = await this.categoryService.getById(validatedData.categoryId);
|
|
15138
|
+
if (!category) throw new Error(`Category ${validatedData.categoryId} not found`);
|
|
15187
15139
|
updatedProcedureData.category = category;
|
|
15188
15140
|
finalCategoryId = category.id;
|
|
15189
15141
|
}
|
|
@@ -15198,34 +15150,23 @@ var ProcedureService = class extends BaseService {
|
|
|
15198
15150
|
);
|
|
15199
15151
|
updatedProcedureData.subcategory = subcategory;
|
|
15200
15152
|
} else if (validatedData.subcategoryId) {
|
|
15201
|
-
console.warn(
|
|
15202
|
-
"Attempted to update subcategory without a valid categoryId"
|
|
15203
|
-
);
|
|
15153
|
+
console.warn("Attempted to update subcategory without a valid categoryId");
|
|
15204
15154
|
}
|
|
15205
15155
|
let finalTechnologyId = existingProcedure.technology.id;
|
|
15206
15156
|
if (validatedData.technologyId) {
|
|
15207
|
-
const technology = await this.technologyService.getById(
|
|
15208
|
-
|
|
15209
|
-
);
|
|
15210
|
-
if (!technology)
|
|
15211
|
-
throw new Error(`Technology ${validatedData.technologyId} not found`);
|
|
15157
|
+
const technology = await this.technologyService.getById(validatedData.technologyId);
|
|
15158
|
+
if (!technology) throw new Error(`Technology ${validatedData.technologyId} not found`);
|
|
15212
15159
|
updatedProcedureData.technology = technology;
|
|
15213
15160
|
finalTechnologyId = technology.id;
|
|
15214
15161
|
updatedProcedureData.blockingConditions = technology.blockingConditions;
|
|
15215
|
-
updatedProcedureData.contraindications = technology.contraindications || [];
|
|
15216
|
-
updatedProcedureData.contraindicationIds = ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [];
|
|
15217
15162
|
updatedProcedureData.treatmentBenefits = technology.benefits;
|
|
15218
|
-
updatedProcedureData.treatmentBenefitIds = ((_c = technology.benefits) == null ? void 0 : _c.map((b) => b.id)) || [];
|
|
15219
15163
|
updatedProcedureData.preRequirements = technology.requirements.pre;
|
|
15220
15164
|
updatedProcedureData.postRequirements = technology.requirements.post;
|
|
15221
15165
|
updatedProcedureData.certificationRequirement = technology.certificationRequirement;
|
|
15222
15166
|
updatedProcedureData.documentationTemplates = technology.documentationTemplates || [];
|
|
15223
15167
|
}
|
|
15224
15168
|
if (validatedData.productId && finalTechnologyId) {
|
|
15225
|
-
const product = await this.productService.getById(
|
|
15226
|
-
finalTechnologyId,
|
|
15227
|
-
validatedData.productId
|
|
15228
|
-
);
|
|
15169
|
+
const product = await this.productService.getById(finalTechnologyId, validatedData.productId);
|
|
15229
15170
|
if (!product)
|
|
15230
15171
|
throw new Error(
|
|
15231
15172
|
`Product ${validatedData.productId} not found for technology ${finalTechnologyId}`
|
|
@@ -15307,11 +15248,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15307
15248
|
limit16(pagination)
|
|
15308
15249
|
);
|
|
15309
15250
|
} else {
|
|
15310
|
-
proceduresQuery = (0, import_firestore45.query)(
|
|
15311
|
-
proceduresCollection,
|
|
15312
|
-
(0, import_firestore45.orderBy)("name"),
|
|
15313
|
-
limit16(pagination)
|
|
15314
|
-
);
|
|
15251
|
+
proceduresQuery = (0, import_firestore45.query)(proceduresCollection, (0, import_firestore45.orderBy)("name"), limit16(pagination));
|
|
15315
15252
|
}
|
|
15316
15253
|
} else {
|
|
15317
15254
|
proceduresQuery = (0, import_firestore45.query)(proceduresCollection, (0, import_firestore45.orderBy)("name"));
|
|
@@ -15342,7 +15279,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15342
15279
|
*
|
|
15343
15280
|
* @param filters - Various filters to apply
|
|
15344
15281
|
* @param filters.nameSearch - Optional search text for procedure name
|
|
15345
|
-
* @param filters.
|
|
15282
|
+
* @param filters.treatmentBenefits - Optional array of treatment benefits to filter by
|
|
15346
15283
|
* @param filters.procedureFamily - Optional procedure family to filter by
|
|
15347
15284
|
* @param filters.procedureCategory - Optional procedure category to filter by
|
|
15348
15285
|
* @param filters.procedureSubcategory - Optional procedure subcategory to filter by
|
|
@@ -15360,9 +15297,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15360
15297
|
*/
|
|
15361
15298
|
async getProceduresByFilters(filters) {
|
|
15362
15299
|
try {
|
|
15363
|
-
console.log(
|
|
15364
|
-
"[PROCEDURE_SERVICE] Starting procedure filtering with multiple strategies"
|
|
15365
|
-
);
|
|
15300
|
+
console.log("[PROCEDURE_SERVICE] Starting procedure filtering with multiple strategies");
|
|
15366
15301
|
if (filters.location && filters.radiusInKm) {
|
|
15367
15302
|
console.log("[PROCEDURE_SERVICE] Executing geo query:", {
|
|
15368
15303
|
location: filters.location,
|
|
@@ -15370,10 +15305,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15370
15305
|
serviceName: "ProcedureService"
|
|
15371
15306
|
});
|
|
15372
15307
|
if (!filters.location.latitude || !filters.location.longitude) {
|
|
15373
|
-
console.warn(
|
|
15374
|
-
"[PROCEDURE_SERVICE] Invalid location data:",
|
|
15375
|
-
filters.location
|
|
15376
|
-
);
|
|
15308
|
+
console.warn("[PROCEDURE_SERVICE] Invalid location data:", filters.location);
|
|
15377
15309
|
filters.location = void 0;
|
|
15378
15310
|
filters.radiusInKm = void 0;
|
|
15379
15311
|
}
|
|
@@ -15393,19 +15325,13 @@ var ProcedureService = class extends BaseService {
|
|
|
15393
15325
|
constraints.push((0, import_firestore45.where)("family", "==", filters.procedureFamily));
|
|
15394
15326
|
}
|
|
15395
15327
|
if (filters.procedureCategory) {
|
|
15396
|
-
constraints.push(
|
|
15397
|
-
(0, import_firestore45.where)("category.id", "==", filters.procedureCategory)
|
|
15398
|
-
);
|
|
15328
|
+
constraints.push((0, import_firestore45.where)("category.id", "==", filters.procedureCategory));
|
|
15399
15329
|
}
|
|
15400
15330
|
if (filters.procedureSubcategory) {
|
|
15401
|
-
constraints.push(
|
|
15402
|
-
(0, import_firestore45.where)("subcategory.id", "==", filters.procedureSubcategory)
|
|
15403
|
-
);
|
|
15331
|
+
constraints.push((0, import_firestore45.where)("subcategory.id", "==", filters.procedureSubcategory));
|
|
15404
15332
|
}
|
|
15405
15333
|
if (filters.procedureTechnology) {
|
|
15406
|
-
constraints.push(
|
|
15407
|
-
(0, import_firestore45.where)("technology.id", "==", filters.procedureTechnology)
|
|
15408
|
-
);
|
|
15334
|
+
constraints.push((0, import_firestore45.where)("technology.id", "==", filters.procedureTechnology));
|
|
15409
15335
|
}
|
|
15410
15336
|
if (filters.minPrice !== void 0) {
|
|
15411
15337
|
constraints.push((0, import_firestore45.where)("price", ">=", filters.minPrice));
|
|
@@ -15414,32 +15340,20 @@ var ProcedureService = class extends BaseService {
|
|
|
15414
15340
|
constraints.push((0, import_firestore45.where)("price", "<=", filters.maxPrice));
|
|
15415
15341
|
}
|
|
15416
15342
|
if (filters.minRating !== void 0) {
|
|
15417
|
-
constraints.push(
|
|
15418
|
-
(0, import_firestore45.where)("reviewInfo.averageRating", ">=", filters.minRating)
|
|
15419
|
-
);
|
|
15343
|
+
constraints.push((0, import_firestore45.where)("reviewInfo.averageRating", ">=", filters.minRating));
|
|
15420
15344
|
}
|
|
15421
15345
|
if (filters.maxRating !== void 0) {
|
|
15422
|
-
constraints.push(
|
|
15423
|
-
(0, import_firestore45.where)("reviewInfo.averageRating", "<=", filters.maxRating)
|
|
15424
|
-
);
|
|
15346
|
+
constraints.push((0, import_firestore45.where)("reviewInfo.averageRating", "<=", filters.maxRating));
|
|
15425
15347
|
}
|
|
15426
15348
|
if (filters.treatmentBenefits && filters.treatmentBenefits.length > 0) {
|
|
15427
|
-
const
|
|
15428
|
-
constraints.push(
|
|
15429
|
-
(0, import_firestore45.where)(
|
|
15430
|
-
"treatmentBenefitIds",
|
|
15431
|
-
"array-contains-any",
|
|
15432
|
-
benefitIdsToMatch
|
|
15433
|
-
)
|
|
15434
|
-
);
|
|
15349
|
+
const benefitsToMatch = filters.treatmentBenefits;
|
|
15350
|
+
constraints.push((0, import_firestore45.where)("treatmentBenefits", "array-contains-any", benefitsToMatch));
|
|
15435
15351
|
}
|
|
15436
15352
|
return constraints;
|
|
15437
15353
|
};
|
|
15438
15354
|
if (filters.nameSearch && filters.nameSearch.trim()) {
|
|
15439
15355
|
try {
|
|
15440
|
-
console.log(
|
|
15441
|
-
"[PROCEDURE_SERVICE] Strategy 1: Trying nameLower search"
|
|
15442
|
-
);
|
|
15356
|
+
console.log("[PROCEDURE_SERVICE] Strategy 1: Trying nameLower search");
|
|
15443
15357
|
const searchTerm = filters.nameSearch.trim().toLowerCase();
|
|
15444
15358
|
const constraints = getBaseConstraints();
|
|
15445
15359
|
constraints.push((0, import_firestore45.where)("nameLower", ">=", searchTerm));
|
|
@@ -15455,18 +15369,13 @@ var ProcedureService = class extends BaseService {
|
|
|
15455
15369
|
}
|
|
15456
15370
|
}
|
|
15457
15371
|
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
|
-
);
|
|
15372
|
+
const q = (0, import_firestore45.query)((0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
15462
15373
|
const querySnapshot = await (0, import_firestore45.getDocs)(q);
|
|
15463
15374
|
const procedures = querySnapshot.docs.map(
|
|
15464
15375
|
(doc37) => ({ ...doc37.data(), id: doc37.id })
|
|
15465
15376
|
);
|
|
15466
15377
|
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
|
-
);
|
|
15378
|
+
console.log(`[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures`);
|
|
15470
15379
|
if (procedures.length < (filters.pagination || 10)) {
|
|
15471
15380
|
return { procedures, lastDoc: null };
|
|
15472
15381
|
}
|
|
@@ -15477,9 +15386,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15477
15386
|
}
|
|
15478
15387
|
if (filters.nameSearch && filters.nameSearch.trim()) {
|
|
15479
15388
|
try {
|
|
15480
|
-
console.log(
|
|
15481
|
-
"[PROCEDURE_SERVICE] Strategy 2: Trying name field search"
|
|
15482
|
-
);
|
|
15389
|
+
console.log("[PROCEDURE_SERVICE] Strategy 2: Trying name field search");
|
|
15483
15390
|
const searchTerm = filters.nameSearch.trim().toLowerCase();
|
|
15484
15391
|
const constraints = getBaseConstraints();
|
|
15485
15392
|
constraints.push((0, import_firestore45.where)("name", ">=", searchTerm));
|
|
@@ -15495,18 +15402,13 @@ var ProcedureService = class extends BaseService {
|
|
|
15495
15402
|
}
|
|
15496
15403
|
}
|
|
15497
15404
|
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
|
-
);
|
|
15405
|
+
const q = (0, import_firestore45.query)((0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
15502
15406
|
const querySnapshot = await (0, import_firestore45.getDocs)(q);
|
|
15503
15407
|
const procedures = querySnapshot.docs.map(
|
|
15504
15408
|
(doc37) => ({ ...doc37.data(), id: doc37.id })
|
|
15505
15409
|
);
|
|
15506
15410
|
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
|
-
);
|
|
15411
|
+
console.log(`[PROCEDURE_SERVICE] Strategy 2 success: ${procedures.length} procedures`);
|
|
15510
15412
|
if (procedures.length < (filters.pagination || 10)) {
|
|
15511
15413
|
return { procedures, lastDoc: null };
|
|
15512
15414
|
}
|
|
@@ -15531,19 +15433,14 @@ var ProcedureService = class extends BaseService {
|
|
|
15531
15433
|
}
|
|
15532
15434
|
}
|
|
15533
15435
|
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
|
-
);
|
|
15436
|
+
const q = (0, import_firestore45.query)((0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
15538
15437
|
const querySnapshot = await (0, import_firestore45.getDocs)(q);
|
|
15539
15438
|
let procedures = querySnapshot.docs.map(
|
|
15540
15439
|
(doc37) => ({ ...doc37.data(), id: doc37.id })
|
|
15541
15440
|
);
|
|
15542
15441
|
procedures = this.applyInMemoryFilters(procedures, filters);
|
|
15543
15442
|
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
|
-
);
|
|
15443
|
+
console.log(`[PROCEDURE_SERVICE] Strategy 3 success: ${procedures.length} procedures`);
|
|
15547
15444
|
if (procedures.length < (filters.pagination || 10)) {
|
|
15548
15445
|
return { procedures, lastDoc: null };
|
|
15549
15446
|
}
|
|
@@ -15558,19 +15455,14 @@ var ProcedureService = class extends BaseService {
|
|
|
15558
15455
|
(0, import_firestore45.orderBy)("createdAt", "desc"),
|
|
15559
15456
|
(0, import_firestore45.limit)(filters.pagination || 10)
|
|
15560
15457
|
];
|
|
15561
|
-
const q = (0, import_firestore45.query)(
|
|
15562
|
-
(0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION),
|
|
15563
|
-
...constraints
|
|
15564
|
-
);
|
|
15458
|
+
const q = (0, import_firestore45.query)((0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
15565
15459
|
const querySnapshot = await (0, import_firestore45.getDocs)(q);
|
|
15566
15460
|
let procedures = querySnapshot.docs.map(
|
|
15567
15461
|
(doc37) => ({ ...doc37.data(), id: doc37.id })
|
|
15568
15462
|
);
|
|
15569
15463
|
procedures = this.applyInMemoryFilters(procedures, filters);
|
|
15570
15464
|
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
|
-
);
|
|
15465
|
+
console.log(`[PROCEDURE_SERVICE] Strategy 4 success: ${procedures.length} procedures`);
|
|
15574
15466
|
if (procedures.length < (filters.pagination || 10)) {
|
|
15575
15467
|
return { procedures, lastDoc: null };
|
|
15576
15468
|
}
|
|
@@ -15578,9 +15470,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15578
15470
|
} catch (error) {
|
|
15579
15471
|
console.log("[PROCEDURE_SERVICE] Strategy 4 failed:", error);
|
|
15580
15472
|
}
|
|
15581
|
-
console.log(
|
|
15582
|
-
"[PROCEDURE_SERVICE] All strategies failed, returning empty result"
|
|
15583
|
-
);
|
|
15473
|
+
console.log("[PROCEDURE_SERVICE] All strategies failed, returning empty result");
|
|
15584
15474
|
return { procedures: [], lastDoc: null };
|
|
15585
15475
|
} catch (error) {
|
|
15586
15476
|
console.error("[PROCEDURE_SERVICE] Error filtering procedures:", error);
|
|
@@ -15600,17 +15490,13 @@ var ProcedureService = class extends BaseService {
|
|
|
15600
15490
|
const nameLower = procedure.nameLower || "";
|
|
15601
15491
|
return name.includes(searchTerm) || nameLower.includes(searchTerm);
|
|
15602
15492
|
});
|
|
15603
|
-
console.log(
|
|
15604
|
-
`[PROCEDURE_SERVICE] Applied name filter, results: ${filteredProcedures.length}`
|
|
15605
|
-
);
|
|
15493
|
+
console.log(`[PROCEDURE_SERVICE] Applied name filter, results: ${filteredProcedures.length}`);
|
|
15606
15494
|
}
|
|
15607
15495
|
if (filters.minPrice !== void 0 || filters.maxPrice !== void 0) {
|
|
15608
15496
|
filteredProcedures = filteredProcedures.filter((procedure) => {
|
|
15609
15497
|
const price = procedure.price || 0;
|
|
15610
|
-
if (filters.minPrice !== void 0 && price < filters.minPrice)
|
|
15611
|
-
|
|
15612
|
-
if (filters.maxPrice !== void 0 && price > filters.maxPrice)
|
|
15613
|
-
return false;
|
|
15498
|
+
if (filters.minPrice !== void 0 && price < filters.minPrice) return false;
|
|
15499
|
+
if (filters.maxPrice !== void 0 && price > filters.maxPrice) return false;
|
|
15614
15500
|
return true;
|
|
15615
15501
|
});
|
|
15616
15502
|
console.log(
|
|
@@ -15621,10 +15507,8 @@ var ProcedureService = class extends BaseService {
|
|
|
15621
15507
|
filteredProcedures = filteredProcedures.filter((procedure) => {
|
|
15622
15508
|
var _a;
|
|
15623
15509
|
const rating = ((_a = procedure.reviewInfo) == null ? void 0 : _a.averageRating) || 0;
|
|
15624
|
-
if (filters.minRating !== void 0 && rating < filters.minRating)
|
|
15625
|
-
|
|
15626
|
-
if (filters.maxRating !== void 0 && rating > filters.maxRating)
|
|
15627
|
-
return false;
|
|
15510
|
+
if (filters.minRating !== void 0 && rating < filters.minRating) return false;
|
|
15511
|
+
if (filters.maxRating !== void 0 && rating > filters.maxRating) return false;
|
|
15628
15512
|
return true;
|
|
15629
15513
|
});
|
|
15630
15514
|
console.log(
|
|
@@ -15632,12 +15516,10 @@ var ProcedureService = class extends BaseService {
|
|
|
15632
15516
|
);
|
|
15633
15517
|
}
|
|
15634
15518
|
if (filters.treatmentBenefits && filters.treatmentBenefits.length > 0) {
|
|
15635
|
-
const
|
|
15519
|
+
const benefitsToMatch = filters.treatmentBenefits;
|
|
15636
15520
|
filteredProcedures = filteredProcedures.filter((procedure) => {
|
|
15637
|
-
const
|
|
15638
|
-
return
|
|
15639
|
-
(benefitId) => procedureBenefitIds.includes(benefitId)
|
|
15640
|
-
);
|
|
15521
|
+
const procedureBenefits = procedure.treatmentBenefits || [];
|
|
15522
|
+
return benefitsToMatch.some((benefit) => procedureBenefits.includes(benefit));
|
|
15641
15523
|
});
|
|
15642
15524
|
console.log(
|
|
15643
15525
|
`[PROCEDURE_SERVICE] Applied benefits filter, results: ${filteredProcedures.length}`
|
|
@@ -15700,12 +15582,8 @@ var ProcedureService = class extends BaseService {
|
|
|
15700
15582
|
procedure.distance = distance;
|
|
15701
15583
|
return distance <= radiusInKm;
|
|
15702
15584
|
});
|
|
15703
|
-
console.log(
|
|
15704
|
-
|
|
15705
|
-
);
|
|
15706
|
-
filteredProcedures.sort(
|
|
15707
|
-
(a, b) => (a.distance || 0) - (b.distance || 0)
|
|
15708
|
-
);
|
|
15585
|
+
console.log(`[PROCEDURE_SERVICE] Applied geo filter, results: ${filteredProcedures.length}`);
|
|
15586
|
+
filteredProcedures.sort((a, b) => (a.distance || 0) - (b.distance || 0));
|
|
15709
15587
|
}
|
|
15710
15588
|
return filteredProcedures;
|
|
15711
15589
|
}
|
|
@@ -15717,30 +15595,19 @@ var ProcedureService = class extends BaseService {
|
|
|
15717
15595
|
if (!location || !radiusInKm) {
|
|
15718
15596
|
return Promise.resolve({ procedures: [], lastDoc: null });
|
|
15719
15597
|
}
|
|
15720
|
-
const bounds = (0, import_geofire_common8.geohashQueryBounds)(
|
|
15721
|
-
[location.latitude, location.longitude],
|
|
15722
|
-
radiusInKm * 1e3
|
|
15723
|
-
);
|
|
15598
|
+
const bounds = (0, import_geofire_common8.geohashQueryBounds)([location.latitude, location.longitude], radiusInKm * 1e3);
|
|
15724
15599
|
const fetches = bounds.map((b) => {
|
|
15725
15600
|
const constraints = [
|
|
15726
15601
|
(0, import_firestore45.where)("clinicInfo.location.geohash", ">=", b[0]),
|
|
15727
15602
|
(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
|
-
)
|
|
15603
|
+
(0, import_firestore45.where)("isActive", "==", filters.isActive !== void 0 ? filters.isActive : true)
|
|
15733
15604
|
];
|
|
15734
|
-
return (0, import_firestore45.getDocs)(
|
|
15735
|
-
(0, import_firestore45.query)((0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION), ...constraints)
|
|
15736
|
-
);
|
|
15605
|
+
return (0, import_firestore45.getDocs)((0, import_firestore45.query)((0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION), ...constraints));
|
|
15737
15606
|
});
|
|
15738
15607
|
return Promise.all(fetches).then((snaps) => {
|
|
15739
15608
|
const collected = [];
|
|
15740
15609
|
snaps.forEach((snap) => {
|
|
15741
|
-
snap.docs.forEach(
|
|
15742
|
-
(d) => collected.push({ ...d.data(), id: d.id })
|
|
15743
|
-
);
|
|
15610
|
+
snap.docs.forEach((d) => collected.push({ ...d.data(), id: d.id }));
|
|
15744
15611
|
});
|
|
15745
15612
|
const uniqueMap = /* @__PURE__ */ new Map();
|
|
15746
15613
|
for (const p of collected) {
|
|
@@ -15751,9 +15618,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15751
15618
|
const pageSize = filters.pagination || 10;
|
|
15752
15619
|
let startIndex = 0;
|
|
15753
15620
|
if (filters.lastDoc && typeof filters.lastDoc === "object" && filters.lastDoc.id) {
|
|
15754
|
-
const idx = procedures.findIndex(
|
|
15755
|
-
(p) => p.id === filters.lastDoc.id
|
|
15756
|
-
);
|
|
15621
|
+
const idx = procedures.findIndex((p) => p.id === filters.lastDoc.id);
|
|
15757
15622
|
if (idx >= 0) startIndex = idx + 1;
|
|
15758
15623
|
}
|
|
15759
15624
|
const page = procedures.slice(startIndex, startIndex + pageSize);
|
|
@@ -15778,7 +15643,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15778
15643
|
* @returns The created procedure
|
|
15779
15644
|
*/
|
|
15780
15645
|
async createConsultationProcedure(data) {
|
|
15781
|
-
var _a
|
|
15646
|
+
var _a;
|
|
15782
15647
|
const procedureId = this.generateId();
|
|
15783
15648
|
const [category, subcategory, technology] = await Promise.all([
|
|
15784
15649
|
this.categoryService.getById(data.categoryId),
|
|
@@ -15794,11 +15659,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15794
15659
|
throw new Error(`Clinic with ID ${data.clinicBranchId} not found`);
|
|
15795
15660
|
}
|
|
15796
15661
|
const clinic = clinicSnapshot.data();
|
|
15797
|
-
const practitionerRef = (0, import_firestore45.doc)(
|
|
15798
|
-
this.db,
|
|
15799
|
-
PRACTITIONERS_COLLECTION,
|
|
15800
|
-
data.practitionerId
|
|
15801
|
-
);
|
|
15662
|
+
const practitionerRef = (0, import_firestore45.doc)(this.db, PRACTITIONERS_COLLECTION, data.practitionerId);
|
|
15802
15663
|
const practitionerSnapshot = await (0, import_firestore45.getDoc)(practitionerRef);
|
|
15803
15664
|
if (!practitionerSnapshot.exists()) {
|
|
15804
15665
|
throw new Error(`Practitioner with ID ${data.practitionerId} not found`);
|
|
@@ -15806,11 +15667,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15806
15667
|
const practitioner = practitionerSnapshot.data();
|
|
15807
15668
|
let processedPhotos = [];
|
|
15808
15669
|
if (data.photos && data.photos.length > 0) {
|
|
15809
|
-
processedPhotos = await this.processMediaArray(
|
|
15810
|
-
data.photos,
|
|
15811
|
-
procedureId,
|
|
15812
|
-
"procedure-photos"
|
|
15813
|
-
);
|
|
15670
|
+
processedPhotos = await this.processMediaArray(data.photos, procedureId, "procedure-photos");
|
|
15814
15671
|
}
|
|
15815
15672
|
const clinicInfo = {
|
|
15816
15673
|
id: clinicSnapshot.id,
|
|
@@ -15852,9 +15709,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15852
15709
|
// Use placeholder product
|
|
15853
15710
|
blockingConditions: technology.blockingConditions,
|
|
15854
15711
|
contraindications: technology.contraindications || [],
|
|
15855
|
-
contraindicationIds: ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [],
|
|
15856
15712
|
treatmentBenefits: technology.benefits,
|
|
15857
|
-
treatmentBenefitIds: ((_c = technology.benefits) == null ? void 0 : _c.map((b) => b.id)) || [],
|
|
15858
15713
|
preRequirements: technology.requirements.pre,
|
|
15859
15714
|
postRequirements: technology.requirements.post,
|
|
15860
15715
|
certificationRequirement: technology.certificationRequirement,
|
|
@@ -16675,16 +16530,8 @@ var TechnologyService = class extends BaseService {
|
|
|
16675
16530
|
*/
|
|
16676
16531
|
async addContraindication(technologyId, contraindication) {
|
|
16677
16532
|
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
16533
|
await (0, import_firestore51.updateDoc)(docRef, {
|
|
16687
|
-
contraindications:
|
|
16534
|
+
contraindications: (0, import_firestore51.arrayUnion)(contraindication),
|
|
16688
16535
|
updatedAt: /* @__PURE__ */ new Date()
|
|
16689
16536
|
});
|
|
16690
16537
|
return this.getById(technologyId);
|
|
@@ -16697,44 +16544,8 @@ var TechnologyService = class extends BaseService {
|
|
|
16697
16544
|
*/
|
|
16698
16545
|
async removeContraindication(technologyId, contraindication) {
|
|
16699
16546
|
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
16547
|
await (0, import_firestore51.updateDoc)(docRef, {
|
|
16737
|
-
contraindications:
|
|
16548
|
+
contraindications: (0, import_firestore51.arrayRemove)(contraindication),
|
|
16738
16549
|
updatedAt: /* @__PURE__ */ new Date()
|
|
16739
16550
|
});
|
|
16740
16551
|
return this.getById(technologyId);
|
|
@@ -16747,16 +16558,8 @@ var TechnologyService = class extends BaseService {
|
|
|
16747
16558
|
*/
|
|
16748
16559
|
async addBenefit(technologyId, benefit) {
|
|
16749
16560
|
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
16561
|
await (0, import_firestore51.updateDoc)(docRef, {
|
|
16759
|
-
benefits:
|
|
16562
|
+
benefits: (0, import_firestore51.arrayUnion)(benefit),
|
|
16760
16563
|
updatedAt: /* @__PURE__ */ new Date()
|
|
16761
16564
|
});
|
|
16762
16565
|
return this.getById(technologyId);
|
|
@@ -16769,44 +16572,8 @@ var TechnologyService = class extends BaseService {
|
|
|
16769
16572
|
*/
|
|
16770
16573
|
async removeBenefit(technologyId, benefit) {
|
|
16771
16574
|
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
16575
|
await (0, import_firestore51.updateDoc)(docRef, {
|
|
16780
|
-
benefits:
|
|
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,
|
|
16576
|
+
benefits: (0, import_firestore51.arrayRemove)(benefit),
|
|
16810
16577
|
updatedAt: /* @__PURE__ */ new Date()
|
|
16811
16578
|
});
|
|
16812
16579
|
return this.getById(technologyId);
|
|
@@ -17060,23 +16827,6 @@ var ProductService = class extends BaseService {
|
|
|
17060
16827
|
}
|
|
17061
16828
|
};
|
|
17062
16829
|
|
|
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
16830
|
// src/backoffice/types/static/treatment-benefit.types.ts
|
|
17081
16831
|
var TreatmentBenefit = /* @__PURE__ */ ((TreatmentBenefit2) => {
|
|
17082
16832
|
TreatmentBenefit2["WRINKLE_REDUCTION"] = "wrinkle_reduction";
|