Пример #1
0
 public static void AddPatientInsurancePackage(BillingDbContext dbContext, int packageId, int patientId, int currentUserId)
 {
     try
     {
         PatientInsurancePackageTransactionModel patInsPkgTxn = new PatientInsurancePackageTransactionModel();
         patInsPkgTxn.PatientId = patientId;
         patInsPkgTxn.PackageId = packageId;
         patInsPkgTxn.StartDate = DateTime.Now;
         patInsPkgTxn.CreatedOn = DateTime.Now;
         patInsPkgTxn.CreatedBy = currentUserId;
         patInsPkgTxn.IsActive  = true;
         dbContext.PatientInsurancePackageTransactions.Add(patInsPkgTxn);
         dbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw new Exception("Unable to update Insurance Balance. Detail:" + ex.ToString());
     }
 }
        public string Put(string reqType, int settlementId)
        {
            DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>();

            responseData.Status = "OK";//by default status would be OK, hence assigning at the top
            try
            {
                int patientId             = ToInt(this.ReadQueryStringData("patientId"));
                int insuranceProviderId   = ToInt(this.ReadQueryStringData("insuranceProviderId"));
                int updatedInsBalance     = ToInt(this.ReadQueryStringData("updatedInsBalance"));
                int patientInsurancePkgId = ToInt(this.ReadQueryStringData("patientInsurancePkgId"));
                int couterId = ToInt(this.ReadQueryStringData("counterId"));
                BillingDbContext billingDbContext = new BillingDbContext(connString);
                RbacUser         currentUser      = HttpContext.Session.Get <RbacUser>("currentuser");

                if (reqType == "update-insurance-balance")
                {
                    BillingBL.UpdateInsuranceCurrentBalance(connString,
                                                            patientId,
                                                            insuranceProviderId,
                                                            currentUser.EmployeeId,
                                                            updatedInsBalance);
                    responseData.Status = "OK";
                }

                else if (reqType == "close-insurance-package")
                {
                    PatientInsurancePackageTransactionModel insPkg = billingDbContext.PatientInsurancePackageTransactions
                                                                     .Where(ins => ins.PatientInsurancePackageId == patientInsurancePkgId).FirstOrDefault();
                    if (insPkg != null)
                    {
                        insPkg.EndDate     = DateTime.Now;
                        insPkg.IsCompleted = true;
                        insPkg.ModifiedOn  = DateTime.Now;
                        insPkg.ModifiedBy  = currentUser.EmployeeId;
                        billingDbContext.Entry(insPkg).State = EntityState.Modified;
                        billingDbContext.SaveChanges();
                        responseData.Status = "OK";
                    }
                }

                else if (reqType == "update-insurance-claim")
                {
                    string       str = this.ReadPostData();
                    List <Int32> billingTransactionIdList         = JsonConvert.DeserializeObject <List <Int32> >(str);
                    List <BillingTransactionModel> claimInsurance = new List <BillingTransactionModel>();
                    DateTime settlementDate = DateTime.Now;
                    foreach (var invoice in billingTransactionIdList)
                    {
                        BillingTransactionModel billingTransaction = billingDbContext.BillingTransactions
                                                                     .Where(a => a.BillingTransactionId == invoice)
                                                                     .FirstOrDefault <BillingTransactionModel>();

                        if (billingTransaction != null)
                        {
                            billingDbContext.BillingTransactions.Attach(billingTransaction);
                            billingTransaction.BillStatus           = "paid";
                            billingTransaction.PaidAmount           = billingTransaction.TotalAmount;
                            billingTransaction.PaidDate             = settlementDate;
                            billingTransaction.PaymentReceivedBy    = currentUser.EmployeeId;
                            billingTransaction.PaidCounterId        = couterId;
                            billingTransaction.IsInsuranceClaimed   = true;
                            billingTransaction.InsuranceClaimedDate = DateTime.Now;
                            billingDbContext.Entry(billingTransaction).Property(b => b.IsInsuranceClaimed).IsModified   = true;
                            billingDbContext.Entry(billingTransaction).Property(b => b.InsuranceClaimedDate).IsModified = true;
                            billingDbContext.Entry(billingTransaction).Property(b => b.BillStatus).IsModified           = true;
                            billingDbContext.Entry(billingTransaction).Property(b => b.PaidAmount).IsModified           = true;
                            billingDbContext.Entry(billingTransaction).Property(b => b.PaidDate).IsModified             = true;
                            billingDbContext.Entry(billingTransaction).Property(b => b.PaymentReceivedBy).IsModified    = true;
                            billingDbContext.Entry(billingTransaction).Property(b => b.PaidCounterId).IsModified        = true;



                            List <BillingTransactionItemModel> txnItems = billingDbContext.BillingTransactionItems
                                                                          .Where(b => b.BillingTransactionId == billingTransaction.BillingTransactionId).ToList();

                            if (txnItems != null && txnItems.Count > 0)
                            {
                                foreach (var txnItm in txnItems)
                                {
                                    billingDbContext.BillingTransactionItems.Attach(txnItm);

                                    txnItm.BillStatus        = "paid";
                                    txnItm.PaidDate          = settlementDate;
                                    txnItm.PaidCounterId     = couterId;
                                    txnItm.PaymentReceivedBy = currentUser.EmployeeId;
                                    billingDbContext.Entry(txnItm).Property(b => b.BillStatus).IsModified        = true;
                                    billingDbContext.Entry(txnItm).Property(b => b.PaidDate).IsModified          = true;
                                    billingDbContext.Entry(txnItm).Property(b => b.PaymentReceivedBy).IsModified = true;
                                    billingDbContext.Entry(txnItm).Property(b => b.PaidCounterId).IsModified     = true;
                                }
                                billingDbContext.SaveChanges();
                            }
                            //claimInsurance.Add(billingTransaction);
                        }
                    }
                    billingDbContext.SaveChanges();
                    responseData.Status  = "OK";
                    responseData.Results = claimInsurance;
                }

                else
                {
                    responseData.Status       = "failed";
                    responseData.ErrorMessage = "Invalid request type.";
                }


                //responseData.Results = null;
            }
            catch (Exception ex)
            {
                responseData.Status       = "Failed";
                responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString();
            }
            return(DanpheJSONConvert.SerializeObject(responseData, true));
        }