Skip to content

Commit

Permalink
Merge pull request #1594 from openhealthcare/1578-remove-active-episo…
Browse files Browse the repository at this point in the history
…de-id

1578 remove active episode
  • Loading branch information
fredkingham committed Oct 4, 2018
2 parents f869cb0 + e895238 commit e335dd7
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 22 deletions.
9 changes: 9 additions & 0 deletions changelog.md
@@ -1,5 +1,14 @@
### 0.13.0 (Major Release)


#### Removes Patient.to_dict().active_episode_id

We no longer include a value for "active_episode_id" as part of the Patient to_dict serialisation.

This is effectively meaningless since we moved to an episode model that allows for multiple
concurrent episodes.


#### Removes CopyToCategory

Removes the entire CopyToCategory flow from Opal Core. If applications continue to rely on it,
Expand Down
6 changes: 1 addition & 5 deletions opal/core/search/static/js/search/controllers/search.js
Expand Up @@ -110,11 +110,7 @@ angular.module('opal.controllers').controller(
};

$scope.getEpisodeID = function(patient){
var epid = patient.active_episode_id;
if(!epid){
epid = _.first(_.keys(patient.episodes));
}
return epid;
return _.first(_.keys(patient.episodes));
};

$scope.jumpToEpisode = function(patient){
Expand Down
11 changes: 8 additions & 3 deletions opal/core/search/static/js/test/search.controller.test.js
Expand Up @@ -172,7 +172,7 @@ describe('SearchCtrl', function (){

describe('getEpisodeId', function() {

it('should use the first episode if we have no active episode_id', function() {
it('should use the first episode', function() {
var patient = {
episodes: {
42: {}, //dummy episode
Expand All @@ -186,8 +186,13 @@ describe('SearchCtrl', function (){

describe('jumpToEpisode()', function (){
it('Should call location.path()', function () {
$scope.jumpToEpisode({active_episode_id: 555});
expect(location.path).toHaveBeenCalledWith('/episode/555');
$scope.jumpToEpisode({
episodes: {
555: {},
8492: {}
}
});
expect(location.path).toHaveBeenCalledWith('/episode/555');
});
});

Expand Down
4 changes: 1 addition & 3 deletions opal/models.py
Expand Up @@ -577,12 +577,10 @@ def bulk_update(self, dict_of_list_of_upgrades, user,
force=force)

def to_dict(self, user):
active_episode = self.get_active_episode()
d = {
'id': self.id,
'episodes': {episode.id: episode.to_dict(user) for episode in
self.episode_set.all()},
'active_episode_id': active_episode.id if active_episode else None,
self.episode_set.all()}
}

for model in patient_subrecords():
Expand Down
28 changes: 23 additions & 5 deletions opal/static/js/opal/controllers/hospital_number.js
Expand Up @@ -67,19 +67,37 @@ angular.module('opal.controllers').controller(
addPatient(demographics);
};

$scope.newForPatient = function(patient){
if (patient.active_episode_id &&
$scope._active_episode_id = function(patient){
var active_ids = _.filter(
_.values(patient.episodes),
function(x){ return x.active == true }
);
if(active_ids.length){
return active_ids[0].id
}else{
return null;
}
}

$scope.newForPatient = function(patient){

var first_active_episode_id = $scope._active_episode_id(patient);

if (first_active_episode_id &&
// Check to see that this episode is not "Discharged"
patient.episodes[patient.active_episode_id].location[0].category != 'Discharged') {
patient.episodes[first_active_episode_id].location[0].category != 'Discharged') {
// This patient has an active episode
$scope.newForPatientWithActiveEpisode(patient);
} else { // This patient has no active episode
$scope.addForPatient(patient);
};
};

$scope.newForPatientWithActiveEpisode = function(patient){
episode = new Episode(patient.episodes[patient.active_episode_id])
$scope.newForPatientWithActiveEpisode = function(patient){

var first_active_episode_id = $scope._active_episode_id(patient);

episode = new Episode(patient.episodes[first_active_episode_id])

if(episode.category_name != 'Inpatient'){ // It's the wrong category - add new
return $scope.addForPatient(patient);
Expand Down
9 changes: 4 additions & 5 deletions opal/static/js/test/hospital_number.controller.test.js
Expand Up @@ -66,7 +66,6 @@ describe('HospitalNumberCtrl', function(){


_patientData = {
"active_episode_id": null,
"demographics": [
{
"consistency_token": "0beb0d46",
Expand Down Expand Up @@ -279,7 +278,7 @@ describe('HospitalNumberCtrl', function(){
var deferred, callArgs;
spyOn($scope, 'newForPatientWithActiveEpisode');

patientData.active_episode_id = 3;
patientData.episodes["3"].active = true;

deferred = $q.defer();
spyOn($modal, 'open').and.returnValue({result: deferred.promise});
Expand All @@ -299,7 +298,7 @@ describe('HospitalNumberCtrl', function(){

it('should call through if there is an active episode.', function(){
spyOn($scope, 'newForPatientWithActiveEpisode');
patientData.active_episode_id = 3;
patientData.episodes["3"].active = true;
patientData.episodes[3].location[0].category = 'Inpatient'

$scope.newForPatient(patientData);
Expand Down Expand Up @@ -372,8 +371,8 @@ describe('HospitalNumberCtrl', function(){
var activePatientData;

beforeEach(function(){
activePatientData = angular.copy(patientData);
activePatientData.active_episode_id = 3;
activePatientData = angular.copy(patientData);
activePatientData.episodes["3"].active = true;
})

describe('if not an inpatient', function(){
Expand Down
1 change: 0 additions & 1 deletion opal/static/js/test/test_helper.js
Expand Up @@ -49,7 +49,6 @@

var patientData = {
id: 1,
active_episode_id: "123",
demographics: demographics,
episodes: {
"123": episodeData
Expand Down

0 comments on commit e335dd7

Please sign in to comment.