Skip to content

Commit c3c4d4a

Browse files
committed
added doctor list and dashboard
1 parent afaec01 commit c3c4d4a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+7830
-289
lines changed

backend/controllers/doctorController.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ const getDoctors = async (req, res) => {
2222
}
2323
};
2424

25+
// Fetch doctors based on user agency
26+
const getCategory = async (req, res) => {
27+
try {
28+
const user = await getUserById(req.userId);
29+
const agency_id = user.agency_id;
30+
const agencyDBDetails = await getAgencyDBDetails(agency_id);
31+
const doctors = await Category.getAllCategories(agencyDBDetails);
32+
res.json(doctors);
33+
} catch (error) {
34+
res.status(500).json({ message: error.message });
35+
}
36+
};
37+
2538
const err_getDoctors = async (req, res) => {
2639
const user = req.user;
2740
logger.info('Accessing getDoctors route', { user });
@@ -60,6 +73,10 @@ const getDoctorById = async (req, res) => {
6073

6174
const createDoctor = async (req, res) => {
6275
const data = req.body;
76+
const user = await getUserById(req.userId);
77+
const agency_id = user.agency_id;
78+
const agencyDBDetails = await getAgencyDBDetails(agency_id);
79+
6380
logger.info('Accessing createDoctor route', { data });
6481

6582
// Validate input data
@@ -69,19 +86,19 @@ const createDoctor = async (req, res) => {
6986
}
7087

7188
// Validate speciality, category, and town existence
72-
const specialityExists = await Speciality.checkSpecialityExists(data.speciality_id);
89+
const specialityExists = await Speciality.checkSpecialityExists(data.speciality_id,agencyDBDetails);
7390
if (!specialityExists) {
7491
logger.warn('Speciality does not exist');
7592
return res.status(400).json({ error: 'Speciality ID does not exist' });
7693
}
7794

78-
const categoryExists = await Category.checkCategoryExists(data.category_id);
95+
const categoryExists = await Category.checkCategoryExists(data.category_id,agencyDBDetails);
7996
if (!categoryExists) {
8097
logger.warn('Category does not exist');
8198
return res.status(400).json({ error: 'Category ID does not exist' });
8299
}
83100

84-
const townExists = await Town.checkTownExists(data.town_id);
101+
const townExists = await Town.checkTownExists(data.town_id,agencyDBDetails);
85102
if (!townExists) {
86103
logger.warn('Town does not exist', { town_id });
87104
return res.status(400).json({ error: 'Town ID does not exist' });
@@ -91,7 +108,10 @@ const createDoctor = async (req, res) => {
91108
try {
92109

93110
// Insert doctor if both checks pass
94-
const result = await Doctor.create(data);
111+
const user = await getUserById(req.userId);
112+
const agency_id = user.agency_id;
113+
const agencyDBDetails = await getAgencyDBDetails(agency_id);
114+
const result = await Doctor.create(data,agencyDBDetails);
95115
logger.info('Doctor created successfully', { doctorId: result.insertId });
96116
res.status(201).json({ message: 'Doctor created', doctorId: result.insertId });
97117
} catch (err) {
@@ -148,4 +168,4 @@ const deleteDoctor = async (req, res) => {
148168
}
149169
};
150170

151-
module.exports = { getDoctors, getDoctorById, createDoctor, updateDoctor, deleteDoctor };
171+
module.exports = { getDoctors, getDoctorById, getCategory, createDoctor, updateDoctor, deleteDoctor };
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const Route = require('../models/routeModel');
2+
const logger = require('../config/logger');
3+
const { getUserById } = require('../models/userModel');
4+
const { getAgencyDBDetails } = require('../models/agencyModel');
5+
6+
const addRoute = async (req, res) => {
7+
const routeData = req.body;
8+
logger.info('Request to add new route', { routeData });
9+
10+
if (!routeData.route_id || !routeData.name) {
11+
logger.error('Missing required fields for route', { townData });
12+
return res.status(400).json({ error: 'Missing required fields' });
13+
}
14+
15+
try {
16+
const result = await Route.addRoute(routeData);
17+
res.status(201).json({ message: 'Route added successfully', routeId: result.insertId });
18+
} catch (err) {
19+
logger.error('Error adding new route', { error: err.message });
20+
res.status(500).json({ error: err.message });
21+
}
22+
};
23+
24+
const getAllRoutes = async (req, res) => {
25+
logger.info('Request to fetch all routes');
26+
try {
27+
const user = await getUserById(req.userId);
28+
const agency_id = user.agency_id;
29+
const agencyDBDetails = await getAgencyDBDetails(agency_id);
30+
const results = await Route.getAllRoutes(agencyDBDetails);
31+
res.status(200).json(results);
32+
} catch (err) {
33+
logger.error('Error fetching routes', { error: err.message });
34+
res.status(500).json({ error: err.message });
35+
}
36+
};
37+
38+
module.exports = { addRoute, getAllRoutes};

backend/controllers/specialityController.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
const Speciality = require('../models/specialityModel');
22
const logger = require('../config/logger');
3+
const { getUserById } = require('../models/userModel');
4+
const { getAgencyDBDetails } = require('../models/agencyModel');
5+
const { getDoctorsByAgency } = require('../models/doctorModel');
6+
37

48

59
const addSpeciality = async (req, res) => {
@@ -23,7 +27,10 @@ const addSpeciality = async (req, res) => {
2327
const getAllSpecialities = async (req, res) => {
2428
logger.info('Request to fetch all specialties');
2529
try {
26-
const results = await Speciality.getAllSpecialities();
30+
const user = await getUserById(req.userId);
31+
const agency_id = user.agency_id;
32+
const agencyDBDetails = await getAgencyDBDetails(agency_id);
33+
const results = await Speciality.getAllSpecialities(agencyDBDetails);
2734
res.status(200).json(results);
2835
} catch (err) {
2936
logger.error('Error fetching specialties', { error: err.message });

backend/controllers/town_controller.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const Town = require('../models/townModel');
22
const logger = require('../config/logger');
3+
const { getUserById } = require('../models/userModel');
4+
const { getAgencyDBDetails } = require('../models/agencyModel');
35

46
const addTown = async (req, res) => {
57
const townData = req.body;
@@ -22,7 +24,10 @@ const addTown = async (req, res) => {
2224
const getAllTowns = async (req, res) => {
2325
logger.info('Request to fetch all towns');
2426
try {
25-
const results = await Town.getAllTowns();
27+
const user = await getUserById(req.userId);
28+
const agency_id = user.agency_id;
29+
const agencyDBDetails = await getAgencyDBDetails(agency_id);
30+
const results = await Town.getTownsByAgency(agencyDBDetails);
2631
res.status(200).json(results);
2732
} catch (err) {
2833
logger.error('Error fetching towns', { error: err.message });

0 commit comments

Comments
 (0)