Exemple #1
0
 public ExportDataValidationTests(ExportTestFixture fixture, ITestOutputHelper testOutputHelper)
 {
     _testFhirClient = fixture.TestFhirClient;
     _outputHelper   = testOutputHelper;
     _fhirJsonParser = new FhirJsonParser();
     _fixture        = fixture;
 }
        public async Task InitializeAsync()
        {
            // Create various resources.
            Device = await TestFhirClient.CreateAsync(Samples.GetJsonSample <Device>("Device-d1"));

            Patient = await TestFhirClient.CreateAsync(Samples.GetJsonSample <Patient>("Patient-f001"));

            string patientReference = $"Patient/{Patient.Id}";

            Observation observationToCreate = Samples.GetJsonSample <Observation>("Observation-For-Patient-f001");

            observationToCreate.Subject.Reference = patientReference;

            observationToCreate.Device = new ResourceReference($"Device/{Device.Id}");

            Observation = await TestFhirClient.CreateAsync(observationToCreate);

            Encounter encounterToCreate = Samples.GetJsonSample <Encounter>("Encounter-For-Patient-f001");

            encounterToCreate.Subject.Reference = patientReference;

            Encounter = await TestFhirClient.CreateAsync(encounterToCreate);

            Condition conditionToCreate = Samples.GetJsonSample <Condition>("Condition-For-Patient-f001");

            conditionToCreate.Subject.Reference = patientReference;

            Condition = await TestFhirClient.CreateAsync(conditionToCreate);
        }
Exemple #3
0
        public StringSearchTestFixture(DataStore dataStore, Format format, TestFhirServerFactory testFhirServerFactory)
            : base(dataStore, format, testFhirServerFactory)
        {
            // Prepare the resources used for string search tests.
            TestFhirClient.DeleteAllResources(ResourceType.Patient).Wait();

            Patients = TestFhirClient.CreateResourcesAsync <Patient>(
                p => SetPatientInfo(p, "Seattle", "Smith", given: "Bea"),
                p => SetPatientInfo(p, "Portland", "Williams"),
                p => SetPatientInfo(p, "Vancouver", "Anderson"),
                p => SetPatientInfo(p, LongString, "Murphy"),
                p => SetPatientInfo(p, "Montreal", "Richard", given: "Bea"))
                       .Result;

            void SetPatientInfo(Patient patient, string city, string family, string given = null)
            {
                patient.Address = new List <Address>()
                {
                    new Address()
                    {
                        City = city
                    },
                };

                patient.Name = new List <HumanName>()
                {
                    new HumanName()
                    {
                        Family = family, Given = new[] { given }
                    },
                };
            }
        }
Exemple #4
0
        public async Task GivenAUserWithConvertDataPermissions_WhenConvertData_TheServerShouldReturnSuccess()
        {
            if (!_convertDataEnabled)
            {
                return;
            }

            TestFhirClient tempClient = _client.CreateClientForUser(TestUsers.ConvertDataUser, TestApplications.NativeClient);
            var            parameters = Samples.GetDefaultConvertDataParameter().ToPoco <Parameters>();
            var            result     = await tempClient.ConvertDataAsync(parameters);

            var setting = new ParserSettings()
            {
                AcceptUnknownMembers = true,
                PermissiveParsing    = true,
            };
            var parser         = new FhirJsonParser(setting);
            var bundleResource = parser.Parse <Bundle>(result);

            Assert.Equal("urn:uuid:9d697ec3-48c3-3e17-db6a-29a1765e22c6", bundleResource.Entry.First().FullUrl);
            Assert.Equal(4, bundleResource.Entry.Count);

            var patient = bundleResource.Entry.First().Resource as Patient;

            Assert.Equal("Kinmonth", patient.Name.First().Family);
            Assert.Equal("1987-06-24", patient.BirthDate);
        }
        protected override async Task OnInitializedAsync()
        {
            Tag = Guid.NewGuid().ToString();

            var meta = new Meta
            {
                Tag = new List <Coding>
                {
                    new Coding("testTag", Tag),
                },
            };

            // Prepare the resources used for number search tests.

            RiskAssessments = await TestFhirClient.CreateResourcesAsync <RiskAssessment>(
                i => SetRiskAssessment(i, 1),
                i => SetRiskAssessment(i, 4),
                i => SetRiskAssessment(i, 5),
                i => SetRiskAssessment(i, 6),
                i => SetRiskAssessment(i, 100));

            void SetRiskAssessment(RiskAssessment riskAssessment, int probability)
            {
                riskAssessment.Meta       = meta;
                riskAssessment.Status     = ObservationStatus.Final;
                riskAssessment.Subject    = new ResourceReference("Patient/123");
                riskAssessment.Prediction = new List <RiskAssessment.PredictionComponent>
                {
                    new RiskAssessment.PredictionComponent {
                        Probability = new FhirDecimal(probability)
                    },
                };
            }
        }
        protected override async Task OnInitializedAsync()
        {
            // Creates a unique code for searches
            Coding = new Coding
            {
                Code   = Guid.NewGuid().ToString(),
                System = "http://fhir-server-test/guid",
            };

            Observations = await TestFhirClient.CreateResourcesAsync <Observation>(
                p => SetObservation(p, "1979-12-31"),              // 1979-12-31T00:00:00.0000000 <-> 1979-12-31T23:59:59.9999999
                p => SetObservation(p, "1980"),                    // 1980-01-01T00:00:00.0000000 <-> 1980-12-31T23:59:59.9999999
                p => SetObservation(p, "1980-05"),                 // 1980-05-01T00:00:00.0000000 <-> 1980-05-31T23:59:59.9999999
                p => SetObservation(p, "1980-05-11"),              // 1980-05-11T00:00:00.0000000 <-> 1980-05-11T23:59:59.9999999
                p => SetObservation(p, "1980-05-11T16:32:15"),     // 1980-05-11T16:32:15.0000000 <-> 1980-05-11T16:32:15.9999999
                p => SetObservation(p, "1980-05-11T16:32:15.500"), // 1980-05-11T16:32:15.5000000 <-> 1980-05-11T16:32:15.5000000
                p => SetObservation(p, "1981-01-01"));             // 1981-01-01T00:00:00.0000000 <-> 1981-12-31T23:59:59.9999999

            void SetObservation(Observation observation, string date)
            {
                observation.Status = ObservationStatus.Final;
                observation.Code   = new CodeableConcept
                {
                    Coding = new List <Coding>
                    {
                        Coding,
                    },
                };
                observation.Effective = new FhirDateTime(date);
            }
        }
Exemple #7
0
        // Check export status and return output once we get 200
        internal static async Task <IList <Uri> > CheckExportStatus(TestFhirClient testFhirClient, Uri contentLocation, int timeToWaitInMinutes = 5)
        {
            HttpStatusCode      resultCode = HttpStatusCode.Accepted;
            HttpResponseMessage response   = null;
            int retryCount = 0;

            // Wait until status change or timeout
            while ((resultCode == HttpStatusCode.Accepted || resultCode == HttpStatusCode.ServiceUnavailable) && retryCount < 60)
            {
                await Task.Delay(timeToWaitInMinutes * 1000);

                response = await testFhirClient.CheckExportAsync(contentLocation);

                resultCode = response.StatusCode;

                retryCount++;
            }

            if (retryCount >= 60)
            {
                throw new Exception($"Export request timed out");
            }

            if (resultCode != HttpStatusCode.OK)
            {
                throw new Exception($"Export request failed with status code {resultCode}");
            }

            // we have got the result. Deserialize into output response.
            var contentString = await response.Content.ReadAsStringAsync();

            ExportJobResult exportJobResult = JsonConvert.DeserializeObject <ExportJobResult>(contentString);

            return(exportJobResult.Output.Select(x => x.FileUri).ToList());
        }
 public ExportLongRunningTests(ExportTestFixture fixture, ITestOutputHelper testOutputHelper)
 {
     _testFhirClient = fixture.TestFhirClient;
     _outputHelper   = testOutputHelper;
     _fhirJsonParser = new FhirJsonParser();
     _fixture        = fixture;
 }
