Exam.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 Exam extends Base {
  12. public function index() {
  13. return $this->fetch('index');
  14. }
  15. public function datas() {
  16. $request = Request::instance();
  17. $params = $request->param();
  18. $insid = isset($params["insid"]) ? $params["insid"] : null;
  19. $deptid = isset($params["deptid"]) ? $params["deptid"] : null;
  20. $patient_num = isset($params["patient_num"]) ? $params["patient_num"] : null;
  21. $accession_num = isset($params["accession_num"]) ? $params["accession_num"] : null;
  22. $insMap = array();
  23. $insArr = Db::table("institution")->field("id, name")->select();
  24. if (!empty($insArr)) {
  25. foreach ($insArr as $key => $val) {
  26. $insMap[$val["id"]] = $val["name"];
  27. }
  28. }
  29. $deptMap = array();
  30. $deptArr = Db::table("department")->field("id, department_name")->select();
  31. if (!empty($deptArr)) {
  32. foreach ($deptArr as $key => $val) {
  33. $deptMap[$val["id"]] = $val["department_name"];
  34. }
  35. }
  36. $doctMap = array();
  37. $doctArr = Db::table("doctors")->field("id, username")->select();
  38. if (!empty($doctArr)) {
  39. foreach ($doctArr as $key => $val) {
  40. $doctMap[$val["id"]] = $val["username"];
  41. }
  42. }
  43. $wheres = array();
  44. if (!empty($insid)) {
  45. $wheres["institution_id"] = $insid;
  46. }
  47. if (!empty($deptid)) {
  48. $wheres["dept_id"] = $deptid;
  49. }
  50. if (!empty($patient_num)) {
  51. $wheres["patient_num"] = $patient_num;
  52. }
  53. if (!empty($accession_num)) {
  54. $wheres["accession_num"] = $accession_num;
  55. }
  56. // 处理分页
  57. $page = empty($_GET["page"]) ? 1 : $_GET["page"];
  58. $pagesize = empty($_GET["rows"]) ? 1 : $_GET["rows"];
  59. if (empty($page) || $page < 1) {
  60. $page = 1;
  61. }
  62. if (empty($pagesize) || $pagesize < 1) {
  63. $pagesize = 30;
  64. }
  65. $resultArr = array();
  66. $sortArr=array();
  67. $sortArr["register_datetime"]="desc";
  68. $rs = Db::table("exam")->where($wheres)->order($sortArr)->page($page, $pagesize)->select();
  69. if (!empty($rs)) {
  70. foreach ($rs as $key => $val) {
  71. if (isset($insMap[$val["institution_id"]])) {
  72. $val["institution_name"] = $insMap[$val["institution_id"]];
  73. } else {
  74. $val["institution_name"] = $val["institution_id"];
  75. }
  76. if (isset($deptMap[$val["dept_id"]])) {
  77. $val["dept_name"] = $deptMap[$val["dept_id"]];
  78. } else {
  79. $val["dept_name"] = $val["dept_id"];
  80. }
  81. // 技师
  82. if (isset($doctMap[$val["technician"]])) {
  83. $val["technician_name"] = $doctMap[$val["technician"]];
  84. } else {
  85. $val["technician_name"] = $val["technician"];
  86. }
  87. // 送诊医生
  88. if (isset($doctMap[$val["clin_doctors"]])) {
  89. $val["clin_doctors_name"] = $doctMap[$val["clin_doctors"]];
  90. } else {
  91. $val["clin_doctors_name"] = $val["clin_doctors"];
  92. }
  93. // 申请医生
  94. if (isset($doctMap[$val["req_doctor"]])) {
  95. $val["req_doctor_name"] = $doctMap[$val["req_doctor"]];
  96. } else {
  97. $val["req_doctor_name"] = $val["req_doctor"];
  98. }
  99. // 登记人员
  100. if (isset($doctMap[$val["register"]])) {
  101. $val["register_name"] = $doctMap[$val["register"]];
  102. } else {
  103. $val["register_name"] = $val["register"];
  104. }
  105. array_push($resultArr, $val);
  106. }
  107. }
  108. $count = Db::table("exam")->where($wheres)->count();
  109. $data = array();
  110. $data["total"] = $count;
  111. $data["rows"] = $resultArr;
  112. echo json_encode($data);
  113. }
  114. /**
  115. * 编辑页面
  116. * @return type
  117. */
  118. public function edit() {
  119. $id = is_string($_GET["id"]) ? $_GET["id"] : null;
  120. if ($id != null) {
  121. // 查询检查表
  122. $exam = Db::table("exam")->where("id", $id)->find();
  123. // 以下追加名称字段
  124. $exam = self::appendName($exam, "technician", "doctors", "username"); // 技师
  125. $exam = self::appendName($exam, "clin_doctors", "doctors", "username"); // 送诊医生
  126. $exam = self::appendName($exam, "req_doctor", "doctors", "username"); // 申请医生
  127. $exam = self::appendName($exam, "register", "doctors", "username"); // 登记人员
  128. $exam = self::appendName($exam, "institution_id", "institution", "name"); // 机构名称
  129. $exam = self::appendName($exam, "clin_dept_id", "department", "department_name"); // 科室
  130. $exam = self::appendName($exam, "body_part", "bodypart", "name"); // 检查部位
  131. $exam = self::appendName($exam, "device", "bodypart", "name"); // 检查设备
  132. $exam = self::appendName($exam, "exam_project", "exam_project", "name"); // 检查设备
  133. $exam = self::appendName($exam, "exam_sub_class", "exam_subclass", "name"); // 检查设备
  134. $exam = self::appendName($exam, "exam_class", "exam_class", "name"); // 检查类型
  135. $exam = self::appendName($exam, "patient_id", "patient_info", "name"); // 患者
  136. $exam = self::appendName($exam, "dept_id", "department", "department_name"); // 患者
  137. $this->assign("exam", $exam);
  138. // 查询报告表
  139. $report = Db::table("report")->where("exam_id", $id)->find();
  140. if (!empty($report)) {
  141. $report = self::appendName($report, "report_doctor_id", "doctors", "username"); // 报告医生
  142. $report = self::appendName($report, "review_doctor_id", "doctors", "username"); // 审核医生
  143. $report = self::appendName($report, "confirm_doctor_id", "doctors", "username"); // 确认医生
  144. }
  145. $this->assign("report", $report);
  146. // 查询报告流程历史记录表
  147. if (!empty($report)) {
  148. $report_record = Db::table("report_record")->where("report_id", $id)->order("createdAt", "asc")->select();
  149. $errlist = array();
  150. if (count($report_record) > 0) {
  151. foreach ($report_record as $key => $val) {
  152. $val = self::appendName($val, "doctor_id", "doctors", "username"); // 操作医生
  153. array_push($errlist, $val);
  154. }
  155. }
  156. $this->assign("report_record", $errlist);
  157. }
  158. // 查询影像表
  159. // TODO 待处理
  160. }
  161. return $this->fetch('edit');
  162. }
  163. /**
  164. * 信息保存<br />
  165. * 暂时只有修改状态
  166. */
  167. public function save() {
  168. $id = is_string($_GET["id"]) ? $_GET["id"] : null;
  169. $status = is_numeric($_GET["status"]) ? $_GET["status"] : null;
  170. if ($id != "" && $status != null) {
  171. $data = array();
  172. $data["status"] = $status;
  173. Db::table("exam")->where("id", $id)->update($data);
  174. $exam = Db::table("exam")->where("id", $id)->find();
  175. SysLogs::log("exam", "U", "id = " . $id . " " . json_encode($data));
  176. }
  177. $id = is_string($_GET["id"]) ? $_GET["id"] : "";
  178. }
  179. }