Cookbook 341: Offline Clinical Orthopedic Trauma Open Fracture Gustilo-Anderson & MESS Engine

This cookbook details how to deploy a localized, containerized orthopedic trauma surgery and emergency limb resuscitation decision-support engine for level-1 trauma centers, emergency departments, and orthopedic operating suites to ingest open wound dimensions, soft-tissue contamination patterns, neurovascular perfusion telemetry, warm ischemia durations, and systemic shock indices, classify injuries according to the Gustilo-Anderson Open Fracture Classification (Types I–IIIC), compute the Mangled Extremity Severity Score ($\text{MESS}$, $0 - 14\text{ points}$) to predict primary amputation vs complex limb salvage feasibility, automate Emergency Antimicrobial Selection & Timing ($\le 3\text{ Hours Golden Window}$), and enforce Tetanus Prophylaxis & Early Soft-Tissue Flap Coverage Sentinels according to Orthopaedic Trauma Association ($\text{OTA}$), AAOS, and EAST consensus guidelines without external cloud API reliance.


1. Clinical Background & Orthopedic Trauma Architecture

Open fractures occur when high-energy skeletal disruption breaches the overlying integument and soft-tissue envelope, exposing bone to bacterial contamination and causing extensive devitalization of the periosteal microcirculation:


2. Pipeline & Workflow Architecture

[Trauma Telemetry: Wound Size, Soft Tissue Crush, Perfusion, Ischemia Hours, SBP, Age]
                                         │
                                         ▼
      [Gustilo-Anderson Classifier: Type I vs II vs IIIA vs IIIB vs IIIC Staging]
                                         │
                                         ▼
      [MESS Engine: Skeletal (1-4) + Ischemia (1-3 x2 if >6h) + Shock (0-2) + Age (0-2)]
                                         │
                                         ▼
      [Limb Salvage vs Primary Amputation Gating: MESS >= 7 Decision Support]
                                         │
                                         ▼
      [Emergency Antibiotic Engine: Cefazolin + Gentamicin + Penicillin G (<3h Golden Window)]
                                         │
                                         ▼
      [Tetanus Toxoid/TIG Protocol & Fix-and-Flap Reconstruction Milestone Auditor]

3. Environment & Prerequisites

Install required scientific Python and orthopedic surgery modeling packages:

pip install numpy scipy pandas torch torchvision matplotlib

4. Complete Offline Python / PyTorch Implementation

"""
Cookbook 341: Offline Orthopedic Trauma Open Fracture Gustilo-Anderson & MESS Engine
OpenPHR Clinical AI Working Group (https://openphr.org)
"""

import math
import numpy as np
import pandas as pd
from typing import Dict, List, Tuple, Optional
from dataclasses import dataclass

@dataclass
class OpenFractureTelemetry:
    patient_id: str
    age_years: float = 42.0 # 30-50 = 1 pt in MESS
    patient_weight_kg: float = 82.0
    time_since_injury_hours: float = 2.5 # Must administer antibiotics within 3 hours
    # Wound & Soft Tissue Telemetry
    wound_length_cm: float = 14.0 # > 10 cm = Type III
    high_energy_mechanism: bool = True # High-speed MVC / crush
    adequate_local_soft_tissue_coverage: bool = False # Requires free/rotational flap -> Type IIIB!
    periosteal_stripping_and_bone_exposure: bool = True
    soil_or_farmyard_contamination: bool = True # Requires Penicillin G for Clostridium
    # Vascular & Ischemia Telemetry
    arterial_injury_requiring_repair: bool = False # If True -> Type IIIC
    limb_perfusion_status: str = "Pulseless with sluggish capillary refill" # "Normal", "Reduced pulse/normal refill", "Pulseless/sluggish refill", "Cold/paralyzed/insensate"
    warm_ischemia_duration_hours: float = 7.0 # > 6 hours -> Ischemia score is DOUBLED (x2)!
    # Hemodynamic & Shock Telemetry
    systolic_bp_mmhg: float = 84.0 # SBP < 90 mmHg
    shock_status: str = "Transient hypotension responsive to IV fluids" # "Normotensive", "Transient hypotension", "Persistent hypotension"
    # Immunization History
    tetanus_vaccine_doses_received: int = 2 # Incomplete (< 3 doses)
    years_since_last_tetanus_booster: float = 8.0 # > 5 years ago for dirty wound

