From 55f27cff71c8fc7c57eeb4639d5b08cd2fd31b39 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 12:39:58 -0600 Subject: [PATCH 01/36] Added functionality - and organized it in it's own function - to add/update the external person id in the person table --- phdi/linkage/core.py | 23 +++++++-- phdi/linkage/postgres.py | 108 +++++++++++++++++++++++++++++++++------ 2 files changed, 111 insertions(+), 20 deletions(-) diff --git a/phdi/linkage/core.py b/phdi/linkage/core.py index 9c0c88ad99..00a8e9907b 100644 --- a/phdi/linkage/core.py +++ b/phdi/linkage/core.py @@ -37,9 +37,10 @@ def get_connection() -> Union[any, None]: def insert_match_patient() -> None: """ If a matching person ID has been found in the MPI, inserts a new patient into - the patient table and updates the person table to link to the new patient; else - inserts a new patient into the patient table and inserts a new person into the - person table with a new personID, linking the new personID to the new patient. + the patient table, including the matched person id, to link the new patient + and matched person ID; else inserts a new patient into the patient table and + inserts a new person into the person table with a new person ID, linking the + new person ID to the new patient. """ pass # pragma: no cover @@ -52,3 +53,19 @@ def _generate_block_query(self, block_vals: dict) -> str: birthdate, addess, city, state, zip, mrn, and sex. """ pass # pragma: no cover + + @abstractmethod + def _insert_person() -> None: + """ + If person id is not supplied and external person id is not supplied + then insert a new person record with an auto-generated person id (UUID) + with a Null external person id and return that new person id. If the + person id is not supplied but an external person id is supplied try + to find an existing person record with the external person id and + return that person id; otherwise add a new person record with an + auto-generated person id (UUID) with the supplied external person id + and return the new person id. If person id and external person id are + both supplied then update the person records external person id if it + is Null and return the person id. + """ + pass # pragma: no cover diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index dcff1656bd..afac9fb162 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -120,16 +120,21 @@ def insert_match_patient( self, patient_resource: Dict, person_id=None, + external_person_id=None, ) -> Union[None, str]: """ If a matching person ID has been found in the MPI, inserts a new patient into - the patient table and updates the person table to link to the new patient; else - inserts a new patient into the patient table and inserts a new person into the - person table with a new personID, linking the new personID to the new patient. + the patient table, including the matched person id, to link the new patient + and matched person ID; else inserts a new patient into the patient table and + inserts a new person into the person table with a new person ID, linking the + new person ID to the new patient. :param patient_resource: A FHIR patient resource. - :param person_id: The personID matching the patient record if a match has been + :param person_id: The person ID matching the patient record if a match has been found in the MPI, defaults to None. + :param external_person_id: The external person id for the person that matches + the patient record if a match has been found in the MPI, defaults to None. + :return: the person id """ db_cursor = None db_conn = None @@ -137,19 +142,15 @@ def insert_match_patient( # Use context manager to handle commits and transactions with self.get_connection() as db_conn: with db_conn.cursor() as db_cursor: - # Match has not been found - if person_id is None: - # Insert a new record into person table to generate new - # person_id - insert_new_person = SQL( - "INSERT INTO {person_table} (external_person_id) VALUES " - "('NULL') RETURNING person_id;" - ).format(person_table=Identifier(self.person_table)) - - db_cursor.execute(insert_new_person) - - # Retrieve newly generated person_id - person_id = db_cursor.fetchall()[0][0] + # handle all logic whether to insert, update + # or query to get an existing person record + # then use the returned person_id to link + # to the newly create patient + person_id = self._insert_person( + db_cursor=db_cursor, + person_id=person_id, + external_person_id=external_person_id, + ) # Insert into patient table insert_new_patient = SQL( @@ -267,3 +268,76 @@ def _close_connections( db_cursor.close() if db_conn is not None: db_conn.close() + + def _insert_person( + self, + db_cursor: Union[cursor, None] = None, + person_id: str = None, + external_person_id: str = None, + ) -> Union[None, str]: + """ + If person id is not supplied and external person id is not supplied + then insert a new person record with an auto-generated person id (UUID) + with a Null external person id and return that new person id. If the + person id is not supplied but an external person id is supplied try + to find an existing person record with the external person id and + return that person id; otherwise add a new person record with an + auto-generated person id (UUID) with the supplied external person id + and return the new person id. If person id and external person id are + both supplied then update the person records external person id if it + is Null and return the person id. + + :param person_id: The person id for the person record to be inserted + or updated, defaults to None. + :param external_person_id: The external person id for the person record + to be inserted or updated, defaults to None. + :return: The person id either supplied or auto-generated + """ + + try: + if external_person_id is None: + external_person_id = "'NULL'" + found_person_id = None + else: + # if external person id is supplied then find if there is already + # a person with that external person id already within the MPI + # - if so, return that person id + person_query = SQL( + "SELECT person_id FROM {person_table} WHERE external_person_id = %s" + ).format(person_table=Identifier(self.person_table)) + query_data = [external_person_id] + db_cursor.execute(person_query, query_data) + # Retrieve person_id that has the supplied external_person_id + found_person_id = db_cursor.fetchall()[0][0] + + if found_person_id and found_person_id is not None: + return found_person_id + + if person_id is None: + # Insert a new record into person table to generate new + # person_id with either the supplied external person id + # or a null external person id + insert_new_person = SQL( + "INSERT INTO {person_table} (external_person_id) VALUES " + "(%s) RETURNING person_id;" + ).format(person_table=Identifier(self.person_table)) + person_data = [external_person_id] + + db_cursor.execute(insert_new_person, person_data) + + # Retrieve newly generated person_id + person_id = db_cursor.fetchall()[0][0] + # otherwise if person id is supplied and the external person id is supplied + # and not none and a record with the external person id was not found + # then update the person record with the supplied external person id + elif found_person_id is not None: + update_person_query = SQL( + "UPDATE {person_table} SET external_person_id = %s " + "WHERE external_person_id = 'NULL'" + ).format(person_table=Identifier(self.person_table)) + update_data = [external_person_id] + db_cursor.execute(update_person_query, update_data) + + except Exception as error: # pragma: no cover + raise ValueError(f"{error}") + return person_id From 61d62fbb72731e32f59a88560e6081dcb3ed9f35 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 13:21:11 -0600 Subject: [PATCH 02/36] Updated new insert person function to return a bool of a matched record or not --- phdi/linkage/postgres.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index afac9fb162..c057e5da78 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -146,7 +146,7 @@ def insert_match_patient( # or query to get an existing person record # then use the returned person_id to link # to the newly create patient - person_id = self._insert_person( + matched, person_id = self._insert_person( db_cursor=db_cursor, person_id=person_id, external_person_id=external_person_id, @@ -274,7 +274,7 @@ def _insert_person( db_cursor: Union[cursor, None] = None, person_id: str = None, external_person_id: str = None, - ) -> Union[None, str]: + ) -> tuple: """ If person id is not supplied and external person id is not supplied then insert a new person record with an auto-generated person id (UUID) @@ -291,13 +291,14 @@ def _insert_person( or updated, defaults to None. :param external_person_id: The external person id for the person record to be inserted or updated, defaults to None. - :return: The person id either supplied or auto-generated + :return: A tuple of two values; the person id either supplied or + auto-generated and a boolean that indicates if there was a match + found within the person table or not based upon the external person id """ - + matched = False try: if external_person_id is None: external_person_id = "'NULL'" - found_person_id = None else: # if external person id is supplied then find if there is already # a person with that external person id already within the MPI @@ -311,7 +312,8 @@ def _insert_person( found_person_id = db_cursor.fetchall()[0][0] if found_person_id and found_person_id is not None: - return found_person_id + matched = True + return matched, found_person_id if person_id is None: # Insert a new record into person table to generate new @@ -330,7 +332,8 @@ def _insert_person( # otherwise if person id is supplied and the external person id is supplied # and not none and a record with the external person id was not found # then update the person record with the supplied external person id - elif found_person_id is not None: + elif external_person_id != "'NULL'": + matched = True update_person_query = SQL( "UPDATE {person_table} SET external_person_id = %s " "WHERE external_person_id = 'NULL'" @@ -340,4 +343,4 @@ def _insert_person( except Exception as error: # pragma: no cover raise ValueError(f"{error}") - return person_id + return matched, person_id From ac412359149ab4d9f4472547b7c06c14e13d1d57 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 16:49:30 -0600 Subject: [PATCH 03/36] Made some updates to the return values as well as adding tests for the new person function --- phdi/linkage/core.py | 2 +- phdi/linkage/link.py | 6 +- phdi/linkage/postgres.py | 5 +- tests/linkage/test_postgres_mpi_connector.py | 111 +++++++++++++++++++ 4 files changed, 119 insertions(+), 5 deletions(-) diff --git a/phdi/linkage/core.py b/phdi/linkage/core.py index 00a8e9907b..b81c8fcbf6 100644 --- a/phdi/linkage/core.py +++ b/phdi/linkage/core.py @@ -55,7 +55,7 @@ def _generate_block_query(self, block_vals: dict) -> str: pass # pragma: no cover @abstractmethod - def _insert_person() -> None: + def _insert_person() -> tuple: """ If person id is not supplied and external person id is not supplied then insert a new person record with an auto-generated person id (UUID) diff --git a/phdi/linkage/link.py b/phdi/linkage/link.py index 0d53ce239b..74331d0386 100644 --- a/phdi/linkage/link.py +++ b/phdi/linkage/link.py @@ -640,8 +640,10 @@ def link_record_against_mpi( # Didn't match any person in our database if len(linkage_scores) == 0: - new_person_id = db_client.insert_match_patient(record, person_id=None) - return (False, new_person_id) + (matched, new_person_id) = db_client.insert_match_patient( + record, person_id=None + ) + return (matched, new_person_id) # Determine strongest match, upsert, then let the caller know else: diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index c057e5da78..0dcd3d547a 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -121,7 +121,7 @@ def insert_match_patient( patient_resource: Dict, person_id=None, external_person_id=None, - ) -> Union[None, str]: + ) -> Union[None, tuple]: """ If a matching person ID has been found in the MPI, inserts a new patient into the patient table, including the matched person id, to link the new patient @@ -136,6 +136,7 @@ def insert_match_patient( the patient record if a match has been found in the MPI, defaults to None. :return: the person id """ + matched = False db_cursor = None db_conn = None try: @@ -176,7 +177,7 @@ def insert_match_patient( finally: self._close_connections(db_conn=db_conn, db_cursor=db_cursor) - return person_id + return (matched, person_id) def _generate_block_query(self, block_vals: dict) -> Tuple[SQL, list[str]]: """ diff --git a/tests/linkage/test_postgres_mpi_connector.py b/tests/linkage/test_postgres_mpi_connector.py index 486ed5d4ef..007302fddc 100644 --- a/tests/linkage/test_postgres_mpi_connector.py +++ b/tests/linkage/test_postgres_mpi_connector.py @@ -432,3 +432,114 @@ def create_valid_mpi_client(): patient_table="test_patient_mpi", person_table="test_person_mpi", ) + + +def test_insert_person(): + postgres_client = create_valid_mpi_client() + postgres_client.connection = postgres_client.get_connection() + postgres_client.cursor = postgres_client.connection.cursor() + + raw_bundle = json.load( + open( + pathlib.Path(__file__).parent.parent.parent + / "tests" + / "assets" + / "general" + / "patient_bundle.json" + ) + ) + + patient_resource = raw_bundle.get("entry")[1].get("resource") + patient_resource["id"] = "4d88cd35-5ee7-4419-a847-2818fdfeec50" + + # Generate test tables + # Create test table and insert data + funcs = { + "drop tables": ( + f""" + DROP TABLE IF EXISTS {postgres_client.person_table}; + """ + ), + "create_person": ( + """ + BEGIN; + + CREATE EXTENSION IF NOT EXISTS "uuid-ossp";""" + + f"CREATE TABLE IF NOT EXISTS {postgres_client.person_table} " + + "(person_id UUID DEFAULT uuid_generate_v4 (), " + + "external_person_id VARCHAR(100));" + ), + "insert_person": ( + f"""INSERT INTO {postgres_client.person_table} (person_id, """ + + "external_person_id) " + + """VALUES ('ce02326f-7ecd-47ea-83eb-71e8d7c39131', + '4d88cd35-5ee7-4419-a847-2818fdfeec38'), + ('cb9dc379-38a9-4ed6-b3a7-a8a3db0e9e6c', + 'NULL');""" + ), + } + + for command, statement in funcs.items(): + try: + postgres_client.cursor.execute(statement) + postgres_client.connection.commit() + except Exception as e: + print(f"{command} was unsuccessful") + print(e) + postgres_client.connection.rollback() + + # Find the person based upon the external person id + external_person_id_test = "4d88cd35-5ee7-4419-a847-2818fdfeec88" + expected_person_id = "ce02326f-7ecd-47ea-83eb-71e8d7c39131" + + # send in null person_id and external_person_id populated and get back a person_id + actual_result, actual_person_id = postgres_client._insert_person( + postgres_client.cursor, None, external_person_id_test + ) + + # Assert existing person_id from MPI + assert actual_result + assert actual_person_id == expected_person_id + + # Now we will insert a new person with a null external id + actual_result, new_person_id = postgres_client._insert_person( + postgres_client.cursor, None, None + ) + + postgres_client.cursor.execute( + f"SELECT * from {postgres_client.person_table} WHERE person_id = {new_person_id}" + ) + postgres_client.connection.commit() + data = postgres_client.cursor.fetchall() + + # Assert record was added to the table + assert len(data) == 1 + assert new_person_id is not None + + # Send in a valid person id and a new external person id + # for a person record where the external person id is null + # should update the person record with the new external person id + valid_person_id = "cb9dc379-38a9-4ed6-b3a7-a8a3db0e9e6c" + new_external_person_id = "'bbbbbbbb-38a9-4ed6-b3a7-a8a3db0e9e6c'" + postgres_client._insert_person( + postgres_client.cursor, valid_person_id, new_external_person_id + ) + + postgres_client.cursor.execute( + f"SELECT * from {postgres_client.person_table} WHERE external_person_id = {new_external_person_id}" + ) + postgres_client.connection.commit() + data = postgres_client.cursor.fetchall() + + # Assert record was updated in table + assert len(data) == 1 + + # Clean up + postgres_client.connection = postgres_client.get_connection() + postgres_client.cursor = postgres_client.connection.cursor() + postgres_client.cursor.execute( + f"DROP TABLE IF EXISTS {postgres_client.person_table}" + ) + postgres_client.connection.commit() + postgres_client.cursor.close() + postgres_client.connection.close() From 3bc6b1fed4208d0d7d2a8a6cac4199039ff240bd Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 16:51:18 -0600 Subject: [PATCH 04/36] Update test_postgres_mpi_connector.py --- tests/linkage/test_postgres_mpi_connector.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/linkage/test_postgres_mpi_connector.py b/tests/linkage/test_postgres_mpi_connector.py index 007302fddc..168bb239c4 100644 --- a/tests/linkage/test_postgres_mpi_connector.py +++ b/tests/linkage/test_postgres_mpi_connector.py @@ -507,7 +507,8 @@ def test_insert_person(): ) postgres_client.cursor.execute( - f"SELECT * from {postgres_client.person_table} WHERE person_id = {new_person_id}" + f"SELECT * from {postgres_client.person_table} " + "WHERE person_id = {new_person_id}" ) postgres_client.connection.commit() data = postgres_client.cursor.fetchall() @@ -526,7 +527,8 @@ def test_insert_person(): ) postgres_client.cursor.execute( - f"SELECT * from {postgres_client.person_table} WHERE external_person_id = {new_external_person_id}" + f"SELECT * from {postgres_client.person_table} " + "WHERE external_person_id = {new_external_person_id}" ) postgres_client.connection.commit() data = postgres_client.cursor.fetchall() From 09b9a2624847aa1ff71ad872f09c60a83014bbc1 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 17:02:51 -0600 Subject: [PATCH 05/36] Update postgres.py --- phdi/linkage/postgres.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index 0dcd3d547a..efd4c33a35 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -310,7 +310,7 @@ def _insert_person( query_data = [external_person_id] db_cursor.execute(person_query, query_data) # Retrieve person_id that has the supplied external_person_id - found_person_id = db_cursor.fetchall()[0][0] + found_person_id = db_cursor.fetchall()[0] if found_person_id and found_person_id is not None: matched = True From d1a96be7f5e7fe6d769a214edd33c2f6a5d1a352 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 17:06:49 -0600 Subject: [PATCH 06/36] Update postgres.py --- phdi/linkage/postgres.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index efd4c33a35..e936f95989 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -310,7 +310,7 @@ def _insert_person( query_data = [external_person_id] db_cursor.execute(person_query, query_data) # Retrieve person_id that has the supplied external_person_id - found_person_id = db_cursor.fetchall()[0] + found_person_id = db_cursor.fetchall() if found_person_id and found_person_id is not None: matched = True From 853d133b79628e0692d541f4c96b3d644110c3f5 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 17:09:43 -0600 Subject: [PATCH 07/36] Update test_postgres_mpi_connector.py --- tests/linkage/test_postgres_mpi_connector.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/linkage/test_postgres_mpi_connector.py b/tests/linkage/test_postgres_mpi_connector.py index 168bb239c4..bd4a9dca2a 100644 --- a/tests/linkage/test_postgres_mpi_connector.py +++ b/tests/linkage/test_postgres_mpi_connector.py @@ -498,6 +498,9 @@ def test_insert_person(): ) # Assert existing person_id from MPI + print("HERE") + print(actual_result) + print(actual_person_id) assert actual_result assert actual_person_id == expected_person_id From 4ad2daedb2a99d3142052b863c7c07d0af27d685 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 17:49:36 -0600 Subject: [PATCH 08/36] Fixed test and description for record-linkage --- containers/record-linkage/description.md | 2 +- tests/linkage/test_postgres_mpi_connector.py | 15 +-------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/containers/record-linkage/description.md b/containers/record-linkage/description.md index 2796834736..05dc52eac1 100644 --- a/containers/record-linkage/description.md +++ b/containers/record-linkage/description.md @@ -18,7 +18,7 @@ Docker version 20.10.21, build baeda1f 2. Navigate to the `containers/record-linkage` folder and start the service by running `docker compose up --build` -Congratulations the FHIR Converter should now be running on `localhost:8080`! +Congratulations the record-linkage should now be running on `localhost:8080`! #### Running with Docker diff --git a/tests/linkage/test_postgres_mpi_connector.py b/tests/linkage/test_postgres_mpi_connector.py index bd4a9dca2a..30d1a1d3e9 100644 --- a/tests/linkage/test_postgres_mpi_connector.py +++ b/tests/linkage/test_postgres_mpi_connector.py @@ -439,19 +439,6 @@ def test_insert_person(): postgres_client.connection = postgres_client.get_connection() postgres_client.cursor = postgres_client.connection.cursor() - raw_bundle = json.load( - open( - pathlib.Path(__file__).parent.parent.parent - / "tests" - / "assets" - / "general" - / "patient_bundle.json" - ) - ) - - patient_resource = raw_bundle.get("entry")[1].get("resource") - patient_resource["id"] = "4d88cd35-5ee7-4419-a847-2818fdfeec50" - # Generate test tables # Create test table and insert data funcs = { @@ -489,7 +476,7 @@ def test_insert_person(): postgres_client.connection.rollback() # Find the person based upon the external person id - external_person_id_test = "4d88cd35-5ee7-4419-a847-2818fdfeec88" + external_person_id_test = "4d88cd35-5ee7-4419-a847-2818fdfeec38" expected_person_id = "ce02326f-7ecd-47ea-83eb-71e8d7c39131" # send in null person_id and external_person_id populated and get back a person_id From e3c9ed5eaa5aac4614db5863d043b17a99e9a571 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 17:53:33 -0600 Subject: [PATCH 09/36] Update postgres.py --- phdi/linkage/postgres.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index e936f95989..efd4c33a35 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -310,7 +310,7 @@ def _insert_person( query_data = [external_person_id] db_cursor.execute(person_query, query_data) # Retrieve person_id that has the supplied external_person_id - found_person_id = db_cursor.fetchall() + found_person_id = db_cursor.fetchall()[0] if found_person_id and found_person_id is not None: matched = True From 95a2455277a5a90aa735485ed3613a56cafe3228 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 17:55:32 -0600 Subject: [PATCH 10/36] Update postgres.py --- phdi/linkage/postgres.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index efd4c33a35..0dcd3d547a 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -310,7 +310,7 @@ def _insert_person( query_data = [external_person_id] db_cursor.execute(person_query, query_data) # Retrieve person_id that has the supplied external_person_id - found_person_id = db_cursor.fetchall()[0] + found_person_id = db_cursor.fetchall()[0][0] if found_person_id and found_person_id is not None: matched = True From 3e32777b0a4b178589ea7a83869bdd6f637c61a4 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 18:07:25 -0600 Subject: [PATCH 11/36] Update test_postgres_mpi_connector.py --- tests/linkage/test_postgres_mpi_connector.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/linkage/test_postgres_mpi_connector.py b/tests/linkage/test_postgres_mpi_connector.py index 30d1a1d3e9..b21804116d 100644 --- a/tests/linkage/test_postgres_mpi_connector.py +++ b/tests/linkage/test_postgres_mpi_connector.py @@ -495,10 +495,9 @@ def test_insert_person(): actual_result, new_person_id = postgres_client._insert_person( postgres_client.cursor, None, None ) - + query_data = [new_person_id] postgres_client.cursor.execute( - f"SELECT * from {postgres_client.person_table} " - "WHERE person_id = {new_person_id}" + f"SELECT * from {postgres_client.person_table} " "WHERE person_id = %s", data ) postgres_client.connection.commit() data = postgres_client.cursor.fetchall() @@ -516,15 +515,19 @@ def test_insert_person(): postgres_client.cursor, valid_person_id, new_external_person_id ) + query_data = [valid_person_id] + postgres_client.cursor.execute( - f"SELECT * from {postgres_client.person_table} " - "WHERE external_person_id = {new_external_person_id}" + f"SELECT external_person_id from {postgres_client.person_table} " + "WHERE person_id = %s", + query_data, ) postgres_client.connection.commit() - data = postgres_client.cursor.fetchall() + data = postgres_client.cursor.fetchall()[0][0] # Assert record was updated in table assert len(data) == 1 + assert data == new_external_person_id # Clean up postgres_client.connection = postgres_client.get_connection() From 42a84e81f84d84e28cb6ea3b92dfc9dc6dc70c48 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 18:12:41 -0600 Subject: [PATCH 12/36] Update test_postgres_mpi_connector.py --- tests/linkage/test_postgres_mpi_connector.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/linkage/test_postgres_mpi_connector.py b/tests/linkage/test_postgres_mpi_connector.py index b21804116d..5f817388cb 100644 --- a/tests/linkage/test_postgres_mpi_connector.py +++ b/tests/linkage/test_postgres_mpi_connector.py @@ -497,7 +497,8 @@ def test_insert_person(): ) query_data = [new_person_id] postgres_client.cursor.execute( - f"SELECT * from {postgres_client.person_table} " "WHERE person_id = %s", data + f"SELECT * from {postgres_client.person_table} " "WHERE person_id = %s", + query_data, ) postgres_client.connection.commit() data = postgres_client.cursor.fetchall() From 169ce594b32566b807b5457cca0b7fbe5528d58c Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 19:00:53 -0600 Subject: [PATCH 13/36] Update postgres.py --- phdi/linkage/postgres.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index 0dcd3d547a..5fafdda608 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -310,7 +310,10 @@ def _insert_person( query_data = [external_person_id] db_cursor.execute(person_query, query_data) # Retrieve person_id that has the supplied external_person_id - found_person_id = db_cursor.fetchall()[0][0] + returned_data = db_cursor.fetchall() + + if returned_data is not None and len(returned_data) > 0: + found_person_id = returned_data[0][0] if found_person_id and found_person_id is not None: matched = True From 129f170193409da43da9b44a54ae8ca1553cc09a Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 19:04:15 -0600 Subject: [PATCH 14/36] Update postgres.py --- phdi/linkage/postgres.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index 5fafdda608..0539c99461 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -314,8 +314,10 @@ def _insert_person( if returned_data is not None and len(returned_data) > 0: found_person_id = returned_data[0][0] + else: + found_person_id = None - if found_person_id and found_person_id is not None: + if found_person_id is not None: matched = True return matched, found_person_id From e23fec6fc8fee1735ac8f40f4f3371fc07930c25 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 19:28:22 -0600 Subject: [PATCH 15/36] Update test_postgres_mpi_connector.py --- tests/linkage/test_postgres_mpi_connector.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/linkage/test_postgres_mpi_connector.py b/tests/linkage/test_postgres_mpi_connector.py index 5f817388cb..cb137517b0 100644 --- a/tests/linkage/test_postgres_mpi_connector.py +++ b/tests/linkage/test_postgres_mpi_connector.py @@ -527,7 +527,6 @@ def test_insert_person(): data = postgres_client.cursor.fetchall()[0][0] # Assert record was updated in table - assert len(data) == 1 assert data == new_external_person_id # Clean up From be83782086b9d282ff2d8219bf47f34f66c2d493 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 20:53:20 -0600 Subject: [PATCH 16/36] Added Parameters to the linkage container and underlying code to accept an external_person_id and return a bool matched based upon the results --- containers/record-linkage/app/main.py | 6 ++++++ phdi/linkage/link.py | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/containers/record-linkage/app/main.py b/containers/record-linkage/app/main.py index 3be912cb65..932c9d64ea 100644 --- a/containers/record-linkage/app/main.py +++ b/containers/record-linkage/app/main.py @@ -91,6 +91,11 @@ class LinkRecordInput(BaseModel): "algorithm.", default={}, ) + external_person_id: str = Field( + description="The External Identifier, provided by the client," + " for a unique patient/person that is linked to patient(s)", + default=None, + ) class LinkRecordResponse(BaseModel): @@ -158,6 +163,7 @@ async def link_record(input: LinkRecordInput, response: Response) -> LinkRecordR input = dict(input) input_bundle = input.get("bundle", {}) + external_id = input.get("external_person_id") # Check that DB type is appropriately set up as Postgres so # we can fail fast if it's not diff --git a/phdi/linkage/link.py b/phdi/linkage/link.py index 74331d0386..f501f9523e 100644 --- a/phdi/linkage/link.py +++ b/phdi/linkage/link.py @@ -546,6 +546,7 @@ def link_record_against_mpi( record: dict, algo_config: List[dict], db_client: BaseMPIConnectorClient, + external_person_id: str = None, ) -> tuple[bool, str]: """ Runs record linkage on a single incoming record (extracted from a FHIR @@ -641,14 +642,16 @@ def link_record_against_mpi( # Didn't match any person in our database if len(linkage_scores) == 0: (matched, new_person_id) = db_client.insert_match_patient( - record, person_id=None + record, person_id=None, external_person_id=external_person_id ) return (matched, new_person_id) # Determine strongest match, upsert, then let the caller know else: best_person = _find_strongest_link(linkage_scores) - db_client.insert_match_patient(record, person_id=best_person) + db_client.insert_match_patient( + record, person_id=best_person, external_person_id=external_person_id + ) return (True, best_person) From 1869e450f818157ed27ea8bb588c401a80cd49bc Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 20:58:40 -0600 Subject: [PATCH 17/36] Update main.py --- containers/record-linkage/app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/containers/record-linkage/app/main.py b/containers/record-linkage/app/main.py index 932c9d64ea..edda87513b 100644 --- a/containers/record-linkage/app/main.py +++ b/containers/record-linkage/app/main.py @@ -204,7 +204,7 @@ async def link_record(input: LinkRecordInput, response: Response) -> LinkRecordR try: db_client = connect_to_mpi_with_env_vars() (found_match, new_person_id) = link_record_against_mpi( - record_to_link, algo_config, db_client + record_to_link, algo_config, db_client, external_person_id=external_id ) updated_bundle = add_person_resource( new_person_id, record_to_link.get("id", ""), input_bundle From c1d477ee489920613ead2a09446b2910c37f6844 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 21:01:49 -0600 Subject: [PATCH 18/36] Update main.py --- containers/record-linkage/app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/containers/record-linkage/app/main.py b/containers/record-linkage/app/main.py index edda87513b..ad51dad2f0 100644 --- a/containers/record-linkage/app/main.py +++ b/containers/record-linkage/app/main.py @@ -204,7 +204,7 @@ async def link_record(input: LinkRecordInput, response: Response) -> LinkRecordR try: db_client = connect_to_mpi_with_env_vars() (found_match, new_person_id) = link_record_against_mpi( - record_to_link, algo_config, db_client, external_person_id=external_id + record_to_link, algo_config, db_client, external_id ) updated_bundle = add_person_resource( new_person_id, record_to_link.get("id", ""), input_bundle From 4fa5671384c329db7577427052e7bec71fe152ab Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 21:09:08 -0600 Subject: [PATCH 19/36] Update main.py --- containers/record-linkage/app/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/containers/record-linkage/app/main.py b/containers/record-linkage/app/main.py index ad51dad2f0..aab27590ef 100644 --- a/containers/record-linkage/app/main.py +++ b/containers/record-linkage/app/main.py @@ -91,7 +91,7 @@ class LinkRecordInput(BaseModel): "algorithm.", default={}, ) - external_person_id: str = Field( + external_person_id: Optional[str] = Field( description="The External Identifier, provided by the client," " for a unique patient/person that is linked to patient(s)", default=None, @@ -163,7 +163,7 @@ async def link_record(input: LinkRecordInput, response: Response) -> LinkRecordR input = dict(input) input_bundle = input.get("bundle", {}) - external_id = input.get("external_person_id") + external_id = input.get("external_person_id", None) # Check that DB type is appropriately set up as Postgres so # we can fail fast if it's not From d03772b0fdef3018c08801effac80ae210b7b1a0 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Thu, 18 May 2023 21:13:16 -0600 Subject: [PATCH 20/36] Update main.py --- containers/record-linkage/app/main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/containers/record-linkage/app/main.py b/containers/record-linkage/app/main.py index aab27590ef..3ad514ed00 100644 --- a/containers/record-linkage/app/main.py +++ b/containers/record-linkage/app/main.py @@ -163,7 +163,9 @@ async def link_record(input: LinkRecordInput, response: Response) -> LinkRecordR input = dict(input) input_bundle = input.get("bundle", {}) - external_id = input.get("external_person_id", None) + # TODO: Once the code that includes the external_person_id in + # the sdk is merged, then bring back the external_id code here + # external_id = input.get("external_person_id", None) # Check that DB type is appropriately set up as Postgres so # we can fail fast if it's not @@ -201,10 +203,12 @@ async def link_record(input: LinkRecordInput, response: Response) -> LinkRecordR # Initialize a DB connection for use with the MPI # Then, link away + # TODO: Once the code that includes the external_person_id in + # the sdk is merged, then bring back the external_id code here try: db_client = connect_to_mpi_with_env_vars() (found_match, new_person_id) = link_record_against_mpi( - record_to_link, algo_config, db_client, external_id + record_to_link, algo_config, db_client # , external_id ) updated_bundle = add_person_resource( new_person_id, record_to_link.get("id", ""), input_bundle From bbce9fd7f071e74733705cb45923dd8ccef6f551 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Fri, 19 May 2023 08:18:02 -0600 Subject: [PATCH 21/36] Remove print statements and fixed a major bug in the update statement --- phdi/linkage/postgres.py | 4 ++-- tests/linkage/test_postgres_mpi_connector.py | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index 0539c99461..a6190ee455 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -342,9 +342,9 @@ def _insert_person( matched = True update_person_query = SQL( "UPDATE {person_table} SET external_person_id = %s " - "WHERE external_person_id = 'NULL'" + "WHERE person_id = %s AND external_person_id = 'NULL'" ).format(person_table=Identifier(self.person_table)) - update_data = [external_person_id] + update_data = [external_person_id, person_id] db_cursor.execute(update_person_query, update_data) except Exception as error: # pragma: no cover diff --git a/tests/linkage/test_postgres_mpi_connector.py b/tests/linkage/test_postgres_mpi_connector.py index cb137517b0..cacd985dac 100644 --- a/tests/linkage/test_postgres_mpi_connector.py +++ b/tests/linkage/test_postgres_mpi_connector.py @@ -485,9 +485,7 @@ def test_insert_person(): ) # Assert existing person_id from MPI - print("HERE") - print(actual_result) - print(actual_person_id) + assert actual_result assert actual_person_id == expected_person_id From 19c5697c6d4428399ef3e56c01cca0e9815245a1 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Fri, 19 May 2023 08:20:14 -0600 Subject: [PATCH 22/36] Update phdi/linkage/postgres.py This makes sense. I think I was too tired last night. ;) Co-authored-by: Daniel Paseltiner <99684231+DanPaseltiner@users.noreply.github.com> --- phdi/linkage/postgres.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index a6190ee455..d7cc6c83f2 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -297,6 +297,7 @@ def _insert_person( found within the person table or not based upon the external person id """ matched = False + found_person_id = None try: if external_person_id is None: external_person_id = "'NULL'" @@ -314,12 +315,8 @@ def _insert_person( if returned_data is not None and len(returned_data) > 0: found_person_id = returned_data[0][0] - else: - found_person_id = None - - if found_person_id is not None: matched = True - return matched, found_person_id + return matched, found_person_id if person_id is None: # Insert a new record into person table to generate new From d5f1483f2b796f0a1e2bfe2437c8f2acc9d91714 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Fri, 19 May 2023 08:23:45 -0600 Subject: [PATCH 23/36] Update postgres.py --- phdi/linkage/postgres.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index a6190ee455..20b1d6ac1a 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -338,7 +338,7 @@ def _insert_person( # otherwise if person id is supplied and the external person id is supplied # and not none and a record with the external person id was not found # then update the person record with the supplied external person id - elif external_person_id != "'NULL'": + elif person_id is not None and external_person_id != "'NULL'": matched = True update_person_query = SQL( "UPDATE {person_table} SET external_person_id = %s " From 3aa6a15085212d765b743cae013a5c08a168ef8c Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Fri, 19 May 2023 08:33:40 -0600 Subject: [PATCH 24/36] Update postgres.py --- phdi/linkage/postgres.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index ee380124e7..b12e4beeb4 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -339,7 +339,7 @@ def _insert_person( matched = True update_person_query = SQL( "UPDATE {person_table} SET external_person_id = %s " - "WHERE person_id = %s AND external_person_id = 'NULL'" + "WHERE person_id = '%s' AND external_person_id = 'NULL'" ).format(person_table=Identifier(self.person_table)) update_data = [external_person_id, person_id] db_cursor.execute(update_person_query, update_data) From bd60f95d01a10a8f02dc50b1ebb716840d8ca939 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Fri, 19 May 2023 08:34:29 -0600 Subject: [PATCH 25/36] fixed test --- phdi/linkage/postgres.py | 2 +- tests/linkage/test_postgres_mpi_connector.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index b12e4beeb4..ee380124e7 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -339,7 +339,7 @@ def _insert_person( matched = True update_person_query = SQL( "UPDATE {person_table} SET external_person_id = %s " - "WHERE person_id = '%s' AND external_person_id = 'NULL'" + "WHERE person_id = %s AND external_person_id = 'NULL'" ).format(person_table=Identifier(self.person_table)) update_data = [external_person_id, person_id] db_cursor.execute(update_person_query, update_data) diff --git a/tests/linkage/test_postgres_mpi_connector.py b/tests/linkage/test_postgres_mpi_connector.py index cacd985dac..8bd322fe88 100644 --- a/tests/linkage/test_postgres_mpi_connector.py +++ b/tests/linkage/test_postgres_mpi_connector.py @@ -509,7 +509,7 @@ def test_insert_person(): # for a person record where the external person id is null # should update the person record with the new external person id valid_person_id = "cb9dc379-38a9-4ed6-b3a7-a8a3db0e9e6c" - new_external_person_id = "'bbbbbbbb-38a9-4ed6-b3a7-a8a3db0e9e6c'" + new_external_person_id = "bbbbbbbb-38a9-4ed6-b3a7-a8a3db0e9e6c" postgres_client._insert_person( postgres_client.cursor, valid_person_id, new_external_person_id ) From c30ce174a7ce1aea2ea77da424ab60fa2db36804 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Fri, 19 May 2023 08:39:58 -0600 Subject: [PATCH 26/36] Update postgres.py --- phdi/linkage/postgres.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index ee380124e7..0194cf2869 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -339,7 +339,7 @@ def _insert_person( matched = True update_person_query = SQL( "UPDATE {person_table} SET external_person_id = %s " - "WHERE person_id = %s AND external_person_id = 'NULL'" + "WHERE person_id = %s AND external_person_id = NULL" ).format(person_table=Identifier(self.person_table)) update_data = [external_person_id, person_id] db_cursor.execute(update_person_query, update_data) From 46c84a02d7f99c1a733a80f7d19f44391293e618 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Fri, 19 May 2023 08:47:48 -0600 Subject: [PATCH 27/36] Update postgres.py --- phdi/linkage/postgres.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index 0194cf2869..11ef655732 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -339,7 +339,7 @@ def _insert_person( matched = True update_person_query = SQL( "UPDATE {person_table} SET external_person_id = %s " - "WHERE person_id = %s AND external_person_id = NULL" + "WHERE person_id = %s AND external_person_id IS NULL" ).format(person_table=Identifier(self.person_table)) update_data = [external_person_id, person_id] db_cursor.execute(update_person_query, update_data) From b42324474acf4df8b57a72ded1e6d5b9e86748bd Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Fri, 19 May 2023 08:50:28 -0600 Subject: [PATCH 28/36] Update postgres.py --- phdi/linkage/postgres.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index 11ef655732..b1235d5447 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -339,7 +339,7 @@ def _insert_person( matched = True update_person_query = SQL( "UPDATE {person_table} SET external_person_id = %s " - "WHERE person_id = %s AND external_person_id IS NULL" + "WHERE person_id = %s AND external_person_id = 'NULL' " ).format(person_table=Identifier(self.person_table)) update_data = [external_person_id, person_id] db_cursor.execute(update_person_query, update_data) From 1429d48ccad11a046589565486b21b2ee8ced5a9 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Fri, 19 May 2023 09:43:13 -0600 Subject: [PATCH 29/36] Update postgres.py --- phdi/linkage/postgres.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index b1235d5447..8ff563206d 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -336,6 +336,9 @@ def _insert_person( # and not none and a record with the external person id was not found # then update the person record with the supplied external person id elif person_id is not None and external_person_id != "'NULL'": + print("HERE") + print(external_person_id) + print(person_id) matched = True update_person_query = SQL( "UPDATE {person_table} SET external_person_id = %s " From f1678f29849b2c960cbe72b81e0c47fabbd398c3 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Fri, 19 May 2023 09:46:34 -0600 Subject: [PATCH 30/36] Update postgres.py --- phdi/linkage/postgres.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index 8ff563206d..91f2ff42a5 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -297,7 +297,9 @@ def _insert_person( found within the person table or not based upon the external person id """ matched = False - found_person_id = None + print("HERE") + print(external_person_id) + print(person_id) try: if external_person_id is None: external_person_id = "'NULL'" @@ -336,7 +338,7 @@ def _insert_person( # and not none and a record with the external person id was not found # then update the person record with the supplied external person id elif person_id is not None and external_person_id != "'NULL'": - print("HERE") + print("THERE") print(external_person_id) print(person_id) matched = True From 46d97dfa59f68672442bfa216e40a9549adff9da Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Fri, 19 May 2023 09:55:10 -0600 Subject: [PATCH 31/36] Update test_postgres_mpi_connector.py --- tests/linkage/test_postgres_mpi_connector.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/linkage/test_postgres_mpi_connector.py b/tests/linkage/test_postgres_mpi_connector.py index 8bd322fe88..1c641d4f80 100644 --- a/tests/linkage/test_postgres_mpi_connector.py +++ b/tests/linkage/test_postgres_mpi_connector.py @@ -510,7 +510,7 @@ def test_insert_person(): # should update the person record with the new external person id valid_person_id = "cb9dc379-38a9-4ed6-b3a7-a8a3db0e9e6c" new_external_person_id = "bbbbbbbb-38a9-4ed6-b3a7-a8a3db0e9e6c" - postgres_client._insert_person( + update_matched, update_person_id = postgres_client._insert_person( postgres_client.cursor, valid_person_id, new_external_person_id ) @@ -525,6 +525,8 @@ def test_insert_person(): data = postgres_client.cursor.fetchall()[0][0] # Assert record was updated in table + assert update_matched + assert update_person_id == valid_person_id assert data == new_external_person_id # Clean up From ac55731d1e7fd44217e5cb65f69d0315be1f5c65 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Fri, 19 May 2023 09:55:12 -0600 Subject: [PATCH 32/36] Update postgres.py --- phdi/linkage/postgres.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index 91f2ff42a5..0275ad5f67 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -318,7 +318,7 @@ def _insert_person( if returned_data is not None and len(returned_data) > 0: found_person_id = returned_data[0][0] matched = True - return matched, found_person_id + return matched, found_person_id if person_id is None: # Insert a new record into person table to generate new From 75112d41de62324ac457ccbd1e0d139d485e0395 Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Fri, 19 May 2023 10:02:19 -0600 Subject: [PATCH 33/36] removed print statements --- phdi/linkage/postgres.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/phdi/linkage/postgres.py b/phdi/linkage/postgres.py index 0275ad5f67..94adb2aec2 100644 --- a/phdi/linkage/postgres.py +++ b/phdi/linkage/postgres.py @@ -297,9 +297,6 @@ def _insert_person( found within the person table or not based upon the external person id """ matched = False - print("HERE") - print(external_person_id) - print(person_id) try: if external_person_id is None: external_person_id = "'NULL'" @@ -338,9 +335,6 @@ def _insert_person( # and not none and a record with the external person id was not found # then update the person record with the supplied external person id elif person_id is not None and external_person_id != "'NULL'": - print("THERE") - print(external_person_id) - print(person_id) matched = True update_person_query = SQL( "UPDATE {person_table} SET external_person_id = %s " From f4059bb53eea41c57485cefa66bb9f93ae64e7be Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Fri, 19 May 2023 10:19:35 -0600 Subject: [PATCH 34/36] Update main.py --- containers/record-linkage/app/main.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/containers/record-linkage/app/main.py b/containers/record-linkage/app/main.py index 3ad514ed00..f28ec72375 100644 --- a/containers/record-linkage/app/main.py +++ b/containers/record-linkage/app/main.py @@ -163,9 +163,7 @@ async def link_record(input: LinkRecordInput, response: Response) -> LinkRecordR input = dict(input) input_bundle = input.get("bundle", {}) - # TODO: Once the code that includes the external_person_id in - # the sdk is merged, then bring back the external_id code here - # external_id = input.get("external_person_id", None) + external_id = input.get("external_person_id", None) # Check that DB type is appropriately set up as Postgres so # we can fail fast if it's not @@ -208,7 +206,7 @@ async def link_record(input: LinkRecordInput, response: Response) -> LinkRecordR try: db_client = connect_to_mpi_with_env_vars() (found_match, new_person_id) = link_record_against_mpi( - record_to_link, algo_config, db_client # , external_id + record_to_link, algo_config, db_client, external_id ) updated_bundle = add_person_resource( new_person_id, record_to_link.get("id", ""), input_bundle From 1bb206d69a734813492e5b650876491fea5f98ac Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Fri, 19 May 2023 10:30:38 -0600 Subject: [PATCH 35/36] REmoved comment and pointed container to main --- containers/record-linkage/app/main.py | 2 -- containers/record-linkage/requirements.txt | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/containers/record-linkage/app/main.py b/containers/record-linkage/app/main.py index f28ec72375..aab27590ef 100644 --- a/containers/record-linkage/app/main.py +++ b/containers/record-linkage/app/main.py @@ -201,8 +201,6 @@ async def link_record(input: LinkRecordInput, response: Response) -> LinkRecordR # Initialize a DB connection for use with the MPI # Then, link away - # TODO: Once the code that includes the external_person_id in - # the sdk is merged, then bring back the external_id code here try: db_client = connect_to_mpi_with_env_vars() (found_match, new_person_id) = link_record_against_mpi( diff --git a/containers/record-linkage/requirements.txt b/containers/record-linkage/requirements.txt index e6a9595a09..27e6997b16 100644 --- a/containers/record-linkage/requirements.txt +++ b/containers/record-linkage/requirements.txt @@ -1,6 +1,6 @@ fastapi uvicorn -phdi +phdi @ git+https://github.com/CDCgov/phdi@main httpx pathlib pydantic \ No newline at end of file From d4022b381b2a024be19cc6afe889b3fa78553b8a Mon Sep 17 00:00:00 2001 From: Brady Fausett at Skylight Date: Fri, 19 May 2023 10:35:56 -0600 Subject: [PATCH 36/36] Update Dockerfile --- containers/record-linkage/Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/containers/record-linkage/Dockerfile b/containers/record-linkage/Dockerfile index 996fc3d45f..dc597df295 100644 --- a/containers/record-linkage/Dockerfile +++ b/containers/record-linkage/Dockerfile @@ -2,6 +2,10 @@ FROM python:3.10-slim WORKDIR /code +RUN apt-get update && \ + apt-get upgrade -y && \ + apt-get install -y git + COPY ./requirements.txt /code/requirements.txt RUN pip install -r requirements.txt