Commit 0e6c7d7d by 赵增煜

脚本自动更新处方单状态

parent 889240a2
...@@ -297,15 +297,15 @@ public function create(Request $request) ...@@ -297,15 +297,15 @@ public function create(Request $request)
// 判断是否为医师自动开方 // 判断是否为医师自动开方
// $prescription_auto = $site_config['prescription_auto']; // $prescription_auto = $site_config['prescription_auto'];
if ($randomDoctor->is_auto == 1) { if ($randomDoctor->is_auto == 1) {
$prescription->status = PrescriptionModel::PRESCRIPTION_STATUS_REVIEWING; // $prescription->status = PrescriptionModel::PRESCRIPTION_STATUS_REVIEWING;
$prescription->save(); // $prescription->save();
// 生成医师开方日志 // // 生成医师开方日志
$doctorLog = new PrescriptionLogModel; // $doctorLog = new PrescriptionLogModel;
$doctorLog->pharmacy_id = $pharmacy_id; // $doctorLog->pharmacy_id = $pharmacy_id;
$doctorLog->pharmacy_name = $pharmacy->name; // $doctorLog->pharmacy_name = $pharmacy->name;
$currentTime = $prescription_at; // $currentTime = $prescription_at;
$doctorLog->log_info = $randomDoctor->name.'在'.$prescription_at.'为'.$patient->name.'('.$patient->mobile.')开具处方单(处方单编号:'.$prescription_number.')'; // $doctorLog->log_info = $randomDoctor->name.'在'.$prescription_at.'为'.$patient->name.'('.$patient->mobile.')开具处方单(处方单编号:'.$prescription_number.')';
$doctorLog->save(); // $doctorLog->save();
} elseif ($randomDoctor->is_auto == 0) { } elseif ($randomDoctor->is_auto == 0) {
// 手动开方发送医师通知短信 // 手动开方发送医师通知短信
if (env('SMS_CHANNEL') == 'chengliye') { if (env('SMS_CHANNEL') == 'chengliye') {
...@@ -327,15 +327,15 @@ public function create(Request $request) ...@@ -327,15 +327,15 @@ public function create(Request $request)
// 药店自动审方(必须处方单待审方) // 药店自动审方(必须处方单待审方)
if ($pharmacy->is_auto == 1 && $prescription->status == PrescriptionModel::PRESCRIPTION_STATUS_REVIEWING) { if ($pharmacy->is_auto == 1 && $prescription->status == PrescriptionModel::PRESCRIPTION_STATUS_REVIEWING) {
$prescription->status = PrescriptionModel::PRESCRIPTION_STATUS_SUCCESS; // $prescription->status = PrescriptionModel::PRESCRIPTION_STATUS_SUCCESS;
$prescription->save(); // $prescription->save();
// 生成药师审方日志 // // 生成药师审方日志
$pharmacistLog = new PrescriptionLogModel; // $pharmacistLog = new PrescriptionLogModel;
$pharmacistLog->pharmacy_id = $pharmacy_id; // $pharmacistLog->pharmacy_id = $pharmacy_id;
$pharmacistLog->pharmacy_name = $pharmacy->name; // $pharmacistLog->pharmacy_name = $pharmacy->name;
$currentTime = $review_at; // $currentTime = $review_at;
$pharmacistLog->log_info = $pharmacist->name.'在'.$review_at.'为'.$patient->name.'('.$patient->mobile.')审方(处方单编号:'.$prescription_number.')'; // $pharmacistLog->log_info = $pharmacist->name.'在'.$review_at.'为'.$patient->name.'('.$patient->mobile.')审方(处方单编号:'.$prescription_number.')';
$pharmacistLog->save(); // $pharmacistLog->save();
} elseif ($pharmacy->is_auto == 0) { } elseif ($pharmacy->is_auto == 0) {
// 手动审方发送药店通知短信 // 手动审方发送药店通知短信
if (env('SMS_CHANNEL') == 'chengliye') { if (env('SMS_CHANNEL') == 'chengliye') {
......
...@@ -32,11 +32,65 @@ class PrescriptionCommand extends Command ...@@ -32,11 +32,65 @@ class PrescriptionCommand extends Command
*/ */
public function handle() public function handle()
{ {
$this->info('开始自动审开方...'); while (true) {
// 执行自动开方
$this->autoPrescriptionGen();
// 执行自动审方
$this->autoPrescriptionReview();
$this->info('等待5秒...');
sleep(5);
}
}
// 自动开方
public function autoPrescriptionGen()
{
$this->info('开始自动开方...');
// 如果处方单是审方状态,同时对应的药店开启自动审方
$prescriptions = PrescriptionModel::where('status', PrescriptionModel::PRESCRIPTION_STATUS_PENDING)
->get();
Log::info('自动开方:'.json_encode($prescriptions));
if ($prescriptions->count() <= 0) {
$this->info('没有需要开方的处方单');
return;
}
foreach ($prescriptions as $prescription) {
// 查询对应的医师是手动并且药师为自动
// $pharmacist = PharmacyModel::where('id', $prescription->pharmacy_id)->first();
$doctor = DoctorModel::where('id', $prescription->doctor_id)->first();
// if ($doctor->is_auto == 0 && $pharmacist->is_auto == 1) {
if ($doctor->is_auto == 1) {
// 更新处方单状态
$prescriptionInfo = PrescriptionModel::find($prescription->id);
if ($prescriptionInfo) {
$prescriptionInfo->status = PrescriptionModel::PRESCRIPTION_STATUS_REVIEWING;
$prescriptionInfo->save();
// 获取患者信息
$patient = PatientModel::where('id', $prescriptionInfo->patient_id)->first();
// 生成审方日志
$dateTime = new DateTime($prescription->created_at);
$dateTime->modify('+3 minutes');
$pharmacistLog = new PrescriptionLogModel;
$pharmacistLog->pharmacy_id = $prescription->pharmacy_id;
$pharmacistLog->pharmacy_name = $prescription->pharmacy_name;
$currentTime = $dateTime->format('Y-m-d H:i:s');
$pharmacistLog->log_info = $prescription->doctor_name.'在'.$currentTime.'为'.$prescription->patient_name.'('.$patient->mobile.')开方(处方单编号:'.$prescription->id.')';
$pharmacistLog->save();
$this->info($prescription->id.'开方成功');
}
}
}
}
// 自动审方
public function autoPrescriptionReview()
{
$this->info('开始自动审方...');
// 如果处方单是审方状态,同时对应的药店开启自动审方 // 如果处方单是审方状态,同时对应的药店开启自动审方
$prescriptions = PrescriptionModel::where('status', PrescriptionModel::PRESCRIPTION_STATUS_REVIEWING) $prescriptions = PrescriptionModel::where('status', PrescriptionModel::PRESCRIPTION_STATUS_REVIEWING)
->get(); ->get();
Log::info('自动审方:'.json_encode($prescriptions)); Log::info('自动审方:'.json_encode($prescriptions));
if ($prescriptions->count() <= 0) { if ($prescriptions->count() <= 0) {
$this->info('没有需要审方的处方单'); $this->info('没有需要审方的处方单');
...@@ -45,8 +99,9 @@ public function handle() ...@@ -45,8 +99,9 @@ public function handle()
foreach ($prescriptions as $prescription) { foreach ($prescriptions as $prescription) {
// 查询对应的医师是手动并且药师为自动 // 查询对应的医师是手动并且药师为自动
$pharmacist = PharmacyModel::where('id', $prescription->pharmacy_id)->first(); $pharmacist = PharmacyModel::where('id', $prescription->pharmacy_id)->first();
$doctor = DoctorModel::where('id', $prescription->doctor_id)->first(); // $doctor = DoctorModel::where('id', $prescription->doctor_id)->first();
if ($doctor->is_auto == 0 && $pharmacist->is_auto == 1) { // if ($doctor->is_auto == 0 && $pharmacist->is_auto == 1) {
if ($pharmacist->is_auto == 1) {
// 更新处方单状态 // 更新处方单状态
$prescriptionInfo = PrescriptionModel::find($prescription->id); $prescriptionInfo = PrescriptionModel::find($prescription->id);
if ($prescriptionInfo) { if ($prescriptionInfo) {
...@@ -67,6 +122,5 @@ public function handle() ...@@ -67,6 +122,5 @@ public function handle()
} }
} }
} }
} }
} }
...@@ -13,7 +13,7 @@ class Kernel extends ConsoleKernel ...@@ -13,7 +13,7 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule): void protected function schedule(Schedule $schedule): void
{ {
// $schedule->command('inspire')->hourly(); // $schedule->command('inspire')->hourly();
$schedule->command('mohe:prescription')->everyMinute(); # $schedule->command('mohe:prescription')->everyMinute();
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment