/* global Dexie, cornerstone, cornerstoneTools, cornerstoneBase64ImageLoader, cornerstoneWebImageLoader, cornerstoneWADOImageLoader */ import * as helper from "./helpers.js"; import * as viewer from "./viewer.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.packet_name = null; window.questions = null; window.question_order = []; 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; 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() { $.getJSON("packets/", function (data) { loadPacketList(data); }) .done(function () {}) .fail(function () { $.getJSON("packets/packets.json", function (data) { 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 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); } }); window.packet_list = data.packets; 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)