96wutang
08/16/2023, 12:10 PMrahul1
08/16/2023, 4:55 PM96wutang
08/16/2023, 7:10 PMthrowing an error if it cannot connect would be expected behavior
Yes but stopping the whole server .. that was my confusion.
About the use case, when a resource is created I need to convert it to HL7v2 and synchronize with another system(using TCP/MLLP protocol).
Sharing a code snippet that might be helpful aswell.
export async function handler(medplum: MedplumClient, event: BotEvent): Promise<any> {
const encounter = event.input as Encounter;
const message : HL7Message = mapResource(encounter);
const config : Hl7ClientOptions = { ... };
const client : Hl7Client = new Hl7Client(config);
await client.send(message);
}rahul1
08/16/2023, 7:13 PMrahul1
08/16/2023, 7:13 PM96wutang
08/16/2023, 7:14 PM96wutang
08/16/2023, 7:16 PMconst wrappedCode = `
const exports = {};
// Start user code
${code}
// End user code
(async () => {
const { baseUrl, accessToken, contentType, secrets } = event;
const medplum = new MedplumClient({
baseUrl,
fetch,
});
medplum.setAccessToken(accessToken);
try {
let input = event.input;
if (contentType === ContentType.HL7_V2 && input) {
input = Hl7Message.parse(input);
}
let result = await exports.handler(medplum, { input, contentType, secrets });
if (contentType === ContentType.HL7_V2 && result) {
result = result.toString();
}
return result;
} catch (err) {
if (err instanceof Error) {
console.log("Unhandled error: " + err.message + "\\n" + err.stack);
} else if (typeof err === "object") {
console.log("Unhandled error: " + JSON.stringify(err, undefined, 2));
} else {
console.log("Unhandled error: " + err);
}
throw err;
}
})();
`;rahul1
08/16/2023, 7:17 PM96wutang
08/16/2023, 7:18 PM