I have an ORU interface in Mirth which splits to two destinations. I need to make some changes to the PID in Mirth before sending to one destination which I have managed except I cannot seem to copy all of PID3 to PID 4 just the first repetition.
Mirth Connect: 3.7.1
Transformer Code:
var i = msg['PID']['PID.3'].length();
var assigner = msg['PID']['PID.3'][0]['PID.3.4']['PID.3.4.1'].toString();
// PID tweaking for xxx
while(i--)
{
//Copy all of PID-3 to PID-4
msg['PID']['PID.4']['PID.4.1']=msg['PID']['PID.3'][i]['PID.3.1'].toString()
msg['PID']['PID.4']['PID.4.4']['PID.4.4.1']=msg['PID']['PID.3'][i]['PID.3.4']
['PID.3.4.1'].toString()
msg['PID']['PID.4']['PID.4.5']=msg['PID']['PID.3'][i]['PID.3.5'].toString()
msg['PID']['PID.4']['PID.4.6']=msg['PID']['PID.3'][i]['PID.3.6'].toString()
if (msg['PID']['PID.3'][i]['PID.3.5'].toString() == '016') {
// Copy MRN into PID-2
msg['PID']['PID.2']['PID.2.1']=msg['PID']['PID.3'][i]['PID.3.1'].toString();
}
//Delete PID-3 and replace with DUMMY ID
if (i!=0){
delete msg['PID']['PID.3'][i];
} else{
msg['PID']['PID.3'][i]['PID.3.1']='DUMMY ID';
delete msg['PID']['PID.3'][i]['PID.3.2'];
delete msg['PID']['PID.3'][i]['PID.3.3'];
delete msg['PID']['PID.3'][i]['PID.3.4'];
delete msg['PID']['PID.3'][i]['PID.3.5'];
delete msg['PID']['PID.3'][i]['PID.3.6'];
}
}
Raw PID:
PID|||485286^^^MRN&&GUID^016^MRN~2858365^^^AUID&&GUID^004^AUID||
Transformed PID:
PID||485286|DUMMY ID|485286^^^MRN^016^MRN|
Desired Transformed PID:
PID||485286|DUMMY ID|485286^^^MRN^016^MRN~2858365^^^AUID&&GUID^004^AUID|
You need to index your left hand side. For example, instead of
msg['PID']['PID.4']['PID.4.5']=msg['PID']['PID.3'][i]['PID.3.5'].toString()
You would need
msg['PID']['PID.4'][i]['PID.4.5']=msg['PID']['PID.3'][i]['PID.3.5'].toString()
Thanks Gavin, I did initially try this but got the error:
TypeError: Cannot set property "PID.4.1" of undefined to "2858365"
After some more investigation I realised that I needed to create the repetitions in PID-4.
So I addition to what Gavin mentioned I needed to add the following above:
//Ensure a PID.4 exists for each PID.3 repetition
var i = msg['PID']['PID.3'].length()-1;
while(i--) {
msg['PID']['PID.4']=msg['PID']['PID.4']+<PID.4/>;
}
var i = msg['PID']['PID.3'].length();
There is an official repository of code templates at https://github.com/nextgenhealthcare/connect-examples
There is a useful code template for doing this called renameField found here.
Using that code template, you can reduce all of your code down to
// Copy all repetitions of PID-3 to PID-4
msg['PID']['PID.4'] = renameField(msg['PID']['PID.3'], 'PID.4');
// Iterate over PID-3 repetitions
for each (var pid3 in msg['PID']['PID.3']) {
if (pid3['PID.3.5'].toString() == '016') {
// Copy MRN into PID-2
msg['PID']['PID.2']['PID.2.1'] = pid3['PID.3.1'].toString();
}
}
// Replace all PID-3 with single repetition containing only DUMMY ID using xml literal
msg['PID']['PID.3'] = <PID.3><PID.3.1>DUMMY ID</PID.3.1></PID.3>;
Related
The name list is supposedly as below:
Rose : 35621548
Jack : 32658495
Lita : 63259547
Seth : 27956431
Cathy: 75821456
Given you have a variable as StudentCode that contains the list above (I think const will do! Like:
const StudentCode = {
[Jack]: [32658495],
[Rose]: [35621548],
[Lita]: [63259547],
[Seth]: [27956431],
[Cathy]:[75821456],
};
)
So here are the questions:
1st: Ho can I define them in URL below:
https://www.mylist.com/student=?StudentCode
So the link for example for Jack will be:
https://www.mylist.com/student=?32658495
The URL is imaginary. Don't click on it please.
2nd: By the way the overall list is above 800 people and I'm planning to save an external .js file to be called within the current code. So tell me about that too. Thanks a million
Given
const StudentCode = {
"Jack": "32658495",
"Rose": "35621548",
"Lita": "63259547",
"Seth": "27956431",
"Cathy": "75821456",
};
You can construct urls like:
const urls = Object.values(StudentCode).map((c) => `https://www.mylist.com?student=${c}`)
// urls: ['https://www.mylist.com?student=32658495', 'https://www.mylist.com?student=35621548', 'https://www.mylist.com?student=63259547', 'https://www.mylist.com?student=27956431', 'https://www.mylist.com?student=75821456']
To get the url for a specific student simply do:
const url = `https://www.mylist.com?student=${StudentCode["Jack"]}`
// url: 'https://www.mylist.com?student=32658495'
Not sure I understand your second question - 800 is a rather low number so will not be any performance issues with it if that is what you are asking?
The properties of the object (after the trailing comma is removed) can be looped through using a for-in loop, (see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in)
This gives references to each key of the array and the value held in that key can be referenced using objectName[key], Thus you will loop through your object using something like:
for (key in StudentCode) {
keyString = key; // e.g = "Jack"
keyValue = StudentCode[key]; // e.g. = 32658495
// build the urls and links
}
to build the urls, string template literals will simplify the process (see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) allowing you to substitute values in your string. e.g.:
url = `https://www.mylist.com/student=?${StudentCode[key]`}
Note the use of back ticks and ${} for the substitutions.
Lastly, to build active links, create an element and sets its innerHTML property to markup built using further string template literals:
let link = `<a href=${url}>${keyValue}</a>`
These steps are combined in the working snippet here:
const StudentCode = {
Jack: 32658495,
Rose: 35621548,
Lita: 63259547,
Seth: 27956431,
Cathy: 75821456,
};
const studentLinks = [];
for (key in StudentCode) {
let url = `https://www.mylist.com/student=?${StudentCode[key]}`;
console.log(url);
studentLinks.push(`<a href href="url">${key}</a>`)
}
let output= document.createElement('div');
output.innerHTML = studentLinks.join("<br>");
document.body.appendChild(output);
I'm trying to move Mongo document from one collection to another and I can't get it to work (in server method):
var oldData = newCollection.findOne({name: name});
if(oldData){
console.log(oldData); // this works
oldCollection.insert({oldData}); // this doesn't
}
Another way:
var oldData = newCollection.findOne({name: name});
if(oldData){
console.log(oldData.score); // this works
oldCollection.insert({
score: oldData.score
}); // this doesn't
What's wrong here?
You shouldn't need the curly brackets in option 1 - oldCollection.insert(oldData)
A javascript data object (JSON notation) has been created with the following content:
"[
{"range":"Shape","values":[{"idx":0,"val":"Random"},{"idx":1,"val":"Line"},{"idx":2,"val":"Square"},{"idx":3,"val":"Circle"},{"idx":4,"val":"Oval"},{"idx":5,"val":"Egg"}]},
{"range":"Color","values":[{"idx":0,"val":"Red"},{"idx":1,"val":"Blue"},{"idx":2,"val":"Yellow"},{"idx":3,"val":"Green"},{"idx":4,"val":"Cyan"}]}
]"
In a next step the index of an ordinal value has to be found in this object. The function should find the index of the value 'Blue' in the range 'Color'.
So the function should have the meta scripting form
f("Color")("Blue")=1
What is the most elegant form to create such a function in the context of D3 and javascript?
Depending on your use case, it might make sense to convert the data structure to a different structure more suitable for direct access. E.g. you could convert your structure to
var data = {
Shape: ['Random', 'Line', ...],
// ...
};
and access it with
data['Shape'].indexOf('Line') // or data.Shape.indexOf('Line')
Or go even one step further and convert to
var data = {
Shape: {
Random: 0,
Line: 1,
// ...
},
// ...
};
and access it with
data['Shape']['Line'] // or data.Shape.Line
What the best solution is depends on the actual use case.
Converting the structure dynamically is pretty straight forward. Here is an example to convert it to the first suggestion:
var newData = {};
data.forEach(function(item) {
newData[item.range] =
item.values.map(function(value) { return value.val; });
});
This would also reduce redundancy (e.g. idx seems to correspond with the element index).
Would this work for you ?
var dataJson = '[ \
{"range":"Shape","values":[{"idx":0,"val":"Random"},{"idx":1,"val":"Line"},{"idx":2,"val":"Square"},{"idx":3,"val":"Circle"},{"idx":4,"val":"Oval"},{"idx":5,"val":"Egg"}]},\
{"range":"Color","values":[{"idx":0,"val":"Red"},{"idx":1,"val":"Blue"},{"idx":2,"val":"Yellow"},{"idx":3,"val":"Green"},{"idx":4,"val":"Cyan"}]}\
]';
var data = JSON.parse(dataJson);
for (each in data){
if ( (data[each].range) === 'Color'){
for (eachVal in data[each].values){
if (data[each].values[eachVal].val === 'Blue'){
alert(data[each].values[eachVal].idx);
}
}
} ;
}
And here is the JSFiddle for you too.
I have JSON data by which i am creating nodes and relationship between nodes using https://github.com/thingdom/node-neo4j connector.
I have following JSON format
{
att0:"abcd",
att1:"val1",
att2:"val2",
att3:"val3",
att4:"val4",
att5:"val5",
att6:"val6",
att7:"val7",
att8:"val8"
} .... more like this around 1000
Here att0+att1 gives me unique id after md5 hash (let it be UID1) .
and att4 gives me unique id after md5 hash (let it be UID2).
and att7 gives me unique id after md5 hash (let it be UID3).
I am creating two node of following properties :
Node 1 :
{
id: UID1 ,
att3:"val3"
}
Node 2 :
{
id:UID2,
att5:"val5",
att6:"val6"
}
Relationship from Node 1 --> Node 2 :
{
id:UID3,
att5:"val8"
}
Following is my data insertion query:
for(i=0; i<1000; i++){ // 1000 objects in json
// create UID1,UID2 and UID3 based on above info for each object
// and create query string as mentioned below
query_string = MERGE (n:nodes_type1 {id:'UID1'})
ON CREATE SET n={ id:'UID1', att3:'val3'},n.count=1
ON MATCH SET n.count = n.count +1
MERGE (m:nodes_type2 {id:'UID2'})
ON CREATE SET m={ id:'UID2', att5:'val5', att6:'val6'},m.count=1
ON MATCH SET m.count = m.count +1
MERGE (n)-[x:relation_type {id:'UID3'} ]->(m)
ON CREATE SET x={ att8:'val8', id:'UID3' },x.count=1
ON MATCH SET x.count = x.count +1 return n
db.query(query_string, params, function (err, results) {
if (err) {
console.log(err);
throw err;
}
console.log("Node Created !!! "+ event_val)
});
}
Firstly i cleared my neo4j database using following query externally ( using neo4j database UI):
Now problem is when i query MATCH (n:nodes_type2) return COUNT(n). Since there are 1000 objects in json it should create 1000 nodes.But the result is coming more than 1000 (around 9000) and keeps on changing as every time when i clear the data and restart the script. When i saw in the results there were multiple nodes of the same UID . Shouldn't merge query handel node match and increment counter . Merge is incrementing the counter but after some number, new node is created with same UID.
Based on your given query, I assume the UUID generated looks to be different on each loop :
1000 loops, 3 queries with 3 different node labels.
Can you count distinct uuids you get from your database, like :
MATCH (n) RETURN count(DISTINCT n.id)
I assue your queries are executed massively in parallel,
make sure to have a unique constraint for : nodes_type1(id) and nodes_type2(id) installed, otherwise MERGE cannot guarantee uniqueness.
Also you should change your query to use parameters instead of literal values
And it should also look like this:
MERGE (n:nodes_type1 {id:{id1}})
ON CREATE SET n.att3={att3},n.count=1
ON MATCH SET n.count = n.count +1
MERGE (m:nodes_type2 {id:{id2}})
ON CREATE SET m.att5={att5}, m.att6={att6},m.count=1
ON MATCH SET m.count = m.count +1
MERGE (n)-[x:relation_type {id:{id3}} ]->(m)
ON CREATE SET x.att8={att8},x.count=1
ON MATCH SET x.count = x.count+1
return n,r,m
I don't think the id and counter on the relationship make sense in a real use-case but for your test it might be ok
i'm newbie in javascript so, in this example exists the geometrycontrols.js (for global controls) and markercontrol.js (for marker controls)
my problem is identify the arrays where "data" is saved...
at the reference i see a savedata function but i have no idea how work with this function...
on the other side, in test.html if i've the outup on the Glog startup and output "data", and let me thinking that comes from array...
My objective is save the coordinates and other all atributes to mysql database, and when i discover where are "data" is the easy part.
if someone worked with this example (or not) can help me i'm grateful
ps: i'm really a newbie on javascript :P
edit1:
I was out for a time, and now I focus in geometrycontrols.js specially in: GeometryControls.prototype.saveData = function(opts){
var me = this;
if(opts.allData === true){
//me.saveAllData();
} else {
//construct a json data record
var geomInfo = opts.geomInfo, index = opts.geomInfo.index;
var record = geomInfo.storage[index];
var recordJSON = {};
recordJSON.type = record.type;
recordJSON.coordinates = [];
//determine geometry type, and copy geometry appropriately
if(record.type === "point"){
recordJSON.coordinates.push({lat:record.geometry.getLatLng().lat(),lng:record.geometry.getLatLng().lng()});
alert(recordJSON.coordinates);
} else {
alert("is not point");
var vertex;
for(var i=0;i<record.geometry.getVertexCount();i++){
vertex = record.geometry.getVertex(i);
recordJSON.coordinates.push({lat:vertex.lat(),lng:vertex.lng()});
}
}
//add title and description
recordJSON.title = record.title[0];
recordJSON.description = record.description[0];
//TODO add styles
recordJSON.style = ""; //TODO} //TODO Make separate prototype function?function postData(data){
//TODO
me.debug(data);
//alert(recordJSON.coordinates);
//alert(data);
};postData(me.serialize(recordJSON));}; `
When I alert(recordJSON.coordinates), the outupt is [object Object] and i've no idea why, in theory this array contains the coordinates...
Here is some code I have used to send the data to MySQL. It uses a little bit of jQuery to do the ajax magic (the line starting with the dollarsign is jQuery).
function postData(data){
me.debug(data);
var dataString = JSON.stringify(data);
me.debug(dataString);
$.post('storage.php', { data: dataString });
};
postData(recordJSON);
As you can see I've modified the way the 'recordJSON' object gets sent to the postData function a bit too: I've removed the serialise function.
Next, create a PHP file (called 'storage.php' in my case) and put this in it:
<?php
$received = json_decode($_POST['data'], true);
echo "just received " . $received['name'];
?>
You now have an array in PHP that you can do with as you please.
In the examplecode above I've modified the jQuery post function a bit, so if it doesn't work, look there.
The data is stored in JSON format in this file: http://gmaps-utility-library-dev.googlecode.com/svn/trunk/geometrycontrols/examples/data/testdata.js -- it's pretty much self-documenting, just follow the example to set your coordinates.
Note that if you need to find the latitude and longitude for a given address this is a good site: http://itouchmap.com/latlong.html