Exemplo n.º 1
0
 public bool DeleteAppointment(ref AppointmentBDO app, ref string message)
 {
     message = "Doctor deleted successfully";
     var ret = true;
     using (var PHEntities = new PublicHospitalEntities())
     {
         var appId = app.id;
         var appointmentInDb = (from a in PHEntities.Appointment
                      where a.id == appId
                      select a).FirstOrDefault();
         if (appointmentInDb != null)
         {
             PHEntities.Appointment.Remove(appointmentInDb);
             var num = PHEntities.SaveChanges();
             if (num != 1)
             {
                 ret = false;
             }
         }
         else
         {
             ret = false;
             message = "Appointment not found";
         }
         return ret;
     }
 }
Exemplo n.º 2
0
 public PatientBDO GetPatient(int id)
 {
     PatientBDO patientBDO = null;
     using (var PHEntities = new PublicHospitalEntities())
     {
         var patientObj = (from a in PHEntities.Patient
                         where a.id == id
                         select a).FirstOrDefault();
         if (patientObj != null)
             patientBDO = new PatientBDO()
             {
                 id = patientObj.id,
                 firstName = patientObj.firstName,
                 lastName = patientObj.lastName,
                 city = patientObj.city,
                 street = patientObj.street,
                 streetNr = patientObj.streetNr,
                 phoneNr = patientObj.phoneNr,
                 zip = patientObj.zip,
                 login = patientObj.login,
                 pass = patientObj.pass,
                 dateOfBirth = patientObj.dateOfBirth,
                 RowVersion = patientObj.rowVersion
             };
     }
     return patientBDO;
 }
Exemplo n.º 3
0
 public bool InsertPatient(ref PatientBDO patientBDO,
     ref string massage)
 {
     massage = "Patient inserted successfully";
     var ret = true;
     Password passObj = new Password();
     string[] passAndSalt = passObj.getFullyHash(patientBDO.pass);
     using (var PHEntities = new PublicHospitalEntities())
     {
         PHEntities.Patient.Add(new Patient
         {
             id = GetNextID(),
             firstName = patientBDO.firstName,
             lastName = patientBDO.lastName,
             city = patientBDO.city,
             street = patientBDO.street,
             streetNr = patientBDO.streetNr,
             phoneNr = patientBDO.phoneNr,
             zip = patientBDO.zip,
             login = patientBDO.login,
             dateOfBirth = patientBDO.dateOfBirth,
             rowVersion = patientBDO.RowVersion,
             pass = passAndSalt[0],
             salt = passAndSalt[1]
         });
         var num = PHEntities.SaveChanges();
         if (num != 1)
         {
             ret = false;
             massage = "Patient was not inserted";
         }
     }
     return ret;
 }
Exemplo n.º 4
0
 public List<VisitBDO> GetAllVisits()
 {
     List<VisitBDO> Visits = null;
     VisitBDO VisitBDO = null;
     using (var PHEntities = new PublicHospitalEntities())
     {
         var listInDb = (from d in PHEntities.Visit
                         select d).ToList();
         if (listInDb != null)
         {
             Visits = new List<VisitBDO>();
             VisitBDO = new VisitBDO();
             foreach (Visit VisitObj in listInDb)
             {
                 if (VisitObj != null)
                 {
                     VisitBDO = new VisitBDO()
                     {
                         id = VisitObj.Ap_Id,
                         patientProblem = VisitObj.patientProblem,
                         symptom = VisitObj.symptom,
                         advice = VisitObj.advice,
                         rowVersion = VisitObj.rowVersion
                     };
                     Visits.Add(VisitBDO);
                 }
             }
         }
     }
     return Visits;
 }
Exemplo n.º 5
0
 public AdminBDO GetAdmin(int id)
 {
     AdminBDO adminBDO = null;
     using (var PHEntities = new PublicHospitalEntities())
     {
         var adminObj = (from a in PHEntities.Admin
                      where a.id == id
                      select a).FirstOrDefault();
         if (adminObj != null)
             adminBDO = new AdminBDO()
             {
                 id = adminObj.id,
                 firstName = adminObj.firstName,
                 lastName = adminObj.lastName,
                 city = adminObj.city,
                 street = adminObj.street,
                 streetNr = adminObj.streetNr,
                 phoneNr = adminObj.phoneNr,
                 zip = adminObj.zip,
                 login = adminObj.login,
                 pass = adminObj.pass
             };
     }
         return adminBDO;
 }
