private Message Map(Domain.Models.Message s) => new Message
 {
     Content    = s.Content,
     AuthorId   = s.AuthorId.ToString(),
     AuthorName = s.AuthorName,
     Time       = Timestamp.FromDateTime(s.Time),
 };
Beispiel #2
0
        public static Data.Models.Message Map(this Domain.Models.Message message)
        {
            return(new Data.Models.Message()
            {
                ID = message.ID,
                ParentID = message.ParentID,
                CorrelationID = message.CorrelationID,

                Content = message.Content,
                FormattedContent = message.FormattedContent,
                CommentID = message.CommentID,
                CreatedBy = message.CreatedBy,
                CreationDate = message.CreationDate,
                //Direction = (int)message.Direction,
                IsAnonymized = message.IsAnonymized,
                ReadDate = message.ReadDate,
                Recipient = message.Recipient,
                RecipientType = (int)message.RecipientType,
                Sender = message.Sender,
                SenderType = (int)message.SenderType,
                Title = message.Title,
                SubmissionID = message.SubmissionID,
                Subverse = message.Subverse,
                Type = (int)message.Type
            });
        }
Beispiel #3
0
        internal static async Task SendUserMentionNotification(Comment comment, IEnumerable <string> users)
        {
            if (comment != null)
            {
                foreach (var user in users)
                {
                    if (UserHelper.UserExists(user))
                    {
                        try
                        {
                            string recipient = UserHelper.OriginalUsername(user);

                            //BlockedUser Implementation - Comment User Mention
                            if (!MesssagingUtility.IsSenderBlocked(comment.UserName, recipient))
                            {
                                if (await UserAllowsAnonMentions(user, comment.IsAnonymized))
                                {
                                    //var submission = DataCache.Submission.Retrieve(comment.SubmissionID);

                                    var q          = new QuerySubmission(comment.SubmissionID.Value);
                                    var submission = await q.ExecuteAsync().ConfigureAwait(CONSTANTS.AWAIT_CAPTURE_CONTEXT);

                                    //var subverse = DataCache.Subverse.Retrieve(submission.Subverse);

                                    var message = new Domain.Models.Message();

                                    message.IsAnonymized  = comment.IsAnonymized;
                                    message.Recipient     = recipient;
                                    message.RecipientType = Domain.Models.IdentityType.User;
                                    message.Sender        = comment.UserName;
                                    message.SenderType    = Domain.Models.IdentityType.User;
                                    message.Subverse      = submission.Subverse;
                                    message.SubmissionID  = comment.SubmissionID;
                                    message.CommentID     = comment.ID;
                                    message.Type          = Domain.Models.MessageType.CommentMention;
                                    message.CreationDate  = Repository.CurrentDate;

                                    using (var repo = new Repository())
                                    {
                                        var response = await repo.SendMessage(message);

                                        if (response.Success)
                                        {
                                            EventNotification.Instance.SendMentionNotice(recipient, comment.UserName, Domain.Models.ContentType.Comment, comment.ID, comment.Content);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// 同步透析下机
        /// </summary>
        /// <param name="sync"></param>
        /// <returns></returns>
        public async Task <OutputBase> AddDialysisOff(AddDialysisOffSync sync)
        {
            var dialysis = await _repository.Get(sync.DialysisRecordId, sync.HospitalId);

            if (dialysis == null)
            {
                return(OutputBase.Fail("不存在透析上机记录"));
            }

            dialysis.ConfirmedUFV         = sync.ConfirmedUFV;
            dialysis.StartTime            = sync.StartTime;
            dialysis.OffSystolicPressure  = sync.OffSystolicPressure;
            dialysis.OffDiastolicPressure = sync.OffDiastolicPressure;
            dialysis.OffPulseRate         = sync.OffPulseRate;
            dialysis.OffBreath            = sync.OffBreath;
            dialysis.PostWeight           = sync.PostWeight;
            dialysis.ActualUFV            = sync.ActualUFV;
            dialysis.EndTime  = sync.EndTime;
            dialysis.OffNurse = sync.OffNurse;
            dialysis.Summary  = sync.Summary;

            #region 添加下机Message
            var endTime = sync.EndTime.GetValueOrDefault();
            var content = string.Format("下机时间: {0}", endTime.ToString(CommConstant.TimeFormatString));
            var message = new Domain.Models.Message
            {
                AppType   = (int)AppTypeEnum.Patient,
                Content   = content,
                IsRead    = false,
                ReceiveId = dialysis.PatientId,
                SendId    = 0,
                SendName  = "系统",
                Title     = "透析前下机测量",
                Type      = (int)MessageTypeEnum.透析下机,
                OuterId   = dialysis.Id.ToString()
            };
            _messageRepository.Add(message);
            #endregion

            if (!_unitWork.Commit())
            {
                OutputBase.Fail("保存失败");
            }

            #region 向患者端异步发送下机JPush
            ThreadPool.QueueUserWorkItem(delegate
            {
                new JPushMessage(AppTypeEnum.Patient, (int)JPushKeyEnum.DialysisOff, dialysis.PatientId.ToString(), content, dialysis.Id.ToString(), _optionsAccessor.IsDevModel).SendPush();
                new JPushNotification(AppTypeEnum.Patient, (int)JPushKeyEnum.DialysisOff, dialysis.PatientId.ToString(), content, dialysis.Id.ToString(), _optionsAccessor.IsDevModel).SendPush();
            });
            #endregion

            return(OutputBase.Success("保存成功"));
        }
Beispiel #5
0
        internal static async Task SendSubmissionReplyNotification(IPrincipal user, Data.Models.Submission submission, Data.Models.Comment comment)
        {
            try
            {
                // comment reply is sent to a root comment which has no parent id, trigger post reply notification
                //var submission = DataCache.Submission.Retrieve(comment.SubmissionID);
                //var q = new QuerySubmission(comment.SubmissionID.Value);
                //var submission = await q.ExecuteAsync().ConfigureAwait(CONSTANTS.AWAIT_CAPTURE_CONTEXT);

                if (submission != null)
                {
                    // check if recipient exists
                    if (UserHelper.UserExists(submission.UserName))
                    {
                        // do not send notification if author is the same as comment author
                        if (submission.UserName != comment.UserName)
                        {
                            //BlockedUser Implementation - Submission Reply
                            if (!MesssagingUtility.IsSenderBlocked(comment.UserName, submission.UserName))
                            {
                                var message = new Domain.Models.Message();

                                message.IsAnonymized  = submission.IsAnonymized;
                                message.Recipient     = submission.UserName;
                                message.RecipientType = Domain.Models.IdentityType.User;
                                message.Sender        = comment.UserName;
                                message.SenderType    = Domain.Models.IdentityType.User;
                                message.Subverse      = submission.Subverse;
                                message.SubmissionID  = submission.ID;
                                message.CommentID     = comment.ID;
                                message.Type          = Domain.Models.MessageType.SubmissionReply;
                                message.CreationDate  = Repository.CurrentDate;

                                using (var repo = new Repository(user))
                                {
                                    var response = await repo.SendMessage(message);

                                    if (response.Success)
                                    {
                                        EventNotification.Instance.SendMessageNotice(message.Recipient, message.Sender, Domain.Models.MessageTypeFlag.CommentReply, Domain.Models.ContentType.Comment, comment.ID);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #6
0
        internal static async Task SendUserMentionNotification(Submission submission, IEnumerable <string> users)
        {
            if (submission != null)
            {
                foreach (var user in users)
                {
                    if (UserHelper.UserExists(user))
                    {
                        try
                        {
                            string recipient = UserHelper.OriginalUsername(user);

                            //BlockedUser Implementation - Submission User Mention
                            if (!MesssagingUtility.IsSenderBlocked(submission.UserName, recipient))
                            {
                                if (await UserAllowsAnonMentions(user, submission.IsAnonymized))
                                {
                                    //var subverse = DataCache.Subverse.Retrieve(submission.Subverse);
                                    var message = new Domain.Models.Message();

                                    message.IsAnonymized  = submission.IsAnonymized;
                                    message.Recipient     = recipient;
                                    message.RecipientType = Domain.Models.IdentityType.User;
                                    message.Sender        = submission.UserName;
                                    message.SenderType    = Domain.Models.IdentityType.User;
                                    message.Subverse      = submission.Subverse;
                                    message.SubmissionID  = submission.ID;
                                    message.Type          = Domain.Models.MessageType.SubmissionMention;
                                    message.CreationDate  = Repository.CurrentDate;

                                    using (var repo = new Repository())
                                    {
                                        var response = await repo.SendMessage(message);

                                        if (response.Success)
                                        {
                                            EventNotification.Instance.SendMentionNotice(recipient, submission.UserName, Domain.Models.ContentType.Submission, submission.ID, submission.Content);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                }
            }
        }
Beispiel #7
0
        public static async Task SendUserMentionNotification(string user, Comment comment)
        {
            if (comment != null)
            {
                if (!UserHelper.UserExists(user))
                {
                    return;
                }
                try
                {
                    string recipient = UserHelper.OriginalUsername(user);

                    //BlockedUser Implementation - Comment User Mention
                    if (!MesssagingUtility.IsSenderBlocked(comment.UserName, recipient))
                    {
                        var submission = DataCache.Submission.Retrieve(comment.SubmissionID);
                        var subverse   = DataCache.Subverse.Retrieve(submission.Subverse);

                        var message = new Domain.Models.Message();

                        message.IsAnonymized  = comment.IsAnonymized;
                        message.Recipient     = recipient;
                        message.RecipientType = Domain.Models.IdentityType.User;
                        message.Sender        = comment.UserName;
                        message.SenderType    = Domain.Models.IdentityType.User;
                        message.Subverse      = subverse.Name;
                        message.SubmissionID  = submission.ID;
                        message.CommentID     = comment.ID;
                        message.Type          = Domain.Models.MessageType.CommentMention;
                        message.CreationDate  = Repository.CurrentDate;

                        using (var repo = new Repository())
                        {
                            var response = await repo.SendMessage(message);

                            if (response.Success)
                            {
                                EventNotification.Instance.SendMentionNotice(recipient, comment.UserName, Domain.Models.ContentType.Comment, comment.ID, comment.Content);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Beispiel #8
0
        public static Domain.Models.Message Map(this Data.Models.Message message, bool protect = true)
        {
            var m = new Domain.Models.Message();

            m.ID            = message.ID;
            m.ParentID      = message.ParentID;
            m.CorrelationID = message.CorrelationID;

            m.Content          = message.Content;
            m.FormattedContent = message.FormattedContent;
            //existing messages do not have formatted content saved - check here
            if (String.IsNullOrEmpty(m.FormattedContent))
            {
                Debug.WriteLine("Formatting PM Content!");
                m.FormattedContent = Formatting.FormatMessage(m.Content);
            }

            m.CommentID    = message.CommentID;
            m.CreatedBy    = message.CreatedBy;
            m.CreationDate = message.CreationDate;
            m.IsAnonymized = message.IsAnonymized;

            m.ReadDate = message.ReadDate;

            if (message.IsAnonymized && protect)
            {
                m.Sender = message.ID.ToString();
            }
            else
            {
                m.Sender = message.Sender;
            }

            m.Recipient     = message.Recipient;
            m.RecipientType = (IdentityType)message.RecipientType;
            m.SenderType    = (IdentityType)message.SenderType;

            m.Title        = message.Title;
            m.SubmissionID = message.SubmissionID;
            m.Subverse     = message.Subverse;
            m.Type         = (MessageType)message.Type;

            return(m);
        }
Beispiel #9
0
 public async Task AddMessageAsync(Domain.Models.Message message)
 {
     await _ticketRepository.AddMessageAsync(message);
 }
Beispiel #10
0
        public static async Task SendCommentReplyNotification(Comment comment)
        {
            try
            {
                using (var _db = new voatEntities())
                {
                    Random _rnd = new Random();

                    if (comment.ParentID != null && comment.Content != null)
                    {
                        // find the parent comment and its author
                        var parentComment = _db.Comments.Find(comment.ParentID);
                        if (parentComment != null)
                        {
                            // check if recipient exists
                            if (UserHelper.UserExists(parentComment.UserName))
                            {
                                // do not send notification if author is the same as comment author
                                if (parentComment.UserName != comment.UserName)
                                {
                                    // send the message
                                    //BlockedUser Implementation - Comment Reply
                                    if (!MesssagingUtility.IsSenderBlocked(comment.UserName, parentComment.UserName))
                                    {
                                        var submission = DataCache.Submission.Retrieve(comment.SubmissionID);
                                        if (submission != null)
                                        {
                                            var subverse = DataCache.Subverse.Retrieve(submission.Subverse);

                                            var message = new Domain.Models.Message();

                                            message.IsAnonymized  = submission.IsAnonymized;
                                            message.Recipient     = parentComment.UserName;
                                            message.RecipientType = Domain.Models.IdentityType.User;
                                            message.Sender        = comment.UserName;
                                            message.SenderType    = Domain.Models.IdentityType.User;
                                            message.Subverse      = subverse.Name;
                                            message.SubmissionID  = submission.ID;
                                            message.CommentID     = comment.ID;
                                            message.Type          = Domain.Models.MessageType.CommentReply;
                                            message.CreationDate  = Repository.CurrentDate;

                                            using (var repo = new Repository())
                                            {
                                                var response = await repo.SendMessage(message);

                                                if (response.Success)
                                                {
                                                    EventNotification.Instance.SendMessageNotice(message.Recipient, message.Sender, Domain.Models.MessageTypeFlag.CommentReply, Domain.Models.ContentType.Comment, comment.ID);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #11
0
        /// <summary>
        /// 同步透析上机(新增或修改)
        /// </summary>
        /// <param name="sync"></param>
        /// <returns></returns>
        public async Task <OutputBase> AddDialysisOn(AddDialysisOnSync sync)
        {
            var patient = await _patientRepository.Get(sync.DialysisPatientId, sync.HospitalId);

            if (patient == null)
            {
                return(OutputBase.Fail("患者不存在"));
            }

            var shift = await _shiftRepository.Get(sync.DialysisShiftId, sync.HospitalId);

            if (shift == null)
            {
                return(OutputBase.Fail("排班信息不存在"));
            }

            var dialysis = await _repository.Get(sync.DialysisRecordId, sync.HospitalId);

            if (dialysis == null)
            {
                dialysis           = Mapper.Map <AddDialysisOnSync, Domain.Models.Dialysis>(sync);
                dialysis.PatientId = patient.Id;
                dialysis.ShiftId   = shift.Id;
                _repository.Add(dialysis);
            }
            else
            {
                dialysis.BedNo               = sync.BedNo;
                dialysis.ConfirmedUFV        = sync.ConfirmedUFV;
                dialysis.DialysisDate        = sync.DialysisDate;
                dialysis.DialysisDuration    = sync.DialysisDuration;
                dialysis.PatientId           = patient.Id;
                dialysis.ShiftId             = shift.Id;
                dialysis.DialysisWay         = sync.DialysisWay;
                dialysis.Doctor              = sync.Doctor;
                dialysis.DryWeight           = sync.DryWeight;
                dialysis.OnBreath            = sync.OnBreath;
                dialysis.OnDiastolicPressure = sync.OnDiastolicPressure;
                dialysis.OnNurse             = sync.OnNurse;
                dialysis.OnPulseRate         = sync.OnPulseRate;
                dialysis.OnSystolicPressure  = sync.OnSystolicPressure;
                dialysis.PatientName         = sync.PatientName;
                dialysis.PlannedUFV          = sync.PlannedUFV;
                dialysis.PreWeight           = sync.PreWeight;
                dialysis.StartTime           = sync.StartTime;
                dialysis.TreatmentComment    = sync.TreatmentComment;
            }

            #region 添加上机Message
            var startTime = sync.StartTime.GetValueOrDefault();
            var content   = string.Format("上机时间:{0} 预计下机时间:{1}", startTime.ToString(CommConstant.TimeFormatString),
                                          startTime.AddMinutes(sync.DialysisDuration.GetValueOrDefault()).ToString(CommConstant.TimeFormatString));
            var message = new Domain.Models.Message
            {
                AppType   = (int)AppTypeEnum.Patient,
                Content   = content,
                IsRead    = false,
                ReceiveId = patient.Id,
                SendId    = 0,
                SendName  = "系统",
                Title     = "透析前上机测量",
                Type      = (int)MessageTypeEnum.透析上机,
                OuterId   = dialysis.Id.ToString()
            };
            _messageRepository.Add(message);
            #endregion

            if (!_unitWork.Commit())
            {
                OutputBase.Fail("保存失败");
            }

            #region 向患者端异步发送上机JPush
            ThreadPool.QueueUserWorkItem(delegate
            {
                new JPushMessage(AppTypeEnum.Patient, (int)JPushKeyEnum.DialysisOn, patient.Id.ToString(), content, dialysis.Id.ToString(), _optionsAccessor.IsDevModel).SendPush();
                new JPushNotification(AppTypeEnum.Patient, (int)JPushKeyEnum.DialysisOn, patient.Id.ToString(), content, dialysis.Id.ToString(), _optionsAccessor.IsDevModel).SendPush();
            });
            #endregion

            return(OutputBase.Success("保存成功"));
        }
Beispiel #12
0
        internal static async Task SendCommentReplyNotification(IPrincipal user, Data.Models.Submission submission, Data.Models.Comment comment)
        {
            try
            {
                using (var _db = new VoatOutOfRepositoryDataContextAccessor())
                {
                    Random _rnd = new Random();

                    if (comment.ParentID != null && comment.Content != null)
                    {
                        // find the parent comment and its author
                        var parentComment = _db.Comment.Find(comment.ParentID);
                        if (parentComment != null)
                        {
                            // check if recipient exists
                            if (UserHelper.UserExists(parentComment.UserName))
                            {
                                // do not send notification if author is the same as comment author
                                if (parentComment.UserName != comment.UserName)
                                {
                                    // send the message
                                    //BlockedUser Implementation - Comment Reply
                                    if (!MesssagingUtility.IsSenderBlocked(comment.UserName, parentComment.UserName))
                                    {
                                        //var submission = DataCache.Submission.Retrieve(comment.SubmissionID);
                                        //var q = new QuerySubmission(comment.SubmissionID.Value);
                                        //var submission = await q.ExecuteAsync().ConfigureAwait(CONSTANTS.AWAIT_CAPTURE_CONTEXT);

                                        if (submission != null)
                                        {
                                            //var subverse = DataCache.Subverse.Retrieve(submission.Subverse);

                                            var message = new Domain.Models.Message();

                                            message.IsAnonymized  = submission.IsAnonymized;
                                            message.Recipient     = parentComment.UserName;
                                            message.RecipientType = Domain.Models.IdentityType.User;
                                            message.Sender        = comment.UserName;
                                            message.SenderType    = Domain.Models.IdentityType.User;
                                            message.Subverse      = submission.Subverse;
                                            message.SubmissionID  = submission.ID;
                                            message.CommentID     = comment.ID;
                                            message.Type          = Domain.Models.MessageType.CommentReply;
                                            message.CreationDate  = Repository.CurrentDate;

                                            using (var repo = new Repository(user))
                                            {
                                                var response = await repo.SendMessage(message);

                                                if (response.Success)
                                                {
                                                    EventNotification.Instance.SendMessageNotice(message.Recipient, message.Sender, Domain.Models.MessageTypeFlag.CommentReply, Domain.Models.ContentType.Comment, comment.ID);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }