@crvouga/mockingbird-service-odx

中文文档
3.10.9发布于 2026/11/03MITTypeScriptES Module构建来源已验证近 30 天下载 1.6万

Stateful emulator of the (retired) Optimal DX partner API: patients, partner links, HL7 and structured lab imports, Functional Health Reports (JSON/PDF), webhook registrations, and signed PatientTest webhooks.

原始使用文档
文档目录9 节
  1. Install
  2. Usage
  3. Routes
  4. Webhooks
  5. Admin (beyond the standard contract)
  6. Namespaces
  7. Known consumer bugs
  8. Deliberately not modelled
  9. API

@crvouga/mockingbird-service-odx

Local emulators. Real API contracts. Part of Mockingbird.

Stateful emulator of the Optimal DX (ODX) partner API for test suites: partner labs and their biomarker elements, practice patients (create, update, delete, partner link, search), lab imports (HL7 v2 ORU and structured results), the Functional Health Report (JSON or PDF), webhook registrations, and the signed PatientTest webhooks ODX posts back.

The vendor was retired 2026-07-22. Our queue paths are gated only by the acme-pdf-enabled flag (default false), so a local stack with no PostHog still calls ODX. The cheaper fix is to turn that flag on through the PostHog emulator (@crvouga/mockingbird-service-posthog); use this emulator when a suite must exercise the ODX path itself (bio-age webhooks, the Healthie PDF upload, migrations).

  • Operation coverage: SUPPORT.md
  • ODX publishes no spec: openapi.yaml is hand-authored from our consumer's wire shapes (optimal.dx.service.ts, the webhook guard and DTO, and QA's odx-client.ts).

Install

npm install -D @crvouga/mockingbird-service-odx

ESM only. Node >= 22 or Bun >= 1.2. No native dependencies. Serve it with npx mockingbird-odx serve, createServer from ./server (Node), or createRuntime with any Fetch server.

Usage

The real base URL is https://odxinstanceresource.azure-api.net/<partner>; the partner segment is your account's slug. Point OPTIMAL_URL at the emulator (it is overridable; no path prefix is needed), keep any OPTIMAL_API_KEY and OPTIMAL_PRACTICE_ID. Pre-register the backend's webhook, or let manageWebhooks register it through POST /v1/webhook as it does in production:

npx mockingbird-odx serve --port 8817 \
  --webhook-url http://127.0.0.1:3000/odx/webhook   # must equal SYSTEM_API_DEPLOYMENT_URL/odx/webhook
import { createServer } from "@crvouga/mockingbird-service-odx/server"

// Test setup: the emulator, with the backend's webhook pre-registered.
const server = await createServer({ webhook: { url: "http://127.0.0.1:3000/odx/webhook" } })

// Application code: OPTIMAL_URL is server.url; any OPTIMAL_API_KEY and practice id.
const baseUrl = server.url
const created = await fetch(`${baseUrl}/v1/practice/p1/patient`, {
  method: "POST",
  headers: { ApiKey: "any", "content-type": "application/json" },
  body: JSON.stringify({
    firstName: "Ada",
    lastName: "Lovelace",
    gender: "Female",
    email: "[email protected]",
  }),
})
const patient = (await created.json()) as { patientId: number }
// …the app posts HL7 to /v1/practice/p1/patient/{patientId}/test; the emulator answers the parsed
// PatientTest and posts a signed `Created` webhook to /odx/webhook.
await server.close()

Routes

