示例#1
0
        public async Task <RegisterPatientResponse> RegisterPatientAsync(RegisterPatientRequest data,
                                                                         CancellationToken cancellationToken)
        {
            var existedUsers = await _patientService.FindPatientsByPersonalIdAsync(data.PersonalId, cancellationToken);

            if (existedUsers.Any())
            {
                return(RegisterPatientResponse.PersonalIdAlreadyExists);
            }

            var patient = new Patient
            {
                FirstName  = data.FirstName,
                Patronymic = data.MiddleName,
                LastName   = data.LastName,
                PersonalId = data.PersonalId,
                BirthDate  = data.BirthDate,
            };

            await _patientService.AddPatientAsync(patient, cancellationToken);

            return(new RegisterPatientResponse
            {
                Guid = patient.Guid,
                Status = RegisterPatientStatus.Ok,
            });
        }
示例#2
0
        public async Task <PatientIdentifierDto> Handle(AddPatientCommand message, CancellationToken cancellationToken)
        {
            await CheckIfPatientIsUniqueAsync(message.Attributes);
            await ValidateCommandModelAsync(message.MeddraTermId, message.CohortGroupId, message.EncounterTypeId);

            var patientDetail = await PreparePatientDetailAsync(message);

            if (!patientDetail.IsValid())
            {
                patientDetail.InvalidAttributes.ForEach(element => throw new DomainException(element));
            }

            var id = await _patientService.AddPatientAsync(patientDetail);

            await _unitOfWork.CompleteAsync();

            _logger.LogInformation($"----- Patient {message.LastName} created");

            var mappedPatient = await GetPatientAsync <PatientIdentifierDto>(id);

            if (mappedPatient == null)
            {
                throw new KeyNotFoundException("Unable to locate newly added patient");
            }

            return(CreateLinks(mappedPatient));
        }
示例#3
0
        public async Task AddRandomPatientAsync(CancellationToken cancellationToken)
        {
            var rand  = new Random();
            var chars = "qazwsxedcrfvtgbyhnujmikolp";

            string generateName()
            {
                return(new string(Enumerable.Range(0, rand.Next(5) + 3).Select(x => chars[rand.Next(chars.Length - 1)]).ToArray()));
            };
            await _patientService.AddPatientAsync(new Patient()
            {
                FirstName = generateName(), LastName = generateName(), PersonalId = Guid.NewGuid().ToString(), BirthDate = DateTime.Now
            }, cancellationToken);
        }
示例#4
0
        public async Task <ActionResult <PatientDTO> > PostPatient([FromBody] PatientAddDTO request)
        {
            var person = _mapper.Map <PatientAddDTO, Patient>(request);

            var successful = await _PatientsService.AddPatientAsync(person);

            if (!successful)
            {
                return(BadRequest("No se pudo agregar al paciente."));
            }

            var patientDTO = _mapper.Map <Patient, PatientDTO>(person);

            return(await GetPatient(patientDTO.DNI));
        }
示例#5
0
        public async Task <IActionResult> Add(PatientModel _patient)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }

            var successful = await _patientService.AddPatientAsync(_patient);

            if (!successful)
            {
                return(BadRequest("Could not Add Patient"));
            }

            return(RedirectToAction("Index"));
        }
示例#6
0
        public async Task ProcessFormForCreationOrUpdateAsync()
        {
            if (_validationErrors.Count > 0)
            {
                throw new Exception("Unable to process form as there are validation errors");
            }
            if (_patientDetailForCreation == null && _patientDetailForUpdate == null)
            {
                throw new Exception("Unable to process form as patient detail is not prepared");
            }

            if (_patientDetailForCreation != null)
            {
                await _patientService.AddPatientAsync(_patientDetailForCreation);
            }
            if (_patientDetailForUpdate != null)
            {
                await _patientService.UpdatePatientAsync(_patientDetailForUpdate);
            }
        }
示例#7
0
        public async Task <IActionResult> Post(AddPatientRequest request)
        {
            var result = await _patientService.AddPatientAsync(request);

            return(CreatedAtAction(nameof(GetById), new { id = result.Id }, null));
        }