123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419 |
- <?php
- namespace app\manage\controller;
- use think\Controller;
- use think\Db;
- use think\Session;
- use think\Config;
- use think\Cookie;
- use think\Request;
- use app\common\library\SysLogs;
- use app\common\library\UUIDs;
- class Insdoctors extends Base {
- public function index() {
- return $this->fetch();
- }
- public function datas() {
- // 只查本机构的
- // 拿到机构ID
- $manager = $admin = Session::get('session_manager');
- $insId = $manager["institution_id"];
- if (empty($insId)) {
- echo "[]";
- return;
- }
- $request = Request::instance()->param();
- $username = isset($request["username"]) ? $request["username"] : null;
- $status = isset($request["status"]) ? $request["status"] : null;
- $institution_id = $insId;
- $whereArr = array();
- if (!empty($username)) {
- $whereArr["username"] = array("like", $username . "%");
- }
- if ($status != null) {
- $whereArr["status"] = $status;
- }
- $whereArr["institution_id"] = $institution_id;
- $page = empty($_GET["page"]) ? 1 : $_GET["page"];
- $pagesize = empty($_GET["rows"]) ? 1 : $_GET["rows"];
- if (empty($page) || $page < 1) {
- $page = 1;
- }
- if (empty($pagesize) || $pagesize < 1) {
- $pagesize = 30;
- }
- $info = DB::table('doctors')->where($whereArr)->page($page, $pagesize)->select();
- foreach ($info as $k => $v) {
- $iname = DB::table('institution')->where('id', $v['institution_id'])->field('name')->find();
- $info[$k]['institution_name'] = $iname['name'];
- $dname = DB::table('department')->where('id', $v['department_id'])->field('department_name')->find();
- $info[$k]['department_name'] = $dname['department_name'];
- }
- $num = DB::table('doctors')->where($whereArr)->count();
- $data = array();
- $data['total'] = $num;
- $data['rows'] = $info;
- echo json_encode($data);
- }
- /**
- * 编辑窗口
- * @return type
- */
- public function edit() {
- // 医院的管理员,只能处理本机构的记录
- $manager = $admin = Session::get('session_manager');
- $insId = $manager["institution_id"];
- if (empty($insId)) {
- echo "not login ?";
- return;
- }
- if (isset($_GET["id"])) {
- $id = $_GET["id"];
- if ($id != null) {
- $doctors = Db::table("doctors")->where("id", $id)->find();
- if (count($doctors) > 0) {
- if (empty($doctors['doctor_role'])) {
- $doctors['doctor_role'] = array();
- } else {
- $doctors['doctor_role'] = explode(',', $doctors['doctor_role']);
- }
- $this->assign("doctors", $doctors);
- $exam_class = explode(',',$doctors['exam_class']);
- $this->assign('examcla',$exam_class);
- // 查询医生的分类
- $doctorsCla = Db::table("doctor_class")->where("doctor_id", $id)->find();
- if (!empty($doctorsCla)) {
- $doctorClaStr = $doctorsCla["doctor_class"];
- if (!empty($doctorClaStr)) {
- $dc_arr = explode(",", $doctorClaStr);
- $this->assign("doctorcla", $dc_arr);
- }
- }
- // 医生的exam报告类权限
- }
- }
- }
- //
- $examCla = DB::table('constant')->where('parent_id','exam_class')->select();
- $this->assign('examclass',$examCla);
- $doctorClas = Db::table("constant")->where("parent_id", "doctor_class")->order("ordernum", "1")->select();
- $this->assign('doctorclas', $doctorClas);
- $institution = DB::table('institution')->where("parent_institution", $insId)->whereOr("id", $insId)->select();
- $this->assign('institution', $institution);
- // 按机构查询科室
- $department = DB::table('department')->where("institution_id", $insId)->select();
- $this->assign('department', $department);
- return $this->fetch('edit');
- }
- public function save() {
- // 医院的管理员,只能处理本机构的记录
- $manager = $admin = Session::get('session_manager');
- $insId = $manager["institution_id"];
- if (empty($insId)) {
- echo "fail";
- return;
- }
- $info = $_GET;
- unset($info['doctorcla']);
- if(isset($_GET['doctor_role']) && !empty($_GET['doctor_role'])){
- $info['doctor_role'] = implode(',', $_GET['doctor_role']);
- }
- // $info['doctor_role'] = implode(',', $_GET['doctor_role']);
- $info['password'] = md5($_GET['password']);
- $info["institution_id"] = $insId;
- if(isset($info['examcla'])){
- $info['exam_class'] = implode(',',$info['examcla']);
- unset($info['examcla']);
- }
- if (empty($_GET['id'])) {
- unset($_GET['id']);
- $id = UUIDs::uuid16();
- $info['id'] = $id;
- $a = DB::table('doctors')->insert($info);
- SysLogs::log("doctors", "C", json_encode($info));
- $this->saveDoctorCla($id,$_GET['doctorcla']);
- return 'insert_ok;' . $id;
- } else {
- $a = DB::table('doctors')->where('id', $_GET['id'])->where("institution_id", $insId)->update($info);
- SysLogs::log("doctors", "U", $_GET['id'] . " --> " . json_encode($info));
- $this->saveDoctorCla($_GET['id'],$_GET['doctorcla']);
- return 'success';
- }
- }
- protected function saveDoctorCla($doctor_id, $doctorcla) {
- // doctorcla
- Db::table("doctor_class")->where("doctor_id", $doctor_id)->delete();
- if (isset($doctorcla) && count($doctorcla) > 0) {
- $newrow = array();
- $newrow["id"] = UUIDs::uuid16();
- $newrow["doctor_id"] = $doctor_id;
- $doctorclaStr = json_encode($doctorcla);
- $doctorclaStr = str_replace('"', '', $doctorclaStr);
- $doctorclaStr = str_replace('[', '', $doctorclaStr);
- $doctorclaStr = str_replace(']', '', $doctorclaStr);
- $doctorclaStr = str_replace(" ", "", $doctorclaStr);
- $newrow["doctor_class"] = $doctorclaStr;
- $newrow["status"] = "1";
- Db::table("doctor_class")->insert($newrow);
- SysLogs::log("doctors", "C", $doctor_id . " doctorclass --> " . $doctorclaStr);
- }
- }
- /**
- * 软删除记录
- */
- public function delete() {
- // 医院的管理员,只能处理本机构的记录
- $manager = $admin = Session::get('session_manager');
- $insId = $manager["institution_id"];
- if (empty($insId)) {
- echo "fail";
- return;
- }
- if (isset($_GET["ids"])) {
- $ids = $_GET["ids"];
- if (!empty($ids)) {
- $idArr = explode(",", $ids);
- if (count($idArr) > 0) {
- Db::table("doctors")->where("id", "in", $idArr)->where("institution_id", $insId)->update(['status' => 1]);
- SysLogs::log("doctors", "U", $ids . " status 修改为 1 ");
- }
- echo "delete_ok";
- return;
- }
- }
- echo "fail";
- }
- /**
- * 显示权限编辑窗口
- * @return type
- */
- public function permissions() {
- // 医院的管理员,只能处理本机构的记录
- $manager = $admin = Session::get('session_manager');
- $insId = $manager["institution_id"];
- $id = is_string($_GET["id"]) ? $_GET["id"] : null;
- if (empty($insId) || empty($id)) {
- // 没有传入管理员ID和医生ID,不能编辑
- echo "no login or no permissions";
- return;
- }
- if ($id != null) {
- // 得到医生信息
- $doctor = Db::table("doctors")->where("id", $id)->find();
- if (empty($doctor)) {
- echo "no doctor !";
- return;
- }
- $this->assign("doctor", $doctor);
- $this->assign("id", $id);
- }
- // 查找已有权限(菜单)
- // 只查询本机构的
- $permitsMenus = Db::table("dr_cla_permission")->where("doctor_id", $id)->where("type", "1")->select();
- $permitMenuIdArr = array();
- if (count($permitsMenus) > 0) {
- foreach ($permitsMenus as $key => $val) {
- array_push($permitMenuIdArr, $val["pass"]);
- }
- $this->assign("permitMenuIdArr", json_encode($permitMenuIdArr));
- }
- // 查找已有权限(写报告)
- $permitsReport = Db::table("dr_cla_permission")->where("doctor_id", $id)->where("type", "2")->find();
- if (!empty($permitsReport)) {
- $this->assign("permitReport", $permitsReport["pass"]);
- } else {
- $this->assign("permitReport", "0");
- }
- return $this->fetch("permissions");
- }
- /**
- * 保存菜单权限
- */
- public function saveMenuPermit() {
- $request = Request::instance();
- $params = $request->param();
- // 医院的管理员,只能处理本机构的记录
- $manager = $admin = Session::get('session_manager');
- $insId = $manager["institution_id"];
- $doctorId = isset($params["id"]) ? $params["id"] : null;
- $menuIds = isset($params["ids"]) ? $params["ids"] : null;
- if (empty($doctorId) || empty($menuIds) || empty($insId)) {
- // 如果医生ID,菜单ID,所在机构ID,某一个为空,直接返回失败
- echo "fail";
- return;
- }
- // 查询该医生信息
- $doctor = Db::table("doctors")->where("institution_id", $insId)->where("id", $doctorId);
- if (empty($doctor)) {
- // 该机构下,没有找到该医生
- echo "fail";
- return;
- }
- $menuIdArr = explode(",", $menuIds);
- $menus = Db::table("menu")->whereIn("id", $menuIdArr)->select();
- if (count($menus) < 1) {
- // 没有找到菜单
- echo "fail";
- return;
- } else {
- // 给用户赋值
- // 查看是否已经有了权限
- $menuIdArr = array();
- foreach ($menus as $key => $val) {
- array_push($menuIdArr, $val["id"]);
- }
- // 将已有权限全部清空
- Db::table("dr_cla_permission")->where("doctor_id", $doctorId)->where("type", "1")->delete();
- SysLogs::log("dr_cla_permission", "D", "where (doctor_id = " . $doctorId . "type = 1) delete ");
- // 如果没有,添加
- foreach ($menuIdArr as $key => $val) {
- $newRow = array();
- $newRow["id"] = UUIDs::uuid16();
- $newRow["type"] = "1";
- $newRow["pass"] = $val;
- $newRow["doctor_id"] = $doctorId;
- Db::table("dr_cla_permission")->insert($newRow);
- SysLogs::log("dr_cla_permission", "C", json_encode($newRow));
- }
- }
- echo "ok";
- }
- /**
- * 保存报告权限
- */
- public function saveReportPermit() {
- $request = Request::instance();
- $params = $request->param();
- // 医院的管理员,只能处理本机构的记录
- $manager = $admin = Session::get('session_manager');
- if (empty($manager) || empty($manager["institution_id"])) {
- // 登录超时,或者者不是机构管理员
- echo "fail";
- return;
- }
- $insId = $manager["institution_id"];
- $doctorId = isset($params["id"]) ? $params["id"] : null;
- $permitReport = isset($params["report"]) ? $params["report"] : null;
- if ($doctorId == null || $permitReport == null || $insId == null) {
- echo "fail";
- return;
- }
- // 查询该医生信息
- $doctor = Db::table("doctors")->where("institution_id", $insId)->where("id", $doctorId);
- if (empty($doctor)) {
- // 该机构下,没有找到该医生
- echo "fail";
- return;
- }
- $permitData = Db::table("dr_cla_permission")->where("doctor_id", $doctorId)->where("type", "2")->find();
- if (!empty($permitData)) {
- // 如果已经有报告权限的配置,
- // 只更新就好
- $permitData["pass"] = $permitReport;
- Db::table("dr_cla_permission")->update($permitData);
- SysLogs::log("dr_cla_permission", "U", json_encode($permitData));
- } else {
- // 新建权限记录
- $newRow = array();
- $newRow["id"] = UUIDs::uuid16();
- $newRow["doctor_id"] = $doctorId;
- $newRow["type"] = "2";
- $newRow["pass"] = $permitReport;
- Db::table("dr_cla_permission")->insert($newRow);
- SysLogs::log("dr_cla_permission", "C", json_encode($newRow));
- }
- echo "ok";
- }
- /**
- * 查询全部菜单
- */
- public function menudata() {
- $rootMenuData = array();
- // 准备根节点
- $rootMenuData["id"] = "root";
- $rootMenuData["pId"] = "0";
- $rootMenuData["name"] = "菜单(根节点)";
- $rootMenuData["url"] = "";
- $rootMenuData["open"] = "true";
- // 查询全部数据
- $menuData = $info = DB::table('menu')->select();
- $jsonarray = array();
- if ($menuData != null) {
- foreach ($menuData as $k => $val) {
- $parent_id = $val["parent_id"];
- unset($val["parent_id"]);
- // 处理parent_id为pId,为前端菜单上下级关系展示处理
- $val['pId'] = $parent_id;
- $val['open'] = "true";
- array_push($jsonarray, $val);
- }
- }
- // 将根节点添加到树
- array_unshift($jsonarray, $rootMenuData);
- // 返回JSON数据
- echo json_encode($jsonarray);
- }
- // 医院的统计
- public function stats() {
- $admin = Session::get('session_manager');
- // 得到所在机构ID
- $insId = $admin["institution_id"];
- if (strpos($insId, ",") !== false) {
- // 有多个机构时,只取第一个
- $insId = substr($insId, 0, trpos($insId, ","));
- }
- $dateStr = date("Ym");
- $whereArr = array();
- $whereArr["role_id"] = $insId;
- // 取最近5个月的数据
- $whereArr["month"] = array(">=", date("Ym", strtotime("201808 - 180 day")));
- $stats = Db::table("operating")->where($whereArr)->order("month", "1")->select();
- if (count($stats) > 0) {
- $this->assign("stats", json_encode($stats));
- } else {
- $this->assign("stats", json_encode(array()));
- }
- return $this->fetch("stats");
- }
- /**
- * 医院科室管理
- * @return type
- */
- public function deptview() {
- $admin = Session::get('session_manager');
- // 得到所在机构ID
- $insId = $admin["institution_id"];
- $this->assign("insId", $insId);
- return $this->fetch('/institution/dept');
- }
- }
|