From bfe5be807e30733a63d711f9ad3f4d0bdf5b1cbd Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 21 Oct 2024 13:27:22 +0100 Subject: [PATCH] add a few more anon checks --- atlas/templates/atlas/new_uploads.html | 70 +++++++++++++++----------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/atlas/templates/atlas/new_uploads.html b/atlas/templates/atlas/new_uploads.html index abc5142d..5909b62e 100644 --- a/atlas/templates/atlas/new_uploads.html +++ b/atlas/templates/atlas/new_uploads.html @@ -22,7 +22,7 @@
Settings - +
@@ -47,6 +47,15 @@ +

Selected files:

@@ -116,15 +125,12 @@ } function uploadFiles(files_to_upload, current_chunk, total_chunks){ - console.log("uploading", files_to_upload) - // Create a FormData object to store the form data const formData = new FormData(); // Append each selected file to the FormData object for (let i = 0; i < files_to_upload.length; i++) { formData.append("files", files_to_upload[i]); } - console.log("formdata", formData) const xhr = new XMLHttpRequest(); xhr.open("POST", "{% url 'api-1:upload_dicom' %}", true); xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}"); @@ -134,8 +140,6 @@ window.upload_count += 1; if (xhr.status === 200) { // Handle successful response from the server - console.log('Files uploaded successfully!'); - console.log(xhr.response); window.upload_results["uploaded"].push(...JSON.parse(xhr.response)["uploaded"]); window.upload_results["duplicates"].push(...JSON.parse(xhr.response)["duplicates"]); window.upload_results["failed"].push(...JSON.parse(xhr.response)["failed"]); @@ -180,14 +184,12 @@ xhr.send(formData); } - function checkAnnonymisation(byteArray) { + function checkAnnonymisation(byteArray, file) { // We need to setup a try/catch block because parseDicom will throw an exception // if you attempt to parse a non dicom part 10 file (or one that is corrupted) try { - console.log("bytearray", byteArray) // parse byteArray into a DataSet object using the parseDicom library var dataSet = dicomParser.parseDicom(byteArray); - console.log("ds", dataSet) // dataSet contains the parsed elements. Each element is available via a property // in the dataSet.elements object. The property name is based on the elements group @@ -200,24 +202,25 @@ var study_description = dataSet.string('x00081030'); var accession_number = dataSet.string('x00080050').toLowerCase(); var patient_id = dataSet.string('x00100020').toLowerCase(); - console.log("STUDY", study_description); - console.log("acc", accession_number); - console.log("pid", patient_id); - not_anon = false; site_codes = ["ref", "rk9", "ra9", "rh8", "rbz", "rba"] + errors = [] for (let i = 0; i < site_codes.length; i++) { - if ( - accession_number.startsWith(site_codes[i]) || - patient_id.startsWith(site_codes[i]) - ) + if ( accession_number.startsWith(site_codes[i])) { not_anon = true; + errors.push(`Accession number starts with ${site_codes[i]} (${accession_number})`); + } + if ( patient_id.startsWith(site_codes[i])) + { + not_anon = true; + errors.push(`Patient ID starts with ${site_codes[i]} (${patient_id})`); } } + console.log(errors) if (not_anon) { toastr.warning(`File does not appear to be annonymised
Accession: ${accession_number}
Patient ID: ${patient_id}
`, 'Anonymisation warning', { @@ -237,7 +240,16 @@ "showMethod": "fadeIn", "hideMethod": "fadeOut", }); - $("uploadButton").prop("disabled", true); + $("#uploadButton").prop("disabled", true); + $(".anon-alert").show(); + + setTimeout( + function(errors) { + console.log(errors) + // We delay this a few seconds otherwise it does not work + $(`.dicom-file[data-path='${file.webkitRelativePath}']`).addClass("image-ident-warning").append($(`
${errors.join("
")}
`)); + }, 2000, errors + ) } // TODO: fix @@ -269,7 +281,8 @@ return false; } } - async function loadDicomViewerTest(callback) { + async function loadDicomViewerUploads(callback) { + $("#uploadButton").attr("disabled", false); $("#single-dicom-viewer").hide(); console.log("load") $("#single-dicom-viewer").empty() @@ -285,7 +298,6 @@ const readFile = (file, el) => { reader(file).then(reader => { - console.log("hello", file, el, image) //if ($("#id_examination").find(":selected")[0].dataset.select2Id == "2") { // var byteArray = new Uint8Array(reader.result); // console.log("etrxact", reader) @@ -296,7 +308,6 @@ image.title = file.name; image.src = reader.result; image.className = "temp-thumb"; - console.log("read", el); $(el).append(image); //images.push(reader.result); loadViewer(images); @@ -315,8 +326,7 @@ const readDicomFile = (file) => { return dicomReader(file).then(reader => { var byteArray = new Uint8Array(reader.result); - console.log("etrxact", reader) - return checkAnnonymisation(byteArray); + return checkAnnonymisation(byteArray, file); }); } @@ -341,12 +351,12 @@ let item = document.createElement("li"); item.className = "dicom-file"; item.textContent = file.webkitRelativePath; + item.dataset.path = file.webkitRelativePath; output.appendChild(item); //await readFile(file, item); let url = URL.createObjectURL(file) - console.log(url) imageId = `wadouri:${url}`; if ($("#show-viewer").is(":checked")) { images.push(imageId); @@ -384,8 +394,6 @@ } } - console.log(images) - const event = new CustomEvent('loadDicomViewerUrls', { "detail": {"images": images, "annontations": undefined} @@ -401,7 +409,6 @@ } function ocr(url, input) { - console.log("OCR", input) Tesseract.recognize( url, 'eng', @@ -414,7 +421,6 @@ l = text.toLowerCase(); uploading_el = $(`img[data-input-id='${input.id}'], div[data-input-id='${input.id}']`) uploading_el.removeClass("image-ident-loading"); - console.log("found text", l); if (l.includes("accession") || l.includes("number") || l.search( /(ref|rk9|rh8|ra9|rbz)\d+/g) > -1) { console.log("Match found ", input); @@ -457,7 +463,7 @@ // output.appendChild(item); //} - loadDicomViewerTest(); + loadDicomViewerUploads(); }, false, ); @@ -469,4 +475,10 @@ }); + {% endblock %} \ No newline at end of file