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.

101 lines
5.0 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace App\Services;
use Illuminate\Support\Facades\DB;
class ReportService
{
public function Save($res)
{
//if(!isset($res['体检号'])) return \Yz::echoError1("数据非预期,缺失'体检号'");
if(!isset($res['体检号'])) return ['status'=>false,'msg'=>"数据非预期,缺失'体检号'",'data'=>'report'];
//根据体检号查询获取id万一不小心有多个相同的体检号 所以返回数组正常就1个
$report_l1_records_ids = DB::table('report_l1_records')->where(['体检号' => $res['体检号']])->pluck('id')->toArray();
//查找对应的收费项目列表 获取id数组
$report_l2_items_ids = DB::table('report_l2_items')->whereIn('reprort_l1_id', $report_l1_records_ids)->pluck('id')->toArray();
//查找 基础项目列表 删除
$report_l3_base_items_del = DB::table('report_l3_base_items')->whereIn('report_l2_id', $report_l2_items_ids)->delete();
//删除report_l2_items表数据
DB::table('report_l2_items')->whereIn('id', $report_l2_items_ids)->delete();
//删除report_l1_records表数据
DB::table('report_l1_records')->whereIn('id', $report_l1_records_ids)->delete();
//删除完后,进行添加
$r_data = [
"体检类型" => isset($res['体检类型']) ? $res['体检类型'] : null,
"查询密码" => isset($res['查询密码']) ? $res['查询密码'] : null,
"审核时间" => isset($res['审核时间']) ? $res['审核时间'] : null,
"总检医生" => isset($res['总检医生']) ? $res['总检医生'] : null,
"总检结论" => isset($res['总检结论']) ? $res['总检结论'] : null,
"总检建议" => isset($res['总检建议']) ? $res['总检建议'] : null,
"病种列表" => isset($res['病种列表']) ? json_encode($res['病种列表'], JSON_UNESCAPED_UNICODE) : null,
"报告文件列表" => isset($res['报告文件列表']) ? json_encode($res['报告文件列表'], JSON_UNESCAPED_UNICODE) : null,
"卡号" => $res['卡号'],
"证件类型" => $res['证件类型'],
"证件号码" => $res['证件号码'],
"地址" => $res['地址'],
"电话号码" => $res['电话号码'],
"婚姻状态" => $res['婚姻状态'],
"单位名称" => $res['单位名称'],
"批次Id" => $res['批次Id'],
"批次名称" => $res['批次名称'],
"部门名称" => $res['部门名称'],
"分组名称" => $res['分组名称'],
"体检号" => $res['体检号'],
"姓名" => $res['姓名'],
"性别" => $res['性别'],
"出生日期" => $res['出生日期'],
"登记时间" => $res['登记时间'],
"检前签到时间" => $res['检前签到时间'],
"体检状态" => $res['体检状态'],
"报告日期" => $res['报告日期'],
"套餐名称" => $res['套餐名称'],
"团检" => $res['团检'],
"支持下载报告文件" => $res['支持下载报告文件'],
];
$l1_id = DB::table('report_l1_records')->insertGetId($r_data);
if ($res['体检状态'] == '报告已出' || $res['体检状态'] == '总检完成') {
foreach ($res['收费项目列表'] as $key => $l2_item) {
$r2_data = [
"reprort_l1_id" => $l1_id,
"科室类型" => $l2_item['科室类型'],
"科室名称" => $l2_item['科室名称'],
"科室顺序" => $l2_item['科室顺序'],
"收费项目名称" => $l2_item['收费项目名称'],
"收费项目顺序" => $l2_item['收费项目顺序'],
"检查医生" => $l2_item['检查医生'],
"审核医生" => $l2_item['审核医生'],
"最后保存时间" => $l2_item['最后保存时间'],
];
$l2_id = DB::table('report_l2_items')->insertGetId($r2_data);
if ($l2_id) {
$report_l3_base_items = [];
foreach ($l2_item['基础项目列表'] as $key2 => $l3_item) {
$r3_data = [
"report_l2_id" => $l2_id,
"基础项目名称" => $l3_item['基础项目名称'],
"基础项目代码" => isset($l3_item['基础项目代码'])?$l3_item['基础项目代码']:$l3_item['基础项目Id'],
"基础项目顺序" => $l3_item['基础项目顺序'],
"结果类型" => $l3_item['结果类型'],
"结果值" => $l3_item['结果值'],
"结果值单位" => $l3_item['结果值单位'],
"结果值范围" => $l3_item['结果值范围'],
"异常标识" => $l3_item['异常标识'],
"所见" => $l3_item['所见'],
"描述" => $l3_item['描述'],
"结论" => $l3_item['结论'],
];
$report_l3_base_items[] = $r3_data;
}
//批量插入l3
DB::table('report_l3_base_items')->insert($report_l3_base_items);
}
}
}
//return \Yz::Return(true,"接收完成",'report');
return ['status'=>true,'msg'=>'接收完成','data'=>'report'];
}
}