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)));
            }
        }
        public void query_patient_fail()
        {
            Guid blogGuid = new Guid();

            Domain.Entities.Patient PatientList = patientService.SearchByKey(blogGuid).Result;

            Assert.Null(PatientList);
        }
        public void query_patient_corrected()
        {
            Guid blogGuid = new Guid("ca3aa909-c935-4c9f-b304-7d744dbe050e");

            Domain.Entities.Patient PatientList = patientService.SearchByKey(blogGuid).Result;

            Assert.Equal("nome teste criar", PatientList.Name);
        }
Exemplo n.º 4
0
        private IList <PatientViewModelList> patientListCollection(Domain.Entities.Patient patient)
        {
            IList <Domain.Entities.Patient> Patients = new List <Domain.Entities.Patient>();

            Patients.Add(patient);

            return(this.patientListCollection(Patients));
        }
Exemplo n.º 5
0
            private static Patient ToPatientViewModel(Domain.Entities.Patient patient)
            {
                var patientAddress = new Address(patient.Address.Street, patient.Address.City,
                                                 patient.Address.State, patient.Address.ZipCode);

                return(new Patient(patient.PatientId, patient.Name, patient.DateOfBirth,
                                   patient.Gender, patientAddress, patient.MobileNumber, patient.HospitalId));
            }
Exemplo n.º 6
0
        public void RepositoryReal_update_patient_corrected()
        {
            PatientTests patientTests = new PatientTests();

            //Domain.Entities.Patient patientToBeUpdate = patientTests.loadPatientFromFile("patientFullCreate.json","","");
            Domain.Entities.Patient patientToBeUpdate = patientTests.loadPatientFromFile("PatientFull_real_updated_fromDB.json", "", "");

            var patientUpdated = this.patientService.UpdatePatient(patientToBeUpdate).Result;

            Assert.Equal(1, patientUpdated);
        }
Exemplo n.º 7
0
        public void update_name_corrected()
        {
            PatientTests patientTests = new PatientTests();

            Domain.Entities.Patient patientFound = this.patientService.SearchByKey(new Guid("08c9895d-d2ff-4720-8d09-5e98a0fe928f")).Result;

            patientFound.SetNamePhone("name 110 _", patientFound.Phone);

            var patientUpdated = this.patientService.UpdatePatient(patientFound).Result;

            Assert.Equal(1, patientUpdated);
        }
Exemplo n.º 8
0
        public void RepositoryReal_Search_by_key_patient_corrected()
        {
            PatientTests patientTests = new PatientTests();

            Domain.Entities.Patient patientToBeSearched = patientTests.loadPatientFromFile("PatientFull_real_updated_fromDB.json", "", "");

            Domain.Entities.Patient patientFound = this.patientService.SearchByKey(patientToBeSearched.Key).Result;

            var patientSerialized = patientTests.SerializePatient(patientFound);

            Assert.Equal(patientToBeSearched.Key, patientFound.Key);
        }
Exemplo n.º 9
0
        public void update_name_already_used()
        {
            PatientTests patientTests = new PatientTests();

            Domain.Entities.Patient patientFound = this.patientService.SearchByKey(new Guid("08c9895d-d2ff-4720-8d09-5e98a0fe928f")).Result;

            patientFound.SetNamePhone("name 109", patientFound.Phone);

            var ex = Assert.Throws <Exception> (() => this.patientService.UpdatePatient(patientFound).Result);

            Assert.Contains("já existe registro com este nome", ex.Message);
        }
Exemplo n.º 10
0
        public void update_schedule_modified_startDate_ocuppied()
        {
            PatientTests patientTests = new PatientTests();

            Domain.Entities.Patient patientFound = this.patientService.SearchByKey(new Guid("08c9895d-d2ff-4720-8d09-5e98a0fe928f")).Result;
            patientFound.Schedules[0].SetStartdDate(new DateTime(2021, 12, 25, 22, 30, 00, DateTimeKind.Utc));
            //patientFound.Schedules[0].SetDuration(51);

            //var patientUpdated = this.patientService.UpdatePatient(patientFound).Result;
            var ex = Assert.Throws <Exception> (() => this.patientService.UpdatePatient(patientFound).Result);

            Assert.Contains("existe atendimento neste horário", ex.Message);
        }
Exemplo n.º 11
0
        public void update_corrected()
        {
            PatientTests patientTests = new PatientTests();

            Domain.Entities.Patient patientFound = this.patientService.SearchByKey(new Guid("eef2220b-160a-4547-b5b5-51746477cbef")).Result;

            patientFound.Schedules[0].SetStartdDate(new System.DateTime(2021, 12, 10, 13, 00, 0, DateTimeKind.Utc));
            patientFound.Schedules[0].SetDuration(40);


            var patientUpdated = this.patientService.UpdatePatient(patientFound).Result;

            Assert.Equal(1, patientUpdated);
        }
Exemplo n.º 12
0
        private void ValidationPatient(Domain.Entities.Patient patientTobeSaved, Domain.Entities.Patient?originalPatient)
        {
            PatientValidationContract patientValidationContract = new PatientValidationContract(patientTobeSaved);

            IList <Schedule> originalSchedules = originalPatient?.Schedules ?? new List <Schedule>();

            var schedulesIsValid = patientTobeSaved.SchedulesIsValid(originalSchedules, this.SearchScheduleDateTimeFree);

            if (!(schedulesIsValid && patientValidationContract.IsValid))
            {
                var mesagensError = patientValidationContract.Notifications.AllInvalidations() + patientTobeSaved.GetScheduleNotifications();
                throw new System.ArgumentException(mesagensError);
            }
        }
Exemplo n.º 13
0
        public Task <long> UpdatePatient(Domain.Entities.Patient patientToBeUpdated)
        {
            Domain.Entities.Patient patientFound = this.SearchByKey(patientToBeUpdated.Key).Result;

            string namePhoneChanged = this.VerifyNamePhoneChanged(patientToBeUpdated, patientFound);

            if (!string.IsNullOrEmpty(namePhoneChanged))
            {
                throw new System.ArgumentException(namePhoneChanged);
            }

            patientToBeUpdated.SetItensConstructor();
            this.ValidationPatient(patientToBeUpdated, patientFound);
            return(Task.FromResult(this.PatientRepository.Update(patientToBeUpdated).Result));
        }
Exemplo n.º 14
0
        public void Integration_update_patient_corrected()
        {
            PatientTests patientTests = new PatientTests();

            string dataToReplace = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd");

            Domain.Entities.Patient patientToBeUpdate = patientTests.loadPatientFromFile("PatientFull_real_updated_fromDB.json", "2021-05-01", dataToReplace);
            patientToBeUpdate.Schedules[2].SetKeyNull();

            var responseInfo = this.UpdatenResult(patientToBeUpdate);
            var resultado    = responseInfo.Content.ReadAsStringAsync().Result;

            var patientUpdateResult = JsonConvert.DeserializeObject <long>(resultado, settings);

            Assert.Equal(1, patientUpdateResult);
        }
Exemplo n.º 15
0
            public async Task <Guid> Handle(Command request, CancellationToken cancellationToken)
            {
                var existingPatient = await _appDbRepository.GetPatientByIdAsync(request.Id);

                if (existingPatient == null)
                {
                    throw new NotFoundException(nameof(Patient), request.Id);
                }

                var patientHospitalId = request.HospitalId;

                if (request.HospitalId != null)
                {
                    var hospital = await _appDbRepository.GetHospitalByIdAsync(request.HospitalId.Value);

                    if (hospital == null)
                    {
                        throw new NotFoundException(nameof(Patient), request.HospitalId);
                    }
                    patientHospitalId = hospital.HospitalId;
                }

                var patient = new Domain.Entities.Patient
                {
                    PatientId    = request.Id,
                    Name         = request.Name,
                    DateOfBirth  = request.DateOfBirth,
                    Gender       = (GenderType)request.Gender,
                    MobileNumber = request.MobileNumber,
                    HospitalId   = patientHospitalId,
                    Address      = new Domain.Entities.Address
                    {
                        Street  = request.Address.Street,
                        City    = request.Address.City,
                        State   = request.Address.State,
                        ZipCode = request.Address.ZipCode
                    }
                };
                await _appDbRepository.EditPatientByIdAsync(request.Id, patient);

                _notificationService.Send(new Message
                {
                    Text    = $"Patient updated with the id {request.Id}",
                    Payload = patient
                });
                return(request.Id);
            }
Exemplo n.º 16
0
        public void update_schedule_changed_corrected()
        {
            PatientTests patientTests = new PatientTests();

            Domain.Entities.Patient patientFound = this.patientService.SearchByKey(new Guid("08c9895d-d2ff-4720-8d09-5e98a0fe928f")).Result;


            DateTime startdDate = patientFound.Schedules[0].StartdDate.AddMinutes(5);

            patientFound.Schedules[0].SetStartdDate(startdDate);
            //patientFound.Schedules[0].SetDuration(patientFound.Schedules[0].Duration + 1);


            var patientUpdated = this.patientService.UpdatePatient(patientFound).Result;

            Assert.Equal(1, patientUpdated);
        }
Exemplo n.º 17
0
        public void Integration_update_patient_fail(string name, string phone, string messageError, HttpStatusCode errorMethod)
        {
            PatientTests patientTests = new PatientTests();

            Domain.Entities.Patient patientToBeUpdate = patientTests.loadPatientFromFile("PatientFull_real_updated_fromDB.json", "", "");

            if (phone == "11999999999")
            {
                Domain.Entities.Schedule newSchedule = new Domain.Entities.Schedule(DateTime.Now.AddDays(-1), false, "", false, 50, new DateTime(), false, "--Nenhum--", "--Nenhum--", 0, 0);
                newSchedule.SetKeyNull();
                patientToBeUpdate.Schedules.Add(newSchedule);
            }
            else if (phone == "11888888888")
            {
                //schedule já existente em outro registro
                Domain.Entities.Schedule newSchedule = new Domain.Entities.Schedule(new DateTime(2021, 5, 10, 18, 30, 0, DateTimeKind.Utc), false, "", false, 50, new DateTime(), false, "--Nenhum--", "--Nenhum--", 0, 0);
                newSchedule.SetKeyNull();
                patientToBeUpdate.Schedules.Add(newSchedule);
            }
            else if (phone == "11777777777")
            {
                //tenta alterar um schedule já existente em horario já utilizado por outro registro
                Domain.Entities.Schedule newSchedule = new Domain.Entities.Schedule(new DateTime(2021, 5, 20, 18, 40, 0, DateTimeKind.Utc), false, "", false, 50, new DateTime(), false, "--Nenhum--", "--Nenhum--", 0, 0);
                patientToBeUpdate.Schedules.Add(newSchedule);
            }
            else if (phone == "11666666666")
            {
                //tenta alterar um schedule já existente em horario já utilizado por outro registro
                Domain.Entities.Schedule newSchedule = new Domain.Entities.Schedule(new DateTime(2021, 5, 20, 18, 0, 0, DateTimeKind.Utc), false, "", false, 50, new DateTime(), false, "--Nenhum--", "--Nenhum--", 0, 0);
                patientToBeUpdate.Schedules.Add(newSchedule);
            }
            else
            {
                patientToBeUpdate.SetNamePhone(name, phone);
                // .Name = name;
                //patientToBeUpdate.Phone = phone;
            }

            var responseInfo = this.UpdatenResult(patientToBeUpdate);

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

            Assert.Equal(errorMethod, responseInfo.StatusCode);
            Assert.True(messageResult.ToLower().Contains(messageError));
        }
Exemplo n.º 18
0
        public static Mock <IPatientRepository> FakePatientRepository()
        {
            Massoterapia.Domain.Tests.PatientTests patientTests = new Domain.Tests.PatientTests();


            Domain.Entities.Patient patientCreatedFakefromDB = patientTests.loadPatientFromFile("patientFull_Create_fromDB.json", "", "");
            Domain.Entities.Patient patientFakefromDB        = patientTests.loadPatientFromFile("patientFull_fromDB.json", "", "");

            var patientViewModel = configurations.GetUserInputModelCriation();

            Domain.Entities.Patient patientTobeSaved = new Domain.Entities.Patient(
                patientViewModel.Name,
                patientViewModel.Phone,
                configurations.GetSchedule(patientViewModel.ScheduleData.StartdDate, 50)
                );

            mockPatientRepository.Setup(repo => repo.Insert(It.IsAny <Domain.Entities.Patient>())).ReturnsAsync(patientCreatedFakefromDB);

            IList <Domain.Entities.Patient> PatientList = new List <Domain.Entities.Patient>();

            patientFakefromDB.SetNamePhone("usuario", "11998877666");
            PatientList.Add(patientFakefromDB);

            mockPatientRepository.Setup(repo => repo.QueryByNameOrPhone("usuario", "11998877666")).ReturnsAsync(PatientList);

            List <DateTime> dateRange = new List <DateTime>();

            dateRange.Add(new DateTime(2021, 05, 11, 09, 10, 0));
            dateRange.Add(new DateTime(2021, 05, 11, 10, 50, 0));

            mockPatientRepository.Setup(repo => repo.QueryLikeNamePhoneScheduledateRange(null, null, dateRange)).ReturnsAsync(PatientList);

            Guid blogGuid = new Guid("ca3aa909-c935-4c9f-b304-7d744dbe050e");

            mockPatientRepository.Setup(repo => repo.Query(blogGuid)).ReturnsAsync(patientTobeSaved);


            return(mockPatientRepository);
        }
Exemplo n.º 19
0
        public void Integration_update_patient_corrected_with_schedule_altered()
        {
            PatientTests patientTests = new PatientTests();

            string dataToReplace = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd");

            Domain.Entities.Patient patientToBeUpdate = patientTests.loadPatientFromFile("PatientFull_real_updated_fromDB.json", "2021-05-01", dataToReplace);
            patientToBeUpdate.Schedules[2].SetKeyNull();

            var responseInfo0 = this.UpdatenResult(patientToBeUpdate);


            //testa o paciente ja existente, tentando alterar o horario do schedule para 20 min depois
            string dataToReplace1 = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + ":15:20";

            Domain.Entities.Patient patientToBeUpdate1 = patientTests.loadPatientFromFile("PatientFull_real_updated_fromDB.json", "2021-05-01:15:00", dataToReplace);

            var responseInfo = this.UpdatenResult(patientToBeUpdate);

            var patientUpdateResult = JsonConvert.DeserializeObject <long>(responseInfo.Content.ReadAsStringAsync().Result, settings);

            Assert.Equal(1, patientUpdateResult);
        }
Exemplo n.º 20
0
            public async Task <Guid> Handle(Command request, CancellationToken cancellationToken)
            {
                var existingPatient = await _appDbRepository.GetPatientIdByMobileNumberAsync(request.MobileNumber);

                if (existingPatient != null)
                {
                    throw new SystemException();
                }

                var patientHospitalId = await _appDbRepository.GetHospitalIdByZipCode(request.Address.ZipCode);

                var patientId = Guid.NewGuid();
                var patient   = new Patient
                {
                    PatientId    = patientId,
                    Name         = request.Name,
                    DateOfBirth  = request.DateOfBirth,
                    Gender       = (GenderType)request.Gender,
                    MobileNumber = request.MobileNumber,
                    HospitalId   = patientHospitalId,
                    Address      = new Domain.Entities.Address
                    {
                        Street  = request.Address.Street,
                        City    = request.Address.City,
                        State   = request.Address.State,
                        ZipCode = request.Address.ZipCode
                    }
                };
                await _appDbRepository.AddPatientAsync(patient);

                _notificationService.Send(new Message
                {
                    Text    = $"Patient created with the id {patientId}",
                    Payload = patient
                });
                return(patientId);
            }
Exemplo n.º 21
0
        private string VerifyNamePhoneChanged(Domain.Entities.Patient patientToBeUpdated, Domain.Entities.Patient patientFound)
        {
            string result = "";

            if (patientToBeUpdated.Name != patientFound.Name || patientToBeUpdated.Phone != patientFound.Phone)
            {
                PatientInputModel patientTobeSearched = new PatientInputModel()
                {
                    Name  = patientToBeUpdated.Name,
                    Phone = patientToBeUpdated.Phone
                };

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

                patientSeached.ToList().ForEach(_patientViewModelList => {
                    if (_patientViewModelList.Key != patientToBeUpdated.Key)
                    {
                        result = $"já existe registro com este nome: {_patientViewModelList.Name} ou com este telefone: {_patientViewModelList.Phone}";
                    }
                }
                                                );
            }
            return(result);
        }
Exemplo n.º 22
0
 public Task <Domain.Entities.Patient> SearchByKey(Guid key)
 {
     Domain.Entities.Patient PatientFromDatabase = this.PatientRepository.Query(key).Result;
     return(Task.FromResult(PatientFromDatabase));
 }