// microbiology_testing.sy -- Clinical microbiology laboratory identification
// as native Scyla. Biochemical tests, culture media, staining, and
// CLSI antibiotic breakpoints.
//
// Sources:
//   Murray PR et al. Medical Microbiology, 9th ed, Elsevier, 2021.
//   Mahon CR et al. Textbook of Diagnostic Microbiology, 6th ed, 2019.
//   CLSI M100 Performance Standards, 34th ed, 2024.
//
// Marjorie McCubbins + Aether, April 2026
// Patent pending: 64/034,536


// ═══════════════════════════════════════════════════════════════
// STRUCTS
// ═══════════════════════════════════════════════════════════════

struct BiochemTest {
    test_name: String,
    principle: String,
    reagent: String,
    positive_result: String,
    negative_result: String,
    organisms_positive: String,
    organisms_negative: String,
    citation: String,
}

struct CultureMedium {
    media_name: String,
    media_type: String,
    composition: String,
    selects_for: String,
    inhibits: String,
    appearance_positive: String,
    citation: String,
}

struct GrowthCondition {
    organism: String,
    temperature_c: Float,
    atmosphere: String,
    time_to_growth: String,
    special_requirements: String,
    citation: String,
}

struct StainingMethod {
    method_name: String,
    stain_type: String,
    steps: String,
    positive_appearance: String,
    negative_appearance: String,
    clinical_use: String,
    citation: String,
}

struct AntibioticBreakpoint {
    organism: String,
    drug: String,
    susceptible_mic: Float,
    intermediate_mic: Float,
    resistant_mic: Float,
    mic_unit: String,
    test_method: String,
    citation: String,
}


// ═══════════════════════════════════════════════════════════════
// CONSTRUCTORS
// ═══════════════════════════════════════════════════════════════

fn btest(tn: String, pr: String, rg: String, pos: String, neg: String, op: String, on: String, ci: String) -> BiochemTest {
    return BiochemTest { test_name: tn, principle: pr, reagent: rg, positive_result: pos, negative_result: neg, organisms_positive: op, organisms_negative: on, citation: ci }
}

fn cmedia(mn: String, mt: String, co: String, sf: String, ih: String, ap: String, ci: String) -> CultureMedium {
    return CultureMedium { media_name: mn, media_type: mt, composition: co, selects_for: sf, inhibits: ih, appearance_positive: ap, citation: ci }
}

fn gcond(org: String, temp: Float, atm: String, ttg: String, sr: String, ci: String) -> GrowthCondition {
    return GrowthCondition { organism: org, temperature_c: temp, atmosphere: atm, time_to_growth: ttg, special_requirements: sr, citation: ci }
}

fn smethod(mn: String, st: String, steps: String, pa: String, na: String, cu: String, ci: String) -> StainingMethod {
    return StainingMethod { method_name: mn, stain_type: st, steps: steps, positive_appearance: pa, negative_appearance: na, clinical_use: cu, citation: ci }
}

fn abp(org: String, drug: String, s: Float, i: Float, r: Float, unit: String, tm: String, ci: String) -> AntibioticBreakpoint {
    return AntibioticBreakpoint { organism: org, drug: drug, susceptible_mic: s, intermediate_mic: i, resistant_mic: r, mic_unit: unit, test_method: tm, citation: ci }
}

fn unknown_biochem_test() -> BiochemTest {
    return btest("Unknown", "", "", "", "", "", "", "")
}

fn unknown_culture_medium() -> CultureMedium {
    return cmedia("Unknown", "", "", "", "", "", "")
}


// ═══════════════════════════════════════════════════════════════
// SECTION ONE: BIOCHEMICAL TESTS
// ═══════════════════════════════════════════════════════════════
//
// These are the classical bench tests that every clinical microbiology
// laboratory uses to identify unknown bacterial isolates. Each test
// exploits a specific metabolic capability (enzyme, substrate, product)
// to differentiate organisms at genus and species level.
//
// Murray 9th ed, Ch 16: Laboratory Diagnosis of Bacterial Diseases.
// Mahon 6th ed, Ch 7: Biochemical Identification.

