From 9b361b4a2845744d0a2ae39f70b490c5921edaf9 Mon Sep 17 00:00:00 2001 From: wh <382379437@qq.com> Date: Wed, 17 Jul 2024 14:43:46 +0800 Subject: [PATCH] fixed --- .../application/api/controller/Reporttt.php | 203 ++++++++++++++++++ digital_doctor/config/app.php | 5 + 2 files changed, 208 insertions(+) create mode 100644 digital_doctor/application/api/controller/Reporttt.php diff --git a/digital_doctor/application/api/controller/Reporttt.php b/digital_doctor/application/api/controller/Reporttt.php new file mode 100644 index 0000000..6ed55bd --- /dev/null +++ b/digital_doctor/application/api/controller/Reporttt.php @@ -0,0 +1,203 @@ +url = $config['base_url']; + $chatobj->model = ''; + $chatobj->apiKey = $config['APIKey']; + + $answer_json_arr = []; + + $ticket = input('ticket'); + if(empty($ticket)){ + + return json(Tools::set_fail('ticket必须')); + } + $user = Db::table('fa_tt_users')->where('ticket',$ticket)->find(); + if(empty($user)){ + return json(Tools::set_fail('用户不存在')); + } + + $day3 = date('Y-m-d 00:00:00',strtotime('-3 day')); + $his_record = Db::table('fa_tt_chathistory') + //->where('username',$user['username']) + ->order('id asc') + ->where('createtime','>',$day3)//3天之内 + ->select(); + $config = [ + 'stream'=>false, + ]; + $content = [ + //["role" => "user", "content" => ''] + ]; + foreach ($his_record as $item){ + $content[] = ["role" => "user", "content" => $item['chat_msg']]; + } + $chatobj->setBefore($content); + + $chatobj->chat($question,$config,$answer_json_arr); + //把返回的报告保存起来 + foreach ($answer_json_arr as $josn){ + $item = json_decode($josn,true); + $choices = $item['choices']; + foreach ($choices as $choice){ + $data = [ + 'doctor'=>$user['username'], + //病人 + 'username'=>Db::table('fa_tt_users')->where('doctor',$user['username'])->value('username'), + 'report_content'=>$choice['message']['content'], + ]; + Db::table('fa_tt_medical_report')->insert($data); + } + } + } + + + /** + * desc:查询报告详情 + * + * api/Reporttt/getReportById + * 参数:dataid 报告id + * ticket:用户ticket + * author:wh + */ + function getReportById(){ + return Mmodel::catchJson(function (){ + $info = Db::table('fa_tt_medical_report') + ->where('id',input('dataid')) + ->find(); + return Tools::set_ok($info); + }); + } + /** + * desc:查询报告列表 + * + * api/Reporttt/getReportList + * 参数:username + * ticket:用户ticket + * + * author:wh + */ + function getReportList(){ + return Mmodel::catchJson(function (){ + $info = Db::table('fa_tt_medical_report') + ->select(); + return Tools::set_ok($info); + }); + } + + /** + * 修改报告 + * api/Reporttt/editReport + * 参数:dataid 报告数据id + name 病人姓名 + gender 病人性别: M=男性, F=女性 + age 病人年龄 + main_complaint 主诉 + medical_history 病史 + past_history 既往史 + allergy_history 过敏史 + family_history 家族史 + personal_history 个人史 + menstrual_marital_history 月经婚育史 + diagnosis 诊断 + treatment 医嘱 + */ + function editReport(){ + return Mmodel::catchJson(function (){ + //$ticket = input('ticket'); + //if(empty($ticket)){ + // return Tools::set_fail('ticket必须'); + //} + //$user = Db::table('fa_tt_users')->where('ticket',$ticket)->find(); + //修改基本信息 + $data = [ + //'username'=>$user['username'],//医生 + 'name'=>input('name',''),//病人姓名 + 'gender'=>input('gender',''),//病人性别: M=男性, F=女性 + 'age'=>input('age',''),//病人年龄 + 'main_complaint'=>input('main_complaint',''),//主诉 + 'medical_history'=>input('medical_history',''),//病史 + 'past_history'=>input('past_history',''),//既往史 + 'allergy_history'=>input('allergy_history',''),//过敏史 + 'family_history'=>input('family_history',''),//家族史 + 'personal_history'=>input('personal_history',''),//个人史 + 'menstrual_marital_history'=>input('menstrual_marital_history',''),//月经婚育史 + 'diagnosis'=>input('diagnosis',''),//诊断 + 'treatment'=>input('treatment',''),//医嘱 + ]; + //修改基本信息 + Mmodel::existsUpdateInsert('fa_tt_userbaseinfo',[ + //'username'=>input('username',''), + 'name'=>input('name',''), + ],$data); + + //修改报告 + $str = <<where('id',$dataid) + ->data(['report_content'=>$str]) + ->update(); + + return Tools::set_ok(); + }); + } +} \ No newline at end of file diff --git a/digital_doctor/config/app.php b/digital_doctor/config/app.php index 6711ecf..0492f4a 100644 --- a/digital_doctor/config/app.php +++ b/digital_doctor/config/app.php @@ -192,6 +192,11 @@ return [ ], ], + //数字人-报告生成接口 + 'ai_num_report_config'=>[ + 'base_url'=>'https://serverfastgpt.excn.top/api/v1/chat/completions', + 'APIKey'=>'fastgpt-e5wq9u6phvyfq4znrXfOuTHKHQHGjpcVBYay602ai5zv4HeOJRMDwT3ptm6', + ], //听译-报告生成接口 'ai_listen_report_config'=>[ 'base_url'=>'https://serverfastgpt.excn.top/api/v1/chat/completions',