public async Task PatientRepositroyUpdatePatientAsyncSuccessTest()
        {
            var testModel = new PatientModel()
            {
                Id          = new Guid(),
                FirstName   = "John",
                LastName    = "Hu",
                Gender      = Gender.male,
                DateOfBirth = new DateTime(1992, 2, 14),
                Email       = "*****@*****.**",
                Phone       = "0425789632",
                CreateTime  = DateTime.Now,
                UpdateTime  = DateTime.Now,
            };
            var expected = new PatientModel()
            {
                Id          = testModel.Id,
                FirstName   = "Tee",
                LastName    = "Hu",
                Gender      = Gender.male,
                DateOfBirth = new DateTime(1992, 2, 14),
                Email       = "*****@*****.**",
                Phone       = "0425789632",
                CreateTime  = DateTime.Now,
                UpdateTime  = DateTime.Now,
            };

            using (var context = new PatientDbContext(dbOptionsBuilder.Options))
            {
                context.Patients.Add(testModel);
                context.SaveChanges();
                var entity = context.Patients.Single(p => p.Id == testModel.Id); //To Avoid tracking error
                context.Entry(entity).State = EntityState.Detached;
                var repo   = new PatientRepository(context);
                var result = await repo.UpdatePatientAsync(
                    new PatientModel()
                {
                    Id          = testModel.Id,
                    FirstName   = "Tee",
                    LastName    = "Hu",
                    Gender      = Gender.male,
                    DateOfBirth = new DateTime(1992, 2, 14),
                    Email       = "*****@*****.**",
                    Phone       = "0425789632",
                    CreateTime  = DateTime.Now,
                    UpdateTime  = DateTime.Now,
                });

                context.SaveChanges();
                Assert.AreEqual("Tee", result.FirstName);
            }
        }
        public IActionResult ChangeDoctorData(Doctor newDoctorData)
        {
            if (!context.Doctor.Any(d => d.IdDoctor == newDoctorData.IdDoctor))
            {
                return(NotFound("Such Doctor does not exists!"));
            }
            Doctor doctor = context.Doctor.Find(newDoctorData.IdDoctor);

            doctor.FirstName = newDoctorData.FirstName;
            doctor.LastName  = newDoctorData.LastName;
            doctor.Email     = newDoctorData.Email;
            context.SaveChanges();
            return(Ok("Updated"));
        }
Beispiel #3
0
        /// <summary>
        /// Seeds the specified patient database context.
        /// </summary>
        /// <param name="patientDbContext">The patient database context.</param>
        public static void Seed(this PatientDbContext patientDbContext)
        {
            patientDbContext.Add(new Patient
            {
                Forename        = $"Arindam",
                Surname         = $"Dhar",
                DateOfBirth     = Convert.ToDateTime("23/10/1985"),
                Gender          = true,
                TelephoneNumber = "{\"WorkNumber\" : \"123456789\"}"
            });

            patientDbContext.Add(new Patient
            {
                Forename        = $"User1",
                Surname         = $"Surname1",
                DateOfBirth     = Convert.ToDateTime("03/01/1989"),
                Gender          = true,
                TelephoneNumber = "{\"MobileNumber\" : \"123456789\", \"WorkNumber\" : \"234567\" }"
            });

            patientDbContext.Add(new Patient
            {
                Forename        = $"User2",
                Surname         = $"Surname2",
                DateOfBirth     = Convert.ToDateTime("03/01/1999"),
                Gender          = false,
                TelephoneNumber = "{\"MobileNumber\" : \"123456789\", \"HomeNumber\" : \"9998645\"}"
            });

            patientDbContext.SaveChanges();
        }
        public async Task PatientRepositroyUpdatePatientAsyncNullTest()
        {
            var testModel = new PatientModel()
            {
                Id          = new Guid(),
                FirstName   = "John",
                LastName    = "Hu",
                Gender      = Gender.male,
                DateOfBirth = new DateTime(1992, 2, 14),
                Email       = "*****@*****.**",
                Phone       = "0425789632",
                CreateTime  = DateTime.Now,
                UpdateTime  = DateTime.Now,
            };

            using (var context = new PatientDbContext(dbOptionsBuilder.Options))
            {
                context.Patients.Add(testModel);
                context.SaveChanges();
                var repo   = new PatientRepository(context);
                var result = await repo.UpdatePatientAsync(new PatientModel()
                {
                    Id = new Guid()
                });

                Assert.IsNull(result);
            }
        }
