-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (53 loc) · 1.45 KB
/
index.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
const Express = require("express");
const BodyParser = require("body-parser");
const fs = require("fs");
const MongoClient = require("mongodb").MongoClient;
const ObjectId = require("mongodb").ObjectID;
const dotenv = require("dotenv");
dotenv.config();
const CONNECTION_URL = process.env.CONNECTION_URL;
const DATABASE_NAME = "CodeTable";
// Import the library:
var cors = require("cors");
var app = Express();
app.use(cors());
app.use(BodyParser.json());
app.use(BodyParser.urlencoded({ extended: true }));
app.listen(process.env.PORT || 6363, () => {
MongoClient.connect(
CONNECTION_URL,
{ useNewUrlParser: true },
async (error, client) => {
if (error) {
throw error;
}
database = client.db(DATABASE_NAME);
console.log("Connected to `" + DATABASE_NAME + "`!");
}
);
console.log("server started");
});
app.get("/", (req, resp) => {
resp.send("Ediapi started. Visit documentation for other routes");
});
app.get("/codes/hcpcs/:value", async (request, response) => {
let collection = await database.collection("HCPCS");
collection
.find({
$or: [
{
code: { $regex: `.*${request.params.value}.*` },
},
{
longDescription: { $regex: `.*${request.params.value}.*` },
},
],
})
.limit(10)
.toArray(function (error, result) {
if (error) {
return response.status(500).send(error);
}
response.send(result);
});
});