@nexalink/coding-contracts 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Nexalink Proprietary Software License
2
+
3
+ Copyright (c) 2026 Nexalink Health, Inc. All rights reserved.
4
+
5
+ This package and its source code are proprietary to Nexalink Health, Inc.
6
+ Access to this package does not grant any ownership interest, sublicensing
7
+ right, or right to redistribute the software except as expressly authorized in a
8
+ written agreement with Nexalink Health, Inc.
9
+
10
+ Authorized Nexalink customers and implementation partners may install and use
11
+ this package solely to evaluate, integrate, test, and operate CareCompass coding
12
+ workflow integrations for customer-approved healthcare deployments.
13
+
14
+ You may not copy, modify, publish, distribute, sell, sublicense, reverse
15
+ engineer, or use this software to provide a competing service except where
16
+ expressly permitted by a written agreement with Nexalink or by applicable law.
17
+
18
+ This software is provided "as is" without warranties of any kind, whether
19
+ express, implied, statutory, or otherwise, including warranties of
20
+ merchantability, fitness for a particular purpose, title, and non-infringement.
21
+ Nexalink is not liable for any claim, damages, or other liability arising from
22
+ use of this software except as required by applicable law or an executed written
23
+ agreement with Nexalink.
package/README.md ADDED
@@ -0,0 +1,200 @@
1
+ # `@nexalink/coding-contracts`
2
+
3
+ Canonical TypeScript contracts for Nexalink CareCompass coding workflows.
4
+
5
+ The package provides:
6
+
7
+ - TypeScript types for coding inputs, grounded outputs, supporting references,
8
+ retrieval metadata, runtime events, model prompts, and workflow policy.
9
+ - Strict [Zod](https://zod.dev/) schemas for parsing untrusted values.
10
+ - Validation helpers that return stable, machine-readable error codes.
11
+ - Canonical workflow identifiers and schema wire-version constants.
12
+ - The underlying JSON Schema documents for non-TypeScript consumers and
13
+ tooling.
14
+
15
+ This package defines data contracts only. It does not make network requests,
16
+ persist data, submit claims, or replace review by a qualified human coder.
17
+
18
+ ## Install
19
+
20
+ Pin an exact version so contract upgrades are deliberate:
21
+
22
+ ```sh
23
+ bun add @nexalink/coding-contracts@0.2.0 --exact
24
+ ```
25
+
26
+ The package supports both ES modules and CommonJS.
27
+
28
+ ## Validate a coding input
29
+
30
+ Use the Zod schema when you want parsed, typed data and detailed issues:
31
+
32
+ ```ts
33
+ import {
34
+ RCM_INPUT_SCHEMA_VERSION,
35
+ rcmCodingInputSchema,
36
+ type RcmCodingInput,
37
+ } from "@nexalink/coding-contracts";
38
+
39
+ const candidate: unknown = {
40
+ encounterId: "DEMO-ENC-1042",
41
+ diagnosisNarrative: "Synthetic example for integration testing.",
42
+ serviceDate: "2026-07-01",
43
+ claimContext: {
44
+ stage: "development",
45
+ },
46
+ };
47
+
48
+ const input: RcmCodingInput = rcmCodingInputSchema.parse(candidate);
49
+
50
+ console.log(RCM_INPUT_SCHEMA_VERSION, input.encounterId);
51
+ ```
52
+
53
+ Use the validation helper when a compact error code is more useful than a Zod
54
+ error:
55
+
56
+ ```ts
57
+ import { rcmCodingInputValidationError } from "@nexalink/coding-contracts";
58
+
59
+ const errorCode = rcmCodingInputValidationError(candidate);
60
+ if (errorCode !== null) {
61
+ throw new Error(`Invalid coding input: ${errorCode}`);
62
+ }
63
+ ```
64
+
65
+ ## Validate a grounded coding output
66
+
67
+ Output validation can enforce both the structural contract and evidence
68
+ grounding. Pass the approved reference IDs and the corresponding evidence text
69
+ when validating recommendations:
70
+
71
+ ```ts
72
+ import { rcmCodingOutputValidationError } from "@nexalink/coding-contracts";
73
+
74
+ const candidate: unknown = {
75
+ disposition: "review_required",
76
+ humanReviewRequired: true,
77
+ recommendations: [
78
+ {
79
+ code: "99236",
80
+ codeSystem: "CPT",
81
+ confidence: "medium",
82
+ rationale: "Synthetic example for qualified coder review.",
83
+ evidenceIds: ["reference-1"],
84
+ },
85
+ ],
86
+ documentationGaps: [],
87
+ rationale: "Synthetic grounded recommendation requiring human review.",
88
+ };
89
+
90
+ const errorCode = rcmCodingOutputValidationError(candidate, {
91
+ allowedReferenceIds: new Set(["reference-1"]),
92
+ referenceTextById: {
93
+ "reference-1": "Synthetic policy excerpt supporting CPT 99236.",
94
+ },
95
+ });
96
+
97
+ if (errorCode !== null) {
98
+ // Fail closed: do not present or act on an invalid recommendation.
99
+ throw new Error(`Invalid coding output: ${errorCode}`);
100
+ }
101
+ ```
102
+
103
+ When grounding options are supplied, each recommendation must cite an approved
104
+ reference and its code must appear in at least one cited evidence text. Use both
105
+ options at trust boundaries. Calling the Zod schema or boolean helper alone
106
+ validates the structural and semantic contract, but not the caller-specific
107
+ approved evidence set.
108
+
109
+ ## Main exports
110
+
111
+ | Category | Exports |
112
+ | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
113
+ | Types | `RcmCodingInput`, `RcmCodingOutput`, `RcmSupportingReference`, `RcmModelPrompt`, `RcmRetrievalMetadata`, `RcmRuntimeEvent`, `RcmWorkflowCatalog` |
114
+ | Case models | `CodingCase`, `CodingCaseContext`, `CodingCasePayer`, `CodingCaseClinical`, `CodingServiceLine`, `CodingExtension`, `CodingBatch` |
115
+ | Decision models | `CodingDecision`, `CodingDecisionLine`, `CodingEvidence`, `CodingRuleResult`, `CodingReviewerAction` |
116
+ | Zod schemas | `rcmCodingInputSchema`, `rcmCodingOutputSchema`, `codingCaseSchema`, `codingDecisionSchema`, and one schema for each additional contract type |
117
+ | Validation | `rcm*ValidationError` functions, `coding*ValidationError` functions, and `valid*` boolean helpers |
118
+ | Workflow policy | `RCM_WORKFLOW_ID`, `RCM_MODEL_POLICY_ID`, `RCM_HUMAN_REVIEW_POLICY_ID`, `RCM_HUMAN_REVIEW_INSTRUCTION`, `RCM_OUTPUT_SCHEMA_NAME` |
119
+ | Schema versions | `RCM_INPUT_SCHEMA_VERSION`, `RCM_OUTPUT_SCHEMA_VERSION`, `RCM_REFERENCE_SCHEMA_VERSION`, `CODING_CASE_SCHEMA_VERSION`, `CODING_DECISION_SCHEMA_VERSION`, and the other contract wire-version constants |
120
+ | Schema documents | `Rcm*SchemaJson`, `Coding*SchemaJson` values, JSON Schema package subpaths, `versions.json`, and `workflow-constants.json` |
121
+
122
+ ## Canonical CodingCase and CodingDecision
123
+
124
+ `CodingCase` is the canonical case envelope for encounter review, claim review,
125
+ longitudinal review, monthly multi-activity time aggregation, and bounded batch
126
+ review. `CodingDecision` is the corresponding reconstructable decision.
127
+
128
+ - **CodingCase** carries case identity (`caseId` is client-supplied and may be
129
+ a direct reference; `analyticsId` is the separate analytics-safe identifier),
130
+ coding intent, the service period, setting/jurisdiction/provider context,
131
+ payer/plan/program/contract context, structured clinical facts (diagnoses,
132
+ procedures, medications, supplies, `timeUnits` with `durationMinutes` and
133
+ `activityCode`, notes, source references), existing claim lines, and
134
+ namespaced `extensions`.
135
+ - **CodingDecision** references the case by the analytics-safe `caseRef` only,
136
+ proposes claim-line actions (`add`, `retain`, `replace`, `remove`, `review`)
137
+ with code identity, modifiers, units, linked diagnoses, and sequencing, and
138
+ records typed evidence, documentation gaps, conflicts, extracted facts, rule
139
+ traces, confidence, and the qualified-human-review disposition.
140
+ - **Provenance** (`decisionSchemaVersion`, `caseSchemaVersion`, pack, model,
141
+ terminology editions with license status, rule versions, retrieval corpus,
142
+ and generation time) lets every recommendation be reconstructed.
143
+ - **ReviewerAction** is appended immutably: the original decision and the
144
+ attributable reviewer disposition are both preserved.
145
+ - **Extensions** are `{ namespace, schemaVersion, payload }` objects. Payloads
146
+ are bounded (at most 50 properties) but otherwise opaque; Nexalink reserves
147
+ `com.nexalink` and `org.nexalink` namespaces. Extensions keep pack-specific
148
+ data out of the shared envelope without making every field optional.
149
+ - **Identifiers**: direct identifiers (`caseId`, provider NPIs/names, `memberId`)
150
+ are documented as such in the schemas and must never be promoted to analytics
151
+ surfaces. Decisions and metrics reference the analytics-safe `analyticsId` /
152
+ `caseRef` only.
153
+ - **Batching**: `CodingBatch` wraps 1–100 cases for bounded batch review; one
154
+ execution stays within runtime limits.
155
+
156
+ The current RCM example (`DEMO-ENC-1042`) and a monthly multi-activity
157
+ time-aggregation workflow both have lossless, round-trip fixtures under
158
+ `fixtures/coding-case/` and `fixtures/coding-decision/`.
159
+
160
+ ## Use the raw JSON Schemas
161
+
162
+ The schemas are available as package subpaths. For example, in CommonJS:
163
+
164
+ ```js
165
+ const inputSchema = require("@nexalink/coding-contracts/schemas/rcm-coding-input.schema");
166
+ const versions = require("@nexalink/coding-contracts/versions.json");
167
+ ```
168
+
169
+ The same documents are also exported as JavaScript values from the package
170
+ root, such as `RcmCodingInputSchemaJson`.
171
+
172
+ ## Versioning
173
+
174
+ Package versions and wire-schema versions serve different purposes:
175
+
176
+ - The npm package follows semantic versioning. Consumers should pin an exact
177
+ version and evaluate contract changes before upgrading.
178
+ - Each schema also has a wire-version constant used in requests, results, and
179
+ runtime events. A package release can update implementation details without
180
+ changing every wire version.
181
+ - Additive contract changes may ship in a minor package release. Breaking
182
+ contract changes require a major package release and a new wire version.
183
+
184
+ The complete package-to-schema mapping is available from
185
+ `@nexalink/coding-contracts/versions.json`.
186
+
187
+ ## Safety and licensing
188
+
189
+ - `humanReviewRequired` is always `true` for coding outputs. Recommendations
190
+ must be reviewed by a qualified human coder before billing, coding, or claim
191
+ submission.
192
+ - Treat validation failures as fail-closed conditions. Do not silently coerce
193
+ invalid input or continue with ungrounded output.
194
+ - Examples in this README are synthetic and must not be interpreted as coding
195
+ guidance.
196
+ - The package does not include licensed terminology descriptions and does not
197
+ grant rights to use licensed code-set content.
198
+
199
+ Use of this package is governed by the included Nexalink Proprietary Software
200
+ License.