Insdoctors.php 14 KB

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