diff --git a/src/In.ProjectEKA.HipService/Discovery/DiscoveryReqMap.cs b/src/In.ProjectEKA.HipService/Discovery/DiscoveryReqMap.cs index 14b1ba80..3e792a56 100644 --- a/src/In.ProjectEKA.HipService/Discovery/DiscoveryReqMap.cs +++ b/src/In.ProjectEKA.HipService/Discovery/DiscoveryReqMap.cs @@ -1,14 +1,9 @@ -using System; using System.Collections.Generic; using In.ProjectEKA.HipLibrary.Patient.Model; -using In.ProjectEKA.HipService.Common.Model; -using In.ProjectEKA.HipService.Link.Model; -using In.ProjectEKA.HipService.UserAuth.Model; -using Microsoft.AspNetCore.Http; namespace In.ProjectEKA.HipService.Discovery { public static class DiscoveryReqMap { - public static Dictionary AbhaIdentifierMap = new Dictionary(); + public static Dictionary PatientInfoMap = new Dictionary(); } } \ No newline at end of file diff --git a/src/In.ProjectEKA.HipService/Discovery/PatientController.cs b/src/In.ProjectEKA.HipService/Discovery/PatientController.cs index e3053c88..7aefbfbb 100644 --- a/src/In.ProjectEKA.HipService/Discovery/PatientController.cs +++ b/src/In.ProjectEKA.HipService/Discovery/PatientController.cs @@ -74,10 +74,9 @@ public async Task GetPatientCareContext(DiscoveryRequest request, string correla new DiscoveryResponse(request.RequestId, error == null ? HttpStatusCode.OK : HttpStatusCode.NotFound, error == null ? SuccessMessage : ErrorMessage)); - var abhaNumberIdentifier = request.Patient?.VerifiedIdentifiers.FirstOrDefault(id => id.Type == IdentifierType.NDHM_HEALTH_NUMBER); - if (!AbhaIdentifierMap.ContainsKey(patientId)) + if (!PatientInfoMap.ContainsKey(patientId)) { - AbhaIdentifierMap.Add(patientId, abhaNumberIdentifier?.Value); + PatientInfoMap.Add(patientId, request.Patient); } Log.Information("new GatewayDiscoveryRepresentation" + gatewayDiscoveryRepresentation); diff --git a/src/In.ProjectEKA.HipService/Link/LinkPatient.cs b/src/In.ProjectEKA.HipService/Link/LinkPatient.cs index a3134fbb..083b06e8 100644 --- a/src/In.ProjectEKA.HipService/Link/LinkPatient.cs +++ b/src/In.ProjectEKA.HipService/Link/LinkPatient.cs @@ -1,4 +1,6 @@ using In.ProjectEKA.HipService.OpenMrs; +using In.ProjectEKA.HipService.UserAuth; +using In.ProjectEKA.HipService.UserAuth.Model; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; @@ -26,6 +28,7 @@ public class LinkPatient private readonly IPatientVerification patientVerification; private readonly ReferenceNumberGenerator referenceNumberGenerator; private readonly IOpenMrsClient openMrsClient; + private readonly IUserAuthService userAuthService; public LinkPatient( ILinkPatientRepository linkPatientRepository, @@ -34,7 +37,7 @@ public LinkPatient( ReferenceNumberGenerator referenceNumberGenerator, IDiscoveryRequestRepository discoveryRequestRepository, IOptions otpService, - IOpenMrsClient openMrsClient) + IOpenMrsClient openMrsClient, IUserAuthService userAuthService) { this.linkPatientRepository = linkPatientRepository; this.patientRepository = patientRepository; @@ -43,6 +46,7 @@ public LinkPatient( this.discoveryRequestRepository = discoveryRequestRepository; this.otpService = otpService; this.openMrsClient = openMrsClient; + this.userAuthService = userAuthService; } public virtual async Task> LinkPatients( @@ -165,9 +169,13 @@ public virtual async Task SaveLinkedAccounts(LinkEnquires linkEnquires,string pat (patientUuid!=null?Guid.Parse(patientUuid): Guid.Empty) ) .ConfigureAwait(false); - LinkAbhaIdentifier(patientUuid, linkEnquires.ConsentManagerUserId); + return linkedAccount.HasValue; } private async void LinkAbhaIdentifier(string patientUuid, string abhaAddress) { - var abhaNumber = AbhaIdentifierMap[abhaAddress]; - var json = JsonConvert.SerializeObject(new PatientAbhaIdentifier(abhaNumber, abhaAddress), new JsonSerializerSettings + var patient = PatientInfoMap[abhaAddress]; + var abhaNumberIdentifier = patient?.VerifiedIdentifiers.FirstOrDefault(id => id.Type == IdentifierType.NDHM_HEALTH_NUMBER); + var json = JsonConvert.SerializeObject(new PatientAbhaIdentifier(abhaNumberIdentifier?.Value, abhaAddress), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, ContractResolver = new DefaultContractResolver @@ -207,6 +216,15 @@ private async void LinkAbhaIdentifier(string patientUuid, string abhaAddress) json ) .ConfigureAwait(false); + string content = await resp.Content.ReadAsStringAsync(); + if (content.Equals("true")) + { + if (patient != null) + { + var ndhmDemographics = new NdhmDemographics(abhaAddress, patient.Name, patient.Gender.ToString(), patient.YearOfBirth.ToString(), patient.VerifiedIdentifiers.FirstOrDefault(id => id.Type == IdentifierType.MOBILE)?.Value); + await userAuthService.Dump(ndhmDemographics); + } + } if (!resp.IsSuccessStatusCode) Log.Error("Errored in linking the abha identifier to the patient"); } diff --git a/test/In.ProjectEKA.HipServiceTest/Link/LinkControllerTest.cs b/test/In.ProjectEKA.HipServiceTest/Link/LinkControllerTest.cs index 21c5eef0..19aea6e6 100644 --- a/test/In.ProjectEKA.HipServiceTest/Link/LinkControllerTest.cs +++ b/test/In.ProjectEKA.HipServiceTest/Link/LinkControllerTest.cs @@ -25,7 +25,7 @@ public class LinkControllerTest public LinkControllerTest() { - link = new Mock(MockBehavior.Strict, null, null, null, null, null, null, null); + link = new Mock(MockBehavior.Strict, null, null, null, null, null, null, null, null); discoveryRequestRepository = new Mock(); var gatewayClient = new Mock(MockBehavior.Strict, null, null); diff --git a/test/In.ProjectEKA.HipServiceTest/Link/LinkPatientTest.cs b/test/In.ProjectEKA.HipServiceTest/Link/LinkPatientTest.cs index cbd724bb..d27b6956 100644 --- a/test/In.ProjectEKA.HipServiceTest/Link/LinkPatientTest.cs +++ b/test/In.ProjectEKA.HipServiceTest/Link/LinkPatientTest.cs @@ -1,6 +1,7 @@ using System.Net; using System.Net.Http; using In.ProjectEKA.HipService.OpenMrs; +using In.ProjectEKA.HipService.UserAuth; namespace In.ProjectEKA.HipServiceTest.Link { @@ -49,6 +50,7 @@ public class LinkPatientTest private readonly Mock patientVerification = new Mock(); private readonly Mock guidGenerator = new Mock(); private readonly Mock openmrsClient = new Mock(); + private readonly Mock userAuthService = new Mock(); public LinkPatientTest() { @@ -60,7 +62,8 @@ public LinkPatientTest() guidGenerator.Object, discoveryRequestRepository.Object, otpServiceConfigurations, - openmrsClient.Object); + openmrsClient.Object, + userAuthService.Object); } [Fact] @@ -217,7 +220,15 @@ private async void SuccessLinkPatientForValidOtp() var testLinkedAccounts = new LinkedAccounts(testLinkRequest.PatientReferenceNumber, testLinkRequest.LinkReferenceNumber, testLinkRequest.ConsentManagerUserId, It.IsAny(), new[] {programRefNo}.ToList(),It.IsAny()); - DiscoveryReqMap.AbhaIdentifierMap.Add(testLinkRequest.ConsentManagerUserId, "1234567891011" ); + var patientEnquiry = + new PatientEnquiry( + "id", verifiedIdentifiers: new List() + { + new Identifier(IdentifierType.MOBILE, "9999999999"), + new Identifier(IdentifierType.NDHM_HEALTH_NUMBER, "123456718910") + }, unverifiedIdentifiers: null, + "name", HipLibrary.Patient.Model.Gender.M, 2000); + DiscoveryReqMap.PatientInfoMap.Add(testLinkRequest.ConsentManagerUserId, patientEnquiry); patientVerification.Setup(e => e.Verify(sessionId, otpToken)) .ReturnsAsync((OtpMessage) null); linkRepository.Setup(e => e.GetPatientFor(sessionId))