public void GetOpenQueries()
        {
            //Arrange
            var dataStorage = new Mock<IDataStorage>();
            var clinic = new Clinic {Caption = "Clinic1"};
            var doctor1 = new User {FirstName = "DoctorFirst1", LastName = "DoctorLast1", Clinic = clinic};
            var doctor2 = new User {FirstName = "DoctorFirst2", LastName = "DoctorLast2", Clinic = clinic};
            var patient1 = new Patient {PatientNumber = 11, Doctor = doctor1};
            var patient2 = new Patient {PatientNumber = 12, Doctor = doctor2};
            var visit1 = new Visit {Caption = "Visit1", Patient = patient1};
            var visit2 = new Visit {Caption = "Visit2", Patient = patient2};
            var form1 = new Form {FormType = FormType.Happiness, Visit = visit1};
            var form2 = new Form {FormType = FormType.Demographics, Visit = visit2};
            var question1 = new Question {Form = form1};
            var question2 = new Question {Form = form2};
            var query1 = new Query {Id = 1, QueryText = "Text1", Question = question1};
            var query2 = new Query {Id = 2, QueryText = "Text2", AnswerText = "Answer1", Question = question2};

            var repository = new QueryRepository(dataStorage.Object);
            dataStorage.Setup(ds => ds.GetData<Query>()).Returns(new List<Query> {query1, query2});

            //Act
            var result = repository.GetOpenQueries();

            //Assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result.Count(), Is.EqualTo(1));
            var query = result.ToList()[0];
            Assert.That(query.FormType, Is.EqualTo(FormType.Happiness));
            Assert.That(query.ClinicName, Is.EqualTo("Clinic1"));
            Assert.That(query.DoctorName, Is.EqualTo("DoctorLast1"));
            Assert.That(query.QuestionText, Is.EqualTo("Text1"));
            Assert.That(query.PatientNumber, Is.EqualTo(11));
            Assert.That(query.VisitName, Is.EqualTo("Visit1"));
        }
        public void GetSingleUserByLoginTest()
        {
            //Arrange
            Mock<IDataStorage> dataStorage = new Mock<IDataStorage>();
            UserRepository repository = new UserRepository(dataStorage.Object);
            User user1 = new User() {Login = "******"};
            dataStorage.Setup(ds => ds.GetData<User>()).Returns(new List<User> {user1});

            //Act
            var result = repository.GetUserByLogin("login1");
            //Assert
            Assert.That(result, Is.EqualTo(user1));
        }
 public void CreatePatient_PatientVisitsVerification()
 {
     //Arrange
     var doctor = new User() {Id = 15, Role = ClinicalStudyRoles.Doctor, Patients = new List<Patient>()};
     //Act
     var result = studyDesign.CreatePatient(doctor);
     //Assert
     Assert.That(result, Is.Not.Null, "Patient was created");
     Assert.That(result.Visits, Is.Not.Null, "Visits were not created");
     Assert.That(result.Visits.Count, Is.EqualTo(3));
     Assert.That(result.Visits.Any(v => v.VisitType == VisitType.Baseline), "Baseline visit was not scheduled");
     Assert.That(result.Visits.Any(v => v.VisitType == VisitType.Day1), "1st Day visist was not scheduled");
     Assert.That(result.Visits.Any(v => v.VisitType == VisitType.Day10), "10th Day visist was not scheduled");
 }
 public void CreatePatient_PatientVerification()
 {
     //Arrange
     var doctor = new User() {Id = 15, Role = ClinicalStudyRoles.Doctor, Patients = new List<Patient>()};
     //Act
     var result = studyDesign.CreatePatient(doctor);
     //Assert
     Assert.That(result, Is.Not.Null, "Patient was created");
     Assert.That(result.Doctor, Is.Not.Null);
     Assert.That(result.Doctor.Id, Is.EqualTo(doctor.Id));
     Assert.That(doctor.Patients.Exists(p => p.Id == result.Id), "Clinic patients list does not include created patient");
 }
        public void CreatePatient_Day1VisitVerification()
        {
            //Arrange
            var doctor = new User() {Id = 15, Role = ClinicalStudyRoles.Doctor, Patients = new List<Patient>()};
            //Act
            var result = studyDesign.CreatePatient(doctor);
            //Assert
            Assert.That(result, Is.Not.Null, "Patient was created");
            Assert.That(result.Visits, Is.Not.Null, "Visits were not created");
            var visit = result.Visits.FirstOrDefault(v => v.VisitType == VisitType.Day1);
            Assert.That(visit, Is.Not.Null, "1st Day visit was not scheduled");

            Assert.That(visit.Caption, Is.EqualTo("1st Day"));
            Assert.That(visit.ExpectedVisitDate, Is.EqualTo(DateTime.Now.Date.AddDays(2)));
            Assert.That(visit.OrderNo, Is.EqualTo(1));
            Assert.That(visit.Patient, Is.Not.Null);
            Assert.That(visit.VisitDate, Is.Null);
            Assert.That(visit.VisitTime, Is.Null);
            Assert.That(visit.Forms, Is.Not.Null);
            visitRepository.Verify(r => r.Add(visit), Times.Once());
        }
        public void CreatePatient_BaselineVisit_FormsVerification()
        {
            //Arrange
            var doctor = new User() {Id = 15, Role = ClinicalStudyRoles.Doctor, Patients = new List<Patient>()};
            var vitalsFormDatas = new List<VitalsFormData>();
            var demogFormDatas = new List<DemographicFormData>();
            vitalsFormDataRepository
                .Setup(r => r.Add(It.IsAny<VitalsFormData>()))
                .Callback<VitalsFormData>(data => vitalsFormDatas.Add(data));
            demogFormDataRepository
                .Setup(r => r.Add(It.IsAny<DemographicFormData>()))
                .Callback<DemographicFormData>(data => demogFormDatas.Add(data));

            //Act
            var result = studyDesign.CreatePatient(doctor);
            //Assert
            Assert.That(result, Is.Not.Null, "Patient was created");
            Assert.That(result.Visits, Is.Not.Null, "Visits were not created");
            var visit = result.Visits.FirstOrDefault(v => v.VisitType == VisitType.Baseline);
            Assert.That(visit, Is.Not.Null, "Baseline visit was not scheduled");
            Assert.That(visit.Forms, Is.Not.Null, "Forms were not created");

            //demographics CRF
            var demographicsForm = visit.Forms.FirstOrDefault(f => f.FormType == FormType.Demographics);
            Assert.That(demographicsForm, Is.Not.Null);
            Assert.That(demographicsForm.Caption, Is.EqualTo("Demographics"));
            Assert.That(demographicsForm.FormState, Is.EqualTo(FormState.Incomplete));
            Assert.That(demographicsForm.FormType, Is.EqualTo(FormType.Demographics));
            Assert.That(demographicsForm.OrderNo, Is.EqualTo(0));
            formRepository.Verify(r => r.Add(demographicsForm), Times.Once());

            var demogFormData = demogFormDatas.FirstOrDefault(data => data.Form == demographicsForm);
            Assert.That(demogFormData, Is.Not.Null);
            Assert.That(demogFormData.DateOfBirth, Is.Not.Null);
            Assert.That(demogFormData.Race, Is.Not.Null);
            Assert.That(demogFormData.Sex, Is.Not.Null);
            Assert.That(demogFormData.Other, Is.Not.Null);

            //vitals CRF
            var vitalsForm = visit.Forms.FirstOrDefault(f => f.FormType == FormType.Vitals);
            Assert.That(vitalsForm, Is.Not.Null);
            Assert.That(vitalsForm.Caption, Is.EqualTo("Vitals"));
            Assert.That(vitalsForm.FormState, Is.EqualTo(FormState.Incomplete));
            Assert.That(vitalsForm.FormType, Is.EqualTo(FormType.Vitals));
            Assert.That(vitalsForm.OrderNo, Is.EqualTo(1));
            formRepository.Verify(r => r.Add(vitalsForm), Times.Once());

            var vitalsFormData = vitalsFormDatas.FirstOrDefault(data => data.Form == vitalsForm);
            Assert.That(vitalsFormData, Is.Not.Null);
            Assert.That(vitalsFormData.ActualTime, Is.Not.Null);
            Assert.That(vitalsFormData.BloodPressureDiastolic, Is.Not.Null);
            Assert.That(vitalsFormData.BloodPressureSystolic, Is.Not.Null);
            Assert.That(vitalsFormData.HeartRate, Is.Not.Null);
            Assert.That(vitalsFormData.Height, Is.Not.Null);
            Assert.That(vitalsFormData.Weight, Is.Not.Null);
            Assert.That(vitalsFormData.Temperature, Is.Not.Null);
        }
        public void CreatePatient_1stDayVisit_FormsVerification()
        {
            //Arrange
            var doctor = new User() {Id = 15, Role = ClinicalStudyRoles.Doctor, Patients = new List<Patient>()};
            var vitalsFormDatas = new List<VitalsFormData>();
            var happinessFormDatas = new List<HappinessFormData>();
            var electrocardiogramFormDatas = new List<ElectrocardiogramFormData>();
            vitalsFormDataRepository
                .Setup(r => r.Add(It.IsAny<VitalsFormData>()))
                .Callback<VitalsFormData>(data => vitalsFormDatas.Add(data));
            happinessFormDataRepository
                .Setup(r => r.Add(It.IsAny<HappinessFormData>()))
                .Callback<HappinessFormData>(data => happinessFormDatas.Add(data));
            electroFormDataRepository
                .Setup(r => r.Add(It.IsAny<ElectrocardiogramFormData>()))
                .Callback<ElectrocardiogramFormData>(data => electrocardiogramFormDatas.Add(data));

            //Act
            var result = studyDesign.CreatePatient(doctor);
            //Assert
            Assert.That(result, Is.Not.Null, "Patient was created");
            Assert.That(result.Visits, Is.Not.Null, "Visits were not created");
            var visit = result.Visits.FirstOrDefault(v => v.VisitType == VisitType.Day1);
            Assert.That(visit, Is.Not.Null, "Baseline visit was not scheduled");
            Assert.That(visit.Forms, Is.Not.Null, "Forms were not created");

            //happiness CRF
            var happinessForm = visit.Forms.FirstOrDefault(f => f.FormType == FormType.Happiness);
            Assert.That(happinessForm, Is.Not.Null);
            Assert.That(happinessForm.Caption, Is.EqualTo("Happiness"));
            Assert.That(happinessForm.FormState, Is.EqualTo(FormState.Incomplete));
            Assert.That(happinessForm.FormType, Is.EqualTo(FormType.Happiness));
            Assert.That(happinessForm.OrderNo, Is.EqualTo(0));
            formRepository.Verify(r => r.Add(happinessForm), Times.Once());

            var happinessFormData = happinessFormDatas.FirstOrDefault(data => data.Form == happinessForm);
            Assert.That(happinessFormData, Is.Not.Null);
            Assert.That(happinessFormData.HappinessLevel, Is.Not.Null);

            //electrocardiogram CRF
            var electroForm = visit.Forms.FirstOrDefault(f => f.FormType == FormType.Electrocardiogram);
            Assert.That(electroForm, Is.Not.Null);
            Assert.That(electroForm.Caption, Is.EqualTo("Electrocardiogram"));
            Assert.That(electroForm.FormState, Is.EqualTo(FormState.Incomplete));
            Assert.That(electroForm.FormType, Is.EqualTo(FormType.Electrocardiogram));
            Assert.That(electroForm.OrderNo, Is.EqualTo(1));
            formRepository.Verify(r => r.Add(electroForm), Times.Once());

            var electrocardiogramFormData = electrocardiogramFormDatas.FirstOrDefault(data => data.Form == electroForm);
            Assert.That(electrocardiogramFormData, Is.Not.Null);
            Assert.That(electrocardiogramFormData.ElectrocardiogramActualTime, Is.Not.Null);
            Assert.That(electrocardiogramFormData.ElectrocardiogramAttachment, Is.Not.Null);

            //vitals CRF
            var vitalsForm = visit.Forms.FirstOrDefault(f => f.FormType == FormType.Vitals);
            Assert.That(vitalsForm, Is.Not.Null);
            Assert.That(vitalsForm.Caption, Is.EqualTo("Vitals"));
            Assert.That(vitalsForm.FormState, Is.EqualTo(FormState.Incomplete));
            Assert.That(vitalsForm.FormType, Is.EqualTo(FormType.Vitals));
            Assert.That(vitalsForm.OrderNo, Is.EqualTo(2));
            formRepository.Verify(r => r.Add(vitalsForm), Times.Once());

            var vitalsFormData = vitalsFormDatas.FirstOrDefault(data => data.Form == vitalsForm);
            Assert.That(vitalsFormData, Is.Not.Null);
            Assert.That(vitalsFormData.ActualTime, Is.Not.Null);
            Assert.That(vitalsFormData.BloodPressureDiastolic, Is.Not.Null);
            Assert.That(vitalsFormData.BloodPressureSystolic, Is.Not.Null);
            Assert.That(vitalsFormData.HeartRate, Is.Not.Null);
            Assert.That(vitalsFormData.Height, Is.Not.Null);
            Assert.That(vitalsFormData.Weight, Is.Not.Null);
            Assert.That(vitalsFormData.Temperature, Is.Not.Null);
        }
 public void CreatePatientForDoctor()
 {
     //Arrange
     const string doctorName = "doctorName";
     var doctor = new User() {Id = 15, Role = ClinicalStudyRoles.Doctor, Patients = new List<Patient>()};
     userRepository.Setup(r => r.GetUserByLogin(doctorName)).Returns(doctor);
     //Act
     var result = studyDesign.CreatePatientForDoctor(doctorName);
     //Assert
     userRepository.Verify(r => r.GetUserByLogin(doctorName), Times.Once());
 }
            public void CorrectModelMapping()
            {
                //Arrange
                var dataStorage = new Mock<IDataStorage>();
                var repository = new QueryRepository(dataStorage.Object);

                var clinic = new Clinic {Caption = "Clinic"};
                var doctor = new User {FirstName = "DoctorFirst", LastName = "DoctorLast", Clinic = clinic};
                var patient = new Patient {Doctor = doctor};
                var visit = new Visit {Caption = "Visit", Patient = patient};
                var form1 = new Form {FormType = FormType.Happiness, Visit = visit};
                var question1 = new Question {Caption = "QuestionCaption1", Form = form1};
                var query1 = new Query {Id = 1, Question = question1};

                var form2 = new Form {FormType = FormType.Inventory, Visit = visit};
                var question2 = new Question {Caption = "QuestionCaption2", Form = form2};
                var query2 = new Query {Id = 2, Question = question2, AnswerText = "Answer"};

                dataStorage.Setup(ds => ds.GetData<Query>()).Returns(new List<Query> {query1, query2});

                //Act
                var result = repository.GetQueriesReportData();

                //Assert
                Assert.That(result, Is.Not.Null);
                Assert.That(result.Count(), Is.EqualTo(2));
                var dto = result.ToList()[0];
                Assert.That(dto.FormType, Is.EqualTo(FormType.Happiness));
                Assert.That(dto.ClinicName, Is.EqualTo("Clinic"));
                Assert.That(dto.DoctorName, Is.EqualTo("DoctorFirst DoctorLast"));
                Assert.That(dto.QuestionName, Is.EqualTo("QuestionCaption1"));
                Assert.That(dto.IsOpen, Is.True);

                dto = result.ToList()[1];
                Assert.That(dto.FormType, Is.EqualTo(FormType.Inventory));
                Assert.That(dto.ClinicName, Is.EqualTo("Clinic"));
                Assert.That(dto.DoctorName, Is.EqualTo("DoctorFirst DoctorLast"));
                Assert.That(dto.QuestionName, Is.EqualTo("QuestionCaption2"));
                Assert.That(dto.IsOpen, Is.False);
            }
            private void PrepareQueriesReportData()
            {
                supervisor1000 = new User {Id = 1000, FirstName = "First1000", LastName = "Last1000"};
                supervisor2000 = new User {Id = 2000, FirstName = "First2000", LastName = "Last2000"};

                doctor1 = new User {Id = 1, FirstName = "First1", LastName = "Last1"};
                doctor2 = new User {Id = 2, FirstName = "First2", LastName = "Last2"};
                doctor3 = new User {Id = 3, FirstName = "First3", LastName = "Last3"};

                form11 = new Form {Id = 11, Caption = "CRF11"};
                form12 = new Form {Id = 12, Caption = "CRF12"};
                form13 = new Form {Id = 13, Caption = "CRF13"};

                form21 = new Form {Id = 21, Caption = "CRF21"};
                form22 = new Form {Id = 22, Caption = "CRF22"};

                form31 = new Form {Id = 31, Caption = "CRF31"};
                form32 = new Form {Id = 32, Caption = "CRF32"};
                form33 = new Form {Id = 33, Caption = "CRF33"};
                form34 = new Form {Id = 34, Caption = "CRF34"};
                form35 = new Form {Id = 35, Caption = "CRF35"};

                question111 = new Question {Id = 111, Caption = "Question111", Form = form11};

                question121 = new Question {Id = 121, Caption = "Question121", Form = form12};
                question122 = new Question {Id = 122, Caption = "Question122", Form = form12};

                question211 = new Question {Id = 211, Caption = "Question211", Form = form21};
                question212 = new Question {Id = 212, Caption = "Question212", Form = form21};
                question213 = new Question {Id = 213, Caption = "Question213", Form = form21};

                question311 = new Question {Id = 311, Caption = "Question311", Form = form31};
                question321 = new Question {Id = 321, Caption = "Question321", Form = form32};
                question331 = new Question {Id = 331, Caption = "Question331", Form = form33};
                question341 = new Question {Id = 341, Caption = "Question341", Form = form34};
                question351 = new Question {Id = 351, Caption = "Question351", Form = form35};

                query1110 = new Query { Id = 1110, Question = question111, QueryAuthor = supervisor1000, QueryTime = DateTime.Today.AddDays(-1110), QueryText = "Query1110", AnswerAuthor = doctor1, AnswerText = "Reply1110", AnswerTime = DateTime.Today.AddDays(1110)};
                query1210 = new Query { Id = 1210, Question = question121, QueryAuthor = supervisor2000, QueryTime = DateTime.Today.AddDays(-1210), QueryText = "Query1210", AnswerAuthor = doctor1, AnswerText = "Reply1210", AnswerTime = DateTime.Today.AddDays(1210) };
                query1220 = new Query { Id = 1220, Question = question122, QueryAuthor = supervisor1000, QueryTime = DateTime.Today.AddDays(-1220), QueryText = "Query1220", AnswerAuthor = doctor1, AnswerText = "Reply1220", AnswerTime = DateTime.Today.AddDays(1220) };
                query2110 = new Query { Id = 2110, Question = question211, QueryAuthor = supervisor2000, QueryTime = DateTime.Today.AddDays(-2110), QueryText = "Query2110", AnswerAuthor = doctor2, AnswerText = "Reply2110", AnswerTime = DateTime.Today.AddDays(2110) };
                query2120 = new Query { Id = 2120, Question = question212, QueryAuthor = supervisor1000, QueryTime = DateTime.Today.AddDays(-2120), QueryText = "Query2120", AnswerAuthor = doctor2, AnswerText = "Reply2120", AnswerTime = DateTime.Today.AddDays(2120) };
                query2130 = new Query { Id = 2130, Question = question213, QueryAuthor = supervisor2000, QueryTime = DateTime.Today.AddDays(-2130), QueryText = "Query2130", AnswerAuthor = doctor2, AnswerText = "Reply2130", AnswerTime = DateTime.Today.AddDays(2130) };
                query3110 = new Query { Id = 3110, Question = question311, QueryAuthor = supervisor1000, QueryTime = DateTime.Today.AddDays(-3110), QueryText = "Query3110"};
                query3210 = new Query { Id = 3210, Question = question321, QueryAuthor = supervisor2000, QueryTime = DateTime.Today.AddDays(-3210), QueryText = "Query3210"};
                query3310 = new Query { Id = 3310, Question = question331, QueryAuthor = supervisor1000, QueryTime = DateTime.Today.AddDays(-3310), QueryText = "Query3310"};
                query3410 = new Query { Id = 3410, Question = question341, QueryAuthor = supervisor2000, QueryTime = DateTime.Today.AddDays(-3410), QueryText = "Query3410"};
                query3510 = new Query { Id = 3510, Question = question351, QueryAuthor = supervisor1000, QueryTime = DateTime.Today.AddDays(-3510), QueryText = "Query3510"};
            }
