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

Standardize DICOMweb assetstore parameter names/style #1338

Merged
merged 8 commits into from
Oct 31, 2023
42 changes: 20 additions & 22 deletions sources/dicom/large_image_source_dicom/assetstore/rest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import json

from girder.api import access
from girder.api.describe import Description, describeRoute
from girder.api.rest import Resource, loadmodel
from girder.api.describe import Description, autoDescribeRoute
from girder.api.rest import Resource
from girder.constants import TokenScope
from girder.exceptions import RestException
from girder.models.assetstore import Assetstore
from girder.utility import assetstore_utilities
from girder.utility.model_importer import ModelImporter
from girder.utility.progress import ProgressContext
Expand All @@ -14,26 +15,24 @@
def __init__(self):
super().__init__()
self.resourceName = 'dicomweb_assetstore'
self.route('PUT', (':id', 'import'), self.importData)
self.route('POST', (':id', 'import'), self.importData)

def _importData(self, assetstore, params):
"""

:param assetstore: the destination assetstore.
:param params: a dictionary of parameters including parentId,
parentType, progress, and filters.
:param params: a dictionary of parameters including destinationId,
destinationType, progress, and filters.
"""
self.requireParams(('parentId'), params)

user = self.getCurrentUser()

parentType = params.get('parentType', 'folder')
if parentType not in ('folder', 'user', 'collection'):
msg = f'Invalid parentType: {parentType}'
destinationType = params.get('destinationType', 'folder')
if destinationType not in ('folder', 'user', 'collection'):
msg = f'Invalid destinationType: {destinationType}'

Check warning on line 31 in sources/dicom/large_image_source_dicom/assetstore/rest.py

View check run for this annotation

Codecov / codecov/patch

sources/dicom/large_image_source_dicom/assetstore/rest.py#L31

Added line #L31 was not covered by tests
raise RestException(msg)

parent = ModelImporter.model(parentType).load(params['parentId'], force=True,
exc=True)
parent = ModelImporter.model(destinationType).load(params['destinationId'], force=True,
exc=True)

limit = params.get('limit') or None
if limit is not None:
Expand Down Expand Up @@ -61,7 +60,7 @@
) as ctx:
items = adapter.importData(
parent,
parentType,
destinationType,
{
'limit': limit,
'search_filters': search_filters,
Expand All @@ -76,22 +75,21 @@
raise RestException(msg)

@access.admin(scope=TokenScope.DATA_WRITE)
@loadmodel(model='assetstore')
@describeRoute(
@autoDescribeRoute(
Description('Import references to DICOM objects from a DICOMweb server')
.param('id', 'The ID of the assetstore representing the DICOMweb server.',
paramType='path')
.param('parentId', 'The ID of the parent folder, collection, or user '
.modelParam('id', 'The ID of the assetstore representing the DICOMweb server.',
model=Assetstore)
.param('destinationId', 'The ID of the parent folder, collection, or user '
'in the Girder data hierarchy under which to import the files.')
.param('parentType', 'The type of the parent object to import into.',
.param('destinationType', 'The type of the parent object to import into.',
enum=('folder', 'user', 'collection'),
required=False)
required=True)
.param('limit', 'The maximum number of results to import.',
required=False, dataType='int')
.param('filters', 'Any search parameters to filter DICOM objects.',
required=False)
required=False, default={})
.param('progress', 'Whether to record progress on this operation ('
'default=False)', required=False, dataType='boolean')
'default=False)', required=False, default=False, dataType='boolean')
.errorResponse()
.errorResponse('You are not an administrator.', 403),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
AssetstoreModel.prototype.dicomwebImport = function (params) {
return restRequest({
url: 'dicomweb_assetstore/' + this.get('_id') + '/import',
type: 'PUT',
type: 'POST',

Check warning on line 10 in sources/dicom/large_image_source_dicom/web_client/models/AssetstoreModel.js

View check run for this annotation

Codecov / codecov/patch

sources/dicom/large_image_source_dicom/web_client/models/AssetstoreModel.js#L10

Added line #L10 was not covered by tests
data: params,
error: null
}).done(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
a.g-dwas-import-button.btn.btn-sm.btn-success(
href=`#dicomweb_assetstore/${assetstore.get('_id')}/import`,
title="Import references to DICOM objects from a DICOMweb server")
i.icon-link-ext
| Import
.g-assetstore-import-button-container
a.g-dwas-import-button.btn.btn-sm.btn-success(
href=`#dicomweb_assetstore/${assetstore.get('_id')}/import`,
title="Import references to DICOM objects from a DICOMweb server")
i.icon-link-ext
| Import data
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ const AssetstoreImportView = View.extend({
e.preventDefault();
this.$('.g-validation-failed-message').empty();

const parentType = this.$('#g-dwas-import-dest-type').val();
const parentId = this.$('#g-dwas-import-dest-id').val().trim().split(/\s/)[0];
const destinationType = this.$('#g-dwas-import-dest-type').val();
const destinationId = this.$('#g-dwas-import-dest-id').val().trim().split(/\s/)[0];
const filters = this.$('#g-dwas-import-filters').val().trim();
const limit = this.$('#g-dwas-import-limit').val().trim();

if (!parentId) {
if (!destinationId) {
this.$('.g-validation-failed-message').html('Invalid Destination ID');
return;
}

this.$('.g-submit-dwas-import').addClass('disabled');
this.model.off().on('g:imported', function () {
router.navigate(parentType + '/' + parentId, { trigger: true });
router.navigate(destinationType + '/' + destinationId, { trigger: true });
}, this).on('g:error', function (err) {
this.$('.g-submit-dwas-import').removeClass('disabled');
this.$('.g-validation-failed-message').html(err.responseJSON.message);
}, this).dicomwebImport({
parentId,
parentType,
destinationId,
destinationType,
limit,
filters,
progress: true
Expand Down
16 changes: 8 additions & 8 deletions sources/dicom/test_dicom/web_client_specs/dicomWebSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ describe('DICOMWeb assetstore', function () {
'Admin',
'adminpassword!'));
it('Create an assetstore and import data', function () {
var parentId;
var parentType;
var destinationId;
var destinationType;

// After importing, we will verify that this item exists
const verifyItemName = '1.3.6.1.4.1.5962.99.1.3510881361.982628633.1635598486609.2.0';
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('DICOMWeb assetstore', function () {
}, 'DICOMweb assetstore to be created');

runs(function () {
// Select the parentId and parentType
// Select the destinationId and destinationType
// Get the user ID
const resp = girder.rest.restRequest({
url: 'user',
Expand All @@ -77,8 +77,8 @@ describe('DICOMWeb assetstore', function () {
});

// Use the user's public folder
parentType = 'folder';
parentId = resp.responseJSON[0]._id;
destinationType = 'folder';
destinationId = resp.responseJSON[0]._id;
});

runs(function () {
Expand All @@ -103,16 +103,16 @@ describe('DICOMWeb assetstore', function () {

runs(function () {
// Set dest type and dest id
$('#g-dwas-import-dest-type').val(parentType);
$('#g-dwas-import-dest-id').val(parentId);
$('#g-dwas-import-dest-type').val(destinationType);
$('#g-dwas-import-dest-id').val(destinationId);
willdunklin marked this conversation as resolved.
Show resolved Hide resolved

// Test error for an invalid limit
$('#g-dwas-import-limit').val('1.3');
$('.g-submit-assetstore-import').trigger('click');
});

waitsFor(function () {
return $('.g-validation-failed-message').html() === 'Invalid limit';
return $('.g-validation-failed-message').html().includes('Invalid value');
}, 'Invalid limit check (float)');

runs(function () {
Expand Down