Skip to content

TheGuyDangerous/Medi-Link

Repository files navigation

Medi-Link: Medical Automation System

Project Overview

Medi-Link is a comprehensive medical automation system built using Next.js, TypeScript, and Tailwind CSS. The primary goal of this project is to streamline interactions between medical staff, doctors, and patients, providing a seamless user experience for scheduling appointments, managing patient information, and handling prescriptions.

Key Features

  1. User Authentication
  2. Role-based Access Control
  3. Appointment Management
  4. Prescription Management
  5. Medical Records Management
  6. Family Member Management
  7. Doctor Search Functionality

Detailed Implementation

Project Initialization

The project was initialized using the following configuration:

  • Project Name: Medi-Link
  • TypeScript: Yes
  • ESLint: Yes
  • Tailwind CSS: Yes
  • src/ directory: Yes
  • App Router: Yes
  • Custom import alias: @/

The project was created using the command: npx create-next-app@latest

with - √ What is your project named? ... medi-link √ Would you like to use TypeScript? ... No / Yes √ Would you like to use ESLint? ... No / Yes √ Would you like to use Tailwind CSS? ... No / Yes √ Would you like to use src/ directory? ... No / Yes √ Would you like to use App Router? (recommended) ... No / Yes √ Would you like to customize the default import alias (@/)? ... No / Yes √ What import alias would you like configured? ... @/ Creating a new Next.js app in C:\Users\sanni\OneDrive\Desktop\cursor\medical-bkchodi\medi-link.

Database Schema and Management

Initially using Prisma with PostgreSQL, the project transitioned to Supabase for its robust features and ease of use. The database schema includes carefully designed tables for users, appointments, prescriptions, medical records, and family members.

Key Tables:

  1. users: Stores user information and roles
  2. appointments: Manages appointment data
  3. prescriptions: Handles prescription information
  4. medical_records: Stores patient medical histories
  5. family_members: Manages family relationships

The authentication system leverages NextAuth.js and Firebase, providing a secure and flexible login process:

  1. User initiates login through the frontend interface
  2. Credentials are securely transmitted to the backend
  3. NextAuth.js handles the authentication process, integrating with Firebase
  4. Upon successful authentication, a JWT is generated and stored
  5. User session is created and maintained for subsequent requests

Component Architecture

The project utilizes a modular component structure, promoting reusability and maintainability:

  1. CreateAppointment.tsx: Handles appointment creation logic
  2. CreatePrescription.tsx: Manages prescription creation for doctors
  3. FamilyMemberManagement.tsx: Allows patients to manage family members
  4. DoctorSearch.tsx: Implements doctor search functionality
  5. AppointmentReminders.tsx: Displays upcoming appointment reminders
  6. MedicalRecordsManagement.tsx: Manages patient medical records
  7. Notifications.tsx: Handles real-time notifications for users
  8. DoctorAnalytics.tsx: Provides analytical insights for doctors

API Routes and Data Management

The application uses Next.js API routes for server-side logic and data operations:

  1. src/pages/api/appointments/index.ts: Manages appointment-related operations

/TODO/ 2. src/pages/api/prescriptions/index.ts: Handles prescription data 3. src/pages/api/family-members/index.ts: Manages family member information 4. src/pages/api/doctors/search.ts: Implements doctor search functionality 5. src/pages/api/medical-records/index.ts: Handles medical record operations

These API routes interact with Supabase to perform database operations, ensuring data integrity and security.

State Management and Data Fetching

The application primarily uses React's built-in hooks (useState, useEffect) for state management. For more complex state requirements, the project is designed to easily integrate with advanced state management libraries like Redux or Zustand in the future.

Data fetching is implemented using a combination of server-side rendering (SSR) and client-side fetching, optimizing performance and user experience.

UI/UX Design Philosophy

The user interface is crafted with a focus on simplicity, accessibility, and responsiveness. Tailwind CSS is utilized to create a consistent and modern design language across the application. The UI is designed to be intuitive for users of all technical levels, with clear navigation and informative feedback mechanisms.

Error Handling and Validation

A robust error handling system is implemented throughout the application:

  1. Client-side form validation using custom hooks and validation libraries
  2. Server-side validation in API routes to ensure data integrity
  3. Comprehensive error catching and logging for debugging and monitoring
  4. User-friendly error messages to guide users in case of issues

Page Structure and Routing

The application follows Next.js 13's App Router structure, organizing pages and components for optimal performance and code splitting:

  1. src/app/page.tsx: The main landing page
  2. src/app/login/page.tsx: Handles user login
  3. src/app/register/page.tsx: Manages new user registration
  4. src/app/dashboard/page.tsx: The central hub for user interactions

User Roles

The system supports three types of users:

  1. Patients
  2. Doctors
  3. Medical Staff

User roles are stored in the database and are used to determine access rights and available features for each user type.

Pages and Components

  1. Home Page (src/app/page.tsx):

    • Serves as the landing page for the application
    • Provides links to login and registration pages
  2. Login Page (src/app/login/page.tsx):

    • Handles user authentication
    • Uses Firebase for email/password login
  3. Register Page (src/app/register/page.tsx):

    • Allows new users to create an account
    • Collects basic information and assigns a user role
  4. Dashboard Page (src/app/dashboard/page.tsx):

    • Central hub for user interactions
    • Displays different content based on user role
    • Integrates various components for appointments, prescriptions, and user-specific features
  5. CreateAppointment Component (src/components/CreateAppointment.tsx):

    • Allows users to schedule new appointments
    • Adapts its interface based on the user's role (patient, doctor, or medical staff)
  6. CreatePrescription Component (src/components/CreatePrescription.tsx):

    • Enables doctors to create new prescriptions for patients
    • Collects medication details, dosage, and instructions
  7. FamilyMemberManagement Component (src/components/FamilyMemberManagement.tsx):

    • Allows patients to add and manage family members
    • Displays a list of existing family members
  8. DoctorSearch Component (src/components/DoctorSearch.tsx):

    • Provides functionality for patients to search for doctors
    • Allows filtering by specialization

API Routes

  1. Appointments API (src/pages/api/appointments/index.ts):

    • Handles CRUD operations for appointments
    • Supports creating new appointments and fetching existing ones
  2. Prescriptions API (src/pages/api/prescriptions/index.ts):

    • Manages prescription-related operations
    • Allows creating new prescriptions and retrieving prescription history
  3. Family Members API (src/pages/api/family-members/index.ts):

    • Handles operations related to family member management
    • Supports adding new family members and fetching existing ones

Data Fetching and State Management

The application uses a combination of server-side rendering (SSR) and client-side data fetching. The dashboard page, for example, fetches user-specific data on the client-side using the Supabase client.

State management is primarily handled using React's useState and useEffect hooks. For more complex state management needs, the project can be extended to use libraries like Redux or Zustand in the future.

Styling and UI

The project uses Tailwind CSS for styling, providing a responsive and modern user interface. The UI is designed to be intuitive and user-friendly, with clear separations between different functional areas.

Error Handling and Validation

Basic error handling is implemented throughout the application, with try-catch blocks used in asynchronous operations. Form validation is performed on the client-side, with additional server-side validation implemented in the API routes.

Security Considerations

  1. Authentication: The use of NextAuth.js and Firebase provides a robust authentication system.
  2. Authorization: Role-based access control ensures users can only access appropriate features and data.
  3. Data Protection: Sensitive data is stored securely in the Supabase database.
  4. API Security: API routes are protected to ensure only authenticated users can access sensitive operations.

Future Enhancements

  1. Implement a more sophisticated notification system for appointments and prescription updates.
  2. Create a reporting and analytics dashboard for doctors and medical staff.
  3. Enhance the user interface and experience with more interactive elements and real-time updates.
  4. Implement a telemedicine feature for remote consultations.
  5. Add support for multiple languages to cater to a diverse user base.
  6. Implement a more robust error handling and logging system.
  7. Enhance security measures, including two-factor authentication and regular security audits.

Future Roadmap and Enhancements

  1. Telemedicine Integration: Implement video consultation features for remote patient-doctor interactions
  2. AI-powered Diagnosis Assistance: Integrate machine learning models to assist doctors in preliminary diagnoses
  3. Blockchain for Medical Records: Explore blockchain technology for immutable and secure medical record keeping
  4. Mobile Application: Develop native mobile apps for iOS and Android for improved accessibility
  5. Internationalization: Add multi-language support to cater to a global user base
  6. Advanced Analytics: Implement more sophisticated analytics tools for healthcare providers and administrators
  7. Integration with Wearable Devices: Allow patients to sync data from wearable health devices
  8. Automated Appointment Scheduling: Implement AI-driven scheduling to optimize doctor availability and patient preferences