///<summary>Called from butOK_Click and butPin_Click</summary>
		private bool UpdateToDB(){
			DateTime dateTimeAskedToArrive=DateTime.MinValue;
			if(textTimeAskedToArrive.Text!=""){
				try{
					dateTimeAskedToArrive=AptCur.AptDateTime.Date+DateTime.Parse(textTimeAskedToArrive.Text).TimeOfDay;
				}
				catch{
					MsgBox.Show(this,"Time Asked To Arrive invalid.");
					return false;
				}
			}
			DateTime dateTimeArrived=AptCur.AptDateTime.Date;
			if(textTimeArrived.Text!=""){
				try{
					dateTimeArrived=AptCur.AptDateTime.Date+DateTime.Parse(textTimeArrived.Text).TimeOfDay;
				}
				catch{
					MsgBox.Show(this,"Time Arrived invalid.");
					return false;
				}
			}
			DateTime dateTimeSeated=AptCur.AptDateTime.Date;
			if(textTimeSeated.Text!=""){
				try{
					dateTimeSeated=AptCur.AptDateTime.Date+DateTime.Parse(textTimeSeated.Text).TimeOfDay;
				}
				catch{
					MsgBox.Show(this,"Time Seated invalid.");
					return false;
				}
			}
			DateTime dateTimeDismissed=AptCur.AptDateTime.Date;
			if(textTimeDismissed.Text!=""){
				try{
					dateTimeDismissed=AptCur.AptDateTime.Date+DateTime.Parse(textTimeDismissed.Text).TimeOfDay;
				}
				catch{
					MsgBox.Show(this,"Time Arrived invalid.");
					return false;
				}
			}
			//This change was just slightly too risky to make to 6.9, so 7.0 only
			if(AptCur.AptStatus!=ApptStatus.Complete//was not originally complete
				&& AptCur.AptStatus!=ApptStatus.PtNote
				&& AptCur.AptStatus!=ApptStatus.PtNoteCompleted
				&& comboStatus.SelectedIndex==1 //making it complete
				&& AptCur.AptDateTime.Date > DateTime.Today)//and future appt
			{
				MsgBox.Show(this,"Not allowed to set complete future appointments.");
				return false;
			}
			string aptPattern=Appointments.ConvertPatternTo5(strBTime.ToString());
			//Only run appt overlap check if editing an appt from the chart module and eCW program link not enabled.
			if(IsInChartModule && !Programs.UsingEcwTightOrFullMode()) {
				List<Appointment> apptList=Appointments.GetForPeriodList(AptCur.AptDateTime,AptCur.AptDateTime);
				if(DoesOverlap(aptPattern,apptList)) {
					MsgBox.Show(this,"Appointment is too long and would overlap another appointment.  Automatically shortened to fit.");
					do {
						aptPattern=aptPattern.Substring(0,aptPattern.Length-1);
						if(aptPattern.Length==1) {
							break;
						}
					} while(DoesOverlap(aptPattern,apptList));
				}
			}
			if(AptCur.AptStatus == ApptStatus.Planned) {
				;
			}
			else if(comboStatus.SelectedIndex==-1) {
				AptCur.AptStatus=ApptStatus.Scheduled;
			}
			else if (AptCur.AptStatus == ApptStatus.PtNote | AptCur.AptStatus == ApptStatus.PtNoteCompleted){
				AptCur.AptStatus = (ApptStatus)comboStatus.SelectedIndex + 7;
			}
			else {
				AptCur.AptStatus=(ApptStatus)comboStatus.SelectedIndex+1;
			}
			//set procs complete was moved further down
			//convert from current increment into 5 minute increment
			//MessageBox.Show(strBTime.ToString());
			AptCur.Pattern=aptPattern;
			if(comboUnschedStatus.SelectedIndex==0){//none
				AptCur.UnschedStatus=0;
			}
			else{
				AptCur.UnschedStatus=DefC.Short[(int)DefCat.RecallUnschedStatus][comboUnschedStatus.SelectedIndex-1].DefNum;
			}
			if(comboConfirmed.SelectedIndex!=-1){
				AptCur.Confirmed=DefC.Short[(int)DefCat.ApptConfirmed][comboConfirmed.SelectedIndex].DefNum;
			}
			AptCur.TimeLocked=checkTimeLocked.Checked;
			AptCur.ColorOverride=butColor.BackColor;
			AptCur.Note=textNote.Text;
			if(comboClinic.SelectedIndex==0) {//none
				AptCur.ClinicNum=0;
			}
			else {
				AptCur.ClinicNum=Clinics.List[comboClinic.SelectedIndex-1].ClinicNum;
			}
			//there should always be a non-hidden primary provider for an appt.
			if(comboProvNum.SelectedIndex==-1) {
				AptCur.ProvNum=ProviderC.ListShort[0].ProvNum;
			}
			else {
				AptCur.ProvNum=ProviderC.ListShort[comboProvNum.SelectedIndex].ProvNum;
			}
			if(comboProvHyg.SelectedIndex==0) {//none
				AptCur.ProvHyg=0;
			}
			else {
				AptCur.ProvHyg=ProviderC.ListShort[comboProvHyg.SelectedIndex-1].ProvNum;
			}
			AptCur.IsHygiene=checkIsHygiene.Checked;
			if(comboAssistant.SelectedIndex==0) {//none
				AptCur.Assistant=0;
			}
			else {
				AptCur.Assistant=Employees.ListShort[comboAssistant.SelectedIndex-1].EmployeeNum;
			}
			AptCur.IsNewPatient=checkIsNewPatient.Checked;
			AptCur.DateTimeAskedToArrive=dateTimeAskedToArrive;
			AptCur.DateTimeArrived=dateTimeArrived;
			AptCur.DateTimeSeated=dateTimeSeated;
			AptCur.DateTimeDismissed=dateTimeDismissed;
			//AptCur.InsPlan1 and InsPlan2 already handled 
			//The ApptProcDescript region is also in FormProcEdit.SaveAndClose() and FormDatabaseMaintenance.butApptProcs_Click()  Make any changes there as well.
			#region ApptProcDescript
			AptCur.ProcDescript="";
			AptCur.ProcsColored="";
			for(int i=0;i<gridProc.SelectedIndices.Length;i++) {
				string procDescOne="";
				string procCode=DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["ProcCode"].ToString();
				if(i>0){
					AptCur.ProcDescript+=", ";
				}
				switch(DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["TreatArea"].ToString()) {
				  case "1"://TreatmentArea.Surf:
				    procDescOne+="#"+Tooth.GetToothLabel(DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["ToothNum"].ToString())+"-"
				      +DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["Surf"].ToString()+"-";//""#12-MOD-"
				    break;
				  case "2"://TreatmentArea.Tooth:
				    procDescOne+="#"+Tooth.GetToothLabel(DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["ToothNum"].ToString())+"-";//"#12-"
				    break;
				  default://area 3 or 0 (mouth)
				    break;
				  case "4"://TreatmentArea.Quad:
				    procDescOne+=DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["Surf"].ToString()+"-";//"UL-"
				    break;
				  case "5"://TreatmentArea.Sextant:
				    procDescOne+="S"+DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["Surf"].ToString()+"-";//"S2-"
				    break;
				  case "6"://TreatmentArea.Arch:
				    procDescOne+=DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["Surf"].ToString()+"-";//"U-"
				    break;
				  case "7"://TreatmentArea.ToothRange:
				    //strLine+=table.Rows[j][13].ToString()+" ";//don't show range
				    break;
				}
				procDescOne+=DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["AbbrDesc"].ToString();
				AptCur.ProcDescript+=procDescOne;
				//Color and previous date are determined by ProcApptColor object
				ProcApptColor pac=ProcApptColors.GetMatch(procCode);
				System.Drawing.Color pColor=System.Drawing.Color.Black;
				string prevDateString="";
				if(pac!=null){
					pColor=pac.ColorText;
					if(pac.ShowPreviousDate) {
						prevDateString=Procedures.GetRecentProcDateString(AptCur.PatNum,AptCur.AptDateTime,pac.CodeRange);
						if(prevDateString!="") {
							prevDateString=" ("+prevDateString+")";
						}
					}
				}
				AptCur.ProcsColored+="<span color=\""+pColor.ToArgb().ToString()+"\">"+procDescOne+prevDateString+"</span>";
			}
			#endregion
			bool isPlanned=AptCur.AptStatus==ApptStatus.Planned;
			try {
				Appointments.Update(AptCur,AptOld);
				//Appointments.UpdateAttached(AptCur.AptNum,procNums,isPlanned);
			}
			catch(ApplicationException ex) {
				MessageBox.Show(ex.Message);
				return false;
			}
			//if appointment is marked complete and any procedures are not,
			//then set the remaining procedures complete
			if(AptCur.AptStatus==ApptStatus.Complete) {
				bool allProcsComplete=true;
				for(int i=0;i<gridProc.SelectedIndices.Length;i++){
					if(DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["ProcStatus"].ToString()!="2") {//Complete
						allProcsComplete=false;
						break;
					}
				}
				if(!allProcsComplete) {
					if(!Security.IsAuthorized(Permissions.ProcComplCreate,AptCur.AptDateTime)) {
						return false;
					}
					List <PatPlan> PatPlanList=PatPlans.Refresh(AptCur.PatNum);
					ProcedureL.SetCompleteInAppt(AptCur,PlanList,PatPlanList,pat.SiteNum,pat.Age,SubList);
					SecurityLogs.MakeLogEntry(Permissions.ProcComplCreate,pat.PatNum,
						AptCur.AptDateTime.ToShortDateString()+", "+AptCur.ProcDescript+", Procedures automatically set complete due to appt being set complete",0);
				}
			}
			else{
				Procedures.SetProvidersInAppointment(AptCur,Procedures.GetProcsForSingle(AptCur.AptNum,false));
			}
			//Do the appointment "break" automation for appointments that were just broken.
			if(AptCur.AptStatus==ApptStatus.Broken && AptOld.AptStatus!=ApptStatus.Broken) {
				SecurityLogs.MakeLogEntry(Permissions.AppointmentMove,pat.PatNum,AptCur.ProcDescript+", "+AptCur.AptDateTime.ToString()
					+", Broken by changing the Status in the Edit Appointment window.",AptCur.AptNum);
				if(PrefC.GetBool(PrefName.BrokenApptCommLogNotAdjustment)) {
					Commlog CommlogCur=new Commlog();
					CommlogCur.PatNum=pat.PatNum;
					CommlogCur.CommDateTime=DateTime.Now;
					CommlogCur.CommType=Commlogs.GetTypeAuto(CommItemTypeAuto.APPT);
					CommlogCur.Note=Lan.g(this,"Appt BROKEN for ")+AptCur.ProcDescript+"  "+AptCur.AptDateTime.ToString();
					CommlogCur.Mode_=CommItemMode.None;
					CommlogCur.UserNum=Security.CurUser.UserNum;
					FormCommItem FormCI=new FormCommItem(CommlogCur);
					FormCI.IsNew=true;
					FormCI.ShowDialog();
				}
				else {
					Adjustment AdjustmentCur=new Adjustment();
					AdjustmentCur.DateEntry=DateTime.Today;
					AdjustmentCur.AdjDate=DateTime.Today;
					AdjustmentCur.ProcDate=DateTime.Today;
					AdjustmentCur.ProvNum=AptCur.ProvNum;
					AdjustmentCur.PatNum=pat.PatNum;
					AdjustmentCur.AdjType=PrefC.GetLong(PrefName.BrokenAppointmentAdjustmentType);
					AdjustmentCur.ClinicNum=pat.ClinicNum;
					FormAdjust FormA=new FormAdjust(pat,AdjustmentCur);
					FormA.IsNew=true;
					FormA.ShowDialog();
				}
				AutomationL.Trigger(AutomationTrigger.BreakAppointment,null,pat.PatNum);
			}
			return true;
		}
		private void tbAdj_CellDoubleClicked(object sender, OpenDental.CellEventArgs e) {
			FormAdjust FormA=new FormAdjust(PatCur,(Adjustment)AdjustmentsForProc[e.Row]);
			FormA.ShowDialog();
			FillAdj();
		}
