From e8d13414dd292529a30251a8114329e6bd5afc15 Mon Sep 17 00:00:00 2001
From: Victor Picussa <vp16@inf.ufpr.br>
Date: Thu, 23 May 2019 11:01:07 -0300
Subject: [PATCH] [v.1.10.4]New indicators and fixes

---
 CHANGELOG.md                            |   3 +
 src/libs/convert/ageStudentCode.js      |  38 ++
 src/libs/convert/ocdeGeral.js           |   2 +-
 src/libs/convert/ocdeSpecific.js        |   4 +-
 src/libs/middlewares/id2str.js          |   7 +-
 src/libs/routes/api.js                  |  21 +-
 src/libs/routes/courseCount.js          | 414 ++++++++++++++++++++
 src/libs/routes/universityEnrollment.js | 479 ++++++++++++++++++++++++
 8 files changed, 949 insertions(+), 19 deletions(-)
 create mode 100644 src/libs/convert/ageStudentCode.js
 create mode 100644 src/libs/routes/courseCount.js
 create mode 100644 src/libs/routes/universityEnrollment.js

diff --git a/CHANGELOG.md b/CHANGELOG.md
index e2b77445..b64b4e11 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
 ## 1.10.4 - 2019-05-23
 ## Changed
 - Fix order in enrollment indicator
+## Added
+- Added university enrollment indicator
+- Added course count indicator
 
 ## 1.10.3 - 2019-05-22
 ## Changed
diff --git a/src/libs/convert/ageStudentCode.js b/src/libs/convert/ageStudentCode.js
new file mode 100644
index 00000000..450c9361
--- /dev/null
+++ b/src/libs/convert/ageStudentCode.js
@@ -0,0 +1,38 @@
+/*
+Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre
+Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
+
+This file is part of simcaq-node.
+
+simcaq-node is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+simcaq-node is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with simcaq-node.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+module.exports = function ageStudentCode(id) {
+    switch (id) {
+        case 1:
+        return 'Menor que 18 anos';
+        case 2:
+        return 'Entre 18 anos e 24 anos';
+        case 3:
+        return 'Entre 25 anos e 29 anos';
+        case 4:
+        return 'Entre 30 anos e 34 anos';
+        case 5:
+        return 'Entre 35 anos e 39 anos';
+        case 6:
+        return 'Maior que 39 anos';
+        default:
+        return 'Não classificado';
+    }
+};
diff --git a/src/libs/convert/ocdeGeral.js b/src/libs/convert/ocdeGeral.js
index 88cc0646..70671edb 100644
--- a/src/libs/convert/ocdeGeral.js
+++ b/src/libs/convert/ocdeGeral.js
@@ -27,7 +27,7 @@ module.exports = function ocdeGeral(id) {
         case 2:
         return 'Humanidades e artes';
         case 3:
-        return 'Ciências sociais, negócios e direitor';
+        return 'Ciências sociais, negócios e direito';
         case 4:
         return 'Ciências, matemática e computação';
         case 5:
diff --git a/src/libs/convert/ocdeSpecific.js b/src/libs/convert/ocdeSpecific.js
index 7b360d86..0133fa97 100644
--- a/src/libs/convert/ocdeSpecific.js
+++ b/src/libs/convert/ocdeSpecific.js
@@ -37,9 +37,11 @@ module.exports = function ocdeSpecific(id) {
         case 38:
         return 'Direito';
         case 42:
-        return 'Ciências';
+        return 'Ciências da vida';
         case 44:
         return 'Ciências físicas';
+        case 46:
+        return 'Matemática e estatística';
         case 48:
         return 'Computação';
         case 52:
diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js
index 0e2b9e9c..c9e21641 100644
--- a/src/libs/middlewares/id2str.js
+++ b/src/libs/middlewares/id2str.js
@@ -42,6 +42,7 @@ const contractType = require(`${libs}/convert/contractType`);
 const ethnicGroupPnad = require(`${libs}/convert/ethnicGroupPnad`);
 const ageRange = require(`${libs}/convert/ageRange`);
 const ageRangeAll = require(`${libs}/convert/ageRangeAll`);
+const ageStudentCode = require(`${libs}/convert/ageStudentCode`);
 const fullAgeRange = require(`${libs}/convert/fullAgeRange`);
 const genderPnad = require(`${libs}/convert/genderPnad`);
 const fifthHouseholdIncome = require(`${libs}/convert/fifthHouseholdIncome`);
@@ -75,7 +76,7 @@ const postgraduatePresentialTeacher = require(`${libs}/convert/booleanVariable`)
 const teacherSchooling = require(`${libs}/convert/teacherSchooling`);
 const ethnicGroupTeacherIES = require(`${libs}/convert/ethnicGroupTeacherIES`);
 const genderIES = require(`${libs}/convert/genderIES`);
-const deficiency = require(`${libs}/convert/booleanVariable`);
+const deficiency = require(`${libs}/convert/studentDeficiency`);
 
 const ids = {
     gender_id: gender,
@@ -145,7 +146,8 @@ const ids = {
     teacher_schooling_id: teacherSchooling,
     ethnic_group_teacher_ies_id: ethnicGroupTeacherIES,
     gender_ies_id: genderIES,
-    deficiency_id: deficiency
+    deficiency_id: deficiency,
+    age_student_code_id: ageStudentCode
 };
 
 function transform(removeId=false) {
@@ -209,6 +211,7 @@ module.exports = {
     ethnicGroupPnad,
     ageRange,
     ageRangeAll,
+    ageStudentCode,
     fullAgeRange,
     genderPnad,
     fifthHouseholdIncome,
diff --git a/src/libs/routes/api.js b/src/libs/routes/api.js
index 835ac113..48734ffd 100644
--- a/src/libs/routes/api.js
+++ b/src/libs/routes/api.js
@@ -40,8 +40,6 @@ const school = require('./school');
 
 const simulation = require('./simulation');
 
-const user = require('./user');
-
 const classroom = require('./classroom');
 
 const teacher = require('./teacher');
@@ -64,16 +62,8 @@ const idhmr = require('./idhmr');
 
 const idhml = require('./idhml');
 
-const oauth2 = require(`${libs}/middlewares/oauth2`);
-
-const verifyToken = require(`${libs}/routes/verifyToken`);
-
-const resetToken = require(`${libs}/routes/resetToken`);
-
 const educationYears = require(`${libs}/routes/educationYears`);
 
-const downloads = require(`${libs}/routes/downloads`);
-
 const infrastructure = require(`${libs}/routes/infrastructure`);
 
 const schoolInfrastructure = require(`${libs}/routes/schoolInfrastructure`);
@@ -106,6 +96,10 @@ const employees = require(`${libs}/routes/employees`);
 
 const financial = require(`${libs}/routes/financial`);
 
+const universityEnrollment = require(`${libs}/routes/universityEnrollment`);
+
+const courseCount = require(`${libs}/routes/courseCount`);
+
 const university = require(`${libs}/routes/university`);
 
 api.get('/', (req, res) => {
@@ -113,7 +107,6 @@ api.get('/', (req, res) => {
 });
 
 // mount API routes
-api.use('/user', user);
 api.use('/simulation', simulation);
 api.use('/class', classes);
 api.use('/enrollment', enrollment);
@@ -132,11 +125,7 @@ api.use('/rate_school', rateSchool);
 api.use('/gloss_enrollment_ratio', glossEnrollmentRatio);
 api.use('/liquid_enrollment_ratio', liquidEnrollmentRatio);
 api.use('/idhml', idhml);
-api.use('/auth/token', oauth2.token);
-api.use('/verify', verifyToken);
-api.use('/reset', resetToken);
 api.use('/education_years', educationYears);
-api.use('/downloads', downloads);
 api.use('/infrastructure', infrastructure);
 api.use('/school_infrastructure', schoolInfrastructure);
 api.use('/distribution_factor', distributionFactor);
@@ -153,6 +142,8 @@ api.use('/portal_mec_inep', portalMecInep);
 api.use('/enrollment_projection', enrollmentProjection);
 api.use('/employees', employees);
 api.use('/financial', financial);
+api.use('/university_enrollment', universityEnrollment);
 api.use('/university', university);
+api.use('/course_count', courseCount);
 
 module.exports = api;
diff --git a/src/libs/routes/courseCount.js b/src/libs/routes/courseCount.js
new file mode 100644
index 00000000..b80e38eb
--- /dev/null
+++ b/src/libs/routes/courseCount.js
@@ -0,0 +1,414 @@
+/*
+Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre
+Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
+
+This file is part of simcaq-node.
+
+simcaq-node is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+simcaq-node is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with simcaq-node.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+const express = require('express');
+
+const courseCountApp = express.Router();
+
+const libs = `${process.cwd()}/libs`;
+
+const log = require(`${libs}/log`)(module);
+
+const squel = require('squel');
+
+const query = require(`${libs}/middlewares/query`).query;
+
+const response = require(`${libs}/middlewares/response`);
+
+const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
+
+const id2str = require(`${libs}/middlewares/id2str`);
+
+const config = require(`${libs}/config`);
+
+const addMissing = require(`${libs}/middlewares/addMissing`);
+
+const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
+
+let rqf = new ReqQueryFields();
+
+courseCountApp.use(cache('15 day'));
+
+courseCountApp.get('/upper_adm_dependency', (req, res, next) => {
+    req.result = [];
+    for(let i = 1; i <= 7; ++i) {
+        req.result.push({
+            id: i,
+            name: id2str.upperAdmDependency(i)
+        });
+    };
+    next();
+}, response('upper_adm_dependency'));
+
+courseCountApp.get('/years', (req, res, next) => {
+    req.sql.from('curso_ens_superior')
+    .field('DISTINCT curso_ens_superior.ano_censo', 'year');
+    next();
+}, query, response('years'));
+
+courseCountApp.get('/year_range', (req, res, next) => {
+    req.sql.from('curso_ens_superior')
+    .field('MIN(curso_ens_superior.ano_censo)', 'start_year')
+    .field('MAX(curso_ens_superior.ano_censo)', 'end_year');
+    next();
+}, query, response('range'));
+
+courseCountApp.get('/academic_organization', (req, res, next) => {
+    req.result = [];
+    for(let i = 1; i <= 5; ++i) {
+        req.result.push({
+            id: i,
+            name: id2str.academicOrganization(i)
+        });
+    };
+    next();
+}, response('academic_organization'));
+
+courseCountApp.get('/capital', (req, res, next) => {
+    req.result = [
+        {id: null, name: 'Não Classificado'},
+        {id: 0, name: 'Não'},
+        {id: 1, name: 'Sim'}
+    ];
+    next();
+}, response('capital'));
+
+courseCountApp.get('/ocde_geral', (req, res, next) => {
+    req.result = [];
+    for(let i = 1; i <= 8; ++i) {
+        req.result.push({
+            id: i,
+            name: id2str.ocdeGeral(i)
+        });
+    };
+    next();
+}, response('ocde_geral'));
+
+courseCountApp.get('/ocde_specific', (req, res, next) => {
+    req.result = [];
+    const defaultCase = null;
+    for(let i = 1; i <= 86; ++i) {
+        let obj = {
+            id: i,
+            name: id2str.ocdeSpecific(i)
+        };
+        if (obj.name !== id2str.ocdeSpecific(defaultCase)){
+            req.result.push(obj);
+        }
+    };
+    req.result.push({
+        id: defaultCase,
+        name: id2str.ocdeSpecific(defaultCase)
+    });
+    next();
+}, response('ocde_specific'));
+
+courseCountApp.get('/ocde_detailed', (req, res, next) => {
+    req.result = [];
+    const defaultCase = null;
+    for(let i = 142; i <= 863; ++i) {
+        let obj = {
+            id: i,
+            name: id2str.ocdeDetailed(i)
+        };
+        if (obj.name !== id2str.ocdeDetailed(defaultCase)){
+            req.result.push(obj);
+        }
+    };
+    req.result.push({
+        id: defaultCase,
+        name: id2str.ocdeDetailed(defaultCase)
+    });
+    next();
+}, response('ocde_detailed'));
+
+courseCountApp.get('/academic_level', (req, res, next) => {
+    req.result = [];
+    for(let i = 1; i <= 4; ++i) {
+        req.result.push({
+            id: i,
+            name: id2str.academicLevel(i)
+        });
+    };
+    next();
+}, response('academic_level'));
+
+courseCountApp.get('/upper_education_mod', (req, res, next) => {
+    req.result = [];
+    for(let i = 1; i <= 3; ++i) {
+        req.result.push({
+            id: i,
+            name: id2str.upperEducationMod(i)
+        });
+    };
+    next();
+}, response('upper_education_mod'));
+
+courseCountApp.get('/is_free', (req, res, next) => {
+    req.result = [
+        {id: null, name: 'Não Classificado'},
+        {id: 0, name: 'Não'},
+        {id: 1, name: 'Sim'}
+    ];
+    next();
+}, response('is_free'));
+
+courseCountApp.get('/night_time', (req, res, next) => {
+    req.result = [
+        {id: null, name: 'Não Classificado'},
+        {id: 0, name: 'Não'},
+        {id: 1, name: 'Sim'}
+    ];
+    next();
+}, response('night_time'));
+
+courseCountApp.get('/university', (req, res, next) => {
+    req.sql.from('curso_ens_superior')
+    .field('DISTINCT curso_ens_superior.nome_ies', 'nome')
+    .field('curso_ens_superior.cod_ies', 'cod')
+    next();
+}, query, response('university'));
+
+rqf.addField({
+    name: 'filter',
+    field: false,
+    where: true
+}).addField({
+    name: 'dims',
+    field: true,
+    where: false
+}).addValue({
+    name: 'region',
+    table: 'regiao',
+    tableField: ['nome', 'id'],
+    resultField: ['region_name', 'region_id'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: 'nome',
+        foreign: 'nome_regiao_curso',
+        foreignTable: 'curso_ens_superior'
+    }
+}).addValue({
+    name: 'state',
+    table: 'estado',
+    tableField: ['nome', 'id'],
+    resultField: ['state_name', 'state_id'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'cod_uf_curso',
+        foreignTable: 'curso_ens_superior'
+    }
+}).addValue({
+    name: 'city',
+    table: 'curso_ens_superior',
+    tableField: ['municipio_curso', 'cod_municipio_curso'],
+    resultField: ['city_name', 'city_id'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_municipio_curso'
+    }
+}).addValue({
+    name: 'university',
+    table: 'curso_ens_superior',
+    tableField: ['cod_ies', 'nome_ies'],
+    resultField: ['university_id', 'university_name'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_ies'
+    }
+}).addValue({
+    name:'upper_adm_dependency',
+    table: 'curso_ens_superior',
+    tableField: 'cod_categoria_administrativa',
+    resultField: 'upper_adm_dependency_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_categoria_administrativa'
+    }
+}).addValue({
+    name:'academic_organization',
+    table: 'curso_ens_superior',
+    tableField: 'cod_organizacao_academica',
+    resultField: 'academic_organization_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_organizacao_academica'
+    }
+}).addValue({
+    name:'capital',
+    table: 'curso_ens_superior',
+    tableField: 'capital_curso',
+    resultField: 'capital_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'capital_curso'
+    }
+}).addValue({
+    name:'course',
+    table: 'curso_ens_superior',
+    tableField: 'nome_curso',
+    resultField: 'course_name',
+    where: {
+        relation: 'LIKE',
+        type: 'string',
+        field: 'nome_curso'
+    }
+}).addValue({
+    name:'ocde_specific',
+    table: 'curso_ens_superior',
+    tableField: ['cod_ocde_area_especifica', 'nome_ocde_area_especifica'],
+    resultField: ['ocde_specific_id', 'ocde_specific_name'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_ocde_area_especifica'
+    }
+}).addValue({
+    name:'ocde_geral',
+    table: 'curso_ens_superior',
+    tableField: ['cod_ocde_area_geral', 'nome_ocde_area_geral'],
+    resultField: ['ocde_geral_id', 'ocde_geral_name'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_ocde_area_geral'
+    }
+}).addValue({
+    name:'ocde_detailed',
+    table: 'curso_ens_superior',
+    tableField: ['cod_ocde_area_detalhada', 'nome_ocde_area_detalhada'],
+    resultField: ['ocde_detailed_id', 'ocde_datailed_name'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_ocde_area_detalhada'
+    }
+}).addValue({
+    name:'academic_level',
+    table: 'curso_ens_superior',
+    tableField: 'cod_grau_academico',
+    resultField: 'academic_level_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_grau_academico'
+    }
+}).addValue({
+    name:'upper_education_mod',
+    table: 'curso_ens_superior',
+    tableField: 'cod_modalidade_ensino',
+    resultField: 'upper_education_mod_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_modalidade_ensino'
+    }
+}).addValue({
+    name:'is_free',
+    table: 'curso_ens_superior',
+    tableField: 'gratuito',
+    resultField: 'is_free_id',
+    where: {
+        relation: '=',
+        type: 'boolean',
+        field: 'gratuito'
+    }
+}).addValue({
+    name:'night_time',
+    table: 'curso_ens_superior',
+    tableField: 'noturno_curso',
+    resultField: 'night_time_id',
+    where: {
+        relation: '=',
+        type: 'boolean',
+        field: 'noturno_curso'
+    }
+}).addValue({
+    name:'situation',
+    table: 'curso_ens_superior',
+    tableField: 'cod_situacao_curso',
+    resultField: 'situacao_curso_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_situacao_curso'
+    }
+}).addValue({
+    name:'year',
+    table: 'curso_ens_superior',
+    tableField: 'ano_censo',
+    resultField: 'year',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'ano_censo'
+    }
+}).addValue({
+    name: 'min_year',
+    table: 'curso_ens_superior',
+    tableField: 'ano_censo',
+    resultField: 'year',
+    where: {
+        relation: '>=',
+        type: 'integer',
+        table: 'curso_ens_superior',
+        field: 'ano_censo'
+    }
+}).addValue({
+    name: 'max_year',
+    table: 'curso_ens_superior',
+    tableField: 'ano_censo',
+    resultField: 'year',
+    where: {
+        relation: '<=',
+        type: 'integer',
+        table: 'curso_ens_superior',
+        field: 'ano_censo'
+    }
+});
+
+courseCountApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
+    req.sql.from('curso_ens_superior')
+        .field('COUNT(curso_ens_superior.cod_curso)', 'total')
+        .field("'Brasil'", 'name')
+        .field('curso_ens_superior.ano_censo', 'year')
+        .group('curso_ens_superior.ano_censo')
+        .order('curso_ens_superior.ano_censo')
+        .where('curso_ens_superior.tipo_atributo_ingresso <> 1')
+        .where('curso_ens_superior.cod_nivel_academico = 1');
+
+    next();
+}, query, addMissing(rqf), id2str.transform(), response('course_count'));
+
+module.exports = courseCountApp;
diff --git a/src/libs/routes/universityEnrollment.js b/src/libs/routes/universityEnrollment.js
new file mode 100644
index 00000000..9eb452fd
--- /dev/null
+++ b/src/libs/routes/universityEnrollment.js
@@ -0,0 +1,479 @@
+/*
+Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre
+Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
+
+This file is part of simcaq-node.
+
+simcaq-node is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+simcaq-node is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with simcaq-node.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+const express = require('express');
+
+const universityEnrollmentApp = express.Router();
+
+const libs = `${process.cwd()}/libs`;
+
+const log = require(`${libs}/log`)(module);
+
+const squel = require('squel');
+
+const query = require(`${libs}/middlewares/query`).query;
+
+const response = require(`${libs}/middlewares/response`);
+
+const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
+
+const id2str = require(`${libs}/middlewares/id2str`);
+
+const addMissing = require(`${libs}/middlewares/addMissing`);
+
+const config = require(`${libs}/config`);
+
+const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
+
+let rqf = new ReqQueryFields();
+
+universityEnrollmentApp.get('/years', (req, res, next) => {
+    req.sql.from('aluno_ens_superior')
+    .field('DISTINCT aluno_ens_superior.ano_censo', 'year');
+    next();
+}, query, response('years'));
+
+universityEnrollmentApp.get('/year_range', (req, res, next) => {
+    req.sql.from('aluno_ens_superior')
+    .field('MIN(aluno_ens_superior.ano_censo)', 'start_year')
+    .field('MAX(aluno_ens_superior.ano_censo)', 'end_year');
+    next();
+}, query, response('range'));
+
+universityEnrollmentApp.get('/academic_organization', (req, res, next) => {
+    req.result = [];
+    for(let i = 1; i <= 5; ++i) {
+        req.result.push({
+            id: i,
+            name: id2str.academicOrganization(i)
+        });
+    };
+    next();
+}, response('academic_organization'));
+
+universityEnrollmentApp.get('/upper_adm_dependency', (req, res, next) => {
+    req.result = [];
+    for(let i = 1; i <= 7; ++i) {
+        req.result.push({
+            id: i,
+            name: id2str.upperAdmDependency(i)
+        });
+    };
+    next();
+}, response('upper_adm_dependency'));
+
+universityEnrollmentApp.get('/ocde_geral', (req, res, next) => {
+    req.result = [];
+    for(let i = 0; i <= 8; ++i) {
+        req.result.push({
+            id: i,
+            name: id2str.ocdeGeral(i)
+        });
+    };
+    next();
+}, response('ocde_geral'));
+
+universityEnrollmentApp.get('/ocde_specific', (req, res, next) => {
+    req.result = [];
+    const defaultCase = null;
+    for(let i = 1; i <= 86; ++i) {
+        let obj = {
+            id: i,
+            name: id2str.ocdeSpecific(i)
+        };
+        if (obj.name !== id2str.ocdeSpecific(defaultCase)){
+            req.result.push(obj);
+        }
+    };
+    req.result.push({
+        id: defaultCase,
+        name: id2str.ocdeSpecific(defaultCase)
+    });
+    next();
+}, response('ocde_specific'));
+
+universityEnrollmentApp.get('/ocde_detailed', (req, res, next) => {
+    req.result = [];
+    const defaultCase = null;
+    for(let i = 142; i <= 863; ++i) {
+        let obj = {
+            id: i,
+            name: id2str.ocdeDetailed(i)
+        };
+        if (obj.name !== id2str.ocdeDetailed(defaultCase)){
+            req.result.push(obj);
+        }
+    };
+    req.result.push({
+        id: defaultCase,
+        name: id2str.ocdeDetailed(defaultCase)
+    });
+    next();
+}, response('ocde_detailed'));
+
+universityEnrollmentApp.get('/upper_turn', (req, res, next) => {
+    req.result = [];
+    for(let i = 1; i <= 4; ++i) {
+        req.result.push({
+            id: i,
+            name: id2str.upperTurn(i)
+        });
+    };
+    next();
+}, response('upper_turn'));
+
+universityEnrollmentApp.get('/student_deficiency', (req, res, next) => {
+    req.result = [];
+    for(let i = 0; i <= 1; ++i) {
+        req.result.push({
+            id: i,
+            name: id2str.studentDeficiency(i)
+        });
+    };
+    next();
+}, response('student_deficiency'));
+
+universityEnrollmentApp.get('/ethnic_group_ies', (req, res, next) => {
+    req.result = [];
+    for(let i = 1; i <=5; ++i) {
+        req.result.push({
+            id: i,
+            name: id2str.ethnicGroupIES(i)
+        });
+    }
+    next();
+}, response('ethnic_group_ies'));
+
+universityEnrollmentApp.get('/school_type', (req, res, next) => {
+    req.result = [];
+    for(let i = 1; i <= 2; ++i) {
+        req.result.push({
+            id: i,
+            name: id2str.schoolType(i)
+        });
+    };
+    next();
+}, response('school_type'));
+
+universityEnrollmentApp.get('/university', (req, res, next) => {
+    req.sql.from('aluno_ens_superior')
+    .field('DISTINCT aluno_ens_superior.nome_ies', 'nome')
+    .field('aluno_ens_superior.cod_ies', 'cod')
+    next();
+}, query, response('university'));
+
+universityEnrollmentApp.get('/academic_level', (req, res, next) => {
+    req.result = [];
+    for(let i = 1; i <= 4; ++i) {
+        req.result.push({
+            id: i,
+            name: id2str.academicLevel(i)
+        });
+    };
+    next();
+}, response('academic_level'));
+
+universityEnrollmentApp.get('/gender_ies', function (req, res, next) {
+    req.result = [];
+    for (var i = 1; i <= 2; ++i) {
+        req.result.push({
+            id: i,
+            name: id2str.genderIES(i)
+        });
+    };
+    next();
+}, response('gender_ies'));
+
+universityEnrollmentApp.get('/upper_education_mod', function (req, res, next) {
+    req.result = [];
+    for (var i = 1; i <= 3; ++i) {
+        req.result.push({
+            id: i,
+            name: id2str.upperEducationMod(i)
+        });
+    };
+    next();
+}, response('upper_education_mod'));
+
+universityEnrollmentApp.get('/age_student_code', function (req, res, next) {
+    req.result = [];
+    for (var i = 1; i <= 6; ++i) {
+        req.result.push({
+            id: i,
+            name: id2str.ageStudentCode(i)
+        });
+    };
+    next();
+}, response('age_student_code'));
+
+rqf.addField({
+    name: 'filter',
+    field: false,
+    where: true
+}).addField({
+    name: 'dims',
+    field: true,
+    where: false
+}).addValue({
+    name: 'min_year',
+    table: '@',
+    tableField: 'ano_censo',
+    resultField: 'year',
+    where: {
+        relation: '>=',
+        type: 'integer',
+        table: '@',
+        field: 'ano_censo'
+    }
+}).addValue({
+    name: 'max_year',
+    table: '@',
+    tableField: 'ano_censo',
+    resultField: 'year',
+    where: {
+        relation: '<=',
+        type: 'integer',
+        table: '@',
+        field: 'ano_censo'
+    }
+}).addValue({
+    name: 'state',
+    table: 'estado',
+    tableField: ['nome', 'id'],
+    resultField: ['state_name', 'state_id'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_uf_ies',
+        table: '@'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'cod_uf_ies',
+        foreignTable: '@'
+    }
+}).addValue({
+    name: 'city',
+    table: 'municipio',
+    tableField: ['nome', 'id'],
+    resultField: ['city_name', 'city_id'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_municipio_ies',
+        table: '@'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'cod_municipio_ies',
+        foreignTable: '@'
+    }
+}).addValue({
+    name: 'region',
+    table: 'regiao',
+    tableField: ['nome', 'id'],
+    resultField: ['region_name', 'region_id'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'cod_regiao_ies',
+        foreignTable: 'aluno_ens_superior'
+    }
+}).addValue({
+    name: 'university',
+    table: 'aluno_ens_superior',
+    tableField: ['cod_ies', 'nome_ies'],
+    resultField: ['university_id', 'university_name'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_ies'
+    }
+}).addValue({
+    name: 'age_student_code',
+    table: 'aluno_ens_superior',
+    tableField: 'idade_aluno_codigo',
+    resultField: 'age_student_code_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'idade_aluno_codigo'
+    }
+}).addValue({
+    name: 'upper_adm_dependency',
+    table: 'aluno_ens_superior',
+    tableField: 'cod_categoria_administrativa',
+    resultField: 'upper_adm_dependency_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        table: 'aluno_ens_superior',
+        field: 'cod_categoria_administrativa'
+    }
+}).addValue({
+    name: 'academic_organization',
+    table: 'aluno_ens_superior',
+    tableField: 'cod_organizacao_academica',
+    resultField: 'academic_organization_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        table: 'aluno_ens_superior',
+        field: 'cod_organizacao_academica'
+    }
+}).addValue({
+    name:'ocde_specific',
+    table: 'aluno_ens_superior',
+    tableField: 'cod_ocde_area_especifica',
+    resultField: 'ocde_specific_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_ocde_area_especifica'
+    }
+}).addValue({
+    name:'ocde_geral',
+    table: 'aluno_ens_superior',
+    tableField: 'cod_ocde_area_geral',
+    resultField: 'ocde_geral_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_ocde_area_geral'
+    }
+}).addValue({
+    name:'ocde_detailed',
+    table: 'aluno_ens_superior',
+    tableField: 'cod_ocde_area_detalhada',
+    resultField: 'ocde_detailed_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_ocde_area_detalhada'
+    }
+}).addValue({
+    name:'academic_level',
+    table: 'aluno_ens_superior',
+    tableField: 'cod_grau_academico',
+    resultField: 'academic_level_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_grau_academico'
+    }
+}).addValue({
+    name:'upper_education_mod',
+    table: 'aluno_ens_superior',
+    tableField: 'cod_modalidade_ensino',
+    resultField: 'upper_education_mod_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_modalidade_ensino'
+    }
+}).addValue({
+    name:'upper_turn',
+    table: 'aluno_ens_superior',
+    tableField: 'cod_turno_aluno',
+    resultField: 'upper_turn_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_turno_aluno'
+    }
+}).addValue({
+    name:'ethnic_group_ies',
+    table: 'aluno_ens_superior',
+    tableField: 'cod_cor_raca_aluno',
+    resultField: 'ethnic_group_ies_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_cor_raca_aluno'
+    }
+}).addValue({
+    name:'student_deficiency',
+    table: 'aluno_ens_superior',
+    tableField: 'aluno_deficiencia_transtorno_superdotacao',
+    resultField: 'student_deficiency_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'aluno_deficiencia_transtorno_superdotacao'
+    }
+}).addValue({
+    name:'school_type',
+    table: 'aluno_ens_superior',
+    tableField: 'tipo_escola_ensino_medio',
+    resultField: 'school_type_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'tipo_escola_ensino_medio'
+    }
+}).addValue({
+    name: 'university',
+    table: 'aluno_ens_superior',
+    tableField: ['cod_ies', 'nome_ies'],
+    resultField: ['university_id', 'university_name'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_ies'
+    }
+}).addValue({
+    name: 'gender_ies',
+    table: 'aluno_ens_superior',
+    tableField: 'genero_aluno',
+    resultField: 'gender_ies_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'genero_aluno'
+    }
+}).addValue({
+    name:'academic_level',
+    table: 'aluno_ens_superior',
+    tableField: 'cod_grau_academico',
+    resultField: 'academic_level_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_grau_academico'
+    }
+});
+
+universityEnrollmentApp.get('/', rqf.parse(), (req, res, next) => {
+    req.sql.field('COUNT(*)', 'total')
+    .field("'Brasil'", 'name')
+    .field('aluno_ens_superior.ano_censo', 'year')
+    .from('aluno_ens_superior')
+    .where('aluno_ens_superior.matriculado = 1 AND aluno_ens_superior.cod_nivel_academico = 1')
+    .group('aluno_ens_superior.ano_censo')
+    .order('aluno_ens_superior.ano_censo')
+
+   next();
+},  rqf.build(), query, addMissing(rqf), id2str.transform(false), response('universityEnrollment'));
+
+module.exports = universityEnrollmentApp;
-- 
GitLab