-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
184 lines (138 loc) · 4.96 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
var config = require('./config.js');
const morgan = require('morgan');
const mysql = require('mysql');
var router = express.Router();
var HashMap = require('hashmap');
var Map = require('sorted-map');
var ArrayList = require('arraylist');
var HashTable = require('hashtable');
var Multimap = require('multimap');
const sortMap = require('sort-map')
const request = require('request');
const argv = require('yargs').argv;
var jsdom = require("jsdom");
const { JSDOM } = jsdom;
const { window } = new JSDOM();
const { document } = (new JSDOM('')).window;
global.document = document;
// const dom = new JSDOM('index.ejs');
app.use(morgan('short'));
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: true }));
// app.use(auth)
// app.set('views', '/views')
app.set('view engine', 'ejs')
app.get('/', function(req, res) {
let url = `http://dmmw-api.australiaeast.cloudapp.azure.com:8080/illnesses`
request(url, function(error, response, body, next) {
var illness = JSON.parse(body)
var ill = illness._embedded.illnesses
//var link = _links.self
res.render('index', {ill: ill} );
});
});
function getConnection(){
var connection = mysql.createConnection(config.databaseOptions);
return connection
}
app.get('/apires', (req,res)=> {
let url = `http://dmmw-api.australiaeast.cloudapp.azure.com:8080/hospitals`;
request(url, function(error, response, body, next) {
var parseddata = JSON.parse(body)
var hospitals = parseddata._embedded.hospitals
var hosid = hospitals.id
res.json(hospitals);
});
//res.send("api data page");
})
app.post('/displayhospital', (req, res) => {
console.log("trying to get form data");
const email = req.body.email_name;
const disease = req.body.disease;
const pain = req.body.pain;
const queryString = "INSERT INTO patient (email, disease, painlevel) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE disease = VALUES(disease), painlevel = VALUES(painlevel)"
// var painmap= new HashMap();
// map.set("Mild", 0);
// map.set("Moderate", 1);
// map.set("Severe", 2);
// map.set("Very Severe", 3);
// map.set("Extreme Pain", 4);
const pains = {
"Mild": 0,
"Moderate":1,
"Severe":2,
"Very Severe":3,
"Extreme Pain":4
}
if(email==""){
res.redirect('back');
}
else{
getConnection().query(queryString, [email,disease,pain],(err,results, fields)=>
{
if(err){
console.log("failed to insert in db" + err);
res.sendStatus(500)
// res.redirect('back');
// res.render('index')
//return
}
console.log("inserted new patient ");
// res.end();
})
let url = `http://dmmw-api.australiaeast.cloudapp.azure.com:8080/hospitals`;
request(url, function(error, response, body, done) {
var parseddata = JSON.parse(body)
var hospitals = parseddata._embedded.hospitals
var hosid = hospitals.id
var name = []
var list = new ArrayList;
var w_time = []
var map = new HashMap();
var obj = {};
var hashtable = new HashTable();
var m = new Multimap();
// res.render('result', { hospitals: hospitals });
if (error) throw new Error(error);
else{
hospitals.forEach(function(h){
wlist = h.waitingList
//if(pain === h.waitingList.)
wlist.forEach(function(wl){
// console.log(pains[pain]);
hospitalpain = wl.levelOfPain;
// console.log("hospain", pains[pain], hospitalpain);
// if(pains[pain] === hospitalpain) // [arraylist]
if(pains[pain] === hospitalpain)
{
// console.log(h.name);
ptncnt = wl.patientCount;
avgtime = wl.averageProcessTime;
time = ptncnt*avgtime;
// console.log(time);
// map.set(time, h.name);
// list.add({});
list.add({name: h.name, time: time}); // [arraylist]
// console.log(list.get(6));
// hashtable.put(time,h.name); [hashtable]
// m.set(time, h.name);
}
});
});
list.sort((a, b) => a.time - b.time);
list.each(function(k){
console.log(k.name);
console.log(k.time);
});
res.render('result', { hospitals: list});
}
res.end();
});
}
});
const server = app.listen(7000, () => {
console.log(`Express running → PORT ${server.address().port}`);
});