Example #1
0
        private static void UpdateExistingDoctorFields(Guid id, DoctorDto doctorDto, PersistenceClassesDataContext dataContext)
        {
            var doctor = dataContext.Doctors.FirstOrDefault(p => p.Guid.Equals(id));

            if (doctor == null)
            {
                throw GetResponseException(HttpStatusCode.NotFound, Messages.DoctorDoesNotExist);
            }
            if (doctorDto.Name != null)
            {
                doctor.Name = doctorDto.Name;
            }
            if (doctorDto.MiddleName != null)
            {
                doctor.MiddleName = doctorDto.MiddleName;
            }
            if (doctorDto.FamilyName != null)
            {
                doctor.FamilyName = doctorDto.FamilyName;
            }
            if (doctorDto.Address != null)
            {
                doctor.Address = doctorDto.Address;
            }
            if (doctorDto.MobilePhone != null)
            {
                doctor.MobilePhone = doctorDto.MobilePhone;
            }
            if (doctorDto.Egn != null)
            {
                doctor.Egn = doctorDto.Egn;
            }
            dataContext.SubmitChanges();
        }
Example #2
0
        public int AddDoctor([FromBody] DoctorDto dto)
        {
            if (dto == null)
            {
                return(0);
            }

            Врач doc = new Врач()
            {
                ВнешнийХэш = dto.Hash,
            };

            int?userId = dto.UserId;

            if (userId == null)
            {
                userId = new UserController().AddUser(dto.User);
            }

            doc.Пользователь = db.GetFromDatabase <Пользователь>(x => x.Id == userId).FirstOrDefault();

            if (string.IsNullOrEmpty(doc.ВнешнийХэш))
            {
                doc.ВнешнийХэш = HashHelper.GetHashForNewEntity(doc);
            }

            db.Insert(doc);
            return(doc.Id);
        }
        public DoctorDto GetDoctor(int id)
        {
            var doctor = new DoctorDto();

            using (SqlConnection connection = new SqlConnection(ConString))
                using (SqlCommand command = new SqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandText = "select IdDoctor, FirstName, LastName, Email " +
                                          "from Doctors " +
                                          "where IdDoctor = @id";
                    command.Parameters.AddWithValue("id", id);
                    connection.Open();

                    SqlDataReader dataReader = command.ExecuteReader();
                    if (!dataReader.Read())
                    {
                        return(null);
                    }

                    doctor.IdDoctor  = int.Parse(dataReader["IdDoctor"].ToString());
                    doctor.FirstName = dataReader["FirstName"].ToString();
                    doctor.LastName  = dataReader["LastName"].ToString();
                    doctor.Email     = dataReader["Email"].ToString();

                    dataReader.Close();
                }

            return(doctor);
        }
Example #4
0
        public async Task <DoctorDto> Post(DoctorDto doctor)
        {
            using (var db = new PatientContext())
            {
                using (var transaction = db.Database.BeginTransaction(System.Data.IsolationLevel.Serializable))
                {
                    try
                    {
                        db.Doctors.AddOrUpdate(doctor.Doctor);
                        db.DoctorAilmentLookups.AddOrUpdate(doctor.DoctorAilmentLookups.ToArray());

                        await db.SaveChangesAsync();

                        transaction.Commit();

                        return(doctor);
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        Console.WriteLine(ex);
                        throw;
                    }
                }
            }
        }
Example #5
0
        public async Task EditDoctorAsync()
        {
            var                  doctorId       = Guid.Parse("00000000-0000-0000-0000-000000000011");
            const string         name           = "John";
            const string         surname        = "Malecki";
            const Specialization specialization = Specialization.Anesthesiologist;

            var returnedDoctor = new Doctor
            {
                Id             = doctorId,
                Name           = name,
                Surname        = surname,
                Specialization = specialization
            };

            var updatedDoctor = new DoctorDto
            {
                Id             = doctorId,
                Name           = name,
                Surname        = surname,
                Specialization = Specialization.AllergistImmunologist
            };

            var mockManager          = new FacadeMockManager();
            var doctorRepositoryMock = mockManager.ConfigureGetAndUpdateRepositoryMock <Doctor>(returnedDoctor, nameof(Doctor.Specialization));
            var doctorQueryMock      = mockManager.ConfigureQueryObjectMock <DoctorDto, Doctor, DoctorFilterDto>(null);
            var doctorFacade         = CreateDoctorFacade(doctorQueryMock, doctorRepositoryMock);

            await doctorFacade.EditDoctorAsync(updatedDoctor);

            Assert.AreEqual((int)updatedDoctor.Specialization, mockManager.CapturedUpdatedUnit);
        }
