public override async Task <ActionResult <CreateAppointmentResponse> > HandleAsync(CreateAppointmentRequest request, CancellationToken cancellationToken)
        {
            var response = new CreateAppointmentResponse(request.CorrelationId());

            var spec     = new ScheduleByIdWithAppointmentsSpec(request.ScheduleId); // TODO: Just get that day's appointments
            var schedule = await _scheduleRepository.GetBySpecAsync(spec);

            var appointmentType = await _appointmentTypeRepository.GetByIdAsync(request.AppointmentTypeId);

            var appointmentStart = request.DateOfAppointment.ToLocalTime();
            var timeRange        = new DateTimeRange(appointmentStart, TimeSpan.FromMinutes(appointmentType.Duration));

            var newAppointment = new Appointment(request.AppointmentTypeId, request.ScheduleId, request.ClientId, request.SelectedDoctor, request.PatientId, request.RoomId, timeRange, request.Details);

            schedule.AddNewAppointment(newAppointment);

            _logger.LogDebug($"Adding appointment to schedule. Total appointments: {schedule.Appointments.Count()}");

            await _scheduleRepository.UpdateAsync(schedule);

            _logger.LogInformation($"Appointment created for patient {request.PatientId} with Id {newAppointment.Id}");

            var dto = _mapper.Map <AppointmentDto>(newAppointment);

            _logger.LogInformation(dto.ToString());
            response.Appointment = dto;

            return(Ok(response));
        }
Пример #2
0
        public IHttpActionResult Create(CreateAppointmentRequest request)
        {
            var service     = ExchangeServer.Open();
            var appointment = new Appointment(service);

            // Set the properties on the appointment object to create the appointment.
            appointment.Subject = request.Subject;
            appointment.Body    = request.Body;
            appointment.Start   = DateTime.Parse(request.Start);
            //appointment.StartTimeZone = TimeZoneInfo.Local;
            appointment.End = DateTime.Parse(request.End);
            //appointment.EndTimeZone = TimeZoneInfo.Local;
            appointment.Location = request.Location;
            //appointment.ReminderDueBy = DateTime.Now;

            foreach (var email in request.Recipients)
            {
                appointment.RequiredAttendees.Add(email);
            }

            // Save the appointment to your calendar.
            appointment.Save(SendInvitationsMode.SendOnlyToAll);

            // Verify that the appointment was created by using the appointment's item ID.
            Item item = Item.Bind(service, appointment.Id, new PropertySet(ItemSchema.Subject));

            var response = new CreateAppointmentResponse
            {
                Message   = "Appointment created: " + item.Subject,
                AppointId = appointment.Id.ToString()
            };

            return(Ok(response));
        }
Пример #3
0
        public override async Task <ActionResult <CreateAppointmentResponse> > HandleAsync(CreateAppointmentRequest request, CancellationToken cancellationToken)
        {
            var response = new CreateAppointmentResponse(request.CorrelationId());

            var appointmentType = await _repository.GetByIdAsync <AppointmentType, int>(request.AppointmentTypeId);

            var newAppointment = Appointment.Create(request.ScheduleId, request.ClientId, request.PatientId, request.RoomId, request.DateOfAppointment, request.DateOfAppointment.AddMinutes(appointmentType.Duration), request.AppointmentTypeId, request.SelectedDoctor, request.Details);

            newAppointment = await _repository.AddAsync <Appointment, Guid>(newAppointment);

            _logger.LogInformation($"Appointment created for patient {request.PatientId} with Id {newAppointment.Id}");

            var dto = _mapper.Map <AppointmentDto>(newAppointment);

            _logger.LogInformation(dto.ToString());
            response.Appointment = dto;

            return(Ok(response));
        }
Пример #4
0
        public async Task <CreateAppointmentResponse> CreateAppointment(CreateAppointmentRequest request)
        {
            var response = new CreateAppointmentResponse();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(_url);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage resp = await client.PostAsJsonAsync("/api/appointments", request);

                if (resp.IsSuccessStatusCode)
                {
                    response = await resp.Content.ReadAsAsync <CreateAppointmentResponse>();

                    return(response);
                }
            }
            return(response);
        }
        public async Task CreateAppointment_ValidRequest_ShouldReturnCreatedAppointment()
        {
            // Arrange
            var employeeId = Guid.NewGuid().ToString();
            var startDate  = DateTime.UtcNow;
            var endDate    = startDate.AddHours(1);
            var subject    = Guid.NewGuid().ToString();

            var createAppointmentRequest = new CreateAppointmentRequest(employeeId, startDate, endDate, subject);

            var expectedAppointment = new CreateAppointmentResponse
            {
                EmployeeId = createAppointmentRequest.EmployeeId,
                StartDate  = createAppointmentRequest.StartDate,
                EndDate    = createAppointmentRequest.EndDate,
                Subject    = createAppointmentRequest.Subject,
            };

            var expectedResponseContent =
                new StringContent(JsonConvert.SerializeObject(expectedAppointment, this.fixture.JsonSerializerSettings));

            var expectedResponse = new HttpResponseMessage
            {
                Content = expectedResponseContent,
            };

            var appointmentApi = this.fixture.GetAppointmentApi(expectedResponse);

            var createAppointmentResponse = default(CreateAppointmentResponse);

            // Act
            Func <Task> act = async() => createAppointmentResponse = await appointmentApi.CreateAppointmentAsync(createAppointmentRequest);

            // Assert
            await act.Should().NotThrowAsync();

            createAppointmentResponse.Should().BeEquivalentTo(expectedAppointment);
        }