简体   繁体   English

不能正确处理HL7文档中的行?

[英]Not properly processing lines in an HL7 document?

I have a script that is supposed to check the first 4 characters of each line. 我有一个脚本,应该检查每行的前4个字符。 It's not working. 没用 I'm processing HL7 documents that look like this: 我正在处理如下所示的HL7文档:

MSH|...
EVN|...
PID|...
MSH|...
EVN|...
PID|...
MSH|...
EVN|...
PID|...

and here is my code: 这是我的代码:

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile (f.path, 1)
Do Until file.AtEndOfStream
    line = file.Readline
    wscript.echo left(line,4)
Loop

This outputs the following: 输出以下内容:

MSH|
MSH|
MSH|

Is there something I should use besides Readline ? 除了Readline我还应该使用其他东西吗?

I ended up using 's replace in files feature to replace all instances of \\r with \\r\\n . 我最终使用replace in files功能将\\r所有实例替换为\\r\\n This seems to fix the issue. 这似乎可以解决问题。

Revisited this for another task and found a better way. 再次讨论此任务,并找到了更好的方法。 The following set of loops and conditions will break down a .dat file full of HL7 messages into Message, Segment, Field and Subfield. 以下一组循环和条件将一个充满HL7消息的.dat文件分解为Message,Segment,Field和Subfield。 It does not account for repeating fields (~). 它不考虑重复的字段(〜)。

The first two FOR statments solve the original issue with line feeds vs carriage returns. 前两个FOR语句使用换行符和回车符解决了原始问题。 It turns out there is a lf between each message and a cr between each segment. 事实证明,每个消息之间都有一个lf,每个段之间有一个cr。

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
file = fso.OpenTextFile(f.path).ReadAll
for each msg in split(file,vbLf)
    if msg <> "" then
        msgType = split(split(msg,"|")(8),"^")(1) 'results in something like A08
        for each line in split(msg,vbCr)
            if line <> "" then
                seg = left(line,3) 'MSH, PID, etc
                for each field in split(line,"|")
                    if instr(field,"^") > 0 then
                        for each subfield in split(field,"^")
                           'do code here for each subfield
                        next
                    end if
                next
            end if
        next
    end if
next

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM