public async Task <PatientDoctor> AddPatientDoctor(int doctorId, int patientId)
        {
            ExceptionThrowers.ThrowErrorIfEntityNotExist(EntityType.doctor, _context, doctorId);

            ExceptionThrowers.ThrowErrorIfEntityNotExist(EntityType.patinet, _context, patientId);


            if (await GetPatientDoctor(doctorId, patientId) != null)
            {
                throw new BadRequestException("This doctor is already assigned for this patient");
            }

            var doctor = await _doctorRepo.GetDoctor(doctorId);

            var patient = await _patientRepo.GetPatient(patientId);


            var patientDoctor = new PatientDoctor()
            {
                DoctorId = doctorId, PatientId = patientId, Doctor = doctor, Patient = patient
            };

            var newPatientDoctor = await _context.PatientDoctors.AddAsync(patientDoctor);

            await _context.SaveChangesAsync();

            return(newPatientDoctor.Entity);
        }
Beispiel #2
0
        public async Task <ActionResult <Patient> > Put(int id, [FromBody] Patient patient)
        {
            if (patient.Id != id)
            {
                return(BadRequest());
            }
            Patient dbPatient = _db.Patients.FirstOrDefault(p => p.Id == patient.Id);

            dbPatient.Name = patient.Name;
            dbPatient.Age  = patient.Age;

            List <PatientDoctor> patientDoctors = _db.PatientDoctors.Where(p => p.PatientId == patient.Id).ToList();

            foreach (var item in patientDoctors)
            {
                dbPatient.PatientDoctors.Remove(item);
            }

            List <PatientDoctor> newPatientDoctors = new List <PatientDoctor>();

            foreach (var item in patient.PatientDoctors)
            {
                PatientDoctor patientDoctor = new PatientDoctor
                {
                    PatientId = dbPatient.Id,
                    DoctorId  = item.DoctorId
                };
                newPatientDoctors.Add(patientDoctor);
            }
            dbPatient.PatientDoctors = newPatientDoctors;
            await _db.SaveChangesAsync();

            return(Ok());
        }
        public async Task CreatePatientDoctor(PatientDoctor patientDoctor)
        {
            patientDoctor.CreationDate = DateTime.Now;

            await db.PatientDoctors.AddAsync(patientDoctor);

            await db.SaveChangesAsync();
        }
Beispiel #4
0
        public PatientDoctorDTO CreatePatientDoctor([FromBody] PatientDoctorDTO patientDoctor)
        {
            PatientDoctor patientDoctorEntity = _mapper.Map <PatientDoctor>(patientDoctor);

            _repository.CreatePatientDoctor(patientDoctorEntity);
            _repository.Save();
            PatientDoctorDTO newPatientDoctor = _mapper.Map <PatientDoctorDTO>(patientDoctorEntity);

            return(newPatientDoctor);
        }
