@ -257,6 +257,113 @@ class ReportController extends Controller
// 如果没有匹配,返回原始输入
return $input;
}
public function contrast(Request $request)
{
$ids = $request->post('tj_numbers');
if(count($ids)< >2) 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]);
}
}