public void GivenATransactionContextWithUpdatedInstanceNumber_WhenprocessedForInstance_ThenDicomPropertyValuesAreUpdatedCorrectly()
        {
            DicomDataset dataset = FhirTransactionContextBuilder.CreateDicomDataset();

            ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(studyInstanceUid, new List <string>()
            {
                seriesInstanceUid
            }, new List <string>()
            {
                sopInstanceUid
            }, patientResourceId);
            FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(dataset);

            ImagingStudy.SeriesComponent   series   = imagingStudy.Series.First();
            ImagingStudy.InstanceComponent instance = series.Instance.First();

            _imagingStudyInstancePropertySynchronizer.Synchronize(context, instance);

            Assert.Equal(1, instance.Number);

            FhirTransactionContext newContext = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset(instanceNumber: "2"));

            _imagingStudyInstancePropertySynchronizer.Synchronize(newContext, instance);
            Assert.Equal(2, instance.Number);
        }
        public async Task GivenATransactionContextWithNoDicomPropertyValueChange_WhenprocessedForInstancee_ThenDicomPropertyValuesUpdateIsSkippedAsync()
        {
            DicomDataset dataset = FhirTransactionContextBuilder.CreateDicomDataset();

            ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(StudyInstanceUid, new List <string>()
            {
                SeriesInstanceUid
            }, new List <string>()
            {
                SopInstanceUid
            }, PatientResourceId);
            FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(dataset);

            ImagingStudy.SeriesComponent   series   = imagingStudy.Series.First();
            ImagingStudy.InstanceComponent instance = series.Instance.First();

            await _imagingStudyInstancePropertySynchronizer.SynchronizeAsync(context, instance, DefaultCancellationToken);

            Assert.Equal(1, instance.Number);

            FhirTransactionContext newContext = FhirTransactionContextBuilder.DefaultFhirTransactionContext(dataset);

            await _imagingStudyInstancePropertySynchronizer.SynchronizeAsync(newContext, instance, DefaultCancellationToken);

            Assert.Equal(1, instance.Number);
        }
        /// <inheritdoc/>
        public void Synchronize(FhirTransactionContext context, ImagingStudy.SeriesComponent series)
        {
            EnsureArg.IsNotNull(context, nameof(context));
            EnsureArg.IsNotNull(context.ChangeFeedEntry, nameof(context.ChangeFeedEntry));
            EnsureArg.IsNotNull(series, nameof(series));

            DicomDataset dataset = context.ChangeFeedEntry.Metadata;

            if (dataset == null)
            {
                return;
            }

            // Add series number
            AddSeriesNumber(series, dataset);

            // Add description to series
            AddDescription(series, dataset);

            // Add modality to series
            AddModalityToSeries(series, dataset);

            // Add startedElement to series
            AddStartedElement(series, dataset, context.UtcDateTimeOffset);
        }
 private void AddDescription(ImagingStudy.SeriesComponent series, DicomDataset dataset)
 {
     if (dataset.TryGetSingleValue(DicomTag.SeriesDescription, out string description))
     {
         series.Description = description;
     }
 }
Exemplo n.º 5
0
        public void SynchronizeSeriesProperties(FhirTransactionContext context, ImagingStudy.SeriesComponent series)
        {
            EnsureArg.IsNotNull(context, nameof(context));
            EnsureArg.IsNotNull(series, nameof(series));

            _imagingStudySeriesPropertySynchronizer.Synchronize(context, series);
        }
        public async Task GivenATransactionContexAndImagingStudy_WhenprocessedForInstance_ThenDicomPropertiesAreCorrectlyMappedtoInstanceWithinImagingStudyAsync()
        {
            DicomDataset dataset = FhirTransactionContextBuilder.CreateDicomDataset();

            ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(StudyInstanceUid, new List <string>()
            {
                SeriesInstanceUid
            }, new List <string>()
            {
                SopInstanceUid
            }, PatientResourceId);
            FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(dataset);

            if (imagingStudy.Series.Count() > 0)
            {
                System.Console.WriteLine("");
            }
            ImagingStudy.SeriesComponent   series   = imagingStudy.Series.First();
            ImagingStudy.InstanceComponent instance = series.Instance.First();

            await _imagingStudyInstancePropertySynchronizer.SynchronizeAsync(context, instance, DefaultCancellationToken);

            Assert.Equal(SopClassUid, instance.SopClass.Code);
            Assert.Equal(1, instance.Number);
        }
 private void AddSeriesNumber(ImagingStudy.SeriesComponent series, DicomDataset dataset)
 {
     if (dataset.TryGetSingleValue(DicomTag.SeriesNumber, out int seriesNumber))
     {
         series.Number = seriesNumber;
     }
 }
