Explainable emergency triage scoring primitives for MoonBit.
moon check
moon test
moon run cmd/mainmoon run cmd/benchmark///|
test "README NEWS2 example" {
let report = @moonbit-triage.score_news2({
respiratory_rate: 16,
oxygen_saturation: 98,
spo2_scale: @moonbit-triage.Scale1,
supplemental_oxygen: false,
temperature_tenths_c: 370,
systolic_bp: 120,
heart_rate: 72,
consciousness: @moonbit-triage.Alert,
})
inspect(report.score, content="0")
debug_inspect(report.severity, content="Low")
}iterations=10000
checksum=54000
critical_reports=4500pub(all) struct ApacheIiInput {
temperature_tenths_c : Int
mean_arterial_pressure : Int
heart_rate : Int
respiratory_rate : Int
oxygenation_value : Int
high_fio2 : Bool
arterial_ph_hundredths : Int
sodium : Int
potassium_tenths : Int
creatinine_hundredths : Int
acute_renal_failure : Bool
hematocrit_tenths : Int
white_cell_count_tenths : Int
gcs : Int
age : Int
chronic_health : Bool
} derive(Eq, Debug)pub(all) struct AssessmentLedger {
snapshots : Array[ScoreSnapshot]
last_timestamp_minutes : Int
} derive(Eq, Debug)pub(all) struct CanadianCspineInput {
age : Int
dangerous_mechanism : Bool
paresthesias : Bool
low_risk_simple_rear_end_collision : Bool
low_risk_sitting_in_ed : Bool
low_risk_ambulatory : Bool
low_risk_delayed_neck_pain : Bool
low_risk_no_midline_tenderness : Bool
rotates_neck_45_degrees : Bool
} derive(Eq, Debug)pub(all) struct CanadianCtHeadInput {
age : Int
gcs_less_than_15_at_two_hours : Bool
suspected_open_skull_fracture : Bool
signs_of_basal_skull_fracture : Bool
vomiting_episodes : Int
age_at_least_65 : Bool
retrograde_amnesia_minutes : Int
dangerous_mechanism : Bool
anticoagulant_or_antiplatelet : Bool
} derive(Eq, Debug)pub(all) struct CapriniInput {
age : Int
bmi_over_25 : Bool
swollen_legs : Bool
varicose_veins : Bool
pregnancy_or_postpartum : Bool
oral_contraceptives_or_hormone : Bool
sepsis : Bool
serious_lung_disease : Bool
abnormal_pulmonary_function : Bool
acute_myocardial_infarction : Bool
congestive_heart_failure : Bool
inflammatory_bowel_disease : Bool
medical_patient : Bool
minor_surgery : Bool
arthroscopic_surgery : Bool
major_surgery : Bool
laparoscopic_surgery_over_45_min : Bool
malignancy : Bool
bed_rest_over_72_hours : Bool
prior_vte : Bool
family_history_vte : Bool
thrombophilia : Bool
stroke : Bool
elective_arthroplasty : Bool
hip_pelvis_leg_fracture : Bool
acute_spinal_cord_injury : Bool
} derive(Eq, Debug)pub(all) struct CharlsonInput {
age : Int
myocardial_infarction : Bool
congestive_heart_failure : Bool
peripheral_vascular_disease : Bool
cerebrovascular_disease : Bool
dementia : Bool
chronic_pulmonary_disease : Bool
connective_tissue_disease : Bool
peptic_ulcer_disease : Bool
mild_liver_disease : Bool
diabetes_without_complication : Bool
diabetes_with_end_organ_damage : Bool
hemiplegia : Bool
moderate_or_severe_renal_disease : Bool
any_tumor : Bool
leukemia : Bool
lymphoma : Bool
moderate_or_severe_liver_disease : Bool
metastatic_solid_tumor : Bool
aids : Bool
} derive(Eq, Debug)pub(all) struct GcsReport {
total : Int
eye : Int
verbal : Int
motor : Int
severity : Severity
explanations : Array[Explanation]
disclaimer : String
} derive(Eq, Debug)pub(all) struct InstrumentMetadata {
id : String
display_name : String
category : InstrumentCategory
unit : String
minimum : Int
maximum : Int
source_url : String
version : String
caution : String
keywords : Array[String]
} derive(Eq, Debug)pub(all) struct InstrumentRegistry {
entries : Array[InstrumentMetadata]
revision : String
} derive(Eq, Debug)pub(all) struct MewsInput {
systolic_bp : Int
heart_rate : Int
respiratory_rate : Int
temperature_tenths_c : Int
consciousness : Consciousness
} derive(Eq, Debug)pub(all) struct News2Input {
respiratory_rate : Int
oxygen_saturation : Int
spo2_scale : Spo2Scale
supplemental_oxygen : Bool
temperature_tenths_c : Int
systolic_bp : Int
heart_rate : Int
consciousness : Consciousness
} derive(Eq, Debug)pub(all) struct Observation {
kind : ObservationKind
value : Int
unit : MeasurementUnit
timestamp_minutes : Int
source : String
} derive(Eq, Debug)pub(all) struct PaduaInput {
active_cancer : Bool
previous_vte : Bool
reduced_mobility : Bool
known_thrombophilia : Bool
recent_trauma_or_surgery : Bool
elderly_age : Bool
heart_or_respiratory_failure : Bool
acute_mi_or_stroke : Bool
acute_infection_or_rheumatologic : Bool
bmi_over_30 : Bool
ongoing_hormonal_treatment : Bool
} derive(Eq, Debug)pub(all) struct PathwayDecision {
tier : EscalationTier
evidence : EvidenceStatus
matched_rules : Array[String]
missing_instruments : Array[String]
highest_severity : Severity
score_count : Int
explanation : String
} derive(Eq, Debug)pub(all) struct PathwayRule {
code : String
title : String
tier : EscalationTier
required_instruments : Array[String]
minimum_severity : Severity
rationale : String
} derive(Eq, Debug)pub(all) struct PecarnHeadInput {
age_under_two : Bool
altered_mentation : Bool
palpable_skull_fracture : Bool
nonfrontal_scalp_hematoma : Bool
loss_of_consciousness_minutes : Int
severe_mechanism : Bool
not_behaving_normally : Bool
signs_of_basilar_skull_fracture : Bool
severe_headache : Bool
} derive(Eq, Debug)pub(all) struct PewsInput {
behavior : PewsBehavior
cardiovascular : PewsCardiovascular
respiratory : PewsRespiratory
oxygen_support : PewsOxygenSupport
nebulizer_count : Int
} derive(Eq, Debug)pub(all) struct PreeclampsiaInput {
systolic_bp : Int
diastolic_bp : Int
platelets_thousands : Int
creatinine_hundredths_mg_dl : Int
ast_units : Int
alt_units : Int
pulmonary_edema : Bool
persistent_headache : Bool
visual_symptoms : Bool
right_upper_quadrant_pain : Bool
fetal_growth_restriction : Bool
} derive(Eq, Debug)pub(all) struct QualityFlag {
field : String
quality : MeasurementQuality
message : String
} derive(Eq, Debug)pub(all) struct RegistryChange {
id : String
kind : RegistryChangeKind
before_version : String
after_version : String
detail : String
} derive(Eq, Debug)pub(all) struct ScoreReport {
instrument : String
score : Int
severity : Severity
interpretation : String
explanations : Array[Explanation]
disclaimer : String
} derive(Eq, Debug)pub(all) struct SofaInput {
pao2_fio2 : Int
respiratory_support : Bool
platelets : Int
bilirubin_micromol : Int
mean_arterial_pressure : Int
vasopressor : VasopressorLevel
gcs_total : Int
creatinine_micromol : Int
urine_ml_day : Int
} derive(Eq, Debug)pub(all) struct Timeline {
observations : Array[Observation]
last_timestamp_minutes : Int
} derive(Eq, Debug)pub(all) struct Trend {
kind : ObservationKind
first_value : Int
latest_value : Int
delta : Int
samples : Int
rising : Bool
falling : Bool
stable : Bool
} derive(Eq, Debug)pub(all) struct TriageBundle {
news2 : ScoreReport
qsofa : ScoreReport
gcs : ScoreReport
overall : Severity
summary : String
disclaimer : String
} derive(Eq, Debug)fn audit_event(sequence : Int, event_type : String, instrument : String, report : ScoreReport, timestamp_minutes : Int, source : String, note : String) -> AuditEventfn compare_metadata(before : InstrumentMetadata?, after : InstrumentMetadata?, id : String) -> RegistryChangefn evaluate_threshold(rule_name : String, value : Int, bands : Array[ThresholdBand]) -> RuleEvaluationfn meld_component_points(value : Int, low : Int, middle : Int, high : Int) -> Intfn metadata(id : String, display_name : String, category : InstrumentCategory, unit : String, minimum : Int, maximum : Int, source_url : String, version : String, caution : String, keywords : Array[String]) -> InstrumentMetadatafn news2_oxygen_saturation_points(saturation : Int, scale : Spo2Scale, supplemental_oxygen : Bool) -> Intfn news2_supplemental_oxygen_points(supplemental_oxygen : Bool) -> Intfn observation(kind : ObservationKind, value : Int, unit : MeasurementUnit, timestamp_minutes : Int, source : String) -> Observationfn pathway_decision_explanation(tier : EscalationTier, evidence : EvidenceStatus, severity : Severity, matched_count : Int) -> Stringfn pediatric_appendicitis_anorexia_points(value : Bool) -> Intfn pediatric_appendicitis_cough_points(value : Bool) -> Intfn pediatric_appendicitis_fever_points(value : Int) -> Intfn pediatric_appendicitis_lab_points(leukocytosis : Bool, neutrophilia : Bool) -> Intfn pediatric_appendicitis_migration_points(value : Bool) -> Intfn pediatric_appendicitis_nausea_points(value : Bool) -> Intfn pediatric_appendicitis_tenderness_points(value : Bool) -> Intfn preeclampsia_liver_points(ast : Int, alt : Int, pain : Bool) -> Intfn preeclampsia_neurologic_points(headache : Bool, visual : Bool) -> Intfn preeclampsia_pressure_points(systolic : Int, diastolic : Int) -> Intfn registry_category_entries(registry : InstrumentRegistry, category : InstrumentCategory) -> Array[InstrumentMetadata]fn registry_changes(before : InstrumentRegistry, after : InstrumentRegistry) -> Array[RegistryChange]fn registry_keyword_search(registry : InstrumentRegistry, keyword : String) -> Array[InstrumentMetadata]fn registry_merge(primary : InstrumentRegistry, additions : InstrumentRegistry) -> InstrumentRegistryfn report(instrument : String, score : Int, severity : Severity, interpretation : String, explanations : Array[Explanation]) -> ScoreReportfn report_score_reconciles_with_explanations(report : ScoreReport, explanations : Array[Explanation]) -> Boolfn snapshot(instrument : String, score : Int, severity : Severity, timestamp_minutes : Int, source : String) -> ScoreSnapshotfn snapshot_from_report(report : ScoreReport, timestamp_minutes : Int, source : String) -> ScoreSnapshotfn threshold_band(label : String, minimum : Int, maximum : Int, points : Int, explanation : String) -> ThresholdBandExplainable emergency triage scoring primitives for MoonBit.