public Message deleteAttachmentFromMessage(Int32 messageId) { SecureMessageDao smDao = new SecureMessageDao(_cxn); Message dbMsg = smDao.getMessage(messageId); if (dbMsg == null || dbMsg.Id <= 0 || !dbMsg.Attachment || dbMsg.AttachmentId <= 0) { throw new MdoException("Not a valid message ID"); } try { _cxn.beginTransaction(); OracleQuery request = buildUpdateMessageQuery(dbMsg, -1); nonQuery qry = delegate() { return((Int32)request.Command.ExecuteNonQuery()); }; if ((Int32)_cxn.query(request, qry) != 1) { throw new MdoException("Failed to update secure message record for attachment"); } deleteAttachment(Convert.ToInt32(dbMsg.AttachmentId)); dbMsg.AttachmentId = 0; dbMsg.Attachment = false; dbMsg.Oplock++; _cxn.commitTransaction(); return(dbMsg); } catch (Exception) { _cxn.rollbackTransaction(); throw; } }
public MessageTO sendDraft(string pwd, Int32 messageId, Int32 messageOplock) { MessageTO result = new MessageTO(); if (String.IsNullOrEmpty(pwd)) { result.fault = new FaultTO("Missing pwd"); } else if (messageId <= 0) { result.fault = new FaultTO("Must supply a valid message ID"); } try { using (MdoOracleConnection cxn = new MdoOracleConnection(new mdo.DataSource() { ConnectionString = pwd })) { SecureMessageDao dao = new SecureMessageDao(cxn); gov.va.medora.mdo.domain.sm.Message msg = new Message() { Id = messageId, Oplock = messageOplock }; result = new MessageTO(dao.sendDraft(msg)); } } catch (Exception exc) { result.fault = new FaultTO(exc); } return(result); }
/// <remarks> /// This function retrieves the message ID from the row that is updated. It does this so as not to put the burden /// on the consuming client application to pass the message ID value. This should make it less confusing which identifier /// is which and therefore the service easier to consume /// </remarks> /// <summary> /// Mark a message as read in the Addressee table. Set the ReadDate property to current timestamp toggle the date on. Or, /// set the ReadDate property to a new DateTime() - year of 1 - to toggle the read date off /// </summary> /// <param name="addressee"></param> /// <returns></returns> public Addressee readMessage(Addressee addressee) { _cxn.beginTransaction(); try { OracleQuery query = buildReadMessageRequest(addressee); nonQuery insertQuery = delegate() { return(query.Command.ExecuteNonQuery()); }; if ((Int32)_cxn.query(query, insertQuery) != 1) { throw new mdo.exceptions.MdoException("Unable to mark message as read"); } Int32 msgId = ((Oracle.DataAccess.Types.OracleDecimal)query.Command.Parameters["outId"].Value).ToInt32(); addressee.Oplock++; SecureMessageDao msgDao = new SecureMessageDao(_cxn); addressee.Message = msgDao.getSecureMessageBody(msgId); _cxn.commitTransaction(); // TBD - any business rules around SECURE_MESSAGE.READ_RECEIPT and marking a message as read? return(addressee); } catch (Exception) { _cxn.rollbackTransaction(); throw; } }
public void testBuildGetMessagesFromThreadSqlStatement() { SecureMessageDao dao = new SecureMessageDao(_cxn); OracleQuery query = dao.buildGetMessagesFromThreadQuery(1); Assert.IsTrue(String.Equals(query.Command.CommandText, "SELECT SM.SECURE_MESSAGE_ID, SM.CLINICIAN_STATUS, SM.COMPLETED_DATE, SM.ASSIGNED_TO, SM.OPLOCK AS SMOPLOCK, SM.SENT_DATE, SM.SENDER_ID, SM.RECIPIENT_ID, MT.SUBJECT, MT.TRIAGE_GROUP_ID, MT.OPLOCK AS MTOPLOCK, MT.CATEGORY_TYPE FROM SMS.SECURE_MESSAGE SM JOIN SMS.MESSAGE_THREAD MT ON SM.THREAD_ID=MT.THREAD_ID WHERE SM.THREAD_ID=:threadId AND SM.ACTIVE=1")); }
public MessageTO sendReplyMessage(string pwd, Int32 replyingToMessageId, Int32 senderId, Int32 recipientId, string messageBody) { MessageTO result = new MessageTO(); if (replyingToMessageId <= 0) { result.fault = new FaultTO("Missing reply message ID"); } else if (senderId <= 0) { result.fault = new FaultTO("Missing sender ID"); } //else if (recipientId <= 0) //{ // result.fault = new FaultTO("Missing recipient ID"); //} else if (String.IsNullOrEmpty(messageBody)) { result.fault = new FaultTO("Must supply a message body"); } if (result.fault != null) { return(result); } try { using (MdoOracleConnection cxn = new MdoOracleConnection(new mdo.DataSource() { ConnectionString = pwd })) { SecureMessageDao dao = new SecureMessageDao(cxn); Message replyingTo = dao.getMessage(replyingToMessageId); if (replyingTo == null || replyingTo.Id <= 0) { throw new Exception("No message found for that ID"); } Message newReply = new Message() { SentDate = DateTime.Now, SenderId = senderId, RecipientId = recipientId, Body = messageBody, Checksum = StringUtils.getMD5Hash(messageBody), MessageThread = replyingTo.MessageThread }; result = new MessageTO(dao.sendReply(replyingTo, newReply)); } } catch (Exception exc) { result.fault = new FaultTO(exc); } return(result); }
public void testBuildGetSecureMessageQuerySqlStatement() { SecureMessageDao dao = new SecureMessageDao(_cxn); OracleQuery query = dao.buildGetSecureMessageBodyQuery(1); Assert.IsTrue(String.Equals(query.Command.CommandText, "SELECT SM.CHECKSUM, SM.BODY FROM SMS.SECURE_MESSAGE SM WHERE SM.SECURE_MESSAGE_ID = :secureMessageId AND SM.ACTIVE = 1")); }
public void testBuildMessagesSqlStatement() { SecureMessageDao dao = new SecureMessageDao(_cxn); OracleQuery query = dao.buildGetSecureMessagesQuery(1, 0, 0); Assert.IsTrue(String.Equals(query.Command.CommandText, "SELECT ADDR.ADDRESSEE_ID, ADDR.ADDRESSEE_ROLE, ADDR.OPLOCK AS ADDROPLOCK, ADDR.ACTIVE AS ADDRACTIVE, ADDR.USER_ID, ADDR.CREATED_DATE AS ADDRCREATEDDATE, ADDR.MODIFIED_DATE AS ADDRMODIFIEDDATE, ADDR.FOLDER_ID, ADDR.READ_DATE, ADDR.REMINDER_DATE, FOLD.FOLDER_NAME, FOLD.ACTIVE AS FOLDACTIVE, FOLD.OPLOCK AS FOLDOPLOCK, SM.SECURE_MESSAGE_ID, SM.CLINICIAN_STATUS, SM.COMPLETED_DATE, SM.ASSIGNED_TO, SM.CHECKSUM, SM.THREAD_ID, SM.STATUS_SET_BY, SM.OPLOCK AS SMOPLOCK, SM.ACTIVE, SM.CREATED_DATE, SM.MODIFIED_DATE, SM.ESCALATED, SM.SENT_DATE, SM.SENDER_TYPE, SM.SENDER_ID, SM.SENDER_NAME, SM.RECIPIENT_TYPE, SM.RECIPIENT_ID, SM.RECIPIENT_NAME, SM.ESCALATION_NOTIFICATION_DATE, SM.ESCALATION_NOTIFICATION_TRIES, SM.READ_RECEIPT, SM.HAS_ATTACHMENT, SM.ATTACHMENT_ID, MT.SUBJECT, MT.TRIAGE_GROUP_ID, MT.CATEGORY_TYPE, MT.OPLOCK AS MTOPLOCK FROM SMS.ADDRESSEE ADDR JOIN SMS.SECURE_MESSAGE SM ON ADDR.SECURE_MESSAGE_ID=SM.SECURE_MESSAGE_ID JOIN SMS.MESSAGE_THREAD MT ON SM.THREAD_ID=MT.THREAD_ID LEFT JOIN SMS.FOLDER FOLD ON ADDR.FOLDER_ID=FOLD.FOLDER_ID WHERE ADDR.USER_ID = :userId AND ADDR.ACTIVE = 1 AND ROWNUM >= :pageStart AND ROWNUM <= :pageSize ORDER BY SM.SENT_DATE DESC")); }
public void testBuildCreateThreadQuerySqlStatement() { SecureMessageDao dao = new SecureMessageDao(_cxn); domain.sm.Thread thread = new domain.sm.Thread(); thread.MailGroup = new domain.sm.TriageGroup(); OracleQuery query = dao.buildCreateThreadQuery(thread); Assert.IsTrue(String.Equals(query.Command.CommandText, "INSERT INTO SMS.MESSAGE_THREAD (SUBJECT, TRIAGE_GROUP_ID, CREATED_DATE, MODIFIED_DATE, CATEGORY_TYPE) VALUES (:subject, :triageGroupId, :createdDate, :modifiedDate, :categoryType) RETURNING THREAD_ID INTO :outId")); }
public void testUpdateMessageSqlStatement() { SecureMessageDao dao = new SecureMessageDao(_cxn); domain.sm.Message message = new domain.sm.Message(); message.MessageThread = new domain.sm.Thread() { Id = 1, Subject = "Test" }; // this must be set otherwise function will try to create it inline OracleQuery query = dao.buildUpdateMessageQuery(message); Assert.IsTrue(String.Equals(query.Command.CommandText, "UPDATE SMS.SECURE_MESSAGE SET OPLOCK = :oplockPlusOne, CLINICIAN_STATUS = :clinicianStatus, COMPLETED_DATE = :completedDate, ASSIGNED_TO = :assignedTo, CHECKSUM = :checksum, THREAD_ID = :threadId, STATUS_SET_BY = :statusSetBy, MODIFIED_DATE = :modifiedDate, ESCALATED = :escalated, BODY = :body, SENT_DATE = :sentDate, SENDER_TYPE = :senderType, SENDER_ID = :senderId, SENDER_NAME = :senderName, RECIPIENT_TYPE = :recipientType, RECIPIENT_ID = :recipientId, RECIPIENT_NAME = :recipientName, SENT_DATE_LOCAL = :sentDateLocal, ESCALATION_NOTIFICATION_DATE = :escalationNotificationDate, ESCALATION_NOTIFICATION_TRIES = :escalationNotificationTries, READ_RECEIPT = :readReceipt, HAS_ATTACHMENT = :hasAttachment, ATTACHMENT_ID = :attachmentId WHERE SECURE_MESSAGE_ID = :secureMessageId AND OPLOCK = :oplock")); }
public void testSendMessageSqlStatement() { SecureMessageDao dao = new SecureMessageDao(_cxn); domain.sm.Message message = new domain.sm.Message(); message.MessageThread = new domain.sm.Thread() { Id = 1, Subject = "Test" }; // this must be set otherwise function will try to create it inline OracleQuery query = dao.buildSendMessageCommand(message); Assert.IsTrue(String.Equals(query.Command.CommandText, "INSERT INTO SMS.SECURE_MESSAGE (CLINICIAN_STATUS, COMPLETED_DATE, ASSIGNED_TO, CHECKSUM, THREAD_ID, STATUS_SET_BY, MODIFIED_DATE, ESCALATED, BODY, SENT_DATE, SENDER_TYPE, SENDER_ID, SENDER_NAME, RECIPIENT_TYPE, RECIPIENT_ID, RECIPIENT_NAME, SENT_DATE_LOCAL, ESCALATION_NOTIFICATION_DATE, ESCALATION_NOTIFICATION_TRIES, READ_RECEIPT, HAS_ATTACHMENT, ATTACHMENT_ID) VALUES (:clinicianStatus, :completedDate, :assignedTo, :checksum, :threadId, :statusSetBy, :modifiedDate, :escalated, :body, :sentDate, :senderType, :senderId, :senderName, :recipientType, :recipientId, :recipientName, :sentDateLocal, :escalationNotificationDate, :escalationNotificationTries, :readReceipt, :hasAttachment, :attachmentId) RETURNING SECURE_MESSAGE_ID INTO :outId")); }
public SecureMessageThreadsTO getMessages(string pwd, Int32 userId, Int32 folderId, Int32 pageStart, Int32 pageSize) { SecureMessageThreadsTO result = new SecureMessageThreadsTO(null); pwd = getConnectionString(pwd); if (String.IsNullOrEmpty(pwd)) { result.fault = new FaultTO("No connection string specified or configured"); } else if (userId <= 0) { result.fault = new dto.FaultTO("Must supply a user ID"); } else if (pageSize <= 0 || pageSize > 250) { result.fault = new FaultTO("Invalid pageSize argument"); } if (result.fault != null) { return(result); } try { using (MdoOracleConnection cxn = new MdoOracleConnection(new mdo.DataSource() { ConnectionString = pwd })) { SecureMessageDao dao = new SecureMessageDao(cxn); if (folderId > 0 || Enum.IsDefined(typeof(gov.va.medora.mdo.domain.sm.enums.SystemFolderEnum), folderId)) { return(new SecureMessageThreadsTO(dao.getMessagesInFolder(userId, folderId, pageStart, pageSize))); } else { return(new SecureMessageThreadsTO(dao.getSecureMessages(userId, pageStart, pageSize))); } } } catch (Exception exc) { result.fault = new dto.FaultTO(exc); } return(result); }
public MessageTO deleteDraft(string pwd, Int32 messageId) { MessageTO result = new MessageTO(); pwd = getConnectionString(pwd); if (String.IsNullOrEmpty(pwd)) { result.fault = new FaultTO("No connection string specified or configured"); } else if (messageId <= 0) { result.fault = new FaultTO("Missing message ID"); } if (result.fault != null) { return(result); } try { Message message = new Message() { Id = messageId }; using (MdoOracleConnection cxn = new MdoOracleConnection(new mdo.DataSource() { ConnectionString = pwd })) { SecureMessageDao dao = new SecureMessageDao(cxn); dao.deleteDraft(message); } message.Addressees = null; message.MessageThread = null; message.Body = "OK"; message.Id = -1; result = new MessageTO(message); } catch (Exception exc) { result.fault = new FaultTO(exc); } return(result); }
/// <remarks> /// This function retrieves the message ID from the row that is updated. It does this so as not to put the burden /// on the consuming client application to pass the message ID value. This should make it less confusing which identifier /// is which and therefore the service easier to consume /// </remarks> /// <summary> /// Mark a message as read in the Addressee table. Set the ReadDate property to current timestamp toggle the date on. Or, /// set the ReadDate property to a new DateTime() - year of 1 - to toggle the read date off /// </summary> /// <param name="addressee"></param> /// <returns></returns> public Addressee readMessage(Addressee addressee) { _cxn.beginTransaction(); try { Addressee original = getAddressee(addressee.Id); OracleQuery query = buildReadMessageRequest(addressee); nonQuery insertQuery = delegate() { return(query.Command.ExecuteNonQuery()); }; if ((Int32)_cxn.query(query, insertQuery) != 1) { throw new mdo.exceptions.MdoException("Unable to mark message as read"); } Int32 msgId = ((Oracle.DataAccess.Types.OracleDecimal)query.Command.Parameters["outId"].Value).ToInt32(); addressee.Oplock++; new MessageActivityDao(_cxn).createMessageActivity( new MessageActivity() { Action = domain.sm.enums.ActivityEnum.MDWS_MESSAGE_READ, Detail = "MOBILE_APPS_ENTRY^MessageRead", MessageId = msgId, PerformerType = domain.sm.enums.UserTypeEnum.PATIENT, UserId = original.Owner.Id }); SecureMessageDao msgDao = new SecureMessageDao(_cxn); addressee.Message = msgDao.getSecureMessageBody(msgId); _cxn.commitTransaction(); // TBD - any business rules around SECURE_MESSAGE.READ_RECEIPT and marking a message as read? return(addressee); } catch (Exception) { _cxn.rollbackTransaction(); throw; } }
public ThreadTO updateMessageThread(string pwd, Int32 threadId, string threadSubject, Int32 messageCategory, Int32 threadOplock) { ThreadTO result = new ThreadTO(); if (threadId <= 0) { result.fault = new FaultTO("Must specify a message thread"); } else if (String.IsNullOrEmpty(threadSubject)) { result.fault = new FaultTO("Missing thread subject"); } else if (messageCategory > 0 && !Enum.IsDefined(typeof(gov.va.medora.mdo.domain.sm.enums.MessageCategoryTypeEnum), messageCategory)) { result.fault = new FaultTO("That message category is not defined"); } if (result.fault != null) { return(result); } try { gov.va.medora.mdo.domain.sm.Thread thread = new gov.va.medora.mdo.domain.sm.Thread() { Id = threadId, Subject = threadSubject, MessageCategoryType = (gov.va.medora.mdo.domain.sm.enums.MessageCategoryTypeEnum)messageCategory, Oplock = threadOplock }; using (MdoOracleConnection cxn = new MdoOracleConnection(new mdo.DataSource() { ConnectionString = pwd })) { SecureMessageDao dao = new SecureMessageDao(cxn); gov.va.medora.mdo.domain.sm.Thread dbThread = dao.getMessagesFromThread(threadId); // we don't want to permit apps to change the mail group this way so just keep what's in the database which gets set through the proper channels thread.MailGroup = dbThread.MailGroup; if (dbThread == null || dbThread.Id <= 0 || dbThread.Messages == null || dbThread.Messages.Count <= 0) { throw new Exception("That thread does not exist in the database or appears malformed"); } // make sure the thread hasn't been marked as completed foreach (Message m in dbThread.Messages) { if (m.CompletedDate.Year > 1900) { throw new Exception("That message thread has already been completed. Unable to edit."); } } result = new ThreadTO(dao.updateThread(thread)); } } catch (Exception exc) { result.fault = new FaultTO(exc); } return(result); }
public ThreadTO sendNewMessage(string pwd, string threadSubject, Int32 groupId, Int32 messageCategory, Int32 senderId, Int32 recipientId, string messageBody) { ThreadTO result = new ThreadTO(); if (String.IsNullOrEmpty(threadSubject)) { result.fault = new FaultTO("Missing thread subject"); } else if (messageCategory >= 0 && !Enum.IsDefined(typeof(gov.va.medora.mdo.domain.sm.enums.MessageCategoryTypeEnum), messageCategory)) { result.fault = new FaultTO("That message category is not defined"); } else if (senderId <= 0) { result.fault = new FaultTO("Missing sender ID"); } else if (recipientId <= 0) { result.fault = new FaultTO("Missing recipient ID"); } else if (String.IsNullOrEmpty(messageBody)) { result.fault = new FaultTO("Must supply a message body"); } if (result.fault != null) { return(result); } try { gov.va.medora.mdo.domain.sm.Thread thread = new Thread() { MailGroup = new TriageGroup() { Id = groupId }, MessageCategoryType = (mdo.domain.sm.enums.MessageCategoryTypeEnum)messageCategory, Subject = threadSubject }; gov.va.medora.mdo.domain.sm.Message message = new Message() { Body = messageBody, Checksum = StringUtils.getMD5Hash(messageBody), MessageThread = thread, RecipientId = recipientId, SenderId = senderId, SentDate = DateTime.Now }; using (MdoOracleConnection cxn = new MdoOracleConnection(new mdo.DataSource() { ConnectionString = pwd })) { SecureMessageDao dao = new SecureMessageDao(cxn); Message newMsg = dao.sendNewMessage(message); result = new ThreadTO(newMsg.MessageThread); result.messages = new MessageTO[] { new MessageTO(newMsg) }; } } catch (Exception exc) { result.fault = new FaultTO(exc); } return(result); }
public ThreadTO saveDraft(string pwd, Int32 replyingToMessageId, string threadSubject, Int32 messageCategory, Int32 messageId, Int32 senderId, Int32 recipientId, string messageBody, Int32 messageOplock, Int32 threadOplock) { ThreadTO result = new ThreadTO(); if (String.IsNullOrEmpty(pwd)) { result.fault = new FaultTO("Missing pwd"); } else if (messageCategory > 0 && !Enum.IsDefined(typeof(gov.va.medora.mdo.domain.sm.enums.MessageCategoryTypeEnum), messageCategory)) { result.fault = new FaultTO("Invalid message category"); } else if (String.IsNullOrEmpty(messageBody)) { result.fault = new FaultTO("Missing message body"); } else if (messageId > 0 && messageOplock < 0) { result.fault = new FaultTO("Invalid message ID/message oplock"); } else if (senderId <= 0 || recipientId <= 0) { result.fault = new FaultTO("Invalid sender/recipient"); } if (result.fault != null) { return(result); } try { Message message = new Message() { Body = messageBody, Checksum = StringUtils.getMD5Hash(messageBody), Id = messageId, MessageThread = new Thread(), RecipientId = recipientId, SenderId = senderId, Oplock = messageOplock }; message.MessageThread.Subject = threadSubject; if (Enum.IsDefined(typeof(mdo.domain.sm.enums.MessageCategoryTypeEnum), messageCategory)) { message.MessageThread.MessageCategoryType = (mdo.domain.sm.enums.MessageCategoryTypeEnum)messageCategory; } message.MessageThread.Oplock = threadOplock; using (MdoOracleConnection cxn = new MdoOracleConnection(new mdo.DataSource() { ConnectionString = pwd })) { SecureMessageDao dao = new SecureMessageDao(cxn); if (replyingToMessageId > 0) { Message replyingToMsg = dao.getMessage(replyingToMessageId); if (replyingToMsg == null || replyingToMsg.Id <= 0 || replyingToMsg.MessageThread == null || replyingToMsg.MessageThread.Id <= 0) { throw new Exception("Invalid reply to message ID"); } message.MessageThread.Id = replyingToMsg.MessageThread.Id; } gov.va.medora.mdo.domain.sm.Message savedDraft = dao.saveDraft(message); MessageTO msg = new MessageTO(savedDraft); result = new ThreadTO(savedDraft.MessageThread); result.messages = new MessageTO[] { msg }; } } catch (Exception exc) { result.fault = new FaultTO(exc); } return(result); }