The Sanctuary

Writing about interests; Computer Science, Philosophy, Mathematics and AI.

Introduction to MUMPS: The Database Programming Language

mumpsdatabaseprogramminghealthcare

The first time I opened a MUMPS codebase, I thought someone was playing a joke on me. Single-letter commands, implicit variables, and a syntax that looked like it had been compressed for telegraph transmission. It took me a week to stop fighting the language and start understanding it — and when I did, something clicked. MUMPS is not a relic; it is a design philosophy. The language and the database are one and the same — there is no ORM, no connection pool, no impedance mismatch. You write a value to a global variable and it persists. That is it. That simplicity is why MUMPS (Massachusetts General Hospital Utility Multi-Programming System), also known as M, has survived since the late 1960s and still powers some of the most critical systems on the planet.

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 will never trend on Hacker News. It will never be the subject of a conference keynote or a venture-capital pitch deck. But somewhere right now, a hospital is admitting a patient, and the system recording that admission — routing the labs, scheduling the follow-up, storing the history that a physician will read ten years from now — is almost certainly running M. There is a lesson in that longevity, and it has nothing to do with syntax. It has to do with what happens when you design a system around the shape of the data rather than the fashion of the decade.


Introduction to MUMPS: The Database Programming Language

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

Achraf SOLTANI — April 17, 2022