diff --git a/docs/SymptomsCausedByDrugs/js/PdfCreator.js b/docs/SymptomsCausedByDrugs/js/PdfCreator.js index 5986d69fcea..6b775e5aaba 100644 --- a/docs/SymptomsCausedByDrugs/js/PdfCreator.js +++ b/docs/SymptomsCausedByDrugs/js/PdfCreator.js @@ -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, + }; + } } \ No newline at end of file