Merge branch 'main' into pages
merging
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
class PdfCreator {
|
||||
|
||||
static createPdf({ symptom, vaccine, heading, valueName }) {
|
||||
const documentDefinition = {
|
||||
static createPdf(pdf) {
|
||||
return pdfMake.createPdf(PdfCreator.#createDocumentDefinition(pdf));
|
||||
}
|
||||
|
||||
static #createDocumentDefinition({ symptom, vaccine, heading, valueName }) {
|
||||
return {
|
||||
content: [
|
||||
PdfCreator.#getPageHeading(heading),
|
||||
...PdfCreator.#getWorstDrugsSection(symptom, valueName),
|
||||
...PdfCreator.#getStrongestSymptomsSection(vaccine)
|
||||
...PdfCreator.#getStrongestSymptomsSection(vaccine),
|
||||
PdfCreator.#link2Origin()
|
||||
]
|
||||
}
|
||||
return pdfMake.createPdf(documentDefinition);
|
||||
};
|
||||
}
|
||||
|
||||
static #getPageHeading(heading) {
|
||||
@@ -24,14 +28,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)
|
||||
];
|
||||
}
|
||||
|
||||
@@ -49,17 +53,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)
|
||||
]
|
||||
}
|
||||
};
|
||||
@@ -75,4 +76,58 @@ 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,
|
||||
};
|
||||
}
|
||||
|
||||
static #link2Origin() {
|
||||
return {
|
||||
text:
|
||||
[
|
||||
'Origin: ',
|
||||
{
|
||||
text: window.location.href,
|
||||
color: 'blue',
|
||||
decoration: 'underline',
|
||||
link: window.location.href
|
||||
}
|
||||
],
|
||||
margin: [0, 10]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user