From f4f89a3fc61c4f93a430aae94e7e849698899c87 Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 11 Nov 2021 18:09:05 +0000 Subject: [PATCH] . --- rapids/templates/rapids/rapid_form.html | 111 ++++++++++++++++++++---- 1 file changed, 92 insertions(+), 19 deletions(-) diff --git a/rapids/templates/rapids/rapid_form.html b/rapids/templates/rapids/rapid_form.html index ab5e8f83..0b91ba7f 100755 --- a/rapids/templates/rapids/rapid_form.html +++ b/rapids/templates/rapids/rapid_form.html @@ -150,7 +150,8 @@ } - readFileAndProcess(); + //readFileAndProcess(); + readFileAndProcess2(); // Check if we have selected a examination type if (!$("#id_examination_to option").length) { @@ -450,6 +451,89 @@ } } + async function readFileAndProcess2(callback) { + //$("#single-dicom-viewer").empty() + //images = [] + //Function that returns a promise to read the file + const reader = (file) => { + return new Promise((resolve, reject) => { + const fileReader = new FileReader(); + fileReader.onload = () => resolve(fileReader); + fileReader.readAsDataURL(file); + }); + } + + // Add file to the process list + active_file_inputs.add(el) + const readFile = (file, el) => { + reader(file).then(reader => { + console.log("12345", reader) + $(el).parent().parent().find(".temp-thumb").remove(); + + if (reader.result.startsWith("data:application/octet-stream;base64")) { + const element = $(`
`).get(0) + $(el).parent().parent().prepend(element); + const imageId = cornerstoneWADOImageLoader.wadouri.fileManager.add( + file + ); + cornerstone.enable(element); + cornerstone.loadAndCacheImage(imageId).then(function (image) { + cornerstone.displayImage(element, image); + cornerstone.resize(element) + + }); + + } else { + var image = new Image(); + image.title = file.name; + image.src = reader.result; + image.className = "temp-thumb"; + $(el).parent().parent().prepend(image); + //images.push(reader.result); + } + + active_file_inputs.delete(el) + console.log("active", active_file_inputs) + // Only load once all queued files have been processed + if (active_file_inputs.size < 1) { + loadViewer(); + } + }); + } + + file_set = $("#image_form_set input[type=file]"); + + file_set.each(async (n, el) => { + if (el.files.length > 0) { + filename = el.files[0].name; + // Probably no need to await here anymore + //await readFile(el.files[0], el); + + let url = URL.createObjectURL(el.files[0]) + + $(el).parent().parent().find(".temp-thumb").remove(); + + const element = $(`
`).get(0) + $(el).parent().parent().prepend(element); + const imageId = `wadouri:${a}`; + cornerstone.enable(element); + cornerstone.loadAndCacheImage(imageId).then(function (image) { + cornerstone.displayImage(element, image); + cornerstone.resize(element) + + }); + + + active_file_inputs.delete(el) + console.log("active", active_file_inputs) + // Only load once all queued files have been processed + if (active_file_inputs.size < 1) { + loadViewer(); + } + } + }) + } + async function readFileAndProcess(callback) { //$("#single-dicom-viewer").empty() //images = [] @@ -491,9 +575,6 @@ //images.push(reader.result); } - - - active_file_inputs.delete(el) console.log("active", active_file_inputs) // Only load once all queued files have been processed @@ -503,12 +584,8 @@ }); } - - file_set = $("#image_form_set input[type=file]"); - - file_set.each(async (n, el) => { if (el.files.length > 0) { filename = el.files[0].name; @@ -516,10 +593,6 @@ await readFile(el.files[0], el); } }) - - - - } function loadViewer() { @@ -540,14 +613,14 @@ console.log(image_set); //console.log() //if (n == image_set.length) { - const event = new CustomEvent('loadDicomViewer', { - "detail": image_set - }); + const event = new CustomEvent('loadDicomViewer', { + "detail": image_set + }); - window.dispatchEvent(event); - sortable('.sortable'); - //sortable('.sortable')[0].addEventListener('sortstop', function(e) { - updateImagePositions(); + window.dispatchEvent(event); + sortable('.sortable'); + //sortable('.sortable')[0].addEventListener('sortstop', function(e) { + updateImagePositions(); //} }