Beispiel #5
0
 public IActionResult AddPatient(Patient patientObj)
 {
     _logger.LogInformation("Add Patient");
     _db.Patients.Add(patientObj); //in memory
     _db.SaveChanges();            //physical commit
     return(Content("result"));
 }
        private void Save(object sender, RoutedEventArgs e)
        {
            patient.Title     = txtTitle.Text;
            patient.FirstName = txtFirstName.Text;
            patient.LastName  = txtLastName.Text;
            patient.PatientId = txtPatientId.Text;

            patient.Birthday = dtBirthday.DisplayDate;

            patient.Age     = Int32.Parse(txtAge.Text != "" ? txtAge.Text : "0");
            patient.AgeType = cbAgeType.SelectedIndex == 0 ? AgeType.Year : AgeType.Month;

            patient.StudyDate           = dtStudyDate.DisplayDate;
            patient.StudyDescription    = txtStudyDescription.Text;
            patient.RequestingPhysician = txtRequestingPhysician.Text;
            patient.AccessionNumber     = txtAccessionNumber.Text;
            patient.Note = txtNote.Text;

            //patient.Pregnant = cbPregnant.IsChecked == true ? true : false;
            patient.NA = cbNa.IsChecked == true ? true : false;

            patient.Gender = rdMale.IsChecked == true ? GenderType.Male : rdFemale.IsChecked == true ? GenderType.Female : GenderType.None;


            if (patient.FirstName.Trim() == "")
            {
                MessageControl messageControl = new MessageControl("Warning", "Please enter firstname!");
                messageControl.ShowDialog();
            }
            else if (patient.LastName.Trim() == "")
            {
                MessageControl messageControl = new MessageControl("Warning", "Please enter lastname!");
                messageControl.ShowDialog();
            }
            else if (patient.PatientId.Trim() == "")
            {
                MessageControl messageControl = new MessageControl("Warning", "Please enter patient ID!");
                messageControl.ShowDialog();
            }
            else
            {
                var item = patientDbContext.Patients.FirstOrDefault(i => i.Id == patient.Id);
                if (item == null || item.Id == -1)
                {
                    patient.Created = DateTime.Now;
                    patientDbContext.Patients.Add(patient);
                }
                else
                {
                    item = patient;
                }
                int value = patientDbContext.SaveChanges();

                if (value > -1)
                {
                    // MessageBox.Show("salam pesar!");
                    nowRefresh();
                }
            }
        }
Beispiel #7
0
        public Patient Insert(Patient p)
        {
            BeginTransaction();

            try
            {
                context.Database.UseTransaction(Transaction as System.Data.Common.DbTransaction);
                dapper.Transaction = Transaction;

                //context.Patients.Attach(p);
                context.Entry <Patient>(p).State = EntityState.Added;
                context.Patients.Add(p);
                context.SaveChanges();

                p.Address = "Updated Address Dpr";

                dapper.Update(p);

                Transaction.Commit();
            }
            catch (Exception ex)
            {
                Transaction.Rollback();
            }
            return(p);
        }
 public static void PopulateTestData(PatientDbContext dbContext)
 {
     dbContext.Patients.AddRange(new PatientEntity {
         Id = 1, Name = "TestPatient1"
     },
                                 new PatientEntity {
         Id = 2, Name = "TestPatient2"
     });
     dbContext.SaveChanges();
 }
        public IActionResult AddDoctor(DoctorRequest doctorRequest)
        {
            if (_context.Doctor.Any(e => e.IdDoctor == doctorRequest.IdDoctor))
            {
                return(BadRequest("Doctor already exists."));
            }
            else
            {
                var doctor = new Doctor()
                {
                    IdDoctor      = doctorRequest.IdDoctor,
                    Email         = doctorRequest.Email,
                    FirstName     = doctorRequest.FirstName,
                    LastName      = doctorRequest.LastName,
                    prescriptions = new List <Prescription>()
                };

                _context.Add(doctor);
                _context.SaveChanges();
                return(Ok("Doctor " + doctor.Email + " added!"));
            }
        }
        public void PatientRepositroyGetQueryablePatientTest()
        {
            var testData = TestDataGenerateHelper.createPatientModelData();

            using (var context = new PatientDbContext(dbOptionsBuilder.Options))
            {
                context.Patients.AddRange(testData);
                context.SaveChanges();
                var repo   = new PatientRepository(context);
                var result = repo.GetQueryablePatient();

                Assert.IsNotNull(result);
            }
        }
Beispiel #11
0
        private static void SeedSampleData(PatientDbContext dbContext)
        {
            dbContext.Patients.Add(new Entities.Patient
            {
                FirstName   = "Firstname",
                LastName    = "Lastname",
                Address     = "Address",
                DateOfBirth = DateTime.Today,
                Phone       = "111-222-3333",
                Sex         = "F"
            });

            dbContext.SaveChanges();
        }
        public async Task PatientRepositroyGetPatientByIdSuccessTest()
        {
            var testData = TestDataGenerateHelper.createPatientModelData();

            using (var context = new PatientDbContext(dbOptionsBuilder.Options))
            {
                context.Patients.AddRange(testData);
                context.SaveChanges();

                var repo   = new PatientRepository(context);
                var result = await repo.GetPatientByIdAsync(testData[0].Id);

                Assert.IsNotNull(result);
            }
        }
        public void AddPatient(Patient patient)
        {
            patient.DateOfBirth = patient.DateOfBirth.Date;

            try {
                _patientDbContext.Patients.Add(patient);
                _patientDbContext.SaveChanges();
            } catch (DbUpdateConcurrencyException e) {
                _logger.LogError(e, "A database concurrency error occured.");
                throw;
            } catch (Exception e) {
                _logger.LogError(e, "An error occured in the database service.");
                throw;
            }
        }
 public void createPatient(Patient entity)
 {
     _patientContext.Patients.Add(entity);
     _patientContext.SaveChanges();
 }