{"id":26075,"library":"picorules-compiler-js-core","title":"Picorules Compiler JS Core","description":"Pure JavaScript/TypeScript compiler and runtime evaluator for the Picorules clinical decision support language. Compiles ruleblocks to optimized SQL (Oracle, SQL Server, PostgreSQL) or evaluates directly in JavaScript for single-patient use (browser, Node.js, edge). v1.1.1 – production-ready, zero runtime dependencies (Zod only for input validation), full type safety, tree-shakeable ESM/CJS, 406 tests. Unique: dual execution mode (SQL batch vs in-memory), pluggable data adapters (EADV built-in), automatic cross-ruleblock dependency resolution.","status":"active","version":"1.1.1","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","picorules","sql","compiler","runtime","evaluator","clinical","eadv","decision-support","typescript"],"install":[{"cmd":"npm install picorules-compiler-js-core","lang":"bash","label":"npm"},{"cmd":"yarn add picorules-compiler-js-core","lang":"bash","label":"yarn"},{"cmd":"pnpm add picorules-compiler-js-core","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Input validation for ruleblock sources and options","package":"zod","optional":false}],"imports":[{"note":"ESM-only since v1.0; use dynamic import for CJS.","wrong":"const { compile } = require('picorules-compiler-js-core')","symbol":"compile","correct":"import { compile } from 'picorules-compiler-js-core'"},{"note":"Named export, not default.","wrong":"import parse from 'picorules-compiler-js-core'","symbol":"parse","correct":"import { parse } from 'picorules-compiler-js-core'"},{"note":"All exports from package root; no subpath exports.","wrong":"import { evaluate } from 'picorules-compiler-js-core/evaluate'","symbol":"evaluate","correct":"import { evaluate } from 'picorules-compiler-js-core'"},{"note":"Case-sensitive: 'Eadv' not 'EADV'.","wrong":"import { EADVDataAdapter } from 'picorules-compiler-js-core'","symbol":"EadvDataAdapter","correct":"import { EadvDataAdapter } from 'picorules-compiler-js-core'"},{"note":"Named enum export.","wrong":"import Dialect from 'picorules-compiler-js-core'","symbol":"Dialect","correct":"import { Dialect } from 'picorules-compiler-js-core'"},{"note":"Available from root index.","wrong":"import { evaluateAll } from 'picorules-compiler-js-core/runtime'","symbol":"evaluateAll","correct":"import { evaluateAll } from 'picorules-compiler-js-core'"}],"quickstart":{"code":"import { parse, evaluate, EadvDataAdapter } from 'picorules-compiler-js-core';\n\nconst prbSource = `\n  #define_ruleblock(cd_obesity, {\n    description: \"BMI assessment\",\n    is_active: 2\n  });\n\n  ht => eadv.obs_height.val.lastdv();\n  wt => eadv.obs_weight.val.lastdv();\n\n  bmi : { ht_val!? and wt_val!? => round(wt_val / power(ht_val / 100, 2), 1) };\n  is_obese : { bmi > 30 => 1 }, { => 0 };\n`;\n\nconst parsed = parse([{ name: 'cd_obesity', text: prbSource, isActive: true }]);\nconst adapter = new EadvDataAdapter([\n  { eid: 1, att: 'obs_height', dt: '2024-06-01', val: 170 },\n  { eid: 1, att: 'obs_weight', dt: '2024-06-01', val: 95 },\n]);\nconst result = evaluate(parsed[0], adapter);\nconsole.log(result);\n// { ht_val: 170, ht_dt: Date, wt_val: 95, wt_dt: Date, bmi: 32.9, is_obese: 1 }","lang":"typescript","description":"Parses a Picorules ruleblock, loads EADV patient data, and evaluates the rule in JavaScript (no SQL required)."},"warnings":[{"fix":"Access result.sql[index] instead of result.sql[ruleblockName].","message":"v1.1.0 changed the `compile` return type: `.sql` is now an array of strings indexed by ruleblock order, not an object keyed by ruleblock name.","severity":"breaking","affected_versions":"<1.1.0"},{"fix":"Upgrade Node.js to >= 16.","message":"v1.0 required Node.js >= 14; v1.1+ requires Node.js >= 16 due to ES2021 features.","severity":"breaking","affected_versions":">=1.1.0"},{"fix":"Wrap data with `new EadvDataAdapter(data)` before passing to `evaluate`.","message":"The `evaluate` function's second parameter `adapter` formerly accepted plain objects; now requires an `EadvDataAdapter` instance.","severity":"deprecated","affected_versions":"<1.1.0"},{"fix":"Ensure each ruleblock has a distinct `name` field.","message":"Ruleblock names must be unique; duplicate names cause silent overwrite.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `compile()` for non-EADV databases.","message":"The `evaluate` mode does NOT support all SQL dialects; it only works with EADV data adapter. For other data sources, compile to SQL and execute externally.","severity":"gotcha","affected_versions":"all"},{"fix":"Always import and use the `Dialect` enum.","message":"TypeScript users: `Dialect` enum values are strings; ensure you use `Dialect.ORACLE`, not raw strings like `'oracle'`.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure EadvDataAdapter receives an array of EADV observations. At minimum: [{ eid: 1, att: 'some_att', dt: '2024-01-01', val: 123 }]","cause":"Data adapter not properly initialized or empty data array.","error":"TypeError: Cannot read properties of undefined (reading 'lastdv')"},{"fix":"Check that all referenced ruleblocks are included in the array passed to `parse()` and that spelling matches.","cause":"Cross-ruleblock reference to a symbol that does not exist in any parsed ruleblock.","error":"Error: Ruleblock 'X' imports unknown symbol 'Y'"},{"fix":"Read the .prb file as a string (e.g., using fs.readFileSync) and pass the text to `parse()`.","cause":"Mistakenly tried to parse a `.prb` file as JSON instead of raw text.","error":"SyntaxError: Unexpected token '#' in JSON at position 0"},{"fix":"Run `npm install picorules-compiler-js-core`. Ensure your bundler resolves ESM (set `\"type\": \"module\"` in package.json or use `.mjs` extension).","cause":"Package not installed or import path incorrect in bundler environment.","error":"Module not found: Error: Can't resolve 'picorules-compiler-js-core' in '/path'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}