更新
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\service\prescriptionai;
|
||||
|
||||
/** Minimal display projection of the immutable prescription; never reads live records. */
|
||||
final class PrescriptionAiDoctorSnapshot
|
||||
{
|
||||
public static function project(array $prescription): array
|
||||
{
|
||||
$patient = self::scalars($prescription, ['gender', 'age']);
|
||||
$patient['name'] = self::text($prescription['patient_name'] ?? null);
|
||||
$gender = self::text($patient['gender'] ?? null);
|
||||
$patient['gender_label'] = in_array($gender, ['1', '男'], true) ? '男'
|
||||
: (in_array($gender, ['0', '2', '女'], true) ? '女' : '未知');
|
||||
$rx = self::scalars($prescription, [
|
||||
'prescription_name', 'prescription_type', 'dosage_unit', 'dose_unit', 'dose_basis',
|
||||
'dose_count', 'usage_instruction', 'usage_days', 'times_per_day', 'usage_time',
|
||||
'usage_way', 'usage_notes', 'dietary_taboo', 'dosage_amount', 'dosage_bag_count',
|
||||
'need_decoction', 'bags_per_dose',
|
||||
]);
|
||||
$auxUsage = self::scalars(PrescriptionAiPolicy::decode($prescription['aux_usage'] ?? []), [
|
||||
'prescription_name', 'dosage_amount', 'dosage_bag_count', 'need_decoction',
|
||||
'bags_per_dose', 'times_per_day', 'usage_days',
|
||||
]);
|
||||
if ($auxUsage !== []) {
|
||||
// Auxiliary formula instructions belong to that formula, never the main usage.
|
||||
$rx['aux_usage'] = $auxUsage;
|
||||
}
|
||||
$rx['herbs'] = [];
|
||||
foreach (PrescriptionAiPolicy::decode($prescription['herbs'] ?? []) as $herb) {
|
||||
if (!is_array($herb)) {
|
||||
continue;
|
||||
}
|
||||
// Preserve saved row order and duplicates, without costs, stock, IDs or attachments.
|
||||
$rx['herbs'][] = self::scalars($herb, [
|
||||
'name', 'dosage', 'unit', 'dose_basis', 'formula_type', 'processing',
|
||||
'special_usage', 'instructions', 'usage', 'remark',
|
||||
]);
|
||||
}
|
||||
return [
|
||||
'patient' => $patient,
|
||||
// The source has one combined clinical diagnosis. Do not invent a Western/TCM split
|
||||
// or expose case_record, which may contain other encounters and contact details.
|
||||
'diagnosis' => ['clinical_diagnosis' => self::text($prescription['clinical_diagnosis'] ?? null)],
|
||||
'prescription' => $rx,
|
||||
];
|
||||
}
|
||||
|
||||
private static function scalars(array $row, array $fields): array
|
||||
{
|
||||
return array_filter(array_intersect_key($row, array_flip($fields)),
|
||||
static fn ($value): bool => is_string($value) || is_int($value) || is_float($value));
|
||||
}
|
||||
|
||||
private static function text($value): string
|
||||
{
|
||||
return is_string($value) || is_numeric($value) ? trim((string) $value) : '';
|
||||
}
|
||||
}
|
||||
@@ -119,7 +119,9 @@ final class PrescriptionAiGenerator
|
||||
}
|
||||
$status = (string) ($file['status'] ?? 'pending');
|
||||
if ($status === 'restricted' || empty($file['url']) || !in_array($file['type'] ?? '', ['image', 'document'], true) || $batchSize === 0) {
|
||||
$coverage['files'][$id] = ['file_id' => $id, 'status' => $status === 'restricted' ? 'restricted' : 'unsupported', 'transmitted' => false,
|
||||
// 附件类型随覆盖清单一起保留:界面按类型展示每个附件的读取结果,不再只有编号。
|
||||
$coverage['files'][$id] = ['file_id' => $id, 'type' => (string) ($file['type'] ?? ''),
|
||||
'status' => $status === 'restricted' ? 'restricted' : 'unsupported', 'transmitted' => false,
|
||||
'version_verified' => false, 'reason' => $batchSize === 0 ? 'FILE_CAPABILITY_DISABLED' : 'FILE_UNAVAILABLE_OR_UNSUPPORTED'];
|
||||
$criticalGap = true;
|
||||
$unavailableGroups++;
|
||||
@@ -149,7 +151,8 @@ final class PrescriptionAiGenerator
|
||||
throw $e;
|
||||
}
|
||||
foreach ($batch as $file) {
|
||||
$coverage['files'][$file['file_id']] = ['file_id' => $file['file_id'], 'status' => 'unsupported', 'transmitted' => false,
|
||||
$coverage['files'][$file['file_id']] = ['file_id' => $file['file_id'], 'type' => (string) ($file['type'] ?? ''),
|
||||
'status' => 'unsupported', 'transmitted' => false,
|
||||
'version_verified' => false, 'reason' => $e->getMessage()];
|
||||
}
|
||||
$criticalGap = true;
|
||||
@@ -162,7 +165,8 @@ final class PrescriptionAiGenerator
|
||||
// Delivery was confirmed and one format repair was already spent, so no finding
|
||||
// in this malformed group is usable evidence.
|
||||
foreach ($batch as $file) {
|
||||
$coverage['files'][$file['file_id']] = ['file_id' => $file['file_id'], 'status' => 'unreadable', 'transmitted' => true,
|
||||
$coverage['files'][$file['file_id']] = ['file_id' => $file['file_id'], 'type' => (string) ($file['type'] ?? ''),
|
||||
'status' => 'unreadable', 'transmitted' => true,
|
||||
'version_verified' => false, 'reason' => 'MODEL_FILE_OUTPUT_INVALID'];
|
||||
}
|
||||
$criticalGap = true;
|
||||
@@ -171,7 +175,8 @@ final class PrescriptionAiGenerator
|
||||
}
|
||||
foreach ($result as $fileResult) {
|
||||
$file = $batch[array_search($fileResult['file_id'], array_column($batch, 'file_id'), true)];
|
||||
$coverage['files'][$fileResult['file_id']] = ['file_id' => $fileResult['file_id'], 'status' => $fileResult['status'], 'transmitted' => true,
|
||||
$coverage['files'][$fileResult['file_id']] = ['file_id' => $fileResult['file_id'], 'type' => (string) ($file['type'] ?? ''),
|
||||
'status' => $fileResult['status'], 'transmitted' => true,
|
||||
'version_verified' => !empty($file['version_verified']), 'reason' => $fileResult['status'] === 'processed' ? '' : 'MODEL_REPORTED_' . strtoupper($fileResult['status'])];
|
||||
if ($fileResult['status'] !== 'processed') {
|
||||
$criticalGap = true;
|
||||
|
||||
Reference in New Issue
Block a user