2013-02-26 30 views
3

我使用欢乐从我们的数据库中读取HL7消息并将它们发送到客户端的EMR。这个特定的EMR要求用于嵌入式PDF的OBR和OBX以特定方式格式化。如果OBR.4.1和OBR.4.2具有“0PDF^PDF报告”,我们需要将“^ PDFReport^PDF^Base64”插入到OBX.5.1,OBX.5.2和OBX.5.3中,如下例所示。欢乐的java代码有条件地更改字段

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

我们目前使用的代码在99%的时间内工作,但似乎打破了特定的报告类型。特别是当OBBR的数量多于OBR时。

任何帮助来解决这个问题,将不胜感激。我们目前使用的代码如下。

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--; 
    } 
} 
+0

您的代码与您正在尝试做的描述不符。你说当一个OBR段具有特定的值时,你想在OBX中设置特定的值。然而,看看你的代码,很明显你正在比较OBR和OBX之间的值。 – csj 2013-02-26 18:53:56

+0

将此问题添加到http://area51.stackexchange.com/proposals/51758/healthcare-it。我们正在努力获得一个医疗保健协议栈交换网站,这将是一个完美的问题 – ChronoFish 2013-02-28 01:51:12

回答

3

问题的症结在于,你的代码假设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片段的数量不相同,或者即使数字IS相同,如果片段不以严格交替的方式出现,那么也不能保证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; 
    } 
} 
+0

正是!这是他错过的。它应该遍历消息中的所有OBR并提取相关数据,然后移至OBX。 +1 – Sid 2013-05-29 01:42:36

+1

如果它帮助了现实世界中的某个人,那么我们都会度过一个美好的一天。 – csj 2013-05-30 06:30:02