@dataclass
class OrthoEvaluationReport:
    patient_id: str
    gustilo_anderson_type: str # "Type IIIB Open Fracture"
    gustilo_infection_risk: str
    mess_total_score: int # 0 - 14
    mess_salvage_guidance: str # "MESS >= 7 (Score 9): High specificity for secondary amputation / primary amputation recommended"
    emergency_antibiotic_orders: List[str]
    tetanus_management: List[str]
    surgical_debridement_and_flap_plan: List[str]
    safety_sentinels: List[str]
    clinical_ota_aaos_directive: str

class OrthopedicOpenFractureDecisionEngine:
    """
    Offline clinical engine for Gustilo-Anderson open fracture classification,
    MESS score calculation, emergency antibiotic selection, and limb salvage triage.
    """

    def classify_gustilo_anderson(self, d: OpenFractureTelemetry) -> Tuple[str, str]:
        if d.arterial_injury_requiring_repair:
            return "Type IIIC Open Fracture", "High Infection Risk (25-50%) with arterial injury requiring emergent vascular reconstruction."
        elif (d.wound_length_cm > 10.0 or d.high_energy_mechanism) and not d.adequate_local_soft_tissue_coverage:
            return "Type IIIB Open Fracture", "Severe Infection Risk (15-40%) with extensive periosteal stripping requiring rotational or free flap coverage."
        elif (d.wound_length_cm > 10.0 or d.high_energy_mechanism) and d.adequate_local_soft_tissue_coverage:
            return "Type IIIA Open Fracture", "Moderate-High Infection Risk (5-10%) with adequate soft-tissue coverage despite high energy."
        elif 1.0 < d.wound_length_cm <= 10.0:
            return "Type II Open Fracture", "Moderate Infection Risk (2-7%) with moderate crush and minimal periosteal stripping."
        else:
            return "Type I Open Fracture", "Low Infection Risk (< 1-2%) with clean puncture <= 1 cm."

    def calculate_mess_score(self, d: OpenFractureTelemetry) -> Tuple[int, Dict[str, int], str]:
        # 1. Skeletal / Soft Tissue Injury (1-4)
        if d.adequate_local_soft_tissue_coverage is False or d.soil_or_farmyard_contamination:
            skeletal_pts = 4 # Massive crush / gross contamination
        elif d.high_energy_mechanism or d.wound_length_cm > 10.0:
            skeletal_pts = 3 # High energy
        elif d.wound_length_cm > 1.0:
            skeletal_pts = 2 # Medium energy
        else:
            skeletal_pts = 1 # Low energy

        # 2. Limb Ischemia (1-3, Doubled if > 6h)
        if "Cold/paralyzed" in d.limb_perfusion_status:
            base_isch = 3
        elif "Pulseless" in d.limb_perfusion_status:
            base_isch = 2
        elif "Reduced pulse" in d.limb_perfusion_status:
            base_isch = 1
        else:
            base_isch = 0

        is_doubled = d.warm_ischemia_duration_hours > 6.0
        ischemia_pts = base_isch * 2 if is_doubled else base_isch

        # 3. Shock (0-2)
        if "Persistent" in d.shock_status:
            shock_pts = 2
        elif "Transient" in d.shock_status:
            shock_pts = 1
        else:
            shock_pts = 0

        # 4. Age (0-2)
        if d.age_years > 50.0:
            age_pts = 2
        elif d.age_years >= 30.0:
            age_pts = 1
        else:
            age_pts = 0

        total_mess = skeletal_pts + ischemia_pts + shock_pts + age_pts

        if total_mess >= 7:
            guidance = f"MESS >= 7 (Score {total_mess}/14): HIGH PREDICTIVE VALUE FOR SECONDARY AMPUTATION (~100%). Primary amputation vs heroic salvage discussion required."
        else:
            guidance = f"MESS < 7 (Score {total_mess}/14): LIMB SALVAGE FEASIBLE. Proceed with urgent revascularization, skeletal stabilization, and serial debridement."

        breakdown = {
            "Skeletal_Pts": skeletal_pts,
            "Ischemia_Pts": ischemia_pts,
            "Shock_Pts": shock_pts,
            "Age_Pts": age_pts
        }

        return total_mess, breakdown, guidance

    def generate_antibiotic_and_tetanus_orders(self, g_type: str, d: OpenFractureTelemetry) -> Tuple[List[str], List[str], List[str]]:
        abx = []
        tetanus = []
        sentinels = []

        # Golden Window Antibiotic Timing
        if d.time_since_injury_hours > 3.0:
            sentinels.append(f"🚨 TIME-TO-ANTIBIOTIC BREACH: {d.time_since_injury_hours:.1f} hours have elapsed since injury (> 3 hours golden window). Administer IV antibiotics IMMEDIATELY to limit osteomyelitis risk!")

        # Antibiotic Selection Matrix
        is_type_3 = "Type III" in g_type

        if is_type_3:
            abx.append("1. FIRST-LINE BROAD SPECTRUM (Type III Open Fracture):")
            abx.append("   • Cefazolin 2.0g IV q8h (Gram-positive coverage).")
            abx.append(f"   • Gentamicin 5 mg/kg IV once daily ({d.patient_weight_kg * 5.0:.0f} mg) for Gram-negative bacilli coverage (Alternative: Ceftriaxone 2.0g IV daily).")
        else:
            abx.append("1. FIRST-LINE PROPHYLAXIS (Type I/II Open Fracture):")
            abx.append("   • Cefazolin 2.0g IV q8h.")

        # Soil / Farmyard Contamination Add-on
        if d.soil_or_farmyard_contamination:
            abx.append("   • 🚜 SOIL / FARMYARD CONTAMINATION ADD-ON: Aqueous Penicillin G 4 million units IV q4h (or Ampicillin-Sulbactam 3.0g IV q6h) for Clostridium perfringens gas gangrene coverage.")

        # Tetanus Protocol
        needs_tig = d.tetanus_vaccine_doses_received < 3 or d.years_since_last_tetanus_booster > 5.0
        if needs_tig:
            tetanus.append("1. TETANUS PROPHYLAXIS PROTOCOL (Dirty / Contaminated Wound):")
            tetanus.append("   • Administer Tetanus Toxoid (Td or Tdap) 0.5 mL IM.")
            if d.tetanus_vaccine_doses_received < 3:
                tetanus.append("   • Administer Tetanus Immune Globulin (TIG) 250 units IM at a SEPARATE anatomical site.")
        else:
            tetanus.append("1. Tetanus immunization up to date (< 5 years since booster).")

        return abx, tetanus, sentinels

    def generate_surgical_plan(self, g_type: str, mess_score: int) -> List[str]:
        plan = []
        plan.append("1. EMERGENCY OPERATING ROOM DEBRIDEMENT: Urgent surgical irrigation and radical debridement within 12-24 hours.")
        plan.append("2. SKELETAL STABILIZATION: Span with external fixator or rigid intramedullary nail.")

        if "Type IIIB" in g_type:
            plan.append("3. 'FIX AND FLAP' SOFT-TISSUE RECONSTRUCTION: Plastic surgery consultation for local rotational flap (e.g. gastrocnemius/soleus) or free microvascular flap coverage within 72 hours to 7 days.")

        if "Type IIIC" in g_type or mess_score >= 7:
            plan.append("4. VASCULAR & ORTHOPEDIC MULTI-DISCIPLINARY CONSULT: Shunt/saphenous vein bypass vs primary amputation discussion.")

        return plan

    def evaluate_case(self, data: OpenFractureTelemetry) -> OrthoEvaluationReport:
        g_type, g_risk = self.classify_gustilo_anderson(data)
        mess_score, breakdown, mess_guide = self.calculate_mess_score(data)
        abx_plan, tet_plan, sentinels = self.generate_antibiotic_and_tetanus_orders(g_type, data)
        surg_plan = self.generate_surgical_plan(g_type, mess_score)

        directives = []
        directives.append(f"STAGING: {g_type}.")
        directives.append(f"MESS SCORE: {mess_score}/14 ({mess_guide}).")
        directives.append("ANTIBIOTICS: Broad-spectrum IV within 3 hours + Tetanus prophylaxis.")

        return OrthoEvaluationReport(
            patient_id=data.patient_id,
            gustilo_anderson_type=g_type,
            gustilo_infection_risk=g_risk,
            mess_total_score=mess_score,
            mess_salvage_guidance=mess_guide,
            emergency_antibiotic_orders=abx_plan,
            tetanus_management=tet_plan,
            surgical_debridement_and_flap_plan=surg_plan,
            safety_sentinels=sentinels,
            clinical_ota_aaos_directive=" ".join(directives)
        )

