diff --git a/docs/BatchCodeTableInitializer.js b/docs/BatchCodeTableInitializer.js index 2a3bdcba7ca..b2990c836e1 100644 --- a/docs/BatchCodeTableInitializer.js +++ b/docs/BatchCodeTableInitializer.js @@ -59,8 +59,7 @@ class BatchCodeTableInitializer { targets: [ this.#getColumnIndex('Batch'), - this.#getColumnIndex('Company'), - this.#getColumnIndex('Countries') + this.#getColumnIndex('Company') ] }, { @@ -75,8 +74,13 @@ class BatchCodeTableInitializer { }, { width: "1000px", - render: function (data, type, row, meta) { - return null; + render: (data, type, row, meta) => { + if (type === 'sort') { + return this.#getJensenShannonDistance( + row[this.#getColumnIndex('Batch')], + barChartDescriptions); + } + return data; }, createdCell: (cell, cellData, row, rowIndex, colIndex) => { if (showCountriesColumn) { @@ -93,7 +97,6 @@ class BatchCodeTableInitializer { }); } - #getColumnIndex(columnName) { switch (columnName) { case 'Batch': @@ -117,14 +120,27 @@ class BatchCodeTableInitializer { } } + #getJensenShannonDistance(batchcode, barChartDescriptions) { + const barChartDescription = this.#getBarChartDescription(barChartDescriptions, batchcode); + const maximally_different = 1; + if (barChartDescription === null) { + return maximally_different; + } + const jensenShannonDistance = barChartDescription['Jensen-Shannon distance']; + return jensenShannonDistance === null ? maximally_different : jensenShannonDistance; + } + #displayBatchcodeByCountryBarChart(batchcode, barChartDescriptions, uiContainer) { - if (batchcode in barChartDescriptions.barChartDescriptions) { - new BatchcodeByCountryBarChartView(uiContainer) - .displayBatchcodeByCountryBarChart(this.#getBarChartDescription(barChartDescriptions, batchcode)); + const barChartDescription = this.#getBarChartDescription(barChartDescriptions, batchcode); + if (barChartDescription !== null) { + new BatchcodeByCountryBarChartView(uiContainer).displayBatchcodeByCountryBarChart(barChartDescription); } } #getBarChartDescription(barChartDescriptions, batchcode) { + if (!(batchcode in barChartDescriptions.barChartDescriptions)) { + return null; + } const barChartDescription = barChartDescriptions.barChartDescriptions[batchcode]; barChartDescription.batchcode = batchcode; barChartDescription['date range guessed'] = barChartDescriptions['date range guessed']; diff --git a/docs/BatchcodeByCountryBarChart.js b/docs/BatchcodeByCountryBarChart.js index 303f3e836f8..f59beddee1d 100644 --- a/docs/BatchcodeByCountryBarChart.js +++ b/docs/BatchcodeByCountryBarChart.js @@ -31,7 +31,8 @@ class BatchcodeByCountryBarChart { labels: barChartDescription.countries, datasets: [ { - label: `Known (${this.#dateRange2str(barChartDescription['date range known'])})`, + // FK-TODO: do not display Jensen-Shannon distance here or do not display at all + label: `Known (${this.#dateRange2str(barChartDescription['date range known'])}) ${barChartDescription['Jensen-Shannon distance']}`, data: barChartDescription["Adverse Reaction Reports known"] }, {