Ejemplo n.º 1
0
        /// <summary>
        /// Attempts to get the Patient model from the Generic Cache.
        /// </summary>
        /// <param name="identifier">The resource identifier used to determine the key to use.</param>
        /// <param name="identifierType">The type of patient identifier we are searching for.</param>
        /// <returns>The found Patient model or null.</returns>
        private PatientModel?GetFromCache(string identifier, PatientIdentifierType identifierType)
        {
            using Activity? activity = Source.StartActivity("GetFromCache");
            PatientModel?retPatient = null;

            if (this.cacheTTL > 0)
            {
                switch (identifierType)
                {
                case PatientIdentifierType.HDID:
                    this.logger.LogDebug($"Querying Patient Cache by HDID");
                    retPatient = this.cacheDelegate.GetCacheObject <PatientModel>(identifier, PatientCacheDomain);
                    break;

                case PatientIdentifierType.PHN:
                    this.logger.LogDebug($"Querying Patient Cache by PHN");
                    retPatient = this.cacheDelegate.GetCacheObjectByJSONProperty <PatientModel>("personalhealthnumber", identifier, PatientCacheDomain);
                    break;
                }

                this.logger.LogDebug($"Patient with identifier {identifier} was {(retPatient == null ? "not" : string.Empty)} found in cache");
            }

            activity?.Stop();
            return(retPatient);
        }
