@cosyte/x12 0.0.13 → 0.0.15
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/CHANGELOG.md +369 -2
- package/KNOWN-LIMITATIONS.md +325 -8
- package/dist/index.cjs +131 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +277 -25
- package/dist/index.d.ts +277 -25
- package/dist/index.mjs +130 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -138,6 +138,7 @@ var WARNING_CODES = {
|
|
|
138
138
|
X12_UNKNOWN_HI_QUALIFIER: "X12_UNKNOWN_HI_QUALIFIER",
|
|
139
139
|
X12_MISSING_REQUIRED_LOOP: "X12_MISSING_REQUIRED_LOOP",
|
|
140
140
|
X12_837_UNKNOWN_VARIANT: "X12_837_UNKNOWN_VARIANT",
|
|
141
|
+
X12_837_AMBIGUOUS_VARIANT: "X12_837_AMBIGUOUS_VARIANT",
|
|
141
142
|
X12_UNKNOWN_CLAIM_STATUS_CATEGORY: "X12_UNKNOWN_CLAIM_STATUS_CATEGORY",
|
|
142
143
|
X12_UNKNOWN_CLAIM_STATUS: "X12_UNKNOWN_CLAIM_STATUS",
|
|
143
144
|
X12_834_UNKNOWN_MAINTENANCE_TYPE: "X12_834_UNKNOWN_MAINTENANCE_TYPE",
|
|
@@ -145,6 +146,7 @@ var WARNING_CODES = {
|
|
|
145
146
|
X12_837_SERVICE_LINE_NOT_DECODED: "X12_837_SERVICE_LINE_NOT_DECODED",
|
|
146
147
|
X12_837_SERVICE_LINE_DROPPED: "X12_837_SERVICE_LINE_DROPPED",
|
|
147
148
|
X12_837_SERVICE_SEGMENT_WITHOUT_LX: "X12_837_SERVICE_SEGMENT_WITHOUT_LX",
|
|
149
|
+
X12_837_SERVICE_SEGMENT_REPEATED: "X12_837_SERVICE_SEGMENT_REPEATED",
|
|
148
150
|
X12_837_ENTITY_SEGMENT_DISCARDED_AFTER_LX: "X12_837_ENTITY_SEGMENT_DISCARDED_AFTER_LX",
|
|
149
151
|
X12_837_PAY_TO_ADDRESS_REPEATED: "X12_837_PAY_TO_ADDRESS_REPEATED",
|
|
150
152
|
X12_835_BALANCE_NOT_EVALUABLE: "X12_835_BALANCE_NOT_EVALUABLE",
|
|
@@ -222,7 +224,8 @@ var WARNING_MESSAGES = {
|
|
|
222
224
|
X12_MISSING_REQUIRED_LOOP_2000B: 'Missing required loop "2000B" (Subscriber HL): no Subscriber HL precedes the CLM.',
|
|
223
225
|
X12_MISSING_REQUIRED_LOOP_2010BA: 'Missing required loop "2010BA" (Subscriber Name): no Subscriber Name follows the Subscriber HL.',
|
|
224
226
|
X12_MISSING_REQUIRED_LOOP_2010BB: 'Missing required loop "2010BB" (Payer Name): no Payer Name follows the Subscriber HL.',
|
|
225
|
-
X12_837_UNKNOWN_VARIANT:
|
|
227
|
+
X12_837_UNKNOWN_VARIANT: "837 variant could not be resolved: ST-03's implementation convention reference is absent, empty, or not an 837 Technical Report Type 3 identifier this reader recognises, and no SVx service-line segment was present to fall back on. The set of references it recognises covers the professional, institutional and dental 837 guides HIPAA adopts at 45 CFR 162.1102 together with their published errata; it is NOT claimed to be exhaustive, and this message deliberately does not enumerate it, because a list here goes stale the moment a guide is added. A reference outside that set is not asserted to be invalid - all this code reports is that this reader could not turn it into a variant and had nothing to fall back on. The verbatim reference is preserved on the model; read it there rather than inferring what the sender meant.",
|
|
228
|
+
X12_837_AMBIGUOUS_VARIANT: "837 variant resolved from a service segment while the transaction body carries service segments of more than one variant: no caller `type` option was supplied and ST-03's implementation convention reference is absent, empty, or not an 837 Technical Report Type 3 identifier this reader recognises, so this reader fell back to the FIRST SV1 / SV2 / SV3 in the body, and a later one names a different variant. `submission.variant` is therefore a guess between contradictory evidence, and every claim and service line in the submission was read against it. Which service segment is the stray one is NOT decided here and is not derivable from the TR3s: this reader cannot tell a stray service segment from a conformant one, and the fallback takes the first regardless of whether any Loop 2400 was open at it, so an orphan segment decides the variant like any other. Read the bound literally, as a property of the RESOLUTION rather than of the document: this reports the fallback's own ambiguity, so a caller-supplied `type`, or an ST-03 this reader does turn into a variant, means no guess was made and this code is NOT raised however mixed the body is. Whatever else this reader raised on a document that reaches this code, it still raises, at the same position, and this one is added beside them. It is NOT a list of what else you will see, and it does not promise that any particular loss on such a document is reported at all. Re-read with the `type` option to decode the document against a variant you trust. The verbatim segments are preserved on the transaction set; read them there before acting on the submission's type.",
|
|
226
229
|
X12_UNKNOWN_CLAIM_STATUS_CATEGORY: "Unknown claim status category (CSCC): the STC composite's first component is outside the bundled snapshot. The verbatim code is preserved on the status; only its description is unavailable.",
|
|
227
230
|
X12_UNKNOWN_CLAIM_STATUS: "Unknown claim status code (CSC): the STC composite's second component is outside the bundled snapshot. The verbatim code is preserved on the status; only its description is unavailable.",
|
|
228
231
|
X12_834_UNKNOWN_MAINTENANCE_TYPE: "Unknown 834 maintenance type: the INS-03/HD-01 code is outside the bundled snapshot. The verbatim code is preserved on the enrollment and the action is NEVER inferred.",
|
|
@@ -230,6 +233,7 @@ var WARNING_MESSAGES = {
|
|
|
230
233
|
X12_837_SERVICE_LINE_NOT_DECODED: "837 service line with no decoded service segment: the Loop 2400 line opened at `position.segmentIndex` is followed by no SV1 / SV2 / SV3 matching the variant this submission resolved to, so NOTHING carried by the service segment was read. The line's `charge` and `units` are `undefined`, which is what this library puts on a decimal slot it decoded no value into; its procedure code, modifiers, unit of measure and place of service are equally undecoded. Two common causes: the line carries no SVx at all, or it carries one for a different 837 variant than ST-03 (or the caller's `type` option) named. Which side is wrong is NOT decided here, because a caller-supplied `type` can disagree with a perfectly conformant document. The verbatim segments are preserved on the transaction set; read them there before acting on the charge or the quantity.",
|
|
231
234
|
X12_837_SERVICE_LINE_DROPPED: "837 service line dropped from the typed model: the LX at `position.segmentIndex` opened no Loop 2400, so no line appears on any claim's `serviceLines` for it and the SV1 / SV2 / SV3 that followed - its charge, units, procedure code and modifiers - was read into nothing. Compare `X12_837_SERVICE_LINE_NOT_DECODED`, where the line IS on the model and only its service segment went unread. Two causes: no Loop 2300 (CLM) is open at this LX, so there is no claim to attach a line to; or the submission's variant is not one of P / I / D, so no variant-specific line shape could be built. Read `submission.variant` and `submission.claims` to tell them apart; do NOT expect `X12_837_UNKNOWN_VARIANT` alongside this code, because a caller-supplied `type` outside P / I / D reaches the second cause without it. Nothing is fabricated to stand in for the missing line and no claim is synthesized. What becomes of a DTP / AMT / NTE / REF that follows the dropped LX depends on the route and this message does not say; see KNOWN-LIMITATIONS.md. The verbatim segments are preserved on the transaction set; read them there before concluding the claim had no service lines.",
|
|
232
235
|
X12_837_SERVICE_SEGMENT_WITHOUT_LX: "837 service segment with no Loop 2400 to read it into: no service line was open at the SV1 / SV2 / SV3 at `position.segmentIndex`, so NOTHING it carries - its charge, units, procedure code, modifiers, unit of measure and place of service - was read. Read that literally: an LX may well appear earlier in the transaction, and what this reports is that none of them had opened a Loop 2400 still current at this segment. No line appears on any claim's `serviceLines` for it and nothing is fabricated to stand in. Compare the two codes anchored at an LX: `X12_837_SERVICE_LINE_DROPPED`, where an LX IS present and opened no line, and `X12_837_SERVICE_LINE_NOT_DECODED`, where the line is on the model and only its service segment went unread. Neither of those can report the SAME service segment as this code, because both are raised at an LX and this one only where no Loop 2400 is open; a document with several claims can still carry all three. This says NOTHING about how the submission's variant resolved: absent a caller-supplied `type` option, and where ST-03 names no known implementation convention, the reader falls back to the first SV1 / SV2 / SV3 in the transaction, and a segment reported here is eligible for that fallback like any other, so a stray one can decide the variant every line is read against. Read `submission.variant`. The verbatim segments are preserved on the transaction set; read them there before concluding the claim had no service lines.",
|
|
236
|
+
X12_837_SERVICE_SEGMENT_REPEATED: "837 service segment repeated inside one Loop 2400: the SV1 / SV2 / SV3 at `position.segmentIndex` is not the first service segment to arrive in the service line the LX before it opened. This reader's line carries ONE service segment's worth of slots, so it cannot hold both, and this code is the only thing that tells you the document sent more than one. It asserts nothing about what usage the TR3s give the segment; what it reports is that this reader has one set of those slots per line. What the line carries is what the LAST service segment MATCHING the submission's resolved variant wrote onto it, and only that. Such a segment writes every slot its kind writes - the charge, the units and the procedure code among them - so a matching one arriving second leaves NOTHING an earlier matching one wrote, including where the later one's charge or units element is ABSENT: there the line is left with undefined, which is what this library puts on a decimal slot it decoded no value into, over an amount the earlier one stated. A service segment of a kind that does NOT match the resolved variant is read into nothing at all - it overwrites no slot, and what it carries reaches no part of the typed model. Which of them the sender meant is NOT decided here and is not derivable from the TR3s: this reader cannot tell a stray service segment from a conformant one, and picking a winner would be inventing. Nothing is fabricated to stand in, no second line is synthesized - an LX is what opens a line and there is none here - and no earlier value is kept in a second slot. Read the bound literally, as a property of the READ: this reports a second service segment arriving while a Loop 2400 IS open, whether or not it decoded. It is disjoint from `X12_837_SERVICE_SEGMENT_WITHOUT_LX`, which requires that NO Loop 2400 be open where this one requires that one is, so the two can never name the same segment; read that as disjointness and NOT as a promise that a service segment outside an open Loop 2400 is always named by that code, because a service segment FOLLOWING an LX that opened no line at all is named by neither of them, the loss having already been reported at that LX by `X12_837_SERVICE_LINE_DROPPED`. `X12_837_SERVICE_LINE_NOT_DECODED`, anchored at the LX, reports that no service segment matching the variant decoded onto the line at all, so a document can carry both codes on different segments. It fires once per repeat, so three service segments in one Loop 2400 are two warnings, and the count resets with the line: a first service segment under a later LX is a first and never a repeat. It says nothing about how the submission's variant resolved; where the fallback decided that and the body names more than one, `X12_837_AMBIGUOUS_VARIANT` reports it separately. The verbatim segments are preserved on the transaction set; read them there before acting on the charge, the quantity or the procedure code.",
|
|
233
237
|
X12_837_ENTITY_SEGMENT_DISCARDED_AFTER_LX: "837 entity segment read into nothing after a dropped LX: the N3 / N4 / PER / REF at `position.segmentIndex` arrived while no entity loop was open, because an earlier LX in this transaction opened no Loop 2400 (no CLM was open at it) and closed the entity loop that was current there. NOTHING this segment carries reached the model: no party's `address`, `contacts` or `references` was written from it, and no party, claim or line was synthesized to hold it. This is the code that names THAT loss; `X12_837_SERVICE_LINE_DROPPED` is raised at the LX itself and names the SERVICE LINE's loss, never an entity segment, so the two report different things about the same stretch of the document. Read the bound literally, because this code does NOT report every unattached entity segment: it reports one discarded after such an LX and only while nothing since has opened a new loop, so an N3 / N4 / PER / REF that reaches no party by any other route is still silent, and one arriving after a later NM1 is outside this code's scope, whether or not this reader surfaces that segment kind on that party. It reports that the segment reached NO party; it does not claim it would have reached one had the LX been absent, because this reader does not surface every one of these segment kinds on every party (a PER on a patient or a pay-to address, for one). Which party a segment following a stray LX belongs to is not derivable from the TR3s in either direction, so it is discarded rather than attributed: see KNOWN-LIMITATIONS.md. The verbatim segments are preserved on the transaction set; read them there before concluding a party had no address, no secondary identifier or no contact.",
|
|
234
238
|
X12_837_PAY_TO_ADDRESS_REPEATED: "837 pay-to address named more than once in one Loop 2000A: the NM1*87 at `position.segmentIndex` is not the first in this Loop 2000A, and the TR3s allow Loop 2010AB at most once there. The model has ONE pay-to address slot, so it cannot carry both, and this code is the only thing that tells you the document named more than one. The reader NEVER merges them: an N3 or N4 after this segment can no longer add a street line to, or fill a blank in, the address an earlier NM1*87 named, which is what this library did through 0.0.12 - it returned a fused address no sender sent, silently. What the slot carries instead is the LAST occurrence that stated an address of its own; an occurrence that states none - one carrying no N3 or N4 at all, or only a valueless N3 or N4 whose elements are empty - does NOT replace one that did, so nothing an earlier occurrence stated is blanked either. Where no occurrence states an address, the slot holds what the FIRST N3 or N4 to arrive under any of them produced, which may be an address with no elements at all, and which is not necessarily the first occurrence's: an occurrence that carries no N3 or N4 writes nothing, so a later one's valueless N3 is the first write and takes a slot still empty. Read that as the corner it is, and never restate it as the first OCCURRENCE winning. Which occurrence the sender meant is NOT decided here and is not derivable from the TR3s, and the losing occurrence's address is NOT on the model in any form. Read the bound literally: this reports repetition within one Loop 2000A, which is where the pay-to route lives, and an NM1*87 arriving while a CLM is open never reaches that route. The verbatim segments are preserved on the transaction set; read them there before acting on where a payment is to be sent.",
|
|
235
239
|
X12_AMOUNT_ROW_DROPPED: "Amount row dropped from the typed model: the AMT or ADX at `position.segmentIndex` carried no decodable amount (AMT-02, ADX-01), so NO row was built for it and the rest of the segment went with it - its qualifier or adjustment reason code, and any reference qualifier and id. Nothing is fabricated to stand in: a row is not built around a zero this library did not read, which is why the loss is reported rather than papered over. Two routes reach it and this code does not say which: the amount element was ABSENT, or it was present and held bytes that do not decode as a decimal. On this segment only the second route also raises `X12_UNPARSEABLE_DECIMAL`, carrying the failing element in its own `position.elementIndex`, so whether one is present at this `position.segmentIndex` is what separates them - and that code is unchanged by this one, which is raised alongside it rather than in place of it. Read the bound literally: this reports a row whose AMOUNT was read and decoded no value, and it is NOT a general report that an amount segment reached no model. A segment a reader discards before reading its amount is not on this channel, and neither is one whose amount decoded and then found no claim, service line, coverage or remittance open to attach the row to. An 820 RMR is not on it either, for its own reason: that row is dropped on open-item IDENTITY, RMR-01 and RMR-02 both empty, before the amount is read at all, so an RMR that states an open item and no amount keeps its row with amountPaid undefined while one that states an amount and no open item is dropped whole. That second case is a separate loss, and so is an 837 AMT that decoded while a Loop 2430 adjudication was open; `X12_STATED_AMOUNT_DISCARDED` reports both, and this code reports neither. The two can never name the same segment, because this one requires an amount element that decoded no value and that one requires the opposite. The verbatim segments are preserved on the transaction set; read them there before concluding the document stated no such amount.",
|
|
@@ -406,6 +410,13 @@ function unknown837Variant(position) {
|
|
|
406
410
|
position
|
|
407
411
|
};
|
|
408
412
|
}
|
|
413
|
+
function ambiguous837Variant(position) {
|
|
414
|
+
return {
|
|
415
|
+
code: WARNING_CODES.X12_837_AMBIGUOUS_VARIANT,
|
|
416
|
+
message: WARNING_MESSAGES.X12_837_AMBIGUOUS_VARIANT,
|
|
417
|
+
position
|
|
418
|
+
};
|
|
419
|
+
}
|
|
409
420
|
function serviceLineNotDecoded(position) {
|
|
410
421
|
return {
|
|
411
422
|
code: WARNING_CODES.X12_837_SERVICE_LINE_NOT_DECODED,
|
|
@@ -427,6 +438,13 @@ function serviceSegmentWithoutLx(position) {
|
|
|
427
438
|
position
|
|
428
439
|
};
|
|
429
440
|
}
|
|
441
|
+
function serviceSegmentRepeated(position) {
|
|
442
|
+
return {
|
|
443
|
+
code: WARNING_CODES.X12_837_SERVICE_SEGMENT_REPEATED,
|
|
444
|
+
message: WARNING_MESSAGES.X12_837_SERVICE_SEGMENT_REPEATED,
|
|
445
|
+
position
|
|
446
|
+
};
|
|
447
|
+
}
|
|
430
448
|
function entitySegmentDiscardedAfterLx(position) {
|
|
431
449
|
return {
|
|
432
450
|
code: WARNING_CODES.X12_837_ENTITY_SEGMENT_DISCARDED_AFTER_LX,
|
|
@@ -1079,7 +1097,10 @@ function splitSegments(text, start, delimiters) {
|
|
|
1079
1097
|
return { segments, endIndex: lastEnd };
|
|
1080
1098
|
}
|
|
1081
1099
|
function splitElements(segment, delimiters) {
|
|
1082
|
-
|
|
1100
|
+
if (delimiters.element === RELEASE_CHAR) {
|
|
1101
|
+
return Object.freeze(segment.split(delimiters.element));
|
|
1102
|
+
}
|
|
1103
|
+
return Object.freeze(splitWithRelease(segment, delimiters.element));
|
|
1083
1104
|
}
|
|
1084
1105
|
function el(elements, index) {
|
|
1085
1106
|
return elements[index] ?? "";
|
|
@@ -3323,9 +3344,20 @@ function statesAnAddress(address) {
|
|
|
3323
3344
|
|
|
3324
3345
|
// src/transactions/claim/get-837.ts
|
|
3325
3346
|
var VARIANT_BY_ICR = wireLookup({
|
|
3347
|
+
// Health Care Claim: Professional (837).
|
|
3348
|
+
"005010X222": "P",
|
|
3349
|
+
"005010X222A1": "P",
|
|
3326
3350
|
"005010X222A2": "P",
|
|
3351
|
+
// Health Care Claim: Institutional (837).
|
|
3352
|
+
"005010X223": "I",
|
|
3353
|
+
"005010X223A1": "I",
|
|
3354
|
+
"005010X223A2": "I",
|
|
3327
3355
|
"005010X223A3": "I",
|
|
3328
|
-
|
|
3356
|
+
// Health Care Claim: Dental (837).
|
|
3357
|
+
"005010X224": "D",
|
|
3358
|
+
"005010X224A1": "D",
|
|
3359
|
+
"005010X224A2": "D",
|
|
3360
|
+
"005010X224A3": "D"
|
|
3329
3361
|
});
|
|
3330
3362
|
var VARIANT_BY_SV_SEGMENT = wireLookup({
|
|
3331
3363
|
SV1: "P",
|
|
@@ -3361,16 +3393,24 @@ function get837Claims(delimiters, tx, opts) {
|
|
|
3361
3393
|
const explicitType = opts?.type;
|
|
3362
3394
|
const variantFromIcr = implementationConventionReference !== void 0 && implementationConventionReference !== "" ? VARIANT_BY_ICR[implementationConventionReference] : void 0;
|
|
3363
3395
|
let variantFromSegment;
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3396
|
+
let serviceSegmentVariantsConflict = false;
|
|
3397
|
+
if (explicitType === void 0 && variantFromIcr === void 0) {
|
|
3398
|
+
for (const seg of body) {
|
|
3399
|
+
const fromSv = VARIANT_BY_SV_SEGMENT[seg.id];
|
|
3400
|
+
if (fromSv === void 0) continue;
|
|
3401
|
+
if (variantFromSegment === void 0) {
|
|
3402
|
+
variantFromSegment = fromSv;
|
|
3403
|
+
} else if (fromSv !== variantFromSegment) {
|
|
3404
|
+
serviceSegmentVariantsConflict = true;
|
|
3405
|
+
break;
|
|
3406
|
+
}
|
|
3369
3407
|
}
|
|
3370
3408
|
}
|
|
3371
3409
|
const variant = explicitType ?? variantFromIcr ?? variantFromSegment ?? "unknown";
|
|
3372
3410
|
if (variant === "unknown") {
|
|
3373
3411
|
warnings.push(unknown837Variant({ segmentIndex: 0, transactionIndex: 0 }));
|
|
3412
|
+
} else if (serviceSegmentVariantsConflict) {
|
|
3413
|
+
warnings.push(ambiguous837Variant({ segmentIndex: 0, transactionIndex: 0 }));
|
|
3374
3414
|
}
|
|
3375
3415
|
const hierarchies = [];
|
|
3376
3416
|
const hlIndex = /* @__PURE__ */ new Map();
|
|
@@ -3419,6 +3459,10 @@ function get837Claims(delimiters, tx, opts) {
|
|
|
3419
3459
|
if (droppedLineReported) return;
|
|
3420
3460
|
warnings.push(serviceSegmentWithoutLx(position));
|
|
3421
3461
|
};
|
|
3462
|
+
const noteServiceSegment = (acc, position) => {
|
|
3463
|
+
if (acc.serviceSegmentSeen) warnings.push(serviceSegmentRepeated(position));
|
|
3464
|
+
acc.serviceSegmentSeen = true;
|
|
3465
|
+
};
|
|
3422
3466
|
const reportDiscardedEntitySegment = (position) => {
|
|
3423
3467
|
if (!entityLoopClosedByStrayLx) return;
|
|
3424
3468
|
warnings.push(entitySegmentDiscardedAfterLx(position));
|
|
@@ -3761,19 +3805,41 @@ function get837Claims(delimiters, tx, opts) {
|
|
|
3761
3805
|
// before the walk and scans every SVx in the body: an orphan segment
|
|
3762
3806
|
// is eligible for that fallback like any other, which is pre-existing
|
|
3763
3807
|
// and disclosed in KNOWN-LIMITATIONS.md rather than changed here.
|
|
3808
|
+
//
|
|
3809
|
+
// A SECOND service segment inside an already-open Loop 2400 is the
|
|
3810
|
+
// other silence on this segment, and it is a worse one: the line IS
|
|
3811
|
+
// open, so the repeat decodes, and every decoder writes all of the
|
|
3812
|
+
// slots its kind writes. `SV1*HC:99213*8500*…` followed by
|
|
3813
|
+
// `SV1*HC:99999*12*…` left ONE line reading `charge` 12 and
|
|
3814
|
+
// `procedureCode` 99999 through `0.0.13`, with `warnings: []` - money
|
|
3815
|
+
// and a CPT code replaced on the model, on no channel at all.
|
|
3816
|
+
// `noteServiceSegment` reports that, at the repeat itself, and changes
|
|
3817
|
+
// NOTHING about which segment wins.
|
|
3764
3818
|
case "SV1": {
|
|
3765
|
-
if (currentServiceLine
|
|
3766
|
-
|
|
3819
|
+
if (currentServiceLine === void 0) {
|
|
3820
|
+
reportOrphanServiceSegment(position);
|
|
3821
|
+
break;
|
|
3822
|
+
}
|
|
3823
|
+
noteServiceSegment(currentServiceLine, position);
|
|
3824
|
+
decodeSv1(currentServiceLine, seg, delimiters, sink);
|
|
3767
3825
|
break;
|
|
3768
3826
|
}
|
|
3769
3827
|
case "SV2": {
|
|
3770
|
-
if (currentServiceLine
|
|
3771
|
-
|
|
3828
|
+
if (currentServiceLine === void 0) {
|
|
3829
|
+
reportOrphanServiceSegment(position);
|
|
3830
|
+
break;
|
|
3831
|
+
}
|
|
3832
|
+
noteServiceSegment(currentServiceLine, position);
|
|
3833
|
+
decodeSv2(currentServiceLine, seg, delimiters, sink);
|
|
3772
3834
|
break;
|
|
3773
3835
|
}
|
|
3774
3836
|
case "SV3": {
|
|
3775
|
-
if (currentServiceLine
|
|
3776
|
-
|
|
3837
|
+
if (currentServiceLine === void 0) {
|
|
3838
|
+
reportOrphanServiceSegment(position);
|
|
3839
|
+
break;
|
|
3840
|
+
}
|
|
3841
|
+
noteServiceSegment(currentServiceLine, position);
|
|
3842
|
+
decodeSv3(currentServiceLine, seg, delimiters, sink);
|
|
3777
3843
|
break;
|
|
3778
3844
|
}
|
|
3779
3845
|
case "TOO": {
|
|
@@ -4080,6 +4146,7 @@ function openServiceLine2(seg, delimiters, variant, position) {
|
|
|
4080
4146
|
lineNumber,
|
|
4081
4147
|
position,
|
|
4082
4148
|
serviceSegmentDecoded: false,
|
|
4149
|
+
serviceSegmentSeen: false,
|
|
4083
4150
|
charge: void 0,
|
|
4084
4151
|
units: void 0,
|
|
4085
4152
|
unitOfMeasure: void 0,
|
|
@@ -4505,6 +4572,29 @@ var VERSION_BY_VARIANT = {
|
|
|
4505
4572
|
I: "005010X223A3",
|
|
4506
4573
|
D: "005010X224A2"
|
|
4507
4574
|
};
|
|
4575
|
+
function resolveVersionRelease(variant, reference, esc) {
|
|
4576
|
+
if (reference === void 0) return VERSION_BY_VARIANT[variant];
|
|
4577
|
+
if (reference === "") {
|
|
4578
|
+
throw new Claim837BuildError(
|
|
4579
|
+
CLAIM_837_BUILD_ERROR_CODES.X12_837_BUILD_INVALID_SPEC,
|
|
4580
|
+
"build837: envelope.implementationConventionReference is empty. ST-03 and GS-08 are required elements and a trailing empty element is not emitted, so an empty reference would remove them rather than send them empty. Omit the field to take the builder's default."
|
|
4581
|
+
);
|
|
4582
|
+
}
|
|
4583
|
+
if (esc(reference) !== reference) {
|
|
4584
|
+
throw new Claim837BuildError(
|
|
4585
|
+
CLAIM_837_BUILD_ERROR_CODES.X12_837_BUILD_INVALID_SPEC,
|
|
4586
|
+
"build837: envelope.implementationConventionReference carries an active delimiter or the release character. Escaping does not make it safe here: the ST and GS segments are read by a splitter that is not release-aware, so a released delimiter still splits the segment and the declaration silently becomes two elements. State a reference that carries neither, or choose different delimiters."
|
|
4587
|
+
);
|
|
4588
|
+
}
|
|
4589
|
+
const named = Object.hasOwn(VARIANT_BY_ICR, reference) ? VARIANT_BY_ICR[reference] : void 0;
|
|
4590
|
+
if (named !== void 0 && named !== variant) {
|
|
4591
|
+
throw new Claim837BuildError(
|
|
4592
|
+
CLAIM_837_BUILD_ERROR_CODES.X12_837_BUILD_INVALID_SPEC,
|
|
4593
|
+
`build837: envelope.implementationConventionReference names an implementation guide this library reads as a DIFFERENT 837 variant, but this is build837${variant}. The emitted file would declare one variant and carry another's service segments, and this library's own reader would then decode none of its service lines. State a reference for the ${variant} 837, or build with the entry point that matches the reference.`
|
|
4594
|
+
);
|
|
4595
|
+
}
|
|
4596
|
+
return reference;
|
|
4597
|
+
}
|
|
4508
4598
|
var X12_837_FUNCTIONAL_ID = "HC";
|
|
4509
4599
|
var X12_AGENCY_CODE2 = "X";
|
|
4510
4600
|
var HL_LEVEL = { BILLING: "20", SUBSCRIBER: "22", PATIENT: "23" };
|
|
@@ -4519,7 +4609,6 @@ function build837D(spec) {
|
|
|
4519
4609
|
}
|
|
4520
4610
|
function buildClaim837(variant, spec) {
|
|
4521
4611
|
const { envelope } = spec;
|
|
4522
|
-
const versionRelease = VERSION_BY_VARIANT[variant];
|
|
4523
4612
|
enforceStructuralSpec2(variant, spec);
|
|
4524
4613
|
const elementSeparator = envelope.elementSeparator ?? "*";
|
|
4525
4614
|
const repetitionSeparator = envelope.repetitionSeparator ?? "^";
|
|
@@ -4545,6 +4634,11 @@ function buildClaim837(variant, spec) {
|
|
|
4545
4634
|
return escaped.slice(0, end).join(componentSeparator);
|
|
4546
4635
|
};
|
|
4547
4636
|
const ctx = { seg, esc, comp };
|
|
4637
|
+
const versionRelease = resolveVersionRelease(
|
|
4638
|
+
variant,
|
|
4639
|
+
envelope.implementationConventionReference,
|
|
4640
|
+
esc
|
|
4641
|
+
);
|
|
4548
4642
|
const senderQualifier = envelope.senderQualifier ?? "ZZ";
|
|
4549
4643
|
const receiverQualifier = envelope.receiverQualifier ?? "ZZ";
|
|
4550
4644
|
const usageIndicator = envelope.usageIndicator ?? "P";
|
|
@@ -9669,18 +9763,27 @@ function expandYY8(yymmdd) {
|
|
|
9669
9763
|
// src/transactions/ack/build-ta1.ts
|
|
9670
9764
|
function buildTA1(spec, options = {}) {
|
|
9671
9765
|
enforceAcceptIsClean2(spec);
|
|
9672
|
-
const
|
|
9766
|
+
const delimiters = {
|
|
9767
|
+
element: options.elementSeparator ?? "*",
|
|
9768
|
+
repetition: options.repetitionSeparator ?? "^",
|
|
9769
|
+
component: options.componentSeparator ?? ":",
|
|
9770
|
+
segment: options.segmentTerminator ?? "~"
|
|
9771
|
+
};
|
|
9772
|
+
const esc = makeCallerEscaper(delimiters, "buildTA1", refuseSpec9);
|
|
9673
9773
|
const elements = Object.freeze([
|
|
9674
9774
|
"TA1",
|
|
9675
|
-
spec.interchangeControlNumber,
|
|
9676
|
-
spec.interchangeDate,
|
|
9677
|
-
spec.interchangeTime,
|
|
9678
|
-
spec.ackCode,
|
|
9679
|
-
spec.noteCode
|
|
9775
|
+
esc(spec.interchangeControlNumber),
|
|
9776
|
+
esc(spec.interchangeDate),
|
|
9777
|
+
esc(spec.interchangeTime),
|
|
9778
|
+
esc(spec.ackCode),
|
|
9779
|
+
esc(spec.noteCode)
|
|
9680
9780
|
]);
|
|
9681
|
-
const raw = elements.join(
|
|
9781
|
+
const raw = elements.join(delimiters.element);
|
|
9682
9782
|
return Object.freeze({ raw, elements });
|
|
9683
9783
|
}
|
|
9784
|
+
function refuseSpec9(message) {
|
|
9785
|
+
throw new AckBuildError(ACK_BUILD_ERROR_CODES.X12_ACK_INVALID_SPEC, message);
|
|
9786
|
+
}
|
|
9684
9787
|
function enforceAcceptIsClean2(spec) {
|
|
9685
9788
|
if (spec.ackCode === TA1_ACK_CODES.A && spec.noteCode !== "000") {
|
|
9686
9789
|
throw new AckBuildError(
|
|
@@ -9869,7 +9972,7 @@ var X12BuildError = class extends Error {
|
|
|
9869
9972
|
};
|
|
9870
9973
|
|
|
9871
9974
|
// src/builder/build-interchange.ts
|
|
9872
|
-
function
|
|
9975
|
+
function refuseSpec10(message) {
|
|
9873
9976
|
throw new X12BuildError(X12_BUILD_ERROR_CODES.X12_BUILD_INVALID_SPEC, message);
|
|
9874
9977
|
}
|
|
9875
9978
|
function buildInterchange(spec) {
|
|
@@ -9883,7 +9986,7 @@ function buildInterchange(spec) {
|
|
|
9883
9986
|
component: componentSeparator,
|
|
9884
9987
|
segment: segmentTerminator
|
|
9885
9988
|
};
|
|
9886
|
-
const esc = makeCallerEscaper(delimiters, "buildInterchange",
|
|
9989
|
+
const esc = makeCallerEscaper(delimiters, "buildInterchange", refuseSpec10);
|
|
9887
9990
|
const senderQualifier = spec.senderQualifier ?? "ZZ";
|
|
9888
9991
|
const receiverQualifier = spec.receiverQualifier ?? "ZZ";
|
|
9889
9992
|
const usageIndicator = spec.usageIndicator ?? "P";
|
|
@@ -9997,7 +10100,7 @@ function buildTransaction(tx, esc, elementSeparator, segmentTerminator) {
|
|
|
9997
10100
|
return st + bodySegments + se;
|
|
9998
10101
|
}
|
|
9999
10102
|
function joinSeg2(parts, elementSeparator, segmentTerminator) {
|
|
10000
|
-
requireCallerSegment(parts, "buildInterchange",
|
|
10103
|
+
requireCallerSegment(parts, "buildInterchange", refuseSpec10);
|
|
10001
10104
|
return parts.join(elementSeparator) + segmentTerminator;
|
|
10002
10105
|
}
|
|
10003
10106
|
function pad9(value, width) {
|
|
@@ -10306,7 +10409,7 @@ var profiles = Object.freeze({
|
|
|
10306
10409
|
});
|
|
10307
10410
|
|
|
10308
10411
|
// src/index.ts
|
|
10309
|
-
var VERSION = "0.0.
|
|
10412
|
+
var VERSION = "0.0.15";
|
|
10310
10413
|
|
|
10311
10414
|
exports.ACK_BUILD_ERROR_CODES = ACK_BUILD_ERROR_CODES;
|
|
10312
10415
|
exports.ALL_WARNING_MESSAGES = ALL_WARNING_MESSAGES;
|
|
@@ -10414,6 +10517,7 @@ exports.X12ParseError = X12ParseError;
|
|
|
10414
10517
|
exports.X12ProfileError = X12ProfileError;
|
|
10415
10518
|
exports.X12_ACK_DISPOSITION_CODES = X12_ACK_DISPOSITION_CODES;
|
|
10416
10519
|
exports.X12_BUILD_ERROR_CODES = X12_BUILD_ERROR_CODES;
|
|
10520
|
+
exports.ambiguous837Variant = ambiguous837Variant;
|
|
10417
10521
|
exports.amountRowDropped = amountRowDropped;
|
|
10418
10522
|
exports.balanceNotEvaluable = balanceNotEvaluable;
|
|
10419
10523
|
exports.build271 = build271;
|
|
@@ -10493,6 +10597,7 @@ exports.segmentCountMismatch = segmentCountMismatch;
|
|
|
10493
10597
|
exports.serializeX12 = serializeX12;
|
|
10494
10598
|
exports.serviceLineDropped = serviceLineDropped;
|
|
10495
10599
|
exports.serviceLineNotDecoded = serviceLineNotDecoded;
|
|
10600
|
+
exports.serviceSegmentRepeated = serviceSegmentRepeated;
|
|
10496
10601
|
exports.serviceSegmentWithoutLx = serviceSegmentWithoutLx;
|
|
10497
10602
|
exports.setDefaultProfile = setDefaultProfile;
|
|
10498
10603
|
exports.statedAmountDiscarded = statedAmountDiscarded;
|