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.

104 lines
5.2 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\Xml;
use Illuminate\Support\Facades\DB;
class ShenQingDanService
{
public function Save($result, $jsonData)
{
$Body = $result['message']['Request']["Body"];
$Header = $result['message']['Request']["Header"];
$orderList = isset($Body['AddRisAppBillRt']['OrderList']) ? $Body['AddRisAppBillRt']['OrderList'] : [];
if (!empty($orderList) && !isset($orderList[0])) {
// 如果OrderList当前不是数组的数组则将其转换为单元素数组
$orderList = array($orderList);
}
$insert_count = 0;//成功插入数量
DB::beginTransaction();
foreach ($orderList as $key => $order) {
$patient_type = null;
if (isset($Body["PATAdmInfo"]["PAADMTypeCode"])) {
$p = $Body["PATAdmInfo"]["PAADMTypeCode"];
if ($p == 'O') $patient_type = 1;
if ($p == 'H') $patient_type = 3;
if ($p == 'E') $patient_type = 2;
if ($p == 'I') $patient_type = 0;
}
$params = [
'list_status' => 0,
'reg_num' => $Body["PATPatientInfo"]["PATPatientID"] ? $Body["PATPatientInfo"]["PATPatientID"] : null,
'user_name' => $Body["PATPatientInfo"]["PATName"] ? $Body["PATPatientInfo"]["PATName"] : null,
'user_sex' => $Body["PATPatientInfo"]["PATName"] == '男' ? 1 : 2,
'entrust_code' => $order["RISRCode"] ? $order["RISRCode"] : null,
'entrust' => $order["RISRDesc"] ? $order["RISRDesc"] : null,
'is_pay' => $order["OrdBillStatus"] == '已收费' ? 1 : 0,
'reservation_department' => $order["AppDeptDesc"] ? $order["AppDeptDesc"] : null,
'entrust_date' => $order["RISRSubmitTime"] ? substr($order["RISRSubmitTime"], 0, 10) : null,
'entrust_time' => $order["RISRSubmitTime"] ? substr($order["RISRSubmitTime"], 11, 8) : null,
'user_brithday' => $Body["PATPatientInfo"]["PATDob"] ? $Body["PATPatientInfo"]["PATDob"] : null,
'docotr' => $Body["PATAdmInfo"]["PAADMDocDesc"] ? $Body["PATAdmInfo"]["PAADMDocDesc"] : null,
'patient_type' => $patient_type,
'user_phone' => $Body["PATPatientInfo"]["PATTelephone"] ? $Body["PATPatientInfo"]["PATTelephone"] : null,
'implement_department' => $order["RISRAcceptDeptDesc"] ? $order["RISRAcceptDeptDesc"] : null,
'entrust_id' => $order["OEORIOrderItemID"] ? $order["OEORIOrderItemID"] : null,//his传过来的本地医嘱id
'episodeid' => $Body["PATAdmInfo"]["PAADMVisitNumber"] ? $Body["PATAdmInfo"]["PAADMVisitNumber"] : null, //就诊号
'RISRExamID' => $order["RISRExamID"] ? $order["RISRExamID"] : null, //检查号
'RISRAcceptDeptCode' => $order["RISRAcceptDeptCode"] ? $order["RISRAcceptDeptCode"] : null, //接收科室代码
'warddesc' => $Body["PATAdmInfo"]["PAADMAdmWardDesc"] ? $Body["PATAdmInfo"]["PAADMAdmWardDesc"] : null, //病区
'beddesc' => $Body["PATAdmInfo"]["PAADMCurBedNo"] ? $Body["PATAdmInfo"]["PAADMCurBedNo"] : null, //病床号
];
$requiredFields = [
'reg_num', 'user_name', 'user_sex', 'entrust', 'is_pay',
'reservation_department', 'entrust_date', 'entrust_time',
'user_brithday', 'docotr', 'patient_type', 'user_phone',
'implement_department', 'entrust_id', 'episodeid', 'RISRAcceptDeptCode'
];
// 判断是否为空
foreach ($requiredFields as $field) {
if (!isset($params[$field]) || $params[$field] === null) {
// return \Yz::echoError1('参数' . $field . '不能为空');
DB::rollBack();
return \Yz::XMLReturn($Header['SourceSystem'], $Header['MessageID'], -1, '参数' . $field . '不能为空');
}
}
$insertListId = DB::table('s_list')->insertGetId($params);
if ($insertListId) {
$data = [
'list_id' => $insertListId,
'reg_num' => $Body["PATPatientInfo"]["PATPatientID"],
'new_status' => 0,
'create_user' => '接口',
'note' => '创建记录',
'data' => $jsonData,//原始数据
];
$insertLog = DB::table('s_list_log')->insert($data);
if ($insertLog) {
$insert_count++;
} else {
DB::rollBack();
return \Yz::XMLReturn($Header['SourceSystem'], $Header['MessageID'], -1, '失败');
}
} else {
DB::rollBack();
return \Yz::XMLReturn($Header['SourceSystem'], $Header['MessageID'], -1, '失败');
}
}
if (count($orderList) == $insert_count) {
DB::commit();
return \Yz::XMLReturn($Header['SourceSystem'], $Header['MessageID'], 0, '成功');
} else {
DB::rollBack();
return \Yz::XMLReturn($Header['SourceSystem'], $Header['MessageID'], -1, '失败');
}
}
}