3232from django .urls import reverse
3333from django .contrib import messages
3434from django .utils .html import escape
35+ from django .utils .encoding import uri_to_iri
3536
3637from google_helpers .stackdriver import StackDriverLogger
3738from cohorts .models import Cohort , Cohort_Perms
3839
39- from idc_collections .models import Program , DataSource , Collection , ImagingDataCommonsVersion , Attribute , Attribute_Tooltips , DataSetType
40+ from idc_collections .models import Program , DataSource , Collection , ImagingDataCommonsVersion , Attribute , Attribute_Tooltips , DataSetType , Citation
4041from idc_collections .collex_metadata_utils import build_explorer_context , get_collex_metadata , create_file_manifest , get_cart_data_serieslvl , get_cart_data_studylvl , get_table_data_with_cart_data
4142from allauth .socialaccount .models import SocialAccount
4243from django .core .exceptions import ObjectDoesNotExist
@@ -366,6 +367,27 @@ def populate_tables(request):
366367 return JsonResponse (response , status = status )
367368
368369
370+ def get_citations (request ):
371+ resp = { 'message' : 'error' , 'citations' : None }
372+ try :
373+ req = request .GET if request .method == 'GET' else request .POST
374+ if request .method == 'GET' :
375+ dois = [uri_to_iri (x ) for x in req .getlist ("doi" , [])]
376+ else :
377+ body_unicode = request .body .decode ('utf-8' )
378+ body = json .loads (body_unicode )
379+ dois = body .get ("doi" , [])
380+ cites = Citation .objects .filter (doi__in = dois )
381+ resp ['citations' ] = {x .doi : x .cite for x in cites }
382+ code = 200
383+ except Exception as e :
384+ logger .error ("[ERROR] While fetching citations: " )
385+ logger .exception (e )
386+ resp ['message' ] = "There was an error while attempting to fetch these citations."
387+ code = 500
388+ return JsonResponse (resp , status = code )
389+
390+
369391# Data exploration and cohort creation page
370392def explore_data_page (request , filter_path = False , path_filters = None ):
371393 context = {'request' : request }
@@ -377,8 +399,7 @@ def explore_data_page(request, filter_path=False, path_filters=None):
377399 request .session .create ()
378400
379401 try :
380- req = request .GET or request .POST
381-
402+ req = request .GET if request .method == 'GET' else request .POST
382403 is_dicofdic = (req .get ('is_dicofdic' , "False" ).lower () == "true" )
383404 source = req .get ('data_source_type' , DataSource .SOLR )
384405 versions = json .loads (req .get ('versions' , '[]' ))
@@ -428,6 +449,7 @@ def explore_data_page(request, filter_path=False, path_filters=None):
428449 collapse_on , is_json , uniques = uniques , totals = totals , with_stats = with_stats , disk_size = disk_size
429450 )
430451
452+ print (context .keys ())
431453 if not ('totals' in context ):
432454 context ['totals' ]= {}
433455 if not ('PatientID' in context ['totals' ]):
@@ -614,39 +636,10 @@ def cart_page(request):
614636 return render (request , 'collections/cart_list.html' , context )
615637
616638
617- def cart_data_stats (request ):
618- status = 200
619- response = {}
620- field_list = ['collection_id' , 'PatientID' , 'StudyInstanceUID' , 'SeriesInstanceUID' , 'aws_bucket' ]
621- try :
622-
623- req = request .GET if request .GET else request .POST
624- current_filters = json .loads (req .get ('filters' , '{}' ))
625- filtergrp_list = json .loads (req .get ('filtergrp_list' , '{}' ))
626- aggregate_level = req .get ('aggregate_level' , 'StudyInstanceUID' )
627- results_level = req .get ('results_level' , 'StudyInstanceUID' )
628-
629- partitions = json .loads (req .get ('partitions' , '{}' ))
630-
631- limit = int (req .get ('limit' , 1000 ))
632- offset = int (req .get ('offset' , 0 ))
633- length = int (req .get ('length' , 100 ))
634- mxseries = int (req .get ('mxseries' ,1000 ))
635-
636- response = get_cart_and_filterset_stats (current_filters ,filtergrp_list , partitions , limit , offset , length , mxseries , results_lvl = results_level )
637-
638- except Exception as e :
639- logger .error ("[ERROR] While loading cart:" )
640- logger .exception (e )
641- status = 400
642-
643- return JsonResponse (response , status = status )
644-
645-
646639def cart_data (request ):
647640 status = 200
648641 response = {}
649- field_list = ['collection_id' , 'PatientID' , 'StudyInstanceUID' , 'SeriesInstanceUID' , 'aws_bucket' ]
642+ field_list = ['collection_id' , 'PatientID' , 'StudyInstanceUID' , 'SeriesInstanceUID' , 'aws_bucket' , "source_DOI" ]
650643 try :
651644 req = request .GET if request .GET else request .POST
652645 filtergrp_list = json .loads (req .get ('filtergrp_list' , '{}' ))
0 commit comments