Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yassine.selmi committed Mar 29, 2020
0 parents commit b6bb2d5
Show file tree
Hide file tree
Showing 73 changed files with 2,821 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
*/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
*/.next/
/out/

# production
/build

# misc
.DS_Store
.env*

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

.now

.idea

logs/*
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Somesh Kar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# COVID19 Tunisia Cluster Network Graph

This is a dashboard of network connections and clusters to track outbreak and transmission COVID19 in Tunisia. The primary data source is collected by volunteers at [Google Form](https://forms.gle/QxWe5zsfj1JfRyjM7), a database collated from various news as well as government sources.
The intention of this graph is to open up options for analysis for policy/decision makers so that they can be more strategic in testing cases and deploying resources like ventilators, beds & medicines.
16 changes: 16 additions & 0 deletions backend.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:12.2.0-alpine

# Create app directory
WORKDIR /app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
ADD backend ./

RUN npm install
# If you are building your code for production
# RUN npm ci --only=production

EXPOSE 8080
CMD [ "npm", "start" ]
16 changes: 16 additions & 0 deletions backend.prod.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:12.2.0-alpine

# Create app directory
WORKDIR /app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
ADD backend ./

RUN npm install
# If you are building your code for production
RUN npm ci --only=production

EXPOSE 8080
CMD [ "npm", "start" ]
6 changes: 6 additions & 0 deletions backend/app/config/db.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
HOST: process.env.MYSQL_HOST,
USER: process.env.MYSQL_USER,
PASSWORD: process.env.MYSQL_PASSWORD,
DB: process.env.MYSQL_DATABASE,
};
14 changes: 14 additions & 0 deletions backend/app/controllers/lastupdate.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const LastUpdate = require("../models/lastupdate.model.js");

// Retrieve all Customers from the database.
exports.getLastUpdate = (req, res) => {
LastUpdate.getLastUpdate((err, data) => {
if (err)
res.status(500).send({
message:
err.message || "Some error occurred while retrieving customers."
});
else res.send(data);
});
};

26 changes: 26 additions & 0 deletions backend/app/controllers/patient.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const Patient = require("../models/patient.model.js");

// Retrieve all Customers from the database.
exports.findAll = (req, res) => {
Patient.getAll((err, data) => {
if (err)
res.status(500).send({
message:
err.message || "Some error occurred while retrieving customers."
});
else res.send(data);
});
};



exports.findAllByDate = (req, res) => {
Patient.getAllByDate(req.params.reportDate, (err, data) => {
if (err)
res.status(500).send({
message:
err.message || "Some error occurred while retrieving customers."
});
else res.send(data);
});
};
11 changes: 11 additions & 0 deletions backend/app/models/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const mysql = require("mysql");
const dbConfig = require("../config/db.config.js");

var connection = mysql.createPool({
host: dbConfig.HOST,
user: dbConfig.USER,
password: dbConfig.PASSWORD,
database: dbConfig.DB
});

module.exports = connection;
21 changes: 21 additions & 0 deletions backend/app/models/lastupdate.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const sql = require("./db.js");

const LastUpdate = function(lastupdate) {
this.lastupdate = lastupdate.lastupdate

}


LastUpdate.getLastUpdate = result => {

var str = "SELECT lastupdate from lastupdate "

sql.query(str, (err, res) => {
if (err) throw err;
result(null, res);
});
};



module.exports = LastUpdate;
183 changes: 183 additions & 0 deletions backend/app/models/patient.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
const sql = require("./db.js");

// constructor
const Patient = function(patient) {
this.patientId = patient.patientId;
this.reportedOn = patient.reportedOn;
this.onsetEstimate = patient.onsetEstimate;
this.ageEstimate = patient.ageEstimate;
this.gender = patient.gender;
this.city = patient.city;
this.district = patient.district;
this.state = patient.state;
this.status = patient.status;
this.notes = patient.notes;
this.contractedFrom = patient.contractedFrom;
this.travel = [];
this.relationship = [];
this.nationality = [];
this.sources = [];
this.place_attributes = [];
};




Patient.getAll = result => {

var str = "SELECT P.*, PPA.place as place_attribute_place, PPA.is_foreign as place_attribute_is_foreign, " +
" PS.source " +
" FROM patient P " +
"LEFT JOIN patient_place_attribute PPA ON PPA.patient_id = P.patientId " +
"LEFT JOIN patient_source PS ON PS.patient_id = P.patientId " // +
// "LEFT JOIN patient_rel PR ON PR.patient_a = P.patientId " +
// "LEFT JOIN patient_travel PT ON PT.patient_id = P.patientId"
str += " ORDER BY state ASC";

sql.query(str, (err, rows) => {
var rawPatientData = [], index = {};
if (err) throw err;

rows.forEach(function (row) {
if ( !(row.patientId in index) ) {
index[row.patientId] = {
patientId : row.patientId,
reportedOn : row.reportedOn,
onsetEstimate : row.onsetEstimate,
ageEstimate : row.ageEstimate,
gender : row.gender,
city : row.city,
district : row.district,
state : row.state,
status : row.status,
notes : row.notes,
contractedFrom : row.contractedFrom,
travel : [],
relationship : [],
nationality : [],
sources : [],
place_attributes : []
};

if (row.place_attribute_place) {
index[row.patientId].place_attributes.push({
is_foreign: row.place_attribute_is_foreign,
place: row.place_attribute_place,
});
}

if (row.source) {
index[row.patientId].sources.push(row.source);
}


rawPatientData.push(index[row.patientId]);

} else {
if (row.place_attribute_place) {
index[row.patientId].place_attributes.push({
is_foreign: row.place_attribute_is_foreign,
place: row.place_attribute_place,
});
}

if (row.source) {
index[row.patientId].sources.push(row.source);
}

}

});



let data = {
"data" : {
"rawPatientData": rawPatientData
}
};
result(null, data);
});
};




Patient.getAllByDate = (reportDate, result) => {


var str = "SELECT P.*, PPA.place as place_attribute_place, PPA.is_foreign as place_attribute_is_foreign, " +
" PS.source " +
" FROM patient P " +
" LEFT JOIN patient_place_attribute PPA ON PPA.patient_id = P.patientId " +
" LEFT JOIN patient_source PS ON PS.patient_id = P.patientId " // +

str += " WHERE P.reportedOn <= ? ";
str += " ORDER BY state ASC";
sql.query(str, [reportDate], (err, rows) => {
var rawPatientData = [], index = {};
if (err) throw err;

rows.forEach(function (row) {
if ( !(row.patientId in index) ) {
index[row.patientId] = {
patientId : row.patientId,
reportedOn : row.reportedOn,
onsetEstimate : row.onsetEstimate,
ageEstimate : row.ageEstimate,
gender : row.gender,
city : row.city,
district : row.district,
state : row.state,
status : row.status,
notes : row.notes,
contractedFrom : row.contractedFrom,
travel : [],
relationship : [],
nationality : [],
sources : [],
place_attributes : []
};

if (row.place_attribute_place) {
index[row.patientId].place_attributes.push({
is_foreign: row.place_attribute_is_foreign,
place: row.place_attribute_place,
});
}

if (row.source) {
index[row.patientId].sources.push(row.source);
}


rawPatientData.push(index[row.patientId]);

} else {
if (row.place_attribute_place) {
index[row.patientId].place_attributes.push({
is_foreign: row.place_attribute_is_foreign,
place: row.place_attribute_place,
});
}

if (row.source) {
index[row.patientId].sources.push(row.source);
}

}

});

let data = {
"data" : {
"rawPatientData": rawPatientData
}
};


result(null, data);
});
};

module.exports = Patient;
7 changes: 7 additions & 0 deletions backend/app/routes/lastupdate.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = app => {
const lastupdate = require("../controllers/lastupdate.controller.js");


app.get("/api/last_update", lastupdate.getLastUpdate);

};
10 changes: 10 additions & 0 deletions backend/app/routes/patients.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = app => {
const patients = require("../controllers/patient.controller.js");


// Retrieve all patients
app.get("/api/patients", patients.findAll);

app.get("/api/patients/date/:reportDate", patients.findAllByDate);

};
Loading

0 comments on commit b6bb2d5

Please sign in to comment.