start with ESlint

This commit is contained in:
Ross
2020-04-28 13:42:22 +01:00
parent e5c49d91bf
commit be8337751e
+134 -130
View File
@@ -8,7 +8,7 @@ window.exam_mode = false;
window.packet_list = []; window.packet_list = [];
// var questions = null window.questions = null;
window.question_order = []; window.question_order = [];
window.number_of_questions = null; window.number_of_questions = null;
window.question_type = null; window.question_type = null;
@@ -19,7 +19,6 @@ window.allow_self_marking = true;
window.dfile = null; window.dfile = null;
retrievePacketList(); retrievePacketList();
/** /**
@@ -31,20 +30,16 @@ function retrievePacketList() {
$.getJSON("packets/", function (data) { $.getJSON("packets/", function (data) {
loadPacketList(data); loadPacketList(data);
}) })
.done(function() { .done(function () {})
})
.fail(function () { .fail(function () {
$.getJSON("packets/packets.json", function (data) { $.getJSON("packets/packets.json", function (data) {
loadPacketList(data); loadPacketList(data);
}) }).fail(function () {
.fail(function() {
console.log("No packet list available"); console.log("No packet list available");
showLoginDialog(); showLoginDialog();
}); });
}) })
.always(function() { .always(function () {});
});
// setUpPacket(questions); // setUpPacket(questions);
} }
@@ -60,7 +55,8 @@ function loadPacketList(data) {
$("#packet-list").append( $("#packet-list").append(
$("<div class='packet-button'>" + packet + "</div>").click(function () { $("<div class='packet-button'>" + packet + "</div>").click(function () {
loadPacketFromAjax("packets/" + packet); loadPacketFromAjax("packets/" + packet);
})); })
);
}); });
$("#options-panel").show(); $("#options-panel").show();
} }
@@ -75,8 +71,7 @@ function loadPacketFromAjax(path) {
setUpPacket(data); setUpPacket(data);
$("#options-panel").hide(); $("#options-panel").hide();
}) })
.done(function() { .done(function () {})
})
.fail(function () { .fail(function () {
console.log("Unable to load packet at: " + path); console.log("Unable to load packet at: " + path);
}); });
@@ -86,31 +81,31 @@ function loadPacketFromAjax(path) {
* Build the currently loaded quiz * Build the currently loaded quiz
*/ */
function setUpQuestions() { function setUpQuestions() {
if (questions == undefined) { if (window.questions == undefined) {
return; return;
} }
// Set an order for the questions // Set an order for the questions
window.question_order = []; window.question_order = [];
Object.keys(questions).forEach(function(e) { Object.keys(window.questions).forEach(function (e) {
window.question_order.push(e); window.question_order.push(e);
// Make sure answers are arrays // Make sure answers are arrays
if (!Array.isArray(questions[e]["answers"])) { if (!Array.isArray(window.questions[e]["answers"])) {
questions[e]["answers"] = [questions[e]["answers"]]; window.questions[e]["answers"] = [window.questions[e]["answers"]];
} }
}); });
console.log("pre", window.question_order); console.log("pre", window.question_order);
window.question_order = helper.shuffleArray(window.question_order); window.question_order = helper.shuffleArray(window.question_order);
console.log("post", window.question_order); console.log("post", window.question_order);
window.number_of_questions = Object.keys(questions).length; window.number_of_questions = Object.keys(window.questions).length;
window.review = false; window.review = false;
console.log(window.question_order); console.log(window.question_order);
// Horrible way to get type of questions // Horrible way to get type of questions
// We assume they are all of the same type.... // We assume they are all of the same type....
if (window.question_type == null) { if (window.question_type == null) {
window.question_type = questions[Object.keys(questions)[0]].type; window.question_type = window.questions[Object.keys(window.questions)[0]].type;
} }
if (window.exam_mode) { if (window.exam_mode) {
@@ -183,7 +178,6 @@ function setUpPacket(data) {
setUpQuestions(); setUpQuestions();
} }
/** /**
* Loads a specific question * Loads a specific question
* @param {number} n - Question number to load * @param {number} n - Question number to load
@@ -197,7 +191,7 @@ function loadQuestion(n, section = 1, force_reload = false) {
const qid = window.question_order[n]; const qid = window.question_order[n];
console.log("qid", qid); console.log("qid", qid);
const current_question = questions[qid]; const current_question = window.questions[qid];
console.log("N=", n, section, current_question); console.log("N=", n, section, current_question);
@@ -236,13 +230,13 @@ function loadQuestion(n, section = 1, force_reload = false) {
if (current_question.title) { if (current_question.title) {
$(".question .title").get(0).innerHTML = $(".question .title").get(0).innerHTML =
"<span style=\"font-weight:700;\">" + '<span style="font-weight:700;">' +
display_n + display_n +
"</span> " + "</span> " +
current_question.title; current_question.title;
} else { } else {
$(".question .title").get(0).innerHTML = $(".question .title").get(0).innerHTML =
"<span style=\"font-weight:700;\">" + display_n + "</span>"; '<span style="font-weight:700;">' + display_n + "</span>";
} }
// Close any open figures // Close any open figures
@@ -267,9 +261,9 @@ function loadQuestion(n, section = 1, force_reload = false) {
} }
thumbnails.append( thumbnails.append(
"<div class=\"figure\" id=\"figure-" + '<div class="figure" id="figure-' +
id + id +
"\"><div class=\"figcaption\">...</div></div>", '"><div class="figcaption">...</div></div>'
); );
// const thumbnail = $(".figure .thumbnail").get(id); // const thumbnail = $(".figure .thumbnail").get(id);
@@ -294,11 +288,11 @@ function loadQuestion(n, section = 1, force_reload = false) {
} else { } else {
// convert the data url to a file // convert the data url to a file
urltoFile(based_img, "dicom", "application/dicom").then(function ( urltoFile(based_img, "dicom", "application/dicom").then(function (
dfile, dfile
) { ) {
// load the file using cornerstoneWADO file loader // load the file using cornerstoneWADO file loader
const imageId = cornerstoneWADOImageLoader.wadouri.fileManager.add( const imageId = cornerstoneWADOImageLoader.wadouri.fileManager.add(
dfile, dfile
); );
cornerstone.loadAndCacheImage(imageId).then(function (image) { cornerstone.loadAndCacheImage(imageId).then(function (image) {
const img = $("<div></div>").get(0); const img = $("<div></div>").get(0);
@@ -350,16 +344,14 @@ function loadQuestion(n, section = 1, force_reload = false) {
} }
} }
$(".figure-open") $(".figure-open").removeClass("figure-open").addClass("figure");
.removeClass("figure-open")
.addClass("figure");
source.className = "figure-open"; source.className = "figure-open";
$(".question").append( $(".question").append(
"<div class= \"canvas-panel\"><div id=\"dicom-image\" data-figure=\"" + '<div class= "canvas-panel"><div id="dicom-image" data-figure="' +
figure_to_load + figure_to_load +
"\"></div></div>", '"></div></div>'
); );
let images = current_question.images[figure_to_load.split("-")[1]]; let images = current_question.images[figure_to_load.split("-")[1]];
@@ -391,7 +383,7 @@ function loadQuestion(n, section = 1, force_reload = false) {
dfile = await urltoFile(data_url, "dicom", "application/dicom"); dfile = await urltoFile(data_url, "dicom", "application/dicom");
const imageId = cornerstoneWADOImageLoader.wadouri.fileManager.add( const imageId = cornerstoneWADOImageLoader.wadouri.fileManager.add(
dfile, dfile
); );
imageIds.push(imageId); imageIds.push(imageId);
// cornerstone.loadImage(imageId).then(function(image) { // cornerstone.loadImage(imageId).then(function(image) {
@@ -403,7 +395,6 @@ function loadQuestion(n, section = 1, force_reload = false) {
currentImageIdIndex: 0, currentImageIdIndex: 0,
imageIds, imageIds,
}; };
// cornerstone.loadAndCacheImage(imageIds[0]).then(function(image) {
cornerstone.loadAndCacheImage(imageIds[0]).then(function (image) { cornerstone.loadAndCacheImage(imageIds[0]).then(function (image) {
loadMainImage(image, stack); loadMainImage(image, stack);
}); });
@@ -418,18 +409,18 @@ function loadQuestion(n, section = 1, force_reload = false) {
switch (current_question.type) { switch (current_question.type) {
case "rapid": { case "rapid": {
ap.append( ap.append(
"<div class=\"answer-item\"><div class=\"answer-label-outer\"><p class=\"answer-label-inner\"><span class=\"answer-label-number\">" + '<div class="answer-item"><div class="answer-label-outer"><p class="answer-label-inner"><span class="answer-label-number">' +
display_n + display_n +
".1</span><span style=\"flex:1\">Case normal/abnormal</span><button class=\"flag\" data-qid=\"" + '.1</span><span style="flex:1">Case normal/abnormal</span><button class="flag" data-qid="' +
n + n +
"\" data-qidn=1 style=\"margin-right:0\">⚐</button></p></div><select class=\"rapid-option-answer\" id=\"rapid-option\" data-answer-section-qidn=1><option selected=\"selected\" disabled=\"disabled\" id=\"rapid-option-not-answered\">--- Not Answered ---</option><option>Abnormal</option><option>Normal</option></select></div>", '" data-qidn=1 style="margin-right:0">⚐</button></p></div><select class="rapid-option-answer" id="rapid-option" data-answer-section-qidn=1><option selected="selected" disabled="disabled" id="rapid-option-not-answered">--- Not Answered ---</option><option>Abnormal</option><option>Normal</option></select></div>'
); );
ap.append( ap.append(
"<div class=\"answer-item\" id=\"rapid-text\" style=\"display: none;\"><div class=\"answer-label-outer\"><p class=\"answer-label-inner\"><span class=\"answer-label-number\">" + '<div class="answer-item" id="rapid-text" style="display: none;"><div class="answer-label-outer"><p class="answer-label-inner"><span class="answer-label-number">' +
display_n + display_n +
".2</span><span style=\"flex:1\">Reason</span><button class=\"flag\" data-qid=\"" + '.2</span><span style="flex:1">Reason</span><button class="flag" data-qid="' +
n + n +
"\" data-qidn=2 style=\"margin-right:0\">⚐</button></p></div><textarea class=\"long-answer\" name=\"Reason\" data-answer-section-qidn=2 style=\"overflow: hidden scroll; overflow-wrap: break-word;\"></textarea></div>", '" data-qidn=2 style="margin-right:0">⚐</button></p></div><textarea class="long-answer" name="Reason" data-answer-section-qidn=2 style="overflow: hidden scroll; overflow-wrap: break-word;"></textarea></div>'
); );
// Handle changing display of optional answer fields and saving of data // Handle changing display of optional answer fields and saving of data
$("#rapid-option").change(function (evt) { $("#rapid-option").change(function (evt) {
@@ -454,7 +445,7 @@ function loadQuestion(n, section = 1, force_reload = false) {
if (evt.target.value.length < 1) { if (evt.target.value.length < 1) {
db.answers.delete([cid, eid, qid, "2"]); db.answers.delete([cid, eid, qid, "2"]);
$( $(
"#question-list-item-" + window.question_order.indexOf(qid) + "-2", "#question-list-item-" + window.question_order.indexOf(qid) + "-2"
).removeClass("question-saved-localdb"); ).removeClass("question-saved-localdb");
return; return;
} }
@@ -467,9 +458,9 @@ function loadQuestion(n, section = 1, force_reload = false) {
ans: evt.target.value, ans: evt.target.value,
}); });
$("#question-list-item-" + window.question_order.indexOf(qid) + "-2").addClass( $(
"question-saved-localdb", "#question-list-item-" + window.question_order.indexOf(qid) + "-2"
); ).addClass("question-saved-localdb");
updateQuestionListPanel(); updateQuestionListPanel();
}); });
@@ -477,13 +468,14 @@ function loadQuestion(n, section = 1, force_reload = false) {
// We chain our db requests as we can only check answers once // We chain our db requests as we can only check answers once
// they have been loaded (should probably use then or after) // they have been loaded (should probably use then or after)
db.answers db.answers
.get({ cid: cid, eid: eid, qid: qid, qidn: "1" }) .get({ cid: cid, eid: eid, qid: qid, qidn: "1" })
.then(function (answer) { .then(function (answer) {
if (answer != undefined) { if (answer != undefined) {
$("#rapid-option option:contains(" + answer.ans + ")").prop( $("#rapid-option option:contains(" + answer.ans + ")").prop(
"selected", "selected",
true, true
); );
// For some reason a change event is not fired... // For some reason a change event is not fired...
if (answer.ans == "Abnormal") { if (answer.ans == "Abnormal") {
@@ -493,6 +485,7 @@ function loadQuestion(n, section = 1, force_reload = false) {
} }
}) })
.catch(function (error) { .catch(function (error) {
console.log("DB", cid, eid, qid);
console.log("error-", error); console.log("error-", error);
}) })
.then( .then(
@@ -507,7 +500,7 @@ function loadQuestion(n, section = 1, force_reload = false) {
}) })
.catch(function (error) { .catch(function (error) {
console.log("error-", error); console.log("error-", error);
}), })
); );
addFlagEvents(); addFlagEvents();
@@ -518,13 +511,13 @@ function loadQuestion(n, section = 1, force_reload = false) {
} }
case "anatomy": { case "anatomy": {
ap.append( ap.append(
"<div class=\"answer-item\" id=\"anatomy-text\"><div class=\"answer-label-outer\"><p class=\"answer-label-inner\"><span class=\"answer-label-number\">" + '<div class="answer-item" id="anatomy-text"><div class="answer-label-outer"><p class="answer-label-inner"><span class="answer-label-number">' +
display_n + display_n +
".1</span><span style=\"flex:1\">" + '.1</span><span style="flex:1">' +
current_question.question + current_question.question +
"</span><button class=\"flag\" data-qid=\"" + '</span><button class="flag" data-qid="' +
n + n +
"\" data-qidn=1 style=\"margin-right:0\">⚐</button></p></div><textarea class=\"long-answer\" name=\"Reason\" data-answer-section-qidn=1 style=\"overflow: hidden scroll; overflow-wrap: break-word;\"></textarea></div>", '" data-qidn=1 style="margin-right:0">⚐</button></p></div><textarea class="long-answer" name="Reason" data-answer-section-qidn=1 style="overflow: hidden scroll; overflow-wrap: break-word;"></textarea></div>'
); );
$(".long-answer").change(function (evt) { $(".long-answer").change(function (evt) {
@@ -532,7 +525,7 @@ function loadQuestion(n, section = 1, force_reload = false) {
if (evt.target.value.length < 1) { if (evt.target.value.length < 1) {
db.answers.delete([cid, eid, qid, "1"]); db.answers.delete([cid, eid, qid, "1"]);
$( $(
"#question-list-item-" + window.question_order.indexOf(qid) + "-1", "#question-list-item-" + window.question_order.indexOf(qid) + "-1"
).removeClass("question-saved-localdb"); ).removeClass("question-saved-localdb");
return; return;
} }
@@ -545,9 +538,9 @@ function loadQuestion(n, section = 1, force_reload = false) {
ans: evt.target.value, ans: evt.target.value,
}); });
$("#question-list-item-" + window.question_order.indexOf(qid) + "-1").addClass( $(
"question-saved-localdb", "#question-list-item-" + window.question_order.indexOf(qid) + "-1"
); ).addClass("question-saved-localdb");
updateQuestionListPanel(); updateQuestionListPanel();
}); });
@@ -571,39 +564,39 @@ function loadQuestion(n, section = 1, force_reload = false) {
case "long": { case "long": {
ap.append( ap.append(
"<div class=\"answer-item\"><div class=\"answer-label-outer\"><p class=\"answer-label-inner\"><span class=\"answer-label-number\">" + '<div class="answer-item"><div class="answer-label-outer"><p class="answer-label-inner"><span class="answer-label-number">' +
display_n + display_n +
".1</span><span style=\"flex:1\">Observations</span><button class=\"flag\" data-qid=\"" + '.1</span><span style="flex:1">Observations</span><button class="flag" data-qid="' +
n + n +
"\" data-qidn=1 style=\"margin-right:0\">⚐</button></p></div><textarea class=\"long-answer\" data-qidn=1 name=\"Observations\" style=\"overflow-x: hidden; overflow-wrap: break-word; height: 80px;\"></textarea></div>", '" data-qidn=1 style="margin-right:0">⚐</button></p></div><textarea class="long-answer" data-qidn=1 name="Observations" style="overflow-x: hidden; overflow-wrap: break-word; height: 80px;"></textarea></div>'
); );
ap.append( ap.append(
"<div class=\"answer-item\"><div class=\"answer-label-outer\"><p class=\"answer-label-inner\"><span class=\"answer-label-number\">" + '<div class="answer-item"><div class="answer-label-outer"><p class="answer-label-inner"><span class="answer-label-number">' +
display_n + display_n +
".2</span><span style=\"flex:1\">Interpretation</span><button class=\"flag\" data-qid=\"" + '.2</span><span style="flex:1">Interpretation</span><button class="flag" data-qid="' +
n + n +
"\" data-qidn=2 style=\"margin-right:0\">⚐</button></p></div><textarea class=\"long-answer\" data-qidn=2 name=\"Interpretation\" style=\"overflow-x: hidden; overflow-wrap: break-word; , trueheight: 80px;\"></textarea></div>", '" data-qidn=2 style="margin-right:0">⚐</button></p></div><textarea class="long-answer" data-qidn=2 name="Interpretation" style="overflow-x: hidden; overflow-wrap: break-word; , trueheight: 80px;"></textarea></div>'
); );
ap.append( ap.append(
"<div class=\"answer-item\"><div class=\"answer-label-outer\"><p class=\"answer-label-inner\"><span class=\"answer-label-number\">" + '<div class="answer-item"><div class="answer-label-outer"><p class="answer-label-inner"><span class="answer-label-number">' +
display_n + display_n +
".3</span><span style=\"flex:1\">Principle Diagnosis</span><button class=\"flag\" data-qid=\"" + '.3</span><span style="flex:1">Principle Diagnosis</span><button class="flag" data-qid="' +
n + n +
"\" data-qidn=3 style=\"margin-right:0\">⚐</button></p></div><textarea class=\"long-answer\" data-qidn=3 name=\"Principle Diagnosis\" style=\"overflow-x: hidden; overflow-wrap: break-word; height: 80px;\"></textarea></div>", '" data-qidn=3 style="margin-right:0">⚐</button></p></div><textarea class="long-answer" data-qidn=3 name="Principle Diagnosis" style="overflow-x: hidden; overflow-wrap: break-word; height: 80px;"></textarea></div>'
); );
ap.append( ap.append(
"<div class=\"answer-item\"><div class=\"answer-label-outer\"><p class=\"answer-label-inner\"><span class=\"answer-label-number\">" + '<div class="answer-item"><div class="answer-label-outer"><p class="answer-label-inner"><span class="answer-label-number">' +
display_n + display_n +
".4</span><span style=\"flex:1\">Differential Diagnosis</span><button class=\"flag\" data-qid=\"" + '.4</span><span style="flex:1">Differential Diagnosis</span><button class="flag" data-qid="' +
n + n +
"\" data-qidn=4 style=\"margin-right:0\">⚐</button></p></div><textarea class=\"long-answer\" data-qidn=4 name=\"Differential Diagnosis\" style=\"overflow-x: hidden; overflow-wrap: break-word; height: 80px;\"></textarea></div>", '" data-qidn=4 style="margin-right:0">⚐</button></p></div><textarea class="long-answer" data-qidn=4 name="Differential Diagnosis" style="overflow-x: hidden; overflow-wrap: break-word; height: 80px;"></textarea></div>'
); );
ap.append( ap.append(
"<div class=\"answer-item\"><div class=\"answer-label-outer\"><p class=\"answer-label-inner\"><span class=\"answer-label-number\">" + '<div class="answer-item"><div class="answer-label-outer"><p class="answer-label-inner"><span class="answer-label-number">' +
display_n + display_n +
".5</span><span style=\"flex:1\">Management (if appropriate)</span><button class=\"flag\" data-qid=\"" + '.5</span><span style="flex:1">Management (if appropriate)</span><button class="flag" data-qid="' +
n + n +
"\" data-qidn=5 style=\"margin-right:0\">⚐</button></p></div><textarea class=\"long-answer\" data-qidn=5 name=\"Management (if appropriate)\" style=\"overflow-x: hidden; overflow-wrap: break-word; height: 80px;\"></textarea></div>", '" data-qidn=5 style="margin-right:0">⚐</button></p></div><textarea class="long-answer" data-qidn=5 name="Management (if appropriate)" style="overflow-x: hidden; overflow-wrap: break-word; height: 80px;"></textarea></div>'
); );
// Save long answers on textchange // Save long answers on textchange
@@ -614,7 +607,10 @@ function loadQuestion(n, section = 1, force_reload = false) {
if (evt.target.value.length < 1) { if (evt.target.value.length < 1) {
db.answers.delete([cid, eid, qid, qidn]); db.answers.delete([cid, eid, qid, qidn]);
$( $(
"#question-list-item-" + window.question_order.indexOf(qid) + "-" + qidn, "#question-list-item-" +
window.question_order.indexOf(qid) +
"-" +
qidn
).removeClass("question-saved-localdb"); ).removeClass("question-saved-localdb");
return; return;
} }
@@ -629,7 +625,10 @@ function loadQuestion(n, section = 1, force_reload = false) {
console.log("SAVE", qid, qidn, evt.target.value); console.log("SAVE", qid, qidn, evt.target.value);
$( $(
"#question-list-item-" + window.question_order.indexOf(qid) + "-" + qidn, "#question-list-item-" +
window.question_order.indexOf(qid) +
"-" +
qidn
).addClass("question-saved-localdb"); ).addClass("question-saved-localdb");
updateQuestionListPanel(); updateQuestionListPanel();
@@ -702,17 +701,21 @@ function updateQuestionListPanel() {
"#question-list-item-" + "#question-list-item-" +
window.question_order.indexOf(answer.qid) + window.question_order.indexOf(answer.qid) +
"-" + "-" +
answer.qidn, answer.qidn
).addClass("question-saved-localdb"); ).addClass("question-saved-localdb");
if (window.question_type == "rapid" && answer.qidn == "1") { if (window.question_type == "rapid" && answer.qidn == "1") {
if (answer.ans == "Abnormal") { if (answer.ans == "Abnormal") {
$( $(
"#question-list-item-" + window.question_order.indexOf(answer.qid) + "-2", "#question-list-item-" +
window.question_order.indexOf(answer.qid) +
"-2"
).css("display", "block"); ).css("display", "block");
} else { } else {
$( $(
"#question-list-item-" + window.question_order.indexOf(answer.qid) + "-2", "#question-list-item-" +
window.question_order.indexOf(answer.qid) +
"-2"
).css("display", "none"); ).css("display", "none");
} }
} }
@@ -733,7 +736,7 @@ function updateQuestionListPanel() {
window.question_order.indexOf(answer.qid) + window.question_order.indexOf(answer.qid) +
"-" + "-" +
answer.qidn + answer.qidn +
" span", " span"
).css("visibility", "visible"); ).css("visibility", "visible");
}); });
// $(".long-answer").text(answer.ans); // $(".long-answer").text(answer.ans);
@@ -749,7 +752,7 @@ function updateQuestionListPanel() {
function createQuestionListPanel() { function createQuestionListPanel() {
$(".question-list-panel").empty(); $(".question-list-panel").empty();
$(".question-list-panel").append( $(".question-list-panel").append(
"<div class=\"review-heading\">Questions</div>", '<div class="review-heading">Questions</div>'
); );
/** /**
@@ -761,19 +764,19 @@ function createQuestionListPanel() {
function appendReviewItem(n, qidn) { function appendReviewItem(n, qidn) {
const qn = n - 1; const qn = n - 1;
const el = $( const el = $(
"<div id=\"question-list-item-" + '<div id="question-list-item-' +
qn + qn +
"-" + "-" +
qidn + qidn +
"\" data-qid=" + '" data-qid=' +
qn + qn +
" data-qidn=\"" + ' data-qidn="' +
qidn + qidn +
"\" class=\"question-list-item\">" + '" class="question-list-item">' +
n + n +
"." + "." +
qidn + qidn +
"<span class=\"question-list-flag\">⚑</span></div>", '<span class="question-list-flag">⚑</span></div>'
); );
$(".question-list-panel").append(el); $(".question-list-panel").append(el);
// return the new element so it can be hidden if necessary // return the new element so it can be hidden if necessary
@@ -1059,9 +1062,7 @@ function changeControlSelection() {
cornerstone.removeElementData(dicom_element); cornerstone.removeElementData(dicom_element);
cornerstone.disable(dicom_element); cornerstone.disable(dicom_element);
$(".canvas-panel").remove(); $(".canvas-panel").remove();
$(".figure-open") $(".figure-open").removeClass("figure-open").addClass("figure");
.removeClass("figure-open")
.addClass("figure");
$(dicom_element).remove(); $(dicom_element).remove();
} }
break; break;
@@ -1090,7 +1091,8 @@ function onImageRendered(e) {
")"; ")";
// update stack data // update stack data
const stack = eventData.enabledElement.toolStateManager.toolState.stack.data[0]; const stack =
eventData.enabledElement.toolStateManager.toolState.stack.data[0];
if (stack.imageIds.length > 1) { if (stack.imageIds.length > 1) {
$("option[value=scroll").prop("disabled", false); $("option[value=scroll").prop("disabled", false);
$("option[value=scroll").prop("hidden", false); $("option[value=scroll").prop("hidden", false);
@@ -1099,7 +1101,7 @@ function onImageRendered(e) {
(stack.currentImageIdIndex + 1) + (stack.currentImageIdIndex + 1) +
"/" + "/" +
stack.imageIds.length + stack.imageIds.length +
")", ")"
); );
// Temp way to enable CT window presets // Temp way to enable CT window presets
@@ -1122,12 +1124,10 @@ function onImageRendered(e) {
function disableFullscreen(dicom_element) { function disableFullscreen(dicom_element) {
// TODO: rescale the image to stop it getting zoomed in // TODO: rescale the image to stop it getting zoomed in
$(".canvas-panel-fullscreen").toggleClass( $(".canvas-panel-fullscreen").toggleClass(
"canvas-panel canvas-panel-fullscreen", "canvas-panel canvas-panel-fullscreen"
); );
$(".question").append($(".canvas-panel")); $(".question").append($(".canvas-panel"));
$(".canvas-panel") $(".canvas-panel").get(0).scrollIntoView();
.get(0)
.scrollIntoView();
setDicomCanvasNonFullscreen(dicom_element); setDicomCanvasNonFullscreen(dicom_element);
} }
@@ -1195,7 +1195,7 @@ function postAnswers(ans) {
$.post("http://localhost:8000/submit_answers", JSON.stringify(ans)).done( $.post("http://localhost:8000/submit_answers", JSON.stringify(ans)).done(
(data) => { (data) => {
console.log(data); console.log(data);
}, }
); );
// $.post( "http://localhost:8000/submit_answers", JSON.stringify(ans)); // $.post( "http://localhost:8000/submit_answers", JSON.stringify(ans));
} }
@@ -1205,7 +1205,9 @@ function postAnswers(ans) {
* This is defined in index.html * This is defined in index.html
*/ */
function loadLocalQuestionSet() { function loadLocalQuestionSet() {
let input; let file; let fr; let input;
let file;
let fr;
if (typeof window.FileReader !== "function") { if (typeof window.FileReader !== "function") {
alert("The file API isn't supported on this browser yet."); alert("The file API isn't supported on this browser yet.");
@@ -1217,7 +1219,7 @@ function loadLocalQuestionSet() {
alert("No fileinput element."); alert("No fileinput element.");
} else if (!input.files) { } else if (!input.files) {
alert( alert(
"This browser doesn't seem to support the `files` property of file inputs.", "This browser doesn't seem to support the `files` property of file inputs."
); );
} else if (!input.files[0]) { } else if (!input.files[0]) {
alert("Please select a file before clicking 'Load'"); alert("Please select a file before clicking 'Load'");
@@ -1246,7 +1248,7 @@ function submitAnswers() {
console.log( console.log(
getJsonAnswers().then((a) => { getJsonAnswers().then((a) => {
postAnswers(a); postAnswers(a);
}), })
); );
} }
@@ -1263,7 +1265,7 @@ function reviewQuestions() {
.where({ cid: cid, eid: eid }) .where({ cid: cid, eid: eid })
.toArray() .toArray()
.then(function (answers) { .then(function (answers) {
current_answers = {}; let current_answers = {};
answers.forEach(function (arr, n) { answers.forEach(function (arr, n) {
answer = arr["ans"]; answer = arr["ans"];
if (answer == undefined) { if (answer == undefined) {
@@ -1282,7 +1284,7 @@ function reviewQuestions() {
n + n +
">Question " + ">Question " +
(n + 1) + (n + 1) +
":</a> <span>Not answered</span></li>", ":</a> <span>Not answered</span></li>"
); );
$("#review-answer-list a").click(function (evt) { $("#review-answer-list a").click(function (evt) {
loadQuestion(this.dataset.qid); loadQuestion(this.dataset.qid);
@@ -1291,14 +1293,13 @@ function reviewQuestions() {
db.user_answers db.user_answers
.get({ qid: qid }) .get({ qid: qid })
.then(function (answers) { .then(function (answers) {
question_answers = questions[qid]["answers"]; let question_answers = window.questions[qid]["answers"];
if (answers == undefined) { if (answers != undefined) {
} else {
question_answers = question_answers.concat(answers.ans); question_answers = question_answers.concat(answers.ans);
} }
section_1_answer = current_answers[[qid, "1"]]; let section_1_answer = current_answers[[qid, "1"]];
section_2_answer = current_answers[[qid, "2"]]; let section_2_answer = current_answers[[qid, "2"]];
if (section_1_answer == undefined) { if (section_1_answer == undefined) {
section_1_answer = "Not Answered"; section_1_answer = "Not Answered";
@@ -1327,7 +1328,7 @@ function reviewQuestions() {
c, c,
user_answer, user_answer,
normal, normal,
question_answers, question_answers
) { ) {
if (normal) { if (normal) {
el.html( el.html(
@@ -1335,7 +1336,7 @@ function reviewQuestions() {
c + c +
"'>Answer: " + "'>Answer: " +
user_answer + user_answer +
" (Normal)</span>", " (Normal)</span>"
); );
} else { } else {
el.html( el.html(
@@ -1345,21 +1346,21 @@ function reviewQuestions() {
user_answer + user_answer +
" (Abnormal: " + " (Abnormal: " +
question_answers.join(", ") + question_answers.join(", ") +
")</span>", ")</span>"
); );
} }
} }
if (window.question_type == "rapid") { if (window.question_type == "rapid") {
// First check normal vs abnormal // First check normal vs abnormal
if (questions[qid]["normal"] == true) { if (window.questions[qid]["normal"] == true) {
if (section_1_answer == "Normal") { if (section_1_answer == "Normal") {
setReviewAnswer( setReviewAnswer(
el, el,
"correct", "correct",
section_1_answer, section_1_answer,
true, true,
question_answers, question_answers
); );
correct_count++; correct_count++;
} else { } else {
@@ -1368,7 +1369,7 @@ function reviewQuestions() {
"incorrect", "incorrect",
section_1_answer, section_1_answer,
true, true,
question_answers, question_answers
); );
} }
} else { } else {
@@ -1379,7 +1380,7 @@ function reviewQuestions() {
"correct", "correct",
section_2_answer, section_2_answer,
false, false,
question_answers, question_answers
); );
} else { } else {
setReviewAnswer( setReviewAnswer(
@@ -1387,7 +1388,7 @@ function reviewQuestions() {
"incorrect", "incorrect",
section_2_answer, section_2_answer,
false, false,
question_answers, question_answers
); );
} }
} }
@@ -1400,7 +1401,7 @@ function reviewQuestions() {
"correct", "correct",
section_1_answer, section_1_answer,
false, false,
question_answers, question_answers
); );
} else { } else {
setReviewAnswer( setReviewAnswer(
@@ -1408,13 +1409,16 @@ function reviewQuestions() {
"incorrect", "incorrect",
section_1_answer, section_1_answer,
false, false,
question_answers, question_answers
); );
} }
} }
$("#review-score").text( $("#review-score").text(
"Score: " + correct_count + " out of " + window.question_order.length, "Score: " +
correct_count +
" out of " +
window.question_order.length
); );
}) })
.catch(function (error) { .catch(function (error) {
@@ -1443,7 +1447,7 @@ function markAnswer(qid, type) {
option = document.getElementById("rapid-option"); option = document.getElementById("rapid-option");
if (current_question.normal == true) { if (current_question.normal == true) {
$(".answer-panel").append( $(".answer-panel").append(
"<div id='correct-answer-block'>This is normal</div>", "<div id='correct-answer-block'>This is normal</div>"
); );
if (option.value == "Normal") { if (option.value == "Normal") {
option.classList.add("correct"); option.classList.add("correct");
@@ -1456,7 +1460,7 @@ function markAnswer(qid, type) {
} }
$(".answer-panel").append( $(".answer-panel").append(
"<div id='correct-answer-block'>Correct answer(s):<ul id='answer-list'></ul></div>", "<div id='correct-answer-block'>Correct answer(s):<ul id='answer-list'></ul></div>"
); );
ul = $("#answer-list"); ul = $("#answer-list");
@@ -1496,8 +1500,8 @@ function markAnswer(qid, type) {
$("<button id='mark-correct'>Mark Correct</button>").click( $("<button id='mark-correct'>Mark Correct</button>").click(
function () { function () {
markCorrect(qid, user_answer); markCorrect(qid, user_answer);
}, }
), )
); );
} }
} }
@@ -1519,8 +1523,8 @@ function addFeedback() {
$( $(
"<div class='feedback'><h4>Feedback</h4>" + "<div class='feedback'><h4>Feedback</h4>" +
current_question.feedback + current_question.feedback +
"</div>", "</div>"
), )
); );
} }
} }
@@ -1533,9 +1537,8 @@ function markCorrect(qid, user_answer) {
db.user_answers db.user_answers
.get({ qid: qid }) .get({ qid: qid })
.then(function (answers) { .then(function (answers) {
if (answers == undefined) { let new_answers = [];
new_answers = []; if (answers != undefined) {
} else {
new_answers = answers.ans; new_answers = answers.ans;
} }
@@ -1550,7 +1553,7 @@ function markCorrect(qid, user_answer) {
$("#mark-correct").remove(); $("#mark-correct").remove();
} }
textarea = $(".long-answer").attr("class", "correct"); let textarea = $(".long-answer").attr("class", "correct");
} }
function compareString(a, b) { function compareString(a, b) {
@@ -1570,23 +1573,23 @@ function answerInArray(arr, ans) {
function addFlagEvents() { function addFlagEvents() {
// Bind flag change events // Bind flag change events
$("button.flag").click(function (event) { $("button.flag").click(function (event) {
el = $(this); const el = $(this);
nqid = el.attr("data-qid"); const nqid = el.attr("data-qid");
qid = window.question_order[nqid]; const qid = window.question_order[nqid];
qidn = el.attr("data-qidn"); const qidn = el.attr("data-qidn");
el.toggleClass("flag flag-selected"); el.toggleClass("flag flag-selected");
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"
); );
db.flags.delete([cid, eid, qid, qidn]); db.flags.delete([cid, eid, qid, qidn]);
} else { } else {
$("#question-list-item-" + nqid + "-" + qidn + " span").css( $("#question-list-item-" + nqid + "-" + qidn + " span").css(
"visibility", "visibility",
"visible", "visible"
); );
db.flags.put({ cid: cid, eid: eid, qid: qid, qidn: qidn }); db.flags.put({ cid: cid, eid: eid, qid: qid, qidn: qidn });
} }
@@ -1669,12 +1672,14 @@ function loadMainImage(image, stack) {
// Add tool selector // Add tool selector
$(".canvas-panel").append( $(".canvas-panel").append(
"<select class=\"control-overlay\"><option value=\"pan\">pan [p]</option><option value=\"zoom\">zoom [z]</option><option value=\"rotate\">rotate [r]</option><option value=\"scroll\" hidden=\"\" disabled=\"\">scroll (1/1)</option><option value=\"window\">window ()</option><option value=\"abdomen\" hidden=\"\" disabled=\"\">window = abdomen [a]</option><option value=\"pulmonary\" hidden=\"\" disabled=\"\">window = pulmonary [u]</option><option value=\"brain\" hidden=\"\" disabled=\"\">window = brain [b]</option><option value=\"bone\" hidden=\"\" disabled=\"\">window = bone [o]</option><option value=\"reset\">reset [e]</option><option value=\"close\">close [c]</option><option disabled=\"true\" value=\"notes\">[modality = CR][size = 9.8]</option></select>", '<select class="control-overlay"><option value="pan">pan [p]</option><option value="zoom">zoom [z]</option><option value="rotate">rotate [r]</option><option value="scroll" hidden="" disabled="">scroll (1/1)</option><option value="window">window ()</option><option value="abdomen" hidden="" disabled="">window = abdomen [a]</option><option value="pulmonary" hidden="" disabled="">window = pulmonary [u]</option><option value="brain" hidden="" disabled="">window = brain [b]</option><option value="bone" hidden="" disabled="">window = bone [o]</option><option value="reset">reset [e]</option><option value="close">close [c]</option><option disabled="true" value="notes">[modality = CR][size = 9.8]</option></select>'
); );
$(".control-overlay") $(".control-overlay")
.get(0) .get(0)
.addEventListener("change", function() {changeControlSelection();}); .addEventListener("change", function () {
changeControlSelection();
});
} }
function setDicomCanvasNonFullscreen(element) { function setDicomCanvasNonFullscreen(element) {
@@ -1698,7 +1703,6 @@ $("#start-exam-button").click(function(evt) {
$.modal.close(); $.modal.close();
}); });
function manualPanDicom(x, y) { function manualPanDicom(x, y) {
dicom_element = document.getElementById("dicom-image"); dicom_element = document.getElementById("dicom-image");
const viewport = cornerstone.getViewport(dicom_element); const viewport = cornerstone.getViewport(dicom_element);