Ejemplo n.º 1
0
        public void ResetOnSchedulePhysicians()
        {
            try
            {
                // create log
                _logger.AddLogEntry(_service2Name, "INPROGRESS", _service2Name + " Started", "");

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

                        using (var objLogService = new PhysicianStatusLogService())
                        {
                            objLogService.Create(new Model.physician_status_log
                            {
                                psl_user_key     = p.physician.Id,
                                psl_created_by   = "reset physician service",
                                psl_created_date = DateTime.Now.ToEST(),
                                psl_phs_key      = PhysicianStatus.Available.ToInt(),
                                psl_start_date   = p.schedule.uss_time_from_calc,
                                psl_end_date     = p.schedule.uss_time_to_calc,
                                psl_status_name  = PhysicianStatus.Available.ToString(),
                                psl_uss_key      = p.schedule.uss_key,
                            });
                        }
                    });

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

                    var NhPhysicians = objService.GetNHPhysiciansForService().ToList();

                    NhPhysicians.ForEach(p =>
                    {
                        p.physician.status_key                = PhysicianStatus.Available.ToInt();
                        p.physician.status_change_date        = DateTime.Now.ToEST();
                        p.physician.status_change_date_forAll = DateTime.Now.ToEST();
                        p.physician.status_change_cas_key     = null;

                        using (var objLogService = new PhysicianStatusLogService())
                        {
                            objLogService.Create(new Model.physician_status_log
                            {
                                psl_user_key     = p.physician.Id,
                                psl_created_by   = "reset physician service",
                                psl_created_date = DateTime.Now.ToEST(),
                                psl_phs_key      = PhysicianStatus.Available.ToInt(),
                                psl_start_date   = p.schedule.uss_time_from_calc,
                                psl_end_date     = p.schedule.uss_time_to_calc,
                                psl_status_name  = PhysicianStatus.Available.ToString(),
                                psl_uss_key      = p.schedule.uss_key,
                            });
                        }
                    });

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