public IActionResult LoadValid() { try { var tempPatientExtracts = _tempPatientExtractRepository.GetAll().Where(n => !n.CheckError).ToList(); return(Ok(tempPatientExtracts)); } catch (Exception e) { var msg = $"Error loading valid Patient Extracts"; Log.Error(msg); Log.Error($"{e}"); return(StatusCode(500, msg)); } }
public async Task <int> Load(Guid extractId, int found, bool diffSupport) { int count = 0; var mapper = diffSupport ? ExtractDiffMapper.Instance : ExtractMapper.Instance; try { DomainEvents.Dispatch( new ExtractActivityNotification(extractId, new DwhProgress( nameof(PatientExtract), nameof(ExtractStatus.Loading), found, 0, 0, 0, 0))); const int take = 500; var eCount = await _tempPatientExtractRepository.GetCleanCount(); var pageCount = _tempPatientExtractRepository.PageCount(take, eCount); int page = 1; while (page <= pageCount) { var tempPatientExtracts = await _tempPatientExtractRepository.GetAll(a => a.ErrorType == 0, page, take); var batch = tempPatientExtracts.ToList(); count += batch.Count; //Auto mapper var extractRecords = mapper.Map <List <TempPatientExtract>, List <PatientExtract> >(batch); foreach (var record in extractRecords) { record.Id = LiveGuid.NewGuid(); } //Batch Insert var inserted = _patientExtractRepository.BatchInsert(extractRecords); if (!inserted) { Log.Error($"Extract {nameof(PatientExtract)} not Loaded"); return(0); } Log.Debug("saved batch"); page++; DomainEvents.Dispatch( new ExtractActivityNotification(extractId, new DwhProgress( nameof(PatientExtract), nameof(ExtractStatus.Loading), found, count, 0, 0, 0))); } await _mediator.Publish(new DocketExtractLoaded("NDWH", nameof(PatientExtract))); return(count); } catch (Exception e) { Log.Error(e, $"Extract {nameof(PatientExtract)} not Loaded"); throw; } }
public async Task <int> Load(Guid extractId, int found) { try { DomainEvents.Dispatch( new ExtractActivityNotification(extractId, new DwhProgress( nameof(PatientExtract), nameof(ExtractStatus.Loading), found, 0, 0, 0, 0))); //load temp extracts without errors var tempPatientExtracts = _tempPatientExtractRepository.GetAll().Where(a => a.CheckError == false); const int take = 1000; int skip = 0; var count = tempPatientExtracts.Count(); while (skip < count) { var batch = tempPatientExtracts.Skip(skip).Take(take).ToList(); //Auto mapper var extractRecords = Mapper.Map <List <TempPatientExtract>, List <PatientExtract> >(batch); foreach (var record in extractRecords) { record.Id = LiveGuid.NewGuid(); } //Batch Insert var inserted = _patientExtractRepository.BatchInsert(extractRecords); if (!inserted) { Log.Error($"Extract {nameof(PatientExtract)} not Loaded"); return(0); } Log.Debug("saved batch"); skip = skip + take; DomainEvents.Dispatch( new ExtractActivityNotification(extractId, new DwhProgress( nameof(PatientExtract), nameof(ExtractStatus.Loading), found, skip, 0, 0, 0))); } return(count); } catch (Exception e) { Log.Error(e, $"Extract {nameof(PatientExtract)} not Loaded"); throw; } }
public async Task <bool> Handle(ExtractPatient request, CancellationToken cancellationToken) { //Extract int found = await _patientSourceExtractor.Extract(request.Extract, request.DatabaseProtocol); //Check for duplicate patients var patientKeys = _tempPatientExtractRepository.GetAll().Select(k => k.PatientPK); var distinct = new HashSet <int?>(); var duplicates = new HashSet <int?>(); foreach (var key in patientKeys) { if (!distinct.Add(key)) { duplicates.Add(key); } } if (duplicates.Any()) { var readDuplicates = string.Join(", ", duplicates.ToArray()); throw new DuplicatePatientException($"Duplicate patient(s) with PatientPK(s) {readDuplicates} found"); } //Validate await _extractValidator.Validate(request.Extract.Id, found, nameof(PatientExtract), $"{nameof(TempPatientExtract)}s"); //Load int loaded = await _patientLoader.Load(request.Extract.Id, found, request.DatabaseProtocol.SupportsDifferential); int rejected = _extractHistoryRepository.ProcessRejected(request.Extract.Id, found - loaded, request.Extract); // _extractHistoryRepository.ProcessExcluded(request.Extract.Id, rejected,0); _extractHistoryRepository.ProcessExcluded(request.Extract.Id, rejected, request.Extract); //notify loaded DomainEvents.Dispatch( new ExtractActivityNotification(request.Extract.Id, new DwhProgress( nameof(PatientExtract), nameof(ExtractStatus.Loaded), found, loaded, rejected, loaded, 0))); return(true); }