增加检查报告时间轴
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 [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user