@openfn/language-fhir-4 0.3.2 → 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 +72 -10
- package/dist/index.js +72 -10
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -129,7 +129,7 @@ var logResponse = (response, query) => {
|
|
|
129
129
|
var request = (method, path, options) => {
|
|
130
130
|
(0, import_util.assertRelativeUrl)(path);
|
|
131
131
|
const { configuration, ...otherOptions } = options;
|
|
132
|
-
const fullPath = import_node_path.default.join(configuration.apiPath ?? "", path);
|
|
132
|
+
const fullPath = import_node_path.default.join(configuration.apiPath ?? "/fhir", path);
|
|
133
133
|
const headers = addAuth(options);
|
|
134
134
|
const opts = {
|
|
135
135
|
...otherOptions,
|
|
@@ -144,20 +144,79 @@ var request = (method, path, options) => {
|
|
|
144
144
|
baseUrl: configuration.baseUrl,
|
|
145
145
|
parseAs: "json"
|
|
146
146
|
};
|
|
147
|
-
return (0, import_util.request)(method, fullPath, opts).then(logResponse).catch(async (e) => {
|
|
147
|
+
return (0, import_util.request)(method, fullPath, opts).then(logResponse).then().catch(async (e) => {
|
|
148
148
|
if (e.headers && "content-type" in e.headers && e.headers["content-type"].match(/fhir\+json/)) {
|
|
149
|
-
|
|
150
|
-
e.body = error;
|
|
151
|
-
if (error.issue && error.issue.length) {
|
|
152
|
-
console.error("Error from FHIR server:");
|
|
153
|
-
error.issue.forEach((issue) => {
|
|
154
|
-
console.error(issue.diagnostics);
|
|
155
|
-
});
|
|
156
|
-
}
|
|
149
|
+
logValidationErrors(e);
|
|
157
150
|
}
|
|
158
151
|
throw e;
|
|
159
152
|
});
|
|
160
153
|
};
|
|
154
|
+
function logValidationErrors(response, logger = console) {
|
|
155
|
+
const error = JSON.parse(response.body);
|
|
156
|
+
if (error.issue && error.issue.length) {
|
|
157
|
+
delete response.body;
|
|
158
|
+
logger.log();
|
|
159
|
+
logger.error("FHIR server reports validation issues:");
|
|
160
|
+
const errCount = error.issue.reduce(
|
|
161
|
+
(count, e) => e.severity === "error" ? count + 1 : count,
|
|
162
|
+
0
|
|
163
|
+
);
|
|
164
|
+
if (errCount) {
|
|
165
|
+
logger.error(` - ${errCount} Errors`);
|
|
166
|
+
}
|
|
167
|
+
const warnCount = error.issue.reduce(
|
|
168
|
+
(count, e) => e.severity === "error" ? count + 1 : count,
|
|
169
|
+
0
|
|
170
|
+
);
|
|
171
|
+
if (warnCount) {
|
|
172
|
+
logger.error(` - ${warnCount} Warnings`);
|
|
173
|
+
}
|
|
174
|
+
logger.log();
|
|
175
|
+
const groups = {};
|
|
176
|
+
error.issue.forEach((issue) => {
|
|
177
|
+
var _a, _b, _c;
|
|
178
|
+
try {
|
|
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 });
|
|
187
|
+
}
|
|
188
|
+
groups[id2] ?? (groups[id2] = {});
|
|
189
|
+
(_a = groups[id2])[_b = issue.severity] ?? (_a[_b] = []);
|
|
190
|
+
const path = issue.location[0];
|
|
191
|
+
(_c = groups[id2][issue.severity])[path] ?? (_c[path] = []);
|
|
192
|
+
groups[id2][issue.severity][path].push(issue.diagnostics);
|
|
193
|
+
} catch (e) {
|
|
194
|
+
logger.log("error parsing issue at ", issue.location);
|
|
195
|
+
console.log(e);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
for (const resource in groups) {
|
|
199
|
+
logger.log(`${resource} issues:`);
|
|
200
|
+
["error", "warning"].forEach((type) => {
|
|
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();
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
response.validationIssues = groups;
|
|
215
|
+
} else {
|
|
216
|
+
response.body = error;
|
|
217
|
+
}
|
|
218
|
+
return response;
|
|
219
|
+
}
|
|
161
220
|
function collectRefs(value2) {
|
|
162
221
|
if (!value2 || typeof value2 !== "object")
|
|
163
222
|
return [];
|
|
@@ -740,6 +799,9 @@ var composite = (object, key, value2) => {
|
|
|
740
799
|
k.push("CodeableConcept");
|
|
741
800
|
} else if (value2.reference) {
|
|
742
801
|
k.push("Reference");
|
|
802
|
+
}
|
|
803
|
+
if (value2.value && typeof value2.value === "number") {
|
|
804
|
+
k.push("Quantity");
|
|
743
805
|
} else if (value2.id && value2.meta && value2.resourceType) {
|
|
744
806
|
k.push("Reference");
|
|
745
807
|
value2 = reference(value2);
|
package/dist/index.js
CHANGED
|
@@ -87,7 +87,7 @@ var logResponse = (response, query) => {
|
|
|
87
87
|
var request = (method, path, options) => {
|
|
88
88
|
assertRelativeUrl(path);
|
|
89
89
|
const { configuration, ...otherOptions } = options;
|
|
90
|
-
const fullPath = nodepath.join(configuration.apiPath ?? "", path);
|
|
90
|
+
const fullPath = nodepath.join(configuration.apiPath ?? "/fhir", path);
|
|
91
91
|
const headers = addAuth(options);
|
|
92
92
|
const opts = {
|
|
93
93
|
...otherOptions,
|
|
@@ -102,20 +102,79 @@ var request = (method, path, options) => {
|
|
|
102
102
|
baseUrl: configuration.baseUrl,
|
|
103
103
|
parseAs: "json"
|
|
104
104
|
};
|
|
105
|
-
return commonRequest(method, fullPath, opts).then(logResponse).catch(async (e) => {
|
|
105
|
+
return commonRequest(method, fullPath, opts).then(logResponse).then().catch(async (e) => {
|
|
106
106
|
if (e.headers && "content-type" in e.headers && e.headers["content-type"].match(/fhir\+json/)) {
|
|
107
|
-
|
|
108
|
-
e.body = error;
|
|
109
|
-
if (error.issue && error.issue.length) {
|
|
110
|
-
console.error("Error from FHIR server:");
|
|
111
|
-
error.issue.forEach((issue) => {
|
|
112
|
-
console.error(issue.diagnostics);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
107
|
+
logValidationErrors(e);
|
|
115
108
|
}
|
|
116
109
|
throw e;
|
|
117
110
|
});
|
|
118
111
|
};
|
|
112
|
+
function logValidationErrors(response, logger = console) {
|
|
113
|
+
const error = JSON.parse(response.body);
|
|
114
|
+
if (error.issue && error.issue.length) {
|
|
115
|
+
delete response.body;
|
|
116
|
+
logger.log();
|
|
117
|
+
logger.error("FHIR server reports validation issues:");
|
|
118
|
+
const errCount = error.issue.reduce(
|
|
119
|
+
(count, e) => e.severity === "error" ? count + 1 : count,
|
|
120
|
+
0
|
|
121
|
+
);
|
|
122
|
+
if (errCount) {
|
|
123
|
+
logger.error(` - ${errCount} Errors`);
|
|
124
|
+
}
|
|
125
|
+
const warnCount = error.issue.reduce(
|
|
126
|
+
(count, e) => e.severity === "error" ? count + 1 : count,
|
|
127
|
+
0
|
|
128
|
+
);
|
|
129
|
+
if (warnCount) {
|
|
130
|
+
logger.error(` - ${warnCount} Warnings`);
|
|
131
|
+
}
|
|
132
|
+
logger.log();
|
|
133
|
+
const groups = {};
|
|
134
|
+
error.issue.forEach((issue) => {
|
|
135
|
+
var _a, _b, _c;
|
|
136
|
+
try {
|
|
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 });
|
|
145
|
+
}
|
|
146
|
+
groups[id2] ?? (groups[id2] = {});
|
|
147
|
+
(_a = groups[id2])[_b = issue.severity] ?? (_a[_b] = []);
|
|
148
|
+
const path = issue.location[0];
|
|
149
|
+
(_c = groups[id2][issue.severity])[path] ?? (_c[path] = []);
|
|
150
|
+
groups[id2][issue.severity][path].push(issue.diagnostics);
|
|
151
|
+
} catch (e) {
|
|
152
|
+
logger.log("error parsing issue at ", issue.location);
|
|
153
|
+
console.log(e);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
for (const resource in groups) {
|
|
157
|
+
logger.log(`${resource} issues:`);
|
|
158
|
+
["error", "warning"].forEach((type) => {
|
|
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();
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
response.validationIssues = groups;
|
|
173
|
+
} else {
|
|
174
|
+
response.body = error;
|
|
175
|
+
}
|
|
176
|
+
return response;
|
|
177
|
+
}
|
|
119
178
|
function collectRefs(value2) {
|
|
120
179
|
if (!value2 || typeof value2 !== "object")
|
|
121
180
|
return [];
|
|
@@ -710,6 +769,9 @@ var composite = (object, key, value2) => {
|
|
|
710
769
|
k.push("CodeableConcept");
|
|
711
770
|
} else if (value2.reference) {
|
|
712
771
|
k.push("Reference");
|
|
772
|
+
}
|
|
773
|
+
if (value2.value && typeof value2.value === "number") {
|
|
774
|
+
k.push("Quantity");
|
|
713
775
|
} else if (value2.id && value2.meta && value2.resourceType) {
|
|
714
776
|
k.push("Reference");
|
|
715
777
|
value2 = reference(value2);
|