Detailed analysis of reports and prescribe appropriate management and treatment
cd "/tmp/workspace/attachments/5be00477-d06b-4788-bc3d-5653c24df247/" && python3 -c " import pdfplumber with pdfplumber.open('502747894 (3).pdf') as pdf: print(f'Total pages: {len(pdf.pages)}') for i, page in enumerate(pdf.pages): print(f'--- PAGE {i+1} ---') text = page.extract_text() if text: print(text) tables = page.extract_tables() for j, table in enumerate(tables): print(f' [Table {j+1}]') for row in table: print(' ', row) "
| Test Group | Status | Key Finding |
|---|---|---|
| Liver & Kidney Function | Mostly Normal | Elevated bilirubin (indirect predominant) |
| Vitamin D | DEFICIENT | 29.31 nmol/L (need >75) |
| Vitamin B12 | LOW-BORDERLINE | 202.10 pg/mL (ref: 211-946) |
| Hemogram | Normal | All parameters within range |
| Thyroid Profile | Normal | TSH, fT3, fT4 all normal |
| Lipid Profile | Excellent | All within desirable range |
| HbA1c / Glucose | Normal | Non-diabetic |
| Apolipoproteins | LOW Apo A1 & Apo B | Below reference (nutritional pattern) |
| Iron Studies | Normal | Transferrin saturation borderline low-normal |
| Urine Routine | Normal | No pathological finding |
| CRP (hsCRP) | Excellent | 0.08 mg/L (very low cardiovascular risk) |
| Amylase | Normal | 94.74 U/L |
| ESR | Normal | 5 mm/hr |
| Parameter | Result | Reference | Status |
|---|---|---|---|
| Vitamin D 25-OH | 29.31 nmol/L | 75-250 nmol/L | DEFICIENT |
| Parameter | Result | Reference | Status |
|---|---|---|---|
| Vitamin B12 | 202.10 pg/mL | 211-946 pg/mL | BELOW RANGE |
| Parameter | Result | Reference | Status |
|---|---|---|---|
| Total Bilirubin | 2.13 mg/dL | 0.30-1.20 mg/dL | HIGH |
| Direct Bilirubin | 0.40 mg/dL | <0.20 mg/dL | Mildly elevated |
| Indirect Bilirubin | 1.73 mg/dL | <1.10 mg/dL | HIGH - Predominant |
| AST/ALT/ALP/GGTP | All normal | - | Normal |
| Parameter | Result | Reference | Status |
|---|---|---|---|
| Apo A1 | 94 mg/dL | 105-175 mg/dL | LOW |
| Apo B | <40 mg/dL | 60-140 mg/dL | LOW |
| Apo B/A1 Ratio | 0.32 | 0.35-0.98 | Slightly below range |
| Parameter | Result | Reference | Status |
|---|---|---|---|
| Uric Acid | 3.25 mg/dL | 3.50-7.20 mg/dL | Slightly below range |
| Parameter | Result | Interpretation |
|---|---|---|
| HbA1c 4.2% | Normal | Non-diabetic, excellent glycemic status |
| Random Glucose 76.44 mg/dL | Normal | No diabetes/prediabetes |
| Thyroid (TSH 2.65, fT4 1.62, fT3 2.85) | Normal | Euthyroid |
| Hemogram (Hb 14.5, MCV 87) | Normal | No anemia; Mentzer Index 17.2 (>13 = less likely thalassemia trait) |
| Iron Studies (Ferritin proxy: sat 21%) | Low-normal | No iron deficiency anemia |
| Serum Amylase 94.74 | Normal | No pancreatitis |
| Kidney (GFR 123, Creatinine 0.82) | Excellent | GFR Category G1 - normal kidney function |
| Lipid Profile | Excellent | All values well within targets |
| hsCRP 0.08 mg/L | Very low | Low cardiovascular inflammatory risk |
| Urine Routine | Normal | No infection, no protein, no glucose |
| ESR 5 mm/hr | Normal | No systemic inflammation |
| Electrolytes (Na, K, Cl, Ca, P) | All normal |
| Test | Reason |
|---|---|
| Serum MMA / Homocysteine | Confirm B12 functional deficiency |
| PTH (Parathyroid Hormone) | Assess secondary hyperparathyroidism from chronic Vitamin D deficiency |
| Serum Ferritin | Iron stores (transferrin saturation 21% is borderline; ferritin would confirm iron stores) |
| H. pylori Ag stool test | If B12 deficiency confirmed + gastric symptoms |
| Reticulocyte count + LDH | To formally rule out hemolysis contributing to bilirubin elevation (optional, not urgent) |
| BMI + dietary history | Low Apo A1/B and low B12 suggest nutritional gap; formal dietary assessment helpful |
Disclaimer: This analysis is based on laboratory values alone and must be correlated with clinical history, symptoms, and physical examination by a qualified physician before initiating treatment.
Create a treatment summary document I can share with the patient
mkdir -p /tmp/workspace/bajarang-lal-report && python3 << 'EOF' from docx import Document from docx.shared import Pt, Inches, RGBColor from docx.enum.text import WD_ALIGN_PARAGRAPH from docx.oxml.ns import qn from docx.oxml import OxmlElement import datetime doc = Document() # --- Page margins --- from docx.shared import Cm section = doc.sections[0] section.page_width = Inches(8.27) # A4 section.page_height = Inches(11.69) section.left_margin = Cm(2.5) section.right_margin = Cm(2.5) section.top_margin = Cm(2.2) section.bottom_margin = Cm(2.2) # --- Default font --- normal_style = doc.styles['Normal'] normal_style.font.name = 'Calibri' normal_style.font.size = Pt(10.5) # ---------------------------------------------------------------- # Helper: set paragraph background shading # ---------------------------------------------------------------- def shade_paragraph(para, fill_hex): pPr = para._p.get_or_add_pPr() shd = OxmlElement('w:shd') shd.set(qn('w:val'), 'clear') shd.set(qn('w:color'), 'auto') shd.set(qn('w:fill'), fill_hex) pPr.append(shd) # ---------------------------------------------------------------- # Helper: add a coloured heading bar # ---------------------------------------------------------------- def add_section_header(doc, text, bg_hex, fg_hex='FFFFFF'): p = doc.add_paragraph() p.paragraph_format.space_before = Pt(10) p.paragraph_format.space_after = Pt(4) run = p.add_run(f' {text}') run.bold = True run.font.size = Pt(11) run.font.color.rgb = RGBColor.from_string(fg_hex) shade_paragraph(p, bg_hex) return p # ---------------------------------------------------------------- # Helper: bullet line # ---------------------------------------------------------------- def add_bullet(doc, text, indent=0, bold_prefix=None): p = doc.add_paragraph(style='Normal') p.paragraph_format.left_indent = Inches(0.3 + indent * 0.25) p.paragraph_format.space_before = Pt(1) p.paragraph_format.space_after = Pt(1) r = p.add_run('• ') r.font.color.rgb = RGBColor(0x1A, 0x73, 0xE8) if bold_prefix: rb = p.add_run(bold_prefix) rb.bold = True p.add_run(text) return p # ---------------------------------------------------------------- # Helper: simple table # ---------------------------------------------------------------- def add_table(doc, headers, rows, col_widths_cm=None): table = doc.add_table(rows=1, cols=len(headers)) table.style = 'Table Grid' hdr_row = table.rows[0] for i, h in enumerate(headers): cell = hdr_row.cells[i] cell.text = h cell.paragraphs[0].runs[0].bold = True cell.paragraphs[0].runs[0].font.size = Pt(10) cell.paragraphs[0].runs[0].font.color.rgb = RGBColor(0xFF, 0xFF, 0xFF) tc = cell._tc tcPr = tc.get_or_add_tcPr() shd = OxmlElement('w:shd') shd.set(qn('w:val'), 'clear') shd.set(qn('w:color'), 'auto') shd.set(qn('w:fill'), '1A4F91') tcPr.append(shd) alt = False for row_data in rows: row = table.add_row() for i, val in enumerate(row_data): cell = row.cells[i] cell.text = str(val) cell.paragraphs[0].runs[0].font.size = Pt(10) if alt: tc = cell._tc tcPr = tc.get_or_add_tcPr() shd = OxmlElement('w:shd') shd.set(qn('w:val'), 'clear') shd.set(qn('w:color'), 'auto') shd.set(qn('w:fill'), 'EBF2FF') tcPr.append(shd) alt = not alt if col_widths_cm: for i, w in enumerate(col_widths_cm): for row in table.rows: row.cells[i].width = Cm(w) return table # ================================================================ # HEADER BLOCK # ================================================================ # Clinic header bar p_hdr = doc.add_paragraph() p_hdr.paragraph_format.space_before = Pt(0) p_hdr.paragraph_format.space_after = Pt(0) shade_paragraph(p_hdr, '1A4F91') r = p_hdr.add_run(' PATIENT TREATMENT SUMMARY') r.bold = True r.font.size = Pt(16) r.font.color.rgb = RGBColor(0xFF, 0xFF, 0xFF) p_sub = doc.add_paragraph() p_sub.paragraph_format.space_before = Pt(0) p_sub.paragraph_format.space_after = Pt(6) shade_paragraph(p_sub, '2C6BC0') r2 = p_sub.add_run(' Based on Blood Work | Dr. Lal PathLabs | Lab No. 502747894') r2.font.size = Pt(10) r2.font.color.rgb = RGBColor(0xE0, 0xF0, 0xFF) # Patient info table doc.add_paragraph() info_table = doc.add_table(rows=2, cols=4) info_table.style = 'Table Grid' info_data = [ ['Patient Name', 'Mr. Bajarang Lal', 'Age / Gender', '27 Years / Male'], ['Sample Collected', '31 July 2026', 'Report Date', '1 August 2026'], ] for ri, row_data in enumerate(info_data): row = info_table.rows[ri] for ci, val in enumerate(row_data): cell = row.cells[ci] cell.text = val run = cell.paragraphs[0].runs[0] run.font.size = Pt(10) if ci % 2 == 0: # label columns run.bold = True run.font.color.rgb = RGBColor(0x1A, 0x4F, 0x91) tc = cell._tc tcPr = tc.get_or_add_tcPr() shd = OxmlElement('w:shd') shd.set(qn('w:val'), 'clear') shd.set(qn('w:color'), 'auto') shd.set(qn('w:fill'), 'D6E4F7') tcPr.append(shd) doc.add_paragraph() # ================================================================ # SECTION 1 - OVERALL HEALTH SNAPSHOT # ================================================================ add_section_header(doc, '1. OVERALL HEALTH SNAPSHOT', '1A4F91') snap_headers = ['Test Area', 'Result', 'Status'] snap_rows = [ ['Kidney Function (GFR)', '123 mL/min/1.73m²', '✓ Excellent'], ['Liver Enzymes (AST/ALT)', 'AST 25.7 / ALT 15.1 U/L', '✓ Normal'], ['Blood Sugar (HbA1c)', '4.2%', '✓ Non-Diabetic'], ['Thyroid (TSH)', '2.65 µIU/mL', '✓ Normal'], ['Cholesterol (Total)', '112 mg/dL', '✓ Excellent'], ['Blood Count (Hemoglobin)', '14.5 g/dL', '✓ Normal'], ['Inflammation (hsCRP)', '0.08 mg/L', '✓ Very Low Risk'], ['Urine Routine', 'No abnormality', '✓ Normal'], ['Vitamin D', '29.31 nmol/L', '⚠ DEFICIENT'], ['Vitamin B12', '202.10 pg/mL', '⚠ Low / Borderline'], ['Bilirubin (Total)', '2.13 mg/dL (indirect dominant)', 'ℹ Likely Gilbert Syndrome'], ] add_table(doc, snap_headers, snap_rows, col_widths_cm=[6.5, 6.5, 4.5]) # ================================================================ # SECTION 2 - CONDITIONS REQUIRING ATTENTION # ================================================================ doc.add_paragraph() add_section_header(doc, '2. CONDITIONS REQUIRING ATTENTION', '1A4F91') # --- 2A: Vitamin D --- add_section_header(doc, 'A. Vitamin D Deficiency (Severe)', 'C0392B', 'FFFFFF') p = doc.add_paragraph() p.add_run('Your Vitamin D level: ').bold = False r = p.add_run('29.31 nmol/L') r.bold = True r.font.color.rgb = RGBColor(0xC0, 0x39, 0x2B) p.add_run(' | Normal range: 75-250 nmol/L') p.paragraph_format.space_after = Pt(4) add_bullet(doc, 'Vitamin D helps your body absorb calcium, keeps your bones and muscles strong, and supports your immune system.', bold_prefix='What this means: ') add_bullet(doc, 'Bone/muscle aches, fatigue, general tiredness, weakness in thighs/upper arms, low mood.', bold_prefix='Possible symptoms: ') p2 = doc.add_paragraph() p2.add_run(' What to do:').bold = True p2.paragraph_format.space_before = Pt(6) add_bullet(doc, 'Cholecalciferol (Vitamin D3) 60,000 IU tablet - take ONE tablet every week for 8 weeks.', bold_prefix='Supplement: ', indent=1) add_bullet(doc, 'Calcium supplement 500 mg daily with meals (calcium citrate or carbonate).', bold_prefix='Calcium: ', indent=1) add_bullet(doc, 'Get 15-20 minutes of direct morning sunlight (arms and face exposed) at least 4 days per week.', bold_prefix='Sunlight: ', indent=1) add_bullet(doc, 'Eat more fatty fish (salmon, mackerel), eggs, and fortified milk/cereals.', bold_prefix='Diet: ', indent=1) add_bullet(doc, 'Repeat Vitamin D blood test after 3 months to check progress.', bold_prefix='Follow-up: ', indent=1) # --- 2B: Vitamin B12 --- doc.add_paragraph() add_section_header(doc, 'B. Vitamin B12 - Borderline Low', 'E67E22', 'FFFFFF') p = doc.add_paragraph() p.add_run('Your B12 level: ').bold = False r = p.add_run('202.10 pg/mL') r.bold = True r.font.color.rgb = RGBColor(0xE6, 0x7E, 0x22) p.add_run(' | Normal range: 211-946 pg/mL') p.paragraph_format.space_after = Pt(4) add_bullet(doc, 'B12 is needed for healthy nerves, red blood cells, and brain function.', bold_prefix='What this means: ') add_bullet(doc, 'Fatigue, tingling/numbness in hands or feet, difficulty concentrating, mild forgetfulness.', bold_prefix='Possible symptoms: ') p3 = doc.add_paragraph() p3.add_run(' What to do:').bold = True p3.paragraph_format.space_before = Pt(6) add_bullet(doc, 'Methylcobalamin (B12) 1,500 mcg tablet - take ONE tablet daily for 3 months.', bold_prefix='Supplement: ', indent=1) add_bullet(doc, 'Eat meat, eggs, dairy (paneer, milk, curd), and fish regularly. If vegetarian, fortified foods are essential.', bold_prefix='Diet: ', indent=1) add_bullet(doc, 'Confirm deficiency with Serum MMA (Methylmalonic Acid) or Homocysteine test.', bold_prefix='Recommended test: ', indent=1) add_bullet(doc, 'Repeat B12 level after 3 months.', bold_prefix='Follow-up: ', indent=1) # --- 2C: Gilbert Syndrome --- doc.add_paragraph() add_section_header(doc, 'C. Mildly Elevated Bilirubin - Likely Gilbert Syndrome', '27AE60', 'FFFFFF') p = doc.add_paragraph() p.add_run('Your Total Bilirubin: ').bold = False r = p.add_run('2.13 mg/dL') r.bold = True r.font.color.rgb = RGBColor(0x27, 0xAE, 0x60) p.add_run(' | Indirect bilirubin is elevated; all liver enzymes are completely normal.') p.paragraph_format.space_after = Pt(4) add_bullet(doc, "Gilbert Syndrome is a common, harmless genetic condition (affects ~5% of people) where the liver processes a pigment called bilirubin slightly more slowly. It is NOT a liver disease.", bold_prefix='What this means: ') add_bullet(doc, 'No treatment is needed. This condition does not damage your liver or affect your health.', bold_prefix='Action required: ') add_bullet(doc, 'Bilirubin may rise temporarily during fasting, stress, illness, or intense exercise - this is normal for you.', bold_prefix='Important to know: ') add_bullet(doc, 'No dietary restrictions. No medications. No follow-up tests required for this finding alone.', bold_prefix='Lifestyle: ') # ================================================================ # SECTION 3 - YOUR MEDICINES / SUPPLEMENTS # ================================================================ doc.add_paragraph() add_section_header(doc, '3. PRESCRIBED SUPPLEMENTS', '1A4F91') med_headers = ['Supplement', 'Dose', 'Frequency', 'Duration', 'Purpose'] med_rows = [ ['Vitamin D3 (Cholecalciferol)', '60,000 IU', 'Once a week', '8 weeks', 'Correct Vitamin D deficiency'], ['Calcium (Citrate/Carbonate)', '500 mg', 'Once daily with meal', 'Ongoing', 'Support bone health with Vit D'], ['Methylcobalamin (B12)', '1,500 mcg', 'Once daily', '3 months', 'Correct B12 deficiency'], ] add_table(doc, med_headers, med_rows, col_widths_cm=[4.5, 2.5, 3.5, 2.5, 4.5]) p_note = doc.add_paragraph() p_note.paragraph_format.space_before = Pt(6) r_note = p_note.add_run('⚕ Note: Do not self-medicate. Take these supplements only as advised by your doctor. Doses may be adjusted after follow-up tests.') r_note.italic = True r_note.font.size = Pt(9.5) r_note.font.color.rgb = RGBColor(0x55, 0x55, 0x55) # ================================================================ # SECTION 4 - TESTS THAT ARE NORMAL (reassurance) # ================================================================ doc.add_paragraph() add_section_header(doc, '4. TESTS THAT ARE NORMAL - GOOD NEWS!', '1A4F91') good_data = [ ['✓ No Diabetes', 'HbA1c 4.2% - blood sugar control is excellent'], ['✓ No Thyroid Problem', 'TSH 2.65 - thyroid is working perfectly'], ['✓ No Anaemia', 'Haemoglobin 14.5 g/dL - healthy blood count'], ['✓ Excellent Cholesterol', 'Total cholesterol 112, LDL 67, HDL 55 - heart-healthy profile'], ['✓ Kidneys are Healthy', 'GFR 123 - kidneys are working at full capacity'], ['✓ No Inflammation', 'CRP 0.08 mg/L - very low cardiovascular risk'], ['✓ Urine is Clear', 'No infection, no protein, no sugar in urine'], ['✓ Thyroid Normal', 'fT3, fT4, TSH all within normal range'], ] good_table = doc.add_table(rows=1, cols=2) good_table.style = 'Table Grid' hrow = good_table.rows[0] for ci, hdr in enumerate(['Finding', 'Details']): hrow.cells[ci].text = hdr hrow.cells[ci].paragraphs[0].runs[0].bold = True hrow.cells[ci].paragraphs[0].runs[0].font.color.rgb = RGBColor(0xFF,0xFF,0xFF) hrow.cells[ci].paragraphs[0].runs[0].font.size = Pt(10) tc = hrow.cells[ci]._tc tcPr = tc.get_or_add_tcPr() shd = OxmlElement('w:shd') shd.set(qn('w:val'), 'clear'); shd.set(qn('w:color'), 'auto'); shd.set(qn('w:fill'), '1A4F91') tcPr.append(shd) alt = False for row_data in good_data: row = good_table.add_row() for ci, val in enumerate(row_data): cell = row.cells[ci] cell.text = val run = cell.paragraphs[0].runs[0] run.font.size = Pt(10) if ci == 0: run.bold = True run.font.color.rgb = RGBColor(0x1E, 0x8B, 0x4C) if alt: tc = cell._tc tcPr = tc.get_or_add_tcPr() shd = OxmlElement('w:shd') shd.set(qn('w:val'), 'clear'); shd.set(qn('w:color'), 'auto'); shd.set(qn('w:fill'), 'EBF7EE') tcPr.append(shd) alt = not alt for row in good_table.rows: row.cells[0].width = Cm(5) row.cells[1].width = Cm(12.5) # ================================================================ # SECTION 5 - FOLLOW-UP PLAN # ================================================================ doc.add_paragraph() add_section_header(doc, '5. FOLLOW-UP PLAN', '1A4F91') fu_headers = ['When', 'What to Do'] fu_rows = [ ['Now (within 1 week)', 'Start Vitamin D3 60,000 IU weekly + Calcium 500 mg daily + Methylcobalamin 1,500 mcg daily'], ['Within 2 weeks', 'Get Serum MMA / Homocysteine test to confirm B12 deficiency level'], ['After 3 months', 'Repeat: Vitamin D (25-OH), Vitamin B12 blood tests'], ['Optional (if symptoms)', 'H. pylori stool antigen test if you have acidity, bloating, or gastric symptoms'], ['1 year later', 'Full health check (lipid profile, apolipoproteins, general blood work)'], ] add_table(doc, fu_headers, fu_rows, col_widths_cm=[4.5, 13]) # ================================================================ # SECTION 6 - LIFESTYLE ADVICE # ================================================================ doc.add_paragraph() add_section_header(doc, '6. LIFESTYLE RECOMMENDATIONS', '1A4F91') add_bullet(doc, 'Get at least 15-20 minutes of morning sunlight daily (before 10 AM or after 4 PM for gradual exposure). Expose arms, face, and legs.', bold_prefix='Sunlight for Vitamin D: ') add_bullet(doc, 'Include eggs, milk, curd, paneer, fish, and chicken (if non-vegetarian) regularly. These are rich in both B12 and protein.', bold_prefix='Balanced Diet: ') add_bullet(doc, 'Drink 2-3 litres of water daily. Your kidneys are healthy - keep them that way.', bold_prefix='Hydration: ') add_bullet(doc, 'Your cholesterol and blood sugar are excellent. Maintain a low-sugar, low-saturated fat diet to keep them that way.', bold_prefix='Heart Health: ') add_bullet(doc, 'Regular moderate exercise (30 min/day of walking, yoga, or light gym) will improve Vitamin D utilization and overall wellbeing.', bold_prefix='Exercise: ') add_bullet(doc, 'Avoid skipping meals. Your bilirubin (Gilbert Syndrome) can temporarily rise with fasting - this is harmless but avoidable.', bold_prefix='Eating Regularly: ') # ================================================================ # FOOTER # ================================================================ doc.add_paragraph() p_disc = doc.add_paragraph() shade_paragraph(p_disc, 'F0F4FA') p_disc.paragraph_format.space_before = Pt(8) p_disc.paragraph_format.space_after = Pt(0) r_disc = p_disc.add_run( ' IMPORTANT: This summary is based on your blood test results dated 31 July 2026. ' 'It is not a substitute for professional medical advice. Please share this document with ' 'your doctor before starting any medication or supplement. All treatment decisions must be ' 'confirmed by a qualified physician.' ) r_disc.italic = True r_disc.font.size = Pt(8.5) r_disc.font.color.rgb = RGBColor(0x55, 0x55, 0x55) p_gen = doc.add_paragraph() shade_paragraph(p_gen, 'F0F4FA') p_gen.paragraph_format.space_before = Pt(2) r_gen = p_gen.add_run(f' Generated: {datetime.date.today().strftime("%d %B %Y")} | Report Reference: Lab No. 502747894 | Dr. Lal PathLabs, Jodhpur') r_gen.font.size = Pt(8.5) r_gen.font.color.rgb = RGBColor(0x88, 0x88, 0x88) # Save out_path = '/tmp/workspace/bajarang-lal-report/Bajarang_Lal_Treatment_Summary.docx' doc.save(out_path) print(f'Saved: {out_path}') EOF
python3 -c " from docx import Document doc = Document('/tmp/workspace/bajarang-lal-report/Bajarang_Lal_Treatment_Summary.docx') print('Pages check - paragraphs:', len(doc.paragraphs)) for p in doc.paragraphs[:10]: if p.text.strip(): print(repr(p.text[:80])) print('Tables:', len(doc.tables)) for i, t in enumerate(doc.tables): print(f' Table {i+1}: {len(t.rows)} rows x {len(t.columns)} cols') import os size = os.path.getsize('/tmp/workspace/bajarang-lal-report/Bajarang_Lal_Treatment_Summary.docx') print(f'File size: {size/1024:.1f} KB') "
Bajarang Lal Treatment Summary
Word Document · DOCX
Prescribe
In word
mkdir -p /tmp/workspace/bajarang-lal-report && python3 << 'EOF' from docx import Document from docx.shared import Pt, Inches, Cm, RGBColor from docx.enum.text import WD_ALIGN_PARAGRAPH from docx.oxml.ns import qn from docx.oxml import OxmlElement import datetime doc = Document() # --- Page setup (A4) --- section = doc.sections[0] section.page_width = Inches(8.27) section.page_height = Inches(11.69) section.left_margin = Cm(1.8) section.right_margin = Cm(1.8) section.top_margin = Cm(1.5) section.bottom_margin= Cm(1.5) normal = doc.styles['Normal'] normal.font.name = 'Calibri' normal.font.size = Pt(10.5) # ── helpers ──────────────────────────────────────────────────── def shade_cell(cell, hex_color): tc = cell._tc tcPr = tc.get_or_add_tcPr() shd = OxmlElement('w:shd') shd.set(qn('w:val'), 'clear') shd.set(qn('w:color'), 'auto') shd.set(qn('w:fill'), hex_color) tcPr.append(shd) def shade_para(para, hex_color): pPr = para._p.get_or_add_pPr() shd = OxmlElement('w:shd') shd.set(qn('w:val'), 'clear') shd.set(qn('w:color'), 'auto') shd.set(qn('w:fill'), hex_color) pPr.append(shd) def set_cell_borders(table, border_color='1A4F91'): """Thin border on all cells.""" for row in table.rows: for cell in row.cells: tc = cell._tc tcPr = tc.get_or_add_tcPr() tcBorders = OxmlElement('w:tcBorders') for side in ('top','left','bottom','right','insideH','insideV'): b = OxmlElement(f'w:{side}') b.set(qn('w:val'), 'single') b.set(qn('w:sz'), '4') b.set(qn('w:space'), '0') b.set(qn('w:color'), border_color) tcBorders.append(b) tcPr.append(tcBorders) def para_spacing(p, before=0, after=3): p.paragraph_format.space_before = Pt(before) p.paragraph_format.space_after = Pt(after) # ── TOP HEADER: Clinic letterhead ────────────────────────────── p_hosp = doc.add_paragraph() para_spacing(p_hosp, 0, 0) shade_para(p_hosp, '1A4F91') r = p_hosp.add_run(' Dr. [Physician Name] | MBBS, MD | Reg. No. __________') r.bold = True; r.font.size = Pt(13); r.font.color.rgb = RGBColor(255,255,255) p_clinic = doc.add_paragraph() para_spacing(p_clinic, 0, 0) shade_para(p_clinic, '2C6BC0') r2 = p_clinic.add_run(' [Clinic / Hospital Name] | [Address, City] | Ph: [Number] | Timing: [Hours]') r2.font.size = Pt(9); r2.font.color.rgb = RGBColor(220,235,255) # ── PRESCRIPTION title ───────────────────────────────────────── doc.add_paragraph() p_rx = doc.add_paragraph() para_spacing(p_rx, 0, 2) p_rx.alignment = WD_ALIGN_PARAGRAPH.CENTER r_rx = p_rx.add_run('℞ PRESCRIPTION') r_rx.bold = True; r_rx.font.size = Pt(14); r_rx.font.color.rgb = RGBColor(26,79,145) # divider p_div = doc.add_paragraph('─' * 100) para_spacing(p_div, 0, 4) p_div.runs[0].font.color.rgb = RGBColor(180,200,230) p_div.runs[0].font.size = Pt(7) # ── PATIENT DETAILS ──────────────────────────────────────────── det = doc.add_table(rows=2, cols=6) det.style = 'Table Grid' labels = ['Patient', 'Age / Sex', 'Date', 'Lab Ref No.', 'Weight', 'Allergies'] values = ['Mr. Bajarang Lal', '27 Yrs / Male', datetime.date.today().strftime('%d/%m/%Y'), '502747894', '___ kg', 'NKDA'] for ci in range(6): lbl = det.rows[0].cells[ci]; val = det.rows[1].cells[ci] lbl.text = labels[ci]; val.text = values[ci] shade_cell(lbl, 'D6E4F7') lbl.paragraphs[0].runs[0].bold = True lbl.paragraphs[0].runs[0].font.size = Pt(8.5) lbl.paragraphs[0].runs[0].font.color.rgb = RGBColor(26,79,145) val.paragraphs[0].runs[0].font.size = Pt(10) val.paragraphs[0].runs[0].bold = (ci == 0) set_cell_borders(det) for row in det.rows: for ci, w in enumerate([4.5, 2.8, 2.5, 2.8, 2.0, 2.5]): row.cells[ci].width = Cm(w) doc.add_paragraph() # ── DIAGNOSIS ────────────────────────────────────────────────── p_dx_hdr = doc.add_paragraph() para_spacing(p_dx_hdr, 0, 2) shade_para(p_dx_hdr, 'EBF2FF') r_dx = p_dx_hdr.add_run(' DIAGNOSIS / CLINICAL FINDINGS') r_dx.bold = True; r_dx.font.size = Pt(10); r_dx.font.color.rgb = RGBColor(26,79,145) dx_table = doc.add_table(rows=4, cols=3) dx_table.style = 'Table Grid' dx_headers = ['#', 'Diagnosis', 'ICD-10 / Note'] dx_data = [ ['1', 'Vitamin D Deficiency (Severe) — 25-OH Vit D: 29.31 nmol/L', 'E55.9 | Normal: >75 nmol/L'], ['2', 'Vitamin B12 Deficiency (Borderline) — B12: 202.10 pg/mL', 'E53.8 | Normal: 211-946 pg/mL'], ['3', 'Unconjugated Hyperbilirubinemia — Gilbert Syndrome (suspected)', 'E80.4 | Benign; no Rx needed'], ] for ci, h in enumerate(dx_headers): c = dx_table.rows[0].cells[ci]; c.text = h shade_cell(c, '1A4F91') c.paragraphs[0].runs[0].bold = True; c.paragraphs[0].runs[0].font.size = Pt(9.5) c.paragraphs[0].runs[0].font.color.rgb = RGBColor(255,255,255) for ri, row_d in enumerate(dx_data): for ci, val in enumerate(row_d): c = dx_table.rows[ri+1].cells[ci]; c.text = val c.paragraphs[0].runs[0].font.size = Pt(10) if ri % 2 == 1: shade_cell(c, 'F0F5FF') set_cell_borders(dx_table) for row in dx_table.rows: row.cells[0].width = Cm(0.7) row.cells[1].width = Cm(10) row.cells[2].width = Cm(5.5) doc.add_paragraph() # ── ℞ MEDICINES ──────────────────────────────────────────────── p_rx_hdr = doc.add_paragraph() para_spacing(p_rx_hdr, 0, 2) shade_para(p_rx_hdr, 'EBF2FF') r_rx2 = p_rx_hdr.add_run(' ℞ MEDICINES & SUPPLEMENTS') r_rx2.bold = True; r_rx2.font.size = Pt(10); r_rx2.font.color.rgb = RGBColor(26,79,145) rx_table = doc.add_table(rows=1, cols=7) rx_table.style = 'Table Grid' rx_headers = ['#', 'Drug / Supplement', 'Strength', 'Form', 'Dose', 'Frequency', 'Duration'] for ci, h in enumerate(rx_headers): c = rx_table.rows[0].cells[ci]; c.text = h shade_cell(c, '1A4F91') c.paragraphs[0].runs[0].bold = True; c.paragraphs[0].runs[0].font.size = Pt(9.5) c.paragraphs[0].runs[0].font.color.rgb = RGBColor(255,255,255) rx_data = [ # (num, name, strength, form, dose, freq, duration) ('1', 'Tab. Cholecalciferol\n(Vitamin D3)', '60,000 IU', 'Tablet', '1 tablet', 'Once weekly\n(same day each week)', '8 weeks\n(Loading dose)'), ('2', 'Tab. Calcium Citrate +\nVitamin D3', '500 mg + 250 IU', 'Tablet', '1 tablet', 'Once daily\n(after meals)', 'Ongoing\n(3–6 months)'), ('3', 'Tab. Methylcobalamin\n(Vitamin B12)', '1500 mcg', 'Tablet', '1 tablet', 'Once daily\n(morning, with food)', '3 months'), ('4', 'Cap. Multivitamin\n(with B-complex, Zinc)', 'Standard', 'Capsule', '1 capsule', 'Once daily\n(after breakfast)', '1 month'), ] for ri, rd in enumerate(rx_data): row = rx_table.add_row() for ci, val in enumerate(rd): c = row.cells[ci]; c.text = val run = c.paragraphs[0].runs[0] run.font.size = Pt(10) if ci == 1: run.bold = True if ri % 2 == 1: shade_cell(c, 'EBF2FF') set_cell_borders(rx_table) col_widths = [0.6, 4.2, 2.3, 1.6, 1.6, 3.2, 2.8] for row in rx_table.rows: for ci, w in enumerate(col_widths): row.cells[ci].width = Cm(w) doc.add_paragraph() # ── ADVICE BOX ───────────────────────────────────────────────── p_adv_hdr = doc.add_paragraph() para_spacing(p_adv_hdr, 0, 2) shade_para(p_adv_hdr, 'EBF2FF') r_adv = p_adv_hdr.add_run(' GENERAL ADVICE & INSTRUCTIONS') r_adv.bold = True; r_adv.font.size = Pt(10); r_adv.font.color.rgb = RGBColor(26,79,145) advice_items = [ ('☀ Sunlight', 'Expose face, arms and legs to direct sunlight for 15-20 minutes daily, preferably before 10 AM or after 4 PM.'), ('🥛 Diet', 'Increase intake of: eggs, milk, paneer, curd, fish/chicken (if non-vegetarian), fortified cereals. Avoid prolonged fasting.'), ('💧 Hydration', 'Drink at least 2.5-3 litres of water per day. Kidney function is excellent — maintain it.'), ('🏃 Exercise', '30 minutes of moderate activity (walking, yoga, cycling) at least 5 days/week.'), ('ℹ Bilirubin', 'Elevated bilirubin is likely Gilbert Syndrome — a harmless genetic variation. No treatment needed. Avoid prolonged fasting as it may temporarily raise bilirubin.'), ('✅ Reassurance', 'Blood sugar, thyroid, cholesterol, kidneys, blood count, and urine are all NORMAL. Cardiovascular risk is very low.'), ] adv_table = doc.add_table(rows=len(advice_items), cols=2) adv_table.style = 'Table Grid' for ri, (label, text) in enumerate(advice_items): c0 = adv_table.rows[ri].cells[0]; c1 = adv_table.rows[ri].cells[1] c0.text = label; c1.text = text c0.paragraphs[0].runs[0].bold = True c0.paragraphs[0].runs[0].font.size = Pt(9.5) c0.paragraphs[0].runs[0].font.color.rgb = RGBColor(26,79,145) c1.paragraphs[0].runs[0].font.size = Pt(10) shade_cell(c0, 'D6E4F7') if ri % 2 == 1: shade_cell(c1, 'F5F8FF') set_cell_borders(adv_table) for row in adv_table.rows: row.cells[0].width = Cm(3.0) row.cells[1].width = Cm(13.3) doc.add_paragraph() # ── INVESTIGATIONS ADVISED ───────────────────────────────────── p_inv_hdr = doc.add_paragraph() para_spacing(p_inv_hdr, 0, 2) shade_para(p_inv_hdr, 'EBF2FF') r_inv = p_inv_hdr.add_run(' INVESTIGATIONS ADVISED') r_inv.bold = True; r_inv.font.size = Pt(10); r_inv.font.color.rgb = RGBColor(26,79,145) inv_table = doc.add_table(rows=1, cols=3) inv_table.style = 'Table Grid' for ci, h in enumerate(['Test', 'When', 'Purpose']): c = inv_table.rows[0].cells[ci]; c.text = h shade_cell(c, '1A4F91') c.paragraphs[0].runs[0].bold = True; c.paragraphs[0].runs[0].font.size = Pt(9.5) c.paragraphs[0].runs[0].font.color.rgb = RGBColor(255,255,255) inv_data = [ ('Serum MMA (Methylmalonic Acid)\n OR Plasma Homocysteine', 'Within 1-2 weeks', 'Confirm functional B12 deficiency'), ('PTH (Parathyroid Hormone)', 'Within 2 weeks', 'Assess secondary hyperparathyroidism from Vit D deficiency'), ('Serum Ferritin', 'Within 2 weeks', 'Confirm iron stores (Transferrin saturation is borderline low-normal)'), ('25-OH Vitamin D (Repeat)', 'After 3 months', 'Check response to Vit D treatment. Target: >75 nmol/L'), ('Vitamin B12 (Repeat)', 'After 3 months', 'Check response to B12 supplementation'), ('H. pylori Stool Antigen', 'If gastric symptoms', 'Rule out H. pylori causing B12 malabsorption'), ] for ri, rd in enumerate(inv_data): row = inv_table.add_row() for ci, val in enumerate(rd): c = row.cells[ci]; c.text = val c.paragraphs[0].runs[0].font.size = Pt(10) if ci == 0: c.paragraphs[0].runs[0].bold = True if ri % 2 == 1: shade_cell(c, 'EBF2FF') set_cell_borders(inv_table) for row in inv_table.rows: row.cells[0].width = Cm(5.8) row.cells[1].width = Cm(3.2) row.cells[2].width = Cm(7.3) # ── REVIEW DATE + SIGNATURE ──────────────────────────────────── doc.add_paragraph() p_rev_table = doc.add_table(rows=1, cols=2) p_rev_table.style = 'Table Grid' # left: review cl = p_rev_table.rows[0].cells[0] shade_cell(cl, 'FFF8E1') cl.text = '' p_l = cl.paragraphs[0] r_l = p_l.add_run('REVIEW DATE: ________________________') r_l.bold = True; r_l.font.size = Pt(10.5); r_l.font.color.rgb = RGBColor(180,100,0) p_l2 = cl.add_paragraph('Next follow-up: After 3 months OR sooner if symptoms worsen') p_l2.runs[0].font.size = Pt(9); p_l2.runs[0].font.color.rgb = RGBColor(100,100,100) # right: signature cr = p_rev_table.rows[0].cells[1] shade_cell(cr, 'F0F4FF') cr.text = '' p_r1 = cr.paragraphs[0] p_r1.alignment = WD_ALIGN_PARAGRAPH.RIGHT r_r1 = p_r1.add_run('Dr. [Physician Name]') r_r1.bold = True; r_r1.font.size = Pt(11); r_r1.font.color.rgb = RGBColor(26,79,145) p_r2 = cr.add_paragraph(); p_r2.alignment = WD_ALIGN_PARAGRAPH.RIGHT p_r2.add_run('MBBS, MD | Reg. No. __________').font.size = Pt(9) p_r3 = cr.add_paragraph(); p_r3.alignment = WD_ALIGN_PARAGRAPH.RIGHT p_r3.add_run('[Clinic Name, City]').font.size = Pt(9) p_r4 = cr.add_paragraph(); p_r4.alignment = WD_ALIGN_PARAGRAPH.RIGHT r_sig = p_r4.add_run('Signature & Stamp: ________________') r_sig.font.size = Pt(9.5); r_sig.font.color.rgb = RGBColor(100,100,100) set_cell_borders(p_rev_table) p_rev_table.rows[0].cells[0].width = Cm(8.5) p_rev_table.rows[0].cells[1].width = Cm(7.8) # ── FOOTER disclaimer ───────────────────────────────────────── doc.add_paragraph() p_foot = doc.add_paragraph() para_spacing(p_foot, 4, 0) shade_para(p_foot, 'F0F4FA') r_foot = p_foot.add_run( ' This prescription is valid for 30 days from the date of issue. ' 'Medicines should be taken as prescribed. Do not alter doses without consulting your doctor. ' 'Store Vitamin D tablets away from sunlight. ' 'Report any unusual symptoms immediately. ' f'| Issued: {datetime.date.today().strftime("%d %B %Y")} | Lab Ref: 502747894') r_foot.italic = True; r_foot.font.size = Pt(8); r_foot.font.color.rgb = RGBColor(100,100,100) # save out_path = '/tmp/workspace/bajarang-lal-report/Bajarang_Lal_Prescription.docx' doc.save(out_path) import os print(f'Saved: {out_path} ({os.path.getsize(out_path)//1024} KB)') EOF
Bajarang Lal Prescription
Word Document · DOCX
| # | Drug | Dose | Frequency | Duration |
|---|---|---|---|---|
| 1 | Tab. Cholecalciferol (Vit D3) 60,000 IU | 1 tab | Once weekly | 8 weeks (loading) |
| 2 | Tab. Calcium Citrate + Vit D3 500 mg | 1 tab | Once daily after meals | 3-6 months |
| 3 | Tab. Methylcobalamin (B12) 1500 mcg | 1 tab | Once daily (morning) | 3 months |
| 4 | Cap. Multivitamin with B-complex | 1 cap | Once daily after breakfast | 1 month |
Fill in the highlighted placeholder fields (doctor name, reg. no., clinic details, weight) before printing.