Example #1
0
        public void CreateExaminationQuerySuccessReturnsExamination()
        {
            // Arrange
            var examination                = new MedicalExaminer.Models.Examination();
            var connectionSettings         = new Mock <IExaminationConnectionSettings>();
            var locationConnectionSettings = new Mock <ILocationConnectionSettings>();
            var myUser = new Mock <MeUser>();
            CreateExaminationQuery query = new CreateExaminationQuery(examination, myUser.Object);
            var dbAccess        = new Mock <IDatabaseAccess>();
            var location        = new MedicalExaminer.Models.Location();
            var locationService = new Mock <LocationIdService>(dbAccess.Object, locationConnectionSettings.Object);

            locationService.Setup(x => x.Handle(It.IsAny <LocationRetrievalByIdQuery>())).Returns(Task.FromResult(location));
            dbAccess.Setup(db => db.CreateItemAsync(
                               connectionSettings.Object,
                               examination,
                               false)).Returns(Task.FromResult(examination)).Verifiable();
            var sut = new CreateExaminationService(dbAccess.Object, connectionSettings.Object, locationService.Object, _urgencySettingsMock.Object);

            // Act
            var result = sut.Handle(query);

            // Assert
            dbAccess.Verify(db => db.CreateItemAsync(connectionSettings.Object, examination, false), Times.Once);
            Assert.NotNull(result.Result);
            Assert.Equal(myUser.Object.UserId, result.Result.LastModifiedBy);
        }
Example #2
0
        public void CreateEventOnExaminationWithNoUrgencyIndicatorsSuccessReturnsExaminationWithUrgencyScoreZero()
        {
            // Arrange
            var examination = new MedicalExaminer.Models.Examination()
            {
                ChildPriority    = false,
                CoronerPriority  = false,
                CulturalPriority = false,
                FaithPriority    = false,
                OtherPriority    = false,
                CreatedAt        = DateTime.Now.AddDays(-3)
            };
            var theEvent           = new Mock <OtherEvent>(); // only other event has been implemented so far.
            var connectionSettings = new Mock <IExaminationConnectionSettings>();
            var query = new CreateEventQuery("1", theEvent.Object);

            theEvent.Object.UserId = "a";
            var dbAccess = new Mock <IDatabaseAccess>();

            dbAccess.Setup(db => db.GetItemByIdAsync <MedicalExaminer.Models.Examination>(connectionSettings.Object,
                                                                                          It.IsAny <string>()))
            .Returns(Task.FromResult(examination)).Verifiable();

            dbAccess.Setup(db => db.UpdateItemAsync(connectionSettings.Object,
                                                    It.IsAny <MedicalExaminer.Models.Examination>())).Returns(Task.FromResult(examination)).Verifiable();

            var sut = new CreateEventService(dbAccess.Object, connectionSettings.Object, _urgencySettingsMock.Object);

            // Act
            var result = sut.Handle(query);

            // Assert
            examination.IsUrgent().Should().BeFalse();
            examination.LastModifiedBy.Should().Be("a");
        }
        public void PatientDetailsUpdateQuerySuccessReturnsExaminationId()
        {
            // Arrange
            var examination        = new MedicalExaminer.Models.Examination();
            var patientDetails     = new Mock <MedicalExaminer.Models.PatientDetails>();
            var connectionSettings = new Mock <IExaminationConnectionSettings>();
            var user = new Mock <MeUser>();

            var query    = new PatientDetailsUpdateQuery("a", patientDetails.Object, user.Object, _locationPath);
            var dbAccess = new Mock <IDatabaseAccess>();
            var locationConnectionSettings = new Mock <ILocationConnectionSettings>();
            var location        = new MedicalExaminer.Models.Location();
            var locationService = new Mock <LocationIdService>(dbAccess.Object, locationConnectionSettings.Object);

            locationService.Setup(x => x.Handle(It.IsAny <LocationRetrievalByIdQuery>())).Returns(Task.FromResult(location));
            dbAccess.Setup(db => db.GetItemAsync(connectionSettings.Object,
                                                 It.IsAny <Expression <Func <MedicalExaminer.Models.Examination, bool> > >()))
            .Returns(Task.FromResult(examination)).Verifiable();
            dbAccess.Setup(db => db.UpdateItemAsync(connectionSettings.Object,
                                                    It.IsAny <MedicalExaminer.Models.Examination>())).Returns(Task.FromResult(examination)).Verifiable();
            var sut = new PatientDetailsUpdateService(dbAccess.Object, connectionSettings.Object, Mapper, locationService.Object, _urgencySettingsMock.Object);

            // Act
            var result = sut.Handle(query);

            // Assert
            dbAccess.Verify(
                db => db.UpdateItemAsync(
                    connectionSettings.Object,
                    It.IsAny <MedicalExaminer.Models.Examination>()),
                Times.Once);
            Assert.NotNull(result.Result);
        }
