private void btnAddProcedure_Click(object sender, RoutedEventArgs e)
        {
            listProceduresAdmin.Items.Add(cboxProcedures.SelectedItem);

            AdministeredProcedure newAdminPro = new AdministeredProcedure();

            var intakeDatum = CTUCareDB.Instance.Appointments.Where(x => x.PatientID == currentPatient).FirstOrDefault().IntakeDateID;

            newAdminPro.PatientID   = currentPatient;
            newAdminPro.ProcedureID = CTUCareDB.Instance.Procedures.Where(x => x.Name == cboxProcedures.SelectedItem.ToString()).FirstOrDefault().ID;
            newAdminPro.EntryDateID = intakeDatum;

            CTUCareDB.Instance.AdministeredProcedures.Add(newAdminPro);
        }
Beispiel #2
0
        private void btnSaveAppointment_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var patient    = patientList.SelectedItem.ToString();
                var appPatient = CTUCareDB.Instance.Patients.Where(x => x.Name == patient).FirstOrDefault();

                var doctor    = cBoxDr.SelectedItem.ToString();
                var appDoctor = CTUCareDB.Instance.Doctors.Where(x => x.Name == doctor).FirstOrDefault();

                var procedure    = cBoxProcedure.SelectedItem.ToString();
                var appProcedure = CTUCareDB.Instance.Procedures.Where(x => x.Name == procedure).FirstOrDefault();

                var intakeDate = dateIntake.SelectedDate;

                var dispatchDate = dateDispatch.SelectedDate;

                EntryDate             loadNewEntry = new EntryDate();
                Appointment           loadNewApp   = new Appointment();
                AdministeredProcedure loadNewPro   = new AdministeredProcedure();

                loadNewEntry.PatientID   = appPatient.ID;
                loadNewEntry.DateEntered = intakeDate;

                db.EntryDates.Add(loadNewEntry);
                db.SaveChanges();

                //Done after entry dates were added so that an ID can be assigned
                var entryDate   = CTUCareDB.Instance.EntryDates.Where(x => x.PatientID == loadNewEntry.PatientID).ToList();
                var entryDateID = entryDate.Last().ID;

                loadNewApp.PatientID    = appPatient.ID;
                loadNewApp.IntakeDateID = entryDateID;
                loadNewApp.DrID         = appDoctor.ID;


                //Only adds if the checkbox is unchecked
                if (checkBox.IsChecked == false)
                {
                    loadNewApp.SheduledDispatchDate = (DateTime)dispatchDate;
                }

                db.Appointments.Add(loadNewApp);
                db.SaveChanges();

                //Done after appointments to generate an ID
                loadNewPro.PatientID   = appPatient.ID;
                loadNewPro.ProcedureID = appProcedure.ID;
                loadNewPro.EntryDateID = entryDateID;

                db.AdministeredProcedures.Add(loadNewPro);

                db.SaveChanges();
            }
            catch (Exception)
            {
                MessageBox.Show("One or more fields still require entries, refer to user manual for more details");
            }

            Appointments goBack = new Appointments();

            goBack.Show();
            this.Close();
        }