Skip to main content

Crate clincalc

Crate clincalc 

Source
Expand description

§clincalc

Open, auditable clinical calculators: the pure scoring engine and the clincalc command-line surface in one crate.

§Feature flags

  • default = ["cli"] builds the standalone clincalc binary and exposes the reusable cli module.
  • mcp adds the optional local stdio MCP server used by clincalc mcp. It pulls in the MCP SDK and async runtime behind the feature gate.
  • default-features = false builds only the leaf engine: calculators, registry, schemas, tags, licences, and CalculationResponse. This mode depends only on serde and serde_json.
clincalc = { version = "0.2", default-features = false }

§One registry, many surfaces

With default-features = false this crate is a strict leaf: it never depends on a host application and never on an async runtime. That is what lets the same logic drive every surface without divergence:

  • the standalone clincalc binary (the default cli feature)
  • host CLIs that embed the cli module (for example GitEHR’s gitehr calc)
  • the optional MCP server (each calculator exposed as a tool)
  • a native desktop GUI (called natively over a Tauri command)
  • the single-file web calculators

Adding a calculator to all() surfaces it everywhere.

let calc = clincalc::get("feverpain").expect("calculator exists");
let input = serde_json::json!({
    "fever": true,
    "purulence": true,
    "attend_rapidly": true,
    "inflamed_tonsils": false,
    "absence_of_cough": false
});
let response = calc.calculate(&input).expect("valid input");
assert_eq!(response.calculator, "feverpain");

Every calculator implements the Calculator trait and returns a CalculationResponse - the Rust counterpart of the JSON schema the web calculators dispatch via gitehr-bridge.js.

Scoring functions are pure: no clock, no I/O, no global state. A host that needs a timestamp stamps it when recording the result, so the core stays deterministic and trivially testable.

Re-exports§

pub use calculator::CalcError;
pub use calculator::Calculator;
pub use license::CalculatorLicense;
pub use proprietary::ProprietaryCalculator;
pub use response::CalculationResponse;
pub use tags::all_tags;
pub use tags::for_name as tags_for_name;
pub use template::template_from_schema;

Modules§

api
The HTTP REST API surface, behind the optional rest-api feature. HTTP REST API surface for clincalc, behind the rest-api feature.
calculator
The Calculator trait and its error type.
calculators
The calculator implementations.
cli
The command-line surface (CalcCommand, run), behind the cli feature. Embeddable by host CLIs such as GitEHR’s gitehr calc.
license
Distribution licence / provenance for a calculator’s clinical algorithm.
mcp
The Model Context Protocol server surface, behind the optional mcp feature. Feature-gated Model Context Protocol server surface.
proprietary
Proprietary / licence-locked calculators.
response
The result schema returned by every calculator.
tags
Calculator tags - lightweight taxonomy for discovery and filtering.
template
Fillable input templates derived from a calculator’s JSON Schema.

Functions§

all
Every calculator known to the engine, in display order.
get
Look up a single calculator by its machine name (e.g. "feverpain").