Please create a colorful pdf handbook of all these questions in English, translate to English all these list of questions.

Reading File
analyse_media
Running Command

cd "/tmp/workspace/attachments/8bfd6c04-34a1-4779-95f7-e18bcb845175/" && python3 -c " import pdfplumber with pdfplumber.open('20260527_122336 (4).pdf') as pdf: for i, page in enumerate(pdf.pages): print(f'=== PAGE {i+1} ===') text = page.extract_text() print(text) print() "

Running Command

mkdir -p /tmp/workspace/medical-handbook && ls /tmp/workspace/medical-handbook/

Writing File

~/medical-handbook/create_handbook.py

from reportlab.lib.pagesizes import A4
from reportlab.lib import colors
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import cm, mm
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, HRFlowable, Table, TableStyle, PageBreak
from reportlab.platypus import KeepTogether
from reportlab.lib.enums import TA_CENTER, TA_LEFT, TA_JUSTIFY
from reportlab.pdfgen import canvas
from reportlab.platypus.frames import Frame
from reportlab.platypus.doctemplate import PageTemplate, BaseDocTemplate
import os

# Color palette
DARK_BLUE = colors.HexColor('#1A3A5C')
MED_BLUE = colors.HexColor('#2E6DA4')
LIGHT_BLUE = colors.HexColor('#D6E8F7')
TEAL = colors.HexColor('#1B7A78')
LIGHT_TEAL = colors.HexColor('#D0EFEE')
GREEN = colors.HexColor('#2E7D32')
LIGHT_GREEN = colors.HexColor('#C8E6C9')
ORANGE = colors.HexColor('#E65100')
LIGHT_ORANGE = colors.HexColor('#FFE0B2')
PURPLE = colors.HexColor('#4A148C')
LIGHT_PURPLE = colors.HexColor('#E1BEE7')
RED = colors.HexColor('#B71C1C')
LIGHT_RED = colors.HexColor('#FFCDD2')
GOLD = colors.HexColor('#F57F17')
LIGHT_GOLD = colors.HexColor('#FFF9C4')
GRAY = colors.HexColor('#546E7A')
LIGHT_GRAY = colors.HexColor('#ECEFF1')
WHITE = colors.white

# Section color mapping
SECTION_COLORS = {
    'General': (DARK_BLUE, LIGHT_BLUE),
    'Pulmonology': (TEAL, LIGHT_TEAL),
    'Cardiology': (RED, LIGHT_RED),
    'Rheumatology': (PURPLE, LIGHT_PURPLE),
    'Gastroenterology': (GREEN, LIGHT_GREEN),
    'Nephrology': (MED_BLUE, LIGHT_BLUE),
    'Hematology & Endocrinology': (ORANGE, LIGHT_ORANGE),
    'Surgery & Vascular': (TEAL, LIGHT_TEAL),
    'Obstetrics & Gynecology': (colors.HexColor('#880E4F'), colors.HexColor('#FCE4EC')),
    'Neurology': (PURPLE, LIGHT_PURPLE),
    'Pediatrics': (GREEN, LIGHT_GREEN),
    'Urology & Oncology': (ORANGE, LIGHT_ORANGE),
    'ENT & Ophthalmology': (MED_BLUE, LIGHT_BLUE),
    'Infectious Diseases': (RED, LIGHT_RED),
    'Dermatology & STI': (colors.HexColor('#4E342E'), colors.HexColor('#EFEBE9')),
    'Pulmonary TB': (GRAY, LIGHT_GRAY),
    'Traumatology': (GOLD, LIGHT_GOLD),
    'Clinical Pharmacology': (TEAL, LIGHT_TEAL),
    'Emergency Medicine': (RED, LIGHT_RED),
    'Palliative Care': (PURPLE, LIGHT_PURPLE),
}

