public List <PatientMedication> getPatientMedications(Patient patient)
 {
     using (pde = new PatientDatabaseEntities())
     {
         return(pde.Patients.FirstOrDefault(p => p.Id == patient.Id).PatientMedications.OrderBy(p => p.Medication.Name).ToList());
     }
 }
        private void btnChooseImage_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.Filter = "JPG Files (*.jpg)|*.jpg|All Files (*.*)|*.*";
                dlg.Title  = "Select Patient Picture";
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    string imageLoc = dlg.FileName.ToString();
                    Image  img      = Image.FromFile(imageLoc);
                    img.Save("sih", System.Drawing.Imaging.ImageFormat.Jpeg);

                    byte[]       image = null;
                    FileStream   fs    = new FileStream(imageLoc, FileMode.Open, FileAccess.Read);
                    BinaryReader br    = new BinaryReader(fs);
                    image = br.ReadBytes((int)fs.Length);
                    using (PatientDatabaseEntities pde = new PatientDatabaseEntities())
                    {
                        PatientImage patientImage = pde.PatientImages.FirstOrDefault(pi => pi.PatientID == 3);
                        patientImage.Image = image;
                        pde.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 public Surgery loadSurgery(int id)
 {
     using (pde = new PatientDatabaseEntities())
     {
         return(pde.Surgeries.FirstOrDefault(s => s.Id == id));
     }
 }
 public Past_Medical_History loadPastMedicalHistory(int id)
 {
     using (pde = new PatientDatabaseEntities())
     {
         return(pde.Past_Medical_History.FirstOrDefault(pmh => pmh.Id == id));
     }
 }
 public List <Patient> loadPatientsFromQuery(List <Query> queries)
 {
     queries = formatQueriesList(queries);
     using (PatientDatabaseEntities pde = new PatientDatabaseEntities())
     {
         IQueryable <Patient> queryBuilder = pde.Set <Patient>();
         var predicate = PredicateBuilder.True <Patient>();
         foreach (Query query in queries)
         {
             if (query.StandAlone || query.StartGroup)
             {
                 predicate = PredicateBuilder.True <Patient>();
                 predicate = predicate.And(query.runQuery());
             }
             else if (query.ContinueGroup || query.EndGroup)
             {
                 predicate = predicate.Or(query.runQuery());
             }
             if (query.StandAlone || query.EndGroup)
             {
                 queryBuilder = queryBuilder.Where(predicate);
             }
         }
         return(queryBuilder.AsExpandable().OrderBy(p => p.Last_Name).ThenBy(p => p.First_Name).ToList());
     }
 }
 public List <PatientOutcome> getPatientOutcome(Patient patient)
 {
     using (pde = new PatientDatabaseEntities())
     {
         return(pde.Patients.FirstOrDefault(p => p.Id == patient.Id).PatientOutcomes.OrderBy(p => p.Outcome.Id).ThenBy(p => p.Protocol.Id).ToList());
     }
 }
 public PatientImage getPatientImage(Patient patient)
 {
     using (pde = new PatientDatabaseEntities())
     {
         return(pde.PatientImages.FirstOrDefault(pi => pi.PatientID == patient.Id));
     }
 }
 public Medication loadMedication(int id)
 {
     using (pde = new PatientDatabaseEntities())
     {
         return(pde.Medications.FirstOrDefault(m => m.Id == id));
     }
 }
 public List <PatientTreatment> getPatientTreatment(Patient patient)
 {
     using (pde = new PatientDatabaseEntities())
     {
         return(pde.Patients.FirstOrDefault(p => p.Id == patient.Id).PatientTreatments.OrderBy(p => p.Treatment.Name).ToList());
     }
 }
 public List <PatientProblem> getPatientProblem(Patient patient)
 {
     using (pde = new PatientDatabaseEntities())
     {
         return(pde.Patients.FirstOrDefault(p => p.Id == patient.Id).PatientProblems.OrderBy(p => p.Problem.Name).ToList());
     }
 }
 public List <PatientSurgery> getPatientSurgery(Patient patient)
 {
     using (pde = new PatientDatabaseEntities())
     {
         return(pde.Patients.FirstOrDefault(p => p.Id == patient.Id).PatientSurgeries.OrderBy(p => p.Surgery.Name).ToList());
     }
 }
 public Patient loadPatient(int id)
 {
     using (pde = new PatientDatabaseEntities())
     {
         return(pde.Patients.FirstOrDefault(p => p.Id == id));
     }
 }
 public Trauma loadTrauma(int id)
 {
     using (pde = new PatientDatabaseEntities())
     {
         return(pde.Traumata.FirstOrDefault(t => t.Id == id));
     }
 }
 public Protocol loadProtocol(int id)
 {
     using (pde = new PatientDatabaseEntities())
     {
         return(pde.Protocols.FirstOrDefault(p => p.Id == id));
     }
 }
 public void establishConnection()
 {
     using (pde = new PatientDatabaseEntities(ConnectionString))
     {
         Patient patient = pde.Patients.FirstOrDefault();
     }
 }
 public Treatment loadTreatment(int id)
 {
     using (pde = new PatientDatabaseEntities())
     {
         return(pde.Treatments.FirstOrDefault(t => t.Id == id));
     }
 }
 public List <ProtocolOutcome> getProtocolOutcome(Protocol protocol)
 {
     using (pde = new PatientDatabaseEntities())
     {
         return(pde.Protocols.FirstOrDefault(p => p.Id == protocol.Id).ProtocolOutcomes.OrderBy(p => p.Outcome.Id).ToList());
     }
 }
 public List <PatientPast_Medical_History> getPatientPastMedicalHistory(Patient patient)
 {
     using (pde = new PatientDatabaseEntities())
     {
         return(pde.Patients.FirstOrDefault(p => p.Id == patient.Id).PatientPast_Medical_History.OrderBy(p => p.Past_Medical_History.Name).ToList());
     }
 }
 public List <Protocol> loadProtocolTable(string filter)
 {
     using (pde = new PatientDatabaseEntities())
     {
         if (filter == "")
         {
             return(pde.Protocols.ToList());
         }
         else
         {
             return(pde.Protocols.Where(p => p.Name.StartsWith(filter)).OrderBy(t => t.Name).ToList());
         }
     }
 }
 public List <Treatment> loadTreatmentTable(string filter)
 {
     using (pde = new PatientDatabaseEntities())
     {
         if (filter == "")
         {
             return(pde.Treatments.ToList());
         }
         else
         {
             return(pde.Treatments.Where(t => t.Name.StartsWith(filter)).OrderBy(t => t.Name).ToList());
         }
     }
 }
 public List <Pathology> loadPathologyTable(string filter)
 {
     using (pde = new PatientDatabaseEntities())
     {
         if (filter == "")
         {
             return(pde.Pathologies.ToList());
         }
         else
         {
             return(pde.Pathologies.Where(p => p.Name.StartsWith(filter)).OrderBy(p => p.Name).ToList());
         }
     }
 }
 public List <Surgery> loadSurgeryTable(string filter)
 {
     using (pde = new PatientDatabaseEntities())
     {
         if (filter == "")
         {
             return(pde.Surgeries.ToList());
         }
         else
         {
             return(pde.Surgeries.Where(s => s.Name.StartsWith(filter)).OrderBy(s => s.Name).ToList());
         }
     }
 }
 public List <Medication> loadMedicationTable(string filter)
 {
     using (pde = new PatientDatabaseEntities())
     {
         if (filter == "")
         {
             return(pde.Medications.ToList());
         }
         else
         {
             return(pde.Medications.Where(m => m.Name.StartsWith(filter)).OrderBy(m => m.Name).ThenBy(m => m.Type).ToList());
         }
     }
 }
 public List <Past_Medical_History> loadPastMedicalHistoryTable(string filter)
 {
     using (pde = new PatientDatabaseEntities())
     {
         if (filter == "")
         {
             return(pde.Past_Medical_History.ToList());
         }
         else
         {
             return(pde.Past_Medical_History.Where(pmh => pmh.Name.StartsWith(filter)).OrderBy(pmh => pmh.Name).ToList());
         }
     }
 }
 public int getTableRecordCount(string table)
 {
     using (pde = new PatientDatabaseEntities())
     {
         if (table == "Patient")
         {
             return(pde.Patients.Count());
         }
         else if (table == "Medication")
         {
             return(pde.Medications.Count());
         }
         else if (table == "PastMedicalHistory")
         {
             return(pde.Past_Medical_History.Count());
         }
         else if (table == "Pathology")
         {
             return(pde.Pathologies.Count());
         }
         else if (table == "Problem")
         {
             return(pde.Problems.Count());
         }
         else if (table == "Trauma")
         {
             return(pde.Traumata.Count());
         }
         else if (table == "Treatment")
         {
             return(pde.Treatments.Count());
         }
         else
         {
             return(0);
         }
     }
 }