Example #1
0
        public void GivenATransactionContexAndImagingStudy_WhenProcessedForStudy_ThenDicomPropertiesAreCorrectlyMappedtoImagingStudy()
        {
            ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(DefaultStudyInstanceUid, new List <string>()
            {
                DefaultSeriesInstanceUid
            }, new List <string>()
            {
                DefaultSopInstanceUid
            }, DefaultPatientResourceId);
            FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset());

            _imagingStudyPropertySynchronizer.Synchronize(context, imagingStudy);

            Assert.Collection(
                imagingStudy.Endpoint,
                reference => string.Equals(reference.Reference, context.Request.Endpoint.Resource.ToString(), StringComparison.Ordinal));

            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);
        }
Example #2
0
        public void GivenATransactionContextAndImagingStudyWithNewEndpointReference_WhenProcessedForStudyWithEndpoint_ThenEndpointIsAdded()
        {
            ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(DefaultStudyInstanceUid, new List <string>()
            {
                DefaultSeriesInstanceUid
            }, new List <string>()
            {
                DefaultSopInstanceUid
            }, DefaultPatientResourceId);

            // Simulate the imaging study with an existing endpoint.
            Endpoint existingEndpoint           = FhirResourceBuilder.CreateEndpointResource(id: "2345", name: "new wado-rs");
            var      existingEndpointResourceId = new ServerResourceId(ResourceType.Endpoint, existingEndpoint.Id);
            var      existingEndpointReference  = existingEndpointResourceId.ToResourceReference();

            imagingStudy.Endpoint.Add(existingEndpointReference);

            Endpoint endpoint           = FhirResourceBuilder.CreateEndpointResource();
            var      endpointResourceId = new ServerResourceId(ResourceType.Endpoint, endpoint.Id);
            var      endpointReference  = endpointResourceId.ToResourceReference();

            FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset());

            context.Request.Endpoint = FhirTransactionRequestEntryGenerator.GenerateDefaultNoChangeRequestEntry <Endpoint>(endpointResourceId);

            _imagingStudyPropertySynchronizer.Synchronize(context, imagingStudy);

            Assert.Collection(
                imagingStudy.Endpoint,
                endPoint => Assert.Equal(existingEndpointReference, endPoint),
                endPoint => Assert.Equal(endpointReference, endPoint));
        }
Example #3
0
        public void GivenATransactionContexAndImagingStudyWithNewStudyDescription_WhenProcessedForStudy_ThenNewNoteIsAdded()
        {
            ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(DefaultStudyInstanceUid, new List <string>()
            {
                DefaultSeriesInstanceUid
            }, new List <string>()
            {
                DefaultSopInstanceUid
            }, DefaultPatientResourceId);
            FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset());

            _imagingStudyPropertySynchronizer.Synchronize(context, imagingStudy);

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

            // When studyDescription is same, note is not added twice

            _imagingStudyPropertySynchronizer.Synchronize(context, imagingStudy);

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

            // When study description is new, new note is added
            FhirTransactionContext newConText = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset(studyDescription: "New Study Description"));

            _imagingStudyPropertySynchronizer.Synchronize(newConText, imagingStudy);

            Assert.Collection(
                imagingStudy.Note,
                note => string.Equals(note.Text.ToString(), "Study Description", StringComparison.Ordinal),
                note => string.Equals(note.Text.ToString(), "New Study Description", StringComparison.Ordinal));
        }
        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);
        }
        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);
        }
        public void GivenATransactionContextAndImagingStudyWithExitsingAccessionNumber_WhenProcessedForStudy_ThenAccessionNumberIsNotAdded()
        {
            ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(DefaultStudyInstanceUid, new List <string>()
            {
                DefaultSeriesInstanceUid
            }, new List <string>()
            {
                DefaultSopInstanceUid
            }, DefaultPatientResourceId);
            FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset());

            _imagingStudyPropertySynchronizer.Synchronize(context, imagingStudy);

            Assert.Collection(
                imagingStudy.Identifier,
                identifier => ValidationUtility.ValidateIdentifier("urn:dicom:uid", $"urn:oid:{DefaultStudyInstanceUid}", identifier),
                identifier => ValidationUtility.ValidateAccessionNumber(null, FhirTransactionContextBuilder.DefaultAccessionNumber, identifier));

            _imagingStudyPropertySynchronizer.Synchronize(context, imagingStudy);

            Assert.Collection(
                imagingStudy.Identifier,
                identifier => ValidationUtility.ValidateIdentifier("urn:dicom:uid", $"urn:oid:{DefaultStudyInstanceUid}", identifier),
                identifier => ValidationUtility.ValidateAccessionNumber(null, FhirTransactionContextBuilder.DefaultAccessionNumber, identifier));
        }
        public async Task GivenNoExistingPatient_WhenRequestIsPrepared_ThenCorrectEntryComponentShouldBeCreated()
        {
            FhirTransactionContext context = CreateFhirTransactionContext();

            Patient creatingPatient = null;

            _patientSynchronizer.When(async synchronizer => await synchronizer.SynchronizeAsync(context, Arg.Any <Patient>(), isNewPatient: true, DefaultCancellationToken)).Do(callback =>
            {
                creatingPatient = callback.ArgAt <Patient>(1);

                // Modify a property of patient so changes can be detected.
                creatingPatient.BirthDateElement = new Date(1990, 01, 01);
            });

            await _patientPipeline.PrepareRequestAsync(context, DefaultCancellationToken);

            FhirTransactionRequestEntry actualPatientEntry = context.Request.Patient;

            ValidationUtility.ValidateRequestEntryMinimumRequirementForWithChange(FhirTransactionRequestMode.Create, "Patient", Bundle.HTTPVerb.POST, actualPatientEntry);

            Assert.Equal("identifier=|p1", actualPatientEntry.Request.IfNoneExist);

            Patient actualPatient = Assert.IsType <Patient>(actualPatientEntry.Resource);

            Assert.Collection(
                actualPatient.Identifier,
                identifier => ValidationUtility.ValidateIdentifier(string.Empty, DefaultPatientId, identifier));

            Assert.Equal(creatingPatient.BirthDate, actualPatient.BirthDate);
        }
        public async Task GivenExistingPatientAndHasChange_WhenRequestIsPrepared_ThenCorrectEntryComponentShouldBeCreated()
        {
            FhirTransactionContext context = CreateFhirTransactionContext();

            var patient = new Patient()
            {
                Id   = "patient1",
                Meta = new Meta()
                {
                    VersionId = "v1",
                },
            };

            _fhirService.RetrievePatientAsync(Arg.Is(TestUtility.BuildIdentifierPredicate(string.Empty, DefaultPatientId)), DefaultCancellationToken)
            .Returns(patient);

            Patient updatingPatient = null;

            _patientSynchronizer.When(async synchronizer => await synchronizer.SynchronizeAsync(context, Arg.Any <Patient>(), isNewPatient: false, DefaultCancellationToken)).Do(callback =>
            {
                updatingPatient = callback.ArgAt <Patient>(1);

                // Modify a property of patient so changes can be detected.
                updatingPatient.Gender = AdministrativeGender.Other;
            });

            await _patientPipeline.PrepareRequestAsync(context, DefaultCancellationToken);

            FhirTransactionRequestEntry actualPatientEntry = context.Request.Patient;

            ValidationUtility.ValidateRequestEntryMinimumRequirementForWithChange(FhirTransactionRequestMode.Update, "Patient/patient1", Bundle.HTTPVerb.PUT, actualPatientEntry);

            Assert.Equal("W/\"v1\"", actualPatientEntry.Request.IfMatch);
            Assert.Same(updatingPatient, actualPatientEntry.Resource);
        }
Example #9
0
        public async Task GivenATransactionContextAndImagingStudyWithExistingEndpointReference_WhenProcessedForStudy_ThenEndpointResourceIsNotAddedAsync()
        {
            ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(DefaultStudyInstanceUid, new List <string>()
            {
                DefaultSeriesInstanceUid
            }, new List <string>()
            {
                DefaultSopInstanceUid
            }, DefaultPatientResourceId);
            Endpoint endpoint           = FhirResourceBuilder.CreateEndpointResource();
            var      endpointResourceId = new ServerResourceId(ResourceType.Endpoint, endpoint.Id);
            var      endpointReference  = endpointResourceId.ToResourceReference();

            FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset());

            context.Request.Endpoint = FhirTransactionRequestEntryGenerator.GenerateDefaultNoChangeRequestEntry <Endpoint>(endpointResourceId);

            imagingStudy.Endpoint.Add(endpointReference);

            await _imagingStudyPropertySynchronizer.SynchronizeAsync(context, imagingStudy);

            Assert.Collection(
                imagingStudy.Endpoint,
                endPoint => Assert.Equal(endpointReference, endPoint));
        }
Example #10
0
        public async Task GivenATransactionContexAndImagingStudyWithNewAccessionNumber_WhenProcessedForStudy_ThenNewAccessionNumberIsAddedAsync()
        {
            ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(DefaultStudyInstanceUid, new List <string>()
            {
                DefaultSeriesInstanceUid
            }, new List <string>()
            {
                DefaultSopInstanceUid
            }, DefaultPatientResourceId);
            FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset());

            await _imagingStudyPropertySynchronizer.SynchronizeAsync(context, imagingStudy);

            Assert.Collection(
                imagingStudy.Identifier,
                identifier => ValidationUtility.ValidateIdentifier("urn:dicom:uid", $"urn:oid:{DefaultStudyInstanceUid}", identifier),            // studyinstanceUid
                identifier => ValidationUtility.ValidateAccessionNumber(null, FhirTransactionContextBuilder.DefaultAccessionNumber, identifier)); // accession number

            FhirTransactionContext newConText = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset(accessionNumber: NewAccessionNumber));

            await _imagingStudyPropertySynchronizer.SynchronizeAsync(newConText, imagingStudy);

            Assert.Collection(
                imagingStudy.Identifier,
                identifier => ValidationUtility.ValidateIdentifier("urn:dicom:uid", $"urn:oid:{DefaultStudyInstanceUid}", identifier),           // studyinstanceUid
                identifier => ValidationUtility.ValidateAccessionNumber(null, FhirTransactionContextBuilder.DefaultAccessionNumber, identifier), // accession number
                identifier => ValidationUtility.ValidateAccessionNumber(null, NewAccessionNumber, identifier));                                  // new accession number
        }
Example #11
0
        public void GivenATransactionContexAndImagingStudyWithNewModality_WhenProcessedForStudy_ThenNewModalityIsAdded()
        {
            ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(DefaultStudyInstanceUid, new List <string>()
            {
                DefaultSeriesInstanceUid
            }, new List <string>()
            {
                DefaultSopInstanceUid
            }, DefaultPatientResourceId);
            FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset());

            _imagingStudyPropertySynchronizer.Synchronize(context, imagingStudy);

            Assert.Collection(
                imagingStudy.Modality,
                modality => string.Equals(modality.Code, "MODALITY", StringComparison.Ordinal));

            FhirTransactionContext newConText = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset(modalityInStudy: "NEWMODALITY", modalityInSeries: "NEWMODALITY"));

            _imagingStudyPropertySynchronizer.Synchronize(newConText, imagingStudy);

            Assert.Collection(
                imagingStudy.Modality,
                modality => string.Equals(modality.Code, "MODALITY", StringComparison.Ordinal),
                modality => string.Equals(modality.Code, "NEWMODALITY", StringComparison.Ordinal));
        }
        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);
        }
        private async Task <FhirTransactionRequestEntry> PrepareRequestAsync(ChangeFeedEntry changeFeedEntry, string patientResourceId)
        {
            _fhirTransactionContext = new FhirTransactionContext(changeFeedEntry);

            _fhirTransactionContext.Request.Patient = FhirTransactionRequestEntryGenerator.GenerateDefaultNoChangeRequestEntry <Patient>(new ServerResourceId(ResourceType.Patient, patientResourceId));

            return(await _imagingStudyDeleteHandler.BuildAsync(_fhirTransactionContext, CancellationToken.None));
        }
        public async Task GivenNullMetadata_WhenRequestIsPrepared_ThenItShouldNotCreateEntryComponent()
        {
            var context = new FhirTransactionContext(ChangeFeedGenerator.Generate());

            await _patientPipeline.PrepareRequestAsync(context, DefaultCancellationToken);

            Assert.Null(context.Request.Patient);
        }
        public void GivenNoUpdateToExistingPatient_WhenResponseIsProcessed_ThenItShouldBeNoOp()
        {
            // Simulate there is no update to patient resource (and therefore no response).
            var context = new FhirTransactionContext(ChangeFeedGenerator.Generate());

            context.Response.Patient = null;

            _patientPipeline.ProcessResponse(context);
        }
Example #16
0
        public void GivenAChangeFeedEntryWithInvalidUtcTimeOffset_WhenDateTimeOffsetIsCalculated_ThenInvalidDicomTagValueExceptionIsThrown()
        {
            FhirTransactionContext fhirTransactionContext = FhirTransactionContextBuilder.DefaultFhirTransactionContext();

            fhirTransactionContext.ChangeFeedEntry.Metadata.Add(DicomTag.TimezoneOffsetFromUTC, "0");

            Assert.Throws <InvalidDicomTagValueException>(
                () => ImagingStudyPipelineHelper.SetDateTimeOffSet(fhirTransactionContext));
        }
Example #17
0
        public async Task GivenAnExistingEndpointWithDifferentAddress_WhenRequestIsPrepared_ThenFhirResourceValidationExceptionShouldBeThrown()
        {
            var context = new FhirTransactionContext(ChangeFeedGenerator.Generate());

            Endpoint endpoint = FhirResourceBuilder.CreateEndpointResource(address: "https://dicom2");

            _fhirService.RetrieveEndpointAsync(Arg.Any <string>(), DefaultCancellationToken).Returns(endpoint);

            await Assert.ThrowsAsync <FhirResourceValidationException>(() => _endpointPipeline.PrepareRequestAsync(context, DefaultCancellationToken));
        }
Example #18
0
        public void GivenAChangeFeedEntry_WhenDateTimeOffsetIsCalculated_ThenDateTimeOffsetIsSet(int hour, int minute, string dicomValue)
        {
            FhirTransactionContext fhirTransactionContext = FhirTransactionContextBuilder.DefaultFhirTransactionContext();

            DateTimeOffset utcTimeZoneOffset = new DateTimeOffset(2020, 1, 1, 0, 0, 0, new TimeSpan(hour, minute, 0));

            fhirTransactionContext.ChangeFeedEntry.Metadata.Add(DicomTag.TimezoneOffsetFromUTC, dicomValue);

            ImagingStudyPipelineHelper.SetDateTimeOffSet(fhirTransactionContext);

            Assert.Equal(utcTimeZoneOffset.Offset, fhirTransactionContext.UtcDateTimeOffset);
        }
Example #19
0
        public void GivenAChangeFeedEntry_WhenDateTimeOffsetIsCalculated_ThenDateTimeOffsetIsSet()
        {
            FhirTransactionContext fhirTransactionContext = FhirTransactionContextBuilder.DefaultFhirTransactionContext();

            DateTimeOffset utcTimeZoneOffset = DateTimeOffset.Now;

            fhirTransactionContext.ChangeFeedEntry.Metadata.Add(DicomTag.TimezoneOffsetFromUTC, utcTimeZoneOffset.ToString(FhirTransactionConstants.UtcTimezoneOffsetFormat));

            ImagingStudyPipelineHelper.SetDateTimeOffSet(fhirTransactionContext);

            Assert.Equal(utcTimeZoneOffset.Offset, fhirTransactionContext.UtcDateTimeOffset);
        }
        public static FhirTransactionContext DefaultFhirTransactionContext(DicomDataset metadata = null)
        {
            var context = new FhirTransactionContext(ChangeFeedGenerator.Generate(metadata: metadata ?? CreateDicomDataset()))
            {
                UtcDateTimeOffset = TimeSpan.Zero,
            };

            context.Request.Patient      = FhirTransactionRequestEntryGenerator.GenerateDefaultCreateRequestEntry <Patient>();
            context.Request.ImagingStudy = FhirTransactionRequestEntryGenerator.GenerateDefaultCreateRequestEntry <ImagingStudy>();
            context.Request.Endpoint     = FhirTransactionRequestEntryGenerator.GenerateDefaultCreateRequestEntry <Endpoint>();

            return(context);
        }
