generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description Implementing the MPI functions, `get_block_data` and `insert_matched_patient`, using the new schema. ## Related Issues closes #10 ## Additional Notes - A couple of large changes to the DB schema - The BlockingKey table has been replaced with an enum. With the direction that we're going, we'll want to lock these in place. Using a DB to store them is fine, but I think that opens up the possibility that a user could add another one (say directly through some SQL query and skip the app), that would throw off all are existing BlockingValues. I think it's safer to store this directly in code, to protect our users from potentially making this mistake. Additionally, each one of these values needs a way to transform a collection of Patient PII into a list of Blocking Values specific to a key, so some code was going to be necessary no matter what. - The ExternalPerson table was deleted. With the current design some fidelity is being lost here that doesn't seem ideal. Yes, we are storing all the external person identifiers received by the documents, but once a Person cluster grows beyond 2 Patients, we have no way to trace an external_person_id back to the Patient it was originally attached to. By moving this field over to the Patient table, we retain the ability to track document external_person_id with patient_id. - Patient.external_patient_id has been added. In the current schema, Patient.id is either internal or external, just depends on if a Patient resource id is present in the FHIR bundle. If want to continue to track that external patient resource id that is sometimes present, we need a column in the patient table to store that info. - The python-dotenv dependency has been removed, `settings.db_uri` now has the information that we used dotenv to load, so we don't need this anymore
- Loading branch information
1 parent
6cc3772
commit 0431771
Showing
16 changed files
with
751 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
DB_URI="postgresql+psycopg2://postgres:pw@localhost:5432/postgres" | ||
DB_URI="postgresql+psycopg2://postgres:pw@localhost:5432/postgres" | ||
TEST_DB_URI="sqlite:///:memory:" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
alembic/versions/64ed9566f189_external_person_id_should_be_nullable.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""external person id should be nullable | ||
Revision ID: 64ed9566f189 | ||
Revises: bfbd015ca466 | ||
Create Date: 2024-09-18 20:22:07.510203 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = '64ed9566f189' | ||
down_revision: Union[str, None] = 'bfbd015ca466' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index('ix_mpi_blocking_value_value', table_name='mpi_blocking_value') | ||
op.alter_column('mpi_patient', 'external_person_id', | ||
existing_type=sa.VARCHAR(length=255), | ||
nullable=True) | ||
op.alter_column('mpi_patient', 'external_person_source', | ||
existing_type=sa.VARCHAR(length=100), | ||
nullable=True) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column('mpi_patient', 'external_person_source', | ||
existing_type=sa.VARCHAR(length=100), | ||
nullable=False) | ||
op.alter_column('mpi_patient', 'external_person_id', | ||
existing_type=sa.VARCHAR(length=255), | ||
nullable=False) | ||
op.create_index('ix_mpi_blocking_value_value', 'mpi_blocking_value', ['value'], unique=False) | ||
# ### end Alembic commands ### |
57 changes: 57 additions & 0 deletions
57
alembic/versions/ad18f1d41fad_convert_blockingkey_into_enum.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"""convert BlockingKey into enum | ||
Revision ID: ad18f1d41fad | ||
Revises: 6052c193a26a | ||
Create Date: 2024-09-17 21:15:37.714595 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = 'ad18f1d41fad' | ||
down_revision: Union[str, None] = '6052c193a26a' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table('mpi_blocking_key') | ||
op.drop_table('mpi_blocking_value') | ||
|
||
op.create_table('mpi_blocking_value', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('patient_id', sa.Integer(), nullable=False), | ||
sa.Column('blockingkey', sa.Integer(), nullable=False), | ||
sa.Column('value', sa.String(length=50), nullable=False), | ||
sa.ForeignKeyConstraint(['patient_id'], ['mpi_patient.id'], ), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_index('idx_blocking_value_patient_key_value', 'mpi_blocking_value', ['patient_id', 'blockingkey', 'value'], unique=False) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table('mpi_blocking_value') | ||
|
||
op.create_table('mpi_blocking_key', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('key', sa.String(length=50), nullable=False), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_table('mpi_blocking_value', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('patient_id', sa.Integer(), nullable=False), | ||
sa.Column('blockingkey_id', sa.Integer(), nullable=False), | ||
sa.Column('value', sa.String(length=50), nullable=False), | ||
sa.ForeignKeyConstraint(['blockingkey_id'], ['mpi_blocking_key.id'], ), | ||
sa.ForeignKeyConstraint(['patient_id'], ['mpi_patient.id'], ), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_index(op.f('ix_mpi_blocking_value_value'), 'mpi_blocking_value', ['value'], unique=False) | ||
# ### end Alembic commands ### |
43 changes: 43 additions & 0 deletions
43
alembic/versions/bfbd015ca466_moving_externalperson_to_patient_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""moving ExternalPerson to Patient table | ||
Revision ID: bfbd015ca466 | ||
Revises: ad18f1d41fad | ||
Create Date: 2024-09-18 20:10:30.193941 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = 'bfbd015ca466' | ||
down_revision: Union[str, None] = 'ad18f1d41fad' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table('mpi_external_person') | ||
op.create_index(op.f('ix_mpi_blocking_value_value'), 'mpi_blocking_value', ['value'], unique=False) | ||
op.add_column('mpi_patient', sa.Column('external_person_id', sa.String(length=255), nullable=False)) | ||
op.add_column('mpi_patient', sa.Column('external_person_source', sa.String(length=100), nullable=False)) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column('mpi_patient', 'external_person_source') | ||
op.drop_column('mpi_patient', 'external_person_id') | ||
op.drop_index(op.f('ix_mpi_blocking_value_value'), table_name='mpi_blocking_value') | ||
op.create_table('mpi_external_person', | ||
sa.Column('id', sa.INTEGER(), nullable=False), | ||
sa.Column('person_id', sa.INTEGER(), nullable=False), | ||
sa.Column('external_id', sa.VARCHAR(length=255), nullable=False), | ||
sa.Column('source', sa.VARCHAR(length=255), nullable=False), | ||
sa.ForeignKeyConstraint(['person_id'], ['mpi_person.id'], ), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
# ### end Alembic commands ### |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.