123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459 |
- <?php
- namespace app\api\model\exam;
- use app\api\model\aireport\AireportModel;
- use app\api\model\annex\AnnexModel;
- use app\api\model\dcmdel\DcmdelModel;
- use app\api\model\dcmreport\DcmreportModel;
- use app\api\model\department\DepartmentModel;
- use app\api\model\doctorclass\DoctorClassModel;
- use app\api\model\application\ApplicationModel;
- use app\api\model\inspect\InspectModel;
- use app\api\model\institution\InstitutionModel;
- use app\api\model\register\RegisterModel;
- use app\api\model\remote\RemoteModel;
- use app\api\model\report\ReportModel;
- use app\api\model\studies\StudiesModel;
- use app\api\model\ZskkDefaultModel;
- use app\api\response\ServerResponse;
- use think\Exception;
- use think\facade\Log;
- use app\api\model\patient\PatientModel;
- class ExamModel extends ZskkDefaultModel {
- protected $table= 'exams';
- protected $logName = "ExamModel";
- protected $model = null;
- public function registerList($institutionId, $fuzzyWhere, $moreWhere,$class_where, $params,$whereStatus)
- {
- try{
- $nameWhere = [];
- if(isset($moreWhere['name']) && !empty($moreWhere['name'])){
- $nameWhere[] = ['e.name','like','%'.$moreWhere['name'].'%'];
- unset($moreWhere['name']);
- }
- $timeWhere = [];
- if(isset($moreWhere[0]) && !empty($moreWhere[0])){
- $timeWhere[] = $moreWhere[0];
- unset($moreWhere[0]);
- }
- $field = [
- 'e.name', 'e.sex', 'e.age','e.institution_id','e.study_id','e.id AS exam_id',
- 'e.id AS exam_id', 'e.patient_num', 'e.exam_class', 'e.exam_datetime', 'e.exam_status', 'e.accession_num', 'e.exam_project','e.accession_num',
- 're.clin_doctors_name','re.register_name'
- ];
- $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();
- $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');
- }
- }
|