From fe0c916a7c297d3b41adfb76d644568bfd453e62 Mon Sep 17 00:00:00 2001 From: Michele Mattioni Date: Tue, 28 Jun 2022 21:52:55 +0200 Subject: [PATCH] Added the function to retrieve the data as #11 from Include FHIR --- include_notebooks/include_helper.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 include_notebooks/include_helper.py diff --git a/include_notebooks/include_helper.py b/include_notebooks/include_helper.py new file mode 100644 index 0000000..80b02a9 --- /dev/null +++ b/include_notebooks/include_helper.py @@ -0,0 +1,27 @@ +import requests +import pandas as pd + +def query_fhir_include(include_cookie, query_statement="https://include-api-fhir-service.includedcc.org/DocumentReference?_tag=HTP&category=RNA-Seq&type=Gene-Expression,Gene-Expression-Quantifications&location:missing=false"): + + + req = requests.get(query_statement, cookies = {"AWSELBAuthSessionCookie-0" : include_cookie}) + req_j = req.json() + FHIR_SERVER_ROOT = "https://" + query_statement.split("//")[1].split('/')[0] + data = [] + for entry in req_j['entry']: + item = {} + item["document_reference_attachement_uri"] = entry['resource']['content'][0]['attachment']['url'] + item['drs_uri'] = entry['resource']['content'][0]['attachment']['url'] + item['document_reference_reference'] = entry['fullUrl'] + item['file_path'] = "" + item['specimen_bodySite'] = "" + item['condition_code'] = entry["resource"]['meta']['tag'][0]['code'] + item['filename'] = entry['resource']['content'][0]['attachment']['title'] + item['research_study_reference'] = entry["resource"]['meta']['tag'][0]['code'] + item['patience_reference'] = FHIR_SERVER_ROOT + "/" + entry["resource"]['subject']['reference'] + item['specimen_reference'] = FHIR_SERVER_ROOT + "/" + entry["resource"]['context']['related'][0]['reference'] + data.append(item) + df = pd.DataFrame(data) + df.set_index("document_reference_attachement_uri", inplace=True) + return df +