-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
114 lines (98 loc) · 5.38 KB
/
app.js
File metadata and controls
114 lines (98 loc) · 5.38 KB
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
const express = require("express");
const bodyParser = require("body-parser");
const path = require('path');
const env = require("dotenv");
const ejs = require("ejs");
const request = require("request");
const http = require("http");
const app = express();
// get environment variables from .env file (use process.env to access)
env.config();
const port = process.env.PORT || 8080;
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
// no longer need to specify .ejs file extension
app.set("view engine", "ejs");
app.set('views', path.join(__dirname, 'views'));
app.get('/main', function(req, res) {
const select = "nct_number,title,acronym,status,conditionsabbrev,interventionabbrev,phases,location,distance,time,url,inclusioncrit,exclusioncrit,age,contactname,contactphone,contactaddress,contactemail,enrollment,longitude,latitude";
const gender = req.query.gender || 'in.(Male,All)';
const age = req.query.age || 'phfts.{Adult}';
const conditions = req.query.conditions || 'neq.null';
const phases = req.query.phases || 'neq.null';
console.log(select, gender);
const url = 'https://query.dropbase.io/guFdPgANE2WEhqhVw4kCeP/cc?select=' + select + '&gender=' + gender + '&age=' + age + '&conditionsabbrev=' + conditions + '&phases=' + phases + '&order=distance.nullsfirst' + '&limit=300';
console.log("URL: " + url);
request({
url: url,
headers: {
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhYmFzZUlkIjoiZ3VGZFBnQU5FMldFaHFoVnc0a0NlUCIsImFjY2Vzc1Blcm0iOiJmdWxsIiwidG9rZW5JZCI6IkhGWElmWGIwRmhDNUpETVhsbVNUeDNMb0lxN3RlZGM3VUN2Z3A0NVd1clZRbUpmdFhGWm5YN1JsNDNFZTVWNDEiLCJpYXQiOjE2MTA4NTIyODIsImV4cCI6MTYxMTAyNTA4MiwiaXNzIjoiZHJvcGJhc2UuaW8iLCJzdWIiOiJCQkJkRmZ4b3hpeEtBM1d2RFhaYTVlIn0.osNKNhoSDyYieDCRFZwg7vExKY6vfvHNuvO-62UejWY'
},
rejectUnauthorized: false
}, function (err, response, body) {
if (err) {
console.log(err);
} else {
console.log("Response " + response.statusCode);
console.log(JSON.parse(body));
const clinics = JSON.parse(body);
res.render("main.ejs", {studies: clinics});
}
});
});
app.get('/', function(req, res){
res.render("login.ejs");
});
app.get('/signup', function(req,res){
res.render("signup.ejs")
});
app.post('/checklogin', function(req, res){
res.redirect('/main');
});
app.get('/search', function(req, res){
const select = "nct_number,title,acronym,status,conditionsabbrev,interventionabbrev,phases,location,distance,time,url,inclusioncrit,exclusioncrit,age,contactname,contactphone,contactaddress,contactemail,enrollment,longitude,latitude";
const search = encodeURIComponent(req.query.query);
const age = req.query.age || 'phfts.{Adult}';
const conditions = req.query.conditions || 'neq.null';
const phases = req.query.phases || 'neq.null';
const searchURL = `https://query.dropbase.io/guFdPgANE2WEhqhVw4kCeP/cc?select=${select}&age=${age}&conditionsabbrev=${conditions}&phases=${phases}&or=(title.phfts.${search},sponsors.phfts.${search},location.phfts.${search})&order=distance.nullsfirst&limit=300`
request({
url: searchURL,
headers: {
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhYmFzZUlkIjoiZ3VGZFBnQU5FMldFaHFoVnc0a0NlUCIsImFjY2Vzc1Blcm0iOiJmdWxsIiwidG9rZW5JZCI6IkhGWElmWGIwRmhDNUpETVhsbVNUeDNMb0lxN3RlZGM3VUN2Z3A0NVd1clZRbUpmdFhGWm5YN1JsNDNFZTVWNDEiLCJpYXQiOjE2MTA4NTIyODIsImV4cCI6MTYxMTAyNTA4MiwiaXNzIjoiZHJvcGJhc2UuaW8iLCJzdWIiOiJCQkJkRmZ4b3hpeEtBM1d2RFhaYTVlIn0.osNKNhoSDyYieDCRFZwg7vExKY6vfvHNuvO-62UejWY'
},
rejectUnauthorized: false
}, function (err, response, body) {
if (err) {
console.log(err);
} else {
res.send(JSON.parse(body))
}
});
});
app.get('/filterSearch', function(req, res){
const select = "nct_number,title,acronym,status,conditionsabbrev,interventionabbrev,phases,location,distance,time,url,inclusioncrit,exclusioncrit,age,contactname,contactphone,contactaddress,contactemail,enrollment,longitude,latitude";
const search = encodeURIComponent(req.query.query);
const age = req.query.age || 'phfts.{Adult}';
const conditions = req.query.conditions || 'neq.null';
const phases = req.query.phases || 'neq.null';
const iab = req.query.iab || 'neq.null'
const searchURL = `https://query.dropbase.io/guFdPgANE2WEhqhVw4kCeP/cc?select=${select}&age=${age}&conditionsabbrev=${conditions}&phases=${phases}&interventionabbrev=${iab}&order=distance.nullsfirst&limit=300`
console.log(searchURL)
request({
url: searchURL,
headers: {
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhYmFzZUlkIjoiZ3VGZFBnQU5FMldFaHFoVnc0a0NlUCIsImFjY2Vzc1Blcm0iOiJmdWxsIiwidG9rZW5JZCI6IkhGWElmWGIwRmhDNUpETVhsbVNUeDNMb0lxN3RlZGM3VUN2Z3A0NVd1clZRbUpmdFhGWm5YN1JsNDNFZTVWNDEiLCJpYXQiOjE2MTA4NTIyODIsImV4cCI6MTYxMTAyNTA4MiwiaXNzIjoiZHJvcGJhc2UuaW8iLCJzdWIiOiJCQkJkRmZ4b3hpeEtBM1d2RFhaYTVlIn0.osNKNhoSDyYieDCRFZwg7vExKY6vfvHNuvO-62UejWY'
},
rejectUnauthorized: false
}, function (err, response, body) {
if (err) {
console.log(err);
} else {
res.send(JSON.parse(body))
}
});
});
//app.listen(port, () => console.log(`Server listening on port ${port}`));
app.listen(port);