nagpur changes
This commit is contained in:
265
scripts/pdf_report.py
Normal file
265
scripts/pdf_report.py
Normal file
@@ -0,0 +1,265 @@
|
||||
import sys
|
||||
import csv
|
||||
from xhtml2pdf import pisa
|
||||
import os
|
||||
import pandas as pd
|
||||
|
||||
rptData = {}
|
||||
|
||||
rptData['Person Name'] = "row['Name']"
|
||||
rptData['Age'] = "row['Age']"
|
||||
rptData['Gender'] = "row['Gender']"
|
||||
rptData['Age / Sex'] = "Male"
|
||||
rptData['Sample type'] = 'Capillary Whole Blood'
|
||||
rptData['Family History of Sickle Cell Anemia'] = 'Unknown'
|
||||
rptData['Marital Status'] = "row['Marital Status']"
|
||||
rptData['Test Date'] = "date"
|
||||
rptData['Patient ID'] = "row['ABHA ID']"
|
||||
rptData['Sample ID'] = "row['_id']"
|
||||
rptData['value'] = "row['Measured Deovix Ratio']"
|
||||
|
||||
rd = rptData
|
||||
# template_path = os.path.join(THIS_DIR, 'report_template.html')
|
||||
|
||||
report_template =r'''
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<style>
|
||||
@media print {
|
||||
body {
|
||||
-webkit-print-color-adjust: exact;
|
||||
}
|
||||
}
|
||||
|
||||
.person-details-row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.person-details-col {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 90px;
|
||||
width: 50%;
|
||||
margin: 1px;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.test-details-row {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.test-details-col {
|
||||
height: 100px;
|
||||
}
|
||||
|
||||
.test-cell-div {
|
||||
/* border: 1px solid black; */
|
||||
border-collapse: collapse;
|
||||
height: 20px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.table-header {
|
||||
border: 1px solid black;
|
||||
margin: 0 0 -10px 10px;
|
||||
background-color: rgb(191, 191, 191);
|
||||
text-align: center;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
display: flex;
|
||||
font-weight: 600;
|
||||
height: 50px;
|
||||
width: 98%;
|
||||
}
|
||||
|
||||
@media print {
|
||||
.table-header {
|
||||
background-color: rgb(191, 191, 191) !important;
|
||||
print-color-adjust: exact;
|
||||
}
|
||||
}
|
||||
|
||||
@media print {
|
||||
.vendorListHeading th {
|
||||
color: white !important;
|
||||
}
|
||||
}
|
||||
|
||||
.test-method {
|
||||
font-weight: 200 !important;
|
||||
color: rgb(191, 191, 191);
|
||||
}
|
||||
|
||||
.result-value {
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.end-of-report {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.logo {
|
||||
background-color: red;
|
||||
width: 10;
|
||||
}
|
||||
|
||||
table,
|
||||
th,
|
||||
td {
|
||||
border: 1px solid black;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style-type: none;
|
||||
/* margin: 0; */
|
||||
/* padding: 0; */
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div>
|
||||
<div class="logo">
|
||||
<img src="logo_nobg.png" width="138" height="128" alt="sickle cell logo" />
|
||||
</div>
|
||||
<table style="border: 1px solid black; margin: 10px; width: 98%;">
|
||||
<tr class="person-details-row">
|
||||
<td class="person-details-col" style="border-right: 2; width: 70%;">
|
||||
<div><strong>Person Name:</strong> {{ reportData["Person Name"] }}</div>
|
||||
<div><strong>Age / Sex:</strong> {{reportData['Age']}} / {{reportData['Gender']}}</div>
|
||||
<div><strong>Sample type:</strong>{{ reportData["Sample type"] }}</div>
|
||||
<div><strong>Family History of Sickle Cell Anemia:</strong>{{ reportData["Family History of Sickle Cell Anemia"] }}</div>
|
||||
</td>
|
||||
<td class="person-details-col" style="width: 30%;">
|
||||
<div><strong>Marital Status:</strong>{{ reportData["Marital Status"] }}</div>
|
||||
<div><strong>Test Date:</strong>{{ reportData["Test Date"] }}</div>
|
||||
<div><strong>ABHA ID:</strong>{{ reportData["Patient ID"] }}</div>
|
||||
<div><strong>Sample ID:</strong>{{ reportData["Sample ID"] }}</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
<div style="height: 2px;width: 98%; background-color: rgb(56, 105, 166); margin: 30px 10px 40px 10px;"></div>
|
||||
|
||||
|
||||
<div>
|
||||
<div class="table-header">POINT OF CARE SICKLE CELL ANEMIA TEST</div>
|
||||
<table class="test-details-table" style="border: 1px solid black; margin: 10px; width: 98%;">
|
||||
<tr style="height: 50px;">
|
||||
<th>
|
||||
Test Description
|
||||
</th>
|
||||
<th>
|
||||
RESULT
|
||||
</th>
|
||||
<th>
|
||||
REFERENCE RANGES
|
||||
</th>
|
||||
</tr>
|
||||
<tr class="test-details-row">
|
||||
<td class="test-details-col" style="width: 20%; margin: 10px;">
|
||||
<div style="margin: 10px;">Sickle Cell
|
||||
Anemia
|
||||
<div class="test-method">(Method: HPOS)</div>
|
||||
</div>
|
||||
</td>
|
||||
<td style="width: 30%;">
|
||||
<div class="result-value">Ra = {{ reportData["value"] }}</div>
|
||||
<!-- <div class="test-cell-div">Normal</div>
|
||||
<div class="test-cell-div">Sickle Cell Trait</div>
|
||||
<div class="test-cell-div">Sickle Cell Disease</div>
|
||||
<div class="test-cell-div">Negative Borderline</div>
|
||||
<div class="test-cell-div">Positive Borderline</div> -->
|
||||
</td>
|
||||
<td style="width: 50%;">
|
||||
<div class="test-cell-div">
|
||||
< 0.16: Normal (HbA)</div>
|
||||
<div class="test-cell-div">0.165 – 0.235: Sickle-cell Trait (HbAS)</div>
|
||||
<div class="test-cell-div">> 0.24: Sickle-cell Disease (HbSS)</div>
|
||||
<div class="test-cell-div">0.16-0.165: Inconclusive (Negative Borderline)</div>
|
||||
<div class="test-cell-div">0.235 – 0.24: Inconclusive (Positive Borderline)</div>
|
||||
</td>
|
||||
<!-- <td style="width: 25%;">
|
||||
<div class="test-cell-div">Normal</div>
|
||||
<div class="test-cell-div">Sickle Cell Trait</div>
|
||||
<div class="test-cell-div">Sickle Cell Disease</div>
|
||||
<div class="test-cell-div">Recommended for HPLC or Electrophoresis Tests</div>
|
||||
<div class="test-cell-div">Recommended for HPLC or Electrophore</div>
|
||||
</td> -->
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<!-- <div style="font-weight: 600; margin: 10px;">INTERPRETATION:</div> -->
|
||||
|
||||
<div style="margin: 10px;">
|
||||
<strong>Test Principle:</strong> 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.
|
||||
</div>
|
||||
|
||||
<div style="margin: 10px;">
|
||||
<strong>Method:</strong> High Performance Optical Spectroscopy (HPOS) for detection of Sickle cell trait and
|
||||
sickle cell disease in whole blood capillary blood samples.
|
||||
</div>
|
||||
|
||||
<div style="margin: 10px;">
|
||||
<strong> Note:</strong>
|
||||
<!-- <ul>
|
||||
<li>a. Blood transfusion may have an impact on the test results.</li>
|
||||
|
||||
<li>
|
||||
b. Patients already on sickle-cell medications may impact test results.
|
||||
</li>
|
||||
</ul> -->
|
||||
|
||||
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.
|
||||
</div>
|
||||
|
||||
<!-- <div
|
||||
style="margin: 80px 10px 20px 50px; width: 88%; display: flex; flex-direction: row; justify-content: space-between; align-items: center;">
|
||||
<div style="margin: 5px;">DATE:</div>
|
||||
<div style="margin: 5px;">Hematologist</div>
|
||||
</div> -->
|
||||
|
||||
<!-- <div style="margin: 30px;">
|
||||
This report is for the perusal of doctor only. Not for medico legal cases. Clinical correlation is
|
||||
essential.
|
||||
Please contact us in case of unexpected result.
|
||||
</div> -->
|
||||
<div style="height: 3px;width: 98%; background-color: black; margin-top: 150px;"></div>
|
||||
<div class="end-of-report">
|
||||
*** END OF REPORT ***</div>
|
||||
<div style="display: flex; justify-content: center; align-items: center; flex-direction: column;">
|
||||
<div style="font-style: italic; color: rgb(191, 191, 191);">
|
||||
This is an electronically generated report. Generated at HH:MM hrs on DD-MMM-YYYY.
|
||||
</div>
|
||||
<div>
|
||||
Note: Assay results should be correlated clinically with other clinical findings
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
'''
|
||||
|
||||
# rptHtml = j2_env.from_string(report_template).render(reportData=rd)
|
||||
reportFile = open('report.pdf','w+b')
|
||||
pisa_status = pisa.CreatePDF(report_template, dest=reportFile)
|
||||
if not pisa_status.err:
|
||||
print("Created PDF report %s." % outFilename)
|
||||
#os.remove(rd['qrcodeImgFile'])
|
||||
Reference in New Issue
Block a user