public async Task CreateAppointmentAsync(CreateAppointmentRequestDto request) { var doctor = await _doctorService.GetDoctorAsync(request.DoctorId); if (doctor == null) { throw new InvalidDoctorIdException(); } var appointmentSet = _dataService.GetSet <Data.Models.Appointment.Appointment>(); var collidingAppointment = await appointmentSet .FirstOrDefaultAsync(x => !x.IsCancelled && x.Date.Day == request.Date.Day && x.Date.Hour == request.Date.Hour && x.Date.Minute == request.Date.Minute); if (collidingAppointment != null) { throw new CollidingAppointmentException( $"Cannot create an appointment for time: {request.Date} as it's already taken!"); } var newAppointment = new Data.Models.Appointment.Appointment { Doctor = doctor, Date = request.Date, UserId = request.UserId }; await appointmentSet.AddAsync(newAppointment); await _dataService.SaveDbAsync(); }
public async Task <IActionResult> CreateAppointmentAsync([FromBody] CreateAppointmentRequestDto requestDto) { var doctorModel = await new DoctorBiz().GetAsync(requestDto.DoctorGuid); if (doctorModel == null) { return(Failed(ErrorCode.UserData, "未查询到此医生")); } if (!doctorModel.Enable || string.Equals(doctorModel.Status, StatusEnum.Draft.ToString(), StringComparison.OrdinalIgnoreCase)) { return(Failed(ErrorCode.UserData, "未查询到此医生")); } var scheduleModel = await new DoctorScheduleBiz().GetAsync(requestDto.ScheduleGuid); if (scheduleModel == null || !scheduleModel.Enable) { return(Failed(ErrorCode.UserData, "未查询到此排班信息")); } var userModel = new UserBiz().GetUserByPhone(requestDto.Phone); if (userModel == null) { return(Failed(ErrorCode.UserData, "通过手机号未查询到用户,请注册")); } var doctorWorkshiftDetailModel = await new DoctorWorkshiftDetailBiz().GetAsync(scheduleModel.WorkshiftDetailGuid); var appointmentTime = Convert.ToDateTime($"{scheduleModel.ScheduleDate.ToString("yyyy-MM-dd")} {doctorWorkshiftDetailModel.StartTime.ToString()}"); var appointmentEndTime = Convert.ToDateTime($"{scheduleModel.ScheduleDate.ToString("yyyy-MM-dd")} {doctorWorkshiftDetailModel.EndTime.ToString()}"); if (DateTime.Now >= appointmentEndTime) { return(Failed(ErrorCode.UserData, "当前时间不可大于就诊截止时间,请重新挂号")); } var model = new DoctorAppointmentModel { AppointmentGuid = Guid.NewGuid().ToString("N"), HospitalGuid = doctorModel.HospitalGuid, UserGuid = userModel.UserGuid, AppointmentNo = "", ScheduleGuid = requestDto.ScheduleGuid, DoctorGuid = requestDto.DoctorGuid, OfficeGuid = doctorModel.OfficeGuid, AppointmentTime = appointmentTime, AppointmentDeadline = appointmentEndTime, PatientGuid = null, PatientName = requestDto.PatientName, PatientPhone = requestDto.Phone, PatientGender = requestDto.PatientGender.ToString(), PatientBirthday = requestDto.PatientBirthday, PatientCardno = requestDto.PatientCardNo, Status = AppointmentStatusEnum.Waiting.ToString(), CreatedBy = UserID, LastUpdatedBy = UserID, OrgGuid = string.Empty }; var result = await new DoctorAppointmentBiz().CreateAppointmentAsync(model, doctorWorkshiftDetailModel.AppointmentNoPrefix, true); return(result ? Success() : Failed(ErrorCode.UserData, "挂号失败")); }
public async Task <IActionResult> CreateAppointmentAsync( [FromBody] CreateAppointmentRequestDto createAppointmentRequestDto, CancellationToken token = default) { try { var validationResult = await _createAppointmentRequestDtoValidator.ValidateAsync(createAppointmentRequestDto, token); if (!validationResult.IsValid) { return(new BadRequestObjectResult(validationResult.Errors.ToValidationErrors())); } var appointmentServiceObject = Mapper.Map <AppointmentServiceObject>(createAppointmentRequestDto); var serviceResponse = await _appointmentService.CreateAppointmentAsync(appointmentServiceObject, token); return(new CreatedResult(string.Empty, Mapper.Map <CreateAppointmentResponseDto>(serviceResponse))); } catch (BadRequestException e) { return(new BadRequestObjectResult(e.Error)); } }