Exemplo n.º 1
0
        public async Task <IActionResult> Get(string id)
        {
            if (id.Length != Requirements.PatientIdLength)
            {
                return(BadRequest());
            }

            var patient = await _patientService.Get(id);

            if (patient == default(Patient))
            {
                var p = new Patient()
                {
                    Id                = id,
                    Allergies         = new List <string>(),
                    BloodType         = string.Empty,
                    EmergencyContacts = new List <string>(),
                    MedicalNotes      = new List <string>()
                };
                await _patientService.Create(p);

                return(Ok(p));
            }

            return(Ok(patient));
        }
Exemplo n.º 2
0
        public async Task TestCreateModelValid()
        {
            // Arrange
            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork
            .Setup(x => x.PatientRepository.Create(It.IsAny <Patient>()))
            .Verifiable();

            mockUnitOfWork
            .Setup(x => x.CommitAsync())
            .Verifiable();

            var service = new PatientService(mockUnitOfWork.Object, _mapper);

            // Act
            var result = await service.Create(new PatientInputModel
            {
                FamilyName = "Test",
            });

            // Assert
            Assert.IsAssignableFrom <Patient>(result);

            mockUnitOfWork
            .Verify(x => x.PatientRepository.Create(It.IsAny <Patient>()), Times.Once);

            mockUnitOfWork
            .Verify(x => x.CommitAsync(), Times.Once);
        }
Exemplo n.º 3
0
        public void AllocateTeamMember_GivenNoReasonForAdmission_WherePatientHasNoTeamMembers()
        {
            // Arrange
            var            connection     = GetConnection();
            ListRepository listRepository = new ListRepository(connection);

            PatientService patientService = new PatientService(connection);

            Patient patient = new Patient()
            {
                Firstname   = _nameDataSet.FirstName(),
                Lastname    = _nameDataSet.LastName(),
                DateOfBirth = _dateDataSet.Past()
            };

            Guid patientId  = patientService.Create(patient);
            Guid facilityId = listRepository.GetFacilities().First(x => x.Name == "Tijger Mental Health Clinic Loevenstein").Id;
            Guid userId     = listRepository.GetFacilityUsers(facilityId).First().Id;

            TeamMember teamMember = new TeamMember()
            {
                FacilityId = facilityId,
                PatientId  = patientId,
                UserIds    = new Guid[] {
                    userId
                }
            };

            // Act

            patientService.AllocateTeamMember(teamMember);

            // Assert
        }
        public async Task CreateShouldReturnTrueAndNewPatient()
        {
            var db                = Tests.GetDatabase();
            var doctorService     = new DoctorService(db, null);
            var departmentService = new DepartmentService(db);
            await departmentService.CreateAsync("Cardiology", "Gosho", "SomeURL");

            await db.SaveChangesAsync();

            await doctorService.CreateAsync(
                "Gosho", "*****@*****.**", "SomeURL", "Cardiologist", "Cardiology");

            await db.SaveChangesAsync();

            var patientService = new PatientService(db);
            var result         = await patientService.Create("Patient",
                                                             "8698969896",
                                                             28, "*****@*****.**");

            await db.SaveChangesAsync();

            result.Should()
            .BeTrue();

            db.Patients.Should()
            .HaveCount(1);
        }
