Ejemplo n.º 1
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.ReportableName   = sAnds.web_sheetfieldlist[i].ReportableName;
                    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;
                    sheetfield.TextAlign        = (HorizontalAlignment)sAnds.web_sheetfieldlist[i].TextAlign;
                    sheetfield.ItemColor        = Color.FromArgb(sAnds.web_sheetfieldlist[i].ItemColor);
                    newSheet.SheetFields.Add(sheetfield);
                }                        // end of j loop
                Sheets.SaveNewSheet(newSheet);
                return(newSheet);
            }
            catch (Exception e) {
                gridMain.EndUpdate();
                MessageBox.Show(e.Message);
            }
            return(newSheet);
        }
Ejemplo n.º 2
0
 private void RetrieveAndSaveData()
 {
     try {
                         #if DEBUG
         //IgnoreCertificateErrors();// used with faulty certificates only while debugging.
                         #endif
         WebSheets.Sheets wh = new WebSheets.Sheets();
         wh.Timeout = 300000;              //5 minutes.  Default is 100000 (1.66667 minutes).
         wh.Url     = PrefC.GetString(PrefName.WebHostSynchServerURL);
         string RegistrationKey = PrefC.GetString(PrefName.RegistrationKey);
         if (wh.GetDentalOfficeID(RegistrationKey) == 0)
         {
             MsgBox.Show(this, "Registration key provided by the dental office is incorrect");
             return;
         }
         List <WebSheets.SheetAndSheetField> listSheets;
         List <long> listSkippedSheets = new List <long>();
         int         iterations        = 0;
         do                                             //Because WebSheets are only downloaded 20 at a time, we need to get the sheets within a loop to download them all.
         {
             listSheets = wh.GetSheets(RegistrationKey) //Only gets the first 20 sheets.
                                                        //if we are not in HQ, filter out non-HQ sheets that don't match our current clinic
                          .Where(x => x.web_sheet.ClinicNum == 0 || Clinics.ClinicNum == 0 || x.web_sheet.ClinicNum == Clinics.ClinicNum).ToList();
             iterations++;
             List <long> SheetsForDeletion = new List <long>();
             listSheets.RemoveAll(x => listSkippedSheets.Contains(x.web_sheet.SheetID));                    //Remove all sheets that the user has already skipped.
             if (listSheets.Count == 0)
             {
                 if (iterations == 1)
                 {
                     MsgBox.Show(this, "No Patient forms retrieved from server");
                 }
                 else
                 {
                     MsgBox.Show(this, "All Patient forms retrieved from server");
                 }
                 return;
             }
             //loop through all incoming sheets
             for (int i = 0; i < listSheets.Count; i++)
             {
                 try {                         //this try catch is put so that a defective downloaded sheet does not stop other sheets from being downloaded.
                     long          patNum           = 0;
                     string        lName            = "";
                     string        fName            = "";
                     List <string> listPhoneNumbers = new List <string>();
                     string        email            = "";
                     DateTime      bDate            = DateTime.MinValue;
                     //loop through each field in this sheet to find First name, last name, and DOB
                     for (int j = 0; j < listSheets[i].web_sheetfieldlist.Count(); j++)
                     {
                         if (listSheets[i].web_sheetfieldlist[j].FieldName.ToLower().Contains("lname") ||
                             listSheets[i].web_sheetfieldlist[j].FieldName.ToLower().Contains("lastname"))
                         {
                             lName = listSheets[i].web_sheetfieldlist[j].FieldValue;
                         }
                         if (listSheets[i].web_sheetfieldlist[j].FieldName.ToLower().Contains("fname") ||
                             listSheets[i].web_sheetfieldlist[j].FieldName.ToLower().Contains("firstname"))
                         {
                             fName = listSheets[i].web_sheetfieldlist[j].FieldValue;
                         }
                         if (listSheets[i].web_sheetfieldlist[j].FieldName.ToLower().Contains("bdate") ||
                             listSheets[i].web_sheetfieldlist[j].FieldName.ToLower().Contains("birthdate"))
                         {
                             bDate = PIn.Date(listSheets[i].web_sheetfieldlist[j].FieldValue);
                         }
                         if (listSheets[i].web_sheetfieldlist[j].FieldName.ToLower().In("hmphone", "wkphone", "wirelessphone") &&
                             listSheets[i].web_sheetfieldlist[j].FieldValue != "")
                         {
                             listPhoneNumbers.Add(listSheets[i].web_sheetfieldlist[j].FieldValue);
                         }
                         if (listSheets[i].web_sheetfieldlist[j].FieldName.ToLower() == "email")
                         {
                             email = listSheets[i].web_sheetfieldlist[j].FieldValue;
                         }
                     }
                     if (bDate.Year < 1880)
                     {
                         //log invalid birth date  format. Shouldn't happen, though.
                     }
                     List <long>            listMatchingPats = Patients.GetPatNumsByNameBirthdayEmailAndPhone(lName, fName, bDate, email, listPhoneNumbers);
                     FormPatientPickWebForm FormPpw          = new FormPatientPickWebForm(listSheets[i]);
                     FormPpw.LnameEntered = lName;
                     FormPpw.FnameEntered = fName;
                     FormPpw.BdateEntered = bDate;
                     if (listMatchingPats.Count == 0)
                     {
                         FormPpw.HasMoreThanOneMatch = false;
                         FormPpw.ShowDialog();
                         if (FormPpw.DialogResult == DialogResult.Cancel)
                         {
                             //user wants to stop importing altogether
                             //we will pick up where we left off here next time
                             wh.DeleteSheetData(RegistrationKey, SheetsForDeletion.ToArray());
                             return;
                         }
                         else if (FormPpw.DialogResult == DialogResult.Ignore)
                         {
                             //user wants to skip this patient import only
                             listSkippedSheets.Add(listSheets[i].web_sheet.SheetID);
                             continue;
                             //future feature suggestion... 4th state = discard
                             //mark this patient's import sheet for delete go to the next patient
                             //SheetsForDeletion.Add(listSheets[i].web_sheet.SheetID);
                             //continue
                         }
                         patNum = FormPpw.SelectedPatNum;                              //might be zero to indicate new patient
                     }
                     else if (listMatchingPats.Count > 1)
                     {
                         FormPpw.HasMoreThanOneMatch = true;
                         FormPpw.ShowDialog();
                         if (FormPpw.DialogResult == DialogResult.Cancel)
                         {
                             //user wants to stop importing altogether
                             //we will pick up where we left off here next time
                             wh.DeleteSheetData(RegistrationKey, SheetsForDeletion.ToArray());
                             return;
                         }
                         else if (FormPpw.DialogResult == DialogResult.Ignore)
                         {
                             //user wants to skip this patient import only
                             listSkippedSheets.Add(listSheets[i].web_sheet.SheetID);
                             continue;
                         }
                         patNum = FormPpw.SelectedPatNum; //might be zero to indicate new patient
                     }
                     else                                 //Exactly one match was found so make a log entry what the match was.
                     {
                         patNum = listMatchingPats[0];
                         Patient pat = Patients.GetPat(patNum);
                         //Security log for OD automatically importing a sheet into a patient.
                         SecurityLogs.MakeLogEntry(Permissions.SheetEdit, patNum, Lan.g(this, "Web form import from:")
                                                   + " " + lName + ", " + fName + " " + bDate.ToShortDateString() + "\r\n"
                                                   + Lan.g(this, "Auto imported into:") + " " + pat.LName + ", " + pat.FName + " " + pat.Birthdate.ToShortDateString());
                     }
                     if (patNum == 0)
                     {
                         Patient newPat = CreatePatient(lName, fName, bDate, listSheets[i]);
                         patNum = newPat.PatNum;
                         //Security log for user creating a new patient.
                         SecurityLogs.MakeLogEntry(Permissions.SheetEdit, patNum, Lan.g(this, "Web form import from:")
                                                   + " " + lName + ", " + fName + " " + bDate.ToShortDateString() + "\r\n"
                                                   + Lan.g(this, "User created new pat:") + " " + newPat.LName + ", " + newPat.FName + " " + newPat.Birthdate.ToShortDateString());
                     }
                     //We should probably make a security log entry for a manually selected patient.
                     Sheet newSheet = SheetUtil.CreateSheetFromWebSheet(patNum, listSheets[i]);
                     Sheets.SaveNewSheet(newSheet);
                     if (DataExistsInDb(newSheet))
                     {
                         SheetsForDeletion.Add(listSheets[i].web_sheet.SheetID);
                     }
                 }
                 catch (Exception e) {
                     MessageBox.Show(e.Message);
                 }
             }                    // end of for loop
             wh.DeleteSheetData(RegistrationKey, SheetsForDeletion.ToArray());
         } while(listSheets.Count > 0);
     }
     catch (Exception e) {
         MessageBox.Show(e.Message);
         return;
     }
 }
