protected override void Handle(UpdateAssessmentReminderRequest request, DtoResponse <AssessmentReminderDto> response)
 {
     if (request.AssessmentReminderKey == Guid.Empty)
     {
         var dto = request.AssessmentReminderDto;
         var assessmentReminder = _assessmentReminderRepository.GetByKey(dto.Key);
         if (assessmentReminder != null)
         {
             if (dto.PatientKey.HasValue && assessmentReminder.PatientKey != dto.PatientKey.Value)
             {
                 assessmentReminder.RevisePatientKey(dto.PatientKey.Value);
             }
             if (dto.CreatedByStaffKey.HasValue && assessmentReminder.CreatedByStaffKey != dto.CreatedByStaffKey.Value)
             {
                 assessmentReminder.ReviseCreatedbyStaffKey(dto.CreatedByStaffKey.Value);
             }
             if (assessmentReminder.Title != dto.Title)
             {
                 assessmentReminder.ReviseTitle(dto.Title);
             }
             if (assessmentReminder.Start.Date != dto.Start.Date)
             {
                 assessmentReminder.ReviseStart(dto.Start);
             }
             if (dto.AssessmentDefinitionKey.HasValue && assessmentReminder.AssessmentDefinitionKey != dto.AssessmentDefinitionKey.Value)
             {
                 assessmentReminder.ReviseAssessmentDefinitionKey(dto.AssessmentDefinitionKey.Value);
             }
             if (dto.ReminderTime > 0)
             {
                 assessmentReminder.ReviseReminder(dto.ReminderTime, dto.ReminderUnit, string.IsNullOrWhiteSpace(dto.SendToEmail) ? null : new Email(dto.SendToEmail));
             }
             if (dto.ForSelfAdministration)
             {
                 assessmentReminder.AllowSelfAdministration();
             }
             var dto2 = Mapper.Map <AssessmentReminder, AssessmentReminderDto>(assessmentReminder);
             response.DataTransferObject = dto2;
         }
     }
     else
     {
         var assessmentReminder = _assessmentReminderRepository.GetByKey(request.AssessmentReminderKey);
         if (assessmentReminder != null)
         {
             assessmentReminder.ReviseStart(assessmentReminder.Start.AddDays(request.DayDelta));
             var dto2 = Mapper.Map <AssessmentReminder, AssessmentReminderDto>(assessmentReminder);
             response.DataTransferObject = dto2;
         }
     }
 }
Beispiel #2
0
        protected override void Handle(AcknowledgeAssessmentReminderRequest request, DtoResponse <AssessmentReminderDto> response)
        {
            var assessmentReminder = _assessmentReminderRepository.GetByKey(request.Key);

            if (assessmentReminder != null)
            {
                assessmentReminder.Acknowledge();
                var dto2 = Mapper.Map <AssessmentReminder, AssessmentReminderDto>(assessmentReminder);
                response.DataTransferObject = dto2;
            }
        }
        protected override void Handle(CancelAssessmentReminderRequest request, DtoResponse <AssessmentReminderDto> response)
        {
            var assessmentReminder = _assessmentReminderRepository.GetByKey(request.AssessmentReminderKey);

            if (assessmentReminder != null)
            {
                assessmentReminder.Cancel();
                var dto = Mapper.Map <AssessmentReminder, AssessmentReminderDto>(assessmentReminder);
                response.DataTransferObject = dto;
            }
        }
