繁体   English   中英

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

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

我有一个脚本,应该检查每行的前4个字符。 没用 我正在处理如下所示的HL7文档:

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

这是我的代码:

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

输出以下内容:

MSH|
MSH|
MSH|

除了Readline我还应该使用其他东西吗?

我最终使用replace in files功能将\\r所有实例替换为\\r\\n 这似乎可以解决问题。

再次讨论此任务,并找到了更好的方法。 以下一组循环和条件将一个充满HL7消息的.dat文件分解为Message,Segment,Field和Subfield。 它不考虑重复的字段(〜)。

前两个FOR语句使用换行符和回车符解决了原始问题。 事实证明,每个消息之间都有一个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