Example #21
0
        public async Task GivenAnExistingEndpointWithMatchingAddress_WhenRequestIsPrepared_ThenCorrectRequestEntryShouldBeCreated()
        {
            var context = new FhirTransactionContext(ChangeFeedGenerator.Generate());

            Endpoint endpoint = FhirResourceBuilder.CreateEndpointResource(address: DefaultDicomWebEndpoint);

            _fhirService.RetrieveEndpointAsync(Arg.Any <string>(), DefaultCancellationToken).Returns(endpoint);

            await _endpointPipeline.PrepareRequestAsync(context, DefaultCancellationToken);

            FhirTransactionRequestEntry actualEndPointEntry = context.Request.Endpoint;

            ValidationUtility.ValidateRequestEntryMinimumRequirementForNoChange(endpoint.ToServerResourceId(), actualEndPointEntry);
        }
        public void GivenARequestToCreateAPatient_WhenResponseIsOK_ThenResourceConflictExceptionShouldBeThrown()
        {
            var response = new Bundle.ResponseComponent();

            response.AddAnnotation(HttpStatusCode.OK);

            var context = new FhirTransactionContext(ChangeFeedGenerator.Generate());

            context.Request.Patient = FhirTransactionRequestEntryGenerator.GenerateDefaultCreateRequestEntry <Patient>();

            context.Response.Patient = new FhirTransactionResponseEntry(response, new Patient());

            Assert.Throws <ResourceConflictException>(() => _patientPipeline.ProcessResponse(context));
        }
        public void GivenARequestToUpdateAPatient_WhenResponseIsOK_ThenItShouldBeNoOp()
        {
            var response = new Bundle.ResponseComponent();

            response.AddAnnotation(HttpStatusCode.OK);

            var context = new FhirTransactionContext(ChangeFeedGenerator.Generate());

            context.Request.Patient = FhirTransactionRequestEntryGenerator.GenerateDefaultUpdateRequestEntry <Patient>(
                new ServerResourceId(ResourceType.Patient, "123"));

            context.Response.Patient = new FhirTransactionResponseEntry(response, new Patient());

            _patientPipeline.ProcessResponse(context);
        }
Example #24
0
        public async Task SyncPropertiesAsync_PartialValidationEnabledAndPropertyRequired_ThrowsError()
        {
            ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(DefaultStudyInstanceUid, new List <string>()
            {
                DefaultSeriesInstanceUid
            }, new List <string>()
            {
                DefaultSopInstanceUid
            }, DefaultPatientResourceId);
            FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset());

            Action <ImagingStudy, FhirTransactionContext> actionSubstitute = Substitute.For <Action <ImagingStudy, FhirTransactionContext> >();

            actionSubstitute.When(x => x.Invoke(imagingStudy, context)).Do(x => throw new InvalidDicomTagValueException("invalid tag", "invalid tag"));

            await Assert.ThrowsAsync <InvalidDicomTagValueException>(() => ImagingStudyPipelineHelper.SynchronizePropertiesAsync(imagingStudy, context, actionSubstitute, true, true, _exceptionStore));
        }
Example #25
0
        public void GivenATransactionContextAndImagingStudyWithNoEndpoint_WhenProcessedForStudy_ThenNewEndpointIsAdded()
        {
            ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(DefaultStudyInstanceUid, new List <string>()
            {
                DefaultSeriesInstanceUid
            }, new List <string>()
            {
                DefaultSopInstanceUid
            }, DefaultPatientResourceId);
            FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset());

            _imagingStudyPropertySynchronizer.Synchronize(context, imagingStudy);

            Assert.Collection(
                imagingStudy.Endpoint,
                endPoint => Assert.Equal(context.Request.Endpoint.ResourceId.ToResourceReference(), endPoint));
        }
Example #26
0
        public FhirTransactionPipelineTests()
        {
            // Use this step to capture the context. The same context will be used across all steps.
            _captureFhirTransactionContextStep.When(pipeline => pipeline.PrepareRequestAsync(Arg.Any <FhirTransactionContext>(), DefaultCancellationToken))
            .Do(callback =>
            {
                FhirTransactionContext context = callback.ArgAt <FhirTransactionContext>(0);

                _capturedFhirTransactionContext = context;
            });

            _fhirTransactionPipelineSteps.Add(_captureFhirTransactionContextStep);

            _fhirTransactionPipeline = new FhirTransactionPipeline(
                _fhirTransactionPipelineSteps,
                _fhirTransactionRequestResponsePropertyAccessors,
                _fhirTransactionExecutor);
        }
Example #27
0
        public async Task WhenDoesNotEnforceAllFields_AndPropertyNotRequired_DoesNotThrowError()
        {
            _dicomCastConfig.Features.EnforceValidationOfTagValues = false;

            _propertySynchronizer.When(synchronizer => synchronizer.Synchronize(Arg.Any <DicomDataset>(), Arg.Any <Patient>(), isNewPatient: false)).Do(synchronizer => { throw new InvalidDicomTagValueException("invalid tag", "invalid tag"); });

            IEnumerable <IPatientPropertySynchronizer> patientPropertySynchronizers = new List <IPatientPropertySynchronizer>()
            {
                _propertySynchronizer,
            };

            PatientSynchronizer patientSynchronizer = new PatientSynchronizer(patientPropertySynchronizers, Options.Create(_dicomCastConfig), _exceptionStore);

            FhirTransactionContext context = new FhirTransactionContext(ChangeFeedGenerator.Generate(metadata: DefaultDicomDataset));
            var patient = new Patient();

            await patientSynchronizer.SynchronizeAsync(context, patient, false, DefaultCancellationToken);
        }
        public async Task GivenAChangeFeedEntryForCreate_WhenPreparingTheRequest_ThenCreateHandlerIsCalled()
        {
            const string studyInstanceUid  = "1";
            const string seriesInstanceUid = "2";
            const string sopInstanceUid    = "3";

            ChangeFeedEntry changeFeed = ChangeFeedGenerator.Generate(
                action: ChangeFeedAction.Create,
                studyInstanceUid: studyInstanceUid,
                seriesInstanceUid: seriesInstanceUid,
                sopInstanceUid: sopInstanceUid);

            var fhirTransactionContext = new FhirTransactionContext(changeFeed);

            await _imagingStudyPipeline.PrepareRequestAsync(fhirTransactionContext, DefaultCancellationToken);

            await _imagingStudyUpsertHandler.Received(1).BuildAsync(fhirTransactionContext, DefaultCancellationToken);
        }
Example #29
0
        public async Task GivenNoExistingPatient_WhenRequestIsPrepared_ThenCorrectEntryComponentShouldBeCreated()
        {
            FhirTransactionContext context = CreateFhirTransactionContext();

            await _patientPipeline.PrepareRequestAsync(context, DefaultCancellationToken);

            FhirTransactionRequestEntry actualPatientEntry = context.Request.Patient;

            ValidationUtility.ValidateRequestEntryMinimumRequirementForWithChange(FhirTransactionRequestMode.Create, "Patient", Bundle.HTTPVerb.POST, actualPatientEntry);

            Assert.Equal("identifier=|p1", actualPatientEntry.Request.IfNoneExist);

            Patient actualPatient = Assert.IsType <Patient>(actualPatientEntry.Resource);

            Assert.Collection(
                actualPatient.Identifier,
                identifier => ValidationUtility.ValidateIdentifier(string.Empty, DefaultPatientId, identifier));
        }
Example #30
0
        public async Task WhenPatialValidationDisabled_AndError_ThrowsError()
        {
            _dicomCastConfig.Features.IgnoreSyncOfInvalidTagValue = false;

            _propertySynchronizer.When(synchronizer => synchronizer.Synchronize(Arg.Any <DicomDataset>(), Arg.Any <Patient>(), isNewPatient: false)).Do(synchronizer => { throw new InvalidDicomTagValueException("invalid tag", "invalid tag"); });

            IEnumerable <IPatientPropertySynchronizer> patientPropertySynchronizers = new List <IPatientPropertySynchronizer>()
            {
                _propertySynchronizer,
            };

            PatientSynchronizer patientSynchronizer = new PatientSynchronizer(patientPropertySynchronizers, Options.Create(_dicomCastConfig), _exceptionStore);

            FhirTransactionContext context = new FhirTransactionContext(ChangeFeedGenerator.Generate(metadata: DefaultDicomDataset));
            var patient = new Patient();

            await Assert.ThrowsAsync <InvalidDicomTagValueException>(() => patientSynchronizer.SynchronizeAsync(context, patient, false, DefaultCancellationToken));
        }