Example #1
0
        private void butAdd_Click(object sender, EventArgs e)
        {
            FormSheetPicker FormS = new FormSheetPicker();

            FormS.SheetType = SheetTypeEnum.ExamSheet;
            FormS.ShowDialog();
            if (FormS.DialogResult != DialogResult.OK)
            {
                return;
            }
            SheetDef sheetDef;
            Sheet    sheet = null;       //only useful if not Terminal

            for (int i = 0; i < FormS.SelectedSheetDefs.Count; i++)
            {
                sheetDef = FormS.SelectedSheetDefs[i];
                sheet    = SheetUtil.CreateSheet(sheetDef, PatNum);
                SheetParameter.SetParameter(sheet, "PatNum", PatNum);
                SheetFiller.FillFields(sheet);
                SheetUtil.CalculateHeights(sheet);
            }
            FormSheetFillEdit.ShowForm(sheet, FormSheetFillEdit_Add_FormClosing);
        }
Example #2
0
        private void butPrint_Click(object sender, System.EventArgs e)
        {
            if (PrinterSettings.InstalledPrinters.Count == 0)
            {
                MsgBox.Show(this, "Error: No Printers Installed\r\n" +
                            "If you do have a printer installed, restarting the workstation may solve the problem."
                            );
                return;
            }
            //only visible if sheet==null.
            if (comboSendStatus.SelectedIndex == (int)RxSendStatus.InElectQueue ||
                comboSendStatus.SelectedIndex == (int)RxSendStatus.SentElect)
            {
                //do not change status
            }
            else
            {
                comboSendStatus.SelectedIndex = (int)RxSendStatus.Printed;
            }
            if (!SaveRx())
            {
                return;
            }
            //This logic is an exact copy of FormRxManage.butPrintSelect_Click()'s logic when 1 Rx is selected.
            //If this is updated, that method needs to be updated as well.
            SheetDef sheetDef = SheetDefs.GetSheetsDefault(SheetTypeEnum.Rx, Clinics.ClinicNum);

            sheet = SheetUtil.CreateSheet(sheetDef, PatCur.PatNum);
            SheetParameter.SetParameter(sheet, "RxNum", RxPatCur.RxNum);
            SheetFiller.FillFields(sheet);
            SheetUtil.CalculateHeights(sheet);
            if (!SheetPrinting.PrintRx(sheet, RxPatCur))
            {
                return;
            }
            DialogResult = DialogResult.OK;
        }
Example #3
0
 private void butOK_Click(object sender, EventArgs e)
 {
     SaveSignature();            //"saves" signature to TPCur, does not save to DB.
     TreatPlans.Update(TPcur);   //save signature to DB.
     TPcur.ListProcTPs = ProcTPs.RefreshForTP(TPcur.TreatPlanNum);
     if (DoPrintUsingSheets)
     {
         SheetParameter.SetParameter(SheetTP, "TreatPlan", TPcur);               //update TP on sheet to have new signature for generating pdfs
     }
     if (TPcur.SignaturePractice.Length > 0 && TPcur.DocNum == 0 && PrefC.GetBool(PrefName.TreatPlanSaveSignedToPdf))
     {
         _hasSigPracticeChanged = true;
     }
     if (TPcur.Signature.Length > 0 && TPcur.DocNum == 0 && PrefC.GetBool(PrefName.TreatPlanSaveSignedToPdf))
     {
         _sigChanged = true;
     }
     else if (TPcur.DocNum > 0 && !Documents.DocExists(TPcur.DocNum) && PrefC.GetBool(PrefName.TreatPlanSaveSignedToPdf))
     {
         //Setting SigChanged to True will resave document below.
         bool doResave = MsgBox.Show(this, MsgBoxButtons.YesNo, "Cannot find saved copy of signed PDF, would you like to resave the document?");
         _sigChanged            = doResave;
         _hasSigPracticeChanged = doResave;
     }
     if (PrefC.GetBool(PrefName.TreatPlanSaveSignedToPdf) && SaveDocDelegate != null &&
         ((_sigChanged && TPcur.Signature.Length > 0) || (_hasSigPracticeChanged && TPcur.SignaturePractice.Length > 0)))
     {
         List <Document> docs = SaveDocDelegate(true, SheetTP);
         if (docs.Count > 0)
         {
             TPcur.DocNum = docs[0].DocNum;                //attach first Doc to TP.
             TreatPlans.Update(TPcur);                     //update docnum. must be called after signature is updated.
         }
     }
     SecurityLogs.MakeLogEntry(Permissions.TreatPlanEdit, TPcur.PatNum, "Sign TP");
     DialogResult = DialogResult.OK;
 }
Example #4
0
        /// <summary>
        /// </summary>
        private Sheet CreateSheet(long PatNum, WebSheets.SheetAndSheetField sAnds)
        {
            Sheet newSheet = null;

            try{
                SheetDef sheetDef = new SheetDef((SheetTypeEnum)sAnds.web_sheet.SheetType);
                newSheet = SheetUtil.CreateSheet(sheetDef, PatNum);
                SheetParameter.SetParameter(newSheet, "PatNum", PatNum);
                newSheet.DateTimeSheet = sAnds.web_sheet.DateTimeSheet;
                newSheet.Description   = sAnds.web_sheet.Description;
                newSheet.Height        = sAnds.web_sheet.Height;
                newSheet.Width         = sAnds.web_sheet.Width;
                newSheet.FontName      = sAnds.web_sheet.FontName;
                newSheet.FontSize      = sAnds.web_sheet.FontSize;
                newSheet.SheetType     = (SheetTypeEnum)sAnds.web_sheet.SheetType;
                newSheet.IsLandscape   = sAnds.web_sheet.IsLandscape == (sbyte)1?true:false;
                newSheet.InternalNote  = "";
                newSheet.IsWebForm     = true;
                //loop through each variable in a single sheetfield
                for (int i = 0; i < sAnds.web_sheetfieldlist.Count(); i++)
                {
                    SheetField sheetfield = new SheetField();
                    sheetfield.FieldName = sAnds.web_sheetfieldlist[i].FieldName;
                    sheetfield.FieldType = (SheetFieldType)sAnds.web_sheetfieldlist[i].FieldType;
                    //sheetfield.FontIsBold=sAnds.web_sheetfieldlist[i].FontIsBold==(sbyte)1?true:false;
                    if (sAnds.web_sheetfieldlist[i].FontIsBold == (sbyte)1)
                    {
                        sheetfield.FontIsBold = true;
                    }
                    else
                    {
                        sheetfield.FontIsBold = false;
                    }
                    sheetfield.FontIsBold = sAnds.web_sheetfieldlist[i].FontIsBold == (sbyte)1?true:false;
                    sheetfield.FontName   = sAnds.web_sheetfieldlist[i].FontName;
                    sheetfield.FontSize   = sAnds.web_sheetfieldlist[i].FontSize;
                    sheetfield.Height     = sAnds.web_sheetfieldlist[i].Height;
                    sheetfield.Width      = sAnds.web_sheetfieldlist[i].Width;
                    sheetfield.XPos       = sAnds.web_sheetfieldlist[i].XPos;
                    sheetfield.YPos       = sAnds.web_sheetfieldlist[i].YPos;
                    //sheetfield.IsRequired=sAnds.web_sheetfieldlist[i].IsRequired==(sbyte)1?true:false;
                    if (sAnds.web_sheetfieldlist[i].IsRequired == (sbyte)1)
                    {
                        sheetfield.IsRequired = true;
                    }
                    else
                    {
                        sheetfield.IsRequired = false;
                    }
                    sheetfield.TabOrder         = sAnds.web_sheetfieldlist[i].TabOrder;
                    sheetfield.RadioButtonGroup = sAnds.web_sheetfieldlist[i].RadioButtonGroup;
                    sheetfield.RadioButtonValue = sAnds.web_sheetfieldlist[i].RadioButtonValue;
                    sheetfield.GrowthBehavior   = (GrowthBehaviorEnum)sAnds.web_sheetfieldlist[i].GrowthBehavior;
                    sheetfield.FieldValue       = sAnds.web_sheetfieldlist[i].FieldValue;
                    newSheet.SheetFields.Add(sheetfield);
                }                        // end of j loop
                Sheets.SaveNewSheet(newSheet);
                return(newSheet);
            }
            catch (Exception e) {
                gridMain.EndUpdate();
                MessageBox.Show(e.Message);
            }
            return(newSheet);
        }
