.
This commit is contained in:
+5
-2
@@ -149,7 +149,7 @@ class SeriesForm(ModelForm):
|
||||
"all": ["css/widgets.css"],
|
||||
}
|
||||
# Adding this javascript is crucial
|
||||
js = ["jsi18n.js", "tesseract.min.js"]
|
||||
js = ["jsi18n.js", "tesseract.min.js", "js/upload_form_helpers.js"]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.user = kwargs.pop(
|
||||
@@ -239,7 +239,7 @@ class CaseForm(ModelForm):
|
||||
"all": ["css/widgets.css"],
|
||||
}
|
||||
# Adding this javascript is crucial
|
||||
js = ["jsi18n.js", "tesseract.min.js"]
|
||||
js = ["jsi18n.js", "tesseract.min.js", "js/upload_form_helpers.js"]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
logging.info("LOG")
|
||||
@@ -371,6 +371,7 @@ CaseDifferentialFormSet = inlineformset_factory(
|
||||
|
||||
|
||||
class CaseSeriesForm(ModelForm):
|
||||
|
||||
def __init__(self, *args, user, **kwargs):
|
||||
super(CaseSeriesForm, self).__init__(*args, **kwargs)
|
||||
|
||||
@@ -386,6 +387,8 @@ class CaseSeriesForm(ModelForm):
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
class CaseCollectionCaseForm(ModelForm):
|
||||
def __init__(self, *args, user, **kwargs):
|
||||
super(CaseCollectionCaseForm, self).__init__(*args, **kwargs)
|
||||
|
||||
@@ -6,15 +6,10 @@
|
||||
<!--<script type="text/javascript" src="/admin/jsi18n/"></script>-->
|
||||
|
||||
<script type="text/javascript">
|
||||
let crsf_token = "{{csrf_token}}";
|
||||
let hash_url = false;
|
||||
document.addEventListener('drop', function (e) { e.preventDefault(); }, false);
|
||||
|
||||
function add_input_form() {
|
||||
var form_idx = $('#id_images-TOTAL_FORMS').val();
|
||||
$('#image_form_set').append($('#empty_form').html().replace(/__prefix__/g, form_idx));
|
||||
$('#id_images-TOTAL_FORMS').val(parseInt(form_idx) + 1);
|
||||
}
|
||||
|
||||
|
||||
$(document).ready(function () {
|
||||
$("#add_examination").appendTo($("label[for='id_examination']"));
|
||||
|
||||
@@ -44,71 +39,93 @@
|
||||
dropContainer.ondrop = function (evt) {
|
||||
$(evt.target).removeClass("drop-target-active");
|
||||
|
||||
file_drop_number = evt.dataTransfer.files.length;
|
||||
|
||||
if (evt.dataTransfer.files.length < 1) {
|
||||
toastr.warning(`Drop failed :( try again?`);
|
||||
if (file_drop_number < 1) {
|
||||
toastr.warning(`Drop failed (no files), try again.`);
|
||||
} else {
|
||||
toastr.info(`Adding ${evt.dataTransfer.files.length} files.`);
|
||||
toastr.info(`Loading ${file_drop_number} dropped image(s).`);
|
||||
}
|
||||
|
||||
// Get all input elements
|
||||
inputs = $("#atlas-form input[type=file][id^=id_images-]");
|
||||
//fileInput = document.getElementById("id_images-0-image");
|
||||
inputs = extendInputs("atlas-form", file_drop_number);
|
||||
|
||||
// Make sure we have enough input targets
|
||||
input_diff = (evt.dataTransfer.files.length - inputs.length)
|
||||
console.log("drop inputs", inputs, evt);
|
||||
|
||||
if (input_diff > 0) {
|
||||
for (let j = 0; j < input_diff; j++) {
|
||||
add_input_form()
|
||||
}
|
||||
|
||||
// Need to make sure we include the new ones...
|
||||
inputs = $("#atlas-form input[type=file][id^=id_images-]");
|
||||
}
|
||||
|
||||
// Loop through each dropped file and try to assign to an
|
||||
// input element
|
||||
[...evt.dataTransfer.files].forEach((f) => {
|
||||
let dT = new DataTransfer();
|
||||
dT.clearData();
|
||||
dT.items.add(f);
|
||||
for (let i = 0; i < inputs.length; i++) {
|
||||
el = inputs.get(i)
|
||||
|
||||
if (el.files.length == 0) {
|
||||
el.files = dT.files;
|
||||
//ocr(el)
|
||||
|
||||
return false
|
||||
}
|
||||
feedback = false;
|
||||
if (evt.target.id == "feedback-drop-target") {
|
||||
feedback = true;
|
||||
}
|
||||
addFile(f, feedback)
|
||||
})
|
||||
|
||||
// // If you want to use some of the dropped files
|
||||
// const dT = new DataTransfer();
|
||||
// dT.items.add(evt.dataTransfer.files[0]);
|
||||
// dT.items.add(evt.dataTransfer.files[3]);
|
||||
// fileInput.files = dT.files;
|
||||
|
||||
loadDicomViewerAndFileImages();
|
||||
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
};
|
||||
//dropContainer.ondrop = function (evt) {
|
||||
// $(evt.target).removeClass("drop-target-active");
|
||||
|
||||
|
||||
// if (evt.dataTransfer.files.length < 1) {
|
||||
// toastr.warning(`Drop failed :( try again?`);
|
||||
// } else {
|
||||
// toastr.info(`Adding ${evt.dataTransfer.files.length} files.`);
|
||||
// }
|
||||
|
||||
// // Get all input elements
|
||||
// inputs = $("#atlas-form input[type=file][id^=id_images-]");
|
||||
// //fileInput = document.getElementById("id_images-0-image");
|
||||
|
||||
// // Make sure we have enough input targets
|
||||
// input_diff = (evt.dataTransfer.files.length - inputs.length)
|
||||
|
||||
// if (input_diff > 0) {
|
||||
// for (let j = 0; j < input_diff; j++) {
|
||||
// add_input_form()
|
||||
// }
|
||||
|
||||
// // Need to make sure we include the new ones...
|
||||
// inputs = $("#atlas-form input[type=file][id^=id_images-]");
|
||||
// }
|
||||
|
||||
// // Loop through each dropped file and try to assign to an
|
||||
// // input element
|
||||
// [...evt.dataTransfer.files].forEach((f) => {
|
||||
// let dT = new DataTransfer();
|
||||
// dT.clearData();
|
||||
// dT.items.add(f);
|
||||
// for (let i = 0; i < inputs.length; i++) {
|
||||
// el = inputs.get(i)
|
||||
|
||||
// if (el.files.length == 0) {
|
||||
// el.files = dT.files;
|
||||
// //ocr(el)
|
||||
|
||||
// return false
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
|
||||
// // // If you want to use some of the dropped files
|
||||
// // const dT = new DataTransfer();
|
||||
// // dT.items.add(evt.dataTransfer.files[0]);
|
||||
// // dT.items.add(evt.dataTransfer.files[3]);
|
||||
// // fileInput.files = dT.files;
|
||||
|
||||
// loadDicomViewerAndFileImages();
|
||||
|
||||
// evt.preventDefault();
|
||||
// evt.stopPropagation();
|
||||
//};
|
||||
|
||||
|
||||
$('#add_more_images').click(() => { add_input_form() });
|
||||
|
||||
$("input[type=file]").on('change', function () {
|
||||
$(this).removeClass("image-ident-warning");
|
||||
$(this).removeClass("image-ident-ok");
|
||||
console.log("input change1");
|
||||
console.log("input change", this);
|
||||
//ocr(this);
|
||||
//LoadDicomViewer();
|
||||
|
||||
});
|
||||
$("input[type=file]").on('change', input_change);
|
||||
|
||||
|
||||
|
||||
@@ -134,63 +151,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
function ocr(input) {
|
||||
// Tesseract.recognize(f, "eng",{ logger: m => console.log(m) }
|
||||
// ).then(({ data: { text } }) => {
|
||||
// console.log(text);
|
||||
// l = text.toLowerCase();
|
||||
// if (l.includes("accesion") || l.includes("number") || l.search(/(REF|RK9|RH8|RA9)\d+/g)) {
|
||||
// console.log("SHIT", this);
|
||||
// }
|
||||
// })
|
||||
|
||||
console.log('{% static "worker.min.js" %}');
|
||||
console.log('{{ STATIC_URL }}/tesseract-core.wasm.js %}');
|
||||
|
||||
const worker = Tesseract.createWorker({
|
||||
workerPath: '{% static "worker.min.js" %}',
|
||||
langPath: '{% static "" %}',
|
||||
//langPath: '{{ STATIC_URL }}',
|
||||
corePath: '{% static "tesseract-core.wasm.js" %}',
|
||||
});
|
||||
|
||||
const url = URL.createObjectURL(input.files[0]);
|
||||
let img = new Image;
|
||||
img.src = url;
|
||||
|
||||
img.onload = function () {
|
||||
|
||||
|
||||
width = img.width;
|
||||
|
||||
// const rectangle = { left: 0, top: 0, width: width, height: 10 }
|
||||
|
||||
|
||||
(async () => {
|
||||
await worker.load();
|
||||
await worker.loadLanguage('eng');
|
||||
await worker.initialize('eng');
|
||||
// const { data: { text } } = await worker.recognize(input.files[0], { rectangle });
|
||||
const { data: { text } } = await worker.recognize(input.files[0]);
|
||||
//console.log(text);
|
||||
l = text.toLowerCase();
|
||||
$(`img[data-input-id='${input.id}'`).removeClass("image-ident-loading");
|
||||
console.log(l);
|
||||
if (l.includes("accesion") || l.includes("number") || l.search(/(ref|rk9|rh8|ra9|rbz)\d+/g) > -1) {
|
||||
$(input).addClass("image-ident-warning");
|
||||
$(`img[data-input-id='${input.id}'`).addClass("image-ident-warning");
|
||||
} else {
|
||||
$(input).addClass("image-ident-ok");
|
||||
|
||||
}
|
||||
|
||||
await worker.terminate();
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function loadDicomViewerAndFileImages(callback) {
|
||||
$("#single-dicom-viewer").empty()
|
||||
//images = []
|
||||
@@ -263,55 +223,29 @@
|
||||
|
||||
}
|
||||
|
||||
function loadViewer(images) {
|
||||
//dicomViewer.loadCornerstone($("#single-dicom-viewer"), null, images, annotations);
|
||||
file_set = $("#image_form_set input[type=file]");
|
||||
|
||||
n = 0;
|
||||
for (let i = 0; i < file_set.length; i++) {
|
||||
el = file_set.get(i)
|
||||
if (el.files.length > 0) {
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
image_set = $("#image_form_set img");
|
||||
if (n == image_set.length) {
|
||||
const event = new CustomEvent('loadDicomViewer', { "detail": image_set });
|
||||
|
||||
window.dispatchEvent(event);
|
||||
sortable('.sortable');
|
||||
//sortable('.sortable')[0].addEventListener('sortstop', function(e) {
|
||||
updateImagePositions();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function updateImagePositions() {
|
||||
console.log("UP pos");
|
||||
|
||||
file_set = $("#image_form_set ul");
|
||||
|
||||
n = 0;
|
||||
for (let i = 0; i < file_set.length; i++) {
|
||||
ul = file_set.get(i);
|
||||
console.log(ul)
|
||||
|
||||
file_element = $(ul).find("input[type=file]").get(0);
|
||||
|
||||
// If a (new) file is being uploaded we save it's name prior to it being hashed
|
||||
if (file_element.files.length > 0) {
|
||||
file_name = file_element.files[0].name
|
||||
$(ul).find("input[type=text]").val(file_name);
|
||||
}
|
||||
|
||||
if (file_element.files.length > 0 || $(ul).find(":contains('Currently:')")) {
|
||||
n++;
|
||||
$(ul).find("input[type=number]").val(n);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// function loadViewer(images) {
|
||||
// //dicomViewer.loadCornerstone($("#single-dicom-viewer"), null, images, annotations);
|
||||
// file_set = $("#image_form_set input[type=file]");
|
||||
//
|
||||
// n = 0;
|
||||
// for (let i = 0; i < file_set.length; i++) {
|
||||
// el = file_set.get(i)
|
||||
// if (el.files.length > 0) {
|
||||
// n++;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// image_set = $("#image_form_set img");
|
||||
// if (n == image_set.length) {
|
||||
// const event = new CustomEvent('loadDicomViewer', { "detail": image_set });
|
||||
//
|
||||
// window.dispatchEvent(event);
|
||||
// sortable('.sortable');
|
||||
// //sortable('.sortable')[0].addEventListener('sortstop', function(e) {
|
||||
// updateImagePositions();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
function extractDicomDetails(byteArray) {
|
||||
// We need to setup a try/catch block because parseDicom will throw an exception
|
||||
@@ -486,13 +420,12 @@
|
||||
</table>
|
||||
|
||||
<h3>Images:</h3>
|
||||
<input type="button" value="Add More Images (manually)" id="add_more_images">
|
||||
<div id="drop-container" class="series-drop">Drop images here (or use the buttons below). Dropping images here will overwrite
|
||||
existing images in the series. When drag and dropping make sure to drag the first image or the order will not be
|
||||
maintained. Note: dicom images are often not exported in order (although their order can be automatically
|
||||
detected once uploaded)
|
||||
<div id="single-dicom-viewer" class="dicom-viewer" data-images="" data-annotations=''></div>
|
||||
<div id="drop-filenames"></div>
|
||||
{% comment %} <div id="drop-filenames"></div> {% endcomment %}
|
||||
</div>
|
||||
<div id="image_form_set" class="sortable">
|
||||
{% for form in image_formset %}
|
||||
|
||||
Reference in New Issue
Block a user