Skip to content

Commit

Permalink
Merge pull request #1415 from openhealthcare/patient-list-refresh
Browse files Browse the repository at this point in the history
Port the detail controller .refresh() function to the list controller
  • Loading branch information
pacharanero committed Feb 21, 2018
2 parents 42c0c7b + 6ebaaaa commit eac54eb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
19 changes: 18 additions & 1 deletion opal/static/js/opal/controllers/patient_list.js
Expand Up @@ -3,7 +3,8 @@ angular.module('opal.controllers').controller(
$location, $routeParams,
$modal, $rootScope, $window, $injector,
growl, Flow, Item, Episode,
episodedata, metadata, profile, episodeVisibility){
episodedata, metadata, profile, episodeLoader,
episodeVisibility){

$scope.ready = false;
var version = window.version;
Expand Down Expand Up @@ -92,6 +93,22 @@ angular.module('opal.controllers').controller(

$scope.ready = true;

//
// Reload a single episode from the server.
// Useful for Pathway callbacks.
//
$scope.refresh = function(episode_id){
episodeLoader(episode_id).then(
function(episode){
$scope.episodes[episode_id] = episode;
if($scope.episode.id == episode_id){
$scope.episode = episode;
}
$scope.rows = $scope.getVisibleEpisodes()
}
)
}

//
// This is used to be callable we can pass to
// the table row iterator in the spreadsheet template.
Expand Down
24 changes: 23 additions & 1 deletion opal/static/js/test/patient_list.controller.test.js
Expand Up @@ -207,8 +207,30 @@ describe('PatientListCtrl', function() {

});

describe('refresh()', function() {
it('should update .episodes with what the server thinks is the episode', function() {
var updated = angular.copy(episodeData)
updated.active = false;

$httpBackend.expectGET('/api/v0.1/record/').respond({})
$httpBackend.expectGET('/api/v0.1/episode/123/').respond(updated);
$scope.refresh(123);

$httpBackend.flush();
$rootScope.$apply();

//
// We just check against the active property because this means
// that the object we're accessing has definitely been cycled
// from the server response
//
expect($scope.episodes['123'].active).toBe(false);
expect($scope.rows[0].active).toEqual(false);
});
});

describe('isSelectedEpisode()', function() {
it('should say yes when given the episode', function() {
it('should say yes when given the episode', function() {
expect($scope.isSelectedEpisode($scope.episode)).toBe(true);
});

Expand Down

0 comments on commit eac54eb

Please sign in to comment.