Index.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. namespace app\index\controller;
  8. use app\common\library\CMCC;
  9. use app\common\library\UUIDs;
  10. use think\Controller;
  11. use think\Db;
  12. class Index extends Controller
  13. {
  14. public function index(){
  15. $a = CMCC::sms('13763459789','1111');
  16. var_dump($a);die;
  17. // echo "index";
  18. return $this->redirect('http://work.pacsonline.cn',302);
  19. }
  20. public function get_studiesinfo(){
  21. $study_id = $_REQUEST['study_id'];
  22. /*if(isset($_REQUEST['address']) && !empty($_REQUEST['address'])){
  23. $url = "dicomweb://".$_REQUEST['address']."/";
  24. }else{
  25. $url = '';
  26. }*/
  27. $info = array();
  28. if(strlen($study_id) == '16'){
  29. $study_info = DB::table('studies')->where('id',$study_id)->field('id,studyuid,studyid,patient_id')->find();
  30. }else{
  31. $study_info = DB::table('studies')->where('studyuid',$study_id)->field('id,studyuid,studyid,patient_id')->find();
  32. }
  33. $info['studyInstanceUid'] = $study_info['studyuid'];
  34. $patient_info = DB::table('patient_infos')->where('id',$study_info['patient_id'])->field('birthday,institution_id,temp_patient_id,name,age,sex')->find();
  35. $date = DB::table('exams')->where('patient_id',$study_info['patient_id'])->field('exam_datetime')->find();
  36. $institution = DB::table('institution')->where('id',$patient_info['institution_id'])->field('name')->find();
  37. $info['patientName'] = $patient_info['name'];
  38. // 根据series_num排序
  39. $series_list = DB::table('series')->where('study_id',$study_info['id'])->where('modality','not in','PR,SR')->field('id,series_num,seriesuid,description')->order('series_num asc')->select();
  40. $series = array();
  41. foreach($series_list as $k=>$v){
  42. // image_number排序
  43. $image = DB::table('images')->where('series_id',$v['id'])->field('remote_url,local_url,status,columns,image_number as instanceNumber,rows,image_id as sopInstanceUid,metadata,url')->order('image_number asc')->select();
  44. foreach($image as $key=>$value){
  45. /*if(empty($url)){
  46. if(substr($value['metadata'], 0, strlen('group')) === 'group'){
  47. $image[$key]['url'] = "dicomweb://dcm.pacsonline.cn/".$value['metadata'];
  48. }else{
  49. $image[$key]['url'] = "dicomweb://static.dcm.pacsonline.cn/".$value['metadata'];
  50. }
  51. }else{
  52. $image[$key]['url'] = $url.$value['metadata'];
  53. }*/
  54. $imageUrl = $this->generateUrl($value['url'],$_REQUEST['address'],$value['remote_url'],$value['local_url'],$value['status']);
  55. if(!$imageUrl){
  56. $dir = ROOT_PATH . 'public' . DS . 'get_studiesinfo';
  57. if (!file_exists($dir)){
  58. mkdir ($dir,0777,true);
  59. }
  60. $file = ROOT_PATH . 'public' . DS . 'get_studiesinfo/'.date('Ymd').'-fail.log';
  61. $log = 'url错误,传值为--'.$_REQUEST['address'];
  62. file_put_contents($file, $log,FILE_APPEND);
  63. continue;
  64. }
  65. $image[$key]['url'] = $imageUrl;
  66. $image[$key]['imageNumber'] = $value['instanceNumber'];
  67. }
  68. $series[$k]['instances'] = $image;
  69. $series[$k]['seriesInstanceUid'] = $v['seriesuid'];
  70. $series[$k]['seriesDescription'] = $v['description'];
  71. $series[$k]['seriesNumber'] = $v['series_num'];
  72. }
  73. $info['seriesList'] = $series;
  74. $return = array();
  75. $return['transactionId'] = $study_info['studyuid'];
  76. if(!empty($patient_info['age'])){
  77. $info['patientAge'] = $patient_info['age'];
  78. }elseif(!empty($patient_info['birthday'])){
  79. $time = date('Ymd',time());
  80. $age = floor(($time - $patient_info['birthday'])/10000);
  81. $info['patientAge'] = $age;
  82. }else{
  83. $info['patientAge'] = '';
  84. }
  85. $info['patientSex'] = $patient_info['sex'];
  86. $info['studyDate'] = $date['exam_datetime'];
  87. $info['studyid'] = $study_info['studyid'];
  88. $info['patientId'] = $patient_info['temp_patient_id'];
  89. $info['institution'] = $institution['name'];
  90. $return['studies'][] = $info;
  91. return json_encode($return);
  92. }
  93. public function generateUrl($url, $address, $remote_url, $local_url, $status) {
  94. if(empty($address)) {
  95. return self::generateNormalUrl($url);
  96. }
  97. if(preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/",$address)) {
  98. return self::generateIpUrl($url,$address,$remote_url, $local_url, $status);
  99. }
  100. return self::generateNormalUrl($url,$address);
  101. }
  102. public function generateIpUrl($url, $address, $remote_url, $local_url, $status) {
  103. //获取ip
  104. $ip = $this->getIpbyAddress($address);
  105. if(in_array($ip,json_decode(LC_IPS,TRUE))) {
  106. //浪潮政务云访问
  107. return "dicomweb://$address/$remote_url";
  108. }
  109. if($status & STATUS_LOCAL) {
  110. //内网url有效
  111. return "dicomweb://$address/$local_url";
  112. }
  113. if($status & STATUS_REMOTE) {
  114. //外网url有效
  115. return "dicomweb://$address/".REMOTE_FLAG."/$remote_url";
  116. }
  117. return null;
  118. }
  119. public function getIpbyAddress($url){
  120. $ip = explode(':',$url);
  121. return $ip[0];
  122. }
  123. public function generateNormalUrl($url , $domain = 'dcm.pacsonline.cn') {
  124. if(substr($url, 0, strlen('dicomweb://')) === 'dicomweb://'){
  125. return $url;
  126. }elseif(substr($url, 0, strlen('http://')) === 'http://'){
  127. $httpurl = str_replace("'http://","dicomweb://",$url);
  128. return $httpurl;
  129. }elseif(substr($url, 0, strlen('https://')) === 'https://'){
  130. $httpsurl = str_replace("'https://","dicomweb://",$url);
  131. return $httpsurl;
  132. }elseif(strstr($domain,'://')){
  133. $lujing = explode('://',$domain);
  134. $dicurl = 'dicomweb://'.$lujing[1].'/'.$url;
  135. return $dicurl;
  136. }else{
  137. $dicurl = 'dicomweb://'.$domain.'/'.$url;
  138. return $dicurl;
  139. }
  140. }
  141. }