From 031cfe6390188271a7e5bcc7db9d275197215f46 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 28 Apr 2025 03:52:53 -0500 Subject: Fetch phenotypes linked to a particular publication. --- uploader/publications/models.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 -- cgit v1.2.3