"""Sterilization Protocols — 20+ checks.

Covers autoclave cycle monitoring, biological indicator testing, chemical indicators,
process indicators, packaging, sterilization failure protocol, maintenance,
load configuration, and record retention.
"""

from __future__ import annotations

STERILIZATION_CONTROLS: dict = {
    # ── Autoclave Cycle Monitoring ──
    "AUTO-1": {
        "name": "Autoclave Cycle Monitoring",
        "regulation_reference": "CDC MMWR 2003; OSAP Sterilization Monitoring Guidelines",
        "checks": [
            {
                "id": "AUTO-1.1",
                "check": "Time, temperature, and pressure monitored and recorded for each cycle",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "critical",
                "remediation": "Record cycle parameters for every sterilization run: time, temperature, pressure. Steam autoclave standards: gravity 121C (250F) 30min or pre-vacuum 132C (270F) 4min. Use printout or manual log.",
                "practice_types": ["all"],
            },
            {
                "id": "AUTO-1.2",
                "check": "Autoclave cycle printout or digital log retained per policy",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Retain cycle records (printout or digital) for the retention period specified by state regulations (typically 3-7 years). Records must include: date, cycle type, parameters, operator, BI results.",
                "practice_types": ["all"],
            },
            {
                "id": "AUTO-1.3",
                "check": "Autoclave not overloaded — load configuration allows steam penetration",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Do not overload autoclave. Arrange packages on edge, not stacked flat. Leave space between packages for steam circulation. Follow manufacturer load capacity guidelines.",
                "practice_types": ["all"],
            },
        ],
    },
    # ── Biological Indicators (Spore Testing) ──
    "BIO-1": {
        "name": "Biological Indicator Testing",
        "regulation_reference": "CDC MMWR 2003; OSAP; AAMI ST79",
        "checks": [
            {
                "id": "BIO-1.1",
                "check": "Spore test (biological indicator) performed at least weekly",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "critical",
                "remediation": "Run biological indicator (Geobacillus stearothermophilus for steam) at least weekly. Place BI in the most challenging area of the load. Use commercially available BI test packs.",
                "practice_types": ["all"],
            },
            {
                "id": "BIO-1.2",
                "check": "Spore test performed with every implantable device load",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "critical",
                "remediation": "Run BI test with every load containing implantable devices. Do NOT release implantable items until BI results are negative (may require rapid-readout incubator).",
                "practice_types": ["oral_surgery", "perio", "all"],
            },
            {
                "id": "BIO-1.3",
                "check": "BI results recorded and filed with test date and autoclave ID",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Record BI results: date, autoclave ID, lot number, incubation period, result (pass/fail), operator. Retain records per state requirements.",
                "practice_types": ["all"],
            },
            {
                "id": "BIO-1.4",
                "check": "Control BI (not sterilized) included with each test batch",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "medium",
                "remediation": "Include an unprocessed control BI from the same lot with each test to confirm viability of the biological indicator. Control must show growth to validate the test.",
                "practice_types": ["all"],
            },
        ],
    },
    # ── Chemical Indicators ──
    "CHEM-1": {
        "name": "Chemical Indicator Use",
        "regulation_reference": "CDC MMWR 2003; AAMI ST79",
        "checks": [
            {
                "id": "CHEM-1.1",
                "check": "External chemical indicator (Class 1 process indicator) on every package",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Place external CI (autoclave tape or printed indicator on pouch) on outside of every package. Distinguishes processed from unprocessed packages.",
                "practice_types": ["all"],
            },
            {
                "id": "CHEM-1.2",
                "check": "Internal chemical indicator (Class 4/5) placed inside every package",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Place internal CI (Class 4 multi-variable or Class 5 integrating) inside each package. Verifies sterilant penetrated packaging and reached instruments. Check before use.",
                "practice_types": ["all"],
            },
            {
                "id": "CHEM-1.3",
                "check": "Chemical indicator results verified before instrument use",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "critical",
                "remediation": "Check internal CI at point of use before opening package. If CI does not indicate adequate processing, do NOT use instruments — re-clean and re-sterilize.",
                "practice_types": ["all"],
            },
        ],
    },
    # ── Process Verification ──
    "PROC-1": {
        "name": "Process Indicator Verification",
        "regulation_reference": "CDC MMWR 2003; AAMI ST79",
        "checks": [
            {
                "id": "PROC-1.1",
                "check": "Bowie-Dick test performed daily for pre-vacuum autoclaves",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Run Bowie-Dick test (air removal test) daily in first run of pre-vacuum autoclaves. Verifies adequate air removal. Failed test indicates air leak or malfunction — remove from service until repaired.",
                "practice_types": ["all"],
            },
        ],
    },
    # ── Packaging and Storage ──
    "PKG-1": {
        "name": "Instrument Packaging and Storage",
        "regulation_reference": "CDC MMWR 2003 — Storage of Sterile Items",
        "checks": [
            {
                "id": "PKG-1.1",
                "check": "Packaging materials compatible with sterilization method",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Use FDA-cleared packaging: sterilization pouches, wraps (CSR wrap, SMS), or rigid containers designed for the sterilization method (steam, chemical vapor, dry heat).",
                "practice_types": ["all"],
            },
            {
                "id": "PKG-1.2",
                "check": "Packages sealed properly (no gaps, proper fold, heat seal intact)",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Ensure proper seal on all packages. Self-seal pouches pressed firmly. Heat-sealed pouches have consistent seal. Wrapped packages use proper folding technique.",
                "practice_types": ["all"],
            },
            {
                "id": "PKG-1.3",
                "check": "Sterilized packages inspected for integrity before use",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Inspect packages before use: no tears, holes, wet spots, or compromised seals. Event-related shelf life — re-sterilize if packaging integrity compromised at any time.",
                "practice_types": ["all"],
            },
            {
                "id": "PKG-1.4",
                "check": "Storage area clean, dry, and away from contaminated areas",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "medium",
                "remediation": "Store sterilized instruments in clean, dry, enclosed cabinets away from instrument processing and patient treatment areas. Maintain separation of clean and dirty zones.",
                "practice_types": ["all"],
            },
        ],
    },
    # ── Sterilization Failure Protocol ──
    "FAIL-1": {
        "name": "Sterilization Failure Protocol (Positive Spore Test)",
        "regulation_reference": "CDC MMWR 2003; OSAP recommendations",
        "checks": [
            {
                "id": "FAIL-1.1",
                "check": "Written protocol for positive spore test documented",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "critical",
                "remediation": "Document protocol: (1) Remove autoclave from service immediately. (2) Recall and re-sterilize all items processed since last negative BI. (3) Retest with 3 consecutive BIs. (4) Do not return to service until 3 consecutive negatives. (5) Service autoclave if repeated failures.",
                "practice_types": ["all"],
            },
            {
                "id": "FAIL-1.2",
                "check": "Recall and re-sterilization procedures documented for failed loads",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "critical",
                "remediation": "Recall all items processed since last negative BI test. Re-clean and re-sterilize. If items were used on patients, consult infection control guidelines for patient notification protocols.",
                "practice_types": ["all"],
            },
        ],
    },
    # ── Maintenance and Calibration ──
    "MAINT-1": {
        "name": "Autoclave Maintenance and Calibration",
        "regulation_reference": "Manufacturer guidelines; AAMI ST79",
        "checks": [
            {
                "id": "MAINT-1.1",
                "check": "Autoclave maintenance performed per manufacturer schedule",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Follow manufacturer preventive maintenance schedule. Typically: daily (drain reservoir, clean chamber), weekly (clean door gasket), monthly (inspect gasket), annually (professional service).",
                "practice_types": ["all"],
            },
            {
                "id": "MAINT-1.2",
                "check": "Door gasket inspected regularly for wear and debris",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "medium",
                "remediation": "Inspect autoclave door gasket weekly. Clean with damp cloth. Replace if cracked, torn, or no longer sealing properly. Poor gasket = failed sterilization.",
                "practice_types": ["all"],
            },
            {
                "id": "MAINT-1.3",
                "check": "Distilled or deionized water used (not tap water)",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "medium",
                "remediation": "Use distilled or deionized water in steam autoclave. Tap water causes mineral deposits, corrosion, and shortened equipment life. Check water quality per manufacturer specs.",
                "practice_types": ["all"],
            },
        ],
    },
    # ── Ultrasonic Cleaner ──
    "ULTRA-1": {
        "name": "Ultrasonic Cleaner Maintenance",
        "regulation_reference": "Manufacturer guidelines; CDC recommendations",
        "checks": [
            {
                "id": "ULTRA-1.1",
                "check": "Ultrasonic cleaner solution changed at least daily (or when visibly soiled)",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Change ultrasonic solution at least daily and whenever visibly contaminated. Use manufacturer-recommended enzymatic cleaner. Cover ultrasonic unit during operation to contain aerosols.",
                "practice_types": ["all"],
            },
            {
                "id": "ULTRA-1.2",
                "check": "Ultrasonic cleaner cavitation test (foil test) performed periodically",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "medium",
                "remediation": "Perform foil test periodically: suspend aluminum foil in operating unit for recommended time. Even pitting pattern indicates proper cavitation. Replace unit if uneven or no pitting.",
                "practice_types": ["all"],
            },
        ],
    },
    # ── Record Retention ──
    "STEREC-1": {
        "name": "Sterilization Record Retention",
        "regulation_reference": "State regulations (varies)",
        "checks": [
            {
                "id": "STEREC-1.1",
                "check": "Sterilization monitoring records retained per state requirements",
                "scanner": "practice",
                "auto_fix": False,
                "severity": "high",
                "remediation": "Retain all sterilization records (cycle logs, BI results, CI verification, maintenance records) per state requirements (typically 3-7 years). Organize by date and autoclave ID.",
                "practice_types": ["all"],
            },
        ],
    },
}
