· 4 years ago · Feb 13, 2021, 08:40 PM
1from kivymd.app import MDApp
2from kivy.lang import Builder
3from kivymd.uix.dialog import MDDialog
4from kivymd.uix.button import MDFlatButton
5from kivy.uix.screenmanager import Screen
6import sqlite3 as sql
7import datetime
8import time
9
10
11class DemoApp(MDApp):
12 class MainMenuScreen(Screen):
13 pass
14
15 class InputScreen(Screen):
16 pass
17
18 class RestingHeartRateScreen(Screen):
19 pass
20
21 class ResultObeseScreen(Screen):
22 pass
23
24 class ResultNormalScreen(Screen):
25 pass
26
27 class ResultOverweightScreen(Screen):
28 pass
29
30 class ResultUnderweightScreen(Screen):
31 pass
32
33 class LocationSearchScreen(Screen):
34 pass
35
36 class LocationResultScreen(Screen):
37 pass
38
39 class HistoryScreen(Screen):
40 pass
41
42 # conn = sql.connect('USERINFO.db')
43 # cur = conn.cursor()
44 # cur.execute(""" CREATE TABLE IF NOT EXISTS results (
45 # UID INTEGER PRIMARY KEY AUTOINCREMENT,
46 # NAME VARCHAR(50),
47 # RESULT INT,
48 # DATE_TIME TEXT DEFAULT CURRENT_TIMESTAMP)
49 # """)
50#
51 # cur.execute(""" CREATE TABLE IF NOT EXISTS information (
52 # id INTEGER PRIMARY KEY AUTOINCREMENT,
53 # fname VARCHAR(50),
54 # height INT,
55 # weight INT,
56 # age INT,
57 # heartrate INT)
58 # """)
59#
60#
61 # conn.commit()
62 # conn.close()
63
64
65 def save_data(self):
66 conn = sql.connect('USERINFO.db')
67 cur = conn.cursor()
68 cur.execute(""" INSERT INTO information (fname,height,weight,age,heartrate) VALUES (?,?,?,?,?)""",
69 (self.root.ids.scr_mngr.get_screen('input').ids.fname.text,
70 self.root.ids.scr_mngr.get_screen('input').ids.height.text,
71 self.root.ids.scr_mngr.get_screen('input').ids.weight.text,
72 self.root.ids.scr_mngr.get_screen('input').ids.age.text,
73 self.root.ids.scr_mngr.get_screen('input').ids.heartrate.text))
74 conn.commit()
75 conn.close()
76
77 def result_condition(self):
78 n = int(10000)
79 h = float(self.root.ids.scr_mngr.get_screen('input').ids.height.text)
80 w = float(self.root.ids.scr_mngr.get_screen('input').ids.weight.text)
81 unix = time.time()
82 date = str(datetime.datetime.fromtimestamp(unix).strftime('%Y-%m-%d %H:%M:%S'))
83 answer = (w / h / h) * n
84 print(answer)
85
86 conn = sql.connect('USERINFO.db')
87 cur = conn.cursor()
88 cur.execute(""" INSERT INTO results (NAME,RESULT,DATE_TIME) VALUES (?,?,?)""",
89 (
90 self.root.ids.scr_mngr.get_screen('input').ids.fname.text,
91 answer,
92 date
93 ))
94 conn.commit()
95 conn.close()
96 if answer <= 18.5:
97 self.root.ids.scr_mngr.current = 'underweight'
98 elif answer >= 18.6 or answer <= 24.9:
99 self.root.ids.scr_mngr.current = 'normal'
100 elif answer >= 25.0 or answer <= 29.9:
101 self.root.ids.scr_mngr.current = 'overweight'
102 else:
103 self.root.ids.scr_mngr.current = 'obese'
104
105 def show_database(self):
106 conn = sql.connect('USERINFO.db')
107 cur = conn.cursor()
108 cur.execute("""
109 SELECT fname, height, weight, heartrate, RESULT, DATE_TIME
110 FROM information INNER JOIN results
111 ON information.id = results.UID
112 """)
113 data = cur.fetchone()
114 # for data in output:
115 print(data)
116
117 def build(self):
118 self.theme_cls.primary_palette = "Lime"
119 self.theme_cls.theme_style = "Light" # "Light"
120 screen = Builder.load_file("main.kv")
121 return screen
122
123 def show_alert_dialog(self):
124 close_button = MDFlatButton(text="Okay",
125 on_release=self.okay)
126 more_button = MDFlatButton(text="Cancel", on_press=self.close_dialog)
127
128 self.dialog = MDDialog(title="Confirmation", text="Confirm Details?",
129 size_hint=(0.7, 1),
130 buttons=[close_button, more_button])
131 self.dialog.open()
132
133 def result_dialog(self):
134 close_button = MDFlatButton(text="Okay", on_release=self.close_dialog)
135 self.dialog = MDDialog(title="Where did we get the Results?",
136 text="Results are Determined based on the Details Given by the User",
137 size_hint=(0.7, 1),
138 buttons=[close_button])
139 self.dialog.open()
140
141 def hakdog(self):
142 close_button = MDFlatButton(text="Okay", on_release=self.close_dialog)
143 self.dialog = MDDialog(title="Instructions",
144 text="Manual Heartbeat check can be used to determine if you have a normal heart rate for your age. "
145 "If height = feet/inches, Convert to Centimeter (FEET× 30.48 +INCHES× 2.54) ",
146 size_hint=(0.7, 1),
147 buttons=[close_button])
148 self.dialog.open()
149
150 def show_data(self, *args):
151 if self.root.ids.scr_mngr.get_screen('input').ids.fname.text == "" \
152 or self.root.ids.scr_mngr.get_screen('input').ids.height.text == "" \
153 or self.root.ids.scr_mngr.get_screen('input').ids.weight.text == "" \
154 or self.root.ids.scr_mngr.get_screen('input').ids.heartrate.text == "" \
155 or self.root.ids.scr_mngr.get_screen('input').ids.age.text == "" \
156 or self.root.ids.scr_mngr.get_screen('input').ids.heartrate.text == "":
157 close_button = MDFlatButton(text="Okay", on_release=self.close_dialog)
158 self.dialog = MDDialog(title="Invalid", text="No item added",
159 size_hint=(0.7, 1), buttons=[close_button])
160 self.dialog.open()
161 else:
162 self.show_alert_dialog()
163
164 def okay(self, *args):
165 print(self.root.ids.scr_mngr.get_screen('input').ids.fname.text),
166 print(self.root.ids.scr_mngr.get_screen('input').ids.height.text),
167 print(self.root.ids.scr_mngr.get_screen('input').ids.weight.text),
168 print(self.root.ids.scr_mngr.get_screen('input').ids.age.text),
169 print(self.root.ids.scr_mngr.get_screen('input').ids.heartrate.text)
170 self.save_data()
171 # self.save_result()
172 self.result_condition()
173 self.dialog.dismiss()
174
175 def search_location(self):
176 conn = sql.connect('Hospital.db')
177 cur = conn.cursor()
178 cur.execute("""SELECT * FROM tbl_loc """)
179 output = cur.fetchall()
180
181 for data in output:
182 print(data)
183
184
185 def close_dialog(self, obj):
186 self.dialog.dismiss()
187
188 def history_screen(self, obj):
189 self.root.ids.scr_mngr.current = 'history'
190 self.root.ids.scr_mngr.transition.direction = "right"
191
192 def location_screen(self, obj):
193 self.root.ids.scr_mngr.current = 'locsearch'
194 self.root.ids.scr_mngr.transition.direction = "left"
195
196 def back_screen(self, obj):
197 self.root.ids.scr_mngr.current = 'menu'
198 self.root.ids.scr_mngr.transition.direction = "left"
199
200 def back2_screen(self, obj):
201 self.root.ids.scr_mngr.current = 'input'
202 self.root.ids.scr_mngr.transition.direction = "right"
203
204 def back3_screen(self, obj):
205 self.root.ids.scr_mngr.current = 'menu'
206 self.root.ids.scr_mngr.transition.direction = "right"
207
208 def back4_screen(self, obj):
209 self.root.ids.scr_mngr.current = 'locsearch'
210 self.root.ids.scr_mngr.transition.direction = "right"
211
212 def on_start(self):
213 pass
214
215
216DemoApp().run()
217------------------------------------------------------------
218
219Screen:
220 ScreenManager:
221 id:scr_mngr
222 MainMenuScreen:
223 name:"menu"
224 InputScreen:
225 name:"input"
226 RestingHeartRateScreen:
227 name:"heartrate"
228 ResultObeseScreen:
229 name:"obese"
230 ResultUnderweightScreen:
231 name:"underweight"
232 ResultOverweightScreen:
233 name:"overweight"
234 ResultNormalScreen:
235 name:"normal"
236 LocationSearchScreen:
237 name:"locsearch"
238 LocationResultScreen:
239 name:"locresult"
240 HistoryScreen:
241 name:"history"
242
243<MainMenuScreen>
244 NavigationLayout:
245 ScreenManager:
246 Screen:
247 BoxLayout:
248 orientation:'vertical'
249 MDToolbar:
250 title:' MD 24/7'
251 elevation:10
252 Widget:
253 MDBottomAppBar:
254 MDToolbar:
255 icon: "account"
256 type: "bottom"
257 on_action_button:
258 root.manager.current='input'
259 root.manager.transition.direction = "right"
260 left_action_items:[["history",lambda x: app.history_screen("history")]]
261 right_action_items:[["google-earth",lambda x: app.location_screen("locsearch")]]
262
263<InputScreen>
264 id:information
265 BoxLayout:
266 orientation: 'vertical'
267 MDToolbar:
268 title:'Input Details'
269 elevation:10
270 left_action_items:[["backspace",lambda x:app.back_screen("menu")]]
271 right_action_items:[["head-question",lambda x:app.hakdog()]]
272
273 Widget:
274 MDTextField:
275 id:fname
276 required: True
277 hint_text: "Full name"
278 pos_hint: {'center_x': 0.5}
279 size_hint_x: None
280 width: '250dp'
281 helper_text:"Please enter your Registered Name"
282 helper_text_mode:"on_focus"
283 Widget:
284 height: 35
285
286 MDTextField:
287 id:height
288 required: True
289 hint_text: "Height"
290 pos_hint: {'center_x': 0.5}
291 size_hint_x: None
292 width: '250dp'
293 helper_text:"Must be in centimeters"
294 helper_text_mode:"on_focus"
295 Widget:
296 height:35
297
298 MDTextField:
299 id:weight
300 required: True
301 hint_text: "Weight"
302 pos_hint: {'center_x': 0.5}
303 size_hint_x: None
304 width: '250dp'
305 helper_text:"Must be in Kilogram"
306 helper_text_mode:"on_focus"
307 Widget:
308 height:35
309
310 MDTextField:
311 id:age
312 hint_text: "Age"
313 required: True
314 pos_hint: {'center_x': 0.5}
315 size_hint_x: None
316 width: '250dp'
317 helper_text:"please enter your age"
318 helper_text_mode:"on_focus"
319 Widget:
320 height: 35
321
322 MDTextField:
323 id:heartrate
324 required: True
325 hint_text: "Heartrate"
326 pos_hint: {'center_x': 0.5}
327 size_hint_x: None
328 width: '250dp'
329 helper_text:"Count the beat on your palm for 60 seconds"
330 helper_text_mode:"on_focus"
331 Widget:
332 size_hint_y: None
333
334 MDScreen:
335 MDRectangleFlatButton:
336 mode: "rectangle"
337 text: 'Confirm'
338 pos_hint: {'center_x':0.5, 'center_y':0.8}
339 on_press :
340 app.show_data()
341
342 Widget:
343 size_hint_x: None
344
345<ResultObeseScreen>
346 BoxLayout:
347 orientation: 'vertical'
348 MDToolbar:
349 title:'Result: OBESE'
350 elevation:10
351 right_action_items:[["head-question",lambda x:app.result_dialog()]]
352 Widget:
353
354 MDLabel:
355 text: " People with obesity have increased risk of cardiovascular disease,type 2 diabetes, high blood pressure, and other health conditions. Waist-to-hip ratio, waist-to-height ratio, and body fat percentage measurements can provide a more complete picture of any health risks. A person should consult with their healthcare provider and consider making lifestyle changes through healthy eating and fitness to improve their health indicators. \n TIPS: \n *Change your diet. \n *Consider adding physical activity \n *Medication \n *Consume less “bad” fat and more “good” fat. \n *Consume less processed and sugary foods. \n *Eat more servings of vegetables and fruits \n *Eat plenty of dietary fiber. \n *limit your vices (drinking,smoking,etc)"
356 halign: "left"
357
358 Widget:
359
360 MDScreen:
361 MDRectangleFlatButton:
362 mode: "rectangle"
363 text: 'Go to Main Menu'
364 pos_hint: {'center_x':0.5, 'center_y':0.8}
365 on_press : root.manager.current='menu'
366
367<ResultNormalScreen>
368 BoxLayout:
369 orientation: 'vertical'
370 MDToolbar:
371 title:'Result: NORMAL WEIGHT'
372 elevation:10
373 right_action_items:[["head-question",lambda x:app.result_dialog()]]
374 Widget:
375
376 MDLabel:
377 text :" Maintaining a healthy weight may lower the risk of developing certain health conditions, including cardiovascular disease and type 2 diabetes. Waist-to-hip ratio, waist-to-height ratio, and body fat percentage measurements can provide a more complete picture of any health risks. \n TIPS: \n *Limit what you eat \n *exercise \n *sleep 7-8 hours a day \n *maintain a consistent sleeping routine \n *consider eating more healthy foods \n *limit your vices (drinking,smoking,etc)"
378 halign: "left"
379
380 Widget:
381
382 MDScreen:
383 MDRectangleFlatButton:
384 mode: "rectangle"
385 text: 'Go to Main Menu'
386 pos_hint: {'center_x':0.5, 'center_y':0.8}
387 on_press : root.manager.current='menu'
388
389<ResultOverweightScreen>
390 BoxLayout:
391 orientation: 'vertical'
392 MDToolbar:
393 title:'Result: OVERWEIGHT'
394 elevation:10
395 right_action_items:[["head-question",lambda x:app.result_dialog()]]
396 Widget:
397
398 MDLabel:
399 text: " Being overweight may increase the risk of certain health conditions, including cardiovascular disease, high blood pressure, and type 2 diabetes. Waist-to-hip ratio, waist-to-height ratio, and body fat percentage measurements can provide a more complete picture of any health risks. A person should consult with their healthcare provider and consider making lifestyle changes through healthy eating and fitness to improve their health indicators.Being overweight or fat is having more body fat than is optimally healthy \n TIPS: \n *Eat a high protein breakfast. \n *Avoid sugary drinks and fruit juice \n *Drink water before meals. \n *Choose weight-loss-friendly foods. \n *Eat soluble fiber. \n *Drink coffee or tea. \n *Base your diet on whole foods. \n *Eat slowly. \n *limit your vices (drinking,smoking,etc)"
400 halign: "left"
401
402 Widget:
403
404 MDScreen:
405 MDRectangleFlatButton:
406 mode: "rectangle"
407 text: 'Go to Main Menu'
408 pos_hint: {'center_x':0.5, 'center_y':0.8}
409 on_press : root.manager.current='menu'
410
411<ResultUnderweightScreen>
412 BoxLayout:
413 orientation: 'vertical'
414 MDToolbar:
415 title:'Result: UNDERWEIGHT'
416 elevation:10
417 right_action_items:[["head-question",lambda x:app.result_dialog()]]
418 Widget:
419
420 MDLabel:
421 text: " Being underweight may pose certain health risks, including nutrient deficiencies and hormonal changes. Waist-to-hip ratio, waist-to-height ratio, and body fat percentage measurements can provide a more complete picture of any health risks. A person should consult with their healthcare provider and consider making lifestyle changes through healthy eating and fitness to improve their health indicators.Being underweight can cause health problems. An underweight person is a person whose body weight is considered too low to be healthy /n TIPS: /n *eat more frequently /n *choose nutrient-rich foods /n *watch what you eat and drink /n *exercise /n *limit your vices (drinking,smoking,etc)"
422 halign: "left"
423
424 Widget:
425
426 MDScreen:
427 MDRectangleFlatButton:
428 mode: "rectangle"
429 text: 'Go to Main Menu'
430 pos_hint: {'center_x':0.5, 'center_y':0.8}
431 on_press : root.manager.current='menu'
432
433<LocationSearchScreen>
434 BoxLayout:
435 orientation: 'vertical'
436 MDToolbar:
437 title:'Location Services'
438 elevation:10
439 left_action_items:[["backspace",lambda x:app.back3_screen("menu")]]
440 Widget:
441
442 MDTextField:
443 id:loc
444 hint_text: "Enter your location"
445 pos_hint: {'center_x': 0.5}
446 size_hint_x: None
447 width: '250dp'
448 helper_text:"please enter your exact/current location"
449 helper_text_mode:"on_focus"
450 Widget:
451 size_hint_y: None
452
453 MDScreen:
454 MDRectangleFlatButton:
455 mode: "rectangle"
456 text: 'Confirm'
457 pos_hint: {'center_x':0.5, 'center_y':0.8}
458 on_press : app.search_location()
459 Widget:
460 size_hint_x: None
461
462<LocationResultScreen>
463 BoxLayout:
464 orientation: 'vertical'
465 MDToolbar:
466 title:'Result'
467 elevation:10
468 left_action_items:[["backspace",lambda x:app.back4_screen("locsearch")]]
469 Widget:
470 size_hint_y: None
471
472 MDLabel:
473 text: "Hospitals/Clinics Near you"
474 Widget:
475 size_hint_y: None
476
477 MDScreen:
478 MDRectangleFlatButton:
479 mode: "rectangle"
480 text: 'Go to Main Menu'
481 pos_hint: {'center_x':0.5, 'center_y':0.8}
482 on_press : root.manager.current='menu'
483 Widget:
484 size_hint_x: None
485
486<HistoryScreen>
487 MDFloatingActionButton:
488 icon: "magnify"
489 md_bg_color: app.theme_cls.primary_color
490 pos_hint: {"center_x": .8, "center_y": .1}
491 user_font_size: "25sp"
492 on_release:
493 app.show_database()
494
495 MDTextField:
496 id: inp
497 hint_text: 'Enter Full Name'
498 size_hint_x: None
499 pos_hint: {"center_x": .4, "center_y": .1}
500 width: '170dp'
501
502 MDCard:
503 size_hint: None, None
504 size: "280dp", "280dp"
505 pos_hint: {"center_x": .5, "center_y": .5}
506 orientation: "vertical"
507
508 ScrollView:
509 MDList:
510 id: list
511
512 MDToolbar:
513 id: toolbar
514 pos_hint: {"top": 1}
515 elevation: 6
516 title: "Check History"
517 left_action_items:[["backspace",lambda x:app.back_screen("menu")]]
518