-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added test for AutoRoutingAttacher #338
Open
jas88
wants to merge
3
commits into
develop
Choose a base branch
from
feature/auto-routing-attacher-test
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
using System; | ||
using DicomTypeTranslation.TableCreation; | ||
using FAnsi.Discovery; | ||
using NUnit.Framework; | ||
using Rdmp.Core.Curation; | ||
using Rdmp.Core.Curation.Data.Pipelines; | ||
using Rdmp.Core.DataFlowPipeline; | ||
using Rdmp.Core.DataLoad.Engine.DatabaseManagement.EntityNaming; | ||
using Rdmp.Core.DataLoad.Engine.Job; | ||
using Rdmp.Core.Logging; | ||
using Rdmp.Dicom.Attachers.Routing; | ||
using Rdmp.Dicom.CommandExecution; | ||
using Rdmp.Dicom.PipelineComponents.DicomSources; | ||
using Rdmp.Dicom.TagPromotionSchema; | ||
using Rdmp.Core.ReusableLibraryCode.Checks; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using Rdmp.Core.Curation.Data; | ||
using Tests.Common; | ||
|
||
namespace Rdmp.Dicom.Tests; | ||
|
||
class AutoRoutingAttacherTests : DatabaseTests | ||
{ | ||
[Test] | ||
public void TestNormalUse() | ||
{ | ||
var numberOfIterations = 50; | ||
|
||
var db = GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer); | ||
var attacher = new AutoRoutingAttacher(); | ||
|
||
|
||
// Create a nice template with lots of columns | ||
var template = new ImageTableTemplate | ||
{ | ||
TableName = "Fish", | ||
Columns = new[] | ||
{ | ||
new ImageColumnTemplate | ||
{ | ||
AllowNulls = true, ColumnName = "RelativeFileArchiveURI" | ||
}, | ||
new ImageColumnTemplate | ||
{ | ||
AllowNulls = true, ColumnName = "SeriesInstanceUID" | ||
}, | ||
new ImageColumnTemplate {IsPrimaryKey = false, AllowNulls = true, ColumnName = "StudyDate"}, | ||
} | ||
}; | ||
|
||
// create the table we want to load | ||
var tbl = db.ExpectTable(template.TableName); | ||
var cmd = new ExecuteCommandCreateNewImagingDataset(RepositoryLocator,tbl , template); | ||
Assert.IsFalse(cmd.IsImpossible); | ||
cmd.Execute(); | ||
|
||
var importer = new TableInfoImporter(CatalogueRepository,tbl); | ||
importer.DoImport(out var tableInfo,out var _); | ||
|
||
var tt = tbl.Database.Server.GetQuerySyntaxHelper().TypeTranslater; | ||
|
||
// add loads more tags | ||
foreach(var tag in Tags) | ||
{ | ||
var adder = new TagColumnAdder(tag,TagColumnAdder.GetDataTypeForTag(tag,tt),tableInfo as TableInfo ?? throw new Exception("Got non-TableInfo from DoImport"),new ThrowImmediatelyCheckNotifier()) | ||
{ | ||
SkipChecksAndSynchronization = true | ||
}; | ||
adder.Execute(); | ||
} | ||
|
||
new TableInfoSynchronizer(tableInfo).Synchronize(new AcceptAllCheckNotifier()); | ||
|
||
// create a mock job that treats our database as RAW | ||
var job = new ThrowImmediatelyDataLoadJob(new HICDatabaseConfiguration(tbl.Database.Server,RdmpMockFactory.Mock_INameDatabasesAndTablesDuringLoads(tbl.Database,tbl.GetRuntimeName()))); | ||
|
||
// Create folder where dicom files are | ||
var dir = new TestLoadDirectory | ||
{ | ||
Cache = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory,"Cache")), | ||
ForLoading = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory,"LoadMe")) | ||
}; | ||
|
||
dir.ForLoading.Create(); | ||
dir.Cache.Create(); | ||
|
||
//tell the job to look for files here | ||
job.LoadDirectory = dir; | ||
job.RegularTablesToLoad = new List<Core.Curation.Data.ITableInfo>{ tableInfo}; | ||
|
||
|
||
// create a dicom file | ||
var fileOrig = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory,"TestData/FileWithLotsOfTags.dcm")); | ||
var fileCopy = fileOrig.CopyTo(Path.Combine(dir.ForLoading.FullName,"test.dcm"),true); | ||
|
||
var sb = new StringBuilder(); | ||
|
||
//create a text file that says to load that file lots of times | ||
for(var i=0;i <numberOfIterations;i++) | ||
sb.AppendLine(fileCopy.FullName); | ||
|
||
File.WriteAllText(Path.Combine(dir.ForLoading.FullName,"loadme.txt"),sb.ToString()); | ||
|
||
attacher.ListPattern = "*.txt"; | ||
attacher.LoadPipeline = CreatePipeline(); | ||
attacher.Initialize(dir,tbl.Database); | ||
|
||
var lm = new LogManager(new DiscoveredServer(UnitTestLoggingConnectionString)); | ||
lm.CreateNewLoggingTaskIfNotExists("test loading"); | ||
var dli = lm.CreateDataLoadInfo("test loading","mee","doing stuff",null,true); | ||
job.DataLoadInfo = dli; | ||
|
||
attacher.Attach(job,new GracefulCancellationToken()); | ||
attacher.Dispose(job,null); | ||
|
||
Assert.AreEqual(numberOfIterations,tbl.GetRowCount()); | ||
} | ||
|
||
private Pipeline CreatePipeline() | ||
{ | ||
var pipe = new Pipeline(CatalogueRepository,"TestImagingPipeline"); | ||
|
||
var source = new PipelineComponent(CatalogueRepository,pipe,typeof(DicomFileCollectionSource),0); | ||
pipe.SourcePipelineComponent_ID = source.ID; | ||
|
||
|
||
return pipe; | ||
} | ||
|
||
readonly string[] Tags = new []{ | ||
"InstanceCreationDate", | ||
"InstanceCreationTime", | ||
"InstanceCreatorUID", | ||
"SOPClassUID", | ||
"SOPInstanceUID", | ||
"SeriesDate", | ||
"AcquisitionDate", | ||
"ContentDate", | ||
"StudyTime", | ||
"SeriesTime", | ||
"AcquisitionTime", | ||
"ContentTime", | ||
"AccessionNumber", | ||
"Modality", | ||
"ModalitiesInStudy", | ||
"ConversionType", | ||
"PresentationIntentType", | ||
"Manufacturer", | ||
"InstitutionName", | ||
"InstitutionAddress", | ||
"ReferringPhysicianName", | ||
"StationName", | ||
"StudyDescription", | ||
"ProcedureCodeSequence", | ||
"SeriesDescription", | ||
"InstitutionalDepartmentName", | ||
"PerformingPhysicianName", | ||
"NameOfPhysiciansReadingStudy", | ||
"OperatorsName", | ||
"AdmittingDiagnosesDescription", | ||
"ManufacturerModelName", | ||
"ReferencedPerformedProcedureStepSequence", | ||
"ReferencedImageSequence", | ||
"ReferencedSOPInstanceUID", | ||
"DerivationDescription", | ||
"SourceImageSequence", | ||
"StageName", | ||
"StageNumber", | ||
"NumberOfStages", | ||
"ViewNumber", | ||
"NumberOfViewsInStage", | ||
"AnatomicRegionSequence", | ||
"CodeValue", | ||
"CodingSchemeDesignator", | ||
"CodeMeaning", | ||
"PixelPresentation", | ||
"VolumetricProperties", | ||
"VolumeBasedCalculationTechnique", | ||
"PatientName", | ||
"PatientID", | ||
"PatientBirthDate", | ||
"PatientBirthTime", | ||
"PatientSex", | ||
"PatientBirthName", | ||
"PatientAge", | ||
"PatientSize", | ||
"PatientWeight", | ||
"MedicalAlerts", | ||
"EthnicGroup", | ||
"AdditionalPatientHistory", | ||
"PregnancyStatus", | ||
"PatientComments", | ||
"ClinicalTrialSponsorName", | ||
"ClinicalTrialProtocolID", | ||
"ClinicalTrialProtocolName", | ||
"ClinicalTrialSubjectReadingID", | ||
"ClinicalTrialTimePointID", | ||
"ClinicalTrialTimePointDescription", | ||
"PatientIdentityRemoved" }; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Missed opportunity to use Select