复制多次重复PID-3到PID-4

Copy multiple repetition PID-3 to PID-4

我在 Mirth 中有一个 ORU 接口,它分为两个目的地。在发送到我管理的一个目的地之前,我需要对 Mirth 中的 PID 进行一些更改,但我似乎无法在第一次重复时将所有 PID3 复制到 PID 4。

欢乐连接:3.7.1

变形金刚代码:

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'];        
    }
}

原始 PID:

PID|||485286^^^MRN&&GUID^016^MRN~2858365^^^AUID&&GUID^004^AUID||

转换后的 PID:

PID||485286|DUMMY ID|485286^^^MRN^016^MRN|

所需的转换 PID:

PID||485286|DUMMY ID|485286^^^MRN^016^MRN~2858365^^^AUID&&GUID^004^AUID|

您需要为您的左侧编制索引。例如,而不是

 msg['PID']['PID.4']['PID.4.5']=msg['PID']['PID.3'][i]['PID.3.5'].toString()

你需要

  msg['PID']['PID.4'][i]['PID.4.5']=msg['PID']['PID.3'][i]['PID.3.5'].toString()

谢谢加文,我最初尝试过这个但得到了错误: 类型错误:无法将未定义的 属性“PID.4.1”设置为“2858365”

经过更多调查后,我意识到我需要在 PID-4 中创建重复。 所以除了加文提到的内容,我还需要在上面添加以下内容:

//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();

https://github.com/nextgenhealthcare/connect-examples

有一个代码模板的官方存储库

找到了一个名为 renameField 的有用代码模板 here

使用该代码模板,您可以将所有代码减少到

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