Exemplo n.º 1
0
        /// <summary>
        /// 创建聊天的房间
        /// </summary>
        /// <param name="OPDRegisterID"></param>
        /// <returns></returns>
        public bool CreateIMRoom(string OPDRegisterID)
        {
            try
            {
                using (DAL.EF.DBEntities db = new DBEntities())
                {
                    var model = (from opd in db.UserOpdRegisters.Where(a => a.OPDRegisterID == OPDRegisterID)
                                 join user in db.Users on opd.UserID equals user.UserID
                                 join member in db.UserMembers on opd.MemberID equals member.MemberID
                                 select new
                    {
                        OPDType = opd.OPDType,
                        DoctorID = opd.DoctorID,             //opd.DoctorID,
                        UserID = opd.UserID,
                        MemberID = opd.MemberID,
                        member.MemberName,
                        user.PhotoUrl,
                        user.UserCNName,
                        user.UserENName
                    }).FirstOrDefault();


                    if (model != null)
                    {
                        #region 创建IM群组
                        XuHos.Integration.QQCloudy.IMHelper imservice    = new XuHos.Integration.QQCloudy.IMHelper();
                        ConversationIMUidService            imUidService = new ConversationIMUidService(CurrentOperatorUserID);
                        var roomService = new BLL.Sys.Implements.ConversationRoomService();

                        BLL.Doctor.Implements.DoctorService doctorService = new Doctor.Implements.DoctorService();

                        //房间信息
                        var room = roomService.GetChannelInfo(OPDRegisterID);

                        if (room != null)
                        {
                            var GroupName      = model.OPDType.GetEnumDescript();
                            var Introduction   = "";
                            var Notification   = "";
                            var groupMembers   = new List <int>();
                            var channelMembers = new List <RequestChannelMemberDTO>();

                            //患者信息
                            var userIdentifier = imUidService.GetUserIMUid(model.UserID);
                            if (userIdentifier > 0)
                            {
                                groupMembers.Add(userIdentifier);
                                channelMembers.Add(new RequestChannelMemberDTO()
                                {
                                    Identifier   = userIdentifier,
                                    UserType     = EnumUserType.User,
                                    UserID       = model.UserID,
                                    UserMemberID = model.MemberID,
                                    PhotoUrl     = model.PhotoUrl,
                                    UserCNName   = model.MemberName,
                                    UserENName   = model.MemberName
                                });
                            }

                            //获取医生信息(如果走导诊系统,此时还未分配医生,分诊后才会把分诊医生加入到IM组)
                            if (!string.IsNullOrEmpty(model.DoctorID))
                            {
                                var doctorInfo       = doctorService.GetDoctorInfo(model.DoctorID);
                                var doctorIdentifier = imUidService.GetDoctorIMUid(model.DoctorID);
                                if (doctorIdentifier > 0)
                                {
                                    groupMembers.Add(doctorIdentifier);
                                    channelMembers.Add(new RequestChannelMemberDTO()
                                    {
                                        Identifier   = doctorIdentifier,
                                        UserID       = doctorInfo.UserID,
                                        UserType     = EnumUserType.Doctor,
                                        UserMemberID = doctorInfo.User.MemberID,
                                        PhotoUrl     = doctorInfo.User._PhotoUrl,//DTO已经进行了路径转换,这里需要使用没有转换之前的数据
                                        UserENName   = doctorInfo.DoctorEnName,
                                        UserCNName   = doctorInfo.DoctorName
                                    });
                                }
                            }

                            if (room.Enable)
                            {
                                if (imservice.AddGroupMember(room.ChannelID, groupMembers))
                                {
                                    return(roomService.InsertChannelMembers(room.ChannelID, channelMembers));
                                }
                            }
                            else
                            {
                                //创建裙子成功
                                if (imservice.CreateGroup(room.ChannelID, GroupName, model.OPDType, groupMembers, Introduction, Notification))
                                {
                                    using (XuHos.EventBus.MQChannel mqChannel = new EventBus.MQChannel())
                                    {
                                        if (mqChannel.Publish <EventBus.Events.ChannelCreatedEvent>(new EventBus.Events.ChannelCreatedEvent()
                                        {
                                            ChannelID = room.ChannelID,
                                            ServiceID = room.ServiceID,
                                            ServiceType = room.ServiceType
                                        }))
                                        {
                                            room.Enable = true;

                                            if (roomService.CompareAndSetChannelInfo(room))
                                            {
                                                return(roomService.InsertChannelMembers(room.ChannelID, channelMembers));
                                            }
                                        }
                                        else
                                        {
                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            return(true);
                        }

                        #endregion
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            //出现数据库并发更新异常需要重试
            catch (DbUpdateConcurrencyException ex)
            {
                return(CreateIMRoom(OPDRegisterID));
            }

            return(false);
        }
Exemplo n.º 2
0
        public UserOPDRegisterDTO Single(string OPDRegisterID, bool WithoutUnSignedRecipe = true)
        {
            var model = this.Single <UserOPDRegisterDTO>(a => a.OPDRegisterID == OPDRegisterID);

            if (model != null)
            {
                #region 订单信息
                model.Order = new BLL.OrderService("").GetOrder("", model.OPDRegisterID);
                #endregion

                #region 房间信息
                model.Room = new BLL.Sys.Implements.ConversationRoomService().GetChannelInfo(model.OPDRegisterID);
                #endregion

                #region 用户资料
                model.User = (from m in this.DBEntities.Users
                              where m.UserID == model.UserID && m.IsDeleted == false
                              select new UserDTO
                {
                    UserID = m.UserID,
                    UserCNName = m.UserCNName,
                    UserENName = m.UserENName,
                    UserLevel = m.UserLevel,
                    UserType = m.UserType
                }).FutureFirstOrDefault();
                #endregion

                #region 用户病历
                model.UserMedicalRecord = (from m in this.DBEntities.UserMedicalRecords
                                           where m.OPDRegisterID == OPDRegisterID && m.IsDeleted == false
                                           orderby m.CreateTime descending
                                           select new UserMedicalRecordDTO()
                {
                    Advised = m.Advised,
                    AllergicHistory = m.AllergicHistory,
                    ConsultationSubject = m.ConsultationSubject,
                    Description = m.Description,
                    FamilyMedicalHistory = m.FamilyMedicalHistory,
                    PastMedicalHistory = m.PastMedicalHistory,
                    PastOperatedHistory = m.PastOperatedHistory,
                    PreliminaryDiagnosis = m.PreliminaryDiagnosis,
                    PresentHistoryIllness = m.PresentHistoryIllness,
                    Sympton = m.Sympton,
                    UserMedicalRecordID = m.UserMedicalRecordID,
                }).FirstOrDefault();

                #endregion

                #region 附件
                IQueryable <UserFile> queryAttachFiles = null;

                if (model.OPDType == EnumDoctorServiceType.AudServiceType || model.OPDType == EnumDoctorServiceType.VidServiceType)
                {
                    queryAttachFiles = (from m in this.DBEntities.UserFiles
                                        where m.OutID == model.OPDRegisterID
                                        select m);
                }

                if (queryAttachFiles != null)
                {
                    model.AttachFiles = queryAttachFiles.Where(i => i.FileType == 0).Select(m => new UserFileDTO
                    {
                        FileID   = m.FileID,
                        FileName = m.FileName,
                        FileType = m.FileType,
                        FileUrl  = m.FileUrl,
                        OutID    = m.OutID,
                        Remark   = m.Remark
                    }).ToList();
                }
                #endregion

                #region 医生信息
                if (!string.IsNullOrEmpty(model.DoctorID))
                {
                    XuHos.BLL.Doctor.Implements.DoctorService doctorService = new Doctor.Implements.DoctorService();
                    var doctor = doctorService.GetDoctorDetail(model.DoctorID);
                    if (doctor != null)
                    {
                        model.Doctor = new DoctorDto()
                        {
                            Title      = Sys.Implements.CodeService.GetDoctorTitles()[doctor.Title],
                            DoctorName = doctor.DoctorName,
                        };
                    }
                }
                #endregion

                #region 患者信息
                if (!string.IsNullOrEmpty(model.MemberID))
                {
                    model.Member = new UserMemberDTO()
                    {
                        MemberID   = model.MemberID,
                        MemberName = model.MemberName,
                        Gender     = model.Gender,
                        Birthday   = model.Birthday,
                        Mobile     = model.Mobile
                    };
                }
                #endregion

                #region 订单来源
                if (!string.IsNullOrEmpty(model.OrgnazitionID))
                {
                    List <string> paths = new XuHos.BLL.HospitalService("").GetOrgFullPathByOrgID(model.OrgnazitionID);//.Single<DTO.HospitalDto>(x => x.HospitalID == model.OrgnazitionID);
                    model.OrgName = paths == null ? null : string.Join(" - ", paths);
                    model.OrgType = null;
                }
                #endregion
            }
            return(model);
        }