Exemple #9
0
        public DateSearchTestFixture(DataStore dataStore, Format format, TestFhirServerFactory testFhirServerFactory)
            : base(dataStore, format, testFhirServerFactory)
        {
            // Creates a unique code for searches
            Coding = new Coding
            {
                Code   = Guid.NewGuid().ToString(),
                System = "http://fhir-server-test/guid",
            };

            Observations = TestFhirClient.CreateResourcesAsync <Observation>(
                p => SetObservation(p, "1979-12-31"),                // 1979-12-31T00:00:00.0000000 <-> 1979-12-31T23:59:59.9999999
                p => SetObservation(p, "1980"),                      // 1980-01-01T00:00:00.0000000 <-> 1980-12-31T23:59:59.9999999
                p => SetObservation(p, "1980-05"),                   // 1980-05-01T00:00:00.0000000 <-> 1980-05-31T23:59:59.9999999
                p => SetObservation(p, "1980-05-11"),                // 1980-05-11T00:00:00.0000000 <-> 1980-05-11T23:59:59.9999999
                p => SetObservation(p, "1980-05-11T16:32:15"),       // 1980-05-11T16:32:15.0000000 <-> 1980-05-11T16:32:15.9999999
                p => SetObservation(p, "1980-05-11T16:32:15.500"),   // 1980-05-11T16:32:15.5000000 <-> 1980-05-11T16:32:15.5000000
                p => SetObservation(p, "1981-01-01")).Result;        // 1981-01-01T00:00:00.0000000 <-> 1981-12-31T23:59:59.9999999

            void SetObservation(Observation observation, string date)
            {
                observation.Status = ObservationStatus.Final;
                observation.Code   = new CodeableConcept
                {
                    Coding = new List <Coding>
                    {
                        Coding,
                    },
                };
                observation.Effective = new FhirDateTime(date);
            }
        }
Exemple #10
0
        protected override async Task OnInitializedAsync()
        {
            Patients = await TestFhirClient.CreateResourcesAsync <Patient>(
                p => SetPatientInfo(p, "Seattle", "Smith", given: "Bea"),
                p => SetPatientInfo(p, "Portland", "Williams"),
                p => SetPatientInfo(p, "Vancouver", "Anderson"),
                p => SetPatientInfo(p, LongString, "Murphy"),
                p => SetPatientInfo(p, "Montreal", "Richard", given: "Bea"),
                p => SetPatientInfo(p, "New York", "Muller"),
                p => SetPatientInfo(p, "Portland", "Müller"),
                p => SetPatientInfo(p, "Moscow", "Richard,Muller"));

            void SetPatientInfo(Patient patient, string city, string family, string given = null)
            {
                patient.Address = new List <Address>()
                {
                    new Address {
                        City = city
                    },
                };

                patient.Name = new List <HumanName>()
                {
                    new HumanName {
                        Family = family, Given = new[] { given }
                    },
                };

                patient.Meta = new Meta();
                patient.Meta.Tag.Add(new Coding("http://e2e-test", FixtureTag));
            }
        }
Exemple #11
0
        protected override async Task OnInitializedAsync()
        {
            // Prepare the resources used for number search tests.

            Tag = Guid.NewGuid().ToString();

            var meta = new Meta
            {
                Tag = new List <Coding>
                {
                    new Coding("testTag", Tag),
                },
            };

            Observations = await TestFhirClient.CreateResourcesAsync <Observation>(
                o => SetObservation(o, 0.002m, "unit1", "system1"),
                o => SetObservation(o, 1.0m, "unit1", "system1"),
                o => SetObservation(o, 3.12m, "unit1", "system2"),
                o => SetObservation(o, 4.0m, "unit1", "system1"),
                o => SetObservation(o, 5.0m, "unit1", "system1"),
                o => SetObservation(o, 5.0m, "unit2", "system2"),
                o => SetObservation(o, 6.0m, "unit2", "system2"),
                o => SetObservation(o, 8.95m, "unit2", "system1"),
                o => SetObservation(o, 10.0m, "unit1", "system1"));

            void SetObservation(Observation observation, decimal quantity, string unit, string system)
            {
                observation.Meta   = meta;
                observation.Code   = new CodeableConcept("system", "code");
                observation.Status = ObservationStatus.Registered;

                observation.Value = new Quantity(quantity, unit, system);
            }
        }
