You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
981 lines
38 KiB
981 lines
38 KiB
using Dapper;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Logging;
|
|
using Newtonsoft.Json;
|
|
using Npgsql;
|
|
using ServiceReferenceHzcyHis;
|
|
using ServiceReferenceYinHai;
|
|
using Shentun.Peis.ChargeRequests;
|
|
using Shentun.Peis.Enums;
|
|
using Shentun.Peis.PlugIns.ChargeRequests;
|
|
using Shentun.Peis.PlugIns.Extensions.ChargeRequests.Hzcy;
|
|
using Shentun.Peis.PlugIns.Extensions.ChargeRequests.YinHai.FeeBacks;
|
|
using Shentun.Peis.PlugIns.Extensions.ChargeRequests.YinHai.His;
|
|
using Shentun.Peis.PlugIns.PatientRegisters;
|
|
using Shentun.Peis.ThirdInterfaces;
|
|
using Shentun.Utilities;
|
|
using Spire.Pdf.Exporting.XPS.Schema;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Common;
|
|
using System.Linq;
|
|
using System.ServiceModel;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml;
|
|
|
|
namespace Shentun.Peis.PlugIns.Extensions.ChargeRequests.YinHai
|
|
{
|
|
public class ChargeRequestPlugInsYinHai
|
|
{
|
|
|
|
protected IConfiguration? AppConfig;
|
|
private readonly string AppConnctionStr;
|
|
private readonly IConfiguration? InterfaceConfig;
|
|
private readonly ThirdInterfaceDto? _thirdInterfaceDto;
|
|
private readonly PluginLogger _logger; // 添加日志实例
|
|
|
|
static ChargeRequestPlugInsYinHai()
|
|
{
|
|
Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true;
|
|
|
|
}
|
|
|
|
public ChargeRequestPlugInsYinHai(Guid thirdInterfaceId)
|
|
{
|
|
_logger = new PluginLogger();
|
|
AppConfig = new ConfigurationBuilder()
|
|
.SetBasePath(DirectoryHelper.GetAppDirectory()) // 设置基础路径为当前目录
|
|
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
|
.Build();
|
|
AppConnctionStr = AppConfig.GetSection("ConnectionStrings")
|
|
.GetSection("Default").Value;
|
|
|
|
|
|
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
|
|
{
|
|
string sql;
|
|
sql = @"
|
|
SELECT *
|
|
from third_interface
|
|
where id =@ThirdInterfaceId
|
|
";
|
|
_thirdInterfaceDto = (conn.Query<ThirdInterfaceDto>(sql,
|
|
new { ThirdInterfaceId = thirdInterfaceId })).Single();
|
|
|
|
|
|
}
|
|
|
|
var configurationBuilder = new ConfigurationBuilder()
|
|
.AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(_thirdInterfaceDto.ParmValue)));
|
|
InterfaceConfig = configurationBuilder.Build();
|
|
}
|
|
public ChargeRequestPlugInsYinHai(string parmValue)
|
|
{
|
|
_logger = new PluginLogger();
|
|
AppConfig = new ConfigurationBuilder()
|
|
.SetBasePath(DirectoryHelper.GetAppDirectory()) // 设置基础路径为当前目录
|
|
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
|
.Build();
|
|
AppConnctionStr = AppConfig.GetSection("ConnectionStrings")
|
|
.GetSection("Default").Value;
|
|
|
|
var configurationBuilder = new ConfigurationBuilder()
|
|
.AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
|
|
InterfaceConfig = configurationBuilder.Build();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 发送收费申请
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="Exception"></exception>
|
|
public async Task<ChargeRequestPlugInsOut> SendChargeRequestAsync(ChargeRequestPlugInsInput input)
|
|
{
|
|
|
|
|
|
_logger.Log("银海收费申请", $"收费申请Id:{input.ChargeRequestId}");
|
|
|
|
|
|
try
|
|
{
|
|
//建立人员档案
|
|
var patientRegisterForPlugIns = await GetPatientRegisterAsync(input.ChargeRequestId);
|
|
var chargeRequestForPlugIns = await GetChargeRequestAsync(input.ChargeRequestId);
|
|
if (chargeRequestForPlugIns == null)
|
|
{
|
|
throw new Exception("没有申请单信息");
|
|
}
|
|
if (!chargeRequestForPlugIns.Asbitems.Any())
|
|
{
|
|
throw new Exception("申请单没有组合项目信息");
|
|
}
|
|
if (patientRegisterForPlugIns.BirthDate == null)
|
|
{
|
|
throw new Exception("出生日期不能为空");
|
|
}
|
|
|
|
|
|
var endpointAddress = InterfaceConfig.GetValue("Interface:EndpointAddress", "");
|
|
if (string.IsNullOrWhiteSpace(endpointAddress))
|
|
{
|
|
throw new Exception("接口地址不能为空");
|
|
}
|
|
|
|
|
|
|
|
|
|
string actionName = "fee_call";
|
|
string codeName = "peis_server";
|
|
|
|
|
|
using (var client = new WebServiceClient(new BasicHttpBinding(),
|
|
new EndpointAddress(endpointAddress)))
|
|
{
|
|
//// 添加消息拦截器行为
|
|
//var behavior = new SoapEndpointBehavior();
|
|
//client.Endpoint.EndpointBehaviors.Add(behavior);
|
|
|
|
var request = new HisFeeCallDto();
|
|
#region head
|
|
string requestId = new Random().Next(100000, 999999).ToString();
|
|
string timestamp = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
request.Head = new HisFeeCallHeadDto
|
|
{
|
|
Action = actionName,
|
|
Code = codeName,
|
|
ObjectSystem = "his",
|
|
RequestId = requestId,
|
|
Sign = "",
|
|
SourceSystem = "peis",
|
|
Timestamp = timestamp,
|
|
Version = "1"
|
|
};
|
|
|
|
string headString = $"version={request.Head.Version}×tamp={request.Head.Timestamp}&request_id={request.Head.RequestId}&source_system={request.Head.SourceSystem}&object_system={request.Head.ObjectSystem}&action={request.Head.Action}";
|
|
string sign = Convert.ToBase64String(Encoding.UTF8.GetBytes(headString));
|
|
request.Head.Sign = sign;
|
|
#endregion
|
|
|
|
var orgCode = InterfaceConfig.GetValue("Interface:OrgCode", "");
|
|
var orgName = InterfaceConfig.GetValue("Interface:OrgName", "");
|
|
var systemSource = InterfaceConfig.GetValue("Interface:SystemSource", "");
|
|
var billingDeptCode = InterfaceConfig.GetValue("Interface:BillingDeptCode", "");
|
|
var billingDeptName = InterfaceConfig.GetValue("Interface:BillingDeptName", "");
|
|
|
|
var commonTableTypeId = InterfaceConfig.GetValue("Interface:CommonTableTypeId", "");
|
|
var execDoctorUser = InterfaceConfig.GetValue("Interface:ExecDoctorUser", "");
|
|
|
|
var chargeUser = await GetUserInfo(patientRegisterForPlugIns.CreatorId);
|
|
|
|
var dataDetails = new List<HisFeeCallBodyDataDetailDto>();
|
|
var dataRequest = new HisFeeCallBodyDataRequestDto
|
|
{
|
|
OrgCode = orgCode,
|
|
OrgName = orgName,
|
|
SystemSource = systemSource,
|
|
VisitId = patientRegisterForPlugIns.PatientRegisterNo,
|
|
PatientId = patientRegisterForPlugIns.PatientNo,
|
|
PatientName = patientRegisterForPlugIns.PatientName,
|
|
GenderCode = ConvertSex(patientRegisterForPlugIns.SexId),
|
|
Birthday = patientRegisterForPlugIns.BirthDate == null ? "" : patientRegisterForPlugIns.BirthDate.Value.ToString("yyyy-MM-dd"),
|
|
CheckupType = "0",
|
|
SumCost = "0",
|
|
RealCost = chargeRequestForPlugIns.Asbitems.Sum(s => s.Charges).ToString(),
|
|
BillingDeptCode = billingDeptCode,
|
|
BillingDeptName = billingDeptName,
|
|
BillingDocCode = chargeUser.UserName,
|
|
BillingDocName = chargeUser.Surname,
|
|
CheckoutId = chargeRequestForPlugIns.ChargeRequestNo,
|
|
Address = "",
|
|
CheckupTime = "",
|
|
IdCard = patientRegisterForPlugIns.IdNo,
|
|
ThisRegisterCount = "",
|
|
TeamCheckupTime = "",
|
|
Phone = "",
|
|
TeamAppointmentNo = "",
|
|
TeamCode = "",
|
|
TeamName = ""
|
|
};
|
|
|
|
|
|
#region 对照关系
|
|
|
|
var yinHaiHisCommonTableList = await GetCommonTableByTypeId(commonTableTypeId);
|
|
|
|
#endregion
|
|
|
|
decimal sumCost = 0M;
|
|
|
|
foreach (var item in chargeRequestForPlugIns.Asbitems)
|
|
{
|
|
var dzList = yinHaiHisCommonTableList.Where(f => f.DisplayName == item.AsbitemId.ToString());
|
|
|
|
if (!dzList.Any())
|
|
{
|
|
throw new Exception($"项目【{item.AsbitemName},Id:{item.AsbitemId}】没有对照");
|
|
}
|
|
|
|
foreach (var dzEnt in dzList)
|
|
{
|
|
dataDetails.Add(new HisFeeCallBodyDataDetailDto
|
|
{
|
|
VisitId = patientRegisterForPlugIns.PatientRegisterNo,
|
|
DetailNo = patientRegisterForPlugIns.PatientRegisterNo + dzEnt.HisCode,
|
|
CheckoutId = chargeRequestForPlugIns.ChargeRequestNo,
|
|
OrgCode = orgCode,
|
|
SystemSource = systemSource,
|
|
FeeDetailNo = dzEnt.HisCode,
|
|
FeeName = dzEnt.HisName,
|
|
Price = dzEnt.HisPrice,
|
|
Count = dzEnt.HisCount,
|
|
DeptId = "",
|
|
DeptName = "",
|
|
PortfolioNo = "",
|
|
RealPrice = item.Charges.ToString()
|
|
});
|
|
|
|
sumCost += (decimal.Parse(dzEnt.HisPrice) * Int32.Parse(dzEnt.HisCount));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
dataRequest.SumCost = sumCost.ToString();
|
|
|
|
var requestBody = new HisFeeCallBodyDto
|
|
{
|
|
Data = new HisFeeCallBodyDataDto
|
|
{
|
|
Request = dataRequest,
|
|
RequestDetails = new HisFeeCallBodyDataDetailsDto
|
|
{
|
|
Details = dataDetails
|
|
}
|
|
}
|
|
};
|
|
|
|
request.Body = requestBody;
|
|
|
|
|
|
var requestXml = XmlHelper.SerializeToXmlEmpty(request);
|
|
|
|
|
|
var resultP = await client.callBussinessAsync(requestXml);
|
|
|
|
|
|
|
|
if (resultP.data.status_code == "1")
|
|
{
|
|
//成功 回写his_charge_no 就用体检本身的收费申请号,用于区分是否发送过申请
|
|
await UpdateChargeRequestHisChargeNo(chargeRequestForPlugIns.ChargeRequestNo);
|
|
|
|
}
|
|
|
|
var returnValue = JsonConvert.SerializeObject(resultP.data, Newtonsoft.Json.Formatting.Indented);
|
|
|
|
_logger.Log("银海收费申请", $"发送结果:{returnValue}");
|
|
|
|
var yinHaiSendInterfaceLogDto = new YinHaiSendInterfaceLogDto
|
|
{
|
|
LogName = "发送收费申请",
|
|
ExecDoctorUser = Guid.Parse(execDoctorUser),
|
|
InterfaceName = $"{codeName}_{actionName}",
|
|
ParaValue = requestXml,
|
|
RequestNo = dataRequest.CheckoutId,
|
|
ReturnParaValue = returnValue
|
|
};
|
|
|
|
await AddSendLog(yinHaiSendInterfaceLogDto);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// Console.WriteLine(ex.Message);
|
|
_logger.Log("银海收费申请", ex, $"发送收费申请异常");
|
|
}
|
|
|
|
|
|
|
|
return new ChargeRequestPlugInsOut();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 取消收费申请
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="Exception"></exception>
|
|
public async Task<ChargeRequestPlugInsOut> CancelChargeRequestAsync(ChargeRequestPlugInsInput input)
|
|
{
|
|
_logger.Log("银海取消收费申请", $"收费申请Id:{input.ChargeRequestId}");
|
|
try
|
|
{
|
|
var patientRegisterForPlugIns = await GetPatientRegisterAsync(input.ChargeRequestId);
|
|
var chargeRequestForPlugIns = await GetChargeRequestAsync(input.ChargeRequestId);
|
|
if (chargeRequestForPlugIns == null)
|
|
{
|
|
throw new Exception("没有申请单信息");
|
|
}
|
|
|
|
var endpointAddress = InterfaceConfig.GetValue("Interface:EndpointAddress", "");
|
|
if (string.IsNullOrWhiteSpace(endpointAddress))
|
|
{
|
|
throw new Exception("接口地址不能为空");
|
|
}
|
|
|
|
|
|
|
|
string actionName = "fee_delete";
|
|
string codeName = "peis_server";
|
|
|
|
using (var client = new WebServiceClient(new BasicHttpBinding(),
|
|
new EndpointAddress(endpointAddress)))
|
|
{
|
|
var request = new HisFeeDeleteDto();
|
|
#region head
|
|
string requestId = new Random().Next(100000, 999999).ToString();
|
|
string timestamp = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
request.Head = new HisFeeDeleteHeadDto
|
|
{
|
|
Action = actionName,
|
|
Code = codeName,
|
|
ObjectSystem = "his",
|
|
RequestId = requestId,
|
|
Sign = "",
|
|
SourceSystem = "peis",
|
|
Timestamp = timestamp,
|
|
Version = "1"
|
|
};
|
|
|
|
string headString = $"version={request.Head.Version}×tamp={request.Head.Timestamp}&request_id={request.Head.RequestId}&source_system={request.Head.SourceSystem}&object_system={request.Head.ObjectSystem}&action={request.Head.Action}";
|
|
string sign = Convert.ToBase64String(Encoding.UTF8.GetBytes(headString));
|
|
request.Head.Sign = sign;
|
|
#endregion
|
|
|
|
|
|
var orgCode = InterfaceConfig.GetValue("Interface:OrgCode", "");
|
|
var systemSource = InterfaceConfig.GetValue("Interface:SystemSource", "");
|
|
|
|
var execDoctorUser = InterfaceConfig.GetValue("Interface:ExecDoctorUser", "");
|
|
|
|
|
|
|
|
var dataDetails = new List<HisFeeCallBodyDataDetailDto>();
|
|
var dataRequest = new HisFeeDeleteBodyDataRequestDto
|
|
{
|
|
OrgCode = orgCode,
|
|
SystemSource = systemSource,
|
|
VisitId = patientRegisterForPlugIns.PatientRegisterNo,
|
|
CheckoutId = chargeRequestForPlugIns.ChargeRequestNo
|
|
};
|
|
|
|
var requestBody = new HisFeeDeleteBodyDto
|
|
{
|
|
Data = new HisFeeDeleteBodyDataDto
|
|
{
|
|
Request = dataRequest
|
|
}
|
|
};
|
|
|
|
request.Body = requestBody;
|
|
|
|
var requestXml = XmlHelper.SerializeToXmlEmpty(request);
|
|
|
|
|
|
var resultP = await client.callBussinessAsync(requestXml);
|
|
|
|
|
|
var returnValue = JsonConvert.SerializeObject(resultP.data, Newtonsoft.Json.Formatting.Indented);
|
|
|
|
_logger.Log("银海取消收费申请", $"发送结果:{returnValue}");
|
|
|
|
var yinHaiSendInterfaceLogDto = new YinHaiSendInterfaceLogDto
|
|
{
|
|
LogName = "取消收费申请",
|
|
ExecDoctorUser = Guid.Parse(execDoctorUser),
|
|
InterfaceName = $"{codeName}_{actionName}",
|
|
ParaValue = requestXml,
|
|
RequestNo = dataRequest.CheckoutId,
|
|
ReturnParaValue = returnValue
|
|
};
|
|
|
|
await AddSendLog(yinHaiSendInterfaceLogDto);
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//Console.WriteLine(ex.Message);
|
|
_logger.Log("银海取消收费申请", ex, $"发送取消收费申请异常");
|
|
}
|
|
|
|
|
|
return new ChargeRequestPlugInsOut();
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 接收收费状态结果
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="Exception"></exception>
|
|
public async Task<CallBussinessResponseDetailDto> SyncChargeRequestStatusAsync(InferfaceXmlDataDto input)
|
|
{
|
|
var res = new CallBussinessResponseDetailDto
|
|
{
|
|
msg = "失败",
|
|
status_code = "-1"
|
|
};
|
|
|
|
//fee_flag 1.成功,0.失败,-1退费
|
|
#region 解析xml
|
|
|
|
var feeBackRequestData = GetFeeBackRequestData(input.message);
|
|
|
|
#endregion
|
|
|
|
_logger.LogResult("银海接收收费状态结果", $"收费申请Id:{input.message}");
|
|
|
|
try
|
|
{
|
|
var execDoctorUser = InterfaceConfig.GetValue("Interface:ExecDoctorUser", "");
|
|
|
|
string actionName = "fee_back";
|
|
string codeName = "peis_server";
|
|
|
|
var bodyData = feeBackRequestData.body.data.request;
|
|
|
|
var chargeRequestNo = bodyData.checkout_id;
|
|
|
|
var chargeRequestIdDto = await GetChargeRequestIdByChargeRequestNoAsync(chargeRequestNo);
|
|
|
|
if (chargeRequestIdDto == null)
|
|
{
|
|
_logger.LogResult("银海接收收费状态结果", $"异常,收费申请单号【{chargeRequestNo}】");
|
|
return res;
|
|
}
|
|
|
|
var chargeRequest = await GetChargeRequestAsync(chargeRequestIdDto.ChargeRequestId);
|
|
|
|
switch (bodyData.fee_flag)
|
|
{
|
|
case "1":
|
|
//收费
|
|
await SetAppChargeRequestFlagAsync(chargeRequest, ChargeRequestFlag.AlreadyCharge);
|
|
break;
|
|
case "-1":
|
|
//退费
|
|
await SetAppChargeRequestFlagAsync(chargeRequest, ChargeRequestFlag.AlreadyRefund);
|
|
break;
|
|
}
|
|
|
|
|
|
_logger.LogResult("银海接收收费状态结果", $"处理成功,收费申请单号【{chargeRequest.ChargeRequestNo}】");
|
|
|
|
var yinHaiSendInterfaceLogDto = new YinHaiSendInterfaceLogDto
|
|
{
|
|
LogName = "接收收费状态结果",
|
|
ExecDoctorUser = Guid.Parse(execDoctorUser),
|
|
InterfaceName = $"{codeName}_{actionName}",
|
|
ParaValue = input.message,
|
|
RequestNo = bodyData.checkout_id,
|
|
ReturnParaValue = ""
|
|
};
|
|
|
|
await AddSendLog(yinHaiSendInterfaceLogDto);
|
|
|
|
res = new CallBussinessResponseDetailDto
|
|
{
|
|
status_code = "1",
|
|
msg = "成功"
|
|
};
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogResult("银海接收收费状态结果", ex, $"接收收费状态结果异常");
|
|
}
|
|
|
|
|
|
return res;
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 任务计划
|
|
|
|
/// <summary>
|
|
/// 自动任务执行方法
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
|
|
public void DoWork()
|
|
{
|
|
|
|
_logger.Log("收费申请自动任务", $"收费申请自动任务开始执行,当前时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
|
|
|
|
var queryDaysStr = InterfaceConfig.GetSection("Interface").GetSection("Scheduler").GetSection("QueryDays").Value;
|
|
if (string.IsNullOrWhiteSpace(queryDaysStr))
|
|
{
|
|
queryDaysStr = "1";
|
|
}
|
|
if (!int.TryParse(queryDaysStr, out int days))
|
|
{
|
|
days = 1;
|
|
}
|
|
var chargeRequests = GetRequestsAsync(days).GetAwaiter().GetResult();
|
|
|
|
_logger.Log("收费申请自动任务", $"获取到需要执行的数量:{chargeRequests.Count}");
|
|
|
|
foreach (var chargeRequest in chargeRequests)
|
|
{
|
|
try
|
|
{
|
|
SendChargeRequestAsync(new ChargeRequestPlugInsInput { ChargeRequestId = chargeRequest.ChargeRequestId })
|
|
.GetAwaiter().GetResult();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_logger.Log("收费申请自动任务", $"执行完成,当前时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 获取任务需要发送申请的数据
|
|
/// </summary>
|
|
/// <param name="days"></param>
|
|
/// <returns></returns>
|
|
private async Task<List<ChargeRequestForPlugIns>> GetRequestsAsync(int days)
|
|
{
|
|
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
|
|
{
|
|
string sql;
|
|
var startDate = DateTime.Now.Date.AddDays(-days);
|
|
sql = @"SELECT id as charge_request_id,
|
|
charge_request_no,
|
|
his_charge_no,
|
|
charge_request_flag,
|
|
concurrency_stamp
|
|
FROM charge_request
|
|
WHERE charge_request_flag = '0' and
|
|
creation_time >@StartDate and coalesce(his_charge_no,'')=''
|
|
";
|
|
var chargeRequestForPlugInss = (await conn.QueryAsync<ChargeRequestForPlugIns>(sql,
|
|
new { StartDate = startDate })).ToList();
|
|
|
|
return chargeRequestForPlugInss;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新收费申请表的his_charge_no,标记用于是否发送
|
|
/// </summary>
|
|
/// <param name="UserId"></param>
|
|
/// <returns></returns>
|
|
private async Task UpdateChargeRequestHisChargeNo(string chargeRequestNo)
|
|
{
|
|
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
|
|
{
|
|
string sql;
|
|
sql = @"update charge_request set his_charge_no=charge_request_no
|
|
WHERE charge_request_no =@chargeRequestNo
|
|
";
|
|
await conn.ExecuteAsync(sql,
|
|
new { chargeRequestNo = chargeRequestNo });
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取用户信息
|
|
/// </summary>
|
|
/// <param name="chargeRequestId"></param>
|
|
/// <returns></returns>
|
|
private async Task<PatientRegisterForPlugIns> GetPatientRegisterAsync(Guid chargeRequestId)
|
|
{
|
|
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
|
|
{
|
|
string sql;
|
|
sql = @"SELECT DISTINCT patient.id as patient_id,
|
|
patient_register.id as patient_register_id,
|
|
patient_register.patient_register_no,
|
|
patient.patient_no ,
|
|
patient_register.his_patient_id,
|
|
patient_register.medical_center_id,
|
|
patient_register.patient_name,
|
|
patient_register.sex_id,
|
|
patient_register.marital_status_id,
|
|
patient_register.birth_date,
|
|
patient_register.age,
|
|
patient_register.creator_id,
|
|
patient.nation_id,
|
|
patient.id_no,
|
|
patient.email,
|
|
patient.telephone,
|
|
patient.mobile_telephone,
|
|
patient.address
|
|
from patient,patient_register,charge_request
|
|
where patient.id = patient_register.patient_id and
|
|
patient_register.id = charge_request.patient_register_id and
|
|
charge_request.id =@ChargeRequestId
|
|
";
|
|
var patientRegisterForPlugIns = (await conn.QueryAsync<PatientRegisterForPlugIns>(sql,
|
|
new { ChargeRequestId = chargeRequestId })).SingleOrDefault();
|
|
return patientRegisterForPlugIns;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取收费申请id 根据收费申请单号
|
|
/// </summary>
|
|
/// <param name="chargeRequestNo"></param>
|
|
/// <returns></returns>
|
|
private async Task<ChargeRequestIdInputDto> GetChargeRequestIdByChargeRequestNoAsync(string chargeRequestNo)
|
|
{
|
|
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
|
|
{
|
|
string sql;
|
|
sql = @"SELECT id as chargeRequestId from charge_request
|
|
where charge_request_no = @ChargeRequestNo
|
|
";
|
|
var chargeRequestIdInputDto = (await conn.QueryAsync<ChargeRequestIdInputDto>(sql,
|
|
new { ChargeRequestNo = chargeRequestNo })).SingleOrDefault();
|
|
return chargeRequestIdInputDto;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取申请单信息
|
|
/// </summary>
|
|
/// <param name="chargeRequestId"></param>
|
|
/// <returns></returns>
|
|
private async Task<ChargeRequestForPlugIns> GetChargeRequestAsync(Guid chargeRequestId)
|
|
{
|
|
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
|
|
{
|
|
string sql;
|
|
sql = @"SELECT id as charge_request_id,
|
|
charge_request_no,
|
|
his_charge_no,
|
|
charge_request_flag,
|
|
concurrency_stamp
|
|
FROM charge_request
|
|
WHERE id =@ChargeRequestId
|
|
";
|
|
var chargeRequestForPlugIns = (await conn.QueryAsync<ChargeRequestForPlugIns>(sql,
|
|
new { ChargeRequestId = chargeRequestId })).SingleOrDefault();
|
|
if (chargeRequestForPlugIns == null)
|
|
{
|
|
return null;
|
|
}
|
|
sql = @"
|
|
SELECT register_check_asbitem.asbitem_id,
|
|
asbitem.display_name as asbitem_name,
|
|
register_check_asbitem.amount * register_check_asbitem.charge_price as charges,
|
|
register_check_asbitem.concurrency_stamp
|
|
from register_check
|
|
JOIN register_check_asbitem on register_check.id = register_check_asbitem.register_check_id
|
|
JOIN charge_request on register_check_asbitem.charge_request_id = charge_request.id
|
|
JOIN asbitem on register_check_asbitem.asbitem_id = asbitem.id
|
|
where
|
|
charge_request.id=@ChargeRequestId
|
|
";
|
|
|
|
chargeRequestForPlugIns.Asbitems = (await conn.QueryAsync<ChargeRequestAsbitemForPlugIns>(sql,
|
|
new { ChargeRequestId = chargeRequestId })).ToList();
|
|
|
|
return chargeRequestForPlugIns;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取收费用户
|
|
/// </summary>
|
|
/// <param name="UserId"></param>
|
|
/// <returns></returns>
|
|
private async Task<ChargeUserDto> GetUserInfo(Guid UserId)
|
|
{
|
|
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
|
|
{
|
|
string sql;
|
|
sql = @"select user_name,surname from abp_users
|
|
WHERE id =@UserId
|
|
";
|
|
var chargeUser = (await conn.QueryAsync<ChargeUserDto>(sql,
|
|
new { UserId = UserId })).SingleOrDefault();
|
|
if (chargeUser == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
|
|
return chargeUser;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取对照数据
|
|
/// </summary>
|
|
/// <param name="commonTableTypeId"></param>
|
|
/// <returns></returns>
|
|
private async Task<List<YinHaiHisCommonTableDto>> GetCommonTableByTypeId(string commonTableTypeId)
|
|
{
|
|
var hisCode = InterfaceConfig.GetValue("Interface:HisCode", "");
|
|
var hisName = InterfaceConfig.GetValue("Interface:HisName", "");
|
|
var hisPrice = InterfaceConfig.GetValue("Interface:HisPrice", "");
|
|
var hisCount = InterfaceConfig.GetValue("Interface:HisCount", "");
|
|
|
|
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
|
|
{
|
|
string sql;
|
|
sql = $@"select display_name,{hisCode} as hisCode,{hisName} as hisName,{hisPrice} as hisPrice,{hisCount} as hisCount from common_table where common_table_type_id='{commonTableTypeId}' ";
|
|
var yinHaiHisCommonTableList = (await conn.QueryAsync<YinHaiHisCommonTableDto>(sql)).ToList();
|
|
|
|
return yinHaiHisCommonTableList;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加日志
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
private async Task AddSendLog(YinHaiSendInterfaceLogDto input)
|
|
{
|
|
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
|
|
{
|
|
string sql;
|
|
sql = $@" insert into interface_send_log (id,log_name,request_no,interface_name,para_value,return_para_value,concurrency_stamp,
|
|
creation_time,creator_id,last_modification_time,last_modifier_id) values
|
|
(@id,@log_name,@request_no,@interface_name,@para_value,@return_para_value,@concurrency_stamp,
|
|
@creation_time,@creator_id,@last_modification_time,@last_modifier_id)
|
|
";
|
|
await conn.ExecuteAsync(sql,
|
|
new
|
|
{
|
|
id = Guid.NewGuid(),
|
|
log_name = input.LogName,
|
|
request_no = input.RequestNo,
|
|
interface_name = input.InterfaceName,
|
|
para_value = input.ParaValue,
|
|
return_para_value = input.ReturnParaValue,
|
|
concurrency_stamp = Guid.NewGuid().ToString("N"),
|
|
creation_time = DateTime.Now,
|
|
creator_id = input.ExecDoctorUser,
|
|
last_modification_time = DateTime.Now,
|
|
last_modifier_id = input.ExecDoctorUser
|
|
});
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 收费 退费 动作
|
|
/// </summary>
|
|
/// <param name="chargeRequestForPlugIns"></param>
|
|
/// <param name="chargeRequestFlag"></param>
|
|
/// <returns></returns>
|
|
private async Task SetAppChargeRequestFlagAsync(ChargeRequestForPlugIns chargeRequestForPlugIns,
|
|
char chargeRequestFlag)
|
|
{
|
|
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
|
|
{
|
|
await conn.OpenAsync();
|
|
|
|
using (var trans = await conn.BeginTransactionAsync())
|
|
{
|
|
try
|
|
{
|
|
string sql;
|
|
sql = @" update charge_request set charge_request_flag =" + chargeRequestFlag +
|
|
@" where id = @ChargeRequestId and concurrency_stamp = @ConcurrencyStamp
|
|
";
|
|
await conn.ExecuteAsync(sql,
|
|
new
|
|
{
|
|
chargeRequestForPlugIns.ChargeRequestId,
|
|
chargeRequestForPlugIns.ConcurrencyStamp
|
|
}, trans);
|
|
|
|
foreach (var chargeRequestAsbitem in chargeRequestForPlugIns.Asbitems)
|
|
{
|
|
if (chargeRequestFlag == ChargeRequestFlag.AlreadyCharge)
|
|
{
|
|
sql = @" update register_check_asbitem set is_charge = 'Y',pay_type_flag='0'
|
|
where charge_request_id = @ChargeRequestId and concurrency_stamp = @ConcurrencyStamp
|
|
";
|
|
await conn.ExecuteAsync(sql,
|
|
new
|
|
{
|
|
chargeRequestForPlugIns.ChargeRequestId,
|
|
chargeRequestAsbitem.ConcurrencyStamp
|
|
}, trans);
|
|
}
|
|
else if (chargeRequestFlag == ChargeRequestFlag.AlreadyRefund)
|
|
{
|
|
sql = @" update register_check_asbitem set is_charge = 'N'
|
|
where charge_request_id = @ChargeRequestId and concurrency_stamp = @ConcurrencyStamp
|
|
";
|
|
await conn.ExecuteAsync(sql,
|
|
new
|
|
{
|
|
chargeRequestForPlugIns.ChargeRequestId,
|
|
chargeRequestAsbitem.ConcurrencyStamp
|
|
}, trans);
|
|
}
|
|
}
|
|
|
|
|
|
await trans.CommitAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await trans.RollbackAsync();
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转换性别
|
|
/// </summary>
|
|
/// <param name="sexId"></param>
|
|
/// <returns></returns>
|
|
private string ConvertSex(char sexId)
|
|
{
|
|
string msg = "";
|
|
switch (sexId)
|
|
{
|
|
case 'M':
|
|
msg = "1";
|
|
break;
|
|
case 'F':
|
|
msg = "2";
|
|
break;
|
|
case 'U':
|
|
msg = "0";
|
|
break;
|
|
default:
|
|
msg = "9";
|
|
break;
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
#region 解析xml
|
|
|
|
private FeeBackRequest GetFeeBackRequestData(string message)
|
|
{
|
|
try
|
|
{
|
|
message = message.TrimStart(); // 去除开头的空白字符
|
|
|
|
var doc = new XmlDocument();
|
|
doc.LoadXml(message);
|
|
|
|
var request = new FeeBackRequest();
|
|
var root = doc.DocumentElement;
|
|
|
|
if (root == null) return null;
|
|
|
|
// 解析 head
|
|
var headNode = root.SelectSingleNode("head");
|
|
if (headNode != null)
|
|
{
|
|
request.head = new CallBussinessRequestHeadDto
|
|
{
|
|
version = GetNodeValue(headNode, "version"),
|
|
timestamp = GetNodeValue(headNode, "timestamp"),
|
|
sign = GetNodeValue(headNode, "sign"),
|
|
request_id = GetNodeValue(headNode, "request_id"),
|
|
source_system = GetNodeValue(headNode, "source_system"),
|
|
object_system = GetNodeValue(headNode, "object_system"),
|
|
action = GetNodeValue(headNode, "action"),
|
|
code = GetNodeValue(headNode, "code")
|
|
};
|
|
}
|
|
|
|
// 解析 body
|
|
var bodyNode = root.SelectSingleNode("body");
|
|
if (bodyNode != null)
|
|
{
|
|
//按方法
|
|
|
|
|
|
request.body = new FeeBackRequestBody();
|
|
var dataNode = bodyNode.SelectSingleNode("data");
|
|
if (dataNode != null)
|
|
{
|
|
request.body.data = new FeeBackRequestData();
|
|
var requestNode = dataNode.SelectSingleNode("request");
|
|
if (requestNode != null)
|
|
{
|
|
request.body.data.request = new FeeBackRequestDetail
|
|
{
|
|
visit_id = GetNodeValue(requestNode, "visit_id"),
|
|
checkout_id = GetNodeValue(requestNode, "checkout_id"),
|
|
org_code = GetNodeValue(requestNode, "org_code"),
|
|
hos_id = GetNodeValue(requestNode, "hos_id"),
|
|
system_source = GetNodeValue(requestNode, "system_source"),
|
|
fee_flag = GetNodeValue(requestNode, "fee_flag"),
|
|
invoice_no = GetNodeValue(requestNode, "invoice_no"),
|
|
collr_collector_code = GetNodeValue(requestNode, "collr_collector_code"),
|
|
collr_collector_name = GetNodeValue(requestNode, "collr_collector_name"),
|
|
collr_collector_date = GetNodeValue(requestNode, "collr_collector_date")
|
|
};
|
|
}
|
|
}
|
|
}
|
|
|
|
return request;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//_logger.LogError(ex, "解析 XML 失败");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private string GetNodeValue(XmlNode parent, string nodeName)
|
|
{
|
|
var node = parent.SelectSingleNode(nodeName);
|
|
return node?.InnerText ?? "";
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|