1 package OpenILS::Utils::MFHDParser;
2 use strict; use warnings;
4 use OpenSRF::EX qw/:try/;
5 use Time::HiRes qw(time);
6 use OpenILS::Utils::Fieldmapper;
7 use OpenSRF::Utils::SettingsClient;
8 use OpenSRF::Utils::Logger qw/$logger/;
10 use OpenILS::Utils::MFHD;
14 sub new { return bless( {}, shift() ); }
20 =item * format_textual_holdings($field)
24 Returns concatenated subfields $a with $z for textual holdings (866-868)
28 sub format_textual_holdings {
29 my ($self, $field) = @_;
33 $holdings = $field->subfield('a');
38 $public_note = $field->subfield('z');
40 return "$holdings - $public_note";
47 =item * mfhd_to_hash($mfhd_xml)
51 Returns a Perl hash containing fields of interest from the MFHD record
55 my ($self, $mfhd_xml) = @_;
60 my $current_holdings = [];
61 my $current_supplements = [];
62 my $current_indexes = [];
63 my $online = []; # Laurentian extension to MFHD standard
64 my $missing = []; # Laurentian extension to MFHD standard
65 my $incomplete = []; # Laurentian extension to MFHD standard
67 my $marc = MARC::Record->new_from_xml($mfhd_xml);
68 my $mfhd = MFHD->new($marc);
70 foreach my $field ($marc->field('866')) {
71 my $textual_holdings = $self->format_textual_holdings($field);
72 if ($textual_holdings) {
73 push @$holdings, $textual_holdings;
76 foreach my $field ($marc->field('867')) {
77 my $textual_holdings = $self->format_textual_holdings($field);
78 if ($textual_holdings) {
79 push @$supplements, $textual_holdings;
82 foreach my $field ($marc->field('868')) {
83 my $textual_holdings = $self->format_textual_holdings($field);
84 if ($textual_holdings) {
85 push @$indexes, $textual_holdings;
89 foreach my $cap_id ($mfhd->captions('853')) {
90 my @curr_holdings = $mfhd->holdings('863', $cap_id);
91 next unless scalar @curr_holdings;
92 foreach (@curr_holdings) {
93 push @$current_holdings, $_->format();
97 foreach my $cap_id ($mfhd->captions('854')) {
98 my @curr_supplements = $mfhd->holdings('864', $cap_id);
99 next unless scalar @curr_supplements;
100 foreach (@curr_supplements) {
101 push @$current_supplements, $_->format();
105 foreach my $cap_id ($mfhd->captions('855')) {
106 my @curr_indexes = $mfhd->holdings('865', $cap_id);
107 next unless scalar @curr_indexes;
108 foreach (@curr_indexes) {
109 push @$current_indexes, $_->format();
113 # Laurentian extensions
114 foreach my $field ($marc->field('530')) {
115 my $online_stmt = $self->format_textual_holdings($field);
117 push @$online, $online_stmt;
121 foreach my $field ($marc->field('590')) {
122 my $missing_stmt = $self->format_textual_holdings($field);
124 push @$missing, $missing_stmt;
128 foreach my $field ($marc->field('591')) {
129 my $incomplete_stmt = $self->format_textual_holdings($field);
130 if ($incomplete_stmt) {
131 push @$incomplete, $incomplete_stmt;
135 return { holdings => $holdings, current_holdings => $current_holdings,
136 supplements => $supplements, current_supplements => $current_supplements,
137 indexes => $indexes, current_indexes => $current_indexes,
138 missing => $missing, incomplete => $incomplete, };
143 =item * init_holdings_virtual_record()
147 Initialize the serial virtual record (svr) instance
150 sub init_holdings_virtual_record {
151 my $record = Fieldmapper::serial::virtual_record->new;
152 $record->holdings([]);
153 $record->current_holdings([]);
154 $record->supplements([]);
155 $record->current_supplements([]);
156 $record->indexes([]);
157 $record->current_indexes([]);
159 $record->missing([]);
160 $record->incomplete([]);
166 =item * init_holdings_virtual_record($mfhd)
170 Given an MFHD record, return a populated svr instance
174 my ($self, $mfhd) = @_;
180 my $record = init_holdings_virtual_record();
181 my $holdings = $self->mfhd_to_hash($mfhd);
183 $record->holdings($holdings->{holdings});
184 $record->current_holdings($holdings->{current_holdings});
185 $record->supplements($holdings->{supplements});
186 $record->current_supplements($holdings->{current_supplements});
187 $record->indexes($holdings->{indexes});
188 $record->current_indexes($holdings->{current_indexes});
189 $record->online($holdings->{online});
190 $record->missing($holdings->{missing});
191 $record->incomplete($holdings->{incomplete});