Skip to content

Commit

Permalink
fix: [TECH-1627] use only valid combinations of orgUnit and ouMode
Browse files Browse the repository at this point in the history
  • Loading branch information
superskip authored Aug 23, 2023
1 parent 73245e0 commit 33e045d
Showing 1 changed file with 50 additions and 25 deletions.
75 changes: 50 additions & 25 deletions scripts/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ var trackerCaptureServices = angular.module('trackerCaptureServices', ['ngResour
return enrollment;
};
var errorHeader = $translate.instant("error");
var exclusiveOuModes = ['ACCESSIBLE', 'CAPTURE', 'ALL'];
return {
get: function(enrollmentUid, teiUid, programUid){
var url = DHIS2URL + '/enrollments/' + enrollmentUid;
Expand All @@ -690,8 +691,15 @@ var trackerCaptureServices = angular.module('trackerCaptureServices', ['ngResour
});
},
getByStartAndEndDate: function( program, orgUnit, ouMode, startDate, endDate, pageSize ){
var url = DHIS2URL + '/enrollments.json?program=' + program;
var paging = pageSize ? '&pageSize=' + pageSize : '&paging=false'
var promise = $http.get( DHIS2URL + '/enrollments.json?program=' + program + '&ou=' + orgUnit + '&ouMode='+ ouMode + '&programStartDate=' + startDate + '&programEndDate=' + endDate + '&fields=:all' + paging).then(function(response){
if (orgUnit && !exclusiveOuModes.includes(ouMode)) {
url = url + '&ou=' + orgUnit;
}
if (ouMode) {
url = url + '&ouMode=' + ouMode;
}
var promise = $http.get(url + '&programStartDate=' + startDate + '&programEndDate=' + endDate + '&fields=:all' + paging).then(function(response){
return convertFromApiToUser(response.data);
}, function(response){
var errorBody = $translate.instant('failed_to_fetch_enrollment');
Expand Down Expand Up @@ -906,44 +914,48 @@ var trackerCaptureServices = angular.module('trackerCaptureServices', ['ngResour
.factory('TEIService', function($http, $translate, DHIS2URL, $q, AttributesFactory, CommonUtils, CurrentSelection, DateUtils, NotificationService, TeiAccessApiService) {
var cachedTeiWithProgramData = null;
var errorHeader = $translate.instant("error");
var exclusiveOuModes = ['ACCESSIBLE', 'CAPTURE', 'ALL'];
var getSearchUrl = function(type,ouId, ouMode, queryUrl, programOrTETUrl, attributeUrl, pager, paging, format){
var baseUrl = DHIS2URL + '/trackedEntityInstances/'+type;
var url = baseUrl;
var params = [];
var deferred = $q.defer();

if (format === "csv") {
url = url+'.csv?ou=' + ouId + '&ouMode=' + ouMode;
url = url+'.csv?';
} else if (format === "xml") {
url = url+'.json?ou=' + ouId + '&ouMode=' + ouMode;
url = url+'.json?';
}else {
url = url+'.json?ou=' + ouId + '&ouMode=' + ouMode;
url = url+'.json?';
}

if (ouId && !exclusiveOuModes.includes(ouMode)) {
params.push('ou=' + ouId);
}
if (ouMode) {
params.push('ouMode=' + ouMode);
}
if(queryUrl){
url = url + '&'+ queryUrl;
params.push(queryUrl);
}
if(programOrTETUrl){
url = url + '&' + programOrTETUrl;
params.push(programOrTETUrl);
}
if(attributeUrl){
url = url + '&' + attributeUrl;
params.push(attributeUrl);
}
if(paging){
var pgSize = (pager && pager.pageSize) || 50;
var pg = (pager && pager.page) || 1;
pgSize = pgSize > 1 ? pgSize : 1;
pg = pg > 1 ? pg : 1;
url = url + '&pageSize=' + pgSize + '&page=' + pg;
if(pager && pager.skipTotalPages) {
url+= '&totalPages=false';
}else{
url+= '&totalPages=true';
}
params.push('pageSize=' + pgSize + '&page=' + pg);
params.push('totalPages=' + !(pager && pager.skipTotalPages));
}
else{
url = url + '&paging=false';
params.push('paging=false');
}
return url;
return url + params.join('&');
}
var setTeiAttributeValues = function(teiAttributes, optionSets, attributesById){
teiAttributes.forEach(function(att) {
Expand Down Expand Up @@ -1419,6 +1431,7 @@ var trackerCaptureServices = angular.module('trackerCaptureServices', ['ngResour

var skipPaging = "&skipPaging=true";
var errorHeader = $translate.instant("error");
var exclusiveOuModes = ['ACCESSIBLE', 'CAPTURE', 'ALL'];

var getContextEvent = function(dhis2Event){
if(Array.isArray(dhis2Event)){
Expand All @@ -1430,7 +1443,7 @@ var trackerCaptureServices = angular.module('trackerCaptureServices', ['ngResour
return {

getEventsByStatus: function(entity, orgUnit, program, programStatus){
var promise = TeiAccessApiService.get(entity, program, DHIS2URL + '/events.json?ouMode=ACCESSIBLE&' + 'trackedEntityInstance=' + entity + '&orgUnit=' + orgUnit + '&program=' + program + '&programStatus=' + programStatus + skipPaging).then(function(response){
var promise = TeiAccessApiService.get(entity, program, DHIS2URL + '/events.json?ouMode=ACCESSIBLE&' + 'trackedEntityInstance=' + entity + '&program=' + program + '&programStatus=' + programStatus + skipPaging).then(function(response){
return response.data.events;
}, function (response) {

Expand Down Expand Up @@ -1473,15 +1486,18 @@ var trackerCaptureServices = angular.module('trackerCaptureServices', ['ngResour
return promise;
},
getByOrgUnitAndProgram: function(orgUnit, ouMode, program, startDate, endDate, pageSize){
var url;
var paging = pageSize ? '&pageSize=' + pageSize : skipPaging;
if(startDate && endDate){
url = DHIS2URL + '/events.json?' + 'orgUnit=' + orgUnit + '&ouMode='+ ouMode + '&program=' + program + '&startDate=' + startDate + '&endDate=' + endDate + paging;
var url = DHIS2URL + '/events.json?program=' + program;
if (orgUnit && !exclusiveOuModes.includes(ouMode)) {
url = url + '&orgUnit=' + orgUnit;
}
else{
url = DHIS2URL + '/events.json?' + 'orgUnit=' + orgUnit + '&ouMode='+ ouMode + '&program=' + program + paging;
if (ouMode) {
url = url + '&ouMode=' + ouMode;
}
var promise = $http.get( url ).then(function(response){
if(startDate && endDate){
url = url + '&startDate=' + startDate + '&endDate=' + endDate;
}
var paging = pageSize ? '&pageSize=' + pageSize : skipPaging;
var promise = $http.get( url + paging ).then(function(response){
return response.data.events;
}, function(response){
if( response && response.data && response.data.status === 'ERROR'){
Expand Down Expand Up @@ -1587,11 +1603,20 @@ var trackerCaptureServices = angular.module('trackerCaptureServices', ['ngResour
/* factory for handling event reports */
.factory('EventReportService', function($http, DHIS2URL, $translate, NotificationService) {
var errorHeader = $translate.instant("error");
var exclusiveOuModes = ['ACCESSIBLE', 'CAPTURE', 'ALL'];
return {

getEventReport: function(orgUnit, ouMode, program, startDate, endDate, programStatus, eventStatus, pager){

var url = DHIS2URL + '/events/eventRows.json?' + 'orgUnit=' + orgUnit + '&ouMode='+ ouMode + '&program=' + program;
var url = DHIS2URL + '/events/eventRows.json?program=' + program;

if (orgUnit && !exclusiveOuModes.includes(ouMode)) {
url = url + '&orgUnit=' + orgUnit;
}

if (ouMode) {
url = url + '&ouMode=' + ouMode;
}

if( programStatus ){
url = url + '&programStatus=' + programStatus;
Expand Down

0 comments on commit 33e045d

Please sign in to comment.