Beispiel #3
0
		private void OnBreak_Click() {
			if(!PrefC.GetBool(PrefName.BrokenApptCommLogNotAdjustment) && PrefC.GetLong(PrefName.BrokenAppointmentAdjustmentType)==0) {
				MsgBox.Show(this,"Broken appointment adjustment type is not setup yet.  Please go to Setup | Modules to fix this.");
				return;
			}
			int thisI=GetIndex(ContrApptSingle.SelectedAptNum);
			if(thisI==-1) {//selected appt is on a different day
				MsgBox.Show(this,"Please select an appointment first.");
				return;
			}
			Appointment apt = Appointments.GetOneApt(ContrApptSingle.SelectedAptNum);
			Patient pat=Patients.GetPat(PIn.Long(ContrApptSingle3[thisI].DataRoww["PatNum"].ToString()));
			if(!Security.IsAuthorized(Permissions.AppointmentEdit)) {
				return;
			}
			if(apt.AptStatus == ApptStatus.PtNote || apt.AptStatus == ApptStatus.PtNoteCompleted) {
				MsgBox.Show(this,"Only appointments may be broken, not notes.");
				return;
			}
			if(PrefC.GetBool(PrefName.BrokenApptCommLogNotAdjustment)) {
				if(!MsgBox.Show(this,true,"Break appointment?")) {
					return;
				}
			}
			Appointments.SetAptStatus(ContrApptSingle.SelectedAptNum,ApptStatus.Broken);
			SecurityLogs.MakeLogEntry(Permissions.AppointmentMove,pat.PatNum,
				ContrApptSingle3[thisI].DataRoww["procs"].ToString()+", "+ContrApptSingle3[thisI].DataRoww["AptDateTime"].ToString()+", Broken from the Appts module.",
				PIn.Long(ContrApptSingle3[thisI].DataRoww["AptNum"].ToString()));
			long provNum=PIn.Long(ContrApptSingle3[thisI].DataRoww["ProvNum"].ToString());//remember before ModuleSelected
			ModuleSelected(pat.PatNum);
			SetInvalid();
			if(PrefC.GetBool(PrefName.BrokenApptCommLogNotAdjustment)) {
				Commlog CommlogCur=new Commlog();
				CommlogCur.PatNum=pat.PatNum;
				CommlogCur.CommDateTime=DateTime.Now;
				CommlogCur.CommType=Commlogs.GetTypeAuto(CommItemTypeAuto.APPT);
				CommlogCur.Note=Lan.g(this,"Appt BROKEN for ")+apt.ProcDescript+"  "+apt.AptDateTime.ToString();
				CommlogCur.Mode_=CommItemMode.None;
				CommlogCur.UserNum=Security.CurUser.UserNum;
				FormCommItem FormCI=new FormCommItem(CommlogCur);
				FormCI.IsNew=true;
				FormCI.ShowDialog();
			}
			else {
				Adjustment AdjustmentCur=new Adjustment();
				AdjustmentCur.DateEntry=DateTime.Today;
				AdjustmentCur.AdjDate=DateTime.Today;
				AdjustmentCur.ProcDate=DateTime.Today;
				AdjustmentCur.ProvNum=provNum;
				AdjustmentCur.PatNum=pat.PatNum;
				AdjustmentCur.AdjType=PrefC.GetLong(PrefName.BrokenAppointmentAdjustmentType);
				AdjustmentCur.ClinicNum=pat.ClinicNum;
				FormAdjust FormA=new FormAdjust(pat,AdjustmentCur);
				FormA.IsNew=true;
				FormA.ShowDialog();
			}
			AutomationL.Trigger(AutomationTrigger.BreakAppointment,null,pat.PatNum);
			Recalls.SynchScheduledApptFull(apt.PatNum);
		}