# Example Execution & Verification
if __name__ == "__main__":
    engine = OrthopedicOpenFractureDecisionEngine()

    print("=" * 80)
    print("OpenPHR Clinical Orthopedic Trauma Open Fracture & MESS Engine")
    print("=" * 80)

    # Test Case 1: 42-year-old male involved in a high-speed motorcycle crash with open tibial fracture.
    # Wound: 14 cm laceration, extensive periosteal stripping, bone exposed, soil contamination (Gustilo Type IIIB).
    # Vascular: Pulseless with sluggish refill, warm ischemia 7.0 hours (> 6h -> Ischemia points doubled!).
    # MESS: Skeletal (4) + Ischemia (2x2=4) + Shock (1) + Age (1) = 10/14 (MESS >= 7!).
    # Triage: STAT Cefazolin + Gentamicin + Penicillin G (<3h) + Tdap/TIG + Primary Amputation vs Complex Salvage!
    ortho1 = OpenFractureTelemetry(
        patient_id="ORTHO-OPEN-5501",
        age_years=42.0,
        patient_weight_kg=82.0,
        time_since_injury_hours=2.5,
        wound_length_cm=14.0,
        high_energy_mechanism=True,
        adequate_local_soft_tissue_coverage=False,
        periosteal_stripping_and_bone_exposure=True,
        soil_or_farmyard_contamination=True,
        arterial_injury_requiring_repair=False,
        limb_perfusion_status="Pulseless with sluggish capillary refill",
        warm_ischemia_duration_hours=7.0,
        systolic_bp_mmhg=84.0,
        shock_status="Transient hypotension responsive to IV fluids",
        tetanus_vaccine_doses_received=2,
        years_since_last_tetanus_booster=8.0
    )

    rep1 = engine.evaluate_case(ortho1)

    print(f"\n[Patient {rep1.patient_id} - Orthopedic Trauma Assessment]")
    print(f"Gustilo-Anderson Stage: {rep1.gustilo_anderson_type}")
    print(f"Infection Risk Profile: {rep1.gustilo_infection_risk}")
    print(f"\nMESS Score: {rep1.mess_total_score}/14\n  {rep1.mess_salvage_guidance}")
    print("\nEmergency Antibiotic Orders:")
    for abx in rep1.emergency_antibiotic_orders:
        print(f"  {abx}")
    print("\nTetanus Prophylaxis:")
    for tet in rep1.tetanus_management:
        print(f"  {tet}")
    print("\nSurgical Reconstruction Plan:")
    for s in rep1.surgical_debridement_and_flap_plan:
        print(f"  {s}")
    if rep1.safety_sentinels:
        print("\nSafety Sentinels:")
        for st in rep1.safety_sentinels:
            print(f"  🚨 {st}")
    print(f"\nOTA / AAOS Consensus Directive:\n{rep1.clinical_ota_aaos_directive}")

5. Clinical Verification & Guideline Conformance


6. References