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) = @_;
61 my $current_holdings = [];
62 my $current_supplements = [];
63 my $current_indexes = [];
64 my $online = []; # Laurentian extension to MFHD standard
65 my $missing = []; # Laurentian extension to MFHD standard
66 my $incomplete = []; # Laurentian extension to MFHD standard
68 my $marc = MARC::Record->new_from_xml($mfhd_xml);
69 my $mfhd = MFHD->new($marc);
71 foreach my $subfield_ref ($marc->field('852')->subfields) {
72 my ($subfield, $data) = @$subfield_ref;
73 $location .= $data . " -- ";
75 $location =~ s/ -- $//;
77 foreach my $field ($marc->field('866')) {
78 my $textual_holdings = $self->format_textual_holdings($field);
79 if ($textual_holdings) {
80 push @$holdings, $textual_holdings;
83 foreach my $field ($marc->field('867')) {
84 my $textual_holdings = $self->format_textual_holdings($field);
85 if ($textual_holdings) {
86 push @$supplements, $textual_holdings;
89 foreach my $field ($marc->field('868')) {
90 my $textual_holdings = $self->format_textual_holdings($field);
91 if ($textual_holdings) {
92 push @$indexes, $textual_holdings;
96 foreach my $cap_id ($mfhd->captions('853')) {
97 my @curr_holdings = $mfhd->holdings('863', $cap_id);
98 next unless scalar @curr_holdings;
99 foreach (@curr_holdings) {
100 push @$current_holdings, $_->format();
104 foreach my $cap_id ($mfhd->captions('854')) {
105 my @curr_supplements = $mfhd->holdings('864', $cap_id);
106 next unless scalar @curr_supplements;
107 foreach (@curr_supplements) {
108 push @$current_supplements, $_->format();
112 foreach my $cap_id ($mfhd->captions('855')) {
113 my @curr_indexes = $mfhd->holdings('865', $cap_id);
114 next unless scalar @curr_indexes;
115 foreach (@curr_indexes) {
116 push @$current_indexes, $_->format();
120 # Laurentian extensions
121 foreach my $field ($marc->field('530')) {
122 my $online_stmt = $self->format_textual_holdings($field);
124 push @$online, $online_stmt;
128 foreach my $field ($marc->field('590')) {
129 my $missing_stmt = $self->format_textual_holdings($field);
131 push @$missing, $missing_stmt;
135 foreach my $field ($marc->field('591')) {
136 my $incomplete_stmt = $self->format_textual_holdings($field);
137 if ($incomplete_stmt) {
138 push @$incomplete, $incomplete_stmt;
142 return { location => $location, holdings => $holdings, current_holdings => $current_holdings,
143 supplements => $supplements, current_supplements => $current_supplements,
144 indexes => $indexes, current_indexes => $current_indexes,
145 missing => $missing, incomplete => $incomplete, };
150 =item * init_holdings_virtual_record()
154 Initialize the serial virtual record (svr) instance
157 sub init_holdings_virtual_record {
158 my $record = Fieldmapper::serial::virtual_record->new;
161 $record->owning_lib();
162 $record->holdings([]);
163 $record->current_holdings([]);
164 $record->supplements([]);
165 $record->current_supplements([]);
166 $record->indexes([]);
167 $record->current_indexes([]);
169 $record->missing([]);
170 $record->incomplete([]);
176 =item * init_holdings_virtual_record($mfhd)
180 Given an MFHD record, return a populated svr instance
184 my ($self, $id, $mfhd, $owning_lib) = @_;
190 my $record = init_holdings_virtual_record();
191 my $holdings = $self->mfhd_to_hash($mfhd);
194 $record->owning_lib($owning_lib);
195 $record->location($holdings->{location});
196 $record->holdings($holdings->{holdings});
197 $record->current_holdings($holdings->{current_holdings});
198 $record->supplements($holdings->{supplements});
199 $record->current_supplements($holdings->{current_supplements});
200 $record->indexes($holdings->{indexes});
201 $record->current_indexes($holdings->{current_indexes});
202 $record->online($holdings->{online});
203 $record->missing($holdings->{missing});
204 $record->incomplete($holdings->{incomplete});