Skip to content

Commit

Permalink
Merge branch '456-changed-hospital-number' into v0.3.5.rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkingham committed Aug 1, 2018
2 parents 0569d27 + c5bd4c7 commit 732c133
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
24 changes: 24 additions & 0 deletions intrahospital_api/test/test_update_demographics.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,30 @@ def test_update_patient_demographics_have_changed(self, demographics):
"Janey"
)

def test_demographics_passed_in(self, demographics):
update_demographics.update_patient_demographics(
self.patient, dict(first_name="Janey")
)
self.assertEqual(
self.patient.demographics_set.first().first_name,
"Janey"
)
self.assertFalse(demographics.called)

def test_no_patient_demographics(self, demographics):
# Tests the edge case of where no demographics are found
demographics.return_value = None
update_demographics.update_patient_demographics(self.patient)
self.assertEqual(
self.patient.demographics_set.first().first_name, "Jane"
)
self.assertEqual(
self.patient.demographics_set.first().surname, "Bloggs"
)
self.assertIsNone(
self.patient.demographics_set.first().updated
)

def test_update_patient_demographics_have_not_changed(self, demographics):
demographics.return_value = dict(first_name="Jane")
update_demographics.update_patient_demographics(self.patient)
Expand Down
27 changes: 17 additions & 10 deletions intrahospital_api/update_demographics.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,32 @@ def is_reconcilable(patient, external_demographics_dict):
def have_demographics_changed(
upstream_demographics, our_demographics_model
):
""" checks to see i the demographics have changed
if they haven't, don't bother updating
""" checks to see i the demographics have changed
if they haven't, don't bother updating
only compares keys that are coming from the
upstream dict
"""
as_dict = our_demographics_model.to_dict(api.user)
relevent_keys = set(upstream_demographics.keys())
our_dict = {i: v for i, v in as_dict.items() if i in relevent_keys}
return not upstream_demographics == our_dict
only compares keys that are coming from the
upstream dict
"""
as_dict = our_demographics_model.to_dict(api.user)
relevent_keys = set(upstream_demographics.keys())
our_dict = {i: v for i, v in as_dict.items() if i in relevent_keys}
return not upstream_demographics == our_dict


def update_patient_demographics(patient, upstream_demographics_dict=None):
""" Updates a patient with the upstream demographics, if they have changed.
"""
Updates a patient with the upstream demographics, if they have changed.
"""
if upstream_demographics_dict is None:
upstream_demographics_dict = api.demographics(
patient.demographics_set.first().hospital_number
)
# this should never really happen but has..
# It happens in the case of a patient who has previously
# matched with WinPath but who's hospital_number has
# then been changed by the admin.
if upstream_demographics_dict is None:
return

demographics = patient.demographics_set.get()
if have_demographics_changed(
Expand Down

0 comments on commit 732c133

Please sign in to comment.