Skip to content

Commit

Permalink
Merge pull request #136 from palladiumkenya/dev
Browse files Browse the repository at this point in the history
NUPI and HTS
  • Loading branch information
koskedk authored Aug 18, 2022
2 parents 71d7e9b + 60583c7 commit a63dbe9
Show file tree
Hide file tree
Showing 141 changed files with 244,032 additions and 235 deletions.
1 change: 1 addition & 0 deletions src/Dwapi.Contracts/Ct/IPatient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public interface IPatient
{
string Pkv { get; set; }
string Occupation { get; set; }
string NUPI { get; set; }
}
}
3 changes: 3 additions & 0 deletions src/Dwapi.Contracts/Ct/IVisit.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

namespace Dwapi.Contracts.Ct
{
public interface IVisit
Expand Down Expand Up @@ -31,5 +33,6 @@ public interface IVisit
string Abdomen {get;set;}
string CNS {get;set;}
string Genitourinary {get;set;}
DateTime? RefillDate { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Dwapi.Contracts/Mnch/IPatientMnch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ public interface IPatientMnch
string InSchool { get; set; }
DateTime? Date_Created { get; set; }
DateTime? Date_Last_Modified { get; set; }
string NUPI { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Dwapi.Contracts/Prep/IPatientPrep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ public interface IPatientPrep
DateTime? DateLastUsedPrev { get; set; }
DateTime? Date_Created { get; set; }
DateTime? Date_Last_Modified { get; set; }
string NUPI { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public async Task Clear(List<Guid> extractIds)
DomainEvents.Dispatch(new HtsNotification(new ExtractProgress(nameof(HtsPartnerTracing) + "Extracts", "clearing...")));
DomainEvents.Dispatch(new HtsNotification(new ExtractProgress(nameof(HtsClientLinkage) + "Extracts", "clearing...")));
DomainEvents.Dispatch(new HtsNotification(new ExtractProgress(nameof(HtsClients) + "Extracts", "clearing...")));
DomainEvents.Dispatch(new HtsNotification(new ExtractProgress(nameof(HtsEligibilityExtract) + "Extracts", "clearing...")));


foreach (var extractId in extractIds)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading;
using System;
using System.Threading;
using System.Threading.Tasks;
using Dwapi.ExtractsManagement.Core.Commands.Hts;
using Dwapi.ExtractsManagement.Core.Interfaces.Extratcors.Hts;
Expand All @@ -15,6 +16,7 @@

namespace Dwapi.ExtractsManagement.Core.ComandHandlers.Hts
{
[Obsolete("No longer Used")]
public class ExtractHTSClientHandler :IRequestHandler<ExtractHTSClient,bool>
{
private readonly IHTSClientSourceExtractor _patientSourceExtractor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading;
using System;
using System.Threading;
using System.Threading.Tasks;
using Dwapi.ExtractsManagement.Core.Commands.Hts;
using Dwapi.ExtractsManagement.Core.Interfaces.Extratcors.Hts;
Expand All @@ -14,6 +15,7 @@

namespace Dwapi.ExtractsManagement.Core.ComandHandlers.Hts
{
[Obsolete("No longer Used")]
public class ExtractHTSClientLinkageHandler : IRequestHandler<ExtractHTSClientLinkage, bool>
{
private readonly IHTSClientLinkageSourceExtractor _patientAdverseEventSourceExtractor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading;
using System;
using System.Threading;
using System.Threading.Tasks;
using Dwapi.ExtractsManagement.Core.Commands.Hts;
using Dwapi.ExtractsManagement.Core.Interfaces.Extratcors.Hts;
Expand All @@ -14,6 +15,7 @@

namespace Dwapi.ExtractsManagement.Core.ComandHandlers.Hts
{
[Obsolete("No longer Used")]
public class ExtractHTSClientPartnerHandler :IRequestHandler<ExtractHTSClientPartner,bool>
{
private readonly IHTSClientPartnerSourceExtractor _patientLaboratorySourceExtractor;
Expand Down
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public async Task<bool> Handle(LoadHtsFromEmrCommand request, CancellationToken

private async Task<bool> ExtractAll(LoadHtsFromEmrCommand request, CancellationToken cancellationToken)
{
Task<bool> ClientTestTask = null, TestKitTask = null, ClientTracingTask = null, PartnerTracingTask = null, PNSTask = null, ClientLinkageTask = null;
Task<bool> ClientTestTask = null, TestKitTask = null, ClientTracingTask = null, PartnerTracingTask = null,
PNSTask = null, ClientLinkageTask = null, HtsEligibilityExtractTask = null;

// HtsClientTestExtract
var HtsClientTestExtractProfile = request.Extracts.FirstOrDefault(x => x.Extract.Name == "HtsClientTests");
Expand Down Expand Up @@ -121,9 +122,23 @@ private async Task<bool> ExtractAll(LoadHtsFromEmrCommand request, CancellationT
};
ClientLinkageTask = _mediator.Send(command, cancellationToken);
}

// HtsEligibilityExtract
var HtsEligibilityExtractProfile = request.Extracts.FirstOrDefault(x => x.Extract.Name == "HtsEligibilityExtract");
if (null != HtsEligibilityExtractProfile)
{
var command = new ExtractHtsEligibilityExtract()
{
Extract = HtsEligibilityExtractProfile?.Extract,
DatabaseProtocol = HtsEligibilityExtractProfile?.DatabaseProtocol
};
HtsEligibilityExtractTask = _mediator.Send(command, cancellationToken);
}



// await all tasks
var ts = new List<Task<bool>> { ClientTestTask, TestKitTask, ClientTracingTask, PartnerTracingTask, PNSTask, ClientLinkageTask };
var ts = new List<Task<bool>> { ClientTestTask, TestKitTask, ClientTracingTask, PartnerTracingTask, PNSTask, ClientLinkageTask, HtsEligibilityExtractTask };
var result = await Task.WhenAll(ts);

return result.All(x=>x);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Dwapi.SharedKernel.Model;
using System;
using Dwapi.SharedKernel.Model;
using MediatR;

namespace Dwapi.ExtractsManagement.Core.Commands.Hts
{
[Obsolete("No longer Used")]
public class ExtractHTSClient : IRequest<bool>
{
public DbExtract Extract { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using Dwapi.SharedKernel.Model;
using MediatR;

namespace Dwapi.ExtractsManagement.Core.Commands.Hts
{
[Obsolete("No longer Used")]
public class ExtractHTSClientLinkage : IRequest<bool>
{
public DbExtract Extract { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using Dwapi.SharedKernel.Model;
using MediatR;

namespace Dwapi.ExtractsManagement.Core.Commands.Hts
{
[Obsolete("No longer Used")]
public class ExtractHTSClientPartner : IRequest<bool>
{
public DbExtract Extract { get; set; }
Expand Down
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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace Dwapi.ExtractsManagement.Core.Extractors.Hts
{
[Obsolete]
[Obsolete("No longer Used")]
public class HTSClientSourceExtractor : IHTSClientSourceExtractor
{
private readonly IHTSExtractSourceReader _reader;
Expand Down
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();
}
}
}
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>
{

}
}
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>
{

}
}
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);
}
}
Loading

0 comments on commit a63dbe9

Please sign in to comment.