From 0ec1b2b852107ea915e0268074c3d5286b939337 Mon Sep 17 00:00:00 2001 From: Daniel Paseltiner <99684231+DanPaseltiner@users.noreply.github.com> Date: Wed, 17 May 2023 14:12:14 -0400 Subject: [PATCH] Log a warning for duplicate patients instead of failing (#581) * Handle empty lists when flattening blocks. * Modify test data for unit coverage on these changes. * Add error handling for patient ID uniqueness. --- phdi/linkage/postgres.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index ab4a4c48ec..dcff1656bd 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -4,6 +4,7 @@ from psycopg2.sql import Identifier, SQL from psycopg2.extensions import connection, cursor import json +import logging class DIBBsConnectorClient(BaseMPIConnectorClient): @@ -160,7 +161,13 @@ def insert_match_patient( person_id, json.dumps(patient_resource), ] - db_cursor.execute(insert_new_patient, data) + try: + db_cursor.execute(insert_new_patient, data) + except psycopg2.errors.UniqueViolation: + logging.warning( + f"Patient with ID {patient_resource.get('id')} already " + "exists in the MPI. The patient table was not updated." + ) except Exception as error: # pragma: no cover raise ValueError(f"{error}")