fix(multiframe): handling proxies properly (#4693)
Co-authored-by: Bill Wallace <wayfarer3130@gmail.com> Co-authored-by: Chao Sui <chao.sui@curvebeamai.com>
This commit is contained in:
5 files changed
+44
-43
No files matched your search
@@ -9,7 +9,6 @@ import combineFrameInstance from '../utils/combineFrameInstance';
|
||||
|
||||
class MetadataProvider {
|
||||
private readonly imageURIToUIDs: Map<string, any> = new Map();
|
||||
private readonly imageUIDsByImageId: Map<string, any> = new Map();
|
||||
// Can be used to store custom metadata for a specific type.
|
||||
// For instance, the scaling metadata for PET can be stored here
|
||||
// as type "scalingModule"
|
||||
@@ -25,7 +24,6 @@ class MetadataProvider {
|
||||
// An example would be dicom hosted at some random site.
|
||||
const imageURI = imageIdToURI(imageId);
|
||||
this.imageURIToUIDs.set(imageURI, uids);
|
||||
this.imageUIDsByImageId.set(imageId, uids);
|
||||
}
|
||||
|
||||
addCustomMetadata(imageId, type, metadata) {
|
||||
@@ -462,11 +460,6 @@ class MetadataProvider {
|
||||
}
|
||||
|
||||
getUIDsFromImageID(imageId) {
|
||||
const cachedUIDs = this.imageUIDsByImageId.get(imageId);
|
||||
if (cachedUIDs) {
|
||||
return cachedUIDs;
|
||||
}
|
||||
|
||||
if (imageId.startsWith('wadors:')) {
|
||||
const strippedImageId = imageId.split('/studies/')[1];
|
||||
const splitImageId = strippedImageId.split('/');
|
||||
|
||||
@@ -67,18 +67,27 @@ const combineFrameInstance = (frame, instance) => {
|
||||
ImagePositionPatientToUse = [position[0], position[1], position[2]];
|
||||
}
|
||||
}
|
||||
const sharedInstance = createCombinedValue(instance, SharedFunctionalGroupsSequence?.[0]);
|
||||
|
||||
// Cache the _parentInstance at the top level as a full copy to prevent
|
||||
// setting values hard.
|
||||
if (!instance._parentInstance) {
|
||||
Object.defineProperty(instance, '_parentInstance', {
|
||||
value: { ...instance },
|
||||
});
|
||||
}
|
||||
const sharedInstance = createCombinedValue(
|
||||
instance._parentInstance,
|
||||
SharedFunctionalGroupsSequence?.[0],
|
||||
'_shared'
|
||||
);
|
||||
const newInstance = createCombinedValue(
|
||||
sharedInstance,
|
||||
PerFrameFunctionalGroupsSequence?.[frameNumber]
|
||||
PerFrameFunctionalGroupsSequence?.[frameNumber - 1],
|
||||
frameNumber
|
||||
);
|
||||
|
||||
Object.defineProperty(newInstance, 'ImagePositionPatient', {
|
||||
value: ImagePositionPatientToUse ?? newInstance.ImagePositionPatient ?? [0, 0, frameNumber],
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
});
|
||||
newInstance.ImagePositionPatient = ImagePositionPatientToUse ??
|
||||
newInstance.ImagePositionPatient ?? [0, 0, frameNumber];
|
||||
|
||||
Object.defineProperty(newInstance, 'frameNumber', {
|
||||
value: frameNumber,
|
||||
@@ -92,14 +101,25 @@ const combineFrameInstance = (frame, instance) => {
|
||||
}
|
||||
};
|
||||
|
||||
function createCombinedValue(parent, functionalGroups) {
|
||||
/**
|
||||
* Creates a combined instance stored in the parent object which
|
||||
* inherits from the parent instance the attributes in the functional groups.
|
||||
* The storage key in the parent is in key
|
||||
*/
|
||||
function createCombinedValue(parent, functionalGroups, key) {
|
||||
if (parent[key]) {
|
||||
return parent[key];
|
||||
}
|
||||
// Exclude any proxying values
|
||||
const newInstance = Object.create(parent);
|
||||
Object.defineProperty(parent, key, {
|
||||
value: newInstance,
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
});
|
||||
if (!functionalGroups) {
|
||||
return newInstance;
|
||||
}
|
||||
if (functionalGroups._sharedValue) {
|
||||
return functionalGroups._sharedValue;
|
||||
}
|
||||
const shared = functionalGroups
|
||||
? Object.values(functionalGroups)
|
||||
.filter(Boolean)
|
||||
@@ -117,11 +137,6 @@ function createCombinedValue(parent, functionalGroups) {
|
||||
newInstance[key] = value;
|
||||
});
|
||||
});
|
||||
Object.defineProperty(functionalGroups, '_sharedValue', {
|
||||
value: newInstance,
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
});
|
||||
return newInstance;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user