コード例 #1
0
        /// <summary>
        /// Adds new appointment
        /// </summary>
        /// <returns></returns>
        public static int InsertAppointment(int doctorid, int patientid, int statusid, string date, string time, string notes)
        {
            try
            {
                HealtheeEntities db = new HealtheeEntities();
                if (DEBUG)
                {
                    db.Database.Log = Console.WriteLine;
                }
                Appointment a = new Appointment
                {
                    DoctorID        = doctorid,
                    PatientID       = patientid,
                    StatusID        = statusid,
                    AppointmentDate = date,
                    AppointmentTime = time,
                    Notes           = notes
                };

                db.Appointments.Add(a);
                db.SaveChanges();
                return(a.AppointmentID);
            }
            catch (Exception e)
            {
                return(0);
            }
        }
コード例 #2
0
        /// <summary>
        /// Inserts row do Activity table
        /// </summary>
        /// <param name="activityType"></param>
        /// <param name="doctorID"></param>
        /// <param name="statusID"></param>
        /// <param name="details"></param>
        /// <param name="data"></param>
        public static void AddDoctorActivity(int activityType, int doctorID, int statusID, string details, string data)
        {
            try
            {
                HealtheeEntities db = new HealtheeEntities();
                if (DEBUG)
                {
                    db.Database.Log = Console.WriteLine;
                }

                db.Activities.Add(new Activity()
                {
                    ActivityTypeID = activityType,
                    DoctorID       = doctorID,
                    StatusID       = statusID,
                    Details        = details,
                    Data           = data,
                    ActivityDate   = DateTime.Now
                });
                db.SaveChanges();
            }
            catch (Exception e)
            {
                // log exception
            }
        }
コード例 #3
0
        /// <summary>
        /// Inserts doctor data
        /// returns last inserted id
        /// </summary>
        /// <returns></returns>
        public static int InsertDoctor(int personId, int doctortypeid, string username, string password)
        {
            // perform encryption on password
            try
            {
                HealtheeEntities db = new HealtheeEntities();
                if (DEBUG)
                {
                    db.Database.Log = Console.WriteLine;
                }
                Doctor d = new Doctor
                {
                    PersonID     = personId,
                    DoctorTypeID = doctortypeid,
                    Username     = username,
                    Password     = password
                };

                db.Doctors.Add(d);
                db.SaveChanges();
                return(d.DoctorID);
            }
            catch (Exception e)
            {
                return(0);
            }
        }
