-
Notifications
You must be signed in to change notification settings - Fork 0
/
diagnosisDetails.js
111 lines (100 loc) · 3.57 KB
/
diagnosisDetails.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
addPatient.controller("diagnosisDetails", ddController);
function ddController($scope) {
$scope.$root.isEmpty.diagnosisDetails.primaryDiagnosis = true;
$scope.$root.isDDActive = false;
$scope.reset = function() {
$scope.model = {};
$scope.model.medications = [];
$scope.model.medications[0] = {name: "", dose: ""}
$scope.model.medicationCount = 0;
$scope.medicationHashKeys = [];
}
$scope.reset($scope);
$scope.$watch('isDDActive', function(newValue, oldValue) {
if (newValue === true) {
$scope.reset($scope);
}
})
};
ddController.prototype.validateData = function($scope) {
if ($scope.model) {
var result = {
validationPass: true,
primaryDiagnosis: true
};
if ($scope.model.primaryDiagnosis === undefined || $scope.model.primaryDiagnosis === "" ) {
result.validationPass = false;
result.primaryDiagnosis = false;
}
return result;
}
};
ddController.prototype.submit = function($scope, unifiedDataModel, $rootScope) {
$scope.$apply(function() {
//Copy data to unified data model. Data is stringified to and parsed from JSON to remove the internal-use values
$scope.model.medications = JSON.parse(angular.toJson($scope.model.medications));
unifiedDataModel.diagnosisDetails.diagnoses[unifiedDataModel.diagnosisDetails.count] = angular.copy($scope.model);
unifiedDataModel.diagnosisDetails.count++;
$scope.$root.isDDActive = false;
$scope.$root.isSummaryActive = true;
});
$rootScope.$broadcast("diagnosisDataSubmit");
};
addPatient.directive("addbutton", function($compile){
return {
scope: true,
link: function(scope, elem, attrs) {
scope.addField = function(){
var index = scope.model.medicationCount;
scope.model.medications[index+1] = {name: "", dose: ""}
var removeButton = $compile("<removebutton>")(scope);
scope.medicationHashKeys[index] = scope.medication.$$hashKey
removeButton.attr("index", index)
elem.replaceWith(removeButton)
scope.model.medicationCount++;
}
},
template: '<button class="medication-add-button" type="button" ng-click="addField()">+</button>'
}
});
addPatient.directive("removebutton", function($compile){
return {
scope: true,
link: function(scope, elem, attrs) {
scope.removeField = function() {
var index = scope.medicationHashKeys.indexOf(scope.medication.$$hashKey)
scope.model.medications.splice(index,1);
scope.medicationHashKeys.splice(index,1)
scope.model.medicationCount -= 1;
}
},
template: '<button class="medication-remove-button" type="button" ng-click="removeField()">-</button>'
}
});
addPatient.directive("medicationsfield", function(){
return {
template: '<span class="inline-fields">'+
'<input class="medication-name" placeholder="Medication Name" type="text" ng-model="medication.name"/>'+
'<input class="medication-dose" placeholder="Medication Dose" type="text" ng-model="medication.dose"/>'+
'<addbutton></addbutton>'+
'</span>'
}
});
addPatient.directive("submitddbutton", function(unifiedDataModel, $rootScope) {
return {
link: function(scope, elem, attrs) {
elem.bind("click", function() {
//var validationResult = scope.dd.validateData(scope);
validationResult = {validationPass: true}
console.warn("Data Validation Bypassed")
if (validationResult && validationResult.validationPass === true) {
scope.dd.submit(scope, unifiedDataModel, $rootScope)
} else {
scope.$apply(function() {
scope.$root.isEmpty.diagnosisDetails = validationResult;
})
}
});
}
}
});