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 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));
        }
Example #3
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
        }
        public async Task GivenAValidCreateChangeFeed_WhenBuilt_ThenCorrectEntryComponentShouldBeCreated()
        {
            const string studyInstanceUid  = "1";
            const string seriesInstanceUid = "2";
            const string sopInstanceUid    = "3";
            const string patientResourceId = "p1";

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

            FhirTransactionRequestEntry entry = await BuildImagingStudyEntryComponent(studyInstanceUid, seriesInstanceUid, sopInstanceUid, patientResourceId);

            ValidationUtility.ValidateRequestEntryMinimumRequirementForWithChange(FhirTransactionRequestMode.Create, "ImagingStudy", Bundle.HTTPVerb.POST, entry);

            ImagingStudy imagingStudy = Assert.IsType <ImagingStudy>(entry.Resource);

            string jsonString;

            jsonString = JsonSerializer.Serialize(entry);

            Assert.IsType <ClientResourceId>(entry.ResourceId);
            Assert.Equal(ImagingStudy.ImagingStudyStatus.Available, imagingStudy.Status);
            Assert.Null(entry.Request.IfMatch);

            ValidationUtility.ValidateResourceReference("Patient/p1", imagingStudy.Subject);

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

            Assert.Collection(
                imagingStudy.Series,
                series =>
            {
                Assert.Equal(seriesInstanceUid, series.Uid);

                Assert.Collection(
                    series.Instance,
                    instance => Assert.Equal(sopInstanceUid, instance.Uid));
            });

            ValidateDicomFilePropertiesAreCorrectlyMapped(imagingStudy, series: imagingStudy.Series.First(), instance: imagingStudy.Series.First().Instance.First());
        }
Example #5
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));
        }