Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allows us to search if the patient number contains a hash #1526

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -62,6 +64,8 @@ override `base.html`in your application we advise that you add this `<meta>` 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

Expand Down
37 changes: 37 additions & 0 deletions opal/core/search/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,43 @@ 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)

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.
Expand Down
2 changes: 1 addition & 1 deletion opal/static/js/opal/services/episode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 36 additions & 0 deletions opal/static/js/test/episode.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,42 @@ 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 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/';
Expand Down