/// <summary> /// 根据修改的数据获取操作类型 /// </summary> /// <param name="entity"></param> /// <param name="model"></param> /// <returns></returns> public dynamic GetOperationType(RemoteConsultation entity, RequestConsultationInfoUpdateDTO model) { var operationType = EnumConsultationOperationType.Edit; var message = "修改会诊资料"; try { if (model.Doctors != null && model.Doctors.Count > 0) { using (DBEntities db = new DBEntities()) { //原分配的医生 var doctors = (from item in db.ConsultationDoctors.Where(i => i.ConsultationID == entity.ConsultationID && i.IsDeleted == false) select new { item.IsAttending, item.DoctorID, item.DoctorName, }).ToList(); //现分配的医生 var attendingDoctorID = model.Doctors.Where(i => i.IsAttending).Select(i => i.DoctorID).FirstOrDefault(); var doctorList = (from doctor in model.Doctors select new { doctor.DoctorID, doctor.DoctorName, IsAttending = attendingDoctorID != null && attendingDoctorID == doctor.DoctorID ? true : false }).ToList(); var count = (from oldDoctor in doctors.Where(i => i.IsAttending == false) join currDoctor in model.Doctors.Where(i => i.IsAttending == false) on oldDoctor.DoctorID equals currDoctor.DoctorID select currDoctor).ToList().Count(); //会诊医生是否发生变化 if (doctors.Count(i => i.IsAttending == false) != model.Doctors.Count(i => i.IsAttending == false) || doctors.Count(i => i.IsAttending == false) != count) { operationType = EnumConsultationOperationType.Specialist; int j = 0; message = "会诊已申请专家:" + string.Join(";", doctorList.Where(i => i.IsAttending == false).Select(i => i.DoctorName));// + "," + i.HospitalName + "," + i.DepartmentName + "," + (int.TryParse(i.Title, out j) ? ((EnumDoctorTitle)j).GetEnumDescript() : i.Title))); return(new { OperationType = operationType, Message = message }); } else { //主诊医生是否发生变化 var attendingDoctor = doctors.Where(i => i.IsAttending == true).FirstOrDefault(); var currAttendingDoctor = doctorList.Where(i => i.IsAttending == true).FirstOrDefault(); if ((attendingDoctor == null && currAttendingDoctor != null) || (attendingDoctor != null && currAttendingDoctor == null) || (attendingDoctor != null && currAttendingDoctor != null && attendingDoctor.DoctorID != currAttendingDoctor.DoctorID)) { operationType = EnumConsultationOperationType.Dispatch; int j = 0; if (currAttendingDoctor == null && attendingDoctor != null) { message = "撤回医生服务人员:" + attendingDoctor.DoctorName; } else { message = "指派给医生服务人员:" + currAttendingDoctor.DoctorName;// + "," + currAttendingDoctor.HospitalName + "," + currAttendingDoctor.DepartmentName + "," + (int.TryParse(currAttendingDoctor.Title, out j) ? ((EnumDoctorTitle)j).GetEnumDescript() : currAttendingDoctor.Title); } return(new { OperationType = operationType, Message = message }); } } } } } catch (Exception ee) { } return(new { OperationType = operationType, Message = message }); }
public EnumApiStatus Modify(RequestConsultationInfoUpdateDTO model, ref ResponseConsultationLogDTO logDto, DBEntities db = null) { bool dbPrivateFlag = false; if (db == null) { db = CreateDb(); dbPrivateFlag = true; } //主诊医生 var attendingDoctor = model.Doctors.Where(i => i.IsAttending == true).FirstOrDefault(); if (attendingDoctor == null) { //当前用户为主诊医生 if (model.CurrUserAttending == true && !string.IsNullOrEmpty(model.ConsultationDoctorID)) { attendingDoctor = new RequestConsultationDoctorDTO { DoctorID = model.ConsultationDoctorID, IsAttending = true }; model.Doctors.Add(attendingDoctor); } } #region 病历 UserMedicalRecord userMedical = null; if (model.MedicalRecord != null) { userMedical = model.MedicalRecord.Map <RequestUserMedicalRecordDTO, UserMedicalRecord>(); } else { userMedical = new UserMedicalRecord(); } userMedical.UserID = model.CurrentOperatorUserID; userMedical.MemberID = model.MemberID; userMedical.DoctorID = attendingDoctor == null?model.Doctors.Select(i => i.DoctorID).First() : attendingDoctor.DoctorID; #endregion ConsultationLog operationLog; RemoteConsultation entity = null; if (!string.IsNullOrEmpty(model.ConsultationID)) { #region 编辑(删除再添加) //订单不存在 entity = db.RemoteConsultations.Where(i => i.ConsultationID == model.ConsultationID && i.IsDeleted == false).FirstOrDefault(); if (entity == null) { return(EnumApiStatus.ConsultationNotExists); } //该状态不能修改 if (entity.ConsultationProgress == EnumConsultationProgress.Arranged || entity.ConsultationProgress == EnumConsultationProgress.InProgress || entity.ConsultationProgress == EnumConsultationProgress.Finished || entity.ConsultationProgress == EnumConsultationProgress.Invalid) { return(EnumApiStatus.CurrStatusNotModify); } //已取消,已付款,已完成的订单不能再修改 var opdRegister = db.UserOPDRegisters.Where(i => i.OPDRegisterID == entity.OPDRegisterID).FirstOrDefault(); if (opdRegister != null && (opdRegister.OPDState != EnumOPDState.NoPay)) { return(EnumApiStatus.CurrOrderStatusNotModify); } //修改会诊单 entity.Requirement = model.Requirement; entity.Purpose = model.Purpose; entity.StartTime = model.StartTime; entity.FinishTime = model.FinishTime; entity.ConsultationProgress = model.ConsultationProgress; entity.Address = model.Address; db.Update(entity); //修改预约记录 //opdRegister.OPDRegisterID = entity.OPDRegisterID; opdRegister = CreateOpdRegister(model, opdRegister, attendingDoctor); db.Update(opdRegister); //修改病例 userMedical.UserMedicalRecordID = db.UserMedicalRecords.Where(i => i.OPDRegisterID == opdRegister.OPDRegisterID).Select(i => i.UserMedicalRecordID).First(); userMedical.OPDRegisterID = opdRegister.OPDRegisterID; db.Update(userMedical); //删除医生 var consultationDoctors = db.ConsultationDoctors.Where(i => i.ConsultationID == entity.ConsultationID); db.ConsultationDoctors.RemoveRange(consultationDoctors); //删除文件 var userFiles = db.UserFiles.Where(i => i.OutID == userMedical.UserMedicalRecordID); db.UserFiles.RemoveRange(userFiles); //操作日志 var operation = GetOperationType(entity, model); operationLog = CreateOperationLog(model.ConsultationID, operation.OperationType, EnumOPDState.NoPay, model.ConsultationProgress, operation.Message, model.CurrentOperatorUserID, model.OrgID); #endregion } else { // 添加会诊单 entity = model.Map <RequestConsultationInfoUpdateDTO, RemoteConsultation>(); entity.ConsultationID = Guid.NewGuid().ToString("N"); entity.OPDRegisterID = entity.ConsultationID; entity.ConsultationNo = CreateConsultationNo(); entity.CreateTime = DateTime.Now; entity.CreateUserID = model.CurrentOperatorUserID; db.RemoteConsultations.Add(entity); //添加预约记录 var opdRegister = CreateOpdRegister(model, null, attendingDoctor); opdRegister.CreateTime = DateTime.Now; opdRegister.OPDDate = DateTime.Now; opdRegister.OrgnazitionID = model.OrgID; opdRegister.OPDRegisterID = entity.OPDRegisterID; db.UserOPDRegisters.Add(opdRegister); #region 是否进入导诊系统分诊,否则分诊状态设为不分诊 db.DoctorTriages.Add(new DoctorTriage { OPDRegisterID = opdRegister.OPDRegisterID, TriageDoctorID = model.IsToGuidance ? "" : opdRegister.DoctorID, TriageStatus = model.IsToGuidance ? EnumTriageStatus.None : EnumTriageStatus.Triaged, IsToGuidance = model.IsToGuidance }); #endregion //添加病历 userMedical.UserMedicalRecordID = Guid.NewGuid().ToString("N"); userMedical.OPDRegisterID = opdRegister.OPDRegisterID; db.UserMedicalRecords.Add(userMedical); //操作日志 operationLog = CreateOperationLog(entity.ConsultationID, EnumConsultationOperationType.Create, EnumOPDState.NoPay, model.ConsultationProgress, "创建会诊订单", model.CurrentOperatorUserID, model.OrgID); } #region 添加医生 if (model.Doctors != null && model.Doctors.Count > 0) { //会诊医生会诊服务价格 decimal totalPrice = 0; model.Doctors.ForEach(item => { totalPrice += item.ServicePrice; db.ConsultationDoctors.Add(new ConsultationDoctor { ConsultationDoctorID = Guid.NewGuid().ToString("N"), ConsultationID = entity.ConsultationID, DoctorID = item.DoctorID, IsAttending = item.IsAttending, Amount = item.ServicePrice }); }); //平台服务费用 totalPrice += model.PlatServicePrice; entity.Amount = totalPrice; } #endregion #region 添加文件 if (model.Files != null) { model.Files.ForEach(i => { db.UserFiles.Add(new UserFile() { FileID = Guid.NewGuid().ToString("N"), FileName = i.FileUrl, FileUrl = i.FileUrl, FileType = 0, Remark = i.Remark, OutID = userMedical.UserMedicalRecordID, UserID = model.CurrentOperatorUserID }); }); } #endregion #region 添加影像资料 if (model.InspectResult != null) { //只保存新资料 var inspectList = model.InspectResult.Where(i => string.IsNullOrEmpty(i.InspectResultID)).ToList(); inspectList.ForEach(i => { var inspectEntity = i.Map <RequestUserInspectResultDTO, UserInspectResult>(); inspectEntity.InspectResultID = Guid.NewGuid().ToString("N"); db.UserInspectResults.Add(inspectEntity); }); UploadInspect(inspectList); } #endregion logDto = operationLog.Map <ConsultationLog, ResponseConsultationLogDTO>(); var ret = true; if (dbPrivateFlag) { ret = db.SaveChanges() > 0; db.Dispose(); } if (ret) { return(EnumApiStatus.BizOK); } else { return(EnumApiStatus.BizError); } }