From 8db90d44525c3bd53a616c4d986114d7d00086ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oriol=20L=C3=B3pez-Doriga?= Date: Tue, 26 Mar 2024 18:47:50 +0100 Subject: [PATCH] bug fixed in biosample cross query --- beacon/db/filters.py | 76 +++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/beacon/db/filters.py b/beacon/db/filters.py index 3d843559..1ccb4bac 100644 --- a/beacon/db/filters.py +++ b/beacon/db/filters.py @@ -29,16 +29,15 @@ def cross_query(query: dict, scope: str, collection: str, request_parameters: di original_id="biosampleId" def_list=[] for iditem in biosample_ids: - for id_item in iditem['caseLevelData']: - if isinstance(id_item, dict): - if id_item != {}: - new_id={} - new_id[final_id] = id_item[original_id] - try: - #LOG.debug(new_id) - subquery['$or'].append(new_id) - except Exception: - def_list.append(new_id) + if isinstance(iditem, dict): + if iditem != {}: + new_id={} + new_id[final_id] = id_item['caseLevelData'][original_id] + try: + #LOG.debug(new_id) + subquery['$or'].append(new_id) + except Exception: + def_list.append(new_id) LOG.debug(subquery) mongo_collection=client.beacon.biosamples @@ -100,16 +99,15 @@ def cross_query(query: dict, scope: str, collection: str, request_parameters: di original_id="biosampleId" def_list=[] for iditem in biosample_ids: - for id_item in iditem['caseLevelData']: - if isinstance(id_item, dict): - if id_item != {}: - new_id={} - new_id[final_id] = id_item[original_id] - try: - #LOG.debug(new_id) - query['$or'].append(new_id) - except Exception: - def_list.append(new_id) + if isinstance(iditem, dict): + if iditem != {}: + new_id={} + new_id[final_id] = id_item['caseLevelData'][original_id] + try: + #LOG.debug(new_id) + query['$or'].append(new_id) + except Exception: + def_list.append(new_id) if def_list != []: try: query['$or'].def_list @@ -142,16 +140,15 @@ def cross_query(query: dict, scope: str, collection: str, request_parameters: di original_id="biosampleId" def_list=[] for iditem in biosample_ids: - for id_item in iditem['caseLevelData']: - if isinstance(id_item, dict): - if id_item != {}: - new_id={} - new_id[final_id] = id_item[original_id] - try: - #LOG.debug(new_id) - query['$or'].append(new_id) - except Exception: - def_list.append(new_id) + if isinstance(iditem, dict): + if iditem != {}: + new_id={} + new_id[final_id] = id_item['caseLevelData'][original_id] + try: + #LOG.debug(new_id) + query['$or'].append(new_id) + except Exception: + def_list.append(new_id) if def_list != []: try: query['$or'].def_list @@ -333,16 +330,15 @@ def apply_filters(query: dict, filters: List[dict], collection: str, query_param def_list=[] partial_query['$or']=[] for iditem in biosample_ids: - for id_item in iditem['caseLevelData']: - if isinstance(id_item, dict): - if id_item != {}: - new_id={} - new_id[final_id] = id_item[original_id] - try: - #LOG.debug(new_id) - partial_query['$or'].append(new_id) - except Exception: - def_list.append(new_id) + if isinstance(iditem, dict): + if iditem != {}: + new_id={} + new_id[final_id] = id_item['caseLevelData'][original_id] + try: + #LOG.debug(new_id) + partial_query['$or'].append(new_id) + except Exception: + def_list.append(new_id) LOG.debug(partial_query) mongo_collection=client.beacon.biosamples