Skip to content

Commit

Permalink
fixes a bug where we are generating the summary based on patient id n…
Browse files Browse the repository at this point in the history
…ot episode id...
  • Loading branch information
fredkingham committed Aug 21, 2017
1 parent 4a513d2 commit b1b2f90
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions opal/core/search/tests/test_views.py
Expand Up @@ -223,6 +223,33 @@ def test_number_of_queries(self):
with self.assertNumQueries(35):
self.get_response('{}/?query=Blofelt'.format(self.url))

def test_with_multiple_patient_episodes(self):
self.patient.create_episode()
blofeld_patient, blofeld_episode = self.create_patient(
"Ernst", "Blofeld", "23422"
)
response = json.loads(
self.get_response('{}/?query=Blofeld'.format(self.url)).content
)
expected = {
"total_pages": 1,
"object_list": [{
"count": 1,
"first_name": "Ernst",
"surname": "Blofeld",
"start": None,
"patient_id": 2,
"hospital_number": "23422",
"date_of_birth": None,
"end": None,
"id": 2,
"categories": ["Inpatient"]
}],
"page_number": 1,
"total_count": 1
}
self.assertEqual(response, expected)


class SearchTemplateTestCase(OpalTestCase):

Expand Down
2 changes: 1 addition & 1 deletion opal/core/search/views.py
Expand Up @@ -99,7 +99,7 @@ def simple_search_view(request):
paginated = _add_pagination(patients, page_number)
paginated_patients = paginated["object_list"]
episodes = models.Episode.objects.filter(
id__in=paginated_patients.values_list("id", flat=True)
id__in=paginated_patients.values_list("episode__id", flat=True)
)
paginated["object_list"] = query.get_aggregate_patients_from_episodes(
episodes
Expand Down

0 comments on commit b1b2f90

Please sign in to comment.