# All 163 questions translated to English, organized by section
SECTIONS = [
    {
        'title': 'SECTION I: General Practice Fundamentals',
        'color_key': 'General',
        'questions': [
            (1, "Ethics and deontology in the work of a general practitioner."),
            (2, "Accounting and reporting documentation in the work of a general practitioner."),
            (3, "Normative legal acts and other legislation of the Republic of Belarus regulating the activities of healthcare organizations and medical workers in the field of preserving, strengthening, and restoring the health of the population."),
        ]
    },
    {
        'title': 'SECTION II: Pulmonology',
        'color_key': 'Pulmonology',
        'questions': [
            (4, "Pneumonia: classification, clinical manifestations, diagnosis, severity criteria, treatment, clinical follow-up, tactics of the general practitioner."),
            (5, "Bronchial asthma: classification, clinical manifestations, diagnosis, severity levels, treatment, clinical follow-up, tactics of the general practitioner."),
            (6, "Chronic obstructive pulmonary disease (COPD): classification, clinical manifestations, diagnosis, severity levels, treatment, clinical follow-up, tactics of the general practitioner."),
        ]
    },
    {
        'title': 'SECTION III: Cardiology',
        'color_key': 'Cardiology',
        'questions': [
            (7, "Ischemic heart disease – angina pectoris: classification, clinical manifestations, diagnosis, treatment and prevention in the outpatient setting of a general practitioner, medical rehabilitation, clinical follow-up."),
            (8, "Acute coronary syndrome: clinical manifestations, diagnosis, tactics of the general practitioner in providing pre-hospital medical care."),
            (9, "Acute coronary syndrome without ST-segment elevation: clinical manifestations, diagnosis, patient management tactics, risk assessment, prognosis evaluation, clinical follow-up, tactics of the general practitioner."),
            (10, "Acute coronary syndrome with ST-segment elevation: clinical manifestations, laboratory and instrumental diagnostics, atypical forms, tactics of the general practitioner in providing pre-hospital medical care, clinical follow-up."),
            (11, "Medical rehabilitation of patients with myocardial infarction, secondary prevention in outpatient settings, clinical follow-up."),
            (12, "Arterial hypertension: classification, clinical manifestations, diagnosis of target organ damage, risk stratification and prognosis of complications."),
            (13, "Arterial hypertension: treatment, prevention in the outpatient setting of a general practitioner."),
            (14, "Symptomatic hypertensions: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (15, "Myocarditis: clinical manifestations, diagnosis, treatment, tactics of the general practitioner."),
            (16, "Diagnosis, treatment, and prevention of dyslipidemia."),
            (17, "Sudden coronary death: risk factors, clinical manifestations, diagnosis, resuscitation measures, prevention."),
            (18, "Arterial hypertension in pregnant women: features of treatment."),
            (19, "Hypertensive crises: diagnostic criteria, management of complicated and uncomplicated hypertensive crises."),
            (20, "Pulmonary artery thromboembolism: clinical manifestations, diagnosis, differential diagnosis, treatment, prognosis."),
            (21, "Supraventricular paroxysmal tachycardia: clinical manifestations, ECG diagnosis, relief of paroxysms, indications for electrical pulse therapy, indications for surgical treatment, prevention of paroxysms."),
            (22, "Atrial fibrillation and flutter: clinical manifestations, diagnosis, ECG diagnosis, patient management strategies, treatment, indications for electrical pulse therapy and defibrillator implantation, treatment of patients after restoration of sinus rhythm, prognosis."),
            (23, "Atrial fibrillation: indications for anticoagulant therapy, stroke risk and bleeding risk assessment scales."),
            (24, "Hypertrophic cardiomyopathy: pathogenesis, risk factors, classification, diagnosis, treatment, indications for surgical treatment."),
            (25, "Dilated cardiomyopathy: pathogenesis, risk factors, classification, diagnosis, treatment, indications for heart transplantation."),
            (26, "Pericarditis: etiology, classification, clinical manifestations, diagnosis of various pericarditis variants, treatment, indications for pericardial puncture, indications and types of surgical treatment."),
            (27, "Acquired heart defects (mitral valve insufficiency, mitral stenosis): pathogenesis of hemodynamic disturbances, course, complications, therapeutic tactics, indications for surgical treatment, prognosis."),
            (28, "Acquired heart defects (aortic valve insufficiency, aortic orifice stenosis): pathogenesis of hemodynamic disturbances, course, complications, therapeutic tactics, indications for surgical treatment, prognosis."),
            (29, "Infective endocarditis: clinical manifestations, diagnosis, diagnostic criteria, antibacterial treatment tactics, indications for surgical treatment, prevention of relapses, prognosis."),
            (30, "Coronary angiography: indications and contraindications, interpretation of results."),
            (31, "Revascularization in patients with stable angina pectoris: patient management after revascularization."),
            (32, "Invasive treatment strategy for patients with acute coronary syndrome: timing of reperfusion therapy, patient management after revascularization."),
            (33, "Types of cardiac pacing, indications, nomenclature of implantable pacemakers, complications."),
            (34, "Main groups of syncope, examination program, emergency medical care for syncope, prevention."),
            (35, "Concept of cardiovascular disease risk factors, prevention strategies, assessment of overall cardiovascular risk from an evidence-based medicine perspective, preventive counseling."),
        ]
    },
    {
        'title': 'SECTION IV: Rheumatology',
        'color_key': 'Rheumatology',
        'questions': [
            (36, "Rheumatoid arthritis: classification, clinical manifestations, diagnosis, principles of treatment, clinical follow-up, tactics of the general practitioner."),
            (37, "Osteoarthritis and gout: clinical manifestations, diagnosis, principles of treatment, clinical follow-up, tactics of the general practitioner."),
            (38, "Systemic lupus erythematosus: classification, clinical manifestations, diagnosis, principles of treatment, clinical follow-up, tactics of the general practitioner."),
        ]
    },
    {
        'title': 'SECTION V: Gastroenterology',
        'color_key': 'Gastroenterology',
        'questions': [
            (39, "Gastric and duodenal ulcer: classification, clinical manifestations, diagnosis, complications, principles of treatment, clinical follow-up, tactics of the general practitioner."),
            (40, "Nonspecific ulcerative colitis: classification, clinical manifestations, diagnosis, principles of treatment, clinical follow-up, tactics of the general practitioner."),
            (41, "Chronic hepatitis: classification, clinical manifestations, diagnosis, principles of treatment, clinical follow-up, tactics of the general practitioner."),
            (42, "Liver cirrhosis: classification, clinical manifestations, diagnosis, principles of treatment, clinical follow-up, tactics of the general practitioner."),
        ]
    },
    {
        'title': 'SECTION VI: Nephrology',
        'color_key': 'Nephrology',
        'questions': [
            (43, "Acute glomerulonephritis: classification, clinical manifestations, diagnosis, principles of treatment, clinical follow-up, tactics of the general practitioner."),
            (44, "Acute and chronic pyelonephritis: classification, clinical manifestations, diagnosis, principles of treatment, clinical follow-up, tactics of the general practitioner."),
            (45, "Chronic kidney disease: classification, clinical manifestations, diagnosis, principles of treatment, clinical follow-up, tactics of the general practitioner."),
        ]
    },
    {
        'title': 'SECTION VII: Hematology & Endocrinology',
        'color_key': 'Hematology & Endocrinology',
        'questions': [
            (46, "Anemias: classification, clinical manifestations, diagnosis, principles of treatment, clinical follow-up, tactics of the general practitioner."),
            (47, "Diabetes mellitus: classification, clinical manifestations, diagnosis, principles of treatment, clinical follow-up, tactics of the general practitioner."),
            (48, "Thyroid gland diseases: classification, clinical manifestations, diagnosis, principles of treatment, clinical follow-up, tactics of the general practitioner."),
        ]
    },
    {
        'title': 'SECTION VIII: Surgery & Vascular Medicine',
        'color_key': 'Surgery & Vascular',
        'questions': [
            (49, "Strangulated hernia: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (50, "Acute appendicitis: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (51, "Acute cholecystitis: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (52, "Acute pancreatitis: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (53, "Acute abdominal diseases: clinical manifestations, differential diagnosis, tactics of the general practitioner."),
            (54, "Abdominal trauma: clinical manifestations, diagnosis, emergency medical care and tactics of the general practitioner."),
            (55, "Chest injuries: clinical manifestations, diagnosis, emergency medical care and tactics of the general practitioner."),
            (56, "Thrombophlebitis of superficial and deep veins of the lower extremities: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (57, "Obliterating atherosclerosis and endarteritis of the lower extremity vessels: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (58, "Inflammatory diseases of the skin and subcutaneous tissue (furuncle, carbuncle, hidradenitis, abscess, phlegmon): clinical manifestations, diagnosis, tactics of the general practitioner."),
            (59, "Purulent diseases of the hand (panaritium, phlegmon): clinical manifestations, diagnosis, tactics of the general practitioner."),
            (60, "Acute proctitis and paraproctitis, hemorrhoids, anal fissures: clinical manifestations, diagnosis, tactics of the general practitioner."),
        ]
    },
    {
        'title': 'SECTION IX: Obstetrics & Gynecology',
        'color_key': 'Obstetrics & Gynecology',
        'questions': [
            (61, "Family planning, prevention of unplanned pregnancy, role of the general practitioner in family planning."),
            (62, "Climacterium, premenopause, menopause, postmenopause: prevention of pathology of the climacteric period and osteoporosis."),
            (63, "Modern methods of pregnancy diagnosis."),
            (64, "Physiology of pregnancy."),
            (65, "Pathology of the first half of pregnancy: clinical manifestations, treatment, prevention."),
            (66, "Preeclampsia and eclampsia: clinical manifestations, diagnosis, treatment, emergency medical care, tactics of the general practitioner."),
            (67, "Non-specific inflammatory diseases of the genitals: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (68, "Specific inflammatory diseases of the genitals (trichomoniasis, chlamydiosis, gonorrhea, tuberculosis of the urogenital organs): clinical manifestations, diagnosis, tactics of the general practitioner."),
            (69, "Lactational mastitis: classification, clinical manifestations, diagnosis, therapeutic tactics, prevention, indications for cessation of lactation."),
            (70, "\"Acute abdomen\" syndrome in gynecology: diagnostic and therapeutic tactics of the general practitioner."),
            (71, "Ectopic pregnancy: clinical manifestations, diagnosis, tactics of the general practitioner."),
        ]
    },
    {
        'title': 'SECTION X: Neurology',
        'color_key': 'Neurology',
        'questions': [
            (72, "Neuropathies and neuritis: etiology, pathogenesis, clinical manifestations, syndromic diagnosis at the outpatient-polyclinic stage, treatment, clinical follow-up, tactics of the general practitioner."),
            (73, "Vertebrogenic lesions of the nervous system: syndromic diagnosis, treatment, features of patient management in outpatient-polyclinic conditions, indications for hospitalization, medical rehabilitation, tactics of the general practitioner."),
            (74, "Brain concussion and contusion, intracranial hypertension syndrome: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (75, "Acute cerebrovascular accident (stroke): pathogenesis, clinical manifestations, diagnosis, tactics of the general practitioner, medical rehabilitation of patients who suffered a stroke."),
            (76, "Chronic cerebrovascular insufficiency (dyscirculatory encephalopathy, vertebrobasilar insufficiency, vascular epilepsy, atherosclerotic Parkinsonism): clinical manifestations, diagnosis, symptomatic treatment, assessment of temporary disability, tactics of the general practitioner."),
            (77, "Diseases of the autonomic nervous system: clinical manifestations, treatment, tactics of the general practitioner."),
            (78, "Parkinsonism: clinical manifestations, differential diagnosis, tactics of the general practitioner."),
            (79, "Epilepsy: clinical forms of seizures and epilepsy, diagnosis in outpatient conditions, treatment, occupational adaptation, tactics of the general practitioner."),
            (80, "Subarachnoid hemorrhage: clinical manifestations, diagnosis, tactics of the general practitioner."),
        ]
    },
    {
        'title': 'SECTION XI: Pediatrics',
        'color_key': 'Pediatrics',
        'questions': [
            (81, "Physiology and pathology of newborns."),
            (82, "Prevention and diagnosis of early health and developmental deviations in children, methods of health improvement in children."),
            (83, "Health groups and risk groups in children."),
            (84, "Diseases of the respiratory organs in children: features of clinical manifestations, diagnosis, and treatment; tactics of the general practitioner."),
            (85, "Acute respiratory viral infection and pneumonia in young children: tactics of the general practitioner."),
            (86, "Diseases of the circulatory organs in children: features of clinical manifestations, diagnosis, and treatment; tactics of the general practitioner."),
            (87, "Acute rheumatic fever in children: clinical manifestations, diagnosis, principles of treatment, tactics of the general practitioner."),
            (88, "Diseases of the esophagus, stomach, and duodenum in children: clinical manifestations, diagnosis, treatment in outpatient conditions."),
            (89, "Diseases of the liver and biliary tract in children: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (90, "Kidney diseases in children: features of clinical manifestations, diagnosis, and treatment; tactics of the general practitioner."),
            (91, "Allergic diseases in children: clinical manifestations, diagnosis, tactics of the general practitioner."),
        ]
    },
    {
        'title': 'SECTION XII: Urology & Oncology',
        'color_key': 'Urology & Oncology',
        'questions': [
            (92, "Acute inflammatory diseases of the kidneys, urinary bladder, urethra, and genitals: clinical picture, diagnosis, tactics of the general practitioner."),
            (93, "Lung cancer: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (94, "Gastric cancer: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (95, "Breast cancer: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (96, "Skin neoplasms: clinical manifestations, diagnosis, tactics of the general practitioner."),
        ]
    },
    {
        'title': 'SECTION XIII: ENT & Ophthalmology',
        'color_key': 'ENT & Ophthalmology',
        'questions': [
            (97, "Inflammatory diseases of the outer and middle ear: clinical manifestations, diagnosis, treatment, tactics of the general practitioner."),
            (98, "Diseases of the nose and paranasal sinuses: clinical manifestations, diagnosis, treatment in outpatient conditions."),
            (99, "Acute and chronic laryngitis: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (100, "Foreign bodies of the ear and upper respiratory tract: clinical manifestations, diagnosis, emergency medical care, tactics of the general practitioner."),
            (101, "Tonsillitis and chronic tonsillitis: clinical manifestations, diagnosis, treatment in outpatient conditions, tactics of the general practitioner."),
            (102, "Inflammatory diseases of the conjunctiva and cornea: clinical manifestations, tactics of the general practitioner."),
            (102, "Inflammatory diseases of the eyelids and lacrimal ducts: clinical manifestations, diagnosis, and treatment in outpatient conditions."),
            (103, "Glaucoma: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (104, "Eye trauma: tactics of the general practitioner."),
        ]
    },
    {
        'title': 'SECTION XIV: Infectious Diseases',
        'color_key': 'Infectious Diseases',
        'questions': [
            (105, "Foodborne infections: clinical manifestations, diagnostic and therapeutic tactics, prevention."),
            (106, "Salmonellosis and dysentery: clinical manifestations, diagnostic and therapeutic tactics, prevention, indications for hospitalization, clinical follow-up of convalescents, tactics of the general practitioner."),
            (107, "Acute viral hepatitis: clinical manifestations, modern approaches to diagnosis, treatment, clinical follow-up, tactics of the general practitioner."),
            (108, "Diphtheria in children and adults: clinical manifestations, diagnosis, treatment."),
            (109, "Acute infectious diseases of the brain and its membranes: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (110, "Herpetic infection: modern approaches to diagnosis and treatment, tactics of the general practitioner."),
            (111, "HIV infection, AIDS: clinical manifestations, diagnostic and therapeutic tactics, prevention, tactics of the general practitioner."),
            (112, "Diagnosis and treatment of influenza and other acute respiratory viral infections (ARVI)."),
        ]
    },
    {
        'title': 'SECTION XV: Dermatology & Sexually Transmitted Infections',
        'color_key': 'Dermatology & STI',
        'questions': [
            (113, "Clinical manifestations, diagnosis, and treatment of the most common non-infectious skin diseases (dermatitis, toxicoderma, eczema, neurodermatitis) in outpatient conditions."),
            (114, "Fungal diseases of the skin and nails: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (115, "Psoriasis: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (116, "Syphilis: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (117, "Gonorrhea and trichomoniasis: clinical manifestations, differential diagnosis, treatment, tactics of the general practitioner."),
        ]
    },
    {
        'title': 'SECTION XVI: Pulmonary Tuberculosis',
        'color_key': 'Pulmonary TB',
        'questions': [
            (118, "Clinical and laboratory diagnostic methods for suspected pulmonary tuberculosis, methods of pathological material collection."),
            (119, "Mandatory diagnostic minimum for examining a patient suspected of tuberculosis by a general practitioner when referring to a tuberculosis dispensary."),
            (120, "Formation of risk groups ('threatened contingent') for tuberculosis disease, work of the general practitioner with risk groups."),
            (121, "Sarcoidosis: clinical manifestations, diagnosis and treatment of respiratory sarcoidosis, dispensary observation, tactics of the general practitioner."),
        ]
    },
    {
        'title': 'SECTION XVII: Traumatology',
        'color_key': 'Traumatology',
        'questions': [
            (122, "Bone cracks, fractures, dislocations, bruises, sprains: clinical manifestations, diagnosis, tactics of the general practitioner."),
            (123, "Burns and frostbite: clinical manifestations, diagnosis, tactics of the general practitioner."),
        ]
    },
    {
        'title': 'SECTION XVIII: Clinical Pharmacology',
        'color_key': 'Clinical Pharmacology',
        'questions': [
            (124, "Clinical pharmacology of antibacterial drugs."),
            (125, "Clinical pharmacology of antianginal drugs."),
            (126, "Clinical pharmacology of antiarrhythmic drugs."),
            (127, "Clinical pharmacology of hypolipidemic drugs."),
            (128, "Clinical pharmacology of antihypertensive drugs."),
            (129, "Clinical pharmacology of diuretics."),
            (130, "Clinical pharmacology of thrombolytics and antiaggregants."),
            (131, "Clinical pharmacology of bronchodilators."),
            (132, "Clinical pharmacology of anti-inflammatory drugs."),
            (133, "Clinical pharmacology of glucocorticoids."),
            (134, "Clinical pharmacology of oral hypoglycemic drugs."),
            (135, "Clinical pharmacology of antisecretory drugs."),
            (136, "Clinical pharmacology of antihistamine drugs."),
            (137, "Clinical pharmacology of iron-containing drugs."),
        ]
    },
    {
        'title': 'SECTION XIX: Emergency Medicine',
        'color_key': 'Emergency Medicine',
        'questions': [
            (138, "Shock (anaphylactic, exotoxic, traumatic, hemorrhagic, cardiogenic, etc.): clinical manifestations, diagnosis, provision of medical care at the pre-hospital stage."),
            (139, "Fainting and collapse: clinical manifestations, diagnosis, provision of medical care at the pre-hospital stage."),
            (140, "Differential diagnosis of comatose states at the pre-hospital stage, provision of medical care at the pre-hospital stage."),
            (141, "Laryngeal edema, false croup: clinical manifestations, diagnosis, provision of medical care at the pre-hospital stage."),
            (142, "Quincke's edema (angioedema): clinical manifestations, diagnosis, provision of medical care at the pre-hospital stage."),
            (143, "Bronchial asthma attack: diagnosis, differential diagnosis, provision of medical care at the pre-hospital stage."),
            (144, "Open, closed, and tension pneumothorax: clinical manifestations, diagnosis, provision of medical care at the pre-hospital stage."),
            (145, "Pulmonary artery thromboembolism: clinical manifestations, diagnosis, provision of medical care at the pre-hospital stage."),
            (146, "Acute heart failure: clinical picture, diagnosis, provision of medical care at the pre-hospital stage."),
            (147, "Hypertensive crisis: clinical manifestations, diagnosis, provision of medical care at the pre-hospital stage."),
            (148, "Relief of pain syndrome in acute coronary syndrome, provision of medical care at the pre-hospital stage."),
            (149, "Sudden coronary death: provision of medical care at the pre-hospital stage."),
            (150, "Resuscitation in ventricular fibrillation: provision of medical care at the pre-hospital stage."),
            (151, "Gastrointestinal and pulmonary bleeding: clinical manifestations, diagnosis, provision of medical care at the pre-hospital stage."),
            (152, "Renal colic, acute urinary retention: clinical manifestations, diagnosis, provision of medical care at the pre-hospital stage."),
            (153, "Acute renal failure: clinical manifestations, diagnosis, provision of medical care at the pre-hospital stage."),
            (154, "Convulsive states, epileptic status: clinical manifestations, diagnosis, provision of medical care at the pre-hospital stage."),
            (155, "Alcoholic delirium, withdrawal syndrome: clinical manifestations, diagnosis, provision of medical care at the pre-hospital stage."),
            (156, "Acute glaucoma attack: clinical manifestations, diagnosis, provision of medical care at the pre-hospital stage."),
            (157, "Chemical and thermal burns, frostbite: clinical manifestations, diagnosis, provision of medical care at the pre-hospital stage."),
            (158, "Poisoning: clinical manifestations, diagnosis, provision of medical care at the pre-hospital stage."),
            (159, "Eclampsia: clinical manifestations, diagnosis, provision of medical care at the pre-hospital stage."),
            (160, "Acute cerebrovascular accident (stroke): clinical manifestations, diagnosis, provision of medical care at the pre-hospital stage."),
            (161, "Subarachnoid hemorrhage: clinical manifestations, diagnosis, provision of medical care at the pre-hospital stage."),
        ]
    },
    {
        'title': 'SECTION XX: Palliative Care',
        'color_key': 'Palliative Care',
        'questions': [
            (162, "Organization of palliative medical care in the Republic of Belarus."),
            (163, "Pharmacotherapy of chronic pain syndrome in the provision of palliative medical care in inpatient, outpatient conditions, and at home."),
        ]
    },
]

class HandbookDocTemplate(BaseDocTemplate):
    def __init__(self, filename, **kwargs):
        BaseDocTemplate.__init__(self, filename, **kwargs)
        frame = Frame(
            self.leftMargin, self.bottomMargin,
            self.width, self.height,
            id='normal'
        )
        template = PageTemplate(id='main', frames=frame, onPage=self.add_page_decorations)
        self.addPageTemplates([template])

    def add_page_decorations(self, canvas, doc):
        canvas.saveState()
        w, h = A4
        # Header bar
        canvas.setFillColor(DARK_BLUE)
        canvas.rect(0, h - 1.2*cm, w, 1.2*cm, fill=1, stroke=0)
        # Header text
        canvas.setFillColor(WHITE)
        canvas.setFont('Helvetica-Bold', 9)
        canvas.drawString(1*cm, h - 0.8*cm, "QUALIFICATION EXAMINATION HANDBOOK")
        canvas.drawRightString(w - 1*cm, h - 0.8*cm, "General Practice Medicine")
        # Footer
        canvas.setFillColor(DARK_BLUE)
        canvas.rect(0, 0, w, 0.9*cm, fill=1, stroke=0)
        canvas.setFillColor(WHITE)
        canvas.setFont('Helvetica', 8)
        canvas.drawCentredString(w/2, 0.3*cm, f"Page {doc.page}")
        canvas.drawString(1*cm, 0.3*cm, "Republic of Belarus")
        canvas.drawRightString(w - 1*cm, 0.3*cm, "General Practitioner Exam Questions")
        # Left accent bar
        canvas.setFillColor(MED_BLUE)
        canvas.rect(0, 0.9*cm, 0.3*cm, h - 2.1*cm, fill=1, stroke=0)
        canvas.restoreState()


def build_pdf():
    output_path = '/tmp/workspace/medical-handbook/GP_Qualification_Exam_Handbook.pdf'

    doc = HandbookDocTemplate(
        output_path,
        pagesize=A4,
        leftMargin=1.5*cm,
        rightMargin=1.5*cm,
        topMargin=1.8*cm,
        bottomMargin=1.5*cm,
    )

    styles = getSampleStyleSheet()

    # Custom styles
    title_style = ParagraphStyle(
        'HandbookTitle',
        parent=styles['Normal'],
        fontName='Helvetica-Bold',
        fontSize=22,
        textColor=WHITE,
        alignment=TA_CENTER,
        spaceAfter=6,
        spaceBefore=6,
    )

    subtitle_style = ParagraphStyle(
        'HandbookSubtitle',
        parent=styles['Normal'],
        fontName='Helvetica',
        fontSize=12,
        textColor=LIGHT_BLUE,
        alignment=TA_CENTER,
        spaceAfter=4,
    )

    section_style = ParagraphStyle(
        'SectionHeader',
        parent=styles['Normal'],
        fontName='Helvetica-Bold',
        fontSize=11,
        textColor=WHITE,
        alignment=TA_LEFT,
        spaceBefore=10,
        spaceAfter=4,
        leftIndent=6,
    )

    q_num_style = ParagraphStyle(
        'QuestionNumber',
        parent=styles['Normal'],
        fontName='Helvetica-Bold',
        fontSize=10,
        textColor=WHITE,
        alignment=TA_CENTER,
    )

    q_text_style = ParagraphStyle(
        'QuestionText',
        parent=styles['Normal'],
        fontName='Helvetica',
        fontSize=9.5,
        textColor=colors.HexColor('#1A1A1A'),
        alignment=TA_JUSTIFY,
        leading=14,
    )

    toc_style = ParagraphStyle(
        'TOCEntry',
        parent=styles['Normal'],
        fontName='Helvetica',
        fontSize=10,
        textColor=DARK_BLUE,
        leading=16,
    )

    story = []

    # ---- COVER PAGE ----
    story.append(Spacer(1, 3*cm))

    # Title box
    cover_data = [[Paragraph("QUALIFICATION EXAMINATION", title_style)],
                  [Paragraph("HANDBOOK", title_style)],
                  [Spacer(1, 0.3*cm)],
                  [Paragraph("General Practice Medicine", subtitle_style)],
                  [Paragraph("Republic of Belarus", subtitle_style)],
                  [Spacer(1, 0.5*cm)],
                  [Paragraph("163 Examination Questions — English Translation", ParagraphStyle(
                      'sub2', parent=styles['Normal'], fontName='Helvetica-Oblique',
                      fontSize=11, textColor=LIGHT_GOLD, alignment=TA_CENTER))],
                  ]
    cover_table = Table(cover_data, colWidths=[16*cm])
    cover_table.setStyle(TableStyle([
        ('BACKGROUND', (0,0), (-1,-1), DARK_BLUE),
        ('ROUNDEDCORNERS', [12]),
        ('TOPPADDING', (0,0), (-1,-1), 10),
        ('BOTTOMPADDING', (0,0), (-1,-1), 10),
        ('LEFTPADDING', (0,0), (-1,-1), 20),
        ('RIGHTPADDING', (0,0), (-1,-1), 20),
    ]))
    story.append(cover_table)

    story.append(Spacer(1, 1.5*cm))

    # Info box
    info_data = [
        [Paragraph("<b>Document Type:</b>", ParagraphStyle('i', parent=styles['Normal'], fontSize=10)),
         Paragraph("Qualification Exam Preparation Handbook", ParagraphStyle('i', parent=styles['Normal'], fontSize=10))],
        [Paragraph("<b>Specialty:</b>", ParagraphStyle('i', parent=styles['Normal'], fontSize=10)),
         Paragraph("General Practice / Family Medicine", ParagraphStyle('i', parent=styles['Normal'], fontSize=10))],
        [Paragraph("<b>Total Questions:</b>", ParagraphStyle('i', parent=styles['Normal'], fontSize=10)),
         Paragraph("163", ParagraphStyle('i', parent=styles['Normal'], fontSize=10))],
        [Paragraph("<b>Sections:</b>", ParagraphStyle('i', parent=styles['Normal'], fontSize=10)),
         Paragraph("20 Clinical Sections", ParagraphStyle('i', parent=styles['Normal'], fontSize=10))],
        [Paragraph("<b>Language:</b>", ParagraphStyle('i', parent=styles['Normal'], fontSize=10)),
         Paragraph("English (Translated from Russian)", ParagraphStyle('i', parent=styles['Normal'], fontSize=10))],
    ]
    info_table = Table(info_data, colWidths=[5*cm, 11*cm])
    info_table.setStyle(TableStyle([
        ('BACKGROUND', (0,0), (-1,-1), LIGHT_BLUE),
        ('BACKGROUND', (0,0), (0,-1), MED_BLUE),
        ('TEXTCOLOR', (0,0), (0,-1), WHITE),
        ('FONTNAME', (0,0), (0,-1), 'Helvetica-Bold'),
        ('GRID', (0,0), (-1,-1), 0.5, colors.white),
        ('TOPPADDING', (0,0), (-1,-1), 8),
        ('BOTTOMPADDING', (0,0), (-1,-1), 8),
        ('LEFTPADDING', (0,0), (-1,-1), 10),
        ('RIGHTPADDING', (0,0), (-1,-1), 10),
    ]))
    story.append(info_table)
    story.append(PageBreak())

    # ---- TABLE OF CONTENTS ----
    toc_title_style = ParagraphStyle(
        'TOCTitle', parent=styles['Normal'],
        fontName='Helvetica-Bold', fontSize=16,
        textColor=DARK_BLUE, alignment=TA_CENTER,
        spaceAfter=16,
    )
    story.append(Paragraph("TABLE OF CONTENTS", toc_title_style))
    story.append(HRFlowable(width='100%', thickness=2, color=DARK_BLUE, spaceAfter=12))

    for i, section in enumerate(SECTIONS):
        color, _ = SECTION_COLORS[section['color_key']]
        q_range = f"Q{section['questions'][0][0]}–Q{section['questions'][-1][0]}"
        toc_row_data = [[
            Paragraph(f"<b>{i+1:02d}.</b> {section['title'].replace('SECTION ' + 'I'*(i+1) + ': ', '').replace('SECTION X: ', '').replace('SECTION XI: ','').replace('SECTION XII: ','').replace('SECTION XIII: ','').replace('SECTION XIV: ','').replace('SECTION XV: ','').replace('SECTION XVI: ','').replace('SECTION XVII: ','').replace('SECTION XVIII: ','').replace('SECTION XIX: ','').replace('SECTION XX: ', '')}",
                       ParagraphStyle('toc_e', parent=styles['Normal'], fontSize=10, textColor=DARK_BLUE, leading=14)),
            Paragraph(q_range, ParagraphStyle('toc_r', parent=styles['Normal'], fontSize=9, textColor=color, alignment=TA_CENTER, fontName='Helvetica-Bold')),
        ]]
        toc_row = Table(toc_row_data, colWidths=[13.5*cm, 2.5*cm])
        bg = LIGHT_BLUE if i % 2 == 0 else colors.white
        toc_row.setStyle(TableStyle([
            ('BACKGROUND', (0,0), (-1,-1), bg),
            ('TOPPADDING', (0,0), (-1,-1), 5),
            ('BOTTOMPADDING', (0,0), (-1,-1), 5),
            ('LEFTPADDING', (0,0), (0,-1), 8),
            ('RIGHTPADDING', (0,0), (-1,-1), 8),
            ('LINEBELOW', (0,0), (-1,-1), 0.3, colors.HexColor('#BBDEFB')),
        ]))
        story.append(toc_row)

    story.append(PageBreak())

    # ---- SECTIONS ----
    for section in SECTIONS:
        color, light_color = SECTION_COLORS[section['color_key']]

        # Section header
        sec_header_data = [[Paragraph(section['title'], section_style)]]
        sec_count = Paragraph(
            f"<font color='white'>{len(section['questions'])} Questions</font>",
            ParagraphStyle('cnt', parent=styles['Normal'], fontName='Helvetica', fontSize=9,
                           textColor=WHITE, alignment=TA_CENTER)
        )
        sec_header_table = Table(
            [[Paragraph(section['title'], section_style), sec_count]],
            colWidths=[13*cm, 3*cm]
        )
        sec_header_table.setStyle(TableStyle([
            ('BACKGROUND', (0,0), (-1,-1), color),
            ('TOPPADDING', (0,0), (-1,-1), 8),
            ('BOTTOMPADDING', (0,0), (-1,-1), 8),
            ('LEFTPADDING', (0,0), (0,-1), 10),
            ('RIGHTPADDING', (0,0), (-1,-1), 8),
            ('VALIGN', (0,0), (-1,-1), 'MIDDLE'),
        ]))
        story.append(KeepTogether([sec_header_table, Spacer(1, 4)]))

        # Questions
        for q_num, q_text in section['questions']:
            q_data = [[
                Paragraph(f"<b>{q_num}</b>", q_num_style),
                Paragraph(q_text, q_text_style),
            ]]
            q_table = Table(q_data, colWidths=[1*cm, 15*cm])
            q_table.setStyle(TableStyle([
                ('BACKGROUND', (0,0), (0,-1), color),
                ('BACKGROUND', (1,0), (1,-1), light_color),
                ('TOPPADDING', (0,0), (-1,-1), 6),
                ('BOTTOMPADDING', (0,0), (-1,-1), 6),
                ('LEFTPADDING', (0,0), (0,-1), 3),
                ('RIGHTPADDING', (0,0), (-1,-1), 8),
                ('LEFTPADDING', (1,0), (1,-1), 8),
                ('VALIGN', (0,0), (-1,-1), 'MIDDLE'),
                ('LINEBELOW', (0,0), (-1,-1), 0.5, WHITE),
            ]))
            story.append(q_table)
            story.append(Spacer(1, 2))

        story.append(Spacer(1, 10))

    doc.build(story)
    print(f"PDF created: {output_path}")
    return output_path

if __name__ == '__main__':
    build_pdf()
Running Command

cd /tmp/workspace/medical-handbook && python3 create_handbook.py 2>&1

Running Command

ls -lh /tmp/workspace/medical-handbook/GP_Qualification_Exam_Handbook.pdf && python3 -c " from pypdf import PdfReader r = PdfReader('/tmp/workspace/medical-handbook/GP_Qualification_Exam_Handbook.pdf') print(f'Pages: {len(r.pages)}') "

Your colorful PDF handbook is ready for download:

GP Qualification Exam Handbook

PDF Document · PDF

Here's what was created:
Handbook Details:
  • 12 pages, professionally formatted
  • 163 questions fully translated from Russian to English
  • 20 color-coded sections, each with its own distinct color scheme
Sections included:
#SectionQuestions
IGeneral Practice FundamentalsQ1–3
IIPulmonologyQ4–6
IIICardiology (largest section)Q7–35
IVRheumatologyQ36–38
VGastroenterologyQ39–42
VINephrologyQ43–45
VIIHematology & EndocrinologyQ46–48
VIIISurgery & Vascular MedicineQ49–60
IXObstetrics & GynecologyQ61–71
XNeurologyQ72–80
XIPediatricsQ81–91
XIIUrology & OncologyQ92–96
XIIIENT & OphthalmologyQ97–104
XIVInfectious DiseasesQ105–112
XVDermatology & STIQ113–117
XVIPulmonary TuberculosisQ118–121
XVIITraumatologyQ122–123
XVIIIClinical PharmacologyQ124–137
XIXEmergency MedicineQ138–161
XXPalliative CareQ162–163
Design features: Color-coded header/footer, section banners with distinct colors per specialty, numbered question blocks with colored accents, Table of Contents, and a cover page.
This is a shared conversation. Sign in to Orris to start your own chat.