///<summary></summary>
		public static void Update(CustReference custReference){
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb){
				Meth.GetVoid(MethodBase.GetCurrentMethod(),custReference);
				return;
			}
			Crud.CustReferenceCrud.Update(custReference);
		}
		///<summary></summary>
		public static long Insert(CustReference custReference){
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb){
				custReference.CustReferenceNum=Meth.GetLong(MethodBase.GetCurrentMethod(),custReference);
				return custReference.CustReferenceNum;
			}
			return Crud.CustReferenceCrud.Insert(custReference);
		}
Example #3
0
 ///<summary></summary>
 public static void Update(CustReference custReference)
 {
     if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
     {
         Meth.GetVoid(MethodBase.GetCurrentMethod(), custReference);
         return;
     }
     Crud.CustReferenceCrud.Update(custReference);
 }
Example #4
0
 ///<summary></summary>
 public static long Insert(CustReference custReference)
 {
     if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
     {
         custReference.CustReferenceNum = Meth.GetLong(MethodBase.GetCurrentMethod(), custReference);
         return(custReference.CustReferenceNum);
     }
     return(Crud.CustReferenceCrud.Insert(custReference));
 }
Example #5
0
		//private void butAddPt_Click(object sender, System.EventArgs e) {
		private void ToolButAdd_Click() {
			//At HQ, we cannot allow users to add patients to reseller families.
			if(PrefC.GetBool(PrefName.DockPhonePanelShow) && Resellers.IsResellerFamily(PatCur.Guarantor)) {
				MsgBox.Show(this,"Cannot add patients to a reseller family.");
				return;
			}
			Patient tempPat=new Patient();
			tempPat.LName      =PatCur.LName;
			tempPat.PatStatus  =PatientStatus.Patient;
			tempPat.Address    =PatCur.Address;
			tempPat.Address2   =PatCur.Address2;
			tempPat.City       =PatCur.City;
			tempPat.State      =PatCur.State;
			tempPat.Zip        =PatCur.Zip;
			tempPat.HmPhone    =PatCur.HmPhone;
			tempPat.Guarantor  =PatCur.Guarantor;
			tempPat.CreditType =PatCur.CreditType;
			tempPat.PriProv    =PatCur.PriProv;
			tempPat.SecProv    =PatCur.SecProv;
			tempPat.FeeSched   =PatCur.FeeSched;
			tempPat.BillingType=PatCur.BillingType;
			tempPat.AddrNote   =PatCur.AddrNote;
			tempPat.ClinicNum  =PatCur.ClinicNum;//this is probably better in case they don't have user.ClinicNums set.
			//tempPat.ClinicNum  =Security.CurUser.ClinicNum;
			if(Patients.GetPat(tempPat.Guarantor).SuperFamily!=0) {
				tempPat.SuperFamily=PatCur.SuperFamily;
			}
			Patients.Insert(tempPat,false);
			CustReference custRef=new CustReference();
			custRef.PatNum=tempPat.PatNum;
			CustReferences.Insert(custRef);
			FormPatientEdit FormPE=new FormPatientEdit(tempPat,FamCur);
			FormPE.IsNew=true;
			FormPE.ShowDialog();
			if(FormPE.DialogResult==DialogResult.OK){
				OnPatientSelected(tempPat);
				ModuleSelected(tempPat.PatNum);
			}
			else{
				ModuleSelected(PatCur.PatNum);
			}
		}
		///<summary>Remember, this button is not even visible if SelectionModeOnly.</summary>
		private void butAddPt_Click(object sender, System.EventArgs e){
			#if(TRIALONLY)
				MsgBox.Show(this,"Trial version.  Maximum 30 patients");
				if(Patients.GetNumberPatients()>30){
					MsgBox.Show(this,"Maximum reached");
					return;
				}
			#endif
			if(textLName.Text=="" && textFName.Text=="" && textChartNumber.Text==""){
				MessageBox.Show(Lan.g(this,"Not allowed to add a new patient until you have done a search to see if that patient already exists. Hint: just type a few letters into the Last Name box above.")); 
				return;
			}
			Patient PatCur=new Patient();
			if(textLName.Text.Length>1){//eg Sp
				PatCur.LName=textLName.Text.Substring(0,1).ToUpper()+textLName.Text.Substring(1);
			}
			if(textFName.Text.Length>1){
				PatCur.FName=textFName.Text.Substring(0,1).ToUpper()+textFName.Text.Substring(1);
			}
			PatCur.PatStatus=PatientStatus.Patient;
			PatCur.BillingType=PrefC.GetLong(PrefName.PracticeDefaultBillType);
			PatCur.PriProv=PrefC.GetLong(PrefName.PracticeDefaultProv);
			if(PrefC.GetBool(PrefName.ShowFeatureEhr)) {
				PatCur.Gender=PatientGender.Unknown;
			}
			PatCur.ClinicNum=Security.CurUser.ClinicNum;
			Patients.Insert(PatCur,false);
			CustReference custRef=new CustReference();
			custRef.PatNum=PatCur.PatNum;
			CustReferences.Insert(custRef);
			Patient PatOld=PatCur.Copy();
			PatCur.Guarantor=PatCur.PatNum;
			Patients.Update(PatCur,PatOld);
			Family FamCur=Patients.GetFamily(PatCur.PatNum);
			FormPatientEdit FormPE=new FormPatientEdit(PatCur,FamCur);
			FormPE.IsNew=true;
			FormPE.ShowDialog();
			if(FormPE.DialogResult==DialogResult.OK){
				NewPatientAdded=true;
				SelectedPatNum=PatCur.PatNum;
				DialogResult=DialogResult.OK;
			}
		}
