示例#1
0
        public async Task <IActionResult> AddPatient([FromBody] PatientRequestDto patientRequestDto)
        {
            if (String.IsNullOrEmpty(patientRequestDto.StudyRequests[0].EstimatedEndTime))
            {
                patientRequestDto.StudyRequests[0].EstimatedEndTime = null;
            }
            var resultModel = new ServiceResultModel <Patient> {
                IsSuccess = false, Errors = new List <string>()
            };
            var patientExsists = _patientRepository.Any(p => p.PatientName == patientRequestDto.PatientName);

            if (patientExsists)
            {
                return(BadRequest("Patient already exsits"));
            }


            var newPatient = _patientRepository.Add(new Patient
            {
                PatientName  = patientRequestDto.PatientName,
                DOB          = patientRequestDto.DOB,
                PatientSexId = patientRequestDto.PatientSex,
                RoomId       = (int)patientRequestDto.RoomNameId,
            });


            var saved = (newPatient != null) ? await _unitOfWork.CommitAsync() : 0;

            var newDoctorPatient = _doctorPatientRepository.Add(new DoctorPatient {
                DoctorId = patientRequestDto.DoctorRequests[0].DoctorId, PatientId = newPatient.PatientId
            });
            var doctorPatientSaved = (newDoctorPatient != null) ? await _unitOfWork.CommitAsync() : 0;

            var newStudy = _studyRepository.Add(new Study {
                PatientId = newPatient.PatientId, StudyStatusId = patientRequestDto.StudyRequests[0].StudyStatusId, DoctorId = patientRequestDto.DoctorRequests[0].DoctorId, PlannedStartTime = DateTime.Now.ToShortDateString(), EstimatedEndTime = patientRequestDto.StudyRequests[0].EstimatedEndTime, Descriptions = patientRequestDto.StudyRequests[0].Descriptions
            });
            var savedStudy = (newStudy != null) ? await _unitOfWork.CommitAsync() : 0;

            var resultPatient = _patientRepository.GetById(newPatient.PatientId);

            if (saved > 0 && doctorPatientSaved > 0 && savedStudy > 0)
            {
                resultModel.IsSuccess = true;
                resultModel.Data      = resultPatient;
                return(Ok(resultModel));
            }

            return(Ok("No Patient Details found"));
        }
示例#2
0
 public void Handle(StudyCreatedEvent @event)
 {
     _repo.Add(@event.Study).Wait();
 }