Insdoctors.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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. $info['doctor_role'] = implode(',', $_GET['doctor_role']);
  118. $info['password'] = md5($_GET['password']);
  119. $info["institution_id"] = $insId;
  120. $info['exam_class'] = implode(',',$info['examcla']);
  121. unset($info['examcla']);
  122. if (empty($_GET['id'])) {
  123. unset($_GET['id']);
  124. $id = UUIDs::uuid16();
  125. $info['id'] = $id;
  126. $a = DB::table('doctors')->insert($info);
  127. SysLogs::log("doctors", "C", json_encode($info));
  128. $this->saveDoctorCla($id,$_GET['doctorcla']);
  129. return 'insert_ok;' . $id;
  130. } else {
  131. $a = DB::table('doctors')->where('id', $_GET['id'])->where("institution_id", $insId)->update($info);
  132. SysLogs::log("doctors", "U", $_GET['id'] . " --> " . json_encode($info));
  133. $this->saveDoctorCla($_GET['id'],$_GET['doctorcla']);
  134. return 'success';
  135. }
  136. }
  137. protected function saveDoctorCla($doctor_id, $doctorcla) {
  138. // doctorcla
  139. Db::table("doctor_class")->where("doctor_id", $doctor_id)->delete();
  140. if (isset($doctorcla) && count($doctorcla) > 0) {
  141. $newrow = array();
  142. $newrow["id"] = UUIDs::uuid16();
  143. $newrow["doctor_id"] = $doctor_id;
  144. $doctorclaStr = json_encode($doctorcla);
  145. $doctorclaStr = str_replace('"', '', $doctorclaStr);
  146. $doctorclaStr = str_replace('[', '', $doctorclaStr);
  147. $doctorclaStr = str_replace(']', '', $doctorclaStr);
  148. $doctorclaStr = str_replace(" ", "", $doctorclaStr);
  149. $newrow["doctor_class"] = $doctorclaStr;
  150. $newrow["status"] = "1";
  151. Db::table("doctor_class")->insert($newrow);
  152. SysLogs::log("doctors", "C", $doctor_id . " doctorclass --> " . $doctorclaStr);
  153. }
  154. }
  155. /**
  156. * 软删除记录
  157. */
  158. public function delete() {
  159. // 医院的管理员,只能处理本机构的记录
  160. $manager = $admin = Session::get('session_manager');
  161. $insId = $manager["institution_id"];
  162. if (empty($insId)) {
  163. echo "fail";
  164. return;
  165. }
  166. if (isset($_GET["ids"])) {
  167. $ids = $_GET["ids"];
  168. if (!empty($ids)) {
  169. $idArr = explode(",", $ids);
  170. if (count($idArr) > 0) {
  171. Db::table("doctors")->where("id", "in", $idArr)->where("institution_id", $insId)->update(['status' => 1]);
  172. SysLogs::log("doctors", "U", $ids . " status 修改为 1 ");
  173. }
  174. echo "delete_ok";
  175. return;
  176. }
  177. }
  178. echo "fail";
  179. }
  180. /**
  181. * 显示权限编辑窗口
  182. * @return type
  183. */
  184. public function permissions() {
  185. // 医院的管理员,只能处理本机构的记录
  186. $manager = $admin = Session::get('session_manager');
  187. $insId = $manager["institution_id"];
  188. $id = is_string($_GET["id"]) ? $_GET["id"] : null;
  189. if (empty($insId) || empty($id)) {
  190. // 没有传入管理员ID和医生ID,不能编辑
  191. echo "no login or no permissions";
  192. return;
  193. }
  194. if ($id != null) {
  195. // 得到医生信息
  196. $doctor = Db::table("doctors")->where("id", $id)->find();
  197. if (empty($doctor)) {
  198. echo "no doctor !";
  199. return;
  200. }
  201. $this->assign("doctor", $doctor);
  202. $this->assign("id", $id);
  203. }
  204. // 查找已有权限(菜单)
  205. // 只查询本机构的
  206. $permitsMenus = Db::table("dr_cla_permission")->where("doctor_id", $id)->where("type", "1")->select();
  207. $permitMenuIdArr = array();
  208. if (count($permitsMenus) > 0) {
  209. foreach ($permitsMenus as $key => $val) {
  210. array_push($permitMenuIdArr, $val["pass"]);
  211. }
  212. $this->assign("permitMenuIdArr", json_encode($permitMenuIdArr));
  213. }
  214. // 查找已有权限(写报告)
  215. $permitsReport = Db::table("dr_cla_permission")->where("doctor_id", $id)->where("type", "2")->find();
  216. if (!empty($permitsReport)) {
  217. $this->assign("permitReport", $permitsReport["pass"]);
  218. } else {
  219. $this->assign("permitReport", "0");
  220. }
  221. return $this->fetch("permissions");
  222. }
  223. /**
  224. * 保存菜单权限
  225. */
  226. public function saveMenuPermit() {
  227. $request = Request::instance();
  228. $params = $request->param();
  229. // 医院的管理员,只能处理本机构的记录
  230. $manager = $admin = Session::get('session_manager');
  231. $insId = $manager["institution_id"];
  232. $doctorId = isset($params["id"]) ? $params["id"] : null;
  233. $menuIds = isset($params["ids"]) ? $params["ids"] : null;
  234. if (empty($doctorId) || empty($menuIds) || empty($insId)) {
  235. // 如果医生ID,菜单ID,所在机构ID,某一个为空,直接返回失败
  236. echo "fail";
  237. return;
  238. }
  239. // 查询该医生信息
  240. $doctor = Db::table("doctors")->where("institution_id", $insId)->where("id", $doctorId);
  241. if (empty($doctor)) {
  242. // 该机构下,没有找到该医生
  243. echo "fail";
  244. return;
  245. }
  246. $menuIdArr = explode(",", $menuIds);
  247. $menus = Db::table("menu")->whereIn("id", $menuIdArr)->select();
  248. if (count($menus) < 1) {
  249. // 没有找到菜单
  250. echo "fail";
  251. return;
  252. } else {
  253. // 给用户赋值
  254. // 查看是否已经有了权限
  255. $menuIdArr = array();
  256. foreach ($menus as $key => $val) {
  257. array_push($menuIdArr, $val["id"]);
  258. }
  259. // 将已有权限全部清空
  260. Db::table("dr_cla_permission")->where("doctor_id", $doctorId)->where("type", "1")->delete();
  261. SysLogs::log("dr_cla_permission", "D", "where (doctor_id = " . $doctorId . "type = 1) delete ");
  262. // 如果没有,添加
  263. foreach ($menuIdArr as $key => $val) {
  264. $newRow = array();
  265. $newRow["id"] = UUIDs::uuid16();
  266. $newRow["type"] = "1";
  267. $newRow["pass"] = $val;
  268. $newRow["doctor_id"] = $doctorId;
  269. Db::table("dr_cla_permission")->insert($newRow);
  270. SysLogs::log("dr_cla_permission", "C", json_encode($newRow));
  271. }
  272. }
  273. echo "ok";
  274. }
  275. /**
  276. * 保存报告权限
  277. */
  278. public function saveReportPermit() {
  279. $request = Request::instance();
  280. $params = $request->param();
  281. // 医院的管理员,只能处理本机构的记录
  282. $manager = $admin = Session::get('session_manager');
  283. if (empty($manager) || empty($manager["institution_id"])) {
  284. // 登录超时,或者者不是机构管理员
  285. echo "fail";
  286. return;
  287. }
  288. $insId = $manager["institution_id"];
  289. $doctorId = isset($params["id"]) ? $params["id"] : null;
  290. $permitReport = isset($params["report"]) ? $params["report"] : null;
  291. if ($doctorId == null || $permitReport == null || $insId == null) {
  292. echo "fail";
  293. return;
  294. }
  295. // 查询该医生信息
  296. $doctor = Db::table("doctors")->where("institution_id", $insId)->where("id", $doctorId);
  297. if (empty($doctor)) {
  298. // 该机构下,没有找到该医生
  299. echo "fail";
  300. return;
  301. }
  302. $permitData = Db::table("dr_cla_permission")->where("doctor_id", $doctorId)->where("type", "2")->find();
  303. if (!empty($permitData)) {
  304. // 如果已经有报告权限的配置,
  305. // 只更新就好
  306. $permitData["pass"] = $permitReport;
  307. Db::table("dr_cla_permission")->update($permitData);
  308. SysLogs::log("dr_cla_permission", "U", json_encode($permitData));
  309. } else {
  310. // 新建权限记录
  311. $newRow = array();
  312. $newRow["id"] = UUIDs::uuid16();
  313. $newRow["doctor_id"] = $doctorId;
  314. $newRow["type"] = "2";
  315. $newRow["pass"] = $permitReport;
  316. Db::table("dr_cla_permission")->insert($newRow);
  317. SysLogs::log("dr_cla_permission", "C", json_encode($newRow));
  318. }
  319. echo "ok";
  320. }
  321. /**
  322. * 查询全部菜单
  323. */
  324. public function menudata() {
  325. $rootMenuData = array();
  326. // 准备根节点
  327. $rootMenuData["id"] = "root";
  328. $rootMenuData["pId"] = "0";
  329. $rootMenuData["name"] = "菜单(根节点)";
  330. $rootMenuData["url"] = "";
  331. $rootMenuData["open"] = "true";
  332. // 查询全部数据
  333. $menuData = $info = DB::table('menu')->select();
  334. $jsonarray = array();
  335. if ($menuData != null) {
  336. foreach ($menuData as $k => $val) {
  337. $parent_id = $val["parent_id"];
  338. unset($val["parent_id"]);
  339. // 处理parent_id为pId,为前端菜单上下级关系展示处理
  340. $val['pId'] = $parent_id;
  341. $val['open'] = "true";
  342. array_push($jsonarray, $val);
  343. }
  344. }
  345. // 将根节点添加到树
  346. array_unshift($jsonarray, $rootMenuData);
  347. // 返回JSON数据
  348. echo json_encode($jsonarray);
  349. }
  350. // 医院的统计
  351. public function stats() {
  352. $admin = Session::get('session_manager');
  353. // 得到所在机构ID
  354. $insId = $admin["institution_id"];
  355. if (strpos($insId, ",") !== false) {
  356. // 有多个机构时,只取第一个
  357. $insId = substr($insId, 0, trpos($insId, ","));
  358. }
  359. $dateStr = date("Ym");
  360. $whereArr = array();
  361. $whereArr["role_id"] = $insId;
  362. // 取最近5个月的数据
  363. $whereArr["month"] = array(">=", date("Ym", strtotime("201808 - 180 day")));
  364. $stats = Db::table("operating")->where($whereArr)->order("month", "1")->select();
  365. if (count($stats) > 0) {
  366. $this->assign("stats", json_encode($stats));
  367. } else {
  368. $this->assign("stats", json_encode(array()));
  369. }
  370. return $this->fetch("stats");
  371. }
  372. /**
  373. * 医院科室管理
  374. * @return type
  375. */
  376. public function deptview() {
  377. $admin = Session::get('session_manager');
  378. // 得到所在机构ID
  379. $insId = $admin["institution_id"];
  380. $this->assign("insId", $insId);
  381. return $this->fetch('/institution/dept');
  382. }
  383. }