public async Task <IActionResult> Create([Bind("ApptId,ApptDate,AppointmentReason,PatientEmail,PatientId,VisitRecord,DoctorId")] Appointment appointment)
        {
            if (ModelState.IsValid)
            {
                var findbyemail = _context.Appointment.Where(c => c.PatientEmail == User.Identity.Name).Count();

                //If the email is found, reject creating the appointment and redirect to the page that says unsuccessful

                if (findbyemail != 0)
                {
                    return(View("AppointmentExists"));
                }
                //Add the user to misused user database

                if (User.IsInRole("Patient"))
                {
                    if (!UserExists(User.Identity.Name))
                    {
                        var newuser = new MisusedUser {
                            UserEmail = User.Identity.Name, Misusedcount = 0
                        };
                        _context.MisusedUser.Add(newuser);
                        await _context.SaveChangesAsync();
                    }
                }
                _context.Add(appointment);
                await _context.SaveChangesAsync();

                //Remove from available time
                var appointment_context = _context.DoctorAvailability.Where(a => a.AvailableTime == appointment.ApptDate && a.DoctorId == appointment.DoctorId).FirstOrDefault();

                _context.DoctorAvailability.Remove(appointment_context);
                await _context.SaveChangesAsync();

                //Add to unavailable time

                var addtime = new DoctorUnavailability {
                    DoctorId = appointment.DoctorId, Unavailable = appointment.ApptDate
                };
                _context.DoctorUnavailability.Add(addtime);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DoctorId"]  = new SelectList(_context.Doctor, "DoctorId", "DoctorName", appointment.DoctorId);
            ViewData["PatientId"] = new SelectList(_context.Patient, "PatientId", "PatientEmail", appointment.PatientId);
            return(View(appointment));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("DoctorName,Salary,DoctorEmail,DoctorId")] Doctor doctor)
        {
            if (ModelState.IsValid)
            {
                _context.Add(doctor);
                await _context.SaveChangesAsync();

                //Create account with role as doctor
                var doctoraccount = new IdentityUser
                {
                    UserName       = doctor.DoctorEmail,
                    Email          = doctor.DoctorEmail,
                    EmailConfirmed = true,
                };

                var user = await _userManager.FindByEmailAsync(doctor.DoctorEmail);

                if (user == null)
                {
                    var createpoweruser = await _userManager.CreateAsync(doctoraccount, "Superuser1!");

                    if (createpoweruser.Succeeded)
                    {
                        await _userManager.AddToRoleAsync(doctoraccount, "Doctor");
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(doctor));
        }
        public async Task <IActionResult> Create([Bind("ApptId,ApptDate,AppointmentReason,PatientEmail,PatientId,VisitRecord,DoctorId")] Appointment appointment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(appointment);
                await _context.SaveChangesAsync();

                Console.WriteLine("The appointment tiem is " + appointment.ApptDate);

                //Remove from available time
                var appointment_context = _context.DoctorAvailability.Where(a => a.AvailableTime == appointment.ApptDate && a.DoctorId == appointment.DoctorId).FirstOrDefault();

                _context.DoctorAvailability.Remove(appointment_context);
                await _context.SaveChangesAsync();

                //Add to unavailable time

                var addtime = new DoctorUnavailability {
                    DoctorId = appointment.DoctorId, Unavailable = appointment.ApptDate
                };
                _context.DoctorUnavailability.Add(addtime);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DoctorId"]  = new SelectList(_context.Doctor, "DoctorId", "DoctorEmail", appointment.DoctorId);
            ViewData["PatientId"] = new SelectList(_context.Patient, "PatientId", "PatientEmail", appointment.PatientId);
            return(View(appointment));
        }
示例#4
0
        public async Task <IActionResult> Create([Bind("NurseName,Salary,NurseEmail,NurseId,DoctorId")] Nurse nurse)
        {
            if (ModelState.IsValid)
            {
                _context.Add(nurse);
                await _context.SaveChangesAsync();

                // Create nurse account using the email and default password

                var nurseaccount = new IdentityUser
                {
                    UserName       = nurse.NurseEmail,
                    Email          = nurse.NurseEmail,
                    EmailConfirmed = true,
                };

                var user = await _userManager.FindByEmailAsync(nurse.NurseEmail);

                if (user == null)
                {
                    var createpoweruser = await _userManager.CreateAsync(nurseaccount, "Superuser1!");

                    if (createpoweruser.Succeeded)
                    {
                        await _userManager.AddToRoleAsync(nurseaccount, "Nurse");
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DoctorId"] = new SelectList(_context.Doctor, "DoctorId", "DoctorEmail", nurse.DoctorId);
            return(View(nurse));
        }
示例#5
0
        public async Task <IActionResult> Create([Bind("PatientName,PatientEmail,PatientAddress,Phone,Ssn,Weight,Height,Insurance,Bloodpressure,Pulse,AppointmentMisused,PatientId,Allergy")] Patient patient)
        {
            if (ModelState.IsValid)
            {
                _context.Add(patient);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(patient));
        }
        public async Task <IActionResult> Create([Bind("MedicalreportId,ReportType")] MedicalreportType medicalreportType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(medicalreportType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(medicalreportType));
        }
        public async Task <IActionResult> Create([Bind("DoctorId,AvailableTime,AvailabilityId")] DoctorAvailability doctorAvailability)
        {
            if (ModelState.IsValid)
            {
                _context.Add(doctorAvailability);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DoctorId"] = new SelectList(_context.Doctor, "DoctorId", "DoctorEmail", doctorAvailability.DoctorId);
            return(View(doctorAvailability));
        }
示例#8
0
        public async Task <IActionResult> Create([Bind("MedicalreportName,ReportFile,MedicalreportId,PatientId")] MedicalReport medicalReports)
        {
            if (ModelState.IsValid)
            {
                _context.Add(medicalReports);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MedicalreportId"] = new SelectList(_context.MedicalreportType, "MedicalreportId", "ReportType", medicalReports.MedicalreportId);
            ViewData["PatientId"]       = new SelectList(_context.Patient, "PatientId", "Allergy", medicalReports.PatientId);
            return(View(medicalReports));
        }
        public async Task <IActionResult> Edit(string id, [Bind("VisitReason,Prescription,Visitid,VisitDate,Visited,PatientId,DoctorId")] VisitRecord visitRecord)
        {
            if (id != visitRecord.Visitid)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(visitRecord);
                    await _context.SaveChangesAsync();

                    if (visitRecord.Visited == true)
                    {
                        //Clear appointment once patient visits the doctor
                        int patient_id          = visitRecord.PatientId;
                        var appointment_context = _context.Appointment.Where(a => a.PatientId == patient_id).FirstOrDefault();
                        _context.Appointment.Remove(appointment_context);
                        await _context.SaveChangesAsync();

                        var record = new Billing {
                            BillingAmount = 50, BillingDate = DateTime.UtcNow, PatientId = visitRecord.PatientId, Paid = false
                        };
                        _context.Add(record);
                        await _context.SaveChangesAsync();

                        //return RedirectToAction("Create", "Billings");
                        return(RedirectToAction("Index", "VisitRecords"));
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VisitRecordExists(visitRecord.Visitid))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DoctorId"]  = new SelectList(_context.Doctor, "DoctorId", "DoctorEmail", visitRecord.DoctorId);
            ViewData["PatientId"] = new SelectList(_context.Patient, "PatientId", "PatientEmail", visitRecord.PatientId);
            return(View(visitRecord));
        }
        public async Task <IActionResult> Create([Bind("PaymentDate,PaymentId,PaymentAmount,BillingId,ReceiveReceipt")] CashPayment cashPayment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cashPayment);
                await _context.SaveChangesAsync();

                //Change status to paid
                var billing = await _context.Billing
                              .FirstOrDefaultAsync(m => m.BillingId == cashPayment.BillingId);

                billing.Paid = true;
                await _context.SaveChangesAsync();

                //Send receipt
                if (cashPayment.ReceiveReceipt == true)
                {
                    var get_patient_id    = _context.Billing.Where(c => c.BillingId == cashPayment.BillingId).FirstOrDefault().PatientId;
                    var get_patient_email = _context.Patient.Where(c => c.PatientId == get_patient_id).FirstOrDefault().PatientEmail;
                    var get_patient_name  = _context.Patient.Where(c => c.PatientId == get_patient_id).FirstOrDefault().PatientName;



                    /**//* SendReceipt receipt = new SendReceipt();
                     *   receipt.Sendemail(get_patient_email, checkPayment.PaymentAmount, checkPayment.BillingId);*//**/


                    //Send an email
                    //Sending email, make a different class file for this.
                    var          fromAddress = new MailAddress("*****@*****.**", "Healthcare Service");
                    var          toAddress   = new MailAddress(get_patient_email, get_patient_name);
                    string       messagebody = "You paid your invoice of amount " + cashPayment.PaymentAmount + " and billing Id " + cashPayment.BillingId;
                    const string subject     = "Receipt of Paymment";
                    string       body        = messagebody;

                    var smtp = new SmtpClient
                    {
                        Host                  = "smtp.gmail.com",
                        Port                  = 587,
                        EnableSsl             = true,
                        DeliveryMethod        = SmtpDeliveryMethod.Network,
                        UseDefaultCredentials = false,
                        Credentials           = new System.Net.NetworkCredential(fromAddress.Address, "xrtwdhjqxqvsurfn")
                    };
                    using (var message = new MailMessage(fromAddress, toAddress)
                    {
                        Subject = subject,
                        Body = body
                    })
                    {
                        smtp.Send(message);
                    }
                }
                return(View("CashPaymentSuccessful"));
            }
            ViewData["BillingId"] = new SelectList(_context.Billing, "BillingId", "BillingId", cashPayment.BillingId);
            return(View("CashPaymentUnSuccessful"));
        }

/*
 *      // GET: CashPayments/Edit/5
 *      public async Task<IActionResult> Edit(int? id)
 *      {
 *          if (id == null)
 *          {
 *              return NotFound();
 *          }
 *
 *          var cashPayment = await _context.CashPayment.FindAsync(id);
 *          if (cashPayment == null)
 *          {
 *              return NotFound();
 *          }
 *          ViewData["BillingId"] = new SelectList(_context.Billing, "BillingId", "BillingId", cashPayment.BillingId);
 *          return View(cashPayment);
 *      }
 *
 *      // POST: CashPayments/Edit/5
 *      // To protect from overposting attacks, enable the specific properties you want to bind to, for
 *      // more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
 *      [HttpPost]
 *      [ValidateAntiForgeryToken]
 *      public async Task<IActionResult> Edit(int id, [Bind("PaymentDate,PaymentId,PaymentAmount,BillingId,ReceiveReceipt")] CashPayment cashPayment)
 *      {
 *          if (id != cashPayment.PaymentId)
 *          {
 *              return NotFound();
 *          }
 *
 *          if (ModelState.IsValid)
 *          {
 *              try
 *              {
 *                  _context.Update(cashPayment);
 *                  await _context.SaveChangesAsync();
 *              }
 *              catch (DbUpdateConcurrencyException)
 *              {
 *                  if (!CashPaymentExists(cashPayment.PaymentId))
 *                  {
 *                      return NotFound();
 *                  }
 *                  else
 *                  {
 *                      throw;
 *                  }
 *              }
 *              return RedirectToAction(nameof(Index));
 *          }
 *          ViewData["BillingId"] = new SelectList(_context.Billing, "BillingId", "BillingId", cashPayment.BillingId);
 *          return View(cashPayment);
 *      }
 *
 *      // GET: CashPayments/Delete/5
 *      public async Task<IActionResult> Delete(int? id)
 *      {
 *          if (id == null)
 *          {
 *              return NotFound();
 *          }
 *
 *          var cashPayment = await _context.CashPayment
 *              .Include(c => c.Billing)
 *              .FirstOrDefaultAsync(m => m.PaymentId == id);
 *          if (cashPayment == null)
 *          {
 *              return NotFound();
 *          }
 *
 *          return View(cashPayment);
 *      }
 *
 *      // POST: CashPayments/Delete/5
 *      [HttpPost, ActionName("Delete")]
 *      [ValidateAntiForgeryToken]
 *      public async Task<IActionResult> DeleteConfirmed(int id)
 *      {
 *          var cashPayment = await _context.CashPayment.FindAsync(id);
 *          _context.CashPayment.Remove(cashPayment);
 *          await _context.SaveChangesAsync();
 *          return RedirectToAction(nameof(Index));
 *      }
 *
 *      private bool CashPaymentExists(int id)
 *      {
 *          return _context.CashPayment.Any(e => e.PaymentId == id);
 *      }*/
    }
}
示例#11
0
        public void GenerateMonthlyReport()
        {
            /*var rand = new Random();
             * int Month = DateTime.Today.Month;
             *
             *
             * var groupByDoc = _context.VisitRecord.AsEnumerable().Where(rec => Int32.Parse((rec.VisitDate.ToShortDateString().Split("/"))[0]) == Month).Select(rec => rec.DoctorId).Distinct().ToList();
             *
             * for (int i = 0; i < groupByDoc.Count(); i++)
             * {
             *
             *  string DocName = _context.Doctor.Where(rec => rec.DoctorId == groupByDoc.ElementAt(i)).Select(rec => rec.DoctorName).FirstOrDefault();
             *
             *  int NumPatients = (_context.DailyReport.Where(rec => rec.DoctorName == DocName)).Sum(rec => rec.NoPatients);
             *
             *  DateTime date = DateTime.Today;
             *
             *  double Income = _context.DailyReport.AsEnumerable().Where(d => d.DoctorName == DocName && Int32.Parse((d.ReportDate.ToShortDateString().Split("/"))[0]) == Month).Sum(rec => rec.DailyIncome);
             *
             *  var monthlyReport = new MonthlyReport
             *  {
             *
             *      ReportId = Guid.NewGuid().ToString(),
             *      DoctorName = DocName,
             *      MonthlyIncome = Income,
             *      ReportMonth = date,
             *       NoPatients= NumPatients
             *
             *
             *
             *  };
             *
             *
             *  _context.MonthlyReport.Add(monthlyReport);
             *
             *  try
             *  {
             *  _context.SaveChangesAsync();
             *
             *   }
             *  catch (Exception d)
             *  {
             *   Console.WriteLine("From DailyReport");
             *  Console.WriteLine(d.InnerException);
             *
             *  }
             *
             * }
             *
             *
             *
             */
            //Find unique doctor names!

            /*  var get_distinct_doctors_list = _context.DailyReport.Include(c => c.DoctorName).Distinct().ToList();
             *
             * foreach( var x in get_distinct_doctors_list)
             * {
             *    string doctorname = x.DoctorName;*/
            //Get total patients and total income for each doctor
            var result = _context.DailyReport.Where(c => c.ReportDate.Month == DateTime.Today.Month).GroupBy(o => o.DoctorName)
                         .Select(g => new { doctorname = g.Key, total = g.Sum(i => i.DailyIncome), total_patient = g.Sum(i => i.NoPatients) });

            foreach (var x in result)
            {
                var newrecord = new MonthlyReport {
                    DoctorName = x.doctorname, NoPatients = x.total_patient, MonthlyIncome = x.total, ReportId = Guid.NewGuid().ToString(), ReportMonth = DateTime.Now
                };
                _context.Add(newrecord);
            }
            _context.SaveChanges();


            //
        }
        //Card payment using stripe
        public async Task <IActionResult> Charge(int?id, string stripeEmail, string stripeToken)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var billing = await _context.Billing
                          .Include(b => b.Patient)
                          .FirstOrDefaultAsync(m => m.BillingId == id);

            if (billing == null)
            {
                return(NotFound());
            }

            //Create stripe charge
            var customers = new CustomerService();
            var charges   = new ChargeService();

            var customer = customers.Create(new CustomerCreateOptions
            {
                Email  = stripeEmail,
                Source = stripeToken,
            });


            var charge = charges.Create(new ChargeCreateOptions
            {
                Amount       = (long)billing.BillingAmount * 100,
                Description  = "Invoice",
                Currency     = "usd",
                Customer     = customer.Id,
                ReceiptEmail = stripeEmail
            });

            //


            if (charge.Status == "succeeded")
            {
                //Add payment record to card payment
                if (ModelState.IsValid)
                {
                    /// Use charge id as reference no
                    var newpayment = new CardPayment {
                        PaymentDate = DateTime.Now, PaymentAmount = billing.BillingAmount, BillingId = (int)id, ReferenceNo = charge.Id
                    };
                    _context.Add(newpayment);
                    await _context.SaveChangesAsync();

                    //Update the paid starus in the invoice
                    billing.Paid = true;
                    await _context.SaveChangesAsync();

                    //Send an email
                    //Sending email, make a different class file for this.
                    var          fromAddress = new MailAddress("*****@*****.**", "Utsav");
                    var          toAddress   = new MailAddress(charge.ReceiptEmail);
                    string       messagebody = "You paid your invoice of amount " + billing.BillingAmount + " and billing Id " + billing.BillingId + ". Your charge id is " + charge.Id;
                    const string subject     = "Receipt of Paymment";
                    string       body        = messagebody;

                    var smtp = new SmtpClient
                    {
                        Host                  = "smtp.gmail.com",
                        Port                  = 587,
                        EnableSsl             = true,
                        DeliveryMethod        = SmtpDeliveryMethod.Network,
                        UseDefaultCredentials = false,
                        Credentials           = new System.Net.NetworkCredential(fromAddress.Address, "xrtwdhjqxqvsurfn")
                    };
                    using (var message = new MailMessage(fromAddress, toAddress)
                    {
                        Subject = subject,
                        Body = body
                    })
                    {
                        smtp.Send(message);
                    }
                }



                return(View("chargesuccessful"));
            }
            else
            {
                return(View("Chargeunsuccessful"));
            }
        }
        public async Task <IActionResult> Create([Bind("CheckNo,PaymentAmount,PaymentDate,BillingId,ReceiveReceipt")] CheckPayment checkPayment)
        {
            if (ModelState.IsValid)

            {
                Console.WriteLine("Check Payment" + checkPayment.BillingId + checkPayment.PaymentAmount
                                  );
                _context.Add(checkPayment);
                await _context.SaveChangesAsync();


                //Update Paid Status in invoice

                var billing = await _context.Billing
                              .FirstOrDefaultAsync(m => m.BillingId == checkPayment.BillingId);

                billing.Paid = true;
                await _context.SaveChangesAsync();


                //Send receipt
                if (checkPayment.ReceiveReceipt == true)
                {
                    var get_patient_id    = _context.Billing.Where(c => c.BillingId == checkPayment.BillingId).FirstOrDefault().PatientId;
                    var get_patient_email = _context.Patient.Where(c => c.PatientId == get_patient_id).FirstOrDefault().PatientEmail;
                    var get_patient_name  = _context.Patient.Where(c => c.PatientId == get_patient_id).FirstOrDefault().PatientName;



                    /* SendReceipt receipt = new SendReceipt();
                     *   receipt.Sendemail(get_patient_email, checkPayment.PaymentAmount, checkPayment.BillingId);*/


                    //Send an email
                    //Sending email, make a different class file for this.
                    var          fromAddress = new MailAddress("*****@*****.**", "Healthcare Service");
                    var          toAddress   = new MailAddress(get_patient_email, get_patient_name);
                    string       messagebody = "You paid your invoice of amount " + checkPayment.PaymentAmount + " and billing Id " + checkPayment.BillingId;
                    const string subject     = "Receipt of Paymment";
                    string       body        = messagebody;

                    var smtp = new SmtpClient
                    {
                        Host                  = "smtp.gmail.com",
                        Port                  = 587,
                        EnableSsl             = true,
                        DeliveryMethod        = SmtpDeliveryMethod.Network,
                        UseDefaultCredentials = false,
                        Credentials           = new System.Net.NetworkCredential(fromAddress.Address, "xrtwdhjqxqvsurfn")
                    };
                    using (var message = new MailMessage(fromAddress, toAddress)
                    {
                        Subject = subject,
                        Body = body
                    })
                    {
                        smtp.Send(message);
                    }

                    Console.WriteLine(get_patient_email);
                    Console.WriteLine(get_patient_name);
                }
                return(View("CheckPaymentSuccessful"));
            }
            ViewData["BillingId"] = new SelectList(_context.Billing, "BillingId", "BillingId", checkPayment.BillingId);
            return(View("CheckPaymentSuccessful"));
        }