initialize(); use app\common\model\doctor\Medicine; use app\common\service\prescriptionai\PrescriptionAiCipher; use app\common\service\prescriptionai\PrescriptionAiComparison; use app\common\service\prescriptionai\PrescriptionAiPolicy; use think\facade\Db; $batchId = (int) ($argv[1] ?? 5); $cipher = new PrescriptionAiCipher(); $batch = Db::name('prescription_ai_batch')->where('id', $batchId)->find(); $doctor = $cipher->decrypt((string) $batch['prescription_cipher'], 'prescription'); $doctor['herbs'] = PrescriptionAiPolicy::decode($doctor['herbs'] ?? []); $doctor['aux_usage'] = PrescriptionAiPolicy::decode($doctor['aux_usage'] ?? []); $catalog = Medicine::where('status', 1)->whereNull('delete_time')->field(['id', 'name', 'unit'])->order('id')->select()->toArray(); $out = ['batch_id' => $batchId, 'doctor_herb_count' => count($doctor['herbs'])]; foreach (Db::name('prescription_ai_result')->where('batch_id', $batchId)->select()->toArray() as $row) { $body = $cipher->decrypt((string) $row['body_cipher'], 'result:' . $row['batch_id'] . ':' . $row['model_key']); $comparison = PrescriptionAiComparison::compare($doctor, (array) ($body['candidate'] ?? []), $catalog); $out['results'][] = [ 'model_key' => $row['model_key'], 'stored' => ['status' => $row['comparison_status'], 'reason' => $row['comparison_reason_code'], 'score' => $row['score']], 'recomputed' => [ 'status' => $comparison['status'], 'score' => $comparison['score'], 'herb_score' => $comparison['herb_score'], 'reason_code' => $comparison['reason_code'], 'doctor_count' => $comparison['doctor_count'], 'candidate_count' => $comparison['candidate_count'], 'matched_count' => $comparison['matched_count'], 'issues' => array_slice(array_map(static fn (array $i): array => ['side' => $i['side'], 'code' => $i['code']], $comparison['normalization']['issues']), 0, 12), 'issue_total' => count($comparison['normalization']['issues']), ], ]; } echo json_encode($out, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), "\n";