Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6e83949
First proposal for the database.
MichelCF May 13, 2022
f0b6afb
Merge pull request #1 from MichelCF/dev
MichelCF May 13, 2022
8e370e2
Add Dockerfile and schema.sql from the database.
MichelCF May 14, 2022
d3e5864
Merge pull request #2 from MichelCF/dev
MichelCF May 14, 2022
3a6bddc
Add primary keys in the endereco,indice_cardiaco and indice_pulmonar.
MichelCF May 16, 2022
ad4f3f1
Add Carga_Batch.
MichelCF May 16, 2022
73380b4
Adding comma before foreign key.
MichelCF May 16, 2022
ebddac7
modifying the primary keys from bigint to serial of tables endereco, …
MichelCF May 17, 2022
4ddfc12
Merge pull request #3 from MichelCF/dev
MichelCF May 17, 2022
d5bb3c2
add models Indice_Cardiaco and Indice_Pulmonar.
MichelCF May 17, 2022
c8a36b4
refactoring connection.py
MichelCF May 17, 2022
fe7a8cc
refactoring carga_batch.py
MichelCF May 17, 2022
27f800f
add Dockerfile Carga_Batch.
MichelCF May 18, 2022
0f240cd
add insert_pulmonar, insert_cardiaco.
MichelCF May 18, 2022
12c1ae4
Changing localhost to the container name.
MichelCF May 18, 2022
4e9cbe4
add docker-compose file.
MichelCF May 18, 2022
1b3340b
adjusting details.
MichelCF May 18, 2022
ea19942
adjusting details.
MichelCF May 18, 2022
073c543
test data.
MichelCF May 18, 2022
5e4e2fd
Merge pull request #4 from MichelCF/dev
MichelCF May 19, 2022
3491773
add API.
MichelCF May 20, 2022
fe4c6c4
Finalizing the dockerfile
MichelCF May 20, 2022
f4b2ab1
Finalizing the dockerfile
MichelCF May 20, 2022
f8c2823
Finalizing the docker-compose.
MichelCF May 20, 2022
da45d22
Adding the routes layer
MichelCF May 20, 2022
46f64db
Fixing the .gitignore file
MichelCF May 20, 2022
b46ad2c
Fixing README for database tables.
MichelCF May 20, 2022
40bcb9d
Adding Batch Load documentation and API documentation.
MichelCF May 20, 2022
ff1ca6e
correcting cardiaca for cardiaco.
MichelCF May 20, 2022
22a5c5d
[200~correcting details
MichelCF May 20, 2022
1209148
Adding information on how to run.
MichelCF May 20, 2022
0cb8c29
Merge pull request #5 from MichelCF/dev
MichelCF May 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions solucao/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Carga_Batch/anlix_desafio/
Carga_Batch/__pycache__/
API/node_modules
1 change: 1 addition & 0 deletions solucao/API/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
7 changes: 7 additions & 0 deletions solucao/API/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:16.15-alpine
WORKDIR /api
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 21262
CMD ["npm", "start"]
215 changes: 215 additions & 0 deletions solucao/API/config/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
const express = require('express')
const routes = express.Router()
const SqlString = require('sqlstring')
const pg = require('pg')
const Pool = require('pg').Pool

const pool = new Pool({
user: 'anlix',
host: 'db',
database: 'hospital',
password: '1234',
})

routes.get('/', (req,res) => {
return res.json({"Menssagem": "Online"})
})

routes.get('/HeartFeature/:cpf', (req,res) => {
const sql = `SELECT ind_cardiaco
FROM indice_cardiaco
INNER JOIN paciente ON paciente.cpf = indice_cardiaco.cpf
WHERE paciente.cpf=?
ORDER BY indice_cardiaco.data_hora DESC limit 1`

pool.query(SqlString.format(sql, req.params.cpf),
(error, results) => {
if (error) {
throw error
}
res.status(200).json(results.rows)
})
})

routes.get('/LungFeature/:cpf', (req,res) => {
const sql = `
SELECT ind_pulmonar
FROM indice_pulmonar
INNER JOIN paciente ON paciente.cpf = indice_pulmonar.cpf
WHERE paciente.cpf=?
ORDER BY indice_pulmonar.data_hora DESC limit 1`

pool.query(SqlString.format(sql, req.params.cpf),
(error, results) => {
if (error) {
throw error
}
res.status(200).json(results.rows)
})
})

routes.get('/AllLastFeatures/:cpf', (req,res) => {
const sql =`
SELECT indice_cardiaco.ind_cardiaco, indice_pulmonar.ind_pulmonar
FROM paciente
INNER JOIN indice_cardiaco ON indice_cardiaco.cpf = paciente.cpf
INNER JOIN indice_pulmonar ON indice_pulmonar.cpf = paciente.cpf
WHERE paciente.cpf=?
ORDER BY indice_cardiaco.data_hora DESC,
indice_pulmonar.data_hora DESC limit 1;


`

pool.query(SqlString.format(sql, req.params.cpf),
(error, results) => {
if (error) {
throw error
}
res.status(200).json(results.rows)
})
})

routes.get('/allIndicesForData/:data', (req,res) => {
const sql =`
SELECT paciente.cpf, CAST(ind_cardiaco as VARCHAR),
CAST(null as VARCHAR) as ind_pulmonar,
TO_CHAR(data_hora, 'YYYY-MM-DD') as data
FROM indice_cardiaco
INNER JOIN paciente ON paciente.cpf = indice_cardiaco.cpf
WHERE TO_CHAR(data_hora, 'YYYY-MM-DD')=?
UNION ALL
SELECT paciente.cpf, CAST(null as VARCHAR)as ind_cardiaco,
CAST(ind_pulmonar as VARCHAR),
TO_CHAR(data_hora, 'YYYY-MM-DD') as data
FROM indice_pulmonar
INNER JOIN paciente ON paciente.cpf = indice_pulmonar.cpf
WHERE TO_CHAR(data_hora, 'YYYY-MM-DD')=?;
`



const [dia, mes, ano] = req.params.data.split('-')
const data = [ano, mes, dia].join('-')

pool.query(SqlString.format(sql, [data,data]),
(error, results) => {
if (error) {
throw error
}
res.status(200).json(results.rows)
})
})


routes.get('/CharacteristicBetweenDates', (req, res) => {
let cpf = req.body.cpf
let caracteristica = req.body.caracteristica
let [dia_inicial, mes_inicial, ano_inicial] = req.body.data_inicial.split('-')
let [dia_final, mes_final, ano_final] = req.body.data_final.split('-')
const data_inicial = [ano_inicial, mes_inicial, dia_inicial].join('-')
const data_final = [ano_final, mes_final, dia_final].join('-')
const parametros = [data_inicial, data_final, cpf]

const sql_cardiaco = `
SELECT paciente.cpf, indice_cardiaco.ind_cardiaco, indice_cardiaco.data_hora
FROM paciente
INNER JOIN indice_cardiaco ON indice_cardiaco.cpf = paciente.cpf
WHERE ?::date >= indice_cardiaco.data_hora AND indice_cardiaco.data_hora <= ?::date
AND paciente.cpf = ?
`

const sql_pulmonar = `
SELECT paciente.cpf, indice_pulmonar.ind_pulmonar, indice_pulmonar.data_hora
FROM paciente
INNER JOIN indice_pulmonar ON indice_pulmonar.cpf = paciente.cpf
WHERE ?::date >= indice_pulmonar.data_hora AND indice_pulmonar.data_hora <= ?::date
AND paciente.cpf = ?
`
if(caracteristica === 'cardiaco'){
pool.query(SqlString.format(sql_cardiaco, parametros),
(error, results) => {
if (error) {
throw error
}
res.status(200).json(results.rows)
})
}
else{
pool.query(SqlString.format(sql_pulmonar, parametros),
(error, results) => {
if (error) {
throw error
}
res.status(200).json(results.rows)
})
}

})

routes.get('/LastCharacteristicBetweenDates', (req, res) => {
let cpf = req.body.cpf
let caracteristica = req.body.caracteristica
let teste = req.body.data_inicial
let [dia_inicial, mes_inicial, ano_inicial] = teste.split('-')
let [dia_final, mes_final, ano_final] = req.body.data_final.split('-')
const data_inicial = [ano_inicial, mes_inicial, dia_inicial].join('-')
const data_final = [ano_final, mes_final, dia_final].join('-')
const parametros = [data_inicial, data_final, cpf]

const sql_cardiaco = `
SELECT paciente.cpf, indice_cardiaco.ind_cardiaco, indice_cardiaco.data_hora
FROM paciente
INNER JOIN indice_cardiaco ON indice_cardiaco.cpf = paciente.cpf
WHERE ?::date >= indice_cardiaco.data_hora AND indice_cardiaco.data_hora <= ?::date
AND paciente.cpf = ?
ORDER BY indice_cardiaco.data_hora DESC limit 1
`

const sql_pulmonar = `
SELECT paciente.cpf, indice_pulmonar.ind_pulmonar, indice_pulmonar.data_hora
FROM paciente
INNER JOIN indice_pulmonar ON indice_pulmonar.cpf = paciente.cpf
WHERE ?::date >= indice_pulmonar.data_hora AND indice_pulmonar.data_hora <= ?::date
AND paciente.cpf = ?
ORDER BY indice_pulmonar.data_hora DESC limit 1
`
if(caracteristica === 'cardiaco'){
pool.query(SqlString.format(sql_cardiaco, parametros),
(error, results) => {
if (error) {
throw error
}
res.status(200).json(results.rows)
})
}
else{
pool.query(SqlString.format(sql_pulmonar, parametros),
(error, results) => {
if (error) {
throw error
}
res.status(200).json(results.rows)
})
}

})

routes.get('/ConsultPatientByName', (req, res) => {
const nome = '%'+req.body.nome+'%'
const sql = `
SELECT *
FROM paciente
WHERE nome LIKE ?
`
pool.query(SqlString.format(sql, nome),
(error, results) => {
if (error) {
throw error
}
res.status(200).json(results.rows)
})
})


module.exports = routes
18 changes: 18 additions & 0 deletions solucao/API/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const express = require('express')
const morgan = require('morgan')
const cors = require('cors')
const bodyParser = require('body-parser')
const routes = require('./config/routes')

const app = express()

app.use(morgan('dev'))
app.use(bodyParser.urlencoded({extended: false}))
app.use(express.json())
app.use(cors())
app.use(routes)


app.listen(21262, () =>{
console.log(`Express started at http://localhost:21262`)
})
Loading