Index.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\common\array2xml;
  5. use think\facade\Config;
  6. use think\facade\Db;
  7. use think\facade\Cache;
  8. class Index extends BaseController
  9. {
  10. public function index()
  11. {
  12. $this->getPdf('12206060840002');
  13. // phpinfo();
  14. }
  15. public function hello($name = 'ThinkPHP6')
  16. {
  17. return 'hello,' . $name;
  18. }
  19. public function getReport()
  20. {
  21. $code = $_REQUEST['code'];
  22. $type = $_REQUEST['type'];
  23. libxml_disable_entity_loader(false);
  24. // $client = new \SoapClient("http://report.dalabs.cn/RasClientDetail.asmx?wsdl");
  25. $client = new \SoapClient("http://115.238.253.166/RasClientDetail.asmx?wsdl");
  26. $data = [
  27. 'ClientID'=>Config::get('app')['dian']['ClientID'],
  28. 'ClientGUID'=>Config::get('app')['dian']['ClientGUID'],
  29. 'hospBarcode'=>$code,
  30. 'SelectType'=>$type
  31. ]; //请求参数
  32. Db::table('api_log')->insert(['type'=>1,'barcode'=>$code]);
  33. try{
  34. $result = $client->GetDetailDataByHospBarcode3($data); //请求获取接口
  35. Db::table('api_log')->insert(['type'=>2,'barcode'=>$code]);
  36. $data = ((array)$result)['GetDetailDataByHospBarcode3Result'];
  37. $obj = simplexml_load_string("<data>".$data."</data>","SimpleXMLElement", LIBXML_NOCDATA);
  38. if($obj)
  39. {
  40. $info = json_decode(json_encode($obj),true);
  41. $returnCode = $info['Error']['Code'];
  42. if($returnCode !== '0')
  43. {
  44. return '报告获取失败!迪安回传信息:'.$info['Error']['Descript'];
  45. }
  46. }
  47. $report = json_encode($obj);
  48. DB::table('dianapiinfo')->where('Barcode',$code)->update(['result_xml'=>$report]);
  49. $this->getPdf($code);
  50. return 'success';
  51. }catch(\SoapFault $e){
  52. return $e->getMessage();
  53. }
  54. }
  55. public function getPdf($code)
  56. {
  57. $type = 1;
  58. libxml_disable_entity_loader(false);
  59. $client = new \SoapClient("https://r.dalabs.cn/ReportService.asmx?wsdl");
  60. try{
  61. $result = $client->QueryReports2(array('ReqInfo'=>[
  62. 'PageNo'=>1,
  63. 'ClientID'=>Config::get('app')['dian']['ClientID'],
  64. 'Key'=>Config::get('app')['dian']['ClientGUID'],
  65. 'Condition'=>[
  66. 'ClinicID'=>$code,
  67. 'StartDate'=>'',
  68. 'EndDate'=>''
  69. ]])); //请求获取接口
  70. $data = ((array)$result)['QueryReports2Result'];
  71. $info = json_decode(json_encode($data),true);
  72. Db::table('api_log')->insert(['type'=>4,'barcode'=>$code,'data'=>json_encode($result)]);
  73. if($info)
  74. {
  75. $returnCode = $info['ResultCode'];
  76. if($returnCode <= 0)
  77. {
  78. return '报告PDF获取失败!迪安回传信息:'.$info['ResultMsg'];
  79. }
  80. if(isset($info['Datas']['Report']['ClinicID']))
  81. {
  82. $pdf = $info['Datas']['Report']['PdfReportUrl'];
  83. $name = $info['Datas']['Report']['ClinicID'];
  84. $this->downImgRar($pdf,$name,'pdf',$info['Datas']['Report']['ClinicID']);
  85. }else{
  86. foreach ($info['Datas']['Report'] as $k=>$v)
  87. {
  88. $pdf = $v['PdfReportUrl'];
  89. $name = $v['ClinicID'].'_'.($k+1);
  90. $this->downImgRar($pdf,$name,'pdf',$v['ClinicID']);
  91. }
  92. }
  93. }
  94. Db::table('dianapiinfo')->where('Barcode',$code)->update(['pdf_xml'=>json_encode($result)]);
  95. return 'success';
  96. }catch(\SoapFault $e){
  97. return $e->getMessage();
  98. }
  99. }
  100. function downImgRar($url,$rename,$ext,$barCode){
  101. switch ($ext) {
  102. case 'png':
  103. case 'jpg': //下载图片
  104. $file_path = '/images/';
  105. break;
  106. case 'pdf': //下载PDF
  107. $file_path = '/pdf/';
  108. break;
  109. case 'zip':
  110. case 'rar': //下载压缩包
  111. $file_path = '/rar/';
  112. break;
  113. default:
  114. $file_path = '/files/';
  115. break;
  116. }
  117. $ch = curl_init($url);
  118. curl_setopt($ch, CURLOPT_HEADER, 0);
  119. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  120. curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
  121. $rawdata=curl_exec ($ch);
  122. curl_close ($ch);
  123. // 使用中文文件名需要转码
  124. file_put_contents('/data/gitcode/newpacs/public'.$file_path.$rename.'.'.$ext,$rawdata);
  125. // 返回路径
  126. $path = '/public'.$file_path.$rename.".".$ext;
  127. $ins = ['type'=>$ext,'url'=>$path,'barcode'=>$barCode];
  128. Db::table('annex')->insert($ins);
  129. $patientId = Db::table('dianapiinfo')->where('Barcode',$barCode)->value('patientId');
  130. Db::table('phy_lis_reports')->where('patientId',$patientId)->update(['is_report_url'=>1]);
  131. return 'success';
  132. }
  133. public function getOnlyPdf()
  134. {
  135. $code = $_REQUEST['code'];
  136. $this->getPdf($code);
  137. return 'success';
  138. }
  139. public function getOnlyReport()
  140. {
  141. $code = $_REQUEST['code'];
  142. $type = $_REQUEST['type'];
  143. libxml_disable_entity_loader(false);
  144. // $client = new \SoapClient("http://report.dalabs.cn/RasClientDetail.asmx?wsdl");
  145. $client = new \SoapClient("http://115.238.253.166/RasClientDetail.asmx?wsdl");
  146. $data = [
  147. 'ClientID'=>Config::get('app')['dian']['ClientID'],
  148. 'ClientGUID'=>Config::get('app')['dian']['ClientGUID'],
  149. 'hospBarcode'=>$code,
  150. 'SelectType'=>$type
  151. ]; //请求参数
  152. Db::table('api_log')->insert(['type'=>1,'barcode'=>$code]);
  153. try{
  154. $result = $client->GetDetailDataByHospBarcode3($data); //请求获取接口
  155. Db::table('api_log')->insert(['type'=>2,'barcode'=>$code]);
  156. $data = ((array)$result)['GetDetailDataByHospBarcode3Result'];
  157. $obj = simplexml_load_string("<data>".$data."</data>","SimpleXMLElement", LIBXML_NOCDATA);
  158. if($obj)
  159. {
  160. $info = json_decode(json_encode($obj),true);
  161. $returnCode = $info['Error']['Code'];
  162. if($returnCode !== '0')
  163. {
  164. return '报告获取失败!迪安回传信息:'.$info['Error']['Descript'];
  165. }
  166. }
  167. $report = json_encode($obj);
  168. DB::table('dianapiinfo')->where('Barcode',$code)->update(['result_xml'=>$report]);
  169. return 'success';
  170. }catch(\SoapFault $e){
  171. return $e->getMessage();
  172. }
  173. }
  174. }