export.js
//and add new groups with data elements and indicators not currently grouped
and add new groups with data elements and indicators not currently grouped
and add new groups with data elements and indicators not currently grouped
function validateGroupReferences() {
	var item, group, grouped = {}, unGrouped = [], found = false, validMembers;
	for (var i = 0; metaData.dataElementGroups && i < metaData.dataElementGroups.length; i++) {
		validMembers = [];
		group = metaData.dataElementGroups[i];
		for (var j = 0; j < group.dataElements.length; j++) {
			item = group.dataElements[j];
			found = false;
			for (var k = 0; !found && metaData.dataElements && k < metaData.dataElements.length; k++) {
				if (item.id === metaData.dataElements[k].id) {
					found = true;
				}
			}
			if (found) {
				validMembers.push(item);
				grouped[item.id] = true;
			}
		}
		metaData.dataElementGroups[i].dataElements = validMembers;
		delete metaData.dataElementGroups[i].dataElementGroupSet;
	}
	for (var i = 0; metaData.dataElements && i < metaData.dataElements.length; i++) {
		if (!grouped.hasOwnProperty(metaData.dataElements[i].id)) {
			unGrouped.push({
				"id": metaData.dataElements[i].id,
				"name": metaData.dataElements[i].shortName,
				"type": "dataElements"
			});
		}
	}
	grouped = {};
	for (var i = 0; metaData.indicatorGroups && i < metaData.indicatorGroups.length; i++) {
		validMembers = [];
		group = metaData.indicatorGroups[i];
		for (var j = 0; j < group.indicators.length; j++) {
			item = group.indicators[j];
			found = false;
			for (var k = 0; !found && metaData.indicators && k < metaData.indicators.length; k++) {
				if (item.id === metaData.indicators[k].id) {
					found = true;
				}
			}
			if (found) {
				validMembers.push(item);
				grouped[item.id] = true;
			}
		}
		metaData.indicatorGroups[i].indicators = validMembers;
		delete metaData.indicatorGroups[i].indicatorGroupSet;
	}
	for (var i = 0; metaData.indicators && i < metaData.indicators.length; i++) {
		if (!grouped.hasOwnProperty(metaData.indicators[i].id)) {
			unGrouped.push({
				"id": metaData.indicators[i].id,
				"name": metaData.indicators[i].shortName,
				"type": "indicators"
			});
		}
	}
	grouped = {};
	for (var i = 0; metaData.programIndicatorGroups && i < metaData.programIndicatorGroups.length; i++) {
		validMembers = [];
		group = metaData.programIndicatorGroups[i];
		for (var j = 0; j < group.programIndicators.length; j++) {
			item = group.programIndicators[j];
			found = false;
			for (var k = 0; !found && metaData.programIndicators && k < metaData.programIndicators.length; k++) {
				if (item.id === metaData.programIndicators[k].id) {
					found = true;
				}
			}
			if (found) {
				validMembers.push(item);
				grouped[item.id] = true;
			}
		}
		metaData.programIndicatorGroups[i].programIndicators = validMembers;
		delete metaData.programIndicatorGroups[i].programIndicatorGroupSet;
	}
	for (var i = 0; metaData.programIndicators && i < metaData.programIndicators.length; i++) {
		if (!grouped.hasOwnProperty(metaData.programIndicators[i].id)) {
			unGrouped.push({
				"id": metaData.programIndicators[i].id,
				"name": metaData.programIndicators[i].shortName,
				"type": "programIndicators"
			});
		}
	}
	for (var i = 0; metaData.hasOwnProperty("categoryOptionGroups") && i < metaData.categoryOptionGroups.length; i++) {
		var group = metaData.categoryOptionGroups[i];
		var validOptions = [];
		for (var j = 0; group.hasOwnProperty("categoryOptions") && j < group.categoryOptions.length; j++) {
			var option = group.categoryOptions[j];
			if (objectExists("categoryOptions", option.id)) {
				validOptions.push(option);
			}
		}
		metaData.categoryOptionGroups[i].categoryOptions = validOptions;
	}
	if (unGrouped.length > 0) {
		console.log("\nERROR | Data elements/indicators referenced, but not in any groups:");
		for (var issue of unGrouped) {
			console.log(issue.type + " - " + issue.id + " - "
				+ issue.name);
		}
	}
	else return true;
}
function validateGroupReferences ( ) { var item , group , grouped = { } , unGrouped = [ ] , found = false , validMembers ; for ( var i = 0 ; metaData . dataElementGroups && i < metaData . dataElementGroups . length ; i ++ ) { validMembers = [ ] ; group = metaData . dataElementGroups [ i ] ; for ( var j = 0 ; j < group . dataElements . length ; j ++ ) { item = group . dataElements [ j ] ; found = false ; for ( var k = 0 ; ! found && metaData . dataElements && k < metaData . dataElements . length ; k ++ ) { if ( item . id === metaData . dataElements [ k ] . id ) { found = true ; } } if ( found ) { validMembers . push ( item ) ; grouped [ item . id ] = true ; } } metaData . dataElementGroups [ i ] . dataElements = validMembers ; delete metaData . dataElementGroups [ i ] . dataElementGroupSet ; } for ( var i = 0 ; metaData . dataElements && i < metaData . dataElements . length ; i ++ ) { if ( ! grouped . hasOwnProperty ( metaData . dataElements [ i ] . id ) ) { unGrouped . push ( { "id" : metaData . dataElements [ i ] . id , "name" : metaData . dataElements [ i ] . shortName , "type" : "dataElements" } ) ; } } grouped = { } ; for ( var i = 0 ; metaData . indicatorGroups && i < metaData . indicatorGroups . length ; i ++ ) { validMembers = [ ] ; group = metaData . indicatorGroups [ i ] ; for ( var j = 0 ; j < group . indicators . length ; j ++ ) { item = group . indicators [ j ] ; found = false ; for ( var k = 0 ; ! found && metaData . indicators && k < metaData . indicators . length ; k ++ ) { if ( item . id === metaData . indicators [ k ] . id ) { found = true ; } } if ( found ) { validMembers . push ( item ) ; grouped [ item . id ] = true ; } } metaData . indicatorGroups [ i ] . indicators = validMembers ; delete metaData . indicatorGroups [ i ] . indicatorGroupSet ; } for ( var i = 0 ; metaData . indicators && i < metaData . indicators . length ; i ++ ) { if ( ! grouped . hasOwnProperty ( metaData . indicators [ i ] . id ) ) { unGrouped . push ( { "id" : metaData . indicators [ i ] . id , "name" : metaData . indicators [ i ] . shortName , "type" : "indicators" } ) ; } } grouped = { } ; for ( var i = 0 ; metaData . programIndicatorGroups && i < metaData . programIndicatorGroups . length ; i ++ ) { validMembers = [ ] ; group = metaData . programIndicatorGroups [ i ] ; for ( var j = 0 ; j < group . programIndicators . length ; j ++ ) { item = group . programIndicators [ j ] ; found = false ; for ( var k = 0 ; ! found && metaData . programIndicators && k < metaData . programIndicators . length ; k ++ ) { if ( item . id === metaData . programIndicators [ k ] . id ) { found = true ; } } if ( found ) { validMembers . push ( item ) ; grouped [ item . id ] = true ; } } metaData . programIndicatorGroups [ i ] . programIndicators = validMembers ; delete metaData . programIndicatorGroups [ i ] . programIndicatorGroupSet ; } for ( var i = 0 ; metaData . programIndicators && i < metaData . programIndicators . length ; i ++ ) { if ( ! grouped . hasOwnProperty ( metaData . programIndicators [ i ] . id ) ) { unGrouped . push ( { "id" : metaData . programIndicators [ i ] . id , "name" : metaData . programIndicators [ i ] . shortName , "type" : "programIndicators" } ) ; } } for ( var i = 0 ; metaData . hasOwnProperty ( "categoryOptionGroups" ) && i < metaData . categoryOptionGroups . length ; i ++ ) { var group = metaData . categoryOptionGroups [ i ] ; var validOptions = [ ] ; for ( var j = 0 ; group . hasOwnProperty ( "categoryOptions" ) && j < group . categoryOptions . length ; j ++ ) { var option = group . categoryOptions [ j ] ; if ( objectExists ( "categoryOptions" , option . id ) ) { validOptions . push ( option ) ; } } metaData . categoryOptionGroups [ i ] . categoryOptions = validOptions ; } if ( unGrouped . length > 0 ) { console . log ( "\nERROR | Data elements/indicators referenced, but not in any groups:" ) ; for ( var issue of unGrouped ) { console . log ( issue . type + " - " + issue . id + " - " + issue . name ) ; } } else return true ; }
and add new groups with data elements and indicators not currently grouped
and add new groups with data elements and indicators not currently grouped
//data element group membership //indicator group membership //program indicator group membership //catetory option group membership //Check if the option referenced is part if the category options