//cid = null; var cid = 1234; var eid = 5678; var exam_mode = false; var packet_list = []; //var questions = null var question_order = []; var number_of_questions = null; var question_type = null; var loaded_question = null; var review = false; var allow_self_marking = true; var dfile = null; var a = null; var b = null; loadPacketList(); function loadPacketList() { var jqxhr = $.getJSON("packets/", function (data) { packet_list = data.packets; packet_list.forEach(function (packet) { $("#packet-list").append($("
").click(function () { loadPacketFromAjax("packets/" + packet); })); }) $("#options-panel").show(); }) .done(function () { }) .fail(function () { console.log("No packet list available"); showLoginDialog(); }) .always(function () { }); //setUpPacket(questions); } function loadPacketFromAjax(path) { console.log("loading packet from " + path) var jqxhr = $.getJSON(path, function (data) { setUpPacket(data); $("#options-panel").hide(); }) .done(function () { }) .fail(function () { console.log("Unable to load packet at: " + path); }) } function setUpQuestions() { if (questions == undefined) { return } // Set an order for the questions question_order = []; Object.keys(questions).forEach(function (e) { question_order.push(e); // Make sure answers are arrays if (!Array.isArray(questions[e]["answers"])) { questions[e]["answers"] = [questions[e]["answers"]]; } }); question_order = shuffleArray(question_order); number_of_questions = Object.keys(questions).length; review = false; console.log(question_order) // Horrible way to get type of questions // We assume they are all of the same type.... if (question_type == null) { question_type = questions[Object.keys(questions)[0]].type; } if (window.exam_mode) { $("#options-button, #review-overlay-button").hide(); } else { $("#submit-button").hide(); } loadQuestion(0, 1, true); createReviewPanel(); } // randomise order function shuffleArray(array) { var currentIndex = array.length, temporaryValue, randomIndex; // While there remain elements to shuffle... while (0 !== currentIndex) { // Pick a remaining element... randomIndex = Math.floor(Math.random() * currentIndex); currentIndex -= 1; // And swap it with the current element. temporaryValue = array[currentIndex]; array[currentIndex] = array[randomIndex]; array[randomIndex] = temporaryValue; } return array; } // Set up cornerstone (the dicom viewer) cornerstoneBase64ImageLoader.external.cornerstone = cornerstone; cornerstoneWebImageLoader.external.cornerstone = cornerstone; //cornerstoneWebImageLoader.configure({ // beforeSend: function(xhr) { // // Add custom headers here (e.g. auth tokens) // //xhr.setRequestHeader('x-auth-token', 'my auth token'); // } //}); cornerstoneWADOImageLoader.external.cornerstone = cornerstone; //cornerstoneWADOImageLoader.configure({ // beforeSend: function(xhr) { // // Add custom headers here (e.g. auth tokens) // //xhr.setRequestHeader('APIKEY', 'my auth token'); // } //}); cornerstoneTools.init(); //Set up database var db = new Dexie("answers_database"); db.version(1).stores({ answers: "[cid+eid+qid+qidn], [cid+eid], ans", flags: "[cid+eid+qid+qidn], [cid+eid]", user_answers: "qid, ans" }); function setUpPacket(data) { if (data.hasOwnProperty("exam_name")) { $(".exam-name").text("Exam: " + data.exam_name); } if (data.hasOwnProperty("eid")) { window.eid = data.eid; } if (data.hasOwnProperty("type")) { window.question_type = data.type; } if (data.hasOwnProperty("exam_mode")) { window.exam_mode = data.exam_mode; } if (data.hasOwnProperty("questions")) { window.questions = data.questions; } else { window.questions = data; } setUpQuestions(); } function loadQuestion(n, section = 1, force_reload = false) { // Make sure we have an integer n = parseInt(n); qid = question_order[n]; current_question = questions[qid]; console.log("N=", n, section, current_question); if (n == loaded_question && force_reload == false) { // Question already loaded setFocus(section); return; } loaded_question = n; // Set up question navigation $(".navigation[value='next']").off(); $(".navigation[value='previous']").off(); if (n == 0) { $(".navigation[value='previous']").attr("disabled", "disabled"); } else { $(".navigation[value='previous']") .removeAttr("disabled") .click(function () { loadQuestion(n - 1); }); } if (n == number_of_questions - 1) { $(".navigation[value='next']").attr("disabled", "disabled"); } else { $(".navigation[value='next']") .removeAttr("disabled") .click(function () { loadQuestion(n + 1); }); } display_n = n + 1; if (current_question.title) { $(".question .title").get(0).innerHTML = '' + display_n + " " + current_question.title; } else { $(".question .title").get(0).innerHTML = '' + display_n + ""; } // Close any open figures el = document.getElementById("dicom-image"); if (el != undefined) { cornerstone.disable(el); $(".canvas-panel").remove(); } // Set up thumbnails thumbnails = $(".thumbs"); // Why are we checking this? if (thumbnails) { thumbnails.empty(); // TODO: figure captions (need to extend base json) current_question.images.forEach(function createThumbnail(image, id) { // For thumbnails we only want a single image if (Array.isArray(image)) { image = image[0]; // Do we want the middle image? } thumbnails.append( '' + display_n + '.1Case normal/abnormal
' + display_n + '.1' + current_question.question + '
' + display_n + '.1Observations
' + display_n + '.2Interpretation
' + display_n + '.3Principle Diagnosis
' + display_n + '.4Differential Diagnosis
' + display_n + '.5Management (if appropriate)