MOISSCode Language Guide
Protocols
Every MOISSCode program contains one or more protocols - named blocks of clinical logic.
protocol SepsisScreen {
input: Patient p;
// statements go here
}
Patient Input
Protocols declare patient inputs. The engine provides a default patient or accepts one via the API.
input: Patient p;
Core Fields (Always Available)
| Field | Type | Default | Description |
|---|---|---|---|
name | str | "Unknown" | Patient name |
age | int | 0 | Age in years |
weight | float | 0.0 | Weight (kg) |
height | float | 170.0 | Height (cm) |
sex | str | "U" | "M", "F", or "U" |
bp | float | 120.0 | Systolic BP (mmHg) |
diastolic_bp | float | 80.0 | Diastolic BP (mmHg) |
hr | float | 80.0 | Heart rate (bpm) |
rr | float | 16.0 | Respiratory rate |
temp | float | 37.0 | Temperature (°C) |
spo2 | float | 98.0 | O₂ saturation (%) |
gcs | int | 15 | Glasgow Coma Scale |
lactate | float | 1.0 | Lactate (mmol/L) |
Computed Properties
p.map- Mean Arterial Pressure (auto-calculated from bp and diastolic_bp)p.bmi- Body Mass Index (auto-calculated from weight and height)
Extensible Fields
The Patient type supports any additional field via the Python SDK:
from moisscode.typesystem import Patient
p = Patient(
name="Jane", age=62, bp=90,
creatinine=2.4, # Extended field
platelets=85, # Extended field
pao2_fio2=180, # Extended field
on_vasopressors=True # Extended field
)
print(p.creatinine) # 2.4 - accessed like any core field
Extended fields are used by advanced scoring systems (e.g., SOFA score uses platelets, bilirubin, creatinine, pao2_fio2). You can add any clinical data you need.
Variables
let score = med.scores.qsofa(p);
let drugs = ["Vancomycin", "Meropenem"];
let threshold = 2.0;
Conditionals
if score >= 2 {
alert "High risk" severity: critical;
} else {
alert "Stable" severity: info;
}
Operators: >, <, >=, <=, ==, !=, and, or, not
Loops
While Loop
let counter = 0;
while counter < 5 {
let counter = counter + 1;
}
For-Each Loop
let drugs = ["A", "B", "C"];
for drug in drugs {
alert drug severity: info;
}
Safety limit: 1000 iterations maximum.
Drug Administration
administer Norepinephrine dose: 0.1 mcg/kg/min;
The MOISS classifier automatically categorizes timing (PROPHYLACTIC, ON_TIME, PARTIAL, MARGINAL, FUTILE, TOO_LATE).
Tracking with KAE
Track a patient value using the Kalman-Autoencoder estimator:
track p.lactate using KAE;
Alerts
alert "Sepsis protocol activated" severity: critical;
alert "Monitoring" severity: info;
Severity levels: critical 🚨, warning ⚠️, info ℹ️
Clinical Assessment
assess p for sepsis;
Automatically calculates qSOFA and assigns risk level (HIGH / MODERATE / LOW).
Custom Types
Define domain-specific data structures:
type Bacteria {
name: str;
mic: float;
resistant: bool;
}
type MDRBacteria extends Bacteria {
resistance_genes: str;
}
Create instances:
let ecoli = Bacteria { name: "E.coli", mic: 0.5, resistant: false };
Functions
function is_resistant(mic, breakpoint) {
if mic > breakpoint {
return true;
}
return false;
}
let result = is_resistant(2.0, 1.0);
Lists
let panel = ["Vancomycin", "Meropenem", "Ceftriaxone"];
let first = panel[0];
Library Calls
All 20 modules are accessed via the med. prefix:
let score = med.scores.qsofa(p);
med.io.infuse("Pump_01", "Norepinephrine", 0.1);
med.finance.bill("99291", "Critical Care");
Comments
// This is a single-line comment
Imports
import med.biochem;
import med.lab;