Insdoctors.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <?php
  2. namespace app\manage\controller;
  3. use think\Controller;
  4. use think\Db;
  5. use think\Session;
  6. use think\Config;
  7. use think\Cookie;
  8. use think\Request;
  9. use app\common\library\SysLogs;
  10. use app\common\library\UUIDs;
  11. class Insdoctors extends Base {
  12. public function index() {
  13. return $this->fetch();
  14. }
  15. public function datas() {
  16. // 只查本机构的
  17. // 拿到机构ID
  18. $manager = $admin = Session::get('session_manager');
  19. $insId = $manager["institution_id"];
  20. if (empty($insId)) {
  21. echo "[]";
  22. return;
  23. }
  24. $request = Request::instance()->param();
  25. $username = isset($request["username"]) ? $request["username"] : null;
  26. $status = isset($request["status"]) ? $request["status"] : null;
  27. $institution_id = $insId;
  28. $whereArr = array();
  29. if (!empty($username)) {
  30. $whereArr["username"] = array("like", $username . "%");
  31. }
  32. if ($status != null) {
  33. $whereArr["status"] = $status;
  34. }
  35. $whereArr["institution_id"] = $institution_id;
  36. $page = empty($_GET["page"]) ? 1 : $_GET["page"];
  37. $pagesize = empty($_GET["rows"]) ? 1 : $_GET["rows"];
  38. if (empty($page) || $page < 1) {
  39. $page = 1;
  40. }
  41. if (empty($pagesize) || $pagesize < 1) {
  42. $pagesize = 30;
  43. }
  44. $info = DB::table('doctors')->where($whereArr)->page($page, $pagesize)->select();
  45. foreach ($info as $k => $v) {
  46. $iname = DB::table('institution')->where('id', $v['institution_id'])->field('name')->find();
  47. $info[$k]['institution_name'] = $iname['name'];
  48. $dname = DB::table('department')->where('id', $v['department_id'])->field('department_name')->find();
  49. $info[$k]['department_name'] = $dname['department_name'];
  50. }
  51. $num = DB::table('doctors')->where($whereArr)->count();
  52. $data = array();
  53. $data['total'] = $num;
  54. $data['rows'] = $info;
  55. echo json_encode($data);
  56. }
  57. /**
  58. * 编辑窗口
  59. * @return type
  60. */
  61. public function edit() {
  62. // 医院的管理员,只能处理本机构的记录
  63. $manager = $admin = Session::get('session_manager');
  64. $insId = $manager["institution_id"];
  65. if (empty($insId)) {
  66. echo "not login ?";
  67. return;
  68. }
  69. if (isset($_GET["id"])) {
  70. $id = $_GET["id"];
  71. if ($id != null) {
  72. $doctors = Db::table("doctors")->where("id", $id)->find();
  73. if (count($doctors) > 0) {
  74. if (empty($doctors['doctor_role'])) {
  75. $doctors['doctor_role'] = array();
  76. } else {
  77. $doctors['doctor_role'] = explode(',', $doctors['doctor_role']);
  78. }
  79. $this->assign("doctors", $doctors);
  80. $exam_class = explode(',',$doctors['exam_class']);
  81. $this->assign('examcla',$exam_class);
  82. // 查询医生的分类
  83. $doctorsCla = Db::table("doctor_class")->where("doctor_id", $id)->find();
  84. if (!empty($doctorsCla)) {
  85. $doctorClaStr = $doctorsCla["doctor_class"];
  86. if (!empty($doctorClaStr)) {
  87. $dc_arr = explode(",", $doctorClaStr);
  88. $this->assign("doctorcla", $dc_arr);
  89. }
  90. }
  91. // 医生的exam报告类权限
  92. }
  93. }
  94. }
  95. //
  96. $examCla = DB::table('constant')->where('parent_id','exam_class')->select();
  97. $this->assign('examclass',$examCla);
  98. $doctorClas = Db::table("constant")->where("parent_id", "doctor_class")->order("ordernum", "1")->select();
  99. $this->assign('doctorclas', $doctorClas);
  100. $institution = DB::table('institution')->where("parent_institution", $insId)->whereOr("id", $insId)->select();
  101. $this->assign('institution', $institution);
  102. // 按机构查询科室
  103. $department = DB::table('department')->where("institution_id", $insId)->select();
  104. $this->assign('department', $department);
  105. return $this->fetch('edit');
  106. }
  107. public function save() {
  108. // 医院的管理员,只能处理本机构的记录
  109. $manager = $admin = Session::get('session_manager');
  110. $insId = $manager["institution_id"];
  111. if (empty($insId)) {
  112. echo "fail";
  113. return;
  114. }
  115. $info = $_GET;
  116. unset($info['doctorcla']);
  117. if(isset($_GET['doctor_role']) && !empty($_GET['doctor_role'])){
  118. $info['doctor_role'] = implode(',', $_GET['doctor_role']);
  119. }
  120. // $info['doctor_role'] = implode(',', $_GET['doctor_role']);
  121. $info['password'] = md5($_GET['password']);
  122. $info["institution_id"] = $insId;
  123. if(isset($info['examcla'])){
  124. $info['exam_class'] = implode(',',$info['examcla']);
  125. unset($info['examcla']);
  126. }
  127. if (empty($_GET['id'])) {
  128. unset($_GET['id']);
  129. $id = UUIDs::uuid16();
  130. $info['id'] = $id;
  131. $a = DB::table('doctors')->insert($info);
  132. SysLogs::log("doctors", "C", json_encode($info));
  133. $this->saveDoctorCla($id,$_GET['doctorcla']);
  134. return 'insert_ok;' . $id;
  135. } else {
  136. $a = DB::table('doctors')->where('id', $_GET['id'])->where("institution_id", $insId)->update($info);
  137. SysLogs::log("doctors", "U", $_GET['id'] . " --> " . json_encode($info));
  138. $this->saveDoctorCla($_GET['id'],$_GET['doctorcla']);
  139. return 'success';
  140. }
  141. }
  142. protected function saveDoctorCla($doctor_id, $doctorcla) {
  143. // doctorcla
  144. Db::table("doctor_class")->where("doctor_id", $doctor_id)->delete();
  145. if (isset($doctorcla) && count($doctorcla) > 0) {
  146. $newrow = array();
  147. $newrow["id"] = UUIDs::uuid16();
  148. $newrow["doctor_id"] = $doctor_id;
  149. $doctorclaStr = json_encode($doctorcla);
  150. $doctorclaStr = str_replace('"', '', $doctorclaStr);
  151. $doctorclaStr = str_replace('[', '', $doctorclaStr);
  152. $doctorclaStr = str_replace(']', '', $doctorclaStr);
  153. $doctorclaStr = str_replace(" ", "", $doctorclaStr);
  154. $newrow["doctor_class"] = $doctorclaStr;
  155. $newrow["status"] = "1";
  156. Db::table("doctor_class")->insert($newrow);
  157. SysLogs::log("doctors", "C", $doctor_id . " doctorclass --> " . $doctorclaStr);
  158. }
  159. }
  160. /**
  161. * 软删除记录
  162. */
  163. public function delete() {
  164. // 医院的管理员,只能处理本机构的记录
  165. $manager = $admin = Session::get('session_manager');
  166. $insId = $manager["institution_id"];
  167. if (empty($insId)) {
  168. echo "fail";
  169. return;
  170. }
  171. if (isset($_GET["ids"])) {
  172. $ids = $_GET["ids"];
  173. if (!empty($ids)) {
  174. $idArr = explode(",", $ids);
  175. if (count($idArr) > 0) {
  176. Db::table("doctors")->where("id", "in", $idArr)->where("institution_id", $insId)->update(['status' => 1]);
  177. SysLogs::log("doctors", "U", $ids . " status 修改为 1 ");
  178. }
  179. echo "delete_ok";
  180. return;
  181. }
  182. }
  183. echo "fail";
  184. }
  185. /**
  186. * 显示权限编辑窗口
  187. * @return type
  188. */
  189. public function permissions() {
  190. // 医院的管理员,只能处理本机构的记录
  191. $manager = $admin = Session::get('session_manager');
  192. $insId = $manager["institution_id"];
  193. $id = is_string($_GET["id"]) ? $_GET["id"] : null;
  194. if (empty($insId) || empty($id)) {
  195. // 没有传入管理员ID和医生ID,不能编辑
  196. echo "no login or no permissions";
  197. return;
  198. }
  199. if ($id != null) {
  200. // 得到医生信息
  201. $doctor = Db::table("doctors")->where("id", $id)->find();
  202. if (empty($doctor)) {
  203. echo "no doctor !";
  204. return;
  205. }
  206. $this->assign("doctor", $doctor);
  207. $this->assign("id", $id);
  208. }
  209. // 查找已有权限(菜单)
  210. // 只查询本机构的
  211. $permitsMenus = Db::table("dr_cla_permission")->where("doctor_id", $id)->where("type", "1")->select();
  212. $permitMenuIdArr = array();
  213. if (count($permitsMenus) > 0) {
  214. foreach ($permitsMenus as $key => $val) {
  215. array_push($permitMenuIdArr, $val["pass"]);
  216. }
  217. $this->assign("permitMenuIdArr", json_encode($permitMenuIdArr));
  218. }
  219. // 查找已有权限(写报告)
  220. $permitsReport = Db::table("dr_cla_permission")->where("doctor_id", $id)->where("type", "2")->find();
  221. if (!empty($permitsReport)) {
  222. $this->assign("permitReport", $permitsReport["pass"]);
  223. } else {
  224. $this->assign("permitReport", "0");
  225. }
  226. return $this->fetch("permissions");
  227. }
  228. /**
  229. * 保存菜单权限
  230. */
  231. public function saveMenuPermit() {
  232. $request = Request::instance();
  233. $params = $request->param();
  234. // 医院的管理员,只能处理本机构的记录
  235. $manager = $admin = Session::get('session_manager');
  236. $insId = $manager["institution_id"];
  237. $doctorId = isset($params["id"]) ? $params["id"] : null;
  238. $menuIds = isset($params["ids"]) ? $params["ids"] : null;
  239. if (empty($doctorId) || empty($menuIds) || empty($insId)) {
  240. // 如果医生ID,菜单ID,所在机构ID,某一个为空,直接返回失败
  241. echo "fail";
  242. return;
  243. }
  244. // 查询该医生信息
  245. $doctor = Db::table("doctors")->where("institution_id", $insId)->where("id", $doctorId);
  246. if (empty($doctor)) {
  247. // 该机构下,没有找到该医生
  248. echo "fail";
  249. return;
  250. }
  251. $menuIdArr = explode(",", $menuIds);
  252. $menus = Db::table("menu")->whereIn("id", $menuIdArr)->select();
  253. if (count($menus) < 1) {
  254. // 没有找到菜单
  255. echo "fail";
  256. return;
  257. } else {
  258. // 给用户赋值
  259. // 查看是否已经有了权限
  260. $menuIdArr = array();
  261. foreach ($menus as $key => $val) {
  262. array_push($menuIdArr, $val["id"]);
  263. }
  264. // 将已有权限全部清空
  265. Db::table("dr_cla_permission")->where("doctor_id", $doctorId)->where("type", "1")->delete();
  266. SysLogs::log("dr_cla_permission", "D", "where (doctor_id = " . $doctorId . "type = 1) delete ");
  267. // 如果没有,添加
  268. foreach ($menuIdArr as $key => $val) {
  269. $newRow = array();
  270. $newRow["id"] = UUIDs::uuid16();
  271. $newRow["type"] = "1";
  272. $newRow["pass"] = $val;
  273. $newRow["doctor_id"] = $doctorId;
  274. Db::table("dr_cla_permission")->insert($newRow);
  275. SysLogs::log("dr_cla_permission", "C", json_encode($newRow));
  276. }
  277. }
  278. echo "ok";
  279. }
  280. /**
  281. * 保存报告权限
  282. */
  283. public function saveReportPermit() {
  284. $request = Request::instance();
  285. $params = $request->param();
  286. // 医院的管理员,只能处理本机构的记录
  287. $manager = $admin = Session::get('session_manager');
  288. if (empty($manager) || empty($manager["institution_id"])) {
  289. // 登录超时,或者者不是机构管理员
  290. echo "fail";
  291. return;
  292. }
  293. $insId = $manager["institution_id"];
  294. $doctorId = isset($params["id"]) ? $params["id"] : null;
  295. $permitReport = isset($params["report"]) ? $params["report"] : null;
  296. if ($doctorId == null || $permitReport == null || $insId == null) {
  297. echo "fail";
  298. return;
  299. }
  300. // 查询该医生信息
  301. $doctor = Db::table("doctors")->where("institution_id", $insId)->where("id", $doctorId);
  302. if (empty($doctor)) {
  303. // 该机构下,没有找到该医生
  304. echo "fail";
  305. return;
  306. }
  307. $permitData = Db::table("dr_cla_permission")->where("doctor_id", $doctorId)->where("type", "2")->find();
  308. if (!empty($permitData)) {
  309. // 如果已经有报告权限的配置,
  310. // 只更新就好
  311. $permitData["pass"] = $permitReport;
  312. Db::table("dr_cla_permission")->update($permitData);
  313. SysLogs::log("dr_cla_permission", "U", json_encode($permitData));
  314. } else {
  315. // 新建权限记录
  316. $newRow = array();
  317. $newRow["id"] = UUIDs::uuid16();
  318. $newRow["doctor_id"] = $doctorId;
  319. $newRow["type"] = "2";
  320. $newRow["pass"] = $permitReport;
  321. Db::table("dr_cla_permission")->insert($newRow);
  322. SysLogs::log("dr_cla_permission", "C", json_encode($newRow));
  323. }
  324. echo "ok";
  325. }
  326. /**
  327. * 查询全部菜单
  328. */
  329. public function menudata() {
  330. $rootMenuData = array();
  331. // 准备根节点
  332. $rootMenuData["id"] = "root";
  333. $rootMenuData["pId"] = "0";
  334. $rootMenuData["name"] = "菜单(根节点)";
  335. $rootMenuData["url"] = "";
  336. $rootMenuData["open"] = "true";
  337. // 查询全部数据
  338. $menuData = $info = DB::table('menu')->select();
  339. $jsonarray = array();
  340. if ($menuData != null) {
  341. foreach ($menuData as $k => $val) {
  342. $parent_id = $val["parent_id"];
  343. unset($val["parent_id"]);
  344. // 处理parent_id为pId,为前端菜单上下级关系展示处理
  345. $val['pId'] = $parent_id;
  346. $val['open'] = "true";
  347. array_push($jsonarray, $val);
  348. }
  349. }
  350. // 将根节点添加到树
  351. array_unshift($jsonarray, $rootMenuData);
  352. // 返回JSON数据
  353. echo json_encode($jsonarray);
  354. }
  355. // 医院的统计
  356. public function stats() {
  357. $admin = Session::get('session_manager');
  358. // 得到所在机构ID
  359. $insId = $admin["institution_id"];
  360. if (strpos($insId, ",") !== false) {
  361. // 有多个机构时,只取第一个
  362. $insId = substr($insId, 0, trpos($insId, ","));
  363. }
  364. $dateStr = date("Ym");
  365. $whereArr = array();
  366. $whereArr["role_id"] = $insId;
  367. // 取最近5个月的数据
  368. $whereArr["month"] = array(">=", date("Ym", strtotime("201808 - 180 day")));
  369. $stats = Db::table("operating")->where($whereArr)->order("month", "1")->select();
  370. if (count($stats) > 0) {
  371. $this->assign("stats", json_encode($stats));
  372. } else {
  373. $this->assign("stats", json_encode(array()));
  374. }
  375. return $this->fetch("stats");
  376. }
  377. /**
  378. * 医院科室管理
  379. * @return type
  380. */
  381. public function deptview() {
  382. $admin = Session::get('session_manager');
  383. // 得到所在机构ID
  384. $insId = $admin["institution_id"];
  385. $this->assign("insId", $insId);
  386. return $this->fetch('/institution/dept');
  387. }
  388. }