daily pastebin goal
1%
SHARE
TWEET

HL7 message construction

nikosv Jul 26th, 2016 142 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Creating an HL7 v2.6 message
  2. #Nikos Vaggalis, www.i-programmer.info
  3. ##http://www.i-programmer.info/programming/perl/9920-health-level-7-hl7-with-perl.html
  4. #license:Artistic 1.0
  5.  
  6. use Net::HL7::Message;
  7. use Net::HL7::Segment;
  8. use Net::HL7::Segments::MSH;
  9. use Time::Piece;
  10. use strict;
  11.  
  12. $Net::HL7::HL7_VERSION='2.6';
  13.  
  14. #####DATA INIT
  15.  
  16. my $msh_9=["ADT","A01","ADT_A01"];
  17. my $msh_10=201;
  18. my $msh_22="DD015";
  19.  
  20. my $pid_3= [
  21.               "100660325",["NationalPN","2.16.840.1.113883.19.3","ISO"],"0"
  22.               ."~"."80253",'','','','',1
  23.            ];
  24. my $pid_5=["GREENING","WAYNE",'','','','',"L"];
  25. my $pid_7="30/01/1961";
  26. my $pid_8="M";
  27. my $pid_19=303603715;
  28. my $pid_23="LONDON";
  29.  
  30. my $pv1_2="E";
  31. my $pv1_7=12345678901;
  32. my $pv1_18=0;
  33. my $pv1_19=185;
  34. my $pv1_20=0;
  35.  
  36. my @dg1data=([1,"S42.1"],[2,"S42.2"]);
  37.  
  38. my $msg = new Net::HL7::Message();
  39.  
  40. #####MSH SEGMENT
  41. my $msh = new Net::HL7::Segments::MSH();
  42.    $msh->setField(7, $msh->getField(7)."+0200");
  43.    $msh->setField(9, $msh_9);
  44.    $msh->setField(10, "id".$msh_10);
  45.    $msh->setField(11, "P");
  46.    $msh->setField(22, $msh_22);
  47. $msg->addSegment($msh);
  48.  
  49. #####PID SEGMENT
  50. my $pid = new Net::HL7::Segment("PID");
  51.    $pid->setField(3,  $pid_3);
  52.    $pid->setField(5,  $pid_5);
  53.  
  54. my $time = Time::Piece->strptime($pid_7,'%d/%m/%Y');
  55.    $time= $time->strftime('%Y%m%d');
  56.    $pid->setField(7,  $time);
  57.  
  58.    $pid->setField(8,  $pid_8);
  59.    $pid->setField(19, $pid_19);
  60.    $pid->setField(23, $pid_23);
  61. $msg->addSegment($pid);
  62.  
  63. #####PV1 SEGMENT
  64. my $pv1 = new Net::HL7::Segment("PV1");
  65.    $pv1->setField(2, $pv1_2);
  66.    $pv1->setField(7, $pv1_7);
  67.    $pv1->setField(18, $pv1_18);
  68.    $pv1->setField(19, $pv1_19);
  69.    $pv1->setField(20, $pv1_20);
  70.  
  71. $msg->addSegment($pv1);
  72.  
  73.  
  74. for (my $i=0;$i<=$#dg1data;$i++) {
  75.     my $dg = new Net::HL7::Segment("DG1");
  76.        $dg->setField(1, $dg1data[$i]->[0]);
  77.        $dg->setField(3, $dg1data[$i]->[1]);
  78.        $msg->addSegment($dg);
  79. };
  80.  
  81.  
  82. print $msg->toString();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top