@blackcode_sa/metaestetics-api 1.7.24 → 1.7.25
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.js
CHANGED
|
@@ -987,14 +987,19 @@ var ClinicAggregationService = class {
|
|
|
987
987
|
);
|
|
988
988
|
for (const practitionerId of practitionerIds) {
|
|
989
989
|
const practitionerRef = this.db.collection(PRACTITIONERS_COLLECTION).doc(practitionerId);
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
990
|
+
const practitionerDoc = await practitionerRef.get();
|
|
991
|
+
if (practitionerDoc.exists) {
|
|
992
|
+
const practitionerData = practitionerDoc.data();
|
|
993
|
+
const currentClinicsInfo = (practitionerData == null ? void 0 : practitionerData.clinicsInfo) || [];
|
|
994
|
+
const filteredClinicsInfo = currentClinicsInfo.filter(
|
|
995
|
+
(clinic) => clinic.id !== clinicId
|
|
996
|
+
);
|
|
997
|
+
const updatedClinicsInfo = [...filteredClinicsInfo, clinicInfo];
|
|
998
|
+
batch.update(practitionerRef, {
|
|
999
|
+
clinicsInfo: updatedClinicsInfo,
|
|
1000
|
+
updatedAt: admin3.firestore.FieldValue.serverTimestamp()
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
998
1003
|
}
|
|
999
1004
|
try {
|
|
1000
1005
|
await batch.commit();
|
|
@@ -1058,28 +1063,35 @@ var ClinicAggregationService = class {
|
|
|
1058
1063
|
);
|
|
1059
1064
|
return;
|
|
1060
1065
|
}
|
|
1061
|
-
const batch = this.db.batch();
|
|
1062
1066
|
const clinicId = clinicInfo.id;
|
|
1063
1067
|
const groupRef = this.db.collection(CLINIC_GROUPS_COLLECTION).doc(clinicGroupId);
|
|
1064
1068
|
console.log(
|
|
1065
1069
|
`[ClinicAggregationService] Starting update of ClinicInfo (ID: ${clinicId}) in Clinic Group ${clinicGroupId}.`
|
|
1066
1070
|
);
|
|
1067
|
-
batch.update(groupRef, {
|
|
1068
|
-
clinicsInfo: admin3.firestore.FieldValue.arrayRemove({ id: clinicId }),
|
|
1069
|
-
updatedAt: admin3.firestore.FieldValue.serverTimestamp()
|
|
1070
|
-
});
|
|
1071
|
-
batch.update(groupRef, {
|
|
1072
|
-
clinicsInfo: admin3.firestore.FieldValue.arrayUnion(clinicInfo),
|
|
1073
|
-
updatedAt: admin3.firestore.FieldValue.serverTimestamp()
|
|
1074
|
-
});
|
|
1075
1071
|
try {
|
|
1076
|
-
await
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1072
|
+
const clinicGroupDoc = await groupRef.get();
|
|
1073
|
+
if (clinicGroupDoc.exists) {
|
|
1074
|
+
const clinicGroupData = clinicGroupDoc.data();
|
|
1075
|
+
const currentClinicsInfo = (clinicGroupData == null ? void 0 : clinicGroupData.clinicsInfo) || [];
|
|
1076
|
+
const filteredClinicsInfo = currentClinicsInfo.filter(
|
|
1077
|
+
(clinic) => clinic.id !== clinicId
|
|
1078
|
+
);
|
|
1079
|
+
const updatedClinicsInfo = [...filteredClinicsInfo, clinicInfo];
|
|
1080
|
+
await groupRef.update({
|
|
1081
|
+
clinicsInfo: updatedClinicsInfo,
|
|
1082
|
+
updatedAt: admin3.firestore.FieldValue.serverTimestamp()
|
|
1083
|
+
});
|
|
1084
|
+
console.log(
|
|
1085
|
+
`[ClinicAggregationService] Successfully updated ClinicInfo (ID: ${clinicId}) in Clinic Group ${clinicGroupId}.`
|
|
1086
|
+
);
|
|
1087
|
+
} else {
|
|
1088
|
+
console.warn(
|
|
1089
|
+
`[ClinicAggregationService] Clinic Group ${clinicGroupId} not found. Cannot update clinic info.`
|
|
1090
|
+
);
|
|
1091
|
+
}
|
|
1080
1092
|
} catch (error) {
|
|
1081
1093
|
console.error(
|
|
1082
|
-
`[ClinicAggregationService] Error
|
|
1094
|
+
`[ClinicAggregationService] Error updating ClinicInfo (ID: ${clinicId}) in Clinic Group ${clinicGroupId}:`,
|
|
1083
1095
|
error
|
|
1084
1096
|
);
|
|
1085
1097
|
throw error;
|
|
@@ -1223,12 +1235,23 @@ var ClinicAggregationService = class {
|
|
|
1223
1235
|
);
|
|
1224
1236
|
for (const practitionerId of practitionerIds) {
|
|
1225
1237
|
const practitionerRef = this.db.collection(PRACTITIONERS_COLLECTION).doc(practitionerId);
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1238
|
+
const practitionerDoc = await practitionerRef.get();
|
|
1239
|
+
if (practitionerDoc.exists) {
|
|
1240
|
+
const practitionerData = practitionerDoc.data();
|
|
1241
|
+
const currentClinicIds = (practitionerData == null ? void 0 : practitionerData.clinics) || [];
|
|
1242
|
+
const currentClinicsInfo = (practitionerData == null ? void 0 : practitionerData.clinicsInfo) || [];
|
|
1243
|
+
const filteredClinicIds = currentClinicIds.filter(
|
|
1244
|
+
(id) => id !== clinicId
|
|
1245
|
+
);
|
|
1246
|
+
const filteredClinicsInfo = currentClinicsInfo.filter(
|
|
1247
|
+
(clinic) => clinic.id !== clinicId
|
|
1248
|
+
);
|
|
1249
|
+
batch.update(practitionerRef, {
|
|
1250
|
+
clinics: filteredClinicIds,
|
|
1251
|
+
clinicsInfo: filteredClinicsInfo,
|
|
1252
|
+
updatedAt: admin3.firestore.FieldValue.serverTimestamp()
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1232
1255
|
}
|
|
1233
1256
|
try {
|
|
1234
1257
|
await batch.commit();
|
|
@@ -1295,15 +1318,30 @@ var ClinicAggregationService = class {
|
|
|
1295
1318
|
`[ClinicAggregationService] Removing Clinic (ID: ${clinicId}) from Clinic Group ${clinicGroupId}.`
|
|
1296
1319
|
);
|
|
1297
1320
|
try {
|
|
1298
|
-
await groupRef.
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1321
|
+
const clinicGroupDoc = await groupRef.get();
|
|
1322
|
+
if (clinicGroupDoc.exists) {
|
|
1323
|
+
const clinicGroupData = clinicGroupDoc.data();
|
|
1324
|
+
const currentClinicIds = (clinicGroupData == null ? void 0 : clinicGroupData.clinics) || [];
|
|
1325
|
+
const currentClinicsInfo = (clinicGroupData == null ? void 0 : clinicGroupData.clinicsInfo) || [];
|
|
1326
|
+
const filteredClinicIds = currentClinicIds.filter(
|
|
1327
|
+
(id) => id !== clinicId
|
|
1328
|
+
);
|
|
1329
|
+
const filteredClinicsInfo = currentClinicsInfo.filter(
|
|
1330
|
+
(clinic) => clinic.id !== clinicId
|
|
1331
|
+
);
|
|
1332
|
+
await groupRef.update({
|
|
1333
|
+
clinics: filteredClinicIds,
|
|
1334
|
+
clinicsInfo: filteredClinicsInfo,
|
|
1335
|
+
updatedAt: admin3.firestore.FieldValue.serverTimestamp()
|
|
1336
|
+
});
|
|
1337
|
+
console.log(
|
|
1338
|
+
`[ClinicAggregationService] Successfully removed Clinic (ID: ${clinicId}) from Clinic Group ${clinicGroupId}.`
|
|
1339
|
+
);
|
|
1340
|
+
} else {
|
|
1341
|
+
console.warn(
|
|
1342
|
+
`[ClinicAggregationService] Clinic Group ${clinicGroupId} not found. Cannot remove clinic.`
|
|
1343
|
+
);
|
|
1344
|
+
}
|
|
1307
1345
|
} catch (error) {
|
|
1308
1346
|
console.error(
|
|
1309
1347
|
`[ClinicAggregationService] Error removing Clinic (ID: ${clinicId}) from Clinic Group ${clinicGroupId}:`,
|
package/dist/admin/index.mjs
CHANGED
|
@@ -930,14 +930,19 @@ var ClinicAggregationService = class {
|
|
|
930
930
|
);
|
|
931
931
|
for (const practitionerId of practitionerIds) {
|
|
932
932
|
const practitionerRef = this.db.collection(PRACTITIONERS_COLLECTION).doc(practitionerId);
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
933
|
+
const practitionerDoc = await practitionerRef.get();
|
|
934
|
+
if (practitionerDoc.exists) {
|
|
935
|
+
const practitionerData = practitionerDoc.data();
|
|
936
|
+
const currentClinicsInfo = (practitionerData == null ? void 0 : practitionerData.clinicsInfo) || [];
|
|
937
|
+
const filteredClinicsInfo = currentClinicsInfo.filter(
|
|
938
|
+
(clinic) => clinic.id !== clinicId
|
|
939
|
+
);
|
|
940
|
+
const updatedClinicsInfo = [...filteredClinicsInfo, clinicInfo];
|
|
941
|
+
batch.update(practitionerRef, {
|
|
942
|
+
clinicsInfo: updatedClinicsInfo,
|
|
943
|
+
updatedAt: admin3.firestore.FieldValue.serverTimestamp()
|
|
944
|
+
});
|
|
945
|
+
}
|
|
941
946
|
}
|
|
942
947
|
try {
|
|
943
948
|
await batch.commit();
|
|
@@ -1001,28 +1006,35 @@ var ClinicAggregationService = class {
|
|
|
1001
1006
|
);
|
|
1002
1007
|
return;
|
|
1003
1008
|
}
|
|
1004
|
-
const batch = this.db.batch();
|
|
1005
1009
|
const clinicId = clinicInfo.id;
|
|
1006
1010
|
const groupRef = this.db.collection(CLINIC_GROUPS_COLLECTION).doc(clinicGroupId);
|
|
1007
1011
|
console.log(
|
|
1008
1012
|
`[ClinicAggregationService] Starting update of ClinicInfo (ID: ${clinicId}) in Clinic Group ${clinicGroupId}.`
|
|
1009
1013
|
);
|
|
1010
|
-
batch.update(groupRef, {
|
|
1011
|
-
clinicsInfo: admin3.firestore.FieldValue.arrayRemove({ id: clinicId }),
|
|
1012
|
-
updatedAt: admin3.firestore.FieldValue.serverTimestamp()
|
|
1013
|
-
});
|
|
1014
|
-
batch.update(groupRef, {
|
|
1015
|
-
clinicsInfo: admin3.firestore.FieldValue.arrayUnion(clinicInfo),
|
|
1016
|
-
updatedAt: admin3.firestore.FieldValue.serverTimestamp()
|
|
1017
|
-
});
|
|
1018
1014
|
try {
|
|
1019
|
-
await
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1015
|
+
const clinicGroupDoc = await groupRef.get();
|
|
1016
|
+
if (clinicGroupDoc.exists) {
|
|
1017
|
+
const clinicGroupData = clinicGroupDoc.data();
|
|
1018
|
+
const currentClinicsInfo = (clinicGroupData == null ? void 0 : clinicGroupData.clinicsInfo) || [];
|
|
1019
|
+
const filteredClinicsInfo = currentClinicsInfo.filter(
|
|
1020
|
+
(clinic) => clinic.id !== clinicId
|
|
1021
|
+
);
|
|
1022
|
+
const updatedClinicsInfo = [...filteredClinicsInfo, clinicInfo];
|
|
1023
|
+
await groupRef.update({
|
|
1024
|
+
clinicsInfo: updatedClinicsInfo,
|
|
1025
|
+
updatedAt: admin3.firestore.FieldValue.serverTimestamp()
|
|
1026
|
+
});
|
|
1027
|
+
console.log(
|
|
1028
|
+
`[ClinicAggregationService] Successfully updated ClinicInfo (ID: ${clinicId}) in Clinic Group ${clinicGroupId}.`
|
|
1029
|
+
);
|
|
1030
|
+
} else {
|
|
1031
|
+
console.warn(
|
|
1032
|
+
`[ClinicAggregationService] Clinic Group ${clinicGroupId} not found. Cannot update clinic info.`
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1023
1035
|
} catch (error) {
|
|
1024
1036
|
console.error(
|
|
1025
|
-
`[ClinicAggregationService] Error
|
|
1037
|
+
`[ClinicAggregationService] Error updating ClinicInfo (ID: ${clinicId}) in Clinic Group ${clinicGroupId}:`,
|
|
1026
1038
|
error
|
|
1027
1039
|
);
|
|
1028
1040
|
throw error;
|
|
@@ -1166,12 +1178,23 @@ var ClinicAggregationService = class {
|
|
|
1166
1178
|
);
|
|
1167
1179
|
for (const practitionerId of practitionerIds) {
|
|
1168
1180
|
const practitionerRef = this.db.collection(PRACTITIONERS_COLLECTION).doc(practitionerId);
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1181
|
+
const practitionerDoc = await practitionerRef.get();
|
|
1182
|
+
if (practitionerDoc.exists) {
|
|
1183
|
+
const practitionerData = practitionerDoc.data();
|
|
1184
|
+
const currentClinicIds = (practitionerData == null ? void 0 : practitionerData.clinics) || [];
|
|
1185
|
+
const currentClinicsInfo = (practitionerData == null ? void 0 : practitionerData.clinicsInfo) || [];
|
|
1186
|
+
const filteredClinicIds = currentClinicIds.filter(
|
|
1187
|
+
(id) => id !== clinicId
|
|
1188
|
+
);
|
|
1189
|
+
const filteredClinicsInfo = currentClinicsInfo.filter(
|
|
1190
|
+
(clinic) => clinic.id !== clinicId
|
|
1191
|
+
);
|
|
1192
|
+
batch.update(practitionerRef, {
|
|
1193
|
+
clinics: filteredClinicIds,
|
|
1194
|
+
clinicsInfo: filteredClinicsInfo,
|
|
1195
|
+
updatedAt: admin3.firestore.FieldValue.serverTimestamp()
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1175
1198
|
}
|
|
1176
1199
|
try {
|
|
1177
1200
|
await batch.commit();
|
|
@@ -1238,15 +1261,30 @@ var ClinicAggregationService = class {
|
|
|
1238
1261
|
`[ClinicAggregationService] Removing Clinic (ID: ${clinicId}) from Clinic Group ${clinicGroupId}.`
|
|
1239
1262
|
);
|
|
1240
1263
|
try {
|
|
1241
|
-
await groupRef.
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1264
|
+
const clinicGroupDoc = await groupRef.get();
|
|
1265
|
+
if (clinicGroupDoc.exists) {
|
|
1266
|
+
const clinicGroupData = clinicGroupDoc.data();
|
|
1267
|
+
const currentClinicIds = (clinicGroupData == null ? void 0 : clinicGroupData.clinics) || [];
|
|
1268
|
+
const currentClinicsInfo = (clinicGroupData == null ? void 0 : clinicGroupData.clinicsInfo) || [];
|
|
1269
|
+
const filteredClinicIds = currentClinicIds.filter(
|
|
1270
|
+
(id) => id !== clinicId
|
|
1271
|
+
);
|
|
1272
|
+
const filteredClinicsInfo = currentClinicsInfo.filter(
|
|
1273
|
+
(clinic) => clinic.id !== clinicId
|
|
1274
|
+
);
|
|
1275
|
+
await groupRef.update({
|
|
1276
|
+
clinics: filteredClinicIds,
|
|
1277
|
+
clinicsInfo: filteredClinicsInfo,
|
|
1278
|
+
updatedAt: admin3.firestore.FieldValue.serverTimestamp()
|
|
1279
|
+
});
|
|
1280
|
+
console.log(
|
|
1281
|
+
`[ClinicAggregationService] Successfully removed Clinic (ID: ${clinicId}) from Clinic Group ${clinicGroupId}.`
|
|
1282
|
+
);
|
|
1283
|
+
} else {
|
|
1284
|
+
console.warn(
|
|
1285
|
+
`[ClinicAggregationService] Clinic Group ${clinicGroupId} not found. Cannot remove clinic.`
|
|
1286
|
+
);
|
|
1287
|
+
}
|
|
1250
1288
|
} catch (error) {
|
|
1251
1289
|
console.error(
|
|
1252
1290
|
`[ClinicAggregationService] Error removing Clinic (ID: ${clinicId}) from Clinic Group ${clinicGroupId}:`,
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import * as admin from "firebase-admin";
|
|
2
2
|
import { ClinicInfo } from "../../../types/profile"; // Corrected path
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
PRACTITIONERS_COLLECTION,
|
|
5
|
+
Practitioner,
|
|
6
|
+
} from "../../../types/practitioner"; // Corrected path
|
|
4
7
|
import { PROCEDURES_COLLECTION } from "../../../types/procedure"; // Added procedure collection
|
|
5
|
-
import { CLINIC_GROUPS_COLLECTION } from "../../../types/clinic"; // Added clinic group collection
|
|
8
|
+
import { CLINIC_GROUPS_COLLECTION, ClinicGroup } from "../../../types/clinic"; // Added clinic group collection
|
|
6
9
|
import { ClinicLocation } from "../../../types/clinic"; // Added ClinicLocation type
|
|
7
10
|
import { CALENDAR_COLLECTION } from "../../../types/calendar"; // Added calendar collection
|
|
8
11
|
import { PATIENTS_COLLECTION } from "../../../types/patient"; // Added patient collection
|
|
@@ -103,16 +106,27 @@ export class ClinicAggregationService {
|
|
|
103
106
|
.collection(PRACTITIONERS_COLLECTION)
|
|
104
107
|
.doc(practitionerId);
|
|
105
108
|
|
|
106
|
-
// Remove old clinic info based on ID matcher
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
109
|
+
// Remove old clinic info based on ID matcher and add updated info
|
|
110
|
+
// First, get the current practitioner data to filter clinicsInfo manually
|
|
111
|
+
const practitionerDoc = await practitionerRef.get();
|
|
112
|
+
if (practitionerDoc.exists) {
|
|
113
|
+
const practitionerData = practitionerDoc.data() as Practitioner;
|
|
114
|
+
const currentClinicsInfo = practitionerData?.clinicsInfo || [];
|
|
115
|
+
|
|
116
|
+
// Filter out the clinic info with matching ID
|
|
117
|
+
const filteredClinicsInfo = currentClinicsInfo.filter(
|
|
118
|
+
(clinic: any) => clinic.id !== clinicId
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
// Add the updated clinic info to the filtered array
|
|
122
|
+
const updatedClinicsInfo = [...filteredClinicsInfo, clinicInfo];
|
|
123
|
+
|
|
124
|
+
// Update with the complete new array
|
|
125
|
+
batch.update(practitionerRef, {
|
|
126
|
+
clinicsInfo: updatedClinicsInfo,
|
|
127
|
+
updatedAt: admin.firestore.FieldValue.serverTimestamp(),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
116
130
|
}
|
|
117
131
|
|
|
118
132
|
try {
|
|
@@ -194,7 +208,6 @@ export class ClinicAggregationService {
|
|
|
194
208
|
return;
|
|
195
209
|
}
|
|
196
210
|
|
|
197
|
-
const batch = this.db.batch();
|
|
198
211
|
const clinicId = clinicInfo.id;
|
|
199
212
|
const groupRef = this.db
|
|
200
213
|
.collection(CLINIC_GROUPS_COLLECTION)
|
|
@@ -204,25 +217,38 @@ export class ClinicAggregationService {
|
|
|
204
217
|
`[ClinicAggregationService] Starting update of ClinicInfo (ID: ${clinicId}) in Clinic Group ${clinicGroupId}.`
|
|
205
218
|
);
|
|
206
219
|
|
|
207
|
-
// Remove old clinic info based on ID matcher
|
|
208
|
-
batch.update(groupRef, {
|
|
209
|
-
clinicsInfo: admin.firestore.FieldValue.arrayRemove({ id: clinicId }),
|
|
210
|
-
updatedAt: admin.firestore.FieldValue.serverTimestamp(),
|
|
211
|
-
});
|
|
212
|
-
// Add updated clinic info
|
|
213
|
-
batch.update(groupRef, {
|
|
214
|
-
clinicsInfo: admin.firestore.FieldValue.arrayUnion(clinicInfo),
|
|
215
|
-
updatedAt: admin.firestore.FieldValue.serverTimestamp(),
|
|
216
|
-
});
|
|
217
|
-
|
|
218
220
|
try {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
221
|
+
// Get current clinic group data to filter clinicsInfo manually
|
|
222
|
+
const clinicGroupDoc = await groupRef.get();
|
|
223
|
+
if (clinicGroupDoc.exists) {
|
|
224
|
+
const clinicGroupData = clinicGroupDoc.data() as ClinicGroup;
|
|
225
|
+
const currentClinicsInfo = clinicGroupData?.clinicsInfo || [];
|
|
226
|
+
|
|
227
|
+
// Filter out the clinic info with matching ID
|
|
228
|
+
const filteredClinicsInfo = currentClinicsInfo.filter(
|
|
229
|
+
(clinic: any) => clinic.id !== clinicId
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
// Add the updated clinic info to the filtered array
|
|
233
|
+
const updatedClinicsInfo = [...filteredClinicsInfo, clinicInfo];
|
|
234
|
+
|
|
235
|
+
// Update with the complete new array
|
|
236
|
+
await groupRef.update({
|
|
237
|
+
clinicsInfo: updatedClinicsInfo,
|
|
238
|
+
updatedAt: admin.firestore.FieldValue.serverTimestamp(),
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
console.log(
|
|
242
|
+
`[ClinicAggregationService] Successfully updated ClinicInfo (ID: ${clinicId}) in Clinic Group ${clinicGroupId}.`
|
|
243
|
+
);
|
|
244
|
+
} else {
|
|
245
|
+
console.warn(
|
|
246
|
+
`[ClinicAggregationService] Clinic Group ${clinicGroupId} not found. Cannot update clinic info.`
|
|
247
|
+
);
|
|
248
|
+
}
|
|
223
249
|
} catch (error) {
|
|
224
250
|
console.error(
|
|
225
|
-
`[ClinicAggregationService] Error
|
|
251
|
+
`[ClinicAggregationService] Error updating ClinicInfo (ID: ${clinicId}) in Clinic Group ${clinicGroupId}:`,
|
|
226
252
|
error
|
|
227
253
|
);
|
|
228
254
|
throw error;
|
|
@@ -427,13 +453,28 @@ export class ClinicAggregationService {
|
|
|
427
453
|
.collection(PRACTITIONERS_COLLECTION)
|
|
428
454
|
.doc(practitionerId);
|
|
429
455
|
|
|
430
|
-
//
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
456
|
+
// Get current practitioner data to filter manually
|
|
457
|
+
const practitionerDoc = await practitionerRef.get();
|
|
458
|
+
if (practitionerDoc.exists) {
|
|
459
|
+
const practitionerData = practitionerDoc.data() as Practitioner;
|
|
460
|
+
const currentClinicIds = practitionerData?.clinics || [];
|
|
461
|
+
const currentClinicsInfo = practitionerData?.clinicsInfo || [];
|
|
462
|
+
|
|
463
|
+
// Filter out the clinic ID and clinic info with matching ID
|
|
464
|
+
const filteredClinicIds = currentClinicIds.filter(
|
|
465
|
+
(id: string) => id !== clinicId
|
|
466
|
+
);
|
|
467
|
+
const filteredClinicsInfo = currentClinicsInfo.filter(
|
|
468
|
+
(clinic: any) => clinic.id !== clinicId
|
|
469
|
+
);
|
|
470
|
+
|
|
471
|
+
// Update with the filtered arrays
|
|
472
|
+
batch.update(practitionerRef, {
|
|
473
|
+
clinics: filteredClinicIds,
|
|
474
|
+
clinicsInfo: filteredClinicsInfo,
|
|
475
|
+
updatedAt: admin.firestore.FieldValue.serverTimestamp(),
|
|
476
|
+
});
|
|
477
|
+
}
|
|
437
478
|
}
|
|
438
479
|
|
|
439
480
|
try {
|
|
@@ -518,16 +559,36 @@ export class ClinicAggregationService {
|
|
|
518
559
|
);
|
|
519
560
|
|
|
520
561
|
try {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
562
|
+
// Get current clinic group data to filter manually
|
|
563
|
+
const clinicGroupDoc = await groupRef.get();
|
|
564
|
+
if (clinicGroupDoc.exists) {
|
|
565
|
+
const clinicGroupData = clinicGroupDoc.data() as ClinicGroup;
|
|
566
|
+
const currentClinicIds = clinicGroupData?.clinics || [];
|
|
567
|
+
const currentClinicsInfo = clinicGroupData?.clinicsInfo || [];
|
|
568
|
+
|
|
569
|
+
// Filter out the clinic ID and clinic info with matching ID
|
|
570
|
+
const filteredClinicIds = currentClinicIds.filter(
|
|
571
|
+
(id: string) => id !== clinicId
|
|
572
|
+
);
|
|
573
|
+
const filteredClinicsInfo = currentClinicsInfo.filter(
|
|
574
|
+
(clinic: any) => clinic.id !== clinicId
|
|
575
|
+
);
|
|
527
576
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
577
|
+
// Update with the filtered arrays
|
|
578
|
+
await groupRef.update({
|
|
579
|
+
clinics: filteredClinicIds,
|
|
580
|
+
clinicsInfo: filteredClinicsInfo,
|
|
581
|
+
updatedAt: admin.firestore.FieldValue.serverTimestamp(),
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
console.log(
|
|
585
|
+
`[ClinicAggregationService] Successfully removed Clinic (ID: ${clinicId}) from Clinic Group ${clinicGroupId}.`
|
|
586
|
+
);
|
|
587
|
+
} else {
|
|
588
|
+
console.warn(
|
|
589
|
+
`[ClinicAggregationService] Clinic Group ${clinicGroupId} not found. Cannot remove clinic.`
|
|
590
|
+
);
|
|
591
|
+
}
|
|
531
592
|
} catch (error) {
|
|
532
593
|
console.error(
|
|
533
594
|
`[ClinicAggregationService] Error removing Clinic (ID: ${clinicId}) from Clinic Group ${clinicGroupId}:`,
|