public IActionResult LoadErrors() { try { var tempPatientLaboratoryExtracts = _tempPatientLaboratoryExtractRepository.GetAll().Where(n => n.CheckError).ToList(); return(Ok(tempPatientLaboratoryExtracts)); } catch (Exception e) { var msg = $"Error loading PatientLaboratory Extracts with errors"; Log.Error(msg); Log.Error($"{e}"); return(StatusCode(500, msg)); } }
public async Task <int> Load(Guid extractId, int found) { int count = 0; try { DomainEvents.Dispatch( new ExtractActivityNotification(extractId, new DwhProgress( nameof(PatientLaboratoryExtract), nameof(ExtractStatus.Loading), found, 0, 0, 0, 0))); StringBuilder query = new StringBuilder(); query.Append($" SELECT s.* FROM {nameof(TempPatientLaboratoryExtract)}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 _tempPatientLaboratoryExtractRepository.GetCount(query.ToString()); var pageCount = _tempPatientLaboratoryExtractRepository.PageCount(take, eCount); int page = 1; while (page <= pageCount) { var tempPatientLaboratoryExtracts = await _tempPatientLaboratoryExtractRepository.GetAll(query.ToString(), page, take); var batch = tempPatientLaboratoryExtracts.ToList(); count += batch.Count(); //Auto mapper var extractRecords = Mapper.Map <List <TempPatientLaboratoryExtract>, List <PatientLaboratoryExtract> >(batch); foreach (var record in extractRecords) { record.Id = LiveGuid.NewGuid(); } //Batch Insert var inserted = _patientLaboratoryExtractRepository.BatchInsert(extractRecords); if (!inserted) { Log.Error($"Extract {nameof(PatientLaboratoryExtract)} not Loaded"); return(0); } Log.Debug("saved batch"); page++; DomainEvents.Dispatch( new ExtractActivityNotification(extractId, new DwhProgress( nameof(PatientLaboratoryExtract), nameof(ExtractStatus.Loading), found, count, 0, 0, 0))); } return(count); } catch (Exception e) { Log.Error(e, $"Extract {nameof(PatientLaboratoryExtract)} not Loaded"); return(0); } }