コード例 #4
0
        /// <summary>
        ///  GEt doctor data
        /// </summary>
        /// <param name="doctorid"></param>
        /// <returns></returns>
        public static DoctorData GetDoctorData(int doctorid)
        {
            try
            {
                HealtheeEntities db = new HealtheeEntities();
                if (DEBUG)
                {
                    db.Database.Log = Console.WriteLine;
                }

                var query = from person in db.People
                            join doctors in db.Doctors on person.PersonID equals doctors.PersonID
                            join doctortypes in db.DoctorTypes on doctors.DoctorTypeID equals doctortypes.DoctorTypeID
                            where doctors.DoctorID == doctorid
                            where doctors.DoctorTypeID == doctortypes.DoctorTypeID
                            select new DoctorData()
                {
                    Person     = person,
                    DoctorID   = doctorid,
                    DoctorType = doctortypes.Type,
                    Username   = doctors.Username
                };
                DoctorData data = query.FirstOrDefault();
                return(data);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #5
0
        /// <summary>
        /// Basic search functionality
        /// - returns doctor data in list form
        /// </summary>
        /// <returns></returns>
        public static List <DoctorData> GetDoctors(string firstName, string lastName, string city)
        {
            try
            {
                HealtheeEntities db = new HealtheeEntities();
                if (DEBUG)
                {
                    db.Database.Log = Console.WriteLine;
                }

                var query = from p in db.People
                            join doctors in db.Doctors on p.PersonID equals doctors.PersonID
                            join doctortypes in db.DoctorTypes on doctors.DoctorTypeID equals doctortypes.DoctorTypeID
                            where (string.IsNullOrEmpty(firstName) ? true : p.FirstName == firstName) &&
                            (string.IsNullOrEmpty(lastName) ? true : p.LastName == lastName) &&
                            (string.IsNullOrEmpty(city) ? true : p.City == city)
                            select new DoctorData()
                {
                    Person     = p,
                    DoctorID   = doctors.DoctorID,
                    DoctorType = doctortypes.Type,
                    Username   = doctors.Username
                };
                return(query.ToList <DoctorData>());
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #6
0
        /// <summary>
        /// Updates medical record
        /// </summary>
        /// <param name="allergies"></param>
        /// <param name="medication"></param>
        /// <param name="notes"></param>
        /// <returns></returns>
        public static bool UpdateMedicalRecord(int medicalrecordid, string allergies, string medication, string notes)
        {
            try
            {
                HealtheeEntities db = new HealtheeEntities();
                if (DEBUG)
                {
                    db.Database.Log = Console.WriteLine;
                }

                var query = from med in db.MedicalRecords
                            where med.MedicalRecordID == medicalrecordid
                            select med;
                MedicalRecord medrecord = query.FirstOrDefault();
                medrecord.Allergies  = allergies;
                medrecord.Medication = medication;
                medrecord.Notes      = notes;
                db.SaveChanges();

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
コード例 #7
0
        /// <summary>
        /// Inserts a medical record
        /// </summary>
        /// <param name="allergies"></param>
        /// <param name="medication"></param>
        /// <param name="notes"></param>
        /// <returns></returns>
        public static int InsertMedicalRecord(string allergies, string medication, string notes)
        {
            try
            {
                HealtheeEntities db = new HealtheeEntities();
                if (DEBUG)
                {
                    db.Database.Log = Console.WriteLine;
                }
                MedicalRecord m = new MedicalRecord
                {
                    Allergies  = allergies,
                    Medication = medication,
                    Notes      = notes
                };

                db.MedicalRecords.Add(m);
                db.SaveChanges();
                return(m.MedicalRecordID);
            }
            catch (Exception e)
            {
                return(0);
            }
        }
コード例 #8
0
        /// <summary>
        /// Basic search functionality
        /// - returns patient data in list form
        /// </summary>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <param name="nationalID"></param>
        /// <param name="mobileNumber"></param>
        /// <returns></returns>
        public static List <PatientData> GetPatients(string firstName, string lastName, string nationalID, string mobileNumber)
        {
            try
            {
                HealtheeEntities db = new HealtheeEntities();
                if (DEBUG)
                {
                    db.Database.Log = Console.WriteLine;
                }

                var query = from p in db.People
                            join patients in db.Patients on p.PersonID equals patients.PersonID
                            join medrecords in db.MedicalRecords on patients.MedicalRecordID equals medrecords.MedicalRecordID
                            where (string.IsNullOrEmpty(firstName) ? true : p.FirstName == firstName) &&
                            (string.IsNullOrEmpty(lastName) ? true : p.LastName == lastName) &&
                            (string.IsNullOrEmpty(nationalID) ? true : p.NationalID == nationalID) &&
                            (string.IsNullOrEmpty(mobileNumber) ? true : p.MobileNumber == mobileNumber)
                            select new PatientData()
                {
                    Person          = p,
                    PatientID       = patients.PatientID,
                    MedicalRecordID = patients.MedicalRecordID,
                    Allergies       = medrecords.Allergies,
                    Medication      = medrecords.Medication,
                    Notes           = medrecords.Notes
                };
                return(query.ToList <PatientData>());
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #9
0
        /// <summary>
        /// Returns patient data using patient id
        /// </summary>
        /// <param name="patientID"></param>
        /// <returns></returns>
        public static PatientData GetPatientData(int patientID)
        {
            try
            {
                HealtheeEntities db = new HealtheeEntities();
                if (DEBUG)
                {
                    db.Database.Log = Console.WriteLine;
                }

                var query = from person in db.People
                            join patients in db.Patients on person.PersonID equals patients.PersonID
                            join medrecords in db.MedicalRecords on patients.MedicalRecordID equals medrecords.MedicalRecordID
                            where patients.PatientID == patientID
                            select new PatientData()
                {
                    Person          = person,
                    PatientID       = patients.PatientID,
                    MedicalRecordID = patients.MedicalRecordID,
                    Allergies       = medrecords.Allergies,
                    Medication      = medrecords.Medication,
                    Notes           = medrecords.Notes
                };
                PatientData data = query.FirstOrDefault();
                return(data);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #10
0
 /// <summary>
 /// returns all doctor types
 /// </summary>
 /// <returns></returns>
 public static List <DoctorType> GetDoctorTypes()
 {
     try
     {
         HealtheeEntities db = new HealtheeEntities();
         var query           = from dt in db.DoctorTypes select dt;
         return(query.ToList <DoctorType>());
     }
     catch (Exception e)
     {
         return(null);
     }
 }
コード例 #11
0
        private static void TestDB()
        {
            Console.WriteLine("Test DB Exists : ");
            HealtheeEntities db = new HealtheeEntities();

            if (db.Database.Exists())
            {
                Console.WriteLine("PASS");
            }
            else
            {
                Console.WriteLine("FAIL");
            }
            Console.WriteLine();
        }
コード例 #12
0
        /// <summary>
        /// Ged doctor type by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static DoctorType GetDoctorType(int id)
        {
            HealtheeEntities db = new HealtheeEntities();

            if (DEBUG)
            {
                db.Database.Log = Console.WriteLine;
            }

            var query = from dt in db.DoctorTypes
                        where dt.DoctorTypeID == id
                        select dt;
            DoctorType dType = query.Single();

            return(dType);
        }
コード例 #13
0
        /// <summary>
        /// returns appointments for a doctor
        /// </summary>
        /// <param name="doctorid"></param>
        /// <returns></returns>
        public static List <Appointment> GetDoctorAppointments(int doctorid)
        {
            try
            {
                HealtheeEntities db = new HealtheeEntities();
                //db.Database.Log = msg => Trace.WriteLine(msg);
                var query = from a in db.Appointments
                            where a.DoctorID == doctorid
                            select a;

                return(query.ToList <Appointment>());
            }
            catch (Exception e)
            {
                return(null);
            }
        }
コード例 #14
0
        /// <summary>
        /// Updates a person record
        /// </summary>
        /// <param name="personid"></param>
        /// <param name="firstname"></param>
        /// <param name="lastname"></param>
        /// <param name="gender"></param>
        /// <param name="dob"></param>
        /// <param name="nationalid"></param>
        /// <param name="mobilenumber"></param>
        /// <param name="homenumber"></param>
        /// <param name="worknumber"></param>
        /// <param name="address1"></param>
        /// <param name="address2"></param>
        /// <param name="city"></param>
        /// <param name="country"></param>
        /// <returns></returns>
        public static bool UpdatePerson(int personid, string firstname, string lastname, string gender, DateTime dob, string nationalid, string mobilenumber,
                                        string homenumber, string worknumber, string address1, string address2, string city, string country, string email)
        {
            try
            {
                HealtheeEntities db = new HealtheeEntities();
                if (DEBUG)
                {
                    db.Database.Log = Console.WriteLine;
                }

                var query = from p in db.People
                            where p.PersonID == personid
                            select p;
                Person person = query.FirstOrDefault();
                //if (person == null) return false;

                person.FirstName = firstname;
                person.LastName  = lastname;
                person.Gender    = gender;
                if (dob != DateTime.MinValue)
                {
                    person.DateOfBirth = dob;
                }
                person.NationalID   = nationalid;
                person.MobileNumber = mobilenumber;
                person.HomeNumber   = homenumber;
                person.Address1     = address1;
                person.Address2     = address2;
                person.City         = city;
                person.Country      = country;
                person.Email        = email;
                person.LastUpdated  = DateTime.Now;

                db.SaveChanges();

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
コード例 #15
0
 /// <summary>
 /// authenticates doctor login
 /// creates activity for successful login
 /// </summary>
 /// <param name="username"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public static LoginData DoctorAuth(string username, string password)
 {
     if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
     {
         return(new LoginData()
         {
             loggedin = false
         });
     }
     // TODO : password encryption
     try
     {
         HealtheeEntities db = new HealtheeEntities();
         var query           = (from d in db.Doctors
                                where d.Username == username &&
                                d.Password == password
                                select d);
         if (query.Count() > 0)
         {
             Doctor d = query.FirstOrDefault();
             UserActivity.AddDoctorActivity((int)ActivityEnum.DoctorLogin, d.DoctorID, (int)StatusEnum.Success, "Logged In", username);
             return(new LoginData()
             {
                 doctorid = d.DoctorID, loggedin = true
             });
         }
         else
         {
             return(new LoginData()
             {
                 loggedin = false
             });
         }
     }
     catch (Exception ex)
     {
         return(new LoginData()
         {
             loggedin = false
         });
     }
 }
コード例 #16
0
        /// <summary>
        /// returns appointments for patients
        /// </summary>
        /// <param name="patientid"></param>
        /// <returns></returns>
        public static List <Appointment> GetPatientAppointments(int patientid)
        {
            try
            {
                HealtheeEntities db = new HealtheeEntities();
                if (DEBUG)
                {
                    db.Database.Log = Console.WriteLine;
                }
                var query = from a in db.Appointments
                            where a.PatientID == patientid
                            select a;

                return(query.ToList <Appointment>());
            }
            catch (Exception e)
            {
                return(null);
            }
        }
コード例 #17
0
 /// <summary>
 /// authenticates doctor login
 /// creates activity for successful login
 /// </summary>
 /// <param name="username"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public static LoginData PatientAuth(string username, string password)
 {
     if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
     {
         return(new LoginData()
         {
             loggedin = false
         });
     }
     // TODO : password encryption
     try
     {
         HealtheeEntities db = new HealtheeEntities();
         var query           = (from p in db.Patients
                                where p.Username == username &&
                                p.Password == password
                                select p);
         if (query.Count() > 0)
         {
             Patient p = query.FirstOrDefault();
             return(new LoginData()
             {
                 patientid = p.PatientID, loggedin = true
             });
         }
         else
         {
             return(new LoginData()
             {
                 loggedin = false
             });
         }
     }
     catch (Exception ex)
     {
         return(new LoginData()
         {
             loggedin = false
         });
     }
 }
コード例 #18
0
        /// <summary>
        /// Inserts person data into database
        /// returns last inserted id
        /// </summary>
        /// <returns></returns>
        public static int InsertPerson(string firstname, string lastname, string gender, DateTime dob, string nationalid, string mobilenumber,
                                       string homenumber, string worknumber, string address1, string address2, string city, string country, string email)
        {
            try
            {
                HealtheeEntities db = new HealtheeEntities();
                if (DEBUG)
                {
                    db.Database.Log = Console.WriteLine;
                }
                Person p = new Person {
                    FirstName    = firstname,
                    LastName     = lastname,
                    Gender       = gender,
                    NationalID   = nationalid,
                    MobileNumber = mobilenumber,
                    HomeNumber   = homenumber,
                    WorkNumber   = worknumber,
                    Address1     = address1,
                    Address2     = address2,
                    City         = city,
                    Country      = country,
                    Email        = email
                };

                if (dob != DateTime.MinValue)
                {
                    p.DateOfBirth = dob;
                }

                db.People.Add(p);
                db.SaveChanges();
                return(p.PersonID);
            }
            catch (Exception e)
            {
                return(0);
            }
        }
コード例 #19
0
        /// <summary>
        /// returns true if person exists
        /// false otherwise
        /// </summary>
        /// <param name="doctorID"></param>
        /// <returns></returns>
        public static bool RecordsExist(int medicalrecordid)
        {
            try
            {
                HealtheeEntities db = new HealtheeEntities();
                if (DEBUG)
                {
                    db.Database.Log = Console.WriteLine;
                }

                var count = (from p in db.MedicalRecords
                             where p.MedicalRecordID == medicalrecordid
                             select p).Count();
                if (count > 0)
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
コード例 #20
0
        /// <summary>
        /// Checks if a doctor exists on the database
        /// Returns true or false if otherwise
        /// </summary>
        /// <param name="doctorID"></param>
        /// <returns></returns>
        public static bool DoctorExists(int doctorID)
        {
            try
            {
                HealtheeEntities db = new HealtheeEntities();
                if (DEBUG)
                {
                    db.Database.Log = Console.WriteLine;
                }

                var count = (from d in db.Doctors
                             where d.DoctorID == doctorID
                             select d).Count();
                if (count > 0)
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
コード例 #21
0
        /// <summary>
        /// returns true if patient exists
        /// false otherwise
        /// </summary>
        /// <param name="doctorID"></param>
        /// <returns></returns>
        public static bool PatientExist(int patientid)
        {
            try
            {
                HealtheeEntities db = new HealtheeEntities();
                if (DEBUG)
                {
                    db.Database.Log = Console.WriteLine;
                }

                var count = (from p in db.Patients
                             where p.PatientID == patientid
                             select p).Count();
                if (count > 0)
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
コード例 #22
0
        /// <summary>
        /// Inserts a row into patient table
        /// </summary>
        /// <param name="personid"></param>
        /// <param name="medicalrecordid"></param>
        /// <returns></returns>
        public static int InsertPatient(int personid, int medicalrecordid)
        {
            try
            {
                HealtheeEntities db = new HealtheeEntities();
                if (DEBUG)
                {
                    db.Database.Log = Console.WriteLine;
                }
                Patient p = new Patient
                {
                    PersonID        = personid,
                    MedicalRecordID = medicalrecordid
                };

                db.Patients.Add(p);
                db.SaveChanges();
                return(p.PatientID);
            }
            catch (Exception e)
            {
                return(0);
            }
        }