@ubercode/dcmtk 0.4.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.
package/dist/tools.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { R as Result } from './types-Cgumy1N4.cjs';
2
- import { d as ToolBaseOptions, c as DicomJsonModel } from './dcmodify-B9js5K1f.cjs';
3
- export { a as DcmodifyOptions, b as DcmodifyResult, D as DicomJsonElement, T as TagModification, e as dcmodify } from './dcmodify-B9js5K1f.cjs';
2
+ import { d as ToolBaseOptions, a as DicomJsonModel } from './dcmodify-Cf-RPHF3.cjs';
3
+ export { b as DcmodifyOptions, c as DcmodifyResult, D as DicomJsonElement, T as TagModification, e as dcmodify } from './dcmodify-Cf-RPHF3.cjs';
4
4
 
5
5
  /**
6
6
  * DICOM to XML conversion using the dcm2xml binary.
package/dist/tools.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { R as Result } from './types-Cgumy1N4.js';
2
- import { d as ToolBaseOptions, c as DicomJsonModel } from './dcmodify-BvaIeyJg.js';
3
- export { a as DcmodifyOptions, b as DcmodifyResult, D as DicomJsonElement, T as TagModification, e as dcmodify } from './dcmodify-BvaIeyJg.js';
2
+ import { d as ToolBaseOptions, a as DicomJsonModel } from './dcmodify-CHvwChFu.js';
3
+ export { b as DcmodifyOptions, c as DcmodifyResult, D as DicomJsonElement, T as TagModification, e as dcmodify } from './dcmodify-CHvwChFu.js';
4
4
 
5
5
  /**
6
6
  * DICOM to XML conversion using the dcm2xml binary.
package/dist/tools.js CHANGED
@@ -401,15 +401,32 @@ function convertSequence(attr, element) {
401
401
  }
402
402
  if (values.length > 0) element.Value = values;
403
403
  }
404
- function convertRegularValue(attr, element) {
404
+ var NUMERIC_JSON_VRS = /* @__PURE__ */ new Set(["DS", "FL", "FD", "IS", "SL", "SS", "SV", "UL", "US", "UV"]);
405
+ function unwrapValue(v) {
406
+ if (typeof v !== "object" || v === null) return v;
407
+ const obj = v;
408
+ if ("#text" in obj) return obj["#text"];
409
+ const keys = Object.keys(obj);
410
+ if (keys.length === 1 && keys[0] !== void 0 && keys[0].startsWith("@_")) {
411
+ return obj[keys[0]];
412
+ }
413
+ return v;
414
+ }
415
+ function coerceNumeric(value) {
416
+ if (typeof value === "number") return value;
417
+ if (typeof value !== "string") return value;
418
+ const trimmed = value.trim();
419
+ if (trimmed.length === 0) return value;
420
+ const num = Number(trimmed);
421
+ return Number.isNaN(num) ? value : num;
422
+ }
423
+ function convertRegularValue(attr, element, vr) {
405
424
  const valArray = toArray(attr.Value);
406
425
  const values = [];
426
+ const isNumeric = NUMERIC_JSON_VRS.has(vr);
407
427
  for (const v of valArray) {
408
- if (typeof v === "object" && v !== null && "#text" in v) {
409
- values.push(v["#text"]);
410
- } else {
411
- values.push(v);
412
- }
428
+ const unwrapped = unwrapValue(v);
429
+ values.push(isNumeric ? coerceNumeric(unwrapped) : unwrapped);
413
430
  }
414
431
  if (values.length > 0) element.Value = values;
415
432
  }
@@ -426,7 +443,7 @@ function convertElement(attr) {
426
443
  } else if (element.vr === "SQ" && attr.Item !== void 0) {
427
444
  convertSequence(attr, element);
428
445
  } else if (attr.Value !== void 0) {
429
- convertRegularValue(attr, element);
446
+ convertRegularValue(attr, element, vr);
430
447
  }
431
448
  return Object.freeze(element);
432
449
  }