alias('e') ->join(['register'=>'re'],'re.exam_id = e.id','LEFT') ->where('e.status','1') ->where($fuzzyWhere) ->where($moreWhere) ->where($whereStatus) ->where($timeWhere) ->where($nameWhere) ->where($class_where) ->where('e.institution_id', $institutionId) ->count(); $num = $total - ($params['page'] - 1) * $params['num']; if($num > $params['num']) { $num = $params['num']; } $list = $this ->alias('e') ->join(['register'=>'re'],'re.exam_id = e.id','LEFT') ->where('e.status','1') ->where($fuzzyWhere) ->where($moreWhere) ->where($whereStatus) ->where($timeWhere) ->where($nameWhere) ->where($class_where) ->where('e.institution_id', $institutionId) ->limit(($params['page'] - 1) * $params['num'], $num) // ->page($params['page'],$params['num']) ->order('e.exam_datetime desc,e.createdAt desc') ->field($field) // ->fetchSql() ->select(); // $total = 10; // $total = $this // ->alias('e') // ->join(['register'=>'re'],'re.exam_id = e.id','LEFT') // ->where('e.status','1') // ->where($fuzzyWhere) // ->where($moreWhere) // ->where($whereStatus) // ->where($timeWhere) // ->where($nameWhere) // ->where($class_where) // ->where('e.institution_id', $institutionId) // ->count(); return ['total'=>$total, 'list'=>$list]; } catch (\Exception $exception){ $this->throwError($exception->getMessage(),0001); } } public function getPatientId($id) { $patientId = $this ->where('id',$id) ->value('patient_id'); return $patientId; } public function updatePatient($patientData,$patientId) { $patient = PatientModel::where('id',$patientId)->update($patientData); return $patient; } public function insertPatient($patientData) { $patient = PatientModel::insert($patientData); return $patient; } public function updateExam($data,$id) { $info = $this->where('id',$id)->update($data); return $info; } public function getRegister($params) { // 获取详情数据 $field = [ 'e.patient_num','r.exam_sub_class','e.exam_project','r.illness_desc','r.phys_sign','e.exam_datetime','e.bed_no','e.hopitalized_no','e.patient_area','e.application_department','e.application_doctor','e.id','e.exam_class', 'e.clin_symp','e.clin_diag','r.anamnesis','r.family_ill','r.ext AS remark','r.device_name','e.out_patient', 'e.name','p.card_type','e.card_num','e.sex','e.age','e.birthday','e.phone','e.institution_id',"'' AS institution", 'e.his_patient_id','e.body_part_text' ]; $data = $this ->alias('e') ->join(['register'=>'r'],'r.exam_id=e.id','left') ->join(['patient_infos'=>'p'], 'e.patient_id = p.id','left') ->where('e.id', $params['examId']) ->field($field) ->find(); if(!empty($data)){ $institution = InstitutionModel::where('id',$data['institution_id'])->value('name'); $data['institution'] = $institution; } return $data; } public function insertRegister($data) { RegisterModel::insert($data); } public function updateRegister($data,$examId) { RegisterModel::where('exam_id',$examId)->update($data); } public function deleteRegister($params,$user) { $info = $this->where('id',$params['examId'])->update(['status'=>'0','del_doctor_id'=>$user['id'],'del_doctor_name'=>$user['realname'],'del_datetime'=>date('Y-m-d H:i:s',time())]); return $info; } public function insertExam($data) { $info = $this->insert($data); return $info; } public function getExamList($institutionId, $fuzzyWhere, $moreWhere,$class_where, $params,$report_where,$gradeWhere) { try{ $nameWhere = []; if(isset($moreWhere['name_fuzzy']) && !empty($moreWhere['name_fuzzy'])){ if(isset($moreWhere['name']) && !empty($moreWhere['name'])) { // todo }else{ $nameWhere[] = ['e.name','like','%'.$moreWhere['name_fuzzy'].'%']; } unset($moreWhere['name_fuzzy']); } if(isset($moreWhere['exam_class']) && !empty($moreWhere['exam_class'])){ $moreWhere['e.exam_class'] = $moreWhere['exam_class']; unset($moreWhere['exam_class']); } $whereStatus = []; if (!(isset($moreWhere['exam_status']) && !empty($moreWhere['exam_status']))){ $whereStatus = "e.exam_status not in ('0','1','2','-99')"; } if(empty($report_where)) { $order = "e.exam_datetime desc,e.createdAt desc"; // $order = "e.id desc"; }else{ // $order = "e.doctor_sign desc,e.id desc"; $order = "e.doctor_sign desc,e.exam_datetime desc,e.createdAt desc"; } $field = [ 'e.name', 'e.sex', 'e.age','e.patient_id AS pid','e.hopitalized_no','e.bed_no','e.patient_area','e.body_part','e.application_department','e.application_doctor','e.out_patient','e.delivery_doctor','e.his_patient_id', 'e.id AS exam_id', 'e.patient_num', 'e.exam_class', 'e.exam_datetime', "e.study_id", 'e.exam_status', 'e.accession_num', 'e.exam_project','e.medical_code','e.body_part_code','e.device_code','e.exam_datetime_code', 'r.report_result', 'r.report_datetime','r.id AS rid','e.doctor_sign','e.patient_source','e.node_type', 'r.report_doctor_name','r.report_datetime', 'r.review_doctor_name','r.review_datetime', 'r.confirm_doctor_name','r.confirm_datetime', 'e.report_status','e.write_report','e.institution_id','r.impression','r.description' ]; $whereDate = []; if(($moreWhere[0] ?? null)) { $whereDate[] = $moreWhere[0]; unset($moreWhere[0]); }; $depart_where = []; if($moreWhere['application_department'] ?? null) { $depart_where[] = ['application_department','in',$moreWhere['application_department'][1]]; unset($moreWhere['application_department']); } $total = $this ->alias('e') // ->join(['patient_infos'=>'p'],'p.id=e.patient_id') // ->join(['report'=>'r'], 'e.id = r.exam_id and r.type=1','LEFT') ->where($fuzzyWhere) ->where($whereDate) ->where($gradeWhere) ->where($moreWhere) ->where($depart_where) ->where($whereStatus) ->where($report_where) ->where($nameWhere) ->where($class_where) ->where('e.institution_id', (string)($institutionId)) ->where('e.status', '1') ->count(); $limit = ($params['page']-1) * $params['num']; $num = $params['num']; // if($limit > $total) // { // $limit = $limit-$total; // } if($limit + $num > $total) { $num = $total-$limit; if($num < 0) { $num = 0; } } $list = $this ->alias('e') ->join(['report'=>'r'], 'e.id = r.exam_id and r.type=1','LEFT') ->where($fuzzyWhere) ->where($whereDate) ->where($gradeWhere) ->where($moreWhere) ->where($depart_where) ->where($whereStatus) ->where($report_where) ->where($nameWhere) ->where($class_where) ->where('e.institution_id', (string)($institutionId)) ->where('e.status', '1') ->limit($limit,$num) ->order($order) ->field($field) ->select(); $institution = InstitutionModel::where('id',$institutionId)->value('custom_field'); $unit = InstitutionModel::where('id',$institutionId)->value('image_unit_code'); foreach ($list as $k=>$v) { if(!empty($v['study_id'])) { $list[$k]['study_id'] = $v['study_id'].'&node_type='; } $list[$k]['studytime'] = ''; $studyTime = StudiesModel::where('id',$v['study_id'])->value('studytime'); if(empty($studyTime)) { $list[$k]['studytime'] = $v['exam_datetime']; }else{ $hour = substr($studyTime,0,2); $minute = substr($studyTime,2,2); $second = substr($studyTime,4,2); $year = substr($v['exam_datetime'],0,4); $month = substr($v['exam_datetime'],4,2); $day = substr($v['exam_datetime'],6,2); $list[$k]['studytime'] = $year.'.'.$month.'.'.$day.' '.$hour.':'.$minute.':'.$second; } $list[$k]['medical_index'] = $v['medical_code'].'-'.$v['exam_datetime_code'].'-'.$v['body_part_code'].'-'.$v['device_code'].'-'.$unit; } return ['total'=>$total, 'list'=>$list,'custom_field'=>$institution]; } catch (Exception $exception){ $this->throwError($exception->getMessage(),0001); } } public function getRemoteExamList($institutionId, $fuzzyWhere, $moreWhere,$class_where, $params,$report_where) { try{ $field = [ 'a.name', 'a.sex', 'a.age', 'a.exam_id', 'a.patient_num', 'a.exam_class', 'a.exam_datetime', 'a.study_id', 'a.accession_num', 'a.exam_project','a.remote_institution_name', 'r.report_result', 'r.report_datetime','r.id AS rid', 'r.report_doctor_name', 'r.review_doctor_name', 'a.report_status', 'r.remote_application_id', 'a.id AS ra_id', 'ro.status','ro.id AS order_id', 'a.remote_doctor_name' ]; $dateWhere = []; if(isset($moreWhere[0]) && !empty($moreWhere[0])){ $dateWhere[] = $moreWhere[0]; unset($moreWhere[0]); } $clWhere = []; if(isset($moreWhere['exam_class']) && !empty($moreWhere['exam_class'])){ $clWhere['a.exam_class'] = $moreWhere['exam_class']; unset($moreWhere['exam_class']); } $list = ApplicationModel::alias('a') ->join(['remote_order'=>'ro'],'a.id=ro.application_id','left') ->join(['report'=>'r'],'r.remote_application_id=a.id','LEFT') ->where($fuzzyWhere) ->where($moreWhere) ->where($clWhere) ->where($report_where) ->where($dateWhere) ->where($class_where) ->where('a.status',0) ->where('a.local_institution_id', $institutionId) ->field($field) ->page($params['page'],$params['num']) ->order('a.req_date_time desc') ->select(); $total = ApplicationModel::alias('a') ->join(['report'=>'r'],'r.remote_application_id=a.id','LEFT') ->where($fuzzyWhere) ->where($moreWhere) ->where($clWhere) ->where($report_where) ->where($dateWhere) ->where($class_where) ->where('a.status',0) ->where('a.local_institution_id', $institutionId) ->count(); return ['total'=>$total, 'list'=>$list]; } catch (Exception $exception){ $this->throwError($exception->getMessage(),0001); } } public function getRemoteList($id,$institutionId) { $field = [ // 'p.name', 'p.sex', 'p.age','p.id AS pid', // 'e.id AS exam_id', 'e.patient_num', 'e.exam_class', 'e.exam_datetime', 'e.is_remote', 'e.study_id', 'e.exam_status', 'e.accession_num', 'e.exam_project', 'r.report_datetime','r.id AS rid', 'a.*','a.id AS ra_id', ]; $list = RemoteModel::alias('a') ->join(['report'=>'r'], 'a.id = r.remote_application_id','LEFT') ->where('a.local_institution_id', $institutionId) ->where('a.exam_id',$id) ->field($field) ->order('a.exam_datetime desc') ->select(); $total = RemoteModel::alias('a') ->join(['report'=>'r'], 'a.id = r.remote_application_id','LEFT') ->where('a.local_institution_id', $institutionId) ->where('a.exam_id',$id) ->count(); return ['total'=>$total, 'list'=>$list]; } public function check($studyId) { $id = $this->where('study_id',$studyId)->value('id'); return $id; } public function getReport($where,$institution) { $data = ReportModel::alias('r') ->join(['exams'=>'e'],'e.id=r.exam_id and r.type=1') ->where('e.institution_id',$institution) ->where($where) ->field(['e.name','r.impression','r.description','e.id AS exam_id','e.study_id','r.id AS report_id','e.exam_class','e.exam_status']) ->limit(0,10) ->select(); return $data; } public function getDoctorClass($doctor) { $class = DoctorClassModel::where('doctor_id',$doctor)->value('doctor_class'); return $class; } public function changeDoctor($doctor,$id) { $info = $this->where('id',$id)->update(['doctor_sign'=>$doctor]); return $info; } public function geInsInfo($id) { $info = InstitutionModel::where('id',$id)->find(); return $info; } public function getDoctorDepart($ids) { return DepartmentModel::where('id','in',$ids)->column('department_name'); } public function getFilmAnnex($id,$exam_datetime,$code) { $info = AnnexModel::where(function ($query) use ($id,$exam_datetime,$code){ $query->where('exam_id',$id) ->whereOr("code = '$code' and exam_datetime='$exam_datetime'"); }) ->distinct(true) ->where('annex_class_code',4) ->where('status',1) ->field('name') ->select(); return $info; } public function del_exam($id) { $info = $this->where('id',$id)->delete(); return $info; } public function insertDcmDel($data) { $info = DcmdelModel::insert($data); return $info; } public function getSyncAi($where) { return DcmreportModel::where($where)->where('type',6)->column('exam_id'); } public function getAiNode($where) { $examId = ExamModel::where($where)->value('id'); return AireportModel::where('exam_id',$examId)->value('detections'); } }