Example #4
0
        public void CreateEventQuerySuccessReturnsEventId()
        {
            // Arrange
            var examination        = new MedicalExaminer.Models.Examination();
            var theEvent           = new Mock <OtherEvent>(); // only other event has been implemented so far.
            var connectionSettings = new Mock <IExaminationConnectionSettings>();
            var query = new CreateEventQuery("1", theEvent.Object);

            theEvent.Object.UserId = "a";
            var dbAccess = new Mock <IDatabaseAccess>();

            dbAccess.Setup(db => db.GetItemByIdAsync <MedicalExaminer.Models.Examination>(connectionSettings.Object,
                                                                                          It.IsAny <string>()))
            .Returns(Task.FromResult(examination)).Verifiable();

            dbAccess.Setup(db => db.UpdateItemAsync(connectionSettings.Object,
                                                    It.IsAny <MedicalExaminer.Models.Examination>())).Returns(Task.FromResult(examination)).Verifiable();

            var sut = new CreateEventService(dbAccess.Object, connectionSettings.Object, _urgencySettingsMock.Object);

            // Act
            var result = sut.Handle(query);

            // Assert
            dbAccess.Verify(db => db.UpdateItemAsync(connectionSettings.Object,
                                                     It.IsAny <MedicalExaminer.Models.Examination>()), Times.Once);

            Assert.NotNull(result.Result);
            Assert.Equal("a", examination.LastModifiedBy);
        }
        public void Send_Coroner_Referral_Sets_CoronerReferralSent_To_True_And_Returns_ExaminationID()
        {
            // Arrange
            var examinationId = Guid.NewGuid().ToString();
            var examination   = new MedicalExaminer.Models.Examination
            {
                ExaminationId     = examinationId,
                ScrutinyConfirmed = false
            };
            var connectionSettings = new Mock <IExaminationConnectionSettings>();
            var query    = new CoronerReferralQuery(examinationId, new MeUser());
            var dbAccess = new Mock <IDatabaseAccess>();

            dbAccess.Setup(db => db.GetItemByIdAsync <MedicalExaminer.Models.Examination>(
                               connectionSettings.Object,
                               It.IsAny <string>()))
            .Returns(Task.FromResult(examination)).Verifiable();

            dbAccess.Setup(db => db.UpdateItemAsync(
                               connectionSettings.Object,
                               It.IsAny <MedicalExaminer.Models.Examination>())).Returns(Task.FromResult(examination)).Verifiable();

            var sut = new CoronerReferralService(dbAccess.Object, connectionSettings.Object, _urgencySettingsMock.Object);

            // Act
            var result = sut.Handle(query);

            // Assert
            Assert.NotNull(result.Result);
            Assert.True(examination.CoronerReferralSent);
            Assert.Equal(examinationId, result.Result);
        }
        public async void UpdateMedicalTeamOfExaminationWithNoUrgencyIndicatorsThenIsUrgentShouldBeFalse()
        {
            // Arrange
            var examination = new MedicalExaminer.Models.Examination
            {
                ChildPriority    = false,
                CoronerPriority  = false,
                CulturalPriority = false,
                FaithPriority    = false,
                OtherPriority    = false,
                CreatedAt        = DateTime.Now.AddDays(-3)
            };
            const string userA = "a";
            var          user  = new MeUser();
            var          userRetrievalByIdService = new Mock <IAsyncQueryHandler <UserRetrievalByIdQuery, MeUser> >();

            userRetrievalByIdService.Setup(x => x.Handle(It.IsAny <UserRetrievalByIdQuery>())).Returns(Task.FromResult(user));

            var connectionSettings = new Mock <IExaminationConnectionSettings>();
            var dbAccess           = new Mock <IDatabaseAccess>();

            dbAccess.Setup(db => db.UpdateItemAsync(connectionSettings.Object, examination))
            .Returns(Task.FromResult(examination));
            var sut = new MedicalTeamUpdateService(dbAccess.Object, connectionSettings.Object, userRetrievalByIdService.Object, _urgencySettingsMock.Object);

            // Act
            var result = await sut.Handle(examination, userA);

            // Assert
            result.IsUrgent().Should().BeFalse();
            result.LastModifiedBy.Should().Be(userA);
        }
        public async void ExaminationFound_ReturnsExaminationId()
        {
            // Arrange
            var examinationId = "1";
            var examination1  = new MedicalExaminer.Models.Examination
            {
                ExaminationId = examinationId
            };

            var connectionSettings = new Mock <IExaminationConnectionSettings>();

            var dbAccess = new Mock <IDatabaseAccess>();
            var user     = new MeUser();
            var userRetrievalByIdService = new Mock <IAsyncQueryHandler <UserRetrievalByIdQuery, MeUser> >();

            userRetrievalByIdService.Setup(x => x.Handle(It.IsAny <UserRetrievalByIdQuery>())).Returns(Task.FromResult(user));

            dbAccess.Setup(db => db.UpdateItemAsync(connectionSettings.Object, examination1))
            .Returns(Task.FromResult(examination1));
            var sut = new MedicalTeamUpdateService(dbAccess.Object, connectionSettings.Object, userRetrievalByIdService.Object, _urgencySettingsMock.Object);

            // Act
            var result = await sut.Handle(examination1, "a");

            // Assert
            Assert.Equal(examinationId, result.ExaminationId);
            Assert.Equal("a", result.LastModifiedBy);
        }
        public async void UpdateMedicalTeamOfExamination_SetsFullName_WhenMeUserIdIsEmpty()
        {
            // Arrange
            const string medicalExaminerUserId        = "";
            const string medicalExaminerOfficerUserId = "";

            var examination = new MedicalExaminer.Models.Examination
            {
                ChildPriority    = true,
                CoronerPriority  = true,
                CulturalPriority = true,
                FaithPriority    = true,
                OtherPriority    = true,
                CreatedAt        = DateTime.Now.AddDays(-3),
                MedicalTeam      = new MedicalExaminer.Models.MedicalTeam
                {
                    MedicalExaminerUserId        = medicalExaminerUserId,
                    MedicalExaminerOfficerUserId = medicalExaminerOfficerUserId
                }
            };

            var userRetrievalByIdService = new Mock <IAsyncQueryHandler <UserRetrievalByIdQuery, MeUser> >(MockBehavior.Strict);
            var connectionSettings       = new Mock <IExaminationConnectionSettings>(MockBehavior.Strict);
            var dbAccess = new Mock <IDatabaseAccess>(MockBehavior.Strict);

            userRetrievalByIdService
            .Setup(x => x.Handle(It.Is <UserRetrievalByIdQuery>(query => query.UserId == medicalExaminerUserId)))
            .Returns(Task.FromResult(new MeUser
            {
                FirstName = null,
                LastName  = null
            }));
            userRetrievalByIdService
            .Setup(x => x.Handle(It.Is <UserRetrievalByIdQuery>(query => query.UserId == medicalExaminerOfficerUserId)))
            .Returns(Task.FromResult(new MeUser
            {
                FirstName = null,
                LastName  = null
            }));

            dbAccess
            .Setup(db => db.UpdateItemAsync(connectionSettings.Object, examination))
            .Returns(Task.FromResult(examination));

            var sut = new MedicalTeamUpdateService(
                dbAccess.Object,
                connectionSettings.Object,
                userRetrievalByIdService.Object,
                _urgencySettingsMock.Object);

            // Act
            var result = await sut.Handle(examination, "a");

            // Assert
            result.MedicalTeam.MedicalExaminerFullName.Should().BeNull();
            result.MedicalTeam.MedicalExaminerOfficerFullName.Should().BeNull();
            result.MedicalTeam.MedicalExaminerGmcNumber.Should().BeNull();
            result.MedicalTeam.MedicalExaminerOfficerGmcNumber.Should().BeNull();
        }
        public void PatientDetailsUpdateOnExaminationWithAllUrgencyIndicatorsSuccessReturnsExaminationWithIsUrgentTrue()
        {
            // Arrange
            var examination = new MedicalExaminer.Models.Examination()
            {
                ChildPriority    = true,
                CoronerPriority  = true,
                CulturalPriority = true,
                FaithPriority    = true,
                OtherPriority    = true,
                CreatedAt        = DateTime.Now.AddDays(-3)
            };
            var patientDetails = new MedicalExaminer.Models.PatientDetails()
            {
                ChildPriority    = true,
                CoronerPriority  = true,
                CulturalPriority = true,
                FaithPriority    = true,
                OtherPriority    = true,
            };

            const string userId = "userId";
            var          user   = new MeUser()
            {
                UserId = userId,
            };

            var connectionSettings = new Mock <IExaminationConnectionSettings>();

            var query    = new PatientDetailsUpdateQuery("a", patientDetails, user, _locationPath);
            var dbAccess = new Mock <IDatabaseAccess>();
            var locationConnectionSettings = new Mock <ILocationConnectionSettings>();
            var location        = new MedicalExaminer.Models.Location();
            var locationService = new Mock <LocationIdService>(dbAccess.Object, locationConnectionSettings.Object);

            locationService.Setup(x => x.Handle(It.IsAny <LocationRetrievalByIdQuery>())).Returns(Task.FromResult(location));
            dbAccess.Setup(db => db.GetItemAsync(connectionSettings.Object,
                                                 It.IsAny <Expression <Func <MedicalExaminer.Models.Examination, bool> > >()))
            .Returns(Task.FromResult(examination)).Verifiable();
            dbAccess.Setup(db => db.UpdateItemAsync(connectionSettings.Object,
                                                    It.IsAny <MedicalExaminer.Models.Examination>())).Returns(Task.FromResult(examination)).Verifiable();
            var sut = new PatientDetailsUpdateService(dbAccess.Object, connectionSettings.Object, Mapper, locationService.Object, _urgencySettingsMock.Object);

            // Act
            var result = sut.Handle(query);

            // Assert
            result.Result.IsUrgent().Should().BeTrue();
            result.Result.LastModifiedBy.Should().Be(userId);
        }
