Ejemplo n.º 1
0
        /// <summary>
        /// 医保出院费用结算
        /// </summary>
        /// <param name="param"></param>
        /// <param name="infoParam"></param>
        /// <returns></returns>
        public HospitalizationPresettlementDto LeaveHospitalSettlement(LeaveHospitalSettlementParam param,
                                                                       LeaveHospitalSettlementInfoParam infoParam)
        {
            HospitalizationPresettlementDto data = null;
            var xmlStr = XmlHelp.SaveXml(param);

            if (!xmlStr)
            {
                return(data);
            }
            int result = MedicalInsuranceDll.CallService_cxjb("CXJB010");

            if (result != 1)
            {
                throw new Exception("居民住院结算执行失败!!!");
            }
            var dataIni = XmlHelp.DeSerializerModel(new HospitalizationPresettlementJsonDto(), true);

            data = AutoMapper.Mapper.Map <HospitalizationPresettlementDto>(dataIni);
            //报销金额 =统筹支付+补充险支付+生育补助+民政救助+民政重大疾病救助+精准扶贫+民政优抚+其它支付
            decimal reimbursementExpenses =
                data.BasicOverallPay + data.SupplementPayAmount + data.BirthAAllowance +
                data.CivilAssistancePayAmount + data.CivilAssistanceSeriousIllnessPayAmount +
                data.AccurateAssistancePayAmount + data.CivilServicessistancePayAmount +
                data.OtherPaymentAmount;

            data.ReimbursementExpenses = reimbursementExpenses;

            return(data);
        }
        /// <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);
        }