fn biochem_test(name: String) -> BiochemTest {

    // ── CATALASE TEST ──────────────────────────────────────
    // Detects cytochrome-based catalase enzyme. Differentiates
    // Staphylococcus (catalase+) from Streptococcus (catalase-).
    // Slide method: colony + drop of H2O2. Vigorous bubbling = positive.
    // Murray 9th ed, Ch 18, p 198. Mahon 6th ed, Ch 7, p 118.
    if name == "catalase" { return btest("Catalase test", "Catalase enzyme decomposes hydrogen peroxide (H2O2) into water (H2O) and oxygen (O2). Bubbles of O2 gas indicate enzyme activity. 2 H2O2 -> 2 H2O + O2.", "3% hydrogen peroxide (H2O2)", "Immediate vigorous bubbling (O2 production)", "No bubbles", "Staphylococcus, Listeria, Corynebacterium, most aerobic bacteria", "Streptococcus, Enterococcus, Clostridium (most anaerobes)", "Murray 9th ed, Ch 18, p 198; Mahon 6th ed, Ch 7, p 118") }

    // ── COAGULASE TEST ─────────────────────────────────────
    // Distinguishes S. aureus from coagulase-negative staphylococci (CoNS).
    // Bound coagulase (clumping factor): slide test with plasma, clumps in seconds.
    // Free coagulase: tube test with rabbit plasma, incubate 4h, clot = positive.
    // Murray 9th ed, Ch 18, p 199. Mahon 6th ed, Ch 7, p 119.
    if name == "coagulase" { return btest("Coagulase test", "Coagulase converts fibrinogen to fibrin, forming a clot. Bound coagulase (clumping factor) on cell surface causes slide agglutination. Free coagulase activates prothrombin to staphylothrombin, which converts fibrinogen to fibrin (tube test clot).", "Rabbit plasma (EDTA anticoagulated)", "Slide test: clumping within 10 seconds. Tube test: visible clot after 4 hours at 37C.", "No clumping (slide), no clot (tube)", "Staphylococcus aureus", "Coagulase-negative staphylococci (S. epidermidis, S. saprophyticus, S. lugdunensis partial)", "Murray 9th ed, Ch 18, p 199; Mahon 6th ed, Ch 7, p 119") }

    // ── OXIDASE TEST ───────────────────────────────────────
    // Detects cytochrome c oxidase (Complex IV). Tetramethyl-p-
    // phenylenediamine is oxidized to a purple/blue color.
    // Key differentiator: Pseudomonas (oxidase+) vs Enterobacteriaceae (oxidase-).
    // Murray 9th ed, Ch 16, p 171. Mahon 6th ed, Ch 7, p 120.
    if name == "oxidase" { return btest("Oxidase test", "Detects presence of cytochrome c oxidase (terminal electron transport chain enzyme). The reagent N,N,N',N'-tetramethyl-p-phenylenediamine (TMPD) is oxidized by cytochrome c oxidase to form indophenol, producing a deep purple/blue color within 10 seconds.", "Kovacs oxidase reagent: 1% tetramethyl-p-phenylenediamine dihydrochloride", "Purple/blue color within 10 seconds (positive)", "No color change within 10 seconds (colorless)", "Pseudomonas, Neisseria, Vibrio, Campylobacter, Helicobacter, Aeromonas", "Enterobacteriaceae (all members), Acinetobacter, Stenotrophomonas", "Murray 9th ed, Ch 16, p 171; Mahon 6th ed, Ch 7, p 120") }

    // ── UREASE TEST ────────────────────────────────────────
    // Detects urease enzyme that hydrolyzes urea to ammonia and CO2.
    // Ammonia raises pH, phenol red turns pink/magenta.
    // Proteus: rapid (2-4 hours). Klebsiella, H. pylori: slow (overnight).
    // Murray 9th ed, Ch 27, p 310. Mahon 6th ed, Ch 7, p 123.
    if name == "urease" { return btest("Urease test", "Urease enzyme hydrolyzes urea to ammonia (NH3) and carbon dioxide (CO2). NH3 raises medium pH. Phenol red indicator turns from yellow/orange to pink/magenta at alkaline pH. Reaction: (NH2)2CO + H2O -> 2 NH3 + CO2.", "Christensen urea agar with phenol red indicator", "Pink to magenta color change (alkaline pH from ammonia production). Rapid = 2-4 hours. Slow = 18-24 hours.", "No color change (yellow/orange remains)", "Proteus (rapid urease), Helicobacter pylori (rapid, CLO test), Klebsiella (slow), Morganella", "Escherichia coli, Salmonella, Shigella", "Murray 9th ed, Ch 27, p 310; Mahon 6th ed, Ch 7, p 123") }

    // ── INDOLE TEST ────────────────────────────────────────
    // Tryptophanase cleaves tryptophan to indole, pyruvic acid, and ammonia.
    // Kovac reagent (p-dimethylaminobenzaldehyde in amyl alcohol) reacts with
    // indole to produce a red/pink ring at surface.
    // Murray 9th ed, Ch 27, p 309. Mahon 6th ed, Ch 7, p 122.
    if name == "indole" { return btest("Indole test", "Tryptophanase enzyme cleaves tryptophan into indole, pyruvic acid, and ammonia. Indole is detected by Kovac reagent (p-dimethylaminobenzaldehyde in amyl alcohol and HCl), which reacts with indole to form a red-colored rosindole dye at the surface.", "Kovac reagent (5% p-dimethylaminobenzaldehyde in amyl alcohol with HCl). SIM medium or tryptone broth.", "Cherry red ring at surface (indole + aldehyde = rosindole)", "No red color (yellow reagent layer)", "Escherichia coli, Proteus vulgaris (not P. mirabilis), Morganella", "Klebsiella pneumoniae, Enterobacter, Serratia, Proteus mirabilis", "Murray 9th ed, Ch 27, p 309; Mahon 6th ed, Ch 7, p 122") }

    // ── CITRATE TEST ───────────────────────────────────────
    // Tests ability to use citrate as sole carbon source.
    // Simmons citrate agar contains bromothymol blue. Citrate utilization
    // produces alkaline byproducts, turning green medium to blue.
    // Murray 9th ed, Ch 27, p 308. Mahon 6th ed, Ch 7, p 121.
    if name == "citrate" { return btest("Citrate utilization test", "Organism uses citrate as sole carbon and energy source via citrate permease. Metabolism of citrate produces oxaloacetate and acetate. CO2 from metabolism combines with sodium to form Na2CO3 (alkaline). Bromothymol blue indicator turns from green to blue at pH > 7.6.", "Simmons citrate agar (citrate + bromothymol blue indicator)", "Blue color (alkaline pH), growth on slant", "Green color unchanged, no growth", "Klebsiella, Enterobacter, Citrobacter, Serratia, Providencia, Salmonella (most)", "Escherichia coli, Shigella, Yersinia", "Murray 9th ed, Ch 27, p 308; Mahon 6th ed, Ch 7, p 121") }

    // ── TSI TEST ───────────────────────────────────────────
    // Triple Sugar Iron agar. Three sugars: glucose (0.1%), lactose (1%),
    // sucrose (1%). Slant/butt reactions, H2S production, gas.
    // Key for Enterobacteriaceae differentiation.
    // Murray 9th ed, Ch 27, p 311. Mahon 6th ed, Ch 7, p 125.
    if name == "TSI" { return btest("Triple Sugar Iron (TSI) test", "TSI agar contains glucose (0.1%), lactose (1%), sucrose (1%), ferrous sulfate (H2S indicator), and phenol red. Slant (aerobic) and butt (anaerobic) reactions read. Acid/Acid = ferments all sugars. Alkaline/Acid = glucose only (small amount exhausted on slant). H2S = black precipitate (FeS). Gas = bubbles or cracked agar.", "TSI agar (three sugars + ferrous sulfate + phenol red)", "A/A + gas + no H2S = E. coli. K/A + H2S = Salmonella. K/A + no H2S = Shigella. A/A + no gas = Klebsiella.", "K/K (alkaline/alkaline) = non-fermenter (not Enterobacteriaceae)", "Enterobacteriaceae (various patterns for identification)", "Non-fermenters (Pseudomonas shows K/K)", "Murray 9th ed, Ch 27, p 311; Mahon 6th ed, Ch 7, p 125") }

    // ── BILE ESCULIN TEST ──────────────────────────────────
    // Tests ability to grow in 40% bile AND hydrolyze esculin.
    // Esculin hydrolysis products react with ferric citrate to form
    // a black complex. Positive: Enterococcus, Group D Strep.
    // Murray 9th ed, Ch 19, p 212. Mahon 6th ed, Ch 7, p 127.
    if name == "bile_esculin" { return btest("Bile esculin test", "Tests two properties: tolerance to 40% bile (oxgall) and hydrolysis of esculin. Esculin is hydrolyzed to esculetin and glucose. Esculetin reacts with ferric citrate (Fe3+) in the medium to form a dark brown/black complex.", "Bile esculin agar (40% bile + esculin + ferric citrate)", "Blackening of medium (more than half the slant) within 48 hours", "No blackening, no growth in bile", "Enterococcus (all species), Group D Streptococcus (S. gallolyticus/bovis)", "Other Streptococcus species (Groups A, B), most viridans group strep", "Murray 9th ed, Ch 19, p 212; Mahon 6th ed, Ch 7, p 127") }

    // ── OPTOCHIN TEST ──────────────────────────────────────
    // Ethylhydrocupreine HCl (optochin) disk on blood agar.
    // S. pneumoniae is sensitive (zone >= 14 mm). Other alpha-hemolytic
    // strep are resistant. Optochin disrupts cell membrane of pneumococcus.
    // Murray 9th ed, Ch 19, p 210. Mahon 6th ed, Ch 7, p 128.
    if name == "optochin" { return btest("Optochin (ethylhydrocupreine) test", "Optochin (ethylhydrocupreine hydrochloride) selectively inhibits S. pneumoniae by disrupting the cell membrane. An optochin disk (P disk, 5 ug) is placed on blood agar streaked with alpha-hemolytic streptococci. Zone of inhibition >= 14 mm = sensitive = S. pneumoniae.", "Optochin disk (P disk, 5 ug ethylhydrocupreine HCl)", "Zone of inhibition >= 14 mm (sensitive) = S. pneumoniae. Must incubate in 5% CO2.", "Zone < 14 mm or no zone (resistant) = not S. pneumoniae (viridans streptococci)", "Streptococcus pneumoniae (sensitive, >= 14 mm zone)", "Viridans group streptococci: S. mitis, S. oralis, S. sanguinis (resistant)", "Murray 9th ed, Ch 19, p 210; Mahon 6th ed, Ch 7, p 128") }

    // ── BACITRACIN TEST ────────────────────────────────────
    // Bacitracin disk (A disk, 0.04 units) differentiates beta-hemolytic strep.
    // Group A (S. pyogenes) is sensitive. Other beta-hemolytic groups resistant.
    // Murray 9th ed, Ch 19, p 211. Mahon 6th ed, Ch 7, p 128.
    if name == "bacitracin" { return btest("Bacitracin susceptibility test", "Low-dose bacitracin (A disk, 0.04 units) selectively inhibits Group A Streptococcus (S. pyogenes). Bacitracin inhibits cell wall synthesis by blocking the dephosphorylation of bactoprenol (C55 lipid carrier). Group A strep is uniquely sensitive at this low concentration.", "Bacitracin disk (A disk, 0.04 units)", "Any zone of inhibition around disk = sensitive = Group A Streptococcus (S. pyogenes)", "No zone of inhibition = resistant = not Group A Strep", "Group A Streptococcus (S. pyogenes)", "Group B (S. agalactiae), Group C, Group G, other beta-hemolytic strep", "Murray 9th ed, Ch 19, p 211; Mahon 6th ed, Ch 7, p 128") }

    // ── CAMP TEST ──────────────────────────────────────────
    // Christie, Atkins, Munch-Petersen test. Group B Strep produces
    // CAMP factor that synergistically enhances the beta-hemolysin
    // (sphingomyelinase C) of S. aureus, forming an arrowhead zone
    // of enhanced hemolysis on blood agar.
    // Murray 9th ed, Ch 19, p 212. Mahon 6th ed, Ch 7, p 129.
    if name == "CAMP" { return btest("CAMP test", "CAMP factor (a pore-forming toxin/protein phospholipase) produced by Group B Streptococcus synergistically enhances the beta-hemolysin (sphingomyelinase C) of S. aureus. A streak of test organism is made perpendicular to, but not touching, an S. aureus streak on blood agar. Enhanced hemolysis appears as an arrowhead-shaped zone at the junction.", "Blood agar plate with perpendicular streaks: test organism and S. aureus (beta-hemolysin producer)", "Arrowhead-shaped zone of enhanced hemolysis at junction of streaks", "No enhanced hemolysis at junction", "Group B Streptococcus (S. agalactiae), Listeria monocytogenes", "Group A Streptococcus, other beta-hemolytic strep", "Murray 9th ed, Ch 19, p 212; Mahon 6th ed, Ch 7, p 129") }

    // ── PYR TEST ───────────────────────────────────────────
    // L-pyrrolidonyl-beta-naphthylamide (PYR) hydrolysis.
    // PYRase enzyme cleaves PYR substrate to beta-naphthylamine,
    // which turns red with cinnamaldehyde reagent.
    // Differentiates Group A Strep and Enterococcus from other strep.
    // Murray 9th ed, Ch 19, p 211. Mahon 6th ed, Ch 7, p 129.
    if name == "PYR" { return btest("PYR (pyrrolidonyl arylamidase) test", "PYRase enzyme hydrolyzes L-pyrrolidonyl-beta-naphthylamide (PYR substrate) to release beta-naphthylamine. Free beta-naphthylamine reacts with p-dimethylaminocinnamaldehyde reagent to produce a bright red/cherry-red color.", "PYR disk or broth (L-pyrrolidonyl-beta-naphthylamide) + cinnamaldehyde detector reagent", "Bright red/cherry-red color within 5 minutes", "No color change (yellow)", "Group A Streptococcus (S. pyogenes), Enterococcus (all species)", "Group B Streptococcus, viridans streptococci, S. pneumoniae", "Murray 9th ed, Ch 19, p 211; Mahon 6th ed, Ch 7, p 129") }

    // ── NOVOBIOCIN TEST ────────────────────────────────────
    // Novobiocin disk (5 ug) differentiates CoNS species.
    // S. epidermidis = sensitive. S. saprophyticus = resistant.
    // S. saprophyticus is a common cause of UTI in young women.
    // Murray 9th ed, Ch 18, p 200. Mahon 6th ed, Ch 7, p 130.
    if name == "novobiocin" { return btest("Novobiocin susceptibility test", "Novobiocin (5 ug disk) inhibits S. epidermidis but not S. saprophyticus. Novobiocin targets DNA gyrase subunit B. S. saprophyticus has intrinsic resistance. Used to identify CoNS from urinary tract infections (S. saprophyticus is the second most common cause of UTI in young sexually active women).", "Novobiocin disk (5 ug)", "Zone of inhibition >= 16 mm = sensitive = S. epidermidis (and most other CoNS)", "Zone < 16 mm = resistant = S. saprophyticus", "S. epidermidis (sensitive)", "S. saprophyticus (resistant)", "Murray 9th ed, Ch 18, p 200; Mahon 6th ed, Ch 7, p 130") }

    // ── DNase TEST ─────────────────────────────────────────
    // Tests for thermostable DNase production. DNase agar contains
    // DNA and toluidine blue or methyl green. DNA hydrolysis clears
    // the agar around colonies. Confirmatory for S. aureus.
    // Murray 9th ed, Ch 18, p 200. Mahon 6th ed, Ch 7, p 130.
    if name == "DNase" { return btest("DNase (deoxyribonuclease) test", "Tests for production of thermostable deoxyribonuclease (TNase/DNase). DNase agar contains DNA and methyl green dye. DNase hydrolyzes DNA, releasing methyl green dye, producing a clear zone around colonies. Alternative: flood with 1N HCl after growth; clear zone = DNA hydrolyzed.", "DNase agar (DNA + methyl green or toluidine blue)", "Clear zone around colony (DNA hydrolyzed, dye released)", "No clearing (DNA intact, methyl green bound)", "Staphylococcus aureus (thermostable DNase is confirmatory), Serratia marcescens", "Coagulase-negative staphylococci, most other organisms", "Murray 9th ed, Ch 18, p 200; Mahon 6th ed, Ch 7, p 130") }

    // ── MOTILITY TEST ──────────────────────────────────────
    // SIM (sulfide-indole-motility) medium or motility agar.
    // Stab inoculation. Motile organisms spread diffusely from stab
    // line, producing a hazy/turbid appearance. Non-motile organisms
    // grow only along the stab line.
    // Mahon 6th ed, Ch 7, p 124. Murray 9th ed, Ch 27, p 310.
    if name == "motility" { return btest("Motility test", "Semi-solid agar (SIM medium, 0.3-0.5% agar) is stab-inoculated. Motile organisms use flagella to swim away from the stab line, causing diffuse hazy growth throughout the medium. Non-motile organisms grow only along the stab line in a sharply defined track.", "SIM (sulfide-indole-motility) medium or motility test medium (semi-solid, 0.3-0.5% agar)", "Diffuse spreading/haziness away from stab line = motile", "Growth only along stab line (sharp, well-defined) = non-motile", "Escherichia coli (peritrichous flagella), Proteus (swarming motility), Salmonella, Pseudomonas (polar flagella)", "Klebsiella (non-motile, no flagella), Shigella, Acinetobacter", "Mahon 6th ed, Ch 7, p 124; Murray 9th ed, Ch 27, p 310") }

    // ── VOGES-PROSKAUER (VP) TEST ──────────────────────────
    // Detects acetoin (acetylmethylcarbinol) as an intermediate in
    // the butanediol fermentation pathway. VP+ organisms produce
    // neutral end products (butanediol) rather than mixed acids.
    // VP and MR are complementary: VP+/MR- or VP-/MR+.
    // Murray 9th ed, Ch 27, p 309. Mahon 6th ed, Ch 7, p 123.
    if name == "VP" { return btest("Voges-Proskauer (VP) test", "Detects acetoin (acetylmethylcarbinol), an intermediate in the 2,3-butanediol fermentation pathway. Barritt reagents: alpha-naphthol (VP-A) and 40% KOH (VP-B) oxidize acetoin to diacetyl, which reacts with guanidine in the peptone to produce a red/pink color. VP+ organisms use the butanediol pathway rather than mixed-acid fermentation.", "MR-VP broth (glucose + peptone), then Barritt reagents: VP-A (alpha-naphthol) and VP-B (40% KOH)", "Red/pink color within 15 minutes (acetoin present)", "No color change (copper/yellow)", "Klebsiella, Enterobacter, Serratia, Hafnia", "Escherichia coli, Citrobacter, Proteus, Salmonella, Shigella", "Murray 9th ed, Ch 27, p 309; Mahon 6th ed, Ch 7, p 123") }

    // ── METHYL RED TEST ────────────────────────────────────
    // Tests for mixed-acid fermentation producing stable acidic end
    // products (lactic, acetic, formic, succinic). pH drops below 4.4.
    // Methyl red is red at pH < 4.4, yellow at pH > 6.2.
    // Murray 9th ed, Ch 27, p 309. Mahon 6th ed, Ch 7, p 122.
    if name == "methyl_red" { return btest("Methyl red (MR) test", "Tests for mixed-acid fermentation. Organisms that produce large amounts of stable acid end products (lactic, acetic, formic, succinic acid) lower the pH of MR-VP broth below 4.4. Methyl red indicator is red at pH < 4.4 (strong acid production = positive). MR and VP are typically complementary: MR+/VP- or MR-/VP+.", "MR-VP broth (glucose + peptone), incubated 48-72 hours. Methyl red indicator added.", "Red color (pH < 4.4, strong mixed-acid fermentation)", "Yellow color (pH > 6.2, acids further metabolized or butanediol pathway used)", "Escherichia coli, Citrobacter, Proteus, Yersinia", "Klebsiella, Enterobacter, Serratia, Hafnia", "Murray 9th ed, Ch 27, p 309; Mahon 6th ed, Ch 7, p 122") }

    // ── NITRATE REDUCTION TEST ─────────────────────────────
    // Tests ability to reduce nitrate (NO3-) to nitrite (NO2-) or
    // further to nitrogen gas (N2). Sulfanilic acid + alpha-naphthylamine
    // detect nitrite (red = NO2- present). If no color, add zinc dust:
    // red = nitrate unreduced (negative), no color = nitrate reduced
    // past nitrite to N2 (positive, complete denitrification).
    // Murray 9th ed, Ch 16, p 172. Mahon 6th ed, Ch 7, p 124.
    if name == "nitrate" { return btest("Nitrate reduction test", "Tests for nitrate reductase enzyme. NO3- reduced to NO2- (nitrite). Reagent A (sulfanilic acid) + Reagent B (alpha-naphthylamine) detect nitrite as a red/pink diazo compound. If no color after reagents, add zinc dust: red = nitrate still present (true negative, organism did not reduce). No color after zinc = nitrate was completely reduced past nitrite to N2 gas (denitrification, still positive).", "Nitrate broth. Reagent A (sulfanilic acid), Reagent B (alpha-naphthylamine). Zinc dust (confirmatory).", "Red color with reagents = NO3- reduced to NO2- (positive). No color with reagents AND no color after zinc = complete denitrification to N2 (also positive).", "No color with reagents, red after zinc = NO3- not reduced (true negative)", "Most Enterobacteriaceae, Staphylococcus, Neisseria, Pseudomonas (complete denitrifiers)", "Some Streptococcus species, Acinetobacter (variable)", "Murray 9th ed, Ch 16, p 172; Mahon 6th ed, Ch 7, p 124") }

    // ── HIPPURATE HYDROLYSIS TEST ──────────────────────────
    // Hippuricase cleaves sodium hippurate to glycine and benzoic acid.
    // Ninhydrin reagent detects free glycine (purple/blue color).
    // Positive: Group B Strep (S. agalactiae), Campylobacter jejuni.
    // Murray 9th ed, Ch 19, p 213. Mahon 6th ed, Ch 7, p 130.
    if name == "hippurate" { return btest("Hippurate hydrolysis test", "Hippuricase enzyme hydrolyzes sodium hippurate to glycine and benzoic acid. Free glycine is detected by ninhydrin reagent, which reacts with amino groups to produce a deep purple/blue color (Ruhemann purple). Differentiates Group B Strep from other beta-hemolytic strep, and C. jejuni from other Campylobacter.", "1% sodium hippurate solution + ninhydrin reagent (triketohydrindene hydrate)", "Deep purple/blue color (glycine detected by ninhydrin)", "No color change (faint yellow)", "Group B Streptococcus (S. agalactiae), Campylobacter jejuni, Listeria monocytogenes", "Other beta-hemolytic streptococci, Campylobacter coli", "Murray 9th ed, Ch 19, p 213; Mahon 6th ed, Ch 7, p 130") }

    // ── LECITHINASE (EGG YOLK) TEST ────────────────────────
    // Detects lecithinase (phospholipase C / alpha toxin) production.
    // Egg yolk agar: lecithinase breaks down lecithin in egg yolk,
    // producing an opaque precipitate around colonies.
    // Nagler reaction: anti-alpha-toxin antibody inhibits one half of
    // plate, confirming C. perfringens identity.
    // Murray 9th ed, Ch 37, p 432. Mahon 6th ed, Ch 7, p 131.
    if name == "lecithinase" { return btest("Lecithinase (egg yolk) test / Nagler reaction", "Lecithinase (phospholipase C, alpha toxin of C. perfringens) hydrolyzes lecithin (phosphatidylcholine) in egg yolk agar, producing an insoluble opaque precipitate (diglyceride) around colonies. Nagler reaction: one half of egg yolk plate is spread with C. perfringens type A antitoxin. Lecithinase activity is inhibited on antitoxin side, confirming alpha toxin = confirming C. perfringens.", "Egg yolk agar (nutrient agar + egg yolk emulsion). Nagler: + C. perfringens type A antitoxin on half the plate.", "Opaque precipitate/halo around colonies (lecithin hydrolyzed). Nagler: inhibition of precipitate on antitoxin side.", "No opacity around colonies", "Clostridium perfringens (alpha toxin, lecithinase), C. bifermentans, Bacillus cereus", "C. difficile, C. tetani, most non-toxigenic clostridia", "Murray 9th ed, Ch 37, p 432; Mahon 6th ed, Ch 7, p 131") }

    // ── REVERSE CAMP TEST ──────────────────────────────────
    // C. perfringens produces phospholipase C (alpha toxin) that
    // enhances the CAMP reaction in the opposite direction: the
    // toxin causes inhibition/hemolysis arc AWAY from S. aureus streak.
    // Forms a bow-tie or reverse arrowhead pattern.
    // Murray 9th ed, Ch 37, p 433.
    if name == "reverse_CAMP" { return btest("Reverse CAMP test", "C. perfringens phospholipase C (alpha toxin) interacts with S. aureus beta-hemolysin in a reverse pattern compared to the standard CAMP test. Instead of enhanced hemolysis at the junction (arrowhead toward S. aureus), C. perfringens shows inhibition of hemolysis producing a bow-tie or reverse arrowhead pattern (zone of inhibition between the two streaks).", "Blood agar plate with perpendicular streaks: test organism and S. aureus beta-hemolysin producer", "Bow-tie or reverse arrowhead zone of inhibited hemolysis at junction", "No characteristic pattern", "Clostridium perfringens", "Other Clostridium species, non-lecithinase producers", "Murray 9th ed, Ch 37, p 433") }

    return unknown_biochem_test()
}


