MarkRowsIfPrrTooHigh

This commit is contained in:
Frank Knoll
2024-07-16 23:53:07 +02:00
parent 8f04a22142
commit 34107357cf

View File

@@ -27,14 +27,14 @@ class PdfCreator {
static #getWorstDrugsSection({ selectElement, table }, valueName) {
return [
PdfCreator.#getHeading(`Worst ${valueName} for "${PdfCreator.#getSelection(selectElement)}"`),
PdfCreator.#getTable(table)
PdfCreator.#getTable(table, true)
];
}
static #getStrongestSymptomsSection({ selectElement, table }) {
return [
PdfCreator.#getHeading(`Strongest Symptoms for "${PdfCreator.#getSelection(selectElement)}"`),
PdfCreator.#getTable(table)
PdfCreator.#getTable(table, false)
];
}
@@ -52,17 +52,14 @@ class PdfCreator {
return selectElement.select2('data')[0].text;
}
// FK-TODO: add red background to some rows
static #getTable(table) {
const headers = PdfCreator.#getTableHeaders(table);
const rows = table.rows({ search: 'applied' }).data().toArray();
static #getTable(table, shallMarkRowsIfPrrTooHigh) {
return {
layout: 'lightHorizontalLines',
table: {
headerRows: 1,
body: [
headers,
...rows
PdfCreator.#getTableHeaders(table),
...PdfCreator.#getMarkedRows(table, shallMarkRowsIfPrrTooHigh)
]
}
};
@@ -78,4 +75,42 @@ class PdfCreator {
}))
.toArray();
}
static #getMarkedRows(table, shallMarkRowsIfPrrTooHigh) {
const rows = PdfCreator.#getRows(table);
return shallMarkRowsIfPrrTooHigh ?
PdfCreator.#markRowsIfPrrTooHigh(rows) :
rows;
}
static #getRows(table) {
return table
.rows({ search: 'applied' })
.data()
.toArray();
}
static #markRowsIfPrrTooHigh(rows) {
return rows.map(PdfCreator.#markRowIfPrrTooHigh);
}
static #markRowIfPrrTooHigh(row) {
const prr = row[1];
return [
PdfCreator.#markValueIfPrrTooHigh({ value: row[0], prr: prr }),
PdfCreator.#markValueIfPrrTooHigh({ value: row[1], prr: prr })
];
}
static #markValueIfPrrTooHigh({ value, prr }) {
return prr >= 2.0 ? PdfCreator.#markValue(value) : value;
}
static #markValue(value) {
return {
text: value,
fillColor: '#FF0000',
fillOpacity: 0.1,
};
}
}