initialize(); try { $batch = \think\facade\Db::name('prescription_ai_batch')->where('id', 1)->where('prescription_id', 7556)->find(); $actor = (int) $batch['actor_id']; $info = \app\common\service\prescriptionai\PrescriptionAiAccess::actor($actor); $detail = \app\adminapi\logic\tcm\PrescriptionAiLogic::detail(1, $actor, $info); $models = []; foreach ($detail['models'] ?? [] as $key => $model) { $coverage = $model['coverage'] ?? []; $fileStatuses = []; $fileReasons = []; foreach ($coverage['files'] ?? [] as $file) { $status = (string) ($file['status'] ?? 'unknown'); $fileStatuses[$status] = ($fileStatuses[$status] ?? 0) + 1; $reason = (string) ($file['reason'] ?? ''); if ($reason !== '') { $fileReasons[$reason] = ($fileReasons[$reason] ?? 0) + 1; } } $models[$key] = ['status' => $model['status'] ?? null, 'report_id' => $model['report_id'] ?? null, 'has_report' => !empty($model['report']), 'candidate_status' => $model['candidate']['status'] ?? null, 'coverage_complete' => $coverage['complete'] ?? null, 'files' => $fileStatuses, 'file_reasons' => $fileReasons, 'comparison_status' => $model['comparison']['status'] ?? null, 'error_code' => $model['error_code'] ?? null]; } $clinicalMissing = array_values(array_map(static fn (array $gap): string => (string) $gap['source_id'], array_filter($detail['missing'] ?? [], static fn (array $gap): bool => ($gap['code'] ?? '') === 'CRITICAL_CLINICAL_FACT_MISSING'))); echo json_encode(['time' => date('c'), 'batch_id' => $detail['id'] ?? null, 'status' => $detail['status'] ?? null, 'clinical_missing_fields' => $clinicalMissing, 'models' => $models], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE), PHP_EOL; } catch (Throwable $e) { echo json_encode(['error' => get_class($e), 'code' => $e->getCode()]), PHP_EOL; exit(1); }