Пример #1
0
        // GET: BillingInvoiceManagement/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //get full include of invoices and
            var            billingInvoices = db.BillingInvoices.Include(i => i.Treatments).Include(i => i.Prescriptions).Include(i => i.Patient).Include(i => i.Payment);
            BillingInvoice billingInvoice  = new BillingInvoice();

            //searches for the one the matches id
            foreach (BillingInvoice invoice in billingInvoices)
            {
                if (invoice.InvoiceNo == id)
                {
                    billingInvoice = invoice;
                }
            }

            if (billingInvoice == null)
            {
                return(HttpNotFound());
            }
            return(View(billingInvoice));
        }
Пример #2
0
        // GET: BillingInvoiceManagement/makepayment
        public ActionResult MakePayment(string id, string patientid)
        {
            ViewBag.patientid = patientid;
            Patient        patient        = db.Patients.Find(patientid);
            BillingInvoice billingInvoice = db.BillingInvoices.Find(id);

            return(View(new CreatePaymentViewModel {
                PatientId = patientid, InvoiceNo = id, Forename = patient.Forename, Surname = patient.Surname, BillingAddress = patient.Street + " " + patient.Town, InvoiceTotal = billingInvoice.TotalDue
            }));
        }
        public async Task <IActionResult> UpdateBillingInvoice(BillingInvoice billingInvoice)
        {
            try
            {
                await _billingRepository.UpdateBillInvoice(billingInvoice);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
Пример #4
0
        public JsonResult AuditBillingInvoice(string entity)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            BillingInvoice       model      = serializer.Deserialize <BillingInvoice>(entity);

            bool bl = FinanceBusiness.BaseBusiness.AuditBillingInvoice(model.InvoiceID, model.BillingID, model.InvoiceMoney, model.InvoiceCode, model.ExpressID, model.ExpressCode, CurrentUser.UserID, CurrentUser.AgentID, CurrentUser.ClientID);

            JsonDictionary.Add("status", bl);

            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Пример #5
0
        public JsonResult SaveBillingInvoice(string entity)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            BillingInvoice       model      = serializer.Deserialize <BillingInvoice>(entity);

            var id = FinanceBusiness.BaseBusiness.CreateBillingInvoice(model.BillingID, model.Type, model.CustomerType, model.InvoiceMoney, model.InvoiceTitle, model.CityCode, model.Address, model.PostalCode, model.ContactName, model.ContactPhone, model.Remark, CurrentUser.UserID, CurrentUser.AgentID, CurrentUser.ClientID);

            model.InvoiceID  = id;
            model.CreateUser = CurrentUser;
            JsonDictionary.Add("item", model);

            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
        public async Task <IActionResult> AddDrugBillingInvoice(BillingInvoice billingInvoice)
        {
            try
            {
                var result = await _billingRepository.AddDrugBillInvoice(billingInvoice);

                PatientTariffByPayorResponse response = new PatientTariffByPayorResponse()
                {
                    TariffAmount    = null,
                    ResponseMessage = result.Item2,
                    Status          = result.Item1
                };
                return(Ok(response));
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
        public ActionResult DeleteConfirmed(string id)
        {
            Treatment treatment = db.Treatments.Find(id);
            string    patientid = treatment.PatientID;

            //temp collection of invoices used to find existing invocie
            var            billinginvoices = db.BillingInvoices.Include(i => i.Patient).Include(i => i.Prescriptions).Include(i => i.Treatments).Include(i => i.Payment).ToList();
            BillingInvoice Invoice         = new BillingInvoice();

            //searches invoices to find current invoice and updates invoice

            try
            {
                foreach (BillingInvoice invoice in billinginvoices)
                {
                    if (invoice.PatientID == treatment.PatientID && invoice.PaymentRecived == false && invoice.PaymentNo == null)
                    {
                        Invoice = invoice;

                        Invoice.TotalDue = Invoice.TotalDue - treatment.TreatmentCost;
                        Invoice.Treatments.Remove(treatment);

                        db.Entry(invoice).State = EntityState.Modified;
                        db.SaveChanges();

                        db.Treatments.Remove(treatment);
                        db.SaveChanges();
                        return(RedirectToAction("Index", "TreatmentManagement", new { patientid }));
                    }
                }
            }
            catch
            {
                return(View("Error"));
            }

            return(RedirectToAction("Index", "TreatmentManagement", new { patientid }));
        }
        public ActionResult DeleteConfirmed(string id)
        {
            //temp variables used to find previous invoice
            Prescription prescription = db.Prescriptions.Find(id);
            string       patientid    = prescription.PatientID;

            var            billinginvoices = db.BillingInvoices.Include(i => i.Patient).Include(i => i.Prescriptions).Include(i => i.Treatments).Include(i => i.Payment).ToList();
            BillingInvoice Invoice         = new BillingInvoice();

            try
            {
                //once found invoice makes changes to invoice then updates
                foreach (BillingInvoice invoice in billinginvoices)
                {
                    if (invoice.PatientID == prescription.PatientID && invoice.PaymentRecived == false && invoice.PaymentNo == null)
                    {
                        Invoice = invoice;

                        Invoice.TotalDue = Invoice.TotalDue - prescription.PrescriptionCost;
                        Invoice.Prescriptions.Remove(prescription);

                        db.Entry(invoice).State = EntityState.Modified;
                        db.SaveChanges();

                        db.Prescriptions.Remove(prescription);
                        db.SaveChanges();
                        return(RedirectToAction("Index", "PrescriptionManagement", new { patientid }));
                    }
                }
            }
            catch
            {
                return(View("Error"));
            }

            return(RedirectToAction("Index", "PrescriptionManagement", new { patientid }));
        }
        public ActionResult Edit([Bind(Include = "TreatmentNo,DateofTreatment,TreatmentDetails,TreatmentCost,DoctorID,PatientID")] Treatment treatment)
        {
            //checks if model is valid
            if (ModelState.IsValid)
            {
                //checks treatment cost is more then 0
                if (!(treatment.TreatmentCost > 0))
                {
                    ViewBag.ErrorMessage = "Please enter a valid treatment cost";
                    return(View(treatment));
                }

                //temp invoice for creation of new invoice and copy of copy treatment before edit
                BillingInvoice Invoice = new BillingInvoice {
                    PatientID = treatment.PatientID, PaymentRecived = false, TotalDue = treatment.TreatmentCost
                };
                Treatment oldtreatment = treatment;

                //collection of invoices
                var billinginvoices = db.BillingInvoices.Include(i => i.Patient).Include(i => i.Prescriptions).Include(i => i.Treatments).Include(i => i.Payment).ToList();

                try
                {
                    //searchs through all invoice to find one by the same patientid that is unpaid, if yes that invoice is used else a new one is made
                    foreach (BillingInvoice invoice in billinginvoices)
                    {
                        if (invoice.PatientID == treatment.PatientID && invoice.PaymentRecived == false && invoice.PaymentNo == null)
                        {
                            Invoice = invoice;

                            foreach (Treatment t in Invoice.Treatments)
                            {
                                if (t.TreatmentNo == treatment.TreatmentNo)
                                {
                                    oldtreatment = t;
                                }
                            }

                            //handles invoice total
                            treatment.InvoiceNo = Invoice.InvoiceNo;
                            Invoice.TotalDue    = Invoice.TotalDue - oldtreatment.TreatmentCost + treatment.TreatmentCost;

                            //forign key error fix when editing, stating primary key conflict instead of using state.modified (the origin of error, apparently)
                            db.Set <BillingInvoice>().AddOrUpdate(invoice);

                            db.Set <Treatment>().AddOrUpdate(treatment);

                            db.SaveChanges();

                            return(RedirectToAction("Index", "TreatmentManagement", new { treatment.PatientID }));
                        }
                    }

                    //creation of new invoice
                    treatment.InvoiceNo = Invoice.InvoiceNo;
                    db.BillingInvoices.Add(Invoice);

                    db.Entry(treatment).State = EntityState.Modified;
                    db.SaveChanges();

                    return(RedirectToAction("Index", "TreatmentManagement", new { treatment.PatientID }));
                }
                catch
                {
                    //failed update of invoice
                    ViewBag.ErrorMessage = "Invoice Failed to update";
                    return(View(treatment));
                }
            }
            //invalid model error message
            ViewBag.ErrorMessage = "Invalid Submition, please fill all fields";
            return(View(treatment));
        }
Пример #10
0
        private void _buildInvoice()
        {
            while (_invoices.Read())
            {
                object[] values = new object[_invoices.FieldCount];
                _invoices.GetValues(values);
                BillingInvoice item = new BillingInvoice();

                /**
                 * ============================================
                 *  Use this for Menara Geno
                 * ============================================
                 */

                // string[] unitInfo = _extractUnit(values[3]);

                /**
                 * ============================================
                 *  Use this for all other clients
                 * ============================================
                 */

                string[] unitInfo = _extractUnitGen(values[3]);

                item.reference_id = values[1].ToString();
                item.description  = values[10].ToString();
                item.project_code = values[13].ToString();
                item.status       = _billStatus(values[9], values[17], values[18]);
                item.due_at       = Convert.ToDateTime(values[9].ToString()).ToString("yyyy-MM-dd");

                /*
                 * ======================================
                 *  Use this unit format for Menara Geno
                 *  =====================================
                 */


                /*item.block = (_withInBounds(2, unitInfo) ? unitInfo[2] : "Unit");
                 * item.floor = (_withInBounds(0, unitInfo) ? unitInfo[0] : "");
                 * item.unit = (_withInBounds(1, unitInfo) ? unitInfo[1] : "");*/


                /*
                 * ======================================
                 *    Use this for all other clients.
                 * ======================================
                 */


                item.block = (_withInBounds(0, unitInfo) ? unitInfo[0] : "Unit");
                item.floor = (_withInBounds(1, unitInfo) ? unitInfo[1] : "");
                item.unit  = (_withInBounds(2, unitInfo) ? unitInfo[2] : "");



                item.currency                 = "RM";
                item.amount_cents             = _amountToCents(values[17]);
                item.outstanding_amount_cents = _outStandingAmount(values[17], values[18]);
                item.reminder_days            = int.Parse(values[8].ToString().Substring(0, values[8].ToString().IndexOf(@"Days")));
                item.type           = _billType(values[13]);
                item.billing_date   = Convert.ToDateTime(values[5].ToString()).ToString("yyyy-MM-dd");
                item.residence_uuid = ConfigurationManager.AppSettings["uuid"];
                InvoiceLst.Add(item);
            }
        }
Пример #11
0
        public ActionResult MakePayment([Bind(Include = "PaymentNo,PaymentMethod,BillingAddress,Forename,Surname,CardNumber,SecurityCode,ExpiryDate,PatientId,InvoiceNo,SelectedMethod,InvoiceTotal")] CreatePaymentViewModel payment, string stripeEmail, string stripeToken)
        {
            //checks if model state is valid
            if (ModelState.IsValid)
            {
                //if stripe is choosen then redirect to stripe payment
                if (payment.SelectedMethod == "Stripe")
                {
                    try
                    {
                        return(RedirectToAction("StripePayment", "BillingInvoiceManagement", payment));
                    }
                    catch
                    {
                        ViewBag.ErrorMessage = "Unable to Redirect to stripe payment";
                        return(View(payment));
                    }
                }
                else
                {
                    //handles non stripe payments that can be directly recorded into the database

                    //transfers details from paymentviewmodel to payment
                    Payment temppayment = new Payment {
                        Forename = payment.Forename, Surname = payment.Surname, BillingAddress = payment.BillingAddress, PaymentMethod = payment.SelectedMethod
                    };
                    BillingInvoice billingInvoice = db.BillingInvoices.Find(payment.InvoiceNo);

                    Patient patient = db.Patients.Find(billingInvoice.PatientID);

                    //email process
                    if (patient.Email != null)
                    {
                        EmailService emailService = new EmailService();
                        emailService.SendAsync(new IdentityMessage {
                            Destination = patient.Email, Body = "Your Payment of £" + payment.InvoiceTotal + " for your treatments has been recived", Subject = "Confirmation of Payment"
                        });
                    }

                    //transfers invoice amount to payment amount
                    temppayment.PaymentAmount = billingInvoice.TotalDue;

                    //create payment
                    db.Payments.Add(temppayment);

                    db.SaveChanges();

                    //assosiated payment with invoice then updates
                    billingInvoice.PaymentRecived = true;
                    billingInvoice.PaymentNo      = temppayment.PaymentNo;

                    db.Entry(billingInvoice).State = EntityState.Modified;

                    db.SaveChanges();
                }

                return(RedirectToAction("Index", "BillingInvoiceManagement", new { payment.PatientId }));
            }
            //invalid model message
            ViewBag.ErrorMessage = "Invalid submittion, please enter all values";
            return(View(payment));
        }
        public async Task <IActionResult> AddPrivatePatientConsultationBillingInvoice(BillingInvoice billingInvoice)
        {
            try
            {
                //patientId = "1011302952"; servicecode = 145; accountId = 1;

                var _billingInvoice = await _billingRepository.WritePatientConsultationBill(billingInvoice);

                PatientTariffByPayorResponse response = new PatientTariffByPayorResponse()
                {
                    TariffAmount    = _billingInvoice.Item3,
                    ResponseMessage = _billingInvoice.Item2,
                    Status          = _billingInvoice.Item1
                };

                return(Ok(response));
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
        public ActionResult Edit([Bind(Include = "PrescriptionNo,Dosage,LengthofTreatment,DateofPrescription,DoctorID,PatientID,DrugNo")] Prescription prescription)
        {
            // check if model is valid
            if (ModelState.IsValid)
            {
                Drug drug = db.Drugs.Find(prescription.DrugNo);

                //chcks if values is integer > 0 else error message in cathc
                try
                {
                    if ((!(int.Parse(prescription.LengthofTreatment) > 0)) || (!(int.Parse(prescription.Dosage) > 0)))
                    {
                        ViewBag.DrugNo       = new SelectList(db.Drugs, "DrugNo", "DrugName");
                        ViewBag.ErrorMessage = "Please enter valid values > 0";
                        return(View(prescription));
                    }
                }
                catch
                {
                    ViewBag.DrugNo       = new SelectList(db.Drugs, "DrugNo", "DrugName");
                    ViewBag.ErrorMessage = "Please enter valid values";
                    return(View(prescription));
                }

                //calculates cost
                prescription.PrescriptionCost = (drug.DrugCost * double.Parse(prescription.Dosage) * double.Parse(prescription.LengthofTreatment));

                //temp invoice for createion and  temp old prescription to be initalised if previous prescription exists
                BillingInvoice Invoice = new BillingInvoice {
                    PatientID = prescription.PatientID, PaymentRecived = false, TotalDue = prescription.PrescriptionCost
                };
                Prescription oldprescription = prescription;

                var billinginvoices = db.BillingInvoices.Include(i => i.Patient).Include(i => i.Prescriptions).Include(i => i.Treatments).Include(i => i.Payment).ToList();

                try
                {
                    //searches for unpaid invoice and look for old prescription matching prescription no
                    foreach (BillingInvoice invoice in billinginvoices)
                    {
                        if (invoice.PatientID == prescription.PatientID && invoice.PaymentRecived == false && invoice.PaymentNo == null)
                        {
                            Invoice = invoice;

                            foreach (Prescription p in Invoice.Prescriptions)
                            {
                                if (p.PrescriptionNo == prescription.PrescriptionNo)
                                {
                                    oldprescription = p;
                                }
                            }

                            prescription.InvoiceNo = Invoice.InvoiceNo;
                            Invoice.TotalDue       = Invoice.TotalDue - oldprescription.PrescriptionCost + prescription.PrescriptionCost;

                            //forign key error fix when editing, stating primary key conflict instead of using state.modified (the origin of error, apparently)
                            db.Set <BillingInvoice>().AddOrUpdate(invoice);

                            db.Set <Prescription>().AddOrUpdate(prescription);

                            db.SaveChanges();

                            return(RedirectToAction("Index", "PrescriptionManagement", new { prescription.PatientID }));
                        }
                    }

                    //create new invoice
                    prescription.InvoiceNo = Invoice.InvoiceNo;
                    db.BillingInvoices.Add(Invoice);

                    db.Entry(prescription).State = EntityState.Modified;
                    db.SaveChanges();

                    return(RedirectToAction("Index", "PrescriptionManagement", new { prescription.PatientID }));
                }
                catch
                {
                    //invoice failed error
                    ViewBag.DrugNo       = new SelectList(db.Drugs, "DrugNo", "DrugName");
                    ViewBag.ErrorMessage = "Invoice failed to update";
                    return(View(prescription));
                }
            }

            //ivnalid submit error
            ViewBag.DrugNo       = new SelectList(db.Drugs, "DrugNo", "DrugName");
            ViewBag.ErrorMessage = "submittion invalid, please enter all values";
            return(View(prescription));
        }
Пример #14
0
        public ActionResult StripePayment([Bind(Include = "PaymentNo,PaymentMethod,BillingAddress,Forename,Surname,CardNumber,SecurityCode,ExpiryDate,PatientId,InvoiceNo,SelectedMethod,InvoiceTotal")] CreatePaymentViewModel payment, string stripeEmail, string stripeToken)
        {
            try
            {
                //attributes
                StripeConfiguration.SetApiKey("sk_test_fHaiXwbfFo3YUowus0cFNdOR00HHNl42Yw");
                var customers = new CustomerService();
                var charges   = new ChargeService();

                //create customer
                var customer = customers.Create(new CustomerCreateOptions
                {
                    Email       = stripeEmail,
                    Description = "test purposes Charge",
                    SourceToken = stripeToken,
                });

                //creates charge, unable to correctly record charge as amount requires a long input which my entire project relises on double

                //most tiresome double to list of char to string to int64 casting ever, but succeeds in turing a double to a long compatable with stripe API
                //create list of char from invoice total
                List <char> chartotal = payment.InvoiceTotal.ToString("C2").ToList();

                //scans through char list removing all decimal points
                while (chartotal.Contains('.') || chartotal.Contains(',') || chartotal.Contains('£'))
                {
                    try
                    {
                        chartotal.Remove('.');
                        chartotal.Remove(',');
                        chartotal.Remove('£');
                    }
                    catch
                    {
                        continue;
                    }
                }

                //utalizes stringbuilder to build a string out of the list of char values
                string temptotal = null;
                var    builder   = new StringBuilder();

                foreach (char c in chartotal)
                {
                    builder.Append(c);
                }

                //final string product of the tiresome cast that now must be converted to long below
                temptotal = builder.ToString();
                //

                //create charge
                var charge = charges.Create(new ChargeCreateOptions
                {
                    Amount       = Int64.Parse(temptotal),
                    Description  = "test purposes Charge",
                    Currency     = "gbp",
                    CustomerId   = customer.Id,
                    ReceiptEmail = customer.Email,
                });

                //if charge and customer creation successfull and can be found on stripe then payment is recorded in database
                if (customers.Get(customer.Id) != null && charges.Get(charge.Id) != null)
                {
                    //transfers details from payment view model and finds invoice
                    Payment temppayment = new Payment {
                        Forename = payment.Forename, Surname = payment.Surname, BillingAddress = payment.BillingAddress, PaymentMethod = payment.SelectedMethod
                    };
                    BillingInvoice billingInvoice = db.BillingInvoices.Find(payment.InvoiceNo);

                    Patient patient = db.Patients.Find(billingInvoice.PatientID);

                    //email process
                    if (patient.Email != null)
                    {
                        EmailService emailService = new EmailService();
                        emailService.SendAsync(new IdentityMessage {
                            Destination = patient.Email, Body = "Your Payment of £" + payment.InvoiceTotal + " for your treatments has been recived", Subject = "Confirmation of Payment"
                        });
                    }

                    //transfers total to payment
                    temppayment.PaymentAmount = billingInvoice.TotalDue;

                    //creates payment
                    db.Payments.Add(temppayment);

                    db.SaveChanges();

                    //assosiates payment with invoice then updates
                    billingInvoice.PaymentRecived = true;
                    billingInvoice.PaymentNo      = temppayment.PaymentNo;

                    db.Entry(billingInvoice).State = EntityState.Modified;

                    db.SaveChanges();

                    return(RedirectToAction("Index", "BillingInvoiceManagement", new { payment.PatientId }));
                }
                else
                {
                    //stripe error message
                    ViewBag.ErrorMessage = "Unable to Process Stripe Payment";
                    return(View(payment));
                }
            }
            catch
            {
                //stripe fault error message
                ViewBag.ErrorMessage = "Error encountered during stripe payment";
                return(View(payment));
            }
        }
        public ActionResult Create([Bind(Include = "TreatmentNo,DateofTreatment,TreatmentDetails,TreatmentCost,DoctorID,PatientID")] Treatment treatment)
        {
            //checks if a model is valid
            if (ModelState.IsValid)
            {
                //checks treatement cost > 0
                if (!(treatment.TreatmentCost > 0))
                {
                    ViewBag.ErrorMessage = "Please enter a valid treatment cost";
                    return(View(treatment));
                }

                //strange improvised fix for forign key error, if staff are not loaded from staffmanagement treatment creation becomes impossible
                db.ApplicationUsers.Load();

                db.Treatments.Add(treatment);
                db.SaveChanges();

                //temp invoice to be used as a new invoice if no unpaid invoice matching patient is found
                BillingInvoice Invoice = new BillingInvoice {
                    PatientID = treatment.PatientID, PaymentRecived = false, TotalDue = treatment.TreatmentCost
                };

                try
                {
                    //list of invoices
                    var billinginvoices = db.BillingInvoices.Include(i => i.Patient).Include(i => i.Prescriptions).Include(i => i.Treatments).Include(i => i.Payment).ToList();

                    //searches list of invoices for an invoice that matches the patient that is unpaid, else outside of foreach creates new invoice with unpaid status
                    foreach (BillingInvoice invoice in billinginvoices)
                    {
                        //if an invoice is found matching patient and also be unpaid the invoice is appended with the new treatment
                        if (invoice.PatientID == treatment.PatientID && invoice.PaymentRecived == false && invoice.PaymentNo == null)
                        {
                            Invoice = invoice;

                            Invoice.TotalDue    = Invoice.TotalDue + treatment.TreatmentCost;
                            treatment.InvoiceNo = Invoice.InvoiceNo;

                            db.Entry(invoice).State   = EntityState.Modified;
                            db.Entry(treatment).State = EntityState.Modified;
                            db.SaveChanges();

                            return(RedirectToAction("Index", "TreatmentManagement", new { treatment.PatientID }));
                        }
                    }

                    //if no invoice found, create new invoice with temp invoice and newly created treatment added within
                    treatment.InvoiceNo = Invoice.InvoiceNo;
                    db.BillingInvoices.Add(Invoice);

                    db.Entry(treatment).State = EntityState.Modified;
                    db.SaveChanges();

                    return(RedirectToAction("Index", "TreatmentManagement", new { treatment.PatientID }));
                }
                catch
                {
                    ViewBag.ErrorMessage = "failed to create invocie";
                    return(View(treatment));
                }
            }

            ViewBag.ErrorMessage = "Invalid Submition, please fill all fields";
            return(View(treatment));
        }
Пример #16
0
        public async Task <IActionResult> UpdateAppointment(int apptId, AppointmentCreate model)
        {
            try
            {
                if (apptId != model.Id)
                {
                    return(BadRequest(new ErrorResponse {
                        ErrorMessage = "Id does not match"
                    }));
                }

                model.Date.AddHours(1);

                //(string, bool, bool) updated = await _repository.UpdateAppointment(model);
                var updated = await _repository.UpdateAppointment(model);

                //updateAppointmentResponse updateAppointmentResponse = new updateAppointmentResponse
                //{
                //    CheckinMessage = updated.Item1,
                //    IsCheckedIn = updated.Item2,
                //    IsUpdated = updated.Item3
                //};

                //if (!updated.Item3)
                //    return BadRequest(new ErrorResponse { ErrorMessage = "Record Not Found" });

                if (!updated.Item1)
                {
                    return(BadRequest(new ErrorResponse {
                        ErrorMessage = "Record Not Found"
                    }));
                }


                if (model.StatusId == 3 && updated.Item2 != null)
                {
                    var patient = await _patientRepo.GetPatientById(model.PatientNo, (int)model.AccountId);

                    var plantype = await _patientRepo.GetPatientPlantype(patient.Plantype);

                    if (plantype != null)
                    {
                        // checks if its a private patient
                        if (plantype.payerid == 1162 && plantype.plantypeid == 32)
                        {
                            // check if this private patient has ever been billed for registration
                            var regBill = await _billingRepository.CheckPrivatePatientBillForRegistration(model.PatientNo, (int)model.AccountId);

                            if (regBill == null)
                            {
                                // if there is no registration bill record for this private
                                // patient a reg bill is added for him or her
                                // add bill
                                BillingInvoice regBillingInvoice = new BillingInvoice()
                                {
                                    patientid   = model.PatientNo,
                                    ProviderID  = model.AccountId,
                                    locationid  = model.LocationId,
                                    encodedby   = int.Parse(model.Adjuster),
                                    encounterId = updated.Item2
                                };

                                var regBillResult = await _billingRepository.WritePatientRegistrationBill(regBillingInvoice);
                            }

                            // add bill
                            BillingInvoice billingInvoice = new BillingInvoice()
                            {
                                patientid   = model.PatientNo,
                                ProviderID  = model.AccountId,
                                locationid  = model.LocationId,
                                encodedby   = int.Parse(model.Adjuster),
                                encounterId = updated.Item2
                            };

                            var billResult = await _billingRepository.WritePatientConsultationBill(billingInvoice);
                        }
                    }
                }

                return(Ok(updated));
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
Пример #17
0
        public async Task <IActionResult> CheckPatientIn(int locationId, int providerId, string patientId, int userid)
        {
            try
            {
                var result = await _checkInRepository.CreaateCheckIn(patientId, providerId, locationId, userid);

                // check that check-In was successfull
                if (result.Item2)
                {
                    var patient = await _patientRepo.GetPatientById(patientId, providerId);

                    var plantype = await _patientRepo.GetPatientPlantype(patient.Plantype);

                    if (plantype != null)
                    {
                        // checks if its a private patient
                        if (plantype.payerid == 1162 && plantype.plantypeid == 32)
                        {
                            // check if this private patient has ever been billed for registration
                            var regBill = await _billingRepository.CheckPrivatePatientBillForRegistration(patientId, providerId);

                            if (regBill == null)
                            {
                                // if there is no registration bill record for this private
                                // patient a reg bill is added for him or her
                                // add bill
                                BillingInvoice regBillingInvoice = new BillingInvoice()
                                {
                                    patientid   = patientId,
                                    ProviderID  = providerId,
                                    locationid  = locationId,
                                    encodedby   = userid,
                                    encounterId = result.Item3
                                };

                                var regBillResult = await _billingRepository.WritePatientRegistrationBill(regBillingInvoice);
                            }

                            // add bill
                            BillingInvoice billingInvoice = new BillingInvoice()
                            {
                                patientid   = patientId,
                                ProviderID  = providerId,
                                locationid  = locationId,
                                encodedby   = userid,
                                encounterId = result.Item3
                            };

                            // adds consultation bill for this private patieny
                            var billResult = await _billingRepository.WritePatientConsultationBill(billingInvoice);
                        }
                    }
                }


                MiniResponseBase response = new MiniResponseBase
                {
                    ErrorMessage = result.Item1,
                    status       = result.Item2
                };

                return(Ok(response));
            }
            catch (Exception ex)
            {
                MiniResponseBase response = new MiniResponseBase
                {
                    ErrorMessage = "An Error Occured patient check-In failed",
                    status       = false
                };

                return(BadRequest(response));
            }
        }
Пример #18
0
        public Billing GetOrderBillByID(string billingid, string agentid, string clientid)
        {
            Billing model = new Billing();
            DataSet ds    = FinanceDAL.BaseProvider.GetOrderBillByID(billingid, agentid, clientid);

            if (ds.Tables["Billing"].Rows.Count > 0)
            {
                model.FillData(ds.Tables["Billing"].Rows[0]);

                model.CreateUser = OrganizationBusiness.GetUserByUserID(model.CreateUserID, model.AgentID);

                model.PayStatusStr = model.PayStatus == 0 ? "未收款"
                                : model.PayStatus == 1 ? "部分收款"
                                : model.PayStatus == 2 ? "已收款"
                                : model.PayStatus == 9 ? "已删除"
                                : "";

                model.InvoiceStatusStr = model.InvoiceStatus == 0 ? "未开票"
                                : model.InvoiceStatus == 1 ? "已申请"
                                : model.InvoiceStatus == 2 ? "已开票"
                                : model.InvoiceStatus == 9 ? "已删除"
                                : "";

                model.BillingPays = new List <BillingPay>();
                foreach (DataRow dr in ds.Tables["Pays"].Rows)
                {
                    BillingPay pay = new BillingPay();
                    pay.FillData(dr);

                    switch (pay.PayType)
                    {
                    case 1:
                        pay.PayTypeStr = "现金支付";
                        break;

                    case 2:
                        pay.PayTypeStr = "在线支付";
                        break;

                    case 3:
                        pay.PayTypeStr = "支付宝";
                        break;

                    case 4:
                        pay.PayTypeStr = "微信";
                        break;

                    case 5:
                        pay.PayTypeStr = "线下汇款";
                        break;
                    }
                    pay.CreateUser = OrganizationBusiness.GetUserByUserID(pay.CreateUserID, pay.AgentID);
                    model.BillingPays.Add(pay);
                }

                model.BillingInvoices = new List <BillingInvoice>();
                foreach (DataRow dr in ds.Tables["Invoices"].Rows)
                {
                    BillingInvoice invoice = new BillingInvoice();
                    invoice.FillData(dr);

                    invoice.StatusStr = invoice.Status == 0 ? "已申请"
                                : invoice.Status == 1 ? "已申请"
                                : invoice.Status == 9 ? "已删除"
                                : "";

                    invoice.CreateUser = OrganizationBusiness.GetUserByUserID(invoice.CreateUserID, invoice.AgentID);
                    model.BillingInvoices.Add(invoice);
                }
            }
            return(model);
        }
        public ActionResult Create([Bind(Include = "PrescriptionNo,Dosage,LengthofTreatment,DateofPrescription,DoctorID,PatientID,DrugNo")] Prescription prescription)
        {
            //checks if model is valid
            if (ModelState.IsValid)
            {
                try
                {
                    //checks lenght of treatment is integer > 0 and dosage is a integer > 0 , else error message in catch
                    if ((!(int.Parse(prescription.LengthofTreatment) > 0)) || (!(int.Parse(prescription.Dosage) > 0)))
                    {
                        ViewBag.DrugNo       = new SelectList(db.Drugs, "DrugNo", "DrugName");
                        ViewBag.ErrorMessage = "Please enter valid values > 0";
                        return(View(prescription));
                    }
                }
                catch
                {
                    ViewBag.DrugNo       = new SelectList(db.Drugs, "DrugNo", "DrugName");
                    ViewBag.ErrorMessage = "Please enter valid values, please enter integer values";
                    return(View(prescription));
                }


                //strange improvised fix for forign key error, if staff are not loaded from staffmanagement prescription creation becomes impossible ALSO
                db.ApplicationUsers.Load();

                Drug drug = db.Drugs.Find(prescription.DrugNo);

                prescription.PrescriptionCost = (drug.DrugCost * double.Parse(prescription.Dosage) * double.Parse(prescription.LengthofTreatment));

                db.Prescriptions.Add(prescription);
                db.SaveChanges();

                //temp invoice to be used as a new invoice if no unpaid invoice matching patient is found
                BillingInvoice Invoice = new BillingInvoice {
                    PatientID = prescription.PatientID, PaymentRecived = false, TotalDue = prescription.PrescriptionCost
                };

                try
                {
                    //list of invoices
                    var billinginvoices = db.BillingInvoices.Include(i => i.Patient).Include(i => i.Prescriptions).Include(i => i.Treatments).Include(i => i.Payment).ToList();

                    //searches list of invoices for an invoice that matches the patient that is unpaid, else outside of foreach creates new invoice with unpaid status
                    foreach (BillingInvoice invoice in billinginvoices)
                    {
                        //if an invoice is found matching patient and also be unpaid the invoice is appended with the new prescription
                        if (invoice.PatientID == prescription.PatientID && invoice.PaymentRecived == false && invoice.PaymentNo == null)
                        {
                            Invoice = invoice;

                            Invoice.TotalDue       = Invoice.TotalDue + prescription.PrescriptionCost;
                            prescription.InvoiceNo = Invoice.InvoiceNo;

                            db.Entry(invoice).State      = EntityState.Modified;
                            db.Entry(prescription).State = EntityState.Modified;
                            db.SaveChanges();

                            return(RedirectToAction("Index", "PrescriptionManagement", new { prescription.PatientID }));
                        }
                    }

                    //if no invoice found, create new invoice with temp invoice and newly created prescription added within
                    prescription.InvoiceNo = Invoice.InvoiceNo;
                    db.BillingInvoices.Add(Invoice);

                    db.Entry(prescription).State = EntityState.Modified;
                    db.SaveChanges();

                    return(RedirectToAction("Index", "PrescriptionManagement", new { prescription.PatientID }));
                }
                catch
                {
                    //failed to create invocie message
                    ViewBag.DrugNo       = new SelectList(db.Drugs, "DrugNo", "DrugName");
                    ViewBag.ErrorMessage = "Failded to create invoice";
                    return(View(prescription));
                }
            }

            //invalid submit message
            ViewBag.DrugNo       = new SelectList(db.Drugs, "DrugNo", "DrugName");
            ViewBag.ErrorMessage = "submittion invalid, please enter all values";
            return(View(prescription));
        }