-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.pl
70 lines (56 loc) · 1.66 KB
/
parse.pl
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
#!/usr/bin/perl -w
use Moose;
use v5.10;
use Time::Piece;
use Data::Dumper;
use xDT::Parser;
my $xdt_file = shift // croak('Error: no xDT file given');
my $config_file = shift;
my $parser = xDT::Parser->new($config_file);
$parser->open($xdt_file);
while (my $object = $parser->next_object) {
last if $object->is_empty;
say _extract_core_data($object);
say _extract_measurements($object);
}
$parser->close();
sub _extract_core_data {
my $object = shift // croak('Error: parameter $object missing.');
return sprintf(
'%s: %s %s (%s, %s)',
$object->get_value('patient_number'),
$object->get_value('firstname'),
$object->get_value('surname'),
Time::Piece->strptime($object->get_value('birthdate'), '%d%m%Y')->ymd,
$object->get_value('sex')
);
}
sub _extract_measurements {
my $object = shift // croak('Error: parameter $object missing.');
my @measurements = ();
my $measurement = ();
while (my $record = $object->next_record) {
last unless defined $record;
if ($record->get_accessor eq 'test_identification') {
push @measurements, $measurement if defined $measurement->{test_identification};
$measurement = ();
$measurement->{test_identification} = $record->get_value;
} else {
foreach my $accessor ('collection_date', 'collection_time', 'result', 'unit') {
next unless $record->get_accessor eq $accessor;
$measurement->{$accessor} = $record->get_value;
}
}
}
push @measurements, $measurement;
return join "\n", map {
my $date = Time::Piece->strptime($_->{collection_date} // '', '%d%m%Y')->ymd;
sprintf(
'%s - %s: %s %s',
$date,
$_->{test_identification},
$_->{result},
$_->{unit}
);
} @measurements;
}