From a64ec3419f37d80c56c84ae74aad7198a7cabdfd Mon Sep 17 00:00:00 2001 From: jazairi <16103405+jazairi@users.noreply.github.com> Date: Mon, 2 Feb 2026 09:59:39 -0800 Subject: [PATCH] Skip Libkey lookup for records with multiple DOIs or PMIDs Why these changes are being introduced: Some records can have many DOIs or PMIDs (as many as 467 in one case). It's probably not helpful for Libkey to assume that the first identifier is the best one. Relevant ticket(s): - https://mitlibraries.atlassian.net/browse/USE-332 How this addresses that need: This adds a guard clause to the DOI and PMID methods that returns nil when multiple identifiers are found. This prevents Libkey from showing an uncertain fulfillment URL. Side effects of this change: Reduction of fulfillment links made available via Libkey. --- app/models/normalize_primo_record.rb | 6 ++++++ test/models/normalize_primo_record_test.rb | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/models/normalize_primo_record.rb b/app/models/normalize_primo_record.rb index cb15beb0..cb1331dd 100644 --- a/app/models/normalize_primo_record.rb +++ b/app/models/normalize_primo_record.rb @@ -184,6 +184,9 @@ def doi if @record['pnx']['addata']['doi'].length > 1 Sentry.set_tags('mitlib.recordId': identifier || 'empty record id') Sentry.capture_message('Multiple DOIs found in one record') + + # Exit method to avoid ambiguous LibKey lookups. + return end @record['pnx']['addata']['doi'].first @@ -195,6 +198,9 @@ def pmid if @record['pnx']['addata']['pmid'].length > 1 Sentry.set_tags('mitlib.recordId': identifier || 'empty record id') Sentry.capture_message('Multiple PMIDs found in one record') + + # Exit method to avoid ambiguous LibKey lookups. + return end @record['pnx']['addata']['pmid'].first diff --git a/test/models/normalize_primo_record_test.rb b/test/models/normalize_primo_record_test.rb index c234d5ae..1fb4fd99 100644 --- a/test/models/normalize_primo_record_test.rb +++ b/test/models/normalize_primo_record_test.rb @@ -142,13 +142,13 @@ def cdi_record assert_nil normalized[:doi] end - test 'multiple dois normalize to the first one' do + test 'multiple dois are ignored' do temp_record = full_record temp_record['pnx']['addata']['doi'] = %w[three two one] normalized = NormalizePrimoRecord.new(temp_record, 'test').normalize - assert_equal normalized[:doi], 'three' + assert_nil normalized[:doi] end test 'normalizes pmid' do @@ -161,13 +161,13 @@ def cdi_record assert_nil normalized[:pmid] end - test 'multiple pmids normalize to the first one' do + test 'multiple pmids are ignored' do temp_record = full_record temp_record['pnx']['addata']['pmid'] = %w[three two one] normalized = NormalizePrimoRecord.new(temp_record, 'test').normalize - assert_equal normalized[:pmid], 'three' + assert_nil normalized[:pmid] end test 'normalizes summary' do