public bool storeTest(Test test)
    {
        if (Authenticated_AorC())
        {
            try
            {
                Movement.Database.User       newUser    = new Movement.Database.User(test.user.userID);
                Movement.Database.Patient    newPatient = new Movement.Database.Patient(test.patient.ID);
                Movement.Database.TestScript newScript  = new Movement.Database.TestScript(test.script.scriptID);
                IEnumerable <Movement.Database.TestDataSample> data;
                data = test.data.ConvertAll <TestDataSample>(new Converter <Data, TestDataSample>(
                                                                 delegate(Data filler) { return(new TestDataSample(filler.time, filler.x, filler.y, filler.pressure)); }));

                Movement.Database.Test.CreateTest(newUser, newPatient, test.hand, newScript, test.mode, data, test.avg_X, test.avg_Y, test.rotation);
                return(true);
            }
            catch (Exception e)
            {
                Log(e);
                return(false);
            }
        }
        else
        {
            throw new UnauthorizedAccessException("You are not authorized to perform that action!");
        }
    }
    public bool updatePatient(PatientObject patient)
    {
        if (Authenticated_AorC())
        {
            Movement.Database.Patient tempPatient = new Movement.Database.Patient(patient.ID);
            try
            {
                tempPatient.Name        = patient.name;
                tempPatient.Address     = patient.address;
                tempPatient.ContactInfo = patient.ContactInfo;
                /* The following patient properties are READ-ONLY in the database */

                /*
                 * sex
                 * dob
                 * handedness
                 * ssn
                 */
                return(true);
            }
            catch (Exception e)
            {
                Log(e);
                return(false);
            }
        }
        else
        {
            throw new UnauthorizedAccessException("You are not authorized to perform that action!");
        }
    }
 public bool updatePatient(PatientObject patient)
 {
     if (Authenticated_AorC())
     {
         Movement.Database.Patient tempPatient = new Movement.Database.Patient(patient.ID);
         try
         {
             tempPatient.Name = patient.name;
             tempPatient.Address = patient.address;
             tempPatient.ContactInfo = patient.ContactInfo;
             /* The following patient properties are READ-ONLY in the database */
             /*
              * sex
              * dob
              * handedness
              * ssn
              */
             return true;
         }
         catch (Exception e)
         {
             Log(e);
             return false;
         }
     }
     else
     {
         throw new UnauthorizedAccessException("You are not authorized to perform that action!");
     }
 }
    public bool storeTest(Test test)
    {
        if (Authenticated_AorC())
        {
            try
            {
                Movement.Database.User newUser = new Movement.Database.User(test.user.userID);
                Movement.Database.Patient newPatient = new Movement.Database.Patient(test.patient.ID);
                Movement.Database.TestScript newScript = new Movement.Database.TestScript(test.script.scriptID);
                IEnumerable<Movement.Database.TestDataSample> data;
                data = test.data.ConvertAll<TestDataSample>(new Converter<Data, TestDataSample>(
                    delegate(Data filler) { return new TestDataSample(filler.time, filler.x, filler.y, filler.pressure); }));

                Movement.Database.Test.CreateTest(newUser, newPatient, test.hand, newScript, test.mode, data, test.avg_X, test.avg_Y, test.rotation);
                return true;
            }
            catch(Exception e)
            {
                Log(e);
                return false;
            }
        }
        else
        {
            throw new UnauthorizedAccessException("You are not authorized to perform that action!");
        }
    }
    public List<Test> getTests(Int32 numTests, PatientObject patient)
    {
        if (Authenticated_AorC())
        {
            try
            {
                List<Test> tests = new List<Test>();
                Test filler = new Test();
                filler.anal = new List<AnalysisData>();
                Movement.Database.Patient p1 = new Movement.Database.Patient(patient.ID);
                ReadOnlyCollection<Movement.Database.Test> testList;
                testList = p1.GetAllTests();
                AnalysisData d1 = new AnalysisData();

                if (numTests == 0)
                {
                    for (int i = 0; i < testList.Count; i++)
                    {
                        filler.anal = new List<AnalysisData>();
                        filler.hand = testList[i].Hand;
                        filler.mode = testList[i].Mode;
                        filler.ID = testList[i].TestID;
                        filler.script.scriptID = testList[i].TestScript.ScriptID;
                        filler.timestamp = testList[i].Timestamp;
                        filler.rotation = testList[i].Rotation;
                        filler.script.type = testList[i].TestScript.ScriptType.Name;
                        foreach (KeyValuePair<Movement.Analysis.AnalysisMetric, Movement.Database.TestAnalysisComponent> data in testList[i].Analysis.Components)
                        {

                            d1.metric = data.Key;
                            d1.max = data.Value.Max;
                            d1.min = data.Value.Min;
                            d1.mean = data.Value.Mean;
                            d1.stdDev = data.Value.StdDev;

                            filler.anal.Add(d1);
                        }

                        tests.Add(filler);
                    }

                }
                else if (numTests < testList.Count)
                {
                    for (int j = 0; j < numTests; j++)
                    {
                        filler.anal = new List<AnalysisData>();
                        filler.hand = testList[j].Hand;
                        filler.mode = testList[j].Mode;
                        filler.ID = testList[j].TestID;
                        filler.script.scriptID = testList[j].TestScript.ScriptID;
                        filler.timestamp = testList[j].Timestamp;
                        filler.rotation = testList[j].Rotation;
                        filler.script.type = testList[j].TestScript.ScriptType.Name;
                        filler.isNormal = testList[j].AnalysisIsNormal;

                        foreach (KeyValuePair<Movement.Analysis.AnalysisMetric, Movement.Database.TestAnalysisComponent> data in testList[j].Analysis.Components)
                        {

                            d1.metric = data.Key;
                            d1.max = data.Value.Max;
                            d1.min = data.Value.Min;
                            d1.mean = data.Value.Mean;
                            d1.stdDev = data.Value.StdDev;

                            filler.anal.Add(d1);
                        }

                        tests.Add(filler);
                    }

                }
                else if (numTests > testList.Count)
                {
                    for (int i = 0; i < testList.Count; i++)
                    {
                        filler.anal = new List<AnalysisData>();
                        filler.hand = testList[i].Hand;
                        filler.mode = testList[i].Mode;
                        filler.ID = testList[i].TestID;
                        filler.script.scriptID = testList[i].TestScript.ScriptID;
                        filler.timestamp = testList[i].Timestamp;
                        filler.rotation = testList[i].Rotation;
                        filler.script.type = testList[i].TestScript.ScriptType.Name;
                        foreach (KeyValuePair<Movement.Analysis.AnalysisMetric, Movement.Database.TestAnalysisComponent> data in testList[i].Analysis.Components)
                        {

                            d1.metric = data.Key;
                            d1.max = data.Value.Max;
                            d1.min = data.Value.Min;
                            d1.mean = data.Value.Mean;
                            d1.stdDev = data.Value.StdDev;

                            filler.anal.Add(d1);
                        }

                        tests.Add(filler);
                    }
                }

                return tests;
            }
            catch (Exception e)
            {
                Log(e);
                return new List<Test>();
            }
        }
        else
        {
            throw new UnauthorizedAccessException("You are not authorized to perform this action!");
        }
    }
    public List <Test> getTests(Int32 numTests, PatientObject patient)
    {
        if (Authenticated_AorC())
        {
            try
            {
                List <Test> tests  = new List <Test>();
                Test        filler = new Test();
                filler.anal = new List <AnalysisData>();
                Movement.Database.Patient p1 = new Movement.Database.Patient(patient.ID);
                ReadOnlyCollection <Movement.Database.Test> testList;
                testList = p1.GetAllTests();
                AnalysisData d1 = new AnalysisData();

                if (numTests == 0)
                {
                    for (int i = 0; i < testList.Count; i++)
                    {
                        filler.anal            = new List <AnalysisData>();
                        filler.hand            = testList[i].Hand;
                        filler.mode            = testList[i].Mode;
                        filler.ID              = testList[i].TestID;
                        filler.script.scriptID = testList[i].TestScript.ScriptID;
                        filler.timestamp       = testList[i].Timestamp;
                        filler.rotation        = testList[i].Rotation;
                        filler.script.type     = testList[i].TestScript.ScriptType.Name;
                        foreach (KeyValuePair <Movement.Analysis.AnalysisMetric, Movement.Database.TestAnalysisComponent> data in testList[i].Analysis.Components)
                        {
                            d1.metric = data.Key;
                            d1.max    = data.Value.Max;
                            d1.min    = data.Value.Min;
                            d1.mean   = data.Value.Mean;
                            d1.stdDev = data.Value.StdDev;

                            filler.anal.Add(d1);
                        }

                        tests.Add(filler);
                    }
                }
                else if (numTests < testList.Count)
                {
                    for (int j = 0; j < numTests; j++)
                    {
                        filler.anal            = new List <AnalysisData>();
                        filler.hand            = testList[j].Hand;
                        filler.mode            = testList[j].Mode;
                        filler.ID              = testList[j].TestID;
                        filler.script.scriptID = testList[j].TestScript.ScriptID;
                        filler.timestamp       = testList[j].Timestamp;
                        filler.rotation        = testList[j].Rotation;
                        filler.script.type     = testList[j].TestScript.ScriptType.Name;
                        filler.isNormal        = testList[j].AnalysisIsNormal;

                        foreach (KeyValuePair <Movement.Analysis.AnalysisMetric, Movement.Database.TestAnalysisComponent> data in testList[j].Analysis.Components)
                        {
                            d1.metric = data.Key;
                            d1.max    = data.Value.Max;
                            d1.min    = data.Value.Min;
                            d1.mean   = data.Value.Mean;
                            d1.stdDev = data.Value.StdDev;

                            filler.anal.Add(d1);
                        }

                        tests.Add(filler);
                    }
                }
                else if (numTests > testList.Count)
                {
                    for (int i = 0; i < testList.Count; i++)
                    {
                        filler.anal            = new List <AnalysisData>();
                        filler.hand            = testList[i].Hand;
                        filler.mode            = testList[i].Mode;
                        filler.ID              = testList[i].TestID;
                        filler.script.scriptID = testList[i].TestScript.ScriptID;
                        filler.timestamp       = testList[i].Timestamp;
                        filler.rotation        = testList[i].Rotation;
                        filler.script.type     = testList[i].TestScript.ScriptType.Name;
                        foreach (KeyValuePair <Movement.Analysis.AnalysisMetric, Movement.Database.TestAnalysisComponent> data in testList[i].Analysis.Components)
                        {
                            d1.metric = data.Key;
                            d1.max    = data.Value.Max;
                            d1.min    = data.Value.Min;
                            d1.mean   = data.Value.Mean;
                            d1.stdDev = data.Value.StdDev;

                            filler.anal.Add(d1);
                        }

                        tests.Add(filler);
                    }
                }

                return(tests);
            }
            catch (Exception e)
            {
                Log(e);
                return(new List <Test>());
            }
        }
        else
        {
            throw new UnauthorizedAccessException("You are not authorized to perform this action!");
        }
    }