Ejemplo n.º 2
0
        private void GetPatient(PatientIdentifierType identifierType, Dictionary <string, string> configDictionary, Database.Constants.DBStatusCode mockDBStatusCode, bool returnValidCache = false)
        {
            RequestResult <PatientModel> requestResult = new RequestResult <PatientModel>()
            {
                ResultStatus     = Common.Constants.ResultType.Success,
                TotalResultCount = 1,
                PageSize         = 1,
                ResourcePayload  = new PatientModel()
                {
                    FirstName = "John",
                    LastName  = "Doe",
                    HdId      = hdid,
                },
            };

            Mock <IClientRegistriesDelegate> patientDelegateMock = new Mock <IClientRegistriesDelegate>();
            var config = new ConfigurationBuilder()
                         .AddInMemoryCollection(configDictionary)
                         .Build();

            patientDelegateMock.Setup(p => p.GetDemographicsByHDIDAsync(It.IsAny <string>())).ReturnsAsync(requestResult);
            patientDelegateMock.Setup(p => p.GetDemographicsByPHNAsync(It.IsAny <string>())).ReturnsAsync(requestResult);

            DBResult <GenericCache> dbResult = new DBResult <GenericCache>()
            {
                Status = mockDBStatusCode,
            };
            Mock <IGenericCacheDelegate> genericCacheDelegateMock = new Mock <IGenericCacheDelegate>();

            genericCacheDelegateMock.Setup(p => p.CacheObject(It.IsAny <object>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), true)).Returns(dbResult);
            if (returnValidCache)
            {
                genericCacheDelegateMock.Setup(p => p.GetCacheObject <PatientModel>(It.IsAny <string>(), It.IsAny <string>())).Returns(requestResult.ResourcePayload);
            }

            IPatientService service = new PatientService(
                new Mock <ILogger <PatientService> >().Object,
                config,
                patientDelegateMock.Object,
                genericCacheDelegateMock.Object);

            // Act
            RequestResult <PatientModel> actual = Task.Run(async() => await service.GetPatient(hdid, identifierType).ConfigureAwait(true)).Result;

            // Verify
            Assert.Equal(Common.Constants.ResultType.Success, actual.ResultStatus);
            Assert.Equal(hdid, actual.ResourcePayload.HdId);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PatientIdentifier"/> class.
        /// </summary>
        /// <param name="patientIdentifierType">Type of the patient identifier.</param>
        /// <param name="identifier">The identifier.</param>
        /// <param name="description">The description.</param>
        /// <param name="effectiveDateRange">The effective date range.</param>
        /// <param name="activeIndicator">The active indicator.</param>
        /// <param name="patientContact">The patient contact.</param>
        public PatientIdentifier(
            PatientIdentifierType patientIdentifierType,
            string identifier,
            string description,
            DateRange effectiveDateRange,
            bool? activeIndicator,
            PatientContact patientContact )
        {
            Check.IsNotNull ( patientIdentifierType, "Patient identifier type is required." );
            Check.IsNotNullOrWhitespace ( identifier, "Identifier is required." );

            _patientIdentifierType = patientIdentifierType;
            _identifier = identifier;
            _description = description;
            _effectiveDateRange = effectiveDateRange;
            _activeIndicator = activeIndicator;
            _patientContact = patientContact;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PatientIdentifier"/> class.
        /// </summary>
        /// <param name="patientIdentifierType">Type of the patient identifier.</param>
        /// <param name="identifier">The identifier.</param>
        /// <param name="description">The description.</param>
        /// <param name="effectiveDateRange">The effective date range.</param>
        /// <param name="activeIndicator">The active indicator.</param>
        /// <param name="patientContact">The patient contact.</param>
        public PatientIdentifier(
            PatientIdentifierType patientIdentifierType,
            string identifier,
            string description,
            DateRange effectiveDateRange,
            bool?activeIndicator,
            PatientContact patientContact)
        {
            Check.IsNotNull(patientIdentifierType, "Patient identifier type is required.");
            Check.IsNotNullOrWhitespace(identifier, "Identifier is required.");

            _patientIdentifierType = patientIdentifierType;
            _identifier            = identifier;
            _description           = description;
            _effectiveDateRange    = effectiveDateRange;
            _activeIndicator       = activeIndicator;
            _patientContact        = patientContact;
        }
Ejemplo n.º 5
0
        /// <inheritdoc/>
        public async System.Threading.Tasks.Task <RequestResult <PatientModel> > GetPatient(string identifier, PatientIdentifierType identifierType = PatientIdentifierType.HDID)
        {
            using Activity? activity = Source.StartActivity("GetPatient");
            RequestResult <PatientModel> requestResult = new RequestResult <PatientModel>();
            PatientModel?patient = this.GetFromCache(identifier, identifierType);

            if (patient == null)
            {
                switch (identifierType)
                {
                case PatientIdentifierType.HDID:
                    this.logger.LogDebug("Performing Patient lookup by HDID");
                    requestResult = await this.patientDelegate.GetDemographicsByHDIDAsync(identifier).ConfigureAwait(true);

                    break;

                case PatientIdentifierType.PHN:
                    this.logger.LogDebug("Performing Patient lookup by PHN");
                    requestResult = await this.patientDelegate.GetDemographicsByPHNAsync(identifier).ConfigureAwait(true);

                    break;

                default:
                    this.logger.LogDebug($"Failed Patient lookup unknown PatientIdentifierType");
                    requestResult.ResultStatus = ResultType.Error;
                    requestResult.ResultError  = new RequestResultError()
                    {
                        ResultMessage = $"Internal Error: PatientIdentifierType is unknown '{identifierType.ToString()}'", ErrorCode = ErrorTranslator.InternalError(ErrorType.InvalidState)
                    };
                    break;
                }

                if (requestResult.ResultStatus == ResultType.Success && requestResult.ResourcePayload != null)
                {
                    this.CachePatient(requestResult.ResourcePayload);
                }
            }
            else
            {
                this.logger.LogDebug("Patient fetched from Cache");
                requestResult.ResourcePayload = patient;
                requestResult.ResultStatus    = ResultType.Success;
            }

            activity?.Stop();
            return(requestResult);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Assigns the type of the patient identifier.
 /// </summary>
 /// <param name="patientIdentifierType">Type of the patient identifier.</param>
 /// <returns>A PatientIdentifierBuilder.</returns>
 public PatientIdentifierBuilder WithPatientIdentifierType( PatientIdentifierType patientIdentifierType )
 {
     _patientIdentifierType = patientIdentifierType;
     return this;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Assigns the type of the patient identifier.
 /// </summary>
 /// <param name="patientIdentifierType">Type of the patient identifier.</param>
 /// <returns>A PatientIdentifierBuilder.</returns>
 public PatientIdentifierBuilder WithPatientIdentifierType(PatientIdentifierType patientIdentifierType)
 {
     _patientIdentifierType = patientIdentifierType;
     return(this);
 }