コード例 #1
0
        public void Execute(IJobExecutionContext context)
        {
            GetJobParams();

            _logger.Info("执行云归档患者信息同步任务");
            try
            {
                PatientExamListQuery query = new PatientExamListQuery
                {
                    ObservationDate = this.startObservationDate,
                    RowCount        = this.taskRowsForEachJob
                };
                var examresult = WebApiRequestHelper.GetPatientExamList(query);
                if (examresult != null && examresult.Count <= 0)
                {
                    // 查不到数据了
                    throw new EmptyResultException();
                }
                _logger.DebugFormat("总共查询到{0}待注册的患者主索引记录", examresult.Count);

                int nIndex = 1;
                foreach (var item in examresult)
                {
                    _logger.InfoFormat("同步第{0}条ObservationRequest记录,ObservationUID={1}", nIndex, item.ObservationRequest.ObservationUID);
                    try
                    {
                        if (CollectExam(item))
                        {
                            UpdateCollectState(item.ObservationRequest.ObservationUID, 1);//更新已注册标示
                        }
                        else
                        {
                            UpdateCollectState(item.ObservationRequest.ObservationUID, 2);//更新注册失败标示
                        }
                        nIndex++;
                    }
                    catch (Exception ex)
                    {
                        UpdateCollectState(item.ObservationRequest.ObservationUID, 2);//更新注册失败标示
                        _logger.Error($"同步第{nIndex}条ObservationRequest记录,出现异常:{JsonConvert.SerializeObject(item)}", ex);
                        continue;
                    }
                }
            }
            catch (EmptyResultException)
            {
                int s = 1000 * 60 * 2;
                _logger.InfoFormat("未查询到待同步的患者信息,休眠{0}", s);
                Thread.Sleep(s);
            }
            catch (Exception e)
            {
                _logger.Error($"执行同步患者信息到主索引库,出现异常:{e.Message}", e);
            }
        }
コード例 #2
0
        /// <summary>
        /// 更新采集状态
        /// </summary>
        /// <param name="model"></param>
        private void UpdateCollectState(Guid observationUID, short pushState)
        {
            var result = WebApiRequestHelper.UpdateAcquisitionStatus(new UpdateAcquisitionStatusQuery()
            {
                ObservationUID = observationUID,
                PushState      = pushState
            });

            if (result.code != ResultCodeEnum.Success)
            {
                throw new ApplicationException($"{result.msg}");
            }

            _logger.InfoFormat("更新检查:{0} 采集状态为{1}", observationUID, pushState);
        }
コード例 #3
0
        private string GetStringToLog(HttpActionExecutedContext request)
        {
            StringBuilder        logString           = new StringBuilder();
            WebApiRequestHelper  webApiRequestHelper = new WebApiRequestHelper();
            JavaScriptSerializer js = new JavaScriptSerializer();


            string body = webApiRequestHelper.GetBodyFromRequest(request);

            List <KeyValuePair <string, string> > headers = webApiRequestHelper.GetHeadersFromRequest(request);
            string stringHeader = js.Serialize(headers);

            var    queryStrings     = webApiRequestHelper.GetQueryStringFromRequest(request);
            string stringQryStrings = js.Serialize(queryStrings);

            string user = request.ActionContext.RequestContext.Principal.Identity.Name;
            var    ctrl = request.ActionContext.ControllerContext.ControllerDescriptor;


            logString.Append(System.Environment.NewLine);
            logString.Append(System.Environment.NewLine);
            logString.Append($"********************{System.Environment.NewLine}");
            logString.Append($"Request details{System.Environment.NewLine}");
            logString.Append($"********************{System.Environment.NewLine}");
            logString.Append($"User: {user}{System.Environment.NewLine}");
            logString.Append($"Url: {request.Request.RequestUri.AbsoluteUri}{System.Environment.NewLine}");
            logString.Append($"Method: {request.Request.Method}{System.Environment.NewLine}{System.Environment.NewLine}");
            logString.Append($"Body content: {System.Environment.NewLine} {body}{System.Environment.NewLine}{System.Environment.NewLine}");
            logString.Append($"Headers: {System.Environment.NewLine}{stringHeader}{System.Environment.NewLine}{System.Environment.NewLine}");
            logString.Append($"Query strings: {System.Environment.NewLine}{stringQryStrings}{System.Environment.NewLine}{System.Environment.NewLine}");

            logString.Append(System.Environment.NewLine);
            logString.Append(System.Environment.NewLine);
            logString.Append($"********************{System.Environment.NewLine}");
            logString.Append($"Controller details{System.Environment.NewLine}");
            logString.Append($"********************{System.Environment.NewLine}");
            logString.Append($"Controller name:{ctrl.ControllerName}{System.Environment.NewLine}");
            logString.Append($"Properties :{PropertiesExtractor(ctrl.Properties)}{System.Environment.NewLine}");

            logString.Append(System.Environment.NewLine);
            logString.Append(System.Environment.NewLine);
            logString.Append($"********************{System.Environment.NewLine}");
            logString.Append($"Stack Trace:{System.Environment.NewLine}");
            logString.Append($"********************{System.Environment.NewLine}");
            logString.Append(this.InnerExceptionExtractor(request.Exception));

            return(logString.ToString());
        }
コード例 #4
0
        /// <summary>
        /// 采集检查
        /// </summary>
        /// <returns></returns>
        private bool CollectExam(PatientExamListDTO item)
        {
            bool bSuccess = false;

            try
            {
                _logger.DebugFormat("开始采集检查记录, observationUID={0}", item.ObservationRequest.ObservationUID);

                if (item.PatientIndex != null && item.ObservationRequest != null)
                {
                    _logger.Debug("获取检查文档信息");
                    List <ExamDocument> examDocuments = WebApiRequestHelper.GetExamDocuments(item.ObservationRequest.ObservationUID);
                    if (examDocuments != null)
                    {
                        string xml = BuildExamInfo(item, examDocuments);

                        //_logger.InfoFormat("构造xml:{0}", xml);

                        var result = WebApiRequestHelper.RegistryExam(xml);
                        if (result.code == ResultCodeEnum.Success)
                        {
                            _logger.InfoFormat("注册检查{0}成功:RepositoryUniqueId = {1}", item.ObservationRequest.ObservationUID, result.msg);

                            bSuccess = true;
                        }
                        else
                        {
                            _logger.Error("注册检查失败");
                        }
                    }
                }
                else
                {
                    _logger.Error($"调用RegistPatientExam出错, ObservationUID:{item.ObservationRequest.ObservationUID},患者检查信息不完整");
                }
            }
            catch (Exception ex)
            {
                _logger.Error($"调用RegistPatientExam出错, ObservationUID:{item.ObservationRequest.ObservationUID}", ex);
            }

            return(bSuccess);
        }