Skip to content

Commit

Permalink
Show past drug orders
Browse files Browse the repository at this point in the history
  • Loading branch information
djazayeri committed Nov 5, 2014
1 parent 6942ec9 commit ab206a1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 8 deletions.
8 changes: 8 additions & 0 deletions omod/src/main/compass/sass/drugOrders.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ form#new-order {
}
}

#past-drug-orders {
color: $darkerGrey;

&:hover {
color: $text;
}
}

.css-form {
.ng-dirty.ng-invalid {
background-color: $error;
Expand Down
21 changes: 18 additions & 3 deletions omod/src/main/webapp/pages/drugOrders.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ ${ ui.includeFragment("coreapps", "patientHeader", [ patient: patient ]) }
</div>

<h3>Active Drug Orders</h3>
<span ng-hide="activeDrugOrders.length > 0">None</span>
<table>
<span ng-show="activeDrugOrders.loading">${ ui.message("uicommons.loading.placeholder") }</span>
<span ng-hide="activeDrugOrders.loading || activeDrugOrders.length > 0">None</span>
<table ng-hide="activeDrugOrders.loading">
<tr ng-repeat="order in activeDrugOrders">
<td ng-class="{ 'will-replace': replacementFor(order) }">
{{ order | dates }}
Expand All @@ -167,7 +168,21 @@ ${ ui.includeFragment("coreapps", "patientHeader", [ patient: patient ]) }
</table>

<h3>Past Drug Orders</h3>
To Do
<span ng-show="pastDrugOrders.loading">${ ui.message("uicommons.loading.placeholder") }</span>
<span ng-hide="pastDrugOrders.loading || pastDrugOrders.length > 0">None</span>
<table id="past-drug-orders" ng-hide="pastDrugOrders.loading">
<tr ng-repeat="order in pastDrugOrders">
<td>
{{ replacementForPastOrder(order) | replacement }}
</td>
<td>
{{ order | dates }}
</td>
<td>
{{ order | instructions }}
</td>
</tr>
</table>
</div>
</div>

Expand Down
46 changes: 41 additions & 5 deletions omod/src/main/webapp/resources/scripts/drugOrders.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ angular.module('drugOrders', ['orderService', 'encounterService', 'uicommons.fil

filter('dates', ['omrsDateFilter', function(omrsDateFilter) {
return function(order) {
if (!order || typeof order != 'object') {
return "";
}
if (order.action === 'DISCONTINUE' || !order.dateActivated) {
return "";
} else {
var text = omrsDateFilter(order.dateActivated);
if (order.autoExpireDate) {
if (order.dateStopped) {
text += ' - ' + omrsDateFilter(order.dateStopped);
}
else if (order.autoExpireDate) {
text += ' - ' + omrsDateFilter(order.autoExpireDate);
}
return text;
Expand All @@ -30,6 +36,9 @@ angular.module('drugOrders', ['orderService', 'encounterService', 'uicommons.fil

filter('instructions', function() {
return function(order) {
if (!order || typeof order != 'object') {
return "";
}
if (order.action == 'DISCONTINUE') {
return "Discontinue " + (order.drug ? order.drug : order.concept ).display;
}
Expand All @@ -43,13 +52,23 @@ angular.module('drugOrders', ['orderService', 'encounterService', 'uicommons.fil
}
}).

filter('replacement', ['omrsDateFilter', function(omrsDateFilter) {
// given the order that replaced the one we are displaying, display the details of the replacement
return function(replacementOrder) {
if (!replacementOrder) {
return "";
}
return replacementOrder.action + "d on " + omrsDateFilter(replacementOrder.dateActivated);
}
}]).

controller('DrugOrdersCtrl', ['$scope', '$window', '$location', '$timeout', 'OrderService', 'EncounterService',
function($scope, $window, $location, $timeout, OrderService, EncounterService) {

// TODO changing dosingType of a draft order should reset defaults (and discard non-defaulted properties)

function loadExistingOrders() {
$scope.activeDrugOrders = [];
$scope.activeDrugOrders = { loading: true };
OrderService.getOrders({
t: 'drugorder',
v: 'full',
Expand All @@ -58,7 +77,17 @@ angular.module('drugOrders', ['orderService', 'encounterService', 'uicommons.fil
}).then(function(results) {
$scope.activeDrugOrders = _.map(results, function(item) { return new OpenMRS.DrugOrderModel(item) });
});
// TODO also load past orders, once REST supports this

$scope.pastDrugOrders = { loading: true };
OrderService.getOrders({
t: 'drugorder',
v: 'full',
patient: config.patient.uuid,
careSetting: $scope.careSetting.uuid,
status: 'inactive'
}).then(function(results) {
$scope.pastDrugOrders = _.map(results, function(item) { return new OpenMRS.DrugOrderModel(item) });
});
}


Expand All @@ -74,8 +103,8 @@ angular.module('drugOrders', ['orderService', 'encounterService', 'uicommons.fil

$scope.loading = false;

$scope.activeDrugOrders = [];
$scope.pastDrugOrders = [];
$scope.activeDrugOrders = { loading: true };
$scope.pastDrugOrders = { loading: true };
$scope.draftDrugOrders = [];
$scope.dosingTypes = OpenMRS.dosingTypes;

Expand Down Expand Up @@ -155,6 +184,13 @@ angular.module('drugOrders', ['orderService', 'encounterService', 'uicommons.fil
return _.findWhere(_.union($scope.draftDrugOrders, [$scope.newDraftDrugOrder]), { previousOrder: activeOrder });
}

$scope.replacementForPastOrder = function(pastOrder) {
var candidates = _.union($scope.activeDrugOrders, $scope.pastDrugOrders)
return _.find(candidates, function(item) {
return item.previousOrder && item.previousOrder.uuid === pastOrder.uuid;
});
}

$scope.signAndSaveDraftDrugOrders = function() {
var orders = _.map($scope.draftDrugOrders, function(order) {
return replaceWithUuids(order, ['drug', 'doseUnits', 'frequency', 'quantityUnits',
Expand Down

0 comments on commit ab206a1

Please sign in to comment.