Commit f3d0cca6 authored by Sasini Perera's avatar Sasini Perera

Merge branch 'master' of http://gitlab.sliit.lk/tmp-23-068/tmp-23-068 into suggestions_chatbot

parents ac8919d0 33c0cde8
......@@ -5,13 +5,11 @@ import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
import registerNNPushToken from 'native-notify';
import TabNavigator from "./navigation/TabNavigator";
import UsImage from "./screens/CaptureImage";
import US from "./screens/CaptureImage";
import Prescription from "./screens/CapturePrescription";
import Sidebar from "./screens/Sidebar";
import Nutrition from "./screens/Nutrition"
import Notification from "./screens/Notification";
import ChatbotScreen from "./screens/ChatbotScreen";
import WelcomeScreen from "./screens/Chat";
import FeedbackScreen from "./screens/Feedback";
......@@ -19,13 +17,29 @@ import Signup from "./screens/Signup";
import Signin from "./screens/Signin";
import BmiCalculator from "./screens/BmiCalculator";
import BmiRecords from "./screens/BmiRecords";
import BMI from "./screens/BMI";
import BloodReportCapture from "./screens/BloodReportCapture";
import Plan from "./screens/Plan";
import UserProfile from "./screens/UserProfile";
import MedHome from "./screens/MedHome";
import MyMed from "./screens/MyMed";
import MoodDetection from "./screens/MoodDetection";
import NutritionWelcome from "./screens/NutritionWelcome";
import MedicineWelcome from "./screens/MedicineWelcome";
import USWelcome from "./screens/USWelcome";
import MoodWelcome from "./screens/MoodWelcome";
import PreviousPlan from "./screens/PreviousPlan";
import SuggestionComponent from "./screens/SuggestionComponent";
import LineChartComponent from "./screens/Graph";
import NotificationInbox from "./screens/NotificationInbox";
import { LogBox } from 'react-native';
const Stack = createStackNavigator()
const Tab = createBottomTabNavigator();
LogBox.ignoreLogs(['Setting a timer']);
export default function App() {
registerNNPushToken(14166, '8pIb6JqSUszbTdAIturtcO');
......@@ -39,29 +53,34 @@ export default function App() {
>
<Stack.Screen name="TabNavigator" component={TabNavigator} />
<Stack.Screen name="Nutrition" component={Nutrition} />
<Stack.Screen name="UsImage" component={UsImage} />
<Stack.Screen name="US" component={US} />
<Stack.Screen name="Prescription" component={Prescription} />
<Stack.Screen name="Sidebar" component={Sidebar} />
<Stack.Screen name="ChatbotScreen" component={ChatbotScreen} />
<Stack.Screen name="Notification" component={Notification} />
<Stack.Screen name="WelcomeScreen" component={WelcomeScreen} />
<Stack.Screen name="FeedbackScreen" component={FeedbackScreen} />
<Stack.Screen name="BmiCalculator" component={BmiCalculator} />
<Stack.Screen name="BmiRecords" component={BmiRecords} />
<Stack.Screen name="BloodReportCapture" component={BloodReportCapture} />
<Stack.Screen name="Plan" component={Plan} />
<Stack.Screen name="bmi" component={BMI} />
<Stack.Screen name="mood" component={MoodDetection} />
<Stack.Screen name="PreviousPlan" component={PreviousPlan} />
<Stack.Screen name="NutritionWelcome" component={NutritionWelcome} />
<Stack.Screen name="MedicineWelcome" component={MedicineWelcome} />
<Stack.Screen name="USWelcome" component={USWelcome} />
<Stack.Screen name="MoodWelcome" component={MoodWelcome} />
<Stack.Screen name="Signup" component={Signup} />
<Stack.Screen name="Signin" component={Signin} />
<Stack.Screen name="UserProfile" component={UserProfile} />
<Stack.Screen name="MedHome" component={MedHome} />
<Stack.Screen name="MyMed" component={MyMed} />
<Stack.Screen name="SuggestionComponent" component={SuggestionComponent} />
<Stack.Screen name="Graph" component={LineChartComponent} />
<Stack.Screen name="NotificationInbox" component={NotificationInbox} />
</Stack.Navigator>
</NavigationContainer>
);
}
This diff is collapsed.
......@@ -6,7 +6,7 @@ import Nutrition from "../screens/Nutrition";
import UsImage from "../screens/CaptureImage";
import Prescription from "../screens/CapturePrescription";
import Sidebar from "../screens/Sidebar";
import Notification from "../screens/Notification";
import NotificationInbox from "../screens/NotificationInbox";
const Tab = createBottomTabNavigator();
......@@ -19,7 +19,7 @@ const tabs = [
},
{
name: "Notification",
component: Notification,
component: NotificationInbox,
source: require("../assets/event-icon.png"),
label: "Notification",
},
......
......@@ -15,6 +15,7 @@
"@react-navigation/stack": "^6.3.20",
"axios": "^1.6.0",
"expo": "~48.0.18",
"expo-camera": "~13.2.1",
"expo-dev-client": "~2.2.1",
"expo-device": "~5.2.1",
"expo-image-picker": "^14.1.1",
......@@ -5988,6 +5989,14 @@
"prop-types": "*"
}
},
"node_modules/dequal": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dequal/-/dequal-1.0.1.tgz",
"integrity": "sha512-Fx8jxibzkJX2aJgyfSdLhr9tlRoTnHKrRJuu2XHlAgKioN2j19/Bcbe0d4mFXYZ3+wpE2KVobUVTfDutcD17xQ==",
"engines": {
"node": ">=6"
}
},
"node_modules/destroy": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
......@@ -6294,6 +6303,43 @@
"url-parse": "^1.5.9"
}
},
"node_modules/expo-camera": {
"version": "13.2.1",
"resolved": "https://registry.npmjs.org/expo-camera/-/expo-camera-13.2.1.tgz",
"integrity": "sha512-fZdRyF402jJGGmLVlumrLcr5Em9+Y2SO1MIlxLBtHXnybyHbTRMRAbzVapKX1Aryfujqadh+Kl+sdsWYkMuJjg==",
"dependencies": {
"@koale/useworker": "^4.0.2",
"invariant": "^2.2.4"
},
"peerDependencies": {
"expo": "*"
}
},
"node_modules/expo-camera/node_modules/@koale/useworker": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/@koale/useworker/-/useworker-4.0.2.tgz",
"integrity": "sha512-xPIPADtom8/3/4FLNj7MvNcBM/Z2FleH85Fdx2O869eoKW8+PoEgtSVvoxWjCWMA46Sm9A5/R1TyzNGc+yM0wg==",
"dependencies": {
"dequal": "^1.0.0"
},
"peerDependencies": {
"react": "^16.8.0"
}
},
"node_modules/expo-camera/node_modules/react": {
"version": "16.14.0",
"resolved": "https://registry.npmjs.org/react/-/react-16.14.0.tgz",
"integrity": "sha512-0X2CImDkJGApiAlcf0ODKIneSwBPhqJawOa5wCtKbu7ZECrmS26NvtSILynQ66cgkT/RJ4LidJOc3bUESwmU8g==",
"peer": true,
"dependencies": {
"loose-envify": "^1.1.0",
"object-assign": "^4.1.1",
"prop-types": "^15.6.2"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/expo-constants": {
"version": "14.2.1",
"resolved": "https://registry.npmjs.org/expo-constants/-/expo-constants-14.2.1.tgz",
......
......@@ -41,6 +41,7 @@ const BMI = () => {
placeholder="Enter Weight (in kg)"
onChangeText={setWeight}
keyboardType="numeric"
required
/>
<Text style={styles.label}>Height</Text>
<TextInput
......@@ -48,6 +49,7 @@ const BMI = () => {
placeholder="Enter Height (in cm)"
onChangeText={setHeight}
keyboardType="numeric"
required
/>
<TouchableOpacity style={styles.button} onPress={navigateToBmiCalculator}>
<Text style={styles.buttonText}>Calculate BMI</Text>
......
......@@ -45,7 +45,7 @@ export default BmiCalculator;
import React, { useState, useEffect } from "react";
import { View, Text, StyleSheet, Button ,TouchableOpacity} from "react-native";
import { View, Text, StyleSheet, Button ,TouchableOpacity,ImageBackground} from "react-native";
import { firebase } from "../config";
import { useNavigation } from "@react-navigation/native";
......@@ -126,7 +126,8 @@ const BmiCalculator = ({ route }) => {
return (
<View style={styles.container}>
<ImageBackground source={require("../assets/backnew.png")} resizeMode="cover" style={styles.image}>
<View style={styles.overlay}>
<Text style={styles.label}>BMI Value:</Text>
<Text style={styles.result}>{bmi}</Text>
......@@ -139,6 +140,8 @@ const BmiCalculator = ({ route }) => {
<TouchableOpacity style={styles.navibutton} onPress={NavigateToNutrition}>
<Text style={styles.buttonText}>Get Nutrition Plan</Text>
</TouchableOpacity>
</View>
</ImageBackground>
</View>
);
};
......@@ -146,15 +149,26 @@ const BmiCalculator = ({ route }) => {
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
},
image: {
flex: 1,
justifyContent: 'center',
},
overlay: {
flex: 1,
backgroundColor: 'rgba(0, 0, 0, 0.3)',
padding: 20,
justifyContent: 'center',
alignItems: "center",
},
button: {
backgroundColor: "pink",
borderRadius: 5,
padding: 10,
marginTop: 20,
marginTop: 60,
width: 200,
},
......
......@@ -63,14 +63,14 @@ export default BmiRecords;
import React, { useState, useEffect } from "react";
import { View, Text, FlatList, StyleSheet, ScrollView } from "react-native";
import React, { useState, useEffect } from "react";
import { View, Text, FlatList, StyleSheet,ImageBackground } from "react-native";
import { firebase } from "../config";
const BmiRecords = () => {
const [bmiRecords, setBmiRecords] = useState([]);
useEffect(() => {
/*useEffect(() => {
// Fetch BMI records from the database
firebase
.firestore()
......@@ -89,9 +89,39 @@ const BmiRecords = () => {
setBmiRecords(records);
});
}, []);
*/
useEffect(() => {
// Fetch BMI records from the database
const unsubscribe = firebase
.firestore()
.collection("bmiRecords")
.orderBy("date", "desc")
.onSnapshot((querySnapshot) => {
const records = [];
querySnapshot.forEach((doc) => {
const { bmi, date } = doc.data();
// Check if date is not null or undefined before converting to Date object
if (date) {
records.push({
id: doc.id,
bmi,
date: date.toDate(),
});
} else {
console.warn("Skipping a record with null date:", doc.id);
}
});
setBmiRecords(records);
});
// Unsubscribe from the snapshot listener when the component unmounts
return () => unsubscribe();
}, []);
return (
<ScrollView style={styles.container}>
<View style={styles.container}>
<ImageBackground source={require("../assets/backnew.png")} resizeMode="cover" style={styles.image}>
<Text style={styles.label}>BMI Records:</Text>
<FlatList
data={bmiRecords}
......@@ -103,24 +133,26 @@ const BmiRecords = () => {
</View>
)}
/>
</ScrollView>
</ImageBackground>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
paddingHorizontal: 16, // Add some horizontal padding
paddingHorizontal: 10, // Add some horizontal padding
paddingTop: 10, // Add some top padding
},
label: {
fontSize: 24,
fontWeight: "bold",
paddingTop: 60,
marginBottom: 10,
},
recordItem: {
marginVertical: 10,
backgroundColor: "#FFFFFF", // Add a background color
backgroundColor: "transparent", // Add a background color
padding: 10, // Add some padding to each record
borderRadius: 8, // Add border radius for rounded corners
shadowColor: "#000000", // Add shadow (if desired)
......
......@@ -59,54 +59,42 @@ const Prescription = () => {
const extractTextFromImage = async () => {
if (image) {
setLoading(true);
const apiUrl = 'http://192.168.8.100:5000/extract'; // Replace with your Flask server URL
const apiUrl = 'https://medicine-name-extractor-1003-d5d4d739612b.herokuapp.com/extract'; // Replace with your Flask server URL
const formData = new FormData();
formData.append('image', {
uri: image,
type: 'image/jpeg',
type: 'image/jpeg', // or 'image/png' based on the actual image type
name: 'image.jpg',
});
try {
const response = await axios.post(apiUrl, formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
// Check if the response contains the expected structure
if (response.data && Array.isArray(response.data.extracted_medicines)) {
const { extracted_medicines } = response.data;
setExtractedMedicineData(extracted_medicines);
// Fetch the existing data from Firestore
const userDetailsRef = firebase.firestore().collection("userDetails").doc(email);
const userDetailsSnapshot = await userDetailsRef.get();
const existingData = userDetailsSnapshot.data();
// Update existing records and add new records
const updatedData = existingData?.extractedMedicines || [];
for (const newMedicine of extracted_medicines) {
const index = updatedData.findIndex(
(record) => record.medicine_name === newMedicine.medicine_name
);
if (index !== -1) {
// If a medicine with the same name exists, replace it
updatedData[index] = newMedicine;
} else {
// If not, add a new record
updatedData.push(newMedicine);
}
}
// Update the Firestore document with the updated data
await userDetailsRef.set({ extractedMedicines: updatedData });
console.log("Data saved to Firestore", updatedData);
const db = firebase.firestore(); // Get Firestore instance
// Loop through extracted medicines and save data to Firestore
extracted_medicines.forEach(async (medicine) => {
try {
await db.collection('userDetails').add({
email,
medicine_name: medicine.medicine_name,
dosages: medicine.dosages.join(', '), // Convert dosages array to a comma-separated string
side_effects: medicine.side_effects,
});
} catch (error) {
console.error('Error saving data to Firestore:', error);
}
});
} else {
console.error('Invalid response format from Flask server.');
}
......@@ -118,6 +106,7 @@ const Prescription = () => {
}
};
return (<ScrollView contentContainerStyle={styles.container}>
<View style={styles.imageContainer}>
......
......@@ -14,11 +14,36 @@ const LineChartComponent = () => {
const { AC, BPD, FL, HC } = extractedValues;
const GA = age;
const data1 = [
{ x: 0, y: 0 }, // Starting point at (0, 0)
{ x: GA, y: parseFloat(BPD.replace('mm', '')) },
const gaData = [
{ value: 0, label: '0' },
{ value: 18, label: '18' },
{ value: 19, label: '19' },
{ value: 20, label: '20' },
{ value: 21, label: '21' },
{ value: 22, label: '22' },
{ value: 23, label: '23' },
{ value: 24, label: '24' },
{ value: 25, label: '25' },
{ value: 26, label: '26' },
{ value: 27, label: '27' },
{ value: 28, label: '28' },
{ value: 29, label: '29' },
{ value: 30, label: '30' },
{ value: 31, label: '31' },
{ value: 32, label: '32' },
{ value: 33, label: '33' },
{ value: 34, label: '34' },
{ value: 35, label: '35' },
{ value: 36, label: '36' },
{ value: 37, label: '37' },
{ value: 38, label: '38' },
];
const data1 = gaData.map((gaDataItem) => ({
x: gaDataItem.value,
y: GA === gaDataItem.value ? parseFloat(BPD.replace('mm', '')) : null,
}));
const upperLimitData1 = [
{ x: 0, y: 0 }, // Upper limit data
{ x: 18, y: 44.1 },
......@@ -69,10 +94,10 @@ const LineChartComponent = () => {
{ x: 38, y: 88.2 }, // Set the limit for the entire range
];
const data2 = [
{ x: 0, y: 0 }, // Starting point at (0, 0)
{ x: GA, y: parseFloat(FL.replace('mm', '')) },
];
const data2 = gaData.map((gaDataItem) => ({
x: gaDataItem.value,
y: GA === gaDataItem.value ? parseFloat(FL.replace('mm', '')) : null,
}));
const upperLimitData2 = [
{ x: 0, y: 0 }, // Upper limit data
......@@ -124,10 +149,10 @@ const LineChartComponent = () => {
{ x: 38, y: 69.8 },
];
const data3 = [
{ x: 0, y: 0 }, // Starting point at (0, 0)
{ x: GA, y: parseFloat(HC.replace('mm', '')) },
];
const data3 = gaData.map((gaDataItem) => ({
x: gaDataItem.value,
y: GA === gaDataItem.value ? parseFloat(HC.replace('mm', '')) : null,
}));
const upperLimitData3 = [
{ x: 0, y: 0 }, // Upper limit data
......@@ -179,10 +204,10 @@ const LineChartComponent = () => {
{ x: 38, y: 322.6 },
];
const data4 = [
{ x: 0, y: 0 }, // Starting point at (0, 0)
{ x: GA, y: parseFloat(AC.replace('mm', '')) },
];
const data4 = gaData.map((gaDataItem) => ({
x: gaDataItem.value,
y: GA === gaDataItem.value ? parseFloat(AC.replace('mm', '')) : null,
}));
const upperLimitData4 = [
{ x: 0, y: 0 }, // Upper limit data
......@@ -244,7 +269,7 @@ const LineChartComponent = () => {
{ x: 'Jun', y: 35 },
];
const chartWidth = 50 * data5.length; // Adjust the factor as needed
const chartWidth = 50 * lowerLimitData4.length; // Adjust the factor as needed
const chartHeight = 200; // You can set this to any desired height
const chartConfig = {
......@@ -265,7 +290,7 @@ const LineChartComponent = () => {
<LineChart
data={{
labels: [0, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38],
labels: gaData.map((gaDataItem) => gaDataItem.label),
datasets: [
{
data: data1.map((item) => item.y),
......
import React from 'react';
import { View, Text, Button, StyleSheet } from 'react-native';
const MedHome = ({ navigation }) => {
return (
<View style={styles.container}>
<Text style={styles.title}>My Health App</Text>
<Button
title="Extract Medicine Names"
onPress={() => navigation.navigate('Prescription')}
/>
<Button
title="My Med Records"
onPress={() => navigation.navigate('MyMed')}
/>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
title: {
fontSize: 24,
marginBottom: 20,
},
});
export default MedHome;
import { ImageBackground, StyleSheet, Text, View, TouchableOpacity } from 'react-native';
import React, { Component } from 'react'
import { useNavigation } from "@react-navigation/native";
const image = {};
export default function MedicineWelcome () {
const navigation = useNavigation();
const navigateToMedicine = () => {
navigation.navigate("Prescription");
};
const navigateToMedicineRecord = () => {
navigation.navigate("MyMed");
};
return (
<View style={styles.container}>
<ImageBackground source={require("../assets/MedicineScreen.png")} resizeMode="cover" style={styles.image}>
<View style={styles.overlay}>
<View style={styles.actionButtons}>
<TouchableOpacity style={styles.actionButton} onPress={navigateToMedicine}>
<Text style={styles.buttonText}>Extract Medicine Names</Text>
</TouchableOpacity>
<TouchableOpacity style={[styles.actionButton, { marginTop: 20 }]} onPress={navigateToMedicineRecord} >
<Text style={styles.buttonText}>My Med Records</Text>
</TouchableOpacity>
</View>
</View>
</ImageBackground>
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
image: {
flex: 1,
justifyContent: 'center',
},
overlay: {
flex: 1,
backgroundColor: 'rgba(0, 0, 0, 0.3)',
padding: 20,
justifyContent: 'center',
},
actionButtons: {
justifyContent: 'space-around',
marginTop: 500,
},
actionButton: {
backgroundColor: 'transparent',
borderWidth: 2,
borderColor: '#FF9DD2', // Pink border color
paddingVertical: 20, // Increase button size by adjusting padding
paddingHorizontal: 40, // Increase button size by adjusting padding
borderRadius: 10,
justifyContent: 'center',
alignItems: 'center',
},
buttonText: {
color: 'white',
fontWeight: 'bold',
},
});
/*
import React, { useState, useEffect } from 'react';
import { View, Text, TouchableOpacity, Image, TextInput, Alert, StyleSheet ,ImageBackground,ScrollView} from 'react-native';
import { Camera } from 'expo-camera';
export default function MoodDetection() {
const [capturedImage, setCapturedImage] = useState(null);
const [userAnswer, setUserAnswer] = useState('');
const [cameraPermission, setCameraPermission] = useState(null);
const [camera, setCamera] = useState(null);
const questionBank = [
'How would you rate your overall mood today? (1-10)',
'On a scale of 1 to 10, how well are you managing stress during your pregnancy?',
'How would you rate your happiness level at this moment? (1-10)',
'On a scale of 1 to 10, how confident do you feel about your pregnancy?',
'On a scale of 1 to 10, how well are you sleeping during your pregnancy?',
'How would you rate your excitement about becoming a mother? (1-10)',
'How would you rate your energy level at this moment? (1-10)',
'How excited are you about the upcoming addition to your family? (Rate 1-10)',
'How are you feeling today?',
'What is your mood like right now?',
'Tell me about your emotions at this moment.',
// Add more questions as needed
];
const [currentQuestionIndex, setCurrentQuestionIndex] = useState(0);
useEffect(() => {
(async () => {
const { status } = await Camera.requestPermissionsAsync();
setCameraPermission(status === 'granted');
})();
}, []);
// Automatically change the question when the component is rendered
useEffect(() => {
// Generate a random question index
const randomIndex = Math.floor(Math.random() * questionBank.length);
setCurrentQuestionIndex(randomIndex);
}, []);
const captureImage = async () => {
if (!cameraPermission) {
Alert.alert('Permission Required', 'Please grant camera permission to capture an image.');
return;
}
try {
if (camera) {
const photo = await camera.takePictureAsync();
setCapturedImage(photo.uri);
} else {
Alert.alert('Error', 'Camera not available.');
}
} catch (error) {
Alert.alert('Error', 'Failed to capture an image. Please try again.');
}
};
return (
<ScrollView contentContainerStyle={styles.scrollViewContent}>
<View style={styles.container}>
<ImageBackground source={require("../assets/Nutritionbackground.png")} resizeMode="cover" style={styles.image}>
<View style={styles.overlay}>
<Text style={styles.title}>Mood Detection</Text>
<Text style={styles.questionText}>{questionBank[currentQuestionIndex]}</Text>
<TextInput
style={styles.answerInput}
placeholder="Type your answer here"
value={userAnswer}
onChangeText={(text) => setUserAnswer(text)}
/>
<Camera
style={styles.camera}
type={Camera.Constants.Type.front}
ref={(ref) => setCamera(ref)}
/>
{capturedImage && (
<Image source={{ uri: capturedImage }} style={styles.resultImage} />
)}
<TouchableOpacity style={styles.button} onPress={captureImage}>
<Text style={styles.buttonText} >Analyze Mood</Text>
</TouchableOpacity>
</View>
</ImageBackground>
</View>
</ScrollView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
scrollViewContent: {
minHeight: '100%', // Set a minimum height to enable scrolling
},
overlay: {
flex: 1,
backgroundColor: 'rgba(0, 0, 0, 0.3)',
alignItems: "center",
},
image: {
flex: 1,
justifyContent: 'center',
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginTop: 95, // Adjusted margin to move the title to the top
},
questionText: {
fontSize: 18,
marginBottom: 20,
paddingRight:10,
paddingLeft:10,
marginTop: 10,
},
camera: {
flex: 1,
marginTop: 150,
width: '80%',
},
answerInput: {
width: '80%',
borderWidth: 1,
borderColor: 'gray',
padding: 10,
},
resultImage: {
width: 200,
height: 200,
marginTop: 170,
},
button: {
borderRadius: 5,
backgroundColor: 'transparent',
borderWidth: 2,
borderColor: '#FF9DD2', // Pink border color
paddingVertical: 20, // Increase button size by adjusting padding
paddingHorizontal: 40, // Increase button size by adjusting padding
borderRadius: 10,
justifyContent: 'center',
alignItems: 'center',
marginTop: 40,
width: '70%',
},
buttonText: {
color: 'black',
fontWeight: 'bold',
},
});
*/
import React, { useState, useEffect } from 'react';
import { View, Text, TouchableOpacity, Image, TextInput, Alert, StyleSheet,ImageBackground } from 'react-native';
import { Camera } from 'expo-camera';
export default function MoodDetection() {
const [capturedImage, setCapturedImage] = useState(null);
const [userAnswer, setUserAnswer] = useState('');
const [cameraPermission, setCameraPermission] = useState(null);
const [camera, setCamera] = useState(null);
const questionBank = [
'How would you rate your overall mood today? (1-10)',
'On a scale of 1 to 10, how well are you managing stress during your pregnancy?',
'How would you rate your happiness level at this moment? (1-10)',
'On a scale of 1 to 10, how confident do you feel about your pregnancy?',
'On a scale of 1 to 10, how well are you sleeping during your pregnancy?',
'How would you rate your excitement about becoming a mother? (1-10)',
'How would you rate your energy level at this moment? (1-10)',
'How excited are you about the upcoming addition to your family? (Rate 1-10)',
'How are you feeling today?',
'What is your mood like right now?',
'Tell me about your emotions at this moment.',
];
const [currentQuestionIndex, setCurrentQuestionIndex] = useState(0);
useEffect(() => {
(async () => {
const { status } = await Camera.requestPermissionsAsync();
setCameraPermission(status === 'granted');
})();
}, []);
useEffect(() => {
// Generate a random question index
const randomIndex = Math.floor(Math.random() * questionBank.length);
setCurrentQuestionIndex(randomIndex);
}, []);
const captureImage = async () => {
if (!cameraPermission) {
Alert.alert('Permission Required', 'Please grant camera permission to capture an image.');
return;
}
try {
if (camera) {
const photo = await camera.takePictureAsync();
setCapturedImage(photo.uri);
} else {
Alert.alert('Error', 'Camera not available.');
}
} catch (error) {
Alert.alert('Error', 'Failed to capture an image. Please try again.');
}
};
return (
<View style={styles.container}>
<ImageBackground source={require("../assets/Nutritionbackground.png")} resizeMode="cover" style={styles.image}>
<View style={styles.overlay}>
<Text style={styles.title}>Mood Detection</Text>
<Text style={styles.questionText}>{questionBank[currentQuestionIndex]}</Text>
<TextInput
style={styles.answerInput}
placeholder="Type your answer here"
value={userAnswer}
onChangeText={(text) => setUserAnswer(text)}
/>
<Camera
style={{ width: 1, height: 1, position: 'absolute' }}
type={Camera.Constants.Type.front}
ref={(ref) => setCamera(ref)}
/>
{capturedImage && (
<Image source={{ uri: capturedImage }} style={styles.resultImage} />
)}
<TouchableOpacity style={styles.button} onPress={captureImage}>
<Text style={styles.buttonText} >Analyze Mood</Text>
</TouchableOpacity>
</View>
</ImageBackground>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
overlay: {
flex: 1,
backgroundColor: 'rgba(0, 0, 0, 0.3)',
alignItems: "center",
},
image: {
flex: 1,
justifyContent: 'center',
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginTop: 95, // Adjusted margin to move the title to the top
},
questionText: {
fontSize: 18,
marginBottom: 20,
paddingRight:10,
paddingLeft:10,
marginTop: 10,
},
camera: {
flex: 1,
width: '100%',
},
answerInput: {
width: '80%',
borderWidth: 1,
borderColor: 'gray',
padding: 10,
},
resultImage: {
width: 200,
height: 200,
marginTop: 170,
},
button: {
borderRadius: 5,
backgroundColor: 'transparent',
borderWidth: 2,
borderColor: '#FF9DD2', // Pink border color
paddingVertical: 20, // Increase button size by adjusting padding
paddingHorizontal: 40, // Increase button size by adjusting padding
borderRadius: 10,
justifyContent: 'center',
alignItems: 'center',
marginBottom: 150,
marginTop: 90,
width: '70%',
},
buttonText: {
color: 'black',
fontWeight: 'bold',
},
});
import { ImageBackground, StyleSheet, Text, View, TouchableOpacity } from 'react-native';
import React, { Component } from 'react'
import { useNavigation } from "@react-navigation/native";
const image = {};
export default function MoodWelcome () {
const navigation = useNavigation();
const navigateToMood = () => {
navigation.navigate("mood");
};
return (
<View style={styles.container}>
<ImageBackground source={require("../assets/MoodScreen.png")} resizeMode="cover" style={styles.image}>
<View style={styles.overlay}>
<View style={styles.actionButtons}>
<TouchableOpacity style={styles.actionButton} onPress={navigateToMood}>
<Text style={styles.buttonText}>Let's Start</Text>
</TouchableOpacity>
</View>
</View>
</ImageBackground>
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
image: {
flex: 1,
justifyContent: 'center',
},
overlay: {
flex: 1,
backgroundColor: 'rgba(0, 0, 0, 0.3)',
padding: 20,
justifyContent: 'center',
},
actionButtons: {
justifyContent: 'space-around',
marginTop: 500,
},
actionButton: {
backgroundColor: 'transparent',
borderWidth: 2,
borderColor: '#FF9DD2', // Pink border color
paddingVertical: 20, // Increase button size by adjusting padding
paddingHorizontal: 40, // Increase button size by adjusting padding
borderRadius: 10,
justifyContent: 'center',
alignItems: 'center',
},
buttonText: {
color: 'black',
fontSize: 20,
fontWeight: 'bold',
},
});
import React, { useState, useEffect } from 'react';
import { View, Text, FlatList, StyleSheet } from 'react-native';
import { firebase } from '../config';
import AsyncStorage from '@react-native-async-storage/async-storage';
const MyMed = ({ route }) => {
const [userDetails, setUserDetails] = useState([]);
const [email, setEmail] = useState('');
useEffect(() => {
// Retrieve the email from local storage
AsyncStorage.getItem('userEmail')
.then(result => {
if (result) {
setEmail(result);
}
})
.catch(error => {
console.error('Error retrieving email from local storage:', error);
});
}, []);
useEffect(() => {
const db = firebase.firestore();
const userDetailsRef = db.collection('userDetails');
// Fetch user details based on the email
userDetailsRef
.where('email', '==', email)
.get()
.then((querySnapshot) => {
const data = [];
querySnapshot.forEach((doc) => {
data.push(doc.data());
});
setUserDetails(data);
})
.catch((error) => {
console.error('Error fetching user details:', error);
});
}, [email]);
return (
<View style={styles.container}>
<Text style={styles.title}>User Details for {email}</Text>
<FlatList
data={userDetails}
keyExtractor={(item) => item.id}
renderItem={({ item }) => (
<View style={styles.itemContainer}>
<Text>Medicine Name: {item.medicine_name}</Text>
<Text>Dosages: {item.dosages}</Text>
<Text>Side Effects: {item.side_effects}</Text>
</View>
)}
/>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 16,
},
title: {
fontSize: 24,
marginBottom: 16,
},
itemContainer: {
marginBottom: 16,
},
});
export default MyMed;
import React, { useState, useEffect } from "react"
import {
View,
Text,
FlatList,
StyleSheet,
TextInput,
TouchableOpacity,
Keyboard,
Pressable,
Alert,
Image,
TouchableHighlight,
} from "react-native"
import { firebase } from "../config"
import { FontAwesome } from "@expo/vector-icons"
import { useNavigation } from "@react-navigation/native"
import { SafeAreaView } from "react-native-safe-area-context"
import * as ImagePicker from "expo-image-picker"
import Swipeout from 'react-native-swipeout';
const MAX_LENGTH = 25;
const Notification = () => {
const [notifications, setNotifications] = useState([])
const [addData, setAddData] = useState("")
const [addDescription, setDescription] = useState("")
const [image, setImage] = useState(null)
const [uploading, setUploading] = useState(false)
const notificationReference = firebase.firestore().collection("notifications")
const navigation = useNavigation()
//fetch the data from firestore
useEffect(() => {
notificationReference
.orderBy("createdAt", "desc")
.onSnapshot((querySnapshot) => {
const notifications = []
querySnapshot.forEach((doc) => {
const { heading, description } = doc.data()
notifications.push({
id: doc.id,
heading,
description,
})
})
setNotifications(notifications)
})
}, [])
//alert box
const deleteNotification = (notification) => {
Alert.alert("Delete Details", "Do you want to delete this details?", [
{
text: "Cancel",
onPress: () => console.log("Cancel Pressed"),
style: "cancel",
},
{
text: "OK",
onPress: () => {
Delete(notification)
},
},
])
}
//delete a notification details from firestore database
const Delete = (notification) => {
notificationReference
.doc(notification.id)
.delete()
.then(() => {
alert("Deleted notification details successfully")
})
.catch((error) => {
alert(error)
})
}
//add a notification details item
const addNotification = () => {
//check if we have a notification item
if (addData && addData.length > 0) {
//get the timestamp
const timestamp = firebase.firestore.FieldValue.serverTimestamp()
const data = {
heading: addData,
description: addDescription,
createdAt: timestamp,
}
notificationReference
.add(data)
.then(() => {
setAddData("")
setDescription("")
//release keyboard
Keyboard.dismiss()
})
.catch((error) => {
alert(error)
})
}
}
const pickImage = async () => {
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: true,
aspect: [4, 3],
quantity: 1,
});
const source = {uri: result.uri}
console.log(source)
setImage(source)
};
const uploadImage = async () => {
setUploading(true);
try {
const response = await fetch(image.uri);
const blob = await response.blob();
const filename = image.uri.substring(image.uri.lastIndexOf("/") + 1);
var ref = firebase.storage().ref().child(filename);
await ref.put(blob);
Alert.alert("Photo uploaded...");
setImage(null);
} catch (error) {
console.error(error);
} finally {
setUploading(false);
}
};
return (
<View style={styles.subContainer}>
<View style={{ flex: 1 }}>
{/* <View style={styles.textAreaView}>
<Text style={{ fontWeight: "bold" }}>Notification</Text>
<TextInput
style={styles.textAreacontainer}
placeholder="Add your Weight"
maxLength={MAX_LENGTH}
placeholderTextColor="#aaaaaa"
onChangeText={(heading) => setAddData(heading)}
value={addData}
underlineColorAndroid="transparent"
autoCapitalize="none"
/>
</View>
<View style={styles.textAreaView}>
<Text style={{ fontWeight: "bold" }}>Details</Text>
<TextInput
multiline={true}
style={styles.textAreacontainer}
placeholder="Add your Height"
placeholderTextColor="#aaaaaa"
onChangeText={(description) => setDescription(description)}
value={addDescription}
underlineColorAndroid="transparent"
autoCapitalize="none"
/>
</View> */}
{/* <TouchableHighlight
style={styles.button}
underlayColor="#FF9DD2"
onPress={addNotification}
>
<Text style={styles.buttonText}>Get Notification</Text>
</TouchableHighlight> */}
<FlatList
data={notifications}
numColumns={1}
renderItem={({ item }) => (
<Swipeout
right={[
{
text: 'Delete',
backgroundColor: 'red',
onPress: () => deleteNotification(item), // Call your delete function here
},
]}
>
<Pressable
style={styles.container}
onPress={() => navigation.navigate("Prescription", { item })}
>
<FontAwesome
name="trash-o"
color="red"
onPress={() => deleteNotification(item)}
style={styles.recipieIcon}
/>
<View style={styles.innerContainer}>
<Text style={styles.itemHeading}>
{item.heading[0].toUpperCase() + item.heading.slice(1)}
</Text>
<Text style={styles.itemBody}>
{item.description[0].toUpperCase() + item.description.slice(1)}
</Text>
</View>
</Pressable>
</Swipeout>
)}
/>
</View>
</View>
)
}
export default Notification
const styles = StyleSheet.create({
notificationContainer: {
flex: 1,
alignItems: "center",
justifyContent: "center",
},
subContainer:{
backgroundColor: "white",
flex: 1,
justifyContent: "center",
},
container: {
padding: 15,
borderRadius: 15,
margin: 5,
marginHorizontal: 10,
flexDirection: "row",
alignItems: "center",
},
textAreacontainer: {
backgroundColor: "white",
padding: 10,
borderRadius: 5,
margin: 5,
marginHorizontal: 10,
flexDirection: "row",
alignItems: "center",
height: 48,
overflow: "hidden",
paddingLeft: 16,
flex: 1,
marginRight: 5,
},
textAreaView: {
backgroundColor: "#e5e5e5",
borderRadius: 15,
margin: 5,
marginHorizontal: 10,
flexDirection: "row",
alignItems: "center",
},
innerContainer: {
alignItems: "center",
flexDirection: "column",
marginLeft: 100,
},
itemHeading: {
fontWeight: "bold",
fontSize: 18,
marginRight: 30,
},
itemBody: {
fontWeight: "italic",
fontSize: 14,
marginRight: 30,
},
formContainer: {
flexDirection: "row",
height: 80,
marginTop: 100,
},
input: {
height: 48,
borderRadius: 5,
overflow: "hidden",
backgroundColor: "white",
paddingLeft: 16,
flex: 1,
marginRight: 5,
},
button: {
height: 47,
borderRadius: 5,
borderWidth: 2,
borderColor: "#FF9DD2",
width: 180,
alignItems: "center",
justifyContent: "center",
marginLeft: 210
},
recipieIcon: {
marginTop: 5,
fontSize: 20,
marginLeft: 14,
},
selectButton: {
borderRadius: 5,
width: 200,
height: 40,
backgroundColor: "pink",
alignItems: "center",
justifyContent: "center",
},
uploadButton: {
borderRadius: 5,
width: 200,
height: 40,
backgroundColor: "#FF9DD2",
alignItems: "center",
justifyContent: "center",
marginTop: 10
},
buttonText: {
color: "black",
fontSize: 14,
fontWeight: "bold",
},
imageContainer: {
marginTop: 2,
marginBottom: 100,
alignItems: "center",
},
})
import React, { useState, useEffect } from "react";
import { View, Text, StyleSheet } from "react-native";
import { getNotificationInbox } from 'native-notify';
const NotificationInbox = () => {
const [data, setData] = useState([]);
useEffect(() => {
const fetchData = async () => {
try {
const notifications = await getNotificationInbox(14166, '8pIb6JqSUszbTdAIturtcO');
setData(notifications);
} catch (error) {
console.error("Error fetching notifications: ", error);
}
};
fetchData();
}, []);
return (
<View style={styles.container}>
{data.map((item) => (
<View style={styles.notification} key={item.notification_id}>
<Text style={styles.title}>{item.title}</Text>
<Text style={styles.message}>{item.message}</Text>
</View>
))}
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 16,
backgroundColor: "#ffffff",
},
notification: {
borderWidth: 1,
borderColor: "#ccc",
borderRadius: 8,
padding: 16,
marginBottom: 16,
},
title: {
fontSize: 18,
fontWeight: "bold",
marginBottom: 8,
},
message: {
fontSize: 16,
color: "#333",
},
});
export default NotificationInbox;
import React, { useState } from 'react';
import { Button, Image, Text, View, TextInput, ScrollView,StyleSheet,TouchableOpacity } 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 pickImage = async (reportType) => {
const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();
......@@ -43,7 +42,7 @@ export default function Nutrition({ route }) {
name: 'image.jpg',
});
const apiUrl = reportType === 'CBC' ? 'http://192.168.1.100:5004/extract_hemoglobin' : 'http://192.168.1.100:5004/extract_glucose';
const apiUrl = reportType === 'CBC' ? 'https://nutrtition-predict-1004-bd09336777f6.herokuapp.com/extract_hemoglobin' : 'https://nutrtition-predict-1004-bd09336777f6.herokuapp.com/extract_glucose';
axios.post(apiUrl, formData, {
headers: {
......@@ -78,7 +77,7 @@ export default function Nutrition({ route }) {
console.log(parseFloat(resultOGTT));
console.log(parseFloat(bmi));
const apiUrl = 'http://192.168.1.100:5005/predict'; // Replace with the actual API endpoint URL of the other model
const apiUrl = 'https://planpredictdeploy.azurewebsites.net/predict'; // Replace with the actual API endpoint URL of the other model
axios
.post(apiUrl, {
......@@ -106,7 +105,7 @@ export default function Nutrition({ route }) {
const outputValue = response.data.prediction;
const customText = outputTexts[outputValue] || 'Default Text for Other Outputs';
// Format the meal plan text with line breaks
const formattedMealPlan = customText.replace(/;/g, '\n');
const formattedMealPlan = customText.replace(/;/g, '\n\n');
setOtherModelResult(formattedMealPlan);
// setOtherModelResult(customText);
console.log(response.data.prediction);
......@@ -124,96 +123,73 @@ export default function Nutrition({ route }) {
};
return (
<ScrollView contentContainerStyle={styles.scrollViewContent}>
<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>
<TouchableOpacity style={styles.navibutton} onPress={navigateToPlan}>
<Text style={styles.buttonText}>Get Nutrition Plan</Text>
</TouchableOpacity>
</View>
</View>
</View>
</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",
fontSize: 12,
overlay: {
flex: 1,
backgroundColor: 'rgba(0, 0, 0, 0.3)',
padding: 20,
justifyContent: 'center',
alignItems: "center",
},
bmiText:{
fontWeight: "bold",
fontSize: 15,
button: {
backgroundColor: "pink",
borderRadius: 5,
padding: 10,
marginTop: 60,
width: 200,
},
navibutton:{
......@@ -221,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 { ImageBackground, StyleSheet, Text, View, TouchableOpacity } from 'react-native';
import React, { Component } from 'react'
import { useNavigation } from "@react-navigation/native";
export default function NutritionWelcome () {
const navigation = useNavigation();
const navigateToNutrition = () => {
navigation.navigate("bmi");
};
const navigateToPreviousPlan = () => {
navigation.navigate("PreviousPlan");
};
return (
<View style={styles.container}>
<ImageBackground source={require("../assets/nutrition.png")} resizeMode="cover" style={styles.image}>
<View style={styles.overlay}>
<View style={styles.actionButtons}>
<TouchableOpacity style={styles.actionButton} onPress={navigateToNutrition}>
<Text style={styles.buttonText}>Nutrition Tracker</Text>
</TouchableOpacity>
<TouchableOpacity style={[styles.actionButton, { marginTop: 20 }]} onPress={navigateToPreviousPlan} >
<Text style={styles.buttonText}>Current Plan</Text>
</TouchableOpacity>
</View>
</View>
</ImageBackground>
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
image: {
flex: 1,
justifyContent: 'center',
},
overlay: {
flex: 1,
backgroundColor: 'rgba(0, 0, 0, 0.3)',
padding: 20,
justifyContent: 'center',
},
actionButtons: {
justifyContent: 'space-around',
marginTop: 500,
},
actionButton: {
backgroundColor: 'transparent',
borderWidth: 2,
borderColor: '#FF9DD2', // Pink border color
paddingVertical: 20, // Increase button size by adjusting padding
paddingHorizontal: 40, // Increase button size by adjusting padding
borderRadius: 10,
justifyContent: 'center',
alignItems: 'center',
},
buttonText: {
color: 'white',
fontWeight: 'bold',
},
});
import React, { useEffect } from 'react';
import { View, Text, Image, ScrollView, TouchableOpacity, StyleSheet } 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.
import AsyncStorage from '@react-native-async-storage/async-storage';
export default function Plan({ route }) {
// Extract nutritionPlan from route.params
const { nutritionPlan } = route.params;
const navigation = useNavigation();
const [email, setEmail] = useState('');
useEffect(() => {
// Retrieve the email from local storage
AsyncStorage.getItem('userEmail')
.then(result => {
if (result) {
setEmail(result);
}
})
.catch(error => {
console.error('Error retrieving email from local storage:', error);
});
}, []);
useEffect(() => {
savePlanToDatabase();
}, []);
// Function to save the nutritionPlan to Firestore
const savePlanToDatabase = (nutritionPlan) => {
const savePlanToDatabase = async (nutritionPlan) => {
try {
const timestamp = firebase.firestore.FieldValue.serverTimestamp();
const data = {
nutritionPlan: nutritionPlan,
date: timestamp,
};
const data = {
email:email,
nutritionPlan: nutritionPlan,
};
// Assuming you have a 'nutritionPlans' collection in your database
firebase.firestore().collection("nutritionPlans").add(data);
};
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);
}
}
return (
<ScrollView contentContainerStyle={styles.container}>
{/* Image at the top */}
<Image
source={require('../assets/bmi.jpg')}
style={styles.image}
/>
{/* 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}>
<View>
<Text style={styles.nutritionPlan}>{nutritionPlan}</Text>
{/* Save Plan Button */}
<TouchableOpacity style={styles.button} onPress={savePlanToDatabase}>
<Text>Save Plan</Text>
</View>
{/* 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,
justifyContent: 'center', // Center vertically
alignItems: 'center', // Center horizontally
},
scrollViewContent: {
minHeight: '120%', // Set a minimum height to enable scrolling
},
image: {
width: '100%',
height: 200, // Adjust the height as needed
flex: 1,
justifyContent: 'center',
},
overlay: {
flex: 1,
backgroundColor: 'rgba(0, 0, 0, 0.3)',
padding: 20,
justifyContent: 'center',
},
title: {
fontSize: 20,
fontWeight: 'bold',
marginTop: 16,
},
nutritionPlan: {
fontSize: 16,
marginTop: 8,
textAlign: 'center', // Center the text within the container
},
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,
},
});
import { ImageBackground, StyleSheet, Text, View, TouchableOpacity } from 'react-native';
import React, { Component } from 'react'
export default function PreviousPlan () {
return (
<View style={styles.container}>
<ImageBackground source={require("../assets/plan2.png")} resizeMode="cover" style={styles.image}>
<View style={styles.overlay}>
</View>
</ImageBackground>
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
image: {
flex: 1,
justifyContent: 'center',
},
overlay: {
flex: 1,
backgroundColor: 'rgba(0, 0, 0, 0.3)',
padding: 20,
justifyContent: 'center',
},
actionButtons: {
justifyContent: 'space-around',
marginTop: 500,
},
actionButton: {
backgroundColor: 'transparent',
borderWidth: 2,
borderColor: '#FF9DD2', // Pink border color
paddingVertical: 20, // Increase button size by adjusting padding
paddingHorizontal: 40, // Increase button size by adjusting padding
borderRadius: 10,
justifyContent: 'center',
alignItems: 'center',
},
buttonText: {
color: 'white',
fontWeight: 'bold',
},
});
import React, { useState } from "react";
import { View, TouchableOpacity, Text, StyleSheet } from "react-native";
import { View, TouchableOpacity, Text, StyleSheet, ImageBackground } from "react-native";
import { useNavigation } from "@react-navigation/native";
import backgroundImage from '../assets/nav.png';
const Sidebar = () => {
const [activeTab, setActiveTab] = useState(0);
......@@ -9,63 +10,75 @@ const Sidebar = () => {
const handleTabPress = (tabIndex) => {
setActiveTab(tabIndex);
if (tabIndex === 0) {
navigation.navigate("Profile");
navigation.navigate("UserProfile");
}if (tabIndex === 1){
navigation.navigate("Prescription");
navigation.navigate("MedicineWelcome");
}if (tabIndex === 2){
navigation.navigate("WelcomeScreen");
}if (tabIndex === 3){
navigation.navigate("bmi");
navigation.navigate("NutritionWelcome");
}if (tabIndex === 4){
navigation.navigate("UsImage");
navigation.navigate("USWelcome");
}if (tabIndex === 5){
navigation.navigate("MoodWelcome");
}
};
return (
<View style={styles.sidebar}>
<TouchableOpacity
style={[styles.tab, activeTab === 0 && styles.activeTab]}
onPress={() => handleTabPress(0)}
>
<Text style={styles.tabText}>Profile</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.tab, activeTab === 1 && styles.activeTab]}
onPress={() => handleTabPress(1)}
>
<Text style={styles.tabText}>My Medicines</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.tab, activeTab === 2 && styles.activeTab]}
onPress={() => handleTabPress(2)}
>
<Text style={styles.tabText}>Chat</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.tab, activeTab === 3 && styles.activeTab]}
onPress={() => handleTabPress(3)}
>
<Text style={styles.tabText}>Food Plans</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.tab, activeTab === 4 && styles.activeTab]}
onPress={() => handleTabPress(4)}
>
<Text style={styles.tabText}>Baby Growth</Text>
</TouchableOpacity>
</View>
<ImageBackground source={backgroundImage} style={styles.backgroundImage}>
<View style={styles.sidebar}>
<TouchableOpacity
style={[styles.tab, activeTab === 0 && styles.activeTab]}
onPress={() => handleTabPress(0)}
>
<Text style={styles.tabText}>Profile</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.tab, activeTab === 1 && styles.activeTab]}
onPress={() => handleTabPress(1)}
>
<Text style={styles.tabText}>My Medicines</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.tab, activeTab === 2 && styles.activeTab]}
onPress={() => handleTabPress(2)}
>
<Text style={styles.tabText}>Chat</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.tab, activeTab === 3 && styles.activeTab]}
onPress={() => handleTabPress(3)}
>
<Text style={styles.tabText}>Food Plans</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.tab, activeTab === 4 && styles.activeTab]}
onPress={() => handleTabPress(4)}
>
<Text style={styles.tabText}>Baby Growth</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.tab, activeTab === 5 && styles.activeTab]}
onPress={() => handleTabPress(5)}
>
<Text style={styles.tabText}>Mood Detection</Text>
</TouchableOpacity>
</View>
</ImageBackground>
);
};
const styles = StyleSheet.create({
backgroundImage: {
flex: 1,
resizeMode: "cover", // or "contain" for different resizing options
},
sidebar: {
flex: 1,
backgroundColor: "#F5F5F5",
paddingTop: 40,
paddingHorizontal: 20,
},
......@@ -75,10 +88,11 @@ const styles = StyleSheet.create({
borderRadius: 5,
},
activeTab: {
backgroundColor: "#FF9DD2",
backgroundColor: 'transparent',
borderWidth: 2,
borderColor: '#FF9DD2', // Pink border color
},
tabText: {
fontSize: 18,
fontWeight: "bold",
textAlign: "left",
......
import React, { useState, useEffect } from 'react';
import { View, Text, TextInput, Button, StyleSheet } from 'react-native';
import { View, Text, TextInput, Button, StyleSheet,ImageBackground,ScrollView} from 'react-native';
import { useNavigation } from '@react-navigation/native';
import { firebase } from '../config';
import { registerIndieID, unregisterIndieDevice } from 'native-notify';
......@@ -11,6 +11,7 @@ const SignIn = () => {
const [password, setPassword] = useState('');
const navigation = useNavigation();
const [users, setUsers] = useState([]);
const [extractedMedicines, setExtractedMedicines] = useState([]);
registerIndieID(email, 14166, '8pIb6JqSUszbTdAIturtcO');
useEffect(() => {
......@@ -39,17 +40,29 @@ const SignIn = () => {
fetchUserRecords();
}, []);
useEffect(() => {
if (email) {
// Your Firebase Firestore code to fetch extracted medicines
const userDetailsRef = firebase.firestore().collection("userDetails").doc(email);
userDetailsRef.get().then((doc) => {
if (doc.exists) {
const data = doc.data();
if (data.extractedMedicines) {
setExtractedMedicines(data.extractedMedicines);
}
}
});
}
}, [email]);
const handleSignIn = () => {
// Implement your sign-in logic here
// Compare the provided email and password with data in the users array
//const user = users.find((user) => user.email === email && user.password === password);
console.log('Email entered:', email);
console.log('Password entered:', password);
const user = users.find((user) => user.email.trim() === email.trim() && user.password === password);
if (user) {
if (email && password) {
// Perform sign-in logic when both email and password are provided
console.log('Sign In successful');
// Save the email to local storage
AsyncStorage.setItem('userEmail', email)
.then(() => {
......@@ -58,26 +71,31 @@ const SignIn = () => {
.catch(error => {
console.error('Error saving email to local storage:', error);
});
// After successful sign-in, navigate to the desired screen
navigation.navigate('TabNavigator');
} else {
// If either email or password is missing, display an error message to the user
console.error('Invalid credentials');
// Handle and display the error to the user
}
};
const goToSignUp = () => {
navigation.navigate('Signup');
};
function sendNotification() {
const sendNotification = () => {
// Build the title using extracted medicine names
const medicineNames = extractedMedicines.map((medicine) => medicine.medicine_name).join(', ');
axios.post(`https://app.nativenotify.com/api/indie/notification`, {
subID: email,
appId: 14166,
appToken: '8pIb6JqSUszbTdAIturtcO',
title: 'put your push notification title here as a string',
message: 'put your push notification message here as a string'
title: `Medicine Reminder: ${medicineNames}`,
message: 'Medicine taking time'
})
.then(response => {
// Handle the response if needed
......@@ -88,16 +106,51 @@ const SignIn = () => {
}
// Schedule the execution of sendNotification every 2 minutes (2 * 60,000 milliseconds)
const intervalId = setInterval(sendNotification, 60 * 60 * 1000);
// const intervalId = setInterval(sendNotification, 1 * 60 * 1000);
const scheduleNotifications = () => {
// Get the current time
const now = new Date();
// Calculate the time until the next scheduled time (8 am)
const msUntil8AM = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 8, 0, 0, 0) - now;
const msUntil2PM = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 14, 0, 0, 0) - now;
const msUntil8PM = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 20, 0, 0, 0) - now;
// Set timeouts for the scheduled times
setTimeout(() => {
sendNotification();
// Schedule the next notification for 2 pm
setInterval(sendNotification, 24 * 60 * 60 * 1000); // Repeat every 24 hours
}, msUntil8AM);
setTimeout(() => {
sendNotification();
}, msUntil2PM);
setTimeout(() => {
sendNotification();
}, msUntil8PM);
};
// Schedule notifications when the component mounts
useEffect(() => {
scheduleNotifications();
}, []);
return (
<ScrollView contentContainerStyle={styles.scrollViewContent}>
<View style={styles.container}>
<ImageBackground source={require("../assets/signNew.png")} resizeMode="cover" style={styles.image}>
<View style={styles.overlay}>
<View style={styles.subcontainer}>
<Text style={styles.label}>Email</Text>
<TextInput
style={styles.input}
placeholder="Enter your email"
value={email}
onChangeText={(text) => setEmail(text)}
required
/>
<Text style={styles.label}>Password</Text>
......@@ -107,12 +160,19 @@ const intervalId = setInterval(sendNotification, 60 * 60 * 1000);
value={password}
onChangeText={(text) => setPassword(text)}
secureTextEntry
required
/>
<View style={styles.subcontainerbut}>
<Button title="Sign In" onPress={handleSignIn} />
<Text style={styles.signUpText}>Don't have an account? Sign Up</Text>
<Button title="Sign Up" onPress={goToSignUp} />
</View>
</View>
</View>
</ImageBackground>
</View>
</ScrollView>
);
};
......@@ -120,21 +180,47 @@ const intervalId = setInterval(sendNotification, 60 * 60 * 1000);
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
margin: 20,
},
subcontainer:{
marginTop: -250,
},
scrollViewContent: {
minHeight: '120%', // Set a minimum height to enable scrolling
},
subcontainerbut:{
marginTop: 20,
},
image: {
flex: 1,
justifyContent: 'center',
},
overlay: {
flex: 1,
backgroundColor: 'rgba(0, 0, 0, 0.3)',
padding: 80,
justifyContent: 'center',
},
label: {
fontSize: 16,
marginBottom: 5,
},
input: {
width: '100%',
height: 40,
borderWidth: 1,
borderColor: 'gray',
marginBottom: 10,
padding: 10,
marginTop: 10,
},
signUpText: {
marginTop: 10,
......
import React, { useState, useEffect } from 'react';
import { View, TextInput, Button, StyleSheet, Text, ScrollView } from 'react-native';
import { View, TextInput, Button, StyleSheet, Text, ScrollView ,ImageBackground} from 'react-native';
import { useNavigation } from '@react-navigation/native';
import { firebase } from "../config";
import { Alert } from 'react-native';
......@@ -63,6 +63,7 @@ const Signup = ({ route }) => {
phone,
password,
});
navigation.navigate('Signin');
}
};
......@@ -80,15 +81,20 @@ const Signup = ({ route }) => {
return (
<View style={styles.body}>
<ScrollView>
<Text style={styles.pageTitle}>Sign Up</Text>
<ImageBackground source={require("../assets/signup.png")} resizeMode="cover" style={styles.image}>
<View style={styles.overlay}>
<View style={styles.container}>
<TextInput
placeholder="User Name"
value={userName}
onChangeText={(text) => setUserName(text)}
maxLength={MAX_LENGTH}
style={styles.input}
style={[styles.input, { width: 300 }]}
required
/>
</View>
<View style={styles.container}>
......@@ -97,7 +103,8 @@ const Signup = ({ route }) => {
value={email}
onChangeText={(text) => setEmail(text)}
keyboardType="email-address"
style={styles.input}
style={[styles.input, { width: 300 }]}
required
/>
</View>
<View style={styles.container}>
......@@ -106,7 +113,8 @@ const Signup = ({ route }) => {
value={phone}
onChangeText={(text) => setPhone(text)}
keyboardType="numeric"
style={styles.input}
style={[styles.input, { width: 300 }]}
required
/>
</View>
<View style={styles.container}>
......@@ -114,35 +122,53 @@ const Signup = ({ route }) => {
placeholder="Password"
value={password}
onChangeText={(password) => setPassword(password)}
style={styles.input}
style={[styles.input, { width: 300 }]}
required
/>
</View>
<View>
<Button title="Sign Up" onPress={saveUserData} />
</View>
<View>
<Button title="Sign In" onPress={handleSignIn} />
<Button title="Sign In" style={styles.actionButton} onPress={handleSignIn} />
</View>
</ScrollView>
</View>
</ImageBackground>
</View>
);
};
const styles = StyleSheet.create({
container: {
backgroundColor: "#e5e5e5",
padding: 15,
borderRadius: 15,
margin: 5,
marginHorizontal: 10,
flexDirection: "row",
alignItems: "center",
},
image: {
flex: 1,
justifyContent: 'center',
},
signin: {
marginTop: 20
},
overlay: {
flex: 1,
backgroundColor: 'rgba(0, 0, 0, 0.3)',
padding: 20,
justifyContent: 'center',
},
input: {
borderWidth: 1,
borderColor: 'gray',
padding: 10,
marginBottom: 20,
marginBottom: 10,
},
body: {
flex: 1,
......@@ -155,6 +181,10 @@ const styles = StyleSheet.create({
color: "#633974",
fontWeight: 'bold',
},
actionButton:{
marginTop: 20
} ,
});
export default Signup;
\ No newline at end of file
import { ImageBackground, StyleSheet, Text, View, TouchableOpacity } from 'react-native';
import React, { Component } from 'react'
import { useNavigation } from "@react-navigation/native";
const image = {};
export default function USWelcome () {
const navigation = useNavigation();
const navigateToUS = () => {
navigation.navigate("Us");
};
return (
<View style={styles.container}>
<ImageBackground source={require("../assets/us.png")} resizeMode="cover" style={styles.image}>
<View style={styles.overlay}>
<View style={styles.actionButtons}>
<TouchableOpacity style={styles.actionButton} onPress={navigateToUS}>
<Text style={styles.buttonText}>Baby Growth Predictor</Text>
</TouchableOpacity>
</View>
</View>
</ImageBackground>
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
image: {
flex: 1,
justifyContent: 'center',
},
overlay: {
flex: 1,
backgroundColor: 'rgba(0, 0, 0, 0.3)',
padding: 20,
justifyContent: 'center',
},
actionButtons: {
justifyContent: 'space-around',
marginTop: 500,
},
actionButton: {
backgroundColor: 'transparent',
borderWidth: 2,
borderColor: '#FF9DD2', // Pink border color
paddingVertical: 20, // Increase button size by adjusting padding
paddingHorizontal: 40, // Increase button size by adjusting padding
borderRadius: 10,
justifyContent: 'center',
alignItems: 'center',
},
buttonText: {
color: 'white',
fontWeight: 'bold',
},
});
import React, { useState, useEffect } from 'react';
import { View, Text, Button, StyleSheet, ScrollView } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import { firebase } from "../config";
import AsyncStorage from '@react-native-async-storage/async-storage';
const UserProfile = () => {
const navigation = useNavigation();
const [userName, setUserName] = useState('');
const [email, setEmail] = useState('');
const [phone, setPhone] = useState('');
useEffect(() => {
// Retrieve the email from local storage
AsyncStorage.getItem('userEmail')
.then(result => {
if (result) {
setEmail(result);
}
})
.catch(error => {
console.error('Error retrieving email from local storage:', error);
});
}, []);
useEffect(() => {
// Replace 'user_email@example.com' with the actual email you want to search for
const userEmail = email;
// Fetch the user data from Firebase Firestore based on email
const userCollection = firebase.firestore().collection("users");
const query = userCollection.where("email", "==", userEmail).limit(1);
query.get()
.then((querySnapshot) => {
if (!querySnapshot.empty) {
const userData = querySnapshot.docs[0].data();
setUserName(userData.userName);
setEmail(userData.email);
setPhone(userData.phone);
}
})
.catch(error => {
console.error('Error fetching user data:', error);
});
}, []);
return (
<View style={styles.body}>
<ScrollView>
<Text style={styles.pageTitle}>User Profile</Text>
<View style={styles.container}>
<Text>User Name: {userName}</Text>
</View>
<View style={styles.container}>
<Text>Email: {email}</Text>
</View>
<View style={styles.container}>
<Text>Phone Number: {phone}</Text>
</View>
</ScrollView>
</View>
);
};
const styles = StyleSheet.create({
container: {
backgroundColor: "#e5e5e5",
padding: 15,
borderRadius: 15,
margin: 5,
marginHorizontal: 10,
flexDirection: "row",
alignItems: "center",
},
input: {
borderWidth: 1,
borderColor: 'gray',
padding: 10,
marginBottom: 20,
},
body: {
flex: 1,
backgroundColor: "#ffffff",
},
pageTitle: {
fontSize: 35,
paddingTop: 50,
paddingLeft: 150,
color: "#633974",
fontWeight: 'bold',
},
});
export default UserProfile;
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