@blackcode_sa/metaestetics-api 1.12.1 → 1.12.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/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +69 -208
- package/dist/index.mjs +69 -208
- package/package.json +1 -1
- package/src/services/procedure/procedure.service.ts +275 -472
package/dist/index.d.mts
CHANGED
|
@@ -5152,7 +5152,7 @@ declare class ProcedureService extends BaseService {
|
|
|
5152
5152
|
* @param practitionerIds - An array of practitioner IDs for whom the procedures will be created.
|
|
5153
5153
|
* @returns A promise that resolves to an array of the newly created procedures.
|
|
5154
5154
|
*/
|
|
5155
|
-
bulkCreateProcedures(baseData: Omit<CreateProcedureData,
|
|
5155
|
+
bulkCreateProcedures(baseData: Omit<CreateProcedureData, 'practitionerId'>, practitionerIds: string[]): Promise<Procedure[]>;
|
|
5156
5156
|
/**
|
|
5157
5157
|
* Gets a procedure by ID
|
|
5158
5158
|
* @param id - The ID of the procedure to get
|
|
@@ -5277,7 +5277,7 @@ declare class ProcedureService extends BaseService {
|
|
|
5277
5277
|
* @param data - The data for creating a consultation procedure (without productId)
|
|
5278
5278
|
* @returns The created procedure
|
|
5279
5279
|
*/
|
|
5280
|
-
createConsultationProcedure(data: Omit<CreateProcedureData,
|
|
5280
|
+
createConsultationProcedure(data: Omit<CreateProcedureData, 'productId'>): Promise<Procedure>;
|
|
5281
5281
|
/**
|
|
5282
5282
|
* Gets all procedures with minimal info for map display (id, name, clinicId, clinicName, address, latitude, longitude)
|
|
5283
5283
|
* This is optimized for mobile map usage to reduce payload size.
|
package/dist/index.d.ts
CHANGED
|
@@ -5152,7 +5152,7 @@ declare class ProcedureService extends BaseService {
|
|
|
5152
5152
|
* @param practitionerIds - An array of practitioner IDs for whom the procedures will be created.
|
|
5153
5153
|
* @returns A promise that resolves to an array of the newly created procedures.
|
|
5154
5154
|
*/
|
|
5155
|
-
bulkCreateProcedures(baseData: Omit<CreateProcedureData,
|
|
5155
|
+
bulkCreateProcedures(baseData: Omit<CreateProcedureData, 'practitionerId'>, practitionerIds: string[]): Promise<Procedure[]>;
|
|
5156
5156
|
/**
|
|
5157
5157
|
* Gets a procedure by ID
|
|
5158
5158
|
* @param id - The ID of the procedure to get
|
|
@@ -5277,7 +5277,7 @@ declare class ProcedureService extends BaseService {
|
|
|
5277
5277
|
* @param data - The data for creating a consultation procedure (without productId)
|
|
5278
5278
|
* @returns The created procedure
|
|
5279
5279
|
*/
|
|
5280
|
-
createConsultationProcedure(data: Omit<CreateProcedureData,
|
|
5280
|
+
createConsultationProcedure(data: Omit<CreateProcedureData, 'productId'>): Promise<Procedure>;
|
|
5281
5281
|
/**
|
|
5282
5282
|
* Gets all procedures with minimal info for map display (id, name, clinicId, clinicName, address, latitude, longitude)
|
|
5283
5283
|
* This is optimized for mobile map usage to reduce payload size.
|
package/dist/index.js
CHANGED
|
@@ -15000,9 +15000,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15000
15000
|
return media;
|
|
15001
15001
|
}
|
|
15002
15002
|
if (media instanceof File || media instanceof Blob) {
|
|
15003
|
-
console.log(
|
|
15004
|
-
`[ProcedureService] Uploading ${collectionName} media for ${ownerId}`
|
|
15005
|
-
);
|
|
15003
|
+
console.log(`[ProcedureService] Uploading ${collectionName} media for ${ownerId}`);
|
|
15006
15004
|
const metadata = await this.mediaService.uploadMedia(
|
|
15007
15005
|
media,
|
|
15008
15006
|
ownerId,
|
|
@@ -15024,11 +15022,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15024
15022
|
if (!mediaArray || mediaArray.length === 0) return [];
|
|
15025
15023
|
const result = [];
|
|
15026
15024
|
for (const media of mediaArray) {
|
|
15027
|
-
const processedUrl = await this.processMedia(
|
|
15028
|
-
media,
|
|
15029
|
-
ownerId,
|
|
15030
|
-
collectionName
|
|
15031
|
-
);
|
|
15025
|
+
const processedUrl = await this.processMedia(media, ownerId, collectionName);
|
|
15032
15026
|
if (processedUrl) {
|
|
15033
15027
|
result.push(processedUrl);
|
|
15034
15028
|
}
|
|
@@ -15044,10 +15038,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15044
15038
|
async transformProductsMetadata(productsMetadata, technologyId) {
|
|
15045
15039
|
const transformedProducts = [];
|
|
15046
15040
|
for (const productData of productsMetadata) {
|
|
15047
|
-
const product = await this.productService.getById(
|
|
15048
|
-
technologyId,
|
|
15049
|
-
productData.productId
|
|
15050
|
-
);
|
|
15041
|
+
const product = await this.productService.getById(technologyId, productData.productId);
|
|
15051
15042
|
if (!product) {
|
|
15052
15043
|
throw new Error(
|
|
15053
15044
|
`Product with ID ${productData.productId} not found for technology ${technologyId}`
|
|
@@ -15074,41 +15065,23 @@ var ProcedureService = class extends BaseService {
|
|
|
15074
15065
|
const procedureId = this.generateId();
|
|
15075
15066
|
const [category, subcategory, technology, product] = await Promise.all([
|
|
15076
15067
|
this.categoryService.getById(validatedData.categoryId),
|
|
15077
|
-
this.subcategoryService.getById(
|
|
15078
|
-
validatedData.categoryId,
|
|
15079
|
-
validatedData.subcategoryId
|
|
15080
|
-
),
|
|
15068
|
+
this.subcategoryService.getById(validatedData.categoryId, validatedData.subcategoryId),
|
|
15081
15069
|
this.technologyService.getById(validatedData.technologyId),
|
|
15082
|
-
this.productService.getById(
|
|
15083
|
-
validatedData.technologyId,
|
|
15084
|
-
validatedData.productId
|
|
15085
|
-
)
|
|
15070
|
+
this.productService.getById(validatedData.technologyId, validatedData.productId)
|
|
15086
15071
|
]);
|
|
15087
15072
|
if (!category || !subcategory || !technology || !product) {
|
|
15088
15073
|
throw new Error("One or more required base entities not found");
|
|
15089
15074
|
}
|
|
15090
|
-
const clinicRef = (0, import_firestore46.doc)(
|
|
15091
|
-
this.db,
|
|
15092
|
-
CLINICS_COLLECTION,
|
|
15093
|
-
validatedData.clinicBranchId
|
|
15094
|
-
);
|
|
15075
|
+
const clinicRef = (0, import_firestore46.doc)(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId);
|
|
15095
15076
|
const clinicSnapshot = await (0, import_firestore46.getDoc)(clinicRef);
|
|
15096
15077
|
if (!clinicSnapshot.exists()) {
|
|
15097
|
-
throw new Error(
|
|
15098
|
-
`Clinic with ID ${validatedData.clinicBranchId} not found`
|
|
15099
|
-
);
|
|
15078
|
+
throw new Error(`Clinic with ID ${validatedData.clinicBranchId} not found`);
|
|
15100
15079
|
}
|
|
15101
15080
|
const clinic = clinicSnapshot.data();
|
|
15102
|
-
const practitionerRef = (0, import_firestore46.doc)(
|
|
15103
|
-
this.db,
|
|
15104
|
-
PRACTITIONERS_COLLECTION,
|
|
15105
|
-
validatedData.practitionerId
|
|
15106
|
-
);
|
|
15081
|
+
const practitionerRef = (0, import_firestore46.doc)(this.db, PRACTITIONERS_COLLECTION, validatedData.practitionerId);
|
|
15107
15082
|
const practitionerSnapshot = await (0, import_firestore46.getDoc)(practitionerRef);
|
|
15108
15083
|
if (!practitionerSnapshot.exists()) {
|
|
15109
|
-
throw new Error(
|
|
15110
|
-
`Practitioner with ID ${validatedData.practitionerId} not found`
|
|
15111
|
-
);
|
|
15084
|
+
throw new Error(`Practitioner with ID ${validatedData.practitionerId} not found`);
|
|
15112
15085
|
}
|
|
15113
15086
|
const practitioner = practitionerSnapshot.data();
|
|
15114
15087
|
let processedPhotos = [];
|
|
@@ -15140,9 +15113,10 @@ var ProcedureService = class extends BaseService {
|
|
|
15140
15113
|
rating: ((_a = practitioner.reviewInfo) == null ? void 0 : _a.averageRating) || 0,
|
|
15141
15114
|
services: practitioner.procedures || []
|
|
15142
15115
|
};
|
|
15116
|
+
const { productsMetadata: _, ...validatedDataWithoutProductsMetadata } = validatedData;
|
|
15143
15117
|
const newProcedure = {
|
|
15144
15118
|
id: procedureId,
|
|
15145
|
-
...
|
|
15119
|
+
...validatedDataWithoutProductsMetadata,
|
|
15146
15120
|
// Ensure nameLower is always set even if omitted by client
|
|
15147
15121
|
nameLower: validatedData.nameLower || validatedData.name.toLowerCase(),
|
|
15148
15122
|
photos: processedPhotos,
|
|
@@ -15152,6 +15126,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15152
15126
|
technology,
|
|
15153
15127
|
product,
|
|
15154
15128
|
productsMetadata: transformedProductsMetadata,
|
|
15129
|
+
// Use transformed data, not original
|
|
15155
15130
|
blockingConditions: technology.blockingConditions,
|
|
15156
15131
|
contraindications: technology.contraindications || [],
|
|
15157
15132
|
contraindicationIds: ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [],
|
|
@@ -15205,24 +15180,16 @@ var ProcedureService = class extends BaseService {
|
|
|
15205
15180
|
const validatedData = createProcedureSchema.parse(validationData);
|
|
15206
15181
|
const [category, subcategory, technology, product, clinicSnapshot] = await Promise.all([
|
|
15207
15182
|
this.categoryService.getById(validatedData.categoryId),
|
|
15208
|
-
this.subcategoryService.getById(
|
|
15209
|
-
validatedData.categoryId,
|
|
15210
|
-
validatedData.subcategoryId
|
|
15211
|
-
),
|
|
15183
|
+
this.subcategoryService.getById(validatedData.categoryId, validatedData.subcategoryId),
|
|
15212
15184
|
this.technologyService.getById(validatedData.technologyId),
|
|
15213
|
-
this.productService.getById(
|
|
15214
|
-
validatedData.technologyId,
|
|
15215
|
-
validatedData.productId
|
|
15216
|
-
),
|
|
15185
|
+
this.productService.getById(validatedData.technologyId, validatedData.productId),
|
|
15217
15186
|
(0, import_firestore46.getDoc)((0, import_firestore46.doc)(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId))
|
|
15218
15187
|
]);
|
|
15219
15188
|
if (!category || !subcategory || !technology || !product) {
|
|
15220
15189
|
throw new Error("One or more required base entities not found");
|
|
15221
15190
|
}
|
|
15222
15191
|
if (!clinicSnapshot.exists()) {
|
|
15223
|
-
throw new Error(
|
|
15224
|
-
`Clinic with ID ${validatedData.clinicBranchId} not found`
|
|
15225
|
-
);
|
|
15192
|
+
throw new Error(`Clinic with ID ${validatedData.clinicBranchId} not found`);
|
|
15226
15193
|
}
|
|
15227
15194
|
const clinic = clinicSnapshot.data();
|
|
15228
15195
|
let processedPhotos = [];
|
|
@@ -15252,12 +15219,8 @@ var ProcedureService = class extends BaseService {
|
|
|
15252
15219
|
}
|
|
15253
15220
|
if (practitionersMap.size !== practitionerIds.length) {
|
|
15254
15221
|
const foundIds = Array.from(practitionersMap.keys());
|
|
15255
|
-
const notFoundIds = practitionerIds.filter(
|
|
15256
|
-
|
|
15257
|
-
);
|
|
15258
|
-
throw new Error(
|
|
15259
|
-
`The following practitioners were not found: ${notFoundIds.join(", ")}`
|
|
15260
|
-
);
|
|
15222
|
+
const notFoundIds = practitionerIds.filter((id) => !foundIds.includes(id));
|
|
15223
|
+
throw new Error(`The following practitioners were not found: ${notFoundIds.join(", ")}`);
|
|
15261
15224
|
}
|
|
15262
15225
|
const batch = (0, import_firestore46.writeBatch)(this.db);
|
|
15263
15226
|
const createdProcedureIds = [];
|
|
@@ -15282,9 +15245,10 @@ var ProcedureService = class extends BaseService {
|
|
|
15282
15245
|
const procedureId = this.generateId();
|
|
15283
15246
|
createdProcedureIds.push(procedureId);
|
|
15284
15247
|
const procedureRef = (0, import_firestore46.doc)(this.db, PROCEDURES_COLLECTION, procedureId);
|
|
15248
|
+
const { productsMetadata: _, ...validatedDataWithoutProductsMetadata } = validatedData;
|
|
15285
15249
|
const newProcedure = {
|
|
15286
15250
|
id: procedureId,
|
|
15287
|
-
...
|
|
15251
|
+
...validatedDataWithoutProductsMetadata,
|
|
15288
15252
|
nameLower: validatedData.nameLower || validatedData.name.toLowerCase(),
|
|
15289
15253
|
practitionerId,
|
|
15290
15254
|
// Override practitionerId with the correct one
|
|
@@ -15294,6 +15258,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15294
15258
|
technology,
|
|
15295
15259
|
product,
|
|
15296
15260
|
productsMetadata: transformedProductsMetadata,
|
|
15261
|
+
// Use transformed data, not original
|
|
15297
15262
|
blockingConditions: technology.blockingConditions,
|
|
15298
15263
|
contraindications: technology.contraindications || [],
|
|
15299
15264
|
contraindicationIds: ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [],
|
|
@@ -15328,10 +15293,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15328
15293
|
const fetchedProcedures = [];
|
|
15329
15294
|
for (let i = 0; i < createdProcedureIds.length; i += 30) {
|
|
15330
15295
|
const chunk = createdProcedureIds.slice(i, i + 30);
|
|
15331
|
-
const q = (0, import_firestore46.query)(
|
|
15332
|
-
(0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION),
|
|
15333
|
-
(0, import_firestore46.where)((0, import_firestore46.documentId)(), "in", chunk)
|
|
15334
|
-
);
|
|
15296
|
+
const q = (0, import_firestore46.query)((0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION), (0, import_firestore46.where)((0, import_firestore46.documentId)(), "in", chunk));
|
|
15335
15297
|
const snapshot = await (0, import_firestore46.getDocs)(q);
|
|
15336
15298
|
snapshot.forEach((doc38) => {
|
|
15337
15299
|
fetchedProcedures.push(doc38.data());
|
|
@@ -15410,12 +15372,10 @@ var ProcedureService = class extends BaseService {
|
|
|
15410
15372
|
}
|
|
15411
15373
|
const existingProcedure = procedureSnapshot.data();
|
|
15412
15374
|
let updatedProcedureData = {};
|
|
15413
|
-
if (validatedData.name !== void 0)
|
|
15414
|
-
updatedProcedureData.name = validatedData.name;
|
|
15375
|
+
if (validatedData.name !== void 0) updatedProcedureData.name = validatedData.name;
|
|
15415
15376
|
if (validatedData.description !== void 0)
|
|
15416
15377
|
updatedProcedureData.description = validatedData.description;
|
|
15417
|
-
if (validatedData.price !== void 0)
|
|
15418
|
-
updatedProcedureData.price = validatedData.price;
|
|
15378
|
+
if (validatedData.price !== void 0) updatedProcedureData.price = validatedData.price;
|
|
15419
15379
|
if (validatedData.currency !== void 0)
|
|
15420
15380
|
updatedProcedureData.currency = validatedData.currency;
|
|
15421
15381
|
if (validatedData.pricingMeasure !== void 0)
|
|
@@ -15440,9 +15400,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15440
15400
|
if (validatedData.productsMetadata !== void 0) {
|
|
15441
15401
|
const technologyId = (_a = validatedData.technologyId) != null ? _a : existingProcedure.technology.id;
|
|
15442
15402
|
if (!technologyId) {
|
|
15443
|
-
throw new Error(
|
|
15444
|
-
"Technology ID is required for updating products metadata"
|
|
15445
|
-
);
|
|
15403
|
+
throw new Error("Technology ID is required for updating products metadata");
|
|
15446
15404
|
}
|
|
15447
15405
|
updatedProcedureData.productsMetadata = await this.transformProductsMetadata(
|
|
15448
15406
|
validatedData.productsMetadata,
|
|
@@ -15458,9 +15416,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15458
15416
|
);
|
|
15459
15417
|
const newPractitionerSnap = await (0, import_firestore46.getDoc)(newPractitionerRef);
|
|
15460
15418
|
if (!newPractitionerSnap.exists())
|
|
15461
|
-
throw new Error(
|
|
15462
|
-
`New Practitioner ${validatedData.practitionerId} not found`
|
|
15463
|
-
);
|
|
15419
|
+
throw new Error(`New Practitioner ${validatedData.practitionerId} not found`);
|
|
15464
15420
|
newPractitioner = newPractitionerSnap.data();
|
|
15465
15421
|
updatedProcedureData.doctorInfo = {
|
|
15466
15422
|
id: newPractitioner.id,
|
|
@@ -15474,11 +15430,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15474
15430
|
}
|
|
15475
15431
|
if (validatedData.clinicBranchId && validatedData.clinicBranchId !== oldClinicId) {
|
|
15476
15432
|
clinicChanged = true;
|
|
15477
|
-
const newClinicRef = (0, import_firestore46.doc)(
|
|
15478
|
-
this.db,
|
|
15479
|
-
CLINICS_COLLECTION,
|
|
15480
|
-
validatedData.clinicBranchId
|
|
15481
|
-
);
|
|
15433
|
+
const newClinicRef = (0, import_firestore46.doc)(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId);
|
|
15482
15434
|
const newClinicSnap = await (0, import_firestore46.getDoc)(newClinicRef);
|
|
15483
15435
|
if (!newClinicSnap.exists())
|
|
15484
15436
|
throw new Error(`New Clinic ${validatedData.clinicBranchId} not found`);
|
|
@@ -15497,11 +15449,8 @@ var ProcedureService = class extends BaseService {
|
|
|
15497
15449
|
updatedProcedureData.nameLower = validatedData.name.toLowerCase();
|
|
15498
15450
|
}
|
|
15499
15451
|
if (validatedData.categoryId) {
|
|
15500
|
-
const category = await this.categoryService.getById(
|
|
15501
|
-
|
|
15502
|
-
);
|
|
15503
|
-
if (!category)
|
|
15504
|
-
throw new Error(`Category ${validatedData.categoryId} not found`);
|
|
15452
|
+
const category = await this.categoryService.getById(validatedData.categoryId);
|
|
15453
|
+
if (!category) throw new Error(`Category ${validatedData.categoryId} not found`);
|
|
15505
15454
|
updatedProcedureData.category = category;
|
|
15506
15455
|
finalCategoryId = category.id;
|
|
15507
15456
|
}
|
|
@@ -15516,17 +15465,12 @@ var ProcedureService = class extends BaseService {
|
|
|
15516
15465
|
);
|
|
15517
15466
|
updatedProcedureData.subcategory = subcategory;
|
|
15518
15467
|
} else if (validatedData.subcategoryId) {
|
|
15519
|
-
console.warn(
|
|
15520
|
-
"Attempted to update subcategory without a valid categoryId"
|
|
15521
|
-
);
|
|
15468
|
+
console.warn("Attempted to update subcategory without a valid categoryId");
|
|
15522
15469
|
}
|
|
15523
15470
|
let finalTechnologyId = existingProcedure.technology.id;
|
|
15524
15471
|
if (validatedData.technologyId) {
|
|
15525
|
-
const technology = await this.technologyService.getById(
|
|
15526
|
-
|
|
15527
|
-
);
|
|
15528
|
-
if (!technology)
|
|
15529
|
-
throw new Error(`Technology ${validatedData.technologyId} not found`);
|
|
15472
|
+
const technology = await this.technologyService.getById(validatedData.technologyId);
|
|
15473
|
+
if (!technology) throw new Error(`Technology ${validatedData.technologyId} not found`);
|
|
15530
15474
|
updatedProcedureData.technology = technology;
|
|
15531
15475
|
finalTechnologyId = technology.id;
|
|
15532
15476
|
updatedProcedureData.blockingConditions = technology.blockingConditions;
|
|
@@ -15540,10 +15484,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15540
15484
|
updatedProcedureData.documentationTemplates = technology.documentationTemplates || [];
|
|
15541
15485
|
}
|
|
15542
15486
|
if (validatedData.productId && finalTechnologyId) {
|
|
15543
|
-
const product = await this.productService.getById(
|
|
15544
|
-
finalTechnologyId,
|
|
15545
|
-
validatedData.productId
|
|
15546
|
-
);
|
|
15487
|
+
const product = await this.productService.getById(finalTechnologyId, validatedData.productId);
|
|
15547
15488
|
if (!product)
|
|
15548
15489
|
throw new Error(
|
|
15549
15490
|
`Product ${validatedData.productId} not found for technology ${finalTechnologyId}`
|
|
@@ -15625,11 +15566,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15625
15566
|
limit21(pagination)
|
|
15626
15567
|
);
|
|
15627
15568
|
} else {
|
|
15628
|
-
proceduresQuery = (0, import_firestore46.query)(
|
|
15629
|
-
proceduresCollection,
|
|
15630
|
-
(0, import_firestore46.orderBy)("name"),
|
|
15631
|
-
limit21(pagination)
|
|
15632
|
-
);
|
|
15569
|
+
proceduresQuery = (0, import_firestore46.query)(proceduresCollection, (0, import_firestore46.orderBy)("name"), limit21(pagination));
|
|
15633
15570
|
}
|
|
15634
15571
|
} else {
|
|
15635
15572
|
proceduresQuery = (0, import_firestore46.query)(proceduresCollection, (0, import_firestore46.orderBy)("name"));
|
|
@@ -15678,9 +15615,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15678
15615
|
*/
|
|
15679
15616
|
async getProceduresByFilters(filters) {
|
|
15680
15617
|
try {
|
|
15681
|
-
console.log(
|
|
15682
|
-
"[PROCEDURE_SERVICE] Starting procedure filtering with multiple strategies"
|
|
15683
|
-
);
|
|
15618
|
+
console.log("[PROCEDURE_SERVICE] Starting procedure filtering with multiple strategies");
|
|
15684
15619
|
if (filters.location && filters.radiusInKm) {
|
|
15685
15620
|
console.log("[PROCEDURE_SERVICE] Executing geo query:", {
|
|
15686
15621
|
location: filters.location,
|
|
@@ -15688,10 +15623,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15688
15623
|
serviceName: "ProcedureService"
|
|
15689
15624
|
});
|
|
15690
15625
|
if (!filters.location.latitude || !filters.location.longitude) {
|
|
15691
|
-
console.warn(
|
|
15692
|
-
"[PROCEDURE_SERVICE] Invalid location data:",
|
|
15693
|
-
filters.location
|
|
15694
|
-
);
|
|
15626
|
+
console.warn("[PROCEDURE_SERVICE] Invalid location data:", filters.location);
|
|
15695
15627
|
filters.location = void 0;
|
|
15696
15628
|
filters.radiusInKm = void 0;
|
|
15697
15629
|
}
|
|
@@ -15711,19 +15643,13 @@ var ProcedureService = class extends BaseService {
|
|
|
15711
15643
|
constraints.push((0, import_firestore46.where)("family", "==", filters.procedureFamily));
|
|
15712
15644
|
}
|
|
15713
15645
|
if (filters.procedureCategory) {
|
|
15714
|
-
constraints.push(
|
|
15715
|
-
(0, import_firestore46.where)("category.id", "==", filters.procedureCategory)
|
|
15716
|
-
);
|
|
15646
|
+
constraints.push((0, import_firestore46.where)("category.id", "==", filters.procedureCategory));
|
|
15717
15647
|
}
|
|
15718
15648
|
if (filters.procedureSubcategory) {
|
|
15719
|
-
constraints.push(
|
|
15720
|
-
(0, import_firestore46.where)("subcategory.id", "==", filters.procedureSubcategory)
|
|
15721
|
-
);
|
|
15649
|
+
constraints.push((0, import_firestore46.where)("subcategory.id", "==", filters.procedureSubcategory));
|
|
15722
15650
|
}
|
|
15723
15651
|
if (filters.procedureTechnology) {
|
|
15724
|
-
constraints.push(
|
|
15725
|
-
(0, import_firestore46.where)("technology.id", "==", filters.procedureTechnology)
|
|
15726
|
-
);
|
|
15652
|
+
constraints.push((0, import_firestore46.where)("technology.id", "==", filters.procedureTechnology));
|
|
15727
15653
|
}
|
|
15728
15654
|
if (filters.minPrice !== void 0) {
|
|
15729
15655
|
constraints.push((0, import_firestore46.where)("price", ">=", filters.minPrice));
|
|
@@ -15732,32 +15658,20 @@ var ProcedureService = class extends BaseService {
|
|
|
15732
15658
|
constraints.push((0, import_firestore46.where)("price", "<=", filters.maxPrice));
|
|
15733
15659
|
}
|
|
15734
15660
|
if (filters.minRating !== void 0) {
|
|
15735
|
-
constraints.push(
|
|
15736
|
-
(0, import_firestore46.where)("reviewInfo.averageRating", ">=", filters.minRating)
|
|
15737
|
-
);
|
|
15661
|
+
constraints.push((0, import_firestore46.where)("reviewInfo.averageRating", ">=", filters.minRating));
|
|
15738
15662
|
}
|
|
15739
15663
|
if (filters.maxRating !== void 0) {
|
|
15740
|
-
constraints.push(
|
|
15741
|
-
(0, import_firestore46.where)("reviewInfo.averageRating", "<=", filters.maxRating)
|
|
15742
|
-
);
|
|
15664
|
+
constraints.push((0, import_firestore46.where)("reviewInfo.averageRating", "<=", filters.maxRating));
|
|
15743
15665
|
}
|
|
15744
15666
|
if (filters.treatmentBenefits && filters.treatmentBenefits.length > 0) {
|
|
15745
15667
|
const benefitIdsToMatch = filters.treatmentBenefits;
|
|
15746
|
-
constraints.push(
|
|
15747
|
-
(0, import_firestore46.where)(
|
|
15748
|
-
"treatmentBenefitIds",
|
|
15749
|
-
"array-contains-any",
|
|
15750
|
-
benefitIdsToMatch
|
|
15751
|
-
)
|
|
15752
|
-
);
|
|
15668
|
+
constraints.push((0, import_firestore46.where)("treatmentBenefitIds", "array-contains-any", benefitIdsToMatch));
|
|
15753
15669
|
}
|
|
15754
15670
|
return constraints;
|
|
15755
15671
|
};
|
|
15756
15672
|
if (filters.nameSearch && filters.nameSearch.trim()) {
|
|
15757
15673
|
try {
|
|
15758
|
-
console.log(
|
|
15759
|
-
"[PROCEDURE_SERVICE] Strategy 1: Trying nameLower search"
|
|
15760
|
-
);
|
|
15674
|
+
console.log("[PROCEDURE_SERVICE] Strategy 1: Trying nameLower search");
|
|
15761
15675
|
const searchTerm = filters.nameSearch.trim().toLowerCase();
|
|
15762
15676
|
const constraints = getBaseConstraints();
|
|
15763
15677
|
constraints.push((0, import_firestore46.where)("nameLower", ">=", searchTerm));
|
|
@@ -15773,18 +15687,13 @@ var ProcedureService = class extends BaseService {
|
|
|
15773
15687
|
}
|
|
15774
15688
|
}
|
|
15775
15689
|
constraints.push((0, import_firestore46.limit)(filters.pagination || 10));
|
|
15776
|
-
const q = (0, import_firestore46.query)(
|
|
15777
|
-
(0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION),
|
|
15778
|
-
...constraints
|
|
15779
|
-
);
|
|
15690
|
+
const q = (0, import_firestore46.query)((0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
15780
15691
|
const querySnapshot = await (0, import_firestore46.getDocs)(q);
|
|
15781
15692
|
const procedures = querySnapshot.docs.map(
|
|
15782
15693
|
(doc38) => ({ ...doc38.data(), id: doc38.id })
|
|
15783
15694
|
);
|
|
15784
15695
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
15785
|
-
console.log(
|
|
15786
|
-
`[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures`
|
|
15787
|
-
);
|
|
15696
|
+
console.log(`[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures`);
|
|
15788
15697
|
if (procedures.length < (filters.pagination || 10)) {
|
|
15789
15698
|
return { procedures, lastDoc: null };
|
|
15790
15699
|
}
|
|
@@ -15795,9 +15704,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15795
15704
|
}
|
|
15796
15705
|
if (filters.nameSearch && filters.nameSearch.trim()) {
|
|
15797
15706
|
try {
|
|
15798
|
-
console.log(
|
|
15799
|
-
"[PROCEDURE_SERVICE] Strategy 2: Trying name field search"
|
|
15800
|
-
);
|
|
15707
|
+
console.log("[PROCEDURE_SERVICE] Strategy 2: Trying name field search");
|
|
15801
15708
|
const searchTerm = filters.nameSearch.trim().toLowerCase();
|
|
15802
15709
|
const constraints = getBaseConstraints();
|
|
15803
15710
|
constraints.push((0, import_firestore46.where)("name", ">=", searchTerm));
|
|
@@ -15813,18 +15720,13 @@ var ProcedureService = class extends BaseService {
|
|
|
15813
15720
|
}
|
|
15814
15721
|
}
|
|
15815
15722
|
constraints.push((0, import_firestore46.limit)(filters.pagination || 10));
|
|
15816
|
-
const q = (0, import_firestore46.query)(
|
|
15817
|
-
(0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION),
|
|
15818
|
-
...constraints
|
|
15819
|
-
);
|
|
15723
|
+
const q = (0, import_firestore46.query)((0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
15820
15724
|
const querySnapshot = await (0, import_firestore46.getDocs)(q);
|
|
15821
15725
|
const procedures = querySnapshot.docs.map(
|
|
15822
15726
|
(doc38) => ({ ...doc38.data(), id: doc38.id })
|
|
15823
15727
|
);
|
|
15824
15728
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
15825
|
-
console.log(
|
|
15826
|
-
`[PROCEDURE_SERVICE] Strategy 2 success: ${procedures.length} procedures`
|
|
15827
|
-
);
|
|
15729
|
+
console.log(`[PROCEDURE_SERVICE] Strategy 2 success: ${procedures.length} procedures`);
|
|
15828
15730
|
if (procedures.length < (filters.pagination || 10)) {
|
|
15829
15731
|
return { procedures, lastDoc: null };
|
|
15830
15732
|
}
|
|
@@ -15849,19 +15751,14 @@ var ProcedureService = class extends BaseService {
|
|
|
15849
15751
|
}
|
|
15850
15752
|
}
|
|
15851
15753
|
constraints.push((0, import_firestore46.limit)(filters.pagination || 10));
|
|
15852
|
-
const q = (0, import_firestore46.query)(
|
|
15853
|
-
(0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION),
|
|
15854
|
-
...constraints
|
|
15855
|
-
);
|
|
15754
|
+
const q = (0, import_firestore46.query)((0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
15856
15755
|
const querySnapshot = await (0, import_firestore46.getDocs)(q);
|
|
15857
15756
|
let procedures = querySnapshot.docs.map(
|
|
15858
15757
|
(doc38) => ({ ...doc38.data(), id: doc38.id })
|
|
15859
15758
|
);
|
|
15860
15759
|
procedures = this.applyInMemoryFilters(procedures, filters);
|
|
15861
15760
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
15862
|
-
console.log(
|
|
15863
|
-
`[PROCEDURE_SERVICE] Strategy 3 success: ${procedures.length} procedures`
|
|
15864
|
-
);
|
|
15761
|
+
console.log(`[PROCEDURE_SERVICE] Strategy 3 success: ${procedures.length} procedures`);
|
|
15865
15762
|
if (procedures.length < (filters.pagination || 10)) {
|
|
15866
15763
|
return { procedures, lastDoc: null };
|
|
15867
15764
|
}
|
|
@@ -15876,19 +15773,14 @@ var ProcedureService = class extends BaseService {
|
|
|
15876
15773
|
(0, import_firestore46.orderBy)("createdAt", "desc"),
|
|
15877
15774
|
(0, import_firestore46.limit)(filters.pagination || 10)
|
|
15878
15775
|
];
|
|
15879
|
-
const q = (0, import_firestore46.query)(
|
|
15880
|
-
(0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION),
|
|
15881
|
-
...constraints
|
|
15882
|
-
);
|
|
15776
|
+
const q = (0, import_firestore46.query)((0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
15883
15777
|
const querySnapshot = await (0, import_firestore46.getDocs)(q);
|
|
15884
15778
|
let procedures = querySnapshot.docs.map(
|
|
15885
15779
|
(doc38) => ({ ...doc38.data(), id: doc38.id })
|
|
15886
15780
|
);
|
|
15887
15781
|
procedures = this.applyInMemoryFilters(procedures, filters);
|
|
15888
15782
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
15889
|
-
console.log(
|
|
15890
|
-
`[PROCEDURE_SERVICE] Strategy 4 success: ${procedures.length} procedures`
|
|
15891
|
-
);
|
|
15783
|
+
console.log(`[PROCEDURE_SERVICE] Strategy 4 success: ${procedures.length} procedures`);
|
|
15892
15784
|
if (procedures.length < (filters.pagination || 10)) {
|
|
15893
15785
|
return { procedures, lastDoc: null };
|
|
15894
15786
|
}
|
|
@@ -15896,9 +15788,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15896
15788
|
} catch (error) {
|
|
15897
15789
|
console.log("[PROCEDURE_SERVICE] Strategy 4 failed:", error);
|
|
15898
15790
|
}
|
|
15899
|
-
console.log(
|
|
15900
|
-
"[PROCEDURE_SERVICE] All strategies failed, returning empty result"
|
|
15901
|
-
);
|
|
15791
|
+
console.log("[PROCEDURE_SERVICE] All strategies failed, returning empty result");
|
|
15902
15792
|
return { procedures: [], lastDoc: null };
|
|
15903
15793
|
} catch (error) {
|
|
15904
15794
|
console.error("[PROCEDURE_SERVICE] Error filtering procedures:", error);
|
|
@@ -15918,17 +15808,13 @@ var ProcedureService = class extends BaseService {
|
|
|
15918
15808
|
const nameLower = procedure.nameLower || "";
|
|
15919
15809
|
return name.includes(searchTerm) || nameLower.includes(searchTerm);
|
|
15920
15810
|
});
|
|
15921
|
-
console.log(
|
|
15922
|
-
`[PROCEDURE_SERVICE] Applied name filter, results: ${filteredProcedures.length}`
|
|
15923
|
-
);
|
|
15811
|
+
console.log(`[PROCEDURE_SERVICE] Applied name filter, results: ${filteredProcedures.length}`);
|
|
15924
15812
|
}
|
|
15925
15813
|
if (filters.minPrice !== void 0 || filters.maxPrice !== void 0) {
|
|
15926
15814
|
filteredProcedures = filteredProcedures.filter((procedure) => {
|
|
15927
15815
|
const price = procedure.price || 0;
|
|
15928
|
-
if (filters.minPrice !== void 0 && price < filters.minPrice)
|
|
15929
|
-
|
|
15930
|
-
if (filters.maxPrice !== void 0 && price > filters.maxPrice)
|
|
15931
|
-
return false;
|
|
15816
|
+
if (filters.minPrice !== void 0 && price < filters.minPrice) return false;
|
|
15817
|
+
if (filters.maxPrice !== void 0 && price > filters.maxPrice) return false;
|
|
15932
15818
|
return true;
|
|
15933
15819
|
});
|
|
15934
15820
|
console.log(
|
|
@@ -15939,10 +15825,8 @@ var ProcedureService = class extends BaseService {
|
|
|
15939
15825
|
filteredProcedures = filteredProcedures.filter((procedure) => {
|
|
15940
15826
|
var _a;
|
|
15941
15827
|
const rating = ((_a = procedure.reviewInfo) == null ? void 0 : _a.averageRating) || 0;
|
|
15942
|
-
if (filters.minRating !== void 0 && rating < filters.minRating)
|
|
15943
|
-
|
|
15944
|
-
if (filters.maxRating !== void 0 && rating > filters.maxRating)
|
|
15945
|
-
return false;
|
|
15828
|
+
if (filters.minRating !== void 0 && rating < filters.minRating) return false;
|
|
15829
|
+
if (filters.maxRating !== void 0 && rating > filters.maxRating) return false;
|
|
15946
15830
|
return true;
|
|
15947
15831
|
});
|
|
15948
15832
|
console.log(
|
|
@@ -16018,12 +15902,8 @@ var ProcedureService = class extends BaseService {
|
|
|
16018
15902
|
procedure.distance = distance;
|
|
16019
15903
|
return distance <= radiusInKm;
|
|
16020
15904
|
});
|
|
16021
|
-
console.log(
|
|
16022
|
-
|
|
16023
|
-
);
|
|
16024
|
-
filteredProcedures.sort(
|
|
16025
|
-
(a, b) => (a.distance || 0) - (b.distance || 0)
|
|
16026
|
-
);
|
|
15905
|
+
console.log(`[PROCEDURE_SERVICE] Applied geo filter, results: ${filteredProcedures.length}`);
|
|
15906
|
+
filteredProcedures.sort((a, b) => (a.distance || 0) - (b.distance || 0));
|
|
16027
15907
|
}
|
|
16028
15908
|
return filteredProcedures;
|
|
16029
15909
|
}
|
|
@@ -16035,30 +15915,19 @@ var ProcedureService = class extends BaseService {
|
|
|
16035
15915
|
if (!location || !radiusInKm) {
|
|
16036
15916
|
return Promise.resolve({ procedures: [], lastDoc: null });
|
|
16037
15917
|
}
|
|
16038
|
-
const bounds = (0, import_geofire_common8.geohashQueryBounds)(
|
|
16039
|
-
[location.latitude, location.longitude],
|
|
16040
|
-
radiusInKm * 1e3
|
|
16041
|
-
);
|
|
15918
|
+
const bounds = (0, import_geofire_common8.geohashQueryBounds)([location.latitude, location.longitude], radiusInKm * 1e3);
|
|
16042
15919
|
const fetches = bounds.map((b) => {
|
|
16043
15920
|
const constraints = [
|
|
16044
15921
|
(0, import_firestore46.where)("clinicInfo.location.geohash", ">=", b[0]),
|
|
16045
15922
|
(0, import_firestore46.where)("clinicInfo.location.geohash", "<=", b[1]),
|
|
16046
|
-
(0, import_firestore46.where)(
|
|
16047
|
-
"isActive",
|
|
16048
|
-
"==",
|
|
16049
|
-
filters.isActive !== void 0 ? filters.isActive : true
|
|
16050
|
-
)
|
|
15923
|
+
(0, import_firestore46.where)("isActive", "==", filters.isActive !== void 0 ? filters.isActive : true)
|
|
16051
15924
|
];
|
|
16052
|
-
return (0, import_firestore46.getDocs)(
|
|
16053
|
-
(0, import_firestore46.query)((0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION), ...constraints)
|
|
16054
|
-
);
|
|
15925
|
+
return (0, import_firestore46.getDocs)((0, import_firestore46.query)((0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION), ...constraints));
|
|
16055
15926
|
});
|
|
16056
15927
|
return Promise.all(fetches).then((snaps) => {
|
|
16057
15928
|
const collected = [];
|
|
16058
15929
|
snaps.forEach((snap) => {
|
|
16059
|
-
snap.docs.forEach(
|
|
16060
|
-
(d) => collected.push({ ...d.data(), id: d.id })
|
|
16061
|
-
);
|
|
15930
|
+
snap.docs.forEach((d) => collected.push({ ...d.data(), id: d.id }));
|
|
16062
15931
|
});
|
|
16063
15932
|
const uniqueMap = /* @__PURE__ */ new Map();
|
|
16064
15933
|
for (const p of collected) {
|
|
@@ -16069,9 +15938,7 @@ var ProcedureService = class extends BaseService {
|
|
|
16069
15938
|
const pageSize = filters.pagination || 10;
|
|
16070
15939
|
let startIndex = 0;
|
|
16071
15940
|
if (filters.lastDoc && typeof filters.lastDoc === "object" && filters.lastDoc.id) {
|
|
16072
|
-
const idx = procedures.findIndex(
|
|
16073
|
-
(p) => p.id === filters.lastDoc.id
|
|
16074
|
-
);
|
|
15941
|
+
const idx = procedures.findIndex((p) => p.id === filters.lastDoc.id);
|
|
16075
15942
|
if (idx >= 0) startIndex = idx + 1;
|
|
16076
15943
|
}
|
|
16077
15944
|
const page = procedures.slice(startIndex, startIndex + pageSize);
|
|
@@ -16112,11 +15979,7 @@ var ProcedureService = class extends BaseService {
|
|
|
16112
15979
|
throw new Error(`Clinic with ID ${data.clinicBranchId} not found`);
|
|
16113
15980
|
}
|
|
16114
15981
|
const clinic = clinicSnapshot.data();
|
|
16115
|
-
const practitionerRef = (0, import_firestore46.doc)(
|
|
16116
|
-
this.db,
|
|
16117
|
-
PRACTITIONERS_COLLECTION,
|
|
16118
|
-
data.practitionerId
|
|
16119
|
-
);
|
|
15982
|
+
const practitionerRef = (0, import_firestore46.doc)(this.db, PRACTITIONERS_COLLECTION, data.practitionerId);
|
|
16120
15983
|
const practitionerSnapshot = await (0, import_firestore46.getDoc)(practitionerRef);
|
|
16121
15984
|
if (!practitionerSnapshot.exists()) {
|
|
16122
15985
|
throw new Error(`Practitioner with ID ${data.practitionerId} not found`);
|
|
@@ -16124,11 +15987,7 @@ var ProcedureService = class extends BaseService {
|
|
|
16124
15987
|
const practitioner = practitionerSnapshot.data();
|
|
16125
15988
|
let processedPhotos = [];
|
|
16126
15989
|
if (data.photos && data.photos.length > 0) {
|
|
16127
|
-
processedPhotos = await this.processMediaArray(
|
|
16128
|
-
data.photos,
|
|
16129
|
-
procedureId,
|
|
16130
|
-
"procedure-photos"
|
|
16131
|
-
);
|
|
15990
|
+
processedPhotos = await this.processMediaArray(data.photos, procedureId, "procedure-photos");
|
|
16132
15991
|
}
|
|
16133
15992
|
const transformedProductsMetadata = await this.transformProductsMetadata(
|
|
16134
15993
|
data.productsMetadata,
|
|
@@ -16164,9 +16023,10 @@ var ProcedureService = class extends BaseService {
|
|
|
16164
16023
|
createdAt: /* @__PURE__ */ new Date(),
|
|
16165
16024
|
updatedAt: /* @__PURE__ */ new Date()
|
|
16166
16025
|
};
|
|
16026
|
+
const { productsMetadata: _, ...dataWithoutProductsMetadata } = data;
|
|
16167
16027
|
const newProcedure = {
|
|
16168
16028
|
id: procedureId,
|
|
16169
|
-
...
|
|
16029
|
+
...dataWithoutProductsMetadata,
|
|
16170
16030
|
nameLower: data.nameLower || data.name.toLowerCase(),
|
|
16171
16031
|
photos: processedPhotos,
|
|
16172
16032
|
category,
|
|
@@ -16175,6 +16035,7 @@ var ProcedureService = class extends BaseService {
|
|
|
16175
16035
|
product: consultationProduct,
|
|
16176
16036
|
// Use placeholder product
|
|
16177
16037
|
productsMetadata: transformedProductsMetadata,
|
|
16038
|
+
// Use transformed data, not original
|
|
16178
16039
|
blockingConditions: technology.blockingConditions,
|
|
16179
16040
|
contraindications: technology.contraindications || [],
|
|
16180
16041
|
contraindicationIds: ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [],
|