lgy 1 day ago
parent
commit
92af3b0e23
1 changed files with 260 additions and 162 deletions
  1. 260 162
      server/application/api/servies/butt/ButtService.php

+ 260 - 162
server/application/api/servies/butt/ButtService.php

@@ -48,185 +48,185 @@ class ButtService extends ZskkDefaultService {
     public function save_report($params)
     {
 //        try{
-            $time1 = time();
-            Log::record('当前传参为'.json_encode($params));
+        $time1 = time();
+        Log::record('当前传参为'.json_encode($params));
 //            Db::startTrans();
-            if(isset($params['type']) && !empty($params['type']))
+        if(isset($params['type']) && !empty($params['type']))
+        {
+            if(empty(Config::get('report_save_type')[$params['type']]))
             {
-                if(empty(Config::get('report_save_type')[$params['type']]))
-                {
-                    $this->throwError('非规则内的type值',0002);
-                }
-                if(empty($params['code']) || empty($params['institution_id']))
-                {
-                    $this->throwError('参数错误',0003);
-                }
-                $search = [Config::get('report_save_type')[$params['type']]=>$params['code']];
-                $exams = $this->butt->getExamBySearch($search,$params['institution_id']);
+                $this->throwError('非规则内的type值',0002);
+            }
+            if(empty($params['code']) || empty($params['institution_id']))
+            {
+                $this->throwError('参数错误',0003);
+            }
+            $search = [Config::get('report_save_type')[$params['type']]=>$params['code']];
+            $exams = $this->butt->getExamBySearch($search,$params['institution_id']);
 //                if(count($exams) !== 1)
 //                {
 //                    $this->throwError('存在复数的检查,请联系管理员',0004);
 //                }
 //                $exam = $exams[0];
-            }else{
-                $exam = $this->butt->getExamById($params['exam_id']);
-                $exams[] = $exam;
-            }
-            if(empty($exams))
-            {
-                $this->throwError('找不到检查',0004);
-            }
-            $id = '';
-            foreach ($exams as $exam)
-            {
+        }else{
+            $exam = $this->butt->getExamById($params['exam_id']);
+            $exams[] = $exam;
+        }
+        if(empty($exams))
+        {
+            $this->throwError('找不到检查',0004);
+        }
+        $id = '';
+        foreach ($exams as $exam)
+        {
 //            if($exam['exam_status'] != '3'){
 //                $this->throwError('报告重复','0999');
 //            }
-                $reportDoctor = $this->getReportDoctor($params['report_doctor_name'],$exam['institution_id']);
-                $reviewDoctor = $this->getReportDoctor($params['review_doctor_name'],$exam['institution_id']);
-                $confirmDoctor = $this->getReportDoctor($params['confirm_doctor_name'],$exam['institution_id']);
-                $report = [
-                    'id'=>UUIDUtils::uuid(),
-                    'exam_id'=>$exam['id'],
-                    'report_doctor_id'=>$reportDoctor,
-                    'report_doctor_name'=>$params['report_doctor_name'],
-                    'report_datetime'=>$params['report_datetime'],
-                    'review_doctor_id'=>$reviewDoctor,
-                    'review_doctor_name'=>$params['review_doctor_name'],
-                    'review_datetime'=>$params['review_datetime'],
-                    'confirm_doctor_id'=>$confirmDoctor,
-                    'confirm_doctor_name'=>$params['confirm_doctor_name'],
-                    'confirm_datetime'=>$params['confirm_datetime'],
-                    'description'=>$params['description'],
-                    'impression'=>$params['impression'],
-                    'report_result'=>$params['report_result'],
-                    'type'=>1
-                ];
-                $id = $report['id'];
-                $report_id = $this->butt->checkReport($exam['id']);
-                if(!empty($report_id)){
-                    unset($report['id']);
-                    $id = $report_id;
-                    $this->butt->saveReport($report,$report_id);
-                    $report['id'] = $report_id;
-                }else{
-                    $this->butt->saveReport($report);
-                }
-                $url = 'https://wechat.pacsonline.cn/wx_patient/api/unifyGetWxQrcode?reportId='.$id.'&version=3';
+            $reportDoctor = $this->getReportDoctor($params['report_doctor_name'],$exam['institution_id']);
+            $reviewDoctor = $this->getReportDoctor($params['review_doctor_name'],$exam['institution_id']);
+            $confirmDoctor = $this->getReportDoctor($params['confirm_doctor_name'],$exam['institution_id']);
+            $report = [
+                'id'=>UUIDUtils::uuid(),
+                'exam_id'=>$exam['id'],
+                'report_doctor_id'=>$reportDoctor,
+                'report_doctor_name'=>$params['report_doctor_name'],
+                'report_datetime'=>$params['report_datetime'],
+                'review_doctor_id'=>$reviewDoctor,
+                'review_doctor_name'=>$params['review_doctor_name'],
+                'review_datetime'=>$params['review_datetime'],
+                'confirm_doctor_id'=>$confirmDoctor,
+                'confirm_doctor_name'=>$params['confirm_doctor_name'],
+                'confirm_datetime'=>$params['confirm_datetime'],
+                'description'=>$params['description'],
+                'impression'=>$params['impression'],
+                'report_result'=>$params['report_result'],
+                'type'=>1
+            ];
+            $id = $report['id'];
+            $report_id = $this->butt->checkReport($exam['id']);
+            if(!empty($report_id)){
+                unset($report['id']);
+                $id = $report_id;
+                $this->butt->saveReport($report,$report_id);
+                $report['id'] = $report_id;
+            }else{
+                $this->butt->saveReport($report);
+            }
+            $url = 'https://wechat.pacsonline.cn/wx_patient/api/unifyGetWxQrcode?reportId='.$id.'&version=3';
 //            exec("nohup /bin/curl '$url' > /dev/null &");
 //                $this->curl_get($url);
-                $examData = [
-                    'exam_status'=>9,
-                    'application_department'=>$params['application_department'] ?? null,
-                    'application_doctor'=>$params['application_doctor'] ?? null,
-                    'clin_diag'=>$params['clin_diag'] ?? null,
-                    'clin_symp'=>$params['clin_symp'] ?? null,
-                    'name'=>$params['name'],
-                    'report_result'=>$params['report_result'] ?? ''
-                ];
-                if(isset($params['patient_source']) && !empty($params['patient_source']))
-                {
-                    $examData['patient_source'] = $params['patient_source'];
-                }
-                if(isset($params['hopitalized_no']) && !empty($params['hopitalized_no']))
-                {
-                    $examData['hopitalized_no'] = $params['hopitalized_no'];
-                }
-                if(isset($params['out_patient']) && !empty($params['out_patient']))
-                {
-                    $examData['out_patient'] = $params['out_patient'];
-                }
-                if(isset($params['his_patient_id']) && !empty($params['his_patient_id']))
-                {
-                    $examData['his_patient_id'] = $params['his_patient_id'];
-                }
-                $patient = [];
-                if(isset($params['exam_class']) && !empty($params['exam_class']))
-                {
-                    $examData['exam_class'] = $params['exam_class'];
-                    if($params['institution_id'] == '16100014')
-                    {
-                        if($examData['exam_class' == 'RF'])
-                        {
-                            $examData['exam_class'] = 'DX';
-                        }
-                    }
-                }
-                if(isset($params['phone']) && !empty($params['phone']))
-                {
-                    $examData['phone'] = $params['phone'];
-                    $patient['phone'] = $params['phone'];
-                }
-                if(isset($params['card_num']) && !empty($params['card_num']))
-                {
-                    $examData['card_num'] = $params['card_num'];
-                    $patient['card_num'] = $params['card_num'];
-                }
-                if(isset($params['exam_project']) && !empty($params['exam_project']))
+            $examData = [
+                'exam_status'=>9,
+                'application_department'=>$params['application_department'] ?? null,
+                'application_doctor'=>$params['application_doctor'] ?? null,
+                'clin_diag'=>$params['clin_diag'] ?? null,
+                'clin_symp'=>$params['clin_symp'] ?? null,
+                'name'=>$params['name'],
+                'report_result'=>$params['report_result'] ?? ''
+            ];
+            if(isset($params['patient_source']) && !empty($params['patient_source']))
+            {
+                $examData['patient_source'] = $params['patient_source'];
+            }
+            if(isset($params['hopitalized_no']) && !empty($params['hopitalized_no']))
+            {
+                $examData['hopitalized_no'] = $params['hopitalized_no'];
+            }
+            if(isset($params['out_patient']) && !empty($params['out_patient']))
+            {
+                $examData['out_patient'] = $params['out_patient'];
+            }
+            if(isset($params['his_patient_id']) && !empty($params['his_patient_id']))
+            {
+                $examData['his_patient_id'] = $params['his_patient_id'];
+            }
+            $patient = [];
+            if(isset($params['exam_class']) && !empty($params['exam_class']))
+            {
+                $examData['exam_class'] = $params['exam_class'];
+                if($params['institution_id'] == '16100014')
                 {
-                    $examData['exam_project'] = $params['exam_project'];
-                    if(empty($exam['body_part_text'] ?? ''))
+                    if($examData['exam_class' == 'RF'])
                     {
-                        $examData['body_part_text'] = $this->butt->getBodyByProject($params['exam_project']);
+                        $examData['exam_class'] = 'DX';
                     }
                 }
-                if(isset($params['exam_method']) && !empty($params['exam_method']))
-                {
-                    $examData['exam_method'] = $params['exam_method'];
-                }
-                //medical_code  国家医保信息平台人员管理码
-                //body_part_code    检查部位代码
-                //device_code   医保医用设备代码
-                $examData['medical_code'] = $params['medical_code'] ?? str_pad(0, 26, "0", STR_PAD_LEFT);
-                $examData['body_part_code'] = $params['body_part_code'] ?? str_pad(0, 9, "0", STR_PAD_LEFT);
-                $examData['device_code'] = $params['device_code'] ?? str_pad(0, 13, "0", STR_PAD_LEFT);
-                $study = $this->butt->getStudyByExamId($exam['id']);
-                if(!empty($study['studytime'] ?? ''))
-                {
-                    $studyDate = $study['studytime'];
-                    $examData['exam_datetime_code'] = $exam['exam_datetime'].substr($studyDate, 0, 4);
-                }
-                $this->butt->updateExam($examData,$exam['id']);
-                PublicPhone::savePublicSearch($params['phone'] ?? '',$exam['id'] ?? '');
-                $patientId = $exam['patient_id'];
-                $patient['name'] = $params['name'];
-                $this->butt->updatePatient($patient,$patientId);
-                $institution = $this->butt->getIns($exam['institution_id']);
-                if($institution['keyword_switch'] == 1)
-                {
-                    $wechat = [
-                        'type'=>7,
-                        'id'=>$exam['id'],
-                        'report_id'=>$id,
-                    ];
-                    $wechat = json_encode($wechat);
-                    $wechatUrl = 'https://ws4.pacsonline.cn/sendWechatMsg?params='.$wechat;
-                    $this->curl_get($wechatUrl);
-                }
-                Log::record('当前医院是否发送短信'.$institution['patient_sms']);
-                if($institution['patient_sms'] == 1)
+            }
+            if(isset($params['phone']) && !empty($params['phone']))
+            {
+                $examData['phone'] = $params['phone'];
+                $patient['phone'] = $params['phone'];
+            }
+            if(isset($params['card_num']) && !empty($params['card_num']))
+            {
+                $examData['card_num'] = $params['card_num'];
+                $patient['card_num'] = $params['card_num'];
+            }
+            if(isset($params['exam_project']) && !empty($params['exam_project']))
+            {
+                $examData['exam_project'] = $params['exam_project'];
+                if(empty($exam['body_part_text'] ?? ''))
                 {
-                    log::record('可以发送短信,查看检查id'.$exam['id'].'查看study是'.$exam['study_id']);
-                    $telSend = $this->butt->getHistorySend($exam['id'],$exam['study_id']);
-                    if(empty($telSend))
-                    {
-                        log::record('手机号'.($params['phone'] ?? $exam['phone']),'没有发送过短信');
-                        // 为空 没有发送过短信
-                        $this->sendSms(($params['phone'] ?? $exam['phone']),$exam['id'],$exam['study_id'],$exam['institution_id'],3,($params['exam_class'] ?? $exam['exam_class']),$exam['exam_datetime']);
-                    }
+                    $examData['body_part_text'] = $this->butt->getBodyByProject($params['exam_project']);
                 }
-                if(in_array($exam['institution_id'],['13000003','04500002']))
+            }
+            if(isset($params['exam_method']) && !empty($params['exam_method']))
+            {
+                $examData['exam_method'] = $params['exam_method'];
+            }
+            //medical_code  国家医保信息平台人员管理码
+            //body_part_code    检查部位代码
+            //device_code   医保医用设备代码
+            $examData['medical_code'] = $params['medical_code'] ?? str_pad(0, 26, "0", STR_PAD_LEFT);
+            $examData['body_part_code'] = $params['body_part_code'] ?? str_pad(0, 9, "0", STR_PAD_LEFT);
+            $examData['device_code'] = $params['device_code'] ?? str_pad(0, 13, "0", STR_PAD_LEFT);
+            $study = $this->butt->getStudyByExamId($exam['id']);
+            if(!empty($study['studytime'] ?? ''))
+            {
+                $studyDate = $study['studytime'];
+                $examData['exam_datetime_code'] = $exam['exam_datetime'].substr($studyDate, 0, 4);
+            }
+            $this->butt->updateExam($examData,$exam['id']);
+            PublicPhone::savePublicSearch($params['phone'] ?? '',$exam['id'] ?? '');
+            $patientId = $exam['patient_id'];
+            $patient['name'] = $params['name'];
+            $this->butt->updatePatient($patient,$patientId);
+            $institution = $this->butt->getIns($exam['institution_id']);
+            if($institution['keyword_switch'] == 1)
+            {
+                $wechat = [
+                    'type'=>7,
+                    'id'=>$exam['id'],
+                    'report_id'=>$id,
+                ];
+                $wechat = json_encode($wechat);
+                $wechatUrl = 'https://ws4.pacsonline.cn/sendWechatMsg?params='.$wechat;
+                $this->curl_get($wechatUrl);
+            }
+            Log::record('当前医院是否发送短信'.$institution['patient_sms']);
+            if($institution['patient_sms'] == 1)
+            {
+                log::record('可以发送短信,查看检查id'.$exam['id'].'查看study是'.$exam['study_id']);
+                $telSend = $this->butt->getHistorySend($exam['id'],$exam['study_id']);
+                if(empty($telSend))
                 {
-                    $newExam = $this->butt->getExamById($exam['id']);
-                    $this->saveHrData($newExam,$report,$institution);
+                    log::record('手机号'.($params['phone'] ?? $exam['phone']),'没有发送过短信');
+                    // 为空 没有发送过短信
+                    $this->sendSms(($params['phone'] ?? $exam['phone']),$exam['id'],$exam['study_id'],$exam['institution_id'],3,($params['exam_class'] ?? $exam['exam_class']),$exam['exam_datetime']);
                 }
             }
+            if(in_array($exam['institution_id'],['13000003','04500002']))
+            {
+                $newExam = $this->butt->getExamById($exam['id']);
+                $this->saveHrData($newExam,$report,$institution);
+            }
+        }
 //            DB::commit();
-            $time2 = time();
-            $time = $time2-$time1;
-            $this->saveMonitorReport($params,$institution);
-            //$this->butt->insertSpecialLog($time,'butt/saveReport');
-            return $id;
+        $time2 = time();
+        $time = $time2-$time1;
+        $this->saveMonitorReport($params,$institution);
+        //$this->butt->insertSpecialLog($time,'butt/saveReport');
+        return $id;
 //        } catch (\Exception $exception){
 //            DB::rollback();
 //            $this->throwError($exception->getMessage(),0001);
@@ -380,8 +380,8 @@ class ButtService extends ZskkDefaultService {
         if($return['code'] == 1)
         {
             // 请求成功
-           $this->setCache('hrToken',$return['data']['token'],3500);
-           return $return['data']['token'];
+            $this->setCache('hrToken',$return['data']['token'],3500);
+            return $return['data']['token'];
         }else{
             return 'error';
         }
@@ -2070,11 +2070,11 @@ class ButtService extends ZskkDefaultService {
                 'link_visit_uv' => 0,
                 'sms_visit_pv' => 0,
                 'sms_visit_uv' => 0,
-            ]; 
+            ];
         }
-        
+
         $analysis = [];
-        
+
         $exams = $this->reportDao->getExamGroupByIns($dateWhere);
         foreach ($exams as $exam)
         {
@@ -2199,4 +2199,102 @@ class ButtService extends ZskkDefaultService {
             return '邮件发送失败: '.$mail->ErrorInfo;
         }
     }
+
+    public function saveDmExam($data)
+    {
+        $arr = $this->makeDmExamDatas($data);
+        $where = ['studyuid'=>$arr['studyuid'],'institution_id'=>$arr['institution_id']];
+        $exam = $this->butt->getExam($where,'*');
+        if(empty($exam))
+        {
+            $info = $this->butt->getExam(['imagenumber'=>$arr['imagenumber'],'institution_id'=>$arr['institution_id']],'*');
+            if(empty($info))
+            {
+                $arr['id'] = UUIDUtils::uuid();
+                $this->butt->insertExam($arr);
+                $id = $arr['id'];
+            }else{
+                $this->butt->updateExam($arr,$info['id']);
+                $id = $info['id'];
+            }
+
+        }else{
+            $this->butt->updateExam($arr,$exam['id']);
+            $id = $exam['id'];
+        }
+        $report = $this->butt->getReportData(['exam_id'=>null,'imagenumber'=>$arr['imagenumber']]);
+        if(!empty($report))
+        {
+            $this->butt->updateReport(['exam_id'=>null,'imagenumber'=>$arr['imagenumber']],['exam_id'=>$id]);
+            $this->butt->updateExam(['exam_status'=>9],$id);
+        }
+        return $id;
+    }
+
+    public function makeDmExamDatas($data)
+    {
+        $sexArr = ['1'=>'M','2'=>'F'];
+        $arr = [];
+        $arr['name'] = $data['A']['AA'];
+        $arr['card_num'] = $data['A']['AC'];
+        $arr['sex'] = $sexArr[$data['A']['AD']] ?? 'O';
+        $arr['birthday'] = $data['A']['AE'];
+        $arr['phone'] = $data['A']['AF'];
+        $arr['patient_num'] = $data['B']['BB'];
+        $arr['imagenumber'] = $data['B']['BD'];
+        $arr['application_department'] = $data['B']['BF'];
+        $arr['application_doctor'] = $data['B']['BG'];
+        $arr['age'] = $data['B']['BJ'];
+        $arr['institution_id'] = $data['B']['BK'];
+        $arr['clin_diag'] = $data['B']['BM'];
+        $arr['exam_class'] = $data['C']['CC'];
+        $arr['exam_project'] = $data['C']['CD'];
+        $arr['body_part'] = $data['C']['CF'];
+        $arr['exam_datetime'] = date('Ymd',strtotime($data['C']['CI']));
+        $arr['studyuid'] = $data['C']['CM'];
+        $arr['exam_status'] = 3;
+        return $arr;
+    }
+
+    public function saveDmReport($data)
+    {
+        $where = ['imagenumber'=>$data['B']['BD'],'institution_id'=>$data['B']['BJ']];
+        $exam = $this->butt->getExam($where,'*');
+        $report = $this->makeReportData($data);
+        if(empty($exam))
+        {
+            $report['id'] = UUIDUtils::uuid();
+            $this->butt->insertReport($report);
+            return '';
+        }else{
+            $report['exam_id'] = $exam['id'];
+            $old = $this->butt->getReportData(['exam_id'=>$exam['id'],'type'=>1],'*');
+            if(empty($old))
+            {
+                //
+                $report['id'] = UUIDUtils::uuid();
+                $this->butt->insertReport($report);
+            }else{
+                $this->butt->updateReport($report,['id'=>$old['id']]);
+            }
+            $this->butt->updateExam(['exam_status'=>9],$exam['id']);
+            return 'success';
+        }
+    }
+
+    public function makeReportData($data)
+    {
+        $report = [];
+        $report['description'] = $data['C']['CD'];
+        $report['impression'] = $data['C']['CE'];
+        $report['report_result'] = ($data['C']['CF'] == 9) ? null : $data['C']['CF'];
+        $report['report_doctor_name'] = $data['C']['CH'];
+        $report['review_doctor_name'] = $data['C']['CI'];
+        $report['confirm_doctor_name'] = $data['C']['CI'];
+        $report['report_datetime'] = $data['C']['CJ'];
+        $report['review_datetime'] = $data['C']['CK'];
+        $report['confirm_datetime'] = $data['C']['CK'];
+        $report['imagenumber'] = $data['B']['BD'];
+        return $report;
+    }
 }