/// <summary>
        /// 门诊费用录入
        /// </summary>
        public OutpatientDepartmentCostInputDto OutpatientDepartmentCostInput(GetOutpatientPersonParam param)
        {
            OutpatientDepartmentCostInputDto resultData = null;
            //获取门诊病人数据
            var outpatientPerson = _serviceBasicService.GetOutpatientPerson(param);

            if (outpatientPerson == null)
            {
                throw new Exception("his中未获取到当前病人!!!");
            }
            //if (string.IsNullOrWhiteSpace(outpatientPerson.IdCardNo)) throw new Exception("当前病人的身份证号码不能为空!!!");
            var inputParam = new OutpatientDepartmentCostInputParam()
            {
                AllAmount    = outpatientPerson.MedicalTreatmentTotalCost,
                IdentityMark = param.IdentityMark,
                AfferentSign = param.AfferentSign,
                Operators    = param.User.UserName
            };

            //医保数据写入
            resultData = _outpatientDepartmentRepository.OutpatientDepartmentCostInput(inputParam);
            if (resultData == null)
            {
                throw new Exception("门诊费用医保执行失败!!!");
            }

            param.IsSave = true;
            param.Id     = Guid.NewGuid();
            //保存门诊病人
            _serviceBasicService.GetOutpatientPerson(param);
            //中间层数据写入
            var saveData = new MedicalInsuranceDto
            {
                AdmissionInfoJson = JsonConvert.SerializeObject(param),
                BusinessId        = param.UiParam.BusinessId,
                Id                                = Guid.NewGuid(),
                IsModify                          = false,
                InsuranceType                     = 999,
                MedicalInsuranceState             = MedicalInsuranceState.MedicalInsuranceHospitalized,
                MedicalInsuranceHospitalizationNo = resultData.DocumentNo,
                AfferentSign                      = param.AfferentSign,
                IdentityMark                      = param.IdentityMark
            };

            //存中间库
            _medicalInsuranceSqlRepository.SaveMedicalInsurance(param.User, saveData);

            //日志写入
            _systemManageRepository.AddHospitalLog(new AddHospitalLogParam()
            {
                User            = param.User,
                JoinOrOldJson   = JsonConvert.SerializeObject(inputParam),
                ReturnOrNewJson = JsonConvert.SerializeObject(resultData),
                RelationId      = param.Id,
                BusinessId      = param.UiParam.BusinessId,
                Remark          = "[R][OutpatientDepartment]门诊病人结算"
            });
            //获取病人的基础信息
            var userInfoData = _residentMedicalInsuranceRepository.GetUserInfo(new ResidentUserInfoParam()
            {
                IdentityMark = param.IdentityMark,
                AfferentSign = param.AfferentSign,
            });
            //回参构建
            var xmlData = new OutpatientDepartmentCostXml()
            {
                AccountBalance = userInfoData.InsuranceType == "342" ? userInfoData.ResidentInsuranceBalance : userInfoData.WorkersInsuranceBalance,
                MedicalInsuranceOutpatientNo = resultData.DocumentNo,
                CashPayment          = resultData.SelfPayFeeAmount,
                SettlementNo         = resultData.DocumentNo,
                AllAmount            = outpatientPerson.MedicalTreatmentTotalCost,
                PatientName          = outpatientPerson.PatientName,
                AccountAmountPay     = 0,
                MedicalInsuranceType = userInfoData.InsuranceType == "310" ? "1" : userInfoData.InsuranceType,
            };

            var strXmlBackParam = XmlSerializeHelper.HisXmlSerialize(xmlData);
            var saveXml         = new SaveXmlDataParam()
            {
                User = param.User,
                MedicalInsuranceBackNum = "zydj",
                MedicalInsuranceCode    = "48",
                BusinessId = param.UiParam.BusinessId,
                BackParam  = strXmlBackParam
            };

            //存基层
            _webBasicRepository.SaveXmlData(saveXml);
            var updateParam = new UpdateMedicalInsuranceResidentSettlementParam()
            {
                UserId = param.User.UserId,
                ReimbursementExpensesAmount = resultData.ReimbursementExpensesAmount,
                SelfPayFeeAmount            = resultData.SelfPayFeeAmount,
                OtherInfo    = JsonConvert.SerializeObject(resultData),
                Id           = saveData.Id,
                SettlementNo = resultData.DocumentNo,
                MedicalInsuranceAllAmount = outpatientPerson.MedicalTreatmentTotalCost,
                SettlementTransactionId   = param.User.TransKey,
                MedicalInsuranceState     = MedicalInsuranceState.HisSettlement
            };

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

            return(resultData);
        }
        /// <summary>
        /// 职工住院结算
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public WorkerHospitalizationPreSettlementDto WorkerHospitalizationSettlement(WorkerHospitalizationSettlementUiParam 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 userData = _systemManageRepository.QueryHospitalOperator(
                new QueryHospitalOperatorParam()
            {
                UserId = param.UserId
            });
            //获取医院等级
            var gradeData = _systemManageRepository.QueryHospitalOrganizationGrade(userBase.OrganizationCode);
            var infoParam = new WorkerHospitalizationSettlementParam()
            {
                User       = userBase,
                Id         = residentData.Id,
                BusinessId = inpatientInfoData.BusinessId,
                MedicalInsuranceHospitalizationNo = residentData.MedicalInsuranceHospitalizationNo,
                LeaveHospitalDate  = Convert.ToDateTime(hisSettlement.LeaveHospitalDate).ToString("yyyyMMdd"),
                LeaveHospitalState = param.LeaveHospitalInpatientState,
                Operators          = userBase.UserName,
                OrganizationCode   = gradeData.MedicalInsuranceAccount,
                AdministrativeArea = gradeData.AdministrativeArea
            };
            //获取诊断
            var diagnosisData = CommonHelp.GetDiagnosis(param.DiagnosisList);

            infoParam.AdmissionMainDiagnosisIcd10 = diagnosisData.AdmissionMainDiagnosisIcd10;
            infoParam.DiagnosisIcd10Two           = diagnosisData.DiagnosisIcd10Two;
            infoParam.DiagnosisIcd10Three         = diagnosisData.DiagnosisIcd10Three;
            infoParam.LeaveHospitalMainDiagnosis  = diagnosisData.DiagnosisDescribe;
            infoParam.IsHospitalizationFrequency  = "1";
            // 医保
            var resultData = _workerMedicalInsuranceRepository.WorkerHospitalizationSettlement(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);
        }
        public ResidentUserInfoDto GetUserInfo(ResidentUserInfoParam param)
        {
            var resultData = _residentMedicalInsuranceRepository.GetUserInfo(param);

            return(resultData);
        }