Exam.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. use OSS\OssClient;
  12. use OSS\Core\OssException;
  13. class Exam extends Base {
  14. public function index() {
  15. return $this->fetch('index');
  16. }
  17. public function datas() {
  18. $request = Request::instance();
  19. $params = $request->param();
  20. $insid = isset($params["insid"]) ? $params["insid"] : null;
  21. $deptid = isset($params["deptid"]) ? $params["deptid"] : null;
  22. $patient_num = isset($params["patient_num"]) ? $params["patient_num"] : null;
  23. $accession_num = isset($params["accession_num"]) ? $params["accession_num"] : null;
  24. $exam_class = isset($params["exam_class"]) ? $params["exam_class"] : null;
  25. $insMap = array();
  26. $insArr = Db::table("institution")->field("id, name")->select();
  27. if (!empty($insArr)) {
  28. foreach ($insArr as $key => $val) {
  29. $insMap[$val["id"]] = $val["name"];
  30. }
  31. }
  32. $deptMap = array();
  33. $deptArr = Db::table("department")->field("id, department_name")->select();
  34. if (!empty($deptArr)) {
  35. foreach ($deptArr as $key => $val) {
  36. $deptMap[$val["id"]] = $val["department_name"];
  37. }
  38. }
  39. $doctMap = array();
  40. $doctArr = Db::table("doctors")->field("id, username")->select();
  41. if (!empty($doctArr)) {
  42. foreach ($doctArr as $key => $val) {
  43. $doctMap[$val["id"]] = $val["username"];
  44. }
  45. }
  46. $wheres = array();
  47. if (!empty($insid)) {
  48. $wheres["institution_id"] = $insid;
  49. }
  50. if (!empty($deptid)) {
  51. $wheres["dept_id"] = $deptid;
  52. }
  53. if (!empty($patient_num)) {
  54. $wheres["patient_num"] = $patient_num;
  55. }
  56. if (!empty($accession_num)) {
  57. $wheres["accession_num"] = $accession_num;
  58. }
  59. if (!empty($exam_class)) {
  60. $wheres["exam_class"] = $exam_class;
  61. }
  62. // 处理分页
  63. $page = empty($_GET["page"]) ? 1 : $_GET["page"];
  64. $pagesize = empty($_GET["rows"]) ? 1 : $_GET["rows"];
  65. if (empty($page) || $page < 1) {
  66. $page = 1;
  67. }
  68. if (empty($pagesize) || $pagesize < 1) {
  69. $pagesize = 30;
  70. }
  71. $resultArr = array();
  72. $sortArr=array();
  73. $sortArr["register_datetime"]="desc";
  74. $rs = Db::table("exams")->where($wheres)->order($sortArr)->page($page, $pagesize)->select();
  75. if (!empty($rs)) {
  76. foreach ($rs as $key => $val) {
  77. if (isset($insMap[$val["institution_id"]])) {
  78. $val["institution_name"] = $insMap[$val["institution_id"]];
  79. } else {
  80. $val["institution_name"] = $val["institution_id"];
  81. }
  82. if (isset($deptMap[$val["dept_id"]])) {
  83. $val["dept_name"] = $deptMap[$val["dept_id"]];
  84. } else {
  85. $val["dept_name"] = $val["dept_id"];
  86. }
  87. // 技师
  88. if (isset($doctMap[$val["technician"]])) {
  89. $val["technician_name"] = $doctMap[$val["technician"]];
  90. } else {
  91. $val["technician_name"] = $val["technician"];
  92. }
  93. // 送诊医生
  94. if (isset($doctMap[$val["clin_doctors"]])) {
  95. $val["clin_doctors_name"] = $doctMap[$val["clin_doctors"]];
  96. } else {
  97. $val["clin_doctors_name"] = $val["clin_doctors"];
  98. }
  99. // 申请医生
  100. if (isset($doctMap[$val["req_doctor"]])) {
  101. $val["req_doctor_name"] = $doctMap[$val["req_doctor"]];
  102. } else {
  103. $val["req_doctor_name"] = $val["req_doctor"];
  104. }
  105. // 登记人员
  106. if (isset($doctMap[$val["register"]])) {
  107. $val["register_name"] = $doctMap[$val["register"]];
  108. } else {
  109. $val["register_name"] = $val["register"];
  110. }
  111. array_push($resultArr, $val);
  112. }
  113. }
  114. $count = Db::table("exams")->where($wheres)->count();
  115. $data = array();
  116. $data["total"] = $count;
  117. $data["rows"] = $resultArr;
  118. echo json_encode($data);
  119. }
  120. /**
  121. * 编辑页面
  122. * @return type
  123. */
  124. public function edit() {
  125. $id = is_string($_GET["id"]) ? $_GET["id"] : null;
  126. if ($id != null) {
  127. // 查询检查表
  128. $exam = Db::table("exams")->where("id", $id)->find();
  129. // 以下追加名称字段
  130. $exam = self::appendName($exam, "technician", "doctors", "username"); // 技师
  131. $exam = self::appendName($exam, "clin_doctors", "doctors", "username"); // 送诊医生
  132. $exam = self::appendName($exam, "req_doctor", "doctors", "username"); // 申请医生
  133. $exam = self::appendName($exam, "register", "doctors", "username"); // 登记人员
  134. $exam = self::appendName($exam, "institution_id", "institution", "name"); // 机构名称
  135. $exam = self::appendName($exam, "clin_dept_id", "department", "department_name"); // 科室
  136. $exam = self::appendName($exam, "body_part", "bodypart", "name"); // 检查部位
  137. $exam = self::appendName($exam, "device", "bodypart", "name"); // 检查设备
  138. $exam = self::appendName($exam, "exam_project", "exam_project", "name"); // 检查设备
  139. $exam = self::appendName($exam, "exam_sub_class", "exam_subclass", "name"); // 检查设备
  140. $exam = self::appendName($exam, "exam_class", "exam_class", "name"); // 检查类型
  141. $exam = self::appendName($exam, "patient_id", "patient_info", "name"); // 患者
  142. $exam = self::appendName($exam, "dept_id", "department", "department_name"); // 患者
  143. $this->assign("exam", $exam);
  144. // 查询报告表
  145. $report = Db::table("report")->where("exam_id", $id)->find();
  146. if (!empty($report)) {
  147. $report = self::appendName($report, "report_doctor_id", "doctors", "username"); // 报告医生
  148. $report = self::appendName($report, "review_doctor_id", "doctors", "username"); // 审核医生
  149. $report = self::appendName($report, "confirm_doctor_id", "doctors", "username"); // 确认医生
  150. }
  151. $this->assign("report", $report);
  152. // 查询报告流程历史记录表
  153. if (!empty($report)) {
  154. $report_record = Db::table("report_record")->where("report_id", $id)->order("createdAt", "asc")->select();
  155. $errlist = array();
  156. if (count($report_record) > 0) {
  157. foreach ($report_record as $key => $val) {
  158. $val = self::appendName($val, "doctor_id", "doctors", "username"); // 操作医生
  159. array_push($errlist, $val);
  160. }
  161. }
  162. $this->assign("report_record", $errlist);
  163. }
  164. // 查询影像表
  165. // TODO 待处理
  166. }
  167. return $this->fetch('edit');
  168. }
  169. /**
  170. * 信息保存<br />
  171. * 暂时只有修改状态
  172. */
  173. public function save() {
  174. $id = is_string($_GET["id"]) ? $_GET["id"] : null;
  175. $status = is_numeric($_GET["status"]) ? $_GET["status"] : null;
  176. if ($id != "" && $status != null) {
  177. $data = array();
  178. $data["status"] = $status;
  179. Db::table("exams")->where("id", $id)->update($data);
  180. $exam = Db::table("exams")->where("id", $id)->find();
  181. SysLogs::log("exam", "U", "id = " . $id . " " . json_encode($data));
  182. }
  183. $id = is_string($_GET["id"]) ? $_GET["id"] : "";
  184. }
  185. public function deleteOne()
  186. {
  187. $id = is_string($_GET["id"]) ? $_GET["id"] : null;
  188. if(empty($id)){
  189. return '';
  190. }
  191. $exam = DB::table('exams')->where('id',$id)->field('study_id')->find();
  192. if(empty($exam['study_id']))
  193. {
  194. return '';
  195. }
  196. $studies = DB::table('series')->where('study_id',$exam['study_id'])->column('id');
  197. $images = DB::table('images')->where('series_id','in',$studies)->column('metadata');
  198. $return = $this->delAli($images);
  199. return 'delete_ok';
  200. }
  201. public function deleteAll()
  202. {
  203. $string = is_string($_GET["ids"]) ? $_GET["ids"] : null;
  204. $ids = explode(',',$string);
  205. if(empty($ids)){
  206. return '';
  207. }
  208. $study_ids = DB::table('exams')->where('id','in',$ids)->where("study_id is not null or study_id != ''")->column('study_id');
  209. $studies = DB::table('series')->where('study_id','in',$study_ids)->column('id');
  210. $images = DB::table('images')->where('series_id','in',$studies)->column('metadata');
  211. $return = $this->delAli($images);
  212. return 'delete_ok';
  213. }
  214. public function delAli($data)
  215. {
  216. if(empty($data)){
  217. return;
  218. }
  219. $count = count($data);
  220. $accessKeyId = "LTAI4GDTQ15b4F85sAaAKTEE";
  221. $accessKeySecret = "6NrhII6uYQj0mEvU7jnPNhr9InSq57";
  222. // Endpoint以杭州为例,其它Region请按实际情况填写。
  223. $endpoint = "http://oss-cn-beijing.aliyuncs.com";
  224. $bucket= "zskk-dcm";
  225. $objects = array();
  226. $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
  227. if($count > 1000){
  228. $c = floor($count/1000);
  229. for ($i=0;$i<=$c;$i++)
  230. {
  231. $num1 = $i*1000;
  232. $num2 = $i*1000+999;
  233. // 截取1000个image数据
  234. $data = array_slice($data,$num1,$num2);
  235. foreach ($data as $k=>$v){
  236. $objects[] = $v;
  237. }
  238. // 调用阿里删除数据
  239. $info = $ossClient->deleteObjects($bucket, $objects);
  240. if($info){
  241. // 删除成功则删除对应数据
  242. DB::table('images')->where('metadata','in',$objects)->delete();
  243. DB::table('oss_callbacks')->where('md5','in',$objects)->delete();
  244. }
  245. }
  246. }else{
  247. foreach ($data as $k=>$v){
  248. $objects[] = $v;
  249. }
  250. $info = $ossClient->deleteObjects($bucket, $objects);
  251. if($info){
  252. DB::table('images')->where('metadata','in',$objects)->delete();
  253. DB::table('oss_callbacks')->where('md5','in',$objects)->delete();
  254. }
  255. }
  256. return $info;
  257. }
  258. }