Commit 71e84059 by 赵增煜

新增药师签名照上传

parent 2f138082
<?php
namespace App\Api\Controllers;
use App\Http\Controllers\BaseApiController;
use App\Models\DoctorCorrectionModel;
use App\Models\DoctorModel;
use App\Models\PrescriptionModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
// 医师控制器
class DoctorController extends BaseApiController
{
// 医师详情
public function detail()
{
$authInfo = auth('api')->user();
$doctor = DoctorModel::where('user_id', $authInfo->id)->first();
if ($doctor) {
return $this->success($doctor);
}
return $this->failed('医师信息获取失败');
}
// 医师签名图片上传
public function upload(Request $request)
{
// 验证上传的图片文件
$validated = $request->validate([
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
// 获取上传的图片
if ($request->hasFile('image')) {
// 获取图片文件
$image = $request->file('image');
// 生成唯一文件名
$fileName = time().'.'.$image->getClientOriginalExtension();
// 保存图片到指定路径
$tempPath = $image->storeAs('app/public', $fileName);
// 读取文件内容
$fileContent = file_get_contents(storage_path('app/public/'.$fileName));
// 上传到腾讯云
Storage::disk('cos')->put('doctor-images/'.$fileName, $fileContent);
// 返回图片地址
$imageUrl = Storage::disk('cos')->url('doctor-images/'.$fileName);
// 签名图片地址记录到数据库
$authInfo = auth('api')->user();
$doctor = DoctorModel::where('user_id', $authInfo->id)->first();
$doctor->signed_pic = $imageUrl;
if ($doctor->save()) {
// 删除临时文件
unlink(storage_path('app/public/'.$fileName));
return $this->success(['message' => 'ok', 'url' => $imageUrl]);
}
return $this->failed('签名图片上传失败');
} else {
return $this->failed('签名图片上传失败');
}
}
// 医师开方接口
public function prescription(Request $request)
{
$id = $request->input('id');
if (empty($id) || ! filter_var($id, FILTER_VALIDATE_INT)) {
return $this->failed('无效的 ID,ID 不能为空且必须为整数');
}
$authInfo = auth('api')->user();
$doctor = DoctorModel::where('user_id', $authInfo->id)->first();
if (! $doctor) {
return $this->failed('医师信息不存在');
}
$prescription = PrescriptionModel::where('id', $id)->first();
if ($prescription->doctor_id != $doctor->id) {
return $this->failed('您没有权限开方该处方');
}
$prescription->status = PrescriptionModel::PRESCRIPTION_STATUS_REVIEWING;
if ($prescription->save()) {
return $this->success('开方成功');
} else {
return $this->failed('开方失败');
}
}
// 医师纠错
public function correction(Request $request)
{
$authInfo = auth('api')->user();
$doctor = DoctorModel::where('user_id', $authInfo->id)->first();
if (! $doctor) {
return $this->failed('医师信息不存在');
}
$content = $request->input('content');
if (empty($content)) {
return $this->failed('纠错内容不能为空');
}
$correction = new DoctorCorrectionModel();
$correction->doctor_id = $doctor->id;
$correction->doctor_name = $doctor->name;
$correction->is_handle = DoctorCorrectionModel::IS_HANDLE_FALSE;
$correction->content = $content;
if ($correction->save()) {
return $this->success('纠错上报成功!');
}
return $this->failed('纠错失败');
}
}
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
use App\Models\PharmacyDrugModel; use App\Models\PharmacyDrugModel;
use App\Models\PharmacyModel; use App\Models\PharmacyModel;
use App\Models\User; use App\Models\User;
use App\Services\SmsService;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use App\Services\SmsService;
// 药品控制器 // 药品控制器
class DrugController extends BaseApiController class DrugController extends BaseApiController
......
<?php
namespace App\Api\Controllers;
use App\Http\Controllers\BaseApiController;
use App\Models\PharmacistModel;
use App\Models\PharmacyModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class PharmacistController extends BaseApiController
{
// 药师列表
public function pharmacistList() {}
// 药师信息
// 药师新增
// 药师编辑
// 设置默认药师
// 药师签名上传
public function upload(Request $request)
{
// 验证上传的图片文件
$validated = $request->validate([
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
// 验证药师编号
$pharmacist_id = $request->input('pharmacist_id');
if (empty($pharmacist_id) || ! filter_var($pharmacist_id, FILTER_VALIDATE_INT)) {
return $this->failed('ID不能为空且必须为整数');
}
$authInfo = auth('api')->user();
// 获取药店信息
$pharmacy = PharmacyModel::where('user_id', $authInfo->id)->first();
if (empty($pharmacy)) {
return $this->failed('该药店不存在');
}
// 获取药师信息
$pharmacist = PharmacistModel::where('id', $pharmacist_id)->where('pharmacy_id', $pharmacy->id)->first();
if (empty($pharmacist)) {
return $this->failed('该药师不存在');
}
// 获取上传的图片
if ($request->hasFile('image')) {
// 获取图片文件
$image = $request->file('image');
// 生成唯一文件名
$fileName = time().'.'.$image->getClientOriginalExtension();
// 保存图片到指定路径
$tempPath = $image->storeAs('app/public', $fileName);
// 读取文件内容
$fileContent = file_get_contents(storage_path('app/public/'.$fileName));
// 上传到腾讯云
Storage::disk('cos')->put('pharmacist-images/'.$fileName, $fileContent);
// 返回图片地址
$imageUrl = Storage::disk('cos')->url('pharmacist-images/'.$fileName);
// 签名图片地址记录到数据库
$pharmacist->signed_pic = $imageUrl;
if ($pharmacist->save()) {
// 删除临时文件
unlink(storage_path('app/public/'.$fileName));
return $this->success(['message' => 'ok', 'url' => $imageUrl]);
}
return $this->failed('签名图片上传失败');
} else {
return $this->failed('签名图片上传失败');
}
}
}
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace App\Api\Controllers; namespace App\Api\Controllers;
use App\Http\Controllers\BaseApiController; use App\Http\Controllers\BaseApiController;
use App\Models\PharmacyCorrectionModel;
use App\Models\PharmacyModel; use App\Models\PharmacyModel;
use Illuminate\Http\Request; use Illuminate\Http\Request;
...@@ -35,4 +36,43 @@ public function PharmacyList(Request $request) ...@@ -35,4 +36,43 @@ public function PharmacyList(Request $request)
return $this->success($data); return $this->success($data);
} }
// 获取药店详情
public function detail($id)
{
$authInfo = auth('api')->user();
$pharmacy = PharmacyModel::where('user_id', $authInfo->id)->first();
if (! $pharmacy) {
return $this->failed('药店信息不存在');
}
return $this->success($pharmacy);
}
// 药店信息纠错
public function correction(Request $request)
{
$authInfo = auth('api')->user();
$pharmacy = PharmacyModel::where('user_id', $authInfo->id)->first();
if (! $pharmacy) {
return $this->failed('药店信息不存在');
}
$content = $request->input('content');
if (empty($content)) {
return $this->failed('纠错内容不能为空');
}
$correction = new PharmacyCorrectionModel();
$correction->pharmacy_id = $pharmacy->id;
$correction->pharmacy_name = $pharmacy->name;
$correction->is_handle = PharmacyCorrectionModel::IS_HANDLE_FALSE;
$correction->content = $content;
if ($correction->save()) {
return $this->success('纠错上报成功!');
} else {
return $this->failed('纠错失败');
}
}
// 药店审方
public function approval(Request $request) {}
} }
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
use App\Models\PrescriptionLogModel; use App\Models\PrescriptionLogModel;
use App\Models\PrescriptionModel; use App\Models\PrescriptionModel;
use App\Models\User; use App\Models\User;
use App\Services\SmsService;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
...@@ -85,69 +86,135 @@ public function prescriptionDetail(Request $request) ...@@ -85,69 +86,135 @@ public function prescriptionDetail(Request $request)
// 开方 // 开方
public function create(Request $request) public function create(Request $request)
{ {
// $userId = auth('api')->user()->id; $authInfo = auth('api')->user();
$pharmacy_id = 0;
$pharmacy = null;
// 获取当前用户信息,如果是药店则无需传pharmacy_id参数
if ($authInfo->last_login_type == User::LOGIN_TYPE_PHARMACY) {
$pharmacy = PharmacyModel::query()->where('user_id', $pharmacy_id)->first();
$pharmacy_id = $pharmacy->id;
} elseif ($authInfo->last_login_type == User::LOGIN_TYPE_DOCTOR) {
$pharmacy_id = $request->input('pharmacy_id');
$pharmacy = PharmacyModel::query()->where('id', $pharmacy_id)->first();
if (! $pharmacy) {
return $this->failed('药店信息不存在');
}
} else {
return $this->failed('pharmacy_id不能为空');
}
// 生成处方单号 // 生成处方单号
$patient_id = $request->input('patient_id'); $patient_id = $request->input('patient_id');
// 获取问诊人信息 // 获取问诊人信息
$patient = PatientModel::query()->where('id', $patient_id)->first(); $patient = PatientModel::query()->where('id', $patient_id)->first();
$prescription_umber = ''; $patient_age = getAgeByIdCard($patient->id_card);
$data = []; $prescription = new PrescriptionModel;
$data['prescription_umber'] = ''; // TODO 处方单编号生成逻辑待定 $prescription->status = PrescriptionModel::PRESCRIPTION_STATUS_PENDING;
$data['status'] = 0; // TODO Model中增加枚举 $prescription->user_id = $authInfo->id; // 获取当前用户ID
$data['user_id'] = ''; // TODO 获取当前用户ID
// 问诊人信息 // 问诊人信息
$data['patient_id'] = $patient_id; // 问诊人编号 $prescription->patient_id = $patient_id; // 问诊人编号
$data['patient_name'] = $patient->name; // 问诊人姓名 $prescription->patient_name = $patient->name; // 问诊人姓名
$data['patient_age'] = $patient->age; // 问诊人年龄 $prescription->patient_age = $patient_age; // 问诊人年龄
$data['patient_gender'] = $patient->gender; // 问诊人性别 $prescription->patient_gender = $patient->gender; // 问诊人性别
// 诊断信息 // 诊断信息
$data['diagnosis_id'] = $request->input('diagnosis_id'); $prescription->diagnosis_id = $request->input('diagnosis_id');
$data['diagnosis_name'] = $request->input('diagnosis_name'); $prescription->diagnosis_name = $request->input('diagnosis_name');
// 问诊问题 // 问诊问题
$data['inquiry_info'] = ''; // TODO 问诊问题 $prescription->inquiry_info = ''; // TODO 问诊问题
// 用药信息 // 用药信息
$data['drug_info'] = ''; // TODO 用药信息 $prescription->drug_info = ''; // TODO 用药信息
// 分派医师 医师当日开方未达到上限以及是否在时间段的搜索出来 // 分派医师 TODO 医师当日开方未达到上限以及是否在时间段的搜索出来
$site_config = DB::table('admin_settings')->where('slug', 'site_config')->value('value');
$site_config = json_decode($site_config, true);
$prescription_limit = $site_config['prescription_limit'];
// 判断是否开启时间段 // 判断是否开启时间段
$doctors = DoctorModel::query()->where('status', 1)->get();
$randomDoctor = $doctors->random();
// foreach ($doctors as $key => $doctor) { // foreach ($doctors as $key => $doctor) {
// } // }
// 判断是否为医师自动开方 $doctors = DoctorModel::query()->where('status', 1)->get();
$randomDoctor = $doctors->random();
$prescription->doctor_id = $randomDoctor->id;
$prescription->doctor_name = $randomDoctor->mame;
$prescription->doctor_online_hospital_name = $randomDoctor->online_hospital_name;
$prescription->doctor_department = $randomDoctor->department;
$prescription->doctor_title = $randomDoctor->doctor_title;
$prescription->doctor_license_no = $randomDoctor->license_no;
$prescription->doctor_signed_pic = $randomDoctor->signed_pic;
// 药店信息
$prescription->pharmacy_id = $pharmacy->id;
$prescription->pharmacy_name = $pharmacy->name;
$pharmacy_id = $request->input('pharmacy_id');
$pharmacy = PharmacyModel::query()->where('id', $pharmacy_id)->first();
// 生成医师开方日志
$dockor_log = [];
$dockor_log['pharmacy_id'] = $pharmacy_id;
$dockor_log['pharmacy_name'] = $pharmacy->name;
$currentTime = Carbon::now()->toDateTimeString();
$dockor_log['log_info'] = $randomDoctor->mame.'在'.$currentTime.'为'.$patient->name.'('.$patient->mobile.')开具处方单(处方单编号:'.$prescription_umber.')';
PrescriptionLogModel::create($dockor_log);
// 分派药师,先搜索是否存在默认药师,如果不存在则随机抽取一个 // 分派药师,先搜索是否存在默认药师,如果不存在则随机抽取一个
$pharmacist = PharmacistModel::query()->where('status', 1)->where('is_default', 1)->where('pharmacy_id', $pharmacy_id)->first(); $pharmacist = PharmacistModel::query()->where('status', 1)->where('is_default', 1)->where('pharmacy_id', $pharmacy_id)->first();
if (! $pharmacist) { if (! $pharmacist) {
$pharmacists = PharmacistModel::query()->where('status', 1)->where('pharmacy_id', $pharmacy_id)->get(); $pharmacists = PharmacistModel::query()->where('status', 1)->where('pharmacy_id', $pharmacy_id)->get();
$pharmacist = $pharmacists->random(); $pharmacist = $pharmacists->random();
} }
// 判断是否药师自动审方 $prescription->pharmacist_id = $pharmacist->id;
$prescription->pharmacist_name = $pharmacist->name;
$prescription->pharmacist_license_number = $pharmacist->license_number;
$prescription->pharmacist_signed_pic = $pharmacist->signed_pic;
// 处方单 默认状态
$prescription->status = PrescriptionModel::PRESCRIPTION_STATUS_PENDING;
// 生成处方单信息
$prescription_number = 0;
if ($prescription->save()) {
$prescription_number = $prescription->id;
} else {
return $this->failed('生成处方单失败');
}
$site_config = DB::table('admin_settings')->where('slug', 'site_config')->value('value');
$site_config = json_decode($site_config, true);
$prescription_limit = $site_config['prescription_limit'];
// 判断是否为医师自动开方
$prescription_auto = $site_config['prescription_auto'];
if ($prescription_auto == 1) {
$prescription->status = PrescriptionModel::PRESCRIPTION_STATUS_REVIEWING;
$prescription->save();
}
// 生成医师开方日志
$doctorLog = new PrescriptionLogModel;
$doctorLog->pharmacy_id = $pharmacy_id;
$doctorLog->pharmacy_name = $pharmacy->name;
$currentTime = Carbon::now()->toDateTimeString();
$doctorLog->log_info = $randomDoctor->mame.'在'.$currentTime.'为'.$patient->name.'('.$patient->mobile.')开具处方单(处方单编号:'.$prescription_number.')';
$doctorLog->save();
// TODO 判断是否药师自动审方
// 生成药师审方日志 // 生成药师审方日志
$pharamcy_log = []; $pharmacistLog = new PrescriptionLogModel;
$pharamcy_log['pharmacy_id'] = $pharmacy_id; $pharmacistLog->pharmacy_id = $pharmacy_id;
$pharamcy_log['pharmacy_name'] = $pharmacy->name; $pharmacistLog->pharmacy_name = $pharmacy->name;
$currentTime = Carbon::now()->toDateTimeString(); $currentTime = Carbon::now()->toDateTimeString();
$pharamcy_log['log_info'] = $pharmacist->name.'在'.$currentTime.'为'.$patient->name.'('.$patient->mobile.')审方'; $pharmacistLog->log_info = $pharmacist->name.'在'.$currentTime.'为'.$patient->name.'('.$patient->mobile.')审方(处方单编号:'.$prescription_number.')';
// 给医师发送短信 $pharmacistLog->save();
// TODO 给医师发送短信
$mobile = '18321861540';
$templateName = 'verification_code';
$templateData = ['code' => '1234'];
$smsService = new SmsService();
$response = $smsService->sendSms($mobile, $templateName, $templateData);
// TODO 给药师发送短信
return $this->success('ok');
// 给药师发送短信 }
// 生成处方单信息 // 开方通过
public function pass(Request $request)
{
$prescription_id = $request->input('prescription_id');
$res = PrescriptionModel::query()->where('id', $prescription_id)->update(['status' => PrescriptionModel::PRESCRIPTION_STATUS_REVIEWING]);
return $this->success($res);
}
// 审方通过
public function reviewPass(Request $request)
{
$prescription_id = $request->input('prescription_id');
$res = PrescriptionModel::query()->where('id', $prescription_id)->update(['status' => PrescriptionModel::PRESCRIPTION_STATUS_SUCCESS]);
return $this->success($data); return $this->success($res);
} }
} }
...@@ -57,4 +57,12 @@ ...@@ -57,4 +57,12 @@
Route::get('/inquirys', 'App\Api\Controllers\InquiryController@InquirytList'); Route::get('/inquirys', 'App\Api\Controllers\InquiryController@InquirytList');
# 开方 # 开方
Route::post('/prescription-create', 'App\Api\Controllers\PrescriptionController@create'); Route::post('/prescription-create', 'App\Api\Controllers\PrescriptionController@create');
# 医师详情
Route::post('/dcotor-detail', 'App\Api\Controllers\PrescriptionController@detail');
# 医师上传签名
Route::post('/dcotor-upload', 'App\Api\Controllers\PrescriptionController@upload');
# 医师纠错
Route::post('/dcotor-correction', 'App\Api\Controllers\PrescriptionController@correction');
# 药店详情
}); });
\ No newline at end of file
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