RegisterService.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <?php
  2. namespace app\api\servies\register;
  3. use app\api\response\ZskkErrorResponse;
  4. use app\api\servies\ZskkDefaultService;
  5. use app\api\utils\UUIDUtils;
  6. use app\api\validate\register\RegisterValidate;
  7. use app\api\dao\register\RegisterDao;
  8. use app\api\servies\common\CommonService;
  9. use app\common\library\PublicPhone;
  10. use think\facade\Log;
  11. use think\Db;
  12. /**
  13. * 后台控制器基类
  14. * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
  15. */
  16. class RegisterService extends ZskkDefaultService {
  17. protected $logName = "RegisterService";
  18. private $registerDao = null;
  19. private $commonService = null;
  20. // protected function zskkInit(TestDao $testDao) {
  21. // $this->testDao;
  22. // }
  23. public function __construct(RegisterDao $registerDao) {
  24. parent::__construct();
  25. $this->registerDao = $registerDao;
  26. }
  27. public function registerList($institutionId, $fuzzyWhere, $moreWhere,$class_where,$params)
  28. {
  29. switch ($params['status']){
  30. case '1':
  31. $whereStatus = [];
  32. break;
  33. case '2':
  34. $whereStatus = 'e.exam_status < 3';
  35. break;
  36. case '3':
  37. $whereStatus = 'e.exam_status > 2';
  38. break;
  39. default:
  40. $whereStatus = [];
  41. break;
  42. }
  43. $info = $this->registerDao->getRegisterList($institutionId,$fuzzyWhere,$moreWhere,$class_where,$params,$whereStatus);
  44. return $info;
  45. }
  46. public function getInstitution($token)
  47. {
  48. $institution = $this->registerDao->getInstitution($token);
  49. return $institution;
  50. }
  51. public function getFuzzyWhere($params)
  52. {
  53. // 获取模糊 where 条件
  54. $fuzzyField = ['name','patient_num','accession_num'];
  55. $fuzzyWhere = $this->getListFuzzyWhere($params,$fuzzyField);
  56. return $fuzzyWhere;
  57. }
  58. public function getSpecificWhere($params)
  59. {
  60. // 获取具体筛选 where 条件
  61. $moreField = ['exam_datetime','name','accession_num','patient_num','exam_class','exam_project','exam_status'];
  62. $moreWhere = $this->getListSpecificWhere($params, $moreField);
  63. return $moreWhere;
  64. }
  65. public function getClassWhere($token)
  66. {
  67. $user = $this->registerDao->getUser($token);
  68. $class = $user['exam_class'];
  69. $where = [];
  70. if($class == '*')
  71. {
  72. return $where;
  73. }else{
  74. $where[] = ['exam_class','in',explode(',',$class)];
  75. return $where;
  76. }
  77. }
  78. public function saveRegister($params,$token, $examId = null)
  79. {
  80. try{
  81. $user = $this->registerDao->getUser($token);
  82. // 添加 patient_infos 表数据
  83. $patient_data = $this->makePatientData($params, $user);
  84. if(!is_null($examId)){
  85. // 修改操作
  86. unset($patient_data['id']);
  87. $pat_id = $this->registerDao->getPatientId($examId);
  88. $patient = $this->registerDao->updatePatient($patient_data,$pat_id);
  89. } else {
  90. // 添加操作
  91. $pat_id = $patient_data['id'];
  92. $patient = $this->registerDao->insertParent($patient_data);
  93. }
  94. // 添加 exam 表数据
  95. $exam_data = $this->makeExamData($params,$user);
  96. $exam_data['patient_id'] = $pat_id;
  97. if(!is_null($examId)){
  98. // 修改操作
  99. unset($exam_data['id']);
  100. unset($exam_data['exam_status']);
  101. $exam_res = $this->registerDao->updateExam($exam_data,$examId);
  102. $exam_data['id'] = $examId;
  103. } else {
  104. $exam_res = $this->registerDao->insertExam($exam_data);
  105. }
  106. $register_data = $this->makeRegister($params,$user);
  107. $register_data['exam_id'] = $exam_data['id'];
  108. $registerId = $this->registerDao->getRegisterId($exam_data['id']);
  109. if(!is_null($registerId)){
  110. // xiugai
  111. $this->registerDao->updateRegister($register_data,$examId);
  112. }else{
  113. // xinzeng
  114. $register_data['id'] = UUIDUtils::uuid();
  115. $this->registerDao->insertRegister($register_data);
  116. }
  117. PublicPhone::savePublicSearch($params['phone'] ?? '',$examId);
  118. // 成功
  119. // Db::commit();
  120. return true;
  121. } catch (Exception $exception){
  122. $this->throwError($exception->getMessage(),0001);
  123. }
  124. }
  125. public function makePatientData($params, $user)
  126. {
  127. try{
  128. $sex_choose = $params['sex'] ?? '';
  129. $sex = $this->getSex($sex_choose);
  130. $data = [
  131. 'id' => UUIDUtils::uuid(),
  132. 'sex' => $sex,
  133. 'name' => $params['name'] ?? '',
  134. 'card_num' => $params['card_num'] ?? '',
  135. 'phone' => $params['phone'] ?? '',
  136. 'ctime' => date('Y-m-d H:i:s'),
  137. 'birthday' => $params['birthday'] ?? '',
  138. 'age' => $params['age'] ?? '',
  139. 'card_type' => $params['card_type'] ?? '',
  140. 'nationality' => $params['nationality'] ?? '',
  141. 'nation' => $params['nation'] ?? '',
  142. 'marry' => $params['marry'] ?? '',
  143. 'professional' => $params['professional'] ?? '',
  144. 'address' => $params['address'] ?? '',
  145. 'status' => 1,
  146. 'anamnesis' => $params['anamnesis'] ?? '',
  147. 'family_ill' => $params['family_ill'] ?? '',
  148. 'createdAt' => date('Y-m-d H:i:s'),
  149. 'institution_id' => $user['institution_id'],
  150. 'temp_patient_id' => $params['patient_num']
  151. ];
  152. return $data;
  153. }catch (Exception $exception){
  154. $this->throwError($exception->getMessage(),0001);
  155. }
  156. }
  157. public function makeExamData($params, $user)
  158. {
  159. try{
  160. // $exam_project = '';
  161. // if(!empty($params['exam_project'])){
  162. // $exam_project = implode(',',$params['exam_project']);
  163. // }
  164. $sex_choose = $params['sex'] ?? '';
  165. $sex = $this->getSex($sex_choose);
  166. $bodyText = '';
  167. if(!empty($params['body_part_text'] ?? ''))
  168. {
  169. $params['body_part_text'] = trim($params['body_part_text'],',');
  170. $body = explode(',',$params['body_part_text']);
  171. $body = array_unique($body);
  172. $bodyText = implode(',',$body);
  173. }
  174. $data = [
  175. 'id' => UUIDUtils::uuid(),
  176. 'institution_id' => $user['institution_id'],
  177. 'name' => $params['name'] ?? '',
  178. 'phone' => $params['phone'] ?? '',
  179. 'card_num' => $params['card_num'] ?? '',
  180. 'patient_num' => $params['patient_num'] ?? '',
  181. // 'accession_num' => $params['accession_num'] ?? '', // 暂无
  182. 'exam_project' => $params['exam_project'],
  183. 'exam_datetime' => $params['exam_datetime'] ?? '',
  184. 'exam_status' => 1,
  185. 'exam_sub_class' => $params['exam_sub_class'] ?? '',
  186. 'body_part' =>$params['body_part'] ?? '',
  187. 'device_name' => $params['device_name'] ?? '',
  188. 'sex' => $sex,
  189. 'age' =>$params['age'] ?? '',
  190. 'birthday' => $params['birthday'] ?? '',
  191. 'hopitalized_no' => $params['hopitalized_no'] ?? '',
  192. 'bed_no' => $params['bed_no'] ?? '',
  193. 'patient_area' => $params['patient_area'] ?? '',
  194. 'application_department' => $params['application_department'] ?? '',
  195. 'application_doctor' => $params['application_doctor'] ?? '',
  196. 'out_patient' => $params['out_patient'] ?? '',
  197. 'clin_symp' => $params['clin_symp'] ?? '',
  198. 'clin_diag' => $params['clin_diag'] ?? '',
  199. 'his_patient_id' => $params['his_patient_id'] ?? '',
  200. 'body_part_text' =>$bodyText
  201. ];
  202. if($params['device_id'] ?? ''){
  203. $data['exam_class'] = $this->getExamClass($params['device_id']);
  204. }
  205. return $data;
  206. }catch (Exception $exception){
  207. $this->throwError($exception->getMessage(),0001);
  208. }
  209. }
  210. public function makeRegister($params,$user)
  211. {
  212. $anamnesis = '';
  213. $family_ill = '';
  214. if(!empty($params['anamnesis'])){
  215. $anamnesis = implode(',',$params['anamnesis']);
  216. }
  217. if(!empty($params['family_ill'])){
  218. $family_ill = implode(',',$params['family_ill']);
  219. }
  220. $data = [
  221. 'exam_sub_class' => $params['exam_sub_class'] ?? '',
  222. 'body_part' =>$params['body_part'] ?? '',
  223. 'device_name' => $params['device_name'] ?? null,
  224. 'register_id' => $user['id'],
  225. 'register_name' => $user['realname'],
  226. 'register_datetime' => date('Y-m-d H:i:s'),
  227. 'illness_desc' => $params['illness_desc'] ?? '',
  228. 'phys_sign' => $params['phys_sign'] ?? '',
  229. 'clin_symp' => $params['clin_symp'] ?? '',
  230. 'anamnesis' => $anamnesis,
  231. 'family_ill' => $family_ill,
  232. 'clin_diag' => $params['clin_diag'] ?? '',
  233. 'application_department' => $params['application_department'] ?? '',
  234. 'ext' => $params['remark'] ?? ''
  235. ];
  236. return $data;
  237. }
  238. public function getExamClass($device_id)
  239. {
  240. try{
  241. $name = $this->registerDao->getExamClass($device_id);
  242. return $name;
  243. } catch (Exception $exception){
  244. $this->throwError($exception->getMessage(),0001);
  245. }
  246. }
  247. public function getRegisterInfo($params,$token)
  248. {
  249. $data = $this->registerDao->RegisterInfo($params,$token);
  250. $info = json_decode(json_encode($data),true);
  251. foreach ($info as $k=>$v){
  252. if($k == 'anamnesis'){
  253. if(!empty($v)){
  254. $info[$k] = explode(',',$v);
  255. }
  256. }
  257. if($k == 'family_ill'){
  258. if(!empty($v)){
  259. $info[$k] = explode(',',$v);
  260. }
  261. }
  262. // if($k == 'exam_project'){
  263. // if(!empty($v)){
  264. // $info[$k] = explode(',',$v);
  265. // }
  266. // }
  267. }
  268. return $info;
  269. }
  270. public function delRegister($params,$token)
  271. {
  272. $info = $this->registerDao->delRegister($params,$token);
  273. return $info;
  274. }
  275. }