This commit is contained in:
Ross
2021-11-11 18:09:05 +00:00
parent 227165bf2e
commit f4f89a3fc6
+92 -19
View File
@@ -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 = $(`<div class='temp-thumb' src=${reader.result}></div>`).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 = $(`<div class='temp-thumb' src=${reader.result}></div>`).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();
//}
}