簡體   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