From 37b385ddffe29589856924ae531529b5a888de32 Mon Sep 17 00:00:00 2001 From: Maloth Madhu Date: Fri, 8 Aug 2025 18:44:14 +0530 Subject: [PATCH] added room booking , patient register , appointment booking and all in reception screen --- backend/controller/appointments.controller.js | 9 +- backend/controller/auth.controller.js | 53 ++++++- backend/controller/billings.controller.js | 2 + backend/controller/patients.controller.js | 7 +- backend/controller/rooms.controller.js | 24 ++- backend/models/patients.model.js | 141 +++++++++++++----- backend/models/rooms.model.js | 2 +- backend/routes/rooms.routes.js | 6 +- backend/server.js | 12 +- 9 files changed, 205 insertions(+), 51 deletions(-) diff --git a/backend/controller/appointments.controller.js b/backend/controller/appointments.controller.js index cad54f7..6a03ba6 100644 --- a/backend/controller/appointments.controller.js +++ b/backend/controller/appointments.controller.js @@ -2,9 +2,15 @@ import Appointment from '../models/appointments.model.js'; // Get all appointments export const getAllAppointments = async (req, res) => { + console.log("Fetching all appointments"); try { const appointments = await Appointment.find(); - res.json(appointments); + console.log(appointments); + res.status(200).json({ + status: "success", + nbHits: appointments.length, + appointments + }); } catch (err) { res.status(500).json({ message: err.message }); } @@ -14,6 +20,7 @@ export const getAllAppointments = async (req, res) => { export const bookAppointment = async (req, res) => { const { name, date, time } = req.body; + console.log("Booking appointment:", req.body); if (!name || !date || !time) { return res.status(400).json({ message: 'All fields are required' }); } diff --git a/backend/controller/auth.controller.js b/backend/controller/auth.controller.js index 77be621..3e02bc3 100644 --- a/backend/controller/auth.controller.js +++ b/backend/controller/auth.controller.js @@ -10,9 +10,24 @@ const generateToken = (id) => // @route POST /signup export const register = async (req, res) => { - console.log("api is being hit"); - const { name, email, password, role ,contact,baseSalary,department,employeeId} = req.body; - console.log(req.body); + + + // console.log("api is being hit"); + // const { name, email, password, role ,contact,baseSaldepartment,employeeIdary,} = req.body; + // console.log(req.body); + + // try{ + // const user = await User.create (req.body); + // const token = generateToken(user._id); + // res.status(200).json({ + // status:"success", + // user, + // token + // }) + // }catch(error){ + // console.log(error); + // } + try { const userExists = await User.findOne({ email }); @@ -61,15 +76,15 @@ export const registerPatient = async (req, res) => { // @route POST /login export const login = async (req, res) => { const { email, password } = req.body; + console.log('hi form login controller'); try { const user = await User.findOne({ email }); + console.log(user); if (!user || !(await user.matchPassword(password))) { return res.status(401).json({ message: 'Invalid credentials' }); } - console.log("user found ") - res.json({ _id: user._id, name: user.name, @@ -83,6 +98,34 @@ export const login = async (req, res) => { }; + + +// //created my madhu +// export const login = async (req, res) => { +// const { email, password } = req.body; +// console.log('hi form login controller'); +// try { +// const user = await User.findOne({ email }); +// console.log(user); +// if (!user || user.password !== password) { +// return res.status(401).json({ message: 'Invalid credentials' }); +// } +// console.log("user found ") +// res.json({ +// _id: user._id, +// name: user.name, +// email: user.email, +// role: user.role, +// token: generateToken(user._id), +// }); +// } catch (error) { +// res.status(500).json({ message: 'Login failed', error }); +// } +// }; +// created by madhu + + + // @route POST /login for patient export const loginPatient = async (req, res) => { const { email, password } = req.body; diff --git a/backend/controller/billings.controller.js b/backend/controller/billings.controller.js index 22e402b..2c27df4 100644 --- a/backend/controller/billings.controller.js +++ b/backend/controller/billings.controller.js @@ -4,6 +4,8 @@ import Billing from '../models/billings.model.js'; export const addBillingEntry = async (req, res) => { const { patient, service, amount, status } = req.body; + console.log(req.body); + if (!patient || !service || !amount) { return res.status(400).json({ message: 'All fields are required' }); } diff --git a/backend/controller/patients.controller.js b/backend/controller/patients.controller.js index f58bbb7..dcf8782 100644 --- a/backend/controller/patients.controller.js +++ b/backend/controller/patients.controller.js @@ -2,10 +2,15 @@ import Patient from '../models/patients.model.js'; // Register new patient export const registerPatient = async (req, res) => { + console.log("api is being hit for patient registration"); + console.log(req.body) try { const patient = new Patient(req.body); await patient.save(); - res.status(201).json(patient); + res.status(200).json({ + status: "success", + patient + }); } catch (err) { res.status(500).json({ message: err.message }); } diff --git a/backend/controller/rooms.controller.js b/backend/controller/rooms.controller.js index 6bf2977..5cb439b 100644 --- a/backend/controller/rooms.controller.js +++ b/backend/controller/rooms.controller.js @@ -31,7 +31,7 @@ export const bookRoom = async (req, res) => { }; // Get all room statuses (for displaying booked rooms) -export const getAllRoomStatus = async (req, res) => { +export const getAllRoomStatus = async(req, res) => { try { const rooms = await Room.find(); res.json(rooms); @@ -40,6 +40,28 @@ export const getAllRoomStatus = async (req, res) => { } }; + +export const createRoom = async (req , res) =>{ + console.log('hi form controller'); + const token = req.headers.authorization.split(" "); + console.log(token); + + try{ + const room = await Room.create(req.body); + res.status(200).json({ + status:"success", + room + }) + }catch(err){ + console.log(err); + res.status(200).json({ + status:"fail", + err + }) + } + +} + // Get available rooms based on type export const getAvailableRooms = async (req, res) => { const { roomType, bedType } = req.body; diff --git a/backend/models/patients.model.js b/backend/models/patients.model.js index 499a5e0..62d275c 100644 --- a/backend/models/patients.model.js +++ b/backend/models/patients.model.js @@ -1,43 +1,112 @@ +// import mongoose from 'mongoose'; + +// const patientSchema = new mongoose.Schema({ +// firstName: String, +// middleName: String, +// lastName: String, +// dob: String, +// age: String, +// gender: String, +// maritalStatus: String, +// address: String, +// city: String, +// state: String, +// zip: String, +// nationality: String, +// email: { +// required: true, +// type: String, +// unique: true, +// }, +// phone: String, +// emergencyName: String, +// emergencyPhone: String, +// emergencyRelation: String, +// insuranceProvider: String, +// plan: String, +// policyNumber: String, +// groupNumber: String, +// insuredName: String, +// insuredPhone: String, +// insuredDOB: String, +// smoker: String, +// alcoholPerWeek: String, +// caffeinePerDay: String, +// recreationalDrugs: String, +// allergies: String, +// currentMedications: String, +// bloodGroup: String, +// conditions: String, +// roomType: String, +// bedType: String, +// }, { timestamps: true }); + +// // ✅ FIX: Check if already compiled +// const Patient = mongoose.models.Patient || mongoose.model('Patient', patientSchema); + +// export default Patient; + + + + + import mongoose from 'mongoose'; const patientSchema = new mongoose.Schema({ - firstName: String, - middleName: String, - lastName: String, - dob: String, - age: String, - gender: String, - maritalStatus: String, - address: String, - city: String, - state: String, - zip: String, - nationality: String, - email: String, - phone: String, - emergencyName: String, - emergencyPhone: String, - emergencyRelation: String, - insuranceProvider: String, - plan: String, - policyNumber: String, - groupNumber: String, - insuredName: String, - insuredPhone: String, - insuredDOB: String, - smoker: String, - alcoholPerWeek: String, - caffeinePerDay: String, - recreationalDrugs: String, - allergies: String, - currentMedications: String, - bloodGroup: String, - conditions: String, - roomType: String, - bedType: String, + // Personal Info + firstName: { type: String }, + middleName: { type: String }, + lastName: { type: String }, + dob: { type: String }, + age: { type: String }, + gender: { type: String }, + maritalStatus: { type: String }, + nationality: { type: String }, + bloodGroup: { type: String }, + address: { type: String }, + city: { type: String }, + state: { type: String }, + zip: { type: String }, + + // Contact Info + email: { + type: String, + required: true, + unique: true, + }, + phone: { type: String }, + + // Emergency Contact + emergencyName: { type: String }, + emergencyPhone: { type: String }, + emergencyRelation: { type: String }, + + // Insurance Details + insuranceProvider: { type: String }, + plan: { type: String }, + policyNumber: { type: String }, + groupNumber: { type: String }, + insuredName: { type: String }, + insuredPhone: { type: String }, + insuredDOB: { type: String }, + + // Lifestyle + smoker: { type: String }, + alcoholPerWeek: { type: String }, + caffeinePerDay: { type: String }, + recreationalDrugs: { type: String }, + + // Medical History + currentMedications: { type: String }, + allergies: { type: String }, + conditions: { type: String }, + + // Room Allotment (Optional) + roomType: { type: String }, + bedType: { type: String }, }, { timestamps: true }); -// ✅ FIX: Check if already compiled -const Patient = mongoose.models.Patient || mongoose.model('Patient', patientSchema); +// Avoid recompilation in dev environment +const Patient = mongoose.model('newPatient', patientSchema); export default Patient; diff --git a/backend/models/rooms.model.js b/backend/models/rooms.model.js index 27376dc..d94c593 100644 --- a/backend/models/rooms.model.js +++ b/backend/models/rooms.model.js @@ -7,5 +7,5 @@ const roomSchema = new mongoose.Schema({ status: { type: String, default: 'Available' }, // Available, Occupied }); -const Room = mongoose.models.Room || mongoose.model('Room', roomSchema); +const Room = mongoose.model('Rooms', roomSchema); export default Room; diff --git a/backend/routes/rooms.routes.js b/backend/routes/rooms.routes.js index f7dda03..e1afa89 100644 --- a/backend/routes/rooms.routes.js +++ b/backend/routes/rooms.routes.js @@ -5,6 +5,7 @@ import { getAvailableRooms, checkRoomAvailability, seedRooms, + createRoom } from '../controller/rooms.controller.js'; const router = express.Router(); @@ -13,6 +14,9 @@ router.post('/book', bookRoom); router.get('/status', getAllRoomStatus); router.post('/available', getAvailableRooms); router.post('/check', checkRoomAvailability); -router.post('/seed', seedRooms); // optional seed route +router.post('/seed', seedRooms); +router.route('/createroom') + .post(createRoom) // optional seed route +router export default router; diff --git a/backend/server.js b/backend/server.js index 0ee035e..a72e8a8 100644 --- a/backend/server.js +++ b/backend/server.js @@ -69,17 +69,19 @@ app.use("/api/reports", reportsRoute); // Auth app.use("/api/auth", authRoute); -app.use('/api/appointments', appointmentRoutes); -app.use('/api/billings', billingRoutes); +app.use('/api/reception/appointments', appointmentRoutes); + +app.use('/api/reception/billing', billingRoutes); app.use('/api/doctors', newdoctorRoutes); -app.use('/api/patients', newpatientRoutes); +app.use('/api/reception/newpatients', newpatientRoutes); app.use('/api/rooms', newroomRoutes); app.use('/api/sanitations', sanitationRoutes); -app.use("/api/patients", RpatientRoutes); +// app.use("/api/patients", RpatientRoutes); app.use('/api/attendance', attendanceRoutes); // Below other routes, register: -app.use('/api/users', userRoutes); // ✅ Add this line +app.use('/api/users', userRoutes); + // Connect DB and Start server connectDB().then(() => {