Example #10
0
        public void Save_Outstanding_Case_Items_When_Scrutiny_Is_Confirmed_Returns_ExaminationID()
        {
            // Arrange
            var examinationId = Guid.NewGuid().ToString();
            var examination   = new MedicalExaminer.Models.Examination
            {
                ExaminationId = examinationId,
                MedicalTeam   = new MedicalExaminer.Models.MedicalTeam()
                {
                    MedicalExaminerOfficerUserId = "MedicalExaminerOfficerUserId",
                    MedicalExaminerUserId        = "MedicalExaminerUserId"
                },
                ScrutinyConfirmed = true
            };
            var connectionSettings = new Mock <IExaminationConnectionSettings>();
            var caseOutcome        = new MedicalExaminer.Models.CaseOutcome
            {
                MccdIssued          = true,
                CremationFormStatus = CremationFormStatus.Yes,
                GpNotifiedStatus    = GPNotified.GPNotified
            };
            var query    = new SaveOutstandingCaseItemsQuery(examinationId, caseOutcome, new MeUser());
            var dbAccess = new Mock <IDatabaseAccess>();

            dbAccess.Setup(db => db.GetItemByIdAsync <MedicalExaminer.Models.Examination>(
                               connectionSettings.Object,
                               It.IsAny <string>()))
            .Returns(Task.FromResult(examination)).Verifiable();

            dbAccess.Setup(db => db.UpdateItemAsync(
                               connectionSettings.Object,
                               It.IsAny <MedicalExaminer.Models.Examination>())).Returns(Task.FromResult(examination)).Verifiable();

            var sut = new SaveOutstandingCaseItemsService(dbAccess.Object, connectionSettings.Object, _urgencySettingsMock.Object);

            // Act
            var result = sut.Handle(query);

            // Assert
            Assert.NotNull(result.Result);
            Assert.True(examination.OutstandingCaseItemsCompleted);
            Assert.Equal(examinationId, result.Result);
        }
