3939from cohorts .models import Cohort , Cohort_Perms
4040
4141from idc_collections .models import Program , DataSource , Collection , ImagingDataCommonsVersion , Attribute , Attribute_Tooltips , DataSetType , Citation
42- from 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
42+ from idc_collections .collex_metadata_utils import (build_explorer_context , get_collex_metadata , create_file_manifest ,
43+ get_cart_data_serieslvl , get_cart_data_studylvl ,
44+ get_table_data_with_cart_data , cart_manifest )
4345from allauth .socialaccount .models import SocialAccount
4446from django .core .exceptions import ObjectDoesNotExist
4547from django .http import HttpResponse , JsonResponse
4850from idc .models import User_Data
4951from solr_helpers import build_solr_query , query_solr_and_format_result
5052
51-
53+ from idc . settings import MAX_FILE_LIST_REQUEST
5254
5355debug = settings .DEBUG
5456logger = logging .getLogger (__name__ )
@@ -678,35 +680,48 @@ def cart_data(request):
678680 return JsonResponse (response , status = status )
679681
680682
681- def get_series (request , collection_id , patient_id = None , study_uid = None ):
683+ def get_series (request , collection_id = None , patient_id = None , study_uid = None ):
684+ status = 200
685+ response = {"result" : []}
682686 try :
683- status = 200
684- response = { "result" : [] }
685- source = ImagingDataCommonsVersion .objects .get (active = True ).get_data_sources (
686- active = True , source_type = DataSource .SOLR ,
687- aggregate_level = "SeriesInstanceUID"
688- ).first ()
689- filters = {
690- "collection_id" : [collection_id ]
691- }
692- if patient_id :
693- filters ['PatientID' ] = [patient_id ]
694- if study_uid :
695- filters ["StudyInstanceUID" ] = [study_uid ]
696- filter_query = build_solr_query (
697- filters ,
698- with_tags_for_ex = False ,
699- search_child_records_by = None , solr_default_op = 'AND'
700- )
701- result = query_solr_and_format_result (
702- {
703- "collection" : source .name ,
704- "fields" : ["collection_id" , "PatientID" , "StudyInstanceUID" , "Modality" , "crdc_series_uuid" , "SeriesInstanceUID" , "aws_bucket" , "instance_size" ],
705- "query_string" : None ,
706- "fqs" : [filter_query ['full_query_str' ]],
707- "facets" : None , "sort" : None , "counts_only" : False , "limit" : 2000
687+ fields = ["collection_id" , "PatientID" , "StudyInstanceUID" , "Modality" , "crdc_series_uuid" , "SeriesInstanceUID" , "aws_bucket" , "instance_size" ]
688+ result = {}
689+ if not collection_id :
690+ # This is a request for filters and/or a cart
691+ body_unicode = request .body .decode ('utf-8' )
692+ body = json .loads (body_unicode )
693+ partitions = body .get ("partitions" , {})
694+ filtergrp_list = body .get ("filtergrp_list" , {})
695+ if not (len (partitions ) or len (filtergrp_list )):
696+ raise Exception ("You can only request series IDs based on a filter, collection ID, Patient ID, or study ID!" )
697+ result = cart_manifest (filtergrp_list , partitions , 0 , fields , MAX_FILE_LIST_REQUEST )
698+ else :
699+ source = ImagingDataCommonsVersion .objects .get (active = True ).get_data_sources (
700+ active = True , source_type = DataSource .SOLR ,
701+ aggregate_level = "SeriesInstanceUID"
702+ ).first ()
703+ filters = {
704+ "collection_id" : [collection_id ]
708705 }
709- )
706+ if patient_id :
707+ filters ['PatientID' ] = [patient_id ]
708+ if study_uid :
709+ filters ["StudyInstanceUID" ] = [study_uid ]
710+ filter_query = build_solr_query (
711+ filters ,
712+ with_tags_for_ex = False ,
713+ search_child_records_by = None , solr_default_op = 'AND'
714+ )
715+ result = query_solr_and_format_result (
716+ {
717+ "collection" : source .name ,
718+ "fields" : fields ,
719+ "query_string" : None ,
720+ "fqs" : [filter_query ['full_query_str' ]],
721+ "facets" : None , "sort" : None , "counts_only" : False , "limit" : 2000
722+ }
723+ )
724+
710725 for doc in result ['docs' ]:
711726 response ['result' ].append ({
712727 "series_id" : doc ['SeriesInstanceUID' ],
@@ -716,7 +731,7 @@ def get_series(request, collection_id, patient_id=None, study_uid=None):
716731 "modality" : doc ['Modality' ][0 ],
717732 "study_id" : doc ['StudyInstanceUID' ],
718733 "patient_id" : doc ["PatientID" ],
719- "collection_id" : doc ['collection_id' ]
734+ "collection_id" : doc ['collection_id' ][ 0 ]
720735 })
721736
722737 except Exception as e :
0 commit comments