Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/diegolozadev/DataMed/llms.txt

Use this file to discover all available pages before exploring further.

This guide covers the complete installation process for DataMed, including development setup and production deployment.

System Requirements

  • Python 3.9 or higher
  • pip (Python package manager)
  • PostgreSQL 12+ (production) or SQLite (development)
  • 512MB RAM minimum (2GB+ recommended for production)
  • Git

Dependencies

DataMed uses the following core dependencies:
requirements.txt
asgiref==3.11.0
brotli==1.2.0
click==8.3.1
diff-match-patch==20241021
dj-database-url==3.1.0
Django==4.2.27
django-import-export==4.4.0
et_xmlfile==2.0.0
gunicorn==23.0.0
h11==0.16.0
openpyxl==3.1.5
packaging==25.0
psycopg2-binary==2.9.11
python-dotenv==1.2.1
sqlparse==0.5.5
tablib==3.9.0
tzdata==2025.3
uvicorn==0.40.0
whitenoise==6.11.0
DataMed is built on Django 4.2.27 (LTS) for long-term stability and security support.

Development Installation

Follow these steps to set up DataMed for local development:
1

Clone the repository

git clone <your-datamed-repo-url>
cd datamed
2

Create a virtual environment

It’s recommended to use a virtual environment to isolate project dependencies:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
3

Install dependencies

pip install -r requirements.txt
This installs all required packages including Django, Gunicorn, PostgreSQL adapter, and WhiteNoise for static files.
4

Configure environment variables

Create a .env file in the project root:
.env
SECRET_KEY=your-development-secret-key
# RENDER variable should NOT be set for development
Do NOT set the RENDER environment variable in development. Its presence switches the system to production mode.
5

Run database migrations

In development, DataMed automatically uses SQLite:
python manage.py migrate
This creates the db.sqlite3 file with all necessary tables including:
  • patients_patient
  • patients_ingreso
  • exams_exam
  • auth_user
  • And other Django system tables
6

Create a superuser

python manage.py createsuperuser
Provide a username, email (optional), and secure password.
7

Start the development server

python manage.py runserver
Access the application at http://localhost:8000

Production Installation

DataMed is configured for deployment on Render.com but can be adapted for other hosting platforms.

Environment Configuration

1

Set production environment variables

Configure the following environment variables on your hosting platform:
Production Environment
SECRET_KEY=your-secure-production-secret-key
DATABASE_URL=postgresql://user:password@host:port/database
RENDER=production
The SECRET_KEY should be a cryptographically secure random string. Never use the development key in production.
2

Configure allowed hosts

Update ALLOWED_HOSTS in config/settings.py to include your production domain:
config/settings.py
ALLOWED_HOSTS = [
    'datamed-k68i.onrender.com',
    'www.datamed-k68i.onrender.com',
    'your-domain.com',  # Add your domain here
    'localhost',
    '127.0.0.1',
]
3

Configure CSRF trusted origins

Add your production domain to CSRF_TRUSTED_ORIGINS:
config/settings.py
CSRF_TRUSTED_ORIGINS = [
    'https://datamed-k68i.onrender.com',
    'https://www.datamed-k68i.onrender.com',
    'https://your-domain.com',  # Add your domain here
]

Database Configuration

DataMed uses different database engines based on the environment:
if not DEBUG:
    DATABASES = {
        'default': dj_database_url.config(
            default=os.environ.get('DATABASE_URL'),
            conn_max_age=600,
        )
    }
The conn_max_age=600 setting enables database connection pooling for better performance in production.

Static Files Configuration

DataMed uses WhiteNoise to serve static files efficiently in production:
config/settings.py
if not DEBUG:
    # Production static files configuration
    STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
    STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
WhiteNoise provides:
  • Compression: Gzip compression for reduced bandwidth
  • Caching: Long-term caching with unique filenames
  • CDN-friendly: Serves files with optimal cache headers

Build Script

For Render.com deployment, use the provided build.sh script:
build.sh
#!/usr/bin/env bash
set -o errexit

# Install dependencies
pip install -r requirements.txt

# Collect static files
python manage.py collectstatic --no-input

# Run migrations
python manage.py migrate

# Verify database state
echo "LOG: Verificando estado de la base de datos..."
python manage.py showmigrations

echo "LOG: Intentando migrar..."
python manage.py migrate --noinput

echo "LOG: Verificando si las tablas se crearon..."
python manage.py inspectdb | head -n 20
The build script includes verification steps to ensure database migrations are applied correctly.

Process Configuration

The Procfile defines the production web process:
web: python manage.py migrate --noinput && python manage.py collectstatic --noinput && gunicorn config.wsgi
This ensures:
  1. Database migrations are applied on each deployment
  2. Static files are collected
  3. Gunicorn WSGI server runs the application

Installed Apps

DataMed includes the following Django applications:
config/settings.py
INSTALLED_APPS = [
    'whitenoise.runserver_nostatic',  # Static file serving
    'import_export',                   # Data import/export functionality
    'apps.users',                      # User authentication
    'apps.exams',                      # Sleep study exam management
    'apps.dashboard',                  # Dashboard and analytics
    'apps.patients',                   # Patient records management
    'django.contrib.admin',           # Django admin interface
    'django.contrib.auth',            # Authentication system
    'django.contrib.contenttypes',    # Content type framework
    'django.contrib.sessions',        # Session management
    'django.contrib.messages',        # Messaging framework
    'django.contrib.staticfiles',     # Static file management
]

Middleware Configuration

config/settings.py
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',  # Serves static files
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
WhiteNoise middleware must be placed immediately after SecurityMiddleware for optimal performance.

Localization Settings

DataMed is configured for Spanish (Mexico) locale:
config/settings.py
LANGUAGE_CODE = 'es-mx'
TIME_ZONE = 'America/Bogota'
USE_I18N = True
USE_TZ = True

Authentication Configuration

config/settings.py
LOGIN_URL = 'login'
LOGIN_REDIRECT_URL = 'dashboard'
LOGOUT_REDIRECT_URL = 'login'
These settings control:
  • LOGIN_URL: Where unauthenticated users are redirected
  • LOGIN_REDIRECT_URL: Default redirect after successful login
  • LOGOUT_REDIRECT_URL: Redirect destination after logout

Verify Installation

After installation, verify everything is working:
1

Check Django version

python manage.py version
Should output: 4.2.27
2

Verify migrations

python manage.py showmigrations
All migrations should show [X] indicating they’re applied.
3

Test the admin interface

Navigate to /admin/ and log in with your superuser credentials.
4

Access the main application

Visit the root URL and verify you’re redirected to the login page.

Troubleshooting

Static files not loading in production

python manage.py collectstatic --noinput
Ensure STATIC_ROOT is configured and the directory is writable.

Database connection errors

Verify your DATABASE_URL is formatted correctly:
postgresql://username:password@hostname:port/database_name

WhiteNoise manifest errors

If you encounter missing static file errors, set:
WHITENOISE_MANIFEST_STRICT = False
This prevents 500 errors for missing minor static files.

Import/Export errors

Ensure django-import-export is properly installed:
pip install django-import-export==4.4.0

Next Steps

Quickstart Guide

Register your first patient and explore the system

Configuration

Advanced configuration options

API Reference

Explore models, views, and endpoints

Deployment

Deploy to production platforms

Build docs developers (and LLMs) love