Example #1
0
		///<summary></summary>
		public static long Insert(ErxLog erxLog) {
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				erxLog.ErxLogNum=Meth.GetLong(MethodBase.GetCurrentMethod(),erxLog);
				return erxLog.ErxLogNum;
			}
			return Crud.ErxLogCrud.Insert(erxLog);
		}
Example #2
0
 ///<summary></summary>
 public static long Insert(ErxLog erxLog)
 {
     if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
     {
         erxLog.ErxLogNum = Meth.GetLong(MethodBase.GetCurrentMethod(), erxLog);
         return(erxLog.ErxLogNum);
     }
     return(Crud.ErxLogCrud.Insert(erxLog));
 }
Example #3
0
		private void Tool_eRx_Click() {
			if(!Security.IsAuthorized(Permissions.RxCreate)) {
				return;
			}
			Program programNewCrop=Programs.GetCur(ProgramName.NewCrop);
			string newCropAccountId=PrefC.GetString(PrefName.NewCropAccountId);
			if(newCropAccountId==""){//NewCrop has not been enabled yet.
				if(!MsgBox.Show(this,MsgBoxButtons.YesNo,"Are you sure you want to enable NewCrop electronic prescriptions?  The cost is $15/month for each prescribing provider.  NewCrop only works for the United States and its territories, including Puerto Rico.")) {
					return;
				}
				//prepare the xml document to send--------------------------------------------------------------------------------------
				XmlWriterSettings settings = new XmlWriterSettings();
				settings.Indent = true;
				settings.IndentChars = ("    ");
				StringBuilder strbuild=new StringBuilder();
				using(XmlWriter writer=XmlWriter.Create(strbuild,settings)) {
					writer.WriteStartElement("CustomerIdRequest");
					writer.WriteStartElement("RegistrationKey");
					writer.WriteString(PrefC.GetString(PrefName.RegistrationKey));
					writer.WriteEndElement();
					writer.WriteEndElement();
				}
#if DEBUG
				OpenDental.localhost.Service1 updateService=new OpenDental.localhost.Service1();
#else
				OpenDental.customerUpdates.Service1 updateService=new OpenDental.customerUpdates.Service1();
					updateService.Url=PrefC.GetString(PrefName.UpdateServerAddress);
#endif
				if(PrefC.GetString(PrefName.UpdateWebProxyAddress) !="") {
					IWebProxy proxy = new WebProxy(PrefC.GetString(PrefName.UpdateWebProxyAddress));
					ICredentials cred=new NetworkCredential(PrefC.GetString(PrefName.UpdateWebProxyUserName),PrefC.GetString(PrefName.UpdateWebProxyPassword));
					proxy.Credentials=cred;
					updateService.Proxy=proxy;
				}
				string patNum="";
				try {
					string result=updateService.RequestCustomerID(strbuild.ToString());//may throw error
					XmlDocument doc=new XmlDocument();
					doc.LoadXml(result);
					XmlNode node=doc.SelectSingleNode("//CustomerIdResponse");
					if(node!=null) {
						patNum=node.InnerText;
					}
					if(patNum=="") {
						throw new ApplicationException("Failed to validate registration key.");
					}
					newCropAccountId=patNum;
					newCropAccountId+="-"+CodeBase.MiscUtils.CreateRandomAlphaNumericString(3);
					long checkSum=PIn.Long(patNum);
					checkSum+=Convert.ToByte(newCropAccountId[newCropAccountId.IndexOf('-')+1])*3;
					checkSum+=Convert.ToByte(newCropAccountId[newCropAccountId.IndexOf('-')+2])*5;
					checkSum+=Convert.ToByte(newCropAccountId[newCropAccountId.IndexOf('-')+3])*7;
					newCropAccountId+=(checkSum%100).ToString().PadLeft(2,'0');
					Prefs.UpdateString(PrefName.NewCropAccountId,newCropAccountId);
					programNewCrop.Enabled=true;
					Programs.Update(programNewCrop);
				}
				catch(Exception ex) {
					MessageBox.Show(ex.Message);
					return;
				}
			}
			else { //newCropAccountId!=""
				if(!programNewCrop.Enabled) {
					MessageBox.Show(Lan.g(this,"Electronic prescriptions are currently disabled.")+"\r\n"+Lan.g(this,"To enable, go to Setup | Program Links | NewCrop."));
					return;
				}
				if(!NewCropIsAccountIdValid()) {
					string newCropName=PrefC.GetString(PrefName.NewCropName);
					string newCropPassword=PrefC.GetString(PrefName.NewCropPassword);
					if(newCropName=="" || newCropPassword=="") { //NewCrop does not allow blank passwords.
						MsgBox.Show(this,"NewCropName preference and NewCropPassword preference must not be blank when using a NewCrop AccountID provided by a reseller.");
						return;
					}
				}
			}
			//Validation------------------------------------------------------------------------------------------------------------------------------------------------------
			if(Security.CurUser.EmployeeNum==0 && Security.CurUser.ProvNum==0) {
				MsgBox.Show(this,"This user must be associated with either a provider or an employee.  The security admin must make this change before this user can submit prescriptions.");
				return;
			}
			if(PatCur==null) {
				MsgBox.Show(this,"No patient selected.");
				return;
			}
			string practicePhone=PrefC.GetString(PrefName.PracticePhone);
			if(!Regex.IsMatch(practicePhone,"^[0-9]{10}$")) {//"^[0-9]{10}(x[0-9]+)?$")) {
				MsgBox.Show(this,"Practice phone must be exactly 10 digits.");
				return;
			}
			if(practicePhone.StartsWith("555")) {
				MsgBox.Show(this,"Practice phone cannot start with 555.");
				return;
			}
			if(Regex.IsMatch(practicePhone,"^[0-9]{3}555[0-9]{4}$")) {
				MsgBox.Show(this,"Practice phone cannot contain 555 in the middle 3 digits.");
				return;
			}
			string practiceFax=PrefC.GetString(PrefName.PracticeFax);
			if(!Regex.IsMatch(practiceFax,"^[0-9]{10}(x[0-9]+)?$")) {
				MsgBox.Show(this,"Practice fax must be exactly 10 digits.");
				return;
			}
			if(practiceFax.StartsWith("555")) {
				MsgBox.Show(this,"Practice fax cannot start with 555.");
				return;
			}
			if(Regex.IsMatch(practiceFax,"^[0-9]{3}555[0-9]{4}$")) {
				MsgBox.Show(this,"Practice fax cannot contain 555 in the middle 3 digits.");
				return;
			}
			if(PrefC.GetString(PrefName.PracticeAddress)=="") {
				MsgBox.Show(this,"Practice address blank.");
				return;
			}
			if(Regex.IsMatch(PrefC.GetString(PrefName.PracticeAddress),".*P\\.?O\\.? .*",RegexOptions.IgnoreCase)) {
				MsgBox.Show(this,"Practice address cannot be a PO BOX.");
				return;
			}
			if(PrefC.GetString(PrefName.PracticeCity)=="") {
				MsgBox.Show(this,"Practice city blank.");
				return;
			}
			List<string> stateCodes=new List<string>(new string[] {
				//50 States.
				"AK","AL","AR","AZ","CA","CO","CT","DE","FL","GA",
				"HI","IA","ID","IL","IN","KS","KY","LA","MA","MD",
				"ME","MI","MN","MO","MS","MT","NC","ND","NE","NH",
				"NJ","NM","NV","NY","OH","OK","OR","PA","RI","SC",
				"SD","TN","TX","UT","VA","VT","WA","WI","WV","WY",
				//US Districts
				"DC",
				//US territories. Reference http://www.itl.nist.gov/fipspubs/fip5-2.htm
				"AS","FM","GU","MH","MP","PW","PR","UM","VI",
			});
			if(stateCodes.IndexOf(PrefC.GetString(PrefName.PracticeST))<0) {
				MsgBox.Show(this,"Practice state abbreviation invalid.");
				return;
			}
			string practiceZip=Regex.Replace(PrefC.GetString(PrefName.PracticeZip),"[^0-9]*","");//Zip with all non-numeric characters removed.
			if(practiceZip.Length!=9) {
				MsgBox.Show(this,"Practice zip must be 9 digits.");
				return;
			}
			if(!PrefC.GetBool(PrefName.EasyNoClinics) && PatCur.ClinicNum!=0) { //Using clinics and the patient is assigned to a clinic.
				Clinic clinic=Clinics.GetClinic(PatCur.ClinicNum);
				if(!Regex.IsMatch(clinic.Phone,"^[0-9]{10}?$")) {
					MessageBox.Show(Lan.g(this,"Clinic phone must be exactly 10 digits")+": "+clinic.Description);
					return;
				}
				if(clinic.Phone.StartsWith("555")) {
					MessageBox.Show(Lan.g(this,"Clinic phone cannot start with 555")+": "+clinic.Description);
					return;
				}
				if(Regex.IsMatch(clinic.Phone,"^[0-9]{3}555[0-9]{4}$")) {
					MessageBox.Show(Lan.g(this,"Clinic phone cannot contain 555 in the middle 3 digits")+": "+clinic.Description);
					return;
				}
				if(!Regex.IsMatch(clinic.Fax,"^[0-9]{10}?$")) {
					MessageBox.Show(Lan.g(this,"Clinic fax must be exactly 10 digits")+": "+clinic.Description);
					return;
				}
				if(clinic.Fax.StartsWith("555")) {
					MessageBox.Show(Lan.g(this,"Clinic fax cannot start with 555")+": "+clinic.Description);
					return;
				}
				if(Regex.IsMatch(clinic.Fax,"^[0-9]{3}555[0-9]{4}$")) {
					MessageBox.Show(Lan.g(this,"Clinic fax cannot contain 555 in the middle 3 digits")+": "+clinic.Description);
					return;
				}
				if(clinic.Address=="") {
					MessageBox.Show(Lan.g(this,"Clinic address blank")+": "+clinic.Description);
					return;
				}
				if(Regex.IsMatch(clinic.Address,".*P\\.?O\\.? .*",RegexOptions.IgnoreCase)) {
					MessageBox.Show(Lan.g(this,"Clinic address cannot be a PO BOX")+": "+clinic.Description);
					return;
				}
				if(clinic.City=="") {
					MessageBox.Show(Lan.g(this,"Clinic city blank")+": "+clinic.Description);
					return;
				}
				if(stateCodes.IndexOf(clinic.State)<0) {
					MessageBox.Show(Lan.g(this,"Clinic state abbreviation invalid")+": "+clinic.Description);
					return;
				}
				string clinicZip=Regex.Replace(clinic.Zip,"[^0-9]*","");//Zip with all non-numeric characters removed.
				if(clinicZip.Length!=9) {
					MessageBox.Show(Lan.g(this,"Clinic zip must be 9 digits")+": "+clinic.Description);
					return;
				}
			}
			Provider prov=null;
			if(Security.CurUser.ProvNum!=0) {
				prov=Providers.GetProv(Security.CurUser.ProvNum);
			}
			else {
				prov=Providers.GetProv(PatCur.PriProv);
			}
			if(prov.IsNotPerson) {
				MessageBox.Show(Lan.g(this,"Provider must be a person")+": "+prov.Abbr);
				return;
			}
			string fname=prov.FName.Trim();
			if(fname=="") {
				MessageBox.Show(Lan.g(this,"Provider first name missing")+": "+prov.Abbr);
				return;
			}
			if(Regex.Replace(fname,"[^A-Za-z\\-]*","")!=fname) {
				MessageBox.Show(Lan.g(this,"Provider first name can only contain letters and dashes.")+": "+prov.Abbr);
				return;
			}
			string lname=prov.LName.Trim();
			if(lname=="") {
				MessageBox.Show(Lan.g(this,"Provider last name missing")+": "+prov.Abbr);
				return;
			}
			if(Regex.Replace(lname,"[^A-Za-z\\-]*","")!=lname) { //Will catch situations such as "Dale Jr. III" and "Ross DMD".
				MessageBox.Show(Lan.g(this,"Provider last name can only contain letters and dashes.  Use the suffix box for I, II, III, Jr, or Sr")+": "+prov.Abbr);
				return;
			}
			//prov.Suffix is not validated here. In ErxXml.cs, the suffix is converted to the appropriate suffix enumeration value, or defaults to DDS if the suffix does not make sense.
			if(prov.DEANum.ToLower()!="none" && !Regex.IsMatch(prov.DEANum,"^[A-Za-z]{2}[0-9]{7}$")) {
				MessageBox.Show(Lan.g(this,"Provider DEA Number must be 2 letters followed by 7 digits.  If no DEA Number, enter NONE.")+": "+prov.Abbr);
				return;
			}
			string npi=Regex.Replace(prov.NationalProvID,"[^0-9]*","");//NPI with all non-numeric characters removed.
			if(npi.Length!=10) {
				MessageBox.Show(Lan.g(this,"Provider NPI must be exactly 10 digits")+": "+prov.Abbr);
				return;
			}
			if(prov.StateLicense=="") {
				MessageBox.Show(Lan.g(this,"Provider state license missing")+": "+prov.Abbr);
				return;
			}
			if(stateCodes.IndexOf(prov.StateWhereLicensed)<0) {
				MessageBox.Show(Lan.g(this,"Provider state where licensed invalid")+": "+prov.Abbr);
				return;
			}
			Employee emp=null;
			if(Security.CurUser.EmployeeNum!=0) {
				emp=Employees.GetEmp(Security.CurUser.EmployeeNum);
				if(emp.LName=="") {//Checked in UI, but check here just in case this database was converted from another software.
					MessageBox.Show(Lan.g(this,"Employee last name missing for user")+": "+Security.CurUser.UserName);
					return;
				}
				if(emp.FName=="") {//Not validated in UI.
					MessageBox.Show(Lan.g(this,"Employee first name missing for user")+": "+Security.CurUser.UserName);
					return;
				}
			}
			if(PatCur.Birthdate.Year<1880) {
				MsgBox.Show(this,"Patient birthdate missing.");
				return;
			}
			if(PatCur.State!="" && stateCodes.IndexOf(PatCur.State)<0) {
				MsgBox.Show(this,"Patient state abbreviation invalid");
				return;
			}
			//FormErx formErx=new FormErx();
			//formErx.prov=prov;
			//formErx.emp=emp;
			//formErx.pat=PatCur;
			//formErx.ShowDialog();
			string clickThroughXml=ErxXml.BuildClickThroughXml(prov,emp,PatCur);
			string xmlBase64=System.Web.HttpUtility.HtmlEncode(Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(clickThroughXml)));
			xmlBase64=xmlBase64.Replace("+","%2B");//A common base 64 character which needs to be escaped within URLs.
			xmlBase64=xmlBase64.Replace("/","%2F");//A common base 64 character which needs to be escaped within URLs.
			xmlBase64=xmlBase64.Replace("=","%3D");//Base 64 strings usually end in '=', which could mean a new parameter definition within the URL so we escape.
			String postdata="RxInput=base64:"+xmlBase64;
			byte[] PostDataBytes=System.Text.Encoding.UTF8.GetBytes(postdata);
			string additionalHeaders="Content-Type: application/x-www-form-urlencoded\r\n";
			InternetExplorer IEControl=new InternetExplorer();
			IWebBrowserApp IE=(IWebBrowserApp)IEControl;
			IE.Visible=true;
#if DEBUG
			string newCropUrl="http://preproduction.newcropaccounts.com/interfaceV7/rxentry.aspx";
#else //Debug
			string newCropUrl="https://secure.newcropaccounts.com/interfacev7/rxentry.aspx";
#endif
			IE.Navigate(newCropUrl,null,null,PostDataBytes,additionalHeaders);
			ErxLog erxLog=new ErxLog();
			erxLog.PatNum=PatCur.PatNum;
			erxLog.MsgText=clickThroughXml;
			erxLog.ProvNum=prov.ProvNum;
			ErxLogs.Insert(erxLog);
		}