"""Dental Radiation Safety — 25+ checks.

Covers X-ray machine registration, operator certification, lead apron inspection,
monitoring badges, technique charts, QA testing, ALARA documentation,
patient dose documentation, sensor/PSP checks, and panoramic/CBCT safety.
"""

from __future__ import annotations

RADIATION_SAFETY_CONTROLS: dict = {
    # ── Equipment Registration ──
    "XREG-1": {
        "name": "Dental X-Ray Machine Registration",
        "regulation_reference": "State radiation control program (varies by state)",
        "checks": [
            {
                "id": "XREG-1.1",
                "check": "All X-ray equipment registered with state radiation control program",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "critical",
                "remediation": "Register all radiation-producing equipment with state radiation control agency. Registration typically required within 30 days of installation. Renew per state schedule.",
                "practice_types": ["all"],
            },
            {
                "id": "XREG-1.2",
                "check": "Registration certificate posted near equipment or on file",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Post current registration certificate in a conspicuous location near the X-ray equipment or maintain on file for inspector access.",
                "practice_types": ["all"],
            },
            {
                "id": "XREG-1.3",
                "check": "Equipment inspection by state agency current (typically every 2-4 years)",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Ensure equipment has passed most recent state inspection. Address any cited deficiencies. Schedule inspection if overdue.",
                "practice_types": ["all"],
            },
        ],
    },
    # ── Operator Certification ──
    "OPCERT-1": {
        "name": "X-Ray Operator Certification",
        "regulation_reference": "State dental practice act (varies by state)",
        "checks": [
            {
                "id": "OPCERT-1.1",
                "check": "All X-ray operators have required certification/training per state law",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "critical",
                "remediation": "Verify all staff operating X-ray equipment have state-required certification. Requirements vary: some states require formal course + exam, others accept on-the-job training with documentation.",
                "practice_types": ["all"],
            },
            {
                "id": "OPCERT-1.2",
                "check": "Operator certification records on file and current",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Maintain copies of all operator certifications on file. Track expiration dates. Ensure renewals completed before expiration.",
                "practice_types": ["all"],
            },
        ],
    },
    # ── Lead Apron and Thyroid Collar ──
    "LEAD-1": {
        "name": "Lead Apron and Thyroid Collar Inspection",
        "regulation_reference": "NCRP Report 145; State regulations",
        "checks": [
            {
                "id": "LEAD-1.1",
                "check": "Lead aprons inspected for cracks/defects at least annually",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Inspect lead aprons annually by visual examination and fluoroscopic/radiographic screening. Replace immediately if cracks, tears, or thin spots found. Document inspection date and results.",
                "practice_types": ["all"],
            },
            {
                "id": "LEAD-1.2",
                "check": "Thyroid collars available and used for all intraoral radiographs",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Use thyroid collar for all intraoral radiographs (periapical, bitewing, occlusal). ADA recommends thyroid collar use, especially for children and pregnant patients.",
                "practice_types": ["all"],
            },
            {
                "id": "LEAD-1.3",
                "check": "Lead aprons stored properly (hung, not folded) to prevent cracking",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "medium",
                "remediation": "Store lead aprons on proper hangers or racks. Never fold — folding causes internal lead cracking that compromises protection.",
                "practice_types": ["all"],
            },
        ],
    },
    # ── Radiation Monitoring ──
    "MONITOR-1": {
        "name": "Radiation Monitoring Badges",
        "regulation_reference": "State radiation control regulations",
        "checks": [
            {
                "id": "MONITOR-1.1",
                "check": "Personnel monitoring badges used if required by state (or if occupational dose may exceed 10% of limits)",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Provide dosimetry badges if required by state or if any operator may receive >10% of occupational dose limit. Most dental offices do NOT exceed this with proper technique.",
                "practice_types": ["all"],
            },
            {
                "id": "MONITOR-1.2",
                "check": "Monitoring reports reviewed quarterly and filed",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "medium",
                "remediation": "Review dosimetry reports upon receipt. Investigate any readings above expected levels. File reports for regulatory retention period (typically 30 years).",
                "practice_types": ["all"],
            },
        ],
    },
    # ── Technique Charts ──
    "TECH-1": {
        "name": "Dental X-Ray Technique Charts",
        "regulation_reference": "State regulations; ADA recommendations",
        "checks": [
            {
                "id": "TECH-1.1",
                "check": "Exposure technique chart posted at each X-ray unit",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Post technique chart listing kVp, mA, and exposure time for each view type. Separate settings for adult vs pediatric patients. Chart specific to each X-ray unit.",
                "practice_types": ["all"],
            },
            {
                "id": "TECH-1.2",
                "check": "Pediatric exposure settings documented and reduced from adult settings",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Document reduced exposure settings for pediatric patients (typically 50-70% of adult exposure). Base on child size categories. Post on technique chart.",
                "practice_types": ["all"],
            },
            {
                "id": "TECH-1.3",
                "check": "Technique chart updated when equipment changed or serviced",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "medium",
                "remediation": "Update technique charts whenever X-ray equipment is replaced, recalibrated, or has major service. Verify settings produce diagnostic-quality images at lowest exposure.",
                "practice_types": ["all"],
            },
        ],
    },
    # ── QA Testing ──
    "QA-1": {
        "name": "Radiation Quality Assurance Testing",
        "regulation_reference": "State regulations; NCRP Report 145",
        "checks": [
            {
                "id": "QA-1.1",
                "check": "X-ray output consistency test performed at least annually",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Perform annual output consistency (reproducibility) testing. Output should not vary more than +/- 5% between identical exposures. Document results.",
                "practice_types": ["all"],
            },
            {
                "id": "QA-1.2",
                "check": "kVp accuracy verified at least annually",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Verify kVp accuracy annually. Actual kVp should be within +/- 5 kVp of indicated setting. Use kVp meter or state inspector verification.",
                "practice_types": ["all"],
            },
            {
                "id": "QA-1.3",
                "check": "Timer accuracy verified at least annually",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "medium",
                "remediation": "Verify exposure timer accuracy annually. Actual exposure time should be within +/- 10% of indicated time. Use spin-top or electronic timer test.",
                "practice_types": ["all"],
            },
        ],
    },
    # ── ALARA ──
    "ALARA-1": {
        "name": "ALARA Principle Documentation",
        "regulation_reference": "10 CFR 20.1101(b); State regulations",
        "checks": [
            {
                "id": "ALARA-1.1",
                "check": "ALARA policy documented for the practice",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Document ALARA (As Low As Reasonably Achievable) policy. Include: selection criteria for radiographs, exposure optimization, protective measures, training requirements.",
                "practice_types": ["all"],
            },
            {
                "id": "ALARA-1.2",
                "check": "Selection criteria for dental radiographs followed (ADA/FDA guidelines)",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Use ADA/FDA selection criteria to determine radiographic need based on clinical examination. Do not take radiographs based solely on time intervals. Document clinical justification.",
                "practice_types": ["all"],
            },
            {
                "id": "ALARA-1.3",
                "check": "Rectangular collimation used (preferred over round) for periapical/bitewing",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "medium",
                "remediation": "Use rectangular collimation with beam-alignment devices for periapical and bitewing radiographs. Reduces patient exposure by up to 60% compared to round collimation.",
                "practice_types": ["all"],
            },
        ],
    },
    # ── Patient Dose Documentation ──
    "DOSE-1": {
        "name": "Patient Dose Documentation",
        "regulation_reference": "ADA recommendations; state regulations",
        "checks": [
            {
                "id": "DOSE-1.1",
                "check": "Patient exposure information recorded in dental record",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "medium",
                "remediation": "Record in patient chart: date, type of radiographs taken, number of exposures, kVp/mA/time settings, and any re-takes. Required for dose tracking.",
                "practice_types": ["all"],
            },
            {
                "id": "DOSE-1.2",
                "check": "Pregnancy status inquired before radiographic exposure",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Ask about pregnancy status before taking radiographs. Document response. If pregnant, only take radiographs if clinically necessary (emergency/urgent care). Use protective apron.",
                "practice_types": ["all"],
            },
        ],
    },
    # ── Digital Sensor / PSP ──
    "SENSOR-1": {
        "name": "Digital Sensor and PSP Plate Condition",
        "regulation_reference": "Manufacturer recommendations; QA protocols",
        "checks": [
            {
                "id": "SENSOR-1.1",
                "check": "Digital sensors inspected for damage and cable integrity",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "medium",
                "remediation": "Inspect digital sensors regularly for: scratches on active area, cable fraying, connector damage. Replace damaged sensors. Avoid dropping or bending cables.",
                "practice_types": ["all"],
            },
            {
                "id": "SENSOR-1.2",
                "check": "PSP (phosphor) plates inspected for scratches and replaced when degraded",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "medium",
                "remediation": "Inspect PSP plates before each use. Replace plates with scratches, bends, or worn edges. These artifacts can mimic pathology or obscure diagnostic information.",
                "practice_types": ["all"],
            },
        ],
    },
    # ── Panoramic / CBCT ──
    "PANO-1": {
        "name": "Panoramic and CBCT Safety Protocols",
        "regulation_reference": "ADA/AAOMR guidelines; state regulations",
        "checks": [
            {
                "id": "PANO-1.1",
                "check": "CBCT imaging follows ADA/AAOMR selection criteria",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Use CBCT only when clinical situation requires 3D imaging that cannot be answered by conventional radiography. Document clinical justification. Use smallest FOV possible.",
                "practice_types": ["oral_surgery", "ortho", "endo", "perio", "all"],
            },
            {
                "id": "PANO-1.2",
                "check": "CBCT reports include incidental finding review",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Review entire CBCT volume for incidental findings (sinus pathology, calcifications, airway, cervical spine). Document review. Refer as appropriate.",
                "practice_types": ["oral_surgery", "ortho", "endo", "perio", "all"],
            },
            {
                "id": "PANO-1.3",
                "check": "Panoramic positioning guides followed to minimize retakes",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "medium",
                "remediation": "Use manufacturer positioning guides. Verify patient position before exposure. Remove jewelry, eyeglasses, hearing aids, dentures. Retakes increase patient dose.",
                "practice_types": ["all"],
            },
        ],
    },
}