Example #11
0
        public void CreateExaminationQueryWithNoUrgencyIndicatorsSuccessReturnsExaminationWithIsUrgentFalse()
        {
            // Arrange
            var examination = new MedicalExaminer.Models.Examination()
            {
                ChildPriority    = false,
                CoronerPriority  = false,
                CulturalPriority = false,
                FaithPriority    = false,
                OtherPriority    = false,
                CreatedAt        = DateTime.Now.AddDays(-3)
            };

            var userId = "userId";
            var user   = new MeUser()
            {
                UserId = userId
            };
            var connectionSettings       = new Mock <IExaminationConnectionSettings>();
            CreateExaminationQuery query = new CreateExaminationQuery(examination, user);
            var dbAccess = new Mock <IDatabaseAccess>();
            var locationConnectionSettings = new Mock <ILocationConnectionSettings>();
            var location        = new MedicalExaminer.Models.Location();
            var locationService = new Mock <LocationIdService>(dbAccess.Object, locationConnectionSettings.Object);

            locationService.Setup(x => x.Handle(It.IsAny <LocationRetrievalByIdQuery>())).Returns(Task.FromResult(location));

            dbAccess.Setup(db => db.CreateItemAsync(
                               connectionSettings.Object,
                               examination,
                               false)).Returns(Task.FromResult(examination)).Verifiable();
            var sut = new CreateExaminationService(dbAccess.Object, connectionSettings.Object, locationService.Object, _urgencySettingsMock.Object);

            // Act
            var result = sut.Handle(query);

            // Assert
            result.Result.Should().NotBeNull();
            result.Result.IsUrgent().Should().BeFalse();
            result.Result.LastModifiedBy.Should().Be(user.UserId);
        }
