Example #1
0
        public void TestHyphens()
        {
            // Retrieve the publications for each person in input1.xls using GetPublications()
            People PeopleFromFile = new People(
                AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPeople",
                "test hyphens.xls");

            Assert.IsTrue(PeopleFromFile.PersonList.Count == 1);
            Person PersonToWrite = PeopleFromFile.PersonList[0];

            Assert.IsTrue(PersonToWrite.Names.Length == 3);
            Assert.IsTrue(PersonToWrite.Names[0] == "wassertheil-smoller s");
            Assert.IsTrue(PersonToWrite.Names[1] == "wassertheil s");
            Assert.IsTrue(PersonToWrite.Names[2] == "wassertheil-smoller sm");

            // Write them to the database and read them back
            Database  DB        = new Database("Publication Harvester Unit Test");
            Harvester harvester = new Harvester(DB);

            harvester.CreateTables();
            PersonToWrite.WriteToDB(DB);
            People PeopleFromDB = new People(DB);

            Assert.IsTrue(PeopleFromDB.PersonList.Count == 1);
            Person PersonToRead = PeopleFromDB.PersonList[0];

            Assert.IsTrue(PersonToRead.Names.Length == 3);
            Assert.IsTrue(PersonToRead.Names[0] == "wassertheil-smoller s");
            Assert.IsTrue(PersonToRead.Names[1] == "wassertheil s");
            Assert.IsTrue(PersonToRead.Names[2] == "wassertheil-smoller sm");
        }
Example #2
0
        public void WriteAndClearError()
        {
            string[] Names         = { "a", "b", "c" };
            Person   PersonToWrite = new Person("1234ABCD", "First", "Middle", "Last",
                                                false, Names, "Medline search query");

            // Write the person to the database
            Database  DB        = new Database("Publication Harvester Unit Test");
            Harvester harvester = new Harvester(DB);

            harvester.CreateTables();
            PersonToWrite.WriteToDB(DB);

            // Write an error
            PersonToWrite.WriteErrorToDB(DB, "This is the error message");
            DataTable Results = DB.ExecuteQuery("SELECT Error, ErrorMessage FROM People WHERE Setnb = '1234ABCD'");

            Assert.IsTrue(Results.Rows[0]["Error"].Equals(true));
            Assert.IsTrue(Results.Rows[0]["ErrorMessage"].ToString() == "This is the error message");

            // Clear the error -- note that we need to use GetBoolValue() to get around the MySQL bug
            PersonToWrite.ClearErrorInDB(DB);
            Results = DB.ExecuteQuery("SELECT " + Database.PEOPLE_COLUMNS + " FROM People WHERE Setnb = '1234ABCD'");
            bool boolValue;

            Assert.IsTrue(Database.GetBoolValue(Results.Rows[0]["Error"], out boolValue));
            Assert.IsTrue(boolValue == false);
            Assert.IsTrue(Results.Rows[0]["ErrorMessage"].ToString() == "");
        }
        public void ResetDatabase()
        {
            // Import "TestPeopleMaintenance/input1 plus testhyphens.xls" into the People table
            People PeopleFromFile = new People(
                AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPeopleMaintenance",
                "input1 plus testhypens.xls");

            DB = new Database("Publication Harvester Unit Test");
            Harvester harvester = new Harvester(DB);

            harvester.CreateTables();
            MockNCBI mockNCBI = new MockNCBI("medline");

            mockNCBI.SearchThrowsAnError = false;
            PublicationTypes ptc = new PublicationTypes(
                AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPublicationTypes",
                "PublicationTypes.csv"
                );

            ptc.WriteToDB(DB);


            // Anonymous callback functions for GetPublications
            Harvester.GetPublicationsStatus StatusCallback = delegate(int number, int total, int averageTime)
            {
                //
            };
            Harvester.GetPublicationsMessage MessageCallback = delegate(string Message, bool StatusBarOnly)
            {
                //
            };
            Harvester.CheckForInterrupt InterruptCallback = delegate()
            {
                return(false);
            };

            // Write the people, then "harvest" the publications using MockNCBI
            double AverageMilliseconds;

            foreach (Person person in PeopleFromFile.PersonList)
            {
                person.WriteToDB(DB);
                harvester.GetPublications(mockNCBI, ptc, person, StatusCallback, MessageCallback, InterruptCallback, out AverageMilliseconds);
            }

            People PeopleFromDB = new People(DB);

            Assert.AreEqual(PeopleFromDB.PersonList.Count, 4);
        }
        public void ReadAndWritePublicationTypes()
        {
            // Read the publication types from the CSV file
            PublicationTypes ptc = new PublicationTypes(
                AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPublicationTypes",
                "PublicationTypes.csv"
                );

            Assert.AreEqual(ptc.Categories.Count, 52);
            Assert.AreEqual(ptc.GetCategoryNumber("Legislation"), 0);
            Assert.AreEqual(ptc.GetCategoryNumber("Consensus Development Conference, NIH"), 1);
            Assert.AreEqual(ptc.GetCategoryNumber("Review, Multicase"), 2);
            Assert.AreEqual(ptc.GetCategoryNumber("Technical Report"), 3);
            Assert.AreEqual(ptc.GetCategoryNumber("Comment"), 4);

            // Verify OverrideFirstCategory values
            Assert.IsTrue(ptc.OverrideFirstCategory.ContainsKey("Review"));
            Assert.IsTrue(ptc.OverrideFirstCategory.ContainsKey("Review, Multicase"));
            Assert.AreEqual(ptc.OverrideFirstCategory.ContainsKey("Comment"), false);


            // First recreate the database, then write the publication types to it
            Database  DB        = new Database("Publication Harvester Unit Test");
            Harvester harvester = new Harvester(DB);

            harvester.CreateTables();
            ptc.WriteToDB(DB);

            // Read the publication types from the database
            PublicationTypes ptcFromDB =
                new PublicationTypes(DB);

            Assert.AreEqual(ptcFromDB.Categories.Count, 52);
            Assert.AreEqual(ptcFromDB.GetCategoryNumber("Overall"), 0);
            Assert.AreEqual(ptcFromDB.GetCategoryNumber("Clinical Trial, Phase II"), 1);
            Assert.AreEqual(ptcFromDB.GetCategoryNumber("Review of Reported Cases"), 2);
            Assert.AreEqual(ptcFromDB.GetCategoryNumber("Technical Report"), 3);
            Assert.AreEqual(ptcFromDB.GetCategoryNumber("Letter"), 4);
            Assert.AreEqual(ptcFromDB.GetCategoryNumber("Comment"), 4);

            // Verify OverrideFirstCategory values
            Assert.IsTrue(ptcFromDB.OverrideFirstCategory.ContainsKey("Review"));
            Assert.IsTrue(ptcFromDB.OverrideFirstCategory.ContainsKey("Review, Multicase"));
            Assert.AreEqual(ptcFromDB.OverrideFirstCategory.ContainsKey("Comment"), false);
        }
        public void TestCreateFromDatabase()
        {
            // Add a publication to the database
            Database  DB        = new Database("Publication Harvester Unit Test");
            Harvester harvester = new Harvester(DB);

            harvester.CreateTables();
            Publication      write = CreateTestPublication();
            PublicationTypes ptc   = new PublicationTypes(
                AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPublicationTypes",
                "PublicationTypes.csv"
                );

            Publications.WriteToDB(write, DB, ptc, new string[] { "eng" });

            // Read it back
            Publication read;

            Assert.IsTrue(Publications.GetPublication(DB, 15904469, out read, false));
            TestCreatedPublication(read);
        }
Example #6
0
        /// <summary>
        /// Verify that input1.* was read properly
        /// </summary>
        /// <param name="PeopleFromFile">People object that contains contents of input1.* file</param>
        private static void VerifyInput1File(People PeopleFromFile)
        {
            int Count = 0;

            // Verify that each PersonToWrite was read properly -- note that the order people
            // are returned is not guaranteed
            foreach (Person person in PeopleFromFile.PersonList)
            {
                Count++;
                TestInput1People(person);
            }
            // Verify that all four people were read from input1.xls
            Assert.AreEqual(Count, 4);

            // Write the people to the database -- first initialize it
            Database  DB        = new Database("Publication Harvester Unit Test");
            Harvester harvester = new Harvester(DB);

            harvester.CreateTables();
            foreach (Person person in PeopleFromFile.PersonList)
            {
                person.WriteToDB(DB);
            }

            // Read the people back from the database
            People PeopleFromDB = new People(DB);

            Count = 0;
            // Verify that each PersonToWrite was read properly -- note that the order people
            // are returned is not guaranteed
            foreach (Person person in PeopleFromDB.PersonList)
            {
                Count++;
                TestInput1People(person);
            }
            // Verify that all four people were read from input1.xls
            Assert.AreEqual(Count, 4);
        }
Example #7
0
        public void TestPeopleReportRows()
        {
            // Set up the database with test publications (and don't forget to add the
            // publication types!)
            DB = new Database("Publication Harvester Unit Test");
            Harvester harvester = new Harvester(DB);

            harvester.CreateTables();
            PublicationTypes PubTypes = new PublicationTypes(
                AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPublicationTypes",
                "PublicationTypes.csv"
                );

            PubTypes.WriteToDB(DB);
            reports = new Reports(DB, AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestReports\\pubmed_jifs.xls");
            Assert.IsTrue(reports.Weights.Count == 10);
            TestHarvester.GetPublicationsFromInput1XLS_Using_MockNCBI(false, new string[] { "eng" }, 22);
            people = new People(DB);


            foreach (Person person in people.PersonList)
            {
                Publications pubs = new Publications(DB, person, false);
                switch (person.Setnb)
                {
                case "A6009400":
                    // Van Eys has two publications in 1998, both have zero weight
                    DataRow Row = WriteAndReadBackCSVRow(reports.ReportRow(person, pubs, 1998));

                    Assert.IsTrue(Row.ItemArray.Length == 74);
                    Assert.IsTrue(Row.ItemArray[0].ToString() == "A6009400");
                    Assert.IsTrue(Row.ItemArray[1].ToString() == "1998");

                    // Verify that all values are zero, except for pubcount (#3),
                    // pubcount_pos1 (#5), 123pubcount (#15), 123pubcount_pos1 (#17),
                    // 3pubcount (#51), 3pubcount_pos1 (#53)
                    for (int i = 2; i <= 73; i++)
                    {
                        if ((i == 2) || (i == 4) || (i == 14) || (i == 16) ||
                            (i == 50) || (i == 52))
                        {
                            Assert.IsTrue(Row.ItemArray[i].ToString() == "2", "Failed at i == " + i.ToString());
                        }
                        else
                        {
                            Assert.IsTrue(Row.ItemArray[i].ToString() == "0", "Failed at i == " + i.ToString());
                        }
                    }
                    break;

                case "A5401532":
                    // Tobian has two publications in 1997 of type 3 with a
                    // combined weight of 4.602
                    Row = WriteAndReadBackCSVRow(reports.ReportRow(person, pubs, 1997));

                    Assert.IsTrue(Row.ItemArray.Length == 74);
                    Assert.IsTrue(Row.ItemArray[0].ToString() == "A5401532");
                    Assert.IsTrue(Row.ItemArray[1].ToString() == "1997");

                    // Verify that all values are zero, except for pubcount (#3),
                    // pubcount_pos1 (#5), 123pubcount (#15), 123pubcount_pos1 (#17),
                    // 3pubcount (#51), 3pubcount_pos1 (#53), which should be 2
                    //
                    // and wghtd_pubcount (#4), wghtd_pubcount_pos1 (#6),
                    // wghtd_123pubcount (#16), wghtd_123pubcount_pos1 (#18),
                    // wghtd_3pubcount (#52), wghtd_3pubcount_pos1 (#54),
                    // which should be 4.602
                    for (int i = 2; i <= 73; i++)
                    {
                        if ((i == 2) || (i == 4) || (i == 14) || (i == 16) ||
                            (i == 50) || (i == 52))
                        {
                            Assert.IsTrue(Row.ItemArray[i].ToString() == "2", "Failed at i == " + i.ToString());
                        }
                        else if ((i == 3) || (i == 5) || (i == 15) || (i == 17) ||
                                 (i == 51) || (i == 53))
                        {
                            Assert.IsTrue(Row.ItemArray[i].ToString() == "4.602", "Failed at i == " + i.ToString());
                        }
                        else
                        {
                            Assert.IsTrue(Row.ItemArray[i].ToString() == "0", "Failed at i == " + i.ToString());
                        }
                    }
                    break;
                }
            }
        }
Example #8
0
        public void TestSkipSetnbs()
        {
            // Set up the database with test publications (and don't forget to add the
            // publication types!)
            DB = new Database("Publication Harvester Unit Test");
            Harvester harvester = new Harvester(DB);

            harvester.CreateTables();
            PublicationTypes PubTypes = new PublicationTypes(
                AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPublicationTypes",
                "PublicationTypes.csv"
                );

            PubTypes.WriteToDB(DB);
            reports = new Reports(DB, AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestReports\\pubmed_jifs.xls");
            Assert.IsTrue(reports.Weights.Count == 10);
            TestHarvester.GetPublicationsFromInput1XLS_Using_MockNCBI(false, new string[] { "eng" }, 22);
            people = new People(DB);


            Reports.ReportStatus StatusCallback = delegate(int number, int total, Person person, bool ProgressBarOnly)
            {
                //
            };
            Reports.ReportMessage MessageCallback = delegate(string Message)
            {
                //
            };

            // Set up the Setnbs to skip
            ArrayList SetnbsToSkip = new ArrayList();

            SetnbsToSkip.Add("A5401532");
            SetnbsToSkip.Add("A6009400");

            // Verify that the people report skips the setnbs
            StreamWriter writer = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\TestSkipSetnbs.csv");

            reports.PeopleReport(SetnbsToSkip, writer, StatusCallback, MessageCallback);
            writer.Close();
            StreamReader reader = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "\\TestSkipSetnbs.csv");
            string       Line   = reader.ReadLine(); // skip the header row

            while ((Line = reader.ReadLine()) != null)
            {
                Assert.IsFalse(Line.StartsWith("A5401532"));
                Assert.IsFalse(Line.StartsWith("A6009400"));
            }
            reader.Close();

            // Verify that the people report skips the setnbs
            writer = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\TestSkipSetnbs.csv", false);
            reports.PubsReport(SetnbsToSkip, writer, StatusCallback, MessageCallback);
            writer.Close();
            reader = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "\\TestSkipSetnbs.csv");
            Line   = reader.ReadLine(); // skip the header row
            while ((Line = reader.ReadLine()) != null)
            {
                Assert.IsFalse(Line.StartsWith("A5401532"));
                Assert.IsFalse(Line.StartsWith("A6009400"));
            }
            reader.Close();

            File.Delete(AppDomain.CurrentDomain.BaseDirectory + "\\TestSkipSetnbs.csv");
        }
