-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpersonalDetails.js
124 lines (116 loc) · 3.54 KB
/
personalDetails.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
112
113
114
115
116
117
118
119
120
121
122
123
124
addPatient.controller("personalDetails", pdController);
function pdController($scope, unifiedDataModel) {
$scope.$root.isEmpty.personalDetails = {
date: true,
firstName: true,
lastName: true,
phoneNumber: true
};
$scope.$root.isPDActive = true;
$scope.model = {};
};
pdController.prototype.init = function() {
};
pdController.prototype.validateData = function($scope) {
if ($scope.model) {
var result = {
validationPass: true,
date: true,
firstName: true,
lastName: true,
phoneNumber: true
};
if ($scope.model.date === undefined || $scope.model.date === "" ) {
result.validationPass = false;
result.date = false;
}
if ($scope.model.firstName === undefined || $scope.model.firstName === "" ) {
result.validationPass = false;
result.firstName = false;
}
if ($scope.model.lastName === undefined || $scope.model.lastName === "" ) {
result.validationPass = false;
result.lastName = false;
}
if ($scope.model.phoneNumber === undefined || $scope.model.phoneNumber === "" ) {
result.validationPass = false;
result.phoneNumber = false;
}
return result;
}
};
pdController.prototype.submit = function($scope, unifiedDataModel, $rootScope) {
$scope.$apply(function() {
unifiedDataModel.personalDetails = angular.copy($scope.model);
$scope.$root.isPDActive = false;
$scope.$root.isDDActive = true;
});
$rootScope.$broadcast("personalDataSubmit")
};
addPatient.directive("validate", function() {
return {
link: function(scope, elem, attrs) {
elem.on("input", function() {
if (attrs.validatetype === "length") {
var maxLength = parseInt(attrs.validatemax);
if (elem.val().length > maxLength) {
elem.val(elem.val().slice(0,maxLength));
scope.model[attrs.ngModel.split('.')[1]] = parseInt(elem.val());
//scope[attrs.ngmodel] = elem.val();
}
} else if (attrs.validatetype === "sex") {
var value = elem.val().toLowerCase();
if (value[0] === 'm' && value !== "mal") {
elem.val("Male");
} else if (value[0] === 'f' && value !== "femal") {
elem.val("Female");
} else if (value === "mal" || value === "femal") {
elem.val("");
} else {
elem.val("");
}
scope.model.sex = elem.val();
} else if (attrs.validatetype === "nonumber") {
var value = elem.val();
var length = elem.val().length
if (value.match(/^[a-zA-Z ]+$/) === null) {
elem.val(elem.val().slice(0, length-1))
}
scope.model[attrs.ngModel.split('.')[1]] = elem.val();
}
});
}
}
});
addPatient.directive("calculateage", function() {
return {
link: function (scope, elem, attrs) {
elem.on("change", function () {
if (scope.model.dob !== undefined) {
var today = new Date();
var todayYear = today.getFullYear()
scope.model.age = todayYear - scope.model.dob.getFullYear();
scope.$apply();
}
})
}
}
})
addPatient.directive("submitpdbutton", function(unifiedDataModel, $rootScope) {
return {
link: function(scope, elem, attrs) {
elem.bind("click", function() {
//var validationResult = scope.pd.validateData(scope);
validationResult = {validationPass: true}
console.warn("Data Validation Bypassed")
if (validationResult && validationResult.validationPass === true) {
scope.pd.submit(scope, unifiedDataModel, $rootScope)
} else {
scope.$apply(function() {
scope.$root.isEmpty.personalDetails = validationResult;
})
}
});
}
}
});