Beispiel #4
0
        ///<summary>Sets given appt.AptStatus to broken.
        ///Provide procCode that should be charted, can be null but will not chart a broken procedure.
        ///Also considers various broken procedure based prefs.
        ///Makes its own securitylog entries.</summary>
        public static void BreakApptHelper(Appointment appt, Patient pat, ProcedureCode procCode)
        {
            //suppressHistory is true due to below logic creating a log with a specific HistAppointmentAction instead of the generic changed.
            DateTime datePrevious    = appt.DateTStamp;
            bool     suppressHistory = false;

            if (procCode != null)
            {
                suppressHistory = (procCode.ProcCode.In("D9986", "D9987"));
            }
            Appointments.SetAptStatus(appt, ApptStatus.Broken, suppressHistory); //Appointments S-Class handles Signalods
            if (appt.AptStatus != ApptStatus.Complete)                           //seperate log entry for completed appointments.
            {
                SecurityLogs.MakeLogEntry(Permissions.AppointmentEdit, pat.PatNum,
                                          appt.ProcDescript + ", " + appt.AptDateTime.ToString()
                                          + ", Broken from the Appts module.", appt.AptNum, datePrevious);
            }
            else
            {
                SecurityLogs.MakeLogEntry(Permissions.AppointmentCompleteEdit, pat.PatNum,
                                          appt.ProcDescript + ", " + appt.AptDateTime.ToString()
                                          + ", Broken from the Appts module.", appt.AptNum, datePrevious);
            }
            #region HL7
            //If there is an existing HL7 def enabled, send a SIU message if there is an outbound SIU message defined
            if (HL7Defs.IsExistingHL7Enabled())
            {
                //S15 - Appt Cancellation event
                MessageHL7 messageHL7 = MessageConstructor.GenerateSIU(pat, Patients.GetPat(pat.Guarantor), EventTypeHL7.S15, appt);
                //Will be null if there is no outbound SIU message defined, so do nothing
                if (messageHL7 != null)
                {
                    HL7Msg hl7Msg = new HL7Msg();
                    hl7Msg.AptNum    = appt.AptNum;
                    hl7Msg.HL7Status = HL7MessageStatus.OutPending;                  //it will be marked outSent by the HL7 service.
                    hl7Msg.MsgText   = messageHL7.ToString();
                    hl7Msg.PatNum    = pat.PatNum;
                    HL7Msgs.Insert(hl7Msg);
#if DEBUG
                    MessageBox.Show("Appointments", messageHL7.ToString());
#endif
                }
            }
            #endregion
            #region Charting the proc
            if (procCode != null)
            {
                switch (procCode.ProcCode)
                {
                case "D9986":                        //Missed
                    HistAppointments.CreateHistoryEntry(appt.AptNum, HistAppointmentAction.Missed);
                    break;

                case "D9987":                        //Cancelled
                    HistAppointments.CreateHistoryEntry(appt.AptNum, HistAppointmentAction.Cancelled);
                    break;
                }
                Procedure procedureCur = new Procedure();
                procedureCur.PatNum       = pat.PatNum;
                procedureCur.ProvNum      = (procCode.ProvNumDefault > 0 ? procCode.ProvNumDefault : appt.ProvNum);
                procedureCur.CodeNum      = procCode.CodeNum;
                procedureCur.ProcDate     = DateTime.Today;
                procedureCur.DateEntryC   = DateTime.Now;
                procedureCur.ProcStatus   = ProcStat.C;
                procedureCur.ClinicNum    = appt.ClinicNum;
                procedureCur.UserNum      = Security.CurUser.UserNum;
                procedureCur.Note         = Lans.g("AppointmentEdit", "Appt BROKEN for") + " " + appt.ProcDescript + "  " + appt.AptDateTime.ToString();
                procedureCur.PlaceService = (PlaceOfService)PrefC.GetInt(PrefName.DefaultProcedurePlaceService);              //Default proc place of service for the Practice is used.
                List <InsSub>  listInsSubs    = InsSubs.RefreshForFam(Patients.GetFamily(pat.PatNum));
                List <InsPlan> listInsPlans   = InsPlans.RefreshForSubList(listInsSubs);
                List <PatPlan> listPatPlans   = PatPlans.Refresh(pat.PatNum);
                InsPlan        insPlanPrimary = null;
                InsSub         insSubPrimary  = null;
                if (listPatPlans.Count > 0)
                {
                    insSubPrimary  = InsSubs.GetSub(listPatPlans[0].InsSubNum, listInsSubs);
                    insPlanPrimary = InsPlans.GetPlan(insSubPrimary.PlanNum, listInsPlans);
                }
                double procFee;
                long   feeSch;
                if (insPlanPrimary == null || procCode.NoBillIns)
                {
                    feeSch = FeeScheds.GetFeeSched(0, pat.FeeSched, procedureCur.ProvNum);
                }
                else                  //Only take into account the patient's insurance fee schedule if the D9986 procedure is not marked as NoBillIns
                {
                    feeSch = FeeScheds.GetFeeSched(insPlanPrimary.FeeSched, pat.FeeSched, procedureCur.ProvNum);
                }
                procFee = Fees.GetAmount0(procedureCur.CodeNum, feeSch, procedureCur.ClinicNum, procedureCur.ProvNum);
                if (insPlanPrimary != null && insPlanPrimary.PlanType == "p" && !insPlanPrimary.IsMedical)         //PPO
                {
                    double provFee = Fees.GetAmount0(procedureCur.CodeNum, Providers.GetProv(procedureCur.ProvNum).FeeSched, procedureCur.ClinicNum,
                                                     procedureCur.ProvNum);
                    procedureCur.ProcFee = Math.Max(provFee, procFee);
                }
                else
                {
                    procedureCur.ProcFee = procFee;
                }
                if (!PrefC.GetBool(PrefName.EasyHidePublicHealth))
                {
                    procedureCur.SiteNum = pat.SiteNum;
                }
                Procedures.Insert(procedureCur);
                //Now make a claimproc if the patient has insurance.  We do this now for consistency because a claimproc could get created in the future.
                List <Benefit>   listBenefits          = Benefits.Refresh(listPatPlans, listInsSubs);
                List <ClaimProc> listClaimProcsForProc = ClaimProcs.RefreshForProc(procedureCur.ProcNum);
                Procedures.ComputeEstimates(procedureCur, pat.PatNum, listClaimProcsForProc, false, listInsPlans, listPatPlans, listBenefits, pat.Age, listInsSubs);
                FormProcBroken FormPB = new FormProcBroken(procedureCur);
                FormPB.IsNew = true;
                FormPB.ShowDialog();
            }
            #endregion
            #region BrokenApptAdjustment
            if (PrefC.GetBool(PrefName.BrokenApptAdjustment))
            {
                Adjustment AdjustmentCur = new Adjustment();
                AdjustmentCur.DateEntry = DateTime.Today;
                AdjustmentCur.AdjDate   = DateTime.Today;
                AdjustmentCur.ProcDate  = DateTime.Today;
                AdjustmentCur.ProvNum   = appt.ProvNum;
                AdjustmentCur.PatNum    = pat.PatNum;
                AdjustmentCur.AdjType   = PrefC.GetLong(PrefName.BrokenAppointmentAdjustmentType);
                AdjustmentCur.ClinicNum = appt.ClinicNum;
                FormAdjust FormA = new FormAdjust(pat, AdjustmentCur);
                FormA.IsNew = true;
                FormA.ShowDialog();
            }
            #endregion
            #region BrokenApptCommLog
            if (PrefC.GetBool(PrefName.BrokenApptCommLog))
            {
                Commlog CommlogCur = new Commlog();
                CommlogCur.PatNum       = pat.PatNum;
                CommlogCur.CommDateTime = DateTime.Now;
                CommlogCur.CommType     = Commlogs.GetTypeAuto(CommItemTypeAuto.APPT);
                CommlogCur.Note         = Lan.g("Appointment", "Appt BROKEN for") + " " + appt.ProcDescript + "  " + appt.AptDateTime.ToString();
                CommlogCur.Mode_        = CommItemMode.None;
                CommlogCur.UserNum      = Security.CurUser.UserNum;
                FormCommItem FormCI = new FormCommItem();
                FormCI.ShowDialog(new CommItemModel()
                {
                    CommlogCur = CommlogCur
                }, new CommItemController(FormCI)
                {
                    IsNew = true
                });
            }
            #endregion
            AutomationL.Trigger(AutomationTrigger.BreakAppointment, null, pat.PatNum);
            Recalls.SynchScheduledApptFull(appt.PatNum);
        }
		private void butAddAdjust_Click(object sender, System.EventArgs e) {
			if(ProcCur.ProcStatus!=ProcStat.C){
				MsgBox.Show(this,"Adjustments may only be added to completed procedures.");
				return;
			}
			Adjustment adj=new Adjustment();
			adj.PatNum=PatCur.PatNum;
			adj.ProvNum=ProcCur.ProvNum;
			adj.DateEntry=DateTime.Today;//but will get overwritten to server date
			adj.AdjDate=DateTime.Today;
			adj.ProcDate=ProcCur.ProcDate;
			adj.ProcNum=ProcCur.ProcNum;
			adj.ClinicNum=ProcCur.ClinicNum;
			FormAdjust FormA=new FormAdjust(PatCur,adj);
			FormA.IsNew=true;
			FormA.ShowDialog();
			FillAdj();
		}
Beispiel #6
0
        ///<summary>Sets given appt.AptStatus to broken.
        ///Provide procCode that should be charted, can be null but will not chart a broken procedure.
        ///Also considers various broken procedure based prefs.
        ///Makes its own securitylog entries.</summary>
        public static void BreakApptHelper(Appointment appt, Patient pat, ProcedureCode procCode)
        {
            //suppressHistory is true due to below logic creating a log with a specific HistAppointmentAction instead of the generic changed.
            DateTime datePrevious    = appt.DateTStamp;
            bool     suppressHistory = false;

            if (procCode != null)
            {
                suppressHistory = (procCode.ProcCode.In("D9986", "D9987"));
            }
            Appointments.SetAptStatus(appt, ApptStatus.Broken, suppressHistory); //Appointments S-Class handles Signalods
            if (appt.AptStatus != ApptStatus.Complete)                           //seperate log entry for completed appointments.
            {
                SecurityLogs.MakeLogEntry(Permissions.AppointmentEdit, pat.PatNum,
                                          appt.ProcDescript + ", " + appt.AptDateTime.ToString()
                                          + ", Broken from the Appts module.", appt.AptNum, datePrevious);
            }
            else
            {
                SecurityLogs.MakeLogEntry(Permissions.AppointmentCompleteEdit, pat.PatNum,
                                          appt.ProcDescript + ", " + appt.AptDateTime.ToString()
                                          + ", Broken from the Appts module.", appt.AptNum, datePrevious);
            }
            #region HL7
            //If there is an existing HL7 def enabled, send a SIU message if there is an outbound SIU message defined
            if (HL7Defs.IsExistingHL7Enabled())
            {
                //S15 - Appt Cancellation event
                MessageHL7 messageHL7 = MessageConstructor.GenerateSIU(pat, Patients.GetPat(pat.Guarantor), EventTypeHL7.S15, appt);
                //Will be null if there is no outbound SIU message defined, so do nothing
                if (messageHL7 != null)
                {
                    HL7Msg hl7Msg = new HL7Msg();
                    hl7Msg.AptNum    = appt.AptNum;
                    hl7Msg.HL7Status = HL7MessageStatus.OutPending;                  //it will be marked outSent by the HL7 service.
                    hl7Msg.MsgText   = messageHL7.ToString();
                    hl7Msg.PatNum    = pat.PatNum;
                    HL7Msgs.Insert(hl7Msg);
#if DEBUG
                    MessageBox.Show("Appointments", messageHL7.ToString());
#endif
                }
            }
            #endregion
            List <Procedure> listProcedures = new List <Procedure>();
            //splits should only exist on procs if they are using tp pre-payments
            List <PaySplit> listSplitsForApptProcs = new List <PaySplit>();
            bool            isNonRefundable        = false;
            double          brokenProcAmount       = 0;
            Procedure       brokenProcedure        = new Procedure();
            bool            wasBrokenProcDeleted   = false;
            if (PrefC.GetYN(PrefName.PrePayAllowedForTpProcs))
            {
                listProcedures = Procedures.GetProcsForSingle(appt.AptNum, false);
                if (listProcedures.Count > 0)
                {
                    listSplitsForApptProcs = PaySplits.GetPaySplitsFromProcs(listProcedures.Select(x => x.ProcNum).ToList());
                }
            }
            #region Charting the proc
            if (procCode != null)
            {
                switch (procCode.ProcCode)
                {
                case "D9986":                        //Missed
                    HistAppointments.CreateHistoryEntry(appt.AptNum, HistAppointmentAction.Missed);
                    break;

                case "D9987":                        //Cancelled
                    HistAppointments.CreateHistoryEntry(appt.AptNum, HistAppointmentAction.Cancelled);
                    break;
                }
                brokenProcedure.PatNum       = pat.PatNum;
                brokenProcedure.ProvNum      = (procCode.ProvNumDefault > 0 ? procCode.ProvNumDefault : appt.ProvNum);
                brokenProcedure.CodeNum      = procCode.CodeNum;
                brokenProcedure.ProcDate     = DateTime.Today;
                brokenProcedure.DateEntryC   = DateTime.Now;
                brokenProcedure.ProcStatus   = ProcStat.C;
                brokenProcedure.ClinicNum    = appt.ClinicNum;
                brokenProcedure.UserNum      = Security.CurUser.UserNum;
                brokenProcedure.Note         = Lans.g("AppointmentEdit", "Appt BROKEN for") + " " + appt.ProcDescript + "  " + appt.AptDateTime.ToString();
                brokenProcedure.PlaceService = (PlaceOfService)PrefC.GetInt(PrefName.DefaultProcedurePlaceService);              //Default proc place of service for the Practice is used.
                List <InsSub>  listInsSubs    = InsSubs.RefreshForFam(Patients.GetFamily(pat.PatNum));
                List <InsPlan> listInsPlans   = InsPlans.RefreshForSubList(listInsSubs);
                List <PatPlan> listPatPlans   = PatPlans.Refresh(pat.PatNum);
                InsPlan        insPlanPrimary = null;
                InsSub         insSubPrimary  = null;
                if (listPatPlans.Count > 0)
                {
                    insSubPrimary  = InsSubs.GetSub(listPatPlans[0].InsSubNum, listInsSubs);
                    insPlanPrimary = InsPlans.GetPlan(insSubPrimary.PlanNum, listInsPlans);
                }
                double procFee;
                long   feeSch;
                if (insPlanPrimary == null || procCode.NoBillIns)
                {
                    feeSch = FeeScheds.GetFeeSched(0, pat.FeeSched, brokenProcedure.ProvNum);
                }
                else                  //Only take into account the patient's insurance fee schedule if the D9986 procedure is not marked as NoBillIns
                {
                    feeSch = FeeScheds.GetFeeSched(insPlanPrimary.FeeSched, pat.FeeSched, brokenProcedure.ProvNum);
                }
                procFee = Fees.GetAmount0(brokenProcedure.CodeNum, feeSch, brokenProcedure.ClinicNum, brokenProcedure.ProvNum);
                if (insPlanPrimary != null && insPlanPrimary.PlanType == "p" && !insPlanPrimary.IsMedical)         //PPO
                {
                    double provFee = Fees.GetAmount0(brokenProcedure.CodeNum, Providers.GetProv(brokenProcedure.ProvNum).FeeSched, brokenProcedure.ClinicNum,
                                                     brokenProcedure.ProvNum);
                    brokenProcedure.ProcFee = Math.Max(provFee, procFee);
                }
                else if (listSplitsForApptProcs.Count > 0 && PrefC.GetBool(PrefName.TpPrePayIsNonRefundable) && procCode.ProcCode == "D9986")
                {
                    //if there are pre-payments, non-refundable pre-payments is turned on, and the broken appointment is a missed code then auto-fill
                    //the window with the sum of the procs for the appointment. Transfer money below after broken procedure is confirmed by the user.
                    brokenProcedure.ProcFee = listSplitsForApptProcs.Sum(x => x.SplitAmt);
                    isNonRefundable         = true;
                }
                else
                {
                    brokenProcedure.ProcFee = procFee;
                }
                if (!PrefC.GetBool(PrefName.EasyHidePublicHealth))
                {
                    brokenProcedure.SiteNum = pat.SiteNum;
                }
                Procedures.Insert(brokenProcedure);
                //Now make a claimproc if the patient has insurance.  We do this now for consistency because a claimproc could get created in the future.
                List <Benefit>   listBenefits          = Benefits.Refresh(listPatPlans, listInsSubs);
                List <ClaimProc> listClaimProcsForProc = ClaimProcs.RefreshForProc(brokenProcedure.ProcNum);
                Procedures.ComputeEstimates(brokenProcedure, pat.PatNum, listClaimProcsForProc, false, listInsPlans, listPatPlans, listBenefits, pat.Age, listInsSubs);
                FormProcBroken FormPB = new FormProcBroken(brokenProcedure, isNonRefundable);
                FormPB.IsNew = true;
                FormPB.ShowDialog();
                brokenProcAmount     = FormPB.AmountTotal;
                wasBrokenProcDeleted = FormPB.IsProcDeleted;
            }
            #endregion
            #region BrokenApptAdjustment
            if (PrefC.GetBool(PrefName.BrokenApptAdjustment))
            {
                Adjustment AdjustmentCur = new Adjustment();
                AdjustmentCur.DateEntry = DateTime.Today;
                AdjustmentCur.AdjDate   = DateTime.Today;
                AdjustmentCur.ProcDate  = DateTime.Today;
                AdjustmentCur.ProvNum   = appt.ProvNum;
                AdjustmentCur.PatNum    = pat.PatNum;
                AdjustmentCur.AdjType   = PrefC.GetLong(PrefName.BrokenAppointmentAdjustmentType);
                AdjustmentCur.ClinicNum = appt.ClinicNum;
                FormAdjust FormA = new FormAdjust(pat, AdjustmentCur);
                FormA.IsNew = true;
                FormA.ShowDialog();
            }
            #endregion
            #region BrokenApptCommLog
            if (PrefC.GetBool(PrefName.BrokenApptCommLog))
            {
                Commlog commlogCur = new Commlog();
                commlogCur.PatNum       = pat.PatNum;
                commlogCur.CommDateTime = DateTime.Now;
                commlogCur.CommType     = Commlogs.GetTypeAuto(CommItemTypeAuto.APPT);
                commlogCur.Note         = Lan.g("Appointment", "Appt BROKEN for") + " " + appt.ProcDescript + "  " + appt.AptDateTime.ToString();
                commlogCur.Mode_        = CommItemMode.None;
                commlogCur.UserNum      = Security.CurUser.UserNum;
                commlogCur.IsNew        = true;
                FormCommItem FormCI = new FormCommItem(commlogCur);
                FormCI.ShowDialog();
            }
            #endregion
            #region Transfer money from TP Procedures if necessary
            //Note this MUST come after FormProcBroken since clicking cancel in that window will delete the procedure.
            if (isNonRefundable && !wasBrokenProcDeleted && listSplitsForApptProcs.Count > 0)
            {
                //transfer what the user specified in the broken appointment window.
                //transfer up to the amount specified by the user
                foreach (Procedure proc in listProcedures)
                {
                    if (brokenProcAmount == 0)
                    {
                        break;
                    }
                    List <PaySplit> listSplitsForAppointmentProcedure = listSplitsForApptProcs.FindAll(x => x.ProcNum == proc.ProcNum);
                    foreach (PaySplit split in listSplitsForAppointmentProcedure)
                    {
                        if (brokenProcAmount == 0)
                        {
                            break;
                        }
                        double amt = Math.Min(brokenProcAmount, split.SplitAmt);
                        Payments.CreateTransferForTpProcs(proc, new List <PaySplit> {
                            split
                        }, brokenProcedure, amt);
                        double amtPaidOnApt = listSplitsForApptProcs.Sum(x => x.SplitAmt);
                        if (amtPaidOnApt > amt)
                        {
                            //If the original prepayment amount is greater than the amt being specified for the appointment break, transfer
                            //the difference to an Unallocated Unearned Paysplit on the account.
                            double remainingAmt = amtPaidOnApt - amt;
                            //We have to create a new transfer payment here to correlate to the split.
                            Payment txfrPayment = new Payment();
                            txfrPayment.PayAmt    = 0;
                            txfrPayment.PayDate   = DateTime.Today;
                            txfrPayment.ClinicNum = split.ClinicNum;
                            txfrPayment.PayNote   = "Automatic transfer from treatment planned procedure prepayment.";
                            txfrPayment.PatNum    = split.PatNum;                       //ultimately where the payment ends up.
                            txfrPayment.PayType   = 0;
                            Payments.Insert(txfrPayment);
                            PaymentEdit.IncomeTransferData transferData = PaymentEdit.IncomeTransferData.CreateTransfer(split, txfrPayment.PayNum, true, remainingAmt);
                            PaySplit offset         = transferData.ListSplitsCur.FirstOrDefault(x => x.FSplitNum != 0);
                            long     offsetSplitNum = PaySplits.Insert(offset);                      //Get the FSplitNum from the offset
                            PaySplit allocation     = transferData.ListSplitsCur.FirstOrDefault(x => x.FSplitNum == 0);
                            allocation.FSplitNum = offsetSplitNum;
                            PaySplits.Insert(allocation);                            //Insert so the split is now up to date
                            SecurityLogs.MakeLogEntry(Permissions.PaymentCreate, txfrPayment.PatNum, "Automatic transfer of funds for treatment plan procedure pre-payments.");
                        }
                        brokenProcAmount -= amt;
                    }
                }
            }
            //if broken appointment procedure was deleted (user cancelled out of the window) just keep money on the original procedure.
            #endregion
            AppointmentEvent.Fire(ODEventType.AppointmentEdited, appt);
            AutomationL.Trigger(AutomationTrigger.BreakAppointment, null, pat.PatNum);
            Recalls.SynchScheduledApptFull(appt.PatNum);
        }
