Writereport.php 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  1. <?php
  2. namespace app\inter\controller;
  3. //use Doctrine\Common\Cache\Cache;
  4. use app\common\library\Message;
  5. use think\Controller;
  6. use think\Db;
  7. use think\Session;
  8. use app\common\library\UUIDs;
  9. use think\Cache;
  10. use think\Log;
  11. use app\common\library\Verify;
  12. use app\common\library\send_message;
  13. class Writereport extends Base
  14. {
  15. /**
  16. * 写报告页面
  17. *
  18. * @ApiTitle (写报告页面)
  19. * @ApiSummary (写报告页面)
  20. * @ApiSector (远程诊断)
  21. * @ApiMethod (POST)
  22. * @ApiRoute (/inter/writereport/index)
  23. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  24. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  25. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  26. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  27. * @ApiParams (name="param", type="string", required=true, description="参数json字符串")
  28. * @ApiParams (name="is_remote", type="string", required=true, description="是否为远程列表进入")
  29. * @ApiParams (name="param[id]", type="string", sample="", description="exams表id值<必填>")
  30. * @ApiParams (name="param[images]", type="string", sample="", description="影像图片<选填>")
  31. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  32. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  33. * @ApiReturnParams (name="info", type="string", required=true, sample="返回成功", description="返回信息")
  34. * @ApiReturnParams (name="is_remote", type="object", sample="{}", description="是否为远程诊断进入")
  35. * @ApiReturnParams (name="sessionid", type="object", sample="{}", description="缓存的数据key")
  36. * @ApiReturn (data="
  37. {
  38. 'status': ok,
  39. 'code': '0000',
  40. 'sessionid': 'a17z7a7a8f9g9rh9d89jio',
  41. 'is_remote': 1,
  42. 'info' : ''
  43. }
  44. *")
  45. **/
  46. public function index(){
  47. try{
  48. log::record('-----请求值-----');
  49. log::record($_REQUEST);
  50. log::record('-----请求值-----');
  51. $sessionid = $_REQUEST['sessionid'];
  52. if(isset($_REQUEST['is_remote']) && !empty($_REQUEST['is_remote'])){
  53. $is_remote = $_REQUEST['is_remote'];
  54. }else{
  55. $is_remote = 0;
  56. }
  57. $doctor = Cache::get($sessionid);
  58. $institution = DB::table('institution')->where('id',$doctor['institution_id'])->field('name,report_subtitle')->find();
  59. $param = $_REQUEST['param'];
  60. $id = $param['id'];
  61. $info = DB::table('exams')->where('id',$id)->field(['id','ext','study_id','exam_class','exam_status','exam_datetime','exam_sub_class','body_part','accession_num','patient_id','film_type'])->find();
  62. $exam_class = DB::table('constant')->where('id',$info['exam_class'])->field('constant_value')->find();
  63. $info['exam_class'] = $exam_class['constant_value'];
  64. $exam_subclass = DB::table('exam_subclass')->where('id',$info['exam_sub_class'])->field('name')->find();
  65. $info['exam_sub_class'] = $exam_subclass['name'];
  66. $patient_info = DB::table('patient_infos')->where('id',$info['patient_id'])->field(['id','temp_patient_id','name','phone','sex','age'])->find();
  67. $info['pid'] = $patient_info['temp_patient_id'];
  68. $info['name'] = $patient_info['name'];
  69. $info['sex'] = $patient_info['sex'];
  70. $info['age'] = $patient_info['age'];
  71. $info['phone'] = $patient_info['phone'];
  72. $info['hospital_name'] = $institution['name'];
  73. $info['hospital_title'] = $institution['report_subtitle'];
  74. $info['images'] = isset($param['images']) ? $param['images'] : '';
  75. if(isset($param['rid']) && !empty($param['rid'])){
  76. $remote_id = $param['rid'];
  77. $report = DB::table('report')->where('exam_id',$id)->where('remote_application_id',$remote_id)->field('id,remote_application_id,report_result,report_datetime,report_doctor_id,review_datetime,review_doctor_id,impression,description')->find();
  78. $sta = DB::table('remote_application')->where('id',$remote_id)->field('report_status')->find();
  79. $info['report_status'] = $sta['report_status'];
  80. $r_id = $report['remote_application_id'];
  81. }else{
  82. // 不存在 本地点击进入 获取本地报告
  83. $report = DB::table('report')->where('exam_id',$id)->where('type',1)->field('id,remote_application_id,report_result,report_datetime,report_doctor_id,review_datetime,review_doctor_id,impression,description')->find();
  84. $info['report_status'] = '';
  85. $r_report = DB::table('report')->where('exam_id',$id)->where('type',2)->field('remote_application_id')->find();
  86. $r_id = $r_report['remote_application_id'];
  87. }
  88. if( $r_id == ''){
  89. $info['remote'] = 1;
  90. }else{
  91. $info['remote'] = 2;
  92. }
  93. $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find();
  94. $info['report_doctor'] = $report_doctor['realname'];
  95. $info['report_datetime'] = $report['report_datetime'];
  96. $review_doctor = DB::table('doctors')->where('id',$report['review_doctor_id'])->field('realname')->find();
  97. $info['review_doctor'] = $review_doctor['realname'];
  98. $info['review_datetime'] = $report['review_datetime'];
  99. $info['description'] = $report['description'];
  100. $info['impression'] = $report['impression'];
  101. $info['report_result'] = $report['report_result'];
  102. $info['report_id'] = $report['id'];
  103. $cache_key = $doctor['id'].'_'.$report['id'];
  104. if(Cache::get($cache_key)){
  105. $cache = Cache::get($cache_key);
  106. $info['description'] = isset($cache['description']) ? $cache['description'] : '';
  107. $info['impression'] = isset($cache['impression']) ? $cache['impression'] : '';
  108. $info['report_result'] = isset($cache['r_result']) ?$cache['r_result'] : '';
  109. $info['name'] = isset($cache['name']) ? $cache['name'] : '';
  110. $info['sex'] = isset($cache['sex']) ? $cache['sex'] : '';
  111. $info['age'] = isset($cache['age']) ? $cache['age'] : '';
  112. $info['phone'] = isset($cache['phone']) ? $cache['phone'] : '';
  113. }
  114. return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'sessionid'=>$sessionid,'is_remote'=>$is_remote]);
  115. }catch(\Exception $e){
  116. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  117. }
  118. }
  119. /**
  120. * 上远程申请附件
  121. *
  122. * @ApiTitle (上远程申请附件)
  123. * @ApiSummary (上远程申请附件)
  124. * @ApiSector (远程诊断)
  125. * @ApiMethod (POST)
  126. * @ApiRoute (/inter/writereport/upload)
  127. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  128. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  129. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  130. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  131. * @ApiParams (name="file", type="string", required=true, description="上传的文件<必填>")
  132. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  133. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  134. * @ApiReturnParams (name="info", type="string", required=true, sample="返回成功", description="返回信息")
  135. * @ApiReturn (data="
  136. {
  137. 'status': ok,
  138. 'code': '0000',
  139. 'info' : '/upload/20180101/12346asd.jpg'
  140. }
  141. *")
  142. **/
  143. public function upload($files){
  144. // 获取表单上传文件
  145. foreach($files as $file){
  146. // 移动到框架应用根目录/public/uploads/ 目录下
  147. $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
  148. if($info){
  149. return $info->getSaveName();
  150. // 成功上传后 获取上传信息
  151. // 输出 jpg
  152. // echo $info-> getExtension();
  153. // 输出 42a79759f284b767dfcb2a0197904287.jpg
  154. // echo $info->getFilename();
  155. }else{
  156. // 上传失败获取错误信息
  157. // echo $file->getError();
  158. }
  159. }
  160. }
  161. /**
  162. * 报告保存
  163. *
  164. * @ApiTitle (报告保存)
  165. * @ApiSummary (报告保存)
  166. * @ApiSector (远程诊断)
  167. * @ApiMethod (POST)
  168. * @ApiRoute (/inter/writereport/write)
  169. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  170. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  171. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  172. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  173. * @ApiParams (name="param", type="string", required=true, description="参数json字符串")
  174. * @ApiParams (name="is_remote", type="string", required=true, description="是否为远程列表进入")
  175. * @ApiParams (name="param[id]", type="string", sample="", description="exams表id值<必填>")
  176. * @ApiParams (name="param[pid]", type="string", sample="", description="患者id值<必填>")
  177. * @ApiParams (name="param[name]", type="string", sample="", description="患者姓名<必填>")
  178. * @ApiParams (name="param[age]", type="string", sample="", description="患者年龄<必填>")
  179. * @ApiParams (name="param[sex]", type="string", sample="", description="患者性别<必填>")
  180. * @ApiParams (name="param[impression]", type="string", sample="", description="影响所见<必填>")
  181. * @ApiParams (name="param[description]", type="string", sample="", description="意见建议<必填>")
  182. * @ApiParams (name="param[film_type]", type="string", sample="", description="胶片<必填>")
  183. * @ApiParams (name="param[r_result]", type="string", sample="", description="检查结果<必填>")
  184. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  185. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  186. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功", description="返回消息")
  187. * @ApiReturnParams (name="sessionid", type="object", sample="{}", description="缓存的数据key")
  188. * @ApiReturn (data="
  189. {
  190. 'status': ok,
  191. 'code': '0000',
  192. 'sessionid': 'a17z7a7a8f9g9rh9d89jio',
  193. 'msg' : '保存成功'
  194. }
  195. *")
  196. **/
  197. public function write(){
  198. try{
  199. $sessionid = $_REQUEST['sessionid'];
  200. if(isset($_REQUEST['is_remote']) && $_REQUEST['is_remote'] == 1){
  201. // 是远程写报告 7
  202. $return = Verify::check_role($sessionid,7);
  203. }else{
  204. // 本地写报告权限 2
  205. $return = Verify::check_role($sessionid,2);
  206. }
  207. if($return != 1){
  208. return json_encode(['status'=>'fail','code'=>'1029','msg'=>'没有操作权限']);
  209. }
  210. $param = $_REQUEST['param'];
  211. if(isset($_REQUEST['is_remote']) && $_REQUEST['is_remote'] == 1){
  212. //远程
  213. $status = DB::table('remote_application')->where('id',$param['rid'])->field('report_status')->find();
  214. if($status['report_status'] == 12){
  215. return json_encode(['status'=>'fail','code'=>'1034','msg'=>'报告已被撤回,无法进行保存填写']);
  216. }elseif($status['report_status'] > 6){
  217. return json_encode(['status'=>'fail','code'=>'1034','msg'=>'报告已被保存,无法再次被修改']);
  218. }
  219. }else{
  220. //本地
  221. $status = DB::table('exams')->where('id',$param['id'])->field('exam_status')->find();
  222. if($status['exam_status'] > 6){
  223. return json_encode(['status'=>'fail','code'=>'1034','msg'=>'报告已被保存,无法再次被修改']);
  224. }
  225. }
  226. // Verify::wreportCheck($param);
  227. $doctor = Cache::get($sessionid);
  228. // $remote_app = DB::table('remote_application')->where('exam_id',$param['id'])->field('remote_doctor_id')->find();
  229. // if(!empty($remote_app['remote_doctor_id'])){
  230. // if($remote_app['remote_doctor_id'] != $doctor['id']){
  231. // return json_encode(['status'=>'fail','code'=>'1029','msg'=>'已被指定报告医生,您没有操作权限']);
  232. // }
  233. // }
  234. $this->uuids = new UUIDs();
  235. //初步报告生成
  236. $film_type = isset($param['film_type']) ? $param['film_type'] : '';
  237. // $exam_status = $this->get_exam_status($doctor['id'],7);
  238. $patient_info = array();
  239. $patient_info['id'] = isset($param['pid']) ? $param['pid'] : '';
  240. $patient_info['name'] = isset($param['name']) ? $param['name'] : '';
  241. $patient_info['age'] = isset($param['age']) ? $param['age'] : '';
  242. $patient_info['phone'] = isset($param['phone']) ? $param['phone'] : '';
  243. $patient_info['sex'] = isset($param['sex']) ? $param['sex'] : '';
  244. $patient = DB::table('patient_infos')->where('id',$param['pid'])->update($patient_info);
  245. $info = array();
  246. $info['exam_id'] = $param['id'];
  247. $info['impression'] = isset($param['impression']) ? $param['impression'] : '';
  248. $info['description'] = isset($param['description']) ? $param['description'] : '';
  249. if(isset($param['r_result']) && $param['r_result'] == 'true'){
  250. $info['report_result'] = 2;
  251. }else{
  252. $info['report_result'] = 1;
  253. }
  254. DB::table('exams')->where('id',$param['id'])->update(['film_type'=>$film_type,'phone'=>isset($param['phone']) ? $param['phone'] : '','exam_report'=>$info['report_result']]);
  255. // 报告的id
  256. $report_id = $param['report_id'];
  257. if(isset($_REQUEST['is_remote']) && !empty($_REQUEST['is_remote'])){
  258. // 远程保存
  259. DB::table('remote_application')->where('id',$param['rid'])->update(['report_status'=>'7']);
  260. $info['type'] = 2;
  261. }else{
  262. //本地保存
  263. DB::table('exams')->where('id',$param['id'])->update(['exam_status'=>'7']);
  264. $info['type'] = 1;
  265. }
  266. $info['report_datetime'] = date('Y-m-d H:i:s',time());
  267. $info['report_doctor_id'] = $doctor['id'];
  268. $info['remote_application_id'] = $param['rid'];
  269. if($report_id){
  270. $report_info = DB::table('report')->where('id',$report_id)->find();
  271. $report = DB::table('report')->where('id',$report_id)->update($info);
  272. $id = $report_info['id'];
  273. $cache_key = $doctor['id'].'_'.$report_id;
  274. $rid = $report_id;
  275. }else{
  276. $id = $this->uuids->uuid16();
  277. $info['id'] = $id;
  278. $info['createdAt'] = date('Y-m-d H:i:s',time());
  279. $report = DB::table('report')->insert($info);
  280. $cache_key = $doctor['id'].'_'.$id;
  281. $rid = $id;
  282. }
  283. if(Cache::get($cache_key)){
  284. Cache::rm($cache_key);
  285. }
  286. //写入log日志
  287. log::record('----日志写入----');
  288. $log = array();
  289. $log['id'] = UUIDs::uuid16();
  290. $log['impression'] = isset($param['impression']) ? $param['impression'] : '';
  291. $log['description'] = isset($param['description']) ? $param['description'] : '';
  292. $log['report_id'] = $id;
  293. $log['createdAt'] = date('Y-m-d H:i:s',time());
  294. $log['doctor_id'] = $doctor['id'];
  295. $log['type'] = 1; //写报告
  296. log::record($log);
  297. $report_log = DB::table('report_record')->insert($log);
  298. log::record($report_log);
  299. log::record('----日志写入成功----');
  300. $application = DB::table('remote_application')->where('exam_id',$id)->find();
  301. if($application['req_doctor_id'] == 'c44663d6d3c0b535'){
  302. $tel = '18910184804';
  303. $type = '保存报告';
  304. $content = $application['id'];
  305. send_message::sendSms2Self($tel,$type,$content);
  306. }
  307. $url = 'wechat.pacsonline.cn/wxzskk/uwx/requestWxQrcode?reportId='.$rid;
  308. $info = $this->curl_get($url);
  309. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'保存成功','sessionid'=>$sessionid]);
  310. }catch(\Exception $e){
  311. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  312. }
  313. }
  314. public function get_exam_status($doctorid,$status){
  315. $doctor_class = DB::table('doctor_class')->where('doctor_id',$doctorid)->field('doctor_class')->find();
  316. if(strpos($doctor_class['doctor_class'],'9')){
  317. return 9;
  318. }elseif(strpos($doctor_class['doctor_class'],'8')){
  319. return 8;
  320. }else{
  321. return $status;
  322. }
  323. }
  324. /**
  325. * 公有模板列表
  326. *
  327. * @ApiTitle (公有模板列表)
  328. * @ApiSummary (公有模板列表)
  329. * @ApiSector (远程诊断)
  330. * @ApiMethod (POST)
  331. * @ApiRoute (/inter/writereport/public_template)
  332. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  333. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  334. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  335. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  336. * @ApiParams (name="exam_class", type="string", required=true, description="检查类id")
  337. * @ApiReturnParams (name="info", type="string", required=true, sample="返回成功", description="返回信息")
  338. * @ApiReturn (data="
  339. {
  340. 'info' : ''
  341. }
  342. *")
  343. **/
  344. public function public_template(){
  345. $sessionid = $_REQUEST['sessionid'];
  346. $doctor = Cache::get($sessionid);
  347. $exam = $_REQUEST['exam_class'];
  348. //第一级 公共模板
  349. $info = $this->get_template(1,$doctor['id'],$exam);
  350. return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'sessionid'=>$sessionid]);
  351. }
  352. /**
  353. * 私有模板列表
  354. *
  355. * @ApiTitle (私有模板列表)
  356. * @ApiSummary (私有模板列表)
  357. * @ApiSector (远程诊断)
  358. * @ApiMethod (POST)
  359. * @ApiRoute (/inter/writereport/private_template)
  360. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  361. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  362. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  363. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  364. * @ApiParams (name="exam_class", type="string", required=true, description="检查类id")
  365. * @ApiReturnParams (name="info", type="string", required=true, sample="返回成功", description="返回信息")
  366. * @ApiReturn (data="
  367. {
  368. 'info' : ''
  369. }
  370. *")
  371. **/
  372. public function private_template(){
  373. $sessionid = $_REQUEST['sessionid'];
  374. $doctor = Cache::get($sessionid);
  375. $exam = $_REQUEST['exam_class'];
  376. //私有模板
  377. $info = $this->get_template(2,$doctor['id'],$exam);
  378. return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'sessionid'=>$sessionid]);
  379. }
  380. public function get_template($public,$id,$exam){
  381. // 查询exam_class表
  382. $examCla = DB::table('constant')->where('id',$exam)->field('constant_value as name')->find();
  383. if($public == 1){
  384. $t = DB::table('templates')->where('is_public',$public)->where('exam_class_id',$examCla['name'])->field(['id','title as label','impression','description','parent_id'])->select();
  385. }else{
  386. // 私有模板 添加创建人条件
  387. $t = DB::table('templates')->where('is_public',$public)->where('create_user',$id)->where('exam_class_id',$examCla['name'])->field(['id','title as label','impression','description','parent_id'])->select();
  388. }
  389. if(!$t){
  390. return '';
  391. }
  392. $data = array();
  393. foreach ($t as $k => $v) {
  394. if($v['parent_id'] == '0'){
  395. $data[] = $v;
  396. }
  397. }
  398. foreach ($data as $k => $v) {
  399. unset($data[$k]['impression']);
  400. unset($data[$k]['description']);
  401. unset($data[$k]['parent_id']);
  402. }
  403. foreach ($t as $k => $v) {
  404. foreach ($data as $key => $value) {
  405. if($v['parent_id'] == $value['id']){
  406. unset($t[$k]['parent_id']);
  407. $data[$key]['children'][] = $t[$k];
  408. }
  409. }
  410. }
  411. if($data){
  412. return $data;
  413. }
  414. }
  415. /**
  416. * 确认报告
  417. *
  418. * @ApiTitle (确认报告)
  419. * @ApiSummary (确认报告)
  420. * @ApiSector (远程诊断)
  421. * @ApiMethod (POST)
  422. * @ApiRoute (/inter/writereport/confirm)
  423. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  424. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  425. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  426. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  427. * @ApiParams (name="id", type="string", sample="", description="exams表id值<必填>")
  428. * @ApiParams (name="film_type", type="string", sample="", description="胶片类型<必填>")
  429. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  430. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  431. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功", description="返回消息")
  432. * @ApiReturn (data="
  433. {
  434. 'status': ok,
  435. 'code': '0000',
  436. 'msg': '已确认',
  437. }
  438. *")
  439. **/
  440. public function confirm(){
  441. try{
  442. $is_remote = $_REQUEST['is_remote'];
  443. if($is_remote == 1){
  444. return json_encode(['status'=>'fail','code'=>'1133','msg'=>'远程无法确诊报告']);
  445. }
  446. $sessionid = $_REQUEST['sessionid'];
  447. $doctor = Cache::get($sessionid);
  448. $param = $_REQUEST['param'];
  449. $id = $param['id'];
  450. $report_id = $param['report_id'];
  451. $report_info = DB::table('report')->where('id',$report_id)->find();
  452. if($report_info['type'] == 1){
  453. //本地报告
  454. $status = DB::table('exams')->where('id',$id)->field('exam_status')->find();
  455. if($status['exam_status'] < 8 ){
  456. return json_encode(['status'=>'fail','code'=>'1033','msg'=>'只能确认通过审核的报告']);
  457. }elseif($status['exam_status'] == 9){
  458. return json_encode(['status'=>'fail','code'=>'1034','msg'=>'已经确认过该报告,不可再次确认']);
  459. }
  460. }else{
  461. Message::read($doctor['id'],$report_info['remote_application_id'],4);
  462. //远程
  463. $status = DB::table('remote_application')->where('id',$report_info['remote_application_id'])->field('remote_doctor_id,report_status')->find();
  464. if($status['report_status'] < 8 ){
  465. return json_encode(['status'=>'fail','code'=>'1033','msg'=>'只能确认通过审核的报告']);
  466. }elseif($status['report_status'] == 9){
  467. return json_encode(['status'=>'fail','code'=>'1034','msg'=>'已经确认过该报告,不可再次确认']);
  468. }
  469. }
  470. $rinfo = array();
  471. $rinfo['impression'] = isset($param['impression']) ? $param['impression'] : '';
  472. $rinfo['description'] = isset($param['description']) ? $param['description'] : '';
  473. if(isset($param['r_result']) && $param['r_result'] == 'true'){
  474. $rinfo['report_result'] = 2;
  475. }else{
  476. $rinfo['report_result'] = 1;
  477. }
  478. $rinfo['confirm_datetime'] = date('Y-m-d H:i:s',time());
  479. $rinfo['confirm_doctor_id'] = $doctor['id'];
  480. if($report_info['type'] == 1){
  481. //本地报告确认
  482. DB::table('exams')->where('id',$id)->update(['exam_status'=>'9']);
  483. }else{
  484. Message::read($doctor['id'],$report_info['remote_application_id'],4);
  485. //远程确认
  486. DB::table('remote_application')->where('id',$report_info['remote_application_id'])->update(['report_status'=>'9']);
  487. // 添加messages消息
  488. $t = '您的报告已确认';
  489. $institution = DB::table('institution')->where('id',$doctor['institution_id'])->field('name')->find();
  490. $c = '您的远程诊断申请报告,已被'.$institution['name'].$doctor['realname'].'医师确认';
  491. $d = $status['remote_doctor_id'];
  492. $type = '6';
  493. $url = '';
  494. Message::insert($t,$c,$d,$type,$url,1,$report_info['remote_application_id']);
  495. }
  496. DB::table('exams')->where('id',$id)->update(['film_type'=>$_REQUEST['param']['film_type']]);
  497. DB::table('report')->where('id',$report_id)->update($rinfo);
  498. $cache_key = $doctor['id'].'_'.$report_info['id'];
  499. if(Cache::get($cache_key)){
  500. Cache::rm($cache_key);
  501. }
  502. // 添加 确认log日志
  503. $info = array();
  504. $info['id'] = UUIDs::uuid16();
  505. $info['createdAt'] = date('Y-m-d H:i:s',time());
  506. $info['doctor_id'] = $doctor['id'];
  507. $info['type'] = 3;
  508. $info['report_id'] = $report_id;
  509. DB::table('report_record')->insert($info);
  510. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已确认']);
  511. }catch(\Exception $e){
  512. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  513. }
  514. }
  515. /**
  516. * 审核报告
  517. *
  518. * @ApiTitle (审核报告)
  519. * @ApiSummary (审核报告)
  520. * @ApiSector (远程诊断)
  521. * @ApiMethod (POST)
  522. * @ApiRoute (/inter/writereport/examine)
  523. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  524. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  525. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  526. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  527. * @ApiParams (name="param", type="string", required=true, description="参数json字符串")
  528. * @ApiParams (name="is_remote", type="string", required=true, description="是否为远程列表进入")
  529. * @ApiParams (name="id", type="string", sample="", description="exams表id值<必填>")
  530. * @ApiParams (name="param[impression]", type="string", sample="", description="检查所见<必填>")
  531. * @ApiParams (name="param[description]", type="string", sample="", description="意见建议<必填>")
  532. * @ApiParams (name="param[r_result]", type="string", sample="", description="检查结果<必填>")
  533. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  534. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  535. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功", description="返回消息")
  536. * @ApiReturn (data="
  537. {
  538. 'status': ok,
  539. 'code': '0000',
  540. 'msg': '已审核',
  541. }
  542. *")
  543. **/
  544. public function examine(){
  545. try{
  546. $id = $_REQUEST['id'];
  547. $param = $_REQUEST['param'];
  548. $report_id = $param['report_id'];
  549. $report = DB::table('report')->where('id',$report_id)->find();
  550. $sessionid = $_REQUEST['sessionid'];
  551. $doctor = Cache::get($sessionid);
  552. if(isset($_REQUEST['is_remote']) && $_REQUEST['is_remote'] == 1){
  553. // 是远程审核报告 8
  554. $return = Verify::check_role($sessionid,8);
  555. $status = DB::table('remote_application')->where('id',$report['remote_application_id'])->field('req_doctor_id,report_status')->find();
  556. if($status['report_status'] < 7){
  557. return json_encode(['status'=>'fail','code'=>'1032','msg'=>'只能审核已提交的报告']);
  558. }elseif($status['report_status']>7){
  559. return json_encode(['status'=>'fail','code'=>'1035','msg'=>'报告已通过审核步骤,请勿重复操作']);
  560. }
  561. DB::table('remote_application')->where('id',$report['remote_application_id'])->update(['report_status'=>'8']);
  562. }else{
  563. // 本地审核权限 3
  564. $return = Verify::check_role($sessionid,3);
  565. $status = DB::table('exams')->where('id',$id)->field('exam_status')->find();
  566. if($status['exam_status'] < 7){
  567. return json_encode(['status'=>'fail','code'=>'1032','msg'=>'只能审核已提交的报告']);
  568. }elseif($status['exam_status']>7){
  569. return json_encode(['status'=>'fail','code'=>'1035','msg'=>'报告已通过审核步骤,请勿重复操作']);
  570. }
  571. DB::table('exams')->where('id',$id)->update(['exam_status'=>'8']);
  572. }
  573. $report_info = array();
  574. $report_info['impression'] = isset($param['impression']) ? $param['impression'] : '';
  575. $report_info['description'] = isset($param['description']) ? $param['description'] : '';
  576. if(isset($param['r_result']) && $param['r_result'] == 'true'){
  577. $report_info['report_result'] = 2;
  578. }else{
  579. $report_info['report_result'] = 1;
  580. }
  581. $report_info['review_datetime'] = date('Y-m-d H:i:s',time());
  582. $report_info['review_doctor_id'] = $doctor['id'];
  583. DB::table('report')->where('id',$report['id'])->update($report_info);
  584. $cache_key = $doctor['id'].'_'.$report['id'];
  585. if(Cache::get($cache_key)){
  586. Cache::rm($cache_key);
  587. }
  588. $info = array();
  589. $info['id'] = UUIDs::uuid16();
  590. $info['type'] = 2; //审核
  591. $info['createdAt'] = date('Y-m-d H:i:s',time());
  592. $info['doctor_id'] = $doctor['id'];
  593. $info['impression'] = isset($param['impression']) ? $param['impression'] : '';
  594. $info['description'] = isset($param['description']) ? $param['description'] : '';
  595. $info['report_id'] = $report['id'];
  596. DB::table('report_record')->insert($info);
  597. DB::table('exams')->where('id',$id)->update(['film_type'=>$param['film_type']]);
  598. // 已审核 发送短信
  599. $application = DB::table('remote_application')->where('exam_id',$id)->find();
  600. $dinfo = DB::table('doctors')->where('id',$application['req_doctor_id'])->find();
  601. $d_phone = $dinfo['phone'];
  602. log::record('发短信的手机号为'.$d_phone);
  603. $d_name = $doctor['realname'];
  604. if(isset($_REQUEST['is_remote']) && $_REQUEST['is_remote'] == 1){
  605. if($dinfo['institution_id'] == '22100002' || $dinfo['send_sms'] == 1){ //魏庙下级
  606. $repsone = send_message::sendSms2CompleteReport($d_phone,$d_name);
  607. }
  608. $tel = '18910184804';
  609. $type = '完成并审核报告';
  610. $content =$application['id'];
  611. send_message::sendSms2Self($tel,$type,$content);
  612. }
  613. // 添加messages消息
  614. if(isset($_REQUEST['is_remote']) && $_REQUEST['is_remote'] == 1){
  615. Message::read($doctor['id'],$report['remote_application_id'],3);
  616. $t = '您的远程诊断申请已完成';
  617. $institution = DB::table('institution')->where('id',$doctor['institution_id'])->field('name')->find();
  618. $c = '您的远程诊断申请,已由被'.$institution['name'].$doctor['realname'].'医师完成报告';
  619. $d = $status['req_doctor_id'];
  620. $type = '5';
  621. $exam_class = DB::table('exams')->where('id',$id)->field('exam_class')->find();
  622. $url = Message::url($sessionid,$id,0,$exam_class['exam_class'],$report_id,$report['remote_application_id']);
  623. Message::insert($t,$c,$d,$type,$url,1,$report['remote_application_id']);
  624. }
  625. $url = 'wechat.pacsonline.cn/wxzskk/uwx/requestWxQrcode?reportId='.$report_id;
  626. $info = $this->curl_get($url);
  627. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已审核']);
  628. }catch(\Exception $e){
  629. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  630. }
  631. }
  632. public function curl_get($url){
  633. //初始化
  634. $curl = curl_init();
  635. //设置抓取的url
  636. curl_setopt($curl, CURLOPT_URL, $url);
  637. //设置头文件的信息作为数据流输出
  638. curl_setopt($curl, CURLOPT_HEADER, 0);
  639. //设置获取的信息以文件流的形式返回,而不是直接输出。
  640. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  641. //执行命令
  642. $data = curl_exec($curl);
  643. //关闭URL请求
  644. curl_close($curl);
  645. return $data;
  646. }
  647. /**
  648. * 获取报告权限
  649. *
  650. * @ApiTitle (获取报告权限)
  651. * @ApiSummary (获取报告权限)
  652. * @ApiSector (远程诊断)
  653. * @ApiMethod (POST)
  654. * @ApiRoute (/inter/writereport/getrole)
  655. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  656. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  657. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  658. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  659. * @ApiParams (name="is_remote", type="string", required=true, description="是否为远程列表进入")
  660. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  661. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  662. * @ApiReturnParams (name="info", type="string", required=true, sample="返回成功", description="返回信息")
  663. * @ApiReturn (data="
  664. {
  665. 'status': ok,
  666. 'code': '0000',
  667. 'info': '',
  668. }
  669. *")
  670. **/
  671. public function getrole(){
  672. try{
  673. if(isset($_REQUEST['is_remote']) && $_REQUEST['is_remote'] == 1){
  674. $is_remote = $_REQUEST['is_remote'];
  675. }
  676. $sessionid = $_REQUEST['sessionid'];
  677. $doctor = Cache::get($sessionid);
  678. $dclass = DB::table('doctor_class')->where('doctor_id',$doctor['id'])->field('doctor_class')->find();
  679. $doctor_class = explode(',',$dclass['doctor_class']);
  680. $info = array();
  681. foreach ($doctor_class as $k=>$v) {
  682. switch($v){
  683. case 2: //报告医生
  684. if(isset($is_remote)){
  685. //远程报告
  686. break;
  687. }
  688. $info['bg'] = 1;
  689. break;
  690. case 7: //远程报告医生
  691. if(!isset($is_remote)){
  692. //远程报告
  693. break;
  694. }
  695. $info['bg'] = 1;
  696. break;
  697. case 3: //3审核医生
  698. if(isset($is_remote)){
  699. //远程报告
  700. break;
  701. }
  702. $info['sh'] = 2;
  703. break;
  704. case 8: //远程审核医生
  705. if(!isset($is_remote)){
  706. //远程报告
  707. break;
  708. }
  709. $info['sh'] = 2;
  710. break;
  711. case 4: //确认医生
  712. $info['qr'] = 3;
  713. break;
  714. }
  715. }
  716. return json_encode(['status'=>'ok','code'=>'0000','info'=>$info]);
  717. }catch(\Exception $e){
  718. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  719. }
  720. }
  721. /**
  722. * 获取报告日志
  723. *
  724. * @ApiTitle (获取报告日志)
  725. * @ApiSummary (获取报告日志)
  726. * @ApiSector (远程诊断)
  727. * @ApiMethod (POST)
  728. * @ApiRoute (/inter/writereport/get_report_log)
  729. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  730. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  731. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  732. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  733. * @ApiParams (name="id", type="string", required=true, description="exams表id值")
  734. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  735. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  736. * @ApiReturnParams (name="info", type="string", required=true, sample="返回成功", description="返回信息")
  737. * @ApiReturn (data="
  738. {
  739. 'status': ok,
  740. 'code': '0000',
  741. 'info': '',
  742. }
  743. *")
  744. **/
  745. public function get_report_log(){
  746. try{
  747. $sessionid = $_REQUEST['sessionid'];
  748. $doctor = Cache::get($sessionid);
  749. $id = $_REQUEST['id'];
  750. $exam_id = $_REQUEST['exam_id'];
  751. if(isset($_REQUEST['is_remote']) && !empty($_REQUEST['is_remote'])){
  752. // 远程
  753. $report = DB::table('report')->where('id',$id)->find();
  754. }else{
  755. // 本地
  756. $report = DB::table('report')->where('exam_id',$exam_id)->where('type',1)->find();
  757. }
  758. if(empty($report)){
  759. return json_encode(['status'=>'ok','code'=>'0000','info'=>'','msg'=>'无数据']);
  760. }
  761. $log = DB::table('report_record')->where('doctor_id',$doctor['id'])->where('report_id',$report['id'])->order('createdAt asc,type asc')->select();
  762. foreach ($log as $k => $v) {
  763. $doc = DB::table('doctors')->where('id',$v['doctor_id'])->field('realname')->find();
  764. $log[$k]['doctor_name'] = $doc['realname'];
  765. }
  766. return json_encode(['status'=>'ok','code'=>'0000','info'=>$log]);
  767. }catch(\Exception $e){
  768. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  769. }
  770. }
  771. /**
  772. * 打印报告
  773. *
  774. * @ApiTitle (打印报告)
  775. * @ApiSummary (打印报告)
  776. * @ApiSector (远程诊断)
  777. * @ApiMethod (POST)
  778. * @ApiRoute (/inter/writereport/print_report)
  779. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  780. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  781. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  782. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  783. * @ApiParams (name="id", type="string", required=true, description="exams表id值")
  784. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  785. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  786. * @ApiReturnParams (name="info", type="string", required=true, sample="返回成功", description="返回信息")
  787. * @ApiReturnParams (name="sessionid", type="object", sample="{}", description="缓存的数据key")
  788. * @ApiReturn (data="
  789. {
  790. 'status': ok,
  791. 'code': '0000',
  792. 'sessionid': 'a17z7a7a8f9g9rh9d89jio',
  793. 'info': '',
  794. }
  795. *")
  796. **/
  797. public function print_report(){
  798. try{
  799. $sessionid = $_REQUEST['sessionid'];
  800. $doctor = Cache::get($sessionid);
  801. $id = $_REQUEST['id'];
  802. $report_id = $_REQUEST['report_id'];
  803. $report = DB::table('report')->where('id',$report_id)->field('qr_code,remote_application_id,report_datetime,impression,description,report_doctor_id,review_doctor_id')->find();
  804. $info = array();
  805. // 检查日期 住院号 床号
  806. $exam_info = DB::table('exams')->where('id',$id)->field('id,ext,accession_num,exam_datetime,exam_class,hopitalized_no,bed_no,exam_project,patient_id')->find();
  807. $info['id'] = $exam_info['id'];
  808. $info['ext'] = $exam_info['ext'];
  809. $info['accession_num'] = $exam_info['accession_num'];
  810. if(!empty($exam_info['exam_datetime'])){
  811. $datetime = explode(' ',$exam_info['exam_datetime']);
  812. $info['exam_datetime'] = $datetime[0];
  813. }else{
  814. $info['exam_datetime'] = '';
  815. }
  816. $info['hopitalized_no'] = $exam_info['hopitalized_no'];
  817. $info['bed_no'] = $exam_info['bed_no'];
  818. // 检查项目
  819. $project = DB::table('exam_project')->where('id',$exam_info['exam_project'])->field('name')->find();
  820. $info['project'] = $project['name'];
  821. //检查类
  822. $exam_class = DB::table('constant')->where('id',$exam_info['exam_class'])->field('constant_value')->find();
  823. $info['exam_class'] = $exam_class['constant_value'];
  824. // 病历号 姓名 年龄 性别
  825. $patient_info = DB::table('patient_infos')->where('id',$exam_info['patient_id'])->field('temp_patient_id,name,sex,age')->find();
  826. $remote = DB::table('remote_application')->where('id',$report['remote_application_id'])->field('req_doctor_id')->find();
  827. $info['pnumber'] = $patient_info['temp_patient_id'];
  828. $info['name'] = $patient_info['name'];
  829. $info['sex'] = $patient_info['sex'];
  830. $info['age'] = $patient_info['age'];
  831. // 申请医生
  832. $application_name = DB::table('doctors')->where('id',$remote['req_doctor_id'])->field('realname,department_id')->find();
  833. $info['application_name'] = $application_name['realname'];
  834. // 申请科室
  835. $department = DB::table('department')->where('id',$application_name['department_id'])->field('department_name')->find();
  836. $info['department_name'] = $department['department_name'];
  837. // 报告时间 影像所见 意见建议
  838. if(!empty($report['report_datetime'])){
  839. $datetime1 = explode(' ',$report['report_datetime']);
  840. $info['report_datetime'] = $datetime1[0];
  841. }else{
  842. $info['report_datetime'] = '';
  843. }
  844. $info['report_datetime_xa'] = $report['report_datetime'];
  845. $info['impression'] = $report['impression'];
  846. $info['description'] = $report['description'];
  847. $info['qr_code'] = $report['qr_code'];
  848. // 报告医生
  849. $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find();
  850. $info['report_doctor'] = $report_doctor['realname'];
  851. //审核医生
  852. $review_doctor = DB::table('doctors')->where('id',$report['review_doctor_id'])->field('realname')->find();
  853. $info['review_doctor'] = $review_doctor['realname'];
  854. $hospital = DB::table('institution')->where('id',$doctor['institution_id'])->field('name')->find();
  855. $info['hospital'] = $hospital['name'];
  856. return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'sessionid'=>$sessionid]);
  857. }catch(\Exception $e){
  858. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  859. }
  860. }
  861. /**
  862. * 变更胶片
  863. *
  864. * @ApiTitle (变更胶片)
  865. * @ApiSummary (变更胶片)
  866. * @ApiSector (远程诊断)
  867. * @ApiMethod (POST)
  868. * @ApiRoute (/inter/writereport/change_film)
  869. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  870. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  871. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  872. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  873. * @ApiParams (name="id", type="string", required=true, description="exams表id值")
  874. * @ApiParams (name="film_type", type="string", required=true, description="胶片")
  875. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  876. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  877. * @ApiReturnParams (name="info", type="string", required=true, sample="返回成功", description="返回信息")
  878. * @ApiReturn (data="z
  879. {
  880. 'status': ok,
  881. 'code': '0000',
  882. 'info': '',
  883. }
  884. *")
  885. **/
  886. public function change_film(){
  887. $id = $_REQUEST['id'];
  888. $film = $_REQUEST['film_type'];
  889. DB::table('exams')->where('id',$id)->update(['film_type'=>$film]);
  890. return json_encode(['status'=>'ok','info'=>$film,'code'=>'0000']);
  891. }
  892. /**
  893. * 保存草稿
  894. *
  895. * @ApiTitle (保存草稿)
  896. * @ApiSummary (保存草稿)
  897. * @ApiSector (远程诊断)
  898. * @ApiMethod (POST)
  899. * @ApiRoute (/inter/writereport/draft)
  900. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  901. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  902. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  903. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  904. * @ApiParams (name="param", type="string", required=true, description="参数json字符串")
  905. * @ApiParams (name="param[report_id]", type="string", sample="", description="报告表id值<必填>")
  906. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  907. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  908. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功", description="返回消息")
  909. * @ApiReturn (data="
  910. {
  911. 'status': ok,
  912. 'code': '0000',
  913. 'msg': '保存成功',
  914. }
  915. *")
  916. **/
  917. public function draft(){
  918. $sessionid = $_REQUEST['sessionid'];
  919. $doctor = Cache::get($sessionid);
  920. $param = $_REQUEST['param'];
  921. $report_id = $param['report_id'];
  922. $rinfo = DB::table('report')->where('id',$report_id)->find();
  923. if($rinfo['type'] == 2){
  924. //远程报告
  925. $status = DB::table('remote_application')->where('id',$rinfo['remote_application_id'])->find();
  926. if($status['report_status'] ==6 || $status['report_status'] ==7){
  927. $key = $doctor['id'].'_'.$report_id;
  928. Cache::set($key,$param);
  929. return json_encode(['status'=>'ok','msg'=>'保存成功','code'=>'0000']);
  930. }else{
  931. return json_encode(['status'=>'fail','msg'=>'只能为未保存或者未审核的报告填写草稿','code'=>'0110']);
  932. }
  933. }else {
  934. //本地报告
  935. $status = DB::table('exams')->where('id', $rinfo['exam_id'])->find();
  936. if ($status['exam_status'] == 7 || $status['exam_status'] == 3) {
  937. $key = $doctor['id'] . '_' . $report_id;
  938. Cache::set($key, $param);
  939. return json_encode(['status' => 'ok', 'msg' => '保存成功', 'code' => '0000']);
  940. } else {
  941. return json_encode(['status' => 'fail', 'msg' => '只能为未保存或者未审核的报告填写草稿', 'code' => '0110']);
  942. }
  943. }
  944. }
  945. /**
  946. * XA类型数据获取
  947. *
  948. * @ApiTitle (XA类型数据获取)
  949. * @ApiSummary (XA类型数据获取)
  950. * @ApiSector (远程诊断)
  951. * @ApiMethod (POST)
  952. * @ApiRoute (/inter/writereport/get_rinfo)
  953. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  954. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  955. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  956. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  957. * @ApiParams (name="param", type="string", required=true, description="参数json字符串")
  958. * @ApiParams (name="report_id", type="string", required=true, description="报告表id<必填>")
  959. * @ApiParams (name="id", type="string", sample="", description="exams表id值<必填>")
  960. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  961. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  962. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功", description="返回消息")
  963. * @ApiReturn (data="
  964. {
  965. 'status': ok,
  966. 'code': '0000',
  967. 'msg': '已审核',
  968. }
  969. *")
  970. **/
  971. public function get_rinfo(){
  972. $sessionid = $_REQUEST['sessionid'];
  973. $doctor = Cache::get($sessionid);
  974. $id = $_REQUEST['id'];
  975. $report_id = $_REQUEST['report_id'];
  976. $key = $doctor['id'].'_'.$report_id;
  977. if(Cache::get($key)){
  978. $patient = Cache::get($key);
  979. }else{
  980. $exam = DB::table('exams')->where('id',$id)->field('accession_num,exam_class,patient_id,ext,hopitalized_no,bed_no')->find();
  981. $patient = DB::table('patient_infos')->where('id',$exam['patient_id'])->field(['id','temp_patient_id','name','phone','sex','age'])->find();
  982. $report_info = DB::table('report')->where('id',$report_id)->field('description')->find();
  983. $patient['ext'] = $exam['ext'];
  984. $patient['exam_id'] = $id;
  985. $patient['bed_no'] = $exam['bed_no'];
  986. $patient['accession_num'] = $exam['accession_num'];
  987. $patient['exam_class'] = $exam['exam_class'];
  988. $patient['hopitalized_no'] = $exam['hopitalized_no'];
  989. $patient['description'] = $report_info['description'];
  990. $patient['report_id'] = $report_id;
  991. }
  992. return json_encode(['status'=>'ok','info'=>$patient,'code'=>'0000']);
  993. }
  994. /**
  995. * XA类型保存
  996. *
  997. * @ApiTitle (XA类型保存)
  998. * @ApiSummary (XA类型保存)
  999. * @ApiSector (远程诊断)
  1000. * @ApiMethod (POST)
  1001. * @ApiRoute (/inter/writereport/write_info)
  1002. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  1003. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  1004. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  1005. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  1006. * @ApiParams (name="param", type="string", required=true, description="参数json字符串")
  1007. * @ApiParams (name="is_remote", type="string", required=true, description="是否为远程列表进入")
  1008. * @ApiParams (name="param[id]", type="string", sample="", description="exams表id值<必填>")
  1009. * @ApiParams (name="param[name]", type="string", sample="", description="姓名<必填>")
  1010. * @ApiParams (name="param[sex]", type="string", sample="", description="性别<必填>")
  1011. * @ApiParams (name="param[age]", type="string", sample="", description="年龄<必填>")
  1012. * @ApiParams (name="param[hospital_number]", type="string", sample="", description="住院号<必填>")
  1013. * @ApiParams (name="param[bed_number]", type="string", sample="", description="病床号<必填>")
  1014. * @ApiParams (name="param[ext]", type="string", sample="", description="其他<必填>")
  1015. * @ApiParams (name="param[description]", type="string", sample="", description="意见建议<必填>")
  1016. * @ApiParams (name="param[accession_num]", type="string", sample="", description="检查号<必填>")
  1017. * @ApiParams (name="param[pid]", type="string", sample="", description="患者id<必填>")
  1018. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  1019. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  1020. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功", description="返回消息")
  1021. * @ApiReturn (data="
  1022. {
  1023. 'status': ok,
  1024. 'code': '0000',
  1025. 'msg': '保存成功',
  1026. }
  1027. *")
  1028. **/
  1029. public function write_info(){
  1030. $sessionid = $_REQUEST['sessionid'];
  1031. $doctor = Cache::get($sessionid);
  1032. $is_remote = $_REQUEST['is_remote'];
  1033. $param = $_REQUEST['param'];
  1034. $patient_info['name'] = isset($param['name']) ? $param['name'] : '';
  1035. $patient_info['sex'] = isset($param['sex']) ? $param['sex'] : '';
  1036. $patient_info['age'] = isset($param['age']) ? $param['age'] : '';
  1037. $exam_info['hopitalized_no'] = isset($param['hospital_number']) ? $param['hospital_number'] : '';
  1038. $exam_info['bed_no'] = isset($param['bed_number']) ? $param['bed_number'] : '';
  1039. $exam_info['ext'] = isset($param['ext']) ? $param['ext'] : '';
  1040. $exam_info['accession_num'] = isset($param['accession_num']) ? $param['accession_num'] : '';
  1041. $report['description'] = isset($param['description']) ? $param['description'] : '';
  1042. $report['report_datetime'] = date('Y-m-d H:i:s',time());
  1043. $report['report_doctor_id'] = $doctor['id'];
  1044. DB::table('patient_infos')->where('id',$param['pid'])->update($patient_info);
  1045. DB::table('exams')->where('id',$param['id'])->update($exam_info);
  1046. $rinfo = DB::table('report')->where('exam_id',$param['id'])->find();
  1047. if($rinfo){
  1048. DB::table('report')->where('exam_id',$param['id'])->update($report);
  1049. $rinfo = DB::table('report')->where('exam_id',$param['id'])->find();
  1050. $rid = $rinfo['id'];
  1051. }else{
  1052. $report['id'] = UUIDs::uuid16();
  1053. $report['exam_id'] = $param['id'];
  1054. $report['createdAt'] = date('Y-m-d H:i:s',time());
  1055. DB::table('report')->insert($report);
  1056. $rid = $report['id'];
  1057. }
  1058. $log = array();
  1059. $log['id'] = UUIDs::uuid16();
  1060. $log['impression'] = isset($param['ext']) ? $param['ext'] : '';
  1061. $log['description'] = isset($param['description']) ? $param['description'] : '';
  1062. $log['report_id'] = $rid;
  1063. $log['createdAt'] = date('Y-m-d H:i:s',time());
  1064. $log['doctor_id'] = $doctor['id'];
  1065. $log['type'] = 1; //写报告
  1066. log::record($log);
  1067. $report_log = DB::table('report_record')->insert($log);
  1068. $application = DB::table('remote_application')->where('exam_id',$param['id'])->find();
  1069. if($application['req_doctor_id'] == 'c44663d6d3c0b535'){
  1070. $tel = '18910184804';
  1071. $type = '保存报告';
  1072. $content = $application['id'];
  1073. send_message::sendSms2Self($tel,$type,$content);
  1074. }
  1075. if($is_remote == 1){
  1076. DB::table('remote_application')->where('exam_id',$param['id'])->update(['report_status'=>7]);
  1077. }else{
  1078. DB::table('exams')->where('id',$param['id'])->update(['exam_status'=>7]);
  1079. }
  1080. $url = 'wechat.pacsonline.cn/wxzskk/uwx/requestWxQrcode?reportId='.$rid;
  1081. $info = $this->curl_get($url);
  1082. return json_encode(['status'=>'ok','msg'=>'保存成功','code'=>'0000']);
  1083. }
  1084. /**
  1085. * 获取远程报告列表
  1086. *
  1087. * @ApiTitle (获取远程报告列表)
  1088. * @ApiSummary (获取远程报告列表)
  1089. * @ApiSector (远程诊断)
  1090. * @ApiMethod (POST)
  1091. * @ApiRoute (/inter/writereport/get_report_list)
  1092. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  1093. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  1094. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  1095. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  1096. * @ApiParams (name="param", type="string", required=true, description="参数json字符串")
  1097. * @ApiParams (name="is_remote", type="string", required=true, description="是否为远程列表进入")
  1098. * @ApiParams (name="param[id]", type="string", sample="", description="exams表id值<必填>")
  1099. * @ApiParams (name="param[pid]", type="string", sample="", description="病历号<必填>")
  1100. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  1101. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  1102. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功", description="返回消息")
  1103. * @ApiReturn (data="
  1104. {
  1105. 'status': ok,
  1106. 'code': '0000',
  1107. 'info': '',
  1108. }
  1109. *")
  1110. **/
  1111. public function get_report_list(){
  1112. $sessionid = $_REQUEST['sessionid'];
  1113. // $doctor = Cache::get($sessionid);
  1114. $param = $_REQUEST['param'];
  1115. $rinfo = DB::table('report')->where('exam_id',$param['id'])->where('type','<>',1)->select();
  1116. $pinfo = DB::table('patient_infos')->where('temp_patient_id',$param['pid'])->field('name,temp_patient_id,sex,age,phone')->find();
  1117. $einfo = DB::table('exams')->where('id',$param['id'])->field('exam_class,exam_sub_class,exam_datetime')->find();
  1118. $info = array();
  1119. $arr = array();
  1120. foreach ($rinfo as $k => $v) {
  1121. $remote_info = DB::table('remote_application')->where('id',$v['remote_application_id'])->find();
  1122. if($remote_info['report_status'] == 8 || $remote_info['report_status'] == 9){
  1123. $arr = $v;
  1124. $remote_did = DB::table('doctors')->where('id',$v['report_doctor_id'])->field('realname')->find();
  1125. $arr['report_doctor'] = $remote_did['realname'];
  1126. $review_did = DB::table('doctors')->where('id',$v['review_doctor_id'])->field('realname')->find();
  1127. $arr['review_doctor'] = $review_did['realname'];
  1128. $arr['name'] = $pinfo['name'];
  1129. $arr['pid'] = $pinfo['temp_patient_id'];
  1130. $arr['sex'] = $pinfo['sex'];
  1131. $arr['age'] = $pinfo['age'];
  1132. $arr['phone'] = $pinfo['phone'];
  1133. $arr['exam_class'] = $einfo['exam_class'];
  1134. $arr['exam_sub_class'] = $einfo['exam_sub_class'];
  1135. $arr['exam_datetime'] = $einfo['exam_datetime'];
  1136. $arr['report_status'] = $remote_info['report_status'];
  1137. $info[] = $arr;
  1138. }elseif($remote_info['report_status'] == 4){
  1139. //申请中
  1140. return json_encode(['status'=>'fail','code'=>'0125','msg'=>'申请单正在申请中,暂无医生接收远程报告']);
  1141. }elseif($remote_info['report_status'] == 5){
  1142. // 驳回
  1143. return json_encode(['status'=>'fail','code'=>'0125','msg'=>'申请单已被驳回,没有医生完成远程报告']);
  1144. }elseif($remote_info['report_status'] == 12){
  1145. // 撤回
  1146. return json_encode(['status'=>'fail','code'=>'0125','msg'=>'申请单正在申请中,暂无医生完成远程报告']);
  1147. }elseif($remote_info['report_status'] == ''){
  1148. // 撤回
  1149. return json_encode(['status'=>'fail','code'=>'0126','msg'=>'没有申请单']);
  1150. }else{
  1151. // 其他
  1152. return json_encode(['status'=>'fail','code'=>'0125','msg'=>'申请单还没有被完成,请等待']);
  1153. }
  1154. }
  1155. return json_encode(['status'=>'ok','info'=>$info,'code'=>'0000']);
  1156. }
  1157. }