更新
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// Read-only re-comparison of an existing batch with the current algorithm. Prints scores,
|
||||
// counts and issue codes only; no herb names, report text, patient data 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 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";
|
||||
Reference in New Issue
Block a user