#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Post-procesa citas.csv para mapear IDs numéricos de médicos a nombres reales.
"""
import csv
from pathlib import Path

DATA_DIR = Path('/root/migracion/datos')

medicos_map = {
    '32': 'Dra. Alejandra Ramos',
    '33': 'Dra. Lidia Martinez',
    '46': 'Dra. Fernanda Cerecer',
    '49': 'RODRIGUEZ FRIDA',
    '54': 'Dr. Benjamín Adrián',
    '79': 'XIMENA',
    '80': 'ELY',
}


def main():
    path = DATA_DIR / 'citas.csv'
    if not path.exists():
        print(f'No existe {path}')
        return
    rows = []
    with open(path, newline='', encoding='utf-8') as f:
        reader = csv.DictReader(f)
        for row in reader:
            doctor = (row.get('doctor_nombre') or '').strip()
            if doctor in medicos_map:
                row['doctor_nombre'] = medicos_map[doctor]
            rows.append(row)
    with open(path, 'w', newline='', encoding='utf-8') as f:
        writer = csv.DictWriter(f, fieldnames=rows[0].keys())
        writer.writeheader()
        writer.writerows(rows)
    print(f'Post-procesadas {len(rows)} citas')


if __name__ == '__main__':
    main()
