Exemple #1
0
        /// <summary>
        /// Processes the model configuration.
        /// </summary>
        /// <param name="uploadQueueItem">The upload queue item.</param>
        /// <param name="dicomFiles">The dicom files.</param>
        /// <param name="queueTransaction">The queue transaction.</param>
        /// <param name="clientConfiguration">The client configuration.</param>
        /// <returns>The waitable task.</returns>
        private async Task ProcessModelConfig(
            IEnumerable <DicomFile> dicomFiles,
            UploadQueueItem uploadQueueItem,
            IQueueTransaction queueTransaction,
            ClientAETConfig clientConfiguration)
        {
            var modelMatchResult = ApplyAETModelConfigProvider.ApplyAETModelConfig(clientConfiguration.Config.ModelsConfig, dicomFiles);

            if (modelMatchResult.Matched)
            {
                var model     = modelMatchResult.Result;
                var queueItem = await StartSegmentationAsync(model.ChannelData, uploadQueueItem, model.ModelId, model.TagReplacements.ToArray(), clientConfiguration).ConfigureAwait(false);

                EnqueueMessage(queueItem, _downloadQueuePath, queueTransaction);
            }
            else
            {
                var failedDicomTags = modelMatchResult.GetDicomConstraintsDicomTags();

                // Log all the tags that did not match
                LogError(LogEntry.Create(AssociationStatus.UploadErrorTagsDoNotMatch,
                                         uploadQueueItem: uploadQueueItem,
                                         failedDicomTags: string.Join(",", failedDicomTags.Select(x => x.DictionaryEntry.Name))),
                         new ProcessorServiceException("Failed to find a model for the received Dicom data."));
            }
        }
 /// <summary>
 /// Clone this into a new instance of the <see cref="AETConfigModel"/> class, optionally replacing some properties.
 /// </summary>
 /// <param name="calledAET">Optional new CalledAET.</param>
 /// <param name="callingAET">Optional new CallingAET.</param>
 /// <param name="aetConfig">Optional new AETConfig.</param>
 /// <returns>New AETConfigModel.</returns>
 public AETConfigModel With(
     string calledAET          = null,
     string callingAET         = null,
     ClientAETConfig aetConfig = null) =>
 new AETConfigModel(
     calledAET ?? CalledAET,
     callingAET ?? CallingAET,
     aetConfig ?? AETConfig);
 /// <summary>
 /// Initialize a new instance of the <see cref="AETConfigModel"/> class.
 /// </summary>
 /// <param name="calledAET">Called application entity title.</param>
 /// <param name="callingAET">Calling application entity title.</param>
 /// <param name="aetConfig">AET config.</param>
 public AETConfigModel(
     string calledAET,
     string callingAET,
     ClientAETConfig aetConfig)
 {
     CalledAET  = calledAET;
     CallingAET = callingAET;
     AETConfig  = aetConfig;
 }
Exemple #4
0
        /// <summary>
        /// Starts the segmentation task.
        /// </summary>
        /// <param name="channelData">The channel data.</param>
        /// <param name="uploadQueueItem">The upload queue item.</param>
        /// <param name="modelGuid">The model unique identifier.</param>
        /// <param name="tagReplacements">The tag replacements.</param>
        /// <param name="clientConfiguration">The client configuration.</param>
        /// <returns>The queue item.</returns>
        /// <exception cref="InvalidQueueDataException">If the result destination is not a valid AET.</exception>
        private async Task <DownloadQueueItem> StartSegmentationAsync
            (IEnumerable <ChannelData> channelData,
            UploadQueueItem uploadQueueItem,
            string modelGuid,
            TagReplacement[] tagReplacements,
            ClientAETConfig clientConfiguration)
        {
            if (clientConfiguration.Destination == null)
            {
                var exception = new ArgumentNullException("clientConfiguration.Destination",
                                                          "The result destination is null. The destination has not been configured.");

                LogError(LogEntry.Create(AssociationStatus.UploadErrorDestinationEmpty, uploadQueueItem: uploadQueueItem),
                         exception);

                throw exception;
            }

            // Validate the destination before uploading.
            ValidateDicomEndpoint(uploadQueueItem, clientConfiguration.Destination);

            LogInformation(LogEntry.Create(AssociationStatus.Uploading,
                                           uploadQueueItem: uploadQueueItem,
                                           modelId: modelGuid));

            var referenceDicomFiles = channelData.First().DicomFiles.ToArray();

            // Read all the bytes from the reference Dicom file and create new DICOM files with only the required DICOM tags
            var referenceDicomByteArrays = referenceDicomFiles
                                           .CreateNewDicomFileWithoutPixelData(
                _innerEyeSegmentationClient.SegmentationAnonymisationProtocol.Select(x => x.DicomTagIndex.DicomTag));

            // Start the segmentation
            var(segmentationId, postedImages) = await _innerEyeSegmentationClient.StartSegmentationAsync(modelGuid, channelData).ConfigureAwait(false);

            LogInformation(LogEntry.Create(AssociationStatus.Uploaded,
                                           uploadQueueItem: uploadQueueItem,
                                           segmentationId: segmentationId,
                                           modelId: modelGuid));

            var isDryRun         = clientConfiguration.Config.AETConfigType == AETConfigType.ModelWithResultDryRun;
            var resultsDirectory = GetResultsDirectory(
                uploadQueueItem.RootDicomFolderPath,
                isDryRun: isDryRun);

            // Copy any data needed to be sent with result to results directory if needed.
            if (clientConfiguration.ShouldReturnImage)
            {
                CopySendDataToResultsDirectory(resultsDirectory, channelData);
            }

            return(new DownloadQueueItem(
                       segmentationId: segmentationId,
                       modelId: modelGuid,
                       resultsDirectory: resultsDirectory,
                       referenceDicomFiles: referenceDicomByteArrays,
                       calledApplicationEntityTitle: uploadQueueItem.CalledApplicationEntityTitle,
                       callingApplicationEntityTitle: uploadQueueItem.CallingApplicationEntityTitle,
                       destinationApplicationEntity: new GatewayApplicationEntity(
                           clientConfiguration.Destination.Title,
                           clientConfiguration.Destination.Port,
                           clientConfiguration.Destination.Ip),
                       tagReplacementJsonString: JsonConvert.SerializeObject(tagReplacements),
                       associationGuid: uploadQueueItem.AssociationGuid,
                       associationDateTime: uploadQueueItem.AssociationDateTime,
                       isDryRun: isDryRun));
        }