Beispiel #4
0
        public void Execute(IJobExecutionContext context)
        {
            Logger.Info("Job executed at {0} ***", DateTime.Now);

            try
            {
                using (var connection = IoC.CurrentContainer.Resolve <IDbConnectionFactory>().CreateConnection())
                {
                    var reminders = connection.Query <AssessmentReminderDto>(
                        @"SELECT [AssessmentReminderKey]  AS 'Key' 
                          ,[PatientKey]
                          ,[PatientFirstName]
                          ,[PatientLastName]
                          ,[CreatedByStaffKey]
                          ,[AssessmentName]
                          ,[Title]
                          ,[Start]
                          ,[SendToEmail]                            
                        FROM MessageModule.AssessmentReminder 
                        WHERE AlertSentDate IS NULL 
                            AND SendToEmail IS NOT NULL 
                            AND Status = 'Default' 
                            AND GetDate() >= DATEADD(day, -ReminderDays, Start) 
                            AND GetDate() <= Start").ToList();

                    Logger.Info("{0} reminders retrieved.", reminders.Count);
                    foreach (var assessmentReminderDto in reminders)
                    {
                        var body = string.Format(AlertTemplate, assessmentReminderDto.Title, assessmentReminderDto.Start.ToString("D"));
                        try
                        {
                            SendEmail(body, assessmentReminderDto.SendToEmail);
                            var assessmentReminder = _assessmentReminderRepository.GetByKey(assessmentReminderDto.Key);
                            assessmentReminder.ReviseAlertSentDate(DateTime.Now);
                        }
                        catch (Exception ex)
                        {
                            Logger.Error("Sending email alert failed.", ex.Message);
                        }
                    }
                    var unitOfWorkProvider = IoC.CurrentContainer.Resolve <IUnitOfWorkProvider>();
                    unitOfWorkProvider.GetCurrentUnitOfWork().Commit();
                }
            }
            catch (Exception ex)
            {
                Logger.ErrorException(ex.Message, ex);
                if (ex.InnerException != null)
                {
                    Logger.ErrorException("innerException", ex.InnerException);
                }
            }
        }
Beispiel #5
0
        protected override void Handle(GetAssessmentReminderByKeyRequest request, DtoResponse <AssessmentReminderDto> response)
        {
            var assessmentReminder = _assessmentReminderRepository.GetByKey(request.AssessmentReminderKey);

            if (assessmentReminder != null)
            {
                var patient = _patientRepository.GetByKey(assessmentReminder.PatientKey);
                var assessmentDefinition  = _assessmentDefinitionRepository.GetByKey(assessmentReminder.AssessmentDefinitionKey);
                var assessmentReminderDto = Mapper.Map <AssessmentReminder, AssessmentReminderDto> (assessmentReminder);
                assessmentReminderDto.AssessmentName   = _resourcesManager.GetResourceManagerByName(assessmentDefinition.CodedConcept.Name).GetString("_" + assessmentDefinition.CodedConcept.Code);
                assessmentReminderDto.PatientFirstName = patient.Name.FirstName;
                assessmentReminderDto.PatientLastName  = patient.Name.LastName;
                response.DataTransferObject            = assessmentReminderDto;
            }
        }
Beispiel #6
0
        private void CreateAssessmentReminders(Guid key)
        {
            using (var connection = _connectionFactory.CreateConnection())
            {
                var assessmentReminder   = _assessmentReminderRepository.GetByKey(key);
                var patient              = _patientRepository.GetByKey(assessmentReminder.PatientKey);
                var assessmentDefinition = _assessmentDefinitionRepository.GetByKey(assessmentReminder.AssessmentDefinitionKey);
                Func <DateTime, DateTime> getStartDate = (date) =>
                {
                    switch (assessmentReminder.ReminderRecurrence)
                    {
                    case AssessmentReminderRecurrence.Weekly:
                        return(date.AddDays(7));

                    case AssessmentReminderRecurrence.Monthly:
                        return(date.AddMonths(1));

                    default:
                        return(date.AddDays(1));
                    }
                };

                var parameterList = new List <object>();
                if (assessmentReminder.End == null)
                {
                    assessmentReminder.End = assessmentReminder.Start;
                }
                if (assessmentReminder.Start > assessmentReminder.End)
                {
                    // add 1 minute to the end date to make it go at least once
                    assessmentReminder.End = assessmentReminder.Start.AddMinutes(1);
                }
                for (DateTime startDate = assessmentReminder.Start; startDate <= assessmentReminder.End; startDate = getStartDate(startDate))
                {
                    parameterList.Add(
                        new
                    {
                        AssessmentReminderKey = Guid.NewGuid(),
                        assessmentReminder.OrganizationKey,
                        assessmentReminder.PatientKey,
                        assessmentReminder.CreatedByStaffKey,
                        assessmentReminder.AssessmentDefinitionKey,
                        assessmentReminder.Title,
                        Start            = startDate,
                        End              = startDate.AddDays(1),
                        Status           = assessmentReminder.Status.ToString(),
                        ReminderDays     = 0.0,
                        Recurrence       = assessmentReminder.ReminderRecurrence.ToString(),
                        PatientFirstName = patient.Name.FirstName,
                        PatientLastName  = patient.Name.LastName,
                        AssessmentCode   = assessmentDefinition.CodedConcept.Code,
                        AssessmentName   = assessmentDefinition.CodedConcept.Name,
                        RecurrenceKey    = assessmentReminder.Key,
                        SystemAccountKey = UserContext.Current.SystemAccountKey ?? assessmentReminder.CreatedByStaffKey
                    });
                }

                // todo: add assessmentinstancekey to the query
                connection.Execute("DELETE FROM [MessageModule].[AssessmentReminder] WHERE [RecurrenceKey] = @RecurrenceKey;", new { RecurrenceKey = key });
                connection.Execute(
                    @"INSERT INTO [MessageModule].[AssessmentReminder] ([AssessmentReminderKey], 
                                        [OrganizationKey], 
                                        [PatientKey] , 
                                        [PatientFirstname], 
                                        [PatientLastname], 
                                        [CreatedByStaffKey], 
                                        [AssessmentDefinitionKey], 
                                        [AssessmentName], 
                                        [AssessmentCode], 
                                        [Title], 
                                        [Start],
                                        [End],
                                        [Status],
                                        [ReminderDays],
                                        [Recurrence],
                                        [RecurrenceKey],
                                        [SystemAccountKey]
                                        ) 
                                    VALUES ( @AssessmentReminderKey,
                                        @OrganizationKey, 
                                        @PatientKey, 
                                        @PatientFirstName, 
                                        @PatientLastName, 
                                        @CreatedByStaffKey, 
                                        @AssessmentDefinitionKey, 
                                        @AssessmentName,
                                        @AssessmentCode, 
                                        @Title, 
                                        @Start,
                                        @End,
                                        @Status,
                                        @ReminderDays,
                                        @Recurrence,
                                        @RecurrenceKey,
                                        @SystemAccountKey)",
                    parameterList);
            }
        }