Exemplo n.º 6
0
 public List<PatientBDO> GetAllpatients()
 {
     List<PatientBDO> patientList = null;
     using (var PHEntities = new PublicHospitalEntities())
     {
         var patientDatabase = from p in PHEntities.Patient select p;
         if ((patientDatabase.FirstOrDefault() != null))
         {
             patientList = new List<PatientBDO>();
             foreach (var patient in patientDatabase)
             {
                 patientList.Add(new PatientBDO()
                 {
                     id = patient.id,
                     firstName = patient.firstName,
                     lastName = patient.lastName,
                     city = patient.city,
                     street = patient.street,
                     streetNr = patient.streetNr,
                     phoneNr = patient.phoneNr,
                     zip = patient.zip,
                     login = patient.login,
                     pass = patient.pass,
                     dateOfBirth = patient.dateOfBirth,
                     RowVersion = patient.rowVersion
                 });
             }
         }
     }
     return patientList;
 }
Exemplo n.º 7
0
        public bool InsertAdmin(ref AdminBDO adminBDO,
            ref string massage)
        {
            massage = "Admin inserted successfully";
            var ret = true;
            Password passObj = new Password();
            string[] passAndSalt = passObj.getFullyHash(adminBDO.pass);
            using (var PHEntities = new PublicHospitalEntities())
            {
                PHEntities.Admin.Add(new Admin
                {
                    id = GetNextID(),
                    firstName = adminBDO.firstName,
                    lastName = adminBDO.lastName,
                    city = adminBDO.city,
                    street = adminBDO.street,
                    streetNr = adminBDO.streetNr,
                    phoneNr = adminBDO.phoneNr,
                    zip = adminBDO.zip,
                    login = adminBDO.login,

                    pass = passAndSalt[0],
                    salt = passAndSalt[1]
                });
                var num = PHEntities.SaveChanges();
                if (num != 1)
                {
                    ret = false;
                    massage = "Admin was not inserted";
                }
            }
            return ret;
        }
Exemplo n.º 8
0
 public List<AppointmentBDO> GetAllAppointments()
 {
     List<AppointmentBDO> appointments = null;
     AppointmentBDO appointmentBDO = null;
     PatientBDO patientBDO = null;
     DoctorBDO doctorBDO = null;
     using (var PHEntities = new PublicHospitalEntities())
     {
         var listInDb = (from Appointment in PHEntities.Appointment
                         from Doctor in PHEntities.Doctor
                         from Patient in PHEntities.Patient
                         where Appointment.idDoctor == Doctor.id &&
                         Appointment.idPatient == Patient.id
                         select new
                         {
                             Appointment.id,
                             Appointment.time,
                             Appointment.serviceType,
                             Doctor.firstName,
                             Doctor.lastName,
                             DoctorId = Doctor.id,
                             Column1 = Patient.firstName,
                             Column2 = Patient.lastName,
                             Column3 = Patient.id
                         });
         if (listInDb != null)
         {
             appointments = new List<AppointmentBDO>();
             foreach (var mergedList in listInDb)
             {
                 if (mergedList != null)
                 {
                     doctorBDO = new DoctorBDO();
                     patientBDO = new PatientBDO();
                     doctorBDO.firstName = mergedList.firstName;
                     doctorBDO.lastName = mergedList.lastName;
                     doctorBDO.id = mergedList.DoctorId;
                     patientBDO.firstName = mergedList.Column1;
                     patientBDO.lastName = mergedList.Column2;
                     patientBDO.id = mergedList.Column3;
                     appointmentBDO = new AppointmentBDO()
                     {
                         id = mergedList.id,
                         time = mergedList.time,
                         serviceType = mergedList.serviceType,
                         doctor = doctorBDO,
                         patient = patientBDO
                     };
                     appointments.Add(appointmentBDO);
                 }
             }
         }
     }
     return appointments;
 }
Exemplo n.º 9
0
 private string[] getPasswordSaltDB(string login)
 {
     using (var PHEntities = new PublicHospitalEntities())
     {
         string[] person = null;
         var admin = PHEntities.Admin.Where(a => a.login == login);
         var doctor = PHEntities.Doctor.Where(d => d.login == login);
         var patient = PHEntities.Patient.Where(p => p.login == login);
         if (admin.FirstOrDefault() != null)
             person = new string[] { admin.First().pass, admin.First().salt, admin.First().id.ToString(), "admin" };
         if (doctor.FirstOrDefault() != null)
             person = new string[] { doctor.First().pass, doctor.First().salt, doctor.First().id.ToString(), "doctor" };
         if (patient.FirstOrDefault() != null)
             person = new string[] { patient.First().pass, patient.First().salt, patient.First().id.ToString(), "patient" };
         return person;
     }
 }
Exemplo n.º 10
0
        private int GetNextID()
        {
            int nextID = -1;

            using (var PHEntities = new PublicHospitalEntities())
            {
                var ids = (from a in PHEntities.Patient select a.id).ToList();
                nextID = ids.Max();
            };

            if (nextID == -1)
            {
                throw new Exception("Patient id couldn't be generated");
            }
            else
            {
                return nextID + 1;
            }
        }
Exemplo n.º 11
0
 public VisitBDO GetVisit(int id)
 {
     VisitBDO VisitBDO = null;
     using (var PHEntities = new PublicHospitalEntities())
     {
         var VisitObj = (from v in PHEntities.Visit
                               where v.Ap_Id == id
                               select v).FirstOrDefault();
         if (VisitObj != null)
             VisitBDO = new VisitBDO()
             {
                 id = VisitObj.Ap_Id,
                 patientProblem = VisitObj.patientProblem,
                 symptom = VisitObj.symptom,
                 advice = VisitObj.advice,
                 rowVersion = VisitObj.rowVersion
             };
     }
     return VisitBDO;
 }
Exemplo n.º 12
0
        public bool UpdateAdmin(ref AdminBDO adminBDO,
            ref string massage)
        {
            massage = "Admin updated successfully";
            var ret = true;
            using (var PHEntites = new PublicHospitalEntities())
            {
                var adminId = adminBDO.id;
                var adminInDb = (from a
                                 in PHEntites.Admin
                                 where a.id == adminId
                                 select a).FirstOrDefault();
                if (adminInDb == null)
                {
                    throw new Exception("No admin with id " +
                                        adminBDO.id);
                }
                adminInDb.firstName = adminBDO.firstName;
                adminInDb.lastName = adminBDO.lastName;
                adminInDb.city = adminBDO.city;
                adminInDb.zip = adminBDO.zip;
                adminInDb.street = adminBDO.street;
                adminInDb.streetNr = adminBDO.streetNr;
                adminInDb.phoneNr = adminBDO.phoneNr;
                adminInDb.rowVersion = adminBDO.RowVersion;
                //without username and pass
                PHEntites.Admin.Attach(adminInDb);
                PHEntites.Entry(adminInDb).State = System.Data.Entity.EntityState.Modified;
                var num = PHEntites.SaveChanges();

                adminBDO.RowVersion = adminInDb.rowVersion;

                if (num != 1)
                {
                    ret = false;
                    massage = "Admin was not updated";
                }
            }
            return ret;
        }
Exemplo n.º 13
0
 public bool UpdatePatient(ref PatientBDO patientBDO,
     ref string massage)
 {
     massage = "Patient updated successfully";
     var ret = true;
     using (var PHEntites = new PublicHospitalEntities())
     {
         var patientId = patientBDO.id;
         var patientInDb = (from a
                          in PHEntites.Patient
                          where a.id == patientId
                          select a).FirstOrDefault();
         if (patientInDb == null)
         {
             throw new Exception("No patient with id " +
                                 patientBDO.id);
         }
         patientInDb.firstName = patientBDO.firstName;
         patientInDb.lastName = patientBDO.lastName;
         patientInDb.city = patientBDO.city;
         patientInDb.zip = patientBDO.zip;
         patientInDb.street = patientBDO.street;
         patientInDb.streetNr = patientBDO.streetNr;
         patientInDb.phoneNr = patientBDO.phoneNr;
         patientInDb.dateOfBirth = patientBDO.dateOfBirth;
         //without username and pass
         PHEntites.Patient.Attach(patientInDb);
         PHEntites.Entry(patientInDb).State = System.Data.Entity.EntityState.Modified;
         var num = PHEntites.SaveChanges();
         if (num != 1)
         {
             ret = false;
             massage = "Patient was not updated";
         }
     }
     return ret;
 }
Exemplo n.º 14
0
 public bool InsertVisit(ref VisitBDO VisitBDO,
     ref string massage)
 {
     massage = "Visit inserted successfully";
     var ret = true;
     using (var PHEntities = new PublicHospitalEntities())
     {
         PHEntities.Visit.Add(new Visit
         {
             Ap_Id = VisitBDO.id,
             advice = VisitBDO.advice,
             symptom = VisitBDO.symptom,
             patientProblem = VisitBDO.patientProblem,
             rowVersion = VisitBDO.rowVersion
         });
         var num = PHEntities.SaveChanges();
         if (num != 1)
         {
             ret = false;
             massage = "Visit was not inserted";
         }
     }
     return ret;
 }
