Пример #1
0
 ///<summary>Inserts one EmailAttach into the database.  Returns the new priKey.</summary>
 internal static long Insert(EmailAttach emailAttach)
 {
     if(DataConnection.DBtype==DatabaseType.Oracle) {
         emailAttach.EmailAttachNum=DbHelper.GetNextOracleKey("emailattach","EmailAttachNum");
         int loopcount=0;
         while(loopcount<100){
             try {
                 return Insert(emailAttach,true);
             }
             catch(Oracle.DataAccess.Client.OracleException ex){
                 if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
                     emailAttach.EmailAttachNum++;
                     loopcount++;
                 }
                 else{
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else {
         return Insert(emailAttach,false);
     }
 }
Пример #2
0
        private void menuItemRemove_Click(object sender, EventArgs e)
        {
            EmailAttach emailAttach = _listEmailAttachDisplayed[gridAttachments.SelectedIndices[0]];

            _emailMessage.Attachments.Remove(emailAttach);
            FillAttachments();
        }
Пример #3
0
 ///<summary>Inserts one EmailAttach into the database.  Provides option to use the existing priKey.</summary>
 internal static long Insert(EmailAttach emailAttach,bool useExistingPK)
 {
     if(!useExistingPK && PrefC.RandomKeys) {
         emailAttach.EmailAttachNum=ReplicationServers.GetKey("emailattach","EmailAttachNum");
     }
     string command="INSERT INTO emailattach (";
     if(useExistingPK || PrefC.RandomKeys) {
         command+="EmailAttachNum,";
     }
     command+="EmailMessageNum,DisplayedFileName,ActualFileName) VALUES(";
     if(useExistingPK || PrefC.RandomKeys) {
         command+=POut.Long(emailAttach.EmailAttachNum)+",";
     }
     command+=
              POut.Long  (emailAttach.EmailMessageNum)+","
         +"'"+POut.String(emailAttach.DisplayedFileName)+"',"
         +"'"+POut.String(emailAttach.ActualFileName)+"')";
     if(useExistingPK || PrefC.RandomKeys) {
         Db.NonQ(command);
     }
     else {
         emailAttach.EmailAttachNum=Db.NonQ(command,true);
     }
     return emailAttach.EmailAttachNum;
 }
Пример #4
0
        ///<summary>Inserts one EmailAttach into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(EmailAttach emailAttach, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO emailattach (";

            if (!useExistingPK && isRandomKeys)
            {
                emailAttach.EmailAttachNum = ReplicationServers.GetKeyNoCache("emailattach", "EmailAttachNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "EmailAttachNum,";
            }
            command += "EmailMessageNum,DisplayedFileName,ActualFileName,EmailTemplateNum) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(emailAttach.EmailAttachNum) + ",";
            }
            command +=
                POut.Long(emailAttach.EmailMessageNum) + ","
                + "'" + POut.String(emailAttach.DisplayedFileName) + "',"
                + "'" + POut.String(emailAttach.ActualFileName) + "',"
                + POut.Long(emailAttach.EmailTemplateNum) + ")";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                emailAttach.EmailAttachNum = Db.NonQ(command, true, "EmailAttachNum", "emailAttach");
            }
            return(emailAttach.EmailAttachNum);
        }
Пример #5
0
        ///<summary>Inserts one EmailAttach into the database.  Provides option to use the existing priKey.</summary>
        internal static long Insert(EmailAttach emailAttach, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                emailAttach.EmailAttachNum = ReplicationServers.GetKey("emailattach", "EmailAttachNum");
            }
            string command = "INSERT INTO emailattach (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "EmailAttachNum,";
            }
            command += "EmailMessageNum,DisplayedFileName,ActualFileName) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(emailAttach.EmailAttachNum) + ",";
            }
            command +=
                POut.Long(emailAttach.EmailMessageNum) + ","
                + "'" + POut.String(emailAttach.DisplayedFileName) + "',"
                + "'" + POut.String(emailAttach.ActualFileName) + "')";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                emailAttach.EmailAttachNum = Db.NonQ(command, true);
            }
            return(emailAttach.EmailAttachNum);
        }
Пример #6
0
 ///<summary>Inserts one EmailAttach into the database.  Returns the new priKey.</summary>
 internal static long Insert(EmailAttach emailAttach)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         emailAttach.EmailAttachNum = DbHelper.GetNextOracleKey("emailattach", "EmailAttachNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(emailAttach, true));
             }
             catch (Oracle.DataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     emailAttach.EmailAttachNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(emailAttach, false));
     }
 }
Пример #7
0
        private void listAttachments_DoubleClick(object sender, EventArgs e)
        {
            if (listAttachments.SelectedIndex == -1)
            {
                return;
            }
            EmailAttach attach = _listAttachments[listAttachments.SelectedIndex];

            FileAtoZ.OpenFile(FileAtoZ.CombinePaths(EmailAttaches.GetAttachPath(), attach.ActualFileName), attach.DisplayedFileName);
        }
Пример #8
0
        ///<summary>Updates one EmailAttach in the database.</summary>
        internal static void Update(EmailAttach emailAttach)
        {
            string command = "UPDATE emailattach SET "
                             + "EmailMessageNum  =  " + POut.Long(emailAttach.EmailMessageNum) + ", "
                             + "DisplayedFileName= '" + POut.String(emailAttach.DisplayedFileName) + "', "
                             + "ActualFileName   = '" + POut.String(emailAttach.ActualFileName) + "' "
                             + "WHERE EmailAttachNum = " + POut.Long(emailAttach.EmailAttachNum);

            Db.NonQ(command);
        }
