Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵增煜
/
tzt-admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3825a4af
authored
Nov 14, 2024
by
赵增煜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
药店
parent
883ee984
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
102 additions
and
56 deletions
+102
-56
app/Api/Controllers/DrugController.php
+24
-11
app/Api/Controllers/PatientController.php
+39
-30
app/Api/Controllers/PrescriptionController.php
+12
-12
routes/api.php
+27
-3
No files found.
app/Api/Controllers/DrugController.php
View file @
3825a4af
...
...
@@ -4,6 +4,8 @@
use
App\Http\Controllers\BaseApiController
;
use
App\Models\DrugModel
;
use
App\Models\PharmacyDrugModel
;
use
App\Models\PharmacyModel
;
use
Illuminate\Http\Request
;
// 药品控制器
...
...
@@ -11,22 +13,33 @@ class DrugController extends BaseApiController
{
public
function
test
()
{
return
$this
->
success
([
'a'
=>
1
,
'b'
=>
2
,
'c'
=>
3
]);
$search_input
=
"测试"
;
$data
=
PharmacyDrugModel
::
where
(
"pharmacy_id"
,
1
)
->
whereHas
(
'drug'
,
function
(
$query
)
use
(
$search_input
)
{
$query
->
where
(
'name'
,
'LIKE'
,
"%
{
$search_input
}
%"
)
->
orWhere
(
'code'
,
'LIKE'
,
"%
{
$search_input
}
%"
);
// 这里的'%筛选条件%'是你想要匹配的药品名称
})
->
paginate
(
10
);
// $drugs = $data->map(function ($row) {
// return $row->drug;
// });
return
$this
->
success
(
$data
);
}
// 药品列表
public
function
drugList
(
Request
$request
)
{
// $code = $request->input('code');
// TODO 通过药店编号筛选药品列表
// pharmacy_id = $request->input('code');
$data
=
DrugModel
::
query
()
->
paginate
(
10
);
// $total = DrugModel::query()->count();
// $data = [
// 'data'=>$drugList,
// 'total'=>$total
// ];
$authInfo
=
auth
(
'api'
)
->
user
();
$pharmacy
=
PharmacyModel
::
where
(
'user_id'
,
$authInfo
->
id
)
->
first
();
$search_input
=
$request
->
input
(
'search_input'
);
$data
=
PharmacyDrugModel
::
where
(
"pharmacy_id"
,
$pharmacy
->
id
)
->
whereHas
(
'drug'
,
function
(
$query
)
use
(
$search_input
)
{
if
(
$search_input
)
{
$query
->
where
(
'name'
,
'LIKE'
,
"%
{
$search_input
}
%"
)
->
orWhere
(
'code'
,
'LIKE'
,
"%
{
$search_input
}
%"
);
// 这里的'%筛选条件%'是你想要匹配的药品名称
}
})
->
paginate
(
10
);
return
$this
->
success
(
$data
);
}
...
...
app/Api/Controllers/PatientController.php
View file @
3825a4af
...
...
@@ -5,6 +5,8 @@
use
App\Common\Util
;
use
App\Http\Controllers\BaseApiController
;
use
App\Models\PatientModel
;
use
App\Models\PharmacyModel
;
use
App\Models\User
;
use
Illuminate\Http\Request
;
// 问诊人控制器
...
...
@@ -18,20 +20,23 @@ public function test()
// 获取问诊人列表
public
function
patientList
(
Request
$request
)
{
$login_type
=
$request
->
input
(
'login_type'
);
$id
=
$request
->
input
(
'id'
);
$authInfo
=
auth
(
'api'
)
->
user
();
$query
=
PatientModel
::
query
();
if
(
$login_type
==
0
)
{
// 用户
$query
=
$query
->
where
(
'user_id'
,
$id
);
}
elseif
(
$login_type
==
2
)
{
// 药店
$query
=
$query
->
where
(
'pharmacy_id'
,
$id
);
if
(
$authInfo
->
last_login_type
==
User
::
LOGIN_TYPE_USER
)
{
// 用户
$query
=
$query
->
where
(
'user_id'
,
$authInfo
->
id
);
}
elseif
(
$authInfo
->
last_login_type
==
User
::
LOGIN_TYPE_PHARMACY
)
{
// 药店
$pharmacy
=
PharmacyModel
::
query
()
->
where
(
'user_id'
,
$authInfo
->
id
)
->
first
();
$query
=
$query
->
where
(
'pharmacy_id'
,
$pharmacy
->
id
);
}
$search_input
=
$request
->
input
(
'search_input'
);
if
(
$search_input
)
{
$query
->
where
(
'mobile'
,
'like'
,
"%
{
$search_input
}
%"
);
// ->orWhere('mobile', 'like', "%{$search_input}%");
}
$data
=
$query
->
paginate
(
10
);
// 分页
$page
=
$request
->
input
(
'page'
,
1
);
$perPage
=
$request
->
input
(
'per_page'
,
10
);
$data
=
$query
->
orderBy
(
'id'
,
'desc'
)
->
paginate
(
$perPage
,
[
'*'
],
'page'
,
$page
);
return
$this
->
success
(
$data
);
}
...
...
@@ -40,13 +45,16 @@ public function patientList(Request $request)
public
function
add
(
Request
$request
)
{
$data
=
$request
->
all
();
// TODO 表中缺少关联
// TODO 验证身份证号码是否正确
$authInfo
=
auth
(
'api'
)
->
user
();
if
(
$authInfo
->
last_login_type
==
User
::
LOGIN_TYPE_USER
)
{
// 用户
$data
[
'user_id'
]
=
$authInfo
->
id
;
}
elseif
(
$authInfo
->
last_login_type
==
User
::
LOGIN_TYPE_PHARMACY
)
{
// 药店
$pharmacy
=
PharmacyModel
::
query
()
->
where
(
'user_id'
,
$authInfo
->
id
)
->
first
();
$data
[
'pharmacy_id'
]
=
$pharmacy
->
id
;
}
$idCardInfo
=
Util
::
getIdCardInfo
(
$data
[
'id_card'
]);
$data
[
'gender'
]
=
$idCardInfo
[
'gender'
];
// $data['age'] = $idCardInfo['age']
;
$data
[
'is_default'
]
=
0
;
$res
=
PatientModel
::
create
(
$data
);
if
(
$res
)
{
return
$this
->
success
(
$res
);
...
...
@@ -92,19 +100,19 @@ public function setDefault(Request $request)
{
// 通过id找到是否存在默认问诊人,如果存在比对id是否相同,如果不同则修改默认问诊人状态
// TODO 验证条件待调整
$login_type
=
$request
->
input
(
'login_type'
);
$uid
=
$request
->
input
(
'uid'
);
$authInfo
=
auth
(
'api'
)
->
user
();
// 把该账号下的默认问诊人状态改为0
$query
=
PatientModel
::
where
(
'id'
,
$uid
)
->
where
(
'is_default'
,
1
);
if
(
$login_type
==
0
)
{
$query
=
$query
->
where
(
'user_id'
,
$uid
);
}
elseif
(
$login_type
==
2
)
{
$query
=
$query
->
where
(
'pharmacy_id'
,
$uid
);
$query
=
PatientModel
::
where
(
'is_default'
,
1
);
if
(
$authInfo
->
last_login_type
==
User
::
LOGIN_TYPE_USER
)
{
$query
=
$query
->
where
(
'user_id'
,
$authInfo
->
id
);
}
elseif
(
$authInfo
->
last_login_type
==
User
::
LOGIN_TYPE_PHARMACY
)
{
$pharmacy
=
PharmacyModel
::
query
()
->
where
(
'user_id'
,
$authInfo
->
id
)
->
first
();
$query
=
$query
->
where
(
'pharmacy_id'
,
$pharmacy
->
id
);
}
$d
ata
=
$query
->
first
();
if
(
$d
ata
)
{
$d
ata
->
is_default
=
0
;
$d
ata
->
save
();
$d
efaultPatient
=
$query
->
first
();
if
(
$d
efaultPatient
)
{
$d
efaultPatient
->
is_default
=
0
;
$d
efaultPatient
->
save
();
}
// 把当前问诊人设为默认
$id
=
$request
->
input
(
'id'
);
...
...
@@ -114,20 +122,21 @@ public function setDefault(Request $request)
}
$data
->
is_default
=
1
;
$data
->
save
();
return
$this
->
success
(
$data
);
}
// 获取默认问诊人
public
function
getDefault
(
Request
$request
)
{
$login_type
=
$request
->
input
(
'login_type'
);
$id
=
$request
->
input
(
'id'
);
$authInfo
=
auth
(
'api'
)
->
user
();
$query
=
PatientModel
::
where
(
'is_default'
,
1
);
if
(
$login_type
==
0
)
{
$query
=
$query
->
where
(
'user_id'
,
$id
);
}
elseif
(
$login_type
==
2
)
{
$query
=
$query
->
where
(
'pharmacy_id'
,
$id
);
$last_login_type
=
$authInfo
->
last_login_type
;
$user_id
=
$authInfo
->
id
;
if
(
$last_login_type
==
User
::
LOGIN_TYPE_USER
)
{
$query
=
$query
->
where
(
'user_id'
,
$user_id
);
}
elseif
(
$last_login_type
==
User
::
LOGIN_TYPE_PHARMACY
)
{
$pharmacy
=
PharmacyModel
::
query
()
->
where
(
'user_id'
,
$user_id
)
->
first
();
$query
=
$query
->
where
(
'pharmacy_id'
,
$pharmacy
->
id
);
}
$data
=
$query
->
first
();
if
(
$data
)
{
...
...
app/Api/Controllers/PrescriptionController.php
View file @
3825a4af
...
...
@@ -36,40 +36,40 @@ public function prescriptionList(Request $request)
$authInfo
=
auth
(
'api'
)
->
user
();
$query
=
PrescriptionModel
::
query
();
// TODO 判断当前登录的用户角色
#
$userInfo = User::with(['doctor', 'pharmacist'])->find($authInfo->id);
if
(
$authInfo
->
last_login_type
==
User
::
LOGIN_TYPE_USER
)
{
//
$userInfo = User::with(['doctor', 'pharmacist'])->find($authInfo->id);
if
(
$authInfo
->
last_login_type
==
User
::
LOGIN_TYPE_USER
)
{
$query
->
where
(
'user_id'
,
$authInfo
->
id
);
}
else
if
(
$authInfo
->
last_login_type
==
User
::
LOGIN_TYPE_DOCTOR
)
{
// 医师
}
elseif
(
$authInfo
->
last_login_type
==
User
::
LOGIN_TYPE_DOCTOR
)
{
// 医师
$doctor
=
DoctorModel
::
query
()
->
where
(
'user_id'
,
$authInfo
->
id
)
->
first
();
$query
->
where
(
'doctor_id'
,
$doctor
->
id
);
}
else
if
(
$authInfo
->
last_login_type
==
User
::
LOGIN_TYPE_PHARMACY
)
{
// 药店
}
elseif
(
$authInfo
->
last_login_type
==
User
::
LOGIN_TYPE_PHARMACY
)
{
// 药店
$pharmacy
=
PharmacyModel
::
query
()
->
where
(
'user_id'
,
$authInfo
->
id
)
->
first
();
$query
->
where
(
'pharmacy_id'
,
$pharmacy
->
id
);
}
#
时间段
//
时间段
$start_time
=
$request
->
input
(
'start_time'
);
$end_time
=
$request
->
input
(
'end_time'
);
if
(
$start_time
&&
$end_time
)
{
$query
->
whereBetween
(
'created_at'
,
[
$start_time
,
$end_time
]);
}
else
if
(
$start_time
)
{
}
elseif
(
$start_time
)
{
$query
->
where
(
'created_at'
,
'>='
,
$start_time
);
}
else
if
(
$end_time
)
{
}
elseif
(
$end_time
)
{
$query
->
where
(
'created_at'
,
'<='
,
$end_time
);
}
#
状态
//
状态
$status
=
$request
->
input
(
'status'
);
if
(
$status
)
{
$query
->
where
(
'status'
,
$status
);
}
#
分页
//
分页
$page
=
$request
->
input
(
'page'
,
1
);
$perPage
=
$request
->
input
(
'per_page'
,
10
);
$prescription
=
$query
->
orderBy
(
'id'
,
'desc'
)
->
paginate
(
$perPage
,
[
'*'
],
'page'
,
$page
);
$prescription
=
$query
->
orderBy
(
'id'
,
'desc'
)
->
paginate
(
$perPage
,
[
'*'
],
'page'
,
$page
);
#
$prescription = $query->paginate(10);
//
$prescription = $query->paginate(10);
return
$this
->
success
(
$prescription
);
}
...
...
routes/api.php
View file @
3825a4af
...
...
@@ -23,8 +23,9 @@
Route
::
post
(
'login'
,
'App\Api\Controllers\UserController@login'
);
// Route::get('test', 'App\Api\Controllers\DrugController@test');
# 获取药品列表
Route
::
get
(
'/drugs'
,
'App\Api\Controllers\DrugController@drugList'
);
// # 获取药品列表
// Route::get('/drugs', 'App\Api\Controllers\DrugController@drugList');
# Route::get('/test', 'App\Api\Controllers\DrugController@test');
# 获取药店列表
Route
::
get
(
'/pharmacys'
,
'App\Api\Controllers\PharmacyController@PharmacyList'
);
# 获取诊断列表
...
...
@@ -53,5 +54,27 @@
// 获取用户信息
Route
::
get
(
'/users'
,
'App\Api\Controllers\UserController@userInfo'
);
# 获取药品列表
Route
::
get
(
'/drugs'
,
'App\Api\Controllers\DrugController@drugList'
);
// # Route::get('/test', 'App\Api\Controllers\DrugController@test');
// # 获取药店列表
// Route::get('/pharmacys', 'App\Api\Controllers\PharmacyController@PharmacyList');
// # 获取诊断列表
// Route::get('/diagnosis', 'App\Api\Controllers\DiagnosisController@diagnosisList');
// # 获取问诊人列表
// Route::get('/patients', 'App\Api\Controllers\PatientController@patientList');
// # 问诊人新增
// Route::post('/patients-add', 'App\Api\Controllers\PatientController@add');
// # 问诊人编辑
// Route::post('/patients-update', 'App\Api\Controllers\PatientController@update');
// # 问诊人删除
// Route::post('/patients-delete', 'App\Api\Controllers\PatientController@delete');
// # 设置默认问诊人
// Route::post('/patients-setDefault', 'App\Api\Controllers\PatientController@setDefault');
// # 获取默认问诊人
// Route::post('/patients-getDefault', 'App\Api\Controllers\PatientController@getDefault');
// # 获取问诊问题列表
// Route::get('/inquirys', 'App\Api\Controllers\InquiryController@InquirytList');
// # 开方
// Route::post('/prescription-create', 'App\Api\Controllers\PrescriptionController@create');
});
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment