$request->post('rid'), "查询密码" => $request->post('password'), "文件Id" => $request->post('id') ]; $reportname=$request->post('reportname'); $username=$request->post('name'); $hospital_info = Hospital::where('id', $request->post('hospital'))->where('del', 2)->first(); if (!$hospital_info) Yo::error_echo(100000, ['机构/医院']); $code = $hospital_info->code; $peis = new PEISApiController(); $url = $peis::Api('报告文件下载', $code); $data_string = json_encode($data, JSON_UNESCAPED_UNICODE); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json; charset=utf-8', 'Content-Length: ' . strlen($data_string) ]); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); $res_string = curl_exec($ch); curl_close($ch); if ($res_string == '无效URL') Yo::error_echo(200065); $disk = Storage::disk('public'); $name = $request->post('id'); $date = $request->post('rid'); $name=$username.$data['体检号'].$reportname.'_'.$name; $path = "/assets/upload/pdf/$date/$name.pdf"; $put = $disk->put($path, $res_string); if (!$put) Yo::error_echo(100028, ['put']); $save = "/storage/assets/upload/pdf/$date/$name.pdf"; return Yo::echo([ 'url' => $save ]); } public function get_report($id) { $peis = new PEISApiController(); $report = $peis::Post('体检报告查询', request()->post('hospital'), [ "电话号码" => "", "证件号码" => '', "体检号" => $id ])['data']; // Yo::error_exit(['message'=>"res",'code'=>200,'data'=>$report]); return $report; } public function orderReport($report_data) { $report_data['收费项目列表'] = self::myUsort($report_data['收费项目列表'], ['收费项目顺序'], [0]); foreach ($report_data['收费项目列表'] as $key => $report_datum) { $report_data['收费项目列表'][$key]['基础项目列表'] = self::myUsort( $report_data['收费项目列表'][$key]['基础项目列表'], ['基础项目顺序'], [0] ); } return $report_data; } 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 myUsort($array, $key_array, $sort) { if (count($key_array) != count($sort)) return $array; usort($array, function ($a, $b) use ($key_array, $sort) { foreach ($key_array as $index => $key) { if ($a[$key] != $b[$key]) { return ($sort[$index] ? $a[$key] < $b[$key] : $a[$key] > $b[$key]) ? 1 : -1; } } return 1; }); return $array; } //报告预查询,检查报告内容是否存在PrepareCheckReport public function PrepareCheckReport(Request $request) { $id = $request->post('id'); $id_number = $request->post('id_number'); $date = $request->post('date'); $hospital = $request->post('hospital'); $analysis_type = AnalysisType::find($id); $mark = $analysis_type->mark; $peis = new PEISApiController(); $res = $peis::Post('体检报告查询', $hospital, [ "电话号码" => "", "证件号码" => $id_number, "体检号" => "" ])['data']; $info = [ 'title' => '', 'result' => '', 'name' => '', 'value' => '', 'date' => '', 'content' => '', 'table' => [ 'name' => '', 'list' => [] ], ]; $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 = []; foreach ($res as $re) { if ($re['体检状态'] == '报告已出') { $res_done_arr[] = $re; } } $res = $res_done_arr; $res = self::orderReportTime($res); $date_list = []; $datetime = ''; foreach ($res as $item) { $report_data = self::get_report($item['体检号']); // Yo::error_exit([ // 'message' => "res", // 'code' => 2001, // 'data' => $report_data // ]); $report = false; if (isset($report_data[0]['收费项目列表'])) { $report = self::orderReport($report_data[0]); } if (!!$report) { $datetime = explode('T', $report['登记时间'])[0]; foreach ($report['收费项目列表'] as $item) { foreach ($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 ($res as $item) { $report_data = self::get_report($item['体检号']); $report = false; if (isset($report_data[0]['收费项目列表'])) { $report = self::orderReport($report_data[0]); } if (!!$report) { $datetime = explode('T', $report['登记时间'])[0]; foreach ($report['收费项目列表'] as $item) { foreach ($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['基础项目名称']; } } } } } if ($rc == 0) Yo::error_echo(200081); if (!$range_str) Yo::error_echo(200081); return Yo::echo([ 'status' => 'ok', ]); } 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 = AnalysisType::find($id); $mark = $analysis_type->mark; $peis = new PEISApiController(); $res = $peis::Post('体检报告查询', $hospital, [ "电话号码" => "", "证件号码" => $id_number, "体检号" => "" ])['data']; $info = [ 'title' => '', 'result' => '', 'name' => '', 'value' => '', 'date' => '', 'content' => '', 'table' => [ 'name' => '', 'list' => [] ], ]; $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 = []; foreach ($res as $re) { if ($re['体检状态'] == '报告已出') { $res_done_arr[] = $re; } } $res = $res_done_arr; $res = self::orderReportTime($res); $date_list = []; $datetime = ''; foreach ($res as $item) { $report_data = self::get_report($item['体检号']); $report = false; if (isset($report_data[0]['收费项目列表'])) { $report = self::orderReport($report_data[0]); } if (!!$report) { $datetime = explode('T', $report['登记时间'])[0]; foreach ($report['收费项目列表'] as $item) { foreach ($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 ($res as $item) { $report_data = self::get_report($item['体检号']); $report = false; if (isset($report_data[0]['收费项目列表'])) { $report = self::orderReport($report_data[0]); } if (!!$report) { $datetime = explode('T', $report['登记时间'])[0]; foreach ($report['收费项目列表'] as $item) { foreach ($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['基础项目名称']; } } } } } if ($rc == 0) Yo::error_echo(200066); $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' => [], ]; if (!$range_str) Yo::error_echo(200066); $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 Yo::echo([ 'date' => $date, 'date_list' => $date_list, 'show' => $data_show, 'info' => $info, 'chart1_option' => $chart1_option, 'chart2_option' => $chart2_option, ]); } public function contrast(Request $request) { $ids = $request->post('ids'); $r1 = self::get_report($ids[0]); $r2 = self::get_report($ids[1]); if($r1[0]['体检状态']!='报告已出' or $r2[0]['体检状态']!='报告已出') Yo::error_echo(200090); $res = self::orderReportTime([$r1[0], $r2[0]]); $r1 = [$res[0]]; $r2 = [$res[1]]; $r1_datetime = ''; $r1_map = []; if (count($r1) != 0) { $r1_info = $r1[0]; foreach ($r1_info['收费项目列表'] as $item) { foreach ($item['基础项目列表'] as $i) { $r1_datetime = explode('T', $r1_info['登记时间'])[0]; $r1_map[$i['基础项目代码']] = $i; } } } $r2_map = []; $r2_datetime = ''; if (count($r2) != 0) { $r2_info = $r2[0]; foreach ($r2_info['收费项目列表'] as $item) { foreach ($item['基础项目列表'] as $i) { $r2_datetime = explode('T', $r2_info['登记时间'])[0]; $r2_map[$i['基础项目代码']] = $i; } } } $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 Yo::echo([ 'report_type1_content' => $report_type1_content, 'report_type2_content' => $report_type2_content, ]); } public function info(Request $request) { $id = $request->post('id'); $res = self::get_report($id); $conclusion = [ 'datetime' => '', 'doctor' => '', 'content' => '', 'suggestion' => '', ]; $content = []; $list = [ 'info' => [ 'id' => '', 'password' => '' ], 'list' => [] ]; if (count($res) != 0) { if($res[0]['体检状态']!='报告已出') Yo::error_echo(200090); $info = self::orderReport($res[0]); // Yo::error_exit([ // 'message' => "res", // 'code' => 2001, // 'data' => $res // ]); $list['info']['id'] = $info['体检号']; $list['info']['name'] = $info['姓名']; $list['info']['password'] = $info['查询密码']; $list['list'] = $info['报告文件列表']; $conclusion = [ 'datetime' => str_replace('T', ' ', $info['登记时间']), 'doctor' => $info['总检医生'], 'content' => $info['总检结论'], 'suggestion' => $info['总检建议'], ]; foreach ($info['收费项目列表'] as $item) { $content_list = []; foreach ($item['基础项目列表'] as $i) { $content_list[] = [ 'title' => $i['基础项目名称'], 'content' => $i['结果值'] .' '. $i['结果值单位'], 'icon' => $i['异常标识'], 'desc' => $i['结果值范围'], ]; } $content[] = [ 'title' => $item['收费项目名称'], 'datetime' => str_replace('T', ' ', $info['登记时间']), 'doctor' => $item['检查医生'], 'list' => $content_list ]; } } return Yo::echo([ 'conclusion' => $conclusion, 'content' => $content, 'list' => $list, ]); } public function list(Request $request) { $id_number = $request->post('id_number'); $phone = $request->post('phone'); $hospital = Hospital::where('id', $request->post('hospital'))->where('del', 2)->first(); if (!$hospital) Yo::error_echo(100000, ['机构/医院']); $peis = new PEISApiController(); $res = $peis::Post('体检报告查询', $hospital->id, [ "电话号码" => $phone, "证件号码" => $id_number, "体检号" => '' ])['data']; $list = []; foreach ($res as $item) { $list[] = [ 'id' => $item['体检号'], 'title' => explode('T', $item['登记时间'])[0] . ' 体检报告', 'desc' => $hospital->name, ]; } return Yo::echo(['list' => $list]); } }