aboutsummaryrefslogtreecommitdiff
path: root/uploader/publications/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'uploader/publications/models.py')
-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