------ Bug 1. ------ 

Ultrasounds failed to load because of RGB LUT. 

Location: node_modules/@cornerstonejs/dicom-image-loader/dist/dynamic-import/cornerstoneDICOMImageLoader.min.js
Method: getNumberValues_getNumberValues()
Change:  to convert the base64 string that Dicom Objects sends in the metadata (should be Uint16Array).

Also changed the value name from "InlineBinary" to "Value"

To fix this, replace the cornerstonewadoimageloader.js with the one in Bug 1 folder. 

------ Bug 2. ------ 

Not recreating VOI lut on image load causes exposure values to get blown out in some cases

Location: node_modules/@cornerstonejs/core/dist/esm/RenderingEngine/StackViewport.js
Method: setVOIGPU
Change: set forceRecreateLUTFunction = true

------ Bug 3. ------ 

Photometric interpretation for series with colour and monochrome images

Location: node_modules/@cornerstonejs/core/dist/esm/RenderingEngine/StackViewport.js
Method: _loadAndDisplayImageGPU
Change: Add a check for matching photometricInterpretation and prevent certain rendering hooks from firing

if(this.csImage?.imageFrame.photometricInterpretation !== image.imageFrame.photometricInterpretation) {
                    this.stackInvalidated = true;
                }

See provided image in Bug 3 folder for where to place the check

------ Bug 4. ------

TO FIX ALL BUGS IN FILE REPLACE ReferenceLinesToo.js WITH ONE PROVIDED IN Bug 9 FOLDER

Location: node_modules/@cornerstonejs/tools/dist/esm/tools/ReferenceLinesTool.js
Prevent series with different Frame of reference UID from syncing
ReferenceLinesTool.js

let for1 = targetViewport.getFrameOfReferenceUID();
            let for2 = sourceViewport.getFrameOfReferenceUID();

            if(for1 !== for2) {
                return renderStatus;
            }

------ Bug 5. --------

TO FIX ALL BUGS IN FILE REPLACE ReferenceLinesToo.js WITH ONE PROVIDED IN Bug 9 FOLDER

Location: node_modules/@cornerstonejs/tools/dist/esm/tools/ReferenceLinesTool.js
Prevent syncing on disabled viewports 
ReferenceLinesTool.js

if(sourceViewport.isDisabled || targetViewport.isDisabled) {
                return renderStatus
            }

------ Bug 6. --------

Prevent altering of svg attributes when svg element is off screen/ has invalid values

Location: node_modules/@cornerstonejs/tools/dist/esm/drawingSvg/_setAttributeIfNecessary.js
method: _setAttributeIfNecessary
Change: Add a check to ensure that if an svg is not currently on screen/rendered, then it will not be altered

See image in Bug 8 folder for where to place the following code
Alternatively, replace the file with the one provided in the Bug 6 folder

if(Object.keys(attributes).some(key => attributes[key] === 'NaN' || attributes[key] === 'translate(NaN NaN)')) return

------ Bug 7. ---------

TO FIX ALL BUGS IN FILE REPLACE ReferenceLinesToo.js WITH ONE PROVIDED IN Bug 9 FOLDER

Location: node_modules/@cornerstonejs/tools/dist/esm/tools/ReferenceLinesTool.js
When setting reference lines to false the renderAnnotations call for reference lines happens without a source
or targets which fails when trying to call getFrameOfReferenceUID()

if(!targetViewport || !sourceViewport) {
                return renderStatus;
            }

------ Bug 8. --------

Draw direction of lines when using cobb angle tool impacts angle. 

Location: node_modules/@cornerstonejs/tools/dist/esm/tools/annotation/CobbAngleTool.js
Method: _calculateCachedStats
Change: Sort coordinates in cobb angle tool to prevent this behaviour

See image in Bug 8 folder for where to place the following code
Alternatively, replace the CobbAngleTool.js in your node_modules folder with the provided CobbAngleTool.js

