Replies: 3 comments
-
There are two examples from the connect-examples repo that should help - https://github.com/nextgenhealthcare/connect-examples/search?q=nte Thanks for including samples and code. When you call |
Beta Was this translation helpful? Give feedback.
-
Thanks for looking but I finally got some code that does work. May not be the most elegant way to do it.
|
Beta Was this translation helpful? Give feedback.
-
A couple small changes and your original code works. The issue is that I renamed the variables to make it more obvious which ones are js arrays and which ones are XMLLists. I also showed an alternate way to do the NTE renumbering. // Get NTEs after PID segment but before the first OBR
var nteArray = getSegmentsAfter(msg, msg.PID, 'NTE', false, 'OBR')
if (nteArray.length > 0) {
// Convert from array to XMLList
var nteList = nteArray.reduce((list, seg) => (list += seg, list), new XMLList())
// Get the first OBR segment group
var obrArray = getSegmentsAfter(msg, msg.OBR[0], /.*/)
// Get the last segment of the first OBR segment group
var lastSeg = obrArray[obrArray.length - 1]
// Inserting will make copies of all the inserted children to the new location
msg.insertChildAfter(lastSeg, nteList)
// Delete original NTE segments
nteArray.forEach(seg => {delete seg[0]})
// Reorder NTE index
var lastNTEIndex = NaN, nextSetId;
for each(var nte in msg.NTE) {
nextSetId = nte.childIndex() === lastNTEIndex + 1 ? nextSetId + 1 : 1
lastNTEIndex = nte.childIndex()
nte['NTE.1']['NTE.1.1'] = nextSetId
}
} |
Beta Was this translation helpful? Give feedback.
-
I'm trying to move the NTE segments (that fall after the PID but before the first OBR), to the end of the first OBR group.
So if I get:
I want to change it to:
I can get the NTEs easy enough using
but not sure about how to add them easily to the end of the first OBR group.
Thought I might could do this but it doesn't work
Also, still need to remove them from the original location.
Beta Was this translation helpful? Give feedback.
All reactions