@@ -83,6 +83,14 @@ class OrderPrescription extends Model
|
||||
return $this->hasOne(UserDoctor::class, 'doctor_id','doctor_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联问诊订单表
|
||||
*/
|
||||
public function OrderInquiry(): HasOne
|
||||
{
|
||||
return $this->hasOne(OrderInquiry::class, 'order_inquiry_id','order_inquiry_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取信息-单条
|
||||
* @param array $params
|
||||
@@ -163,6 +171,49 @@ class OrderPrescription extends Model
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取处方列表-分页 (抄方)
|
||||
* @param array $params 条件
|
||||
* @param array $fields 字段
|
||||
* @param int|null $page 页码
|
||||
* @param int|null $per_page 每页个数
|
||||
* @return array
|
||||
*/
|
||||
public static function getTransferWithIcdPage(array $params, array $fields = ["*"], int $page = null, ?int $per_page = 10): array
|
||||
{
|
||||
$query = self::with([
|
||||
'OrderPrescriptionIcd',
|
||||
'OrderInquiry'
|
||||
]);
|
||||
|
||||
// 如果提供了 doctor_id,则添加 OrderInquiry 表的 doctor_id 条件
|
||||
if (isset($params['doctor_id'])) {
|
||||
$doctorId = $params['doctor_id'];
|
||||
// 从 $params 中移除 doctor_id,避免在 where($params) 中重复使用
|
||||
unset($params['doctor_id']);
|
||||
$query->whereHas('OrderInquiry', function ($q) use ($doctorId) {
|
||||
$q->where('doctor_id', $doctorId);
|
||||
});
|
||||
}
|
||||
|
||||
// 应用其他条件
|
||||
if (!empty($params)) {
|
||||
$query->where($params);
|
||||
}
|
||||
|
||||
$raw = $query->orderBy('created_at','desc')
|
||||
->paginate($per_page, $fields, "page", $page);
|
||||
|
||||
$data = array();
|
||||
$data['current_page'] = $raw->currentPage();// 当前页码
|
||||
$data['total'] = $raw->total();//数据总数
|
||||
$data['data'] = $raw->items();//数据
|
||||
$data['per_page'] = $raw->perPage();//每页个数
|
||||
$data['last_page'] = $raw->lastPage();//最后一页
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param array $params
|
||||
|
||||
Reference in New Issue
Block a user