// ═══════════════════════════════════════════════════════════════
// SECTION TWO: CULTURE MEDIA
// ═══════════════════════════════════════════════════════════════
//
// Media selection is the first critical decision in clinical
// microbiology. Selective media inhibit unwanted organisms.
// Differential media distinguish organisms by metabolic properties.
// Enrichment media support fastidious organisms.
//
// Murray 9th ed, Ch 16: Overview of Bacterial Identification Methods
//   and Strategies, pp 162-178.
// Mahon 6th ed, Ch 6: Cultivation and Isolation of Viable Pathogens.

fn media(name: String) -> CultureMedium {

    // ── BLOOD AGAR (BAP) ───────────────────────────────────
    // Tryptic soy agar + 5% sheep blood. The universal medium.
    // Differential by hemolysis pattern:
    //   Alpha = partial (green, H2O2 reduces hemoglobin to methemoglobin)
    //   Beta = complete (clear zone, streptolysin O/S destroy RBCs)
    //   Gamma = none (no hemolytic enzymes)
    // Murray 9th ed, Ch 16, p 163. Mahon 6th ed, Ch 6, p 89.
    if name == "blood_agar" { return cmedia("Blood agar plate (BAP)", "Differential (general purpose + hemolysis detection)", "Tryptic soy agar base + 5% defibrinated sheep blood. Provides X factor (hemin) but not V factor (NAD, destroyed by heating).", "All bacteria that grow aerobically. Hemolysis patterns differentiate.", "None (non-selective, all organisms grow)", "Alpha hemolysis: green/olive zone (S. pneumoniae, viridans strep). Beta hemolysis: clear zone (S. pyogenes, S. agalactiae, S. aureus). Gamma hemolysis: no change (Enterococcus).", "Murray 9th ed, Ch 16, p 163; Mahon 6th ed, Ch 6, p 89") }

    // ── MacCONKEY AGAR ─────────────────────────────────────
    // Selective for gram-negative. Differential for lactose fermentation.
    // Crystal violet + bile salts inhibit gram-positive organisms.
    // Lactose fermenters produce acid -> neutral red turns pink/red.
    // Non-fermenters remain colorless/translucent.
    // Murray 9th ed, Ch 16, p 164. Mahon 6th ed, Ch 6, p 91.
    if name == "MacConkey" { return cmedia("MacConkey agar", "Selective and differential", "Peptone + lactose + bile salts + crystal violet (inhibits gram-positive) + neutral red (pH indicator). Lactose is the differential sugar.", "Gram-negative bacteria. Lactose fermenters vs non-fermenters.", "Gram-positive bacteria (crystal violet + bile salts inhibit)", "Lactose fermenters: pink/red colonies with bile precipitate (E. coli, Klebsiella, Enterobacter). Non-lactose fermenters: colorless/translucent colonies (Salmonella, Shigella, Proteus, Pseudomonas).", "Murray 9th ed, Ch 16, p 164; Mahon 6th ed, Ch 6, p 91") }

    // ── CHOCOLATE AGAR ─────────────────────────────────────
    // Blood agar heated to 80C (lysing RBCs, releasing X and V factors).
    // Chocolate-brown color from denatured hemoglobin. Enrichment for
    // fastidious organisms requiring X (hemin) and/or V (NAD) factors.
    // Murray 9th ed, Ch 16, p 163. Mahon 6th ed, Ch 6, p 90.
    if name == "chocolate_agar" { return cmedia("Chocolate agar", "Enrichment (non-selective)", "Heated blood agar (80C lyses RBCs). Releases X factor (hemin) and V factor (NAD) from red blood cells. Both factors available for fastidious organisms.", "Fastidious organisms requiring X and/or V factors.", "None (non-selective, enrichment)", "Brown colonies of Neisseria. Small satellite colonies of Haemophilus (requires X+V factors). Incubate 5% CO2.", "Murray 9th ed, Ch 16, p 163; Mahon 6th ed, Ch 6, p 90") }

    // ── THAYER-MARTIN AGAR ─────────────────────────────────
    // Modified chocolate agar + VCN antibiotics:
    //   Vancomycin (inhibits gram-positive), Colistin (inhibits gram-
    //   negative except Neisseria), Nystatin (inhibits fungi).
    // Selective for pathogenic Neisseria from non-sterile sites.
    // Murray 9th ed, Ch 22, p 254. Mahon 6th ed, Ch 6, p 91.
    if name == "Thayer_Martin" { return cmedia("Modified Thayer-Martin agar", "Selective (enrichment base)", "Chocolate agar base + VCN antibiotics: Vancomycin (inhibits gram-positive), Colistin (polymyxin, inhibits gram-negative bacilli), Nystatin (inhibits fungi). Some add TMP for Proteus swarming inhibition.", "Pathogenic Neisseria from non-sterile sites (genital, pharyngeal, rectal).", "Normal flora gram-positive cocci, gram-negative bacilli, fungi", "N. gonorrhoeae: small, grayish, translucent colonies. N. meningitidis: larger, mucoid. Both oxidase-positive. Incubate 5% CO2, 35-37C.", "Murray 9th ed, Ch 22, p 254; Mahon 6th ed, Ch 6, p 91") }

    // ── EMB (EOSIN METHYLENE BLUE) AGAR ────────────────────
    // Selective for gram-negative. Differential for lactose fermentation.
    // Eosin Y + methylene blue inhibit gram-positive and distinguish
    // fermenters. Strong acid production -> metallic green sheen (E. coli).
    // Murray 9th ed, Ch 16, p 164. Mahon 6th ed, Ch 6, p 92.
    if name == "EMB" { return cmedia("Eosin methylene blue (EMB) agar", "Selective and differential", "Peptone + lactose + sucrose + eosin Y + methylene blue. Eosin and methylene blue inhibit gram-positive bacteria and serve as differential indicators for lactose fermentation.", "Gram-negative bacteria. Strong vs weak vs non-lactose fermenters.", "Gram-positive bacteria (eosin + methylene blue inhibit)", "E. coli: dark colonies with distinctive metallic green sheen (strong acid production precipitates dyes). Other lactose fermenters (Klebsiella, Enterobacter): pink-purple mucoid colonies without sheen. Non-fermenters: colorless/translucent.", "Murray 9th ed, Ch 16, p 164; Mahon 6th ed, Ch 6, p 92") }

    // ── MANNITOL SALT AGAR ─────────────────────────────────
    // 7.5% NaCl selects for salt-tolerant organisms (Staphylococcus).
    // Mannitol + phenol red differentiates: S. aureus ferments mannitol
    // (acid, yellow). CoNS do not (pink/red, no color change).
    // Murray 9th ed, Ch 18, p 197. Mahon 6th ed, Ch 6, p 93.
    if name == "mannitol_salt" { return cmedia("Mannitol salt agar (MSA)", "Selective and differential", "Peptone + 7.5% NaCl (selects salt-tolerant organisms) + mannitol (differential sugar) + phenol red indicator. High salt concentration inhibits most non-staphylococcal organisms.", "Staphylococcus species (salt-tolerant). S. aureus (mannitol fermenter) vs CoNS.", "Most gram-negative bacteria, Streptococcus, Enterococcus (inhibited by 7.5% NaCl)", "S. aureus: yellow halo (mannitol fermentation produces acid, phenol red turns yellow). CoNS (S. epidermidis): pink/red (no mannitol fermentation, pH unchanged).", "Murray 9th ed, Ch 18, p 197; Mahon 6th ed, Ch 6, p 93") }

    // ── HEKTOEN ENTERIC AGAR ───────────────────────────────
    // Selective/differential for enteric pathogens (Salmonella, Shigella)
    // from stool. Bile salts inhibit normal flora. Lactose + sucrose +
    // salicin fermentation detected by acid fuchsin + bromothymol blue.
    // H2S production detected by ferric ammonium citrate.
    // Murray 9th ed, Ch 27, p 307. Mahon 6th ed, Ch 6, p 94.
    if name == "Hektoen_enteric" { return cmedia("Hektoen enteric (HE) agar", "Selective and differential", "Bile salts (inhibit normal flora) + lactose, sucrose, salicin (three sugars) + acid fuchsin and bromothymol blue (pH indicators) + ferric ammonium citrate + sodium thiosulfate (H2S detection).", "Enteric pathogens: Salmonella, Shigella from stool specimens.", "Normal fecal flora (inhibited by bile salts)", "Salmonella: green/blue-green colonies with black centers (H2S+, non-lactose fermenter). Shigella: green/transparent colonies, no black center (H2S-, non-fermenter). Normal flora: salmon/orange colonies (lactose/sucrose/salicin fermenters, acid production).", "Murray 9th ed, Ch 27, p 307; Mahon 6th ed, Ch 6, p 94") }

    // ── SABOURAUD DEXTROSE AGAR ────────────────────────────
    // Low pH (5.6) + high glucose (4%) selects for fungi.
    // pH inhibits most bacteria. Used for dermatophytes, yeasts, molds.
    // May add antibiotics (chloramphenicol, gentamicin) and cycloheximide.
    // Murray 9th ed, Ch 59, p 666. Mahon 6th ed, Ch 6, p 95.
    if name == "Sabouraud" { return cmedia("Sabouraud dextrose agar (SDA)", "Selective (fungal)", "4% dextrose (glucose) + peptone. pH 5.6 (acidic, inhibits most bacteria). Optional: chloramphenicol + gentamicin (antibacterial), cycloheximide (inhibits saprophytic fungi, selects dermatophytes).", "Fungi: dermatophytes, yeasts (Candida), dimorphic fungi, molds (Aspergillus).", "Most bacteria (inhibited by low pH). Saprophytic fungi (if cycloheximide added).", "Candida albicans: cream-white pasty colonies (24-48 hours). Dermatophytes: variable (1-4 weeks). Aspergillus: colored sporulating colonies. Mucor/Rhizopus: rapid cottony growth.", "Murray 9th ed, Ch 59, p 666; Mahon 6th ed, Ch 6, p 95") }

    // ── LOWENSTEIN-JENSEN MEDIUM ────────────────────────────
    // Egg-based medium for Mycobacterium. Malachite green inhibits
    // normal flora. M. tuberculosis: buff/tan rough colonies, 2-6 weeks.
    // Slow growth due to mycolic acid cell wall (doubling time 15-20 hours).
    // Murray 9th ed, Ch 25, p 281. Mahon 6th ed, Ch 6, p 96.
    if name == "Lowenstein_Jensen" { return cmedia("Lowenstein-Jensen (LJ) medium", "Selective (mycobacterial)", "Egg-based (coagulated whole eggs + egg yolks) + glycerol + asparagine + mineral salts + malachite green (inhibits contaminating bacteria). Inspissated (heated to coagulate eggs).", "Mycobacterium species (tuberculosis and NTM).", "Most bacteria, fungi (inhibited by malachite green)", "M. tuberculosis: buff/tan rough non-pigmented colonies (eugonic), 2-6 weeks. M. kansasii: photochromogen (yellow in light). M. avium complex: smooth non-pigmented. Colony morphology + growth rate + pigmentation for speciation.", "Murray 9th ed, Ch 25, p 281; Mahon 6th ed, Ch 6, p 96") }

    // ── TCBS AGAR ──────────────────────────────────────────
    // Thiosulfate-citrate-bile salts-sucrose agar. Selective for Vibrio.
    // High pH (8.6) + bile salts inhibit most enteric flora.
    // V. cholerae ferments sucrose = yellow colonies.
    // V. parahaemolyticus does not = green/blue-green colonies.
    // Murray 9th ed, Ch 29, p 330. Mahon 6th ed, Ch 6, p 95.
    if name == "TCBS" { return cmedia("TCBS (thiosulfate-citrate-bile salts-sucrose) agar", "Selective and differential", "Sodium thiosulfate + sodium citrate (inhibit gram-positive) + ox bile (inhibits most enteric bacteria) + sucrose (differential sugar) + bromothymol blue + thymol blue (pH indicators). pH 8.6 (alkaline, selective).", "Vibrio species from stool and environmental samples.", "Most enteric gram-negative bacteria, gram-positive bacteria (bile salts + alkaline pH inhibit)", "V. cholerae: large yellow colonies (sucrose fermenter, acid production). V. parahaemolyticus: green/blue-green colonies (non-sucrose fermenter). V. vulnificus: green colonies.", "Murray 9th ed, Ch 29, p 330; Mahon 6th ed, Ch 6, p 95") }

    return unknown_culture_medium()
}


// ═══════════════════════════════════════════════════════════════
// SECTION THREE: GROWTH CONDITIONS
// ═══════════════════════════════════════════════════════════════
//
// Correct atmosphere and temperature are as critical as media selection.
// Obligate aerobes, facultative anaerobes, obligate anaerobes,
// microaerophiles, and capnophiles all require different environments.
//
// Murray 9th ed, Ch 16, pp 167-170.
// Mahon 6th ed, Ch 6, pp 82-88.

fn growth_conditions(organism: String) -> GrowthCondition {

    if organism == "E_coli" { return gcond("Escherichia coli", 37.0, "Aerobic or anaerobic (facultative anaerobe)", "18-24 hours", "Grows on most media. Indole+, MR+, VP-, Citrate-. Optimal 37C.", "Murray 9th ed, Ch 27, p 303") }

    if organism == "S_aureus" { return gcond("Staphylococcus aureus", 37.0, "Aerobic or anaerobic (facultative anaerobe)", "18-24 hours", "Salt tolerant (grows on MSA 7.5% NaCl). Catalase+, coagulase+. Golden pigment on BAP.", "Murray 9th ed, Ch 18, p 194") }

    if organism == "S_pneumoniae" { return gcond("Streptococcus pneumoniae", 37.0, "5% CO2 (capnophilic, enhanced growth)", "18-24 hours", "Alpha hemolytic on BAP. Optochin sensitive. Bile soluble. Requires 5% CO2 for optimal recovery.", "Murray 9th ed, Ch 19, p 208") }

    if organism == "N_gonorrhoeae" { return gcond("Neisseria gonorrhoeae", 37.0, "5% CO2 (strict requirement, capnophilic)", "24-48 hours", "Very fastidious. Dies at room temperature. Requires chocolate or Thayer-Martin. 5% CO2, 35-37C, humid. Do not refrigerate specimens.", "Murray 9th ed, Ch 22, p 252") }

    if organism == "N_meningitidis" { return gcond("Neisseria meningitidis", 37.0, "5% CO2 (capnophilic)", "24-48 hours", "Chocolate agar or blood agar with 5% CO2. Oxidase+. Meningitis and meningococcemia. BSL-2 pathogen.", "Murray 9th ed, Ch 22, p 256") }

    if organism == "H_influenzae" { return gcond("Haemophilus influenzae", 37.0, "5% CO2 (enhanced recovery)", "24-48 hours", "Requires X factor (hemin) AND V factor (NAD). Chocolate agar (both factors). Satellitism around S. aureus on BAP (S. aureus releases V factor).", "Murray 9th ed, Ch 24, p 271") }

    if organism == "C_jejuni" { return gcond("Campylobacter jejuni", 42.0, "Microaerophilic (5% O2, 10% CO2, 85% N2)", "48-72 hours", "Thermophilic (42C optimal, not 37C). Microaerophilic atmosphere required. Campy-BAP or Skirrow medium. Hippurate+. Oxidase+.", "Murray 9th ed, Ch 30, p 337") }

    if organism == "H_pylori" { return gcond("Helicobacter pylori", 37.0, "Microaerophilic (5% O2, 10% CO2)", "3-7 days (slow grower)", "Gastric biopsy specimens. Urease+ (rapid, CLO test). Oxidase+. Catalase+. Requires microaerophilic conditions.", "Murray 9th ed, Ch 30, p 340") }

    if organism == "M_tuberculosis" { return gcond("Mycobacterium tuberculosis", 37.0, "Aerobic (obligate aerobe, prefers high O2)", "2-6 weeks (doubling time 15-20 hours)", "Lowenstein-Jensen or Middlebrook 7H10/7H11. Acid-fast (ZN stain). BSL-3 pathogen. BACTEC MGIT liquid culture detects in 1-2 weeks.", "Murray 9th ed, Ch 25, p 279") }

    if organism == "Pseudomonas" { return gcond("Pseudomonas aeruginosa", 37.0, "Aerobic (obligate aerobe)", "18-24 hours", "Oxidase+. Grape-like odor. Blue-green pigment (pyocyanin + pyoverdin). Grows at 42C (useful for identification). Non-lactose fermenter on MacConkey.", "Murray 9th ed, Ch 28, p 319") }

    if organism == "C_difficile" { return gcond("Clostridioides difficile", 37.0, "Anaerobic (obligate anaerobe)", "48-72 hours", "CCFA (cycloserine-cefoxitin-fructose agar) selective medium. Ground-glass colonies with horse-barn odor. Toxin A/B testing more common than culture. Spore-forming.", "Murray 9th ed, Ch 37, p 428") }

    if organism == "C_perfringens" { return gcond("Clostridium perfringens", 37.0, "Anaerobic (obligate anaerobe)", "18-24 hours (rapid for anaerobe)", "Fastest growing pathogenic clostridium. Double-zone hemolysis on BAP (inner beta from theta toxin, outer partial from alpha toxin/lecithinase). Egg yolk agar: lecithinase+.", "Murray 9th ed, Ch 37, p 430") }

    if organism == "Candida" { return gcond("Candida albicans", 37.0, "Aerobic (facultative anaerobe)", "24-48 hours", "Sabouraud dextrose agar. CHROMagar Candida: green colonies = C. albicans. Germ tube test positive at 37C in serum (distinguishes from other Candida). Chlamydospores on cornmeal agar.", "Murray 9th ed, Ch 62, p 690") }

    if organism == "Enterococcus" { return gcond("Enterococcus faecalis", 37.0, "Aerobic or anaerobic (facultative anaerobe)", "18-24 hours", "Growth in 6.5% NaCl (distinguishes from streptococci). Bile esculin+. PYR+. Gamma hemolytic (usually). Survives 60C for 30 minutes.", "Murray 9th ed, Ch 19, p 215") }

    if organism == "Salmonella" { return gcond("Salmonella enterica", 37.0, "Aerobic or anaerobic (facultative anaerobe)", "18-24 hours", "Non-lactose fermenter. H2S+ on HE/XLD agar (black center colonies). Selenite or tetrathionate enrichment broth from stool. TSI: K/A, H2S+, gas+.", "Murray 9th ed, Ch 27, p 299") }

    if organism == "Shigella" { return gcond("Shigella species", 37.0, "Aerobic or anaerobic (facultative anaerobe)", "18-24 hours", "Non-lactose fermenter. Non-motile (distinguishes from Salmonella). No H2S. No gas from glucose. TSI: K/A, H2S-, gas-. Green colonies on HE agar.", "Murray 9th ed, Ch 27, p 302") }

    if organism == "Legionella" { return gcond("Legionella pneumophila", 37.0, "Aerobic with increased humidity", "3-5 days", "BCYE (buffered charcoal yeast extract) agar with L-cysteine and iron. Does NOT grow on BAP (requires L-cysteine). Silver stain in tissue. Urinary antigen test for serogroup 1.", "Murray 9th ed, Ch 33, p 373") }

    if organism == "Cryptococcus" { return gcond("Cryptococcus neoformans", 37.0, "Aerobic", "48-72 hours", "Sabouraud or BHI agar. Mucoid yeast colonies. India ink capsule visualization in CSF. Latex agglutination for capsular antigen. Urease+.", "Murray 9th ed, Ch 62, p 695") }

    return gcond("Unknown", 37.0, "", "", "", "")
}


// ═══════════════════════════════════════════════════════════════
// SECTION FOUR: STAINING METHODS
// ═══════════════════════════════════════════════════════════════
//
// Staining is the fastest diagnostic tool in microbiology. A Gram
// stain takes 5 minutes and immediately classifies an unknown
// organism into gram-positive vs gram-negative, coccus vs bacillus.
// Special stains detect organisms that Gram stain misses.
//
// Murray 9th ed, Ch 16, pp 165-167.
// Mahon 6th ed, Ch 5: Microscopy and Staining.

fn staining_method(name: String) -> StainingMethod {

    // ── GRAM STAIN ─────────────────────────────────────────
    // The most important stain in microbiology. Developed by Hans
    // Christian Gram (1884). Differentiates by cell wall structure:
    // thick peptidoglycan retains crystal violet-iodine complex.
    // Murray 9th ed, Ch 16, p 165. Mahon 6th ed, Ch 5, p 68.
    if name == "Gram" { return smethod("Gram stain", "Differential (cell wall)", "Step 1: Crystal violet (primary stain, 1 min). Step 2: Gram iodine (mordant, fixes crystal violet-iodine complex, 1 min). Step 3: Acetone-alcohol decolorizer (dissolves outer membrane of gram-negatives, removes crystal violet, 10-30 sec). Step 4: Safranin (counterstain, stains decolorized gram-negatives pink/red, 1 min).", "Gram-positive: purple/violet (thick peptidoglycan layer retains crystal violet-iodine complex). Cocci in clusters (Staphylococcus), chains (Streptococcus), diplococci (Pneumococcus).", "Gram-negative: pink/red (thin peptidoglycan, outer membrane dissolved by decolorizer, counterstained by safranin). Rods (E. coli, Klebsiella), diplococci (Neisseria).", "Immediate classification of organism morphology and Gram reaction. Direct specimen examination before culture results. Guides empiric antibiotic therapy.", "Murray 9th ed, Ch 16, p 165; Mahon 6th ed, Ch 5, p 68. Gram HC, Fortschr Med 2:185-189, 1884.") }

    // ── ACID-FAST (ZIEHL-NEELSEN) STAIN ────────────────────
    // Mycobacteria have waxy mycolic acid cell wall that resists
    // decolorization by acid-alcohol after hot carbol fuchsin.
    // Murray 9th ed, Ch 25, p 280. Mahon 6th ed, Ch 5, p 72.
    if name == "acid_fast" { return smethod("Ziehl-Neelsen acid-fast stain", "Differential (mycolic acid cell wall)", "Step 1: Carbol fuchsin (primary stain, heat-fixed, apply with steam for 5 min to drive stain through mycolic acid). Step 2: Acid-alcohol decolorizer (3% HCl in 95% ethanol, decolorizes non-acid-fast organisms). Step 3: Methylene blue counterstain (1-2 min).", "Acid-fast positive: bright red/pink bacilli against blue background. Mycobacterium tuberculosis: thin beaded rods in cords (cord factor = trehalose dimycolate).", "Acid-fast negative: blue (decolorized by acid-alcohol, counterstained by methylene blue). Most bacteria, fungi, and parasites are non-acid-fast.", "Sputum smear for tuberculosis. Nocardia (modified acid-fast, weak acid). Cryptosporidium oocysts in stool (modified acid-fast).", "Murray 9th ed, Ch 25, p 280; Mahon 6th ed, Ch 5, p 72") }

    // ── INDIA INK ──────────────────────────────────────────
    // Negative stain for capsules. India ink particles are excluded
    // by the polysaccharide capsule, creating a clear halo around
    // the yeast cell against a dark background.
    // Murray 9th ed, Ch 62, p 695. Mahon 6th ed, Ch 5, p 75.
    if name == "India_ink" { return smethod("India ink (negative stain)", "Negative stain (capsule visualization)", "Mix drop of CSF sediment with drop of India ink on slide. Apply coverslip. Examine under light microscopy at 40x.", "Clear halo (capsule) surrounding round budding yeast cells against a dark background. Cryptococcus neoformans: 5-20 um spherical yeast with wide capsule, narrow-based budding.", "No halo, no yeast cells visible. Note: India ink sensitivity is only 50% in non-AIDS patients. Latex agglutination or lateral flow assay for capsular antigen is more sensitive (>95%).", "CSF examination for Cryptococcal meningitis. Rapid bedside test. Used alongside cryptococcal antigen (CrAg) testing.", "Murray 9th ed, Ch 62, p 695; Mahon 6th ed, Ch 5, p 75") }

    // ── GIEMSA STAIN ───────────────────────────────────────
    // Romanowsky-type stain for intracellular parasites, blood smears.
    // Azure dyes stain DNA/RNA of parasites blue-purple. Eosin stains
    // cytoplasm pink. Gold standard for malaria species identification.
    // Murray 9th ed, Ch 67, p 741. Mahon 6th ed, Ch 5, p 76.
    if name == "Giemsa" { return smethod("Giemsa stain", "Differential (Romanowsky-type)", "Fix thin smear with methanol. Stain with Giemsa (azure B + eosin Y in methanol/glycerol) diluted in buffer pH 7.2 for 20-30 minutes. Thick smears: no fixation (lyses RBCs for parasite concentration). Rinse, dry, examine under oil immersion.", "Malaria: ring forms (trophozoites) in RBCs with blue cytoplasm and red chromatin dot. P. falciparum: multiple rings per RBC, banana-shaped gametocytes. Babesia: ring forms resembling P. falciparum but tetrad (Maltese cross) diagnostic. Intracellular bacteria (Chlamydia inclusions, Histoplasma in macrophages).", "No intracellular organisms. Normal RBC morphology. No parasites identified.", "Malaria species identification (thick and thin smears). Babesiosis. Leishmaniasis (amastigotes in macrophages). Chlamydia inclusions. Borrelia (spirochetes in blood).", "Murray 9th ed, Ch 67, p 741; Mahon 6th ed, Ch 5, p 76") }

    // ── SILVER STAIN (GMS / WARTHIN-STARRY) ────────────────
    // Silver impregnation techniques. GMS (Grocott methenamine silver)
    // for fungi in tissue. Warthin-Starry for Legionella, Bartonella,
    // H. pylori in tissue sections.
    // Murray 9th ed, Ch 33, p 374. Mahon 6th ed, Ch 5, p 77.
    if name == "silver" { return smethod("Silver stain (GMS and Warthin-Starry)", "Impregnation (tissue sections)", "GMS (Grocott): Chromic acid oxidation, then methenamine-silver nitrate (silver ions reduced to metallic silver on fungal cell walls). Black fungal elements on green background (light green counterstain). Warthin-Starry: silver nitrate with hydroquinone developer for bacteria in tissue.", "GMS: black fungal cell walls on green background. Pneumocystis jirovecii: cysts as crushed ping-pong balls. Aspergillus: septate hyphae, 45-degree branching. Warthin-Starry: black bacteria against yellow-brown background. Legionella, Bartonella, H. pylori.", "No organisms stained. Normal tissue architecture only.", "Fungal identification in tissue (Pneumocystis, Aspergillus, Histoplasma, Blastomyces). Legionella pneumophila in lung tissue. Bartonella in tissue. Cat scratch disease.", "Murray 9th ed, Ch 33, p 374; Ch 59, p 667; Mahon 6th ed, Ch 5, p 77") }

    // ── PAS (PERIODIC ACID-SCHIFF) STAIN ───────────────────
    // Periodic acid oxidizes carbohydrate hydroxyl groups to aldehydes.
    // Schiff reagent reacts with aldehydes to produce magenta/pink color.
    // Detects fungi, glycogen, mucin in tissue.
    // Murray 9th ed, Ch 59, p 667.
    if name == "PAS" { return smethod("PAS (periodic acid-Schiff) stain", "Histochemical (carbohydrate detection)", "Step 1: Periodic acid (oxidizes vicinal hydroxyl groups on carbohydrates to aldehyde groups). Step 2: Schiff reagent (pararosaniline in sulfurous acid, reacts with aldehydes to produce magenta/pink color). Step 3: Counterstain with hematoxylin.", "Fungal cell walls: magenta/pink (rich in polysaccharides). Tropheryma whipplei (Whipple disease): PAS-positive macrophages in lamina propria of small intestine.", "No PAS-positive organisms. Normal tissue.", "Fungal infections in tissue. Whipple disease (T. whipplei). Glycogen storage diseases. Mucin-secreting tumors.", "Murray 9th ed, Ch 59, p 667") }

    // ── WRIGHT STAIN ───────────────────────────────────────
    // Romanowsky stain for peripheral blood smears. Eosin (acidic,
    // stains basic structures pink) + methylene blue (basic, stains
    // acidic structures blue/purple). Standard for CBC differentials.
    // Mahon 6th ed, Ch 5, p 76.
    if name == "Wright" { return smethod("Wright stain", "Differential (blood smear)", "Air-dry blood smear. Fix with methanol component of Wright stain (1-2 min). Apply Wright stain (eosin + methylene blue in methanol). Add phosphate buffer pH 6.8 for 3-5 minutes. Rinse, dry, oil immersion.", "RBCs: pink/salmon (eosin stains hemoglobin). WBC nuclei: blue-purple (methylene blue). Neutrophil granules: lilac/pink. Eosinophil granules: bright orange-red. Basophil granules: dark blue-purple. Malaria parasites: blue cytoplasm, red chromatin.", "Normal blood smear morphology. No parasites or abnormal cells.", "CBC differential. Malaria parasites. Babesia. Blood-borne bacteria (Borrelia, Anaplasma/Ehrlichia morulae). Atypical lymphocytes (EBV). Sickle cells, spherocytes.", "Mahon 6th ed, Ch 5, p 76") }

    return smethod("Unknown", "", "", "", "", "", "")
}


// ═══════════════════════════════════════════════════════════════
// SECTION FIVE: ANTIBIOTIC SUSCEPTIBILITY (CLSI M100 Ed34, 2024)
// ═══════════════════════════════════════════════════════════════
//
// MIC breakpoints (ug/mL) define Susceptible (S), Intermediate (I),
// and Resistant (R) categories per CLSI M100 Performance Standards
// for Antimicrobial Susceptibility Testing, 34th Edition, 2024.
//
// S = MIC at which most infections respond to standard dosing.
// I = MIC requiring increased dosing or specific site accumulation.
// R = MIC at which standard therapy is expected to fail.
//
// Breakpoints are organism-drug specific. Using wrong breakpoints
// can lead to treatment failure or inappropriate resistance calls.
//
// CLSI M100 Ed34, 2024. Tables 2A-2J.

fn antibiotic_breakpoint(organism: String, drug: String) -> AntibioticBreakpoint {

    // ═══════════════════════════════════════════════
    // STAPHYLOCOCCUS AUREUS
    // CLSI M100 Ed34, 2024, Table 2C.
    // ═══════════════════════════════════════════════

    // Oxacillin: surrogate test for all beta-lactams.
    // MRSA (mecA/mecC positive) = resistant to ALL beta-lactams
    // (penicillins, cephalosporins, carbapenems) regardless of MIC.
    // S <= 2, R >= 4. Cefoxitin disk screen preferred (30 ug, zone <= 21 = MRSA).
    if organism == "S_aureus" {
        if drug == "oxacillin" { return abp("Staphylococcus aureus", "Oxacillin", 2.0, 0.0, 4.0, "ug/mL", "MIC by broth dilution or cefoxitin disk screen (30 ug disk, zone <= 21 mm = MRSA). mecA/mecC gene detection by PCR is definitive.", "CLSI M100 Ed34, 2024, Table 2C") }
        // Vancomycin: last-line for MRSA. VISA (MIC 4-8), VRSA (MIC >= 16).
        // No disk diffusion for S. aureus vancomycin (MIC only).
        if drug == "vancomycin" { return abp("Staphylococcus aureus", "Vancomycin", 2.0, 4.0, 16.0, "ug/mL", "MIC by broth microdilution ONLY. Do NOT use disk diffusion for vancomycin vs staphylococci. VISA: MIC 4-8 ug/mL. VRSA: MIC >= 16 ug/mL (vanA gene from Enterococcus).", "CLSI M100 Ed34, 2024, Table 2C") }
        return abp("Staphylococcus aureus", drug, 0.0, 0.0, 0.0, "ug/mL", "Not found in lookup", "CLSI M100 Ed34, 2024")
    }

    // ═══════════════════════════════════════════════
    // ENTEROCOCCUS
    // CLSI M100 Ed34, 2024, Table 2D.
    // ═══════════════════════════════════════════════

    if organism == "Enterococcus" {
        // Vancomycin: VRE is a major healthcare-associated pathogen.
        // vanA (high-level, inducible, transferable), vanB (variable level).
        // S <= 4, I 8-16, R >= 32.
        if drug == "vancomycin" { return abp("Enterococcus species", "Vancomycin", 4.0, 8.0, 32.0, "ug/mL", "MIC by broth microdilution or agar dilution. vanA: high-level resistance (MIC >= 64, transferable to S. aureus = VRSA risk). vanB: variable (MIC 16-512). vanC: intrinsic low-level in E. gallinarum/casseliflavus.", "CLSI M100 Ed34, 2024, Table 2D") }
        // Ampicillin: primary treatment for susceptible enterococcal infections.
        // E. faecalis usually susceptible. E. faecium usually resistant.
        // S <= 8, R >= 16.
        if drug == "ampicillin" { return abp("Enterococcus species", "Ampicillin", 8.0, 0.0, 16.0, "ug/mL", "MIC or disk diffusion (10 ug disk, S >= 17 mm). E. faecalis: usually ampicillin-susceptible. E. faecium: usually ampicillin-resistant (altered PBP5). Ampicillin is preferred over vancomycin when susceptible.", "CLSI M100 Ed34, 2024, Table 2D") }
        return abp("Enterococcus species", drug, 0.0, 0.0, 0.0, "ug/mL", "Not found in lookup", "CLSI M100 Ed34, 2024")
    }

    // ═══════════════════════════════════════════════
    // ESCHERICHIA COLI (Enterobacterales)
    // CLSI M100 Ed34, 2024, Table 2A.
    // ═══════════════════════════════════════════════

    if organism == "E_coli" {
        // Ciprofloxacin: fluoroquinolone. Resistance via gyrA/parC mutations
        // or plasmid-mediated qnr genes.
        // S <= 0.25, I 0.5, R >= 1.
        if drug == "ciprofloxacin" { return abp("Escherichia coli", "Ciprofloxacin", 0.25, 0.5, 1.0, "ug/mL", "MIC or disk (5 ug, S >= 21 mm, I 16-20, R <= 15). Resistance: chromosomal gyrA/parC mutations (topoisomerase targets) and plasmid-mediated qnr genes. Global resistance rates increasing (30-50% in some regions).", "CLSI M100 Ed34, 2024, Table 2A") }
        // Ceftriaxone: third-generation cephalosporin.
        // ESBL producers test susceptible in vitro but may fail clinically.
        // S <= 1, I 2, R >= 4.
        if drug == "ceftriaxone" { return abp("Escherichia coli", "Ceftriaxone", 1.0, 2.0, 4.0, "ug/mL", "MIC or disk (30 ug, S >= 23 mm, I 20-22, R <= 19). ESBL screening: ceftriaxone MIC >= 2 ug/mL triggers confirmatory testing (clavulanate synergy). ESBL genes: CTX-M (most common globally), TEM, SHV. Report ESBL producers as resistant to all cephalosporins.", "CLSI M100 Ed34, 2024, Table 2A") }
        // TMP-SMX (trimethoprim-sulfamethoxazole): folate pathway inhibitor.
        // S <= 2/38, R >= 4/76.
        if drug == "TMP-SMX" { return abp("Escherichia coli", "Trimethoprim-sulfamethoxazole", 2.0, 0.0, 4.0, "ug/mL (TMP component)", "MIC or disk (1.25/23.75 ug, S >= 16 mm, R <= 10 mm). Resistance: dfr genes (TMP target bypass) and sul genes (sulfonamide target bypass). Common first-line for uncomplicated UTI if local resistance < 20%.", "CLSI M100 Ed34, 2024, Table 2A") }
        return abp("Escherichia coli", drug, 0.0, 0.0, 0.0, "ug/mL", "Not found in lookup", "CLSI M100 Ed34, 2024")
    }

    // ═══════════════════════════════════════════════
    // PSEUDOMONAS AERUGINOSA
    // CLSI M100 Ed34, 2024, Table 2B-2.
    // ═══════════════════════════════════════════════

    if organism == "Pseudomonas" {
        // Piperacillin-tazobactam: extended-spectrum penicillin + BLI.
        // S <= 16/4, I 32/4-64/4, R >= 128/4.
        if drug == "piperacillin_tazobactam" { return abp("Pseudomonas aeruginosa", "Piperacillin-tazobactam", 16.0, 32.0, 128.0, "ug/mL (piperacillin component, fixed 4 ug/mL tazobactam)", "MIC by broth dilution. Tazobactam has limited activity against Pseudomonas AmpC beta-lactamase. Activity primarily from piperacillin binding PBPs. Important anti-pseudomonal agent for empiric therapy.", "CLSI M100 Ed34, 2024, Table 2B-2") }
        // Meropenem: carbapenem.
        // S <= 2, I 4, R >= 8.
        if drug == "meropenem" { return abp("Pseudomonas aeruginosa", "Meropenem", 2.0, 4.0, 8.0, "ug/mL", "MIC by broth dilution or disk (10 ug, S >= 19 mm, I 16-18, R <= 15). Resistance: loss of OprD porin (most common), MBL production (VIM, NDM, IMP), efflux pumps (MexAB-OprM). Imipenem breakpoints differ from meropenem.", "CLSI M100 Ed34, 2024, Table 2B-2") }
        // Cefepime: fourth-generation cephalosporin.
        // S <= 8, SDD 16, R >= 32.
        if drug == "cefepime" { return abp("Pseudomonas aeruginosa", "Cefepime", 8.0, 16.0, 32.0, "ug/mL", "MIC or disk (30 ug, S >= 18 mm, SDD 15-17, R <= 14). CLSI uses SDD (susceptible-dose dependent) instead of I for cefepime vs Pseudomonas. SDD = susceptible at higher doses (2g q8h vs standard 1g q12h). Extended infusion improves PK/PD.", "CLSI M100 Ed34, 2024, Table 2B-2") }
        return abp("Pseudomonas aeruginosa", drug, 0.0, 0.0, 0.0, "ug/mL", "Not found in lookup", "CLSI M100 Ed34, 2024")
    }

    // ═══════════════════════════════════════════════
    // STREPTOCOCCUS PNEUMONIAE
    // CLSI M100 Ed34, 2024, Table 2G.
    // Breakpoints depend on site of infection (meningitis vs non-meningitis).
    // ═══════════════════════════════════════════════

    if organism == "S_pneumoniae" {
        // Penicillin: breakpoints revised in 2008.
        // Non-meningitis (oral penicillin V): S <= 0.06, I 0.12-1, R >= 2.
        // Non-meningitis (parenteral penicillin G): S <= 2, I 4, R >= 8.
        // Meningitis: S <= 0.06, R >= 0.12 (no intermediate).
        if drug == "penicillin" { return abp("Streptococcus pneumoniae", "Penicillin", 2.0, 4.0, 8.0, "ug/mL (parenteral, non-meningitis)", "MIC required (disk diffusion with oxacillin 1 ug disk screens only: zone >= 20 = susceptible to penicillin, < 20 = need MIC). Meningitis breakpoints stricter: S <= 0.06, R >= 0.12. Resistance via altered PBPs (pbp1a, pbp2b, pbp2x mosaic genes). No beta-lactamase in pneumococcus.", "CLSI M100 Ed34, 2024, Table 2G") }
        // Ceftriaxone: commonly used for empiric meningitis and pneumonia.
        // Non-meningitis: S <= 1, I 2, R >= 4.
        // Meningitis: S <= 0.5, I 1, R >= 2.
        if drug == "ceftriaxone" { return abp("Streptococcus pneumoniae", "Ceftriaxone", 1.0, 2.0, 4.0, "ug/mL (non-meningitis)", "MIC by broth dilution or Etest. Non-meningitis: S <= 1, I 2, R >= 4. Meningitis: S <= 0.5, I 1, R >= 2. Third-gen cephalosporin resistance via altered PBPs. Empiric meningitis: vancomycin + ceftriaxone until susceptibility known.", "CLSI M100 Ed34, 2024, Table 2G") }
        return abp("Streptococcus pneumoniae", drug, 0.0, 0.0, 0.0, "ug/mL", "Not found in lookup", "CLSI M100 Ed34, 2024")
    }

    return abp("Unknown", drug, 0.0, 0.0, 0.0, "ug/mL", "", "")
}