Example #9
0
        public void TestEntireReport()
        {
            string Setnb = "";

            // Set up the database with test publications (and don't forget to add the
            // publication types!)
            DB = new Database("Publication Harvester Unit Test");
            Harvester harvester = new Harvester(DB);

            harvester.CreateTables();
            PublicationTypes PubTypes = new PublicationTypes(
                AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPublicationTypes",
                "PublicationTypes.csv"
                );

            PubTypes.WriteToDB(DB);
            reports = new Reports(DB, AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestReports\\pubmed_jifs.xls");
            Assert.IsTrue(reports.Weights.Count == 10);
            TestHarvester.GetPublicationsFromInput1XLS_Using_MockNCBI(false, new string[] { "eng" }, 22);
            people = new People(DB);


            // Write the report
            StreamWriter writer = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\TestEntireReport.csv");

            Reports.ReportStatus StatusCallback   = delegate(int number, int total, Person person, bool ProgressBarOnly) {
                //
            };
            Reports.ReportMessage MessageCallback = delegate(string Message)
            {
                //
            };
            reports.PeopleReport(null, writer, StatusCallback, MessageCallback);
            writer.Close();

            // Read the report into an array
            var lines = File.ReadAllLines($"{AppDomain.CurrentDomain.BaseDirectory}\\TestEntireReport.csv")
                        .Select(line => line.Split(new char[] { ',' }));
            var header = lines.First();
            var data   = lines.Skip(1).ToList();

            Assert.AreEqual(85, data.Count);

            string ReportData(string setnb, string year, string column)
            {
                var index = Array.IndexOf(header, column);
                var row   = data.Where(line => line[0] == setnb && line[1] == year);

                Assert.AreEqual(1, row.Count(), $"Unable to find setnb={setnb} year={year} in TestEntireReport.csv");
                return(row.First()[index]);
            }

            var q = ReportData("A5401532", "1997", "wghtd_pubcount_pos1");

            // Read the report file that was generated by hand (TestEntireReport_Data.xls)
            // and check each value against the report that was generated by Reports()
            string[] Columns =
            {
                "setnb",                    "year",                   "pubcount",               "wghtd_pubcount",       "pubcount_pos1",
                "wghtd_pubcount_pos1",      "pubcount_posN",          "wghtd_pubcount_posN",
                "pubcount_posM",            "wghtd_pubcount_posM",    "pubcount_posNTL",
                "wghtd_pubcount_posNTL",    "pubcount_pos2",          "wghtd_pubcount_pos2",
                "123pubcount",              "wghtd_123pubcount",      "123pubcount_pos1",
                "wghtd_123pubcount_pos1",   "123pubcount_posN",       "wghtd_123pubcount_posN",
                "123pubcount_posM",         "wghtd_123pubcount_posM", "123pubcount_posNTL",
                "wghtd_123pubcount_posNTL", "123pubcount_pos2",       "wghtd_123pubcount_pos2",
                "1pubcount",                "wghtd_1pubcount",        "1pubcount_pos1",         "wghtd_1pubcount_pos1",
                "1pubcount_posN",           "wghtd_1pubcount_posN",   "1pubcount_posM",
                "wghtd_1pubcount_posM",     "1pubcount_posNTL",       "wghtd_1pubcount_posNTL",
                "1pubcount_pos2",           "wghtd_1pubcount_pos2",   "2pubcount",              "wghtd_2pubcount",
                "2pubcount_pos1",           "wghtd_2pubcount_pos1",   "2pubcount_posN",
                "wghtd_2pubcount_posN",     "2pubcount_posM",         "wghtd_2pubcount_posM",
                "2pubcount_posNTL",         "wghtd_2pubcount_posNTL", "2pubcount_pos2",
                "wghtd_2pubcount_pos2",     "3pubcount",              "wghtd_3pubcount",        "3pubcount_pos1",
                "wghtd_3pubcount_pos1",     "3pubcount_posN",         //"wghtd_3pubcount_posN",
                "3pubcount_posM",           "wghtd_3pubcount_posM",   "3pubcount_posNTL",
                "wghtd_3pubcount_posNTL",   "3pubcount_pos2",         "wghtd_3pubcount_pos2",
                "4pubcount",                "wghtd_4pubcount",        "4pubcount_pos1",         "wghtd_4pubcount_pos1",
                "4pubcount_posN",           "wghtd_4pubcount_posN",   "4pubcount_posM",
                "wghtd_4pubcount_posM",     "4pubcount_posNTL",       "wghtd_4pubcount_posNTL",
                "4pubcount_pos2",           "wghtd_4pubcount_pos2"
            };

            DataTable HandGeneratedData = NpoiHelper.ReadExcelFileToDataTable(AppDomain.CurrentDomain.BaseDirectory +
                                                                              "\\Unit Tests\\TestReports", "TestEntireReport_Data.xls");

            Assert.AreEqual(HandGeneratedData.Rows.Count, 85);

            var valuesChecked = 0;

            for (int RowNum = 0; RowNum < HandGeneratedData.Rows.Count; RowNum++)
            {
                // Find the rows in the hand-generated data and the report
                DataRow HandGeneratedRow = HandGeneratedData.Rows[RowNum];
                Setnb = HandGeneratedRow[0].ToString();
                int Year = Convert.ToInt32(HandGeneratedRow[1]);

                for (int i = 2; i < Columns.Length; i++)
                {
                    valuesChecked++;
                    String columnName    = Columns[i];
                    var    actualValue   = ReportData(Setnb, Year.ToString(), columnName);
                    string expectedValue = HandGeneratedRow[columnName].ToString();
                    Assert.AreEqual(expectedValue, actualValue, Setnb + "/" + Year.ToString() + "/" + columnName + " -- hand generated has " + expectedValue + ", report has" + actualValue);
                }
            }

            Assert.AreEqual((HandGeneratedData.Rows.Count) * (Columns.Length - 2), valuesChecked);

            // Use BackupReportAndGetSetnbs to back up the report -- check that it
            // returns the correct list of Setnbs and removes the last one from
            // the file. The last Setnb should still be in Setnb.
            ArrayList Setnbs = Reports.BackupReportAndGetSetnbs(AppDomain.CurrentDomain.BaseDirectory + "\\TestEntireReport.csv");
            // Read the backup file that was created, make sure that the last setnb in the
            // file isn't contained and the others are
            StreamReader reader = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "\\TestEntireReport.csv.bak");
            string       Line   = reader.ReadLine();   //skip the header row

            while ((Line = reader.ReadLine()) != null) // Find the last setnb in the original file
            {
                Setnb = Line.Substring(0, 8);
            }
            string RemovedSetnb = Setnb;

            Assert.IsFalse(Setnbs.Contains(RemovedSetnb));
            reader.Close();

            // Verify that the new file contains only the other setnbs
            Assert.IsTrue(Setnbs.Count == 3);
            Assert.IsFalse(Setnbs.Contains(RemovedSetnb));
            reader = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "\\TestEntireReport.csv");
            Line   = reader.ReadLine(); //skip the header row
            while ((Line = reader.ReadLine()) != null)
            {
                Setnb = Line.Substring(0, 8);
                Assert.IsTrue(Setnbs.Contains(Setnb));
                Assert.IsFalse(Setnb == RemovedSetnb);
            }
            reader.Close();

            // Delete the temporary files
            File.Delete(AppDomain.CurrentDomain.BaseDirectory + "\\TestEntireReport.csv");
            File.Delete(AppDomain.CurrentDomain.BaseDirectory + "\\TestEntireReport.csv.bak");
        }
