From fead71fd128f36104b0134968abc28803bc4fd0d Mon Sep 17 00:00:00 2001 From: zsloan Date: Tue, 31 May 2022 20:59:09 +0000 Subject: Check if entered pubmed_id is already associated with a publication, and set PublishXRef.PublicationId equal to that Id if it exists --- wqflask/wqflask/metadata_edits.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/metadata_edits.py b/wqflask/wqflask/metadata_edits.py index cd5b7893..5a5ee4ac 100644 --- a/wqflask/wqflask/metadata_edits.py +++ b/wqflask/wqflask/metadata_edits.py @@ -339,12 +339,28 @@ def update_phenotype(dataset_id: str, name: str): } updated_publications = "" with database_connection() as conn: - updated_publications = update( - conn, - "Publication", - data=Publication(**publication_), - where=Publication(id_=data_.get("old_id_")), + + existing_publication = fetchone( + conn=conn, + table="Publication", + where=Publication(pubmed_id=data_.get("pubmed-id")) ) + + if existing_publication: + update( + conn, + "PublishXRef", + data=PublishXRef(publication_id=existing_publication.id_), + where=PublishXRef(id_=name, inbred_set_id=dataset_id) + ) + else: + updated_publications = update( + conn, + "Publication", + data=Publication(**publication_), + where=Publication(id_=data_.get("old_id_")), + ) + if updated_publications: diff_data.update( { -- cgit v1.2.3