-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
2,121 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
angular.module('opal.services').factory('DemographicsSearch', function($q, $http, $window, Patient, ngProgressLite) { | ||
"use strict"; | ||
/* | ||
* The demographics search used by the find patient | ||
* pathway. | ||
*/ | ||
|
||
var url = '/elcid/v0.1/demographics_search/'; | ||
|
||
// we have four call backs that we are expecting | ||
|
||
// patient is found in elcid (Yay!) | ||
var PATIENT_FOUND_IN_ELCID = "patient_found_in_elcid"; | ||
|
||
// patient is not found in elcid but is found | ||
// in the hospital (Yay!) | ||
var PATIENT_FOUND_UPSTREAM = "patient_found_upstream"; | ||
|
||
// patient is not found | ||
var PATIENT_NOT_FOUND = "patient_not_found"; | ||
|
||
var expectedStatuses = [ | ||
PATIENT_FOUND_IN_ELCID, | ||
PATIENT_FOUND_UPSTREAM, | ||
PATIENT_NOT_FOUND, | ||
] | ||
|
||
var find = function(hospitalNumber, findPatientOptions){ | ||
ngProgressLite.set(0); | ||
ngProgressLite.start(); | ||
var callBackNames = _.keys(findPatientOptions); | ||
_.each(callBackNames, function(key){ | ||
if(expectedStatuses.indexOf(key) === -1){ | ||
throw "unknown call back"; | ||
} | ||
}); | ||
var patientUrl = url + hospitalNumber + "/" | ||
$http.get(patientUrl).then(function(response) { | ||
ngProgressLite.done(); | ||
if(response.data.status == PATIENT_FOUND_IN_ELCID){ | ||
findPatientOptions[PATIENT_FOUND_IN_ELCID](response.data.patient); | ||
} | ||
else if(response.data.status == PATIENT_FOUND_UPSTREAM){ | ||
findPatientOptions[PATIENT_FOUND_UPSTREAM](response.data.patient); | ||
} | ||
else if(response.data.status == PATIENT_NOT_FOUND){ | ||
findPatientOptions[PATIENT_NOT_FOUND](response.data.patient); | ||
} | ||
else{ | ||
$window.alert('DemographicsSearch could not be loaded'); | ||
} | ||
}, function(){ | ||
ngProgressLite.done(); | ||
$window.alert('DemographicsSearch could not be loaded'); | ||
}); | ||
} | ||
|
||
return { | ||
find: find | ||
}; | ||
}); |
149 changes: 149 additions & 0 deletions
149
elcid/assets/js/elcidtest/demographics_search.service.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
describe("DemographicsSearch", function(){ | ||
"use strict"; | ||
|
||
var DemographicsSearch, $rootScope, $httpBackend, $window, ngProgressLite; | ||
|
||
beforeEach(function(){ | ||
module('opal.services', function($provide){ | ||
ngProgressLite = jasmine.createSpyObj([ | ||
"set", "start", "done" | ||
]) | ||
$provide.service('ngProgressLite', function(){ | ||
return ngProgressLite | ||
}); | ||
|
||
}); | ||
inject(function($injector){ | ||
DemographicsSearch = $injector.get('DemographicsSearch'); | ||
$rootScope = $injector.get('$rootScope'); | ||
$httpBackend = $injector.get('$httpBackend'); | ||
$window = $injector.get('$window'); | ||
}); | ||
}); | ||
|
||
afterEach(function() { | ||
$httpBackend.verifyNoOutstandingExpectation(); | ||
$httpBackend.verifyNoOutstandingRequest(); | ||
}); | ||
|
||
it('should blow up if we pass in an unknown call back', function(){ | ||
expect(function(){ | ||
DemographicsSearch.find( | ||
"1231231221", | ||
{ | ||
blahblah: function(){} | ||
}); | ||
}).toThrow("unknown call back"); | ||
|
||
}); | ||
|
||
it('should call find patient found in elcid', function(){ | ||
var called_result = false; | ||
$httpBackend.expectGET('/elcid/v0.1/demographics_search/52/').respond( | ||
{status: "patient_found_in_elcid", patient: "some_patient"} | ||
); | ||
|
||
DemographicsSearch.find( | ||
"52", | ||
{ | ||
patient_found_in_elcid: function(some_result){ | ||
called_result = some_result; | ||
} | ||
}); | ||
|
||
$rootScope.$apply(); | ||
$httpBackend.flush(); | ||
expect(called_result).toBe("some_patient"); | ||
}); | ||
|
||
it('should call done on the ng progress lite', function(){ | ||
var called_result = false; | ||
$httpBackend.expectGET('/elcid/v0.1/demographics_search/52/').respond( | ||
{status: "patient_found_in_elcid", patient: "some_patient"} | ||
); | ||
|
||
DemographicsSearch.find( | ||
"52", | ||
{ | ||
patient_found_in_elcid: function(some_result){ | ||
called_result = some_result; | ||
} | ||
}); | ||
|
||
$rootScope.$apply(); | ||
$httpBackend.flush(); | ||
expect(ngProgressLite.set).toHaveBeenCalledWith(0); | ||
expect(ngProgressLite.start).toHaveBeenCalled(); | ||
expect(ngProgressLite.done).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call patient found in hosptial', function(){ | ||
var called_result = false; | ||
$httpBackend.expectGET('/elcid/v0.1/demographics_search/52/').respond( | ||
{status: "patient_found_upstream", patient: "some_patient"} | ||
); | ||
|
||
DemographicsSearch.find( | ||
"52", | ||
{ | ||
patient_found_upstream: function(some_result){ | ||
called_result = some_result; | ||
} | ||
}); | ||
|
||
$rootScope.$apply(); | ||
$httpBackend.flush(); | ||
expect(called_result).toBe("some_patient"); | ||
}); | ||
|
||
it('should call patient not found', function(){ | ||
var called_result = false; | ||
$httpBackend.expectGET('/elcid/v0.1/demographics_search/52/').respond( | ||
{status: "patient_found_upstream"} | ||
); | ||
|
||
DemographicsSearch.find( | ||
"52", | ||
{ | ||
patient_found_upstream: function(some_result){ | ||
called_result = undefined; | ||
} | ||
}); | ||
|
||
$rootScope.$apply(); | ||
$httpBackend.flush(); | ||
expect(_.isUndefined(called_result)).toBe(true); | ||
}); | ||
|
||
it('should raise an alert if an unknown status is returned', function(){ | ||
spyOn($window, "alert"); | ||
var called_result = false; | ||
$httpBackend.expectGET('/elcid/v0.1/demographics_search/52/').respond( | ||
{status: "blah blah"} | ||
); | ||
|
||
DemographicsSearch.find("52"); | ||
|
||
$rootScope.$apply(); | ||
$httpBackend.flush(); | ||
expect($window.alert).toHaveBeenCalledWith( | ||
"DemographicsSearch could not be loaded" | ||
) | ||
}); | ||
|
||
it('should blow up if the search errors', function(){ | ||
spyOn($window, "alert"); | ||
var called_result = false; | ||
$httpBackend.expectGET('/elcid/v0.1/demographics_search/52/').respond( | ||
500, "NO" | ||
); | ||
|
||
DemographicsSearch.find("52"); | ||
|
||
$rootScope.$apply(); | ||
$httpBackend.flush(); | ||
expect($window.alert).toHaveBeenCalledWith( | ||
"DemographicsSearch could not be loaded" | ||
) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.