Skip to content

Commit

Permalink
Updates to api call
Browse files Browse the repository at this point in the history
  • Loading branch information
Ariel Virgulto committed Sep 20, 2024
1 parent accf432 commit f3a0f78
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 78 deletions.
6 changes: 6 additions & 0 deletions frontend/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,9 @@
display: grid;
grid-template-areas: ' main right';
}

.err-msg {
color: red;
font-style: italic;
text-align: center;
}
1 change: 1 addition & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import axios from 'axios'
function App() {
const [token, setToken] = useState(null);

// to do - add popup for a 'are you sure'
const resetDB = async () => {
await axios
.post('http://localhost:8090/etasu/reset')
Expand Down
71 changes: 36 additions & 35 deletions frontend/src/views/Data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import axios from 'axios'
import { useEffect } from 'react'
import { Box, Tab, Tabs } from '@mui/material';
import { Container } from '@mui/system';
import CaseCollection from './DataViews/CaseCollection';
import Medications from './DataViews/Medications';
import MetRequirements from './DataViews/MetRequirements';

function a11yProps(index: number) {
return {
Expand All @@ -12,30 +15,29 @@ function a11yProps(index: number) {
}
const Data = () => {

const [allData, setAllData] = useState([]);
// const [allData, setAllData] = useState([]);
const [tabIndex, setValue] = useState(0);

const handleChange = (event: SyntheticEvent, newValue: number) => {
setValue(newValue);
};

useEffect(() => {
getAllRemsCase();
}, [])
// useEffect(() => {
// getAllRemsCase();
// }, [])

const getAllRemsCase = async () => {
const url = 'http://localhost:8090/all/remscase';
await axios
.get(url)
.then(function (response: { data: SetStateAction<never[]>; }) {
console.log('Response is -- > ', response);
setAllData(response.data);
// const getAllRemsCase = async () => {
// const url = 'http://localhost:8090/all/remscase';
// await axios
// .get(url)
// .then(function (response: { data: SetStateAction<never[]>; }) {
// setAllData(response.data);

})
.catch((error: any) => {
console.log('Error -- > ', error);
})
}
// })
// .catch((error: any) => {
// console.log('Error -- > ', error);
// })
// }

return (
<Container maxWidth="xl">
Expand All @@ -52,29 +54,28 @@ const Data = () => {
<Box sx={{ backgroundColor: '#F1F3F4', borderBottom: 1, borderColor: 'divider' }}>
<Tabs value={tabIndex} onChange={handleChange} aria-label="basic tabs example" centered>
<Tab label="Rems Case Collection" {...a11yProps(0)} />
<Tab label="Etasu" {...a11yProps(1)} />
<Tab label="Other" {...a11yProps(2)} />
<Tab label="Medications" {...a11yProps(1)} />
<Tab label="Met Requirements" {...a11yProps(2)} />
</Tabs>
</Box>

<Box>
<Box sx={{ padding: 2 }}>
{tabIndex === 0 && (
<Box>
<div>This is for rems case</div>
</Box>
)}
{tabIndex === 1 && (
<Box>
<div>This is for etasu</div>
<Box sx={{ padding: 2 }}>
{tabIndex === 0 && (
<Box>
<CaseCollection />
</Box>
)}
{tabIndex === 1 && (
<Box>
<Medications />
</Box>
)}
{tabIndex === 2 && (
<Box>
<MetRequirements />
</Box>
)}
</Box>
)}
{tabIndex === 2 && (
<Box>
<div>This is for other</div>
</Box>
)}
</Box>
</Box>
</Box>

Expand Down
1 change: 0 additions & 1 deletion frontend/src/views/DataViews/Medications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const Medications = () => {

useEffect(() => {
getAllMedications();
// getAllMetReqs();
}, [])

const getAllMedications = async () => {
Expand Down
65 changes: 35 additions & 30 deletions frontend/src/views/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { SetStateAction } from 'react'
import { SetStateAction, useState } from 'react'
import axios from 'axios'
import { Avatar, Box, Button, Container, CssBaseline, TextField, Typography } from '@mui/material';
import LockOutlinedIcon from '@mui/icons-material/LockOutlined';
import config from '../../config.json';

const Login = (props) => {
const [showMessage, setShowMessage] = useState(false);

const handleSubmit = (event: { preventDefault: () => void; currentTarget: HTMLFormElement | undefined; }) => {
event.preventDefault();
Expand All @@ -25,6 +26,7 @@ const Login = (props) => {
// do something with the token
const scope = result.data.scope;
if (scope) {
setShowMessage(true);
props.tokenCallback(result.data.access_token);
} else {
console.error('Unauthorized User');
Expand All @@ -33,6 +35,8 @@ const Login = (props) => {
.catch(err => {
if (err.response.status === 401) {
console.error('Unknown user');
setShowMessage(true);

} else {
console.error(err);
}
Expand All @@ -51,35 +55,36 @@ const Login = (props) => {
alignItems: 'center'
}}
>
<Avatar sx={{ m: 1 }}>
<LockOutlinedIcon />
</Avatar>
<Typography component="h1" variant="h5">
Sign in
</Typography>
<Box component="form" onSubmit={handleSubmit} noValidate sx={{ mt: 1 }}>
<TextField
margin="normal"
fullWidth
id="email"
label="Username"
name="username"
autoComplete="username"
autoFocus
/>
<TextField
margin="normal"
fullWidth
name="password"
label="Password"
type="password"
id="password"
autoComplete="current-password"
/>
<Button type="submit" fullWidth variant="contained" sx={{ mt: 3, mb: 2 }}>
Sign In
</Button>
</Box>
<Avatar sx={{ m: 1 }}>
<LockOutlinedIcon />
</Avatar>
<Typography component="h1" variant="h5">
Sign in
</Typography>
<Box component="form" onSubmit={handleSubmit} noValidate sx={{ mt: 1 }}>
<TextField
margin="normal"
fullWidth
id="email"
label="Username"
name="username"
autoComplete="username"
autoFocus
/>
<TextField
margin="normal"
fullWidth
name="password"
label="Password"
type="password"
id="password"
autoComplete="current-password"
/>
<Button type="submit" fullWidth variant="contained" sx={{ mt: 3, mb: 2 }}>
Sign In
</Button>
{ showMessage ? <p className="err-msg">Error signing in. Please try again.</p> : ""};
</Box>
</Box>
</Container>
)
Expand Down
43 changes: 31 additions & 12 deletions src/lib/api_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import {
medicationCollection,
metRequirementsCollection
} from '../fhir/models';
import axios from 'axios';
const router = Router();

router.get('/all/remscase', async (req: Request, res: Response) => {
try {
console.log('Getting all data');
console.log('Getting all rems case collection');
res.send(await remsCaseCollection.find({}));
} catch (error) {
console.log('ERROR getting data --> ', error);
console.log('ERROR getting rems case collection --> ', error);
throw error;
}
});
Expand All @@ -21,8 +20,29 @@ router.post('/remsCase/deleteOne', async (req: Request, res: Response) => {
try {
// delete rems case collection
await remsCaseCollection.findByIdAndDelete({ _id: req.body.data.params?._id });
// delete patient met requirements, either enrollment or status update forms
res.send(`Deleted REMS Case collection case number - ${req.body.data.params?.case_number}`);
// find and delete patient met requirements, either enrollment or status update forms
const allMatchedMetReqs = await metRequirementsCollection.find({
case_numbers: { $in: req.body.data.params?.case_number }
});
allMatchedMetReqs.forEach(async matchedReq => {
if (matchedReq.requirementName.includes('Patient')) {
await metRequirementsCollection.findOneAndDelete({ _id: matchedReq._id });
} else {
// If not a patient form - remove case number from prescriber forms
await metRequirementsCollection.findOneAndUpdate(
{ _id: matchedReq._id },
{
case_numbers: matchedReq.case_numbers.filter(
num => num !== req.body.data.params?.case_number
)
},
{ new: true }
);
}
});
res.send(
`Deleted REMS Case collection and patient forms with case number - ${req.body.data.params?.case_number}`
);
} catch (error) {
console.log('ERROR deleting data --> ', error);
throw error;
Expand All @@ -31,32 +51,31 @@ router.post('/remsCase/deleteOne', async (req: Request, res: Response) => {

router.get('/all/medications', async (req: Request, res: Response) => {
try {
console.log('Getting all data');
console.log('Getting all medications');
res.send(await medicationCollection.find({}));
} catch (error) {
console.log('ERROR getting data --> ', error);
console.log('ERROR getting all medications --> ', error);
throw error;
}
});

router.get('/all/metreqs', async (req: Request, res: Response) => {
try {
console.log('Getting all data');
console.log('Getting all met requirements');
res.send(await metRequirementsCollection.find({}));
} catch (error) {
console.log('ERROR getting data --> ', error);
console.log('ERROR getting met requirements --> ', error);
throw error;
}
});

router.post('/metreqs/deleteOne', async (req: Request, res: Response) => {
try {
// delete rems case collection
// delete met requirements
await metRequirementsCollection.findByIdAndDelete({ _id: req.body.data.params?._id });
// delete patient met requirements, either enrollment or status update forms
res.send(`Deleted met requirement with name - ${req.body.data.params?.requirementName}`);
} catch (error) {
console.log('ERROR deleting data --> ', error);
console.log('ERROR deleting met requirement --> ', error);
throw error;
}
});
Expand Down

0 comments on commit f3a0f78

Please sign in to comment.