コード例 #1
0
        public override async Task <OperationResultEnum> Execute()
        {
            Validate(_arguments);

            TokenResponse tokenResponse = null;

            if (!string.IsNullOrEmpty(_arguments.Credentials))
            {
                tokenResponse = await GetToken(_arguments.Environment?.AuthorizationUrl, _arguments.Credentials, _arguments.AuthorizationUrl);
            }

            var endpoint = _arguments.FhirBaseUrl?.Uri;

            if (string.IsNullOrEmpty(endpoint))
            {
                endpoint = tokenResponse == null ? _arguments.Environment.FhirBaseUrl : _arguments.Environment.ProxyBaseUrl;
            }

            var client = new FhirClientWrapper(endpoint, _logger, _arguments.FhirVersion, tokenResponse?.AccessToken);

            var baseDir = CreateBaseDirectory(new Uri(endpoint), client.FhirVersion);

            _logger.LogInformation($"Created local storage at {MakeRelativeToCurrentDirectory(baseDir.FullName)}");
            await DownloadAndStore(client, baseDir);

            return(_issues.Any(issue => issue.Severity == IssueSeverityEnum.Error)
                ? OperationResultEnum.Failed
                : OperationResultEnum.Succeeded);
        }
コード例 #2
0
        private async Task DownloadAndStore(FhirClientWrapper client, DirectoryInfo baseDir)
        {
            foreach (var resourceType in _arguments.Resources)
            {
                _logger.LogInformation($"Starting to download resources of type {resourceType}");
                await DownloadAndStoreResource(resourceType, client, baseDir);

                _logger.LogInformation($"Done downloading resources of type {resourceType}");
            }
        }
コード例 #3
0
        private async Task DownloadAndStoreResource(string resourceType, FhirClientWrapper client, DirectoryInfo baseDir)
        {
            var resourceTypeDir = Directory.CreateDirectory(SafeDirectoryName(Path.Combine(baseDir.FullName, resourceType)));
            var result          = await client.SearchAsync(resourceType);

            result = _arguments.KeepServerUrl && result != null?UpdateBundleServerUrl(result, client.Endpoint) : result;
            await SerializeAndStore(result, resourceTypeDir);

            while (result != null)
            {
                result = await client.ContinueAsync(result);

                result = _arguments.KeepServerUrl && result != null?UpdateBundleServerUrl(result, client.Endpoint) : result;
                await SerializeAndStore(result, resourceTypeDir);
            }
        }
コード例 #4
0
        public override async Tasks.Task <OperationResultEnum> Execute()
        {
            Validate(_arguments);

            TokenResponse tokenResponse = null;

            if (!string.IsNullOrEmpty(_arguments.Credentials))
            {
                tokenResponse = await GetToken(_arguments.Environment?.AuthorizationUrl, _arguments.Credentials, _arguments.AuthorizationUrl);
            }

            var endpoint = _arguments.FhirBaseUrl?.Uri;

            if (string.IsNullOrEmpty(endpoint))
            {
                endpoint = tokenResponse == null ? _arguments.Environment.FhirBaseUrl : _arguments.Environment.ProxyBaseUrl;
            }

            var client = new FhirClientWrapper(endpoint, _logger, _arguments.FhirVersion, tokenResponse?.AccessToken);

            var batches = FindFiles().Batch(_arguments.BatchSize);

            foreach (var batch in batches)
            {
                var bundle = await CreateBundle(batch, client.FhirVersion);

                bundle.Type = BundleTypeWrapper.Transaction;

                try
                {
                    _logger.LogInformation($"Uploading batch with {batch.Count()} entries");
                    await client.TransactionAsync(bundle);

                    System.Threading.Thread.Sleep(_arguments.Sleep);
                }
                catch (Exception e)
                {
                    _logger.LogError($"Failed to upload batch: {e.Message}");
                    _logger.LogError($"Response was: {client.LastBodyAsText}");
                    var bundleAsStr = new SerializationWrapper(client.FhirVersion).Serialize(bundle.ToBase());
                    await File.WriteAllTextAsync("debug-on-exception", bundleAsStr);
                }
            }

            return(await Tasks.Task.FromResult(OperationResultEnum.Succeeded));
        }
コード例 #5
0
        public override async Task <OperationResultEnum> Execute()
        {
            Validate(_arguments);

            TokenResponse tokenResponse = null;

            if (!string.IsNullOrEmpty(_arguments.Credentials))
            {
                tokenResponse = await GetToken(_arguments.Environment?.AuthorizationUrl, _arguments.Credentials, _arguments.AuthorizationUrl);
            }

            var endpoint = _arguments.FhirBaseUrl?.Uri;

            if (string.IsNullOrEmpty(endpoint))
            {
                endpoint = tokenResponse == null ? _arguments.Environment.FhirBaseUrl : _arguments.Environment.ProxyBaseUrl;
            }

            var resourceType = _arguments.ResourceType.GetLiteral();

            _logger.LogInformation($"Starting delete operation of FHIR {resourceType} with id: '{_arguments.ResourceId}'.");

            var client = new FhirClientWrapper(endpoint, _logger, _arguments.FhirVersion, tokenResponse?.AccessToken);

            try
            {
                await client.DeleteAsync(resourceType, _arguments.ResourceId);

                _logger.LogInformation($"Successfully deleted {resourceType} with id: '{_arguments.ResourceId}' at endpoint: '{endpoint}'.");
            }
            catch (Exception e)
            {
                _issues.Add(new Issue
                {
                    Details  = e.Message,
                    Severity = IssueSeverityEnum.Error,
                });
            }

            return(_issues.Any(issue => issue.Severity == IssueSeverityEnum.Error)
                ? OperationResultEnum.Failed
                : OperationResultEnum.Succeeded);
        }
コード例 #6
0
        public override async Tasks.Task <OperationResultEnum> Execute()
        {
            Validate(_arguments);

            TokenResponse tokenResponse = null;

            if (!string.IsNullOrEmpty(_arguments.Credentials))
            {
                tokenResponse = await GetToken(_arguments.Environment?.AuthorizationUrl, _arguments.Credentials, _arguments.AuthorizationUrl);
            }

            var endpoint = _arguments.FhirBaseUrl?.Uri;

            if (string.IsNullOrEmpty(endpoint))
            {
                endpoint = tokenResponse == null ? _arguments.Environment.FhirBaseUrl : _arguments.Environment.ProxyBaseUrl;
            }

            _logger.LogInformation($"Deserializing Fhir resource at '{_arguments.QuestionnairePath}'.");
            _logger.LogInformation($"Expecting format: '{_arguments.MimeType}'.");

            await foreach (var resource in ExpandInputFiles())
            {
                _logger.LogInformation($"Uploading {resource.ResourceType} to endpoint: '{endpoint}'");
                // Set a relative url before posting to the server
                SetQuestionnaireUrl(resource);

                var client   = new FhirClientWrapper(endpoint, _logger, _arguments.FhirVersion, tokenResponse?.AccessToken);
                var response = await UploadResource(resource, client);

                var resourceType = resource.ResourceType.GetLiteral();
                _logger.LogInformation($"Successfully uploaded {resourceType} to endpoint: '{endpoint}'.");
                if (response != null)
                {
                    _logger.LogInformation($"Resource was assigned the Id: '{resource.Id}'");
                    _logger.LogInformation($"Resource can be accessed at: '{resource.ResourceType.GetLiteral()}/{resource.Id}'");
                }
            }

            return(_issues.Any(issue => issue.Severity == IssueSeverityEnum.Error)
                ? OperationResultEnum.Failed
                : OperationResultEnum.Succeeded);
        }
コード例 #7
0
 private async Tasks.Task <ResourceWrapper> UploadResource(ResourceWrapper resource, FhirClientWrapper client)
 {
     if (string.IsNullOrWhiteSpace(resource.Id))
     {
         return(await client.CreateAsync(resource));
     }
     else
     {
         return(await client.UpdateAsync(resource));
     }
 }