Commit d8b561e1 authored by isuraem's avatar isuraem

changes_in_exercise

parent e307cf1f
...@@ -20,6 +20,7 @@ export default { ...@@ -20,6 +20,7 @@ export default {
EXERCISE_HOME: 'Exercise_Home', EXERCISE_HOME: 'Exercise_Home',
EXERCISE_FORM: 'Health_Form', EXERCISE_FORM: 'Health_Form',
EXERCISE_MAIN_MENU: 'Exercise_Home_Menu', EXERCISE_MAIN_MENU: 'Exercise_Home_Menu',
EXERCISE_MAIN_NEW_MENU: 'Exercise_Home_New_Menu',
EXERCISE_VIEW: 'Exercise_View', EXERCISE_VIEW: 'Exercise_View',
EXERCISE_ACTION_VIEW: 'Exercise_ACTION_View', EXERCISE_ACTION_VIEW: 'Exercise_ACTION_View',
EXERCISE_PROGRESS: 'Exercise_PROGRESS' EXERCISE_PROGRESS: 'Exercise_PROGRESS'
......
...@@ -68,7 +68,7 @@ function ExerciseNavigator() { ...@@ -68,7 +68,7 @@ function ExerciseNavigator() {
<> <>
<Stack.Screen name={ROUTES.EXERCISE_WELCOME} component={WelcomeExercise} key="ExerciseWelcome" /> <Stack.Screen name={ROUTES.EXERCISE_WELCOME} component={WelcomeExercise} key="ExerciseWelcome" />
<Stack.Screen name={ROUTES.EXERCISE_FORM} component={HealthFormExercise} key="ExerciseForm" /> <Stack.Screen name={ROUTES.EXERCISE_FORM} component={HealthFormExercise} key="ExerciseForm" />
<Stack.Screen name={ROUTES.EXERCISE_MAIN_MENU} component={MainMenuExercise} key="MainMenuExercise" /> <Stack.Screen name={ROUTES.EXERCISE_MAIN_NEW_MENU} component={MainMenuExercise} key="MainMenuNewExercise" />
</> </>
)} )}
</Stack.Navigator> </Stack.Navigator>
......
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { TextInput, View, SafeAreaView, KeyboardAvoidingView, TouchableOpacity, Text, Modal, StyleSheet, ScrollView, ToastAndroid, Image} from 'react-native'; import { TextInput, View, SafeAreaView, KeyboardAvoidingView, TouchableOpacity, Text, Modal, StyleSheet, ScrollView, ToastAndroid, Image } from 'react-native';
import { Formik } from 'formik'; import { Formik } from 'formik';
import CheckBox from '@react-native-community/checkbox'; import CheckBox from '@react-native-community/checkbox';
import LinearGradient from 'react-native-linear-gradient'; import LinearGradient from 'react-native-linear-gradient';
import { COLORS, IMGS, ROUTES } from '../../../constants'; import { COLORS, IMGS, ROUTES } from '../../../constants';
import Button from '../../../components/Button'; import Button from '../../../components/Button';
import { meternalHealthPredict, addInitialExercises } from '../../../services/exercises/index'; import { meternalHealthPredict, addInitialExercises, updateDeviceStatus } from '../../../services/exercises/index';
import AsyncStorage from '@react-native-async-storage/async-storage'; import AsyncStorage from '@react-native-async-storage/async-storage';
import database from '@react-native-firebase/database'; import database from '@react-native-firebase/database';
import Dot from '../../../assets/icons/dot.svg'; import Dot from '../../../assets/icons/dot.svg';
...@@ -20,34 +20,50 @@ const HealthFormExercise = (props) => { ...@@ -20,34 +20,50 @@ const HealthFormExercise = (props) => {
const [initialBodyTemp, setInitialBodyTemp] = useState(); const [initialBodyTemp, setInitialBodyTemp] = useState();
const [initialHeartRate, setInitialHeartRate] = useState(); const [initialHeartRate, setInitialHeartRate] = useState();
const [dataArray, setDataArray] = useState(null); const [dataArray, setDataArray] = useState(null);
const [isWearbleDevice, setIsWearbleDevice] = useState(false);
const [wearableModalVisible, setWearableModalVisible] = useState(false);
useEffect(() => { useEffect(() => {
// Reference to your Firebase Realtime Database if (isWearbleDevice) {
const databaseRef = database().ref('test'); // Reference to your Firebase Realtime Database
ToastAndroid.show('Data reading on device !', ToastAndroid.SHORT); const databaseRef = database().ref('test');
// Attach an asynchronous listener to read the data at our reference ToastAndroid.show('Data reading on device !', ToastAndroid.SHORT);
const onDataChange = (snapshot) => {
const data = snapshot.val();
setDataArray(data);
console.log("dada", data)
};
databaseRef.on('value', onDataChange); // Attach an asynchronous listener to read the data at our reference
const onDataChange = (snapshot) => {
const data = snapshot.val();
setDataArray(data);
console.log("data", data);
};
updateDeviceState()
databaseRef.on('value', onDataChange);
// Detach the listener when component unmounts // Detach the listener when component unmounts or when isWearableDevice changes
return () => { return () => {
databaseRef.off('value', onDataChange); databaseRef.off('value', onDataChange);
}; };
}, []); // Empty dependency array to run the effect only once }
const onSubmit = async (values) => { }, [isWearbleDevice]);
const updateDeviceState = async () => {
let userDataString = await AsyncStorage.getItem('userData'); let userDataString = await AsyncStorage.getItem('userData');
let userData = JSON.parse(userDataString); let userData = JSON.parse(userDataString);
console.log(userData) console.log(userData)
let respond = await meternalHealthPredict(userData.age, values.SystolicBP, values.DiastolicBP, values.Blood_glucose, values.BodyTemp, values.HeartRate); let deviceStatus = isWearbleDevice;
await updateDeviceStatus(userData._id, deviceStatus);
}
if (respond.data.prediction) { const onSubmit = async (values) => {
let userDataString = await AsyncStorage.getItem('userData');
let userData = JSON.parse(userDataString);
console.log(values)
let respond = await meternalHealthPredict(userData.age, values.SystolicBP, values.DiastolicBP, values.Blood_glucose, values.BodyTemp, values.HeartRate);
console.log(respond)
if (respond) {
ToastAndroid.show('Prediction getting successfully !', ToastAndroid.SHORT);
//0:"high risk",1:"low risk",2:"mid risk" //0:"high risk",1:"low risk",2:"mid risk"
let prediction = respond.data.prediction === "high risk" ? 0 : respond.data.prediction === "low risk" ? 1 : respond.data.prediction === "mid risk" ? 2 : null; let prediction = respond.data.prediction === "high risk" ? 0 : respond.data.prediction === "low risk" ? 1 : respond.data.prediction === "mid risk" ? 2 : null;
let predictionStatus = respond.data.prediction === "high risk" ? 20 : respond.data.prediction === "low risk" ? 0 : respond.data.prediction === "mid risk" ? 10 : null; let predictionStatus = respond.data.prediction === "high risk" ? 20 : respond.data.prediction === "low risk" ? 0 : respond.data.prediction === "mid risk" ? 10 : null;
...@@ -76,7 +92,7 @@ const HealthFormExercise = (props) => { ...@@ -76,7 +92,7 @@ const HealthFormExercise = (props) => {
return ( return (
<SafeAreaView > <SafeAreaView >
<Formik <Formik
initialValues={{ SystolicBP: '', DiastolicBP: '', Blood_glucose: '', BodyTemp: `${dataArray?.temp}` || '', HeartRate: `${dataArray?.bpm}` || '' }} initialValues={{ SystolicBP: '', DiastolicBP: '', Blood_glucose: '', BodyTemp: isWearbleDevice ? `${dataArray?.temp}` : '', HeartRate: isWearbleDevice ? `${dataArray?.bpm}` : '' }}
onSubmit={values => onSubmit(values)} onSubmit={values => onSubmit(values)}
enableReinitialize={true} enableReinitialize={true}
> >
...@@ -110,20 +126,53 @@ const HealthFormExercise = (props) => { ...@@ -110,20 +126,53 @@ const HealthFormExercise = (props) => {
//borderRadius style will help us make the Round Shape Image //borderRadius style will help us make the Round Shape Image
style={{ width: 72, height: 100, borderRadius: 20, paddingVertical: 10, paddingHorizontal: 10, marginLeft: 20, marginTop: 10 }} style={{ width: 72, height: 100, borderRadius: 20, paddingVertical: 10, paddingHorizontal: 10, marginLeft: 20, marginTop: 10 }}
/> />
<Image <Image
source={require("../../../assets/glucose.jpg")} source={require("../../../assets/glucose.jpg")}
//borderRadius style will help us make the Round Shape Image //borderRadius style will help us make the Round Shape Image
style={{ width: 72, height: 100, borderRadius: 20, paddingVertical: 10, paddingHorizontal: 10, marginLeft: 20, marginTop: 10 }} style={{ width: 72, height: 100, borderRadius: 20, paddingVertical: 10, paddingHorizontal: 10, marginLeft: 20, marginTop: 10 }}
/> />
</View> </View>
<View style={Styles.closeDiv}> <View style={Styles.closeDiv}>
<TouchableOpacity onPress={() => setModalVisible(false)}> <TouchableOpacity onPress={() => { setModalVisible(false); setWearableModalVisible(true) }}>
<Text style={Styles.closeButton}>Close</Text> <Text style={Styles.closeButton}>Close</Text>
</TouchableOpacity> </TouchableOpacity>
</View> </View>
</View> </View>
</View> </View>
</Modal> </Modal>
<Modal
animationType="slide"
transparent={true}
visible={wearableModalVisible}
onRequestClose={() => {
setWearableModalVisible(!wearableModalVisible);
}}
>
<View style={Styles.centeredView}>
<View style={Styles.modalView}>
<Text>Do you have a wearable device?</Text>
<View style={Styles.buttonRow}>
<TouchableOpacity
onPress={() => {
setIsWearbleDevice(true);
setWearableModalVisible(false);
}}
>
<Text style={Styles.closeButton}>Yes</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => {
setWearableModalVisible(false);
}}
>
<Text style={Styles.closeNewButton}>No</Text>
</TouchableOpacity>
</View>
</View>
</View>
</Modal>
<Text style={Styles.textInputLabel}>SystolicBP (mmHg)</Text> <Text style={Styles.textInputLabel}>SystolicBP (mmHg)</Text>
<View style={Styles.inputBox}> <View style={Styles.inputBox}>
...@@ -237,6 +286,13 @@ const Styles = StyleSheet.create({ ...@@ -237,6 +286,13 @@ const Styles = StyleSheet.create({
fontSize: 18, fontSize: 18,
fontWeight: 'bold', fontWeight: 'bold',
}, },
closeNewButton: {
marginTop: 10,
color: COLORS.danger,
textAlign: 'center',
fontSize: 18,
fontWeight: 'bold',
},
submitButton: { submitButton: {
backgroundColor: '#1899D6', backgroundColor: '#1899D6',
borderRadius: 10, // Adjust the border radius as needed borderRadius: 10, // Adjust the border radius as needed
...@@ -354,8 +410,17 @@ const Styles = StyleSheet.create({ ...@@ -354,8 +410,17 @@ const Styles = StyleSheet.create({
display: "flex", display: "flex",
flexDirection: "row", flexDirection: "row",
justifyContent: "center", justifyContent: "center",
alignItems:"center", alignItems: "center",
width: "100%" width: "100%"
},
buttonRow: {
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-around',
alignItems: 'center',
width: '100%',
marginTop: 10,
gap: 20
} }
}); });
import axios from "axios"; import axios from "axios";
const BASE_PATH = 'http://139.162.3.203:8010'; const BASE_PATH = 'http://16.170.242.186:8080';
const BASE_PATH2 = 'http://139.162.3.203:8070/api/mother'; const BASE_PATH2 = 'http://10.0.2.2:8070/api/mother';
import AsyncStorage from '@react-native-async-storage/async-storage'; import AsyncStorage from '@react-native-async-storage/async-storage';
//initialize payment API Call
export let meternalHealthPredict = async (Age,SystolicBP, DiastolicBP, Blood_glucose, BodyTemp, HeartRate) => { export let meternalHealthPredict = async (Age,SystolicBP, DiastolicBP, Blood_glucose, BodyTemp, HeartRate) => {
try { try {
let value = await axios.post(BASE_PATH + '/predict', { let value = await axios.post(BASE_PATH + '/predict', {
...@@ -22,7 +21,6 @@ export let meternalHealthPredict = async (Age,SystolicBP, DiastolicBP, Blood_glu ...@@ -22,7 +21,6 @@ export let meternalHealthPredict = async (Age,SystolicBP, DiastolicBP, Blood_glu
} }
//initialize payment API Call
export let addInitialExercises = async (id, riskLevel) => { export let addInitialExercises = async (id, riskLevel) => {
try { try {
let value = await axios.post(BASE_PATH2 + '/initial_exercises', { let value = await axios.post(BASE_PATH2 + '/initial_exercises', {
...@@ -36,7 +34,7 @@ export let addInitialExercises = async (id, riskLevel) => { ...@@ -36,7 +34,7 @@ export let addInitialExercises = async (id, riskLevel) => {
} }
//initialize payment API Call
export let getAllExerciseDay = async (id, dateNum) => { export let getAllExerciseDay = async (id, dateNum) => {
try { try {
let value = await axios.post(BASE_PATH2 + '/get_all_exercise_day', { let value = await axios.post(BASE_PATH2 + '/get_all_exercise_day', {
...@@ -47,4 +45,17 @@ export let getAllExerciseDay = async (id, dateNum) => { ...@@ -47,4 +45,17 @@ export let getAllExerciseDay = async (id, dateNum) => {
} catch (error) { } catch (error) {
return error return error
} }
}
export let updateDeviceStatus = async (id, deviceStatus) => {
try {
let value = await axios.post(BASE_PATH2 + '/update_device_status', {
_id: id,
deviceStatus: deviceStatus
})
return value;
} catch (error) {
return error
}
} }
\ No newline at end of file
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