// ═══════════════════════════════════════════════════════════════
// SECTION SIX: CLINICAL IDENTIFICATION ALGORITHMS
// ═══════════════════════════════════════════════════════════════
//
// These functions encode the decision trees that clinical
// microbiologists use to identify unknown isolates. Start with
// Gram stain morphology, then apply sequential biochemical tests.
//
// Murray 9th ed, Ch 16-19. Mahon 6th ed, Ch 7-9.

fn identify_gram_positive_coccus(catalase_pos: Bool, coagulase_pos: Bool, optochin_sens: Bool, bacitracin_sens: Bool, bile_esculin_pos: Bool, pyr_pos: Bool) -> String {
    // Step 1: Catalase
    if catalase_pos == true {
        // Staphylococcus (catalase+)
        if coagulase_pos == true { return "Staphylococcus aureus (catalase+, coagulase+). Confirm with DNase, mannitol fermentation. MRSA screen with cefoxitin disk or mecA PCR." }
        return "Coagulase-negative Staphylococcus (catalase+, coagulase-). Novobiocin: sensitive = S. epidermidis, resistant = S. saprophyticus (UTI pathogen in young women)."
    }
    // Catalase-negative: Streptococcus or Enterococcus
    // Step 2: Hemolysis pattern determines next test
    if optochin_sens == true { return "Streptococcus pneumoniae (catalase-, alpha-hemolytic, optochin-sensitive, bile-soluble). Lancet-shaped diplococci. Quellung reaction for serotyping." }
    if bacitracin_sens == true { return "Group A Streptococcus - S. pyogenes (catalase-, beta-hemolytic, bacitracin-sensitive, PYR+). Pharyngitis, impetigo, necrotizing fasciitis, rheumatic fever, PSGN." }
    if bile_esculin_pos == true {
        if pyr_pos == true { return "Enterococcus (catalase-, gamma/alpha-hemolytic, bile esculin+, PYR+, growth in 6.5% NaCl). E. faecalis (most common) or E. faecium (often VRE). Check vancomycin susceptibility." }
        return "Group D Streptococcus - S. gallolyticus/bovis (catalase-, bile esculin+, PYR-). Associated with colon cancer -- colonoscopy recommended if isolated from blood cultures."
    }
    return "Further testing needed. Consider CAMP test (Group B Strep if positive), Lancefield grouping, or MALDI-TOF."
}

