Advertisement
Guest User

Untitled

a guest
Jul 11th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 53.15 KB | None | 0 0
  1. const express = require('express');
  2. const app = express();
  3. const PORT = process.env.PORT || 8080
  4. const fs = require('fs');
  5. var upload = require('express-fileupload');
  6. let mkdirp = require('mkdirp');
  7. let MongoClient = require('mongodb').MongoClient;
  8. let url = "mongodb://localhost:27017/clinicsAndDoctors";
  9. let bool = false
  10. var nodemailer = require('nodemailer');
  11.  
  12. function isEquivalent(a, b) {
  13. // Create arrays of property names
  14. var aProps = Object.getOwnPropertyNames(a);
  15. var bProps = Object.getOwnPropertyNames(b);
  16.  
  17. // If number of properties is different,
  18. // objects are not equivalent
  19. if (aProps.length != bProps.length) {
  20. return false;
  21. }
  22.  
  23. for (var i = 0; i < aProps.length; i++) {
  24. var propName = aProps[i];
  25.  
  26. // If values of same property are not equal,
  27. // objects are not equivalent
  28. if (a[propName] !== b[propName]) {
  29. return false;
  30. }
  31. }
  32.  
  33. // If we made it this far, objects
  34. // are considered equivalent
  35. return true;
  36. }
  37.  
  38. MongoClient.connect(url, function(err, db) {
  39. if (err) throw err;
  40. db.createCollection("clinicsAndDoctors", function(err, res) {
  41. if (err) throw err;
  42. console.log("Table created!");
  43. });
  44. db.collection("clinicsAndDoctors").find({}).toArray(function(err, result) {
  45. if (err) throw err;
  46. db = result
  47. console.log(result);
  48. })
  49. });
  50.  
  51. app.use(express.static('client'))
  52. app.use(upload()); // configure middleware
  53.  
  54. app.post('/upload',function(req,res){
  55.  
  56. console.log(req.body[`doc[patientName]`]);
  57. if(req.files.upfile){
  58. var file = req.files.upfile,
  59. name = file.name,
  60. type = file.mimetype;
  61. var uploadpath = __dirname + '/client/media/usersMedia' + "/" + req.body[`doc[name]`].split(' ').join('_') + `/` + req.body[`doc[patientName]`].split(' ').join('_') + "/" + name;
  62. file.mv(uploadpath,function(err){
  63. if(err){
  64. console.log("File Upload Failed",name,err);
  65. // res.send("Error Occured!")
  66. }
  67. else {
  68. console.log("File Uploaded",name);
  69. MongoClient.connect(url, function(err, db) {
  70. if (err) throw err
  71. db.collection("clinicsAndDoctors").find({username: req.body[`doc[name]`]}).toArray(function(err, result) {
  72. if (err) throw err
  73. console.log(result);
  74. for (var i = 0; i < result[0].patients.length; i++) {
  75. if (result[0].patients[i].fullName == req.body[`doc[patientName]`]) {
  76. console.log(req.body[`doc[patientName]`]);
  77. result[0].patients[i].nameOfFiles.push(req.files.upfile.name)
  78. db.collection("clinicsAndDoctors").save({
  79. "_id": result[0]._id,
  80. username: result[0].username,
  81. password: result[0].password,
  82. patients: result[0].patients,
  83. background: result[0].background,
  84. FavMedicines: result[0].FavMedicines
  85. })
  86. res.send("<script>window.open(`singleDoc.html`, '_self')</script>")
  87. }
  88. }
  89. })
  90. })
  91. // res.send('Done! Uploading files')
  92. }
  93. });
  94. }
  95. else {
  96. res.send("No File selected !");
  97. res.end();
  98. };
  99. })
  100.  
  101. app.post("/infoComments", function(req, res) {
  102. let body = "";
  103. req.on("data", function(data) {
  104. body += data
  105. })
  106. req.on(`end`, function(){
  107. let jsObject = JSON.parse(body)
  108. MongoClient.connect(url, function(err, db) {
  109. if (err) throw err
  110. db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
  111. if (err) throw err
  112. console.log(result);
  113. for (var i = 0; i < result[0].patients.length; i++) {
  114. if (result[0].patients[i].fullName == jsObject.namePatient) {
  115. result[0].patients[i].infoComments = jsObject.infoComments
  116. db.collection("clinicsAndDoctors").save({
  117. "_id": result[0]._id,
  118. username: result[0].username,
  119. password: result[0].password,
  120. patients: result[0].patients,
  121. background: result[0].background,
  122. FavMedicines: result[0].FavMedicines
  123. })
  124. res.end(JSON.stringify({message: jsObject.infoComments}))
  125. }
  126. }
  127. })
  128. })
  129. })
  130. })
  131.  
  132. app.post("/prescriptionsComment", function(req, res) {
  133. let body = "";
  134. req.on("data", function(data) {
  135. body += data
  136. })
  137. req.on(`end`, function(){
  138. let jsObject = JSON.parse(body)
  139. MongoClient.connect(url, function(err, db) {
  140. if (err) throw err
  141. db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
  142. if (err) throw err
  143. console.log(result);
  144. for (var i = 0; i < result[0].patients.length; i++) {
  145. if (result[0].patients[i].fullName == jsObject.namePatient) {
  146. result[0].patients[i].prescriptionsComment = jsObject.comment
  147. db.collection("clinicsAndDoctors").save({
  148. "_id": result[0]._id,
  149. username: result[0].username,
  150. password: result[0].password,
  151. patients: result[0].patients,
  152. background: result[0].background,
  153. FavMedicines: result[0].FavMedicines
  154. })
  155. res.end(JSON.stringify({message: jsObject.comment}))
  156. }
  157. }
  158. })
  159. })
  160. })
  161. })
  162.  
  163. app.post("/commentPayment", function(req, res) {
  164. let body = "";
  165. req.on("data", function(data) {
  166. body += data
  167. })
  168. req.on(`end`, function(){
  169. let jsObject = JSON.parse(body)
  170. MongoClient.connect(url, function(err, db) {
  171. if (err) throw err
  172. db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
  173. if (err) throw err
  174. console.log(result);
  175. for (var i = 0; i < result[0].patients.length; i++) {
  176. if (result[0].patients[i].fullName == jsObject.namePatient) {
  177. result[0].patients[i].commentPayment = jsObject.comment
  178. db.collection("clinicsAndDoctors").save({
  179. "_id": result[0]._id,
  180. username: result[0].username,
  181. password: result[0].password,
  182. patients: result[0].patients,
  183. background: result[0].background,
  184. FavMedicines: result[0].FavMedicines
  185. })
  186. res.end(JSON.stringify({message: jsObject.comment}))
  187. }
  188. }
  189. })
  190. })
  191. })
  192. })
  193.  
  194. app.post("/treatmentComment", function(req, res) {
  195. let body = "";
  196. req.on("data", function(data) {
  197. body += data
  198. })
  199. req.on(`end`, function(){
  200. let jsObject = JSON.parse(body)
  201. MongoClient.connect(url, function(err, db) {
  202. if (err) throw err
  203. db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
  204. if (err) throw err
  205. console.log(result);
  206. for (var i = 0; i < result[0].patients.length; i++) {
  207. if (result[0].patients[i].fullName == jsObject.namePatient) {
  208. result[0].patients[i].treatmentComments = jsObject.comment
  209. db.collection("clinicsAndDoctors").save({
  210. "_id": result[0]._id,
  211. username: result[0].username,
  212. password: result[0].password,
  213. patients: result[0].patients,
  214. background: result[0].background,
  215. FavMedicines: result[0].FavMedicines
  216. })
  217. res.end(JSON.stringify({message: jsObject.comment}))
  218. }
  219. }
  220. })
  221. })
  222. })
  223. })
  224.  
  225.  
  226.  
  227. app.post("/createDoc", function(req, res) {
  228. let body = "";
  229. req.on("data", function(data) {
  230. body += data
  231. })
  232. req.on(`end`, function(){
  233. let jsObjectInfo = JSON.parse(body)
  234. let html = `
  235. <div>
  236. <h1>` + jsObjectInfo.username.split(' ').join('_') + `</h1>
  237. <button class="confirmEmailUser_` + jsObjectInfo.username.split(' ').join('_') + `">confirm Email</button>
  238. <script
  239. src="https://code.jquery.com/jquery-3.2.1.min.js"
  240. integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
  241. crossorigin="anonymous"></script>
  242. <script src="confirmEmail.js"></script>
  243. </div>
  244. `
  245. fs.writeFile('client/confirm_' + jsObjectInfo.username.split(' ').join('_') + '.html', html, function (err) {
  246. if (err) throw err;
  247. console.log('Saved!');
  248. var transporter = nodemailer.createTransport({
  249. service: 'gmail',
  250. auth: {
  251. user: 'techsystems999@gmail.com',
  252. pass: 'danielg99'
  253. }
  254. });
  255.  
  256. var mailOptions = {
  257. from: 'jonathan.gilyadov@gmail.com',
  258. to: jsObjectInfo.emailAddress,
  259. subject: 'Confirm Email!(https://ct-doc.tk)',
  260. html: `<h1>Hello</h1><p>confirm your account <a href="http://ct-doc.tk/confirm_` + jsObjectInfo.username.split(' ').join('_') + `.html">confirm</a></p>`
  261. };
  262.  
  263. transporter.sendMail(mailOptions, function(error, info){
  264. if (error) {
  265. console.log(error);
  266. } else {
  267. app.post("/confirmDoctor", function(req, res) {
  268. let body = "";
  269. req.on("data", function(data) {
  270. body += data
  271. })
  272. req.on(`end`, function(){
  273. let jsObject = JSON.parse(body)
  274. MongoClient.connect(url, function(err, db) {
  275. if (err) throw err
  276. db.collection("clinicsAndDoctors").find({username: jsObject.name}).toArray(function(err, result) {
  277. if (err) throw err
  278. console.log(result);
  279. fs.unlink('client/confirm_' + jsObject.name.split(' ').join('_') +'.html', function (err) {
  280. db.collection("clinicsAndDoctors").insertOne(jsObjectInfo, function(err, res) {
  281. if (err) throw err;
  282. console.log("record inserted");
  283. })
  284. console.log('File deleted!');
  285. });
  286.  
  287. // db.collection("clinicsAndDoctors").save({
  288. // "_id": result[0]._id,
  289. // username: result[0].username,
  290. // password: result[0].password,
  291. // patients: result[0].patients,
  292. // background: result[0].background,
  293. // FavMedicines: result[0].FavMedicines,
  294. // confirm: true
  295. // })
  296. })
  297. })
  298. })
  299. })
  300. console.log('Email sent: ' + info.response);
  301. }
  302. });
  303. mkdirp('/system/client/media/usersMedia/' + jsObjectInfo.username.split(' ').join('_'), function (err) {
  304. if (err) console.error(err)
  305. else console.log('media dir created!')
  306. });
  307. });
  308. console.log(jsObjectInfo)
  309. // console.log(jsObject.password)
  310. // console.log(typeof(body));
  311. res.end("done")
  312. })
  313. })
  314.  
  315. app.post("/createNewClinic", function(req,res) {
  316. let body = ""
  317. req.on("data", function(data) {
  318. body += data
  319. })
  320. req.on("end", function() {
  321. let jsObjectInfo = JSON.parse(body)
  322. // MongoClient.connect(url, function(err, db) {
  323. // if (err) throw err
  324. // db.collection("clinicsAndDoctors").insertOne(jsObjectInfo, function(err, res) {
  325. // if (err) throw err;
  326. // console.log("record inserted");
  327. // })
  328. // })
  329. let html = `
  330. <div>
  331. <h1>` + jsObjectInfo.nameOfNewClinic.split(' ').join('_') + `</h1>
  332. <button class="confirmEmailUser_` + jsObjectInfo.nameOfNewClinic.split(' ').join('_') + `">confirm Email</button>
  333. <script
  334. src="https://code.jquery.com/jquery-3.2.1.min.js"
  335. integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
  336. crossorigin="anonymous"></script>
  337. <script src="confirmEmail.js"></script>
  338. </div>
  339. `
  340. fs.writeFile('client/confirm_' + jsObjectInfo.nameOfNewClinic.split(' ').join('_') + '.html', html, function (err) {
  341. if (err) throw err;
  342. console.log('Saved!');
  343. var transporter = nodemailer.createTransport({
  344. service: 'gmail',
  345. auth: {
  346. user: 'techsystems999@gmail.com',
  347. pass: 'danielg99'
  348. }
  349. });
  350.  
  351. var mailOptions = {
  352. from: 'jonathan.gilyadov@gmail.com',
  353. to: jsObjectInfo.emailAddress,
  354. subject: 'Confirm Email!(https://ct-doc.tk)',
  355. html: `<h1>Hello</h1><p>confirm your account <a href="http://ct-doc.tk/confirm_` + jsObjectInfo.nameOfNewClinic.split(' ').join('_') + `.html">confirm</a></p>`
  356. };
  357.  
  358. transporter.sendMail(mailOptions, function(error, info){
  359. if (error) {
  360. console.log(error);
  361. } else {
  362. app.post("/confirmDoctor", function(req, res) {
  363. let body = "";
  364. req.on("data", function(data) {
  365. body += data
  366. })
  367. req.on(`end`, function(){
  368. let jsObject = JSON.parse(body)
  369. MongoClient.connect(url, function(err, db) {
  370. if (err) throw err
  371. db.collection("clinicsAndDoctors").find({nameOfNewClinic: jsObject.name}).toArray(function(err, result) {
  372. if (err) throw err
  373. console.log(result);
  374. fs.unlink('client/confirm_' + jsObject.name.split(' ').join('_') +'.html', function (err) {
  375. db.collection("clinicsAndDoctors").insertOne(jsObjectInfo, function(err, res) {
  376. if (err) throw err;
  377. console.log("record inserted");
  378. })
  379. console.log('File deleted!');
  380. });
  381.  
  382. // db.collection("clinicsAndDoctors").save({
  383. // "_id": result[0]._id,
  384. // username: result[0].username,
  385. // password: result[0].password,
  386. // patients: result[0].patients,
  387. // background: result[0].background,
  388. // FavMedicines: result[0].FavMedicines,
  389. // confirm: true
  390. // })
  391. })
  392. })
  393. })
  394. })
  395. console.log('Email sent: ' + info.response);
  396. }
  397. });
  398. mkdirp('/system/client/media/usersMedia/' + jsObjectInfo.nameOfNewClinic.split(' ').join('_'), function (err) {
  399. if (err) console.error(err)
  400. else console.log('media dir created!')
  401. });
  402. res.end(JSON.stringify(jsObjectInfo))
  403. })
  404. })
  405. })
  406.  
  407. app.post("/loginClinic", function(req, res) {
  408. let bool = false
  409. let body = ""
  410. req.on("data", function(data) {
  411. body += data
  412. })
  413. req.on("end", function() {
  414. let jsObject = JSON.parse(body)
  415. MongoClient.connect(url, function(err, db) {
  416. if (err) throw err
  417. db.collection("clinicsAndDoctors").find({emailAddress: jsObject.emailOfClinic, password:jsObject.password}).toArray(function(err, result) {
  418. if (err) throw err
  419. console.log(result);
  420. if (result.length == 0) {
  421. console.log("No Users Found! :(")
  422. } else {
  423. bool = true
  424. let infoUser = {
  425. "email": jsObject.emailOfClinic,
  426. "patients": jsObject.doctors,
  427. "nameOfClinic": result[0].nameOfNewClinic,
  428. "bool": bool,
  429. "idUser": result[0]._id,
  430. "doctorsOfClinic": result[0].doctors
  431. }
  432. console.log(result[0])
  433. res.end(JSON.stringify(infoUser))
  434. }
  435. })
  436. })
  437. })
  438. })
  439.  
  440.  
  441.  
  442.  
  443. app.post("/loginReq", function(req, resP) {
  444. let username;
  445. let body = "";
  446. req.on("data", function(data) {
  447. body += data
  448. })
  449. req.on(`end`, function(){
  450. let jsObject = JSON.parse(body)
  451. MongoClient.connect(url, function(err, db) {
  452. if (err) throw err;
  453. db.collection("clinicsAndDoctors").find({username: jsObject.username, password: jsObject.password}).toArray(function(err, result) {
  454. if (err) throw err;
  455. console.log(result);
  456. console.log(result.length);
  457. if (result.length == 0) {
  458. console.log("fuck!")
  459. } else {
  460. bool = true
  461. let objectlol = {
  462. "username": jsObject.username,
  463. "bool": bool,
  464. "patients": jsObject.patients,
  465. "idUser": result[0]._id,
  466. background: result[0].background
  467. }
  468. resP.send(objectlol)
  469. console.log("guys we did it!")
  470. }
  471. })
  472. })
  473. })
  474. })
  475.  
  476.  
  477.  
  478. app.post("/PatientDetails", function(req, res) {
  479. let body = "";
  480. req.on("data", function(data) {
  481. body += data
  482. })
  483. req.on(`end`, function(){
  484. let jsObject = JSON.parse(body)
  485. MongoClient.connect(url, function(err, db) {
  486. if (err) throw err
  487. db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
  488. console.log(result[0].FavMedicines);
  489. if (err) throw err;
  490. if (result[0].username === jsObject.nameDoc) {
  491. let inPatients = result[0].patients
  492. inPatients.push(jsObject.data)
  493. db.collection("clinicsAndDoctors").save({
  494. "_id": result[0]._id,
  495. username: result[0].username,
  496. password: result[0].password,
  497. patients: inPatients,
  498. background: result[0].background,
  499. FavMedicines: result[0].FavMedicines
  500. })
  501. mkdirp('/system/client/media/usersMedia/' + jsObject.nameDoc.split(' ').join('_') + "/" + jsObject.data.fullName.split(' ').join('_'), function (err) {
  502. if (err) console.error(err)
  503. else console.log('media dir created!')
  504. });
  505. res.end("done")
  506. }
  507. });
  508. });
  509. // mkdirp('/system/client/images/${jsObject.nameDoc}', function (err) {
  510. // if (err) console.error(err)
  511. // else console.log('pow!')
  512. // });
  513. })
  514. })
  515.  
  516. app.post("aRowClickingClinic", function(res, req) {
  517. let body = ""
  518. req.on("data", function(data) {
  519. bpdy += data
  520. })
  521. req.on("end", function() {
  522. let jsObject = JSON.parse(body)
  523. let allPatientsInArray = []
  524. MongoClient.connect(url, function(err, db) {
  525. if (err) throw err
  526. db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
  527. if (err) throw err;
  528. console.log(result[0].FavMedicines);
  529. if (result[0].username === jsObject.nameDoc) {
  530. for (var i = 0; i < result[0].doctors.length; i++) {
  531. for (var d = 0; d < result[0].doctors[i].patients.length; d++) {
  532. allPatientsInArray.push(result[0].doctors[i].patients[d])
  533. }
  534. }
  535. res.end(allPatientsInArray)
  536. }
  537. });
  538. });
  539. })
  540. })
  541.  
  542. app.post("/patientsTeeth", function(req, res) {
  543. let body = "";
  544. req.on("data", function(data) {
  545. body += data
  546. })
  547. req.on(`end`, function(){
  548. let jsObject = JSON.parse(body)
  549. MongoClient.connect(url, function(err, db) {
  550. if (err) throw err
  551. db.collection("clinicsAndDoctors").find({username: jsObject.docName}).toArray(function(err, result) {
  552. if (err) throw err;
  553. for (var i = 0; i < result[0].patients.length; i++) {
  554. if(result[0].patients[i].firstName + " " + result[0].patients[i].SubName == jsObject.patientName){
  555. let inPatients = result[0].patients
  556. console.log(Object.keys(jsObject.teeth).length);
  557. for (var j = 0; j < Object.keys(jsObject.teeth).length; j++) {
  558. let teethNumberSent = Object.keys(jsObject.teeth)[j]
  559. inPatients[i].teethArage.teeth[teethNumberSent] = jsObject.teeth[teethNumberSent]
  560. }
  561. db.collection("clinicsAndDoctors").save({
  562. "_id": result[0]._id,
  563. username: result[0].username,
  564. password: result[0].password,
  565. patients: inPatients,
  566. FavMedicines: result[0].FavMedicines
  567. })
  568. res.end(JSON.stringify(result[0].patients[i].teethArage.teeth))
  569. }
  570. }
  571. });
  572. });
  573. })
  574. })
  575.  
  576. app.post("/newMeeting", function(req, res) {
  577. let body = "";
  578. req.on("data", function(data) {
  579. body += data
  580. })
  581. req.on(`end`, function(){
  582. let jsObject = JSON.parse(body)
  583. MongoClient.connect(url, function(err, db) {
  584. db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
  585. for (let j = 0; j < result[0].patients.length; j++) {
  586. if(result[0].patients[j].firstName + " " + result[0].patients[j].SubName === jsObject.patientName){
  587. console.log("passesss");
  588. result[0].patients[j].meetings.push(jsObject.newMeeting)
  589. db.collection("clinicsAndDoctors").save({
  590. "_id": result[0]._id,
  591. username: result[0].username,
  592. password: result[0].password,
  593. patients: result[0].patients,
  594. FavMedicines: result[0].FavMedicines
  595. })
  596. res.end(JSON.stringify(result[0].patients[j].meetings))
  597. }
  598. }
  599. })
  600. })
  601. })
  602. })
  603.  
  604. app.post("/newMeetingClinic", function(req, res) {
  605. let body = "";
  606. req.on("data", function(data) {
  607. body += data
  608. })
  609. req.on(`end`, function(){
  610. let jsObject = JSON.parse(body)
  611. MongoClient.connect(url, function(err, db) {
  612. db.collection("clinicsAndDoctors").find({nameOfNewClinic: jsObject.nameOfClinic}).toArray(function(err, result) {
  613. for (let j = 0; j < result[0].patients.length; j++) {
  614. if(result[0].patients[j].firstName + " " + result[0].patients[j].SubName === jsObject.patientName){
  615. console.log("passesss");
  616. result[0].patients[j].meetings.push(jsObject.newMeeting)
  617. db.collection("clinicsAndDoctors").save({
  618. "_id": result[0]._id,
  619. nameOfNewClinic: result[0].nameOfNewClinic,
  620. password: result[0].password,
  621. address: result[0].address,
  622. doctors: result[0].doctors,
  623. patients: result[0].patients,
  624. emailAddress: result[0].emailAddress
  625. })
  626. res.end(JSON.stringify(result[0].patients[j].meetings))
  627. }
  628. }
  629. })
  630. })
  631. })
  632. })
  633.  
  634. app.post("/info_meeting", function(req, res) {
  635. let body = ""
  636. let allMeetingOfAllPatients = {}
  637. req.on('data', function(data) {
  638. body += data
  639. })
  640. req.on("end", function() {
  641. let jsObject = JSON.parse(body)
  642. console.log(jsObject.docName);
  643. MongoClient.connect(url, function(err, db) {
  644. db.collection("clinicsAndDoctors").find({username: jsObject.docName}).toArray(function(err, result) {
  645. console.log(result);
  646. for (var i = 0; i < result[0].patients.length; i++) {
  647. allMeetingOfAllPatients[result[0].patients[i].firstName + " " + result[0].patients[i].SubName] = result[0].patients[i].meetings
  648. }
  649. let allMeetingOfAllPatientsJson = JSON.stringify(allMeetingOfAllPatients)
  650. res.end(allMeetingOfAllPatientsJson)
  651. })
  652. })
  653. })
  654. })
  655. app.post("/info_meeting_clinic", function(req, res) {
  656. let body = ""
  657. let allMeetingOfAllPatients = {}
  658. req.on('data', function(data) {
  659. body += data
  660. })
  661. req.on("end", function() {
  662. let jsObject = JSON.parse(body)
  663. MongoClient.connect(url, function(err, db) {
  664. db.collection("clinicsAndDoctors").find({nameOfNewClinic: jsObject.nameOfClinic}).toArray(function(err, result) {
  665. for (var i = 0; i < result[0].patients.length; i++) {
  666. allMeetingOfAllPatients[result[0].patients[i].fullName] = [result[0].patients[i].meetings, result[0].patients[i].doctor]
  667. }
  668. let allMeetingOfAllPatientsJson = JSON.stringify(allMeetingOfAllPatients)
  669. res.end(allMeetingOfAllPatientsJson)
  670. })
  671. })
  672. })
  673. })
  674.  
  675. MongoClient.connect(url, function(err, db) {
  676. app.post("/reqPatientsDetails", function(req, res) {
  677. let body = "";
  678. req.on("data", function(data) {
  679. body += data
  680. })
  681. req.on(`end`, function(){
  682. let docName = JSON.parse(body)
  683. db.collection("clinicsAndDoctors").find({username: docName.nameDoc}).toArray(function(err, result) {
  684. let patients = {patients: result[0].patients, FavMedicines: result[0].FavMedicines}
  685. let patientsJSON = JSON.stringify(patients)
  686. res.send(patientsJSON)
  687. app.post("/archivePatient", function(req, res) {
  688. let body = "";
  689. req.on("data", function(data) {
  690. body += data
  691. })
  692. req.on(`end`, function(){
  693. let jsObject = JSON.parse(body)
  694. for (var i = 0; i < result[0].patients.length; i++) {
  695. if(result[0].patients[i].fullName == jsObject.namePatient) {
  696. let patient = result[0].patients[i]
  697. console.log(patient.archive);
  698. patient.archive = true;
  699. db.collection("clinicsAndDoctors").save({
  700. "_id": result[0]._id,
  701. username: result[0].username,
  702. password: result[0].password,
  703. patients: result[0].patients,
  704. FavMedicines: result[0].FavMedicines
  705. })
  706. res.send(JSON.stringify({message: "Patient Archived"}))
  707. break;
  708. }
  709. }
  710. })
  711. })
  712. })
  713. })
  714. })
  715. })
  716.  
  717. MongoClient.connect(url, function(err, db) {
  718. app.post("/reqPatientsDetailsclinic", function(req, res) {
  719. let body = ""
  720. let allPatientsInArray = []
  721. let allPatientsOfAllDoctors = []
  722. req.on("data", function(data) {
  723. body += data
  724. })
  725. req.on("end", function() {
  726. let jsObject = JSON.parse(body)
  727. MongoClient.connect(url, function(err,db) {
  728. if(err) throw err
  729. db.collection("clinicsAndDoctors").find({nameOfNewClinic: jsObject.nameOfClinic}).toArray(function(err, result) {
  730. // db.collection("clinicsAndDoctors").find({doctors: jsObject.nameOfDoc}).toArray(function(err, resultdoc) {
  731. // if(err) throw err
  732. // console.log(resultdoc);
  733. // })
  734. // console.log(result[0].doctors.length);
  735. // // allPatientsOfAllDoctors.push(result[0].doctors[0].patients)
  736. // // allPatientsOfAllDoctors.push(result[0].doctors[1].patients)
  737. // for (var i = 0; i < result[0].doctors.length; i++) {
  738. // console.log(i);
  739. // allPatientsOfAllDoctors.push(result[0].doctors[i].patients)
  740. // }
  741. // res.end(JSON.stringify(allPatientsOfAllDoctors))
  742. //// for (var i = 0; i < result[0].doctors.length; i++) {
  743. //// for (var d = 0; d < result[0].doctors[i].patients.length; d++) {
  744. //// allPatientsInArray.push(result[0].doctors[i].patients[d])
  745. //// }
  746. //// }
  747. if (jsObject.nameOfDoc == "") {
  748. res.end(JSON.stringify(result[0].patients))
  749. } else {
  750. for (var i = 0; i < result[0].patients.length; i++) {
  751. if (jsObject.nameOfDoc in result[0].patients[i]) {
  752. allPatientsInArray.push(result[0].patients[i])
  753. }
  754. }
  755. res.send(JSON.stringify(allPatientsInArray))
  756. }
  757. app.post("/backFromArchiveClinic", function(req, res) {
  758. let body = "";
  759. req.on("data", function(data) {
  760. body += data
  761. })
  762. req.on(`end`, function(){
  763. let jsObject = JSON.parse(body)
  764. for (var i = 0; i < result[0].patients.length; i++) {
  765. if (result[0].patients[i].fullName == jsObject.nameOfPatient) {
  766. result[0].patients[i].archive = false
  767. db.collection("clinicsAndDoctors").save({
  768. "_id": result[0]._id,
  769. nameOfNewClinic: result[0].nameOfNewClinic,
  770. password: result[0].password,
  771. address: result[0].address,
  772. doctors: result[0].doctors,
  773. patients: result[0].patients,
  774. emailAddress: result[0].emailAddress
  775. })
  776. break;
  777. }
  778. }
  779. })
  780. })
  781. })
  782. })
  783. })
  784. })
  785. })
  786.  
  787. app.post("/patientsOfDoctors", function(req, res) {
  788. let body = ""
  789. let bool = false
  790. let allPatientsOfAllDoctors = []
  791. req.on("data", function(data) {
  792. body += data
  793. })
  794. req.on("end", function() {
  795. let jsObject = JSON.parse(body)
  796. MongoClient.connect(url, function(err,db) {
  797. if(err) throw err
  798. db.collection("clinicsAndDoctors").find({nameOfNewClinic: jsObject.nameOfClinic}).toArray(function(err, result) {
  799. // db.collection("clinicsAndDoctors").find({doctors: jsObject.nameOfDoc}).toArray(function(err, resultdoc) {
  800. // if(err) throw err
  801. // console.log(resultdoc);
  802. // })
  803. console.log(result[0].doctors.length);
  804. if (jsObject.nameOfDoc == "") {
  805. // allPatientsOfAllDoctors.push(result[0].doctors[0].patients)fcreate
  806. // allPatientsOfAllDoctors.push(result[0].doctors[1].patients)
  807. bool=true
  808. res.end(JSON.stringify(result[0].patients))
  809. }else {
  810. for (var i = 0; i < result[0].patients.length; i++) {
  811. if (jsObject.nameOfDoc in result[0].patients[i]) {
  812. allPatientsOfAllDoctors.push(result[0].patients[i])
  813. }
  814. }
  815. res.end(JSON.stringify(allPatientsOfAllDoctors))
  816. }
  817. })
  818. })
  819. })
  820. })
  821.  
  822. app.post("/PatientDetailsOfClinic", function(req, res) {
  823. let body = "";
  824. req.on("data", function(data) {
  825. body += data
  826. })
  827. req.on(`end`, function(){
  828. let jsObject = JSON.parse(body)
  829. MongoClient.connect(url, function(err, db) {
  830. if (err) throw err
  831. db.collection("clinicsAndDoctors").find({nameOfNewClinic: jsObject.nameOfClinic}).toArray(function(err, result) {
  832. if (err) throw err;
  833. result[0].patients.push(jsObject.data)
  834. db.collection("clinicsAndDoctors").save({
  835. "_id": result[0]._id,
  836. nameOfNewClinic: result[0].nameOfNewClinic,
  837. password: result[0].password,
  838. address: result[0].address,
  839. doctors: result[0].doctors,
  840. patients: result[0].patients,
  841. emailAddress: result[0].emailAddress
  842. })
  843. mkdirp('/system/client/media/usersMedia/' + jsObject.nameOfClinic.split(' ').join('_') + "/" + jsObject.data.fullName.split(' ').join('_'), function (err) {
  844. if (err) console.error(err)
  845. else console.log('media dir created!')
  846. });
  847. res.send("done")
  848. });
  849. });
  850. })
  851. })
  852.  
  853. app.post("/meetingToday", function(req, res) {
  854. let body = "";
  855. req.on("data", function(data) {
  856. body += data
  857. })
  858. req.on(`end`, function(){
  859. let JSobject = JSON.parse(body)
  860. let array = []
  861. MongoClient.connect(url, function(err, db) {
  862. db.collection("clinicsAndDoctors").find({username: JSobject.username}).toArray(function(err, result) {
  863. for (let i = 0; i < result[0].patients.length; i++) {
  864. for (let j = 0; j < result[0].patients[i].meetings.length; j++) {
  865. if(result[0].patients[i].meetings[j][0].slice(0,10) === JSobject.date) {
  866. let nameOfPatient = result[0].patients[i].firstName + " " + result[0].patients[i].SubName
  867. let duration = result[0].patients[i].meetings[j][1]
  868. let time = result[0].patients[i].meetings[j][0].slice(10,19)
  869. let patientAndTime = {}
  870. patientAndTime[nameOfPatient] = [time, duration]
  871. array.push(patientAndTime)
  872. }
  873. }
  874. }
  875. })
  876. })
  877. })
  878. })
  879.  
  880. app.post("/medicineClinic", function(req, res) {
  881. let body = "";
  882. req.on("data", function(data) {
  883. body += data
  884. })
  885. req.on("end", function() {
  886. let jsObject = JSON.parse(body)
  887. MongoClient.connect(url, function(err, db) {
  888. db.collection("clinicsAndDoctors").find({nameOfNewClinic: jsObject.nameClinic}).toArray(function(err, result) {
  889. for (var i = 0; i < result[0].patients.length; i++) {
  890. if(result[0].patients[i].fullName == jsObject.patientName) {
  891. let patient = result[0].patients[i]
  892. patient.medicines.push(jsObject.medicine)
  893. db.collection("clinicsAndDoctors").save({
  894. "_id": result[0]._id,
  895. nameOfNewClinic: result[0].nameOfNewClinic,
  896. password: result[0].password,
  897. address: result[0].address,
  898. doctors: result[0].doctors,
  899. patients: result[0].patients,
  900. emailAddress: result[0].emailAddress
  901. })
  902. res.send(patient.medicines)
  903. break;
  904. }
  905. }
  906. })
  907. })
  908. })
  909. })
  910.  
  911. app.post("/medicine", function(req, res) {
  912. let body = "";
  913. req.on("data", function(data) {
  914. body += data
  915. })
  916. req.on("end", function() {
  917. let jsObject = JSON.parse(body)
  918. MongoClient.connect(url, function(err, db) {
  919. db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
  920. for (var i = 0; i < result[0].patients.length; i++) {
  921. if(result[0].patients[i].fullName == jsObject.patientName) {
  922. let patient = result[0].patients[i]
  923. patient.medicines.push(jsObject.medicine)
  924. db.collection("clinicsAndDoctors").save({
  925. "_id": result[0]._id,
  926. username: result[0].username,
  927. password: result[0].password,
  928. patients: result[0].patients,
  929. FavMedicines: result[0].FavMedicines
  930. })
  931. res.send(patient.medicines)
  932. break;
  933. }
  934. }
  935. })
  936. })
  937. })
  938. })
  939.  
  940. app.post("/medicineFav", function(req, res) {
  941. let body = ""
  942. req.on("data", function(data) {
  943. body += data
  944. })
  945. req.on("end", function() {
  946. let jsObject = JSON.parse(body)
  947. MongoClient.connect(url, function(err, db) {
  948. db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
  949. console.log(result);
  950. let FavMedicinesArray = result[0].FavMedicines
  951. FavMedicinesArray.push(jsObject.medicine)
  952. let medicines = FavMedicinesArray
  953. console.log(medicines);
  954. db.collection("clinicsAndDoctors").save({
  955. "_id": result[0]._id,
  956. username: result[0].username,
  957. password: result[0].password,
  958. patients: result[0].patients,
  959. FavMedicines: result[0].FavMedicines
  960. })
  961. res.send(result[0].FavMedicines)
  962. })
  963. })
  964. })
  965. })
  966.  
  967.  
  968. app.post("/addDoctor", function(req, res) {
  969. let body = ""
  970. req.on("data", function(data) {
  971. body += data
  972. })
  973. req.on("end", function() {
  974. let jsObject = JSON.parse(body)
  975. MongoClient.connect(url, function(err, db) {
  976. db.collection("clinicsAndDoctors").find({nameOfNewClinic:jsObject.nameOfClinic}).toArray(function(err, result) {
  977. let doctor = {
  978. docName: jsObject.nameOfNewDoc,
  979. patients: [],
  980. FavMedicine: [],
  981. meetings: [],
  982. "id_of_new_worker": jsObject.id_of_new_worker
  983. }
  984. result[0].doctors.push(doctor)
  985. db.collection("clinicsAndDoctors").save({
  986. "_id": result[0]._id,
  987. nameOfNewClinic: result[0].nameOfNewClinic,
  988. doctors: result[0].doctors,
  989. address: result[0].address,
  990. password: result[0].password,
  991. patients: result[0].patients
  992. })
  993. res.end(JSON.stringify(result[0].doctors))
  994. })
  995. })
  996. })
  997. })
  998.  
  999. app.post("/getAllDoctors", function(req,res) {
  1000. let body = ""
  1001. req.on("data", function(data) {
  1002. body += data
  1003. })
  1004. req.on("end", function() {
  1005. let jsObject = JSON.parse(body)
  1006. MongoClient.connect(url, function(err, db) {
  1007. db.collection("clinicsAndDoctors").find({nameOfNewClinic:jsObject.nameOfClinic}).toArray(function(err, result) {
  1008. res.end(JSON.stringify(result[0].doctors))
  1009. })
  1010. })
  1011. })
  1012. })
  1013.  
  1014. app.post("/getPatientClickedClinic", function(req,res) {
  1015. let body = ""
  1016. req.on("data", function(data) {
  1017. body += data
  1018. })
  1019. req.on("end", function() {
  1020. let jsObject = JSON.parse(body)
  1021. MongoClient.connect(url, function(err, db) {
  1022. db.collection("clinicsAndDoctors").find({nameOfNewClinic:jsObject.nameOfClinic}).toArray(function(err, result) {
  1023. for (var i = 0; i < result[0].patients.length; i++) {
  1024. if (result[0].patients[i].firstName + " " + result[0].patients[i].SubName == jsObject.nameOfPatient) {
  1025. let patient = result[0].patients[i]
  1026. let clinic = result[0]
  1027. console.log(patient.meetings);
  1028. app.post("/getfavMedicinesClinic", function(req, res) {
  1029. let body = "";
  1030. req.on("data", function(data) {
  1031. body += data
  1032. })
  1033. req.on(`end`, function(){
  1034. let jsObject = JSON.parse(body)
  1035. for (var i = 0; i < clinic.doctors.length; i++) {
  1036. console.log(clinic.doctors[i].docName, jsObject.nameOfDoc);
  1037. if (clinic.doctors[i].docName === jsObject.nameOfDoc) {
  1038.  
  1039. res.send(JSON.stringify({doctor: clinic.doctors[i].favMedicine}))
  1040. break;
  1041. }
  1042. }
  1043. })
  1044. })
  1045. // app.post("/meetingDeleteClinic", function(req, res) {
  1046. // let body = "";
  1047. // req.on("data", function(data) {
  1048. // body += data
  1049. // })
  1050. // req.on(`end`, function(){
  1051. // let jsObject = JSON.parse(body)
  1052. // console.log(patient.meetings);
  1053. // for (var z = 0; z < patient.meetings.length; z++) {
  1054. // if(isEquivalent(jsObject, patient.meetings[z])){
  1055. // console.log(z);
  1056. // console.log(true);
  1057. // patient.meetings.splice(z, 1)
  1058. // db.collection("clinicsAndDoctors").save({
  1059. // "_id": result[0]._id,
  1060. // nameOfNewClinic: result[0].nameOfNewClinic,
  1061. // doctors: result[0].doctors,
  1062. // address: result[0].address,
  1063. // password: result[0].password,
  1064. // patients: result[0].patients,
  1065. // emailAddress: result[0].emailAddress
  1066. // })
  1067. // break;
  1068. // }
  1069. // }
  1070. // res.send(JSON.stringify({message: "meeting deleted"}))
  1071. // })
  1072. // })
  1073. app.get("/archiveClinic", function(req, res) {
  1074. console.log("archive wating");
  1075. console.log(patient.archive);
  1076. patient.archive = true;
  1077. db.collection("clinicsAndDoctors").save({
  1078. "_id": result[0]._id,
  1079. nameOfNewClinic: result[0].nameOfNewClinic,
  1080. doctors: result[0].doctors,
  1081. address: result[0].address,
  1082. password: result[0].password,
  1083. patients: result[0].patients
  1084. })
  1085. res.send(JSON.stringify({message: "Patient Archived"}))
  1086. })
  1087. app.post("/infoCommentsClinic", function(req, res) {
  1088. let body = "";
  1089. req.on("data", function(data) {
  1090. body += data
  1091. })
  1092. req.on(`end`, function(){
  1093. let jsObject = JSON.parse(body)
  1094. console.log(result);
  1095. patient.infoComments = jsObject.infoComments
  1096. db.collection("clinicsAndDoctors").save({
  1097. "_id": result[0]._id,
  1098. nameOfNewClinic: result[0].nameOfNewClinic,
  1099. doctors: result[0].doctors,
  1100. address: result[0].address,
  1101. password: result[0].password,
  1102. patients: result[0].patients,
  1103. emailAddress: result[0].emailAddress
  1104. })
  1105. res.send(JSON.stringify({message: jsObject.infoComments}))
  1106. })
  1107. })
  1108.  
  1109. app.post("/medicineFavClinic", function(req, res) {
  1110. let body = ""
  1111. req.on("data", function(data) {
  1112. body += data
  1113. })
  1114. req.on("end", function() {
  1115. let jsObject = JSON.parse(body)
  1116. console.log(jsObject);
  1117. for (var i = 0; i < clinic.doctors.length; i++) {
  1118. console.log(clinic.doctors[i].docName, jsObject.nameOfDoc);
  1119. if (clinic.doctors[i].docName = jsObject.nameOfDoc) {
  1120. clinic.doctors[i].FavMedicine.push(jsObject.medicine)
  1121. db.collection("clinicsAndDoctors").save({
  1122. "_id": result[0]._id,
  1123. nameOfNewClinic: result[0].nameOfNewClinic,
  1124. password: result[0].password,
  1125. address: result[0].address,
  1126. doctors: result[0].doctors,
  1127. patients: result[0].patients,
  1128. emailAddress: result[0].emailAddress
  1129. })
  1130. res.send(result[0].doctors[i].FavMedicine)
  1131. break;
  1132. }
  1133. }
  1134. })
  1135. })
  1136. app.post("/treatmentCommentClinic", function(req, res) {
  1137. let body = "";
  1138. req.on("data", function(data) {
  1139. body += data
  1140. })
  1141. req.on(`end`, function(){
  1142. let jsObject = JSON.parse(body)
  1143. patient.treatmentComments = jsObject.comment
  1144. db.collection("clinicsAndDoctors").save({
  1145. "_id": result[0]._id,
  1146. nameOfNewClinic: result[0].nameOfNewClinic,
  1147. doctors: result[0].doctors,
  1148. address: result[0].address,
  1149. password: result[0].password,
  1150. patients: result[0].patients,
  1151. emailAddress: result[0].emailAddress
  1152. })
  1153. res.send(JSON.stringify({message: jsObject.comment}))
  1154. })
  1155. })
  1156. app.post("/prescriptionsCommentClinic", function(req, res) {
  1157. let body = "";
  1158. req.on("data", function(data) {
  1159. body += data
  1160. })
  1161. req.on(`end`, function(){
  1162. let jsObject = JSON.parse(body)
  1163. patient.prescriptionsComment = jsObject.comment
  1164. db.collection("clinicsAndDoctors").save({
  1165. "_id": result[0]._id,
  1166. nameOfNewClinic: result[0].nameOfNewClinic,
  1167. doctors: result[0].doctors,
  1168. address: result[0].address,
  1169. password: result[0].password,
  1170. patients: result[0].patients,
  1171. emailAddress: result[0].emailAddress
  1172. })
  1173. res.send(JSON.stringify({message: jsObject.comment}))
  1174. })
  1175. })
  1176. app.post('/uploadClinic',function(req,res){
  1177. if(req.files.upfile){
  1178. var file = req.files.upfile,
  1179. name = file.name,
  1180. type = file.mimetype;
  1181. var uploadpath = __dirname + '/client/media/usersMedia' + "/" + clinic.nameOfNewClinic.split(' ').join('_') + `/` + patient.fullName.split(' ').join('_') + "/" + name;
  1182. file.mv(uploadpath,function(err){
  1183. if(err){
  1184. console.log("File Upload Failed",name,err);
  1185. // res.send("Error Occured!")
  1186. }
  1187. else {
  1188. patient.nameOfFiles.push(req.files.upfile.name)
  1189. db.collection("clinicsAndDoctors").save({
  1190. "_id": result[0]._id,
  1191. nameOfNewClinic: result[0].nameOfNewClinic,
  1192. doctors: result[0].doctors,
  1193. address: result[0].address,
  1194. password: result[0].password,
  1195. patients: result[0].patients
  1196. })
  1197. res.send("<script>window.open(`singleDoc.html`, '_self')</script>")
  1198. // res.send('Done! Uploading files')
  1199. }
  1200. });
  1201. }
  1202. else {
  1203. res.send("No File selected !");
  1204. res.end();
  1205. };
  1206. })
  1207. app.post("/commentPaymentClinic", function(req, res) {
  1208. let body = "";
  1209. req.on("data", function(data) {
  1210. body += data
  1211. })
  1212. req.on(`end`, function(){
  1213. let jsObject = JSON.parse(body)
  1214. patient.paymentComment = jsObject.comment
  1215. db.collection("clinicsAndDoctors").save({
  1216. "_id": result[0]._id,
  1217. nameOfNewClinic: result[0].nameOfNewClinic,
  1218. doctors: result[0].doctors,
  1219. address: result[0].address,
  1220. password: result[0].password,
  1221. patients: result[0].patients
  1222. })
  1223. res.send(JSON.stringify({message: jsObject.comment}))
  1224. })
  1225. })
  1226. res.send(JSON.stringify(patient))
  1227. break
  1228. }
  1229. }
  1230. })
  1231. })
  1232. })
  1233. })
  1234.  
  1235. app.post("/patientsTeethClinic", function(req, res) {
  1236. let body = "";
  1237. req.on("data", function(data) {
  1238. body += data
  1239. })
  1240. req.on(`end`, function(){
  1241. let jsObject = JSON.parse(body)
  1242. MongoClient.connect(url, function(err, db) {
  1243. if (err) throw err
  1244. db.collection("clinicsAndDoctors").find({nameOfNewClinic:jsObject.nameOfClinic}).toArray(function(err, result) {
  1245. if (err) throw err;
  1246. for (var i = 0; i < result[0].patients.length; i++) {
  1247. if(result[0].patients[i].firstName + " " + result[0].patients[i].SubName == jsObject.patientName){
  1248. let inPatients = result[0].patients
  1249. // console.log(Object.keys(jsObject.teeth).length);
  1250. for (var j = 0; j < Object.keys(jsObject.teeth).length; j++) {
  1251. let teethNumberSent = Object.keys(jsObject.teeth)[j]
  1252. // console.log(Object.keys(jsObject.teeth)[j]);
  1253. inPatients[i].teethArage.teeth[teethNumberSent] = jsObject.teeth[teethNumberSent]
  1254. console.log(inPatients[i].teethArage.teeth[teethNumberSent]);
  1255. }
  1256. db.collection("clinicsAndDoctors").save({
  1257. "_id": result[0]._id,
  1258. nameOfNewClinic: result[0].nameOfNewClinic,
  1259. doctors: result[0].doctors,
  1260. address: result[0].address,
  1261. password: result[0].password,
  1262. patients: result[0].patients,
  1263. emailAddress: result[0].emailAddress
  1264. })
  1265. res.send(JSON.stringify(result[0].patients[i].teethArage.teeth))
  1266.  
  1267. break
  1268. }
  1269. }
  1270. });
  1271. });
  1272. })
  1273. })
  1274.  
  1275. app.post("/patientDeleted", function(req, res) {
  1276. let body = "";
  1277. req.on("data", function(data) {
  1278. body += data
  1279. })
  1280. req.on(`end`, function(){
  1281. let jsObject = JSON.parse(body)
  1282. console.log(jsObject);
  1283. MongoClient.connect(url, function(err, db) {
  1284. db.collection("clinicsAndDoctors").find({username: jsObject.nameOfDoctor}).toArray(function(err, result) {
  1285. console.log(result);
  1286. for (var i = 0; i < result[0].patients.length; i++) {
  1287. if(result[0].patients[i].fullName == jsObject.nameOfPatient) {
  1288. let patient = result[0].patients[i]
  1289. result[0].patients.splice(i, 1)
  1290. db.collection("clinicsAndDoctors").save({
  1291. "_id": result[0]._id,
  1292. username: result[0].username,
  1293. password: result[0].password,
  1294. patients: result[0].patients,
  1295. FavMedicines: result[0].FavMedicines
  1296. })
  1297. res.end("Patient Deleted")
  1298. break;
  1299. }
  1300. }
  1301. })
  1302. })
  1303. })
  1304. })
  1305.  
  1306. app.post("/patientDeletedClinic", function(req, res) {
  1307. let body = "";
  1308. req.on("data", function(data) {
  1309. body += data
  1310. })
  1311. req.on(`end`, function(){
  1312. let jsObject = JSON.parse(body)
  1313. console.log(jsObject);
  1314. MongoClient.connect(url, function(err, db) {
  1315. db.collection("clinicsAndDoctors").find({nameOfNewClinic: jsObject.nameOfClinic}).toArray(function(err, result) {
  1316. console.log(result);
  1317. for (var i = 0; i < result[0].patients.length; i++) {
  1318. if(result[0].patients[i].fullName == jsObject.nameOfPatient) {
  1319. let patient = result[0].patients[i]
  1320. result[0].patients.splice(i, 1)
  1321. db.collection("clinicsAndDoctors").save({
  1322. "_id": result[0]._id,
  1323. nameOfNewClinic: result[0].nameOfNewClinic,
  1324. doctors: result[0].doctors,
  1325. address: result[0].address,
  1326. password: result[0].password,
  1327. patients: result[0].patients,
  1328. emailAddress: result[0].emailAddress
  1329. })
  1330. res.end("Patient Deleted")
  1331. break;
  1332. }
  1333. }
  1334. })
  1335. })
  1336. })
  1337. })
  1338.  
  1339.  
  1340.  
  1341. app.post("/backFromArchive", function(req, res) {
  1342. let body = "";
  1343. console.log("hello");
  1344. req.on("data", function(data) {
  1345. body += data
  1346. })
  1347. req.on(`end`, function(){
  1348. let jsObject = JSON.parse(body)
  1349. MongoClient.connect(url, function(err, db) {
  1350. console.log(jsObject);
  1351. db.collection("clinicsAndDoctors").find({username: jsObject.nameDoc}).toArray(function(err, result) {
  1352. console.log(result);
  1353. //check if this possible
  1354. for (var i = 0; i < result[0].patients.length; i++) {
  1355. console.log(jsObject.nameOfPatient);
  1356. console.log(result[0].patients[i].fullName == jsObject.nameOfPatient);
  1357. if (result[0].patients[i].fullName == jsObject.nameOfPatient) {
  1358. result[0].patients[i].archive = false
  1359. db.collection("clinicsAndDoctors").save({
  1360. "_id": result[0]._id,
  1361. username: result[0].username,
  1362. password: result[0].password,
  1363. patients: result[0].patients,
  1364. FavMedicines: result[0].FavMedicines
  1365. })
  1366. break;
  1367. }
  1368. }
  1369. })
  1370. })
  1371. })
  1372. })
  1373. //chat
  1374. app.post("/message", function(req, res) {
  1375. let body = "";
  1376. console.log("hello");
  1377. req.on("data", function(data) {
  1378. body += data
  1379. })
  1380. req.on(`end`, function(){
  1381. let jsObject = JSON.parse(body)
  1382. console.log(jsObject);
  1383. let dataSentBack = {
  1384. success: true
  1385. }
  1386. res.end(JSON.stringify(dataSentBack))
  1387. })
  1388. })
  1389.  
  1390. app.listen(PORT, function() {
  1391. console.log("server running on port " + PORT);
  1392. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement