83 lines
2.4 KiB
PHP
83 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\adminapi\lists\tcm;
|
|
|
|
use app\adminapi\lists\BaseAdminDataLists;
|
|
use app\common\lists\ListsSearchInterface;
|
|
use app\common\model\tcm\Prescription;
|
|
|
|
/**
|
|
* 处方列表
|
|
*/
|
|
class PrescriptionLists extends BaseAdminDataLists implements ListsSearchInterface
|
|
{
|
|
/**
|
|
* @notes 搜索条件
|
|
*/
|
|
public function setSearch(): array
|
|
{
|
|
return [
|
|
'=' => ['is_shared'],
|
|
'%like%' => ['prescription_name', 'patient_name', 'sn']
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @notes 获取列表
|
|
*/
|
|
public function lists(): array
|
|
{
|
|
$lists = Prescription::where($this->searchWhere)
|
|
->where(function ($query) {
|
|
// 如果不是共享的,只能看到自己创建的
|
|
$query->whereOr([
|
|
['is_shared', '=', 1],
|
|
['creator_id', '=', $this->adminId]
|
|
]);
|
|
})
|
|
->whereNull('delete_time')
|
|
->order('id', 'desc')
|
|
->limit($this->limitOffset, $this->limitLength)
|
|
->select()
|
|
->toArray();
|
|
|
|
// 处理字段格式
|
|
foreach ($lists as &$item) {
|
|
// 设置默认值
|
|
$item['usage_time'] = $item['usage_time'] ?? '饭前';
|
|
$item['usage_way'] = $item['usage_way'] ?? '温水送服';
|
|
$item['usage_notes'] = $item['usage_notes'] ?? '';
|
|
$item['usage_days'] = $item['usage_days'] ?? 7;
|
|
$item['is_shared'] = $item['is_shared'] ?? 0;
|
|
|
|
// 将 dietary_taboo 从逗号分隔的字符串转换为数组(前端需要数组格式)
|
|
if (!empty($item['dietary_taboo']) && is_string($item['dietary_taboo'])) {
|
|
$item['dietary_taboo'] = array_filter(explode(',', $item['dietary_taboo']));
|
|
} else {
|
|
$item['dietary_taboo'] = [];
|
|
}
|
|
}
|
|
|
|
return $lists;
|
|
}
|
|
|
|
/**
|
|
* @notes 获取数量
|
|
*/
|
|
public function count(): int
|
|
{
|
|
return Prescription::where($this->searchWhere)
|
|
->where(function ($query) {
|
|
// 如果不是共享的,只能看到自己创建的
|
|
$query->whereOr([
|
|
['is_shared', '=', 1],
|
|
['creator_id', '=', $this->adminId]
|
|
]);
|
|
})
|
|
->whereNull('delete_time')
|
|
->count();
|
|
}
|
|
}
|