Skip to content

Commit

Permalink
Log a warning for duplicate patients instead of failing (#581)
Browse files Browse the repository at this point in the history
* Handle empty lists when flattening blocks.

* Modify test data for unit coverage on these changes.

* Add error handling for patient ID uniqueness.
  • Loading branch information
DanPaseltiner authored May 17, 2023
1 parent 7bfba5e commit 0ec1b2b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion phdi/linkage/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from psycopg2.sql import Identifier, SQL
from psycopg2.extensions import connection, cursor
import json
import logging


class DIBBsConnectorClient(BaseMPIConnectorClient):
Expand Down Expand Up @@ -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}")
Expand Down

0 comments on commit 0ec1b2b

Please sign in to comment.