From 11bf031bd42d41006ffcabc9da57e0c8412a2456 Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Tue, 5 Dec 2023 13:44:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=82=A3=E8=80=85=E5=A1=AB?= =?UTF-8?q?=E5=86=99=E7=BC=BA=E5=B0=91=E5=AD=97=E6=AE=B5=E8=87=B3=E5=8C=BB?= =?UTF-8?q?=E7=94=9F=EF=BC=8C=E5=90=8C=E6=AD=A5=E4=BF=AE=E6=94=B9=E9=97=AE?= =?UTF-8?q?=E8=AF=8A=E7=97=85=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/PatientCaseService.php | 45 ++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/app/Services/PatientCaseService.php b/app/Services/PatientCaseService.php index 9cace7b..c91c069 100644 --- a/app/Services/PatientCaseService.php +++ b/app/Services/PatientCaseService.php @@ -16,6 +16,7 @@ use App\Model\PatientFamilyHealth; use App\Model\PatientFamilyPersonal; use App\Model\User; use App\Model\UserDoctor; +use Hyperf\DbConnection\Db; use Hyperf\Redis\Redis; /** @@ -473,6 +474,16 @@ class PatientCaseService extends BaseService return fail(); } + // 获取病例信息 + $params = array(); + $params['order_inquiry_id'] = $order_inquiry_id; + $order_inquiry_case = OrderInquiryCase::getOne($params); + if (empty($order_inquiry_case)) { + return fail(); + } + + $order_inquiry_case = $order_inquiry_case->toArray(); + // 初始字段定义 $fields = [ "relation", // 与患者关系(1:本人 2:父母 3:爱人 4:子女 5:亲戚 6:其他 ) @@ -505,6 +516,8 @@ class PatientCaseService extends BaseService "chemical_compound_describe", // 化合物描述 ]; + Db::beginTransaction(); + try { $redis = $this->container->get(Redis::class); $redis_key = "patient_family_inquiry_case_unfilled_fields_" . $order_inquiry_id; @@ -515,19 +528,46 @@ class PatientCaseService extends BaseService // 患者病例字段 $case_fields = []; + + // 修改字段 + $order_inquiry_case_data = []; + foreach ($request_params['fields'] as $key => $value){ if (!in_array($key,$fields)){ if ($key != "order_inquiry_id"){ + Db::rollBack(); return fail(HttpEnumCode::HTTP_ERROR,"存在非法数据"); } } + if ($value === ""){ + continue; + } + + // 判断修改数据 + if (array_key_exists($key,$order_inquiry_case)){ + if ($order_inquiry_case[$key] == null){ + $order_inquiry_case_data[$key] = $value; + } + } + $case_fields[$key] = $value; } - $case_fields = json_encode($case_fields,JSON_UNESCAPED_UNICODE); + // 存储至问诊病例中 + if (!empty($order_inquiry_case_data)){ + $params = array(); + $params['inquiry_case_id'] = $order_inquiry_case['inquiry_case_id']; + $res = OrderInquiryCase::edit($params,$order_inquiry_case_data); + if (!$res){ + Db::rollBack(); + return fail(); + } + } // 发送im消息 + $case_fields = json_encode($case_fields,JSON_UNESCAPED_UNICODE); + $imService = new ImService(); $imService->CaseUnfilledFieldsToDoctor($order_inquiry,$doctor['user_id'],$user_info['user_id'],$case_fields); @@ -545,7 +585,10 @@ class PatientCaseService extends BaseService }else{ $redis->del($redis_key); } + + Db::commit(); }catch (\Throwable $e){ + Db::rollBack(); return fail(); }