Skip to content

Commit

Permalink
add endpoint for returning oprhaned patient data
Browse files Browse the repository at this point in the history
  • Loading branch information
m-goggins committed Feb 20, 2025
1 parent bba6265 commit 55afb49
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/recordlinker/database/mpi_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,12 @@ def delete_persons(
session.delete(person)
if commit:
session.commit()


def get_orphaned_patients(
session: orm.Session,
) -> typing.Sequence[schemas.PatientRefs]:
"""
Retrieve all the orphaned Patients in the MPI database.
"""
return session.scalars(select(models.Patient).where(models.Patient.person_id.is_(None))).all()
17 changes: 17 additions & 0 deletions src/recordlinker/routes/patient_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ def create_patient(
)


@router.get(
"/orphaned", summary="Retrieve orphaned patients", status_code=fastapi.status.HTTP_200_OK
)
def get_orphaned_patients(
session: orm.Session = fastapi.Depends(get_session),
) -> schemas.PatientRefs | None:
"""
Retrieve patient_reference_id(s) for all Patients that are not linked to a Person.
"""
patients = service.get_orphaned_patients(session)
if not patients:
return None
return schemas.PatientRefs(
patients=[p.reference_id for p in patients if p.reference_id is not None]
)


@router.get(
"/{patient_reference_id}",
summary="Retrieve a patient record",
Expand Down

0 comments on commit 55afb49

Please sign in to comment.