public async Task GivenAValidConfigurationWithETag_WhenExportingAnonymizedData_ResourceShouldBeAnonymized(string path)
        {
            _metricHandler?.ResetCount();
            var dateTime         = DateTimeOffset.UtcNow;
            var resourceToCreate = Samples.GetDefaultPatient().ToPoco <Patient>();

            resourceToCreate.Id = Guid.NewGuid().ToString();
            await _testFhirClient.UpdateAsync(resourceToCreate);

            (string fileName, string etag) = await UploadConfigurationAsync(RedactResourceIdAnonymizationConfiguration);

            string containerName   = Guid.NewGuid().ToString("N");
            Uri    contentLocation = await _testFhirClient.AnonymizedExportAsync(fileName, dateTime, containerName, etag, path);

            HttpResponseMessage response = await WaitForCompleteAsync(contentLocation);

            IList <Uri> blobUris = await CheckExportStatus(response);

            IEnumerable <string> dataFromExport = await DownloadBlobAndParse(blobUris);

            FhirJsonParser parser = new FhirJsonParser();

            foreach (string content in dataFromExport)
            {
                Resource result = parser.Parse <Resource>(content);

                Assert.Contains(result.Meta.Security, c => "REDACTED".Equals(c.Code));
            }

            // Only check metric for local tests
            if (_isUsingInProcTestServer)
            {
                Assert.Single(_metricHandler.NotificationMapping[typeof(ExportTaskMetricsNotification)]);
            }
        }
Esempio n. 2
0
        public async Task GivenAValidConfigurationWithETag_WhenExportingAnonymizedData_ResourceShouldBeAnonymized()
        {
            if (!_isUsingInProcTestServer)
            {
                return;
            }

            _metricHandler.ResetCount();

            (string fileName, string etag) = await UploadConfigurationAsync(RedactResourceIdAnonymizationConfiguration);

            string containerName   = Guid.NewGuid().ToString("N");
            Uri    contentLocation = await _testFhirClient.AnonymizedExportAsync(fileName, containerName, etag);

            HttpResponseMessage response = await WaitForCompleteAsync(contentLocation);

            IList <Uri> blobUris = await CheckExportStatus(response);

            IEnumerable <string> dataFromExport = await DownloadBlobAndParse(blobUris);

            FhirJsonParser parser = new FhirJsonParser();

            foreach (string content in dataFromExport)
            {
                Resource result = parser.Parse <Resource>(content);

                Assert.Contains(result.Meta.Security, c => "REDACTED".Equals(c.Code));
            }

            Assert.Single(_metricHandler.NotificationMapping[typeof(ExportTaskMetricsNotification)]);
        }
Esempio n. 3
0
        public async Task GivenAUserWithImportPermissions_WhenImportData_TheServerShouldReturnSuccess()
        {
            _metricHandler?.ResetCount();
            TestFhirClient tempClient            = _client.CreateClientForUser(TestUsers.BulkImportUser, TestApplications.NativeClient);
            string         patientNdJsonResource = Samples.GetNdJson("Import-Patient");

            patientNdJsonResource       = Regex.Replace(patientNdJsonResource, "##PatientID##", m => Guid.NewGuid().ToString("N"));
            (Uri location, string etag) = await ImportTestHelper.UploadFileAsync(patientNdJsonResource, _fixture.CloudStorageAccount);

            var request = new ImportRequest()
            {
                InputFormat   = "application/fhir+ndjson",
                InputSource   = new Uri("https://other-server.example.org"),
                StorageDetail = new ImportRequestStorageDetail()
                {
                    Type = "azure-blob"
                },
                Input = new List <InputResource>()
                {
                    new InputResource()
                    {
                        Url  = location,
                        Type = "Patient",
                    },
                },
            };

            await ImportCheckAsync(request, tempClient);

            // Only check metric for local tests
            if (_fixture.IsUsingInProcTestServer)
            {
                var resourceCount    = Regex.Matches(patientNdJsonResource, "{\"resourceType\":").Count;
                var notificationList = _metricHandler.NotificationMapping[typeof(ImportTaskMetricsNotification)];
                Assert.Single(notificationList);
                var notification = notificationList.First() as ImportTaskMetricsNotification;
                Assert.Equal(TaskResult.Success.ToString(), notification.Status);
                Assert.NotNull(notification.DataSize);
                Assert.Equal(resourceCount, notification.SucceedCount);
                Assert.Equal(0, notification.FailedCount);
            }
        }