about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-04-28 03:52:53 -0500
committerFrederick Muriuki Muriithi2025-04-28 03:52:53 -0500
commit031cfe6390188271a7e5bcc7db9d275197215f46 (patch)
tree2dabb66be572031591ec59aa49ef8974e246f8f7
parent60c6f059c3f62807f1a4520e3a0a9af940ebe4af (diff)
downloadgn-uploader-031cfe6390188271a7e5bcc7db9d275197215f46.tar.gz
Fetch phenotypes linked to a particular publication.
-rw-r--r--uploader/publications/models.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/uploader/publications/models.py b/uploader/publications/models.py
index 22690f8..7d2862d 100644
--- a/uploader/publications/models.py
+++ b/uploader/publications/models.py
@@ -88,3 +88,21 @@ def fetch_publication_by_id(conn: Connection, publication_id: int) -> dict:
         cursor.execute("SELECT * FROM Publication WHERE Id=%s",
                        (publication_id,))
         return dict(cursor.fetchone())
+
+
+def fetch_publication_phenotypes(
+        conn: Connection, publication_id: int) -> Iterable[dict]:
+    """Fetch all phenotypes linked to this publication."""
+    with conn.cursor(cursorclass=DictCursor) as cursor:
+        cursor.execute(
+            "SELECT pxr.Id AS xref_id, pxr.PublicationId, phe.* "
+            "FROM PublishXRef AS pxr INNER JOIN Phenotype AS phe "
+            "ON pxr.PhenotypeId=phe.Id "
+            "WHERE pxr.PublicationId=%s",
+            (publication_id,))
+        while True:
+            row = cursor.fetchone()
+            if row:
+                yield row
+            else:
+                break