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);
        }
        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 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());
        }
Beispiel #4
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));
        }
Beispiel #5
0
        public async Task GivenEndpointDoesNotAlreadyExist_WhenRequestIsPrepared_ThenCorrentRequestEntryShouldBeCreated()
        {
            var context = new FhirTransactionContext(ChangeFeedGenerator.Generate());

            await _endpointPipeline.PrepareRequestAsync(context, DefaultCancellationToken);

            FhirTransactionRequestEntry actualEndpointEntry = context.Request.Endpoint;

            ValidationUtility.ValidateRequestEntryMinimumRequirementForWithChange(FhirTransactionRequestMode.Create, "Endpoint", Bundle.HTTPVerb.POST, actualEndpointEntry);

            Assert.Equal($"name={EndpointName}&connection-type={EndpointConnectionTypeSystem}|{EndpointConnectionTypeCode}", actualEndpointEntry.Request.IfNoneExist);

            Endpoint endpoint = Assert.IsType <Endpoint>(actualEndpointEntry.Resource);

            Assert.Equal(EndpointName, endpoint.Name);
            Assert.Equal(Endpoint.EndpointStatus.Active, endpoint.Status);
            Assert.NotNull(endpoint.ConnectionType);
            Assert.Equal(EndpointConnectionTypeSystem, endpoint.ConnectionType.System);
            Assert.Equal(EndpointConnectionTypeCode, endpoint.ConnectionType.Code);
            Assert.Equal(_configuration.Endpoint.ToString(), endpoint.Address);
            Assert.Equal(EndpointPayloadTypeText, endpoint.PayloadType.First().Text);
            Assert.Equal(new[] { DicomMimeType }, endpoint.PayloadMimeType);
        }