gdc-common-utils-ts 1.14.13 → 1.14.15

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.
@@ -0,0 +1,134 @@
1
+ import { ClaimsPersonSchemaorg } from '../constants/schemaorg.js';
2
+ import { buildFhirParametersResourceFromSearchParams, buildSearchQueryString, } from './fhir-search.js';
3
+ function cloneClaims(claims) {
4
+ return { ...(claims || {}) };
5
+ }
6
+ function normalizeEmployeeSearchClaims(claims) {
7
+ const normalized = {};
8
+ for (const [key, value] of Object.entries(claims || {})) {
9
+ if (key === '@context')
10
+ continue;
11
+ normalized[key] = value;
12
+ }
13
+ return normalized;
14
+ }
15
+ function inferEmployeeEntryType(method) {
16
+ switch (method) {
17
+ case 'DELETE':
18
+ return 'Employee-delete-request-v1.0';
19
+ case 'PUT':
20
+ case 'PATCH':
21
+ return 'Employee-update-request-v1.0';
22
+ case 'GET':
23
+ return 'Employee-search-request-v1.0';
24
+ case 'POST':
25
+ default:
26
+ return 'Employee-create-request-v1.0';
27
+ }
28
+ }
29
+ /**
30
+ * Builds canonical `org.schema.Person.*` employee claims from semantic input.
31
+ */
32
+ export function buildEmployeeClaims(input) {
33
+ const claims = {
34
+ '@context': 'org.schema',
35
+ ...cloneClaims(input.additionalClaims),
36
+ };
37
+ if (typeof input.identifier === 'string' && input.identifier.trim()) {
38
+ claims[ClaimsPersonSchemaorg.identifier] = input.identifier.trim();
39
+ }
40
+ if (typeof input.email === 'string' && input.email.trim()) {
41
+ claims[ClaimsPersonSchemaorg.email] = input.email.trim();
42
+ }
43
+ if (typeof input.role === 'string' && input.role.trim()) {
44
+ claims[ClaimsPersonSchemaorg.hasOccupationalRoleValue] = input.role.trim();
45
+ }
46
+ if (typeof input.worksFor === 'string' && input.worksFor.trim()) {
47
+ claims[ClaimsPersonSchemaorg.worksFor] = input.worksFor.trim();
48
+ }
49
+ if (typeof input.memberOf === 'string' && input.memberOf.trim()) {
50
+ claims[ClaimsPersonSchemaorg.memberOf] = input.memberOf.trim();
51
+ }
52
+ if (typeof input.memberOfOrgTaxId === 'string' && input.memberOfOrgTaxId.trim()) {
53
+ claims[ClaimsPersonSchemaorg.memberOfOrgTaxId] = input.memberOfOrgTaxId.trim();
54
+ }
55
+ return claims;
56
+ }
57
+ /**
58
+ * Builds a claims-first employee batch entry from the minimum semantic input.
59
+ *
60
+ * Callers only provide the operation method, employee claims, and optional
61
+ * resource id. The helper places claims in the canonical `resource.meta.claims`
62
+ * location and infers the business `type` internally.
63
+ */
64
+ export function buildEmployeeBatchEntry(input) {
65
+ const claims = cloneClaims(input.claims);
66
+ const resourceType = input.resourceType || 'Employee';
67
+ return {
68
+ type: input.type || inferEmployeeEntryType(input.method),
69
+ request: { method: input.method },
70
+ resource: {
71
+ resourceType,
72
+ ...(input.resourceId ? { id: input.resourceId } : {}),
73
+ meta: { claims },
74
+ },
75
+ };
76
+ }
77
+ /**
78
+ * Builds a canonical employee `_batch` bundle from one or more employee batch
79
+ * entries.
80
+ */
81
+ export function buildEmployeeBatchBundle(input) {
82
+ return {
83
+ resourceType: 'Bundle',
84
+ type: 'batch',
85
+ entry: [...input.entries].map((entry) => buildEmployeeBatchEntry(entry)),
86
+ };
87
+ }
88
+ /**
89
+ * Builds the legacy query-string employee search target kept for compatibility
90
+ * with older `_search` wrappers.
91
+ */
92
+ export function buildEmployeeSearchQuery(input = {}) {
93
+ const resourceType = input.resourceType || 'Employee';
94
+ const query = buildSearchQueryString(normalizeEmployeeSearchClaims(input.claims));
95
+ return query ? `${resourceType}?${query}` : resourceType;
96
+ }
97
+ /**
98
+ * Builds a canonical employee search bundle.
99
+ *
100
+ * Defaults to `POST + Parameters`. Set `method` or `encoding` to legacy GET
101
+ * only when talking to older search consumers.
102
+ */
103
+ export function buildEmployeeSearchBundle(input = {}) {
104
+ const resourceType = input.resourceType || 'Employee';
105
+ const claims = normalizeEmployeeSearchClaims(input.claims);
106
+ const method = input.method || (input.encoding === 'get-query' ? 'GET' : 'POST');
107
+ if (method === 'GET') {
108
+ return {
109
+ resourceType: 'Bundle',
110
+ type: 'batch',
111
+ entry: [
112
+ {
113
+ request: {
114
+ method: 'GET',
115
+ url: buildEmployeeSearchQuery({ ...input, resourceType }),
116
+ },
117
+ },
118
+ ],
119
+ };
120
+ }
121
+ return {
122
+ resourceType: 'Bundle',
123
+ type: 'batch',
124
+ entry: [
125
+ {
126
+ request: {
127
+ method: 'POST',
128
+ url: `${resourceType}/_search`,
129
+ },
130
+ resource: buildFhirParametersResourceFromSearchParams(claims),
131
+ },
132
+ ],
133
+ };
134
+ }
@@ -0,0 +1,26 @@
1
+ import { ParameterData } from '../models/params';
2
+ export type SearchParameterPrimitive = string | number | boolean | readonly (string | number | boolean)[];
3
+ export type SearchRequestEncoding = 'get-query' | 'post-parameters';
4
+ export type FhirParametersParameter = {
5
+ name: string;
6
+ valueString?: string;
7
+ valueCode?: string;
8
+ valueBoolean?: boolean;
9
+ valueInteger?: number;
10
+ valueDecimal?: number;
11
+ valueUri?: string;
12
+ valueReference?: {
13
+ reference: string;
14
+ };
15
+ valueCoding?: {
16
+ system?: string;
17
+ code: string;
18
+ };
19
+ };
20
+ export type FhirParametersResource = {
21
+ resourceType: 'Parameters';
22
+ parameter: FhirParametersParameter[];
23
+ };
24
+ export declare function buildSearchQueryString(searchParams: Readonly<Record<string, SearchParameterPrimitive | undefined>>): string;
25
+ export declare function buildFhirParametersResourceFromSearchParams(searchParams: Readonly<Record<string, SearchParameterPrimitive | undefined>>): FhirParametersResource;
26
+ export declare function buildFhirParametersResourceFromParameterData(parameters: ReadonlyArray<ParameterData>): FhirParametersResource;
@@ -0,0 +1,84 @@
1
+ function normalizeSearchPrimitiveValues(value) {
2
+ const values = Array.isArray(value) ? [...value] : [value];
3
+ return values
4
+ .map((item) => typeof item === 'string' ? item.trim() : item)
5
+ .filter((item) => item !== '' && item !== undefined && item !== null);
6
+ }
7
+ function toPrimitiveString(value) {
8
+ return typeof value === 'string' ? value.trim() : String(value);
9
+ }
10
+ function toSearchParameter(name, value) {
11
+ if (typeof value === 'boolean') {
12
+ return { name, valueBoolean: value };
13
+ }
14
+ if (typeof value === 'number') {
15
+ return Number.isInteger(value)
16
+ ? { name, valueInteger: value }
17
+ : { name, valueDecimal: value };
18
+ }
19
+ return { name, valueString: value.trim() };
20
+ }
21
+ function flattenParameterDataValue(parameter) {
22
+ const name = String(parameter?.name || '').trim();
23
+ if (!name) {
24
+ return undefined;
25
+ }
26
+ if (parameter.type === 'reference') {
27
+ const reference = String(parameter.reference || parameter.value || '').trim();
28
+ return reference ? { name, valueReference: { reference } } : undefined;
29
+ }
30
+ if (parameter.type === 'token') {
31
+ const code = String(parameter.value || '').trim();
32
+ if (!code) {
33
+ return undefined;
34
+ }
35
+ return parameter.system
36
+ ? { name, valueCoding: { system: String(parameter.system).trim(), code } }
37
+ : { name, valueCode: code };
38
+ }
39
+ if (parameter.type === 'uri') {
40
+ const value = String(parameter.value || '').trim();
41
+ return value ? { name, valueUri: value } : undefined;
42
+ }
43
+ if (typeof parameter.value === 'number') {
44
+ return Number.isInteger(parameter.value)
45
+ ? { name, valueInteger: parameter.value }
46
+ : { name, valueDecimal: parameter.value };
47
+ }
48
+ const value = String(parameter.value || '').trim();
49
+ return value ? { name, valueString: value } : undefined;
50
+ }
51
+ export function buildSearchQueryString(searchParams) {
52
+ const params = new URLSearchParams();
53
+ for (const [key, value] of Object.entries(searchParams)) {
54
+ if (value === undefined || value === null)
55
+ continue;
56
+ const normalized = normalizeSearchPrimitiveValues(value);
57
+ if (normalized.length === 0)
58
+ continue;
59
+ params.set(key, normalized.map(toPrimitiveString).join(','));
60
+ }
61
+ return params.toString();
62
+ }
63
+ export function buildFhirParametersResourceFromSearchParams(searchParams) {
64
+ const parameter = [];
65
+ for (const [name, value] of Object.entries(searchParams)) {
66
+ if (value === undefined || value === null)
67
+ continue;
68
+ for (const item of normalizeSearchPrimitiveValues(value)) {
69
+ parameter.push(toSearchParameter(name, item));
70
+ }
71
+ }
72
+ return {
73
+ resourceType: 'Parameters',
74
+ parameter,
75
+ };
76
+ }
77
+ export function buildFhirParametersResourceFromParameterData(parameters) {
78
+ return {
79
+ resourceType: 'Parameters',
80
+ parameter: parameters
81
+ .map((parameter) => flattenParameterDataValue(parameter))
82
+ .filter((parameter) => Boolean(parameter)),
83
+ };
84
+ }
@@ -14,17 +14,19 @@ export * from './did-resolution';
14
14
  export * from './dataspace-discovery';