Exemplo n.º 8
0
        public static void ValidateSeries(ImagingStudy.SeriesComponent series, string seriesInstanceUid, params string[] sopInstanceUidList)
        {
            Assert.Equal(seriesInstanceUid, series.Uid);

            for (int i = 0; i < series.Instance.Count; i++)
            {
                Assert.Equal(sopInstanceUidList[i], series.Instance[i].Uid);
            }
        }
        // Add modality to series
        private void AddModalityToSeries(ImagingStudy.SeriesComponent series, DicomDataset dataset)
        {
            string modalityInString = ImagingStudyPipelineHelper.GetModalityInString(dataset);

            if (modalityInString != null && !string.Equals(series.Modality?.Code, modalityInString, StringComparison.Ordinal))
            {
                series.Modality = ImagingStudyPipelineHelper.GetModality(modalityInString);
            }
        }
        /// <inheritdoc/>
        public async Task <FhirTransactionRequestEntry> BuildAsync(FhirTransactionContext context, CancellationToken cancellationToken)
        {
            EnsureArg.IsNotNull(context, nameof(context));
            EnsureArg.IsNotNull(context.ChangeFeedEntry, nameof(context.ChangeFeedEntry));

            ChangeFeedEntry changeFeedEntry = context.ChangeFeedEntry;

            Identifier   imagingStudyIdentifier = ImagingStudyIdentifierUtility.CreateIdentifier(changeFeedEntry.StudyInstanceUid);
            ImagingStudy imagingStudy           = await _fhirService.RetrieveImagingStudyAsync(imagingStudyIdentifier, cancellationToken);

            // Returns null if imagingStudy does not exists for given studyInstanceUid
            if (imagingStudy == null)
            {
                return(null);
            }

            string imagingStudySource = imagingStudy.Meta.Source;

            ImagingStudy.SeriesComponent   series   = ImagingStudyPipelineHelper.GetSeriesWithinAStudy(changeFeedEntry.SeriesInstanceUid, imagingStudy.Series);
            ImagingStudy.InstanceComponent instance = ImagingStudyPipelineHelper.GetInstanceWithinASeries(changeFeedEntry.SopInstanceUid, series);

            // Return null if the given instance is not present in ImagingStudy
            if (instance == null)
            {
                return(null);
            }

            // Removes instance from series collection
            series.Instance.Remove(instance);

            // Removes series from ImagingStudy if its instance collection is empty
            if (series.Instance.Count == 0)
            {
                imagingStudy.Series.Remove(series);
            }

            if (imagingStudy.Series.Count == 0 && _dicomWebEndpoint.Equals(imagingStudySource, System.StringComparison.Ordinal))
            {
                return(new FhirTransactionRequestEntry(
                           FhirTransactionRequestMode.Delete,
                           ImagingStudyPipelineHelper.GenerateDeleteRequest(imagingStudy),
                           imagingStudy.ToServerResourceId(),
                           imagingStudy));
            }

            return(new FhirTransactionRequestEntry(
                       FhirTransactionRequestMode.Update,
                       ImagingStudyPipelineHelper.GenerateUpdateRequest(imagingStudy),
                       imagingStudy.ToServerResourceId(),
                       imagingStudy));
        }
