Skip to content

Commit

Permalink
Makes sure we get_or_create in the load ipc status table
Browse files Browse the repository at this point in the history
This is because the ipc status table can have multiple rows per MRN.
  • Loading branch information
fredkingham committed Apr 9, 2023
1 parent ab1e657 commit 8de49cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion plugins/ipc/management/commands/load_ipc_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ def handle(self, *args, **options):
if len(mrn) == 0:
continue
else:
patient = loader.create_rfh_patient_from_hospital_number(
# The table contains multiple results for the same
# MRN so get or create in case they have already
# recently been created.
patient, _ = loader.get_or_create_patient(
mrn, elcid_episode_categories.InfectionService
)

Expand Down
6 changes: 3 additions & 3 deletions plugins/ipc/tests/test_load_ipc_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def test_creates(self, ProdAPI):
self.assertEqual(ipc_status.comments, "A comment")

@patch('plugins.ipc.management.commands.load_ipc_status.ProdAPI')
@patch('intrahospital_api.loader.create_rfh_patient_from_hospital_number')
def test_creates_patient(self, create_rfh_patient_from_hospital_number, ProdAPI):
@patch('intrahospital_api.loader.get_or_create_patient')
def test_creates_patient(self, get_or_create_patient, ProdAPI):
ProdAPI.return_value.execute_hospital_query.return_value = [self.upstream_row]
self.upstream_row["Patient_Number"] = "234"
def create_patient():
Expand All @@ -46,7 +46,7 @@ def create_patient():
episode.save()
return patient

create_rfh_patient_from_hospital_number.side_effect = lambda x, y: create_patient()
get_or_create_patient.side_effect = lambda x, y: (create_patient(), True,)
self.cmd.handle()
self.assertTrue(
Patient.objects.filter(
Expand Down

0 comments on commit 8de49cc

Please sign in to comment.