|
@@ -0,0 +1,1143 @@
|
|
|
+<?php
|
|
|
+namespace app\inter\controller;
|
|
|
+
|
|
|
+use think\Controller;
|
|
|
+use think\Db;
|
|
|
+use think\Session;
|
|
|
+use app\common\library\UUIDs;
|
|
|
+use think\Cache;
|
|
|
+use think\Log;
|
|
|
+use app\common\library\Verify;
|
|
|
+use think\File;
|
|
|
+use app\common\library\send_message;
|
|
|
+use app\common\library\Message;
|
|
|
+use app\inter\service\WechatService;
|
|
|
+
|
|
|
+class Application extends Base
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 发起远程申请
|
|
|
+ *
|
|
|
+ * @ApiTitle (发起远程申请)
|
|
|
+ * @ApiSummary (发起远程申请)
|
|
|
+ * @ApiSector (远程诊断)
|
|
|
+ * @ApiMethod (POST)
|
|
|
+ * @ApiRoute (/inter/application/index)
|
|
|
+ * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
|
|
|
+ * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
|
|
|
+ * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
|
|
|
+ * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
|
|
|
+ * @ApiParams (name="param", type="string", required=true, description="参数json字符串")
|
|
|
+ * @ApiParams (name="is_remote", type="string", required=true, description="参数json字符串")
|
|
|
+ * @ApiParams (name="param[id]", type="string", sample="", description="预约登记exams表id值<必填>")
|
|
|
+ * @ApiParams (name="param[rid]", type="string", sample="", description="远程申请表id值<远程列表进入必填>")
|
|
|
+ * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
|
|
|
+ * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
|
|
|
+ * @ApiReturnParams (name="info", type="string", required=true, sample="返回成功", description="返回信息")
|
|
|
+ * @ApiReturnParams (name="is_remote", type="object", sample="{}", description="是否为远程诊断进入")
|
|
|
+ * @ApiReturnParams (name="sessionid", type="object", sample="{}", description="缓存的数据key")
|
|
|
+ * @ApiReturn (data="
|
|
|
+{
|
|
|
+'status': ok,
|
|
|
+'code': '0000',
|
|
|
+'sessionid': 'a17z7a7a8f9g9rh9d89jio',
|
|
|
+'is_remote': 1,
|
|
|
+'info' : '',
|
|
|
+'rid' : ''
|
|
|
+}
|
|
|
+ *")
|
|
|
+ **/
|
|
|
+ public function index(){
|
|
|
+ try{
|
|
|
+ $sessionid = $_REQUEST['sessionid'];
|
|
|
+ $param = $_REQUEST['param'];
|
|
|
+ $id = $param['id'];
|
|
|
+ $is_remote = 0;
|
|
|
+ if(isset($_REQUEST['is_remote']) && $_REQUEST['is_remote']==1){
|
|
|
+ $is_remote = 1;
|
|
|
+ }
|
|
|
+ $info = DB::table('exams')->where('id',$id)->field('id,urgent,study_id,patient_id,register_datetime,exam_class,exam_sub_class,exam_project,device,exam_datetime,exam_status')->find();
|
|
|
+ $exam_class = DB::table('constant')->where('id',$info['exam_class'])->field('constant_value')->find();
|
|
|
+ $exam_subclass = DB::table('exam_subclass')->where('id',$info['exam_sub_class'])->cache(300)->find();
|
|
|
+ $exam_project = DB::table('exam_project')->where('id',$info['exam_project'])->cache(300)->find();
|
|
|
+ $device = DB::table('device')->where('id',$info['device'])->cache(300)->find();
|
|
|
+ $info['exam_class_name'] = $exam_class['constant_value'];
|
|
|
+ $info['exam_subclass_name'] = $exam_subclass['name'];
|
|
|
+ $info['exam_project_name'] = $exam_project['name'];
|
|
|
+ $info['device_name'] = $device['name'];
|
|
|
+ $patient_info = DB::table('patient_infos')->where('id',$info['patient_id'])->field(['temp_patient_id','id','name','sex','age','birthday', 'phone'])->find();
|
|
|
+ $info['pid'] = $patient_info['id'];
|
|
|
+ $info['temp_patient_id'] = $patient_info['temp_patient_id'];
|
|
|
+ $info['name'] = $patient_info['name'];
|
|
|
+ $info['sex'] = $patient_info['sex'];
|
|
|
+ $info['age'] = $patient_info['age'];
|
|
|
+ $info['phone'] = $patient_info['phone'];
|
|
|
+ if(!empty($patient_info['birthday'])){
|
|
|
+ $info['birthday'] = $patient_info['birthday'];
|
|
|
+ }
|
|
|
+ $doctor = Cache::get($sessionid);
|
|
|
+ $institution_id = $doctor['institution_id'];
|
|
|
+ $hospital = DB::table('institution')->where('id',$institution_id)->find();
|
|
|
+ $is_pay = $hospital['is_pay'];
|
|
|
+ $parent_name = array();
|
|
|
+
|
|
|
+ // 特殊机构
|
|
|
+ $special_doctors = Db::table('special_contact')
|
|
|
+ ->alias("sc")
|
|
|
+ ->join('doctors d', 'sc.did = d.id')
|
|
|
+ ->join('institution i', 'sc.hid = i.id')
|
|
|
+ ->join('special_remote sr', 'sc.sid = sr.id')
|
|
|
+ ->where('sr.status', 1)
|
|
|
+ ->where('sc.status', 1)
|
|
|
+ ->order('sr.sort asc')
|
|
|
+ ->order('sc.sort asc')
|
|
|
+ ->field('sc.hid, sc.did, sc.id, sc.cost, sc.describe, sr.id as sid, sr.name, sr.color, d.realname as dname, i.name as hname')
|
|
|
+ ->select();
|
|
|
+ // 特殊机构
|
|
|
+ if(!empty($special_doctors)) {
|
|
|
+ $special_hospitals = array();
|
|
|
+ foreach($special_doctors as $v) {
|
|
|
+ if(!isset($special_doctors[$v['hid']])){
|
|
|
+ $super_hospitals[$v['hid']] = [
|
|
|
+ "doctor" => [
|
|
|
+ [
|
|
|
+ "id" => $v['did'],
|
|
|
+ "is_admin" => '0',
|
|
|
+ "realname" => $v['dname'],
|
|
|
+ "describe" => $v['describe'],
|
|
|
+ "hname" => $v['hname'],
|
|
|
+ "scid" => $v['id']
|
|
|
+ ]
|
|
|
+ ],
|
|
|
+ "id" => $v['hid'],
|
|
|
+ "name" => $v['name'],
|
|
|
+ "color" => $v['color'],
|
|
|
+ "sid" => $v['sid']
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ $super_hospitals[$v['hid']]['doctor'][] = [
|
|
|
+ "id" => $v['did'],
|
|
|
+ "is_admin" => '0',
|
|
|
+ "realname" => $v['dname'],
|
|
|
+ "describe" => $v['describe'],
|
|
|
+ "hname" => $v['hname'],
|
|
|
+ "scid" => $v['id']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach($super_hospitals as $v) {
|
|
|
+ $parent_name[] = $v;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // select rc1.hospital_id, rc1.super_hospital_id, rc1.hospital_name, rc1.super_hospital_name, rc1.pay_type, rc2.super_doctor_id, rc2.super_doctor_name, rc2.exam_class from remote_contact rc1 join remote_cost rc2 on rc1.hospital_id = rc2.hospital_id and rc1.super_hospital_id = rc2.super_hospital_id where rc1.hospital_id = '13000003' and rc2.exam_class='CT' order by rc1.sort, rc2.sort
|
|
|
+ if($is_pay === 1) {
|
|
|
+ $super_hospitals = array();
|
|
|
+ $super_doctors = DB::table("remote_contact")
|
|
|
+ ->alias("rc1")
|
|
|
+ ->join('remote_cost rc2', 'rc1.hospital_id = rc2.hospital_id and rc1.super_hospital_id = rc2.super_hospital_id')
|
|
|
+ ->where('rc1.hospital_id', $institution_id)
|
|
|
+ ->where('rc2.exam_class', $info['exam_class'])
|
|
|
+ ->field('rc1.hospital_id, rc1.super_hospital_id, rc1.hospital_name, rc1.super_hospital_name, rc1.pay_type, rc2.super_doctor_id, rc2.super_doctor_name, rc2.exam_class, rc2.is_admin')
|
|
|
+ // ->fetchSql()
|
|
|
+ ->select();
|
|
|
+ // var_dump($super_doctors);
|
|
|
+ foreach($super_doctors as $v) {
|
|
|
+ if(!isset($super_hospitals[$v['hospital_id']])){
|
|
|
+ $super_hospitals[$v['hospital_id']] = [
|
|
|
+ "doctor" => [
|
|
|
+ [
|
|
|
+ "id" => $v['super_doctor_id'],
|
|
|
+ "is_admin" => $v['is_admin'],
|
|
|
+ "realname" => $v['super_doctor_name']
|
|
|
+ ]
|
|
|
+ ],
|
|
|
+ "id" => $v['super_hospital_id'],
|
|
|
+ "name" => $v['super_hospital_name'],
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ $super_hospitals[$v['hospital_id']]['doctor'][] = [
|
|
|
+ "id" => $v['super_doctor_id'],
|
|
|
+ "is_admin" => $v['is_admin'],
|
|
|
+ "realname" => $v['super_doctor_name']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach($super_hospitals as $v) {
|
|
|
+ $parent_name[] = $v;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $parent_hosp = explode(',',$hospital['parent_institution']);
|
|
|
+ foreach($parent_hosp as $v){
|
|
|
+ $phname = DB::table("institution")->where('id',$v)->cache(300)->field(['id','name'])->find();
|
|
|
+ log::record('上级医院----'.json_encode($phname));
|
|
|
+ if(!isset($phname['id']) || empty($phname['id'])){
|
|
|
+ $phname['id'] = $v;
|
|
|
+ }
|
|
|
+ $doctor_info = DB::table('doctors')->where('institution_id',$v)->field('id,realname,is_admin')->order('is_admin desc')->select();
|
|
|
+ foreach($doctor_info as $key=>$value){
|
|
|
+ if($value['is_admin'] == 1){
|
|
|
+ $doctor_info[$key]['realname'] = $value['realname'].'---医院管理员';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $phname['doctor'] = $doctor_info;
|
|
|
+ $parent_name[] =$phname;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $info['parent_hospital'] = $parent_name;
|
|
|
+ //申请信息
|
|
|
+ if(isset($param['rid']) && !empty($param['rid'])){
|
|
|
+ $rid = $param['rid'];
|
|
|
+ $application = DB::table('remote_application')->where('id',$rid)->field(['id,report_status,id,remote_doctor_id','application_desc','attachment','req_doctor_id','illness_desc','phys_sign','is_urgent','clin_symp','anamnesis','family_ill','remark','clin_diag'])->find();
|
|
|
+ $aid = $application['id'];
|
|
|
+ }else{
|
|
|
+ $rid = '';
|
|
|
+ $application = DB::table('remote_application')->where('exam_id',$id)->field(['id,report_status,id,remote_doctor_id','application_desc','attachment','req_doctor_id','illness_desc','phys_sign','clin_symp','is_urgent','anamnesis','family_ill','remark','clin_diag'])->find();
|
|
|
+ $aid = $application['id'];
|
|
|
+ }
|
|
|
+ $remote_order = DB::table('remote_order')
|
|
|
+ ->where('application_id', $application['id'])
|
|
|
+ ->where('status', 'neq', self::ORDER_STATUS['CANCEL'])
|
|
|
+ ->where('status', 'neq', self::ORDER_STATUS['REDUCE'])
|
|
|
+ ->field('id, status, exam_class, super_hospital_id, super_doctor_id')
|
|
|
+ ->find();
|
|
|
+ if($remote_order) {
|
|
|
+ $info['remote_order'] = $remote_order;
|
|
|
+ }
|
|
|
+ if($is_remote == 1){
|
|
|
+ Message::read($doctor['id'],$aid,1);
|
|
|
+ //远程申请点击进入
|
|
|
+ $dinfo = DB::table('doctors')->where('id',$application['req_doctor_id'])->field('department_id')->find();
|
|
|
+ $dep = DB::table('department')->where('id',$dinfo['department_id'])->field('department_name')->find();
|
|
|
+ }else{
|
|
|
+ Message::read($doctor['id'],$aid,2);
|
|
|
+ //本地远程申请中
|
|
|
+ $dep = DB::table('department')->where('id',$doctor['department_id'])->field('department_name')->find();
|
|
|
+ }
|
|
|
+ $info['department_name'] = $dep['department_name'];
|
|
|
+ if(empty($application)){
|
|
|
+ $exam_application = DB::table('exams')->where('id',$id)->field(['illness_desc','phys_sign','clin_symp','remark','clin_diag','anamnesis','family_ill'])->find();
|
|
|
+ if(empty($exam_application['anamnesis'])){
|
|
|
+ $exam_application['anamnesis'] = '';
|
|
|
+ }else{
|
|
|
+ $exam_application['anamnesis'] = explode(',',$exam_application['anamnesis']);
|
|
|
+ }
|
|
|
+ if(empty($exam_application['family_ill'])){
|
|
|
+ $exam_application['family_ill'] = '';
|
|
|
+ }else{
|
|
|
+ $exam_application['family_ill'] = explode(',',$exam_application['family_ill']);
|
|
|
+ }
|
|
|
+ $exam_application['report_status'] = '';
|
|
|
+ $info['application'] = $exam_application;
|
|
|
+ }else{
|
|
|
+ $remote_name = DB::table('doctors')->where('id',$application['remote_doctor_id'])->field('realname')->find();
|
|
|
+ $application['remote_doctor'] = $remote_name['realname'];
|
|
|
+ if(empty($application['anamnesis'])){
|
|
|
+ $application['anamnesis'] = '';
|
|
|
+ }else{
|
|
|
+ $application['anamnesis'] = explode(',',$application['anamnesis']);
|
|
|
+ }
|
|
|
+ if(empty($application['family_ill'])){
|
|
|
+ $application['family_ill'] = '';
|
|
|
+ }else{
|
|
|
+ $application['family_ill'] = explode(',',$application['family_ill']);
|
|
|
+ }
|
|
|
+ $info['application'] = $application;
|
|
|
+ }
|
|
|
+ $count = DB::table('messages')->where('application_id',$aid)->where('doctor_id',$doctor['id'])->where('status',0)->where('type',7)->where('is_read',0)->field('count')->find();
|
|
|
+ $info['unread_message_num'] = $count['count'];
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'sessionid'=>$sessionid,'is_remote'=>$is_remote,'rid'=>$aid]);
|
|
|
+ }catch(\Exception $e){
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**取消订单 */
|
|
|
+ public function cancel(WechatService $wechatService){
|
|
|
+ try{
|
|
|
+ log::record($_REQUEST);
|
|
|
+ $sessionid = $_REQUEST['sessionid'];
|
|
|
+ $doctor = Cache::get($sessionid);
|
|
|
+ // 远程申请权限 6
|
|
|
+ $return = Verify::check_role($sessionid, 6);
|
|
|
+ if($return != 1){
|
|
|
+ return json_encode(['status'=>'fail','code'=>'1029','msg'=>'没有操作权限']);
|
|
|
+ }
|
|
|
+ $param = $_REQUEST['param'];
|
|
|
+ $order_id = $param['order_id'];
|
|
|
+ $remote_order = DB::table('remote_order')->where('id', $order_id)->field('application_id, hospital_id, doctor_id, status, pay_type, order_money')->find();
|
|
|
+ if(!$remote_order) {
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2101','msg'=> '没有找到该订单']);
|
|
|
+ }
|
|
|
+ if(!($remote_order['status'] === self::ORDER_STATUS['CREATE'] || $remote_order['status'] === self::ORDER_STATUS['PAYCOMPLTET'])) {
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2102','msg'=> '订单状态不可取消']);
|
|
|
+ }
|
|
|
+ $application = DB::table('remote_application')->where('id', $remote_order['application_id'])->field('report_status, exam_id')->find();
|
|
|
+ if(!$application) {
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2103','msg'=> '没有找到远程诊断申请单']);
|
|
|
+ }
|
|
|
+ if(!($application['report_status'] === '5' || $application['report_status'] === '12')) {
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2103','msg'=> '进行中的远程诊断订单不可取消']);
|
|
|
+ }
|
|
|
+ // 微信消息推送
|
|
|
+ // $wechatService->pushWechatCancel($application['exam_id']);
|
|
|
+ $wechatService->pushWechatCancel($order_id);
|
|
|
+ if($remote_order['pay_type'] === self::PAY_TYPE['HOSPITAL']) {
|
|
|
+ return $this->cancelHospitalOrder($order_id, $remote_order['hospital_id'], $remote_order['order_money']);
|
|
|
+ }
|
|
|
+ if($remote_order['pay_type'] === self::PAY_TYPE['PATIENT']) {
|
|
|
+ return $this->cancelPatientsOrder($order_id, $remote_order['application_id']);
|
|
|
+ }
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000','sessionid'=>$sessionid]);
|
|
|
+ }catch(\Exception $e){
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 提交申请
|
|
|
+ *
|
|
|
+ * @ApiTitle (提交申请)
|
|
|
+ * @ApiSummary (提交申请)
|
|
|
+ * @ApiSector (远程诊断)
|
|
|
+ * @ApiMethod (POST)
|
|
|
+ * @ApiRoute (/inter/application/apply)
|
|
|
+ * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
|
|
|
+ * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
|
|
|
+ * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
|
|
|
+ * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
|
|
|
+ * @ApiParams (name="param", type="string", required=true, description="参数json字符串")
|
|
|
+ * @ApiParams (name="param[id]", type="string", sample="", description="预约登记exams表id值<必填>")
|
|
|
+ * @ApiParams (name="param[illness]", type="string", sample="", description="主诉<选填>")
|
|
|
+ * @ApiParams (name="param[clin_symp]", type="string", sample="", description="临床症状<选填>")
|
|
|
+ * @ApiParams (name="param[anamnesis]", type="string", sample="", description="既往史<选填>")
|
|
|
+ * @ApiParams (name="param[family_ill]", type="string", sample="", description="家族史<选填>")
|
|
|
+ * @ApiParams (name="param[remark]", type="string", sample="", description="备注<选填>")
|
|
|
+ * @ApiParams (name="param[institution_id]", type="string", sample="", description="发起申请医院id值<选填>")
|
|
|
+ * @ApiParams (name="param[clin_diag]", type="string", sample="", description="临床诊断<选填>")
|
|
|
+ * @ApiParams (name="param[remote_institution]", type="string", sample="", description="申请的目标医院id值<选填>")
|
|
|
+ * @ApiParams (name="param[is_urgent]", type="string", sample="", description="是否急诊 0否 1是<选填>")
|
|
|
+ * @ApiParams (name="param[description]", type="string", sample="", description="申请描述<选填>")
|
|
|
+ * @ApiParams (name="param[remote_doctor_id]", type="string", sample="", description="申请的目标医生id值<选填>")
|
|
|
+ * @ApiParams (name="param[attachment]", type="string", sample="", description="附件<选填>")
|
|
|
+ * @ApiParams (name="param[apply]", type="string", sample="", description="保存或者申请 存在值即保存 不存在则为申请<必填>")
|
|
|
+ * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
|
|
|
+ * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
|
|
|
+ * @ApiReturnParams (name="sessionid", type="object", sample="{}", description="缓存的数据key")
|
|
|
+ * @ApiReturn (data="
|
|
|
+ {
|
|
|
+ 'status': ok,
|
|
|
+ 'code': '0000',
|
|
|
+ 'sessionid': 'a17z7a7a8f9g9rh9d89jio'
|
|
|
+ }
|
|
|
+ *")
|
|
|
+ **/
|
|
|
+ public function apply(WechatService $wechatService){
|
|
|
+ try{
|
|
|
+ // var_dump(1);
|
|
|
+ // var_dump($wechatService);
|
|
|
+ log::record($_REQUEST);
|
|
|
+ $sessionid = $_REQUEST['sessionid'];
|
|
|
+ $doctor = Cache::get($sessionid);
|
|
|
+ // 远程申请权限 6
|
|
|
+ $return = Verify::check_role($sessionid,6);
|
|
|
+ if($return != 1){
|
|
|
+ return json_encode(['status'=>'fail','code'=>'1029','msg'=>'没有操作权限']);
|
|
|
+ }
|
|
|
+ $param = $_REQUEST['param'];
|
|
|
+ $application_info = array();
|
|
|
+ $application_info['remote_institution_id'] = isset($param['remote_institution']) ? $param['remote_institution'] : '';
|
|
|
+ if(isset($param['remote_doctor_id']) && !empty($param['remote_doctor_id']) && empty($application_info['remote_doctor_id'])){
|
|
|
+ $remote_doctor = DB::table('doctors')->where('id',$param['remote_doctor_id'])->find();
|
|
|
+ $application_info['remote_institution_id'] = $remote_doctor['institution_id'];
|
|
|
+ }
|
|
|
+ if(empty($application_info['remote_institution_id'])){
|
|
|
+ return json_encode(['status'=>'fail','code'=>'3029','msg'=>'没有选择远程机构']);
|
|
|
+ }
|
|
|
+ $exam_info = DB::table('exams')->where('id',$param['id'])->field('exam_class,exam_status,patient_id')->find();
|
|
|
+ // 修改病人姓名
|
|
|
+ DB::table('patient_infos')->where('id',$exam_info['patient_id'])->update(['name'=>$param['name'], 'phone'=> $param['phone']]??'');
|
|
|
+ if($exam_info['exam_status'] != 3 && $exam_info['exam_status'] != 5 && $exam_info['exam_status'] != 8){
|
|
|
+ // 3 检查完毕 5已驳回
|
|
|
+ switch($exam_info['exam_status']){
|
|
|
+ case 1:
|
|
|
+ $msg = '患者还未检查,请检查完毕后再进行远程申请';
|
|
|
+ return json_encode(['status'=>'fail','code'=>'1029','msg'=>$msg]);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ $msg = '影像未到达,不能发起远程申请';
|
|
|
+ return json_encode(['status'=>'fail','code'=>'1029','msg'=>$msg]);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Verify::applicationCheck($param);
|
|
|
+ $where = array();
|
|
|
+ // 申请医生
|
|
|
+ $where['req_doctor_id'] = $doctor['id'];
|
|
|
+ $where['remote_institution_id'] = $application_info['remote_institution_id'];
|
|
|
+ // 只允许有一个申请 ----------------------------- 暂时添加
|
|
|
+ $r = DB::table('remote_application')->where('exam_id',$param['id'])->where('report_status','not in',',5,12')->find();
|
|
|
+ if($r){
|
|
|
+ return json_encode(['status'=>'fail','code'=>'1120','msg'=>'每个医院同一个检查只能申请一次']);
|
|
|
+ }
|
|
|
+ //不等于9 代表
|
|
|
+ $a_info = DB::table('remote_application')->where($where)->where('exam_id',$param['id'])->where('report_status','not in',',12,5,9')->find();
|
|
|
+ if($a_info){
|
|
|
+ return json_encode(['status'=>'fail','code'=>'1120','msg'=>'该申请目标医院存在未完成报告,只有报告完成后才能再次发起申请']);
|
|
|
+ }
|
|
|
+ $application_info['exam_id'] = isset($param['id']) ? $param['id'] : '';
|
|
|
+ $application_info['illness_desc'] = isset($param['illness']) ? $param['illness'] : '';
|
|
|
+ $application_info['phys_sign'] = isset($param['phys_sign']) ? $param['phys_sign'] : '';
|
|
|
+ $application_info['clin_symp'] = isset($param['clin_symp']) ? $param['clin_symp'] : '';
|
|
|
+ if(!empty($param['anamnesis'])){
|
|
|
+ $application_info['anamnesis'] = implode(',',$param['anamnesis']);
|
|
|
+ }
|
|
|
+ if(!empty($param['family_ill'])){
|
|
|
+ $application_info['family_ill'] = implode(',',$param['family_ill']);
|
|
|
+ }
|
|
|
+ $application_info['remark'] = isset($param['remark']) ? $param['remark'] : '';
|
|
|
+ $application_info['local_institution_id'] = $doctor['institution_id'];
|
|
|
+ $application_info['req_date_time'] = date('Y-m-d H:i:s',time());
|
|
|
+ $application_info['clin_diag'] = isset($param['clin_diag']) ? $param['clin_diag'] : '';
|
|
|
+ if(isset($param['is_urgent']) && $param['is_urgent'] == 'true' ){
|
|
|
+ $application_info['is_urgent'] = 1;
|
|
|
+ $remote_doctor_id = '';
|
|
|
+ $d_time = date('H:i',strtotime('+30 min'));
|
|
|
+ }else{
|
|
|
+ $application_info['is_urgent'] = 0;
|
|
|
+ $remote_doctor_id = isset($param['remote_doctor_id']) ? $param['remote_doctor_id'] : '';
|
|
|
+ $d_time = date('H:i',strtotime('+1 hour'));
|
|
|
+ if($remote_doctor_id === '') {
|
|
|
+ $manager = DB::table('doctors')->where('institution_id',$application_info['remote_institution_id'])->where('is_admin', '1')->field('id')->find();
|
|
|
+ if(!empty($manager)) {
|
|
|
+ $remote_doctor_id = $manager['id'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $application_info['application_desc'] = isset($param['description']) ? $param['description'] : '';
|
|
|
+ $application_info['req_doctor_id'] = $doctor['id'];
|
|
|
+ $application_info['phone'] = $param['phone']?? '';
|
|
|
+ $application_info['remote_doctor_id'] = $remote_doctor_id;
|
|
|
+ $application_info['attachment'] = isset($param['attachment']) ? $param['attachment'] : '';
|
|
|
+// $remote_application = DB::table('remote_application')->where('exam_id',$param['id'])->select();
|
|
|
+ // 申请远程
|
|
|
+// if(empty($remote_application)){
|
|
|
+ log::record('新增远程申请');
|
|
|
+ $re = DB::table('remote_application')->where('exam_id',$param['id'])->find();
|
|
|
+ $report = array();
|
|
|
+ if($re){
|
|
|
+ // 存在被驳回申请 再次申请时则为驳回后发起的申请
|
|
|
+ DB::table('remote_application')->where('exam_id',$param['id'])->update($application_info);
|
|
|
+ $app_id = $re['id'];
|
|
|
+ }else{
|
|
|
+ $application_info['id'] = UUIDs::uuid16();
|
|
|
+ $application_info['createdAt'] = date('Y-m-d H:i:s',time());
|
|
|
+ DB::table('remote_application')->insert($application_info);
|
|
|
+ $app_id = $application_info['id'];
|
|
|
+ }
|
|
|
+ $aid = $app_id;
|
|
|
+ $r_info = DB::table('report')->where('exam_id',$param['id'])->where('remote_application_id', $aid)->find();
|
|
|
+ if(empty($r_info)){
|
|
|
+ $report['id'] = UUIDs::uuid16();
|
|
|
+ $report['exam_id'] = $param['id'];
|
|
|
+ $report['remote_application_id'] = $aid;
|
|
|
+ $report['type'] = 2;
|
|
|
+ DB::table('report')->insert($report);
|
|
|
+ $r_id = $report['id'];
|
|
|
+ }else{
|
|
|
+ $r_id = $r_info['id'];
|
|
|
+ }
|
|
|
+// }else{
|
|
|
+// log::record('修改远程申请');
|
|
|
+// DB::table('remote_application')->where('exam_id',$param['id'])->update($application_info);
|
|
|
+// $r = DB::table('remote_application')->where('exam_id',$param['id'])->field('id')->find();
|
|
|
+// $aid = $r['id'];
|
|
|
+// }
|
|
|
+ if(isset($param['apply']) && !empty($param['apply'])){
|
|
|
+ $institution_id = $doctor['institution_id'];
|
|
|
+ $lower_hospital = DB::table('institution')->where('id', $institution_id)->field('is_pay')->find();
|
|
|
+ $is_pay = $lower_hospital['is_pay'];
|
|
|
+ $application = DB::table('remote_application')->where('exam_id', $param['id'])->field('id, remote_institution_id, remote_doctor_id, local_institution_id, req_doctor_id, is_urgent')->find();
|
|
|
+ if(empty($application)) {
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2011','msg'=> '申请单创建失败']);
|
|
|
+ }
|
|
|
+ $remote_institution_id = $application['remote_institution_id'];
|
|
|
+ $remote_doctor_id = $application['remote_doctor_id'];
|
|
|
+ $is_urgent = $application['is_urgent'];
|
|
|
+ $local_institution_id = $application['local_institution_id'];
|
|
|
+ $req_doctor_id = $application['req_doctor_id'];
|
|
|
+ if(empty($remote_institution_id)) {
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2012','msg'=> '远程机构id为空']);
|
|
|
+ }
|
|
|
+ // if(empty($remote_doctor_id)) {
|
|
|
+ // return json_encode(['status'=>'fail','code'=>'2013','msg'=> '远程医生id为空']);
|
|
|
+ // }
|
|
|
+ if(empty($local_institution_id)) {
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2014','msg'=> '本地机构id为空']);
|
|
|
+ }
|
|
|
+ if(empty($req_doctor_id)) {
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2015','msg'=> '本地医生id为空']);
|
|
|
+ }
|
|
|
+ if($is_pay === 1) {
|
|
|
+ $cost = DB::table('remote_cost')
|
|
|
+ ->where('hospital_id', $local_institution_id)
|
|
|
+ ->where('super_hospital_id', $remote_institution_id)
|
|
|
+ ->where('super_doctor_id', $remote_doctor_id)
|
|
|
+ ->where('exam_class', $exam_info['exam_class'])
|
|
|
+ ->field('money')
|
|
|
+ ->find();
|
|
|
+ if(!$cost) {
|
|
|
+ return json_encode(['status'=>'ok','code'=>'2016','msg'=> '远程医生获取失败']);
|
|
|
+ }
|
|
|
+ if($cost['money'] !== 0) {
|
|
|
+ $contact = DB::table('remote_contact')
|
|
|
+ ->where('hospital_id', $local_institution_id)
|
|
|
+ ->where('super_hospital_id', $remote_institution_id)
|
|
|
+ ->field('pay_type')
|
|
|
+ ->find();
|
|
|
+ if(!$contact) {
|
|
|
+ return json_encode(['status'=>'ok','code'=>'2017','msg'=> '远程机构获取失败']);
|
|
|
+ }
|
|
|
+ $res = false;
|
|
|
+ if($contact['pay_type'] === self::PAY_TYPE['HOSPITAL']) { //医院挂账
|
|
|
+ // $hospital_id, $super_hospital_id, $doctor_id, $super_doctor_id, $exam_class, $application_id, $order_money
|
|
|
+ $res = $this->createHospitalOrder($local_institution_id, $remote_institution_id, $req_doctor_id, $remote_doctor_id, $exam_info['exam_class'], $application['id'], $cost['money'], $is_urgent, $wechatService);
|
|
|
+ }
|
|
|
+ if($contact['pay_type'] === self::PAY_TYPE['PATIENT']) { // 患者支付
|
|
|
+ // var_dump(2);
|
|
|
+ // var_dump($wechatService);
|
|
|
+ // $push_res = WechatService::pushWechatOrder($param['id']);
|
|
|
+ // $wechatService->pushWechatOrder($param['id']);
|
|
|
+ $res = $this->createPatientsOrder($local_institution_id, $remote_institution_id, $req_doctor_id, $remote_doctor_id, $exam_info['exam_class'], $application['id'], $cost['money'], $is_urgent, $wechatService);
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000']);
|
|
|
+ }
|
|
|
+ if($res === true) {
|
|
|
+ return ['status'=>'ok','code'=>'0000'];
|
|
|
+ }
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ DB::table('remote_order')->insert([
|
|
|
+ 'id' => UUIDs::uuid16(),
|
|
|
+ 'hospital_id' => $local_institution_id,
|
|
|
+ 'super_hospital_id' => $remote_institution_id,
|
|
|
+ 'exam_class' => $exam_info['exam_class'],
|
|
|
+ 'doctor_id' => $req_doctor_id,
|
|
|
+ 'application_id' => $application['id'],
|
|
|
+ 'super_doctor_id' => $remote_doctor_id,
|
|
|
+ 'is_urgent' => $is_urgent,
|
|
|
+ 'status' => self::ORDER_STATUS['PAYCOMPLTET'],
|
|
|
+ 'order_money' => 0,
|
|
|
+ 'pay_type' => self::PAY_TYPE['HOSPITAL'],
|
|
|
+ 'pay_way' => self::PAY_WAY['HOSPITAL'],
|
|
|
+ 'timestamp' => time()
|
|
|
+ ]);
|
|
|
+ DB::table('remote_application')->where('exam_id',$param['id'])->update(['report_status'=>4]);
|
|
|
+ }
|
|
|
+ // 添加messages信息
|
|
|
+
|
|
|
+ // $wechatService->pushWechatOrder($param['id']);
|
|
|
+ $t = '收到一条远程诊断申请';
|
|
|
+ $ins = DB::table('institution')->where('id',$doctor['institution_id'])->field('name')->find();
|
|
|
+ $c = $ins['name'].$doctor['realname'].'医师向您发起一条远程诊断申请';
|
|
|
+ $d = $application_info['remote_doctor_id'];
|
|
|
+ $type = '1';
|
|
|
+ $url = Message::url($sessionid,$param['id'],1,$exam_info['exam_class'],$r_id,$aid);
|
|
|
+ Message::insert($t,$c,$d,$type,$url,1,$aid);
|
|
|
+ //保存 申请
|
|
|
+ $dinfo = DB::table('doctors')->where('id',$application_info['remote_doctor_id'])->find();
|
|
|
+ $d_phone = $dinfo['phone'];
|
|
|
+ $d_name = $dinfo['realname'];
|
|
|
+ if($dinfo['institution_id'] == '22100003' || $dinfo['send_sms'] == 1){ //魏庙
|
|
|
+ $repsone = send_message::sendSms2Apply($d_phone,$d_time,$d_name);
|
|
|
+ }
|
|
|
+ // $tel = '18910184804';
|
|
|
+ // $type = '发起申请';
|
|
|
+ // $content = $aid;
|
|
|
+ // $response = send_message::sendSms2Self($tel,$type,$content);
|
|
|
+ }
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000','sessionid'=>$sessionid,'aid'=>$aid]);
|
|
|
+ }catch(\Exception $e){
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function createHospitalOrder($hospital_id, $super_hospital_id, $doctor_id, $super_doctor_id, $exam_class, $application_id, $order_money, $is_urgent = 0, $wechatService) {
|
|
|
+ DB::startTrans();
|
|
|
+ $pay_type = self::PAY_TYPE['HOSPITAL'];
|
|
|
+ $pay_way = self::PAY_TYPE['HOSPITAL'];
|
|
|
+ $water_type = self::WATER_TYPE['REDUCE'];
|
|
|
+ $water_why = self::WATER_WHY['REMOTEPAY'];
|
|
|
+ try{
|
|
|
+ $remote_order = DB::table('remote_order')
|
|
|
+ ->where('application_id', $application_id)
|
|
|
+ ->where('status', 'neq', self::ORDER_STATUS['CANCEL'])
|
|
|
+ ->where('status', 'neq', self::ORDER_STATUS['REDUCE'])
|
|
|
+ ->field('id')
|
|
|
+ ->find();
|
|
|
+ DB::table('remote_application')->where('id',$application_id)->update(['report_status'=>4]);
|
|
|
+ if($remote_order) {
|
|
|
+ DB::commit();
|
|
|
+ // return true;
|
|
|
+ // DB::rollback();
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2019','msg' => '已存在订单,请勿重复发起']);
|
|
|
+ }
|
|
|
+ $hospital = DB::table('institution')
|
|
|
+ ->where('id', $hospital_id)
|
|
|
+ ->field('min_money, current_money')
|
|
|
+ ->find();
|
|
|
+ if(!$hospital) {
|
|
|
+ DB::rollback();
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2017','msg' => '查找本地医院失败']);
|
|
|
+ }
|
|
|
+ $min_money = $hospital['min_money'];
|
|
|
+ $current_money = $hospital['current_money'];
|
|
|
+ if($current_money - $order_money < $min_money) {
|
|
|
+ DB::rollback();
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2017','msg' => '余额不足请联系医院管理员充值']);
|
|
|
+ }
|
|
|
+ DB::table('institution')->where('id',$hospital_id)->update(['current_money'=> $current_money - $order_money]);
|
|
|
+ $order_id = UUIDs::uuid16();
|
|
|
+ DB::table('remote_order')->insert([
|
|
|
+ 'id' => $order_id,
|
|
|
+ 'hospital_id' => $hospital_id,
|
|
|
+ 'super_hospital_id' => $super_hospital_id,
|
|
|
+ 'exam_class' => $exam_class,
|
|
|
+ 'doctor_id' => $doctor_id,
|
|
|
+ 'is_urgent' => $is_urgent,
|
|
|
+ 'application_id' => $application_id,
|
|
|
+ 'super_doctor_id' => $super_doctor_id,
|
|
|
+ 'order_money' => $order_money,
|
|
|
+ 'pay_type' => $pay_type,
|
|
|
+ 'pay_way' => $pay_way,
|
|
|
+ 'timestamp' => time(),
|
|
|
+ ]);
|
|
|
+ DB::table('remote_water')->insert([
|
|
|
+ 'id' => UUIDs::uuid16(),
|
|
|
+ 'hospital_id' => $hospital_id,
|
|
|
+ 'order_id' => $order_id,
|
|
|
+ 'money' => $order_money,
|
|
|
+ 'type' => $water_type,
|
|
|
+ 'why' => $water_why,
|
|
|
+ 'timestamp' => time(),
|
|
|
+ ]);
|
|
|
+ // 提交事务
|
|
|
+ DB::commit();
|
|
|
+ $wechatService->pushWechatOrder($order_id);
|
|
|
+ return true;
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ // 回滚事务
|
|
|
+ DB::rollback();
|
|
|
+ }
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2018','msg' => '远程诊断发起失败']);
|
|
|
+ }
|
|
|
+ private function createPatientsOrder($hospital_id, $super_hospital_id, $doctor_id, $super_doctor_id, $exam_class, $application_id, $order_money, $is_urgent = 0, $wechatService) {
|
|
|
+ $pay_type = self::PAY_TYPE['PATIENT'];
|
|
|
+ $pay_way = self::PAY_WAY['WECHAT'];
|
|
|
+ DB::startTrans();
|
|
|
+ try{
|
|
|
+ $remote_order = DB::table('remote_order')
|
|
|
+ ->where('application_id', $application_id)
|
|
|
+ ->where('status', 'neq', self::ORDER_STATUS['CANCEL'])
|
|
|
+ ->where('status', 'neq', self::ORDER_STATUS['REDUCE'])
|
|
|
+ ->field('id')
|
|
|
+ ->find();
|
|
|
+ DB::table('remote_application')->where('id',$application_id)->update(['report_status'=>4]);
|
|
|
+ if($remote_order) {
|
|
|
+ DB::commit();
|
|
|
+ // return json_encode(['status'=>'ok','code'=>'0000','oid'=>$remote_order['id'],'aid'=>$application_id]);
|
|
|
+ // DB::rollback();
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2019','msg' => '已存在订单,请勿重复发起']);
|
|
|
+ }
|
|
|
+ $order_id = UUIDs::uuid16();
|
|
|
+ DB::table('remote_order')->insert([
|
|
|
+ 'id' => $order_id,
|
|
|
+ 'hospital_id' => $hospital_id,
|
|
|
+ 'super_hospital_id' => $super_hospital_id,
|
|
|
+ 'exam_class' => $exam_class,
|
|
|
+ 'doctor_id' => $doctor_id,
|
|
|
+ 'application_id' => $application_id,
|
|
|
+ 'super_doctor_id' => $super_doctor_id,
|
|
|
+ 'is_urgent' => $is_urgent,
|
|
|
+ 'order_money' => $order_money,
|
|
|
+ 'pay_type' => $pay_type,
|
|
|
+ 'pay_way' => $pay_way,
|
|
|
+ 'timestamp' => time(),
|
|
|
+ 'status' => self::ORDER_STATUS['CREATE']
|
|
|
+ ]);
|
|
|
+ DB::commit();
|
|
|
+ $wechatService->pushWechatOrder($order_id);
|
|
|
+ return true;
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ var_dump($e);
|
|
|
+ DB::rollback();
|
|
|
+ }
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2020','msg' => '远程诊断发起失败']);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function cancelHospitalOrder($order_id, $hospital_id, $order_money) {
|
|
|
+ DB::startTrans();
|
|
|
+ $water_type = self::WATER_TYPE['ADD'];
|
|
|
+ $water_why = self::WATER_WHY['REFUNDINCOME'];
|
|
|
+ try{
|
|
|
+ DB::table('remote_order')->where('id', $order_id)->update(["status" => self::ORDER_STATUS["REDUCE"]]);
|
|
|
+ $hospital = DB::table('institution')
|
|
|
+ ->where('id', $hospital_id)
|
|
|
+ ->field('current_money')
|
|
|
+ ->find();
|
|
|
+ $current_money = $hospital['current_money'];
|
|
|
+ DB::table('institution')->where('id',$hospital_id)->update(['current_money'=> $current_money + $order_money]);
|
|
|
+ DB::table('remote_water')->insert([
|
|
|
+ 'id' => UUIDs::uuid16(),
|
|
|
+ 'hospital_id' => $hospital_id,
|
|
|
+ 'order_id' => $order_id,
|
|
|
+ 'money' => $order_money,
|
|
|
+ 'type' => $water_type,
|
|
|
+ 'why' => $water_why,
|
|
|
+ 'timestamp' => time(),
|
|
|
+ ]);
|
|
|
+ // 提交事务
|
|
|
+ DB::commit();
|
|
|
+ // todo 消息推送
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000']);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ // 回滚事务
|
|
|
+ DB::rollback();
|
|
|
+ }
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2018','msg' => '取消订单失败']);
|
|
|
+ }
|
|
|
+ private function cancelPatientsOrder($order_id) {
|
|
|
+ try{
|
|
|
+ DB::table('remote_order')->where('id', $order_id)->update(["status" => self::ORDER_STATUS["CANCEL"]]);
|
|
|
+ // todo 消息推送
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000']);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ var_dump($e);
|
|
|
+ }
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2109','msg' => '订单取消失败']);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**订单状态 创建 支付完成 订单完成 取消 退款 */
|
|
|
+ public const ORDER_STATUS = [
|
|
|
+ 'CREATE' => 1,
|
|
|
+ 'PAYCOMPLTET' => 2,
|
|
|
+ 'CONFIRM' => 3,
|
|
|
+ 'CANCEL' => 4,
|
|
|
+ 'REDUCE' => 5
|
|
|
+ ];
|
|
|
+
|
|
|
+ /**流水类型 加 减 */
|
|
|
+ public const WATER_TYPE = [
|
|
|
+ 'ADD' => 1,
|
|
|
+ 'REDUCE' => 2
|
|
|
+ ];
|
|
|
+
|
|
|
+ /**流水原因 远程诊断医院扣款 远程诊断医院收入 远程诊断退款 远程诊断退款收入 */
|
|
|
+ public const WATER_WHY = [
|
|
|
+ 'REMOTEPAY' => 21,
|
|
|
+ 'REMOTEINCOME' => 11,
|
|
|
+ 'REMOTEREFUND' => 22,
|
|
|
+ 'REFUNDINCOME' => 12
|
|
|
+ ];
|
|
|
+ // why 患者支付/远程诊断收入/远程诊断付款/远程诊断退款/提现
|
|
|
+ /**支付方式 微信 支付宝 银联 医院扣款*/
|
|
|
+ public const PAY_WAY = [
|
|
|
+ "HOSPITAL" => 1,
|
|
|
+ "WECHAT" => 11,
|
|
|
+ "ALIPAY" => 12,
|
|
|
+ "BANK" => 13
|
|
|
+ ];
|
|
|
+
|
|
|
+ /**支付类型 微信 医院 */
|
|
|
+ public const PAY_TYPE = [
|
|
|
+ "PATIENT" => 0,
|
|
|
+ "HOSPITAL" => 1
|
|
|
+ ];
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传附件
|
|
|
+ *
|
|
|
+ * @ApiTitle (上传附件)
|
|
|
+ * @ApiSummary (上传附件)
|
|
|
+ * @ApiSector (远程诊断)
|
|
|
+ * @ApiMethod (POST)
|
|
|
+ * @ApiRoute (/inter/application/upload)
|
|
|
+ * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
|
|
|
+ * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
|
|
|
+ * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
|
|
|
+ * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
|
|
|
+ * @ApiParams (name="file", type="string", required=true, description="上传的文件<必填>")
|
|
|
+ * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
|
|
|
+ * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
|
|
|
+ * @ApiReturnParams (name="info", type="string", required=true, sample="返回成功", description="返回信息")
|
|
|
+ * @ApiReturn (data="
|
|
|
+ {
|
|
|
+ 'status': ok,
|
|
|
+ 'code': '0000',
|
|
|
+ 'info' : '/upload/20180101/12346asd.jpg'
|
|
|
+ }
|
|
|
+ *")
|
|
|
+ **/
|
|
|
+ //上传附件
|
|
|
+ public function upload(){
|
|
|
+ // 获取表单上传文件 例如上传了001.jpg
|
|
|
+ $file = request()->file('file');
|
|
|
+ log::record('----------上传的文件-----------');
|
|
|
+ log::record($file);
|
|
|
+ // 移动到框架应用根目录/public/uploads/ 目录下
|
|
|
+ if($file){
|
|
|
+ $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
|
|
|
+ log::record($info);
|
|
|
+ if($info){
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000','info'=>'/'.$_SERVER["SERVER_NAME"]. '/' . 'uploads'. '/' .$info->getSaveName()]);
|
|
|
+ }else{
|
|
|
+ // 上传失败获取错误信息
|
|
|
+ return json_encode(['status'=>'fail','code'=>'1040','info'=>$file->getError()]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 远程申请驳回
|
|
|
+ *
|
|
|
+ * @ApiTitle (远程申请驳回)
|
|
|
+ * @ApiSummary (远程申请驳回)
|
|
|
+ * @ApiSector (远程诊断)
|
|
|
+ * @ApiMethod (POST)
|
|
|
+ * @ApiRoute (/inter/application/reject)
|
|
|
+ * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
|
|
|
+ * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
|
|
|
+ * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
|
|
|
+ * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
|
|
|
+ * @ApiParams (name="param", type="string", required=true, sample="", description="参数json字符串,预约登记exams表id值<必填>")
|
|
|
+ * @ApiParams (name="param[id]", type="string", sample="", description="预约登记exams表id值<必填>")
|
|
|
+ * @ApiParams (name="param[description]", type="string", sample="", description="驳回原因<必填>")
|
|
|
+ * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
|
|
|
+ * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
|
|
|
+ * @ApiReturnParams (name="sessionid", type="object", sample="{}", description="缓存的数据key")
|
|
|
+ * @ApiReturn (data="
|
|
|
+ {
|
|
|
+ 'status': ok,
|
|
|
+ 'code': '0000',
|
|
|
+ 'sessionid': 'a17z7a7a8f9g9rh9d89jio'
|
|
|
+ }
|
|
|
+ *")
|
|
|
+ **/
|
|
|
+ //驳回 7
|
|
|
+ public function reject(){
|
|
|
+ $sessionid = $_REQUEST['sessionid'];
|
|
|
+ $doctor = Cache::get($sessionid);
|
|
|
+ $param = $_REQUEST['param'];
|
|
|
+ $id = $param['id'];
|
|
|
+ $re = DB::table('remote_application')->where('id',$id)->field('exam_id,report_status')->find();
|
|
|
+ if($re['report_status'] != 4){
|
|
|
+ return json_encode(['status'=>'fail','code'=>'0321','msg'=>'只能驳回申请中的单子']);
|
|
|
+ }
|
|
|
+ $report = DB::table('report')->where('remote_application_id',$id)->field('id')->find();
|
|
|
+ $info = array();
|
|
|
+ $info['id'] = UUIDs::uuid16();
|
|
|
+ $info['report_id'] = $report['id'];
|
|
|
+ $info['description'] = $param['description'];
|
|
|
+ $info['createdAt'] = date('Y-m-d H:i:s',time());
|
|
|
+ $info['type'] = 4;
|
|
|
+ $info['doctor_id'] = $doctor['id'];
|
|
|
+ DB::table('report_record')->insert($info);
|
|
|
+ $binfo = array();
|
|
|
+ $binfo['id'] = UUIDs::uuid16();
|
|
|
+ $binfo['initiator'] = $doctor['id'];
|
|
|
+// $info['reply'] = $param['reply']; // 回复人
|
|
|
+ $binfo['remote_application_id'] = $id; //申请单id
|
|
|
+ $binfo['content'] = '驳回原因:'.$param['description'];
|
|
|
+ $binfo['createdAt'] = date('Y-m-d H:i:s',time());
|
|
|
+ DB::table('bbs')->insert($binfo);
|
|
|
+// $message = array();
|
|
|
+// $message['id'] = UUIDs::uuid16();
|
|
|
+// $message['title'] = '申请单驳回';
|
|
|
+// $message['content'] = $param['description'];
|
|
|
+// $message['createdAt'] = date('Y-m-d H:i:s',time());
|
|
|
+ $application = DB::table('remote_application')->where('id',$id)->find();
|
|
|
+// $message['doctor_id'] = $application['req_doctor_id'];
|
|
|
+// $message['institution_id'] = $application['local_institution_id'];
|
|
|
+ DB::table('remote_application')->where('id',$id)->update(['report_status'=>5]);
|
|
|
+ $dinfo = DB::table('doctors')->where('id',$application['req_doctor_id'])->find();
|
|
|
+ $institution = DB::table('institution')->where('id',$doctor['institution_id'])->field('name')->find();
|
|
|
+ // 驳回添加messages消息
|
|
|
+ $t = '您的远程诊断申请被驳回';
|
|
|
+ $c = '您的远程诊断申请,被'.$institution['name'].$doctor['realname'].'医师驳回。驳回理由:'.$param['description'];
|
|
|
+ $d = $application['req_doctor_id'];
|
|
|
+ $type = '2';
|
|
|
+ $exam_class = DB::table('exams')->where('id',$re['exam_id'])->field('exam_class')->find();
|
|
|
+ $url = Message::url($sessionid,$re['exam_id'],0,$exam_class['exam_class'],$report['id'],$id);
|
|
|
+ Message::insert($t,$c,$d,$type,$url,1,$id);
|
|
|
+ // 驳回发短信
|
|
|
+ $d_phone = $dinfo['phone'];
|
|
|
+ if($dinfo['institution_id'] == '22100002' || $dinfo['send_sms'] == 1){ //魏庙下级
|
|
|
+ $des = mb_substr($param['description'],0,20,'utf-8');
|
|
|
+ $repsone = send_message::sendSms2RejectApply($d_phone,$des);
|
|
|
+ }
|
|
|
+ $tel = '18910184804';
|
|
|
+ $type = '驳回申请';
|
|
|
+ $content = $application['id'];
|
|
|
+// send_message::sendSms2Self($tel,$type,$content);
|
|
|
+ $tel = '18366391911';
|
|
|
+ send_message::sendSms2Self($tel,$type,$content);
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000','sessionid'=>$sessionid]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 远程申请接收
|
|
|
+ *
|
|
|
+ * @ApiTitle (远程申请接收)
|
|
|
+ * @ApiSummary (远程申请接收)
|
|
|
+ * @ApiSector (远程诊断)
|
|
|
+ * @ApiMethod (POST)
|
|
|
+ * @ApiRoute (/inter/application/recive)
|
|
|
+ * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
|
|
|
+ * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
|
|
|
+ * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
|
|
|
+ * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
|
|
|
+ * @ApiParams (name="id", type="string", required=true, sample="", description="参数json字符串,预约登记exams表id值<必填>")
|
|
|
+ * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
|
|
|
+ * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
|
|
|
+ * @ApiReturnParams (name="sessionid", type="object", sample="{}", description="缓存的数据key")
|
|
|
+ * @ApiReturn (data="
|
|
|
+ {
|
|
|
+ 'status': ok,
|
|
|
+ 'code': '0000',
|
|
|
+ 'sessionid': 'a17z7a7a8f9g9rh9d89jio'
|
|
|
+ }
|
|
|
+ *")
|
|
|
+ **/
|
|
|
+ public function recive(){
|
|
|
+ $sessionid = $_REQUEST['sessionid'];
|
|
|
+ $doctor = Cache::get($sessionid);
|
|
|
+ $id = $_REQUEST['id'];
|
|
|
+ $re = DB::table('remote_application')->where('id',$id)->field('report_status,req_doctor_id,exam_id')->find();
|
|
|
+ if($re['report_status'] != 4){
|
|
|
+ return json_encode(['status'=>'fail','code'=>'0321','msg'=>'只能接收申请中的单子']);
|
|
|
+ }
|
|
|
+ DB::table('remote_application')->where('id',$id)->update(['report_status'=>6]);
|
|
|
+ $application = DB::table('remote_application')->where('exam_id',$id)->find();
|
|
|
+ $tel = '18910184804';
|
|
|
+ $type = '接收申请';
|
|
|
+ $content = $application['id'];
|
|
|
+// send_message::sendSms2Self($tel,$type,$content);
|
|
|
+ // 添加messages消息
|
|
|
+ $t = '您的远程诊断申请被接收';
|
|
|
+ $institution = DB::table('institution')->where('id',$doctor['institution_id'])->field('name')->find();
|
|
|
+ $c = '您的远程诊断申请,被'.$institution['name'].$doctor['realname'].'医师接收';
|
|
|
+ $d = $re['req_doctor_id'];
|
|
|
+ $type = '4';
|
|
|
+ $exam_class = DB::table('exams')->where('id',$re['exam_id'])->field('exam_class')->find();
|
|
|
+ $report = DB::table('report')->where('exam_id',$re['exam_id'])->where('type',1)->field('id')->find();
|
|
|
+ $url = Message::url($sessionid,$re['exam_id'],0,$exam_class['exam_class'],$report['id'],$id);
|
|
|
+ Message::insert($t,$c,$d,$type,$url,1,$id);
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000','sessionid'=>$sessionid]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * bbs通话保存
|
|
|
+ *
|
|
|
+ * @ApiTitle (bbs通话保存)
|
|
|
+ * @ApiSummary (bbs通话保存)
|
|
|
+ * @ApiSector (远程诊断)
|
|
|
+ * @ApiMethod (POST)
|
|
|
+ * @ApiRoute (/inter/application/bbs_save)
|
|
|
+ * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
|
|
|
+ * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
|
|
|
+ * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
|
|
|
+ * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
|
|
|
+ * @ApiParams (name="param", type="string", required=true, sample="", description="参数json字符串,预约登记exams表id值<必填>")
|
|
|
+ * @ApiParams (name="param[appid]", type="string", sample="", description="申请单id值<必填>")
|
|
|
+ * @ApiParams (name="param[content]", type="string", sample="", description="留言内容<必填>")
|
|
|
+ * @ApiParams (name="param[attachment]", type="string", sample="", description="上传图片<选填>")
|
|
|
+ * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
|
|
|
+ * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
|
|
|
+ * @ApiReturnParams (name="sessionid", type="object", sample="{}", description="缓存的数据key")
|
|
|
+ * @ApiReturn (data="
|
|
|
+ {
|
|
|
+ 'status': ok,
|
|
|
+ 'code': '0000',
|
|
|
+ 'sessionid': 'a17z7a7a8f9g9rh9d89jio',
|
|
|
+ 'info' : ''
|
|
|
+ }
|
|
|
+ *")
|
|
|
+ **/
|
|
|
+ public function bbs_save(){
|
|
|
+ $sessionid = $_REQUEST['sessionid'];
|
|
|
+ $doctor = Cache::get($sessionid);
|
|
|
+ $param = $_REQUEST['param'];
|
|
|
+ if(empty($param['content'])){
|
|
|
+ return json_encode(['status'=>'fail','msg'=>'内容为空,请填写要发送的内容','sessionid'=>$sessionid]);
|
|
|
+ }
|
|
|
+ $info = array();
|
|
|
+ $info['id'] = UUIDs::uuid16();
|
|
|
+ $info['initiator'] = $doctor['id'];
|
|
|
+ $is_remote = $_REQUEST['is_remote'];
|
|
|
+ $rinfo = DB::table('remote_application')->where('id',$param['appid'])->field('req_doctor_id,remote_doctor_id')->find();
|
|
|
+ if($is_remote == 1){
|
|
|
+ // 远程医生
|
|
|
+ $info['reply'] = $rinfo['req_doctor_id']; //申请医生
|
|
|
+ $remote = 0;
|
|
|
+ }else{
|
|
|
+ $info['reply'] = $rinfo['remote_doctor_id']; //申请的目标远程医生
|
|
|
+ $remote = 1;
|
|
|
+ }
|
|
|
+ $info['remote_application_id'] = $param['appid']; //申请单id
|
|
|
+ $info['content'] = $param['content'];
|
|
|
+ $info['attachment'] = $param['attachment'];
|
|
|
+ $info['createdAt'] = date('Y-m-d H:i:s',time());
|
|
|
+ DB::table('bbs')->insert($info);
|
|
|
+ // 添加message消息
|
|
|
+ Message::bbs_message($param['appid'],$doctor['id'],$param['content'],$info['reply'],$remote,$sessionid);
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000','sessionid'=>$sessionid]);
|
|
|
+ }
|
|
|
+ public function getbbs(){
|
|
|
+ $sessionid = $_REQUEST['sessionid'];
|
|
|
+ $doctor = Cache::get($sessionid);
|
|
|
+ $remote_id = $_REQUEST['application_id'];
|
|
|
+ Message::read($doctor['id'],$remote_id,5);
|
|
|
+ $info = DB::table('bbs')->where('remote_application_id',$remote_id)->order('createdAt desc')->select();
|
|
|
+ foreach ($info as $k => $v) {
|
|
|
+ $initiator = DB::table('doctors')->where('id',$v['initiator'])->field('realname')->find();
|
|
|
+ $info[$k]['faqiren'] = $initiator['realname'];
|
|
|
+// $reply = DB::table('doctors')->where('id',$v['reply'])->field('realname')->find();
|
|
|
+// $info[$k]['huifuren'] = $reply['realname'];
|
|
|
+ }
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000','sessionid'=>$sessionid,'info'=>$info]);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 上传通话留言附件
|
|
|
+ *
|
|
|
+ * @ApiTitle (上传通话留言附件)
|
|
|
+ * @ApiSummary (上传通话留言附件)
|
|
|
+ * @ApiSector (远程诊断)
|
|
|
+ * @ApiMethod (POST)
|
|
|
+ * @ApiRoute (/inter/application/bbs_upload)
|
|
|
+ * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
|
|
|
+ * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
|
|
|
+ * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
|
|
|
+ * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
|
|
|
+ * @ApiParams (name="file", type="string", required=true, description="上传的文件<必填>")
|
|
|
+ * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
|
|
|
+ * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
|
|
|
+ * @ApiReturnParams (name="info", type="string", required=true, sample="返回成功", description="返回信息")
|
|
|
+ * @ApiReturn (data="
|
|
|
+ {
|
|
|
+ 'status': ok,
|
|
|
+ 'code': '0000',
|
|
|
+ 'info' : '/upload/20180101/12346asd.jpg'
|
|
|
+ }
|
|
|
+ *")
|
|
|
+ **/
|
|
|
+ public function bbs_upload(){
|
|
|
+ // 获取表单上传文件 例如上传了001.jpg
|
|
|
+ $file = request()->file('file');
|
|
|
+ log::record('----------上传的文件-----------');
|
|
|
+ log::record($file);
|
|
|
+ // 移动到框架应用根目录/public/uploads/ 目录下
|
|
|
+ if($file){
|
|
|
+ $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
|
|
|
+ log::record($info);
|
|
|
+ if($info){
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000','info'=>'/'.$_SERVER["SERVER_NAME"]. '/' . 'uploads'. '/' .$info->getSaveName()]);
|
|
|
+ }else{
|
|
|
+ // 上传失败获取错误信息
|
|
|
+ echo $file->getError();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 撤回
|
|
|
+ *
|
|
|
+ * @ApiTitle (撤回)
|
|
|
+ * @ApiSummary (撤回)
|
|
|
+ * @ApiSector (远程诊断)
|
|
|
+ * @ApiMethod (POST)
|
|
|
+ * @ApiRoute (/inter/application/revoke)
|
|
|
+ * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
|
|
|
+ * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
|
|
|
+ * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
|
|
|
+ * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
|
|
|
+ * @ApiParams (name="id", type="string", required=true, sample="", description="参数json字符串,预约登记exams表id值<必填>")
|
|
|
+ * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
|
|
|
+ * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
|
|
|
+ * @ApiReturnParams (name="sessionid", type="object", sample="{}", description="缓存的数据key")
|
|
|
+ * @ApiReturn (data="
|
|
|
+ {
|
|
|
+ 'status': ok,
|
|
|
+ 'code': '0000',
|
|
|
+ 'sessionid': 'a17z7a7a8f9g9rh9d89jio'
|
|
|
+ }
|
|
|
+ *")
|
|
|
+ **/
|
|
|
+ //
|
|
|
+ public function revoke(){
|
|
|
+ $sessionid = $_REQUEST['sessionid'];
|
|
|
+ $doctor = Cache::get($sessionid);
|
|
|
+ $id = $_REQUEST['id'];
|
|
|
+ $status = DB::table('remote_application')->where('exam_id',$id)->field('id,report_status,remote_doctor_id')->find();
|
|
|
+ if($status['report_status'] == 4){
|
|
|
+ DB::table('remote_application')->where('exam_id',$id)->update(['report_status'=>12]);
|
|
|
+ }else{
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0100','msg'=>'只能撤回申请中状态的申请单']);
|
|
|
+ }
|
|
|
+ $binfo = array();
|
|
|
+ $binfo['id'] = UUIDs::uuid16();
|
|
|
+ $binfo['initiator'] = $doctor['id'];
|
|
|
+// $info['reply'] = $param['reply']; // 回复人
|
|
|
+ $binfo['remote_application_id'] = $status['id']; //申请单id
|
|
|
+ $binfo['content'] = '已撤回了该申请';
|
|
|
+ $binfo['createdAt'] = date('Y-m-d H:i:s',time());
|
|
|
+ DB::table('bbs')->insert($binfo);
|
|
|
+ //
|
|
|
+ $t = '发起给您的远程诊断申请被撤回';
|
|
|
+ $institution = DB::table('institution')->where('id',$doctor['institution_id'])->field('name')->find();
|
|
|
+ $c = '您的远程诊断申请'.$institution['name'].$doctor['realname'].'医师撤回';
|
|
|
+ $d = $status['remote_doctor_id'];
|
|
|
+ $type = '3';
|
|
|
+ $exam_class = DB::table('exams')->where('id',$id)->field('exam_class')->find();
|
|
|
+ $report = DB::table('report')->where('remote_application_id',$status['id'])->field('id')->find();
|
|
|
+ $url = Message::url($sessionid,$id,1,$exam_class['exam_class'],$report['id'],$status['id']);
|
|
|
+ Message::insert($t,$c,$d,$type,$url,1,$status['id']);
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000','msg'=>'撤回成功']);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function bind_doctor()
|
|
|
+ {
|
|
|
+ try{
|
|
|
+ $ra_id = $_REQUEST['ra_id'];
|
|
|
+ $status = DB::table('remote_application')->where('id',$ra_id)->value('report_status');
|
|
|
+ if($status != 4){
|
|
|
+ return json_encode(['status'=>'fail','code'=>'0410','msg'=>'只能分配未经处理的报告']);
|
|
|
+ }
|
|
|
+ $did = $_REQUEST['did'];
|
|
|
+ $info = DB::table('remote_application')->where('id',$ra_id)->update(['remote_doctor_id'=>$did]);
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000','info'=>$info]);
|
|
|
+ }catch(\Exception $e){
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取医生的接收和分配权限
|
|
|
+ public function get_doctor_role()
|
|
|
+ {
|
|
|
+ try{
|
|
|
+ $sessionid = $_REQUEST['sessionid'];
|
|
|
+ $doctor = Cache::get($sessionid);
|
|
|
+ $info = [];
|
|
|
+ $info['is_admin'] = $doctor['is_admin'];
|
|
|
+ $role = DB::table('doctor_class')->where('doctor_id',$doctor['id'])->value('doctor_class');
|
|
|
+ if(strpos($role,'7') !== false){
|
|
|
+ $info['is_doctor'] = 1;
|
|
|
+ }else{
|
|
|
+ $info['is_doctor'] = 0;
|
|
|
+ }
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000','info'=>$info]);
|
|
|
+ }catch(\Exception $e){
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|