vet-data-utils-ts 0.5.21 → 0.5.22
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/README.md +16 -4
- package/dist/place-service-directory.d.ts +191 -2
- package/dist/place-service-directory.js +221 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,12 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
The product-local `place-service-directory` export models persistent public
|
|
4
4
|
sites as claims-only Schema.org `Place` resources and their offerings as
|
|
5
|
-
claims-only `Service` resources.
|
|
6
|
-
|
|
7
|
-
`
|
|
8
|
-
|
|
5
|
+
claims-only `Service` or `Product` resources. A care organization publishes
|
|
6
|
+
services; an insurance organization publishes products in a Schema.org
|
|
7
|
+
`OfferCatalog`. Photos, accessibility, coordinates, address and opening-hours
|
|
8
|
+
specifications remain neutral indexed claims. Native FHIR R5 `Location`,
|
|
9
|
+
`HealthcareService` and `InsurancePlan` are produced only by explicit
|
|
10
|
+
projection helpers. Member-specific FHIR `Coverage` is never a public catalog
|
|
11
|
+
entry. The shared `gdc-*` claim catalog remains unchanged while this profile is
|
|
9
12
|
validated in VetChain.
|
|
10
13
|
|
|
14
|
+
The customer-facing Schema.org `OfferCatalog` is distinct from the Eclipse
|
|
15
|
+
Dataspace Protocol catalog. `buildDataspaceCatalogAdvertisement(...)` exposes a
|
|
16
|
+
transferable catalog snapshot as a DSP 2025-1 Dataset with an ODRL use Offer;
|
|
17
|
+
`buildDataspaceDataAddress(...)` describes the endpoint only in the negotiated
|
|
18
|
+
transfer flow. The package deliberately has no third-party DSP runtime
|
|
19
|
+
dependency: the Eclipse project publishes the specification and Java TCK/EDC
|
|
20
|
+
implementation, while currently available npm implementations are independent
|
|
21
|
+
projects and are not adopted implicitly.
|
|
22
|
+
|
|
11
23
|
## Veterinary immunization credentials
|
|
12
24
|
|
|
13
25
|
`buildVeterinaryImmunization(...)` creates a FHIR R4 `Immunization` with the
|
|
@@ -33,10 +33,31 @@ export declare enum ClaimsDirectoryServiceSchemaorg {
|
|
|
33
33
|
areaServed = "org.schema.Service.areaServed",
|
|
34
34
|
userSelected = "Service.user-selected"
|
|
35
35
|
}
|
|
36
|
-
/** Product
|
|
36
|
+
/** Schema.org Product claims for an organization's public commercial offering. */
|
|
37
|
+
export declare enum ClaimsProductSchemaorg {
|
|
38
|
+
identifier = "org.schema.Product.identifier",
|
|
39
|
+
additionalType = "org.schema.Product.additionalType",
|
|
40
|
+
name = "org.schema.Product.name",
|
|
41
|
+
description = "org.schema.Product.description",
|
|
42
|
+
providerIdentifier = "org.schema.Product.provider.identifier",
|
|
43
|
+
category = "org.schema.Product.category",
|
|
44
|
+
areaServed = "org.schema.Product.areaServed",
|
|
45
|
+
url = "org.schema.Product.url",
|
|
46
|
+
imageContentUrl = "org.schema.Product.image.contentUrl",
|
|
47
|
+
availabilityStarts = "org.schema.Product.offers.availabilityStarts",
|
|
48
|
+
availabilityEnds = "org.schema.Product.offers.availabilityEnds",
|
|
49
|
+
price = "org.schema.Product.offers.price",
|
|
50
|
+
priceCurrency = "org.schema.Product.offers.priceCurrency",
|
|
51
|
+
insuranceStatus = "org.schema.Product.additionalProperty.insuranceStatus",
|
|
52
|
+
insuranceCoverageType = "org.schema.Product.additionalProperty.insuranceCoverageType",
|
|
53
|
+
insuranceNetwork = "org.schema.Product.additionalProperty.insuranceNetwork",
|
|
54
|
+
userSelected = "Product.user-selected"
|
|
55
|
+
}
|
|
56
|
+
/** Product-local allowlist for the experimental Place, Service and Product directory profile. */
|
|
37
57
|
export declare const DirectoryFlatClaimCatalog: Readonly<{
|
|
38
58
|
readonly Place: readonly ClaimsPlaceSchemaorg[];
|
|
39
59
|
readonly Service: readonly ClaimsDirectoryServiceSchemaorg[];
|
|
60
|
+
readonly Product: readonly ClaimsProductSchemaorg[];
|
|
40
61
|
}>;
|
|
41
62
|
export type DirectoryResourceType = keyof typeof DirectoryFlatClaimCatalog;
|
|
42
63
|
export type DirectoryClaimValue = string | number | boolean | readonly string[];
|
|
@@ -105,11 +126,45 @@ export type ServiceDirectoryInput = Readonly<{
|
|
|
105
126
|
areaServed?: readonly string[];
|
|
106
127
|
userSelected?: boolean;
|
|
107
128
|
}>;
|
|
129
|
+
export type ProductDirectoryInput = Readonly<{
|
|
130
|
+
id: string;
|
|
131
|
+
organizationIdentifier: string;
|
|
132
|
+
name: string;
|
|
133
|
+
description?: string;
|
|
134
|
+
productType: string;
|
|
135
|
+
categories?: readonly string[];
|
|
136
|
+
areaServed?: readonly string[];
|
|
137
|
+
url?: string;
|
|
138
|
+
imageUrl?: string;
|
|
139
|
+
availableFrom?: string;
|
|
140
|
+
availableThrough?: string;
|
|
141
|
+
price?: number;
|
|
142
|
+
priceCurrency?: string;
|
|
143
|
+
insurance?: Readonly<{
|
|
144
|
+
status: 'draft' | 'active' | 'retired' | 'unknown';
|
|
145
|
+
coverageTypes: readonly string[];
|
|
146
|
+
networks?: readonly string[];
|
|
147
|
+
}>;
|
|
148
|
+
userSelected?: boolean;
|
|
149
|
+
}>;
|
|
150
|
+
/** Sector-owned offering kind. It drives presentation only and grants no authority. */
|
|
151
|
+
export declare const OrganizationOfferingKinds: Readonly<{
|
|
152
|
+
readonly 'animal-care': "Service";
|
|
153
|
+
readonly 'animal-insurance': "Product";
|
|
154
|
+
}>;
|
|
155
|
+
/** Stable Eclipse Dataspace Protocol 2025-1 identifiers, including current editorial errata. */
|
|
156
|
+
export declare const DataspaceProtocol2025: Readonly<{
|
|
157
|
+
readonly release: "2025-1-err1";
|
|
158
|
+
readonly context: "https://w3id.org/dspace/2025/1/context.jsonld";
|
|
159
|
+
readonly httpEndpointType: "https://w3id.org/idsa/v4.1/HTTP";
|
|
160
|
+
}>;
|
|
108
161
|
/** Builds the claims-only public Place authored by an organization. */
|
|
109
162
|
export declare function buildPlaceDirectoryResource(input: PlaceDirectoryInput): DirectoryResource;
|
|
110
163
|
/** Builds a claims-only Schema.org Service joined to its provider and public Places. */
|
|
111
164
|
export declare function buildServiceDirectoryResource(input: ServiceDirectoryInput): DirectoryResource;
|
|
112
|
-
/**
|
|
165
|
+
/** Builds a claims-only Schema.org Product; insurance details remain a public plan definition, not personal Coverage. */
|
|
166
|
+
export declare function buildProductDirectoryResource(input: ProductDirectoryInput): DirectoryResource;
|
|
167
|
+
/** Rejects native fields and converts a directory resource into deterministic array-valued claims. */
|
|
113
168
|
export declare function normalizeDirectoryFlatClaimsResource(input: unknown): DirectoryFlatClaimsResource;
|
|
114
169
|
/** Explicitly projects one neutral Place to native FHIR R5 Location for export or interop. */
|
|
115
170
|
export declare function projectPlaceToFhirR5Location(place: DirectoryResource | DirectoryFlatClaimsResource): Readonly<{
|
|
@@ -204,6 +259,140 @@ export declare function projectServiceToFhirR5HealthcareService(service: Directo
|
|
|
204
259
|
reference: string;
|
|
205
260
|
}[];
|
|
206
261
|
}>;
|
|
262
|
+
/** Explicitly projects a public insurance Product definition to FHIR R5 InsurancePlan. */
|
|
263
|
+
export declare function projectProductToFhirR5InsurancePlan(product: DirectoryResource | DirectoryFlatClaimsResource): Readonly<{
|
|
264
|
+
ownedBy: {
|
|
265
|
+
reference: string;
|
|
266
|
+
};
|
|
267
|
+
coverageArea: {
|
|
268
|
+
reference: string;
|
|
269
|
+
}[];
|
|
270
|
+
network: {
|
|
271
|
+
reference: string;
|
|
272
|
+
}[];
|
|
273
|
+
coverage: {
|
|
274
|
+
type: {
|
|
275
|
+
coding: {
|
|
276
|
+
code: string;
|
|
277
|
+
}[];
|
|
278
|
+
};
|
|
279
|
+
network: {
|
|
280
|
+
reference: string;
|
|
281
|
+
}[];
|
|
282
|
+
benefit: {
|
|
283
|
+
type: {
|
|
284
|
+
coding: {
|
|
285
|
+
code: string;
|
|
286
|
+
}[];
|
|
287
|
+
};
|
|
288
|
+
}[];
|
|
289
|
+
}[];
|
|
290
|
+
meta: {
|
|
291
|
+
claims: {
|
|
292
|
+
'InsurancePlan.identifier': string;
|
|
293
|
+
'InsurancePlan.status': string;
|
|
294
|
+
'InsurancePlan.name': string;
|
|
295
|
+
'InsurancePlan.owned-by': string;
|
|
296
|
+
'InsurancePlan.type': string;
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
period?: {
|
|
300
|
+
start: string;
|
|
301
|
+
end: string;
|
|
302
|
+
} | undefined;
|
|
303
|
+
resourceType: "InsurancePlan";
|
|
304
|
+
id: string;
|
|
305
|
+
identifier: {
|
|
306
|
+
value: string;
|
|
307
|
+
}[];
|
|
308
|
+
status: string;
|
|
309
|
+
type: {
|
|
310
|
+
coding: {
|
|
311
|
+
code: string;
|
|
312
|
+
}[];
|
|
313
|
+
}[];
|
|
314
|
+
name: string;
|
|
315
|
+
}>;
|
|
316
|
+
/** Builds the Schema.org JSON-LD OfferCatalog presented by one organization. */
|
|
317
|
+
export declare function buildOrganizationOfferCatalog(input: Readonly<{
|
|
318
|
+
id: string;
|
|
319
|
+
name: string;
|
|
320
|
+
organizationIdentifier: string;
|
|
321
|
+
sector: keyof typeof OrganizationOfferingKinds;
|
|
322
|
+
offerings: readonly (DirectoryResource | DirectoryFlatClaimsResource)[];
|
|
323
|
+
}>): Readonly<{
|
|
324
|
+
'@context': "https://schema.org";
|
|
325
|
+
'@type': "OfferCatalog";
|
|
326
|
+
identifier: string;
|
|
327
|
+
name: string;
|
|
328
|
+
offeredBy: Readonly<{
|
|
329
|
+
'@type': "Organization";
|
|
330
|
+
identifier: string;
|
|
331
|
+
}>;
|
|
332
|
+
numberOfItems: number;
|
|
333
|
+
itemListElement: readonly Readonly<{
|
|
334
|
+
'@type': "Offer";
|
|
335
|
+
itemOffered: Readonly<{
|
|
336
|
+
'@type': "Service" | "Product";
|
|
337
|
+
identifier: string;
|
|
338
|
+
name: string;
|
|
339
|
+
}>;
|
|
340
|
+
}>[];
|
|
341
|
+
}>;
|
|
342
|
+
/** Advertises a transferable catalog snapshot as a DSP Dataset with an ODRL use Offer. */
|
|
343
|
+
export declare function buildDataspaceCatalogAdvertisement(input: Readonly<{
|
|
344
|
+
catalogId: string;
|
|
345
|
+
participantId: string;
|
|
346
|
+
dataServiceId: string;
|
|
347
|
+
endpointUrl: string;
|
|
348
|
+
datasetId: string;
|
|
349
|
+
policyId: string;
|
|
350
|
+
distributionFormat: string;
|
|
351
|
+
}>): Readonly<{
|
|
352
|
+
'@context': readonly "https://w3id.org/dspace/2025/1/context.jsonld"[];
|
|
353
|
+
'@id': string;
|
|
354
|
+
'@type': "Catalog";
|
|
355
|
+
participantId: string;
|
|
356
|
+
service: readonly Readonly<{
|
|
357
|
+
'@id': string;
|
|
358
|
+
'@type': "DataService";
|
|
359
|
+
endpointURL: string;
|
|
360
|
+
}>[];
|
|
361
|
+
dataset: readonly Readonly<{
|
|
362
|
+
'@id': string;
|
|
363
|
+
'@type': "Dataset";
|
|
364
|
+
hasPolicy: readonly Readonly<{
|
|
365
|
+
'@id': string;
|
|
366
|
+
'@type': "Offer";
|
|
367
|
+
permission: readonly Readonly<{
|
|
368
|
+
action: "use";
|
|
369
|
+
}>[];
|
|
370
|
+
}>[];
|
|
371
|
+
distribution: readonly Readonly<{
|
|
372
|
+
'@type': "Distribution";
|
|
373
|
+
format: string;
|
|
374
|
+
accessService: string;
|
|
375
|
+
}>[];
|
|
376
|
+
}>[];
|
|
377
|
+
}>;
|
|
378
|
+
/** Builds the DSP DataAddress exchanged only after agreement negotiation starts a transfer. */
|
|
379
|
+
export declare function buildDataspaceDataAddress(input: Readonly<{
|
|
380
|
+
endpointType: string;
|
|
381
|
+
endpoint?: string;
|
|
382
|
+
endpointProperties?: readonly Readonly<{
|
|
383
|
+
name: string;
|
|
384
|
+
value: string;
|
|
385
|
+
}>[];
|
|
386
|
+
}>): Readonly<{
|
|
387
|
+
endpointProperties?: readonly Readonly<{
|
|
388
|
+
'@type': "EndpointProperty";
|
|
389
|
+
name: string;
|
|
390
|
+
value: string;
|
|
391
|
+
}>[] | undefined;
|
|
392
|
+
endpoint?: string | undefined;
|
|
393
|
+
'@type': "DataAddress";
|
|
394
|
+
endpointType: string;
|
|
395
|
+
}>;
|
|
207
396
|
export type ClinicMarketplaceResult = Readonly<{
|
|
208
397
|
place: DirectoryResource | DirectoryFlatClaimsResource;
|
|
209
398
|
services: readonly (DirectoryResource | DirectoryFlatClaimsResource)[];
|
|
@@ -36,10 +36,43 @@ export var ClaimsDirectoryServiceSchemaorg;
|
|
|
36
36
|
ClaimsDirectoryServiceSchemaorg["areaServed"] = "org.schema.Service.areaServed";
|
|
37
37
|
ClaimsDirectoryServiceSchemaorg["userSelected"] = "Service.user-selected";
|
|
38
38
|
})(ClaimsDirectoryServiceSchemaorg || (ClaimsDirectoryServiceSchemaorg = {}));
|
|
39
|
-
/** Product
|
|
39
|
+
/** Schema.org Product claims for an organization's public commercial offering. */
|
|
40
|
+
export var ClaimsProductSchemaorg;
|
|
41
|
+
(function (ClaimsProductSchemaorg) {
|
|
42
|
+
ClaimsProductSchemaorg["identifier"] = "org.schema.Product.identifier";
|
|
43
|
+
ClaimsProductSchemaorg["additionalType"] = "org.schema.Product.additionalType";
|
|
44
|
+
ClaimsProductSchemaorg["name"] = "org.schema.Product.name";
|
|
45
|
+
ClaimsProductSchemaorg["description"] = "org.schema.Product.description";
|
|
46
|
+
ClaimsProductSchemaorg["providerIdentifier"] = "org.schema.Product.provider.identifier";
|
|
47
|
+
ClaimsProductSchemaorg["category"] = "org.schema.Product.category";
|
|
48
|
+
ClaimsProductSchemaorg["areaServed"] = "org.schema.Product.areaServed";
|
|
49
|
+
ClaimsProductSchemaorg["url"] = "org.schema.Product.url";
|
|
50
|
+
ClaimsProductSchemaorg["imageContentUrl"] = "org.schema.Product.image.contentUrl";
|
|
51
|
+
ClaimsProductSchemaorg["availabilityStarts"] = "org.schema.Product.offers.availabilityStarts";
|
|
52
|
+
ClaimsProductSchemaorg["availabilityEnds"] = "org.schema.Product.offers.availabilityEnds";
|
|
53
|
+
ClaimsProductSchemaorg["price"] = "org.schema.Product.offers.price";
|
|
54
|
+
ClaimsProductSchemaorg["priceCurrency"] = "org.schema.Product.offers.priceCurrency";
|
|
55
|
+
ClaimsProductSchemaorg["insuranceStatus"] = "org.schema.Product.additionalProperty.insuranceStatus";
|
|
56
|
+
ClaimsProductSchemaorg["insuranceCoverageType"] = "org.schema.Product.additionalProperty.insuranceCoverageType";
|
|
57
|
+
ClaimsProductSchemaorg["insuranceNetwork"] = "org.schema.Product.additionalProperty.insuranceNetwork";
|
|
58
|
+
ClaimsProductSchemaorg["userSelected"] = "Product.user-selected";
|
|
59
|
+
})(ClaimsProductSchemaorg || (ClaimsProductSchemaorg = {}));
|
|
60
|
+
/** Product-local allowlist for the experimental Place, Service and Product directory profile. */
|
|
40
61
|
export const DirectoryFlatClaimCatalog = Object.freeze({
|
|
41
62
|
Place: Object.freeze(Object.values(ClaimsPlaceSchemaorg)),
|
|
42
63
|
Service: Object.freeze(Object.values(ClaimsDirectoryServiceSchemaorg)),
|
|
64
|
+
Product: Object.freeze(Object.values(ClaimsProductSchemaorg)),
|
|
65
|
+
});
|
|
66
|
+
/** Sector-owned offering kind. It drives presentation only and grants no authority. */
|
|
67
|
+
export const OrganizationOfferingKinds = Object.freeze({
|
|
68
|
+
'animal-care': 'Service',
|
|
69
|
+
'animal-insurance': 'Product',
|
|
70
|
+
});
|
|
71
|
+
/** Stable Eclipse Dataspace Protocol 2025-1 identifiers, including current editorial errata. */
|
|
72
|
+
export const DataspaceProtocol2025 = Object.freeze({
|
|
73
|
+
release: '2025-1-err1',
|
|
74
|
+
context: 'https://w3id.org/dspace/2025/1/context.jsonld',
|
|
75
|
+
httpEndpointType: 'https://w3id.org/idsa/v4.1/HTTP',
|
|
43
76
|
});
|
|
44
77
|
const RESOURCE_ID_PATTERN = /^[A-Za-z0-9\-.]{1,64}$/;
|
|
45
78
|
const TIME_PATTERN = /^(?:[01]\d|2[0-3]):[0-5]\d$/;
|
|
@@ -55,6 +88,20 @@ function optional(value) {
|
|
|
55
88
|
const normalized = String(value ?? '').trim();
|
|
56
89
|
return normalized || undefined;
|
|
57
90
|
}
|
|
91
|
+
function optionalHttpsUrl(value, code) {
|
|
92
|
+
const normalized = optional(value);
|
|
93
|
+
if (!normalized)
|
|
94
|
+
return undefined;
|
|
95
|
+
try {
|
|
96
|
+
const parsed = new URL(normalized);
|
|
97
|
+
if (parsed.protocol !== 'https:')
|
|
98
|
+
throw new Error();
|
|
99
|
+
return parsed.toString();
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
throw new TypeError(code);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
58
105
|
function unique(values, code) {
|
|
59
106
|
const result = [...new Set((values ?? []).map(value => required(value, code)))];
|
|
60
107
|
return Object.freeze(result);
|
|
@@ -184,12 +231,71 @@ export function buildServiceDirectoryResource(input) {
|
|
|
184
231
|
claims[ClaimsDirectoryServiceSchemaorg.areaServed] = areaServed;
|
|
185
232
|
return Object.freeze({ resourceType: 'Service', id, meta: Object.freeze({ claims: Object.freeze(claims) }) });
|
|
186
233
|
}
|
|
187
|
-
/**
|
|
234
|
+
/** Builds a claims-only Schema.org Product; insurance details remain a public plan definition, not personal Coverage. */
|
|
235
|
+
export function buildProductDirectoryResource(input) {
|
|
236
|
+
const id = required(input.id, 'product_id_required');
|
|
237
|
+
if (!RESOURCE_ID_PATTERN.test(id))
|
|
238
|
+
throw new TypeError('product_id_invalid');
|
|
239
|
+
const productType = required(input.productType, 'product_type_required');
|
|
240
|
+
const categories = unique(input.categories, 'product_category_invalid');
|
|
241
|
+
const areaServed = unique(input.areaServed, 'product_area_invalid');
|
|
242
|
+
const url = optionalHttpsUrl(input.url, 'product_url_invalid');
|
|
243
|
+
const imageUrl = optionalHttpsUrl(input.imageUrl, 'product_image_url_invalid');
|
|
244
|
+
const availableFrom = input.availableFrom ? assertDate(input.availableFrom, 'product_period_invalid') : undefined;
|
|
245
|
+
const availableThrough = input.availableThrough ? assertDate(input.availableThrough, 'product_period_invalid') : undefined;
|
|
246
|
+
if (Boolean(availableFrom) !== Boolean(availableThrough) || (availableFrom && availableThrough && availableFrom > availableThrough))
|
|
247
|
+
throw new TypeError('product_period_invalid');
|
|
248
|
+
if (input.price !== undefined && (!Number.isFinite(input.price) || input.price < 0))
|
|
249
|
+
throw new TypeError('product_price_invalid');
|
|
250
|
+
const priceCurrency = optional(input.priceCurrency)?.toUpperCase();
|
|
251
|
+
if ((input.price === undefined) !== (priceCurrency === undefined) || (priceCurrency && !/^[A-Z]{3}$/.test(priceCurrency)))
|
|
252
|
+
throw new TypeError('product_price_invalid');
|
|
253
|
+
if (productType === 'insurance-plan' && !input.insurance)
|
|
254
|
+
throw new TypeError('insurance_product_profile_required');
|
|
255
|
+
const coverageTypes = unique(input.insurance?.coverageTypes, 'insurance_coverage_type_invalid');
|
|
256
|
+
if (input.insurance && !coverageTypes.length)
|
|
257
|
+
throw new TypeError('insurance_coverage_type_invalid');
|
|
258
|
+
const networks = unique(input.insurance?.networks, 'insurance_network_invalid');
|
|
259
|
+
const claims = {
|
|
260
|
+
[ClaimsProductSchemaorg.identifier]: id,
|
|
261
|
+
[ClaimsProductSchemaorg.providerIdentifier]: required(input.organizationIdentifier, 'product_organization_required'),
|
|
262
|
+
[ClaimsProductSchemaorg.name]: required(input.name, 'product_name_required'),
|
|
263
|
+
[ClaimsProductSchemaorg.additionalType]: productType,
|
|
264
|
+
[ClaimsProductSchemaorg.userSelected]: input.userSelected ?? false,
|
|
265
|
+
};
|
|
266
|
+
const description = optional(input.description);
|
|
267
|
+
if (description)
|
|
268
|
+
claims[ClaimsProductSchemaorg.description] = description;
|
|
269
|
+
if (categories.length)
|
|
270
|
+
claims[ClaimsProductSchemaorg.category] = categories;
|
|
271
|
+
if (areaServed.length)
|
|
272
|
+
claims[ClaimsProductSchemaorg.areaServed] = areaServed;
|
|
273
|
+
if (url)
|
|
274
|
+
claims[ClaimsProductSchemaorg.url] = url;
|
|
275
|
+
if (imageUrl)
|
|
276
|
+
claims[ClaimsProductSchemaorg.imageContentUrl] = imageUrl;
|
|
277
|
+
if (availableFrom)
|
|
278
|
+
claims[ClaimsProductSchemaorg.availabilityStarts] = availableFrom;
|
|
279
|
+
if (availableThrough)
|
|
280
|
+
claims[ClaimsProductSchemaorg.availabilityEnds] = availableThrough;
|
|
281
|
+
if (input.price !== undefined)
|
|
282
|
+
claims[ClaimsProductSchemaorg.price] = input.price;
|
|
283
|
+
if (priceCurrency)
|
|
284
|
+
claims[ClaimsProductSchemaorg.priceCurrency] = priceCurrency;
|
|
285
|
+
if (input.insurance)
|
|
286
|
+
claims[ClaimsProductSchemaorg.insuranceStatus] = input.insurance.status;
|
|
287
|
+
if (coverageTypes.length)
|
|
288
|
+
claims[ClaimsProductSchemaorg.insuranceCoverageType] = coverageTypes;
|
|
289
|
+
if (networks.length)
|
|
290
|
+
claims[ClaimsProductSchemaorg.insuranceNetwork] = networks;
|
|
291
|
+
return Object.freeze({ resourceType: 'Product', id, meta: Object.freeze({ claims: Object.freeze(claims) }) });
|
|
292
|
+
}
|
|
293
|
+
/** Rejects native fields and converts a directory resource into deterministic array-valued claims. */
|
|
188
294
|
export function normalizeDirectoryFlatClaimsResource(input) {
|
|
189
295
|
if (!input || typeof input !== 'object' || Array.isArray(input))
|
|
190
296
|
throw new TypeError('directory_flat_resource_invalid');
|
|
191
297
|
const value = input;
|
|
192
|
-
if ((value.resourceType !== 'Place' && value.resourceType !== 'Service') || Object.keys(value).some(key => !['resourceType', 'id', 'meta'].includes(key)))
|
|
298
|
+
if ((value.resourceType !== 'Place' && value.resourceType !== 'Service' && value.resourceType !== 'Product') || Object.keys(value).some(key => !['resourceType', 'id', 'meta'].includes(key)))
|
|
193
299
|
throw new TypeError('directory_flat_resource_invalid');
|
|
194
300
|
const resourceType = value.resourceType;
|
|
195
301
|
const id = required(value.id, 'directory_flat_resource_invalid');
|
|
@@ -292,6 +398,118 @@ export function projectServiceToFhirR5HealthcareService(service, input) {
|
|
|
292
398
|
} },
|
|
293
399
|
});
|
|
294
400
|
}
|
|
401
|
+
/** Explicitly projects a public insurance Product definition to FHIR R5 InsurancePlan. */
|
|
402
|
+
export function projectProductToFhirR5InsurancePlan(product) {
|
|
403
|
+
if (product.resourceType !== 'Product')
|
|
404
|
+
throw new TypeError('product_resource_required');
|
|
405
|
+
if (first(product, ClaimsProductSchemaorg.additionalType) !== 'insurance-plan')
|
|
406
|
+
throw new TypeError('insurance_product_required');
|
|
407
|
+
const organization = required(first(product, ClaimsProductSchemaorg.providerIdentifier), 'product_organization_required');
|
|
408
|
+
const status = required(first(product, ClaimsProductSchemaorg.insuranceStatus), 'insurance_product_profile_required');
|
|
409
|
+
const coverageTypes = values(product, ClaimsProductSchemaorg.insuranceCoverageType);
|
|
410
|
+
if (!coverageTypes.length)
|
|
411
|
+
throw new TypeError('insurance_coverage_type_invalid');
|
|
412
|
+
const networks = values(product, ClaimsProductSchemaorg.insuranceNetwork);
|
|
413
|
+
const areaServed = values(product, ClaimsProductSchemaorg.areaServed);
|
|
414
|
+
const name = required(first(product, ClaimsProductSchemaorg.name), 'product_name_required');
|
|
415
|
+
const start = first(product, ClaimsProductSchemaorg.availabilityStarts);
|
|
416
|
+
const end = first(product, ClaimsProductSchemaorg.availabilityEnds);
|
|
417
|
+
const concept = (code) => ({ coding: [{ code }] });
|
|
418
|
+
return Object.freeze({
|
|
419
|
+
resourceType: 'InsurancePlan', id: product.id,
|
|
420
|
+
identifier: [{ value: product.id }], status, type: [concept('insurance-plan')], name,
|
|
421
|
+
...(start && end ? { period: { start, end } } : {}),
|
|
422
|
+
ownedBy: { reference: organization },
|
|
423
|
+
coverageArea: areaServed.map(reference => ({ reference })),
|
|
424
|
+
network: networks.map(reference => ({ reference })),
|
|
425
|
+
coverage: coverageTypes.map(type => ({ type: concept(type), network: networks.map(reference => ({ reference })), benefit: [{ type: concept(type) }] })),
|
|
426
|
+
meta: { claims: {
|
|
427
|
+
'InsurancePlan.identifier': product.id,
|
|
428
|
+
'InsurancePlan.status': status,
|
|
429
|
+
'InsurancePlan.name': name,
|
|
430
|
+
'InsurancePlan.owned-by': organization,
|
|
431
|
+
'InsurancePlan.type': 'insurance-plan',
|
|
432
|
+
} },
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
/** Builds the Schema.org JSON-LD OfferCatalog presented by one organization. */
|
|
436
|
+
export function buildOrganizationOfferCatalog(input) {
|
|
437
|
+
const expectedKind = OrganizationOfferingKinds[input.sector];
|
|
438
|
+
const organizationIdentifier = required(input.organizationIdentifier, 'organization_identifier_required');
|
|
439
|
+
const itemListElement = input.offerings.map(offering => {
|
|
440
|
+
if (offering.resourceType !== expectedKind)
|
|
441
|
+
throw new TypeError('organization_offering_kind_invalid');
|
|
442
|
+
const isService = offering.resourceType === 'Service';
|
|
443
|
+
const nameClaim = isService ? ClaimsDirectoryServiceSchemaorg.name : ClaimsProductSchemaorg.name;
|
|
444
|
+
const providerClaim = isService ? ClaimsDirectoryServiceSchemaorg.providerIdentifier : ClaimsProductSchemaorg.providerIdentifier;
|
|
445
|
+
if (first(offering, providerClaim) !== organizationIdentifier)
|
|
446
|
+
throw new TypeError('organization_offering_owner_invalid');
|
|
447
|
+
return Object.freeze({
|
|
448
|
+
'@type': 'Offer',
|
|
449
|
+
itemOffered: Object.freeze({
|
|
450
|
+
'@type': offering.resourceType,
|
|
451
|
+
identifier: offering.id,
|
|
452
|
+
name: required(first(offering, nameClaim), 'organization_offering_name_required'),
|
|
453
|
+
}),
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
return Object.freeze({
|
|
457
|
+
'@context': 'https://schema.org', '@type': 'OfferCatalog',
|
|
458
|
+
identifier: required(input.id, 'organization_catalog_id_required'),
|
|
459
|
+
name: required(input.name, 'organization_catalog_name_required'),
|
|
460
|
+
offeredBy: Object.freeze({ '@type': 'Organization', identifier: organizationIdentifier }),
|
|
461
|
+
numberOfItems: itemListElement.length,
|
|
462
|
+
itemListElement: Object.freeze(itemListElement),
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
/** Advertises a transferable catalog snapshot as a DSP Dataset with an ODRL use Offer. */
|
|
466
|
+
export function buildDataspaceCatalogAdvertisement(input) {
|
|
467
|
+
const endpointURL = optionalHttpsUrl(input.endpointUrl, 'dataspace_endpoint_url_invalid');
|
|
468
|
+
if (!endpointURL)
|
|
469
|
+
throw new TypeError('dataspace_endpoint_url_invalid');
|
|
470
|
+
const dataServiceId = required(input.dataServiceId, 'dataspace_data_service_id_required');
|
|
471
|
+
const datasetId = required(input.datasetId, 'dataspace_dataset_id_required');
|
|
472
|
+
const service = Object.freeze({ '@id': dataServiceId, '@type': 'DataService', endpointURL });
|
|
473
|
+
const dataset = Object.freeze({
|
|
474
|
+
'@id': datasetId,
|
|
475
|
+
'@type': 'Dataset',
|
|
476
|
+
hasPolicy: Object.freeze([Object.freeze({
|
|
477
|
+
'@id': required(input.policyId, 'dataspace_policy_id_required'),
|
|
478
|
+
'@type': 'Offer',
|
|
479
|
+
permission: Object.freeze([Object.freeze({ action: 'use' })]),
|
|
480
|
+
})]),
|
|
481
|
+
distribution: Object.freeze([Object.freeze({
|
|
482
|
+
'@type': 'Distribution',
|
|
483
|
+
format: required(input.distributionFormat, 'dataspace_distribution_format_required'),
|
|
484
|
+
accessService: dataServiceId,
|
|
485
|
+
})]),
|
|
486
|
+
});
|
|
487
|
+
return Object.freeze({
|
|
488
|
+
'@context': Object.freeze([DataspaceProtocol2025.context]),
|
|
489
|
+
'@id': required(input.catalogId, 'dataspace_catalog_id_required'),
|
|
490
|
+
'@type': 'Catalog',
|
|
491
|
+
participantId: required(input.participantId, 'dataspace_participant_id_required'),
|
|
492
|
+
service: Object.freeze([service]),
|
|
493
|
+
dataset: Object.freeze([dataset]),
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
/** Builds the DSP DataAddress exchanged only after agreement negotiation starts a transfer. */
|
|
497
|
+
export function buildDataspaceDataAddress(input) {
|
|
498
|
+
const endpointType = required(input.endpointType, 'dataspace_data_address_invalid');
|
|
499
|
+
if (!endpointType.startsWith('https://'))
|
|
500
|
+
throw new TypeError('dataspace_data_address_invalid');
|
|
501
|
+
const endpoint = optionalHttpsUrl(input.endpoint, 'dataspace_data_address_invalid');
|
|
502
|
+
const endpointProperties = (input.endpointProperties ?? []).map(property => Object.freeze({
|
|
503
|
+
'@type': 'EndpointProperty',
|
|
504
|
+
name: required(property.name, 'dataspace_data_address_invalid'),
|
|
505
|
+
value: required(property.value, 'dataspace_data_address_invalid'),
|
|
506
|
+
}));
|
|
507
|
+
return Object.freeze({
|
|
508
|
+
'@type': 'DataAddress', endpointType,
|
|
509
|
+
...(endpoint ? { endpoint } : {}),
|
|
510
|
+
...(endpointProperties.length ? { endpointProperties: Object.freeze(endpointProperties) } : {}),
|
|
511
|
+
});
|
|
512
|
+
}
|
|
295
513
|
function normalizedPostal(value) { return value.replace(/[^A-Za-z0-9]/g, '').toUpperCase(); }
|
|
296
514
|
function distanceKm(left, right) {
|
|
297
515
|
const radians = (value) => value * Math.PI / 180;
|