This commit is contained in:
Ross
2022-04-08 17:44:19 +01:00
parent 210f5dc70f
commit 0fcbf61432
3 changed files with 133 additions and 13 deletions
+95 -12
View File
@@ -15,7 +15,6 @@ cornerstoneTools.init({
let tool_state = {};
export function loadCornerstone(main_element, db, images, annotations_to_load, load_as_stack = false) {
// canvas-panel holds the enabled elements and all tools / menus
const canvas_panel = $("<div class='canvas-panel'></div>");
@@ -619,6 +618,7 @@ export function loadCornerstone(main_element, db, images, annotations_to_load, l
//console.log("LOAD and cache, then", image);
loadCornerstoneMainImage(element, image, stack, db, load_as_stack);
checkAnonStatus(image.data)
let load_annotation_image = true;
if (load_annotation_image) {
@@ -791,6 +791,12 @@ function keyDownHandler(e, element) {
}
e.preventDefault(); // Needed to stop the default action (scroll)
break;
case 38: // Up
manualScrollDicom(1, element);
break;
case 40: // down
manualScrollDicom(-1, element);
break;
case 46: // .
//toggleFlagged();
break;
@@ -865,6 +871,9 @@ function loadCornerstoneMainImage(element, image, stack, db, load_as_stack) {
const ArrowAnnotateTool = cornerstoneTools.ArrowAnnotateTool;
const RectangleRoiTool = cornerstoneTools.RectangleRoiTool;
const LengthTool = cornerstoneTools.LengthTool;
const AngleTool = cornerstoneTools.AngleTool;
const CobbAngleTool = cornerstoneTools.CobbAngleTool;
const EraserTool = cornerstoneTools.EraserTool;
cornerstone.enable(element);
element.tabIndex = 0;
@@ -886,6 +895,9 @@ function loadCornerstoneMainImage(element, image, stack, db, load_as_stack) {
cornerstoneTools.addToolForElement(element, StackScrollTool);
cornerstoneTools.addToolForElement(element, MagnifyTool);
cornerstoneTools.addToolForElement(element, LengthTool);
cornerstoneTools.addToolForElement(element, AngleTool);
cornerstoneTools.addToolForElement(element, CobbAngleTool);
cornerstoneTools.addToolForElement(element, EraserTool);
//cornerstoneTools.addTool(ArrowAnnotateTool);
//cornerstoneTools.addTool(RectangleRoiTool);
@@ -924,6 +936,9 @@ function loadCornerstoneMainImage(element, image, stack, db, load_as_stack) {
"Length",
"ArrowAnnotate",
"RectangleRoi",
"Angle",
"CobbAngle",
"Eraser",
];
$(".mouse-binding-select option").remove();
@@ -973,6 +988,7 @@ function loadCornerstoneMainImage(element, image, stack, db, load_as_stack) {
loadAltDicomInterface(db);
element.addEventListener("cornerstoneimagerendered", onImageRendered);
element.addEventListener("cornerstonenewimage", onNewImage);
//element.addEventListener("cornerstonetoolskeydown", keyDownHandler);
//setDicomCanvasNonFullscreen(element);
@@ -1012,7 +1028,9 @@ function loadCornerstoneMainImage(element, image, stack, db, load_as_stack) {
$(element).on("mouseup", function (event) {
console.log(event)
if (event.which == 4) { getNextAnnotationImage(element)}
if (event.which == 4) {
getNextAnnotationImage(element)
}
$(".magnifyTool").hide();
});
}
@@ -1053,6 +1071,48 @@ async function loadAltDicomInterface(db) {
});
}
function onNewImage(e) {
let dataSet = e.detail.image.data;
checkAnonStatus(dataSet)
}
function checkAnonStatus(dataSet) {
let accession_number = dataSet.string('x00080050').toLowerCase();
let patient_id = dataSet.string('x00100020').toLowerCase();
let not_anon = false;
let site_codes = ["ref", "rk9", "ra9", "rh8", "rbz", "rba"]
for (let i = 0; i < site_codes.length; i++) {
if (
accession_number.startsWith(site_codes[i]) ||
patient_id.startsWith(site_codes[i])) {
not_anon = true;
}
}
if (not_anon) {
toastr.warning(`File does not appear to be annonymised<br/>Accession: ${accession_number} <br/>Patient ID: ${patient_id}<br/>`, 'Anonymisation warning', {
"closeButton": false,
"debug": false,
"newestOnTop": false,
"progressBar": false,
"positionClass": "toast-top-full-width",
"preventDuplicates": false,
"onclick": null,
"showDuration": "0",
"hideDuration": "0",
"timeOut": 0,
"extendedTimeOut": 0,
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut",
});
}
}
// Called when the dicom image is loaded / rendered
function onImageRendered(e) {
const eventData = e.detail;
@@ -1071,16 +1131,6 @@ function onImageRendered(e) {
$(".thumb").removeClass("thumb-active");
$("#thumb-" + stack.currentImageIdIndex).addClass("thumb-active");
}
//if (stack.imageIds.length > 1) {
// $("option[value=scroll").prop("disabled", false);
// $("option[value=scroll").prop("hidden", false);
// $("option[value=scroll").text(
// "scroll (" +
// (stack.currentImageIdIndex + 1) +
// "/" +
// stack.imageIds.length +
// ")"
// );
}
function stopEvent(evt) {
@@ -1222,4 +1272,37 @@ export function getNextAnnotationImage(element) {
}
}
}
}
function manualScrollDicom(n, dicom_element) {
// There must be a better way to do this...
//dicom_element = document.getElementById("dicom-image");
let c = cornerstone.getEnabledElement(dicom_element);
let max = c.toolStateManager.toolState.stack.data[0].imageIds.length;
if (max < 2) {
return;
}
let current_index =
c.toolStateManager.toolState.stack.data[0].currentImageIdIndex;
let new_index = current_index + n
let corrected_index = Math.min(Math.max(new_index, 0), max)
// TODO: if loop
//if (new_index >= max) {
// corrected_index = new_index - max;
//} else if (new_index < 0) {
// corrected_index = new_index + max;
//}
c.toolStateManager.toolState.stack.data[0].currentImageIdIndex = corrected_index;
let id = c.toolStateManager.toolState.stack.data[0].imageIds[corrected_index];
cornerstone.loadImage(id).then((b) => {
cornerstone.displayImage(dicom_element, b);
});
// c = cornerstone.getEnabledElement(dicom_element)
}
+2 -1
View File
@@ -25,7 +25,8 @@
<h1>A dicom viewer</h1>
<!-- <div id="dicom-viewer" class="dicom-viewer" style="height: 600px;" data-images='["test_images/IMG1.dcm","test_images/IMG1.dcm"]' data-annotations='[&quot;{\&quot;ArrowAnnotate\&quot;:{\&quot;data\&quot;:[{\&quot;visible\&quot;:true,\&quot;active\&quot;:false,\&quot;handles\&quot;:{\&quot;start\&quot;:{\&quot;x\&quot;:450.01249999999993,\&quot;y\&quot;:592.8031510416666,\&quot;highlight\&quot;:true,\&quot;active\&quot;:false},\&quot;end\&quot;:{\&quot;x\&quot;:283.38750000000005,\&quot;y\&quot;:343.976484375,\&quot;highlight\&quot;:true,\&quot;active\&quot;:false,\&quot;moving\&quot;:false},\&quot;textBox\&quot;:{\&quot;active\&quot;:false,\&quot;hasMoved\&quot;:false,\&quot;movesIndependently\&quot;:false,\&quot;drawnIndependently\&quot;:true,\&quot;allowedOutsideImage\&quot;:true,\&quot;hasBoundingBox\&quot;:true}},\&quot;uuid\&quot;:\&quot;51ca68b0-734c-4046-b3da-dd2886496fd5\&quot;,\&quot;invalidated\&quot;:true}]}}&quot;, null]'></div></div> -->
<div id="dicom-viewer" class="dicom-viewer" style="height: 600px;" data-images='["test_images/IMG1.dcm", "test_images/IMG2.dcm", "test_images/IMG3.dcm", "test_images/IMG4.dcm", "test_images/IMG5.dcm", "test_images/IMG6.dcm"]' data-annotations=''></div></div>
<div id="dicom-viewer" class="dicom-viewer" style="height: 600px;" data-images='["test_images/IMG1.dcm", "test_images/IMG2.dcm", "test_images/IMG3.dcm", "test_images/IMG4.dcm", "test_images/IMG5.dcm", "test_images/IMG6.dcm"]' data-annotations=''></div>
<!-- <div id="dicom-viewer2" class="dicom-viewer" style="height: 600px;" data-images='["test_images/IMG1.dcm", "test_images/IMG2.dcm", "test_images/IMG3.dcm", "test_images/IMG4.dcm", "test_images/IMG5.dcm", "test_images/IMG6.dcm"]' data-annotations=''></div> -->
<!-- <div id="dicom-viewer" class="dicom-viewer" style="height: 600px;" data-images='["test_images/CXR.dcm"]' data-annotations=''></div></div> -->
</main>
+36
View File
@@ -43,4 +43,40 @@ function loadDicomViewer(images_to_load, annotations_to_load) {
dicomViewer.loadCornerstone($(single_dicom), null, images, annotations, load_as_stack);
}
}
let single_dicom2 = document.getElementById("dicom-viewer2");
if (single_dicom2) {
let images = single_dicom2.dataset.images;
if (images_to_load != undefined) {
images = images_to_load;
} else {
images = JSON.parse(images);
}
console.log(images);
let annotations = single_dicom2.dataset.annotations;
if (annotations_to_load != undefined) {
annotations = annotations_to_load;
} else if (annotations && annotations.indexOf(",") > 0) {
console.log("annon2", annotations)
annotations = JSON.parse(annotations);
} else {
annotations = undefined;
}
console.log("annon1", annotations)
let load_as_stack;
if (images.length > 5) {
load_as_stack = true;
} else {
load_as_stack = false;
}
if (images) {
dicomViewer.loadCornerstone($(single_dicom2), null, images, annotations, load_as_stack);
}
}
}