Exemple #12
0
        private async Task <Uri> ImportCheckAsync(ImportRequest request, TestFhirClient client = null, int?errorCount = null)
        {
            client = client ?? _client;
            Uri checkLocation = await ImportTestHelper.CreateImportTaskAsync(client, request);

            HttpResponseMessage response;

            while ((response = await client.CheckImportAsync(checkLocation, CancellationToken.None)).StatusCode == System.Net.HttpStatusCode.Accepted)
            {
                await Task.Delay(TimeSpan.FromSeconds(5));
            }

            Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
            ImportTaskResult result = JsonConvert.DeserializeObject <ImportTaskResult>(await response.Content.ReadAsStringAsync());

            Assert.NotEmpty(result.Output);
            if (errorCount != null)
            {
                Assert.Equal(errorCount.Value, result.Error.First().Count);
            }
            else
            {
                Assert.Empty(result.Error);
            }

            Assert.NotEmpty(result.Request);

            return(checkLocation);
        }
Exemple #13
0
        protected override async System.Threading.Tasks.Task OnInitializedAsync()
        {
            // Delete all profile related resources before starting the test suite.
            var sd = new List <string>()
            {
                "StructureDefinition-us-core-birthsex", "StructureDefinition-us-core-ethnicity", "StructureDefinition-us-core-patient",
                "StructureDefinition-us-core-race", "StructureDefinition-us-core-organization", "StructureDefinition-us-core-careplan",
            };

            foreach (var name in sd)
            {
                await TestFhirClient.CreateAsync(Samples.GetJsonSample <StructureDefinition>(name), $"name={name}");
            }

            var valueSets = new List <string>()
            {
                "ValueSet-detailed-ethnicity", "ValueSet-detailed-race", "ValueSet-omb-ethnicity-category",
                "ValueSet-omb-race-category", "ValueSet-us-core-birthsex", "ValueSet-us-core-narrative-status",
            };

            foreach (var name in valueSets)
            {
                await TestFhirClient.CreateAsync(Samples.GetJsonSample <ValueSet>(name), $"name={name}");
            }

            var codeSystem = new List <string>()
            {
                "CodeSystem-careplan-category"
            };

            foreach (var name in codeSystem)
            {
                await TestFhirClient.CreateAsync(Samples.GetJsonSample <CodeSystem>(name), $"name={name}");
            }
        }
Exemple #14
0
 public AuditTests(AuditTestFixture fixture)
 {
     _fixture     = fixture;
     _client      = fixture.TestFhirClient;
     _auditLogger = _fixture.AuditLogger;
     _client.DeleteAllResources(ResourceType.Patient).Wait();
 }
Exemple #15
0
        public async Task GivenAUserWithImportPermissions_WhenImportData_TheServerShouldReturnSuccess()
        {
            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);
        }
        public async Task InitializeAsync()
        {
            string environmentUrl = Environment.GetEnvironmentVariable($"TestEnvironmentUrl{Constants.TestEnvironmentVariableVersionSuffix}");

            // Only set up test fixture if running against remote server
            if (!string.IsNullOrWhiteSpace(environmentUrl))
            {
                var baseUrl = "https://localhost:" + Port;
                SmartLauncherUrl = baseUrl + "/index.html";

                var builder = WebHost.CreateDefaultBuilder()
                    .ConfigureAppConfiguration((hostingContext, config) =>
                    {
                        config.AddInMemoryCollection(new Dictionary<string, string>
                        {
                            { "FhirServerUrl", environmentUrl },
                            { "ClientId", TestApplications.NativeClient.ClientId },
                            { "DefaultSmartAppUrl", "/sampleapp/launch.html" },
                        });
                    })
                    .UseStartup<SmartLauncher.Startup>()
                    .UseUrls(baseUrl);

                WebServer = builder.Build();
                WebServer.Start();

                TestFhirServer testFhirServer = await _testFhirServerFactory.GetTestFhirServerAsync(DataStore.CosmosDb, null);
                TestFhirClient = testFhirServer.GetTestFhirClient(ResourceFormat.Json);
            }
        }
Exemple #17
0
        public async Task GivenAClientWithNoAuthToken_WhenCreatingAResource_TheServerShouldReturnUnauthorized()
        {
            TestFhirClient tempClient = _client.CreateClientForClientApplication(TestApplications.InvalidClient);

            FhirException fhirException = await Assert.ThrowsAsync <FhirException>(async() => await tempClient.CreateAsync(Samples.GetDefaultObservation().ToPoco <Observation>()));

            Assert.Equal(UnauthorizedMessage, fhirException.Message);
            Assert.Equal(HttpStatusCode.Unauthorized, fhirException.StatusCode);

            List <AuthenticationHeaderValue> wwwAuthenticationHeaderValues = fhirException.Headers.WwwAuthenticate.Where(h => h.Scheme == "Bearer").ToList();

            Assert.Single(wwwAuthenticationHeaderValues);

            Match matchResults = WwwAuthenticatePattern.Match(wwwAuthenticationHeaderValues.First().Parameter);

            Assert.Single(matchResults.Groups["authorization_uri"].Captures);
            var authorizationUri = matchResults.Groups["authorization_uri"].Captures[0].Value;

            Assert.Single(matchResults.Groups["realm"].Captures);
            var realm = matchResults.Groups["realm"].Captures[0].Value;

            Assert.Single(matchResults.Groups["resource_id"].Captures);
            var resourceId = matchResults.Groups["resource_id"].Captures[0].Value;

            Assert.Equal(AuthenticationSettings.Resource, realm);
            Assert.Equal(realm, resourceId);

            // We can only verify that this is a URI since a server with SmartOnFHIR enabled will not report the actual authorization server anywhere else.
            Assert.True(Uri.TryCreate(authorizationUri, UriKind.Absolute, out _));
        }
Exemple #18
0
        public async Task GivenAValidBundleWithReadonlyUser_WhenSubmittingABatch_ThenForbiddenAndOutcomeIsReturned()
        {
            TestFhirClient tempClient    = _client.CreateClientForUser(TestUsers.ReadOnlyUser, TestApplications.NativeClient);
            Bundle         requestBundle = Samples.GetDefaultBatch().ToPoco <Bundle>();

            using FhirResponse <Bundle> fhirResponse = await tempClient.PostBundleAsync(requestBundle);

            Assert.NotNull(fhirResponse);
            Assert.Equal(HttpStatusCode.OK, fhirResponse.StatusCode);

            for (int i = 0; i < 7; i++)
            {
                var entry            = fhirResponse.Resource.Entry[i];
                var operationOutcome = entry.Response.Outcome as OperationOutcome;
                ValidateOperationOutcome(entry.Response.Status, operationOutcome, _statusCodeMap[HttpStatusCode.Forbidden], "Authorization failed.", IssueType.Forbidden);
            }

            var resourceEntry = fhirResponse.Resource.Entry[7];

            ValidateOperationOutcome(resourceEntry.Response.Status, resourceEntry.Response.Outcome as OperationOutcome, _statusCodeMap[HttpStatusCode.NotFound], "The route for \"/ValueSet/$lookup\" was not found.", IssueType.NotFound);
            resourceEntry = fhirResponse.Resource.Entry[8];
            Assert.Equal("200", resourceEntry.Response.Status);
            Assert.Null(resourceEntry.Response.Outcome);
            resourceEntry = fhirResponse.Resource.Entry[9];
            ValidateOperationOutcome(resourceEntry.Response.Status, resourceEntry.Response.Outcome as OperationOutcome, _statusCodeMap[HttpStatusCode.NotFound], "Resource type 'Patient' with id '12334' couldn't be found.", IssueType.NotFound);
        }
Exemple #19
0
 public AnonymizedExportTests(ExportTestFixture fixture)
 {
     _isUsingInProcTestServer = fixture.IsUsingInProcTestServer;
     _testFhirClient          = fixture.TestFhirClient;
     _metricHandler           = fixture.MetricHandler;
     _exportConfiguration     = ((IOptions <ExportJobConfiguration>)(fixture.TestFhirServer as InProcTestFhirServer)?.Server?.Services?.GetService(typeof(IOptions <ExportJobConfiguration>)))?.Value;
 }
