@blackcode_sa/metaestetics-api 1.13.8 → 1.13.10

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 CHANGED
@@ -6697,9 +6697,17 @@ declare class ProcedureService extends BaseService {
6697
6697
  constructor(db: Firestore, auth: Auth, app: FirebaseApp, categoryService: CategoryService, subcategoryService: SubcategoryService, technologyService: TechnologyService, productService: ProductService, mediaService: MediaService);
6698
6698
  setPractitionerService(practitionerService: PractitionerService): void;
6699
6699
  /**
6700
- * Filters out procedures from draft practitioners
6700
+ * Filters out procedures that should not be visible to patients:
6701
+ * 1. Procedures with no practitioner (missing practitionerId)
6702
+ * 2. Procedures where practitioner doesn't exist
6703
+ * 3. Procedures from draft practitioners
6704
+ * 4. Procedures from inactive practitioners (isActive === false)
6705
+ *
6706
+ * Note: Each procedure has ONE practitionerId. If that practitioner is inactive/draft/missing,
6707
+ * the procedure is filtered out.
6708
+ *
6701
6709
  * @param procedures - Array of procedures to filter
6702
- * @returns Filtered array of procedures (excluding those from draft practitioners)
6710
+ * @returns Filtered array of procedures (excluding invalid/inactive/draft practitioners)
6703
6711
  */
6704
6712
  private filterDraftPractitionerProcedures;
6705
6713
  /**
package/dist/index.d.ts CHANGED
@@ -6697,9 +6697,17 @@ declare class ProcedureService extends BaseService {
6697
6697
  constructor(db: Firestore, auth: Auth, app: FirebaseApp, categoryService: CategoryService, subcategoryService: SubcategoryService, technologyService: TechnologyService, productService: ProductService, mediaService: MediaService);
6698
6698
  setPractitionerService(practitionerService: PractitionerService): void;
6699
6699
  /**
6700
- * Filters out procedures from draft practitioners
6700
+ * Filters out procedures that should not be visible to patients:
6701
+ * 1. Procedures with no practitioner (missing practitionerId)
6702
+ * 2. Procedures where practitioner doesn't exist
6703
+ * 3. Procedures from draft practitioners
6704
+ * 4. Procedures from inactive practitioners (isActive === false)
6705
+ *
6706
+ * Note: Each procedure has ONE practitionerId. If that practitioner is inactive/draft/missing,
6707
+ * the procedure is filtered out.
6708
+ *
6701
6709
  * @param procedures - Array of procedures to filter
6702
- * @returns Filtered array of procedures (excluding those from draft practitioners)
6710
+ * @returns Filtered array of procedures (excluding invalid/inactive/draft practitioners)
6703
6711
  */
6704
6712
  private filterDraftPractitionerProcedures;
6705
6713
  /**
package/dist/index.js CHANGED
@@ -20022,44 +20022,82 @@ var ProcedureService = class extends BaseService {
20022
20022
  this.practitionerService = practitionerService;
20023
20023
  }
20024
20024
  /**
20025
- * Filters out procedures from draft practitioners
20025
+ * Filters out procedures that should not be visible to patients:
20026
+ * 1. Procedures with no practitioner (missing practitionerId)
20027
+ * 2. Procedures where practitioner doesn't exist
20028
+ * 3. Procedures from draft practitioners
20029
+ * 4. Procedures from inactive practitioners (isActive === false)
20030
+ *
20031
+ * Note: Each procedure has ONE practitionerId. If that practitioner is inactive/draft/missing,
20032
+ * the procedure is filtered out.
20033
+ *
20026
20034
  * @param procedures - Array of procedures to filter
20027
- * @returns Filtered array of procedures (excluding those from draft practitioners)
20035
+ * @returns Filtered array of procedures (excluding invalid/inactive/draft practitioners)
20028
20036
  */
20029
20037
  async filterDraftPractitionerProcedures(procedures) {
20030
20038
  if (!this.practitionerService || procedures.length === 0) {
20031
20039
  return procedures;
20032
20040
  }
20033
20041
  try {
20042
+ const proceduresWithPractitioner = procedures.filter(
20043
+ (p) => p.practitionerId && p.practitionerId.trim() !== ""
20044
+ );
20045
+ if (proceduresWithPractitioner.length === 0) {
20046
+ console.log(
20047
+ `[ProcedureService] All ${procedures.length} procedures have no practitionerId - filtering out`
20048
+ );
20049
+ return [];
20050
+ }
20034
20051
  const practitionerIds = Array.from(
20035
- new Set(procedures.map((p) => p.practitionerId).filter(Boolean))
20052
+ new Set(proceduresWithPractitioner.map((p) => p.practitionerId).filter(Boolean))
20036
20053
  );
20037
20054
  if (practitionerIds.length === 0) {
20038
- return procedures;
20055
+ return [];
20039
20056
  }
20040
20057
  const practitionerPromises = practitionerIds.map(
20041
20058
  (id) => this.practitionerService.getPractitioner(id).catch(() => null)
20042
20059
  );
20043
20060
  const practitioners = await Promise.all(practitionerPromises);
20044
- const practitionerStatusMap = /* @__PURE__ */ new Map();
20061
+ const practitionerMap = /* @__PURE__ */ new Map();
20045
20062
  practitioners.forEach((practitioner, index) => {
20046
20063
  if (practitioner) {
20047
- practitionerStatusMap.set(practitionerIds[index], practitioner.status);
20064
+ practitionerMap.set(practitionerIds[index], practitioner);
20048
20065
  }
20049
20066
  });
20050
- const filteredProcedures = procedures.filter((procedure) => {
20051
- const practitionerStatus = practitionerStatusMap.get(procedure.practitionerId);
20052
- return practitionerStatus !== "draft" /* DRAFT */;
20067
+ const filteredProcedures = proceduresWithPractitioner.filter((procedure) => {
20068
+ const practitioner = practitionerMap.get(procedure.practitionerId);
20069
+ if (!practitioner) {
20070
+ console.log(
20071
+ `[ProcedureService] Filtering out procedure ${procedure.id} - practitioner ${procedure.practitionerId} not found`
20072
+ );
20073
+ return false;
20074
+ }
20075
+ if (practitioner.status === "draft" /* DRAFT */) {
20076
+ console.log(
20077
+ `[ProcedureService] Filtering out procedure ${procedure.id} - practitioner ${procedure.practitionerId} is DRAFT`
20078
+ );
20079
+ return false;
20080
+ }
20081
+ if (!practitioner.isActive) {
20082
+ console.log(
20083
+ `[ProcedureService] Filtering out procedure ${procedure.id} - practitioner ${procedure.practitionerId} is not active`
20084
+ );
20085
+ return false;
20086
+ }
20087
+ return true;
20053
20088
  });
20054
- if (filteredProcedures.length !== procedures.length) {
20089
+ const filteredCount = procedures.length - filteredProcedures.length;
20090
+ if (filteredCount > 0) {
20091
+ const noPractitionerCount = procedures.length - proceduresWithPractitioner.length;
20092
+ const invalidPractitionerCount = proceduresWithPractitioner.length - filteredProcedures.length;
20055
20093
  console.log(
20056
- `[ProcedureService] Filtered out ${procedures.length - filteredProcedures.length} procedures from draft practitioners`
20094
+ `[ProcedureService] Filtered out ${filteredCount} procedures: ${noPractitionerCount} with no practitionerId, ${invalidPractitionerCount} with missing/draft/inactive practitioners`
20057
20095
  );
20058
20096
  }
20059
20097
  return filteredProcedures;
20060
20098
  } catch (error) {
20061
20099
  console.error(
20062
- "[ProcedureService] Error filtering draft practitioner procedures:",
20100
+ "[ProcedureService] Error filtering practitioner procedures:",
20063
20101
  error
20064
20102
  );
20065
20103
  return procedures;
@@ -20769,7 +20807,8 @@ var ProcedureService = class extends BaseService {
20769
20807
  (0, import_firestore58.where)("isActive", "==", true)
20770
20808
  );
20771
20809
  const snapshot = await (0, import_firestore58.getDocs)(q);
20772
- return snapshot.docs.map((doc47) => doc47.data());
20810
+ const procedures = snapshot.docs.map((doc47) => doc47.data());
20811
+ return await this.filterDraftPractitionerProcedures(procedures);
20773
20812
  }
20774
20813
  /**
20775
20814
  * Gets all procedures for a practitioner
@@ -21172,6 +21211,7 @@ var ProcedureService = class extends BaseService {
21172
21211
  if (hasNestedFilters) {
21173
21212
  procedures = this.applyInMemoryFilters(procedures, filters);
21174
21213
  }
21214
+ procedures = await this.filterDraftPractitionerProcedures(procedures);
21175
21215
  const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
21176
21216
  console.log(`[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures`);
21177
21217
  if (procedures.length < (filters.pagination || 10)) {
package/dist/index.mjs CHANGED
@@ -20258,44 +20258,82 @@ var ProcedureService = class extends BaseService {
20258
20258
  this.practitionerService = practitionerService;
20259
20259
  }
20260
20260
  /**
20261
- * Filters out procedures from draft practitioners
20261
+ * Filters out procedures that should not be visible to patients:
20262
+ * 1. Procedures with no practitioner (missing practitionerId)
20263
+ * 2. Procedures where practitioner doesn't exist
20264
+ * 3. Procedures from draft practitioners
20265
+ * 4. Procedures from inactive practitioners (isActive === false)
20266
+ *
20267
+ * Note: Each procedure has ONE practitionerId. If that practitioner is inactive/draft/missing,
20268
+ * the procedure is filtered out.
20269
+ *
20262
20270
  * @param procedures - Array of procedures to filter
20263
- * @returns Filtered array of procedures (excluding those from draft practitioners)
20271
+ * @returns Filtered array of procedures (excluding invalid/inactive/draft practitioners)
20264
20272
  */
20265
20273
  async filterDraftPractitionerProcedures(procedures) {
20266
20274
  if (!this.practitionerService || procedures.length === 0) {
20267
20275
  return procedures;
20268
20276
  }
20269
20277
  try {
20278
+ const proceduresWithPractitioner = procedures.filter(
20279
+ (p) => p.practitionerId && p.practitionerId.trim() !== ""
20280
+ );
20281
+ if (proceduresWithPractitioner.length === 0) {
20282
+ console.log(
20283
+ `[ProcedureService] All ${procedures.length} procedures have no practitionerId - filtering out`
20284
+ );
20285
+ return [];
20286
+ }
20270
20287
  const practitionerIds = Array.from(
20271
- new Set(procedures.map((p) => p.practitionerId).filter(Boolean))
20288
+ new Set(proceduresWithPractitioner.map((p) => p.practitionerId).filter(Boolean))
20272
20289
  );
20273
20290
  if (practitionerIds.length === 0) {
20274
- return procedures;
20291
+ return [];
20275
20292
  }
20276
20293
  const practitionerPromises = practitionerIds.map(
20277
20294
  (id) => this.practitionerService.getPractitioner(id).catch(() => null)
20278
20295
  );
20279
20296
  const practitioners = await Promise.all(practitionerPromises);
20280
- const practitionerStatusMap = /* @__PURE__ */ new Map();
20297
+ const practitionerMap = /* @__PURE__ */ new Map();
20281
20298
  practitioners.forEach((practitioner, index) => {
20282
20299
  if (practitioner) {
20283
- practitionerStatusMap.set(practitionerIds[index], practitioner.status);
20300
+ practitionerMap.set(practitionerIds[index], practitioner);
20284
20301
  }
20285
20302
  });
20286
- const filteredProcedures = procedures.filter((procedure) => {
20287
- const practitionerStatus = practitionerStatusMap.get(procedure.practitionerId);
20288
- return practitionerStatus !== "draft" /* DRAFT */;
20303
+ const filteredProcedures = proceduresWithPractitioner.filter((procedure) => {
20304
+ const practitioner = practitionerMap.get(procedure.practitionerId);
20305
+ if (!practitioner) {
20306
+ console.log(
20307
+ `[ProcedureService] Filtering out procedure ${procedure.id} - practitioner ${procedure.practitionerId} not found`
20308
+ );
20309
+ return false;
20310
+ }
20311
+ if (practitioner.status === "draft" /* DRAFT */) {
20312
+ console.log(
20313
+ `[ProcedureService] Filtering out procedure ${procedure.id} - practitioner ${procedure.practitionerId} is DRAFT`
20314
+ );
20315
+ return false;
20316
+ }
20317
+ if (!practitioner.isActive) {
20318
+ console.log(
20319
+ `[ProcedureService] Filtering out procedure ${procedure.id} - practitioner ${procedure.practitionerId} is not active`
20320
+ );
20321
+ return false;
20322
+ }
20323
+ return true;
20289
20324
  });
20290
- if (filteredProcedures.length !== procedures.length) {
20325
+ const filteredCount = procedures.length - filteredProcedures.length;
20326
+ if (filteredCount > 0) {
20327
+ const noPractitionerCount = procedures.length - proceduresWithPractitioner.length;
20328
+ const invalidPractitionerCount = proceduresWithPractitioner.length - filteredProcedures.length;
20291
20329
  console.log(
20292
- `[ProcedureService] Filtered out ${procedures.length - filteredProcedures.length} procedures from draft practitioners`
20330
+ `[ProcedureService] Filtered out ${filteredCount} procedures: ${noPractitionerCount} with no practitionerId, ${invalidPractitionerCount} with missing/draft/inactive practitioners`
20293
20331
  );
20294
20332
  }
20295
20333
  return filteredProcedures;
20296
20334
  } catch (error) {
20297
20335
  console.error(
20298
- "[ProcedureService] Error filtering draft practitioner procedures:",
20336
+ "[ProcedureService] Error filtering practitioner procedures:",
20299
20337
  error
20300
20338
  );
20301
20339
  return procedures;
@@ -21005,7 +21043,8 @@ var ProcedureService = class extends BaseService {
21005
21043
  where33("isActive", "==", true)
21006
21044
  );
21007
21045
  const snapshot = await getDocs33(q);
21008
- return snapshot.docs.map((doc47) => doc47.data());
21046
+ const procedures = snapshot.docs.map((doc47) => doc47.data());
21047
+ return await this.filterDraftPractitionerProcedures(procedures);
21009
21048
  }
21010
21049
  /**
21011
21050
  * Gets all procedures for a practitioner
@@ -21408,6 +21447,7 @@ var ProcedureService = class extends BaseService {
21408
21447
  if (hasNestedFilters) {
21409
21448
  procedures = this.applyInMemoryFilters(procedures, filters);
21410
21449
  }
21450
+ procedures = await this.filterDraftPractitionerProcedures(procedures);
21411
21451
  const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
21412
21452
  console.log(`[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures`);
21413
21453
  if (procedures.length < (filters.pagination || 10)) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.13.8",
4
+ "version": "1.13.10",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -90,9 +90,17 @@ export class ProcedureService extends BaseService {
90
90
  }
91
91
 
92
92
  /**
93
- * Filters out procedures from draft practitioners
93
+ * Filters out procedures that should not be visible to patients:
94
+ * 1. Procedures with no practitioner (missing practitionerId)
95
+ * 2. Procedures where practitioner doesn't exist
96
+ * 3. Procedures from draft practitioners
97
+ * 4. Procedures from inactive practitioners (isActive === false)
98
+ *
99
+ * Note: Each procedure has ONE practitionerId. If that practitioner is inactive/draft/missing,
100
+ * the procedure is filtered out.
101
+ *
94
102
  * @param procedures - Array of procedures to filter
95
- * @returns Filtered array of procedures (excluding those from draft practitioners)
103
+ * @returns Filtered array of procedures (excluding invalid/inactive/draft practitioners)
96
104
  */
97
105
  private async filterDraftPractitionerProcedures(
98
106
  procedures: Procedure[]
@@ -102,13 +110,25 @@ export class ProcedureService extends BaseService {
102
110
  }
103
111
 
104
112
  try {
113
+ // First, filter out procedures with no practitionerId
114
+ const proceduresWithPractitioner = procedures.filter((p) =>
115
+ p.practitionerId && p.practitionerId.trim() !== ''
116
+ );
117
+
118
+ if (proceduresWithPractitioner.length === 0) {
119
+ console.log(
120
+ `[ProcedureService] All ${procedures.length} procedures have no practitionerId - filtering out`
121
+ );
122
+ return [];
123
+ }
124
+
105
125
  // Get unique practitioner IDs from procedures
106
126
  const practitionerIds = Array.from(
107
- new Set(procedures.map((p) => p.practitionerId).filter(Boolean))
127
+ new Set(proceduresWithPractitioner.map((p) => p.practitionerId).filter(Boolean))
108
128
  );
109
129
 
110
130
  if (practitionerIds.length === 0) {
111
- return procedures;
131
+ return [];
112
132
  }
113
133
 
114
134
  // Fetch all practitioners in parallel
@@ -117,32 +137,64 @@ export class ProcedureService extends BaseService {
117
137
  );
118
138
  const practitioners = await Promise.all(practitionerPromises);
119
139
 
120
- // Create a map of practitioner ID to status
121
- const practitionerStatusMap = new Map<string, PractitionerStatus>();
140
+ // Create a map of practitioner ID to practitioner data
141
+ const practitionerMap = new Map<string, Practitioner>();
122
142
  practitioners.forEach((practitioner, index) => {
123
143
  if (practitioner) {
124
- practitionerStatusMap.set(practitionerIds[index], practitioner.status);
144
+ practitionerMap.set(practitionerIds[index], practitioner);
125
145
  }
126
146
  });
127
147
 
128
- // Filter out procedures from draft practitioners
129
- const filteredProcedures = procedures.filter((procedure) => {
130
- const practitionerStatus = practitionerStatusMap.get(procedure.practitionerId);
131
- return practitionerStatus !== PractitionerStatus.DRAFT;
148
+ // Filter out procedures that:
149
+ // 1. Have no practitionerId (already filtered above, but double-check)
150
+ // 2. Have a practitioner that doesn't exist
151
+ // 3. Have a practitioner with DRAFT status
152
+ // 4. Have a practitioner that is not active (isActive === false)
153
+ const filteredProcedures = proceduresWithPractitioner.filter((procedure) => {
154
+ // Check if practitioner exists
155
+ const practitioner = practitionerMap.get(procedure.practitionerId);
156
+
157
+ if (!practitioner) {
158
+ console.log(
159
+ `[ProcedureService] Filtering out procedure ${procedure.id} - practitioner ${procedure.practitionerId} not found`
160
+ );
161
+ return false;
162
+ }
163
+
164
+ // Check if practitioner is DRAFT
165
+ if (practitioner.status === PractitionerStatus.DRAFT) {
166
+ console.log(
167
+ `[ProcedureService] Filtering out procedure ${procedure.id} - practitioner ${procedure.practitionerId} is DRAFT`
168
+ );
169
+ return false;
170
+ }
171
+
172
+ // Check if practitioner is active (must be true to show procedure)
173
+ if (!practitioner.isActive) {
174
+ console.log(
175
+ `[ProcedureService] Filtering out procedure ${procedure.id} - practitioner ${procedure.practitionerId} is not active`
176
+ );
177
+ return false;
178
+ }
179
+
180
+ return true;
132
181
  });
133
182
 
134
- if (filteredProcedures.length !== procedures.length) {
183
+ const filteredCount = procedures.length - filteredProcedures.length;
184
+ if (filteredCount > 0) {
185
+ const noPractitionerCount = procedures.length - proceduresWithPractitioner.length;
186
+ const invalidPractitionerCount = proceduresWithPractitioner.length - filteredProcedures.length;
135
187
  console.log(
136
- `[ProcedureService] Filtered out ${
137
- procedures.length - filteredProcedures.length
138
- } procedures from draft practitioners`
188
+ `[ProcedureService] Filtered out ${filteredCount} procedures: ` +
189
+ `${noPractitionerCount} with no practitionerId, ` +
190
+ `${invalidPractitionerCount} with missing/draft/inactive practitioners`
139
191
  );
140
192
  }
141
193
 
142
194
  return filteredProcedures;
143
195
  } catch (error) {
144
196
  console.error(
145
- '[ProcedureService] Error filtering draft practitioner procedures:',
197
+ '[ProcedureService] Error filtering practitioner procedures:',
146
198
  error
147
199
  );
148
200
  // On error, return original procedures to avoid breaking functionality
@@ -1062,7 +1114,10 @@ export class ProcedureService extends BaseService {
1062
1114
  where('isActive', '==', true),
1063
1115
  );
1064
1116
  const snapshot = await getDocs(q);
1065
- return snapshot.docs.map(doc => doc.data() as Procedure);
1117
+ const procedures = snapshot.docs.map(doc => doc.data() as Procedure);
1118
+
1119
+ // Filter out procedures from draft practitioners
1120
+ return await this.filterDraftPractitionerProcedures(procedures);
1066
1121
  }
1067
1122
 
1068
1123
  /**
@@ -1591,6 +1646,9 @@ export class ProcedureService extends BaseService {
1591
1646
  procedures = this.applyInMemoryFilters(procedures, filters);
1592
1647
  }
1593
1648
 
1649
+ // Filter out procedures from draft practitioners
1650
+ procedures = await this.filterDraftPractitionerProcedures(procedures);
1651
+
1594
1652
  const lastDoc =
1595
1653
  querySnapshot.docs.length > 0
1596
1654
  ? querySnapshot.docs[querySnapshot.docs.length - 1]