@blackcode_sa/metaestetics-api 1.13.2 → 1.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +53 -0
- package/dist/index.mjs +53 -0
- package/package.json +1 -1
- package/src/services/procedure/procedure.service.ts +64 -3
package/dist/index.js
CHANGED
|
@@ -20035,6 +20035,25 @@ var ProcedureService = class extends BaseService {
|
|
|
20035
20035
|
throw new Error(`Practitioner with ID ${validatedData.practitionerId} not found`);
|
|
20036
20036
|
}
|
|
20037
20037
|
const practitioner = practitionerSnapshot.data();
|
|
20038
|
+
const existingProceduresQuery = (0, import_firestore58.query)(
|
|
20039
|
+
(0, import_firestore58.collection)(this.db, PROCEDURES_COLLECTION),
|
|
20040
|
+
(0, import_firestore58.where)("practitionerId", "==", validatedData.practitionerId),
|
|
20041
|
+
(0, import_firestore58.where)("clinicBranchId", "==", validatedData.clinicBranchId),
|
|
20042
|
+
(0, import_firestore58.where)("isActive", "==", true)
|
|
20043
|
+
);
|
|
20044
|
+
const existingProceduresSnapshot = await (0, import_firestore58.getDocs)(existingProceduresQuery);
|
|
20045
|
+
const existingProcedures = existingProceduresSnapshot.docs.map((doc47) => doc47.data());
|
|
20046
|
+
const hasSameTechnology = existingProcedures.some(
|
|
20047
|
+
(proc) => {
|
|
20048
|
+
var _a2;
|
|
20049
|
+
return ((_a2 = proc.technology) == null ? void 0 : _a2.id) === validatedData.technologyId;
|
|
20050
|
+
}
|
|
20051
|
+
);
|
|
20052
|
+
if (hasSameTechnology) {
|
|
20053
|
+
throw new Error(
|
|
20054
|
+
`Practitioner ${practitioner.basicInfo.firstName} ${practitioner.basicInfo.lastName} already has a procedure with technology "${(technology == null ? void 0 : technology.name) || validatedData.technologyId}" in this clinic branch`
|
|
20055
|
+
);
|
|
20056
|
+
}
|
|
20038
20057
|
let processedPhotos = [];
|
|
20039
20058
|
if (validatedData.photos && validatedData.photos.length > 0) {
|
|
20040
20059
|
processedPhotos = await this.processMediaArray(
|
|
@@ -20455,6 +20474,40 @@ var ProcedureService = class extends BaseService {
|
|
|
20455
20474
|
const notFoundIds = practitionerIds.filter((id) => !foundIds.includes(id));
|
|
20456
20475
|
throw new Error(`The following practitioners were not found: ${notFoundIds.join(", ")}`);
|
|
20457
20476
|
}
|
|
20477
|
+
const duplicatePractitioners = [];
|
|
20478
|
+
const duplicateChecks = await Promise.all(
|
|
20479
|
+
practitionerIds.map(async (practitionerId) => {
|
|
20480
|
+
const existingProceduresQuery = (0, import_firestore58.query)(
|
|
20481
|
+
(0, import_firestore58.collection)(this.db, PROCEDURES_COLLECTION),
|
|
20482
|
+
(0, import_firestore58.where)("practitionerId", "==", practitionerId),
|
|
20483
|
+
(0, import_firestore58.where)("clinicBranchId", "==", validatedData.clinicBranchId),
|
|
20484
|
+
(0, import_firestore58.where)("isActive", "==", true)
|
|
20485
|
+
);
|
|
20486
|
+
const existingProceduresSnapshot = await (0, import_firestore58.getDocs)(existingProceduresQuery);
|
|
20487
|
+
const existingProcedures = existingProceduresSnapshot.docs.map((doc47) => doc47.data());
|
|
20488
|
+
const hasSameTechnology = existingProcedures.some(
|
|
20489
|
+
(proc) => {
|
|
20490
|
+
var _a2;
|
|
20491
|
+
return ((_a2 = proc.technology) == null ? void 0 : _a2.id) === validatedData.technologyId;
|
|
20492
|
+
}
|
|
20493
|
+
);
|
|
20494
|
+
return { practitionerId, hasSameTechnology };
|
|
20495
|
+
})
|
|
20496
|
+
);
|
|
20497
|
+
duplicateChecks.forEach(({ practitionerId, hasSameTechnology }) => {
|
|
20498
|
+
if (hasSameTechnology) {
|
|
20499
|
+
duplicatePractitioners.push(practitionerId);
|
|
20500
|
+
}
|
|
20501
|
+
});
|
|
20502
|
+
if (duplicatePractitioners.length > 0) {
|
|
20503
|
+
const duplicateNames = duplicatePractitioners.map((id) => {
|
|
20504
|
+
const practitioner = practitionersMap.get(id);
|
|
20505
|
+
return `${practitioner.basicInfo.firstName} ${practitioner.basicInfo.lastName}`;
|
|
20506
|
+
}).join(", ");
|
|
20507
|
+
throw new Error(
|
|
20508
|
+
`The following practitioner(s) already have a procedure with technology "${(technology == null ? void 0 : technology.name) || validatedData.technologyId}" in this clinic branch: ${duplicateNames}. Please remove them from the selection and try again.`
|
|
20509
|
+
);
|
|
20510
|
+
}
|
|
20458
20511
|
const batch = (0, import_firestore58.writeBatch)(this.db);
|
|
20459
20512
|
const createdProcedureIds = [];
|
|
20460
20513
|
const clinicInfo = {
|
package/dist/index.mjs
CHANGED
|
@@ -20271,6 +20271,25 @@ var ProcedureService = class extends BaseService {
|
|
|
20271
20271
|
throw new Error(`Practitioner with ID ${validatedData.practitionerId} not found`);
|
|
20272
20272
|
}
|
|
20273
20273
|
const practitioner = practitionerSnapshot.data();
|
|
20274
|
+
const existingProceduresQuery = query33(
|
|
20275
|
+
collection33(this.db, PROCEDURES_COLLECTION),
|
|
20276
|
+
where33("practitionerId", "==", validatedData.practitionerId),
|
|
20277
|
+
where33("clinicBranchId", "==", validatedData.clinicBranchId),
|
|
20278
|
+
where33("isActive", "==", true)
|
|
20279
|
+
);
|
|
20280
|
+
const existingProceduresSnapshot = await getDocs33(existingProceduresQuery);
|
|
20281
|
+
const existingProcedures = existingProceduresSnapshot.docs.map((doc47) => doc47.data());
|
|
20282
|
+
const hasSameTechnology = existingProcedures.some(
|
|
20283
|
+
(proc) => {
|
|
20284
|
+
var _a2;
|
|
20285
|
+
return ((_a2 = proc.technology) == null ? void 0 : _a2.id) === validatedData.technologyId;
|
|
20286
|
+
}
|
|
20287
|
+
);
|
|
20288
|
+
if (hasSameTechnology) {
|
|
20289
|
+
throw new Error(
|
|
20290
|
+
`Practitioner ${practitioner.basicInfo.firstName} ${practitioner.basicInfo.lastName} already has a procedure with technology "${(technology == null ? void 0 : technology.name) || validatedData.technologyId}" in this clinic branch`
|
|
20291
|
+
);
|
|
20292
|
+
}
|
|
20274
20293
|
let processedPhotos = [];
|
|
20275
20294
|
if (validatedData.photos && validatedData.photos.length > 0) {
|
|
20276
20295
|
processedPhotos = await this.processMediaArray(
|
|
@@ -20691,6 +20710,40 @@ var ProcedureService = class extends BaseService {
|
|
|
20691
20710
|
const notFoundIds = practitionerIds.filter((id) => !foundIds.includes(id));
|
|
20692
20711
|
throw new Error(`The following practitioners were not found: ${notFoundIds.join(", ")}`);
|
|
20693
20712
|
}
|
|
20713
|
+
const duplicatePractitioners = [];
|
|
20714
|
+
const duplicateChecks = await Promise.all(
|
|
20715
|
+
practitionerIds.map(async (practitionerId) => {
|
|
20716
|
+
const existingProceduresQuery = query33(
|
|
20717
|
+
collection33(this.db, PROCEDURES_COLLECTION),
|
|
20718
|
+
where33("practitionerId", "==", practitionerId),
|
|
20719
|
+
where33("clinicBranchId", "==", validatedData.clinicBranchId),
|
|
20720
|
+
where33("isActive", "==", true)
|
|
20721
|
+
);
|
|
20722
|
+
const existingProceduresSnapshot = await getDocs33(existingProceduresQuery);
|
|
20723
|
+
const existingProcedures = existingProceduresSnapshot.docs.map((doc47) => doc47.data());
|
|
20724
|
+
const hasSameTechnology = existingProcedures.some(
|
|
20725
|
+
(proc) => {
|
|
20726
|
+
var _a2;
|
|
20727
|
+
return ((_a2 = proc.technology) == null ? void 0 : _a2.id) === validatedData.technologyId;
|
|
20728
|
+
}
|
|
20729
|
+
);
|
|
20730
|
+
return { practitionerId, hasSameTechnology };
|
|
20731
|
+
})
|
|
20732
|
+
);
|
|
20733
|
+
duplicateChecks.forEach(({ practitionerId, hasSameTechnology }) => {
|
|
20734
|
+
if (hasSameTechnology) {
|
|
20735
|
+
duplicatePractitioners.push(practitionerId);
|
|
20736
|
+
}
|
|
20737
|
+
});
|
|
20738
|
+
if (duplicatePractitioners.length > 0) {
|
|
20739
|
+
const duplicateNames = duplicatePractitioners.map((id) => {
|
|
20740
|
+
const practitioner = practitionersMap.get(id);
|
|
20741
|
+
return `${practitioner.basicInfo.firstName} ${practitioner.basicInfo.lastName}`;
|
|
20742
|
+
}).join(", ");
|
|
20743
|
+
throw new Error(
|
|
20744
|
+
`The following practitioner(s) already have a procedure with technology "${(technology == null ? void 0 : technology.name) || validatedData.technologyId}" in this clinic branch: ${duplicateNames}. Please remove them from the selection and try again.`
|
|
20745
|
+
);
|
|
20746
|
+
}
|
|
20694
20747
|
const batch = writeBatch6(this.db);
|
|
20695
20748
|
const createdProcedureIds = [];
|
|
20696
20749
|
const clinicInfo = {
|
package/package.json
CHANGED
|
@@ -244,6 +244,25 @@ export class ProcedureService extends BaseService {
|
|
|
244
244
|
}
|
|
245
245
|
const practitioner = practitionerSnapshot.data() as Practitioner; // Assert type
|
|
246
246
|
|
|
247
|
+
// Check if practitioner already has a procedure with the same technology ID in this clinic branch
|
|
248
|
+
const existingProceduresQuery = query(
|
|
249
|
+
collection(this.db, PROCEDURES_COLLECTION),
|
|
250
|
+
where('practitionerId', '==', validatedData.practitionerId),
|
|
251
|
+
where('clinicBranchId', '==', validatedData.clinicBranchId),
|
|
252
|
+
where('isActive', '==', true)
|
|
253
|
+
);
|
|
254
|
+
const existingProceduresSnapshot = await getDocs(existingProceduresQuery);
|
|
255
|
+
const existingProcedures = existingProceduresSnapshot.docs.map(doc => doc.data() as Procedure);
|
|
256
|
+
|
|
257
|
+
const hasSameTechnology = existingProcedures.some(
|
|
258
|
+
proc => proc.technology?.id === validatedData.technologyId
|
|
259
|
+
);
|
|
260
|
+
if (hasSameTechnology) {
|
|
261
|
+
throw new Error(
|
|
262
|
+
`Practitioner ${practitioner.basicInfo.firstName} ${practitioner.basicInfo.lastName} already has a procedure with technology "${technology?.name || validatedData.technologyId}" in this clinic branch`
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
247
266
|
// Process photos if provided
|
|
248
267
|
let processedPhotos: string[] = [];
|
|
249
268
|
if (validatedData.photos && validatedData.photos.length > 0) {
|
|
@@ -787,7 +806,49 @@ export class ProcedureService extends BaseService {
|
|
|
787
806
|
throw new Error(`The following practitioners were not found: ${notFoundIds.join(', ')}`);
|
|
788
807
|
}
|
|
789
808
|
|
|
790
|
-
// 5.
|
|
809
|
+
// 5. Check for duplicates across all practitioners before creating any procedures
|
|
810
|
+
const duplicatePractitioners: string[] = [];
|
|
811
|
+
const duplicateChecks = await Promise.all(
|
|
812
|
+
practitionerIds.map(async (practitionerId) => {
|
|
813
|
+
const existingProceduresQuery = query(
|
|
814
|
+
collection(this.db, PROCEDURES_COLLECTION),
|
|
815
|
+
where('practitionerId', '==', practitionerId),
|
|
816
|
+
where('clinicBranchId', '==', validatedData.clinicBranchId),
|
|
817
|
+
where('isActive', '==', true)
|
|
818
|
+
);
|
|
819
|
+
const existingProceduresSnapshot = await getDocs(existingProceduresQuery);
|
|
820
|
+
const existingProcedures = existingProceduresSnapshot.docs.map(doc => doc.data() as Procedure);
|
|
821
|
+
|
|
822
|
+
const hasSameTechnology = existingProcedures.some(
|
|
823
|
+
proc => proc.technology?.id === validatedData.technologyId
|
|
824
|
+
);
|
|
825
|
+
|
|
826
|
+
return { practitionerId, hasSameTechnology };
|
|
827
|
+
})
|
|
828
|
+
);
|
|
829
|
+
|
|
830
|
+
// Collect all practitioners with duplicates
|
|
831
|
+
duplicateChecks.forEach(({ practitionerId, hasSameTechnology }) => {
|
|
832
|
+
if (hasSameTechnology) {
|
|
833
|
+
duplicatePractitioners.push(practitionerId);
|
|
834
|
+
}
|
|
835
|
+
});
|
|
836
|
+
|
|
837
|
+
// If any duplicates found, throw error listing all of them
|
|
838
|
+
if (duplicatePractitioners.length > 0) {
|
|
839
|
+
const duplicateNames = duplicatePractitioners
|
|
840
|
+
.map(id => {
|
|
841
|
+
const practitioner = practitionersMap.get(id)!;
|
|
842
|
+
return `${practitioner.basicInfo.firstName} ${practitioner.basicInfo.lastName}`;
|
|
843
|
+
})
|
|
844
|
+
.join(', ');
|
|
845
|
+
|
|
846
|
+
throw new Error(
|
|
847
|
+
`The following practitioner(s) already have a procedure with technology "${technology?.name || validatedData.technologyId}" in this clinic branch: ${duplicateNames}. Please remove them from the selection and try again.`
|
|
848
|
+
);
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
// 6. Use a Firestore batch for atomic creation
|
|
791
852
|
const batch = writeBatch(this.db);
|
|
792
853
|
const createdProcedureIds: string[] = [];
|
|
793
854
|
const clinicInfo = {
|
|
@@ -887,10 +948,10 @@ export class ProcedureService extends BaseService {
|
|
|
887
948
|
});
|
|
888
949
|
}
|
|
889
950
|
|
|
890
|
-
//
|
|
951
|
+
// 7. Commit the atomic batch write
|
|
891
952
|
await batch.commit();
|
|
892
953
|
|
|
893
|
-
//
|
|
954
|
+
// 8. Fetch and return the newly created procedures
|
|
894
955
|
const fetchedProcedures: Procedure[] = [];
|
|
895
956
|
for (let i = 0; i < createdProcedureIds.length; i += 30) {
|
|
896
957
|
const chunk = createdProcedureIds.slice(i, i + 30);
|