Exemplo n.º 5
0
        public IActionResult Create(PatientDto patientDto)
        {
            if (PatientService.Create(patientDto) == null)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Exemplo n.º 6
0
        public void Sends_verification_email()
        {
            var            mockVerify     = new Mock <IEmailVerificationService>();
            PatientService patientService = new PatientService(CreateStubRepository(), mockVerify.Object, new RegularAppointmentService(new AppointmentRepository(), new EmployeesScheduleRepository(), new DoctorService(new OperationRepository(), new AppointmentRepository(), new EmployeesScheduleRepository(), new DoctorRepository()), new PatientsRepository(), new OperationService(new OperationRepository())));

            PatientUser patient1 = patientService.Create(new PatientDto("Pera2", "Peric", "Male", "1234", "11/11/2000", "1231412", "21312312", "Alergija", "Grad", "*****@*****.**", "pass", false, "Grad2", "Roditelj", "", ""));

            mockVerify.Verify(v => v.SendVerificationMail(new MailAddress(patient1.email), patient1.id), Times.Once);
        }
Exemplo n.º 7
0
        public async Task TestCreateModelNull()
        {
            // Arrange
            var service = new PatientService(null, null);

            // Act
            async Task Action() => await service.Create(null);

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(Action);
        }
        public void Create_Registration_Successfuly()
        {
            var            mockVerify = new Mock <IEmailVerificationService>();
            PatientService service    = new PatientService(CreateStubRepository(), mockVerify.Object, new RegularAppointmentService(new AppointmentRepository(), new EmployeesScheduleRepository(), new DoctorService(new OperationRepository(), new AppointmentRepository(), new EmployeesScheduleRepository(), new DoctorRepository()), new PatientsRepository(), new OperationService(new OperationRepository())));



            PatientUser patient = service.Create(new PatientDto("Pera2", "Peric", "Male", "1234", "11/11/2000", "1231412", "21312312", "Alergija", "Grad", "*****@*****.**", "pass", false, "Grad2", "Roditelj", "", ""));

            patient.ShouldNotBeNull();
        }
Exemplo n.º 9
0
        public IActionResult Create([Bind("FirstName,LastName,City,Email,Phone")] Patient newPatient)
        {
            if (!ModelState.IsValid)
            {
                return(View(newPatient));
            }

            _patientService.Create(newPatient);

            var _listOfPatients = _patientService.ReadAll().OrderBy(p => p.Id).ToList();

            return(RedirectToAction(nameof(ReadAll), _listOfPatients));
        }
Exemplo n.º 10
0
 public ActionResult Create(Patient Model)
 {
     try
     {
         // TODO: Add insert logic here
         Service.Create(Model);
         return(RedirectToAction("Index", "Patient"));
     }
     catch
     {
         return(View());
     }
 }
Exemplo n.º 11
0
        public void DeallocateTeamMember_GivenNoDischargeTypeId_WhereDischaringLastTeamMember()
        {
            // Arrange
            var               connection        = GetConnection();
            ListRepository    listRepository    = new ListRepository(connection);
            PatientRepository patientRepository = new PatientRepository(connection);

            PatientService patientService = new PatientService(connection);

            Patient patient = new Patient()
            {
                Firstname   = _nameDataSet.FirstName(),
                Lastname    = _nameDataSet.LastName(),
                DateOfBirth = _dateDataSet.Past()
            };

            Guid patientId  = patientService.Create(patient);
            Guid facilityId = listRepository.GetFacilities().First(x => x.Name == "Tijger Mental Health Clinic Loevenstein").Id;

            Guid[] userIds         = listRepository.GetFacilityUsers(facilityId).Select(x => x.Id).ToArray();
            Guid   admissionTypeId = listRepository.GetAdmissionTypes().First().Id;

            TeamMember teamMember = new TeamMember()
            {
                FacilityId                  = facilityId,
                PatientId                   = patientId,
                ReasonForAdmissionName      = "G46.4 - Cerebellar stroke syndrome (I60-I67+)",
                ReasonForAdmissionTimestamp = _dateDataSet.Past(),
                AdmissionTypeId             = admissionTypeId,
                UserIds = userIds
            };

            patientService.AllocateTeamMember(teamMember);

            try
            {
                foreach (var item in userIds.Skip(1))
                {
                    patientService.DeallocateTeamMember(patientId, item);
                }
            }catch (Exception ex)
            {
                throw;
            }

            // Act
            patientService.DeallocateTeamMember(patientId, userIds.First());


            // Assert
        }
Exemplo n.º 12
0
        public async Task TestCreateDTOPhoneNumbersNull()
        {
            // Arrange
            var testDTO = new PatientInputModel {
                PhoneNumbers = null
            };

            var service = new PatientService(null, null);

            // Act
            async Task Action() => await service.Create(testDTO);

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(Action);
        }
Exemplo n.º 13
0
        public void Should_Return_Create_Success_Response()
        {
            AutoMapperConfiguration.Configure();
            AssignState();
            var result = _patientService.Create(new PatientModel
            {
                Id = 0,
                PatientName = "Baswara",
                Gender = Gender.Male,
                PatientStatus = PatientStatus.Active,
                RelationshipStatus = RelationshipStatus.Child
            });

            Assert.NotNull(result.Item);
            Assert.Equal(MessageConstant.Create, result.Message);
            Assert.True(result.Success);

        }
Exemplo n.º 14
0
        public HttpResponseMessage Post(Patient patient)
        {
            if (ModelState.IsValid)
            {
                service.Create(patient);

                var response = Request.CreateResponse(HttpStatusCode.Created, new DataSourceResult {
                    Data = new[] { patient }, Total = 1
                });
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = patient.Id }));
                return(response);
            }
            else
            {
                var errors = ModelState.Values.SelectMany(v => v.Errors).Select(error => error.ErrorMessage);

                return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
            }
        }
        public async Task EditShouldReturnTrueAndEditedPatient()
        {
            var db                = Tests.GetDatabase();
            var doctorService     = new DoctorService(db, null);
            var departmentService = new DepartmentService(db);
            await departmentService.CreateAsync("Cardiology", "Gosho", "SomeURL");

            await db.SaveChangesAsync();

            await doctorService.CreateAsync(
                "Gosho", "*****@*****.**", "SomeURL", "Cardiologist", "Cardiology");

            await db.SaveChangesAsync();

            var patientService = new PatientService(db);
            var result         = await patientService.Create("Patient",
                                                             "8698969896",
                                                             28, "*****@*****.**");

            await db.SaveChangesAsync();

            var id = await db.Patients
                     .Where(d => d.Name == "Patient")
                     .Select(d => d.Id)
                     .FirstOrDefaultAsync();

            var edited = await patientService
                         .Edit(id, "PatientEdited",
                               "8698969896",
                               28, "*****@*****.**");

            edited.Should()
            .BeTrue();

            db.Patients.Should()
            .HaveCount(1);

            result.Should()
            .BeTrue();
        }
Exemplo n.º 16
0
        public async Task TestCreatePatientEntityAlreadyExists()
        {
            // Arrange
            var testDTO = new PatientInputModel();

            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork
            .Setup(x => x.PatientRepository.GetByFullPersonalia(It.IsAny <PatientInputModel>()))
            .ReturnsAsync(new Patient())
            .Verifiable();

            var service = new PatientService(mockUnitOfWork.Object, null);

            // Act
            async Task Action() => await service.Create(testDTO);

            // Assert
            var ex = await Assert.ThrowsAsync <Exception>(Action);

            Assert.Equal("Error: a Patient entity already exists that matches the supplied personalia.", ex.Message);
        }
Exemplo n.º 17
0
        public async Task TestCreateException()
        {
            // Arrange
            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork
            .Setup(x => x.PatientRepository.Create(It.IsAny <Patient>()))
            .Verifiable();

            mockUnitOfWork
            .Setup(x => x.CommitAsync())
            .Throws <Exception>()
            .Verifiable();

            mockUnitOfWork
            .Setup(x => x.RollbackAsync())
            .Verifiable();

            var service = new PatientService(mockUnitOfWork.Object, _mapper);

            // Act
            async Task <Patient> Action() => await service.Create(new PatientInputModel
            {
                FamilyName = "Test",
            });

            // Assert
            await Assert.ThrowsAsync <Exception>(Action);

            mockUnitOfWork
            .Verify(x => x.PatientRepository.Create(It.IsAny <Patient>()), Times.Once);

            mockUnitOfWork
            .Verify(x => x.CommitAsync(), Times.Once);

            mockUnitOfWork
            .Verify(x => x.RollbackAsync(), Times.Once());
        }
 public IActionResult Create(Patient patient)
 {
     _patientService.Create(patient);
     ViewBag.Information = "Пациент успешно сохранен!";
     return(View("Update", patient));
 }
Exemplo n.º 19
0
        public ActionResult CreatePost(Application.Entities.Patient model)
        {
            Guid patientId = _patientService.Create(model);

            return(RedirectToAction("Edit", "Patient", new { patientId = patientId }));
        }
Exemplo n.º 20
0
 public Patient Create(Patient entity)
 => _patientService.Create(entity);
Exemplo n.º 21
0
 public List <PatientModel> Add(PatientModel model)
 {
     service.Create(model);
     return(GetAll());
 }
