From 08f433b090ce946bfed93796347197ff55ed6981 Mon Sep 17 00:00:00 2001 From: m-goggins Date: Thu, 20 Feb 2025 10:29:33 -0800 Subject: [PATCH] tests for get_orphaned_patients --- tests/unit/database/test_mpi_service.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/unit/database/test_mpi_service.py b/tests/unit/database/test_mpi_service.py index 37150e43..b78f0cee 100644 --- a/tests/unit/database/test_mpi_service.py +++ b/tests/unit/database/test_mpi_service.py @@ -876,3 +876,21 @@ def test_delete_persons(self, session): assert session.query(models.Person).count() == 1 assert mpi_service.get_person_by_reference_id(session, person1.reference_id) is None assert mpi_service.get_person_by_reference_id(session, person2.reference_id) == person2 + + +class TestGetOrphanedPatients: + def test_get_orphaned_patients_success(self, session): + patient = models.Patient(person=None, data={"reference_id": str(uuid.uuid4())}) + patient2 = models.Patient(person=models.Person(), data={}) + session.add_all([patient, patient2]) + session.flush() + assert session.query(models.Patient).count() == 2 + assert session.query(models.Person).count() == 1 + assert mpi_service.get_orphaned_patients(session) == [patient] + + def test_get_orphaned_patients_no_patients(self, session): + person = models.Person() + patient = models.Patient(person=person, data={}) + session.add(patient) + session.flush() + assert mpi_service.get_orphaned_patients(session) == []