diff --git a/docs/batchCodeTable.html b/docs/batchCodeTable.html index 58229e7752c..ca7c22c3127 100644 --- a/docs/batchCodeTable.html +++ b/docs/batchCodeTable.html @@ -11,77 +11,17 @@ + diff --git a/docs/batchCodeTable.js b/docs/batchCodeTable.js new file mode 100644 index 00000000000..edd4c388223 --- /dev/null +++ b/docs/batchCodeTable.js @@ -0,0 +1,80 @@ +class BatchCodeTableInitializer { + + #heading; + #countrySelect; + #batchCodeTableElement; + #batchCodeTable; + + constructor({ heading, countrySelect, batchCodeTableElement }) { + this.#heading = heading; + this.#countrySelect = countrySelect; + this.#batchCodeTableElement = batchCodeTableElement; + } + + initialize() { + this.#batchCodeTable = this.#createEmptyBatchCodeTable(); + this.#countrySelect.addEventListener('change', event => this.#displayCountry(event.target.value)); + this.#displayCountry('Global') + } + + #createEmptyBatchCodeTable() { + const columnIndex = { + 'Batch': 0, + 'Adverse Reaction Reports': 1, + 'Deaths': 2, + 'Disabilities': 3, + 'Life Threatening Illnesses': 4, + 'Company': 5, + 'Severe reports': 6, + 'Lethality': 7 + }; + return this.#batchCodeTableElement.DataTable( + { + language: + { + searchPlaceholder: "Enter Batch Code" + }, + search: + { + return: false + }, + processing: true, + deferRender: true, + order: [[columnIndex['Adverse Reaction Reports'], "desc"]], + columnDefs: + [ + { + searchable: false, + targets: [ + columnIndex['Adverse Reaction Reports'], + columnIndex['Deaths'], + columnIndex['Disabilities'], + columnIndex['Life Threatening Illnesses'], + columnIndex['Company'], + columnIndex['Severe reports'], + columnIndex['Lethality'] + ] + }, + { + render: (data, type, row) => { + const numberInPercent = parseFloat(data); + return !isNaN(numberInPercent) ? numberInPercent.toFixed(2) + " %" : ''; + }, + targets: [columnIndex['Severe reports'], columnIndex['Lethality']] + } + ] + }); + } + + #displayCountry(country) { + this.#heading.textContent = country == 'Global' ? 'Global Batch Codes' : `Batch Codes for ${country}`; + this.#batchCodeTable.ajax.url(`data/${country}.json`).load(); + this.#selectInput(); + } + + #selectInput() { + const input = document.querySelector(".dataTables_filter input"); + input.focus(); + input.select(); + } +}