Skip to content

Commit

Permalink
fix: catch errors in getPTImageIdInstanceMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
pwespi committed Jan 15, 2024
1 parent 9c553fd commit 893ebe4
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions extensions/default/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,29 @@ const handlePETImageMetadata = ({ SeriesInstanceUID, StudyInstanceUID }) => {

const imageIds = instances.map(instance => instance.imageId);
const instanceMetadataArray = [];
imageIds.forEach(imageId => {
const instanceMetadata = getPTImageIdInstanceMetadata(imageId);
if (instanceMetadata) {
instanceMetadataArray.push(instanceMetadata);
}
});

if (!instanceMetadataArray.length) {
return;
}

// try except block to prevent errors when the metadata is not correct
let suvScalingFactors;
try {
suvScalingFactors = calculateSUVScalingFactors(instanceMetadataArray);
imageIds.forEach(imageId => {
const instanceMetadata = getPTImageIdInstanceMetadata(imageId);
if (instanceMetadata) {
instanceMetadataArray.push(instanceMetadata);
}
});

if (!instanceMetadataArray.length) {
return;
}

const suvScalingFactors = calculateSUVScalingFactors(instanceMetadataArray);
instanceMetadataArray.forEach((instanceMetadata, index) => {
metadataProvider.addCustomMetadata(
imageIds[index],
'scalingModule',
suvScalingFactors[index]
);
});
} catch (error) {
console.log(error);
}

if (!suvScalingFactors) {
return;
}

instanceMetadataArray.forEach((instanceMetadata, index) => {
metadataProvider.addCustomMetadata(imageIds[index], 'scalingModule', suvScalingFactors[index]);
});
};

0 comments on commit 893ebe4

Please sign in to comment.