FHIR Billing Rules API reference
Generated from the TypeScript declarations published in @cognovis/fhir-billing-rules 0.42.4, the version the npm dist-tag latest named at render time. FHIR Billing Rules · All SDKs.
Entry points
@cognovis/fhir-billing-rules
- billingCatalogDefinitionDigest function
- billingCatalogEditionDigest function
- billingCatalogMemberSetDigest function
- billingCatalogSourceSetDigest function
- billingConfiguredRuleMembersDigest function
- buildBillingLibrary function
- decodeBillingLibrary function
- decodeBillingRuleSet function
- BillingCatalogDefinitionCode interface
- BillingCatalogEditionLibraryInput interface
- BillingCatalogEditionMemberLink interface
- BillingLibraryResourceLink interface
- BillingConfiguredRuleLibraryInput interface
- BillingContactDetail interface
- BillingContactPoint interface
- BillingLibraryKind type
- BillingLibraryPeriod interface
- BillingLibraryRelatedArtifact interface
- BillingLibraryResource interface
- BillingRuleSetLibraryInput interface
- BuildBillingLibraryInput type
- DecodedBillingLibrary type
- DecodedBillingRuleSetLibrary type
- billingAdmittedConfiguredRulesDigest function
- billingAdmittedConfiguredRulesUnion function
- decodeBillingAdmission function
- encodeBillingAdmission function
- BillingAdmissionInput interface
- BillingAdmittedConfiguredRulesShard interface
- DecodedBillingAdmission type
- DecodedBillingAdmissionRecord interface
- DecodedBillingAdmittedConfiguredRules interface
- EncodedBillingAdmission interface
- CORE_CANONICAL const
- BILLING_RULE_PAYLOAD_SCHEMA_URI const
- BILLING_RULE_CLASS_SYSTEM const
- BILLING_RULE_REASON_SYSTEM const
- BILLING_RULE_SET_ID_SYSTEM const
- RuleClassDefinition interface
- BILLING_RULE_CLASS_DEFINITIONS const
- BILLING_INTERPRETABLE_UNITS const
- BillingInterpretableUnit type
- compareUnitBearingValues function
- BillingRuleAdmissionReason type
- BillingRuleAdmission type
- BillingInputErrorCause type
- BillingInputError class
- isGenericRuleClass function
- BillingRuleNamedCode interface
- billingRuleNamedCodes function
- BillingFactSourcePathStep type
- parseBillingFactSourcePath function
- billingRuleSetDigest function
- defineBillingRuleSet function
- admitBillingRuleSet function
- canonicalizeJson function
- billingRulePayloadDigest function
- sortRules function
billingCatalogDefinitionDigest function
A catalog definition's content digest: `sha256:<hex>` over the canonical JSON of its `resourceType`, `url`, `version`, `code` and `propertyGroup`, so it changes with every price and nothing outside the definition's content (its id or `meta`) changes it.
function billingCatalogDefinitionDigest(definition: Record<string, unknown>): string;
billingCatalogEditionDigest function
A native catalog edition's member-set digest, scheme 2 (cognovis/fhir-billing-core#165): `sha256:<hex>` over the canonical JSON of `{ scheme: 2, members }`, where `members` lists `[url|version, catalog definition digest or null, configured-rule members digest or null]` per `composed-of` entry, sorted by `url|version`. An admission record binding it binds every definition's prices and every definition's configured rules. A contract-bound edition's digest also covers its manifest's `contracts`, sorted, as `{ scheme: 2, members, contracts }` (cognovis/fhir-billing-core#127), each member with its catalog definition coding or null as a fourth element, so the admission record binds the Contract assignment and which codings the edition holds; an unbound edition's digest is unchanged. A legacy edition keeps the scheme-1 billingCatalogMemberSetDigest.
function billingCatalogEditionDigest(members: readonly BillingCatalogEditionMemberLink[], contracts?: readonly string[]): string;
billingCatalogMemberSetDigest function
function billingCatalogMemberSetDigest(members: readonly string[]): string;
billingCatalogSourceSetDigest function
function billingCatalogSourceSetDigest(sources: readonly BillingCatalogSource[]): string;
billingConfiguredRuleMembersDigest function
The digest of the configured-rule members whose `depends-on` names one catalog definition: `sha256:<hex>` over the canonical JSON of their sorted, unique `url|version` list, as the member-set digest is formed.
function billingConfiguredRuleMembersDigest(members: readonly string[]): string;
buildBillingLibrary function
function buildBillingLibrary(input: BuildBillingLibraryInput): BillingLibraryResource;
decodeBillingLibrary function
function decodeBillingLibrary(input: unknown): DecodedBillingLibrary;
decodeBillingRuleSet function
Strict decoding of a bare rule-set file, as `fhir-billing-check` and other bare-payload consumers read it. The file may name its JSON Schema in a top-level `$schema` string, which is dropped: it is no part of the payload and its digest never covered it. Otherwise it is the payload a rule-set Library carries.
function decodeBillingRuleSet(input: unknown): BillingRuleSet;
BillingCatalogDefinitionCode interface
A catalog definition a declaring edition's configured rules may name: its `canonical|version` and its billed `system|code`.
interface BillingCatalogDefinitionCode {
readonly canonical: string;
readonly system: string;
readonly code: string;
}
BillingCatalogEditionLibraryInput interface
interface BillingCatalogEditionLibraryInput extends BillingLibraryInputBase {
readonly kind: 'catalog-edition';
readonly publisher: string;
readonly payload: BillingCatalogEditionManifestV1;
/**
* The edition's `composed-of` members. A contract-bound edition's Contracts are its manifest `contracts`:
* the builder writes one `depends-on` link per Contract after the members, sorted, and the decoder
* refuses an edition whose `depends-on` links differ from them (cognovis/fhir-billing-core#127).
*/
readonly relatedArtifacts: readonly BillingCatalogEditionMemberLink[];
/**
* Build input only (not decoded), required: every ChargeItemDefinition member of the edition as the
* resource the producer writes, each a member by `url|version` and given once. The builder writes each
* one's {@link billingCatalogDefinitionDigest} on its `composed-of` entry, so the member-set digest an
* admission record binds covers the definitions' prices.
*/
readonly catalogDefinitions?: readonly Record<string, unknown>[];
/**
* The edition's rule completeness declaration (`BILLING_RULE_COMPLETENESS_SYSTEM` identifier):
* `configured-rule-per-code` states that its configured-rule members carry every rule of the edition,
* one Library per rule whose `depends-on` links name the edition's definition of every code the rule
* names; a named code without a definition in the edition needs no link. Outside the manifest, so an
* older SDK still decodes the edition; absent when the edition declares nothing. Building it requires
* `configuredRules` and `definitions`, which with `ruleSet` account for every `composed-of` member.
*/
readonly ruleCompleteness?: BillingRuleCompleteness;
/**
* Build input of a declaring or a contract-bound edition only (not decoded): every configured-rule Library member of the
* edition. The builder refuses the declaration when one is no member, two carry one rule id, a rule of
* a class Core knows names no explicit codes (`billingRuleNamedCodes` is `undefined`: a `"*"` or
* code-less selector), or its `depends-on` links are not exactly the given `definitions` of the codes it
* names (a named code none of them carries needs no link).
* For a class Core does not know, the publisher's `depends-on` links stand as given.
*/
readonly configuredRules?: readonly unknown[];
/**
* Build input of a declaring edition only (not decoded): every catalog definition of the edition, each
* canonical once and each an edition member. A named code counts as absent from the edition only when no
* given definition carries it, so the builder refuses an incomplete inventory: every `composed-of` member
* must be a given definition, a given configured rule or the given `ruleSet`, and any other member is
* refused as a catalog definition missing from `definitions` or an unknown member.
*/
readonly definitions?: readonly BillingCatalogDefinitionCode[];
/**
* Build input of a declaring or a contract-bound edition only (not decoded): the edition's one rule-set Library member, when
* it has one, as `configuredRules` passes its Libraries. The builder decodes it, refuses anything but a
* rule-set Library, and exempts its `url|version`, which must be a member and neither a given definition
* nor a given configured rule. A canonical alone is not accepted, so an omitted catalog definition cannot
* pass as the rule-set member.
*/
readonly ruleSet?: unknown;
}
BillingCatalogEditionMemberLink interface
A catalog edition's `composed-of` member. On an edition that declares per-code rule completeness, `configuredRuleMembersDigest` is the digest (billingConfiguredRuleMembersDigest) of the configured-rule members whose `depends-on` names this member, a catalog definition; it is carried as the `BILLING_CONFIGURED_RULE_MEMBERS_DIGEST_EXTENSION` extension of the entry and is absent for a member without configured rules. `catalogDefinitionDigest` is the content digest (billingCatalogDefinitionDigest) of the member when it is a catalog definition, carried as the `BILLING_CATALOG_DEFINITION_DIGEST_EXTENSION` extension. The edition's member-set digest (billingCatalogEditionDigest) covers both. `buildBillingLibrary` computes them and ignores supplied values.
interface BillingCatalogEditionMemberLink {
readonly type: 'composed-of';
readonly resource: string;
readonly configuredRuleMembersDigest?: string;
readonly catalogDefinitionDigest?: string;
/**
* On a contract-bound edition, the billed coding (`system|code`) of a catalog definition member, carried
* as the `BILLING_CATALOG_DEFINITION_CODING_EXTENSION` extension and covered by the member-set digest;
* absent on every other entry and on an unbound edition. `buildBillingLibrary` writes it.
*/
readonly catalogDefinitionCoding?: string;
}
BillingLibraryResourceLink interface
A related artifact as a Billing Library carries it; only an edition's `composed-of` entry carries an extension.
interface BillingLibraryResourceLink extends BillingLibraryRelatedArtifact {
readonly extension?: readonly {
readonly url: string;
readonly valueString: string;
}[];
}
BillingConfiguredRuleLibraryInput interface
interface BillingConfiguredRuleLibraryInput extends BillingLibraryInputBase {
readonly kind: 'configured-rule';
readonly payload: BillingConfiguredRulePayloadV2;
/**
* At least one `depends-on` link, each a catalog definition `canonical|version`, unique; the Library
* carries them sorted. Under an edition's per-code rule completeness declaration they name the
* edition's definition of every code the rule names in any role ({@link billingRuleNamedCodes}) that
* has one there. The links are
* outside the payload, so they never change the configured-rule digest.
*/
readonly relatedArtifacts: readonly (BillingLibraryRelatedArtifact & {
readonly type: 'depends-on';
})[];
}
BillingContactDetail interface
A FHIR R4 ContactDetail: a name, telecom entries, or both.
interface BillingContactDetail {
readonly name?: string;
readonly telecom?: readonly BillingContactPoint[];
}
BillingContactPoint interface
A FHIR R4 ContactPoint of a rule-set publisher contact; `value` is required.
interface BillingContactPoint {
readonly system?: 'phone' | 'fax' | 'email' | 'pager' | 'url' | 'sms' | 'other';
readonly value: string;
readonly use?: 'home' | 'work' | 'temp' | 'old' | 'mobile';
readonly rank?: number;
}
BillingLibraryKind type
type BillingLibraryKind = 'catalog-edition' | 'configured-rule' | 'rule-set';
BillingLibraryPeriod interface
interface BillingLibraryPeriod {
readonly start: string;
readonly end?: string;
}
BillingLibraryRelatedArtifact interface
interface BillingLibraryRelatedArtifact {
readonly type: 'composed-of' | 'depends-on';
readonly resource: string;
}
BillingLibraryResource interface
interface BillingLibraryResource extends Record<string, unknown> {
readonly resourceType: 'Library';
readonly id: string;
readonly url: string;
readonly version: string;
readonly status: string;
readonly type: {
readonly coding: readonly {
readonly system: typeof LIBRARY_TYPE_SYSTEM;
readonly code: 'asset-collection' | 'logic-library';
}[];
};
readonly identifier: readonly {
readonly system: string;
readonly value: string;
}[];
readonly effectivePeriod?: BillingLibraryPeriod;
readonly publisher?: string;
readonly contact?: readonly BillingContactDetail[];
readonly relatedArtifact?: readonly BillingLibraryResourceLink[];
readonly content: readonly [{
readonly contentType: string;
readonly data: string;
}];
}
BillingRuleSetLibraryInput interface
interface BillingRuleSetLibraryInput extends BillingLibraryInputBase {
readonly kind: 'rule-set';
/** Who maintains the rule set and is responsible for it; required to build a rule-set Library. */
readonly publisher: string;
readonly contact?: readonly BillingContactDetail[];
readonly payload: BillingRuleSet;
/**
* Empty for a rule set that is not bound. A contract rule set carries one `depends-on` link per
* Contract canonical of its payload's `appliesTo.contracts`, an overlay rule set one per catalog-edition
* canonical of `appliesTo.catalogEditions`, and no other link.
*/
readonly relatedArtifacts: readonly (BillingLibraryRelatedArtifact & {
readonly type: 'depends-on';
})[];
}
BuildBillingLibraryInput type
type BuildBillingLibraryInput = BillingCatalogEditionLibraryInput | BillingConfiguredRuleLibraryInput | BillingRuleSetLibraryInput;
DecodedBillingLibrary type
type DecodedBillingLibrary = (BillingCatalogEditionLibraryInput | BillingConfiguredRuleLibraryInput | DecodedBillingRuleSetLibrary) & {
readonly digest: string;
readonly resource: BillingLibraryResource;
};
DecodedBillingRuleSetLibrary type
A decoded rule-set Library. `publisher` and `contact` are present when the Library carries them; a rule-set Library published before 0.17.0 carries neither and still decodes.
type DecodedBillingRuleSetLibrary = Omit<BillingRuleSetLibraryInput, 'publisher'> & {
readonly publisher?: string;
};
billingAdmittedConfiguredRulesDigest function
The configured-rules digest: `sha256:<hex>` over the canonical JSON of the `[[url|version, digest], ...]` list sorted by `url|version`. Record 1 binds it; the SDK recomputes it from record 2.
function billingAdmittedConfiguredRulesDigest(rules: readonly BillingAdmittedConfiguredRule[]): string;
billingAdmittedConfiguredRulesUnion function
The admitted configured rules of an edition: the union of its record-2 shards, given in the order record 1 binds them, each already checked against its bound digest. The shards must be disjoint, sorted and contiguous: the last key of each shard sorts below the first key of the next. Otherwise it throws `BillingInputError` naming the first shard that breaks the order.
function billingAdmittedConfiguredRulesUnion(shards: readonly DecodedBillingAdmittedConfiguredRules[]): ReadonlyMap<string, string>;
decodeBillingAdmission function
The SDK's strict decoder of both records, chosen by profile. A record that is not exactly the contract shape (see encodeBillingAdmission) throws `BillingInputError`; non-Billing-Core extensions and store `meta` fields are left alone.
function decodeBillingAdmission(input: unknown): DecodedBillingAdmission;
encodeBillingAdmission function
The producer's encoder: record 1 (admission) and, when `configuredRules` is given, the record-2 shards (admitted configured rules, entities sorted by `url|version`, at most BILLING_ADMITTED_CONFIGURED_RULES_SHARD_SIZE per shard, ids `<configuredRulesId>-<n>`), each bound into record 1 by reference and its own digest, in shard order. Every input is validated as decodeBillingAdmission reads it; a record it writes always decodes.
function encodeBillingAdmission(input: BillingAdmissionInput): EncodedBillingAdmission;
BillingAdmissionInput interface
What a producer admits for one tenant and one Library: record 1, and the record-2 shards when the edition has configured rules.
interface BillingAdmissionInput {
/** The id of record 1, deterministic per tenant, producer instance and admitted Library. */
readonly id: string;
/**
* The base id of the record-2 shards; required exactly when `configuredRules` is given. Shard `n`
* (1-based, in key order) has the id `<configuredRulesId>-<n>`, which must be a FHIR id (at most 64
* characters).
*/
readonly configuredRulesId?: string;
readonly tenant: string;
/** The id of the admitted Library (catalog edition, or a contract or overlay rule set). */
readonly target: string;
/** `Provenance.recorded`: when the admission was recorded. */
readonly recorded: string;
/** The admitting producer (`agent[0].who`): informational, never trusted for a decision. */
readonly producer: {
readonly reference?: string;
readonly display?: string;
};
/**
* The admitted artifacts: at most one catalog edition (its member-set digest and source-set digest)
* and the rule sets admitted with it (payload digest and, when the Library names one, publisher).
*/
readonly artifacts: readonly BillingAdmittedArtifact[];
/** The edition's configured-rule members with their configured-rule digests; requires a catalog-edition artifact. */
readonly configuredRules?: readonly BillingAdmittedConfiguredRule[];
}
BillingAdmittedConfiguredRulesShard interface
One record-2 shard as record 1 binds it: its reference and its configured-rules digest.
interface BillingAdmittedConfiguredRulesShard {
readonly reference: string;
readonly digest: string;
}
DecodedBillingAdmission type
type DecodedBillingAdmission = DecodedBillingAdmissionRecord | DecodedBillingAdmittedConfiguredRules;
DecodedBillingAdmissionRecord interface
A decoded admission record (record 1).
interface DecodedBillingAdmissionRecord {
readonly kind: 'admission';
readonly id: string;
readonly tenant: string;
/** The id of the admitted Library. */
readonly target: string;
readonly artifacts: readonly BillingAdmittedArtifact[];
/** The record-2 shards record 1 binds, in shard order; absent when it binds none. */
readonly configuredRules?: readonly BillingAdmittedConfiguredRulesShard[];
/** `agent[0].who` as reference or display: the admitting producer, informational only. */
readonly producer: string;
readonly resource: Record<string, unknown>;
}
DecodedBillingAdmittedConfiguredRules interface
A decoded admitted-configured-rules record (one record-2 shard) with its recomputed digest.
interface DecodedBillingAdmittedConfiguredRules {
readonly kind: 'admitted-configured-rules';
readonly id: string;
readonly target: string;
/** Each admitted configured rule `url|version` of the shard with its configured-rule digest, in key order (at least one). */
readonly rules: ReadonlyMap<string, string>;
/** {@link billingAdmittedConfiguredRulesDigest} of the entries, computed by the decoder. */
readonly digest: string;
readonly resource: Record<string, unknown>;
}
EncodedBillingAdmission interface
The Provenance resources of one admission.
interface EncodedBillingAdmission {
/** Record 1. */
readonly admission: Record<string, unknown>;
/**
* The record-2 shards in key order, present exactly when `configuredRules` was given: the sorted
* configured rules in consecutive shards of at most {@link BILLING_ADMITTED_CONFIGURED_RULES_SHARD_SIZE}
* entries (none for no configured rules). Record 1 binds each by reference and digest, in this order.
*/
readonly configuredRules?: readonly Record<string, unknown>[];
}
CORE_CANONICAL const
const CORE_CANONICAL: "https://fhir.cognovis.de/billing-core";
BILLING_RULE_PAYLOAD_SCHEMA_URI const
const BILLING_RULE_PAYLOAD_SCHEMA_URI: "https://fhir.cognovis.de/billing-core/schema/billing-rules/v2";
BILLING_RULE_CLASS_SYSTEM const
const BILLING_RULE_CLASS_SYSTEM: "https://fhir.cognovis.de/billing-core/CodeSystem/billing-rule-class";
BILLING_RULE_REASON_SYSTEM const
const BILLING_RULE_REASON_SYSTEM: "https://fhir.cognovis.de/billing-core/CodeSystem/billing-reason";
BILLING_RULE_SET_ID_SYSTEM const
const BILLING_RULE_SET_ID_SYSTEM: "https://fhir.cognovis.de/billing-core/sid/billing-rule-set";
RuleClassDefinition interface
interface RuleClassDefinition {
readonly requiredParameters: readonly string[];
readonly description: string;
}
BILLING_RULE_CLASS_DEFINITIONS const
const BILLING_RULE_CLASS_DEFINITIONS: Readonly<Record<GenericRuleClass, RuleClassDefinition>>;
BILLING_INTERPRETABLE_UNITS const
const BILLING_INTERPRETABLE_UNITS: {
readonly a: {
readonly dimension: "calendar-month";
readonly factor: 12;
};
readonly mo: {
readonly dimension: "calendar-month";
readonly factor: 1;
};
readonly wk: {
readonly dimension: "elapsed-second";
readonly factor: 604800;
};
readonly d: {
readonly dimension: "elapsed-second";
readonly factor: 86400;
};
readonly h: {
readonly dimension: "elapsed-second";
readonly factor: 3600;
};
readonly min: {
readonly dimension: "elapsed-second";
readonly factor: 60;
};
readonly s: {
readonly dimension: "elapsed-second";
readonly factor: 1;
};
readonly '1': {
readonly dimension: "count";
readonly factor: 1;
};
};
BillingInterpretableUnit type
type BillingInterpretableUnit = keyof typeof BILLING_INTERPRETABLE_UNITS;
compareUnitBearingValues function
function compareUnitBearingValues(left: {
value: number;
unit: string;
}, right: {
value: number;
unit: string;
}): -1 | 0 | 1 | 'uninterpretable';
BillingRuleAdmissionReason type
type BillingRuleAdmissionReason = BillingReason['code'];
BillingRuleAdmission type
type BillingRuleAdmission = {
status: 'admitted';
reasons: readonly [];
} | {
status: 'needs-review';
reasons: readonly BillingReason[];
};
BillingInputErrorCause type
Why a `BillingInputError` was raised, where a caller needs to tell causes apart: a digest that does not match its content or is not a valid digest, a catalog edition still carrying a scheme-1 member-set digest (to re-import and re-admit), an unsupported payload schema version or semantic major, a modifier extension or implicit rules the carrier schema does not support, or a duplicate. Errors without a cause carry no discriminant; the message is diagnostics only and never a contract.
type BillingInputErrorCause = 'digest-mismatch' | 'digest-scheme-v1' | 'digest-invalid' | 'schema-version' | 'semantic-major' | 'modifier-extension' | 'implicit-rules' | 'duplicate';
BillingInputError class
class BillingInputError extends TypeError {
readonly code = "BILLING_INPUT_INVALID";
readonly cause?: BillingInputErrorCause;
constructor(message: string, options?: {
readonly cause?: BillingInputErrorCause;
});
}
isGenericRuleClass function
function isGenericRuleClass(value: string): value is GenericRuleClass;
BillingRuleNamedCode interface
One code a rule names, with the code system when the rule states it.
interface BillingRuleNamedCode {
readonly system?: string;
readonly code: string;
}
billingRuleNamedCodes function
The fee codes a rule names in any role (selector, excluded, required), unique and ordered by system and code. `undefined` when the rule names no explicit codes, so no per-code publication can carry it: a `"*"` or code-less selector, or a class whose code parameters Core does not know (a jurisdiction's own class such as `unsupported-source-rule`), whose publisher has to name the codes itself.
function billingRuleNamedCodes(rule: Pick<BillingRule, 'class' | 'parameters'>): readonly BillingRuleNamedCode[] | undefined;
BillingFactSourcePathStep type
One step of a fact-source path: an element name, an extension by url, or the final coding filter by system.
type BillingFactSourcePathStep = {
readonly kind: 'element';
readonly name: string;
} | {
readonly kind: 'extension';
readonly url: string;
} | {
readonly kind: 'coding';
readonly system: string;
};
parseBillingFactSourcePath function
Parses the restricted path of a fact-source declaration: steps separated by `.`, each an element name (`[a-z][A-Za-z0-9]*`, never `coding`, `extension` or an `Object.prototype` member name), `extension('<url>')` or, as the last step after at least one other, `coding('<system>')`. A quoted argument is non-empty and holds no `'`. Anything else, an empty step, or more than 32 steps is a `BillingInputError`.
function parseBillingFactSourcePath(path: string): readonly BillingFactSourcePathStep[];
billingRuleSetDigest function
function billingRuleSetDigest(ruleSet: Pick<BillingRuleSet, 'rules' | 'factSources' | 'appliesTo'>): string;
defineBillingRuleSet function
function defineBillingRuleSet(input: BillingRuleSet): BillingRuleSet;
admitBillingRuleSet function
function admitBillingRuleSet(admission: AdmissionState, rules: readonly BillingRule[]): BillingRuleAdmission;
canonicalizeJson function
Canonical JSON: object members with a defined value sorted by key (UTF-16 code units), arrays in order with `undefined` as `null`, scalars as `JSON.stringify` writes them; a value JSON cannot carry (`undefined`, a function, a symbol) throws. The output is byte-identical to the implementation before 0.25.0 (an array hole still prints as nothing between its commas), built in one pass without intermediate arrays.
function canonicalizeJson(value: unknown): string;
billingRulePayloadDigest function
function billingRulePayloadDigest(payload: BillingRulePayloadV2): string;
sortRules function
function sortRules(rules: readonly BillingRule[]): BillingRule[];