public async Task <BaseResponse <Patient> > Handle(CreatePatientCommand request, CancellationToken cancellationToken) { var response = new BaseResponse <Patient> () { ReponseName = nameof(CreatePatientCommand), Content = new List <Patient> () { } }; var entity = _mapper.Map <Patient> (request); var newentity = await _patientRepository.AddAsync(entity); if (newentity == null) { response.Status = ResponseType.Error; response.Message = $"{nameof(Patient)} could not be created."; response.Content = null; } else { response.Status = ResponseType.Success; response.Message = $"{nameof(Patient)} created successfully."; response.Content.Add(newentity); } return(response); }
public async Task <IActionResult> RegisterAsync(PatientDto patientDto) { if (await patientRepository.GetAsync(patientDto.PeselNumber) != null) { return(new JsonResult(new ExceptionDto { Message = "Patient with given identity number already exists" }) { StatusCode = 422 }); } var patient = new Patient { FirstName = patientDto.FirstName, LastName = patientDto.LastName, PeselNumber = patientDto.PeselNumber, Address = new Address { Country = patientDto.Country, City = patientDto.City, BuildingNumber = patientDto.BuildingNumber, PostalCode = patientDto.PostalCode, Street = patientDto.Street } }; return(new JsonResult(await patientRepository.AddAsync(patient)) { StatusCode = 201 }); }
public async Task Add(Patient newPatient) { try { // local time zone offset as TimeSpan object // add the offsetTime to the datetime recieved as UTC newPatient.DateOfBirth = ChangeUtcDate(newPatient.DateOfBirth); var entity = await _patientRepository.AddAsync(newPatient); } catch (Exception exp) { Console.WriteLine(exp); } }
/// <summary> /// Handle Command /// </summary> /// <param name="request"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <RegisteredPatientDto> Handle(RegisterPatientCommand request, CancellationToken cancellationToken) { var patientToRegister = Patient.RegisterPatient(_patientEmailMustBeUniqueRuleValidator, request.FirstName, request.LastName, request.DateOfBirth, request.EmailAddress, request.TelephoneNumber, request.Address, request.PostCode); await _patientRepository.AddAsync(patientToRegister); // raise other events that use the generated Id await _mediator.Publish(RegisteredPatientEvent.Create(patientToRegister.Id, $"{request.FirstName} {request.LastName}", request.EmailAddress), cancellationToken); //MarkPatientAsWelcomedCommand await _mediator.Send(new MarkPatientAsWelcomedCommand(patientToRegister.Id)); return(new RegisteredPatientDto { PatientId = patientToRegister.Id }); }
public async Task <ActionResult <int> > Post([FromBody] PatientDto patient) { int recordId; try { recordId = await _patientRepository.AddAsync(patient); } catch (ArgumentException) { return(BadRequest()); } return(recordId); }
public async Task <string> RegisterAsync(Patient newPatient) { try { await _patientRepository.AddAsync(newPatient); //var patient = await AuthenticateAsync(newPatient.name, newPatient.password); return("register succeded"); } catch (Exception e) { Console.WriteLine(e); return(e.Message); } }
public async Task <IActionResult> Post([FromBody] PatientDto patientDto) { var cpfAlreadyRegistered = await _patientRepository.CpfIsAlreadyRegistered(patientDto.CPF); var model = _mapper.Map <PatientDto, Patient>(patientDto); if (cpfAlreadyRegistered) { return(BadRequest(new ErrorResponseModel("CPF já registrado"))); } await _patientRepository.AddAsync(model); return(Ok(model)); }
public async Task <PatientResponse> SaveAsync(Patient patient) { try { await _patientRepository.AddAsync(patient); await _unitOfWork.CompleteAsync(); return(new PatientResponse(patient)); } catch (Exception ex) { // Do some logging stuff return(new PatientResponse($"An error occurred when saving the patient: {ex.Message}")); } }
public async Task <int> Add(Patient patient) { return(await _patientRepository.AddAsync(patient)); }
public async Task Create(PatientDataModel request) { var hasPatient = await _patientRepository.GetAsync(request.Cpf); if (hasPatient is not null) { Notify("Já existe um paciente cadastrado com este cpf informado."); return; } if (request.BirthDate == DateTime.MinValue) { Notify("Data inválida"); return; } var userId = Guid.NewGuid(); if (request.CreateUser) { var user = new IdentityUser { UserName = request.Email, Email = request.Email }; userId = Guid.Parse(user.Id); var options = _userManager.Options.Password; var password = Utils.GeneratePassword(options.RequiredLength, options.RequireNonAlphanumeric, options.RequireDigit, options.RequireLowercase, options.RequireUppercase); var result = await _userManager.CreateAsync(user, password); if (result.Succeeded) { var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); await _userManager.ConfirmEmailAsync(user, code); await AddClaims(userId); _emailService.SendEmail(user.Email, "Credenciais de Acesso - SisOdonto", "Credenciais", $"Usuário: {user.Email} <br> Senha: {password}"); } else { Notify("Erro ao criar usuário."); return; } } var patient = new Patient(userId, request.BirthDate, request.Cep, request.City, request.Complement, request.Cpf.Replace(".", "").Replace("-", ""), request.District, request.Email, request.Name, request.Number, request.State, request.HealthInsuranceId, request.Street, request.MaritalStatus, request.Gender, request.Occupation, request.Telephone.Replace("(", "").Replace(")", "").Replace("-", "").Trim(), request.Cellular.Replace("(", "").Replace(")", "").Replace("-", "").Trim()); if (patient.IsValid()) { await _patientRepository.AddAsync(patient); } else { var userManager = await _userManager.FindByIdAsync(userId.ToString()); if (userManager is not null) { await _userManager.DeleteAsync(userManager); } Notify(patient.ValidationResult); return; } if (await CommitAsync() is false) { Notify("Erro ao salvar dados."); var userManager = await _userManager.FindByIdAsync(userId.ToString()); if (userManager is not null) { await _userManager.DeleteAsync(userManager); } } }
public async Task AddPatient([FromBody] Patient patient) { await _patientRepository.AddAsync(patient); await _unitOfWork.SaveChangesAsync(); }
public async Task <PatientDTO> Handle(CreatePatientCommand request, CancellationToken cancellationToken) { bool tableInsertStatus; try { _patient = await _patientRepository.AddAsync(request.PatientDTO); using (EventProducer eventProducer = _eventStore.CreateEventProducer()) { EventData eventData = eventProducer.CreateEventData(_patient, "Patient-Creation-Pending"); eventProducer.SendEvent($"Patient-{_patient.ID}", eventData); } tableInsertStatus = true; } catch (Exception) { tableInsertStatus = false; } if (tableInsertStatus == true) { try { PatientMessage patientMessage = new PatientMessage("PatientCreated", _patient); var message = await _client.SendObjectMessageAsync("EmailQueue", patientMessage); using (EventProducer eventProducer = _eventStore.CreateEventProducer()) { EventData eventData = eventProducer.CreateEventData(message, "PatientCreatedConfirmation-Sent"); eventProducer.SendEvent($"AMQMessages-Patient-{_patient.ID}", eventData); } } catch (Exception) { await _patientRepository.DeleteAsync(_patient.ID); using (EventProducer eventProducer = _eventStore.CreateEventProducer()) { EventData eventData = eventProducer.CreateEventData(_patient, "Patient-Creation-Rollback"); eventProducer.SendEvent($"Patient-{_patient.ID}", eventData); } tableInsertStatus = false; } } using (EventConsumer eventConsumer = _eventStore.CreateEventConsumer($"AMQMessages-Patient-{_patient.ID}", "EmailCheck")) { bool eventFound = false; while (eventFound == false) { var events = await eventConsumer.ReadStreamEventsForwardAsync(); if (eventConsumer.FindEventType(events, "EmailConfirmation-Sent")) { eventFound = true; _workerSucceeded = true; } else if (eventConsumer.FindEventType(events, "EmailConfirmation-Failed")) { eventFound = true; _workerSucceeded = false; } } } if (_workerSucceeded == false) { await _patientRepository.DeleteAsync(_patient.ID); using (EventProducer eventProducer = _eventStore.CreateEventProducer()) { EventData eventData = eventProducer.CreateEventData(_patient, "Patient-Creation-Rollback"); eventProducer.SendEvent($"Patient-{_patient.ID}", eventData); } tableInsertStatus = false; } if (tableInsertStatus == false) { return(null); } using (EventProducer eventProducer = _eventStore.CreateEventProducer()) { EventData eventData = eventProducer.CreateEventData(_patient, "Patient-Creation-Committed"); eventProducer.SendEvent($"Patient-{_patient.ID}", eventData); } return(_patient); }