gpt4 book ai didi

javascript - 有条件地更改字段的 Mirth Java 代码

转载 作者:行者123 更新时间:2023-11-29 10:48:19 25 4
gpt4 key购买 nike

我正在使用 Mirth 从我们的数据库中读取 HL7 消息并将它们发送到客户的 EMR。这个特定的 EMR 要求嵌入式 PDF 的 OBR 和 OBX 以特定方式格式化。如果 OBR.4.1 和 OBR.4.2 有“0PDF^PDF Report”,我们需要将“^PDFReport^PDF^Base64”插入 OBX.5.1、OBX.5.2 和 OBX.5.3,如下例所示。

OBR|2||13PS061163CYT|0PDF^PDF Report|
OBX|1|ED|0PDF^PDF Report|1|^PDFReport^PDF^Base64^JVBERi0xLjMNJf////

我们目前使用的代码在 99% 的时间都有效,但似乎在特定的报告类型上出现问题。特别是当 OBR 多于 OBX 时。

如能帮助解决此问题,我们将不胜感激。我们目前使用的代码如下。

for (var i=0;i<msg['OBX'].length();i++ ){
var Access=msg['OBR'][i]['OBR.3']['OBR.3.1'].toString()
var Report=msg['OBX'][i]['OBX.5']['OBX.5.1'].toString()
var ID=msg['OBR'][i]['OBR.2']['OBR.2.1'].toString()

if(msg['OBX'][i]['OBX.3']['OBX.3.1'].toString() == Access + ".PDF"){
msg['OBX'][i]['OBX.3']['OBX.3.1'] = "0PDF"
msg['OBX'][i]['OBX.3']['OBX.3.2'] = "PDF Report"
msg['OBX'][i]['OBX.5']['OBX.5.1'] = ID
msg['OBX'][i]['OBX.5']['OBX.5.2'] = "PDFReport"
msg['OBX'][i]['OBX.5']['OBX.5.3'] = "PDF"
msg['OBX'][i]['OBX.5']['OBX.5.4'] = "Base64"
msg['OBX'][i]['OBX.5']['OBX.5.5'] = Report
i--;
}
}

最佳答案

问题的症结在于您的代码假定 OBR 和 OBX 段将始终成对出现。

OBR|1|...
OBX|1|...
OBR|2|...
OBX|1|...
OBR|3|...
OBX|1|...

但是,一旦遇到 OBR 和 OBX 段的数量不匹配,或者没有以严格交替的方式出现的情况,事情就会开始崩溃。

OBR|1|... oh oh, this obr is followed by two obx segments
OBX|1|...
OBX|2|...
OBR|2|... oh oh, this obr isn't followed by an obx segment at all.
OBR|3|...
OBX|1|...

您需要先了解以下代码行的含义。

var obrSegments = msg['OBR'];
var obxSegments = msg['OBX'];

在这个例子中,obrSegments 是一个数组,你猜对了,obr 段。类似地,obxSegments 是一个 obxSegments 数组。这些数组都不是在知道 obx 段相对于 obr 段如何定位的情况下构建的。

如果您可以保证消息中的 obr 段和 obx 段始终以严格交替的方式出现,那么您就可以保证 obrSegments[i] 和 obxSegments[i] 始终是连续的。

另一方面,如果 obr 和 obx 段的数量不相同,或者即使数量相同,如果段没有以严格交替的方式出现,则不能保证 obrSegments[ i] 后面紧跟着 obxSegments[i]。

您问题的措辞不是 100% 清楚。但是,我推断无论何时检查 OBR 的内容,您都希望有条件地更改紧随其后的所有 obx 段的内容。

我推荐更多类似的东西。

var obrSegments = msg['OBR'];

// iterate through the OBR segments
for each (var obr in obrSegments) {

// extract the field components that you need from this OBR
// don't assume I've done this correctly. The text of your
// question didn't match your example code, so I don't exactly know what you need
var OBR4_1 = obr['OBR.4']['OBR.4.1'];
var OBR4_2 = obr['OBR.4']['OBR.4.2'];

// now iterate through the OBX segments that immediately follow this OBR.
// This is a bit tricky to do, but here's how I approach the problem

// you need an XML list of all the segments, not just the current OBR
var segments = obr.parent().children();

// you need to know the current OBR's index in the segments list
var obrIndex = obr.childIndex();

// theoretically, at this point, obr should refer to exactly the same
// data as segments[obrIndex]

// to do the actual OBX iteration:
var nextIndex = obrIndex + 1;
while (nextIndex < segments.length()) {
var nextSegment = segments[nextIndex];
var nextSegmentType = nextSegment.localName();

if (nextSegmentType == 'OBX') {
var obx = nextSegment;

// Bearing in mind that I haven't tested this code and have just been spewing it
// off into my web browser,
// you can now be confident that variable obx refers to one of the obx
// segments immediately following variable obr.

if (OBR4_1 == blah blah blah) {
obx['OBX.5']['OBX.5.1'] = blah blah blah;
obx['OBX.5']['OBX.5.2'] = blah blah blah;
}
else {
// looks like we've finished processing all the OBX segments for the current
// obr, time to break out of the inner loop.
break;
}

++nextIndex;
}
}

关于javascript - 有条件地更改字段的 Mirth Java 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15081723/

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