/// <summary>
        /// Determines if a test analysis is normal (within normal limits) based on this normative analysis.
        /// </summary>
        /// <param name="analysis">The analysis results to check.</param>
        /// <returns>True if the test analysis is within normal limits, otherwise false.</returns>
        public bool IsNormal(TestAnalysis analysis)
        {
            foreach (TestAnalysisComponent c in analysis.Components.Values)
            {
                if (!IsNormal(c))
                {
                    return(false);
                }
            }

            //no analysis was abnormal, so the result is normal
            return(true);
        }
示例#2
0
        /// <summary>
        /// Creates and stores a new test.
        /// </summary>
        /// <param name="user">The user that administered the test.</param>
        /// <param name="patient">The patient that took the test.</param>
        /// <param name="hand">The hand that the test was taken with.</param>
        /// <param name="script">The script used to run the test.</param>
        /// <param name="mode">The mode that the test was run in.</param>
        /// <param name="data">The data collected during the test.</param>
        /// <param name="meanX">The average x-coordinate of all the data collected.</param>
        /// <param name="meanY">The average y-coordinate of all the data collected.</param>
        /// <param name="rotation">The number of degrees that the test was rotated (from the positive x-axis) when taken.</param>
        /// <returns>The created test.</returns>
        public static Test CreateTest(
            User user,
            Patient patient,
            char hand,
            TestScript script,
            char mode,
            IEnumerable <TestDataSample> data,
            double meanX,
            double meanY,
            short rotation)
        {
            int TestID = -1;

            //create an analyzer
            Analyzer DataAnalyzer = new Analyzer(
                meanX,
                meanY,
                new ScriptEngine(script.ScriptData).Path);

            using (DbConnection Connection = GetAsyncConnection())
            {
                Connection.Open();

                //begin a transaction so that creation is atomic
                DbTransaction Transaction = Connection.BeginTransaction();

                try
                {
                    //create the test
                    TestID = Execute(Connection, Transaction,
                                     "STORE_TEST_RESULTS",
                                     "@scriptID", script.ScriptID,
                                     "@patientID", patient.PatientID,
                                     "@userID", user.UserID,
                                     "@hand", hand,
                                     "@mode", mode,
                                     "@rotation", rotation);


                    //prepare the add-sample command ahead of time for efficiency
                    DbCommand AddSampleCommand = PrepareCommand(Connection, Transaction, "ADD_TEST_SAMPLE");
                    AddSampleCommand.Parameters["@testID"].Value = TestID;
                    int O_X = AddSampleCommand.Parameters.IndexOf("@x"),                        //determine the parameter indices ahead of time for efficiency
                        O_Y = AddSampleCommand.Parameters.IndexOf("@y"),
                        O_P = AddSampleCommand.Parameters.IndexOf("@p"),
                        O_T = AddSampleCommand.Parameters.IndexOf("@t");

                    IAsyncResult AddSampleHandle = null;


                    //store and analyze samples in parallel
                    foreach (TestDataSample s in data)
                    {
                        //modify the prepared procedure arguments
                        AddSampleCommand.Parameters[O_X].Value = s.X;
                        AddSampleCommand.Parameters[O_Y].Value = s.Y;
                        AddSampleCommand.Parameters[O_P].Value = s.Pressure;
                        AddSampleCommand.Parameters[O_T].Value = s.Time;

                        //finish the last procedure execution
                        EndExecute(AddSampleHandle);

                        //start the next procedure execution
                        AddSampleHandle = BeginExecute(AddSampleCommand);

                        //perform analysis on the sample
                        DataAnalyzer.AnalyzeSample(s.Time, s.X, s.Y, s.Pressure);
                    }

                    EndExecute(AddSampleHandle);

                    //store the analysis
                    TestAnalysis.StoreAnalysis(
                        Connection,
                        Transaction,
                        TestID,
                        DataAnalyzer.CurrentAnalysis);

                    Transaction.Commit();
                }
                catch (Exception e)
                {
                    Transaction.Rollback();
                    throw e;
                }
            }



            return(new Test(TestID));
        }