public async Task GivenFhirServer_WhenPatientDataIsExported_ThenExportedDataIsSameAsDataInFhirServer()
        {
            // NOTE: Azure Storage Emulator is required to run these tests locally.

            // Trigger export request and check for export status
            Uri contentLocation = await _testFhirClient.ExportAsync("Patient/");

            IList <Uri> blobUris = await ExportTestHelper.CheckExportStatus(_testFhirClient, contentLocation, timeToWaitInMinutes : 15);

            // Download exported data from storage account
            Dictionary <(string resourceType, string resourceId), Resource> dataFromExport =
                await ExportTestHelper.DownloadBlobAndParse(blobUris, _fhirJsonParser, _outputHelper);

            // Download resources from fhir server
            Uri address = new Uri(_testFhirClient.HttpClient.BaseAddress, "Patient/");
            Dictionary <(string resourceType, string resourceId), Resource> dataFromFhirServer = await ExportTestHelper.GetResourcesFromFhirServer(_testFhirClient, address, _fhirJsonParser, _outputHelper);

            Dictionary <(string resourceType, string resourceId), Resource> compartmentData = new Dictionary <(string resourceType, string resourceId), Resource>();

            foreach ((string resourceType, string resourceId)key in dataFromFhirServer.Keys)
            {
                address = new Uri(_testFhirClient.HttpClient.BaseAddress, "Patient/" + key.resourceId + "/*");

                // copies all the new values into the compartment data dictionary
                (await ExportTestHelper.GetResourcesFromFhirServer(_testFhirClient, address, _fhirJsonParser, _outputHelper))
                .ToList()
                .ForEach(x => compartmentData.TryAdd(x.Key, x.Value));
            }

            compartmentData.ToList().ForEach(x => dataFromFhirServer.TryAdd(x.Key, x.Value));
            dataFromFhirServer.Union(compartmentData);

            // Assert both data are equal
            Assert.True(ExportTestHelper.ValidateDataFromBothSources(dataFromFhirServer, dataFromExport, _outputHelper));
        }
Ejemplo n.º 2
0
        public async Task GivenFhirServer_WhenGroupDataWithNoMemberPatientIdIsExported_ThenNoDataIsExported()
        {
            // NOTE: Azure Storage Emulator is required to run these tests locally.

            // Add data for test
            string groupId = await CreateGroupWithoutPatientIds();

            // Trigger export request and check for export status
            Uri contentLocation = await _testFhirClient.ExportAsync($"Group/{groupId}/");

            IList <Uri> blobUris = await ExportTestHelper.CheckExportStatus(_testFhirClient, contentLocation);

            Assert.Empty(blobUris);

            async Task <string> CreateGroupWithoutPatientIds()
            {
                var group = new FhirGroup()
                {
                    Type   = FhirGroup.GroupType.Person,
                    Actual = true,
                };

                var groupResponse = await _testFhirClient.CreateAsync(group);

                return(groupResponse.Resource.Id);
            }
        }
Ejemplo n.º 3
0
        internal static async Task <Dictionary <(string resourceType, string resourceId), Resource> > DownloadBlobAndParse(
            IList <Uri> blobUri,
            FhirJsonParser fhirJsonParser,
            ITestOutputHelper outputHelper)
        {
            if (blobUri == null || blobUri.Count == 0)
            {
                return(new Dictionary <(string resourceType, string resourceId), Resource>());
            }

            // Extract storage account name from blob uri in order to get corresponding access token.
            Uri    sampleUri          = blobUri[0];
            string storageAccountName = sampleUri.Host.Split('.')[0];

            CloudStorageAccount cloudAccount = ExportTestHelper.GetCloudStorageAccountHelper(storageAccountName);
            CloudBlobClient     blobClient   = cloudAccount.CreateCloudBlobClient();
            var resourceIdToResourceMapping  = new Dictionary <(string resourceType, string resourceId), Resource>();

            foreach (Uri uri in blobUri)
            {
                var    blob    = new CloudBlockBlob(uri, blobClient);
                string allData = await blob.DownloadTextAsync();

                var splitData = allData.Split("\n");

                foreach (string entry in splitData)
                {
                    if (string.IsNullOrWhiteSpace(entry))
                    {
                        continue;
                    }

                    Resource resource;
                    try
                    {
                        resource = fhirJsonParser.Parse <Resource>(entry);
                    }
                    catch (Exception ex)
                    {
                        outputHelper.WriteLine($"Unable to parse ndjson string to resource: {ex}");
                        return(resourceIdToResourceMapping);
                    }

                    // Ideally this should just be Add, but until we prevent duplicates from being added to the server
                    // there is a chance the same resource being added multiple times resulting in a key conflict.
                    resourceIdToResourceMapping.TryAdd((resource.TypeName, resource.Id), resource);
                }
            }

            return(resourceIdToResourceMapping);
        }
Ejemplo n.º 4
0
        public async Task GivenFhirServer_WhenGroupDataIsExportedWithTypeParameter_ThenExportedDataIsSameAsDataInFhirServer()
        {
            // NOTE: Azure Storage Emulator is required to run these tests locally.

            // Add data for test
            var(dataInFhirServer, groupId) = await CreateGroupWithPatient(false);

            // Trigger export request and check for export status
            Uri contentLocation = await _testFhirClient.ExportAsync($"Group/{groupId}/", "_type=RelatedPerson,Encounter");

            IList <Uri> blobUris = await ExportTestHelper.CheckExportStatus(_testFhirClient, contentLocation);

            // Download exported data from storage account
            Dictionary <(string resourceType, string resourceId), Resource> dataFromExport =
                await ExportTestHelper.DownloadBlobAndParse(blobUris, _fhirJsonParser, _outputHelper);

            // Assert both sets of data are equal
            Assert.True(ExportTestHelper.ValidateDataFromBothSources(dataInFhirServer, dataFromExport, _outputHelper));
        }
        public async Task GivenFhirServer_WhenAllDataIsExported_ThenExportedDataIsSameAsDataInFhirServer()
        {
            // NOTE: Azure Storage Emulator is required to run these tests locally.

            // Trigger export request and check for export status
            Uri contentLocation = await _testFhirClient.ExportAsync();

            IList <Uri> blobUris = await ExportTestHelper.CheckExportStatus(_testFhirClient, contentLocation, timeToWaitInMinutes : 15);

            // Download exported data from storage account
            Dictionary <(string resourceType, string resourceId), Resource> dataFromExport =
                await ExportTestHelper.DownloadBlobAndParse(blobUris, _fhirJsonParser, _outputHelper);

            // Download all resources from fhir server
            Dictionary <(string resourceType, string resourceId), Resource> dataFromFhirServer =
                await ExportTestHelper.GetResourcesFromFhirServer(_testFhirClient, _testFhirClient.HttpClient.BaseAddress, _fhirJsonParser, _outputHelper);

            // Assert both data are equal
            Assert.True(ExportTestHelper.ValidateDataFromBothSources(dataFromFhirServer, dataFromExport, _outputHelper));
        }
        public async Task GivenFhirServer_WhenAllDataIsExportedToASpecificContainer_ThenExportedDataIsInTheSpecifiedContianer()
        {
            // NOTE: Azure Storage Emulator is required to run these tests locally.

            string testContainer = "test-container";

            // Trigger export request and check for export status
            Uri contentLocation = await _testFhirClient.ExportAsync(parameters : $"_container={testContainer}");

            IList <Uri> blobUris = await ExportTestHelper.CheckExportStatus(_testFhirClient, contentLocation, timeToWaitInMinutes : 15);

            // Download exported data from storage account
            Dictionary <(string resourceType, string resourceId), Resource> dataFromExport =
                await ExportTestHelper.DownloadBlobAndParse(blobUris, _fhirJsonParser, _outputHelper);

            // Download all resources from fhir server
            Dictionary <(string resourceType, string resourceId), Resource> dataFromFhirServer =
                await ExportTestHelper.GetResourcesFromFhirServer(_testFhirClient, _testFhirClient.HttpClient.BaseAddress, _fhirJsonParser, _outputHelper);

            // Assert both data are equal
            Assert.True(ExportTestHelper.ValidateDataFromBothSources(dataFromFhirServer, dataFromExport, _outputHelper));
            Assert.True(blobUris.All((url) => url.OriginalString.Contains(testContainer)));
        }
Ejemplo n.º 7
0
        public async Task GivenFhirServer_WhenDataIsExported_ThenExportTaskMetricsNotificationShouldBePosted()
        {
            // NOTE: Azure Storage Emulator is required to run these tests locally.

            if (!_fixture.IsUsingInProcTestServer)
            {
                // This test only works with the in-proc server with a customized metric handler.
                return;
            }

            // Clean notification before tests
            _fixture.MetricHandler.ResetCount();

            // Add data for test
            var(_, groupId) = await CreateGroupWithPatient(true);

            // Trigger export request and check for export status
            Uri contentLocation = await _testFhirClient.ExportAsync($"Group/{groupId}/");

            await ExportTestHelper.CheckExportStatus(_testFhirClient, contentLocation);

            // Assert at least one notification handled.
            Assert.Single(_fixture.MetricHandler.NotificationMapping[typeof(ExportTaskMetricsNotification)]);
        }