From 52a02e2ff582ec75a8c0d431b9506fa35a5f3155 Mon Sep 17 00:00:00 2001 From: fredkingham Date: Fri, 11 May 2018 16:26:57 +0100 Subject: [PATCH 1/3] allows us to search if the patient number contains a hash --- opal/core/search/tests/test_views.py | 9 +++++++++ opal/static/js/opal/services/episode.js | 2 +- opal/static/js/test/episode.service.test.js | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/opal/core/search/tests/test_views.py b/opal/core/search/tests/test_views.py index 0efcd2a9d..4e702b4bf 100644 --- a/opal/core/search/tests/test_views.py +++ b/opal/core/search/tests/test_views.py @@ -85,6 +85,15 @@ def test_patient_exists_number(self): expected = json.loads(json.dumps(expected, cls=DjangoJSONEncoder)) self.assertEqual(expected, data) + def test_patient_number_with_hash(self): + self.patient.demographics_set.update(hospital_number="#007") + url = '/search/patient/?hospital_number=%23007' + resp = self.get_response(url) + data = json.loads(resp.content.decode('UTF-8')) + expected = [self.patient.to_dict(self.user)] + expected = json.loads(json.dumps(expected, cls=DjangoJSONEncoder)) + self.assertEqual(expected, data) + # TODO: # Searching for a patient that exists but only has episodes that are # restricted teams that the user is not a member of. diff --git a/opal/static/js/opal/services/episode.js b/opal/static/js/opal/services/episode.js index 319e80636..5ccb11493 100644 --- a/opal/static/js/opal/services/episode.js +++ b/opal/static/js/opal/services/episode.js @@ -282,7 +282,7 @@ recently changed it - refresh the page and try again'); if(number){ // The user entered a hospital number - $http.get('/search/patient/?hospital_number=' + number) + $http.get('/search/patient/?hospital_number=' + encodeURIComponent(number)) .success(function(response) { // We have retrieved patient records matching the hospital number result.patients = response; diff --git a/opal/static/js/test/episode.service.test.js b/opal/static/js/test/episode.service.test.js index efe62b217..9c1a18a66 100644 --- a/opal/static/js/test/episode.service.test.js +++ b/opal/static/js/test/episode.service.test.js @@ -339,6 +339,15 @@ describe('Episode', function() { expect(mock_new).toHaveBeenCalled(); }); + it("Should encode URIs to handle hashes", function(){ + var mock_new = jasmine.createSpy('Mock for new patient') + $httpBackend.expectGET('/search/patient/?hospital_number=%23123').respond([]); + Episode.findByHospitalNumber('#123', {newPatient: mock_new}) + $httpBackend.flush(); + $scope.$digest(); // Fire actual resolving + expect(mock_new).toHaveBeenCalled(); + }); + it('Should call the error callback on error', function () { var mock_new = jasmine.createSpy('Mock for new patient') var search_url = '/search/patient/'; From 29785fe6f88f29647853f40d2b1cc37de3e4476f Mon Sep 17 00:00:00 2001 From: David Miller Date: Fri, 15 Jun 2018 11:32:47 +0100 Subject: [PATCH 2/3] Note URIEncoding fix for findByHospitalNumber() in Changelog --- CHANGELOG.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17597c200..51a184e77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,9 @@ This also includes a change to the signature of the `.serialised()` method of th Episode manager, which no longer accepts a `episode_history` kwarg. #### Deprecates the _title property -In future we will use the standard `verbose_name` property as the display name. The abstract models have been changed to account for this. + +In future we will use the standard `verbose_name` property as the display name. +The abstract models have been changed to account for this. #### Core API registration @@ -41,7 +43,7 @@ We removed a number of superfluous templates: * opal/templates/patient_lists/spreadsheet_list.html * opal/templates/layouts/left-panel.html -#### Static asset minification +#### Static asset minification The Django upgrade in Opal 0.10 stopped compressor minifying files when DEBUG is set to False. This fixes that issue by upgrading Django compressor to @@ -62,6 +64,8 @@ override `base.html`in your application we advise that you add this `` tag * Adds the utility function `opal.core.subrecords.singletons()` which returns a generator function which will yield all subrecord singletons. +* Fixes a URI encoding bug in the `Episode.findByHospitalNumber()` method that +made hospital numbers including `#` or `/` raise an error. #### Updates to the Dependency Graph From 7c5387906f2a5db0ded48fb7daed93cd1b3f6eb1 Mon Sep 17 00:00:00 2001 From: David Miller Date: Fri, 15 Jun 2018 11:33:03 +0100 Subject: [PATCH 3/3] Add further tests for UIREncoding of hospital number search strings. --- opal/core/search/tests/test_views.py | 28 +++++++++++++++++++++ opal/static/js/test/episode.service.test.js | 27 ++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/opal/core/search/tests/test_views.py b/opal/core/search/tests/test_views.py index 4e702b4bf..76bcc0812 100644 --- a/opal/core/search/tests/test_views.py +++ b/opal/core/search/tests/test_views.py @@ -94,6 +94,34 @@ def test_patient_number_with_hash(self): expected = json.loads(json.dumps(expected, cls=DjangoJSONEncoder)) self.assertEqual(expected, data) + def test_patient_number_with_slash(self): + self.patient.demographics_set.update(hospital_number="/007") + url = '/search/patient/?hospital_number=%2F007' + resp = self.get_response(url) + data = json.loads(resp.content.decode('UTF-8')) + expected = [self.patient.to_dict(self.user)] + expected = json.loads(json.dumps(expected, cls=DjangoJSONEncoder)) + self.assertEqual(expected, data) + + def test_patient_number_with_question_mark(self): + self.patient.demographics_set.update(hospital_number="?007") + url = '/search/patient/?hospital_number=%3F007' + resp = self.get_response(url) + data = json.loads(resp.content.decode('UTF-8')) + expected = [self.patient.to_dict(self.user)] + expected = json.loads(json.dumps(expected, cls=DjangoJSONEncoder)) + self.assertEqual(expected, data) + + def test_patient_number_with_ampersand(self): + self.patient.demographics_set.update(hospital_number="&007") + url = '/search/patient/?hospital_number=%26007' + resp = self.get_response(url) + data = json.loads(resp.content.decode('UTF-8')) + expected = [self.patient.to_dict(self.user)] + expected = json.loads(json.dumps(expected, cls=DjangoJSONEncoder)) + self.assertEqual(expected, data) + + # TODO: # Searching for a patient that exists but only has episodes that are # restricted teams that the user is not a member of. diff --git a/opal/static/js/test/episode.service.test.js b/opal/static/js/test/episode.service.test.js index 9c1a18a66..e81450f77 100644 --- a/opal/static/js/test/episode.service.test.js +++ b/opal/static/js/test/episode.service.test.js @@ -348,6 +348,33 @@ describe('Episode', function() { expect(mock_new).toHaveBeenCalled(); }); + it("Should encode URIs to handle slashes", function(){ + var mock_new = jasmine.createSpy('Mock for new patient') + $httpBackend.expectGET('/search/patient/?hospital_number=%2F123').respond([]); + Episode.findByHospitalNumber('/123', {newPatient: mock_new}) + $httpBackend.flush(); + $scope.$digest(); // Fire actual resolving + expect(mock_new).toHaveBeenCalled(); + }); + + it("Should encode URIs to handle question marks", function(){ + var mock_new = jasmine.createSpy('Mock for new patient') + $httpBackend.expectGET('/search/patient/?hospital_number=%3F123').respond([]); + Episode.findByHospitalNumber('?123', {newPatient: mock_new}) + $httpBackend.flush(); + $scope.$digest(); // Fire actual resolving + expect(mock_new).toHaveBeenCalled(); + }); + + it("Should encode URIs to handle ampersands", function(){ + var mock_new = jasmine.createSpy('Mock for new patient') + $httpBackend.expectGET('/search/patient/?hospital_number=%26123').respond([]); + Episode.findByHospitalNumber('&123', {newPatient: mock_new}) + $httpBackend.flush(); + $scope.$digest(); // Fire actual resolving + expect(mock_new).toHaveBeenCalled(); + }); + it('Should call the error callback on error', function () { var mock_new = jasmine.createSpy('Mock for new patient') var search_url = '/search/patient/';