Ejemplo n.º 3
0
        ///<summary>Triggered when any field value changes.  This immediately invalidates signatures.  It also causes fields to grow as needed and deselects other radiobuttons in a group.</summary>
        private void text_TextChanged(object sender, EventArgs e)
        {
            foreach (Control control in panelMain.Controls)
            {
                if (control.GetType() != typeof(OpenDental.UI.SignatureBoxWrapper))
                {
                    continue;
                }
                if (control.Tag == null)
                {
                    continue;
                }
                SheetField field = (SheetField)control.Tag;
                OpenDental.UI.SignatureBoxWrapper sigBox = (OpenDental.UI.SignatureBoxWrapper)control;
                sigBox.SetInvalid();
            }
            if (sender.GetType() == typeof(SheetCheckBox))
            {
                SheetCheckBox checkbox = (SheetCheckBox)sender;
                if (checkbox.Tag == null)
                {
                    return;
                }
                if (!checkbox.IsChecked)                 //if user unchecked a radiobutton, nothing else happens
                {
                    return;
                }
                SheetField fieldThis = (SheetField)checkbox.Tag;
                if (fieldThis.RadioButtonGroup == "" && fieldThis.RadioButtonValue == "")            //if it's a checkbox instead of a radiobutton
                {
                    return;
                }
                foreach (Control control in panelMain.Controls)                 //set some other radiobuttons to be not checked
                {
                    if (control.GetType() != typeof(SheetCheckBox))
                    {
                        continue;
                    }
                    if (control.Tag == null)
                    {
                        continue;
                    }
                    if (control == sender)
                    {
                        continue;
                    }
                    SheetField fieldOther = (SheetField)control.Tag;
                    if (fieldThis.FieldName != fieldOther.FieldName)                   //different radio group
                    {
                        continue;
                    }
                    //If both checkbox field names are set to "misc" then we instead use the RadioButtonGroup as the actual radio button group name.
                    if (fieldThis.FieldName == "misc" && fieldThis.RadioButtonGroup != fieldOther.RadioButtonGroup)
                    {
                        continue;
                    }
                    ((SheetCheckBox)control).IsChecked = false;
                }
                return;
            }
            if (sender.GetType() != typeof(RichTextBox))
            {
                //since CheckBoxes also trigger this event for sig invalid.
                return;
            }
            //everything below here is for growth calc.
            RichTextBox textBox = (RichTextBox)sender;
            //remember where we were
            int cursorPos = textBox.SelectionStart;
            //int boxX=textBox.Location.X;
            //int boxY=textBox.Location.Y;
            //string originalFieldValue=((SheetField)((RichTextBox)control).Tag).FieldValue;
            SheetField fld = (SheetField)textBox.Tag;

            if (fld.GrowthBehavior == GrowthBehaviorEnum.None)
            {
                return;
            }
            fld.FieldValue = textBox.Text;
            Graphics  g         = this.CreateGraphics();
            FontStyle fontstyle = FontStyle.Regular;

            if (fld.FontIsBold)
            {
                fontstyle = FontStyle.Bold;
            }
            Font font  = new Font(fld.FontName, fld.FontSize, fontstyle);
            int  calcH = GraphicsHelper.MeasureStringH(g, fld.FieldValue, font, fld.Width);

            //(int)(g.MeasureString(fld.FieldValue,font,fld.Width).Height * 1.133f);//Seems to need 2 pixels per line of text to prevent hidden text due to scroll.
            calcH += font.Height + 2;        //add one line just in case.
            g.Dispose();
            if (calcH <= fld.Height)         //no growth needed
            {
                return;
            }
            //the field height needs to change, so:
            int amountOfGrowth = calcH - fld.Height;

            fld.Height = calcH;
            FillFieldsFromControls();            //We already changed the value of this field manually,
            //but if the other fields don't get changed, they will erroneously 'reset'.
            if (fld.GrowthBehavior == GrowthBehaviorEnum.DownGlobal)
            {
                SheetUtil.MoveAllDownBelowThis(SheetCur, fld, amountOfGrowth);
            }
            else if (fld.GrowthBehavior == GrowthBehaviorEnum.DownLocal)
            {
                SheetUtil.MoveAllDownWhichIntersect(SheetCur, fld, amountOfGrowth);
            }
            LayoutFields();
            //find the original textbox, and put the cursor back where it belongs
            foreach (Control control in panelMain.Controls)
            {
                if (control.GetType() == typeof(RichTextBox))
                {
                    if ((SheetField)(control.Tag) == fld)
                    {
                        ((RichTextBox)control).Select(cursorPos, 0);
                        ((RichTextBox)control).Focus();
                        //((RichTextBox)control).SelectionStart=cursorPos;
                    }
                }
            }
        }