Beispiel #5
0
 public ActionResult AddDoctor(PatientDoctor patientDoctor)
 {
     if (patientDoctor.DoctorId != 0)
     {
         if (_db.PatientDoctors.Where(x => x.PatientId == patientDoctor.PatientId && x.DoctorId == patientDoctor.DoctorId).ToHashSet().Count == 0)
         {
             _db.PatientDoctors.Add(patientDoctor);
         }
     }
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Beispiel #6
0
        public List <PatientDoctor> GetPatientDoctor()
        {
            string        connectionString = ConfigurationManager.ConnectionStrings["HospitalConnectionString"].ConnectionString;
            SqlConnection sqlConnection    = new SqlConnection(connectionString);
            string        query            = "SELECT * FROM PatientDoctorView";
            SqlCommand    sqlCommand       = new SqlCommand(query, sqlConnection);

            sqlConnection.Open();
            SqlDataReader        sqlDataReader     = sqlCommand.ExecuteReader();
            List <PatientDoctor> patientDoctorList = new List <PatientDoctor>();

            while (sqlDataReader.Read())
            {
                PatientDoctor patientDoctor = new PatientDoctor();
                patientDoctor.Id          = int.Parse(sqlDataReader["Id"].ToString());
                patientDoctor.PatientName = sqlDataReader["PatientName"].ToString();
                patientDoctor.DoctorName  = sqlDataReader["DoctorName"].ToString();
                patientDoctorList.Add(patientDoctor);
            }
            return(patientDoctorList);
        }
        public async Task <IActionResult> CreatePatient(PatientCreationBindingModel patientCreationBindingModel)
        {
            ViewBag.Gender = gender.Select(g => new SelectListItem {
                Text = g, Value = g
            });
            ViewBag.BloodType = bloodtypes.Select(g => new SelectListItem {
                Text = g, Value = g
            });
            //Create 'Patient' Role if it doesn't exist
            string RoleString = "Patient";
            var    role       = await _roleManager.RoleExistsAsync(RoleString);

            if (!role)
            {
                await _roleManager.CreateAsync(new IdentityRole(RoleString));
            }

            Patient patient = null;

            //Validate Model
            if (ModelState.IsValid)
            {
                var user = CreateUser(patientCreationBindingModel);
                //create user and assign role if successful
                var result = await _userManager.CreateAsync(user, patientCreationBindingModel.Password);

                if (result.Succeeded)
                {
                    //Fill role related attributes
                    patient = new Patient()
                    {
                        BloodType = patientCreationBindingModel.BloodType,
                        User      = user
                    };
                    _context.Add(patient);
                    _context.SaveChanges();

                    var assistant = await _context.Assistants
                                    .Where(a => a.Id.Equals(_activeUser.Id))
                                    .Include(a => a.User)
                                    .Include(a => a.Doctor)
                                    .SingleAsync();

                    Doctor        doctor = _context.Doctors.Where(d => d.Id.Equals(assistant.Id)).Single();
                    PatientDoctor pd     = new PatientDoctor()
                    {
                        Patient = patient, Doctor = doctor
                    };
                    _context.Add(pd);
                    await _context.SaveChangesAsync();

                    await _userManager.AddToRoleAsync(user, RoleString);
                }

                if (result.Succeeded)
                {
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }

                return(RedirectToAction("Create", patientCreationBindingModel));
            }
            return(View("Create", patient));
        }
 public async Task CreatePatientDoctor(PatientDoctor patientDoctor)
 {
     await patientDoctorsRepository.CreatePatientDoctor(patientDoctor);
 }
        public IActionResult Create([Bind("PatientId,FirstName,LastName,Nationality,AccountId,Image,FatherName,MotherName,UserName,Password")] Patient patient, IFormFile Image)
        {
            if (Image != null)
            {
                using (var stream = new MemoryStream())
                {
                    Image.CopyTo(stream);
                    byte[] ProfileImage = stream.ToArray();
                    patient.ProfileImage = ProfileImage;
                }
            }
            if (ModelState.IsValid)
            {
                //check if patient existed
                bool ExistedBefore = _context.Patient.Any(x =>
                                                          x.FirstName.ToLower().TrimEnd().Equals(patient.FirstName.ToLower().TrimEnd()) &&
                                                          x.LastName.ToLower().TrimEnd().Equals(patient.LastName.ToLower().TrimEnd()) &&
                                                          x.MotherName.ToLower().TrimEnd().Equals(patient.MotherName.ToLower().TrimEnd()) &&
                                                          x.FatherName.ToLower().TrimEnd().Equals(patient.FatherName.ToLower().TrimEnd()));

                //create account and generate a user name
                bool    IsAccountExisted = _context.Account.Any(x => x.UserName.ToLower().TrimEnd().Equals(patient.UserName.ToLower().TrimEnd()));
                int?    AccountId        = null;
                Account account          = new Account()
                {
                    UserName      = patient.UserName,
                    Password      = patient.Password,
                    AccountTypeId = 2
                };

                _context.Account.Add(account);
                _context.SaveChanges();
                AccountId = account.AccountId;

                if (!ExistedBefore)
                {
                    patient.AccountId = AccountId;
                    _context.Add(patient);
                    _context.SaveChanges();
                    int? PatientId            = patient.PatientId;
                    int? DoctorId             = new GlobalMethods(_context, _httpContextAccessor).GetDoctorId();
                    bool PatientDoctorExisted = _context.PatientDoctor.Any(x => x.DoctorId == DoctorId && x.PatientId == PatientId);
                    if (!PatientDoctorExisted)
                    {
                        PatientDoctor patientDoctor = new PatientDoctor()
                        {
                            PatientId = PatientId,
                            DoctorId  = DoctorId
                        };
                        _context.PatientDoctor.Add(patientDoctor);
                        _context.SaveChanges();
                    }
                    return(RedirectToAction("Create"));
                }
                else
                {
                    ViewData["FeedBack"] = "this account is already existed!";
                    return(View(patient));
                }
            }
            return(View(patient));
        }