@ubercode/dcmtk 0.10.1 → 0.11.0

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/servers.cjs CHANGED
@@ -3055,14 +3055,32 @@ var DicomReceiver = class _DicomReceiver extends events.EventEmitter {
3055
3055
  return this.on(event, listener);
3056
3056
  }
3057
3057
  /**
3058
- * Registers a listener for received files.
3058
+ * Registers a listener for files received by dcmrecv (before move/parse).
3059
3059
  *
3060
- * @param listener - Callback receiving file data
3060
+ * @param listener - Callback receiving raw file data
3061
3061
  * @returns this for chaining
3062
3062
  */
3063
3063
  onFileReceived(listener) {
3064
3064
  return this.on("FILE_RECEIVED", listener);
3065
3065
  }
3066
+ /**
3067
+ * Registers a listener for files stored in the association directory.
3068
+ *
3069
+ * @param listener - Callback receiving stored file data with size
3070
+ * @returns this for chaining
3071
+ */
3072
+ onFileStored(listener) {
3073
+ return this.on("FILE_STORED", listener);
3074
+ }
3075
+ /**
3076
+ * Registers a listener for parsed DicomInstance availability.
3077
+ *
3078
+ * @param listener - Callback receiving instance data
3079
+ * @returns this for chaining
3080
+ */
3081
+ onInstanceReceived(listener) {
3082
+ return this.on("INSTANCE_RECEIVED", listener);
3083
+ }
3066
3084
  /**
3067
3085
  * Registers a listener for completed associations.
3068
3086
  *
@@ -3356,11 +3374,18 @@ var DicomReceiver = class _DicomReceiver extends events.EventEmitter {
3356
3374
  });
3357
3375
  return;
3358
3376
  }
3377
+ this.emit("FILE_RECEIVED", {
3378
+ filePath: data.filePath,
3379
+ associationId: ctx.associationId,
3380
+ callingAE: data.callingAE,
3381
+ calledAE: data.calledAE,
3382
+ source: data.source
3383
+ });
3359
3384
  const promise = this.handleFileReceived(worker, data, ctx);
3360
3385
  worker.trackFile(promise);
3361
3386
  });
3362
3387
  }
3363
- /** Moves a received file, opens it as DicomInstance, and emits FILE_RECEIVED. */
3388
+ /** Moves file to association dir, emits FILE_STORED, then parses instance. */
3364
3389
  async handleFileReceived(worker, data, ctx) {
3365
3390
  try {
3366
3391
  await this.moveAndEmitFile(worker, data, ctx);
@@ -3377,7 +3402,7 @@ var DicomReceiver = class _DicomReceiver extends events.EventEmitter {
3377
3402
  });
3378
3403
  }
3379
3404
  }
3380
- /** Inner handler: move file, parse DICOM, emit FILE_RECEIVED or error. */
3405
+ /** Inner handler: move file, emit FILE_STORED, parse DICOM, emit INSTANCE_RECEIVED. */
3381
3406
  async moveAndEmitFile(worker, data, ctx) {
3382
3407
  const srcPath = data.filePath;
3383
3408
  const destPath = path__namespace.join(ctx.associationDir, path__namespace.basename(srcPath));
@@ -3385,28 +3410,42 @@ var DicomReceiver = class _DicomReceiver extends events.EventEmitter {
3385
3410
  const finalPath = moveResult.ok ? destPath : srcPath;
3386
3411
  const fileSize = await statFileSafe(finalPath);
3387
3412
  worker.recordFile(finalPath, fileSize);
3388
- const openResult = await DicomInstance.open(finalPath);
3389
- if (!openResult.ok) {
3390
- this.emit("error", {
3391
- error: openResult.error,
3392
- filePath: finalPath,
3393
- associationId: ctx.associationId,
3394
- associationDir: ctx.associationDir,
3395
- callingAE: data.callingAE,
3396
- calledAE: data.calledAE,
3397
- source: data.source
3398
- });
3399
- return;
3400
- }
3401
- this.emit("FILE_RECEIVED", {
3413
+ this.emit("FILE_STORED", {
3402
3414
  filePath: finalPath,
3403
3415
  fileSize,
3404
3416
  associationId: ctx.associationId,
3405
3417
  associationDir: ctx.associationDir,
3406
3418
  callingAE: data.callingAE,
3407
3419
  calledAE: data.calledAE,
3408
- source: data.source,
3409
- instance: openResult.value
3420
+ source: data.source
3421
+ });
3422
+ this.emitInstanceReceived(finalPath, fileSize, data, ctx);
3423
+ }
3424
+ /** Parses a DICOM file and emits INSTANCE_RECEIVED or error. */
3425
+ emitInstanceReceived(filePath, fileSize, data, ctx) {
3426
+ void DicomInstance.open(filePath).then((openResult) => {
3427
+ if (!openResult.ok) {
3428
+ this.emit("error", {
3429
+ error: openResult.error,
3430
+ filePath,
3431
+ associationId: ctx.associationId,
3432
+ associationDir: ctx.associationDir,
3433
+ callingAE: data.callingAE,
3434
+ calledAE: data.calledAE,
3435
+ source: data.source
3436
+ });
3437
+ return;
3438
+ }
3439
+ this.emit("INSTANCE_RECEIVED", {
3440
+ filePath,
3441
+ fileSize,
3442
+ associationId: ctx.associationId,
3443
+ associationDir: ctx.associationDir,
3444
+ callingAE: data.callingAE,
3445
+ calledAE: data.calledAE,
3446
+ source: data.source,
3447
+ instance: openResult.value
3448
+ });
3410
3449
  });
3411
3450
  }
3412
3451
  /** Returns worker to idle pool on association complete, emits summary. */