Beispiel #7
0
		///<summary>Called from butOK_Click and butPin_Click</summary>
		private bool UpdateToDB(){
			DateTime dateTimeAskedToArrive=DateTime.MinValue;
			if((AptOld.AptStatus==ApptStatus.Complete && comboStatus.SelectedIndex!=1)
				|| (AptOld.AptStatus==ApptStatus.Broken && comboStatus.SelectedIndex!=4)) //Un-completing or un-breaking the appt.  We must use selectedindex due to AptCur gets updated later UpdateDB()
			{
				//If the insurance plans have changed since this appt was completed, warn the user that the historical data will be neutralized.
				List<PatPlan> listPatPlans=PatPlans.Refresh(pat.PatNum);
				InsSub sub1=InsSubs.GetSub(PatPlans.GetInsSubNum(listPatPlans,PatPlans.GetOrdinal(PriSecMed.Primary,listPatPlans,PlanList,SubList)),SubList);
				InsSub sub2=InsSubs.GetSub(PatPlans.GetInsSubNum(listPatPlans,PatPlans.GetOrdinal(PriSecMed.Secondary,listPatPlans,PlanList,SubList)),SubList);
				if(sub1.PlanNum!=AptCur.InsPlan1 || sub2.PlanNum!=AptCur.InsPlan2) {
					if(!MsgBox.Show(this,MsgBoxButtons.OKCancel,"The current insurance plans for this patient are different than the plans associated to this appointment.  They will be updated to the patient's current insurance plans.  Continue?")) {
						return false;
					}
					//Update the ins plans associated to this appointment so that they're the most accurate at this time.
					AptCur.InsPlan1=sub1.PlanNum;
					AptCur.InsPlan2=sub2.PlanNum;
				}
			}
			if(textTimeAskedToArrive.Text!=""){
				try{
					dateTimeAskedToArrive=AptCur.AptDateTime.Date+DateTime.Parse(textTimeAskedToArrive.Text).TimeOfDay;
				}
				catch{
					MsgBox.Show(this,"Time Asked To Arrive invalid.");
					return false;
				}
			}
			DateTime dateTimeArrived=AptCur.AptDateTime.Date;
			if(textTimeArrived.Text!=""){
				try{
					dateTimeArrived=AptCur.AptDateTime.Date+DateTime.Parse(textTimeArrived.Text).TimeOfDay;
				}
				catch{
					MsgBox.Show(this,"Time Arrived invalid.");
					return false;
				}
			}
			DateTime dateTimeSeated=AptCur.AptDateTime.Date;
			if(textTimeSeated.Text!=""){
				try{
					dateTimeSeated=AptCur.AptDateTime.Date+DateTime.Parse(textTimeSeated.Text).TimeOfDay;
				}
				catch{
					MsgBox.Show(this,"Time Seated invalid.");
					return false;
				}
			}
			DateTime dateTimeDismissed=AptCur.AptDateTime.Date;
			if(textTimeDismissed.Text!=""){
				try{
					dateTimeDismissed=AptCur.AptDateTime.Date+DateTime.Parse(textTimeDismissed.Text).TimeOfDay;
				}
				catch{
					MsgBox.Show(this,"Time Arrived invalid.");
					return false;
				}
			}
			//This change was just slightly too risky to make to 6.9, so 7.0 only
			if(AptCur.AptStatus!=ApptStatus.Complete//was not originally complete
				&& AptCur.AptStatus!=ApptStatus.PtNote
				&& AptCur.AptStatus!=ApptStatus.PtNoteCompleted
				&& comboStatus.SelectedIndex==1 //making it complete
				&& AptCur.AptDateTime.Date > DateTime.Today)//and future appt
			{
				MsgBox.Show(this,"Not allowed to set complete future appointments.");
				return false;
			}
			string aptPattern=Appointments.ConvertPatternTo5(strBTime.ToString());
			//Only run appt overlap check if editing an appt not in unscheduled list and in chart module and eCW program link not enabled.
			if((IsInChartModule || IsInViewPatAppts) && !Programs.UsingEcwTightOrFullMode() && AptCur.AptStatus!=ApptStatus.UnschedList) {
				//==Travis 04/06/2015:  This call was added on 04/23/2014 and backported to 14.1.  It is not storing the return value and does not look to be
				//		doing anything so it has been commented out.
				//Appointments.RefreshPeriod(AptCur.AptDateTime,AptCur.AptDateTime);
				List<Appointment> apptList=Appointments.GetForPeriodList(AptCur.AptDateTime,AptCur.AptDateTime);
				if(DoesOverlap(aptPattern,apptList)) {
					MsgBox.Show(this,"Appointment is too long and would overlap another appointment.  Automatically shortened to fit.");
					do {
						aptPattern=aptPattern.Substring(0,aptPattern.Length-1);
						if(aptPattern.Length==1) {
							break;
						}
					} while(DoesOverlap(aptPattern,apptList));
				}
			}
			if(AptCur.AptStatus == ApptStatus.Planned) {
				;
			}
			else if(comboStatus.SelectedIndex==-1) {
				AptCur.AptStatus=ApptStatus.Scheduled;
			}
			else if (AptCur.AptStatus == ApptStatus.PtNote | AptCur.AptStatus == ApptStatus.PtNoteCompleted){
				AptCur.AptStatus = (ApptStatus)comboStatus.SelectedIndex + 7;
			}
			else {
				AptCur.AptStatus=(ApptStatus)comboStatus.SelectedIndex+1;
			}
			//set procs complete was moved further down
			//convert from current increment into 5 minute increment
			//MessageBox.Show(strBTime.ToString());
			AptCur.Pattern=aptPattern;
			if(comboUnschedStatus.SelectedIndex==0){//none
				AptCur.UnschedStatus=0;
			}
			else{
				AptCur.UnschedStatus=DefC.Short[(int)DefCat.RecallUnschedStatus][comboUnschedStatus.SelectedIndex-1].DefNum;
			}
			if(comboConfirmed.SelectedIndex!=-1){
				AptCur.Confirmed=DefC.Short[(int)DefCat.ApptConfirmed][comboConfirmed.SelectedIndex].DefNum;
			}
			AptCur.TimeLocked=checkTimeLocked.Checked;
			AptCur.ColorOverride=butColor.BackColor;
			AptCur.Note=textNote.Text;
			if(comboClinic.SelectedIndex==0) {//none
				AptCur.ClinicNum=0;
			}
			else {
				AptCur.ClinicNum=Clinics.List[comboClinic.SelectedIndex-1].ClinicNum;
			}
			//there should always be a non-hidden primary provider for an appt.
			if(comboProvNum.SelectedIndex==-1) {
				AptCur.ProvNum=ProviderC.ListShort[0].ProvNum;
			}
			else {
				AptCur.ProvNum=ProviderC.ListShort[comboProvNum.SelectedIndex].ProvNum;
			}
			if(comboProvHyg.SelectedIndex==0) {//none
				AptCur.ProvHyg=0;
			}
			else {
				AptCur.ProvHyg=ProviderC.ListShort[comboProvHyg.SelectedIndex-1].ProvNum;
			}
			AptCur.IsHygiene=checkIsHygiene.Checked;
			if(comboAssistant.SelectedIndex==0) {//none
				AptCur.Assistant=0;
			}
			else {
				AptCur.Assistant=Employees.ListShort[comboAssistant.SelectedIndex-1].EmployeeNum;
			}
			AptCur.IsNewPatient=checkIsNewPatient.Checked;
			AptCur.DateTimeAskedToArrive=dateTimeAskedToArrive;
			AptCur.DateTimeArrived=dateTimeArrived;
			AptCur.DateTimeSeated=dateTimeSeated;
			AptCur.DateTimeDismissed=dateTimeDismissed;
			//AptCur.InsPlan1 and InsPlan2 already handled 
			//The ApptProcDescript region is also in FormProcEdit.SaveAndClose() and FormDatabaseMaintenance.butApptProcs_Click()  Make any changes there as well.
			#region ApptProcDescript
			AptCur.ProcDescript="";
			AptCur.ProcsColored="";
			for(int i=0;i<gridProc.SelectedIndices.Length;i++) {
				string procDescOne="";
				string procCode=DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["ProcCode"].ToString();
				if(i>0){
					AptCur.ProcDescript+=", ";
				}
				switch(DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["TreatArea"].ToString()) {
				  case "1"://TreatmentArea.Surf:
				    procDescOne+="#"+Tooth.GetToothLabel(DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["ToothNum"].ToString())+"-"
				      +DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["Surf"].ToString()+"-";//""#12-MOD-"
				    break;
				  case "2"://TreatmentArea.Tooth:
				    procDescOne+="#"+Tooth.GetToothLabel(DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["ToothNum"].ToString())+"-";//"#12-"
				    break;
				  default://area 3 or 0 (mouth)
				    break;
				  case "4"://TreatmentArea.Quad:
				    procDescOne+=DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["Surf"].ToString()+"-";//"UL-"
				    break;
				  case "5"://TreatmentArea.Sextant:
				    procDescOne+="S"+DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["Surf"].ToString()+"-";//"S2-"
				    break;
				  case "6"://TreatmentArea.Arch:
				    procDescOne+=DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["Surf"].ToString()+"-";//"U-"
				    break;
				  case "7"://TreatmentArea.ToothRange:
				    //strLine+=table.Rows[j][13].ToString()+" ";//don't show range
				    break;
				}
				procDescOne+=DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["AbbrDesc"].ToString();
				AptCur.ProcDescript+=procDescOne;
				//Color and previous date are determined by ProcApptColor object
				ProcApptColor pac=ProcApptColors.GetMatch(procCode);
				System.Drawing.Color pColor=System.Drawing.Color.Black;
				string prevDateString="";
				if(pac!=null){
					pColor=pac.ColorText;
					if(pac.ShowPreviousDate) {
						prevDateString=Procedures.GetRecentProcDateString(AptCur.PatNum,AptCur.AptDateTime,pac.CodeRange);
						if(prevDateString!="") {
							prevDateString=" ("+prevDateString+")";
						}
					}
				}
				AptCur.ProcsColored+="<span color=\""+pColor.ToArgb().ToString()+"\">"+procDescOne+prevDateString+"</span>";
			}
			#endregion
			bool isPlanned=AptCur.AptStatus==ApptStatus.Planned;
			if(comboApptType.SelectedIndex==0) {//0 index = none.
				AptCur.AppointmentTypeNum=0;
			}
			else {
				AptCur.AppointmentTypeNum=_listAppointmentType[comboApptType.SelectedIndex-1].AppointmentTypeNum;
			}
			try {
				Appointments.Update(AptCur,AptOld);
				//Appointments.UpdateAttached(AptCur.AptNum,procNums,isPlanned);
			}
			catch(ApplicationException ex) {
				MessageBox.Show(ex.Message);
				return false;
			}
			//if appointment is marked complete and any procedures are not,
			//then set the remaining procedures complete
			if(AptCur.AptStatus==ApptStatus.Complete) {
				bool allProcsComplete=true;
				for(int i=0;i<gridProc.SelectedIndices.Length;i++){
					if(DS.Tables["Procedure"].Rows[gridProc.SelectedIndices[i]]["ProcStatus"].ToString()!="2") {//Complete
						allProcsComplete=false;
						break;
					}
				}
				if(!allProcsComplete) {
					if(!Security.IsAuthorized(Permissions.ProcComplCreate,AptCur.AptDateTime)) {
						return false;
					}
					List <PatPlan> PatPlanList=PatPlans.Refresh(AptCur.PatNum);
					ProcedureL.SetCompleteInAppt(AptCur,PlanList,PatPlanList,pat.SiteNum,pat.Age,SubList);
					SecurityLogs.MakeLogEntry(Permissions.AppointmentEdit,pat.PatNum,
						AptCur.AptDateTime.ToShortDateString()+", "+AptCur.ProcDescript+", Procedures automatically set complete due to appt being set complete",AptCur.AptNum);
				}
			}
			else{
				Procedures.SetProvidersInAppointment(AptCur,Procedures.GetProcsForSingle(AptCur.AptNum,false));
			}
			//Do the appointment "break" automation for appointments that were just broken.
			if(AptCur.AptStatus==ApptStatus.Broken && AptOld.AptStatus!=ApptStatus.Broken) {
				SecurityLogs.MakeLogEntry(Permissions.AppointmentMove,pat.PatNum,AptCur.ProcDescript+", "+AptCur.AptDateTime.ToString()
					+", Broken by changing the Status in the Edit Appointment window.",AptCur.AptNum);
				//If there is an existing HL7 def enabled, send a SIU message if there is an outbound SIU message defined
				if(HL7Defs.IsExistingHL7Enabled()) {
					//S15 - Appt Cancellation event
					MessageHL7 messageHL7=MessageConstructor.GenerateSIU(pat,fam.GetPatient(pat.Guarantor),EventTypeHL7.S15,AptCur);
					//Will be null if there is no outbound SIU message defined, so do nothing
					if(messageHL7!=null) {
						HL7Msg hl7Msg=new HL7Msg();
						hl7Msg.AptNum=AptCur.AptNum;
						hl7Msg.HL7Status=HL7MessageStatus.OutPending;//it will be marked outSent by the HL7 service.
						hl7Msg.MsgText=messageHL7.ToString();
						hl7Msg.PatNum=pat.PatNum;
						HL7Msgs.Insert(hl7Msg);
#if DEBUG
						MessageBox.Show(this,messageHL7.ToString());
#endif
					}
				}
				ProcedureCode procCodeBrokenApt=ProcedureCodes.GetProcCode("D9986");
				if(procCodeBrokenApt.CodeNum!=0) {//ADA proc code D9986 exists
					Procedure procedureCur=new Procedure();
					procedureCur.PatNum=pat.PatNum;
					procedureCur.ProvNum=AptCur.ProvNum;
					procedureCur.ProcFee=0;
					procedureCur.CodeNum=procCodeBrokenApt.CodeNum;
					procedureCur.ProcDate=DateTime.Today;
					procedureCur.DateEntryC=DateTime.Now;
					procedureCur.ProcStatus=ProcStat.C;
					procedureCur.ClinicNum=pat.ClinicNum;
					procedureCur.Note=Lan.g(this,"Appt BROKEN for ")+AptCur.ProcDescript+"  "+AptCur.AptDateTime.ToString();
					Procedures.Insert(procedureCur);
					//Now make a claimproc if the patient has insurance.  We do this now for consistency because a claimproc could get created in the future.
					List<InsSub> listInsSubs=InsSubs.RefreshForFam(Patients.GetFamily(pat.PatNum));
					List<InsPlan> listInsPlans=InsPlans.RefreshForSubList(listInsSubs);
					List<PatPlan> listPatPlans=PatPlans.Refresh(pat.PatNum);
					List<Benefit> listBenefits=Benefits.Refresh(listPatPlans,listInsSubs);
					List<ClaimProc> listClaimProcsForProc=ClaimProcs.RefreshForProc(procedureCur.ProcNum);
					Procedures.ComputeEstimates(procedureCur,pat.PatNum,listClaimProcsForProc,false,listInsPlans,listPatPlans,listBenefits,pat.Age,listInsSubs);
					FormProcEdit FormP=new FormProcEdit(procedureCur,pat,Patients.GetFamily(pat.PatNum));
					FormP.IsNew=false;
					FormP.ShowDialog();
					if(PrefC.GetBool(PrefName.BrokenApptCommLogWithProcedure)) {
						Commlog CommlogCur=new Commlog();
						CommlogCur.PatNum=pat.PatNum;
						CommlogCur.CommDateTime=DateTime.Now;
						CommlogCur.CommType=Commlogs.GetTypeAuto(CommItemTypeAuto.APPT);
						CommlogCur.Note=Lan.g(this,"Appt BROKEN for ")+AptCur.ProcDescript+"  "+AptCur.AptDateTime.ToString();
						CommlogCur.Mode_=CommItemMode.None;
						CommlogCur.UserNum=Security.CurUser.UserNum;
						FormCommItem FormCI=new FormCommItem(CommlogCur);
						FormCI.IsNew=true;
						FormCI.ShowDialog();
					}
				}
				else {//No D9986 present
					if(PrefC.GetBool(PrefName.BrokenApptCommLogNotAdjustment)) {
						Commlog CommlogCur=new Commlog();
						CommlogCur.PatNum=pat.PatNum;
						CommlogCur.CommDateTime=DateTime.Now;
						CommlogCur.CommType=Commlogs.GetTypeAuto(CommItemTypeAuto.APPT);
						CommlogCur.Note=Lan.g(this,"Appt BROKEN for ")+AptCur.ProcDescript+"  "+AptCur.AptDateTime.ToString();
						CommlogCur.Mode_=CommItemMode.None;
						CommlogCur.UserNum=Security.CurUser.UserNum;
						FormCommItem FormCI=new FormCommItem(CommlogCur);
						FormCI.IsNew=true;
						FormCI.ShowDialog();
					}
					else {
						Adjustment AdjustmentCur=new Adjustment();
						AdjustmentCur.DateEntry=DateTime.Today;
						AdjustmentCur.AdjDate=DateTime.Today;
						AdjustmentCur.ProcDate=DateTime.Today;
						AdjustmentCur.ProvNum=AptCur.ProvNum;
						AdjustmentCur.PatNum=pat.PatNum;
						AdjustmentCur.AdjType=PrefC.GetLong(PrefName.BrokenAppointmentAdjustmentType);
						AdjustmentCur.ClinicNum=pat.ClinicNum;
						FormAdjust FormA=new FormAdjust(pat,AdjustmentCur);
						FormA.IsNew=true;
						FormA.ShowDialog();
					}
				}
				AutomationL.Trigger(AutomationTrigger.BreakAppointment,null,pat.PatNum);
			}
			return true;
		}
		private void toolBarButAdj_Click() {
			Adjustment AdjustmentCur=new Adjustment();
			AdjustmentCur.DateEntry=DateTime.Today;//cannot be changed. Handled automatically
			AdjustmentCur.AdjDate=DateTime.Today;
			AdjustmentCur.ProcDate=DateTime.Today;
			AdjustmentCur.ProvNum=PatCur.PriProv;
			AdjustmentCur.PatNum=PatCur.PatNum;
			AdjustmentCur.ClinicNum=PatCur.ClinicNum;
			FormAdjust FormAdjust2=new FormAdjust(PatCur,AdjustmentCur);
			FormAdjust2.IsNew=true;
			FormAdjust2.ShowDialog();
			//Shared.ComputeBalances();
			ModuleSelected(PatCur.PatNum);
		}
		private void gridAccount_CellDoubleClick(object sender, OpenDental.UI.ODGridClickEventArgs e) {
			if(ViewingInRecall) return;
			Actscrollval=gridAccount.ScrollValue;
			DataTable table=DataSetMain.Tables["account"];
			if(table.Rows[e.Row]["ProcNum"].ToString()!="0"){
				Procedure proc=Procedures.GetOneProc(PIn.Long(table.Rows[e.Row]["ProcNum"].ToString()),true);
				Patient pat=FamCur.GetPatient(proc.PatNum);
				FormProcEdit FormPE=new FormProcEdit(proc,pat,FamCur);
				FormPE.ShowDialog();
			}
			else if(table.Rows[e.Row]["AdjNum"].ToString()!="0"){
				Adjustment adj=Adjustments.GetOne(PIn.Long(table.Rows[e.Row]["AdjNum"].ToString()));
				FormAdjust FormAdj=new FormAdjust(PatCur,adj);
				FormAdj.ShowDialog();
			}
			else if(table.Rows[e.Row]["PayNum"].ToString()!="0"){
				Payment PaymentCur=Payments.GetPayment(PIn.Long(table.Rows[e.Row]["PayNum"].ToString()));
				/*
				if(PaymentCur.PayType==0){//provider income transfer
					FormProviderIncTrans FormPIT=new FormProviderIncTrans();
					FormPIT.PatNum=PatCur.PatNum;
					FormPIT.PaymentCur=PaymentCur;
					FormPIT.IsNew=false;
					FormPIT.ShowDialog();
				}
				else{*/
				FormPayment FormPayment2=new FormPayment(PatCur,FamCur,PaymentCur);
				FormPayment2.IsNew=false;
				FormPayment2.ShowDialog();
				//}
			}
			else if(table.Rows[e.Row]["ClaimNum"].ToString()!="0"){//claims and claimpayments
				Claim claim=Claims.GetClaim(PIn.Long(table.Rows[e.Row]["ClaimNum"].ToString()));
				Patient pat=FamCur.GetPatient(claim.PatNum);
				FormClaimEdit FormClaimEdit2=new FormClaimEdit(claim,pat,FamCur);
				FormClaimEdit2.IsNew=false;
				FormClaimEdit2.ShowDialog();
			}
			else if(table.Rows[e.Row]["StatementNum"].ToString()!="0"){
				Statement stmt=Statements.CreateObject(PIn.Long(table.Rows[e.Row]["StatementNum"].ToString()));
				FormStatementOptions FormS=new FormStatementOptions();
				FormS.StmtCur=stmt;
				FormS.ShowDialog();
			}
			else if(table.Rows[e.Row]["PayPlanNum"].ToString()!="0"){
				PayPlan payplan=PayPlans.GetOne(PIn.Long(table.Rows[e.Row]["PayPlanNum"].ToString()));
				FormPayPlan2=new FormPayPlan(PatCur,payplan);
				FormPayPlan2.ShowDialog();
				if(FormPayPlan2.GotoPatNum!=0){
					ModuleSelected(FormPayPlan2.GotoPatNum,false);
					return;
				}
			}
			bool isSelectingFamily=gridAcctPat.GetSelectedIndex()==this.DataSetMain.Tables["patient"].Rows.Count-1;
			ModuleSelected(PatCur.PatNum,isSelectingFamily);
		}
