I have to make a medical certificate for Krishna Vishwakarma 20 year old male who has come for a routine checkup
mkdir -p /tmp/workspace/medical-certificate && ls -la /tmp/workspace/
~/medical-certificate/create_certificate.py
from docx import Document
from docx.shared import Pt, Inches, RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.enum.table import WD_TABLE_ALIGNMENT
from datetime import date
doc = Document()
# Default font
style = doc.styles["Normal"]
style.font.name = "Arial"
style.font.size = Pt(11)
# Set margins
sections = doc.sections
for section in sections:
section.top_margin = Inches(0.8)
section.bottom_margin = Inches(0.8)
section.left_margin = Inches(1)
section.right_margin = Inches(1)
# ---- Letterhead placeholders ----
clinic_name = doc.add_paragraph()
clinic_name.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = clinic_name.add_run("[CLINIC / HOSPITAL NAME]")
run.bold = True
run.font.size = Pt(16)
run.font.color.rgb = RGBColor(0x1F, 0x4E, 0x79)
addr = doc.add_paragraph()
addr.alignment = WD_ALIGN_PARAGRAPH.CENTER
r = addr.add_run("[Clinic Address, City, State, PIN] | Phone: [Phone Number] | Reg. No.: [Clinic Registration No.]")
r.font.size = Pt(9)
r.italic = True
# Horizontal rule (simple line using border paragraph)
line = doc.add_paragraph()
line.paragraph_format.space_after = Pt(2)
pPr = line._p.get_or_add_pPr()
from docx.oxml.ns import qn
from docx.oxml import OxmlElement
pBdr = OxmlElement('w:pBdr')
bottom = OxmlElement('w:bottom')
bottom.set(qn('w:val'), 'single')
bottom.set(qn('w:sz'), '12')
bottom.set(qn('w:space'), '1')
bottom.set(qn('w:color'), '1F4E79')
pBdr.append(bottom)
pPr.append(pBdr)
doc.add_paragraph()
# ---- Title ----
title = doc.add_paragraph()
title.alignment = WD_ALIGN_PARAGRAPH.CENTER
t = title.add_run("MEDICAL CERTIFICATE")
t.bold = True
t.underline = True
t.font.size = Pt(14)
doc.add_paragraph()
# ---- Certificate No. and Date ----
meta = doc.add_paragraph()
meta.alignment = WD_ALIGN_PARAGRAPH.RIGHT
meta_run = meta.add_run(f"Certificate No.: [Certificate No.]\nDate: {date.today().strftime('%d-%m-%Y')}")
meta_run.font.size = Pt(10)
doc.add_paragraph()
# ---- Body text ----
body1 = doc.add_paragraph()
body1.add_run(
"This is to certify that I have physically examined Mr. Krishna Vishwakarma, "
"20-year-old Male, who presented on the above date for a routine health checkup."
).font.size = Pt(11)
body1.paragraph_format.line_spacing = 1.5
# ---- Patient details table ----
doc.add_paragraph()
table = doc.add_table(rows=5, cols=2)
table.alignment = WD_TABLE_ALIGNMENT.CENTER
table.style = 'Table Grid'
data = [
("Patient Name", "Krishna Vishwakarma"),
("Age / Sex", "20 Years / Male"),
("Date of Examination", date.today().strftime('%d-%m-%Y')),
("Purpose of Examination", "Routine Health Checkup"),
("Address / Contact No.", "[Patient Address / Contact Number]"),
]
for i, (label, value) in enumerate(data):
row = table.rows[i]
row.cells[0].text = label
row.cells[1].text = value
row.cells[0].paragraphs[0].runs[0].bold = True
for cell in row.cells:
for p in cell.paragraphs:
for r in p.runs:
r.font.size = Pt(10.5)
row.cells[0].width = Inches(2.2)
row.cells[1].width = Inches(3.8)
doc.add_paragraph()
# ---- Examination findings ----
findings_heading = doc.add_paragraph()
fh = findings_heading.add_run("Examination Findings:")
fh.bold = True
fh.font.size = Pt(11)
findings_table = doc.add_table(rows=6, cols=2)
findings_table.style = 'Table Grid'
findings_data = [
("General Condition", "Well-nourished, well-hydrated, no acute distress"),
("Vital Signs", "Within normal limits (BP, Pulse, Temperature, Respiratory Rate)"),
("Systemic Examination", "No abnormality detected (CVS, RS, P/A, CNS)"),
("Height / Weight", "[___ cm] / [___ kg]"),
("Relevant Investigations", "[None advised / As attached]"),
("Remarks", "No significant abnormality detected on this routine checkup"),
]
for i, (label, value) in enumerate(findings_data):
row = findings_table.rows[i]
row.cells[0].text = label
row.cells[1].text = value
row.cells[0].paragraphs[0].runs[0].bold = True
for cell in row.cells:
for p in cell.paragraphs:
for r in p.runs:
r.font.size = Pt(10.5)
row.cells[0].width = Inches(2.2)
row.cells[1].width = Inches(3.8)
doc.add_paragraph()
# ---- Conclusion ----
conclusion = doc.add_paragraph()
conclusion.add_run(
"Based on the above examination, Mr. Krishna Vishwakarma is found to be in good general health "
"at the time of this routine checkup. This certificate is issued upon the request of the patient "
"for record purposes."
).font.size = Pt(11)
conclusion.paragraph_format.line_spacing = 1.5
doc.add_paragraph()
doc.add_paragraph()
# ---- Signature block ----
sig_table = doc.add_table(rows=1, cols=2)
sig_table.autofit = True
left_cell = sig_table.rows[0].cells[0]
right_cell = sig_table.rows[0].cells[1]
left_cell.text = ""
right_para = right_cell.paragraphs[0]
right_para.alignment = WD_ALIGN_PARAGRAPH.RIGHT
right_para.add_run("_______________________________\n").font.size = Pt(10)
r2 = right_para.add_run("Dr. [Doctor's Full Name]\n")
r2.bold = True
r2.font.size = Pt(11)
right_para.add_run("MBBS, [Qualifications]\n").font.size = Pt(10)
right_para.add_run("Reg. No.: [Medical Council Registration No.]\n").font.size = Pt(10)
right_para.add_run("[Clinic Name], [City]").font.size = Pt(10)
doc.add_paragraph()
note = doc.add_paragraph()
note_run = note.add_run("Note: This certificate is valid only with the original signature and stamp of the examining physician.")
note_run.italic = True
note_run.font.size = Pt(8.5)
note_run.font.color.rgb = RGBColor(0x66, 0x66, 0x66)
doc.save("/tmp/workspace/medical-certificate/Medical_Certificate_Krishna_Vishwakarma.docx")
print("Saved successfully")
cd /tmp/workspace/medical-certificate && python3 create_certificate.py
ls -la /tmp/workspace/medical-certificate/
Medical Certificate Krishna Vishwakarma
Word Document · DOCX
[...]) - clinic name/address, doctor's name and registration number, patient's contact details, and any specific vitals/measurements before printing. If you want, tell me the actual doctor/clinic details and I can fill them in directly, or let me know if this is for a specific purpose (employment, travel, sports, etc.) so I can adjust the wording accordingly.