Exemplo n.º 1
0
        public Task <IList <PatientViewModelList> > CreatePatient(PatientInputModel patientInput)
        {
            patientInput = this.NormalizaPatientInput(patientInput);

            Domain.Entities.Patient patientTobeSaved = new Domain.Entities.Patient(
                patientInput.Name,
                patientInput.Phone,
                patientInput.ScheduleData
                );

            this.ValidationPatient(patientTobeSaved, null);

            IList <PatientViewModelList> patientSeached = this.SearchForCreate(patientInput).Result;

            if (patientSeached?.Count > 0)
            {
                return(Task.FromResult(patientSeached));
            }
            else
            {
                Domain.Entities.Patient PatientSaved = this.PatientRepository.Insert(patientTobeSaved).Result;

                return(Task.FromResult(patientListCollection(PatientSaved)));
            }
        }
Exemplo n.º 2
0
        public void Integration_create_patient_error(string name, string phone, string messageError, HttpStatusCode errorMethod)
        {
            var patientInputModelToCreate = new PatientInputModel {
                Name         = name,
                Phone        = phone,
                ScheduleData = new Schedule(DateTime.Now.AddDays(1).ToUniversalTime(), false, "", false, 50, new DateTime(), false, "--Nenhum--", "--Nenhum--", 0, 0)
            };

            /*
             * if (phone == "11999999999")    // para incluir data vazias
             *  patientInputModelToCreate.Scheduletime = patientInputModelToCreate.Scheduledate;
             */

            if (phone == "11999998888")    // para incluir data menores que a data atual
            {
                patientInputModelToCreate.ScheduleData.SetStartdDate(DateTime.Now.AddDays(-1).ToUniversalTime());
            }


            if (phone == "11999990000")    // para incluir data já utilizada
            {
                patientInputModelToCreate.ScheduleData.SetStartdDate(new DateTime(2021, 5, 10, 18, 30, 0, DateTimeKind.Utc));
            }

            var responseInfo = this.CreationResult(patientInputModelToCreate);

            var messageResult = responseInfo.Content.ReadAsStringAsync().Result;

            Assert.Equal(errorMethod, responseInfo.StatusCode);
            Assert.True(messageResult.ToLower().Contains(messageError));
        }
Exemplo n.º 3
0
        public async Task TestGetByFullPersonaliaModelInvalid()
        {
            // Arrange
            var patients = GeneratePatientEntityList();

            var mockDbSet = patients.AsQueryable().BuildMockDbSet();

            var mockContext = new Mock <DemographicsDbContext>();

            mockContext
            .Setup(x => x.Set <Patient>())
            .Returns(mockDbSet.Object)
            .Verifiable();

            var testModel = new PatientInputModel
            {
                FamilyName = "Test",
                GivenName  = "Twenty",
                SexId      = 2
            };

            var repository = new PatientRepository(mockContext.Object);

            // Act
            var result = await repository.GetByFullPersonalia(testModel);

            // Assert
            Assert.Null(result);
        }
Exemplo n.º 4
0
        private IEnumerable <(Guid, string)> SearchScheduleDateTimeFree(DateTime startDate, int duration)
        {
            IList <(Guid, string)> returnValue = new List <(Guid, string)>();
            string            DateUsed         = "";
            PatientInputModel patientInput     = new PatientInputModel();

            patientInput.ScheduledateRange.Add(startDate.ToUniversalTime());
            patientInput.ScheduledateRange.Add(startDate.AddMinutes(duration).ToUniversalTime());
            IList <PatientViewModelList> result = this.SearchByScheduleDateRange(patientInput.ScheduledateRange).Result;


            if (result != null)
            {
                result.ToList <PatientViewModelList>().ForEach(_patient =>
                {
                    _patient.Schedules
                    .Where(_schedule =>
                    {
                        if (_schedule.Canceled || _schedule.Executed)
                        {
                            return(false);
                        }

                        return(SharedCore.tools.DateTimeTools.DateTimeBetween(_schedule.StartdDate, patientInput.ScheduledateRange[0], patientInput.ScheduledateRange[1]) ||
                               SharedCore.tools.DateTimeTools.DateTimeBetween(_schedule.EndDate, patientInput.ScheduledateRange[0], patientInput.ScheduledateRange[1]));
                    })
                    .ToList().ForEach(_schedule => DateUsed = ScheduleDateUsed(_schedule));
                    returnValue.Add((_patient.Key, _patient.Name + " em " + DateUsed));
                });
            }
            return(returnValue);

            string ScheduleDateUsed(Schedule _Schedule) => SharedCore.tools.DateTimeTools.ConvertDateToString(_Schedule.StartdDate) + " ~ " + SharedCore.tools.DateTimeTools.ConvertDateHourToString(_Schedule.EndDate);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Asynchronously creates a new Patient entity and persists it to the DB.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public async Task <Patient> Create(PatientInputModel model)
        {
            if (model?.Addresses == null || model.PhoneNumbers == null)
            {
                throw new ArgumentNullException();
            }

            var patient = await _unitOfWork.PatientRepository.GetByFullPersonalia(model);

            if (patient != null)
            {
                throw new Exception("Error: a Patient entity already exists that matches the supplied personalia.");
            }

            var entity = _mapper.Map <Patient>(model);

            await LinkAddresses(model.Addresses, entity);
            await LinkPhoneNumbers(model.PhoneNumbers, entity);

            try
            {
                _unitOfWork.PatientRepository.Create(entity);
                await _unitOfWork.CommitAsync();

                return(entity);
            }
            catch (Exception)
            {
                await _unitOfWork.RollbackAsync();

                throw;
            }
        }
Exemplo n.º 6
0
        public PatientsViewModel GetPatientsOnPathway([ModelBinder(typeof(RoleDataModelBinder))] RoleData role, int?index = null, int?pageCount = null, string patientName = null, string hospital = null, string specialty = null, string clinician = null, string ppiNumber = null, string nhsNumber = null, string periodType = null, string orderBy = null, string orderDirection = null)
        {
            var patiensInputModel = new PatientInputModel
            {
                PatientsFilterInputModel = new PatientFilterInputModel
                {
                    PatientName = patientName,
                    Hospital    = hospital,
                    Specialty   = specialty,
                    Clinician   = clinician,
                    PpiNumber   = ppiNumber,
                    NhsNumber   = nhsNumber,
                    PeriodType  = periodType
                },
                ListInputModel = new ListInputModel
                {
                    Index          = index,
                    PageCount      = pageCount,
                    OrderBy        = orderBy,
                    OrderDirection = orderDirection
                }
            };

            return(_patientPresentationService.GetPatientsOnPathway(role, patiensInputModel));
        }
Exemplo n.º 7
0
        public void RepositoryReal_serch_patient_by_nome_phone_corrected()
        {
            PatientInputModel            patientImputModel = configurations.GetUserInputModelCriation();
            IList <PatientViewModelList> patientSaved      = this.patientService.SearchForCreate(patientImputModel).Result;

            Assert.Equal(1, patientSaved.Count);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Updates a Patient entity and persists any changes made to the DB.
        /// </summary>
        /// <param name="entity">The <see cref="Patient"/> entity to update.</param>
        /// <param name="model">The <see cref="PatientInputModel"/> model containing the updated data.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public async Task Update(Patient entity, PatientInputModel model)
        {
            if (entity == null || model == null)
            {
                throw new ArgumentNullException();
            }

            try
            {
                _mapper.Map(model, entity);

                await UpdateAddresses(model.Addresses, entity);
                await UpdatePhoneNumbers(model.PhoneNumbers, entity);

                _unitOfWork
                .PatientRepository
                .Update(entity);

                await _unitOfWork.CommitAsync();
            }
            catch (Exception)
            {
                await _unitOfWork.RollbackAsync();

                throw;
            }
        }
Exemplo n.º 9
0
        public void RepositoryReal_query_all_patient_no_filter()
        {
            PatientInputModel patientImputModel = new PatientInputModel {
            };

            IList <PatientViewModelList> patientSearched = this.patientService.SearchByLikeNamePhoneScheduleDateRange(patientImputModel).Result;

            Assert.NotEqual(0, patientSearched.Count);
        }
Exemplo n.º 10
0
        public void RepositoryReal_query_patient_only_name_parcial_not_found()
        {
            PatientInputModel patientImputModel = new PatientInputModel {
                Name = "nome _texto não deve ser encontrado"
            };

            IList <PatientViewModelList> patientSearched = this.patientService.SearchByLikeNamePhoneScheduleDateRange(patientImputModel).Result;

            Assert.Equal(0, patientSearched.Count);
        }
Exemplo n.º 11
0
        public void RepositoryReal_query_patient_only_phone_parcial_found()
        {
            PatientInputModel patientImputModel = new PatientInputModel {
                Phone = "11999"
            };

            IList <PatientViewModelList> patientSearched = this.patientService.SearchByLikeNamePhoneScheduleDateRange(patientImputModel).Result;

            Assert.True(patientSearched?[0].Phone.Contains("11999"));
        }
Exemplo n.º 12
0
        public void RepositoryReal_query_patient_only_name_parcial_found()
        {
            PatientInputModel patientImputModel = new PatientInputModel {
                Name = "name create 09"
            };

            IList <PatientViewModelList> patientSearched = this.patientService.SearchByLikeNamePhoneScheduleDateRange(patientImputModel).Result;

            Assert.Equal(4, patientSearched.Count);
        }
Exemplo n.º 13
0
        public static PatientInputModel GetUserInputModelCriation()
        {
            var patientInputModel = new PatientInputModel();

            patientInputModel.Name         = "nome teste criar";
            patientInputModel.Phone        = "11999887776";
            patientInputModel.ScheduleData = new Schedule(DateTime.Now.AddDays(1), false, "", false, 50, DateTime.Now.AddDays(1), false, "--Nenhum--", "--Nenhum--", 0, 0);

            return(patientInputModel);
        }
Exemplo n.º 14
0
        public void RepositoryReal_query_patient_only_phone_parcial_not_found()
        {
            PatientInputModel patientImputModel = new PatientInputModel {
                Phone = "1199448875"
            };

            IList <PatientViewModelList> patientSearched = this.patientService.SearchByLikeNamePhoneScheduleDateRange(patientImputModel).Result;

            Assert.Equal(0, patientSearched.Count);
        }
Exemplo n.º 15
0
        public void RepositoryReal_serchForCreate_patient_only_nome_equal_found()
        {
            PatientInputModel patientImputModel = configurations.GetUserInputModelCriation();

            //nome se mantem e telefone mudado
            patientImputModel.Phone = "11999994444";

            IList <PatientViewModelList> patientSaved = this.patientService.SearchForCreate(patientImputModel).Result;

            Assert.Equal(1, patientSaved.Count);
        }
Exemplo n.º 16
0
        public void RepositoryReal_query_patient_date_range_not_found()
        {
            PatientInputModel patientImputModel = new PatientInputModel();

            patientImputModel.ScheduledateRange.Add(new System.DateTime(2021, 04, 20));
            patientImputModel.ScheduledateRange.Add(new System.DateTime(2021, 04, 21));

            IList <PatientViewModelList> patientSearched = this.patientService.SearchByLikeNamePhoneScheduleDateRange(patientImputModel).Result;

            Assert.Equal(0, patientSearched.Count);
        }
Exemplo n.º 17
0
        public void RepositoryReal_serchForCreate_patient_only_phone_equal_found()
        {
            PatientInputModel patientImputModel = configurations.GetUserInputModelCriation();

            //nome se altera e telefone se manter
            patientImputModel.Name = "nome não existente";

            IList <PatientViewModelList> patientSaved = this.patientService.SearchForCreate(patientImputModel).Result;

            Assert.Equal(1, patientSaved.Count);
        }
Exemplo n.º 18
0
        public void RepositoryReal_serch_patient_by_nome_phone_not_found()
        {
            PatientInputModel patientImputModel = configurations.GetUserInputModelCriation();

            patientImputModel.Name  = "nome não existente";
            patientImputModel.Phone = "11999994444";

            IList <PatientViewModelList> patientSaved = this.patientService.SearchForCreate(patientImputModel).Result;

            Assert.Equal(0, patientSaved.Count);
        }
Exemplo n.º 19
0
        public async Task <IActionResult> Post(PatientInputModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            var createdEntity = await _patientService.Create(model);

            return(CreatedAtAction("Get", new { createdEntity.Id }, createdEntity));
        }
Exemplo n.º 20
0
        public void RepositoryReal_ceate_patient_corrected()
        {
            PatientInputModel patientImputModel = configurations.GetUserInputModelCriation();

            patientImputModel.Name         = "name 112";
            patientImputModel.Phone        = "11598487760";
            patientImputModel.ScheduleData = new Schedule(DateTime.Now.AddDays(1), false, "", false, 30, DateTime.Now.AddDays(1), false, "escalda pés", "Pacote Relaxar 1", 100, 1);

            IList <PatientViewModelList> patientSaved = this.patientService.CreatePatient(patientImputModel).Result;

            Assert.Equal(1, patientSaved.Count);
        }
Exemplo n.º 21
0
        public ActionResult AddPatient(PatientInputModel model)
        {
            // Add Patient to patient repository
            Patient patient = _patientManagementService.AddPatient(model.FirstName, model.LastName, model.Age,
                                                                   model.Gender, model.HealthCardNumber, model.PhoneNumber, model.Address);

            // Create patient account
            _accountManagementService.CreateAccountForPatient(patient.PatientId);

            // Redirect to All Patients
            return(RedirectToAction("Details", "Staff", new { id = patient.PatientId, role = UserRole.Patient, showUserCreatedAlert = true }));
        }
Exemplo n.º 22
0
        public void create_patient_incorrected_schedule_existent()
        {
            var patienteInputModel = new PatientInputModel();

            patienteInputModel.Name         = "name teste 14";
            patienteInputModel.Phone        = "11909998888";
            patienteInputModel.ScheduleData = new Domain.Entities.Schedule(new DateTime(2021, 09, 23, 17, 0, 0), false, "", false, 50, new DateTime(), false, "--Nenhum--", "--Nenhum--", 0, 0);

            var ex = Assert.ThrowsAsync <ArgumentException> (() => patientService.CreatePatient(patienteInputModel));

            Assert.Contains("existe atendimento neste", ex.Result.Message);
        }
Exemplo n.º 23
0
        private HttpResponseMessage CreationResult(PatientInputModel patientInputModelToCreate)
        {
            var json = JsonConvert.SerializeObject(patientInputModelToCreate);

            request.Content = new StringContent(json, Encoding.UTF8, "application/json");

            var response = client.PostAsync(request.RequestUri.AbsolutePath, request.Content).ConfigureAwait(false);

            var responseInfo = response.GetAwaiter().GetResult();

            return(responseInfo);
        }
Exemplo n.º 24
0
        public async Task <ResultModel <PatientOutputModel> > InsertPatient([FromBody] PatientInputModel item)
        {
            var patientItem = new PatientModel()
            {
                IdentityNumber = item.IdentityNumber,
                FirstName      = item.FirstName,
                LastName       = item.LastName,
                Phone          = item.Phone,
                Address        = item.Address
            };

            return(await _patientStoreService.InsertAndSaveAsync <PatientOutputModel>(patientItem));
        }
Exemplo n.º 25
0
        private void InitCreate()
        {
            FormValid        = false;
            PatientValid     = false;
            AddressValid     = true;
            PhoneNumberValid = true;

            OperationStatus = APIOperationStatus.Initial;

            PatientModel = new PatientInputModel();
            PatientModel.Addresses.Add(new AddressInputModel());
            PatientModel.PhoneNumbers.Add(new PhoneNumberInputModel());
        }
Exemplo n.º 26
0
        private PatientInputModel NormalizaPatientInput(PatientInputModel patientInput)
        {
            if (patientInput.Name?.Length > 0)
            {
                patientInput.Name = patientInput.Name.Trim();
            }

            if (patientInput.Phone?.Length > 0)
            {
                patientInput.Phone = patientInput.Phone.Trim();
            }

            return(patientInput);
        }
Exemplo n.º 27
0
        public ActionResult <PatientViewModel> Post(PatientInputModel patientInputModel)
        {
            Patient patient  = metodos.MapearPatient(patientInputModel);
            var     response = _Service.Save(patient);

            if (response.Error == false)
            {
                return(Ok(response.Object));
            }
            else
            {
                return(BadRequest(response.Message));
            }
        }
Exemplo n.º 28
0
        public void RepositoryReal_query_patient_date_range_found_2()
        {
            PatientInputModel patientImputModel = new PatientInputModel();

            patientImputModel.ScheduledateRange.Add(new System.DateTime(2021, 04, 28));
            patientImputModel.ScheduledateRange.Add(new System.DateTime(2021, 04, 29, 0, 2, 0));

            var strrr = patientImputModel.ScheduledateRange[1].ToUniversalTime();

            // DateTime ttt = DateTime.Parse(strrr);

            IList <PatientViewModelList> patientSearched = this.patientService.SearchByLikeNamePhoneScheduleDateRange(patientImputModel).Result;

            Assert.Equal(3, patientSearched?.Count);
        }
Exemplo n.º 29
0
        public async Task TestCreateDTOPhoneNumbersNull()
        {
            // Arrange
            var testDTO = new PatientInputModel {
                PhoneNumbers = null
            };

            var service = new PatientService(null, null);

            // Act
            async Task Action() => await service.Create(testDTO);

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(Action);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Asynchronously gets a <see cref="Patient" /> entity by the minimal set
        /// of properties that uniquely identify it: FamilyName, GivenName, DateOfBirth, and SexId.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public async Task <Patient> GetByFullPersonalia(PatientInputModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException();
            }

            var result =
                await base.GetByCondition(p =>
                                          p.FamilyName.Contains(model.FamilyName) &&
                                          p.GivenName.Contains(model.GivenName))
                .FirstOrDefaultAsync(p => p.SexId == model.SexId && p.DateOfBirth.Date == model.DateOfBirth.Date);

            return(result);
        }