Exemplo n.º 11
0
        private async Task AddSeriesToImagingStudyAsync(FhirTransactionContext context, ImagingStudy imagingStudy, CancellationToken cancellationToken)
        {
            ChangeFeedEntry changeFeedEntry = context.ChangeFeedEntry;

            List <ImagingStudy.SeriesComponent> existingSeriesCollection = imagingStudy.Series;

            ImagingStudy.InstanceComponent instance = new ImagingStudy.InstanceComponent()
            {
                Uid = changeFeedEntry.SopInstanceUid,
            };

            // Checks if the given series already exists within a study
            ImagingStudy.SeriesComponent series = ImagingStudyPipelineHelper.GetSeriesWithinAStudy(changeFeedEntry.SeriesInstanceUid, existingSeriesCollection);

            if (series == null)
            {
                series = new ImagingStudy.SeriesComponent()
                {
                    Uid = changeFeedEntry.SeriesInstanceUid,
                };

                series.Instance.Add(instance);
                imagingStudy.Series.Add(series);
            }
            else
            {
                ImagingStudy.InstanceComponent existingInstance = ImagingStudyPipelineHelper.GetInstanceWithinASeries(changeFeedEntry.SopInstanceUid, series);

                if (existingInstance == null)
                {
                    series.Instance.Add(instance);
                }
                else
                {
                    instance = existingInstance;
                }
            }

            await _imagingStudySynchronizer.SynchronizeSeriesPropertiesAsync(context, series, cancellationToken);

            await _imagingStudySynchronizer.SynchronizeInstancePropertiesAsync(context, instance, cancellationToken);
        }
        public async Task GivenATransactionContexAndImagingStudy_WhenprocessedForSeries_ThenDicomPropertiesAreCorrectlyMappedtoSeriesWithinImagingStudyAsync()
        {
            ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(StudyInstanceUid, new List <string>()
            {
                SeriesInstanceUid
            }, new List <string>()
            {
                SopInstanceUid
            }, PatientResourceId);
            FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset());

            ImagingStudy.SeriesComponent series = imagingStudy.Series.First();

            await _imagingStudySeriesPropertySynchronizer.SynchronizeAsync(context, series, DefaultCancellationToken);

            Assert.Equal("Series Description", series.Description);
            Assert.Equal("MODALITY", series.Modality.Code);
            Assert.Equal(1, series.Number);
            Assert.Equal(new FhirDateTime(1974, 8, 10, 8, 10, 24, TimeSpan.Zero), series.StartedElement);
        }
        public void GivenATransactionContexAndImagingStudy_WhenprocessedForInstance_ThenDicomPropertiesAreCorrectlyMappedtoInstanceWithinImagingStudy()
        {
            DicomDataset dataset = FhirTransactionContextBuilder.CreateDicomDataset();

            ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(studyInstanceUid, new List <string>()
            {
                seriesInstanceUid
            }, new List <string>()
            {
                sopInstanceUid
            }, patientResourceId);
            FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(dataset);

            ImagingStudy.SeriesComponent   series   = imagingStudy.Series.First();
            ImagingStudy.InstanceComponent instance = series.Instance.First();

            _imagingStudyInstancePropertySynchronizer.Synchronize(context, instance);

            Assert.Equal(sopClassUid, instance.SopClass.Code);
            Assert.Equal(1, instance.Number);
        }
Exemplo n.º 14
0
        public void GivenATransactionContextWithNoPropertyValueChange_WhenprocessedForSeries_ThenDicomPropertyValuesUpdateIsSkipped()
        {
            ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(studyInstanceUid, new List <string>()
            {
                seriesInstanceUid
            }, new List <string>()
            {
                sopInstanceUid
            }, patientResourceId);
            FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext();

            ImagingStudy.SeriesComponent series = imagingStudy.Series.First();

            _imagingStudySeriesPropertySynchronizer.Synchronize(context, series);

            Assert.Equal(1, series.Number);

            FhirTransactionContext newContext = FhirTransactionContextBuilder.DefaultFhirTransactionContext();

            _imagingStudySeriesPropertySynchronizer.Synchronize(newContext, series);
            Assert.Equal(1, series.Number);
        }
Exemplo n.º 15
0
        public static ImagingStudy CreateNewImagingStudy(string studyInstanceUid, List <string> seriesInstanceUidList, List <string> sopInstanceUidList, string patientResourceId, string source = "defaultSouce")
        {
            // Create a new ImagingStudy
            ImagingStudy study = new ImagingStudy
            {
                Id      = "123",
                Status  = ImagingStudy.ImagingStudyStatus.Available,
                Subject = new ResourceReference(patientResourceId),
                Meta    = new Meta()
                {
                    VersionId = "1",
                    Source    = source,
                },
            };

            foreach (string seriesInstanceUid in seriesInstanceUidList)
            {
                ImagingStudy.SeriesComponent series = new ImagingStudy.SeriesComponent()
                {
                    Uid = seriesInstanceUid,
                };

                foreach (string sopInstanceUid in sopInstanceUidList)
                {
                    ImagingStudy.InstanceComponent instance = new ImagingStudy.InstanceComponent()
                    {
                        Uid = sopInstanceUid,
                    };

                    series.Instance.Add(instance);
                }

                study.Series.Add(series);
            }

            study.Identifier.Add(ImagingStudyIdentifierUtility.CreateIdentifier(studyInstanceUid));

            return(study);
        }
