public async Task <OutputBase> SyncDialysisOn([FromBody] AddDialysisOnSync sync)
 {
     return(await _dialysisService.AddDialysisOn(sync));
 }
Beispiel #2
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("保存成功"));
        }