-
Notifications
You must be signed in to change notification settings - Fork 401
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
Export API for a system level export returning one resource per resource type #2005
Export API for a system level export returning one resource per resource type #2005
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
while (hasMore) { | ||
const bundle = await repo.search({ | ||
resourceType, | ||
count: 1000, | ||
offset, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addresses infinite loop when there are more than 1000 resources for a resource type
for (const entry of bundle.entry) { | ||
if (entry.resource?.id) { | ||
writes.push(exporter.writeResource(entry.resource)); | ||
await exporter.writeResource(entry.resource); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removing using 'Promise.all'. Each time export.writeResource was called this.writers
was always {}
. A new writer for each resourceType was always being created at
const binary = await this.repo.createResource<Binary>({ |
@@ -34,7 +34,7 @@ export async function bulkExportHandler(req: Request, res: Response): Promise<vo | |||
if (!canBeExported(resourceType) || (types && !types.includes(resourceType))) { | |||
continue; | |||
} | |||
await exportResourceType(exporter, project, resourceType as ResourceType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
project
was unused
@@ -44,30 +44,40 @@ export async function bulkExportHandler(req: Request, res: Response): Promise<vo | |||
res.set('Content-Location', `${baseUrl}fhir/R4/bulkdata/export/${bulkDataExport.id}`).status(202).json(accepted); | |||
} | |||
|
|||
async function exportResourceType(exporter: BulkExporter, project: Project, resourceType: ResourceType): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
project
was unused
@@ -44,30 +44,40 @@ export async function bulkExportHandler(req: Request, res: Response): Promise<vo | |||
res.set('Content-Location', `${baseUrl}fhir/R4/bulkdata/export/${bulkDataExport.id}`).status(202).json(accepted); | |||
} | |||
|
|||
async function exportResourceType(exporter: BulkExporter, project: Project, resourceType: ResourceType): Promise<void> { | |||
export async function exportResourceType( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding export
and param maxResources
to unit test pagination.
This reverts commit 5c37862.
Kudos, SonarCloud Quality Gate passed! |
fixes export returning one resource per resource type and fixes infinite loop when there are greater than 1000 resources for a resource type
🤖 Generated by Copilot at 5c37862
Summary
🆕🐛📄
Enhanced the bulk export operation to support pagination and resource limits, and added tests to verify the functionality. Fixed a bug in
exportResourceType
that affected the output files.Walkthrough
exportResourceType
function to accept amaxResources
parameter and anoffset
variable, and to iterate through paginated search results by following thenext
link in the search bundle (link, link)exportResourceType
function that caused some resources to be skipped or written to the wrong file by calling thegetWriter
function on the exporter before writing each resource (link)project
parameter from theexportResourceType
function call in thebulkExportHandler
function (link)export.test.ts
file to test the functionality of exporting multiple resources by resource type and iterating through paginated search results, using therequest
,waitFor
, andexpect
libraries, and theinitTestAuth
,createTestProject
, andcreateReference
functions (link)Observation
andPatient
types from@medplum/fhirtypes
, and thesystemRepo
,exportResourceType
,BulkExporter
, andcreateReference
functions from their respective modules, to be used in the new test cases (link, link)export.ts
file to match the order of the imports in theexport.test.ts
file, for consistency and readability (link)