Skip to content

Commit

Permalink
Merge pull request #40 from mohit-codes/main
Browse files Browse the repository at this point in the history
Tips added | view report API url corrected
  • Loading branch information
Ashuto7h authored May 19, 2021
2 parents f10853e + ccff323 commit d099fe0
Show file tree
Hide file tree
Showing 7 changed files with 248 additions and 13 deletions.
1 change: 0 additions & 1 deletion client/lib/add_patient_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ class _AddPatientScreenState extends State<AddPatientScreen> {
),
wsb(0.05),
Container(
height: deviceHeight * 0.07,
width: deviceWidth * 0.42,
child: DropdownButtonFormField(
validator: FormBuilderValidators.compose(
Expand Down
4 changes: 1 addition & 3 deletions client/lib/generate_report_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ class _GenerateReportFormState extends State<GenerateReportForm> {
if (_form.currentState.validate()) {
_form.currentState.save();
generateReport(context, _reportObj, _tempPatient);
// _form.currentState.reset();
_form.currentState.reset();
}
}

@override
Widget build(BuildContext context) {
// ignore: avoid_print
print(_patient);
final double deviceWidth = MediaQuery.of(context).size.width;
final double deviceHeight = MediaQuery.of(context).size.height;
return Container(
Expand Down
15 changes: 10 additions & 5 deletions client/lib/recent_reports.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:client/models/report_model.dart';
import 'package:client/report_screen.dart';
import 'package:client/resources/api_provider.dart';
import 'package:client/resources/helper.dart';
import 'package:client/view_report.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:http/http.dart' as http;
Expand All @@ -21,7 +22,8 @@ class _RecentReportsScreenState extends State<RecentReportsScreen> {
void fetchReports() async {
final localStorage = await SharedPreferences.getInstance();
final userid = localStorage.getString('userId');
final url = Uri.parse("https://nutrihelpb.herokuapp.com/reports/$userid");
final url =
Uri.parse("https://nutrihelpb.herokuapp.com/reports/$userid/recent");

final res = await http.get(
url,
Expand All @@ -46,7 +48,10 @@ class _RecentReportsScreenState extends State<RecentReportsScreen> {
}

String per(double p) {
return "${p.toString().substring(0, 4)} %";
String trimmed =
p.toString().length > 5 ? p.toString().substring(0, 3) : p.toString();

return "${trimmed} %";
}

@override
Expand Down Expand Up @@ -121,9 +126,9 @@ class _RecentReportsScreenState extends State<RecentReportsScreen> {
context,
MaterialPageRoute(
builder: (context) =>
ReportScreen(
patientId:
reports[index].patientId,
ViewReportScreen(
reportId:
reports[index].reportId,
),
),
);
Expand Down
7 changes: 4 additions & 3 deletions client/lib/report_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class _ReportScreenState extends State<ReportScreen> {
final double deviceWidth = MediaQuery.of(context).size.width;
final double deviceHeight = MediaQuery.of(context).size.height;
SizedBox hsb(val) => SizedBox(height: deviceHeight * val);

return template(
body: ListView(
children: [
Expand Down Expand Up @@ -103,14 +104,14 @@ class _ReportScreenState extends State<ReportScreen> {
radius: deviceWidth * 0.4,
lineWidth: deviceWidth * 0.02,
percent: report.probability / 100,
center: Text(
"${(report.probability / 100).toString().substring(0, 4)} %"),
center:
Text("${(report.probability).toString()} %"),
progressColor: Colors.green,
),
],
),
Text(
"Dibetic prediction probability of Patient ${report.patientName} is ${(report.probability / 100).toString().substring(0, 4)} %",
"Dibetic prediction probability of Patient ${report.patientName} is ${(report.probability).toString()} %",
style:
GoogleFonts.poppins(fontSize: deviceWidth * 0.05),
),
Expand Down
27 changes: 27 additions & 0 deletions client/lib/resources/tips.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const tips = [
{
'heading': 'Get plenty of fiber',
'detail':
'- Include foods in diet with high fiber such as fruits, vegetables, beans, whole grains and Oats.'
},
{
'heading': 'Get more physical activity',
'detail':
'- aerobic exercise and resistance training can help control diabetes.\n - The greatest benefit comes from a fitness program that includes both.\n - Useful forms of exercise include weightlifting, brisk walking, running, biking, dancing, hiking, swimming, and more.'
},
{
'heading': 'Drink water and stay hydrated',
'detail':
'- Drinking enough water may help you keep your blood sugar levels within healthy limits.\n - Keep in mind that water and other non-caloric beverages are best.\n - Sugar-sweetened drinks raise blood glucose, drive weight gain, and increase diabetes risk .'
},
{
'heading': 'Manage stress levels',
'detail':
'- Stress can affect your blood sugar levels.\n - Hormones such as glucagon and cortisol are secreted during stress.\n - These hormones cause blood sugar levels to go up.'
},
{
'heading': 'Eat less salt',
'detail':
'- Eating lots of salt can increase your risk of high blood pressure,which in turn increases risk of heart diseases and stroke.\n - And when you have diabetes, you’re already more at risk of all of these conditions.\n - Try to limit yourself to a maximum of 6g (one teaspoonful) of salt a day.\n - Lots of pre-packaged foods already contain salt so remember to check food labels and choose those with less salt.'
}
];
205 changes: 205 additions & 0 deletions client/lib/view_report.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
import 'dart:convert';

import 'package:client/dashboard_screen.dart';
import 'package:client/models/patient_list_object_model.dart';
import 'package:client/models/report_model.dart';
import 'package:client/resources/helper.dart';
import 'package:client/resources/tips.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:http/http.dart' as http;
import 'package:percent_indicator/circular_percent_indicator.dart';
import 'package:shared_preferences/shared_preferences.dart';

class ViewReportScreen extends StatefulWidget {
final String reportId;

const ViewReportScreen({this.reportId});

@override
_ViewReportScreenState createState() => _ViewReportScreenState(reportId);
}

class _ViewReportScreenState extends State<ViewReportScreen> {
_ViewReportScreenState(String _tempreportId) {
_reportId = _tempreportId;
}

String _reportId;
bool _loading = true;
dynamic report;

void fetchReport() async {
final localStorage = await SharedPreferences.getInstance();
final userid = localStorage.getString('userId');
final url = Uri.parse(
"https://nutrihelpb.herokuapp.com/reports/$userid/$_reportId");

final res = await http.get(
url,
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
);

if (res.statusCode == 200) {
setState(() {
_loading = false;
report = Report.fromJson(jsonDecode(res.body));
});
}
return null;
}

@override
void initState() {
fetchReport();
}

@override
Widget build(BuildContext context) {
final double deviceWidth = MediaQuery.of(context).size.width;
final double deviceHeight = MediaQuery.of(context).size.height;
SizedBox hsb(val) => SizedBox(height: deviceHeight * val);

return template(
body: ListView(
children: [
Row(
children: [
Padding(
padding: const EdgeInsets.only(left: 15.0, top: 10),
child: Container(
width: deviceWidth * 0.9,
child: Text(
'Prediction Report ',
style: GoogleFonts.poppins(fontSize: deviceWidth * 0.08),
),
),
)
],
),
Container(
width: deviceWidth * 0.9,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: _loading
? Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 50,
height: 50,
child: const CircularProgressIndicator(),
),
],
)
: Container(
width: deviceWidth * 0.5,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularPercentIndicator(
radius: deviceWidth * 0.4,
lineWidth: deviceWidth * 0.02,
percent: report.probability / 100,
center:
Text("${(report.probability).toString()} %"),
progressColor: Colors.green,
),
],
),
Text(
"Diabetic prediction probability of Patient ${report.patientName} is ${(report.probability).toString()} % .",
style:
GoogleFonts.poppins(fontSize: deviceWidth * 0.05),
),
hsb(0.01),
report.probability > 50 == false
? Text(
'Paitent is less prone to diabetes.',
style: GoogleFonts.poppins(
fontSize: deviceWidth * 0.05),
)
: Container(
width: deviceWidth * 0.9,
child: Column(
children: [
Text('Some Tips for Patient',
style: GoogleFonts.poppins(
fontSize: deviceWidth * 0.05)),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: tips
.map((e) => Card(
child: Padding(
padding:
const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(e['heading'],
style:
GoogleFonts.poppins(
fontSize:
deviceWidth *
0.05)),
Text(e['detail'])
],
),
)))
.toList(),
),
],
),
)
],
),
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: deviceWidth * 0.3,
child: TextButton(
onPressed: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => const DashBoardScreen()));
},
style: TextButton.styleFrom(
primary: Colors.white,
minimumSize: Size(deviceWidth * 0.25, deviceHeight * 0.07),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(15)),
),
backgroundColor: const Color(0xff05483F),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
const Icon(Icons.arrow_back_ios),
Text('Back',
style: TextStyle(fontSize: deviceWidth * 0.05)),
],
),
),
),
),
],
),
hsb(0.01),
],
));
}
}
2 changes: 1 addition & 1 deletion client/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
stack_trace:
dependency: transitive
description:
Expand Down

0 comments on commit d099fe0

Please sign in to comment.