Ejemplo n.º 4
0
 private void SetStaticFields(Patient pat, Family fam = null, StaticTextData staticTextData = null)
 {
     _sheetWidget = SheetUtil.CreateSheet(_sheetDefWidget, pat?.PatNum ?? 0);
     SheetFiller.FillFields(_sheetWidget, pat: pat, fam: fam, staticTextData: staticTextData);
 }
Ejemplo n.º 5
0
 public static void LoadImagesToSheetDef(SheetDef sheetDefCur)
 {
     for (int j = 0; j < sheetDefCur.SheetFieldDefs.Count; j++)
     {
         try {
             if (sheetDefCur.SheetFieldDefs[j].FieldType == SheetFieldType.Image)
             {
                 string      filePathAndName = ODFileUtils.CombinePaths(SheetUtil.GetImagePath(), sheetDefCur.SheetFieldDefs[j].FieldName);
                 Image       img             = null;
                 ImageFormat imgFormat       = null;
                 if (sheetDefCur.SheetFieldDefs[j].ImageField != null)                       //The image has already been downloaded.
                 {
                     img       = new Bitmap(sheetDefCur.SheetFieldDefs[j].ImageField);
                     imgFormat = ImageFormat.Bmp;
                 }
                 else if (sheetDefCur.SheetFieldDefs[j].FieldName == "Patient Info.gif")
                 {
                     img       = OpenDentBusiness.Properties.Resources.Patient_Info;
                     imgFormat = img.RawFormat;
                 }
                 else if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ && File.Exists(filePathAndName))
                 {
                     img       = Image.FromFile(filePathAndName);
                     imgFormat = img.RawFormat;
                 }
                 else if (CloudStorage.IsCloudStorage)
                 {
                     OpenDentalCloud.Core.TaskStateDownload state = CloudStorage.Download(SheetUtil.GetImagePath(), sheetDefCur.SheetFieldDefs[j].FieldName);
                     if (state == null || state.FileContent == null)
                     {
                         throw new Exception(Lan.g(CloudStorage.LanThis, "Unable to download image."));
                     }
                     else
                     {
                         using (MemoryStream stream = new MemoryStream(state.FileContent)) {
                             img = new Bitmap(Image.FromStream(stream));
                         }
                         imgFormat = ImageFormat.Bmp;
                     }
                 }
                 //sheetDefCur.SheetFieldDefs[j].ImageData=POut.Bitmap(new Bitmap(img),ImageFormat.Png);//Because that's what we did before. Review this later.
                 long fileByteSize = 0;
                 using (MemoryStream ms = new MemoryStream()) {
                     img.Save(ms, imgFormat);                            // done solely to compute the file size of the image
                     fileByteSize = ms.Length;
                 }
                 if (fileByteSize > 2000000)
                 {
                     //for large images greater that ~2MB use jpeg format for compression. Large images in the 4MB + range have difficulty being displayed. It could be an issue with MYSQL or ASP.NET
                     sheetDefCur.SheetFieldDefs[j].ImageData = POut.Bitmap(new Bitmap(img), ImageFormat.Jpeg);
                 }
                 else
                 {
                     sheetDefCur.SheetFieldDefs[j].ImageData = POut.Bitmap(new Bitmap(img), imgFormat);
                 }
             }
             else
             {
                 sheetDefCur.SheetFieldDefs[j].ImageData = "";                      // because null is not allowed
             }
         }
         catch (Exception ex) {
             sheetDefCur.SheetFieldDefs[j].ImageData = "";
             MessageBox.Show(ex.Message);
         }
     }
 }
Ejemplo n.º 6
0
        ///<summary>Runs as the final step of loading the form, and also immediately after fields are moved down due to growth.</summary>
        private void LayoutFields()
        {
            panelMain.Controls.Clear();
            RichTextBox   textbox;          //has to be richtextbox due to MS bug that doesn't show cursor.
            FontStyle     style;
            SheetCheckBox checkbox;

            //first, draw images---------------------------------------------------------------------------------------
            //might change this to only happen once when first loading form:
            if (pictDraw != null)
            {
                if (panelMain.Controls.Contains(pictDraw))
                {
                    Controls.Remove(pictDraw);
                }
                pictDraw = null;
            }
            imgDraw  = null;
            pictDraw = new PictureBox();
            if (SheetCur.IsLandscape)
            {
                imgDraw         = new Bitmap(SheetCur.Height, SheetCur.Width);
                pictDraw.Width  = SheetCur.Height;
                pictDraw.Height = SheetCur.Width;
            }
            else
            {
                imgDraw         = new Bitmap(SheetCur.Width, SheetCur.Height);
                pictDraw.Width  = SheetCur.Width;
                pictDraw.Height = SheetCur.Height;
            }
            pictDraw.Location = new Point(0, 0);
            pictDraw.Image    = (Image)imgDraw.Clone();
            pictDraw.SizeMode = PictureBoxSizeMode.StretchImage;
            panelMain.Controls.Add(pictDraw);
            panelMain.SendToBack();
            Graphics pictGraphics = Graphics.FromImage(imgDraw);

            foreach (SheetField field in SheetCur.SheetFields)
            {
                if (field.FieldType != SheetFieldType.Image)
                {
                    continue;
                }
                string filePathAndName = ODFileUtils.CombinePaths(SheetUtil.GetImagePath(), field.FieldName);
                Image  img             = null;
                if (field.FieldName == "Patient Info.gif")
                {
                    img = Properties.Resources.Patient_Info;
                }
                else if (File.Exists(filePathAndName))
                {
                    img = Image.FromFile(filePathAndName);
                }
                else
                {
                    continue;
                }
                pictGraphics.DrawImage(img, field.XPos, field.YPos, field.Width, field.Height);
            }
            pictGraphics.Dispose();
            //Set mouse events for the pictDraw
            pictDraw.MouseDown += new MouseEventHandler(pictDraw_MouseDown);
            pictDraw.MouseMove += new MouseEventHandler(pictDraw_MouseMove);
            pictDraw.MouseUp   += new MouseEventHandler(pictDraw_MouseUp);
            //draw drawings, rectangles, and lines-----------------------------------------------------------------------
            RefreshPanel();
            //draw textboxes----------------------------------------------------------------------------------------------
            foreach (SheetField field in SheetCur.SheetFields)
            {
                if (field.FieldType != SheetFieldType.InputField &&
                    field.FieldType != SheetFieldType.OutputText &&
                    field.FieldType != SheetFieldType.StaticText)
                {
                    continue;
                }
                textbox             = new RichTextBox();
                textbox.BorderStyle = BorderStyle.None;
                //textbox.Multiline=true;//due to MS malfunction at 9pt which cuts off the bottom of the text.
                if (field.FieldType == SheetFieldType.OutputText ||
                    field.FieldType == SheetFieldType.StaticText)
                {
                    //textbox.BackColor=Color.White;
                    //textbox.BackColor=Color.FromArgb(245,245,200);
                }
                else if (field.FieldType == SheetFieldType.InputField)
                {
                    textbox.BackColor = Color.FromArgb(245, 245, 200);
                    textbox.TabStop   = (field.TabOrder == 0?false:true);
                    textbox.TabIndex  = field.TabOrder;
                }
                textbox.Location   = new Point(field.XPos, field.YPos);
                textbox.Width      = field.Width;
                textbox.ScrollBars = RichTextBoxScrollBars.None;
                textbox.Text       = field.FieldValue;
                style = FontStyle.Regular;
                if (field.FontIsBold)
                {
                    style = FontStyle.Bold;
                }
                textbox.Font = new Font(field.FontName, field.FontSize, style);
                if (field.Height < textbox.Font.Height + 2)
                {
                    textbox.Multiline = false;
                    //textbox.AcceptsReturn=false;
                }
                else
                {
                    textbox.Multiline = true;
                    //textbox.AcceptsReturn=true;
                }
                textbox.Height = field.Height;
                //textbox.ScrollBars=RichTextBoxScrollBars.None;
                textbox.Tag          = field;
                textbox.TextChanged += new EventHandler(text_TextChanged);
                panelMain.Controls.Add(textbox);
                textbox.BringToFront();
            }
            //draw checkboxes----------------------------------------------------------------------------------------------
            foreach (SheetField field in SheetCur.SheetFields)
            {
                if (field.FieldType != SheetFieldType.CheckBox)
                {
                    continue;
                }
                checkbox = new SheetCheckBox();
                if (field.FieldValue == "X")
                {
                    checkbox.IsChecked = true;
                }
                checkbox.Location = new Point(field.XPos, field.YPos);
                checkbox.Width    = field.Width;
                checkbox.Height   = field.Height;
                checkbox.Tag      = field;
                checkbox.Click   += new EventHandler(text_TextChanged);
                checkbox.TabStop  = (field.TabOrder == 0?false:true);
                checkbox.TabIndex = field.TabOrder;
                panelMain.Controls.Add(checkbox);
                checkbox.BringToFront();
            }
            //draw signature boxes----------------------------------------------------------------------------------------------
            foreach (SheetField field in SheetCur.SheetFields)
            {
                if (field.FieldType != SheetFieldType.SigBox)
                {
                    continue;
                }
                OpenDental.UI.SignatureBoxWrapper sigBox = new OpenDental.UI.SignatureBoxWrapper();
                sigBox.Location = new Point(field.XPos, field.YPos);
                sigBox.Width    = field.Width;
                sigBox.Height   = field.Height;
                if (field.FieldValue.Length > 0)               //a signature is present
                {
                    bool sigIsTopaz = false;
                    if (field.FieldValue[0] == '1')
                    {
                        sigIsTopaz = true;
                    }
                    string signature = "";
                    if (field.FieldValue.Length > 1)
                    {
                        signature = field.FieldValue.Substring(1);
                    }
                    string keyData = Sheets.GetSignatureKey(SheetCur);
                    sigBox.FillSignature(sigIsTopaz, keyData, signature);
                }
                sigBox.Tag      = field;
                sigBox.TabStop  = (field.TabOrder == 0?false:true);
                sigBox.TabIndex = field.TabOrder;
                panelMain.Controls.Add(sigBox);
                sigBox.BringToFront();
            }
        }
Ejemplo n.º 7
0
        public static void CreatePdfPage(Sheet sheet, PdfPage page)
        {
            page.Width  = p(sheet.Width);         //XUnit.FromInch((double)sheet.Width/100);  //new XUnit((double)sheet.Width/100,XGraphicsUnit.Inch);
            page.Height = p(sheet.Height);        //new XUnit((double)sheet.Height/100,XGraphicsUnit.Inch);
            if (sheet.IsLandscape)
            {
                page.Orientation = PageOrientation.Landscape;
            }
            XGraphics g = XGraphics.FromPdfPage(page);

            g.SmoothingMode = XSmoothingMode.HighQuality;
            //g.PageUnit=XGraphicsUnit. //wish they had pixel
            //XTextFormatter tf = new XTextFormatter(g);//needed for text wrap
            //tf.Alignment=XParagraphAlignment.Left;
            //pd.DefaultPageSettings.Landscape=
            //already done?:SheetUtil.CalculateHeights(sheet,g);//this is here because of easy access to g.
            XFont      xfont;
            XFontStyle xfontstyle;

            //first, draw images--------------------------------------------------------------------------------------
            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.Image)
                {
                    continue;
                }
                string filePathAndName = ODFileUtils.CombinePaths(SheetUtil.GetImagePath(), field.FieldName);
                Bitmap bitmapOriginal  = null;
                if (field.FieldName == "Patient Info.gif")
                {
                    bitmapOriginal = Properties.Resources.Patient_Info;
                }
                else if (File.Exists(filePathAndName))
                {
                    bitmapOriginal = new Bitmap(filePathAndName);
                }
                else
                {
                    continue;
                }
                Bitmap bitmapResampled = (Bitmap)bitmapOriginal.Clone();
                if (bitmapOriginal.HorizontalResolution != 96 || bitmapOriginal.VerticalResolution != 96)            //to avoid slowdown for other pdfs
                //The scaling on the XGraphics.DrawImage() function causes unreadable output unless the image is in 96 DPI native format.
                //We use GDI here first to convert the image to the correct size and DPI, then pass the second image to XGraphics.DrawImage().
                {
                    bitmapResampled.Dispose();
                    bitmapResampled = null;
                    bitmapResampled = new Bitmap(field.Width, field.Height);
                    Graphics gr = Graphics.FromImage(bitmapResampled);
                    gr.DrawImage(bitmapOriginal, 0, 0, field.Width, field.Height);
                    gr.Dispose();
                }
                g.DrawImage(bitmapResampled, p(field.XPos), p(field.YPos), p(field.Width), p(field.Height));
                bitmapResampled.Dispose();
                bitmapResampled = null;
                bitmapOriginal.Dispose();
                bitmapOriginal = null;
            }
            //then, drawings--------------------------------------------------------------------------------------------
            XPen pen = new XPen(XColors.Black, p(2));

            string[]     pointStr;
            List <Point> points;
            Point        point;

            string[] xy;
            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.Drawing)
                {
                    continue;
                }
                pointStr = field.FieldValue.Split(';');
                points   = new List <Point>();
                for (int j = 0; j < pointStr.Length; j++)
                {
                    xy = pointStr[j].Split(',');
                    if (xy.Length == 2)
                    {
                        point = new Point(PIn.Int(xy[0]), PIn.Int(xy[1]));
                        points.Add(point);
                    }
                }
                for (int i = 1; i < points.Count; i++)
                {
                    g.DrawLine(pen, p(points[i - 1].X), p(points[i - 1].Y), p(points[i].X), p(points[i].Y));
                }
            }
            //then, rectangles and lines----------------------------------------------------------------------------------
            XPen pen2 = new XPen(XColors.Black, p(1));

            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType == SheetFieldType.Rectangle)
                {
                    g.DrawRectangle(pen2, p(field.XPos), p(field.YPos), p(field.Width), p(field.Height));
                }
                if (field.FieldType == SheetFieldType.Line)
                {
                    g.DrawLine(pen2, p(field.XPos), p(field.YPos),
                               p(field.XPos + field.Width),
                               p(field.YPos + field.Height));
                }
            }
            //then, draw text--------------------------------------------------------------------------------------------
            Bitmap   doubleBuffer = new Bitmap(sheet.Width, sheet.Height);
            Graphics gfx          = Graphics.FromImage(doubleBuffer);

            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.InputField &&
                    field.FieldType != SheetFieldType.OutputText &&
                    field.FieldType != SheetFieldType.StaticText)
                {
                    continue;
                }
                xfontstyle = XFontStyle.Regular;
                if (field.FontIsBold)
                {
                    xfontstyle = XFontStyle.Bold;
                }
                xfont = new XFont(field.FontName, field.FontSize, xfontstyle);
                //xfont=new XFont(field.FontName,field.FontSize,xfontstyle);
                //Rectangle rect=new Rectangle((int)p(field.XPos),(int)p(field.YPos),(int)p(field.Width),(int)p(field.Height));
                XRect xrect = new XRect(p(field.XPos), p(field.YPos), p(field.Width), p(field.Height));
                //XStringFormat format=new XStringFormat();
                //tf.DrawString(field.FieldValue,font,XBrushes.Black,xrect,XStringFormats.TopLeft);
                GraphicsHelper.DrawStringX(g, gfx, 1d / p(1), field.FieldValue, xfont, XBrushes.Black, xrect);
            }
            gfx.Dispose();
            //then, checkboxes----------------------------------------------------------------------------------
            XPen pen3 = new XPen(XColors.Black, p(1.6f));

            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.CheckBox)
                {
                    continue;
                }
                if (field.FieldValue == "X")
                {
                    g.DrawLine(pen3, p(field.XPos), p(field.YPos), p(field.XPos + field.Width), p(field.YPos + field.Height));
                    g.DrawLine(pen3, p(field.XPos + field.Width), p(field.YPos), p(field.XPos), p(field.YPos + field.Height));
                }
            }
            //then signature boxes----------------------------------------------------------------------
            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.SigBox)
                {
                    continue;
                }
                SignatureBoxWrapper wrapper = new SignatureBoxWrapper();
                wrapper.Width  = field.Width;
                wrapper.Height = field.Height;
                if (field.FieldValue.Length > 0)              //a signature is present
                {
                    bool sigIsTopaz = false;
                    if (field.FieldValue[0] == '1')
                    {
                        sigIsTopaz = true;
                    }
                    string signature = "";
                    if (field.FieldValue.Length > 1)
                    {
                        signature = field.FieldValue.Substring(1);
                    }
                    string keyData = Sheets.GetSignatureKey(sheet);
                    wrapper.FillSignature(sigIsTopaz, keyData, signature);
                }
                XImage sigBitmap = XImage.FromGdiPlusImage(wrapper.GetSigImage());
                g.DrawImage(sigBitmap, p(field.XPos), p(field.YPos), p(field.Width - 2), p(field.Height - 2));
            }
        }
