| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- <?php
- namespace app\api\servies\register;
- use app\api\response\ZskkErrorResponse;
- use app\api\servies\ZskkDefaultService;
- use app\api\utils\UUIDUtils;
- use app\api\validate\register\RegisterValidate;
- use app\api\dao\register\RegisterDao;
- use app\api\servies\common\CommonService;
- use app\common\library\PublicPhone;
- use think\facade\Log;
- use think\Db;
- /**
- * 后台控制器基类
- * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
- */
- class RegisterService extends ZskkDefaultService {
- protected $logName = "RegisterService";
- private $registerDao = null;
- private $commonService = null;
- // protected function zskkInit(TestDao $testDao) {
- // $this->testDao;
- // }
- public function __construct(RegisterDao $registerDao) {
- parent::__construct();
- $this->registerDao = $registerDao;
- }
- public function registerList($institutionId, $fuzzyWhere, $moreWhere,$class_where,$params)
- {
- switch ($params['status']){
- case '1':
- $whereStatus = [];
- break;
- case '2':
- $whereStatus = 'e.exam_status < 3';
- break;
- case '3':
- $whereStatus = 'e.exam_status > 2';
- break;
- default:
- $whereStatus = [];
- break;
- }
- $info = $this->registerDao->getRegisterList($institutionId,$fuzzyWhere,$moreWhere,$class_where,$params,$whereStatus);
- return $info;
- }
- public function getInstitution($token)
- {
- $institution = $this->registerDao->getInstitution($token);
- return $institution;
- }
- public function getFuzzyWhere($params)
- {
- // 获取模糊 where 条件
- $fuzzyField = ['name','patient_num','accession_num'];
- $fuzzyWhere = $this->getListFuzzyWhere($params,$fuzzyField);
- return $fuzzyWhere;
- }
- public function getSpecificWhere($params)
- {
- // 获取具体筛选 where 条件
- $moreField = ['exam_datetime','name','accession_num','patient_num','exam_class','exam_project','exam_status'];
- $moreWhere = $this->getListSpecificWhere($params, $moreField);
- return $moreWhere;
- }
- public function getClassWhere($token)
- {
- $user = $this->registerDao->getUser($token);
- $class = $user['exam_class'];
- $where = [];
- if($class == '*')
- {
- return $where;
- }else{
- $where[] = ['exam_class','in',explode(',',$class)];
- return $where;
- }
- }
- public function saveRegister($params,$token, $examId = null)
- {
- try{
- $user = $this->registerDao->getUser($token);
- // 添加 patient_infos 表数据
- $patient_data = $this->makePatientData($params, $user);
- if(!is_null($examId)){
- // 修改操作
- unset($patient_data['id']);
- $pat_id = $this->registerDao->getPatientId($examId);
- $patient = $this->registerDao->updatePatient($patient_data,$pat_id);
- } else {
- // 添加操作
- $pat_id = $patient_data['id'];
- $patient = $this->registerDao->insertParent($patient_data);
- }
- // 添加 exam 表数据
- $exam_data = $this->makeExamData($params,$user);
- $exam_data['patient_id'] = $pat_id;
- if(!is_null($examId)){
- // 修改操作
- unset($exam_data['id']);
- unset($exam_data['exam_status']);
- $exam_res = $this->registerDao->updateExam($exam_data,$examId);
- $exam_data['id'] = $examId;
- } else {
- $exam_res = $this->registerDao->insertExam($exam_data);
- }
- $register_data = $this->makeRegister($params,$user);
- $register_data['exam_id'] = $exam_data['id'];
- $registerId = $this->registerDao->getRegisterId($exam_data['id']);
- if(!is_null($registerId)){
- // xiugai
- $this->registerDao->updateRegister($register_data,$examId);
- }else{
- // xinzeng
- $register_data['id'] = UUIDUtils::uuid();
- $this->registerDao->insertRegister($register_data);
- }
- PublicPhone::savePublicSearch($params['phone'] ?? '',$examId);
- // 成功
- // Db::commit();
- return true;
- } catch (Exception $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- public function makePatientData($params, $user)
- {
- try{
- $sex_choose = $params['sex'] ?? '';
- $sex = $this->getSex($sex_choose);
- $data = [
- 'id' => UUIDUtils::uuid(),
- 'sex' => $sex,
- 'name' => $params['name'] ?? '',
- 'card_num' => $params['card_num'] ?? '',
- 'phone' => $params['phone'] ?? '',
- 'ctime' => date('Y-m-d H:i:s'),
- 'birthday' => $params['birthday'] ?? '',
- 'age' => $params['age'] ?? '',
- 'card_type' => $params['card_type'] ?? '',
- 'nationality' => $params['nationality'] ?? '',
- 'nation' => $params['nation'] ?? '',
- 'marry' => $params['marry'] ?? '',
- 'professional' => $params['professional'] ?? '',
- 'address' => $params['address'] ?? '',
- 'status' => 1,
- 'anamnesis' => $params['anamnesis'] ?? '',
- 'family_ill' => $params['family_ill'] ?? '',
- 'createdAt' => date('Y-m-d H:i:s'),
- 'institution_id' => $user['institution_id'],
- 'temp_patient_id' => $params['patient_num']
- ];
- return $data;
- }catch (Exception $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- public function makeExamData($params, $user)
- {
- try{
- // $exam_project = '';
- // if(!empty($params['exam_project'])){
- // $exam_project = implode(',',$params['exam_project']);
- // }
- $sex_choose = $params['sex'] ?? '';
- $sex = $this->getSex($sex_choose);
- $bodyText = '';
- if(!empty($params['body_part_text'] ?? ''))
- {
- $params['body_part_text'] = trim($params['body_part_text'],',');
- $body = explode(',',$params['body_part_text']);
- $body = array_unique($body);
- $bodyText = implode(',',$body);
- }
- $data = [
- 'id' => UUIDUtils::uuid(),
- 'institution_id' => $user['institution_id'],
- 'name' => $params['name'] ?? '',
- 'phone' => $params['phone'] ?? '',
- 'card_num' => $params['card_num'] ?? '',
- 'patient_num' => $params['patient_num'] ?? '',
- // 'accession_num' => $params['accession_num'] ?? '', // 暂无
- 'exam_project' => $params['exam_project'],
- 'exam_datetime' => $params['exam_datetime'] ?? '',
- 'exam_status' => 1,
- 'exam_sub_class' => $params['exam_sub_class'] ?? '',
- 'body_part' =>$params['body_part'] ?? '',
- 'device_name' => $params['device_name'] ?? '',
- 'sex' => $sex,
- 'age' =>$params['age'] ?? '',
- 'birthday' => $params['birthday'] ?? '',
- 'hopitalized_no' => $params['hopitalized_no'] ?? '',
- 'bed_no' => $params['bed_no'] ?? '',
- 'patient_area' => $params['patient_area'] ?? '',
- 'application_department' => $params['application_department'] ?? '',
- 'application_doctor' => $params['application_doctor'] ?? '',
- 'out_patient' => $params['out_patient'] ?? '',
- 'clin_symp' => $params['clin_symp'] ?? '',
- 'clin_diag' => $params['clin_diag'] ?? '',
- 'his_patient_id' => $params['his_patient_id'] ?? '',
- 'body_part_text' =>$bodyText
- ];
- if($params['device_id'] ?? ''){
- $data['exam_class'] = $this->getExamClass($params['device_id']);
- }
- return $data;
- }catch (Exception $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- public function makeRegister($params,$user)
- {
- $anamnesis = '';
- $family_ill = '';
- if(!empty($params['anamnesis'])){
- $anamnesis = implode(',',$params['anamnesis']);
- }
- if(!empty($params['family_ill'])){
- $family_ill = implode(',',$params['family_ill']);
- }
- $data = [
- 'exam_sub_class' => $params['exam_sub_class'] ?? '',
- 'body_part' =>$params['body_part'] ?? '',
- 'device_name' => $params['device_name'] ?? null,
- 'register_id' => $user['id'],
- 'register_name' => $user['realname'],
- 'register_datetime' => date('Y-m-d H:i:s'),
- 'illness_desc' => $params['illness_desc'] ?? '',
- 'phys_sign' => $params['phys_sign'] ?? '',
- 'clin_symp' => $params['clin_symp'] ?? '',
- 'anamnesis' => $anamnesis,
- 'family_ill' => $family_ill,
- 'clin_diag' => $params['clin_diag'] ?? '',
- 'application_department' => $params['application_department'] ?? '',
- 'ext' => $params['remark'] ?? ''
- ];
- return $data;
- }
- public function getExamClass($device_id)
- {
- try{
- $name = $this->registerDao->getExamClass($device_id);
- return $name;
- } catch (Exception $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- public function getRegisterInfo($params,$token)
- {
- $data = $this->registerDao->RegisterInfo($params,$token);
- $info = json_decode(json_encode($data),true);
- foreach ($info as $k=>$v){
- if($k == 'anamnesis'){
- if(!empty($v)){
- $info[$k] = explode(',',$v);
- }
- }
- if($k == 'family_ill'){
- if(!empty($v)){
- $info[$k] = explode(',',$v);
- }
- }
- // if($k == 'exam_project'){
- // if(!empty($v)){
- // $info[$k] = explode(',',$v);
- // }
- // }
- }
- return $info;
- }
- public function delRegister($params,$token)
- {
- $info = $this->registerDao->delRegister($params,$token);
- return $info;
- }
- }
|