diff --git a/src/libs/routes_v1/enrollmentRate.js b/src/libs/routes_v1/enrollmentRate.js index ab2c9018167c5f423c56183c54321d8c8bbd628b..6a87a5f17c3418374e16628f77a8bfd201556d90 100644 --- a/src/libs/routes_v1/enrollmentRate.js +++ b/src/libs/routes_v1/enrollmentRate.js @@ -110,6 +110,25 @@ EnrollmentRateApp.get('/state', (req, res, next) => { next(); }, response('state')); +EnrollmentRateApp.get('/age_range', (req, res, next) => { + req.result = [] + for (let i = 1; i < 6; i++) { + req.result.push({ + id: i, name: id2str.ageRange(i) + }); + } + next(); +}, response('age_range')); + +EnrollmentRateApp.get('/attended_modality', (req, res, next) => { + req.result = [] + for (let i = 1; i < 8; i++) { + req.result.push({ + id: i, name: id2str.attendedModality(i) + }); + } + next(); +}, response('attended_modality')); rqf.addField({ @@ -121,7 +140,7 @@ rqf.addField({ field: true, where: false }).addValue({ - name: 'location', + name: 'situacao_domicilio', table: 'pnad_novo', tableField: 'situacao_domicilio', resultField: 'location_id', @@ -141,10 +160,10 @@ rqf.addField({ field: 'localizacao_id' } }).addValue({ - name: 'cap_code', + name: 'cod_cap', table: 'pnad_novo', tableField: 'cod_cap', - resultField: 'cap_code_id', + resultField: 'cod_cap_id', where: { relation: '=', type: 'integer', @@ -161,7 +180,7 @@ rqf.addField({ field: 'municipio_id' } }).addValue({ - name: 'region', + name: 'cod_regiao', table: 'pnad_novo', tableField: 'cod_regiao', resultField: 'region_id', @@ -181,10 +200,10 @@ rqf.addField({ field: 'regiao_id' } }).addValue({ - name: 'state', + name: 'cod_uf', table: 'pnad_novo', tableField: 'cod_uf', - resultField: 'cod_uf', + resultField: 'cod_uf_id', where: { relation: '=', type: 'integer', @@ -213,7 +232,6 @@ rqf.addField({ }) - function matchQueries(queryPartial, queryTotal) { let match = []; console.log(queryPartial, queryTotal) @@ -222,46 +240,60 @@ function matchQueries(queryPartial, queryTotal) { queryPartial.forEach((partial) => { console.log(result.year, partial.year) if (result.year === partial.year) { + match.push({ + year: result.year, + age_range: result.age_range, + age_range_name: id2str.ageRange(result.age_range), + location: result.location, + location_name: id2str.location(result.location), + cap_code: result.cap_code, + cap_code_name: id2str.capitalCode(result.cap_code), + region: result.region, + region_name: id2str.regionCode(result.region), + state: result.state, + state_name: id2str.stateName(result.state) + }); + + switch (result.age_range) { case 1: - console.log("é 1") match.push({ - year: result.year, - age_range: result.age_range, // total: result.total, // total_partial: partial.total_inf_cre, + attended_modality_id: 1, + attended_modality_name: id2str.attendedModality(1), total: ((partial.total_inf_cre/result.total) * 100).toFixed(2), }); found = true; break; case 2: match.push({ - year: result.year, - age_range: result.age_range, + attended_modality_id: 2, + attended_modality_name: id2str.attendedModality(2), total: ((partial.total_inf_pre/result.total) * 100).toFixed(2), }); found = true; break; case 3: match.push({ - year: result.year, - age_range: result.age_range, + attended_modality_id: 4, + attended_modality_name: id2str.attendedModality(4), total: ((partial.total_fund_ai/result.total) * 100).toFixed(2), }); found = true; break; case 4: match.push({ - year: result.year, - age_range: result.age_range, + attended_modality_id: 5, + attended_modality_name: id2str.attendedModality(5), total: ((partial.total_fund_af/result.total) * 100).toFixed(2), }); found = true; break; case 5: match.push({ - year: result.year, - age_range: result.age_range, + attended_modality_id: 7, + attended_modality: id2str.attendedModality(7), total: ((partial.total_med/result.total) * 100).toFixed(2), }); found = true; @@ -275,8 +307,8 @@ function matchQueries(queryPartial, queryTotal) { }); if (!found) { match.push({ - year: result.year, - age_range: result.age_range, + attended_modality_id: 0, + attended_modality_name: 'Não informado', total: result.total, total_taxa: 0, }); @@ -307,10 +339,18 @@ req.querySet = []; .from('pnad_novo') .field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total') .field('pnad_novo.faixa_etaria', 'age_range') + .field('pnad_novo.cod_uf', 'state') + .field('pnad_novo.situacao_domicilio', 'location') + .field('pnad_novo.cod_cap', 'cap_code') + .field('pnad_novo.cod_regiao', 'region') .field('pnad_novo.ano_ref', 'year') .where('pnad_novo.ano_ref IN (2019, 2022, 2023) AND pnad_novo.faixa_etaria IN (1, 2, 3, 4, 5)') .group('pnad_novo.ano_ref') .group('pnad_novo.faixa_etaria') + .group('pnad_novo.cod_uf') + .group('pnad_novo.situacao_domicilio') + .group('pnad_novo.cod_cap') + .group('pnad_novo.cod_regiao') .order('pnad_novo.ano_ref') .order('pnad_novo.faixa_etaria'); @@ -324,6 +364,6 @@ next(); let newObj = matchQueries(req.result[0], req.result[1]); req.result = newObj; next(); -}, id2str.transform(false), response('enrollmentRate')); +}, response('enrollmentRate')); module.exports = EnrollmentRateApp;