fixed
This commit is contained in:
203
digital_doctor/application/api/controller/Reporttt.php
Normal file
203
digital_doctor/application/api/controller/Reporttt.php
Normal file
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/7/12} {11:29}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\gpt\chat\ChatGPT;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
/**
|
||||
* 疼痛科-数字人-报告
|
||||
* Class Reporttt
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Reporttt
|
||||
{
|
||||
|
||||
/**
|
||||
* desc:疼痛科-数字人-生成听诊报告
|
||||
*
|
||||
* api/Reporttt/createReport
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
function createReport(){
|
||||
//header('Content-Type: text/event-stream');
|
||||
//header('Cache-Control: no-cache');
|
||||
//header('Connection: keep-alive');
|
||||
//header('X-Accel-Buffering: no');
|
||||
$config = config('ai_num_report_config');
|
||||
|
||||
$question = '';//input('question','');
|
||||
|
||||
$chatobj = new ChatGPT();
|
||||
$chatobj->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 = <<<EOF
|
||||
【姓名】:{$data['name']}
|
||||
【年龄】:{$data['age']}
|
||||
【性别】:{$data['gender']}
|
||||
【主诉】:{$data['main_complaint']}
|
||||
【病史】:{$data['medical_history']}
|
||||
【既往史】:{$data['past_history']}
|
||||
【过敏史】:{$data['allergy_history']}
|
||||
【家族史】:{$data['family_history']}
|
||||
【个人史】:{$data['personal_history']}
|
||||
【月经婚育史】:{$data['menstrual_marital_history']}
|
||||
【诊断】:{$data['diagnosis']}
|
||||
【医嘱】:{$data['treatment']}
|
||||
EOF;
|
||||
|
||||
|
||||
|
||||
$dataid = input('dataid');
|
||||
if(empty($dataid)){
|
||||
return Tools::set_fail('dataid必须');
|
||||
}
|
||||
|
||||
Db::table('fa_tt_medical_report')
|
||||
->where('id',$dataid)
|
||||
->data(['report_content'=>$str])
|
||||
->update();
|
||||
|
||||
return Tools::set_ok();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user