├── client
├── .gitignore
├── package-lock.json
├── package.json
├── public
│ ├── favicon.ico
│ ├── index.html
│ ├── logo192.png
│ ├── logo512.png
│ ├── manifest.json
│ └── robots.txt
└── src
│ ├── App.css
│ ├── App.js
│ ├── App.test.js
│ ├── Components
│ ├── Admin
│ │ ├── AdminHomePage.js
│ │ ├── AdminProfile.js
│ │ └── Navbar.js
│ ├── Bills
│ │ ├── AddBill.js
│ │ ├── PatientBills.js
│ │ ├── ViewBill.js
│ │ └── index.js
│ ├── Carriers
│ │ ├── AddCarrier.js
│ │ ├── CarrierNav.js
│ │ └── index.js
│ ├── Doctor
│ │ ├── AddDoctor.js
│ │ ├── DoctorList.js
│ │ ├── DoctorNav.js
│ │ ├── EditDoctor.js
│ │ ├── PreviousPatients.js
│ │ └── Profile.js
│ ├── ErrorBoundary
│ │ └── index.js
│ ├── Footer
│ │ └── index.js
│ ├── Home
│ │ ├── Cards.jsx
│ │ ├── Home.styles.js
│ │ └── index.js
│ ├── Loader
│ │ └── index.js
│ ├── Login
│ │ ├── LoginCard.js
│ │ ├── LoginNav.js
│ │ └── index.js
│ ├── Patient
│ │ ├── AdmitPatient.js
│ │ ├── AdmittedPatients.js
│ │ ├── EditPatient.js
│ │ ├── PatientDetails.js
│ │ ├── PatientNav.js
│ │ ├── Patients.js
│ │ ├── Profile.js
│ │ ├── addPatient.js
│ │ ├── secNavBar.js
│ │ └── signUp.js
│ ├── Rooms
│ │ ├── AddRoom.js
│ │ ├── EditRoom.js
│ │ ├── RoomNav.js
│ │ ├── ViewRoom.js
│ │ └── index.js
│ └── header.js
│ ├── Routes
│ ├── doctorRoutes.js
│ ├── entryRoutes.js
│ └── patientRoutes.js
│ ├── assets
│ ├── admin.png
│ ├── background.svg
│ ├── doctor_2.jpg
│ ├── doctor_new.png
│ └── patient.jpg
│ ├── index.css
│ ├── index.js
│ └── utils
│ ├── ProtectedRoute.js
│ ├── Redux
│ ├── loginReducer.js
│ ├── rootReducer.js
│ └── store.js
│ └── axiosInstance.js
└── server
├── .gitignore
├── Dockerfile
├── controllers
├── Admin.js
├── Appointment.js
├── Bill.js
├── Carrier.js
├── Doctor.js
├── Patient.js
├── Room.js
├── Treatement.js
└── User.js
├── db
└── connectDB.js
├── index.js
├── middleware
├── adminDoctorMiddleware.js
├── adminMiddleware.js
├── auth.js
├── doctorMiddleware.js
├── errorMiddleware
│ └── index.js
└── notFound.js
├── models
├── Admin.js
├── Admission.js
├── Bill.js
├── Carrier.js
├── Doctor.js
├── Patient.js
├── Room.js
└── Treatments.js
├── package-lock.json
├── package.json
└── routes
├── Admin.js
├── Bill.js
├── Carrier.js
├── Doctor.js
├── Patient.js
├── Room.js
├── Treatement.js
└── User.js
/client/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | .env
--------------------------------------------------------------------------------
/client/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "client",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@fortawesome/fontawesome-svg-core": "^1.2.35",
7 | "@fortawesome/free-brands-svg-icons": "^5.15.3",
8 | "@fortawesome/free-regular-svg-icons": "^5.15.3",
9 | "@fortawesome/free-solid-svg-icons": "^5.15.3",
10 | "@fortawesome/react-fontawesome": "^0.1.14",
11 | "@material-ui/core": "^4.12.3",
12 | "@testing-library/jest-dom": "^5.12.0",
13 | "@testing-library/react": "^11.2.6",
14 | "@testing-library/user-event": "^12.8.3",
15 | "axios": "^0.21.1",
16 | "bootstrap": "^4.6.0",
17 | "gh-pages": "^3.2.0",
18 | "js-cookie": "^2.2.1",
19 | "jwt-decode": "^3.1.2",
20 | "loadash": "^1.0.0",
21 | "moment": "^2.29.4",
22 | "react": "^17.0.2",
23 | "react-dom": "^17.0.2",
24 | "react-icons": "^4.8.0",
25 | "react-redux": "^7.2.6",
26 | "react-router-dom": "^5.2.0",
27 | "react-scripts": "4.0.3",
28 | "react-social-icons": "^5.2.0",
29 | "reactstrap": "^8.9.0",
30 | "reactstrap-date-picker": "^1.0.9",
31 | "redux": "^4.1.2",
32 | "styled-components": "^5.3.3",
33 | "web-vitals": "^1.1.1"
34 | },
35 | "scripts": {
36 | "start": "react-scripts start",
37 | "build": "react-scripts build",
38 | "test": "react-scripts test",
39 | "eject": "react-scripts eject"
40 | },
41 | "eslintConfig": {
42 | "extends": [
43 | "react-app",
44 | "react-app/jest"
45 | ]
46 | },
47 | "browserslist": {
48 | "production": [
49 | ">0.2%",
50 | "not dead",
51 | "not op_mini all"
52 | ],
53 | "development": [
54 | "last 1 chrome version",
55 | "last 1 firefox version",
56 | "last 1 safari version"
57 | ]
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/client/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sainikhil1605/Hospital-Management-System-MERN-Stack/3043ca5517a69ae3b66bd9b50f0ca4c43bf2bfcc/client/public/favicon.ico
--------------------------------------------------------------------------------
/client/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | In Patient Managament System
28 |
29 |
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/client/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sainikhil1605/Hospital-Management-System-MERN-Stack/3043ca5517a69ae3b66bd9b50f0ca4c43bf2bfcc/client/public/logo192.png
--------------------------------------------------------------------------------
/client/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sainikhil1605/Hospital-Management-System-MERN-Stack/3043ca5517a69ae3b66bd9b50f0ca4c43bf2bfcc/client/public/logo512.png
--------------------------------------------------------------------------------
/client/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/client/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/client/src/App.css:
--------------------------------------------------------------------------------
1 | body {
2 | overflow-x: hidden;
3 | }
4 | .App {
5 | text-align: center;
6 | }
7 | li {
8 | list-style: none;
9 | }
10 | li :active {
11 | color: white;
12 | }
13 | .App-logo {
14 | height: 40vmin;
15 | pointer-events: none;
16 | }
17 | .header {
18 | background-color: #242526;
19 | color: white;
20 | border-radius: 0;
21 | }
22 | @media (prefers-reduced-motion: no-preference) {
23 | .App-logo {
24 | animation: App-logo-spin infinite 20s linear;
25 | }
26 | }
27 | .App-header {
28 | background-color: #282c34;
29 | min-height: 100vh;
30 | display: flex;
31 | flex-direction: column;
32 | align-items: center;
33 | justify-content: center;
34 | font-size: calc(10px + 2vmin);
35 | color: white;
36 | }
37 |
38 | .App-link {
39 | color: #61dafb;
40 | }
41 | @keyframes App-logo-spin {
42 | from {
43 | transform: rotate(0deg);
44 | }
45 | to {
46 | transform: rotate(360deg);
47 | }
48 | }
49 | /* .header {
50 | background-color: rgb(144, 144, 221);
51 | color: white;
52 | } */
53 | .nav-link {
54 | color: white;
55 | }
56 | a {
57 | list-style: none;
58 | text-decoration: none;
59 | /* color: white; */
60 | }
61 | a:hover {
62 | list-style: none;
63 | text-decoration: none;
64 | }
65 | footer {
66 | padding-top: 50px;
67 | background-color: #223c50;
68 | color: white;
69 | }
70 |
71 | .container {
72 | display: flex;
73 | justify-content: space-around;
74 | align-items: flex-start;
75 | padding: "0px 0px";
76 | }
77 | @media (max-width: 768px) {
78 | .container {
79 | display: flex;
80 | flex-direction: column;
81 | padding: 0px;
82 | align-items: center;
83 | }
84 | img {
85 | width: 100%;
86 | }
87 | }
88 | @media (min-width: 1200px) {
89 | .container {
90 | max-width: 100%;
91 | padding: 0px;
92 | }
93 | }
94 | @media (max-width: 1200px) {
95 | .container {
96 | max-width: 100%;
97 | padding: 0px;
98 | }
99 | }
100 | .footer {
101 | margin-top: 10px;
102 | padding-top: 20px;
103 | background-color: #223c50;
104 | color: white;
105 | }
106 | .DocForm {
107 | margin-top: 200px;
108 | margin-left: 200px;
109 | }
110 | @media (max-width: 760px) {
111 | .DocForm {
112 | margin-left: 0px;
113 | margin-top: 50px;
114 | }
115 | }
116 | .mynav a {
117 | color: white;
118 | margin-left: 10px;
119 | }
120 |
--------------------------------------------------------------------------------
/client/src/App.js:
--------------------------------------------------------------------------------
1 | import { Provider } from "react-redux";
2 | import { Route, Switch, useLocation } from "react-router-dom";
3 | import "./App.css";
4 | import NavBar from "./Components/Admin/Navbar";
5 | import ErrorBoundary from "./Components/ErrorBoundary";
6 | import Footer from "./Components/Footer";
7 | import Home from "./Components/Home";
8 | import LogIn from "./Components/Login";
9 | import store from "./utils/Redux/store";
10 | import AdminProfile from "./Components/Admin/AdminProfile";
11 | import Header from "./Components/header";
12 |
13 | import Bills from "./Components/Bills";
14 | import ViewBill from "./Components/Bills/ViewBill";
15 | import Patients from "./Components/Patient/Patients";
16 | import AddPatientForm from "./Components/Patient/addPatient";
17 | import AddDoctor from "./Components/Doctor/AddDoctor";
18 | import DoctorNav from "./Components/Doctor/DoctorNav";
19 | import DoctorList from "./Components/Doctor/DoctorList";
20 | import AddBill from "./Components/Bills/AddBill";
21 | import PatientNav from "./Components/Patient/PatientNav";
22 | import AdmitPatient from "./Components/Patient/AdmitPatient";
23 | import PatientDetails from "./Components/Patient/PatientDetails";
24 | import Profile from "./Components/Patient/Profile";
25 | import PatientBills from "./Components/Bills/PatientBills";
26 | import Rooms from "./Components/Rooms";
27 | import ViewRoom from "./Components/Rooms/ViewRoom";
28 | import Carrier from "./Components/Carriers";
29 | import RoomNav from "./Components/Rooms/RoomNav";
30 | import AddRoom from "./Components/Rooms/AddRoom";
31 | import CarrierNav from "./Components/Carriers/CarrierNav";
32 | import AddCarrier from "./Components/Carriers/AddCarrier";
33 | import EditDoctor from "./Components/Doctor/EditDoctor";
34 | import ProtectedRoute from "./utils/ProtectedRoute";
35 | import EditPatientForm from "./Components/Patient/EditPatient";
36 | import EditRoom from "./Components/Rooms/EditRoom";
37 | import AdmittedPatients from "./Components/Patient/AdmittedPatients";
38 | import DoctorProfile from "./Components/Doctor/Profile";
39 | import PreviousPatients from "./Components/Doctor/PreviousPatients";
40 | function App() {
41 | const location = useLocation();
42 | return (
43 |
44 |
45 | {location.pathname !== "/login" && location.pathname !== "/" && (
46 | <>
47 |
48 |
49 | >
50 | )}
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 | );
154 | }
155 | export default App;
156 |
--------------------------------------------------------------------------------
/client/src/App.test.js:
--------------------------------------------------------------------------------
1 | import { render, screen } from "@testing-library/react";
2 | import App from "./App";
3 |
4 | test("renders learn react link", () => {
5 | render();
6 | const linkElement = screen.getByText(/learn react/i);
7 | expect(linkElement).toBeInTheDocument();
8 | });
9 |
--------------------------------------------------------------------------------
/client/src/Components/Admin/AdminHomePage.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { useSelector } from "react-redux";
3 | import { useParams } from "react-router-dom";
4 | import AddDepartmentForm from "../Department/addDepartment";
5 | import GetDepartment from "../Department/getDepartment";
6 | import FeedBack from "../Feedback";
7 | import Header from "../header";
8 | import Patients from "../Patient/Patients";
9 | function AdminHomePage() {
10 | const name = useSelector((state) => state.login.name);
11 | const { pagename } = useParams();
12 | const getPage = () => {
13 | switch (pagename) {
14 | case "addDepartment":
15 | return ;
16 | case "getDepartment":
17 | return ;
18 | case "profile":
19 | return;
20 | case "feedback":
21 | return ;
22 | case "patients":
23 | return ;
24 | case "addPatient":
25 | return ;
26 | default:
27 | return Page Not Found
;
28 | }
29 | };
30 | return (
31 |
32 |
33 | {getPage()}
34 |
35 | );
36 | }
37 | export default AdminHomePage;
38 |
--------------------------------------------------------------------------------
/client/src/Components/Admin/AdminProfile.js:
--------------------------------------------------------------------------------
1 | import jwt from "jwt-decode";
2 | import React, { useEffect, useState } from "react";
3 | import { Button, Col, Form, FormGroup, Input, Label, Row } from "reactstrap";
4 | import axiosInstance from "../../utils/axiosInstance";
5 | import Loader from "../Loader";
6 | import { useHistory } from "react-router-dom";
7 | function AdminProfile() {
8 | const [adminDetails, setAdminDetails] = useState();
9 | const { _id } = jwt(localStorage.getItem("token"));
10 | const [loading, setLoading] = useState(true);
11 | const [oldPassword, setOldPassword] = useState(null);
12 | const [newPassword, setNewPassword] = useState(null);
13 | const [showChangePassword, setShowChangePassword] = useState(false);
14 | const history = useHistory();
15 | useEffect(() => {
16 | if (localStorage.getItem("token") === null) {
17 | history.push("/login");
18 | }
19 | const getProfile = async () => {
20 | setLoading(true);
21 | const res = await axiosInstance.get(`/admin/${_id}`);
22 | if (res.status === 200) {
23 | setAdminDetails(res.data.admin);
24 | setLoading(false);
25 | } else {
26 | console.log(res.data.error);
27 | }
28 | };
29 |
30 | getProfile();
31 | }, []);
32 | const handleSubmit = async () => {
33 | await axiosInstance.patch(`/admin/${_id}`, { ...adminDetails });
34 | window.location.reload();
35 | };
36 | const handlePasswordChange = async () => {
37 | try {
38 | const res = await axiosInstance.patch(`/update/${_id}`, {
39 | oldPassword,
40 | newPassword,
41 | role: "admin",
42 | });
43 | if (res.status === 200) {
44 | setShowChangePassword(false);
45 | window.alert("Password Changed Successfully");
46 | }
47 | } catch (e) {
48 | console.log(e.response.data.error);
49 | window.alert(e.response.data.error);
50 | }
51 | };
52 | if (loading) {
53 | return ;
54 | }
55 | if (showChangePassword) {
56 | return (
57 |
58 |
59 |
60 |
61 | Change Password
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | {
74 | const temp = e.target.value;
75 | setOldPassword(temp);
76 | }}
77 | />
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 | {
92 | const temp = e.target.value;
93 | setNewPassword(temp);
94 | }}
95 | />
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | );
107 | }
108 | return (
109 |
110 |
111 |
112 |
113 | Edit Profile
114 |
195 |
196 |
197 |
198 |
199 | );
200 | }
201 | export default AdminProfile;
202 |
--------------------------------------------------------------------------------
/client/src/Components/Admin/Navbar.js:
--------------------------------------------------------------------------------
1 | import jwtDecode from "jwt-decode";
2 | import React, { useState } from "react";
3 | import { useDispatch } from "react-redux";
4 | import { NavLink, useHistory } from "react-router-dom";
5 | import { FaBriefcaseMedical, FaMoneyBill } from "react-icons/fa";
6 | import { GiMedicalThermometer } from "react-icons/gi";
7 | import { CgProfile } from "react-icons/cg";
8 | import { RiHospitalFill } from "react-icons/ri";
9 | import { GiTwoCoins } from "react-icons/gi";
10 | import {
11 | Button,
12 | Collapse,
13 | Nav,
14 | Navbar,
15 | NavbarText,
16 | NavbarToggler,
17 | NavItem,
18 | } from "reactstrap";
19 | function NavBar() {
20 | const [isOpen, setOpen] = useState(false);
21 | const dispatch = useDispatch();
22 | const history = useHistory();
23 | const Logout = () => {
24 | dispatch({ type: "LOG_OUT" });
25 | history.push("/");
26 | };
27 | const { role } = jwtDecode(localStorage.getItem("token"));
28 | console.log(role);
29 | if (role === "patient") {
30 | return (
31 |
32 |
33 | setOpen(!isOpen)} />
34 |
35 |
77 |
78 |
79 |
82 |
83 |
84 |
85 |
86 | );
87 | }
88 | if (role === "doctor") {
89 | return (
90 |
91 |
92 | setOpen(!isOpen)} />
93 |
94 |
120 |
121 |
122 |
125 |
126 |
127 |
128 |
129 | );
130 | }
131 | return (
132 |
133 |
134 | setOpen(!isOpen)} />
135 |
136 |
199 |
200 |
201 |
204 |
205 |
206 |
207 |
208 | );
209 | }
210 |
211 | export default NavBar;
212 |
--------------------------------------------------------------------------------
/client/src/Components/Bills/AddBill.js:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from "react";
2 | import { Button, Col, Form, FormGroup, Input, Label, Row } from "reactstrap";
3 | import axiosInstance from "../../utils/axiosInstance";
4 |
5 | const AddBill = () => {
6 | const [bill, setBillDetails] = useState([]);
7 | const [patients, setPatients] = useState([]);
8 | const [doctors, setDoctors] = useState([]);
9 | useEffect(() => {
10 | const getPatients = async () => {
11 | const {
12 | data: { patients },
13 | } = await axiosInstance.get("/patient");
14 | setPatients(patients);
15 | };
16 | const getDoctors = async () => {
17 | const {
18 | data: { doctors },
19 | } = await axiosInstance.get("/doctor");
20 | setDoctors(doctors);
21 | };
22 |
23 | getPatients();
24 | getDoctors();
25 | }, []);
26 | const handleSubmit = () => {
27 | console.log(bill);
28 | };
29 | return (
30 |
142 | );
143 | };
144 |
145 | export default AddBill;
146 |
--------------------------------------------------------------------------------
/client/src/Components/Bills/PatientBills.js:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from "react";
2 | import jwt from "jwt-decode";
3 | import axiosInstance from "../../utils/axiosInstance";
4 | import { Button, Col, Row, Table } from "reactstrap";
5 | import moment from "moment";
6 | import { useHistory } from "react-router-dom";
7 | import Loader from "../Loader";
8 | const PatientBills = () => {
9 | const { _id: patientId } = jwt(localStorage.getItem("token"));
10 | const [bills, setBills] = useState([]);
11 | const [loading, setLoading] = useState(true);
12 | const history = useHistory();
13 | useEffect(() => {
14 | if (localStorage.getItem("token") === null) {
15 | history.push("/login");
16 | }
17 | const getData = async () => {
18 | setLoading(true);
19 | const {
20 | data: { bill },
21 | } = await axiosInstance.get(`/patient/bill/${patientId}`);
22 | setBills(bill);
23 | setLoading(false);
24 | };
25 | getData();
26 | }, []);
27 | if (loading) {
28 | return ;
29 | }
30 | return (
31 |
32 |
33 |
34 |
42 |
43 |
44 | | S.No |
45 |
46 | Net Payable Cost |
47 | Discharge Date |
48 |
49 |
50 |
51 | {bills.map((bill, index) => {
52 | return (
53 |
54 | | {index + 1} |
55 |
56 | {bill.net_payable_cost} |
57 | {moment(bill.discharge_date).format("YYYY-MM-DD")} |
58 |
59 |
66 | |
67 |
68 | );
69 | })}
70 |
71 |
72 |
73 | );
74 | };
75 | export default PatientBills;
76 |
--------------------------------------------------------------------------------
/client/src/Components/Bills/ViewBill.js:
--------------------------------------------------------------------------------
1 | import { useParams } from "react-router-dom";
2 | import { useEffect, useState } from "react";
3 | import axiosInstance from "../../utils/axiosInstance";
4 | import { Col, Row, Table } from "reactstrap";
5 | import moment from "moment";
6 | import _ from "lodash";
7 | function ViewBill() {
8 | const { billId } = useParams();
9 | const [bill, setBill] = useState();
10 | const formatBill = (bill) => {
11 | const formatedBill = {};
12 | if (bill !== null && bill !== undefined) {
13 | Object?.keys(bill)?.forEach((key) => {
14 | if (key === "admission_id") {
15 | formatedBill.doctor_name = bill[key]["doctor_id"]["name"];
16 | formatedBill.doctor_fee = bill[key]["doctor_id"]["fee"];
17 | formatedBill.insurance_name = bill[key]["insurance_id"]["name"];
18 | formatedBill.insurance_percentage =
19 | bill[key]["insurance_id"]["percentage"];
20 | formatedBill.admit_date = moment(bill[key].admit_date).format(
21 | "YYYY-MM-DD"
22 | );
23 | formatedBill.treatments = bill[key].treatments;
24 | } else if (key === "patient_id") {
25 | formatedBill.patient_name = bill[key].name;
26 | } else {
27 | if (key !== "__v") {
28 | formatedBill[key] = bill[key];
29 | }
30 | if (key === "discharge_date") {
31 | formatedBill[key] = moment(bill[key]).format("YYYY-MM-DD");
32 | }
33 | }
34 | });
35 | }
36 | return formatedBill;
37 | };
38 | useEffect(() => {
39 | const getData = async () => {
40 | const {
41 | data: { bill },
42 | } = await axiosInstance.get(`/bill/${billId}`);
43 | if (bill !== null || bill !== undefined) {
44 | const formatedBill = formatBill(bill);
45 | setBill(_.omit(formatedBill, ["_id"]));
46 | }
47 | };
48 | getData();
49 | }, []);
50 | if (!bill) {
51 | return <>>;
52 | }
53 | return (
54 | <>
55 |
56 |
57 | Treatments
58 |
66 |
67 |
68 | | Type |
69 | Amount |
70 |
71 |
72 |
73 | {bill["treatments"].map((treatement) => (
74 |
75 | | {treatement.name} |
76 | {treatement.cost} |
77 |
78 | ))}
79 |
80 |
81 |
82 |
83 |
84 |
85 | Bill
86 |
94 |
95 | {Object.keys(bill).map((key) => {
96 | if (key === "treatments") {
97 | return <>>;
98 | } else {
99 | return (
100 |
101 | | {_.startCase(key.split("_").join(" "))} |
102 | {bill[key]} |
103 |
104 | );
105 | }
106 | })}
107 |
108 |
109 |
110 |
111 | >
112 | );
113 | }
114 | export default ViewBill;
115 |
--------------------------------------------------------------------------------
/client/src/Components/Bills/index.js:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from "react";
2 | import { useHistory, useLocation } from "react-router-dom";
3 | import { Button, Col, Row, Table } from "reactstrap";
4 | import axiosInstance from "../../utils/axiosInstance";
5 | import moment from "moment";
6 | function Bills() {
7 | const [bills, setBills] = useState();
8 | const history = useHistory();
9 | useEffect(() => {
10 | const getData = async () => {
11 | const {
12 | data: { bills },
13 | } = await axiosInstance.get("/bill");
14 |
15 | setBills([...bills]);
16 | };
17 | getData();
18 | }, []);
19 | if (!bills) {
20 | return <>>;
21 | }
22 | return (
23 |
24 |
25 |
26 |
34 |
35 |
36 | | S.No |
37 | Patient Name |
38 | Net Payable Cost |
39 | Discharge Date |
40 |
41 |
42 |
43 | {bills.map((bill, index) => {
44 | return (
45 |
46 | | {index + 1} |
47 | {bill.patient_id.name} |
48 | {bill.net_payable_cost} |
49 | {moment(bill.discharge_date).format("YYYY-MM-DD")} |
50 |
51 |
58 | |
59 |
60 | );
61 | })}
62 |
63 |
64 |
65 | );
66 | }
67 | export default Bills;
68 |
--------------------------------------------------------------------------------
/client/src/Components/Carriers/AddCarrier.js:
--------------------------------------------------------------------------------
1 | import { useState } from "react";
2 | import { useHistory } from "react-router-dom";
3 | import axiosInstance from "../../utils/axiosInstance";
4 | import { Button, Col, Form, FormGroup, Input, Label, Row } from "reactstrap";
5 |
6 | const AddCarrier = () => {
7 | const [carrier, setCarrier] = useState({
8 | name: "",
9 | percentage: "",
10 | });
11 | const history = useHistory();
12 | const handleSubmit = async (e) => {
13 | e.preventDefault();
14 | const { data } = await axiosInstance.post("/carrier", carrier);
15 | history.push(`/carriers`);
16 | };
17 | return (
18 |
19 |
Add Carrier
20 |
55 |
56 | );
57 | };
58 | export default AddCarrier;
59 |
--------------------------------------------------------------------------------
/client/src/Components/Carriers/CarrierNav.js:
--------------------------------------------------------------------------------
1 | import jwtDecode from "jwt-decode";
2 | import { AiOutlineOrderedList } from "react-icons/ai";
3 | import { GrAddCircle } from "react-icons/gr";
4 | import { Link, useLocation } from "react-router-dom";
5 | import { Nav, NavItem, NavLink } from "reactstrap";
6 |
7 | const CarrierNav = ({ children }) => {
8 | const location = useLocation();
9 | const { role } = jwtDecode(localStorage.getItem("token"));
10 | return (
11 | <>
12 | {role === "admin" && (
13 | <>
14 |
36 | >
37 | )}
38 | {children}
39 | >
40 | );
41 | };
42 | export default CarrierNav;
43 |
--------------------------------------------------------------------------------
/client/src/Components/Carriers/index.js:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from "react";
2 | import { useHistory } from "react-router-dom";
3 | import axiosInstance from "../../utils/axiosInstance";
4 | import { Table } from "reactstrap";
5 |
6 | const Carrier = () => {
7 | const [carrier, setCarrier] = useState([]);
8 | const history = useHistory();
9 | useEffect(() => {
10 | const getData = async () => {
11 | const {
12 | data: { carriers },
13 | } = await axiosInstance.get("/carrier");
14 | setCarrier([...carriers]);
15 | };
16 | getData();
17 | }, []);
18 |
19 | return (
20 |
21 |
22 | This is the list of Insurance carriers we support
23 |
24 |
33 |
34 |
35 | | S.no |
36 | Carrier Name |
37 | Carrier Percentage |
38 |
39 |
40 |
41 | {carrier.map((carrier, index) => {
42 | return (
43 |
44 | | {index + 1} |
45 | {carrier.name} |
46 | {carrier.percentage} |
47 |
48 | );
49 | })}
50 |
51 |
52 |
53 | );
54 | };
55 | export default Carrier;
56 |
--------------------------------------------------------------------------------
/client/src/Components/Doctor/AddDoctor.js:
--------------------------------------------------------------------------------
1 | import { useState } from "react";
2 | import { useHistory, useLocation } from "react-router-dom";
3 | import { Button, Col, Form, FormGroup, Input, Label, Row } from "reactstrap";
4 | import axiosInstance from "../../utils/axiosInstance";
5 |
6 | const AddDoctor = () => {
7 | const [docDetails, setDocDetails] = useState({});
8 | const location = useLocation();
9 | const history = useHistory();
10 | const handleSubmit = async () => {
11 | const data = await axiosInstance.post("/doctor", docDetails);
12 | if (data.status === 201) {
13 | history.push("/doctors");
14 | }
15 | };
16 | return (
17 | <>
18 |
125 | >
126 | );
127 | };
128 | export default AddDoctor;
129 |
--------------------------------------------------------------------------------
/client/src/Components/Doctor/DoctorList.js:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useState } from "react";
2 | import { useSelector } from "react-redux";
3 | import { Button, Col, Input, Row, Table } from "reactstrap";
4 | import axiosInstance from "../../utils/axiosInstance";
5 | import Loader from "../Loader";
6 | import { useHistory, useLocation } from "react-router-dom";
7 | function DoctorList() {
8 | const [doctors, setDoctors] = useState([]);
9 | const [search, setSearch] = useState("");
10 | const role = useSelector((state) => state.login.role);
11 | const [loading, setLoading] = useState(true);
12 | const history = useHistory();
13 | const location = useLocation();
14 | useEffect(() => {
15 | const getData = async () => {
16 | setLoading(true);
17 | const res = await axiosInstance.get("/doctor");
18 | if (res.status === 200) {
19 | setDoctors(res.data.doctors);
20 | setLoading(false);
21 | }
22 | };
23 | getData();
24 | }, []);
25 | const handleDelete = async (id) => {
26 | await axiosInstance.delete(`/doctor/${id}`);
27 | location.reload();
28 | };
29 | if (loading) {
30 | return ;
31 | }
32 | return (
33 |
113 | );
114 | }
115 |
116 | export default DoctorList;
117 |
--------------------------------------------------------------------------------
/client/src/Components/Doctor/DoctorNav.js:
--------------------------------------------------------------------------------
1 | import jwtDecode from "jwt-decode";
2 | import { Link, useLocation } from "react-router-dom";
3 | import { Nav, NavItem, NavLink } from "reactstrap";
4 | import { GrAddCircle } from "react-icons/gr";
5 | import { AiOutlineOrderedList } from "react-icons/ai";
6 | const DoctorNav = ({ children }) => {
7 | const location = useLocation();
8 | const { role } = jwtDecode(localStorage.getItem("token"));
9 | return (
10 | <>
11 | {role === "admin" && (
12 | <>
13 |
35 | >
36 | )}
37 | {children}
38 | >
39 | );
40 | };
41 | export default DoctorNav;
42 |
--------------------------------------------------------------------------------
/client/src/Components/Doctor/EditDoctor.js:
--------------------------------------------------------------------------------
1 | import { useHistory, useLocation, useParams } from "react-router-dom";
2 | import { Button, Col, Form, FormGroup, Input, Label, Row } from "reactstrap";
3 | import axiosInstance from "../../utils/axiosInstance";
4 | import { useEffect, useState } from "react";
5 |
6 | const EditDoctor = (props) => {
7 | const { id } = useParams();
8 | const [doctor, setDoctor] = useState({});
9 | // const [departments, setDepartments] = useState([]);
10 | // const [docDetails, setDocDetails] = useState({});
11 | const location = useLocation();
12 | const history = useHistory();
13 | const handleSubmit = async () => {
14 | const data = await axiosInstance.patch(`/doctor/${id}`, doctor);
15 | if (data.status === 200) {
16 | history.push("/doctors");
17 | }
18 | };
19 | useEffect(() => {
20 | const getData = async () => {
21 | const {
22 | data: { doctor },
23 | } = await axiosInstance.get(`/doctor/${id}`);
24 | setDoctor(doctor);
25 | };
26 | getData();
27 | }, [id]);
28 | return (
29 | <>
30 |
122 | >
123 | );
124 | };
125 | export default EditDoctor;
126 |
--------------------------------------------------------------------------------
/client/src/Components/Doctor/PreviousPatients.js:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from "react";
2 | import axiosInstance from "../../utils/axiosInstance";
3 | import jwtDecode from "jwt-decode";
4 | import { Table } from "reactstrap";
5 | import moment from "moment";
6 |
7 | const PreviousPatients = () => {
8 | const [patients, setPatients] = useState(null);
9 | useEffect(() => {
10 | const getData = async () => {
11 | const { _id } = jwtDecode(localStorage.getItem("token"));
12 | const {
13 | data: { patients },
14 | } = await axiosInstance.get(`/doctor/previousPatients/${_id}`);
15 | setPatients(patients);
16 | };
17 | getData();
18 | }, []);
19 | if (!patients) {
20 | return ;
21 | }
22 | return (
23 |
24 |
25 |
26 | | S.No |
27 | Name |
28 | Admit Date |
29 |
30 | {patients.map((patient, index) => (
31 |
32 | | {index + 1} |
33 |
34 | {patient.patient_id.name} |
35 | {moment(patient.admit_date).format("MM-DD-YYYY")} |
36 |
37 | ))}
38 |
39 |
40 | );
41 | };
42 | export default PreviousPatients;
43 |
--------------------------------------------------------------------------------
/client/src/Components/Doctor/Profile.js:
--------------------------------------------------------------------------------
1 | import jwt from "jwt-decode";
2 | import React, { useEffect, useState } from "react";
3 | import { useHistory } from "react-router-dom";
4 | import { Button, Col, Form, FormGroup, Input, Label, Row } from "reactstrap";
5 | import axiosInstance from "../../utils/axiosInstance";
6 | import Loader from "../Loader";
7 |
8 | function Profile() {
9 | const [patientDetails, setPatientDetails] = useState({});
10 | const [loading, setLoading] = useState(true);
11 | const { _id } = jwt(localStorage.getItem("token"));
12 | const [oldPassword, setOldPassword] = useState("");
13 | const [newPassword, setNewPassword] = useState("");
14 | const [showChangePassword, setShowChangePassword] = useState(false);
15 | const history = useHistory();
16 | useEffect(() => {
17 | if (localStorage.getItem("token") === null) {
18 | history.push("/login");
19 | }
20 | const getData = async () => {
21 | setLoading(true);
22 | const res = await axiosInstance.get(`/doctor/${_id}`);
23 | if (res.status === 200) {
24 | setPatientDetails(res.data.doctor);
25 | setLoading(false);
26 | }
27 | };
28 | getData();
29 | }, [_id]);
30 | const handleSubmit = async () => {
31 | const res = await axiosInstance.patch(`/doctor/${_id}`, {
32 | ...patientDetails,
33 | });
34 | alert("Details Updated Successfully");
35 | };
36 | const handlePasswordChange = async () => {
37 | try {
38 | const res = await axiosInstance.patch(`/update/${_id}`, {
39 | oldPassword,
40 | newPassword,
41 | role: "doctor",
42 | });
43 | if (res.status === 200) {
44 | setShowChangePassword(false);
45 | window.alert("Password Changed Successfully");
46 | }
47 | } catch (e) {
48 | console.log(e.response.data.error);
49 | window.alert(e.response.data.error);
50 | }
51 | };
52 |
53 | console.log(patientDetails);
54 | if (loading) {
55 | return ;
56 | }
57 | if (showChangePassword) {
58 | return (
59 |
60 |
61 |
62 |
63 | Change Password
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | {
76 | const temp = e.target.value;
77 | setOldPassword(temp);
78 | }}
79 | />
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 | {
94 | const temp = e.target.value;
95 | setNewPassword(temp);
96 | }}
97 | />
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 | );
109 | }
110 | return (
111 |
112 |
113 |
114 |
115 | Edit Profile
116 |
188 |
189 |
190 |
191 |
192 | );
193 | }
194 |
195 | export default Profile;
196 |
--------------------------------------------------------------------------------
/client/src/Components/ErrorBoundary/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import styled from 'styled-components';
3 | const Container = styled.div`
4 | display: flex;
5 | height: 100vh;
6 | justify-content: center;
7 | align-items: center;
8 | `;
9 | class ErrorBoundary extends React.Component {
10 | constructor(props) {
11 | super(props);
12 | this.state = {
13 | hasError: false,
14 | };
15 | }
16 | static getDerivedStateFromError(error) {
17 | return {
18 | hasError: true,
19 | };
20 | }
21 | componentDidCatch(error, info) {
22 | console.log(error);
23 | console.log(info);
24 | }
25 | render() {
26 | if (this.state.hasError) {
27 | return (
28 |
29 | Something went wrong
30 |
31 | );
32 | }
33 | return this.props.children;
34 | }
35 | }
36 | export default ErrorBoundary;
37 |
--------------------------------------------------------------------------------
/client/src/Components/Footer/index.js:
--------------------------------------------------------------------------------
1 | import { Container, Row, Col } from "reactstrap";
2 | import { faPhone, faEnvelope } from "@fortawesome/free-solid-svg-icons";
3 | import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
4 | import { SocialIcon } from "react-social-icons";
5 | function Footer() {
6 | return (
7 |
65 | );
66 | }
67 | export default Footer;
68 |
--------------------------------------------------------------------------------
/client/src/Components/Home/Cards.jsx:
--------------------------------------------------------------------------------
1 | import { Button } from "@material-ui/core";
2 | import React from "react";
3 | import { useHistory } from "react-router-dom";
4 | import { HomeCard } from "./Home.styles";
5 | function Card({ role, src, link }) {
6 | const history = useHistory();
7 | return (
8 |
9 |
10 | {role.toUpperCase()}
11 | Click Below to Login
12 |
13 |
14 | );
15 | }
16 |
17 | export default Card;
18 |
19 |
--------------------------------------------------------------------------------
/client/src/Components/Home/Home.styles.js:
--------------------------------------------------------------------------------
1 | import styled from "styled-components";
2 |
3 | const HomeContainer = styled.div`
4 | display: flex;
5 | flex-direction: column;
6 | width: 100%;
7 | display: "flex";
8 |
9 | padding-top: 20px;
10 | margin-top: 0;
11 | margin-bottom: 0px;
12 | padding-bottom: 30px;
13 | background-color: #242526;
14 | color: "white";
15 | `;
16 | const HomeItem = styled.div`
17 | flex: 1;
18 | `;
19 | const HomeBody = styled.div`
20 | display: flex;
21 | width: 100%;
22 | @media (max-width: 780px) {
23 | flex-direction: column;
24 | }
25 | padding: 5px;
26 | `;
27 | const HomeCard = styled.div`
28 | display: flex;
29 | flex-direction: column;
30 | align-items: center;
31 | justify-content: center;
32 | flex: 1;
33 | margin: 5px;
34 | `;
35 | export { HomeContainer, HomeItem, HomeBody, HomeCard };
36 |
--------------------------------------------------------------------------------
/client/src/Components/Home/index.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import admin from "../../assets/admin.png";
3 | import patient from "../../assets/patient.jpg";
4 | import doctor from "../../assets/doctor_new.png";
5 | import Card from "./Cards";
6 | import { HomeBody, HomeContainer, HomeItem } from "./Home.styles";
7 | function Home() {
8 | return (
9 | <>
10 |
11 |
18 | Global Hospitals
19 |
20 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | >
34 | );
35 | }
36 |
37 | export default Home;
38 |
--------------------------------------------------------------------------------
/client/src/Components/Loader/index.js:
--------------------------------------------------------------------------------
1 | import { CircularProgress } from '@material-ui/core';
2 | import React from 'react';
3 | import styled from 'styled-components';
4 |
5 | const LoaderOuterContainer = styled.div`
6 | height: 100vh;
7 | width: 100%;
8 | display: flex;
9 | align-items: center;
10 | justify-content: center;
11 | `;
12 |
13 | function Loader() {
14 | return (
15 |
16 |
17 |
18 | );
19 | }
20 | export default Loader;
21 |
--------------------------------------------------------------------------------
/client/src/Components/Login/LoginCard.js:
--------------------------------------------------------------------------------
1 | import { Card, CardBody, CardImg, CardTitle, Col } from "reactstrap";
2 | import admin from "../../assets/admin.png";
3 | export default function LoginCard({ role }) {
4 | return (
5 |
6 |
7 |
8 |
9 | Hello!! {role.toUpperCase()}
10 |
11 |
12 |
13 | );
14 | }
15 |
--------------------------------------------------------------------------------
/client/src/Components/Login/LoginNav.js:
--------------------------------------------------------------------------------
1 | import { Link } from "react-router-dom";
2 | import { Nav, Navbar, NavItem } from "reactstrap";
3 |
4 | export default function LoginNav({ msg }) {
5 | return (
6 |
7 |
20 |
21 | );
22 | }
23 |
--------------------------------------------------------------------------------
/client/src/Components/Login/index.js:
--------------------------------------------------------------------------------
1 | import { Button, Paper, TextField } from "@material-ui/core";
2 | import jwt from "jwt-decode";
3 | import React, { useState } from "react";
4 | import { useDispatch } from "react-redux";
5 | import { Link, useHistory, useLocation } from "react-router-dom";
6 | import { Nav, Navbar, NavItem } from "reactstrap";
7 | import styled from "styled-components";
8 | import axiosInstance from "../../utils/axiosInstance";
9 | import LoginCard from "./LoginCard";
10 | const LoginPaper = styled(Paper)`
11 | width: 100%;
12 | max-width: 500px;
13 | height: 500px;
14 | display: flex;
15 | padding: 80px;
16 | align-items: center;
17 | justify-content: center;
18 | flex-direction: column;
19 | `;
20 | const Container = styled.div`
21 | display: flex;
22 | @media (max-width: 780px) {
23 | flex-direction: column;
24 | }
25 | flex-direction: row;
26 | `;
27 | const LoginContainer = styled.div`
28 | display: flex;
29 | width: 100%;
30 | align-items: center;
31 | justify-content: center;
32 | flex-direction: column;
33 | `;
34 | function LogIn() {
35 | const location = useLocation();
36 | const [email, setEmail] = useState("");
37 | const [password, setPassword] = useState("");
38 | const [loginError, setLoginError] = useState("");
39 | const dispatch = useDispatch();
40 | const history = useHistory();
41 | const handleSubmit = async () => {
42 | if (!email || !password) {
43 | setLoginError("Please enter email and password");
44 | return;
45 | }
46 | try {
47 | const res = await axiosInstance.post("/login", {
48 | role: location.state,
49 | email,
50 | password,
51 | });
52 | const token = res.data.token;
53 | const { name, role } = jwt(token);
54 |
55 | dispatch({ type: "LOG_IN", payload: { token, name, role } });
56 | if (role === "admin") {
57 | history.push(`/doctors/`);
58 | } else if (role === "doctor") {
59 | history.push(`/doctor/profile`);
60 | } else {
61 | history.push(`/user/profile`);
62 | }
63 | } catch (err) {
64 | console.log(err);
65 | setLoginError(err.response.data.error);
66 | }
67 | };
68 | console.log(location);
69 | if (!location.state) {
70 | history.push("/");
71 | return null;
72 | } else {
73 | return (
74 | <>
75 |
76 |
89 |
90 |
91 |
92 |
93 |
94 | Login
95 | {loginError}
96 |
97 | setEmail(e.target.value)}
103 | />
104 | setPassword(e.target.value)}
109 | />
110 |
117 |
118 |
119 |
120 | >
121 | );
122 | }
123 | }
124 | export default LogIn;
125 |
--------------------------------------------------------------------------------
/client/src/Components/Patient/AdmitPatient.js:
--------------------------------------------------------------------------------
1 | import { useEffect } from "react";
2 | import { useState } from "react";
3 | import { useHistory, useParams } from "react-router-dom";
4 | import {
5 | Button,
6 | Col,
7 | Form,
8 | FormGroup,
9 | Input,
10 | Label,
11 | Row,
12 | Table,
13 | } from "reactstrap";
14 | import axiosInstance from "../../utils/axiosInstance";
15 | import Loader from "../Loader";
16 | import moment from "moment";
17 | import { DatePicker } from "reactstrap-date-picker";
18 | import jwtDecode from "jwt-decode";
19 | const AdmitPatient = () => {
20 | const { id } = useParams();
21 |
22 | const [admitData, setAdmitData] = useState({});
23 | const [doctors, setDoctors] = useState(null);
24 | const [rooms, setRooms] = useState(null);
25 | const [currRoom, setCurrRom] = useState({});
26 | const [carriers, setCarriers] = useState(null);
27 | const [prevAdmissions, setPrevAdmissions] = useState(null);
28 | const history = useHistory();
29 | const [loading, setLoading] = useState(false);
30 | const [treatments, setTreatments] = useState([{ name: "", cost: "" }]);
31 | const [admissionId, setAdmissionId] = useState(null);
32 | const { role } = jwtDecode(localStorage.getItem("token"));
33 | const [showTreatment, setShowTreatment] = useState(
34 | role === "doctor" ? true : false
35 | );
36 |
37 | const handleSubmit = async () => {
38 | console.log({ ...admitData, patient_id: id });
39 | const admit = await axiosInstance.post("/patient/admit", {
40 | ...admitData,
41 | patient_id: id,
42 | });
43 | history.push("/patients");
44 | };
45 | const handleDischarge = async (e) => {
46 | const {
47 | data: { treatment },
48 | } = await axiosInstance.post("/treatement", treatments);
49 | // console.log(treatment);
50 | const {
51 | data: { admission },
52 | } = await axiosInstance.patch(`/patient/admit/${admissionId}`, {
53 | treatment: treatment,
54 | });
55 |
56 | const discharge = await axiosInstance.post("/bill", {
57 | patient_id: id,
58 | admission_id: admissionId,
59 | discharge_date: new Date(),
60 | });
61 |
62 | if (role === "doctor") {
63 | history.push("/patients");
64 | } else {
65 | history.push(`/patient/${id}`);
66 | }
67 | };
68 |
69 | const hasPreviousAdmission = (admissions) => {
70 | // console.log(admissions);
71 | return admissions?.some((admit) => {
72 | if (admit.bill_id === undefined) {
73 | // setAdmissionId(admit._id);
74 | return true;
75 | } else {
76 | return false;
77 | }
78 | });
79 | };
80 | useEffect(() => {
81 | const getData = async () => {
82 | setLoading(true);
83 | const {
84 | data: { admission },
85 | } = await axiosInstance.get(`/patient/admit/${id}`);
86 | setPrevAdmissions(admission);
87 | // else {
88 | const {
89 | data: { doctors },
90 | } = await axiosInstance.get("/doctor");
91 | // console.log(doctors);
92 | admission?.some((admit) => {
93 | if (admit.bill_id === undefined) {
94 | setAdmissionId(admit._id);
95 | return true;
96 | } else {
97 | return false;
98 | }
99 | });
100 | if (doctors) {
101 | setDoctors([...doctors]);
102 | }
103 |
104 | const {
105 | data: { rooms },
106 | } = await axiosInstance.get("/room");
107 |
108 | const filteredRooms = await Promise.all(
109 | rooms.map(async (room) => {
110 | const {
111 | data: { room: roomData },
112 | } = await axiosInstance.get(`/room/${room._id}`);
113 | // console.log(roomData.length);
114 | // console.log(room.no_of_beds);
115 | if (roomData.length < room.no_of_beds) {
116 | return room;
117 | }
118 | })
119 | ).then((res) => res.filter(Boolean));
120 |
121 | console.log(filteredRooms);
122 |
123 | // getRoomsWithSpace(rooms);
124 |
125 | setRooms(filteredRooms);
126 | const {
127 | data: { carriers },
128 | } = await axiosInstance.get("/carrier");
129 | setCarriers([...carriers]);
130 | setLoading(false);
131 | // }
132 | // hasPreviousAdmission(prevAdmissions);
133 | };
134 |
135 | getData();
136 | }, []);
137 | useEffect(() => {
138 | if (role === "doctor") {
139 | hasPreviousAdmission(prevAdmissions);
140 | }
141 | console.log("Boom");
142 | }, [admissionId]);
143 | useEffect(() => {}, [treatments]);
144 | console.log(doctors);
145 | if (loading && role !== "doctor") {
146 | return ;
147 | }
148 | // useEffect(() => {}, []);
149 |
150 | // console.log(treatments);
151 | if (showTreatment) {
152 | // hasPreviousAdmission(prevAdmissions);
153 | return (
154 |
155 |
Please Add Treatements for patient before discharge
156 | {treatments.map((treatment, index) => (
157 |
158 |
159 |
160 |
161 |
162 |
163 | {
166 | let temp = treatments;
167 | temp[index].name = e.target.value;
168 | setTreatments([...temp]);
169 | }}
170 | />
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 | {
181 | let temp = treatments;
182 | temp[index].cost = e.target.value;
183 | setTreatments([...temp]);
184 | }}
185 | />
186 |
187 |
188 |
189 |
190 |
191 |
201 |
202 |
203 |
204 | ))}
205 |
206 |
207 |
208 |
209 |
210 |
220 |
221 |
222 |
225 |
226 | );
227 | }
228 | if (hasPreviousAdmission(prevAdmissions)) {
229 | return (
230 |
231 |
232 |
233 | |
234 | | Admit Date
235 |
236 | Reason For Admit |
237 | Actions |
238 |
239 |
240 | {prevAdmissions.map((admission) => (
241 |
242 | | {moment(admission.admit_date).format("YYYY-MM-DD")} |
243 | {admission.reason_for_admit} |
244 |
245 | {admission.bill_id !== undefined ? (
246 |
252 | ) : (
253 |
263 | )}
264 | |
265 |
266 | ))}
267 |
268 |
269 |
270 | );
271 | }
272 |
273 | return (
274 |
431 | );
432 | };
433 |
434 | export default AdmitPatient;
435 |
--------------------------------------------------------------------------------
/client/src/Components/Patient/AdmittedPatients.js:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from "react";
2 | import axiosInstance from "../../utils/axiosInstance";
3 | import { Button, Col, FormGroup, Input, Label, Row, Table } from "reactstrap";
4 | import moment from "moment";
5 | import { useHistory } from "react-router-dom";
6 | import jwtDecode from "jwt-decode";
7 |
8 | const AdmittedPatients = () => {
9 | const [patients, setPatients] = useState([]);
10 | const [showTreatment, setShowTreatment] = useState(false);
11 | const [treatments, setTreatments] = useState([{ name: "", cost: "" }]);
12 | const [admissionId, setAdmissionId] = useState(null);
13 | const [patientId, setPatientId] = useState(null);
14 | const { role, _id } = jwtDecode(localStorage.getItem("token"));
15 | // if (role === "doctor") {
16 | // setShowTreatment(true);
17 | // }
18 | // const [showTreatment, setShowTreatment] = useState(
19 | // role === "doctor" ? true : false
20 | // );
21 | // console.log(showTreatment);
22 | useEffect(() => {
23 | const getData = async () => {
24 | const {
25 | data: { patients },
26 | } = await axiosInstance.get("/patient/admitted");
27 | setPatients(patients);
28 | };
29 | getData();
30 | }, []);
31 | const history = useHistory();
32 | const handleDischarge = async (e) => {
33 | const {
34 | data: { treatment },
35 | } = await axiosInstance.post("/treatement", treatments);
36 | // console.log(treatment);
37 | const {
38 | data: { admission },
39 | } = await axiosInstance.patch(`/patient/admit/${admissionId}`, {
40 | treatment: treatment,
41 | });
42 |
43 | const discharge = await axiosInstance.post("/bill", {
44 | patient_id: patientId,
45 | admission_id: admissionId,
46 | discharge_date: new Date(),
47 | });
48 |
49 | console.log(admission);
50 | history.push(`/patient/${patientId}`);
51 | };
52 | if (showTreatment) {
53 | return (
54 |
55 |
Please Add Treatements for patient before discharge
56 | {treatments.map((treatment, index) => (
57 |
58 |
59 |
60 |
61 |
62 |
63 | {
66 | let temp = treatments;
67 | temp[index].name = e.target.value;
68 | setTreatments([...temp]);
69 | }}
70 | />
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 | {
81 | let temp = treatments;
82 | temp[index].cost = e.target.value;
83 | setTreatments([...temp]);
84 | }}
85 | />
86 |
87 |
88 |
89 |
90 |
91 |
101 |
102 |
103 |
104 | ))}
105 |
106 |
107 |
108 |
109 |
110 |
120 |
121 |
122 |
125 |
126 | );
127 | }
128 | return (
129 |
130 |
131 |
132 |
133 | | S.No |
134 | Patient Name |
135 | Admission Date |
136 |
137 |
138 |
139 | {patients.map(({ _id, patient_id, admit_date }, index) => (
140 |
141 | | {index + 1} |
142 | {patient_id.name} |
143 | {moment(admit_date).format("MM/DD/YYYY")} |
144 |
145 |
155 | |
156 |
157 | ))}
158 |
159 |
160 |
161 | );
162 | };
163 | export default AdmittedPatients;
164 |
--------------------------------------------------------------------------------
/client/src/Components/Patient/EditPatient.js:
--------------------------------------------------------------------------------
1 | import { Row, Col, FormGroup, Button, Label, Input, Form } from "reactstrap";
2 | import { useHistory, useParams } from "react-router-dom";
3 | import React, { useState, useEffect } from "react";
4 | import axiosInstance from "../../utils/axiosInstance";
5 | import moment from "moment";
6 | function EditPatientForm() {
7 | const [patientDetails, setPatientDetails] = useState({
8 | name: "",
9 | email: "",
10 | password: "",
11 | address: "",
12 | phone: "",
13 | sex: "",
14 | birthdate: "",
15 | age: "",
16 | });
17 | const { id } = useParams();
18 | const history = useHistory();
19 | useEffect(() => {
20 | const getData = async () => {
21 | const {
22 | data: { patient },
23 | } = await axiosInstance.get(`/patient/${id}`);
24 | setPatientDetails(patient?.[0]);
25 | };
26 | getData();
27 | }, []);
28 | const handleSubmit = async () => {
29 | const patient = await axiosInstance.patch(`/patient/${id}`, patientDetails);
30 | history.push("/patients");
31 | };
32 | return (
33 |
34 |
35 |
36 |
37 |
38 |
168 |
169 |
170 |
171 |
172 |
173 | );
174 | }
175 | export default EditPatientForm;
176 |
--------------------------------------------------------------------------------
/client/src/Components/Patient/PatientDetails.js:
--------------------------------------------------------------------------------
1 | import { useState } from "react";
2 | import { useEffect } from "react";
3 | import { useHistory, useParams } from "react-router-dom";
4 | import { Button, Col, Container, Row, Table } from "reactstrap";
5 | import _ from "lodash";
6 | import moment from "moment";
7 | import axiosInstance from "../../utils/axiosInstance";
8 | import Loader from "../Loader";
9 |
10 | const PatientDetails = () => {
11 | const { id } = useParams();
12 | const [patientDetails, setPatientDetails] = useState(null);
13 | const [bills, setBills] = useState(null);
14 | const history = useHistory();
15 |
16 | useEffect(() => {
17 | if (localStorage.getItem("token") === null) {
18 | history.push("/login");
19 | }
20 | const getData = async () => {
21 | const {
22 | data: { patient },
23 | } = await axiosInstance.get(`/patient/${id}`);
24 | const patientDet = patient[0];
25 | patientDet["birthdate"] = moment(patientDet["birthdate"]).format(
26 | "YYYY-MM-DD"
27 | );
28 |
29 | setPatientDetails(_.omit(patientDet, ["_id", "__v"]));
30 | // console.log(_.omit(patient[0], ["_id", "__v"]));
31 | const {
32 | data: { bill },
33 | } = await axiosInstance.get(`/patient/bill/${id}`);
34 | setBills(bill);
35 | };
36 |
37 | getData();
38 | }, []);
39 | if (patientDetails === null || bills === null) {
40 | return ;
41 | }
42 | return (
43 |
44 |
45 | Patient Details
46 |
47 |
48 |
49 | {Object.keys(patientDetails).map((key) => (
50 |
51 | | {_.startCase(key)} |
52 | {patientDetails[key]} |
53 |
54 | ))}
55 |
56 |
57 |
58 | Bills
59 |
60 |
68 |
69 |
70 | | S.No |
71 | Total Cost |
72 | Net Payable Cost |
73 |
74 |
75 |
76 | {bills.map((bill, index) => {
77 | return (
78 |
79 | | {index + 1} |
80 | {bill.total_cost} |
81 | {bill.net_payable_cost} |
82 |
83 |
84 |
91 | |
92 |
93 | );
94 | })}
95 |
96 |
97 |
98 |
99 |
100 | );
101 | };
102 | export default PatientDetails;
103 |
--------------------------------------------------------------------------------
/client/src/Components/Patient/PatientNav.js:
--------------------------------------------------------------------------------
1 | import { Link, useLocation } from "react-router-dom";
2 | import { Nav, NavItem, NavLink } from "reactstrap";
3 |
4 | import { AiOutlineOrderedList } from "react-icons/ai";
5 | import { GrAddCircle } from "react-icons/gr";
6 | import jwtDecode from "jwt-decode";
7 | const PatientNav = ({ children }) => {
8 | const location = useLocation();
9 | const { role } = jwtDecode(localStorage.getItem("token"));
10 | return (
11 | <>
12 |
49 | {children}
50 | >
51 | );
52 | };
53 | export default PatientNav;
54 |
--------------------------------------------------------------------------------
/client/src/Components/Patient/Patients.js:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useState } from "react";
2 | import { useHistory, useLocation } from "react-router-dom";
3 | import { Button, Col, Input, Row, Table } from "reactstrap";
4 | import axiosInstance from "../../utils/axiosInstance";
5 | import Loader from "../Loader";
6 | import jwtDecode from "jwt-decode";
7 | function Patients() {
8 | const [patients, setPatients] = useState([]);
9 | const [search, setSearch] = useState("");
10 | const [loading, setLoading] = useState(true);
11 | const location = useLocation();
12 | const history = useHistory();
13 | // const [role, setRole] = useState("");
14 | const { role, _id } = jwtDecode(localStorage.getItem("token"));
15 | useEffect(() => {
16 | const getData = async () => {
17 | if (role === "doctor") {
18 | const {
19 | data: { patients },
20 | } = await axiosInstance.get(`/doctor/patients/${_id}`);
21 | setPatients([...patients]);
22 | setLoading(false);
23 | } else {
24 | setLoading(true);
25 | const res = await axiosInstance.get("/patient");
26 | if (res.status === 200) {
27 | setPatients(res.data.patients);
28 | setLoading(false);
29 | }
30 | }
31 | };
32 | getData();
33 | }, [role, _id]);
34 |
35 | const handleDelete = async (id) => {
36 | await axiosInstance.delete(`/patient/${id}`);
37 | location.reload();
38 | };
39 | if (loading || role === undefined) {
40 | return ;
41 | }
42 | console.log(role);
43 | // if (role === "doctor") {
44 | // ;
140 | // }
141 |
142 | return (
143 |
376 | );
377 | }
378 |
379 | export default Patients;
380 |
--------------------------------------------------------------------------------
/client/src/Components/Patient/Profile.js:
--------------------------------------------------------------------------------
1 | import jwt from "jwt-decode";
2 | import React, { useEffect, useState } from "react";
3 | import { useHistory } from "react-router-dom";
4 | import { Button, Col, Form, FormGroup, Input, Label, Row } from "reactstrap";
5 | import axiosInstance from "../../utils/axiosInstance";
6 | import Loader from "../Loader";
7 |
8 | function Profile() {
9 | const [patientDetails, setPatientDetails] = useState({});
10 | const [loading, setLoading] = useState(true);
11 | const { _id } = jwt(localStorage.getItem("token"));
12 | const [oldPassword, setOldPassword] = useState("");
13 | const [newPassword, setNewPassword] = useState("");
14 | const [showChangePassword, setShowChangePassword] = useState(false);
15 | const history = useHistory();
16 | useEffect(() => {
17 | if (localStorage.getItem("token") === null) {
18 | history.push("/login");
19 | }
20 | const getData = async () => {
21 | setLoading(true);
22 | const res = await axiosInstance.get(`/patient/${_id}`);
23 | if (res.status === 200) {
24 | setPatientDetails(res.data.patient?.[0]);
25 | setLoading(false);
26 | }
27 | };
28 | getData();
29 | }, [_id]);
30 | const handleSubmit = async () => {
31 | const res = await axiosInstance.patch(`/patient/${_id}`, {
32 | ...patientDetails,
33 | });
34 | alert("Details Updated Successfully");
35 | };
36 | const handlePasswordChange = async () => {
37 | try {
38 | const res = await axiosInstance.patch(`/update/${_id}`, {
39 | oldPassword,
40 | newPassword,
41 | role: "patient",
42 | });
43 | if (res.status === 200) {
44 | setShowChangePassword(false);
45 | window.alert("Password Changed Successfully");
46 | }
47 | } catch (e) {
48 | console.log(e.response.data.error);
49 | window.alert(e.response.data.error);
50 | }
51 | };
52 |
53 | console.log(patientDetails);
54 | if (loading) {
55 | return ;
56 | }
57 | if (showChangePassword) {
58 | return (
59 |
60 |
61 |
62 |
63 | Change Password
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | {
76 | const temp = e.target.value;
77 | setOldPassword(temp);
78 | }}
79 | />
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 | {
94 | const temp = e.target.value;
95 | setNewPassword(temp);
96 | }}
97 | />
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 | );
109 | }
110 | return (
111 |
112 |
113 |
114 |
115 | Edit Profile
116 |
205 |
206 |
207 |
208 |
209 | );
210 | }
211 |
212 | export default Profile;
213 |
--------------------------------------------------------------------------------
/client/src/Components/Patient/addPatient.js:
--------------------------------------------------------------------------------
1 | import { Row, Col, FormGroup, Button, Label, Input, Form } from "reactstrap";
2 | import { useHistory } from "react-router-dom";
3 | import React, { useState } from "react";
4 | import axiosInstance from "../../utils/axiosInstance";
5 | import moment from "moment";
6 | function AddPatientForm() {
7 | const [patientDetails, setPatientDetails] = useState({
8 | name: "",
9 | email: "",
10 | password: "",
11 | address: "",
12 | phone: "",
13 | sex: "",
14 | birthdate: "",
15 | age: "",
16 | });
17 | const history = useHistory();
18 | const handleSubmit = async () => {
19 | const patient = await axiosInstance.post("/patient", patientDetails);
20 | history.push("/patients");
21 | };
22 |
23 | return (
24 |
25 |
26 |
27 |
28 |
29 |
172 |
173 |
174 |
175 |
176 |
177 | );
178 | }
179 | export default AddPatientForm;
180 |
--------------------------------------------------------------------------------
/client/src/Components/Patient/secNavBar.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { Navbar, Nav, NavItem, NavbarText, NavLink, Button } from "reactstrap";
3 | import { withRouter } from "react-router-dom";
4 | import Cookies from "js-cookie";
5 | class SecNavBar extends React.Component {
6 | constructor(props) {
7 | super(props);
8 | this.state = {
9 | redirect: false,
10 | };
11 | // this.logout=this.logout.bind(this);
12 | }
13 | logout() {
14 | Cookies.remove(this.props.data);
15 | Cookies.remove(this.props.name);
16 | Cookies.remove("auth");
17 | // sessionStorage.clear();
18 | // sessionStorage.clear();
19 | //
20 | // window.location.reload();
21 | this.props.history.push(this.props.link);
22 | }
23 | render() {
24 | return (
25 |
26 |
27 |
32 |
33 |
36 |
37 |
38 |
39 | );
40 | }
41 | }
42 | export default withRouter(SecNavBar);
43 |
--------------------------------------------------------------------------------
/client/src/Components/Patient/signUp.js:
--------------------------------------------------------------------------------
1 | import axios from "axios";
2 | import Cookies from "js-cookie";
3 | import React from "react";
4 | import { Button, Col, Form, FormGroup, Input, Label, Row } from "reactstrap";
5 | class SignUp extends React.Component {
6 | constructor(props) {
7 | super(props);
8 | this.state = {
9 | patient_name: "",
10 | email: "",
11 | password: "",
12 | address: "",
13 | phone: "",
14 | sex: "",
15 | birthdate: "",
16 | age: "",
17 | bloodgroup: "",
18 | };
19 | this.handleSubmit = this.handleSubmit.bind(this);
20 | }
21 | handleSubmit(e) {
22 | console.log(this.state);
23 | const headers = {
24 | authorization: Cookies.get("token"),
25 | };
26 | axios
27 | .post("http://localhost:4000/patient/patientList", this.state, {
28 | headers: headers,
29 | })
30 | .then((res) => {
31 | console.log(res);
32 | if (res.data.isError) {
33 | alert(res.data.message);
34 | } else {
35 | alert(res.data);
36 | }
37 | });
38 | }
39 | render() {
40 | return (
41 |
42 |
202 |
203 | );
204 | }
205 | }
206 | export default SignUp;
207 |
--------------------------------------------------------------------------------
/client/src/Components/Rooms/AddRoom.js:
--------------------------------------------------------------------------------
1 | import { useState } from "react";
2 | import axiosInstance from "../../utils/axiosInstance";
3 | import { useHistory } from "react-router-dom";
4 | import { Button, Col, Form, FormGroup, Input, Label, Row } from "reactstrap";
5 |
6 | const AddRoom = () => {
7 | const [roomData, setRoomData] = useState();
8 | const history = useHistory();
9 | const handleSubmit = async (e) => {
10 | // e.preventDefault();
11 | const {
12 | data: { room },
13 | } = await axiosInstance.post("/room", roomData);
14 | history.push(`/rooms/${room._id}`);
15 | };
16 | return (
17 |
18 |
Add Room
19 |
97 |
98 | );
99 | };
100 |
101 | export default AddRoom;
102 |
--------------------------------------------------------------------------------
/client/src/Components/Rooms/EditRoom.js:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from "react";
2 | import axiosInstance from "../../utils/axiosInstance";
3 | import { useHistory, useParams } from "react-router-dom";
4 | import { Button, Col, Form, FormGroup, Input, Label, Row } from "reactstrap";
5 |
6 | const EditRoom = () => {
7 | const [roomData, setRoomData] = useState();
8 | const { id } = useParams();
9 | const history = useHistory();
10 | useEffect(() => {
11 | const getData = async () => {
12 | const {
13 | data: { room },
14 | } = await axiosInstance.get(`/room/details/${id}`);
15 | setRoomData(room);
16 | };
17 | getData();
18 | }, []);
19 |
20 | const handleSubmit = async (e) => {
21 | // e.preventDefault();
22 | const {
23 | data: { room },
24 | } = await axiosInstance.patch(`/room/${id}`, roomData);
25 | history.push("/rooms");
26 | };
27 | return (
28 |
29 |
Edit Room
30 |
112 |
113 | );
114 | };
115 |
116 | export default EditRoom;
117 |
--------------------------------------------------------------------------------
/client/src/Components/Rooms/RoomNav.js:
--------------------------------------------------------------------------------
1 | import { AiOutlineOrderedList } from "react-icons/ai";
2 | import { GrAddCircle } from "react-icons/gr";
3 | import { Link, useLocation } from "react-router-dom";
4 | import { Nav, NavItem, NavLink } from "reactstrap";
5 |
6 | const RoomNav = ({ children }) => {
7 | const location = useLocation();
8 | return (
9 | <>
10 |
32 | {children}
33 | >
34 | );
35 | };
36 | export default RoomNav;
37 |
--------------------------------------------------------------------------------
/client/src/Components/Rooms/ViewRoom.js:
--------------------------------------------------------------------------------
1 | import { useHistory, useParams } from "react-router-dom";
2 | import axiosInstance from "../../utils/axiosInstance";
3 | import { useEffect, useState } from "react";
4 | import { Table } from "reactstrap";
5 |
6 | const ViewRoom = () => {
7 | const { id } = useParams();
8 | const [room, setRoom] = useState({});
9 | const [patients, setPatients] = useState([]);
10 | const [search, setSearch] = useState("");
11 | const history = useHistory();
12 | useEffect(() => {
13 | const getData = async () => {
14 | const {
15 | data: { room },
16 | } = await axiosInstance.get(`/room/${id}`);
17 |
18 | setPatients(room);
19 | };
20 | getData();
21 | }, [id]);
22 | return (
23 |
24 |
Patients
25 |
34 |
35 |
36 | | S.no |
37 | Name |
38 | Phone |
39 | Email |
40 |
41 |
42 |
43 | {typeof doctors != undefined ? (
44 | patients
45 | .filter((doctor, index) => {
46 | if (search === "") {
47 | return doctor;
48 | } else if (
49 | doctor.name.toLowerCase().includes(search.toLowerCase())
50 | ) {
51 | return doctor;
52 | }
53 | })
54 | .map(({ patient_id: patient }, index) => {
55 | return (
56 |
57 | | {index + 1} |
58 | {patient.name} |
59 | {patient.phone} |
60 | {patient.email} |
61 |
62 | );
63 | })
64 | ) : (
65 | ok
66 | )}
67 |
68 |
69 |
70 | );
71 | };
72 | export default ViewRoom;
73 |
--------------------------------------------------------------------------------
/client/src/Components/Rooms/index.js:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from "react";
2 | import axiosInstance from "../../utils/axiosInstance";
3 | import { Button, Col, Table } from "reactstrap";
4 | import { useHistory } from "react-router-dom";
5 | const Rooms = () => {
6 | const [rooms, setRooms] = useState([]);
7 | const history = useHistory();
8 | useEffect(() => {
9 | const getData = async () => {
10 | const {
11 | data: { rooms },
12 | } = await axiosInstance.get("/room");
13 | setRooms([...rooms]);
14 | };
15 | getData();
16 | }, []);
17 | return (
18 |
19 |
20 |
Rooms
21 |
30 |
31 |
32 | | S.no |
33 | Room Number |
34 | Cost Per Day |
35 | Meal Cost Per Day |
36 | Total No of Beds |
37 | Actions |
38 |
39 |
40 |
41 | {rooms.map((room, index) => {
42 | return (
43 |
44 | | {index + 1} |
45 | {room.room_no} |
46 | {room.cost_per_day} |
47 | {room.meal_cost_per_day} |
48 | {room.no_of_beds} |
49 |
50 |
51 |
59 | |
60 |
61 |
71 | |
72 | {/*
73 |
84 | | */}
85 |
86 | );
87 | })}
88 |
89 |
90 |
91 |
92 | );
93 | };
94 | export default Rooms;
95 |
--------------------------------------------------------------------------------
/client/src/Components/header.js:
--------------------------------------------------------------------------------
1 | import { Col, Jumbotron, Row } from 'reactstrap';
2 |
3 | function Header({ msg }) {
4 | return (
5 |
6 |
7 |
8 | Welcome!!! {msg}
9 |
10 |
11 |
12 | );
13 | }
14 | export default Header;
15 |
--------------------------------------------------------------------------------
/client/src/Routes/doctorRoutes.js:
--------------------------------------------------------------------------------
1 | import Cookies from "js-cookie";
2 | import { Route, Switch } from "react-router";
3 | import GetAppointments from "../Components/Doctor/Appointments";
4 | import GetDocProfile from "../Components/Doctor/getDocProfile";
5 | export default function DoctorRoutes() {
6 | return (
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | );
16 | }
17 |
--------------------------------------------------------------------------------
/client/src/Routes/entryRoutes.js:
--------------------------------------------------------------------------------
1 | import { Route } from "react-router";
2 | import { Col, Row } from "reactstrap";
3 | import AdminWelcome from "../Components/Admin/admin-welcome";
4 | import DoctorLogin from "../Components/Doctor/doctorLogin";
5 | import LoginCard from "../Components/LoginCard";
6 | import LoginNav from "../Components/LoginNav";
7 | import PatientLogin from "../Components/Patient/loginPatient";
8 | import doctor_login from "../assets/doctor_2.jpg";
9 | import SignUp from "../Components/Patient/signUp";
10 | export default function EntryRoutes() {
11 | return (
12 | <>
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
29 |
30 | Sign Up
31 |
32 |
33 |
34 |
35 | >
36 | );
37 | }
38 |
--------------------------------------------------------------------------------
/client/src/Routes/patientRoutes.js:
--------------------------------------------------------------------------------
1 | import { Route, Switch } from "react-router";
2 | import GetDoctor from "../Components/Doctor/getDoctor";
3 | import BookAppointment from "../Components/Patient/bookAppointment";
4 | import GetPatientProfile from "../Components/Patient/getPatientProfile";
5 | import PatientAppointments from "../Components/Patient/patientAppointments";
6 | import Cookies from "js-cookie";
7 | export default function PatientRoutes() {
8 | return (
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | );
24 | }
25 |
--------------------------------------------------------------------------------
/client/src/assets/admin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sainikhil1605/Hospital-Management-System-MERN-Stack/3043ca5517a69ae3b66bd9b50f0ca4c43bf2bfcc/client/src/assets/admin.png
--------------------------------------------------------------------------------
/client/src/assets/background.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/client/src/assets/doctor_2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sainikhil1605/Hospital-Management-System-MERN-Stack/3043ca5517a69ae3b66bd9b50f0ca4c43bf2bfcc/client/src/assets/doctor_2.jpg
--------------------------------------------------------------------------------
/client/src/assets/doctor_new.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sainikhil1605/Hospital-Management-System-MERN-Stack/3043ca5517a69ae3b66bd9b50f0ca4c43bf2bfcc/client/src/assets/doctor_new.png
--------------------------------------------------------------------------------
/client/src/assets/patient.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sainikhil1605/Hospital-Management-System-MERN-Stack/3043ca5517a69ae3b66bd9b50f0ca4c43bf2bfcc/client/src/assets/patient.jpg
--------------------------------------------------------------------------------
/client/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
4 | "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans",
5 | "Helvetica Neue", sans-serif;
6 | -webkit-font-smoothing: antialiased;
7 | -moz-osx-font-smoothing: grayscale;
8 | }
9 |
10 | code {
11 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
12 | monospace;
13 | }
14 |
--------------------------------------------------------------------------------
/client/src/index.js:
--------------------------------------------------------------------------------
1 | import 'bootstrap/dist/css/bootstrap.min.css';
2 | import React from 'react';
3 | import ReactDOM from 'react-dom';
4 | import { BrowserRouter } from 'react-router-dom';
5 | import App from './App';
6 | import './index.css';
7 |
8 | ReactDOM.render(
9 |
10 |
11 | ,
12 | document.getElementById('root')
13 | );
14 |
--------------------------------------------------------------------------------
/client/src/utils/ProtectedRoute.js:
--------------------------------------------------------------------------------
1 | import jwtDecode from "jwt-decode";
2 | import { Redirect, Route } from "react-router-dom";
3 |
4 | const ProtectedRoute = ({ children, isAdminRoute, ...rest }) => {
5 | const { role } = jwtDecode(localStorage.getItem("token"));
6 | console.log(role);
7 | console.log(
8 | (localStorage.getItem("token") && isAdminRoute && role === "admin") ||
9 | !isAdminRoute
10 | );
11 | return (
12 | {
15 | if (
16 | (localStorage.getItem("token") && isAdminRoute && role === "admin") ||
17 | !isAdminRoute
18 | ) {
19 | return children;
20 | } else {
21 | return ;
22 | }
23 | }}
24 | />
25 | );
26 | };
27 |
28 | export default ProtectedRoute;
29 |
--------------------------------------------------------------------------------
/client/src/utils/Redux/loginReducer.js:
--------------------------------------------------------------------------------
1 | const initialState = {
2 | isLogedIn: false,
3 | name: localStorage.getItem('name') || '',
4 | role: localStorage.getItem('role') || '',
5 | };
6 |
7 | const loginReducer = (state = initialState, action) => {
8 | const { type, payload } = action;
9 | switch (type) {
10 | case 'LOG_IN':
11 | localStorage.setItem('token', payload.token);
12 | localStorage.setItem('name', payload.name);
13 | localStorage.setItem('role', payload.role);
14 | return {
15 | ...state,
16 | isLogedIn: true,
17 | name: payload.name,
18 | role: payload.role,
19 | };
20 | case 'LOG_OUT':
21 | localStorage.removeItem('token');
22 | localStorage.removeItem('name');
23 | localStorage.removeItem('role');
24 | return {};
25 | default:
26 | return state;
27 | }
28 | };
29 | export default loginReducer;
30 |
--------------------------------------------------------------------------------
/client/src/utils/Redux/rootReducer.js:
--------------------------------------------------------------------------------
1 | import { combineReducers } from 'redux';
2 | import loginReducer from './loginReducer';
3 | const rootReducer = combineReducers({ login: loginReducer });
4 |
5 | export default rootReducer;
6 |
--------------------------------------------------------------------------------
/client/src/utils/Redux/store.js:
--------------------------------------------------------------------------------
1 | import { createStore } from 'redux';
2 | import rootReducer from './rootReducer';
3 |
4 | const store = createStore(
5 | rootReducer,
6 | window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
7 | );
8 | export default store;
9 |
--------------------------------------------------------------------------------
/client/src/utils/axiosInstance.js:
--------------------------------------------------------------------------------
1 | import axios from "axios";
2 |
3 | const axiosInstance = axios.create({
4 | baseURL: `${process.env.REACT_APP_API_URL}`,
5 | headers: {
6 | "Content-Type": "application/json",
7 | Accept: "application/json",
8 | Authorization: `Bearer ${localStorage.getItem("token")}`,
9 | },
10 | });
11 | axiosInstance.interceptors.request.use((config) => {
12 | const token = localStorage.getItem("token");
13 | config.headers.Authorization = `Bearer ${token}`;
14 | return config;
15 | });
16 | export default axiosInstance;
17 |
--------------------------------------------------------------------------------
/server/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | .env
--------------------------------------------------------------------------------
/server/Dockerfile:
--------------------------------------------------------------------------------
1 |
2 | # Use the official Node.js image as the base image
3 | FROM node:18
4 |
5 | # Set the working directory in the container
6 | WORKDIR /app
7 | COPY package*.json ./
8 |
9 | # Copy the application files into the working directory
10 | COPY . /app
11 |
12 | # Install the application dependencies
13 | RUN npm install --force
14 | EXPOSE 5000
15 | # Define the entry point for the container
16 | CMD ["npm", "start"]
17 |
--------------------------------------------------------------------------------
/server/controllers/Admin.js:
--------------------------------------------------------------------------------
1 | const Admin = require('../models/Admin');
2 |
3 | const postAdmin = async (req, res) => {
4 | const admin = await Admin.create(req.body);
5 | res.status(200).json({ admin });
6 | };
7 | const getAdmins = async (req, res) => {
8 | const admins = await Admin.find({}).select('-password');
9 | res.status(200).json({ admins });
10 | };
11 | const updateAdmin = async (req, res) => {
12 | const admin = await Admin.findByIdAndUpdate(req.params.id, req.body, {
13 | new: true,
14 | }).select('-password');
15 | res.status(200).json({ admin });
16 | };
17 | const getAdmin = async (req, res) => {
18 | const { id } = req.params;
19 | const admin = await Admin.findById(id);
20 | if (admin) {
21 | res.status(200).json({ admin });
22 | } else {
23 | res.status(404).json({ error: 'Admin not found' });
24 | }
25 | };
26 | module.exports = {
27 | postAdmin,
28 | getAdmins,
29 | getAdmin,
30 | updateAdmin,
31 | };
32 |
--------------------------------------------------------------------------------
/server/controllers/Appointment.js:
--------------------------------------------------------------------------------
1 | const Doctor = require('../models/Doctor');
2 | const { StatusCodes } = require('http-status-codes');
3 | const getAppointments = async (req, res) => {
4 | const { id } = req.params;
5 | const doctor = await Doctor.findById(id);
6 | const appointments = doctor.appointments;
7 | res.status(StatusCodes.OK).json({ appointments });
8 | };
9 | const postAppointment = async (req, res) => {
10 | const { id } = req.params;
11 | const doctor = await Doctor.findById(id);
12 | doctor.appointments.push(req.body);
13 | doctor.save();
14 | res.status(StatusCodes.CREATED).json({ doctor });
15 | };
16 | const updateAppointment = async (req, res) => {
17 | const { id } = req.params;
18 | const user = req.user;
19 | const doctor = await Doctor.findById(user._id);
20 | const index = doctor.appointments.findIndex(
21 | (appointment) => appointment._id == id
22 | );
23 | if (index == -1) {
24 | res
25 | .status(StatusCodes.NOT_FOUND)
26 | .json({ message: 'Appointment not found' });
27 | } else {
28 | doctor.appointments[index] = req.body;
29 | doctor.save();
30 | res.status(StatusCodes.OK).json({ doctor });
31 | }
32 | };
33 | module.exports = {
34 | getAppointments,
35 | postAppointment,
36 | updateAppointment,
37 | };
38 |
--------------------------------------------------------------------------------
/server/controllers/Bill.js:
--------------------------------------------------------------------------------
1 | const { StatusCodes } = require("http-status-codes");
2 | const Admission = require("../models/Admission");
3 | const Bill = require("../models/Bill");
4 | const getBills = async (req, res) => {
5 | const bills = await Bill.find({})
6 | .populate("admission_id")
7 | .populate("patient_id");
8 |
9 | res.status(StatusCodes.OK).json({ bills });
10 | };
11 | const addBill = async (req, res) => {
12 | const bill = await Bill.create(req.body);
13 | const admission = await Admission.findByIdAndUpdate(req.body.admission_id, {
14 | bill_id: bill._id,
15 | });
16 | console.log(admission);
17 |
18 | res.status(StatusCodes.OK).json({ bill });
19 | };
20 | const getBill = async (req, res) => {
21 | const { billId } = req.params;
22 | const bill = await Bill.findById(billId)
23 | .populate("admission_id")
24 | .populate("patient_id")
25 | .populate({
26 | path: "admission_id",
27 | populate: {
28 | path: "insurance_id",
29 | model: "InsuranceCarrier",
30 | },
31 | })
32 | .populate({
33 | path: "admission_id",
34 | populate: {
35 | path: "doctor_id",
36 | model: "doctor",
37 | },
38 | })
39 | .populate({
40 | path: "admission_id",
41 | populate: {
42 | path: "treatments",
43 | model: "Treatment",
44 | },
45 | });
46 | res.status(StatusCodes.OK).json({ bill });
47 | };
48 | const getBillByPatient = async (req, res) => {
49 | const { id } = req.params;
50 | const bill = await Bill.find({ patient_id: id });
51 |
52 | res.status(StatusCodes.OK).json({ bill });
53 | };
54 | module.exports = { getBills, addBill, getBill, getBillByPatient };
55 |
--------------------------------------------------------------------------------
/server/controllers/Carrier.js:
--------------------------------------------------------------------------------
1 | const { StatusCodes } = require("http-status-codes");
2 | const CarrierSchema = require("../models/Carrier");
3 | const getCarriers = async (req, res) => {
4 | const carriers = await CarrierSchema.find({});
5 |
6 | res.status(StatusCodes.OK).json({ carriers });
7 | };
8 | const addCarrier = async (req, res) => {
9 | const carrier = await CarrierSchema.create(req.body);
10 | res.status(StatusCodes.OK).json({ carrier });
11 | };
12 | module.exports = { getCarriers, addCarrier };
13 |
--------------------------------------------------------------------------------
/server/controllers/Doctor.js:
--------------------------------------------------------------------------------
1 | const Doctor = require("../models/Doctor");
2 | const Patient = require("../models/Patient");
3 | const Admission = require("../models/Admission");
4 | const { StatusCodes } = require("http-status-codes");
5 | const getDoctors = async (req, res) => {
6 | const doctors = await Doctor.find({});
7 |
8 | res.status(StatusCodes.OK).json({ doctors });
9 | };
10 | const getPrevPatients = async (req, res) => {
11 | const patients = await Admission.find({ doctor_id: req.params.id }).populate(
12 | "patient_id"
13 | );
14 | res.status(StatusCodes.OK).json({ patients });
15 | };
16 | const getPatients = async (req, res) => {
17 | const patients = await Admission.find({
18 | doctor_id: req.params.id,
19 | bill_id: { $exists: null },
20 | }).populate("patient_id");
21 | // console.log(admission);
22 | // const patients = await Patient.find({ doctor: req.params.id });
23 | res.status(StatusCodes.OK).json({ patients });
24 | };
25 |
26 | const postDoctors = async (req, res) => {
27 | const doctor = await Doctor.create(req.body);
28 | res.status(StatusCodes.CREATED).json({ doctor });
29 | };
30 | const deleteDoctor = async (req, res) => {
31 | const { id } = req.params;
32 | const doctor = await Doctor.findByIdAndDelete(id);
33 | res.status(StatusCodes.OK).json({ doctor });
34 | };
35 |
36 | const getDoctor = async (req, res) => {
37 | const doctor = await Doctor.findById(req.params.id).select("-password");
38 | res.status(StatusCodes.OK).json({ doctor });
39 | };
40 | const editDoctor = async (req, res) => {
41 | const doctor = await Doctor.findByIdAndUpdate(req.params.id, req.body, {
42 | new: true,
43 | });
44 | res.status(StatusCodes.OK).json({ doctor });
45 | };
46 |
47 | module.exports = {
48 | getDoctors,
49 | postDoctors,
50 | deleteDoctor,
51 | getDoctor,
52 | editDoctor,
53 | getPatients,
54 | getPrevPatients,
55 | };
56 |
--------------------------------------------------------------------------------
/server/controllers/Patient.js:
--------------------------------------------------------------------------------
1 | const { StatusCodes } = require("http-status-codes");
2 | const Patient = require("../models/Patient");
3 | const Admission = require("../models/Admission");
4 | const getPatientDetails = async (req, res) => {
5 | const { id } = req.params;
6 | console.log(id);
7 | const patient = await Patient.find({ _id: id }).select("-password");
8 |
9 | res.status(StatusCodes.OK).json({ patient });
10 | };
11 | const getAdmittedPatients = async (req, res) => {
12 | const patients = await Admission.find({
13 | bill_id: { $exists: null },
14 | }).populate("patient_id");
15 | // console.log(patients);
16 | res.status(StatusCodes.OK).json({ patients });
17 | };
18 | const addTreatment = async (req, res) => {
19 | const { id } = req.params;
20 | const { treatment } = req.body;
21 | console.log(treatment);
22 | const admission = await Admission.findByIdAndUpdate(id, {
23 | $push: { treatments: treatment },
24 | });
25 | res.status(StatusCodes.OK).json({ admission });
26 | };
27 |
28 | const getAllPatientDetails = async (req, res) => {
29 | const patients = await Patient.find({}).select("-password");
30 | res.status(StatusCodes.OK).json({ patients });
31 | };
32 | const updatePatient = async (req, res) => {
33 | const { id } = req.params;
34 |
35 | const patient = await Patient.findByIdAndUpdate(id, req.body);
36 | res.status(StatusCodes.OK).json({ patient });
37 | };
38 | const deletePatient = async (req, res) => {
39 | const { id } = req.params;
40 | const patient = await Patient.findByIdAndDelete(id);
41 | if (!patient) {
42 | res.status(StatusCodes.BAD_REQUEST).json({ error: "Patient not found" });
43 | } else {
44 | res.status(StatusCodes.OK).json({ patient });
45 | }
46 | };
47 | const addPatient = async (req, res) => {
48 | try {
49 | const patient = await Patient.create(req.body);
50 | res.status(StatusCodes.CREATED).json({ patient });
51 | } catch (e) {
52 | console.log(e);
53 | res.status(StatusCodes.BAD_REQUEST).json({ e });
54 | }
55 | };
56 | const admitPatient = async (req, res) => {
57 | // console.log(req.bod y);
58 | try {
59 | const admission = await Admission.create(req.body);
60 | res.status(StatusCodes.CREATED).json({ admission });
61 | } catch (e) {
62 | console.log(e);
63 | res.status(StatusCodes.BAD_REQUEST).json({ e });
64 | }
65 | };
66 | const getAdmissionInfo = async (req, res) => {
67 | const { id } = req.params;
68 | const admission = await Admission.find({ patient_id: id });
69 | res.status(StatusCodes.CREATED).json({ admission });
70 | };
71 |
72 | module.exports = {
73 | getPatientDetails,
74 | getAllPatientDetails,
75 | updatePatient,
76 | deletePatient,
77 | addPatient,
78 | admitPatient,
79 | getAdmissionInfo,
80 | addTreatment,
81 | getAdmittedPatients,
82 | };
83 |
--------------------------------------------------------------------------------
/server/controllers/Room.js:
--------------------------------------------------------------------------------
1 | const Room = require("../models/Room");
2 | const Admission = require("../models/Admission");
3 | const { StatusCodes } = require("http-status-codes");
4 | const getRooms = async (req, res) => {
5 | const rooms = await Room.find({});
6 |
7 | res.status(StatusCodes.OK).json({ rooms });
8 | };
9 | const deleteRoom = async (req, res) => {
10 | const { id } = req.params;
11 | const room = await Room.findByIdAndDelete(id);
12 | if (!room) {
13 | res.status(StatusCodes.BAD_REQUEST).json({ error: "Room not found" });
14 | } else {
15 | res.status(StatusCodes.OK).json({ room });
16 | }
17 | };
18 |
19 | const getRoom = async (req, res) => {
20 | const { id } = req.params;
21 | const room = await Admission.find({
22 | room_id: id,
23 | bill_id: { $exists: null },
24 | }).populate("patient_id");
25 | res.status(StatusCodes.OK).json({ room });
26 | };
27 | const postRooms = async (req, res) => {
28 | const room = await Room.create(req.body);
29 | res.status(StatusCodes.CREATED).json({ room });
30 | };
31 | const updateRoom = async (req, res) => {
32 | const { id } = req.params;
33 |
34 | const room = await Room.findByIdAndUpdate(id, req.body);
35 | res.status(StatusCodes.OK).json({ room });
36 | };
37 | const getRoomDetails = async (req, res) => {
38 | const { id } = req.params;
39 | const room = await Room.findById(id);
40 | res.status(StatusCodes.OK).json({ room });
41 | };
42 | module.exports = {
43 | getRooms,
44 | postRooms,
45 | updateRoom,
46 | getRoom,
47 | deleteRoom,
48 | getRoomDetails,
49 | };
50 |
--------------------------------------------------------------------------------
/server/controllers/Treatement.js:
--------------------------------------------------------------------------------
1 | const Treatement = require("../models/Treatments");
2 | const { StatusCodes } = require("http-status-codes");
3 | const addTreatement = async (req, res) => {
4 | const treatment = await Treatement.create(req.body);
5 | res.status(StatusCodes.CREATED).json({ treatment });
6 | };
7 |
8 | module.exports = {
9 | addTreatement,
10 | };
11 |
--------------------------------------------------------------------------------
/server/controllers/User.js:
--------------------------------------------------------------------------------
1 | const Admin = require("../models/Admin");
2 | const Doctor = require("../models/Doctor");
3 | const Patient = require("../models/Patient");
4 | const { StatusCodes } = require("http-status-codes");
5 | const Login = async (req, res) => {
6 | var { email, password, role } = req.body;
7 | if (!email || !password) {
8 | res
9 | .status(StatusCodes.BAD_REQUEST)
10 | .json({ error: "Please enter email and password" });
11 | }
12 | let currModel;
13 | if (role === "admin") {
14 | currModel = Admin;
15 | } else if (role == "doctor") {
16 | currModel = Doctor;
17 | } else {
18 | currModel = Patient;
19 | }
20 | const user = await currModel.findOne({ email: email });
21 | if (!user) {
22 | res.status(StatusCodes.BAD_REQUEST).json({ error: "User not found" });
23 | }
24 |
25 | const isCorrect = await user.checkPassword(password);
26 |
27 | if (isCorrect) {
28 | const token = user.generateAuthToken();
29 | res.status(StatusCodes.OK).json({ token });
30 | } else {
31 | res.status(StatusCodes.UNAUTHORIZED).json({ error: "Incorrect password" });
32 | }
33 | };
34 | const SignUp = async (req, res) => {
35 | const { role, user } = req.body;
36 | console.log(user);
37 | let currModel;
38 | if (role === "admin") {
39 | currModel = Admin;
40 | } else if (role === "doctor") {
41 | currModel = Doctor;
42 | } else {
43 | currModel = Patient;
44 | }
45 | const savedUser = await currModel.create({ ...user });
46 |
47 | if (savedUser) {
48 | const token = savedUser.generateAuthToken();
49 | res.status(StatusCodes.OK).json({ token });
50 | } else {
51 | res.status(StatusCodes.BAD_REQUEST).json({ error: "User not saved" });
52 | }
53 | };
54 | const updatePassword = async (req, res) => {
55 | const { role } = req.body;
56 | let currModel;
57 | if (role === "admin") {
58 | currModel = Admin;
59 | } else if (role === "doctor") {
60 | currModel = Doctor;
61 | } else {
62 | currModel = Patient;
63 | }
64 | const { id } = req.params;
65 | const { oldPassword, newPassword } = req.body;
66 | const user = await currModel.findById(id);
67 | const isCorrect = await user.checkPassword(oldPassword);
68 | if (isCorrect) {
69 | user.password = newPassword;
70 | await user.save();
71 | res.status(StatusCodes.OK).json({ user });
72 | } else {
73 | res.status(StatusCodes.BAD_REQUEST).json({ error: "Incorrect password" });
74 | }
75 | };
76 |
77 | module.exports = { Login, SignUp, updatePassword };
78 |
--------------------------------------------------------------------------------
/server/db/connectDB.js:
--------------------------------------------------------------------------------
1 | const mongoose = require('mongoose');
2 |
3 | const connectDB = async (url) => {
4 | return await mongoose.connect(url);
5 | };
6 |
7 | module.exports = connectDB;
8 |
--------------------------------------------------------------------------------
/server/index.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 | require("dotenv").config();
3 | require("express-async-errors");
4 | const cors = require("cors");
5 | const morgan = require("morgan");
6 | const PORT = process.env.PORT || 5000;
7 | const authMiddleware = require("./middleware/auth");
8 | const errorHandlerMiddleware = require("./middleware/errorMiddleware");
9 | const notFound = require("./middleware/notFound");
10 | const connectDB = require("./db/connectDB");
11 | const app = express();
12 | app.use(express.json());
13 | app.use(morgan("dev"));
14 | app.use(cors());
15 | // app.use("/api/v1", require("./routes/User"));
16 | // app.use("/api/v1/patient", require("./routes/Patient"));
17 | // app.use("/api/v1/doctor", require("./routes/Doctor"));
18 | // app.use("/api/v1/admin", require("./routes/Admin"));
19 | // app.use("/api/v1/room", require("./routes/Room"));
20 | // app.use("/api/v1/carrier", require("./routes/Carrier"));
21 | // app.use("/api/v1/bill", require("./routes/Bill"));
22 | // app.use("/api/v1/treatement", require("./routes/Treatement"));
23 | app.use("/api/v1", require("./routes/User"));
24 | app.use("/api/v1/patient", authMiddleware, require("./routes/Patient"));
25 | app.use("/api/v1/doctor", require("./routes/Doctor"));
26 | app.use("/api/v1/admin", authMiddleware, require("./routes/Admin"));
27 | app.use("/api/v1/room", authMiddleware, require("./routes/Room"));
28 | app.use("/api/v1/carrier", authMiddleware, require("./routes/Carrier"));
29 | app.use("/api/v1/bill", authMiddleware, require("./routes/Bill"));
30 | app.use("/api/v1/treatement", authMiddleware, require("./routes/Treatement"));
31 | app.use(notFound);
32 | app.use(errorHandlerMiddleware);
33 | const startServer = () => {
34 | try {
35 | connectDB(process.env.MONGO_URI);
36 | app.listen(PORT, () => {
37 | console.log(`Server running on ${PORT}`);
38 | });
39 | } catch (err) {
40 | throw new Error(err);
41 | }
42 | };
43 |
44 | startServer();
45 |
--------------------------------------------------------------------------------
/server/middleware/adminDoctorMiddleware.js:
--------------------------------------------------------------------------------
1 | const adminDoctorMiddleware = (req, res, next) => {
2 | if (req.user.role === 'admin' || req.user.role === 'doctor') {
3 | next();
4 | } else {
5 | res.status(401).json({ error: 'Unauthorized' });
6 | }
7 | };
8 | module.exports = adminDoctorMiddleware;
9 |
--------------------------------------------------------------------------------
/server/middleware/adminMiddleware.js:
--------------------------------------------------------------------------------
1 | const adminMiddleware = (req, res, next) => {
2 | if (req.user.role === 'admin') {
3 | next();
4 | } else {
5 | res.status(401).json({ error: 'Unauthorized' });
6 | }
7 | };
8 | module.exports = adminMiddleware;
9 |
--------------------------------------------------------------------------------
/server/middleware/auth.js:
--------------------------------------------------------------------------------
1 | const { StatusCodes } = require("http-status-codes");
2 | const jwt = require("jsonwebtoken");
3 | const authMiddleware = async (req, res, next) => {
4 | const { authorization } = req.headers; //get token from header
5 | console.log(authorization);
6 | if (!authorization || !authorization.startsWith("Bearer ")) {
7 | res
8 | .status(StatusCodes.UNAUTHORIZED)
9 | .json({ error: "Missing or invalid token" });
10 | } else {
11 | const token = authorization.split(" ")[1];
12 |
13 | const user = await jwt.verify(token, process.env.JWT_KEY);
14 | console.log(user);
15 | if (!user) {
16 | res.status(StatusCodes.UNAUTHORIZED).json({ error: "Invalid token" });
17 | }
18 | req.user = user;
19 | next();
20 | }
21 | };
22 | module.exports = authMiddleware;
23 |
--------------------------------------------------------------------------------
/server/middleware/doctorMiddleware.js:
--------------------------------------------------------------------------------
1 | const doctorMiddleWare = (req, res, next) => {
2 | if (req.user.role === 'admin' || req.user.role === 'doctor') {
3 | next();
4 | } else {
5 | res.status(401).json({ error: 'Unauthorized' });
6 | }
7 | };
8 |
--------------------------------------------------------------------------------
/server/middleware/errorMiddleware/index.js:
--------------------------------------------------------------------------------
1 | const { StatusCodes } = require('http-status-codes');
2 | const errorHandlerMiddleware = async (err, req, res, next) => {
3 | res.status(StatusCodes.INTERNAL_SERVER_ERROR).json({ error: err.message });
4 | };
5 | module.exports = errorHandlerMiddleware;
6 |
--------------------------------------------------------------------------------
/server/middleware/notFound.js:
--------------------------------------------------------------------------------
1 | const notFound = (req, res, next) => {
2 | res.status(404).json({ error: 'Route Not found' });
3 | };
4 |
5 | module.exports = notFound;
6 |
--------------------------------------------------------------------------------
/server/models/Admin.js:
--------------------------------------------------------------------------------
1 | const mongoose = require('mongoose');
2 | const bycrypt = require('bcryptjs');
3 | const jwt = require('jsonwebtoken');
4 | const adminSchema = new mongoose.Schema({
5 | name: {
6 | type: String,
7 | required: [true, 'Please enter your name'],
8 | },
9 | email: {
10 | type: String,
11 | required: [true, 'Please enter email'],
12 | unique: [true, 'Email already exists'],
13 | },
14 | password: {
15 | type: String,
16 | required: [true, 'Please enter password'],
17 | },
18 | phone: {
19 | type: String,
20 | },
21 | address: {
22 | type: String,
23 | },
24 | });
25 | adminSchema.pre('save', async function (next) {
26 | const salt = await bycrypt.genSalt(10);
27 | this.password = await bycrypt.hash(this.password, salt);
28 | next();
29 | });
30 | adminSchema.methods.checkPassword = async function (password) {
31 | const isMatch = await bycrypt.compare(password, this.password);
32 | return isMatch;
33 | };
34 | adminSchema.methods.generateAuthToken = function () {
35 | const token = jwt.sign(
36 | { _id: this._id, role: 'admin', name: this.name },
37 | process.env.JWT_KEY,
38 | { expiresIn: process.env.JWT_EXPIRES_IN }
39 | );
40 | return token;
41 | };
42 |
43 | module.exports = mongoose.model('admin', adminSchema);
44 |
--------------------------------------------------------------------------------
/server/models/Admission.js:
--------------------------------------------------------------------------------
1 | const mongoose = require("mongoose");
2 | const admissionSchema = new mongoose.Schema({
3 | doctor_id: {
4 | type: mongoose.Types.ObjectId,
5 | ref: "doctor",
6 | },
7 | room_id: {
8 | type: mongoose.Schema.Types.ObjectId,
9 | ref: "Room",
10 | },
11 | treatments: [
12 | {
13 | type: mongoose.Schema.Types.ObjectId,
14 | ref: "Treatment",
15 | },
16 | ],
17 | bill_id: {
18 | type: mongoose.Schema.Types.ObjectId,
19 | ref: "Bill",
20 | },
21 | admit_date: {
22 | type: Date,
23 | },
24 | patient_id: {
25 | type: mongoose.Schema.Types.ObjectId,
26 | ref: "Patient",
27 | required: true,
28 | },
29 | insurance_id: {
30 | type: mongoose.Schema.Types.ObjectId,
31 | ref: "InsuranceCarrier",
32 | },
33 | reason_for_admit: {
34 | type: String,
35 | },
36 | });
37 |
38 | module.exports = mongoose.model("Admission", admissionSchema);
39 |
--------------------------------------------------------------------------------
/server/models/Bill.js:
--------------------------------------------------------------------------------
1 | const mongoose = require("mongoose");
2 | const Carrier = require("./Carrier");
3 | const Doctor = require("./Doctor");
4 | const Room = require("./Room");
5 | const Admission = require("./Admission");
6 | const billSchema = new mongoose.Schema({
7 | patient_id: {
8 | type: mongoose.Types.ObjectId,
9 | ref: "Patient",
10 | },
11 | admission_id: {
12 | type: mongoose.Schema.Types.ObjectId,
13 | ref: "Admission",
14 | },
15 | discharge_date: {
16 | type: Date,
17 | },
18 | total_room_cost: {
19 | type: Number,
20 | },
21 | total_cost: {
22 | type: Number,
23 | },
24 | total_carrier_payable: {
25 | type: Number,
26 | },
27 | net_payable_cost: {
28 | type: Number,
29 | },
30 | total_treatements_cost: {
31 | type: Number,
32 | },
33 | meals_cost: {
34 | type: Number,
35 | },
36 | });
37 | billSchema.pre("save", async function (next) {
38 | // await Admission.findById(this.admission_id).populate("treatments")
39 |
40 | const { admit_date, treatments, room_id, doctor_id, insurance_id } =
41 | await Admission.findById(this.admission_id).populate("treatments");
42 |
43 | const total_treatements_cost = treatments.reduce(
44 | (ac, cur) => ac + cur.cost,
45 | 0
46 | );
47 |
48 | const oneDay = 24 * 60 * 60 * 1000;
49 | const diffDays = Math.round(
50 | Math.abs((this.discharge_date - admit_date) / oneDay)
51 | );
52 | // console.log(diffDays);
53 | const { cost_per_day, meal_cost_per_day } = await Room.findById(room_id);
54 |
55 | const { fee: doctorFee } = await Doctor.findById(doctor_id);
56 | const { percentage } = await Carrier.findById(insurance_id);
57 | this.total_treatements_cost = total_treatements_cost;
58 | this.total_room_cost = diffDays * cost_per_day;
59 | this.meals_cost = diffDays * meal_cost_per_day;
60 | this.total_cost =
61 | doctorFee +
62 | this.total_room_cost +
63 | this.total_treatements_cost +
64 | this.meals_cost;
65 |
66 | this.total_carrier_payable = this.total_cost * (percentage / 100.0);
67 | this.net_payable_cost = this.total_cost - this.total_carrier_payable;
68 | // const admission = await Admission.findById(this.admission_id);
69 | next();
70 | });
71 | module.exports = mongoose.model("Bill", billSchema);
72 |
--------------------------------------------------------------------------------
/server/models/Carrier.js:
--------------------------------------------------------------------------------
1 | const mongoose = require("mongoose");
2 | const carrierSchema = mongoose.Schema({
3 | name: {
4 | type: String,
5 | required: [true, "Name is required"],
6 | },
7 | percentage: {
8 | type: Number,
9 | required: [true, "Percentage is required"],
10 | },
11 | });
12 |
13 | module.exports = mongoose.model("InsuranceCarrier", carrierSchema);
14 |
--------------------------------------------------------------------------------
/server/models/Doctor.js:
--------------------------------------------------------------------------------
1 | const mongoose = require("mongoose");
2 | const bycrypt = require("bcryptjs");
3 | const jwt = require("jsonwebtoken");
4 | const doctorSchema = new mongoose.Schema({
5 | name: {
6 | type: String,
7 | required: [true, "Please enter your name"],
8 | },
9 | email: {
10 | type: String,
11 | required: [true, "Please enter email"],
12 | unique: [true, "Email already exists"],
13 | },
14 | password: {
15 | type: String,
16 | required: [true, "Please enter password"],
17 | },
18 | phone: {
19 | type: String,
20 | unique: [true, "Phone already exists"],
21 | },
22 | department: {
23 | type: String,
24 | },
25 | fee: {
26 | type: Number,
27 | },
28 | });
29 | doctorSchema.pre("save", async function (next) {
30 | const salt = await bycrypt.genSalt(10);
31 | this.password = await bycrypt.hash(this.password, salt);
32 | next();
33 | });
34 | doctorSchema.methods.checkPassword = async function (password) {
35 | const isMatch = await bycrypt.compare(password, this.password);
36 | return isMatch;
37 | };
38 | doctorSchema.methods.generateAuthToken = function () {
39 | const token = jwt.sign(
40 | { _id: this._id, role: "doctor", name: this.name },
41 | process.env.JWT_KEY,
42 | { expiresIn: process.env.JWT_EXPIRES_IN }
43 | );
44 | return token;
45 | };
46 | module.exports = mongoose.model("doctor", doctorSchema);
47 |
--------------------------------------------------------------------------------
/server/models/Patient.js:
--------------------------------------------------------------------------------
1 | const mongoose = require("mongoose");
2 | const bycrypt = require("bcryptjs");
3 | const jwt = require("jsonwebtoken");
4 | const Room = require("./Room");
5 | const patientSchema = new mongoose.Schema({
6 | name: {
7 | type: String,
8 | required: [true, "Please enter your name"],
9 | },
10 | email: {
11 | type: String,
12 | unique: [true, "Email already exists"],
13 | required: [true, "Please enter email"],
14 | },
15 | password: {
16 | type: String,
17 | required: [true, "Please enter password"],
18 | },
19 | phone: {
20 | type: String,
21 | },
22 | address: {
23 | type: String,
24 | },
25 | sex: {
26 | type: String,
27 | },
28 | birthdate: {
29 | type: Date,
30 | },
31 | });
32 | patientSchema.pre("save", async function (next) {
33 | const salt = await bycrypt.genSalt(10);
34 | this.password = await bycrypt.hash(this.password, salt);
35 | next();
36 | });
37 | patientSchema.methods.checkPassword = async function (password) {
38 | const isMatch = await bycrypt.compare(password, this.password);
39 | return isMatch;
40 | };
41 | patientSchema.methods.generateAuthToken = function () {
42 | const token = jwt.sign(
43 | { _id: this._id, role: "patient", name: this.name },
44 | process.env.JWT_KEY,
45 | { expiresIn: process.env.JWT_EXPIRES_IN }
46 | );
47 | return token;
48 | };
49 | module.exports = mongoose.model("Patient", patientSchema);
50 |
--------------------------------------------------------------------------------
/server/models/Room.js:
--------------------------------------------------------------------------------
1 | const mongoose = require("mongoose");
2 | const roomSchema = mongoose.Schema({
3 | room_no: {
4 | type: String,
5 | },
6 | cost_per_day: {
7 | type: Number,
8 | },
9 | no_of_beds: {
10 | type: Number,
11 | },
12 | meal_cost_per_day: {
13 | type: Number,
14 | },
15 | });
16 | module.exports = mongoose.model("Room", roomSchema);
17 |
--------------------------------------------------------------------------------
/server/models/Treatments.js:
--------------------------------------------------------------------------------
1 | const mongoose = require("mongoose");
2 | const treatmentSchema = new mongoose.Schema({
3 | name: {
4 | type: String,
5 | },
6 | cost: {
7 | type: Number,
8 | },
9 | });
10 | module.exports = mongoose.model("Treatment", treatmentSchema);
11 |
--------------------------------------------------------------------------------
/server/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "server",
3 | "version": "1.0.0",
4 | "main": "index.js",
5 | "scripts": {
6 | "start": "nodemon index.js",
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "bcryptjs": "^2.4.3",
14 | "cors": "^2.8.5",
15 | "dotenv": "^10.0.0",
16 | "express": "^4.17.1",
17 | "express-async-errors": "^3.1.1",
18 | "helmet": "^4.6.0",
19 | "http-status-codes": "^2.1.4",
20 | "jsonwebtoken": "^8.5.1",
21 | "mongoose": "^6.1.2",
22 | "mongoose-auto-increment": "^5.0.1",
23 | "morgan": "^1.10.0"
24 | },
25 | "devDependencies": {
26 | "nodemon": "^2.0.22"
27 | },
28 | "description": ""
29 | }
30 |
--------------------------------------------------------------------------------
/server/routes/Admin.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 | const router = express.Router();
3 | const adminMiddleware = require("../middleware/adminMiddleware");
4 | const {
5 | postAdmin,
6 | getAdmins,
7 | getAdmin,
8 | updateAdmin,
9 | } = require("../controllers/Admin");
10 | router.get("/", adminMiddleware, getAdmins);
11 | router.post("/", postAdmin);
12 | router.get("/:id", getAdmin);
13 | router.patch("/:id", updateAdmin);
14 | module.exports = router;
15 |
--------------------------------------------------------------------------------
/server/routes/Bill.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 | const router = express.Router();
3 | const { addBill, getBills, getBill } = require("../controllers/Bill");
4 | router.get("/", getBills);
5 | router.post("/", addBill);
6 | router.get("/:billId", getBill);
7 | module.exports = router;
8 |
--------------------------------------------------------------------------------
/server/routes/Carrier.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 | const router = express.Router();
3 | const { addCarrier, getCarriers } = require("../controllers/Carrier");
4 | router.get("/", getCarriers);
5 | router.post("/", addCarrier);
6 | module.exports = router;
7 |
--------------------------------------------------------------------------------
/server/routes/Doctor.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 | const router = express.Router();
3 |
4 | const {
5 | getDoctors,
6 | postDoctors,
7 | deleteDoctor,
8 | getDoctor,
9 | editDoctor,
10 | getPatients,
11 | getPrevPatients,
12 | } = require("../controllers/Doctor");
13 |
14 | router.get("/", getDoctors);
15 | router.post("/", postDoctors);
16 | router.get("/:id", getDoctor);
17 | router.get("/patients/:id", getPatients);
18 | router.get("/previousPatients/:id", getPrevPatients);
19 | router.patch("/:id", editDoctor);
20 | router.delete("/:id", deleteDoctor);
21 |
22 | module.exports = router;
23 |
--------------------------------------------------------------------------------
/server/routes/Patient.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 | const router = express.Router();
3 | const adminMiddleware = require("../middleware/adminMiddleware");
4 | const adminDocMiddleware = require("../middleware/adminDoctorMiddleware");
5 | const {
6 | getPatientDetails,
7 | getAllPatientDetails,
8 | updatePatient,
9 | deletePatient,
10 | addPatient,
11 | admitPatient,
12 | getAdmissionInfo,
13 | addTreatment,
14 | getAdmittedPatients,
15 | } = require("../controllers/Patient");
16 | const { getBillByPatient } = require("../controllers/Bill");
17 | // const { addTreatement } = require("../controllers/Treatement");
18 |
19 | router.get("/", getAllPatientDetails);
20 | router.post("/", addPatient);
21 | router.get("/admitted", getAdmittedPatients);
22 | router.get("/:id", getPatientDetails);
23 | router.patch("/:id", updatePatient);
24 | router.delete("/:id", adminMiddleware, deletePatient);
25 | router.post("/admit", admitPatient);
26 |
27 | router.patch("/admit/:id", addTreatment);
28 | router.get("/admit/:id", getAdmissionInfo);
29 | router.get("/bill/:id", getBillByPatient);
30 | module.exports = router;
31 |
--------------------------------------------------------------------------------
/server/routes/Room.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 | const router = express.Router();
3 | const {
4 | getRooms,
5 | postRooms,
6 | updateRoom,
7 | getRoom,
8 | deleteRoom,
9 | getRoomDetails,
10 | } = require("../controllers/Room");
11 | router.get("/", getRooms);
12 | router.get("/details/:id", getRoomDetails);
13 | router.get("/:id", getRoom);
14 | router.delete("/:id", deleteRoom);
15 | router.post("/", postRooms);
16 | router.patch("/:id", updateRoom);
17 | module.exports = router;
18 |
--------------------------------------------------------------------------------
/server/routes/Treatement.js:
--------------------------------------------------------------------------------
1 | const router = require("express").Router();
2 | const { addTreatement } = require("../controllers/Treatement");
3 | router.post("/", addTreatement);
4 | // router.get("/:billId", getTreatements);
5 | // router.post('/signUp', SignUp/);
6 |
7 | module.exports = router;
8 |
--------------------------------------------------------------------------------
/server/routes/User.js:
--------------------------------------------------------------------------------
1 | const router = require("express").Router();
2 | const { Login, SignUp, updatePassword } = require("../controllers/User");
3 | router.post("/login", Login);
4 | router.patch("/update/:id", updatePassword);
5 | router.post("/signUp", SignUp);
6 |
7 | module.exports = router;
8 |
--------------------------------------------------------------------------------