Skip to content

Commit fc370df

Browse files
authored
Merge pull request #428 from DigitalSlideArchive/status-endpoints
Add status endpoints
2 parents 01fd4df + 3c8889e commit fc370df

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

wsi_deid/rest.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ def __init__(self, apiRoot):
317317
self.route('PUT', ('action', 'bulkRefile'), self.refileItems)
318318
self.route('PUT', ('item', ':id', 'redactList'), self.setRedactList)
319319
self.route('GET', ('item', ':id', 'refileList'), self.getRefileList)
320+
self.route('GET', ('item', ':id', 'status'), self.itemStatus)
320321
self.route('GET', ('next_unprocessed_folders', ), self.nextUnprocessedFolders)
321322
self.route('GET', ('next_unprocessed_item', ), self.nextUnprocessedItem)
322323
self.route('GET', ('project_folder', ':id'), self.isProjectFolder)
@@ -325,6 +326,7 @@ def __init__(self, apiRoot):
325326
self.route('GET', ('settings',), self.getSettings)
326327
self.route('POST', ('matching', ), self.callMatchingAPI)
327328
self.route('POST', ('matching', 'wsi'), self.fakeMatchingAPI)
329+
self.route('GET', ('status', ), self.allItemStatus)
328330
self._item_find = apiRoot.item._find
329331

330332
@autoDescribeRoute(
@@ -989,6 +991,74 @@ def fakeMatchingAPI(self, match): # noqa
989991
return results
990992
return results
991993

994+
def _allItemStatus(self):
995+
project_folders = []
996+
results = {'folders': {}, 'items': {}}
997+
for key, val in ProjectFolders.items():
998+
if key == 'original':
999+
continue
1000+
projFolderId = Setting().get(val)
1001+
project_folders.append(ObjectId(projFolderId))
1002+
results['folders'][projFolderId] = {
1003+
'key': val,
1004+
'name': Folder().load(projFolderId, force=True)['name'],
1005+
'items': {}}
1006+
pipeline = [
1007+
{'$match': {'_id': {'$in': project_folders}}},
1008+
{'$graphLookup': {
1009+
'from': 'folder',
1010+
'startWith': '$_id',
1011+
'connectFromField': '_id',
1012+
'connectToField': 'parentId',
1013+
'as': 'descendants',
1014+
'restrictSearchWithMatch': {'parentCollection': 'folder'}}},
1015+
{'$project': {
1016+
'rootFolderId': '$_id', 'rootFolderName': '$name', 'allFolders': {
1017+
'$concatArrays': [
1018+
['$_id'],
1019+
{'$map': {'input': '$descendants', 'as': 'desc', 'in': '$$desc._id'}},
1020+
]}}},
1021+
{'$unwind': '$allFolders'},
1022+
{'$lookup': {
1023+
'from': 'item',
1024+
'localField': 'allFolders',
1025+
'foreignField': 'folderId',
1026+
'as': 'item'}},
1027+
{'$unwind': '$item'},
1028+
{'$project': {
1029+
'folderId': '$_id',
1030+
'folderName': '$name',
1031+
'itemId': '$item._id',
1032+
'itemName': '$item.name'}},
1033+
]
1034+
1035+
for entry in Folder().collection.aggregate(pipeline):
1036+
results['folders'][str(entry['folderId'])]['items'][
1037+
str(entry['itemId'])] = {'name': entry['itemName']}
1038+
results['items'][str(entry['itemId'])] = {
1039+
'folder': results['folders'][str(entry['folderId'])]['key'],
1040+
'name': entry['itemName'],
1041+
}
1042+
return results
1043+
1044+
@autoDescribeRoute(
1045+
Description('Get the status of all tracked items in wsi_deid folders')
1046+
.errorResponse(),
1047+
)
1048+
@access.admin
1049+
def allItemStatus(self):
1050+
return self._allItemStatus()
1051+
1052+
@autoDescribeRoute(
1053+
Description('Get the status of a tracked item.')
1054+
.modelParam('id', model=Item, level=AccessType.READ)
1055+
.errorResponse(),
1056+
)
1057+
@access.admin
1058+
def itemStatus(self, item):
1059+
results = self._allItemStatus()
1060+
return results['items'].get(str(item['_id']), None)
1061+
9921062

9931063
def addSystemEndpoints(apiRoot):
9941064
"""

0 commit comments

Comments
 (0)