修改问诊表重复请求问题

This commit is contained in:
wucongxing 2023-12-05 17:42:08 +08:00
parent 811acd7880
commit 74a72c1cf6
2 changed files with 73 additions and 33 deletions

View File

@ -218,6 +218,10 @@ class PatientCaseService extends BaseService
$user_info = $this->request->getAttribute("userInfo") ?? []; $user_info = $this->request->getAttribute("userInfo") ?? [];
$order_inquiry_id = $this->request->input('order_inquiry_id'); $order_inquiry_id = $this->request->input('order_inquiry_id');
if ($user_info['user_type'] != 2){
return fail(HttpEnumCode::HTTP_ERROR,"非法请求");
}
// 获取订单数据 // 获取订单数据
$params = array(); $params = array();
$params['order_inquiry_id'] = $order_inquiry_id; $params['order_inquiry_id'] = $order_inquiry_id;
@ -235,6 +239,8 @@ class PatientCaseService extends BaseService
return fail(); return fail();
} }
$order_inquiry_case = $order_inquiry_case->toArray();
// 获取患者家庭成员信息表-基本信息 // 获取患者家庭成员信息表-基本信息
$params = array(); $params = array();
$params['family_id'] = $order_inquiry_case['family_id']; $params['family_id'] = $order_inquiry_case['family_id'];
@ -274,6 +280,20 @@ class PatientCaseService extends BaseService
try { try {
// 获取缓存 // 获取缓存
/**
* 获取缓存
* 缓存格式
* {
"height":{
"value":1,
"is_filled":1
},
"weight":{
"value":1,
"is_filled":1
}
* }
*/
$redis = $this->container->get(Redis::class); $redis = $this->container->get(Redis::class);
$redis_key = "patient_family_inquiry_case_unfilled_fields_" . $order_inquiry_id; $redis_key = "patient_family_inquiry_case_unfilled_fields_" . $order_inquiry_id;
$redis_value = $redis->get($redis_key); $redis_value = $redis->get($redis_key);
@ -284,31 +304,41 @@ class PatientCaseService extends BaseService
// 处理字段 // 处理字段
$result = null; $result = null;
foreach ($fields as $field){ foreach ($fields as $field){
if (array_key_exists($field,$order_inquiry_case)){
if ($order_inquiry_case[$field] !== null){ if ($order_inquiry_case[$field] !== null){
continue; continue;
} }
}
if (!empty($patient_family)){ if (!empty($patient_family)){
if (array_key_exists($field,$patient_family->toArray())){
if ($patient_family[$field] !== null){ if ($patient_family[$field] !== null){
continue; continue;
} }
} }
}
if (!empty($patient_family_health)){ if (!empty($patient_family_health)){
if (array_key_exists($field,$patient_family_health->toArray())){
if ($patient_family_health[$field] !== null){ if ($patient_family_health[$field] !== null){
continue; continue;
} }
} }
}
if (!empty($patient_family_personal)){ if (!empty($patient_family_personal)){
if (array_key_exists($field,$patient_family_personal->toArray())){
if ($patient_family_personal[$field] !== null){ if ($patient_family_personal[$field] !== null){
continue; continue;
} }
} }
}
// 缓存 // 缓存
if (!empty($redis_value)){ if (!empty($redis_value)){
if (strstr($redis_value,$field)){ $redis_value = json_decode($redis_value,true);
if (array_key_exists($field,$redis_value)){
continue; continue;
} }
} }
@ -393,25 +423,29 @@ class PatientCaseService extends BaseService
// 获取缓存 // 获取缓存
$redis_value = $redis->get($redis_key); $redis_value = $redis->get($redis_key);
if (!empty($redis_value)){ if (!empty($redis_value)){
$redis_value = explode(',',$redis_value); $redis_value = json_decode($redis_value,true);
} }
// 患者病例字段 // 患者病例字段
$case_fields = []; $case_fields = [];
foreach ($request_params['fields'] as $value){ foreach ($request_params['fields'] as $key){
if (!in_array($value,$fields)){ if (!in_array($key,$fields)){
return fail(HttpEnumCode::HTTP_ERROR,"数据选择错误"); return fail(HttpEnumCode::HTTP_ERROR,"数据选择错误");
} }
$case_fields[] = $value; $case_fields[] = $key;
// 处理缓存 // 处理缓存
if (!empty($redis_value)){ if (!empty($redis_value)){
if (in_array($value,$redis_value)){ if (array_key_exists($key,$redis_value)){
continue; continue;
} }
} }
$redis_value[] = $value;
$redis_value[$key] = [
"value" => "",
"is_filled" => 0
];
} }
if (empty($case_fields)){ if (empty($case_fields)){
@ -426,8 +460,8 @@ class PatientCaseService extends BaseService
// 添加缓存-逗号分割字符串 // 添加缓存-逗号分割字符串
if (!empty($redis_value)){ if (!empty($redis_value)){
$redis_value = implode(',',$redis_value); $redis_value = json_encode($redis_value,JSON_UNESCAPED_UNICODE);
$res = $redis->set($redis_key,$redis_value,3 * 24 * 60 * 60); $res = $redis->set($redis_key,$redis_value,31 * 24 * 60 * 60);
if (!$res){ if (!$res){
return fail(); return fail();
} }
@ -523,7 +557,7 @@ class PatientCaseService extends BaseService
$redis_key = "patient_family_inquiry_case_unfilled_fields_" . $order_inquiry_id; $redis_key = "patient_family_inquiry_case_unfilled_fields_" . $order_inquiry_id;
$redis_value = $redis->get($redis_key); $redis_value = $redis->get($redis_key);
if (!empty($redis_value)){ if (!empty($redis_value)){
$redis_value = explode(',',$redis_value); $redis_value = json_decode($redis_value,true);
} }
// 患者病例字段 // 患者病例字段
@ -540,10 +574,27 @@ class PatientCaseService extends BaseService
} }
} }
// 跳过关联字段传空,如是否是否过敏史、过敏史描述
if ($value === ""){ if ($value === ""){
continue; continue;
} }
// 判断是否存在于缓存中
if (!empty($redis_value)){
if (!array_key_exists($key,$redis_value)){
Db::rollBack();
return fail(HttpEnumCode::HTTP_ERROR,"存在非法数据");
}else{
if ($redis_value[$key]['is_filled'] == 1){
Db::rollBack();
return fail(HttpEnumCode::HTTP_ERROR,"请勿重复提交");
}
$redis_value[$key]['value'] = $value;
$redis_value[$key]['is_filled'] = 1;
}
}
// 判断修改数据 // 判断修改数据
if (array_key_exists($key,$order_inquiry_case)){ if (array_key_exists($key,$order_inquiry_case)){
if ($order_inquiry_case[$key] == null){ if ($order_inquiry_case[$key] == null){
@ -573,18 +624,12 @@ class PatientCaseService extends BaseService
// 处理缓存 // 处理缓存
if (!empty($redis_value)){ if (!empty($redis_value)){
$diff_values = array_diff($redis_value, array_keys($request_params['fields'])); $redis_value = json_encode($redis_value,JSON_UNESCAPED_UNICODE);
if (!empty($diff_values)){ $res = $redis->set($redis_key,$redis_value,31 * 24 * 60 * 60);
// 添加缓存-逗号分割字符串
$redis_value = implode(',',$diff_values);
$res = $redis->set($redis_key,$redis_value,3 * 24 * 60 * 60);
if (!$res){ if (!$res){
return fail(); return fail();
} }
} }
}else{
$redis->del($redis_key);
}
Db::commit(); Db::commit();
}catch (\Throwable $e){ }catch (\Throwable $e){

View File

@ -22,7 +22,6 @@ use App\Controller\LoginController;
use App\Controller\CodeController; use App\Controller\CodeController;
use App\Controller\MessageNoticeController; use App\Controller\MessageNoticeController;
use App\Controller\PatientCaseController; use App\Controller\PatientCaseController;
use App\Controller\PatientCenterController;
use App\Controller\PatientDoctorController; use App\Controller\PatientDoctorController;
use App\Controller\PatientFamilyController; use App\Controller\PatientFamilyController;
use App\Controller\PatientOrderController; use App\Controller\PatientOrderController;
@ -35,7 +34,6 @@ use App\Controller\UserDoctorController;
use App\Controller\UserPatientController; use App\Controller\UserPatientController;
use App\Controller\UserPharmacistController; use App\Controller\UserPharmacistController;
use App\Middleware\Rule\LockRequestMiddleware; use App\Middleware\Rule\LockRequestMiddleware;
use App\Services\SafeService;
use Hyperf\HttpServer\Router\Router; use Hyperf\HttpServer\Router\Router;
@ -83,9 +81,6 @@ Router::addGroup('/doctor', function () {
// 修改医生问诊配置 // 修改医生问诊配置
Router::put('/config', [UserDoctorController::class, 'putInquiryConfig']); Router::put('/config', [UserDoctorController::class, 'putInquiryConfig']);
// // 获取患者问诊病例
// Router::get('/case', [InquiryController::class, 'getPatientInquiryCase']);
// 获取医生问诊消息列表 // 获取医生问诊消息列表
Router::get('/message', [UserDoctorController::class, 'getDoctorMessageList']); Router::get('/message', [UserDoctorController::class, 'getDoctorMessageList']);