diff --git a/frontend/src/App.js b/frontend/src/App.js index aed9608585ccb00932d792093fb06c65022711db..9bbceb0c5a42830200a5867798db780fc29a8bd0 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -1,26 +1,26 @@ -import React from 'react'; -import './App.scss'; -import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom"; -import Startseite from './components/startseite/Startseite'; -import BTMBuch from './components/btmbuch/BTMBuch'; -import ApothekeEinstellungen from './components/apotheke/einstellungen/ApothekeEinstellungen'; -import { SnackbarProvider } from 'notistack'; -require('dotenv').config() - -function App() { - return ( - <React.Fragment> - <SnackbarProvider maxSnack={10} anchorOrigin={{vertical:'bottom', horizontal:'center'}}> - <Router> - <Switch> - <Route path="/" exact component={Startseite} /> - <Route path="/login" exact component={Startseite} /> - <Route path="/apotheke/:apoId" exact component={BTMBuch} /> - <Route path="/apotheke/:apoId/einstellungen" exact component={ApothekeEinstellungen} /> - </Switch> - </Router> - </SnackbarProvider> - </React.Fragment>); -} - -export default App; +import React from 'react'; +import './App.scss'; +import { BrowserRouter as Router, Switch, Route } from "react-router-dom"; +import Startseite from './components/startseite/Startseite'; +import BTMBuch from './components/btmbuch/BTMBuch'; +import ApothekeEinstellungen from './components/apotheke/einstellungen/ApothekeEinstellungen'; +import { SnackbarProvider } from 'notistack'; +require('dotenv').config() + +function App() { + return ( + <React.Fragment> + <SnackbarProvider maxSnack={10} anchorOrigin={{vertical:'bottom', horizontal:'center'}}> + <Router> + <Switch> + <Route path="/" exact component={Startseite} /> + <Route path="/login" exact component={Startseite} /> + <Route path="/apotheke/:apoId" exact component={BTMBuch} /> + <Route path="/apotheke/:apoId/einstellungen" exact component={ApothekeEinstellungen} /> + </Switch> + </Router> + </SnackbarProvider> + </React.Fragment>); +} + +export default App; diff --git a/frontend/src/components/apotheke/ApothekeBtmList.js b/frontend/src/components/apotheke/ApothekeBtmList.js index a477422eb6691cba3d2472696a95915ff1232857..94a56db2f9de91b7f6cb2ab6d1ffd70a5e1f120d 100644 --- a/frontend/src/components/apotheke/ApothekeBtmList.js +++ b/frontend/src/components/apotheke/ApothekeBtmList.js @@ -1,69 +1,70 @@ -import React, { useState, useEffect } from "react"; -import { useParams } from 'react-router-dom'; -import BuchungTabelle from "../btmbuch/BuchungTabelle"; - -function ApothekeBtmList(props) { - - const { apoId } = useParams(); - const [btms, setBtms] = useState([]); - const [input, setInput] = useState(""); - - const getBtms = async () => { - const response = await fetch( - `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/btmbuchung`, - { - method: "GET", - headers: { - Authorization: - "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), - }, - } - ).catch((err) => { - //SHOW ERROR - return; - }); - - if (response.status === 200) { - setBtms(await response.json()); - } else if (response.status === 403) { - props.history.push("/forbidden"); - } else if (response.status === 400) { - props.history.push("/badrequest"); - } - }; - - //wird aufgerufen von NeuesBtmModal wenn ein neues BTM hinzugefügt wurde - props.apothekeRefFunctions.updateBtmList = getBtms; - - useEffect(() => { - getBtms(); - }, []); - - return ( - <div className="btm-buchung-wrapper"> - <input - id="searchBtmField" - type="text" - placeholder="Betäubungsmittel suchen" - onChange={(event) => { - setInput(event.target.value); - }} - value={input} - /> - {btms - .filter((val) => { - if (input === "") { - return val; - } else if (val.btm.name.toLowerCase().includes(input.toLowerCase())){ - return val; - } - }) - .map((btm, key) => ( - <BuchungTabelle {...props} btm={btm} /> - ))} - </div> - ); -} - -export default ApothekeBtmList; - +import React, { useState, useEffect } from "react"; +import { useParams } from 'react-router-dom'; +import BuchungTabelle from "../btmbuch/BuchungTabelle"; + +function ApothekeBtmList(props) { + + const { apoId } = useParams(); + const [btms, setBtms] = useState([]); + const [input, setInput] = useState(""); + + const getBtms = async () => { + const response = await fetch( + `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/btmbuchung`, + { + method: "GET", + headers: { + Authorization: + "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), + }, + } + ).catch((err) => { + //SHOW ERROR + return; + }); + + if (response.status === 200) { + setBtms(await response.json()); + } else if (response.status === 403) { + props.history.push("/forbidden"); + } else if (response.status === 400) { + props.history.push("/badrequest"); + } + }; + + //wird aufgerufen von NeuesBtmModal wenn ein neues BTM hinzugefügt wurde + props.apothekeRefFunctions.updateBtmList = getBtms; + + useEffect(() => { + getBtms(); + }, []); + + return ( + <div className="btm-buchung-wrapper"> + <input + id="searchBtmField" + type="text" + placeholder="Betäubungsmittel suchen" + onChange={(event) => { + setInput(event.target.value); + }} + value={input} + /> + {btms + .filter((val) => { + if (input === "") { + return val; + } else if (val.btm.name.toLowerCase().includes(input.toLowerCase())){ + return val; + } + return null; + }) + .map((btm) => ( + <BuchungTabelle {...props} btm={btm} /> + ))} + </div> + ); +} + +export default ApothekeBtmList; + diff --git a/frontend/src/components/apotheke/ApothekenDetails.js b/frontend/src/components/apotheke/ApothekenDetails.js index c8edc5d6be832783a24ff5fb734b8ad86f12dd43..a055b77324289b61b4e7105b8fd9d2c90ea5f79b 100644 --- a/frontend/src/components/apotheke/ApothekenDetails.js +++ b/frontend/src/components/apotheke/ApothekenDetails.js @@ -1,60 +1,60 @@ -import React, { useEffect, useState } from "react"; -import { useParams, Link } from 'react-router-dom'; -import { Button } from "react-bootstrap"; -import NeuesBtmModal from "../btmbuch/NeuesBtmModal"; -import "../../App.scss"; - -function ApothekenDetails(props) { - const [apotheke, setApotheke] = useState({ anschrift: {} }); - const [neuesBtmModalShow, setneuesBtmModalShow] = useState(false); - - const getApothekeData = async () => { - const response = await fetch( - `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.match.params.apoId}`, - { - method: "GET", - headers: { - Authorization: - "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), - }, - } - ).catch((err) => { - //SHOW ERROR - return; - }); - - if (response.status === 200) { - setApotheke(await response.json()); - } else if (response.status === 403) { - props.history.push("/forbidden"); - } else if (response.status === 400) { - props.history.push("/badrequest"); - } - }; - - useEffect(() => { - getApothekeData(); - }, []); - - return ( - <div className="apo-details"> - <ul> - <li>Name: {apotheke.name}</li> - <li>E-Mail: {apotheke.email}</li> - </ul> - <Link to={`${props.match.params.apoId}/einstellungen`} ><Button >Apotheke Einstellungen</Button></Link> - <Button - onClick={() => setneuesBtmModalShow(true)} - style={{ marginLeft: "1em" }} - > - Neues Betäubungsmittel anlegen - </Button> - <NeuesBtmModal - show={neuesBtmModalShow} - {...props} - onHide={() => setneuesBtmModalShow(false)} - /> - </div> - ); -} -export default ApothekenDetails; +import React, { useEffect, useState } from "react"; +import { Link } from 'react-router-dom'; +import { Button } from "react-bootstrap"; +import NeuesBtmModal from "../btmbuch/NeuesBtmModal"; +import "../../App.scss"; + +function ApothekenDetails(props) { + const [apotheke, setApotheke] = useState({ anschrift: {} }); + const [neuesBtmModalShow, setneuesBtmModalShow] = useState(false); + + const getApothekeData = async () => { + const response = await fetch( + `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.match.params.apoId}`, + { + method: "GET", + headers: { + Authorization: + "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), + }, + } + ).catch((err) => { + //SHOW ERROR + return; + }); + + if (response.status === 200) { + setApotheke(await response.json()); + } else if (response.status === 403) { + props.history.push("/forbidden"); + } else if (response.status === 400) { + props.history.push("/badrequest"); + } + }; + + useEffect(() => { + getApothekeData(); + }, []); + + return ( + <div className="apo-details"> + <ul> + <li>Name: {apotheke.name}</li> + <li>E-Mail: {apotheke.email}</li> + </ul> + <Link to={`${props.match.params.apoId}/einstellungen`} ><Button >Apotheke Einstellungen</Button></Link> + <Button + onClick={() => setneuesBtmModalShow(true)} + style={{ marginLeft: "1em" }} + > + Neues Betäubungsmittel anlegen + </Button> + <NeuesBtmModal + show={neuesBtmModalShow} + {...props} + onHide={() => setneuesBtmModalShow(false)} + /> + </div> + ); +} +export default ApothekenDetails; diff --git a/frontend/src/components/btmbuch/BuchungTabelle.js b/frontend/src/components/btmbuch/BuchungTabelle.js index d5a141b6b5973651df9fa65bd0cf834e6b5e2084..e6906a2e99094352a9058497062431fcc049eb82 100644 --- a/frontend/src/components/btmbuch/BuchungTabelle.js +++ b/frontend/src/components/btmbuch/BuchungTabelle.js @@ -1,336 +1,325 @@ -import React, { useState, useEffect } from "react"; -import { faEdit, faTrash, faPlus } from "@fortawesome/free-solid-svg-icons"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { Table, Button, Row, Col } from "react-bootstrap"; -import { Collapse, Checkbox } from "@material-ui/core"; -import Moment from "react-moment"; -import { useSnackbar } from "notistack"; -import { useParams } from "react-router-dom"; -import TableBody from '@material-ui/core/TableBody'; -import NeueBuchungModal from "./NeueBuchungModal"; -import UpdateBuchungModal from "../../modals/UpdateBuchungModal"; -import DeleteModal from "../../modals/DeleteModal"; -import { makeStyles } from '@material-ui/core/styles'; -import TablePagination from '@material-ui/core/TablePagination'; - -const useStyles = makeStyles({ - root: { - width: '100%', - }, - container: { - maxHeight: 440, - }, -}); - -function BuchungTabelle(props) { - let { btm } = props; - const { apoId } = useParams(); - - const classes = useStyles(); - const [page, setPage] = React.useState(0); - const [rowsPerPage, setRowsPerPage] = React.useState(10); - - const [open, setOpen] = useState(false); - const { enqueueSnackbar } = useSnackbar(); - - const [showNewBuchungModal, setShowNewBuchungModal] = useState(false); - const [showUpdateBuchungModal, setShowUpdateBuchungModal] = useState(false); - const [showDeleteModal, setShowDeleteModal] = useState(false); - - const [lieferanten, setLieferanten] = useState([]); - const [aerzte, setAerzte] = useState([]); - const [empfaenger, setEmpfaenger] = useState([]); - const [selectedBuchung, setSelectedBuchung] = useState({}); - - const handleChangePage = (event, newPage) => { - setPage(newPage); - }; - - const handleChangeRowsPerPage = (event) => { - setRowsPerPage(+event.target.value); - setPage(0); - }; - - const loadLieferanten = async () => { - const response = await fetch( - `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/lieferant`, - { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: - "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), - }, - } - ).catch((err) => { - //SHOW ERROR - console.log(err); - }); - - if (response.status === 200) { - setLieferanten(await response.json()); - } else if (response.status === 403) { - // props.history.push('/forbidden'); - } else if (response.status === 400) { - // props.history.push('/badrequest'); - } - }; - - const loadAerzte = async () => { - const response = await fetch( - `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/arzt`, - { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: - "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), - }, - } - ).catch((err) => { - //SHOW ERROR - console.log(err); - }); - - if (response.status === 200) { - setAerzte(await response.json()); - } else if (response.status === 403) { - // props.history.push('/forbidden'); - } else if (response.status === 400) { - // props.history.push('/badrequest'); - } - }; - - const loadEmpfaenger = async () => { - const response = await fetch( - `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/empfaenger`, - { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: - "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), - }, - } - ).catch((err) => { - //SHOW ERROR - console.log(err); - }); - - if (response.status === 200) { - setEmpfaenger(await response.json()); - } else if (response.status === 403) { - // props.history.push('/forbidden'); - } else if (response.status === 400) { - // props.history.push('/badrequest'); - } - }; - - const deleteBtm = async () => { - const response = await fetch( - `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/btmbuchung/${selectedBuchung.id}`, - { - method: "DELETE", - headers: { - Authorization: - "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), - }, - } - ).catch((err) => { - //SHOW ERROR - console.log(err); - }); - - if (response && response.status === 200) { - props.apothekeRefFunctions.updateBtmList(); - enqueueSnackbar("Buchung erfolgreich gelöscht", { - variant: "success", - autoHideDuration: 3000, - }); - } else { - //SHOW ERROR - console.log(response); - } - }; - - const update = (buchung) => { - setSelectedBuchung(buchung); - setShowUpdateBuchungModal(true); - }; - - const del = (buchung) => { - setSelectedBuchung(buchung); - setShowDeleteModal(true); - }; - - const renderEditButtons = (buchung) => { - return ( - <Row style={{ display: "block" }}> - <Button onClick={() => update(buchung)} style={{ marginLeft: "0.5em" }}> - <FontAwesomeIcon icon={faEdit} /> - </Button> - <Button onClick={() => del(buchung)} style={{ marginLeft: "0.5em" }}> - <FontAwesomeIcon icon={faTrash} /> - </Button> - </Row> - ); - }; - - const renderPruefButton = (buchung) => { - return ( - <Row> - <Checkbox checked={buchung.pruefdatum} onChange={event => sendUpdateRequest(buchung)} style={{ marginLeft: "0.5em" }} ></Checkbox> - </Row> - ); - }; - - const sendUpdateRequest = async (buchung) => { - let geprueft = buchung.pruefdatum == null; - const response = await fetch(`http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/btmbuchung/${buchung.id}?setGeprueft=${geprueft}`, { - method: "PUT", - headers: { - "Content-Type": "application/json", - Authorization: "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), - body: JSON.stringify(buchung) - } - }).catch((err) => { - //SHOW ERROR - console.log(err); - }); - - if (response && response.status === 200) { - enqueueSnackbar('Buchung erfolgreich aktualisiert', { variant: 'success', autoHideDuration: 3000 }); - props.apothekeRefFunctions.updateBtmList(); - } else { - //SHOW ERROR - console.log(response); - } - }; - - useEffect(() => { - loadLieferanten(); - loadAerzte(); - loadEmpfaenger(); - }, []); - - return ( - <React.Fragment> - <NeueBuchungModal - {...props} - lieferanten={lieferanten} - aerzte={aerzte} - empfaenger={empfaenger} - buchung={selectedBuchung} - show={showNewBuchungModal} - onHide={() => setShowNewBuchungModal(false)} - /> - <UpdateBuchungModal - {...props} - lieferanten={lieferanten} - aerzte={aerzte} - empfaenger={empfaenger} - buchung={selectedBuchung} - show={showUpdateBuchungModal} - onHide={() => setShowUpdateBuchungModal(false)} - /> - - <DeleteModal - {...props} - headertext={"Betäubungsmittel-Buchung löschen"} - maintext={"Möchtest du diese Buchung wirklich löschen?"} - onSubmit={deleteBtm} - subtext={"Dieser Vorgang kann nicht rückgängig gemacht werden"} - show={showDeleteModal} - onHide={() => setShowDeleteModal(false)} - /> - - <div style={{ marginBottom: "2em" }}> - <Row - onClick={() => setOpen(!open)} - className="noselect btm-table-header-name" - > - <Col sm={3}> - <p> - {btm.btm.name} ({btm.btm.menge}) - </p> - </Col> - <Col sm={9}> - <div style={{ marginLeft: "-9em" }}> - <Button - onClick={(event) => { - event.stopPropagation(); - setShowNewBuchungModal(true); - }} - > - Neue Buchung - <FontAwesomeIcon - style={{ marginLeft: "0.4em" }} - icon={faPlus} - /> - </Button> - </div> - </Col> - </Row> - <Collapse in={open}> - <Table striped bordered hover> - <thead> - <tr> - <th>Datum</th> - <th>Lieferant / Patient</th> - <th>Arztpraxis</th> - <th>Zugang</th> - <th>Abgang</th> - <th>Rezept Nr. / Lieferschein Nr.</th> - <th>Prüfdatum</th> - <th>Prüfer Kürzel</th> - {props.aktiveRolle.toLowerCase() === "admin" || props.aktiveRolle.toLowerCase() === "pruefer" ? ( - <th>Geprüft</th> - ) : null} - {props.aktiveRolle.toLowerCase() === "admin" ? ( - <th></th> - ) : null} - </tr> - </thead> - <TableBody> - {btm.buchungen.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage).map((buchung) => ( - <tr key={buchung.id}> - <td> <Moment format="DD.MM.YYYY">{buchung.datum}</Moment> </td> - <td>{buchung.typ === "ZUGANG" - ? buchung.lieferant.name - : buchung.empfaenger.vorname + " " + buchung.empfaenger.name} - </td> - <td>{buchung.typ === "ABGANG" ? buchung.arzt.name : ""}</td> - <td>{buchung.typ === "ZUGANG" ? buchung.menge : ""}</td> - <td>{buchung.typ === "ZUGANG" ? "" : buchung.menge}</td> - <td>{buchung.typ === "ZUGANG" ? buchung.anforderungsschein : buchung.rezept}</td> - <td>{buchung.pruefdatum ? <Moment format="DD.MM.YYYY">{buchung.pruefdatum}</Moment> : ""}</td> - <td>{buchung.pruefer ? buchung.pruefer.vorname+" "+buchung.pruefer.name : ""}</td> - - {props.aktiveRolle.toLowerCase() === "admin" || props.aktiveRolle.toLowerCase() === "pruefer" ? - <th>{renderPruefButton(buchung)}</th> : null} - - {props.aktiveRolle.toLowerCase() === "admin" ? - <td style={{ textAlign: "center", verticalAlign: "middle" }} > - {renderEditButtons(buchung)} - </td> : null} - - </tr> - ))} - </TableBody> - </Table> - <TablePagination - rowsPerPageOptions={[5, 10, 15]} - component="div" - count={btm.buchungen.length} - rowsPerPage={rowsPerPage} - page={page} - onChangePage={handleChangePage} - onChangeRowsPerPage={handleChangeRowsPerPage} - /> - </Collapse> - </div> - </React.Fragment> - ); -} - -export default BuchungTabelle; +import React, { useState, useEffect } from "react"; +import { faEdit, faTrash, faPlus } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { Table, Button, Row, Col } from "react-bootstrap"; +import { Collapse, Checkbox } from "@material-ui/core"; +import Moment from "react-moment"; +import { useSnackbar } from "notistack"; +import { useParams } from "react-router-dom"; +import TableBody from '@material-ui/core/TableBody'; +import NeueBuchungModal from "./NeueBuchungModal"; +import UpdateBuchungModal from "../../modals/UpdateBuchungModal"; +import DeleteModal from "../../modals/DeleteModal"; +import TablePagination from '@material-ui/core/TablePagination'; + +function BuchungTabelle(props) { + let { btm } = props; + const { apoId } = useParams(); + + const [page, setPage] = React.useState(0); + const [rowsPerPage, setRowsPerPage] = React.useState(10); + + const [open, setOpen] = useState(false); + const { enqueueSnackbar } = useSnackbar(); + + const [showNewBuchungModal, setShowNewBuchungModal] = useState(false); + const [showUpdateBuchungModal, setShowUpdateBuchungModal] = useState(false); + const [showDeleteModal, setShowDeleteModal] = useState(false); + + const [lieferanten, setLieferanten] = useState([]); + const [aerzte, setAerzte] = useState([]); + const [empfaenger, setEmpfaenger] = useState([]); + const [selectedBuchung, setSelectedBuchung] = useState({}); + + const handleChangePage = (event, newPage) => { + setPage(newPage); + }; + + const handleChangeRowsPerPage = (event) => { + setRowsPerPage(+event.target.value); + setPage(0); + }; + + const loadLieferanten = async () => { + const response = await fetch( + `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/lieferant`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: + "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), + }, + } + ).catch((err) => { + //SHOW ERROR + console.log(err); + }); + + if (response.status === 200) { + setLieferanten(await response.json()); + } else if (response.status === 403) { + // props.history.push('/forbidden'); + } else if (response.status === 400) { + // props.history.push('/badrequest'); + } + }; + + const loadAerzte = async () => { + const response = await fetch( + `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/arzt`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: + "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), + }, + } + ).catch((err) => { + //SHOW ERROR + console.log(err); + }); + + if (response.status === 200) { + setAerzte(await response.json()); + } else if (response.status === 403) { + // props.history.push('/forbidden'); + } else if (response.status === 400) { + // props.history.push('/badrequest'); + } + }; + + const loadEmpfaenger = async () => { + const response = await fetch( + `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/empfaenger`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: + "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), + }, + } + ).catch((err) => { + //SHOW ERROR + console.log(err); + }); + + if (response.status === 200) { + setEmpfaenger(await response.json()); + } else if (response.status === 403) { + // props.history.push('/forbidden'); + } else if (response.status === 400) { + // props.history.push('/badrequest'); + } + }; + + const deleteBtm = async () => { + const response = await fetch( + `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/btmbuchung/${selectedBuchung.id}`, + { + method: "DELETE", + headers: { + Authorization: + "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), + }, + } + ).catch((err) => { + //SHOW ERROR + console.log(err); + }); + + if (response && response.status === 200) { + props.apothekeRefFunctions.updateBtmList(); + enqueueSnackbar("Buchung erfolgreich gelöscht", { + variant: "success", + autoHideDuration: 3000, + }); + } else { + //SHOW ERROR + console.log(response); + } + }; + + const update = (buchung) => { + setSelectedBuchung(buchung); + setShowUpdateBuchungModal(true); + }; + + const del = (buchung) => { + setSelectedBuchung(buchung); + setShowDeleteModal(true); + }; + + const renderEditButtons = (buchung) => { + return ( + <Row style={{ display: "block" }}> + <Button onClick={() => update(buchung)} style={{ marginLeft: "0.5em" }}> + <FontAwesomeIcon icon={faEdit} /> + </Button> + <Button onClick={() => del(buchung)} style={{ marginLeft: "0.5em" }}> + <FontAwesomeIcon icon={faTrash} /> + </Button> + </Row> + ); + }; + + const renderPruefButton = (buchung) => { + return ( + <Row> + <Checkbox checked={buchung.pruefdatum} onChange={event => sendUpdateRequest(buchung)} style={{ marginLeft: "0.5em" }} ></Checkbox> + </Row> + ); + }; + + const sendUpdateRequest = async (buchung) => { + let geprueft = buchung.pruefdatum == null; + const response = await fetch(`http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/btmbuchung/${buchung.id}?setGeprueft=${geprueft}`, { + method: "PUT", + headers: { + "Content-Type": "application/json", + Authorization: "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), + body: JSON.stringify(buchung) + } + }).catch((err) => { + //SHOW ERROR + console.log(err); + }); + + if (response && response.status === 200) { + enqueueSnackbar('Buchung erfolgreich aktualisiert', { variant: 'success', autoHideDuration: 3000 }); + props.apothekeRefFunctions.updateBtmList(); + } else { + //SHOW ERROR + console.log(response); + } + }; + + useEffect(() => { + loadLieferanten(); + loadAerzte(); + loadEmpfaenger(); + }, []); + + return ( + <React.Fragment> + <NeueBuchungModal + {...props} + lieferanten={lieferanten} + aerzte={aerzte} + empfaenger={empfaenger} + buchung={selectedBuchung} + show={showNewBuchungModal} + onHide={() => setShowNewBuchungModal(false)} + /> + <UpdateBuchungModal + {...props} + lieferanten={lieferanten} + aerzte={aerzte} + empfaenger={empfaenger} + buchung={selectedBuchung} + show={showUpdateBuchungModal} + onHide={() => setShowUpdateBuchungModal(false)} + /> + + <DeleteModal + {...props} + headertext={"Betäubungsmittel-Buchung löschen"} + maintext={"Möchtest du diese Buchung wirklich löschen?"} + onSubmit={deleteBtm} + subtext={"Dieser Vorgang kann nicht rückgängig gemacht werden"} + show={showDeleteModal} + onHide={() => setShowDeleteModal(false)} + /> + + <div style={{ marginBottom: "2em" }}> + <Row + onClick={() => setOpen(!open)} + className="noselect btm-table-header-name" + > + <Col sm={3}> + <p> + {btm.btm.name} ({btm.btm.menge}) + </p> + </Col> + <Col sm={9}> + <div style={{ marginLeft: "-9em" }}> + <Button + onClick={(event) => { + event.stopPropagation(); + setShowNewBuchungModal(true); + }} + > + Neue Buchung + <FontAwesomeIcon + style={{ marginLeft: "0.4em" }} + icon={faPlus} + /> + </Button> + </div> + </Col> + </Row> + <Collapse in={open}> + <Table striped bordered hover> + <thead> + <tr> + <th>Datum</th> + <th>Lieferant / Patient</th> + <th>Arztpraxis</th> + <th>Zugang</th> + <th>Abgang</th> + <th>Rezept Nr. / Lieferschein Nr.</th> + <th>Prüfdatum</th> + <th>Prüfer Kürzel</th> + {props.aktiveRolle.toLowerCase() === "admin" || props.aktiveRolle.toLowerCase() === "pruefer" ? ( + <th>Geprüft</th> + ) : null} + {props.aktiveRolle.toLowerCase() === "admin" ? ( + <th></th> + ) : null} + </tr> + </thead> + <TableBody> + {btm.buchungen.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage).map((buchung) => ( + <tr key={buchung.id}> + <td> <Moment format="DD.MM.YYYY">{buchung.datum}</Moment> </td> + <td>{buchung.typ === "ZUGANG" + ? buchung.lieferant.name + : buchung.empfaenger.vorname + " " + buchung.empfaenger.name} + </td> + <td>{buchung.typ === "ABGANG" ? buchung.arzt.name : ""}</td> + <td>{buchung.typ === "ZUGANG" ? buchung.menge : ""}</td> + <td>{buchung.typ === "ZUGANG" ? "" : buchung.menge}</td> + <td>{buchung.typ === "ZUGANG" ? buchung.anforderungsschein : buchung.rezept}</td> + <td>{buchung.pruefdatum ? <Moment format="DD.MM.YYYY">{buchung.pruefdatum}</Moment> : ""}</td> + <td>{buchung.pruefer ? buchung.pruefer.vorname+" "+buchung.pruefer.name : ""}</td> + + {props.aktiveRolle.toLowerCase() === "admin" || props.aktiveRolle.toLowerCase() === "pruefer" ? + <th>{renderPruefButton(buchung)}</th> : null} + + {props.aktiveRolle.toLowerCase() === "admin" ? + <td style={{ textAlign: "center", verticalAlign: "middle" }} > + {renderEditButtons(buchung)} + </td> : null} + + </tr> + ))} + </TableBody> + </Table> + <TablePagination + rowsPerPageOptions={[5, 10, 15]} + component="div" + count={btm.buchungen.length} + rowsPerPage={rowsPerPage} + page={page} + onChangePage={handleChangePage} + onChangeRowsPerPage={handleChangeRowsPerPage} + /> + </Collapse> + </div> + </React.Fragment> + ); +} + +export default BuchungTabelle; diff --git a/frontend/src/modals/ApothekeRegisterModal.js b/frontend/src/modals/ApothekeRegisterModal.js index 6d5fb79a59ecab706319a573ab71737527d7aa5c..25a205c88e1769ff775434430485ce867d8489a4 100644 --- a/frontend/src/modals/ApothekeRegisterModal.js +++ b/frontend/src/modals/ApothekeRegisterModal.js @@ -1,7 +1,6 @@ -import React, { useEffect, useState } from "react"; -import { useParams } from 'react-router-dom'; +import React, { useState } from "react"; import { makeStyles, useTheme } from "@material-ui/core/styles"; -import { Modal, Button, Form, Row, Col } from "react-bootstrap"; +import { Modal, Button, Form, Col } from "react-bootstrap"; import { useForm } from "./useForm"; import MobileStepper from "@material-ui/core/MobileStepper"; import KeyboardArrowLeft from "@material-ui/icons/KeyboardArrowLeft"; @@ -297,8 +296,8 @@ function ApothekeRegisterModal(props) { nextButton={ <Button size="small" - type={activeStep == 1 ? "submit" : "button"} - onClick={activeStep == 0 ? handleNext : null} + type={activeStep === 1 ? "submit" : "button"} + onClick={activeStep === 0 ? handleNext : null} disabled={activeStep === 2} > {activeStep === 1 ? 'Registrien' : 'Weiter'} @@ -308,7 +307,7 @@ function ApothekeRegisterModal(props) { backButton={ <Button size="small" - type={activeStep == 1 ? "submit" : "button"} + type={activeStep === 1 ? "submit" : "button"} onClick={handleBack} disabled={activeStep === 0} > diff --git a/frontend/src/modals/UpdateBuchungModal.js b/frontend/src/modals/UpdateBuchungModal.js index b09897ce00b236224ad5f650ba809514b268f2a3..b007f4f77d7edd1e09ea9edc36c118357689ee59 100644 --- a/frontend/src/modals/UpdateBuchungModal.js +++ b/frontend/src/modals/UpdateBuchungModal.js @@ -1,4 +1,4 @@ -import React,{useEffect} from 'react'; +import React from 'react'; import { Modal, Button, Form, Row, Col } from 'react-bootstrap'; import { useSnackbar } from 'notistack'; import { useParams } from 'react-router-dom'; diff --git a/frontend/src/user/UserDetails.js b/frontend/src/user/UserDetails.js index 2d2fc2b9c19a11de8bf83172b84bc8a8c1bdcc8c..7db7f5cd6e25125f30fa4bd24f4858e5eaeeec22 100644 --- a/frontend/src/user/UserDetails.js +++ b/frontend/src/user/UserDetails.js @@ -1,45 +1,45 @@ -import React, {useState} from 'react' -import { Button, Col, Row, Form } from 'react-bootstrap'; -import { Settings } from '@material-ui/icons'; -import UserDetailsUpdateModal from '../modals/UserDetailsUpdateModal'; - -function UserDetails(props) { - //eslint disable-next-line - const {rolle, vorname, name, nutzername, aktiv} = props.user; - const [showUserSettings, setShowUserSettings] = useState(false); - - var allRoles = { - ADMIN : { 0: "Admin", 1 : "Pruefer", 2: "Benutzer"}, - PRUEFER : { 0 : "Pruefer", 1: "Benutzer"}, - BENUTZER : { 0: "Benutzer"} - } - - const logout = () => { - window.sessionStorage.removeItem("edbapo-jwt") - props.history.push('/'); - } - - return( - <Row> - <UserDetailsUpdateModal {...props} loggedInUser={props.user} show={showUserSettings} onHide={() => setShowUserSettings(false)}/> - - <Col><b>Nutzername:</b> {nutzername}</Col> - <Col> - <Form.Control as="select" onChange={(event) => props.setAktiveRolle(event.target.value.toUpperCase())}> - {Object.keys(allRoles[rolle]).map( role => <option key={allRoles[rolle][role]} value={allRoles[rolle][role]}>{allRoles[rolle][role]}</option>)} - </Form.Control> - </Col> - <Col> - <Button onClick={() => setShowUserSettings(true)}> - <Settings /> - Einstellungen - </Button> - </Col> - <Col> - <Button onClick={logout}>Logout</Button> - </Col> - </Row> - ) -} - -export default UserDetails; +import React, {useState} from 'react' +import { Button, Col, Row, Form } from 'react-bootstrap'; +import { Settings } from '@material-ui/icons'; +import UserDetailsUpdateModal from '../modals/UserDetailsUpdateModal'; + +function UserDetails(props) { + //eslint disable-next-line + const {rolle, nutzername } = props.user; + const [showUserSettings, setShowUserSettings] = useState(false); + + var allRoles = { + ADMIN : { 0: "Admin", 1 : "Pruefer", 2: "Benutzer"}, + PRUEFER : { 0 : "Pruefer", 1: "Benutzer"}, + BENUTZER : { 0: "Benutzer"} + } + + const logout = () => { + window.sessionStorage.removeItem("edbapo-jwt") + props.history.push('/'); + } + + return( + <Row> + <UserDetailsUpdateModal {...props} loggedInUser={props.user} show={showUserSettings} onHide={() => setShowUserSettings(false)}/> + + <Col><b>Nutzername:</b> {nutzername}</Col> + <Col> + <Form.Control as="select" onChange={(event) => props.setAktiveRolle(event.target.value.toUpperCase())}> + {Object.keys(allRoles[rolle]).map( role => <option key={allRoles[rolle][role]} value={allRoles[rolle][role]}>{allRoles[rolle][role]}</option>)} + </Form.Control> + </Col> + <Col> + <Button onClick={() => setShowUserSettings(true)}> + <Settings /> + Einstellungen + </Button> + </Col> + <Col> + <Button onClick={logout}>Logout</Button> + </Col> + </Row> + ) +} + +export default UserDetails;