Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new import tool #3182

Merged
merged 9 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Microsoft.Health.Fhir.sln
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Health.TaskManage
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Health.Fhir.Store.Utils", "src\Microsoft.Health.Fhir.Store.Utils\Microsoft.Health.Fhir.Store.Utils.csproj", "{7A736E5F-DA6E-483F-AD5B-EE8F66828E36}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RegisterAndMonitorImport", "tools\RegisterAndMonitorImport\RegisterAndMonitorImport.csproj", "{E85BCB9A-5D6E-45AD-BE67-AEFA060FEBF1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Importer", "tools\Importer\Importer.csproj", "{F6B94905-B496-46AD-B2A7-2ABCB0B2A6B4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Exporter", "tools\Exporter\Exporter.csproj", "{E468B6C6-9098-4293-AFD6-3B1675D67063}"
Expand Down Expand Up @@ -344,6 +346,10 @@ Global
{7A736E5F-DA6E-483F-AD5B-EE8F66828E36}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7A736E5F-DA6E-483F-AD5B-EE8F66828E36}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7A736E5F-DA6E-483F-AD5B-EE8F66828E36}.Release|Any CPU.Build.0 = Release|Any CPU
{E85BCB9A-5D6E-45AD-BE67-AEFA060FEBF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E85BCB9A-5D6E-45AD-BE67-AEFA060FEBF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E85BCB9A-5D6E-45AD-BE67-AEFA060FEBF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E85BCB9A-5D6E-45AD-BE67-AEFA060FEBF1}.Release|Any CPU.Build.0 = Release|Any CPU
{F6B94905-B496-46AD-B2A7-2ABCB0B2A6B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F6B94905-B496-46AD-B2A7-2ABCB0B2A6B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6B94905-B496-46AD-B2A7-2ABCB0B2A6B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -474,6 +480,7 @@ Global
{03AD4FC4-A56F-4E94-B295-B02A9E3E3CCD} = {7457B218-2651-49B5-BED8-22233889516A}
{BB7512E7-E148-4AF8-9D34-AA47A6AE692D} = {7457B218-2651-49B5-BED8-22233889516A}
{7A736E5F-DA6E-483F-AD5B-EE8F66828E36} = {B70945F4-01A6-4351-955B-C4A2943B5E3B}
{E85BCB9A-5D6E-45AD-BE67-AEFA060FEBF1} = {B70945F4-01A6-4351-955B-C4A2943B5E3B}
{F6B94905-B496-46AD-B2A7-2ABCB0B2A6B4} = {B70945F4-01A6-4351-955B-C4A2943B5E3B}
{E468B6C6-9098-4293-AFD6-3B1675D67063} = {B70945F4-01A6-4351-955B-C4A2943B5E3B}
{A0320AE9-3F87-44A3-8263-5AF7E00085D4} = {38B3BA4A-3510-4615-BCC4-4C9B96A486C4}
Expand Down
33 changes: 33 additions & 0 deletions tools/RegisterAndMonitorImport/ImportResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// -------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Microsoft.Health.Internal.Fhir.RegisterAndMonitorImport
{
#pragma warning disable CA1812 // Avoid uninstantiated internal classes
internal sealed class ImportResponse
{
[JsonPropertyName("error")]
public List<Json> Error { get; set; } = new();

[JsonPropertyName("output")]
public List<Json> Output { get; set; } = new();

public sealed class Json
{
[JsonPropertyName("type")]
public string Type { get; set; } = string.Empty;

[JsonPropertyName("count")]
public int Count { get; set; }

[JsonPropertyName("inputUrl")]
public string InputUrl { get; set; } = string.Empty;
}
}
#pragma warning disable CA1812 // Avoid uninstantiated internal classes
}
27 changes: 27 additions & 0 deletions tools/RegisterAndMonitorImport/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// -------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.Health.Internal.Fhir.RegisterAndMonitorImport
{
public static class Program
{
public static async Task Main()
{
IConfigurationRoot configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.Build();

RegisterAndMonitorConfiguration registerAndMonitorConfiguration = new();
configuration.GetSection(RegisterAndMonitorConfiguration.SectionName).Bind(registerAndMonitorConfiguration);

var import = new RegisterAndMonitorImport(registerAndMonitorConfiguration);
await import.Run();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// -------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using System;

namespace Microsoft.Health.Internal.Fhir.RegisterAndMonitorImport
{
internal sealed class RegisterAndMonitorConfiguration
{
public const string SectionName = "RegisterAndMonitor";

/// <summary>
/// If you just want to monitor an import then provide a url for this key/value
/// Note that if this is provided then it only performs this operation and will not do any import.
/// The endpoint would be something similar to this https://{your fhir endpoint}/_operations/import/{import id}
/// </summary>
public string MonitorImportStatusEndpoint { get; set; } = string.Empty;

/// <summary>
/// the time delay between calls to get the status of the import
/// generally smaller ndjson files can be used with smaller timespans
/// and larger ndjson files should have larger timespans
/// </summary>
public TimeSpan ImportStatusDelay { get; set; } = TimeSpan.FromMinutes(2);

/// <summary>
/// Azure blob storage connection string
/// </summary>
public string ConnectionString { get; set; } = string.Empty;

/// <summary>
/// Azure blob storage container name - used with the ConnectionString
/// </summary>
public string ContainerName { get; set; } = string.Empty;

/// <summary>
/// the type of file it'll search for in the container
/// do not add a file extension - It's assumed and added to the ResourceType automatically
/// </summary>
public string ResourceType { get; set; } = string.Empty;

/// <summary>
/// a simple flag to indicate that when true we're going to use the token for/// our http POST/GET
/// this is useful when you have a Paas deployment if you set to false then you could use it against an oss fhir service
/// and Token properties do not need to be set.
/// </summary>
public bool UseBearerToken { get; set; }

/// <summary>
/// the number of blobs we want to import at a time
/// </summary>
public int NumberOfBlobsForImport { get; set; } = 1;

/// <summary>
/// the url of your FHIR endpoint - also used as the value for the key "resource" for getting a token
/// </summary>
public string FhirEndpoint { get; set; }

/// <summary>
/// Used for the value of the key "grant_type" for getting a token
/// </summary>
public string TokenGrantType { get; set; } = "Client_Credentials";

/// <summary>
/// Used for the value of the key "client_id" for getting a token
/// </summary>
public string TokenClientId { get; set; }

/// <summary>
/// Used for the value of the key "client_secret" for getting a token
/// </summary>
public string TokenClientSecret { get; set; }

public bool IsMonitorImportStatusEndpoint => !string.IsNullOrWhiteSpace(MonitorImportStatusEndpoint);
}
}
Loading