Commit 0afe3698 authored by Yasara19's avatar Yasara19

Fixed Nutrition Plan Bug

parent 625720ae
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
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,
},
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment