forked from microsoft/fhir-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial import operation (microsoft#1992)
Add import operation for customer to initial load data to FHIR service. Sample request: ``` curl --location --request POST 'https://localhost:44348/$import' \ --header 'Accept: application/fhir+json' \ --header 'Prefer: respond-async' \ --header 'Content-Type: application/fhir+json' \ --data-raw '{ "resourceType": "Parameters", "parameter": [ { "name": "inputFormat", "valueString": "application/fhir+ndjson" }, { "name": "mode", "valueString": "InitialLoad" }, { "name": "input", "part": [ { "name": "type", "valueString": "Patient" }, { "name": "url", "valueUri": "http://127.0.0.1:10000/devstoreaccount1/0000/Patient.ndjson" } ] }, { "name": "input", "part": [ { "name": "type", "valueString": "Patient" }, { "name": "url", "valueUri": "http://127.0.0.1:10000/devstoreaccount1/0000/PatientErr.ndjson" } ] }, { "name": "storageDetail", "part": [ { "name": "type", "valueString": "azure-blob" } ] } ] }' ``` Sample result ``` { "transactionTime": "2021-05-17T06:23:47.0892657+00:00", "request": "https://localhost:44348/$import", "output": [ { "type": "Patient", "count": 4, "inputUrl": "http://127.0.0.1:10000/devstoreaccount1/0000/Patient.ndjson" }, { "type": "Patient", "count": 4, "inputUrl": "http://127.0.0.1:10000/devstoreaccount1/0000/PatientErr.ndjson" } ], "error": [ { "type": "Patient", "count": 1, "inputUrl": "http://127.0.0.1:10000/devstoreaccount1/0000/PatientErr.ndjson", "url": "http://127.0.0.1:10000/devstoreaccount1/fhirlogs/Patient38d5d864efcc40ecbdf31ee63dea7f89.ndjson" } ] } ```
- Loading branch information
Showing
235 changed files
with
18,387 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/Microsoft.Health.Fhir.Api/Features/ActionResults/ImportResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System.Net; | ||
using EnsureThat; | ||
using Microsoft.Health.Fhir.Core.Features.Operations.Import; | ||
|
||
namespace Microsoft.Health.Fhir.Api.Features.ActionResults | ||
{ | ||
/// <summary> | ||
/// Used to return the result of a bulk import operation. | ||
/// </summary> | ||
public class ImportResult : ResourceActionResult<ImportTaskResult> | ||
{ | ||
public ImportResult(HttpStatusCode statusCode) | ||
: base(null, statusCode) | ||
{ | ||
} | ||
|
||
public ImportResult(ImportTaskResult jobResult, HttpStatusCode statusCode) | ||
: base(jobResult, statusCode) | ||
{ | ||
EnsureArg.IsNotNull(jobResult, nameof(jobResult)); | ||
} | ||
|
||
/// <summary> | ||
/// Creates an ImportResult with HttpStatusCode Accepted. | ||
/// </summary> | ||
public static ImportResult Accepted() | ||
{ | ||
return new ImportResult(HttpStatusCode.Accepted); | ||
} | ||
|
||
/// <summary> | ||
/// Creates an ImportResult with HttpStatusCode Ok. | ||
/// </summary> | ||
/// <param name="taskResult">The job payload that must be returned as part of the ImportResult.</param> | ||
public static ImportResult Ok(ImportTaskResult taskResult) | ||
{ | ||
EnsureArg.IsNotNull(taskResult, nameof(taskResult)); | ||
|
||
return new ImportResult(taskResult, HttpStatusCode.OK); | ||
} | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
src/Microsoft.Health.Fhir.Api/Features/BackgroundTaskService/TaskFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using EnsureThat; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Health.Core.Features.Context; | ||
using Microsoft.Health.Fhir.Core.Features.Context; | ||
using Microsoft.Health.Fhir.Core.Features.Operations; | ||
using Microsoft.Health.Fhir.Core.Features.Operations.Import; | ||
using Microsoft.Health.TaskManagement; | ||
using Newtonsoft.Json; | ||
|
||
namespace Microsoft.Health.Fhir.Api.Features.BackgroundTaskService | ||
{ | ||
/// <summary> | ||
/// Factory to create different tasks. | ||
/// </summary> | ||
public class TaskFactory : ITaskFactory | ||
{ | ||
private readonly IImportResourceLoader _importResourceLoader; | ||
private readonly IResourceBulkImporter _resourceBulkImporter; | ||
private readonly IImportErrorStoreFactory _importErrorStoreFactory; | ||
private readonly IImportOrchestratorTaskDataStoreOperation _importOrchestratorTaskDataStoreOperation; | ||
private readonly ISequenceIdGenerator<long> _sequenceIdGenerator; | ||
private readonly IIntegrationDataStoreClient _integrationDataStoreClient; | ||
private readonly ITaskManager _taskmanager; | ||
private readonly IContextUpdaterFactory _contextUpdaterFactory; | ||
private readonly RequestContextAccessor<IFhirRequestContext> _contextAccessor; | ||
private readonly ILoggerFactory _loggerFactory; | ||
|
||
public TaskFactory( | ||
IImportResourceLoader importResourceLoader, | ||
IResourceBulkImporter resourceBulkImporter, | ||
IImportErrorStoreFactory importErrorStoreFactory, | ||
IImportOrchestratorTaskDataStoreOperation importOrchestratorTaskDataStoreOperation, | ||
IContextUpdaterFactory contextUpdaterFactory, | ||
ITaskManager taskmanager, | ||
ISequenceIdGenerator<long> sequenceIdGenerator, | ||
IIntegrationDataStoreClient integrationDataStoreClient, | ||
RequestContextAccessor<IFhirRequestContext> contextAccessor, | ||
ILoggerFactory loggerFactory) | ||
{ | ||
EnsureArg.IsNotNull(importResourceLoader, nameof(importResourceLoader)); | ||
EnsureArg.IsNotNull(resourceBulkImporter, nameof(resourceBulkImporter)); | ||
EnsureArg.IsNotNull(importErrorStoreFactory, nameof(importErrorStoreFactory)); | ||
EnsureArg.IsNotNull(importOrchestratorTaskDataStoreOperation, nameof(importOrchestratorTaskDataStoreOperation)); | ||
EnsureArg.IsNotNull(contextUpdaterFactory, nameof(contextUpdaterFactory)); | ||
EnsureArg.IsNotNull(taskmanager, nameof(taskmanager)); | ||
EnsureArg.IsNotNull(sequenceIdGenerator, nameof(sequenceIdGenerator)); | ||
EnsureArg.IsNotNull(integrationDataStoreClient, nameof(integrationDataStoreClient)); | ||
EnsureArg.IsNotNull(contextAccessor, nameof(contextAccessor)); | ||
EnsureArg.IsNotNull(loggerFactory, nameof(loggerFactory)); | ||
|
||
_importResourceLoader = importResourceLoader; | ||
_resourceBulkImporter = resourceBulkImporter; | ||
_importErrorStoreFactory = importErrorStoreFactory; | ||
_importOrchestratorTaskDataStoreOperation = importOrchestratorTaskDataStoreOperation; | ||
_sequenceIdGenerator = sequenceIdGenerator; | ||
_integrationDataStoreClient = integrationDataStoreClient; | ||
_taskmanager = taskmanager; | ||
_contextUpdaterFactory = contextUpdaterFactory; | ||
_contextAccessor = contextAccessor; | ||
_loggerFactory = loggerFactory; | ||
} | ||
|
||
public ITask Create(TaskInfo taskInfo) | ||
{ | ||
EnsureArg.IsNotNull(taskInfo, nameof(taskInfo)); | ||
|
||
if (taskInfo.TaskTypeId == ImportProcessingTask.ImportProcessingTaskId) | ||
{ | ||
IContextUpdater contextUpdater = _contextUpdaterFactory.CreateContextUpdater(taskInfo.TaskId, taskInfo.RunId); | ||
ImportProcessingTaskInputData inputData = JsonConvert.DeserializeObject<ImportProcessingTaskInputData>(taskInfo.InputData); | ||
ImportProcessingProgress importProgress = string.IsNullOrEmpty(taskInfo.Context) ? new ImportProcessingProgress() : JsonConvert.DeserializeObject<ImportProcessingProgress>(taskInfo.Context); | ||
return new ImportProcessingTask( | ||
inputData, | ||
importProgress, | ||
_importResourceLoader, | ||
_resourceBulkImporter, | ||
_importErrorStoreFactory, | ||
contextUpdater, | ||
_contextAccessor, | ||
_loggerFactory); | ||
} | ||
|
||
if (taskInfo.TaskTypeId == ImportOrchestratorTask.ImportOrchestratorTaskId) | ||
{ | ||
IContextUpdater contextUpdater = _contextUpdaterFactory.CreateContextUpdater(taskInfo.TaskId, taskInfo.RunId); | ||
ImportOrchestratorTaskInputData inputData = JsonConvert.DeserializeObject<ImportOrchestratorTaskInputData>(taskInfo.InputData); | ||
ImportOrchestratorTaskContext orchestratorTaskProgress = string.IsNullOrEmpty(taskInfo.Context) ? new ImportOrchestratorTaskContext() : JsonConvert.DeserializeObject<ImportOrchestratorTaskContext>(taskInfo.Context); | ||
|
||
return new ImportOrchestratorTask( | ||
inputData, | ||
orchestratorTaskProgress, | ||
_taskmanager, | ||
_sequenceIdGenerator, | ||
contextUpdater, | ||
_contextAccessor, | ||
_importOrchestratorTaskDataStoreOperation, | ||
_integrationDataStoreClient, | ||
_loggerFactory); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.