Exemplo n.º 16
0
        public void GivenATransactionContextWithUpdatedSeriesModality_WhenprocessedForSeries_ThenDicomPropertyValuesAreUpdatedAreCorrectly()
        {
            ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(studyInstanceUid, new List <string>()
            {
                seriesInstanceUid
            }, new List <string>()
            {
                sopInstanceUid
            }, patientResourceId);
            FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset());

            ImagingStudy.SeriesComponent series = imagingStudy.Series.First();

            _imagingStudySeriesPropertySynchronizer.Synchronize(context, series);

            Assert.Equal("MODALITY", series.Modality.Code);

            FhirTransactionContext newContext = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset(modalityInSeries: "NEWMODALITY"));

            _imagingStudySeriesPropertySynchronizer.Synchronize(newContext, series);
            Assert.Equal("NEWMODALITY", series.Modality.Code);
        }
        public async Task GivenATransactionContextWithUpdatedSeriesDescription_WhenprocessedForSeries_ThenDicomPropertyValuesAreUpdatedAreCorrectlyAsync()
        {
            ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(StudyInstanceUid, new List <string>()
            {
                SeriesInstanceUid
            }, new List <string>()
            {
                SopInstanceUid
            }, PatientResourceId);
            FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset());

            ImagingStudy.SeriesComponent series = imagingStudy.Series.First();

            await _imagingStudySeriesPropertySynchronizer.SynchronizeAsync(context, series, DefaultCancellationToken);

            Assert.Equal("Series Description", series.Description);

            FhirTransactionContext newContext = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset(seriesDescrition: "New Series Description"));

            await _imagingStudySeriesPropertySynchronizer.SynchronizeAsync(newContext, series, DefaultCancellationToken);

            Assert.Equal("New Series Description", series.Description);
        }
        private void ValidateDicomFilePropertiesAreCorrectlyMapped(ImagingStudy imagingStudy, ImagingStudy.SeriesComponent series, ImagingStudy.InstanceComponent instance)
        {
            Assert.Collection(
                imagingStudy.Endpoint,
                reference => string.Equals(reference.Reference, _fhirTransactionContext.Request.Endpoint.ToString(), StringComparison.Ordinal));

            // Assert imaging study properties are mapped correctly
            Assert.Collection(
                imagingStudy.Modality,
                modality => string.Equals(modality.Code, "MODALITY", StringComparison.Ordinal));

            Assert.Collection(
                imagingStudy.Note,
                note => string.Equals(note.Text.ToString(), "Study Description", StringComparison.Ordinal));

            Assert.Equal(new FhirDateTime(1974, 7, 10, 7, 10, 24, TimeSpan.Zero), imagingStudy.StartedElement);

            // Assert series properties are mapped correctly
            Assert.Equal("Series Description", series.Description);
            Assert.Equal("MODALITY", series.Modality.Code);
            Assert.Equal(1, series.Number);
            Assert.Equal(new FhirDateTime(1974, 8, 10, 8, 10, 24, TimeSpan.Zero), series.StartedElement);

            // Assert instance properties are mapped correctly
            Assert.Equal("4444", instance.SopClass.Code);
            Assert.Equal(1, instance.Number);
        }
        public static ImagingStudy.InstanceComponent GetInstanceWithinASeries(string sopInstanceUid, ImagingStudy.SeriesComponent existingSeries)
        {
            if (existingSeries == null)
            {
                return(null);
            }

            return(existingSeries.Instance.FirstOrDefault(instance => sopInstanceUid.Equals(instance.Uid, EqualsStringComparison)));
        }
Exemplo n.º 20
0
        public async Task SynchronizeSeriesPropertiesAsync(FhirTransactionContext context, ImagingStudy.SeriesComponent series, CancellationToken cancellationToken)
        {
            EnsureArg.IsNotNull(context, nameof(context));
            EnsureArg.IsNotNull(series, nameof(series));

            await _imagingStudySeriesPropertySynchronizer.SynchronizeAsync(context, series, cancellationToken);
        }
 // Add startedElement to series
 private void AddStartedElement(ImagingStudy.SeriesComponent series, DicomDataset dataset, TimeSpan utcOffset)
 {
     series.StartedElement = dataset.GetDateTimePropertyIfNotDefaultValue(DicomTag.SeriesDate, DicomTag.SeriesTime, utcOffset);
 }