Example #12
0
        public void Confirmation_Of_Scrutiny_Marks_ScrutinyConfirmed_To_True_And_Returns_ScrutinyConfirmedOn_DateTime()
        {
            // Arrange
            var examinationId = Guid.NewGuid().ToString();
            var caseOutcome   = new MedicalExaminer.Models.CaseOutcome
            {
                ScrutinyConfirmedOn = null
            };
            var examination = new MedicalExaminer.Models.Examination
            {
                ExaminationId     = examinationId,
                ScrutinyConfirmed = false,
                CaseOutcome       = caseOutcome
            };
            var connectionSettings = new Mock <IExaminationConnectionSettings>();
            var query    = new ConfirmationOfScrutinyQuery(examinationId, new MeUser());
            var dbAccess = new Mock <IDatabaseAccess>();

            dbAccess.Setup(db => db.GetItemByIdAsync <MedicalExaminer.Models.Examination>(
                               connectionSettings.Object,
                               It.IsAny <string>()))
            .Returns(Task.FromResult(examination)).Verifiable();

            dbAccess.Setup(db => db.UpdateItemAsync(
                               connectionSettings.Object,
                               It.IsAny <MedicalExaminer.Models.Examination>())).Returns(Task.FromResult(examination)).Verifiable();

            var sut = new ConfirmationOfScrutinyService(dbAccess.Object, connectionSettings.Object, _urgencySettingsMock.Object);

            // Act
            var result = sut.Handle(query);

            // Assert
            Assert.NotNull(result.Result);
            Assert.True(examination.ScrutinyConfirmed);
            Assert.NotNull(examination.CaseOutcome.ScrutinyConfirmedOn);
        }
