Skip to content

Commit

Permalink
discharge an episode if its on the list and you want to add the same …
Browse files Browse the repository at this point in the history
…hospital number, needs unit tests
  • Loading branch information
fredkingham committed Feb 20, 2017
1 parent 8b9603d commit f035a66
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 21 deletions.
1 change: 1 addition & 0 deletions elcid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Application(application.OpalApplication):
javascripts = [
'js/elcid/routes.js',
'js/elcid/controllers/discharge.js',
'js/elcid/controllers/confirm_discharge.js',
'js/elcid/controllers/diagnosis_hospital_number.js',
'js/elcid/controllers/diagnosis_add_episode.js',
'js/elcid/controllers/diagnosis_discharge.js',
Expand Down
46 changes: 46 additions & 0 deletions elcid/assets/js/elcid/controllers/confirm_discharge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* is a patient is currently on the list, give the option to discharge
*/
angular.module('opal.controllers').controller('ConfirmDischargeCtrl', function(
$scope, $modal, $modalInstance, DischargePatientService,
patient, episode, tags, context
){
$scope.newPatient = function(result){
// There is no patient with this hospital number
// Show user the form for creating a new episode,
// with the hospital number pre-populated
modal = $modal.open({
backdrop: 'static',
templateUrl: '/templates/modals/add_episode.html',
controller: 'DiagnosisAddEpisodeCtrl',
resolve: {
referencedata: function(Referencedata) { return Referencedata; },
demographics: function() {
return patient.demographics[0];
},
tags: function(){ return tags; }
}
}).result.then(function(result) {
// The user has created the episode, or cancelled
if(result.then){
result.then(function(r){
$modalInstance.close(r);
});
}else{
$modalInstance.close(result);
}
});
};

$scope.confirm = function(){
var dischargePatientService = new DischargePatientService();
dischargePatientService.discharge(episode, {category: "Discharged"}, tags).then(function(){
context.removeFromList(episode.id);
$scope.newPatient(patient);
});
};

$scope.cancel = function(){
$modalInstance.close();
};
});
2 changes: 1 addition & 1 deletion elcid/assets/js/elcid/controllers/diagnosis_discharge.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ controllers.controller(
growl.success($scope.episode.demographics[0].first_name + ' ' + $scope.episode.demographics[0].surname + ' discharged.');
}
$scope.discharged = true;
$modalInstance.close('discharged');
$modalInstance.close('discharged', episode);
});
});

Expand Down
59 changes: 40 additions & 19 deletions elcid/assets/js/elcid/controllers/diagnosis_hospital_number.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ angular.module('opal.controllers').controller(
$q,
Episode,
tags,
context,
hospital_number
){

$scope.model = {}
$scope.model = {};
if(hospital_number){
$scope.model.hospitalNumber = hospital_number;
}
Expand Down Expand Up @@ -88,24 +89,44 @@ angular.module('opal.controllers').controller(
return $scope.addForPatient(patient);
}

if (episode.tagging[0][$scope.tags.tag] &&
($scope.tags.subtag === "" ||
episode.tagging[0][$scope.tags.subtag])) {
// There is already an active episode for this patient
// with the current tag
$modalInstance.close(episode);
} else {
// There is already an active episode for this patient but
// it doesn't have the current tag.
// Add the current Tag.
episode.tagging[0][$scope.tags.tag] = true;
if($scope.tags.subtag !== ""){
episode.tagging[0][$scope.tags.subtag] = true;
}
episode.tagging[0].save(episode.tagging[0].makeCopy()).then(
function(){
$modalInstance.close(episode);
});
if(episode.location[0].category == 'Followup'){
modal = $modal.open({
templateUrl: '/templates/modals/confirm_discharge.html',
controller: 'ConfirmDischargeCtrl',
resolve: {
patient: function() { return patient; },
episode: function() { return episode; },
tags: function(){ return $scope.tags; },
context: function(){ return context; }
}
}).result.then(
function(result){
$modalInstance.close(result);
},
function(result){
$modalInstance.close(result);
});
}
else{
if (episode.tagging[0][$scope.tags.tag] &&
($scope.tags.subtag === "" ||
episode.tagging[0][$scope.tags.subtag])) {
// There is already an active episode for this patient
// with the current tag
$modalInstance.close(episode);
} else {
// There is already an active episode for this patient but
// it doesn't have the current tag.
// Add the current Tag.
episode.tagging[0][$scope.tags.tag] = true;
if($scope.tags.subtag !== ""){
episode.tagging[0][$scope.tags.subtag] = true;
}
episode.tagging[0].save(episode.tagging[0].makeCopy()).then(
function(){
$modalInstance.close(episode);
});
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ describe('DiagnosisHospitalNumber', function(){
$scope : $scope,
$modalInstance : modalInstance,
tags : {},
hospital_number: hospital_number
hospital_number: hospital_number,
context: {ctx: 'some context'}
});
});

Expand Down Expand Up @@ -81,6 +82,9 @@ describe('DiagnosisHospitalNumber', function(){
hospital_number: "1",
patient_id: "1",
}],
location: [{
category: "Discharged"
}],
category_name: "Inpatient"
}},
demographics: [{
Expand Down Expand Up @@ -122,6 +126,17 @@ describe('DiagnosisHospitalNumber', function(){
$scope.newForPatientWithActiveEpisode(patient);
expect($scope.addForPatient).toHaveBeenCalled();
});
fit('if the patient is marked for follow up we should call the confirm discharge modal', function(){
var patient = angular.copy(patientData);
patient.episodes['1'].location[0].category = "Followup";
spyOn($modal, "open").and.returnValue({result: {then: function(x, y){}}});
$scope.newForPatientWithActiveEpisode(patient);
expect($modal.open).toHaveBeenCalled();
var modalArgs = $modal.open.calls.argsFor(0)[0];
expect(modalArgs.templateUrl).toBe('/templates/modals/confirm_discharge.html');
expect(modalArgs.controller).toBe('ConfirmDischargeCtrl');
expect(modalArgs.resolve.context()).toEqual({ctx: 'some context'});
});
});

describe('addForPatient()', function() {
Expand Down
21 changes: 21 additions & 0 deletions elcid/templates/modals/confirm_discharge.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends 'base_templates/form_modal_base.html' %}
{% load forms %}
{% block icon_name %}glyphicon glyphicon-plus{% endblock %}
{% block title %}Confirm Addition{% endblock %}
{% block modal_body %}
<form class="form-horizontal text-center" name="form">
<p class="lead">
The Patient is already on the list, awaiting follow up tasks from their discharge.
</p>
<p class="lead">
Would you like to close this episode of care and readmit the patient?
</p>
<span ng-show="form">
<button one-click-only class="btn btn-primary" ng-click="confirm()">
<i class="fa fa-save"></i>
Confirm
</button>
</span>
</form>
{% endblock %}
{% block modal_save %}{% endblock %}

0 comments on commit f035a66

Please sign in to comment.