@dcmjs-org/dcmjs 1.0.0-beta.22 → 1.0.0-beta.24

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/build/dcmjs.js CHANGED
@@ -8567,7 +8567,7 @@
8567
8567
  }
8568
8568
  var validationLog = log.getLogger("validation.dcmjs");
8569
8569
 
8570
- var _excluded = ["littleEndian", "start", "stop", "noCopy", "clearBuffers", "decoder"];
8570
+ var _excluded$1 = ["littleEndian", "start", "stop", "noCopy", "clearBuffers", "decoder"];
8571
8571
  var legacyWarned = new Set();
8572
8572
 
8573
8573
  /** Warns once per class that a positional (0.x) constructor form was used. */
@@ -9265,7 +9265,7 @@
9265
9265
  _options$clearBuffers = _options.clearBuffers,
9266
9266
  clearBuffers = _options$clearBuffers === void 0 ? false : _options$clearBuffers,
9267
9267
  decoder = _options.decoder,
9268
- rest = _objectWithoutProperties(_options, _excluded);
9268
+ rest = _objectWithoutProperties(_options, _excluded$1);
9269
9269
  _this3 = _callSuper(this, ReadBufferStream, [_objectSpread2(_objectSpread2({}, rest), {}, {
9270
9270
  littleEndian: littleEndian,
9271
9271
  clearBuffers: clearBuffers
@@ -12767,6 +12767,8 @@
12767
12767
  var group = parseInt(hex8.slice(0, 4), 16);
12768
12768
  var elem = parseInt(hex8.slice(4, 8), 16);
12769
12769
  if (!Number.isFinite(group) || !Number.isFinite(elem)) return undefined;
12770
+ // An odd group is private, also in the 50xx and 60xx ranges.
12771
+ if (group & 1) return undefined;
12770
12772
  for (var i = 0; i < rangeEntries.length; i++) {
12771
12773
  var r = rangeEntries[i];
12772
12774
  if (group >= r.groupMin && group <= r.groupMax && elem === r.elem) {
@@ -12846,6 +12848,19 @@
12846
12848
  }
12847
12849
  var cache = new Map();
12848
12850
  var nameCache = new Map();
12851
+
12852
+ /** Set by DicomMetaDictionary at load: the entry of an existing keyword. */
12853
+ var keywordLookup = null;
12854
+
12855
+ /**
12856
+ * Set the lookup of existing keywords that registerTag() checks. Injected,
12857
+ * because DicomMetaDictionary imports this module.
12858
+ *
12859
+ * @param {(name: string) => { tag: string } | undefined} fn
12860
+ */
12861
+ function setKeywordLookup(fn) {
12862
+ keywordLookup = fn;
12863
+ }
12849
12864
  function isPrivateTagKey(prop) {
12850
12865
  return typeof prop === "string" && prop.length > 11 && prop.indexOf('"') !== -1;
12851
12866
  }
@@ -12853,6 +12868,79 @@
12853
12868
  // '(0008,0005)' -> '00080005'
12854
12869
  return k.slice(1, 5) + k.slice(6, 10);
12855
12870
  }
12871
+ function _toParenKeyFromHex8(hex8) {
12872
+ // '00080005' -> '(0008,0005)'
12873
+ return "(" + hex8.slice(0, 4) + "," + hex8.slice(4, 8) + ")";
12874
+ }
12875
+
12876
+ /**
12877
+ * Register a tag entry in the cache so it is returned by the dictionary for that tag.
12878
+ * Use for tags not in the standard or private dictionaries.
12879
+ * The tag is stored in upper case, the case that a reader makes, and lookups
12880
+ * accept both cases. The tag of the first argument wins over `entry.tag`.
12881
+ * Name rules (docs/specs/registries.md, REG-U-18 to REG-U-21):
12882
+ * - A name that is an existing keyword of a different tag throws.
12883
+ * - When two tags use one name, the first tag keeps the name and a warning
12884
+ * names both tags. The second tag gets its hex tag as its name, and keeps
12885
+ * its VR and VM.
12886
+ * - A new name for a registered tag replaces the old name.
12887
+ *
12888
+ * @param {string} tagOrHex - Tag as '(GGGG,EEEE)' or 'GGGGEEEE'
12889
+ * @param {{ name: string, vr: string, vm?: string, [key: string]: unknown }} entry - At least name and vr; vm and other fields optional
12890
+ * @returns {void}
12891
+ */
12892
+ function registerTag(tagOrHex, entry) {
12893
+ var _keywordLookup, _entry$version;
12894
+ if (typeof tagOrHex !== "string" || !entry || typeof entry.name !== "string" || typeof entry.vr !== "string") {
12895
+ return;
12896
+ }
12897
+ var parenKey;
12898
+ var hex8;
12899
+ if (tagOrHex.length === 11 && tagOrHex[0] === "(" && tagOrHex[5] === "," && tagOrHex[10] === ")") {
12900
+ parenKey = tagOrHex;
12901
+ hex8 = _toHex8FromParenKey(tagOrHex);
12902
+ } else if (tagOrHex.length === 8) {
12903
+ hex8 = tagOrHex;
12904
+ parenKey = _toParenKeyFromHex8(tagOrHex);
12905
+ } else {
12906
+ return;
12907
+ }
12908
+ var upperHex = hex8.toUpperCase();
12909
+ var lowerHex = hex8.toLowerCase();
12910
+ var tag = _toParenKeyFromHex8(upperHex);
12911
+ var keyword = (_keywordLookup = keywordLookup) === null || _keywordLookup === void 0 ? void 0 : _keywordLookup(entry.name);
12912
+ if (keyword && keyword.tag.toUpperCase() !== tag) {
12913
+ throw new Error("registerTag: name ".concat(entry.name, " is the keyword of ").concat(keyword.tag, "; ") + "".concat(tag, " cannot use it"));
12914
+ }
12915
+ var name = entry.name;
12916
+ var existing = nameCache.get(name);
12917
+ if (existing && existing.tag !== tag) {
12918
+ log.warn("registerTag: name ".concat(name, " already maps to ").concat(existing.tag, "; ") + "".concat(tag, " uses the name ").concat(upperHex));
12919
+ name = upperHex;
12920
+ }
12921
+ var previous = cache.get(upperHex);
12922
+ if (previous && nameCache.get(previous.name) === previous) {
12923
+ nameCache.delete(previous.name);
12924
+ }
12925
+ var cached = _objectSpread2(_objectSpread2({}, entry), {}, {
12926
+ name: name,
12927
+ tag: tag,
12928
+ version: (_entry$version = entry.version) !== null && _entry$version !== void 0 ? _entry$version : "User"
12929
+ });
12930
+ var _iterator = _createForOfIteratorHelper(new Set([upperHex, lowerHex, hex8, parenKey, _toParenKeyFromHex8(upperHex), _toParenKeyFromHex8(lowerHex)])),
12931
+ _step;
12932
+ try {
12933
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
12934
+ var key = _step.value;
12935
+ cache.set(key, cached);
12936
+ }
12937
+ } catch (err) {
12938
+ _iterator.e(err);
12939
+ } finally {
12940
+ _iterator.f();
12941
+ }
12942
+ nameCache.set(name, cached);
12943
+ }
12856
12944
 
12857
12945
  /**
12858
12946
  * Look up a registerTag() entry by its keyword name, so registration is
@@ -13383,7 +13471,7 @@
13383
13471
  * True when the dataset alias `name` was deleted, or replaced by a plain
13384
13472
  * value, after definePrivateAliases defined it.
13385
13473
  */
13386
- function aliasDeleted(target, name, record) {
13474
+ function aliasDeleted$1(target, name, record) {
13387
13475
  var descriptor = Object.getOwnPropertyDescriptor(target, name);
13388
13476
  return !descriptor || descriptor.get !== record.get;
13389
13477
  }
@@ -13392,7 +13480,7 @@
13392
13480
  * The alias record of `target` itself. An Object.create child must not use
13393
13481
  * the record of its prototype: the aliases there belong to the parent.
13394
13482
  */
13395
- function ownAliases(target) {
13483
+ function ownAliases$1(target) {
13396
13484
  return Object.prototype.hasOwnProperty.call(target, DATASET_ALIASES) ? target[DATASET_ALIASES] : undefined;
13397
13485
  }
13398
13486
 
@@ -13403,7 +13491,7 @@
13403
13491
  * deleted.
13404
13492
  */
13405
13493
  function definePrivateAliases(target) {
13406
- var aliases = ownAliases(target);
13494
+ var aliases = ownAliases$1(target);
13407
13495
  if (!aliases) {
13408
13496
  aliases = new Map();
13409
13497
  Object.defineProperty(target, DATASET_ALIASES, {
@@ -13427,7 +13515,7 @@
13427
13515
  var set = elementKey === null ? undefined : function (v) {
13428
13516
  var _this$_vrMap, _this$_vrMap2;
13429
13517
  var creator = aliases.get(creatorName);
13430
- var creatorDeleted = creator && aliasDeleted(target, creatorName, creator);
13518
+ var creatorDeleted = creator && aliasDeleted$1(target, creatorName, creator);
13431
13519
  if (this !== target && this[key] && !creatorDeleted && !Object.prototype.hasOwnProperty.call(this, key)) {
13432
13520
  // a child writes to its own copy of this block only,
13433
13521
  // without the elements the parent deleted (NAT-U-HIST-7)
@@ -13655,7 +13743,7 @@
13655
13743
  blocks: new Set(),
13656
13744
  elements: new Set()
13657
13745
  };
13658
- var aliases = ownAliases(dataset);
13746
+ var aliases = ownAliases$1(dataset);
13659
13747
  if (!aliases) return deleted;
13660
13748
  var _iterator3 = _createForOfIteratorHelper(aliases),
13661
13749
  _step3;
@@ -13664,7 +13752,7 @@
13664
13752
  var _step3$value = _slicedToArray(_step3.value, 2),
13665
13753
  name = _step3$value[0],
13666
13754
  record = _step3$value[1];
13667
- if (!aliasDeleted(dataset, name, record)) continue;
13755
+ if (!aliasDeleted$1(dataset, name, record)) continue;
13668
13756
  var key = record.key,
13669
13757
  elementKey = record.elementKey;
13670
13758
  if (elementKey === null) deleted.blocks.add(key);else deleted.elements.add("".concat(key, "\n").concat(elementKey));
@@ -13684,7 +13772,7 @@
13684
13772
  function privateAliasTarget(dataset, name) {
13685
13773
  var _dataset$DATASET_ALIA;
13686
13774
  var record = (_dataset$DATASET_ALIA = dataset[DATASET_ALIASES]) === null || _dataset$DATASET_ALIA === void 0 ? void 0 : _dataset$DATASET_ALIA.get(name);
13687
- if (!record || aliasDeleted(dataset, name, record)) return undefined;
13775
+ if (!record || aliasDeleted$1(dataset, name, record)) return undefined;
13688
13776
  return {
13689
13777
  key: record.key,
13690
13778
  elementKey: record.elementKey
@@ -13883,6 +13971,324 @@
13883
13971
  return view;
13884
13972
  }
13885
13973
 
13974
+ var _excluded = ["group"];
13975
+
13976
+ /**
13977
+ * Overlay groups (60xx, xx even) in the naturalized form
13978
+ * (docs/specs/naturalized-dataset.md, NAT-U-OVL). All overlay groups use the
13979
+ * same keywords, so each group is one item of `OverlaySequence`, with its
13980
+ * group as `group` ("6002") and its attributes by keyword. As for a private
13981
+ * block, the 8-digit hex tag of each element (`"60023000"`) is a
13982
+ * non-enumerable alias on the dataset, and a delete of the alias removes the
13983
+ * element from the output.
13984
+ */
13985
+
13986
+ /** Naturalized name of the overlay groups, which DICOM has as groups 60xx. */
13987
+ var OVERLAY_SEQUENCE = "OverlaySequence";
13988
+
13989
+ // The overlay aliases that defineOverlayAliases defined, by hex tag:
13990
+ // { group, keyword, get }.
13991
+ var OVERLAY_ALIASES = Symbol.for("dcmjs.overlayAliases");
13992
+ var elementOfKeyword;
13993
+ var keywordOfElement;
13994
+ function overlayKeywords() {
13995
+ if (!elementOfKeyword) {
13996
+ elementOfKeyword = new Map();
13997
+ keywordOfElement = new Map();
13998
+ var _iterator = _createForOfIteratorHelper(rangeEntries),
13999
+ _step;
14000
+ try {
14001
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
14002
+ var r = _step.value;
14003
+ if (r.groupMin !== 0x6000) continue;
14004
+ var ee = r.elem.toString(16).toUpperCase().padStart(4, "0");
14005
+ elementOfKeyword.set(r.name, ee);
14006
+ keywordOfElement.set(ee, r.name);
14007
+ }
14008
+ } catch (err) {
14009
+ _iterator.e(err);
14010
+ } finally {
14011
+ _iterator.f();
14012
+ }
14013
+ }
14014
+ return {
14015
+ elementOfKeyword: elementOfKeyword,
14016
+ keywordOfElement: keywordOfElement
14017
+ };
14018
+ }
14019
+
14020
+ /**
14021
+ * The overlay group ("6000" to "60FE", even) of an 8-digit hex tag, else
14022
+ * undefined. An odd 60xx group is private, not an overlay.
14023
+ */
14024
+ function overlayGroupOfTag(tag) {
14025
+ if (typeof tag !== "string" || tag.length !== 8 || !/^60[0-9A-F][02468ACE][0-9A-F]{4}$/i.test(tag)) {
14026
+ return undefined;
14027
+ }
14028
+ return tag.slice(0, 4).toUpperCase();
14029
+ }
14030
+
14031
+ /** The overlay keyword of an 8-digit hex tag, or undefined. */
14032
+ function overlayKeyword(tag) {
14033
+ return overlayGroupOfTag(tag) && overlayKeywords().keywordOfElement.get(tag.slice(4).toUpperCase());
14034
+ }
14035
+
14036
+ /** The OverlaySequence items of `dataset`, as a list. */
14037
+ function overlayItems(dataset) {
14038
+ var seq = dataset[OVERLAY_SEQUENCE];
14039
+ if (!seq) return [];
14040
+ return Array.isArray(seq) ? seq : [seq];
14041
+ }
14042
+
14043
+ /** The 4-digit uppercase group of an item `group` (a string or a number). */
14044
+ function groupText(group) {
14045
+ return (typeof group === "number" ? group.toString(16) : String(group)).toUpperCase();
14046
+ }
14047
+ function findItem(dataset, group) {
14048
+ return overlayItems(dataset).find(function (item) {
14049
+ return item && groupText(item.group) === group;
14050
+ });
14051
+ }
14052
+
14053
+ /**
14054
+ * The item of `overlays` (group -> item) that receives the element `tag`, or
14055
+ * undefined when `tag` is not in an overlay group. The item is created on
14056
+ * first use. Both producers call it, so they give the same items.
14057
+ */
14058
+ function overlayItem(overlays, tag) {
14059
+ var group = overlayGroupOfTag(tag);
14060
+ if (!group) {
14061
+ return undefined;
14062
+ }
14063
+ overlays[group] = overlays[group] || {
14064
+ _vrMap: {}
14065
+ };
14066
+ return overlays[group];
14067
+ }
14068
+
14069
+ /**
14070
+ * Sets `target.OverlaySequence` from `overlays` (group -> item): the items in
14071
+ * group order, each with `group`, by the sequence rule (NAT-U-SQ). Then
14072
+ * defines the hex-tag aliases.
14073
+ */
14074
+ function placeOverlayItems(target, overlays) {
14075
+ var groups = Object.keys(overlays).sort();
14076
+ if (!groups.length) {
14077
+ return;
14078
+ }
14079
+ var items = groups.map(function (group) {
14080
+ overlays[group].group = group;
14081
+ return overlays[group];
14082
+ });
14083
+ target[OVERLAY_SEQUENCE] = sequenceValue(items);
14084
+ defineOverlayAliases(target);
14085
+ }
14086
+ function ownAliases(target) {
14087
+ return Object.prototype.hasOwnProperty.call(target, OVERLAY_ALIASES) ? target[OVERLAY_ALIASES] : undefined;
14088
+ }
14089
+ function aliasDeleted(target, tag, record) {
14090
+ var descriptor = Object.getOwnPropertyDescriptor(target, tag);
14091
+ return !descriptor || descriptor.get !== record.get;
14092
+ }
14093
+
14094
+ /**
14095
+ * Defines a non-enumerable alias `gggg eeee` on `target` for each element of
14096
+ * each OverlaySequence item. The alias reads and writes the item that the
14097
+ * dataset holds for that group when it is used. Without that item, a write
14098
+ * makes a flat hex element. An alias that was deleted stays deleted.
14099
+ */
14100
+ function defineOverlayAliases(target) {
14101
+ var aliases = ownAliases(target);
14102
+ if (!aliases) {
14103
+ aliases = new Map();
14104
+ Object.defineProperty(target, OVERLAY_ALIASES, {
14105
+ value: aliases
14106
+ });
14107
+ }
14108
+ var _overlayKeywords = overlayKeywords(),
14109
+ elementOfKeyword = _overlayKeywords.elementOfKeyword;
14110
+ var _iterator2 = _createForOfIteratorHelper(overlayItems(target)),
14111
+ _step2;
14112
+ try {
14113
+ var _loop = function _loop() {
14114
+ var item = _step2.value;
14115
+ if (!item || item.group === undefined) return 1; // continue
14116
+ var group = groupText(item.group);
14117
+ var _loop2 = function _loop2() {
14118
+ var keyword = _Object$keys[_i];
14119
+ var ee = elementOfKeyword.get(keyword);
14120
+ var tag = "".concat(group).concat(ee);
14121
+ if (!ee || aliases.has(tag) || Object.prototype.hasOwnProperty.call(target, tag)) {
14122
+ return 1; // continue
14123
+ }
14124
+ // `this` is the dataset, or an Object.create child of it.
14125
+ // shortcut: a child writes into the item of its parent; copy on
14126
+ // write as for private blocks when a frame view needs it.
14127
+ var record = {
14128
+ group: group,
14129
+ keyword: keyword,
14130
+ get: function get() {
14131
+ var _findItem;
14132
+ return (_findItem = findItem(this, group)) === null || _findItem === void 0 ? void 0 : _findItem[keyword];
14133
+ }
14134
+ };
14135
+ var set = function set(v) {
14136
+ var found = findItem(this, group);
14137
+ if (found) {
14138
+ found[keyword] = v;
14139
+ return;
14140
+ }
14141
+ Object.defineProperty(this, tag, {
14142
+ value: v,
14143
+ writable: true,
14144
+ enumerable: true,
14145
+ configurable: true
14146
+ });
14147
+ };
14148
+ Object.defineProperty(target, tag, {
14149
+ get: record.get,
14150
+ set: set,
14151
+ configurable: true
14152
+ });
14153
+ aliases.set(tag, record);
14154
+ };
14155
+ for (var _i = 0, _Object$keys = Object.keys(item); _i < _Object$keys.length; _i++) {
14156
+ if (_loop2()) continue;
14157
+ }
14158
+ };
14159
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
14160
+ if (_loop()) continue;
14161
+ }
14162
+ } catch (err) {
14163
+ _iterator2.e(err);
14164
+ } finally {
14165
+ _iterator2.f();
14166
+ }
14167
+ }
14168
+
14169
+ /** The hex tags of the overlay aliases of `dataset` that were deleted. */
14170
+ function deletedAliases(dataset) {
14171
+ var deleted = new Set();
14172
+ var aliases = ownAliases(dataset);
14173
+ if (!aliases) return deleted;
14174
+ var _iterator3 = _createForOfIteratorHelper(aliases),
14175
+ _step3;
14176
+ try {
14177
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
14178
+ var _step3$value = _slicedToArray(_step3.value, 2),
14179
+ tag = _step3$value[0],
14180
+ record = _step3$value[1];
14181
+ if (aliasDeleted(dataset, tag, record)) deleted.add(tag);
14182
+ }
14183
+ } catch (err) {
14184
+ _iterator3.e(err);
14185
+ } finally {
14186
+ _iterator3.f();
14187
+ }
14188
+ return deleted;
14189
+ }
14190
+
14191
+ /**
14192
+ * The item and keyword that a write of the hex tag `tag` goes to in
14193
+ * `dataset`, or undefined when `tag` is no overlay element or its alias was
14194
+ * deleted. With `create`, a missing item is added to OverlaySequence.
14195
+ */
14196
+ function overlayElementTarget(dataset, tag, create) {
14197
+ var _ownAliases;
14198
+ var keyword = overlayKeyword(tag);
14199
+ if (!keyword) return undefined;
14200
+ var record = (_ownAliases = ownAliases(dataset)) === null || _ownAliases === void 0 ? void 0 : _ownAliases.get(tag.toUpperCase());
14201
+ if (record && aliasDeleted(dataset, tag.toUpperCase(), record)) {
14202
+ return undefined;
14203
+ }
14204
+ var group = tag.slice(0, 4).toUpperCase();
14205
+ var item = findItem(dataset, group);
14206
+ if (!item && create) {
14207
+ item = {
14208
+ _vrMap: {},
14209
+ group: group
14210
+ };
14211
+ var items = [].concat(_toConsumableArray(overlayItems(dataset)), [item]).sort(function (a, b) {
14212
+ return groupText(a.group).localeCompare(groupText(b.group));
14213
+ });
14214
+ dataset[OVERLAY_SEQUENCE] = sequenceValue(items);
14215
+ }
14216
+ return item && {
14217
+ item: item,
14218
+ keyword: keyword
14219
+ };
14220
+ }
14221
+
14222
+ /**
14223
+ * The flat overlay hex keys of `dataset` (`"60023000"`), as items by group,
14224
+ * so they write as an item does. Their VR comes from `dataset._vrMap`.
14225
+ */
14226
+ function flatOverlayItems(dataset) {
14227
+ var byGroup = new Map();
14228
+ for (var _i2 = 0, _Object$keys2 = Object.keys(dataset); _i2 < _Object$keys2.length; _i2++) {
14229
+ var _dataset$_vrMap;
14230
+ var key = _Object$keys2[_i2];
14231
+ var keyword = overlayKeyword(key);
14232
+ if (!keyword) continue;
14233
+ var group = key.slice(0, 4).toUpperCase();
14234
+ if (!byGroup.has(group)) byGroup.set(group, {
14235
+ _vrMap: {},
14236
+ group: group
14237
+ });
14238
+ var item = byGroup.get(group);
14239
+ item[keyword] = dataset[key];
14240
+ var vr = (_dataset$_vrMap = dataset._vrMap) === null || _dataset$_vrMap === void 0 ? void 0 : _dataset$_vrMap[key];
14241
+ if (vr) item._vrMap[keyword] = vr;
14242
+ }
14243
+ return _toConsumableArray(byGroup.values());
14244
+ }
14245
+
14246
+ /** True for a key that denaturalizeOverlays writes: the sequence or a hex key. */
14247
+ function isOverlayKey(key) {
14248
+ return key === OVERLAY_SEQUENCE || !!overlayKeyword(key);
14249
+ }
14250
+
14251
+ /**
14252
+ * Writes the overlays of the naturalized `dataset` into `target`, a DICOM
14253
+ * JSON dict: first its flat overlay hex keys, then each OverlaySequence item,
14254
+ * so an item wins. `denaturalize(item)` gives the dict of one item. An item
14255
+ * without `group` takes group 6000 + 2 * index; `group` can be a number. An
14256
+ * element whose alias was deleted is left out.
14257
+ */
14258
+ function denaturalizeOverlays(dataset, target, denaturalize) {
14259
+ var deleted = deletedAliases(dataset);
14260
+ var write = function write(item, index, keepDeleted) {
14261
+ if (!item) {
14262
+ return;
14263
+ }
14264
+ var itemGroup = item.group,
14265
+ attributes = _objectWithoutProperties(item, _excluded);
14266
+ var group = groupText(itemGroup !== null && itemGroup !== void 0 ? itemGroup : 0x6000 + 2 * index);
14267
+ if (!overlayGroupOfTag("".concat(group, "0000"))) {
14268
+ log.warn("".concat(OVERLAY_SEQUENCE, ": group ").concat(group, " is not an overlay group"));
14269
+ return;
14270
+ }
14271
+ var tags = denaturalize(attributes);
14272
+ Object.keys(tags).forEach(function (tag) {
14273
+ if (!overlayGroupOfTag(tag)) {
14274
+ log.warn("".concat(OVERLAY_SEQUENCE, ": ").concat(tag, " is not an overlay attribute"));
14275
+ return;
14276
+ }
14277
+ var groupTag = group + tag.slice(4);
14278
+ if (keepDeleted || !deleted.has(groupTag)) {
14279
+ target[groupTag] = tags[tag];
14280
+ }
14281
+ });
14282
+ };
14283
+ // a flat key is a value that the user set, also after a delete
14284
+ flatOverlayItems(dataset).forEach(function (item) {
14285
+ return write(item, 0, true);
14286
+ });
14287
+ overlayItems(dataset).forEach(function (item, index) {
14288
+ return write(item, index, false);
14289
+ });
14290
+ }
14291
+
13886
14292
  /**
13887
14293
  * Utilities that add or replace one attribute of a naturalized dataset in
13888
14294
  * the naturalized form (docs/specs/naturalized-dataset.md, NAT-U-SET).
@@ -13917,7 +14323,7 @@
13917
14323
  /** The dictionary entry of a keyword, a registerTag() keyword or a hex tag. */
13918
14324
  function entryFor(key) {
13919
14325
  if (isHexTag(key)) return registeredTagEntry(key);
13920
- return DicomMetaDictionary.nameMap[key] || lookupRegisteredTagByName(key);
14326
+ return DicomMetaDictionary.entryForName(key);
13921
14327
  }
13922
14328
 
13923
14329
  /**
@@ -13932,6 +14338,10 @@
13932
14338
  * @param {string} [elementKey] - with a block key: the element, e.g. "x01"
13933
14339
  */
13934
14340
  function setVr(dataset, key, vr, elementKey) {
14341
+ var overlay = elementKey === undefined && overlayElementTarget(dataset, key, true);
14342
+ if (overlay) {
14343
+ return setVr(overlay.item, overlay.keyword, vr); // NAT-U-OVL-10
14344
+ }
13935
14345
  if (elementKey === undefined) {
13936
14346
  key = naturalKey(dataset, key);
13937
14347
  var alias = privateAliasTarget(dataset, key);
@@ -13973,6 +14383,10 @@
13973
14383
  function setAttribute(dataset, key, value) {
13974
14384
  var _Object$getOwnPropert;
13975
14385
  var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
14386
+ var overlay = overlayElementTarget(dataset, key, true);
14387
+ if (overlay) {
14388
+ return setAttribute(overlay.item, overlay.keyword, value, options); // NAT-U-OVL-10
14389
+ }
13976
14390
  key = naturalKey(dataset, key);
13977
14391
  var alias = assertNotCreator(dataset, key);
13978
14392
  var entry = entryFor(key);
@@ -14015,6 +14429,10 @@
14015
14429
  * @returns {Object|Object[]|null} the stored value
14016
14430
  */
14017
14431
  function setPersonName(dataset, key, value, length) {
14432
+ var overlay = overlayElementTarget(dataset, key, true);
14433
+ if (overlay) {
14434
+ return setPersonName(overlay.item, overlay.keyword, value, length);
14435
+ }
14018
14436
  key = naturalKey(dataset, key);
14019
14437
  assertNotCreator(dataset, key);
14020
14438
  var entry = entryFor(key);
@@ -14072,6 +14490,11 @@
14072
14490
  // a list, as for VM > 1
14073
14491
  return ValueRepresentation$1.addValueAccessorsFor(data.vr, simpleValue(values, valueLength(entry)));
14074
14492
  }
14493
+
14494
+ /** The own entry of `name`, so `constructor` and other prototype keys miss. */
14495
+ function ownEntry(nameMap, name) {
14496
+ return Object.prototype.hasOwnProperty.call(nameMap, name) ? nameMap[name] : undefined;
14497
+ }
14075
14498
  var DicomMetaDictionary = /*#__PURE__*/function () {
14076
14499
  // intakes a custom dictionary that will be used to parse/denaturalize the dataset
14077
14500
  function DicomMetaDictionary(customDictionary) {
@@ -14122,10 +14545,26 @@
14122
14545
  var integerValue = parseInt("0x" + DicomMetaDictionary.unpunctuateTag(tag));
14123
14546
  return integerValue;
14124
14547
  }
14548
+
14549
+ /**
14550
+ * The dictionary entry of a keyword: a standard keyword from `nameMap`
14551
+ * first, then a registerTag() name. registerTag() names are kept out of
14552
+ * the shared nameMap, so a read never changes global state.
14553
+ *
14554
+ * @param {string} name - A keyword
14555
+ * @param {object} [nameMap] - The name map to search first
14556
+ * @returns {{ tag: string, name: string, vr: string } | undefined}
14557
+ */
14558
+ }, {
14559
+ key: "entryForName",
14560
+ value: function entryForName(name) {
14561
+ var nameMap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DicomMetaDictionary.nameMap;
14562
+ return ownEntry(nameMap, name) || lookupRegisteredTagByName(name);
14563
+ }
14125
14564
  }, {
14126
14565
  key: "tagAsIntegerFromName",
14127
14566
  value: function tagAsIntegerFromName(name) {
14128
- var item = DicomMetaDictionary.nameMap[name];
14567
+ var item = DicomMetaDictionary.entryForName(name);
14129
14568
  if (item != undefined) {
14130
14569
  return this.parseIntFromTag(item.tag);
14131
14570
  } else {
@@ -14201,7 +14640,10 @@
14201
14640
  * hidden [0] and length (see addAccessors); otherwise it is a list;
14202
14641
  * - PN values get their value accessors here, when the value is built;
14203
14642
  * - private elements group by reserved block under `${group}:${creator}`
14204
- * keys, with non-enumerable hex-tag aliases (see privateBlocks.js).
14643
+ * keys, with non-enumerable hex-tag aliases (see privateBlocks.js);
14644
+ * - each overlay group (60xx, xx even) is one item of `OverlaySequence`,
14645
+ * with its group as `group` ("6000") and its attributes by keyword
14646
+ * and non-enumerable hex-tag aliases (see overlaySequence.js).
14205
14647
  *
14206
14648
  * The result is a plain object: there is no Proxy. The 0.x shapes are in
14207
14649
  * the DicomMetaDictionary of @dcmjs-org/legacy.
@@ -14222,8 +14664,11 @@
14222
14664
  _vrMap: {}
14223
14665
  };
14224
14666
  var privateElements = [];
14667
+ var overlays = {};
14225
14668
  Object.keys(dataset).forEach(function (tag) {
14226
14669
  var data = dataset[tag];
14670
+ // an overlay element goes into the item of its group
14671
+ var target = overlayItem(overlays, tag) || naturalDataset;
14227
14672
  var punctuatedTag = DicomMetaDictionary.punctuateTag(tag);
14228
14673
  var entry = DicomMetaDictionary.dictionary[punctuatedTag];
14229
14674
  if (isPrivateTag(tag)) {
@@ -14238,15 +14683,16 @@
14238
14683
  // no dictionary entry: the tag stays the key, and the VR goes
14239
14684
  // into _vrMap so denaturalizeDataset can rebuild it
14240
14685
  var naturalName = entry ? entry.name : tag.toUpperCase();
14241
- recordVr(naturalDataset._vrMap, naturalName, entry, data.vr);
14686
+ recordVr(target._vrMap, naturalName, entry, data.vr);
14242
14687
  if (data.vr === "PN") {
14243
14688
  var _data$Value2;
14244
14689
  // one conversion, and the converting setter (NAT-U-VAL-5)
14245
- setPersonName(naturalDataset, naturalName, (_data$Value2 = data.Value) !== null && _data$Value2 !== void 0 ? _data$Value2 : null, valueLength(entry));
14690
+ setPersonName(target, naturalName, (_data$Value2 = data.Value) !== null && _data$Value2 !== void 0 ? _data$Value2 : null, valueLength(entry));
14246
14691
  return;
14247
14692
  }
14248
- naturalDataset[naturalName] = naturalizeElement(data, entry, options);
14693
+ target[naturalName] = naturalizeElement(data, entry, options);
14249
14694
  });
14695
+ placeOverlayItems(naturalDataset, overlays);
14250
14696
  placePrivateElements(naturalDataset, naturalDataset._vrMap, privateElements);
14251
14697
  return naturalDataset;
14252
14698
  }
@@ -14281,19 +14727,17 @@
14281
14727
  value: function denaturalizeDataset(dataset) {
14282
14728
  var nameMap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DicomMetaDictionary.nameMap;
14283
14729
  var unnaturalDataset = {};
14730
+ // the overlay alias record is on the dataset, not on the view below
14731
+ var source = dataset;
14284
14732
  // reserved private blocks become a creator plus hex-tag elements
14285
14733
  dataset = expandPrivateBlocks(dataset);
14286
14734
  Object.keys(dataset).forEach(function (naturalName) {
14735
+ if (isOverlayKey(naturalName)) {
14736
+ return; // denaturalizeOverlays below
14737
+ }
14287
14738
  // check if it's a sequence
14288
14739
  var name = naturalName;
14289
- var entry = nameMap[name];
14290
- if (!entry) {
14291
- // registerTag() names are kept in a registry-local index
14292
- // instead of being written into the shared nameMap, so a
14293
- // registered keyword denaturalizes symmetrically without
14294
- // naturalizeDataset ever mutating global state
14295
- entry = lookupRegisteredTagByName(name);
14296
- }
14740
+ var entry = DicomMetaDictionary.entryForName(name, nameMap);
14297
14741
  if (!entry && isHexTag(name) && dataset._vrMap && dataset._vrMap[name]) {
14298
14742
  // private/unknown element kept under its hex tag by
14299
14743
  // naturalizeDataset: rebuild it with the VR recorded in
@@ -14371,6 +14815,10 @@
14371
14815
  }
14372
14816
  }
14373
14817
  });
14818
+ // After the flat attributes, so an item wins over a flat overlay keyword.
14819
+ denaturalizeOverlays(source, unnaturalDataset, function (item) {
14820
+ return DicomMetaDictionary.denaturalizeDataset(item, nameMap);
14821
+ });
14374
14822
  return unnaturalDataset;
14375
14823
  }
14376
14824
 
@@ -14505,6 +14953,9 @@
14505
14953
  ValueRepresentation$1.setDicomMetaDictionary(DicomMetaDictionary);
14506
14954
  DicomMetaDictionary.dictionary = dictionary;
14507
14955
  DicomMetaDictionary._generateNameMap();
14956
+ setKeywordLookup(function (name) {
14957
+ return ownEntry(DicomMetaDictionary.nameMap, name);
14958
+ });
14508
14959
 
14509
14960
  // AUTO-GENERATED from dictionary.mjs by generate/pack_private.mjs
14510
14961
  // Private tags only (creator strings). Decoded on first use; use ensurePrivateLoaded() if needed.
@@ -31213,11 +31664,12 @@
31213
31664
  });
31214
31665
 
31215
31666
  // Every entry below must be a real dictionary keyword
31216
- // (DicomMetaDictionary.nameMap): cleanTags silently skips names that do not
31667
+ // (DicomMetaDictionary.entryForName()): cleanTags silently skips names that do not
31217
31668
  // resolve, so a misspelled entry means the data it was meant to scrub is
31218
31669
  // left in place (issue #345). Retired attributes use the dictionary's
31219
31670
  // RETIRED_ keyword prefix. All 103 previously non-resolving names were
31220
31671
  // mapped to their intended keywords; none had to be removed.
31672
+ // ResponsiblePersonRole was added to match 0.53.3.
31221
31673
  var tagNamesToEmpty = [
31222
31674
  // please override these in specificReplaceDefaults to have useful values
31223
31675
  "PatientID", "PatientName",
@@ -31230,7 +31682,7 @@
31230
31682
  // cat 2/3: CTP: set to increment dates
31231
31683
  "InstanceCreationDate", "StudyDate", "ContentDate", "DateOfSecondaryCapture", "DateOfLastCalibration", "DateOfLastDetectorCalibration", "FrameAcquisitionDateTime", "FrameReferenceDateTime", "RETIRED_StudyVerifiedDate", "RETIRED_StudyReadDate", "RETIRED_ScheduledStudyStartDate", "RETIRED_ScheduledStudyStopDate", "RETIRED_StudyArrivalDate", "RETIRED_StudyCompletionDate", "RETIRED_ScheduledAdmissionDate", "RETIRED_ScheduledDischargeDate", "RETIRED_DischargeDate", "ScheduledProcedureStepStartDate", "ScheduledProcedureStepEndDate", "PerformedProcedureStepStartDate", "PerformedProcedureStepEndDate", "IssueDateOfImagingServiceRequest", "VerificationDateTime", "ObservationDateTime", "DateTime", "Date", "ReferencedDateTime",
31232
31684
  // cat 3/3: CTP: set to remove using @remove
31233
- "AcquisitionDate", "RETIRED_OverlayDate", "RETIRED_CurveDate", "AcquisitionDateTime", "SeriesTime", "AcquisitionTime", "RETIRED_OverlayTime", "RETIRED_CurveTime", "InstitutionName", "InstitutionAddress", "ReferringPhysicianAddress", "ReferringPhysicianTelephoneNumbers", "ReferringPhysicianIdentificationSequence", "TimezoneOffsetFromUTC", "StationName", "StudyDescription", "InstitutionalDepartmentName", "PhysiciansOfRecord", "PhysiciansOfRecordIdentificationSequence", "PerformingPhysicianName", "PerformingPhysicianIdentificationSequence", "NameOfPhysiciansReadingStudy", "PhysiciansReadingStudyIdentificationSequence", "OperatorsName", "OperatorIdentificationSequence", "AdmittingDiagnosesDescription", "AdmittingDiagnosesCodeSequence", "ReferencedStudySequence", "ReferencedPerformedProcedureStepSequence", "ReferencedPatientSequence", "ReferencedImageSequence", "DerivationDescription", "SourceImageSequence", "RETIRED_IdentifyingComments", "IssuerOfPatientID", "PatientBirthTime", "PatientInsurancePlanCodeSequence", "PatientPrimaryLanguageCodeSequence", "PatientPrimaryLanguageModifierCodeSequence", "OtherPatientIDs", "OtherPatientNames", "OtherPatientIDsSequence", "PatientBirthName", "PatientAge", "PatientSize", "PatientWeight", "PatientAddress", "RETIRED_InsurancePlanIdentification", "PatientMotherBirthName", "MilitaryRank", "BranchOfService", "MedicalRecordLocator", "MedicalAlerts", "Allergies", "CountryOfResidence", "RegionOfResidence", "PatientTelephoneNumbers", "EthnicGroup", "Occupation", "SmokingStatus", "AdditionalPatientHistory", "PregnancyStatus", "LastMenstrualDate", "PatientReligiousPreference", "PatientSexNeutered", "ResponsiblePerson", "ResponsibleOrganization", "PatientComments", "DeviceSerialNumber", "PlateID", "GeneratorID", "CassetteID", "GantryID",
31685
+ "AcquisitionDate", "RETIRED_OverlayDate", "RETIRED_CurveDate", "AcquisitionDateTime", "SeriesTime", "AcquisitionTime", "RETIRED_OverlayTime", "RETIRED_CurveTime", "InstitutionName", "InstitutionAddress", "ReferringPhysicianAddress", "ReferringPhysicianTelephoneNumbers", "ReferringPhysicianIdentificationSequence", "TimezoneOffsetFromUTC", "StationName", "StudyDescription", "InstitutionalDepartmentName", "PhysiciansOfRecord", "PhysiciansOfRecordIdentificationSequence", "PerformingPhysicianName", "PerformingPhysicianIdentificationSequence", "NameOfPhysiciansReadingStudy", "PhysiciansReadingStudyIdentificationSequence", "OperatorsName", "OperatorIdentificationSequence", "AdmittingDiagnosesDescription", "AdmittingDiagnosesCodeSequence", "ReferencedStudySequence", "ReferencedPerformedProcedureStepSequence", "ReferencedPatientSequence", "ReferencedImageSequence", "DerivationDescription", "SourceImageSequence", "RETIRED_IdentifyingComments", "IssuerOfPatientID", "PatientBirthTime", "PatientInsurancePlanCodeSequence", "PatientPrimaryLanguageCodeSequence", "PatientPrimaryLanguageModifierCodeSequence", "OtherPatientIDs", "OtherPatientNames", "OtherPatientIDsSequence", "PatientBirthName", "PatientAge", "PatientSize", "PatientWeight", "PatientAddress", "RETIRED_InsurancePlanIdentification", "PatientMotherBirthName", "MilitaryRank", "BranchOfService", "MedicalRecordLocator", "MedicalAlerts", "Allergies", "CountryOfResidence", "RegionOfResidence", "PatientTelephoneNumbers", "EthnicGroup", "Occupation", "SmokingStatus", "AdditionalPatientHistory", "PregnancyStatus", "LastMenstrualDate", "PatientReligiousPreference", "PatientSexNeutered", "ResponsiblePerson", "ResponsiblePersonRole", "ResponsibleOrganization", "PatientComments", "DeviceSerialNumber", "PlateID", "GeneratorID", "CassetteID", "GantryID",
31234
31686
  // we keep - should be SoftwareVersions anyway
31235
31687
  // "SoftwareVersion",
31236
31688
  "ProtocolName", "AcquisitionDeviceProcessingDescription", "RETIRED_AcquisitionComments", "DetectorID", "AcquisitionProtocolDescription", "ContributionDescription", "RETIRED_ModifyingDeviceID", "RETIRED_ModifyingDeviceManufacturer", "RETIRED_ModifiedImageDescription", "ImageComments", "RETIRED_ImagePresentationComments", "RETIRED_StudyIDIssuer", "RETIRED_ScheduledStudyLocation", "RETIRED_ScheduledStudyLocationAETitle", "RETIRED_ReasonForStudy", "RequestingPhysician", "RequestingService", "RequestedProcedureDescription", "RequestedContrastAgent", "RETIRED_StudyComments", "AdmissionID", "RETIRED_IssuerOfAdmissionID", "RETIRED_ScheduledPatientInstitutionResidence", "AdmittingDate", "AdmittingTime", "RETIRED_DischargeDiagnosisDescription", "SpecialNeeds", "ServiceEpisodeID", "RETIRED_IssuerOfServiceEpisodeID", "ServiceEpisodeDescription", "CurrentPatientLocation", "PatientInstitutionResidence", "PatientState", "ReferencedPatientAliasSequence", "VisitComments", "ScheduledStationAETitle", "ScheduledPerformingPhysicianName", "ScheduledProcedureStepDescription", "ScheduledStationName", "ScheduledProcedureStepLocation", "PreMedication", "PerformedStationAETitle", "PerformedStationName", "PerformedLocation", "PerformedStationNameCodeSequence", "PerformedProcedureStepID", "PerformedProcedureStepDescription", "RequestAttributesSequence", "CommentsOnThePerformedProcedureStep", "AcquisitionContextSequence", "PatientTransportArrangements", "RequestedProcedureLocation", "NamesOfIntendedRecipientsOfResults", "IntendedRecipientsOfResultsIdentificationSequence", "PersonAddress", "PersonTelephoneNumbers", "RequestedProcedureComments", "RETIRED_ReasonForTheImagingServiceRequest", "OrderEnteredBy", "OrderEntererLocation", "OrderCallbackPhoneNumber", "ImagingServiceRequestComments", "ConfidentialityConstraintOnPatientDataDescription", "ScheduledStationNameCodeSequence", "ScheduledStationGeographicLocationCodeSequence", "PerformedStationGeographicLocationCodeSequence", "ScheduledHumanPerformersSequence", "ActualHumanPerformersSequence", "HumanPerformerOrganization", "HumanPerformerName", "VerifyingOrganization", "VerifyingObserverName", "AuthorObserverSequence", "ParticipantSequence", "CustodialOrganizationSequence", "VerifyingObserverIdentificationCodeSequence", "PersonName", "ContentSequence", "OverlayData", "RETIRED_OverlayComments", "IconImageSequence", "RETIRED_TopicSubject", "RETIRED_TopicAuthor", "RETIRED_TopicKeywords", "TextString", "RETIRED_Arbitrary", "RETIRED_TextComments", "RETIRED_ResultsIDIssuer", "RETIRED_InterpretationRecorder", "RETIRED_InterpretationTranscriber", "RETIRED_InterpretationText", "RETIRED_InterpretationAuthor", "RETIRED_InterpretationApproverSequence", "RETIRED_PhysicianApprovingInterpretation", "RETIRED_InterpretationDiagnosisDescription", "RETIRED_ResultsDistributionListSequence", "RETIRED_DistributionName", "RETIRED_DistributionAddress", "RETIRED_InterpretationIDIssuer", "RETIRED_Impressions", "RETIRED_ResultsComments", "DigitalSignaturesSequence", "DataSetTrailingPadding"];
@@ -31248,7 +31700,7 @@
31248
31700
  }
31249
31701
  var tags = customTagNamesToEmpty != undefined ? customTagNamesToEmpty : tagNamesToEmpty;
31250
31702
  tags.forEach(function (tag) {
31251
- var tagInfo = DicomMetaDictionary.nameMap[tag];
31703
+ var tagInfo = DicomMetaDictionary.entryForName(tag);
31252
31704
  if (tagInfo && tagInfo.version != "PrivateTag") {
31253
31705
  var tagNumber = tagInfo.tag,
31254
31706
  tagString = Tag.fromPString(tagNumber).toCleanString();
@@ -31285,6 +31737,8 @@
31285
31737
  datasetToDict: datasetToDict,
31286
31738
  datasetToBuffer: datasetToBuffer,
31287
31739
  datasetToBlob: datasetToBlob,
31740
+ dictionary: dictionary,
31741
+ registerTag: registerTag,
31288
31742
  // naturalized-dataset utilities (docs/specs/naturalized-dataset.md)
31289
31743
  setVr: setVr,
31290
31744
  setAttribute: setAttribute,