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.
		
		
		
		
		
			
		
			
				
					
					
						
							285 lines
						
					
					
						
							11 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							285 lines
						
					
					
						
							11 KiB
						
					
					
				
								using Dapper;
							 | 
						|
								using Npgsql;
							 | 
						|
								using ServiceReferenceHzcyHis;
							 | 
						|
								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.Gem
							 | 
						|
								{
							 | 
						|
								    public class ChargeRequestPlugInsGem : ChargeRequestPlugInsBase
							 | 
						|
								    {
							 | 
						|
								        private string _endpointAddress = "";
							 | 
						|
								        public ChargeRequestPlugInsGem(string parmValue) : base(parmValue)
							 | 
						|
								        {
							 | 
						|
								            _endpointAddress = InterfaceConfig.GetSection("Interface").GetSection("EndpointAddress").Value;
							 | 
						|
								        }
							 | 
						|
								        public override async Task<ChargeRequestPlugInsOut> SendRequest(ChargeRequestPlugInsInput input)
							 | 
						|
								        {
							 | 
						|
								            //建立人员档案
							 | 
						|
								           var patientRegisterForPlugIns = await GetPatientRegisterForPlugInsAsync(input.ChargeRequestId);
							 | 
						|
								           var chargeRequestForPlugIns = await GeChargeRequestForPlugInsAsync(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 = "1",
							 | 
						|
								                        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,
							 | 
						|
								                        PatientRegisterId = 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,
							 | 
						|
								                        ChargeRequestId = input.ChargeRequestId
							 | 
						|
								                    });
							 | 
						|
								
							 | 
						|
								            }
							 | 
						|
								            return new ChargeRequestPlugInsOut();
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								        public override async Task<ChargeRequestPlugInsOut> CancelRequest(ChargeRequestPlugInsInput input)
							 | 
						|
								        {
							 | 
						|
								            var chargeRequestForPlugIns = await GeChargeRequestForPlugInsAsync(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")
							 | 
						|
								            {
							 | 
						|
								                throw new Exception("作废申请单失败" + result.MsgHeader.Detail);
							 | 
						|
								            }
							 | 
						|
								            return new ChargeRequestPlugInsOut();
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								        public override async Task<ChargeRequestPlugInsOut> RefundRequest(ChargeRequestPlugInsInput input)
							 | 
						|
								        {
							 | 
						|
								            var chargeRequestForPlugIns = await GeChargeRequestForPlugInsAsync(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")
							 | 
						|
								            {
							 | 
						|
								                throw new Exception("允许退费申请失败" + result.MsgHeader.Detail);
							 | 
						|
								            }
							 | 
						|
								            return new ChargeRequestPlugInsOut();
							 | 
						|
								        }
							 | 
						|
								        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);
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								    }
							 | 
						|
								}
							 |