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);
        }
Exemplo n.º 2
0
        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(synchronizer => synchronizer.Synchronize(DefaultDicomDataset, Arg.Any <Patient>())).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);
        }