Skip to main content

Example Projects

MOISSCode ships with five example protocols in the examples/ directory. Three of these are comprehensive, production-style projects that demonstrate real-world clinical workflows across different medical domains.


Quick Start

Run any example with:

moiss run examples/icu_admission.moiss -v

Or via Python directly:

python -m moisscode.cli run examples/icu_admission.moiss -v

1. ICU Admission Bundle

File: examples/icu_admission.moiss
Domain: Critical Care
Events generated: 103

A comprehensive ICU admission workup covering everything from initial severity scoring to nutrition planning and multi-drug therapy.

Modules Used

ModulePurpose
med.scoresSOFA + qSOFA severity scoring
med.lab8 individual lab results + eGFR (CKD-EPI 2021)
med.nutritionBMI, Harris-Benedict, ICU caloric targets, TPN, IV fluids
med.pk3-drug interaction check + dose validation
med.dbPatient and lab persistence
KAEBiomarker tracking (HR, lactate, SpO2)

Process Flow

graph TD
A[Patient Admission] --> B[Severity Scoring]
B --> C[SOFA + qSOFA]
C --> D{SOFA >= 6?}
D -->|Yes| E[CRITICAL Alert]
D -->|No| F[Continue]
E --> F
F --> G[KAE Biomarker Tracking]
G --> H[Lab Interpretation]
H --> I[8 labs: WBC, Hgb, Plt, Na, K, Cr, Glucose, Lactate]
I --> J[Renal Function: eGFR]
J --> K{eGFR < 60?}
K -->|Yes| L[Dose Adjustment Warning]
K -->|No| M[Continue]
L --> M
M --> N[Nutrition Assessment]
N --> O[BMI + Harris-Benedict + ICU targets + TPN + Fluids]
O --> P[PK Drug Workflow]
P --> Q[Interaction Check x3 drugs]
Q --> R[Administer: Norepinephrine + Vancomycin + Meropenem]
R --> S[Database Persistence]
S --> T[Clinical Assessment: Sepsis]
T --> U[Summary Alerts]

Code

protocol ICU_Admission {
input: Patient p;

// -- Severity Scoring --
let sofa = med.scores.sofa(p);
let qsofa = med.scores.qsofa(p);

if sofa >= 6 {
alert "SOFA >= 6 -> High mortality risk" severity: critical;
}

// -- Vital Sign Tracking via KAE --
track p.hr using KAE;
track p.lactate using KAE;
track p.spo2 using KAE;

// -- Lab Interpretation --
let wbc = med.lab.interpret("WBC", 18.5);
let hgb = med.lab.interpret("Hgb", 8.2);
let plt = med.lab.interpret("Plt", 95);
let sodium = med.lab.interpret("Na", 131);
let potassium = med.lab.interpret("K", 5.8);
let creatinine = med.lab.interpret("Cr", 2.1);
let glucose = med.lab.interpret("Glucose", 220);
let lactate_lab = med.lab.interpret("Lactate", 3.2);

// -- Renal Function (CKD-EPI 2021) --
let gfr_result = med.lab.gfr(2.1, 55, "M");

// -- Nutrition Assessment --
let bmi = med.nutrition.bmi(70, 170);
let caloric_need = med.nutrition.harris_benedict(70, 170, 55, "M");
let icu_targets = med.nutrition.icu_caloric_target(70, "acute");
let fluids = med.nutrition.maintenance_fluids(70);
let tpn = med.nutrition.tpn_calculate(70, 1400, 84);

// -- Multi-Drug PK Workflow --
let drugs = ["Vancomycin", "Meropenem", "Norepinephrine"];
for drug in drugs {
med.pk.check_interactions(drug);
}

administer Norepinephrine dose: 0.1 mcg/kg/min;
administer Vancomycin dose: 1000 mg;
administer Meropenem dose: 1000 mg;

// -- Persistence + Assessment --
med.db.save_patient("ICU-001", "Admission Patient", 55, 70.0, "M");
assess p for sepsis;
}

Sample Output (abbreviated)

[1]  LOG: [Import] med.lab
[2] LOG: [Import] med.nutrition
[3] LOG: [Import] med.pk
[7] LOG: [Protocol] Executing: ICU_Admission
[9] LOG: [Let] sofa = 1
[12] LOG: [Let] qsofa = 3
[14] LOG: [Track] p.hr = 110 (KAE: pos=91.67, vel=21.6471)
[15] LOG: [Track] p.lactate = 3.2 (KAE: pos=2.67, vel=0.6306)
[16] LOG: [Track] p.spo2 = 94 (KAE: pos=78.33, vel=18.5098)
...
[PK] Interaction check: Vancomycin ? No known interactions
[PK] Interaction check: Meropenem ? No known interactions
[PK] Administer Norepinephrine 0.1 mcg/kg/min | MOISS: PROPHYLACTIC
[PK] Administer Vancomycin 1000 mg | MOISS: FUTILE
[PK] Administer Meropenem 1000 mg | MOISS: FUTILE
[DB] Patient ICU-001 saved
...
[93] LOG: [Assess] Evaluating p for sepsis...
[94] LOG: [Assess] Result: score=3, scoring=qSOFA, risk=HIGH

