public async Task <Guid> Handle(Query request, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(request.MobileNumber)) { throw new ArgumentNullException(); } var patient = await _appDbRepository.GetPatientIdByMobileNumberAsync(request.MobileNumber); if (patient == null) { throw new UnauthorizedAccessException(); } return(patient.PatientId); }
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); }