/* global Dexie, cornerstone, cornerstoneTools, cornerstoneBase64ImageLoader, cornerstoneWebImageLoader, cornerstoneWADOImageLoader */ import * as helper from "./helpers.js"; import * as viewer from "./viewer.js"; import * as config from "./config.js"; // const { v4: uuidv4 } = require('uuid'); // cid = null; window.aid = null; window.cid = 1234; window.eid = 5678; window.exam_mode = false; window.packet_list = []; window.exams = []; window.packet_name = null; window.questions = null; window.question_order = []; window.questions_correct = {}; window.number_of_questions = null; window.question_type = null; window.loaded_question = null; window.review = false; window.exam_time = 60; window.date_started = null; window.score = 0; window.allow_self_marking = true; window.timer = null; //window.dfile = null; window.config = config; retrievePacketList(); /** * Retrieves a list of available packets via JSON ajax requests * Will initially try /packets/ (for example if index.php generates the list) * and then fallback to packets.json */ function retrievePacketList() { let url = "packets/"; console.log(window.config.exam_query_url) if (window.config.exam_query_url != undefined) { url = window.config.exam_query_url; } $.getJSON(url, function (data) { if (data.hasOwnProperty("exams")) { loadExamList(data); } else { loadPacketList(data); } }) .done(function () {}) .fail(function () { $.getJSON("packets/packets.json", function (data) { if (data.hasOwnProperty("exams")) { loadExamList(data); } else { loadPacketList(data); } }).fail(function (jqXHR, textStatus, errorThrown) { console.log(jqXHR); console.log(textStatus); console.log(errorThrown); console.log("No packet list available"); showLoginDialog(); }); }) .always(function () {}); } /** * Generate a list of exams that are available to be loaded * this is based on the subsequant function but gives less options * * @param {JSON} data - json containing available exams */ async function loadExamList(data) { let sessions = await window.db.session.toArray().catch(function (error) { console.log("Error loading session", error); $("#database-error").text( "Error loading the database, schema has probably changed and needs updating. You will probably need to delete the local database." ); let delete_button = $("").click( () => { window.indexedDB.deleteDatabase("answers_database"); location.reload(); } ); $("#database-error").append(delete_button); $("#database-error").show(); }); // db.session // .where("packet") // .equals() let exams_started = []; let exams_completed = []; sessions.forEach((s) => { if (s.status == "active") { exams_started.push(s.packet); } else { exams_completed.push(s.packet); } }); if (data != null) { window.exam_list = data.exams; } $("#packet-list").empty(); window.exam_list.forEach(function (exam) { let name = exam["name"]; let url = exam["url"]; let c = ""; if (exams_started.indexOf(name) > -1) { c = " session-started"; } if (exams_completed.indexOf(name) > -1) { c = " session-completed"; } $("#packet-list").append( $(`
`) .text(name) .click(function () { loadPacketFromAjax(url); }) ); }); $("#options-panel").show(); } /** * Generate a list of the packets that are available to be loaded * * @param {JSON} data - json containing available packets */ async function loadPacketList(data) { let sessions = await window.db.session.toArray().catch(function (error) { console.log("Error loading session", error); $("#database-error").text( "Error loading the database, schema has probably changed and needs updating. You will probably need to delete the local database." ); let delete_button = $("").click( () => { window.indexedDB.deleteDatabase("answers_database"); location.reload(); } ); $("#database-error").append(delete_button); $("#database-error").show(); }); // db.session // .where("packet") // .equals() let packets_started = []; let packets_completed = []; sessions.forEach((s) => { if (s.status == "active") { packets_started.push(s.packet); } else { packets_completed.push(s.packet); } }); if (data != null) { window.packet_list = data.packets; } $("#packet-list").empty(); window.packet_list.forEach(function (packet) { let c = ""; if (packets_started.indexOf(packet) > -1) { c = " session-started"; } if (packets_completed.indexOf(packet) > -1) { c = " session-completed"; } $("#packet-list").append( $(``) .text(packet) .click(function () { loadPacketFromAjax("packets/" + packet); }) .append( $( `` ).click(function () { console.log("packets/" + packet); event.stopPropagation(); }) ) ); }); $("#options-panel").show(); } /** * Loads the requisite packet into the quiz system * @param {string} path - relative path to the packet json file */ function loadPacketFromAjax(path) { console.log("loading packet from " + path); $("#progress").html(`Requesting packet: ${path}`); $.ajax({ dataType: "json", url: path, progress: function (e) { if (e.lengthComputable) { var completedPercentage = Math.round((e.loaded * 100) / e.total); $("#progress").html( `${completedPercentage}%' + display_n + '.1Case normal/abnormal
' + display_n + '.1' + current_question.question + '
' + display_n + '.1Observations
' + display_n + '.2Interpretation
' + display_n + '.3Principal Diagnosis
' + display_n + '.4Differential Diagnosis
' + display_n + '.5Management (if appropriate)