Exemplo n.º 15
0
 private string setSessionIdDB(string idd, int type)
 {
     string sessionID = getSessionID();
     int changes = 0;
     using (var PHEntities = new PublicHospitalEntities())
     {
         int id = 0;
         Int32.TryParse(idd, out id);
         switch (type)
         {
             case 0:
                 var admin = (from a in PHEntities.Admin where a.id == id select a).FirstOrDefault();
                 admin.sessionID = sessionID;
                 changes = PHEntities.SaveChanges();
                 break;
             case 1:
                 var doctor = (from a in PHEntities.Doctor where a.id == id select a).FirstOrDefault();
                 doctor.sessionID = sessionID;
                 changes = PHEntities.SaveChanges();
                 break;
             case 2:
                 var patient = (from a in PHEntities.Patient where a.id == id select a).FirstOrDefault();
                 patient.sessionID = sessionID;
                 changes = PHEntities.SaveChanges();
                 break;
         }
         if (changes != 1)
             sessionID = null;
     }
     return sessionID;
 }
Exemplo n.º 16
0
 public List<AppointmentBDO> GetAllAppointmentsByPatient(int patientId)
 {
     List<AppointmentBDO> appointments = null;
     AppointmentBDO appointmentBDO = null;
     using (var PHEntities = new PublicHospitalEntities())
     {
         var listInDb = (from appointment in PHEntities.Appointment
                         where appointment.idPatient == patientId
                         select appointment).ToList();
         if (listInDb != null)
         {
             appointments = new List<AppointmentBDO>();
             foreach (Appointment app in listInDb)
             {
                 appointmentBDO = new AppointmentBDO()
                 {
                     id = app.id,
                     time = Convert.ToDateTime(app.time),
                     serviceType = app.serviceType,
                     patient = new PatientBDO(),
                     doctor = new DoctorBDO(),
                     rowVersion = app.rowVersion
                 };
                 appointmentBDO.patient.id = (int)app.idPatient;
                 appointmentBDO.doctor.id = (int)app.idDoctor;
                 appointments.Add(appointmentBDO);
             }
             return appointments;
         }
         else
         {
             return null;
         }
     }
 }
Exemplo n.º 17
0
 public bool UpdateVisit(ref VisitBDO VisitBDO)
 {
     var ret = true;
     using (var PHEntites = new PublicHospitalEntities())
     {
         var VisitId = VisitBDO.id;
         var VisitInDb = (from a
                          in PHEntites.Visit
                                where a.Ap_Id == VisitId
                                select a).FirstOrDefault();
         if (VisitInDb == null)
         {
             throw new Exception("No Visit with id " +
                                 VisitBDO.id);
         }
         VisitInDb.Ap_Id = VisitBDO.id;
         VisitInDb.advice = VisitBDO.advice;
         VisitInDb.symptom = VisitBDO.symptom;
         VisitInDb.patientProblem = VisitBDO.patientProblem;
         VisitInDb.rowVersion = VisitBDO.rowVersion;
         //without username and pass
         PHEntites.Visit.Attach(VisitInDb);
         PHEntites.Entry(VisitInDb).State = System.Data.Entity.EntityState.Modified;
         var num = PHEntites.SaveChanges();
         VisitBDO.rowVersion = VisitInDb.rowVersion;
         if (num != 1)
         {
             ret = false;
         }
     }
     return ret;
 }
Exemplo n.º 18
0
 public AppointmentBDO GetAppointment(int id)
 {
     AppointmentBDO appointmentBDO = null;
     using (var PHEntities = new PublicHospitalEntities())
     {
         var appointmentObj = (from a in PHEntities.Appointment
                               where a.id == id
                               select a).FirstOrDefault();
         if (appointmentObj != null)
         {
             patientDAO = new PatientDAO();
             doctorDAO = new DoctorDAO();
             appointmentBDO = new AppointmentBDO()
             {
                 id = appointmentObj.id,
                 time = Convert.ToDateTime(appointmentObj.time),
                 serviceType = appointmentObj.serviceType,
                 patient = patientDAO.GetPatient(appointmentObj.idPatient.Value),
                 doctor = doctorDAO.GetDoctor(appointmentObj.idDoctor.Value),
                 rowVersion = appointmentObj.rowVersion
             };
         }
     }
     return appointmentBDO;
 }
