Supabase HMS Setup Guide – MediCare HMS

Supabase HMS Setup Guide

Welcome to the official **Supabase HMS Setup Guide**. This documentation will walk you through connecting your Supabase account to the MediCare Hospital Management System. The process involves creating a new project, configuring the database schema with our provided script, and connecting your application for a seamless integration.

Prerequisites for This Guide

  • A Supabase account (the free tier is sufficient to start).
  • Basic understanding of copy/paste operations.
  • Access to a modern web browser.

Step 1: Create Your Supabase Project

1. Sign up or Login to Supabase

Navigate to the official Supabase website and sign up for a new account or log in to your existing one.

2. Create a New HMS Project

  1. Click “New Project” in your Supabase dashboard and choose your organization.
  2. Enter project details as follows:
    • Project Name: hospital-management (or your preferred name)
    • Database Password: Choose a strong password and save it securely.
    • Region: Select the region closest to your users for optimal performance.
  3. Click “Create new project” and wait 2-3 minutes for initialization to complete.

Step 2: Get Your Project API Credentials

In your Supabase project dashboard, navigate to Settings > API. You will need to copy the following information for this setup guide:

  • Project URL: Format: https://xxxxx.supabase.co
  • Project `anon` (public) key: This key is safe to use in a browser and starts with eyJ...

Keep your `service_role` key secret! It should never be exposed on the client-side. The application only requires the `anon` key for this setup.

Step 3: Configure Your HMS Application

  1. Open your Hospital Management System application and navigate to the Settings > Database Connection area.
  2. Click on the “Cloud” tab to reveal the Supabase configuration fields.
  3. Enter your credentials from the previous step:
    • Supabase URL: Paste your Project URL.
    • Anon Key: Paste your `anon` key.
  4. Click the “Test Connection” button. A “Connection successful” message should appear, confirming your HMS is connected.
  5. Finally, click the “Connect” button to link the application to your Supabase project.

Step 4: Run the Database Schema Setup

After connecting, a “Database Bootstrap” section will appear in the application. This provides the complete SQL script to set up your database tables and security policies as part of this Supabase HMS Setup Guide.

Database Migration Script

-- =====================================================
-- COMPREHENSIVE SUPABASE DATABASE INITIALIZATION
-- Includes: Extensions, Types, Functions, Tables, Views, 
-- Policies, Triggers, Storage, and Seed Data
-- =====================================================

-- Initialize required extensions
create extension if not exists pgcrypto with schema extensions;
create extension if not exists "uuid-ossp" with schema extensions;

-- Enums
do $$ begin
  create type public.app_role as enum (
    'admin','doctor','nurse','receptionist','pharmacist','lab_technician','finance','patient'
  );
exception when duplicate_object then null; end $$;

do $$ begin
  create type public.app_section as enum (
    'dashboard','appointments','patients','doctors','pharmacy','lab_tests','blood_bank','beds','billing','reports','user_management'
  );
exception when duplicate_object then null; end $$;

-- ... [rest of the SQL script] ...
  1. Click the “Copy SQL Script” button inside your application.
  2. Open the Supabase SQL Editor for your project. You can find more information in the official Supabase documentation.
  3. Paste the copied script into the SQL Editor.
  4. Click “Run” and wait for the execution to complete. You should see a “Success” message.
  5. Return to the Hospital Management System application and click “Finalize Setup” to create your admin user profile.

Step 5: Verify Your HMS Setup

Confirm that the setup was successful by performing the following checks:

  • Check Tables: In your Supabase dashboard, go to the “Table Editor”. You should see tables like `patients`, `doctors`, `appointments`, etc.
  • Test Features: Navigate through the application. Try creating a test patient or doctor to ensure data is being saved to your Supabase database correctly.

Supabase HMS Troubleshooting Guide

Connection Issues

If connection fails, double-check your Supabase URL and anon key. If problems persist, please contact our support team for assistance.

Database Issues

If you see “Table does not exist” errors, ensure the full SQL script from Step 4 was executed successfully in the Supabase SQL Editor.

Authentication Issues

If you can’t log in, make sure you clicked the “Finalize Setup” button after running the SQL migration to create the initial admin account.

Security Recommendations for Your Setup

  • Environment Variables: For developers, always store sensitive keys in environment variables, never in version control.
  • Row Level Security (RLS): RLS is enabled by default in our provided SQL script to ensure data privacy and role-based access for your HMS.
  • User Management: Use strong, unique passwords for all accounts and regularly review user roles and permissions within the application.