As promised
;msg: to-string read/binary %test/hl7/h0000024.hl7
hl7: make object! [
msgtype: make block! 2
segsep: "^M"
fldsep: "|"
compsep: "^^"
repsep: "~"
escape: "\"
subsep: "&"
frame.start: none
frame.end: none
segments: make block! 50
segnumber: 0
ok: true
warning: none
in: func ["should parse and check a message according
HL7-Rules"
msg [string!] /local seg
] [
clear segments clear msgtype segnumber: 0 ok: true
parse msg [copy frame.start [ to "MSH" | to "FHS"] seg: (
append/only msgtype copy/part seg 3
fldsep: pick seg 4
either fldsep = pick seg 9 [
fldsep: to-string fldsep
compsep: to-string pick seg 5
repsep: to-string pick seg 6
escape: to-string pick seg 7
subsep: to-string pick seg 8
] [ok: false warning: "Delimiter"]
)
some [ copy seg to segsep (
if seg [
either fldsep/1 = pick seg 4 [
segnumber: :segnumber + 1
append/only segments to-word copy/part seg 3
seg: skip seg 4
append/only segments to-block parse/all seg fldsep
] [ok: false
warning: join "Header after segment nro " form
segnumber
]
) 1 skip
]
copy frame.end to end (
insert segments/msh fldsep
append/only msgtype replace copy segments/msh/9 compsep ""
)
]
return segments
]
msg: make string! 1000
out: func ["should generate a message according the HL7 rules" ]
[
clear msg
fldsep: copy segments/msh/1
remove segments/msh
foreach [head body] segments [
append msg form head append msg fldsep
foreach fld body [append msg fld append msg fldsep]
append msg segsep
]
insert segments/msh fldsep
return msg
]
]
Usage:
s: hl7/in msg
m: hl7/out
msh-segment: s/msh
version-id: s/msh/12
reply-for: s/msa/2
internal-patientid: s/pid/3
etc.
You see, there's a lot to do. Especially the syntax checking is very
rudimentary. Also the autosensing for the frame type has problems with the MLLP.
I'm still thinking if I really has to do a walk through the segments in
order to get the segment number of an given segment.
If you or someone else knows an easy solution, don't hesitate to post it
or mail me directly!
Regards
AR
> Hi
>
> As I'm working with physically separated networks, I do not have this
> routines at hand, but hope to transfer and post some tomorrow.
>
> Regards
> AR
>
--
Sent through Global Message Exchange - http://www.gmx.net