Skip to content

Commit

Permalink
Merge pull request #1353 from willdunklin/amend-dicomweb-assetstore
Browse files Browse the repository at this point in the history
Add progress context to dicomWEB assetstore _importData
  • Loading branch information
manthey authored Nov 2, 2023
2 parents 8460ef7 + 9bf13e4 commit bc3cbec
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions sources/dicom/large_image_source_dicom/assetstore/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self):
self.resourceName = 'dicomweb_assetstore'
self.route('POST', (':id', 'import'), self.importData)

def _importData(self, assetstore, params):
def _importData(self, assetstore, params, progress):
"""
:param assetstore: the destination assetstore.
Expand Down Expand Up @@ -51,28 +51,22 @@ def _importData(self, assetstore, params):
msg = f'Invalid filters: {e}'
raise RestException(msg)

progress = self.boolParam('progress', params, default=False)

adapter = assetstore_utilities.getAssetstoreAdapter(assetstore)
items = adapter.importData(
parent,
destinationType,
{
'limit': limit,
'search_filters': search_filters,
'auth': None,
},
progress,
user,
)

with ProgressContext(
progress, user=user, title='Importing DICOM references',
) as ctx:
items = adapter.importData(
parent,
destinationType,
{
'limit': limit,
'search_filters': search_filters,
'auth': None,
},
ctx,
user,
)

if not items:
msg = 'No DICOM objects matching the search filters were found'
raise RestException(msg)
if not items:
msg = 'No DICOM objects matching the search filters were found'
raise RestException(msg)

@access.admin(scope=TokenScope.DATA_WRITE)
@autoDescribeRoute(
Expand All @@ -87,11 +81,21 @@ def _importData(self, assetstore, params):
.param('limit', 'The maximum number of results to import.',
required=False, dataType='int')
.param('filters', 'Any search parameters to filter DICOM objects.',
required=False, default={})
.param('progress', 'Whether to record progress on this operation ('
'default=False)', required=False, default=False, dataType='boolean')
required=False, default='{}')
.param('progress', 'Whether to record progress on this operation.',
required=False, default=False, dataType='boolean')
.errorResponse()
.errorResponse('You are not an administrator.', 403),
)
def importData(self, assetstore, params):
return self._importData(assetstore, params)
def importData(self, assetstore, destinationId, destinationType, limit, filters, progress):
user = self.getCurrentUser()

with ProgressContext(
progress, user=user, title='Importing DICOM references',
) as ctx:
return self._importData(assetstore, params={
'destinationId': destinationId,
'destinationType': destinationType,
'limit': limit,
'filters': filters,
}, progress=ctx)

0 comments on commit bc3cbec

Please sign in to comment.