Example #10
0
        public void TestPubsReportRow()
        {
            // Set up the database with test publications (and don't forget to add the
            // publication types!)
            DB = new Database("Publication Harvester Unit Test");
            Harvester harvester = new Harvester(DB);

            harvester.CreateTables();
            PublicationTypes PubTypes = new PublicationTypes(
                AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPublicationTypes",
                "PublicationTypes.csv"
                );

            PubTypes.WriteToDB(DB);
            reports = new Reports(DB, AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestReports\\pubmed_jifs.xls");
            Assert.IsTrue(reports.Weights.Count == 10);
            TestHarvester.GetPublicationsFromInput1XLS_Using_MockNCBI(false, new string[] { "eng" }, 22);
            people = new People(DB);


            foreach (Person person in people.PersonList)
            {
                Publications pubs = new Publications(DB, person, false);

                if (pubs.PublicationList != null)
                {
                    foreach (Publication pub in pubs.PublicationList)
                    {
                        DataRow Row = WriteAndReadBackCSVRow(reports.PubsReportRow(person, pub));

                        switch (pub.PMID)
                        {
                        case 15249795:
                            // 0. setnb
                            Assert.IsTrue(Row.ItemArray[0].ToString() == "A5401532");

                            // 1. pmid
                            Assert.IsTrue(Row.ItemArray[1].ToString() == "15249795");

                            // 2. journal_name
                            Assert.IsTrue(Row.ItemArray[2].ToString() == "J Clin Hypertens (Greenwich)");

                            // 3. year
                            Assert.IsTrue(Row.ItemArray[3].ToString() == "2004");

                            // 4. Month
                            Assert.IsTrue(Row.ItemArray[4].ToString() == "Jul");

                            // 5. day
                            Assert.IsTrue(Row.ItemArray[5].ToString() == "");

                            // 6. title
                            Assert.IsTrue(Row.ItemArray[6].ToString() == "Interview with Louis Tobian, MD. Interview by Marvin Moser.");

                            // 7. Volume
                            Assert.IsTrue(Row.ItemArray[7].ToString() == "6");

                            // 8. issue
                            Assert.IsTrue(Row.ItemArray[8].ToString() == "7");

                            // 9. position
                            Assert.IsTrue(Row.ItemArray[9].ToString() == "1");

                            // 10. nbauthors
                            Assert.IsTrue(Row.ItemArray[10].ToString() == "1");

                            // 11. Bin
                            Assert.IsTrue(Row.ItemArray[11].ToString() == "0");

                            // 12. Pages
                            Assert.IsTrue(Row.ItemArray[12].ToString() == "391-2");

                            // 13. Publication_type
                            Assert.IsTrue(Row.ItemArray[13].ToString() == "Historical Article");


                            break;
                        }
                    }
                }
            }
        }
Example #11
0
        /// <summary>
        /// Set up the database with data from Input1.XLS using the Mock NCBI object
        /// (this is also called from TestReports())
        /// </summary>
        /// <param name="NCBISearchThrowsAnError">True if the MockNCBI object is supposed to throw an error</param>
        public static void GetPublicationsFromInput1XLS_Using_MockNCBI(bool NCBISearchThrowsAnError, string[] Languages, int ExpectedPublications)
        {
            bool TablesCreated;
            int  NumPeople;
            int  NumHarvestedPeople;
            int  NumPublications;
            int  NumErrors;

            Database DB = new Database("Publication Harvester Unit Test");

            // Drop all tables and make sure the database reports as empty
            foreach (string Table in new string[] {
                "meshheadings", "people", "peoplepublications", "publicationauthors",
                "publicationmeshheadings", "publications", "pubtypecategories"
            })
            {
                DB.ExecuteNonQuery("DROP TABLE IF EXISTS " + Table);
                DB.GetStatus(out TablesCreated, out NumPeople, out NumHarvestedPeople, out NumPublications, out NumErrors);
                Assert.IsFalse(TablesCreated);
                Assert.AreEqual(NumPeople, 0);
                Assert.AreEqual(NumHarvestedPeople, 0);
                Assert.AreEqual(NumPublications, 0);
                Assert.AreEqual(NumErrors, 0);
            }

            // Create and populate the tables
            Harvester harvester = new Harvester(DB);

            harvester.Languages = Languages;
            MockNCBI mockNCBI = new MockNCBI("medline");

            mockNCBI.SearchThrowsAnError = NCBISearchThrowsAnError;
            PublicationTypes ptc = new PublicationTypes(
                AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPublicationTypes",
                "PublicationTypes.csv"
                );

            // Reinitialize the database
            harvester.CreateTables();
            ptc.WriteToDB(DB);

            // Retrieve the publications for each person in input1.xls using GetPublications()
            People PeopleFromFile = new People(
                AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPeople",
                "input1.xls");

            // Make an anonymous callback function that keeps track of the callback data
            int Callbacks = 0; // this will count all of the publications

            Harvester.GetPublicationsStatus StatusCallback = delegate(int number, int total, int averageTime)
            {
                Callbacks++;
            };

            // Make an anonymous callback function to do nothing for GetPublicationsMessage
            Harvester.GetPublicationsMessage MessageCallback = delegate(string Message, bool StatusBarOnly)
            {
                //
            };

            // Make an anonymous callback function to return false for CheckForInterrupt
            Harvester.CheckForInterrupt InterruptCallback = delegate()
            {
                return(false);
            };


            // Verify that the database was created and populated properly
            DB.GetStatus(out TablesCreated, out NumPeople, out NumHarvestedPeople, out NumPublications, out NumErrors);
            Assert.IsTrue(TablesCreated);
            Assert.AreEqual(NumPeople, 0);
            Assert.AreEqual(NumHarvestedPeople, 0);
            Assert.AreEqual(NumPublications, 0);
            Assert.AreEqual(NumErrors, 0);

            int PeopleCount    = 0;
            int HarvestedCount = 0;
            int PubCount       = 0;

            foreach (Person person in PeopleFromFile.PersonList)
            {
                double AverageMilliseconds;

                // First write the person to the database
                person.WriteToDB(DB);
                PeopleCount++;

                // Check that the database status is updated properly
                DB.GetStatus(out TablesCreated, out NumPeople, out NumHarvestedPeople, out NumPublications, out NumErrors);
                Assert.IsTrue(TablesCreated);
                Assert.AreEqual(NumPeople, PeopleCount);
                if (!NCBISearchThrowsAnError)
                {
                    Assert.AreEqual(NumHarvestedPeople, HarvestedCount);
                }
                else
                {
                    Assert.AreEqual(NumHarvestedPeople, 0);
                }
                Assert.AreEqual(NumPublications, PubCount);
                if (!NCBISearchThrowsAnError)
                {
                    Assert.AreEqual(NumErrors, 0);
                }
                else
                {
                    Assert.AreEqual(NumErrors, PeopleCount - 1);
                }

                // Harvest the person's publications
                PubCount += harvester.GetPublications(mockNCBI, ptc, person, StatusCallback, MessageCallback, InterruptCallback, out AverageMilliseconds);
                HarvestedCount++;

                // Check the status again after the people were harvested
                DB.GetStatus(out TablesCreated, out NumPeople, out NumHarvestedPeople, out NumPublications, out NumErrors);
                Assert.IsTrue(TablesCreated);
                Assert.AreEqual(NumPeople, PeopleCount);
                if (!NCBISearchThrowsAnError)
                {
                    Assert.AreEqual(NumHarvestedPeople, HarvestedCount);
                }
                else
                {
                    Assert.AreEqual(NumHarvestedPeople, 0);
                }
                Assert.AreEqual(NumPublications, PubCount);
                if (!NCBISearchThrowsAnError)
                {
                    Assert.AreEqual(NumErrors, 0);
                }
                else
                {
                    Assert.AreEqual(NumErrors, PeopleCount);
                }
            }

            // Verify that the database was written properly
            if (!NCBISearchThrowsAnError)
            {
                Assert.IsTrue(Callbacks == 24);
            }
            else
            {
                Assert.IsTrue(Callbacks == 0);
            }
            DB.GetStatus(out TablesCreated, out NumPeople, out NumHarvestedPeople, out NumPublications, out NumErrors);
            Assert.IsTrue(TablesCreated);
            Assert.AreEqual(NumPeople, 4);
            if (!NCBISearchThrowsAnError)
            {
                Assert.AreEqual(NumHarvestedPeople, 4);
                Assert.AreEqual(NumPublications, ExpectedPublications);
                Assert.AreEqual(NumErrors, 0);
            }
            else
            {
                Assert.AreEqual(NumHarvestedPeople, 0);
                Assert.AreEqual(NumPublications, 0);
                Assert.AreEqual(NumErrors, 4);
            }
        }
Example #12
0
        /// <summary>
        /// Harvest each of the publications in the people file
        /// </summary>
        /// <param name="PeopleFile">Filename of the people file</param>
        /// <param name="PublicationTypeFile">Filename of publication type file</param>
        /// <param name="ContinueFromInterruption">True if continuing from a previously interrupted harvest</param>
        public void Harvest(string PeopleFile, string PublicationTypeFile, bool ContinueFromInterruption)
        {
            // First verify that the files exist
            if (!File.Exists(PeopleFile))
            {
                MessageBox.Show("The People file '" + PeopleFile + "' does not exist", "People file not found", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (!File.Exists(PublicationTypeFile))
            {
                MessageBox.Show("The Publication Type file '" + PublicationTypeFile + "' does not exist", "Publication Type file not found", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }


            UpdateDatabaseStatus();
            if (ContinueFromInterruption)
            {
                AddLogEntry("Continuing interrupted harvest");
            }
            else
            {
                AddLogEntry("Beginning harvesting");
            }

            // Reset lastDSNSelected to make sure that the next check for interrupted data is NOT skipped
            lastDSNSelected = "";

            // Initialize the harvester
            Harvester harvester;
            Database  DB;

            // Initialize objects
            try
            {
                DB        = new Database(DSN.Text);
                harvester = new Harvester(DB);

                // Set the language restriction
                string[] Languages;
                if (LanguageList.Text != "")
                {
                    Languages           = LanguageList.Text.Split(',');
                    harvester.Languages = Languages;
                    foreach (string Language in Languages)
                    {
                        AddLogEntry("Adding language restriction: " + Language);
                    }
                }
                else
                {
                    AddLogEntry("No language restriction added");
                }
            }
            catch (Exception ex)
            {
                AddLogEntryWithErrorBox(ex.Message, "Unable to begin harvesting");
                return;
            }

            // Initializethe database
            try
            {
                if (!ContinueFromInterruption)
                {
                    AddLogEntry("Initializing the database");
                    harvester.CreateTables();
                    UpdateDatabaseStatus();
                }
            }
            catch (Exception ex)
            {
                AddLogEntryWithErrorBox(ex.Message, "Unable to initialize database");
                return;
            }


            PublicationTypes pubTypes;

            if (ContinueFromInterruption)
            {
                // If we're continuing, read the publication types from the databse
                try
                {
                    AddLogEntry("Reading publication types from the database");
                    pubTypes = new PublicationTypes(DB);
                }
                catch (Exception ex)
                {
                    AddLogEntryWithErrorBox(ex.Message, "Unable to read publication types");
                    return;
                }
                // Remove any data left over from the interruption
                if (ContinueFromInterruption)
                {
                    AddLogEntry("Removing any data left over from the previous interruption");
                    harvester.ClearDataAfterInterruption();
                }
                UpdateDatabaseStatus();
            }
            else
            {
                // Read the publication types from the file and write them to the database
                try
                {
                    AddLogEntry("Writing publication types to database");
                    pubTypes = new PublicationTypes(Path.GetDirectoryName(PublicationTypeFile), Path.GetFileName(PublicationTypeFile));
                    pubTypes.WriteToDB(DB);
                    UpdateDatabaseStatus();
                }
                catch (Exception ex)
                {
                    AddLogEntryWithErrorBox(ex.Message, "Unable to read publication types");
                    return;
                }

                // Read the people
                try
                {
                    AddLogEntry("Reading people from " + Path.GetFileName(PeopleFile) + " and writing them to the database");
                    harvester.ImportPeople(PeopleFile);
                    UpdateDatabaseStatus();
                }
                catch (Exception ex)
                {
                    AddLogEntryWithErrorBox(ex.Message, "Unable to read the people from " + Path.GetFileName(PeopleFile));
                    return;
                }
            }


            // Make an anonymous callback function that keeps track of the callback data
            Harvester.GetPublicationsStatus StatusCallback = delegate(int number, int total, int averageTime)
            {
                // No need to update the progress bar for this -- it leads to a messy-looking UI because it's also updated for the person total
                // toolStripProgressBar1.Minimum = 0;
                // toolStripProgressBar1.Maximum = total;
                // toolStripProgressBar1.Value = number;
                toolStripStatusLabel1.Text = "Reading publication " + number.ToString() + " of " + total.ToString() + " (" + averageTime.ToString() + " ms average)";
                UpdateDatabaseStatus();
                Application.DoEvents();
            };

            // Make an anonymous callback function that logs any messages passed back
            Harvester.GetPublicationsMessage MessageCallback = delegate(string Message, bool StatusBarOnly)
            {
                if (StatusBarOnly)
                {
                    toolStripStatusLabel1.Text = Message;
                    //this.Refresh();
                    //statusStrip1.Refresh();
                    Application.DoEvents();
                }
                else
                {
                    AddLogEntry(Message);
                }
            };

            // Make an anonymous callback function to return the value of Interrupt for CheckForInterrupt
            Harvester.CheckForInterrupt InterruptCallback = delegate()
            {
                return(InterruptClicked);
            };

            // Get each person's publications and write them to the database
            NCBI ncbi = new NCBI("medline");

            if (NCBI.ApiKeyExists)
            {
                AddLogEntry("Using API key: " + NCBI.ApiKeyPath);
            }
            else
            {
                AddLogEntry("Performance is limited to under 3 requests per second.");
                AddLogEntry("Consider pasting an API key into " + NCBI.ApiKeyPath);
                AddLogEntry("Or set the NCBI_API_KEY_FILE environemnt variable to the API key file path");
                AddLogEntry("For more information, see https://ncbiinsights.ncbi.nlm.nih.gov/2017/11/02/new-api-keys-for-the-e-utilities/");
            }
            People people = new People(DB);
            int    totalPeopleInPersonList = people.PersonList.Count;
            int    numberOfPeopleProcessed = 0;

            toolStripProgressBar1.Minimum = 0;
            toolStripProgressBar1.Maximum = totalPeopleInPersonList;

            foreach (Person person in people.PersonList)
            {
                numberOfPeopleProcessed++;
                try
                {
                    // If continuing from interruption, only harvest unharvested people
                    if ((!ContinueFromInterruption) || (!person.Harvested))
                    {
                        AddLogEntry("Getting publications for " + person.Last + " (" + person.Setnb + "), number " + numberOfPeopleProcessed.ToString() + " of " + totalPeopleInPersonList.ToString());
                        toolStripProgressBar1.Value = numberOfPeopleProcessed;
                        double AverageMilliseconds;
                        int    NumPublications = harvester.GetPublications(ncbi, pubTypes, person, StatusCallback, MessageCallback, InterruptCallback, out AverageMilliseconds);
                        if (InterruptClicked)
                        {
                            AddLogEntry("Publication harvesting was interrupted");
                            UpdateDatabaseStatus();
                            return;
                        }
                        AddLogEntry("Wrote " + NumPublications.ToString() + " publications, average write time " + Convert.ToString(Math.Round(AverageMilliseconds, 1)) + " ms");
                        UpdateDatabaseStatus();
                    }
                    else
                    {
                        AddLogEntry("Already retrieved publications for " + person.Last + " (" + person.Setnb + ")");
                    }
                }
                catch (Exception ex)
                {
                    AddLogEntry("An error occurred while reading publications for " + person.Last + " (" + person.Setnb + "): " + ex.Message);
                }
            }

            AddLogEntry("Finished reading publications");
            UpdateDatabaseStatus();
        }
        public void TestMiddleAuthor()
        {
            string MedlineData = @"PMID- 14332364
OWN - NLM
STAT- OLDMEDLINE
DA  - 19651101
DCOM- 19961201
LR  - 20051116
PUBM- Print
IS  - 0002-922X (Print)
VI  - 110
DP  - 1965 Sep
TI  - CONGENITAL SCALP DEFECTS IN TWIN SISTERS.
PG  - 293-5
FAU - HODGMAN, J E
AU  - HODGMAN JE
FAU - MATHIES, A W Jr
AU  - MATHIES AW Jr
FAU - LEVAN, N E
AU  - LEVAN NE
LA  - eng
PT  - Journal Article
PL  - UNITED STATES
TA  - Am J Dis Child
JT  - American journal of diseases of children (1960)
JID - 0370471
SB  - OM
MH  - *Abnormalities
MH  - *Diseases in Twins
MH  - *Infant, Newborn
MH  - *Scalp
OTO - NLM
OT  - *ABNORMALITIES
OT  - *DISEASES IN TWINS
OT  - *INFANT, NEWBORN
OT  - *SCALP
EDAT- 1965/09/01
MHDA- 1965/09/01 00:01
PST - ppublish
SO  - Am J Dis Child. 1965 Sep;110:293-5.";

            // Add a person to the database
            Database DB      = new Database("Publication Harvester Unit Test");
            Person   Mathies = new Person("A5703161", "Allan", "W", "MATHIES", false,
                                          new String[] { "MATHIES AW Jr" }, "MATHIES AW Jr[au]");

            // Create the publication
            PublicationTypes ptc = new PublicationTypes(
                AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPublicationTypes",
                "PublicationTypes.csv"
                );
            Publications Pubs = new Publications(MedlineData, ptc);

            Assert.IsTrue(Pubs.PublicationList.Length == 1);
            Publication Pub = Pubs.PublicationList[0];

            Assert.IsTrue(Pub.Authors[1] == "MATHIES AW Jr");

            // Clear the database
            Harvester harvester = new Harvester(DB);

            harvester.CreateTables();

            // Write the person and publication to the database
            // NOTE: The author position is determined in WritePeoplePublicationsToDB()
            PublicationTypes PubTypes = new PublicationTypes(
                AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPublicationTypes",
                "PublicationTypes.csv"
                );

            Mathies.WriteToDB(DB);
            Publications.WriteToDB(Pub, DB, PubTypes, new string[] { "eng" });
            Publications.WritePeoplePublicationsToDB(DB, Mathies, Pub);

            // Verify that Mathies is the middle author, not the second author
            Publications PubsFromDB = new Publications(DB, Mathies, false);

            Assert.IsTrue(PubsFromDB.PublicationList.Length == 1);
            Assert.IsTrue(PubsFromDB.PublicationList[0].PMID == 14332364);
            Harvester.AuthorPositions PositionType;
            Assert.IsTrue(Publications.GetAuthorPosition(DB, 14332364, Mathies, out PositionType, "PeoplePublications") == 2);
            Assert.IsTrue(PositionType == Harvester.AuthorPositions.Middle);
        }
        public void TestWriteToDB()
        {
            // Create a new database and write the publication to it
            Database  DB = new Database("Publication Harvester Unit Test");
            Harvester h  = new Harvester(DB);

            h.CreateTables();
            Publication      p   = CreateTestPublication();
            PublicationTypes ptc = new PublicationTypes(
                AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPublicationTypes",
                "PublicationTypes.csv"
                );

            Publications.WriteToDB(p, DB, ptc, new string[] { "eng" });

            // Verify the publication has been added
            DataTable Results = DB.ExecuteQuery(
                @"SELECT Journal, Year, Authors, Month, Day, Title, Volume,
                         Issue, Pages, PubType, PubTypeCategoryID
                    FROM Publications
                   WHERE PMID = 15904469"
                );

            Assert.IsTrue(Results.Rows[0]["Year"].Equals(2005));
            Assert.IsTrue(Results.Rows[0]["Authors"].Equals(4));
            Assert.IsTrue(Results.Rows[0]["Year"].Equals(2005));
            Assert.IsTrue(Results.Rows[0]["Month"].Equals("May"));
            Assert.IsTrue(Results.Rows[0]["Day"].Equals(DBNull.Value));
            Assert.IsTrue(Results.Rows[0]["Title"].Equals("Charcoal cigarette filters and lung cancer risk in Aichi Prefecture, Japan."));
            Assert.IsTrue(Results.Rows[0]["Volume"].Equals("96"));
            Assert.IsTrue(Results.Rows[0]["Issue"].Equals("5"));
            Assert.IsTrue(Results.Rows[0]["Pages"].Equals("283-7"));
            Assert.IsTrue(Results.Rows[0]["PubType"].Equals("Clinical Trial"));
            Assert.IsTrue(Results.Rows[0]["PubTypeCategoryID"].Equals((short)1));


            // Verify the authors
            Assert.IsTrue(DB.GetIntValue("SELECT Count(*) FROM PublicationAuthors") == 4);
            Results = DB.ExecuteQuery("SELECT PMID, Position, Author, First, Last FROM PublicationAuthors ORDER BY Position");
            Assert.IsTrue(Results.Rows[0]["PMID"].Equals(15904469));
            Assert.IsTrue(Results.Rows[1]["PMID"].Equals(15904469));
            Assert.IsTrue(Results.Rows[2]["PMID"].Equals(15904469));
            Assert.IsTrue(Results.Rows[3]["PMID"].Equals(15904469));
            Assert.IsTrue(Results.Rows[0]["Position"].Equals(1));
            Assert.IsTrue(Results.Rows[1]["Position"].Equals(2));
            Assert.IsTrue(Results.Rows[2]["Position"].Equals(3));
            Assert.IsTrue(Results.Rows[3]["Position"].Equals(4));
            Assert.IsTrue(Results.Rows[0]["Author"].ToString() == "Muscat JE");
            Assert.IsTrue(Results.Rows[1]["Author"].ToString() == "Takezaki T");
            Assert.IsTrue(Results.Rows[2]["Author"].ToString() == "Tajima K");
            Assert.IsTrue(Results.Rows[3]["Author"].ToString() == "Stellman SD");
            Assert.IsTrue(Results.Rows[0]["First"].Equals((short)1));
            Assert.IsTrue(Results.Rows[1]["First"].Equals((short)0));
            Assert.IsTrue(Results.Rows[2]["First"].Equals((short)0));
            Assert.IsTrue(Results.Rows[3]["First"].Equals((short)0));
            Assert.IsTrue(Results.Rows[0]["Last"].Equals((short)0));
            Assert.IsTrue(Results.Rows[1]["Last"].Equals((short)0));
            Assert.IsTrue(Results.Rows[2]["Last"].Equals((short)0));
            Assert.IsTrue(Results.Rows[3]["Last"].Equals((short)1));

            // Verifying the MeSH headings
            // Note the join to PublicationMeSHHeadings to make sure it was populated properly
            Assert.IsTrue(DB.GetIntValue("SELECT Count(*) FROM PublicationMeSHHeadings WHERE PMID = " + p.PMID.ToString()) == 17);
            Results = DB.ExecuteQuery(
                @"SELECT m.Heading 
                    FROM MeSHHeadings m, PublicationMeSHHeadings p
                   WHERE p.MeSHHeadingID = m.ID
                     AND p.PMID = " + p.PMID.ToString()
                );
            Assert.IsTrue(Results.Rows.Count == 17);
            Assert.IsTrue(Results.Rows[0]["Heading"].ToString() == "Adult");
            Assert.IsTrue(Results.Rows[5]["Heading"].ToString() == "Female");
            Assert.IsTrue(Results.Rows[9]["Heading"].ToString() == "Lung Neoplasms/*etiology/pathology");
            Assert.IsTrue(Results.Rows[16]["Heading"].ToString() == "Smoking/*adverse effects");

            // Verify the grants
            Assert.IsTrue(DB.GetIntValue("SELECT Count(*) FROM PublicationGrants WHERE PMID = " + p.PMID.ToString()) == 2);
            Results = DB.ExecuteQuery(
                @"SELECT GrantID
                    FROM PublicationGrants
                   WHERE PMID = " + p.PMID.ToString() + " ORDER BY GrantID ASC"
                );
            Assert.IsTrue(Results.Rows[0]["GrantID"].ToString() == "CA-17613/CA/NCI");
            Assert.IsTrue(Results.Rows[1]["GrantID"].ToString() == "CA-68387/CA/NCI");
        }
Example #15
0
        public void TestOtherPeople()
        {
            // Note: Publication 14560782 was added to OtherPeople.dat to verify
            // that the software handles the situation where a publication has
            // no authors listed.

            Database         DB        = new Database("Publication Harvester Unit Test");
            Harvester        harvester = new Harvester(DB);
            MockNCBI         mockNCBI  = new MockNCBI("medline");
            PublicationTypes ptc       = new PublicationTypes(
                AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPublicationTypes",
                "PublicationTypes.csv"
                );

            // Reinitialize the database
            harvester.CreateTables();

            // Make an anonymous callback function that keeps track of the callback data
            int Callbacks = 0; // this will count all of the publications

            Harvester.GetPublicationsStatus StatusCallback = delegate(int number, int total, int averageTime)
            {
                Callbacks++;
            };

            // Make an anonymous callback function to do nothing for GetPublicationsMessage
            Harvester.GetPublicationsMessage MessageCallback = delegate(string Message, bool StatusBarOnly)
            {
                //
            };

            // Make an anonymous callback function to return false for CheckForInterrupt
            Harvester.CheckForInterrupt InterruptCallback = delegate()
            {
                return(false);
            };

            // Create a new person to test
            string[] names = new string[2];
            names[0] = "Klein RG";
            names[1] = "Guillemin R";
            Person person = new Person("A1234567", "FIRST", "MIDDLE", "LAST",
                                       false, names, "Special query for OtherPeople.dat");

            person.WriteToDB(DB);
            double AverageMilliseconds;

            harvester.GetPublications(mockNCBI, ptc, person, StatusCallback, MessageCallback, InterruptCallback, out AverageMilliseconds);

            // Verify that the data was written properly
            int          FoundPublications = 0;
            Publications pubs = new Publications(DB, person, false);

            if (pubs.PublicationList != null)
            {
                foreach (Publication pub in pubs.PublicationList)
                {
                    FoundPublications++;
                    switch (pub.PMID)
                    {
                    case 12679283:
                        // The weird part of this publication is the second MeSH heading, which is very long
                        Assert.IsTrue(pub.MeSHHeadings.Count == 23);
                        Assert.IsTrue(pub.MeSHHeadings.Contains(
                                          "Attention Deficit and Disruptive Behavior Disorders/etiology/*prevention & control/psychology"));
                        break;

                    case 2417121:
                        // The weird part of this publication is the date, which has a weird format that causes
                        // the day to be long
                        Assert.IsTrue(pub.Day == "19-1986 Jan 1");
                        break;

                    case 6148773:
                        // One of the headers is long
                        Assert.IsTrue(pub.MeSHHeadings.Contains("Peptide Fragments/antagonists & inhibitors/chemical synthesis/diagnostic use/isolation & purification/pharmacology/*physiology"));
                        break;

                    case 16291338:
                        // One of the authors is long
                        Assert.IsTrue(pub.Authors.Length == 8);
                        Assert.IsTrue(pub.Authors[7] == "For The Michigan Alliance For The National Children's Study");
                        break;

                    case 15451956:
                        // Volume is long
                        Assert.IsTrue(pub.Volume == "Suppl Web Exclusives");
                        break;

                    case 14653276:
                        // Issue is long
                        Assert.IsTrue(pub.Issue == "5 Suppl Nitric Oxide");
                        break;

                    case 9965612:
                        // Journal name is long
                        Assert.IsTrue(pub.Journal == "PHYSICAL REVIEW. E. STATISTICAL PHYSICS, PLASMAS, FLUIDS, AND RELATED INTERDISCIPLINARY TOPICS");
                        break;

                    case 9469584:
                        // Title is long
                        Assert.IsTrue(pub.Title ==
                                      Database.Left("Down-regulation of cholesterol biosynthesis in sitosterolemia: diminished activities of acetoacetyl-CoA thiolase, 3-hydroxy-3-methylglutaryl-CoA synthase, reductase, squalene synthase, and 7-dehydrocholesterol delta7-reductase in liver and mononuclear leukocytes."
                                                    , 244));
                        break;

                    case 2545230:
                        // Month is long
                        Assert.IsTrue(pub.Month == "Spring-Summer");
                        break;

                    default:
                        break;
                    }
                }
            }
            Assert.IsTrue(FoundPublications == 13);
        }
Example #16
0
        public void TestMeSHHeadingReport()
        {
            // Set up the database with test publications (and don't forget to add the
            // publication types!)
            DB = new Database("Publication Harvester Unit Test");
            Harvester harvester = new Harvester(DB);

            harvester.CreateTables();
            PublicationTypes PubTypes = new PublicationTypes(
                AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPublicationTypes",
                "PublicationTypes.csv"
                );

            PubTypes.WriteToDB(DB);
            reports = new Reports(DB, AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestReports\\pubmed_jifs.xls");
            Assert.IsTrue(reports.Weights.Count == 10);
            TestHarvester.GetPublicationsFromInput1XLS_Using_MockNCBI(false, new string[] { "eng" }, 22);

            // Write the MeSH Heading report
            StreamWriter writer = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\MeSHHeadingReport.csv");

            Reports.ReportStatus StatusCallback = delegate(int number, int total, Person person, bool ProgressBarOnly)
            {
                //
            };
            Reports.ReportMessage MessageCallback = delegate(string Message)
            {
                //
            };
            reports.MeSHHeadingReport(writer, StatusCallback, MessageCallback);
            writer.Close();

            // Verify that the MeSH headings were written properly

            // Read the rows back from the file
            string ConnectionString =
                "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq="
                + AppDomain.CurrentDomain.BaseDirectory + ";";
            OdbcConnection  Connection  = new OdbcConnection(ConnectionString);
            OdbcDataAdapter DataAdapter = new OdbcDataAdapter
                                              ("SELECT * FROM [MeSHHeadingReport.csv]", Connection);
            DataTable Results = new DataTable();
            int       Rows    = DataAdapter.Fill(Results);

            Connection.Close();

            int numChecked = 0;

            // Check a few selected results
            foreach (DataRow Row in Results.Rows)
            {
                string Setnb   = Row[0].ToString();
                int    Year    = Convert.ToInt32(Row[1]);
                string Heading = Row[2].ToString();
                int    Count   = Convert.ToInt32(Row[3]);

                switch (Setnb)
                {
                case "A6009400":     // Van Eys
                    if ((Year == 1998) && (Heading == "Humans"))
                    {
                        Assert.IsTrue(Count == 2);
                        numChecked++;
                    }
                    if ((Year == 1998) && (Heading == "Child"))
                    {
                        Assert.IsTrue(Count == 1);
                        numChecked++;
                    }
                    if ((Year == 2001) && (Heading == "Humans"))
                    {
                        Assert.IsTrue(Count == 1);
                        numChecked++;
                    }
                    break;

                case "A5702471":     // Guillemin
                    if ((Year == 2005) && (Heading == "Hypothalamic Hormones/*physiology"))
                    {
                        Assert.IsTrue(Count == 1);
                        numChecked++;
                    }
                    break;
                }
            }
            Assert.IsTrue(numChecked == 4);

            File.Delete(AppDomain.CurrentDomain.BaseDirectory + "\\MeSHHeadingReport.csv");
        }
Example #17
0
        public void TestGrantsReport()
        {
            // Set up the database with test publications (and don't forget to add the
            // publication types!)
            DB = new Database("Publication Harvester Unit Test");
            Harvester harvester = new Harvester(DB);

            harvester.CreateTables();
            PublicationTypes PubTypes = new PublicationTypes(
                AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPublicationTypes",
                "PublicationTypes.csv"
                );

            PubTypes.WriteToDB(DB);
            reports = new Reports(DB, AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestReports\\pubmed_jifs.xls");
            Assert.IsTrue(reports.Weights.Count == 10);
            TestHarvester.GetPublicationsFromInput1XLS_Using_MockNCBI(false, new string[] { "eng" }, 22);

            // Write the grants report
            StreamWriter writer = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\GrantsReport.csv");

            reports.GrantsReport(writer);
            writer.Close();

            // Verify that the grants were written properly

            // Read the rows back from the file
            string ConnectionString =
                "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq="
                + AppDomain.CurrentDomain.BaseDirectory + ";";
            OdbcConnection  Connection  = new OdbcConnection(ConnectionString);
            OdbcDataAdapter DataAdapter = new OdbcDataAdapter
                                              ("SELECT * FROM [GrantsReport.csv]", Connection);
            DataTable Results = new DataTable();
            int       Rows    = DataAdapter.Fill(Results);

            Connection.Close();

            int numChecked = 0;

            // Check a few selected results
            foreach (DataRow Row in Results.Rows)
            {
                int    Year    = Convert.ToInt32(Row[0]);
                int    PMID    = Convert.ToInt32(Row[1]);
                string GrantID = Row[2].ToString();

                switch (PMID)
                {
                case 3086749:     // Guillemin
                    numChecked++;
                    Assert.IsTrue((Year == 1986) && (
                                      (GrantID == "AM-18811/AM/NIADDK") ||
                                      (GrantID == "HD-09690/HD/NICHD") ||
                                      (GrantID == "MH-00663/MH/NIMH") ||
                                      (GrantID == "AG 03106/AG/NIA") ||
                                      (GrantID == "DK-26741/DK/NIDDK")));
                    break;

                case 9049886:     // Van Eys
                    numChecked++;
                    Assert.IsTrue((Year == 1997) && (GrantID == "RO1-CA33097/CA/NCI"));
                    break;
                }
            }
            Assert.IsTrue(numChecked == 6);

            File.Delete(AppDomain.CurrentDomain.BaseDirectory + "\\GrantsReport.csv");
        }
Example #18
0
        public void WriteAPersonTwice()
        {
            string[] Names         = { "a", "b", "c" };
            Person   PersonToWrite = new Person("1234ABCD", "First", "Middle", "Last",
                                                false, Names, "Medline search query");

            Assert.IsTrue(PersonToWrite.Setnb == "1234ABCD");
            Assert.IsTrue(PersonToWrite.First == "First");
            Assert.IsTrue(PersonToWrite.Middle == "Middle");
            Assert.IsTrue(PersonToWrite.Last == "Last");
            Assert.IsTrue(PersonToWrite.Harvested == false);
            Assert.IsTrue(PersonToWrite.Names.Length == 3);
            Assert.IsTrue(PersonToWrite.Names[0] == "a");
            Assert.IsTrue(PersonToWrite.Names[1] == "b");
            Assert.IsTrue(PersonToWrite.Names[2] == "c");
            Assert.IsTrue(PersonToWrite.MedlineSearch == "Medline search query");

            // Write the person to the database
            Database  DB        = new Database("Publication Harvester Unit Test");
            Harvester harvester = new Harvester(DB);

            harvester.CreateTables();
            PersonToWrite.WriteToDB(DB);

            // Read the person back from the database
            DataTable PeopleFileData = new DataTable();

            PeopleFileData = DB.ExecuteQuery("SELECT " + Database.PEOPLE_COLUMNS + " FROM People WHERE Setnb = '1234ABCD'");
            Assert.IsTrue(PeopleFileData.Rows.Count == 1);
            Person PersonToRead = new Person(PeopleFileData.Rows[0], PeopleFileData.Columns);

            Assert.IsTrue(PersonToRead.Setnb == "1234ABCD");
            Assert.IsTrue(PersonToRead.First == "First");
            Assert.IsTrue(PersonToRead.Middle == "Middle");
            Assert.IsTrue(PersonToRead.Last == "Last");
            Assert.IsTrue(PersonToRead.Harvested == false);
            Assert.IsTrue(PersonToRead.Names.Length == 3);
            Assert.IsTrue(PersonToRead.Names[0] == "a");
            Assert.IsTrue(PersonToRead.Names[1] == "b");
            Assert.IsTrue(PersonToRead.Names[2] == "c");
            Assert.IsTrue(PersonToRead.MedlineSearch == "Medline search query");

            // Update the database, read him back again, and make sure there's still
            // one row in People
            PersonToRead.First         = "NewFirst";
            PersonToRead.Middle        = "NewMiddle";
            PersonToRead.Last          = "NewLast";
            PersonToRead.Names         = new string[] { "d", "e", "f", "g" };
            PersonToRead.MedlineSearch = "new query";
            PersonToRead.Harvested     = true;
            PersonToRead.WriteToDB(DB);
            DataTable Results = DB.ExecuteQuery("SELECT " + Database.PEOPLE_COLUMNS + " FROM People WHERE Setnb = '1234ABCD'");

            Assert.IsTrue(Results.Rows.Count == 1);
            Assert.IsTrue(Results.Rows[0]["Setnb"].ToString() == "1234ABCD");
            Assert.IsTrue(Results.Rows[0]["First"].ToString() == "NewFirst");
            Assert.IsTrue(Results.Rows[0]["Middle"].ToString() == "NewMiddle");
            Assert.IsTrue(Results.Rows[0]["Last"].ToString() == "NewLast");
            Assert.IsTrue(Results.Rows[0]["Name1"].ToString() == "d");
            Assert.IsTrue(Results.Rows[0]["Name2"].ToString() == "e");
            Assert.IsTrue(Results.Rows[0]["Name3"].ToString() == "f");
            Assert.IsTrue(Results.Rows[0]["Name4"].ToString() == "g");
            Assert.IsTrue(Results.Rows[0]["MedlineSearch"].ToString() == "new query");

            bool boolValue;

            Assert.IsTrue(Database.GetBoolValue(Results.Rows[0]["Harvested"], out boolValue));
            Assert.IsTrue(boolValue);

            // Make sure that Name2 through Name4 are updated properly when nulls are inserted
            PersonToRead.Names = new string[] { "a name" };
            PersonToRead.WriteToDB(DB);
            Results = DB.ExecuteQuery("SELECT " + Database.PEOPLE_COLUMNS + " FROM People WHERE Setnb = '1234ABCD'");
            Assert.IsTrue(Results.Rows[0]["Name1"].ToString() == "a name");
            Assert.IsTrue(Results.Rows[0]["Name2"].Equals(DBNull.Value));
            Assert.IsTrue(Results.Rows[0]["Name3"].Equals(DBNull.Value));
            Assert.IsTrue(Results.Rows[0]["Name4"].Equals(DBNull.Value));
        }
        public void TestColleaguesSetUp()
        {
            // Create the AAMC roster object
            roster = new Roster(AppDomain.CurrentDomain.BaseDirectory + "\\Test Data\\TestRoster\\testroster.csv");


            // Stuff for GetPublications()

            // Make an anonymous callback function that keeps track of the callback data
            Harvester.GetPublicationsStatus StatusCallback = delegate(int number, int total, int averageTime)
            {
                //
            };
            // Make an anonymous callback function to do nothing for GetPublicationsMessage
            Harvester.GetPublicationsMessage MessageCallback = delegate(string Message, bool StatusBarOnly)
            {
                //
            };
            // Make an anonymous callback function to return false for CheckForInterrupt
            Harvester.CheckForInterrupt InterruptCallback = delegate()
            {
                return(false);
            };
            double AverageMilliseconds;



            // Read the people file
            People PeopleFromFile = new People(
                AppDomain.CurrentDomain.BaseDirectory + "\\Test Data\\TestColleagues",
                "PeopleFile.xls");

            // Drop all tables from the test database
            DB = new Database("Colleague Generator Unit Test");
            foreach (string Table in new string[]
            {
                "colleaguepublications", "colleagues", "meshheadings",
                "people", "peoplepublications", "publicationauthors",
                "publicationgrants", "publicationmeshheadings", "publications",
                "pubtypecategories", "starcolleagues"
            }
                     )
            {
                DB.ExecuteNonQuery("DROP TABLE IF EXISTS " + Table + ";");
            }

            // Create the test database
            harvester = new Harvester(DB);
            harvester.CreateTables();
            ColleagueFinder.CreateTables(DB);

            // Populate it using the Mock NCBI object
            ncbi     = new MockNCBI("Medline");
            PubTypes = new PublicationTypes(
                AppDomain.CurrentDomain.BaseDirectory + "\\Test Data\\TestColleagues",
                "PublicationTypes.csv"
                );

            // Write each person and his publications to the database
            foreach (Person person in PeopleFromFile.PersonList)
            {
                person.WriteToDB(DB);
                harvester.GetPublications(ncbi, PubTypes, person, StatusCallback, MessageCallback, InterruptCallback, out AverageMilliseconds);
            }
        }
Example #20
0
        public void GetPeopleFromInputXLS()
        {
            // Import input1.xls into the database
            Database  DB        = new Database("Publication Harvester Unit Test");
            Harvester harvester = new Harvester(DB);

            harvester.CreateTables();
            harvester.ImportPeople(AppDomain.CurrentDomain.BaseDirectory
                                   + "\\Unit Tests\\TestPeople\\input1.xls");
            DataTable Results = DB.ExecuteQuery(
                @"SELECT Setnb, First, Middle, Last, Name1, Name2, Name3, Name4, Name5, Name6,
                        MedlineSearch, Harvested, Error, ErrorMessage
                   FROM People"
                );

            // Test each person
            for (int Row = 0; Row < Results.Rows.Count; Row++)
            {
                Person person = new Person(Results.Rows[Row], Results.Columns);
                switch (person.Setnb)
                {
                case "A6009400":
                    Assert.IsTrue(person.First == "Jan");
                    Assert.IsTrue(person.Middle == "");
                    Assert.IsTrue(person.Last == "Van Eys");
                    Assert.IsTrue(person.Names.Length == 3);
                    Assert.IsTrue(person.Names[0] == "van eys j");
                    Assert.IsTrue(person.Names[1] == "vaneys j");
                    Assert.IsTrue(person.Names[2] == "eys jv");
                    Assert.IsTrue(person.MedlineSearch == "(\"van eys j\"[au] OR \"vaneys j\"[au] OR \"eys jv\"[au])");
                    break;

                case "A5401532":
                    Assert.IsTrue(person.First == "Louis");
                    Assert.IsTrue(person.Middle == "");
                    Assert.IsTrue(person.Last == "Tobian");
                    Assert.IsTrue(person.Names.Length == 3);
                    Assert.IsTrue(person.Names[0] == "tobian l");
                    Assert.IsTrue(person.Names[1] == "tobian l jr");
                    Assert.IsTrue(person.Names[2] == "tobian lj");
                    Assert.IsTrue(person.MedlineSearch == "(\"tobian l\"[au] OR \"tobian l jr\"[au] OR \"tobian lj\"[au])");
                    break;

                case "A5501586":
                    Assert.IsTrue(person.First == "Keith");
                    Assert.IsTrue(person.Middle == "B");
                    Assert.IsTrue(person.Last == "Reemtsma");
                    Assert.IsTrue(person.Names.Length == 6);
                    Assert.IsTrue(person.Names[0] == "reemtsma k");
                    Assert.IsTrue(person.Names[1] == "reemtsma kb");
                    Assert.IsTrue(person.Names[2] == "test data");
                    Assert.IsTrue(person.Names[3] == "more test data");
                    Assert.IsTrue(person.Names[4] == "test data name 5");
                    Assert.IsTrue(person.Names[5] == "test data name 6");
                    Assert.IsTrue(person.MedlineSearch == "((\"reemtsma k\"[au] OR \"reemtsma kb\"[au]) AND 1956:2000[dp])");
                    break;

                case "A5702471":
                    Assert.IsTrue(person.First == "Roger");
                    Assert.IsTrue(person.Middle == "");
                    Assert.IsTrue(person.Last == "Guillemin");
                    Assert.IsTrue(person.Names.Length == 2);
                    Assert.IsTrue(person.Names[0] == "guillemin r");
                    Assert.IsTrue(person.Names[1] == "guillemin rc");
                    Assert.IsTrue(person.MedlineSearch ==
                                  "(\"guillemin rc\"[au] OR (\"guillemin r\"[au] NOT (Electrodiagn Ther[ta] OR Phys Rev Lett[ta] OR vegas[ad] OR lindle[au])))"
                                  );
                    break;
                }
            }
        }