Example #7
0
File: Patients.cs Project: mnisl/OD
		///<summary>Updated 05/09/2014 v14.2.  To prevent orphaned patients, if patFrom is a guarantor then all family members of patFrom are moved into the family patTo belongs to, and then the merge of the two specified accounts is performed.  Returns false if the merge was canceled by the user.</summary>
		public static bool MergeTwoPatients(long patTo,long patFrom){
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				return Meth.GetBool(MethodBase.GetCurrentMethod(),patTo,patFrom);
			}
			if(patTo==patFrom) {
				//Do not merge the same patient onto itself.
				return true;
			}
			string[] patNumForeignKeys=new string[]{
				"adjustment.PatNum",
				"allergy.PatNum",
				"anestheticrecord.PatNum",
				"anesthvsdata.PatNum",
				"appointment.PatNum",
				"claim.PatNum",
				"claimproc.PatNum",
				"commlog.PatNum",
				"creditcard.PatNum",
				"custrefentry.PatNumCust",
				"custrefentry.PatNumRef",
				//"custreference.PatNum",  //This is handled below.  We do not want to change patnum, the references form only shows entries for active patients.
				"disease.PatNum",
				//"document.PatNum",  //This is handled below when images are stored in the database and on the client side for images stored in the AtoZ folder due to the middle tier.
				"ehramendment.PatNum",
				"ehrcareplan.PatNum",
				"ehrlab.PatNum",
				"ehrmeasureevent.PatNum",
				"ehrnotperformed.PatNum",				
				//"ehrpatient.PatNum",  //This is handled below.  We do not want to change patnum here because there can only be one entry per patient.
				"ehrprovkey.PatNum",
				"ehrquarterlykey.PatNum",
				"ehrsummaryccd.PatNum",
				"emailmessage.PatNum",
				"encounter.PatNum",
				"erxlog.PatNum",
				"etrans.PatNum",
				"familyhealth.PatNum",
				"formpat.PatNum",
				"hl7msg.PatNum",
				"inssub.Subscriber",
				"installmentplan.PatNum",
				"intervention.PatNum",
				"labcase.PatNum",
				"labpanel.PatNum",
				"medicalorder.PatNum",
				"medicationpat.PatNum",
				"medlab.PatNum",
				"mount.PatNum",
				"orthochart.PatNum",
				//"patfield.PatNum", //Taken care of below
				"patient.ResponsParty",
				//"patientnote.PatNum"	//The patientnote table is ignored because only one record can exist for each patient.  The record in 'patFrom' remains so it can be accessed again if needed.
				//"patientrace.PatNum", //The patientrace table is ignored because we don't want duplicate races.  We could merge them but we would have to add specific code to stop duplicate races being inserted.
				"patplan.PatNum",
				"payment.PatNum",
				"payortype.PatNum",
				"payplan.Guarantor",//Treated as a patnum, because it is actually a guarantor for the payment plan, and not a patient guarantor.
				"payplan.PatNum",				
				"payplancharge.Guarantor",//Treated as a patnum, because it is actually a guarantor for the payment plan, and not a patient guarantor.
				"payplancharge.PatNum",
				"paysplit.PatNum",
				"perioexam.PatNum",
				"phonenumber.PatNum",
				"plannedappt.PatNum",
				"popup.PatNum",
				"procedurelog.PatNum",
				"procnote.PatNum",
				"proctp.PatNum",
				"question.PatNum",
				"recall.PatNum",
				"refattach.PatNum",
				//"referral.PatNum",  //This is synched with the new information below.
				"registrationkey.PatNum",
				"repeatcharge.PatNum",
				"reqstudent.PatNum",
				"reseller.PatNum",
				"rxpat.PatNum",
				"screenpat.PatNum",
				"securitylog.PatNum",
				"sheet.PatNum",
				"statement.PatNum",
				//task.KeyNum,  //Taken care of in a seperate step, because it is not always a patnum.
				"terminalactive.PatNum",
				"toothinitial.PatNum",
				"treatplan.PatNum",
				"treatplan.ResponsParty",
				"vaccinepat.PatNum",
				//vaccinepat.VaccinePatNum IS NOT a PatNum so it is should not be merged. It is the primary key.
				//vaccineobs.VaccinePatNum IS NOT a PatNum so it is should not be merged. It is the FK to the vaccinepat.VaccinePatNum.
				"vitalsign.PatNum",
				"xchargetransaction.PatNum"
			};
			string command="";
			Patient patientFrom=Patients.GetPat(patFrom);
			Patient patientTo=Patients.GetPat(patTo);
			//We need to test patfields before doing anything else because the user may wish to cancel and abort the merge.
			PatField[] patToFields=PatFields.Refresh(patTo);
			PatField[] patFromFields=PatFields.Refresh(patFrom);
			List<PatField> patFieldsToDelete=new List<PatField>();
			List<PatField> patFieldsToUpdate=new List<PatField>();
			for(int i=0;i<patFromFields.Length;i++) {
				bool hasMatch=false;
				for(int j=0;j<patToFields.Length;j++) {
					//Check patient fields that are the same to see if they have different values.
					if(patFromFields[i].FieldName==patToFields[j].FieldName) {
						hasMatch=true;
						if(patFromFields[i].FieldValue!=patToFields[j].FieldValue) {
							//Get input from user on which value to use.
							DialogResult result=MessageBox.Show("The two patients being merged have different values set for the patient field:\r\n\""+patFromFields[i].FieldName+"\"\r\n\r\n"
								+"The merge into patient has the value: \""+patToFields[j].FieldValue+"\"\r\n"
								+"The merge from patient has the value: \""+patFromFields[i].FieldValue+"\"\r\n\r\n"
								+"Would you like to overwrite the merge into value with the merge from value?\r\n(Cancel will abort the merge)","Warning",MessageBoxButtons.YesNoCancel);
							if(result==DialogResult.Yes) {
								//User chose to use the merge from patient field info.
								patFromFields[i].PatNum=patTo;
								patFieldsToUpdate.Add(patFromFields[i]);
								patFieldsToDelete.Add(patToFields[j]);
							}
							else if(result==DialogResult.Cancel) {
								return false;//Completely cancels the entire merge.  No changes have been made at this point.
							}
						}
					}
				}
				if(!hasMatch) {//The patient field does not exist in the merge into account.
					patFromFields[i].PatNum=patTo;
					patFieldsToUpdate.Add(patFromFields[i]);
				}
			}

			//Do not allow the user to abort below this point.  Any checks that could let a user abort the merge should be done above.
			#region Point of no return
			//Update and remove all patfields that were added to the list above.
			for(int i=0;i<patFieldsToDelete.Count;i++) {
				PatFields.Delete(patFieldsToDelete[i]);
			}
			for(int j=0;j<patFieldsToUpdate.Count;j++) {
				PatFields.Update(patFieldsToUpdate[j]);
			}
			//CustReference.  We need to combine patient from and patient into entries to have the into patient information from both.
			CustReference custRefFrom=CustReferences.GetOneByPatNum(patientFrom.PatNum);
			CustReference custRefTo=CustReferences.GetOneByPatNum(patientTo.PatNum);
			if(custRefFrom!=null && custRefTo!=null) { //If either of these are null, do nothing.  This is an internal only table so we didn't bother fixing it/warning users here.
				CustReference newCustRef=new CustReference();
				newCustRef.CustReferenceNum=custRefTo.CustReferenceNum; //Use same primary key so we can update.
				newCustRef.PatNum=patientTo.PatNum;
				if(custRefTo.DateMostRecent > custRefFrom.DateMostRecent) {
					newCustRef.DateMostRecent=custRefTo.DateMostRecent; //Use the most recent date.
				}
				else {
					newCustRef.DateMostRecent=custRefFrom.DateMostRecent; //Use the most recent date.
				}
				if(custRefTo.Note=="") {
					newCustRef.Note=custRefFrom.Note;
				}
				else if(custRefFrom.Note=="") {
					newCustRef.Note=custRefTo.Note;
				}
				else {//Both entries have a note
					newCustRef.Note=(custRefTo.Note+" | "+custRefFrom.Note); /*Combine in a | delimited string*/
				}
				newCustRef.IsBadRef=(custRefFrom.IsBadRef || custRefTo.IsBadRef);  //If either entry is a bad reference, count as a bad reference.
				CustReferences.Update(newCustRef); //Overwrites the old custRefTo entry.
			}
			//Merge ehrpatient.  We only do something here if there is a FROM patient entry and no INTO patient entry, in which case we change the patnum on the row to bring it over.
			EhrPatient ehrPatFrom=EhrPatients.GetOne(patientFrom.PatNum);
			EhrPatient ehrPatTo=EhrPatients.GetOne(patientTo.PatNum);
			if(ehrPatFrom!=null && ehrPatTo==null) {  //There is an entry for the FROM patient, but not the INTO patient.
				ehrPatFrom.PatNum=patientTo.PatNum;
				EhrPatients.Update(ehrPatFrom); //Bring the patfrom entry over to the new.
			}
			//Move the patient documents if they are stored in the database.
			//We do not have to worry about documents having the same name when storing within the database, only physical documents need to be renamed.
			//Physical documents are handled on the client side (not here) due to middle tier issues.
			if(!PrefC.AtoZfolderUsed) {
				//Storing documents in the database.  Simply update the PatNum column accordingly. 
				//This query cannot be ran below where all the other tables are handled dyncamically because we do NOT want to update the PatNums in the case that documents are stored physically.
				command="UPDATE document "
					+"SET PatNum="+POut.Long(patTo)+" "
					+"WHERE PatNum="+POut.Long(patFrom);
				Db.NonQ(command);
			}
			//If the 'patFrom' had any ties to guardians, they should be deleted to prevent duplicate entries.
			command="DELETE FROM guardian"
				+" WHERE PatNumChild="+POut.Long(patFrom)
				+" OR PatNumGuardian="+POut.Long(patFrom);
			Db.NonQ(command);
			//Update all guarantor foreign keys to change them from 'patFrom' to 
			//the guarantor of 'patTo'. This will effectively move all 'patFrom' family members 
			//to the family defined by 'patTo' in the case that 'patFrom' is a guarantor. If
			//'patFrom' is not a guarantor, then this command will have no effect and is
			//thus safe to always be run.
			command="UPDATE patient "
				+"SET Guarantor="+POut.Long(patientTo.Guarantor)+" "
				+"WHERE Guarantor="+POut.Long(patFrom);
			Db.NonQ(command);
			//At this point, the 'patFrom' is a regular patient and is absoloutely not a guarantor.
			//Now modify all PatNum foreign keys from 'patFrom' to 'patTo' to complete the majority of the
			//merge of the records between the two accounts.			
			for(int i=0;i<patNumForeignKeys.Length;i++) {
				if(DataConnection.DBtype==DatabaseType.Oracle 
					&& patNumForeignKeys[i]=="ehrlab.PatNum") //Oracle does not currently support EHR labs.
				{
					continue;
				}
				string[] tableAndKeyName=patNumForeignKeys[i].Split(new char[] {'.'});
				command="UPDATE "+tableAndKeyName[0]
					+" SET "+tableAndKeyName[1]+"="+POut.Long(patTo)
					+" WHERE "+tableAndKeyName[1]+"="+POut.Long(patFrom);
				Db.NonQ(command);
			}
			//We have to move over the tasks belonging to the 'patFrom' patient in a seperate step because
			//the KeyNum field of the task table might be a foreign key to something other than a patnum,
			//including possibly an appointment number.
			command="UPDATE task "
				+"SET KeyNum="+POut.Long(patTo)+" "
				+"WHERE KeyNum="+POut.Long(patFrom)+" AND ObjectType="+((int)TaskObjectType.Patient);
			Db.NonQ(command);
			//Mark the patient where data was pulled from as archived unless the patient is already marked as deceased.
			//We need to have the patient marked either archived or deceased so that it is hidden by default, and
			//we also need the customer to be able to access the account again in case a particular table gets missed
			//in the merge tool after an update to Open Dental. This will allow our customers to remerge the missing
			//data after a bug fix is released. 
			command="UPDATE patient "
				+"SET PatStatus="+((int)PatientStatus.Archived)+" "
				+"WHERE PatNum="+POut.Long(patFrom)+" "
				+"AND PatStatus<>"+((int)PatientStatus.Deceased)+" "
				+DbHelper.LimitAnd(1);
			Db.NonQ(command);
			//This updates the referrals with the new patient information from the merge.
			for(int i=0;i<Referrals.List.Length;i++){
				if(Referrals.List[i].PatNum==patFrom){
					//Referrals.Cur=Referrals.List[i];
					Referrals.List[i].PatNum=patientTo.PatNum;
					Referrals.List[i].LName=patientTo.LName;
					Referrals.List[i].FName=patientTo.FName;
					Referrals.List[i].MName=patientTo.MiddleI;
					Referrals.List[i].Address=patientTo.Address;
					Referrals.List[i].Address2=patientTo.Address2;
					Referrals.List[i].City=patientTo.City;
					Referrals.List[i].ST=patientTo.State;
					Referrals.List[i].SSN=patientTo.SSN;
					Referrals.List[i].Zip=patientTo.Zip;
					Referrals.List[i].Telephone=TelephoneNumbers.FormatNumbersExactTen(patientTo.HmPhone);
					Referrals.List[i].EMail=patientTo.Email;
					Referrals.Update(Referrals.List[i]);
					Referrals.RefreshCache();
					break;
				}
			}
			#endregion
			return true;
		}
