/// <summary>
        /// Get PaymentType PerVisit Details
        /// </summary>
        /// <param name="paymentTypePerVisit"></param>
        /// <returns></returns>
        public PaymentTypePerVisit GetPaymentTypePerVisitDetails(PaymentTypePerVisit paymentTypePerVisit)
        {
            // Initialize the Stored Procedure
            _cmd = _db.GetStoredProcCommand("GetServiceLinesandPaymentTypes");
            // Pass parameters to Stored Procedure(i.e., @ParamName), add values for
            _db.AddInParameter(_cmd, "@PaymentTypeID ", DbType.Int64, paymentTypePerVisit.PaymentTypeId);
            _db.AddInParameter(_cmd, "@ContractID", DbType.Int64, paymentTypePerVisit.ContractId);
            _db.AddInParameter(_cmd, "@ContractServiceTypeID", DbType.Int64, paymentTypePerVisit.ServiceTypeId);
            _db.AddInParameter(_cmd, "@ServiceLineTypeId", DbType.Int64, 0);
            _db.AddInParameter(_cmd, "@UserName", DbType.String, paymentTypePerVisit.UserName);

            // Retrieve the results of the Stored Procedure in Data set
            DataSet paymentTypePerVisitDataSet = _db.ExecuteDataSet(_cmd);

            if (paymentTypePerVisitDataSet != null && paymentTypePerVisitDataSet.Tables.Count > 0)
            {
                //populating PerVisit data
                if (paymentTypePerVisitDataSet.Tables[0].Rows != null && paymentTypePerVisitDataSet.Tables[0] != null && paymentTypePerVisitDataSet.Tables[0].Rows.Count > 0)
                {
                    PaymentTypePerVisit paymentPerVisit = new PaymentTypePerVisit
                    {
                        Rate = DBNull.Value == paymentTypePerVisitDataSet.Tables[0].Rows[0]["Rate"] ? (double?)null : Convert.ToDouble(paymentTypePerVisitDataSet.Tables[0].Rows[0]["Rate"]),
                        PaymentTypeDetailId = Convert.ToInt64(paymentTypePerVisitDataSet.Tables[0].Rows[0]["PaymentTypeDetailID"])
                    };
                    return(paymentPerVisit);
                }
            }

            //returns response to Business layer
            return(null);
        }
        /// <summary>
        /// Gets the payment type per visit.
        /// </summary>
        /// <param name="contractServiceTypeId">The contract service type identifier.</param>
        /// <param name="dtPerVisitTable">The dt per visit table.</param>
        /// <returns></returns>
        public static PaymentTypePerVisit GetPaymentType(long contractServiceTypeId, DataTable dtPerVisitTable)
        {
            PaymentTypePerVisit paymentTypePerVisit = null;

            if (dtPerVisitTable != null && dtPerVisitTable.Rows.Count > 0)
            {
                paymentTypePerVisit = (from DataRow row in dtPerVisitTable.Rows
                                       where
                                       (row["contractServiceTypeId"] != DBNull.Value &&
                                        Convert.ToInt64(row["contractServiceTypeId"]) == contractServiceTypeId)
                                       select new PaymentTypePerVisit
                {
                    ContractId = DBNull.Value == row["ContractId"]
                                               ? (long?)null
                                               : Convert.ToInt64(
                        row["ContractId"]),
                    ServiceTypeId =
                        DBNull.Value == row["ContractServiceTypeID"]
                                                   ? (long?)null
                                                   : Convert.ToInt64(
                            row["ContractServiceTypeID"]),
                    Rate = DBNull.Value == row["Rate"]
                                              ? (double?)null
                                              : Convert.ToDouble(
                        row["Rate"]),
                    PaymentTypeDetailId = Convert.ToInt64(row["PaymentTypeDetailID"]),
                    PaymentTypeId = (byte)Enums.PaymentTypeCodes.PerVisit
                }).FirstOrDefault();
                # region "For future Use"
                //if (paymentTypePerVisit != null)
                //{
                //    List<ICondition> conditions = new List<ICondition>();
                //    if (!string.IsNullOrEmpty(paymentTypePerVisit.RevCode))
                //    {
                //        ICondition conditionRevCode = new Condition
                //        {
                //            ConditionOperator = (int)Enums.ConditionOperation.EqualTo,
                //            OperandIdentifier = (int)Enums.OperandIdentifier.RevCode,
                //            RightOperand = paymentTypePerVisit.RevCode
                //        };
                //        conditionRevCode = UpdatePropertyAndOperand(conditionRevCode);
                //        conditions.Add(conditionRevCode);
                //    }
                //    if (!string.IsNullOrEmpty(paymentTypePerVisit.HCPCSCode))
                //    {
                //        ICondition conditionHCPCSCode = new Condition
                //        {
                //            ConditionOperator = (int)Enums.ConditionOperation.EqualTo,
                //            OperandIdentifier = (int)Enums.OperandIdentifier.HCPCSCode,
                //            RightOperand = paymentTypePerVisit.HCPCSCode
                //        };
                //        conditionHCPCSCode = UpdatePropertyAndOperand(conditionHCPCSCode);
                //        conditions.Add(conditionHCPCSCode);
                //    }
                //    paymentTypePerVisit.Conditions = conditions;
                //}
                #endregion
            }
            return(paymentTypePerVisit);
        }
        //
        // GET: /PaymentTypePerVisitDetails/

        public ActionResult PaymentTypePerVisit(long?contractId, long?serviceTypeId, int paymentTypeId, bool isEdit)
        {
            PaymentTypePerVisitViewModel modePaymentTypePerVisitViewModel = new PaymentTypePerVisitViewModel();

            if (isEdit)
            {
                PaymentTypePerVisit paymentTypePerVisitForPost = new PaymentTypePerVisit
                {
                    ServiceTypeId = serviceTypeId,
                    ContractId    = contractId,
                    PaymentTypeId = paymentTypeId,
                    UserName      = GetCurrentUserName()
                };
                //Get the Name of User logged in
                PaymentTypePerVisit paymentTypePerVisitViewModelInfo =
                    PostApiResponse <PaymentTypePerVisit>("PaymentTypePerVisit",
                                                          "GetPaymentTypePerVisitDetails",
                                                          paymentTypePerVisitForPost);

                modePaymentTypePerVisitViewModel = AutoMapper.Mapper.Map <PaymentTypePerVisit, PaymentTypePerVisitViewModel>(paymentTypePerVisitViewModelInfo);
            }

            modePaymentTypePerVisitViewModel.ContractId    = contractId;
            modePaymentTypePerVisitViewModel.ServiceTypeId = serviceTypeId;
            modePaymentTypePerVisitViewModel.PaymentTypeId = paymentTypeId;
            modePaymentTypePerVisitViewModel.IsEdit        = isEdit;
            return(View(modePaymentTypePerVisitViewModel));
        }
        public JsonResult AddEditPaymentPerVisit(PaymentTypePerVisitViewModel info)
        {
            PaymentTypePerVisit perVisistPaymentInfo = AutoMapper.Mapper.Map <PaymentTypePerVisitViewModel, PaymentTypePerVisit>(info);

            //Get the Name of User logged in
            perVisistPaymentInfo.UserName = GetCurrentUserName();
            long pervisitId = PostApiResponse <long>("PaymentTypePerVisit", "AddEditPaymentTypePerVisitDetails", perVisistPaymentInfo);

            return(pervisitId > 0 ? Json(new { sucess = true, Id = pervisitId }) : Json(new { sucess = false }));
        }
        public void GetPaymentTypePerVisitDetailsMockTestIsNull()
        {
            var mockProductRepository = new Mock <IPaymentTypePerVisitRepository>();

            mockProductRepository.Setup(f => f.GetPaymentTypePerVisitDetails(It.IsAny <PaymentTypePerVisit>())).Returns((PaymentTypePerVisit)null);
            PaymentTypePerVisitLogic target = new PaymentTypePerVisitLogic(mockProductRepository.Object);
            PaymentTypePerVisit      actual = (PaymentTypePerVisit)target.GetPaymentType(null);

            Assert.IsNull(actual);
            // Assert.IsNotNull(actual);
        }
        public void GetPaymentTypePerVisitDetailsMockTestIsNotNull()
        {
            PaymentTypePerVisit objPaymentTypeVisit = new PaymentTypePerVisit {
                PaymentTypeId = 1
            };
            var mockProductRepository = new Mock <IPaymentTypePerVisitRepository>();

            mockProductRepository.Setup(f => f.GetPaymentTypePerVisitDetails(It.IsAny <PaymentTypePerVisit>())).Returns(objPaymentTypeVisit);
            PaymentTypePerVisitLogic target = new PaymentTypePerVisitLogic(mockProductRepository.Object);
            PaymentTypePerVisit      actual = (PaymentTypePerVisit)target.GetPaymentType(objPaymentTypeVisit);

            Assert.AreEqual(1, actual.PaymentTypeId);
        }
        public void EditNewPaymentTypePerVisitDetailsIfNotNull()
        {
            var mockProductRepository = new Mock <IPaymentTypePerVisitRepository>();

            mockProductRepository.Setup(f => f.AddEditPaymentTypePerVisitDetails(It.IsAny <PaymentTypePerVisit>())).Returns(2);
            PaymentTypePerVisitLogic target = new PaymentTypePerVisitLogic(mockProductRepository.Object);
            PaymentTypePerVisit      objPaymentTypePerVisit = new PaymentTypePerVisit {
                PaymentTypeDetailId = 1
            };
            long actual = target.AddEditPaymentType(objPaymentTypePerVisit);

            // Assert.IsNull(actual);
            Assert.AreEqual(2, actual);
        }
        /// <summary>
        /// Add Edit PaymentType PerVisit Details
        /// </summary>
        /// <param name="paymentTypePerVisit"></param>
        /// <returns></returns>
        public long AddEditPaymentTypePerVisitDetails(PaymentTypePerVisit paymentTypePerVisit)
        {
            //Checks if input request is not null
            if (paymentTypePerVisit != null)
            {
                // Initialize the Stored Procedure
                _cmd = _db.GetStoredProcCommand("AddEditPerVisitPaymentType");
                // Pass parameters to Stored Procedure(i.e., @ParamName), add values for
                _db.AddInParameter(_cmd, "@PaymentTypeDetailID", DbType.Int64, paymentTypePerVisit.PaymentTypeDetailId);
                _db.AddInParameter(_cmd, "@Rate", DbType.Decimal, paymentTypePerVisit.Rate);
                _db.AddInParameter(_cmd, "@PaymentTypeID", DbType.Int64, paymentTypePerVisit.PaymentTypeId);
                _db.AddInParameter(_cmd, "@ContractID", DbType.Int64, paymentTypePerVisit.ContractId);
                _db.AddInParameter(_cmd, "@ContractServiceTypeID", DbType.Int64, paymentTypePerVisit.ServiceTypeId);
                _db.AddInParameter(_cmd, "@UserName", DbType.String, paymentTypePerVisit.UserName);

                // Retrieve the results of the Stored Procedure in Datatable
                return(long.Parse(_db.ExecuteScalar(_cmd).ToString()));
            }

            return(0);
        }
        public void EvaluateAtClaimLevelTest()
        {
            List <PaymentResult> paymentResults = new List <PaymentResult>
            {
                new PaymentResult {
                    ClaimId = 123, Line = 1, AdjudicatedValue = null
                },
                new PaymentResult {
                    ClaimId = 123, Line = 2, AdjudicatedValue = null
                },
            };
            PaymentTypePerVisit paymentTypePerVisit = new PaymentTypePerVisit
            {
                Rate            = 10,
                PayAtClaimLevel = true,
                ValidLineIds    = new List <int> {
                    1, 2, 3, 4, 5, 6
                },
                Conditions = new List <ICondition>
                {
                    new Condition
                    {
                        ConditionOperator = (byte)Enums.ConditionOperation.EqualTo,
                        LeftOperands      = new List <string> {
                            "300"
                        },
                        OperandType  = (byte)Enums.OperandIdentifier.HcpcsCode,
                        RightOperand = "300"
                    }
                },
                ContractId = 1,
                HcpcsCode  = "300",
            };
            // Arrange
            var mockContractServiceTypeLogic = new Mock <IContractServiceTypeLogic>();
            var mockPaymentResultLogic       = new Mock <IPaymentResultLogic>();

            mockPaymentResultLogic.Setup(
                x =>
                x.Evaluate(It.IsAny <EvaluateableClaim>(), It.IsAny <List <PaymentResult> >(), It.IsAny <bool>(),
                           It.IsAny <bool>())).Returns(paymentResults);
            Mock <IPaymentTypePerVisitRepository> paymentTypePerVisitRepository = new Mock <IPaymentTypePerVisitRepository>();

            paymentTypePerVisitRepository.Setup(x => x.GetPaymentTypePerVisitDetails(It.IsAny <PaymentTypePerVisit>()))
            .Returns(paymentTypePerVisit);

            var target = new PaymentTypePerVisitLogic(paymentTypePerVisitRepository.Object)
            {
                PaymentTypeBase = paymentTypePerVisit
            };


            // _target.Contract = contract;
            IEvaluateableClaim evaluateableClaim = new EvaluateableClaim();

            evaluateableClaim.ClaimId      = 123;
            evaluateableClaim.ClaimTotal   = 100;
            evaluateableClaim.ClaimCharges = new List <ClaimCharge>
            {
                new ClaimCharge
                {
                    Line      = 1,
                    Amount    = 20,
                    HcpcsCode = "300"
                },
                new ClaimCharge
                {
                    Line      = 2,
                    Amount    = 20,
                    HcpcsCode = "301"
                },
                new ClaimCharge
                {
                    Line      = 3,
                    Amount    = 20,
                    HcpcsCode = "302"
                },
                new ClaimCharge
                {
                    Line      = 4,
                    Amount    = 20,
                    HcpcsCode = "303"
                },
                new ClaimCharge
                {
                    Line      = 5,
                    Amount    = 20,
                    HcpcsCode = "304"
                },
                new ClaimCharge
                {
                    Line      = 6,
                    Amount    = 20,
                    HcpcsCode = "305"
                }
            };


            List <PaymentResult> updatedPaymentResults = new List <PaymentResult>
            {
                new PaymentResult {
                    ClaimId = 123, ContractId = 1, AdjudicatedValue = 110
                },
                new PaymentResult {
                    ClaimId = 123, Line = 1, ContractId = 1, AdjudicatedValue = 110
                }
            };

            Mock <ContractBaseLogic> mockContractBaseLogic = new Mock <ContractBaseLogic>();

            mockContractServiceTypeLogic.Setup(x => x.IsValidServiceType()).Returns(true);
            mockContractServiceTypeLogic.Setup(x => x.Evaluate(evaluateableClaim, paymentResults, true, false))
            .Returns(updatedPaymentResults);
            mockContractBaseLogic.SetupAllProperties();

            //Act
            List <PaymentResult> actual = target.EvaluatePaymentType(evaluateableClaim, paymentResults, true, false);

            // Assert
            Assert.AreEqual(3, actual.Count);
            var firstOrDefault = paymentResults.FirstOrDefault(x => x.AdjudicatedValue != null);

            if (firstOrDefault != null)
            {
                Assert.AreEqual(10, firstOrDefault.AdjudicatedValue);
            }
        }
 public PaymentTypePerVisit GetPaymentTypePerVisitDetails(PaymentTypePerVisit paymentTypePerVisit)
 {
     return((PaymentTypePerVisit)_paymentTypePerVisitDetailsLogic.GetPaymentType(paymentTypePerVisit));
 }
 public long AddEditPaymentTypePerVisitDetails(PaymentTypePerVisit paymentTypePerVisit)
 {
     return(_paymentTypePerVisitDetailsLogic.AddEditPaymentType(paymentTypePerVisit));
 }