Commit 625720ae authored by Balasooriya B.M.D.D's avatar Balasooriya B.M.D.D

Merge branch 'UI_Changes' into 'master'

Ui changes

See merge request !24
parents 3f902d31 fea8c04f
......@@ -5,7 +5,6 @@ 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 Prescription from "./screens/CapturePrescription";
......@@ -22,14 +21,19 @@ 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";
const Stack = createStackNavigator()
const Tab = createBottomTabNavigator();
......@@ -61,24 +65,20 @@ export default function App() {
<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="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.Navigator>
</NavigationContainer>
);
}
......@@ -15,6 +15,7 @@
"@react-navigation/stack": "^6.3.20",
"axios": "^1.6.0",
"expo": "~48.0.18",
"expo-camera": "^13.6.0",
"expo-dev-client": "~2.2.1",
"expo-device": "~5.2.1",
"expo-image-picker": "^14.1.1",
......@@ -6294,6 +6295,17 @@
"url-parse": "^1.5.9"
}
},
"node_modules/expo-camera": {
"version": "13.6.0",
"resolved": "https://registry.npmjs.org/expo-camera/-/expo-camera-13.6.0.tgz",
"integrity": "sha512-8lxK15D2tuEZom9bhDMMqNPW+5241Ak4wIup/ebh4JekgOtSQ/egbq7qDn2FCFi+5vPFKX4nRsvGOuzfuzvmZA==",
"dependencies": {
"invariant": "^2.2.4"
},
"peerDependencies": {
"expo": "*"
}
},
"node_modules/expo-constants": {
"version": "14.2.1",
"resolved": "https://registry.npmjs.org/expo-constants/-/expo-constants-14.2.1.tgz",
......
......@@ -59,54 +59,42 @@ const Prescription = () => {
const extractTextFromImage = async () => {
if (image) {
setLoading(true);
const apiUrl = 'http://192.168.1.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}>
......
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 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 } from "react";
import { View, TouchableOpacity, Text, StyleSheet } from "react-native";
import React, { useState } from "react";
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,122 +10,18 @@ const Sidebar = () => {
const handleTabPress = (tabIndex) => {
setActiveTab(tabIndex);
if (tabIndex === 0) {
navigation.navigate("Profile");
navigation.navigate("UserProfile");
}if (tabIndex === 1){
navigation.navigate("MedicineWelcome");
navigation.navigate("MedHome");
}if (tabIndex === 2){
navigation.navigate("WelcomeScreen");
}if (tabIndex === 3){
navigation.navigate("NutritionWelcome");
navigation.navigate("bmi");
}if (tabIndex === 4){
navigation.navigate("USWelcome");
}if (tabIndex === 5){
navigation.navigate("MoodWelcome");
navigation.navigate("UsImage");
}
};
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>
<TouchableOpacity
style={[styles.tab, activeTab === 5 && styles.activeTab]}
onPress={() => handleTabPress(5)}
>
<Text style={styles.tabText}>Mood Detection</Text>
</TouchableOpacity>
</View>
);
};
const styles = StyleSheet.create({
sidebar: {
flex: 1,
backgroundColor: "#F5F5F5",
paddingTop: 40,
paddingHorizontal: 20,
},
tab: {
paddingVertical: 10,
marginBottom: 10,
borderRadius: 5,
},
activeTab: {
backgroundColor: "#FF9DD2",
},
tabText: {
fontSize: 18,
fontWeight: "bold",
textAlign: "left",
},
});
export default Sidebar;
*/
import React, { useState } from "react";
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);
const navigation = useNavigation();
const handleTabPress = (tabIndex) => {
setActiveTab(tabIndex);
if (tabIndex === 0) {
navigation.navigate("Profile");
}if (tabIndex === 1){
navigation.navigate("MedicineWelcome");
}if (tabIndex === 2){
navigation.navigate("WelcomeScreen");
}if (tabIndex === 3){
navigation.navigate("NutritionWelcome");
}if (tabIndex === 4){
navigation.navigate("USWelcome");
}if (tabIndex === 5){
navigation.navigate("MoodWelcome");
}
};
return (
......
......@@ -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,6 +40,22 @@ 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
......@@ -71,13 +88,16 @@ const SignIn = () => {
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,7 +108,36 @@ 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 (
<View style={styles.container}>
......
......@@ -63,6 +63,7 @@ const Signup = ({ route }) => {
phone,
password,
});
navigation.navigate('Signin');
}
};
......
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