Giter VIP home page Giter VIP logo

connect-examples's Issues

determineVariableType

/**
 * 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;
}

Getting SyntaxError: Empty JSON string in Mirth while passing the message

ERROR

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.

Convert multiple input date formats to a single out format

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)

mirth 3.7

The examples don't work with mirth 3.7

Pull data from Filename

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"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.