public async Task <IHttpActionResult> GetProgramSchedule( int customerId, Guid programId, [FromUri] ProgramScheduleRequestDto model = null ) { if (model == null) { model = new ProgramScheduleRequestDto(); } var result = await controllerHelper.GetProgramSchedule(customerId, programId, model); if (result == null) { return(Content( HttpStatusCode.NotFound, new ErrorResponseDto { Error = ErrorCode.InvalidRequest, Message = ErrorCode.InvalidRequest.Description(), Details = DeleteProgramStatus.NotFound.Description() } )); } return(Ok(result)); }
/// <summary> /// Generates list of program events in accordance with provided criteria. /// </summary> /// <param name="customerId"></param> /// <param name="programId"></param> /// <param name="model"></param> /// <returns></returns> public async Task <ProgramScheduleDto> GetProgramSchedule( int customerId, Guid programId, ProgramScheduleRequestDto model ) { var program = await programService.Get(customerId, programId); if (program == null) { return(null); } int startDay = model.StartDay ?? 1; int dayIndex = startDay; int endDay = program.ProgramElements.Max(pe => pe.ProgramDayElements.Max(pde => pde.Day)); if (model.EndDay.HasValue && model.EndDay.Value < endDay) { endDay = model.EndDay.Value; } DateTime startDateUtc = model.StartDateUtc ?? DateTime.UtcNow; DateTime dateIndex = DateTime.SpecifyKind(startDateUtc, DateTimeKind.Utc); var result = new List <ProgramScheduleEventDto>(); while (dayIndex <= endDay) { var dayElements = program.ProgramElements.Where(pe => pe.ProgramDayElements.Any(pde => pde.Day == dayIndex)).ToList(); if (dayElements.Any()) { var scheduleEvent = new ProgramScheduleEventDto(model, dayElements, dateIndex, dayIndex) { ProgramDay = dayIndex, Name = program.Name, EventTz = model.StartDateTz }; result.Add(scheduleEvent); } dateIndex = AddDays(dateIndex, model.StartDateTz, 1); dayIndex++; } return(new ProgramScheduleDto { ProgramEvents = result, EndDay = endDay, StartDay = startDay, ExpireMinutes = model.ExpireMinutes, ProgramId = programId, ProgramName = program.Name, StartDateUtc = startDateUtc }); }
/// <summary> /// Generates program schedule and creates events in calendar. /// </summary> /// <param name="customerId"></param> /// <param name="patientId"></param> /// <param name="programId"></param> /// <param name="calendarProgramId"></param> /// <param name="searchCriteria"></param> /// <param name="token"></param> /// <returns></returns> public async Task UpdateCalendarProgram(int customerId, Guid patientId, Guid programId, Guid calendarProgramId, ProgramScheduleRequestDto searchCriteria, string token) { await this.patientsDataProvider.DeleteCalendarProgram( customerId, patientId, calendarProgramId, token); await this.CreateCalendarProgram(customerId, patientId, programId, searchCriteria, token); }
/// <summary> /// Generates program schedule and creates events in calendar. /// </summary> /// <param name="customerId"></param> /// <param name="patientId"></param> /// <param name="programId"></param> /// <param name="searchCriteria"></param> /// <param name="token"></param> /// <returns></returns> public async Task CreateCalendarProgram(int customerId, Guid patientId, Guid programId, ProgramScheduleRequestDto searchCriteria, string token) { var programRequestDto = await this.healthLibraryDataProvider.GetProgramSchedule(customerId, programId, searchCriteria, token); await this.patientsDataProvider.CreateCalendarProgram(customerId, patientId, programRequestDto, token); }
/// <summary> /// Generates program schedule for calendar. /// </summary> /// <param name="customerId"></param> /// <param name="programId"></param> /// <param name="searchCriteria"></param> /// <param name="token"></param> /// <returns></returns> public async Task <CreateCalendarProgramRequestDto> GetProgramSchedule(int customerId, Guid programId, ProgramScheduleRequestDto searchCriteria, string token) { var url = string.Format("/api/{0}/programs/{1}/schedule", customerId, programId); return(await this.apiClient.SendRequestAsync <CreateCalendarProgramRequestDto>( url, searchCriteria, Method.GET, null, token)); }