@blackcode_sa/metaestetics-api 1.7.27 → 1.7.28
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 +13 -1
- package/dist/admin/index.d.ts +13 -1
- package/dist/admin/index.js +137 -6
- package/dist/admin/index.mjs +137 -6
- package/dist/backoffice/index.d.mts +1 -0
- package/dist/backoffice/index.d.ts +1 -0
- package/dist/index.d.mts +182 -145
- package/dist/index.d.ts +182 -145
- package/dist/index.js +235 -1
- package/dist/index.mjs +235 -1
- package/package.json +1 -1
- package/src/admin/aggregation/procedure/procedure.aggregation.service.ts +202 -8
- package/src/services/practitioner/practitioner.service.ts +178 -1
- package/src/services/procedure/procedure.service.ts +141 -0
- package/src/types/practitioner/index.ts +3 -0
- package/src/validations/practitioner.schema.ts +3 -0
|
@@ -35,8 +35,14 @@ export class ProcedureAggregationService {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
const procedureId = procedureSummary.id;
|
|
38
|
+
const clinicId = procedureSummary.clinicId;
|
|
39
|
+
const isFreeConsultation =
|
|
40
|
+
procedureSummary.technologyName === "free-consultation-tech";
|
|
41
|
+
|
|
38
42
|
console.log(
|
|
39
|
-
`[ProcedureAggregationService] Adding procedure ${procedureId} to practitioner ${practitionerId}
|
|
43
|
+
`[ProcedureAggregationService] Adding procedure ${procedureId} to practitioner ${practitionerId}. ${
|
|
44
|
+
isFreeConsultation ? "(Free Consultation)" : ""
|
|
45
|
+
}`
|
|
40
46
|
);
|
|
41
47
|
|
|
42
48
|
const practitionerRef = this.db
|
|
@@ -44,11 +50,54 @@ export class ProcedureAggregationService {
|
|
|
44
50
|
.doc(practitionerId);
|
|
45
51
|
|
|
46
52
|
try {
|
|
47
|
-
|
|
53
|
+
// Prepare the basic update data
|
|
54
|
+
const updateData: any = {
|
|
48
55
|
procedureIds: admin.firestore.FieldValue.arrayUnion(procedureId),
|
|
49
56
|
proceduresInfo: admin.firestore.FieldValue.arrayUnion(procedureSummary),
|
|
50
57
|
updatedAt: admin.firestore.FieldValue.serverTimestamp(),
|
|
51
|
-
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// If this is a free consultation, we need to update the freeConsultations map
|
|
61
|
+
if (isFreeConsultation) {
|
|
62
|
+
await this.db.runTransaction(async (transaction) => {
|
|
63
|
+
const practitionerDoc = await transaction.get(practitionerRef);
|
|
64
|
+
if (!practitionerDoc.exists) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
`Practitioner ${practitionerId} does not exist for adding free consultation`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const practitionerData = practitionerDoc.data();
|
|
71
|
+
const currentFreeConsultations =
|
|
72
|
+
practitionerData?.freeConsultations || {};
|
|
73
|
+
|
|
74
|
+
// Check if there's already a free consultation for this clinic
|
|
75
|
+
if (currentFreeConsultations[clinicId]) {
|
|
76
|
+
console.log(
|
|
77
|
+
`[ProcedureAggregationService] Warning: Clinic ${clinicId} already has a free consultation ${currentFreeConsultations[clinicId]}. Replacing with new one ${procedureId}.`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Set the single procedure ID for this clinic (replaces any existing one)
|
|
82
|
+
const updatedFreeConsultations = {
|
|
83
|
+
...currentFreeConsultations,
|
|
84
|
+
[clinicId]: procedureId,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// Apply all updates including freeConsultations
|
|
88
|
+
transaction.update(practitionerRef, {
|
|
89
|
+
...updateData,
|
|
90
|
+
freeConsultations: updatedFreeConsultations,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
console.log(
|
|
94
|
+
`[ProcedureAggregationService] Set free consultation ${procedureId} for practitioner ${practitionerId} at clinic ${clinicId}`
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
} else {
|
|
98
|
+
// For regular procedures, just do the standard update
|
|
99
|
+
await practitionerRef.update(updateData);
|
|
100
|
+
}
|
|
52
101
|
|
|
53
102
|
console.log(
|
|
54
103
|
`[ProcedureAggregationService] Successfully added procedure ${procedureId} to practitioner ${practitionerId}.`
|
|
@@ -374,11 +423,13 @@ export class ProcedureAggregationService {
|
|
|
374
423
|
* Removes procedure from a practitioner when a procedure is deleted or inactivated
|
|
375
424
|
* @param practitionerId - ID of the practitioner who performs the procedure
|
|
376
425
|
* @param procedureId - ID of the procedure
|
|
426
|
+
* @param clinicId - Optional clinic ID for free consultation removal
|
|
377
427
|
* @returns {Promise<void>}
|
|
378
428
|
*/
|
|
379
429
|
async removeProcedureFromPractitioner(
|
|
380
430
|
practitionerId: string,
|
|
381
|
-
procedureId: string
|
|
431
|
+
procedureId: string,
|
|
432
|
+
clinicId?: string
|
|
382
433
|
): Promise<void> {
|
|
383
434
|
if (!practitionerId || !procedureId) {
|
|
384
435
|
console.log(
|
|
@@ -414,17 +465,52 @@ export class ProcedureAggregationService {
|
|
|
414
465
|
// Get current procedures info array
|
|
415
466
|
const proceduresInfo = practitionerData.proceduresInfo || [];
|
|
416
467
|
|
|
468
|
+
// Find the procedure being removed to check if it's a free consultation
|
|
469
|
+
const procedureBeingRemoved = proceduresInfo.find(
|
|
470
|
+
(p: any) => p.id === procedureId
|
|
471
|
+
);
|
|
472
|
+
|
|
473
|
+
const isFreeConsultation =
|
|
474
|
+
procedureBeingRemoved?.technologyName === "free-consultation-tech";
|
|
475
|
+
const procedureClinicId = clinicId || procedureBeingRemoved?.clinicId;
|
|
476
|
+
|
|
417
477
|
// Remove the procedure summary
|
|
418
478
|
const updatedProceduresInfo = proceduresInfo.filter(
|
|
419
|
-
(p:
|
|
479
|
+
(p: any) => p.id !== procedureId
|
|
420
480
|
);
|
|
421
481
|
|
|
422
|
-
//
|
|
423
|
-
|
|
482
|
+
// Prepare update data
|
|
483
|
+
const updateData: any = {
|
|
424
484
|
procedureIds: admin.firestore.FieldValue.arrayRemove(procedureId),
|
|
425
485
|
proceduresInfo: updatedProceduresInfo,
|
|
426
486
|
updatedAt: admin.firestore.FieldValue.serverTimestamp(),
|
|
427
|
-
}
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
// If this is a free consultation, also remove it from the freeConsultations map
|
|
490
|
+
if (isFreeConsultation && procedureClinicId) {
|
|
491
|
+
const currentFreeConsultations =
|
|
492
|
+
practitionerData.freeConsultations || {};
|
|
493
|
+
|
|
494
|
+
// Check if this clinic's free consultation matches the procedure being removed
|
|
495
|
+
if (currentFreeConsultations[procedureClinicId] === procedureId) {
|
|
496
|
+
// Remove the clinic entry from the freeConsultations map
|
|
497
|
+
const updatedFreeConsultations = { ...currentFreeConsultations };
|
|
498
|
+
delete updatedFreeConsultations[procedureClinicId];
|
|
499
|
+
|
|
500
|
+
updateData.freeConsultations = updatedFreeConsultations;
|
|
501
|
+
|
|
502
|
+
console.log(
|
|
503
|
+
`[ProcedureAggregationService] Removed free consultation ${procedureId} from practitioner ${practitionerId} for clinic ${procedureClinicId}`
|
|
504
|
+
);
|
|
505
|
+
} else {
|
|
506
|
+
console.log(
|
|
507
|
+
`[ProcedureAggregationService] Free consultation mismatch for clinic ${procedureClinicId}: expected ${procedureId}, found ${currentFreeConsultations[procedureClinicId]}`
|
|
508
|
+
);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// Update the practitioner document
|
|
513
|
+
transaction.update(practitionerRef, updateData);
|
|
428
514
|
});
|
|
429
515
|
|
|
430
516
|
console.log(
|
|
@@ -505,4 +591,112 @@ export class ProcedureAggregationService {
|
|
|
505
591
|
throw error;
|
|
506
592
|
}
|
|
507
593
|
}
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Handles procedure status changes (activation/deactivation) specifically for free consultations
|
|
597
|
+
* @param practitionerId - ID of the practitioner who performs the procedure
|
|
598
|
+
* @param procedureId - ID of the procedure
|
|
599
|
+
* @param clinicId - ID of the clinic where the procedure is performed
|
|
600
|
+
* @param isActive - New active status of the procedure
|
|
601
|
+
* @param technologyName - Technology name of the procedure (to check if it's a free consultation)
|
|
602
|
+
* @returns {Promise<void>}
|
|
603
|
+
*/
|
|
604
|
+
async handleFreeConsultationStatusChange(
|
|
605
|
+
practitionerId: string,
|
|
606
|
+
procedureId: string,
|
|
607
|
+
clinicId: string,
|
|
608
|
+
isActive: boolean,
|
|
609
|
+
technologyName: string
|
|
610
|
+
): Promise<void> {
|
|
611
|
+
if (!practitionerId || !procedureId || !clinicId) {
|
|
612
|
+
console.log(
|
|
613
|
+
"[ProcedureAggregationService] Missing required parameters for handling free consultation status change. Skipping."
|
|
614
|
+
);
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// Only handle free consultations
|
|
619
|
+
if (technologyName !== "free-consultation-tech") {
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
console.log(
|
|
624
|
+
`[ProcedureAggregationService] Handling free consultation status change: procedure ${procedureId} for practitioner ${practitionerId} in clinic ${clinicId}. New status: ${
|
|
625
|
+
isActive ? "active" : "inactive"
|
|
626
|
+
}`
|
|
627
|
+
);
|
|
628
|
+
|
|
629
|
+
const practitionerRef = this.db
|
|
630
|
+
.collection(PRACTITIONERS_COLLECTION)
|
|
631
|
+
.doc(practitionerId);
|
|
632
|
+
|
|
633
|
+
try {
|
|
634
|
+
await this.db.runTransaction(async (transaction) => {
|
|
635
|
+
const practitionerDoc = await transaction.get(practitionerRef);
|
|
636
|
+
if (!practitionerDoc.exists) {
|
|
637
|
+
throw new Error(
|
|
638
|
+
`Practitioner ${practitionerId} does not exist for free consultation status change`
|
|
639
|
+
);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
const practitionerData = practitionerDoc.data();
|
|
643
|
+
if (!practitionerData) {
|
|
644
|
+
throw new Error(
|
|
645
|
+
`Practitioner ${practitionerId} data is empty for free consultation status change`
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
const currentFreeConsultations =
|
|
650
|
+
practitionerData.freeConsultations || {};
|
|
651
|
+
let updatedFreeConsultations = { ...currentFreeConsultations };
|
|
652
|
+
|
|
653
|
+
if (isActive) {
|
|
654
|
+
// If procedure is being activated, set it as the free consultation for this clinic
|
|
655
|
+
if (
|
|
656
|
+
currentFreeConsultations[clinicId] &&
|
|
657
|
+
currentFreeConsultations[clinicId] !== procedureId
|
|
658
|
+
) {
|
|
659
|
+
console.log(
|
|
660
|
+
`[ProcedureAggregationService] Warning: Clinic ${clinicId} already has a different free consultation ${currentFreeConsultations[clinicId]}. Replacing with ${procedureId}.`
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
updatedFreeConsultations[clinicId] = procedureId;
|
|
665
|
+
|
|
666
|
+
console.log(
|
|
667
|
+
`[ProcedureAggregationService] Set free consultation ${procedureId} for practitioner ${practitionerId} at clinic ${clinicId} (activated)`
|
|
668
|
+
);
|
|
669
|
+
} else {
|
|
670
|
+
// If procedure is being deactivated, remove it from the free consultations map
|
|
671
|
+
if (currentFreeConsultations[clinicId] === procedureId) {
|
|
672
|
+
delete updatedFreeConsultations[clinicId];
|
|
673
|
+
|
|
674
|
+
console.log(
|
|
675
|
+
`[ProcedureAggregationService] Removed free consultation ${procedureId} from practitioner ${practitionerId} for clinic ${clinicId} (deactivated)`
|
|
676
|
+
);
|
|
677
|
+
} else {
|
|
678
|
+
console.log(
|
|
679
|
+
`[ProcedureAggregationService] Free consultation mismatch for clinic ${clinicId}: expected ${procedureId}, found ${currentFreeConsultations[clinicId]}`
|
|
680
|
+
);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// Update the practitioner document with the new freeConsultations map
|
|
685
|
+
transaction.update(practitionerRef, {
|
|
686
|
+
freeConsultations: updatedFreeConsultations,
|
|
687
|
+
updatedAt: admin.firestore.FieldValue.serverTimestamp(),
|
|
688
|
+
});
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
console.log(
|
|
692
|
+
`[ProcedureAggregationService] Successfully handled free consultation status change for procedure ${procedureId} of practitioner ${practitionerId}.`
|
|
693
|
+
);
|
|
694
|
+
} catch (error) {
|
|
695
|
+
console.error(
|
|
696
|
+
`[ProcedureAggregationService] Error handling free consultation status change for procedure ${procedureId} of practitioner ${practitionerId}:`,
|
|
697
|
+
error
|
|
698
|
+
);
|
|
699
|
+
throw error;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
508
702
|
}
|
|
@@ -55,19 +55,29 @@ import { distanceBetween } from "geofire-common";
|
|
|
55
55
|
import { CertificationSpecialty } from "../../backoffice/types/static/certification.types";
|
|
56
56
|
import { Clinic, DoctorInfo, CLINICS_COLLECTION } from "../../types/clinic";
|
|
57
57
|
import { ClinicInfo } from "../../types/profile";
|
|
58
|
+
import { ProcedureService } from "../procedure/procedure.service";
|
|
59
|
+
import { ProcedureFamily } from "../../backoffice/types/static/procedure-family.types";
|
|
60
|
+
import {
|
|
61
|
+
Currency,
|
|
62
|
+
PricingMeasure,
|
|
63
|
+
} from "../../backoffice/types/static/pricing.types";
|
|
64
|
+
import { CreateProcedureData } from "../../types/procedure";
|
|
58
65
|
|
|
59
66
|
export class PractitionerService extends BaseService {
|
|
60
67
|
private clinicService?: ClinicService;
|
|
61
68
|
private mediaService: MediaService;
|
|
69
|
+
private procedureService?: ProcedureService;
|
|
62
70
|
|
|
63
71
|
constructor(
|
|
64
72
|
db: Firestore,
|
|
65
73
|
auth: Auth,
|
|
66
74
|
app: FirebaseApp,
|
|
67
|
-
clinicService?: ClinicService
|
|
75
|
+
clinicService?: ClinicService,
|
|
76
|
+
procedureService?: ProcedureService
|
|
68
77
|
) {
|
|
69
78
|
super(db, auth, app);
|
|
70
79
|
this.clinicService = clinicService;
|
|
80
|
+
this.procedureService = procedureService;
|
|
71
81
|
this.mediaService = new MediaService(db, auth, app);
|
|
72
82
|
}
|
|
73
83
|
|
|
@@ -78,10 +88,21 @@ export class PractitionerService extends BaseService {
|
|
|
78
88
|
return this.clinicService;
|
|
79
89
|
}
|
|
80
90
|
|
|
91
|
+
private getProcedureService(): ProcedureService {
|
|
92
|
+
if (!this.procedureService) {
|
|
93
|
+
throw new Error("Procedure service not initialized!");
|
|
94
|
+
}
|
|
95
|
+
return this.procedureService;
|
|
96
|
+
}
|
|
97
|
+
|
|
81
98
|
setClinicService(clinicService: ClinicService): void {
|
|
82
99
|
this.clinicService = clinicService;
|
|
83
100
|
}
|
|
84
101
|
|
|
102
|
+
setProcedureService(procedureService: ProcedureService): void {
|
|
103
|
+
this.procedureService = procedureService;
|
|
104
|
+
}
|
|
105
|
+
|
|
85
106
|
/**
|
|
86
107
|
* Handles profile photo upload for practitioners
|
|
87
108
|
* @param profilePhoto - MediaResource (File, Blob, or URL string)
|
|
@@ -1183,4 +1204,160 @@ export class PractitionerService extends BaseService {
|
|
|
1183
1204
|
throw error;
|
|
1184
1205
|
}
|
|
1185
1206
|
}
|
|
1207
|
+
|
|
1208
|
+
/**
|
|
1209
|
+
* Enables free consultation for a practitioner in a specific clinic
|
|
1210
|
+
* Creates a free consultation procedure with hardcoded parameters
|
|
1211
|
+
* @param practitionerId - ID of the practitioner
|
|
1212
|
+
* @param clinicId - ID of the clinic
|
|
1213
|
+
* @returns The created consultation procedure
|
|
1214
|
+
*/
|
|
1215
|
+
async EnableFreeConsultation(
|
|
1216
|
+
practitionerId: string,
|
|
1217
|
+
clinicId: string
|
|
1218
|
+
): Promise<void> {
|
|
1219
|
+
try {
|
|
1220
|
+
// Validate that practitioner exists and is active
|
|
1221
|
+
const practitioner = await this.getPractitioner(practitionerId);
|
|
1222
|
+
if (!practitioner) {
|
|
1223
|
+
throw new Error(`Practitioner ${practitionerId} not found`);
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
if (
|
|
1227
|
+
!practitioner.isActive ||
|
|
1228
|
+
practitioner.status !== PractitionerStatus.ACTIVE
|
|
1229
|
+
) {
|
|
1230
|
+
throw new Error(`Practitioner ${practitionerId} is not active`);
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
// Validate that clinic exists
|
|
1234
|
+
const clinic = await this.getClinicService().getClinic(clinicId);
|
|
1235
|
+
if (!clinic) {
|
|
1236
|
+
throw new Error(`Clinic ${clinicId} not found`);
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
// Check if practitioner is associated with this clinic
|
|
1240
|
+
if (!practitioner.clinics.includes(clinicId)) {
|
|
1241
|
+
throw new Error(
|
|
1242
|
+
`Practitioner ${practitionerId} is not associated with clinic ${clinicId}`
|
|
1243
|
+
);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
// Check if free consultation already exists for this practitioner in this clinic
|
|
1247
|
+
const existingProcedures =
|
|
1248
|
+
await this.getProcedureService().getProceduresByPractitioner(
|
|
1249
|
+
practitionerId
|
|
1250
|
+
);
|
|
1251
|
+
const existingConsultation = existingProcedures.find(
|
|
1252
|
+
(procedure) =>
|
|
1253
|
+
procedure.name === "Free Consultation" &&
|
|
1254
|
+
procedure.clinicBranchId === clinicId &&
|
|
1255
|
+
procedure.isActive
|
|
1256
|
+
);
|
|
1257
|
+
|
|
1258
|
+
if (existingConsultation) {
|
|
1259
|
+
console.log(
|
|
1260
|
+
`Free consultation already exists for practitioner ${practitionerId} in clinic ${clinicId}`
|
|
1261
|
+
);
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
// Create procedure data for free consultation (without productId)
|
|
1266
|
+
const consultationData: Omit<CreateProcedureData, "productId"> = {
|
|
1267
|
+
name: "Free Consultation",
|
|
1268
|
+
description:
|
|
1269
|
+
"Free initial consultation to discuss treatment options and assess patient needs.",
|
|
1270
|
+
family: ProcedureFamily.AESTHETICS,
|
|
1271
|
+
categoryId: "consultation",
|
|
1272
|
+
subcategoryId: "free-consultation",
|
|
1273
|
+
technologyId: "free-consultation-tech",
|
|
1274
|
+
price: 0,
|
|
1275
|
+
currency: Currency.EUR,
|
|
1276
|
+
pricingMeasure: PricingMeasure.PER_SESSION,
|
|
1277
|
+
duration: 30, // 30 minutes consultation
|
|
1278
|
+
practitionerId: practitionerId,
|
|
1279
|
+
clinicBranchId: clinicId,
|
|
1280
|
+
photos: [], // No photos for consultation
|
|
1281
|
+
};
|
|
1282
|
+
|
|
1283
|
+
// Create the consultation procedure using the special method
|
|
1284
|
+
await this.getProcedureService().createConsultationProcedure(
|
|
1285
|
+
consultationData
|
|
1286
|
+
);
|
|
1287
|
+
|
|
1288
|
+
console.log(
|
|
1289
|
+
`Free consultation enabled for practitioner ${practitionerId} in clinic ${clinicId}`
|
|
1290
|
+
);
|
|
1291
|
+
} catch (error) {
|
|
1292
|
+
console.error(
|
|
1293
|
+
`Error enabling free consultation for practitioner ${practitionerId} in clinic ${clinicId}:`,
|
|
1294
|
+
error
|
|
1295
|
+
);
|
|
1296
|
+
throw error;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
/**
|
|
1301
|
+
* Disables free consultation for a practitioner in a specific clinic
|
|
1302
|
+
* Finds and deactivates the existing free consultation procedure
|
|
1303
|
+
* @param practitionerId - ID of the practitioner
|
|
1304
|
+
* @param clinicId - ID of the clinic
|
|
1305
|
+
*/
|
|
1306
|
+
async DisableFreeConsultation(
|
|
1307
|
+
practitionerId: string,
|
|
1308
|
+
clinicId: string
|
|
1309
|
+
): Promise<void> {
|
|
1310
|
+
try {
|
|
1311
|
+
// Validate that practitioner exists
|
|
1312
|
+
const practitioner = await this.getPractitioner(practitionerId);
|
|
1313
|
+
if (!practitioner) {
|
|
1314
|
+
throw new Error(`Practitioner ${practitionerId} not found`);
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
// Validate that clinic exists
|
|
1318
|
+
const clinic = await this.getClinicService().getClinic(clinicId);
|
|
1319
|
+
if (!clinic) {
|
|
1320
|
+
throw new Error(`Clinic ${clinicId} not found`);
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
// Check if practitioner is associated with this clinic
|
|
1324
|
+
if (!practitioner.clinics.includes(clinicId)) {
|
|
1325
|
+
throw new Error(
|
|
1326
|
+
`Practitioner ${practitionerId} is not associated with clinic ${clinicId}`
|
|
1327
|
+
);
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
// Find the free consultation procedure for this practitioner in this clinic
|
|
1331
|
+
const existingProcedures =
|
|
1332
|
+
await this.getProcedureService().getProceduresByPractitioner(
|
|
1333
|
+
practitionerId
|
|
1334
|
+
);
|
|
1335
|
+
const freeConsultation = existingProcedures.find(
|
|
1336
|
+
(procedure) =>
|
|
1337
|
+
procedure.name === "Free Consultation" &&
|
|
1338
|
+
procedure.clinicBranchId === clinicId &&
|
|
1339
|
+
procedure.isActive
|
|
1340
|
+
);
|
|
1341
|
+
|
|
1342
|
+
if (!freeConsultation) {
|
|
1343
|
+
console.log(
|
|
1344
|
+
`No active free consultation found for practitioner ${practitionerId} in clinic ${clinicId}`
|
|
1345
|
+
);
|
|
1346
|
+
return;
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
// Deactivate the consultation procedure
|
|
1350
|
+
await this.getProcedureService().deactivateProcedure(freeConsultation.id);
|
|
1351
|
+
|
|
1352
|
+
console.log(
|
|
1353
|
+
`Free consultation disabled for practitioner ${practitionerId} in clinic ${clinicId}`
|
|
1354
|
+
);
|
|
1355
|
+
} catch (error) {
|
|
1356
|
+
console.error(
|
|
1357
|
+
`Error disabling free consultation for practitioner ${practitionerId} in clinic ${clinicId}:`,
|
|
1358
|
+
error
|
|
1359
|
+
);
|
|
1360
|
+
throw error;
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1186
1363
|
}
|
|
@@ -1001,4 +1001,145 @@ export class ProcedureService extends BaseService {
|
|
|
1001
1001
|
|
|
1002
1002
|
return filteredProcedures;
|
|
1003
1003
|
}
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* Creates a consultation procedure without requiring a product
|
|
1007
|
+
* This is a special method for consultation procedures that don't use products
|
|
1008
|
+
* @param data - The data for creating a consultation procedure (without productId)
|
|
1009
|
+
* @returns The created procedure
|
|
1010
|
+
*/
|
|
1011
|
+
async createConsultationProcedure(
|
|
1012
|
+
data: Omit<CreateProcedureData, "productId">
|
|
1013
|
+
): Promise<Procedure> {
|
|
1014
|
+
// Generate procedure ID first so we can use it for media uploads
|
|
1015
|
+
const procedureId = this.generateId();
|
|
1016
|
+
|
|
1017
|
+
// Get references to related entities (Category, Subcategory, Technology)
|
|
1018
|
+
// For consultation, we don't need a product
|
|
1019
|
+
const [category, subcategory, technology] = await Promise.all([
|
|
1020
|
+
this.categoryService.getById(data.categoryId),
|
|
1021
|
+
this.subcategoryService.getById(data.categoryId, data.subcategoryId),
|
|
1022
|
+
this.technologyService.getById(data.technologyId),
|
|
1023
|
+
]);
|
|
1024
|
+
|
|
1025
|
+
if (!category || !subcategory || !technology) {
|
|
1026
|
+
throw new Error("One or more required base entities not found");
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
// Get clinic and practitioner information for aggregation
|
|
1030
|
+
const clinicRef = doc(this.db, CLINICS_COLLECTION, data.clinicBranchId);
|
|
1031
|
+
const clinicSnapshot = await getDoc(clinicRef);
|
|
1032
|
+
if (!clinicSnapshot.exists()) {
|
|
1033
|
+
throw new Error(`Clinic with ID ${data.clinicBranchId} not found`);
|
|
1034
|
+
}
|
|
1035
|
+
const clinic = clinicSnapshot.data() as Clinic;
|
|
1036
|
+
|
|
1037
|
+
const practitionerRef = doc(
|
|
1038
|
+
this.db,
|
|
1039
|
+
PRACTITIONERS_COLLECTION,
|
|
1040
|
+
data.practitionerId
|
|
1041
|
+
);
|
|
1042
|
+
const practitionerSnapshot = await getDoc(practitionerRef);
|
|
1043
|
+
if (!practitionerSnapshot.exists()) {
|
|
1044
|
+
throw new Error(`Practitioner with ID ${data.practitionerId} not found`);
|
|
1045
|
+
}
|
|
1046
|
+
const practitioner = practitionerSnapshot.data() as Practitioner;
|
|
1047
|
+
|
|
1048
|
+
// Process photos if provided
|
|
1049
|
+
let processedPhotos: string[] = [];
|
|
1050
|
+
if (data.photos && data.photos.length > 0) {
|
|
1051
|
+
processedPhotos = await this.processMediaArray(
|
|
1052
|
+
data.photos,
|
|
1053
|
+
procedureId,
|
|
1054
|
+
"procedure-photos"
|
|
1055
|
+
);
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
// Create aggregated clinic info for the procedure document
|
|
1059
|
+
const clinicInfo = {
|
|
1060
|
+
id: clinicSnapshot.id,
|
|
1061
|
+
name: clinic.name,
|
|
1062
|
+
description: clinic.description || "",
|
|
1063
|
+
featuredPhoto:
|
|
1064
|
+
clinic.featuredPhotos && clinic.featuredPhotos.length > 0
|
|
1065
|
+
? typeof clinic.featuredPhotos[0] === "string"
|
|
1066
|
+
? clinic.featuredPhotos[0]
|
|
1067
|
+
: ""
|
|
1068
|
+
: typeof clinic.coverPhoto === "string"
|
|
1069
|
+
? clinic.coverPhoto
|
|
1070
|
+
: "",
|
|
1071
|
+
location: clinic.location,
|
|
1072
|
+
contactInfo: clinic.contactInfo,
|
|
1073
|
+
};
|
|
1074
|
+
|
|
1075
|
+
// Create aggregated doctor info for the procedure document
|
|
1076
|
+
const doctorInfo = {
|
|
1077
|
+
id: practitionerSnapshot.id,
|
|
1078
|
+
name: `${practitioner.basicInfo.firstName} ${practitioner.basicInfo.lastName}`,
|
|
1079
|
+
description: practitioner.basicInfo.bio || "",
|
|
1080
|
+
photo:
|
|
1081
|
+
typeof practitioner.basicInfo.profileImageUrl === "string"
|
|
1082
|
+
? practitioner.basicInfo.profileImageUrl
|
|
1083
|
+
: "",
|
|
1084
|
+
rating: practitioner.reviewInfo?.averageRating || 0,
|
|
1085
|
+
services: practitioner.procedures || [],
|
|
1086
|
+
};
|
|
1087
|
+
|
|
1088
|
+
// Create a placeholder product for consultation procedures
|
|
1089
|
+
const consultationProduct: Product = {
|
|
1090
|
+
id: "consultation-no-product",
|
|
1091
|
+
name: "No Product Required",
|
|
1092
|
+
description: "Consultation procedures do not require specific products",
|
|
1093
|
+
brandId: "consultation-brand",
|
|
1094
|
+
brandName: "Consultation",
|
|
1095
|
+
technologyId: data.technologyId,
|
|
1096
|
+
technologyName: technology.name,
|
|
1097
|
+
isActive: true,
|
|
1098
|
+
createdAt: new Date(),
|
|
1099
|
+
updatedAt: new Date(),
|
|
1100
|
+
};
|
|
1101
|
+
|
|
1102
|
+
// Create the procedure object
|
|
1103
|
+
const newProcedure: Omit<Procedure, "createdAt" | "updatedAt"> = {
|
|
1104
|
+
id: procedureId,
|
|
1105
|
+
...data,
|
|
1106
|
+
photos: processedPhotos,
|
|
1107
|
+
category,
|
|
1108
|
+
subcategory,
|
|
1109
|
+
technology,
|
|
1110
|
+
product: consultationProduct, // Use placeholder product
|
|
1111
|
+
blockingConditions: technology.blockingConditions,
|
|
1112
|
+
contraindications: technology.contraindications || [],
|
|
1113
|
+
treatmentBenefits: technology.benefits,
|
|
1114
|
+
preRequirements: technology.requirements.pre,
|
|
1115
|
+
postRequirements: technology.requirements.post,
|
|
1116
|
+
certificationRequirement: technology.certificationRequirement,
|
|
1117
|
+
documentationTemplates: technology?.documentationTemplates || [],
|
|
1118
|
+
clinicInfo,
|
|
1119
|
+
doctorInfo,
|
|
1120
|
+
reviewInfo: {
|
|
1121
|
+
totalReviews: 0,
|
|
1122
|
+
averageRating: 0,
|
|
1123
|
+
effectivenessOfTreatment: 0,
|
|
1124
|
+
outcomeExplanation: 0,
|
|
1125
|
+
painManagement: 0,
|
|
1126
|
+
followUpCare: 0,
|
|
1127
|
+
valueForMoney: 0,
|
|
1128
|
+
recommendationPercentage: 0,
|
|
1129
|
+
},
|
|
1130
|
+
isActive: true,
|
|
1131
|
+
};
|
|
1132
|
+
|
|
1133
|
+
// Create the procedure document
|
|
1134
|
+
const procedureRef = doc(this.db, PROCEDURES_COLLECTION, procedureId);
|
|
1135
|
+
await setDoc(procedureRef, {
|
|
1136
|
+
...newProcedure,
|
|
1137
|
+
createdAt: serverTimestamp(),
|
|
1138
|
+
updatedAt: serverTimestamp(),
|
|
1139
|
+
});
|
|
1140
|
+
|
|
1141
|
+
// Return the created procedure (fetch again to get server timestamps)
|
|
1142
|
+
const savedDoc = await getDoc(procedureRef);
|
|
1143
|
+
return savedDoc.data() as Procedure;
|
|
1144
|
+
}
|
|
1004
1145
|
}
|
|
@@ -94,6 +94,7 @@ export interface Practitioner {
|
|
|
94
94
|
clinicWorkingHours: PractitionerClinicWorkingHours[]; // Radno vreme za svaku kliniku
|
|
95
95
|
clinicsInfo: ClinicInfo[]; // Aggregated clinic information
|
|
96
96
|
procedures: string[]; // Reference na procedure koje izvodi
|
|
97
|
+
freeConsultations?: Record<string, string> | null; // Map of clinic IDs to procedure ID for free consultations (one per clinic)
|
|
97
98
|
proceduresInfo: ProcedureSummaryInfo[]; // Aggregated procedure information
|
|
98
99
|
reviewInfo: PractitionerReviewInfo; // Aggregated review information
|
|
99
100
|
isActive: boolean;
|
|
@@ -113,6 +114,7 @@ export interface CreatePractitionerData {
|
|
|
113
114
|
clinics?: string[];
|
|
114
115
|
clinicWorkingHours?: PractitionerClinicWorkingHours[];
|
|
115
116
|
clinicsInfo?: ClinicInfo[];
|
|
117
|
+
freeConsultations?: Record<string, string> | null;
|
|
116
118
|
isActive: boolean;
|
|
117
119
|
isVerified: boolean;
|
|
118
120
|
status?: PractitionerStatus;
|
|
@@ -127,6 +129,7 @@ export interface CreateDraftPractitionerData {
|
|
|
127
129
|
clinics?: string[];
|
|
128
130
|
clinicWorkingHours?: PractitionerClinicWorkingHours[];
|
|
129
131
|
clinicsInfo?: ClinicInfo[];
|
|
132
|
+
freeConsultations?: Record<string, string> | null;
|
|
130
133
|
isActive?: boolean;
|
|
131
134
|
isVerified?: boolean;
|
|
132
135
|
}
|
|
@@ -125,6 +125,7 @@ export const practitionerSchema = z.object({
|
|
|
125
125
|
clinicWorkingHours: z.array(practitionerClinicWorkingHoursSchema),
|
|
126
126
|
clinicsInfo: z.array(clinicInfoSchema),
|
|
127
127
|
procedures: z.array(z.string()),
|
|
128
|
+
freeConsultations: z.record(z.string(), z.string()).optional().nullable(),
|
|
128
129
|
proceduresInfo: z.array(procedureSummaryInfoSchema),
|
|
129
130
|
reviewInfo: practitionerReviewInfoSchema,
|
|
130
131
|
isActive: z.boolean(),
|
|
@@ -144,6 +145,7 @@ export const createPractitionerSchema = z.object({
|
|
|
144
145
|
clinics: z.array(z.string()).optional(),
|
|
145
146
|
clinicWorkingHours: z.array(practitionerClinicWorkingHoursSchema).optional(),
|
|
146
147
|
clinicsInfo: z.array(clinicInfoSchema).optional(),
|
|
148
|
+
freeConsultations: z.record(z.string(), z.string()).optional().nullable(),
|
|
147
149
|
proceduresInfo: z.array(procedureSummaryInfoSchema).optional(),
|
|
148
150
|
isActive: z.boolean(),
|
|
149
151
|
isVerified: z.boolean(),
|
|
@@ -159,6 +161,7 @@ export const createDraftPractitionerSchema = z.object({
|
|
|
159
161
|
clinics: z.array(z.string()).optional(),
|
|
160
162
|
clinicWorkingHours: z.array(practitionerClinicWorkingHoursSchema).optional(),
|
|
161
163
|
clinicsInfo: z.array(clinicInfoSchema).optional(),
|
|
164
|
+
freeConsultations: z.record(z.string(), z.string()).optional().nullable(),
|
|
162
165
|
proceduresInfo: z.array(procedureSummaryInfoSchema).optional(),
|
|
163
166
|
isActive: z.boolean().optional().default(false),
|
|
164
167
|
isVerified: z.boolean().optional().default(false),
|