RouteBehaviour
GET /v1/partner/labs[{labId, name, isCurrentLab}]: AHA (1), Quest (2), LabCorp (3).
GET /v1/elements/{labId}The element corpus (ELEMENTS) for the lab: elementId, elementName, elementGenderType, cuUnit, siUnit, cuToSiConversionFactor, elementReferences[{elementCode}] (LOINC codes HL7 OBX-3 is mapped by). Includes the nine phenotypic-age inputs (ids 494, 496, 506, 511, 537/538, 556, 564, 568, 571). Unknown lab → 404 {Message}.
POST /v1/practice/{pid}/patientCreates an OdxPatient with a numeric patientId (100001…). firstName, lastName, email required, else ASP.NET problem details 400. dateOfBirth becomes YYYY-MM-DDT00:00:00; gender is normalized to Male/Female/Unknown.
PUT /v1/practice/{pid}/patient/{id}Replaces the patient; 404 {Message} when unknown in that practice.
DELETE /v1/practice/{pid}/patient/{id}204; drops its tests (QA teardown).
POST /v1/practice/{pid}/patient/{id}/partner/{localUserId}Body is the literal false; stores our user id (admin-visible). Answers true.
GET /v1/practice/{pid}/patientsAll patients; with any of email, firstName, lastName, dateOfBirth it is a case-insensitive search that answers 404 when nothing matches (our client passes ignore404).
POST …/patient/{id}/testHL7 import: {labProfileId, labId, testDate, unitType, userId, externalReference, externalMessageControlId?, externalPatientTestId, menstrualPhase, isFasting, hl7}. OBX-3 code^text maps to an element by lab code, EL<id>, or name (hs-CRP picks the patient's sex); OBX-5 values like <0.2 become comparison: "<". Unmapped / non-numeric observations land in importLogs. Emits Created. A message without MSH or OBX is a 400.
PUT …/patient/{id}/test/{testId}Re-import; emits Updated (ODX sends a Created+Updated pair with identical data).
POST …/patient/{id}/testresultsStructured import (results[{elementId, value, comparison}]); emits Created.
GET …/patient/{id}/testsThe patient's tests, oldest first.
POST /v1/reports/FunctionalHealthReportoutputType: Json → {metadata, labs, elements, sections} with the sections our storeHealthData reads (groups, above/below optimal, "Functional Body Systems" conditions, health concerns); Pdf → a valid single-page application/pdf. Unknown test → 404.
GET /v1/webhooks[{partnerWebhookId, signingKey, createDate, entityEvents: {PatientTest}, webhookUrl}] — our guard calls this on every inbound webhook to fetch the key.
POST /v1/webhook, PUT /v1/webhook/{id}Register / update (manageWebhooks).

Errors: missing / unknown ApiKey → 401 {statusCode, message} (Azure API Management's shape); ODX errors → {Message}; validation → ASP.NET problem details {title, status, errors}.

Webhooks

Every test import or re-import posts {entityType: "PatientTest", eventType, data: <PatientTest>} to each registered webhook URL subscribed to that event, with optimaldx-signature: <UPPERCASE hex HMAC-SHA256(signingKey, rawBody)>. data is the full PatientTest (results[].comparison is always a string, as our receiver's zod DTO requires). Non-2xx answers are retried (immediately, 5 s, 5 min, 30 min, 2 h). GET /__admin/webhooks, /__admin/webhooks/events, POST /__admin/webhooks/flush and …/replay work as usual.

Admin (beyond the standard contract)

RouteEffect
POST /__admin/tests/:id/webhook{eventType?: Created|Updated|Deleted, signature?: valid|short|bad}: emit a webhook for a stored test.
DELETE /__admin/tests/:idEmit Deleted and drop the test.
GET /__admin/patients, GET /__admin/testsThe namespace's records (patients include partnerUserId; the HL7 text is never stored).
GET/PUT /__admin/settings{apiKeys?: string[]} (empty accepts any key).

Fault presets (POST /__admin/faults {"preset": "<name>", "count"?: n}): wrong_length_signature, bad_signature, empty_success, no_content, not_found, server_error, slow, webhook_duplicate, webhook_reorder, webhook_drop.

Namespaces

x-mockingbird-namespace, a /__admin/ns/<name> prefix on OPTIMAL_URL, or by API key: PUT /__admin/credentials {"credentials": {"<OPTIMAL_API_KEY>": "<namespace>"}}.

Known consumer bugs

  • Wrong-length signature → 500. OdxSignatureGuard.verifyHmac calls crypto.timingSafeEqual on buffers of different lengths, which throws RangeError instead of returning false, so a truncated optimaldx-signature is a 500 (ODX then retries) rather than a 403. The wrong_length_signature preset sends a 32-character signature to reproduce it.
  • manageWebhooks "updates" a stale registration with its own old URL (a no-op), then registers the new one, so stale registrations accumulate.
  • updateWebhook passes the method as 'Put'; Node's fetch normalizes it (Bun's does not — the consumer port normalizes, as the app runs on Node).

Deliberately not modelled

  • Clinical logic: report conditions and health concerns are derived only from which results fall outside their optimal range; bio-age is not computed.
  • The real element catalog (thousands of elements, lab-specific codes): a 13-element corpus covers our consumer's needs. HL7 segments other than MSH/OBX are ignored; PID is never stored.
  • Report themes, recipients beyond the metadata label, and PDF content.
  • No official SDK exists, so there is no SDK drop-in test.

API

ExportKindDescription
OdxAPIclassThe in-process emulator: fetch(request), reset(), emit(testId, eventType, signature?), patients(), tests(). Options: sqlite, now, namespace, settings, onWebhook.
createRuntimefunctionThe emulator with the full service contract. Options: webhook: {url, signingKey?}, settings, retryDelaysMs, fetch, clock, seed, adminKey, onLog.
ODX_PRESETSobjectEvery named fault preset.
ODX_NAMESPACEstringThe service name, "odx".
SIGNATURE_HEADERstring"optimaldx-signature".
signOdxfunction(signingKey, body) → UPPERCASE hex HMAC-SHA256.
apiKeyCredentialfunctionThe ApiKey header (how credentials map to namespaces).
ELEMENTS, LABSarraysThe element corpus and partner labs.
matchElement, parseObservationsfunctionsHL7 OBX parsing and code → element mapping.
DEFAULT_SETTINGSobjectPer-namespace defaults.
document, operationIds, supportedOperationIdsvaluesThe vendored OpenAPI contract and its operation ids.
createServer, serveTarget, DEFAULT_PORT (./server)NodeServe over node:http; the serve CLI target; port 8817.

Part of mockingbird.

版本与发布记录

@crvouga/mockingbird-service-odx 共发布 41 个版本,首次发布于 2026/09/23;过去 12 个月发布了 41 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.10.9latest2026/11/038 天前
3.10.82026/11/038 天前
3.10.72026/11/038 天前
3.10.62026/11/038 天前
3.10.52026/11/038 天前
3.10.42026/11/038 天前

关于 @crvouga/mockingbird-service-odx 的常见问题

@crvouga/mockingbird-service-odx 是什么?

Stateful emulator of the (retired) Optimal DX partner API: patients, partner links, HL7 and structured lab imports, Functional Health Reports (JSON/PDF), webhook registrations, and signed PatientTest webhooks.

如何安装 @crvouga/mockingbird-service-odx?

在项目目录运行 npm install @crvouga/mockingbird-service-odx,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 mockingbird-odx,可以用 npx mockingbird-odx 直接运行。

@crvouga/mockingbird-service-odx 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@crvouga/mockingbird-service-odx 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@crvouga/mockingbird-service-odx 可以商用吗?

@crvouga/mockingbird-service-odx 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@crvouga/mockingbird-service-odx 的下载量有多少?

根据 npm 官方下载统计,@crvouga/mockingbird-service-odx 在 2026/10/11 – 2026/11/09 这 30 天内被下载 16,247 次,日均约 542 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@crvouga/mockingbird-service-odx 还在维护吗?

最新版本 3.10.9 发布于 2026/11/03(8 天前);至今共发布 41 个版本,其中过去 12 个月发布了 41 个;首次发布于 2026/09/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。