2. Antibiotic Stewardship Advisor

File: examples/abx_stewardship.moiss
Domain: Infectious Disease
Events generated: 113

An intelligent antimicrobial selection workflow that identifies organisms, checks susceptibility, evaluates pharmacogenomics, and selects therapy based on patient severity.

Modules Used

ModulePurpose
med.microOrganism ID, susceptibility (MIC), Gram stain DDx, empiric therapy
med.labRenal function (eGFR) for dose adjustment
med.pkDrug interaction screening
med.genomicsCYP450 metabolism, drug-gene checks, dosing guidance
med.researchHIPAA de-identification for research export
med.dbPatient and lab persistence

Process Flow

graph TD
A[Patient Evaluation] --> B[qSOFA Severity]
B --> C{qSOFA >= 2?}
C -->|Yes| D[Urgent: Broad Spectrum]
C -->|No| E[Targeted: Narrow Spectrum]

A --> F[Organism Identification]
F --> G[E. coli + S. aureus + P. aeruginosa]
G --> H[Gram Stain DDx]
H --> I[Susceptibility Testing]
I --> J[5 MIC Breakpoint Tests]

A --> K[Empiric Therapy Lookup]
K --> L[UTI + Pneumonia + Sepsis]

A --> M[Renal Function]
M --> N{eGFR < 30?}
N -->|Yes| O[Dose Adjustment Warning]
N -->|No| P[Standard Dosing]

A --> Q[Pharmacogenomics]
Q --> R[CYP2C19 Check: Voriconazole]
R --> S[Dosing Guidance]
S --> T[Multi-Drug Interaction Screen]

D --> U[Administer Meropenem + Vancomycin]
E --> V[Administer Ceftriaxone]

U --> W[De-identify for Research]
V --> W
W --> X[Final Assessment]

Code

protocol AntibioticStewardship {
input: Patient p;

let score = med.scores.qsofa(p);

// -- Organism Identification --
let ecoli_profile = med.micro.identify("e_coli");
let staph_profile = med.micro.identify("s_aureus");
let pseudo_profile = med.micro.identify("p_aeruginosa");
let gram_neg_rods = med.micro.gram_stain_ddx("negative", "rod");

// -- Susceptibility Testing --
let ecoli_cipro = med.micro.susceptibility("e_coli", "Ciprofloxacin", 0.25);
let ecoli_ceftri = med.micro.susceptibility("e_coli", "Ceftriaxone", 0.5);
let staph_vanco = med.micro.susceptibility("s_aureus", "Vancomycin", 1.0);

// -- Empiric Therapy --
let sepsis_empiric = med.micro.empiric_therapy("sepsis");

// -- Pharmacogenomics --
let cyp_voriconazole = med.genomics.drug_gene_check("Voriconazole");
let dosing = med.genomics.dosing_guidance("CYP2C19", "Voriconazole", "*1/*2");
let genomic_interactions = med.genomics.interaction_check(
["Voriconazole", "Omeprazole", "Clopidogrel"]
);

// -- Therapy Selection --
if score >= 2 {
administer Meropenem dose: 1000 mg;
administer Vancomycin dose: 1000 mg;
} else {
administer Ceftriaxone dose: 1000 mg;
}

// -- Research Export --
med.research.deidentify(p);
assess p for sepsis;
}

Sample Output (abbreviated)

[7]  LOG: [Protocol] Executing: AntibioticStewardship
[9] LOG: [Let] score = 3
...
[17] LOG: [Let] ecoli_profile = {type: MICRO_ID, organism: Escherichia coli,
gram: negative, shape: rod, ...}
[22] LOG: [Let] gram_neg_rods = {type: GRAM_DDX, differentials:
[Escherichia coli, Klebsiella pneumoniae, Pseudomonas aeruginosa, ...]}
...
[30] LOG: [Let] ecoli_cipro = {interpretation: SUSCEPTIBLE, mic: 0.25,
breakpoint: 1.0}
...
[45] LOG: [Let] cyp_voriconazole = {gene: CYP2C19, impact: MAJOR,
recommendation: Consider dose adjustment}
...
[PK] Administer Meropenem 1000 mg | MOISS: FUTILE
[PK] Administer Vancomycin 1000 mg | MOISS: FUTILE
...
[103] LOG: [Assess] Result: score=3, scoring=qSOFA, risk=HIGH

3. Outbreak Response Toolkit

File: examples/outbreak_response.moiss
Domain: Public Health & Epidemiology
Events generated: 106

Population-level epidemic modeling combined with patient-level triage. Models disease transmission with SIR and SEIR compartmental models, calculates public health metrics, and triages individual patients.

