vet-sdk-core-ts 0.4.12 → 0.4.13

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
@@ -41,6 +41,19 @@ to the ResearchStudy through `Consent.provision.data.reference` and to
41
41
  only create, read, update and search. It contains no delete permission and
42
42
  never authorizes SMART access.
43
43
 
44
+ `buildVeterinaryResearchStudyGroupCreateEntry` and
45
+ `buildVeterinaryResearchStudyGroupMemberPatchEntries` build the native R5 Group
46
+ POST/PATCH entries for an enumerated professional review team. Every member is
47
+ a registered `PractitionerRole`; the exact twelve Group search claims are
48
+ derived from `vet-data-utils-ts/group`. The ResearchStudy points to the team
49
+ through the reference returned by
50
+ `buildVeterinaryResearchStudyEligibilityGroupReference`, used as
51
+ `ResearchStudy.recruitment.eligibility`.
52
+ `buildVeterinaryResearchStudyEligibilityGroupPatchEntry` links an existing
53
+ study and is wrapped by `buildVeterinaryResearchStudyBatch`; it does not invent
54
+ a mixed-resource gateway batch. Group itself contains no reverse study link
55
+ and grants no authorization, permission or SMART scope.
56
+
44
57
  The complete controller-to-professional contract and a browser-safe snippet
45
58
  are in
46
59
  [`docs/101-RESEARCH-STUDY-INVITATIONS.md`](docs/101-RESEARCH-STUDY-INVITATIONS.md).
@@ -51,6 +64,8 @@ FHIR references:
51
64
  - https://hl7.org/fhir/R5/researchsubject-search.html
52
65
  - https://hl7.org/fhir/R5/communication.html
53
66
  - https://hl7.org/fhir/R5/consent-definitions.html
67
+ - https://hl7.org/fhir/R5/group.html
68
+ - https://hl7.org/fhir/R5/group-search.html
54
69
 
55
70
  ## Reusable professional BFF
56
71
 
@@ -1,4 +1,5 @@
1
1
  import { type ResearchStudyAssociatedParty } from 'vet-data-utils-ts/research-study';
2
+ import { type GroupR5ResearchTeam } from 'vet-data-utils-ts/group';
2
3
  import { HealthcareConsentPurposes } from 'gdc-common-utils-ts/constants/healthcare';
3
4
  import { ResourceTypesFhirR5 } from 'gdc-common-utils-ts/constants/fhir-resource-types';
4
5
  import { ClaimConsent, ConsentStatuses } from 'gdc-common-utils-ts/models/consent-rule';