Ejemplo n.º 8
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.SetApptStatus:
                    if (listAutomations[i].AptStatus == ApptStatus.None)
                    {
                        MsgBox.Show("Automations", "Invalid appointment status set in automation.");
                        automationHappened = true;
                        continue;
                    }
                    aptNew = Appointments.GetOneApt(aptNum);
                    if (aptNew == null)
                    {
                        MsgBox.Show("Automations", "Invalid appointment for automation.");
                        automationHappened = true;
                        continue;
                    }
                    aptOld           = aptNew.Copy();
                    aptNew.AptStatus = listAutomations[i].AptStatus;
                    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);
        }
Ejemplo n.º 9
0
        private void butView_Click(object sender, EventArgs e)
        {
            Sheet sheet = SheetUtil.CreateSheetFromWebSheet(0, _sheetAndSheetField);

            FormSheetFillEdit.ShowForm(sheet, isReadOnly: true);
        }
Ejemplo n.º 10
0
        private static void pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Graphics g = e.Graphics;

            g.SmoothingMode = SmoothingMode.HighQuality;
            Sheet sheet = SheetList[sheetsPrinted];

            SheetUtil.CalculateHeights(sheet, g);           //this is here because of easy access to g.
            Font      font;
            FontStyle fontstyle;

            //first, draw images------------------------------------------------------------------------------------
            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.Image)
                {
                    continue;
                }
                string filePathAndName = ODFileUtils.CombinePaths(SheetUtil.GetImagePath(), field.FieldName);
                Image  img             = null; //js consider switching this from an image to a bitmap
                if (field.FieldName == "Patient Info.gif")
                {
                    img = Properties.Resources.Patient_Info;
                }
                else if (File.Exists(filePathAndName))
                {
                    img = Image.FromFile(filePathAndName);
                }
                else
                {
                    continue;
                }
                g.DrawImage(img, field.XPos, field.YPos, field.Width, field.Height);
                img.Dispose();
                img = null;
            }
            //then, drawings--------------------------------------------------------------------------------------------
            Pen pen = new Pen(Brushes.Black, 2f);

            string[]     pointStr;
            List <Point> points;
            Point        point;

            string[] xy;
            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.Drawing)
                {
                    continue;
                }
                pointStr = field.FieldValue.Split(';');
                points   = new List <Point>();
                for (int p = 0; p < pointStr.Length; p++)
                {
                    xy = pointStr[p].Split(',');
                    if (xy.Length == 2)
                    {
                        point = new Point(PIn.Int(xy[0]), PIn.Int(xy[1]));
                        points.Add(point);
                    }
                }
                for (int i = 1; i < points.Count; i++)
                {
                    g.DrawLine(pen, points[i - 1].X, points[i - 1].Y, points[i].X, points[i].Y);
                }
            }
            //then, rectangles and lines----------------------------------------------------------------------------------
            Pen pen2 = new Pen(Brushes.Black, 1f);

            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType == SheetFieldType.Rectangle)
                {
                    g.DrawRectangle(pen2, field.XPos, field.YPos, field.Width, field.Height);
                }
                if (field.FieldType == SheetFieldType.Line)
                {
                    g.DrawLine(pen2, field.XPos, field.YPos,
                               field.XPos + field.Width,
                               field.YPos + field.Height);
                }
            }
            //then, draw text-----------------------------------------------------------------------------------------------
            Bitmap   doubleBuffer = new Bitmap(sheet.Width, sheet.Height);
            Graphics gfx          = Graphics.FromImage(doubleBuffer);

            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.InputField &&
                    field.FieldType != SheetFieldType.OutputText &&
                    field.FieldType != SheetFieldType.StaticText)
                {
                    continue;
                }
                fontstyle = FontStyle.Regular;
                if (field.FontIsBold)
                {
                    fontstyle = FontStyle.Bold;
                }
                font = new Font(field.FontName, field.FontSize, fontstyle);
                Plugins.HookAddCode(null, "SheetPrinting.pd_PrintPage_drawFieldLoop", field);
                GraphicsHelper.DrawString(g, gfx, field.FieldValue, font, Brushes.Black, field.Bounds);
                //g.DrawString(field.FieldValue,font,Brushes.Black,field.BoundsF);
            }
            gfx.Dispose();
            //then, checkboxes----------------------------------------------------------------------------------
            Pen pen3 = new Pen(Brushes.Black, 1.6f);

            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.CheckBox)
                {
                    continue;
                }
                if (field.FieldValue == "X")
                {
                    g.DrawLine(pen3, field.XPos, field.YPos, field.XPos + field.Width, field.YPos + field.Height);
                    g.DrawLine(pen3, field.XPos + field.Width, field.YPos, field.XPos, field.YPos + field.Height);
                }
            }
            //then signature boxes----------------------------------------------------------------------
            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.SigBox)
                {
                    continue;
                }
                SignatureBoxWrapper wrapper = new SignatureBoxWrapper();
                wrapper.Width  = field.Width;
                wrapper.Height = field.Height;
                if (field.FieldValue.Length > 0)              //a signature is present
                {
                    bool sigIsTopaz = false;
                    if (field.FieldValue[0] == '1')
                    {
                        sigIsTopaz = true;
                    }
                    string signature = "";
                    if (field.FieldValue.Length > 1)
                    {
                        signature = field.FieldValue.Substring(1);
                    }
                    string keyData = Sheets.GetSignatureKey(sheet);
                    wrapper.FillSignature(sigIsTopaz, keyData, signature);
                }
                Bitmap sigBitmap = wrapper.GetSigImage();
                g.DrawImage(sigBitmap, field.XPos, field.YPos, field.Width - 2, field.Height - 2);
            }
            g.Dispose();
            //no logic yet for multiple pages on one sheet.
            sheetsPrinted++;
            //heightsCalculated=false;
            if (sheetsPrinted < SheetList.Count)
            {
                e.HasMorePages = true;
            }
            else
            {
                e.HasMorePages = false;
                sheetsPrinted  = 0;
            }
        }
Ejemplo n.º 11
0
        private void butImport_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Multiselect = false;
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            if (!File.Exists(dlg.FileName))
            {
                MsgBox.Show(this, "File does not exist.");
                return;
            }
            if (!ImageHelper.HasImageExtension(dlg.FileName))
            {
                MsgBox.Show(this, "Only allowed to import an image.");
                return;
            }
            string newName = dlg.FileName;

            if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ)
            {
                newName = ODFileUtils.CombinePaths(SheetUtil.GetImagePath(), Path.GetFileName(dlg.FileName));
                if (File.Exists(newName))
                {
                    MsgBox.Show(this, "A file of that name already exists in SheetImages.  Please rename the file before importing.");
                    return;
                }
                File.Copy(dlg.FileName, newName);
            }
            else if (CloudStorage.IsCloudStorage)
            {
                if (CloudStorage.FileExists(ODFileUtils.CombinePaths(SheetUtil.GetImagePath(), Path.GetFileName(dlg.FileName))))
                {
                    MsgBox.Show(this, "A file of that name already exists in SheetImages.  Please rename the file before importing.");
                    return;
                }
                FormProgress FormP = new FormProgress();
                FormP.DisplayText          = Lan.g(CloudStorage.LanThis, "Uploading...");
                FormP.NumberFormat         = "F";
                FormP.NumberMultiplication = 1;
                FormP.MaxVal = 100;              //Doesn't matter what this value is as long as it is greater than 0
                FormP.TickMS = 1000;
                OpenDentalCloud.Core.TaskStateUpload state = CloudStorage.UploadAsync(SheetUtil.GetImagePath(), Path.GetFileName(dlg.FileName)
                                                                                      , File.ReadAllBytes(dlg.FileName)
                                                                                      , new OpenDentalCloud.ProgressHandler(FormP.OnProgress));
                if (FormP.ShowDialog() == DialogResult.Cancel)
                {
                    state.DoCancel = true;
                    return;
                }
                newName = Path.GetFileName(dlg.FileName);
                //It would be nice to save the image somewhere so that we don't have to download it again.
            }
            FillCombo();
            for (int i = 0; i < comboFieldName.Items.Count; i++)
            {
                if (comboFieldName.Items[i].ToString() == Path.GetFileName(newName))
                {
                    comboFieldName.SelectedIndex = i;
                    comboFieldName.Text          = Path.GetFileName(newName);
                    FillImage();
                    ShrinkToFit();
                }
            }
        }
Ejemplo n.º 12
0
 private void FillCombo()
 {
     if (PrefC.AtoZfolderUsed != DataStorageType.InDatabase)
     {
         comboFieldName.Items.Clear();
         string[] files = null;
         if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ)
         {
             files = Directory.GetFiles(SheetUtil.GetImagePath());
         }
         else                  //Cloud
                               //Get file list
         {
             OpenDentalCloud.Core.TaskStateListFolders state = CloudStorage.ListFolderContents(SheetUtil.GetImagePath());
             files = state.ListFolderPathsDisplay.ToArray();
         }
         for (int i = 0; i < files.Length; i++)
         {
             //remove some common offending file types (non image files)
             if (files[i].EndsWith("db") ||
                 files[i].EndsWith("doc") ||
                 files[i].EndsWith("pdf")
                 )
             {
                 continue;
             }
             comboFieldName.Items.Add(Path.GetFileName(files[i]));
         }
         //comboFieldName.Items.Add("Patient Info.gif");
     }
 }
Ejemplo n.º 13
0
 private void FillImage()
 {
     if (comboFieldName.Text == "")
     {
         return;
     }
     if (CloudStorage.IsCloudStorage)
     {
         textFullPath.Text = CloudStorage.PathTidy(ODFileUtils.CombinePaths(SheetUtil.GetImagePath(), comboFieldName.Text));
     }
     else
     {
         textFullPath.Text = ODFileUtils.CombinePaths(SheetUtil.GetImagePath(), comboFieldName.Text);
     }
     if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ && File.Exists(textFullPath.Text))
     {
         GC.Collect();
         try {
             pictureBox.Image = Image.FromFile(textFullPath.Text);
         }
         catch {
             pictureBox.Image = null;
             MsgBox.Show(this, "Invalid image type.");
         }
     }
     else if (comboFieldName.Text == "Patient Info.gif")           //Interal image
     {
         pictureBox.Image  = OpenDentBusiness.Properties.Resources.Patient_Info;
         textFullPath.Text = "Patient Info.gif (internal)";
     }
     else if (CloudStorage.IsCloudStorage)
     {
         if (comboFieldName.Text == SheetFieldDefCur.FieldName && SheetFieldDefCur.ImageField != null)
         {
             pictureBox.Image = SheetFieldDefCur.ImageField;
         }
         else
         {
             FormProgress FormP = new FormProgress();
             FormP.DisplayText          = Lan.g(CloudStorage.LanThis, "Downloading...");
             FormP.NumberFormat         = "F";
             FormP.NumberMultiplication = 1;
             FormP.MaxVal = 100;                  //Doesn't matter what this value is as long as it is greater than 0
             FormP.TickMS = 1000;
             OpenDentalCloud.Core.TaskStateDownload state = CloudStorage.DownloadAsync(SheetUtil.GetImagePath(), comboFieldName.Text,
                                                                                       new OpenDentalCloud.ProgressHandler(FormP.OnProgress));
             if (FormP.ShowDialog() == DialogResult.Cancel)
             {
                 state.DoCancel = true;
                 return;
             }
             if (state == null || state.FileContent == null)
             {
                 pictureBox.Image = null;
             }
             else
             {
                 using (MemoryStream stream = new MemoryStream(state.FileContent)) {
                     pictureBox.Image = new Bitmap(Image.FromStream(stream));
                 }
             }
         }
     }
     else
     {
         pictureBox.Image = null;
     }
     if (pictureBox.Image == null)
     {
         textWidth2.Text  = "";
         textHeight2.Text = "";
     }
     else
     {
         textWidth2.Text  = pictureBox.Image.Width.ToString();
         textHeight2.Text = pictureBox.Image.Height.ToString();
     }
 }
