DoctorServer.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <?php
  2. namespace app\admin\server\medical;
  3. use app\admin\model\MedicalCareDoctor;
  4. use app\admin\model\MedicalCareDoctorAppointment;
  5. use app\admin\model\Package;
  6. use app\admin\model\SystemAdmin;
  7. use app\admin\model\SystemMenu;
  8. use app\admin\model\SystemRole;
  9. use http\Exception;
  10. class DoctorServer
  11. {
  12. /**
  13. * Notes:获取医生列表
  14. * @param string $keywords
  15. * @param int $page
  16. * @param int $limit
  17. * @return array
  18. * User: QJF
  19. * Date: 2022/9/17
  20. */
  21. public static function getDoctorList( $page, int $limit, $keywords)
  22. {
  23. [$list, $count] = MedicalCareDoctor::getDoctorList($page, $limit, $keywords);
  24. if(!empty($list))
  25. {
  26. foreach ($list as $k => $item)
  27. {
  28. $list[$k]['doctor_create_time'] = date("Y-m-d H:i:s", $item['doctor_create_time']);
  29. }
  30. }
  31. return compact('list', 'page', 'limit', 'count');
  32. }
  33. /**
  34. * Notes:添加医生
  35. * @param array $param
  36. * @param int $admin_id
  37. * @return int
  38. * @throws \Exception
  39. * User: yym
  40. * Date: 2022/9/26
  41. */
  42. public static function insertDoctor(array $param, int $admin_id)
  43. {
  44. MedicalCareDoctor::affairBegin();
  45. try {
  46. //检测同一医生是否存在
  47. if(MedicalCareDoctor::checkDoctorName($param['doctor_name'], $param['doctor_mobile']))
  48. {
  49. throw new \Exception($param['doctor_name'] . '医生已存在');
  50. }
  51. $param['doctor_create_time'] = time();
  52. $result = MedicalCareDoctor::insertGetId($param);
  53. if (!empty($result)){
  54. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '添加医生: ' . $param['doctor_name'] . $result;
  55. plog('medical-doctor-create', '医疗-医生-创建医生', $msg);
  56. MedicalCareDoctor::affairCommit();
  57. return $result;
  58. }
  59. throw new \Exception('操作失败!');
  60. }catch (\Exception $exception){
  61. MedicalCareDoctor::affairRollback();
  62. throw new \Exception($exception->getMessage(), 500);
  63. }
  64. }
  65. /**
  66. * Notes:修改角色
  67. * @param array $param
  68. * @param int $admin_id
  69. * @return int
  70. * User: QJF
  71. * Date: 2022/9/19
  72. */
  73. public static function updateDoctor(array $param, int $admin_id)
  74. {
  75. MedicalCareDoctor::affairBegin();
  76. try {
  77. $info = MedicalCareDoctor::getDoctorInfo($param['doctor_id']);
  78. if(empty($info) || $info === false)
  79. {
  80. throw new \Exception('医生信息不存在');
  81. }
  82. if(MedicalCareDoctor::checkDoctorCount($param['doctor_name'], $param['doctor_mobile'], $param['doctor_id']))
  83. {
  84. throw new \Exception($param['doctor_name'] . '医生已存在');
  85. }
  86. $where = [];
  87. $where['doctor_id'] = $param['doctor_id'];
  88. $result = MedicalCareDoctor::where($where)->update($param);
  89. if ($result !== false){
  90. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '编辑医生-编号: ' . $param['doctor_id'];
  91. plog('medical-doctor-update', '医疗-医生-编辑医生', $msg);
  92. MedicalCareDoctor::affairCommit();
  93. return true;
  94. }
  95. throw new \Exception('操作失败!');
  96. }catch (\Exception $exception){
  97. MedicalCareDoctor::affairRollback();
  98. throw new \Exception($exception->getMessage(), 500);
  99. }
  100. }
  101. /**
  102. * Notes:删除医生
  103. * @param int $doctor_id
  104. * @param int $admin_id
  105. * @return bool
  106. * @throws \Exception
  107. * User: yym
  108. * Date: 2022/9/26
  109. */
  110. public static function deleteDoctor(int $doctor_id, int $admin_id)
  111. {
  112. MedicalCareDoctor::affairBegin();
  113. try {
  114. $info = MedicalCareDoctor::getDoctorInfo($doctor_id);
  115. if(empty($info) || $info === false)
  116. {
  117. throw new \Exception('医生信息不存在');
  118. }
  119. $result = MedicalCareDoctor::updateDoctor($doctor_id, ['doctor_del' => MedicalCareDoctor::DEL_YES]);
  120. if ($result === false){
  121. throw new \Exception('删除失败');
  122. }
  123. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '删除医生-编号: ' . $doctor_id;
  124. plog('medical-doctor-delete', '医疗-医生-删除医生', $msg);
  125. MedicalCareDoctor::affairCommit();
  126. return true;
  127. }catch (\Exception $exception){
  128. MedicalCareDoctor::affairRollback();
  129. throw new \Exception($exception->getMessage(), 500);
  130. }
  131. }
  132. /**
  133. * Notes:获取医生详情
  134. * @param int $doctor_id
  135. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object
  136. * @throws \Exception
  137. * User: yym
  138. * Date: 2022/9/26
  139. */
  140. public static function getDoctorInfo(int $doctor_id)
  141. {
  142. try {
  143. $info = MedicalCareDoctor::getDoctorInfo($doctor_id);
  144. if(empty($info) || $info === false)
  145. {
  146. throw new \Exception('医生信息不存在');
  147. }
  148. $info['doctor_create_time'] = date("Y-m-d H:i:s", $info['doctor_create_time']);
  149. return $info;
  150. }catch (\Exception $exception){
  151. throw new \Exception($exception->getMessage(), 500);
  152. }
  153. }
  154. /**
  155. * Notes:医生每日工作接纳人数设置----目前按照每半小时时间段设置
  156. * @param int $doctor_id
  157. * @param int $admin_id
  158. * @param string $work_time
  159. * @param string $morning_start
  160. * @param string $morning_end
  161. * @param string $afternoon_start
  162. * @param string $afternoon_end
  163. * @param int $appointment_sum
  164. * @return bool
  165. * @throws \Exception
  166. * User: yym
  167. * Date: 2022/9/27
  168. */
  169. public static function setAppointment(int $doctor_id, int $admin_id, string $work_time, string $morning_start, string $morning_end, string $afternoon_start, string $afternoon_end, int $appointment_sum)
  170. {
  171. MedicalCareDoctorAppointment::affairBegin();
  172. try {
  173. if(!empty($morning_start) && !empty($morning_end))
  174. {
  175. if(strtotime(date("Y-m-d", time()) . $morning_start) > strtotime(date("Y-m-d", time()) . $morning_end))
  176. {
  177. throw new \Exception('上午开始时间不能大于上午结束时间');
  178. }
  179. }
  180. if(!empty($afternoon_start) && !empty($afternoon_end))
  181. {
  182. if(strtotime(date("Y-m-d", time()) . $afternoon_start) > strtotime(date("Y-m-d", time()) . $afternoon_end))
  183. {
  184. throw new \Exception('下午开始时间不能大于下午结束时间');
  185. }
  186. }
  187. if(!empty($morning_end) && !empty($afternoon_start))
  188. {
  189. if(strtotime(date("Y-m-d", time()) . $morning_end) > strtotime(date("Y-m-d", time()) . $afternoon_start))
  190. {
  191. throw new \Exception('上午结束时间不能大于下午开始时间');
  192. }
  193. }
  194. if(!in_array($work_time, MedicalCareDoctorAppointment::WORK_TIME_ARR))
  195. {
  196. throw new \Exception('设置日期错误');
  197. }
  198. //上午时间处理
  199. $morning_time_data = array();
  200. if(!empty($morning_start) && !empty($morning_end))
  201. {
  202. $morning_time_data = timeDifference($morning_start, $morning_end);
  203. if(empty($morning_time_data))
  204. {
  205. throw new \Exception('上午设置时间存在问题');
  206. }
  207. foreach ($morning_time_data as $k => $row)
  208. {
  209. $morning_time_data[$k] = $appointment_sum;
  210. }
  211. }
  212. //下午时间处理
  213. $afternoon_time_data = array();
  214. if(!empty($afternoon_start) && !empty($afternoon_end))
  215. {
  216. $afternoon_time_data = timeDifference($afternoon_start, $afternoon_end);
  217. if(empty($afternoon_time_data))
  218. {
  219. throw new \Exception('下午设置时间存在问题');
  220. }
  221. foreach ($afternoon_time_data as $k => $row)
  222. {
  223. $afternoon_time_data[$k] = $appointment_sum;
  224. }
  225. }
  226. $content = array(
  227. 'morning_time_data' => $morning_time_data,
  228. 'afternoon_time_data' => $afternoon_time_data
  229. );
  230. $log_msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time());
  231. //检测医生是否已经设置
  232. if(MedicalCareDoctorAppointment::getDoctorAppointment($doctor_id))
  233. {
  234. $log_type = 'doctor-appointment-update';
  235. $log_name = '医生-工作设置-修改';
  236. $log_msg .= '修改医生:' . $doctor_id . '工作信息周' . $work_time;
  237. $update = array(
  238. MedicalCareDoctorAppointment::WORK_TIME[$work_time] => json_encode($content),
  239. 'appointment_update_time' => time()
  240. );
  241. $result = MedicalCareDoctorAppointment::updateData($doctor_id, $update);
  242. }else{
  243. $log_type = 'doctor-appointment-insert';
  244. $log_name = '医生-工作设置-新增';
  245. $log_msg .= '新增医生:' . $doctor_id . '工作信息周' . $work_time;
  246. $insert = array(
  247. 'appointment_doctor_id' => $doctor_id,
  248. MedicalCareDoctorAppointment::WORK_TIME[$work_time] => json_encode($content),
  249. 'appointment_create_time' => time()
  250. );
  251. $result = MedicalCareDoctorAppointment::insertData($insert);
  252. }
  253. if($result !== false)
  254. {
  255. plog($log_type, $log_name, $log_msg);
  256. MedicalCareDoctorAppointment::affairCommit();
  257. return true;
  258. }
  259. throw new \Exception('操作失败');
  260. }catch (\Exception $exception){
  261. MedicalCareDoctorAppointment::affairRollback();
  262. throw new \Exception($exception->getMessage(), $exception->getCode());
  263. }
  264. }
  265. /**
  266. * Notes:获取设置详情
  267. * @param int $doctor_id
  268. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  269. * User: yym
  270. * Date: 2022/10/13
  271. */
  272. public static function getAppointment(int $doctor_id)
  273. {
  274. $info = MedicalCareDoctorAppointment::getDoctorAppointment($doctor_id);
  275. if(!empty($info))
  276. {
  277. $info = $info->toArray();
  278. $info['appointment_monday'] = appointment_data($info, 'appointment_monday');
  279. $info['appointment_tuesday'] = appointment_data($info, 'appointment_tuesday');
  280. $info['appointment_wednesday'] = appointment_data($info, 'appointment_wednesday');
  281. $info['appointment_thursday'] = appointment_data($info, 'appointment_thursday');
  282. $info['appointment_friday'] = appointment_data($info, 'appointment_friday');
  283. $info['appointment_saturday'] = appointment_data($info, 'appointment_saturday');
  284. $info['appointment_sunday'] = appointment_data($info, 'appointment_sunday');
  285. }
  286. return $info;
  287. }
  288. }