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
@@ -76,7 +77,8 @@ def landing_page(request):
7677 "Testicles" : "Testis" ,
7778 "Adrenal Glands" : "Adrenal Gland" ,
7879 "Adrenal" : "Adrenal Gland" ,
79- "Lymph Node" : "Lymph Nodes"
80+ "Lymph Node" : "Lymph Nodes" ,
81+ "Bone Marrow" : "Blood"
8082 }
8183
8284 skip = [
@@ -91,7 +93,9 @@ def landing_page(request):
9193 "Chest-Abdomen-Pelvis, Leg, TSpine" ,
9294 "Abdomen, Arm, Bladder, Chest, Head-Neck, Kidney, Leg, Retroperitoneum, Stomach, Uterus" ,
9395 "Blood, Bone" ,
94- "Esophagus, Lung, Pancreas, Thymus"
96+ "Esophagus, Lung, Pancreas, Thymus" ,
97+ "Esophagus, Head-Neck, Lung, Pancreas, Rectum, Thymus" ,
98+ "Arm, Bladder, Buttock, Colon, Liver, Myometrium, Pancreas, Rectum, Shoulder, Scapula"
9599 ]
96100
97101 for collection in collex :
@@ -363,6 +367,27 @@ def populate_tables(request):
363367 return JsonResponse (response , status = status )
364368
365369
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+
366391# Data exploration and cohort creation page
367392def explore_data_page (request , filter_path = False , path_filters = None ):
368393 context = {'request' : request }
@@ -374,8 +399,7 @@ def explore_data_page(request, filter_path=False, path_filters=None):
374399 request .session .create ()
375400
376401 try :
377- req = request .GET or request .POST
378-
402+ req = request .GET if request .method == 'GET' else request .POST
379403 is_dicofdic = (req .get ('is_dicofdic' , "False" ).lower () == "true" )
380404 source = req .get ('data_source_type' , DataSource .SOLR )
381405 versions = json .loads (req .get ('versions' , '[]' ))
@@ -425,6 +449,7 @@ def explore_data_page(request, filter_path=False, path_filters=None):
425449 collapse_on , is_json , uniques = uniques , totals = totals , with_stats = with_stats , disk_size = disk_size
426450 )
427451
452+ print (context .keys ())
428453 if not ('totals' in context ):
429454 context ['totals' ]= {}
430455 if not ('PatientID' in context ['totals' ]):
@@ -611,39 +636,10 @@ def cart_page(request):
611636 return render (request , 'collections/cart_list.html' , context )
612637
613638
614- def cart_data_stats (request ):
615- status = 200
616- response = {}
617- field_list = ['collection_id' , 'PatientID' , 'StudyInstanceUID' , 'SeriesInstanceUID' , 'aws_bucket' ]
618- try :
619-
620- req = request .GET if request .GET else request .POST
621- current_filters = json .loads (req .get ('filters' , '{}' ))
622- filtergrp_list = json .loads (req .get ('filtergrp_list' , '{}' ))
623- aggregate_level = req .get ('aggregate_level' , 'StudyInstanceUID' )
624- results_level = req .get ('results_level' , 'StudyInstanceUID' )
625-
626- partitions = json .loads (req .get ('partitions' , '{}' ))
627-
628- limit = int (req .get ('limit' , 1000 ))
629- offset = int (req .get ('offset' , 0 ))
630- length = int (req .get ('length' , 100 ))
631- mxseries = int (req .get ('mxseries' ,1000 ))
632-
633- response = get_cart_and_filterset_stats (current_filters ,filtergrp_list , partitions , limit , offset , length , mxseries , results_lvl = results_level )
634-
635- except Exception as e :
636- logger .error ("[ERROR] While loading cart:" )
637- logger .exception (e )
638- status = 400
639-
640- return JsonResponse (response , status = status )
641-
642-
643639def cart_data (request ):
644640 status = 200
645641 response = {}
646- field_list = ['collection_id' , 'PatientID' , 'StudyInstanceUID' , 'SeriesInstanceUID' , 'aws_bucket' ]
642+ field_list = ['collection_id' , 'PatientID' , 'StudyInstanceUID' , 'SeriesInstanceUID' , 'aws_bucket' , "source_DOI" ]
647643 try :
648644 req = request .GET if request .GET else request .POST
649645 filtergrp_list = json .loads (req .get ('filtergrp_list' , '{}' ))
0 commit comments