Skip to content
Snippets Groups Projects
Commit 67d966e5 authored by tgcl21's avatar tgcl21
Browse files

Starded fixes

parent 9c9b68cd
Branches
No related tags found
No related merge requests found
...@@ -110,6 +110,25 @@ EnrollmentRateApp.get('/state', (req, res, next) => { ...@@ -110,6 +110,25 @@ EnrollmentRateApp.get('/state', (req, res, next) => {
next(); next();
}, response('state')); }, 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({ rqf.addField({
...@@ -121,7 +140,7 @@ rqf.addField({ ...@@ -121,7 +140,7 @@ rqf.addField({
field: true, field: true,
where: false where: false
}).addValue({ }).addValue({
name: 'location', name: 'situacao_domicilio',
table: 'pnad_novo', table: 'pnad_novo',
tableField: 'situacao_domicilio', tableField: 'situacao_domicilio',
resultField: 'location_id', resultField: 'location_id',
...@@ -141,10 +160,10 @@ rqf.addField({ ...@@ -141,10 +160,10 @@ rqf.addField({
field: 'localizacao_id' field: 'localizacao_id'
} }
}).addValue({ }).addValue({
name: 'cap_code', name: 'cod_cap',
table: 'pnad_novo', table: 'pnad_novo',
tableField: 'cod_cap', tableField: 'cod_cap',
resultField: 'cap_code_id', resultField: 'cod_cap_id',
where: { where: {
relation: '=', relation: '=',
type: 'integer', type: 'integer',
...@@ -161,7 +180,7 @@ rqf.addField({ ...@@ -161,7 +180,7 @@ rqf.addField({
field: 'municipio_id' field: 'municipio_id'
} }
}).addValue({ }).addValue({
name: 'region', name: 'cod_regiao',
table: 'pnad_novo', table: 'pnad_novo',
tableField: 'cod_regiao', tableField: 'cod_regiao',
resultField: 'region_id', resultField: 'region_id',
...@@ -181,10 +200,10 @@ rqf.addField({ ...@@ -181,10 +200,10 @@ rqf.addField({
field: 'regiao_id' field: 'regiao_id'
} }
}).addValue({ }).addValue({
name: 'state', name: 'cod_uf',
table: 'pnad_novo', table: 'pnad_novo',
tableField: 'cod_uf', tableField: 'cod_uf',
resultField: 'cod_uf', resultField: 'cod_uf_id',
where: { where: {
relation: '=', relation: '=',
type: 'integer', type: 'integer',
...@@ -213,7 +232,6 @@ rqf.addField({ ...@@ -213,7 +232,6 @@ rqf.addField({
}) })
function matchQueries(queryPartial, queryTotal) { function matchQueries(queryPartial, queryTotal) {
let match = []; let match = [];
console.log(queryPartial, queryTotal) console.log(queryPartial, queryTotal)
...@@ -222,46 +240,60 @@ function matchQueries(queryPartial, queryTotal) { ...@@ -222,46 +240,60 @@ function matchQueries(queryPartial, queryTotal) {
queryPartial.forEach((partial) => { queryPartial.forEach((partial) => {
console.log(result.year, partial.year) console.log(result.year, partial.year)
if (result.year === partial.year) { if (result.year === partial.year) {
switch (result.age_range) {
case 1:
console.log("é 1")
match.push({ match.push({
year: result.year, year: result.year,
age_range: result.age_range, 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:
match.push({
// total: result.total, // total: result.total,
// total_partial: partial.total_inf_cre, // 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), total: ((partial.total_inf_cre/result.total) * 100).toFixed(2),
}); });
found = true; found = true;
break; break;
case 2: case 2:
match.push({ match.push({
year: result.year, attended_modality_id: 2,
age_range: result.age_range, attended_modality_name: id2str.attendedModality(2),
total: ((partial.total_inf_pre/result.total) * 100).toFixed(2), total: ((partial.total_inf_pre/result.total) * 100).toFixed(2),
}); });
found = true; found = true;
break; break;
case 3: case 3:
match.push({ match.push({
year: result.year, attended_modality_id: 4,
age_range: result.age_range, attended_modality_name: id2str.attendedModality(4),
total: ((partial.total_fund_ai/result.total) * 100).toFixed(2), total: ((partial.total_fund_ai/result.total) * 100).toFixed(2),
}); });
found = true; found = true;
break; break;
case 4: case 4:
match.push({ match.push({
year: result.year, attended_modality_id: 5,
age_range: result.age_range, attended_modality_name: id2str.attendedModality(5),
total: ((partial.total_fund_af/result.total) * 100).toFixed(2), total: ((partial.total_fund_af/result.total) * 100).toFixed(2),
}); });
found = true; found = true;
break; break;
case 5: case 5:
match.push({ match.push({
year: result.year, attended_modality_id: 7,
age_range: result.age_range, attended_modality: id2str.attendedModality(7),
total: ((partial.total_med/result.total) * 100).toFixed(2), total: ((partial.total_med/result.total) * 100).toFixed(2),
}); });
found = true; found = true;
...@@ -275,8 +307,8 @@ function matchQueries(queryPartial, queryTotal) { ...@@ -275,8 +307,8 @@ function matchQueries(queryPartial, queryTotal) {
}); });
if (!found) { if (!found) {
match.push({ match.push({
year: result.year, attended_modality_id: 0,
age_range: result.age_range, attended_modality_name: 'Não informado',
total: result.total, total: result.total,
total_taxa: 0, total_taxa: 0,
}); });
...@@ -307,10 +339,18 @@ req.querySet = []; ...@@ -307,10 +339,18 @@ req.querySet = [];
.from('pnad_novo') .from('pnad_novo')
.field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total') .field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total')
.field('pnad_novo.faixa_etaria', 'age_range') .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') .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)') .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.ano_ref')
.group('pnad_novo.faixa_etaria') .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.ano_ref')
.order('pnad_novo.faixa_etaria'); .order('pnad_novo.faixa_etaria');
...@@ -324,6 +364,6 @@ next(); ...@@ -324,6 +364,6 @@ next();
let newObj = matchQueries(req.result[0], req.result[1]); let newObj = matchQueries(req.result[0], req.result[1]);
req.result = newObj; req.result = newObj;
next(); next();
}, id2str.transform(false), response('enrollmentRate')); }, response('enrollmentRate'));
module.exports = EnrollmentRateApp; module.exports = EnrollmentRateApp;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment