3.8 KiB
3.8 KiB
患者搜索 API - 快速总结
✅ 已完成
新增 API 端点
GET /tcm.diagnosis/searchPatient
功能: 从诊单表搜索患者,用于创建订单等场景
后端实现
文件: server/app/adminapi/controller/tcm/DiagnosisController.php
public function searchPatient()
{
$keyword = $this->request->get('keyword', '');
$page_no = $this->request->get('page_no', 1);
$page_size = $this->request->get('page_size', 10);
if (empty($keyword)) {
return $this->success('', ['lists' => [], 'count' => 0]);
}
$offset = ($page_no - 1) * $page_size;
$lists = \app\common\model\tcm\Diagnosis::where('patient_name|patient_phone|patient_id_card', 'like', '%' . $keyword . '%')
->field(['id', 'patient_name', 'patient_phone', 'patient_id_card', 'gender', 'age'])
->limit($offset, $page_size)
->order('id desc')
->select()
->toArray();
$count = \app\common\model\tcm\Diagnosis::where('patient_name|patient_phone|patient_id_card', 'like', '%' . $keyword . '%')
->count();
return $this->success('', [
'lists' => $lists,
'count' => $count,
'page_no' => $page_no,
'page_size' => $page_size
]);
}
前端实现
文件: admin/src/api/order.ts
// 搜索患者(从诊单表)
export function searchPatients(params: any) {
return request.get({ url: '/tcm.diagnosis/searchPatient', params })
}
组件集成
文件: admin/src/views/order/index.vue
import { searchPatients as searchPatientsAPI } from '@/api/order'
const searchPatients = async (query: string) => {
if (!query) {
patientList.value = []
return
}
try {
patientLoading.value = true
const res = await searchPatientsAPI({
keyword: query,
page_no: 1,
page_size: 10
})
patientList.value = res?.lists || []
} finally {
patientLoading.value = false
}
}
🔌 API 使用
请求
GET /tcm.diagnosis/searchPatient?keyword=张三&page_no=1&page_size=10
参数
| 参数 | 说明 |
|---|---|
| keyword | 搜索关键词(必填) |
| page_no | 页码(可选,默认1) |
| page_size | 每页数量(可选,默认10) |
响应
{
"code": 1,
"msg": "success",
"data": {
"lists": [
{
"id": 1,
"patient_name": "张三",
"patient_phone": "13800138000",
"patient_id_card": "110101199001011234",
"gender": 1,
"age": 34
}
],
"count": 1,
"page_no": 1,
"page_size": 10
}
}
🎯 使用场景
在创建订单时搜索患者:
<el-select
v-model="createForm.patient_id"
placeholder="请选择患者"
filterable
remote
:remote-method="searchPatients"
:loading="patientLoading"
>
<el-option
v-for="item in patientList"
:key="item.id"
:label="`${item.patient_name} (${item.patient_phone})`"
:value="item.id"
/>
</el-select>
📊 搜索字段
patient_name- 患者姓名patient_phone- 患者手机号patient_id_card- 患者身份证号
✨ 特性
✅ 多字段搜索 ✅ 分页支持 ✅ 性能优化 ✅ 模糊匹配 ✅ 权限控制
📝 修改的文件
server/app/adminapi/controller/tcm/DiagnosisController.php- 新增 searchPatient() 方法admin/src/api/order.ts- 新增 searchPatients() 函数admin/src/views/order/index.vue- 已集成
🚀 立即使用
无需额外配置,创建订单时患者搜索框会自动使用新的 API。
📚 详细文档
PATIENT_SEARCH_API.md- 完整 API 文档
创建日期: 2024-03-10 版本: 1.0.0 状态: ✅ 完成