vet-sdk-core-ts 0.4.22 → 0.4.24

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 CHANGED
@@ -9,6 +9,15 @@ UHC SDK packages and must not import them.
9
9
  The SDK consumes governed browser-safe values from `vet-data-utils-ts` and
10
10
  owns gateway request construction. GW VET remains the policy authority.
11
11
 
12
+ ## Veterinary scheduling bundles
13
+
14
+ The `vet-sdk-core-ts/scheduling` entrypoint extends the generic GW bundle
15
+ boundary without changing `gdc-*`. It builds claims-first JSON:API batches,
16
+ reads canonical `body.data[].resource` search matches and reconciles removed
17
+ occupied Slots as pending Appointments plus durable rescheduling
18
+ Communications. The same product extension can later be promoted for SOSChain
19
+ or UHC/UNID after their resource policy is defined.
20
+
12
21
  ## Veterinary health-card issuance
13
22
 
14
23
  `issueVeterinaryHealthCardCredential(...)` accepts only an authoritative
package/dist/index.d.ts CHANGED
@@ -7,4 +7,5 @@ export * from "./reusable-bff.js";
7
7
  export * from "./research-study.js";
8
8
  export * from "./payment.js";
9
9
  export * from "./health-card-issuance.js";
10
+ export * from "./scheduling.js";
10
11
  export * from "vet-data-utils-ts";
package/dist/index.js CHANGED
@@ -7,4 +7,5 @@ export * from "./reusable-bff.js";
7
7
  export * from "./research-study.js";
8
8
  export * from "./payment.js";
9
9
  export * from "./health-card-issuance.js";
10
+ export * from "./scheduling.js";
10
11
  export * from "vet-data-utils-ts";
