public IActionResult LoadErrors()
 {
     try
     {
         var tempPatientArtExtracts = _tempPatientArtExtractRepository.GetAll().Where(n => n.CheckError).ToList();
         return(Ok(tempPatientArtExtracts));
     }
     catch (Exception e)
     {
         var msg = $"Error loading PatientArt Extracts with errors";
         Log.Error(msg);
         Log.Error($"{e}");
         return(StatusCode(500, msg));
     }
 }
示例#2
0
        public async Task <int> Load(Guid extractId, int found)
        {
            int count = 0;

            try
            {
                DomainEvents.Dispatch(
                    new ExtractActivityNotification(extractId, new DwhProgress(
                                                        nameof(PatientArtExtract),
                                                        nameof(ExtractStatus.Loading),
                                                        found, 0, 0, 0, 0)));


                StringBuilder query = new StringBuilder();
                query.Append($" SELECT s.* FROM {nameof(TempPatientArtExtract)}s s");
                query.Append($" INNER JOIN PatientExtracts p ON ");
                query.Append($" s.PatientPK = p.PatientPK AND ");
                query.Append($" s.SiteCode = p.SiteCode ");

                const int take   = 500;
                var       eCount = await _tempPatientArtExtractRepository.GetCount(query.ToString());

                var pageCount = _tempPatientArtExtractRepository.PageCount(take, eCount);

                int page = 1;
                while (page <= pageCount)
                {
                    var tempPatientArtExtracts = await
                                                 _tempPatientArtExtractRepository.GetAll(query.ToString(), page, take);

                    var batch = tempPatientArtExtracts.ToList();
                    count += batch.Count;

                    //Auto mapper
                    var extractRecords = Mapper.Map <List <TempPatientArtExtract>, List <PatientArtExtract> >(batch);
                    foreach (var record in extractRecords)
                    {
                        record.Id = LiveGuid.NewGuid();
                    }
                    //Batch Insert
                    var inserted = _patientArtExtractRepository.BatchInsert(extractRecords);
                    if (!inserted)
                    {
                        Log.Error($"Extract {nameof(PatientArtExtract)} not Loaded");
                        return(0);
                    }
                    Log.Debug("saved batch");
                    page++;
                    DomainEvents.Dispatch(
                        new ExtractActivityNotification(extractId, new DwhProgress(
                                                            nameof(PatientArtExtract),
                                                            nameof(ExtractStatus.Loading),
                                                            found, count, 0, 0, 0)));
                }
                return(count);
            }
            catch (Exception e)
            {
                Log.Error(e, $"Extract {nameof(PatientArtExtract)} not Loaded");
                return(0);
            }
        }