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,23 @@ def populate_tables(request):
366367 return JsonResponse (response , status = status )
367368
368369
370+ def get_citations (request ):
371+ resp = { 'message' : 'error' , 'citations' : None }
372+ code = 400
373+ try :
374+ req = request .GET if request .method == 'GET' else request .POST
375+ dois = [uri_to_iri (x ) for x in req .getlist ("doi" , [])]
376+ cites = Citation .objects .filter (doi__in = dois )
377+ resp ['citations' ] = {x .doi : x .cite for x in cites }
378+ code = 200
379+ except Exception as e :
380+ logger .error ("[ERROR] While fetching citations: " )
381+ logger .exception (e )
382+ resp ['message' ] = "There was an error while attempting to fetch these citations."
383+ code = 500
384+ return JsonResponse (resp , status = code )
385+
386+
369387# Data exploration and cohort creation page
370388def explore_data_page (request , filter_path = False , path_filters = None ):
371389 context = {'request' : request }
@@ -377,8 +395,7 @@ def explore_data_page(request, filter_path=False, path_filters=None):
377395 request .session .create ()
378396
379397 try :
380- req = request .GET or request .POST
381-
398+ req = request .GET if request .method == 'GET' else request .POST
382399 is_dicofdic = (req .get ('is_dicofdic' , "False" ).lower () == "true" )
383400 source = req .get ('data_source_type' , DataSource .SOLR )
384401 versions = json .loads (req .get ('versions' , '[]' ))
@@ -428,6 +445,7 @@ def explore_data_page(request, filter_path=False, path_filters=None):
428445 collapse_on , is_json , uniques = uniques , totals = totals , with_stats = with_stats , disk_size = disk_size
429446 )
430447
448+ print (context .keys ())
431449 if not ('totals' in context ):
432450 context ['totals' ]= {}
433451 if not ('PatientID' in context ['totals' ]):
@@ -614,39 +632,10 @@ def cart_page(request):
614632 return render (request , 'collections/cart_list.html' , context )
615633
616634
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-
646635def cart_data (request ):
647636 status = 200
648637 response = {}
649- field_list = ['collection_id' , 'PatientID' , 'StudyInstanceUID' , 'SeriesInstanceUID' , 'aws_bucket' ]
638+ field_list = ['collection_id' , 'PatientID' , 'StudyInstanceUID' , 'SeriesInstanceUID' , 'aws_bucket' , "source_DOI" ]
650639 try :
651640 req = request .GET if request .GET else request .POST
652641 filtergrp_list = json .loads (req .get ('filtergrp_list' , '{}' ))
0 commit comments