Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Adding the Admitted patients list
Browse files Browse the repository at this point in the history
addresses #349
  • Loading branch information
Darin Swanson committed Mar 15, 2016
1 parent f5fb033 commit 868d5b0
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 0 deletions.
34 changes: 34 additions & 0 deletions app/patients/admitted/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import AbstractPagedController from 'hospitalrun/controllers/abstract-paged-controller';
import PatientVisits from 'hospitalrun/mixins/patient-visits';
export default AbstractPagedController.extend(PatientVisits, {
addPermission: 'add_patient',
deletePermission: 'delete_patient',
canAdmitPatient: function() {
return this.currentUserCan('admit_patient');
}.property(),

canDischargePatient: function() {
return this.currentUserCan('discharge_patient');
}.property(),

startKey: [],
actions: {
admitPatient: function(patient) {
this.getPatientVisits(patient).then(function(visits) {
this.send('createNewVisit', patient, visits);
}.bind(this));

},

dischargePatient: function(patient) {
this.getPatientVisits(patient).then(function(visits) {
var visitToDischarge = visits.findBy('status', 'Admitted');
if (visitToDischarge) {
visitToDischarge.set('status', 'Discharged');
visitToDischarge.set('endDate', new Date());
this.transitionToRoute('visits.edit', visitToDischarge);
}
}.bind(this));
}
}
});
19 changes: 19 additions & 0 deletions app/patients/admitted/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import AbstractIndexRoute from 'hospitalrun/routes/abstract-index-route';
export default AbstractIndexRoute.extend({
modelName: 'patient',
pageTitle: 'Admitted patients',

_getStartKeyFromItem: function(item) {
var displayPatientId = item.get('displayPatientId');
return [displayPatientId, 'patient_' + item.get('id')];
},

_modelQueryParams: function() {
return {
options: {
key: true
},
mapReduce: 'patient_by_admission'
};
}
});
55 changes: 55 additions & 0 deletions app/patients/admitted/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{{#item-listing paginationProps=paginationProps }}
{{#if hasRecords}}
<table class="table">
<thead>
<tr class="table-header">
{{#sortable-column sortBy='id' sortDesc=sortDesc sortKey=sortKey }}ID{{/sortable-column}}
{{#sortable-column sortBy='firstName' sortDesc=sortDesc sortKey=sortKey }}First Name{{/sortable-column}}
{{#sortable-column sortBy='lastName' sortDesc=sortDesc sortKey=sortKey }}Last Name{{/sortable-column}}
{{#sortable-column sortBy='sex' sortDesc=sortDesc sortKey=sortKey }}Sex{{/sortable-column}}
{{#sortable-column sortBy='dateOfBirth' sortDesc=sortDesc sortKey=sortKey }}DOB{{/sortable-column}}
{{#sortable-column sortBy='status' sortDesc=sortDesc sortKey=sortKey }}Status{{/sortable-column}}
{{#if showActions}}
<th>{{t 'labels.actions'}}</th>
{{/if}}
</tr>
</thead>
<tbody>
{{#each model as |patient|}}
<tr {{action 'editItem' patient}}>
<td>{{patient.displayPatientId}}</td>
<td>{{patient.firstName}}</td>
<td>{{patient.lastName}}</td>
<td>{{patient.sex}}</td>
<td>{{date-format patient.dateOfBirth}}</td>
<td>{{patient.status}}</td>
{{#if showActions}}
<td>
{{#if canAdd}}
<button class="btn btn-default neutral" {{action 'editItem' patient bubbles=false }}>{{t 'labels.edit'}}</button>
{{/if}}
{{#unless patient.admitted}}
{{#if canAdmitPatient}}
<button class="btn btn-default success" {{action 'admitPatient' patient bubbles=false }}><span class="glyphicon glyphicon-log-in"></span> Admit</button>
{{/if}}
{{/unless}}
{{#if patient.admitted}}
{{#if canDischargePatient}}
<button class="btn btn-default info" {{action 'dischargePatient' patient bubbles=false }}><span class="glyphicon glyphicon-log-out"></span> Discharge</button>
{{/if}}
{{/if}}
{{#if canDelete}}
<button class="btn btn-default warning" {{action 'deleteItem' patient bubbles=false }}><span class="octicon octicon-x"></span> Delete</button>
{{/if}}
</td>
{{/if}}
</tr>
{{/each}}
</tbody>
</table>
{{else}}
<div class="alert alert-info" data-test-selector="no-patients-found">
<p>No patients found. {{#if canAdd}}<a href="#" {{action 'newItem'}}>Create a new patient record?</a>{{/if}}</p>
</div>
{{/if}}
{{/item-listing}}
3 changes: 3 additions & 0 deletions app/patients/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ export default AbstractModuleRoute.extend(PatientId, {
subActions: [{
text: 'Patient listing',
linkTo: 'patients.index'
}, {
text: 'Admitted patients',
linkTo: 'patients.admitted'
}, {
text: 'Reports',
linkTo: 'patients.reports'
Expand Down
1 change: 1 addition & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Router.map(function() {
}, function() {
this.route('edit', { path: '/edit/:patient_id' });
this.route('reports');
this.route('admitted');
this.route('search', { path: '/search/:search_text' });
});

Expand Down
6 changes: 6 additions & 0 deletions app/utils/pouch-views.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@ var designDocs = [{
'emit(doc.data.status);'
),
version: 2
},{
name: 'patient_by_admission',
function: generateView('patient',
'emit(doc.data.admitted);'
),
version: 1
}, {
name: 'photo_by_patient',
function: generateView('photo',
Expand Down

0 comments on commit 868d5b0

Please sign in to comment.