@blackcode_sa/metaestetics-api 1.11.0 → 1.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/index.d.mts +328 -319
- package/dist/admin/index.d.ts +328 -319
- package/dist/backoffice/index.d.mts +283 -67
- package/dist/backoffice/index.d.ts +283 -67
- package/dist/backoffice/index.js +114 -6
- package/dist/backoffice/index.mjs +112 -6
- package/dist/index.d.mts +3872 -3806
- package/dist/index.d.ts +3872 -3806
- package/dist/index.js +369 -123
- package/dist/index.mjs +369 -124
- package/package.json +1 -1
- package/src/backoffice/expo-safe/index.ts +2 -0
- package/src/backoffice/services/README.md +40 -0
- package/src/backoffice/services/constants.service.ts +268 -0
- package/src/backoffice/services/technology.service.ts +122 -10
- package/src/backoffice/types/admin-constants.types.ts +69 -0
- package/src/backoffice/types/index.ts +1 -0
- package/src/backoffice/types/product.types.ts +3 -1
- package/src/backoffice/types/technology.types.ts +4 -4
- package/src/backoffice/validations/schemas.ts +35 -9
- package/src/services/appointment/appointment.service.ts +0 -5
- package/src/services/appointment/utils/appointment.utils.ts +124 -113
- package/src/services/procedure/procedure.service.ts +434 -234
- package/src/types/appointment/index.ts +5 -3
- package/src/types/clinic/index.ts +1 -6
- package/src/types/patient/medical-info.types.ts +3 -3
- package/src/types/procedure/index.ts +20 -17
- package/src/validations/clinic.schema.ts +1 -6
- package/src/validations/patient/medical-info.schema.ts +7 -2
- package/src/backoffice/services/__tests__/brand.service.test.ts +0 -196
- package/src/backoffice/services/__tests__/category.service.test.ts +0 -201
- package/src/backoffice/services/__tests__/product.service.test.ts +0 -358
- package/src/backoffice/services/__tests__/requirement.service.test.ts +0 -226
- package/src/backoffice/services/__tests__/subcategory.service.test.ts +0 -181
- package/src/backoffice/services/__tests__/technology.service.test.ts +0 -1097
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__ */ ((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;
|
|
191
191
|
})(PaymentStatus || {});
|
|
192
192
|
var MediaType = /* @__PURE__ */ ((MediaType2) => {
|
|
193
193
|
MediaType2["BEFORE_PHOTO"] = "before_photo";
|
|
@@ -936,44 +936,48 @@ async function updateAppointmentUtil(db, appointmentId, data) {
|
|
|
936
936
|
const validPreReqIds = currentAppointment.preProcedureRequirements.map(
|
|
937
937
|
(req) => req.id
|
|
938
938
|
);
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
if (invalidPreReqIds.length > 0) {
|
|
943
|
-
throw new Error(
|
|
944
|
-
`Invalid pre-requirement IDs: ${invalidPreReqIds.join(", ")}`
|
|
939
|
+
if (Array.isArray(data.completedPreRequirements)) {
|
|
940
|
+
const invalidPreReqIds = data.completedPreRequirements.filter(
|
|
941
|
+
(id) => !validPreReqIds.includes(id)
|
|
945
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
|
+
];
|
|
946
954
|
}
|
|
947
|
-
completedPreRequirements = [
|
|
948
|
-
.../* @__PURE__ */ new Set([
|
|
949
|
-
...completedPreRequirements,
|
|
950
|
-
...data.completedPreRequirements
|
|
951
|
-
])
|
|
952
|
-
];
|
|
953
955
|
}
|
|
954
956
|
if (data.completedPostRequirements) {
|
|
955
957
|
const validPostReqIds = currentAppointment.postProcedureRequirements.map(
|
|
956
958
|
(req) => req.id
|
|
957
959
|
);
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
if (invalidPostReqIds.length > 0) {
|
|
962
|
-
throw new Error(
|
|
963
|
-
`Invalid post-requirement IDs: ${invalidPostReqIds.join(", ")}`
|
|
960
|
+
if (Array.isArray(data.completedPostRequirements)) {
|
|
961
|
+
const invalidPostReqIds = data.completedPostRequirements.filter(
|
|
962
|
+
(id) => !validPostReqIds.includes(id)
|
|
964
963
|
);
|
|
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
|
+
];
|
|
965
975
|
}
|
|
966
|
-
completedPostRequirements = [
|
|
967
|
-
.../* @__PURE__ */ new Set([
|
|
968
|
-
...completedPostRequirements,
|
|
969
|
-
...data.completedPostRequirements
|
|
970
|
-
])
|
|
971
|
-
];
|
|
972
976
|
}
|
|
973
977
|
const updateData = {
|
|
974
978
|
...data,
|
|
975
|
-
completedPreRequirements,
|
|
976
|
-
completedPostRequirements,
|
|
979
|
+
completedPreRequirements: Array.isArray(data.completedPreRequirements) ? completedPreRequirements : data.completedPreRequirements,
|
|
980
|
+
completedPostRequirements: Array.isArray(data.completedPostRequirements) ? completedPostRequirements : data.completedPostRequirements,
|
|
977
981
|
updatedAt: (0, import_firestore.serverTimestamp)()
|
|
978
982
|
};
|
|
979
983
|
Object.keys(updateData).forEach((key) => {
|
|
@@ -1023,7 +1027,7 @@ async function updateCalendarEventStatus(db, calendarEventId, appointmentStatus)
|
|
|
1023
1027
|
case "canceled_clinic" /* CANCELED_CLINIC */:
|
|
1024
1028
|
calendarStatus = "canceled";
|
|
1025
1029
|
break;
|
|
1026
|
-
case
|
|
1030
|
+
case "rescheduled_by_clinic" /* RESCHEDULED_BY_CLINIC */:
|
|
1027
1031
|
calendarStatus = "rescheduled";
|
|
1028
1032
|
break;
|
|
1029
1033
|
case "completed" /* COMPLETED */:
|
|
@@ -2839,23 +2843,6 @@ var BlockingCondition = /* @__PURE__ */ ((BlockingCondition2) => {
|
|
|
2839
2843
|
return BlockingCondition2;
|
|
2840
2844
|
})(BlockingCondition || {});
|
|
2841
2845
|
|
|
2842
|
-
// src/backoffice/types/static/contraindication.types.ts
|
|
2843
|
-
var Contraindication = /* @__PURE__ */ ((Contraindication2) => {
|
|
2844
|
-
Contraindication2["SENSITIVE_SKIN"] = "sensitive_skin";
|
|
2845
|
-
Contraindication2["RECENT_TANNING"] = "recent_tanning";
|
|
2846
|
-
Contraindication2["RECENT_BOTOX"] = "recent_botox";
|
|
2847
|
-
Contraindication2["RECENT_FILLERS"] = "recent_fillers";
|
|
2848
|
-
Contraindication2["SKIN_ALLERGIES"] = "skin_allergies";
|
|
2849
|
-
Contraindication2["MEDICATIONS"] = "medications";
|
|
2850
|
-
Contraindication2["RECENT_CHEMICAL_PEEL"] = "recent_chemical_peel";
|
|
2851
|
-
Contraindication2["RECENT_LASER"] = "recent_laser";
|
|
2852
|
-
Contraindication2["SKIN_INFLAMMATION"] = "skin_inflammation";
|
|
2853
|
-
Contraindication2["OPEN_WOUNDS"] = "open_wounds";
|
|
2854
|
-
Contraindication2["HERPES_SIMPLEX"] = "herpes_simplex";
|
|
2855
|
-
Contraindication2["COLD_SORES"] = "cold_sores";
|
|
2856
|
-
return Contraindication2;
|
|
2857
|
-
})(Contraindication || {});
|
|
2858
|
-
|
|
2859
2846
|
// src/validations/common.schema.ts
|
|
2860
2847
|
var import_zod5 = require("zod");
|
|
2861
2848
|
var import_firestore6 = require("firebase/firestore");
|
|
@@ -2910,8 +2897,13 @@ var blockingConditionSchema = import_zod6.z.object({
|
|
|
2910
2897
|
notes: import_zod6.z.string().optional().nullable(),
|
|
2911
2898
|
isActive: import_zod6.z.boolean()
|
|
2912
2899
|
});
|
|
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
|
+
});
|
|
2913
2905
|
var contraindicationSchema = import_zod6.z.object({
|
|
2914
|
-
condition:
|
|
2906
|
+
condition: contraindicationDynamicSchema,
|
|
2915
2907
|
lastOccurrence: timestampSchema,
|
|
2916
2908
|
frequency: import_zod6.z.enum(["rare", "occasional", "frequent"]),
|
|
2917
2909
|
notes: import_zod6.z.string().optional().nullable(),
|
|
@@ -10631,7 +10623,7 @@ async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId,
|
|
|
10631
10623
|
}
|
|
10632
10624
|
|
|
10633
10625
|
// src/services/calendar/utils/appointment.utils.ts
|
|
10634
|
-
async function
|
|
10626
|
+
async function createAppointmentUtil(db, clinicId, practitionerId, patientId, eventData, generateId2) {
|
|
10635
10627
|
const eventId = generateId2();
|
|
10636
10628
|
const autoConfirm = await checkAutoConfirmAppointmentsUtil(db, clinicId);
|
|
10637
10629
|
const initialStatus = autoConfirm ? "confirmed" /* CONFIRMED */ : "pending" /* PENDING */;
|
|
@@ -11949,7 +11941,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
11949
11941
|
syncStatus: "internal" /* INTERNAL */,
|
|
11950
11942
|
eventType: "appointment" /* APPOINTMENT */
|
|
11951
11943
|
};
|
|
11952
|
-
const appointment = await
|
|
11944
|
+
const appointment = await createAppointmentUtil(
|
|
11953
11945
|
this.db,
|
|
11954
11946
|
params.clinicId,
|
|
11955
11947
|
params.doctorId,
|
|
@@ -14754,7 +14746,9 @@ var ProcedureService = class extends BaseService {
|
|
|
14754
14746
|
return media;
|
|
14755
14747
|
}
|
|
14756
14748
|
if (media instanceof File || media instanceof Blob) {
|
|
14757
|
-
console.log(
|
|
14749
|
+
console.log(
|
|
14750
|
+
`[ProcedureService] Uploading ${collectionName} media for ${ownerId}`
|
|
14751
|
+
);
|
|
14758
14752
|
const metadata = await this.mediaService.uploadMedia(
|
|
14759
14753
|
media,
|
|
14760
14754
|
ownerId,
|
|
@@ -14776,7 +14770,11 @@ var ProcedureService = class extends BaseService {
|
|
|
14776
14770
|
if (!mediaArray || mediaArray.length === 0) return [];
|
|
14777
14771
|
const result = [];
|
|
14778
14772
|
for (const media of mediaArray) {
|
|
14779
|
-
const processedUrl = await this.processMedia(
|
|
14773
|
+
const processedUrl = await this.processMedia(
|
|
14774
|
+
media,
|
|
14775
|
+
ownerId,
|
|
14776
|
+
collectionName
|
|
14777
|
+
);
|
|
14780
14778
|
if (processedUrl) {
|
|
14781
14779
|
result.push(processedUrl);
|
|
14782
14780
|
}
|
|
@@ -14789,28 +14787,46 @@ var ProcedureService = class extends BaseService {
|
|
|
14789
14787
|
* @returns The created procedure
|
|
14790
14788
|
*/
|
|
14791
14789
|
async createProcedure(data) {
|
|
14792
|
-
var _a;
|
|
14790
|
+
var _a, _b, _c;
|
|
14793
14791
|
const validatedData = createProcedureSchema.parse(data);
|
|
14794
14792
|
const procedureId = this.generateId();
|
|
14795
14793
|
const [category, subcategory, technology, product] = await Promise.all([
|
|
14796
14794
|
this.categoryService.getById(validatedData.categoryId),
|
|
14797
|
-
this.subcategoryService.getById(
|
|
14795
|
+
this.subcategoryService.getById(
|
|
14796
|
+
validatedData.categoryId,
|
|
14797
|
+
validatedData.subcategoryId
|
|
14798
|
+
),
|
|
14798
14799
|
this.technologyService.getById(validatedData.technologyId),
|
|
14799
|
-
this.productService.getById(
|
|
14800
|
+
this.productService.getById(
|
|
14801
|
+
validatedData.technologyId,
|
|
14802
|
+
validatedData.productId
|
|
14803
|
+
)
|
|
14800
14804
|
]);
|
|
14801
14805
|
if (!category || !subcategory || !technology || !product) {
|
|
14802
14806
|
throw new Error("One or more required base entities not found");
|
|
14803
14807
|
}
|
|
14804
|
-
const clinicRef = (0, import_firestore45.doc)(
|
|
14808
|
+
const clinicRef = (0, import_firestore45.doc)(
|
|
14809
|
+
this.db,
|
|
14810
|
+
CLINICS_COLLECTION,
|
|
14811
|
+
validatedData.clinicBranchId
|
|
14812
|
+
);
|
|
14805
14813
|
const clinicSnapshot = await (0, import_firestore45.getDoc)(clinicRef);
|
|
14806
14814
|
if (!clinicSnapshot.exists()) {
|
|
14807
|
-
throw new Error(
|
|
14815
|
+
throw new Error(
|
|
14816
|
+
`Clinic with ID ${validatedData.clinicBranchId} not found`
|
|
14817
|
+
);
|
|
14808
14818
|
}
|
|
14809
14819
|
const clinic = clinicSnapshot.data();
|
|
14810
|
-
const practitionerRef = (0, import_firestore45.doc)(
|
|
14820
|
+
const practitionerRef = (0, import_firestore45.doc)(
|
|
14821
|
+
this.db,
|
|
14822
|
+
PRACTITIONERS_COLLECTION,
|
|
14823
|
+
validatedData.practitionerId
|
|
14824
|
+
);
|
|
14811
14825
|
const practitionerSnapshot = await (0, import_firestore45.getDoc)(practitionerRef);
|
|
14812
14826
|
if (!practitionerSnapshot.exists()) {
|
|
14813
|
-
throw new Error(
|
|
14827
|
+
throw new Error(
|
|
14828
|
+
`Practitioner with ID ${validatedData.practitionerId} not found`
|
|
14829
|
+
);
|
|
14814
14830
|
}
|
|
14815
14831
|
const practitioner = practitionerSnapshot.data();
|
|
14816
14832
|
let processedPhotos = [];
|
|
@@ -14851,7 +14867,9 @@ var ProcedureService = class extends BaseService {
|
|
|
14851
14867
|
product,
|
|
14852
14868
|
blockingConditions: technology.blockingConditions,
|
|
14853
14869
|
contraindications: technology.contraindications || [],
|
|
14870
|
+
contraindicationIds: ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [],
|
|
14854
14871
|
treatmentBenefits: technology.benefits,
|
|
14872
|
+
treatmentBenefitIds: ((_c = technology.benefits) == null ? void 0 : _c.map((b) => b.id)) || [],
|
|
14855
14873
|
preRequirements: technology.requirements.pre,
|
|
14856
14874
|
postRequirements: technology.requirements.post,
|
|
14857
14875
|
certificationRequirement: technology.certificationRequirement,
|
|
@@ -14892,7 +14910,7 @@ var ProcedureService = class extends BaseService {
|
|
|
14892
14910
|
* @returns A promise that resolves to an array of the newly created procedures.
|
|
14893
14911
|
*/
|
|
14894
14912
|
async bulkCreateProcedures(baseData, practitionerIds) {
|
|
14895
|
-
var _a;
|
|
14913
|
+
var _a, _b, _c;
|
|
14896
14914
|
if (!practitionerIds || practitionerIds.length === 0) {
|
|
14897
14915
|
throw new Error("Practitioner IDs array cannot be empty.");
|
|
14898
14916
|
}
|
|
@@ -14900,16 +14918,24 @@ var ProcedureService = class extends BaseService {
|
|
|
14900
14918
|
const validatedData = createProcedureSchema.parse(validationData);
|
|
14901
14919
|
const [category, subcategory, technology, product, clinicSnapshot] = await Promise.all([
|
|
14902
14920
|
this.categoryService.getById(validatedData.categoryId),
|
|
14903
|
-
this.subcategoryService.getById(
|
|
14921
|
+
this.subcategoryService.getById(
|
|
14922
|
+
validatedData.categoryId,
|
|
14923
|
+
validatedData.subcategoryId
|
|
14924
|
+
),
|
|
14904
14925
|
this.technologyService.getById(validatedData.technologyId),
|
|
14905
|
-
this.productService.getById(
|
|
14926
|
+
this.productService.getById(
|
|
14927
|
+
validatedData.technologyId,
|
|
14928
|
+
validatedData.productId
|
|
14929
|
+
),
|
|
14906
14930
|
(0, import_firestore45.getDoc)((0, import_firestore45.doc)(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId))
|
|
14907
14931
|
]);
|
|
14908
14932
|
if (!category || !subcategory || !technology || !product) {
|
|
14909
14933
|
throw new Error("One or more required base entities not found");
|
|
14910
14934
|
}
|
|
14911
14935
|
if (!clinicSnapshot.exists()) {
|
|
14912
|
-
throw new Error(
|
|
14936
|
+
throw new Error(
|
|
14937
|
+
`Clinic with ID ${validatedData.clinicBranchId} not found`
|
|
14938
|
+
);
|
|
14913
14939
|
}
|
|
14914
14940
|
const clinic = clinicSnapshot.data();
|
|
14915
14941
|
let processedPhotos = [];
|
|
@@ -14935,8 +14961,12 @@ var ProcedureService = class extends BaseService {
|
|
|
14935
14961
|
}
|
|
14936
14962
|
if (practitionersMap.size !== practitionerIds.length) {
|
|
14937
14963
|
const foundIds = Array.from(practitionersMap.keys());
|
|
14938
|
-
const notFoundIds = practitionerIds.filter(
|
|
14939
|
-
|
|
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
|
+
);
|
|
14940
14970
|
}
|
|
14941
14971
|
const batch = (0, import_firestore45.writeBatch)(this.db);
|
|
14942
14972
|
const createdProcedureIds = [];
|
|
@@ -14974,7 +15004,9 @@ var ProcedureService = class extends BaseService {
|
|
|
14974
15004
|
product,
|
|
14975
15005
|
blockingConditions: technology.blockingConditions,
|
|
14976
15006
|
contraindications: technology.contraindications || [],
|
|
15007
|
+
contraindicationIds: ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [],
|
|
14977
15008
|
treatmentBenefits: technology.benefits,
|
|
15009
|
+
treatmentBenefitIds: ((_c = technology.benefits) == null ? void 0 : _c.map((b) => b.id)) || [],
|
|
14978
15010
|
preRequirements: technology.requirements.pre,
|
|
14979
15011
|
postRequirements: technology.requirements.post,
|
|
14980
15012
|
certificationRequirement: technology.certificationRequirement,
|
|
@@ -15004,7 +15036,10 @@ var ProcedureService = class extends BaseService {
|
|
|
15004
15036
|
const fetchedProcedures = [];
|
|
15005
15037
|
for (let i = 0; i < createdProcedureIds.length; i += 30) {
|
|
15006
15038
|
const chunk = createdProcedureIds.slice(i, i + 30);
|
|
15007
|
-
const q = (0, import_firestore45.query)(
|
|
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
|
+
);
|
|
15008
15043
|
const snapshot = await (0, import_firestore45.getDocs)(q);
|
|
15009
15044
|
snapshot.forEach((doc37) => {
|
|
15010
15045
|
fetchedProcedures.push(doc37.data());
|
|
@@ -15074,7 +15109,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15074
15109
|
* @returns The updated procedure
|
|
15075
15110
|
*/
|
|
15076
15111
|
async updateProcedure(id, data) {
|
|
15077
|
-
var _a;
|
|
15112
|
+
var _a, _b, _c;
|
|
15078
15113
|
const validatedData = updateProcedureSchema.parse(data);
|
|
15079
15114
|
const procedureRef = (0, import_firestore45.doc)(this.db, PROCEDURES_COLLECTION, id);
|
|
15080
15115
|
const procedureSnapshot = await (0, import_firestore45.getDoc)(procedureRef);
|
|
@@ -15105,7 +15140,9 @@ var ProcedureService = class extends BaseService {
|
|
|
15105
15140
|
);
|
|
15106
15141
|
const newPractitionerSnap = await (0, import_firestore45.getDoc)(newPractitionerRef);
|
|
15107
15142
|
if (!newPractitionerSnap.exists())
|
|
15108
|
-
throw new Error(
|
|
15143
|
+
throw new Error(
|
|
15144
|
+
`New Practitioner ${validatedData.practitionerId} not found`
|
|
15145
|
+
);
|
|
15109
15146
|
newPractitioner = newPractitionerSnap.data();
|
|
15110
15147
|
updatedProcedureData.doctorInfo = {
|
|
15111
15148
|
id: newPractitioner.id,
|
|
@@ -15119,7 +15156,11 @@ var ProcedureService = class extends BaseService {
|
|
|
15119
15156
|
}
|
|
15120
15157
|
if (validatedData.clinicBranchId && validatedData.clinicBranchId !== oldClinicId) {
|
|
15121
15158
|
clinicChanged = true;
|
|
15122
|
-
const newClinicRef = (0, import_firestore45.doc)(
|
|
15159
|
+
const newClinicRef = (0, import_firestore45.doc)(
|
|
15160
|
+
this.db,
|
|
15161
|
+
CLINICS_COLLECTION,
|
|
15162
|
+
validatedData.clinicBranchId
|
|
15163
|
+
);
|
|
15123
15164
|
const newClinicSnap = await (0, import_firestore45.getDoc)(newClinicRef);
|
|
15124
15165
|
if (!newClinicSnap.exists())
|
|
15125
15166
|
throw new Error(`New Clinic ${validatedData.clinicBranchId} not found`);
|
|
@@ -15138,8 +15179,11 @@ var ProcedureService = class extends BaseService {
|
|
|
15138
15179
|
updatedProcedureData.nameLower = validatedData.name.toLowerCase();
|
|
15139
15180
|
}
|
|
15140
15181
|
if (validatedData.categoryId) {
|
|
15141
|
-
const category = await this.categoryService.getById(
|
|
15142
|
-
|
|
15182
|
+
const category = await this.categoryService.getById(
|
|
15183
|
+
validatedData.categoryId
|
|
15184
|
+
);
|
|
15185
|
+
if (!category)
|
|
15186
|
+
throw new Error(`Category ${validatedData.categoryId} not found`);
|
|
15143
15187
|
updatedProcedureData.category = category;
|
|
15144
15188
|
finalCategoryId = category.id;
|
|
15145
15189
|
}
|
|
@@ -15154,23 +15198,34 @@ var ProcedureService = class extends BaseService {
|
|
|
15154
15198
|
);
|
|
15155
15199
|
updatedProcedureData.subcategory = subcategory;
|
|
15156
15200
|
} else if (validatedData.subcategoryId) {
|
|
15157
|
-
console.warn(
|
|
15201
|
+
console.warn(
|
|
15202
|
+
"Attempted to update subcategory without a valid categoryId"
|
|
15203
|
+
);
|
|
15158
15204
|
}
|
|
15159
15205
|
let finalTechnologyId = existingProcedure.technology.id;
|
|
15160
15206
|
if (validatedData.technologyId) {
|
|
15161
|
-
const technology = await this.technologyService.getById(
|
|
15162
|
-
|
|
15207
|
+
const technology = await this.technologyService.getById(
|
|
15208
|
+
validatedData.technologyId
|
|
15209
|
+
);
|
|
15210
|
+
if (!technology)
|
|
15211
|
+
throw new Error(`Technology ${validatedData.technologyId} not found`);
|
|
15163
15212
|
updatedProcedureData.technology = technology;
|
|
15164
15213
|
finalTechnologyId = technology.id;
|
|
15165
15214
|
updatedProcedureData.blockingConditions = technology.blockingConditions;
|
|
15215
|
+
updatedProcedureData.contraindications = technology.contraindications || [];
|
|
15216
|
+
updatedProcedureData.contraindicationIds = ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [];
|
|
15166
15217
|
updatedProcedureData.treatmentBenefits = technology.benefits;
|
|
15218
|
+
updatedProcedureData.treatmentBenefitIds = ((_c = technology.benefits) == null ? void 0 : _c.map((b) => b.id)) || [];
|
|
15167
15219
|
updatedProcedureData.preRequirements = technology.requirements.pre;
|
|
15168
15220
|
updatedProcedureData.postRequirements = technology.requirements.post;
|
|
15169
15221
|
updatedProcedureData.certificationRequirement = technology.certificationRequirement;
|
|
15170
15222
|
updatedProcedureData.documentationTemplates = technology.documentationTemplates || [];
|
|
15171
15223
|
}
|
|
15172
15224
|
if (validatedData.productId && finalTechnologyId) {
|
|
15173
|
-
const product = await this.productService.getById(
|
|
15225
|
+
const product = await this.productService.getById(
|
|
15226
|
+
finalTechnologyId,
|
|
15227
|
+
validatedData.productId
|
|
15228
|
+
);
|
|
15174
15229
|
if (!product)
|
|
15175
15230
|
throw new Error(
|
|
15176
15231
|
`Product ${validatedData.productId} not found for technology ${finalTechnologyId}`
|
|
@@ -15252,7 +15307,11 @@ var ProcedureService = class extends BaseService {
|
|
|
15252
15307
|
limit16(pagination)
|
|
15253
15308
|
);
|
|
15254
15309
|
} else {
|
|
15255
|
-
proceduresQuery = (0, import_firestore45.query)(
|
|
15310
|
+
proceduresQuery = (0, import_firestore45.query)(
|
|
15311
|
+
proceduresCollection,
|
|
15312
|
+
(0, import_firestore45.orderBy)("name"),
|
|
15313
|
+
limit16(pagination)
|
|
15314
|
+
);
|
|
15256
15315
|
}
|
|
15257
15316
|
} else {
|
|
15258
15317
|
proceduresQuery = (0, import_firestore45.query)(proceduresCollection, (0, import_firestore45.orderBy)("name"));
|
|
@@ -15283,7 +15342,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15283
15342
|
*
|
|
15284
15343
|
* @param filters - Various filters to apply
|
|
15285
15344
|
* @param filters.nameSearch - Optional search text for procedure name
|
|
15286
|
-
* @param filters.
|
|
15345
|
+
* @param filters.treatmentBenefitIds - Optional array of treatment benefits to filter by
|
|
15287
15346
|
* @param filters.procedureFamily - Optional procedure family to filter by
|
|
15288
15347
|
* @param filters.procedureCategory - Optional procedure category to filter by
|
|
15289
15348
|
* @param filters.procedureSubcategory - Optional procedure subcategory to filter by
|
|
@@ -15301,7 +15360,9 @@ var ProcedureService = class extends BaseService {
|
|
|
15301
15360
|
*/
|
|
15302
15361
|
async getProceduresByFilters(filters) {
|
|
15303
15362
|
try {
|
|
15304
|
-
console.log(
|
|
15363
|
+
console.log(
|
|
15364
|
+
"[PROCEDURE_SERVICE] Starting procedure filtering with multiple strategies"
|
|
15365
|
+
);
|
|
15305
15366
|
if (filters.location && filters.radiusInKm) {
|
|
15306
15367
|
console.log("[PROCEDURE_SERVICE] Executing geo query:", {
|
|
15307
15368
|
location: filters.location,
|
|
@@ -15309,7 +15370,10 @@ var ProcedureService = class extends BaseService {
|
|
|
15309
15370
|
serviceName: "ProcedureService"
|
|
15310
15371
|
});
|
|
15311
15372
|
if (!filters.location.latitude || !filters.location.longitude) {
|
|
15312
|
-
console.warn(
|
|
15373
|
+
console.warn(
|
|
15374
|
+
"[PROCEDURE_SERVICE] Invalid location data:",
|
|
15375
|
+
filters.location
|
|
15376
|
+
);
|
|
15313
15377
|
filters.location = void 0;
|
|
15314
15378
|
filters.radiusInKm = void 0;
|
|
15315
15379
|
}
|
|
@@ -15329,13 +15393,19 @@ var ProcedureService = class extends BaseService {
|
|
|
15329
15393
|
constraints.push((0, import_firestore45.where)("family", "==", filters.procedureFamily));
|
|
15330
15394
|
}
|
|
15331
15395
|
if (filters.procedureCategory) {
|
|
15332
|
-
constraints.push(
|
|
15396
|
+
constraints.push(
|
|
15397
|
+
(0, import_firestore45.where)("category.id", "==", filters.procedureCategory)
|
|
15398
|
+
);
|
|
15333
15399
|
}
|
|
15334
15400
|
if (filters.procedureSubcategory) {
|
|
15335
|
-
constraints.push(
|
|
15401
|
+
constraints.push(
|
|
15402
|
+
(0, import_firestore45.where)("subcategory.id", "==", filters.procedureSubcategory)
|
|
15403
|
+
);
|
|
15336
15404
|
}
|
|
15337
15405
|
if (filters.procedureTechnology) {
|
|
15338
|
-
constraints.push(
|
|
15406
|
+
constraints.push(
|
|
15407
|
+
(0, import_firestore45.where)("technology.id", "==", filters.procedureTechnology)
|
|
15408
|
+
);
|
|
15339
15409
|
}
|
|
15340
15410
|
if (filters.minPrice !== void 0) {
|
|
15341
15411
|
constraints.push((0, import_firestore45.where)("price", ">=", filters.minPrice));
|
|
@@ -15344,20 +15414,32 @@ var ProcedureService = class extends BaseService {
|
|
|
15344
15414
|
constraints.push((0, import_firestore45.where)("price", "<=", filters.maxPrice));
|
|
15345
15415
|
}
|
|
15346
15416
|
if (filters.minRating !== void 0) {
|
|
15347
|
-
constraints.push(
|
|
15417
|
+
constraints.push(
|
|
15418
|
+
(0, import_firestore45.where)("reviewInfo.averageRating", ">=", filters.minRating)
|
|
15419
|
+
);
|
|
15348
15420
|
}
|
|
15349
15421
|
if (filters.maxRating !== void 0) {
|
|
15350
|
-
constraints.push(
|
|
15422
|
+
constraints.push(
|
|
15423
|
+
(0, import_firestore45.where)("reviewInfo.averageRating", "<=", filters.maxRating)
|
|
15424
|
+
);
|
|
15351
15425
|
}
|
|
15352
15426
|
if (filters.treatmentBenefits && filters.treatmentBenefits.length > 0) {
|
|
15353
|
-
const
|
|
15354
|
-
constraints.push(
|
|
15427
|
+
const benefitIdsToMatch = filters.treatmentBenefits;
|
|
15428
|
+
constraints.push(
|
|
15429
|
+
(0, import_firestore45.where)(
|
|
15430
|
+
"treatmentBenefitIds",
|
|
15431
|
+
"array-contains-any",
|
|
15432
|
+
benefitIdsToMatch
|
|
15433
|
+
)
|
|
15434
|
+
);
|
|
15355
15435
|
}
|
|
15356
15436
|
return constraints;
|
|
15357
15437
|
};
|
|
15358
15438
|
if (filters.nameSearch && filters.nameSearch.trim()) {
|
|
15359
15439
|
try {
|
|
15360
|
-
console.log(
|
|
15440
|
+
console.log(
|
|
15441
|
+
"[PROCEDURE_SERVICE] Strategy 1: Trying nameLower search"
|
|
15442
|
+
);
|
|
15361
15443
|
const searchTerm = filters.nameSearch.trim().toLowerCase();
|
|
15362
15444
|
const constraints = getBaseConstraints();
|
|
15363
15445
|
constraints.push((0, import_firestore45.where)("nameLower", ">=", searchTerm));
|
|
@@ -15373,13 +15455,18 @@ var ProcedureService = class extends BaseService {
|
|
|
15373
15455
|
}
|
|
15374
15456
|
}
|
|
15375
15457
|
constraints.push((0, import_firestore45.limit)(filters.pagination || 10));
|
|
15376
|
-
const q = (0, import_firestore45.query)(
|
|
15458
|
+
const q = (0, import_firestore45.query)(
|
|
15459
|
+
(0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION),
|
|
15460
|
+
...constraints
|
|
15461
|
+
);
|
|
15377
15462
|
const querySnapshot = await (0, import_firestore45.getDocs)(q);
|
|
15378
15463
|
const procedures = querySnapshot.docs.map(
|
|
15379
15464
|
(doc37) => ({ ...doc37.data(), id: doc37.id })
|
|
15380
15465
|
);
|
|
15381
15466
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
15382
|
-
console.log(
|
|
15467
|
+
console.log(
|
|
15468
|
+
`[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures`
|
|
15469
|
+
);
|
|
15383
15470
|
if (procedures.length < (filters.pagination || 10)) {
|
|
15384
15471
|
return { procedures, lastDoc: null };
|
|
15385
15472
|
}
|
|
@@ -15390,7 +15477,9 @@ var ProcedureService = class extends BaseService {
|
|
|
15390
15477
|
}
|
|
15391
15478
|
if (filters.nameSearch && filters.nameSearch.trim()) {
|
|
15392
15479
|
try {
|
|
15393
|
-
console.log(
|
|
15480
|
+
console.log(
|
|
15481
|
+
"[PROCEDURE_SERVICE] Strategy 2: Trying name field search"
|
|
15482
|
+
);
|
|
15394
15483
|
const searchTerm = filters.nameSearch.trim().toLowerCase();
|
|
15395
15484
|
const constraints = getBaseConstraints();
|
|
15396
15485
|
constraints.push((0, import_firestore45.where)("name", ">=", searchTerm));
|
|
@@ -15406,13 +15495,18 @@ var ProcedureService = class extends BaseService {
|
|
|
15406
15495
|
}
|
|
15407
15496
|
}
|
|
15408
15497
|
constraints.push((0, import_firestore45.limit)(filters.pagination || 10));
|
|
15409
|
-
const q = (0, import_firestore45.query)(
|
|
15498
|
+
const q = (0, import_firestore45.query)(
|
|
15499
|
+
(0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION),
|
|
15500
|
+
...constraints
|
|
15501
|
+
);
|
|
15410
15502
|
const querySnapshot = await (0, import_firestore45.getDocs)(q);
|
|
15411
15503
|
const procedures = querySnapshot.docs.map(
|
|
15412
15504
|
(doc37) => ({ ...doc37.data(), id: doc37.id })
|
|
15413
15505
|
);
|
|
15414
15506
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
15415
|
-
console.log(
|
|
15507
|
+
console.log(
|
|
15508
|
+
`[PROCEDURE_SERVICE] Strategy 2 success: ${procedures.length} procedures`
|
|
15509
|
+
);
|
|
15416
15510
|
if (procedures.length < (filters.pagination || 10)) {
|
|
15417
15511
|
return { procedures, lastDoc: null };
|
|
15418
15512
|
}
|
|
@@ -15437,14 +15531,19 @@ var ProcedureService = class extends BaseService {
|
|
|
15437
15531
|
}
|
|
15438
15532
|
}
|
|
15439
15533
|
constraints.push((0, import_firestore45.limit)(filters.pagination || 10));
|
|
15440
|
-
const q = (0, import_firestore45.query)(
|
|
15534
|
+
const q = (0, import_firestore45.query)(
|
|
15535
|
+
(0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION),
|
|
15536
|
+
...constraints
|
|
15537
|
+
);
|
|
15441
15538
|
const querySnapshot = await (0, import_firestore45.getDocs)(q);
|
|
15442
15539
|
let procedures = querySnapshot.docs.map(
|
|
15443
15540
|
(doc37) => ({ ...doc37.data(), id: doc37.id })
|
|
15444
15541
|
);
|
|
15445
15542
|
procedures = this.applyInMemoryFilters(procedures, filters);
|
|
15446
15543
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
15447
|
-
console.log(
|
|
15544
|
+
console.log(
|
|
15545
|
+
`[PROCEDURE_SERVICE] Strategy 3 success: ${procedures.length} procedures`
|
|
15546
|
+
);
|
|
15448
15547
|
if (procedures.length < (filters.pagination || 10)) {
|
|
15449
15548
|
return { procedures, lastDoc: null };
|
|
15450
15549
|
}
|
|
@@ -15459,14 +15558,19 @@ var ProcedureService = class extends BaseService {
|
|
|
15459
15558
|
(0, import_firestore45.orderBy)("createdAt", "desc"),
|
|
15460
15559
|
(0, import_firestore45.limit)(filters.pagination || 10)
|
|
15461
15560
|
];
|
|
15462
|
-
const q = (0, import_firestore45.query)(
|
|
15561
|
+
const q = (0, import_firestore45.query)(
|
|
15562
|
+
(0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION),
|
|
15563
|
+
...constraints
|
|
15564
|
+
);
|
|
15463
15565
|
const querySnapshot = await (0, import_firestore45.getDocs)(q);
|
|
15464
15566
|
let procedures = querySnapshot.docs.map(
|
|
15465
15567
|
(doc37) => ({ ...doc37.data(), id: doc37.id })
|
|
15466
15568
|
);
|
|
15467
15569
|
procedures = this.applyInMemoryFilters(procedures, filters);
|
|
15468
15570
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
15469
|
-
console.log(
|
|
15571
|
+
console.log(
|
|
15572
|
+
`[PROCEDURE_SERVICE] Strategy 4 success: ${procedures.length} procedures`
|
|
15573
|
+
);
|
|
15470
15574
|
if (procedures.length < (filters.pagination || 10)) {
|
|
15471
15575
|
return { procedures, lastDoc: null };
|
|
15472
15576
|
}
|
|
@@ -15474,7 +15578,9 @@ var ProcedureService = class extends BaseService {
|
|
|
15474
15578
|
} catch (error) {
|
|
15475
15579
|
console.log("[PROCEDURE_SERVICE] Strategy 4 failed:", error);
|
|
15476
15580
|
}
|
|
15477
|
-
console.log(
|
|
15581
|
+
console.log(
|
|
15582
|
+
"[PROCEDURE_SERVICE] All strategies failed, returning empty result"
|
|
15583
|
+
);
|
|
15478
15584
|
return { procedures: [], lastDoc: null };
|
|
15479
15585
|
} catch (error) {
|
|
15480
15586
|
console.error("[PROCEDURE_SERVICE] Error filtering procedures:", error);
|
|
@@ -15494,13 +15600,17 @@ var ProcedureService = class extends BaseService {
|
|
|
15494
15600
|
const nameLower = procedure.nameLower || "";
|
|
15495
15601
|
return name.includes(searchTerm) || nameLower.includes(searchTerm);
|
|
15496
15602
|
});
|
|
15497
|
-
console.log(
|
|
15603
|
+
console.log(
|
|
15604
|
+
`[PROCEDURE_SERVICE] Applied name filter, results: ${filteredProcedures.length}`
|
|
15605
|
+
);
|
|
15498
15606
|
}
|
|
15499
15607
|
if (filters.minPrice !== void 0 || filters.maxPrice !== void 0) {
|
|
15500
15608
|
filteredProcedures = filteredProcedures.filter((procedure) => {
|
|
15501
15609
|
const price = procedure.price || 0;
|
|
15502
|
-
if (filters.minPrice !== void 0 && price < filters.minPrice)
|
|
15503
|
-
|
|
15610
|
+
if (filters.minPrice !== void 0 && price < filters.minPrice)
|
|
15611
|
+
return false;
|
|
15612
|
+
if (filters.maxPrice !== void 0 && price > filters.maxPrice)
|
|
15613
|
+
return false;
|
|
15504
15614
|
return true;
|
|
15505
15615
|
});
|
|
15506
15616
|
console.log(
|
|
@@ -15511,8 +15621,10 @@ var ProcedureService = class extends BaseService {
|
|
|
15511
15621
|
filteredProcedures = filteredProcedures.filter((procedure) => {
|
|
15512
15622
|
var _a;
|
|
15513
15623
|
const rating = ((_a = procedure.reviewInfo) == null ? void 0 : _a.averageRating) || 0;
|
|
15514
|
-
if (filters.minRating !== void 0 && rating < filters.minRating)
|
|
15515
|
-
|
|
15624
|
+
if (filters.minRating !== void 0 && rating < filters.minRating)
|
|
15625
|
+
return false;
|
|
15626
|
+
if (filters.maxRating !== void 0 && rating > filters.maxRating)
|
|
15627
|
+
return false;
|
|
15516
15628
|
return true;
|
|
15517
15629
|
});
|
|
15518
15630
|
console.log(
|
|
@@ -15520,10 +15632,12 @@ var ProcedureService = class extends BaseService {
|
|
|
15520
15632
|
);
|
|
15521
15633
|
}
|
|
15522
15634
|
if (filters.treatmentBenefits && filters.treatmentBenefits.length > 0) {
|
|
15523
|
-
const
|
|
15635
|
+
const benefitIdsToMatch = filters.treatmentBenefits;
|
|
15524
15636
|
filteredProcedures = filteredProcedures.filter((procedure) => {
|
|
15525
|
-
const
|
|
15526
|
-
return
|
|
15637
|
+
const procedureBenefitIds = procedure.treatmentBenefitIds || [];
|
|
15638
|
+
return benefitIdsToMatch.some(
|
|
15639
|
+
(benefitId) => procedureBenefitIds.includes(benefitId)
|
|
15640
|
+
);
|
|
15527
15641
|
});
|
|
15528
15642
|
console.log(
|
|
15529
15643
|
`[PROCEDURE_SERVICE] Applied benefits filter, results: ${filteredProcedures.length}`
|
|
@@ -15586,8 +15700,12 @@ var ProcedureService = class extends BaseService {
|
|
|
15586
15700
|
procedure.distance = distance;
|
|
15587
15701
|
return distance <= radiusInKm;
|
|
15588
15702
|
});
|
|
15589
|
-
console.log(
|
|
15590
|
-
|
|
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
|
+
);
|
|
15591
15709
|
}
|
|
15592
15710
|
return filteredProcedures;
|
|
15593
15711
|
}
|
|
@@ -15599,19 +15717,30 @@ var ProcedureService = class extends BaseService {
|
|
|
15599
15717
|
if (!location || !radiusInKm) {
|
|
15600
15718
|
return Promise.resolve({ procedures: [], lastDoc: null });
|
|
15601
15719
|
}
|
|
15602
|
-
const bounds = (0, import_geofire_common8.geohashQueryBounds)(
|
|
15720
|
+
const bounds = (0, import_geofire_common8.geohashQueryBounds)(
|
|
15721
|
+
[location.latitude, location.longitude],
|
|
15722
|
+
radiusInKm * 1e3
|
|
15723
|
+
);
|
|
15603
15724
|
const fetches = bounds.map((b) => {
|
|
15604
15725
|
const constraints = [
|
|
15605
15726
|
(0, import_firestore45.where)("clinicInfo.location.geohash", ">=", b[0]),
|
|
15606
15727
|
(0, import_firestore45.where)("clinicInfo.location.geohash", "<=", b[1]),
|
|
15607
|
-
(0, import_firestore45.where)(
|
|
15728
|
+
(0, import_firestore45.where)(
|
|
15729
|
+
"isActive",
|
|
15730
|
+
"==",
|
|
15731
|
+
filters.isActive !== void 0 ? filters.isActive : true
|
|
15732
|
+
)
|
|
15608
15733
|
];
|
|
15609
|
-
return (0, import_firestore45.getDocs)(
|
|
15734
|
+
return (0, import_firestore45.getDocs)(
|
|
15735
|
+
(0, import_firestore45.query)((0, import_firestore45.collection)(this.db, PROCEDURES_COLLECTION), ...constraints)
|
|
15736
|
+
);
|
|
15610
15737
|
});
|
|
15611
15738
|
return Promise.all(fetches).then((snaps) => {
|
|
15612
15739
|
const collected = [];
|
|
15613
15740
|
snaps.forEach((snap) => {
|
|
15614
|
-
snap.docs.forEach(
|
|
15741
|
+
snap.docs.forEach(
|
|
15742
|
+
(d) => collected.push({ ...d.data(), id: d.id })
|
|
15743
|
+
);
|
|
15615
15744
|
});
|
|
15616
15745
|
const uniqueMap = /* @__PURE__ */ new Map();
|
|
15617
15746
|
for (const p of collected) {
|
|
@@ -15622,7 +15751,9 @@ var ProcedureService = class extends BaseService {
|
|
|
15622
15751
|
const pageSize = filters.pagination || 10;
|
|
15623
15752
|
let startIndex = 0;
|
|
15624
15753
|
if (filters.lastDoc && typeof filters.lastDoc === "object" && filters.lastDoc.id) {
|
|
15625
|
-
const idx = procedures.findIndex(
|
|
15754
|
+
const idx = procedures.findIndex(
|
|
15755
|
+
(p) => p.id === filters.lastDoc.id
|
|
15756
|
+
);
|
|
15626
15757
|
if (idx >= 0) startIndex = idx + 1;
|
|
15627
15758
|
}
|
|
15628
15759
|
const page = procedures.slice(startIndex, startIndex + pageSize);
|
|
@@ -15647,7 +15778,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15647
15778
|
* @returns The created procedure
|
|
15648
15779
|
*/
|
|
15649
15780
|
async createConsultationProcedure(data) {
|
|
15650
|
-
var _a;
|
|
15781
|
+
var _a, _b, _c;
|
|
15651
15782
|
const procedureId = this.generateId();
|
|
15652
15783
|
const [category, subcategory, technology] = await Promise.all([
|
|
15653
15784
|
this.categoryService.getById(data.categoryId),
|
|
@@ -15663,7 +15794,11 @@ var ProcedureService = class extends BaseService {
|
|
|
15663
15794
|
throw new Error(`Clinic with ID ${data.clinicBranchId} not found`);
|
|
15664
15795
|
}
|
|
15665
15796
|
const clinic = clinicSnapshot.data();
|
|
15666
|
-
const practitionerRef = (0, import_firestore45.doc)(
|
|
15797
|
+
const practitionerRef = (0, import_firestore45.doc)(
|
|
15798
|
+
this.db,
|
|
15799
|
+
PRACTITIONERS_COLLECTION,
|
|
15800
|
+
data.practitionerId
|
|
15801
|
+
);
|
|
15667
15802
|
const practitionerSnapshot = await (0, import_firestore45.getDoc)(practitionerRef);
|
|
15668
15803
|
if (!practitionerSnapshot.exists()) {
|
|
15669
15804
|
throw new Error(`Practitioner with ID ${data.practitionerId} not found`);
|
|
@@ -15671,7 +15806,11 @@ var ProcedureService = class extends BaseService {
|
|
|
15671
15806
|
const practitioner = practitionerSnapshot.data();
|
|
15672
15807
|
let processedPhotos = [];
|
|
15673
15808
|
if (data.photos && data.photos.length > 0) {
|
|
15674
|
-
processedPhotos = await this.processMediaArray(
|
|
15809
|
+
processedPhotos = await this.processMediaArray(
|
|
15810
|
+
data.photos,
|
|
15811
|
+
procedureId,
|
|
15812
|
+
"procedure-photos"
|
|
15813
|
+
);
|
|
15675
15814
|
}
|
|
15676
15815
|
const clinicInfo = {
|
|
15677
15816
|
id: clinicSnapshot.id,
|
|
@@ -15713,7 +15852,9 @@ var ProcedureService = class extends BaseService {
|
|
|
15713
15852
|
// Use placeholder product
|
|
15714
15853
|
blockingConditions: technology.blockingConditions,
|
|
15715
15854
|
contraindications: technology.contraindications || [],
|
|
15855
|
+
contraindicationIds: ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [],
|
|
15716
15856
|
treatmentBenefits: technology.benefits,
|
|
15857
|
+
treatmentBenefitIds: ((_c = technology.benefits) == null ? void 0 : _c.map((b) => b.id)) || [],
|
|
15717
15858
|
preRequirements: technology.requirements.pre,
|
|
15718
15859
|
postRequirements: technology.requirements.post,
|
|
15719
15860
|
certificationRequirement: technology.certificationRequirement,
|
|
@@ -16534,8 +16675,16 @@ var TechnologyService = class extends BaseService {
|
|
|
16534
16675
|
*/
|
|
16535
16676
|
async addContraindication(technologyId, contraindication) {
|
|
16536
16677
|
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
|
+
}
|
|
16537
16686
|
await (0, import_firestore51.updateDoc)(docRef, {
|
|
16538
|
-
contraindications:
|
|
16687
|
+
contraindications: [...existingContraindications, contraindication],
|
|
16539
16688
|
updatedAt: /* @__PURE__ */ new Date()
|
|
16540
16689
|
});
|
|
16541
16690
|
return this.getById(technologyId);
|
|
@@ -16548,8 +16697,44 @@ var TechnologyService = class extends BaseService {
|
|
|
16548
16697
|
*/
|
|
16549
16698
|
async removeContraindication(technologyId, contraindication) {
|
|
16550
16699
|
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;
|
|
16551
16736
|
await (0, import_firestore51.updateDoc)(docRef, {
|
|
16552
|
-
contraindications:
|
|
16737
|
+
contraindications: updatedContraindications,
|
|
16553
16738
|
updatedAt: /* @__PURE__ */ new Date()
|
|
16554
16739
|
});
|
|
16555
16740
|
return this.getById(technologyId);
|
|
@@ -16562,8 +16747,16 @@ var TechnologyService = class extends BaseService {
|
|
|
16562
16747
|
*/
|
|
16563
16748
|
async addBenefit(technologyId, benefit) {
|
|
16564
16749
|
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
|
+
}
|
|
16565
16758
|
await (0, import_firestore51.updateDoc)(docRef, {
|
|
16566
|
-
benefits:
|
|
16759
|
+
benefits: [...existingBenefits, benefit],
|
|
16567
16760
|
updatedAt: /* @__PURE__ */ new Date()
|
|
16568
16761
|
});
|
|
16569
16762
|
return this.getById(technologyId);
|
|
@@ -16576,8 +16769,44 @@ var TechnologyService = class extends BaseService {
|
|
|
16576
16769
|
*/
|
|
16577
16770
|
async removeBenefit(technologyId, benefit) {
|
|
16578
16771
|
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
|
+
);
|
|
16579
16779
|
await (0, import_firestore51.updateDoc)(docRef, {
|
|
16580
|
-
benefits:
|
|
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,
|
|
16581
16810
|
updatedAt: /* @__PURE__ */ new Date()
|
|
16582
16811
|
});
|
|
16583
16812
|
return this.getById(technologyId);
|
|
@@ -16831,6 +17060,23 @@ var ProductService = class extends BaseService {
|
|
|
16831
17060
|
}
|
|
16832
17061
|
};
|
|
16833
17062
|
|
|
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
|
+
|
|
16834
17080
|
// src/backoffice/types/static/treatment-benefit.types.ts
|
|
16835
17081
|
var TreatmentBenefit = /* @__PURE__ */ ((TreatmentBenefit2) => {
|
|
16836
17082
|
TreatmentBenefit2["WRINKLE_REDUCTION"] = "wrinkle_reduction";
|