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. //远程
  462. $status = DB::table('remote_application')->where('id',$report_info['remote_application_id'])->field('remote_doctor_id,report_status')->find();
  463. if($status['report_status'] < 8 ){
  464. return json_encode(['status'=>'fail','code'=>'1033','msg'=>'只能确认通过审核的报告']);
  465. }elseif($status['report_status'] == 9){
  466. return json_encode(['status'=>'fail','code'=>'1034','msg'=>'已经确认过该报告,不可再次确认']);
  467. }
  468. }
  469. $rinfo = array();
  470. $rinfo['impression'] = isset($param['impression']) ? $param['impression'] : '';
  471. $rinfo['description'] = isset($param['description']) ? $param['description'] : '';
  472. if(isset($param['r_result']) && $param['r_result'] == 'true'){
  473. $rinfo['report_result'] = 2;
  474. }else{
  475. $rinfo['report_result'] = 1;
  476. }
  477. $rinfo['confirm_datetime'] = date('Y-m-d H:i:s',time());
  478. $rinfo['confirm_doctor_id'] = $doctor['id'];
  479. if($report_info['type'] == 1){
  480. //本地报告确认
  481. DB::table('exams')->where('id',$id)->update(['exam_status'=>'9']);
  482. }else{
  483. Message::read($doctor['id'],$report_info['remote_application_id'],4);
  484. //远程确认
  485. DB::table('remote_application')->where('id',$report_info['remote_application_id'])->update(['report_status'=>'9']);
  486. // 添加messages消息
  487. $t = '您的报告已确认';
  488. $institution = DB::table('institution')->where('id',$doctor['institution_id'])->field('name')->find();
  489. $c = '您的远程诊断申请报告,已被'.$institution['name'].$doctor['realname'].'医师确认';
  490. $d = $status['remote_doctor_id'];
  491. $type = '6';
  492. $url = '';
  493. Message::insert($t,$c,$d,$type,$url,1,$report_info['remote_application_id']);
  494. }
  495. DB::table('exams')->where('id',$id)->update(['film_type'=>$_REQUEST['param']['film_type']]);
  496. DB::table('report')->where('id',$report_id)->update($rinfo);
  497. $cache_key = $doctor['id'].'_'.$report_info['id'];
  498. if(Cache::get($cache_key)){
  499. Cache::rm($cache_key);
  500. }
  501. // 添加 确认log日志
  502. $info = array();
  503. $info['id'] = UUIDs::uuid16();
  504. $info['createdAt'] = date('Y-m-d H:i:s',time());
  505. $info['doctor_id'] = $doctor['id'];
  506. $info['type'] = 3;
  507. $info['report_id'] = $report_id;
  508. DB::table('report_record')->insert($info);
  509. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已确认']);
  510. }catch(\Exception $e){
  511. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  512. }
  513. }
  514. /**
  515. * 审核报告
  516. *
  517. * @ApiTitle (审核报告)
  518. * @ApiSummary (审核报告)
  519. * @ApiSector (远程诊断)
  520. * @ApiMethod (POST)
  521. * @ApiRoute (/inter/writereport/examine)
  522. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  523. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  524. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  525. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  526. * @ApiParams (name="param", type="string", required=true, description="参数json字符串")
  527. * @ApiParams (name="is_remote", type="string", required=true, description="是否为远程列表进入")
  528. * @ApiParams (name="id", type="string", sample="", description="exams表id值<必填>")
  529. * @ApiParams (name="param[impression]", type="string", sample="", description="检查所见<必填>")
  530. * @ApiParams (name="param[description]", type="string", sample="", description="意见建议<必填>")
  531. * @ApiParams (name="param[r_result]", type="string", sample="", description="检查结果<必填>")
  532. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  533. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  534. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功", description="返回消息")
  535. * @ApiReturn (data="
  536. {
  537. 'status': ok,
  538. 'code': '0000',
  539. 'msg': '已审核',
  540. }
  541. *")
  542. **/
  543. public function examine(){
  544. try{
  545. $id = $_REQUEST['id'];
  546. $param = $_REQUEST['param'];
  547. $report_id = $param['report_id'];
  548. $report = DB::table('report')->where('id',$report_id)->find();
  549. $sessionid = $_REQUEST['sessionid'];
  550. $doctor = Cache::get($sessionid);
  551. if(isset($_REQUEST['is_remote']) && $_REQUEST['is_remote'] == 1){
  552. // 是远程审核报告 8
  553. $return = Verify::check_role($sessionid,8);
  554. $status = DB::table('remote_application')->where('id',$report['remote_application_id'])->field('req_doctor_id,report_status')->find();
  555. if($status['report_status'] < 7){
  556. return json_encode(['status'=>'fail','code'=>'1032','msg'=>'只能审核已提交的报告']);
  557. }elseif($status['report_status']>7){
  558. return json_encode(['status'=>'fail','code'=>'1035','msg'=>'报告已通过审核步骤,请勿重复操作']);
  559. }
  560. DB::table('remote_application')->where('id',$report['remote_application_id'])->update(['report_status'=>'8']);
  561. }else{
  562. // 本地审核权限 3
  563. $return = Verify::check_role($sessionid,3);
  564. $status = DB::table('exams')->where('id',$id)->field('exam_status')->find();
  565. if($status['exam_status'] < 7){
  566. return json_encode(['status'=>'fail','code'=>'1032','msg'=>'只能审核已提交的报告']);
  567. }elseif($status['exam_status']>7){
  568. return json_encode(['status'=>'fail','code'=>'1035','msg'=>'报告已通过审核步骤,请勿重复操作']);
  569. }
  570. DB::table('exams')->where('id',$id)->update(['exam_status'=>'8']);
  571. }
  572. $report_info = array();
  573. $report_info['impression'] = isset($param['impression']) ? $param['impression'] : '';
  574. $report_info['description'] = isset($param['description']) ? $param['description'] : '';
  575. if(isset($param['r_result']) && $param['r_result'] == 'true'){
  576. $report_info['report_result'] = 2;
  577. }else{
  578. $report_info['report_result'] = 1;
  579. }
  580. $report_info['review_datetime'] = date('Y-m-d H:i:s',time());
  581. $report_info['review_doctor_id'] = $doctor['id'];
  582. DB::table('report')->where('id',$report['id'])->update($report_info);
  583. $cache_key = $doctor['id'].'_'.$report['id'];
  584. if(Cache::get($cache_key)){
  585. Cache::rm($cache_key);
  586. }
  587. $info = array();
  588. $info['id'] = UUIDs::uuid16();
  589. $info['type'] = 2; //审核
  590. $info['createdAt'] = date('Y-m-d H:i:s',time());
  591. $info['doctor_id'] = $doctor['id'];
  592. $info['impression'] = isset($param['impression']) ? $param['impression'] : '';
  593. $info['description'] = isset($param['description']) ? $param['description'] : '';
  594. $info['report_id'] = $report['id'];
  595. DB::table('report_record')->insert($info);
  596. DB::table('exams')->where('id',$id)->update(['film_type'=>$param['film_type']]);
  597. // 已审核 发送短信
  598. $application = DB::table('remote_application')->where('exam_id',$id)->find();
  599. $dinfo = DB::table('doctors')->where('id',$application['req_doctor_id'])->find();
  600. $d_phone = $dinfo['phone'];
  601. log::record('发短信的手机号为'.$d_phone);
  602. $d_name = $doctor['realname'];
  603. if(isset($_REQUEST['is_remote']) && $_REQUEST['is_remote'] == 1){
  604. if($dinfo['institution_id'] == '22100002' || $dinfo['send_sms'] == 1){ //魏庙下级
  605. $repsone = send_message::sendSms2CompleteReport($d_phone,$d_name);
  606. }
  607. $tel = '18910184804';
  608. $type = '完成并审核报告';
  609. $content =$application['id'];
  610. send_message::sendSms2Self($tel,$type,$content);
  611. }
  612. // 添加messages消息
  613. if(isset($_REQUEST['is_remote']) && $_REQUEST['is_remote'] == 1){
  614. Message::read($doctor['id'],$report['remote_application_id'],3);
  615. $t = '您的远程诊断申请已完成';
  616. $institution = DB::table('institution')->where('id',$doctor['institution_id'])->field('name')->find();
  617. $c = '您的远程诊断申请,已由被'.$institution['name'].$doctor['realname'].'医师完成报告';
  618. $d = $status['req_doctor_id'];
  619. $type = '5';
  620. $exam_class = DB::table('exams')->where('id',$id)->field('exam_class')->find();
  621. $url = Message::url($sessionid,$id,0,$exam_class['exam_class'],$report_id,$report['remote_application_id']);
  622. Message::insert($t,$c,$d,$type,$url,1,$report['remote_application_id']);
  623. }
  624. $url = 'wechat.pacsonline.cn/wxzskk/uwx/requestWxQrcode?reportId='.$report_id;
  625. $info = $this->curl_get($url);
  626. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已审核']);
  627. }catch(\Exception $e){
  628. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  629. }
  630. }
  631. public function curl_get($url){
  632. //初始化
  633. $curl = curl_init();
  634. //设置抓取的url
  635. curl_setopt($curl, CURLOPT_URL, $url);
  636. //设置头文件的信息作为数据流输出
  637. curl_setopt($curl, CURLOPT_HEADER, 0);
  638. //设置获取的信息以文件流的形式返回,而不是直接输出。
  639. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  640. //执行命令
  641. $data = curl_exec($curl);
  642. //关闭URL请求
  643. curl_close($curl);
  644. return $data;
  645. }
  646. /**
  647. * 获取报告权限
  648. *
  649. * @ApiTitle (获取报告权限)
  650. * @ApiSummary (获取报告权限)
  651. * @ApiSector (远程诊断)
  652. * @ApiMethod (POST)
  653. * @ApiRoute (/inter/writereport/getrole)
  654. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  655. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  656. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  657. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  658. * @ApiParams (name="is_remote", type="string", required=true, description="是否为远程列表进入")
  659. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  660. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  661. * @ApiReturnParams (name="info", type="string", required=true, sample="返回成功", description="返回信息")
  662. * @ApiReturn (data="
  663. {
  664. 'status': ok,
  665. 'code': '0000',
  666. 'info': '',
  667. }
  668. *")
  669. **/
  670. public function getrole(){
  671. try{
  672. if(isset($_REQUEST['is_remote']) && $_REQUEST['is_remote'] == 1){
  673. $is_remote = $_REQUEST['is_remote'];
  674. }
  675. $sessionid = $_REQUEST['sessionid'];
  676. $doctor = Cache::get($sessionid);
  677. $dclass = DB::table('doctor_class')->where('doctor_id',$doctor['id'])->field('doctor_class')->find();
  678. $doctor_class = explode(',',$dclass['doctor_class']);
  679. $info = array();
  680. foreach ($doctor_class as $k=>$v) {
  681. switch($v){
  682. case 2: //报告医生
  683. if(isset($is_remote)){
  684. //远程报告
  685. break;
  686. }
  687. $info['bg'] = 1;
  688. break;
  689. case 7: //远程报告医生
  690. if(!isset($is_remote)){
  691. //远程报告
  692. break;
  693. }
  694. $info['bg'] = 1;
  695. break;
  696. case 3: //3审核医生
  697. if(isset($is_remote)){
  698. //远程报告
  699. break;
  700. }
  701. $info['sh'] = 2;
  702. break;
  703. case 8: //远程审核医生
  704. if(!isset($is_remote)){
  705. //远程报告
  706. break;
  707. }
  708. $info['sh'] = 2;
  709. break;
  710. case 4: //确认医生
  711. $info['qr'] = 3;
  712. break;
  713. }
  714. }
  715. return json_encode(['status'=>'ok','code'=>'0000','info'=>$info]);
  716. }catch(\Exception $e){
  717. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  718. }
  719. }
  720. /**
  721. * 获取报告日志
  722. *
  723. * @ApiTitle (获取报告日志)
  724. * @ApiSummary (获取报告日志)
  725. * @ApiSector (远程诊断)
  726. * @ApiMethod (POST)
  727. * @ApiRoute (/inter/writereport/get_report_log)
  728. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  729. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  730. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  731. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  732. * @ApiParams (name="id", type="string", required=true, description="exams表id值")
  733. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  734. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  735. * @ApiReturnParams (name="info", type="string", required=true, sample="返回成功", description="返回信息")
  736. * @ApiReturn (data="
  737. {
  738. 'status': ok,
  739. 'code': '0000',
  740. 'info': '',
  741. }
  742. *")
  743. **/
  744. public function get_report_log(){
  745. try{
  746. $sessionid = $_REQUEST['sessionid'];
  747. $doctor = Cache::get($sessionid);
  748. $id = $_REQUEST['id'];
  749. $exam_id = $_REQUEST['exam_id'];
  750. if(isset($_REQUEST['is_remote']) && !empty($_REQUEST['is_remote'])){
  751. // 远程
  752. $report = DB::table('report')->where('id',$id)->find();
  753. }else{
  754. // 本地
  755. $report = DB::table('report')->where('exam_id',$exam_id)->where('type',1)->find();
  756. }
  757. if(empty($report)){
  758. return json_encode(['status'=>'ok','code'=>'0000','info'=>'','msg'=>'无数据']);
  759. }
  760. $log = DB::table('report_record')->where('doctor_id',$doctor['id'])->where('report_id',$report['id'])->order('createdAt asc,type asc')->select();
  761. foreach ($log as $k => $v) {
  762. $doc = DB::table('doctors')->where('id',$v['doctor_id'])->field('realname')->find();
  763. $log[$k]['doctor_name'] = $doc['realname'];
  764. }
  765. return json_encode(['status'=>'ok','code'=>'0000','info'=>$log]);
  766. }catch(\Exception $e){
  767. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  768. }
  769. }
  770. /**
  771. * 打印报告
  772. *
  773. * @ApiTitle (打印报告)
  774. * @ApiSummary (打印报告)
  775. * @ApiSector (远程诊断)
  776. * @ApiMethod (POST)
  777. * @ApiRoute (/inter/writereport/print_report)
  778. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  779. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  780. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  781. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  782. * @ApiParams (name="id", type="string", required=true, description="exams表id值")
  783. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  784. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  785. * @ApiReturnParams (name="info", type="string", required=true, sample="返回成功", description="返回信息")
  786. * @ApiReturnParams (name="sessionid", type="object", sample="{}", description="缓存的数据key")
  787. * @ApiReturn (data="
  788. {
  789. 'status': ok,
  790. 'code': '0000',
  791. 'sessionid': 'a17z7a7a8f9g9rh9d89jio',
  792. 'info': '',
  793. }
  794. *")
  795. **/
  796. public function print_report(){
  797. try{
  798. $sessionid = $_REQUEST['sessionid'];
  799. $doctor = Cache::get($sessionid);
  800. $id = $_REQUEST['id'];
  801. $report_id = $_REQUEST['report_id'];
  802. $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();
  803. $info = array();
  804. // 检查日期 住院号 床号
  805. $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();
  806. $info['id'] = $exam_info['id'];
  807. $info['ext'] = $exam_info['ext'];
  808. $info['accession_num'] = $exam_info['accession_num'];
  809. if(!empty($exam_info['exam_datetime'])){
  810. $datetime = explode(' ',$exam_info['exam_datetime']);
  811. $info['exam_datetime'] = $datetime[0];
  812. }else{
  813. $info['exam_datetime'] = '';
  814. }
  815. $info['hopitalized_no'] = $exam_info['hopitalized_no'];
  816. $info['bed_no'] = $exam_info['bed_no'];
  817. // 检查项目
  818. $project = DB::table('exam_project')->where('id',$exam_info['exam_project'])->field('name')->find();
  819. $info['project'] = $project['name'];
  820. //检查类
  821. $exam_class = DB::table('constant')->where('id',$exam_info['exam_class'])->field('constant_value')->find();
  822. $info['exam_class'] = $exam_class['constant_value'];
  823. // 病历号 姓名 年龄 性别
  824. $patient_info = DB::table('patient_infos')->where('id',$exam_info['patient_id'])->field('temp_patient_id,name,sex,age')->find();
  825. $remote = DB::table('remote_application')->where('id',$report['remote_application_id'])->field('req_doctor_id')->find();
  826. $info['pnumber'] = $patient_info['temp_patient_id'];
  827. $info['name'] = $patient_info['name'];
  828. $info['sex'] = $patient_info['sex'];
  829. $info['age'] = $patient_info['age'];
  830. // 申请医生
  831. $application_name = DB::table('doctors')->where('id',$remote['req_doctor_id'])->field('realname,department_id')->find();
  832. $info['application_name'] = $application_name['realname'];
  833. // 申请科室
  834. $department = DB::table('department')->where('id',$application_name['department_id'])->field('department_name')->find();
  835. $info['department_name'] = $department['department_name'];
  836. // 报告时间 影像所见 意见建议
  837. if(!empty($report['report_datetime'])){
  838. $datetime1 = explode(' ',$report['report_datetime']);
  839. $info['report_datetime'] = $datetime1[0];
  840. }else{
  841. $info['report_datetime'] = '';
  842. }
  843. $info['report_datetime_xa'] = $report['report_datetime'];
  844. $info['impression'] = $report['impression'];
  845. $info['description'] = $report['description'];
  846. $info['qr_code'] = $report['qr_code'];
  847. // 报告医生
  848. $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find();
  849. $info['report_doctor'] = $report_doctor['realname'];
  850. //审核医生
  851. $review_doctor = DB::table('doctors')->where('id',$report['review_doctor_id'])->field('realname')->find();
  852. $info['review_doctor'] = $review_doctor['realname'];
  853. $hospital = DB::table('institution')->where('id',$doctor['institution_id'])->field('name')->find();
  854. $info['hospital'] = $hospital['name'];
  855. return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'sessionid'=>$sessionid]);
  856. }catch(\Exception $e){
  857. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  858. }
  859. }
  860. /**
  861. * 变更胶片
  862. *
  863. * @ApiTitle (变更胶片)
  864. * @ApiSummary (变更胶片)
  865. * @ApiSector (远程诊断)
  866. * @ApiMethod (POST)
  867. * @ApiRoute (/inter/writereport/change_film)
  868. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  869. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  870. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  871. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  872. * @ApiParams (name="id", type="string", required=true, description="exams表id值")
  873. * @ApiParams (name="film_type", type="string", required=true, description="胶片")
  874. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  875. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  876. * @ApiReturnParams (name="info", type="string", required=true, sample="返回成功", description="返回信息")
  877. * @ApiReturn (data="z
  878. {
  879. 'status': ok,
  880. 'code': '0000',
  881. 'info': '',
  882. }
  883. *")
  884. **/
  885. public function change_film(){
  886. $id = $_REQUEST['id'];
  887. $film = $_REQUEST['film_type'];
  888. DB::table('exams')->where('id',$id)->update(['film_type'=>$film]);
  889. return json_encode(['status'=>'ok','info'=>$film,'code'=>'0000']);
  890. }
  891. /**
  892. * 保存草稿
  893. *
  894. * @ApiTitle (保存草稿)
  895. * @ApiSummary (保存草稿)
  896. * @ApiSector (远程诊断)
  897. * @ApiMethod (POST)
  898. * @ApiRoute (/inter/writereport/draft)
  899. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  900. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  901. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  902. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  903. * @ApiParams (name="param", type="string", required=true, description="参数json字符串")
  904. * @ApiParams (name="param[report_id]", type="string", sample="", description="报告表id值<必填>")
  905. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  906. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  907. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功", description="返回消息")
  908. * @ApiReturn (data="
  909. {
  910. 'status': ok,
  911. 'code': '0000',
  912. 'msg': '保存成功',
  913. }
  914. *")
  915. **/
  916. public function draft(){
  917. $sessionid = $_REQUEST['sessionid'];
  918. $doctor = Cache::get($sessionid);
  919. $param = $_REQUEST['param'];
  920. $report_id = $param['report_id'];
  921. $rinfo = DB::table('report')->where('id',$report_id)->find();
  922. if($rinfo['type'] == 2){
  923. //远程报告
  924. $status = DB::table('remote_application')->where('id',$rinfo['remote_application_id'])->find();
  925. if($status['report_status'] ==6 || $status['report_status'] ==7){
  926. $key = $doctor['id'].'_'.$report_id;
  927. Cache::set($key,$param);
  928. return json_encode(['status'=>'ok','msg'=>'保存成功','code'=>'0000']);
  929. }else{
  930. return json_encode(['status'=>'fail','msg'=>'只能为未保存或者未审核的报告填写草稿','code'=>'0110']);
  931. }
  932. }else {
  933. //本地报告
  934. $status = DB::table('exams')->where('id', $rinfo['exam_id'])->find();
  935. if ($status['exam_status'] == 7 || $status['exam_status'] == 3) {
  936. $key = $doctor['id'] . '_' . $report_id;
  937. Cache::set($key, $param);
  938. return json_encode(['status' => 'ok', 'msg' => '保存成功', 'code' => '0000']);
  939. } else {
  940. return json_encode(['status' => 'fail', 'msg' => '只能为未保存或者未审核的报告填写草稿', 'code' => '0110']);
  941. }
  942. }
  943. }
  944. /**
  945. * XA类型数据获取
  946. *
  947. * @ApiTitle (XA类型数据获取)
  948. * @ApiSummary (XA类型数据获取)
  949. * @ApiSector (远程诊断)
  950. * @ApiMethod (POST)
  951. * @ApiRoute (/inter/writereport/get_rinfo)
  952. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  953. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  954. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  955. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  956. * @ApiParams (name="param", type="string", required=true, description="参数json字符串")
  957. * @ApiParams (name="report_id", type="string", required=true, description="报告表id<必填>")
  958. * @ApiParams (name="id", type="string", sample="", description="exams表id值<必填>")
  959. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  960. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  961. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功", description="返回消息")
  962. * @ApiReturn (data="
  963. {
  964. 'status': ok,
  965. 'code': '0000',
  966. 'msg': '已审核',
  967. }
  968. *")
  969. **/
  970. public function get_rinfo(){
  971. $sessionid = $_REQUEST['sessionid'];
  972. $doctor = Cache::get($sessionid);
  973. $id = $_REQUEST['id'];
  974. $report_id = $_REQUEST['report_id'];
  975. $key = $doctor['id'].'_'.$report_id;
  976. if(Cache::get($key)){
  977. $patient = Cache::get($key);
  978. }else{
  979. $exam = DB::table('exams')->where('id',$id)->field('accession_num,exam_class,patient_id,ext,hopitalized_no,bed_no')->find();
  980. $patient = DB::table('patient_infos')->where('id',$exam['patient_id'])->field(['id','temp_patient_id','name','phone','sex','age'])->find();
  981. $report_info = DB::table('report')->where('id',$report_id)->field('description')->find();
  982. $patient['ext'] = $exam['ext'];
  983. $patient['exam_id'] = $id;
  984. $patient['bed_no'] = $exam['bed_no'];
  985. $patient['accession_num'] = $exam['accession_num'];
  986. $patient['exam_class'] = $exam['exam_class'];
  987. $patient['hopitalized_no'] = $exam['hopitalized_no'];
  988. $patient['description'] = $report_info['description'];
  989. $patient['report_id'] = $report_id;
  990. }
  991. return json_encode(['status'=>'ok','info'=>$patient,'code'=>'0000']);
  992. }
  993. /**
  994. * XA类型保存
  995. *
  996. * @ApiTitle (XA类型保存)
  997. * @ApiSummary (XA类型保存)
  998. * @ApiSector (远程诊断)
  999. * @ApiMethod (POST)
  1000. * @ApiRoute (/inter/writereport/write_info)
  1001. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  1002. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  1003. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  1004. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  1005. * @ApiParams (name="param", type="string", required=true, description="参数json字符串")
  1006. * @ApiParams (name="is_remote", type="string", required=true, description="是否为远程列表进入")
  1007. * @ApiParams (name="param[id]", type="string", sample="", description="exams表id值<必填>")
  1008. * @ApiParams (name="param[name]", type="string", sample="", description="姓名<必填>")
  1009. * @ApiParams (name="param[sex]", type="string", sample="", description="性别<必填>")
  1010. * @ApiParams (name="param[age]", type="string", sample="", description="年龄<必填>")
  1011. * @ApiParams (name="param[hospital_number]", type="string", sample="", description="住院号<必填>")
  1012. * @ApiParams (name="param[bed_number]", type="string", sample="", description="病床号<必填>")
  1013. * @ApiParams (name="param[ext]", type="string", sample="", description="其他<必填>")
  1014. * @ApiParams (name="param[description]", type="string", sample="", description="意见建议<必填>")
  1015. * @ApiParams (name="param[accession_num]", type="string", sample="", description="检查号<必填>")
  1016. * @ApiParams (name="param[pid]", type="string", sample="", description="患者id<必填>")
  1017. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  1018. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  1019. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功", description="返回消息")
  1020. * @ApiReturn (data="
  1021. {
  1022. 'status': ok,
  1023. 'code': '0000',
  1024. 'msg': '保存成功',
  1025. }
  1026. *")
  1027. **/
  1028. public function write_info(){
  1029. $sessionid = $_REQUEST['sessionid'];
  1030. $doctor = Cache::get($sessionid);
  1031. $is_remote = $_REQUEST['is_remote'];
  1032. $param = $_REQUEST['param'];
  1033. $patient_info['name'] = isset($param['name']) ? $param['name'] : '';
  1034. $patient_info['sex'] = isset($param['sex']) ? $param['sex'] : '';
  1035. $patient_info['age'] = isset($param['age']) ? $param['age'] : '';
  1036. $exam_info['hopitalized_no'] = isset($param['hospital_number']) ? $param['hospital_number'] : '';
  1037. $exam_info['bed_no'] = isset($param['bed_number']) ? $param['bed_number'] : '';
  1038. $exam_info['ext'] = isset($param['ext']) ? $param['ext'] : '';
  1039. $exam_info['accession_num'] = isset($param['accession_num']) ? $param['accession_num'] : '';
  1040. $report['description'] = isset($param['description']) ? $param['description'] : '';
  1041. $report['report_datetime'] = date('Y-m-d H:i:s',time());
  1042. $report['report_doctor_id'] = $doctor['id'];
  1043. DB::table('patient_infos')->where('id',$param['pid'])->update($patient_info);
  1044. DB::table('exams')->where('id',$param['id'])->update($exam_info);
  1045. $rinfo = DB::table('report')->where('exam_id',$param['id'])->find();
  1046. if($rinfo){
  1047. DB::table('report')->where('exam_id',$param['id'])->update($report);
  1048. $rinfo = DB::table('report')->where('exam_id',$param['id'])->find();
  1049. $rid = $rinfo['id'];
  1050. }else{
  1051. $report['id'] = UUIDs::uuid16();
  1052. $report['exam_id'] = $param['id'];
  1053. $report['createdAt'] = date('Y-m-d H:i:s',time());
  1054. DB::table('report')->insert($report);
  1055. $rid = $report['id'];
  1056. }
  1057. $log = array();
  1058. $log['id'] = UUIDs::uuid16();
  1059. $log['impression'] = isset($param['ext']) ? $param['ext'] : '';
  1060. $log['description'] = isset($param['description']) ? $param['description'] : '';
  1061. $log['report_id'] = $rid;
  1062. $log['createdAt'] = date('Y-m-d H:i:s',time());
  1063. $log['doctor_id'] = $doctor['id'];
  1064. $log['type'] = 1; //写报告
  1065. log::record($log);
  1066. $report_log = DB::table('report_record')->insert($log);
  1067. $application = DB::table('remote_application')->where('exam_id',$param['id'])->find();
  1068. if($application['req_doctor_id'] == 'c44663d6d3c0b535'){
  1069. $tel = '18910184804';
  1070. $type = '保存报告';
  1071. $content = $application['id'];
  1072. send_message::sendSms2Self($tel,$type,$content);
  1073. }
  1074. if($is_remote == 1){
  1075. DB::table('remote_application')->where('exam_id',$param['id'])->update(['report_status'=>7]);
  1076. }else{
  1077. DB::table('exams')->where('id',$param['id'])->update(['exam_status'=>7]);
  1078. }
  1079. $url = 'wechat.pacsonline.cn/wxzskk/uwx/requestWxQrcode?reportId='.$rid;
  1080. $info = $this->curl_get($url);
  1081. return json_encode(['status'=>'ok','msg'=>'保存成功','code'=>'0000']);
  1082. }
  1083. /**
  1084. * 获取远程报告列表
  1085. *
  1086. * @ApiTitle (获取远程报告列表)
  1087. * @ApiSummary (获取远程报告列表)
  1088. * @ApiSector (远程诊断)
  1089. * @ApiMethod (POST)
  1090. * @ApiRoute (/inter/writereport/get_report_list)
  1091. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  1092. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  1093. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  1094. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  1095. * @ApiParams (name="param", type="string", required=true, description="参数json字符串")
  1096. * @ApiParams (name="is_remote", type="string", required=true, description="是否为远程列表进入")
  1097. * @ApiParams (name="param[id]", type="string", sample="", description="exams表id值<必填>")
  1098. * @ApiParams (name="param[pid]", type="string", sample="", description="病历号<必填>")
  1099. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  1100. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  1101. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功", description="返回消息")
  1102. * @ApiReturn (data="
  1103. {
  1104. 'status': ok,
  1105. 'code': '0000',
  1106. 'info': '',
  1107. }
  1108. *")
  1109. **/
  1110. public function get_report_list(){
  1111. $sessionid = $_REQUEST['sessionid'];
  1112. $doctor = Cache::get($sessionid);
  1113. $param = $_REQUEST['param'];
  1114. $rinfo = DB::table('report')->where('exam_id',$param['id'])->where('type','<>',1)->select();
  1115. $pinfo = DB::table('patient_infos')->where('temp_patient_id',$param['pid'])->field('name,temp_patient_id,sex,age,phone')->find();
  1116. $einfo = DB::table('exams')->where('id',$param['id'])->field('exam_class,exam_sub_class,exam_datetime')->find();
  1117. $info = array();
  1118. $arr = array();
  1119. foreach ($rinfo as $k => $v) {
  1120. $remote_info = DB::table('remote_application')->where('id',$v['remote_application_id'])->find();
  1121. Message::read($doctor['id'],$remote_info['remote_application_id'],4);
  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. }