Merge branch 'long-consultation-desk'
This commit is contained in:
@@ -4,11 +4,12 @@ namespace app\adminapi\logic\doctor;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\doctor\DoctorNote;
|
||||
use app\common\service\FileService;
|
||||
|
||||
class DoctorNoteLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* 按 diagnosis_id + 当天 find-or-create,追加 content / tongue_images
|
||||
* 按 diagnosis_id + 当天 find-or-create,追加 content / tongue_images / report_files
|
||||
*/
|
||||
public static function addOrAppend(array $params): bool
|
||||
{
|
||||
@@ -24,10 +25,8 @@ class DoctorNoteLogic extends BaseLogic
|
||||
->find();
|
||||
|
||||
$newContent = trim($params['content'] ?? '');
|
||||
$newImages = $params['tongue_images'] ?? [];
|
||||
if (is_string($newImages)) {
|
||||
$newImages = json_decode($newImages, true) ?: [];
|
||||
}
|
||||
$newImages = self::parseJsonArray($params['tongue_images'] ?? []);
|
||||
$newReports = self::parseJsonArray($params['report_files'] ?? []);
|
||||
|
||||
if ($existing) {
|
||||
$data = [];
|
||||
@@ -39,17 +38,17 @@ class DoctorNoteLogic extends BaseLogic
|
||||
}
|
||||
|
||||
if (!empty($newImages)) {
|
||||
$prev = $existing->tongue_images;
|
||||
if (is_string($prev)) {
|
||||
$prev = json_decode($prev, true) ?: [];
|
||||
}
|
||||
if (!is_array($prev)) {
|
||||
$prev = [];
|
||||
}
|
||||
$prev = self::parseJsonArray($existing->tongue_images);
|
||||
$merged = array_values(array_unique(array_merge($prev, $newImages)));
|
||||
$data['tongue_images'] = json_encode($merged, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
if (!empty($newReports)) {
|
||||
$prev = self::parseJsonArray($existing->report_files);
|
||||
$merged = array_values(array_unique(array_merge($prev, $newReports)));
|
||||
$data['report_files'] = json_encode($merged, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
if (!empty($data)) {
|
||||
$existing->save($data);
|
||||
}
|
||||
@@ -63,6 +62,9 @@ class DoctorNoteLogic extends BaseLogic
|
||||
'tongue_images' => !empty($newImages)
|
||||
? json_encode($newImages, JSON_UNESCAPED_UNICODE)
|
||||
: null,
|
||||
'report_files' => !empty($newReports)
|
||||
? json_encode($newReports, JSON_UNESCAPED_UNICODE)
|
||||
: null,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -91,14 +93,12 @@ class DoctorNoteLogic extends BaseLogic
|
||||
->toArray();
|
||||
|
||||
foreach ($records as &$record) {
|
||||
$images = $record['tongue_images'] ?? [];
|
||||
if (is_string($images)) {
|
||||
$images = json_decode($images, true) ?: [];
|
||||
}
|
||||
if (!is_array($images)) {
|
||||
$images = [];
|
||||
}
|
||||
$record['tongue_images'] = $images;
|
||||
$record['tongue_images'] = array_map(function ($url) {
|
||||
return empty($url) ? $url : FileService::getFileUrl($url);
|
||||
}, self::parseJsonArray($record['tongue_images'] ?? []));
|
||||
$record['report_files'] = array_map(function ($url) {
|
||||
return empty($url) ? $url : FileService::getFileUrl($url);
|
||||
}, self::parseJsonArray($record['report_files'] ?? []));
|
||||
}
|
||||
|
||||
return $records;
|
||||
@@ -107,4 +107,14 @@ class DoctorNoteLogic extends BaseLogic
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private static function parseJsonArray($value): array
|
||||
{
|
||||
if (is_array($value)) return $value;
|
||||
if (is_string($value)) {
|
||||
$decoded = json_decode($value, true);
|
||||
return is_array($decoded) ? $decoded : [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ use app\common\model\tcm\Diagnosis;
|
||||
use app\common\model\tcm\DiagnosisAssignLog;
|
||||
use app\common\model\tcm\ImChatMessage;
|
||||
use app\common\model\DiagnosisViewRecord;
|
||||
use app\adminapi\logic\doctor\DoctorNoteLogic;
|
||||
use app\common\service\FileService;
|
||||
use think\facade\Db;
|
||||
/**
|
||||
* 中医辨房病因诊单逻辑
|
||||
@@ -192,14 +194,37 @@ class DiagnosisLogic extends BaseLogic
|
||||
$params['diagnosis_date'] = strtotime($params['diagnosis_date']);
|
||||
}
|
||||
|
||||
// 保存前记录旧的检查报告,用于对比新增
|
||||
$oldReportFiles = [];
|
||||
if (isset($params['report_files'])) {
|
||||
$old = Diagnosis::where('id', $params['id'])->value('report_files');
|
||||
if ($old) {
|
||||
$oldReportFiles = is_string($old) ? (json_decode($old, true) ?: []) : (array) $old;
|
||||
}
|
||||
}
|
||||
|
||||
Diagnosis::update($params);
|
||||
|
||||
|
||||
// 检查报告有新增时同步到医生备注
|
||||
if (isset($params['report_files'])) {
|
||||
$newReportFiles = is_string($params['report_files'])
|
||||
? (json_decode($params['report_files'], true) ?: [])
|
||||
: (array) $params['report_files'];
|
||||
$added = array_values(array_diff($newReportFiles, $oldReportFiles));
|
||||
if (!empty($added)) {
|
||||
DoctorNoteLogic::addOrAppend([
|
||||
'diagnosis_id' => (int) $params['id'],
|
||||
'report_files' => $added,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果是编辑,也确保患者有 TRTC 账号
|
||||
$diagnosis = Diagnosis::find($params['id']);
|
||||
if ($diagnosis) {
|
||||
self::createPatientTrtcAccount($diagnosis->patient_id);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
@@ -256,57 +281,30 @@ class DiagnosisLogic extends BaseLogic
|
||||
|
||||
|
||||
if (!empty($diagnosis['tongue_images'])) {
|
||||
// 先尝试 JSON 解析(兼容旧数据)
|
||||
$files = json_decode($diagnosis['tongue_images'], true);
|
||||
if (is_array($files)) {
|
||||
$diagnosis['tongue_images'] = $files;
|
||||
} else {
|
||||
// JSON 解析失败则按逗号分割
|
||||
$diagnosis['tongue_images'] = array_filter(explode(',', $diagnosis['tongue_images'])) ?: [];
|
||||
}
|
||||
|
||||
// 为没有 http 前缀的图片添加域名
|
||||
$domain = request()->domain();
|
||||
$diagnosis['tongue_images'] = array_map(function($url) use ($domain) {
|
||||
if (empty($url)) {
|
||||
return $url;
|
||||
$files = json_decode($diagnosis['tongue_images'], true);
|
||||
if (is_array($files)) {
|
||||
$diagnosis['tongue_images'] = $files;
|
||||
} else {
|
||||
$diagnosis['tongue_images'] = array_filter(explode(',', $diagnosis['tongue_images'])) ?: [];
|
||||
}
|
||||
$diagnosis['tongue_images'] = array_map(function($url) {
|
||||
return empty($url) ? $url : FileService::getFileUrl($url);
|
||||
}, $diagnosis['tongue_images']);
|
||||
} else {
|
||||
$diagnosis['tongue_images'] = [];
|
||||
}
|
||||
// 如果已经包含 http:// 或 https://,则跳过
|
||||
if (stripos($url, 'http://') === 0 || stripos($url, 'https://') === 0) {
|
||||
return $url;
|
||||
}
|
||||
// 添加域名前缀
|
||||
return $domain .'/'. $url;
|
||||
}, $diagnosis['tongue_images']);
|
||||
} else {
|
||||
$diagnosis['tongue_images'] = [];
|
||||
}
|
||||
|
||||
// 处理检查报告(JSON转数组)
|
||||
if (!empty($diagnosis['report_files'])) {
|
||||
// 先尝试 JSON 解析(兼容旧数据)
|
||||
$files = json_decode($diagnosis['report_files'], true);
|
||||
if (is_array($files)) {
|
||||
$diagnosis['report_files'] = $files;
|
||||
} else {
|
||||
// JSON 解析失败则按逗号分割
|
||||
$diagnosis['report_files'] = array_filter(explode(',', $diagnosis['report_files'])) ?: [];
|
||||
}
|
||||
|
||||
// 为没有 http 前缀的文件添加域名
|
||||
$domain = request()->domain();
|
||||
$diagnosis['report_files'] = array_map(function($url) use ($domain) {
|
||||
if (empty($url)) {
|
||||
return $url;
|
||||
}
|
||||
// 如果已经包含 http:// 或 https://,则跳过
|
||||
if (stripos($url, 'http://') === 0 || stripos($url, 'https://') === 0) {
|
||||
return $url;
|
||||
}
|
||||
// 添加域名前缀
|
||||
return $domain . $url;
|
||||
}, $diagnosis['report_files']);
|
||||
} else {
|
||||
if (!empty($diagnosis['report_files'])) {
|
||||
$files = json_decode($diagnosis['report_files'], true);
|
||||
if (is_array($files)) {
|
||||
$diagnosis['report_files'] = $files;
|
||||
} else {
|
||||
$diagnosis['report_files'] = array_filter(explode(',', $diagnosis['report_files'])) ?: [];
|
||||
}
|
||||
$diagnosis['report_files'] = array_map(function($url) {
|
||||
return empty($url) ? $url : FileService::getFileUrl($url);
|
||||
}, $diagnosis['report_files']);
|
||||
} else {
|
||||
$diagnosis['report_files'] = [];
|
||||
}
|
||||
// 处理诊断日期格式
|
||||
|
||||
Reference in New Issue
Block a user