fn identify_gram_negative_rod(oxidase_pos: Bool, lactose_ferm: Bool, indole_pos: Bool, h2s_pos: Bool, motile: Bool, urease_pos: Bool) -> String {
    if oxidase_pos == true { return "Oxidase-positive gram-negative rod. Consider: Pseudomonas aeruginosa (green pigment, grape odor, 42C growth), Vibrio (curved rod, TCBS), Campylobacter (42C microaerophilic, seagull-wing morphology), Aeromonas (freshwater exposure)." }
    // Oxidase-negative = Enterobacteriaceae
    if lactose_ferm == true {
        if indole_pos == true { return "Escherichia coli (oxidase-, lactose+, indole+, MR+, VP-, citrate-). Most common gram-negative in clinical specimens. EMB: metallic green sheen. Check ESBL if ceftriaxone MIC >= 2." }
        return "Lactose-fermenting, indole-negative Enterobacteriaceae. Likely Klebsiella pneumoniae (mucoid colonies, urease+, VP+, non-motile, citrate+) or Enterobacter (motile, VP+, citrate+)."
    }
    // Non-lactose fermenter
    if h2s_pos == true { return "Non-lactose fermenter with H2S production. Likely Salmonella (motile, H2S+, citrate+, lysine decarboxylase+). Green colonies with black center on HE agar. Serotyping for epidemiology." }
    if motile == false { return "Non-lactose fermenter, non-motile, H2S-negative. Likely Shigella (non-motile, H2S-, gas-negative from glucose, lysine decarboxylase-). Green colonies on HE agar without black center." }
    if urease_pos == true { return "Non-lactose fermenter, motile, urease-positive. Likely Proteus (swarming motility on BAP, urease+ rapid, H2S variable). P. mirabilis: indole-negative. P. vulgaris: indole-positive." }
    return "Non-lactose fermenting Enterobacteriaceae. Further biochemical testing or MALDI-TOF identification required. Consider Serratia (red pigment), Citrobacter, Providencia."
}


// ═══════════════════════════════════════════════════════════════
// SECTION SEVEN: QUICK-REFERENCE FUNCTIONS
// ═══════════════════════════════════════════════════════════════

fn biochem_test_count() -> Int {
    return 21
}

fn culture_media_count() -> Int {
    return 10
}

fn staining_method_count() -> Int {
    return 7
}

fn breakpoint_organism_count() -> Int {
    return 5
}

fn growth_condition_count() -> Int {
    return 18
}

fn hemolysis_type(pattern: String) -> String {
    if pattern == "alpha" { return "Alpha hemolysis: partial lysis of RBCs. Green/olive discoloration around colonies (hemoglobin oxidized to methemoglobin by H2O2). Organisms: S. pneumoniae, viridans streptococci (S. mitis, S. mutans, S. sanguinis)." }
    if pattern == "beta" { return "Beta hemolysis: complete lysis of RBCs. Clear/transparent zone around colonies. Streptolysin O (oxygen-labile) and Streptolysin S (oxygen-stable) destroy RBCs. Organisms: S. pyogenes (Group A), S. agalactiae (Group B), S. aureus." }
    if pattern == "gamma" { return "Gamma hemolysis: no hemolysis. No change in blood agar around colonies. Organisms: Enterococcus (most), Group D Streptococcus." }
    return "Unknown hemolysis pattern. Valid patterns: alpha, beta, gamma."
}

fn imvic_pattern(organism: String) -> String {
    // IMViC: Indole, Methyl Red, VP, Citrate
    // Classic pattern for Enterobacteriaceae differentiation
    if organism == "E_coli" { return "E. coli IMViC: +, +, -, - (Indole+, MR+, VP-, Citrate-)" }
    if organism == "Klebsiella" { return "Klebsiella IMViC: -, -, +, + (Indole-, MR-, VP+, Citrate+)" }
    if organism == "Enterobacter" { return "Enterobacter IMViC: -, -, +, + (Indole-, MR-, VP+, Citrate+). Same as Klebsiella but motile and ornithine decarboxylase+." }
    if organism == "Citrobacter" { return "Citrobacter IMViC: -, +, -, + (Indole variable, MR+, VP-, Citrate+). H2S variable." }
    if organism == "Salmonella" { return "Salmonella IMViC: -, +, -, + (Indole-, MR+, VP-, Citrate+ usually). H2S+, motile, lysine decarboxylase+." }
    if organism == "Shigella" { return "Shigella IMViC: variable, +, -, - (Indole variable, MR+, VP-, Citrate-). Non-motile, H2S-, gas-negative." }
    return "Unknown organism for IMViC pattern."
}

fn x_and_v_factor_requirement(organism: String) -> String {
    // Haemophilus species identification by growth factor requirements
    // X factor = hemin (protoporphyrin IX). V factor = NAD (nicotinamide adenine dinucleotide).
    if organism == "H_influenzae" { return "H. influenzae: requires BOTH X (hemin) and V (NAD) factors. Grows on chocolate agar (both released from lysed RBCs). Satellitism around S. aureus on BAP (S. aureus secretes V factor)." }
    if organism == "H_parainfluenzae" { return "H. parainfluenzae: requires V factor (NAD) only. Does not require X factor." }
    if organism == "H_ducreyi" { return "H. ducreyi: requires X factor (hemin) only. Chancroid pathogen. Difficult to culture (special media)." }
    return "Unknown Haemophilus species."
}

fn mrsa_detection_method() -> String {
    return "MRSA detection: (1) Cefoxitin disk screen (30 ug disk, zone <= 21 mm = MRSA per CLSI M100 Ed34). (2) Oxacillin MIC >= 4 ug/mL. (3) mecA/mecC gene PCR (definitive). (4) PBP2a latex agglutination. mecA encodes PBP2a (penicillin-binding protein 2a) with low affinity for all beta-lactams. MRSA = resistant to ALL beta-lactams (penicillins, cephalosporins, carbapenems). Treat with vancomycin, daptomycin, linezolid, or TMP-SMX depending on site and susceptibility."
}

fn esbl_detection_method() -> String {
    return "ESBL detection: (1) Screen: ceftriaxone MIC >= 2 ug/mL or ceftazidime MIC >= 2 ug/mL. (2) Phenotypic confirmation: combination disk method (cefotaxime +/- clavulanate, zone difference >= 5 mm = ESBL). (3) Molecular: PCR for CTX-M, TEM, SHV genes. CTX-M is most prevalent globally. Report ESBL-producing Enterobacterales as resistant to all penicillins and cephalosporins. Treat with carbapenems (meropenem, ertapenem) or piperacillin-tazobactam (if MIC allows). CLSI M100 Ed34, 2024."
}

fn vre_detection_method() -> String {
    return "VRE detection: (1) Vancomycin MIC by broth microdilution: S <= 4, I 8-16, R >= 32 ug/mL. (2) Vancomycin agar screen (6 ug/mL vancomycin in BHI agar, growth at 24h = resistant). (3) Molecular: PCR for vanA (high-level, inducible, transferable on Tn1546) and vanB (variable level, inducible, NOT transferable to S. aureus). vanC: intrinsic low-level in E. gallinarum/casseliflavus (motile enterococci). Treat VRE with linezolid, daptomycin, or tigecycline. CLSI M100 Ed34, 2024."
}
