Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Modify the path variable
- $path = "C:\Documents and Settings\BLAHBLAHBLAHUSERNAME\Desktop\HL7Messages"
- $src = (Get-ChildItem $path)[1].FullName
- # take hl7 message as string, convert to posh obj
- function hl7-to-object {
- param($src)
- # go from hl7 to powershell array of objects
- $msg = @()
- $cursorCount = 0
- $src | Foreach {
- $split = $_.Split("|")
- $nodeName = $split[0]
- $properties = @()
- $split | select -skip 1 | foreach {
- $properties += $_
- }
- $object = New-Object psobject
- $object | Add-Member –membertype noteproperty –Name HL7Pos –Value $cursorCount
- $object | Add-Member –membertype noteproperty –Name Segment –Value $nodeName
- $object | Add-Member –membertype noteproperty –Name Fields –Value $properties
- $msg += $object
- $cursorCount += 1
- }
- return $msg
- }
- # take posh object formed from hl7 and convert to hl7 string
- function object-to-hl7 {
- param($msgObj)
- # convert back to HL7
- $msgSrc = @()
- $msgObj | foreach {
- $msgSrc += $_.Segment + "|" + ($_.Fields -join "|")
- }
- return ($msgSrc -join "`r`n")
- }
- # --------
- # EXAMPLES
- # --------
- #read hl7 file
- $msg = hl7-to-object((get-content $src))
- #reading and writing
- # grab
- $MSH = ($msg | where {$_.Segment -eq "MSH"} | select -First 1)
- $IN1_B = ($msg | where {$_.Segment -eq "IN1"} | select -Skip 1)
- #$IN1_B.HL7Pos
- ($msg | where {$_.HL7Pos -eq $IN1_B.HL7Pos} | select -First 1)
- # set field
- $MSH.Fields[4] = "TEST"
- # ensure its set to our value
- write-host (($msg | where {$_.Segment -eq "MSH"} | select -First 1).Fields[4])
- #print back out to console with our changes
- write-host (object-to-hl7($msg))
- # search all hl7s and return whether the patient name has a john in it
- (Get-ChildItem $path) | foreach {
- $msg = hl7-to-object((get-content $_))
- $isRightPatient = ($msg | where {($_.Segment -eq "PID") -and ($_.Fields[4] -like "*JOHN*")} | select -First 1)
- if($isRightPatient -eq $null) {
- write-host "No"
- } else {
- write-host "Yes"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement