This commit is contained in:
Ross
2021-03-07 13:47:36 +00:00
parent 2f22c3750b
commit fa00766620
2 changed files with 99 additions and 68 deletions
+98 -65
View File
@@ -244,9 +244,9 @@ async function loadPacketList(data) {
.append( .append(
$( $(
`<div class='save-button' title='Download packet for offline use (or to save bandwidth)'><a href='packets/${packet}' download='${packet}'>💾</a></div>` `<div class='save-button' title='Download packet for offline use (or to save bandwidth)'><a href='packets/${packet}' download='${packet}'>💾</a></div>`
).click(function () { ).click(function (evt) {
console.log("packets/" + packet); console.log("packets/" + packet);
event.stopPropagation(); evt.stopPropagation();
}) })
) )
); );
@@ -268,7 +268,6 @@ function loadPacketFromAjax(path) {
cache: true, cache: true,
progress: function (e) { progress: function (e) {
if (e.lengthComputable) { if (e.lengthComputable) {
console.log("1")
var completedPercentage = Math.round((e.loaded * 100) / e.total); var completedPercentage = Math.round((e.loaded * 100) / e.total);
$("#progress").html( $("#progress").html(
@@ -622,14 +621,12 @@ function loadQuestion(n, section = 1, force_reload = false) {
// Make sure we have an integer // Make sure we have an integer
n = parseInt(n); n = parseInt(n);
console.log(n); console.log("loading question (n)", n);
const qid = window.question_order[n]; const qid = window.question_order[n];
console.log("qid", qid); console.log("qid", qid);
const current_question = window.questions[qid]; const current_question = window.questions[qid];
console.log("N=", n, section, current_question);
if (n == window.loaded_question && force_reload == false) { if (n == window.loaded_question && force_reload == false) {
// Question already loaded // Question already loaded
setFocus(section); setFocus(section);
@@ -682,9 +679,11 @@ function loadQuestion(n, section = 1, force_reload = false) {
} }
// disable any further enabled elements // disable any further enabled elements
cornerstone.getEnabledElements().forEach((el) => { let enabled_elements = cornerstone.getEnabledElements();
cornerstone.disable(el.element); for (var i = enabled_elements.length - 1; i >= 0; i--) {
}) console.log("disable, ", enabled_elements[i]);
cornerstone.disable(enabled_elements[i].element);
}
cornerstone.imageCache.purgeCache(); cornerstone.imageCache.purgeCache();
@@ -700,7 +699,7 @@ function loadQuestion(n, section = 1, force_reload = false) {
// TODO: figure captions (need to extend base json) // TODO: figure captions (need to extend base json)
current_question.images.forEach(function createThumbnail(image, id) { current_question.images.forEach(function createThumbnail(image, id) {
console.log("create thumb", image); //console.log("create thumb", image);
// For thumbnails we only want a single image // For thumbnails we only want a single image
if (Array.isArray(image)) { if (Array.isArray(image)) {
image = image[0]; // Do we want the middle image? image = image[0]; // Do we want the middle image?
@@ -796,16 +795,19 @@ function loadQuestion(n, section = 1, force_reload = false) {
} else { } else {
$("#rapid-text").css("display", "none"); $("#rapid-text").css("display", "none");
} }
window.db.answers.put({
let answer = {
aid: aid, aid: aid,
cid: cid, cid: cid,
eid: eid, eid: eid,
qid: qid, qid: qid,
qidn: "1", qidn: "1",
ans: evt.target.value, ans: evt.target.value,
}); }
window.db.answers.put(answer);
saveSession(); saveSession();
updateQuestionListPanel(); updateQuestionListPanel(answer);
}); });
// Save long answers on textchange // Save long answers on textchange
@@ -818,22 +820,24 @@ function loadQuestion(n, section = 1, force_reload = false) {
).removeClass("question-saved-localdb"); ).removeClass("question-saved-localdb");
return; return;
} }
// db.answers.put({aid: [cid, eid, qidn], ans: evt.target.value});
window.db.answers.put({ let answer = {
aid: aid, aid: aid,
cid: cid, cid: cid,
eid: eid, eid: eid,
qid: qid, qid: qid,
qidn: "2", qidn: "2",
ans: evt.target.value, ans: evt.target.value,
}); }
// db.answers.put({aid: [cid, eid, qidn], ans: evt.target.value});
window.db.answers.put(answer);
$( $(
"#question-list-item-" + window.question_order.indexOf(qid) + "-2" "#question-list-item-" + window.question_order.indexOf(qid) + "-2"
).addClass("question-saved-localdb"); ).addClass("question-saved-localdb");
saveSession(); saveSession();
updateQuestionListPanel(); updateQuestionListPanel(answer);
}); });
// We chain our db requests as we can only check answers once // We chain our db requests as we can only check answers once
@@ -899,21 +903,23 @@ function loadQuestion(n, section = 1, force_reload = false) {
).removeClass("question-saved-localdb"); ).removeClass("question-saved-localdb");
return; return;
} }
// db.answers.put({aid: [cid, eid, qidn], ans: evt.target.value});
window.db.answers.put({ let answer = {
aid: aid, aid: aid,
cid: cid, cid: cid,
eid: eid, eid: eid,
qid: qid, qid: qid,
qidn: "1", qidn: "1",
ans: evt.target.value, ans: evt.target.value,
}); }
// db.answers.put({aid: [cid, eid, qidn], ans: evt.target.value});
window.db.answers.put(answer);
$( $(
"#question-list-item-" + window.question_order.indexOf(qid) + "-1" "#question-list-item-" + window.question_order.indexOf(qid) + "-1"
).addClass("question-saved-localdb"); ).addClass("question-saved-localdb");
saveSession(); saveSession();
updateQuestionListPanel(); updateQuestionListPanel(answer);
}); });
window.db.answers window.db.answers
@@ -987,14 +993,16 @@ function loadQuestion(n, section = 1, force_reload = false) {
return; return;
} }
// db.answers.put({aid: [cid, eid, qidn], ans: evt.target.value}); // db.answers.put({aid: [cid, eid, qidn], ans: evt.target.value});
window.db.answers.put({ const answer = {
aid: aid, aid: aid,
cid: cid, cid: cid,
eid: eid, eid: eid,
qid: qid, qid: qid,
qidn: qidn, qidn: qidn,
ans: evt.target.value, ans: evt.target.value,
}); }
window.db.answers.put(answer);
console.log("SAVE", qid, qidn, evt.target.value); console.log("SAVE", qid, qidn, evt.target.value);
$( $(
@@ -1004,7 +1012,7 @@ function loadQuestion(n, section = 1, force_reload = false) {
qidn qidn
).addClass("question-saved-localdb"); ).addClass("question-saved-localdb");
saveSession(); saveSession();
updateQuestionListPanel(); updateQuestionListPanel(answer);
}); });
// Loop through the 5 text areas and retrieve from db // Loop through the 5 text areas and retrieve from db
@@ -1047,8 +1055,8 @@ function loadQuestion(n, section = 1, force_reload = false) {
} }
} }
updateQuestionListPanel(); //rebuildQuestionListPanel();
setFocus(section); setTimeout(() => { setFocus(section); }, 200);
} }
/** /**
@@ -1057,7 +1065,7 @@ function loadQuestion(n, section = 1, force_reload = false) {
*/ */
function setFocus(section) { function setFocus(section) {
// Horrible (but it works) // Horrible (but it works)
setTimeout(function () { //setTimeout(function () {
// In pratique it selects the end of a textarea but I'm not sure if I can be bothered... // In pratique it selects the end of a textarea but I'm not sure if I can be bothered...
// Apparently I can... // Apparently I can...
const el = $("*[data-answer-section-qidn=" + section + "]"); const el = $("*[data-answer-section-qidn=" + section + "]");
@@ -1074,51 +1082,78 @@ function setFocus(section) {
} else { } else {
el.focus(); el.focus();
} }
}, 200); //}, 200);
} }
function updateQuestionListPanel(answer) {
$(
"#question-list-item-" +
window.question_order.indexOf(answer.qid) +
"-" +
answer.qidn
).addClass("question-saved-localdb");
if (window.question_type == "rapid" && answer.qidn == "1") {
if (answer.ans == "Abnormal") {
$(
"#question-list-item-" +
window.question_order.indexOf(answer.qid) +
"-2"
).css("display", "block");
} else {
$(
"#question-list-item-" +
window.question_order.indexOf(answer.qid) +
"-2"
).css("display", "none");
}
}
}
function deleteQuestionListPanelFlags(answer) {
$(
"#question-list-item-" +
window.question_order.indexOf(answer.qid) +
"-" +
answer.qidn +
" span"
).css("visibility", "hidden");
}
function updateQuestionListPanelFlags(answer) {
$(
"#question-list-item-" +
window.question_order.indexOf(answer.qid) +
"-" +
answer.qidn +
" span"
).css("visibility", "visible");
}
/** /**
* Updates the question list panel * Updates the question list panel
* Test with just a global update (may need to do these individually * Test with just a global update (may need to do these individually
* if it gets slow...) * if it gets slow...)
*/ */
function updateQuestionListPanel() { function rebuildQuestionListPanel() {
const aid = window.exam_details.aid; const aid = window.exam_details.aid;
const cid = window.exam_details.cid; const cid = window.exam_details.cid;
const eid = window.exam_details.eid; const eid = window.exam_details.eid;
console.log("UP"); console.log("UP");
// Reset all classes
window.db.answers window.db.answers
.where({ aid: aid, cid: cid, eid: eid }) .where({ aid: aid, cid: cid, eid: eid })
.toArray() .toArray()
.then(function (answers) { .then(function (answers) {
// Reset all classes (of question-list-item s)
$(".question-list-panel div") $(".question-list-panel div")
.slice(1) .slice(1)
.attr("class", "question-list-item"); .attr("class", "question-list-item");
answers.forEach(function (answer, n) {
$(
"#question-list-item-" +
window.question_order.indexOf(answer.qid) +
"-" +
answer.qidn
).addClass("question-saved-localdb");
if (window.question_type == "rapid" && answer.qidn == "1") { // Loop through each saved answer
if (answer.ans == "Abnormal") { answers.forEach(function (answer, n) {
$( updateQuestionListPanel(answer);
"#question-list-item-" +
window.question_order.indexOf(answer.qid) +
"-2"
).css("display", "block");
} else {
$(
"#question-list-item-" +
window.question_order.indexOf(answer.qid) +
"-2"
).css("display", "none");
}
}
}); });
// $(".long-answer").text(answer.ans); // $(".long-answer").text(answer.ans);
}) })
@@ -1131,13 +1166,7 @@ function updateQuestionListPanel() {
.toArray() .toArray()
.then(function (answers) { .then(function (answers) {
answers.forEach(function (answer, n) { answers.forEach(function (answer, n) {
$( updateQuestionListPanelFlags(answer);
"#question-list-item-" +
window.question_order.indexOf(answer.qid) +
"-" +
answer.qidn +
" span"
).css("visibility", "visible");
}); });
// $(".long-answer").text(answer.ans); // $(".long-answer").text(answer.ans);
}) })
@@ -1225,6 +1254,8 @@ function createQuestionListPanel() {
$(".question-list-item").click(function (evt) { $(".question-list-item").click(function (evt) {
loadQuestion($(this).attr("data-qid"), $(this).attr("data-qidn")); loadQuestion($(this).attr("data-qid"), $(this).attr("data-qidn"));
}); });
rebuildQuestionListPanel();
} }
$("#btn-local-file-load").click(function (evt) { $("#btn-local-file-load").click(function (evt) {
@@ -1387,7 +1418,6 @@ function reviewQuestions() {
if (model_answers[0] != undefined) { if (model_answers[0] != undefined) {
model_answers = model_answers[0]; model_answers = model_answers[0];
} }
console.log("test", window.questions[qid], model_answers);
const titles = [ const titles = [
"Observations", "Observations",
@@ -1621,7 +1651,7 @@ function reviewQuestions() {
.finally(() => { .finally(() => {
// This will lead to saveSession being called after each question is marked // This will lead to saveSession being called after each question is marked
saveSession(); saveSession();
updateQuestionListPanel(); rebuildQuestionListPanel();
}); });
}); });
}) })
@@ -1666,7 +1696,6 @@ function markAnswer(qid, current_question) {
if (type == "long") { if (type == "long") {
// For long cases we simple disable the texareas and append the // For long cases we simple disable the texareas and append the
// model answers // model answers
console.log(current_question);
let model_answers = current_question.answers[0]; let model_answers = current_question.answers[0];
// TODO: FIX THIS // TODO: FIX THIS
@@ -1738,7 +1767,7 @@ function markAnswer(qid, current_question) {
console.log("error-", error); console.log("error-", error);
}); });
addFeedback(current_question); addFeedback(current_question);
updateQuestionListPanel(); rebuildQuestionListPanel();
} }
} }
@@ -1821,23 +1850,27 @@ function addFlagEvents() {
el.toggleClass("flag flag-selected"); el.toggleClass("flag flag-selected");
const flag_db_data = { aid: aid, cid: cid, eid: eid, qid: qid, qidn: qidn };
if (el.hasClass("flag")) { if (el.hasClass("flag")) {
$("#question-list-item-" + nqid + "-" + qidn + " span").css( $("#question-list-item-" + nqid + "-" + qidn + " span").css(
"visibility", "visibility",
"hidden" "hidden"
); );
window.db.flags.delete([aid, cid, eid, qid, qidn]); window.db.flags.delete([aid, cid, eid, qid, qidn]);
deleteQuestionListPanelFlags(flag_db_data);
} else { } else {
$("#question-list-item-" + nqid + "-" + qidn + " span").css( $("#question-list-item-" + nqid + "-" + qidn + " span").css(
"visibility", "visibility",
"visible" "visible"
); );
window.db.flags.put({ aid: aid, cid: cid, eid: eid, qid: qid, qidn: qidn }); window.db.flags.put(flag_db_data);
updateQuestionListPanelFlags(flag_db_data);
} }
updateQuestionListPanel();
}); });
} }
// Loads the current question flag status and updates display
function loadFlagsFromDb(qid, n) { function loadFlagsFromDb(qid, n) {
const aid = window.exam_details.aid; const aid = window.exam_details.aid;
const cid = window.exam_details.cid; const cid = window.exam_details.cid;
+1 -3
View File
@@ -264,8 +264,6 @@ export function changeControlSelection() {
const old = sel.oldSelectedIndex; const old = sel.oldSelectedIndex;
sel.oldSelectedIndex = sel.selectedIndex; sel.oldSelectedIndex = sel.selectedIndex;
console.log(event);
const dicom_element = document.getElementById("dicom-image"); const dicom_element = document.getElementById("dicom-image");
switch (sel.options[sel.selectedIndex].value) { switch (sel.options[sel.selectedIndex].value) {
case "pan": { case "pan": {
@@ -533,7 +531,7 @@ export function openMainImage(current_question, t, source) {
toolStateManager.restoreToolState(tool_state); toolStateManager.restoreToolState(tool_state);
} }
async function load(images, annotations) { async function load(images, annotations) {
console.log("Load function", images) //console.log("Load function", images)
const imageIds = []; const imageIds = [];
for (let i = 0; i < images.length; i++) { for (let i = 0; i < images.length; i++) {
const data_url = images[i]; const data_url = images[i];