nextgenhealthcare / connect-examples Goto Github PK
View Code? Open in Web Editor NEWExample channels, code templates, and more!
License: Mozilla Public License 2.0
Example channels, code templates, and more!
License: Mozilla Public License 2.0
/**
* Determines the type of a given variable.
* If the variable is a Java instance, it returns the Java class name.
* If the variable is a JS object, it returns the JS constructor name (if available)
* or extracts the type from the default toString representation (as a fallback).
* Otherwise, it returns the JS primitive type.
*
* @param {any} variable The variable whose type needs to be determined.
* @return {string} The type of the variable.
*/
function determineVariableType(variable) {
// Check for Java instances
if (variable instanceof java.lang.Object) {
return variable.class.name;
}
// Check for JS objects (excluding null)
if (typeof variable === 'object') {
// If constructor.name is available, use it. Otherwise, use the toString fallback and extract the type
if (variable && variable.constructor && variable.constructor.name) {
return variable.constructor.name;
} else {
let toStringType = Object.prototype.toString.call(variable);
return toStringType.slice(8, -1); // Extracts "Type" from "[object Type]"
}
}
// Return JS primitive type
return typeof variable;
}
ERROR OUTPUT
Transformer error
ERROR MESSAGE: Error evaluating transformer
com.mirth.connect.server.MirthJavascriptTransformerException:
CHANNEL: HTTP_HWSAFE_DOCUMENT_TO_HL7_ORU_AHC
CONNECTOR: sourceConnector
SCRIPT SOURCE:
SOURCE CODE:
1649: }
1650: eval('importPackage(' + Packages.java.lang.Class.forName(className).getPackage().getName() + ')');
1651: }
1652: }
1653: function doScript() {
1654: msg = JSON.parse(connectorMessage.getTransformedData());
1655: tmp = new XML(template);
1656: function filterRule1() {
1657: if(connectorMessage.getRawData().toString().length() > 0 ) {
1658: return true;
LINE NUMBER: 1654
DETAILS: SyntaxError: Empty JSON string
at e31fd331-0a80-41b3-9971-afd75e1760c3_JavaScript_Filter_Transformer_0:1654 (doScript)
at e31fd331-0a80-41b3-9971-afd75e1760c3_JavaScript_Filter_Transformer_0:1752
at com.mirth.connect.server.transformers.JavaScriptFilterTransformer$FilterTransformerTask.doCall(JavaScriptFilterTransformer.java:235)
at com.mirth.connect.server.transformers.JavaScriptFilterTransformer$FilterTransformerTask.doCall(JavaScriptFilterTransformer.java:187)
at com.mirth.connect.server.util.javascript.JavaScriptTask.call(JavaScriptTask.java:114)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.base/java.lang.Thread.run(Thread.java:831)
The error message indicates that there is an empty JSON string on line 1654 of the code. This error is preventing the transformer from being evaluated properly. It seems that the transformer is part of a channel called HTTP_HWSAFE_DOCUMENT_TO_HL7_ORU_AHC, and the error is occurring in the source connector. The error message also includes a stack trace that shows the sequence of events leading up to the error.
Transformer Code we Using
var messageType = "";
var messageEvent = "";
var objJson = JSON.parse(messageObject.getRawData());
channelMap.put('messageDateTime', DateUtil.getCurrentDate("yyyyMMddHHmmss"));
channelMap.put('accessionId', msg['accessionId']);
channelMap.put('patientName', msg['patientName']);
channelMap.put('patientId', msg['patientId']);
channelMap.put('patientAccNum', msg['patientAccountNumber']);
if (msg['OrganizationID'] !== "") {
if (msg['OrganizationID'] === "Athens Medical Center") {
messageType = "ORU";
messageEvent = "R01";
channelMap.put('messageEventType', messageType + "^" + messageEvent);
}
}
channelMap.put('date', DateUtil.getCurrentDate('yyyyMMdd'));
channelMap.put('fileName', msg['patientId'] + "_" + msg['patientName'] + ".json");
Filter logic I'm Applying to resolve this Error
if(connectorMessage.getRawData().toString().length() > 0 ) {
return true;
} else {
return false;
}
But Still getting the Same error
can anyone help me to resolve that error or explain me how to do that.
I get Date of Birth in two formats (YYYYMMDD and YYYYMMDDHHMMSS) and then need to output in a single format of MM-DD-YYYY.
I can convert one or the other to MM-DD-YYYY but don't know how to write an if then else statement in Java to convert whichever one is sent over.
I am no expert in Java scripting so any help would be appreciated. What I have used in the transformer is
DateUtil.convertDate("yyyy-MM-dd", "MM-dd-yyyy", msg['PID']['PID.7']['PID.7.1'].toString());
or
DateUtil.convertDate('yyyyMMdd','MM-dd-yyyy',DOBouput)
๐ This link is no longer active and should be removed or replaced:
๐ https://www.mirthcorp.com/community/wiki/display/mirth/Home
The examples don't work with mirth 3.7
I need to take a date out of the filename to add to the HL7 output.
Filename example: MRMC_Epic_Demo_2024-2-29.txt
Not sure how to do this in the Transformer to use to strip away the "MRMC_Epic_Demo_" and ".txt"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.