Example #13
0
        public void Close_Case_When_Outstanding_Case_Items_Completed_Marks_Examination_Completed_And_Returns_ExaminationID()
        {
            // Arrange
            var examinationId = Guid.NewGuid().ToString();
            var caseOutcome   = new MedicalExaminer.Models.CaseOutcome
            {
                CaseMedicalExaminerFullName       = "ME Full Name",
                ScrutinyConfirmedOn               = new DateTime(2019, 6, 20),
                OutcomeQapDiscussion              = QapDiscussionOutcome.MccdCauseOfDeathProvidedByQAP,
                OutcomeOfPrescrutiny              = OverallOutcomeOfPreScrutiny.IssueAnMccd,
                OutcomeOfRepresentativeDiscussion = BereavedDiscussionOutcome.CauseOfDeathAccepted,
                CaseCompleted       = false,
                CaseOutcomeSummary  = CaseOutcomeSummary.IssueMCCD,
                MccdIssued          = true,
                CremationFormStatus = CremationFormStatus.Yes,
                GpNotifiedStatus    = GPNotified.GPNotified,
                CoronerReferralSent = false
            };
            var examination = new MedicalExaminer.Models.Examination
            {
                ExaminationId                 = examinationId,
                ScrutinyConfirmed             = false,
                OutstandingCaseItemsCompleted = true,
                CaseOutcome = caseOutcome
            };
            var user = new MeUser
            {
                UserId    = "UserId",
                FirstName = "FirstName",
                LastName  = "LastName",
                GmcNumber = "GmcNumber"
            };
            var connectionSettings = new Mock <IExaminationConnectionSettings>();
            var query    = new CloseCaseQuery(examinationId, user);
            var dbAccess = new Mock <IDatabaseAccess>();

            dbAccess.Setup(db => db.GetItemByIdAsync <MedicalExaminer.Models.Examination>(
                               connectionSettings.Object,
                               It.IsAny <string>()))
            .Returns(Task.FromResult(examination)).Verifiable();

            dbAccess.Setup(db => db.UpdateItemAsync(
                               connectionSettings.Object,
                               It.IsAny <MedicalExaminer.Models.Examination>())).Returns(Task.FromResult(examination)).Verifiable();

            var sut = new CloseCaseService(dbAccess.Object, connectionSettings.Object, _urgencySettingsMock.Object);

            // Act
            var result = sut.Handle(query);

            // Assert
            Assert.NotNull(result.Result);
            Assert.True(examination.CaseCompleted);
            Assert.Equal(examinationId, result.Result);
            Assert.NotNull(examination.DateCaseClosed);
            Assert.Equal(DateTime.Now.Date, examination.DateCaseClosed.Value.Date);
            Assert.NotNull(examination.CaseBreakdown.CaseClosedEvent);
            Assert.Equal(user.FullName(), examination.CaseBreakdown.CaseClosedEvent.UserFullName);
            Assert.Equal(user.UserId, examination.CaseBreakdown.CaseClosedEvent.UserId);
            Assert.Equal(user.GmcNumber, examination.CaseBreakdown.CaseClosedEvent.GmcNumber);
        }