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

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

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

                const int take   = 500;
                var       eCount = await _tempPatientPharmacyExtractRepository.GetCount(queryBuilder.ToString());

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

                int page = 1;
                while (page <= pageCount)
                {
                    var tempPatientPharmacyExtracts = await
                                                      _tempPatientPharmacyExtractRepository.GetAll(queryBuilder.ToString(), page, take);

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

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