Example #6
0
        public async Task <ActionResult> Create(DoctorCreateModel doctorCreateModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(doctorCreateModel));
            }
            DoctorDto doctorDto = new DoctorDto
            {
                Username       = doctorCreateModel.Username,
                Password       = doctorCreateModel.Password,
                Specialization = doctorCreateModel.Specialization,
                Name           = doctorCreateModel.Name,
                Surname        = doctorCreateModel.Surname
            };

            if (await PatientFacade.GetPatientByUsernameAsync(doctorCreateModel.Username) != null ||
                await DoctorFacade.GetDoctorByUsernameAsync(doctorCreateModel.Username) != null)
            {
                ModelState.AddModelError("Username", "Account with that username already exists");
                return(View(doctorCreateModel));
            }
            await DoctorFacade.RegisterDoctor(doctorDto);

            return(RedirectToAction("Login", "Account"));
        }
Example #7
0
        public async Task <ActionResult> Update(DoctorUpdateModel doctorUpdateModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(doctorUpdateModel));
            }
            doctorUpdateModel.Username = HttpContext.User.Identity.Name;
            var doctorToUpdate = await DoctorFacade.GetDoctorByUsernameAsync(doctorUpdateModel.Username);

            if (doctorToUpdate == null)
            {
                ModelState.AddModelError("Username", "Account does not exist");
                return(View(doctorUpdateModel));
            }
            DoctorDto doctorDto = new DoctorDto
            {
                Username       = HttpContext.User.Identity.Name,
                Id             = doctorToUpdate.Id,
                Specialization = doctorToUpdate.Specialization,
                Name           = doctorUpdateModel.Name,
                Surname        = doctorUpdateModel.Surname
            };
            await DoctorFacade.EditDoctorAsync(doctorDto);

            return(RedirectToAction("Index", "Home"));
        }
Example #8
0
        public bool RegisterDoctor(DoctorDto doctor)
        {
            if (_userRepository.Single(x => x.Login == doctor.Login) != null)
            {
                return(false);
            }

            var salt   = EncryptionUtil.GenerateSalt();
            var passwd = EncryptionUtil.HashPassword(doctor.Password, salt);

            var user = _mapper.Map <User>(doctor);

            user.Password = passwd;
            user.Salt     = salt;
            user.Role     = _roleRepository.Single(x => x.Name == doctor.Role.ToString());


            var newDoctor = new Doctor
            {
                Specialization = _specializationRepository.Single(x => x.Name == doctor.SpecializationName),
                User           = user
            };

            _userRepository.Add(user);
            _doctorRepository.Add(newDoctor);

            return(true);
        }
Example #9
0
        public async Task <IActionResult> UpdateDoctor(Guid doctorId, [FromBody] DoctorDto doctor)
        {
            await _doctorService.UpdateDoctor(doctorId, doctor.Street, doctor.PostCode,
                                              doctor.PhoneNumber, doctor.City);

            return(NoContent());
        }
        public IEnumerable <DoctorDto> GetDoctors()
        {
            var list = new List <DoctorDto>();

            using (SqlConnection connection = new SqlConnection(ConString))
                using (SqlCommand command = new SqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandText = "select IdDoctor, FirstName, LastName, Email " +
                                          "from Doctors";
                    connection.Open();

                    SqlDataReader dataReader = command.ExecuteReader();

                    while (dataReader.Read())
                    {
                        var doctor = new DoctorDto
                        {
                            IdDoctor  = int.Parse(dataReader["IdDoctor"].ToString()),
                            FirstName = dataReader["FirstName"].ToString(),
                            LastName  = dataReader["LastName"].ToString(),
                            Email     = dataReader["Email"].ToString()
                        };
                        list.Add(doctor);
                    }

                    dataReader.Close();
                }

            return(list);
        }
        public async Task <IActionResult> Create(DoctorDto model)
        {
            var doctor = new Doctor();

            if (ModelState.IsValid)
            {
                string uniqueName = null;
                if (model.Photo != null)
                {
                    var folderPath = Path.Combine(hostingEnvironment.WebRootPath, "images");
                    uniqueName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
                    var filePath = Path.Combine(folderPath, uniqueName);

                    if (filePath != null)
                    {
                        model.Photo.CopyTo(new FileStream(filePath, mode: FileMode.Create));
                    }
                }


                doctor = _mapper.Map <Doctor>(model);

                doctor.ProfilePhoto = uniqueName;

                _context.Add(doctor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Example #12
0
 public void ReceiveVisitRequest(DoctorDto doctor, VisitRequestDto visitRequest)
 {
     if (_activeDoctors.Any(x => x.Key.Id == doctor.Id))
     {
         _activeDoctors.First(x => x.Key.Id == doctor.Id).Value.UpdatePendingRequests(visitRequest);
     }
 }
Example #13
0
        public async Task <ActionResult <DoctorDto> > Put(int id, DoctorDto model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Model is not valid"));
                }

                var oldDoctor = await _doctorService.GetDoctorByIdAsync(id);

                if (oldDoctor == null)
                {
                    return(NotFound($"Could not find camp with id of {id}"));
                }

                var updatedDoctor = _mapper.Map(model, oldDoctor);

                if (await _doctorService.UpdateDoctor(updatedDoctor))
                {
                    return(Ok(updatedDoctor));
                }
            }
            catch (Exception e)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure: {e}"));
            }

            return(BadRequest());
        }
Example #14
0
        /// <summary>
        /// Updates the specified doctor.
        /// </summary>
        /// <param name="item">The item.</param>
        public void Update(DoctorDto item)
        {
            var entity = this.Session.Get <Doctor>(item.Id);

            Mapper.Map <DoctorDto, Doctor>(item, entity);
            this.Session.Merge(entity);
        }
Example #15
0
        public async Task <string> Create(DoctorDto model)
        {
            //var officer = _httpContextAccessor.HttpContext.User.Identity.Name;

            //if (officer == "SuperAdmin")
            //{
            //    officer = "Admin";
            //}

            var user = new ApplicationUser
            {
                UserName     = model.EmailAddress,
                SurName      = model.SurName,
                Email        = model.EmailAddress,
                FirstName    = model.FirstName,
                OtherName    = model.OtherName,
                MobileNo     = model.MobileNo,
                Sex          = model.Sex,
                Address      = model.Address,
                EntityStatus = model.Status
            };

            var result = await userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                await userManager.AddToRoleAsync(user, "Doctor");

                Doctor doctor = new Doctor();
                doctor.UserId         = user.Id;
                doctor.SurName        = model.SurName;
                doctor.FirstName      = model.SurName;
                doctor.OtherName      = model.OtherName;
                doctor.EmailAddress   = model.EmailAddress;
                doctor.PhoneNo        = model.PhoneNo;
                doctor.MobileNo       = model.MobileNo;
                doctor.Sex            = model.Sex;
                doctor.Address        = model.Address;
                doctor.Status         = model.Status;
                doctor.ProfilePicture = model.ProfilePicture;
                doctor.Address        = model.Address;
                doctor.Biography      = model.Biography;
                doctor.BloodGroupId   = model.BloodGroupId;
                doctor.DepartmentId   = model.DepartmentId;
                doctor.Designation    = model.Designation;
                doctor.Specialist     = model.Specialist;
                doctor.Education      = model.Education;

                _context.Doctor.Add(doctor);
                await _context.SaveChangesAsync();


                return("true");
            }
            var errors  = result.Errors;
            var message = string.Join(",", errors);

            return(message);
        }
Example #16
0
        public async Task <IActionResult> Post([FromBody] DoctorDto doctor)
        {
            await _doctorService.AddDoctor(doctor.Email, doctor.Password, doctor.Pesel,
                                           doctor.FirstName, doctor.SecondName, doctor.PhoneNumber, doctor.PostCode,
                                           doctor.City, doctor.Street, doctor.HouseNumber);

            return(Created("/doctors/5", null));
        }
Example #17
0
        private static Doctor CreateDoctor(DoctorDto doctorDto, SysUser sysUser)
        {
            var doctor = Mapper.Map <DoctorDto, Doctor>(doctorDto);

            doctor.Guid   = Guid.Empty;
            doctor.UserId = sysUser.Guid;
            return(doctor);
        }
 private void CreateClick()
 {
     if (Doctors.Count == 0 || Doctors[Doctors.Count - 1].DoctorId != 0)
     {
         ToSave = new DoctorDto();
         Doctors.Add(ToSave);
     }
 }
Example #19
0
        public IEnumerable <VisitRequestDto> GetPendingRequests(DoctorDto doctor)
        {
            var pendingRequests = _requestsRepository.Get(d => d.DoctorId == doctor.Id && d.IsApproved == null,
                                                          cfg => cfg.Doctor, cfg => cfg.Doctor.User, cfg => cfg.Patient, cfg => cfg.Patient.User,
                                                          cfg => cfg.Doctor.Specialization);

            return(_mapper.Map <VisitRequestDto[]>(pendingRequests));
        }
 private bool CompareInput(DoctorDto doctorDto, string name)
 {
     if (doctorDto.Name.ToLower().Contains(name.ToLower()) || doctorDto.Surname.ToLower().Contains(name.ToLower()))
     {
         return(true);
     }
     return(false);
 }
Example #21
0
 private DoctorDto HideSensitiveInformationIfNeeded(DoctorDto doctorDto)
 {
     if (IsUserInRole(User, UserRole.Patient))
     {
         doctorDto.Egn = "HIDDEN";
     }
     return(doctorDto);
 }
 private void CancelClick()
 {
     if (ToSave.DoctorId == 0)
     {
         Doctors.RemoveAt(Doctors.Count - 1);
     }
     ToSave = new DoctorDto();
 }
Example #23
0
        public void Doctor_dto_to_doctor()
        {
            DoctorDto doctorDto = CreateDoctorDto();

            Doctor myDoctor = HospitalApp.Adapters.DoctorAdapter.DoctorDtoToDoctor(doctorDto);

            myDoctor.ShouldBeOfType(typeof(Doctor));
        }
Example #24
0
 public void UpdateExistingDoctor(Guid id, [FromBody] DoctorDto doctorDto)
 {
     EnsureNotInRole(User, UserRole.Patient, Messages.PatientNotAllowedToExecute);
     if (IsUserInRole(User, UserRole.Doctor))
     {
         EnsureId(User, id, Messages.DoctorNotAllowedToModifyOtherDoctors);
     }
     Execute(dataContext => UpdateExistingDoctorFields(id, doctorDto, dataContext));
 }
Example #25
0
        public void LogoutDoctor(DoctorDto doctor)
        {
            var foundDoctor = _activeDoctors.FirstOrDefault(x => x.Key.Id == doctor.Id);

            if (foundDoctor.Key != null)
            {
                _activeDoctors.Remove(foundDoctor.Key);
            }
        }
Example #26
0
        public static Doctor DoctorDtoToDoctor(DoctorDto dto)
        {
            Doctor doctor = new Doctor();

            doctor.Id      = dto.Id;
            doctor.Name    = dto.Name;
            doctor.Surname = dto.Surname;
            return(doctor);
        }
Example #27
0
        public static DoctorDto DoctorToDoctorDto(Doctor doctor)
        {
            DoctorDto dto = new DoctorDto();

            dto.Id      = doctor.Id;
            dto.Name    = doctor.Name;
            dto.Surname = doctor.Surname;
            return(dto);
        }
Example #28
0
 /// <summary>
 /// Removes the specified doctor.
 /// </summary>
 /// <param name="item">The item.</param>
 public void Remove(DoctorDto item)
 {
     Assert.IsNotNull(item, "item");
     if (!this.CanRemove(item))
     {
         throw new ReferencialIntegrityException();
     }
     this.Remove <Doctor>(item);
 }
Example #29
0
        public IActionResult Add(DoctorDto doctorDto)
        {
            if (_doctorService.Add(doctorDto) == null)
            {
                return(NotFound());
            }

            return(Ok(doctorDto));
        }
Example #30
0
        public async Task <ActionResult> UpdateInfoAsync(DoctorDto doctor)
        {
            var model = _mapper.Map <DoctorDto, DoctorModel>(doctor);

            model.Id = UserId;

            var result = await _doctorService.UpdateAsync(model);

            return(StatusCode((int)result));
        }