Example #5
0
        public static bool Trigger <T>(AutomationTrigger trigger, List <string> procCodes, long patNum, long aptNum = 0, T triggerObj = default(T))
        {
            if (patNum == 0)           //Could happen for OpenPatient trigger
            {
                return(false);
            }
            List <Automation> listAutomations = Automations.GetDeepCopy();
            bool automationHappened           = false;

            for (int i = 0; i < listAutomations.Count; i++)
            {
                if (listAutomations[i].Autotrigger != trigger)
                {
                    continue;
                }
                if (trigger == AutomationTrigger.CompleteProcedure || trigger == AutomationTrigger.ScheduleProcedure)
                {
                    if (procCodes == null || procCodes.Count == 0)
                    {
                        continue;                        //fail silently
                    }
                    string[] arrayCodes = listAutomations[i].ProcCodes.Split(',');
                    if (procCodes.All(x => !arrayCodes.Contains(x)))
                    {
                        continue;
                    }
                }
                //matching automation item has been found
                //Get possible list of conditions that exist for this automation item
                List <AutomationCondition> autoConditionsList = AutomationConditions.GetListByAutomationNum(listAutomations[i].AutomationNum);
                if (autoConditionsList.Count > 0 && !CheckAutomationConditions(autoConditionsList, patNum, triggerObj))
                {
                    continue;
                }
                SheetDef          sheetDef;
                Sheet             sheet;
                FormSheetFillEdit FormSF;
                Appointment       aptNew;
                Appointment       aptOld;
                switch (listAutomations[i].AutoAction)
                {
                case AutomationAction.CreateCommlog:
                    if (Plugins.HookMethod(null, "AutomationL.Trigger_CreateCommlog_start", patNum, aptNum, listAutomations[i].CommType,
                                           listAutomations[i].MessageContent, trigger))
                    {
                        automationHappened = true;
                        continue;
                    }
                    Commlog commlogCur = new Commlog();
                    commlogCur.PatNum       = patNum;
                    commlogCur.CommDateTime = DateTime.Now;
                    commlogCur.CommType     = listAutomations[i].CommType;
                    commlogCur.Note         = listAutomations[i].MessageContent;
                    commlogCur.Mode_        = CommItemMode.None;
                    commlogCur.UserNum      = Security.CurUser.UserNum;
                    commlogCur.IsNew        = true;
                    FormCommItem commItemView = new FormCommItem(commlogCur);
                    commItemView.ShowDialog();
                    automationHappened = true;
                    continue;

                case AutomationAction.PopUp:
                    MessageBox.Show(listAutomations[i].MessageContent);
                    automationHappened = true;
                    continue;

                case AutomationAction.PopUpThenDisable10Min:
                    Plugins.HookAddCode(null, "AutomationL.Trigger_PopUpThenDisable10Min_begin", listAutomations[i], procCodes, patNum);
                    long automationNum      = listAutomations[i].AutomationNum;
                    bool hasAutomationBlock = FormOpenDental.DicBlockedAutomations.ContainsKey(automationNum);
                    if (hasAutomationBlock && FormOpenDental.DicBlockedAutomations[automationNum].ContainsKey(patNum))                             //Automation block exist for current patient.
                    {
                        continue;
                    }
                    if (hasAutomationBlock)
                    {
                        FormOpenDental.DicBlockedAutomations[automationNum].Add(patNum, DateTime.Now.AddMinutes(10)); //Disable for 10 minutes.
                    }
                    else                                                                                              //Add automationNum to higher level dictionary .
                    {
                        FormOpenDental.DicBlockedAutomations.Add(automationNum,
                                                                 new Dictionary <long, DateTime>()
                        {
                            { patNum, DateTime.Now.AddMinutes(10) }                                           //Disable for 10 minutes.
                        });
                    }
                    MessageBox.Show(listAutomations[i].MessageContent);
                    automationHappened = true;
                    continue;

                case AutomationAction.PrintPatientLetter:
                case AutomationAction.ShowExamSheet:
                case AutomationAction.ShowConsentForm:
                    sheetDef = SheetDefs.GetSheetDef(listAutomations[i].SheetDefNum);
                    sheet    = SheetUtil.CreateSheet(sheetDef, patNum);
                    SheetParameter.SetParameter(sheet, "PatNum", patNum);
                    SheetFiller.FillFields(sheet);
                    SheetUtil.CalculateHeights(sheet);
                    FormSF = new FormSheetFillEdit(sheet);
                    FormSF.ShowDialog();
                    automationHappened = true;
                    continue;

                case AutomationAction.PrintReferralLetter:
                    long referralNum = RefAttaches.GetReferralNum(patNum);
                    if (referralNum == 0)
                    {
                        MsgBox.Show("Automations", "This patient has no referral source entered.");
                        automationHappened = true;
                        continue;
                    }
                    sheetDef = SheetDefs.GetSheetDef(listAutomations[i].SheetDefNum);
                    sheet    = SheetUtil.CreateSheet(sheetDef, patNum);
                    SheetParameter.SetParameter(sheet, "PatNum", patNum);
                    SheetParameter.SetParameter(sheet, "ReferralNum", referralNum);
                    //Don't fill these params if the sheet doesn't use them.
                    if (sheetDef.SheetFieldDefs.Any(x =>
                                                    (x.FieldType == SheetFieldType.Grid && x.FieldName == "ReferralLetterProceduresCompleted") ||
                                                    (x.FieldType == SheetFieldType.Special && x.FieldName == "toothChart")))
                    {
                        List <Procedure> listProcs = Procedures.GetCompletedForDateRange(DateTime.Today, DateTime.Today
                                                                                         , listPatNums: new List <long>()
                        {
                            patNum
                        }
                                                                                         , includeNote: true
                                                                                         , includeGroupNote: true
                                                                                         );
                        if (sheetDef.SheetFieldDefs.Any(x => x.FieldType == SheetFieldType.Grid && x.FieldName == "ReferralLetterProceduresCompleted"))
                        {
                            SheetParameter.SetParameter(sheet, "CompletedProcs", listProcs);
                        }
                        if (sheetDef.SheetFieldDefs.Any(x => x.FieldType == SheetFieldType.Special && x.FieldName == "toothChart"))
                        {
                            SheetParameter.SetParameter(sheet, "toothChartImg", SheetPrinting.GetToothChartHelper(patNum, false, listProceduresFilteredOverride: listProcs));
                        }
                    }
                    SheetFiller.FillFields(sheet);
                    SheetUtil.CalculateHeights(sheet);
                    FormSF = new FormSheetFillEdit(sheet);
                    FormSF.ShowDialog();
                    automationHappened = true;
                    continue;

                case AutomationAction.SetApptASAP:
                    aptNew = Appointments.GetOneApt(aptNum);
                    if (aptNew == null)
                    {
                        MsgBox.Show("Automations", "Invalid appointment for automation.");
                        automationHappened = true;
                        continue;
                    }
                    aptOld          = aptNew.Copy();
                    aptNew.Priority = ApptPriority.ASAP;
                    Appointments.Update(aptNew, aptOld);                           //Appointments S-Class handles Signalods
                    continue;

                case AutomationAction.SetApptType:
                    aptNew = Appointments.GetOneApt(aptNum);
                    if (aptNew == null)
                    {
                        MsgBox.Show("Automations", "Invalid appointment for automation.");
                        automationHappened = true;
                        continue;
                    }
                    aptOld = aptNew.Copy();
                    aptNew.AppointmentTypeNum = listAutomations[i].AppointmentTypeNum;
                    AppointmentType aptTypeCur = AppointmentTypes.GetFirstOrDefault(x => x.AppointmentTypeNum == aptNew.AppointmentTypeNum);
                    if (aptTypeCur != null)
                    {
                        aptNew.ColorOverride = aptTypeCur.AppointmentTypeColor;
                        aptNew.Pattern       = AppointmentTypes.GetTimePatternForAppointmentType(aptTypeCur);
                        List <Procedure> listProcs = Appointments.ApptTypeMissingProcHelper(aptNew, aptTypeCur, new List <Procedure>());
                        Procedures.UpdateAptNums(listProcs.Select(x => x.ProcNum).ToList(), aptNew.AptNum, aptNew.AptStatus == ApptStatus.Planned);
                    }
                    Appointments.Update(aptNew, aptOld);                           //Appointments S-Class handles Signalods
                    continue;

                case AutomationAction.PatRestrictApptSchedTrue:
                    if (!Security.IsAuthorized(Permissions.PatientApptRestrict, true))
                    {
                        SecurityLogs.MakeLogEntry(Permissions.PatientApptRestrict, patNum, "Attempt to restrict patient scheduling was blocked due to lack of user permission.");
                        continue;
                    }
                    PatRestrictions.Upsert(patNum, PatRestrict.ApptSchedule);
                    automationHappened = true;
                    continue;

                case AutomationAction.PatRestrictApptSchedFalse:
                    if (!Security.IsAuthorized(Permissions.PatientApptRestrict, true))
                    {
                        SecurityLogs.MakeLogEntry(Permissions.PatientApptRestrict, patNum, "Attempt to allow patient scheduling was blocked due to lack of user permission.");
                        continue;
                    }
                    PatRestrictions.RemovePatRestriction(patNum, PatRestrict.ApptSchedule);
                    automationHappened = true;
                    continue;

                case AutomationAction.PrintRxInstruction:
                    List <RxPat> listRx = (List <RxPat>)(object) triggerObj;
                    if (listRx == null)
                    {
                        //Got here via a pre-existing trigger that doesn't pass in triggerObj.  We now block creation of automation triggers that could get
                        //here via code that does not pass in triggerObj.
                        continue;
                    }
                    //We go through each new Rx where the patient note isn't blank.
                    //There should only usually be one new rx, but we'll loop just in case.
                    foreach (RxPat rx in listRx.Where(x => !string.IsNullOrWhiteSpace(x.PatientInstruction)))
                    {
                        //This logic is an exact copy of FormRxManage.butPrintSelect_Click()'s logic when 1 Rx is selected.
                        //If this is updated, that method needs to be updated as well.
                        sheetDef = SheetDefs.GetSheetDef(listAutomations[i].SheetDefNum);
                        sheet    = SheetUtil.CreateSheet(sheetDef, patNum);
                        SheetParameter.SetParameter(sheet, "RxNum", rx.RxNum);
                        SheetFiller.FillFields(sheet);
                        SheetUtil.CalculateHeights(sheet);
                        FormSF = new FormSheetFillEdit(sheet);
                        FormSF.ShowDialog();
                        automationHappened = true;
                    }
                    continue;

                case AutomationAction.ChangePatStatus:
                    Patient pat    = Patients.GetPat(patNum);
                    Patient patOld = pat.Copy();
                    pat.PatStatus = listAutomations[i].PatStatus;
                    //Don't allow changing status from Archived if this is a merged patient.
                    if (patOld.PatStatus != pat.PatStatus &&
                        patOld.PatStatus == PatientStatus.Archived &&
                        PatientLinks.WasPatientMerged(patOld.PatNum))
                    {
                        MsgBox.Show("FormPatientEdit", "Not allowed to change the status of a merged patient.");
                        continue;
                    }
                    switch (pat.PatStatus)
                    {
                    case PatientStatus.Deceased:
                        if (patOld.PatStatus != PatientStatus.Deceased)
                        {
                            List <Appointment> listFutureAppts = Appointments.GetFutureSchedApts(pat.PatNum);
                            if (listFutureAppts.Count > 0)
                            {
                                string apptDates = string.Join("\r\n", listFutureAppts.Take(10).Select(x => x.AptDateTime.ToString()));
                                if (listFutureAppts.Count > 10)
                                {
                                    apptDates += "(...)";
                                }
                                if (MessageBox.Show(
                                        Lan.g("FormPatientEdit", "This patient has scheduled appointments in the future") + ":\r\n" + apptDates + "\r\n"
                                        + Lan.g("FormPatientEdit", "Would you like to delete them and set the patient to Deceased?"),
                                        Lan.g("FormPatientEdit", "Delete future appointments?"),
                                        MessageBoxButtons.YesNo) == DialogResult.Yes)
                                {
                                    foreach (Appointment appt in listFutureAppts)
                                    {
                                        Appointments.Delete(appt.AptNum, true);
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }
                        break;
                    }
                    //Re-activate or disable recalls depending on the the status that the patient is changing to.
                    Patients.UpdateRecalls(pat, patOld, "ChangePatStatus automation");
                    if (Patients.Update(pat, patOld))
                    {
                        SecurityLogs.MakeLogEntry(Permissions.PatientEdit, patNum, "Patient status changed from " + patOld.PatStatus.GetDescription() +
                                                  " to " + listAutomations[i].PatStatus.GetDescription() + " through ChangePatStatus automation.");
                    }
                    automationHappened = true;
                    continue;
                }
            }
            return(automationHappened);
        }
Example #6
0
        public static bool Trigger <T>(AutomationTrigger trigger, List <string> procCodes, long patNum, long aptNum = 0, T triggerObj = default(T))
        {
            if (patNum == 0)           //Could happen for OpenPatient trigger
            {
                return(false);
            }
            List <Automation> listAutomations = Automations.GetDeepCopy();
            bool automationHappened           = false;

            for (int i = 0; i < listAutomations.Count; i++)
            {
                if (listAutomations[i].Autotrigger != trigger)
                {
                    continue;
                }
                if (trigger == AutomationTrigger.CompleteProcedure || trigger == AutomationTrigger.ScheduleProcedure)
                {
                    if (procCodes == null || procCodes.Count == 0)
                    {
                        continue;                        //fail silently
                    }
                    string[] arrayCodes = listAutomations[i].ProcCodes.Split(',');
                    if (procCodes.All(x => !arrayCodes.Contains(x)))
                    {
                        continue;
                    }
                }
                //matching automation item has been found
                //Get possible list of conditions that exist for this automation item
                List <AutomationCondition> autoConditionsList = AutomationConditions.GetListByAutomationNum(listAutomations[i].AutomationNum);
                if (autoConditionsList.Count > 0 && !CheckAutomationConditions(autoConditionsList, patNum, triggerObj))
                {
                    continue;
                }
                SheetDef          sheetDef;
                Sheet             sheet;
                FormSheetFillEdit FormSF;
                Appointment       aptNew;
                Appointment       aptOld;
                switch (listAutomations[i].AutoAction)
                {
                case AutomationAction.CreateCommlog:
                    if (Plugins.HookMethod(null, "AutomationL.Trigger_CreateCommlog_start", patNum, aptNum, listAutomations[i].CommType,
                                           listAutomations[i].MessageContent))
                    {
                        automationHappened = true;
                        continue;
                    }
                    Commlog commlogCur = new Commlog();
                    commlogCur.PatNum       = patNum;
                    commlogCur.CommDateTime = DateTime.Now;
                    commlogCur.CommType     = listAutomations[i].CommType;
                    commlogCur.Note         = listAutomations[i].MessageContent;
                    commlogCur.Mode_        = CommItemMode.None;
                    commlogCur.UserNum      = Security.CurUser.UserNum;
                    FormCommItem commItemView = new FormCommItem();
                    commItemView.ShowDialog(new CommItemModel()
                    {
                        CommlogCur = commlogCur
                    }, new CommItemController(commItemView)
                    {
                        IsNew = true
                    });
                    automationHappened = true;
                    continue;

                case AutomationAction.PopUp:
                    MessageBox.Show(listAutomations[i].MessageContent);
                    automationHappened = true;
                    continue;

                case AutomationAction.PopUpThenDisable10Min:
                    long automationNum      = listAutomations[i].AutomationNum;
                    bool hasAutomationBlock = FormOpenDental.DicBlockedAutomations.ContainsKey(automationNum);
                    if (hasAutomationBlock && FormOpenDental.DicBlockedAutomations[automationNum].ContainsKey(patNum))                             //Automation block exist for current patient.
                    {
                        continue;
                    }
                    if (hasAutomationBlock)
                    {
                        FormOpenDental.DicBlockedAutomations[automationNum].Add(patNum, DateTime.Now.AddMinutes(10)); //Disable for 10 minutes.
                    }
                    else                                                                                              //Add automationNum to higher level dictionary .
                    {
                        FormOpenDental.DicBlockedAutomations.Add(automationNum,
                                                                 new Dictionary <long, DateTime>()
                        {
                            { patNum, DateTime.Now.AddMinutes(10) }                                           //Disable for 10 minutes.
                        });
                    }
                    MessageBox.Show(listAutomations[i].MessageContent);
                    automationHappened = true;
                    continue;

                case AutomationAction.PrintPatientLetter:
                case AutomationAction.ShowExamSheet:
                case AutomationAction.ShowConsentForm:
                    sheetDef = SheetDefs.GetSheetDef(listAutomations[i].SheetDefNum);
                    sheet    = SheetUtil.CreateSheet(sheetDef, patNum);
                    SheetParameter.SetParameter(sheet, "PatNum", patNum);
                    SheetFiller.FillFields(sheet);
                    SheetUtil.CalculateHeights(sheet);
                    FormSF = new FormSheetFillEdit(sheet);
                    FormSF.ShowDialog();
                    automationHappened = true;
                    continue;

                case AutomationAction.PrintReferralLetter:
                    long referralNum = RefAttaches.GetReferralNum(patNum);
                    if (referralNum == 0)
                    {
                        MsgBox.Show("Automations", "This patient has no referral source entered.");
                        automationHappened = true;
                        continue;
                    }
                    sheetDef = SheetDefs.GetSheetDef(listAutomations[i].SheetDefNum);
                    sheet    = SheetUtil.CreateSheet(sheetDef, patNum);
                    SheetParameter.SetParameter(sheet, "PatNum", patNum);
                    SheetParameter.SetParameter(sheet, "ReferralNum", referralNum);
                    //Don't fill these params if the sheet doesn't use them.
                    if (sheetDef.SheetFieldDefs.Any(x =>
                                                    (x.FieldType == SheetFieldType.Grid && x.FieldName == "ReferralLetterProceduresCompleted") ||
                                                    (x.FieldType == SheetFieldType.Special && x.FieldName == "toothChart")))
                    {
                        List <Procedure> listProcs = Procedures.GetCompletedForDateRange(DateTime.Today, DateTime.Today
                                                                                         , listPatNums: new List <long>()
                        {
                            patNum
                        }
                                                                                         , includeNote: true
                                                                                         , includeGroupNote: true
                                                                                         );
                        if (sheetDef.SheetFieldDefs.Any(x => x.FieldType == SheetFieldType.Grid && x.FieldName == "ReferralLetterProceduresCompleted"))
                        {
                            SheetParameter.SetParameter(sheet, "CompletedProcs", listProcs);
                        }
                        if (sheetDef.SheetFieldDefs.Any(x => x.FieldType == SheetFieldType.Special && x.FieldName == "toothChart"))
                        {
                            SheetParameter.SetParameter(sheet, "toothChartImg", SheetPrinting.GetToothChartHelper(patNum, false, listProceduresFilteredOverride: listProcs));
                        }
                    }
                    SheetFiller.FillFields(sheet);
                    SheetUtil.CalculateHeights(sheet);
                    FormSF = new FormSheetFillEdit(sheet);
                    FormSF.ShowDialog();
                    automationHappened = true;
                    continue;

                case AutomationAction.SetApptASAP:
                    aptNew = Appointments.GetOneApt(aptNum);
                    if (aptNew == null)
                    {
                        MsgBox.Show("Automations", "Invalid appointment for automation.");
                        automationHappened = true;
                        continue;
                    }
                    aptOld          = aptNew.Copy();
                    aptNew.Priority = ApptPriority.ASAP;
                    Appointments.Update(aptNew, aptOld);                           //Appointments S-Class handles Signalods
                    continue;

                case AutomationAction.SetApptType:
                    aptNew = Appointments.GetOneApt(aptNum);
                    if (aptNew == null)
                    {
                        MsgBox.Show("Automations", "Invalid appointment for automation.");
                        automationHappened = true;
                        continue;
                    }
                    aptOld = aptNew.Copy();
                    aptNew.AppointmentTypeNum = listAutomations[i].AppointmentTypeNum;
                    AppointmentType aptTypeCur = AppointmentTypes.GetFirstOrDefault(x => x.AppointmentTypeNum == aptNew.AppointmentTypeNum);
                    if (aptTypeCur != null)
                    {
                        aptNew.ColorOverride = aptTypeCur.AppointmentTypeColor;
                    }
                    Appointments.Update(aptNew, aptOld);                           //Appointments S-Class handles Signalods
                    continue;

                case AutomationAction.PatRestrictApptSchedTrue:
                    if (!Security.IsAuthorized(Permissions.PatientApptRestrict, true))
                    {
                        SecurityLogs.MakeLogEntry(Permissions.PatientApptRestrict, patNum, "Attempt to restrict patient scheduling was blocked due to lack of user permission.");
                        continue;
                    }
                    PatRestrictions.Upsert(patNum, PatRestrict.ApptSchedule);
                    automationHappened = true;
                    continue;

                case AutomationAction.PatRestrictApptSchedFalse:
                    if (!Security.IsAuthorized(Permissions.PatientApptRestrict, true))
                    {
                        SecurityLogs.MakeLogEntry(Permissions.PatientApptRestrict, patNum, "Attempt to allow patient scheduling was blocked due to lack of user permission.");
                        continue;
                    }
                    PatRestrictions.RemovePatRestriction(patNum, PatRestrict.ApptSchedule);
                    automationHappened = true;
                    continue;
                }
            }
            return(automationHappened);
        }
Example #7
0
        ///<summary>ProcCodes will be null unless trigger is CompleteProcedure.  This routine will generally fail silently.  Will return true if a trigger happened.</summary>
        public static bool Trigger(AutomationTrigger trigger, List <string> procCodes, long patNum)
        {
            if (patNum == 0)           //Could happen for OpenPatient trigger
            {
                return(false);
            }
            bool automationHappened = false;

            for (int i = 0; i < Automations.Listt.Count; i++)
            {
                if (Automations.Listt[i].Autotrigger != trigger)
                {
                    continue;
                }
                if (trigger == AutomationTrigger.CompleteProcedure)
                {
                    if (procCodes == null)
                    {
                        continue;                        //fail silently
                    }
                    bool     codeFound  = false;
                    string[] arrayCodes = Automations.Listt[i].ProcCodes.Split(',');
                    for (int p = 0; p < procCodes.Count; p++)
                    {
                        for (int a = 0; a < arrayCodes.Length; a++)
                        {
                            if (arrayCodes[a] == procCodes[p])
                            {
                                codeFound = true;
                                break;
                            }
                        }
                    }
                    if (!codeFound)
                    {
                        continue;
                    }
                }
                //matching automation item has been found
                //Get possible list of conditions that exist for this automation item
                List <AutomationCondition> autoConditionsList = AutomationConditions.GetListByAutomationNum(Automations.Listt[i].AutomationNum);
                if (Automations.Listt[i].AutoAction == AutomationAction.CreateCommlog)
                {
                    if (autoConditionsList.Count > 0)
                    {
                        if (!CheckAutomationConditions(autoConditionsList, patNum))
                        {
                            continue;
                        }
                    }
                    Commlog CommlogCur = new Commlog();
                    CommlogCur.PatNum       = patNum;
                    CommlogCur.CommDateTime = DateTime.Now;
                    CommlogCur.CommType     = Automations.Listt[i].CommType;
                    CommlogCur.Note         = Automations.Listt[i].MessageContent;
                    CommlogCur.Mode_        = CommItemMode.None;
                    CommlogCur.UserNum      = Security.CurUser.UserNum;
                    FormCommItem FormCI = new FormCommItem(CommlogCur);
                    FormCI.IsNew = true;
                    FormCI.ShowDialog();
                    automationHappened = true;
                }
                else if (Automations.Listt[i].AutoAction == AutomationAction.PopUp)
                {
                    if (autoConditionsList.Count > 0)
                    {
                        if (!CheckAutomationConditions(autoConditionsList, patNum))
                        {
                            continue;
                        }
                    }
                    MessageBox.Show(Automations.Listt[i].MessageContent);
                    automationHappened = true;
                }
                else if (Automations.Listt[i].AutoAction == AutomationAction.PrintPatientLetter)
                {
                    if (autoConditionsList.Count > 0)
                    {
                        if (!CheckAutomationConditions(autoConditionsList, patNum))
                        {
                            continue;
                        }
                    }
                    SheetDef sheetDef = SheetDefs.GetSheetDef(Automations.Listt[i].SheetDefNum);
                    Sheet    sheet    = SheetUtil.CreateSheet(sheetDef, patNum);
                    SheetParameter.SetParameter(sheet, "PatNum", patNum);
                    //SheetParameter.SetParameter(sheet,"ReferralNum",referral.ReferralNum);
                    SheetFiller.FillFields(sheet);
                    using (Bitmap bmp = new Bitmap(100, 100)) {                //a dummy bitmap for the graphics object
                        using (Graphics g = Graphics.FromImage(bmp)) {
                            SheetUtil.CalculateHeights(sheet, g);
                        }
                    }
                    FormSheetFillEdit FormSF = new FormSheetFillEdit(sheet);
                    FormSF.ShowDialog();
                    automationHappened = true;
                }
                else if (Automations.Listt[i].AutoAction == AutomationAction.PrintReferralLetter)
                {
                    if (autoConditionsList.Count > 0)
                    {
                        if (!CheckAutomationConditions(autoConditionsList, patNum))
                        {
                            continue;
                        }
                    }
                    long referralNum = RefAttaches.GetReferralNum(patNum);
                    if (referralNum == 0)
                    {
                        MsgBox.Show("Automations", "This patient has no referral source entered.");
                        automationHappened = true;
                        continue;
                    }
                    SheetDef sheetDef = SheetDefs.GetSheetDef(Automations.Listt[i].SheetDefNum);
                    Sheet    sheet    = SheetUtil.CreateSheet(sheetDef, patNum);
                    SheetParameter.SetParameter(sheet, "PatNum", patNum);
                    SheetParameter.SetParameter(sheet, "ReferralNum", referralNum);
                    SheetFiller.FillFields(sheet);
                    using (Bitmap bmp = new Bitmap(100, 100)) {                //a dummy bitmap for the graphics object
                        using (Graphics g = Graphics.FromImage(bmp)) {
                            SheetUtil.CalculateHeights(sheet, g);
                        }
                    }
                    FormSheetFillEdit FormSF = new FormSheetFillEdit(sheet);
                    FormSF.ShowDialog();
                    automationHappened = true;
                }
                else if (Automations.Listt[i].AutoAction == AutomationAction.ShowExamSheet)
                {
                    if (autoConditionsList.Count > 0)
                    {
                        if (!CheckAutomationConditions(autoConditionsList, patNum))
                        {
                            continue;
                        }
                    }
                    SheetDef sheetDef = SheetDefs.GetSheetDef(Automations.Listt[i].SheetDefNum);
                    Sheet    sheet    = SheetUtil.CreateSheet(sheetDef, patNum);
                    SheetParameter.SetParameter(sheet, "PatNum", patNum);
                    SheetFiller.FillFields(sheet);
                    using (Bitmap bmp = new Bitmap(100, 100)) {                //a dummy bitmap for the graphics object
                        using (Graphics g = Graphics.FromImage(bmp)) {
                            SheetUtil.CalculateHeights(sheet, g);
                        }
                    }
                    FormSheetFillEdit FormSF = new FormSheetFillEdit(sheet);
                    FormSF.ShowDialog();
                    automationHappened = true;
                }
            }
            return(automationHappened);
        }