Advertisement
Guest User

Untitled

a guest
Apr 24th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1.  
  2. # Modify the path variable
  3. $path = "C:\Documents and Settings\BLAHBLAHBLAHUSERNAME\Desktop\HL7Messages"
  4. $src = (Get-ChildItem $path)[1].FullName
  5.  
  6. # take hl7 message as string, convert to posh obj
  7. function hl7-to-object {
  8. param($src)
  9. # go from hl7 to powershell array of objects
  10. $msg = @()
  11. $cursorCount = 0
  12. $src | Foreach {
  13. $split = $_.Split("|")
  14.  
  15. $nodeName = $split[0]
  16.  
  17. $properties = @()
  18. $split | select -skip 1 | foreach {
  19. $properties += $_
  20. }
  21.  
  22. $object = New-Object psobject
  23. $object | Add-Member –membertype noteproperty –Name HL7Pos –Value $cursorCount
  24. $object | Add-Member –membertype noteproperty –Name Segment –Value $nodeName
  25. $object | Add-Member –membertype noteproperty –Name Fields –Value $properties
  26.  
  27. $msg += $object
  28.  
  29. $cursorCount += 1
  30. }
  31. return $msg
  32. }
  33.  
  34. # take posh object formed from hl7 and convert to hl7 string
  35. function object-to-hl7 {
  36. param($msgObj)
  37. # convert back to HL7
  38. $msgSrc = @()
  39. $msgObj | foreach {
  40. $msgSrc += $_.Segment + "|" + ($_.Fields -join "|")
  41. }
  42. return ($msgSrc -join "`r`n")
  43. }
  44.  
  45. # --------
  46. # EXAMPLES
  47. # --------
  48.  
  49. #read hl7 file
  50. $msg = hl7-to-object((get-content $src))
  51. #reading and writing
  52. # grab
  53. $MSH = ($msg | where {$_.Segment -eq "MSH"} | select -First 1)
  54.  
  55. $IN1_B = ($msg | where {$_.Segment -eq "IN1"} | select -Skip 1)
  56.  
  57. #$IN1_B.HL7Pos
  58. ($msg | where {$_.HL7Pos -eq $IN1_B.HL7Pos} | select -First 1)
  59.  
  60. # set field
  61. $MSH.Fields[4] = "TEST"
  62. # ensure its set to our value
  63. write-host (($msg | where {$_.Segment -eq "MSH"} | select -First 1).Fields[4])
  64. #print back out to console with our changes
  65. write-host (object-to-hl7($msg))
  66.  
  67. # search all hl7s and return whether the patient name has a john in it
  68.  
  69. (Get-ChildItem $path) | foreach {
  70. $msg = hl7-to-object((get-content $_))
  71. $isRightPatient = ($msg | where {($_.Segment -eq "PID") -and ($_.Fields[4] -like "*JOHN*")} | select -First 1)
  72. if($isRightPatient -eq $null) {
  73. write-host "No"
  74. } else {
  75. write-host "Yes"
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement