public ServiceResponse <bool> Create(PatientTests patient, int appointmentId) { var now = DateTime.UtcNow; var appointment = _db.Appointment.Find(appointmentId); if (appointment != null) { try { var tests = new PatientTests { IsBloodPressure = patient.IsBloodPressure, IsCancer = patient.IsCancer, IsHIV = patient.IsHIV, Prescription = patient.Prescription, IsSugarDiabetes = patient.IsSugarDiabetes, NextAppointmentDate = patient.NextAppointmentDate, CreatedOn = now, UpdatedOn = now, AppointmentId = appointment.Id }; _db.PatientTests.Add(tests); _db.SaveChanges(); return(new ServiceResponse <bool> { IsSuccess = true, Message = "Success!", Time = now, Data = true }); } catch (Exception e) { return(new ServiceResponse <bool> { IsSuccess = false, Message = e.StackTrace, Time = now, Data = false }); } } else { return(new ServiceResponse <bool> { Data = false, Message = "Could not find Appointment with that Id", IsSuccess = false, Time = now }); } }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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)); }
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); }
public ActionResult Create([FromBody] PatientTests tests, int appointmentId) => Ok(_diagnosis.Create(tests, appointmentId));