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
15ac49c6
authored
Nov 19, 2024
by
赵增煜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化开方
parent
61409061
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
24 deletions
+54
-24
app/Api/Controllers/PharmacistController.php
+1
-0
app/Api/Controllers/PrescriptionController.php
+53
-24
No files found.
app/Api/Controllers/PharmacistController.php
View file @
15ac49c6
...
...
@@ -47,6 +47,7 @@ public function detail(Request $request)
// 证书上传
public
function
uploadCertificate
(
Request
$request
)
{
// 验证上传的图片文件
$validated
=
$request
->
validate
([
'image'
=>
'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048'
,
...
...
app/Api/Controllers/PrescriptionController.php
View file @
15ac49c6
...
...
@@ -157,18 +157,45 @@ public function create(Request $request)
$prescription_period_end
=
$site_config
[
'prescription_period_end'
];
$prescription_limit_buy_7
=
$site_config
[
'prescription_limit_buy_7'
];
// 分派医师 TODO 医师当日开方未达到上限以及是否在时间段的搜索出来
// 分派医师 医师当日开方未达到上限以及是否在时间段的搜索出来
if
(
$prescription_period_status
==
'1'
)
{
// 获取当前时间
$currentTime
=
Carbon
::
now
();
// 解析开始和结束时间
$startTime
=
Carbon
::
createFromFormat
(
'H:i'
,
$prescription_period_start
);
$endTime
=
Carbon
::
createFromFormat
(
'H:i'
,
$prescription_period_end
);
// 判断当前时间是否在范围内
if
(
!
$currentTime
->
between
(
$startTime
,
$endTime
))
{
return
$this
->
failed
(
'当前时间不在开方时间段内'
);
}
}
if
(
intval
(
$prescription_limit
)
>
0
)
{
$startOfDay
=
Carbon
::
now
()
->
startOfDay
();
$endOfDay
=
Carbon
::
now
()
->
endOfDay
();
$doctorIds
=
DoctorModel
::
query
()
->
where
(
'status'
,
1
)
->
pluck
(
'id'
)
->
toArray
();
$prescriptionCounts
=
DB
::
table
(
'prescription'
)
->
select
(
'doctor_id'
,
DB
::
raw
(
'COUNT(*) as prescription_count'
))
->
whereIn
(
'doctor_id'
,
$doctorIds
)
->
whereBetween
(
'created_at'
,
[
$startOfDay
,
$endOfDay
])
->
groupBy
(
'doctor_id'
)
->
pluck
(
'prescription_count'
,
'doctor_id'
);
}
else
{
// 筛选未达到上限的医师
$availableDoctors
=
collect
(
$doctorIds
)
->
filter
(
function
(
$doctorId
)
use
(
$prescriptionCounts
,
$prescription_limit
)
{
return
$prescriptionCounts
->
get
(
$doctorId
,
0
)
<
$prescription_limit
;
})
->
values
()
->
all
();
// 随机取一个随机医师
$randomDoctor
=
DB
::
table
(
'doctor'
)
->
whereIn
(
'id'
,
$availableDoctors
)
->
inRandomOrder
()
->
first
();
}
else
{
$randomDoctor
=
DoctorModel
::
inRandomOrder
()
->
where
(
'status'
,
1
)
->
first
();
}
// 判断是否开启时间段
// foreach ($doctors as $key => $doctor) {
// }
$randomDoctor
=
DoctorModel
::
inRandomOrder
()
->
where
(
'status'
,
1
)
->
first
();
$prescription
->
doctor_id
=
$randomDoctor
->
id
;
$prescription
->
doctor_name
=
$randomDoctor
->
mame
;
$prescription
->
doctor_online_hospital_name
=
$randomDoctor
->
online_hospital_name
;
...
...
@@ -212,27 +239,29 @@ public function create(Request $request)
// 判断是否为医师自动开方
$prescription_auto
=
$site_config
[
'prescription_auto'
];
if
(
$
prescription
_auto
==
1
)
{
if
(
$
$randomDoctor
->
is
_auto
==
1
)
{
$prescription
->
status
=
PrescriptionModel
::
PRESCRIPTION_STATUS_REVIEWING
;
$prescription
->
save
();
// 生成医师开方日志
$doctorLog
=
new
PrescriptionLogModel
;
$doctorLog
->
pharmacy_id
=
$pharmacy_id
;
$doctorLog
->
pharmacy_name
=
$pharmacy
->
name
;
$currentTime
=
$prescription_at
;
$doctorLog
->
log_info
=
$randomDoctor
->
mame
.
'在'
.
$prescription_at
.
'为'
.
$patient
->
name
.
'('
.
$patient
->
mobile
.
')开具处方单(处方单编号:'
.
$prescription_number
.
')'
;
$doctorLog
->
save
();
}
if
(
$pharmacy
->
is_auto
==
1
)
{
$prescription
->
status
=
PrescriptionModel
::
PRESCRIPTION_STATUS_SUCCESS
;
$prescription
->
save
();
// 生成药师审方日志
$pharmacistLog
=
new
PrescriptionLogModel
;
$pharmacistLog
->
pharmacy_id
=
$pharmacy_id
;
$pharmacistLog
->
pharmacy_name
=
$pharmacy
->
name
;
$currentTime
=
$review_at
;
$pharmacistLog
->
log_info
=
$pharmacist
->
name
.
'在'
.
$review_at
.
'为'
.
$patient
->
name
.
'('
.
$patient
->
mobile
.
')审方(处方单编号:'
.
$prescription_number
.
')'
;
$pharmacistLog
->
save
();
}
// 生成医师开方日志
$doctorLog
=
new
PrescriptionLogModel
;
$doctorLog
->
pharmacy_id
=
$pharmacy_id
;
$doctorLog
->
pharmacy_name
=
$pharmacy
->
name
;
$currentTime
=
$prescription_at
;
$doctorLog
->
log_info
=
$randomDoctor
->
mame
.
'在'
.
$prescription_at
.
'为'
.
$patient
->
name
.
'('
.
$patient
->
mobile
.
')开具处方单(处方单编号:'
.
$prescription_number
.
')'
;
$doctorLog
->
save
();
// TODO 判断是否药师自动审方
// 生成药师审方日志
$pharmacistLog
=
new
PrescriptionLogModel
;
$pharmacistLog
->
pharmacy_id
=
$pharmacy_id
;
$pharmacistLog
->
pharmacy_name
=
$pharmacy
->
name
;
$currentTime
=
$review_at
;
$pharmacistLog
->
log_info
=
$pharmacist
->
name
.
'在'
.
$review_at
.
'为'
.
$patient
->
name
.
'('
.
$patient
->
mobile
.
')审方(处方单编号:'
.
$prescription_number
.
')'
;
$pharmacistLog
->
save
();
return
$this
->
success
(
'ok'
);
...
...
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