From 9809144df12558d37d4b4d8ef10e0f854976b085 Mon Sep 17 00:00:00 2001 From: Ivo Leist Date: Thu, 31 Aug 2023 19:14:21 +0200 Subject: [PATCH] proof of concept: mouse-over shows ontology id --- .vscode/settings.json | 14 ++++++- .../components/dataGrid/CopyOnClick.jsx | 25 ++++++++--- convertPheno_server/server/apis/clinical.py | 41 +++++++++++++++++-- 3 files changed, 71 insertions(+), 9 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index f18bbb77..54245b7c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,5 +16,17 @@ "**/.git/objects/**": true, "**/.git/subtree-cache/**": true, "**/node_modules/*/**": true - } + }, + "sqltools.connections": [ + { + "previewLimit": 50, + "server": "10.10.0.3", + "port": 5432, + "driver": "PostgreSQL", + "name": "CP", + "password": "postgres", + "database": "postgres", + "username": "postgres" + } + ] } diff --git a/convertPheno_client/src/code/views/conversion/ components/clinicalData/components/dataGrid/CopyOnClick.jsx b/convertPheno_client/src/code/views/conversion/ components/clinicalData/components/dataGrid/CopyOnClick.jsx index 7f84a6c1..7edd2cc1 100644 --- a/convertPheno_client/src/code/views/conversion/ components/clinicalData/components/dataGrid/CopyOnClick.jsx +++ b/convertPheno_client/src/code/views/conversion/ components/clinicalData/components/dataGrid/CopyOnClick.jsx @@ -50,6 +50,16 @@ const getValue = (props) => { ? data[field]["values"] : []; + const urls = + data[field] && Array.isArray(data[field]["urls"]) + ? data[field]["urls"] + : []; + + const ontology_ids = + data[field] && Array.isArray(data[field]["ontology_ids"]) + ? data[field]["ontology_ids"] + : []; + return checkKeyExists(data[field], "count") ? ( { }} > {values.map((value, index) => ( - + ))} ) : ( @@ -69,7 +84,7 @@ const getValue = (props) => { ); }; -const ValueWithTooltip = ({ value }) => { +const ValueWithTooltip = ({ value, ontology_id, url }) => { const [isTooltipOpen, setIsTooltipOpen] = useState(false); const tooltipTimeout = useRef({ current: null }); @@ -86,7 +101,7 @@ const ValueWithTooltip = ({ value }) => { const handleLinkClick = () => { clearTimeout(tooltipTimeout.current); - window.open(`https://google.com`, "_blank"); + window.open(url, "_blank"); }; return ( @@ -96,12 +111,12 @@ const ValueWithTooltip = ({ value }) => { Click to open{" "} - {value} link + {ontology_id} } diff --git a/convertPheno_server/server/apis/clinical.py b/convertPheno_server/server/apis/clinical.py index c732f6d9..db1a4b4b 100644 --- a/convertPheno_server/server/apis/clinical.py +++ b/convertPheno_server/server/apis/clinical.py @@ -170,6 +170,26 @@ def recursive_search(dictionary, key): return None +def generate_url(ontology_id): + if ( + ontology_id is not None + and "NCIT" in ontology_id + and ontology_id != "NCIT:NA0000" + ): + ont_query = ontology_id.split(":")[1] + + # TODO + # The NCIT base url should be in a config file + + ncit_base = "https://ncit.nci.nih.gov/ncitbrowser/ConceptReport.jsp" + ncit_query = f"?dictionary=NCI_Thesaurus&code={ont_query}" + ncit_url = f"{ncit_base}{ncit_query}" + + return ncit_url + + return "NA" + + def parse_meta_info(meta, field): """ Parse the meta info from the json array @@ -177,14 +197,22 @@ def parse_meta_info(meta, field): data = [] nested_info = ["value", "status"] values = [] + ontology_ids = [] + urls = [] for meta_data in meta: meta_row = {} for key in meta_data: if isinstance(meta_data[key], dict): value = recursive_search(meta_data[key], "label") + ontology_id = recursive_search(meta_data[key], "id") + ncit_url = generate_url(ontology_id) + meta_row[key] = value if key == field[0] or key in field[0]: values.append(value) + ontology_ids.append(ontology_id) + urls.append(ncit_url) + for info in nested_info: nested_info_val = recursive_search(meta_data[key], info) if nested_info_val is not None: @@ -192,7 +220,7 @@ def parse_meta_info(meta, field): else: meta_row[key] = meta_data[key] data.append(meta_row) - return data, values + return data, values, ontology_ids, urls def catch_errors(func): @@ -231,8 +259,14 @@ def get_basic_row(row, key, selected_fields): row_data[key] = row[key] return row_data - data, values = parse_meta_info(row[key], selected_fields[key]) - row_data[key] = {"data": data, "count": len(row[key]), "values": values} + data, values, ontology_ids, urls = parse_meta_info(row[key], selected_fields[key]) + row_data[key] = { + "data": data, + "count": len(row[key]), + "values": values, + "ontology_ids": ontology_ids, + "urls": urls, + } return row_data @@ -559,6 +593,7 @@ def post(self, userid): "shownColumns": selected_cols, "nodeToSelected": node_to_selected, } + # print(response) return make_response(response)