Пример #1
0
        public void MovePhysicianStatuses()
        {
            try
            {
                // create log
                _logger.AddLogEntry(_serviceName, "INPROGRESS", _serviceName + " Started", "");

                var snoozePoupUsersIds = new List <PhysicianStatusSnoozeViewModel>();
                var movedUserIds       = new List <string>();

                using (var objService = new PhysicianService())
                {
                    objService.GetPhysicianStatusDashboard()
                    .Where(m => m.physician.physician_status.phs_move_status_key != null && m.physician.status_key != m.physician.physician_status.phs_move_status_key)
                    .ToList()
                    .ForEach(item =>
                    {
                        var status_key = item.physician.status_key;
                        var isSendSnoozeNotification = false;
                        var snoozeTime = item.physician.physician_status_snooze.Where(m => m.pss_processed_date == null &&
                                                                                      m.pss_phs_key == status_key
                                                                                      );



                        double snoozeMinutes = 0;
                        if (snoozeTime.Count() > 0)
                        {
                            snoozeMinutes = snoozeTime.Sum(m => m.pss_snooze_time.TotalMinutes);
                        }

                        if (item.physician.physician_status.phs_move_threshhold_time.HasValue && item.physician.physician_status.phs_enable_snooze)
                        {
                            // this condition will be rechecked after the task is completed. little bit doubt on it
                            var elapsedTime = DateTime.Now.ToEST() - item.physician.status_change_date_forAll.Value.AddMinutes(snoozeMinutes);
                            var difference  = item.physician.physician_status.phs_move_threshhold_time.Value.TotalMinutes - elapsedTime.TotalMinutes;

                            var currentSnooze = item.physician.physician_status_snooze.Where(m => m.pss_processed_date == null &&
                                                                                             m.pss_phs_key == status_key &&
                                                                                             m.pss_is_latest_snooze
                                                                                             )
                                                .FirstOrDefault();

                            if (difference <= 2.1 && difference >= 1.5 && currentSnooze == null)
                            {
                                isSendSnoozeNotification = true;
                            }
                        }

                        if (isSendSnoozeNotification && snoozeTime.Count() < item.physician.physician_status.phs_max_snooze_count.Value)
                        {
                            snoozePoupUsersIds.Add(new PhysicianStatusSnoozeViewModel {
                                phs_key = item.physician.status_key.Value, UserId = item.physician.Id
                            });
                        }
                        else
                        {
                            if (RunStatusUpdateCode(item, snoozeMinutes))
                            {
                                snoozeTime.ToList().ForEach(m =>
                                {
                                    m.pss_processed_date   = DateTime.Now.ToEST();
                                    m.pss_is_latest_snooze = false;
                                    m.pss_modified_by      = "physician status move service";
                                    m.pss_modified_by_name = "physician status move service";
                                    m.pss_modified_date    = DateTime.Now.ToEST();
                                });

                                movedUserIds.Add(item.physician.Id);
                            }
                        }
                    });

                    objService.SaveChanges();
                }

                if (snoozePoupUsersIds.Count() > 0)
                {
                    RunSnoozePopupCode(snoozePoupUsersIds);
                    snoozePoupUsersIds.Clear();
                }

                if (movedUserIds.Count() > 0)
                {
                    // sending request to signal r controller to update the status of online physician
                    string url      = scrapper.baseUrl + "/RPCHandler/RefreshPhysicianStatus?SignalRAuthKey=" + Settings.SignalRAuthKey;
                    string postData = Newtonsoft.Json.JsonConvert.SerializeObject(movedUserIds);
                    scrapper.GetData(url, "POST", postData, ref Cookies, ContentTypes.Json);
                }
            }
            catch (Exception exception)
            {
                _logger.AddLogEntry(_serviceName, "ERROR", exception, "");
            }
            finally
            {
                _logger.AddLogEntry(_serviceName, "COMPLETED", "", "");
            }
        }
Пример #2
0
        public void ResetUnSchedulePhysicians()
        {
            try
            {
                // create log
                _logger.AddLogEntry(_service3Name, "INPROGRESS", _service3Name + " Started", "");

                using (var objService = new PhysicianService())
                {
                    var now        = DateTime.Now.ToEST();
                    var physicians = objService.GetUnSchedulePhysiciansForService()
                                     .ToList();
                    physicians.ForEach(p =>
                    {
                        p.status_key                = PhysicianStatus.NotAvailable.ToInt();
                        p.status_change_date        = now;
                        p.status_change_cas_key     = null;
                        p.status_change_date_forAll = now;

                        using (var objLogService = new PhysicianStatusLogService())
                        {
                            objLogService.Create(new Model.physician_status_log
                            {
                                psl_user_key     = p.Id,
                                psl_created_by   = "unscheduled physicians service",
                                psl_created_date = DateTime.Now.ToEST(),
                                psl_phs_key      = PhysicianStatus.NotAvailable.ToInt(),
                                psl_start_date   = DateTime.Now.ToEST(),
                                psl_status_name  = PhysicianStatus.NotAvailable.ToString()
                            });
                        }
                    });

                    if (physicians.Count() > 0)
                    {
                        objService.SaveChanges();
                        var    physicianUserIds = physicians.Select(m => m.Id).ToList();
                        string url      = scrapper.baseUrl + "/RPCHandler/RefreshPhysicianStatus?SignalRAuthKey=" + Settings.SignalRAuthKey;
                        string postData = Newtonsoft.Json.JsonConvert.SerializeObject(physicianUserIds);
                        scrapper.GetData(url, "POST", postData, ref Cookies, ContentTypes.Json);
                    }

                    var Nhphysicians = objService.GetNHUnSchedulePhysiciansForService()
                                       .ToList();
                    Nhphysicians.ForEach(p =>
                    {
                        p.status_key                = PhysicianStatus.NotAvailable.ToInt();
                        p.status_change_date        = now;
                        p.status_change_cas_key     = null;
                        p.status_change_date_forAll = now;

                        using (var objLogService = new PhysicianStatusLogService())
                        {
                            objLogService.Create(new Model.physician_status_log
                            {
                                psl_user_key     = p.Id,
                                psl_created_by   = "unscheduled physicians service",
                                psl_created_date = DateTime.Now.ToEST(),
                                psl_phs_key      = PhysicianStatus.NotAvailable.ToInt(),
                                psl_start_date   = DateTime.Now.ToEST(),
                                psl_status_name  = PhysicianStatus.NotAvailable.ToString()
                            });
                        }
                    });

                    if (Nhphysicians.Count() > 0)
                    {
                        objService.SaveChanges();
                        var    physicianUserIds = Nhphysicians.Select(m => m.Id).ToList();
                        string url      = scrapper.baseUrl + "/RPCHandler/RefreshPhysicianStatus?SignalRAuthKey=" + Settings.SignalRAuthKey;
                        string postData = Newtonsoft.Json.JsonConvert.SerializeObject(physicianUserIds);
                        scrapper.GetData(url, "POST", postData, ref Cookies, ContentTypes.Json);
                    }
                }
            }
            catch (Exception exception)
            {
                _logger.AddLogEntry(_service3Name, "ERROR", exception, "");
            }
            finally
            {
                _logger.AddLogEntry(_service3Name, "COMPLETED", "", "");
            }
        }