Beispiel #10
0
		private void OnBreak_Click() {
			if(!PrefC.GetBool(PrefName.BrokenApptCommLogNotAdjustment) && PrefC.GetLong(PrefName.BrokenAppointmentAdjustmentType)==0) {
				MsgBox.Show(this,"Broken appointment adjustment type is not setup yet.  Please go to Setup | Modules to fix this.");
				return;
			}
			int thisI=GetIndex(ContrApptSingle.SelectedAptNum);
			if(thisI==-1) {//selected appt is on a different day
				MsgBox.Show(this,"Please select an appointment first.");
				return;
			}
			Appointment apt = Appointments.GetOneApt(ContrApptSingle.SelectedAptNum);
			Patient pat=Patients.GetPat(PIn.Long(ContrApptSingle3[thisI].DataRoww["PatNum"].ToString()));
			if(!Security.IsAuthorized(Permissions.AppointmentEdit)) {
				return;
			}
			if(apt.AptStatus == ApptStatus.PtNote || apt.AptStatus == ApptStatus.PtNoteCompleted) {
				MsgBox.Show(this,"Only appointments may be broken, not notes.");
				return;
			}
			if(PrefC.GetBool(PrefName.BrokenApptCommLogNotAdjustment)) {
				if(!MsgBox.Show(this,true,"Break appointment?")) {
					return;
				}
			}
			Appointments.SetAptStatus(ContrApptSingle.SelectedAptNum,ApptStatus.Broken);
			SecurityLogs.MakeLogEntry(Permissions.AppointmentMove,pat.PatNum,
				ContrApptSingle3[thisI].DataRoww["procs"].ToString()+", "+ContrApptSingle3[thisI].DataRoww["AptDateTime"].ToString()+", Broken from the Appts module.",
				PIn.Long(ContrApptSingle3[thisI].DataRoww["AptNum"].ToString()));
			//If there is an existing HL7 def enabled, send a SIU message if there is an outbound SIU message defined
			if(HL7Defs.IsExistingHL7Enabled()) {
				//S15 - Appt Cancellation event
				MessageHL7 messageHL7=MessageConstructor.GenerateSIU(pat,Patients.GetPat(pat.Guarantor),EventTypeHL7.S15,apt);
				//Will be null if there is no outbound SIU message defined, so do nothing
				if(messageHL7!=null) {
					HL7Msg hl7Msg=new HL7Msg();
					hl7Msg.AptNum=apt.AptNum;
					hl7Msg.HL7Status=HL7MessageStatus.OutPending;//it will be marked outSent by the HL7 service.
					hl7Msg.MsgText=messageHL7.ToString();
					hl7Msg.PatNum=pat.PatNum;
					HL7Msgs.Insert(hl7Msg);
#if DEBUG
					MessageBox.Show(this,messageHL7.ToString());
#endif
				}
			}
			long provNum=PIn.Long(ContrApptSingle3[thisI].DataRoww["ProvNum"].ToString());//remember before ModuleSelected
			ProcedureCode procCodeBrokenApt=ProcedureCodes.GetProcCode("D9986");
			if(procCodeBrokenApt.CodeNum!=0) {//ADA proc code D9986 exists
				Procedure procedureCur=new Procedure();
				procedureCur.PatNum=pat.PatNum;
				procedureCur.ProvNum=provNum;
				procedureCur.ProcFee=0;
				procedureCur.CodeNum=procCodeBrokenApt.CodeNum;
				procedureCur.ProcDate=DateTime.Today;
				procedureCur.DateEntryC=DateTime.Now;
				procedureCur.ProcStatus=ProcStat.C;
				procedureCur.ClinicNum=pat.ClinicNum;
				procedureCur.Note=Lan.g(this,"Appt BROKEN for ")+apt.ProcDescript+"  "+apt.AptDateTime.ToString();
				Procedures.Insert(procedureCur);
				//Now make a claimproc if the patient has insurance.  We do this now for consistency because a claimproc could get created in the future.
				List<InsSub> listInsSubs=InsSubs.RefreshForFam(Patients.GetFamily(pat.PatNum));
				List<InsPlan> listInsPlans=InsPlans.RefreshForSubList(listInsSubs);
				List<PatPlan> listPatPlans=PatPlans.Refresh(pat.PatNum);
				List<Benefit> listBenefits=Benefits.Refresh(listPatPlans,listInsSubs);
				List<ClaimProc> listClaimProcsForProc=ClaimProcs.RefreshForProc(procedureCur.ProcNum);
				Procedures.ComputeEstimates(procedureCur,pat.PatNum,listClaimProcsForProc,false,listInsPlans,listPatPlans,listBenefits,pat.Age,listInsSubs);
				FormProcEdit formP=new FormProcEdit(procedureCur,pat,Patients.GetFamily(pat.PatNum));
				formP.IsNew=false;
				formP.ShowDialog();
				if(PrefC.GetBool(PrefName.BrokenApptCommLogWithProcedure)) {
					Commlog CommlogCur=new Commlog();
					CommlogCur.PatNum=pat.PatNum;
					CommlogCur.CommDateTime=DateTime.Now;
					CommlogCur.CommType=Commlogs.GetTypeAuto(CommItemTypeAuto.APPT);
					CommlogCur.Note=Lan.g(this,"Appt BROKEN for ")+apt.ProcDescript+"  "+apt.AptDateTime.ToString();
					CommlogCur.Mode_=CommItemMode.None;
					CommlogCur.UserNum=Security.CurUser.UserNum;
					FormCommItem FormCI=new FormCommItem(CommlogCur);
					FormCI.IsNew=true;
					FormCI.ShowDialog();
				}
			}
			else {//No D9986 present
				if(PrefC.GetBool(PrefName.BrokenApptCommLogNotAdjustment)) {
					Commlog CommlogCur=new Commlog();
					CommlogCur.PatNum=pat.PatNum;
					CommlogCur.CommDateTime=DateTime.Now;
					CommlogCur.CommType=Commlogs.GetTypeAuto(CommItemTypeAuto.APPT);
					CommlogCur.Note=Lan.g(this,"Appt BROKEN for ")+apt.ProcDescript+"  "+apt.AptDateTime.ToString();
					CommlogCur.Mode_=CommItemMode.None;
					CommlogCur.UserNum=Security.CurUser.UserNum;
					FormCommItem FormCI=new FormCommItem(CommlogCur);
					FormCI.IsNew=true;
					FormCI.ShowDialog();
				}
				else {
					Adjustment AdjustmentCur=new Adjustment();
					AdjustmentCur.DateEntry=DateTime.Today;
					AdjustmentCur.AdjDate=DateTime.Today;
					AdjustmentCur.ProcDate=DateTime.Today;
					AdjustmentCur.ProvNum=provNum;
					AdjustmentCur.PatNum=pat.PatNum;
					AdjustmentCur.AdjType=PrefC.GetLong(PrefName.BrokenAppointmentAdjustmentType);
					AdjustmentCur.ClinicNum=pat.ClinicNum;
					FormAdjust FormA=new FormAdjust(pat,AdjustmentCur);
					FormA.IsNew=true;
					FormA.ShowDialog();
				}
			}
			ModuleSelected(pat.PatNum);//Must be ran after the "D9986" break logic due to the addition of a completed procedure.
			SetInvalid();
			AutomationL.Trigger(AutomationTrigger.BreakAppointment,null,pat.PatNum);
			Recalls.SynchScheduledApptFull(apt.PatNum);
		}