Пример #1
0
 public static void AddSingleCompleteRelationships(DataBaseContext context, DbVisit visit, DbMedicalWorker medicalWorker, DbPatient patient, DbSpecialization specialization)
 {
     if (!medicalWorker.Specializations.Contains(context.Specializations.SingleOrDefault(x => x.Id == specialization.Id)))
     {
         throw new Exception("In function AddSingleCompleteRelationships medicalWorker doesn't have required specialization");
     }
     AddSingleRelationship(context, visit, medicalWorker);
     AddSingleRelationship(context, visit, patient);
     AddSingleRelationship(context, visit, specialization);
 }
        private void RegisterVisitButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (DataHolderForMainWindow.PatientId == -1)
                {
                    throw new Exception("You need to select patient first!");
                }
                using (var context = new DataBaseContext())
                {
                    DateTime dateTime = DateTime.Now;
                    for (int i = 1; i <= 7; i++)
                    {
                        if (DayOfWeekTextBlock.Text == DateTime.Now.AddDays(i).DayOfWeek.ToString())
                        {
                            dateTime = DateTime.Now.AddDays(i);
                            dateTime = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, TimeForNewVisit.Hour, TimeForNewVisit.Minute, 0);
                        }
                    }
                    int localMedicalWorkerId  = Convert.ToInt32(MedicalWorkerIdHolderHack.Text);
                    var localMedicalWorker    = context.MedicalWorkers.Single(x => x.Id == localMedicalWorkerId);
                    int localSpecializationId = Convert.ToInt32(SpecializationIdHolderHack.Text);
                    var localSpecialization   = context.Specializations.Single(x => x.Id == localSpecializationId);

                    if (context.Visits.Any(x => x.MedicalWorker.Id == localMedicalWorkerId && x.TimeStart == TimeForNewVisit))
                    {
                        throw new Exception("Nie mogą odbywać się 2 wizyty w tym samym czasie. Proszę wybrać inną godzinę.");
                    }

                    DbVisit visit = new DbVisit()
                    {
                        MedicalWorker       = localMedicalWorker,
                        Specialization      = localSpecialization,
                        OptionalDescription = "",
                        Patient             = context.Patients.Single(x => x.Id == DataHolderForMainWindow.PatientId),
                        TimeStart           = TimeForNewVisit
                    };
                    context.Visits.AddOrUpdate(x => x.Id, visit);
                    context.SaveChanges();

                    context.MedicalWorkers.Single(x => x.Id == localMedicalWorkerId).Visits.Add(visit);
                    context.Patients.Single(x => x.Id == DataHolderForMainWindow.PatientId).Visits.Add(visit);
                    context.SaveChanges();

                    MessageBox.Show("Wizyta odbędzie się: " + dateTime.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #3
0
        private void EditDescriptionButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var visitId = VisitsList[VisitsListView.SelectedIndex].VisitId;

                using (var context = new DataBaseContext())
                {
                    DbVisit visit = context.Visits.SingleOrDefault(x => x.Id == visitId);
                    visit.OptionalDescription = DescriptionTextBox.Text;
                    context.SaveChanges();
                }
                ResetTab();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #4
0
        private void EditDescriptionButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var visitId = VisitsList[VisitsListView.SelectedIndex].VisitId;

                using (var context = new DataBaseContext())
                {
                    DbVisit visit = context.Visits.SingleOrDefault(x => x.Id == visitId);
                    if (visit.TimeStart < DateTime.Now)
                    {
                        throw new Exception("You cannot change visits that have already taken place!");
                    }
                    visit.OptionalDescription = DescriptionTextBox.Text;
                    context.SaveChanges();
                }
                ResetTab();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #5
0
 private static void AddSingleRelationship(DataBaseContext context, DbVisit visit, DbSpecialization specialization)
 {
     context.Visits.SingleOrDefault(v => v.Id == visit.Id).Specialization = context.Specializations.SingleOrDefault(s => s.Id == specialization.Id);
 }
Пример #6
0
 private static void AddSingleRelationship(DataBaseContext context, DbVisit visit, DbPatient patient)
 {
     context.Visits.SingleOrDefault(v => v.Id == visit.Id).Patient = context.Patients.SingleOrDefault(p => p.Id == patient.Id);
     context.Patients.SingleOrDefault(p => p.Id == patient.Id).Visits.Add(context.Visits.SingleOrDefault(v => v.Id == visit.Id));
 }
Пример #7
0
 private static void AddSingleRelationship(DataBaseContext context, DbVisit visit, DbMedicalWorker medicalWorker)
 {
     context.Visits.SingleOrDefault(v => v.Id == visit.Id).MedicalWorker = context.MedicalWorkers.SingleOrDefault(mw => mw.Id == medicalWorker.Id);
     context.MedicalWorkers.SingleOrDefault(mw => mw.Id == medicalWorker.Id).Visits.Add(context.Visits.SingleOrDefault(v => v.Id == visit.Id));
 }
Пример #8
0
 public static void AddSingleRelationship(DataBaseContext context, DbVisit visit, DbTreatment treatment)
 {
     context.Treatments.SingleOrDefault(t => t.Id == treatment.Id).Visit = context.Visits.SingleOrDefault(v => v.Id == visit.Id);
 }
Пример #9
0
        public async Task CreateAsync(Visit place)
        {
            await _context.Visits.AddAsync(DbVisit.Create(place));

            await _context.SaveChangesAsync();
        }