@@ -0,0 +1,78 @@
1
+ import { type VeterinarySchedulingFlatClaimsResource, type VeterinarySchedulingResourceType } from 'vet-data-utils-ts/scheduling';
2
+ export type VeterinarySchedulingBatchMethod = 'POST' | 'PUT';
3
+ export type VeterinarySchedulingBatch = Readonly<{
4
+ data: readonly Readonly<{
5
+ type: `${VeterinarySchedulingResourceType}-v5.0.0`;
6
+ resource: VeterinarySchedulingFlatClaimsResource;
7
+ request: Readonly<{
8
+ method: VeterinarySchedulingBatchMethod;
9
+ url: string;
10
+ }>;
11
+ }>[];
12
+ }>;
13
+ /**
14
+ * Extends the generic GW JSON:API batch boundary for VetChain scheduling.
15
+ * Resources are revalidated at this product boundary and remain claims-only.
16
+ */
17
+ export declare function buildVeterinarySchedulingBatch(resources: readonly unknown[], method?: VeterinarySchedulingBatchMethod): VeterinarySchedulingBatch;
18
+ /** Builds the governed claims-first search envelope accepted by GW VET. */
19
+ export declare function buildVeterinarySchedulingSearch(resourceType: VeterinarySchedulingResourceType, claims: Readonly<Record<string, unknown>>): Readonly<{
20
+ data: readonly Readonly<{
21
+ resource: Readonly<{
22
+ resourceType: VeterinarySchedulingResourceType;
23
+ id: string;
24
+ meta: Readonly<{
25
+ claims: Readonly<Record<string, readonly string[]>>;
26
+ }>;
27
+ }>;
28
+ }>[];
29
+ }>;
30
+ /** Builds the clinic-wide `_search` envelope for responses recorded inside an inclusive time period. */
31
+ export declare function buildVeterinaryAppointmentResponseSearchPeriod(input: Readonly<{
32
+ from: string;
33
+ to: string;
34
+ }>): Readonly<{
35
+ data: readonly Readonly<{
36
+ resource: Readonly<{
37
+ resourceType: VeterinarySchedulingResourceType;
38
+ id: string;
39
+ meta: Readonly<{
40
+ claims: Readonly<Record<string, readonly string[]>>;
41
+ }>;
42
+ }>;
43
+ }>[];
44
+ }>;
45
+ export type VeterinaryAppointmentResponseEmailPayload = Readonly<{
46
+ to: string;
47
+ subject: string;
48
+ text: string;
49
+ metadata: Readonly<Record<string, string>>;
50
+ }>;
51
+ /** Converts the governed English AppointmentResponse Communication projection into an email-adapter payload. */
52
+ export declare function convertVeterinaryAppointmentResponseCommunicationToEnglishEmail(input: Readonly<{
53
+ recipientEmail: string;
54
+ communication: unknown;
55
+ }>): VeterinaryAppointmentResponseEmailPayload;
56
+ /** Reads canonical GW search matches from `body.data[].resource`. */
57
+ export declare function readVeterinarySchedulingSearch(body: unknown, expectedResourceType: VeterinarySchedulingResourceType): readonly VeterinarySchedulingFlatClaimsResource[];
58
+ export type VeterinaryScheduleReconciliation = Readonly<{
59
+ appointments: readonly VeterinarySchedulingFlatClaimsResource[];
60
+ notifications: readonly Readonly<{
61
+ resourceType: 'Communication';
62
+ id: string;
63
+ meta: Readonly<{
64
+ claims: Readonly<Record<string, readonly string[]>>;
65
+ }>;
66
+ }>[];
67
+ }>;
68
+ /**
69
+ * Produces recoverable updates for bookings whose slots disappeared.
70
+ * It deliberately does not cancel: the patient receives a durable
71
+ * Communication and may choose another slot before a final decline.
72
+ */
73
+ export declare function reconcileVeterinaryAppointmentsAfterSlotChange(input: Readonly<{
74
+ appointments: readonly unknown[];
75
+ availableSlotReferences: ReadonlySet<string>;
76
+ subjectReferenceFor: (appointment: VeterinarySchedulingFlatClaimsResource) => string;
77
+ reason: string;
78
+ }>): VeterinaryScheduleReconciliation;
@@ -0,0 +1,112 @@
1
+ import { buildVeterinaryAppointmentNotificationResource, normalizeVeterinarySchedulingFlatClaimsResource, } from 'vet-data-utils-ts/scheduling';
2
+ const asArrayClaims = (claims) => Object.freeze(Object.fromEntries(Object.entries(claims).map(([name, raw]) => [
3
+ name,
4
+ Object.freeze((Array.isArray(raw) ? raw : [raw]).map(value => String(value))),
5
+ ])));
6
+ /**
7
+ * Extends the generic GW JSON:API batch boundary for VetChain scheduling.
8
+ * Resources are revalidated at this product boundary and remain claims-only.
9
+ */
10
+ export function buildVeterinarySchedulingBatch(resources, method = 'POST') {
11
+ return Object.freeze({
12
+ data: Object.freeze(resources.map(candidate => {
13
+ const resource = normalizeVeterinarySchedulingFlatClaimsResource(candidate);
14
+ return Object.freeze({
15
+ type: `${resource.resourceType}-v5.0.0`,
16
+ resource,
17
+ request: Object.freeze({ method, url: `${resource.resourceType}/${resource.id}` }),
18
+ });
19
+ })),
20
+ });
21
+ }
22
+ /** Builds the governed claims-first search envelope accepted by GW VET. */
23
+ export function buildVeterinarySchedulingSearch(resourceType, claims) {
24
+ const resource = normalizeVeterinarySchedulingFlatClaimsResource({
25
+ resourceType,
26
+ id: 'search',
27
+ meta: { claims },
28
+ });
29
+ return Object.freeze({ data: Object.freeze([Object.freeze({ resource })]) });
30
+ }
31
+ /** Builds the clinic-wide `_search` envelope for responses recorded inside an inclusive time period. */
32
+ export function buildVeterinaryAppointmentResponseSearchPeriod(input) {
33
+ const from = Date.parse(input.from);
34
+ const to = Date.parse(input.to);
35
+ if (!Number.isFinite(from) || !Number.isFinite(to) || from > to)
36
+ throw new Error('appointment_response_search_period_invalid');
37
+ return buildVeterinarySchedulingSearch('AppointmentResponse', {
38
+ 'VeterinaryAppointmentResponse.respondedAt': [`ge${new Date(from).toISOString()}`, `le${new Date(to).toISOString()}`],
39
+ });
40
+ }
41
+ /** Converts the governed English AppointmentResponse Communication projection into an email-adapter payload. */
42
+ export function convertVeterinaryAppointmentResponseCommunicationToEnglishEmail(input) {
43
+ const email = String(input.recipientEmail || '').trim().toLowerCase();
44
+ const resource = input.communication;
45
+ const claims = resource?.resourceType === 'Communication' ? resource?.meta?.claims : undefined;
46
+ const references = Array.isArray(claims?.['Communication.content-reference']) ? claims['Communication.content-reference'].map(String) : [];
47
+ const appointmentResponse = references.find((value) => value.startsWith('AppointmentResponse/'));
48
+ const appointment = references.find((value) => value.startsWith('Appointment/'));
49
+ const text = String(claims?.['Communication.text'] || '').trim();
50
+ const recipient = String(claims?.['Communication.recipient'] || '').trim();
51
+ if (!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email) || !appointmentResponse || !appointment || !text || !recipient)
52
+ throw new Error('appointment_response_email_invalid');
53
+ return Object.freeze({ to: email, subject: 'Appointment response', text, metadata: Object.freeze({ appointmentResponse, appointment, recipient, language: 'en' }) });
54
+ }
55
+ /** Reads canonical GW search matches from `body.data[].resource`. */
56
+ export function readVeterinarySchedulingSearch(body, expectedResourceType) {
57
+ if (!body || typeof body !== 'object' || !Array.isArray(body.data)) {
58
+ throw new TypeError('veterinary_scheduling_search_invalid');
59
+ }
60
+ return Object.freeze(body.data.map(entry => {
61
+ if (!entry || typeof entry !== 'object' || !('resource' in entry)) {
62
+ throw new TypeError('veterinary_scheduling_search_resource_invalid');
63
+ }
64
+ try {
65
+ const resource = normalizeVeterinarySchedulingFlatClaimsResource(entry.resource);
66
+ if (resource.resourceType !== expectedResourceType)
67
+ throw new Error('wrong type');
68
+ return resource;
69
+ }
70
+ catch {
71
+ throw new TypeError('veterinary_scheduling_search_resource_invalid');
72
+ }
73
+ }));
74
+ }
75
+ /**
76
+ * Produces recoverable updates for bookings whose slots disappeared.
77
+ * It deliberately does not cancel: the patient receives a durable
78
+ * Communication and may choose another slot before a final decline.
79
+ */
80
+ export function reconcileVeterinaryAppointmentsAfterSlotChange(input) {
81
+ const appointments = [];
82
+ const notifications = [];
83
+ for (const candidate of input.appointments) {
84
+ const appointment = normalizeVeterinarySchedulingFlatClaimsResource(candidate);
85
+ if (appointment.resourceType !== 'Appointment')
86
+ throw new TypeError('veterinary_scheduling_appointment_required');
87
+ const slots = appointment.meta.claims['Appointment.slot'] ?? [];
88
+ if (slots.length > 0 && slots.every(slot => input.availableSlotReferences.has(slot)))
89
+ continue;
90
+ const updated = normalizeVeterinarySchedulingFlatClaimsResource({
91
+ ...appointment,
92
+ meta: { claims: {
93
+ ...appointment.meta.claims,
94
+ 'Appointment.status': ['pending'],
95
+ 'VeterinaryAppointment.reschedulingReason': [input.reason],
96
+ } },
97
+ });
98
+ appointments.push(updated);
99
+ const notification = buildVeterinaryAppointmentNotificationResource({
100
+ id: `${appointment.id}-schedule-change`,
101
+ appointmentReference: `Appointment/${appointment.id}`,
102
+ subjectReference: input.subjectReferenceFor(appointment),
103
+ reason: input.reason,
104
+ });
105
+ notifications.push(Object.freeze({
106
+ resourceType: 'Communication',
107
+ id: notification.id,
108
+ meta: Object.freeze({ claims: asArrayClaims(notification.meta.claims) }),
109
+ }));
110
+ }
111
+ return Object.freeze({ appointments: Object.freeze(appointments), notifications: Object.freeze(notifications) });
112
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vet-sdk-core-ts",
3
- "version": "0.4.22",
3
+ "version": "0.4.24",
4
4
  "description": "Browser-safe VetChain core contracts and governed animal species identifiers",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Connecting Solution & Applications Ltd",
@@ -47,6 +47,10 @@
47
47
  "./health-card-issuance": {
48
48
  "types": "./dist/health-card-issuance.d.ts",
49
49
  "default": "./dist/health-card-issuance.js"
50
+ },
51
+ "./scheduling": {
52
+ "types": "./dist/scheduling.d.ts",
53
+ "default": "./dist/scheduling.js"
50
54
  }
51
55
  },
52
56
  "files": [
@@ -72,6 +76,6 @@
72
76
  "dependencies": {
73
77
  "@noble/hashes": "^2.2.0",
74
78
  "gdc-common-utils-ts": "2.9.10",
75
- "vet-data-utils-ts": "0.5.9"
79
+ "vet-data-utils-ts": "0.5.13"
76
80
  }
77
81
  }