Skip to content

Mlaz0/mlaz-backend

Repository files navigation

Mlaz Medical Platform Backend

Overview

Mlaz is a comprehensive medical platform backend that connects patients with doctors, facilitating online consultations, appointment booking, payment processing, and medical content management. The platform provides a complete healthcare ecosystem with features for patients, doctors, and administrators.

Features

Doctor Features

  • Profile Management: Complete doctor profiles with specializations, experience, bio, and certifications
  • Availability Management: Set and manage appointment slots with flexible scheduling
  • Patient Consultations: Conduct online meetings with integrated Google Meet
  • Medical Content: Create and publish medical blogs and educational content
  • AI-Powered Analysis: Advanced patient group analysis using AI for clinical insights and research assistance
  • Reporting System: Generate and manage patient reports
  • Appointment Management: Confirm, complete, or cancel patient bookings
  • Community Engagement: Respond to patient in community posts

Patient Features

  • Profile Management: Comprehensive patient profiles with medical history
  • Doctor Discovery: Search and filter doctors by specialization, experience, and ratings
  • Appointment Booking: Easy booking system with payment integration
  • Wallet System: Secure payment processing with Stripe integration
  • Medical Content Access: Browse medical blogs and educational content
  • Community Platform: Post questions and engage with healthcare professionals
  • Online Consultations: Video meetings with doctors via Google Meet

Admin Features

  • User Management: Manage doctors, patients, and user verifications
  • Content Moderation: Oversee blogs, community posts, and comments
  • Report Management: Review and manage patient reports
  • Payment Oversight: Monitor all payment transactions
  • Category Management: Manage medical specialization categories
  • Doctor Approval: Approve and verify doctor accounts

Technology Stack

Backend Framework

  • Node.js with Express.js - RESTful API development
  • MongoDB with Mongoose - Database and ODM
  • JWT - Authentication and authorization

Payment Integration

  • Stripe - Secure payment processing
  • Webhook Integration - Real-time payment status updates

AI & External Services

  • Groq AI - Advanced patient analysis and clinical insights
  • Google Meet API - Video consultation integration
  • Cloudinary - Image and file management
  • Nodemailer - Email notifications

Project Structure

mlaz-backend/
├── config/
│   ├── cloudinary.js           # Cloudinary configuration
│   └── database.js             # MongoDB connection
├── controllers/
│   ├── auth.controller.js      # Authentication logic
│   ├── availability.controller.js  # Doctor availability
│   ├── blog.controller.js      # Medical blog management
│   ├── booking.controller.js   # Appointment booking
│   ├── category.controller.js  # Medical categories
│   ├── comment.controller.js   # Comment system
│   ├── community.controller.js # Community posts
│   ├── doctorAnalysis.controller.js # AI analysis
│   ├── doctorSessionAnalysisReport.controller.js # Diagnosis for completed session
│   ├── payment.controller.js   # Payment processing
│   ├── report.controller.js    # Medical reports
│   ├── upload.controller.js    # File uploads
│   └── user.controller.js      # User management
├── middlewares/
│   ├── auth.js                 # Authentication middleware
│   ├── authValidation.js       # Auth input validation
│   ├── uploadMiddleware.js     # File upload handling
│   └── *.validator.js          # Input validation middlewares
├── models/
│   ├── User.model.js           # User schema (patients/doctors/admin)
│   ├── Availability.model.js   # Doctor availability
│   ├── Booking.model.js        # Appointment bookings
│   ├── blog.model.js           # Medical blogs
│   ├── Category.model.js       # Medical specializations
│   ├── Comment.model.js        # Comments system
│   ├── CommunityPost.model.js  # Community discussions
│   ├── DoctorAnalysis.model.js # AI analysis reports
│   ├── DoctorSessionAnalysisReport.model.js # Diagnosis for completed session
│   ├── payment.model.js        # Payment transactions
│   ├── Report.model.js         # Medical reports
│   └── schema/
│       ├── doctor.js           # Doctor-specific fields
│       ├── patient.js          # Patient-specific fields
│       └── file.js             # File schema
├── routes/
│   └── *.route.js              # API route definitions
├── services/
│   └── *.service.js            # Business logic layer
├── utils/
│   ├── AppError.js             # Error handling
│   ├── cloudinaryUtils.js      # Cloudinary utilities
│   ├── emailService.js         # Email notifications
│   ├── helpers.js              # Helper functions
│   └── queryHelper.js          # Database query helpers
├── server.js                   # Application entry point
└── package.json                # Dependencies and scripts

API Endpoints

Authentication

POST /api/auth/register          # User registration
POST /api/auth/login             # User login
POST /api/auth/verify-email      # Email verification
POST /api/auth/forgot-password   # Password reset request
POST /api/auth/reset-password    # Password reset

User Management

GET  /api/users/doctors          # Get all doctors
GET  /api/users/patients         # Get all patients (admin only)
GET  /api/users/me               # Get user profile
GET  /api/users/doctors/:id      # Get specific doctor
PATCH /api/users/doctors/:id     # Update doctor profile
PATCH /api/users/patients/:id    # Update patient profile

Appointments & Availability

GET  /api/availability/doctor/:doctorId  # Get doctor availability
POST /api/availability                   # Create availability slot
PATCH /api/availability/:id              # Update availability
DELETE /api/availability/:id             # Delete availability

POST /api/booking                        # Create booking
GET  /api/booking/patient/my             # Get patient bookings
GET  /api/booking/doctor/my              # Get doctor bookings
PATCH /api/booking/:id/confirm           # Confirm booking
PATCH /api/booking/:id/complete          # Complete booking
PATCH /api/booking/:id/cancel            # Cancel booking
GET  /api/booking/:id/meetlink           # Get meeting link

Payment System

POST /api/payment/charge                 # Create payment session
POST /api/payment/webhook                # Stripe webhook
GET  /api/payment/my                     # Get user payments
GET  /api/payment/all                    # Get all payments (admin)

Medical Content

GET  /api/blog/posts                     # Get all blogs
POST /api/blog/posts                     # Create blog (doctor/admin)
PATCH /api/blog/posts/:id                # Update blog
DELETE /api/blog/posts/:id               # Delete blog
PATCH /api/blog/posts/:id/toggle-like    # Like/unlike blog

Community Platform

GET  /api/community/posts                # Get community posts
POST /api/community/posts                # Create post (patient)
PATCH /api/community/posts/:id           # Update post
DELETE /api/community/posts/:id          # Delete post
PATCH /api/community/posts/:id/toggle-like # Like/unlike post

GET  /api/comments/post/:postId          # Get post comments
POST /api/comments/post/:postId          # Add comment (doctor/admin)
PATCH /api/comments/:id                  # Update comment
DELETE /api/comments/:id                 # Delete comment

AI Analysis

POST /api/ai/analysis/analysis-tool      # Generate patient analysis
GET  /api/ai/analysis/my-analyses        # Get doctor's analyses

Reports

POST /api/reports                        # Create report (patient)
GET  /api/reports                        # Get all reports (admin)
GET  /api/reports/patient/me             # Get patient reports
GET  /api/reports/doctor/me              # Get doctor reports
PATCH /api/reports/:id                   # Update report status (admin)

File Upload

POST /api/upload/proxy                   # Upload files to Cloudinary

Categories

GET  /api/categories                     # Get medical categories
POST /api/categories                     # Create category (admin)
PATCH /api/categories/:id                # Update category (admin)
DELETE /api/categories/:id               # Delete category (admin)

Diagnosis

POST  /api/diagnosis/:bookingId          # Generate diagnosis report for a completed session (doctor only)
GET  /api/diagnosis/my                   # Get all diagnosis reports created by the logged-in doctor
GET  /api/diagnosis/patient/:patientId   # Get diagnosis reports for a specific patient (only if a completed session exists between them)

🗄️ Database Schema

User Model

The User model supports three roles: patient, doctor, and admin with role-specific data:

{
  name: String,
  email: String,
  password: String,
  phone: String,
  gender: ["male", "female", "other"],
  dateOfBirth: Date,
  role: ["patient", "doctor", "admin"],
  isEmailVerified: Boolean,
  walletBalance: Number,
  userImg: FileSchema,

  // Doctor-specific fields
  doctorData: {
    specializations: [{ id: ObjectId, name: String }],
    yearsOfExperience: Number,
    bio: String,
    certifications: [FileSchema],
    availability: [ObjectId],
    isApproved: Boolean,
    clinicLocation: String,
    ratingCount: Number,
    ratingNumber: Number
  },

  // Patient-specific fields
  patientData: {
    medicalHistory: [String],
  }
}

Booking Model

{
  doctorId: ObjectId,
  patientId: ObjectId,
  availabilityId: ObjectId,
  appointmentDate: Date,
  startTime: Date,
  endTime: Date,
  price: Number,
  status: ["confirmed", "cancelled", "completed", "no-show"],
  paymentStatus: ["pending", "paid", "refunded"],
  diagnosis: String,
  meetLink: String,
}

Authentication & Authorization

Role-Based Access Control

  • Patients: Can book appointments, access medical content, participate in community
  • Doctors: Can manage availability, conduct consultations, create content, analyze patient data
  • Admins: Full platform management and oversight capabilities

JWT Authentication

  • Secure token-based authentication
  • Role-based route protection
  • Token expiration and refresh mechanism

Payment Integration

Stripe Integration

  • Secure payment processing
  • Webhook handling for real-time updates
  • Wallet system for easy transactions
  • Payment session management

Payment Flow

  1. User initiates payment through wallet charge
  2. Stripe checkout session created
  3. User completes payment on Stripe
  4. Webhook updates payment status
  5. User wallet balance updated automatically

AI-Powered Features

Doctor Analysis Tool

  • Uses Groq AI with Allam-2-7b model
  • Analyzes multiple patient cases simultaneously
  • Generates clinical insights and recommendations
  • Provides research-level analysis
  • Identifies common patterns and risk factors

Analysis Capabilities

  • Symptom pattern recognition
  • Risk factor identification
  • Treatment recommendations
  • Research insights generation
  • Academic reference inclusion

Getting Started

Prerequisites

  • Node.js (v18 or higher)
  • MongoDB
  • Stripe account
  • Cloudinary account
  • Groq API key

Environment Variables

PORT=3000
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret
STRIPE_SECRET_KEY=your_stripe_secret_key
STRIPE_WEBHOOK_SECRET=your_stripe_webhook_secret
CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name
CLOUDINARY_API_KEY=your_cloudinary_api_key
CLOUDINARY_API_SECRET=your_cloudinary_api_secret
EMAIL_SERVICE=your_email_service
EMAIL_USER=your_email_user
EMAIL_PASS=your_email_password
GROQ_API_KEY=your_groq_api_key
FRONTEND_URL=your_frontend_url
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret

Installation

  1. Clone the repository
git clone <repository-url>
cd mlaz-backend
  1. Install dependencies
npm install
  1. Set up environment variables
cp .env.example .env
# Edit .env with your configuration
  1. Start the development server
npm run dev
  1. Start the production server
npm start

Mlaz Medical Platform - Connecting patients with healthcare professionals through technology 🏥💻

About

mlaz-backend

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors