From 4f95f088735f01516a95c7589334478ac830786a Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 27 Jul 2012 10:42:34 -0400 Subject: [PATCH] Support copy-level data via GIR segments Currently supported fields: copy_id fund (fund code) owning_lib (library code) call_number item_type copy_location quantity barcode collection_code For reference, see http://www.editeur.org/31/Library-Book-Supply/, section "Purchase Order for book orders". Signed-off-by: Bill Erickson --- lib/openils/mapper.rb | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/openils/mapper.rb b/lib/openils/mapper.rb index 9cdac4cd9..3f1004eed 100644 --- a/lib/openils/mapper.rb +++ b/lib/openils/mapper.rb @@ -79,6 +79,36 @@ OpenILS::Mapper.map 'item' do |mapper,key,value| end mapper.add('PRI', { 'C509' => { '5118' => value['price'] } }) mapper.add('RFF', { 'C506' => { '1153' => 'LI', '1154' => value['line_number'] } }) + + # map copy-level data to GIR + if value.has_key?('copies') + copies = value['copies'] + + copies.each_with_index { |copy,index| + + break if index == 1000 # max allowed by spec + + fields = [] + fields.push({'7405' => 'LCO', '7402' => copy['copy_id']}) if copy.has_key?('copy_id') + fields.push({'7405' => 'LAC', '7402' => copy['barcode']}) if copy.has_key?('barcode') + fields.push({'7405' => 'LFN', '7402' => copy['fund']}) if copy.has_key?('fund') + fields.push({'7405' => 'LLO', '7402' => copy['owning_lib']}) if copy.has_key?('owning_lib') + fields.push({'7405' => 'LSM', '7402' => copy['call_number']}) if copy.has_key?('call_number') + fields.push({'7405' => 'LST', '7402' => copy['item_type']}) if copy.has_key?('item_type') + fields.push({'7405' => 'LSQ', '7402' => copy['copy_location']}) if copy.has_key?('copy_location') + fields.push({'7405' => 'LQT', '7402' => copy['quantity']}) if copy.has_key?('quantity') + fields.push({'7405' => 'LFH', '7402' => copy['collection_code']}) if copy.has_key?('collection_code') + + ident = sprintf('%.3d', index + 1) + + # GIR segments may only have 5 fields. Any more and we + # must add an additional segment with the extra fields + mapper.add('GIR', { '7297' => ident, 'C206' => fields.slice!(0, 5) }) + if fields.length > 0 + mapper.add('GIR', { '7297' => ident, 'C206' => fields }) + end + } + end end OpenILS::Mapper.map('party',/^(buyer|vendor)$/) do |mapper,key,value| @@ -120,4 +150,4 @@ OpenILS::Mapper.map 'desc' do |mapper,key,value| mapper.add('IMD', { '7077' => code_qual, '7081' => code, 'C273' => { '7008' => data } }) } end -end \ No newline at end of file +end -- 2.11.0