Ejemplo n.º 1
0
        public ActionResult Index()
        {
            ViewBag.Title = "ICD-10 Søk";
            var searchResultsModel = new SearchResultsDataContract();

            return(View(searchResultsModel));
        }
Ejemplo n.º 2
0
        private static SearchResultsDataContract GetIcd10Codes(string code)
        {
            var client =
                new RestClient("https://finnkode.ehelse.no/FinnKodeWS/SearchService.svc/CommitSearch?_dc=1579468909297");

            client.Timeout = -1;
            var request = new RestRequest(Method.POST);

            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json",
                                 "{\"searchExpression\":\"" + code +
                                 "\",\"sources\":[{\"SearchSourceId\":\"ICD10SysDel\",\"Selected\":true}],\"page\":1,\"start\":0,\"limit\":25}",
                                 ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);

            Console.WriteLine(response.Content);
            var result = new SearchResultsDataContract();

            var xmlDoc = XDocument.Parse(response.Content);

            //var jsonDoc = JsonConvert.SerializeObject(xmlDoc);

            if (xmlDoc.Root != null)
            {
                var records = xmlDoc.Root.Elements("record");
                foreach (var record in records)
                {
                    var item = new SearchResultDataContract
                    {
                        Code = record.Element("code")?.Value,
                        Text = record.Element("title")?.Value
                    };
                    if (string.IsNullOrEmpty(item.Code) || string.IsNullOrEmpty(item.Text) || item.Code.Contains("(") ||
                        !item.Code.StartsWith(code, StringComparison.InvariantCultureIgnoreCase) || !item.Code.Contains("."))
                    {
                        continue;
                    }

                    //replace the "." sign
                    item.Code = item.Code.Replace(".", "");
                    result.SearchResults.Add(item);
                }

                result.Code = code;
            }

            if (result.SearchResults.Any())
            {
                result.SearchResults = result.SearchResults.OrderBy(item => item.Code, new AlphanumericComparator <string>())
                                       .ToList();
            }

            return(result);
        }
        /// <summary>
        /// Atomic work 1)Get old search result 2)New Search 3) Compare 4) generate report to database.
        /// </summary>
        /// <param name="task"></param>
        /// <param name="jobParameters"></param>
        /// <returns></returns>
        protected override bool DoAtomicWork(CompareSavedSearchResultsJobTaskEntity task,
                                             CompareSavedSearchResultsJobBEO jobParameters)
        {
            task.ShouldNotBe(null);
            jobParameters.ShouldNotBe(null);
            var queryContext = _searchResultsProperty.DocumentQuery;

            queryContext.DocumentStartIndex    = 0;
            queryContext.DocumentCount         = 1;
            queryContext.IgnoreDocumentSnippet = true;
            queryContext.OutputFields.Clear();
            queryContext.OutputFields.Add(new Field {
                FieldName = EVSystemFields.DcnField
            });
            try
            {
                LogMessage(string.Format(Constants.DoAtomicWorkStartMessage, task.TaskNumber), GetType(),
                           Constants.DoAtomicMethodFullName, EventLogEntryType.Information, jobParameters.JobId,
                           jobParameters.JobRunId);
                switch (task.TaskType)
                {
                case TypeOfTask.FetchRecordFromDb:
                {
                    var searchResultuuid = string.Format(SaveSearchResultIdentifierBEO.UniqueIdentifierFormat,
                                                         _searchResultsProperty.DocumentQuery.QueryObject.MatterId,
                                                         _searchResultsProperty.DocumentQuery.QueryObject.DatasetId,
                                                         _searchResultsProperty.SearchResultId);
                    _oldSearchResult = SearchResultsService.GetSavedSearchResultsWithDocument(searchResultuuid);
                }
                break;

                case TypeOfTask.FetchRecordFromSearchSubSystem:
                {
                    LogMessage(string.Format("New Search start at : {0}",
                                             DateTime.UtcNow.ConvertToUserTime()), GetType(), Constants.DoAtomicMethodFullName,
                               EventLogEntryType.Information, jobParameters.JobId, jobParameters.JobRunId);

                    //SearchContextObject searchContextObject = ConvertToSearchContextObject(queryContext);
                    ReviewerSearchResults rvwSearchBeo;
                    queryContext.QueryObject.TransactionName =
                        "CompareSavedSearchResultsJob - DoAtomicWork (GetCount)";
                    var totalResultCount = JobSearchHandler.GetSearchResultsCount(queryContext.QueryObject);
                    //searchContextObject.ItemsPerPage = totalResultCount;
                    queryContext.DocumentCount   = (int)totalResultCount;
                    queryContext.TransactionName = "CompareSavedSearchResultsJob - DoAtomicWork (GetAll)";
                    rvwSearchBeo = JobSearchHandler.GetAllDocuments(queryContext, false);
                    // Getting search result list by page index
                    LogMessage(string.Format("New Search End at : {0}", DateTime.UtcNow.ConvertToUserTime()),
                               GetType(), Constants.DoAtomicMethodFullName, EventLogEntryType.Information,
                               jobParameters.JobId, jobParameters.JobRunId);
                    //Constructing New search Result Beo
                    _newSearchResult = new SearchResultsDataContract
                    {
                        Information = new SearchResultsInformationDataContract
                        {
                            Properties =
                                new SearchResultsPropertiesDataContract
                            {
                                SearchResultId           = _searchResultsProperty.SearchResultId,
                                SearchResultsName        = _searchResultsProperty.SearchResultsName,
                                SearchResultsDescription = _searchResultsProperty.SearchResultsDescription,
                                DocumentQuery            = _searchResultsProperty.DocumentQuery
                            },
                            CreatedBy   = _userEntityOfJobOwner.UserId,
                            CreatedDate = DateTime.UtcNow.ConvertToUserTime()
                        }
                    };
                    if (rvwSearchBeo != null)
                    {
                        if (rvwSearchBeo.ResultDocuments != null && rvwSearchBeo.ResultDocuments.Any())
                        {
                            //int totalHitCount = 0;
                            foreach (var document in rvwSearchBeo.ResultDocuments)
                            {
                                var documentDeatail = new SearchResultDocumentDetailsDataContract();
                                documentDeatail.DocumentId            = document.DocumentID;
                                documentDeatail.DocumentControlNumber = document.DocumentControlNumber;
                                documentDeatail.NativeFilePath        = GetNativeFilePath(document);
                                _newSearchResult.Details.Add(documentDeatail);
                            }
                            _newSearchResult.Information.NumberOfDocuments = rvwSearchBeo.ResultDocuments.Count;
                        }
                    }
                    LogMessage(string.Format("New Search Results Construction done at : {0}",
                                             DateTime.UtcNow.ConvertToUserTime()), GetType(), Constants.DoAtomicMethodFullName,
                               EventLogEntryType.Information, jobParameters.JobId, jobParameters.JobRunId);
                }
                break;

                case TypeOfTask.CompareRecords:
                {
                    var comparisonStart = DateTime.Now;
                    _savedSearchCompareReport = new SavedSearchCompareReportBEO();
                    LogMessage(string.Format("Comparison Start at: {0}", DateTime.UtcNow.ConvertToUserTime()),
                               GetType(), Constants.DoAtomicMethodFullName, EventLogEntryType.Information,
                               jobParameters.JobId, jobParameters.JobRunId);
                    var oldResultSet = new List <SearchResultsDetailBEO>();
                    var newResultSet = new List <SearchResultsDetailBEO>();
                    _oldSearchResult.Details.SafeForEach(x => oldResultSet.Add(x.ToBusinessEntity()));
                    _newSearchResult.Details.SafeForEach(x => newResultSet.Add(x.ToBusinessEntity()));

                    // Extracting Common document details
                    (newResultSet.Intersect(oldResultSet).ToList()).SafeForEach(x =>
                                                                                _savedSearchCompareReport.CommonDocumentSet.Add(x));
                    //Extracting Unique document details from new Search result
                    (newResultSet.Except(_savedSearchCompareReport.CommonDocumentSet).ToList()).
                    SafeForEach(x => _savedSearchCompareReport.DocumentsOnlyInNewResultSet.Add(x));
                    //Extracting Unique document details from old(Saved) Search result
                    (oldResultSet.Except(_savedSearchCompareReport.CommonDocumentSet).ToList()).
                    SafeForEach(x => _savedSearchCompareReport.DocumentOnlyInOldResultSet.Add(x));
                    var comparisonStop = DateTime.Now;
                    LogMessage(string.Format("Total Time taken for comparison: {0}",
                                             (comparisonStop - comparisonStart).Milliseconds), GetType(),
                               Constants.DoAtomicMethodFullName, EventLogEntryType.Information, jobParameters.JobId,
                               jobParameters.JobRunId);
                }
                break;

                case TypeOfTask.ConstructFileContent:
                {
                    LogMessage(
                        string.Format("File Construction start at: {0}", DateTime.UtcNow.ConvertToUserTime()),
                        GetType(), Constants.DoAtomicMethodFullName, EventLogEntryType.Information,
                        jobParameters.JobId, jobParameters.JobRunId);

                    //Saving Old search results information
                    _savedSearchCompareReport.OldResultDetails = new SearchResultsInformationBEO
                    {
                        CreatedBy          = _oldSearchResult.Information.CreatedBy,
                        CreatedDate        = _oldSearchResult.Information.CreatedDate,
                        NumberOfDocuments  = _oldSearchResult.Information.NumberOfDocuments,
                        NumberOfSearchHits = _oldSearchResult.Information.NumberOfSearchHits
                    };
                    //Saving Old search results information
                    _savedSearchCompareReport.NewResultDetails = new SearchResultsInformationBEO
                    {
                        CreatedBy          = _newSearchResult.Information.CreatedBy,
                        CreatedDate        = _newSearchResult.Information.CreatedDate,
                        NumberOfDocuments  = _newSearchResult.Information.NumberOfDocuments,
                        NumberOfSearchHits = _newSearchResult.Information.NumberOfSearchHits
                    };
                    _savedSearchCompareReport.CreatedBy       = _userEntityOfJobOwner.UserId;
                    _savedSearchCompareReport.SearchQueryTerm = queryContext.QueryObject.DisplayQuery;
                    _savedSearchCompareReport.CreatedDate     = DateTime.UtcNow.ConvertToUserTime();
                    //File Creation Logic
                    CreateReportFile(out _reportString);
                    LogMessage(string.Format("File Construction End at: {0}", DateTime.UtcNow.ConvertToUserTime()),
                               GetType(), Constants.DoAtomicMethodFullName, EventLogEntryType.Information,
                               jobParameters.JobId, jobParameters.JobRunId);
                    //Clean up all class level variable
                    _oldSearchResult = null;
                    _newSearchResult = null;
                }
                break;
                }
            }
            catch (EVException ex)
            {
                _isJobFailed = true;
                WriteToEventViewer(ex, GetType(), MethodBase.GetCurrentMethod().Name, jobParameters.JobId,
                                   jobParameters.JobRunId);
                HandleTaskException(null, string.Format(Constants.TaskKeyStringFormat, task.TaskType),
                                    ErrorCodes.ProblemInDoAtomicWork);
            }
            catch (Exception ex)
            {
                _isJobFailed = true;
                // Handle exception in DoAutomic
                LogMessage(ex, GetType(), MethodBase.GetCurrentMethod().Name, EventLogEntryType.Error,
                           jobParameters.JobId, jobParameters.JobRunId);
                HandleTaskException(ex, string.Format(Constants.TaskKeyStringFormat, task.TaskType),
                                    ErrorCodes.ProblemInDoAtomicWork);
            }
            return(true);
        }
        /// <summary>
        /// Atomic work 1) Search 2) Insert to DB 3) Audit Log.
        /// </summary>
        /// <param name="task"></param>
        /// <param name="jobParameters"></param>
        /// <returns></returns>
        protected override bool DoAtomicWork(SaveSearchResultsJobTaskBEO task, SaveSearchResultsJobBEO jobParameters)
        {
            #region Pre-condition asserts

            task.ShouldNotBe(null);
            jobParameters.ShouldNotBe(null);

            #endregion

            var searchResultsDataEntityObject = new SearchResultsDataContract();
            var searchContext = jobParameters.DocumentQuery;
            searchContext.DocumentStartIndex    = (task.PageNo * task.PageSize);
            searchContext.DocumentCount         = task.PageSize;
            searchContext.IgnoreDocumentSnippet = true;
            searchContext.OutputFields.Clear();
            searchContext.OutputFields.Add(new Field {
                FieldName = EVSystemFields.DcnField
            });
            LogMessage(string.Format(Constants.DoAtomicWorkStartMessage, task.TaskNumber), false, LogCategory.Job, null);
            LogMessage(string.Format(Constants.DoAtomicWorkStartMessage, task.TaskNumber), GetType(),
                       Constants.DoAtomicMethodFullName, EventLogEntryType.Information, jobParameters.JobId,
                       jobParameters.JobRunId);
            try
            {
                // Perform Atomic Task
                //ReviewerSearchResults rvwSearchBeo = JobSearchHandler.GetSearchResultsWithMatchContext(searchContext);
                // we get the search results from   search sub-system in batches of 1000
                searchContext.TransactionName = "SaveSearchResultJob - DoAtomicWork";
                var rvwSearchBeo = JobSearchHandler.GetSearchResults(searchContext);

                LogMessage(string.Format(Constants.SearchDoneForTask, task.TaskNumber), false, LogCategory.Job, null);
                LogMessage(string.Format(Constants.SearchDoneForTask, task.TaskNumber), GetType(),
                           Constants.DoAtomicMethodFullName, EventLogEntryType.Information, jobParameters.JobId,
                           jobParameters.JobRunId);
                if (rvwSearchBeo != null)
                {
                    if (rvwSearchBeo.ResultDocuments != null && rvwSearchBeo.ResultDocuments.Any())
                    {
                        searchResultsDataEntityObject = new SearchResultsDataContract();

                        foreach (var searchDocument in rvwSearchBeo.ResultDocuments)
                        {
                            var documentDetail =
                                new SearchResultDocumentDetailsDataContract
                            {
                                DocumentId            = searchDocument.DocumentID,
                                DocumentControlNumber = searchDocument.DocumentControlNumber,
                                NativeFilePath        = GetNativeFilePath(searchDocument),
                                DatasetId             = _jobBeo.DocumentQuery.QueryObject.DatasetId
                            };
                            searchResultsDataEntityObject.Information = new SearchResultsInformationDataContract
                            {
                                Properties = new SearchResultsPropertiesDataContract
                                {
                                    SearchResultId = _jobBeo.SearchQueryId,
                                    DocumentQuery  = _jobBeo.DocumentQuery
                                },
                                CreatedBy   = _userEntityOfJobOwner.UserGUID,
                                CreatedDate = DateTime.UtcNow
                            };
                            documentDetail.SearchHitCount = searchDocument.SearchHitCount;
                            searchResultsDataEntityObject.Details.Add(documentDetail);
                        }
                        // perform db insertion
                        LogMessage(Constants.InsertDocumentDetailMessage, false, LogCategory.Job, null);
                        LogMessage(Constants.InsertDocumentDetailMessage, GetType(), Constants.DoAtomicMethodFullName,
                                   EventLogEntryType.Information, jobParameters.JobId, jobParameters.JobRunId);

                        #region Audit for each document

                        if (rvwSearchBeo.ResultDocuments != null && rvwSearchBeo.ResultDocuments.Count > 0)
                        {
                            foreach (var searchDocument in rvwSearchBeo.ResultDocuments)
                            {
                                var additionalDetails = new List <KeyValuePair <string, string> >();

                                var additionalDetail = new KeyValuePair <string, string>(Constants.AuditFor,
                                                                                         jobParameters.JobName);
                                additionalDetails.Add(additionalDetail);
                                additionalDetail = new KeyValuePair <string, string>(Constants.DocumentControlNumber,
                                                                                     searchDocument.DocumentControlNumber);
                                additionalDetails.Add(additionalDetail);
                                additionalDetail = new KeyValuePair <string, string>(Constants.DocumentGuid,
                                                                                     searchDocument.DocumentID);
                                additionalDetails.Add(additionalDetail);
                            }
                        }

                        #endregion

                        searchResultsDataEntityObject =
                            SearchResultsService.SaveSearchResultsDocumentDetails(searchResultsDataEntityObject);

                        LogMessage(string.Format(Constants.DoAtomicWorkCompletedMessage, task.TaskNumber), false,
                                   LogCategory.Job, null);
                        LogMessage(string.Format(Constants.DoAtomicWorkCompletedMessage, task.TaskNumber), GetType(),
                                   Constants.DoAtomicMethodFullName, EventLogEntryType.Information, jobParameters.JobId,
                                   jobParameters.JobRunId);
                    }
                }
            }
            finally
            {
                if (searchResultsDataEntityObject.Details != null && searchResultsDataEntityObject.Details.Count > 0)
                {
                    searchResultsDataEntityObject.Details.SafeForEach(x => _dcnList.Add(x.DocumentControlNumber));
                }
            }

            #region Post-condition and class invariant asserts

            task.ShouldNotBe(null);
            jobParameters.ShouldNotBe(null);

            #endregion

            return(true);
        }