From 8ab276d489c121c9f53bf9b55e20188acb744ea3 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 21 Jul 2023 08:36:44 +0300 Subject: Fetch a publication by its PubMed ID --- gn3/db/phenotypes.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gn3') diff --git a/gn3/db/phenotypes.py b/gn3/db/phenotypes.py index a908c41..009dc1a 100644 --- a/gn3/db/phenotypes.py +++ b/gn3/db/phenotypes.py @@ -141,3 +141,13 @@ def fetch_publication_by_id(conn: DBConnection, publication_id: int) -> dict: "WHERE Id=%(publication_id)s"), {"publication_id": publication_id}) return cursor.fetchone() + +def fetch_publication_by_pubmed_id(conn: DBConnection, pubmed_id: int) -> dict: + """Fetch the publication by its PUBMED ID.""" + with conn.cursor(cursorclass=DictCursor) as cursor: + cols = ', '.join(mapping_to_query_columns(publication_mapping)) + cursor.execute( + (f"SELECT Id as id, {cols} FROM Publication " + "WHERE PubMed_Id=%(pubmed_id)s"), + {"pubmed_id": pubmed_id}) + return cursor.fetchone() -- cgit v1.2.3