/* global Dexie, cornerstone, cornerstoneTools, cornerstoneBase64ImageLoader, cornerstoneWebImageLoader, cornerstoneWADOImageLoader */ import * as helper from "./helpers.js"; import * as viewer from "./viewer.js"; import * as interact from "./interact.js"; import * as config from "./config.js"; // const { v4: uuidv4 } = require('uuid'); // cid = null; window.aid = null; window.cid = ""; 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 = null; 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 * * if exam_query_url is defined in config.js this will be used in preference */ 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; } $.ajax({dataType: "json", cache: false, url: url, success : 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 subsequent 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"; } let list; if (exam.type != undefined) { if ($(`#packet-list .${exam.type}`).length) { list = $(`#packet-list .${exam.type}`); } else { list = $("#packet-list").append(`
' + 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)