예제 #11
0
        private void CreateUserLoginName(User user, List<User> users)
        {
            var baseLogin = user.FirstName.Substring(0, 1).ToLower() + user.LastName.ToLower();
            var login = baseLogin;
            int iterator = 1;
            while (users.Any(u => string.Equals(login, u.Login, StringComparison.InvariantCultureIgnoreCase))) {
                login = baseLogin + iterator.ToString();
                iterator++;
            }

            user.Login = login;
        }
예제 #12
0
        private User CreateUserRecord(Clinic clinic, List<User>users, string role)
        {
            bool isMale = PeopleDataProvider.IsMale();

            var user = new User() {
                Id = entityIdIncrement++,
                FirstName = PeopleDataProvider.GetRandomFirstName(isMale),
                LastName = PeopleDataProvider.GetRandomLastName(isMale),
                Photo = GetBytesFromImage(GetNextPhotoUrl(isMale)),
                CanVisitWebSite = false,
                Clinic = clinic,
                Patients = new List<Patient>(),
                Role = role
            };
            CreateUserLoginName(user, users);
            users.Add(user);
            clinic.Doctors.Add(user);
            return user;
        }
            private Patient CreatePatient(int clinicId, int doctorId, int patId)
            {
                var clinic = new Clinic {Id = clinicId, Caption = String.Format("Clinic{0}", clinicId)};
                var doctor = new User {
                    Id = doctorId,
                    Clinic = clinic,
                    Role = ClinicalStudyRoles.Doctor,
                    FirstName = String.Format("First{0}", doctorId),
                    LastName = String.Format("Last{0}", doctorId)
                };
                var pat = new Patient {Id = patId, PatientNumber = 10 + patId, Doctor = doctor};

                var demog = new Form { FormType = FormType.Demographics, Id = 201 + patId};

                var hap1 = new Form {FormType = FormType.Happiness, Id = 202 + patId};
                var hap2 = new Form { FormType = FormType.Happiness, Id = 203 + patId };

                var visitB = new Visit
                             {Id = 101 + patId, Caption = String.Format("Visit{0}", 101 + patId), VisitType = VisitType.Baseline, Forms = new List<Form>{demog}};
                var visit1 = new Visit { Id = 102 + patId, Caption = String.Format("Visit{0}", 102 + patId), VisitType = VisitType.Day1, Forms = new List<Form>{hap1}};
                var visit10 = new Visit { Id = 103 + patId, Caption = String.Format("Visit{0}", 103 + patId), VisitType = VisitType.Day10, Forms = new List<Form> { hap2 } };

                pat.Visits = new List<Visit>{visitB, visit1, visit10};

                return pat;
            }
        public Patient CreatePatient(User doctor)
        {
            var patient = new Patient();
            PatientRepository.Add(patient);

            //verify that patient number is unique
            //if it is not, then assign unique number
            var maxNumber = PatientRepository.GetMaxPatientNumber();
            patient.PatientNumber = maxNumber + 1;
            patient.Caption = string.Format("Subj {0}{1:D3}", "A", patient.PatientNumber);
            patient.Doctor = doctor;
            doctor.Patients.Add(patient);

            patient.Visits = new List<Visit>();
            patient.Visits.Add(CreateBaselineVisit(patient));
            patient.Visits.Add(Create1stDayVisit(patient));
            patient.Visits.Add(Create10thDayVisit(patient));
            foreach (var visit in patient.Visits) {
                VisitRepository.Add(visit);
                foreach (var form in visit.Forms) {
                    FormRepository.Add(form);
                }
            }

            return patient;
        }
        public void Doctors_DetailGrid()
        {
            //Arrange
            var cRepository = new Mock<IClinicRepository>();
            var controller = new AdministrationController(cRepository.Object);
            var clinicId = 111;
            var doctor1 = new User {
                Id = 10,
                FirstName = "First10",
                LastName = "Last10",
                Role = "Doctor",
                Patients = new List<Patient> {new Patient()},
                Login = "******",
                Photo = new byte[]{1,2,3}
            };
            var doctor2 = new User {
                Id = 20,
                FirstName = "First20",
                LastName = "Last20",
                Role = "Supervisor",
                Patients = new List<Patient> {new Patient(), new Patient()},
                Login = "******",
                Photo = new byte[]{3,4,5}
            };

            var clinic = new Clinic {Id = clinicId, Caption = "Clinic111", Doctors = new List<User> {doctor1, doctor2}};

            cRepository.Setup(r => r.GetByKey(clinicId)).Returns(clinic);

            //Act
            var result = controller.ClinicDoctors(clinicId);

            //Assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result is PartialViewResult);
            var viewResultBase = result as ViewResultBase;
            Assert.That(viewResultBase.Model, Is.Not.Null);
            Assert.That(viewResultBase.ViewName, Is.EqualTo("_ClinicDoctorsGrid"));
            Assert.That(viewResultBase.Model is ClinicDetailsViewModel);
            var model = viewResultBase.Model as ClinicDetailsViewModel;
            Assert.That(model.Doctors, Is.Not.Null);
            Assert.That(model.Doctors.Count, Is.EqualTo(2));

            Assert.That(model.ClinicId, Is.EqualTo(111));

            Assert.That(model.Doctors[0].ClinicId, Is.EqualTo(111));
            Assert.That(model.Doctors[0].DoctorId, Is.EqualTo(10));
            Assert.That(model.Doctors[0].FirstName, Is.EqualTo("First10"));
            Assert.That(model.Doctors[0].LastName, Is.EqualTo("Last10"));
            Assert.That(model.Doctors[0].Role, Is.EqualTo("Doctor"));
            Assert.That(model.Doctors[0].PatientsCount, Is.EqualTo(1));
            Assert.That(model.Doctors[0].Login, Is.EqualTo("login10"));
            Assert.That(model.Doctors[0].Photo, Is.EqualTo(new byte[] { 1, 2, 3 }));

            Assert.That(model.Doctors[1].ClinicId, Is.EqualTo(111));
            Assert.That(model.Doctors[1].DoctorId, Is.EqualTo(20));
            Assert.That(model.Doctors[1].FirstName, Is.EqualTo("First20"));
            Assert.That(model.Doctors[1].LastName, Is.EqualTo("Last20"));
            Assert.That(model.Doctors[1].Role, Is.EqualTo("Supervisor"));
            Assert.That(model.Doctors[1].PatientsCount, Is.EqualTo(2));
            Assert.That(model.Doctors[1].Login, Is.EqualTo("login20"));
            Assert.That(model.Doctors[1].Photo, Is.EqualTo(new byte[] { 3, 4, 5 }));

            cRepository.Verify(r => r.GetByKey(clinicId), Times.Once());
        }
        public List<Query> BuildQueries(User doctor, User supervisor)
        {
            var list = new List<Query>();

            int firstPatientNumber = doctor.Patients.First().PatientNumber;

            var query = new Query {
                Id = queryId++,
                QueryText = "Please use Country Name, not Code",
                QueryAuthor = supervisor,
                QueryTime = DateTime.Now.AddDays(-1),
                AnswerAuthor = doctor,
                AnswerText = "Corrected from “CAR” to “Central African Republic”",
                AnswerTime = DateTime.Now.AddDays(-0.75)
            };
            AssociateQueryWithQuestion(query, firstPatientNumber, VisitType.Baseline, FormType.Demographics,
                                       (formId) => DemographicFormDatas.Find(d => d.Form.Id == formId).Other);

            list.Add(query);

            query = new Query {
                Id = queryId++,
                QueryText = "Please specify the reason for high temperature",
                QueryAuthor = supervisor,
                QueryTime = DateTime.Now.AddDays(-1),
                AnswerAuthor = doctor,
                AnswerText = "Patient had flu-like symptoms occurr a day before the visit",
                AnswerTime = DateTime.Now.AddDays(-0.75)
            };
            AssociateQueryWithQuestion(query, firstPatientNumber, VisitType.Day1, FormType.Vitals,
                                       (formId) => VitalsFormDatas.Find(d => d.Form.Id == formId).Temperature);

            list.Add(query);

            query = new Query {
                Id = queryId++,
                QueryText = "Cardiogram image is not full",
                QueryAuthor = supervisor,
                QueryTime = DateTime.Now.AddDays(-1),
                AnswerAuthor = null,
                AnswerText = null,
                AnswerTime = null
            };
            AssociateQueryWithQuestion(query, firstPatientNumber, VisitType.Day1, FormType.Electrocardiogram,
                                       (formId) =>
                                       ElectrocardiogramFormDatas.Find(d => d.Form.Id == formId).ElectrocardiogramAttachment);

            list.Add(query);

            query = new Query {
                Id = queryId++,
                QueryText = "Was the measurement performed in regular conditions?",
                QueryAuthor = supervisor,
                QueryTime = DateTime.Now.AddDays(-1),
                AnswerAuthor = null,
                AnswerText = null,
                AnswerTime = null
            };
            AssociateQueryWithQuestion(query, firstPatientNumber, VisitType.Day10, FormType.Vitals,
                                       (formId) => VitalsFormDatas.Find(d => d.Form.Id == formId).HeartRate);

            list.Add(query);

            AddTemparatureQueries(list);
            AddHappinessChangeQueries(list);
            AddDemographicQueries(list);
            AddInventoryQueries(list);
            return list;
        }
            public void CorrectModelMapping()
            {
                //Arrange
                var dataStorage = new Mock<IDataStorage>();
                var repository = new VisitRepository(dataStorage.Object);

                var clinic = new Clinic { Caption = "Clinic" };
                var doctor1 = new User { FirstName = "DoctorFirst1", LastName = "DoctorLast1", Clinic = clinic };
                var patient1 = new Patient { Doctor = doctor1 };
                var visit1B = new Visit { Caption = "Visit1B", Patient = patient1, VisitType = VisitType.Baseline, Forms = new List<Form>{new Form { Id = 1, FormType = FormType.Demographics}}};
                var visit1Ae1 = new Visit { Caption = "Visit1Ae1", Patient = patient1, VisitType = VisitType.AdverseEventVisit, Forms = new List<Form> { new Form { Id = 2, FormType = FormType.AdverseEvent } } };
                var visit1Ae2 = new Visit { Caption = "Visit1Ae2", Patient = patient1, VisitType = VisitType.AdverseEventVisit, Forms = new List<Form> { new Form { Id = 3, FormType = FormType.AdverseEvent } } };
                patient1.Visits = new List<Visit> {visit1B, visit1Ae1, visit1Ae2};

                var doctor2 = new User { FirstName = "DoctorFirst2", LastName = "DoctorLast2", Clinic = clinic };
                var patient2 = new Patient { Doctor = doctor2 };
                var visit2B = new Visit { Caption = "Visit2B", Patient = patient2, VisitType = VisitType.Baseline, Forms = new List<Form> { new Form { Id = 13, FormType = FormType.Demographics } } };
                var visit2Ae1 = new Visit { Caption = "Visit2Ae1", Patient = patient2, VisitType = VisitType.AdverseEventVisit, Forms = new List<Form> { new Form { Id = 23, FormType = FormType.AdverseEvent } } };
                patient2.Visits = new List<Visit> { visit2B, visit2Ae1 };

                dataStorage.Setup(ds => ds.GetData<Visit>()).Returns(new List<Visit> { visit1Ae1, visit1Ae2, visit1B, visit2B, visit2Ae1 });

                //Act
                var result = repository.GetAeAnalyticsData();

                //Assert
                Assert.That(result, Is.Not.Null);
                Assert.That(result.Count, Is.EqualTo(3));
                var dto = result[0];
                Assert.That(dto.ClinicName, Is.EqualTo("Clinic"));
                Assert.That(dto.DoctorName, Is.EqualTo("DoctorFirst1 DoctorLast1"));
                Assert.That(dto.DemographicFormId, Is.EqualTo(1));
                Assert.That(dto.AeFormId, Is.EqualTo(2));

                dto = result[1];
                Assert.That(dto.ClinicName, Is.EqualTo("Clinic"));
                Assert.That(dto.DoctorName, Is.EqualTo("DoctorFirst1 DoctorLast1"));
                Assert.That(dto.DemographicFormId, Is.EqualTo(1));
                Assert.That(dto.AeFormId, Is.EqualTo(3));

                dto = result[2];
                Assert.That(dto.ClinicName, Is.EqualTo("Clinic"));
                Assert.That(dto.DoctorName, Is.EqualTo("DoctorFirst2 DoctorLast2"));
                Assert.That(dto.DemographicFormId, Is.EqualTo(13));
                Assert.That(dto.AeFormId, Is.EqualTo(23));
            }