Mirth - Add new field to OBR 16 segment - javascript

Got an opportunity to work in Mirth to add an entry in the OBR field.
With the help of this forum, I was able to edit an existing data, that works perfectly fine.
But failing to add a data to a field which doesn't exist in the source HL7.
Below is the example,
SourceHL7
PV2|||||||System Alert Off~0437689973~ABC-KOTHAI-AUS
OBR|1||ABCDEDFGH|754051^ABCEDEF^MDC|||20190225133500+0000||||||||||||||||||F
In the DestinationHL7, I want to check if PV2.7.2 has "KOTHAI", if yes, then update the OBR.16 as below
OBR|1||ABCDEDFGH|754051^ABCEDEF^MDC|||20190225133500+0000|||||||||KOTHAI|||||||||F
With the below Javascript, I am able to see the last value in OBR is changed as M but no "KOTHAI" is available. I could see the change in Transformed data but not in Encoded data. Could you let me know what am I doing wrong.
tmp=msg;
var code = tmp['ORU_R01.PATIENT_RESULT']['ORU_R01.PATIENT']['ORU_R01.VISIT']['PV2']['PV2.7'][2].toString();
if (code.indexOf("ARSTALL") != -1 )
{
tmp['ORU_R01.PATIENT_RESULT']['ORU_R01.ORDER_OBSERVATION']['OBR']['OBR.25'] = "M";
tmp['ORU_R01.PATIENT_RESULT']['ORU_R01.ORDER_OBSERVATION']['OBR']['OBR.16'] = "KOTHAI";
}else {
tmp['ORU_R01.PATIENT_RESULT']['ORU_R01.ORDER_OBSERVATION']['OBR']['OBR.25'] = "F";
}

Here is the same answer I gave on your forum post http://www.mirthcorp.com/community/forums/showthread.php?t=218996
You're using the strict parser, so you need to make sure everything is named correctly depending on hl7 datatype.
I think you want to do this:
tmp['ORU_R01.PATIENT_RESULT']['ORU_R01.ORDER_OBSERVATION']['OBR']['OBR.16']['XCN.1'] = "KOTHAI";

Related

How to create an if else statement when using custom calculatoin script

I am new to using Kofax Power Editor, which uses Javascript, and I am trying to create an if else statement that involves simple calculations. It depends on what the user enters into a textfield box, and then displays it in a separate text field box. Here is the line I wrote:
if (Textfield1 <= 15,000) { Textfield3 = (Textfield1*.05)/12; }
Although, nothing is showing up in Textfield3. I have no clue why.
If anyone would like to help, I am available via phone as well. Or facetime.... because this not making any sense to me.
You have a comma , which is interpreted as comma operator and all checks yields false, because of zero value.
To overcome this, remove the comma.
var Textfield1 = 42,
Textfield3;
if (Textfield1 <= 15000) { Textfield3 = (Textfield1*.05)/12; }
console.log(Textfield3); // undefined

Data changes after assigning to another variable

I work with Discord.js User object and Mongoose Schema. But the problem doesn't seems to be part of those.
var Message = require('../app/models/message'); //Mongoose Schema
...
var newMessage = new Message();
...
//taggedUser is an object containing all the info about user. id property contains user id which is number.
const taggedUser = message.mentions.users.first();
newMessage.message.to = taggedUser.id;
console.log(taggedUser.id);
console.log(newMessage.message.to);
The code above should assign user ID to Schema. Everything works, but...
442090269928849410
442090269928849400
Last 2 characters aren't the same among these variables now. How is this even possible? The = changed the actual data inside the variable?
In case it is Mongoose here is how Schema looks like:
var msgSchema = mongoose.Schema({
message : {
from : Number,
to : Number,
content : String,
time : Date
}
});
Edit:
If I change
to : Number,
to string:
to : String,
It works properly. I still need the answer on why does this work incorrectly with number. Right above the problematic line I have another id which works perfectly fine:
newMessage.message.from = msg.author.id;
I have already tried to parse taggedUser.id to integer or creating Number() object but that didn't help. So every time I turn taggedUser.id into a Number or parse it to int it changes to the slightly different number.
I don't know what to think. How can data change during the assignment?
If there is not enough data provided in the question please ask me and I'll add everything needed. I can't imagine what might be causing this bug.
9007199254740992 - Highest safe number in JS
442090269928849410 - Your integer (id)
The reason of that small variation is the 'Max precision' JavaScript can work with.
When you tried to use the id as a number it was affected by this and it changed because JavaScript can't be that precise.
If you see both numbers at the beginning of this answer you can see that they are separated by 2 characters, that is why only the 2 last character changed.
Basically your integer was affected by the max precision JS numbers can have.
Reference: https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/Number/MAX_SAFE_INTEGER
You might just be seeing an artifact of console.log running asynchronously. Try this:
console.log('' + taggedUser.id);
console.log('' + newMessage.message.to);
...and see if that makes any difference.

