diff --git a/Project1/models/Appointments.js b/Project1/models/Appointments.js index ac38a1db..0d18ed8f 100644 --- a/Project1/models/Appointments.js +++ b/Project1/models/Appointments.js @@ -8,19 +8,23 @@ let Appointment = new Schema({ name : { type : String, + required: true }, email:{ type:String, + required: true }, phone:{ type:String, + required: true }, petName:{ type:String, + required: true }, @@ -35,13 +39,19 @@ let Appointment = new Schema({ }, Reason:{ type:String, + required: true }, note:{ type:String, - } + }, + + reggdate: { + type: Date, + default: Date.now, + }, }, { diff --git a/Project1/models/Schedule.js b/Project1/models/Schedule.js new file mode 100644 index 00000000..ab432e95 --- /dev/null +++ b/Project1/models/Schedule.js @@ -0,0 +1,30 @@ + +const mongoose = require('mongoose'); +const Schema = mongoose.Schema; + +let schedule = new Schema({ + + + name: { + type: String, + required: true + }, + + + lname: { + type: String, + required: true + }, + + date: { + type: Date, + default: Date.now + } +}, + { + collection: 'schedule' + } + + ); + + module.exports = mongoose.model ('schedule', schedule) \ No newline at end of file diff --git a/Project1/myapp/src/App.js b/Project1/myapp/src/App.js index 9cdf39b8..32094b52 100644 --- a/Project1/myapp/src/App.js +++ b/Project1/myapp/src/App.js @@ -42,6 +42,9 @@ import PrescriptionListPreview from './components/PrescriptionListPrintPreview' import ShelterListPrintPreview from './components/ShelterListPrintPreview' import SupplierListPrintPreview from './components/SupplierListPrintPreview'; import UserListPrintPreview from './components/UserListPrintPreview'; +import DoctorsList from './components/DoctorsList'; +import ScheduleList from './components/ScheduleList' + class App extends Component { @@ -80,9 +83,10 @@ class App extends Component { }/> }/> }/> - + }/> }/> + }/> }/> @@ -97,7 +101,7 @@ class App extends Component { }/> }/> }/> - + }/> diff --git a/Project1/myapp/src/components/AppointmentList.js b/Project1/myapp/src/components/AppointmentList.js index 7d20b1fd..37e4a937 100644 --- a/Project1/myapp/src/components/AppointmentList.js +++ b/Project1/myapp/src/components/AppointmentList.js @@ -7,6 +7,8 @@ import Form from "react-bootstrap/Form"; import Modal from "react-bootstrap/Modal"; import { withRouter } from "./withRouter"; + + import "../components/CSS/listmain.css"; @@ -127,7 +129,7 @@ function ApplicationList(props) { > Email Address Phone number: -

Application List

+

Appointment List

Total: {count}

@@ -232,11 +235,25 @@ function ApplicationList(props) { - +

View Appointments

+ + + +

Create Schedule

+ + + + + + +

View Schedules

+ + + @@ -249,9 +266,6 @@ function ApplicationList(props) { Name - - Email - Phone @@ -259,17 +273,9 @@ function ApplicationList(props) { Pet Name - Species - - - Breed - - - Reason - - - Note + Date & Time + {tabRow()} diff --git a/Project1/myapp/src/components/AppointmentTableRow.js b/Project1/myapp/src/components/AppointmentTableRow.js index 302f8535..c6c1c3bb 100644 --- a/Project1/myapp/src/components/AppointmentTableRow.js +++ b/Project1/myapp/src/components/AppointmentTableRow.js @@ -17,6 +17,7 @@ const AppointmentTableRow = (props) => { Breed:props.obj.Breed, Reason:props.obj.Reason, note:props.obj.note, + date:props.obj.reggdate, }); const [show, setShow] = useState(false); @@ -71,7 +72,7 @@ const AppointmentTableRow = (props) => { -

Centered Modal

+
Full Name: @@ -113,7 +114,7 @@ const AppointmentTableRow = (props) => { Pet's Name: { Species: @@ -135,7 +136,7 @@ const AppointmentTableRow = (props) => { Breed: { Reasons: { {" "} {appointmentState.name} - {appointmentState.email} {appointmentState.phone} {appointmentState.petName} - {appointmentState.Species} - {appointmentState.Breed} - {appointmentState.Reason} - {appointmentState.note} + {appointmentState.date} + ); diff --git a/Project1/myapp/src/components/DoctorsList.js b/Project1/myapp/src/components/DoctorsList.js new file mode 100644 index 00000000..e8e6ed64 --- /dev/null +++ b/Project1/myapp/src/components/DoctorsList.js @@ -0,0 +1,186 @@ +import React, { useState, useEffect, Component, useRef } from 'react' +import axios from 'axios' +import DoctorsTableRow from './DoctorsTableRow' +import Button from "react-bootstrap/Button"; +import { withRouter } from './withRouter'; +import Table from 'react-bootstrap/Table'; +import { EmployeePrint } from './EmployeePrint'; +import ReactToPrint from 'react-to-print'; +import Form from "react-bootstrap/Form"; +import Modal from "react-bootstrap/Modal"; +import { Link } from "react-router-dom"; + + +import '../components/CSS/listmain.css'; + + + +function DoctorsList(props) { + + + const componentRef = useRef(); + + //read hook + const [employee, setEmployee] = useState([]); + + + //Bootsrap Modal configurations + + const [show, setShow] = useState(false); + const handleClose = () => setShow(false); + const handleShow = () => setShow(true); + + + //get data from database + useEffect(() => { + axios + .get("http://localhost:5000/employee/") + .then((response) => { + setEmployee(response.data); + }) + .catch((error) => { + console.log(error); + }); + }, []); + + + + + const tabRow = () => { + + return employee + .filter((employee) => employee.jobrole === 'doctor') + .map((object, i) => ( + + {object._id} + {object.name} + {object.lname} + {object.date} + + + + + + )); + }; + + //taking count + const [count, setCount] = useState(0); + + useEffect(() => { + axios + .get("http://localhost:5000/employee/get/count") + .then((response) => { + console.log(response); + setCount(response.data); + }) + .catch((error) => { + console.log(error); + }); + }, []); + + + + return ( + <>
+ + + } + + content={() => componentRef.current}> + + + + +

Available Doctors List

+

+ Total: {count} +

+ + + + + { + //-------------------------Display data from database------------------- + } + + + + + + + + + + + + + {tabRow()} +
+ First Name + + Last Name + + Date +
+
+ +
+ + + Add Today's Schedule + + + + + + F Name: + + + + L Name + + + + Date: + + + + + + + + + + + ); +} + +export default withRouter(DoctorsList); diff --git a/Project1/myapp/src/components/DoctorsTableRow.js b/Project1/myapp/src/components/DoctorsTableRow.js new file mode 100644 index 00000000..e69de29b diff --git a/Project1/myapp/src/components/EmployeeLoginList.js b/Project1/myapp/src/components/EmployeeLoginList.js index 8d999fe2..c22dd6d7 100644 --- a/Project1/myapp/src/components/EmployeeLoginList.js +++ b/Project1/myapp/src/components/EmployeeLoginList.js @@ -62,7 +62,7 @@ function EmployeeLoginList(props) { }; //taking count - const [count, setCount] = useState(0); + const [count, setCount] = useState(0); useEffect(() => { axios diff --git a/Project1/myapp/src/components/ScheduleList.js b/Project1/myapp/src/components/ScheduleList.js new file mode 100644 index 00000000..b6fa6dc4 --- /dev/null +++ b/Project1/myapp/src/components/ScheduleList.js @@ -0,0 +1,122 @@ +import React, { useState, useEffect , useRef} from "react"; +import axios from "axios"; +import ScheduleTableRow from "./ScheduleTableRow"; +import { Link } from "react-router-dom"; +import Button from "react-bootstrap/Button"; +import Form from "react-bootstrap/Form"; +import Modal from "react-bootstrap/Modal"; +import { withRouter } from "./withRouter"; + +import "../components/CSS/listmain.css"; + + +function ScheduleList(props) { + //read hook + + const [schedule, setSchedule] = useState([]); + + //insert hook + const [data, setData] = useState({ + name:"", + lname:"", + }); + + const handleChange = (e) => { + const { name, value } = e.target; + + setData((prev) => ({ + ...prev, + [name]: value, + })); + }; + + //Bootsrap Modal configurations + + const [show, setShow] = useState(false); + const handleClose = () => setShow(false); + const handleShow = () => setShow(true); + + //get data from database + useEffect(() => { + axios + .get("http://localhost:5000/schedules/") + .then((response) => { + setSchedule(response.data); + }) + .catch((error) => { + console.log(error); + }); + }, []); + + const tabRow = () => { + return schedule.map((object, i) => { + return ; + }); + }; + + //taking count + const [count, setCount] = useState(0); + + useEffect(() => { + axios + .get("http://localhost:5000/schedules/get/count") + .then((response) => { + console.log(response); + setCount(response.data); + }) + .catch((error) => { + console.log(error); + }); + }, []); + + //send new data to database + const handleClick = (e) => { + e.preventDefault(); + axios + .post(`http://localhost:5000/schedules/add`, data) + .then((res) => { + alert(`Added Successfully`); + handleClose(); + window.location.reload(); + }) + .catch((err) => { + console.log(err); + }); + }; + + return ( +
+ +

Today's Schedule

+

+ Total: {count} +

+ + + + { + //-------------------------Display data from database------------------- + } + + + + + + + + + {tabRow()} +
+ First Name + + Last Name + + Date & Time +
+ +
+ + ); +} + +export default withRouter(ScheduleList); diff --git a/Project1/myapp/src/components/ScheduleTableRow.js b/Project1/myapp/src/components/ScheduleTableRow.js new file mode 100644 index 00000000..8eaeace8 --- /dev/null +++ b/Project1/myapp/src/components/ScheduleTableRow.js @@ -0,0 +1,66 @@ +import React, { useState } from "react"; +import { Link } from "react-router-dom"; +import axios from "axios"; +import Button from "react-bootstrap/Button"; +import Form from "react-bootstrap/Form"; +import Modal from "react-bootstrap/Modal"; +import { withRouter } from "./withRouter"; +import EmployeeLoginTableRow from "./EmployeeLoginTableRow"; + +const ScheduleTableRow = (props) => { + const [scheduleState] = useState({ + _id: props.obj._id, + name:props.obj.name, + lname:props.obj.lname, + date:props.obj.date, + }); + + const [show, setShow] = useState(false); + + const handleClose = () => setShow(false); + const handleShow = () => setShow(true); + + + const onDelete = (id) => { + axios.get(`http://localhost:5000/ /delete/${id}`).then((res) => { + alert(`Deleted Successfully : ${id}`); + window.location.reload(); + }); + }; + + + return ( + + + + + { + //-------------------------Display All data ------------------- + } + + + {" "} + + {scheduleState.name} + {scheduleState.lname} + {EmployeeLoginTableRow.date} + + + + + + + + ); +}; + +export default withRouter(ScheduleTableRow); + + + diff --git a/Project1/routes/Appointments.js b/Project1/routes/Appointments.js index 7764617f..285de1eb 100644 --- a/Project1/routes/Appointments.js +++ b/Project1/routes/Appointments.js @@ -75,6 +75,7 @@ AppointmentRoutes.route('/update/:id').put(async (req, res) => { appointment.Breed = req.body.Breed; appointment.Reason = req.body.Reason; appointment.note = req.body.note; + const today = new Date(); await appointment.save(); res.json(appointment); diff --git a/Project1/routes/Schedule.js b/Project1/routes/Schedule.js new file mode 100644 index 00000000..f2124b36 --- /dev/null +++ b/Project1/routes/Schedule.js @@ -0,0 +1,94 @@ +const express = require('express'); +const ScheduleRoutes = express.Router(); + +let Schedule = require ( "../models/Schedule.js"); + +//insert +ScheduleRoutes.route('/add').post(async function(req,res) { + try { + const today = new Date(); + const Scheduledata = { + name:req.body.name, + lname:req.body.lname, + created: today + }; + + const schedule = await sch.findOne({ NIC:req.body.name }); + + if (!schedule) { + let schedule = new sch(req.body); + schedule.save() + .then(schedule => { + res.status(200).json({'schedule': 'schedule added succesfully'}); + }) + .catch (err => { + res.status(400).send ("Unable to save") + }) + } + else { + res.json({ error: "schedule already added" }); + } + } catch (err) { + res.send("error" + err); + } +}) + +//readAll +ScheduleRoutes.route('/').get(async function (req, res) { +try{ + const schedule = await sch.find(); + res.json(schedule); +} +catch{ + console.log(err); +} +}) + +//delete +ScheduleRoutes.route('/delete/:id').get(async (req, res) => { +try { + const schedule = await sch.findByIdAndRemove({_id: req.params.id }); + + if (schedule) { + res.json('Successfully removed'); + } else { + res.json('schedule not found'); + } +} catch (err) { + res.json(err); +} +}); + +// Update +ScheduleRoutes.route('/update/:id').put(async (req, res) => { +try { + const schedule = await sch.findById(req.params.id); + + if (!schedule) { + return res.status(404).json({ error: 'schedule not found' }); + } + + schedule.name = req.body.schedule_name; + schedule.lname = req.body.schedule_lname; + + await schedule.save(); + res.json(schedule); +} catch (err) { + res.status(500).json({ error: err.message }); +} +}); + +//count +ScheduleRoutes.route('/get/count').get(async function (req, res) { + try { + const count = await sch.countDocuments(); + res.json(count); + } catch (err) { + console.log(err); + res.status(500).send("Server error"); + } +}); + + + +module.exports = ScheduleRoutes; diff --git a/Project1/server.js b/Project1/server.js index 8fc52e81..437ac34e 100644 --- a/Project1/server.js +++ b/Project1/server.js @@ -111,3 +111,8 @@ app.use('/shelters', shelterRoutes); var appointmentsRoutes = require('./routes/Appointments'); app.use('/appointments', appointmentsRoutes); + +var schedulesRoutes = require('./routes/Schedule'); +app.use('/schedules', schedulesRoutes); + +