-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Send.pm
203 lines (143 loc) · 3.72 KB
/
Send.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package App::HL7::Send;
use strict;
use warnings;
use Class::Utils qw(set_params);
use Error::Pure qw(err);
use Getopt::Std;
use Net::HL7::Connection;
use Net::HL7::Message;
use Perl6::Slurp qw(slurp);
our $VERSION = 0.06;
# Constructor.
sub new {
my ($class, @params) = @_;
# Create object.
my $self = bless {}, $class;
# Process params.
set_params($self, @params);
# Object.
return $self;
}
# Run.
sub run {
my $self = shift;
# Process arguments.
$self->{'_opts'} = {
'h' => 0,
};
if (! getopts('h', $self->{'_opts'}) || @ARGV < 3
|| $self->{'_opts'}->{'h'}) {
print STDERR "Usage: $0 [-h] [--version] host port hl7_file|-\n";
print STDERR "\t-h\t\tPrint help.\n";
print STDERR "\t--version\tPrint version.\n";
return 1;
}
$self->{'_hl7_host'} = $ARGV[0];
$self->{'_hl7_port'} = $ARGV[1];
$self->{'_hl7_file'} = $ARGV[2];
# Get hl7_file.
my $hl7;
if ($self->{'_hl7_file'} eq '-') {
while (my $line = <STDIN>) {
$hl7 .= $line;
}
} else {
$hl7 = slurp($self->{'_hl7_file'});
}
# Create message.
my $msg = Net::HL7::Message->new($hl7);
if (! $msg) {
err 'Cannot parse HL7 file.', 'File', $self->{'_hl7_file'};
}
# Create connection.
my $conn = Net::HL7::Connection->new($self->{'_hl7_host'},
$self->{'_hl7_port'});
if (! $conn) {
err 'Cannot connect to host.';
}
# Send.
$conn->send($msg);
print "Message was send.\n";
return 0;
}
1;
__END__
=pod
=encoding utf8
=head1 NAME
App::HL7::Send - Base class for hl7send script.
=head1 SYNOPSIS
use App::HL7::Send;
my $app = App::HL7::Send->new;
my $exit_code = $app->run;
=head1 METHODS
=head2 C<new>
my $app = App::HL7::Send->new;
Constructor.
Returns instance of object.
=head2 C<run>
my $exit_code = $app->run;
Run method.
Returns 1 for error, 0 for success.
=head1 ERRORS
new():
From Class::Utils::set_params():
Unknown parameter '%s'.
run():
Cannot connect to host.
Cannot parse HL7 file.
File: %s
=head1 EXAMPLE
=for comment filename=send_test_orm_to_dcm4chee.pl
use strict;
use warnings;
use App::HL7::Send;
use File::Temp qw(tempfile);
use IO::Barf qw(barf);
# Arguments.
if (@ARGV < 1) {
print STDERR "Usage: $0 host port\n";
exit 1;
}
my $host = $ARGV[0];
my $port = $ARGV[1] || 2575;
# Test ORM data for dcm4chee.
my $hl7 = <<'END';
MSH|^~\&|FROM|Facility #1|TO|Facility #2|20160403211012||ORM^O01|MSGID20160403211012|P|1.0
PID|||11111||Novak^Jan^^^Ing.||19680821|M|||Olomoucká^^Brno^^61300^Czech Republic|||||||
PV1||O|OP^PAREG^||||1234^Clark^Bob|||OP|||||||||2|||||||||||||||||||||||||20160403211012|
ORC|NW|A100Z^MESA_ORDPLC|B100Z^MESA_ORDFIL||SC||1^once^^20160101121212^^S||200008161510|^ROSEWOOD^RANDOLPH||7101^ESTRADA^JAIME^P^^DR||(314)555-1212|200008161510||922229-10^IHE-RAD^IHE-CODE-231||
OBR|1|A100Z^MESA_ORDPLC|B100Z^MESA_ORDFIL|P1^Procedure 1^ERL_MESA^X1_A1^SPAction Item X1_A1^DSS_MESA|||||||||xxx||Radiology^^^^R|7101^ESTRADA^JAIME^P^^DR||XR999999|RP123456|SPS123456||||ES|||1^once^^20160101121212^^S|||WALK|||||||||||A|||RP_X1^RP Action Item RP_X1^DSS_MESA
ZDS|1.2.1^100^Application^DICOM
END
# Barf to temp file.
my (undef, $file) = tempfile();
barf($file, $hl7);
# Arguments (dcm4chee).
@ARGV = (
$host,
$port,
$file,
);
# Run.
App::HL7::Send->new->run;
# Output:
# Message was send.
=head1 DEPENDENCIES
L<Class::Utils>,
L<Error::Pure>,
L<Getopt::Std>,
L<Net::HL7::Connection>,
L<Net::HL7::Message>,
L<Perl6::Slurp>.
=head1 REPOSITORY
L<https://github.com/michal-josef-spacek/App-HL7-Send>
=head1 AUTHOR
Michal Josef Špaček L<mailto:skim@cpan.org>
L<http://skim.cz>
=head1 LICENSE AND COPYRIGHT
© 2016-2023 Michal Josef Špaček
BSD 2-Clause License
=head1 VERSION
0.06
=cut