-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from palladiumkenya/dev
NUPI and HTS
- Loading branch information
Showing
141 changed files
with
244,032 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/Dwapi.ExtractsManagement.Core/ComandHandlers/Hts/ExtractHtsEligibilityHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Dwapi.ExtractsManagement.Core.Commands.Hts; | ||
using Dwapi.ExtractsManagement.Core.Interfaces.Cleaner.Hts; | ||
using Dwapi.ExtractsManagement.Core.Interfaces.Extratcors.Hts; | ||
using Dwapi.ExtractsManagement.Core.Interfaces.Loaders.Hts; | ||
using Dwapi.ExtractsManagement.Core.Interfaces.Repository; | ||
using Dwapi.ExtractsManagement.Core.Interfaces.Repository.Hts; | ||
using Dwapi.ExtractsManagement.Core.Interfaces.Validators.Hts; | ||
using Dwapi.ExtractsManagement.Core.Model.Destination.Hts.NewHts; | ||
using Dwapi.ExtractsManagement.Core.Notifications; | ||
using Dwapi.SharedKernel.Enum; | ||
using Dwapi.SharedKernel.Events; | ||
using Dwapi.SharedKernel.Model; | ||
using MediatR; | ||
|
||
namespace Dwapi.ExtractsManagement.Core.ComandHandlers.Hts | ||
{ | ||
public class ExtractHtsEligibilityHandler : IRequestHandler<ExtractHtsEligibilityExtract, bool> | ||
{ | ||
private readonly IHtsEligibilityExtractSourceExtractor _patientSourceExtractor; | ||
private readonly IHtsExtractValidator _extractValidator; | ||
private readonly IHtsEligibilityExtractLoader _patientLoader; | ||
private readonly IClearHtsExtracts _clearDwhExtracts; | ||
private readonly ITempHtsEligibilityExtractRepository _tempPatientExtractRepository; | ||
private readonly IExtractHistoryRepository _extractHistoryRepository; | ||
|
||
public ExtractHtsEligibilityHandler(IHtsEligibilityExtractSourceExtractor patientSourceExtractor, IHtsExtractValidator extractValidator, IHtsEligibilityExtractLoader patientLoader, IClearHtsExtracts clearDwhExtracts, ITempHtsEligibilityExtractRepository tempPatientExtractRepository, IExtractHistoryRepository extractHistoryRepository) | ||
{ | ||
_patientSourceExtractor = patientSourceExtractor; | ||
_extractValidator = extractValidator; | ||
_patientLoader = patientLoader; | ||
_clearDwhExtracts = clearDwhExtracts; | ||
_tempPatientExtractRepository = tempPatientExtractRepository; | ||
_extractHistoryRepository = extractHistoryRepository; | ||
} | ||
|
||
public async Task<bool> Handle(ExtractHtsEligibilityExtract request, CancellationToken cancellationToken) | ||
{ | ||
|
||
//Extract | ||
int found = await _patientSourceExtractor.Extract(request.Extract, request.DatabaseProtocol); | ||
|
||
|
||
//Validate | ||
await _extractValidator.Validate(request.Extract.Id, found, "HtsEligibilityExtracts", "TempHtsEligibilityExtracts"); | ||
|
||
//Load | ||
int loaded = await _patientLoader.Load(request.Extract.Id, found, false); | ||
|
||
int rejected = | ||
_extractHistoryRepository.ProcessRejected(request.Extract.Id, found - loaded, request.Extract); | ||
|
||
|
||
_extractHistoryRepository.ProcessExcluded(request.Extract.Id, rejected, request.Extract); | ||
|
||
//notify loaded | ||
DomainEvents.Dispatch( | ||
new HtsExtractActivityNotification(request.Extract.Id, new ExtractProgress( | ||
nameof(HtsEligibilityExtract), | ||
nameof(ExtractStatus.Loaded), | ||
found, loaded, rejected, loaded, 0))); | ||
|
||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
src/Dwapi.ExtractsManagement.Core/Commands/Hts/ExtractHTSClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/Dwapi.ExtractsManagement.Core/Commands/Hts/ExtractHTSClientLinkage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/Dwapi.ExtractsManagement.Core/Commands/Hts/ExtractHTSClientPartner.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/Dwapi.ExtractsManagement.Core/Commands/Hts/ExtractHtsEligibilityScreening.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Dwapi.SharedKernel.Model; | ||
using MediatR; | ||
|
||
namespace Dwapi.ExtractsManagement.Core.Commands.Hts | ||
{ | ||
public class ExtractHtsEligibilityExtract: IRequest<bool> | ||
{ | ||
public DbExtract Extract { get; set; } | ||
public DbProtocol DatabaseProtocol { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/Dwapi.ExtractsManagement.Core/Extractors/Hts/HtsEligibilityExtractSourceExtractor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Threading.Tasks; | ||
using AutoMapper; | ||
using Dwapi.ExtractsManagement.Core.Interfaces.Extratcors.Hts; | ||
using Dwapi.ExtractsManagement.Core.Interfaces.Reader.Hts; | ||
using Dwapi.ExtractsManagement.Core.Interfaces.Repository.Hts; | ||
using Dwapi.ExtractsManagement.Core.Model.Destination.Hts.NewHts; | ||
using Dwapi.ExtractsManagement.Core.Model.Source.Hts.NewHts; | ||
using Dwapi.ExtractsManagement.Core.Notifications; | ||
using Dwapi.ExtractsManagement.Core.Profiles; | ||
using Dwapi.SharedKernel.Enum; | ||
using Dwapi.SharedKernel.Events; | ||
using Dwapi.SharedKernel.Model; | ||
using Dwapi.SharedKernel.Utility; | ||
using MediatR; | ||
using Serilog; | ||
|
||
namespace Dwapi.ExtractsManagement.Core.Extractors.Hts | ||
{ | ||
public class HtsEligibilityExtractSourceExtractor : IHtsEligibilityExtractSourceExtractor | ||
{ | ||
private readonly IHTSExtractSourceReader _reader; | ||
private readonly IMediator _mediator; | ||
private readonly ITempHtsEligibilityExtractRepository _extractRepository; | ||
|
||
public HtsEligibilityExtractSourceExtractor(IHTSExtractSourceReader reader, IMediator mediator, ITempHtsEligibilityExtractRepository extractRepository) | ||
{ | ||
_reader = reader; | ||
_mediator = mediator; | ||
_extractRepository = extractRepository; | ||
} | ||
|
||
public async Task<int> Extract(DbExtract extract, DbProtocol dbProtocol) | ||
{ | ||
var mapper = dbProtocol.SupportsDifferential ? ExtractDiffMapper.Instance : ExtractMapper.Instance; | ||
int batch = 500; | ||
|
||
DomainEvents.Dispatch(new HtsNotification(new ExtractProgress(nameof(HtsEligibilityExtract), "extracting..."))); | ||
//DomainEvents.Dispatch(new CbsStatusNotification(extract.Id,ExtractStatus.Loading)); | ||
|
||
var list = new List<TempHtsEligibilityExtract>(); | ||
|
||
int count = 0; | ||
int totalCount = 0; | ||
|
||
using (var rdr = await _reader.ExecuteReader(dbProtocol, extract)) | ||
{ | ||
while (rdr.Read()) | ||
{ | ||
totalCount++; | ||
count++; | ||
// AutoMapper profiles | ||
var extractRecord = mapper.Map<IDataRecord, TempHtsEligibilityExtract>(rdr); | ||
extractRecord.Id = LiveGuid.NewGuid(); | ||
list.Add(extractRecord); | ||
|
||
if (count == batch) | ||
{ | ||
// TODO: batch and save | ||
_extractRepository.BatchInsert(list); | ||
|
||
try | ||
{ | ||
DomainEvents.Dispatch(new HtsNotification(new ExtractProgress(nameof(HtsEligibilityExtract), "extracting...", totalCount, count, 0, 0, 0))); | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.Error(e, "Notification error"); | ||
|
||
} | ||
count = 0; | ||
list = new List<TempHtsEligibilityExtract>(); | ||
} | ||
|
||
// TODO: Notify progress... | ||
|
||
|
||
} | ||
|
||
if (count > 0) | ||
{ | ||
_extractRepository.BatchInsert(list); | ||
} | ||
_extractRepository.CloseConnection(); | ||
} | ||
|
||
try | ||
{ | ||
|
||
DomainEvents.Dispatch(new HtsNotification(new ExtractProgress(nameof(HtsEligibilityExtract), "extracted", totalCount, 0, 0, 0, 0))); | ||
DomainEvents.Dispatch(new HtsStatusNotification(extract.Id, ExtractStatus.Found, totalCount)); | ||
DomainEvents.Dispatch(new HtsStatusNotification(extract.Id, ExtractStatus.Loaded, totalCount)); | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.Error(e, "Notification error"); | ||
|
||
} | ||
|
||
return totalCount; | ||
} | ||
|
||
public Task<int> ReadExtract(DbExtract extract, DbProtocol dbProtocol) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...xtractsManagement.Core/Interfaces/Extratcors/Hts/IHtsEligibilityExtractSourceExtractor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Dwapi.ExtractsManagement.Core.Model.Source.Hts.NewHts; | ||
using Dwapi.SharedKernel.Interfaces; | ||
|
||
namespace Dwapi.ExtractsManagement.Core.Interfaces.Extratcors.Hts | ||
{ | ||
public interface IHtsEligibilityExtractSourceExtractor: ISourceExtractor<TempHtsEligibilityExtract> | ||
{ | ||
|
||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Dwapi.ExtractsManagement.Core/Interfaces/Loaders/Hts/IHtsEligibilityLoader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Dwapi.ExtractsManagement.Core.Model.Source.Hts.NewHts; | ||
|
||
namespace Dwapi.ExtractsManagement.Core.Interfaces.Loaders.Hts | ||
{ | ||
public interface IHtsEligibilityExtractLoader: ILoader<TempHtsEligibilityExtract> | ||
{ | ||
|
||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...api.ExtractsManagement.Core/Interfaces/Repository/Hts/IHtsEligibilityExtractRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Dwapi.ExtractsManagement.Core.Model.Destination.Hts.NewHts; | ||
using Dwapi.SharedKernel.Interfaces; | ||
using Dwapi.SharedKernel.Model; | ||
|
||
namespace Dwapi.ExtractsManagement.Core.Interfaces.Repository.Hts | ||
{ | ||
public interface IHtsEligibilityExtractRepository : IRepository<HtsEligibilityExtract, Guid> | ||
{ | ||
bool BatchInsert(IEnumerable<HtsEligibilityExtract> extracts); | ||
IEnumerable<HtsEligibilityExtract> GetView(); | ||
void UpdateSendStatus(List<SentItem> sentItems); | ||
} | ||
} |
Oops, something went wrong.