let worldPos1, worldPos2, worldPos3, worldPos4;
        const point0 = data.handles.points[0];
        const point1 = data.handles.points[1];
        const point2 = data.handles.points[2];
        const point3 = data.handles.points[3];

        if (point0[0] < point1[0] || (point0[0] == point1[0] && point0[1] < point1[1]) || point0[1] == point1[1] && point0[2] < point1[2]) {
            worldPos1 = data.handles.points[1];
            worldPos2 = data.handles.points[0];
        } else {
            worldPos1 = data.handles.points[0];
            worldPos2 = data.handles.points[1];
        }

        if (point2[0] < point3[0] || (point2[0] == point3[0] && point2[1] < point3[1]) || point2[1] == point3[1] && point2[2] < point3[2]) {
            worldPos3 = data.handles.points[2];
            worldPos4 = data.handles.points[3];
        } else {
            worldPos3 = data.handles.points[3];
            worldPos4 = data.handles.points[2];
        }

------- Bug 9. ----------

TO FIX ALL BUGS IN FILE REPLACE ReferenceLinesToo.js WITH ONE PROVIDED IN Bug 9 FOLDER

When setting reference lines to false the renderAnnotations call for reference lines happens without a source
or targets which fails when trying to call getFrameOfReferenceUID()

Prevent syncing on disabled viewports

Prevent series with different Frame of reference UID from syncing 

Location: node_modules/@cornerstonejs/tools/dist/esm/tools/ReferenceLinesTool.js
Method: this.renderAnnotation
Change: return from method when target or source viewport are null

See image "noTargetOrSource.PNG" in Bug 9 folder for where to place the following check

if(!targetViewport || !sourceViewport) {
                return renderStatus;
}

Change: Return from method when either target or source viewport are disabled

See image "viewportDisabled.PNG" for where to place the following check

if(sourceViewport.isDisabled || targetViewport.isDisabled) {
    return renderStatus
}

Change: Return from method when target and source viewport do not share a frame of reference UID

See image "frameofref.png" for where to place the following check

let frameofref1= targetViewport.getFrameOfReferenceUID();
let frameofref2 = sourceViewport.getFrameOfReferenceUID();

if(frameofref1=  !== frameofref2 ) {
   return renderStatus;
}

------ Bug 10. -----------

In some cases the length tool displays px when the it should be mm due to the 
has pixel spacing boolean on the image being false incorrectly. This happens when image plane module 
is not present but is not always correct such as in the case of US. 

Location: node_modules/@cornerstonejs/tools/dist/esm/tools/annotation/LengthTool.js
Method: _calculateCachedStats
Change: check for whether a non default value for spacing has been set if hasPixelSpacing is false in lengthtool.js

See image provided in Bug 10 folder for where to place the following code

let pixelSpacing = hasPixelSpacing ? hasPixelSpacing : JSON.stringify((spacing) !== JSON.stringify([1, 1, 1]));
.
.
.
cachedStats[targetId] = {
	length, 
	unit: pixelSpacing ? 'mm' : 'px',
}

------ Bug 11. -----------

When removing viewport from tool group, mouse events try to destructure viewport and fail

Location: node_modules/@cornerstonejs/tools/dist/esm/eventListeners/mouse
Files: getMouseEventPointer.js & mouseDownListener.js
Change: When this happens return null and reset points

Replace files in @cornerstonejs/tools/dist/esm/eventListeners/mouse with those provided in Bug 11 folder

------ Bug 12. -----------

we dont wanna show cm or mm

Location: node_modules\@cornerstonejs\tools\dist\esm\tools
Files: ScaleOverlayTool.js
Change: When this happens return null and reset points

Replace file in node_modules\@cornerstonejs\tools\dist\esm\tools\ScaleOverlayTool.js with those provided in Bug 12 folder

------ Bug 13. -----------

Issues: 
1. Arrow annotation tool deosn't show the existing text when editing
2. Clicking "Cancel" while editing would remove the arrow text instead of just closing the dialog without changes.

Improvements:
Improved the "Arrow" annotation tool by ensuring that the existing annotation text is displayed in the editing dialog box when editing. 
Fixed the issue where clicking the "Cancel" button unintentionally removed the annotation text.

Location: node_modules\@cornerstonejs\tools\dist\esm\tools\annotation
File: ArrowAnnotateTool.js

Edit ArrowAnnotateTool.js according to the screenshot in the Bug 13 folder.

