///<summary>Creates an alert item. Setting allClinicAlert bool to true creates an eConnector alert which will have a clinicNum of -1 ///and appear in all clinics for users subscribed to the alert category containing econnector alerts. </summary> private static void CreateAlertItem(bool allClinicAlert, long clinicNum = 0) { if (allClinicAlert) { AlertItems.Insert(new AlertItem { Actions = ActionType.MarkAsRead | ActionType.MarkAsRead, Description = Lans.g("Econnector", "eConnector needs to be restarted"), Severity = SeverityType.High, Type = AlertType.EConnectorDown, ClinicNum = -1, //Show for all clinics FormToOpen = FormType.FormEServicesEConnector, }); } else if (clinicNum != 0) { AlertItems.Insert(new AlertItem() { Type = AlertType.Generic, Actions = ActionType.MarkAsRead | ActionType.Delete | ActionType.ShowItemValue, Description = "A generic alert.", Severity = SeverityType.Low, ItemValue = "A generic alert created for testing alert Items for all clinics. ClinicNum==" + clinicNum, ClinicNum = clinicNum, });; } else { AlertItems.CreateGenericAlert("A generic alert.", "A generic alert created for testing alert Items for all clinics. ClinicNum==0"); } }
///<summary>Validates that PrefName.EasyNoClinics is ok to be changed and changes it when necessary. Sends an alert to eConnector to perform the conversion. ///If fails then restores checkEnableClinics to original value when form was opened.</summary> private bool IsClinicCheckBoxOk() { try { if (!_hasClinicsEnabledChanged) //No change. { return(true); } //Turn clinics on/off locally and send the signal to other workstations. This must happen before we call HQ so we tell HQ the new value. Prefs.UpdateBool(PrefName.EasyNoClinics, !checkEnableClinics.Checked); DataValid.SetInvalid(InvalidType.Prefs); //Create an alert for the user to know they may need to restart the eConnector if they are subscribed to eServices AlertItems.Insert(new AlertItem() { Description = Lan.g(this, "Clinic Feature Changed, you may need to restart the eConnector if you are subscribed to eServices"), Type = AlertType.ClinicsChanged, Severity = SeverityType.Low, Actions = ActionType.OpenForm | ActionType.MarkAsRead | ActionType.Delete, FormToOpen = FormType.FormEServicesEConnector, ItemValue = "Clinics turned " + (checkEnableClinics.Checked ? "On":"Off") }); //Create an alert for the eConnector to perform the clinic conversion as needed. AlertItems.Insert(new AlertItem() { Description = "Clinics Changed", Type = AlertType.ClinicsChangedInternal, Severity = SeverityType.Normal, Actions = ActionType.None, ItemValue = checkEnableClinics.Checked ? "On":"Off" }); return(true); } catch (Exception ex) { //Change it back to what the db has. RestoreClinicCheckBox(); MessageBox.Show(ex.Message); return(false); } }
///<summary>Send a summary of eConnector statistics to OD HQ. This should only be called from the eConnector.</summary> public static void UpdateEConnectorStats() { EConnectorStatistics eConnStats = new EConnectorStatistics() { ListEServiceSignals = new List <EServiceSignal>(), ListEServicePrefs = new List <Pref>(), }; eConnStats.EConnectorComputerName = Environment.MachineName; eConnStats.EConnectorDomainUserName = Environment.UserName; eConnStats.EConnectorIP = ODEnvironment.GetLocalIPAddress(); eConnStats.HasClinicsEnabled = PrefC.HasClinicsEnabled; if (PrefC.HasClinicsEnabled) { eConnStats.CountActiveClinics = OpenDentBusiness.Clinics.GetCount(); eConnStats.CountInactiveClinics = OpenDentBusiness.Clinics.GetCount() - eConnStats.CountActiveClinics; } else { eConnStats.CountActiveClinics = 0; eConnStats.CountInactiveClinics = OpenDentBusiness.Clinics.GetCount(); } if (DateTime.Now.Hour == 0) //These are heavy queries so only run them once a day around midnight. { eConnStats.CountActivePatients = OpenDentBusiness.Procedures.GetCountPatsComplete(DateTime.Today.AddYears(-2), DateTime.Today); eConnStats.CountNonactivePatients = OpenDentBusiness.Patients.GetPatCountAll() - eConnStats.CountActivePatients; eConnStats.ListEServiceSignals = OpenDentBusiness.EServiceSignals.GetServiceHistory(eServiceCode.ListenerService, DateTime.Today.AddDays(-30), DateTime.Today, 30); } eConnStats.DateTimeNow = DateTime.Now; foreach (PrefName prefName in Enum.GetValues(typeof(PrefName))) { if (prefName.In( PrefName.RegistrationKey, PrefName.ProgramVersion, PrefName.DataBaseVersion, PrefName.TextingDefaultClinicNum, PrefName.WebServiceServerName, PrefName.SendEmailsInDiffProcess, PrefName.EmailAlertMaxConsecutiveFails, PrefName.AutoCommNumClinicsParallel, PrefName.AutomaticCommunicationTimeStart, PrefName.AutomaticCommunicationTimeEnd) || prefName.ToString().StartsWith("WebSched") || prefName.ToString().StartsWith("ApptConfirm") || prefName.ToString().StartsWith("ApptRemind") || prefName.ToString().StartsWith("ApptEConfirm") || prefName.ToString().StartsWith("Recall") || prefName.ToString().StartsWith("PatientPortal") || prefName.ToString().StartsWith("Sms")) { try { eConnStats.ListEServicePrefs.Add(Prefs.GetPref(prefName.ToString())); } catch (Exception ex) { ex.DoNothing(); } } } List <EConnectorStatistics> listStatsToSend = new List <EConnectorStatistics> { eConnStats }; string dbStats = PrefC.GetString(PrefName.EConnectorStatistics); List <EConnectorStatistics> listDbStats = DeserializeListFromJson(dbStats) ?? new List <EConnectorStatistics>(); bool doCreateAlert = false; foreach (EConnectorStatistics stats in listDbStats) { //If a different eConnector is saving stats, add that one to the list to be sent to HQ. if (!AreSameEConnector(eConnStats, stats) && (eConnStats.DateTimeNow - stats.DateTimeNow).TotalHours < 23) { stats.ListEServicePrefs = new List <Pref>(); //To save on bandwidth stats.ListEServiceSignals = new List <EServiceSignal>(); listStatsToSend.Add(stats); if ((eConnStats.DateTimeNow - stats.DateTimeNow).TotalHours < 3) { doCreateAlert = true; } } } if (doCreateAlert && AlertItems.RefreshForType(AlertType.MultipleEConnectors).Count == 0) { AlertItem alert = new AlertItem { Actions = ActionType.MarkAsRead | ActionType.Delete, Description = Lans.g("EConnectorStats", "eConnector services are being run on these computers:") + " " + string.Join(", ", listStatsToSend.Select(x => x.EConnectorComputerName)), Severity = SeverityType.High, Type = AlertType.MultipleEConnectors, }; AlertItems.Insert(alert); } string statsStr = SerializeToJson(listStatsToSend); OpenDentBusiness.Prefs.UpdateString(PrefName.EConnectorStatistics, statsStr); string payload = PayloadHelper.CreatePayload(PayloadHelper.CreatePayloadContent(statsStr, "EConnectorStatsStr"), eServiceCode.ListenerService); WebServiceMainHQProxy.GetWebServiceMainHQInstance().SetEConnectorStatsAsync(payload); }