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.
427 lines
16 KiB
427 lines
16 KiB
using Dapper;
|
|
using log4net.Repository.Hierarchy;
|
|
using Npgsql;
|
|
using ServiceReferenceHzcyHis;
|
|
using Shentun.Peis.Enums;
|
|
using Shentun.Peis.PlugIns.ChargeRequests;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Common;
|
|
using System.Linq;
|
|
using System.ServiceModel;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static ServiceReferenceHzcyHis.bstjPortTypeClient;
|
|
|
|
namespace Shentun.Peis.PlugIns.Extensions.ChargeRequests.Hzcy
|
|
{
|
|
public class ChargeRequestPlugInsHzcy : ChargeRequestPlugInsBase
|
|
{
|
|
private string _endpointAddress = "";
|
|
|
|
public ChargeRequestPlugInsHzcy(Guid thirdInterfaceId) : base(thirdInterfaceId)
|
|
{
|
|
_endpointAddress = InterfaceConfig.GetSection("Interface").GetSection("EndpointAddress").Value;
|
|
}
|
|
public ChargeRequestPlugInsHzcy(string parmValue) : base(parmValue)
|
|
{
|
|
_endpointAddress = InterfaceConfig.GetSection("Interface").GetSection("EndpointAddress").Value;
|
|
}
|
|
public override async Task<ChargeRequestPlugInsOut> SendChargeRequestAsync(ChargeRequestPlugInsInput input)
|
|
{
|
|
//建立人员档案
|
|
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 hisPatientQueryInput = new HisPatientQueryInput()
|
|
{
|
|
Data = new HisPatientQueryDataInput()
|
|
{
|
|
MsgHeader = new HisMsgHeaderInput()
|
|
{
|
|
Sender = "PEIS",
|
|
MsgType = "SVR_ODS_1101",
|
|
MsgVersion = "3.1",
|
|
},
|
|
Patient = new HisPatientQueryPatientInput()
|
|
{
|
|
IdCard = patientRegisterForPlugIns.IdNo,
|
|
IdCardCode = "01",
|
|
Name = patientRegisterForPlugIns.PatientName,
|
|
Sex = ConverSex(patientRegisterForPlugIns.SexId),
|
|
BirthDate = ((DateTime)patientRegisterForPlugIns.BirthDate).ToString("yyyy-MM-dd", System.Globalization.DateTimeFormatInfo.InvariantInfo),
|
|
PatientPhone = patientRegisterForPlugIns.MobileTelephone,
|
|
EthnicGroupCode = "01",
|
|
WorkUnit = patientRegisterForPlugIns.CustomerOrgName,
|
|
Address = patientRegisterForPlugIns.Address,
|
|
}
|
|
}
|
|
};
|
|
|
|
var result = await PatientQuery(hisPatientQueryInput);
|
|
|
|
if (result.MsgHeader.Status != "true")
|
|
{
|
|
throw new Exception("建立HIS档案失败" + result.MsgHeader.Detail);
|
|
|
|
}
|
|
//更新人员登记信息
|
|
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
|
|
{
|
|
conn.Execute(@"update patient_register set his_patient_id = @HisPatientId
|
|
where id = @PatientRegisterId",
|
|
new
|
|
{
|
|
HisPatientId = result.Patient.PatientId,
|
|
patientRegisterForPlugIns.PatientRegisterId
|
|
});
|
|
|
|
}
|
|
|
|
//发送项目
|
|
var hisInput = new HisMecSaveInput()
|
|
{
|
|
Data = new HisMecSaveDataInput()
|
|
{
|
|
MsgHeader = new HisMsgHeaderInput()
|
|
{
|
|
Sender = "PEIS",
|
|
MsgType = "SVR_ODS_6101",
|
|
MsgVersion = "3.1",
|
|
},
|
|
Items = new List<HisMecSaveDataItemInput>()
|
|
{
|
|
new HisMecSaveDataItemInput()
|
|
{
|
|
ExamRequestNo =chargeRequestForPlugIns.ChargeRequestNo,
|
|
FeeType = "1",
|
|
EmpId = result.Patient.PatientId,
|
|
DeptId = "",
|
|
DoctId = "",
|
|
ExeDeptId = "",
|
|
Tjunit = patientRegisterForPlugIns.CustomerOrgName,
|
|
Tjfee = chargeRequestForPlugIns.Asbitems.Sum(o=>o.Charges).ToString(),
|
|
Ztxm = "",
|
|
Remark = "体检科"
|
|
|
|
},
|
|
|
|
}
|
|
}
|
|
};
|
|
var mecSaveResult = await MecSave(hisInput);
|
|
if (mecSaveResult.MsgHeader.Status != "true")
|
|
{
|
|
throw new Exception("建立HIS档案失败" + mecSaveResult.MsgHeader.Detail);
|
|
}
|
|
//更新申请单信息
|
|
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
|
|
{
|
|
conn.Execute(@"update charge_request set his_charge_no = @HisChargeNo
|
|
where id = @ChargeRequestId",
|
|
new
|
|
{
|
|
HisChargeNo = mecSaveResult.MsgHeader.Yjxh,
|
|
input.ChargeRequestId
|
|
});
|
|
|
|
}
|
|
return new ChargeRequestPlugInsOut();
|
|
}
|
|
|
|
public override async Task<ChargeRequestPlugInsOut> CancelChargeRequestAsync(ChargeRequestPlugInsInput input)
|
|
{
|
|
var chargeRequestForPlugIns = await GetChargeRequestAsync(input.ChargeRequestId);
|
|
if (chargeRequestForPlugIns == null)
|
|
{
|
|
throw new Exception("没有申请单信息");
|
|
}
|
|
var hisInput = new HisCancelQrCodeInput()
|
|
{
|
|
Data = new HisCancelQrCodeDataInput()
|
|
{
|
|
MsgHeader = new HisMsgHeaderInput()
|
|
{
|
|
Sender = "PEIS",
|
|
MsgType = "SVR_ODS_6105",
|
|
MsgVersion = "3.1",
|
|
},
|
|
Item = new HisCancelQrCodeDataItemInput()
|
|
{
|
|
Yjxh = chargeRequestForPlugIns.HisChargeNo,
|
|
ExamRequestNo = chargeRequestForPlugIns.ChargeRequestNo
|
|
}
|
|
}
|
|
};
|
|
|
|
var result = await CancelQrCode(hisInput);
|
|
if (result.MsgHeader.Status != "true")
|
|
{
|
|
//-1 申请单未找到
|
|
if (!result.MsgHeader.Detail.Contains("未查到开单信息"))
|
|
{
|
|
|
|
var payStatus = await GetPayStatus(chargeRequestForPlugIns.ChargeRequestNo, chargeRequestForPlugIns.HisChargeNo);
|
|
if (payStatus == "1")
|
|
{
|
|
throw new Exception("his已缴费");
|
|
}
|
|
else if (payStatus == "2")
|
|
{
|
|
throw new Exception("his已作废");
|
|
}
|
|
else if (payStatus == "3")
|
|
{
|
|
throw new Exception("his已退费");
|
|
}
|
|
}
|
|
|
|
}
|
|
await SetAppChargeRequestFlagAsync(chargeRequestForPlugIns, ChargeRequestFlag.AlreadyCancelCharge);
|
|
return new ChargeRequestPlugInsOut();
|
|
}
|
|
|
|
public override async Task DoWorkAsync()
|
|
{
|
|
throw new Exception("格尔木DoWorkAsync。。。");
|
|
//return base.DoWorkAsync();
|
|
}
|
|
public override async Task<ChargeRequestPlugInsOut> RefundRequestAsync(ChargeRequestPlugInsInput input)
|
|
{
|
|
var chargeRequestForPlugIns = await GetChargeRequestAsync(input.ChargeRequestId);
|
|
if (chargeRequestForPlugIns == null)
|
|
{
|
|
throw new Exception("没有申请单信息");
|
|
}
|
|
|
|
var hisInput = new HisAgreeRefundInput()
|
|
{
|
|
Data = new HisAgreeRefundDataInput()
|
|
{
|
|
MsgHeader = new HisMsgHeaderInput()
|
|
{
|
|
Sender = "PEIS",
|
|
MsgType = "SVR_ODS_6105",
|
|
MsgVersion = "3.1",
|
|
},
|
|
Item = new HisAgreeRefundDataItemInput()
|
|
{
|
|
Yjxh = chargeRequestForPlugIns.HisChargeNo,
|
|
ExamRequestNo = chargeRequestForPlugIns.ChargeRequestNo
|
|
}
|
|
}
|
|
};
|
|
|
|
var result = await AgreeRefund(hisInput);
|
|
if (result.MsgHeader.Status != "true")
|
|
{
|
|
var payStatus = await GetPayStatus(chargeRequestForPlugIns.ChargeRequestNo, chargeRequestForPlugIns.HisChargeNo);
|
|
if (payStatus != "3")
|
|
{
|
|
throw new Exception("允许退费申请失败" + result.MsgHeader.Detail);
|
|
}
|
|
|
|
}
|
|
await SetAppChargeRequestFlagAsync(chargeRequestForPlugIns, ChargeRequestFlag.RefundRequest);
|
|
return new ChargeRequestPlugInsOut();
|
|
}
|
|
public override Task DoWork()
|
|
{
|
|
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).Result;
|
|
|
|
foreach (var chargeRequest in chargeRequests)
|
|
{
|
|
try
|
|
{
|
|
SyncChargeRequestFlagFromInterfaceAsync(new ChargeRequestPlugInsInput { ChargeRequestId = chargeRequest.ChargeRequestId })
|
|
.GetAwaiter().GetResult();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
return base.DoWork();
|
|
}
|
|
|
|
public override async Task SyncChargeRequestFlagFromInterfaceAsync(ChargeRequestPlugInsInput input)
|
|
{
|
|
var chargeRequest = await GetChargeRequestAsync(input.ChargeRequestId);
|
|
|
|
var payStatus = await GetPayStatus(chargeRequest.ChargeRequestNo, chargeRequest.HisChargeNo);
|
|
|
|
//1:已支付,2.已作废3.已退费, 其他:未支付
|
|
char charRequstFlag;
|
|
if (payStatus == "1" && chargeRequest.ChargeRequestFlag != ChargeRequestFlag.RefundRequest)
|
|
{
|
|
charRequstFlag = ChargeRequestFlag.AlreadyCharge;
|
|
await SetAppChargeRequestFlagAsync(chargeRequest, charRequstFlag);
|
|
|
|
}
|
|
else if (payStatus == "2")
|
|
{
|
|
charRequstFlag = ChargeRequestFlag.AlreadyCancelCharge;
|
|
await SetAppChargeRequestFlagAsync(chargeRequest, charRequstFlag);
|
|
}
|
|
else if (payStatus == "3")
|
|
{
|
|
charRequstFlag = ChargeRequestFlag.AlreadyRefund;
|
|
await SetAppChargeRequestFlagAsync(chargeRequest, charRequstFlag);
|
|
}
|
|
else
|
|
{
|
|
//throw new Exception("查询支付状态不支持的收费标志" + result.MsgHeader.ErrCode);
|
|
}
|
|
}
|
|
|
|
private async Task<string> GetPayStatus(string chargeRequestNo, string hisChargeNo)
|
|
{
|
|
var hisInput = new HisPayStatusInput()
|
|
{
|
|
Data = new HisPayStatusDataInput()
|
|
{
|
|
MsgHeader = new HisMsgHeaderInput()
|
|
{
|
|
Sender = "PEIS",
|
|
MsgType = "SVR_ODS_6105",
|
|
MsgVersion = "3.1",
|
|
},
|
|
Item = new HisPayStatusDataItemInput()
|
|
{
|
|
Yjxh = hisChargeNo,
|
|
ExamRequestNo = chargeRequestNo,
|
|
}
|
|
}
|
|
};
|
|
var result = await PayStatus(hisInput);
|
|
if (result.MsgHeader.Status != "true")
|
|
{
|
|
throw new Exception("查询支付状态失败" + result.MsgHeader.Detail);
|
|
}
|
|
//1:已支付,2.已作废3.已退费, 其他:未支付
|
|
return result.MsgHeader.ErrCode;
|
|
}
|
|
public async Task<HisPatientQueryOut> PatientQuery(HisPatientQueryInput input)
|
|
{
|
|
using (var client = CreateClient())
|
|
{
|
|
input.SeviceBaseArg.Service = "patientQuery";
|
|
var data = XmlHelper.SerializeToXml(input.Data);
|
|
|
|
var resultStr = (await client.invokeAsync(input.SeviceBaseArg.Service,
|
|
input.SeviceBaseArg.Urid,
|
|
input.SeviceBaseArg.Pwd,
|
|
data)).@return;
|
|
var result = XmlHelper.DeserializeXml<HisPatientQueryOut>(resultStr);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public async Task<HisMecSaveOut> MecSave(HisMecSaveInput input)
|
|
{
|
|
using (var client = CreateClient())
|
|
{
|
|
input.SeviceBaseArg.Service = "mecSave";
|
|
var data = XmlHelper.SerializeToXml(input.Data);
|
|
|
|
var resultStr = (await client.invokeAsync(input.SeviceBaseArg.Service,
|
|
input.SeviceBaseArg.Urid,
|
|
input.SeviceBaseArg.Pwd,
|
|
data)).@return;
|
|
var result = XmlHelper.DeserializeXml<HisMecSaveOut>(resultStr);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public async Task<HisOutBase> CancelQrCode(HisCancelQrCodeInput input)
|
|
{
|
|
using (var client = CreateClient())
|
|
{
|
|
input.SeviceBaseArg.Service = "cancelQrCode";
|
|
var data = XmlHelper.SerializeToXml(input.Data);
|
|
|
|
var resultStr = (await client.invokeAsync(input.SeviceBaseArg.Service,
|
|
input.SeviceBaseArg.Urid,
|
|
input.SeviceBaseArg.Pwd,
|
|
data)).@return;
|
|
var result = XmlHelper.DeserializeXml<HisOutBase>(resultStr);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public async Task<HisOutBase> PayStatus(HisPayStatusInput input)
|
|
{
|
|
using (var client = CreateClient())
|
|
{
|
|
input.SeviceBaseArg.Service = "payStatus";
|
|
var data = XmlHelper.SerializeToXml(input.Data);
|
|
|
|
var resultStr = (await client.invokeAsync(input.SeviceBaseArg.Service,
|
|
input.SeviceBaseArg.Urid,
|
|
input.SeviceBaseArg.Pwd,
|
|
data)).@return;
|
|
var result = XmlHelper.DeserializeXml<HisOutBase>(resultStr);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public async Task<HisOutBase> AgreeRefund(HisAgreeRefundInput input)
|
|
{
|
|
using (var client = CreateClient())
|
|
{
|
|
input.SeviceBaseArg.Service = "agreeRefund";
|
|
var data = XmlHelper.SerializeToXml(input.Data);
|
|
|
|
var resultStr = (await client.invokeAsync(input.SeviceBaseArg.Service,
|
|
input.SeviceBaseArg.Urid,
|
|
input.SeviceBaseArg.Pwd,
|
|
data)).@return;
|
|
var result = XmlHelper.DeserializeXml<HisOutBase>(resultStr);
|
|
return result;
|
|
}
|
|
}
|
|
private bstjPortTypeClient CreateClient()
|
|
{
|
|
return new bstjPortTypeClient(EndpointConfiguration.bstjHttpSoap11Endpoint,
|
|
_endpointAddress);
|
|
}
|
|
|
|
private string ConverSex(char sexId)
|
|
{
|
|
switch (sexId)
|
|
{
|
|
case 'M':
|
|
return "1";
|
|
case 'F':
|
|
return "2";
|
|
case 'U':
|
|
return "3";
|
|
default:
|
|
return "3";
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|