Skip to content

Commit 5439037

Browse files
committed
Merge branch 'main' of shubham_personal:ShubhaMahobia/VH_Backend
2 parents e801aa6 + 42a18f6 commit 5439037

12 files changed

+493
-29
lines changed

controller/appointmentController.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ exports.bookAppointment = async (req, res) => {
1313
const newAppointment = new Appointment({
1414
doctorId: req.body.doctorId,
1515
patientId: req.body.patientId,
16-
timeSlot: req.body.timeSlot,
17-
day: req.body.day,
16+
date: req.body.date,
17+
meetingHour: req.body.meetingHour,
18+
startTimeMin: req.body.startTimeMin,
19+
endTimeMin: req.body.endTimeMin,
1820
description: req.body.description,
19-
meetingLink: req.body.meetingLink,
21+
meetingId: req.body.meetingId,
2022
});
2123
const appointmentExist = await Appointment.findOne({
22-
meetingLink: req.body.meetingLink,
24+
meetingId: req.body.meetingId,
2325
});
2426
// Checking for unique Identification Number for every appointment -
2527
if (appointmentExist) {

controller/authenticationController.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ exports.signUpDoctor = async (req, res) => {
101101
Experience: req.body.experience,
102102
SpecializedField: req.body.specializedField,
103103
gender: req.body.gender,
104-
availability: req.body.availability,
104+
startTimeHour: req.body.startTimeHour,
105+
endTimeHour: req.body.endTimeHour,
106+
startTimeMin: req.body.startTimeMin,
107+
endTimeMin: req.body.endTimeMin,
105108
profilePicture: req.body.profilePicture,
106109
address: req.body.address,
107110
degree: req.body.degree,
@@ -136,13 +139,13 @@ exports.signUpDoctor = async (req, res) => {
136139
//Login Fuction for fetching user Patient details
137140
exports.fetchUserDetails = async (req, res) => {
138141
try {
139-
const email = req.body.email;
140-
if (email == null) {
142+
const userID = req.body.id;
143+
if (userID == null) {
141144
return res
142145
.status(400)
143-
.json({ success: false, message: "Please provide an email" });
146+
.json({ success: false, message: "Please provide an id" });
144147
} else {
145-
const user = await userPatient.findOne({ Email: email });
148+
const user = await userPatient.findOne({ firebaseUserId: userID });
146149
if (!user) {
147150
return res.status(401).json({
148151
success: false,
@@ -168,7 +171,7 @@ exports.fetchDoctorDetails = async (req, res) => {
168171
if (docid == null) {
169172
return res
170173
.status(400)
171-
.json({ success: false, message: "Please provide an email" });
174+
.json({ success: false, message: "Please provide an id" });
172175
} else {
173176
const doctor = await userDoctor.findOne({ firebaseUserId: docid });
174177
if (!doctor) {
@@ -188,5 +191,3 @@ exports.fetchDoctorDetails = async (req, res) => {
188191
.json({ success: false, message: "Internal Server Error" });
189192
}
190193
};
191-
192-

controller/documentController.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
const express = require("express");
2+
const bcrypt = require("bcryptjs");
3+
const UserDoctor = require("../model/UserDoctorModel");
4+
const UserPatient = require("../model/UserPatientModel");
5+
const Appointment = require("../model/AppointmentModel");
6+
const Document = require("../model/DocumentModel");
7+
const mongoose = require("mongoose");
8+
9+
//Function for generate the Document
10+
exports.uploadDocument = async (req, res) => {
11+
try {
12+
13+
//Creating Document Object
14+
const newDocument= new Document({
15+
doctorId: req.body.doctorId,
16+
patientId: req.body.patientId,
17+
date: req.body.date,
18+
title:req.body.title,
19+
description: req.body.description,
20+
documentLink: req.body.documentLink,
21+
});
22+
const DocumentExist = await Document.findOne({
23+
documentLink: req.body.documentLink,
24+
});
25+
// Checking for unique Identification Number for every Document -
26+
if (DocumentExist) {
27+
return res.status(400).json({
28+
success: false,
29+
message: "Document Already Exist in Database",
30+
});
31+
}
32+
await newDocument.save(); //Saving command for saving Document to database
33+
return res.status(200).json({
34+
success: true,
35+
message: "Document uploaded successfully",
36+
});
37+
} catch (error) {
38+
console.log(error);
39+
return res.status(400).json({
40+
success: false,
41+
message: "Internal Server Error",
42+
});
43+
}
44+
};
45+
46+
// Function for fetching the Document by ID
47+
exports.getDocumentDetails = async (req, res) => {
48+
try {
49+
const documentId = req.params.id; // Extract the Document ID from request parameters
50+
51+
// Check if Document ID is provided
52+
if (!documentId) {
53+
return res.status(400).json({
54+
success: false,
55+
message: "Document ID is required",
56+
});
57+
}
58+
59+
// Find the Document by ID
60+
const document = await Document.findOne({ _id: documentId });
61+
62+
// Check if document is not found
63+
if (!document) {
64+
return res.status(404).json({
65+
success: false,
66+
message: "document not found",
67+
});
68+
}
69+
70+
// Find document details using patientId
71+
const patient = await UserPatient.findOne({
72+
firebaseUserId: document.patientId,
73+
});
74+
75+
// Find doctor details using doctorId
76+
const doctor = await UserDoctor.findOne({
77+
firebaseUserId: document.doctorId,
78+
});
79+
80+
if (!patient || !doctor) {
81+
return res.status(404).json({
82+
success: false,
83+
message: "Patient or Doctor details not found",
84+
});
85+
}
86+
87+
return res.status(200).json({
88+
success: true,
89+
message: "document details fetched successfully",
90+
document: {
91+
date: document.date,
92+
title:document.title,
93+
description: document.description,
94+
meetingLink: document.meetingLink,
95+
patient: patient,
96+
doctor: doctor,
97+
},
98+
});
99+
} catch (error) {
100+
console.log(error);
101+
return res.status(500).json({
102+
success: false,
103+
message: "Internal Server Error",
104+
});
105+
}
106+
};

controller/hospitalController.js

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
const express = require("express");
2+
const bcrypt = require("bcryptjs");
3+
const UserDoctor = require("../model/UserDoctorModel");
4+
const UserPatient = require("../model/UserPatientModel");
5+
const Appointment = require("../model/AppointmentModel");
6+
const Hospital = require("../model/HospitalModel");
7+
const mongoose = require("mongoose");
8+
const geolib = require("geolib");
9+
10+
//Function for Booking the Hospital
11+
exports.addHospital = async (req, res) => {
12+
try {
13+
//Creating Hospital Object
14+
const newHospital = new Hospital({
15+
name: req.body.name,
16+
rating: req.body.rating,
17+
hours: req.body.hours,
18+
address: req.body.address,
19+
phone: req.body.phone,
20+
description: req.body.description,
21+
longitude: req.body.longitude,
22+
latitude: req.body.latitude,
23+
imageLink: req.body.imageLink,
24+
noOfBed: req.body.noOfBed,
25+
specilization: req.body.specilization,
26+
browserLink: req.body.browserLink,
27+
});
28+
const hospitalExist = await Hospital.findOne({
29+
address: req.body.address,
30+
});
31+
// Checking for unique Identification Number for every Hospital -
32+
if (hospitalExist) {
33+
return res.status(400).json({
34+
success: false,
35+
message: "Identification Number Already Exist in Database",
36+
});
37+
}
38+
await newHospital.save(); //Saving command for saving Hospital to database
39+
return res.status(200).json({
40+
success: true,
41+
message: "Hospital added successfully",
42+
});
43+
} catch (error) {
44+
console.log(error);
45+
return res.status(400).json({
46+
success: false,
47+
message: "Internal Server Error",
48+
});
49+
}
50+
};
51+
52+
// Function for fetching the Hospital by ID
53+
exports.getAllHospitalDetails = async (req, res) => {
54+
try {
55+
// Find the All Hospital
56+
const hospitals = await Hospital.find();
57+
58+
// Check if Hospital is not found
59+
if (!hospitals) {
60+
return res.status(404).json({
61+
success: false,
62+
message: "Hospital not found",
63+
});
64+
}
65+
66+
return res.status(200).json({
67+
success: true,
68+
message: "Hospital details fetched successfully",
69+
data: hospitals,
70+
});
71+
} catch (error) {
72+
console.log(error);
73+
return res.status(500).json({
74+
success: false,
75+
message: "Internal Server Error",
76+
});
77+
}
78+
};
79+
80+
// Function for fetching the Hospital by ID
81+
exports.getHospitalDetails = async (req, res) => {
82+
try {
83+
const hospitalId = req.params.id; // Extract the Hospital ID from request parameters
84+
85+
// Check if Hospital ID is provided
86+
if (!hospitalId) {
87+
return res.status(400).json({
88+
success: false,
89+
message: "Hospital ID is required",
90+
});
91+
}
92+
93+
// Find the Hospital by ID
94+
const hospital = await Hospital.findOne({ _id: hospitalId });
95+
96+
// Check if Hospital is not found
97+
if (!hospital) {
98+
return res.status(404).json({
99+
success: false,
100+
message: "Hospital not found",
101+
});
102+
}
103+
104+
return res.status(200).json({
105+
success: true,
106+
message: "Hospital details fetched successfully",
107+
hospital: {
108+
name: hospital.name,
109+
rating: hospital.rating,
110+
hours: hospital.hours,
111+
address: hospital.address,
112+
phone: hospital.phone,
113+
description: hospital.description,
114+
longitude: hospital.longitude,
115+
latitude: hospital.latitude,
116+
imageLink: hospital.imageLink,
117+
noOfBed: hospital.noOfBed,
118+
specilization: hospital.specilization,
119+
browserLink: hospital.browserLink,
120+
},
121+
});
122+
} catch (error) {
123+
console.log(error);
124+
return res.status(500).json({
125+
success: false,
126+
message: "Internal Server Error",
127+
});
128+
}
129+
};
130+
131+
//function to fetch hospitals based on patient latitude and longitude
132+
exports.fetchHospitalsByLocation = async (req, res) => {
133+
try {
134+
const { latitude, longitude } = req.body; // Assuming latitude and longitude are passed in the request body
135+
const radius = req.query.radius || 10000; // Default radius of 10km, can be overridden in query parameter
136+
137+
// Fetch all hospitals from the database
138+
const hospitals = await Hospital.find();
139+
140+
// If latitude and longitude are provided, filter hospitals based on distance from patient's location
141+
if (latitude && longitude) {
142+
const nearbyHospitals = hospitals.filter((hospital) => {
143+
const hospitalLocation = {
144+
latitude: hospital.latitude,
145+
longitude: hospital.longitude,
146+
};
147+
const distance = geolib.getDistance(
148+
{ latitude, longitude },
149+
hospitalLocation
150+
);
151+
return distance <= radius;
152+
});
153+
res.json(nearbyHospitals);
154+
} else {
155+
// If latitude and longitude are not provided, return all hospitals
156+
res.json(hospitals);
157+
}
158+
} catch (error) {
159+
console.error("Error fetching hospitals:", error);
160+
res.status(500).json({
161+
success: false,
162+
message: "Internal server error",
163+
});
164+
}
165+
};

0 commit comments

Comments
 (0)