Exemplo n.º 22
0
        public static void Test()
        {
            try
            {
                Console.WriteLine("Connecting to database...");
                using (var init = new InitDatabaseService())
                {
                    Console.WriteLine("Connection successful.\nResetting the database...");
                    init.Reset();
                    Console.WriteLine("Reset successful.\nLoading data...");

                    //create dummy pharmacy
                    Pharmacy pharm = new Pharmacy(1, "CSV Pharmacy", "19187661052", "1400 chrissartin street");
                    using (var service = new PharmacyService())
                    {
                        service.Create(pharm);
                    }
                    //create dummy patient
                    Patient patient  = new Patient(1, "Chris", "Sartin", new DateTime(2000, DateTime.Today.Month, DateTime.Today.Day), "77777", "19183994836", "*****@*****.**", pharm);
                    Patient patient1 = new Patient(2, "Matthew", "Miller", new DateTime(2000, DateTime.Today.Month, DateTime.Today.Day), "8675309", "19187661052", "*****@*****.**", pharm);

                    using (var service = new PatientService())
                    {
                        service.Create(patient);
                        service.Create(patient1);
                    }
                    //create dummy drug
                    Drug drug = new Drug(1, "Taco Medication");
                    using (var service = new DrugService())
                    {
                        service.Create(drug);
                    }
                    //create dummy prescription
                    Prescription prescription  = new Prescription(1, patient, drug, 7, 7);
                    Prescription prescription1 = new Prescription(2, patient1, drug, 6, 6);

                    using (var service = new PrescriptionService())
                    {
                        service.Create(prescription);
                        service.Create(prescription1);
                    }
                    EventRefill RefillEvent;

                    //create dummy event
                    using (var service = new EventService())
                    {
                        //create dummy eventRefill
                        Event Event  = new Event(patient, "this is a message", EventStatus.ToSend, EventType.REFILL);
                        Event Event1 = new Event(patient, "refill test event", EventStatus.Sent, EventType.REFILL);
                        Event Event2 = new Event(patient1, "this is a test", EventStatus.Fill, EventType.REFILL);
                        RefillEvent = new EventRefill(prescription, Event);
                        EventRefill RefillEvent1 = new EventRefill(prescription1, Event1);
                        EventRefill RefillEvent2 = new EventRefill(prescription1, Event2);
                        using (var service2 = new EventRefillService())
                        {
                            service.Create(Event);
                            service2.Create(RefillEvent);

                            service.Create(Event1);
                            service2.Create(RefillEvent1);

                            service.Create(Event2);
                            service2.Create(RefillEvent2);
                        }

                        //create dummy birthdayevent
                        Event BirthdayEvent = new Event(patient, "this is a message", EventStatus.ToSend, EventType.BIRTHDAY);
                        service.Create(BirthdayEvent);

                        //create dummy recallevent
                        Event = new Event(patient, "this is a message", EventStatus.ToSend, EventType.REFILL);
                        EventRecall RecallEvent = new EventRecall(Event);
                        using (var service2 = new EventRecallService())
                        {
                            service.Create(Event);
                            service2.Create(RecallEvent);
                        }

                        //create dummy eventhistory
                        EventHistory history = new EventHistory(Event, EventStatus.InActive, new DateTime(2000, 7, 14));
                        using (var service2 = new EventHistoryService())
                        {
                            service2.Create(history);
                        }
                    }

                    //create dummy pharmacist in the pharmacy
                    Pharmacist pharmacist  = new Pharmacist("James", "Taco", "*****@*****.**", "18884443333", new byte[] { 0 }, new byte[] { 0 });
                    Pharmacist pharmacist1 = new Pharmacist("Matthew", "Miller", "*****@*****.**", "19187661052", new byte[] { 0 }, new byte[] { 0 });
                    Pharmacist pharmacist2 = new Pharmacist("Luke", "Thorne", "*****@*****.**", "14056932048", new byte[] { 0 }, new byte[] { 0 });
                    Pharmacist pharmacist3 = new Pharmacist("Emily", "Pielemeier", "*****@*****.**", "13177536066", new byte[] { 0 }, new byte[] { 0 });
                    Pharmacist pharmacist4 = new Pharmacist("Tom", "Hartnett", "*****@*****.**", "14696671743", new byte[] { 0 }, new byte[] { 0 });

                    using (var service = new PharmacistService())
                    {
                        service.Create(pharmacist);
                        service.Create(pharmacist1);
                        service.Create(pharmacist2);
                        service.Create(pharmacist3);
                        service.Create(pharmacist4);
                    }


                    //create dummy fillhistory
                    FillHistory fill = new FillHistory(RefillEvent, pharmacist, new DateTime(2000, 7, 14));
                    using (var service = new FillHistoryService())
                    {
                        service.Create(fill);
                    }

                    //create dummy sysadmins (us)
                    SystemAdmin admin  = new SystemAdmin("testing", "the stuff", "*****@*****.**", "19184661052", new byte[] { 0 }, new byte[] { 0 });
                    SystemAdmin admin1 = new SystemAdmin("Tom", "Hartnett", "*****@*****.**", "14696671743", new byte[] { 0 }, new byte[] { 0 });
                    SystemAdmin admin2 = new SystemAdmin("Luke", "Thorne", "*****@*****.**", "14056932048", new byte[] { 0 }, new byte[] { 0 });
                    SystemAdmin admin3 = new SystemAdmin("Jon", "Hartnett", "*****@*****.**", "14696671064", new byte[] { 0 }, new byte[] { 0 });
                    SystemAdmin admin4 = new SystemAdmin("Emily", "Pielemeier", "*****@*****.**", "13177536066", new byte[] { 0 }, new byte[] { 0 });
                    using (var service = new SystemAdminService())
                    {
                        service.Create(admin);
                        service.Create(admin1);
                        service.Create(admin2);
                        service.Create(admin3);
                        service.Create(admin4);
                    }

                    //create dummy job
                    Job job = new Job(pharm, pharmacist, true, false);
                    using (var service = new JobService())
                    {
                        service.Create(job);
                        Job j1 = new Job(pharm, pharmacist1, true, true);
                        service.Create(j1);
                        Job j2 = new Job(pharm, pharmacist2, true, true);
                        service.Create(j2);
                        Job j3 = new Job(pharm, pharmacist3, true, true);
                        service.Create(j3);
                        Job j4 = new Job(pharm, pharmacist4, true, true);
                        service.Create(j4);
                    }

                    init.LoadFromFile(@"..\..\App_Data\Scrubbed_Data.xlsx - Sheet1.csv", pharm);
                    Console.WriteLine("Loading data successful.\nAll tests successful...");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.ReadKey();
            }
        }
 public Patient Create(Patient patient) => service.Create(patient);
Exemplo n.º 24
0
        public void FindCompletedEpisodesOfCare()
        {
            // Arrange
            var               connection        = GetConnection();
            ListRepository    listRepository    = new ListRepository(connection);
            PatientRepository patientRepository = new PatientRepository(connection);

            PatientService patientService = new PatientService(connection);

            Patient patient = new Patient()
            {
                Firstname   = _nameDataSet.FirstName(),
                Lastname    = _nameDataSet.LastName(),
                DateOfBirth = _dateDataSet.Past()
            };

            Guid patientId  = patientService.Create(patient);
            Guid facilityId = listRepository.GetFacilities().First(x => x.Name == "Tijger Mental Health Clinic Loevenstein").Id;

            Guid[] userIds         = listRepository.GetFacilityUsers(facilityId).Select(x => x.Id).ToArray();
            Guid   admissionTypeId = listRepository.GetAdmissionTypes().First().Id;
            Guid   dischargeTypeId = listRepository.GetDischargeTypes().First().Id;

            userIds = Shuffle <Guid>(userIds, _random).ToArray();

            TeamMember teamMember1 = new TeamMember()
            {
                FacilityId                  = facilityId,
                PatientId                   = patientId,
                ReasonForAdmissionName      = "G46.4 - Cerebellar stroke syndrome (I60-I67+)",
                ReasonForAdmissionTimestamp = _dateDataSet.Past(),
                AdmissionTypeId             = admissionTypeId,
                UserIds = userIds.Take(1).ToArray()
            };

            patientService.AllocateTeamMember(teamMember1);

            TeamMember teamMember2 = new TeamMember()
            {
                FacilityId = facilityId,
                PatientId  = patientId,
                UserIds    = userIds.Skip(1).ToArray()
            };

            patientService.AllocateTeamMember(teamMember2);


            userIds = Shuffle <Guid>(userIds, _random).ToArray();

            try
            {
                foreach (var item in userIds.Skip(1))
                {
                    patientService.DeallocateTeamMember(patientId, item, null, null, null);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            patientService.DeallocateTeamMember(patientId, userIds.First(), dischargeTypeId, null, null);


            ////
            Thread.Sleep(5000);

            userIds = Shuffle <Guid>(userIds, _random).ToArray();

            TeamMember teamMember3 = new TeamMember()
            {
                FacilityId                  = facilityId,
                PatientId                   = patientId,
                ReasonForAdmissionName      = "G46.4 - Cerebellar stroke syndrome (I60-I67+)",
                ReasonForAdmissionTimestamp = _dateDataSet.Past(),
                AdmissionTypeId             = admissionTypeId,
                UserIds = userIds.Take(1).ToArray()
            };

            patientService.AllocateTeamMember(teamMember1);

            TeamMember teamMember4 = new TeamMember()
            {
                FacilityId = facilityId,
                PatientId  = patientId,
                UserIds    = userIds.Skip(1).ToArray()
            };

            patientService.AllocateTeamMember(teamMember2);


            userIds = Shuffle <Guid>(userIds, _random).ToArray();

            try
            {
                foreach (var item in userIds.Skip(1))
                {
                    patientService.DeallocateTeamMember(patientId, item);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            patientService.DeallocateTeamMember(patientId, userIds.First(), dischargeTypeId, null, null);

            //////

            // Act
            var result = patientRepository.FindCompletedEpisodesOfCare(patientId, facilityId);


            // Assert
            Assert.Equals(2, result.Count);
        }