Ejemplo n.º 1
0
        /// <summary>
        /// 门诊月结
        /// </summary>
        /// <param name="param"></param>
        public void MonthlyHospitalization(MonthlyHospitalizationUiParam param)
        {
            var userBase = _serviceBasicService.GetUserBaseInfo(param.UserId);
            MonthlyHospitalizationDto data;

            data = JsonConvert.DeserializeObject <MonthlyHospitalizationDto>(param.SettlementJson);
            var insertParam = new MonthlyHospitalizationEntity()
            {
                Amount      = data.ReimbursementAllAmount,
                Id          = Guid.NewGuid(),
                DocumentNo  = data.DocumentNo,
                PeopleNum   = data.ReimbursementPeopleNum,
                PeopleType  = ((int)param.PeopleType).ToString(),
                SummaryType = "22",
                StartTime   = Convert.ToDateTime(param.StartTime + " 00:00:00.000"),
                EndTime     = Convert.ToDateTime(param.EndTime + " 00:00:00.000"),
                IsRevoke    = false
            };

            _monthlyHospitalizationBase.Insert(insertParam, userBase);
            //添加日志
            var logParam = new AddHospitalLogParam()
            {
                JoinOrOldJson = JsonConvert.SerializeObject(param),
                User          = userBase,
                Remark        = "门诊月结汇总",
                RelationId    = insertParam.Id,
            };

            _systemManageRepository.AddHospitalLog(logParam);
        }
 /// <summary>
 /// 添加操作日志
 /// </summary>
 /// <returns></returns>
 public int AddHospitalLog(AddHospitalLogParam param)
 {
     using (var sqlConnection = new SqlConnection(_connectionString))
     {
         string querySql = null;
         try
         {
             sqlConnection.Open();
             querySql = $@"insert into  [dbo].[HospitalLog](
                         [Id]
                        ,[RelationId]
                        ,[JoinOrOldJson]
                        ,[ReturnOrNewJson]
                        ,[Remark]
                        ,[OrganizationCode]
                        ,[OrganizationName]
                        ,[CreateTime]
                        ,[IsDelete]
                        ,[CreateUserId]
                        ,[BusinessId]
                       )
                      values('{Guid.NewGuid()}','{param.RelationId}','{param.JoinOrOldJson}','{param.ReturnOrNewJson}',
                       '{param.Remark}','{param.User.OrganizationCode}','{param.User.OrganizationName}',getDate(),0,'{param.User.UserId}','{param.BusinessId}')";
             var data = sqlConnection.Execute(querySql);
             sqlConnection.Close();
             return(data);
         }
         catch (Exception e)
         {
             _log.Debug(querySql);
             throw new Exception(e.Message);
         }
     }
 }
        /// <summary>
        /// 门诊月结
        /// </summary>
        /// <param name="param"></param>
        public void MonthlyHospitalization(MonthlyHospitalizationUiParam param)
        {
            var userBase = _serviceBasicService.GetUserBaseInfo(param.UserId);

            //医保登录
            _residentMedicalInsuranceService.Login(new QueryHospitalOperatorParam()
            {
                UserId = param.UserId
            });
            var data = _outpatientDepartmentRepository.MonthlyHospitalization(
                new MonthlyHospitalizationParam()
            {
                User          = userBase,
                Participation = new MonthlyHospitalizationParticipationParam()
                {
                    StartTime   = Convert.ToDateTime(param.StartTime).ToString("yyyyMMdd"),
                    EndTime     = Convert.ToDateTime(param.EndTime).ToString("yyyyMMdd"),
                    SummaryType = "22",
                    PeopleType  = ((int)param.PeopleType).ToString()
                }
            });
            var insertParam = new MonthlyHospitalizationEntity()
            {
                Amount      = data.ReimbursementAllAmount,
                Id          = Guid.NewGuid(),
                DocumentNo  = data.DocumentNo,
                PeopleNum   = data.ReimbursementPeopleNum,
                PeopleType  = ((int)param.PeopleType).ToString(),
                SummaryType = "22",
                StartTime   = Convert.ToDateTime(param.StartTime + " 00:00:00.000"),
                EndTime     = Convert.ToDateTime(param.EndTime + " 00:00:00.000"),
                IsRevoke    = false
            };

            _monthlyHospitalizationBase.Insert(insertParam, userBase);
            //添加日志
            var logParam = new AddHospitalLogParam()
            {
                JoinOrOldJson = JsonConvert.SerializeObject(param),
                User          = userBase,
                Remark        = "门诊月结汇总",
                RelationId    = insertParam.Id,
            };

            _systemManageRepository.AddHospitalLog(logParam);
        }
        /// <summary>
        /// 职工生育结算
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public WorkerHospitalizationPreSettlementDto WorkerBirthSettlement(WorkerBirthSettlementUiParam param)
        {
            //获取操作人员信息
            var userBase = _serviceBasicService.GetUserBaseInfo(param.UserId);

            userBase.TransKey = param.TransKey;
            var infoData = new GetInpatientInfoParam()
            {
                User       = userBase,
                BusinessId = param.BusinessId,
            };
            //获取his结算
            var hisSettlement      = _serviceBasicService.GetHisHospitalizationSettlement(infoData);
            var queryResidentParam = new QueryMedicalInsuranceResidentInfoParam()
            {
                BusinessId       = param.BusinessId,
                OrganizationCode = userBase.OrganizationCode
            };
            //获取医保病人信息
            var residentData = _medicalInsuranceSqlRepository.QueryMedicalInsuranceResidentInfo(queryResidentParam);

            if (residentData.MedicalInsuranceState == MedicalInsuranceState.HisSettlement)
            {
                throw new Exception("当前病人已办理医保结算,不能办理预结算!!!");
            }
            if (residentData.MedicalInsuranceState != MedicalInsuranceState.MedicalInsurancePreSettlement)
            {
                throw new Exception("当前病人未办理预结算,不能办理结算!!!");
            }
            var inpatientInfoParam = new QueryInpatientInfoParam()
            {
                BusinessId = param.BusinessId
            };
            //获取住院病人
            var inpatientInfoData = _hisSqlRepository.QueryInpatientInfo(inpatientInfoParam);

            if (inpatientInfoData == null)
            {
                throw new Exception("该病人未在中心库中,请检查是否办理医保入院!!!");
            }

            var infoParam = new WorkerBirthSettlementParam()
            {
                LeaveHospitalInpatientState = param.LeaveHospitalInpatientState,
                FetusNumber     = param.FetusNumber,
                MedicalCategory = param.MedicalCategory,
                Operator        = userBase.UserName,
                MedicalInsuranceHospitalizationNo = residentData.MedicalInsuranceHospitalizationNo,
                LeaveHospitalDate = Convert.ToDateTime(hisSettlement.LeaveHospitalDate).ToString("yyyyMMdd"),
            };
            //获取诊断
            var diagnosisData = CommonHelp.GetDiagnosis(param.DiagnosisList);

            infoParam.AdmissionMainDiagnosisIcd10 = diagnosisData.AdmissionMainDiagnosisIcd10;
            infoParam.DiagnosisIcd10Two           = diagnosisData.DiagnosisIcd10Two;
            infoParam.DiagnosisIcd10Three         = diagnosisData.DiagnosisIcd10Three;
            infoParam.AdmissionMainDiagnosis      = diagnosisData.DiagnosisDescribe;

            // 医保
            var resultData = _workerMedicalInsuranceRepository.WorkerBirthSettlement(infoParam);
            //报销金额 =统筹支付+补充医疗保险支付金额+专项基金支付金额+
            //公务员补贴+公务员补助+其它支付金额
            decimal reimbursementExpenses = resultData.BasicOverallPay + resultData.SupplementPayAmount + resultData.SpecialFundPayAmount
                                            + resultData.CivilServantsSubsidies + resultData.CivilServantsSubsidy + resultData.OtherPaymentAmount;

            resultData.ReimbursementExpenses = reimbursementExpenses;
            var updateData = new UpdateMedicalInsuranceResidentSettlementParam()
            {
                UserId = userBase.UserId,
                ReimbursementExpensesAmount = CommonHelp.ValueToDouble(reimbursementExpenses),
                SelfPayFeeAmount            = resultData.CashPayment,
                OtherInfo    = JsonConvert.SerializeObject(resultData),
                Id           = residentData.Id,
                SettlementNo = resultData.DocumentNo,
                MedicalInsuranceAllAmount = resultData.TotalAmount,
                SettlementTransactionId   = userBase.UserId,
                MedicalInsuranceState     = MedicalInsuranceState.MedicalInsuranceSettlement
            };

            //存入中间层
            _medicalInsuranceSqlRepository.UpdateMedicalInsuranceResidentSettlement(updateData);
            //添加日志
            var logParam = new AddHospitalLogParam()
            {
                JoinOrOldJson   = JsonConvert.SerializeObject(param),
                ReturnOrNewJson = JsonConvert.SerializeObject(resultData),
                User            = userBase,
                Remark          = "职工住院结算",
                RelationId      = residentData.Id,
            };
            //存入基层
            var userInfoData = _residentMedicalInsuranceRepository.GetUserInfo(new ResidentUserInfoParam()
            {
                IdentityMark = residentData.IdentityMark,
                AfferentSign = residentData.AfferentSign,
            });

            // 回参构建
            var xmlData = new HospitalSettlementXml()
            {
                MedicalInsuranceHospitalizationNo = residentData.MedicalInsuranceHospitalizationNo,
                CashPayment      = resultData.CashPayment,
                SettlementNo     = resultData.DocumentNo,
                PaidAmount       = resultData.PaidAmount,
                AllAmount        = resultData.TotalAmount,
                PatientName      = userInfoData.PatientName,
                AccountBalance   = userInfoData.WorkersInsuranceBalance,
                AccountAmountPay = resultData.AccountPayment,
            };


            var strXmlBackParam = XmlSerializeHelper.HisXmlSerialize(xmlData);
            var saveXml         = new SaveXmlDataParam()
            {
                User = userBase,
                MedicalInsuranceBackNum = resultData.DocumentNo,
                MedicalInsuranceCode    = "41",
                BusinessId = param.BusinessId,
                BackParam  = strXmlBackParam
            };

            //结算存基层
            _webBasicRepository.SaveXmlData(saveXml);

            var updateParamData = new UpdateMedicalInsuranceResidentSettlementParam()
            {
                UserId = param.UserId,
                Id     = residentData.Id,
                MedicalInsuranceState = MedicalInsuranceState.HisSettlement,
                IsHisUpdateState      = true
            };

            //  更新中间层
            _medicalInsuranceSqlRepository.UpdateMedicalInsuranceResidentSettlement(updateParamData);


            //结算后保存信息
            var saveParam = AutoMapper.Mapper.Map <SaveInpatientSettlementParam>(hisSettlement);

            saveParam.Id   = (Guid)inpatientInfoData.Id;
            saveParam.User = userBase;
            saveParam.LeaveHospitalDiagnosisJson = JsonConvert.SerializeObject(param.DiagnosisList);
            _hisSqlRepository.SaveInpatientSettlement(saveParam);
            return(resultData);
        }
        /// <summary>
        /// 职工生育预结算
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public WorkerHospitalizationPreSettlementDto WorkerBirthPreSettlement(WorkerBirthPreSettlementUiParam param)
        {
            //获取操作人员信息
            var userBase = _serviceBasicService.GetUserBaseInfo(param.UserId);

            userBase.TransKey = param.TransKey;
            var queryResidentParam = new QueryMedicalInsuranceResidentInfoParam()
            {
                BusinessId       = param.BusinessId,
                OrganizationCode = userBase.OrganizationCode
            };
            var infoData = new GetInpatientInfoParam()
            {
                User       = userBase,
                BusinessId = param.BusinessId,
            };
            //获取his结算
            var settlementData = _serviceBasicService.GetHisHospitalizationSettlement(infoData);

            //获取医保病人信息
            var residentData = _medicalInsuranceSqlRepository.QueryMedicalInsuranceResidentInfo(queryResidentParam);

            if (string.IsNullOrWhiteSpace(settlementData.LeaveHospitalDate))
            {
                throw new Exception("当前病人在基层中未办理出院,不能办理医保预结算!!!");
            }

            var preSettlement = new WorkerBirthPreSettlementParam()
            {
                MedicalCategory = param.MedicalCategory,
                FetusNumber     = param.FetusNumber,
                MedicalInsuranceHospitalizationNo = residentData.MedicalInsuranceHospitalizationNo,
                LeaveHospitalDate = Convert.ToDateTime(settlementData.LeaveHospitalDate).ToString("yyyyMMdd"),
            };
            //获取诊断
            var diagnosisData = CommonHelp.GetDiagnosis(param.DiagnosisList);

            preSettlement.AdmissionMainDiagnosisIcd10 = diagnosisData.AdmissionMainDiagnosisIcd10;
            preSettlement.DiagnosisIcd10Two           = diagnosisData.DiagnosisIcd10Two;
            preSettlement.DiagnosisIcd10Three         = diagnosisData.DiagnosisIcd10Three;
            //医保结算
            var resultData = _workerMedicalInsuranceRepository.WorkerBirthPreSettlement(preSettlement);

            //报销金额 =统筹支付+补充医疗保险支付金额+专项基金支付金额+
            //公务员补贴+公务员补助+其它支付金额
            decimal reimbursementExpenses = resultData.BasicOverallPay + resultData.SupplementPayAmount + resultData.SpecialFundPayAmount
                                            + resultData.CivilServantsSubsidies + resultData.CivilServantsSubsidy + resultData.OtherPaymentAmount;
            var updateParam = new UpdateMedicalInsuranceResidentSettlementParam()
            {
                ReimbursementExpensesAmount = CommonHelp.ValueToDouble(reimbursementExpenses),
                SelfPayFeeAmount            = resultData.CashPayment,
                OtherInfo    = JsonConvert.SerializeObject(resultData),
                Id           = residentData.Id,
                UserId       = userBase.UserId,
                SettlementNo = resultData.DocumentNo,
                MedicalInsuranceAllAmount  = resultData.TotalAmount,
                PreSettlementTransactionId = userBase.TransKey,
                MedicalInsuranceState      = MedicalInsuranceState.MedicalInsurancePreSettlement
            };

            //存入中间库
            _medicalInsuranceSqlRepository.UpdateMedicalInsuranceResidentSettlement(updateParam);
            var logParam = new AddHospitalLogParam()
            {
                JoinOrOldJson   = JsonConvert.SerializeObject(param),
                ReturnOrNewJson = JsonConvert.SerializeObject(resultData),
                User            = userBase,
                Remark          = "职工生育住院病人预结算"
            };

            _systemManageRepository.AddHospitalLog(logParam);

            return(resultData);
        }
        /// <summary>
        ///取消结算
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public string WorkerSettlementCancel(WorkerSettlementCancelParam param)
        {
            string resultData = null;

            if (param.CancelLimit == "1")
            { //划卡取消
                if (param.WorkersStrokeCardNo != null)
                {
                    _workerMedicalInsuranceRepository.CancelWorkerStrokeCard(new CancelWorkersStrokeCardParam()
                    {
                        WorkersStrokeCardNo = param.WorkersStrokeCardNo,
                        Operate             = param.User.UserName,
                        Remarks             = param.CancelSettlementRemarks
                    });
                }

                // 结算取消
                resultData = _workerMedicalInsuranceRepository.WorkerSettlementCancel(param);
                //取消交易id
                var cancelTransactionId = param.User.TransKey;
                //回参构建
                var xmlData = new HospitalSettlementCancelXml()
                {
                    SettlementNo = param.SettlementNo,
                };
                var strXmlBackParam = XmlSerializeHelper.HisXmlSerialize(xmlData);
                var saveXml         = new SaveXmlDataParam()
                {
                    User = param.User,
                    MedicalInsuranceBackNum = param.MedicalInsuranceHospitalizationNo,
                    MedicalInsuranceCode    = "42",
                    BusinessId = param.BusinessId,
                    BackParam  = strXmlBackParam
                };
                //存基层
                _webBasicRepository.SaveXmlData(saveXml);
                var updateParam = new UpdateMedicalInsuranceResidentSettlementParam()
                {
                    UserId = param.User.UserId,
                    Id     = param.Id,
                    CancelTransactionId     = cancelTransactionId,
                    MedicalInsuranceState   = MedicalInsuranceState.MedicalInsurancePreSettlement,
                    CancelSettlementRemarks = param.CancelSettlementRemarks
                };
                //存入中间层
                _medicalInsuranceSqlRepository.UpdateMedicalInsuranceResidentSettlement(updateParam);
                //添加日志
                var logParam = new AddHospitalLogParam()
                {
                    JoinOrOldJson   = JsonConvert.SerializeObject(param),
                    ReturnOrNewJson = "{ yearSign= " + resultData + " }",
                    User            = param.User,
                    Remark          = "职工住院结算取消",
                    RelationId      = param.Id,
                };
                _systemManageRepository.AddHospitalLog(logParam);
            }
            else if (param.CancelLimit == "2")//取消结算,并删除资料<==>删除资料与取消入院
            {
                //回参构建
                var xmlData = new HospitalizationRegisterXml()
                {
                    MedicalInsuranceHospitalizationNo = param.MedicalInsuranceHospitalizationNo,
                };
                var strXmlBackParam = XmlSerializeHelper.HisXmlSerialize(xmlData);
                var saveXml         = new SaveXmlDataParam()
                {
                    User = param.User,
                    MedicalInsuranceBackNum = "Qxjs",
                    MedicalInsuranceCode    = "22",
                    BusinessId = param.BusinessId,
                    BackParam  = strXmlBackParam
                };
                //存基层
                _webBasicRepository.SaveXmlData(saveXml);

                var updateParamData = new UpdateMedicalInsuranceResidentSettlementParam()
                {
                    UserId = param.User.UserId,
                    Id     = param.Id,
                    CancelTransactionId   = param.User.TransKey,
                    MedicalInsuranceState = MedicalInsuranceState.MedicalInsuranceCancelSettlement,
                    IsHisUpdateState      = true
                };
                //更新中间层
                _medicalInsuranceSqlRepository.UpdateMedicalInsuranceResidentSettlement(updateParamData);
            }



            //if (param.CancelLimit == "2") //取消结算,并删除资料<==>删除资料与取消入院
            //{
            //    //回参构建
            //    var xmlData = new HospitalizationRegisterXml()
            //    {
            //        MedicalInsuranceHospitalizationNo = param.MedicalInsuranceHospitalizationNo,
            //    };
            //    var strXmlBackParam = XmlSerializeHelper.HisXmlSerialize(xmlData);
            //    var saveXml = new SaveXmlDataParam()
            //    {
            //        User = param.User,
            //        MedicalInsuranceBackNum = "Qxjs",
            //        MedicalInsuranceCode = "22",
            //        BusinessId = param.BusinessId,
            //        BackParam = strXmlBackParam
            //    };
            //    //存基层
            //    _webBasicRepository.SaveXmlData(saveXml);

            //    var updateParamData = new UpdateMedicalInsuranceResidentSettlementParam()
            //    {
            //        UserId = param.User.UserId,
            //        Id = param.Id,
            //        CancelTransactionId = cancelTransactionId,
            //        MedicalInsuranceState = MedicalInsuranceState.MedicalInsuranceCancelSettlement,
            //        IsHisUpdateState = true
            //    };
            //    //更新中间层
            //    _medicalInsuranceSqlRepository.UpdateMedicalInsuranceResidentSettlement(updateParamData);

            //}
            return(resultData);
        }
        /// <summary>
        /// 职工划卡
        /// </summary>
        /// <param name="param"></param>
        public void WorkerStrokeCard(WorkerStrokeCardParam param)
        {
            var queryResidentParam = new QueryMedicalInsuranceResidentInfoParam()
            {
                BusinessId = param.BusinessId,
            };
            //获取医保病人信息
            var residentData = _medicalInsuranceSqlRepository.QueryMedicalInsuranceResidentInfo(queryResidentParam);

            var userInfoData = _residentMedicalInsuranceRepository.GetUserInfo(new ResidentUserInfoParam()
            {
                IdentityMark = residentData.IdentityMark,
                AfferentSign = residentData.AfferentSign
            });

            //回参构建
            var xmlData = new HospitalSettlementXml()
            {
                MedicalInsuranceHospitalizationNo = param.MedicalInsuranceHospitalizationNo,
                CashPayment      = param.SelfPayFeeAmount,
                SettlementNo     = param.DocumentNo,
                PaidAmount       = 0,
                AllAmount        = param.AllAmount,
                PatientName      = userInfoData.PatientName,
                AccountBalance   = userInfoData.WorkersInsuranceBalance,
                AccountAmountPay = param.AccountPayAmount,
            };
            var strXmlBackParam = XmlSerializeHelper.HisXmlSerialize(xmlData);
            var saveXml         = new SaveXmlDataParam()
            {
                User = param.User,
                MedicalInsuranceBackNum = param.DocumentNo,
                MedicalInsuranceCode    = "41",
                BusinessId = param.BusinessId,
                BackParam  = strXmlBackParam
            };

            //结算存基层
            _webBasicRepository.SaveXmlData(saveXml);
            var updateParam = new UpdateMedicalInsuranceResidentSettlementParam()
            {
                UserId = param.User.UserId,
                ReimbursementExpensesAmount = param.AccountPayAmount,
                SelfPayFeeAmount            = param.SelfPayFeeAmount,
                OtherInfo             = JsonConvert.SerializeObject(xmlData),
                Id                    = param.Id,
                WorkersStrokeCardNo   = param.DocumentNo,
                WorkersStrokeCardInfo = JsonConvert.SerializeObject(xmlData),
                MedicalInsuranceState = MedicalInsuranceState.HisSettlement
            };

            //  更新中间层
            _medicalInsuranceSqlRepository.UpdateMedicalInsuranceResidentSettlement(updateParam);
            //添加日志
            var logParam = new AddHospitalLogParam()
            {
                JoinOrOldJson   = JsonConvert.SerializeObject(param),
                ReturnOrNewJson = JsonConvert.SerializeObject(xmlData),
                User            = param.User,
                Remark          = "职工病人划卡结算",
                RelationId      = param.Id,
            };

            _systemManageRepository.AddHospitalLog(logParam); //回参构建
        }
        /// <summary>
        /// 职工住院预结算
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public WorkerHospitalizationPreSettlementDto WorkerHospitalizationPreSettlement(UiBaseDataParam param)
        {
            //获取操作人员信息
            var userBase = _serviceBasicService.GetUserBaseInfo(param.UserId);

            userBase.TransKey = param.TransKey;
            var queryResidentParam = new QueryMedicalInsuranceResidentInfoParam()
            {
                BusinessId       = param.BusinessId,
                OrganizationCode = userBase.OrganizationCode
            };
            var infoData = new GetInpatientInfoParam()
            {
                User       = userBase,
                BusinessId = param.BusinessId,
            };
            //获取his预结算
            var hisPreSettlementData = _serviceBasicService.GetHisHospitalizationPreSettlement(infoData);
            var preSettlementData    = hisPreSettlementData.PreSettlementData.FirstOrDefault();
            //获取医保病人信息
            var residentData = _medicalInsuranceSqlRepository.QueryMedicalInsuranceResidentInfo(queryResidentParam);
            //获取医院等级
            var gradeData = _systemManageRepository.QueryHospitalOrganizationGrade(userBase.OrganizationCode);

            if (string.IsNullOrWhiteSpace(preSettlementData.EndDate))
            {
                throw new Exception("当前病人在基层中未办理出院,不能办理医保预结算!!!");
            }
            //获取医保账号
            var userData = _systemManageRepository.QueryHospitalOperator(
                new QueryHospitalOperatorParam()
            {
                UserId = param.UserId
            });
            var preSettlement = new WorkerHospitalizationPreSettlementParam()
            {
                User       = userBase,
                Id         = residentData.Id,
                BusinessId = param.BusinessId,
                MedicalInsuranceHospitalizationNo = residentData.MedicalInsuranceHospitalizationNo,
                LeaveHospitalDate          = Convert.ToDateTime(preSettlementData.EndDate).ToString("yyyyMMdd"),
                AdministrativeArea         = gradeData.AdministrativeArea,
                Operators                  = preSettlementData.Operator,
                IsHospitalizationFrequency = "0",
                OrganizationCode           = gradeData.MedicalInsuranceAccount,
            };
            //医保结算
            var resultData = _workerMedicalInsuranceRepository.WorkerHospitalizationPreSettlement(preSettlement);

            //报销金额 =统筹支付+补充医疗保险支付金额+专项基金支付金额+
            //公务员补贴+公务员补助+其它支付金额
            decimal reimbursementExpenses = resultData.BasicOverallPay + resultData.SupplementPayAmount + resultData.SpecialFundPayAmount
                                            + resultData.CivilServantsSubsidies + resultData.CivilServantsSubsidy + resultData.OtherPaymentAmount;
            var updateParam = new UpdateMedicalInsuranceResidentSettlementParam()
            {
                ReimbursementExpensesAmount = CommonHelp.ValueToDouble(reimbursementExpenses),
                SelfPayFeeAmount            = resultData.CashPayment,
                OtherInfo    = JsonConvert.SerializeObject(resultData),
                Id           = residentData.Id,
                UserId       = userBase.UserId,
                SettlementNo = resultData.DocumentNo,
                MedicalInsuranceAllAmount  = resultData.TotalAmount,
                PreSettlementTransactionId = userBase.TransKey,
                MedicalInsuranceState      = MedicalInsuranceState.MedicalInsurancePreSettlement
            };

            //存入中间库
            _medicalInsuranceSqlRepository.UpdateMedicalInsuranceResidentSettlement(updateParam);
            var logParam = new AddHospitalLogParam()
            {
                JoinOrOldJson   = JsonConvert.SerializeObject(param),
                ReturnOrNewJson = JsonConvert.SerializeObject(resultData),
                User            = userBase,
                Remark          = "职工住院病人预结算"
            };

            _systemManageRepository.AddHospitalLog(logParam);

            return(resultData);
        }
        /// <summary>
        /// 职工入院登记修改
        /// </summary>
        /// <param name="uiParam"></param>
        public void ModifyWorkerHospitalization(HospitalizationModifyUiParam uiParam)
        { //his登陆
            var userBase = _serviceBasicService.GetUserBaseInfo(uiParam.UserId);

            userBase.TransKey = uiParam.TransKey;
            var param = GetWorkerHospitalizationModify(uiParam, userBase);

            //医保执行
            _workerMedicalInsuranceRepository.ModifyWorkerHospitalization(param);
            // 回参构建
            var xmlData = new HospitalizationModifyXml()
            {
                MedicalInsuranceHospitalizationNo = param.MedicalInsuranceHospitalizationNo,
            };
            //var strXmlBackParam = XmlSerializeHelper.HisXmlSerialize(xmlData);
            //var saveXml = new SaveXmlDataParam()
            //{
            //    User = param.User,
            //    MedicalInsuranceBackNum = "zyzlxgall",
            //    MedicalInsuranceCode = "23",
            //    BusinessId = param.BusinessId,
            //    BackParam = strXmlBackParam
            //};
            ////存基层
            //_webBasicRepository.SaveXmlData(saveXml);
            var paramStr  = "";
            var queryData = _medicalInsuranceSqlRepository.QueryMedicalInsuranceResidentInfo(
                new QueryMedicalInsuranceResidentInfoParam
            {
                BusinessId       = param.BusinessId,
                OrganizationCode = param.User.OrganizationCode
            });

            if (!string.IsNullOrWhiteSpace(queryData.AdmissionInfoJson))
            {
                var data =
                    JsonConvert.DeserializeObject <WorKerHospitalizationRegisterParam>(queryData
                                                                                       .AdmissionInfoJson);
                if (!string.IsNullOrWhiteSpace(param.AdmissionDate))
                {
                    data.AdmissionDate = param.AdmissionDate;
                }
                if (!string.IsNullOrWhiteSpace(param.AdmissionMainDiagnosis))
                {
                    data.AdmissionMainDiagnosis = param.AdmissionMainDiagnosis;
                }
                if (!string.IsNullOrWhiteSpace(param.AdmissionMainDiagnosisIcd10))
                {
                    data.AdmissionMainDiagnosisIcd10 = param.AdmissionMainDiagnosisIcd10;
                }
                if (!string.IsNullOrWhiteSpace(param.DiagnosisIcd10Three))
                {
                    data.DiagnosisIcd10Three = param.DiagnosisIcd10Three;
                }
                if (!string.IsNullOrWhiteSpace(param.DiagnosisIcd10Two))
                {
                    data.DiagnosisIcd10Two = param.DiagnosisIcd10Two;
                }
                if (!string.IsNullOrWhiteSpace(param.InpatientDepartmentCode))
                {
                    data.InpatientDepartmentCode = param.InpatientDepartmentCode;
                }
                if (!string.IsNullOrWhiteSpace(param.BedNumber))
                {
                    data.BedNumber = param.BedNumber;
                }
                data.Id  = queryData.Id;
                paramStr = JsonConvert.SerializeObject(data);
            }
            var saveData = new MedicalInsuranceDto
            {
                AdmissionInfoJson = paramStr,
                BusinessId        = queryData.BusinessId,
                Id       = queryData.Id,
                IsModify = true,
            };

            _medicalInsuranceSqlRepository.SaveMedicalInsurance(param.User, saveData);
            //日志
            var logParam = new AddHospitalLogParam();

            logParam.User            = param.User;
            logParam.RelationId      = queryData.Id;
            logParam.JoinOrOldJson   = queryData.AdmissionInfoJson;
            logParam.ReturnOrNewJson = paramStr;
            logParam.Remark          = "医保入院登记修改";
            _systemManageRepository.AddHospitalLog(logParam);
        }
        //门诊取消结算
        public void CancelOutpatientDepartmentCost(CancelOutpatientDepartmentCostUiParam param)
        {
            var userBase = _serviceBasicService.GetUserBaseInfo(param.UserId);

            userBase.TransKey = param.TransKey;
            //获取医保病人信息
            var queryResidentParam = new QueryMedicalInsuranceResidentInfoParam()
            {
                BusinessId       = param.BusinessId,
                OrganizationCode = userBase.OrganizationCode
            };
            var residentData = _medicalInsuranceSqlRepository.QueryMedicalInsuranceResidentInfo(queryResidentParam);

            if (residentData == null)
            {
                throw new Exception("当前病人未结算,不能取消结算!!!");
            }
            if (residentData.MedicalInsuranceState != MedicalInsuranceState.HisSettlement)
            {
                throw new Exception("当前病人未结算,不能取消结算!!!");
            }
            //计划生育
            if (residentData.IsBirthHospital == 1)
            {
                _outpatientDepartmentRepository.OutpatientPlanBirthSettlementCancel(new OutpatientPlanBirthSettlementCancelParam()
                {
                    SettlementNo  = residentData.SettlementNo,
                    CancelRemarks = param.CancelSettlementRemarks
                });
            }
            else  //普通门诊
            {
                _outpatientDepartmentRepository.CancelOutpatientDepartmentCost(new CancelOutpatientDepartmentCostParam()
                {
                    DocumentNo = residentData.SettlementNo
                });
            }



            //添加日志
            var logParam = new AddHospitalLogParam()
            {
                JoinOrOldJson = JsonConvert.SerializeObject(param),
                User          = userBase,
                Remark        = "门诊取消结算",
                RelationId    = residentData.Id,
                BusinessId    = param.BusinessId,
            };

            _systemManageRepository.AddHospitalLog(logParam);

            //回参构建
            var xmlData = new OutpatientDepartmentCostCancelXml()
            {
                SettlementNo = residentData.SettlementNo
            };
            var strXmlBackParam = XmlSerializeHelper.HisXmlSerialize(xmlData);
            var saveXml         = new SaveXmlDataParam()
            {
                User = userBase,
                MedicalInsuranceBackNum = "Qxjs",
                MedicalInsuranceCode    = "42MZ",
                BusinessId = param.BusinessId,
                BackParam  = strXmlBackParam
            };

            //存基层
            _webBasicRepository.SaveXmlData(saveXml);

            var updateParamData = new UpdateMedicalInsuranceResidentSettlementParam()
            {
                UserId = param.UserId,
                Id     = residentData.Id,
                CancelTransactionId     = param.TransKey,
                MedicalInsuranceState   = MedicalInsuranceState.MedicalInsuranceCancelSettlement,
                IsHisUpdateState        = true,
                CancelSettlementRemarks = param.CancelSettlementRemarks
            };

            //更新中间层
            _medicalInsuranceSqlRepository.UpdateMedicalInsuranceResidentSettlement(updateParamData);
        }
        /// <summary>
        /// 入院登记
        /// </summary>
        /// <returns></returns>
        public void HospitalizationRegister(ResidentHospitalizationRegisterUiParam param)
        { //his登陆
            var userBase = _webserviceBasicService.GetUserBaseInfo(param.UserId);

            userBase.TransKey = param.TransKey;
            var infoData = new GetInpatientInfoParam()
            {
                User       = userBase,
                BusinessId = param.BusinessId,
            };
            //获取医保病人
            var inpatientData = _webserviceBasicService.GetInpatientInfo(infoData);
            var registerParam = GetResidentHospitalizationRegisterParam(param, inpatientData);
            var residentData  = _residentMedicalInsuranceRepository.HospitalizationRegister(registerParam);
            var saveData      = new MedicalInsuranceDto
            {
                AdmissionInfoJson = JsonConvert.SerializeObject(registerParam),
                BusinessId        = param.BusinessId,
                Id            = Guid.NewGuid(),
                InsuranceType = 342,
                MedicalInsuranceHospitalizationNo = residentData.MedicalInsuranceInpatientNo,
                MedicalInsuranceState             = MedicalInsuranceState.MedicalInsuranceHospitalized,
                AfferentSign = param.AfferentSign,
                IdentityMark = param.IdentityMark
            };

            //保存中间库
            _medicalInsuranceSqlRepository.SaveMedicalInsurance(userBase, saveData);
            //回参构建
            var xmlData = new HospitalizationRegisterXml()
            {
                MedicalInsuranceType = "10",
                MedicalInsuranceHospitalizationNo = residentData.MedicalInsuranceInpatientNo,
                InsuranceNo = null,
            };
            var strXmlBackParam = XmlSerializeHelper.HisXmlSerialize(xmlData);
            var saveXml         = new SaveXmlDataParam()
            {
                User = userBase,
                MedicalInsuranceBackNum = "CXJB002",
                MedicalInsuranceCode    = "21",
                BusinessId = param.BusinessId,
                BackParam  = strXmlBackParam
            };

            //存基层
            _webBasicRepository.SaveXmlData(saveXml);
            //更新中间库
            saveData.MedicalInsuranceState = MedicalInsuranceState.HisHospitalized;
            _medicalInsuranceSqlRepository.SaveMedicalInsurance(userBase, saveData);
            //日志
            var logParam = new AddHospitalLogParam
            {
                User            = userBase,
                RelationId      = saveData.Id,
                JoinOrOldJson   = JsonConvert.SerializeObject(param),
                ReturnOrNewJson = JsonConvert.SerializeObject(residentData),
                BusinessId      = param.BusinessId,
                Remark          = "医保入院登记;TransactionId:" + userBase.TransKey
            };

            _systemManageRepository.AddHospitalLog(logParam);
            //保存入院数据
            infoData.IsSave = true;
            _webserviceBasicService.GetInpatientInfo(infoData);
        }
        /// <summary>
        /// 居民住院结算
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public HospitalizationPresettlementDto LeaveHospitalSettlement(LeaveHospitalSettlementUiParam param)
        {
            // 获取操作人员信息
            var userBase           = _webserviceBasicService.GetUserBaseInfo(param.UserId);
            var queryResidentParam = new QueryMedicalInsuranceResidentInfoParam()
            {
                BusinessId       = param.BusinessId,
                OrganizationCode = userBase.OrganizationCode
            };

            userBase.TransKey = param.TransKey;
            var infoData = new GetInpatientInfoParam()
            {
                User       = userBase,
                BusinessId = param.BusinessId,
            };
            //获取his结算
            var hisSettlement = _webserviceBasicService.GetHisHospitalizationSettlement(infoData);
            //获取医保病人信息
            var residentData = _medicalInsuranceSqlRepository.QueryMedicalInsuranceResidentInfo(queryResidentParam);

            if (residentData.MedicalInsuranceState != MedicalInsuranceState.MedicalInsurancePreSettlement)
            {
                throw new Exception("当前病人未办理预结算,不能办理结算!!!");
            }
            if (residentData.MedicalInsuranceState == MedicalInsuranceState.HisSettlement)
            {
                throw new Exception("当前病人已办理医保结算,不能办理再次结算!!!");
            }

            var inpatientInfoParam = new QueryInpatientInfoParam()
            {
                BusinessId = param.BusinessId
            };
            //获取住院病人
            var inpatientInfoData = _hisSqlRepository.QueryInpatientInfo(inpatientInfoParam);

            if (inpatientInfoData == null)
            {
                throw new Exception("该病人未在中心库中,请检查是否办理医保入院!!!");
            }

            var settlementParam = new LeaveHospitalSettlementParam()
            {
                MedicalInsuranceHospitalizationNo = residentData.MedicalInsuranceHospitalizationNo,
                LeaveHospitalDate           = Convert.ToDateTime(hisSettlement.LeaveHospitalDate).ToString("yyyyMMdd"),
                UserId                      = hisSettlement.LeaveHospitalOperator,
                LeaveHospitalInpatientState = param.LeaveHospitalInpatientState,
            };
            //获取诊断
            var diagnosisData = CommonHelp.GetDiagnosis(param.DiagnosisList);

            settlementParam.LeaveHospitalMainDiagnosisIcd10  = diagnosisData.AdmissionMainDiagnosisIcd10;
            settlementParam.LeaveHospitalDiagnosisIcd10Two   = diagnosisData.DiagnosisIcd10Two;
            settlementParam.LeaveHospitalDiagnosisIcd10Three = diagnosisData.DiagnosisIcd10Three;
            settlementParam.LeaveHospitalMainDiagnosis       = diagnosisData.DiagnosisDescribe;
            var infoParam = new LeaveHospitalSettlementInfoParam()
            {
                User        = userBase,
                Id          = residentData.Id,
                InsuranceNo = residentData.InsuranceNo,
                BusinessId  = inpatientInfoData.BusinessId,
                IdCardNo    = inpatientInfoData.IdCardNo,
            };
            //医保执行
            var data = _residentMedicalInsuranceRepository.LeaveHospitalSettlement(settlementParam, infoParam);

            if (data == null)
            {
                throw new Exception("居民住院结算反馈失败");
            }
            var updateData = new UpdateMedicalInsuranceResidentSettlementParam()
            {
                UserId = userBase.UserId,
                ReimbursementExpensesAmount = CommonHelp.ValueToDouble(data.ReimbursementExpenses),
                SelfPayFeeAmount            = data.CashPayment,
                OtherInfo    = JsonConvert.SerializeObject(data),
                Id           = residentData.Id,
                SettlementNo = data.DocumentNo,
                MedicalInsuranceAllAmount = data.TotalAmount,
                SettlementTransactionId   = userBase.UserId,
                MedicalInsuranceState     = MedicalInsuranceState.MedicalInsuranceSettlement
            };

            //存入中间层
            _medicalInsuranceSqlRepository.UpdateMedicalInsuranceResidentSettlement(updateData);
            //添加日志
            var logParam = new AddHospitalLogParam()
            {
                JoinOrOldJson   = JsonConvert.SerializeObject(param),
                ReturnOrNewJson = JsonConvert.SerializeObject(data),
                User            = userBase,
                Remark          = "居民住院结算",
                RelationId      = residentData.Id,
                BusinessId      = param.BusinessId,
            };


            var userInfoData = _residentMedicalInsuranceRepository.GetUserInfo(new ResidentUserInfoParam()
            {
                IdentityMark = residentData.IdentityMark,
                AfferentSign = residentData.AfferentSign,
            });

            // 回参构建
            var xmlData = new HospitalSettlementXml()
            {
                MedicalInsuranceHospitalizationNo = residentData.MedicalInsuranceHospitalizationNo,
                CashPayment      = data.CashPayment,
                SettlementNo     = data.DocumentNo,
                PaidAmount       = data.PaidAmount,
                AllAmount        = data.TotalAmount,
                PatientName      = userInfoData.PatientName,
                AccountBalance   = userInfoData.WorkersInsuranceBalance,
                AccountAmountPay = 0,
            };


            var strXmlBackParam = XmlSerializeHelper.HisXmlSerialize(xmlData);
            var saveXml         = new SaveXmlDataParam()
            {
                User = userBase,
                MedicalInsuranceBackNum = data.DocumentNo,
                MedicalInsuranceCode    = "41",
                BusinessId = param.BusinessId,
                BackParam  = strXmlBackParam
            };

            //结算存基层
            _webBasicRepository.SaveXmlData(saveXml);


            var updateParamData = new UpdateMedicalInsuranceResidentSettlementParam()
            {
                UserId = param.UserId,
                Id     = residentData.Id,
                MedicalInsuranceState = MedicalInsuranceState.HisSettlement,
                IsHisUpdateState      = true
            };

            //  更新中间层
            _medicalInsuranceSqlRepository.UpdateMedicalInsuranceResidentSettlement(updateParamData);
            //结算后保存信息
            var saveParam = AutoMapper.Mapper.Map <SaveInpatientSettlementParam>(hisSettlement);

            saveParam.Id   = (Guid)inpatientInfoData.Id;
            saveParam.User = userBase;
            saveParam.LeaveHospitalDiagnosisJson = JsonConvert.SerializeObject(param.DiagnosisList);
            _hisSqlRepository.SaveInpatientSettlement(saveParam);
            return(data);
        }
        //public void PrescriptionUploadAll(UploadAllParam param)
        //{
        //    //更新费用
        //}

        /// <summary>
        /// 居民住院预结算
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public HospitalizationPresettlementDto HospitalizationPreSettlement(UiBaseDataParam param)
        {
            HospitalizationPresettlementDto resultData = null;
            //获取操作人员信息
            var userBase = _webserviceBasicService.GetUserBaseInfo(param.UserId);

            userBase.TransKey = param.TransKey;
            var queryResidentParam = new QueryMedicalInsuranceResidentInfoParam()
            {
                BusinessId       = param.BusinessId,
                OrganizationCode = userBase.OrganizationCode
            };
            var infoData = new GetInpatientInfoParam()
            {
                User       = userBase,
                BusinessId = param.BusinessId,
            };
            //获取his预结算
            var hisPreSettlementData = _webserviceBasicService.GetHisHospitalizationPreSettlement(infoData);
            var preSettlementData    = hisPreSettlementData.PreSettlementData.FirstOrDefault();
            //获取医保病人信息
            var residentData = _medicalInsuranceSqlRepository.QueryMedicalInsuranceResidentInfo(queryResidentParam);

            if (string.IsNullOrWhiteSpace(preSettlementData.EndDate))
            {
                throw new Exception("当前病人在基层中未办理出院,不能办理医保预结算!!!");
            }
            //医保执行
            var data = _residentMedicalInsuranceRepository.HospitalizationPreSettlement(new HospitalizationPresettlementParam()
            {
                LeaveHospitalDate = Convert.ToDateTime(preSettlementData.EndDate).ToString("yyyyMMdd"),
                MedicalInsuranceHospitalizationNo = residentData.MedicalInsuranceHospitalizationNo,
            });

            resultData = data ?? throw new Exception("居民预结算返回结果有误!!!");
            //报销金额 =统筹支付+补充险支付+生育补助+民政救助+民政重大疾病救助+精准扶贫+民政优抚+其它支付
            decimal reimbursementExpenses =
                data.BasicOverallPay + data.SupplementPayAmount + data.BirthAAllowance +
                data.CivilAssistancePayAmount + data.CivilAssistanceSeriousIllnessPayAmount +
                data.AccurateAssistancePayAmount + data.CivilServicessistancePayAmount +
                data.OtherPaymentAmount;

            resultData.ReimbursementExpenses = reimbursementExpenses;
            var updateParam = new UpdateMedicalInsuranceResidentSettlementParam()
            {
                ReimbursementExpensesAmount = CommonHelp.ValueToDouble(reimbursementExpenses),
                SelfPayFeeAmount            = data.CashPayment,
                OtherInfo    = JsonConvert.SerializeObject(data),
                Id           = residentData.Id,
                UserId       = param.UserId,
                SettlementNo = data.DocumentNo,
                MedicalInsuranceAllAmount  = data.TotalAmount,
                PreSettlementTransactionId = param.TransKey,
                MedicalInsuranceState      = MedicalInsuranceState.MedicalInsurancePreSettlement
            };

            //存入中间库
            _medicalInsuranceSqlRepository.UpdateMedicalInsuranceResidentSettlement(updateParam);
            var logParam = new AddHospitalLogParam()
            {
                JoinOrOldJson   = JsonConvert.SerializeObject(param),
                ReturnOrNewJson = JsonConvert.SerializeObject(data),
                User            = userBase,
                BusinessId      = param.BusinessId,
                Remark          = "居民住院病人预结算"
            };

            _systemManageRepository.AddHospitalLog(logParam);
            return(resultData);
        }
        public void DeletePrescriptionUpload(BaseUiBusinessIdDataParam param)
        {
            var userBase = _webserviceBasicService.GetUserBaseInfo(param.UserId);

            userBase.TransKey = param.TransKey;
            //获取医保病人信息
            var residentDataParam = new QueryMedicalInsuranceResidentInfoParam()
            {
                BusinessId       = param.BusinessId,
                OrganizationCode = userBase.OrganizationCode,
            };
            List <QueryInpatientInfoDetailDto> queryData;
            //获取病人明细
            var queryDataDetail = _hisSqlRepository.InpatientInfoDetailQuery
                                      (new InpatientInfoDetailQueryParam()
            {
                BusinessId = param.BusinessId
            });

            //获取选择
            queryData = param.DataIdList != null?queryDataDetail.Where(c => param.DataIdList.Contains(c.Id.ToString())).ToList() : queryDataDetail;

            //获取病人医保信息
            var residentData = _medicalInsuranceSqlRepository.QueryMedicalInsuranceResidentInfo(residentDataParam);

            if (queryData.Any())
            {
                //获取已上传数据、
                var uploadDataId    = queryData.Where(c => c.UploadMark == 1).Select(d => d.Id).ToList();
                var batchNumberList = queryData.Where(c => c.UploadMark == 1).GroupBy(d => d.BatchNumber).Select(b => b.Key).ToList();
                if (batchNumberList.Any())
                {
                    var deleteParam = new DeletePrescriptionUploadParam()
                    {
                        BatchNumber = string.Join(",", batchNumberList.ToArray()),
                        MedicalInsuranceHospitalizationNo = residentData.MedicalInsuranceHospitalizationNo
                    };
                    _residentMedicalInsuranceRepository.DeletePrescriptionUpload(deleteParam, uploadDataId, userBase);
                    //取消医保上传状态
                    var updateFeeParam =
                        uploadDataId.Select(c => new UpdateHospitalizationFeeParam {
                        Id = c
                    })
                        .ToList();
                    _medicalInsuranceSqlRepository.UpdateHospitalizationFee(updateFeeParam, true, userBase);
                    //日志
                    var joinJson = JsonConvert.SerializeObject(queryData.Select(c => c.DetailId).ToList());
                    var logParam = new AddHospitalLogParam
                    {
                        User            = userBase,
                        RelationId      = Guid.Parse(param.BusinessId),
                        JoinOrOldJson   = joinJson,
                        ReturnOrNewJson = "",
                        BusinessId      = param.BusinessId,
                        Remark          = "医保取消处方明细id执行成功"
                    };
                    _systemManageRepository.AddHospitalLog(logParam);
                    // 回参构建
                    var xmlData = new HospitalizationFeeUploadCancelXml()
                    {
                        MedicalInsuranceHospitalizationNo = residentData.MedicalInsuranceHospitalizationNo,
                        RowDataList = queryData.Select(c => new HospitalizationFeeUploadRowXml()
                        {
                            SerialNumber = c.DetailId
                        }).ToList()
                    };
                    var strXmlBackParam = XmlSerializeHelper.HisXmlSerialize(xmlData);
                    var saveXml         = new SaveXmlDataParam()
                    {
                        User = userBase,
                        MedicalInsuranceBackNum = "CXJB005",
                        MedicalInsuranceCode    = "32",
                        BusinessId = param.BusinessId,
                        BackParam  = strXmlBackParam
                    };
                    //存基层
                    _webBasicRepository.SaveXmlData(saveXml);
                    //日志
                    logParam.Remark = "基层取消处方明细id执行成功";
                    _systemManageRepository.AddHospitalLog(logParam);
                }
            }
            else
            {
                throw new Exception("未获取到医保退处方数据,请核实数据的正确性!!!");
            }
        }
        /// <summary>
        /// 入院登记修改
        /// </summary>
        /// <param name="param"></param>
        /// <param name="user"></param>
        public void HospitalizationModify(HospitalizationModifyUiParam param)
        {//his登陆
            var userBase = _webserviceBasicService.GetUserBaseInfo(param.UserId);

            userBase.TransKey = param.TransKey;
            var modifyParam = GetResidentHospitalizationModify(param);

            _residentMedicalInsuranceRepository.HospitalizationModify(modifyParam, userBase);
            var paramStr  = "";
            var queryData = _medicalInsuranceSqlRepository.QueryMedicalInsuranceResidentInfo(
                new QueryMedicalInsuranceResidentInfoParam
            {
                BusinessId       = param.BusinessId,
                OrganizationCode = userBase.OrganizationCode
            });

            if (!string.IsNullOrWhiteSpace(queryData.AdmissionInfoJson))
            {
                var data =
                    JsonConvert.DeserializeObject <QueryMedicalInsuranceDetailDto>(queryData
                                                                                   .AdmissionInfoJson);
                if (!string.IsNullOrWhiteSpace(modifyParam.AdmissionDate))
                {
                    data.AdmissionDate = modifyParam.AdmissionDate;
                }
                if (!string.IsNullOrWhiteSpace(modifyParam.AdmissionMainDiagnosis))
                {
                    data.AdmissionMainDiagnosis = modifyParam.AdmissionMainDiagnosis;
                }
                if (!string.IsNullOrWhiteSpace(modifyParam.AdmissionMainDiagnosisIcd10))
                {
                    data.AdmissionMainDiagnosisIcd10 = modifyParam.AdmissionMainDiagnosisIcd10;
                }
                if (!string.IsNullOrWhiteSpace(modifyParam.DiagnosisIcd10Three))
                {
                    data.DiagnosisIcd10Three = modifyParam.DiagnosisIcd10Three;
                }
                if (!string.IsNullOrWhiteSpace(modifyParam.DiagnosisIcd10Two))
                {
                    data.DiagnosisIcd10Two = modifyParam.DiagnosisIcd10Two;
                }
                if (!string.IsNullOrWhiteSpace(param.FetusNumber))
                {
                    data.FetusNumber = param.FetusNumber;
                }
                if (!string.IsNullOrWhiteSpace(param.HouseholdNature))
                {
                    data.HouseholdNature = param.HouseholdNature;
                }
                if (!string.IsNullOrWhiteSpace(param.InpatientDepartmentCode))
                {
                    data.InpatientDepartmentCode = param.InpatientDepartmentCode;
                }
                if (!string.IsNullOrWhiteSpace(param.BedNumber))
                {
                    data.BedNumber = param.BedNumber;
                }
                data.Id  = queryData.Id;
                paramStr = JsonConvert.SerializeObject(data);
            }

            var saveData = new MedicalInsuranceDto
            {
                AdmissionInfoJson = paramStr,
                BusinessId        = queryData.BusinessId,
                Id       = queryData.Id,
                IsModify = true,
                MedicalInsuranceHospitalizationNo = queryData.MedicalInsuranceHospitalizationNo
            };

            _medicalInsuranceSqlRepository.SaveMedicalInsurance(userBase, saveData);
            //日志
            var logParam = new AddHospitalLogParam
            {
                User            = userBase,
                RelationId      = queryData.Id,
                JoinOrOldJson   = queryData.AdmissionInfoJson,
                ReturnOrNewJson = paramStr,
                BusinessId      = param.BusinessId,
                Remark          = "医保入院登记修改"
            };

            _systemManageRepository.AddHospitalLog(logParam);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 取消医保出院结算
        /// </summary>
        /// <param name="param"></param>
        /// <param name="infoParam"></param>
        /// <returns></returns>
        public void LeaveHospitalSettlementCancel(LeaveHospitalSettlementCancelParam param,
                                                  LeaveHospitalSettlementCancelInfoParam infoParam)
        {
            var cancelLimit = param.CancelLimit;

            if (param.CancelLimit == "1")
            {
                Cancel(param);
                var updateParam = new UpdateMedicalInsuranceResidentSettlementParam()
                {
                    UserId = infoParam.User.UserId,
                    Id     = infoParam.Id,
                    CancelTransactionId   = infoParam.User.TransKey,
                    MedicalInsuranceState = MedicalInsuranceState.MedicalInsurancePreSettlement
                };
                //存入中间层
                _medicalInsuranceSqlRepository.UpdateMedicalInsuranceResidentSettlement(updateParam);
                //添加日志
                var logParam = new AddHospitalLogParam()
                {
                    JoinOrOldJson = JsonConvert.SerializeObject(param),
                    User          = infoParam.User,
                    Remark        = "居民住院结算取消",
                    RelationId    = infoParam.Id,
                };
                //回参构建
                var xmlData = new HospitalizationRegisterXml()
                {
                    MedicalInsuranceHospitalizationNo = param.MedicalInsuranceHospitalizationNo,
                };
                var strXmlBackParam = XmlSerializeHelper.HisXmlSerialize(xmlData);
                var saveXml         = new SaveXmlDataParam()
                {
                    User = infoParam.User,
                    MedicalInsuranceBackNum = "CXJB011",
                    MedicalInsuranceCode    = "42",
                    BusinessId = infoParam.BusinessId,
                    BackParam  = strXmlBackParam
                };
                //存基层
                _webBasicRepository.SaveXmlData(saveXml);
            }
            else if (param.CancelLimit == "2") //取消入院登记并删除资料
            {
                Cancel(param);
                //回参构建
                var xmlData = new HospitalizationRegisterCancelXml()
                {
                    MedicalInsuranceHospitalizationNo = param.MedicalInsuranceHospitalizationNo
                };
                var strXmlBackParam = XmlSerializeHelper.HisXmlSerialize(xmlData);
                var saveXml         = new SaveXmlDataParam()
                {
                    User = infoParam.User,
                    MedicalInsuranceBackNum = "CXJB004",
                    MedicalInsuranceCode    = "22",
                    BusinessId = infoParam.BusinessId,
                    BackParam  = strXmlBackParam
                };
                //存基层
                _webBasicRepository.SaveXmlData(saveXml);
            }
            void Cancel(LeaveHospitalSettlementCancelParam paramc)
            {
                var xmlStr = XmlHelp.SaveXml(paramc);

                if (xmlStr)
                {
                    int result = MedicalInsuranceDll.CallService_cxjb("CXJB011");
                    if (result == 1)
                    {
                        var data = XmlHelp.DeSerializerModel(new IniDto(), true);
                    }
                }
            }
        }