The Sanctuary

Writing about interests; Computer Science, Philosophy, Artificial Intelligence and more!

Introduction to MUMPS: The Database Programming Language

mumpsdatabaseprogramminghealthcare

MUMPS (Massachusetts General Hospital Utility Multi-Programming System), also known as M, is a programming language created in the late 1960s that remains widely used today, particularly in healthcare and financial systems. What makes MUMPS unique is its integrated database—the language and database are inseparable, making it exceptionally efficient for handling hierarchical data.

Why MUMPS Still Matters

Despite its age, MUMPS powers critical systems worldwide:

  • Epic Systems - The largest electronic health records (EHR) vendor in the US
  • VA VistA - The Veterans Affairs hospital information system
  • Major financial institutions - For transaction processing

The language’s persistence stems from its:

  • Built-in hierarchical database with automatic persistence
  • Exceptional performance for sparse data
  • Native support for concurrent access
  • Compact, efficient code

Getting Started with MUMPS Implementations

There are several open-source MUMPS implementations available. Here are two notable ones:

MUMPS 1995 by Ray Newman

This is an implementation of ANSI Standard MUMPS 1995 (ISO/IEC 11756) that runs on FreeBSD, macOS, Linux, Raspberry Pi (ARM under Debian), and Windows (via Cygwin).

Downloading and Building:

The project is hosted on SourceForge. Download the source code, then compile it:

# Extract and enter the directory
tar -xzf mumps-*.tar.gz
cd mumps-*

# Build the project
./make

Setting Up the Database:

# Create a new database environment
./mumps -v TEST -b 16 -s 1000 testdb

# Start with 2 jobs
./mumps -j2 testdb

# Load utilities
./mumps -x 'O 1:("utils":"R") U 1 R X X X' testdb

# Start interactive session
./mumps testdb

You can now run MUMPS commands interactively. Type halt to exit the session.

Open Mumps by Kevin C. O’Kane

Open Mumps is an implementation developed by Kevin C. O’Kane of the University of Northern Iowa. It’s actively maintained and regularly updated, making it a good choice for learning and experimentation.

The interpreter is straightforward to set up and reflects a clean implementation of the M technology. After installation, you can run MUMPS files directly from the command line.

Connecting MUMPS to Apache via CGI

Common Gateway Interface (CGI) allows web servers to execute programs and generate dynamic web pages. You can integrate MUMPS with Apache to build web applications.

Setting Up Apache

First, install Apache if you haven’t already:

sudo apt-get install apache2

Verify the installation by navigating to http://127.0.0.1/

The configuration file /etc/apache2/conf-available/serve-cgi-bin.conf maps /cgi-bin to /usr/lib/cgi-bin/ and enables CGI execution.

Enabling CGI Module

Activate the CGI module on Apache:

sudo a2enmod cgi
sudo service apache2 restart

Writing a MUMPS CGI Script

Here’s a simple MUMPS CGI script that outputs HTML:

#!/usr/bin/env mumps
; MUMPS CGI Example
;
write "Content-Type: text/html",!,!
write "<html>",!
write "<head><title>MUMPS CGI</title></head>",!
write "<body>",!
write "<h1>Hello from MUMPS!</h1>",!
write "<p>This page was generated by a MUMPS script.</p>",!
write "</body>",!
write "</html>",!
quit

Important: Always output the correct HTTP headers before your HTML content. The Content-Type header followed by a blank line is required.

Place your script in /usr/lib/cgi-bin/, make it executable, and access it via http://127.0.0.1/cgi-bin/your-script.

MUMPS Language Basics

Here are some fundamental concepts:

; Variables - no declaration needed
SET name="Achraf"
SET age=30

; Global variables (persisted to database) start with ^
SET ^patients(1,"name")="John Doe"
SET ^patients(1,"age")=45

; Output
WRITE "Hello, ",name,!

; Conditionals
IF age>18 WRITE "Adult"

; Loops
FOR i=1:1:10 WRITE i,!

Further Resources


MUMPS may seem archaic compared to modern languages, but its elegant integration of database and programming language concepts continues to serve mission-critical applications. Understanding MUMPS opens doors to healthcare IT and systems where reliability is paramount.


Introduction to MUMPS: The Database Programming Language

A comprehensive guide to the language powering healthcare and financial systems.

Achraf SOLTANI — April 17, 2022