scripts/verify_iip0056_route4_omentum_and_exvivo_rest.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0056_route4_omentum_and_exvivo_rest.py · SHA-256: 25e12d578ba80b55…
if polyglactin_used is None:
hold_reasons.append("MISSING_POLYGLACTIN_BOOL")
elif not _is_strict_bool(polyglactin_used):
fail_reasons.append("INVALID_POLYGLACTIN_BOOL")
elif polyglactin_used:
fail_reasons.append("POLYGLACTIN_SUTURES_PROHIBITED_FBR_RISK")
ductal_pct = obs.get("ductal_cytokeratin_impurity_pct")
if ductal_pct is None:
hold_reasons.append("MISSING_DUCTAL_IMPURITY_PCT")
elif not _is_finite_number(ductal_pct):
fail_reasons.append("INVALID_DUCTAL_IMPURITY_PCT")
else:
ductal_d = _to_exact_decimal(ductal_pct)
if ductal_d < ZERO_DEC or ductal_d > Decimal("100"):
fail_reasons.append("INVALID_DUCTAL_IMPURITY_PCT")
elif ductal_d >= Decimal("2"):
fail_reasons.append("DUCTAL_IMPURITY_GE_2PCT_FAIL")
endotoxin = obs.get("endotoxin_eu_per_ml")
if endotoxin is None:
hold_reasons.append("MISSING_ENDOTOXIN_ASSAY")
elif not _is_finite_number(endotoxin):
fail_reasons.append("INVALID_ENDOTOXIN_ASSAY")
else:
endo_d = _to_exact_decimal(endotoxin)
if endo_d < ZERO_DEC:
fail_reasons.append("INVALID_ENDOTOXIN_ASSAY")
elif endo_d >= Decimal("0.5"):
fail_reasons.append("R4O_01_ENDOTOXIN_GE_0P5_EU_ML_FAIL")
sterility_ok = obs.get("sterility_pass")
if sterility_ok is None:
hold_reasons.append("MISSING_R4O01_STERILITY_ASSAY")
elif not _is_strict_bool(sterility_ok):
fail_reasons.append("INVALID_R4O01_STERILITY_BOOL")
elif not sterility_ok:
fail_reasons.append("R4O_01_STERILITY_FAILED")
myco_neg = obs.get("mycoplasma_negative")
if myco_neg is None:
hold_reasons.append("MISSING_R4O01_MYCOPLASMA_ASSAY")
elif not _is_strict_bool(myco_neg):
fail_reasons.append("INVALID_R4O01_MYCOPLASMA_BOOL")
elif not myco_neg:
fail_reasons.append("R4O_01_MYCOPLASMA_POSITIVE_FAIL")
fasl_ug = obs.get("analytical_fasl_ug")
if fasl_ug is None:
hold_reasons.append("MISSING_ANALYTICAL_FASL_ZERO_CERTIFICATION")
elif not _is_finite_number(fasl_ug):
fail_reasons.append("INVALID_ANALYTICAL_FASL_UG")
else:
fasl_d = _to_exact_decimal(fasl_ug)
if fasl_d < ZERO_DEC:
fail_reasons.append("INVALID_ANALYTICAL_FASL_UG")
elif fasl_d > ZERO_DEC:
fail_reasons.append("R4O_02_ANALYTICAL_FASL_NONZERO_VETO")
hep_casp = obs.get("hepatocyte_72h_caspase37_u95_fold")
if hep_casp is None:
hold_reasons.append("MISSING_R4O02_HEPATOCYTE_CASPASE37_ASSAY")
elif not _is_finite_number(hep_casp):
fail_reasons.append("INVALID_HEPATOCYTE_CASPASE37_ASSAY")
else:
hep_casp_d = _to_exact_decimal(hep_casp)
if hep_casp_d <= ZERO_DEC:
fail_reasons.append("INVALID_HEPATOCYTE_CASPASE37_ASSAY")
elif hep_casp_d > Decimal("1.15"):
fail_reasons.append("R4O_02_HEPATOCYTE_CASPASE37_EXCEEDS_1P15X_FAIL")
hep_alt = obs.get("hepatocyte_72h_alt_ldh_u95_fold")
if hep_alt is None:
hold_reasons.append("MISSING_R4O02_HEPATOCYTE_ALT_LDH_ASSAY")
elif not _is_finite_number(hep_alt):
fail_reasons.append("INVALID_HEPATOCYTE_ALT_LDH_ASSAY")
else:
hep_alt_d = _to_exact_decimal(hep_alt)
if hep_alt_d <= ZERO_DEC:
fail_reasons.append("INVALID_HEPATOCYTE_ALT_LDH_ASSAY")
elif hep_alt_d > Decimal("1.15"):
fail_reasons.append("R4O_02_HEPATOCYTE_ALT_LDH_EXCEEDS_1P15X_FAIL")
leachate_ok = obs.get("cuff_leachate_assay_passed")
if leachate_ok is None:
hold_reasons.append("MISSING_R4O02_CUFF_LEACHATE_ASSAY")
elif not _is_strict_bool(leachate_ok):
fail_reasons.append("INVALID_CUFF_LEACHATE_BOOL")
elif not leachate_ok:
fail_reasons.append("R4O_02_CUFF_LEACHATE_ASSAY_FAILED")
# 5. Physical Geometry, Sieving (40..65 um), Layout, Plane Offset (|z_c| >= 20 um)
layout = obs.get("construct_layout")
if layout is None:
hold_reasons.append("MISSING_CONSTRUCT_LAYOUT")
elif not _is_literal_nonempty_str(layout) or layout != "STAGGERED_BILAYER":
fail_reasons.append("CONSTRUCT_LAYOUT_MUST_BE_STAGGERED_BILAYER")
h_um = obs.get("construct_thickness_um")
h_d: Optional[Decimal] = None
h_domain_ok = False
if h_um is None:
hold_reasons.append("MISSING_CONSTRUCT_THICKNESS_UM")
elif not _is_finite_number(h_um):
fail_reasons.append("CONSTRUCT_THICKNESS_OUTSIDE_100_TO_120UM_FAIL")
else:
h_d = _to_exact_decimal(h_um)
if h_d < Decimal("100") or h_d > Decimal("120"):
fail_reasons.append("CONSTRUCT_THICKNESS_OUTSIDE_100_TO_120UM_FAIL")
else:
h_domain_ok = True
d_min = obs.get("cluster_min_diam_um")
d_rms3 = obs.get("cluster_d_rms3_um")
d_p95 = obs.get("cluster_d_p95_um")
d_max = obs.get("cluster_max_diam_um")
d_min_d: Optional[Decimal] = None
d_rms3_d: Optional[Decimal] = None
d_p95_d: Optional[Decimal] = None
d_max_d: Optional[Decimal] = None
if d_min is None:
hold_reasons.append("MISSING_CLUSTER_MIN_DIAM_UM")
elif not _is_finite_number(d_min):
fail_reasons.append("CLUSTER_MIN_DIAM_OUTSIDE_40_TO_65UM_FAIL")
else:
d_min_d = _to_exact_decimal(d_min)
if d_min_d < Decimal("40") or d_min_d > Decimal("65"):
fail_reasons.append("CLUSTER_MIN_DIAM_OUTSIDE_40_TO_65UM_FAIL")
if d_rms3 is None:
hold_reasons.append("MISSING_CLUSTER_D_RMS3_UM")
elif not _is_finite_number(d_rms3):
fail_reasons.append("CLUSTER_D_RMS3_OUTSIDE_40_TO_65UM_FAIL")
else:
d_rms3_d = _to_exact_decimal(d_rms3)
if d_rms3_d < Decimal("40") or d_rms3_d > Decimal("65"):
fail_reasons.append("CLUSTER_D_RMS3_OUTSIDE_40_TO_65UM_FAIL")
if d_p95 is None:
hold_reasons.append("MISSING_CLUSTER_D_P95_UM")
elif not _is_finite_number(d_p95):
fail_reasons.append("CLUSTER_D_P95_OUTSIDE_40_TO_65UM_FAIL")
else:
d_p95_d = _to_exact_decimal(d_p95)
if d_p95_d < Decimal("40") or d_p95_d > Decimal("65"):
fail_reasons.append("CLUSTER_D_P95_OUTSIDE_40_TO_65UM_FAIL")
if d_max is None:
hold_reasons.append("MISSING_CLUSTER_MAX_DIAM_UM")
elif not _is_finite_number(d_max):
fail_reasons.append("CLUSTER_MAX_DIAM_EXCEEDS_65UM_SIEVING_LAW")
else:
d_max_d = _to_exact_decimal(d_max)
if d_max_d < Decimal("40") or d_max_d > Decimal("65"):
fail_reasons.append("CLUSTER_MAX_DIAM_EXCEEDS_65UM_SIEVING_LAW")
diam_domain_ok = False
if d_min_d is not None and d_rms3_d is not None and d_p95_d is not None and d_max_d is not None:
if Decimal("40") <= d_min_d <= d_rms3_d <= d_p95_d <= d_max_d <= Decimal("65"):
diam_domain_ok = True
else:
fail_reasons.append("CLUSTER_DIAMETER_QUANTILE_ORDER_INVALID")
z_c_val = obs.get("staggered_bilayer_plane_offset_um")
z_c_d: Optional[Decimal] = None
zc_domain_ok = False
if z_c_val is None:
hold_reasons.append("MISSING_STAGGERED_BILAYER_PLANE_OFFSET_UM")
elif not _is_finite_number(z_c_val):
fail_reasons.append("STAGGERED_BILAYER_PLANE_OFFSET_LT_20UM_FAIL")
else:
z_c_d = _to_exact_decimal(z_c_val)
if z_c_d < Decimal("20") or z_c_d > Decimal("60"):
fail_reasons.append("STAGGERED_BILAYER_PLANE_OFFSET_LT_20UM_FAIL")
else:
zc_domain_ok = True
if h_domain_ok and diam_domain_ok and zc_domain_ok and h_d is not None and d_max_d is not None and z_c_d is not None:
half_h_d = _dec_mul(Decimal("0.5"), h_d)
outer_edge_d = _dec_add(z_c_d, _dec_mul(Decimal("0.5"), d_max_d))
wall_clear_d = _dec_sub(half_h_d, outer_edge_d)
if outer_edge_d > half_h_d:
fail_reasons.append("CLUSTER_PROTRUDES_OUTSIDE_SLAB_THICKNESS_FAIL")
elif wall_clear_d < MIN_GY028_WALL_CLEARANCE_UM_DEC:
fail_reasons.append("GY028_WALL_CLEARANCE_LT_7P5UM_FAIL")
# 6. Bilateral Face Bed pO2, Measured O2, Lot OCR, Per-Leaf Reconciliation (Audit F4),
# Actual Max-Leaf Steric Packing (Review #6 / Audit R4-03), Scope-Bound scale_mode, & Tier Union
bi_perf = obs.get("bilateral_vascular_perfusion_verified")
if bi_perf is None:
hold_reasons.append("MISSING_BILATERAL_PERFUSION_VERIFICATION")
elif not _is_strict_bool(bi_perf):
fail_reasons.append("INVALID_BILATERAL_PERFUSION_BOOL")
elif not bi_perf:
fail_reasons.append("UNILATERAL_PERFUSION_ANOXIA_FAIL")
stacked = obs.get("back_to_back_unperfused_stacking")
if stacked is None:
hold_reasons.append("MISSING_BACK_TO_BACK_STACKING_BOOL")
elif not _is_strict_bool(stacked):
fail_reasons.append("INVALID_BACK_TO_BACK_STACKING_BOOL")
elif stacked:
fail_reasons.append("BACK_TO_BACK_UNPERFUSED_FOLDED_STACKING_PROHIBITED")
loading = _extract_areal_loading_with_alias(
obs, fail_reasons=fail_reasons, mismatch_code="INCONSISTENT_AREAL_LOADING_ALIAS_FIELD",
)
loading_d: Optional[Decimal] = None
loading_domain_ok = False
if loading is None:
hold_reasons.append("MISSING_AREAL_LOADING_IEQ_CM2")
elif not _is_finite_number(loading):
fail_reasons.append("INVALID_AREAL_LOADING")
else:
loading_d = _to_exact_decimal(loading)
if not (ONE_DEC <= loading_d <= Decimal("1e6")):
fail_reasons.append("INVALID_AREAL_LOADING")
else:
loading_domain_ok = True
bed_bot = obs.get("bed_face_bot_po2_mmhg")
bed_top = obs.get("bed_face_top_po2_mmhg")
bed_bot_d: Optional[Decimal] = None
bed_top_d: Optional[Decimal] = None
if bed_bot is None:
hold_reasons.append("MISSING_BED_FACE_BOT_PO2_MMHG")
elif not _is_finite_number(bed_bot):
fail_reasons.append("INVALID_BED_FACE_BOT_PO2_MMHG")
else:
bed_bot_d = _to_exact_decimal(bed_bot)
if bed_bot_d <= ZERO_DEC:
fail_reasons.append("INVALID_BED_FACE_BOT_PO2_MMHG")
bed_bot_d = None
if bed_top is None:
hold_reasons.append("MISSING_BED_FACE_TOP_PO2_MMHG")
elif not _is_finite_number(bed_top):
fail_reasons.append("INVALID_BED_FACE_TOP_PO2_MMHG")
else:
bed_top_d = _to_exact_decimal(bed_top)
if bed_top_d <= ZERO_DEC:
fail_reasons.append("INVALID_BED_FACE_TOP_PO2_MMHG")
bed_top_d = None
min_bed_po2_d: Optional[Decimal] = None
max_bed_po2_d: Optional[Decimal] = None
if bed_bot_d is not None and bed_top_d is not None:
min_bed_po2_d = min(bed_bot_d, bed_top_d)
max_bed_po2_d = max(bed_bot_d, bed_top_d)