refactoring
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
<script src="./js/PrrByKey2CsvConverter.js"></script>
|
<script src="./js/PrrByKey2CsvConverter.js"></script>
|
||||||
<script src="./js/PageInitializer.js"></script>
|
<script src="./js/PageInitializer.js"></script>
|
||||||
<script src="./js/PrrByVaccineProvider.js"></script>
|
<script src="./js/PrrByVaccineProvider.js"></script>
|
||||||
|
<script src="./js/PrrByKeyTable.js"></script>
|
||||||
<script src="./js/PrrByVaccineTable.js"></script>
|
<script src="./js/PrrByVaccineTable.js"></script>
|
||||||
<script src="./js/PrrBySymptomTable.js"></script>
|
<script src="./js/PrrBySymptomTable.js"></script>
|
||||||
<script src="./js/PrrByKeyTableView.js"></script>
|
<script src="./js/PrrByKeyTableView.js"></script>
|
||||||
|
|||||||
107
docs/SymptomsCausedByVaccines/js/PrrByKeyTable.js
Normal file
107
docs/SymptomsCausedByVaccines/js/PrrByKeyTable.js
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
class PrrByKeyTable {
|
||||||
|
|
||||||
|
#tableElement;
|
||||||
|
#table;
|
||||||
|
#sumPrrs;
|
||||||
|
#prrByKey;
|
||||||
|
#keyColumnName;
|
||||||
|
#prrColumnName;
|
||||||
|
#shallMarkRowIfPrrTooHigh;
|
||||||
|
|
||||||
|
constructor({ tableElement, keyColumnName, prrColumnName, shallMarkRowIfPrrTooHigh }) {
|
||||||
|
this.#tableElement = tableElement;
|
||||||
|
this.#keyColumnName = keyColumnName;
|
||||||
|
this.#prrColumnName = prrColumnName;
|
||||||
|
this.#shallMarkRowIfPrrTooHigh = shallMarkRowIfPrrTooHigh;
|
||||||
|
}
|
||||||
|
|
||||||
|
initialize() {
|
||||||
|
this.#table = this.#createEmptyTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
display(prrByKey) {
|
||||||
|
this.#prrByKey = prrByKey;
|
||||||
|
const key_prr_pairs = Object.entries(prrByKey);
|
||||||
|
this.#setTableRows(key_prr_pairs);
|
||||||
|
}
|
||||||
|
|
||||||
|
getDisplayedTableAsCsv(heading) {
|
||||||
|
return PrrByKey2CsvConverter.convertPrrByKey2Csv(
|
||||||
|
{
|
||||||
|
heading: heading,
|
||||||
|
columns: {
|
||||||
|
keyColumn: this.#keyColumnName,
|
||||||
|
prrColumn: this.#prrColumnName
|
||||||
|
},
|
||||||
|
prrByKey: this.#prrByKey
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#createEmptyTable() {
|
||||||
|
return this.#tableElement.DataTable(
|
||||||
|
{
|
||||||
|
search:
|
||||||
|
{
|
||||||
|
return: false
|
||||||
|
},
|
||||||
|
processing: true,
|
||||||
|
deferRender: true,
|
||||||
|
order: [[this.#getColumnIndex(this.#prrColumnName), "desc"]],
|
||||||
|
columnDefs:
|
||||||
|
[
|
||||||
|
{
|
||||||
|
searchable: false,
|
||||||
|
targets: [this.#getColumnIndex(this.#prrColumnName)]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
render: prr =>
|
||||||
|
NumberWithBarElementFactory
|
||||||
|
.createNumberWithBarElement(
|
||||||
|
{
|
||||||
|
number: prr,
|
||||||
|
barLenInPercent: prr / this.#sumPrrs * 100
|
||||||
|
})
|
||||||
|
.outerHTML,
|
||||||
|
targets: [this.#getColumnIndex(this.#prrColumnName)]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
createdRow: (row, data) => {
|
||||||
|
if (this.#shallMarkRowIfPrrTooHigh) {
|
||||||
|
this.#markRowIfPrrTooHigh(
|
||||||
|
{
|
||||||
|
prr: data[this.#getColumnIndex(this.#prrColumnName)],
|
||||||
|
row: row
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#markRowIfPrrTooHigh({ prr, row }) {
|
||||||
|
if (prr > 1.0) {
|
||||||
|
$(row).addClass('prrTooHigh');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#getColumnIndex(columnName) {
|
||||||
|
switch (columnName) {
|
||||||
|
case this.#keyColumnName:
|
||||||
|
return 0;
|
||||||
|
case this.#prrColumnName:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#setTableRows(key_prr_pairs) {
|
||||||
|
this.#sumPrrs = this.#getSumPrrs(key_prr_pairs);
|
||||||
|
this.#table
|
||||||
|
.clear()
|
||||||
|
.rows.add(key_prr_pairs)
|
||||||
|
.draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
#getSumPrrs(key_prr_pairs) {
|
||||||
|
const prrs = key_prr_pairs.map(key_prr_pair => key_prr_pair[1])
|
||||||
|
return Utils.sum(prrs);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,86 +1,25 @@
|
|||||||
class PrrBySymptomTable {
|
class PrrBySymptomTable {
|
||||||
|
|
||||||
#tableElement;
|
#delegate;
|
||||||
#table;
|
|
||||||
#sumPrrs;
|
|
||||||
#prrBySymptom;
|
|
||||||
|
|
||||||
constructor(tableElement) {
|
constructor(tableElement) {
|
||||||
this.#tableElement = tableElement;
|
this.#delegate = new PrrByKeyTable({
|
||||||
|
tableElement: tableElement,
|
||||||
|
keyColumnName: 'Symptom',
|
||||||
|
prrColumnName: 'Proportional Reporting Ratio > 1',
|
||||||
|
shallMarkRowIfPrrTooHigh: false
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize() {
|
initialize() {
|
||||||
this.#table = this.#createEmptyTable();
|
this.#delegate.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
display(prrBySymptom) {
|
display(prrBySymptom) {
|
||||||
this.#prrBySymptom = prrBySymptom;
|
this.#delegate.display(prrBySymptom);
|
||||||
const symptom_prr_pairs = Object.entries(prrBySymptom);
|
|
||||||
this.#setTableRows(symptom_prr_pairs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getDisplayedTableAsCsv(heading) {
|
getDisplayedTableAsCsv(heading) {
|
||||||
return PrrByKey2CsvConverter.convertPrrByKey2Csv(
|
return this.#delegate.getDisplayedTableAsCsv(heading);
|
||||||
{
|
|
||||||
heading: heading,
|
|
||||||
columns: {
|
|
||||||
keyColumn: 'Symptom',
|
|
||||||
prrColumn: 'Proportional Reporting Ratio > 1'
|
|
||||||
},
|
|
||||||
prrByKey: this.#prrBySymptom
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#createEmptyTable() {
|
|
||||||
return this.#tableElement.DataTable(
|
|
||||||
{
|
|
||||||
search:
|
|
||||||
{
|
|
||||||
return: false
|
|
||||||
},
|
|
||||||
processing: true,
|
|
||||||
deferRender: true,
|
|
||||||
order: [[this.#getColumnIndex('Proportional Reporting Ratio > 1'), "desc"]],
|
|
||||||
columnDefs:
|
|
||||||
[
|
|
||||||
{
|
|
||||||
searchable: false,
|
|
||||||
targets: [this.#getColumnIndex('Proportional Reporting Ratio > 1')]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
render: prr =>
|
|
||||||
NumberWithBarElementFactory
|
|
||||||
.createNumberWithBarElement(
|
|
||||||
{
|
|
||||||
number: prr,
|
|
||||||
barLenInPercent: prr / this.#sumPrrs * 100
|
|
||||||
})
|
|
||||||
.outerHTML,
|
|
||||||
targets: [this.#getColumnIndex('Proportional Reporting Ratio > 1')]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#getColumnIndex(columnName) {
|
|
||||||
switch (columnName) {
|
|
||||||
case 'Symptom':
|
|
||||||
return 0;
|
|
||||||
case 'Proportional Reporting Ratio > 1':
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#setTableRows(symptom_prr_pairs) {
|
|
||||||
this.#sumPrrs = this.#getSumPrrs(symptom_prr_pairs);
|
|
||||||
this.#table
|
|
||||||
.clear()
|
|
||||||
.rows.add(symptom_prr_pairs)
|
|
||||||
.draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
#getSumPrrs(symptom_prr_pairs) {
|
|
||||||
const prrs = symptom_prr_pairs.map(symptom_prr_pair => symptom_prr_pair[1])
|
|
||||||
return Utils.sum(prrs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,99 +1,25 @@
|
|||||||
class PrrByVaccineTable {
|
class PrrByVaccineTable {
|
||||||
|
|
||||||
#tableElement;
|
#delegate;
|
||||||
#table;
|
|
||||||
#sumPrrs;
|
|
||||||
#prrByVaccine;
|
|
||||||
|
|
||||||
constructor(tableElement) {
|
constructor(tableElement) {
|
||||||
this.#tableElement = tableElement;
|
this.#delegate = new PrrByKeyTable({
|
||||||
|
tableElement: tableElement,
|
||||||
|
keyColumnName: 'Vaccine',
|
||||||
|
prrColumnName: 'Proportional Reporting Ratio',
|
||||||
|
shallMarkRowIfPrrTooHigh: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize() {
|
initialize() {
|
||||||
this.#table = this.#createEmptyTable();
|
this.#delegate.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
display(prrByVaccine) {
|
display(prrByVaccine) {
|
||||||
this.#prrByVaccine = prrByVaccine;
|
this.#delegate.display(prrByVaccine);
|
||||||
const vaccine_prr_pairs = Object.entries(prrByVaccine);
|
|
||||||
this.#setTableRows(vaccine_prr_pairs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getDisplayedTableAsCsv(heading) {
|
getDisplayedTableAsCsv(heading) {
|
||||||
return PrrByKey2CsvConverter.convertPrrByKey2Csv(
|
return this.#delegate.getDisplayedTableAsCsv(heading);
|
||||||
{
|
|
||||||
heading: heading,
|
|
||||||
columns: {
|
|
||||||
keyColumn: 'Vaccine',
|
|
||||||
prrColumn: 'Proportional Reporting Ratio'
|
|
||||||
},
|
|
||||||
prrByKey: this.#prrByVaccine
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#createEmptyTable() {
|
|
||||||
return this.#tableElement.DataTable(
|
|
||||||
{
|
|
||||||
search:
|
|
||||||
{
|
|
||||||
return: false
|
|
||||||
},
|
|
||||||
processing: true,
|
|
||||||
deferRender: true,
|
|
||||||
order: [[this.#getColumnIndex('Proportional Reporting Ratio'), "desc"]],
|
|
||||||
columnDefs:
|
|
||||||
[
|
|
||||||
{
|
|
||||||
searchable: false,
|
|
||||||
targets: [this.#getColumnIndex('Proportional Reporting Ratio')]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
render: prr =>
|
|
||||||
NumberWithBarElementFactory
|
|
||||||
.createNumberWithBarElement(
|
|
||||||
{
|
|
||||||
number: prr,
|
|
||||||
barLenInPercent: prr / this.#sumPrrs * 100
|
|
||||||
})
|
|
||||||
.outerHTML,
|
|
||||||
targets: [this.#getColumnIndex('Proportional Reporting Ratio')]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
createdRow: (row, data) => {
|
|
||||||
this.#markRowIfPrrTooHigh(
|
|
||||||
{
|
|
||||||
prr: data[this.#getColumnIndex('Proportional Reporting Ratio')],
|
|
||||||
row: row
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#markRowIfPrrTooHigh({ prr, row }) {
|
|
||||||
if (prr > 1.0) {
|
|
||||||
$(row).addClass('prrTooHigh');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#getColumnIndex(columnName) {
|
|
||||||
switch (columnName) {
|
|
||||||
case 'Vaccine':
|
|
||||||
return 0;
|
|
||||||
case 'Proportional Reporting Ratio':
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#setTableRows(vaccine_prr_pairs) {
|
|
||||||
this.#sumPrrs = this.#getSumPrrs(vaccine_prr_pairs);
|
|
||||||
this.#table
|
|
||||||
.clear()
|
|
||||||
.rows.add(vaccine_prr_pairs)
|
|
||||||
.draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
#getSumPrrs(vaccine_prr_pairs) {
|
|
||||||
const prrs = vaccine_prr_pairs.map(vaccine_prr_pair => vaccine_prr_pair[1])
|
|
||||||
return Utils.sum(prrs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByKey2CsvConverter.js"></script>
|
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByKey2CsvConverter.js"></script>
|
||||||
<script src="../../docs/SymptomsCausedByVaccines/js/PageInitializer.js"></script>
|
<script src="../../docs/SymptomsCausedByVaccines/js/PageInitializer.js"></script>
|
||||||
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByVaccineProvider.js"></script>
|
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByVaccineProvider.js"></script>
|
||||||
|
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByKeyTable.js"></script>
|
||||||
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByVaccineTable.js"></script>
|
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByVaccineTable.js"></script>
|
||||||
<script src="../../docs/SymptomsCausedByVaccines/js/PrrBySymptomTable.js"></script>
|
<script src="../../docs/SymptomsCausedByVaccines/js/PrrBySymptomTable.js"></script>
|
||||||
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByKeyTableView.js"></script>
|
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByKeyTableView.js"></script>
|
||||||
|
|||||||
Reference in New Issue
Block a user