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}")