@@ -100,6 +101,24 @@ export type VeterinaryResearchStudyBatchEntry = Readonly<{
100
101
  export type VeterinaryResearchStudyBatch = Readonly<{
101
102
  data: readonly VeterinaryResearchStudyBatchEntry[];
102
103
  }>;
104
+ export type VeterinaryResearchStudyGroupResource = GroupR5ResearchTeam & Readonly<{
105
+ id: string;
106
+ meta: Readonly<{
107
+ claims: Readonly<Record<string, readonly string[]>>;
108
+ [key: string]: unknown;
109
+ }>;
110
+ }>;
111
+ export type VeterinaryResearchStudyGroupBatchEntry = Readonly<{
112
+ type: 'Group-v5.0.0';
113
+ resource: VeterinaryResearchStudyGroupResource;
114
+ request: Readonly<{
115
+ method: 'POST' | 'PATCH';
116
+ url: string;
117
+ }>;
118
+ }>;
119
+ export type VeterinaryResearchStudyGroupBatch = Readonly<{
120
+ data: readonly VeterinaryResearchStudyGroupBatchEntry[];
121
+ }>;
103
122
  export type VeterinaryResearchStudySmartAuthorization = Readonly<{
104
123
  purpose: typeof HealthcareConsentPurposes.Research;
105
124
  researchStudyReference: string;
@@ -163,6 +182,54 @@ export declare function buildVeterinaryResearchStudyActiveConsentBatch(inputs: r
163
182
  /** Builds one POST Consent entry accepted by the VET ResearchStudy manager. */
164
183
  export declare function buildVeterinaryResearchStudyActiveConsentEntry(input: VeterinaryResearchStudyActiveConsentInput): VeterinaryResearchStudyActiveConsentEntry;
165
184
  export declare function buildVeterinaryResearchStudyBatch(entries: readonly VeterinaryResearchStudyBatchEntry[]): VeterinaryResearchStudyBatch;
185
+ /**
186
+ * Returns the native eligibility reference by which an R5 ResearchStudy links
187
+ * to its descriptive professional Group. The direction is deliberately from
188
+ * `ResearchStudy.recruitment.eligibility` to Group; no invented study field or
189
+ * search claim is added to Group.
190
+ *
191
+ * @see https://hl7.org/fhir/R5/researchstudy.html
192
+ * @see https://hl7.org/fhir/R5/group.html
193
+ */
194
+ export declare function buildVeterinaryResearchStudyEligibilityGroupReference(groupId: string): Readonly<{
195
+ reference: `Group/${string}`;
196
+ type: 'Group';
197
+ }>;
198
+ /**
199
+ * Builds the native ResearchStudy PATCH that links a descriptive Group through
200
+ * `ResearchStudy.recruitment.eligibility`. The existing ResearchStudy batch
201
+ * builder wraps this entry; Group and ResearchStudy remain separate resource
202
+ * endpoints and no mixed-resource transport envelope is invented.
203
+ *
204
+ * @see https://hl7.org/fhir/R5/researchstudy.html
205
+ * @see https://hl7.org/fhir/R5/researchstudy-search.html
206
+ */
207
+ export declare function buildVeterinaryResearchStudyEligibilityGroupPatchEntry(input: Readonly<{
208
+ researchStudyId: string;
209
+ groupId: string;
210
+ }>): VeterinaryResearchStudyBatchEntry;
211
+ /**
212
+ * Builds the Group POST used to create one enumerated ResearchStudy review
213
+ * team. Every member is a native PractitionerRole reference. Group remains a
214
+ * description only and the generated resource cannot carry access policy.
215
+ *
216
+ * @see https://hl7.org/fhir/R5/group.html
217
+ * @see https://hl7.org/fhir/R5/group-search.html
218
+ */
219
+ export declare function buildVeterinaryResearchStudyGroupCreateEntry(input: Readonly<{
220
+ group: GroupR5ResearchTeam;
221
+ }>): VeterinaryResearchStudyGroupBatchEntry;
222
+ /**
223
+ * Builds one independently correlated PATCH per PractitionerRole member. A
224
+ * PATCH changes descriptive membership only; DCR, Consent and SMART remain
225
+ * separate authorization boundaries.
226
+ */
227
+ export declare function buildVeterinaryResearchStudyGroupMemberPatchEntries(input: Readonly<{
228
+ groupId: string;
229
+ members: unknown;
230
+ }>): readonly VeterinaryResearchStudyGroupBatchEntry[];
231
+ /** Wraps only validated Group POST/PATCH entries in one JSON:API document. */
232
+ export declare function buildVeterinaryResearchStudyGroupBatch(entries: readonly VeterinaryResearchStudyGroupBatchEntry[]): VeterinaryResearchStudyGroupBatch;
166
233
  export declare function buildVeterinaryResearchStudyCreateEntry(input: Readonly<{
167
234
  study: VeterinaryResearchStudyCreateResource;
168
235
  }>): VeterinaryResearchStudyBatchEntry;
@@ -1,5 +1,6 @@
1
1
  import { normalizeResearchStudyAssociatedParties, projectResearchStudyAssociatedPartyClaims, projectResearchStudyR5SearchClaims, } from 'vet-data-utils-ts/research-study';
2
2
  import { VeterinaryCommunicationPresetFilters, VeterinaryResearchCommunicationTopics, } from 'vet-data-utils-ts/communication';
3
+ import { normalizeGroupPractitionerRoleMembers, normalizeGroupR5ResearchTeam, projectGroupR5SearchClaims, } from 'vet-data-utils-ts/group';
3
4
  import { HealthcareConsentPurposes } from 'gdc-common-utils-ts/constants/healthcare';
4
5
  import { ResourceTypesFhirR5 } from 'gdc-common-utils-ts/constants/fhir-resource-types';
5
6
  import { InteroperableContext } from 'gdc-common-utils-ts/constants/lifecycle';
@@ -110,6 +111,86 @@ export function buildVeterinaryResearchStudyBatch(entries) {
110
111
  throw new TypeError('veterinary_research_study_batch_empty');
111
112
  return deepFreeze({ data: entries.map(entry => clonePlain(entry)) });
112
113
  }
114
+ /**
115
+ * Returns the native eligibility reference by which an R5 ResearchStudy links
116
+ * to its descriptive professional Group. The direction is deliberately from
117
+ * `ResearchStudy.recruitment.eligibility` to Group; no invented study field or
118
+ * search claim is added to Group.
119
+ *
120
+ * @see https://hl7.org/fhir/R5/researchstudy.html
121
+ * @see https://hl7.org/fhir/R5/group.html
122
+ */
123
+ export function buildVeterinaryResearchStudyEligibilityGroupReference(groupId) {
124
+ return deepFreeze({ reference: `Group/${boundedGroupId(groupId)}`, type: 'Group' });
125
+ }
126
+ /**
127
+ * Builds the native ResearchStudy PATCH that links a descriptive Group through
128
+ * `ResearchStudy.recruitment.eligibility`. The existing ResearchStudy batch
129
+ * builder wraps this entry; Group and ResearchStudy remain separate resource
130
+ * endpoints and no mixed-resource transport envelope is invented.
131
+ *
132
+ * @see https://hl7.org/fhir/R5/researchstudy.html
133
+ * @see https://hl7.org/fhir/R5/researchstudy-search.html
134
+ */
135
+ export function buildVeterinaryResearchStudyEligibilityGroupPatchEntry(input) {
136
+ if (containsAuthorizationProperty(input)) {
137
+ throw new TypeError('veterinary_research_study_group_authorization_forbidden');
138
+ }
139
+ const researchStudyId = boundedId(input.researchStudyId);
140
+ const eligibility = buildVeterinaryResearchStudyEligibilityGroupReference(input.groupId);
141
+ return deepFreeze({
142
+ type: 'ResearchStudy-v5.0.0',
143
+ resource: withProjectedClaims({
144
+ resourceType: 'ResearchStudy',
145
+ id: researchStudyId,
146
+ recruitment: { eligibility },
147
+ }),
148
+ request: { method: 'PATCH', url: `ResearchStudy/${researchStudyId}` },
149
+ });
150
+ }
151
+ /**
152
+ * Builds the Group POST used to create one enumerated ResearchStudy review
153
+ * team. Every member is a native PractitionerRole reference. Group remains a
154
+ * description only and the generated resource cannot carry access policy.
155
+ *
156
+ * @see https://hl7.org/fhir/R5/group.html
157
+ * @see https://hl7.org/fhir/R5/group-search.html
158
+ */
159
+ export function buildVeterinaryResearchStudyGroupCreateEntry(input) {
160
+ const group = normalizedResearchTeamGroup(input.group);
161
+ return deepFreeze({
162
+ type: 'Group-v5.0.0',
163
+ resource: withProjectedGroupClaims(group),
164
+ request: { method: 'POST', url: 'Group' },
165
+ });
166
+ }
167
+ /**
168
+ * Builds one independently correlated PATCH per PractitionerRole member. A
169
+ * PATCH changes descriptive membership only; DCR, Consent and SMART remain
170
+ * separate authorization boundaries.
171
+ */
172
+ export function buildVeterinaryResearchStudyGroupMemberPatchEntries(input) {
173
+ const id = boundedGroupId(input.groupId);
174
+ const members = normalizeGroupPractitionerRoleMembers(input.members);
175
+ return deepFreeze(members.map(member => ({
176
+ type: 'Group-v5.0.0',
177
+ resource: withProjectedGroupClaims(deepFreeze({
178
+ resourceType: 'Group',
179
+ id,
180
+ type: 'practitioner',
181
+ membership: 'enumerated',
182
+ member: [member],
183
+ })),
184
+ request: { method: 'PATCH', url: `Group/${id}` },
185
+ })));
186
+ }
187
+ /** Wraps only validated Group POST/PATCH entries in one JSON:API document. */
188
+ export function buildVeterinaryResearchStudyGroupBatch(entries) {
189
+ if (!Array.isArray(entries) || entries.length === 0) {
190
+ throw new TypeError('veterinary_research_study_group_batch_empty');
191
+ }
192
+ return deepFreeze({ data: entries.map(normalizeResearchStudyGroupEntry) });
193
+ }
113
194
  export function buildVeterinaryResearchStudyCreateEntry(input) {
114
195
  const study = normalizedStudy(input.study);
115
196
  return deepFreeze({
@@ -290,6 +371,37 @@ function normalizedStudy(input) {
290
371
  ...(associatedParty ? { associatedParty } : {}),
291
372
  });
292
373
  }
374
+ function normalizedResearchTeamGroup(input) {
375
+ const source = clonePlain(input);
376
+ const normalized = normalizeGroupR5ResearchTeam(source);
377
+ return deepFreeze({ ...normalized, id: boundedGroupId(normalized.id) });
378
+ }
379
+ function normalizeResearchStudyGroupEntry(input) {
380
+ if (!input || input.type !== 'Group-v5.0.0') {
381
+ throw new TypeError('veterinary_research_study_group_entry_invalid');
382
+ }
383
+ const group = normalizedResearchTeamGroup(input.resource);
384
+ const method = input.request?.method;
385
+ const expectedUrl = method === 'POST' ? 'Group' : method === 'PATCH' ? `Group/${group.id}` : '';
386
+ if (!expectedUrl || input.request.url !== expectedUrl) {
387
+ throw new TypeError('veterinary_research_study_group_request_invalid');
388
+ }
389
+ return deepFreeze({
390
+ type: 'Group-v5.0.0',
391
+ resource: withProjectedGroupClaims(group),
392
+ request: { method, url: expectedUrl },
393
+ });
394
+ }
395
+ function withProjectedGroupClaims(group) {
396
+ const claims = projectGroupR5SearchClaims(group);
397
+ return deepFreeze({
398
+ ...group,
399
+ meta: {
400
+ ...(typeof group.meta === 'object' && group.meta !== null ? group.meta : {}),
401
+ claims,
402
+ },
403
+ });
404
+ }
293
405
  function clonePlain(value) {
294
406
  if (Array.isArray(value))
295
407
  return value.map(clonePlain);
@@ -325,6 +437,12 @@ function boundedId(value) {
325
437
  throw new TypeError('veterinary_research_study_id_invalid');
326
438
  return id;
327
439
  }
440
+ function boundedGroupId(value) {
441
+ const id = String(value || '').trim();
442
+ if (!/^[A-Za-z0-9\-.]{1,64}$/.test(id))
443
+ throw new TypeError('veterinary_research_study_group_id_invalid');
444
+ return id;
445
+ }
328
446
  function boundedReference(value, resourceType) {
329
447
  const reference = String(value || '').trim();
330
448
  const prefix = `${resourceType}/`;
@@ -352,6 +470,16 @@ function optionalInstant(value) {
352
470
  throw new TypeError('veterinary_research_study_invitation_sent_invalid');
353
471
  return instant;
354
472
  }
473
+ function containsAuthorizationProperty(value, seen = new WeakSet()) {
474
+ if (!value || typeof value !== 'object')
475
+ return false;
476
+ if (seen.has(value))
477
+ return false;
478
+ seen.add(value);
479
+ if (Array.isArray(value))
480
+ return value.some(item => containsAuthorizationProperty(item, seen));
481
+ return Object.entries(value).some(([name, nested]) => ['authorization', 'permission', 'scope'].includes(name) || containsAuthorizationProperty(nested, seen));
482
+ }
355
483
  function splitCodingToken(value) {
356
484
  const separator = value.lastIndexOf('|');
357
485
  if (separator < 1 || separator === value.length - 1) {
@@ -17,10 +17,39 @@ related to the exact ResearchStudy. Whole-twin delete is absent.
17
17
  ```ts
18
18
  import {
19
19
  buildVeterinaryResearchStudyActiveConsentBatch,
20
+ buildVeterinaryResearchStudyBatch,
21
+ buildVeterinaryResearchStudyEligibilityGroupPatchEntry,
22
+ buildVeterinaryResearchStudyGroupBatch,
23
+ buildVeterinaryResearchStudyGroupCreateEntry,
24
+ buildVeterinaryResearchStudyGroupMemberPatchEntries,
20
25
  buildVeterinaryResearchStudyPartyInvitations,
21
26
  buildVeterinaryResearchStudySmartAuthorization,
22
27
  } from 'vet-sdk-core-ts/research-study'
23
28
 
29
+ const researchGroupId = 'review-team'
30
+ const groupCreate = buildVeterinaryResearchStudyGroupCreateEntry({
31
+ group: {
32
+ resourceType: 'Group',
33
+ id: researchGroupId,
34
+ type: 'practitioner',
35
+ membership: 'enumerated',
36
+ member: [],
37
+ },
38
+ })
39
+ const memberPatches = buildVeterinaryResearchStudyGroupMemberPatchEntries({
40
+ groupId: researchGroupId,
41
+ members: associatedParties.map(({ party }) => ({ entity: party })),
42
+ })
43
+ const groupBatch = buildVeterinaryResearchStudyGroupBatch([groupCreate, ...memberPatches])
44
+ // The protected controller BFF submits `groupBatch`; membership grants no access.
45
+ const eligibilityPatch = buildVeterinaryResearchStudyEligibilityGroupPatchEntry({
46
+ researchStudyId: study.id,
47
+ groupId: researchGroupId,
48
+ })
49
+ const studyPatchBatch = buildVeterinaryResearchStudyBatch([eligibilityPatch])
50
+ // Submit `studyPatchBatch` through the protected ResearchStudy BFF after the
51
+ // Group exists. The two native resource endpoints remain separate.
52
+
24
53
  const invitations = buildVeterinaryResearchStudyPartyInvitations({
25
54
  researchStudyId: study.id,
26
55
  controllerReference: organizationReference,
@@ -60,6 +89,18 @@ const authorization = buildVeterinaryResearchStudySmartAuthorization({
60
89
  await professionalRuntime.requestSmartToken(authorization)
61
90
  ```
62
91
 
92
+ The controller may also create a descriptive review team with
93
+ `buildVeterinaryResearchStudyGroupCreateEntry()` and append each registered
94
+ `PractitionerRole` with
95
+ `buildVeterinaryResearchStudyGroupMemberPatchEntries()`. The Group is linked
96
+ from `ResearchStudy.recruitment.eligibility` using
97
+ `buildVeterinaryResearchStudyEligibilityGroupPatchEntry()` and the existing
98
+ ResearchStudy batch builder. Group membership is not evidence of DCR or
99
+ Consent and never grants the SMART authorization above.
100
+
101
+ These builders follow the native [FHIR R5 Group resource](https://hl7.org/fhir/R5/group.html)
102
+ and its exact [resource-specific search catalogue](https://hl7.org/fhir/R5/group-search.html).
103
+
63
104
  The SMART authorization intentionally does not carry `subjectDid`:
64
105
  `openProfessional()` supplies its DCR-bound actor as `sub`, while GW derives
65
106
  the authorization subject `ResearchStudy/<id>` from the exact unescaped scope.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vet-sdk-core-ts",
3
- "version": "0.4.12",
3
+ "version": "0.4.13",
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",
@@ -64,6 +64,6 @@
64
64
  "dependencies": {
65
65
  "@noble/hashes": "^2.2.0",
66
66
  "gdc-common-utils-ts": "2.9.4",
67
- "vet-data-utils-ts": "0.5.0"
67
+ "vet-data-utils-ts": "0.5.1"
68
68
  }
69
69
  }