gpt4 book ai didi

javascript - 似乎无法将片段移动到重复字段中

转载 作者:行者123 更新时间:2023-11-28 19:35:55 24 4
gpt4 key购买 nike

我有一段代码正在尝试在界面上运行。基本上我们把一些领域放到其他领域。问题似乎在于它将数据保留在原来的位置,而不是将其移动到索引的 PID 段。此外,CP 变量由于某种原因返回“未定义”。

var i = msg['PID']['PID.13'].length(); 
var homeNum;
var netNum;
var cpNum;

while(i--)
{
if (msg['PID']['PID.13'][i]['PID.13.2'].toString() == "PRN")
{
homeNum = msg['PID']['PID.13'][i]['PID.13.9'];
}

if (msg['PID']['PID.13'][i]['PID.13.2'].toString() == "NET")
{
netNum = msg['PID']['PID.13'][i]['PID.13.4'];
}

if (msg['PID']['PID.13'][i]['PID.13.2'].toString() == "CP")
{
cpNum = msg['PID']['PID.13'][i]['PID.13.9'];
}

msg['PID']['PID.13'][i] = "";
}

msg['PID']['PID.13'][0]['PID.13.1'] = homeNum;
msg['PID']['PID.13'][0]['PID.13.4'] = netNum;
msg['PID']['PID.13'][1]['PID.13.1'] = cpNum;

我在转换之前使用的示例 HL7 消息(来 self 们的测试系统,而不是实时数据)

它应该类似于这样:

|9999999999^^^test@test.com~99999999999~~~|

关于它为什么不动的任何想法/指针?

最佳答案

设置变量时缺少 toString()。 典型的 Mirth 事物,因为您将 E4X 对象返回到变量中,而不是您期望的值。

除此之外,您还应该在将变量设置到新结构之前检查变量是否有未定义的值,否则最终会在字段中出现“未定义”。

这是一个可行的解决方案:

var i = msg['PID']['PID.13'].length(); 
var homeNum;
var netNum;
var cpNum;

while(i--)
{
if (msg['PID']['PID.13'][i]['PID.13.2'].toString() == "PRN")
{
homeNum = msg['PID']['PID.13'][i]['PID.13.9'].toString();
}

if (msg['PID']['PID.13'][i]['PID.13.2'].toString() == "NET")
{
netNum = msg['PID']['PID.13'][i]['PID.13.4'].toString();
}

if (msg['PID']['PID.13'][i]['PID.13.2'].toString() == "CP")
{
cpNum = msg['PID']['PID.13'][i]['PID.13.9'].toString();
}

msg['PID']['PID.13'][i] = "";
}

if(homeNum != null) msg['PID']['PID.13'][0]['PID.13.1'] = homeNum;
if(netNum != null) msg['PID']['PID.13'][0]['PID.13.4'] = netNum;
if(cpNum != null) msg['PID']['PID.13'][1]['PID.13.1'] = cpNum;

关于javascript - 似乎无法将片段移动到重复字段中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25890491/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com