om_perf = s.get("omentectomy_performed") om_proc_id = s.get("omentectomy_procedure_id") om_d = s.get("omentectomy_day") ext_sid = s.get("cpeptide_extinction_subject_id") ext_pid = s.get("cpeptide_extinction_procedure_id") cpep_d = s.get("cpeptide_extinction_assessment_day") ext_out = s.get("post_omentectomy_cpeptide_extinguished") port_d = s.get("portal_gradient_assessment_day") day_v = s.get("insulin_indep_day") cap_v = s.get("month3_capsule_um") ins_v = s.get("residual_exogenous_insulin_u_kg_d") gsis_v = s.get("paired_dynamic_gsis_pass") retr_v = s.get("retrieval_mass_pct") tot_cells_v = s.get("total_implanted_cells") res_cells_v = s.get("residual_viable_cells_measured") samp_frac_v = s.get("residual_sampling_fraction") loc_v = s.get("localization_verified") elig_types_ok = True base_ins_d: Optional[Decimal] = None base_cpep_d: Optional[Decimal] = None dose_d: Optional[Decimal] = None if pre_diab is not None and not _is_strict_bool(pre_diab): fail_reasons.append("INVALID_NHP_PREIMPLANT_DIABETIC_BOOL") elig_types_ok = False if base_ins is not None: if not _is_finite_number(base_ins) or _to_exact_decimal(base_ins) < ZERO_DEC: fail_reasons.append("INVALID_NHP_BASELINE_EXOGENOUS_INSULIN") elig_types_ok = False else: base_ins_d = _to_exact_decimal(base_ins) if base_cpep is not None: if not _is_finite_number(base_cpep) or _to_exact_decimal(base_cpep) < ZERO_DEC: fail_reasons.append("INVALID_NHP_BASELINE_FASTING_C_PEPTIDE") elig_types_ok = False else: base_cpep_d = _to_exact_decimal(base_cpep) types_ok = elig_types_ok and (not sid_adverse) if dose_v is not None: if not _is_finite_number(dose_v) or _to_exact_decimal(dose_v) <= ZERO_DEC: fail_reasons.append("INVALID_NHP_SUBJECT_DOSE_IEQ_PER_KG") types_ok = False else: dose_d = _to_exact_decimal(dose_v) if achieved_ii is not None and not _is_strict_bool(achieved_ii): fail_reasons.append("INVALID_NHP_ACHIEVED_INSULIN_INDEPENDENCE_BOOL") types_ok = False fu_val: Optional[Decimal] = None if followup_d is not None: if not _is_finite_number(followup_d) or _to_exact_decimal(followup_d) <= Decimal("0"): fail_reasons.append("INVALID_NHP_FOLLOWUP_DURATION_DAYS") types_ok = False else: fu_val = _to_exact_decimal(followup_d) cap_d_val: Optional[Decimal] = None nhp_cap_day_ok = False if cap_d is not None: if not _is_finite_number(cap_d) or _to_exact_decimal(cap_d) <= Decimal("0"): fail_reasons.append("INVALID_NHP_CAPSULE_SAMPLING_DAY") types_ok = False else: cap_d_val = _to_exact_decimal(cap_d) cap_d_local = True if cap_d_val < NHP_MIN_FOLLOWUP_DAYS_DEC: fail_reasons.append("R4O_05_NHP_CAPSULE_SAMPLING_DAY_LT_90D_FAIL") cap_d_local = False types_ok = False if fu_val is not None and cap_d_val > fu_val: fail_reasons.append("R4O_05_NHP_CAPSULE_SAMPLING_DAY_EXCEEDS_FOLLOWUP_FAIL") cap_d_local = False types_ok = False nhp_cap_day_ok = cap_d_local # Round-7 Audit R6-05 + Round-8 Audit R7-08 / R7-13 + Round-9 Audit R8-04 / R8-05: # Require one complete, internally consistent procedure/extinction tuple — INCLUDING an explicit # non-None boolean post_omentectomy_cpeptide_extinguished in the verified archived row — whenever # achieved_insulin_independence is True OR ANY procedure/extinction field/alias is supplied, # enforce exact decimal.Decimal 0 <= (cpeptide_extinction_assessment_day - omentectomy_day) <= 14 # (ZERO ungoverned tolerance), and reject any intra-group alias conflict across all performed, # outcome, ID, and date groups. is_responder = (achieved_ii is True) nhp_binding_alias_adverse = False perf_bools: List[Tuple[str, bool]] = [] if om_perf is not None and _is_strict_bool(om_perf): perf_bools.append(("omentectomy_performed", om_perf)) for akey in NHP_OMENTECTOMY_PERFORMED_ALIAS_KEYS: if akey in s and s[akey] is not None: aval = s[akey] if not _is_strict_bool(aval): fail_reasons.append(f"INVALID_NHP_OMENTECTOMY_PERFORMED_ALIAS:{akey}") nhp_binding_alias_adverse = True else: perf_bools.append((akey, aval)) if len({v for _, v in perf_bools}) > 1: fail_reasons.append("NHP_CONFLICTING_OMENTECTOMY_PERFORMED_ALIAS_GROUP") nhp_binding_alias_adverse = True any_performed_true = any(v is True for _, v in perf_bools) any_performed_false = any(v is False for _, v in perf_bools) ext_outcome_bools: List[Tuple[str, bool]] = [] any_noncanonical_ext_outcome_present = False for akey in NHP_EXTINCTION_OUTCOME_BOOL_ALIAS_KEYS: if akey in s and s[akey] is not None: if akey != "post_omentectomy_cpeptide_extinguished": any_noncanonical_ext_outcome_present = True aval = s[akey] if not _is_strict_bool(aval): fail_reasons.append(f"INVALID_NHP_EXTINCTION_BOOL_ALIAS:{akey}") nhp_binding_alias_adverse = True else: ext_outcome_bools.append((akey, aval)) if len({v for _, v in ext_outcome_bools}) > 1: fail_reasons.append("NHP_CONFLICTING_EXTINCTION_OUTCOME_ALIAS_GROUP") nhp_binding_alias_adverse = True any_ext_outcome_true = any(v is True for _, v in ext_outcome_bools) any_ext_outcome_false = any(v is False for _, v in ext_outcome_bools) if is_responder and any_ext_outcome_false: fail_reasons.append("R4O_05_NHP_RESPONDER_POST_OMENTECTOMY_CPEP_NOT_EXTINGUISHED_FAIL") nhp_binding_alias_adverse = True # Round-14 Review fix: Decouple post-explant C-peptide extinction from full insulin independence. # Partial responders on residual exogenous insulin (achieved_insulin_independence == False) CAN # legitimately produce graft-derived stimulated C-peptide that extinguishes post-omentectomy, # verified independently via paired pre/post stimulated C-peptide against prespecified LLOQ # without inflating full insulin-independent responder counts (derived_nhp_qualified_ii_count). any_proc_date_present = (om_d is not None) or any(s.get(k) is not None for k in NHP_OMENTECTOMY_PROCEDURE_DATE_ALIAS_KEYS) any_proc_id_present = (om_proc_id is not None) or any(s.get(k) is not None for k in NHP_PROCEDURE_ID_ALIAS_KEYS) any_ext_sid_present = (ext_sid is not None) or any(s.get(k) is not None for k in NHP_EXTINCTION_SUBJECT_ID_ALIAS_KEYS) any_ext_pid_present = (ext_pid is not None) or any(s.get(k) is not None for k in NHP_EXTINCTION_PROCEDURE_ID_ALIAS_KEYS) any_ext_date_present = (cpep_d is not None) or any(s.get(k) is not None for k in NHP_CPEP_EXTINCTION_DATE_ALIAS_KEYS) any_proc_or_ext_evidence = ( any_performed_true or any_proc_date_present or any_proc_id_present or any_ext_sid_present or any_ext_pid_present or any_ext_date_present or any_ext_outcome_true ) require_proc_ext_tuple = is_responder or any_proc_or_ext_evidence # Round-9 Audit R8-04 + Round-14 Review decoupled paired C-peptide extinction & LLOQ verification: # Require explicit non-None boolean post_omentectomy_cpeptide_extinguished whenever ANY # procedure/extinction claim is present (or responder) or any non-canonical outcome alias is set; # whenever extinction is claimed (True, whether full or partial responder), require paired # pre/post stimulated C-peptide and prespecified LLOQ with exact Decimal pre > LLOQ and post <= LLOQ. ext_outcome_ok = True if ext_out is None: if require_proc_ext_tuple or any_noncanonical_ext_outcome_present: hold_reasons.append("MISSING_NHP_POST_OMENTECTOMY_EXTINCTION_OUTCOME") hold_reasons.append("NHP_INCOMPLETE_PROCEDURE_OR_EXTINCTION_TUPLE") ext_outcome_ok = False elif not _is_strict_bool(ext_out): ext_outcome_ok = False types_ok = False elif is_responder and ext_out is not True: ext_outcome_ok = False types_ok = False lloq_v = s.get("lloq_c_peptide_ng_ml") pre_cpep_v = s.get("pre_explant_stimulated_c_peptide_ng_ml") post_cpep_v = s.get("post_explant_stimulated_c_peptide_ng_ml") lloq_d: Optional[Decimal] = None pre_cpep_d: Optional[Decimal] = None post_cpep_d: Optional[Decimal] = None paired_cpep_ok = True if lloq_v is not None: if not _is_finite_number(lloq_v) or _to_exact_decimal(lloq_v) <= ZERO_DEC: fail_reasons.append("INVALID_NHP_LLOQ_CPEPTIDE_NG_ML") paired_cpep_ok = False types_ok = False else: lloq_d = _to_exact_decimal(lloq_v) if pre_cpep_v is not None: if not _is_finite_number(pre_cpep_v) or _to_exact_decimal(pre_cpep_v) < ZERO_DEC: fail_reasons.append("INVALID_NHP_PRE_EXPLANT_STIMULATED_CPEPTIDE") paired_cpep_ok = False types_ok = False else: pre_cpep_d = _to_exact_decimal(pre_cpep_v) if post_cpep_v is not None: if not _is_finite_number(post_cpep_v) or _to_exact_decimal(post_cpep_v) < ZERO_DEC: fail_reasons.append("INVALID_NHP_POST_EXPLANT_STIMULATED_CPEPTIDE") paired_cpep_ok = False types_ok = False else: post_cpep_d = _to_exact_decimal(post_cpep_v) if (ext_out is True) or any_ext_outcome_true: if lloq_v is None or pre_cpep_v is None or post_cpep_v is None: hold_reasons.append("MISSING_NHP_PAIRED_STIMULATED_CPEPTIDE_OR_LLOQ") hold_reasons.append("NHP_INCOMPLETE_PROCEDURE_OR_EXTINCTION_TUPLE") paired_cpep_ok = False elif lloq_d is not None and pre_cpep_d is not None and post_cpep_d is not None: if pre_cpep_d <= lloq_d: fail_reasons.append("R4O_05_NHP_PRE_EXPLANT_CPEPTIDE_NOT_ABOVE_LLOQ_FAIL") paired_cpep_ok = False types_ok = False if post_cpep_d > lloq_d: fail_reasons.append("R4O_05_NHP_POST_EXPLANT_CPEPTIDE_EXCEEDS_LLOQ_FAIL") paired_cpep_ok = False types_ok = False om_perf_ok = True if om_perf is None: if require_proc_ext_tuple: hold_reasons.append( "MISSING_NHP_RESPONDER_OMENTECTOMY_PERFORMED" if is_responder else "MISSING_NHP_OMENTECTOMY_PERFORMED" ) hold_reasons.append("NHP_INCOMPLETE_PROCEDURE_OR_EXTINCTION_TUPLE") om_perf_ok = False elif not _is_strict_bool(om_perf): fail_reasons.append("INVALID_NHP_OMENTECTOMY_PERFORMED_BOOL") om_perf_ok = False types_ok = False elif om_perf is False: if is_responder: fail_reasons.append("R4O_05_NHP_RESPONDER_OMENTECTOMY_NOT_PERFORMED_FAIL") om_perf_ok = False types_ok = False elif any_proc_or_ext_evidence: fail_reasons.append("R4O_05_NHP_OMENTECTOMY_PERFORMED_FALSE_CONTRADICTS_PROCEDURE_DATA_FAIL") om_perf_ok = False types_ok = False if any_performed_false and om_perf is not False: if is_responder: fail_reasons.append("R4O_05_NHP_RESPONDER_OMENTECTOMY_NOT_PERFORMED_FAIL") om_perf_ok = False types_ok = False elif any_proc_or_ext_evidence: fail_reasons.append("R4O_05_NHP_OMENTECTOMY_PERFORMED_FALSE_CONTRADICTS_PROCEDURE_DATA_FAIL") om_perf_ok = False types_ok = False om_proc_id_ok = True row_proc_dedup_added: Optional[str] = None if om_proc_id is None: if require_proc_ext_tuple: hold_reasons.append( "MISSING_NHP_RESPONDER_OMENTECTOMY_PROCEDURE_ID" if is_responder else "MISSING_NHP_OMENTECTOMY_PROCEDURE_ID" ) hold_reasons.append("NHP_INCOMPLETE_PROCEDURE_OR_EXTINCTION_TUPLE") om_proc_id_ok = False