Insdoctors.php 13 KB

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