Commit 54282bb7 authored by Malsha Jayakody's avatar Malsha Jayakody

Merge remote-tracking branch 'origin/exercise-manage' into final-app

parents bb74bb1a d8b561e1
......@@ -20,6 +20,7 @@ export default {
EXERCISE_HOME: 'Exercise_Home',
EXERCISE_FORM: 'Health_Form',
EXERCISE_MAIN_MENU: 'Exercise_Home_Menu',
EXERCISE_MAIN_NEW_MENU: 'Exercise_Home_New_Menu',
EXERCISE_VIEW: 'Exercise_View',
EXERCISE_ACTION_VIEW: 'Exercise_ACTION_View',
EXERCISE_PROGRESS: 'Exercise_PROGRESS',
......
......@@ -68,7 +68,7 @@ function ExerciseNavigator() {
<>
<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_MAIN_MENU} component={MainMenuExercise} key="MainMenuExercise" />
<Stack.Screen name={ROUTES.EXERCISE_MAIN_NEW_MENU} component={MainMenuExercise} key="MainMenuNewExercise" />
</>
)}
</Stack.Navigator>
......
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 CheckBox from '@react-native-community/checkbox';
import LinearGradient from 'react-native-linear-gradient';
import { COLORS, IMGS, ROUTES } from '../../../constants';
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 database from '@react-native-firebase/database';
import Dot from '../../../assets/icons/dot.svg';
......@@ -20,34 +20,50 @@ const HealthFormExercise = (props) => {
const [initialBodyTemp, setInitialBodyTemp] = useState();
const [initialHeartRate, setInitialHeartRate] = useState();
const [dataArray, setDataArray] = useState(null);
const [isWearbleDevice, setIsWearbleDevice] = useState(false);
const [wearableModalVisible, setWearableModalVisible] = useState(false);
useEffect(() => {
if (isWearbleDevice) {
// Reference to your Firebase Realtime Database
const databaseRef = database().ref('test');
ToastAndroid.show('Data reading on device !', ToastAndroid.SHORT);
// Attach an asynchronous listener to read the data at our reference
const onDataChange = (snapshot) => {
const data = snapshot.val();
setDataArray(data);
console.log("dada", 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 () => {
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 userData = JSON.parse(userDataString);
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"
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;
......@@ -76,7 +92,7 @@ const HealthFormExercise = (props) => {
return (
<SafeAreaView >
<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)}
enableReinitialize={true}
>
......@@ -117,13 +133,46 @@ const HealthFormExercise = (props) => {
/>
</View>
<View style={Styles.closeDiv}>
<TouchableOpacity onPress={() => setModalVisible(false)}>
<TouchableOpacity onPress={() => { setModalVisible(false); setWearableModalVisible(true) }}>
<Text style={Styles.closeButton}>Close</Text>
</TouchableOpacity>
</View>
</View>
</View>
</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>
<View style={Styles.inputBox}>
......@@ -237,6 +286,13 @@ const Styles = StyleSheet.create({
fontSize: 18,
fontWeight: 'bold',
},
closeNewButton: {
marginTop: 10,
color: COLORS.danger,
textAlign: 'center',
fontSize: 18,
fontWeight: 'bold',
},
submitButton: {
backgroundColor: '#1899D6',
borderRadius: 10, // Adjust the border radius as needed
......@@ -354,8 +410,17 @@ const Styles = StyleSheet.create({
display: "flex",
flexDirection: "row",
justifyContent: "center",
alignItems:"center",
alignItems: "center",
width: "100%"
},
buttonRow: {
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-around',
alignItems: 'center',
width: '100%',
marginTop: 10,
gap: 20
}
});
import axios from "axios";
const BASE_PATH = 'http://139.162.3.203:8010';
const BASE_PATH2 = 'http://139.162.3.203:8070/api/mother';
const BASE_PATH = 'http://16.170.242.186:8080';
const BASE_PATH2 = 'http://10.0.2.2:8070/api/mother';
import AsyncStorage from '@react-native-async-storage/async-storage';
//initialize payment API Call
export let meternalHealthPredict = async (Age,SystolicBP, DiastolicBP, Blood_glucose, BodyTemp, HeartRate) => {
try {
let value = await axios.post(BASE_PATH + '/predict', {
......@@ -22,7 +21,6 @@ export let meternalHealthPredict = async (Age,SystolicBP, DiastolicBP, Blood_glu
}
//initialize payment API Call
export let addInitialExercises = async (id, riskLevel) => {
try {
let value = await axios.post(BASE_PATH2 + '/initial_exercises', {
......@@ -36,7 +34,7 @@ export let addInitialExercises = async (id, riskLevel) => {
}
//initialize payment API Call
export let getAllExerciseDay = async (id, dateNum) => {
try {
let value = await axios.post(BASE_PATH2 + '/get_all_exercise_day', {
......@@ -48,3 +46,16 @@ export let getAllExerciseDay = async (id, dateNum) => {
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