Esempio n. 1
0
 public IActionResult postDoctor(Doctor doctor)
 {
     try
     {
         context.Add <Doctor>(doctor);
         context.SaveChanges();
         return(CreatedAtAction("getDoctor", new { id = doctor.IdDoctor }, doctor));
     }
     catch (DbUpdateException)
     {
         return(this.BadRequest("nie dodano"));
     }
 }
Esempio n. 2
0
        public IActionResult AddDoctor(DoctorDTO doctorDTO)
        {
            Doctor doctor = new Doctor();

            doctor.FirstName = doctorDTO.FirstName;
            doctor.LastName  = doctorDTO.LastName;
            doctor.Email     = doctorDTO.Email;

            hospitalContext.Doctors.Add(doctor);
            hospitalContext.SaveChanges();

            return(Ok(doctor));
        }
Esempio n. 3
0
        public ActionResult Create([Bind(Include = "IdCitas,Paciente_Id,Medico_Id,Fecha,Hora")] Citas citas)
        {
            if (ModelState.IsValid)
            {
                db.Citas.Add(citas);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Medico_Id   = new SelectList(db.Medicos, "IdMedicos", "Nombre", citas.Medico_Id);
            ViewBag.Paciente_Id = new SelectList(db.Pacientes, "IdPacientes", "Cedula", citas.Paciente_Id);
            return(View(citas));
        }
        public ActionResult Create([Bind(Include = "Id,Job_id,Name,Email,Phone,CV,Text,Date")] Job_applications job_application)
        {
            if (ModelState.IsValid)
            {
                job_application.Date = DateTime.Now;
                db.Job_applications.Add(job_application);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Job_id = new SelectList(db.Jobs, "Id", "Title", job_application.Job_id);
            return(View("Admin/Create", job_application));
        }
        // Salva ou atualiza um objeto
        public void SalvarObjeto(Consulta objeto)
        {
            try
            {
                // marca os attributos que são objetos como já existentes evitando a duplicação
                ctx.Entry(objeto.Paciente).State          = System.Data.Entity.EntityState.Unchanged;
                ctx.Entry(objeto.Paciente.Convenio).State = System.Data.Entity.EntityState.Unchanged;

                //----------
                // Objetos (class) que possuem mais de um objeto (class) aninhado
                // e melhor buscar pelo ctx do que marcar como nao alterado
                //----------

                // seleciona um medico ja existente para atribuir ao objeto
                // evitando a duplicação do registro
                var medicoQuery = from medico
                                  in ctx.Medicos.Include("Banco").Include("AreaAtuacao")
                                  where medico.Id == objeto.Medico.Id
                                  select medico;
                objeto.Medico = medicoQuery.ToList().ElementAt(0);

                // seleciona um agendamento ja existente para atribuir ao objeto
                // evitando a duplicação do registro
                var agendamentoQuery = from agendamento
                                       in ctx.Agendamentos.Include("Paciente").Include("Medico").Include("Secretaria")
                                       where agendamento.Id == objeto.Agendamento.Id
                                       select agendamento;
                objeto.Agendamento = agendamentoQuery.ToList().ElementAt(0);

                if (objeto.Id == 0)
                {
                    ctx.Consultas.Add(objeto);
                }
                else
                {
                    var tempObjeto = ctx.Consultas.SingleOrDefault(temp => temp.Id == objeto.Id);
                    tempObjeto.Id          = objeto.Id;
                    tempObjeto.Paciente    = objeto.Paciente;
                    tempObjeto.Medico      = objeto.Medico;
                    tempObjeto.Agendamento = objeto.Agendamento;
                    tempObjeto.Data        = objeto.Data;
                    tempObjeto.PrecoTotal  = objeto.PrecoTotal;
                }

                ctx.SaveChanges();
            }
            catch (Exception ex)
            {
                Util.HandleSQLDBException(ex);
            }
        }
Esempio n. 6
0
        public void createMedico(Medico medico)
        {
            if (medico.conta != null)
            {
                ctx.Entry(medico.conta).State = System.Data.Entity.EntityState.Unchanged;
            }
            if (medico.Especialidade != null)
            {
                ctx.Entry(medico.Especialidade).State = System.Data.Entity.EntityState.Unchanged;
            }

            ctx.Medicos.Add(medico);
            ctx.SaveChanges();
        }
Esempio n. 7
0
        public IActionResult updateDoctor(Doctor doctor)
        {
            Doctor d = context.doctor.Find(doctor.IdDoctor);

            if (d == null)
            {
                return(NotFound("Doctor o takim id nieistnieje"));
            }
            context.Database.BeginTransaction();
            context.Entry(d).CurrentValues.SetValues(doctor);
            context.SaveChanges();
            context.Database.CommitTransaction();
            return(Ok(doctor));
        }
        public ActionResult Create([Bind(Include = "BookingID,DoctorID,NurseID,PatientID")] Booking booking)
        {
            if (ModelState.IsValid)
            {
                db.Bookings.Add(booking);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DoctorID  = new SelectList(db.Doctors, "DoctorID", "DoctorName", booking.DoctorID);
            ViewBag.NurseID   = new SelectList(db.Nurses, "NurseID", "NurseName", booking.NurseID);
            ViewBag.PatientID = new SelectList(db.Patients, "PatientID", "PatientName", booking.PatientID);
            return(View(booking));
        }
Esempio n. 9
0
        public ActionResult Create([Bind(Include = "Name,Role,Subject,Content,Rate,DepartmentId")] Testimonial testimonial)
        {
            try
            {
                if (this.IsCaptchaValid("Captcha is not valid."))
                {
                    if (ModelState.IsValid)
                    {
                        var DirtyWords = db.DirtyWords.ToList();
                        foreach (var row in DirtyWords)
                        {
                            if ((testimonial.Content.Contains(row.Word)) || (testimonial.Subject.Contains(row.Word)))
                            {
                                testimonial.Timestamp = DateTime.Now;
                                testimonial.Reviewed  = "PENDING";
                                db.Testimonials.Add(testimonial);
                                db.SaveChanges();

                                TempData["SuccessMessage"] = "Your testimonial has been successfully submitted.";
                                return(RedirectToAction("Index"));
                            }
                        }
                        testimonial.Timestamp = DateTime.Now;
                        testimonial.Reviewed  = "NO";
                        db.Testimonials.Add(testimonial);
                        db.SaveChanges();
                        TempData["SuccessMessage"] = "Your testimonial has been successfully submitted.";
                        return(RedirectToAction("Index"));
                    }
                    ViewBag.ErrorCaptcha = "Captcha is not valid.";
                    return(View(testimonial));
                }

                ViewBag.departments = db.departments.ToList();
                return(View(testimonial));
            }
            catch (DbUpdateException dbException)
            {
                ViewBag.DbExceptionMessage = dbException.Message;
            }
            catch (SqlException sqlException)
            {
                ViewBag.SqlException = sqlException.Message;
            }
            catch (Exception genericException)
            {
                ViewBag.ExceptionMessage = genericException.Message;
            }
            return(View("~/Views/Errors/Details.cshtml"));
        }
Esempio n. 10
0
        public int FillAppointmentInfo(Appointment appointment, string description, List <Medicine> prescription, AppointmentEnumState state)
        {
            if (appointment != null)
            {
                string tempDescription;
                if (string.IsNullOrEmpty(description.Trim()))
                {
                    tempDescription = null;
                }
                else
                {
                    tempDescription = description;
                }
                using (HospitalContext context = new HospitalContext())
                {
                    using (DbContextTransaction transaction = context.Database.BeginTransaction())
                    {
                        try
                        {
                            appointment.Description          = tempDescription;
                            appointment.State                = state;
                            appointment.UpdateTime           = DateTime.Now;
                            context.Entry(appointment).State = EntityState.Modified;
                            int result = context.SaveChanges();

                            var tempAppointment = context.Appointments.Include("Medicines").Single(I => I.Id == appointment.Id);
                            foreach (var item in prescription)
                            {
                                var tempMedicine = context.Medicines.Single(I => I.Id == item.Id);
                                tempAppointment.Medicines.Add(tempMedicine);
                            }
                            context.SaveChanges();

                            transaction.Commit();
                            return(1);
                        }
                        catch (Exception)
                        {
                            transaction.Rollback();
                            return(0);
                        }
                    }
                }
            }
            else
            {
                return(-1);
            }
        }
Esempio n. 11
0
        public ActionResult Create([Bind(Include = "Id,Name,Status,DayOfBirth,TaxCode,Doctor")] Patient patient)
        {
            if (ModelState.IsValid)
            {
                db.Patients.Add(patient);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            //DoctorsDropDownList(patient.Doctors);
            ViewBag.DoctorsList = from d in db.Doctors
                                  orderby d.Name
                                  select d;

            return(View(patient));
        }
Esempio n. 12
0
        public ActionResult Create([Bind(Include = "Id,Title,Type,Time,Regularity,Desc,Status,Contact_person,Contact_phone")] Task task)
        {
            if (ModelState.IsValid)
            {
                task.Created_by    = 1;
                task.Modified_by   = 1;
                task.Created_date  = DateTime.Now;
                task.Modified_date = DateTime.Now;
                db.Tasks.Add(task);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View("Admin/Create", task));
        }
        public static bool AddDoctor(HospitalContext dbContext)
        {
            Console.Clear();
            Console.Write("Enter name: ");
            string doctorName = Console.ReadLine();

            Console.Write("Enter specialty: ");
            string specialty = Console.ReadLine();

            Console.Write("Enter E-Mail Address: ");
            string emailAddress = Console.ReadLine();

            Console.Write("Enter Password: ");
            string password = EncryptionHelper.Encrypt(Console.ReadLine());

            if (PatientDataValidation.IsEmailAddressValid(emailAddress))
            {
                dbContext.Add(new Doctor
                {
                    DoctorName   = doctorName,
                    Specialty    = specialty,
                    EmailAddress = emailAddress,
                    Password     = password
                });

                dbContext.SaveChanges();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 14
0
        public ActionResult Registration(AccountRegistrationVM vm)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    User    u = context.Users.Single(q => q.Id == vm.UserId);
                    Patient p = context.Patients.Single(q => q.UserId == vm.UserId);

                    // hash password
                    u.Password = Hasher.ToHashedStr(vm.Password);

                    // replace the email token used for generating the link to new token
                    // String.Empty does not work because the column must be unique
                    p.EmailToken = TokenGenerator.GenerateEmailToken();

                    context.SaveChanges();
                }

                return(View("RegistrationComplete"));
            }
            catch (Exception e)
            {
                ViewBag.ExceptionMessage = e.Message;
            }
            return(View("~/Views/Errors/Details.cshtml"));
        }
Esempio n. 15
0
        public ActionResult Test(FormCollection collection)
        {
            if (Session["UserId"] == null)
            {
                return(RedirectToAction("Login"));
            }
            else
            {
                string doctorName  = collection["DoctorName"];
                string patientName = Session["Username"].ToString();
                string date        = collection["Date"].ToString();
                string time        = collection["Time"].ToString();
                //time = time.Insert(6, ":00");
                //DateTime dt = DateTime.ParseExact("08/04/2019 08:00 PM", "dd/MM/yyyy hh:mm tt", CultureInfo.InvariantCulture);
                DateTime dt = DateTime.ParseExact(date + " " + time, "dd/MM/yyyy hh:mm tt", CultureInfo.InvariantCulture);
                Response.Write(date);
                Response.Write(time);
                //DateTime dt = DateTime.ParseExact(date+time, "MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
                HospitalContext hc = new HospitalContext();
                Doctor          d  = hc.Doctors.Single(u => u.DoctorName == doctorName);
                Appointment     b  = hc.Appointments.OrderByDescending(x => x.AppointmentId).First();
                int             k  = b.AppointmentId + 1;
                Appointment     a  = new Appointment
                {
                    DoctorId  = d.DoctorId,
                    PatientId = Int32.Parse(Session["UserId"].ToString()),
                    Date      = dt,
                };

                hc.Appointments.Add(a);
                hc.SaveChanges();
                return(RedirectToAction("AppointmentList"));
            }
        }
Esempio n. 16
0
 public ActionResult Cadastrar(Medico medico)
 {
     _context.Medicos.Add(medico);
     _context.SaveChanges();
     TempData["msg"] = "Médico registrado!";
     return(RedirectToAction("Cadastrar"));
 }
Esempio n. 17
0
        //Delete patient from system
        public void DeletePatient(HospitalContext context)
        {
            Console.WriteLine("Write patient first name and last name:");
            List <string> names = Console.ReadLine()
                                  .Split(" ")
                                  .ToList();

            string patientFirstname = names[0];
            string patientLastname  = names[1];

            var patientToDelete = context.Patients
                                  .Where(p => p.FirstName == patientFirstname && p.LastName == patientLastname)
                                  .FirstOrDefault();

            if (context.Patients.Any(p => p == patientToDelete))
            {
                context.Patients.Remove(patientToDelete);
                Console.WriteLine($"{patientToDelete.FirstName} {patientToDelete.LastName} deleted!");
            }
            else
            {
                throw new ArgumentNullException("There is no such patient in the system!");
            }

            context.SaveChanges();
        }
Esempio n. 18
0
        public JsonResult ChangeApproval(int id, int value, int session, int docId, string date)
        {
            int serial = 0;

            using (var ctx = new HospitalContext())
            {
                int amount = ctx.Appointment.Where(c => c.DoctorId == docId && c.Session == session &&
                                                   c.Date == date && c.Approval == 1).Select(c => c.Id).ToList().Count();

                if (value == 1)
                {
                    serial = amount + 1;
                }
                else
                {
                    serial = 0;
                }
                Appointment a = ctx.Appointment.Single(c => c.Id == id);
                a.Approval = value;
                a.IsSeen   = 2;
                a.SerialNo = serial;
                ctx.SaveChanges();
            }
            return(Json('1'));
        }
Esempio n. 19
0
        public void Getqty()
        {
            var drugs = from d in _context.Drug
                        where d.Qty == 0
                        select d.Name;

            var state = from d in _context.Drug
                        where d.Qty == 0
                        select d.State;


            if (drugs != null)
            {
                foreach (string s in state)
                {
                    if (s != "Not Available")
                    {
                        (from m in _context.Drug
                         where m.Qty == 0
                         select m).ToList().ForEach(n => n.State = "Not Available");



                        foreach (string name in drugs)
                        {
                            string      to       = "*****@*****.**"; //To address
                            string      from     = "*****@*****.**";       //From address
                            MailMessage message  = new MailMessage(from, to);
                            string      mailbody = name + " is out of stock";


                            message.Subject = "Some Drugs are out of stock ";
                            message.Body    = mailbody;
                            //var filename = @"c:\test.pdf";
                            //message.Attachments.Add(new Attachment(filename));
                            message.BodyEncoding = System.Text.Encoding.UTF8;
                            message.IsBodyHtml   = true;
                            SmtpClient client = new SmtpClient("smtp.gmail.com", 587); //Gmail smtp
                            System.Net.NetworkCredential basicCredential1 = new
                                                                            System.Net.NetworkCredential("*****@*****.**", "tomcat123456");
                            client.EnableSsl             = true;
                            client.UseDefaultCredentials = false;
                            client.Credentials           = basicCredential1;

                            try
                            {
                                client.Send(message);
                            }

                            catch (Exception ex)
                            {
                                throw ex;
                            }
                        }
                    }
                }
                _context.SaveChanges();
            }
        }
Esempio n. 20
0
        public ActionResult DeleteConfirmed(int id)
        {
            feedback feedback = db.feedbacks.Find(id);

            db.feedbacks.Remove(feedback);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 21
0
 public static void Main()
 {
     using (var db = new HospitalContext())
     {
         db.Database.Migrate();
         db.SaveChanges();
     }
 }
Esempio n. 22
0
 public void Deletar(int id)
 {
     using (HospitalContext ctx = new HospitalContext())
     {
         ctx.Pacientes.Remove(ctx.Pacientes.Find(id));
         ctx.SaveChanges();
     }
 }
 public void Cadastrar(Doutores doutor)
 {
     using (HospitalContext ctx = new HospitalContext())
     {
         ctx.Doutores.Add(doutor);
         ctx.SaveChanges();
     }
 }
Esempio n. 24
0
 public void Cadastrar(Pacientes paciente)
 {
     using (HospitalContext ctx = new HospitalContext())
     {
         ctx.Pacientes.Add(paciente);
         ctx.SaveChanges();
     }
 }
Esempio n. 25
0
        public ActionResult Profile(string message)
        {
            ViewBag.PatientProfile = "active";
            ViewBag.UpdateMessage  = message;
            int pid = (int)Session["PatientId"];

            List <DoctorAppointmentView> ProfileList = new List <DoctorAppointmentView>();
            Patient p = new Patient();

            using (var ctx = new HospitalContext())
            {
                List <Appointment> lap = (from a in ctx.Appointment
                                          where a.PatientId == pid && a.IsSeen == 2
                                          select a).ToList();
                foreach (Appointment q in lap)
                {
                    q.IsSeen = 1;
                }
                ctx.SaveChanges();

                Session["PatientNotify"] = 0;

                var data = (from a in ctx.Appointment
                            join d in ctx.Doctor on a.DoctorId equals d.Id
                            where a.PatientId == pid
                            select new
                {
                    aDate = a.Date,
                    aApproval = a.Approval,
                    aName = d.Name,
                    aPrescription = a.Prescription,
                    aDesignation = d.Designation,
                    aSerial = a.SerialNo
                });
                foreach (var d in data)
                {
                    DoctorAppointmentView dc = new DoctorAppointmentView();
                    dc.Name         = baseControl.Decrypt(d.aName);
                    dc.Designation  = baseControl.Decrypt(d.aDesignation);
                    dc.Approval     = d.aApproval;
                    dc.Date         = d.aDate;
                    dc.Prescription = d.aPrescription;
                    dc.Serial       = d.aSerial;
                    ProfileList.Add(dc);
                }
                // int id = Convert.ToInt32(Session["PatientId"]);
                var k = ctx.Patient.Where(e => e.Id == pid).Select(c => new { c.Name, c.Age, c.Address, c.PhoneNo });
                foreach (var i in k)
                {
                    p.Name    = baseControl.Decrypt(i.Name);
                    p.Address = baseControl.Decrypt(i.Address);
                    p.Age     = i.Age;
                    p.PhoneNo = baseControl.Decrypt(i.PhoneNo);
                }
                ViewBag.Patient = p;
            }
            return(View(ProfileList));
        }
        public static void SeedPatients(HospitalContext context, int count)
        {
            for (int i = 0; i < count; i++)
            {
                context.Patients.Add(PatientGenerator.NewPatient(context));
            }

            context.SaveChanges();
        }
Esempio n. 27
0
        public void createPaciente(Paciente Paciente)
        {
            Paciente tempPaciente = new Paciente();

            tempPaciente.Nome       = Paciente.Nome;
            tempPaciente.Nascimento = Paciente.Nascimento;
            tempPaciente.Telefone   = Paciente.Telefone;
            tempPaciente.CPF        = Paciente.CPF;
            tempPaciente.Convenio   = Paciente.Convenio;

            if (tempPaciente.Convenio != null)
            {
                ctx.Entry(tempPaciente.Convenio).State = System.Data.Entity.EntityState.Unchanged;
            }

            ctx.Pacientes.Add(tempPaciente);
            ctx.SaveChanges();
        }
Esempio n. 28
0
        public ActionResult Add(DoctorsWithPatients doctorsWithPatients)
        {
            var patient = db.Patients.Find(doctorsWithPatients.PatientName);
            var doctor  = db.Doctors.Find(doctorsWithPatients.DoctorName);

            patient.Doctors.Add(doctor);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 29
0
        private static void SeedDoctors(HospitalContext context, int count)
        {
            for (int i = 0; i < count; i++)
            {
                context.Doctors.Add(DoctorsGenerator.NewDoctor(context));
            }

            context.SaveChanges();
        }
Esempio n. 30
0
 public string AddPatient(Patient patient)
 {
     using (var ctx = new HospitalContext())
     {
         ctx.Patients.Add(patient);
         ctx.SaveChanges();
     }
     return(patient.Pesel);
 }