@openfn/language-fhir-4 0.4.0 → 0.4.1
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/dist/index.cjs +38 -21
- package/dist/index.js +38 -21
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -117,11 +117,11 @@ var logResponse = (response, query) => {
|
|
|
117
117
|
}
|
|
118
118
|
const message = `${method} ${urlWithQuery} - ${statusCode} in ${duration}ms`;
|
|
119
119
|
if (response instanceof Error) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
console.error(message);
|
|
121
|
+
console.error("response body: ");
|
|
122
|
+
console.error(response.body || "[no body]");
|
|
123
123
|
} else {
|
|
124
|
-
|
|
124
|
+
console.log(message);
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
return response;
|
|
@@ -151,50 +151,64 @@ var request = (method, path, options) => {
|
|
|
151
151
|
throw e;
|
|
152
152
|
});
|
|
153
153
|
};
|
|
154
|
-
function logValidationErrors(response,
|
|
154
|
+
function logValidationErrors(response, logger = console) {
|
|
155
155
|
const error = JSON.parse(response.body);
|
|
156
156
|
if (error.issue && error.issue.length) {
|
|
157
157
|
delete response.body;
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
logger.log();
|
|
159
|
+
logger.error("FHIR server reports validation issues:");
|
|
160
160
|
const errCount = error.issue.reduce(
|
|
161
161
|
(count, e) => e.severity === "error" ? count + 1 : count,
|
|
162
162
|
0
|
|
163
163
|
);
|
|
164
164
|
if (errCount) {
|
|
165
|
-
|
|
165
|
+
logger.error(` - ${errCount} Errors`);
|
|
166
166
|
}
|
|
167
167
|
const warnCount = error.issue.reduce(
|
|
168
168
|
(count, e) => e.severity === "error" ? count + 1 : count,
|
|
169
169
|
0
|
|
170
170
|
);
|
|
171
171
|
if (warnCount) {
|
|
172
|
-
|
|
172
|
+
logger.error(` - ${warnCount} Warnings`);
|
|
173
173
|
}
|
|
174
|
-
|
|
174
|
+
logger.log();
|
|
175
175
|
const groups = {};
|
|
176
176
|
error.issue.forEach((issue) => {
|
|
177
|
-
var _a, _b;
|
|
177
|
+
var _a, _b, _c;
|
|
178
178
|
try {
|
|
179
|
-
let id2 =
|
|
180
|
-
if (
|
|
181
|
-
id2 =
|
|
179
|
+
let id2 = "unidentified resource";
|
|
180
|
+
if (issue.location) {
|
|
181
|
+
id2 = issue.location[0];
|
|
182
|
+
if (id2.startsWith("Bundle")) {
|
|
183
|
+
id2 = id2.split("*").at(1) ?? id2;
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
console.log({ issue });
|
|
182
187
|
}
|
|
183
188
|
groups[id2] ?? (groups[id2] = {});
|
|
184
189
|
(_a = groups[id2])[_b = issue.severity] ?? (_a[_b] = []);
|
|
185
|
-
|
|
190
|
+
const path = issue.location[0];
|
|
191
|
+
(_c = groups[id2][issue.severity])[path] ?? (_c[path] = []);
|
|
192
|
+
groups[id2][issue.severity][path].push(issue.diagnostics);
|
|
186
193
|
} catch (e) {
|
|
187
|
-
|
|
194
|
+
logger.log("error parsing issue at ", issue.location);
|
|
195
|
+
console.log(e);
|
|
188
196
|
}
|
|
189
197
|
});
|
|
190
198
|
for (const resource in groups) {
|
|
191
|
-
|
|
199
|
+
logger.log(`${resource} issues:`);
|
|
192
200
|
["error", "warning"].forEach((type) => {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
201
|
+
if (type in groups[resource]) {
|
|
202
|
+
logger.log(` ${type}s:`.toUpperCase());
|
|
203
|
+
for (const path in groups[resource][type]) {
|
|
204
|
+
logger.log();
|
|
205
|
+
logger.log(" ", path);
|
|
206
|
+
for (const message of groups[resource][type][path]) {
|
|
207
|
+
logger.log(" -", message);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
logger.log();
|
|
196
211
|
}
|
|
197
|
-
logger2.log();
|
|
198
212
|
});
|
|
199
213
|
}
|
|
200
214
|
response.validationIssues = groups;
|
|
@@ -785,6 +799,9 @@ var composite = (object, key, value2) => {
|
|
|
785
799
|
k.push("CodeableConcept");
|
|
786
800
|
} else if (value2.reference) {
|
|
787
801
|
k.push("Reference");
|
|
802
|
+
}
|
|
803
|
+
if (value2.value && typeof value2.value === "number") {
|
|
804
|
+
k.push("Quantity");
|
|
788
805
|
} else if (value2.id && value2.meta && value2.resourceType) {
|
|
789
806
|
k.push("Reference");
|
|
790
807
|
value2 = reference(value2);
|
package/dist/index.js
CHANGED
|
@@ -75,11 +75,11 @@ var logResponse = (response, query) => {
|
|
|
75
75
|
}
|
|
76
76
|
const message = `${method} ${urlWithQuery} - ${statusCode} in ${duration}ms`;
|
|
77
77
|
if (response instanceof Error) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
console.error(message);
|
|
79
|
+
console.error("response body: ");
|
|
80
|
+
console.error(response.body || "[no body]");
|
|
81
81
|
} else {
|
|
82
|
-
|
|
82
|
+
console.log(message);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
return response;
|
|
@@ -109,50 +109,64 @@ var request = (method, path, options) => {
|
|
|
109
109
|
throw e;
|
|
110
110
|
});
|
|
111
111
|
};
|
|
112
|
-
function logValidationErrors(response,
|
|
112
|
+
function logValidationErrors(response, logger = console) {
|
|
113
113
|
const error = JSON.parse(response.body);
|
|
114
114
|
if (error.issue && error.issue.length) {
|
|
115
115
|
delete response.body;
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
logger.log();
|
|
117
|
+
logger.error("FHIR server reports validation issues:");
|
|
118
118
|
const errCount = error.issue.reduce(
|
|
119
119
|
(count, e) => e.severity === "error" ? count + 1 : count,
|
|
120
120
|
0
|
|
121
121
|
);
|
|
122
122
|
if (errCount) {
|
|
123
|
-
|
|
123
|
+
logger.error(` - ${errCount} Errors`);
|
|
124
124
|
}
|
|
125
125
|
const warnCount = error.issue.reduce(
|
|
126
126
|
(count, e) => e.severity === "error" ? count + 1 : count,
|
|
127
127
|
0
|
|
128
128
|
);
|
|
129
129
|
if (warnCount) {
|
|
130
|
-
|
|
130
|
+
logger.error(` - ${warnCount} Warnings`);
|
|
131
131
|
}
|
|
132
|
-
|
|
132
|
+
logger.log();
|
|
133
133
|
const groups = {};
|
|
134
134
|
error.issue.forEach((issue) => {
|
|
135
|
-
var _a, _b;
|
|
135
|
+
var _a, _b, _c;
|
|
136
136
|
try {
|
|
137
|
-
let id2 =
|
|
138
|
-
if (
|
|
139
|
-
id2 =
|
|
137
|
+
let id2 = "unidentified resource";
|
|
138
|
+
if (issue.location) {
|
|
139
|
+
id2 = issue.location[0];
|
|
140
|
+
if (id2.startsWith("Bundle")) {
|
|
141
|
+
id2 = id2.split("*").at(1) ?? id2;
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
console.log({ issue });
|
|
140
145
|
}
|
|
141
146
|
groups[id2] ?? (groups[id2] = {});
|
|
142
147
|
(_a = groups[id2])[_b = issue.severity] ?? (_a[_b] = []);
|
|
143
|
-
|
|
148
|
+
const path = issue.location[0];
|
|
149
|
+
(_c = groups[id2][issue.severity])[path] ?? (_c[path] = []);
|
|
150
|
+
groups[id2][issue.severity][path].push(issue.diagnostics);
|
|
144
151
|
} catch (e) {
|
|
145
|
-
|
|
152
|
+
logger.log("error parsing issue at ", issue.location);
|
|
153
|
+
console.log(e);
|
|
146
154
|
}
|
|
147
155
|
});
|
|
148
156
|
for (const resource in groups) {
|
|
149
|
-
|
|
157
|
+
logger.log(`${resource} issues:`);
|
|
150
158
|
["error", "warning"].forEach((type) => {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
159
|
+
if (type in groups[resource]) {
|
|
160
|
+
logger.log(` ${type}s:`.toUpperCase());
|
|
161
|
+
for (const path in groups[resource][type]) {
|
|
162
|
+
logger.log();
|
|
163
|
+
logger.log(" ", path);
|
|
164
|
+
for (const message of groups[resource][type][path]) {
|
|
165
|
+
logger.log(" -", message);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
logger.log();
|
|
154
169
|
}
|
|
155
|
-
logger2.log();
|
|
156
170
|
});
|
|
157
171
|
}
|
|
158
172
|
response.validationIssues = groups;
|
|
@@ -755,6 +769,9 @@ var composite = (object, key, value2) => {
|
|
|
755
769
|
k.push("CodeableConcept");
|
|
756
770
|
} else if (value2.reference) {
|
|
757
771
|
k.push("Reference");
|
|
772
|
+
}
|
|
773
|
+
if (value2.value && typeof value2.value === "number") {
|
|
774
|
+
k.push("Quantity");
|
|
758
775
|
} else if (value2.id && value2.meta && value2.resourceType) {
|
|
759
776
|
k.push("Reference");
|
|
760
777
|
value2 = reference(value2);
|