refactoring
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
<script src="./js/PrrByVaccineProvider.js"></script>
|
||||
<script src="./js/PrrByVaccineTable.js"></script>
|
||||
<script src="./js/PrrBySymptomTable.js"></script>
|
||||
<script src="./js/PrrByKeyTableView.js"></script>
|
||||
<script src="./js/PrrByVaccineTableView.js"></script>
|
||||
<script src="./js/PrrBySymptomTableView.js"></script>
|
||||
<script>
|
||||
|
||||
44
docs/SymptomsCausedByVaccines/js/PrrByKeyTableView.js
Normal file
44
docs/SymptomsCausedByVaccines/js/PrrByKeyTableView.js
Normal file
@@ -0,0 +1,44 @@
|
||||
class PrrByKeyTableView {
|
||||
|
||||
#prrByKeyTable;
|
||||
#downloadPrrByKeyTableButton;
|
||||
#value;
|
||||
#valueName;
|
||||
#prrByKeyProvider;
|
||||
|
||||
constructor(prrByKeyTable, downloadPrrByKeyTableButton, valueName, prrByKeyProvider) {
|
||||
this.#prrByKeyTable = prrByKeyTable;
|
||||
this.#prrByKeyTable.initialize();
|
||||
this.#initializeButton(downloadPrrByKeyTableButton);
|
||||
this.#valueName = valueName;
|
||||
this.#prrByKeyProvider = prrByKeyProvider;
|
||||
}
|
||||
|
||||
displayPrrByKeyTable4Value(value) {
|
||||
UIUtils.disableButton(this.#downloadPrrByKeyTableButton);
|
||||
this.#prrByKeyProvider(value)
|
||||
.then(prrByKey => {
|
||||
this.#value = value;
|
||||
this.#prrByKeyTable.display(prrByKey);
|
||||
UIUtils.enableButton(this.#downloadPrrByKeyTableButton);
|
||||
});
|
||||
}
|
||||
|
||||
#initializeButton(downloadPrrByKeyTableButton) {
|
||||
this.#downloadPrrByKeyTableButton = downloadPrrByKeyTableButton;
|
||||
UIUtils.disableButton(downloadPrrByKeyTableButton);
|
||||
downloadPrrByKeyTableButton.addEventListener(
|
||||
'click',
|
||||
() => this.#downloadPrrByKey())
|
||||
}
|
||||
|
||||
#downloadPrrByKey() {
|
||||
UIUtils.downloadUrlAsFilename(
|
||||
window.URL.createObjectURL(
|
||||
new Blob(
|
||||
[this.#prrByKeyTable.getDisplayedTableAsCsv(`# ${this.#valueName}: ${this.#value}`)],
|
||||
{ type: 'text/csv' })),
|
||||
this.#value
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ class PrrBySymptomTable {
|
||||
#tableElement;
|
||||
#table;
|
||||
#sumPrrs;
|
||||
#prrBySymptom;
|
||||
|
||||
constructor(tableElement) {
|
||||
this.#tableElement = tableElement;
|
||||
@@ -13,10 +14,23 @@ class PrrBySymptomTable {
|
||||
}
|
||||
|
||||
display(prrBySymptom) {
|
||||
this.#prrBySymptom = prrBySymptom;
|
||||
const symptom_prr_pairs = Object.entries(prrBySymptom);
|
||||
this.#setTableRows(symptom_prr_pairs);
|
||||
}
|
||||
|
||||
getDisplayedTableAsCsv(heading) {
|
||||
return PrrByKey2CsvConverter.convertPrrByKey2Csv(
|
||||
{
|
||||
heading: heading,
|
||||
columns: {
|
||||
keyColumn: 'Symptom',
|
||||
prrColumn: 'Proportional Reporting Ratio > 1'
|
||||
},
|
||||
prrByKey: this.#prrBySymptom
|
||||
});
|
||||
}
|
||||
|
||||
#createEmptyTable() {
|
||||
return this.#tableElement.DataTable(
|
||||
{
|
||||
|
||||
@@ -1,53 +1,16 @@
|
||||
class PrrBySymptomTableView {
|
||||
|
||||
#prrBySymptomTable;
|
||||
#downloadPrrBySymptomTableButton;
|
||||
#prrBySymptom;
|
||||
#vaccine;
|
||||
#delegate;
|
||||
|
||||
constructor(prrBySymptomTableElement, downloadPrrBySymptomTableButton) {
|
||||
this.#prrBySymptomTable = new PrrBySymptomTable(prrBySymptomTableElement);
|
||||
this.#prrBySymptomTable.initialize();
|
||||
this.#initializeButton(downloadPrrBySymptomTableButton);
|
||||
this.#delegate = new PrrByKeyTableView(
|
||||
new PrrBySymptomTable(prrBySymptomTableElement),
|
||||
downloadPrrBySymptomTableButton,
|
||||
'Vaccine',
|
||||
PrrByVaccineProvider.getPrrBySymptom);
|
||||
}
|
||||
|
||||
displayPrrBySymptomTable4Vaccine(vaccine) {
|
||||
UIUtils.disableButton(this.#downloadPrrBySymptomTableButton);
|
||||
PrrByVaccineProvider
|
||||
.getPrrBySymptom(vaccine)
|
||||
.then(prrBySymptom => {
|
||||
this.#prrBySymptom = prrBySymptom;
|
||||
this.#vaccine = vaccine;
|
||||
this.#prrBySymptomTable.display(prrBySymptom);
|
||||
UIUtils.enableButton(this.#downloadPrrBySymptomTableButton);
|
||||
});
|
||||
}
|
||||
|
||||
#initializeButton(downloadPrrBySymptomTableButton) {
|
||||
this.#downloadPrrBySymptomTableButton = downloadPrrBySymptomTableButton;
|
||||
UIUtils.disableButton(downloadPrrBySymptomTableButton);
|
||||
downloadPrrBySymptomTableButton.addEventListener(
|
||||
'click',
|
||||
() => this.#downloadPrrBySymptom())
|
||||
}
|
||||
|
||||
#downloadPrrBySymptom() {
|
||||
UIUtils.downloadUrlAsFilename(
|
||||
window.URL.createObjectURL(
|
||||
new Blob(
|
||||
[
|
||||
PrrByKey2CsvConverter.convertPrrByKey2Csv(
|
||||
{
|
||||
heading: '# Vaccine: ' + this.#vaccine,
|
||||
columns: {
|
||||
keyColumn: 'Symptom',
|
||||
prrColumn: 'Proportional Reporting Ratio > 1'
|
||||
},
|
||||
prrByKey: this.#prrBySymptom
|
||||
})
|
||||
],
|
||||
{ type: 'text/csv' })),
|
||||
this.#vaccine
|
||||
);
|
||||
this.#delegate.displayPrrByKeyTable4Value(vaccine);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,16 @@
|
||||
class PrrByVaccineTableView {
|
||||
|
||||
#prrByVaccineTable;
|
||||
#downloadPrrByVaccineTableButton;
|
||||
#symptom;
|
||||
#delegate;
|
||||
|
||||
constructor(prrByVaccineTableElement, downloadPrrByVaccineTableButton) {
|
||||
this.#prrByVaccineTable = new PrrByVaccineTable(prrByVaccineTableElement);
|
||||
this.#prrByVaccineTable.initialize();
|
||||
this.#initializeButton(downloadPrrByVaccineTableButton);
|
||||
this.#delegate = new PrrByKeyTableView(
|
||||
new PrrByVaccineTable(prrByVaccineTableElement),
|
||||
downloadPrrByVaccineTableButton,
|
||||
'Symptom',
|
||||
PrrByVaccineProvider.getPrrByVaccine);
|
||||
}
|
||||
|
||||
displayPrrByVaccineTable4Symptom(symptom) {
|
||||
UIUtils.disableButton(this.#downloadPrrByVaccineTableButton);
|
||||
PrrByVaccineProvider
|
||||
.getPrrByVaccine(symptom)
|
||||
.then(prrByVaccine => {
|
||||
this.#symptom = symptom;
|
||||
this.#prrByVaccineTable.display(prrByVaccine);
|
||||
UIUtils.enableButton(this.#downloadPrrByVaccineTableButton);
|
||||
});
|
||||
}
|
||||
|
||||
#initializeButton(downloadPrrByVaccineTableButton) {
|
||||
this.#downloadPrrByVaccineTableButton = downloadPrrByVaccineTableButton;
|
||||
UIUtils.disableButton(downloadPrrByVaccineTableButton);
|
||||
downloadPrrByVaccineTableButton.addEventListener(
|
||||
'click',
|
||||
() => this.#downloadPrrByVaccine())
|
||||
}
|
||||
|
||||
#downloadPrrByVaccine() {
|
||||
UIUtils.downloadUrlAsFilename(
|
||||
window.URL.createObjectURL(
|
||||
new Blob(
|
||||
[this.#prrByVaccineTable.getDisplayedTableAsCsv('# Symptom: ' + this.#symptom)],
|
||||
{ type: 'text/csv' })),
|
||||
this.#symptom
|
||||
);
|
||||
this.#delegate.displayPrrByKeyTable4Value(symptom);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByVaccineProvider.js"></script>
|
||||
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByVaccineTable.js"></script>
|
||||
<script src="../../docs/SymptomsCausedByVaccines/js/PrrBySymptomTable.js"></script>
|
||||
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByKeyTableView.js"></script>
|
||||
<script src="../../docs/SymptomsCausedByVaccines/js/PrrByVaccineTableView.js"></script>
|
||||
<script src="../../docs/SymptomsCausedByVaccines/js/PrrBySymptomTableView.js"></script>
|
||||
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.17.2.css">
|
||||
|
||||
Reference in New Issue
Block a user