moonbit-neuroscore

    Typed, explainable neurosurgical scoring primitives for MoonBit

    clinical
    neurosurgery
    scoring
    healthcare
    cli
    Download zip
    Author
    Version
    0.3.0
    License
    MIT
    Last updated
    last month
    Downloads
    13

    #moonbit-neuroscore

    面向神经外科、神经重症与急诊流程的 MoonBit 评分基础设施。它把公开临床量表表达为类型安全、可测试、可解释的纯函数;库只负责结构化计算与记录,不提供诊断或治疗建议。

    #核心能力

    • GCS、mRS、Hunt–Hess、WFNS、modified Fisher、ICH Score、ASPECTS 记录模型
    • 统一 ScoreResult:总分、风险带、缺失字段和解释文本
    • JSON 输出函数与最小 CLI:calc gcs、explain ich-score
    • 非法范围显式返回 NotApplicable,避免把坏输入伪装成临床结果

    moon run cmd/main -- calc gcs 3 4 5 # {"name":"GCS","total":12,"band":"high",...}

    #快速开始

    需要当前 MoonBit stable:

    moon check --deny-warn moon test moon fmt --check moon info

    #CLI

    moon run cmd/main -- calc gcs 3 4 5 moon run cmd/main -- explain ich-score 1 1 1 1 0

    #架构

    根包提供纯评分函数和统一结果模型,序列化独立于领域计算,cmd/main 仅负责参数解析和输出。

    #基准

    使用 pwsh ./scripts/benchmark.ps1 运行本机可复现实验,记录与限制见 BENCHMARKS.md。

    #设计边界

    量表计算的输入语义、分界点与临床场景必须由专业人员核对。本项目不是医疗器械、诊断系统或患者个体化建议工具;真实应用必须由具备资质的医护人员依据当地指南、原始病历和机构流程复核。

    公式与范围说明见 SOURCES.md,开发规划见 PROPOSAL.md。本项目刻意保持领域模型与 I/O 适配解耦,后续可增加 CSV、FHIR Observation/QuestionnaireResponse、批处理和更多公开量表,而不破坏评分核心 API。

    #许可证

    MIT License。详见 LICENSE。

    ScoreError

    pub(all) suberror ScoreError {
    UnknownScale(String)
    InvalidField(label~ : String, value~ : String, reason~ : String)
    MissingField(label~ : String)
    InvalidRow(row~ : Int, reason~ : String)
    InvalidColumn(row~ : Int, column~ : String, reason~ : String)
    DuplicateField(label~ : String)
    EmptyInput
    UnsupportedVersion(scale~ : String, version~ : String)
    } derive(Eq,
    Debug
    )

    Structured failures shared by parsers, registries, and batch evaluators.

    AuditEvent

    pub struct AuditEvent {
    sequence : Int
    kind : AuditKind
    scale : String
    case_id : String
    detail : String
    } derive(Eq,
    Debug
    )

    AuditEvent::kind_name

    fn AuditEvent::kind_name(self : AuditEvent) -> String

    AuditEvent::to_json

    fn AuditEvent::to_json(self : AuditEvent) -> String

    AuditKind

    pub(all) enum AuditKind {
    EvaluationStarted
    EvaluationCompleted
    EvaluationRejected
    BatchStarted
    BatchCompleted
    } derive(Eq,
    Debug
    )

    BatchSummary

    pub struct BatchSummary {
    total : Int
    successes : Int
    failures : Int
    records : Array[EvaluationRecord]
    } derive(
    Debug
    )

    CaseId

    pub struct CaseId {
    suite : String
    number : Int
    } derive(Eq,
    Debug
    )

    A stable identifier for a synthetic or integration test case.

    CaseId::to_string

    fn CaseId::to_string(self : CaseId) -> String

    EvaluationRecord

    pub struct EvaluationRecord {
    case_id : String
    scale : String
    result : ScoreResult?
    error : ScoreError?
    } derive(
    Debug
    )

    The result of evaluating a named score through the registry.

    EvaluationRecord::is_success

    fn EvaluationRecord::is_success(self : EvaluationRecord) -> Bool

    EvaluationRecord::summary

    fn EvaluationRecord::summary(self : EvaluationRecord) -> String

    EvidenceNote

    pub struct EvidenceNote {
    source : String
    note : String
    } derive(
    Debug
    )

    FieldDiagnostic

    pub struct FieldDiagnostic {
    field : String
    value : String
    message : String
    } derive(Eq,
    Debug
    )

    RiskBand

    pub(all) enum RiskBand {
    Low
    Moderate
    High
    Severe
    NotApplicable
    } derive(Eq,
    Debug
    )

    ScaleDescriptor

    pub struct ScaleDescriptor {
    id : String
    title : String
    minimum : Int
    maximum : Int
    description : String
    } derive(Eq,
    Debug
    )

    A machine-readable description of a score exposed by this module.

    The catalog is intentionally descriptive: it does not replace the source notes or a local clinical validation process.

    ScoreCase

    pub struct ScoreCase {
    id : CaseId
    scale : String
    fields : Array[ScoreInput]
    expected_total : Int?
    expected_band : RiskBand?
    note : String
    } derive(Eq,
    Debug
    )

    ScoreCase::is_expected

    fn ScoreCase::is_expected(self : ScoreCase, result : ScoreResult) -> Bool

    ScoreInput

    pub struct ScoreInput {
    label : String
    value : Int
    } derive(Eq,
    Debug
    )

    ScoreResult

    pub struct ScoreResult {
    name : String
    total : Int
    band : RiskBand
    missing : Array[String]
    explanation : String
    evidence : Array[EvidenceNote]
    } derive(
    Debug
    )

    aspects

    fn aspects(regions_involved : Int) -> ScoreResult

    audit_event

    fn audit_event(sequence~ : Int, kind~ : AuditKind, scale~ : String, case_id~ : String, detail~ : String) -> AuditEvent

    band_name

    fn band_name(band : RiskBand) -> String

    case_id

    fn case_id(suite~ : String, number~ : Int) -> CaseId

    evaluate_csv_rows

    fn evaluate_csv_rows(scale~ : String, rows~ : Array[String]) -> BatchSummary

    evaluate_scale

    fn evaluate_scale(case_id~ : String, scale~ : String, fields~ : Array[ScoreInput]) -> EvaluationRecord

    Evaluate a supported scale using the same public calculators as direct callers.

    evaluation_failure

    fn evaluation_failure(case_id~ : String, scale~ : String, error~ : ScoreError) -> EvaluationRecord

    evaluation_success

    fn evaluation_success(case_id~ : String, scale~ : String, result~ : ScoreResult) -> EvaluationRecord

    field_diagnostic

    fn field_diagnostic(field~ : String, value~ : String, message~ : String) -> FieldDiagnostic

    gcs

    fn gcs(eye : Int, verbal : Int, motor : Int) -> ScoreResult

    hunt_hess

    fn hunt_hess(grade : Int) -> ScoreResult

    ich_score

    fn ich_score(gcs_points : Int, age_points : Int, volume_points : Int, ivh_points : Int, infratentorial_points : Int) -> ScoreResult

    modified_fisher

    fn modified_fisher(ct_grade : Int) -> ScoreResult

    mrs

    fn mrs(stage : Int) -> ScoreResult

    parse_csv_row

    fn parse_csv_row(row : String) -> Array[String] raise ScoreError

    Parse one RFC-4180-style row. Quoted fields may contain commas and escaped quotes. Newlines are handled by the caller so row diagnostics remain clear.

    scale_catalog

    fn scale_catalog() -> Array[ScaleDescriptor]

    Return the stable catalog of score identifiers supported by this release.

    scale_descriptor

    fn scale_descriptor(id : String) -> ScaleDescriptor?

    Look up a score descriptor without throwing on an unknown identifier.

    score_case

    fn score_case(id~ : CaseId, scale~ : String, fields~ : Array[ScoreInput], expected_total? : Int, expected_band? : RiskBand, note~ : String) -> ScoreCase

    score_error_code

    fn score_error_code(error : ScoreError) -> String

    score_error_message

    fn score_error_message(error : ScoreError) -> String

    score_input

    fn score_input(label~ : String, value~ : Int) -> ScoreInput

    score_result_fhir_observation

    fn score_result_fhir_observation(result : ScoreResult, identifier : String) -> String

    score_result_json

    fn score_result_json(result : ScoreResult) -> String

    wfns

    fn wfns(grade : Int) -> ScoreResult