Pulling Data out of an object in Javascript - FIXED - Double Encoded Json Epic Fail On My Part

I am having a problem retrieving data out of an object passed back from PHP. I've tried many different ways to access this data and none work.
In Firebug I see the following... (it looks nicer in Firebug) - I tried to make this look as close to Firebug as possible
results Object { data="{"formName":"form3","formData":"data goes here"}", phpLiveDebug="<...s: 198.91.215.227"}
data "{"formName":"form3","formData":"data goes here"}"
phpLiveDebug "<...s: 198.91.215.227"
I can access phpLiveDebug no problem, but the data portion is an object. I have tried the following...
success: function(results) {
//$("#formName").val(results.data.formName);
//$("#formName").val(results.data[0].formName);
//$("#formName").val(results.data[0]);
//$("#formName").val(results.data[1]);
//$("#formName").val(results.data[0]["formName"]);
var tmp = results.data[formName];
alert("!" + tmp + "!");
$("#formName").val(tmp);
$("#jqueryPHPDebug").val(results.phpLiveDebug);
}
This line works in the example above...
$("#jqueryPHPDebug").val(results.phpLiveDebug);
but... I can't figure out how to get at the data inside the results.data portion... as you can see above, I have been trying different things and more not even listed there.
I was really hoping this line would work :)
var tmp = results.data[formName];
But it doesn't. So, after many days of reading, tinkering, my solution was to re-write it to return data similar to the phpLiveDebug but then I thought... it's gotta be something simple I'm overlooking...
Thank you for your time. Please try and explain why my logic (my horrible attempts at trying to figure out the proper method) above is wrong if you can?
UPDATE - this line here SHOULD have worked... but didn't... here is why...
success: function(results) {
//$("#formName").val(results.data.formName);
Why that didn't work...
In my function I had...
$jsonData["formName"] = $rowName; // the name of the form we are fetching
$jsonData["formData"] = "data goes here";
return (json_encode($jsonData));
How I called the function...
$dataReturn["data"] = $ds1->Invoke(rawurldecode($_POST["data"]));
if (DEBUGMODE) $dataReturn["phpLiveDebug"] = EH::CloseDebug();
exit (json_encode($dataReturn));
I was DOUBLE ENCODING the data... and for some reason...
$("#formName").val(results.data.formName);
Was not working.
I fixed the code by changing 1 line...
return (json_encode($jsonData));
to
return $jsonData;
Hope this helps someone!
I don't know exactly what it did to not work but... it works now!
I wonder what happens internally when you encode an array and then add another array and RE encode that! Double encoding. My bad.
The keys are strings.
var tmp = results.data['formName'];
or
var tmp = results.data.formName;

jquery masked input plugin to not clear field when errored

I'm looking at the http://digitalbush.com/projects/masked-input-plugin/
I'm calling it like this:
$(control).mask('999-999-9999');
And I don't want it to throw away the users input if something is wrong, e.g. they haven't finished
[407-555-____]
If you leave the field after having typed this much, it clears it. I'd like to leave it so they can finish later.
I'm new to jQuery, and I've looked through his source, but I can't find any way to do that, nor can I find any way to edit it to accomplish what I want, because the code is arcane to my eyes.
Set autoclear option to false.
$(control).mask('999-999-9999', {autoclear: false});
It looks like I should just make the whole mask optional:
mask('?999-999-9999')
That way the control thinks what the user has is "valid" and I can continue. Even though it isn't really the optional part of the mask.
You should delete statement input.val(""); in checkVal() function for a proper solution.
If you're using minified version, you should search and delete statement:
if(!a&&c+1<i)f.val(""),t(0,k);else
Try update file jquery.maskedinput.js
In function function checkVal(allow) set parameter allow on true. Its help for me.
function checkVal(allow) {
allow = true; ///add this command
//..............
}
In addition to removing the input.val("") in checkVal() you can also change the call to clearBuffer.
In the original code it is: clearBuffer(0, len); removing all user input.
if you change this to clearBuffer(lastMatch + 1, len); the user input will be displayed, followed by the mask placeholders that are still needed to complete correct input.
I have also added a user message in the .bind. This works for us, as we are using the MaskedInput for exactly one type of input. I'm checking for any input going further than position 7, because that's where the user input starts.
Here is what I did:
.bind("blur.mask", function() {
// find out at which position the checkVal took place
var pos = checkVal();
// if there was no input, ignore
if (pos <=7) {input.val(""); clearBuffer(0, len);}
// if the user started to input something, which is not complete, issue an alert
if (pos > 7 && pos < partialPosition) alert("Tell the user what he needs to do.");
if (input.val() != focusText)
input.change();
})
Adding Placeholder could solve the problem.
$(control).mask('999-999-9999');
Add an empty place holder into mask. see below
$(control).mask('999-999-9999', { placeholder: "" });
which would replace _ on the input text field by default. so there would bot be any _ left if the input length is dynamic and not fixed.
Looking for into the pluging script the unmask method.
$('#checkbox').unmask();

How can I ensure that changes to a form DOM are complete before POSTing?

Currently I have a race condition existing in my JavaScript code. What I am trying to do with this code is convert all check boxes which are a part of the 'checkbox' class and are not checked into text boxes with a value of zero. Currently when you post a check box that is not checked it does not appear in the $_POST data. However I need to know all the values whether true or false for these particular set of check boxes.
The code I have is here:
Code:
function checkboxConvert() {
var chkBxs = $$('.checkbox');
for (var i = 0; i < chkBxs.length; i++) {
if (chkBxs[i].checked == false) {
chkBxs[i].type = 'textbox';
chkBxs[i].value = '0';
}
}
setTimeout("document.productForm.submit();",1000);
}
Now the problem that I have been getting is that when I try to submit this form the values of the recently changed text boxes does not appear in the $_POST data. Therefore, as you can see above I have postponed the page submit for 1 sec and then I have all the data available to me. However as time goes on and my data set gets larger, 1 sec may no longer be enough. This I think is a race condition and I need to figure some way of running the code only after all the check boxes have been converted and they have their new values. I would have thought that this would be unnecessary from the start, but for some reason it's trying to run both pieces simultaneously and I can't submit until I have the proper values in place.
Any help is much appreciated!
This is definitely not the way to do web. I strongly advise you abandon your checkboxConvert function, and solve this issue on the server side
JavaScript always runs single-threaded in the browser so I don't think it can be a race condition.
I'd generally agree with others that you shouldn't do this, but your problem may be that you're changing the element to a type of "textbox" instead of "text". If you declare an input of type "textbox" in HTML markup, it will usually render as a text field anyway because that's the default. However, changing an already valid "checkbox" type input to the invalid "textbox" may not work predictably.
Try changing it to this:
function checkboxConvert() {
var chkBxs = $$('.checkbox');
for (var i = 0; i < chkBxs.length; i++) {
if (chkBxs[i].checked == false) {
chkBxs[i].type = 'text';
chkBxs[i].value = '0';
}
}
// Because JS in the browser is single-threaded, this
// cannot execute before the preceding loop completes anyway.
document.productForm.submit();
}
There's got to be a better way to do this. Try something like:
Know about all your possible values on the server side. It looks like you're using PHP; keep a simple array with the names of your checkboxes.
When you take your $_POST data, remove the names of checkboxes you've received values for from your array.
The remaining are all false.

Categories

Resources