dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36206
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18537: tracker-capture: centeralized autoEventGeneration
------------------------------------------------------------
revno: 18537
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-03-09 15:38:11 +0100
message:
tracker-capture: centeralized autoEventGeneration
modified:
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js 2015-03-06 14:43:54 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js 2015-03-09 14:38:11 +0000
@@ -193,7 +193,20 @@
$scope.selectedEnrollment = enrollment;
$scope.enrollments.push($scope.selectedEnrollment);
- $scope.autoGenerateEvents(tei, $scope.selectedProgram, $scope.selectedOrgUnit, $scope.selectedEnrollment);
+ var dhis2Events = EventUtils.autoGenerateEvents(tei.trackedEntityInstance, $scope.selectedProgram, $scope.selectedOrgUnit, $scope.selectedEnrollment);
+
+ $scope.showEnrollmentDiv = false;
+ $scope.outerForm.submitted = false;
+
+ CurrentSelection.set({tei: tei, te: $scope.selectedEntity, prs: $scope.programs, pr: $scope.selectedProgram, prNames: $scope.programNames, prStNames: $scope.programStageNames, enrollments: $scope.enrollments, selectedEnrollment: $scope.selectedEnrollment, optionSets: $scope.optionSets});
+ if(dhis2Events.events.length > 0){
+ DHIS2EventFactory.create(dhis2Events).then(function(data) {
+ $scope.broadCastSelections('dashboardWidgets');
+ });
+ }
+ else{
+ $scope.broadCastSelections('dashboardWidgets');
+ }
});
}
else{
@@ -290,48 +303,6 @@
});
});
};
-
- $scope.autoGenerateEvents = function(tei, program, orgUnit, enrollment){
- if(tei && program && orgUnit && enrollment){
- var dhis2Events = {events: []};
- angular.forEach(program.programStages, function(stage){
- if(stage.autoGenerateEvent){
- var newEvent = {
- trackedEntityInstance: tei.trackedEntityInstance,
- program: program.id,
- programStage: stage.id,
- orgUnit: orgUnit.id,
- dueDate: DateUtils.formatFromUserToApi( EventUtils.getEventDueDate(null, stage, enrollment) ),
- status: 'SCHEDULE'
- };
-
- if(stage.openAfterEnrollment){
- if(stage.reportDateToUse === 'dateOfIncident'){
- newEvent.eventDate = DateUtils.formatFromUserToApi(enrollment.dateOfIncident);
- }
- else{
- newEvent.eventDate = DateUtils.formatFromUserToApi(enrollment.dateOfEnrollment);
- }
- }
-
- dhis2Events.events.push(newEvent);
- }
- });
-
- $scope.showEnrollmentDiv = false;
- $scope.outerForm.submitted = false;
-
- CurrentSelection.set({tei: tei, te: $scope.selectedEntity, prs: $scope.programs, pr: program, prNames: $scope.programNames, prStNames: $scope.programStageNames, enrollments: $scope.enrollments, selectedEnrollment: enrollment, optionSets: $scope.optionSets});
- if(dhis2Events.events.length > 0){
- DHIS2EventFactory.create(dhis2Events).then(function(data) {
- $scope.broadCastSelections('dashboardWidgets');
- });
- }
- else{
- $scope.broadCastSelections('dashboardWidgets');
- }
- }
- };
$scope.markForFollowup = function(){
$scope.selectedEnrollment.followup = !$scope.selectedEnrollment.followup;
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js 2015-03-09 12:29:40 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js 2015-03-09 14:38:11 +0000
@@ -135,7 +135,14 @@
}
else{
enrollment.enrollment = data.reference;
- $scope.autoGenerateEvents(teiId,$scope.selectedProgram, $scope.selectedOrgUnit, enrollment, destination);
+ var dhis2Events = EventUtils.autoGenerateEvents(teiId, $scope.selectedProgram, $scope.selectedOrgUnit, enrollment);
+ if(dhis2Events.events.length > 0){
+ DHIS2EventFactory.create(dhis2Events).then(function(data){
+ goToDashboard(destination, teiId);
+ });
+ }else{
+ goToDashboard(destination, teiId);
+ }
}
});
}
@@ -172,44 +179,6 @@
}, 100);
};
- $scope.autoGenerateEvents = function(teiId, program, orgUnit, enrollment, destination){
-
- if(teiId && program && orgUnit && enrollment){
- var dhis2Events = {events: []};
- angular.forEach(program.programStages, function(stage){
- if(stage.autoGenerateEvent){
- var newEvent = {
- trackedEntityInstance: teiId,
- program: program.id,
- programStage: stage.id,
- orgUnit: orgUnit.id,
- dueDate: DateUtils.formatFromUserToApi(EventUtils.getEventDueDate(null,stage, enrollment)),
- status: 'SCHEDULE'
- };
-
- if(stage.openAfterEnrollment){
- if(stage.reportDateToUse === 'dateOfIncident'){
- newEvent.eventDate = DateUtils.formatFromUserToApi(enrollment.dateOfIncident);
- }
- else{
- newEvent.eventDate = DateUtils.formatFromUserToApi(enrollment.dateOfEnrollment);
- }
- }
-
- dhis2Events.events.push(newEvent);
- }
- });
-
- if(dhis2Events.events.length > 0){
- DHIS2EventFactory.create(dhis2Events).then(function(data){
- goToDashboard(destination, teiId);
- });
- }else{
- goToDashboard(destination, teiId);
- }
- }
- };
-
var goToDashboard = function(destination, teiId){
//reset form
$scope.selectedTei = {};
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js 2015-03-06 16:27:25 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js 2015-03-09 14:38:11 +0000
@@ -574,7 +574,7 @@
att.value = AttributesFactory.formatAttributeValue(att, attributesById, optionSets, 'API');
});
- var promise = $http.put( '../api/trackedEntityInstances' , formattedTei ).then(function(response){
+ var promise = $http.post( '../api/trackedEntityInstances' , formattedTei ).then(function(response){
return response.data;
});
return promise;
@@ -1177,10 +1177,40 @@
})
.service('EventUtils', function(DateUtils, CalendarService, OptionSetService, $filter, orderByFilter){
+
+ var getEventDueDate = function(eventsByStage, programStage, enrollment){
+ var referenceDate = enrollment.dateOfIncident ? enrollment.dateOfIncident : enrollment.dateOfEnrollment,
+ offset = programStage.minDaysFromStart,
+ calendarSetting = CalendarService.getSetting();
+
+ if(programStage.generatedByEnrollmentDate){
+ referenceDate = enrollment.dateOfEnrollment;
+ }
+
+ if(programStage.repeatable){
+ var evs = [];
+ angular.forEach(eventsByStage, function(ev){
+ if(ev.eventDate){
+ evs.push(ev);
+ }
+ });
+
+ if(evs.length > 0){
+ evs = orderByFilter(evs, '-eventDate');
+ referenceDate = evs[0].eventDate;
+ offset = programStage.standardInterval;
+ }
+ }
+
+ var dueDate = moment(referenceDate, calendarSetting.momentFormat).add('d', offset)._d;
+ dueDate = $filter('date')(dueDate, calendarSetting.keyDateFormat);
+ return dueDate;
+ };
+
return {
createDummyEvent: function(eventsPerStage, programStage, orgUnit, enrollment){
var today = DateUtils.getToday();
- var dueDate = this.getEventDueDate(eventsPerStage, programStage, enrollment);
+ var dueDate = getEventDueDate(eventsPerStage, programStage, enrollment);
var dummyEvent = {programStage: programStage.id,
orgUnit: orgUnit.id,
orgUnitName: orgUnit.name,
@@ -1227,34 +1257,36 @@
}
}
},
- getEventDueDate: function(eventsByStage, programStage, enrollment){
- var referenceDate = enrollment.dateOfIncident ? enrollment.dateOfIncident : enrollment.dateOfEnrollment,
- offset = programStage.minDaysFromStart,
- calendarSetting = CalendarService.getSetting();
-
- if(programStage.generatedByEnrollmentDate){
- referenceDate = enrollment.dateOfEnrollment;
- }
-
- if(programStage.repeatable){
- var evs = [];
- angular.forEach(eventsByStage, function(ev){
- if(ev.eventDate){
- evs.push(ev);
+ autoGenerateEvents: function(teiId, program, orgUnit, enrollment){
+ var dhis2Events = {events: []};
+ if(teiId && program && orgUnit && enrollment){
+ angular.forEach(program.programStages, function(stage){
+ if(stage.autoGenerateEvent){
+ var newEvent = {
+ trackedEntityInstance: teiId,
+ program: program.id,
+ programStage: stage.id,
+ orgUnit: orgUnit.id,
+ dueDate: DateUtils.formatFromUserToApi(getEventDueDate(null,stage, enrollment)),
+ status: 'SCHEDULE'
+ };
+
+ if(stage.openAfterEnrollment){
+ if(stage.reportDateToUse === 'dateOfIncident'){
+ newEvent.eventDate = DateUtils.formatFromUserToApi(enrollment.dateOfIncident);
+ }
+ else{
+ newEvent.eventDate = DateUtils.formatFromUserToApi(enrollment.dateOfEnrollment);
+ }
+ }
+
+ dhis2Events.events.push(newEvent);
}
});
-
- if(evs.length > 0){
- evs = orderByFilter(evs, '-eventDate');
- referenceDate = evs[0].eventDate;
- offset = programStage.standardInterval;
- }
- }
+ }
- var dueDate = moment(referenceDate, calendarSetting.momentFormat).add('d', offset)._d;
- dueDate = $filter('date')(dueDate, calendarSetting.keyDateFormat);
- return dueDate;
- },
+ return dhis2Events;
+ },
reconstruct: function(dhis2Event, programStage, optionSets){
var e = {dataValues: [],
@@ -1305,5 +1337,5 @@
return e;
}
- };
+ };
});