Пример #9
0
        public void EmailAttaches_CreateAttach_InvalidDisaplyName()
        {
            string      displayName       = "invalid*display?Name.gif";
            EmailAttach emailAttachFirst  = EmailAttaches.CreateAttach(displayName, "", Encoding.UTF8.GetBytes(_attachmentRaw), false);
            EmailAttach emailAttachSecond = EmailAttaches.CreateAttach(displayName, "", Encoding.UTF8.GetBytes(_attachmentRaw), false);

            Assert.IsTrue(File.Exists(ODFileUtils.CombinePaths(EmailAttaches.GetAttachPath(), emailAttachFirst.ActualFileName)));
            Assert.IsTrue(File.Exists(ODFileUtils.CombinePaths(EmailAttaches.GetAttachPath(), emailAttachSecond.ActualFileName)));
            Assert.AreNotEqual(emailAttachFirst.ActualFileName, emailAttachSecond.ActualFileName);
        }
Пример #10
0
		private void menuItemRename_Click(object sender,EventArgs e) {
			InputBox input=new InputBox(Lan.g(this,"Filename"));
			EmailAttach emailAttach=_listEmailAttachDisplayed[gridAttachments.SelectedIndices[0]];
			input.textResult.Text=emailAttach.DisplayedFileName;
			input.ShowDialog();
			if(input.DialogResult!=DialogResult.OK) {
				return;
			}
			emailAttach.DisplayedFileName=input.textResult.Text;
			FillAttachments();
		}
Пример #11
0
        private void butAttach_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Multiselect = true;
            Patient PatCur = Patients.GetPat(MessageCur.PatNum);

            if (PatCur.ImageFolder != "")
            {
                if (PrefB.UsingAtoZfolder)
                {
                    dlg.InitialDirectory = ODFileUtils.CombinePaths(new string[] { FormPath.GetPreferredImagePath(),
                                                                                   PatCur.ImageFolder.Substring(0, 1).ToUpper(),
                                                                                   PatCur.ImageFolder });
                }
                else
                {
                    //Use the OS default directory for this type of file viewer.
                    dlg.InitialDirectory = "";
                }
            }
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            Random      rnd = new Random();
            string      newName;
            EmailAttach attach;
            string      attachPath = GetAttachPath();

            if (!Directory.Exists(attachPath))
            {
                Directory.CreateDirectory(attachPath);
            }
            try{
                for (int i = 0; i < dlg.FileNames.Length; i++)
                {
                    //copy the file
                    newName = DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString() + rnd.Next(1000).ToString();
                    File.Copy(dlg.FileNames[i], ODFileUtils.CombinePaths(attachPath, newName));
                    //create the attachment
                    attach = new EmailAttach();
                    attach.DisplayedFileName = Path.GetFileName(dlg.FileNames[i]);
                    attach.ActualFileName    = newName;
                    MessageCur.Attachments.Add(attach);
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
            FillAttachments();
        }
Пример #12
0
        ///<summary>Gets one email message from the database.</summary>
        public static EmailMessage GetOne(int msgNum)
        {
            string commands = "SELECT * FROM emailmessage WHERE EmailMessageNum = " + POut.PInt(msgNum)
                              + ";SELECT * FROM emailattach WHERE EmailMessageNum = " + POut.PInt(msgNum);
            DataSet ds = null;

            try {
                if (RemotingClient.OpenDentBusinessIsLocal)
                {
                    ds = GeneralB.GetDataSet(commands);
                }
                else
                {
                    DtoGeneralGetDataSet dto = new DtoGeneralGetDataSet();
                    dto.Commands = commands;
                    ds           = RemotingClient.ProcessQuery(dto);
                }
            }
            catch (Exception e) {
                MessageBox.Show(e.Message);
            }
            DataTable    table = ds.Tables[0];
            EmailMessage Cur   = new EmailMessage();

            if (table.Rows.Count == 0)
            {
                return(null);
            }
            //for(int i=0;i<table.Rows.Count;i++){
            Cur.EmailMessageNum = PIn.PInt(table.Rows[0][0].ToString());
            Cur.PatNum          = PIn.PInt(table.Rows[0][1].ToString());
            Cur.ToAddress       = PIn.PString(table.Rows[0][2].ToString());
            Cur.FromAddress     = PIn.PString(table.Rows[0][3].ToString());
            Cur.Subject         = PIn.PString(table.Rows[0][4].ToString());
            Cur.BodyText        = PIn.PString(table.Rows[0][5].ToString());
            Cur.MsgDateTime     = PIn.PDateT(table.Rows[0][6].ToString());
            Cur.SentOrReceived  = (CommSentOrReceived)PIn.PInt(table.Rows[0][7].ToString());
            table           = ds.Tables[1];
            Cur.Attachments = new List <EmailAttach>();
            EmailAttach attach;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                attach = new EmailAttach();
                attach.EmailAttachNum    = PIn.PInt(table.Rows[i][0].ToString());
                attach.EmailMessageNum   = PIn.PInt(table.Rows[i][1].ToString());
                attach.DisplayedFileName = PIn.PString(table.Rows[i][2].ToString());
                attach.ActualFileName    = PIn.PString(table.Rows[i][3].ToString());
                Cur.Attachments.Add(attach);
            }
            return(Cur);
        }
