English 中文(简体)
Windows scripting to parse a HL7 file
原标题:

I have a HUGE file with a lot of HL7 segments. It must be split into 1000 (or so ) smaller files. Since it has HL7 data, there is a pattern (logic) to go by. Each data chunk starts with "MSH|" and ends when next segment starts with "MSH|".

The script must be windows (cmd) based or VBS as I cannot install any software on that machine.

File structure:

MSH|abc|123|....
s2|sdsd|2323|
...
..
MSH|ns|43|...
...
..
.. 
MSH|sdfns|4343|...
...
..
asds|sds

MSH|sfns|3|...
...
..
as|ss

File in above example, must be split into 2 or 3 files. Also, the files comes from UNIX, so newlines must remain as they are in the source file.

Any help?

最佳回答

This is a sample script that I used to parse large hl7 files into separate files with the new file names based on the data file. Uses REBOL which does not require installation ie. the core version does not make any registry entries.

I have a more generalised version that scans an incoming directory and splits them into single files and then waits for the next file to arrive.

Rebol [
    file: %split-hl7.r
    author: "Graham Chiu"
    date: 17-Feb-2010
    purpose: {split HL7 messages into single messages}
]

fn: %05112010_0730.dat
outdir: %05112010_0730/

if not exists? outdir [
    make-dir outdir
]

data: read fn
cnt: 0
filename: join copy/part form fn -4 + length? form fn "-"
separator: rejoin [ newline "MSH"]
parse/all data [
    some [
        [ copy result to separator | copy result to end ]
        (
            write to-file rejoin [ outdir filename cnt ".txt" ] result
            print "Got result"
            ?? result
            cnt: cnt + 1
        )
        1 skip
    ]
]
问题回答

HL7 has a lot of segments - I assume that you know that your file has only MSH segments. So, have you tried parsing the file for the string "(newline)MSH|"? Just keep a running buffer and dump that into an output file when it gets too big.





相关问题
What approach should I use to test a VBScript?

I ve been asked to help out with a project which has made extensive use of VBScript to process a whole bunch of text files and generate certain outputs - sanitized files, SQL entries etc.. The script ...

Unable to call c# code from vbscript - ActiveX error

I am trying to call a method I have written in C# from VBScript. I have followed just about all of the instructions I can find on the web and am still having problems. Specifically I am getting Error:...

How to set delay in vbscript

How to set delay in vbscript? WScript.Sleep(100) does not work on Windows XP, Vista.

Using Classes in a Dictionary in Classic ASP

I usually do C# but have inherited a classic ASP project. I have defined a class: Class clsPayment Public Name End Class Set objPayment = New clsPayment objPayment.Name = "...

How to check which Operating System?

How can I check OS version in a batch file or through a vbs in an Windows 2k/2k3 environment ? You know ... Something like ... : "If winver Win2k then ... or if winver Win2k3 then ....

Problem casting field when querying spreadsheet

I am trying to query an .xls spreadsheet with VBScript, but I have run into an issue when trying to cast a field. I connect to the spreadsheet like this. Set objConnection = CreateObject("ADODB....

热门标签