forked from openmrs/openmrs-module-coreapps
/
addcondition.controller.js
64 lines (52 loc) · 2.7 KB
/
addcondition.controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var app = angular.module("conditionApp",
['uicommons.widget.coded-or-free-text-answer', 'app.restfulServices', 'app.models', 'app.commonFunctionsFactory']);
app.controller("ConditionController", ConditionController);
ConditionController.$inject = ['$scope', 'RestfulService', 'ConditionModel', 'ConceptModel', 'CommonFunctions'];
function ConditionController($scope, RestfulService, ConditionModel, ConceptModel, CommonFunctions) {
var self = this;
$scope.patientUuid = null;
$scope.condition = null;
// this is required inorder to initialize the Restangular service
RestfulService.setBaseUrl('/' + OPENMRS_CONTEXT_PATH + '/ws/rest/emrapi');
/**
* Perform POST save
* PS: Make sure the 'Non Coded Uuid' setting (under Settings->Condition List) is set inorder to work with noncoded concepts,
* the LOCALE needs to be set (most concepts have 'en')
* @type {Function}
*/
self.saveCondition = self.saveCondition || function () {
var conditions = [];
conditions.push($scope.condition);
RestfulService.post('condition', conditions, function (data) {
//emr.successAlert("conditionlist.updateCondition.success"); Messages not being resolved
emr.successAlert("Condition added successfully")
window.location = '/' + OPENMRS_CONTEXT_PATH + '/coreapps/conditionlist/manageConditions.page?patientId=' + $scope.patientUuid + '&';
}, function (error) {
//emr.errorAlert("conditionlist.updateCondition.error");
emr.errorAlert("Error Saving condition");
});
}
self.initCondition = self.initCondition || function () {
$scope.patientUuid = CommonFunctions.extractUrlArgs(window.location.search)['patientId'];
$scope.condition = new ConditionModel($scope.patientUuid);
}
self.validateCondition = self.validateCondition || function () {
var concept = $scope.concept.concept;
if (concept !== null) {
$scope.condition.concept = new ConceptModel(concept.uuid, concept.display);
} else {
// noncoded diagnosis
$scope.condition.conditionNonCoded = "NON_CODED:" + $scope.concept.word;
}
$scope.condition.onSetDate = self.getSelectedDate();
self.saveCondition();
}
self.getSelectedDate = self.getSelectedDate || function () {
var datePicker = angular.element(document.getElementsByName('conditionStartDate'))[0];
return datePicker.value;
}
// init page
self.initCondition();
// bind functions to scope
$scope.validateCondition = self.validateCondition;
}