Index.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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\send_message;
  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. $phone = '13763459789';
  16. $code = '1234';
  17. $id = '2345678iuytrgbn';
  18. $data = send_message::sendSms2Patient($phone,$code,$id);
  19. $info = json_decode(json_encode($data),true);
  20. var_dump($info);die;
  21. echo "index";
  22. // return $this->redirect('http://work.pacsonline.cn',302);
  23. }
  24. public function get_studiesinfo(){
  25. $study_id = $_REQUEST['study_id'];
  26. /*if(isset($_REQUEST['address']) && !empty($_ REQUEST['address'])){
  27. $url = "dicomweb://".$_REQUEST['address']."/";
  28. }else{
  29. $url = '';
  30. }*/
  31. $info = array();
  32. if(strlen($study_id) == '16'){
  33. $study_info = DB::table('studies')->where('id',$study_id)->field('id,studyuid,studyid,patient_id')->find();
  34. }else{
  35. $study_info = DB::table('studies')->where('studyuid',$study_id)->field('id,studyuid,studyid,patient_id')->find();
  36. }
  37. $info['studyInstanceUid'] = $study_info['studyuid'];
  38. $patient_info = DB::table('patient_infos')->where('id',$study_info['patient_id'])->field('birthday,institution_id,temp_patient_id,name,age,sex')->find();
  39. $date = DB::table('exams')->where('patient_id',$study_info['patient_id'])->field('exam_datetime')->find();
  40. $institution = DB::table('institution')->where('id',$patient_info['institution_id'])->field('name')->find();
  41. $info['patientName'] = $patient_info['name'];
  42. // 根据series_num排序
  43. $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();
  44. $series = array();
  45. foreach($series_list as $k=>$v){
  46. // image_number排序
  47. $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();
  48. foreach($image as $key=>$value){
  49. /*if(empty($url)){
  50. if(substr($value['metadata'], 0, strlen('group')) === 'group'){
  51. $image[$key]['url'] = "dicomweb://dcm.pacsonline.cn/".$value['metadata'];
  52. }else{
  53. $image[$key]['url'] = "dicomweb://static.dcm.pacsonline.cn/".$value['metadata'];
  54. }
  55. }else{
  56. $image[$key]['url'] = $url.$value['metadata'];
  57. }*/
  58. $imageUrl = $this->generateUrl($value['url'],$_REQUEST['address'],$value['remote_url'],$value['local_url'],$value['status']);
  59. if(!$imageUrl){
  60. $dir = ROOT_PATH . 'public' . DS . 'get_studiesinfo';
  61. if (!file_exists($dir)){
  62. mkdir ($dir,0777,true);
  63. }
  64. $file = ROOT_PATH . 'public' . DS . 'get_studiesinfo/'.date('Ymd').'-fail.log';
  65. $log = 'url错误,传值为--'.$_REQUEST['address'];
  66. file_put_contents($file, $log,FILE_APPEND);
  67. continue;
  68. }
  69. $image[$key]['url'] = $imageUrl;
  70. $image[$key]['imageNumber'] = $value['instanceNumber'];
  71. }
  72. $series[$k]['instances'] = $image;
  73. $series[$k]['seriesInstanceUid'] = $v['seriesuid'];
  74. $series[$k]['seriesDescription'] = $v['description'];
  75. $series[$k]['seriesNumber'] = $v['series_num'];
  76. }
  77. $info['seriesList'] = $series;
  78. $return = array();
  79. $return['transactionId'] = $study_info['studyuid'];
  80. if(!empty($patient_info['age'])){
  81. $info['patientAge'] = $patient_info['age'];
  82. }elseif(!empty($patient_info['birthday'])){
  83. $time = date('Ymd',time());
  84. $age = floor(($time - $patient_info['birthday'])/10000);
  85. $info['patientAge'] = $age;
  86. }else{
  87. $info['patientAge'] = '';
  88. }
  89. $info['patientSex'] = $patient_info['sex'];
  90. $info['studyDate'] = $date['exam_datetime'];
  91. $info['studyid'] = $study_info['studyid'];
  92. $info['patientId'] = $patient_info['temp_patient_id'];
  93. $info['institution'] = $institution['name'];
  94. $return['studies'][] = $info;
  95. return json_encode($return);
  96. }
  97. public function generateUrl($url, $address, $remote_url, $local_url, $status) {
  98. if(empty($address)) {
  99. return self::generateNormalUrl($url);
  100. }
  101. if(preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/",$address)) {
  102. return self::generateIpUrl($url,$address,$remote_url, $local_url, $status);
  103. }
  104. return self::generateNormalUrl($url,$address);
  105. }
  106. public function generateIpUrl($url, $address, $remote_url, $local_url, $status) {
  107. //获取ip
  108. $ip = $this->getIpbyAddress($address);
  109. if(in_array($ip,json_decode(LC_IPS,TRUE))) {
  110. //浪潮政务云访问
  111. return "dicomweb://$address/$remote_url";
  112. }
  113. if($status & STATUS_LOCAL) {
  114. //内网url有效
  115. return "dicomweb://$address/$local_url";
  116. }
  117. if($status & STATUS_REMOTE) {
  118. //外网url有效
  119. return "dicomweb://$address/".REMOTE_FLAG."/$remote_url";
  120. }
  121. return null;
  122. }
  123. public function getIpbyAddress($url){
  124. $ip = explode(':',$url);
  125. return $ip[0];
  126. }
  127. public function generateNormalUrl($url , $domain = 'dcm.pacsonline.cn') {
  128. if(substr($url, 0, strlen('dicomweb://')) === 'dicomweb://'){
  129. return $url;
  130. }elseif(substr($url, 0, strlen('http://')) === 'http://'){
  131. $httpurl = str_replace("'http://","dicomweb://",$url);
  132. return $httpurl;
  133. }elseif(substr($url, 0, strlen('https://')) === 'https://'){
  134. $httpsurl = str_replace("'https://","dicomweb://",$url);
  135. return $httpsurl;
  136. }elseif(strstr($domain,'://')){
  137. $lujing = explode('://',$domain);
  138. $dicurl = 'dicomweb://'.$lujing[1].'/'.$url;
  139. return $dicurl;
  140. }else{
  141. $dicurl = 'dicomweb://'.$domain.'/'.$url;
  142. return $dicurl;
  143. }
  144. }
  145. }