Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const app = express();
- const PORT = process.env.PORT || 8080
- const fs = require('fs');
- var upload = require('express-fileupload');
- let mkdirp = require('mkdirp');
- let MongoClient = require('mongodb').MongoClient;
- let url = "mongodb://localhost:27017/clinicsAndDoctors";
- let bool = false
- var nodemailer = require('nodemailer');
- function isEquivalent(a, b) {
- // Create arrays of property names
- var aProps = Object.getOwnPropertyNames(a);
- var bProps = Object.getOwnPropertyNames(b);
- // If number of properties is different,
- // objects are not equivalent
- if (aProps.length != bProps.length) {
- return false;
- }
- for (var i = 0; i < aProps.length; i++) {
- var propName = aProps[i];
- // If values of same property are not equal,
- // objects are not equivalent
- if (a[propName] !== b[propName]) {
- return false;
- }
- }
- // If we made it this far, objects
- // are considered equivalent
- return true;
- }
- MongoClient.connect(url, function(err, db) {
- if (err) throw err;
- db.createCollection("clinicsAndDoctors", function(err, res) {
- if (err) throw err;
- console.log("Table created!");
- });
- db.collection("clinicsAndDoctors").find({}).toArray(function(err, result) {
- if (err) throw err;
- db = result
- console.log(result);
- })
- });
- app.use(express.static('client'))
- app.use(upload()); // configure middleware
- app.post('/upload',function(req,res){
- console.log(req.body[`doc[patientName]`]);
- if(req.files.upfile){
- var file = req.files.upfile,
- name = file.name,
- type = file.mimetype;
- var uploadpath = __dirname + '/client/media/usersMedia' + "/" + req.body[`doc[name]`].split(' ').join('_') + `/` + req.body[`doc[patientName]`].split(' ').join('_') + "/" + name;
- file.mv(uploadpath,function(err){
- if(err){
- console.log("File Upload Failed",name,err);
- // res.send("Error Occured!")
- }
- else {
- console.log("File Uploaded",name);
- MongoClient.connect(url, function(err, db) {
- if (err) throw err
- db.collection("clinicsAndDoctors").find({username: req.body[`doc[name]`]}).toArray(function(err, result) {
- if (err) throw err
- console.log(result);
- for (var i = 0; i < result[0].patients.length; i++) {
- if (result[0].patients[i].fullName == req.body[`doc[patientName]`]) {
- console.log(req.body[`doc[patientName]`]);
- result[0].patients[i].nameOfFiles.push(req.files.upfile.name)
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- username: result[0].username,
- password: result[0].password,
- patients: result[0].patients,
- background: result[0].background,
- FavMedicines: result[0].FavMedicines
- })
- res.send("<script>window.open(`singleDoc.html`, '_self')</script>")
- }
- }
- })
- })
- // res.send('Done! Uploading files')
- }
- });
- }
- else {
- res.send("No File selected !");
- res.end();
- };
- })
- app.post("/infoComments", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- if (err) throw err
- db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
- if (err) throw err
- console.log(result);
- for (var i = 0; i < result[0].patients.length; i++) {
- if (result[0].patients[i].fullName == jsObject.namePatient) {
- result[0].patients[i].infoComments = jsObject.infoComments
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- username: result[0].username,
- password: result[0].password,
- patients: result[0].patients,
- background: result[0].background,
- FavMedicines: result[0].FavMedicines
- })
- res.end(JSON.stringify({message: jsObject.infoComments}))
- }
- }
- })
- })
- })
- })
- app.post("/prescriptionsComment", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- if (err) throw err
- db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
- if (err) throw err
- console.log(result);
- for (var i = 0; i < result[0].patients.length; i++) {
- if (result[0].patients[i].fullName == jsObject.namePatient) {
- result[0].patients[i].prescriptionsComment = jsObject.comment
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- username: result[0].username,
- password: result[0].password,
- patients: result[0].patients,
- background: result[0].background,
- FavMedicines: result[0].FavMedicines
- })
- res.end(JSON.stringify({message: jsObject.comment}))
- }
- }
- })
- })
- })
- })
- app.post("/commentPayment", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- if (err) throw err
- db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
- if (err) throw err
- console.log(result);
- for (var i = 0; i < result[0].patients.length; i++) {
- if (result[0].patients[i].fullName == jsObject.namePatient) {
- result[0].patients[i].commentPayment = jsObject.comment
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- username: result[0].username,
- password: result[0].password,
- patients: result[0].patients,
- background: result[0].background,
- FavMedicines: result[0].FavMedicines
- })
- res.end(JSON.stringify({message: jsObject.comment}))
- }
- }
- })
- })
- })
- })
- app.post("/treatmentComment", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- if (err) throw err
- db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
- if (err) throw err
- console.log(result);
- for (var i = 0; i < result[0].patients.length; i++) {
- if (result[0].patients[i].fullName == jsObject.namePatient) {
- result[0].patients[i].treatmentComments = jsObject.comment
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- username: result[0].username,
- password: result[0].password,
- patients: result[0].patients,
- background: result[0].background,
- FavMedicines: result[0].FavMedicines
- })
- res.end(JSON.stringify({message: jsObject.comment}))
- }
- }
- })
- })
- })
- })
- app.post("/createDoc", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObjectInfo = JSON.parse(body)
- let html = `
- <div>
- <h1>` + jsObjectInfo.username.split(' ').join('_') + `</h1>
- <button class="confirmEmailUser_` + jsObjectInfo.username.split(' ').join('_') + `">confirm Email</button>
- <script
- src="https://code.jquery.com/jquery-3.2.1.min.js"
- integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
- crossorigin="anonymous"></script>
- <script src="confirmEmail.js"></script>
- </div>
- `
- fs.writeFile('client/confirm_' + jsObjectInfo.username.split(' ').join('_') + '.html', html, function (err) {
- if (err) throw err;
- console.log('Saved!');
- var transporter = nodemailer.createTransport({
- service: 'gmail',
- auth: {
- user: 'techsystems999@gmail.com',
- pass: 'danielg99'
- }
- });
- var mailOptions = {
- from: 'jonathan.gilyadov@gmail.com',
- to: jsObjectInfo.emailAddress,
- subject: 'Confirm Email!(https://ct-doc.tk)',
- html: `<h1>Hello</h1><p>confirm your account <a href="http://ct-doc.tk/confirm_` + jsObjectInfo.username.split(' ').join('_') + `.html">confirm</a></p>`
- };
- transporter.sendMail(mailOptions, function(error, info){
- if (error) {
- console.log(error);
- } else {
- app.post("/confirmDoctor", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- if (err) throw err
- db.collection("clinicsAndDoctors").find({username: jsObject.name}).toArray(function(err, result) {
- if (err) throw err
- console.log(result);
- fs.unlink('client/confirm_' + jsObject.name.split(' ').join('_') +'.html', function (err) {
- db.collection("clinicsAndDoctors").insertOne(jsObjectInfo, function(err, res) {
- if (err) throw err;
- console.log("record inserted");
- })
- console.log('File deleted!');
- });
- // db.collection("clinicsAndDoctors").save({
- // "_id": result[0]._id,
- // username: result[0].username,
- // password: result[0].password,
- // patients: result[0].patients,
- // background: result[0].background,
- // FavMedicines: result[0].FavMedicines,
- // confirm: true
- // })
- })
- })
- })
- })
- console.log('Email sent: ' + info.response);
- }
- });
- mkdirp('/system/client/media/usersMedia/' + jsObjectInfo.username.split(' ').join('_'), function (err) {
- if (err) console.error(err)
- else console.log('media dir created!')
- });
- });
- console.log(jsObjectInfo)
- // console.log(jsObject.password)
- // console.log(typeof(body));
- res.end("done")
- })
- })
- app.post("/createNewClinic", function(req,res) {
- let body = ""
- req.on("data", function(data) {
- body += data
- })
- req.on("end", function() {
- let jsObjectInfo = JSON.parse(body)
- // MongoClient.connect(url, function(err, db) {
- // if (err) throw err
- // db.collection("clinicsAndDoctors").insertOne(jsObjectInfo, function(err, res) {
- // if (err) throw err;
- // console.log("record inserted");
- // })
- // })
- let html = `
- <div>
- <h1>` + jsObjectInfo.nameOfNewClinic.split(' ').join('_') + `</h1>
- <button class="confirmEmailUser_` + jsObjectInfo.nameOfNewClinic.split(' ').join('_') + `">confirm Email</button>
- <script
- src="https://code.jquery.com/jquery-3.2.1.min.js"
- integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
- crossorigin="anonymous"></script>
- <script src="confirmEmail.js"></script>
- </div>
- `
- fs.writeFile('client/confirm_' + jsObjectInfo.nameOfNewClinic.split(' ').join('_') + '.html', html, function (err) {
- if (err) throw err;
- console.log('Saved!');
- var transporter = nodemailer.createTransport({
- service: 'gmail',
- auth: {
- user: 'techsystems999@gmail.com',
- pass: 'danielg99'
- }
- });
- var mailOptions = {
- from: 'jonathan.gilyadov@gmail.com',
- to: jsObjectInfo.emailAddress,
- subject: 'Confirm Email!(https://ct-doc.tk)',
- html: `<h1>Hello</h1><p>confirm your account <a href="http://ct-doc.tk/confirm_` + jsObjectInfo.nameOfNewClinic.split(' ').join('_') + `.html">confirm</a></p>`
- };
- transporter.sendMail(mailOptions, function(error, info){
- if (error) {
- console.log(error);
- } else {
- app.post("/confirmDoctor", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- if (err) throw err
- db.collection("clinicsAndDoctors").find({nameOfNewClinic: jsObject.name}).toArray(function(err, result) {
- if (err) throw err
- console.log(result);
- fs.unlink('client/confirm_' + jsObject.name.split(' ').join('_') +'.html', function (err) {
- db.collection("clinicsAndDoctors").insertOne(jsObjectInfo, function(err, res) {
- if (err) throw err;
- console.log("record inserted");
- })
- console.log('File deleted!');
- });
- // db.collection("clinicsAndDoctors").save({
- // "_id": result[0]._id,
- // username: result[0].username,
- // password: result[0].password,
- // patients: result[0].patients,
- // background: result[0].background,
- // FavMedicines: result[0].FavMedicines,
- // confirm: true
- // })
- })
- })
- })
- })
- console.log('Email sent: ' + info.response);
- }
- });
- mkdirp('/system/client/media/usersMedia/' + jsObjectInfo.nameOfNewClinic.split(' ').join('_'), function (err) {
- if (err) console.error(err)
- else console.log('media dir created!')
- });
- res.end(JSON.stringify(jsObjectInfo))
- })
- })
- })
- app.post("/loginClinic", function(req, res) {
- let bool = false
- let body = ""
- req.on("data", function(data) {
- body += data
- })
- req.on("end", function() {
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- if (err) throw err
- db.collection("clinicsAndDoctors").find({emailAddress: jsObject.emailOfClinic, password:jsObject.password}).toArray(function(err, result) {
- if (err) throw err
- console.log(result);
- if (result.length == 0) {
- console.log("No Users Found! :(")
- } else {
- bool = true
- let infoUser = {
- "email": jsObject.emailOfClinic,
- "patients": jsObject.doctors,
- "nameOfClinic": result[0].nameOfNewClinic,
- "bool": bool,
- "idUser": result[0]._id,
- "doctorsOfClinic": result[0].doctors
- }
- console.log(result[0])
- res.end(JSON.stringify(infoUser))
- }
- })
- })
- })
- })
- app.post("/loginReq", function(req, resP) {
- let username;
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- if (err) throw err;
- db.collection("clinicsAndDoctors").find({username: jsObject.username, password: jsObject.password}).toArray(function(err, result) {
- if (err) throw err;
- console.log(result);
- console.log(result.length);
- if (result.length == 0) {
- console.log("fuck!")
- } else {
- bool = true
- let objectlol = {
- "username": jsObject.username,
- "bool": bool,
- "patients": jsObject.patients,
- "idUser": result[0]._id,
- background: result[0].background
- }
- resP.send(objectlol)
- console.log("guys we did it!")
- }
- })
- })
- })
- })
- app.post("/PatientDetails", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- if (err) throw err
- db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
- console.log(result[0].FavMedicines);
- if (err) throw err;
- if (result[0].username === jsObject.nameDoc) {
- let inPatients = result[0].patients
- inPatients.push(jsObject.data)
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- username: result[0].username,
- password: result[0].password,
- patients: inPatients,
- background: result[0].background,
- FavMedicines: result[0].FavMedicines
- })
- mkdirp('/system/client/media/usersMedia/' + jsObject.nameDoc.split(' ').join('_') + "/" + jsObject.data.fullName.split(' ').join('_'), function (err) {
- if (err) console.error(err)
- else console.log('media dir created!')
- });
- res.end("done")
- }
- });
- });
- // mkdirp('/system/client/images/${jsObject.nameDoc}', function (err) {
- // if (err) console.error(err)
- // else console.log('pow!')
- // });
- })
- })
- app.post("aRowClickingClinic", function(res, req) {
- let body = ""
- req.on("data", function(data) {
- bpdy += data
- })
- req.on("end", function() {
- let jsObject = JSON.parse(body)
- let allPatientsInArray = []
- MongoClient.connect(url, function(err, db) {
- if (err) throw err
- db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
- if (err) throw err;
- console.log(result[0].FavMedicines);
- if (result[0].username === jsObject.nameDoc) {
- for (var i = 0; i < result[0].doctors.length; i++) {
- for (var d = 0; d < result[0].doctors[i].patients.length; d++) {
- allPatientsInArray.push(result[0].doctors[i].patients[d])
- }
- }
- res.end(allPatientsInArray)
- }
- });
- });
- })
- })
- app.post("/patientsTeeth", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- if (err) throw err
- db.collection("clinicsAndDoctors").find({username: jsObject.docName}).toArray(function(err, result) {
- if (err) throw err;
- for (var i = 0; i < result[0].patients.length; i++) {
- if(result[0].patients[i].firstName + " " + result[0].patients[i].SubName == jsObject.patientName){
- let inPatients = result[0].patients
- console.log(Object.keys(jsObject.teeth).length);
- for (var j = 0; j < Object.keys(jsObject.teeth).length; j++) {
- let teethNumberSent = Object.keys(jsObject.teeth)[j]
- inPatients[i].teethArage.teeth[teethNumberSent] = jsObject.teeth[teethNumberSent]
- }
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- username: result[0].username,
- password: result[0].password,
- patients: inPatients,
- FavMedicines: result[0].FavMedicines
- })
- res.end(JSON.stringify(result[0].patients[i].teethArage.teeth))
- }
- }
- });
- });
- })
- })
- app.post("/newMeeting", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
- for (let j = 0; j < result[0].patients.length; j++) {
- if(result[0].patients[j].firstName + " " + result[0].patients[j].SubName === jsObject.patientName){
- console.log("passesss");
- result[0].patients[j].meetings.push(jsObject.newMeeting)
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- username: result[0].username,
- password: result[0].password,
- patients: result[0].patients,
- FavMedicines: result[0].FavMedicines
- })
- res.end(JSON.stringify(result[0].patients[j].meetings))
- }
- }
- })
- })
- })
- })
- app.post("/newMeetingClinic", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- db.collection("clinicsAndDoctors").find({nameOfNewClinic: jsObject.nameOfClinic}).toArray(function(err, result) {
- for (let j = 0; j < result[0].patients.length; j++) {
- if(result[0].patients[j].firstName + " " + result[0].patients[j].SubName === jsObject.patientName){
- console.log("passesss");
- result[0].patients[j].meetings.push(jsObject.newMeeting)
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- nameOfNewClinic: result[0].nameOfNewClinic,
- password: result[0].password,
- address: result[0].address,
- doctors: result[0].doctors,
- patients: result[0].patients,
- emailAddress: result[0].emailAddress
- })
- res.end(JSON.stringify(result[0].patients[j].meetings))
- }
- }
- })
- })
- })
- })
- app.post("/info_meeting", function(req, res) {
- let body = ""
- let allMeetingOfAllPatients = {}
- req.on('data', function(data) {
- body += data
- })
- req.on("end", function() {
- let jsObject = JSON.parse(body)
- console.log(jsObject.docName);
- MongoClient.connect(url, function(err, db) {
- db.collection("clinicsAndDoctors").find({username: jsObject.docName}).toArray(function(err, result) {
- console.log(result);
- for (var i = 0; i < result[0].patients.length; i++) {
- allMeetingOfAllPatients[result[0].patients[i].firstName + " " + result[0].patients[i].SubName] = result[0].patients[i].meetings
- }
- let allMeetingOfAllPatientsJson = JSON.stringify(allMeetingOfAllPatients)
- res.end(allMeetingOfAllPatientsJson)
- })
- })
- })
- })
- app.post("/info_meeting_clinic", function(req, res) {
- let body = ""
- let allMeetingOfAllPatients = {}
- req.on('data', function(data) {
- body += data
- })
- req.on("end", function() {
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- db.collection("clinicsAndDoctors").find({nameOfNewClinic: jsObject.nameOfClinic}).toArray(function(err, result) {
- for (var i = 0; i < result[0].patients.length; i++) {
- allMeetingOfAllPatients[result[0].patients[i].fullName] = [result[0].patients[i].meetings, result[0].patients[i].doctor]
- }
- let allMeetingOfAllPatientsJson = JSON.stringify(allMeetingOfAllPatients)
- res.end(allMeetingOfAllPatientsJson)
- })
- })
- })
- })
- MongoClient.connect(url, function(err, db) {
- app.post("/reqPatientsDetails", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let docName = JSON.parse(body)
- db.collection("clinicsAndDoctors").find({username: docName.nameDoc}).toArray(function(err, result) {
- let patients = {patients: result[0].patients, FavMedicines: result[0].FavMedicines}
- let patientsJSON = JSON.stringify(patients)
- res.send(patientsJSON)
- app.post("/archivePatient", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- for (var i = 0; i < result[0].patients.length; i++) {
- if(result[0].patients[i].fullName == jsObject.namePatient) {
- let patient = result[0].patients[i]
- console.log(patient.archive);
- patient.archive = true;
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- username: result[0].username,
- password: result[0].password,
- patients: result[0].patients,
- FavMedicines: result[0].FavMedicines
- })
- res.send(JSON.stringify({message: "Patient Archived"}))
- break;
- }
- }
- })
- })
- })
- })
- })
- })
- MongoClient.connect(url, function(err, db) {
- app.post("/reqPatientsDetailsclinic", function(req, res) {
- let body = ""
- let allPatientsInArray = []
- let allPatientsOfAllDoctors = []
- req.on("data", function(data) {
- body += data
- })
- req.on("end", function() {
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err,db) {
- if(err) throw err
- db.collection("clinicsAndDoctors").find({nameOfNewClinic: jsObject.nameOfClinic}).toArray(function(err, result) {
- // db.collection("clinicsAndDoctors").find({doctors: jsObject.nameOfDoc}).toArray(function(err, resultdoc) {
- // if(err) throw err
- // console.log(resultdoc);
- // })
- // console.log(result[0].doctors.length);
- // // allPatientsOfAllDoctors.push(result[0].doctors[0].patients)
- // // allPatientsOfAllDoctors.push(result[0].doctors[1].patients)
- // for (var i = 0; i < result[0].doctors.length; i++) {
- // console.log(i);
- // allPatientsOfAllDoctors.push(result[0].doctors[i].patients)
- // }
- // res.end(JSON.stringify(allPatientsOfAllDoctors))
- //// for (var i = 0; i < result[0].doctors.length; i++) {
- //// for (var d = 0; d < result[0].doctors[i].patients.length; d++) {
- //// allPatientsInArray.push(result[0].doctors[i].patients[d])
- //// }
- //// }
- if (jsObject.nameOfDoc == "") {
- res.end(JSON.stringify(result[0].patients))
- } else {
- for (var i = 0; i < result[0].patients.length; i++) {
- if (jsObject.nameOfDoc in result[0].patients[i]) {
- allPatientsInArray.push(result[0].patients[i])
- }
- }
- res.send(JSON.stringify(allPatientsInArray))
- }
- app.post("/backFromArchiveClinic", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- for (var i = 0; i < result[0].patients.length; i++) {
- if (result[0].patients[i].fullName == jsObject.nameOfPatient) {
- result[0].patients[i].archive = false
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- nameOfNewClinic: result[0].nameOfNewClinic,
- password: result[0].password,
- address: result[0].address,
- doctors: result[0].doctors,
- patients: result[0].patients,
- emailAddress: result[0].emailAddress
- })
- break;
- }
- }
- })
- })
- })
- })
- })
- })
- })
- app.post("/patientsOfDoctors", function(req, res) {
- let body = ""
- let bool = false
- let allPatientsOfAllDoctors = []
- req.on("data", function(data) {
- body += data
- })
- req.on("end", function() {
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err,db) {
- if(err) throw err
- db.collection("clinicsAndDoctors").find({nameOfNewClinic: jsObject.nameOfClinic}).toArray(function(err, result) {
- // db.collection("clinicsAndDoctors").find({doctors: jsObject.nameOfDoc}).toArray(function(err, resultdoc) {
- // if(err) throw err
- // console.log(resultdoc);
- // })
- console.log(result[0].doctors.length);
- if (jsObject.nameOfDoc == "") {
- // allPatientsOfAllDoctors.push(result[0].doctors[0].patients)fcreate
- // allPatientsOfAllDoctors.push(result[0].doctors[1].patients)
- bool=true
- res.end(JSON.stringify(result[0].patients))
- }else {
- for (var i = 0; i < result[0].patients.length; i++) {
- if (jsObject.nameOfDoc in result[0].patients[i]) {
- allPatientsOfAllDoctors.push(result[0].patients[i])
- }
- }
- res.end(JSON.stringify(allPatientsOfAllDoctors))
- }
- })
- })
- })
- })
- app.post("/PatientDetailsOfClinic", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- if (err) throw err
- db.collection("clinicsAndDoctors").find({nameOfNewClinic: jsObject.nameOfClinic}).toArray(function(err, result) {
- if (err) throw err;
- result[0].patients.push(jsObject.data)
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- nameOfNewClinic: result[0].nameOfNewClinic,
- password: result[0].password,
- address: result[0].address,
- doctors: result[0].doctors,
- patients: result[0].patients,
- emailAddress: result[0].emailAddress
- })
- mkdirp('/system/client/media/usersMedia/' + jsObject.nameOfClinic.split(' ').join('_') + "/" + jsObject.data.fullName.split(' ').join('_'), function (err) {
- if (err) console.error(err)
- else console.log('media dir created!')
- });
- res.send("done")
- });
- });
- })
- })
- app.post("/meetingToday", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let JSobject = JSON.parse(body)
- let array = []
- MongoClient.connect(url, function(err, db) {
- db.collection("clinicsAndDoctors").find({username: JSobject.username}).toArray(function(err, result) {
- for (let i = 0; i < result[0].patients.length; i++) {
- for (let j = 0; j < result[0].patients[i].meetings.length; j++) {
- if(result[0].patients[i].meetings[j][0].slice(0,10) === JSobject.date) {
- let nameOfPatient = result[0].patients[i].firstName + " " + result[0].patients[i].SubName
- let duration = result[0].patients[i].meetings[j][1]
- let time = result[0].patients[i].meetings[j][0].slice(10,19)
- let patientAndTime = {}
- patientAndTime[nameOfPatient] = [time, duration]
- array.push(patientAndTime)
- }
- }
- }
- })
- })
- })
- })
- app.post("/medicineClinic", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on("end", function() {
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- db.collection("clinicsAndDoctors").find({nameOfNewClinic: jsObject.nameClinic}).toArray(function(err, result) {
- for (var i = 0; i < result[0].patients.length; i++) {
- if(result[0].patients[i].fullName == jsObject.patientName) {
- let patient = result[0].patients[i]
- patient.medicines.push(jsObject.medicine)
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- nameOfNewClinic: result[0].nameOfNewClinic,
- password: result[0].password,
- address: result[0].address,
- doctors: result[0].doctors,
- patients: result[0].patients,
- emailAddress: result[0].emailAddress
- })
- res.send(patient.medicines)
- break;
- }
- }
- })
- })
- })
- })
- app.post("/medicine", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on("end", function() {
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
- for (var i = 0; i < result[0].patients.length; i++) {
- if(result[0].patients[i].fullName == jsObject.patientName) {
- let patient = result[0].patients[i]
- patient.medicines.push(jsObject.medicine)
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- username: result[0].username,
- password: result[0].password,
- patients: result[0].patients,
- FavMedicines: result[0].FavMedicines
- })
- res.send(patient.medicines)
- break;
- }
- }
- })
- })
- })
- })
- app.post("/medicineFav", function(req, res) {
- let body = ""
- req.on("data", function(data) {
- body += data
- })
- req.on("end", function() {
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
- console.log(result);
- let FavMedicinesArray = result[0].FavMedicines
- FavMedicinesArray.push(jsObject.medicine)
- let medicines = FavMedicinesArray
- console.log(medicines);
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- username: result[0].username,
- password: result[0].password,
- patients: result[0].patients,
- FavMedicines: result[0].FavMedicines
- })
- res.send(result[0].FavMedicines)
- })
- })
- })
- })
- app.post("/addDoctor", function(req, res) {
- let body = ""
- req.on("data", function(data) {
- body += data
- })
- req.on("end", function() {
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- db.collection("clinicsAndDoctors").find({nameOfNewClinic:jsObject.nameOfClinic}).toArray(function(err, result) {
- let doctor = {
- docName: jsObject.nameOfNewDoc,
- patients: [],
- FavMedicine: [],
- meetings: [],
- "id_of_new_worker": jsObject.id_of_new_worker
- }
- result[0].doctors.push(doctor)
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- nameOfNewClinic: result[0].nameOfNewClinic,
- doctors: result[0].doctors,
- address: result[0].address,
- password: result[0].password,
- patients: result[0].patients
- })
- res.end(JSON.stringify(result[0].doctors))
- })
- })
- })
- })
- app.post("/getAllDoctors", function(req,res) {
- let body = ""
- req.on("data", function(data) {
- body += data
- })
- req.on("end", function() {
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- db.collection("clinicsAndDoctors").find({nameOfNewClinic:jsObject.nameOfClinic}).toArray(function(err, result) {
- res.end(JSON.stringify(result[0].doctors))
- })
- })
- })
- })
- app.post("/getPatientClickedClinic", function(req,res) {
- let body = ""
- req.on("data", function(data) {
- body += data
- })
- req.on("end", function() {
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- db.collection("clinicsAndDoctors").find({nameOfNewClinic:jsObject.nameOfClinic}).toArray(function(err, result) {
- for (var i = 0; i < result[0].patients.length; i++) {
- if (result[0].patients[i].firstName + " " + result[0].patients[i].SubName == jsObject.nameOfPatient) {
- let patient = result[0].patients[i]
- let clinic = result[0]
- console.log(patient.meetings);
- app.post("/getfavMedicinesClinic", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- for (var i = 0; i < clinic.doctors.length; i++) {
- console.log(clinic.doctors[i].docName, jsObject.nameOfDoc);
- if (clinic.doctors[i].docName === jsObject.nameOfDoc) {
- res.send(JSON.stringify({doctor: clinic.doctors[i].favMedicine}))
- break;
- }
- }
- })
- })
- // app.post("/meetingDeleteClinic", function(req, res) {
- // let body = "";
- // req.on("data", function(data) {
- // body += data
- // })
- // req.on(`end`, function(){
- // let jsObject = JSON.parse(body)
- // console.log(patient.meetings);
- // for (var z = 0; z < patient.meetings.length; z++) {
- // if(isEquivalent(jsObject, patient.meetings[z])){
- // console.log(z);
- // console.log(true);
- // patient.meetings.splice(z, 1)
- // db.collection("clinicsAndDoctors").save({
- // "_id": result[0]._id,
- // nameOfNewClinic: result[0].nameOfNewClinic,
- // doctors: result[0].doctors,
- // address: result[0].address,
- // password: result[0].password,
- // patients: result[0].patients,
- // emailAddress: result[0].emailAddress
- // })
- // break;
- // }
- // }
- // res.send(JSON.stringify({message: "meeting deleted"}))
- // })
- // })
- app.get("/archiveClinic", function(req, res) {
- console.log("archive wating");
- console.log(patient.archive);
- patient.archive = true;
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- nameOfNewClinic: result[0].nameOfNewClinic,
- doctors: result[0].doctors,
- address: result[0].address,
- password: result[0].password,
- patients: result[0].patients
- })
- res.send(JSON.stringify({message: "Patient Archived"}))
- })
- app.post("/infoCommentsClinic", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- console.log(result);
- patient.infoComments = jsObject.infoComments
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- nameOfNewClinic: result[0].nameOfNewClinic,
- doctors: result[0].doctors,
- address: result[0].address,
- password: result[0].password,
- patients: result[0].patients,
- emailAddress: result[0].emailAddress
- })
- res.send(JSON.stringify({message: jsObject.infoComments}))
- })
- })
- app.post("/medicineFavClinic", function(req, res) {
- let body = ""
- req.on("data", function(data) {
- body += data
- })
- req.on("end", function() {
- let jsObject = JSON.parse(body)
- console.log(jsObject);
- for (var i = 0; i < clinic.doctors.length; i++) {
- console.log(clinic.doctors[i].docName, jsObject.nameOfDoc);
- if (clinic.doctors[i].docName = jsObject.nameOfDoc) {
- clinic.doctors[i].FavMedicine.push(jsObject.medicine)
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- nameOfNewClinic: result[0].nameOfNewClinic,
- password: result[0].password,
- address: result[0].address,
- doctors: result[0].doctors,
- patients: result[0].patients,
- emailAddress: result[0].emailAddress
- })
- res.send(result[0].doctors[i].FavMedicine)
- break;
- }
- }
- })
- })
- app.post("/treatmentCommentClinic", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- patient.treatmentComments = jsObject.comment
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- nameOfNewClinic: result[0].nameOfNewClinic,
- doctors: result[0].doctors,
- address: result[0].address,
- password: result[0].password,
- patients: result[0].patients,
- emailAddress: result[0].emailAddress
- })
- res.send(JSON.stringify({message: jsObject.comment}))
- })
- })
- app.post("/prescriptionsCommentClinic", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- patient.prescriptionsComment = jsObject.comment
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- nameOfNewClinic: result[0].nameOfNewClinic,
- doctors: result[0].doctors,
- address: result[0].address,
- password: result[0].password,
- patients: result[0].patients,
- emailAddress: result[0].emailAddress
- })
- res.send(JSON.stringify({message: jsObject.comment}))
- })
- })
- app.post('/uploadClinic',function(req,res){
- if(req.files.upfile){
- var file = req.files.upfile,
- name = file.name,
- type = file.mimetype;
- var uploadpath = __dirname + '/client/media/usersMedia' + "/" + clinic.nameOfNewClinic.split(' ').join('_') + `/` + patient.fullName.split(' ').join('_') + "/" + name;
- file.mv(uploadpath,function(err){
- if(err){
- console.log("File Upload Failed",name,err);
- // res.send("Error Occured!")
- }
- else {
- patient.nameOfFiles.push(req.files.upfile.name)
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- nameOfNewClinic: result[0].nameOfNewClinic,
- doctors: result[0].doctors,
- address: result[0].address,
- password: result[0].password,
- patients: result[0].patients
- })
- res.send("<script>window.open(`singleDoc.html`, '_self')</script>")
- // res.send('Done! Uploading files')
- }
- });
- }
- else {
- res.send("No File selected !");
- res.end();
- };
- })
- app.post("/commentPaymentClinic", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- patient.paymentComment = jsObject.comment
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- nameOfNewClinic: result[0].nameOfNewClinic,
- doctors: result[0].doctors,
- address: result[0].address,
- password: result[0].password,
- patients: result[0].patients
- })
- res.send(JSON.stringify({message: jsObject.comment}))
- })
- })
- res.send(JSON.stringify(patient))
- break
- }
- }
- })
- })
- })
- })
- app.post("/patientsTeethClinic", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- if (err) throw err
- db.collection("clinicsAndDoctors").find({nameOfNewClinic:jsObject.nameOfClinic}).toArray(function(err, result) {
- if (err) throw err;
- for (var i = 0; i < result[0].patients.length; i++) {
- if(result[0].patients[i].firstName + " " + result[0].patients[i].SubName == jsObject.patientName){
- let inPatients = result[0].patients
- // console.log(Object.keys(jsObject.teeth).length);
- for (var j = 0; j < Object.keys(jsObject.teeth).length; j++) {
- let teethNumberSent = Object.keys(jsObject.teeth)[j]
- // console.log(Object.keys(jsObject.teeth)[j]);
- inPatients[i].teethArage.teeth[teethNumberSent] = jsObject.teeth[teethNumberSent]
- console.log(inPatients[i].teethArage.teeth[teethNumberSent]);
- }
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- nameOfNewClinic: result[0].nameOfNewClinic,
- doctors: result[0].doctors,
- address: result[0].address,
- password: result[0].password,
- patients: result[0].patients,
- emailAddress: result[0].emailAddress
- })
- res.send(JSON.stringify(result[0].patients[i].teethArage.teeth))
- break
- }
- }
- });
- });
- })
- })
- app.post("/patientDeleted", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- console.log(jsObject);
- MongoClient.connect(url, function(err, db) {
- db.collection("clinicsAndDoctors").find({username: jsObject.nameOfDoctor}).toArray(function(err, result) {
- console.log(result);
- for (var i = 0; i < result[0].patients.length; i++) {
- if(result[0].patients[i].fullName == jsObject.nameOfPatient) {
- let patient = result[0].patients[i]
- result[0].patients.splice(i, 1)
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- username: result[0].username,
- password: result[0].password,
- patients: result[0].patients,
- FavMedicines: result[0].FavMedicines
- })
- res.end("Patient Deleted")
- break;
- }
- }
- })
- })
- })
- })
- app.post("/patientDeletedClinic", function(req, res) {
- let body = "";
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- console.log(jsObject);
- MongoClient.connect(url, function(err, db) {
- db.collection("clinicsAndDoctors").find({nameOfNewClinic: jsObject.nameOfClinic}).toArray(function(err, result) {
- console.log(result);
- for (var i = 0; i < result[0].patients.length; i++) {
- if(result[0].patients[i].fullName == jsObject.nameOfPatient) {
- let patient = result[0].patients[i]
- result[0].patients.splice(i, 1)
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- nameOfNewClinic: result[0].nameOfNewClinic,
- doctors: result[0].doctors,
- address: result[0].address,
- password: result[0].password,
- patients: result[0].patients,
- emailAddress: result[0].emailAddress
- })
- res.end("Patient Deleted")
- break;
- }
- }
- })
- })
- })
- })
- app.post("/backFromArchive", function(req, res) {
- let body = "";
- console.log("hello");
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- MongoClient.connect(url, function(err, db) {
- console.log(jsObject);
- db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
- console.log(result);
- //check if this possible
- for (var i = 0; i < result[0].patients.length; i++) {
- console.log(jsObject.nameOfPatient);
- console.log(result[0].patients[i].fullName == jsObject.nameOfPatient);
- if (result[0].patients[i].fullName == jsObject.nameOfPatient) {
- result[0].patients[i].archive = false
- db.collection("clinicsAndDoctors").save({
- "_id": result[0]._id,
- username: result[0].username,
- password: result[0].password,
- patients: result[0].patients,
- FavMedicines: result[0].FavMedicines
- })
- break;
- }
- }
- })
- })
- })
- })
- //chat
- app.post("/message", function(req, res) {
- let body = "";
- console.log("hello");
- req.on("data", function(data) {
- body += data
- })
- req.on(`end`, function(){
- let jsObject = JSON.parse(body)
- console.log(jsObject);
- let dataSentBack = {
- success: true
- }
- res.end(JSON.stringify(dataSentBack))
- })
- })
- app.listen(PORT, function() {
- console.log("server running on port " + PORT);
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement