Support copy-level data via GIR segments collab/berick/openils-mapper
authorBill Erickson <berick@esilibrary.com>
Fri, 27 Jul 2012 14:42:34 +0000 (10:42 -0400)
committerBill Erickson <berick@esilibrary.com>
Thu, 16 Aug 2012 14:48:14 +0000 (10:48 -0400)
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 <berick@esilibrary.com>
lib/openils/mapper.rb

index 9cdac4c..3f1004e 100644 (file)
@@ -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