Exemple #20
0
        public StringSearchTestFixture(DataStore dataStore, Format format, TestFhirServerFactory testFhirServerFactory)
            : base(dataStore, format, testFhirServerFactory)
        {
            Patients = TestFhirClient.CreateResourcesAsync <Patient>(
                p => SetPatientInfo(p, "Seattle", "Smith", given: "Bea"),
                p => SetPatientInfo(p, "Portland", "Williams"),
                p => SetPatientInfo(p, "Vancouver", "Anderson"),
                p => SetPatientInfo(p, LongString, "Murphy"),
                p => SetPatientInfo(p, "Montreal", "Richard", given: "Bea"),
                p => SetPatientInfo(p, "New York", "Muller"),
                p => SetPatientInfo(p, "Portland", "Müller"))
                       .Result;

            void SetPatientInfo(Patient patient, string city, string family, string given = null)
            {
                patient.Address = new List <Address>()
                {
                    new Address {
                        City = city
                    },
                };

                patient.Name = new List <HumanName>()
                {
                    new HumanName {
                        Family = family, Given = new[] { given }
                    },
                };

                patient.Meta = new Meta();
                patient.Meta.Tag.Add(new Coding("http://e2e-test", FixtureTag));
            }
        }
        public NumberSearchTestFixture(DataStore dataStore, Format format, TestFhirServerFactory testFhirServerFactory)
            : base(dataStore, format, testFhirServerFactory)
        {
            // Prepare the resources used for number search tests.
            TestFhirClient.DeleteAllResources(ResourceType.RiskAssessment).Wait();

            RiskAssessments = TestFhirClient.CreateResourcesAsync <RiskAssessment>(
                i => SetRiskAssessment(i, 1),
                i => SetRiskAssessment(i, 4),
                i => SetRiskAssessment(i, 5),
                i => SetRiskAssessment(i, 6),
                i => SetRiskAssessment(i, 100)).Result;

            void SetRiskAssessment(RiskAssessment riskAssessment, int probability)
            {
                riskAssessment.Status     = ObservationStatus.Final;
                riskAssessment.Subject    = new ResourceReference("Patient/123");
                riskAssessment.Prediction = new List <RiskAssessment.PredictionComponent>
                {
                    new RiskAssessment.PredictionComponent {
                        Probability = new FhirDecimal(probability)
                    },
                };
            }
        }
Exemple #22
0
        public async Task GivenAUserWithoutImportPermissions_WhenImportData_ThenServerShouldReturnForbidden()
        {
            TestFhirClient tempClient            = _client.CreateClientForUser(TestUsers.ReadOnlyUser, TestApplications.NativeClient);
            string         patientNdJsonResource = Samples.GetNdJson("Import-Patient");

            (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",
                    },
                },
            };

            request.Mode  = ImportConstants.InitialLoadMode;
            request.Force = true;
            FhirException fhirException = await Assert.ThrowsAsync <FhirException>(async() => await tempClient.ImportAsync(request.ToParameters(), CancellationToken.None));

            Assert.Equal(ForbiddenMessage, fhirException.Message);
            Assert.Equal(HttpStatusCode.Forbidden, fhirException.StatusCode);
        }
Exemple #23
0
        protected override async Task OnInitializedAsync()
        {
            Observation resource1 = Samples.GetDefaultObservation().ToPoco <Observation>();

            resource1.Meta         = new Meta();
            resource1.Meta.Profile = new[]
            {
                ObservationProfileV1,
            };

            GivenObservation1 = (await TestFhirClient.CreateAsync(resource1)).Resource;

            Observation resource2 = Samples.GetDefaultObservation().ToPoco <Observation>();

            resource2.Meta         = new Meta();
            resource2.Meta.Profile = new[]
            {
                ObservationProfileV2,
            };

            GivenObservation2 = (await TestFhirClient.CreateAsync(resource2)).Resource;

            Observation resource3 = Samples.GetDefaultObservation().ToPoco <Observation>();

            resource3.Meta         = new Meta();
            resource3.Meta.Profile = new[]
            {
                ObservationProfileUriAlternate,
                $"{ObservationProfileUri}{ObservationProfileV1Version}",
            };

            GivenObservation3 = (await TestFhirClient.CreateAsync(resource3)).Resource;
        }
