Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
TMP-23-068
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TMP-23-068
TMP-23-068
Commits
0afe3698
Commit
0afe3698
authored
Oct 31, 2023
by
Yasara19
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed Nutrition Plan Bug
parent
625720ae
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
125 additions
and
175 deletions
+125
-175
screens/Nutrition.js
screens/Nutrition.js
+79
-141
screens/Plan.js
screens/Plan.js
+46
-34
No files found.
screens/Nutrition.js
View file @
0afe3698
import
React
,
{
useState
}
from
'
react
'
;
import
{
Button
,
Image
,
Text
,
View
,
TextInput
,
ScrollView
,
StyleSheet
,
TouchableOpacity
,
ImageBackground
}
from
'
react-native
'
;
import
{
Button
,
Image
,
Text
,
View
,
TextInput
,
ScrollView
,
ImageBackground
,
StyleSheet
,
TouchableOpacity
}
from
'
react-native
'
;
import
*
as
ImagePicker
from
'
expo-image-picker
'
;
import
axios
from
'
axios
'
;
import
{
useNavigation
}
from
"
@react-navigation/native
"
;
export
default
function
Nutrition
({
route
})
{
const
[
imageCBC
,
setImageCBC
]
=
useState
(
null
);
const
[
imageOGTT
,
setImageOGTT
]
=
useState
(
null
);
const
[
resultCBC
,
setResultCBC
]
=
useState
(
''
);
const
[
resultOGTT
,
setResultOGTT
]
=
useState
(
''
);
//const [bmi, setBMI] = useState('');
const
[
otherModelResult
,
setOtherModelResult
]
=
useState
(
''
);
const
navigation
=
useNavigation
();
const
{
bmi
}
=
route
.
params
;
const
[
isPlanButtonVisible
,
setIsPlanButtonVisible
]
=
useState
(
false
);
const
[
isDataReady
,
setIsDataReady
]
=
useState
(
false
);
const
pickImage
=
async
(
reportType
)
=>
{
const
{
status
}
=
await
ImagePicker
.
requestMediaLibraryPermissionsAsync
();
...
...
@@ -69,22 +67,11 @@ export default function Nutrition({ route }) {
}
};
/*
const sendToOtherModel = () => {
const
sendToOtherModel
=
()
=>
{
if
(
!
resultCBC
||
!
resultOGTT
||
!
bmi
)
{
alert
(
'
Please provide Hemoglobin, Glucose, and BMI values.
'
);
return
;
}
*/
const
sendToOtherModel
=
()
=>
{
// Check if at least one of the required data is available
if
(
resultCBC
||
resultOGTT
||
bmi
)
{
setIsDataReady
(
true
);
}
else
{
alert
(
'
Please provide Hemoglobin, Glucose, or BMI values.
'
);
}
console
.
log
(
parseFloat
(
resultCBC
));
console
.
log
(
parseFloat
(
resultOGTT
));
...
...
@@ -121,13 +108,10 @@ export default function Nutrition({ route }) {
const
formattedMealPlan
=
customText
.
replace
(
/;/g
,
'
\n
'
);
setOtherModelResult
(
formattedMealPlan
);
// setOtherModelResult(customText);
// Set the state variable to make the "Get Nutrition Plan" button visible
setIsPlanButtonVisible
(
true
);
console
.
log
(
response
.
data
.
prediction
);
})
.
catch
(
error
=>
{
console
.
error
(
'
Error sending data to other model:
'
,
error
);
alert
(
'
Error occurred while sending data to other model.
'
);
});
};
...
...
@@ -139,103 +123,73 @@ export default function Nutrition({ route }) {
};
return
(
<
ScrollView
contentContainerStyle
=
{
styles
.
scrollViewContent
}
>
<
ImageBackground
source
=
{
require
(
"
../assets/nutrition.png
"
)}
resizeMode
=
"
cover
"
style
=
{
styles
.
image
}
>
<
View
style
=
{{
flex
:
1
}}
>
<
View
style
=
{
styles
.
container
}
>
<
View
style
=
{
styles
.
subContainer
}
>
<
Text
style
=
{
styles
.
heading
}
>
Upload
Your
Blood
Report
<
/Text
>
<
Text
style
=
{
styles
.
description
}
>
(
*
Please
Upload
Fasting
Blood
Sugar
(
OGTT
-
FBS
)
or
Full
Blood
Count
(
FBC
)
Report
)
<
/Text
>
<
View
style
=
{
styles
.
imageCBCContainer
}
>
<
Button
title
=
"
Pick CBC image
"
onPress
=
{()
=>
pickImage
(
'
CBC
'
)}
/
>
{
imageCBC
&&
<
Image
source
=
{{
uri
:
imageCBC
}}
style
=
{{
width
:
200
,
height
:
200
}}
/>
}
{
resultCBC
&&
<
Text
style
=
{
styles
.
labelText
}
>
Hemoglobin
:{
resultCBC
}
<
/Text>
}
<
/View
>
<
View
style
=
{
styles
.
imageOGTTContainer
}
>
<
Button
title
=
"
Pick OGTT image
"
onPress
=
{()
=>
pickImage
(
'
OGTT
'
)}
/
>
{
imageOGTT
&&
<
Image
source
=
{{
uri
:
imageOGTT
}}
style
=
{{
width
:
200
,
height
:
200
}}
/>
}
{
resultOGTT
&&
<
Text
style
=
{
styles
.
labelText
}
>
Glucose
:{
resultOGTT
}
<
/Text>
}
<
/View>
<
View
style
=
{
styles
.
bmiContainer
}
>
<
Text
style
=
{
styles
.
bmiText
}
>
BMI
:
<
/Text
>
<
TextInput
placeholder
=
"
Enter BMI
"
onChangeText
=
{(
text
)
=>
setBMI
(
text
)}
value
=
{
bmi
?
bmi
.
toString
()
:
""
}
// Set the BMI value from the route
keyboardType
=
"
numeric
"
style
=
{
styles
.
labelText
}
editable
=
{
false
}
// Make the TextInput read-only
/
>
<
/View
>
<
TouchableOpacity
style
=
{
styles
.
selectButton
}
onPress
=
{
sendToOtherModel
}
>
<
Text
style
=
{
styles
.
buttonText
}
>
Save
<
/Text
>
<
/TouchableOpacity
>
{
/* Conditionally render the "Get Nutrition Plan" button */
}
{
isPlanButtonVisible
&&
(
<
TouchableOpacity
style
=
{
styles
.
navibutton
}
onPress
=
{
navigateToPlan
}
>
<
Text
style
=
{
styles
.
buttonText
}
>
Get
Nutrition
Plan
<
/Text
>
<
/TouchableOpacity
>
)}
<
/View
>
<
/View
>
<
/View
>
<
/ImageBackground>
<
/ScrollView
>
);
}
<
ScrollView
contentContainerStyle
=
{{
flexGrow
:
1
}}
>
<
ImageBackground
source
=
{
require
(
"
../assets/backnew.png
"
)}
resizeMode
=
"
cover
"
style
=
{
styles
.
image
}
>
<
View
style
=
{
styles
.
overlay
}
>
<
View
style
=
{{
flex
:
1
,
alignItems
:
'
center
'
,
justifyContent
:
'
center
'
}}
>
<
Button
title
=
"
Pick CBC image
"
onPress
=
{()
=>
pickImage
(
'
CBC
'
)}
/
>
{
imageCBC
&&
<
Image
source
=
{{
uri
:
imageCBC
}}
style
=
{{
width
:
200
,
height
:
200
}}
/>
}
{
resultCBC
&&
<
Text
>
Hemoglobin
:{
resultCBC
}
<
/Text>
}
<
Button
title
=
"
Pick OGTT image
"
onPress
=
{()
=>
pickImage
(
'
OGTT
'
)}
/
>
{
imageOGTT
&&
<
Image
source
=
{{
uri
:
imageOGTT
}}
style
=
{{
width
:
200
,
height
:
200
}}
/>
}
{
resultOGTT
&&
<
Text
>
Glucose
:{
resultOGTT
}
<
/Text>
}
<
TextInput
placeholder
=
"
Enter BMI
"
onChangeText
=
{
text
=>
setBMI
(
text
)}
value
=
{
bmi
}
keyboardType
=
"
numeric
"
/>
<
TextInput
placeholder
=
"
Enter BMI
"
onChangeText
=
{(
text
)
=>
setBMI
(
text
)}
value
=
{
bmi
?
bmi
.
toString
()
:
""
}
// Set the BMI value from the route
keyboardType
=
"
numeric
"
editable
=
{
false
}
// Make the TextInput read-only
/
>
<
TouchableOpacity
style
=
{
styles
.
button
}
onPress
=
{
sendToOtherModel
}
>
<
Text
style
=
{
styles
.
buttonText
}
>
Save
<
/Text
>
<
/TouchableOpacity
>
<
TouchableOpacity
style
=
{
styles
.
navibutton
}
onPress
=
{
navigateToPlan
}
>
<
Text
style
=
{
styles
.
buttonText
}
>
Get
Nutrition
Plan
<
/Text
>
<
/TouchableOpacity
>
<
/View
>
<
/View
>
<
/ImageBackground
>
<
/ScrollView
>
);
}
const
styles
=
StyleSheet
.
create
({
container
:
{
backgroundColor
:
"
#FFEBFA
"
,
flex
:
1
,
},
subContainer
:
{
padding
:
15
,
borderRadius
:
15
,
marginTop
:
15
,
marginLeft
:
15
,
marginRight
:
15
,
flex
:
1
,
},
scrollViewContent
:
{
minHeight
:
'
120%
'
,
// Set a minimum height to enable scrolling
image
:
{
flex
:
1
,
justifyContent
:
'
center
'
,
},
imageCBCContainer
:
{
marginTop
:
40
,
// Add some margin between the button and the description
alignItems
:
'
center
'
,
// Center the images horizontally
},
imageOGTTContainer
:{
marginTop
:
40
,
alignItems
:
'
center
'
,
// Center the images horizontally
},
bmiContainer
:{
marginTop
:
40
,
fontWeight
:
"
bold
"
,
fontSize
:
12
,
},
labelText
:{
fontWeight
:
"
bold
"
,
color
:
"
black
"
,
fontSize
:
15
,
overlay
:
{
flex
:
1
,
backgroundColor
:
'
rgba(0, 0, 0, 0.3)
'
,
padding
:
20
,
justifyContent
:
'
center
'
,
alignItems
:
"
center
"
,
},
bmiText
:{
fontWeight
:
"
bold
"
,
fontSize
:
20
,
button
:
{
backgroundColor
:
"
pink
"
,
borderRadius
:
5
,
padding
:
10
,
marginTop
:
60
,
width
:
200
,
},
navibutton
:{
...
...
@@ -243,42 +197,26 @@ const styles = StyleSheet.create({
borderRadius
:
5
,
padding
:
10
,
marginTop
:
30
,
width
:
"
100%
"
,
alignItems
:
"
center
"
,
justifyContent
:
"
center
"
,
width
:
200
,
},
selectButton
:
{
borderRadius
:
10
,
marginTop
:
40
,
width
:
"
100%
"
,
height
:
47
,
backgroundColor
:
"
#FF9DD2
"
,
alignItems
:
"
center
"
,
justifyContent
:
"
center
"
,
buttonText
:
{
color
:
"
white
"
,
fontWeight
:
"
bold
"
,
textAlign
:
"
center
"
,
fontSize
:
16
,
},
buttonText
:
{
color
:
"
black
"
,
fontSize
:
18
,
label
:
{
fontSize
:
24
,
fontWeight
:
"
bold
"
,
marginBottom
:
10
,
},
heading
:
{
marginTop
:
50
,
marginLeft
:
60
,
color
:
"
black
"
,
fontSize
:
35
,
result
:
{
fontSize
:
36
,
fontWeight
:
"
bold
"
,
alignItems
:
"
center
"
color
:
"
black
"
,
// You can style the color based on BMI ranges
},
});
description
:{
marginTop
:
10
,
marginLeft
:
50
,
color
:
"
black
"
,
fontSize
:
15
,
align
:
"
right
"
,
}
})
\ No newline at end of file
screens/Plan.js
View file @
0afe3698
import
React
,
{
useEffect
}
from
'
react
'
;
import
{
View
,
Text
,
Image
,
ScrollView
,
TouchableOpacity
,
StyleSheet
,
ImageBackground
}
from
'
react-native
'
;
import
{
firebase
}
from
'
../config
'
;
// Make sure to import 'firestore' and 'firebase' correctly.
import
{
View
,
Text
,
TouchableOpacity
,
StyleSheet
,
ImageBackground
,
ScrollView
}
from
'
react-native
'
;
import
{
useNavigation
}
from
'
@react-navigation/native
'
;
import
{
firestore
,
firebase
}
from
'
../config
'
;
// Make sure to import 'firestore' and 'firebase' correctly.
export
default
function
Plan
({
route
})
{
// Extract nutritionPlan from route.params
const
{
nutritionPlan
}
=
route
.
params
;
const
navigation
=
useNavigation
();
// Function to save the nutritionPlan to Firestor
const
savePlanToDatabase
=
async
(
nutritionPlan
)
=>
{
try
{
const
timestamp
=
firebase
.
firestore
.
FieldValue
.
serverTimestamp
();
const
data
=
{
nutritionPlan
:
nutritionPlan
,
date
:
timestamp
,
};
useEffect
(()
=>
{
savePlanToDatabase
();
},
[]);
const
docRef
=
await
firebase
.
firestore
().
collection
(
"
mealPlans
"
).
add
(
data
);
console
.
log
(
"
Meal plan saved with ID:
"
,
docRef
.
id
);
}
catch
(
error
)
{
console
.
error
(
'
Error saving Nutrition Plan to Firestore:
'
,
error
);
}
}
// Function to save the nutritionPlan to Firestore
const
savePlanToDatabase
=
(
nutritionPlan
)
=>
{
const
data
=
{
nutritionPlan
:
parseFloat
(
nutritionPlan
),
};
// Assuming you have a 'nutritionPlans' collection in your database
firebase
.
firestore
().
collection
(
"
nutritionPlans
"
).
add
(
data
);
};
return
(
<
ScrollView
contentContainerStyle
=
{
styles
.
container
}
>
<
ImageBackground
source
=
{
require
(
"
../assets/plan1.png
"
)}
resizeMode
=
"
cover
"
style
=
{
styles
.
image
}
>
<
View
style
=
{
styles
.
overlay
}
>
{
/* Nutrition Plan */
}
<
Text
style
=
{
styles
.
title
}
>
Nutrition
Plan
:
<
/Text
>
return
(
<
ScrollView
contentContainerStyle
=
{
styles
.
scrollViewContent
}
>
<
View
style
=
{
styles
.
container
}
>
<
ImageBackground
source
=
{
require
(
"
../assets/plan1.png
"
)}
resizeMode
=
"
cover
"
style
=
{
styles
.
image
}
>
<
View
style
=
{
styles
.
overlay
}
>
<
Text
style
=
{
styles
.
nutritionPlan
}
>
{
nutritionPlan
}
<
/Text
>
{
/* Save Plan Button */
}
<
TouchableOpacity
style
=
{
styles
.
button
}
onPress
=
{
savePlanToDatabase
}
>
<
Text
>
Save
Plan
<
/Text
>
{
/* Save Plan Button */
}
<
TouchableOpacity
style
=
{
styles
.
button
}
onPress
=
{
savePlanToDatabase
}
>
<
Text
style
=
{
styles
.
buttonText
}
>
Save
Plan
<
/Text
>
<
/TouchableOpacity
>
<
/View
>
<
/ImageBackground
>
<
/View
>
<
/ScrollView
>
);
}
const
styles
=
StyleSheet
.
create
({
container
:
{
padding
:
16
,
flex
:
1
,
},
scrollViewContent
:
{
minHeight
:
'
120%
'
,
// Set a minimum height to enable scrolling
},
image
:
{
...
...
@@ -72,13 +78,19 @@ const styles = StyleSheet.create({
marginTop
:
8
,
},
button
:
{
backgroundColor
:
"
#FF9DD2
"
,
backgroundColor
:
'
transparent
'
,
borderWidth
:
2
,
borderColor
:
'
#FF9DD2
'
,
// Pink border color
padding
:
12
,
borderRadius
:
8
,
alignItems
:
'
center
'
,
marginTop
:
16
,
},
buttonText
:
{
color
:
'
white
'
,
color
:
'
black
'
,
fontWeight
:
'
bold
'
,
fontSize
:
20
,
},
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment