Esempio n. 1
0
        //public bool ComfirmReg(RequestUserOPDRegisterSubmitDTO request)
        //{
        //    var existsOrder = new OrderRepeatReturnDTO();
        //    if (ExistsWithSubmitRequest(request, out existsOrder))
        //    {
        //        using (var db = new DBEntities())
        //        {
        //            v
        //    }
        //    }


        //}

        /// <summary>
        /// 获取预约记录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public Response <List <UserOPDRegisterDTO> > GetPageList(RequestUserQueryOPDRegisterDTO request)
        {
            Response <List <UserOPDRegisterDTO> > result = new Response <List <UserOPDRegisterDTO> >();

            var today = DateTime.Now;

            using (XuHos.DAL.EF.DBEntities db = new DBEntities())
            {
                int Total = 0;

                string        queryPredicate = "IsDeleted = @0 AND (OPDType = @1 OR OPDType = @2)";
                List <object> paramValues    = new List <object> {
                    false, EnumDoctorServiceType.VidServiceType, EnumDoctorServiceType.AudServiceType
                };

                if (!string.IsNullOrEmpty(request.MemberID))
                {
                    BLL.User.Implements.UserMemberService memser = new UserMemberService();
                    var member = memser.GetMemberInfo(request.MemberID);
                    if (!string.IsNullOrEmpty(member.IDNumber))
                    {
                        queryPredicate += " AND IDNumber = @3";
                        paramValues.Add(member.IDNumber);
                    }
                    else
                    {
                        queryPredicate += " AND MemberID = @3";
                        paramValues.Add(request.MemberID);
                    }
                }
                else
                {
                    queryPredicate += " AND UserID = @3";
                    paramValues.Add(CurrentOperatorUserID);
                }

                IQueryable <UserOPDRegisterDTO> query = null;
                // 过滤排班与处方明细,app不需要用到提高查询效率
                if (request.FilterRecipeAndSchedule.HasValue && request.FilterRecipeAndSchedule.Value)
                {
                    // 指定用户条件筛选,建议在UserOpdRegisters表Where条件进行
                    query = from opd in db.UserOpdRegisters.Where(queryPredicate, paramValues.ToArray())
                            join doctor in db.Doctors.Where(a => !a.IsDeleted) on opd.DoctorID equals doctor.DoctorID
                            join dept in db.HospitalDepartments on doctor.DepartmentID equals dept.DepartmentID into leftJoinDept
                            from deptIfEmpty in leftJoinDept.DefaultIfEmpty()
                            join hosp in db.Hospitals on deptIfEmpty.HospitalID equals hosp.HospitalID into leftJoinHosp
                            from hsopIfEmpty in leftJoinHosp.DefaultIfEmpty()
                            join order in db.Orders.Where(a => !a.IsDeleted) on opd.OPDRegisterID equals order.OrderOutID
                            join room in db.Set <Entity.ConversationRoom>().Where(a => a.IsDeleted == false) on opd.OPDRegisterID equals room.ServiceID into leftJoinRoom
                            from roomIfEmpty in leftJoinRoom.DefaultIfEmpty()
                            select new UserOPDRegisterDTO()
                    {
                        OPDRegisterID  = opd.OPDRegisterID, //预约编号
                        OPDDate        = opd.OPDDate.Value, //排版日期
                        OPDType        = opd.OPDType,       //预约类型
                        UserID         = opd.UserID,        //用户编号
                        Fee            = opd.Fee,           //费用
                        ConsultContent = opd.ConsultContent,
                        IDNumber       = opd.IDNumber,
                        MemberID       = opd.MemberID,
                        Age            = opd.Age,
                        Room           = new ConversationRoomDTO()
                        {
                            //就诊当天,没有就诊,用户已经支付
                            ChannelID = roomIfEmpty != null && (order.OrderState == EnumOrderState.Finish ||
                                                                (order.OrderState == EnumOrderState.Paid &&
                                                                 (opd.OPDDate.Value.Year == today.Year &&
                                                                  opd.OPDDate.Value.Month == today.Month &&
                                                                  opd.OPDDate.Value.Day == today.Day))
                                                                ) ? roomIfEmpty.ChannelID : 0,                   //就诊房间
                            RoomState = roomIfEmpty != null ? roomIfEmpty.RoomState : EnumRoomState.NoTreatment, //预约状态
                            Secret    = roomIfEmpty != null ? roomIfEmpty.Secret : "",                           //房间密码
                        },
                        Order = new OrderDTO()
                        {
                            OrderNo       = order.OrderNo,   //订单编号
                            OrderTime     = order.OrderTime, //订单时间
                            OrderState    = order.OrderState,
                            LogisticNo    = order.LogisticNo,
                            LogisticState = order.LogisticState,
                            PayType       = order.PayType,
                            CostType      = order.CostType,
                            TotalFee      = order.totalFee,
                            TradeNo       = order.TradeNo,
                            IsEvaluated   = order.IsEvaluated,
                            RefundState   = order.RefundState
                        },
                        Member = new UserMemberDTO()
                        {
                            UserID     = opd.UserID,
                            MemberID   = opd.MemberID,      //成员编号
                            MemberName = opd.MemberName,
                            Gender     = opd.Gender,
                            IDNumber   = opd.IDNumber,
                            Age        = opd.Age
                        },
                        Doctor = new DoctorDto()
                        {
                            DoctorID       = opd.DoctorID,  //医生编号
                            DoctorName     = doctor.DoctorName,
                            DepartmentID   = doctor.DepartmentID,
                            DepartmentName = deptIfEmpty != null ? deptIfEmpty.DepartmentName : "",
                            HospitalID     = hsopIfEmpty != null ? hsopIfEmpty.HospitalID : "",
                            HospitalName   = hsopIfEmpty != null ? hsopIfEmpty.HospitalName : "",
                            Specialty      = doctor.Specialty,
                            Title          = doctor.Title,
                            Duties         = doctor.Duties,
                        }
                    };
                }
                else
                {
                    // 指定用户条件筛选,建议在UserOpdRegisters表Where条件进行
                    query = from opd in db.UserOpdRegisters.Where(queryPredicate, paramValues.ToArray())
                            join doctor in db.Doctors.Where(a => !a.IsDeleted) on opd.DoctorID equals doctor.DoctorID into doctorLeftMid
                            from doctorLeft in doctorLeftMid.DefaultIfEmpty()
                            join dept in db.HospitalDepartments on doctorLeft.DepartmentID equals dept.DepartmentID into leftJoinDept
                            from deptIfEmpty in leftJoinDept.DefaultIfEmpty()
                            join hosp in db.Hospitals on deptIfEmpty.HospitalID equals hosp.HospitalID into leftJoinHosp
                            from hsopIfEmpty in leftJoinHosp.DefaultIfEmpty()
                            join emr in db.UserMedicalRecords.Where(a => !a.IsDeleted && a.DoctorID != null && a.DoctorID != "") on opd.OPDRegisterID equals emr.OPDRegisterID into leftJoinEmr
                            from emrIfEmpty in leftJoinEmr.DefaultIfEmpty()
                            //join depart in db.HospitalDepartments on doctor.DepartmentID equals depart.DepartmentID
                            //join hosp in db.Hospitals on depart.HospitalID equals hosp.HospitalID
                            join order in db.Orders.Where(a => !a.IsDeleted) on opd.OPDRegisterID equals order.OrderOutID
                            join sch in db.DoctorSchedules.Where(a => !a.IsDeleted) on opd.ScheduleID equals sch.ScheduleID into leftJoinSch
                            from schIfEmpty in leftJoinSch.DefaultIfEmpty()
                            join room in db.Set <Entity.ConversationRoom>().Where(a => a.IsDeleted == false) on opd.OPDRegisterID equals room.ServiceID into leftJoinRoom
                            from roomIfEmpty in leftJoinRoom.DefaultIfEmpty()
                            select new UserOPDRegisterDTO()
                    {
                        OPDRegisterID  = opd.OPDRegisterID, //预约编号
                        OPDDate        = opd.OPDDate.Value, //排版日期
                        OPDType        = opd.OPDType,       //预约类型
                        UserID         = opd.UserID,        //用户编号
                        Fee            = opd.Fee,           //费用
                        ConsultContent = opd.ConsultContent,
                        IDNumber       = opd.IDNumber,
                        MemberID       = opd.MemberID,
                        Age            = opd.Age,
                        Room           = new ConversationRoomDTO()
                        {
                            //就诊当天,没有就诊,用户已经支付
                            ChannelID = roomIfEmpty != null && (order.OrderState == EnumOrderState.Finish ||
                                                                (order.OrderState == EnumOrderState.Paid &&
                                                                 (opd.OPDDate.Value.Year == today.Year &&
                                                                  opd.OPDDate.Value.Month == today.Month &&
                                                                  opd.OPDDate.Value.Day == today.Day))
                                                                ) ? roomIfEmpty.ChannelID : 0,                   //就诊房间
                            RoomState = roomIfEmpty != null ? roomIfEmpty.RoomState : EnumRoomState.NoTreatment, //预约状态
                            Secret    = roomIfEmpty != null ? roomIfEmpty.Secret : "",                           //房间密码
                        },
                        Order = new OrderDTO()
                        {
                            OrderNo       = order.OrderNo,   //订单编号
                            OrderTime     = order.OrderTime, //订单时间
                            OrderState    = order.OrderState,
                            LogisticNo    = order.LogisticNo,
                            LogisticState = order.LogisticState,
                            PayType       = order.PayType,
                            CostType      = order.CostType,
                            TotalFee      = order.totalFee,
                            TradeNo       = order.TradeNo,
                            IsEvaluated   = order.IsEvaluated,
                            RefundState   = order.RefundState
                        },
                        Member = new UserMemberDTO()
                        {
                            UserID     = opd.UserID,
                            MemberID   = opd.MemberID,      //成员编号
                            MemberName = opd.MemberName,
                            Gender     = opd.Gender,
                            IDNumber   = opd.IDNumber,
                            Age        = opd.Age
                        },
                        Doctor = new DoctorDto()
                        {
                            DoctorID       = opd.DoctorID,  //医生编号
                            DoctorName     = doctorLeft == null ? "" : doctorLeft.DoctorName,
                            DepartmentID   = doctorLeft != null ? doctorLeft.DepartmentID : "",
                            DepartmentName = deptIfEmpty != null ? deptIfEmpty.DepartmentName : "",
                            HospitalID     = hsopIfEmpty != null ? hsopIfEmpty.HospitalID : "",
                            HospitalName   = hsopIfEmpty != null ? hsopIfEmpty.HospitalName : "",
                            Specialty      = doctorLeft == null ? "" : doctorLeft.Specialty,
                            Title          = doctorLeft == null ? "" : doctorLeft.Title,
                            Duties         = doctorLeft == null ? "" : doctorLeft.Duties,
                        },
                        Schedule = new DoctorScheduleDto
                        {
                            ScheduleID = schIfEmpty.ScheduleID,
                            StartTime  = schIfEmpty != null ? schIfEmpty.StartTime : opd.OPDBeginTime,
                            EndTime    = schIfEmpty != null ? schIfEmpty.EndTime : opd.OPDEndTime,
                        },
                        IsExistMedicalRecord = emrIfEmpty != null
                    };
                }

                #region 处理搜索条件
                //查询关键字
                if (!string.IsNullOrEmpty(request.Keyword))
                {
                    query = query.Where(a => a.Member.MemberName.Contains(request.Keyword));
                }

                //开始日期
                if (request.BeginDate.HasValue)
                {
                    query = query.Where(a => a.OPDDate >= request.BeginDate);
                }

                //结束日期
                if (request.EndDate.HasValue)
                {
                    request.EndDate = request.EndDate.Value.AddDays(1);
                    query           = query.Where(a => a.OPDDate < request.EndDate);
                }


                //类型
                if (request.OPDType.HasValue)
                {
                    query = query.Where(a => a.OPDType == request.OPDType.Value);
                }
                //状态
                if (request.OrderState.HasValue)
                {
                    query = query.Where(a => a.Order.OrderState == request.OrderState.Value);
                }

                #endregion

                query       = query.OrderByDescending(a => new { a.Order.OrderTime, a.Order.OrderState });
                result.Data = query.Pager <UserOPDRegisterDTO>(out Total, request.CurrentPage, request.PageSize);

                result.Total = Total;
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 提交预约
        /// </summary>
        /// <param name="request"></param>
        /// <param name="CheckExists">是否检查重复预约</param>
        /// <returns></returns>
        public ResponseUserOPDRegisterSubmitDTO Submit(RequestUserOPDRegisterSubmitDTO request)
        {
            #region 校验失败:重复预约
            var existsOrder = new OrderRepeatReturnDTO();

            if (ExistsWithSubmitRequest(request, out existsOrder))
            {
                if (existsOrder.OrderState == EnumOrderState.NoPay)
                {
                    return(new ResponseUserOPDRegisterSubmitDTO
                    {
                        ErrorInfo = "预约成功",
                        ActionStatus = "Success",
                        OPDRegisterID = existsOrder.OrderOutID,
                        OrderNO = existsOrder.OrderNo,
                        OrderState = existsOrder.OrderState,
                        ChannelID = existsOrder.ChannelID
                    });
                }
                else
                {
                    return(new ResponseUserOPDRegisterSubmitDTO
                    {
                        ErrorInfo = "已有未完成的预约,不能重复预约",
                        OPDRegisterID = existsOrder.OrderOutID,
                        OrderNO = existsOrder.OrderNo,
                        OrderState = existsOrder.OrderState,
                        ChannelID = existsOrder.ChannelID,
                        ActionStatus = "Repeat"
                    });
                }
            }
            #endregion

            using (DAL.EF.DBEntities db = new DBEntities())
            {
                var Reason = "";

                var orderService = new OrderService(CurrentOperatorUserID);

                //获取服务价格
                decimal ServicePrice    = 0.01M;
                var     OPDDate         = DateTime.Now;
                var     OPDBeginTime    = DateTime.Now.ToString("HH:mm");
                var     OPDEndTime      = DateTime.Now.AddMinutes(30).ToString("HH:mm");
                var     OrderExpireTime = DateTime.Now.AddMinutes(30);

                RequestUserMemberDTO member = new UserMemberService().
                                              GetDefaultMemberInfo(request.UserID).Map <ResponseUserMemberDTO, RequestUserMemberDTO>();


                #region 新增预约记录
                UserOPDRegister model = new UserOPDRegister()
                {
                    CreateUserID   = request.UserID,
                    OPDType        = request.OPDType,
                    MemberID       = request.MemberID,
                    Fee            = ServicePrice,//服务价格
                    OPDRegisterID  = Guid.NewGuid().ToString("N"),
                    UserID         = request.UserID,
                    ConsultContent = string.IsNullOrEmpty(request.ConsultContent) ? "" : request.ConsultContent,
                };

                if (member != null)
                {
                    model.MemberName = member.MemberName;
                    model.Gender     = member.Gender;
                    model.Marriage   = member.Marriage;
                    model.Age        = member.Age;
                    model.IDNumber   = string.IsNullOrEmpty(member.IDNumber) ? "" : member.IDNumber;
                    model.IDType     = member.IDType;
                    model.Mobile     = member.Mobile;
                    model.Address    = member.Address;
                    model.Birthday   = member.Birthday;
                }

                db.UserOpdRegisters.Add(model);

                #endregion

                #region 添加附件
                if (request.Files != null)
                {
                    foreach (var file in request.Files)
                    {
                        db.UserFiles.Add(new UserFile()
                        {
                            FileID     = Guid.NewGuid().ToString("N"),
                            FileName   = file.FileUrl,
                            FileUrl    = file.FileUrl,
                            FileType   = 0,
                            Remark     = file.Remark,
                            AccessKey  = "",
                            ResourceID = "",
                            OutID      = model.OPDRegisterID,
                            UserID     = request.UserID
                        });
                    }
                }
                #endregion

                #region 创建房间
                var room = new Entity.ConversationRoom();
                room.EndTime            = DateTime.Parse(OPDDate.ToString("yyyy-MM-dd ") + OPDEndTime);
                room.BeginTime          = DateTime.Parse(OPDDate.ToString("yyyy-MM-dd ") + OPDBeginTime);
                room.TotalTime          = 0;
                room.RoomState          = EnumRoomState.NoTreatment;//状态
                room.ConversationRoomID = Guid.NewGuid().ToString("N");
                room.ServiceID          = model.OPDRegisterID;
                room.ServiceType        = model.OPDType;
                //如果预约类型是挂号那么房间类型就是线下看诊,否则是线上看诊
                room.RoomType = EnumRoomType.Group;
                db.Set <ConversationRoom>().Add(room);
                #endregion

                #region 创建订单

                EnumProductType ProductType = EnumProductType.Other;

                switch (model.OPDType)
                {
                case EnumDoctorServiceType.VidServiceType:
                    ProductType = EnumProductType.video;
                    break;

                default:
                    break;
                }

                var order = orderService.CreateOrder(new OrderDTO()
                {
                    OrderType       = ProductType,
                    OrderOutID      = model.OPDRegisterID,
                    UserID          = model.UserID,
                    OrderTime       = DateTime.Now,
                    OrderExpireTime = OrderExpireTime,
                    Details         = new List <OrderDetailDTO>()
                    {
                        new OrderDetailDTO()
                        {
                            Subject     = ProductType.GetEnumDescript(),
                            Body        = "",
                            ProductId   = "",
                            ProductType = ProductType,
                            Quantity    = 1,
                            UnitPrice   = model.Fee
                        }
                    }
                }, db);

                #endregion

                if (db.SaveChanges() > 0)
                {
                    //确定订单
                    if (orderService.Confirm(order.OrderNo, new RequestOrderConfirmDTO()
                    {
                        OrderNo = order.OrderOutID,
                    }) == EnumApiStatus.BizOK)
                    {
                        order = orderService.GetOrder(order.OrderNo);

                        return(new ResponseUserOPDRegisterSubmitDTO
                        {
                            ErrorInfo = "预约成功",
                            ActionStatus = "Success",
                            OPDRegisterID = model.OPDRegisterID,
                            OrderNO = order.OrderNo,
                            OrderState = order.OrderState,
                            ChannelID = room.ChannelID
                        });
                    }
                    else
                    {
                        orderService.Cancel(order.OrderNo);
                    }
                }

                return(new ResponseUserOPDRegisterSubmitDTO
                {
                    ErrorInfo = "预约失败",
                    ActionStatus = "Fail",
                });
            }
        }