Example #8
0
		private void butOK_Click(object sender,EventArgs e) {
			if(  textBirthdate1.errorProvider1.GetError(textBirthdate1)!=""
				|| textBirthdate2.errorProvider1.GetError(textBirthdate2)!=""
				|| textBirthdate3.errorProvider1.GetError(textBirthdate3)!=""
				|| textBirthdate4.errorProvider1.GetError(textBirthdate4)!=""
				|| textBirthdate5.errorProvider1.GetError(textBirthdate5)!=""
				){
				MsgBox.Show(this,"Please fix data entry errors first.");
				return;
			}
			//no validation on birthdate reasonableness.
			if(textLName1.Text=="" || textFName1.Text==""){
				MsgBox.Show(this,"Guarantor name must be entered.");
				return;
			}
			// Validate Insurance subscribers--------------------------------------------------------------------------------------------------------
			if((comboSubscriber1.SelectedIndex==2 || comboSubscriber2.SelectedIndex==2) && (textFName2.Text=="" || textLName2.Text=="")){
				MsgBox.Show(this,"Subscriber must have name entered.");
				return;
			}
			if((comboSubscriber1.SelectedIndex==3 || comboSubscriber2.SelectedIndex==3) && (textFName3.Text=="" || textLName3.Text=="")){
				MsgBox.Show(this,"Subscriber must have name entered.");
				return;
			}
			if((comboSubscriber1.SelectedIndex==4 || comboSubscriber2.SelectedIndex==4) && (textFName4.Text=="" || textLName4.Text=="")){
				MsgBox.Show(this,"Subscriber must have name entered.");
				return;
			}
			if((comboSubscriber1.SelectedIndex==5 || comboSubscriber2.SelectedIndex==5) && (textFName5.Text=="" || textLName5.Text=="")){
				MsgBox.Show(this,"Subscriber must have name entered.");
				return;
			}
			// Validate Insurance Plans--------------------------------------------------------------------------------------------------------------
			bool insComplete1=false;
			bool insComplete2=false;
			if(comboSubscriber1.SelectedIndex>0
				&& textSubscriberID1.Text!=""
				&& textCarrier1.Text!="")
			{
				insComplete1=true;
			}
			if(comboSubscriber2.SelectedIndex>0
				&& textSubscriberID2.Text!=""
				&& textCarrier2.Text!="")
			{
				insComplete2=true;
			}
			//test for insurance having only some of the critical fields filled in
			if(comboSubscriber1.SelectedIndex>0
				|| textSubscriberID1.Text!=""
				|| textCarrier1.Text!="")
			{
				if(!insComplete1){
					MsgBox.Show(this,"Subscriber, Subscriber ID, and Carrier are all required fields if adding insurance.");
					return;
				}
			}
			if(comboSubscriber2.SelectedIndex>0
				|| textSubscriberID2.Text!=""
				|| textCarrier2.Text!="")
			{
				if(!insComplete2){
					MsgBox.Show(this,"Subscriber, Subscriber ID, and Carrier are all required fields if adding insurance.");
					return;
				}
			}
			if(checkInsOne1.Checked
				|| checkInsOne2.Checked
				|| checkInsOne3.Checked
				|| checkInsOne4.Checked
				|| checkInsOne5.Checked)
			{
				if(!insComplete1){
					MsgBox.Show(this,"Subscriber, Subscriber ID, and Carrier are all required fields if adding insurance.");
					return;
				}
			}
			if(checkInsTwo1.Checked
				|| checkInsTwo2.Checked
				|| checkInsTwo3.Checked
				|| checkInsTwo4.Checked
				|| checkInsTwo5.Checked)
			{
				if(!insComplete2){
					MsgBox.Show(this,"Subscriber, Subscriber ID, and Carrier are all required fields if adding insurance.");
					return;
				}
			}
			//Validate Insurance subscriptions---------------------------------------------------------------------------------------------------
			if(insComplete1){
				if(!checkInsOne1.Checked
					&& !checkInsOne2.Checked
					&& !checkInsOne3.Checked
					&& !checkInsOne4.Checked
					&& !checkInsOne5.Checked)
				{
					MsgBox.Show(this,"Insurance information has been filled in, but has not been assigned to any patients.");
					return;
				}
				if(checkInsOne1.Checked && (textLName1.Text=="" || textFName1.Text=="")//Insurance1 assigned to invalid patient1
					|| checkInsOne2.Checked && (textLName2.Text=="" || textFName2.Text=="")//Insurance1 assigned to invalid patient2
					|| checkInsOne3.Checked && (textLName3.Text=="" || textFName3.Text=="")//Insurance1 assigned to invalid patient3
					|| checkInsOne4.Checked && (textLName4.Text=="" || textFName4.Text=="")//Insurance1 assigned to invalid patient4
					|| checkInsOne5.Checked && (textLName5.Text=="" || textFName5.Text=="")) //Insurance1 assigned to invalid patient5
				{
					MsgBox.Show(this,"Insurance information 1 has been filled in, but has been assigned to a patient with no name.");
					return;
				}
			}
			if(insComplete2){
				if(!checkInsTwo1.Checked
					&& !checkInsTwo2.Checked
					&& !checkInsTwo3.Checked
					&& !checkInsTwo4.Checked
					&& !checkInsTwo5.Checked)
				{
					MsgBox.Show(this,"Insurance information 2 has been filled in, but has not been assigned to any patients.");
					return;
				}
				if(checkInsTwo1.Checked && (textLName1.Text=="" || textFName1.Text=="")//Insurance2 assigned to invalid patient1
					|| checkInsTwo2.Checked && (textLName2.Text=="" || textFName2.Text=="")//Insurance2 assigned to invalid patient2
					|| checkInsTwo3.Checked && (textLName3.Text=="" || textFName3.Text=="")//Insurance2 assigned to invalid patient3
					|| checkInsTwo4.Checked && (textLName4.Text=="" || textFName4.Text=="")//Insurance2 assigned to invalid patient4
					|| checkInsTwo5.Checked && (textLName5.Text=="" || textFName5.Text=="")) //Insurance2 assigned to invalid patient5
				{
					MsgBox.Show(this,"Insurance information 2 has been filled in, but has been assigned to a patient with no name.");
					return;
				}
			}
			//End of validation------------------------------------------------------------------------------------------
			//Create Guarantor-------------------------------------------------------------------------------------------
			Patient guar=new Patient();
			guar.LName=textLName1.Text;
			guar.FName=textFName1.Text;
			if(listGender1.SelectedIndex==0){
				guar.Gender=PatientGender.Male;
			}
			else{
				guar.Gender=PatientGender.Female;
			}
			if(listPosition1.SelectedIndex==0){
				guar.Position=PatientPosition.Single;
			}
			else{
				guar.Position=PatientPosition.Married;
			}
			guar.Birthdate=PIn.Date(textBirthdate1.Text);
			guar.BillingType=PrefC.GetLong(PrefName.PracticeDefaultBillType);
			guar.PatStatus=PatientStatus.Patient;
			guar.PriProv=ProviderC.ListShort[comboPriProv1.SelectedIndex].ProvNum;
			if(comboSecProv1.SelectedIndex>0){
				guar.SecProv=ProviderC.ListShort[comboSecProv1.SelectedIndex-1].ProvNum;
			}
			guar.HmPhone=textHmPhone.Text;
			guar.Address=textAddress.Text;
			guar.Address2=textAddress2.Text;
			guar.City=textCity.Text;
			guar.State=textState.Text;
			guar.Country=textCountry.Text;
			guar.Zip=textZip.Text;
			guar.AddrNote=textAddrNotes.Text;
			guar.ClinicNum=FormOpenDental.ClinicNum;
			Patients.Insert(guar,false);
			CustReference custRef=new CustReference();
			custRef.PatNum=guar.PatNum;
			CustReferences.Insert(custRef);
			Patient guarOld=guar.Copy();
			guar.Guarantor=guar.PatNum;
			Patients.Update(guar,guarOld);
			RefAttach refAttach;
			if(textReferral.Text!=""){
				//selectedReferral will already be set if user picked from list.
				//but, if selectedReferral doesn't match data in boxes, then clear it.
				if(selectedReferral!=null
					&& (selectedReferral.LName!=textReferral.Text
					|| selectedReferral.FName!=textReferralFName.Text))
				{
					selectedReferral=null;
				}
				if(selectedReferral==null){
					selectedReferral=new Referral();
					selectedReferral.LName=textReferral.Text;
					selectedReferral.FName=textReferralFName.Text;
					Referrals.Insert(selectedReferral);
				}
				//Now we will always have a valid referral to attach.  We will use it again for the other family members.
				refAttach=new RefAttach();
				refAttach.IsFrom=true;
				refAttach.RefDate=DateTimeOD.Today;
				refAttach.ReferralNum=selectedReferral.ReferralNum;
				refAttach.PatNum=guar.PatNum;
				RefAttaches.Insert(refAttach);
				SecurityLogs.MakeLogEntry(Permissions.RefAttachAdd,refAttach.PatNum,"Referred From "+Referrals.GetNameFL(refAttach.ReferralNum));
			}
			//Patient #2-----------------------------------------------------------------------------------------------------
			Patient pat2=null;
			if(textFName2.Text!="" && textLName2.Text!=""){
				pat2=new Patient();
				pat2.LName=textLName2.Text;
				pat2.FName=textFName2.Text;
				if(listGender2.SelectedIndex==0){
					pat2.Gender=PatientGender.Male;
				}
				else{
					pat2.Gender=PatientGender.Female;
				}
				if(listPosition2.SelectedIndex==0){
					pat2.Position=PatientPosition.Single;
				}
				else{
					pat2.Position=PatientPosition.Married;
				}
				pat2.Birthdate=PIn.Date(textBirthdate2.Text);
				pat2.BillingType=PrefC.GetLong(PrefName.PracticeDefaultBillType);
				pat2.PatStatus=PatientStatus.Patient;
				pat2.PriProv=ProviderC.ListShort[comboPriProv2.SelectedIndex].ProvNum;
				if(comboSecProv2.SelectedIndex>0){
					pat2.SecProv=ProviderC.ListShort[comboSecProv2.SelectedIndex-1].ProvNum;
				}
				pat2.HmPhone=textHmPhone.Text;
				pat2.Address=textAddress.Text;
				pat2.Address2=textAddress2.Text;
				pat2.City=textCity.Text;
				pat2.State=textState.Text;
				pat2.Country=textCountry.Text;
				pat2.Zip=textZip.Text;
				pat2.AddrNote=textAddrNotes.Text;
				pat2.ClinicNum=FormOpenDental.ClinicNum;;
				pat2.Guarantor=guar.Guarantor;
				Patients.Insert(pat2,false);
				custRef=new CustReference();
				custRef.PatNum=pat2.PatNum;
				CustReferences.Insert(custRef);
				if(textReferral.Text!=""){
					//selectedReferral will already have been set in the guarantor loop
					refAttach=new RefAttach();
					refAttach.IsFrom=true;
					refAttach.RefDate=DateTimeOD.Today;
					refAttach.ReferralNum=selectedReferral.ReferralNum;
					refAttach.PatNum=pat2.PatNum;
					RefAttaches.Insert(refAttach);
					SecurityLogs.MakeLogEntry(Permissions.RefAttachAdd,refAttach.PatNum,"Referred From "+Referrals.GetNameFL(refAttach.ReferralNum));
				}
			}
			//Patient #3-----------------------------------------------------------------------------------------------------
			Patient pat3=null;
			if(textFName3.Text!="" && textLName3.Text!=""){
				pat3=new Patient();
				pat3.LName=textLName3.Text;
				pat3.FName=textFName3.Text;
				if(listGender3.SelectedIndex==0){
					pat3.Gender=PatientGender.Male;
				}
				else{
					pat3.Gender=PatientGender.Female;
				}
				pat3.Position=PatientPosition.Child;
				pat3.Birthdate=PIn.Date(textBirthdate3.Text);
				pat3.BillingType=PrefC.GetLong(PrefName.PracticeDefaultBillType);
				pat3.PatStatus=PatientStatus.Patient;
				pat3.PriProv=ProviderC.ListShort[comboPriProv3.SelectedIndex].ProvNum;
				if(comboSecProv3.SelectedIndex>0){
					pat3.SecProv=ProviderC.ListShort[comboSecProv3.SelectedIndex-1].ProvNum;
				}
				pat3.HmPhone=textHmPhone.Text;
				pat3.Address=textAddress.Text;
				pat3.Address2=textAddress2.Text;
				pat3.City=textCity.Text;
				pat3.State=textState.Text;
				pat3.Country=textCountry.Text;
				pat3.Zip=textZip.Text;
				pat3.AddrNote=textAddrNotes.Text;
				pat3.ClinicNum=FormOpenDental.ClinicNum;
				pat3.Guarantor=guar.Guarantor;
				Patients.Insert(pat3,false);
				custRef=new CustReference();
				custRef.PatNum=pat3.PatNum;
				CustReferences.Insert(custRef);
				if(textReferral.Text!=""){
					//selectedReferral will already have been set in the guarantor loop
					refAttach=new RefAttach();
					refAttach.IsFrom=true;
					refAttach.RefDate=DateTimeOD.Today;
					refAttach.ReferralNum=selectedReferral.ReferralNum;
					refAttach.PatNum=pat3.PatNum;
					RefAttaches.Insert(refAttach);
					SecurityLogs.MakeLogEntry(Permissions.RefAttachAdd,refAttach.PatNum,"Referred From "+Referrals.GetNameFL(refAttach.ReferralNum));
				}
			}
			//Patient #4-----------------------------------------------------------------------------------------------------
			Patient pat4=null;
			if(textFName4.Text!="" && textLName4.Text!=""){
				pat4=new Patient();
				pat4.LName=textLName4.Text;
				pat4.FName=textFName4.Text;
				if(listGender4.SelectedIndex==0){
					pat4.Gender=PatientGender.Male;
				}
				else{
					pat4.Gender=PatientGender.Female;
				}
				pat4.Position=PatientPosition.Child;
				pat4.Birthdate=PIn.Date(textBirthdate4.Text);
				pat4.BillingType=PrefC.GetLong(PrefName.PracticeDefaultBillType);
				pat4.PatStatus=PatientStatus.Patient;
				pat4.PriProv=ProviderC.ListShort[comboPriProv4.SelectedIndex].ProvNum;
				if(comboSecProv4.SelectedIndex>0){
					pat4.SecProv=ProviderC.ListShort[comboSecProv4.SelectedIndex-1].ProvNum;
				}
				pat4.HmPhone=textHmPhone.Text;
				pat4.Address=textAddress.Text;
				pat4.Address2=textAddress2.Text;
				pat4.City=textCity.Text;
				pat4.State=textState.Text;
				pat4.Country=textCountry.Text;
				pat4.Zip=textZip.Text;
				pat4.AddrNote=textAddrNotes.Text;
				pat4.ClinicNum=FormOpenDental.ClinicNum;
				pat4.Guarantor=guar.Guarantor;
				Patients.Insert(pat4,false);
				custRef=new CustReference();
				custRef.PatNum=pat4.PatNum;
				CustReferences.Insert(custRef);
				if(textReferral.Text!=""){
					//selectedReferral will already have been set in the guarantor loop
					refAttach=new RefAttach();
					refAttach.IsFrom=true;
					refAttach.RefDate=DateTimeOD.Today;
					refAttach.ReferralNum=selectedReferral.ReferralNum;
					refAttach.PatNum=pat4.PatNum;
					RefAttaches.Insert(refAttach);
					SecurityLogs.MakeLogEntry(Permissions.RefAttachAdd,refAttach.PatNum,"Referred From "+Referrals.GetNameFL(refAttach.ReferralNum));
				}
			}
			//Patient #5-----------------------------------------------------------------------------------------------------
			Patient pat5=null;
			if(textFName5.Text!="" && textLName5.Text!=""){
				pat5=new Patient();
				pat5.LName=textLName5.Text;
				pat5.FName=textFName5.Text;
				if(listGender5.SelectedIndex==0){
					pat5.Gender=PatientGender.Male;
				}
				else{
					pat5.Gender=PatientGender.Female;
				}
				pat5.Position=PatientPosition.Child;
				pat5.Birthdate=PIn.Date(textBirthdate5.Text);
				pat5.BillingType=PrefC.GetLong(PrefName.PracticeDefaultBillType);
				pat5.PatStatus=PatientStatus.Patient;
				pat5.PriProv=ProviderC.ListShort[comboPriProv5.SelectedIndex].ProvNum;
				if(comboSecProv5.SelectedIndex>0){
					pat5.SecProv=ProviderC.ListShort[comboSecProv5.SelectedIndex-1].ProvNum;
				}
				pat5.HmPhone=textHmPhone.Text;
				pat5.Address=textAddress.Text;
				pat5.Address2=textAddress2.Text;
				pat5.City=textCity.Text;
				pat5.State=textState.Text;
				pat5.Country=textCountry.Text;
				pat5.Zip=textZip.Text;
				pat5.AddrNote=textAddrNotes.Text;
				pat5.ClinicNum=FormOpenDental.ClinicNum;
				pat5.Guarantor=guar.Guarantor;
				Patients.Insert(pat5,false);
				custRef=new CustReference();
				custRef.PatNum=pat5.PatNum;
				CustReferences.Insert(custRef);
				if(textReferral.Text!=""){
					//selectedReferral will already have been set in the guarantor loop
					refAttach=new RefAttach();
					refAttach.IsFrom=true;
					refAttach.RefDate=DateTimeOD.Today;
					refAttach.ReferralNum=selectedReferral.ReferralNum;
					refAttach.PatNum=pat5.PatNum;
					RefAttaches.Insert(refAttach);
					SecurityLogs.MakeLogEntry(Permissions.RefAttachAdd,refAttach.PatNum,"Referred From "+Referrals.GetNameFL(refAttach.ReferralNum));
				}
			}
			//Insurance------------------------------------------------------------------------------------------------------------
			InsSub sub1=null;
			InsSub sub2=null;
			if(selectedPlan1!=null){
				//validate the ins fields.  If they don't match perfectly, then set it to null
				if(Employers.GetName(selectedPlan1.EmployerNum)!=textEmployer1.Text
					|| Carriers.GetName(selectedPlan1.CarrierNum)!=textCarrier1.Text
					|| selectedPlan1.GroupName!=textGroupName1.Text
					|| selectedPlan1.GroupNum!=textGroupNum1.Text)
				{
					selectedPlan1=null;
				}
			}
			if(selectedPlan2!=null){
				if(Employers.GetName(selectedPlan2.EmployerNum)!=textEmployer2.Text
					|| Carriers.GetName(selectedPlan2.CarrierNum)!=textCarrier2.Text
					|| selectedPlan2.GroupName!=textGroupName2.Text
					|| selectedPlan2.GroupNum!=textGroupNum2.Text)
				{
					selectedPlan2=null;
				}
			}
			if(selectedCarrier1!=null){
				//validate the carrier fields.  If they don't match perfectly, then set it to null
				if(selectedCarrier1.CarrierName!=textCarrier1.Text
					|| selectedCarrier1.Phone!=textPhone1.Text)
				{
					selectedCarrier1=null;
				}
			}
			if(selectedCarrier2!=null){
				if(selectedCarrier2.CarrierName!=textCarrier2.Text
					|| selectedCarrier2.Phone!=textPhone2.Text)
				{
					selectedCarrier2=null;
				}
			}
			if(insComplete1){
				if(selectedCarrier1==null){
					//get a carrier, possibly creating a new one if needed.
					selectedCarrier1=Carriers.GetByNameAndPhone(textCarrier1.Text,textPhone1.Text);
				}
				long empNum1=Employers.GetEmployerNum(textEmployer1.Text);
				if(selectedPlan1==null){
					//don't try to get a copy of an existing plan. Instead, start from scratch.
					selectedPlan1=new InsPlan();
					selectedPlan1.EmployerNum=empNum1;
					selectedPlan1.CarrierNum=selectedCarrier1.CarrierNum;
					selectedPlan1.GroupName=textGroupName1.Text;
					selectedPlan1.GroupNum=textGroupNum1.Text;
					selectedPlan1.PlanType="";
					InsPlans.Insert(selectedPlan1);
					Benefit ben;
					for(int i=0;i<CovCatC.ListShort.Count;i++){
						if(CovCatC.ListShort[i].DefaultPercent==-1){
							continue;
						}
						ben=new Benefit();
						ben.BenefitType=InsBenefitType.CoInsurance;
						ben.CovCatNum=CovCatC.ListShort[i].CovCatNum;
						ben.PlanNum=selectedPlan1.PlanNum;
						ben.Percent=CovCatC.ListShort[i].DefaultPercent;
						ben.TimePeriod=BenefitTimePeriod.CalendarYear;
						ben.CodeNum=0;
						Benefits.Insert(ben);
					}
					//Zero deductible diagnostic
					if(CovCats.GetForEbenCat(EbenefitCategory.Diagnostic)!=null) {
						ben=new Benefit();
						ben.CodeNum=0;
						ben.BenefitType=InsBenefitType.Deductible;
						ben.CovCatNum=CovCats.GetForEbenCat(EbenefitCategory.Diagnostic).CovCatNum;
						ben.PlanNum=selectedPlan1.PlanNum;
						ben.TimePeriod=BenefitTimePeriod.CalendarYear;
						ben.MonetaryAmt=0;
						ben.Percent=-1;
						ben.CoverageLevel=BenefitCoverageLevel.Individual;
						Benefits.Insert(ben);
					}
					//Zero deductible preventive
					if(CovCats.GetForEbenCat(EbenefitCategory.RoutinePreventive)!=null) {
						ben=new Benefit();
						ben.CodeNum=0;
						ben.BenefitType=InsBenefitType.Deductible;
						ben.CovCatNum=CovCats.GetForEbenCat(EbenefitCategory.RoutinePreventive).CovCatNum;
						ben.PlanNum=selectedPlan1.PlanNum;
						ben.TimePeriod=BenefitTimePeriod.CalendarYear;
						ben.MonetaryAmt=0;
						ben.Percent=-1;
						ben.CoverageLevel=BenefitCoverageLevel.Individual;
						Benefits.Insert(ben);
					}
				}
				sub1=new InsSub();
				sub1.PlanNum=selectedPlan1.PlanNum;
				sub1.AssignBen=PrefC.GetBool(PrefName.InsDefaultAssignBen);
				sub1.ReleaseInfo=true;
				sub1.DateEffective=DateTime.MinValue;
				sub1.DateTerm=DateTime.MinValue;
				if(comboSubscriber1.SelectedIndex==1){
					sub1.Subscriber=guar.PatNum;
				}
				if(comboSubscriber1.SelectedIndex==2){
					sub1.Subscriber=pat2.PatNum;
				}
				if(comboSubscriber1.SelectedIndex==3){
					sub1.Subscriber=pat3.PatNum;
				}
				if(comboSubscriber1.SelectedIndex==4){
					sub1.Subscriber=pat4.PatNum;
				}
				if(comboSubscriber1.SelectedIndex==5){
					sub1.Subscriber=pat5.PatNum;
				}
				sub1.SubscriberID=textSubscriberID1.Text;
				InsSubs.Insert(sub1);
			}
			if(insComplete2){
				if(selectedCarrier2==null){
					selectedCarrier2=Carriers.GetByNameAndPhone(textCarrier2.Text,textPhone2.Text);
				}
				long empNum2=Employers.GetEmployerNum(textEmployer2.Text);
				if(selectedPlan2==null){
					//don't try to get a copy of an existing plan. Instead, start from scratch.
					selectedPlan2=new InsPlan();
					selectedPlan2.EmployerNum=empNum2;
					selectedPlan2.CarrierNum=selectedCarrier2.CarrierNum;
					selectedPlan2.GroupName=textGroupName2.Text;
					selectedPlan2.GroupNum=textGroupNum2.Text;
					selectedPlan2.PlanType="";
					InsPlans.Insert(selectedPlan2);
					Benefit ben;
					for(int i=0;i<CovCatC.ListShort.Count;i++){
						if(CovCatC.ListShort[i].DefaultPercent==-1){
							continue;
						}
						ben=new Benefit();
						ben.BenefitType=InsBenefitType.CoInsurance;
						ben.CovCatNum=CovCatC.ListShort[i].CovCatNum;
						ben.PlanNum=selectedPlan2.PlanNum;
						ben.Percent=CovCatC.ListShort[i].DefaultPercent;
						ben.TimePeriod=BenefitTimePeriod.CalendarYear;
						ben.CodeNum=0;
						Benefits.Insert(ben);
					}
					//Zero deductible diagnostic
					if(CovCats.GetForEbenCat(EbenefitCategory.Diagnostic)!=null) {
						ben=new Benefit();
						ben.CodeNum=0;
						ben.BenefitType=InsBenefitType.Deductible;
						ben.CovCatNum=CovCats.GetForEbenCat(EbenefitCategory.Diagnostic).CovCatNum;
						ben.PlanNum=selectedPlan2.PlanNum;
						ben.TimePeriod=BenefitTimePeriod.CalendarYear;
						ben.MonetaryAmt=0;
						ben.Percent=-1;
						ben.CoverageLevel=BenefitCoverageLevel.Individual;
						Benefits.Insert(ben);
					}
					//Zero deductible preventive
					if(CovCats.GetForEbenCat(EbenefitCategory.RoutinePreventive)!=null) {
						ben=new Benefit();
						ben.CodeNum=0;
						ben.BenefitType=InsBenefitType.Deductible;
						ben.CovCatNum=CovCats.GetForEbenCat(EbenefitCategory.RoutinePreventive).CovCatNum;
						ben.PlanNum=selectedPlan2.PlanNum;
						ben.TimePeriod=BenefitTimePeriod.CalendarYear;
						ben.MonetaryAmt=0;
						ben.Percent=-1;
						ben.CoverageLevel=BenefitCoverageLevel.Individual;
						Benefits.Insert(ben);
					}
				}
				sub2=new InsSub();
				sub2.PlanNum=selectedPlan2.PlanNum;
				sub2.AssignBen=PrefC.GetBool(PrefName.InsDefaultAssignBen);
				sub2.ReleaseInfo=true;
				sub2.DateEffective=DateTime.MinValue;
				sub2.DateTerm=DateTime.MinValue;
				if(comboSubscriber2.SelectedIndex==1){
					sub2.Subscriber=guar.PatNum;
				}
				if(comboSubscriber2.SelectedIndex==2){
					sub2.Subscriber=pat2.PatNum;
				}
				if(comboSubscriber2.SelectedIndex==3){
					sub2.Subscriber=pat3.PatNum;
				}
				if(comboSubscriber2.SelectedIndex==4){
					sub2.Subscriber=pat4.PatNum;
				}
				if(comboSubscriber2.SelectedIndex==5){
					sub2.Subscriber=pat5.PatNum;
				}
				sub2.SubscriberID=textSubscriberID2.Text;
				InsSubs.Insert(sub2);
			}
			PatPlan patplan;
			//attach insurance to subscriber--------------------------------------------------------------------------------
			if(checkInsOne1.Checked){
				patplan=new PatPlan();
				//the only situation where ordinal would be 2 is if ins2 has this patient as the subscriber.
				if(comboSubscriber2.SelectedIndex==1){
					patplan.Ordinal=2;
				}
				else{
					patplan.Ordinal=1;
				}
				patplan.PatNum=guar.PatNum;
				patplan.InsSubNum=sub1.InsSubNum;
				if(comboSubscriber1.SelectedIndex==1){
					patplan.Relationship=Relat.Self;
				}
				else if(comboSubscriber1.SelectedIndex==2){
					patplan.Relationship=Relat.Spouse;
				}
				else{
					//the subscriber would never be a child
				}
				PatPlans.Insert(patplan);
			}
			if(checkInsTwo1.Checked){
				patplan=new PatPlan();
				//the only situations where ordinal would be 1 is if ins1 is not checked or if ins2 has this patient as subscriber.
				if(comboSubscriber2.SelectedIndex==1){
					patplan.Ordinal=1;
				}
				else if(!checkInsOne1.Checked){
					patplan.Ordinal=1;
				}
				else{
					patplan.Ordinal=2;
				}
				patplan.PatNum=guar.PatNum;
				patplan.InsSubNum=sub2.InsSubNum;
				if(comboSubscriber2.SelectedIndex==1){
					patplan.Relationship=Relat.Self;
				}
				else if(comboSubscriber2.SelectedIndex==2){
					patplan.Relationship=Relat.Spouse;
				}
				else{
					//the subscriber would never be a child
				}
				PatPlans.Insert(patplan);
			}
			//attach insurance to patient 2, the other parent----------------------------------------------------------------------
			if(checkInsOne2.Checked){
				patplan=new PatPlan();
				//the only situation where ordinal would be 2 is if ins2 has this patient as the subscriber.
				if(comboSubscriber2.SelectedIndex==2){
					patplan.Ordinal=2;
				}
				else{
					patplan.Ordinal=1;
				}
				patplan.PatNum=pat2.PatNum;
				patplan.InsSubNum=sub1.InsSubNum;
				if(comboSubscriber1.SelectedIndex==2){
					patplan.Relationship=Relat.Self;
				}
				else if(comboSubscriber1.SelectedIndex==1){
					patplan.Relationship=Relat.Spouse;
				}
				else{
					//the subscriber would never be a child
				}
				PatPlans.Insert(patplan);
			}
			if(checkInsTwo2.Checked){
				patplan=new PatPlan();
				//the only situations where ordinal would be 1 is if ins1 is not checked or if ins2 has this patient as subscriber.
				if(comboSubscriber2.SelectedIndex==2){
					patplan.Ordinal=1;
				}
				else if(!checkInsOne2.Checked){
					patplan.Ordinal=1;
				}
				else{
					patplan.Ordinal=2;
				}
				patplan.PatNum=pat2.PatNum;
				patplan.InsSubNum=sub2.InsSubNum;
				if(comboSubscriber2.SelectedIndex==2){
					patplan.Relationship=Relat.Self;
				}
				else if(comboSubscriber2.SelectedIndex==1){
					patplan.Relationship=Relat.Spouse;
				}
				else{
					//the subscriber would never be a child
				}
				PatPlans.Insert(patplan);
			}
			//attach insurance to patient 3, a child----------------------------------------------------------------------
			if(checkInsOne3.Checked){
				patplan=new PatPlan();
				patplan.Ordinal=1;
				patplan.PatNum=pat3.PatNum;
				patplan.InsSubNum=sub1.InsSubNum;
				patplan.Relationship=Relat.Child;
				PatPlans.Insert(patplan);
			}
			if(checkInsTwo3.Checked){
				patplan=new PatPlan();
				//the only situation where ordinal would be 1 is if ins1 is not checked.
				if(!checkInsOne3.Checked){
					patplan.Ordinal=1;
				}
				else{
					patplan.Ordinal=2;
				}
				patplan.PatNum=pat3.PatNum;
				patplan.InsSubNum=sub2.InsSubNum;
				patplan.Relationship=Relat.Child;
				PatPlans.Insert(patplan);
			}
			//attach insurance to patient 4, a child----------------------------------------------------------------------
			if(checkInsOne4.Checked){
				patplan=new PatPlan();
				patplan.Ordinal=1;
				patplan.PatNum=pat4.PatNum;
				patplan.InsSubNum=sub1.InsSubNum;
				patplan.Relationship=Relat.Child;
				PatPlans.Insert(patplan);
			}
			if(checkInsTwo4.Checked){
				patplan=new PatPlan();
				//the only situation where ordinal would be 1 is if ins1 is not checked.
				if(!checkInsOne4.Checked){
					patplan.Ordinal=1;
				}
				else{
					patplan.Ordinal=2;
				}
				patplan.PatNum=pat4.PatNum;
				patplan.InsSubNum=sub2.InsSubNum;
				patplan.Relationship=Relat.Child;
				PatPlans.Insert(patplan);
			}
			//attach insurance to patient 5, a child----------------------------------------------------------------------
			if(checkInsOne5.Checked){
				patplan=new PatPlan();
				patplan.Ordinal=1;
				patplan.PatNum=pat5.PatNum;
				patplan.InsSubNum=sub1.InsSubNum;
				patplan.Relationship=Relat.Child;
				PatPlans.Insert(patplan);
			}
			if(checkInsTwo5.Checked){
				patplan=new PatPlan();
				//the only situation where ordinal would be 1 is if ins1 is not checked.
				if(!checkInsOne5.Checked){
					patplan.Ordinal=1;
				}
				else{
					patplan.Ordinal=2;
				}
				patplan.PatNum=pat5.PatNum;
				patplan.InsSubNum=sub2.InsSubNum;
				patplan.Relationship=Relat.Child;
				PatPlans.Insert(patplan);
			}
			SelectedPatNum=guar.PatNum;
			//If there is an existing HL7 def enabled, send an ADT message for each patient inserted if there is an outbound ADT message defined
			if(HL7Defs.IsExistingHL7Enabled()) {
				if(guar!=null) {
					//new patients get the A04 ADT, updating existing patients we send an A08
					MessageHL7 messageHL7=MessageConstructor.GenerateADT(guar,guar,EventTypeHL7.A04);
					//Will be null if there is no outbound ADT message defined, so do nothing
					if(messageHL7!=null) {
						HL7Msg hl7Msg=new HL7Msg();
						hl7Msg.AptNum=0;
						hl7Msg.HL7Status=HL7MessageStatus.OutPending;//it will be marked outSent by the HL7 service.
						hl7Msg.MsgText=messageHL7.ToString();
						hl7Msg.PatNum=guar.PatNum;
						HL7Msgs.Insert(hl7Msg);
#if DEBUG
						MessageBox.Show(this,messageHL7.ToString());
#endif
					}
				}
				if(pat2!=null) {
					//new patients get the A04 ADT, updating existing patients we send an A08
					MessageHL7 messageHL7=MessageConstructor.GenerateADT(pat2,guar,EventTypeHL7.A04);
					//Will be null if there is no outbound ADT message defined, so do nothing
					if(messageHL7!=null) {
						HL7Msg hl7Msg=new HL7Msg();
						hl7Msg.AptNum=0;
						hl7Msg.HL7Status=HL7MessageStatus.OutPending;//it will be marked outSent by the HL7 service.
						hl7Msg.MsgText=messageHL7.ToString();
						hl7Msg.PatNum=pat2.PatNum;
						HL7Msgs.Insert(hl7Msg);
#if DEBUG
						MessageBox.Show(this,messageHL7.ToString());
#endif
					}
				}
				if(pat3!=null) {
					//new patients get the A04 ADT, updating existing patients we send an A08
					MessageHL7 messageHL7=MessageConstructor.GenerateADT(pat3,guar,EventTypeHL7.A04);
					//Will be null if there is no outbound ADT message defined, so do nothing
					if(messageHL7!=null) {
						HL7Msg hl7Msg=new HL7Msg();
						hl7Msg.AptNum=0;
						hl7Msg.HL7Status=HL7MessageStatus.OutPending;//it will be marked outSent by the HL7 service.
						hl7Msg.MsgText=messageHL7.ToString();
						hl7Msg.PatNum=pat3.PatNum;
						HL7Msgs.Insert(hl7Msg);
#if DEBUG
						MessageBox.Show(this,messageHL7.ToString());
#endif
					}
				}
				if(pat4!=null) {
					//new patients get the A04 ADT, updating existing patients we send an A08
					MessageHL7 messageHL7=MessageConstructor.GenerateADT(pat4,guar,EventTypeHL7.A04);
					//Will be null if there is no outbound ADT message defined, so do nothing
					if(messageHL7!=null) {
						HL7Msg hl7Msg=new HL7Msg();
						hl7Msg.AptNum=0;
						hl7Msg.HL7Status=HL7MessageStatus.OutPending;//it will be marked outSent by the HL7 service.
						hl7Msg.MsgText=messageHL7.ToString();
						hl7Msg.PatNum=pat4.PatNum;
						HL7Msgs.Insert(hl7Msg);
#if DEBUG
						MessageBox.Show(this,messageHL7.ToString());
#endif
					}
				}
				if(pat5!=null) {
					//new patients get the A04 ADT, updating existing patients we send an A08
					MessageHL7 messageHL7=MessageConstructor.GenerateADT(pat5,guar,EventTypeHL7.A04);
					//Will be null if there is no outbound ADT message defined, so do nothing
					if(messageHL7!=null) {
						HL7Msg hl7Msg=new HL7Msg();
						hl7Msg.AptNum=0;
						hl7Msg.HL7Status=HL7MessageStatus.OutPending;//it will be marked outSent by the HL7 service.
						hl7Msg.MsgText=messageHL7.ToString();
						hl7Msg.PatNum=pat5.PatNum;
						HL7Msgs.Insert(hl7Msg);
#if DEBUG
						MessageBox.Show(this,messageHL7.ToString());
#endif
					}
				}
			}
			MessageBox.Show("Done");
			DialogResult=DialogResult.OK;
		}
Example #9
0
		public FormReferenceEdit(CustReference refCur) {
			InitializeComponent();
			Lan.F(this);
			RefCur=refCur;
		}
Example #10
0
		///<summary>Remember, this button is not even visible if SelectionModeOnly.</summary>
		private void butAddPt_Click(object sender, System.EventArgs e){
			#if(TRIALONLY)
				MsgBox.Show(this,"Trial version.  Maximum 30 patients");
				if(Patients.GetNumberPatients()>30){
					MsgBox.Show(this,"Maximum reached");
					return;
				}
			#endif
			if(textLName.Text=="" && textFName.Text=="" && textChartNumber.Text==""){
				MessageBox.Show(Lan.g(this,"Not allowed to add a new patient until you have done a search to see if that patient already exists. Hint: just type a few letters into the Last Name box above.")); 
				return;
			}
			Patient PatCur=new Patient();
			if(textLName.Text.Length>1){//eg Sp
				PatCur.LName=textLName.Text.Substring(0,1).ToUpper()+textLName.Text.Substring(1);
			}
			if(textFName.Text.Length>1){
				PatCur.FName=textFName.Text.Substring(0,1).ToUpper()+textFName.Text.Substring(1);
			}
			PatCur.PatStatus=PatientStatus.Patient;
			PatCur.BillingType=PrefC.GetLong(PrefName.PracticeDefaultBillType);
			//Explicitly use the combo clinic instead of FormOpenDental.ClinicNum becuase the combo box should default to that clinic unless manually changed by the user.
			if(!PrefC.GetBool(PrefName.EasyNoClinics) && comboClinic.SelectedIndex!=0) {//not no clinics and all isn't selected
				//Set the patients primary provider to the clinic default provider.
				PatCur.PriProv=Providers.GetDefaultProvider(_listClinics[comboClinic.SelectedIndex-1].ClinicNum).ProvNum;
			}
			else {
				//Set the patients primary provider to the practice default provider.
				PatCur.PriProv=Providers.GetDefaultProvider().ProvNum;
			}
			if(PrefC.GetBool(PrefName.ShowFeatureEhr)) {
				PatCur.Gender=PatientGender.Unknown;
			}
			PatCur.ClinicNum=FormOpenDental.ClinicNum;
			Patients.Insert(PatCur,false);
			CustReference custRef=new CustReference();
			custRef.PatNum=PatCur.PatNum;
			CustReferences.Insert(custRef);
			Patient PatOld=PatCur.Copy();
			PatCur.Guarantor=PatCur.PatNum;
			Patients.Update(PatCur,PatOld);
			Family FamCur=Patients.GetFamily(PatCur.PatNum);
			FormPatientEdit FormPE=new FormPatientEdit(PatCur,FamCur);
			FormPE.IsNew=true;
			FormPE.ShowDialog();
			if(FormPE.DialogResult==DialogResult.OK){
				NewPatientAdded=true;
				SelectedPatNum=PatCur.PatNum;
				DialogResult=DialogResult.OK;
			}
		}