Skip to content

Commit

Permalink
try exists instead
Browse files Browse the repository at this point in the history
  • Loading branch information
m-goggins committed Feb 26, 2025
1 parent 8e21c2d commit 0a45a3e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/recordlinker/database/mpi_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from sqlalchemy import literal
from sqlalchemy import orm
from sqlalchemy import select
from sqlalchemy.sql import exists
from sqlalchemy.sql import expression

from recordlinker import models
Expand Down Expand Up @@ -405,10 +406,13 @@ def get_orphaned_persons(
cursor (in the form of a person reference_id) is provided, only retrieve Persons
with a reference_id greater than the cursor.
"""
query = (
select(models.Person)
.outerjoin(models.Patient, models.Patient.person_id == models.Person.id)
.filter(models.Patient.id.is_(None))
# query = (
# select(models.Person)
# .outerjoin(models.Patient, models.Patient.person_id == models.Person.id)
# .filter(models.Patient.id.is_(None))
# )
query = select(models.Person).filter(
~exists().where(models.Patient.person_id == models.Person.id)
)
if cursor:
query = query.filter(models.Person.id > cursor)
Expand Down

0 comments on commit 0a45a3e

Please sign in to comment.