public void FromCataloguesExtractionRequestFulfiller_NormalMatching_SeriesInstanceUIDOnly(DatabaseType databaseType) { var db = GetCleanedServer(databaseType); var dt = new DataTable(); dt.Columns.Add("SeriesInstanceUID"); dt.Columns.Add("Extractable", typeof(bool)); dt.Columns.Add(QueryToExecuteColumnSet.DefaultImagePathColumnName); dt.Rows.Add("123", true, "/images/1.dcm"); dt.Rows.Add("123", false, "/images/2.dcm"); dt.Rows.Add("1234", false, "/images/3.dcm"); dt.Rows.Add("1234", true, "/images/4.dcm"); dt.SetDoNotReType(true); var tbl = db.CreateTable("FromCataloguesExtractionRequestFulfillerTests", dt); var catalogue = Import(tbl); var fulfiller = new FromCataloguesExtractionRequestFulfiller(new[] { catalogue }); var matching = fulfiller.GetAllMatchingFiles(new ExtractionRequestMessage() { KeyTag = "SeriesInstanceUID", ExtractionIdentifiers = new List <string>(new string[] { "123" }), }, new NullAuditExtractions()).ToArray(); Assert.AreEqual(1, matching.Length); Assert.AreEqual(2, matching[0].Accepted.Count()); Assert.AreEqual(1, matching[0].Accepted.Count(f => f.FilePathValue.Equals("/images/1.dcm"))); Assert.AreEqual(1, matching[0].Accepted.Count(f => f.FilePathValue.Equals("/images/2.dcm"))); }
public void Test_FromCataloguesExtractionRequestFulfiller_NoFilterExtraction(DatabaseType databaseType, bool isNoFiltersExtraction) { DiscoveredDatabase db = GetCleanedServer(databaseType); var dt = new DataTable(); dt.Columns.Add("StudyInstanceUID"); dt.Columns.Add("SeriesInstanceUID"); dt.Columns.Add("SOPInstanceUID"); dt.Columns.Add("Extractable", typeof(bool)); dt.Columns.Add(QueryToExecuteColumnSet.DefaultImagePathColumnName); dt.Rows.Add("1.1", "123.1", "1.1", true, "/images/1.dcm"); dt.SetDoNotReType(true); DiscoveredTable tbl = db.CreateTable("FromCataloguesExtractionRequestFulfillerTests", dt); ICatalogue catalogue = Import(tbl); ExtractionInformation ei = catalogue.GetAllExtractionInformation(ExtractionCategory.Any).First(); var filter = new ExtractionFilter(CatalogueRepository, "Extractable only", ei) { IsMandatory = true, WhereSQL = "Extractable = 1" }; filter.SaveToDatabase(); var fulfiller = new FromCataloguesExtractionRequestFulfiller(new[] { catalogue }); fulfiller.Rejectors.Add(new RejectAll()); var message = new ExtractionRequestMessage { KeyTag = "SeriesInstanceUID", ExtractionIdentifiers = new List <string>(new [] { "123.1" }), IsNoFilterExtraction = isNoFiltersExtraction, }; ExtractImageCollection[] matching = fulfiller.GetAllMatchingFiles(message, new NullAuditExtractions()).ToArray(); int expected = isNoFiltersExtraction ? 1 : 0; Assert.AreEqual(1, matching.Length); Assert.AreEqual(expected, matching[0].Accepted.Count); }
public void FromCataloguesExtractionRequestFulfiller_MandatoryFilter(DatabaseType databaseType) { var db = GetCleanedServer(databaseType); var dt = new DataTable(); dt.Columns.Add("StudyInstanceUID"); dt.Columns.Add("SeriesInstanceUID"); dt.Columns.Add("SOPInstanceUID"); dt.Columns.Add("Extractable", typeof(bool)); dt.Columns.Add(QueryToExecuteColumnSet.DefaultImagePathColumnName); dt.Rows.Add("1.1", "123.1", "1.1", true, "/images/1.dcm"); dt.Rows.Add("1.1", "123.1", "2.1", false, "/images/2.dcm"); dt.Rows.Add("1.1", "1234.1", "3.1", false, "/images/3.dcm"); dt.Rows.Add("1.1", "1234.1", "4.1", true, "/images/4.dcm"); dt.SetDoNotReType(true); var tbl = db.CreateTable("FromCataloguesExtractionRequestFulfillerTests", dt); var catalogue = Import(tbl); var ei = catalogue.GetAllExtractionInformation(ExtractionCategory.Any).First(); var filter = new ExtractionFilter(CatalogueRepository, "Extractable only", ei); filter.IsMandatory = true; filter.WhereSQL = "Extractable = 1"; filter.SaveToDatabase(); var fulfiller = new FromCataloguesExtractionRequestFulfiller(new[] { catalogue }); var matching = fulfiller.GetAllMatchingFiles(new ExtractionRequestMessage() { KeyTag = "SeriesInstanceUID", ExtractionIdentifiers = new List <string>(new string[] { "123.1" }), }, new NullAuditExtractions()).ToArray(); Assert.AreEqual(1, matching.Length); Assert.AreEqual(1, matching[0].Accepted.Count); Assert.AreEqual(1, matching[0].Accepted.Count(f => f.FilePathValue.Equals("/images/1.dcm"))); }
public void Test_OnlyExtractableImages(DatabaseType dbType, bool useDynamic) { var db = GetCleanedServer(dbType); //create table with 300 rows to ensure at least two studies const int testrows = 300; var tbl = BuildExampleExtractionTable(db, "CT", testrows, true); Assert.AreEqual(testrows, tbl.GetRowCount()); var cata = Import(tbl); List <string> studies; //fetch all unique studies from the database using (var dt = tbl.GetDataTable()) studies = dt.Rows.Cast <DataRow>().Select(r => r["StudyInstanceUID"]).Cast <string>().Distinct().ToList(); Assert.GreaterOrEqual(studies.Count, 2, "Expected at least 2 studies to be randomly generated in database"); //Create message to extract all the studies by StudyInstanceUID var msgIn = new ExtractionRequestMessage(); msgIn.KeyTag = DicomTag.StudyInstanceUID.DictionaryEntry.Keyword; msgIn.ExtractionIdentifiers = studies; int matches = 0; //The strategy pattern implementation that goes to the database but also considers reason var fulfiller = new FromCataloguesExtractionRequestFulfiller(new[] { cata }); fulfiller.Rejectors.Add(useDynamic? (IRejector) new DynamicRejector():new TestRejector()); foreach (ExtractImageCollection msgOut in fulfiller.GetAllMatchingFiles(msgIn, new NullAuditExtractions())) { matches += msgOut.Accepted.Count(); Assert.IsEmpty(msgOut.Rejected); } //currently all images are extractable Assert.AreEqual(testrows, matches); //now make 10 not extractable using (var con = tbl.Database.Server.GetConnection()) { con.Open(); string sql = GetUpdateTopXSql(tbl, 10, "Set IsExtractableToDisk=0, IsExtractableToDisk_Reason = 'We decided NO!'"); //make the top 10 not extractable using (var cmd = tbl.Database.Server.GetCommand(sql, con)) { cmd.ExecuteNonQuery(); } } matches = 0; int rejections = 0; foreach (ExtractImageCollection msgOut in fulfiller.GetAllMatchingFiles(msgIn, new NullAuditExtractions())) { matches += msgOut.Accepted.Count; rejections += msgOut.Rejected.Count; Assert.IsTrue(msgOut.Rejected.All(v => v.RejectReason.Equals("We decided NO!"))); } Assert.AreEqual(testrows - 10, matches); Assert.AreEqual(10, rejections); }
public void Test_OnlyListedModalities(DatabaseType dbType) { var db = GetCleanedServer(dbType); //create table with 100 rows var tblCT = BuildExampleExtractionTable(db, "CT", 70, true); var tblMR = BuildExampleExtractionTable(db, "MR", 30, true); var cataCT = Import(tblCT); var cataMR = Import(tblMR); List <string> studies = new List <string>(); //fetch all unique studies from the database using (var dt = tblCT.GetDataTable()) studies.AddRange(dt.Rows.Cast <DataRow>().Select(r => r["StudyInstanceUID"]).Cast <string>().Distinct()); using (var dt = tblMR.GetDataTable()) studies.AddRange(dt.Rows.Cast <DataRow>().Select(r => r["StudyInstanceUID"]).Cast <string>().Distinct()); //Create message to extract all the series by StudyInstanceUID var msgIn = new ExtractionRequestMessage(); msgIn.KeyTag = DicomTag.StudyInstanceUID.DictionaryEntry.Keyword; //extract only MR (this is what we are actually testing). msgIn.Modality = "MR"; msgIn.ExtractionIdentifiers = studies; int matches = 0; //The strategy pattern implementation that goes to the database but also considers reason var fulfiller = new FromCataloguesExtractionRequestFulfiller(new[] { cataCT, cataMR }) { //Give it the default modality pattern (table prefix) ModalityRoutingRegex = new Regex(new CohortExtractorOptions().ModalityRoutingRegex) }; foreach (ExtractImageCollection msgOut in fulfiller.GetAllMatchingFiles(msgIn, new NullAuditExtractions())) { matches += msgOut.Accepted.Count(); Assert.IsEmpty(msgOut.Rejected); } //expect only the MR images to be returned Assert.AreEqual(30, matches); // Ask for something that doesn't exist msgIn.Modality = "Hello"; var ex = Assert.Throws <Exception>(() => fulfiller.GetAllMatchingFiles(msgIn, new NullAuditExtractions()).ToArray()); StringAssert.Contains("Modality=Hello", ex.Message); // Ask for all modalities at once by not specifying any msgIn.Modality = null; Assert.AreEqual(100, fulfiller.GetAllMatchingFiles(msgIn, new NullAuditExtractions()).Sum(r => r.Accepted.Count)); // Ask for both modalities specifically msgIn.Modality = "CT,Hello"; Assert.AreEqual(70, fulfiller.GetAllMatchingFiles(msgIn, new NullAuditExtractions()).Sum(r => r.Accepted.Count)); // Ask for both modalities specifically msgIn.Modality = "CT,MR"; Assert.AreEqual(100, fulfiller.GetAllMatchingFiles(msgIn, new NullAuditExtractions()).Sum(r => r.Accepted.Count)); //when we don't have that flag anymore the error should tell us that tblCT.DropColumn(tblCT.DiscoverColumn("IsOriginal")); msgIn.Modality = "CT,MR"; ex = Assert.Throws(Is.AssignableTo(typeof(Exception)), () => fulfiller.GetAllMatchingFiles(msgIn, new NullAuditExtractions()).ToArray()); StringAssert.Contains("IsOriginal", ex.Message); }