Beispiel #1
0
        public void addResult(EQresult result)
        {
            string qCode  = result.qCode;
            string answer = result.answer;

            questionHash[qCode] = answer;
        }
Beispiel #2
0
        private EQresult copyResult(EQresult orig, string newCode, string newAnswer)
        {
            EQresult res = new EQresult();

            res.partID   = orig.partID;
            res.surveyID = orig.surveyID;
            res.qCode    = newCode;
            res.answer   = newAnswer;

            return(res);
        }
Beispiel #3
0
        public void addParticipantData(EQresult result)
        {
            string query = "insert into eq_data(questionnaire_name, participant_id, question_code, answer) values (@qName, @partID, @qCode, @answer)";

            MySqlCommand cmd = new MySqlCommand(query, conn);

            cmd.Parameters.AddWithValue("@qName", result.surveyID);
            cmd.Parameters.AddWithValue("@partID", result.partID);
            cmd.Parameters.AddWithValue("@qCode", result.qCode);
            cmd.Parameters.AddWithValue("@answer", result.answer);


            cmd.ExecuteNonQuery();
        }
Beispiel #4
0
        private void readfile(string filepath, string surveyID, string partID, List <EQresult> resultList)
        {
            StreamReader dh = new StreamReader(filepath);

            char[] splitOn = { '\t' };
            string qCode;
            string answer;

            EQresult eqRes;

            try
            {
                while (dh.EndOfStream == false)
                {
                    string line = dh.ReadLine();


                    //split into qcode and answer
                    string[] items = line.Split(splitOn);

                    //first item is the qCode
                    //second item is the data for that qCode
                    qCode  = items[0];
                    answer = items[1];

                    eqRes = new EQresult();

                    eqRes.qCode    = qCode;
                    eqRes.answer   = answer;
                    eqRes.partID   = partID;
                    eqRes.surveyID = surveyID;

                    resultList.Add(eqRes);
                }
            }


            catch (Exception ex1)
            {
                MessageBox.Show("Error reading file:" + ex1.Message);
            }

            finally
            {
                if (dh != null)
                {
                    dh.Close();
                }
            }
        }
Beispiel #5
0
        public void addResult(EQresult result)
        {
            //which participant?
            string part = result.partID;

            //get EQparticipant

            EQparticipant eqPart;

            if (partHash.ContainsKey(part))
            {
                eqPart = partHash[part];
                eqPart.addResult(result);
            }
            else
            {
                eqPart         = new EQparticipant();
                partHash[part] = eqPart;
                eqPart.addResult(result);
            }
        }
