fail_reasons.append("INVALID_NHP_SUBJECT_MONTH3_CAPSULE_UM") types_ok = False else: cap_um_d = _to_exact_decimal(cap_v) if cap_um_d < ZERO_DEC: fail_reasons.append("INVALID_NHP_SUBJECT_MONTH3_CAPSULE_UM") types_ok = False cap_um_d = None elif cap_um_d > tier_fibrin_max_d: fail_reasons.append("R4O_05_NHP_MONTH3_CAPSULE_EXCEEDS_TIER_MAX_FAIL") ins_d: Optional[Decimal] = None if ins_v is not None: if not _is_finite_number(ins_v) or _to_exact_decimal(ins_v) < ZERO_DEC: fail_reasons.append("INVALID_NHP_SUBJECT_RESIDUAL_INSULIN") types_ok = False else: ins_d = _to_exact_decimal(ins_v) if gsis_v is not None and not _is_strict_bool(gsis_v): fail_reasons.append("INVALID_NHP_SUBJECT_PAIRED_DYNAMIC_GSIS_BOOL") types_ok = False if loc_v is not None and not _is_strict_bool(loc_v): fail_reasons.append("INVALID_NHP_SUBJECT_LOCALIZATION_BOOL") types_ok = False retr_all_present = all(x is not None for x in (retr_v, tot_cells_v, res_cells_v, samp_frac_v)) retr_reconciled = _check_retrieval_residual_reconciliation( prefix="NHP", retrieval_mass_pct=retr_v, total_implanted_cells=tot_cells_v, residual_viable_cells_measured=res_cells_v, residual_sampling_fraction=samp_frac_v, require_ge_99p9=False, fail_reasons=fail_reasons, ) # Review #7 / Audit R4-04 / Audit R5-04 / Audit R8-05: exact Decimal Month-3 follow-up >= 90 d on responders + contradictory nonresponder event ban responder_day_ok = False responder_day_missing = False if _is_strict_bool(achieved_ii): if achieved_ii is True: if day_v is None: hold_reasons.append("MISSING_NHP_RESPONDER_INSULIN_INDEP_DAY") responder_day_missing = True elif not _is_finite_number(day_v) or _to_exact_decimal(day_v) <= Decimal("0"): fail_reasons.append("INVALID_NHP_SUBJECT_INSULIN_INDEP_DAY") types_ok = False else: day_v_dec = _to_exact_decimal(day_v) if fu_val is not None and day_v_dec > fu_val: fail_reasons.append("INVALID_NHP_SUBJECT_INSULIN_INDEP_DAY_EXCEEDS_FOLLOWUP") types_ok = False elif fu_val is not None and fu_val < NHP_MIN_FOLLOWUP_DAYS_DEC: fail_reasons.append("R4O_05_NHP_RESPONDER_FOLLOWUP_LT_90D_MONTH3_INCONSISTENT_FAIL") responder_day_ok = False else: responder_day_ok = (Decimal("0") < day_v_dec <= NHP_MAX_INSULIN_INDEP_DAY_DEC) and (fu_val is not None and fu_val >= NHP_MIN_FOLLOWUP_DAYS_DEC) if day_v is None and fu_val is not None and fu_val < NHP_MIN_FOLLOWUP_DAYS_DEC: fail_reasons.append("R4O_05_NHP_RESPONDER_FOLLOWUP_LT_90D_MONTH3_INCONSISTENT_FAIL") types_ok = False else: if day_v is not None: fail_reasons.append("R4O_05_NHP_NONRESPONDER_CONTRADICTORY_INSULIN_INDEP_DAY_FAIL") types_ok = False if fu_val is not None and fu_val < NHP_MIN_FOLLOWUP_DAYS_DEC: hold_reasons.append("HOLD_NHP_RIGHT_CENSORED_FOLLOWUP_LT_90D") if ( (not sid_adverse) and fu_val is not None and fu_val >= NHP_MIN_FOLLOWUP_DAYS_DEC and nhp_cap_day_ok and om_perf_ok and om_proc_id_ok and om_day_ok and ext_sid_ok and ext_pid_ok and cpep_d_ok and ext_outcome_ok and paired_cpep_ok and port_d_ok and not nhp_binding_alias_adverse and not nhp_date_alias_adverse ): n_visit_eligible_count += 1 elig_present = (pre_diab is not None and base_ins is not None and base_cpep is not None) is_eligible_diabetic = False if elig_present and elig_types_ok and base_ins_d is not None and base_cpep_d is not None: is_eligible_diabetic = ( (pre_diab is True) and base_ins_d >= Decimal("0.5") and base_cpep_d <= Decimal("0.2") ) if is_eligible_diabetic: eligible_diabetic_count += 1 elif not elig_present and elig_types_ok: pending_diabetic_eligibility_count += 1 # Independently score graft localization / post-explant C-peptide extinction # (allows documented partial responders on exogenous insulin to pass localization # without inflating full insulin-independence efficacy count!) if ( is_eligible_diabetic and sid_ok and sp_ok and lot_ok and fu_val is not None and fu_val >= NHP_MIN_FOLLOWUP_DAYS_DEC and om_perf_ok and (om_perf is True) and om_proc_id_ok and om_day_ok and ext_sid_ok and ext_pid_ok and cpep_d_ok and ext_outcome_ok and (ext_out is True) and paired_cpep_ok and lloq_d is not None and pre_cpep_d is not None and post_cpep_d is not None and pre_cpep_d > lloq_d and post_cpep_d <= lloq_d and not nhp_binding_alias_adverse and not nhp_date_alias_adverse ): cpep_extinction_verified_count += 1 responder_endpoint_fields_present = ( (not responder_day_missing) and (om_perf is not None) and (om_proc_id is not None) and (om_d is not None) and (ext_sid is not None) and (ext_pid is not None) and (cpep_d is not None) and (ext_out is not None) and (lloq_v is not None) and (pre_cpep_v is not None) and (post_cpep_v is not None) and (port_d is not None) ) all_qual_fields_present = ( (sid is not None) and (sp is not None) and (lot_v is not None) and (achieved_ii is not None) and (followup_d is not None) and (cap_d is not None) and nhp_comp_resolved and (dose_v is not None) and (cap_v is not None) and (ins_v is not None) and (gsis_v is not None) and (loc_v is not None) and retr_all_present and (responder_endpoint_fields_present if achieved_ii is True else True) ) retr_d: Optional[Decimal] = _to_exact_decimal(retr_v) if _is_finite_number(retr_v) else None if is_eligible_diabetic: if types_ok and all_qual_fields_present: subj_qualifies = ( sid_ok and sp_ok and lot_ok and (achieved_ii is True) and responder_day_ok and fu_val is not None and fu_val >= NHP_MIN_FOLLOWUP_DAYS_DEC and nhp_cap_day_ok and om_perf_ok and (om_perf is True) and om_proc_id_ok and om_day_ok and ext_sid_ok and ext_pid_ok and cpep_d_ok and ext_outcome_ok and (ext_out is True) and paired_cpep_ok and port_d_ok and nhp_comp_resolved and not nhp_comp_adverse and not nhp_binding_alias_adverse and not nhp_date_alias_adverse and dose_d is not None and dose_d <= Decimal("10000") and cap_um_d is not None and cap_um_d <= tier_fibrin_max_d and ins_d is not None and ins_d == ZERO_DEC and (gsis_v is True) and (loc_v is True) and retr_reconciled and (retr_d is not None and retr_d >= Decimal("99.9") if valid_site == "R4_OMENTUM_LEAD" else True) ) if subj_qualifies: qual_count += 1 elif types_ok and not all_qual_fields_present and (achieved_ii is True or achieved_ii is None): no_adverse_present = ( (sid is None or sid_ok) and (sp is None or sp_ok) and (lot_v is None or lot_ok) and (fu_val is None or fu_val >= NHP_MIN_FOLLOWUP_DAYS_DEC) and (cap_d is None or nhp_cap_day_ok) and (om_perf is None or om_perf_ok) and (om_proc_id is None or om_proc_id_ok) and (om_d is None or om_day_ok) and (ext_sid is None or ext_sid_ok) and (ext_pid is None or ext_pid_ok) and (cpep_d is None or cpep_d_ok) and (ext_out is None or ext_outcome_ok) and paired_cpep_ok and (port_d is None or port_d_ok) and not nhp_comp_adverse and not nhp_binding_alias_adverse and not nhp_date_alias_adverse and (day_v is None or (_is_finite_number(day_v) and ZERO_DEC < _to_exact_decimal(day_v) <= NHP_MAX_INSULIN_INDEP_DAY_DEC and (fu_val is None or _to_exact_decimal(day_v) <= fu_val))) and (dose_v is None or (dose_d is not None and dose_d <= Decimal("10000"))) and (cap_v is None or (cap_um_d is not None and cap_um_d <= tier_fibrin_max_d)) and (ins_v is None or (ins_d is not None and ins_d == ZERO_DEC)) and (gsis_v is None or gsis_v is True) and (loc_v is None or loc_v is True) and (retr_v is None or (retr_d is not None and (retr_d >= Decimal("99.9") if valid_site == "R4_OMENTUM_LEAD" else True))) and ((not retr_all_present) or retr_reconciled) ) if no_adverse_present: pending_responder_qual_count += 1 derived_nhp_eligible_visit_n = n_visit_eligible_count if n_any_complication: derived_nhp_zero_complications = False elif n_all_complications_resolved: derived_nhp_zero_complications = True else: derived_nhp_zero_complications = None derived_nhp_eligible_diabetic_n = eligible_diabetic_count derived_nhp_ii = qual_count derived_nhp_cpeptide_extinction_verified_count = cpep_extinction_verified_count if derived_nhp_n >= 4 and (eligible_diabetic_count + pending_diabetic_eligibility_count) < 4: fail_reasons.append("R4O_05_NHP_ELIGIBLE_DIABETIC_N_LT_4_FAIL") if eligible_diabetic_count >= 4: if (qual_count + pending_responder_qual_count) < 3 or 4 * (qual_count + pending_responder_qual_count) < 3 * eligible_diabetic_count: fail_reasons.append("R4O_05_NHP_QUALIFIED_INSULIN_INDEPENDENCE_FAIL") elif derived_nhp_n >= 4 and (qual_count + pending_responder_qual_count + pending_diabetic_eligibility_count) < 3: fail_reasons.append("R4O_05_NHP_QUALIFIED_INSULIN_INDEPENDENCE_FAIL") if valid_site == "R4_OMENTUM_LEAD": if use_dec009_primate_free: grad = obs.get("porcine_portal_peripheral_insulin_gradient") if grad is None: grad = obs.get("nhp_r4o05_portal_peripheral_insulin_gradient") if grad is None: hold_reasons.append("MISSING_DEC009_PORTAL_INSULIN_GRADIENT") elif not _is_finite_number(grad): fail_reasons.append("INVALID_PORTAL_INSULIN_GRADIENT") else: grad_d = _to_exact_decimal(grad)