public async Task <ActionResult <Patient> > GetPatientByIdAsync(Guid patientId)
        {
            if (patientId == default)
            {
                ModelState.AddModelError(nameof(patientId), "Patient Id should not be null or default");
                return(BadRequest(ModelState));
            }

            var query = new GetPatient.Query(patientId);

            return(await Mediator.Send(query));
        }
        public async Task Handle_Fetch_Should_GetPatients_Return_Empty()
        {
            // Arrange
            var query = new GetPatient.Query(Guid.NewGuid());

            var mockAppDbRepository = new Mock <IAppDbRepository>();

            mockAppDbRepository
            .Setup(x => x.GetPatientByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync((Patient)null);

            var handler = new GetPatient.Handler(mockAppDbRepository.Object);
            // Act
            // Assert
            await Assert.ThrowsAsync <NotFoundException>(() => handler.Handle(query, new CancellationToken()));
        }
        public async Task <GetPatient.Model> Handle(GetPatient.Query request, CancellationToken cancellationToken)
        {
            #region how nested Bundle was handled
            //var transaction = new TransactionBuilder(_client.Endpoint);

            //var patientById = new SearchParams()
            // .Where($"_id={request.PatientId}");

            //transaction.Search(patientById, "Patient");// went away from the transaction builder because it returned nested Bundles (which were handled successfullly, but no need to add complexity) and added an additional search to the server. Unclear if the Include method is also a serach but I should be much more effiecient. Also, not all servers support TransactionsBuilder.
            //transaction.Search(conception, "Observation");
            //var qResult = await _client.TransactionAsync(transaction.ToBundle());

            //var patBundle = (Bundle)qResult.Entry.First().Resource;
            //var pat = (Patient)patBundle.Entry.First().Resource;

            //var concpetionBundle = (Bundle)qResult.Entry[1].Resource;
            #endregion

            //var conception = new SearchParams()
            //                .Where($"subject={request.PatientId}")
            //                .Where("code=33067-0")//Fixed to ConceptionDate LOINC
            //                .LimitTo(1)//Incase there is more than one, though there shouldnt be, but I added two to the FHIR server to see what happens
            //                .Include("Observation:subject");//TODO: this will get all Observation infor from the server on Patient?

            var qResult = await client.ReadAsync <Patient>($"Patient/{request.PatientId}");

            //var conceptionObservation = (Observation)qResult.Entry[0].Resource;
            //var conceptionFhirDateTime = (FhirDateTime)conceptionObservation.Value;
            //var pat = (Patient)qResult.Entry[1].Resource;

            //Create map from FHIR Patient to your Patient.
            //Decided to see what it would be like if my Patient type inheirited FHIRs.
            var modelPatient = new LockStepPatient()
            {
                FhirPatient = qResult,
                LastName    = qResult.Name[0].Family,
            };
            modelPatient.GivenNames.AddRange(qResult.Name.SelectMany(n => n.GivenElement.Select(nm => nm.Value)));
            modelPatient.DateOfBirth = qResult.BirthDateElement.ToDateTimeOffset();
            return(new GetPatient.Model()
            {
                QueriedPatient = modelPatient
            });
        }
示例#4
0
        public async Task <GetPatient.Model> Handle(GetPatient.Query request, CancellationToken cancellationToken)
        {
            var qResult = await client.ReadAsync <Patient>($"Patient/{request.PatientId}");

            //Create map from FHIR Patient to your Patient.
            //Decided to see what it would be like if my Patient type inheirited FHIRs.
            var modelPatient = new LockStepPatient()
            {
                FhirPatient = qResult,
                LastName    = qResult.Name[0].Family,
            };

            modelPatient.GivenNames.AddRange(qResult.Name.SelectMany(n => n.GivenElement.Select(nm => nm.Value)));
            modelPatient.DateOfBirth = qResult.BirthDateElement.ToDateTimeOffset();
            return(new GetPatient.Model()
            {
                QueriedPatient = modelPatient
            });
        }
        public async Task Handle_Fetch_Should_GetPatient_Return_Hospital()
        {
            // Arrange
            var patientId = Guid.NewGuid();
            var query     = new GetPatient.Query(patientId);
            var patient   = new Patient
            {
                PatientId = patientId,
                Address   = new Address()
            };

            var mockAppDbRepository = new Mock <IAppDbRepository>();

            mockAppDbRepository
            .Setup(x => x.GetPatientByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(patient);

            var handler = new GetPatient.Handler(mockAppDbRepository.Object);
            // Act
            var result = await handler.Handle(query, new CancellationToken());

            // Assert
            Assert.Equal(patientId, result.Id);
        }