vet-data-utils-ts 0.5.0 → 0.5.2
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 +19 -4
- package/dist/group.d.ts +106 -0
- package/dist/group.js +286 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/research-study.d.ts +18 -2
- package/dist/research-study.js +61 -12
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -10,12 +10,27 @@ veterinary assistant intents.
|
|
|
10
10
|
|
|
11
11
|
FHIR R5 ResearchStudy screens consume the exact 25 resource-specific search
|
|
12
12
|
parameters and the separate associated-party projection from
|
|
13
|
-
`vet-data-utils-ts/research-study`.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
`vet-data-utils-ts/research-study`. GW persistence receives only
|
|
14
|
+
`resourceType`, `id` and flat `resource.meta.claims`; each party uses its own
|
|
15
|
+
`ResearchStudy.party-*` claim map so repeating roles, periods and classifiers
|
|
16
|
+
cannot be attributed to the wrong party. A party classifier describes an
|
|
17
|
+
organization category; it never represents Consent or CRUDS authorization. See
|
|
17
18
|
[`docs/research-study-r5-contract.md`](docs/research-study-r5-contract.md).
|
|
18
19
|
|
|
20
|
+
ResearchStudy professional teams use native FHIR R5 Group resources from
|
|
21
|
+
`vet-data-utils-ts/group`: required type and membership codes, the exact twelve
|
|
22
|
+
resource-specific SearchParameters, canonical flat claim projection and
|
|
23
|
+
enumerated PractitionerRole member normalization. Group membership is
|
|
24
|
+
descriptive and never carries authorization, permission or scope. See
|
|
25
|
+
[`docs/group-r5-contract.md`](docs/group-r5-contract.md).
|
|
26
|
+
|
|
27
|
+
`projectResearchStudyR5FlatClaimsResource()` and
|
|
28
|
+
`projectGroupR5FlatClaimsResource()` create the minimal claims-first resource;
|
|
29
|
+
their repeating-party/member companions return one correlated resource per
|
|
30
|
+
future PATCH. The matching `normalize*FlatClaimsResource()` functions reject
|
|
31
|
+
nested FHIR persistence fields and unknown claims. Native FHIR JSON remains an
|
|
32
|
+
explicit import, projection or export boundary.
|
|
33
|
+
|
|
19
34
|
Reusable Communication screens receive immutable workflow presets from
|
|
20
35
|
`vet-data-utils-ts/communication`. The research-agreement screen is fixed to
|
|
21
36
|
FHIR `notification` plus HL7 v3 ActReason `HRESCH` and does not expose a topic
|
package/dist/group.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe FHIR R5 Group contract for research-team descriptions.
|
|
3
|
+
*
|
|
4
|
+
* Group membership is descriptive. It never grants authorization, permission
|
|
5
|
+
* or a SMART scope; those decisions remain separate Consent and credential
|
|
6
|
+
* contracts.
|
|
7
|
+
*
|
|
8
|
+
* @see https://hl7.org/fhir/R5/group.html
|
|
9
|
+
* @see https://hl7.org/fhir/R5/group-search.html
|
|
10
|
+
*/
|
|
11
|
+
export declare const GroupR5Version: "5.0.0";
|
|
12
|
+
export declare const GroupR5TypeSystem: "http://hl7.org/fhir/group-type";
|
|
13
|
+
export declare const GroupR5TypeCodes: readonly ["person", "animal", "practitioner", "device", "careteam", "healthcareservice", "location", "organization", "relatedperson", "specimen"];
|
|
14
|
+
export type GroupR5TypeCode = (typeof GroupR5TypeCodes)[number];
|
|
15
|
+
export declare const GroupR5MembershipSystem: "http://hl7.org/fhir/group-membership-basis";
|
|
16
|
+
export declare const GroupR5MembershipCodes: readonly ["definitional", "enumerated"];
|
|
17
|
+
export type GroupR5MembershipCode = (typeof GroupR5MembershipCodes)[number];
|
|
18
|
+
export declare const GroupR5Bindings: Readonly<{
|
|
19
|
+
readonly type: Readonly<{
|
|
20
|
+
valueSet: "http://hl7.org/fhir/ValueSet/group-type";
|
|
21
|
+
strength: "required";
|
|
22
|
+
}>;
|
|
23
|
+
readonly membership: Readonly<{
|
|
24
|
+
valueSet: "http://hl7.org/fhir/ValueSet/group-membership-basis";
|
|
25
|
+
strength: "required";
|
|
26
|
+
}>;
|
|
27
|
+
}>;
|
|
28
|
+
export type GroupSearchParameterType = 'composite' | 'reference' | 'string' | 'token';
|
|
29
|
+
export type GroupR5SearchParameter = Readonly<{
|
|
30
|
+
code: string;
|
|
31
|
+
type: GroupSearchParameterType;
|
|
32
|
+
expression: string;
|
|
33
|
+
components: readonly string[];
|
|
34
|
+
}>;
|
|
35
|
+
/** Exact resource-specific SearchParameters published by FHIR R5 5.0.0. */
|
|
36
|
+
export declare const GroupR5SearchParameterCatalog: readonly GroupR5SearchParameter[];
|
|
37
|
+
declare const standardSearchClaims: readonly `Group.${string}`[];
|
|
38
|
+
/** Canonical claims derived only from the official resource-specific catalogue. */
|
|
39
|
+
export declare const GroupFlatClaimCatalog: Readonly<{
|
|
40
|
+
standardSearch: readonly `Group.${string}`[];
|
|
41
|
+
all: readonly `Group.${string}`[];
|
|
42
|
+
}>;
|
|
43
|
+
export type GroupR5SearchClaim = (typeof standardSearchClaims)[number];
|
|
44
|
+
export type GroupR5SearchClaims = Readonly<Partial<Record<GroupR5SearchClaim, readonly string[]>>>;
|
|
45
|
+
export type GroupR5FlatClaimsResource = Readonly<{
|
|
46
|
+
resourceType: 'Group';
|
|
47
|
+
id: string;
|
|
48
|
+
meta: Readonly<{
|
|
49
|
+
claims: Readonly<Record<string, readonly string[]>>;
|
|
50
|
+
}>;
|
|
51
|
+
}>;
|
|
52
|
+
export type GroupR5Reference = Readonly<{
|
|
53
|
+
reference: string;
|
|
54
|
+
type?: string;
|
|
55
|
+
display?: string;
|
|
56
|
+
}>;
|
|
57
|
+
export type GroupR5Period = Readonly<{
|
|
58
|
+
start?: string;
|
|
59
|
+
end?: string;
|
|
60
|
+
}>;
|
|
61
|
+
export type GroupPractitionerRoleMember = Readonly<{
|
|
62
|
+
entity: Readonly<{
|
|
63
|
+
reference: `PractitionerRole/${string}`;
|
|
64
|
+
type: 'PractitionerRole';
|
|
65
|
+
display?: string;
|
|
66
|
+
}>;
|
|
67
|
+
period?: GroupR5Period;
|
|
68
|
+
inactive?: boolean;
|
|
69
|
+
}>;
|
|
70
|
+
export type GroupR5ResearchTeam = Readonly<Record<string, unknown> & {
|
|
71
|
+
resourceType: 'Group';
|
|
72
|
+
id?: string;
|
|
73
|
+
type: 'practitioner';
|
|
74
|
+
membership: 'enumerated';
|
|
75
|
+
member: readonly GroupPractitionerRoleMember[];
|
|
76
|
+
}>;
|
|
77
|
+
/**
|
|
78
|
+
* Normalizes the members used by an enumerated professional research team.
|
|
79
|
+
* Every entity is a native PractitionerRole reference; a Practitioner or an
|
|
80
|
+
* employee identifier cannot substitute for the registered role assignment.
|
|
81
|
+
*/
|
|
82
|
+
export declare function normalizeGroupPractitionerRoleMembers(input: unknown): readonly GroupPractitionerRoleMember[];
|
|
83
|
+
/**
|
|
84
|
+
* Normalizes the Group profile used to describe an explicit professional
|
|
85
|
+
* ResearchStudy team. This data is descriptive and authorization-shaped
|
|
86
|
+
* properties are rejected at every depth.
|
|
87
|
+
*/
|
|
88
|
+
export declare function normalizeGroupR5ResearchTeam(input: unknown): GroupR5ResearchTeam;
|
|
89
|
+
/**
|
|
90
|
+
* Projects all populated official resource-specific R5 Group SearchParameters
|
|
91
|
+
* into flat `resource.meta.claims`. A referenced characteristic is indexed by
|
|
92
|
+
* `characteristic-reference`, not as the token-valued `value` parameter.
|
|
93
|
+
*
|
|
94
|
+
* @see https://hl7.org/fhir/R5/group-search.html
|
|
95
|
+
*/
|
|
96
|
+
export declare function projectGroupR5SearchClaims(input: unknown): GroupR5SearchClaims;
|
|
97
|
+
/** Projects native-shaped Group input to the claims-only GW persistence shape. */
|
|
98
|
+
export declare function projectGroupR5FlatClaimsResource(input: unknown): GroupR5FlatClaimsResource;
|
|
99
|
+
/** Projects one correlated claims-only GW resource per PractitionerRole member. */
|
|
100
|
+
export declare function projectGroupPractitionerRoleMemberFlatClaimResources(input: Readonly<{
|
|
101
|
+
groupId: string;
|
|
102
|
+
members: unknown;
|
|
103
|
+
}>): readonly GroupR5FlatClaimsResource[];
|
|
104
|
+
/** Validates and freezes a claims-only Group GW resource. */
|
|
105
|
+
export declare function normalizeGroupR5FlatClaimsResource(input: unknown): GroupR5FlatClaimsResource;
|
|
106
|
+
export {};
|
package/dist/group.js
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe FHIR R5 Group contract for research-team descriptions.
|
|
3
|
+
*
|
|
4
|
+
* Group membership is descriptive. It never grants authorization, permission
|
|
5
|
+
* or a SMART scope; those decisions remain separate Consent and credential
|
|
6
|
+
* contracts.
|
|
7
|
+
*
|
|
8
|
+
* @see https://hl7.org/fhir/R5/group.html
|
|
9
|
+
* @see https://hl7.org/fhir/R5/group-search.html
|
|
10
|
+
*/
|
|
11
|
+
export const GroupR5Version = '5.0.0';
|
|
12
|
+
export const GroupR5TypeSystem = 'http://hl7.org/fhir/group-type';
|
|
13
|
+
export const GroupR5TypeCodes = Object.freeze([
|
|
14
|
+
'person',
|
|
15
|
+
'animal',
|
|
16
|
+
'practitioner',
|
|
17
|
+
'device',
|
|
18
|
+
'careteam',
|
|
19
|
+
'healthcareservice',
|
|
20
|
+
'location',
|
|
21
|
+
'organization',
|
|
22
|
+
'relatedperson',
|
|
23
|
+
'specimen',
|
|
24
|
+
]);
|
|
25
|
+
export const GroupR5MembershipSystem = 'http://hl7.org/fhir/group-membership-basis';
|
|
26
|
+
export const GroupR5MembershipCodes = Object.freeze(['definitional', 'enumerated']);
|
|
27
|
+
export const GroupR5Bindings = Object.freeze({
|
|
28
|
+
type: Object.freeze({
|
|
29
|
+
valueSet: 'http://hl7.org/fhir/ValueSet/group-type',
|
|
30
|
+
strength: 'required',
|
|
31
|
+
}),
|
|
32
|
+
membership: Object.freeze({
|
|
33
|
+
valueSet: 'http://hl7.org/fhir/ValueSet/group-membership-basis',
|
|
34
|
+
strength: 'required',
|
|
35
|
+
}),
|
|
36
|
+
});
|
|
37
|
+
const searchParameter = (code, type, expression, components = []) => Object.freeze({
|
|
38
|
+
code,
|
|
39
|
+
type,
|
|
40
|
+
expression,
|
|
41
|
+
components: Object.freeze([...components]),
|
|
42
|
+
});
|
|
43
|
+
/** Exact resource-specific SearchParameters published by FHIR R5 5.0.0. */
|
|
44
|
+
export const GroupR5SearchParameterCatalog = Object.freeze([
|
|
45
|
+
searchParameter('characteristic', 'token', 'Group.characteristic.code'),
|
|
46
|
+
searchParameter('characteristic-reference', 'reference', '(Group.characteristic.value.ofType(Reference))'),
|
|
47
|
+
searchParameter('characteristic-value', 'composite', 'Group.characteristic', [
|
|
48
|
+
'http://hl7.org/fhir/SearchParameter/Group-characteristic',
|
|
49
|
+
'http://hl7.org/fhir/SearchParameter/Group-value',
|
|
50
|
+
]),
|
|
51
|
+
searchParameter('code', 'token', 'Group.code'),
|
|
52
|
+
searchParameter('exclude', 'token', 'Group.characteristic.exclude'),
|
|
53
|
+
searchParameter('identifier', 'token', 'Group.identifier'),
|
|
54
|
+
searchParameter('managing-entity', 'reference', 'Group.managingEntity'),
|
|
55
|
+
searchParameter('member', 'reference', 'Group.member.entity'),
|
|
56
|
+
searchParameter('membership', 'token', 'Group.membership'),
|
|
57
|
+
searchParameter('name', 'string', 'Group.name'),
|
|
58
|
+
searchParameter('type', 'token', 'Group.type'),
|
|
59
|
+
searchParameter('value', 'token', '(Group.characteristic.value.ofType(CodeableConcept)) | (Group.characteristic.value.ofType(boolean))'),
|
|
60
|
+
]);
|
|
61
|
+
const standardSearchClaims = Object.freeze(GroupR5SearchParameterCatalog.map(parameter => `Group.${parameter.code}`));
|
|
62
|
+
/** Canonical claims derived only from the official resource-specific catalogue. */
|
|
63
|
+
export const GroupFlatClaimCatalog = Object.freeze({
|
|
64
|
+
standardSearch: standardSearchClaims,
|
|
65
|
+
all: standardSearchClaims,
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* Normalizes the members used by an enumerated professional research team.
|
|
69
|
+
* Every entity is a native PractitionerRole reference; a Practitioner or an
|
|
70
|
+
* employee identifier cannot substitute for the registered role assignment.
|
|
71
|
+
*/
|
|
72
|
+
export function normalizeGroupPractitionerRoleMembers(input) {
|
|
73
|
+
if (!Array.isArray(input))
|
|
74
|
+
throw new TypeError('group_members_invalid');
|
|
75
|
+
return Object.freeze(input.map((value, index) => {
|
|
76
|
+
if (!isRecord(value) || containsAuthorizationProperty(value)) {
|
|
77
|
+
throw new TypeError(containsAuthorizationProperty(value) ? 'group_authorization_property_forbidden' : `group_member_${index}_invalid`);
|
|
78
|
+
}
|
|
79
|
+
if (!isRecord(value.entity))
|
|
80
|
+
throw new TypeError(`group_member_${index}_practitioner_role_reference_invalid`);
|
|
81
|
+
const reference = optionalString(value.entity.reference);
|
|
82
|
+
const declaredType = optionalString(value.entity.type);
|
|
83
|
+
if (!reference || !/^PractitionerRole\/[A-Za-z0-9.-]{1,64}$/.test(reference) || (declaredType && declaredType !== 'PractitionerRole')) {
|
|
84
|
+
throw new TypeError(`group_member_${index}_practitioner_role_reference_invalid`);
|
|
85
|
+
}
|
|
86
|
+
const display = optionalString(value.entity.display);
|
|
87
|
+
const period = value.period === undefined ? undefined : normalizePeriod(value.period, index);
|
|
88
|
+
if (value.inactive !== undefined && typeof value.inactive !== 'boolean') {
|
|
89
|
+
throw new TypeError(`group_member_${index}_inactive_invalid`);
|
|
90
|
+
}
|
|
91
|
+
return Object.freeze({
|
|
92
|
+
entity: Object.freeze({
|
|
93
|
+
reference: reference,
|
|
94
|
+
type: 'PractitionerRole',
|
|
95
|
+
...(display ? { display } : {}),
|
|
96
|
+
}),
|
|
97
|
+
...(period ? { period } : {}),
|
|
98
|
+
...(value.inactive !== undefined ? { inactive: value.inactive } : {}),
|
|
99
|
+
});
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Normalizes the Group profile used to describe an explicit professional
|
|
104
|
+
* ResearchStudy team. This data is descriptive and authorization-shaped
|
|
105
|
+
* properties are rejected at every depth.
|
|
106
|
+
*/
|
|
107
|
+
export function normalizeGroupR5ResearchTeam(input) {
|
|
108
|
+
if (!isRecord(input) || input.resourceType !== 'Group')
|
|
109
|
+
throw new TypeError('group_resource_invalid');
|
|
110
|
+
if (containsAuthorizationProperty(input))
|
|
111
|
+
throw new TypeError('group_authorization_property_forbidden');
|
|
112
|
+
if (input.type !== 'practitioner')
|
|
113
|
+
throw new TypeError('group_research_team_type_invalid');
|
|
114
|
+
if (input.membership !== 'enumerated')
|
|
115
|
+
throw new TypeError('group_research_team_membership_invalid');
|
|
116
|
+
const member = normalizeGroupPractitionerRoleMembers(input.member);
|
|
117
|
+
return Object.freeze({ ...input, type: 'practitioner', membership: 'enumerated', member });
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Projects all populated official resource-specific R5 Group SearchParameters
|
|
121
|
+
* into flat `resource.meta.claims`. A referenced characteristic is indexed by
|
|
122
|
+
* `characteristic-reference`, not as the token-valued `value` parameter.
|
|
123
|
+
*
|
|
124
|
+
* @see https://hl7.org/fhir/R5/group-search.html
|
|
125
|
+
*/
|
|
126
|
+
export function projectGroupR5SearchClaims(input) {
|
|
127
|
+
if (!isRecord(input) || input.resourceType !== 'Group')
|
|
128
|
+
throw new TypeError('group_resource_invalid');
|
|
129
|
+
if (containsAuthorizationProperty(input))
|
|
130
|
+
throw new TypeError('group_authorization_property_forbidden');
|
|
131
|
+
if (!GroupR5TypeCodes.includes(input.type))
|
|
132
|
+
throw new TypeError('group_type_invalid');
|
|
133
|
+
if (!GroupR5MembershipCodes.includes(input.membership)) {
|
|
134
|
+
throw new TypeError('group_membership_invalid');
|
|
135
|
+
}
|
|
136
|
+
const characteristics = normalizeRecords(input.characteristic, 'group_characteristic_invalid');
|
|
137
|
+
const characteristicCodes = characteristics.flatMap(item => conceptTokens(item.code));
|
|
138
|
+
const characteristicValues = characteristics.flatMap(characteristicTokenValues);
|
|
139
|
+
const claims = {};
|
|
140
|
+
addClaim(claims, 'Group.characteristic', characteristicCodes);
|
|
141
|
+
addClaim(claims, 'Group.characteristic-reference', characteristics.flatMap(item => referenceTokens(item.valueReference)));
|
|
142
|
+
addClaim(claims, 'Group.characteristic-value', characteristics.flatMap(item => conceptTokens(item.code).flatMap(code => characteristicTokenValues(item).map(value => `${code}$${value}`))));
|
|
143
|
+
addClaim(claims, 'Group.code', conceptTokens(input.code));
|
|
144
|
+
addClaim(claims, 'Group.exclude', characteristics.flatMap(item => typeof item.exclude === 'boolean' ? [String(item.exclude)] : []));
|
|
145
|
+
addClaim(claims, 'Group.identifier', identifierTokens(input.identifier));
|
|
146
|
+
addClaim(claims, 'Group.managing-entity', referenceTokens(input.managingEntity));
|
|
147
|
+
addClaim(claims, 'Group.member', normalizeRecords(input.member, 'group_members_invalid').flatMap(item => referenceTokens(item.entity)));
|
|
148
|
+
addClaim(claims, 'Group.membership', [input.membership]);
|
|
149
|
+
addClaim(claims, 'Group.name', strings(input.name));
|
|
150
|
+
addClaim(claims, 'Group.type', [input.type]);
|
|
151
|
+
addClaim(claims, 'Group.value', characteristicValues);
|
|
152
|
+
return Object.freeze(claims);
|
|
153
|
+
}
|
|
154
|
+
/** Projects native-shaped Group input to the claims-only GW persistence shape. */
|
|
155
|
+
export function projectGroupR5FlatClaimsResource(input) {
|
|
156
|
+
if (!isRecord(input) || input.resourceType !== 'Group')
|
|
157
|
+
throw new TypeError('group_resource_invalid');
|
|
158
|
+
const id = fhirId(input.id, 'group_flat_resource_invalid');
|
|
159
|
+
if (Array.isArray(input.member) && input.member.length > 0)
|
|
160
|
+
throw new TypeError('group_members_require_separate_resources');
|
|
161
|
+
return normalizeGroupR5FlatClaimsResource({
|
|
162
|
+
resourceType: 'Group',
|
|
163
|
+
id,
|
|
164
|
+
meta: { claims: projectGroupR5SearchClaims(input) },
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
/** Projects one correlated claims-only GW resource per PractitionerRole member. */
|
|
168
|
+
export function projectGroupPractitionerRoleMemberFlatClaimResources(input) {
|
|
169
|
+
const id = fhirId(input.groupId, 'group_flat_resource_invalid');
|
|
170
|
+
const members = normalizeGroupPractitionerRoleMembers(input.members);
|
|
171
|
+
return Object.freeze(members.map(member => normalizeGroupR5FlatClaimsResource({
|
|
172
|
+
resourceType: 'Group',
|
|
173
|
+
id,
|
|
174
|
+
meta: {
|
|
175
|
+
claims: projectGroupR5SearchClaims({
|
|
176
|
+
resourceType: 'Group',
|
|
177
|
+
id,
|
|
178
|
+
type: 'practitioner',
|
|
179
|
+
membership: 'enumerated',
|
|
180
|
+
member: [member],
|
|
181
|
+
}),
|
|
182
|
+
},
|
|
183
|
+
})));
|
|
184
|
+
}
|
|
185
|
+
/** Validates and freezes a claims-only Group GW resource. */
|
|
186
|
+
export function normalizeGroupR5FlatClaimsResource(input) {
|
|
187
|
+
if (!isRecord(input)
|
|
188
|
+
|| input.resourceType !== 'Group'
|
|
189
|
+
|| Object.keys(input).some(key => !['resourceType', 'id', 'meta'].includes(key))) {
|
|
190
|
+
throw new TypeError('group_flat_resource_invalid');
|
|
191
|
+
}
|
|
192
|
+
const id = fhirId(input.id, 'group_flat_resource_invalid');
|
|
193
|
+
if (!isRecord(input.meta) || !isRecord(input.meta.claims))
|
|
194
|
+
throw new TypeError('group_flat_resource_invalid');
|
|
195
|
+
const claims = {};
|
|
196
|
+
for (const [name, rawValues] of Object.entries(input.meta.claims)) {
|
|
197
|
+
if (!GroupFlatClaimCatalog.all.includes(name)
|
|
198
|
+
|| !Array.isArray(rawValues)
|
|
199
|
+
|| rawValues.length === 0
|
|
200
|
+
|| rawValues.some(value => typeof value !== 'string' || !value.trim())) {
|
|
201
|
+
throw new TypeError('group_flat_claim_invalid');
|
|
202
|
+
}
|
|
203
|
+
claims[name] = Object.freeze(rawValues.map(value => value.trim()));
|
|
204
|
+
}
|
|
205
|
+
return Object.freeze({ resourceType: 'Group', id, meta: Object.freeze({ claims: Object.freeze(claims) }) });
|
|
206
|
+
}
|
|
207
|
+
function addClaim(claims, name, values) {
|
|
208
|
+
const normalized = [...new Set(values.flatMap(value => strings(value)))];
|
|
209
|
+
if (normalized.length > 0)
|
|
210
|
+
claims[name] = Object.freeze(normalized);
|
|
211
|
+
}
|
|
212
|
+
function identifierTokens(value) {
|
|
213
|
+
return normalizeRecords(value, 'group_identifier_invalid').flatMap(identifier => {
|
|
214
|
+
const system = optionalString(identifier.system);
|
|
215
|
+
const identifierValue = optionalString(identifier.value);
|
|
216
|
+
return identifierValue ? [`${system ? `${system}|` : ''}${identifierValue}`] : [];
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
function conceptTokens(value) {
|
|
220
|
+
if (!isRecord(value))
|
|
221
|
+
return [];
|
|
222
|
+
const coding = normalizeRecords(value.coding, 'group_coding_invalid').flatMap(item => {
|
|
223
|
+
const system = optionalString(item.system);
|
|
224
|
+
const code = optionalString(item.code);
|
|
225
|
+
return code ? [`${system ? `${system}|` : ''}${code}`] : [];
|
|
226
|
+
});
|
|
227
|
+
return coding.length > 0 ? coding : strings(value.text);
|
|
228
|
+
}
|
|
229
|
+
function characteristicTokenValues(value) {
|
|
230
|
+
if (typeof value.valueBoolean === 'boolean')
|
|
231
|
+
return [String(value.valueBoolean)];
|
|
232
|
+
return conceptTokens(value.valueCodeableConcept);
|
|
233
|
+
}
|
|
234
|
+
function referenceTokens(value) {
|
|
235
|
+
return isRecord(value) ? strings(value.reference) : [];
|
|
236
|
+
}
|
|
237
|
+
function normalizeRecords(value, error) {
|
|
238
|
+
if (value === undefined)
|
|
239
|
+
return [];
|
|
240
|
+
if (!Array.isArray(value) || !value.every(isRecord))
|
|
241
|
+
throw new TypeError(error);
|
|
242
|
+
return value;
|
|
243
|
+
}
|
|
244
|
+
function normalizePeriod(value, index) {
|
|
245
|
+
if (!isRecord(value))
|
|
246
|
+
throw new TypeError(`group_member_${index}_period_invalid`);
|
|
247
|
+
const start = optionalString(value.start);
|
|
248
|
+
const end = optionalString(value.end);
|
|
249
|
+
if (!start && !end)
|
|
250
|
+
throw new TypeError(`group_member_${index}_period_invalid`);
|
|
251
|
+
if ((start && !isFhirDateTime(start)) || (end && !isFhirDateTime(end))) {
|
|
252
|
+
throw new TypeError(`group_member_${index}_period_invalid`);
|
|
253
|
+
}
|
|
254
|
+
if (start && end && Date.parse(end) < Date.parse(start))
|
|
255
|
+
throw new TypeError(`group_member_${index}_period_invalid`);
|
|
256
|
+
return Object.freeze({ ...(start ? { start } : {}), ...(end ? { end } : {}) });
|
|
257
|
+
}
|
|
258
|
+
function containsAuthorizationProperty(value, seen = new WeakSet()) {
|
|
259
|
+
if (!value || typeof value !== 'object')
|
|
260
|
+
return false;
|
|
261
|
+
if (seen.has(value))
|
|
262
|
+
return false;
|
|
263
|
+
seen.add(value);
|
|
264
|
+
if (Array.isArray(value))
|
|
265
|
+
return value.some(item => containsAuthorizationProperty(item, seen));
|
|
266
|
+
return Object.entries(value).some(([name, nested]) => ['authorization', 'permission', 'scope'].includes(name) || containsAuthorizationProperty(nested, seen));
|
|
267
|
+
}
|
|
268
|
+
function strings(value) {
|
|
269
|
+
const normalized = optionalString(value);
|
|
270
|
+
return normalized ? [normalized] : [];
|
|
271
|
+
}
|
|
272
|
+
function optionalString(value) {
|
|
273
|
+
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
274
|
+
}
|
|
275
|
+
function isFhirDateTime(value) {
|
|
276
|
+
return /^\d{4}(?:-(?:0[1-9]|1[0-2])(?:-(?:0[1-9]|[12]\d|3[01])(?:T.+)?)?)?$/.test(value);
|
|
277
|
+
}
|
|
278
|
+
function isRecord(value) {
|
|
279
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
280
|
+
}
|
|
281
|
+
function fhirId(value, error) {
|
|
282
|
+
const id = optionalString(value);
|
|
283
|
+
if (!id || !/^[A-Za-z0-9.-]{1,64}$/.test(id))
|
|
284
|
+
throw new TypeError(error);
|
|
285
|
+
return id;
|
|
286
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './clinical-terminology.js';
|
|
|
5
5
|
export * from './digital-twin.js';
|
|
6
6
|
export * from './emergency.js';
|
|
7
7
|
export * from './financial.js';
|
|
8
|
+
export * from './group.js';
|
|
8
9
|
export * from './iso-jurisdictions.js';
|
|
9
10
|
export * from './organization-application.js';
|
|
10
11
|
export * from './research-study.js';
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from './clinical-terminology.js';
|
|
|
5
5
|
export * from './digital-twin.js';
|
|
6
6
|
export * from './emergency.js';
|
|
7
7
|
export * from './financial.js';
|
|
8
|
+
export * from './group.js';
|
|
8
9
|
export * from './iso-jurisdictions.js';
|
|
9
10
|
export * from './organization-application.js';
|
|
10
11
|
export * from './research-study.js';
|
package/dist/research-study.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export type ResearchStudyR5SearchParameter = Readonly<{
|
|
|
42
42
|
/** Exact resource-specific SearchParameters published by FHIR R5 5.0.0. */
|
|
43
43
|
export declare const ResearchStudyR5SearchParameterCatalog: readonly ResearchStudyR5SearchParameter[];
|
|
44
44
|
declare const standardSearchClaims: readonly `ResearchStudy.${string}`[];
|
|
45
|
-
declare const associatedPartyClaims: readonly ["ResearchStudy.
|
|
45
|
+
declare const associatedPartyClaims: readonly ["ResearchStudy.party-name", "ResearchStudy.party-role", "ResearchStudy.party-period-start", "ResearchStudy.party-period-end", "ResearchStudy.party-classifier", "ResearchStudy.party"];
|
|
46
46
|
/**
|
|
47
47
|
* Governed flat claims for ResearchStudy.
|
|
48
48
|
*
|
|
@@ -53,7 +53,7 @@ declare const associatedPartyClaims: readonly ["ResearchStudy.associated-party-n
|
|
|
53
53
|
*/
|
|
54
54
|
export declare const ResearchStudyFlatClaimCatalog: Readonly<{
|
|
55
55
|
standardSearch: readonly `ResearchStudy.${string}`[];
|
|
56
|
-
associatedParty: readonly ["ResearchStudy.
|
|
56
|
+
associatedParty: readonly ["ResearchStudy.party-name", "ResearchStudy.party-role", "ResearchStudy.party-period-start", "ResearchStudy.party-period-end", "ResearchStudy.party-classifier", "ResearchStudy.party"];
|
|
57
57
|
all: readonly `ResearchStudy.${string}`[];
|
|
58
58
|
}>;
|
|
59
59
|
export type ResearchStudyCoding = Readonly<{
|
|
@@ -89,6 +89,13 @@ export type ResearchStudyAssociatedPartyClaimProjection = Readonly<{
|
|
|
89
89
|
}>;
|
|
90
90
|
export type ResearchStudyR5SearchClaim = (typeof standardSearchClaims)[number];
|
|
91
91
|
export type ResearchStudyR5SearchClaims = Readonly<Partial<Record<ResearchStudyR5SearchClaim, readonly string[]>>>;
|
|
92
|
+
export type ResearchStudyR5FlatClaimsResource = Readonly<{
|
|
93
|
+
resourceType: 'ResearchStudy';
|
|
94
|
+
id: string;
|
|
95
|
+
meta: Readonly<{
|
|
96
|
+
claims: Readonly<Record<string, readonly string[]>>;
|
|
97
|
+
}>;
|
|
98
|
+
}>;
|
|
92
99
|
/**
|
|
93
100
|
* Projects the official resource-specific R5 SearchParameters from one native
|
|
94
101
|
* ResearchStudy into flat `resource.meta.claims`. Composite values use FHIR's
|
|
@@ -110,4 +117,13 @@ export declare function normalizeResearchStudyAssociatedParties(input: unknown):
|
|
|
110
117
|
* required when a later Bundle PATCH changes one party.
|
|
111
118
|
*/
|
|
112
119
|
export declare function projectResearchStudyAssociatedPartyClaims(input: unknown): readonly ResearchStudyAssociatedPartyClaimProjection[];
|
|
120
|
+
/** Projects native-shaped study input to the claims-only GW persistence shape. */
|
|
121
|
+
export declare function projectResearchStudyR5FlatClaimsResource(input: unknown): ResearchStudyR5FlatClaimsResource;
|
|
122
|
+
/** Projects one correlated claims-only GW resource per associated party. */
|
|
123
|
+
export declare function projectResearchStudyAssociatedPartyFlatClaimResources(input: Readonly<{
|
|
124
|
+
researchStudyId: string;
|
|
125
|
+
associatedParties: unknown;
|
|
126
|
+
}>): readonly ResearchStudyR5FlatClaimsResource[];
|
|
127
|
+
/** Validates and freezes a claims-only ResearchStudy GW resource. */
|
|
128
|
+
export declare function normalizeResearchStudyR5FlatClaimsResource(input: unknown): ResearchStudyR5FlatClaimsResource;
|
|
113
129
|
export {};
|
package/dist/research-study.js
CHANGED
|
@@ -90,12 +90,12 @@ export const ResearchStudyR5SearchParameterCatalog = Object.freeze([
|
|
|
90
90
|
]);
|
|
91
91
|
const standardSearchClaims = Object.freeze(ResearchStudyR5SearchParameterCatalog.map(parameter => `ResearchStudy.${parameter.code}`));
|
|
92
92
|
const associatedPartyClaims = Object.freeze([
|
|
93
|
-
'ResearchStudy.
|
|
94
|
-
'ResearchStudy.
|
|
95
|
-
'ResearchStudy.
|
|
96
|
-
'ResearchStudy.
|
|
97
|
-
'ResearchStudy.
|
|
98
|
-
'ResearchStudy.
|
|
93
|
+
'ResearchStudy.party-name',
|
|
94
|
+
'ResearchStudy.party-role',
|
|
95
|
+
'ResearchStudy.party-period-start',
|
|
96
|
+
'ResearchStudy.party-period-end',
|
|
97
|
+
'ResearchStudy.party-classifier',
|
|
98
|
+
'ResearchStudy.party',
|
|
99
99
|
]);
|
|
100
100
|
/**
|
|
101
101
|
* Governed flat claims for ResearchStudy.
|
|
@@ -171,15 +171,58 @@ export function projectResearchStudyAssociatedPartyClaims(input) {
|
|
|
171
171
|
return Object.freeze(parties.map(party => Object.freeze({
|
|
172
172
|
associatedParty: party,
|
|
173
173
|
claims: Object.freeze({
|
|
174
|
-
'ResearchStudy.
|
|
175
|
-
'ResearchStudy.
|
|
176
|
-
'ResearchStudy.
|
|
177
|
-
'ResearchStudy.
|
|
178
|
-
'ResearchStudy.
|
|
179
|
-
'ResearchStudy.
|
|
174
|
+
'ResearchStudy.party-name': Object.freeze(party.name ? [party.name] : []),
|
|
175
|
+
'ResearchStudy.party-role': Object.freeze(conceptValues([party.role])),
|
|
176
|
+
'ResearchStudy.party-period-start': Object.freeze((party.period || []).flatMap(period => period.start ? [period.start] : [])),
|
|
177
|
+
'ResearchStudy.party-period-end': Object.freeze((party.period || []).flatMap(period => period.end ? [period.end] : [])),
|
|
178
|
+
'ResearchStudy.party-classifier': Object.freeze(conceptValues(party.classifier || [])),
|
|
179
|
+
'ResearchStudy.party': Object.freeze(party.party ? [party.party.reference] : []),
|
|
180
180
|
}),
|
|
181
181
|
})));
|
|
182
182
|
}
|
|
183
|
+
/** Projects native-shaped study input to the claims-only GW persistence shape. */
|
|
184
|
+
export function projectResearchStudyR5FlatClaimsResource(input) {
|
|
185
|
+
if (!isRecord(input) || input.resourceType !== 'ResearchStudy')
|
|
186
|
+
throw new TypeError('research_study_resource_invalid');
|
|
187
|
+
const id = fhirId(input.id, 'research_study_flat_resource_invalid');
|
|
188
|
+
if (input.associatedParty !== undefined)
|
|
189
|
+
throw new TypeError('research_study_parties_require_separate_resources');
|
|
190
|
+
return normalizeResearchStudyR5FlatClaimsResource({
|
|
191
|
+
resourceType: 'ResearchStudy',
|
|
192
|
+
id,
|
|
193
|
+
meta: { claims: projectResearchStudyR5SearchClaims(input) },
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
/** Projects one correlated claims-only GW resource per associated party. */
|
|
197
|
+
export function projectResearchStudyAssociatedPartyFlatClaimResources(input) {
|
|
198
|
+
const id = fhirId(input.researchStudyId, 'research_study_flat_resource_invalid');
|
|
199
|
+
return Object.freeze(projectResearchStudyAssociatedPartyClaims(input.associatedParties).map(projection => {
|
|
200
|
+
const claims = Object.fromEntries(Object.entries(projection.claims).filter(([, values]) => values.length > 0));
|
|
201
|
+
return normalizeResearchStudyR5FlatClaimsResource({ resourceType: 'ResearchStudy', id, meta: { claims } });
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
/** Validates and freezes a claims-only ResearchStudy GW resource. */
|
|
205
|
+
export function normalizeResearchStudyR5FlatClaimsResource(input) {
|
|
206
|
+
if (!isRecord(input)
|
|
207
|
+
|| input.resourceType !== 'ResearchStudy'
|
|
208
|
+
|| Object.keys(input).some(key => !['resourceType', 'id', 'meta'].includes(key))) {
|
|
209
|
+
throw new TypeError('research_study_flat_resource_invalid');
|
|
210
|
+
}
|
|
211
|
+
const id = fhirId(input.id, 'research_study_flat_resource_invalid');
|
|
212
|
+
if (!isRecord(input.meta) || !isRecord(input.meta.claims))
|
|
213
|
+
throw new TypeError('research_study_flat_resource_invalid');
|
|
214
|
+
const claims = {};
|
|
215
|
+
for (const [name, rawValues] of Object.entries(input.meta.claims)) {
|
|
216
|
+
if (!ResearchStudyFlatClaimCatalog.all.includes(name)
|
|
217
|
+
|| !Array.isArray(rawValues)
|
|
218
|
+
|| rawValues.length === 0
|
|
219
|
+
|| rawValues.some(value => typeof value !== 'string' || !value.trim())) {
|
|
220
|
+
throw new TypeError('research_study_flat_claim_invalid');
|
|
221
|
+
}
|
|
222
|
+
claims[name] = Object.freeze(rawValues.map(value => value.trim()));
|
|
223
|
+
}
|
|
224
|
+
return Object.freeze({ resourceType: 'ResearchStudy', id, meta: Object.freeze({ claims: Object.freeze(claims) }) });
|
|
225
|
+
}
|
|
183
226
|
function normalizeAssociatedParty(value, index) {
|
|
184
227
|
if (!isRecord(value))
|
|
185
228
|
throw new TypeError(`research_study_associated_party_${index}_invalid`);
|
|
@@ -399,3 +442,9 @@ function isFhirDateTime(value) {
|
|
|
399
442
|
function isRecord(value) {
|
|
400
443
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
401
444
|
}
|
|
445
|
+
function fhirId(value, error) {
|
|
446
|
+
const id = optionalString(value);
|
|
447
|
+
if (!id || !/^[A-Za-z0-9.-]{1,64}$/.test(id))
|
|
448
|
+
throw new TypeError(error);
|
|
449
|
+
return id;
|
|
450
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vet-data-utils-ts",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Browser-safe governed VetChain data contracts",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Connecting Solution & Applications Ltd",
|
|
@@ -36,6 +36,10 @@
|
|
|
36
36
|
"types": "./dist/financial.d.ts",
|
|
37
37
|
"default": "./dist/financial.js"
|
|
38
38
|
},
|
|
39
|
+
"./group": {
|
|
40
|
+
"types": "./dist/group.d.ts",
|
|
41
|
+
"default": "./dist/group.js"
|
|
42
|
+
},
|
|
39
43
|
"./iso-jurisdictions": {
|
|
40
44
|
"types": "./dist/iso-jurisdictions.d.ts",
|
|
41
45
|
"default": "./dist/iso-jurisdictions.js"
|