@blackcode_sa/metaestetics-api 1.6.18 → 1.6.19

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.
@@ -3345,18 +3345,46 @@ var AppointmentAggregationService = class {
3345
3345
  try {
3346
3346
  const batch = this.db.batch();
3347
3347
  let instancesCreatedCount = 0;
3348
+ Logger.info(
3349
+ `[AggService] Found ${appointment.preProcedureRequirements.length} pre-requirements to process: ${JSON.stringify(
3350
+ appointment.preProcedureRequirements.map((r) => {
3351
+ var _a2, _b;
3352
+ return {
3353
+ id: r.id,
3354
+ name: r.name,
3355
+ type: r.type,
3356
+ isActive: r.isActive,
3357
+ hasTimeframe: !!r.timeframe,
3358
+ notifyAtLength: ((_b = (_a2 = r.timeframe) == null ? void 0 : _a2.notifyAt) == null ? void 0 : _b.length) || 0
3359
+ };
3360
+ })
3361
+ )}`
3362
+ );
3348
3363
  for (const template of appointment.preProcedureRequirements) {
3349
- if (!template) continue;
3364
+ if (!template) {
3365
+ Logger.warn(
3366
+ `[AggService] Found null/undefined template in preProcedureRequirements array`
3367
+ );
3368
+ continue;
3369
+ }
3350
3370
  if (template.type !== "pre" /* PRE */ || !template.isActive) {
3351
3371
  Logger.debug(
3352
3372
  `[AggService] Skipping template ${template.id} (${template.name}): not an active PRE requirement.`
3353
3373
  );
3354
3374
  continue;
3355
3375
  }
3376
+ if (!template.timeframe || !template.timeframe.notifyAt || template.timeframe.notifyAt.length === 0) {
3377
+ Logger.warn(
3378
+ `[AggService] Template ${template.id} (${template.name}) has no timeframe.notifyAt values. Creating with empty instructions.`
3379
+ );
3380
+ }
3356
3381
  Logger.debug(
3357
3382
  `[AggService] Processing template ${template.id} (${template.name}) for appt ${appointment.id}`
3358
3383
  );
3359
3384
  const newInstanceRef = this.db.collection(PATIENTS_COLLECTION).doc(appointment.patientId).collection(PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME).doc();
3385
+ Logger.debug(
3386
+ `[AggService] Created doc reference: ${newInstanceRef.path}`
3387
+ );
3360
3388
  const instructions = (((_a = template.timeframe) == null ? void 0 : _a.notifyAt) || []).map((notifyAtValue) => {
3361
3389
  let dueTime = appointment.appointmentStartTime;
3362
3390
  if (template.timeframe && typeof notifyAtValue === "number") {
@@ -3403,6 +3431,15 @@ var AppointmentAggregationService = class {
3403
3431
  createdAt: admin10.firestore.FieldValue.serverTimestamp(),
3404
3432
  updatedAt: admin10.firestore.FieldValue.serverTimestamp()
3405
3433
  };
3434
+ Logger.debug(
3435
+ `[AggService] Setting data for requirement: ${JSON.stringify({
3436
+ id: newInstanceRef.id,
3437
+ patientId: newInstanceData.patientId,
3438
+ appointmentId: newInstanceData.appointmentId,
3439
+ requirementName: newInstanceData.requirementName,
3440
+ instructionsCount: newInstanceData.instructions.length
3441
+ })}`
3442
+ );
3406
3443
  batch.set(newInstanceRef, newInstanceData);
3407
3444
  instancesCreatedCount++;
3408
3445
  Logger.debug(
@@ -3410,10 +3447,18 @@ var AppointmentAggregationService = class {
3410
3447
  );
3411
3448
  }
3412
3449
  if (instancesCreatedCount > 0) {
3413
- await batch.commit();
3414
- Logger.info(
3415
- `[AggService] Successfully created ${instancesCreatedCount} PRE_APPOINTMENT requirement instances for appointment ${appointment.id}.`
3416
- );
3450
+ try {
3451
+ await batch.commit();
3452
+ Logger.info(
3453
+ `[AggService] Successfully created ${instancesCreatedCount} PRE_APPOINTMENT requirement instances for appointment ${appointment.id}.`
3454
+ );
3455
+ } catch (commitError) {
3456
+ Logger.error(
3457
+ `[AggService] Error committing batch for PRE_APPOINTMENT requirement instances for appointment ${appointment.id}:`,
3458
+ commitError
3459
+ );
3460
+ throw commitError;
3461
+ }
3417
3462
  } else {
3418
3463
  Logger.info(
3419
3464
  `[AggService] No new PRE_APPOINTMENT requirement instances were prepared for batch commit for appointment ${appointment.id}.`
@@ -3424,6 +3469,7 @@ var AppointmentAggregationService = class {
3424
3469
  `[AggService] Error creating PRE_APPOINTMENT requirement instances for appointment ${appointment.id}:`,
3425
3470
  error
3426
3471
  );
3472
+ throw error;
3427
3473
  }
3428
3474
  }
3429
3475
  /**
@@ -3290,18 +3290,46 @@ var AppointmentAggregationService = class {
3290
3290
  try {
3291
3291
  const batch = this.db.batch();
3292
3292
  let instancesCreatedCount = 0;
3293
+ Logger.info(
3294
+ `[AggService] Found ${appointment.preProcedureRequirements.length} pre-requirements to process: ${JSON.stringify(
3295
+ appointment.preProcedureRequirements.map((r) => {
3296
+ var _a2, _b;
3297
+ return {
3298
+ id: r.id,
3299
+ name: r.name,
3300
+ type: r.type,
3301
+ isActive: r.isActive,
3302
+ hasTimeframe: !!r.timeframe,
3303
+ notifyAtLength: ((_b = (_a2 = r.timeframe) == null ? void 0 : _a2.notifyAt) == null ? void 0 : _b.length) || 0
3304
+ };
3305
+ })
3306
+ )}`
3307
+ );
3293
3308
  for (const template of appointment.preProcedureRequirements) {
3294
- if (!template) continue;
3309
+ if (!template) {
3310
+ Logger.warn(
3311
+ `[AggService] Found null/undefined template in preProcedureRequirements array`
3312
+ );
3313
+ continue;
3314
+ }
3295
3315
  if (template.type !== "pre" /* PRE */ || !template.isActive) {
3296
3316
  Logger.debug(
3297
3317
  `[AggService] Skipping template ${template.id} (${template.name}): not an active PRE requirement.`
3298
3318
  );
3299
3319
  continue;
3300
3320
  }
3321
+ if (!template.timeframe || !template.timeframe.notifyAt || template.timeframe.notifyAt.length === 0) {
3322
+ Logger.warn(
3323
+ `[AggService] Template ${template.id} (${template.name}) has no timeframe.notifyAt values. Creating with empty instructions.`
3324
+ );
3325
+ }
3301
3326
  Logger.debug(
3302
3327
  `[AggService] Processing template ${template.id} (${template.name}) for appt ${appointment.id}`
3303
3328
  );
3304
3329
  const newInstanceRef = this.db.collection(PATIENTS_COLLECTION).doc(appointment.patientId).collection(PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME).doc();
3330
+ Logger.debug(
3331
+ `[AggService] Created doc reference: ${newInstanceRef.path}`
3332
+ );
3305
3333
  const instructions = (((_a = template.timeframe) == null ? void 0 : _a.notifyAt) || []).map((notifyAtValue) => {
3306
3334
  let dueTime = appointment.appointmentStartTime;
3307
3335
  if (template.timeframe && typeof notifyAtValue === "number") {
@@ -3348,6 +3376,15 @@ var AppointmentAggregationService = class {
3348
3376
  createdAt: admin10.firestore.FieldValue.serverTimestamp(),
3349
3377
  updatedAt: admin10.firestore.FieldValue.serverTimestamp()
3350
3378
  };
3379
+ Logger.debug(
3380
+ `[AggService] Setting data for requirement: ${JSON.stringify({
3381
+ id: newInstanceRef.id,
3382
+ patientId: newInstanceData.patientId,
3383
+ appointmentId: newInstanceData.appointmentId,
3384
+ requirementName: newInstanceData.requirementName,
3385
+ instructionsCount: newInstanceData.instructions.length
3386
+ })}`
3387
+ );
3351
3388
  batch.set(newInstanceRef, newInstanceData);
3352
3389
  instancesCreatedCount++;
3353
3390
  Logger.debug(
@@ -3355,10 +3392,18 @@ var AppointmentAggregationService = class {
3355
3392
  );
3356
3393
  }
3357
3394
  if (instancesCreatedCount > 0) {
3358
- await batch.commit();
3359
- Logger.info(
3360
- `[AggService] Successfully created ${instancesCreatedCount} PRE_APPOINTMENT requirement instances for appointment ${appointment.id}.`
3361
- );
3395
+ try {
3396
+ await batch.commit();
3397
+ Logger.info(
3398
+ `[AggService] Successfully created ${instancesCreatedCount} PRE_APPOINTMENT requirement instances for appointment ${appointment.id}.`
3399
+ );
3400
+ } catch (commitError) {
3401
+ Logger.error(
3402
+ `[AggService] Error committing batch for PRE_APPOINTMENT requirement instances for appointment ${appointment.id}:`,
3403
+ commitError
3404
+ );
3405
+ throw commitError;
3406
+ }
3362
3407
  } else {
3363
3408
  Logger.info(
3364
3409
  `[AggService] No new PRE_APPOINTMENT requirement instances were prepared for batch commit for appointment ${appointment.id}.`
@@ -3369,6 +3414,7 @@ var AppointmentAggregationService = class {
3369
3414
  `[AggService] Error creating PRE_APPOINTMENT requirement instances for appointment ${appointment.id}:`,
3370
3415
  error
3371
3416
  );
3417
+ throw error;
3372
3418
  }
3373
3419
  }
3374
3420
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.6.18",
4
+ "version": "1.6.19",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
@@ -508,8 +508,29 @@ export class AppointmentAggregationService {
508
508
  const batch = this.db.batch();
509
509
  let instancesCreatedCount = 0;
510
510
 
511
+ // Log more details about the pre-requirements
512
+ Logger.info(
513
+ `[AggService] Found ${
514
+ appointment.preProcedureRequirements.length
515
+ } pre-requirements to process: ${JSON.stringify(
516
+ appointment.preProcedureRequirements.map((r) => ({
517
+ id: r.id,
518
+ name: r.name,
519
+ type: r.type,
520
+ isActive: r.isActive,
521
+ hasTimeframe: !!r.timeframe,
522
+ notifyAtLength: r.timeframe?.notifyAt?.length || 0,
523
+ }))
524
+ )}`
525
+ );
526
+
511
527
  for (const template of appointment.preProcedureRequirements) {
512
- if (!template) continue; // Skip if template is null or undefined in the array
528
+ if (!template) {
529
+ Logger.warn(
530
+ `[AggService] Found null/undefined template in preProcedureRequirements array`
531
+ );
532
+ continue;
533
+ }
513
534
 
514
535
  // Ensure it's an active, PRE-type requirement
515
536
  if (template.type !== RequirementType.PRE || !template.isActive) {
@@ -519,6 +540,16 @@ export class AppointmentAggregationService {
519
540
  continue;
520
541
  }
521
542
 
543
+ if (
544
+ !template.timeframe ||
545
+ !template.timeframe.notifyAt ||
546
+ template.timeframe.notifyAt.length === 0
547
+ ) {
548
+ Logger.warn(
549
+ `[AggService] Template ${template.id} (${template.name}) has no timeframe.notifyAt values. Creating with empty instructions.`
550
+ );
551
+ }
552
+
522
553
  Logger.debug(
523
554
  `[AggService] Processing template ${template.id} (${template.name}) for appt ${appointment.id}`
524
555
  );
@@ -529,6 +560,11 @@ export class AppointmentAggregationService {
529
560
  .collection(PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME)
530
561
  .doc(); // Auto-generate ID for the new instance
531
562
 
563
+ // Log the path for debugging
564
+ Logger.debug(
565
+ `[AggService] Created doc reference: ${newInstanceRef.path}`
566
+ );
567
+
532
568
  const instructions: PatientRequirementInstruction[] = (
533
569
  template.timeframe?.notifyAt || []
534
570
  ).map((notifyAtValue) => {
@@ -585,6 +621,17 @@ export class AppointmentAggregationService {
585
621
  updatedAt: admin.firestore.FieldValue.serverTimestamp() as any,
586
622
  };
587
623
 
624
+ // Log the data being set
625
+ Logger.debug(
626
+ `[AggService] Setting data for requirement: ${JSON.stringify({
627
+ id: newInstanceRef.id,
628
+ patientId: newInstanceData.patientId,
629
+ appointmentId: newInstanceData.appointmentId,
630
+ requirementName: newInstanceData.requirementName,
631
+ instructionsCount: newInstanceData.instructions.length,
632
+ })}`
633
+ );
634
+
588
635
  batch.set(newInstanceRef, newInstanceData);
589
636
  instancesCreatedCount++;
590
637
  Logger.debug(
@@ -593,10 +640,18 @@ export class AppointmentAggregationService {
593
640
  }
594
641
 
595
642
  if (instancesCreatedCount > 0) {
596
- await batch.commit();
597
- Logger.info(
598
- `[AggService] Successfully created ${instancesCreatedCount} PRE_APPOINTMENT requirement instances for appointment ${appointment.id}.`
599
- );
643
+ try {
644
+ await batch.commit();
645
+ Logger.info(
646
+ `[AggService] Successfully created ${instancesCreatedCount} PRE_APPOINTMENT requirement instances for appointment ${appointment.id}.`
647
+ );
648
+ } catch (commitError) {
649
+ Logger.error(
650
+ `[AggService] Error committing batch for PRE_APPOINTMENT requirement instances for appointment ${appointment.id}:`,
651
+ commitError
652
+ );
653
+ throw commitError; // Re-throw to ensure the caller knows there was a problem
654
+ }
600
655
  } else {
601
656
  Logger.info(
602
657
  `[AggService] No new PRE_APPOINTMENT requirement instances were prepared for batch commit for appointment ${appointment.id}.`
@@ -607,8 +662,7 @@ export class AppointmentAggregationService {
607
662
  `[AggService] Error creating PRE_APPOINTMENT requirement instances for appointment ${appointment.id}:`,
608
663
  error
609
664
  );
610
- // Rethrow or handle as per error policy, e.g., if this failure should halt further processing.
611
- // For now, just logging.
665
+ throw error; // Re-throw to ensure the caller knows there was a problem
612
666
  }
613
667
  }
614
668