59 lines
3.0 KiB
PHP
59 lines
3.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
// Read-only diagnostic for preparation wait and model timing. Metadata and counts only;
|
|
// never prints clinical content, attachment URLs, prompts or credentials.
|
|
$serverRoot = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'server' . DIRECTORY_SEPARATOR;
|
|
chdir($serverRoot);
|
|
require $serverRoot . 'vendor/autoload.php';
|
|
$app = new \think\App($serverRoot);
|
|
$app->initialize();
|
|
|
|
use think\facade\Db;
|
|
|
|
$rxId = (int) ($argv[1] ?? 7556);
|
|
$out = ['now' => time(), 'prescription_id' => $rxId];
|
|
|
|
$rx = Db::name('tcm_prescription')->where('id', $rxId)->field('id,diagnosis_id,appointment_id,patient_id,is_system_auto,update_time')->find();
|
|
$out['prescription'] = $rx;
|
|
$diagnosisId = (int) ($rx['diagnosis_id'] ?? 0);
|
|
|
|
$out['call_records'] = Db::name('tcm_call_record')->where('diagnosis_id', $diagnosisId)
|
|
->field('id,diagnosis_id,status,transcription_status,transcription_session_id,transcription_segment_count,start_time,end_time,create_time,update_time,transcription_started_at,transcription_finished_at')
|
|
->order('id', 'desc')->limit(10)->select()->toArray();
|
|
foreach ($out['call_records'] as &$call) {
|
|
$call['segment_total'] = (int) Db::name('tcm_call_transcript_segment')->where('call_record_id', $call['id'])->count();
|
|
$call['segment_current_session'] = (string) $call['transcription_session_id'] !== ''
|
|
? (int) Db::name('tcm_call_transcript_segment')->where('call_record_id', $call['id'])
|
|
->where('transcription_session_id', $call['transcription_session_id'])->count()
|
|
: 0;
|
|
}
|
|
unset($call);
|
|
|
|
$batches = Db::name('prescription_ai_batch')->where('prescription_id', $rxId)
|
|
->field('id,status,validity,cutoff_at,decision_at,wait_until,next_run_at,created_at,updated_at,coverage_status,source_summary_json,missing_json,error_code')
|
|
->order('id', 'desc')->limit(5)->select()->toArray();
|
|
foreach ($batches as &$batch) {
|
|
$batch['prepare_seconds'] = (int) $batch['cutoff_at'] > 0 ? (int) $batch['cutoff_at'] - (int) $batch['created_at'] : null;
|
|
$batch['missing_codes'] = array_count_values(array_column(json_decode((string) $batch['missing_json'], true) ?: [], 'code'));
|
|
unset($batch['missing_json']);
|
|
}
|
|
unset($batch);
|
|
$out['batches'] = $batches;
|
|
|
|
$ids = array_column($batches, 'id');
|
|
$out['tasks'] = $ids ? Db::name('prescription_ai_task')->whereIn('batch_id', $ids)
|
|
->field('id,batch_id,model_key,status,attempts,total_attempts,error_code,started_at,finished_at,updated_at')
|
|
->order('id')->select()->toArray() : [];
|
|
foreach ($out['tasks'] as &$task) {
|
|
$task['run_seconds'] = (int) $task['finished_at'] > 0 && (int) $task['started_at'] > 0
|
|
? (int) $task['finished_at'] - (int) $task['started_at'] : null;
|
|
}
|
|
unset($task);
|
|
|
|
$taskIds = array_column($out['tasks'], 'id');
|
|
$out['attempts'] = $taskIds ? Db::name('prescription_ai_attempt')->whereIn('task_id', $taskIds)
|
|
->field('id,task_id,attempt_no,status,error_code,started_at,finished_at')->order('id')->limit(40)->select()->toArray() : [];
|
|
|
|
echo json_encode($out, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), "\n";
|