Exam.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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. $this->delOneAli($images);
  199. return 'delete_ok';
  200. }
  201. public function deleteAll()
  202. {
  203. $string = is_string($_GET["ids"]) ? $_GET["ids"] : null;
  204. $this->del($string);
  205. return 'delete_ok';
  206. }
  207. public function curl_get($url){
  208. // $header = array(
  209. // 'Accept: text/html',
  210. // );
  211. $curl = curl_init();
  212. //设置抓取的url
  213. curl_setopt($curl, CURLOPT_URL, $url);
  214. //设置头文件的信息作为数据流输出
  215. curl_setopt($curl, CURLOPT_HEADER, 0);
  216. // 超时设置,以秒为单位
  217. curl_setopt($curl, CURLOPT_TIMEOUT, 1);
  218. // 超时设置,以毫秒为单位
  219. // curl_setopt($curl, CURLOPT_TIMEOUT_MS, 500);
  220. // 设置请求头
  221. // curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  222. //设置获取的信息以文件流的形式返回,而不是直接输出。
  223. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  224. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  225. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  226. //执行命令
  227. $data = curl_exec($curl);
  228. curl_close($curl);
  229. // // 显示错误信息
  230. // if (curl_error($curl)) {
  231. // print "Error: " . curl_error($curl);
  232. // } else {
  233. // // 打印返回的内容
  234. // var_dump($data);
  235. // }
  236. }
  237. public function del($string)
  238. {
  239. $ids = explode(',',$string);
  240. if(empty($ids)){
  241. return '';
  242. }
  243. $study_ids = DB::table('exams')->where('id','in',$ids)->where("study_id is not null or study_id != ''")->column('study_id');
  244. $studies = DB::table('series')->where('study_id','in',$study_ids)->column('id');
  245. $images = DB::table('images')->where('series_id','in',$studies)->column('metadata');
  246. if(empty($images)){
  247. return;
  248. }
  249. $count = count($images);
  250. $accessKeyId = "LTAI4GDTQ15b4F85sAaAKTEE";
  251. $accessKeySecret = "6NrhII6uYQj0mEvU7jnPNhr9InSq57";
  252. // Endpoint以杭州为例,其它Region请按实际情况填写。
  253. $endpoint = "http://oss-cn-beijing.aliyuncs.com";
  254. $bucket= "zskk-dcm";
  255. $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
  256. if($count > 499){
  257. $c = floor($count/500);
  258. for ($i=0;$i<=$c;$i++)
  259. {
  260. $data = [];
  261. $objects = array();
  262. $num1 = $i*500;
  263. $num2 = 500;
  264. // 截取500个image数据
  265. $data = array_slice($images,$num1,$num2);
  266. foreach ($data as $k=>$v){
  267. $objects[] = $v;
  268. }
  269. // 调用阿里删除数据
  270. $this->delAli($ossClient,$bucket,$objects);
  271. }
  272. }else{
  273. foreach ($images as $k=>$v){
  274. $objects[] = $v;
  275. }
  276. $this->delAli($ossClient,$bucket,$objects);
  277. }
  278. return;
  279. }
  280. public function delAli($ossClient,$bucket,$objects)
  281. {
  282. $info = $ossClient->deleteObjects($bucket, $objects);
  283. if($info){
  284. // 删除成功则删除对应数据
  285. DB::table('images')->where('metadata','in',$objects)->delete();
  286. DB::table('oss_callbacks')->where('md5','in',$objects)->delete();
  287. }
  288. }
  289. public function delOneAli($data)
  290. {
  291. if(empty($data)){
  292. return;
  293. }
  294. $count = count($data);
  295. $accessKeyId = "LTAI4GDTQ15b4F85sAaAKTEE";
  296. $accessKeySecret = "6NrhII6uYQj0mEvU7jnPNhr9InSq57";
  297. // Endpoint以杭州为例,其它Region请按实际情况填写。
  298. $endpoint = "http://oss-cn-beijing.aliyuncs.com";
  299. $bucket= "zskk-dcm";
  300. $objects = array();
  301. $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
  302. if($count > 1000){
  303. $c = floor($count/1000);
  304. for ($i=0;$i<=$c;$i++)
  305. {
  306. $num1 = $i*1000;
  307. $num2 = $i*1000+999;
  308. // 截取1000个image数据
  309. $data = array_slice($data,$num1,$num2);
  310. foreach ($data as $k=>$v){
  311. $objects[] = $v;
  312. }
  313. // 调用阿里删除数据
  314. $info = $ossClient->deleteObjects($bucket, $objects);
  315. if($info){
  316. // 删除成功则删除对应数据
  317. DB::table('images')->where('metadata','in',$objects)->delete();
  318. DB::table('oss_callbacks')->where('md5','in',$objects)->delete();
  319. }
  320. }
  321. }else{
  322. foreach ($data as $k=>$v){
  323. $objects[] = $v;
  324. }
  325. $info = $ossClient->deleteObjects($bucket, $objects);
  326. if($info){
  327. DB::table('images')->where('metadata','in',$objects)->delete();
  328. DB::table('oss_callbacks')->where('md5','in',$objects)->delete();
  329. }
  330. }
  331. return $info;
  332. }
  333. }