Files
zyt/admin/PATIENT_SEARCH_SUMMARY.md
T
2026-03-11 09:49:47 +08:00

181 lines
3.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 患者搜索 API - 快速总结
## ✅ 已完成
### 新增 API 端点
```
GET /tcm.diagnosis/searchPatient
```
**功能**: 从诊单表搜索患者,用于创建订单等场景
### 后端实现
**文件**: `server/app/adminapi/controller/tcm/DiagnosisController.php`
```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`
```typescript
// 搜索患者(从诊单表)
export function searchPatients(params: any) {
return request.get({ url: '/tcm.diagnosis/searchPatient', params })
}
```
### 组件集成
**文件**: `admin/src/views/order/index.vue`
```typescript
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 使用
### 请求
```bash
GET /tcm.diagnosis/searchPatient?keyword=张三&page_no=1&page_size=10
```
### 参数
| 参数 | 说明 |
|------|------|
| keyword | 搜索关键词(必填) |
| page_no | 页码(可选,默认1 |
| page_size | 每页数量(可选,默认10) |
### 响应
```json
{
"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
}
}
```
## 🎯 使用场景
在创建订单时搜索患者:
```vue
<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` - 患者身份证号
## ✨ 特性
✅ 多字段搜索
✅ 分页支持
✅ 性能优化
✅ 模糊匹配
✅ 权限控制
## 📝 修改的文件
1. `server/app/adminapi/controller/tcm/DiagnosisController.php` - 新增 searchPatient() 方法
2. `admin/src/api/order.ts` - 新增 searchPatients() 函数
3. `admin/src/views/order/index.vue` - 已集成
## 🚀 立即使用
无需额外配置,创建订单时患者搜索框会自动使用新的 API。
## 📚 详细文档
- `PATIENT_SEARCH_API.md` - 完整 API 文档
---
**创建日期**: 2024-03-10
**版本**: 1.0.0
**状态**: ✅ 完成