Skip to content

Commit

Permalink
updated storage model according to the backend routes
Browse files Browse the repository at this point in the history
  • Loading branch information
DoParkEQ committed Jul 11, 2021
1 parent 05622b0 commit a363f3c
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 15 deletions.
3 changes: 2 additions & 1 deletion client/src/configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ export const defaultOxyData = {

export const defaultVital = new storage(
process.env.REACT_APP_SERVICE_UUID,
process.env.REACT_APP_CHT_UUID);
process.env.REACT_APP_CHT_UUID,
'ajsdo222');

export const tabsList = [{
name: 'Dashboard 📈',
Expand Down
15 changes: 11 additions & 4 deletions client/src/context/DashboardContext.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import React, { createContext, useReducer } from 'react';
import { initialState, defaultOxyData } from '../configs';
import { getSummary } from '../utils';
import { postVital } from '../lib/api/vitals';

export const DashboardContext = createContext(initialState);

const reducer = (state, action) => {
switch (action.type) {
case 'LOAD_SAVED_DATA': {
const { userVital } = action.payload;
return { ...state, userVital };
case 'LOAD_DATA': {
const { userVital, userInfo } = action.payload;
if (userVital.length > 0) {
state.userVital.addHistory(userVital);
// state.userVital.addUUIDs(userInfo.serviceUUID, userInfo.chtUUID)
}
return { ...state };
}

case 'CONNECT': {
Expand All @@ -29,16 +34,18 @@ const reducer = (state, action) => {
const history = {
runTime: state.oxyData.elapsedTime,
date: state.userStatus.startTime,
vitalLog: [...state.userVital.vitalLog],
};

getSummary(state.userVital.vitalLog);
postVital(history, state.userVital.userID);
state.userVital.updateHistory(history);
const userStatus = {
...state.userStatus,
isConnected: false,
deviceName: null,
startTime: new Date(),
};
console.log(state.userVital);
const oxyData = { ...defaultOxyData };
return { ...state, userStatus, oxyData };
}
Expand Down
12 changes: 9 additions & 3 deletions client/src/controller/DashboardController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@ import React, { useEffect, useContext } from 'react';
import Dashboard from '../view/Dashboard';
import { checkVitalAnomalies, getTime } from '../utils';
import { DashboardContext } from '../context/DashboardContext';
import { getSavedVitals } from '../lib/api/vitals';
import { getVitals, postVital } from '../lib/api/vitals';
import { getUserInfo } from '../lib/api/user';

const timeInterval = 1000;
const flags = {
breakPoint: 170,
graph: 7,
vital: 8,
};

const DashboardController = () => {

const { dispatch, state } = useContext(DashboardContext);
const { oximetry, userStatus, userVital, vitalSnapshot, rollbackCount, device } = state;
const signal = [];

useEffect(() => {
getSavedVitals().then(([userVital]) => dispatch({ type: 'LOAD_SAVED_DATA', payload: { userVital } }));
useEffect(async () => {
const fetchedUserVital = await getVitals(userVital.userID);
const fetchedUserInfo = await getUserInfo(userVital.userID);
console.log('userInfo:', fetchedUserInfo);
console.log('userVital:', fetchedUserVital);
dispatch({ type: 'LOAD_DATA', payload: { userVital: fetchedUserVital, userInfo: fetchedUserInfo } });
}, []);

useEffect(() => {
Expand Down
10 changes: 10 additions & 0 deletions client/src/lib/api/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import axios from 'axios';

const PORT = 5000;
const URL = `http://localhost:${PORT}/user`;

//TODO: get userinfo to fill out UUIDs
export const getUserInfo = async (userId) => {
const res = await axios.get(`${URL}/${userId}`);
return res.data;
};
7 changes: 4 additions & 3 deletions client/src/lib/api/vitals.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import axios from 'axios';

const PORT = 5000;
const url = `http://localhost:${PORT}/vitals`;
const URL = `http://localhost:${PORT}/vitals`;

export const getSavedVitals = async () => {
const res = await axios.get(url);
export const getVitals = async (userId) => {
const res = await axios.get(`${URL}/${userId}`);
return res.data;
};

export const postVital = (history, userId) => axios.post(`${URL}/${userId}/post`, history);
11 changes: 9 additions & 2 deletions client/src/model/storage.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

class storage {
constructor(serviceUUID, chtUUID) {
constructor(serviceUUID, chtUUID, userID) {
this.vitalLog = [];
this.history = [];
this.serviceUUID = serviceUUID || null;
this.chtUUID = chtUUID || null;
this.userID = userID || null;

}

Expand All @@ -25,6 +25,13 @@ class storage {
this.serviceUUID = serviceUUID;
this.chtUUID = chtUUID;
}

addHistory(data) {
if (data.length > 0) {
this.history = data.map(d => d.history);
}
}
}

export default storage;

5 changes: 3 additions & 2 deletions client/src/view/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const Dashboard = ({ onSubscribe, onDisconnect }) => {
return n;
});
};

console.log(userVital.serviceUUID, userVital.chtUUID);
return (
<>
{openModal &&
Expand Down Expand Up @@ -151,7 +151,8 @@ const Dashboard = ({ onSubscribe, onDisconnect }) => {
{`Total run time: ${runTime}`}
</Typography>
<Typography variant='body'>
{`Date: ${formatDate(date)}`}
{/* {`Date: ${formatDate(date)}`} */}
{`Date: ${date}`}
</Typography>
</div>,
)}
Expand Down

0 comments on commit a363f3c

Please sign in to comment.