Modules Used

ModulePurpose
med.epiDisease params, R0, SIR/SEIR simulation, herd immunity, incidence, prevalence, CFR
med.microOutbreak pathogen ID and susceptibility
med.labSurveillance lab interpretation (WBC, CRP, Procalcitonin, Lactate)
med.scoresPatient triage (qSOFA)
med.dbSurveillance data persistence
med.researchDe-identification for outbreak reporting

Process Flow

graph TD
A[Outbreak Detection] --> B[Disease Parameter Lookup]
B --> C[COVID-19 + Measles + Influenza]

A --> D[R0 Calculation]
D --> E{R0 >= 2?}
E -->|Yes| F[CRITICAL: Sustained Transmission]
E -->|No| G[Monitor]

D --> H[Herd Immunity Threshold]

A --> I[Epidemic Modeling]
I --> J[SIR Model: 100K population, 90 days]
I --> K[SEIR Model: with exposed compartment]

A --> L[Population Metrics]
L --> M[Incidence Rate]
L --> N[Prevalence]
L --> O[Case Fatality Rate]

A --> P[Pathogen ID]
P --> Q[K. pneumoniae identification]
Q --> R[Susceptibility: Meropenem + Ciprofloxacin]

A --> S[Patient Triage]
S --> T[qSOFA Scoring]
T --> U{qSOFA >= 2?}
U -->|Yes| V[RED: Administer Meropenem]
U -->|No| W[YELLOW/GREEN: Monitor]

V --> X[De-identify + Report]
W --> X

Code

protocol OutbreakSurveillance {
input: Patient p;

// -- Disease Parameters --
let covid_params = med.epi.disease_params("covid19");
let measles_params = med.epi.disease_params("measles");

// -- R0 Calculation --
let r0_estimate = med.epi.r0(0.3, 0.1);
let herd_thresh = med.epi.herd_immunity(3.0);

// -- Epidemic Modeling --
let sir_result = med.epi.sir_model(100000, 10, 0.3, 0.1, 90);
let seir_result = med.epi.seir_model(100000, 10, 0.3, 0.1, 0.2, 90);

// -- Population Metrics --
let incidence = med.epi.incidence_rate(450, 500000, 30);
let prev = med.epi.prevalence(2500, 500000);
let cfr = med.epi.cfr(12, 450);

// -- Pathogen Identification --
let pathogen = med.micro.identify("k_pneumoniae");
let kp_mero = med.micro.susceptibility("k_pneumoniae", "Meropenem", 0.25);

// -- Patient Triage --
let qsofa_score = med.scores.qsofa(p);
track p.hr using KAE;
track p.spo2 using KAE;

if qsofa_score >= 2 {
alert "Patient triaged RED" severity: critical;
administer Meropenem dose: 1000 mg;
}

med.research.deidentify(p);
assess p for sepsis;
}

Sample Output (abbreviated)

[7]  LOG: [Protocol] Executing: OutbreakSurveillance
[9] LOG: [Let] covid_params = {type: EPI_DISEASE, R0: 3.0,
incubation_days: 5, infectious_days: 10, cfr: 1.0, ...}
...
[15] LOG: [Let] r0_estimate = {type: EPI_R0, R0: 3.0, status: EPIDEMIC,
herd_immunity_threshold: 0.667}
[17] LOG: [Let] herd_thresh = {threshold_percent: 66.67,
interpretation: 66.7% of population must be immune}
...
[19] LOG: [Let] sir_result = {type: EPI_SIR, population: 100000,
peak_infected: 28933, peak_day: 45, attack_rate: 94.06}
[21] LOG: [Let] seir_result = {type: EPI_SEIR, population: 100000,
peak_infected: 14960, peak_day: 52, incubation_period: 5.0}
...
[29] LOG: [Let] incidence = {incidence_per_100k_per_year: 1095.0}
[31] LOG: [Let] prev = {prevalence_percent: 0.5, prevalence_per_100k: 500.0}
[33] LOG: [Let] cfr = {cfr_percent: 2.667}
...
[95] LOG: [Assess] Result: score=3, scoring=qSOFA, risk=HIGH

4. Diabetes CGM Dashboard

Domain: Endocrinology / Diabetes Management

A comprehensive diabetes management protocol using med.glucose, med.lab, med.scores, med.icd, and med.pk.

Read the full step-by-step walkthrough


5. Drug Discovery Screening Pipeline

Domain: Medicinal Chemistry / Pharmaceutical R&D

An end-to-end compound screening and clinical trial design workflow using med.chem, med.pk, med.research, and med.lab.

Read the full step-by-step walkthrough


Legacy Examples

Two simpler examples are also included for quick reference:

  • examples/sepsis_workup.moiss - Basic sepsis screening with custom types and loops
  • examples/pk_workflow.moiss - PK calculations, MOISS classification, and billing
  • examples/language_features.moiss - Syntax showcase (variables, conditionals, alerts)

See Also