15
15
  export * from './dataspace-discovery-defaults';
16
16
  export * from './dataspace-protocol';
17
+ export * from './employee';
17
18
  export * from './didcomm';
18
19
  export * from './didcomm-submit';
19
20
  export * from './didcomm-submit-policy';
20
21
  export * from './discovery-normalization';
21
22
  export * from './format-converter';
22
23
  export * from './fhir-cid';
24
+ export * from './fhir-search';
23
25
  export * from './communication-fhir-r4';
24
26
  export * from './communication-document-reference';
25
27
  export * from './communication-bundle-document-request';
26
28
  export * from './communication-identity';
27
- export * from './communication-bundle-session';
29
+ export * from './communication-attached-bundle-session';
28
30
  export * from './clinical-resource-converters';
29
31
  export * from './clinical-resource-view';
30
32
  export * from './fhir-validator';
@@ -14,17 +14,19 @@ export * from './did-resolution.js';
14
14
  export * from './dataspace-discovery.js';
15
15
  export * from './dataspace-discovery-defaults.js';
16
16
  export * from './dataspace-protocol.js';
17
+ export * from './employee.js';
17
18
  export * from './didcomm.js';
18
19
  export * from './didcomm-submit.js';
19
20
  export * from './didcomm-submit-policy.js';
20
21
  export * from './discovery-normalization.js';
21
22
  export * from './format-converter.js';
22
23
  export * from './fhir-cid.js';
24
+ export * from './fhir-search.js';
23
25
  export * from './communication-fhir-r4.js';
24
26
  export * from './communication-document-reference.js';
25
27
  export * from './communication-bundle-document-request.js';
26
28
  export * from './communication-identity.js';
27
- export * from './communication-bundle-session.js';
29
+ export * from './communication-attached-bundle-session.js';
28
30
  export * from './clinical-resource-converters.js';
29
31
  export * from './clinical-resource-view.js';
30
32
  export * from './fhir-validator.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gdc-common-utils-ts",
3
- "version": "1.14.13",
3
+ "version": "1.14.15",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },