var fs = require('fs'); const csv = require('csv-parser'); const moment = require('moment'); const html_to_pdf = require('html-pdf-node'); async function makePdf(data) { let options = { format: 'A4' }; let template = { content: `
Person Name: ${data?.Name}
Age / Sex: ${data?.Age} / ${data?.Gender}
Sample type: Capillary Whole Blood
Family History of Sickle Cell Anemia: NA
Marital Status: ${data["Marital Status"]}
Test Date: ${data?.testTime}
ABHA ID: ${data["ABHA ID"]}
Sample ID: ${data["_id"]}
POINT OF CARE SICKLE CELL ANEMIA TEST
Test Description RESULT REFERENCE RANGES
Sickle Cell Anemia
(Method: HPOS)
Ra = ${data["Test Right device 5 ratio"]}
< 0.16: Normal (HbA)
0.165 – 0.235: Sickle-cell Trait (HbAS)
> 0.24: Sickle-cell Disease (HbSS)
0.16-0.165: Inconclusive (Negative Borderline)
0.235 – 0.24: Inconclusive (Positive Borderline)
Test Principle: This point of care quantitative diagnostic test for sickle-cell anemia works on the principle of absorption spectroscopy. The test helps in differentiating heterozygous/homozygous hemoglobin from normal hemoglobin.
Method: High Performance Optical Spectroscopy (HPOS) for detection of Sickle cell trait and sickle cell disease in whole blood capillary blood samples.
Note: Borderline cases are reported as inconclusive. It may occur due to several factors such as medication, transfusion, field conditions and assay process. Further clinical tests are recommended in these cases for diagnosis.
*** END OF REPORT ***
This is an electronically generated report. Generated at ${moment().format('HH:MM')} hrs on ${moment().format('DD-MM-YYYY')}.
Note: Assay results should be correlated clinically with other clinical findings
` }; html_to_pdf.generatePdf(template, options).then(pdfBuffer => { fs.writeFile(`reports/${data._id}.pdf`, pdfBuffer, "binary", function (err) { if (err) { console.log(err); } else { console.log("The file was saved!"); } }); }); } const delay = (delayInms) => { return new Promise(resolve => setTimeout(resolve, delayInms)); } const users = []; fs.createReadStream("data/result.csv") .pipe(csv()) .on('data', function(data){ try { console.log("id: " + data._id); users.push(data); } catch(err) { //error handler } }) .on('end', async function(){ console.log('size ', users.length); for (let i = 0; i < users.length; i++) { await makePdf(users[i]); let delayres = await delay(10000); console.log('index ', i); } });