dicom-curate 0.22.0 → 0.23.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.
@@ -79452,7 +79452,7 @@ function getParser(inputPathPattern, inputFilePath, naturalData, dicomPS315EOpti
79452
79452
 
79453
79453
  // src/collectMappings.ts
79454
79454
  var import_lodash3 = __toESM(require_lodash(), 1);
79455
- function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOptions) {
79455
+ function collectMappings(inputFilePath, dicomData, mappingOptions) {
79456
79456
  const mapResults = {
79457
79457
  // original UID for this dicomData
79458
79458
  sourceInstanceUID: "",
@@ -79469,10 +79469,9 @@ function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOption
79469
79469
  );
79470
79470
  mapResults.sourceInstanceUID = naturalData.SOPInstanceUID;
79471
79471
  const finalSpec = composeSpecs(mappingOptions.curationSpec());
79472
- const finalFilePath = finalSpec.dicomPS315EOptions === "Off" ? inputFilePath : inputFilePath.slice(0, inputFilePath.lastIndexOf("/") + 1) + `${String(inputFileIndex + 1).padStart(5, "0")}.dcm`;
79473
79472
  const parser = getParser(
79474
79473
  finalSpec.inputPathPattern,
79475
- finalFilePath,
79474
+ inputFilePath,
79476
79475
  naturalData,
79477
79476
  finalSpec.dicomPS315EOptions,
79478
79477
  mappingOptions.columnMappings,
@@ -79500,6 +79499,14 @@ function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOption
79500
79499
  if (!mappingOptions.skipModifications) {
79501
79500
  mapResults.outputFilePath = finalSpec.outputFilePathComponents(parser).join("/");
79502
79501
  }
79502
+ const rawModality = naturalData.Modality;
79503
+ let modalityStr = "";
79504
+ if (typeof rawModality === "string") {
79505
+ modalityStr = rawModality;
79506
+ } else if (Array.isArray(rawModality) && rawModality.length > 0) {
79507
+ modalityStr = String(rawModality[0]);
79508
+ }
79509
+ const modality = modalityStr.trim().replace(/\W/g, "") || "OT";
79503
79510
  if (finalSpec.dicomPS315EOptions !== "Off") {
79504
79511
  deidentifyPS315E({
79505
79512
  naturalData,
@@ -79508,6 +79515,19 @@ function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOption
79508
79515
  mapResults,
79509
79516
  originalDicomDict: dicomData.dict
79510
79517
  });
79518
+ const mappedInstanceUID = naturalData.SOPInstanceUID;
79519
+ if (mapResults.outputFilePath && mappedInstanceUID) {
79520
+ const parts = mapResults.outputFilePath.split("/");
79521
+ parts[parts.length - 1] = `${modality}_${mappedInstanceUID}.dcm`;
79522
+ mapResults.outputFilePath = parts.join("/");
79523
+ }
79524
+ } else if (mapResults.outputFilePath) {
79525
+ const normaliseFilename = (p4) => p4.replace(/\/+/g, "/").replace(/^\/|\/$/g, "");
79526
+ if (normaliseFilename(mapResults.outputFilePath) !== normaliseFilename(inputFilePath)) {
79527
+ const parts = mapResults.outputFilePath.split("/");
79528
+ parts[parts.length - 1] = `${modality}_${mapResults.sourceInstanceUID}.dcm`;
79529
+ mapResults.outputFilePath = parts.join("/");
79530
+ }
79511
79531
  }
79512
79532
  if (!mappingOptions.skipModifications) {
79513
79533
  const dicomMap = finalSpec.modifyDicomHeader(parser);
@@ -79554,10 +79574,9 @@ function mapMetaheader(metaHeader, newInstanceUid) {
79554
79574
 
79555
79575
  // src/curateDict.ts
79556
79576
  var import_lodash4 = __toESM(require_lodash(), 1);
79557
- function curateDict(inputFilePath, inputFileIndex, dicomData, mappingOptions) {
79577
+ function curateDict(inputFilePath, dicomData, mappingOptions) {
79558
79578
  const [naturalData, mapResults] = collectMappings(
79559
79579
  inputFilePath,
79560
- inputFileIndex,
79561
79580
  dicomData,
79562
79581
  mappingOptions
79563
79582
  );
@@ -79731,7 +79750,6 @@ async function loadS3Client() {
79731
79750
  // src/curateOne.ts
79732
79751
  async function curateOne({
79733
79752
  fileInfo,
79734
- fileIndex = 0,
79735
79753
  outputTarget,
79736
79754
  mappingOptions,
79737
79755
  hashMethod,
@@ -79901,12 +79919,7 @@ async function curateOne({
79901
79919
  };
79902
79920
  return mapResults;
79903
79921
  }
79904
- const { dicomData: mappedDicomData, mapResults: clonedMapResults } = curateDict(
79905
- `${fileInfo.path}/${fileInfo.name}`,
79906
- fileIndex,
79907
- dicomData,
79908
- mappingOptions
79909
- );
79922
+ const { dicomData: mappedDicomData, mapResults: clonedMapResults } = curateDict(`${fileInfo.path}/${fileInfo.name}`, dicomData, mappingOptions);
79910
79923
  clonedMapResults.mappingRequired = true;
79911
79924
  if (!preMappedHash) {
79912
79925
  try {
@@ -80014,7 +80027,8 @@ async function curateOne({
80014
80027
  forcePathStyle: outputTarget.s3.forcePathStyle
80015
80028
  });
80016
80029
  try {
80017
- const key = outputTarget.s3.prefix + clonedMapResults.outputFilePath;
80030
+ const prefix = outputTarget.s3.prefix ? outputTarget.s3.prefix.endsWith("/") ? outputTarget.s3.prefix : outputTarget.s3.prefix + "/" : "";
80031
+ const key = prefix + clonedMapResults.outputFilePath;
80018
80032
  await client.send(
80019
80033
  new s32.PutObjectCommand({
80020
80034
  Bucket: outputTarget.s3.bucketName,
@@ -85716,7 +85730,6 @@ fixupNodeWorkerEnvironment().then(() => {
85716
85730
  try {
85717
85731
  curateOne({
85718
85732
  fileInfo,
85719
- fileIndex: event.data.fileIndex,
85720
85733
  outputTarget: event.data.outputTarget || {},
85721
85734
  hashMethod: event.data.hashMethod,
85722
85735
  mappingOptions,
@@ -35446,7 +35446,7 @@ function getParser(inputPathPattern, inputFilePath, naturalData, dicomPS315EOpti
35446
35446
 
35447
35447
  // src/collectMappings.ts
35448
35448
  var import_lodash3 = __toESM(require_lodash(), 1);
35449
- function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOptions) {
35449
+ function collectMappings(inputFilePath, dicomData, mappingOptions) {
35450
35450
  const mapResults = {
35451
35451
  // original UID for this dicomData
35452
35452
  sourceInstanceUID: "",
@@ -35463,10 +35463,9 @@ function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOption
35463
35463
  );
35464
35464
  mapResults.sourceInstanceUID = naturalData.SOPInstanceUID;
35465
35465
  const finalSpec = composeSpecs(mappingOptions.curationSpec());
35466
- const finalFilePath = finalSpec.dicomPS315EOptions === "Off" ? inputFilePath : inputFilePath.slice(0, inputFilePath.lastIndexOf("/") + 1) + `${String(inputFileIndex + 1).padStart(5, "0")}.dcm`;
35467
35466
  const parser = getParser(
35468
35467
  finalSpec.inputPathPattern,
35469
- finalFilePath,
35468
+ inputFilePath,
35470
35469
  naturalData,
35471
35470
  finalSpec.dicomPS315EOptions,
35472
35471
  mappingOptions.columnMappings,
@@ -35494,6 +35493,14 @@ function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOption
35494
35493
  if (!mappingOptions.skipModifications) {
35495
35494
  mapResults.outputFilePath = finalSpec.outputFilePathComponents(parser).join("/");
35496
35495
  }
35496
+ const rawModality = naturalData.Modality;
35497
+ let modalityStr = "";
35498
+ if (typeof rawModality === "string") {
35499
+ modalityStr = rawModality;
35500
+ } else if (Array.isArray(rawModality) && rawModality.length > 0) {
35501
+ modalityStr = String(rawModality[0]);
35502
+ }
35503
+ const modality = modalityStr.trim().replace(/\W/g, "") || "OT";
35497
35504
  if (finalSpec.dicomPS315EOptions !== "Off") {
35498
35505
  deidentifyPS315E({
35499
35506
  naturalData,
@@ -35502,6 +35509,19 @@ function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOption
35502
35509
  mapResults,
35503
35510
  originalDicomDict: dicomData.dict
35504
35511
  });
35512
+ const mappedInstanceUID = naturalData.SOPInstanceUID;
35513
+ if (mapResults.outputFilePath && mappedInstanceUID) {
35514
+ const parts = mapResults.outputFilePath.split("/");
35515
+ parts[parts.length - 1] = `${modality}_${mappedInstanceUID}.dcm`;
35516
+ mapResults.outputFilePath = parts.join("/");
35517
+ }
35518
+ } else if (mapResults.outputFilePath) {
35519
+ const normaliseFilename = (p) => p.replace(/\/+/g, "/").replace(/^\/|\/$/g, "");
35520
+ if (normaliseFilename(mapResults.outputFilePath) !== normaliseFilename(inputFilePath)) {
35521
+ const parts = mapResults.outputFilePath.split("/");
35522
+ parts[parts.length - 1] = `${modality}_${mapResults.sourceInstanceUID}.dcm`;
35523
+ mapResults.outputFilePath = parts.join("/");
35524
+ }
35505
35525
  }
35506
35526
  if (!mappingOptions.skipModifications) {
35507
35527
  const dicomMap = finalSpec.modifyDicomHeader(parser);
@@ -35463,7 +35463,7 @@ function getParser(inputPathPattern, inputFilePath, naturalData, dicomPS315EOpti
35463
35463
 
35464
35464
  // src/collectMappings.ts
35465
35465
  var import_lodash3 = __toESM(require_lodash(), 1);
35466
- function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOptions) {
35466
+ function collectMappings(inputFilePath, dicomData, mappingOptions) {
35467
35467
  const mapResults = {
35468
35468
  // original UID for this dicomData
35469
35469
  sourceInstanceUID: "",
@@ -35480,10 +35480,9 @@ function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOption
35480
35480
  );
35481
35481
  mapResults.sourceInstanceUID = naturalData.SOPInstanceUID;
35482
35482
  const finalSpec = composeSpecs(mappingOptions.curationSpec());
35483
- const finalFilePath = finalSpec.dicomPS315EOptions === "Off" ? inputFilePath : inputFilePath.slice(0, inputFilePath.lastIndexOf("/") + 1) + `${String(inputFileIndex + 1).padStart(5, "0")}.dcm`;
35484
35483
  const parser = getParser(
35485
35484
  finalSpec.inputPathPattern,
35486
- finalFilePath,
35485
+ inputFilePath,
35487
35486
  naturalData,
35488
35487
  finalSpec.dicomPS315EOptions,
35489
35488
  mappingOptions.columnMappings,
@@ -35511,6 +35510,14 @@ function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOption
35511
35510
  if (!mappingOptions.skipModifications) {
35512
35511
  mapResults.outputFilePath = finalSpec.outputFilePathComponents(parser).join("/");
35513
35512
  }
35513
+ const rawModality = naturalData.Modality;
35514
+ let modalityStr = "";
35515
+ if (typeof rawModality === "string") {
35516
+ modalityStr = rawModality;
35517
+ } else if (Array.isArray(rawModality) && rawModality.length > 0) {
35518
+ modalityStr = String(rawModality[0]);
35519
+ }
35520
+ const modality = modalityStr.trim().replace(/\W/g, "") || "OT";
35514
35521
  if (finalSpec.dicomPS315EOptions !== "Off") {
35515
35522
  deidentifyPS315E({
35516
35523
  naturalData,
@@ -35519,6 +35526,19 @@ function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOption
35519
35526
  mapResults,
35520
35527
  originalDicomDict: dicomData.dict
35521
35528
  });
35529
+ const mappedInstanceUID = naturalData.SOPInstanceUID;
35530
+ if (mapResults.outputFilePath && mappedInstanceUID) {
35531
+ const parts = mapResults.outputFilePath.split("/");
35532
+ parts[parts.length - 1] = `${modality}_${mappedInstanceUID}.dcm`;
35533
+ mapResults.outputFilePath = parts.join("/");
35534
+ }
35535
+ } else if (mapResults.outputFilePath) {
35536
+ const normaliseFilename = (p) => p.replace(/\/+/g, "/").replace(/^\/|\/$/g, "");
35537
+ if (normaliseFilename(mapResults.outputFilePath) !== normaliseFilename(inputFilePath)) {
35538
+ const parts = mapResults.outputFilePath.split("/");
35539
+ parts[parts.length - 1] = `${modality}_${mapResults.sourceInstanceUID}.dcm`;
35540
+ mapResults.outputFilePath = parts.join("/");
35541
+ }
35522
35542
  }
35523
35543
  if (!mappingOptions.skipModifications) {
35524
35544
  const dicomMap = finalSpec.modifyDicomHeader(parser);
@@ -35565,10 +35585,9 @@ function mapMetaheader(metaHeader, newInstanceUid) {
35565
35585
 
35566
35586
  // src/curateDict.ts
35567
35587
  var import_lodash4 = __toESM(require_lodash(), 1);
35568
- function curateDict(inputFilePath, inputFileIndex, dicomData, mappingOptions) {
35588
+ function curateDict(inputFilePath, dicomData, mappingOptions) {
35569
35589
  const [naturalData, mapResults] = collectMappings(
35570
35590
  inputFilePath,
35571
- inputFileIndex,
35572
35591
  dicomData,
35573
35592
  mappingOptions
35574
35593
  );
@@ -73161,7 +73161,7 @@ function getParser(inputPathPattern, inputFilePath, naturalData, dicomPS315EOpti
73161
73161
 
73162
73162
  // src/collectMappings.ts
73163
73163
  var import_lodash3 = __toESM(require_lodash(), 1);
73164
- function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOptions) {
73164
+ function collectMappings(inputFilePath, dicomData, mappingOptions) {
73165
73165
  const mapResults = {
73166
73166
  // original UID for this dicomData
73167
73167
  sourceInstanceUID: "",
@@ -73178,10 +73178,9 @@ function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOption
73178
73178
  );
73179
73179
  mapResults.sourceInstanceUID = naturalData.SOPInstanceUID;
73180
73180
  const finalSpec = composeSpecs(mappingOptions.curationSpec());
73181
- const finalFilePath = finalSpec.dicomPS315EOptions === "Off" ? inputFilePath : inputFilePath.slice(0, inputFilePath.lastIndexOf("/") + 1) + `${String(inputFileIndex + 1).padStart(5, "0")}.dcm`;
73182
73181
  const parser = getParser(
73183
73182
  finalSpec.inputPathPattern,
73184
- finalFilePath,
73183
+ inputFilePath,
73185
73184
  naturalData,
73186
73185
  finalSpec.dicomPS315EOptions,
73187
73186
  mappingOptions.columnMappings,
@@ -73209,6 +73208,14 @@ function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOption
73209
73208
  if (!mappingOptions.skipModifications) {
73210
73209
  mapResults.outputFilePath = finalSpec.outputFilePathComponents(parser).join("/");
73211
73210
  }
73211
+ const rawModality = naturalData.Modality;
73212
+ let modalityStr = "";
73213
+ if (typeof rawModality === "string") {
73214
+ modalityStr = rawModality;
73215
+ } else if (Array.isArray(rawModality) && rawModality.length > 0) {
73216
+ modalityStr = String(rawModality[0]);
73217
+ }
73218
+ const modality = modalityStr.trim().replace(/\W/g, "") || "OT";
73212
73219
  if (finalSpec.dicomPS315EOptions !== "Off") {
73213
73220
  deidentifyPS315E({
73214
73221
  naturalData,
@@ -73217,6 +73224,19 @@ function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOption
73217
73224
  mapResults,
73218
73225
  originalDicomDict: dicomData.dict
73219
73226
  });
73227
+ const mappedInstanceUID = naturalData.SOPInstanceUID;
73228
+ if (mapResults.outputFilePath && mappedInstanceUID) {
73229
+ const parts = mapResults.outputFilePath.split("/");
73230
+ parts[parts.length - 1] = `${modality}_${mappedInstanceUID}.dcm`;
73231
+ mapResults.outputFilePath = parts.join("/");
73232
+ }
73233
+ } else if (mapResults.outputFilePath) {
73234
+ const normaliseFilename = (p4) => p4.replace(/\/+/g, "/").replace(/^\/|\/$/g, "");
73235
+ if (normaliseFilename(mapResults.outputFilePath) !== normaliseFilename(inputFilePath)) {
73236
+ const parts = mapResults.outputFilePath.split("/");
73237
+ parts[parts.length - 1] = `${modality}_${mapResults.sourceInstanceUID}.dcm`;
73238
+ mapResults.outputFilePath = parts.join("/");
73239
+ }
73220
73240
  }
73221
73241
  if (!mappingOptions.skipModifications) {
73222
73242
  const dicomMap = finalSpec.modifyDicomHeader(parser);
@@ -73263,10 +73283,9 @@ function mapMetaheader(metaHeader, newInstanceUid) {
73263
73283
 
73264
73284
  // src/curateDict.ts
73265
73285
  var import_lodash4 = __toESM(require_lodash(), 1);
73266
- function curateDict(inputFilePath, inputFileIndex, dicomData, mappingOptions) {
73286
+ function curateDict(inputFilePath, dicomData, mappingOptions) {
73267
73287
  const [naturalData, mapResults] = collectMappings(
73268
73288
  inputFilePath,
73269
- inputFileIndex,
73270
73289
  dicomData,
73271
73290
  mappingOptions
73272
73291
  );
@@ -73440,7 +73459,6 @@ async function loadS3Client() {
73440
73459
  // src/curateOne.ts
73441
73460
  async function curateOne({
73442
73461
  fileInfo,
73443
- fileIndex = 0,
73444
73462
  outputTarget,
73445
73463
  mappingOptions,
73446
73464
  hashMethod,
@@ -73610,12 +73628,7 @@ async function curateOne({
73610
73628
  };
73611
73629
  return mapResults;
73612
73630
  }
73613
- const { dicomData: mappedDicomData, mapResults: clonedMapResults } = curateDict(
73614
- `${fileInfo.path}/${fileInfo.name}`,
73615
- fileIndex,
73616
- dicomData,
73617
- mappingOptions
73618
- );
73631
+ const { dicomData: mappedDicomData, mapResults: clonedMapResults } = curateDict(`${fileInfo.path}/${fileInfo.name}`, dicomData, mappingOptions);
73619
73632
  clonedMapResults.mappingRequired = true;
73620
73633
  if (!preMappedHash) {
73621
73634
  try {
@@ -73723,7 +73736,8 @@ async function curateOne({
73723
73736
  forcePathStyle: outputTarget.s3.forcePathStyle
73724
73737
  });
73725
73738
  try {
73726
- const key = outputTarget.s3.prefix + clonedMapResults.outputFilePath;
73739
+ const prefix = outputTarget.s3.prefix ? outputTarget.s3.prefix.endsWith("/") ? outputTarget.s3.prefix : outputTarget.s3.prefix + "/" : "";
73740
+ const key = prefix + clonedMapResults.outputFilePath;
73727
73741
  await client.send(
73728
73742
  new s32.PutObjectCommand({
73729
73743
  Bucket: outputTarget.s3.bucketName,
package/dist/esm/index.js CHANGED
@@ -81012,7 +81012,7 @@ function getParser(inputPathPattern, inputFilePath, naturalData, dicomPS315EOpti
81012
81012
 
81013
81013
  // src/collectMappings.ts
81014
81014
  var import_lodash3 = __toESM(require_lodash(), 1);
81015
- function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOptions) {
81015
+ function collectMappings(inputFilePath, dicomData, mappingOptions) {
81016
81016
  const mapResults = {
81017
81017
  // original UID for this dicomData
81018
81018
  sourceInstanceUID: "",
@@ -81029,10 +81029,9 @@ function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOption
81029
81029
  );
81030
81030
  mapResults.sourceInstanceUID = naturalData.SOPInstanceUID;
81031
81031
  const finalSpec = composeSpecs(mappingOptions.curationSpec());
81032
- const finalFilePath = finalSpec.dicomPS315EOptions === "Off" ? inputFilePath : inputFilePath.slice(0, inputFilePath.lastIndexOf("/") + 1) + `${String(inputFileIndex + 1).padStart(5, "0")}.dcm`;
81033
81032
  const parser = getParser(
81034
81033
  finalSpec.inputPathPattern,
81035
- finalFilePath,
81034
+ inputFilePath,
81036
81035
  naturalData,
81037
81036
  finalSpec.dicomPS315EOptions,
81038
81037
  mappingOptions.columnMappings,
@@ -81060,6 +81059,14 @@ function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOption
81060
81059
  if (!mappingOptions.skipModifications) {
81061
81060
  mapResults.outputFilePath = finalSpec.outputFilePathComponents(parser).join("/");
81062
81061
  }
81062
+ const rawModality = naturalData.Modality;
81063
+ let modalityStr = "";
81064
+ if (typeof rawModality === "string") {
81065
+ modalityStr = rawModality;
81066
+ } else if (Array.isArray(rawModality) && rawModality.length > 0) {
81067
+ modalityStr = String(rawModality[0]);
81068
+ }
81069
+ const modality = modalityStr.trim().replace(/\W/g, "") || "OT";
81063
81070
  if (finalSpec.dicomPS315EOptions !== "Off") {
81064
81071
  deidentifyPS315E({
81065
81072
  naturalData,
@@ -81068,6 +81075,19 @@ function collectMappings(inputFilePath, inputFileIndex, dicomData, mappingOption
81068
81075
  mapResults,
81069
81076
  originalDicomDict: dicomData.dict
81070
81077
  });
81078
+ const mappedInstanceUID = naturalData.SOPInstanceUID;
81079
+ if (mapResults.outputFilePath && mappedInstanceUID) {
81080
+ const parts = mapResults.outputFilePath.split("/");
81081
+ parts[parts.length - 1] = `${modality}_${mappedInstanceUID}.dcm`;
81082
+ mapResults.outputFilePath = parts.join("/");
81083
+ }
81084
+ } else if (mapResults.outputFilePath) {
81085
+ const normaliseFilename = (p4) => p4.replace(/\/+/g, "/").replace(/^\/|\/$/g, "");
81086
+ if (normaliseFilename(mapResults.outputFilePath) !== normaliseFilename(inputFilePath)) {
81087
+ const parts = mapResults.outputFilePath.split("/");
81088
+ parts[parts.length - 1] = `${modality}_${mapResults.sourceInstanceUID}.dcm`;
81089
+ mapResults.outputFilePath = parts.join("/");
81090
+ }
81071
81091
  }
81072
81092
  if (!mappingOptions.skipModifications) {
81073
81093
  const dicomMap = finalSpec.modifyDicomHeader(parser);
@@ -81114,10 +81134,9 @@ function mapMetaheader(metaHeader, newInstanceUid) {
81114
81134
 
81115
81135
  // src/curateDict.ts
81116
81136
  var import_lodash4 = __toESM(require_lodash(), 1);
81117
- function curateDict(inputFilePath, inputFileIndex, dicomData, mappingOptions) {
81137
+ function curateDict(inputFilePath, dicomData, mappingOptions) {
81118
81138
  const [naturalData, mapResults] = collectMappings(
81119
81139
  inputFilePath,
81120
- inputFileIndex,
81121
81140
  dicomData,
81122
81141
  mappingOptions
81123
81142
  );
@@ -81291,7 +81310,6 @@ async function loadS3Client() {
81291
81310
  // src/curateOne.ts
81292
81311
  async function curateOne({
81293
81312
  fileInfo,
81294
- fileIndex = 0,
81295
81313
  outputTarget,
81296
81314
  mappingOptions,
81297
81315
  hashMethod,
@@ -81461,12 +81479,7 @@ async function curateOne({
81461
81479
  };
81462
81480
  return mapResults;
81463
81481
  }
81464
- const { dicomData: mappedDicomData, mapResults: clonedMapResults } = curateDict(
81465
- `${fileInfo.path}/${fileInfo.name}`,
81466
- fileIndex,
81467
- dicomData,
81468
- mappingOptions
81469
- );
81482
+ const { dicomData: mappedDicomData, mapResults: clonedMapResults } = curateDict(`${fileInfo.path}/${fileInfo.name}`, dicomData, mappingOptions);
81470
81483
  clonedMapResults.mappingRequired = true;
81471
81484
  if (!preMappedHash) {
81472
81485
  try {
@@ -81574,7 +81587,8 @@ async function curateOne({
81574
81587
  forcePathStyle: outputTarget.s3.forcePathStyle
81575
81588
  });
81576
81589
  try {
81577
- const key = outputTarget.s3.prefix + clonedMapResults.outputFilePath;
81590
+ const prefix = outputTarget.s3.prefix ? outputTarget.s3.prefix.endsWith("/") ? outputTarget.s3.prefix : outputTarget.s3.prefix + "/" : "";
81591
+ const key = prefix + clonedMapResults.outputFilePath;
81578
81592
  await client.send(
81579
81593
  new s32.PutObjectCommand({
81580
81594
  Bucket: outputTarget.s3.bucketName,
@@ -87355,9 +87369,8 @@ async function initializeFileListWorker() {
87355
87369
  (event) => {
87356
87370
  switch (event.data.response) {
87357
87371
  case "file": {
87358
- const { fileIndex, fileInfo, previousFileInfo } = event.data;
87372
+ const { fileInfo, previousFileInfo } = event.data;
87359
87373
  filesToProcess.push({
87360
- fileIndex,
87361
87374
  fileInfo,
87362
87375
  scanAnomalies: [],
87363
87376
  // Files sent to processing have no scan anomalies
@@ -87492,7 +87505,7 @@ async function getHttpOutputHeaders(outputTarget) {
87492
87505
  }
87493
87506
  async function dispatchMappingJobs() {
87494
87507
  while (filesToProcess.length > 0 && availableMappingWorkers.length > 0) {
87495
- const { fileInfo, fileIndex, previousFileInfo } = filesToProcess.pop();
87508
+ const { fileInfo, previousFileInfo } = filesToProcess.pop();
87496
87509
  const mappingWorker = availableMappingWorkers.pop();
87497
87510
  const { outputTarget, hashMethod, ...mappingOptions } = (
87498
87511
  // Not partial anymore.
@@ -87501,7 +87514,6 @@ async function dispatchMappingJobs() {
87501
87514
  mappingWorker.postMessage({
87502
87515
  request: "apply",
87503
87516
  fileInfo: await getHttpInputHeaders(fileInfo),
87504
- fileIndex,
87505
87517
  outputTarget: await getHttpOutputHeaders(outputTarget),
87506
87518
  previousFileInfo,
87507
87519
  hashMethod,
@@ -87582,7 +87594,7 @@ async function collectMappingOptions(organizeOptions) {
87582
87594
  };
87583
87595
  }
87584
87596
  function queueFilesForMapping(organizeOptions) {
87585
- organizeOptions.inputFiles.forEach((inputFile, fileIndex) => {
87597
+ organizeOptions.inputFiles.forEach((inputFile) => {
87586
87598
  const fileInfo = {
87587
87599
  path: "",
87588
87600
  name: inputFile.name,
@@ -87592,14 +87604,13 @@ function queueFilesForMapping(organizeOptions) {
87592
87604
  };
87593
87605
  filesToProcess.push({
87594
87606
  fileInfo,
87595
- fileIndex,
87596
87607
  scanAnomalies: []
87597
87608
  });
87598
87609
  });
87599
87610
  dispatchMappingJobs();
87600
87611
  }
87601
87612
  function queueUrlsForMapping(organizeOptions) {
87602
- organizeOptions.inputUrls.forEach((inputUrl, fileIndex) => {
87613
+ organizeOptions.inputUrls.forEach((inputUrl) => {
87603
87614
  const fileInfo = {
87604
87615
  kind: "http",
87605
87616
  url: inputUrl,
@@ -87610,7 +87621,6 @@ function queueUrlsForMapping(organizeOptions) {
87610
87621
  };
87611
87622
  filesToProcess.push({
87612
87623
  fileInfo,
87613
- fileIndex,
87614
87624
  scanAnomalies: []
87615
87625
  });
87616
87626
  });
@@ -37299,7 +37299,6 @@ async function scanS3Bucket(bucketOptions) {
37299
37299
  forcePathStyle: bucketOptions.forcePathStyle
37300
37300
  });
37301
37301
  let continuationToken = void 0;
37302
- let fileIndex = 0;
37303
37302
  do {
37304
37303
  const listCommand = new s32.ListObjectsV2Command({
37305
37304
  Bucket: bucketOptions.bucketName,
@@ -37314,7 +37313,6 @@ async function scanS3Bucket(bucketOptions) {
37314
37313
  const prev = previousIndex ? previousIndex[item.Key] : void 0;
37315
37314
  globalThis.postMessage({
37316
37315
  response: "file",
37317
- fileIndex: fileIndex++,
37318
37316
  fileInfo: {
37319
37317
  size: item.Size,
37320
37318
  name: item.Key,
@@ -37325,12 +37323,10 @@ async function scanS3Bucket(bucketOptions) {
37325
37323
  },
37326
37324
  previousFileInfo: prev
37327
37325
  });
37328
- fileIndex += 1;
37329
37326
  } else if (fileAnomalies.length > 0) {
37330
37327
  const prev = previousIndex ? previousIndex[item.Key] : void 0;
37331
37328
  globalThis.postMessage({
37332
37329
  response: "scanAnomalies",
37333
- fileIndex: fileIndex++,
37334
37330
  fileInfo: {
37335
37331
  size: item.Size,
37336
37332
  name: item.Key,
@@ -37359,26 +37355,17 @@ async function scanS3Bucket(bucketOptions) {
37359
37355
  }
37360
37356
  async function scanDirectory(dir) {
37361
37357
  async function traverse(dir2, prefix) {
37362
- const entries = [];
37363
37358
  for await (const entry of dir2.values()) {
37364
- entries.push(entry);
37365
- }
37366
- entries.sort((a4, b4) => a4.name.localeCompare(b4.name));
37367
- let fileIndex = 0;
37368
- for (const entry of entries) {
37369
- if (entry.kind === "file" && keepScanning) {
37359
+ if (!keepScanning)
37360
+ return;
37361
+ if (entry.kind === "file") {
37370
37362
  const file = await entry.getFile();
37371
37363
  const fileAnomalies = [];
37372
- if (await shouldProcessFile(
37373
- file,
37374
- fileAnomalies,
37375
- `${prefix}/${entry.name}`
37376
- )) {
37364
+ if (await shouldProcessFile(file, fileAnomalies, `${prefix}/${entry.name}`)) {
37377
37365
  const key = `${prefix}/${entry.name}`;
37378
37366
  const prev = previousIndex ? previousIndex[key] : void 0;
37379
37367
  globalThis.postMessage({
37380
37368
  response: "file",
37381
- fileIndex: fileIndex++,
37382
37369
  fileInfo: {
37383
37370
  path: prefix,
37384
37371
  name: entry.name,
@@ -37393,7 +37380,6 @@ async function scanDirectory(dir) {
37393
37380
  const prev = previousIndex ? previousIndex[key] : void 0;
37394
37381
  globalThis.postMessage({
37395
37382
  response: "scanAnomalies",
37396
- fileIndex: fileIndex++,
37397
37383
  fileInfo: {
37398
37384
  path: prefix,
37399
37385
  name: entry.name,
@@ -37405,7 +37391,7 @@ async function scanDirectory(dir) {
37405
37391
  previousFileInfo: prev
37406
37392
  });
37407
37393
  }
37408
- } else if (entry.kind === "directory" && keepScanning) {
37394
+ } else if (entry.kind === "directory") {
37409
37395
  await traverse(
37410
37396
  entry,
37411
37397
  prefix + "/" + entry.name
@@ -37430,10 +37416,10 @@ async function scanDirectoryNode(dirPath) {
37430
37416
  const path = await import("path");
37431
37417
  async function traverse(currentPath, prefix) {
37432
37418
  const entries = await fs.readdir(currentPath, { withFileTypes: true });
37433
- entries.sort((a4, b4) => a4.name.localeCompare(b4.name));
37434
- let fileIndex = 0;
37435
37419
  for (const entry of entries) {
37436
- if (entry.isFile() && keepScanning) {
37420
+ if (!keepScanning)
37421
+ return;
37422
+ if (entry.isFile()) {
37437
37423
  const filePath = path.join(currentPath, entry.name);
37438
37424
  const stats = await fs.stat(filePath);
37439
37425
  const fileAnomalies = [];
@@ -37446,7 +37432,6 @@ async function scanDirectoryNode(dirPath) {
37446
37432
  )) {
37447
37433
  globalThis.postMessage({
37448
37434
  response: "file",
37449
- fileIndex: fileIndex++,
37450
37435
  fileInfo: {
37451
37436
  path: prefix,
37452
37437
  name: entry.name,
@@ -37458,7 +37443,6 @@ async function scanDirectoryNode(dirPath) {
37458
37443
  } else if (fileAnomalies.length > 0) {
37459
37444
  globalThis.postMessage({
37460
37445
  response: "scanAnomalies",
37461
- fileIndex: fileIndex++,
37462
37446
  fileInfo: {
37463
37447
  path: prefix,
37464
37448
  name: entry.name,
@@ -37469,7 +37453,7 @@ async function scanDirectoryNode(dirPath) {
37469
37453
  anomalies: fileAnomalies
37470
37454
  });
37471
37455
  }
37472
- } else if (entry.isDirectory() && keepScanning) {
37456
+ } else if (entry.isDirectory()) {
37473
37457
  await traverse(
37474
37458
  path.join(currentPath, entry.name),
37475
37459
  prefix + "/" + entry.name
@@ -2,7 +2,6 @@ import { type TFileInfo, type TSerializedMappingOptions, type THTTPOptions, type
2
2
  export type MappingRequest = {
3
3
  request: 'apply';
4
4
  fileInfo: TFileInfo;
5
- fileIndex: number;
6
5
  outputTarget?: {
7
6
  http?: THTTPOptions;
8
7
  directory?: FileSystemDirectoryHandle | string;
@@ -1,3 +1,3 @@
1
1
  import type { TMappingOptions, TMapResults } from './types';
2
2
  import type { TDicomData, TNaturalData } from 'dcmjs';
3
- export default function collectMappings(inputFilePath: string, inputFileIndex: number, dicomData: TDicomData, mappingOptions: TMappingOptions): [TNaturalData, TMapResults];
3
+ export default function collectMappings(inputFilePath: string, dicomData: TDicomData, mappingOptions: TMappingOptions): [TNaturalData, TMapResults];
@@ -1,7 +1,7 @@
1
1
  import * as dcmjs from 'dcmjs';
2
2
  import type { TDicomData } from 'dcmjs';
3
3
  import type { TMappingOptions } from './types';
4
- export default function curateDict(inputFilePath: string, inputFileIndex: number, dicomData: TDicomData, mappingOptions: TMappingOptions): {
4
+ export default function curateDict(inputFilePath: string, dicomData: TDicomData, mappingOptions: TMappingOptions): {
5
5
  dicomData: dcmjs.data.DicomDict;
6
6
  mapResults: import("./types").TMapResults;
7
7
  };
@@ -1,7 +1,6 @@
1
1
  import type { TFileInfo, THashMethod, THTTPOptions, TMappingOptions, TMapResults, TS3BucketOptions } from './types';
2
2
  export type TCurateOneArgs = {
3
3
  fileInfo: TFileInfo;
4
- fileIndex?: number;
5
4
  outputTarget: {
6
5
  http?: THTTPOptions;
7
6
  s3?: TS3BucketOptions;
@@ -18,6 +17,6 @@ export type TCurateOneArgs = {
18
17
  postMappedHash?: string;
19
18
  } | undefined;
20
19
  };
21
- export declare function curateOne({ fileInfo, fileIndex, outputTarget, mappingOptions, hashMethod, previousSourceFileInfo, previousMappedFileInfo, }: TCurateOneArgs): Promise<Omit<Partial<TMapResults>, 'anomalies'> & {
20
+ export declare function curateOne({ fileInfo, outputTarget, mappingOptions, hashMethod, previousSourceFileInfo, previousMappedFileInfo, }: TCurateOneArgs): Promise<Omit<Partial<TMapResults>, 'anomalies'> & {
22
21
  anomalies: TMapResults['anomalies'];
23
22
  }>;
@@ -2,7 +2,6 @@ import type { TFileInfo, TFileInfoIndex, TS3BucketOptions } from './types';
2
2
  export {};
3
3
  export type FileScanMsg = {
4
4
  response: 'file';
5
- fileIndex: number;
6
5
  fileInfo: TFileInfo;
7
6
  previousFileInfo?: {
8
7
  size?: number;
@@ -11,7 +10,6 @@ export type FileScanMsg = {
11
10
  };
12
11
  } | {
13
12
  response: 'scanAnomalies';
14
- fileIndex: number;
15
13
  fileInfo: TFileInfo;
16
14
  anomalies: string[];
17
15
  previousFileInfo?: {