Пример #13
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<EmailAttach> TableToList(DataTable table){
			List<EmailAttach> retVal=new List<EmailAttach>();
			EmailAttach emailAttach;
			for(int i=0;i<table.Rows.Count;i++) {
				emailAttach=new EmailAttach();
				emailAttach.EmailAttachNum   = PIn.Long  (table.Rows[i]["EmailAttachNum"].ToString());
				emailAttach.EmailMessageNum  = PIn.Long  (table.Rows[i]["EmailMessageNum"].ToString());
				emailAttach.DisplayedFileName= PIn.String(table.Rows[i]["DisplayedFileName"].ToString());
				emailAttach.ActualFileName   = PIn.String(table.Rows[i]["ActualFileName"].ToString());
				retVal.Add(emailAttach);
			}
			return retVal;
		}
Пример #14
0
        private void OpenFile()
        {
            EmailAttach emailAttach       = _listEmailAttachDisplayed[gridAttachments.SelectedIndices[0]];
            string      strFilePathAttach = FileAtoZ.CombinePaths(EmailAttaches.GetAttachPath(), emailAttach.ActualFileName);

            try {
                if (EhrCCD.IsCcdEmailAttachment(emailAttach))
                {
                    string strTextXml = FileAtoZ.ReadAllText(strFilePathAttach);
                    if (EhrCCD.IsCCD(strTextXml))
                    {
                        Patient patEmail = null;                      //Will be null for most email messages.
                        if (_emailMessage.SentOrReceived == EmailSentOrReceived.ReadDirect || _emailMessage.SentOrReceived == EmailSentOrReceived.ReceivedDirect)
                        {
                            patEmail = _patCur;                          //Only allow reconcile if received via Direct.
                        }
                        string strAlterateFilPathXslCCD = "";
                        //Try to find a corresponding stylesheet. This will only be used in the event that the default stylesheet cannot be loaded from the EHR dll.
                        for (int i = 0; i < _listEmailAttachDisplayed.Count; i++)
                        {
                            if (Path.GetExtension(_listEmailAttachDisplayed[i].ActualFileName).ToLower() == ".xsl")
                            {
                                strAlterateFilPathXslCCD = FileAtoZ.CombinePaths(EmailAttaches.GetAttachPath(), _listEmailAttachDisplayed[i].ActualFileName);
                                break;
                            }
                        }
                        FormEhrSummaryOfCare.DisplayCCD(strTextXml, patEmail, strAlterateFilPathXslCCD);
                        return;
                    }
                }
                else if (IsORU_R01message(strFilePathAttach))
                {
                    if (DataConnection.DBtype == DatabaseType.Oracle)
                    {
                        MsgBox.Show(this, "Labs not supported with Oracle.  Opening raw file instead.");
                    }
                    else
                    {
                        FormEhrLabOrderImport FormELOI = new FormEhrLabOrderImport();
                        FormELOI.Hl7LabMessage = FileAtoZ.ReadAllText(strFilePathAttach);
                        FormELOI.ShowDialog();
                        return;
                    }
                }
                FileAtoZ.OpenFile(FileAtoZ.CombinePaths(EmailAttaches.GetAttachPath(), emailAttach.ActualFileName), emailAttach.DisplayedFileName);
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
Пример #15
0
 ///<summary>Inserts one EmailAttach into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(EmailAttach emailAttach)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(emailAttach, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             emailAttach.EmailAttachNum = DbHelper.GetNextOracleKey("emailattach", "EmailAttachNum");                  //Cacheless method
         }
         return(InsertNoCache(emailAttach, true));
     }
 }
Пример #16
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        internal static List <EmailAttach> TableToList(DataTable table)
        {
            List <EmailAttach> retVal = new List <EmailAttach>();
            EmailAttach        emailAttach;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                emailAttach = new EmailAttach();
                emailAttach.EmailAttachNum    = PIn.Long(table.Rows[i]["EmailAttachNum"].ToString());
                emailAttach.EmailMessageNum   = PIn.Long(table.Rows[i]["EmailMessageNum"].ToString());
                emailAttach.DisplayedFileName = PIn.String(table.Rows[i]["DisplayedFileName"].ToString());
                emailAttach.ActualFileName    = PIn.String(table.Rows[i]["ActualFileName"].ToString());
                retVal.Add(emailAttach);
            }
            return(retVal);
        }
Пример #17
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <EmailAttach> TableToList(DataTable table)
        {
            List <EmailAttach> retVal = new List <EmailAttach>();
            EmailAttach        emailAttach;

            foreach (DataRow row in table.Rows)
            {
                emailAttach = new EmailAttach();
                emailAttach.EmailAttachNum    = PIn.Long(row["EmailAttachNum"].ToString());
                emailAttach.EmailMessageNum   = PIn.Long(row["EmailMessageNum"].ToString());
                emailAttach.DisplayedFileName = PIn.String(row["DisplayedFileName"].ToString());
                emailAttach.ActualFileName    = PIn.String(row["ActualFileName"].ToString());
                emailAttach.EmailTemplateNum  = PIn.Long(row["EmailTemplateNum"].ToString());
                retVal.Add(emailAttach);
            }
            return(retVal);
        }
Пример #18
0
        ///<summary>Updates one EmailAttach in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
        public static bool Update(EmailAttach emailAttach, EmailAttach oldEmailAttach)
        {
            string command = "";

            if (emailAttach.EmailMessageNum != oldEmailAttach.EmailMessageNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "EmailMessageNum = " + POut.Long(emailAttach.EmailMessageNum) + "";
            }
            if (emailAttach.DisplayedFileName != oldEmailAttach.DisplayedFileName)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DisplayedFileName = '" + POut.String(emailAttach.DisplayedFileName) + "'";
            }
            if (emailAttach.ActualFileName != oldEmailAttach.ActualFileName)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ActualFileName = '" + POut.String(emailAttach.ActualFileName) + "'";
            }
            if (emailAttach.EmailTemplateNum != oldEmailAttach.EmailTemplateNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "EmailTemplateNum = " + POut.Long(emailAttach.EmailTemplateNum) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE emailattach SET " + command
                      + " WHERE EmailAttachNum = " + POut.Long(emailAttach.EmailAttachNum);
            Db.NonQ(command);
            return(true);
        }
