OHIF / Viewers

OHIF zero-footprint DICOM viewer and oncology specific Lesion Tracker, plus shared extension packages
https://docs.ohif.org/
MIT License
3.37k stars 3.41k forks source link

[Bug] Improve hydrateStructuredReport with validation & types #4358

Open headwinds opened 2 months ago

headwinds commented 2 months ago

Describe the Bug

This is very low priority issue and it may be related to old data that is missing certain critical properties.

tdlr; if you encounter this issue, try changing your test dataset

My issue happens in the hydrateStructuredReport.ts when it attempt to set the instance

const instance = getLatestInstance(displaySet.instances);

I can log and see that instance has this shape

{
    "ContentDate": 0,
    "ContentTime": 0,
    "SOPInstanceUID": "",
    "InstanceNumber": ""
}

Since this instance is missing ContentSequence, the remaining functions in this file assume it's present and basically it all falls apart from here.

I'd recommend updating...

const toArray = function (x) {

...to provide both a type and null check on the x so that we don't add a null or undefined value to array

I'd also add some validation and typing FP work in _mapLegacyDataSet(dataset) so that it returns a new dataset with all expected properties and not a mutated one.

codeMeaningEquals is a powerhouse comparator and again could benefit from a null and type check on the contentItem; and splash in some nullish coalescing on contentItem.ConceptNameCodeSequence.CodeMeaning === codeMeaningName; for good measure!

Steps to Reproduce

the instance is missing the property ContentSequence

The current behavior

it crashes the Viewer with this error:

Cannot read properties of undefined (reading 'ConceptNameCodeSequence')

The expected behavior

The Viewer should appear

OS

macOS 14.6

Node version

20.12.2

Browser

Chrome 126

sedghi commented 3 weeks ago

Can you check if it is still happening in the latest master branch?