You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
520 lines
18 KiB
PHP
520 lines
18 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API\H5;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Services\ReportService;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\API\PEISApiController;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class ReportController extends Controller
|
|
{
|
|
public function GetReportList()
|
|
{
|
|
$openid = request('openid');
|
|
$tj_status = request('tj_status');
|
|
$hospital_id=request('hospital_id');
|
|
if (!isset($openid)) return \Yz::echoError1("openid不能为空");
|
|
if (!isset($hospital_id)) return \Yz::echoError1("hospital_id不能为空");
|
|
|
|
$user = DB::table('web_users')->where(['openid' => $openid, 'status' => 1, 'is_del' => 0])->first();
|
|
if (!$user) return \Yz::echoError1('用户不存在');
|
|
$persons = DB::table('web_user_person')->where(['user_id' => $user->id, 'is_del' => 0])->pluck('id_number')->toArray();
|
|
$report_list=[];
|
|
$peis = new PEISApiController();
|
|
foreach ($persons as $key => $id_number) {
|
|
if(strlen($id_number)==0) continue;
|
|
$data = [
|
|
'电话号码' => "",
|
|
'证件号码' => $id_number,
|
|
'体检号' => ""
|
|
];
|
|
$reports = $peis::Post('体检报告查询', $hospital_id, $data);
|
|
if (count($reports['data']) > 0) {
|
|
$reports_detail_list = $reports['data'];
|
|
foreach ($reports_detail_list as $key => $reports_detail) {
|
|
$report_list[]=$reports_detail;
|
|
}
|
|
}
|
|
}
|
|
$list=[];
|
|
|
|
foreach ($report_list as $key => $report) {
|
|
$report_list[$key]['is_read']=0;
|
|
$report_list[$key]['登记时间']= explode('T', $report_list[$key]['登记时间'])[0];
|
|
if($report['体检状态']=='报告已出' || $report['体检状态']=='总检完成'){
|
|
$cha=DB::table('report_l1_records')->where(['体检号' => $report['体检号']])->first();
|
|
if(!!$cha and $cha->is_read==1){
|
|
$report_list[$key]['is_read']=1;
|
|
}
|
|
}
|
|
if(isset($tj_status) and $tj_status!==0){
|
|
if($tj_status==1 and $report['体检状态']=='报告已出' || $report['体检状态']=='总检完成'){
|
|
$list[]= $report_list[$key];
|
|
}
|
|
if($tj_status==2 and $report['体检状态']=='报告未出'){
|
|
$list[]= $report_list[$key];
|
|
}
|
|
}else{
|
|
$list[]= $report_list[$key];
|
|
}
|
|
|
|
}
|
|
return \Yz::Return(true, "查询完成", ['list' => $list]);
|
|
|
|
|
|
// $list = DB::table('report_l1_records')->select('姓名', '性别', '登记时间', '套餐名称', '体检号', '体检状态', 'is_read')->whereIn('证件号码', $persons);
|
|
// if(isset($tj_status) and $tj_status!==0){
|
|
// if($tj_status===1){
|
|
// $tj_status='报告未出';
|
|
// $list=$list->where('体检状态', $tj_status);
|
|
//
|
|
// }
|
|
// if($tj_status===2){
|
|
// $tj_status='报告已出';
|
|
// $list=$list->where('体检状态', $tj_status);
|
|
// $list = $list->where(function ($query) use ($tj_status) {
|
|
// $query->where('体检状态', '报告已出')->orWhere('体检状态', '总检完成');
|
|
// });
|
|
// }
|
|
//
|
|
// }
|
|
// $list=$list->get();
|
|
// return \Yz::Return(true, "查询完成", ['list' => $list]);
|
|
}
|
|
|
|
public function GetReportJieLunJianYi()
|
|
{
|
|
$YiBanJianChaList = [
|
|
['name' => "身高(cm)",
|
|
'code' => "SG"],
|
|
['name' => "体重(kg)",
|
|
'code' => "TZ"],
|
|
['name' => "收缩压",
|
|
'code' => "XY(SSY)"],
|
|
['name' => "血红蛋白",
|
|
'code' => "BXBSM"],
|
|
];
|
|
$tijian_num = request('tijian_num');
|
|
$hospital_id=request('hospital_id');
|
|
if (!isset($tijian_num)) return \Yz::echoError1("tijian_num不能为空");
|
|
if (!isset($hospital_id)) return \Yz::echoError1("hospital_id不能为空");
|
|
$report = DB::table('report_l1_records as a')->where(['a.体检号' => $tijian_num])->first();
|
|
if (!$report) {
|
|
//如果本地没报告,则尝试拉取一下思信的报告
|
|
$peis = new PEISApiController();
|
|
$data = [
|
|
'电话号码' => "",
|
|
'证件号码' => "",
|
|
'体检号' => $tijian_num
|
|
];
|
|
$res = $peis::Post('体检报告查询', $hospital_id, $data);
|
|
if(count($res['data']) > 0) {
|
|
$res = $res['data'][0];
|
|
$report_res = new ReportService();
|
|
$save= $report_res->Save($res);
|
|
if($save['status']){
|
|
$report = DB::table('report_l1_records as a')->where(['a.体检号' => $tijian_num])->first();
|
|
}else{
|
|
return $save;
|
|
}
|
|
}else{
|
|
return \Yz::echoError1("查询报告详情失败");
|
|
}
|
|
|
|
}
|
|
if (!!$report){
|
|
if ($report->体检状态 == '报告未出') return \Yz::echoError1("此报告暂时未出");
|
|
$items = DB::table('report_l2_items as b')->leftJoin('report_l3_base_items as c', 'b.id', '=', 'c.report_l2_id')->where(['b.reprort_l1_id' => $report->id])->get();
|
|
$v_error_items = [];
|
|
$error_items = [];
|
|
$base_items = [];
|
|
foreach ($items as $item) {
|
|
foreach ($YiBanJianChaList as $ybitem) {
|
|
if ($item->基础项目代码 == $ybitem['code']) {
|
|
$base_items[] = [
|
|
'name' => $ybitem['name'],
|
|
'value' => $item->结果值,
|
|
];
|
|
}
|
|
}
|
|
if ($item->异常标识 != null and $item->异常标识 != '') {
|
|
$error_items[] = $item;
|
|
}
|
|
}
|
|
|
|
$info = [];
|
|
$info['name'] = $report->姓名;
|
|
$info['base_date'] = $base_items;
|
|
$info['items'] = [
|
|
'all_count' => count($items),
|
|
'ipt_error_count' => count($v_error_items),//重要异常数量
|
|
'error_count' => count($error_items),//异常数量
|
|
|
|
];
|
|
$info['content'] = $report->总检建议;
|
|
DB::table('report_l1_records')->where(['id' => $report->id])->update(['is_read' => 1]);
|
|
return \Yz::Return(true, "查询完成", ['info' => $info]);
|
|
}
|
|
}
|
|
|
|
//完整报告中的列表
|
|
public function GetReportDetaiList()
|
|
{
|
|
$tijian_num = request('tijian_num');
|
|
$report = DB::table('report_l1_records as a')->where(['a.体检号' => $tijian_num])->first();
|
|
if (!$report) return \Yz::echoError1("查询报告失败");
|
|
if ($report->体检状态 == '报告未出') return \Yz::echoError1("此报告暂时未出");
|
|
$items = DB::table('report_l2_items as b')->leftJoin('report_l3_base_items as c', 'b.id', '=', 'c.report_l2_id')->where(['b.reprort_l1_id' => $report->id])->get();
|
|
$list = [];
|
|
|
|
foreach ($items as $item) {
|
|
$ShouFeiName = $item->收费项目名称;
|
|
if (!isset($list[$ShouFeiName])) {
|
|
$error_count = 0;
|
|
$list[$ShouFeiName] = ['id' => $item->report_l2_id, 'error_count' => $error_count];
|
|
}
|
|
if ($item->异常标识 != null and $item->异常标识 != '') {
|
|
$error_count++;
|
|
}
|
|
$list[$ShouFeiName] = ['id' => $item->report_l2_id, 'error_count' => $error_count];
|
|
}
|
|
return \Yz::Return(true, "查询完成", ['list' => $list]);
|
|
}
|
|
|
|
public function GetReportDetai()
|
|
{
|
|
$id = request('id');
|
|
$l2 = DB::table('report_l2_items')->where(['id' => $id])->first();
|
|
$items = DB::table('report_l3_base_items')->where(['report_l2_id' => $id])->orderBy('基础项目顺序')->get();
|
|
if ($l2->科室类型 == 'PACS') {
|
|
$suojian = [];
|
|
$zhenduan = [];
|
|
foreach ($items as $item) {
|
|
$suojian[] = $item->所见;
|
|
$jielun[] = $item->结论;
|
|
}
|
|
|
|
if (count($items) > 0) {
|
|
return \Yz::Return(true, "查询完成", ['is_pacs'=>true,'suojian' => $suojian,'jielun' => $jielun]);
|
|
} else {
|
|
return \Yz::echoError1('此项暂无内容');
|
|
}
|
|
|
|
} else {
|
|
|
|
$error_items = [];
|
|
foreach ($items as $item) {
|
|
if ($item->异常标识 != null and $item->异常标识 != '') {
|
|
$m = '';
|
|
if ($item->异常标识 == '↓') {
|
|
$m = '低';
|
|
}
|
|
if ($item->异常标识 == '↑') {
|
|
$m = '高';
|
|
}
|
|
$error_items[] = $item->基础项目名称 . $m;
|
|
}
|
|
if($item->结果类型=='数值' and $item->结果值!='' and $item->结果值!=null and $item->结果值范围!='' and $item->结果值范围 !=null){
|
|
|
|
$range = $this->convertToArray($item->结果值范围);
|
|
|
|
$item->结果值范围=$range;
|
|
$item->最大范围=[];
|
|
if(count($range)>1){
|
|
$kuadu=$range[1]-$range[0];
|
|
if($item->结果值=='未见') $item->结果值=0;
|
|
if(($item->结果值-$range[1])/$kuadu<=1){
|
|
$max=$range[1]+$kuadu;
|
|
}else{
|
|
$max=$item->结果值;
|
|
}
|
|
$item->最大范围=[0,$max];
|
|
}
|
|
}
|
|
}
|
|
if (count($items) > 0) {
|
|
return \Yz::Return(true, "查询完成", ['is_pacs'=>false,'list' => $items, 'error_items' => $error_items]);
|
|
} else {
|
|
return \Yz::echoError1('此项暂无内容');
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
function convertToArray($input) {
|
|
// 检查是否是范围表示法
|
|
if (preg_match('/^(\d*\.?\d*)-(\d*\.?\d*)$/', $input, $matches)) {
|
|
return [(float)$matches[1], (float)$matches[2]];
|
|
}
|
|
|
|
// 检查是否是小于符号
|
|
if (preg_match('/^<(\d*\.?\d*)$/', $input, $matches)) {
|
|
return [0, (float)$matches[1]];
|
|
}
|
|
|
|
// 检查是否是小于等于符号
|
|
if (preg_match('/^<=(\d*\.?\d*)$/', $input, $matches)) {
|
|
return [0, (float)$matches[1]];
|
|
}
|
|
|
|
// 如果没有匹配,返回原始输入
|
|
return $input;
|
|
}
|
|
public function contrast(Request $request)
|
|
{
|
|
$ids = $request->post('tj_numbers');
|
|
if(count($ids)<>2) return \Yz::echoError1("请选择两份报告");
|
|
if($ids[0]==$ids[1]) return \Yz::echoError1('不能选择相同的报告');
|
|
sort($ids);
|
|
$report1=DB::table('report_l1_records as a')->leftJoin('report_l2_items as b' ,'a.id','=','b.reprort_l1_id')->where('a.体检号',$ids[0])->whereIn('体检状态',['报告已出','总检完成'])->get();
|
|
$report2=DB::table('report_l1_records as a')->leftJoin('report_l2_items as b' ,'a.id','=','b.reprort_l1_id')->where('a.体检号',$ids[1])->whereIn('体检状态',['报告已出','总检完成'])->get();
|
|
if(count($report1)==0 || count($report2)==0) return \Yz::echoError1("有未出报告,无法对比");
|
|
$ids1=$ids = $report1->pluck('id')->all();
|
|
$ids2=$ids = $report2->pluck('id')->all();
|
|
|
|
$report1_jc_item=DB::table('report_l3_base_items')->whereIn('report_l2_id',$ids1)->get();
|
|
$report2_jc_item=DB::table('report_l3_base_items')->whereIn('report_l2_id',$ids2)->get();
|
|
//dd($report1_jc_item,$report2_jc_item);
|
|
$r1_datetime =$report1[0]->报告日期;
|
|
$r2_datetime =$report2[0]->报告日期;
|
|
$r1_map = [];
|
|
foreach ($report1_jc_item as $i) {
|
|
$r1_map[$i->基础项目代码] = json_decode(json_encode($i,JSON_UNESCAPED_UNICODE),true);
|
|
}
|
|
$r2_map = [];
|
|
foreach ($report2_jc_item as $i) {
|
|
$r2_map[$i->基础项目代码] = json_decode(json_encode($i,JSON_UNESCAPED_UNICODE),true);
|
|
}
|
|
|
|
$clear_type1_list = [];
|
|
$clear_type2_list = [];
|
|
$id = 1;
|
|
foreach ($r1_map as $key => $item) {
|
|
$r2_data = isset($r2_map[$key]) ? [
|
|
'date' => $r2_datetime,
|
|
'content' => $r2_map[$key]['结果值'] . $r2_map[$key]['结果值单位'],
|
|
'icon' => $r2_map[$key]['异常标识'],
|
|
'desc' => $r2_map[$key]['结果值范围'],
|
|
] : [
|
|
'date' => $r2_datetime,
|
|
'content' => '',
|
|
'icon' => '',
|
|
'desc' => ''
|
|
];
|
|
$i = [
|
|
'id' => $id,
|
|
'title' => $item['基础项目名称'],
|
|
'r1' => [
|
|
'date' => $r1_datetime,
|
|
'content' => $item['结果值'] . $item['结果值单位'],
|
|
'icon' => $item['异常标识'],
|
|
'desc' => $item['结果值范围'],
|
|
],
|
|
'r2' => $r2_data
|
|
];
|
|
if ($item['结果类型'] == '数值') {
|
|
$clear_type2_list[$key] = $i;
|
|
} else {
|
|
$clear_type1_list[$key] = $i;
|
|
}
|
|
$id = $id + 1;
|
|
}
|
|
foreach ($r2_map as $key => $item) {
|
|
$r1_data = isset($r1_map[$key]) ? [
|
|
'date' => $r1_datetime,
|
|
'content' => $r1_map[$key]['结果值'] . $r1_map[$key]['结果值单位'],
|
|
'icon' => $r1_map[$key]['异常标识'],
|
|
'desc' => $r1_map[$key]['结果值范围'],
|
|
] : [
|
|
'date' => $r1_datetime,
|
|
'content' => '',
|
|
'icon' => '',
|
|
'desc' => '',
|
|
];
|
|
$i = [
|
|
'id' => $id,
|
|
'title' => $item['基础项目名称'],
|
|
'r1' => $r1_data,
|
|
'r2' => [
|
|
'date' => $r2_datetime,
|
|
'content' => $item['结果值'] . $item['结果值单位'],
|
|
'icon' => $item['异常标识'],
|
|
'desc' => $item['结果值范围'],
|
|
]
|
|
];
|
|
if ($item['结果类型'] == '数值') {
|
|
$clear_type2_list[$key] = $i;
|
|
} else {
|
|
$clear_type1_list[$key] = $i;
|
|
}
|
|
$id = $id + 1;
|
|
}
|
|
$report_type1_content = [];
|
|
$report_type2_content = [];
|
|
foreach ($clear_type1_list as $item) {
|
|
$report_type1_content[] = $item;
|
|
}
|
|
foreach ($clear_type2_list as $item) {
|
|
$report_type2_content[] = $item;
|
|
}
|
|
return \Yz::return(true,"",[
|
|
'report_type1_content' => $report_type1_content,
|
|
'report_type2_content' => $report_type2_content,
|
|
]);
|
|
}
|
|
public function orderReportTime($res)
|
|
{
|
|
foreach ($res as $key => $re) {
|
|
$res[$key]['order_time'] = date('YmdHi', strtotime($re['登记时间']));
|
|
}
|
|
return self::myUsort($res, ['order_time'], [0]);
|
|
}
|
|
|
|
|
|
//趋势分析
|
|
public function Analysis(Request $request)
|
|
{
|
|
$id = $request->post('id');
|
|
$id_number = $request->post('id_number');
|
|
$date = $request->post('date');
|
|
$hospital = $request->post('hospital');
|
|
$analysis_type = DB::table('analysis_types')->where('id', $id)->first();
|
|
$mark = $analysis_type->mark;
|
|
$value = 0;
|
|
$unit = '';
|
|
$info['title'] = $analysis_type->name;
|
|
$info['content'] = $analysis_type->content;
|
|
$range_data = json_decode($analysis_type->range, true);
|
|
$range = $range_data['r'];
|
|
$label = $range_data['l'];
|
|
$step = $range_data['s'];
|
|
$color = ['#357e24', '#a7ea9b', '#95cde8', '#f0a93f', '#f0a93f', '#ec572c'];
|
|
$time = 0;
|
|
$range_str = '';
|
|
$data_arr = [];
|
|
$res_done_arr = [];
|
|
//查询数据库
|
|
$reports=DB::table('report_l1_records')->where(['证件号码'=>$id_number])
|
|
->whereIn('体检状态',['报告已出','总检完成'])->orderBy('报告日期','asc')->get();
|
|
$date_list = [];
|
|
$datetime = '';
|
|
foreach ($reports as $item) {
|
|
$datetime=explode('T', $item->登记时间)[0];
|
|
$jc_item=DB::table('report_l2_items as a')->leftJoin('report_l3_base_items as b','a.id','=','b.report_l2_id')->where(['a.reprort_l1_id'=>$item->id])->get();
|
|
foreach ($jc_item as $i) {
|
|
if ($i->基础项目代码 == $mark) {
|
|
if ($i->结果类型 == '数值' && !!$i->结果值范围) {
|
|
$date_list[] = $datetime;
|
|
$result = '正常';
|
|
if ($i->异常标识 == '↑') $result = '偏高';
|
|
if ($i->异常标识 == '↓') $result = '偏低';
|
|
$range_str = $i->结果值范围;
|
|
if (strtotime($datetime) > $time) {
|
|
$info['result'] = $result;
|
|
$info['value'] = $i->异常标识 . $i->结果值 . $i->结果值单位;
|
|
$value = $i->结果值;
|
|
$data_arr[] = [
|
|
'value' => $value,
|
|
'datetime' => $datetime,
|
|
];
|
|
$unit = $i->结果值单位;
|
|
$info['date'] = $datetime;
|
|
$time = strtotime($datetime);
|
|
}
|
|
$info['name'] = $i->基础项目名称;
|
|
$info['table']['name'] = $i->基础项目名称;
|
|
$info['table']['list'][] = [
|
|
'date' => $datetime,
|
|
'value' => $i->异常标识 . $i->结果值,
|
|
'assess' => $result,
|
|
];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ($date == '') $date = $datetime;
|
|
$rc = 0;
|
|
foreach ($reports as $item) {
|
|
$datetime=explode('T', $item->登记时间);
|
|
$jc_item=DB::table('report_l2_items as a')->leftJoin('report_l3_base_items as b','a.id','=','b.report_l2_id')->where(['a.reprort_l1_id'=>$item->id])->get();
|
|
foreach ($jc_item as $i) {
|
|
if ($i->基础项目代码 == $mark) {
|
|
$result = '正常';
|
|
if ($i->异常标识 == '↑') $result = '偏高';
|
|
if ($i->异常标识 == '↓') $result = '偏低';
|
|
if ($datetime == $date) {
|
|
$info['result'] = $result;
|
|
$info['value'] = $i->异常标识 . $i->结果值 . $i->结果值单位;
|
|
$value = $i->结果值;
|
|
$unit = $i->结果值单位;
|
|
$info['date'] = $datetime;
|
|
$rc++;
|
|
}
|
|
$info['name'] = $i->基础项目名称;
|
|
$info['table']['name'] = $i->基础项目名称;
|
|
}
|
|
}
|
|
}
|
|
|
|
$chart1_option = [
|
|
'show' => true,
|
|
'range' => [],
|
|
'min' => 0,
|
|
'max' => 0,
|
|
'value' => $value,
|
|
'label' => $label,
|
|
];
|
|
$chart2_option = [
|
|
'show' => true,
|
|
'data' => $data_arr,
|
|
'min' => 0,
|
|
'max' => 0,
|
|
'unit' => $unit,
|
|
'step' => $step,
|
|
'range' => [],
|
|
];
|
|
|
|
$data_show = true;
|
|
if (!$range_str) {
|
|
$data_show = false;
|
|
$chart1_option['show'] = false;
|
|
$chart2_option['show'] = false;
|
|
} else if (strstr($range_str, '>') || strstr($range_str, '<')) {
|
|
$data_show = false;
|
|
$chart1_option['show'] = false;
|
|
$chart2_option['show'] = false;
|
|
} else {
|
|
$range_str = str_replace('~~', '-', $range_str);
|
|
$range_str = str_replace('--', '-', $range_str);
|
|
$range_str = str_replace('~', '-', $range_str);
|
|
$range_arr = explode('-', $range_str);
|
|
$min_index = array_search("min", $range);
|
|
$max_index = array_search("max", $range);
|
|
$range[$min_index] = $range_arr[0];
|
|
$range[$max_index] = $range_arr[1];
|
|
$chart1_option['min'] = $range_arr[0];
|
|
$chart1_option['max'] = $range_arr[1];
|
|
$chart2_option['range'] = $range_arr;
|
|
$chart2_option['min'] = $range[0];
|
|
$chart2_option['max'] = $range[count($range) - 1];
|
|
foreach ($range as $key => $item) {
|
|
$chart1_option['range'][] = [
|
|
'percent' => $item / ($range[count($range) - 1] - $range[0]),
|
|
'value' => $item,
|
|
'color' => $color[$key - $min_index + 1],
|
|
];
|
|
}
|
|
}
|
|
return \Yz::return(true,"查询完成",[
|
|
'date' => $date,
|
|
'date_list' => $date_list,
|
|
'show' => $data_show,
|
|
'info' => $info,
|
|
'chart1_option' => $chart1_option,
|
|
'chart2_option' => $chart2_option,
|
|
]);
|
|
}
|
|
}
|