Exemplo n.º 19
0
 public List<string> getAppointmentsByDocAndDate(DateTime date, int docId)
 {
     List<string> appTimes;
     using (var PHEntities = new PublicHospitalEntities())
     {
         var listInDb = (from appointment in PHEntities.Appointment
                         where appointment.idDoctor == docId &&
                         appointment.time.Year == date.Year &&
                         appointment.time.Month == date.Month &&
                         appointment.time.Day == date.Day
                         select new
                         {
                             appointment.time
                         }).ToList();
         appTimes = new List<string>();
         if (listInDb != null)
         {
             foreach (var d in listInDb)
             {
                 appTimes.Add(d.time.ToString("HH:mm"));
             }
         }
     }
     return appTimes;
 }
Exemplo n.º 20
0
 public bool GetAppointmentsHistoryPatient(ref PatientBDO patient, ref string message)
 {
     bool succesful = false;
     using (var PHEntities = new PublicHospitalEntities())
     {
         int patientID = patient.id;
         var appointments = PHEntities.Appointment.Where(a => a.idPatient == patientID);
         if (appointments.FirstOrDefault() != null)
         {
             VisitDAO visitDAO = new VisitDAO();
             List<AppointmentBDO> appointmentList = new List<AppointmentBDO>();
             foreach (var appointment in appointments)
             {
                 appointmentList.Add(new AppointmentBDO()
                 {
                     id = appointment.id,
                     time = Convert.ToDateTime(appointment.time),
                     serviceType = appointment.serviceType,
                     doctor = new DoctorDAO().GetDoctor(appointment.idDoctor.Value),
                     visit = visitDAO.GetVisit(appointment.id)
                 });
             }
             if (appointmentList != null)
             {
                 patient.appointmentsHistory = appointmentList;
                 succesful = true;
             }
             else
                 message = "Appointment list is empty";
         }
         else
             message = "Can not get id from the database appointment";
     }
     return succesful;
 }
Exemplo n.º 21
0
 public bool InsertAppointment(ref AppointmentBDO appointmentBDO,
 ref string massage)
 {
     massage = "Appointment inserted successfully";
     var ret = true;
     using (var PHEntities = new PublicHospitalEntities())
     {
         PHEntities.Appointment.Add(new Appointment
         {
             id = appointmentBDO.id,
             time = appointmentBDO.time,
             serviceType = appointmentBDO.serviceType,
             idPatient = appointmentBDO.patient.id,
             idDoctor = appointmentBDO.doctor.id,
             rowVersion = appointmentBDO.rowVersion
         });
         var num = PHEntities.SaveChanges();
         if (num != 1)
         {
             ret = false;
             massage = "Appointment was not inserted";
         }
     }
     return ret;
 }
Exemplo n.º 22
0
        public bool Updateappointment(ref AppointmentBDO appointmentBDO,
        ref string massage)
        {
            massage = "appointment updated successfully";
            var ret = true;
            using (var PHEntites = new PublicHospitalEntities())
            {
                var appointmentId = appointmentBDO.id;
                var appointmentInDb = (from a
                in PHEntites.Appointment
                                       where a.id == appointmentId
                                       select a).FirstOrDefault();
                if (appointmentInDb == null)
                {
                    throw new Exception("No appointment with id " +
                    appointmentBDO.id);
                }
                appointmentInDb.id = appointmentBDO.id;
                appointmentInDb.time = appointmentBDO.time.Date;
                appointmentInDb.serviceType = appointmentBDO.serviceType;
                appointmentInDb.idPatient = appointmentBDO.patient.id;
                appointmentInDb.idDoctor = appointmentBDO.patient.id;
                appointmentInDb.rowVersion = appointmentBDO.rowVersion;
                PHEntites.Appointment.Attach(appointmentInDb);
                PHEntites.Entry(appointmentInDb).State = System.Data.Entity.EntityState.Modified;
                var num = PHEntites.SaveChanges();

                appointmentBDO.rowVersion = appointmentInDb.rowVersion;
                if (num != 1)
                {
                    ret = false;
                    massage = "appointment was not updated";
                }
            }
            return ret;
        }
Exemplo n.º 23
0
 private string getSessionIdDB(int id)
 {
     string sessionID = null;
     using (var PHEntities = new PublicHospitalEntities())
     {
         var admin = from a in PHEntities.Admin where a.id == id select a;
         var doctor = from a in PHEntities.Doctor where a.id == id select a;
         var patient = from a in PHEntities.Patient where a.id == id select a;
         if (admin.FirstOrDefault() != null)
             sessionID = admin.First().sessionID.ToString();
         else if (doctor.FirstOrDefault() != null)
             sessionID = doctor.First().sessionID.ToString();
         else if (patient.FirstOrDefault() != null)
             sessionID = patient.First().sessionID.ToString();
     }
     return sessionID;
 }