refining PdfCreator
This commit is contained in:
@@ -1,16 +1,73 @@
|
||||
class PdfCreator {
|
||||
|
||||
static createPdf() {
|
||||
static createPdf({ symptom, vaccine }) {
|
||||
const documentDefinition = {
|
||||
content: [
|
||||
{ text: 'EU Safety Signal (All drugs)', fontSize: 16, alignment: 'center', margin: [0, 0, 0, 20], bold: true },
|
||||
{ text: 'Worst Drugs', fontSize: 12, alignment: 'left', margin: [0, 10, 0, 10], bold: true },
|
||||
{ text: 'table' },
|
||||
{ text: 'Strongest Symptoms', fontSize: 12, alignment: 'left', margin: [0, 10, 0, 10], bold: true },
|
||||
{ text: 'table' },
|
||||
{
|
||||
text: 'EU Safety Signal (All drugs)',
|
||||
fontSize: 18,
|
||||
alignment: 'center',
|
||||
margin: [0, 0, 0, 20],
|
||||
bold: true
|
||||
},
|
||||
...PdfCreator.#getWorstDrugsSection(symptom),
|
||||
...PdfCreator.#getStrongestSymptoms(vaccine)
|
||||
]
|
||||
}
|
||||
return pdfMake.createPdf(documentDefinition);
|
||||
// pdfMake.createPdf(documentDefinition).download();
|
||||
}
|
||||
|
||||
static #getWorstDrugsSection({ selectElement, table }) {
|
||||
return [
|
||||
PdfCreator.#getHeading(`Worst Drugs for ${PdfCreator.#getSelection(selectElement)}`),
|
||||
PdfCreator.#getTable(table)
|
||||
];
|
||||
}
|
||||
|
||||
static #getStrongestSymptoms({ selectElement, table }) {
|
||||
return [
|
||||
PdfCreator.#getHeading(`Strongest Symptoms for ${PdfCreator.#getSelection(selectElement)}`),
|
||||
PdfCreator.#getTable(table)
|
||||
];
|
||||
}
|
||||
|
||||
static #getHeading(text) {
|
||||
return {
|
||||
text: text,
|
||||
fontSize: 14,
|
||||
alignment: 'left',
|
||||
margin: [0, 15, 0, 15],
|
||||
bold: true
|
||||
}
|
||||
}
|
||||
|
||||
static #getSelection(selectElement) {
|
||||
return selectElement.select2('data')[0].text;
|
||||
}
|
||||
|
||||
static #getTable(table) {
|
||||
const headers = PdfCreator.#getTableHeaders(table);
|
||||
const rows = table.rows({ search: 'applied' }).data().toArray();
|
||||
return {
|
||||
layout: 'lightHorizontalLines',
|
||||
table: {
|
||||
headerRows: 1,
|
||||
body: [
|
||||
headers,
|
||||
...rows
|
||||
]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static #getTableHeaders(table) {
|
||||
return table
|
||||
.columns()
|
||||
.header()
|
||||
.map(header => ({
|
||||
text: header.textContent,
|
||||
bold: true
|
||||
}))
|
||||
.toArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user