public static PTLocalPatient CreatePatient(PTLocalPatient patient)
        {
            try
            {
                //TODO: if user does not yet exist, we add the user, but it probably shouldn't add with status as confirmed.
                // add the patient to the db, set patient.ID, and return the patient
                using (PTLinkDatabaseDataContext db = new PTLinkDatabaseDataContext())
                {
                    Person person = new Person();
                    User user = (from u in db.Users
                                 where u.Email == patient.email
                                 && u.Password == patient.password
                                 select u).SingleOrDefault();

                    person.FirstName = patient.firstName;
                    person.LastName = patient.lastName;
                    person.Permissions = "Patient";
                    person.PushToken = patient.pushtoken;
                    person.IsActive = true;

                    if (user == null)
                    {
                        user = new User();
                        user.Email = patient.email;
                        user.Password = patient.password;
                        user.RegistrationStatus = (from r in db.RegistrationStatus
                                                   where r.Status == "Confirmed"
                                                   select r
                                                   ).SingleOrDefault();
                        user.Persons.Add(person);
                        db.Users.InsertOnSubmit(user);
                        db.SubmitChanges();
                    }
                    else
                    {
                        user.Persons.Add(person);
                        db.SubmitChanges();
                    }

                    patient.ID = user.Persons.SingleOrDefault().Id;
                    return patient;
                }
            }
            catch
            {
                return null;
            }
        }
 public string Login(PTLocalPatient patient)
 {
     try {
         SyncArgs args = new SyncArgs();
         args.authentication = new Auth();
         args.authentication.email = patient.email;
         args.authentication.password = patient.password;
         args.lastTime = 0;
         return Sync(args);
     } catch (Exception e) {
         return e.Message;
     }
 }
        public static PTLocalPatient GetPatient(string email, string password)
        {
            try
            {
                // get the patient with this email and password, or return null if it doesn't exist
                using (PTLinkDatabaseDataContext db = new PTLinkDatabaseDataContext())
                {
                    PTLocalPatient patient = new PTLocalPatient();
                    var dbPatient = (from p in db.Persons
                                     where p.User.Email == email
                                     && p.User.Password == password
                                     && p.Permissions == "Patient"
                                     && p.User.RegistrationStatus.Status == "Confirmed"
                                     select p).SingleOrDefault();
                    if (dbPatient != null)
                    {
                        patient.email = email;
                        patient.firstName = dbPatient.FirstName;
                        patient.lastName = dbPatient.LastName;
                        patient.ID = dbPatient.Id;
                        patient.password = password;
                        patient.pushtoken = dbPatient.PushToken;

                        return patient;
                    }
                }
                return null;
            }
            catch
            {
                return null;
            }
        }
 public string CreatePatient(PTLocalPatient patient)
 {
     Dictionary<string, object> results = new Dictionary<string, object>();
     try {
         PTLocalPatient p = PTDatabase.CreatePatient(patient);
         if (p == null) {
             results["error"] = "Error creating patient.";
         } else {
             results["patient"] = p;
         }
     } catch (Exception e) {
         results["error"] = e.Message;
     }
     return s.Serialize(results);
 }