Merge branch 'main' into pages
merging
This commit is contained in:
@@ -1,14 +1,18 @@
|
|||||||
class PdfCreator {
|
class PdfCreator {
|
||||||
|
|
||||||
static createPdf({ symptom, vaccine, heading, valueName }) {
|
static createPdf(pdf) {
|
||||||
const documentDefinition = {
|
return pdfMake.createPdf(PdfCreator.#createDocumentDefinition(pdf));
|
||||||
|
}
|
||||||
|
|
||||||
|
static #createDocumentDefinition({ symptom, vaccine, heading, valueName }) {
|
||||||
|
return {
|
||||||
content: [
|
content: [
|
||||||
PdfCreator.#getPageHeading(heading),
|
PdfCreator.#getPageHeading(heading),
|
||||||
...PdfCreator.#getWorstDrugsSection(symptom, valueName),
|
...PdfCreator.#getWorstDrugsSection(symptom, valueName),
|
||||||
...PdfCreator.#getStrongestSymptomsSection(vaccine)
|
...PdfCreator.#getStrongestSymptomsSection(vaccine),
|
||||||
|
PdfCreator.#link2Origin()
|
||||||
]
|
]
|
||||||
}
|
};
|
||||||
return pdfMake.createPdf(documentDefinition);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static #getPageHeading(heading) {
|
static #getPageHeading(heading) {
|
||||||
@@ -24,14 +28,14 @@ class PdfCreator {
|
|||||||
static #getWorstDrugsSection({ selectElement, table }, valueName) {
|
static #getWorstDrugsSection({ selectElement, table }, valueName) {
|
||||||
return [
|
return [
|
||||||
PdfCreator.#getHeading(`Worst ${valueName} for "${PdfCreator.#getSelection(selectElement)}"`),
|
PdfCreator.#getHeading(`Worst ${valueName} for "${PdfCreator.#getSelection(selectElement)}"`),
|
||||||
PdfCreator.#getTable(table)
|
PdfCreator.#getTable(table, true)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
static #getStrongestSymptomsSection({ selectElement, table }) {
|
static #getStrongestSymptomsSection({ selectElement, table }) {
|
||||||
return [
|
return [
|
||||||
PdfCreator.#getHeading(`Strongest Symptoms for "${PdfCreator.#getSelection(selectElement)}"`),
|
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;
|
return selectElement.select2('data')[0].text;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FK-TODO: add red background to some rows
|
static #getTable(table, shallMarkRowsIfPrrTooHigh) {
|
||||||
static #getTable(table) {
|
|
||||||
const headers = PdfCreator.#getTableHeaders(table);
|
|
||||||
const rows = table.rows({ search: 'applied' }).data().toArray();
|
|
||||||
return {
|
return {
|
||||||
layout: 'lightHorizontalLines',
|
layout: 'lightHorizontalLines',
|
||||||
table: {
|
table: {
|
||||||
headerRows: 1,
|
headerRows: 1,
|
||||||
body: [
|
body: [
|
||||||
headers,
|
PdfCreator.#getTableHeaders(table),
|
||||||
...rows
|
...PdfCreator.#getMarkedRows(table, shallMarkRowsIfPrrTooHigh)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -75,4 +76,58 @@ class PdfCreator {
|
|||||||
}))
|
}))
|
||||||
.toArray();
|
.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