public void NoClaims()
        {
            RequestResult <MSPVisitHistoryResponse> delegateResult = new RequestResult <MSPVisitHistoryResponse>()
            {
                ResultStatus    = Common.Constants.ResultType.Success,
                PageSize        = 100,
                PageIndex       = 1,
                ResourcePayload = new MSPVisitHistoryResponse()
                {
                    Claims = null,
                }
            };

            string hdid      = "MOCKHDID";
            string ipAddress = "127.0.0.1";

            using Microsoft.Extensions.Logging.ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());

            var mockMSPDelegate = new Mock <IMSPVisitDelegate>();

            mockMSPDelegate.Setup(s => s.GetMSPVisitHistoryAsync(It.IsAny <ODRHistoryQuery>(), It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(delegateResult));

            RequestResult <PatientModel> patientResult = new RequestResult <PatientModel>()
            {
                ResultStatus    = Common.Constants.ResultType.Success,
                ResourcePayload = new PatientModel()
                {
                    PersonalHealthNumber = "912345678",
                    Birthdate            = DateTime.ParseExact("1983/07/15", "yyyy/MM/dd", CultureInfo.InvariantCulture)
                }
            };

            var mockPatientService = new Mock <IPatientService>();

            mockPatientService.Setup(s => s.GetPatient(It.IsAny <string>(), It.IsAny <PatientIdentifierType>())).Returns(Task.FromResult(patientResult));

            var mockHttpContextAccessor = new Mock <IHttpContextAccessor>();
            var context = new DefaultHttpContext()
            {
                Connection =
                {
                    RemoteIpAddress = IPAddress.Parse(ipAddress),
                },
            };

            context.Request.Headers.Add("Authorization", "MockJWTHeader");
            mockHttpContextAccessor.Setup(_ => _.HttpContext).Returns(context);


            IEncounterService service = new EncounterService(new Mock <ILogger <EncounterService> >().Object,
                                                             mockHttpContextAccessor.Object,
                                                             mockPatientService.Object,
                                                             mockMSPDelegate.Object);

            var actualResult = service.GetEncounters(hdid).Result;

            Assert.True(actualResult.ResultStatus == Common.Constants.ResultType.Success &&
                        actualResult.ResourcePayload.Count() == 0);
        }
        public void PatientError()
        {
            RequestResult <MSPVisitHistoryResponse> delegateResult = new RequestResult <MSPVisitHistoryResponse>()
            {
            };

            string hdid      = "MOCKHDID";
            string ipAddress = "127.0.0.1";

            using Microsoft.Extensions.Logging.ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());

            var mockMSPDelegate = new Mock <IMSPVisitDelegate>();

            mockMSPDelegate.Setup(s => s.GetMSPVisitHistoryAsync(It.IsAny <ODRHistoryQuery>(), It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(delegateResult));

            RequestResult <PatientModel> patientResult = new RequestResult <PatientModel>()
            {
                ResultStatus = Common.Constants.ResultType.Error,
                ResultError  = new RequestResultError()
                {
                    ErrorCode     = "Mock Error",
                    ResultMessage = "Mock Error Message",
                }
            };

            var mockPatientService = new Mock <IPatientService>();

            mockPatientService.Setup(s => s.GetPatient(It.IsAny <string>(), It.IsAny <PatientIdentifierType>())).Returns(Task.FromResult(patientResult));

            var mockHttpContextAccessor = new Mock <IHttpContextAccessor>();
            var context = new DefaultHttpContext()
            {
                Connection =
                {
                    RemoteIpAddress = IPAddress.Parse(ipAddress),
                },
            };

            context.Request.Headers.Add("Authorization", "MockJWTHeader");
            mockHttpContextAccessor.Setup(_ => _.HttpContext).Returns(context);

            IEncounterService service = new EncounterService(new Mock <ILogger <EncounterService> >().Object,
                                                             mockHttpContextAccessor.Object,
                                                             mockPatientService.Object,
                                                             mockMSPDelegate.Object);

            var actualResult = service.GetEncounters(hdid).Result;

            Assert.True(actualResult.ResultStatus == Common.Constants.ResultType.Error &&
                        actualResult.ResultError.IsDeepEqual(patientResult.ResultError));
        }
        public void ValidateEncounters()
        {
            var sameClaim = new Claim()
            {
                ClaimId          = 1,
                PractitionerName = "Mock Name 1",
                LocationName     = "Mock Name 1",
                SpecialtyDesc    = "Mocked SpecialtyDesc 1",
                ServiceDate      = DateTime.ParseExact("2000/07/15", "yyyy/MM/dd", CultureInfo.InvariantCulture),
                LocationAddress  = new LocationAddress()
                {
                    Province   = "BC",
                    City       = "Victoria",
                    PostalCode = "V6Y 0C2",
                    AddrLine1  = "NoWay",
                    AddrLine2  = "Alt"
                },
            };
            RequestResult <MSPVisitHistoryResponse> delegateResult = new RequestResult <MSPVisitHistoryResponse>()
            {
                ResultStatus    = Common.Constants.ResultType.Success,
                PageSize        = 100,
                PageIndex       = 1,
                ResourcePayload = new MSPVisitHistoryResponse()
                {
                    Claims = new List <Claim>()
                    {
                        sameClaim,
                        new Claim()
                        {
                            ClaimId          = 2,
                            PractitionerName = "Mock Name 2",
                            ServiceDate      = DateTime.ParseExact("2015/07/15", "yyyy/MM/dd", CultureInfo.InvariantCulture)
                        },
                        sameClaim,
                    },
                }
            };
            var expectedResult = EncounterModel.FromODRClaimModelList(delegateResult.ResourcePayload.Claims.ToList());

            string hdid      = "MOCKHDID";
            string ipAddress = "127.0.0.1";

            using Microsoft.Extensions.Logging.ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());

            var mockMSPDelegate = new Mock <IMSPVisitDelegate>();

            mockMSPDelegate.Setup(s => s.GetMSPVisitHistoryAsync(It.IsAny <ODRHistoryQuery>(), It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(delegateResult));

            RequestResult <PatientModel> patientResult = new RequestResult <PatientModel>()
            {
                ResultStatus    = Common.Constants.ResultType.Success,
                ResourcePayload = new PatientModel()
                {
                    PersonalHealthNumber = "912345678",
                    Birthdate            = DateTime.ParseExact("1983/07/15", "yyyy/MM/dd", CultureInfo.InvariantCulture)
                }
            };

            var mockPatientService = new Mock <IPatientService>();

            mockPatientService.Setup(s => s.GetPatient(It.IsAny <string>(), It.IsAny <PatientIdentifierType>())).Returns(Task.FromResult(patientResult));

            var mockHttpContextAccessor = new Mock <IHttpContextAccessor>();
            var context = new DefaultHttpContext()
            {
                Connection =
                {
                    RemoteIpAddress = IPAddress.Parse(ipAddress),
                },
            };

            context.Request.Headers.Add("Authorization", "MockJWTHeader");
            mockHttpContextAccessor.Setup(_ => _.HttpContext).Returns(context);


            IEncounterService service = new EncounterService(new Mock <ILogger <EncounterService> >().Object,
                                                             mockHttpContextAccessor.Object,
                                                             mockPatientService.Object,
                                                             mockMSPDelegate.Object);

            var actualResult = service.GetEncounters(hdid).Result;

            Assert.True(actualResult.ResultStatus == Common.Constants.ResultType.Success);
            Assert.Equal(2, actualResult.ResourcePayload.Count()); // should return distint claims only.
#pragma warning disable CA5351                                     // Do Not Use Broken Cryptographic Algorithms
#pragma warning disable SCS0006                                    // Weak hashing function
            using var md5CryptoService = MD5.Create();
#pragma warning restore SCS0006                                    // Weak hashing function
#pragma warning restore CA5351                                     // Do Not Use Broken Cryptographic Algorithms
            var model               = actualResult.ResourcePayload.First();
            var generatedId         = new Guid(md5CryptoService.ComputeHash(Encoding.Default.GetBytes($"{model.EncounterDate:yyyyMMdd}{model.SpecialtyDescription}{model.PractitionerName}{model.Clinic.Name}{model.Clinic.Province}{model.Clinic.City}{model.Clinic.PostalCode}{model.Clinic.AddressLine1}{model.Clinic.AddressLine2}{model.Clinic.AddressLine3}{model.Clinic.AddressLine4}")));
            var expectedGeneratedId = new Guid(md5CryptoService.ComputeHash(Encoding.Default.GetBytes($"{sameClaim.ServiceDate:yyyyMMdd}{sameClaim.SpecialtyDesc}{sameClaim.PractitionerName}{sameClaim.LocationName}{sameClaim.LocationAddress.Province}{sameClaim.LocationAddress.City}{sameClaim.LocationAddress.PostalCode}{sameClaim.LocationAddress.AddrLine1}{sameClaim.LocationAddress.AddrLine2}{sameClaim.LocationAddress.AddrLine3}{sameClaim.LocationAddress.AddrLine4}")));
            Assert.Equal(expectedGeneratedId, generatedId);
        }