Beispiel #6
0
        private void splitVars(List <EQresult> resultList, string missingStr, string noAnswerText, string dontKnowText, string notAppText)
        {
            //search for compound vars which can be split into chunks where each chunk is a new var
            //missingStr is whatever was chosen to represent missing values


            //delete list: what we need to remove from the data list
            List <EQresult> dList = new List <EQresult>();


            //add list: new things to add
            List <EQresult> aList = new List <EQresult>();



            Regex pattAVEW  = new Regex(@"([WMY]):(\d+)");
            Regex pattDEXAM = new Regex(@"^(\d+)/(\d+)/(\d+) .+");
            Regex pattTAC2  = new Regex(@"^TAC2[A-E]-R$");
            Regex pattBlood = new Regex(@"^(.+):(.+)$");
            Regex pattTOB   = new Regex(@"^(\d):(.+)$");


            //blood samples
            //mapping of the qCode of the result to the qCode of the corresponding barcode
            var bloodMap = new Dictionary <string, string>();

            bloodMap["PST"]    = "PSTB1";
            bloodMap["EDTA1A"] = "EDTAB1A";
            bloodMap["EDTA1B"] = "EDTAB1B";
            bloodMap["EDTA1C"] = "EDTAB1C";
            bloodMap["PL1"]    = "PLTB1";
            bloodMap["SPU"]    = "SPUB";
            bloodMap["NAF1"]   = "NAFB1";
            bloodMap["NAF2"]   = "NAFB2";
            bloodMap["PST2"]   = "PSTB2";


            foreach (EQresult res in resultList)
            {
                string qCode  = res.qCode;
                string answer = res.answer;


                //blood sample?
                if (bloodMap.Keys.Contains(qCode))
                {
                    //split the value into barcode and result
                    //e.g. PST	1:111



                    EQresult newRes;
                    EQresult newResBC;  //barcode

                    //was this skipped
                    if (answer == missingStr || answer == noAnswerText || answer == dontKnowText || answer == notAppText)
                    {
                        //create second result (barcode)
                        newRes = copyResult(res, bloodMap[qCode], answer);
                        aList.Add(newRes);
                    }
                    else
                    {
                        //split into barcode and result

                        Match  match  = pattBlood.Match(answer);
                        string result = match.Groups[1].Value;
                        string bc     = match.Groups[2].Value;

                        //result
                        newRes = copyResult(res, qCode, result);
                        aList.Add(newRes);

                        //barcode
                        newResBC = copyResult(res, bloodMap[qCode], bc);
                        aList.Add(newResBC);

                        //delete the original
                        dList.Add(res);
                    }
                }



                //AVEW	W:123

                else if (qCode == "AVEW")
                {
                    //split into Weeks, Months, Years.


                    EQresult avewRes;
                    EQresult avemRes;
                    EQresult aveyRes;

                    //might have been skipped
                    if (answer == missingStr || answer == noAnswerText || answer == dontKnowText || answer == notAppText)
                    {
                        avewRes = copyResult(res, "AVEW", answer);
                        avemRes = copyResult(res, "AVEM", answer);
                        aveyRes = copyResult(res, "AVEY", answer);
                    }
                    else
                    {
                        Match match = pattAVEW.Match(answer);

                        string wmy  = match.Groups[1].Value;
                        string time = match.Groups[2].Value;



                        if (wmy == "W")
                        {
                            //create 3 new results and remove this one
                            avewRes = copyResult(res, "AVEW", time);
                            avemRes = copyResult(res, "AVEM", missingStr);
                            aveyRes = copyResult(res, "AVEY", missingStr);
                        }
                        else if (wmy == "M")
                        {
                            //create 3 new results and remove this one
                            avewRes = copyResult(res, "AVEW", missingStr);
                            avemRes = copyResult(res, "AVEM", time);
                            aveyRes = copyResult(res, "AVEY", missingStr);
                        }
                        else if (wmy == "Y")
                        {
                            //create 3 new results and remove this one
                            avewRes = copyResult(res, "AVEW", missingStr);
                            avemRes = copyResult(res, "AVEM", missingStr);
                            aveyRes = copyResult(res, "AVEY", time);
                        }
                        else
                        {
                            throw new Exception("Illegal prefix for code:AVEW");
                        }
                    }



                    //remove original res
                    dList.Add(res);

                    //add 3 new ones
                    aList.Add(avewRes);
                    aList.Add(avemRes);
                    aList.Add(aveyRes);
                }

                else if (qCode == "AVEW-2")
                {
                    //duplicate of AVEW: delete

                    dList.Add(res);
                }

                else if (qCode == "CRWD")
                {
                    //delete CRWD
                    dList.Add(res);
                }

                else if (qCode == "START")
                {
                    //change this to SITECODE

                    EQresult newRes = copyResult(res, "SITECODE", answer);
                    aList.Add(newRes);

                    //delete original
                    dList.Add(res);
                }



                else if (checkPatternMatch(qCode, pattTAC2))
                {
                    //delete
                    dList.Add(res);
                }


                else if (qCode == "TOB9")
                {
                    EQresult days;
                    EQresult weeks;
                    EQresult months;
                    EQresult years;

                    if (answer == missingStr || answer == noAnswerText || answer == dontKnowText || answer == notAppText)
                    {
                        days   = copyResult(res, "TOB9D", answer);
                        weeks  = copyResult(res, "TOB9W", answer);
                        months = copyResult(res, "TOB9M", answer);
                        years  = copyResult(res, "TOB9Y", answer);
                    }
                    else
                    {
                        Match match = pattTOB.Match(answer);

                        string dwmy     = match.Groups[1].Value;
                        string timespan = match.Groups[2].Value;

                        string answerDays   = "0";
                        string answerWeeks  = "0";
                        string answerMonths = "0";
                        string answerYears  = "0";

                        if (dwmy == "1")
                        {
                            answerDays = timespan;
                        }
                        else if (dwmy == "2")
                        {
                            answerWeeks = timespan;
                        }

                        else if (dwmy == "3")
                        {
                            answerMonths = timespan;
                        }

                        else if (dwmy == "8")
                        {
                            answerYears = timespan;
                        }
                        else
                        {
                            throw new Exception("unknown timespan for TOB9");
                        }



                        days   = copyResult(res, "TOB9D", answerDays);
                        weeks  = copyResult(res, "TOB9W", answerWeeks);
                        months = copyResult(res, "TOB9M", answerMonths);
                        years  = copyResult(res, "TOB9Y", answerYears);
                    }

                    //remove original res
                    dList.Add(res);

                    //add 3 new ones
                    aList.Add(days);
                    aList.Add(weeks);
                    aList.Add(months);
                    aList.Add(years);
                }



                else if (qCode == "DEXAM")
                {
                    //DEXAM	22/08/2014 13:38:42

                    //split into d/m/y and ignore timestamp part


                    EQresult dexam;
                    EQresult mexam;
                    EQresult yexam;

                    if (answer == missingStr || answer == noAnswerText || answer == dontKnowText || answer == notAppText)
                    {
                        dexam = copyResult(res, "DEXAM", answer);
                        mexam = copyResult(res, "MEXAM", answer);
                        yexam = copyResult(res, "YEXAM", answer);
                    }
                    else
                    {
                        Match match = pattDEXAM.Match(answer);

                        string days   = match.Groups[1].Value;
                        string months = match.Groups[2].Value;
                        string years  = match.Groups[3].Value;



                        dexam = copyResult(res, "DEXAM", days);
                        mexam = copyResult(res, "MEXAM", months);
                        yexam = copyResult(res, "YEXAM", years);
                    }



                    //remove original res
                    dList.Add(res);

                    //add 3 new ones
                    aList.Add(dexam);
                    aList.Add(mexam);
                    aList.Add(yexam);
                }
            }

            //build a new result-list, i.e. remove things in dList and add things in aList
            foreach (EQresult res in dList)
            {
                //delete from main list
                resultList.Remove(res);
            }

            //add new items
            resultList.AddRange(aList);
        }