private bool ShouldSendEmailReminderForDto(AssessmentReminderDto assessmentReminderDto, out DateTime reminderDate) { reminderDate = assessmentReminderDto.Start; var thresholdDate = GetThresholdDateForAssessmentReminder(reminderDate, assessmentReminderDto.ReminderUnit, assessmentReminderDto.ReminderTime); Logger.Info("reminderDate is {0}.", reminderDate); Logger.Info("thresholdDate is {0}.", thresholdDate); bool sendReminder = false; Logger.Info("ReminderRecurrence is {0}.", assessmentReminderDto.ReminderRecurrence); if (assessmentReminderDto.ReminderRecurrence == AssessmentReminderRecurrence.OneTime) { Logger.Info("ReminderRecurrence for OneTime is returning {0}.", DateTime.Now > thresholdDate && DateTime.Now > assessmentReminderDto.AlertSentDate); return(DateTime.Now > thresholdDate && DateTime.Now > assessmentReminderDto.AlertSentDate); } while (reminderDate < assessmentReminderDto.End && !sendReminder) { thresholdDate = GetThresholdDateForAssessmentReminder(reminderDate, assessmentReminderDto.ReminderUnit, assessmentReminderDto.ReminderTime); sendReminder = DateTime.Now > thresholdDate && (thresholdDate > assessmentReminderDto.AlertSentDate || assessmentReminderDto.AlertSentDate == null); reminderDate = AddDaysToReminderForRecurrence(reminderDate, assessmentReminderDto.ReminderRecurrence, sendReminder); } Logger.Info("ShouldSendEmailReminderForDto is returning {0}.", sendReminder); return(sendReminder); }
public async Task <ActionResult> Edit(AssessmentReminderDto assessmentReminder) { assessmentReminder.OrganizationKey = UserContext.Current.OrganizationKey.Value; assessmentReminder.CreatedByStaffKey = UserContext.Current.StaffKey.Value; var requestDispatcher = CreateAsyncRequestDispatcher(); requestDispatcher.Add(new UpdateAssessmentReminderRequest { AssessmentReminderDto = assessmentReminder, }); var response = await requestDispatcher.GetAsync <DtoResponse <AssessmentReminderDto> >(); if (response.DataTransferObject == null) { throw new HttpException(500, "Assessment Reminder cannot be saved."); } if (response.DataTransferObject.DataErrorInfoCollection.Any()) { return(new JsonResult { Data = new { error = true, errors = response.DataTransferObject.DataErrorInfoCollection } }); } return(new JsonResult { Data = new { sucess = true } }); }
/// <summary> /// Creates the specified patient key. /// </summary> /// <param name="patientKey">The patient key.</param> /// <param name="assessmentDefinitionKey">The assessment definition key.</param> /// <param name="workflowKey">The workflow key.</param> /// <param name="assessmentReminderKey">The assessment reminder key.</param> /// <param name="recurrenceKey">The recurrence key.</param> /// <returns> /// A <see cref="ActionResult" />. /// </returns> public async Task <ActionResult> Create( Guid patientKey, Guid assessmentDefinitionKey, Guid?workflowKey = null, Guid?assessmentReminderKey = null, Guid?recurrenceKey = null) { var requestDispatcher = CreateAsyncRequestDispatcher(); bool canSelfAdminister = false; if (assessmentReminderKey != null) { requestDispatcher.Add(new GetAssessmentReminderByKeyRequest { AssessmentReminderKey = recurrenceKey.GetValueOrDefault() }); var assessmentReminderResponse = await requestDispatcher.GetAsync <DtoResponse <AssessmentReminderDto> >(); canSelfAdminister = assessmentReminderResponse.DataTransferObject.ForSelfAdministration; } requestDispatcher.Clear(); requestDispatcher.Add( new CreateAssessmentRequest { AssessmentDefinitionKey = assessmentDefinitionKey, PatientKey = patientKey, WorkflowKey = workflowKey, ForSelfAdministration = canSelfAdminister }); var response = await requestDispatcher.GetAsync <CreateAssessmentResponse> (); if (assessmentReminderKey != null) { var reminderDto = new AssessmentReminderDto { OrganizationKey = UserContext.Current.OrganizationKey.Value, AssessmentInstanceKey = response.AssessmentInstanceKey, RecurrenceKey = recurrenceKey.Value }; requestDispatcher.Clear(); requestDispatcher.Add( new UpdateAssessmentReminderRequest { AssessmentReminderDto = reminderDto, AssessmentReminderKey = assessmentReminderKey.Value }); await requestDispatcher.GetAsync <DtoResponse <AssessmentReminderDto> > (); } return(RedirectToAction("Edit", new { key = response.AssessmentInstanceKey, patientKey })); }
private CalendarEventModel GetCalenderEventModelFromAssessmentReminderDto(AssessmentReminderDto reminderDto, DateTime date) { var reminderTitleDisplayLength = 50; return(new CalendarEventModel { Key = reminderDto.Key.ToString(), Title = string.Format("{0}: {1} for {2} {3}", reminderDto.Title.Length > reminderTitleDisplayLength ? reminderDto.Title.Substring(0, reminderTitleDisplayLength - 1) + "..." : reminderDto.Title, _resourcesManager.GetResourceManagerByName(reminderDto.AssessmentName).GetString(SharedStringNames.ResourceKeyPrefix + reminderDto.AssessmentCode), reminderDto.PatientFirstName, reminderDto.PatientLastName), Start = DateTimeToUnixTimestamp(date), AllDay = true, RecurrenceKey = reminderDto.RecurrenceKey.GetValueOrDefault().ToString() }); }
public async Task <ActionResult> Get(Guid key) { var requestDispatcher = CreateAsyncRequestDispatcher(); requestDispatcher.Add(new GetAssessmentReminderByKeyRequest { AssessmentReminderKey = key }); var response = await requestDispatcher.GetAsync <DtoResponse <AssessmentReminderDto> >(); var dto = response.DataTransferObject; ViewData.TemplateInfo.HtmlFieldPrefix = "assessmentReminder"; //note: matches the Edit action parameter name if (!dto.ForSelfAdministration && UserContext.Current.PatientKey != null) { dto = new AssessmentReminderDto(); ModelState.AddModelError("error", "You do not have access to this reminder."); } return(PartialView("~/Views/Shared/EditorTemplates/AssessmentReminderDto.cshtml", dto)); }
public async Task <ActionResult> Edit(AssessmentReminderDto assessmentReminder) { assessmentReminder.OrganizationKey = UserContext.Current.OrganizationKey.Value; assessmentReminder.CreatedByStaffKey = UserContext.Current.StaffKey.Value; var requestDispatcher = CreateAsyncRequestDispatcher(); requestDispatcher.Add(new UpdateAssessmentReminderRequest { AssessmentReminderDto = assessmentReminder, }); var response = await requestDispatcher.GetAsync <DtoResponse <AssessmentReminderDto> >(); var dto = response.DataTransferObject; return(new JsonResult { Data = new { success = true } }); }