Ejemplo n.º 14
0
        ///<summary>Returns true if the import was successful. Imports either a webform or a sheet that was transferred using the CEMT tool.
        ///Tries to find a matching patient using LName,FName,and DOB. If no matching patient is found automatically, it will allow the user to either
        ///create a new patient, select an existing patient,delete, or skip the sheet. Call using a try/catch.</summary>
        private static bool DidImportSheet(WebForms_Sheet webFormsSheet, Sheet sheet, List <WebForms_Sheet> listWebSheets, List <Sheet> listSheets, string cultureName,
                                           ref List <long> listSheetIdsForDeletion)
        {
            bool          isWebForms       = webFormsSheet != null && listWebSheets != null;
            long          patNum           = 0;
            string        lName            = "";
            string        fName            = "";
            List <string> listPhoneNumbers = new List <string>();
            string        email            = "";
            DateTime      bDate            = DateTime.MinValue;

            if (isWebForms)
            {
                WebForms_Sheets.ParseWebFormSheet(webFormsSheet, cultureName, out lName, out fName, out bDate, out listPhoneNumbers, out email);
            }
            else
            {
                Sheets.ParseTransferSheet(sheet, out lName, out fName, out bDate, out listPhoneNumbers, out email);
            }
            List <long> listMatchingPats = Patients.GetPatNumsByNameBirthdayEmailAndPhone(lName, fName, bDate, email, listPhoneNumbers);
            Patient     pat = null;

            if (listMatchingPats.IsNullOrEmpty() || listMatchingPats.Count > 1)             //0 or > 1
            {
                List <long> listWebSheetNumsForPat = new List <long>();
                if (isWebForms)
                {
                    List <long> listSheetsToDelete = listSheetIdsForDeletion;
                    listWebSheetNumsForPat = WebForms_Sheets.FindSheetsForPat(webFormsSheet, listWebSheets, cultureName)
                                             //Only include web sheets that have not already been imported
                                             .Where(x => !listSheetsToDelete.Contains(x)).ToList();
                }
                else                  //Cemt Import
                {
                    listWebSheetNumsForPat = Sheets.FindSheetsForPat(sheet, listSheets);
                }
                FormPatientPickWebForm FormPpw = new FormPatientPickWebForm(webFormsSheet, listWebSheetNumsForPat.Count, sheet);
                FormPpw.LnameEntered        = lName;
                FormPpw.FnameEntered        = fName;
                FormPpw.BdateEntered        = bDate;
                FormPpw.HasMoreThanOneMatch = (listMatchingPats.Count > 1);
                FormPpw.ShowDialog();
                if (FormPpw.DialogResult == DialogResult.Cancel)
                {
                    if (isWebForms)
                    {
                        //user wants to stop importing altogether
                        //we will pick up where we left off here next time
                        WebForms_Sheets.DeleteSheetData(listSheetIdsForDeletion.Distinct().ToList());
                    }
                    return(false);                   // only false when user wants to stop importing
                }
                else if (FormPpw.DialogResult == DialogResult.Ignore)
                {
                    if (FormPpw.IsDiscardAll)
                    {
                        //user wants to delete all webforms for this patient. Mark them for deletion.
                        listSheetIdsForDeletion.AddRange(listWebSheetNumsForPat);
                    }
                    return(true);                //continue on to the next one
                }
                patNum = FormPpw.SelectedPatNum; //might be zero to indicate new patient
            }
            else                                 //Exactly one match was found so make a log entry what the match was.
            {
                patNum = listMatchingPats[0];
                pat    = Patients.GetPat(patNum);
                //Security log for OD automatically importing a sheet into a patient.
                string logText;
                if (isWebForms)
                {
                    logText = Lan.g("FormWebForms", "Web form import from:");
                }
                else
                {
                    logText = Lan.g("FormWebForms", "CEMT patient transfer import from:");
                }
                logText += " " + lName + ", " + fName + " " + bDate.ToShortDateString() + "\r\n"
                           + Lan.g("FormWebForms", "Auto imported into:") + " " + pat.LName + ", " + pat.FName + " " + pat.Birthdate.ToShortDateString();
                SecurityLogs.MakeLogEntry(Permissions.SheetEdit, patNum, logText);
            }
            if (patNum == 0)
            {
                pat    = CreatePatient(lName, fName, bDate, webFormsSheet, sheet, cultureName);
                patNum = pat.PatNum;
                //Security log for user creating a new patient.
                string logText;
                if (isWebForms)
                {
                    logText = Lan.g("FormWebForms", "Web form import from:");
                }
                else
                {
                    logText = Lan.g("FormWebForms", "CEMT patient transfer import from:");
                }
                logText += " " + lName + ", " + fName + " " + bDate.ToShortDateString() + "\r\n"
                           + Lan.g("FormWebForms", "User created new pat:") + " " + pat.LName + ", " + pat.FName + " " + pat.Birthdate.ToShortDateString();
                SecurityLogs.MakeLogEntry(Permissions.SheetEdit, patNum, logText);
            }
            else if (pat == null)
            {
                pat = Patients.GetPat(patNum);
            }
            //We should probably make a security log entry for a manually selected patient.
            if (isWebForms)
            {
                Sheet newSheet = SheetUtil.CreateSheetFromWebSheet(patNum, webFormsSheet);
                Sheets.SaveNewSheet(newSheet);
                if (DataExistsInDb(newSheet))
                {
                    listSheetIdsForDeletion.Add(webFormsSheet.SheetID);
                }
            }
            else              //CEMT Patient Transfer
                              //Sheet is ready to get updated with the patient.
            {
                sheet.PatNum        = patNum;
                sheet.DateTimeSheet = MiscData.GetNowDateTime();
                if (PrefC.HasClinicsEnabled)
                {
                    sheet.ClinicNum = pat.ClinicNum;
                }
                sheet.IsWebForm = true;              //This is so the sheet shows up in gridmain in this form.
                Sheets.Update(sheet);
            }
            return(true);
        }
Ejemplo n.º 15
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);
        }