Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion backend/controller/appointments.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand All @@ -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' });
}
Expand Down
53 changes: 48 additions & 5 deletions backend/controller/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions backend/controller/billings.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
}
Expand Down
7 changes: 6 additions & 1 deletion backend/controller/patients.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down
24 changes: 23 additions & 1 deletion backend/controller/rooms.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
141 changes: 105 additions & 36 deletions backend/models/patients.model.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion backend/models/rooms.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 5 additions & 1 deletion backend/routes/rooms.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getAvailableRooms,
checkRoomAvailability,
seedRooms,
createRoom
} from '../controller/rooms.controller.js';

const router = express.Router();
Expand All @@ -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;
12 changes: 7 additions & 5 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down