Exemple #24
0
        public HistoryTests(HttpIntegrationTestFixture fixture)
        {
            Fixture = fixture;
            _client = fixture.TestFhirClient;

            _createdResource = _client.CreateAsync(Samples.GetDefaultObservation().ToPoco <Observation>()).GetAwaiter().GetResult();
        }
        public BasicAuthTests(HttpIntegrationTestFixture fixture)
        {
            _client = fixture.TestFhirClient;
            var convertDataConfiguration = ((IOptions <ConvertDataConfiguration>)(fixture.TestFhirServer as InProcTestFhirServer)?.Server?.Services?.GetService(typeof(IOptions <ConvertDataConfiguration>)))?.Value;

            _convertDataEnabled = convertDataConfiguration?.Enabled ?? false;
        }
Exemple #26
0
        public async Task GivenAUserWithNoCreatePermissions_WhenCreatingAResource_TheServerShouldReturnForbidden()
        {
            TestFhirClient tempClient    = _client.CreateClientForUser(TestUsers.ReadOnlyUser, TestApplications.NativeClient);
            FhirException  fhirException = await Assert.ThrowsAsync <FhirException>(async() => await tempClient.CreateAsync(Samples.GetDefaultObservation().ToPoco <Observation>()));

            Assert.Equal(ForbiddenMessage, fhirException.Message);
            Assert.Equal(HttpStatusCode.Forbidden, fhirException.StatusCode);
        }
Exemple #27
0
        public async Task GivenAUserWithExportPermissions_WhenExportResources_TheServerShouldReturnSuccess()
        {
            TestFhirClient tempClient = _client.CreateClientForUser(TestUsers.ExportUser, TestApplications.NativeClient);

            Uri contentLocation = await tempClient.ExportAsync();

            await tempClient.CancelExport(contentLocation);
        }
Exemple #28
0
        public async Task GivenAClientWithWrongAudience_WhenCreatingAResource_TheServerShouldReturnUnauthorized()
        {
            TestFhirClient tempClient    = _client.CreateClientForClientApplication(TestApplications.WrongAudienceClient);
            FhirException  fhirException = await Assert.ThrowsAsync <FhirException>(async() => await tempClient.CreateAsync(Samples.GetDefaultObservation().ToPoco <Observation>()));

            Assert.Equal(UnauthorizedMessage, fhirException.Message);
            Assert.Equal(HttpStatusCode.Unauthorized, fhirException.StatusCode);
        }
        public async Task GivenUserWithNoProfileAdminPermission_WhenDeleteProfileDefinitionResource_ThenServerShouldReturnForbidden()
        {
            TestFhirClient tempClient    = _client.CreateClientForUser(TestUsers.ReadWriteUser, TestApplications.NativeClient);
            var            resource      = Samples.GetJsonSample("ValueSet").ToPoco <ValueSet>();
            var            fhirException = await Assert.ThrowsAsync <FhirException>(async() => await tempClient.DeleteAsync <ValueSet>(resource));

            Assert.Equal(ForbiddenMessage, fhirException.Message);
            Assert.Equal(HttpStatusCode.Forbidden, fhirException.StatusCode);
        }
Exemple #30
0
        public async Task GivenAUserWithNoExportPermissions_WhenExportResources_TheServerShouldReturnForbidden()
        {
            TestFhirClient tempClient = _client.CreateClientForUser(TestUsers.ReadOnlyUser, TestApplications.NativeClient);

            FhirException fhirException = await Assert.ThrowsAsync <FhirException>(async() => await tempClient.ExportAsync());

            Assert.Equal(ForbiddenMessage, fhirException.Message);
            Assert.Equal(HttpStatusCode.Forbidden, fhirException.StatusCode);
        }
        public void RetrieveWebArtifactCustomFhirClient()
        {
            TestFhirClient client = null;

            var wa = new WebArtifactSource(id => client = new TestFhirClient(id));

            Assert.IsNull(client);

            var artifact = wa.LoadConformanceResourceByUrl("http://fhir-dev.healthintersections.com.au/open/StructureDefinition/Flag");

            Assert.IsNotNull(client);
            Assert.AreEqual(client.Status, 3);

            Assert.IsNotNull(artifact);
            Assert.IsTrue(artifact is StructureDefinition);
            Assert.AreEqual("Flag", ((StructureDefinition)artifact).Name);
        }