Advertisement
Guest User

Untitled

a guest
Sep 15th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.38 KB | None | 0 0
  1. 'use strict';
  2. var mongoose = require('mongoose');
  3. mongoose.Promise = global.Promise;
  4. var dbURL = process.env.MONGODB_ADDON_URI || "mongodb://127.0.0.1:27017/medicalmull";
  5. mongoose.connect(dbURL);
  6. mongoose.connection.on("error",function(err){
  7. console.log(err)
  8. });
  9.  
  10. var Schema = mongoose.Schema;
  11.  
  12. var myModel = function () {
  13. var fileSchema = Schema({
  14. type: String,
  15. filename: String,
  16. path: String,
  17. file_id: String,
  18. },{
  19. collections: "fileinfo"
  20. });
  21.  
  22. var skillSchema = Schema({
  23. skill_id: String,
  24. disease: String,
  25. skill: String,
  26. procedure_description: String,
  27. files: [fileSchema]
  28. });
  29.  
  30. var service_objSchema = Schema({
  31. name: String,
  32. val: Boolean,
  33. id: Number,
  34. price: Number
  35. });
  36.  
  37. var serviceSchema = Schema({
  38. center_name: String,
  39. center_address: String,
  40. center_city: String,
  41. center_country: String,
  42. center_phone: Number,
  43. user_id: String,
  44. unavailable_services: [service_objSchema],
  45. type: String
  46.  
  47. },{
  48. collections: "centerservices"
  49. });
  50.  
  51. var mailSchema = Schema({
  52. firstname: String,
  53. message_id: Number,
  54. title: String,
  55. lastname: String,
  56. specialty: String,
  57. user_id: String,
  58. date: String,
  59. consultation_fee: Number,
  60. service_access: String,
  61. profile_pic_url: String,
  62. message: String,
  63. category: String,//note categories are admin, decline, redirect,need_doctor.
  64. reason: String,
  65. complaint_id: String,
  66. redirect: {
  67. title: String,
  68. firstname: String,
  69. lastname: String,
  70. specialty: String,
  71. user_id: String
  72. }
  73. });
  74.  
  75. var AwardSchema = Schema({
  76. id: Number,
  77. type_of_Award: String,
  78. date: String,
  79. description: String
  80. });
  81.  
  82. var EducationSchema = Schema({
  83. id: Number,
  84. school: String,
  85. start_year: Date,
  86. end_year: Date,
  87. certificate: String
  88. });
  89.  
  90. //prescriptionbodyschema goes inside prescription schema
  91.  
  92. var prescriptionBodySchema = Schema({
  93. sn: Number,
  94. dosage: String,
  95. frequency: String,
  96. drug_name: String,
  97. duration: String
  98. });
  99.  
  100. var statusSchema = Schema({
  101. date: Date,
  102. center_name: String,
  103. address: String,
  104. city:String,
  105. country: String,
  106. ref_id: Number,
  107. prescriptionId: Number
  108. });
  109.  
  110. var prescriptionSchema = Schema({
  111. prescriptionId: Number,
  112. provisional_diagnosis: String,
  113. date: String,
  114. doctor_experience: Number,
  115. doctor_firstname: String,
  116. doctor_lastname: String,
  117. doctor_address: String,
  118. doctor_id: String,
  119. doctor_verified:Boolean,
  120. doctor_work_place: String,
  121. doctor_city: String,
  122. doctor_country: String,
  123. doctor_phone: String,
  124. lab_analysis: String,
  125. scan_analysis: String,
  126. Doctor_profile_pic_url: String,
  127. patient_profile_pic_url: String,
  128. patient_firstname: String,
  129. patient_id: String,
  130. patient_lastname: String,
  131. patient_address: String,
  132. patient_gender: String,
  133. patient_age: String,
  134. patient_city: String,
  135. patient_country: String,
  136. prescription_body: [prescriptionBodySchema],
  137. ref_id: Number,
  138. eligible:Boolean,
  139. payment_acknowledgement: Boolean // use to check if patient have actually paid for a prescription through our app.
  140. //if false, prescription will be deleted after one month it was created.
  141. });
  142.  
  143. var transactionSchema = Schema({
  144. date: String,
  145. source: String,
  146. message: String,
  147. activity: String,
  148. body: {
  149. amount: Number,
  150. beneficiary: String,
  151. },
  152.  
  153. });
  154.  
  155. var noteSchema = Schema({
  156. sender_id: String,
  157. message_id: Number,
  158. type: String,
  159. date: String,
  160. message: String,
  161. sender_firstname: String,
  162. sender_lastname: String,
  163. sender_profile_pic_url: String
  164. });
  165.  
  166. var periodSchema = Schema({
  167. day: String,
  168. from: String,
  169. to: String
  170. });
  171.  
  172. var subspecialtySchema = Schema({
  173. id: Number,
  174. sub_specialty: String
  175. });
  176.  
  177.  
  178.  
  179. var accessSchema = Schema({
  180. patient_id: String,
  181. access_to_record: Boolean
  182. });
  183.  
  184. var patient_noteSchema = Schema({
  185. date: String,
  186. note_id: Number,
  187. ref_id: Number,
  188. session_id: Number,
  189. type: String,
  190. message: String
  191. });
  192.  
  193. var doc_briefSchema = Schema({
  194. doctor_id: String,
  195. date_of_acceptance: String,
  196. doctor_firstname: String,
  197. doctor_lastname: String,
  198. doctor_profile_pic_url: String,
  199. service_access: Boolean,
  200. doctor_specialty: String,
  201. work_place: String,
  202. office_hour:[periodSchema],
  203. presence: Boolean
  204. });
  205.  
  206. var patient_briefSchema = Schema({
  207. patient_firstname: String,
  208. patient_lastname: String,
  209. patient_id: String,
  210. patient_profile_pic_url: String,
  211. patient_address: String,
  212. patient_city: String,
  213. Patient_country: String,
  214. patient_gender: String,
  215. patient_age: Number,
  216. patient_body_weight: String,
  217. presence: Boolean
  218. });
  219. //this holds records for lab,prescription and scan for the patient
  220. var diagnosisSchema = Schema({
  221. doctor_note: String,
  222. doctor_firstname: String,
  223. doctor_lastname: String,
  224. date: Date,
  225. illness: String
  226. });
  227.  
  228. var patient_TestSchema = Schema({
  229. test_to_run: Array,
  230. center_name: String,
  231. center_phone: String,
  232. center_address: String,
  233. center_city: String,
  234. center_country: String,
  235. center_id: String,
  236. patient_id: String,
  237. ref_id: Number,
  238. referral_firstname: String,
  239. referral_lastname: String,
  240. referral_title: String,
  241. sent_date: String,
  242. receive_date: String,
  243. report: String,
  244. conclusion: String,
  245. session_id: Number,
  246. files: Array,
  247. history: String,
  248. payment_acknowledgement: Boolean //use to check if patient have actually paid for a service.
  249. });
  250.  
  251. //this holds the sent test to ba ran by the laboratory center
  252. var center_refSchema = Schema({
  253. test_to_run: Array,
  254. patient_firstname: String,
  255. age: String,
  256. gender: String,
  257. history: String,
  258. patient_lastname: String,
  259. patient_profile_pic_url: String,
  260. patient_title: String,
  261. patient_gender: String,
  262. patient_age: String,
  263. session_id: Number,
  264. patient_id: String,
  265. test_id: Number,
  266. attended: Boolean,
  267. title: String,
  268. doctor_firstname: String,
  269. doctor_lastname: String,
  270. doctor_id: String,
  271. doctor_phone: Number
  272. });
  273.  
  274. var drug_refSchema = Schema({
  275. dosage: String,
  276. drugName: String,
  277. frequency: String,
  278. duration: String,
  279. drugId: Number
  280. });
  281.  
  282. var refSchema = Schema({
  283. ref_id: Number,
  284. referral_firstname: String,
  285. referral_lastname: String,
  286. referral_title: String,
  287. referral_id: String,
  288. date: String,
  289. type_of_test: String,
  290. laboratory: center_refSchema,
  291. radiology: center_refSchema,
  292. pharmacy: prescriptionSchema
  293. });
  294.  
  295. var appointment_schema = Schema({
  296. date: String,
  297. time: String,
  298. last_meeting: String,
  299. firstname: String,
  300. lastname: String,
  301. title: String,
  302. patient_id: String,
  303. address: String,
  304. session_id: Number,
  305. typeOfSession: String,
  306. profilePic: String
  307. });
  308.  
  309. var ref_notificationSchema = Schema({
  310. sender_firstname: String,
  311. sender_lastname: String,
  312. sender_title : String,
  313. sent_date: String,
  314. ref_id: Number,
  315. note_id: Number,
  316. sender_profile_pic_url: String,
  317. message: String
  318. });
  319. //for session
  320. var conversationSchema = Schema({
  321. date: Date,
  322. messages: String
  323. });
  324.  
  325. var testResultSchema = Schema({ //note received date will be set as pending if the test has not returned. other be updated to date when returned
  326. receive_date: String,
  327. test_to_run: Array,
  328. report: String,
  329. conclusion: String,
  330. sent_date: String,
  331. test_ran_by: String,
  332. test_id: Number,
  333. files: Array
  334. });
  335.  
  336. var docDignosisSchema = Schema({
  337. presenting_complain: String,
  338. history_of_presenting_complain: String,
  339. past_medical_history: String,
  340. social_history: String,
  341. family_history: String,
  342. drug_history: String,
  343. summary: String,
  344. provisional_diagnosis: String,
  345. general_examination: String,
  346. systemic_examination: String,
  347. diagnosis: String,
  348. laboratory_test_results: [testResultSchema],
  349. radiology_test_results: [testResultSchema],
  350. ecg_test_result: [testResultSchema],
  351. others: [testResultSchema],
  352. final_diagnosis: String,
  353. files: Array
  354. });
  355.  
  356. var sessionSchema = Schema({
  357. date: String,
  358. last_modified: String,
  359. session_id: Number,
  360. patient_id: String,
  361. profilePic: String,
  362. patient_firstname: String,
  363. patient_lastname: String,
  364. patient_username: String,
  365. prescription_id: Number,
  366. typeOfSession: String,
  367. conversations: conversationSchema,
  368. diagnosis: docDignosisSchema
  369. });
  370.  
  371. var requestSchema = Schema({
  372. status: String,
  373. sender_firstname: String,
  374. sender_lastname: String,
  375. sender_profile_pic_url: String,
  376. sender_id: String,
  377. conclusion: String,
  378. type_of_test: String,
  379. center_name: String,
  380. center_address: String,
  381. cente_city: String,
  382. center_country: String,
  383. test_result: Array,
  384. files: Array,
  385. date_sent: String,
  386. ref_id: Number
  387. });
  388.  
  389. //end for session
  390. var userSchema = Schema({
  391. firstname: String,
  392. username: String,
  393. lastname: String,
  394. user_id: String,
  395. password: String,
  396. age: String,
  397. email: String,
  398. gender: String,
  399. address: String,
  400. state: String,
  401. city: String,
  402. title: String,
  403. marital_status: String,
  404. medications: [prescriptionSchema],
  405. date: Date,
  406. profile_url: String,
  407. verified: Boolean,
  408. ewallet:{
  409. available_amount: Number,
  410. transaction:[transactionSchema]
  411. },
  412. admin: Boolean,
  413. type: String,
  414. profile_pic: {
  415. fieldname: String,
  416. originalname: String,
  417. encoding: String,
  418. mimetype: String,
  419. destination: String,
  420. filename: String,
  421. path: String,
  422. size: Number
  423. },
  424. files:[fileSchema],
  425. rating: Number,
  426. profile_pic_url: String,
  427. sub_specialty: [subspecialtySchema],
  428. skills: [skillSchema],
  429. introductory: String,
  430. awards: [AwardSchema],
  431. education: [EducationSchema],
  432. specialty: String,
  433. work_place: String,
  434. phone: Number,
  435. experience: Number,
  436. country: String,
  437. doctor_notification:[noteSchema],
  438. referral: [refSchema],
  439. patient_notification: [patient_noteSchema],
  440. office_hour:[periodSchema],
  441. record_access:[accessSchema],
  442. accepted_doctors: [doc_briefSchema],
  443. doctor_patients_list : [patient_briefSchema],
  444. medical_records: {
  445. diagnosis: [diagnosisSchema],
  446. prescription: [prescriptionSchema],
  447. laboratory_test: [patient_TestSchema],
  448. radiology_test: [patient_TestSchema]
  449. },
  450. name: String,
  451. diagnostic_center_notification:[ref_notificationSchema],
  452. accepted_patients: [patient_briefSchema],
  453. appointment:[appointment_schema],
  454. prescription_tracking: [statusSchema],
  455. doctor_patient_session: [sessionSchema],
  456. doctor_prescriptionRequest: [requestSchema],
  457. emergency_ref_url: String,
  458. patient_mail: [mailSchema],
  459. presence: Boolean,
  460. set_presence:{
  461. general: Boolean,
  462. particular: Array // sets the presence of the user and controls who sends messages to the user.
  463. },
  464. city_grade: Number,
  465. watch_list: Array,
  466. barred: Boolean
  467. },{
  468. collections: "userinfos"
  469. })
  470.  
  471.  
  472.  
  473. var helpSchema = Schema({
  474. helpType: String,
  475. description: String,
  476. sent_date: String,
  477. symptoms: Array,
  478. introductory: String,
  479. patient_id: String,
  480. complaint_id: String,
  481. age: String,
  482. gender: String,
  483. preferred_city: String,
  484. isview: Boolean,
  485. response: Array,
  486. files: Array
  487. },{
  488. collections: "helpinfos"
  489. });
  490.  
  491. var otpSchema = Schema({
  492. expirationDate: {
  493. type: Date,
  494. expires: 3600
  495. },
  496. createdAt: {
  497. type: Date,
  498. expires: Number
  499. },
  500. user_id: String,
  501. time: Number,
  502. amount: Number,
  503. otp: String,
  504. senderId: String
  505. },{
  506. collections:"otpinfos"
  507. });
  508.  
  509. var phoneVerificationSchema = Schema({
  510. expirationDate: {
  511. type: Date,
  512. expires: 3600
  513. },
  514. createdAt: {
  515. type: Date,
  516. expires: Number
  517. },
  518. phone: Number,
  519. pin: String
  520. },{
  521. collections: "phoneVerify"
  522. });
  523.  
  524. var authChangeSchema = Schema({
  525. expirationDate: {
  526. type: Date,
  527. expires: 3600
  528. },
  529. createdAt: {
  530. type: Date,
  531. expires: Number
  532. },
  533. user_id: String,
  534. pin: String
  535. },{
  536. collections: "authVerify"
  537. });
  538.  
  539. var pinSchema = Schema({
  540. voucher: Array,
  541. voucher_two: Array,
  542. voucher_three: Array,
  543. otp: Array
  544. },{
  545. collections: "pininfo"
  546. });
  547.  
  548. var inConversationSchema = Schema({
  549. ongoing_conversation: Array
  550. },{
  551. collections:"callinfo"
  552. });
  553.  
  554. var chatSchema = Schema({
  555. chat_id: String,
  556. type: String,
  557. messages: Array,
  558. date_created: String
  559. },{
  560. collections: "chatinfos"
  561. });
  562.  
  563. var cashOutSchema = Schema({
  564. date: Number,
  565. account_number: String,
  566. firstname: String,
  567. lastname: String,
  568. user_id: String,
  569. amount: Number,
  570. phone: Number,
  571. bank: String,
  572. id: Number,
  573. name: String
  574. },{
  575. collections: "cashoutinfos"
  576. })
  577.  
  578. /*var callRequestSchema = Schema({
  579. message_id: String,
  580. type: String,
  581. request: Array,
  582. date: String
  583. },{
  584. collections: "requestinfos"
  585. });*/
  586.  
  587. //models
  588. var models = {};
  589. models.user = mongoose.model('userinfos', userSchema);
  590. models.files = mongoose.model('fileinfo', fileSchema);
  591. models.patient = mongoose.model("patientinfo",patient_briefSchema);
  592. models.services = mongoose.model("centerservices",serviceSchema);
  593. models.help = mongoose.model("helpinfos",helpSchema);
  594. models.pins = mongoose.model("pininfo",pinSchema);
  595. models.communication = mongoose.model("callinfo",inConversationSchema);
  596. models.chats = mongoose.model("chatinfos",chatSchema);
  597. models.otpSchema = mongoose.model("otpinfos",otpSchema);
  598. models.verifyPhone = mongoose.model("phoneVerify",phoneVerificationSchema);
  599. models.authCheck = mongoose.model("authVerify",authChangeSchema);
  600. models.cashout = mongoose.model("cashoutinfos",cashOutSchema);
  601. //models.requests = mongoose.model("requestinfos",chatSchema);
  602. /*models.award = mongoose.model('awardinfo', AwardSchema);
  603. models.education = mongoose.model('educationinfo', EducationSchema);
  604. models.prescribtion = mongoose.model("prescribtioninfo", prescribtionSchema);
  605. models.transaction = mongoose.model("transactioninfo",transactionSchema);
  606. models.procedure = mongoose.model("procedureinfo",procedureSchema);
  607. models.subSpecialty = mongoose.model("subspecialtyinfo",subspecialtySchema);*/
  608. return models
  609. }
  610.  
  611. module.exports = myModel;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement