aboutsummaryrefslogtreecommitdiff
path: root/uploader/publications/models.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-04-14 12:33:27 -0500
committerFrederick Muriuki Muriithi2025-04-14 12:33:27 -0500
commit49f1b2fa06da54d2f839ef6d4ca3061b92883417 (patch)
tree5125af311d32dcee37cf601f39eee0b528db1861 /uploader/publications/models.py
parent386e3e70de5bad8db03b83d91f08fcfb3faa1d05 (diff)
downloadgn-uploader-49f1b2fa06da54d2f839ef6d4ca3061b92883417.tar.gz
Update existing linked publication(s) rather than creating new.
Diffstat (limited to 'uploader/publications/models.py')
-rw-r--r--uploader/publications/models.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/uploader/publications/models.py b/uploader/publications/models.py
index 37c1df6..3fc9542 100644
--- a/uploader/publications/models.py
+++ b/uploader/publications/models.py
@@ -1,7 +1,11 @@
"""Module to handle persistence and retrieval of publication to/from MariaDB"""
+import logging
+
from MySQLdb.cursors import DictCursor
-from gn_libs.mysqldb import Connection
+from gn_libs.mysqldb import Connection, debug_query
+
+logger = logging.getLogger(__name__)
def fetch_phenotype_publications(
@@ -48,3 +52,22 @@ def create_new_publications(
**row, "PublicationId": row["Id"]
} for row in cursor.fetchall())
return tuple()
+
+
+def update_publications(conn: Connection , publications: tuple[dict, ...]) -> tuple[dict, ...]:
+ """Update details for multiple publications"""
+ if len(publications) > 0:
+ with conn.cursor(cursorclass=DictCursor) as cursor:
+ logger.debug("UPDATING PUBLICATIONS: %s", publications)
+ cursor.executemany(
+ ("UPDATE Publication SET "
+ "PubMed_ID=%(pubmed_id)s, Abstract=%(abstract)s, "
+ "Authors=%(authors)s, Title=%(title)s, Journal=%(journal)s, "
+ "Volume=%(volume)s, Pages=%(pages)s, Month=%(month)s, "
+ "Year=%(year)s "
+ "WHERE Id=%(publication_id)s"),
+ publications)
+ debug_query(cursor, logger)
+ return publications
+ return tuple()
+ return tuple()