Skip to content

Commit

Permalink
fix(patient groups): require notes
Browse files Browse the repository at this point in the history
This commit fixes the patient groups form making the description a
required field.  It is a required field in the database so this catches
the error on the client before it is even submitted.

Additionally, the client now uses Notify to alert the any errors on data
download or group submission.
  • Loading branch information
jniles committed Dec 5, 2017
1 parent 18d811b commit e9ff0f2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DB_NAME='bhima_test'
# session variables
SESS_SECRET='XopEn BlowFISH'

DEBUG=db
DEBUG=app

# Amazon S3 Creds
S3_ACCESS_KEY_ID=""
Expand Down
12 changes: 6 additions & 6 deletions client/src/js/directives/loading.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
angular.module('bhima.directives')
.directive('loadingIndicator', function () {
return {
restrict : 'E',
template: '<h3><p class="text-info"><span class="fa fa-circle-o-notch fa-spin"></span> <span translate>FORM.INFO.LOADING</span></p></h3>',
};
});
.directive('loadingIndicator', function () {
return {
restrict : 'E',
template: '<p><p class="text-info"><span class="fa fa-circle-o-notch fa-spin"></span> <span translate>FORM.INFO.LOADING</span></p></p>',
};
});
6 changes: 2 additions & 4 deletions client/src/modules/patients/groups/groups.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@
<tr>
<th translate> TABLE.COLUMNS.NAME </th>
<th translate> TABLE.COLUMNS.PRICE_LIST </th>
<th translate> TABLE.COLUMNS.NOTE </th>
<th translate> TABLE.COLUMNS.ACTION </th>
</tr>
</thead>
<tbody>
<tr ng-repeat="group in PatientGroupCtrl.groups track by group.uuid" ng-class="{ 'bg-primary' : group.uuid == PatientGroupCtrl.patientGroup.uuid }">
<td>{{ group.name}}</td>
<td>{{ group.priceListLable }}</td>
<td>{{ group.note }}</td>
<td>
<a class="btn btn-xs btn-default" ng-click="PatientGroupCtrl.update(group.uuid)" id="group-{{group.uuid}}">
<span class="glyphicon glyphicon-pencil"></span>
Expand All @@ -50,7 +48,7 @@
</td>
</tr>
<tr ng-if="PatientGroupCtrl.loading" class="text-center">
<td colspan="4"><loading-indicator></loading-indicator></td>
<td colspan="3"><loading-indicator></loading-indicator></td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -108,7 +106,7 @@ <h4 translate> PATIENT_GROUP.TITLE </h4>
<label class="control-label" translate>
FORM.LABELS.NOTES
</label>
<textarea class="form-control" ng-maxlength="PatientGroupCtrl.maxLength" name="note" ng-model="PatientGroupCtrl.patientGroup.note"></textarea>
<textarea class="form-control" ng-maxlength="PatientGroupCtrl.maxLength" name="note" ng-model="PatientGroupCtrl.patientGroup.note" required></textarea>
<div class="help-block" ng-messages="CreateForm.note.$error" ng-show="CreateForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
Expand Down
76 changes: 34 additions & 42 deletions client/src/modules/patients/groups/groups.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
angular.module('bhima.controllers')
.controller('PatientGroupController', PatientGroupController);
.controller('PatientGroupController', PatientGroupController);

PatientGroupController.$inject = [
'PatientGroupService', 'PriceListService', 'SessionService', '$translate', 'ModalService', 'util'
'PatientGroupService', 'PriceListService', 'SessionService', 'ModalService',
'util', 'NotifyService',
];

/**
Expand All @@ -17,7 +18,7 @@ PatientGroupController.$inject = [
*
* @constructor
*/
function PatientGroupController (PatientGroups, PriceLists, Session, $translate, ModalService, util) {
function PatientGroupController(PatientGroups, PriceLists, Session, ModalService, util, Notify) {
var vm = this;

vm.length100 = util.length100;
Expand All @@ -28,26 +29,24 @@ function PatientGroupController (PatientGroups, PriceLists, Session, $translate,

// This method is responsible of initializing data
function startup() {

// make the loading state into true, while loading data
toggleLoadingIndicator();

// fetching all price list
PriceLists.read()
.then(function (priceLists) {

// attaching the price list to the view
vm.priceLists = priceLists;
.then(function (priceLists) {

// load all patient groups
return loadPatientGroups();
})
.then(function (patientGroups) {
vm.groups = patientGroups;
// attaching the price list to the view
vm.priceLists = priceLists;

// turn off loading indicator
toggleLoadingIndicator();
});
// load all patient groups
return loadPatientGroups();
})
.then(function (patientGroups) {
vm.groups = patientGroups;
})
.catch(Notify.handleError)
.finally(toggleLoadingIndicator);
}

function toggleLoadingIndicator() {
Expand All @@ -56,7 +55,6 @@ function PatientGroupController (PatientGroups, PriceLists, Session, $translate,

// this method is responsible to propose a GUI to user for creation
function create() {

// init the patient group
vm.patientGroup = {};

Expand All @@ -66,7 +64,6 @@ function PatientGroupController (PatientGroups, PriceLists, Session, $translate,

// this function is responsible of submitting the patient group to the server for creation
function submit(form) {

// if the form is not valid do nothing
if (form.$invalid) { return; }

Expand All @@ -88,24 +85,20 @@ function PatientGroupController (PatientGroups, PriceLists, Session, $translate,
vm.groups = groups;
vm.view = 'default';
})
.catch(handler);
.catch(Notify.handleError);
}

// this function is handling error from $http server
function handler(error) {
throw error;
}

// this method is changing the view for the update
function update(uuid) {

// switch view to update
vm.view = 'update';

PatientGroups.read(uuid)
.then(function (data) {
vm.patientGroup = data;
});
.then(function (data) {
vm.patientGroup = data;
})
.catch(Notify.handleError);
}

// this function clears the selected form
Expand All @@ -115,22 +108,21 @@ function PatientGroupController (PatientGroups, PriceLists, Session, $translate,

// this function is responsible of removing a patient group
function remove() {

ModalService.confirm('FORM.DIALOGS.CONFIRM_DELETE')
.then(function (bool){
// if the user cancels, return immediately.
if (!bool) { return; }

PatientGroups.delete(vm.patientGroup.uuid)
.then(function (message) {
vm.view = 'default';
return loadPatientGroups();
})
.then(function (groups) {
vm.groups = groups;
})
.catch(handler);
});
.then(function (bool) {
// if the user cancels, return immediately.
if (!bool) { return; }

PatientGroups.delete(vm.patientGroup.uuid)
.then(function () {
vm.view = 'default';
return loadPatientGroups();
})
.then(function (groups) {
vm.groups = groups;
})
.catch(Notify.handleError);
});
}

// this method is load the list of patient group
Expand Down

0 comments on commit e9ff0f2

Please sign in to comment.