/// <summary> /// Anonymises every DICOM file in the specified folder path and saves locally to the /// correct dry run folder. /// </summary> /// <param name="anonymisationProtocolId">The anonymisation protocol unique identifier.</param> /// <param name="anonymisationProtocol">The anonymisation protocol.</param> /// <param name="uploadQueueItem">The upload queue item.</param> /// <param name="aETConfigType">Type of application entity title configuration.</param> /// <returns>The async task.</returns> private async Task AnonymiseAndSaveDicomFilesAsync( Guid anonymisationProtocolId, IEnumerable <DicomTagAnonymisation> anonymisationProtocol, UploadQueueItem uploadQueueItem, AETConfigType aETConfigType) { var dryRunFolder = DryRunFolders.GetFolder(aETConfigType); var resultFolderPath = Path.Combine(uploadQueueItem.RootDicomFolderPath, dryRunFolder, uploadQueueItem.AssociationGuid.ToString()); foreach (var filePath in EnumerateFiles(uploadQueueItem.AssociationFolderPath, uploadQueueItem)) { var dicomFile = TryOpenDicomFile(filePath, uploadQueueItem); // Not a DICOM file or is not a structure set file. if (dicomFile == null) { EnqueueMessage(new DeleteQueueItem(uploadQueueItem, filePath), _deleteQueuePath); continue; } var anonymizedDicomFile = _innerEyeSegmentationClient.AnonymizeDicomFile( dicomFile: dicomFile, anonymisationProtocolId: anonymisationProtocolId, anonymisationProtocol: anonymisationProtocol); await SaveDicomFilesAsync(resultFolderPath, anonymizedDicomFile).ConfigureAwait(false); // This item has been saved, we can now delete this file EnqueueMessage(new DeleteQueueItem(uploadQueueItem, filePath), _deleteQueuePath); } }
/// <inheritdoc/> public override int GetHashCode() { var hashCode = 602733048; hashCode = hashCode * -1521134295 + AETConfigType.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <IReadOnlyList <ModelConstraintsConfig> > .Default.GetHashCode(ModelsConfig); return(hashCode); }
/// <summary> /// Converts the config type to a dry run folder. /// </summary> /// <param name="configType">Type of the configuration.</param> /// <returns>The dry run folder.</returns> /// <exception cref="ArgumentException">If the config type is not a dry run type.</exception> public static string GetFolder(AETConfigType configType) { switch (configType) { case AETConfigType.ModelDryRun: return(DryRunAnonymisedImageFolder); case AETConfigType.ModelWithResultDryRun: return(DryRunModelWithResultFolder); default: throw new ArgumentException("Unknown configuration type", nameof(configType)); } }
/// <summary> /// Initializes a new instance of the <see cref="AETConfig"/> class. /// </summary> /// <param name="aetConfigType">Type of application entity configuration.</param> /// <param name="modelsConfig">The models configuration required if it is not feedback</param> /// <exception cref="ArgumentNullException"> /// Model configuration null /// </exception> /// <exception cref="ArgumentException"> /// calledAET /// or /// modelConfig /// </exception> public AETConfig( AETConfigType aetConfigType, IReadOnlyList <ModelConstraintsConfig> modelsConfig) { AETConfigType = aetConfigType; if (NeedsModelConfig(aetConfigType)) { ModelsConfig = modelsConfig ?? throw new ArgumentNullException(nameof(modelsConfig)); if (!ModelsConfig.Any()) { throw new ArgumentException("You must specify at least 1 ModelConstraintConfig", nameof(modelsConfig)); } } // If this is not a model AET config type the models config should be null if (!NeedsModelConfig(aetConfigType) && modelsConfig != null) { throw new ArgumentException("This config type does not require a ModelConstraintsConfig", nameof(modelsConfig)); } }
/// <summary> /// Configuration needs a destination endpoint /// </summary> public static bool NeedsEndpoint(AETConfigType aetConfigType) => aetConfigType == AETConfigType.Model;
/// <summary> /// Needs a model configuration /// </summary> public static bool NeedsModelConfig(AETConfigType aetConfigType) => aetConfigType == AETConfigType.Model || aetConfigType == AETConfigType.ModelWithResultDryRun;