Пример #19
0
        private void butAttach_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Multiselect = true;
            Patient PatCur = Patients.GetPat(MessageCur.PatNum);

            if (PatCur.ImageFolder != "")
            {
                dlg.InitialDirectory = PrefB.GetString("DocPath") + PatCur.ImageFolder.Substring(0, 1) + @"\" + PatCur.ImageFolder + @"\";
            }
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            Random      rnd = new Random();
            string      newName;
            EmailAttach attach;
            string      attachPath = PrefB.GetString("DocPath") + @"EmailAttachments\";

            if (!Directory.Exists(attachPath))
            {
                Directory.CreateDirectory(attachPath);
            }
            try{
                for (int i = 0; i < dlg.FileNames.Length; i++)
                {
                    //copy the file
                    newName = DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString() + rnd.Next(1000).ToString();
                    File.Copy(dlg.FileNames[i], attachPath + newName);
                    //create the attachment
                    attach = new EmailAttach();
                    attach.DisplayedFileName = Path.GetFileName(dlg.FileNames[i]);
                    attach.ActualFileName    = newName;
                    MessageCur.Attachments.Add(attach);
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
            FillAttachments();
        }
Пример #20
0
 ///<summary>Returns true if Update(EmailAttach,EmailAttach) would make changes to the database.
 ///Does not make any changes to the database and can be called before remoting role is checked.</summary>
 public static bool UpdateComparison(EmailAttach emailAttach, EmailAttach oldEmailAttach)
 {
     if (emailAttach.EmailMessageNum != oldEmailAttach.EmailMessageNum)
     {
         return(true);
     }
     if (emailAttach.DisplayedFileName != oldEmailAttach.DisplayedFileName)
     {
         return(true);
     }
     if (emailAttach.ActualFileName != oldEmailAttach.ActualFileName)
     {
         return(true);
     }
     if (emailAttach.EmailTemplateNum != oldEmailAttach.EmailTemplateNum)
     {
         return(true);
     }
     return(false);
 }
Пример #21
0
		///<summary>Accepts a list of MimeEntity and parses it for paths, htmls and other key factors. It will test that the resulting parts
		///have a valid image extension. If they do, they are saved to a temporary web page for presentation to the user. If they are not
		///then they are disreguarded an a message is sent to the user warning them of potentially malicious content.</summary>
		private string ParseAndSaveAttachement(string htmlFolderPath,string html,List<MimeEntity> listParts) {
				bool hasDangerousAttachment=false;
				foreach(MimeEntity entity in listParts) {
					string contentId=EmailMessages.GetMimeImageContentId(entity);
					string fileName=EmailMessages.GetMimeImageFileName(entity);
					//Only show image types.  Otherwise, prompt user that potentially dangerous code is attached to the email and will not be shown.
					if(!ImageStore.HasImageExtension(fileName)) {//Check file format against known image format extensions.
						hasDangerousAttachment=true;
						continue;
					}
					html=html.Replace("cid:"+contentId,fileName);
					EmailAttach attachment=_listEmailAttachDisplayed.FirstOrDefault(x => x.DisplayedFileName.ToLower().Trim()==fileName.ToLower().Trim());
					//The path and filename must be directly accessed from the EmailAttach object in question, otherwise subsequent code would have accessed
					//an empty bodied message and never shown an image.
					EmailMessages.SaveMimeImageToFile(entity,htmlFolderPath,attachment?.ActualFileName);
				}
				if(hasDangerousAttachment) {
					//Since the extension is not within the image formats it may contain mallware and we will not parse or present it.
					MsgBox.Show("This message contains some elements that may not be safe and will not be loaded.");
				}
				return html;
		}
Пример #22
0
        private void butSendToPortal_Click(object sender, EventArgs e)
        {
            //Validate
            string strCcdValidationErrors = EhrCCD.ValidateSettings();

            if (strCcdValidationErrors != "")            //Do not even try to export if global settings are invalid.
            {
                MessageBox.Show(strCcdValidationErrors); //We do not want to use translations here, because the text is dynamic. The errors are generated in the business layer, and Lan.g() is not available there.
                return;
            }
            strCcdValidationErrors = EhrCCD.ValidatePatient(PatCur);          //Patient cannot be null, because a patient must be selected before the EHR dashboard will open.
            if (strCcdValidationErrors != "")
            {
                MessageBox.Show(strCcdValidationErrors);                //We do not want to use translations here, because the text is dynamic. The errors are generated in the business layer, and Lan.g() is not available there.
                return;
            }
            Provider prov = null;

            if (Security.CurUser.ProvNum != 0)           //If the current user is a provider.
            {
                prov = Providers.GetProv(Security.CurUser.ProvNum);
            }
            else
            {
                prov = Providers.GetProv(PatCur.PriProv);              //PriProv is not 0, because EhrCCD.ValidatePatient() will block if PriProv is 0.
            }
            try {
                //Create the Clinical Summary.
                FormEhrExportCCD FormEEC = new FormEhrExportCCD(PatCur);
                FormEEC.ShowDialog();
                if (FormEEC.DialogResult != DialogResult.OK)               //Canceled
                {
                    return;
                }
                //Save the clinical summary (ccd.xml) and style sheet (ccd.xsl) as webmail message attachments.
                //TODO: It would be more patient friendly if we instead generated a PDF file containing the Clinical Summary printout, or if we simply displayed the Clinical Summary in the portal.
                //The CMS definition does not prohibit sending human readable files, and sending a PDF to the portal mimics printing the Clinical Summary and handing to patient.
                Random             rnd             = new Random();
                string             attachPath      = EmailAttaches.GetAttachPath();
                List <EmailAttach> listAttachments = new List <EmailAttach>();
                EmailAttach        attachCcd       = new EmailAttach(); //Save Clinical Summary to file in the email attachments folder.
                attachCcd.DisplayedFileName = "ccd.xml";
                attachCcd.ActualFileName    = DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString() + rnd.Next(1000).ToString() + ".xml";
                listAttachments.Add(attachCcd);
                FileAtoZ.WriteAllText(FileAtoZ.CombinePaths(attachPath, attachCcd.ActualFileName), FormEEC.CCD, "Uploading Attachment for Clinical Summary...");
                EmailAttach attachSs = new EmailAttach();                                                                         //Style sheet attachment.
                attachSs.DisplayedFileName = "ccd.xsl";
                attachSs.ActualFileName    = attachCcd.ActualFileName.Substring(0, attachCcd.ActualFileName.Length - 4) + ".xsl"; //Same base name as the CCD.  The base names must match or the file will not display properly in internet browsers.
                listAttachments.Add(attachSs);
                FileAtoZ.WriteAllText(FileAtoZ.CombinePaths(attachPath, attachSs.ActualFileName), FormEHR.GetEhrResource("CCD"),
                                      "Uploading Attachment for Clinical Summary...");
                //Create and save the webmail message containing the attachments.
                EmailMessage msgWebMail = new EmailMessage();
                msgWebMail.FromAddress    = prov.GetFormalName();
                msgWebMail.ToAddress      = PatCur.GetNameFL();
                msgWebMail.PatNum         = PatCur.PatNum;
                msgWebMail.SentOrReceived = EmailSentOrReceived.WebMailSent;
                msgWebMail.ProvNumWebMail = prov.ProvNum;
                msgWebMail.Subject        = "Clinical Summary";
                msgWebMail.BodyText       = "To view the clinical summary:\r\n1) Download all attachments to the same folder.  Do not rename the files.\r\n2) Open the ccd.xml file in an internet browser.";
                msgWebMail.MsgDateTime    = DateTime.Now;
                msgWebMail.PatNumSubj     = PatCur.PatNum;
                msgWebMail.Attachments    = listAttachments;
                EmailMessages.Insert(msgWebMail);
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
                return;
            }
            EhrMeasureEvent newMeasureEvent = new EhrMeasureEvent();

            newMeasureEvent.DateTEvent = DateTime.Now;
            newMeasureEvent.EventType  = EhrMeasureEventType.ClinicalSummaryProvidedToPt;
            newMeasureEvent.PatNum     = PatCur.PatNum;
            EhrMeasureEvents.Insert(newMeasureEvent);
            FillGridEHRMeasureEvents();            //This will cause the measure event to show in the grid below the popup message on the next line.  Reassures the user that the event was immediately recorded.
            MsgBox.Show(this, "Clinical Summary Sent");
        }
Пример #23
0
        ///<summary>Allow the user to pick the files to be attached. The 'pat' argument can be null. If the user cancels at any step, the return value
        ///will be an empty list.</summary>
        public static List <EmailAttach> PickAttachments(Patient pat)
        {
            List <EmailAttach> listAttaches = new List <EmailAttach>();
            OpenFileDialog     dlg          = new OpenFileDialog();

            dlg.Multiselect = true;
            bool          isLocalFileSelected = false;
            List <string> listFileNames;

            if (pat != null && PrefC.AtoZfolderUsed != DataStorageType.InDatabase)
            {
                string patFolder = ImageStore.GetPatientFolder(pat, ImageStore.GetPreferredAtoZpath());
                if (CloudStorage.IsCloudStorage)
                {
                    FormFilePicker FormFP = new FormFilePicker(patFolder);
                    if (FormFP.ShowDialog() != DialogResult.OK)
                    {
                        return(listAttaches);
                    }
                    isLocalFileSelected = FormFP.WasLocalFileSelected;
                    listFileNames       = FormFP.SelectedFiles;
                }
                else
                {
                    dlg.InitialDirectory = patFolder;
                    if (dlg.ShowDialog() != DialogResult.OK)
                    {
                        return(listAttaches);
                    }
                    isLocalFileSelected = true;
                    listFileNames       = dlg.FileNames.ToList();
                }
            }
            else              //No patient selected or images in database
                              //Use the OS default directory for this type of file viewer.
            {
                dlg.InitialDirectory = "";
                if (dlg.ShowDialog() != DialogResult.OK)
                {
                    return(listAttaches);
                }
                isLocalFileSelected = true;
                listFileNames       = dlg.FileNames.ToList();
            }
            try {
                for (int i = 0; i < listFileNames.Count; i++)
                {
                    if (CloudStorage.IsCloudStorage)
                    {
                        FileAtoZSourceDestination sourceDestination;
                        if (isLocalFileSelected)
                        {
                            sourceDestination = FileAtoZSourceDestination.LocalToAtoZ;
                        }
                        else
                        {
                            sourceDestination = FileAtoZSourceDestination.AtoZToAtoZ;
                        }
                        //Create EmailAttach using EmailAttaches.CreateAttach logic, shortened for our specific purpose.
                        EmailAttach emailAttach = new EmailAttach();
                        emailAttach.DisplayedFileName = Path.GetFileName(listFileNames[i]);
                        string attachDir = EmailAttaches.GetAttachPath();
                        string subDir    = "Out";
                        emailAttach.ActualFileName = ODFileUtils.CombinePaths(subDir,
                                                                              DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString()
                                                                              + "_" + MiscUtils.CreateRandomAlphaNumericString(4) + "_" + emailAttach.DisplayedFileName).Replace("\\", "/");
                        FileAtoZ.Copy(listFileNames[i], FileAtoZ.CombinePaths(attachDir, emailAttach.ActualFileName), sourceDestination);
                        listAttaches.Add(emailAttach);
                    }
                    else                      //Not cloud
                    {
                        listAttaches.Add(EmailAttaches.CreateAttach(Path.GetFileName(listFileNames[i]), File.ReadAllBytes(listFileNames[i])));
                    }
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
            return(listAttaches);
        }
Пример #24
0
        private void butPrint_Click(object sender, EventArgs e)
        {
            if (!TryToSaveData())
            {
                return;
            }
            SheetCur = Sheets.GetSheet(SheetCur.SheetNum);
            //whether this is a new sheet, or one pulled from the database,
            //it will have the extra parameter we are looking for.
            //A new sheet will also have a PatNum parameter which we will ignore.
            FormSheetOutputFormat FormS = new FormSheetOutputFormat();

            if (SheetCur.SheetType == SheetTypeEnum.ReferralSlip ||
                SheetCur.SheetType == SheetTypeEnum.ReferralLetter)
            {
                FormS.PaperCopies = 2;
            }
            else
            {
                FormS.PaperCopies = 1;
            }
            if (SheetCur.PatNum != 0 &&
                SheetCur.SheetType != SheetTypeEnum.DepositSlip)
            {
                Patient pat = Patients.GetPat(SheetCur.PatNum);
                if (SheetCur.SheetType == SheetTypeEnum.LabSlip)
                {
                    FormS.IsForLab = true;                  //Changes label to "E-mail to Lab:"
                }
                else if (pat.Email != "")
                {
                    FormS.EmailPatOrLabAddress = pat.Email;
                    FormS.EmailPatOrLab        = true;
                    FormS.PaperCopies--;
                }
            }
            Referral referral = null;

            if (SheetCur.SheetType == SheetTypeEnum.ReferralSlip ||
                SheetCur.SheetType == SheetTypeEnum.ReferralLetter)
            {
                FormS.Email2Visible = true;
                SheetParameter parameter = SheetParameter.GetParamByName(SheetCur.Parameters, "ReferralNum");
                if (parameter == null)              //it can be null sometimes because of old bug in db.
                {
                    FormS.Email2Visible = false;    //prevents trying to attach email to nonexistent referral.
                }
                else
                {
                    long referralNum = PIn.Long(parameter.ParamValue.ToString());
                    referral = Referrals.GetReferral(referralNum);
                    if (referral.EMail != "")
                    {
                        FormS.Email2Address = referral.EMail;
                        FormS.Email2        = true;
                        FormS.PaperCopies--;
                    }
                }
            }
            else
            {
                FormS.Email2Visible = false;
            }
            FormS.ShowDialog();
            if (FormS.DialogResult != DialogResult.OK)
            {
                return;
            }
            if (FormS.PaperCopies > 0)
            {
                SheetPrinting.Print(SheetCur, FormS.PaperCopies, RxIsControlled);
            }
            EmailMessage message;
            Random       rnd        = new Random();
            string       attachPath = FormEmailMessageEdit.GetAttachPath();
            string       fileName;
            string       filePathAndName;

            //Graphics g=this.CreateGraphics();
            if (FormS.EmailPatOrLab)
            {
                fileName        = DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString() + rnd.Next(1000).ToString() + ".pdf";
                filePathAndName = ODFileUtils.CombinePaths(attachPath, fileName);
                SheetPrinting.CreatePdf(SheetCur, filePathAndName);
                //Process.Start(filePathAndName);
                message             = new EmailMessage();
                message.PatNum      = SheetCur.PatNum;
                message.ToAddress   = FormS.EmailPatOrLabAddress;
                message.FromAddress = PrefC.GetString(PrefName.EmailSenderAddress);
                message.Subject     = SheetCur.Description.ToString();          //this could be improved
                EmailAttach attach        = new EmailAttach();
                string      shortFileName = Regex.Replace(SheetCur.Description.ToString(), @"[^\w'@-_()&]", "");
                attach.DisplayedFileName = shortFileName + ".pdf";
                attach.ActualFileName    = fileName;
                message.Attachments.Add(attach);
                FormEmailMessageEdit FormE = new FormEmailMessageEdit(message);
                FormE.IsNew = true;
                FormE.ShowDialog();
            }
            if ((SheetCur.SheetType == SheetTypeEnum.ReferralSlip ||
                 SheetCur.SheetType == SheetTypeEnum.ReferralLetter) &&
                FormS.Email2)
            {
                //email referral
                fileName        = DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString() + rnd.Next(1000).ToString() + ".pdf";
                filePathAndName = ODFileUtils.CombinePaths(attachPath, fileName);
                SheetPrinting.CreatePdf(SheetCur, filePathAndName);
                //Process.Start(filePathAndName);
                message             = new EmailMessage();
                message.PatNum      = SheetCur.PatNum;
                message.ToAddress   = FormS.Email2Address;
                message.FromAddress = PrefC.GetString(PrefName.EmailSenderAddress);
                message.Subject     = SheetCur.Description.ToString() + " to " + Referrals.GetNameFL(referral.ReferralNum);      //this could be improved
                EmailAttach attach        = new EmailAttach();
                string      shortFileName = Regex.Replace(SheetCur.Description.ToString(), @"[^\w,'@-_()&]", "");
                attach.DisplayedFileName = shortFileName + ".pdf";
                attach.ActualFileName    = fileName;
                message.Attachments.Add(attach);
                FormEmailMessageEdit FormE = new FormEmailMessageEdit(message);
                FormE.IsNew = true;
                FormE.ShowDialog();
            }
            //g.Dispose();
            DialogResult = DialogResult.OK;
        }
Пример #25
0
        private void butPrint_Click(object sender, EventArgs e)
        {
            if (!TryToSaveData())
            {
                return;
            }
            SheetCur = Sheets.GetSheet(SheetCur.SheetNum);
            //whether this is a new sheet, or one pulled from the database,
            //it will have the extra parameter we are looking for.
            //A new sheet will also have a PatNum parameter which we will ignore.
            FormSheetOutputFormat FormS = new FormSheetOutputFormat();

            if (SheetCur.SheetType == SheetTypeEnum.ReferralSlip ||
                SheetCur.SheetType == SheetTypeEnum.ReferralLetter)
            {
                FormS.PaperCopies = 2;
            }
            else
            {
                FormS.PaperCopies = 1;
            }
            if (SheetCur.PatNum != 0 &&
                SheetCur.SheetType != SheetTypeEnum.DepositSlip)
            {
                Patient pat = Patients.GetPat(SheetCur.PatNum);
                if (SheetCur.SheetType == SheetTypeEnum.LabSlip)
                {
                    FormS.IsForLab = true;                  //Changes label to "E-mail to Lab:"
                }
                else if (pat.Email != "")
                {
                    FormS.EmailPatOrLabAddress = pat.Email;
                    //No need to email to a patient for sheet types: LabelPatient (0), LabelCarrier (1), LabelReferral (2), ReferralSlip (3), LabelAppointment (4), Rx (5), Consent (6), ReferralLetter (8), ExamSheet (13), DepositSlip (14)
                    //The data is too private to email unencrypted for sheet types: PatientForm (9), RoutingSlip (10), MedicalHistory (11), LabSlip (12)
                    //A patient might want email for the following sheet types and the data is not very private: PatientLetter (7)
                    if (SheetCur.SheetType == SheetTypeEnum.PatientLetter)
                    {
                        //This just defines the default selection. The user can manually change selections in FormSheetOutputFormat.
                        FormS.EmailPatOrLab = true;
                        FormS.PaperCopies--;
                    }
                }
            }
            Referral referral = null;

            if (SheetCur.SheetType == SheetTypeEnum.ReferralSlip ||
                SheetCur.SheetType == SheetTypeEnum.ReferralLetter)
            {
                FormS.Email2Visible = true;
                SheetParameter parameter = SheetParameter.GetParamByName(SheetCur.Parameters, "ReferralNum");
                if (parameter == null)              //it can be null sometimes because of old bug in db.
                {
                    FormS.Email2Visible = false;    //prevents trying to attach email to nonexistent referral.
                }
                else
                {
                    long referralNum = PIn.Long(parameter.ParamValue.ToString());
                    referral = Referrals.GetReferral(referralNum);
                    if (referral.EMail != "")
                    {
                        FormS.Email2Address = referral.EMail;
                        FormS.Email2        = true;
                        FormS.PaperCopies--;
                    }
                }
            }
            else
            {
                FormS.Email2Visible = false;
            }
            FormS.ShowDialog();
            if (FormS.DialogResult != DialogResult.OK)
            {
                return;
            }
            if (FormS.PaperCopies > 0)
            {
                SheetPrinting.Print(SheetCur, FormS.PaperCopies, RxIsControlled);
            }
            EmailMessage message;
            Random       rnd        = new Random();
            string       attachPath = EmailMessages.GetEmailAttachPath();
            string       fileName;
            string       filePathAndName;
            EmailAddress emailAddress;
            Patient      patCur = Patients.GetPat(SheetCur.PatNum);

            if (patCur == null)
            {
                emailAddress = EmailAddresses.GetByClinic(0);
            }
            else
            {
                emailAddress = EmailAddresses.GetByClinic(patCur.ClinicNum);
            }
            //Graphics g=this.CreateGraphics();
            if (FormS.EmailPatOrLab)
            {
                fileName        = DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString() + rnd.Next(1000).ToString() + ".pdf";
                filePathAndName = ODFileUtils.CombinePaths(attachPath, fileName);
                SheetPrinting.CreatePdf(SheetCur, filePathAndName);
                //Process.Start(filePathAndName);
                message             = new EmailMessage();
                message.PatNum      = SheetCur.PatNum;
                message.ToAddress   = FormS.EmailPatOrLabAddress;
                message.FromAddress = emailAddress.SenderAddress;              //Can be blank just as it could with the old pref.
                message.Subject     = SheetCur.Description.ToString();         //this could be improved
                EmailAttach attach        = new EmailAttach();
                string      shortFileName = Regex.Replace(SheetCur.Description.ToString(), @"[^\w'@-_()&]", "");
                attach.DisplayedFileName = shortFileName + ".pdf";
                attach.ActualFileName    = fileName;
                message.Attachments.Add(attach);
                FormEmailMessageEdit FormE = new FormEmailMessageEdit(message);
                FormE.IsNew = true;
                FormE.ShowDialog();
            }
            if ((SheetCur.SheetType == SheetTypeEnum.ReferralSlip ||
                 SheetCur.SheetType == SheetTypeEnum.ReferralLetter) &&
                FormS.Email2)
            {
                //email referral
                fileName        = DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString() + rnd.Next(1000).ToString() + ".pdf";
                filePathAndName = ODFileUtils.CombinePaths(attachPath, fileName);
                SheetPrinting.CreatePdf(SheetCur, filePathAndName);
                //Process.Start(filePathAndName);
                message             = new EmailMessage();
                message.PatNum      = SheetCur.PatNum;
                message.ToAddress   = FormS.Email2Address;
                message.FromAddress = emailAddress.SenderAddress;                                         //Can be blank just as it could with the old pref.
                message.Subject     = Lan.g(this, "RE: ") + Patients.GetLim(SheetCur.PatNum).GetNameLF(); //works even if patnum invalid
                //SheetCur.Description.ToString()+" to "+Referrals.GetNameFL(referral.ReferralNum);//this could be improved
                EmailAttach attach        = new EmailAttach();
                string      shortFileName = Regex.Replace(SheetCur.Description.ToString(), @"[^\w,'@-_()&]", "");
                attach.DisplayedFileName = shortFileName + ".pdf";
                attach.ActualFileName    = fileName;
                message.Attachments.Add(attach);
                FormEmailMessageEdit FormE = new FormEmailMessageEdit(message);
                FormE.IsNew = true;
                FormE.ShowDialog();
            }
            //g.Dispose();
            DialogResult = DialogResult.OK;
        }
Пример #26
0
        private void menuItemOpen_Click(object sender, EventArgs e)
        {
            EmailAttach attach = _listEmailAttachDisplayed[gridAttachments.SelectedIndices[0]];

            FileAtoZ.OpenFile(FileAtoZ.CombinePaths(EmailAttaches.GetAttachPath(), attach.ActualFileName), attach.DisplayedFileName);
        }
Пример #27
0
 ///<summary>Updates one EmailAttach in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.</summary>
 internal static void Update(EmailAttach emailAttach,EmailAttach oldEmailAttach)
 {
     string command="";
     if(emailAttach.EmailMessageNum != oldEmailAttach.EmailMessageNum) {
         if(command!=""){ command+=",";}
         command+="EmailMessageNum = "+POut.Long(emailAttach.EmailMessageNum)+"";
     }
     if(emailAttach.DisplayedFileName != oldEmailAttach.DisplayedFileName) {
         if(command!=""){ command+=",";}
         command+="DisplayedFileName = '"+POut.String(emailAttach.DisplayedFileName)+"'";
     }
     if(emailAttach.ActualFileName != oldEmailAttach.ActualFileName) {
         if(command!=""){ command+=",";}
         command+="ActualFileName = '"+POut.String(emailAttach.ActualFileName)+"'";
     }
     if(command==""){
         return;
     }
     command="UPDATE emailattach SET "+command
         +" WHERE EmailAttachNum = "+POut.Long(emailAttach.EmailAttachNum);
     Db.NonQ(command);
 }
Пример #28
0
 ///<summary>Updates one EmailAttach in the database.</summary>
 internal static void Update(EmailAttach emailAttach)
 {
     string command="UPDATE emailattach SET "
         +"EmailMessageNum  =  "+POut.Long  (emailAttach.EmailMessageNum)+", "
         +"DisplayedFileName= '"+POut.String(emailAttach.DisplayedFileName)+"', "
         +"ActualFileName   = '"+POut.String(emailAttach.ActualFileName)+"' "
         +"WHERE EmailAttachNum = "+POut.Long(emailAttach.EmailAttachNum);
     Db.NonQ(command);
 }
Пример #29
0
 ///<summary>Inserts one EmailAttach into the database.  Returns the new priKey.</summary>
 public static long Insert(EmailAttach emailAttach)
 {
     return(Insert(emailAttach, false));
 }
Пример #30
0
        public void EmailAttaches_CreateAttach_Outbound()
        {
            EmailAttach emailAttach = EmailAttaches.CreateAttach("map_of_argentina.gif", "", Encoding.UTF8.GetBytes(_attachmentRaw), true);

            Assert.IsTrue(File.Exists(ODFileUtils.CombinePaths(EmailAttaches.GetAttachPath(), emailAttach.ActualFileName)));
        }
Пример #31
0
        public static ServiceResponse DeliverEmail(EmailDeliveryRequest edr)
        {
            ServiceResponse sr = new ServiceResponse();

            if (!EmailingEnabled)
            {
                return(sr);
            }

            sr = ValidateEmailDeliveryRequest(edr);
            if (!sr.Status)
            {
                return(sr);
            }

            Email email = new Email();

            // Body
            if (edr.EmailTemplateCode != null)
            {
                ParsedEmailTemplate pet = ParseEmailTemplate(edr.EmailTemplateCode, edr.TemplateData);
                email.Body    = pet.ParsedBody;
                email.Subject = pet.ParsedSubject;
            }
            else
            {
                email.Body    = edr.Body;
                email.Subject = edr.Subject;
            }

            // Sender
            if (String.IsNullOrEmpty(edr.Sender))
            {
                email.Sender = Config.Emailing.FromAddress;
            }
            else
            {
                email.Sender = edr.Sender;
            }

            // Recipients
            email.Recipients = edr.Recipients;

            // Queue
            email.StatusCode = EmailStatusCode.QUEUED.ToString();

            // Attachments
            if (edr.AttachmentList != null)
            {
                foreach (int dataFileId in edr.AttachmentList)
                {
                    var ea = new EmailAttach
                    {
                        Email      = email,
                        DataFileId = dataFileId
                    };

                    email.EmailAttachs.Add(ea);
                }
            }

            // Save email
            DB db = new DB();

            db.Email.Add(email);
            DB.SaveChanges(Identity.AuditLogin);

            // Send right away
            SendQueuedEmail(email, edr.Important);

            // Return data about email
            sr.ReturnValue = email.EmailId;

            return(sr);
        }