Commit f241f0de by lujunyi

命令 自动任务

parent e201d581
...@@ -17,59 +17,54 @@ class PrescriptionCommand extends Command ...@@ -17,59 +17,54 @@ class PrescriptionCommand extends Command
* *
* @var string * @var string
*/ */
protected $signature = 'app:prescription-command'; protected $signature = 'mohe:prescription';
/** /**
* The console command description. * The console command description.
* *
* @var string * @var string
*/ */
protected $description = 'Command description'; protected $description = '自动审开方';
/** /**
* Execute the console command. * Execute the console command.
*/ */
public function handle() public function handle()
{ {
$this->info('start command'); $this->info('开始自动审开方...');
// 常驻脚本 // 如果处方单是审方状态,同时对应的药店开启自动审方
while (true) { $prescriptions = PrescriptionModel::where('status', 1)
sleep(5); ->where('status', PrescriptionModel::PRESCRIPTION_STATUS_REVIEWING)
// 如果处方单是审方状态,同时对应的药店开启自动审方 ->get();
$prescriptions = PrescriptionModel::where('status', 1)
->where('status', PrescriptionModel::PRESCRIPTION_STATUS_REVIEWING)
->get();
if ($prescriptions->count() > 0) { if ($prescriptions->count() > 0) {
foreach ($prescriptions as $prescription) { $this->info('没有需要审方的处方单');
// 查询对应的医师是手动并且药师为自动
$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) {
// var_dump($prescription);
// 更新处方单状态
$prescriptionInfo = PrescriptionModel::find($prescription->id);
if ($prescriptionInfo) {
$prescriptionInfo->status = PrescriptionModel::PRESCRIPTION_STATUS_SUCCESS;
$prescriptionInfo->save();
// 获取患者信息
$patient = PatientModel::where('id', $prescriptionInfo->patient_id)->first();
// 生成审方日志
$dateTime = new DateTime($prescription->created_at);
$dateTime->modify('+5 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->pharmacist_name.'在'.$currentTime.'为'.$prescription->patient_name.'('.$patient->mobile.')审方(处方单编号:'.$prescription->id.')';
$pharmacistLog->save();
$this->info($prescription->id.'审方成功');
}
} 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) {
// 更新处方单状态
$prescriptionInfo = PrescriptionModel::find($prescription->id);
if ($prescriptionInfo) {
$prescriptionInfo->status = PrescriptionModel::PRESCRIPTION_STATUS_SUCCESS;
$prescriptionInfo->save();
// 获取患者信息
$patient = PatientModel::where('id', $prescriptionInfo->patient_id)->first();
// 生成审方日志
$dateTime = new DateTime($prescription->created_at);
$dateTime->modify('+5 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->pharmacist_name.'在'.$currentTime.'为'.$prescription->patient_name.'('.$patient->mobile.')审方(处方单编号:'.$prescription->id.')';
$pharmacistLog->save();
$this->info($prescription->id.'审方成功');
} }
} else {
$this->info('没有需要审方的处方单');
} }
} }
......
...@@ -7,16 +7,13 @@ ...@@ -7,16 +7,13 @@
class Kernel extends ConsoleKernel class Kernel extends ConsoleKernel
{ {
protected $commands = [
\App\Console\Commands\PrescriptionCommand::class,
];
/** /**
* Define the application's command schedule. * Define the application's command schedule.
*/ */
protected function schedule(Schedule $schedule): void protected function schedule(Schedule $schedule): void
{ {
// $schedule->command('inspire')->hourly(); // $schedule->command('inspire')->hourly();
$schedule->command('mohe:prescription')->everyFiveMinutes();
} }
/** /**
......
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