123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 |
- <?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;
- use OSS\OssClient;
- use OSS\Core\OssException;
- class Exam extends Base {
- public function index() {
- return $this->fetch('index');
- }
- public function datas() {
- $request = Request::instance();
- $params = $request->param();
- $insid = isset($params["insid"]) ? $params["insid"] : null;
- $deptid = isset($params["deptid"]) ? $params["deptid"] : null;
- $patient_num = isset($params["patient_num"]) ? $params["patient_num"] : null;
- $accession_num = isset($params["accession_num"]) ? $params["accession_num"] : null;
- $exam_class = isset($params["exam_class"]) ? $params["exam_class"] : null;
- $insMap = array();
- $insArr = Db::table("institution")->field("id, name")->select();
- if (!empty($insArr)) {
- foreach ($insArr as $key => $val) {
- $insMap[$val["id"]] = $val["name"];
- }
- }
- $deptMap = array();
- $deptArr = Db::table("department")->field("id, department_name")->select();
- if (!empty($deptArr)) {
- foreach ($deptArr as $key => $val) {
- $deptMap[$val["id"]] = $val["department_name"];
- }
- }
- $doctMap = array();
- $doctArr = Db::table("doctors")->field("id, username")->select();
- if (!empty($doctArr)) {
- foreach ($doctArr as $key => $val) {
- $doctMap[$val["id"]] = $val["username"];
- }
- }
- $wheres = array();
- if (!empty($insid)) {
- $wheres["institution_id"] = $insid;
- }
- if (!empty($deptid)) {
- $wheres["dept_id"] = $deptid;
- }
- if (!empty($patient_num)) {
- $wheres["patient_num"] = $patient_num;
- }
- if (!empty($accession_num)) {
- $wheres["accession_num"] = $accession_num;
- }
- if (!empty($exam_class)) {
- $wheres["exam_class"] = $exam_class;
- }
- // 处理分页
- $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;
- }
- $resultArr = array();
-
- $sortArr=array();
- $sortArr["register_datetime"]="desc";
-
- $rs = Db::table("exams")->where($wheres)->order($sortArr)->page($page, $pagesize)->select();
- if (!empty($rs)) {
- foreach ($rs as $key => $val) {
- if (isset($insMap[$val["institution_id"]])) {
- $val["institution_name"] = $insMap[$val["institution_id"]];
- } else {
- $val["institution_name"] = $val["institution_id"];
- }
- if (isset($deptMap[$val["dept_id"]])) {
- $val["dept_name"] = $deptMap[$val["dept_id"]];
- } else {
- $val["dept_name"] = $val["dept_id"];
- }
- // 技师
- if (isset($doctMap[$val["technician"]])) {
- $val["technician_name"] = $doctMap[$val["technician"]];
- } else {
- $val["technician_name"] = $val["technician"];
- }
- // 送诊医生
- if (isset($doctMap[$val["clin_doctors"]])) {
- $val["clin_doctors_name"] = $doctMap[$val["clin_doctors"]];
- } else {
- $val["clin_doctors_name"] = $val["clin_doctors"];
- }
- // 申请医生
- if (isset($doctMap[$val["req_doctor"]])) {
- $val["req_doctor_name"] = $doctMap[$val["req_doctor"]];
- } else {
- $val["req_doctor_name"] = $val["req_doctor"];
- }
- // 登记人员
- if (isset($doctMap[$val["register"]])) {
- $val["register_name"] = $doctMap[$val["register"]];
- } else {
- $val["register_name"] = $val["register"];
- }
-
-
- array_push($resultArr, $val);
- }
- }
- $count = Db::table("exams")->where($wheres)->count();
- $data = array();
- $data["total"] = $count;
- $data["rows"] = $resultArr;
- echo json_encode($data);
- }
- /**
- * 编辑页面
- * @return type
- */
- public function edit() {
- $id = is_string($_GET["id"]) ? $_GET["id"] : null;
- if ($id != null) {
- // 查询检查表
- $exam = Db::table("exams")->where("id", $id)->find();
- // 以下追加名称字段
- $exam = self::appendName($exam, "technician", "doctors", "username"); // 技师
- $exam = self::appendName($exam, "clin_doctors", "doctors", "username"); // 送诊医生
- $exam = self::appendName($exam, "req_doctor", "doctors", "username"); // 申请医生
- $exam = self::appendName($exam, "register", "doctors", "username"); // 登记人员
- $exam = self::appendName($exam, "institution_id", "institution", "name"); // 机构名称
- $exam = self::appendName($exam, "clin_dept_id", "department", "department_name"); // 科室
- $exam = self::appendName($exam, "body_part", "bodypart", "name"); // 检查部位
- $exam = self::appendName($exam, "device", "bodypart", "name"); // 检查设备
- $exam = self::appendName($exam, "exam_project", "exam_project", "name"); // 检查设备
- $exam = self::appendName($exam, "exam_sub_class", "exam_subclass", "name"); // 检查设备
- $exam = self::appendName($exam, "exam_class", "exam_class", "name"); // 检查类型
- $exam = self::appendName($exam, "patient_id", "patient_info", "name"); // 患者
- $exam = self::appendName($exam, "dept_id", "department", "department_name"); // 患者
- $this->assign("exam", $exam);
- // 查询报告表
- $report = Db::table("report")->where("exam_id", $id)->find();
- if (!empty($report)) {
- $report = self::appendName($report, "report_doctor_id", "doctors", "username"); // 报告医生
- $report = self::appendName($report, "review_doctor_id", "doctors", "username"); // 审核医生
- $report = self::appendName($report, "confirm_doctor_id", "doctors", "username"); // 确认医生
- }
- $this->assign("report", $report);
- // 查询报告流程历史记录表
- if (!empty($report)) {
- $report_record = Db::table("report_record")->where("report_id", $id)->order("createdAt", "asc")->select();
- $errlist = array();
- if (count($report_record) > 0) {
- foreach ($report_record as $key => $val) {
- $val = self::appendName($val, "doctor_id", "doctors", "username"); // 操作医生
- array_push($errlist, $val);
- }
- }
- $this->assign("report_record", $errlist);
- }
- // 查询影像表
- // TODO 待处理
- }
- return $this->fetch('edit');
- }
- /**
- * 信息保存<br />
- * 暂时只有修改状态
- */
- public function save() {
- $id = is_string($_GET["id"]) ? $_GET["id"] : null;
- $status = is_numeric($_GET["status"]) ? $_GET["status"] : null;
- if ($id != "" && $status != null) {
- $data = array();
- $data["status"] = $status;
- Db::table("exams")->where("id", $id)->update($data);
- $exam = Db::table("exams")->where("id", $id)->find();
- SysLogs::log("exam", "U", "id = " . $id . " " . json_encode($data));
- }
- $id = is_string($_GET["id"]) ? $_GET["id"] : "";
- }
- public function deleteOne()
- {
- $id = is_string($_GET["id"]) ? $_GET["id"] : null;
- if(empty($id)){
- return '';
- }
- $exam = DB::table('exams')->where('id',$id)->field('study_id')->find();
- if(empty($exam['study_id']))
- {
- return '';
- }
- $studies = DB::table('series')->where('study_id',$exam['study_id'])->column('id');
- $images = DB::table('images')->where('series_id','in',$studies)->column('metadata');
- $this->delOneAli($images);
- return 'delete_ok';
- }
- public function deleteAll()
- {
- $string = is_string($_GET["ids"]) ? $_GET["ids"] : null;
- $this->del($string);
- return 'delete_ok';
- }
- public function curl_get($url){
- // $header = array(
- // 'Accept: text/html',
- // );
- $curl = curl_init();
- //设置抓取的url
- curl_setopt($curl, CURLOPT_URL, $url);
- //设置头文件的信息作为数据流输出
- curl_setopt($curl, CURLOPT_HEADER, 0);
- // 超时设置,以秒为单位
- curl_setopt($curl, CURLOPT_TIMEOUT, 1);
- // 超时设置,以毫秒为单位
- // curl_setopt($curl, CURLOPT_TIMEOUT_MS, 500);
- // 设置请求头
- // curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
- //设置获取的信息以文件流的形式返回,而不是直接输出。
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- //执行命令
- $data = curl_exec($curl);
- curl_close($curl);
- // // 显示错误信息
- // if (curl_error($curl)) {
- // print "Error: " . curl_error($curl);
- // } else {
- // // 打印返回的内容
- // var_dump($data);
- // }
- }
- public function del($string)
- {
- $ids = explode(',',$string);
- if(empty($ids)){
- return '';
- }
- $study_ids = DB::table('exams')->where('id','in',$ids)->where("study_id is not null or study_id != ''")->column('study_id');
- $studies = DB::table('series')->where('study_id','in',$study_ids)->column('id');
- $images = DB::table('images')->where('series_id','in',$studies)->column('metadata');
- if(empty($images)){
- return;
- }
- $count = count($images);
- $accessKeyId = "LTAI4GDTQ15b4F85sAaAKTEE";
- $accessKeySecret = "6NrhII6uYQj0mEvU7jnPNhr9InSq57";
- // Endpoint以杭州为例,其它Region请按实际情况填写。
- $endpoint = "http://oss-cn-beijing.aliyuncs.com";
- $bucket= "zskk-dcm";
- $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
- if($count > 499){
- $c = floor($count/500);
- for ($i=0;$i<=$c;$i++)
- {
- $data = [];
- $objects = array();
- $num1 = $i*500;
- $num2 = 500;
- // 截取500个image数据
- $data = array_slice($images,$num1,$num2);
- foreach ($data as $k=>$v){
- $objects[] = $v;
- }
- // 调用阿里删除数据
- $this->delAli($ossClient,$bucket,$objects);
- }
- }else{
- foreach ($images as $k=>$v){
- $objects[] = $v;
- }
- $this->delAli($ossClient,$bucket,$objects);
- }
- return;
- }
- public function delAli($ossClient,$bucket,$objects)
- {
- $info = $ossClient->deleteObjects($bucket, $objects);
- if($info){
- // 删除成功则删除对应数据
- DB::table('images')->where('metadata','in',$objects)->delete();
- DB::table('oss_callbacks')->where('md5','in',$objects)->delete();
- }
- }
- public function delOneAli($data)
- {
- if(empty($data)){
- return;
- }
- $count = count($data);
- $accessKeyId = "LTAI4GDTQ15b4F85sAaAKTEE";
- $accessKeySecret = "6NrhII6uYQj0mEvU7jnPNhr9InSq57";
- // Endpoint以杭州为例,其它Region请按实际情况填写。
- $endpoint = "http://oss-cn-beijing.aliyuncs.com";
- $bucket= "zskk-dcm";
- $objects = array();
- $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
- if($count > 1000){
- $c = floor($count/1000);
- for ($i=0;$i<=$c;$i++)
- {
- $num1 = $i*1000;
- $num2 = $i*1000+999;
- // 截取1000个image数据
- $data = array_slice($data,$num1,$num2);
- foreach ($data as $k=>$v){
- $objects[] = $v;
- }
- // 调用阿里删除数据
- $info = $ossClient->deleteObjects($bucket, $objects);
- if($info){
- // 删除成功则删除对应数据
- DB::table('images')->where('metadata','in',$objects)->delete();
- DB::table('oss_callbacks')->where('md5','in',$objects)->delete();
- }
- }
- }else{
- foreach ($data as $k=>$v){
- $objects[] = $v;
- }
- $info = $ossClient->deleteObjects($bucket, $objects);
- if($info){
- DB::table('images')->where('metadata','in',$objects)->delete();
- DB::table('oss_callbacks')->where('md5','in',$objects)->delete();
- }
- }
- return $info;
- }
- }
|