This is the backend for a hospital patient registration system with authentication, patient registration, and prescription image upload functionality.
- Staff and Admin authentication
- Patient registration with details
- Prescription image upload with compression
- Firebase Storage integration for image storage
- Search and sort functionality for patients
- Pagination for patient listing
- Node.js (v14 or higher)
- MongoDB
- Firebase account
-
Clone the repository
-
Install dependencies:
npm install -
Set up Firebase:
- Create a Firebase project at https://console.firebase.google.com/
- Go to Project Settings > Service accounts
- Generate a new private key (this will download a JSON file)
- Enable Firebase Storage in your project
-
Create a
.envfile based onenv.example:- Set your MongoDB connection string
- Set your JWT secret
- Set your Firebase credentials. There are two options:
- Set the entire Firebase service account JSON as a string in FIREBASE_SERVICE_ACCOUNT, or
- Set individual Firebase credentials (FIREBASE_PROJECT_ID, FIREBASE_PRIVATE_KEY, etc.)
- Set your Firebase storage bucket name
- Set default admin user credentials for initial setup
The application has been configured to use environment variables for all sensitive information:
- Firebase Credentials: No credentials are hardcoded in the code. The Firebase configuration loads all credentials from environment variables.
- Database Connection: MongoDB connection strings are loaded from environment variables.
- JWT Secrets: Authentication tokens are signed with a secret stored in environment variables.
- Admin Creation: Admin credentials are loaded from environment variables instead of being hardcoded.
Make sure to:
- Keep your
.envfile secure and never commit it to version control - Use strong, unique passwords for your admin accounts
- Rotate your Firebase service account keys periodically
- Set appropriate Firebase Storage security rules
npm start
POST /api/auth/loginStaff- Staff loginPOST /api/auth/signupStaff- Staff registration
POST /api/auth/staff-dashboard/patientRegistration- Register a new patient with prescription imagesGET /api/auth/staff-dashboard/patients- Get all patients (with search, sort, and pagination)GET /api/auth/staff-dashboard/patients/:id- Get a specific patient by ID
POST /api/auth/staff-dashboard/patientRegistration
Headers:
Authorization: Bearer <staff_token>
Content-Type: multipart/form-data
Form Data:
name: Patient Name
age: 30
gender: Male
address: 123 Hospital St
mobileNo: 1234567890
registrationDate: 2023-10-20 (optional)
prescriptionFront: [Image File]
prescriptionBack: [Image File] (optional)
{
"success": true,
"data": {
"name": "Patient Name",
"age": 30,
"gender": "Male",
"address": "123 Hospital St",
"mobileNo": "1234567890",
"registrationDate": "2023-10-20T00:00:00.000Z",
"prescriptionFrontUrl": "https://storage.googleapis.com/your-bucket/prescriptions/front/image.jpg",
"prescriptionBackUrl": "https://storage.googleapis.com/your-bucket/prescriptions/back/image.jpg",
"registeredBy": "staff_id",
"_id": "patient_id",
"createdAt": "2023-10-20T12:00:00.000Z",
"updatedAt": "2023-10-20T12:00:00.000Z"
}
}