@ubercode/dcmtk 0.5.0 → 0.6.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.
@@ -1,7 +1,7 @@
1
1
  import { L as LineSource, R as Result } from './types-Cgumy1N4.cjs';
2
2
  import { EventEmitter } from 'node:events';
3
3
  import * as net from 'node:net';
4
- import { d as DicomInstance } from './DicomInstance-DWOjhccQ.cjs';
4
+ import { d as DicomInstance } from './DicomInstance-zsmyd7fs.cjs';
5
5
 
6
6
  /**
7
7
  * Base class for long-lived DCMTK processes (servers).
@@ -1,7 +1,7 @@
1
1
  import { L as LineSource, R as Result } from './types-Cgumy1N4.js';
2
2
  import { EventEmitter } from 'node:events';
3
3
  import * as net from 'node:net';
4
- import { d as DicomInstance } from './DicomInstance-CGBr3a-C.js';
4
+ import { d as DicomInstance } from './DicomInstance-BjrSIEGN.js';
5
5
 
6
6
  /**
7
7
  * Base class for long-lived DCMTK processes (servers).
package/dist/index.cjs CHANGED
@@ -30480,6 +30480,45 @@ function segmentsToModifyPath(segments) {
30480
30480
  function segmentsToString(segments) {
30481
30481
  return segmentsToModifyPath(segments);
30482
30482
  }
30483
+
30484
+ // src/dicom/walkTags.ts
30485
+ var DEFAULT_MAX_DEPTH = 16;
30486
+ function walkTags(data, options) {
30487
+ const ctx = {
30488
+ maxDepth: options?.maxDepth ?? DEFAULT_MAX_DEPTH,
30489
+ vrSet: options?.vrFilter !== void 0 ? new Set(options.vrFilter) : void 0,
30490
+ results: []
30491
+ };
30492
+ walkLevel(data, 0, "", ctx);
30493
+ return ctx.results;
30494
+ }
30495
+ function walkLevel(data, depth, pathPrefix, ctx) {
30496
+ const keys = Object.keys(data);
30497
+ for (let i = 0; i < keys.length; i++) {
30498
+ const tag2 = keys[i];
30499
+ if (tag2 === void 0) continue;
30500
+ const element = data[tag2];
30501
+ if (element === void 0) continue;
30502
+ const vr = element.vr;
30503
+ const path2 = pathPrefix.length > 0 ? `${pathPrefix}.${tag2}` : tag2;
30504
+ if (ctx.vrSet === void 0 || ctx.vrSet.has(vr)) {
30505
+ ctx.results.push({ tag: tag2, element, vr, depth, path: path2 });
30506
+ }
30507
+ if (vr === "SQ" && element.Value !== void 0 && depth < ctx.maxDepth) {
30508
+ walkSequenceItems(element.Value, depth, path2, ctx);
30509
+ }
30510
+ }
30511
+ }
30512
+ function walkSequenceItems(items, depth, parentPath, ctx) {
30513
+ for (let idx = 0; idx < items.length; idx++) {
30514
+ const item = items[idx];
30515
+ if (typeof item !== "object" || item === null) continue;
30516
+ const itemPath = `${parentPath}[${idx}]`;
30517
+ walkLevel(item, depth + 1, itemPath, ctx);
30518
+ }
30519
+ }
30520
+
30521
+ // src/dicom/DicomDataset.ts
30483
30522
  var HEX_TAG_KEY = /^[0-9A-Fa-f]{8}$/;
30484
30523
  function isDicomJsonElement(value) {
30485
30524
  return typeof value === "object" && value !== null && "vr" in value && typeof value["vr"] === "string";
@@ -30808,6 +30847,15 @@ var DicomDataset = class _DicomDataset {
30808
30847
  const result = collectWildcard(this.data, segments);
30809
30848
  return result.values;
30810
30849
  }
30850
+ /**
30851
+ * Walks all tags in this dataset, optionally filtering by VR and recursing into sequences.
30852
+ *
30853
+ * @param options - Optional VR filter and max depth
30854
+ * @returns A readonly array of all matching tag entries
30855
+ */
30856
+ walkTags(options) {
30857
+ return walkTags(this.data, options);
30858
+ }
30811
30859
  // -----------------------------------------------------------------------
30812
30860
  // Convenience readonly getters
30813
30861
  // -----------------------------------------------------------------------
@@ -31286,15 +31334,32 @@ function convertSequence(attr, element) {
31286
31334
  }
31287
31335
  if (values.length > 0) element.Value = values;
31288
31336
  }
31289
- function convertRegularValue(attr, element) {
31337
+ var NUMERIC_JSON_VRS = /* @__PURE__ */ new Set(["DS", "FL", "FD", "IS", "SL", "SS", "SV", "UL", "US", "UV"]);
31338
+ function unwrapValue(v) {
31339
+ if (typeof v !== "object" || v === null) return v;
31340
+ const obj = v;
31341
+ if ("#text" in obj) return obj["#text"];
31342
+ const keys = Object.keys(obj);
31343
+ if (keys.length === 1 && keys[0] !== void 0 && keys[0].startsWith("@_")) {
31344
+ return obj[keys[0]];
31345
+ }
31346
+ return v;
31347
+ }
31348
+ function coerceNumeric(value) {
31349
+ if (typeof value === "number") return value;
31350
+ if (typeof value !== "string") return value;
31351
+ const trimmed = value.trim();
31352
+ if (trimmed.length === 0) return value;
31353
+ const num = Number(trimmed);
31354
+ return Number.isNaN(num) ? value : num;
31355
+ }
31356
+ function convertRegularValue(attr, element, vr) {
31290
31357
  const valArray = toArray(attr.Value);
31291
31358
  const values = [];
31359
+ const isNumeric = NUMERIC_JSON_VRS.has(vr);
31292
31360
  for (const v of valArray) {
31293
- if (typeof v === "object" && v !== null && "#text" in v) {
31294
- values.push(v["#text"]);
31295
- } else {
31296
- values.push(v);
31297
- }
31361
+ const unwrapped = unwrapValue(v);
31362
+ values.push(isNumeric ? coerceNumeric(unwrapped) : unwrapped);
31298
31363
  }
31299
31364
  if (values.length > 0) element.Value = values;
31300
31365
  }
@@ -31311,7 +31376,7 @@ function convertElement(attr) {
31311
31376
  } else if (element.vr === "SQ" && attr.Item !== void 0) {
31312
31377
  convertSequence(attr, element);
31313
31378
  } else if (attr.Value !== void 0) {
31314
- convertRegularValue(attr, element);
31379
+ convertRegularValue(attr, element, vr);
31315
31380
  }
31316
31381
  return Object.freeze(element);
31317
31382
  }
@@ -38032,6 +38097,7 @@ exports.storescu = storescu;
38032
38097
  exports.tag = tag;
38033
38098
  exports.tagPathToSegments = tagPathToSegments;
38034
38099
  exports.termscu = termscu;
38100
+ exports.walkTags = walkTags;
38035
38101
  exports.xml2dcm = xml2dcm;
38036
38102
  exports.xml2dsr = xml2dsr;
38037
38103
  exports.xmlToJson = xmlToJson;