///<summary>Sends a text message to this patient if it is feasible.</summary> private bool SendText(PatComm patComm, long clinicNum, string message) { if (!patComm.IsSmsAnOption) { Cursor = Cursors.Default; MessageBox.Show(Lan.g(this, "It is not OK to text patient") + " " + patComm.FName + " " + patComm.LName + "."); Cursor = Cursors.WaitCursor; return(false); } return(SmsToMobiles.SendSmsSingle(patComm.PatNum, patComm.SmsPhone, message, clinicNum, _messageSource, true, Security.CurUser)); }
public static SmsToMobile CreateSmsToMobile(Patient pat, string guidMessage, SmsMessageSource source) { string guidBatch = Guid.NewGuid().ToString(); SmsToMobile smsToMobile = new SmsToMobile() { GuidBatch = guidBatch, GuidMessage = guidMessage, MsgType = source, PatNum = pat.PatNum, MobilePhoneNumber = pat.WirelessPhone }; smsToMobile.SmsToMobileNum = SmsToMobiles.Insert(smsToMobile); return(smsToMobile); }
/// <summary>May be called from other parts of the program without showing this form. You must still create an instance of this form though. /// Checks CallFire bridge, if it is OK to send a text, etc. (Buttons to load this form are usually disabled if it is not OK, /// but this is needed for Confirmations, Recalls, etc.). CanIncreaseLimit will prompt the user to increase the spending limit if sending the /// text would exceed that limit. Should only be true when this method is called from this form. </summary> public bool SendText(long patNum, string wirelessPhone, string message, YN txtMsgOk, long clinicNum, SmsMessageSource smsMessageSource, bool canIncreaseLimit = false) { if (Plugins.HookMethod(this, "FormTxtMsgEdit.SendText_Start", patNum, wirelessPhone, message, txtMsgOk)) { return(false); } if (Plugins.HookMethod(this, "FormTxtMsgEdit.SendText_Start2", patNum, wirelessPhone, message, txtMsgOk)) { return(true); } if (wirelessPhone == "") { MsgBox.Show(this, "Please enter a phone number."); return(false); } if (SmsPhones.IsIntegratedTextingEnabled()) { if (!PrefC.HasClinicsEnabled && PrefC.GetDateT(PrefName.SmsContractDate).Year < 1880) //Checking for practice (clinics turned off). { MsgBox.Show(this, "Integrated Texting has not been enabled."); return(false); } else if (PrefC.HasClinicsEnabled && !Clinics.IsTextingEnabled(clinicNum)) //Checking for specific clinic. //This is likely to happen a few times per office until they setup texting properly. { if (clinicNum != 0) { MessageBox.Show(Lans.g(this, "Integrated Texting has not been enabled for the following clinic") + ":\r\n" + Clinics.GetClinic(clinicNum).Description + "."); } else { //Should never happen. This message is precautionary. MsgBox.Show(this, "The default texting clinic has not been set."); } return(false); } } else if (!Programs.IsEnabled(ProgramName.CallFire)) { MsgBox.Show(this, "CallFire Program Link must be enabled."); return(false); } if (patNum != 0 && txtMsgOk == YN.Unknown && PrefC.GetBool(PrefName.TextMsgOkStatusTreatAsNo)) { MsgBox.Show(this, "It is not OK to text this patient."); return(false); } if (patNum != 0 && txtMsgOk == YN.No) { MsgBox.Show(this, "It is not OK to text this patient."); return(false); } if (SmsPhones.IsIntegratedTextingEnabled()) { try { SmsToMobiles.SendSmsSingle(patNum, wirelessPhone, message, clinicNum, smsMessageSource, user: Security.CurUser); //Can pass in 0 as PatNum if no patient selected. return(true); } catch (Exception ex) { //ProcessSendSmsException handles the spending limit has been reached error, or returns false if the exception is different. if (!canIncreaseLimit || !FormEServicesSetup.ProcessSendSmsException(ex)) { MsgBox.Show(this, ex.Message); } return(false); } } else { if (message.Length > 160) //only a limitation for CallFire { MsgBox.Show(this, "Text length must be less than 160 characters."); return(false); } return(SendCallFire(patNum, wirelessPhone, message)); //Can pass in 0 as PatNum if no patient selected. } }
///<summary>Sends a request to HQ to update the Short Code Opt In status of this patient. Can be sent silently without any feedback in the UI. ///</summary> private static bool TrySendToHq(string wirelessPhone, YN optIn, long patNum, long clinicNum, bool isSilent = false) { List <PayloadItem> listPayloadItems = new List <PayloadItem>() { new PayloadItem(wirelessPhone, "PhonePat"), new PayloadItem((int)optIn, "ShortCodeOptInInt"), new PayloadItem(patNum, "PatNum"), new PayloadItem(clinicNum, "ClinicNum"), new PayloadItem(false, "IsWebSchedNewPat"), new PayloadItem(isSilent, "IsSilentUpdate"), }; string result = ""; if (isSilent) { ODThread threadSilent = new ODThread((o) => WebServiceMainHQProxy.GetWebServiceMainHQInstance() .SetSmsPatientPhoneOptIn(PayloadHelper.CreatePayload(listPayloadItems, eServiceCode.IntegratedTexting))); threadSilent.AddExceptionHandler((ex) => ex.DoNothing()); threadSilent.Name = "ShortCodeOptIn"; threadSilent.Start(); return(true); } ODProgress.ShowAction(() => { result = WebServiceMainHQProxy.GetWebServiceMainHQInstance() .SetSmsPatientPhoneOptIn(PayloadHelper.CreatePayload(listPayloadItems, eServiceCode.IntegratedTexting)); }); XmlDocument doc = new XmlDocument(); doc.LoadXml(result); XmlNode node = doc.SelectSingleNode("//ListSmsToMobiles"); if (node is null) { node = doc.SelectSingleNode("//Error"); if (!(node is null)) { MessageBox.Show(Lan.g("ShortCodes", "An error occurred: ") + node.InnerText); } return(false); } List <SmsToMobile> listSmsToMobiles; using (XmlReader reader = XmlReader.Create(new System.IO.StringReader(node.InnerXml))) { System.Xml.Serialization.XmlSerializer xmlListSmsToMobileSerializer = new System.Xml.Serialization.XmlSerializer(typeof(List <SmsToMobile>)); listSmsToMobiles = (List <SmsToMobile>)xmlListSmsToMobileSerializer.Deserialize(reader); } if (listSmsToMobiles == null) //List should always be there even if it's empty. { MessageBox.Show(Lan.g("ShortCodes", "An error occurred: ") + node.InnerText); return(false); } //Should only be 0 or 1. if (listSmsToMobiles.Count > 0) { listSmsToMobiles.ForEach(x => x.DateTimeSent = DateTime.Now); SmsToMobiles.InsertMany(listSmsToMobiles); string message = $"{wirelessPhone} will shortly receive the following message{(listSmsToMobiles.Count>1 ? "s" : "")}:\n" + string.Join("\n", listSmsToMobiles.Select((x, i) => $"{i+1}) {x.MsgText}")); MessageBox.Show(message, "Appointment Texts"); } //Local OptIn status for this patient will be updated by a Transmission from HQ, resulting from this call to SetSmsPatientPhoneOptIn(). return(true); }