This cookbook details how to deploy a localized, containerized reproductive endocrinology, infertility ($\text{REI}$), and in vitro fertilization ($\text{IVF}$) decision-support engine for fertility clinics, reproductive surgical centers, and emergency gynecology suites to ingest follicular ultrasound dimensions, peak estradiol ($\text{E}_2$) levels, oocyte yields, transvaginal pelvic fluid volumes, hematocrit hemoconcentration metrics, and renal perfusion telemetry, classify complications according to the Golan & Navot OHSS Clinical Staging (Mild, Moderate, Severe, Critical), automate Dopamine Agonist ($\text{Cabergoline } 0.5\text{ mg}$) $\text{VEGFR-2}$ Hyperpermeability Prophylaxis, enforce ASRM / ESHRE Primary Prevention Protocols (GnRH Agonist Trigger & Elective “Freeze-All” Embryo Cryopreservation), and manage Thromboembolism & Diuretic Hemoconcentration Safety Sentinels according to American Society for Reproductive Medicine ($\text{ASRM}$), ESHRE, and RCOG consensus guidelines without external cloud API reliance.
Ovarian Hyperstimulation Syndrome ($\text{OHSS}$) is a potentially life-threatening iatrogenic complication of controlled ovarian stimulation ($\text{COS}$) during assisted reproductive technology ($\text{ART}$), characterized by ovarian enlargement, massive capillary hyperpermeability, and fluid shift from the intravascular compartment into the third space:
[IVF Telemetry: AFC, Follicles >=11mm, E2, Oocytes, Ascites, Hct, WBC, Cr, Output]
│
▼
[Golan/Navot OHSS Staging: Mild vs Moderate vs Severe vs Critical OHSS]
│
▼
[Primary Prevention Gating: GnRH Agonist Trigger vs Elective Freeze-All]
│
▼
[Cabergoline Dopamine-Agonist VEGFR-2 Prophylaxis Titrator (0.5mg x 8d)]
│
▼
[Inpatient Resuscitation: Isotonic Crystalloids + Albumin + Paracentesis]
│
▼
[Safety Sentinels: Diuretic Hemoconcentration Hazard & LMWH VTE Prophylaxis]
Install required scientific Python and reproductive medicine modeling packages:
pip install numpy scipy pandas torch torchvision matplotlib
"""
Cookbook 354: Offline Reproductive Medicine OHSS Golan Staging & Cabergoline Prophylaxis 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 OHSSTelemetry:
patient_id: str
age_years: float = 29.0
bmi: float = 21.5 # Low BMI / PCOS phenotype = high risk
has_pcos: bool = True
antral_follicle_count: int = 34 # High baseline reserve
# Controlled Ovarian Stimulation Telemetry
total_follicles_ge_11mm: int = 24 # >= 20 follicles is high risk!
peak_serum_estradiol_pg_ml: float = 5400.0 # > 4,000 pg/mL is high risk!
oocytes_retrieved_count: int = 26 # >= 20 oocytes
trigger_agent_planned_or_used: str = "hCG 10,000 IU" # "hCG 10,000 IU", "GnRH Agonist (Leuprolide 1mg)", "Dual Trigger"
fresh_embryo_transfer_planned: bool = True # Freeze-all recommended!
# Physical Exam & TVUS Telemetry
clinical_symptoms: List[str] = None # ["Abdominal distension", "Nausea", "Dyspnea"]
ovarian_diameter_max_cm: float = 13.5 # > 12 cm = Severe
sonographic_ascites_location: str = "Gross ascites extending to upper abdomen" # "None", "Pelvic cul-de-sac", "Gross ascites extending to upper abdomen", "Pleural effusion"
# Laboratory & Hemodynamic Telemetry
hematocrit_percent: float = 48.2 # > 45% = Severe hemoconcentration!
white_blood_cell_count_per_ul: float = 17500.0 # > 15,000 /uL
serum_sodium_meq_l: float = 132.0 # Hyponatremia < 135
serum_potassium_meq_l: float = 5.2 # Hyperkalemia > 5.0
serum_creatinine_mg_dl: float = 1.2 # Mild renal impairment
urine_output_ml_kg_hr: float = 0.40 # Oliguria < 0.5 mL/kg/h
thromboembolic_event_present: bool = False
@dataclass
class OHSSEvaluationReport:
patient_id: str
golan_ohss_stage: str # "SEVERE OHSS (Grade 5)"
ohss_risk_profile: str
prevention_and_trigger_guidance: List[str]
cabergoline_prophylaxis_order: str
inpatient_resuscitation_protocol: List[str]
safety_sentinels: List[str]
clinical_asrm_eshre_directive: str
class OvarianHyperstimulationDecisionEngine:
"""
Offline clinical engine for Golan OHSS staging, cabergoline VEGFR-2 prophylaxis,
ASRM/ESHRE primary prevention gating, and hemoconcentration safety audit.
"""
def stage_golan_ohss(self, d: OHSSTelemetry) -> Tuple[str, str, List[str]]:
features = []
is_critical = (
d.hematocrit_percent >= 55.0 or
d.white_blood_cell_count_per_ul >= 25000.0 or
d.serum_creatinine_mg_dl >= 1.6 or
d.urine_output_ml_kg_hr < 0.15 or
d.thromboembolic_event_present or
"Pleural effusion" in d.sonographic_ascites_location
)
is_severe = (
d.ovarian_diameter_max_cm > 12.0 or
"Gross ascites" in d.sonographic_ascites_location or
d.hematocrit_percent >= 45.0 or
d.white_blood_cell_count_per_ul >= 15000.0 or
d.urine_output_ml_kg_hr < 0.50 or
d.serum_creatinine_mg_dl >= 1.0 or
d.serum_sodium_meq_l < 135.0
)
is_moderate = (
d.ovarian_diameter_max_cm >= 8.0 or
"Pelvic cul-de-sac" in d.sonographic_ascites_location
)
if d.hematocrit_percent >= 45.0: features.append(f"Severe Hemoconcentration (Hct {d.hematocrit_percent:.1f}% >= 45%)")
if d.white_blood_cell_count_per_ul >= 15000.0: features.append(f"Leukocytosis ({d.white_blood_cell_count_per_ul:.0f} /uL >= 15,000)")
if d.ovarian_diameter_max_cm > 12.0: features.append(f"Massive Ovarian Enlargement ({d.ovarian_diameter_max_cm:.1f} cm > 12 cm)")
if "Gross ascites" in d.sonographic_ascites_location: features.append("Clinical Gross Ascites")
if d.urine_output_ml_kg_hr < 0.50: features.append(f"Oliguria ({d.urine_output_ml_kg_hr:.2f} mL/kg/h < 0.50)")
if is_critical:
stage = "CRITICAL OHSS (Grade 6)"
risk = "Life-threatening complication with acute organ failure, massive third-spacing, and high thromboembolism mortality."
elif is_severe:
stage = "SEVERE OHSS (Grade 5)"
risk = "Severe hyperpermeability state requiring immediate hospital admission, volume expansion, and thromboprophylaxis."
elif is_moderate:
stage = "MODERATE OHSS (Grade 3)"
risk = "Moderate fluid shift with ultrasonic ascites requiring outpatient surveillance and cabergoline prophylaxis."
else:
stage = "MILD OHSS (Grades 1-2)"
risk = "Mild ovarian enlargement and distension; self-limiting with conservative hydration."
return stage, risk, features
def generate_prevention_plan(self, d: OHSSTelemetry) -> List[str]:
plan = []
is_high_responder = d.total_follicles_ge_11mm >= 18 or d.peak_serum_estradiol_pg_ml >= 4000.0 or d.oocytes_retrieved_count >= 20
if is_high_responder:
plan.append("1. PRIMARY PREVENTION - GnRH AGONIST TRIGGER:")
plan.append(" • If prior to trigger: CANCEL hCG trigger. Administer Leuprolide acetate 1.0 - 2.0 mg SC (or Triptorelin 0.2 mg) to induce endogenous LH surge with rapid luteal regression.")
plan.append("2. ELECTIVE 'FREEZE-ALL' EMBRYO CRYOPRESERVATION:")
plan.append(" • CANCEL fresh embryo transfer. Cryopreserve all 2PN zygotes / blastocysts. Eliminates pregnancy-derived endogenous hCG and prevents late-onset OHSS.")
else:
plan.append("1. Standard stimulation protocol with close monitoring.")
return plan
def generate_cabergoline_order(self, d: OHSSTelemetry) -> str:
return "Cabergoline 0.5 mg PO once daily at bedtime for 8 consecutive days (starting day of trigger / oocyte retrieval) to inhibit VEGFR-2 phosphorylation and reverse microvascular permeability."
def generate_inpatient_protocol(self, stage: str, d: OHSSTelemetry) -> Tuple[List[str], List[str]]:
protocol = []
sentinels = []
# Inpatient Medical Resuscitation for Severe/Critical OHSS
if "SEVERE" in stage or "CRITICAL" in stage:
protocol.append("1. INTRAVASCULAR VOLUME EXPANSION:")
protocol.append(" • Administer Isotonic Normal Saline (0.9% NaCl) or Plasmalyte at 125-150 mL/h to restore renal perfusion.")
protocol.append(" • If Hct remains >= 45% despite crystalloids: Administer 20-25% Human Albumin (50-100 mL IV over 2 hours) to increase intravascular oncotic pressure.")
protocol.append("2. THROMBOPROPHYLAXIS (MANDATORY):")
protocol.append(" • Enoxaparin 40 mg SC once daily + Graduated Compression Stockings (due to hypercoagulable third-spacing).")
protocol.append("3. ULTRASOUND-GUIDED PARACENTESIS / CULDOCENTESIS:")
protocol.append(" • Indicated for tense ascites, intractable pain, oliguria unresponsive to fluids, or respiratory compromise (relieves renal vein compression).")
# Safety Sentinels
if d.hematocrit_percent >= 45.0:
sentinels.append("🚨 ABSOLUTE DIURETIC PROHIBITION: NEVER administer Loop Diuretics (e.g. Furosemide) to an intravascularly depleted patient with elevated Hematocrit (Hct >= 45%). Diuretics precipitate acute hypovolemic collapse, acute tubular necrosis, and FATAL THROMBOEMBOLISM!")
if d.serum_potassium_meq_l >= 5.0:
sentinels.append(f"🚨 HYPERKALEMIA ALERT (K+ {d.serum_potassium_meq_l:.1f} mEq/L): Withhold potassium-containing IV fluids and potassium-sparing agents. Maintain continuous ECG monitoring.")
return protocol, sentinels
def evaluate_case(self, data: OHSSTelemetry) -> OHSSEvaluationReport:
stage, risk, features = self.stage_golan_ohss(data)
prev_plan = self.generate_prevention_plan(data)
cab_order = self.generate_cabergoline_order(data)
inpatient_plan, sentinels = self.generate_inpatient_protocol(stage, data)
directives = []
directives.append(f"STAGING: {stage}.")
directives.append("PRIMARY ACTIONS: GnRH agonist trigger + Elective Freeze-All + Cabergoline 0.5mg x 8d.")
directives.append("INPATIENT: Volume expansion + Albumin + Enoxaparin VTE prophylaxis.")
return OHSSEvaluationReport(
patient_id=data.patient_id,
golan_ohss_stage=stage,
ohss_risk_profile=risk,
prevention_and_trigger_guidance=prev_plan,
cabergoline_prophylaxis_order=cab_order,
inpatient_resuscitation_protocol=inpatient_plan,
safety_sentinels=sentinels,
clinical_asrm_eshre_directive=" ".join(directives)
)
# Example Execution & Verification
if __name__ == "__main__":
engine = OvarianHyperstimulationDecisionEngine()
print("=" * 80)
print("OpenPHR Clinical Reproductive Medicine OHSS Golan & Cabergoline Engine")
print("=" * 80)
# Test Case 1: 29-year-old female with PCOS undergoing IVF COS.
# Telemetry: 24 follicles >= 11mm, E2 5400 pg/mL, 26 oocytes retrieved.
# Exam & TVUS: Gross ascites, max ovarian diameter 13.5 cm.
# Labs: Hematocrit 48.2% (Severe hemoconcentration), WBC 17.5k, K+ 5.2, Oliguria 0.40 mL/kg/h.
# Staging: SEVERE OHSS (Grade 5).
# Actions: Elective Freeze-All + Cabergoline 0.5mg x 8d + Albumin/NS expansion + LMWH Enoxaparin!
# Sentinel: ABSOLUTE DIURETIC CONTRAINDICATION!
ohss1 = OHSSTelemetry(
patient_id="REI-IVF-9901",
age_years=29.0,
bmi=21.5,
has_pcos=True,
antral_follicle_count=34,
total_follicles_ge_11mm=24,
peak_serum_estradiol_pg_ml=5400.0,
oocytes_retrieved_count=26,
trigger_agent_planned_or_used="hCG 10,000 IU",
fresh_embryo_transfer_planned=True,
ovarian_diameter_max_cm=13.5,
sonographic_ascites_location="Gross ascites extending to upper abdomen",
hematocrit_percent=48.2,
white_blood_cell_count_per_ul=17500.0,
serum_sodium_meq_l=132.0,
serum_potassium_meq_l=5.2,
serum_creatinine_mg_dl=1.2,
urine_output_ml_kg_hr=0.40
)
rep1 = engine.evaluate_case(ohss1)
print(f"\n[Patient {rep1.patient_id} - OHSS Clinical Assessment]")
print(f"Golan OHSS Stage: {rep1.golan_ohss_stage}")
print(f"Risk Profile: {rep1.ohss_risk_profile}")
print("\nPrevention & Trigger Guidance:")
for p in rep1.prevention_and_trigger_guidance:
print(f" {p}")
print(f"\nVEGFR-2 Prophylaxis Order:\n {rep1.cabergoline_prophylaxis_order}")
print("\nInpatient Medical Resuscitation:")
for r in rep1.inpatient_resuscitation_protocol:
print(f" {r}")
if rep1.safety_sentinels:
print("\nSafety Sentinels:")
for s in rep1.safety_sentinels:
print(f" 🚨 {s}")
print(f"\nASRM / ESHRE Consensus Directive:\n{rep1.clinical_asrm_eshre_directive}")