gdc-common-utils-ts 1.21.0 → 1.23.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.
@@ -25,6 +25,7 @@ export declare const ResourceTypesFhirR4: Readonly<{
25
25
  readonly Flag: "Flag";
26
26
  readonly ImagingStudy: "ImagingStudy";
27
27
  readonly Immunization: "Immunization";
28
+ readonly Invoice: "Invoice";
28
29
  readonly Location: "Location";
29
30
  readonly MedicationStatement: "MedicationStatement";
30
31
  readonly Observation: "Observation";
@@ -59,6 +60,7 @@ export declare const FhirResourceTypes: Readonly<{
59
60
  readonly Flag: "Flag";
60
61
  readonly ImagingStudy: "ImagingStudy";
61
62
  readonly Immunization: "Immunization";
63
+ readonly Invoice: "Invoice";
62
64
  readonly Location: "Location";
63
65
  readonly MedicationStatement: "MedicationStatement";
64
66
  readonly Observation: "Observation";
@@ -25,6 +25,7 @@ export const ResourceTypesFhirR4 = Object.freeze({
25
25
  Flag: 'Flag',
26
26
  ImagingStudy: 'ImagingStudy',
27
27
  Immunization: 'Immunization',
28
+ Invoice: 'Invoice',
28
29
  Location: 'Location',
29
30
  MedicationStatement: 'MedicationStatement',
30
31
  Observation: 'Observation',
@@ -6,6 +6,7 @@ export * from './individual-controller';
6
6
  export * from './professional';
7
7
  export * from './employee';
8
8
  export * from './license';
9
+ export * from './invoice';
9
10
  export * from './related-person';
10
11
  export * from './consent-access';
11
12
  export * from './relationship-access';
@@ -6,6 +6,7 @@ export * from './individual-controller.js';
6
6
  export * from './professional.js';
7
7
  export * from './employee.js';
8
8
  export * from './license.js';
9
+ export * from './invoice.js';
9
10
  export * from './related-person.js';
10
11
  export * from './consent-access.js';
11
12
  export * from './relationship-access.js';
@@ -0,0 +1,37 @@
1
+ export declare const EXAMPLE_INVOICE_PDF_DOCUMENT: Readonly<{
2
+ readonly documentId: "invoice-001-pdf";
3
+ readonly contentType: "application/pdf";
4
+ readonly title: "invoice-001.pdf";
5
+ readonly description: "Human-readable invoice PDF";
6
+ readonly language: "en";
7
+ readonly dataBase64: "JVBERi0xLjQKJUZha2UgaW52b2ljZSBQREYK";
8
+ readonly createdAt: "2026-06-11T10:00:00Z";
9
+ }>;
10
+ export declare const EXAMPLE_INVOICE_JSON_DOCUMENT: Readonly<{
11
+ readonly documentId: "invoice-001-json";
12
+ readonly contentType: "application/json";
13
+ readonly title: "invoice-001.json";
14
+ readonly description: "Structured invoice JSON";
15
+ readonly language: "en";
16
+ readonly dataBase64: "eyJpbnZvaWNlSWQiOiJpbnZvaWNlLTAwMSJ9";
17
+ readonly createdAt: "2026-06-11T10:00:00Z";
18
+ }>;
19
+ export declare const EXAMPLE_INVOICE_BUNDLE: Readonly<Record<string, unknown>>;
20
+ export declare const EXAMPLE_INVOICE_CHARGE_ITEM_ROW_A: Readonly<{
21
+ readonly identifier: "chargeitem-001";
22
+ readonly status: "billable";
23
+ readonly partOf: "invoice-001";
24
+ readonly code: "08412345678903";
25
+ readonly codeText: "Botella de suero salino estéril 500 mL";
26
+ readonly category: "medical-supplies";
27
+ readonly supplierProductCode: "IMP-SAL-500";
28
+ readonly quantity: "3|bottle";
29
+ readonly quantityNumber: "3";
30
+ readonly quantityUnit: "bottle";
31
+ readonly itemsPerUnit: "24";
32
+ readonly itemsQuantity: "500|mL";
33
+ readonly itemsQuantityNumber: "500";
34
+ readonly itemsQuantityUnit: "mL";
35
+ }>;
36
+ export declare const EXAMPLE_INVOICE_FHIR_CLAIMS: Readonly<import("..").InvoiceClaims>;
37
+ export declare const EXAMPLE_INVOICE_CHARGEITEM_FHIR_CLAIMS_ROWS: readonly (import("..").InvoiceClaims & import("..").ChargeItemClaims)[];
@@ -0,0 +1,72 @@
1
+ import { EXAMPLE_INVOICE_CHARGEITEM_CATEGORY, EXAMPLE_INVOICE_CHARGEITEM_CODE_TEXT, EXAMPLE_INVOICE_CHARGEITEM_IDENTIFIER, EXAMPLE_INVOICE_CHARGEITEM_ITEMS_PER_UNIT, EXAMPLE_INVOICE_CHARGEITEM_ITEMS_QUANTITY, EXAMPLE_INVOICE_CHARGEITEM_ITEMS_QUANTITY_NUMBER, EXAMPLE_INVOICE_CHARGEITEM_ITEMS_QUANTITY_UNIT, EXAMPLE_INVOICE_CHARGEITEM_PART_OF, EXAMPLE_INVOICE_CHARGEITEM_PRODUCT_CODE, EXAMPLE_INVOICE_CHARGEITEM_QUANTITY, EXAMPLE_INVOICE_CHARGEITEM_QUANTITY_NUMBER, EXAMPLE_INVOICE_CHARGEITEM_STATUS, EXAMPLE_INVOICE_CHARGEITEM_SUPPLIER_PRODUCT_CODE, EXAMPLE_INVOICE_CHARGEITEM_QUANTITY_UNIT, EXAMPLE_API_ORGANIZATION_DID, EXAMPLE_CONTENT_TYPE_APPLICATION_JSON, EXAMPLE_DOCUMENT_REFERENCE_CONTENT_TYPE_PDF, EXAMPLE_DOCUMENT_REFERENCE_LANGUAGE, EXAMPLE_LICENSE_AMOUNT, EXAMPLE_LICENSE_INVOICE_ID, EXAMPLE_LICENSE_PAYMENT_METHOD_INVOICE, EXAMPLE_LICENSE_PAYMENT_URL, EXAMPLE_LICENSE_CURRENCY, EXAMPLE_SUBJECT_DID, EXAMPLE_INVOICE_DATE, EXAMPLE_VAULT_PRIMARY_DATE_TIME, } from './shared.js';
2
+ import { createInvoiceBundleEditor } from '../utils/invoice-bundle.js';
3
+ export const EXAMPLE_INVOICE_PDF_DOCUMENT = Object.freeze({
4
+ documentId: `${EXAMPLE_LICENSE_INVOICE_ID}-pdf`,
5
+ contentType: EXAMPLE_DOCUMENT_REFERENCE_CONTENT_TYPE_PDF,
6
+ title: `${EXAMPLE_LICENSE_INVOICE_ID}.pdf`,
7
+ description: 'Human-readable invoice PDF',
8
+ language: EXAMPLE_DOCUMENT_REFERENCE_LANGUAGE,
9
+ dataBase64: 'JVBERi0xLjQKJUZha2UgaW52b2ljZSBQREYK',
10
+ createdAt: EXAMPLE_VAULT_PRIMARY_DATE_TIME,
11
+ });
12
+ export const EXAMPLE_INVOICE_JSON_DOCUMENT = Object.freeze({
13
+ documentId: `${EXAMPLE_LICENSE_INVOICE_ID}-json`,
14
+ contentType: EXAMPLE_CONTENT_TYPE_APPLICATION_JSON,
15
+ title: `${EXAMPLE_LICENSE_INVOICE_ID}.json`,
16
+ description: 'Structured invoice JSON',
17
+ language: EXAMPLE_DOCUMENT_REFERENCE_LANGUAGE,
18
+ dataBase64: 'eyJpbnZvaWNlSWQiOiJpbnZvaWNlLTAwMSJ9',
19
+ createdAt: EXAMPLE_VAULT_PRIMARY_DATE_TIME,
20
+ });
21
+ export const EXAMPLE_INVOICE_BUNDLE = Object.freeze(createInvoiceBundleEditor()
22
+ .setInvoiceId(EXAMPLE_LICENSE_INVOICE_ID)
23
+ .setSubjectReference(EXAMPLE_SUBJECT_DID)
24
+ .setIssuerReference(EXAMPLE_API_ORGANIZATION_DID)
25
+ .setRecipientReference(EXAMPLE_SUBJECT_DID)
26
+ .setIssuedAt(EXAMPLE_INVOICE_DATE)
27
+ .setAmount(EXAMPLE_LICENSE_AMOUNT)
28
+ .setCurrency(EXAMPLE_LICENSE_CURRENCY)
29
+ .setPaymentMethod(EXAMPLE_LICENSE_PAYMENT_METHOD_INVOICE)
30
+ .setPaymentUrl(EXAMPLE_LICENSE_PAYMENT_URL)
31
+ .setPdfDocument(EXAMPLE_INVOICE_PDF_DOCUMENT)
32
+ .setStructuredDocument(EXAMPLE_INVOICE_JSON_DOCUMENT)
33
+ .buildBundle());
34
+ export const EXAMPLE_INVOICE_CHARGE_ITEM_ROW_A = Object.freeze({
35
+ identifier: EXAMPLE_INVOICE_CHARGEITEM_IDENTIFIER,
36
+ status: EXAMPLE_INVOICE_CHARGEITEM_STATUS,
37
+ partOf: EXAMPLE_INVOICE_CHARGEITEM_PART_OF,
38
+ code: EXAMPLE_INVOICE_CHARGEITEM_PRODUCT_CODE,
39
+ codeText: EXAMPLE_INVOICE_CHARGEITEM_CODE_TEXT,
40
+ category: EXAMPLE_INVOICE_CHARGEITEM_CATEGORY,
41
+ supplierProductCode: EXAMPLE_INVOICE_CHARGEITEM_SUPPLIER_PRODUCT_CODE,
42
+ quantity: EXAMPLE_INVOICE_CHARGEITEM_QUANTITY,
43
+ quantityNumber: EXAMPLE_INVOICE_CHARGEITEM_QUANTITY_NUMBER,
44
+ quantityUnit: EXAMPLE_INVOICE_CHARGEITEM_QUANTITY_UNIT,
45
+ itemsPerUnit: EXAMPLE_INVOICE_CHARGEITEM_ITEMS_PER_UNIT,
46
+ itemsQuantity: EXAMPLE_INVOICE_CHARGEITEM_ITEMS_QUANTITY,
47
+ itemsQuantityNumber: EXAMPLE_INVOICE_CHARGEITEM_ITEMS_QUANTITY_NUMBER,
48
+ itemsQuantityUnit: EXAMPLE_INVOICE_CHARGEITEM_ITEMS_QUANTITY_UNIT,
49
+ });
50
+ export const EXAMPLE_INVOICE_FHIR_CLAIMS = Object.freeze(createInvoiceBundleEditor()
51
+ .setInvoiceId(EXAMPLE_LICENSE_INVOICE_ID)
52
+ .setSubjectReference(EXAMPLE_SUBJECT_DID)
53
+ .setIssuerReference(EXAMPLE_API_ORGANIZATION_DID)
54
+ .setRecipientReference(EXAMPLE_SUBJECT_DID)
55
+ .setIssuedAt(EXAMPLE_INVOICE_DATE)
56
+ .setAmount(EXAMPLE_LICENSE_AMOUNT)
57
+ .setCurrency(EXAMPLE_LICENSE_CURRENCY)
58
+ .setPaymentMethod(EXAMPLE_LICENSE_PAYMENT_METHOD_INVOICE)
59
+ .setPaymentUrl(EXAMPLE_LICENSE_PAYMENT_URL)
60
+ .buildInvoiceClaims());
61
+ export const EXAMPLE_INVOICE_CHARGEITEM_FHIR_CLAIMS_ROWS = Object.freeze(createInvoiceBundleEditor()
62
+ .setInvoiceId(EXAMPLE_LICENSE_INVOICE_ID)
63
+ .setSubjectReference(EXAMPLE_SUBJECT_DID)
64
+ .setIssuerReference(EXAMPLE_API_ORGANIZATION_DID)
65
+ .setRecipientReference(EXAMPLE_SUBJECT_DID)
66
+ .setIssuedAt(EXAMPLE_INVOICE_DATE)
67
+ .setAmount(EXAMPLE_LICENSE_AMOUNT)
68
+ .setCurrency(EXAMPLE_LICENSE_CURRENCY)
69
+ .setPaymentMethod(EXAMPLE_LICENSE_PAYMENT_METHOD_INVOICE)
70
+ .setPaymentUrl(EXAMPLE_LICENSE_PAYMENT_URL)
71
+ .addChargeItem(EXAMPLE_INVOICE_CHARGE_ITEM_ROW_A)
72
+ .buildChargeItemClaimRows());
@@ -208,6 +208,22 @@ export declare const EXAMPLE_LICENSE_PAYMENT_METHOD_INVOICE: "invoice";
208
208
  export declare const EXAMPLE_LICENSE_CHECKOUT_URL: "https://pay.example/offer-001";
209
209
  export declare const EXAMPLE_LICENSE_PAYMENT_URL: "https://pay.example/invoice-001";
210
210
  export declare const EXAMPLE_LICENSE_INVOICE_ID: "invoice-001";
211
+ export declare const EXAMPLE_INVOICE_DATE: "2026-06-11T10:00:00Z";
212
+ export declare const EXAMPLE_INVOICE_CHARGEITEM_PRODUCT_CODE: "08412345678903";
213
+ export declare const EXAMPLE_INVOICE_CHARGEITEM_PRODUCT_NAME: "Sterile saline bottle 500 mL";
214
+ export declare const EXAMPLE_INVOICE_CHARGEITEM_CATEGORY: "medical-supplies";
215
+ export declare const EXAMPLE_INVOICE_CHARGEITEM_SUPPLIER_PRODUCT_CODE: "IMP-SAL-500";
216
+ export declare const EXAMPLE_INVOICE_CHARGEITEM_IDENTIFIER: "chargeitem-001";
217
+ export declare const EXAMPLE_INVOICE_CHARGEITEM_STATUS: "billable";
218
+ export declare const EXAMPLE_INVOICE_CHARGEITEM_PART_OF: "invoice-001";
219
+ export declare const EXAMPLE_INVOICE_CHARGEITEM_QUANTITY: "3|bottle";
220
+ export declare const EXAMPLE_INVOICE_CHARGEITEM_QUANTITY_NUMBER: "3";
221
+ export declare const EXAMPLE_INVOICE_CHARGEITEM_QUANTITY_UNIT: "bottle";
222
+ export declare const EXAMPLE_INVOICE_CHARGEITEM_CODE_TEXT: "Botella de suero salino est\u00E9ril 500 mL";
223
+ export declare const EXAMPLE_INVOICE_CHARGEITEM_ITEMS_PER_UNIT: "24";
224
+ export declare const EXAMPLE_INVOICE_CHARGEITEM_ITEMS_QUANTITY: "500|mL";
225
+ export declare const EXAMPLE_INVOICE_CHARGEITEM_ITEMS_QUANTITY_NUMBER: "500";
226
+ export declare const EXAMPLE_INVOICE_CHARGEITEM_ITEMS_QUANTITY_UNIT: "mL";
211
227
  export declare const EXAMPLE_LICENSE_PLAN_DEFAULT: "default";
212
228
  export declare const EXAMPLE_LICENSE_RENEWAL_CYCLE_YEARLY: "12m";
213
229
  export declare const EXAMPLE_LICENSE_SUBJECT_ID_ACTIVE: "urn:uuid:employee-controller-active-001";
@@ -221,6 +221,22 @@ export const EXAMPLE_LICENSE_PAYMENT_METHOD_INVOICE = 'invoice';
221
221
  export const EXAMPLE_LICENSE_CHECKOUT_URL = 'https://pay.example/offer-001';
222
222
  export const EXAMPLE_LICENSE_PAYMENT_URL = 'https://pay.example/invoice-001';
223
223
  export const EXAMPLE_LICENSE_INVOICE_ID = 'invoice-001';
224
+ export const EXAMPLE_INVOICE_DATE = '2026-06-11T10:00:00Z';
225
+ export const EXAMPLE_INVOICE_CHARGEITEM_PRODUCT_CODE = '08412345678903';
226
+ export const EXAMPLE_INVOICE_CHARGEITEM_PRODUCT_NAME = 'Sterile saline bottle 500 mL';
227
+ export const EXAMPLE_INVOICE_CHARGEITEM_CATEGORY = 'medical-supplies';
228
+ export const EXAMPLE_INVOICE_CHARGEITEM_SUPPLIER_PRODUCT_CODE = 'IMP-SAL-500';
229
+ export const EXAMPLE_INVOICE_CHARGEITEM_IDENTIFIER = 'chargeitem-001';
230
+ export const EXAMPLE_INVOICE_CHARGEITEM_STATUS = 'billable';
231
+ export const EXAMPLE_INVOICE_CHARGEITEM_PART_OF = EXAMPLE_LICENSE_INVOICE_ID;
232
+ export const EXAMPLE_INVOICE_CHARGEITEM_QUANTITY = '3|bottle';
233
+ export const EXAMPLE_INVOICE_CHARGEITEM_QUANTITY_NUMBER = '3';
234
+ export const EXAMPLE_INVOICE_CHARGEITEM_QUANTITY_UNIT = 'bottle';
235
+ export const EXAMPLE_INVOICE_CHARGEITEM_CODE_TEXT = 'Botella de suero salino estéril 500 mL';
236
+ export const EXAMPLE_INVOICE_CHARGEITEM_ITEMS_PER_UNIT = '24';
237
+ export const EXAMPLE_INVOICE_CHARGEITEM_ITEMS_QUANTITY = '500|mL';
238
+ export const EXAMPLE_INVOICE_CHARGEITEM_ITEMS_QUANTITY_NUMBER = '500';
239
+ export const EXAMPLE_INVOICE_CHARGEITEM_ITEMS_QUANTITY_UNIT = 'mL';
224
240
  export const EXAMPLE_LICENSE_PLAN_DEFAULT = 'default';
225
241
  export const EXAMPLE_LICENSE_RENEWAL_CYCLE_YEARLY = '12m';
226
242
  export const EXAMPLE_LICENSE_SUBJECT_ID_ACTIVE = 'urn:uuid:employee-controller-active-001';
@@ -23,6 +23,10 @@ export type FhirAttachment = {
23
23
  url?: string;
24
24
  title?: string;
25
25
  creation?: string;
26
+ hash?: string;
27
+ };
28
+ export type FhirMeta = {
29
+ claims?: Record<string, unknown>;
26
30
  };
27
31
  export interface FhirCompositionResource {
28
32
  resourceType: 'Composition';
@@ -46,6 +50,7 @@ export interface FhirCompositionResource {
46
50
  export interface FhirDocumentReferenceResource {
47
51
  resourceType: 'DocumentReference';
48
52
  id?: string;
53
+ meta?: FhirMeta;
49
54
  status?: string;
50
55
  identifier?: Array<{
51
56
  system?: string;
@@ -81,9 +86,39 @@ export interface FhirDocumentReferenceResource {
81
86
  format?: FhirCoding;
82
87
  }>;
83
88
  }
89
+ export interface FhirInvoiceResource {
90
+ resourceType: 'Invoice';
91
+ id?: string;
92
+ meta?: FhirMeta;
93
+ status?: string;
94
+ identifier?: Array<{
95
+ system?: string;
96
+ value?: string;
97
+ }>;
98
+ subject?: FhirReference;
99
+ recipient?: FhirReference;
100
+ issuer?: {
101
+ reference?: string;
102
+ display?: string;
103
+ };
104
+ date?: string;
105
+ paymentTerms?: string;
106
+ note?: Array<{
107
+ text?: string;
108
+ }>;
109
+ totalNet?: {
110
+ value?: number;
111
+ currency?: string;
112
+ };
113
+ totalGross?: {
114
+ value?: number;
115
+ currency?: string;
116
+ };
117
+ }
84
118
  export interface FhirCommunicationResource {
85
119
  resourceType: 'Communication';
86
120
  id?: string;
121
+ meta?: FhirMeta;
87
122
  status?: string;
88
123
  category?: FhirCodeableConcept[];
89
124
  subject?: FhirReference;
@@ -22,3 +22,4 @@ export * from './related-person-claims';
22
22
  export * from './coverage-claims';
23
23
  export * from './clinical-impression-claims';
24
24
  export * from './task-claims';
25
+ export * from './invoice-claims';
@@ -24,3 +24,4 @@ export * from './related-person-claims.js';
24
24
  export * from './coverage-claims.js';
25
25
  export * from './clinical-impression-claims.js';
26
26
  export * from './task-claims.js';
27
+ export * from './invoice-claims.js';
@@ -0,0 +1,277 @@
1
+ import type { ClaimSpec } from './types';
2
+ /**
3
+ * Canonical flat claim keys for invoice-level business data.
4
+ *
5
+ * These claims are the claims-first source of truth. FHIR `Invoice` is one
6
+ * downstream projection built from them.
7
+ */
8
+ export declare const InvoiceClaim: {
9
+ /** Stable business invoice identifier. Example: `invoice-001`. */
10
+ readonly Identifier: "Invoice.identifier";
11
+ /** Invoice issue date/time. Example: `2026-06-11T10:00:00Z`. */
12
+ readonly Date: "Invoice.date";
13
+ /** Invoice lifecycle status. Example: `issued`. */
14
+ readonly Status: "Invoice.status";
15
+ /** Subject or tenant context reference. Example: `did:web:api.acme.org:individual:123`. */
16
+ readonly Subject: "Invoice.subject";
17
+ /** Billed recipient reference. Example: `did:web:portal.example.org:billing`. */
18
+ readonly Recipient: "Invoice.recipient";
19
+ /** Invoice issuer reference. Example: `did:web:api.acme.org`. */
20
+ readonly Issuer: "Invoice.issuer";
21
+ /** Human-readable issuer label. Example: `Gateway Host Services`. */
22
+ readonly IssuerDisplay: "Invoice.issuer-display";
23
+ /** Commercial payment method/terms. Example: `invoice`. */
24
+ readonly PaymentTerms: "Invoice.payment-terms";
25
+ /** Payment or settlement URL when available. Example: `https://pay.example/invoice-001`. */
26
+ readonly PaymentUrl: "Invoice.payment-url";
27
+ /** Net amount numeric value serialized as string. Example: `9.99`. */
28
+ readonly TotalNetValue: "Invoice.totalnet-value";
29
+ /** Net amount ISO currency. Example: `EUR`. */
30
+ readonly TotalNetCurrency: "Invoice.totalnet-currency";
31
+ /** Gross amount numeric value serialized as string. Example: `9.99`. */
32
+ readonly TotalGrossValue: "Invoice.totalgross-value";
33
+ /** Gross amount ISO currency. Example: `EUR`. */
34
+ readonly TotalGrossCurrency: "Invoice.totalgross-currency";
35
+ };
36
+ export type InvoiceClaimKey = typeof InvoiceClaim[keyof typeof InvoiceClaim];
37
+ export interface InvoiceClaims {
38
+ [InvoiceClaim.Identifier]?: string;
39
+ [InvoiceClaim.Date]?: string;
40
+ [InvoiceClaim.Status]?: string;
41
+ [InvoiceClaim.Subject]?: string;
42
+ [InvoiceClaim.Recipient]?: string;
43
+ [InvoiceClaim.Issuer]?: string;
44
+ [InvoiceClaim.IssuerDisplay]?: string;
45
+ [InvoiceClaim.PaymentTerms]?: string;
46
+ [InvoiceClaim.PaymentUrl]?: string;
47
+ [InvoiceClaim.TotalNetValue]?: string;
48
+ [InvoiceClaim.TotalNetCurrency]?: string;
49
+ [InvoiceClaim.TotalGrossValue]?: string;
50
+ [InvoiceClaim.TotalGrossCurrency]?: string;
51
+ }
52
+ /**
53
+ * Contextualized FHIR-API-like invoice claims.
54
+ *
55
+ * Convention:
56
+ * - `org.hl7.fhir.api.Invoice.<concrete-parameter>`
57
+ * - scalar/string-friendly values only
58
+ * - invoice totals/payment URL remain extension-style operational claims
59
+ * because not every business field maps to one native FHIR search parameter
60
+ */
61
+ export declare enum InvoiceClaimsFhirApiExtended {
62
+ Identifier = "org.hl7.fhir.api.Invoice.identifier",
63
+ Date = "org.hl7.fhir.api.Invoice.date",
64
+ Status = "org.hl7.fhir.api.Invoice.status",
65
+ Subject = "org.hl7.fhir.api.Invoice.subject",
66
+ Recipient = "org.hl7.fhir.api.Invoice.recipient",
67
+ Issuer = "org.hl7.fhir.api.Invoice.issuer",
68
+ IssuerDisplay = "org.hl7.fhir.api.Invoice.issuer-display",
69
+ PaymentTerms = "org.hl7.fhir.api.Invoice.payment-terms",
70
+ PaymentUrl = "org.hl7.fhir.api.Invoice.payment-url",
71
+ TotalNetValue = "org.hl7.fhir.api.Invoice.totalnet-value",
72
+ TotalNetCurrency = "org.hl7.fhir.api.Invoice.totalnet-currency",
73
+ TotalGrossValue = "org.hl7.fhir.api.Invoice.totalgross-value",
74
+ TotalGrossCurrency = "org.hl7.fhir.api.Invoice.totalgross-currency"
75
+ }
76
+ /**
77
+ * Canonical non-contextualized parameter names for query builders and readers.
78
+ */
79
+ export declare const InvoiceSearchParamNames: {
80
+ readonly Identifier: "identifier";
81
+ readonly Date: "date";
82
+ readonly Status: "status";
83
+ readonly Subject: "subject";
84
+ readonly Recipient: "recipient";
85
+ readonly Issuer: "issuer";
86
+ readonly IssuerDisplay: "issuer-display";
87
+ readonly PaymentTerms: "payment-terms";
88
+ readonly PaymentUrl: "payment-url";
89
+ readonly TotalNetValue: "totalnet-value";
90
+ readonly TotalNetCurrency: "totalnet-currency";
91
+ readonly TotalGrossValue: "totalgross-value";
92
+ readonly TotalGrossCurrency: "totalgross-currency";
93
+ };
94
+ /**
95
+ * Charge-item-level claims used when one business invoice line is represented
96
+ * as one claims row. The future FHIR export can compact multiple rows sharing
97
+ * one invoice identifier into a single `Invoice` with multiple items.
98
+ *
99
+ * Note:
100
+ * - FHIR `Invoice` does not expose all these details as search parameters.
101
+ * - `ChargeItem` is therefore modeled here as claims-first operational data.
102
+ */
103
+ export declare const ChargeItemClaim: {
104
+ /** Stable invoice line identifier. Example: `chargeitem-001`. */
105
+ readonly Identifier: "ChargeItem.identifier";
106
+ /** Charge item lifecycle status from FHIR ChargeItemStatus. Example: `billable`. */
107
+ readonly Status: "ChargeItem.status";
108
+ /** Parent business aggregate identifier. Example: `invoice-001`. */
109
+ readonly PartOf: "ChargeItem.part-of";
110
+ /** Public code such as GTIN/UDI/barcode. Example: `08412345678903`. */
111
+ readonly Code: "ChargeItem.code";
112
+ /** Local-language UI/help label for the coded product. Example: `Sterile saline bottle 500 mL`. */
113
+ readonly CodeText: "ChargeItem.code-text";
114
+ /** Normalized aggregate reporting category. Example: `medical-supplies`. */
115
+ readonly Category: "ChargeItem.category";
116
+ /** Supplier or import product code. Example: `IMP-SAL-500`. */
117
+ readonly SupplierProductCode: "ChargeItem.supplier-productcode";
118
+ /** Compact FHIR-style quantity token for search/readback. Example: `3|bottle`. */
119
+ readonly Quantity: "ChargeItem.quantity";
120
+ /** Main quantity numeric scalar serialized as string. Example: `3`. */
121
+ readonly QuantityNumber: "ChargeItem.quantity-number";
122
+ /** Main quantity unit code or label. Example: `bottle`. */
123
+ readonly QuantityUnit: "ChargeItem.quantity-unit";
124
+ /** Contained items per main unit. Example: `24`. */
125
+ readonly ItemsPerUnit: "ChargeItem.items-per-unit";
126
+ /** Compact contained-item quantity token for search/readback. Example: `500|mL`. */
127
+ readonly ItemsQuantity: "ChargeItem.items-quantity";
128
+ /** Contained item numeric quantity serialized as string. Example: `500`. */
129
+ readonly ItemsQuantityNumber: "ChargeItem.items-quantity-number";
130
+ /** Contained item UCUM-like unit. Example: `mL`. */
131
+ readonly ItemsQuantityUnit: "ChargeItem.items-quantity-unit";
132
+ };
133
+ export type ChargeItemClaimKey = typeof ChargeItemClaim[keyof typeof ChargeItemClaim];
134
+ export interface ChargeItemClaims {
135
+ [ChargeItemClaim.Identifier]?: string;
136
+ [ChargeItemClaim.Status]?: string;
137
+ [ChargeItemClaim.PartOf]?: string;
138
+ [ChargeItemClaim.Code]?: string;
139
+ [ChargeItemClaim.CodeText]?: string;
140
+ [ChargeItemClaim.Category]?: string;
141
+ [ChargeItemClaim.SupplierProductCode]?: string;
142
+ [ChargeItemClaim.Quantity]?: string;
143
+ [ChargeItemClaim.QuantityNumber]?: string;
144
+ [ChargeItemClaim.QuantityUnit]?: string;
145
+ [ChargeItemClaim.ItemsPerUnit]?: string;
146
+ [ChargeItemClaim.ItemsQuantity]?: string;
147
+ [ChargeItemClaim.ItemsQuantityNumber]?: string;
148
+ [ChargeItemClaim.ItemsQuantityUnit]?: string;
149
+ }
150
+ export declare enum ChargeItemClaimsFhirApiExtended {
151
+ Identifier = "org.hl7.fhir.api.ChargeItem.identifier",
152
+ Status = "org.hl7.fhir.api.ChargeItem.status",
153
+ PartOf = "org.hl7.fhir.api.ChargeItem.part-of",
154
+ Code = "org.hl7.fhir.api.ChargeItem.code",
155
+ CodeText = "org.hl7.fhir.api.ChargeItem.code-text",
156
+ Category = "org.hl7.fhir.api.ChargeItem.category",
157
+ SupplierProductCode = "org.hl7.fhir.api.ChargeItem.supplier-productcode",
158
+ Quantity = "org.hl7.fhir.api.ChargeItem.quantity",
159
+ QuantityNumber = "org.hl7.fhir.api.ChargeItem.quantity-number",
160
+ QuantityUnit = "org.hl7.fhir.api.ChargeItem.quantity-unit",
161
+ ItemsPerUnit = "org.hl7.fhir.api.ChargeItem.items-per-unit",
162
+ ItemsQuantity = "org.hl7.fhir.api.ChargeItem.items-quantity",
163
+ ItemsQuantityNumber = "org.hl7.fhir.api.ChargeItem.items-quantity-number",
164
+ ItemsQuantityUnit = "org.hl7.fhir.api.ChargeItem.items-quantity-unit"
165
+ }
166
+ export declare const ChargeItemSearchParamNames: {
167
+ readonly Identifier: "identifier";
168
+ readonly Status: "status";
169
+ readonly PartOf: "part-of";
170
+ readonly Code: "code";
171
+ readonly CodeText: "code-text";
172
+ readonly Category: "category";
173
+ readonly SupplierProductCode: "supplier-productcode";
174
+ readonly Quantity: "quantity";
175
+ readonly QuantityNumber: "quantity-number";
176
+ readonly QuantityUnit: "quantity-unit";
177
+ readonly ItemsPerUnit: "items-per-unit";
178
+ readonly ItemsQuantity: "items-quantity";
179
+ readonly ItemsQuantityNumber: "items-quantity-number";
180
+ readonly ItemsQuantityUnit: "items-quantity-unit";
181
+ };
182
+ export interface InvoiceClaimsContextualized {
183
+ [InvoiceClaimsFhirApiExtended.Identifier]?: string;
184
+ [InvoiceClaimsFhirApiExtended.Date]?: string;
185
+ [InvoiceClaimsFhirApiExtended.Status]?: string;
186
+ [InvoiceClaimsFhirApiExtended.Subject]?: string;
187
+ [InvoiceClaimsFhirApiExtended.Recipient]?: string;
188
+ [InvoiceClaimsFhirApiExtended.Issuer]?: string;
189
+ [InvoiceClaimsFhirApiExtended.IssuerDisplay]?: string;
190
+ [InvoiceClaimsFhirApiExtended.PaymentTerms]?: string;
191
+ [InvoiceClaimsFhirApiExtended.PaymentUrl]?: string;
192
+ [InvoiceClaimsFhirApiExtended.TotalNetValue]?: string;
193
+ [InvoiceClaimsFhirApiExtended.TotalNetCurrency]?: string;
194
+ [InvoiceClaimsFhirApiExtended.TotalGrossValue]?: string;
195
+ [InvoiceClaimsFhirApiExtended.TotalGrossCurrency]?: string;
196
+ }
197
+ export interface ChargeItemClaimsContextualized {
198
+ [ChargeItemClaimsFhirApiExtended.Identifier]?: string;
199
+ [ChargeItemClaimsFhirApiExtended.Status]?: string;
200
+ [ChargeItemClaimsFhirApiExtended.PartOf]?: string;
201
+ [ChargeItemClaimsFhirApiExtended.Code]?: string;
202
+ [ChargeItemClaimsFhirApiExtended.CodeText]?: string;
203
+ [ChargeItemClaimsFhirApiExtended.Category]?: string;
204
+ [ChargeItemClaimsFhirApiExtended.SupplierProductCode]?: string;
205
+ [ChargeItemClaimsFhirApiExtended.Quantity]?: string;
206
+ [ChargeItemClaimsFhirApiExtended.QuantityNumber]?: string;
207
+ [ChargeItemClaimsFhirApiExtended.QuantityUnit]?: string;
208
+ [ChargeItemClaimsFhirApiExtended.ItemsPerUnit]?: string;
209
+ [ChargeItemClaimsFhirApiExtended.ItemsQuantity]?: string;
210
+ [ChargeItemClaimsFhirApiExtended.ItemsQuantityNumber]?: string;
211
+ [ChargeItemClaimsFhirApiExtended.ItemsQuantityUnit]?: string;
212
+ }
213
+ export declare const InvoiceClaimSpecs: ClaimSpec[];
214
+ export declare const ChargeItemClaimSpecs: ClaimSpec[];
215
+ export declare const InvoiceClaimToFhirPath: Record<string, string | string[]>;
216
+ export declare function contextualizeInvoiceClaims(claims: InvoiceClaims): InvoiceClaimsContextualized;
217
+ export declare function contextualizeChargeItemClaims(claims: ChargeItemClaims): ChargeItemClaimsContextualized;
218
+ /**
219
+ * Generic low-level invoice claim accessor.
220
+ *
221
+ * Prefer the explicit `getInvoice*` helpers below from application code when
222
+ * you want stronger autocomplete and clearer intent at the call site.
223
+ */
224
+ export declare function getInvoiceClaim(claims: InvoiceClaims | undefined, key: InvoiceClaimKey): string | undefined;
225
+ /**
226
+ * Generic low-level charge item claim accessor.
227
+ *
228
+ * Prefer the explicit `getCode()`, `getCodeText()`, `getQuantityNumber()`,
229
+ * etc. helpers below from application code when you want stronger
230
+ * autocomplete and clearer intent at the call site.
231
+ */
232
+ export declare function getChargeItemClaim(claims: ChargeItemClaims | undefined, key: ChargeItemClaimKey): string | undefined;
233
+ export declare function getInvoiceIdentifier(claims: InvoiceClaims | undefined): string | undefined;
234
+ export declare function getInvoiceDate(claims: InvoiceClaims | undefined): string | undefined;
235
+ export declare function getInvoiceStatus(claims: InvoiceClaims | undefined): string | undefined;
236
+ export declare function getInvoiceSubject(claims: InvoiceClaims | undefined): string | undefined;
237
+ export declare function getInvoiceRecipient(claims: InvoiceClaims | undefined): string | undefined;
238
+ export declare function getInvoiceIssuer(claims: InvoiceClaims | undefined): string | undefined;
239
+ export declare function getInvoiceIssuerDisplay(claims: InvoiceClaims | undefined): string | undefined;
240
+ export declare function getInvoicePaymentTerms(claims: InvoiceClaims | undefined): string | undefined;
241
+ export declare function getInvoicePaymentUrl(claims: InvoiceClaims | undefined): string | undefined;
242
+ export declare function getInvoiceTotalNetValue(claims: InvoiceClaims | undefined): string | undefined;
243
+ export declare function getInvoiceTotalNetCurrency(claims: InvoiceClaims | undefined): string | undefined;
244
+ export declare function getInvoiceTotalGrossValue(claims: InvoiceClaims | undefined): string | undefined;
245
+ export declare function getInvoiceTotalGrossCurrency(claims: InvoiceClaims | undefined): string | undefined;
246
+ export declare function getChargeItemIdentifier(claims: ChargeItemClaims | undefined): string | undefined;
247
+ export declare function getChargeItemStatus(claims: ChargeItemClaims | undefined): string | undefined;
248
+ export declare function getChargeItemPartOf(claims: ChargeItemClaims | undefined): string | undefined;
249
+ export declare function getCode(claims: ChargeItemClaims | undefined): string | undefined;
250
+ export declare function getCodeText(claims: ChargeItemClaims | undefined): string | undefined;
251
+ export declare function getCategory(claims: ChargeItemClaims | undefined): string | undefined;
252
+ export declare function getSupplierProductCode(claims: ChargeItemClaims | undefined): string | undefined;
253
+ export declare function getQuantity(claims: ChargeItemClaims | undefined): string | undefined;
254
+ export declare function getQuantityNumber(claims: ChargeItemClaims | undefined): string | undefined;
255
+ export declare function getQuantityUnit(claims: ChargeItemClaims | undefined): string | undefined;
256
+ export declare function getItemsPerUnit(claims: ChargeItemClaims | undefined): string | undefined;
257
+ export declare function getItemsQuantity(claims: ChargeItemClaims | undefined): string | undefined;
258
+ export declare function getItemsQuantityNumber(claims: ChargeItemClaims | undefined): string | undefined;
259
+ export declare function getItemsQuantityUnit(claims: ChargeItemClaims | undefined): string | undefined;
260
+ export interface ChargeItemView {
261
+ identifier?: string;
262
+ status?: string;
263
+ partOf?: string;
264
+ code?: string;
265
+ codeText?: string;
266
+ category?: string;
267
+ supplierProductCode?: string;
268
+ quantity?: string;
269
+ quantityNumber?: string;
270
+ quantityUnit?: string;
271
+ itemsPerUnit?: string;
272
+ itemsQuantity?: string;
273
+ itemsQuantityNumber?: string;
274
+ itemsQuantityUnit?: string;
275
+ }
276
+ export declare function getChargeItemView(claims: ChargeItemClaims | undefined): ChargeItemView;
277
+ export declare function getChargeItemList(rows: ReadonlyArray<ChargeItemClaims | (InvoiceClaims & ChargeItemClaims)> | undefined): ChargeItemView[];
@@ -0,0 +1,353 @@
1
+ // Copyright 2026 Conéctate Soluciones y Aplicaciones SL under the Apache License, Version 2.0.
2
+ // File: src/models/interoperable-claims/invoice-claims.ts
3
+ /**
4
+ * Canonical flat claim keys for invoice-level business data.
5
+ *
6
+ * These claims are the claims-first source of truth. FHIR `Invoice` is one
7
+ * downstream projection built from them.
8
+ */
9
+ export const InvoiceClaim = {
10
+ /** Stable business invoice identifier. Example: `invoice-001`. */
11
+ Identifier: 'Invoice.identifier',
12
+ /** Invoice issue date/time. Example: `2026-06-11T10:00:00Z`. */
13
+ Date: 'Invoice.date',
14
+ /** Invoice lifecycle status. Example: `issued`. */
15
+ Status: 'Invoice.status',
16
+ /** Subject or tenant context reference. Example: `did:web:api.acme.org:individual:123`. */
17
+ Subject: 'Invoice.subject',
18
+ /** Billed recipient reference. Example: `did:web:portal.example.org:billing`. */
19
+ Recipient: 'Invoice.recipient',
20
+ /** Invoice issuer reference. Example: `did:web:api.acme.org`. */
21
+ Issuer: 'Invoice.issuer',
22
+ /** Human-readable issuer label. Example: `Gateway Host Services`. */
23
+ IssuerDisplay: 'Invoice.issuer-display',
24
+ /** Commercial payment method/terms. Example: `invoice`. */
25
+ PaymentTerms: 'Invoice.payment-terms',
26
+ /** Payment or settlement URL when available. Example: `https://pay.example/invoice-001`. */
27
+ PaymentUrl: 'Invoice.payment-url',
28
+ /** Net amount numeric value serialized as string. Example: `9.99`. */
29
+ TotalNetValue: 'Invoice.totalnet-value',
30
+ /** Net amount ISO currency. Example: `EUR`. */
31
+ TotalNetCurrency: 'Invoice.totalnet-currency',
32
+ /** Gross amount numeric value serialized as string. Example: `9.99`. */
33
+ TotalGrossValue: 'Invoice.totalgross-value',
34
+ /** Gross amount ISO currency. Example: `EUR`. */
35
+ TotalGrossCurrency: 'Invoice.totalgross-currency',
36
+ };
37
+ /**
38
+ * Contextualized FHIR-API-like invoice claims.
39
+ *
40
+ * Convention:
41
+ * - `org.hl7.fhir.api.Invoice.<concrete-parameter>`
42
+ * - scalar/string-friendly values only
43
+ * - invoice totals/payment URL remain extension-style operational claims
44
+ * because not every business field maps to one native FHIR search parameter
45
+ */
46
+ export var InvoiceClaimsFhirApiExtended;
47
+ (function (InvoiceClaimsFhirApiExtended) {
48
+ InvoiceClaimsFhirApiExtended["Identifier"] = "org.hl7.fhir.api.Invoice.identifier";
49
+ InvoiceClaimsFhirApiExtended["Date"] = "org.hl7.fhir.api.Invoice.date";
50
+ InvoiceClaimsFhirApiExtended["Status"] = "org.hl7.fhir.api.Invoice.status";
51
+ InvoiceClaimsFhirApiExtended["Subject"] = "org.hl7.fhir.api.Invoice.subject";
52
+ InvoiceClaimsFhirApiExtended["Recipient"] = "org.hl7.fhir.api.Invoice.recipient";
53
+ InvoiceClaimsFhirApiExtended["Issuer"] = "org.hl7.fhir.api.Invoice.issuer";
54
+ InvoiceClaimsFhirApiExtended["IssuerDisplay"] = "org.hl7.fhir.api.Invoice.issuer-display";
55
+ InvoiceClaimsFhirApiExtended["PaymentTerms"] = "org.hl7.fhir.api.Invoice.payment-terms";
56
+ InvoiceClaimsFhirApiExtended["PaymentUrl"] = "org.hl7.fhir.api.Invoice.payment-url";
57
+ InvoiceClaimsFhirApiExtended["TotalNetValue"] = "org.hl7.fhir.api.Invoice.totalnet-value";
58
+ InvoiceClaimsFhirApiExtended["TotalNetCurrency"] = "org.hl7.fhir.api.Invoice.totalnet-currency";
59
+ InvoiceClaimsFhirApiExtended["TotalGrossValue"] = "org.hl7.fhir.api.Invoice.totalgross-value";
60
+ InvoiceClaimsFhirApiExtended["TotalGrossCurrency"] = "org.hl7.fhir.api.Invoice.totalgross-currency";
61
+ })(InvoiceClaimsFhirApiExtended || (InvoiceClaimsFhirApiExtended = {}));
62
+ /**
63
+ * Canonical non-contextualized parameter names for query builders and readers.
64
+ */
65
+ export const InvoiceSearchParamNames = {
66
+ Identifier: 'identifier',
67
+ Date: 'date',
68
+ Status: 'status',
69
+ Subject: 'subject',
70
+ Recipient: 'recipient',
71
+ Issuer: 'issuer',
72
+ IssuerDisplay: 'issuer-display',
73
+ PaymentTerms: 'payment-terms',
74
+ PaymentUrl: 'payment-url',
75
+ TotalNetValue: 'totalnet-value',
76
+ TotalNetCurrency: 'totalnet-currency',
77
+ TotalGrossValue: 'totalgross-value',
78
+ TotalGrossCurrency: 'totalgross-currency',
79
+ };
80
+ /**
81
+ * Charge-item-level claims used when one business invoice line is represented
82
+ * as one claims row. The future FHIR export can compact multiple rows sharing
83
+ * one invoice identifier into a single `Invoice` with multiple items.
84
+ *
85
+ * Note:
86
+ * - FHIR `Invoice` does not expose all these details as search parameters.
87
+ * - `ChargeItem` is therefore modeled here as claims-first operational data.
88
+ */
89
+ export const ChargeItemClaim = {
90
+ /** Stable invoice line identifier. Example: `chargeitem-001`. */
91
+ Identifier: 'ChargeItem.identifier',
92
+ /** Charge item lifecycle status from FHIR ChargeItemStatus. Example: `billable`. */
93
+ Status: 'ChargeItem.status',
94
+ /** Parent business aggregate identifier. Example: `invoice-001`. */
95
+ PartOf: 'ChargeItem.part-of',
96
+ /** Public code such as GTIN/UDI/barcode. Example: `08412345678903`. */
97
+ Code: 'ChargeItem.code',
98
+ /** Local-language UI/help label for the coded product. Example: `Sterile saline bottle 500 mL`. */
99
+ CodeText: 'ChargeItem.code-text',
100
+ /** Normalized aggregate reporting category. Example: `medical-supplies`. */
101
+ Category: 'ChargeItem.category',
102
+ /** Supplier or import product code. Example: `IMP-SAL-500`. */
103
+ SupplierProductCode: 'ChargeItem.supplier-productcode',
104
+ /** Compact FHIR-style quantity token for search/readback. Example: `3|bottle`. */
105
+ Quantity: 'ChargeItem.quantity',
106
+ /** Main quantity numeric scalar serialized as string. Example: `3`. */
107
+ QuantityNumber: 'ChargeItem.quantity-number',
108
+ /** Main quantity unit code or label. Example: `bottle`. */
109
+ QuantityUnit: 'ChargeItem.quantity-unit',
110
+ /** Contained items per main unit. Example: `24`. */
111
+ ItemsPerUnit: 'ChargeItem.items-per-unit',
112
+ /** Compact contained-item quantity token for search/readback. Example: `500|mL`. */
113
+ ItemsQuantity: 'ChargeItem.items-quantity',
114
+ /** Contained item numeric quantity serialized as string. Example: `500`. */
115
+ ItemsQuantityNumber: 'ChargeItem.items-quantity-number',
116
+ /** Contained item UCUM-like unit. Example: `mL`. */
117
+ ItemsQuantityUnit: 'ChargeItem.items-quantity-unit',
118
+ };
119
+ export var ChargeItemClaimsFhirApiExtended;
120
+ (function (ChargeItemClaimsFhirApiExtended) {
121
+ ChargeItemClaimsFhirApiExtended["Identifier"] = "org.hl7.fhir.api.ChargeItem.identifier";
122
+ ChargeItemClaimsFhirApiExtended["Status"] = "org.hl7.fhir.api.ChargeItem.status";
123
+ ChargeItemClaimsFhirApiExtended["PartOf"] = "org.hl7.fhir.api.ChargeItem.part-of";
124
+ ChargeItemClaimsFhirApiExtended["Code"] = "org.hl7.fhir.api.ChargeItem.code";
125
+ ChargeItemClaimsFhirApiExtended["CodeText"] = "org.hl7.fhir.api.ChargeItem.code-text";
126
+ ChargeItemClaimsFhirApiExtended["Category"] = "org.hl7.fhir.api.ChargeItem.category";
127
+ ChargeItemClaimsFhirApiExtended["SupplierProductCode"] = "org.hl7.fhir.api.ChargeItem.supplier-productcode";
128
+ ChargeItemClaimsFhirApiExtended["Quantity"] = "org.hl7.fhir.api.ChargeItem.quantity";
129
+ ChargeItemClaimsFhirApiExtended["QuantityNumber"] = "org.hl7.fhir.api.ChargeItem.quantity-number";
130
+ ChargeItemClaimsFhirApiExtended["QuantityUnit"] = "org.hl7.fhir.api.ChargeItem.quantity-unit";
131
+ ChargeItemClaimsFhirApiExtended["ItemsPerUnit"] = "org.hl7.fhir.api.ChargeItem.items-per-unit";
132
+ ChargeItemClaimsFhirApiExtended["ItemsQuantity"] = "org.hl7.fhir.api.ChargeItem.items-quantity";
133
+ ChargeItemClaimsFhirApiExtended["ItemsQuantityNumber"] = "org.hl7.fhir.api.ChargeItem.items-quantity-number";
134
+ ChargeItemClaimsFhirApiExtended["ItemsQuantityUnit"] = "org.hl7.fhir.api.ChargeItem.items-quantity-unit";
135
+ })(ChargeItemClaimsFhirApiExtended || (ChargeItemClaimsFhirApiExtended = {}));
136
+ export const ChargeItemSearchParamNames = {
137
+ Identifier: 'identifier',
138
+ Status: 'status',
139
+ PartOf: 'part-of',
140
+ Code: 'code',
141
+ CodeText: 'code-text',
142
+ Category: 'category',
143
+ SupplierProductCode: 'supplier-productcode',
144
+ Quantity: 'quantity',
145
+ QuantityNumber: 'quantity-number',
146
+ QuantityUnit: 'quantity-unit',
147
+ ItemsPerUnit: 'items-per-unit',
148
+ ItemsQuantity: 'items-quantity',
149
+ ItemsQuantityNumber: 'items-quantity-number',
150
+ ItemsQuantityUnit: 'items-quantity-unit',
151
+ };
152
+ export const InvoiceClaimSpecs = [
153
+ { key: InvoiceClaim.Identifier, meaning: 'Stable business invoice identifier.', example: 'invoice-001' },
154
+ { key: InvoiceClaim.Date, meaning: 'Invoice issue date/time.', example: '2026-06-11T10:00:00Z' },
155
+ { key: InvoiceClaim.Status, meaning: 'Invoice lifecycle status.', example: 'issued' },
156
+ { key: InvoiceClaim.Subject, meaning: 'Subject or tenant context reference.', example: 'did:web:api.acme.org:individual:123' },
157
+ { key: InvoiceClaim.Recipient, meaning: 'Billed recipient reference.', example: 'did:web:portal.example.org:billing' },
158
+ { key: InvoiceClaim.Issuer, meaning: 'Invoice issuer reference.', example: 'did:web:api.acme.org' },
159
+ { key: InvoiceClaim.IssuerDisplay, meaning: 'Human-readable issuer label.', example: 'Gateway Host Services' },
160
+ { key: InvoiceClaim.PaymentTerms, meaning: 'Commercial payment method/terms.', example: 'invoice' },
161
+ { key: InvoiceClaim.PaymentUrl, meaning: 'Payment or settlement URL when available.', example: 'https://pay.example/invoice-001' },
162
+ { key: InvoiceClaim.TotalNetValue, meaning: 'Net amount numeric value serialized as string.', example: '9.99' },
163
+ { key: InvoiceClaim.TotalNetCurrency, meaning: 'Net amount ISO currency.', example: 'EUR' },
164
+ { key: InvoiceClaim.TotalGrossValue, meaning: 'Gross amount numeric value serialized as string.', example: '9.99' },
165
+ { key: InvoiceClaim.TotalGrossCurrency, meaning: 'Gross amount ISO currency.', example: 'EUR' },
166
+ ];
167
+ export const ChargeItemClaimSpecs = [
168
+ { key: ChargeItemClaim.Identifier, meaning: 'Stable invoice line identifier.', example: 'chargeitem-001' },
169
+ { key: ChargeItemClaim.Status, meaning: 'Charge item lifecycle status from FHIR ChargeItemStatus.', example: 'billable' },
170
+ { key: ChargeItemClaim.PartOf, meaning: 'Parent business aggregate identifier.', example: 'invoice-001' },
171
+ { key: ChargeItemClaim.Code, meaning: 'Public code such as GTIN/UDI/barcode.', example: '08412345678903' },
172
+ { key: ChargeItemClaim.CodeText, meaning: 'Local-language UI/help label for the coded product.', example: 'Botella de suero salino estéril 500 mL' },
173
+ { key: ChargeItemClaim.Category, meaning: 'Normalized aggregate reporting category.', example: 'medical-supplies' },
174
+ { key: ChargeItemClaim.SupplierProductCode, meaning: 'Supplier or import product code.', example: 'IMP-SAL-500' },
175
+ { key: ChargeItemClaim.Quantity, meaning: 'Compact FHIR-style quantity token for search/readback.', example: '3|bottle' },
176
+ { key: ChargeItemClaim.QuantityNumber, meaning: 'Main quantity numeric scalar serialized as string.', example: '3' },
177
+ { key: ChargeItemClaim.QuantityUnit, meaning: 'Main quantity unit code or label.', example: 'bottle' },
178
+ { key: ChargeItemClaim.ItemsPerUnit, meaning: 'Contained items per main unit.', example: '24' },
179
+ { key: ChargeItemClaim.ItemsQuantity, meaning: 'Compact contained-item quantity token for search/readback.', example: '500|mL' },
180
+ { key: ChargeItemClaim.ItemsQuantityNumber, meaning: 'Contained item numeric quantity serialized as string.', example: '500' },
181
+ { key: ChargeItemClaim.ItemsQuantityUnit, meaning: 'Contained item UCUM-like unit.', example: 'mL' },
182
+ ];
183
+ export const InvoiceClaimToFhirPath = {
184
+ [InvoiceClaim.Identifier]: 'Invoice.identifier.value',
185
+ [InvoiceClaim.Date]: 'Invoice.date',
186
+ [InvoiceClaim.Status]: 'Invoice.status',
187
+ [InvoiceClaim.Subject]: 'Invoice.subject.reference',
188
+ [InvoiceClaim.Recipient]: 'Invoice.recipient.reference',
189
+ [InvoiceClaim.Issuer]: 'Invoice.issuer.reference',
190
+ [InvoiceClaim.IssuerDisplay]: 'Invoice.issuer.display',
191
+ [InvoiceClaim.PaymentTerms]: 'Invoice.paymentTerms',
192
+ [InvoiceClaim.PaymentUrl]: 'Invoice.note.text',
193
+ [InvoiceClaim.TotalNetValue]: 'Invoice.totalNet.value',
194
+ [InvoiceClaim.TotalNetCurrency]: 'Invoice.totalNet.currency',
195
+ [InvoiceClaim.TotalGrossValue]: 'Invoice.totalGross.value',
196
+ [InvoiceClaim.TotalGrossCurrency]: 'Invoice.totalGross.currency',
197
+ };
198
+ export function contextualizeInvoiceClaims(claims) {
199
+ return {
200
+ ...(claims[InvoiceClaim.Identifier] ? { [InvoiceClaimsFhirApiExtended.Identifier]: claims[InvoiceClaim.Identifier] } : {}),
201
+ ...(claims[InvoiceClaim.Date] ? { [InvoiceClaimsFhirApiExtended.Date]: claims[InvoiceClaim.Date] } : {}),
202
+ ...(claims[InvoiceClaim.Status] ? { [InvoiceClaimsFhirApiExtended.Status]: claims[InvoiceClaim.Status] } : {}),
203
+ ...(claims[InvoiceClaim.Subject] ? { [InvoiceClaimsFhirApiExtended.Subject]: claims[InvoiceClaim.Subject] } : {}),
204
+ ...(claims[InvoiceClaim.Recipient] ? { [InvoiceClaimsFhirApiExtended.Recipient]: claims[InvoiceClaim.Recipient] } : {}),
205
+ ...(claims[InvoiceClaim.Issuer] ? { [InvoiceClaimsFhirApiExtended.Issuer]: claims[InvoiceClaim.Issuer] } : {}),
206
+ ...(claims[InvoiceClaim.IssuerDisplay] ? { [InvoiceClaimsFhirApiExtended.IssuerDisplay]: claims[InvoiceClaim.IssuerDisplay] } : {}),
207
+ ...(claims[InvoiceClaim.PaymentTerms] ? { [InvoiceClaimsFhirApiExtended.PaymentTerms]: claims[InvoiceClaim.PaymentTerms] } : {}),
208
+ ...(claims[InvoiceClaim.PaymentUrl] ? { [InvoiceClaimsFhirApiExtended.PaymentUrl]: claims[InvoiceClaim.PaymentUrl] } : {}),
209
+ ...(claims[InvoiceClaim.TotalNetValue] ? { [InvoiceClaimsFhirApiExtended.TotalNetValue]: claims[InvoiceClaim.TotalNetValue] } : {}),
210
+ ...(claims[InvoiceClaim.TotalNetCurrency] ? { [InvoiceClaimsFhirApiExtended.TotalNetCurrency]: claims[InvoiceClaim.TotalNetCurrency] } : {}),
211
+ ...(claims[InvoiceClaim.TotalGrossValue] ? { [InvoiceClaimsFhirApiExtended.TotalGrossValue]: claims[InvoiceClaim.TotalGrossValue] } : {}),
212
+ ...(claims[InvoiceClaim.TotalGrossCurrency] ? { [InvoiceClaimsFhirApiExtended.TotalGrossCurrency]: claims[InvoiceClaim.TotalGrossCurrency] } : {}),
213
+ };
214
+ }
215
+ export function contextualizeChargeItemClaims(claims) {
216
+ return {
217
+ ...(claims[ChargeItemClaim.Identifier] ? { [ChargeItemClaimsFhirApiExtended.Identifier]: claims[ChargeItemClaim.Identifier] } : {}),
218
+ ...(claims[ChargeItemClaim.Status] ? { [ChargeItemClaimsFhirApiExtended.Status]: claims[ChargeItemClaim.Status] } : {}),
219
+ ...(claims[ChargeItemClaim.PartOf] ? { [ChargeItemClaimsFhirApiExtended.PartOf]: claims[ChargeItemClaim.PartOf] } : {}),
220
+ ...(claims[ChargeItemClaim.Code] ? { [ChargeItemClaimsFhirApiExtended.Code]: claims[ChargeItemClaim.Code] } : {}),
221
+ ...(claims[ChargeItemClaim.CodeText] ? { [ChargeItemClaimsFhirApiExtended.CodeText]: claims[ChargeItemClaim.CodeText] } : {}),
222
+ ...(claims[ChargeItemClaim.Category] ? { [ChargeItemClaimsFhirApiExtended.Category]: claims[ChargeItemClaim.Category] } : {}),
223
+ ...(claims[ChargeItemClaim.SupplierProductCode] ? { [ChargeItemClaimsFhirApiExtended.SupplierProductCode]: claims[ChargeItemClaim.SupplierProductCode] } : {}),
224
+ ...(claims[ChargeItemClaim.Quantity] ? { [ChargeItemClaimsFhirApiExtended.Quantity]: claims[ChargeItemClaim.Quantity] } : {}),
225
+ ...(claims[ChargeItemClaim.QuantityNumber] ? { [ChargeItemClaimsFhirApiExtended.QuantityNumber]: claims[ChargeItemClaim.QuantityNumber] } : {}),
226
+ ...(claims[ChargeItemClaim.QuantityUnit] ? { [ChargeItemClaimsFhirApiExtended.QuantityUnit]: claims[ChargeItemClaim.QuantityUnit] } : {}),
227
+ ...(claims[ChargeItemClaim.ItemsPerUnit] ? { [ChargeItemClaimsFhirApiExtended.ItemsPerUnit]: claims[ChargeItemClaim.ItemsPerUnit] } : {}),
228
+ ...(claims[ChargeItemClaim.ItemsQuantity] ? { [ChargeItemClaimsFhirApiExtended.ItemsQuantity]: claims[ChargeItemClaim.ItemsQuantity] } : {}),
229
+ ...(claims[ChargeItemClaim.ItemsQuantityNumber] ? { [ChargeItemClaimsFhirApiExtended.ItemsQuantityNumber]: claims[ChargeItemClaim.ItemsQuantityNumber] } : {}),
230
+ ...(claims[ChargeItemClaim.ItemsQuantityUnit] ? { [ChargeItemClaimsFhirApiExtended.ItemsQuantityUnit]: claims[ChargeItemClaim.ItemsQuantityUnit] } : {}),
231
+ };
232
+ }
233
+ /**
234
+ * Generic low-level invoice claim accessor.
235
+ *
236
+ * Prefer the explicit `getInvoice*` helpers below from application code when
237
+ * you want stronger autocomplete and clearer intent at the call site.
238
+ */
239
+ export function getInvoiceClaim(claims, key) {
240
+ return claims?.[key];
241
+ }
242
+ /**
243
+ * Generic low-level charge item claim accessor.
244
+ *
245
+ * Prefer the explicit `getCode()`, `getCodeText()`, `getQuantityNumber()`,
246
+ * etc. helpers below from application code when you want stronger
247
+ * autocomplete and clearer intent at the call site.
248
+ */
249
+ export function getChargeItemClaim(claims, key) {
250
+ return claims?.[key];
251
+ }
252
+ export function getInvoiceIdentifier(claims) {
253
+ return getInvoiceClaim(claims, InvoiceClaim.Identifier);
254
+ }
255
+ export function getInvoiceDate(claims) {
256
+ return getInvoiceClaim(claims, InvoiceClaim.Date);
257
+ }
258
+ export function getInvoiceStatus(claims) {
259
+ return getInvoiceClaim(claims, InvoiceClaim.Status);
260
+ }
261
+ export function getInvoiceSubject(claims) {
262
+ return getInvoiceClaim(claims, InvoiceClaim.Subject);
263
+ }
264
+ export function getInvoiceRecipient(claims) {
265
+ return getInvoiceClaim(claims, InvoiceClaim.Recipient);
266
+ }
267
+ export function getInvoiceIssuer(claims) {
268
+ return getInvoiceClaim(claims, InvoiceClaim.Issuer);
269
+ }
270
+ export function getInvoiceIssuerDisplay(claims) {
271
+ return getInvoiceClaim(claims, InvoiceClaim.IssuerDisplay);
272
+ }
273
+ export function getInvoicePaymentTerms(claims) {
274
+ return getInvoiceClaim(claims, InvoiceClaim.PaymentTerms);
275
+ }
276
+ export function getInvoicePaymentUrl(claims) {
277
+ return getInvoiceClaim(claims, InvoiceClaim.PaymentUrl);
278
+ }
279
+ export function getInvoiceTotalNetValue(claims) {
280
+ return getInvoiceClaim(claims, InvoiceClaim.TotalNetValue);
281
+ }
282
+ export function getInvoiceTotalNetCurrency(claims) {
283
+ return getInvoiceClaim(claims, InvoiceClaim.TotalNetCurrency);
284
+ }
285
+ export function getInvoiceTotalGrossValue(claims) {
286
+ return getInvoiceClaim(claims, InvoiceClaim.TotalGrossValue);
287
+ }
288
+ export function getInvoiceTotalGrossCurrency(claims) {
289
+ return getInvoiceClaim(claims, InvoiceClaim.TotalGrossCurrency);
290
+ }
291
+ export function getChargeItemIdentifier(claims) {
292
+ return getChargeItemClaim(claims, ChargeItemClaim.Identifier);
293
+ }
294
+ export function getChargeItemStatus(claims) {
295
+ return getChargeItemClaim(claims, ChargeItemClaim.Status);
296
+ }
297
+ export function getChargeItemPartOf(claims) {
298
+ return getChargeItemClaim(claims, ChargeItemClaim.PartOf);
299
+ }
300
+ export function getCode(claims) {
301
+ return getChargeItemClaim(claims, ChargeItemClaim.Code);
302
+ }
303
+ export function getCodeText(claims) {
304
+ return getChargeItemClaim(claims, ChargeItemClaim.CodeText);
305
+ }
306
+ export function getCategory(claims) {
307
+ return getChargeItemClaim(claims, ChargeItemClaim.Category);
308
+ }
309
+ export function getSupplierProductCode(claims) {
310
+ return getChargeItemClaim(claims, ChargeItemClaim.SupplierProductCode);
311
+ }
312
+ export function getQuantity(claims) {
313
+ return getChargeItemClaim(claims, ChargeItemClaim.Quantity);
314
+ }
315
+ export function getQuantityNumber(claims) {
316
+ return getChargeItemClaim(claims, ChargeItemClaim.QuantityNumber);
317
+ }
318
+ export function getQuantityUnit(claims) {
319
+ return getChargeItemClaim(claims, ChargeItemClaim.QuantityUnit);
320
+ }
321
+ export function getItemsPerUnit(claims) {
322
+ return getChargeItemClaim(claims, ChargeItemClaim.ItemsPerUnit);
323
+ }
324
+ export function getItemsQuantity(claims) {
325
+ return getChargeItemClaim(claims, ChargeItemClaim.ItemsQuantity);
326
+ }
327
+ export function getItemsQuantityNumber(claims) {
328
+ return getChargeItemClaim(claims, ChargeItemClaim.ItemsQuantityNumber);
329
+ }
330
+ export function getItemsQuantityUnit(claims) {
331
+ return getChargeItemClaim(claims, ChargeItemClaim.ItemsQuantityUnit);
332
+ }
333
+ export function getChargeItemView(claims) {
334
+ return {
335
+ identifier: getChargeItemIdentifier(claims),
336
+ status: getChargeItemStatus(claims),
337
+ partOf: getChargeItemPartOf(claims),
338
+ code: getCode(claims),
339
+ codeText: getCodeText(claims),
340
+ category: getCategory(claims),
341
+ supplierProductCode: getSupplierProductCode(claims),
342
+ quantity: getQuantity(claims),
343
+ quantityNumber: getQuantityNumber(claims),
344
+ quantityUnit: getQuantityUnit(claims),
345
+ itemsPerUnit: getItemsPerUnit(claims),
346
+ itemsQuantity: getItemsQuantity(claims),
347
+ itemsQuantityNumber: getItemsQuantityNumber(claims),
348
+ itemsQuantityUnit: getItemsQuantityUnit(claims),
349
+ };
350
+ }
351
+ export function getChargeItemList(rows) {
352
+ return Array.isArray(rows) ? rows.map((row) => getChargeItemView(row)) : [];
353
+ }
@@ -2,4 +2,4 @@
2
2
  * Canonical interoperable-claims keys used by claims-first payloads.
3
3
  * Keep this separated from strict FHIR resource typings.
4
4
  */
5
- export * from './interoperable-claims';
5
+ export * from './interoperable-claims/index';
@@ -4,4 +4,4 @@
4
4
  * Canonical interoperable-claims keys used by claims-first payloads.
5
5
  * Keep this separated from strict FHIR resource typings.
6
6
  */
7
- export * from './interoperable-claims.js';
7
+ export * from './interoperable-claims/index.js';
@@ -46,6 +46,7 @@ export * from './individual-onboarding-editor';
46
46
  export * from './individual-onboarding-document-reference';
47
47
  export * from './individual-organization-kyc';
48
48
  export * from './individual-bundle-vault';
49
+ export * from './invoice-bundle';
49
50
  export * from './ips-bundle-claims';
50
51
  export * from './interoperable-resource-operation';
51
52
  export * from './jwt';
@@ -46,6 +46,7 @@ export * from './individual-onboarding-editor.js';
46
46
  export * from './individual-onboarding-document-reference.js';
47
47
  export * from './individual-organization-kyc.js';
48
48
  export * from './individual-bundle-vault.js';
49
+ export * from './invoice-bundle.js';
49
50
  export * from './ips-bundle-claims.js';
50
51
  export * from './interoperable-resource-operation.js';
51
52
  export * from './jwt.js';
@@ -0,0 +1,82 @@
1
+ import { ChargeItemClaims, ChargeItemClaimsContextualized, InvoiceClaims, InvoiceClaimsContextualized } from '../models/interoperable-claims/invoice-claims';
2
+ export type InvoiceBundleDocument = Readonly<{
3
+ documentId: string;
4
+ contentType: string;
5
+ title: string;
6
+ description: string;
7
+ language?: string;
8
+ dataBase64?: string;
9
+ url?: string;
10
+ hash?: string;
11
+ createdAt?: string;
12
+ }>;
13
+ export type InvoiceChargeItemDraft = Readonly<{
14
+ identifier?: string;
15
+ status?: string;
16
+ partOf?: string;
17
+ code?: string;
18
+ codeText?: string;
19
+ category?: string;
20
+ supplierProductCode?: string;
21
+ quantity?: string;
22
+ quantityNumber?: string;
23
+ quantityUnit?: string;
24
+ itemsPerUnit?: string;
25
+ itemsQuantity?: string;
26
+ itemsQuantityNumber?: string;
27
+ itemsQuantityUnit?: string;
28
+ }>;
29
+ export type InvoiceBundleDraft = Readonly<{
30
+ invoiceId?: string;
31
+ subjectReference?: string;
32
+ issuerReference?: string;
33
+ issuerDisplay?: string;
34
+ recipientReference?: string;
35
+ issuedAt?: string;
36
+ amount?: string;
37
+ currency?: string;
38
+ paymentMethod?: string;
39
+ paymentUrl?: string;
40
+ pdfDocument?: InvoiceBundleDocument;
41
+ structuredDocument?: InvoiceBundleDocument;
42
+ chargeItems?: readonly InvoiceChargeItemDraft[];
43
+ }>;
44
+ export type InvoiceBundleSummary = Readonly<{
45
+ invoiceId?: string;
46
+ amount?: string;
47
+ currency?: string;
48
+ paymentMethod?: string;
49
+ paymentUrl?: string;
50
+ pdfDocumentId?: string;
51
+ structuredDocumentId?: string;
52
+ }>;
53
+ export interface InvoiceBundleEditor {
54
+ setInvoiceId(value: string): InvoiceBundleEditor;
55
+ setSubjectReference(value: string): InvoiceBundleEditor;
56
+ setIssuerReference(value: string): InvoiceBundleEditor;
57
+ setIssuerDisplay(value: string): InvoiceBundleEditor;
58
+ setRecipientReference(value: string): InvoiceBundleEditor;
59
+ setIssuedAt(value: string): InvoiceBundleEditor;
60
+ setAmount(value: string): InvoiceBundleEditor;
61
+ setCurrency(value: string): InvoiceBundleEditor;
62
+ setPaymentMethod(value: string): InvoiceBundleEditor;
63
+ setPaymentUrl(value: string): InvoiceBundleEditor;
64
+ setPdfDocument(value: InvoiceBundleDocument): InvoiceBundleEditor;
65
+ setStructuredDocument(value: InvoiceBundleDocument): InvoiceBundleEditor;
66
+ setChargeItems(value: readonly InvoiceChargeItemDraft[]): InvoiceBundleEditor;
67
+ addChargeItem(value: InvoiceChargeItemDraft): InvoiceBundleEditor;
68
+ getDraft(): InvoiceBundleDraft;
69
+ buildBundle(): Record<string, unknown>;
70
+ buildInvoiceClaims(): InvoiceClaims;
71
+ buildInvoiceClaimsContextualized(): InvoiceClaimsContextualized;
72
+ buildChargeItemClaimRows(): Array<InvoiceClaims & ChargeItemClaims>;
73
+ buildChargeItemClaimRowsContextualized(): ChargeItemClaimsContextualized[];
74
+ getSummary(): InvoiceBundleSummary;
75
+ readBundleFromResponseBody(body: unknown): Record<string, unknown> | undefined;
76
+ }
77
+ export declare function buildInvoiceFhirClaims(draftInput: Partial<InvoiceBundleDraft>): InvoiceClaims;
78
+ export declare function buildInvoiceChargeItemClaimRows(draftInput: Partial<InvoiceBundleDraft>): Array<InvoiceClaims & ChargeItemClaims>;
79
+ export declare function buildInvoiceBundle(draftInput: Partial<InvoiceBundleDraft>): Record<string, unknown>;
80
+ export declare function extractInvoiceBundleFromResponseBody(body: unknown): Record<string, unknown> | undefined;
81
+ export declare function readInvoiceBundleSummaryFromResponseBody(body: unknown): InvoiceBundleSummary;
82
+ export declare function createInvoiceBundleEditor(initial?: Partial<InvoiceBundleDraft>): InvoiceBundleEditor;
@@ -0,0 +1,240 @@
1
+ import { ResourceTypesFhirR4 } from '../constants/fhir-resource-types.js';
2
+ import { ChargeItemClaim, InvoiceClaim, contextualizeChargeItemClaims, contextualizeInvoiceClaims, } from '../models/interoperable-claims/invoice-claims.js';
3
+ function normalizeText(value) {
4
+ const normalized = String(value ?? '').trim();
5
+ return normalized || undefined;
6
+ }
7
+ function normalizeDocument(value) {
8
+ if (!value)
9
+ return undefined;
10
+ return {
11
+ documentId: String(value.documentId || '').trim(),
12
+ contentType: String(value.contentType || '').trim(),
13
+ title: String(value.title || '').trim(),
14
+ description: String(value.description || '').trim(),
15
+ language: normalizeText(value.language),
16
+ dataBase64: normalizeText(value.dataBase64),
17
+ url: normalizeText(value.url),
18
+ hash: normalizeText(value.hash),
19
+ createdAt: normalizeText(value.createdAt),
20
+ };
21
+ }
22
+ function cloneDraft(draft) {
23
+ return {
24
+ invoiceId: normalizeText(draft?.invoiceId),
25
+ subjectReference: normalizeText(draft?.subjectReference),
26
+ issuerReference: normalizeText(draft?.issuerReference),
27
+ issuerDisplay: normalizeText(draft?.issuerDisplay),
28
+ recipientReference: normalizeText(draft?.recipientReference),
29
+ issuedAt: normalizeText(draft?.issuedAt),
30
+ amount: normalizeText(draft?.amount),
31
+ currency: normalizeText(draft?.currency),
32
+ paymentMethod: normalizeText(draft?.paymentMethod),
33
+ paymentUrl: normalizeText(draft?.paymentUrl),
34
+ pdfDocument: normalizeDocument(draft?.pdfDocument),
35
+ structuredDocument: normalizeDocument(draft?.structuredDocument),
36
+ chargeItems: Array.isArray(draft?.chargeItems)
37
+ ? draft?.chargeItems.map((item) => ({
38
+ identifier: normalizeText(item?.identifier),
39
+ status: normalizeText(item?.status),
40
+ partOf: normalizeText(item?.partOf),
41
+ code: normalizeText(item?.code),
42
+ codeText: normalizeText(item?.codeText),
43
+ category: normalizeText(item?.category),
44
+ supplierProductCode: normalizeText(item?.supplierProductCode),
45
+ quantity: normalizeText(item?.quantity),
46
+ quantityNumber: normalizeText(item?.quantityNumber),
47
+ quantityUnit: normalizeText(item?.quantityUnit),
48
+ itemsPerUnit: normalizeText(item?.itemsPerUnit),
49
+ itemsQuantity: normalizeText(item?.itemsQuantity),
50
+ itemsQuantityNumber: normalizeText(item?.itemsQuantityNumber),
51
+ itemsQuantityUnit: normalizeText(item?.itemsQuantityUnit),
52
+ }))
53
+ : [],
54
+ };
55
+ }
56
+ export function buildInvoiceFhirClaims(draftInput) {
57
+ const draft = cloneDraft(draftInput);
58
+ return {
59
+ ...(draft.invoiceId ? { [InvoiceClaim.Identifier]: draft.invoiceId } : {}),
60
+ ...(draft.issuedAt ? { [InvoiceClaim.Date]: draft.issuedAt } : {}),
61
+ [InvoiceClaim.Status]: 'issued',
62
+ ...(draft.subjectReference ? { [InvoiceClaim.Subject]: draft.subjectReference } : {}),
63
+ ...(draft.recipientReference ? { [InvoiceClaim.Recipient]: draft.recipientReference } : {}),
64
+ ...(draft.issuerReference ? { [InvoiceClaim.Issuer]: draft.issuerReference } : {}),
65
+ ...(draft.issuerDisplay ? { [InvoiceClaim.IssuerDisplay]: draft.issuerDisplay } : {}),
66
+ ...(draft.paymentMethod ? { [InvoiceClaim.PaymentTerms]: draft.paymentMethod } : {}),
67
+ ...(draft.paymentUrl ? { [InvoiceClaim.PaymentUrl]: draft.paymentUrl } : {}),
68
+ ...(draft.amount ? { [InvoiceClaim.TotalNetValue]: draft.amount } : {}),
69
+ ...(draft.currency ? { [InvoiceClaim.TotalNetCurrency]: draft.currency } : {}),
70
+ ...(draft.amount ? { [InvoiceClaim.TotalGrossValue]: draft.amount } : {}),
71
+ ...(draft.currency ? { [InvoiceClaim.TotalGrossCurrency]: draft.currency } : {}),
72
+ };
73
+ }
74
+ export function buildInvoiceChargeItemClaimRows(draftInput) {
75
+ const draft = cloneDraft(draftInput);
76
+ const invoiceClaims = buildInvoiceFhirClaims(draft);
77
+ return (draft.chargeItems || []).map((item) => ({
78
+ ...invoiceClaims,
79
+ ...(item.identifier ? { [ChargeItemClaim.Identifier]: item.identifier } : {}),
80
+ ...((item.status || 'billable') ? { [ChargeItemClaim.Status]: item.status || 'billable' } : {}),
81
+ ...((item.partOf || draft.invoiceId) ? { [ChargeItemClaim.PartOf]: item.partOf || draft.invoiceId } : {}),
82
+ ...(item.code ? { [ChargeItemClaim.Code]: item.code } : {}),
83
+ ...(item.codeText ? { [ChargeItemClaim.CodeText]: item.codeText } : {}),
84
+ ...(item.category ? { [ChargeItemClaim.Category]: item.category } : {}),
85
+ ...(item.supplierProductCode ? { [ChargeItemClaim.SupplierProductCode]: item.supplierProductCode } : {}),
86
+ ...(item.quantity ? { [ChargeItemClaim.Quantity]: item.quantity } : {}),
87
+ ...(item.quantityNumber ? { [ChargeItemClaim.QuantityNumber]: item.quantityNumber } : {}),
88
+ ...(item.quantityUnit ? { [ChargeItemClaim.QuantityUnit]: item.quantityUnit } : {}),
89
+ ...(item.itemsPerUnit ? { [ChargeItemClaim.ItemsPerUnit]: item.itemsPerUnit } : {}),
90
+ ...(item.itemsQuantity ? { [ChargeItemClaim.ItemsQuantity]: item.itemsQuantity } : {}),
91
+ ...(item.itemsQuantityNumber ? { [ChargeItemClaim.ItemsQuantityNumber]: item.itemsQuantityNumber } : {}),
92
+ ...(item.itemsQuantityUnit ? { [ChargeItemClaim.ItemsQuantityUnit]: item.itemsQuantityUnit } : {}),
93
+ }));
94
+ }
95
+ function asRecord(value) {
96
+ return value && typeof value === 'object' && !Array.isArray(value)
97
+ ? value
98
+ : undefined;
99
+ }
100
+ function buildDocumentReferenceResource(draft, document) {
101
+ return {
102
+ resourceType: ResourceTypesFhirR4.DocumentReference,
103
+ id: document.documentId,
104
+ status: 'current',
105
+ identifier: [{ value: document.documentId }],
106
+ subject: draft.subjectReference ? { reference: draft.subjectReference } : undefined,
107
+ date: document.createdAt || draft.issuedAt,
108
+ description: document.description,
109
+ content: [{
110
+ attachment: {
111
+ contentType: document.contentType,
112
+ data: document.dataBase64,
113
+ url: document.url,
114
+ title: document.title,
115
+ language: document.language,
116
+ creation: document.createdAt || draft.issuedAt,
117
+ hash: document.hash,
118
+ },
119
+ }],
120
+ };
121
+ }
122
+ export function buildInvoiceBundle(draftInput) {
123
+ const draft = cloneDraft(draftInput);
124
+ const amountNumber = Number(draft.amount || '');
125
+ const normalizedAmount = Number.isFinite(amountNumber) ? amountNumber : undefined;
126
+ const invoiceResource = {
127
+ resourceType: ResourceTypesFhirR4.Invoice,
128
+ id: draft.invoiceId,
129
+ meta: { claims: buildInvoiceFhirClaims(draft) },
130
+ status: 'issued',
131
+ identifier: draft.invoiceId ? [{ value: draft.invoiceId }] : undefined,
132
+ subject: draft.subjectReference ? { reference: draft.subjectReference } : undefined,
133
+ recipient: draft.recipientReference ? { reference: draft.recipientReference } : undefined,
134
+ issuer: draft.issuerReference || draft.issuerDisplay
135
+ ? { reference: draft.issuerReference, display: draft.issuerDisplay }
136
+ : undefined,
137
+ date: draft.issuedAt,
138
+ paymentTerms: draft.paymentMethod,
139
+ note: draft.paymentUrl ? [{ text: draft.paymentUrl }] : undefined,
140
+ totalNet: normalizedAmount !== undefined
141
+ ? { value: normalizedAmount, currency: draft.currency }
142
+ : undefined,
143
+ totalGross: normalizedAmount !== undefined
144
+ ? { value: normalizedAmount, currency: draft.currency }
145
+ : undefined,
146
+ };
147
+ const entry = [{ resource: invoiceResource }];
148
+ if (draft.pdfDocument) {
149
+ entry.push({ resource: buildDocumentReferenceResource(draft, draft.pdfDocument) });
150
+ }
151
+ if (draft.structuredDocument) {
152
+ entry.push({ resource: buildDocumentReferenceResource(draft, draft.structuredDocument) });
153
+ }
154
+ return {
155
+ resourceType: ResourceTypesFhirR4.Bundle,
156
+ type: 'collection',
157
+ entry,
158
+ };
159
+ }
160
+ export function extractInvoiceBundleFromResponseBody(body) {
161
+ const root = asRecord(body) || {};
162
+ const bodyNode = asRecord(root.body) || root;
163
+ const data = Array.isArray(bodyNode.data) ? bodyNode.data : [];
164
+ for (const candidate of data) {
165
+ const entry = asRecord(candidate) || {};
166
+ const resource = asRecord(entry.resource);
167
+ if (!resource || resource.resourceType !== ResourceTypesFhirR4.Bundle)
168
+ continue;
169
+ const bundleEntries = Array.isArray(resource.entry) ? resource.entry : [];
170
+ const hasInvoice = bundleEntries.some((bundleEntry) => {
171
+ const nested = asRecord(bundleEntry);
172
+ const nestedResource = asRecord(nested?.resource);
173
+ return nestedResource?.resourceType === ResourceTypesFhirR4.Invoice;
174
+ });
175
+ if (hasInvoice)
176
+ return resource;
177
+ }
178
+ return undefined;
179
+ }
180
+ export function readInvoiceBundleSummaryFromResponseBody(body) {
181
+ const bundle = extractInvoiceBundleFromResponseBody(body);
182
+ const entries = Array.isArray(bundle?.entry) ? bundle.entry : [];
183
+ const invoice = entries
184
+ .map((entry) => asRecord(entry)?.resource)
185
+ .map((resource) => asRecord(resource))
186
+ .find((resource) => resource?.resourceType === ResourceTypesFhirR4.Invoice);
187
+ const documents = entries
188
+ .map((entry) => asRecord(entry)?.resource)
189
+ .map((resource) => asRecord(resource))
190
+ .filter((resource) => resource?.resourceType === ResourceTypesFhirR4.DocumentReference);
191
+ const pdf = documents.find((resource) => {
192
+ const content = Array.isArray(resource?.content) ? resource.content : [];
193
+ const attachment = asRecord(asRecord(content[0])?.attachment);
194
+ return String(attachment?.contentType || '').trim() === 'application/pdf';
195
+ });
196
+ const structured = documents.find((resource) => resource !== pdf);
197
+ return {
198
+ invoiceId: normalizeText(asRecord((Array.isArray(invoice?.identifier) ? invoice?.identifier[0] : undefined))?.value
199
+ || invoice?.id),
200
+ amount: normalizeText(asRecord(invoice?.totalGross)?.value),
201
+ currency: normalizeText(asRecord(invoice?.totalGross)?.currency),
202
+ paymentMethod: normalizeText(invoice?.paymentTerms),
203
+ paymentUrl: normalizeText(asRecord(Array.isArray(invoice?.note) ? invoice.note[0] : undefined)?.text),
204
+ pdfDocumentId: normalizeText(pdf?.id),
205
+ structuredDocumentId: normalizeText(structured?.id),
206
+ };
207
+ }
208
+ export function createInvoiceBundleEditor(initial) {
209
+ let draft = cloneDraft(initial);
210
+ const editor = {
211
+ setInvoiceId(value) { draft = cloneDraft({ ...draft, invoiceId: value }); return editor; },
212
+ setSubjectReference(value) { draft = cloneDraft({ ...draft, subjectReference: value }); return editor; },
213
+ setIssuerReference(value) { draft = cloneDraft({ ...draft, issuerReference: value }); return editor; },
214
+ setIssuerDisplay(value) { draft = cloneDraft({ ...draft, issuerDisplay: value }); return editor; },
215
+ setRecipientReference(value) { draft = cloneDraft({ ...draft, recipientReference: value }); return editor; },
216
+ setIssuedAt(value) { draft = cloneDraft({ ...draft, issuedAt: value }); return editor; },
217
+ setAmount(value) { draft = cloneDraft({ ...draft, amount: value }); return editor; },
218
+ setCurrency(value) { draft = cloneDraft({ ...draft, currency: value }); return editor; },
219
+ setPaymentMethod(value) { draft = cloneDraft({ ...draft, paymentMethod: value }); return editor; },
220
+ setPaymentUrl(value) { draft = cloneDraft({ ...draft, paymentUrl: value }); return editor; },
221
+ setPdfDocument(value) { draft = cloneDraft({ ...draft, pdfDocument: value }); return editor; },
222
+ setStructuredDocument(value) { draft = cloneDraft({ ...draft, structuredDocument: value }); return editor; },
223
+ setChargeItems(value) { draft = cloneDraft({ ...draft, chargeItems: value }); return editor; },
224
+ addChargeItem(value) { draft = cloneDraft({ ...draft, chargeItems: [...(draft.chargeItems || []), value] }); return editor; },
225
+ getDraft() { return cloneDraft(draft); },
226
+ buildBundle() { return buildInvoiceBundle(draft); },
227
+ buildInvoiceClaims() { return buildInvoiceFhirClaims(draft); },
228
+ buildInvoiceClaimsContextualized() { return contextualizeInvoiceClaims(buildInvoiceFhirClaims(draft)); },
229
+ buildChargeItemClaimRows() { return buildInvoiceChargeItemClaimRows(draft); },
230
+ buildChargeItemClaimRowsContextualized() {
231
+ return buildInvoiceChargeItemClaimRows(draft).map((row) => ({
232
+ ...contextualizeInvoiceClaims(row),
233
+ ...contextualizeChargeItemClaims(row),
234
+ }));
235
+ },
236
+ getSummary() { return readInvoiceBundleSummaryFromResponseBody({ data: [{ resource: buildInvoiceBundle(draft) }] }); },
237
+ readBundleFromResponseBody(body) { return extractInvoiceBundleFromResponseBody(body); },
238
+ };
239
+ return editor;
240
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gdc-common-utils-ts",
3
- "version": "1.21.0",
3
+ "version": "1.23.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -10,7 +10,7 @@
10
10
  "@stablelib/base64": "^1.0.1",
11
11
  "@stablelib/utf8": "^1.0.2",
12
12
  "base-x": "^4.0.0",
13
- "gdc-common-utils-ts": "^1.21.0",
13
+ "gdc-common-utils-ts": "^1.23.0",
14
14
  "pako": "^2.1.0"
15
15
  },
16
16
  "scripts": {