Пример #1
0
        private bool IsDailyNotificationCountEnough(AssignedMedicament assignedMedicament)
        {
            if (assignedMedicament.Frequency >= 1)
            {
                return false;
            }

            var maxDailyNotificationCount = (int)Math.Round(1 / assignedMedicament.Frequency);
            var dailyNotificationCount = this.notificationRepository.GetEntitiesByQuery(
                v =>
                v.AssignedMedicamentId == assignedMedicament.Id
                && v.SendingDate.Date == DateTime.Now.Date).Count();

            return maxDailyNotificationCount == dailyNotificationCount;
        }
Пример #2
0
 private Notification GetLastNonAnsweredNotification(AssignedMedicament assignedMedicament)
 {
     return this.notificationRepository.GetEntitiesByQuery(
         v =>
         !v.IsActive && v.AssignedMedicamentId == assignedMedicament.Id && !v.ExecutedDate.HasValue).OrderByDescending(v => v.SendingDate).FirstOrDefault();
 }
Пример #3
0
 private string GetNotificationMessage(AssignedMedicament assignedMedicament)
 {
     var medicamentForm = this.medicamentFormRepository.GetEntityById(assignedMedicament.Medicament.Id);
     return string.Format(
         "Примите {0} {1} {2} с кодом {3}",
         assignedMedicament.Medicament.Name,
         assignedMedicament.Dosage,
         medicamentForm.Name,
         assignedMedicament.Medicament.Code);
 }
Пример #4
0
        private void CreateNewNotification(AssignedMedicament assignedMedicament)
        {
            var periodInMinutes = this.GetPeriodInMinutes(assignedMedicament.Frequency);
            if (this.IsDailyNotificationCountEnough(assignedMedicament))
            {
                return;
            }

            DateTime sendingDate;
            var notification = this.GetLastAnsweredNotification(assignedMedicament);

            if (notification == null)
            {
                var nonAnsweredNotification = this.GetLastNonAnsweredNotification(assignedMedicament);
                if (nonAnsweredNotification == null)
                {
                    sendingDate = new DateTime(
                        assignedMedicament.StartDate.Year, assignedMedicament.StartDate.Month, assignedMedicament.StartDate.Day, this.startDayFromHour, 0, 0);
                }
                else
                {
                    sendingDate = this.GetSendingDate(nonAnsweredNotification.SendingDate, periodInMinutes);
                }
            }
            else
            {
                sendingDate = this.GetSendingDate(notification.ExecutedDate.Value, periodInMinutes);
            }

            if (sendingDate.Date >= assignedMedicament.FinishDate.Date)
            {
                return;
            }

            var newNotification = this.notificationFactory.Create(
                        Guid.NewGuid(),
                        assignedMedicament.Id,
                        assignedMedicament.PersonConsultation.PatientId,
                        assignedMedicament.MedicamentId,
                        sendingDate,
                        this.GetNotificationMessage(assignedMedicament));
            this.notificationRepository.CreateOrUpdateEntity(newNotification);
            //            this.logger.LogMessage(string.Format("Notification {0} was created", newNotification.Id));
        }