From c45b4fae5bd1a2c2666727b1868f4591796d3bd5 Mon Sep 17 00:00:00 2001 From: Javier-Jimenez-18 Date: Wed, 13 Dec 2023 22:27:06 -0700 Subject: [PATCH 1/2] Created ipd_information_types_data mapper method to the v2 processor and added RSpec test case. --- app/models/study_json_record/processor_v2.rb | 7 +++++++ .../study_json_record/processor_v2_spec.rb | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/app/models/study_json_record/processor_v2.rb b/app/models/study_json_record/processor_v2.rb index 0b32e2d5..a14aeda0 100644 --- a/app/models/study_json_record/processor_v2.rb +++ b/app/models/study_json_record/processor_v2.rb @@ -227,6 +227,13 @@ def id_information_data end def ipd_information_types_data + return unless protocol_section + + nct_id = protocol_section.dig('identificationModule', 'nctId') + ipd_sharing_info_types = protocol_section.dig('ipdSharingStatementModule', 'infoTypes') + return unless ipd_sharing_info_types + + { nct_id: nct_id, name: ipd_sharing_info_types } end def keywords_data diff --git a/spec/models/study_json_record/processor_v2_spec.rb b/spec/models/study_json_record/processor_v2_spec.rb index 8f1280a9..1303ffc9 100644 --- a/spec/models/study_json_record/processor_v2_spec.rb +++ b/spec/models/study_json_record/processor_v2_spec.rb @@ -329,4 +329,20 @@ end end + describe '#ipd_information_types_data' do + it 'should use JSON API to generate data that will be inserted into the ipd information types table' do + expected_data = { + nct_id: "NCT03630471", + name: [ + "STUDY_PROTOCOL", + "SAP", + "ICF" + ] + } + hash = JSON.parse(File.read('spec/support/json_data/NCT03630471.json')) + processor = StudyJsonRecord::ProcessorV2.new(hash) + expect(processor.ipd_information_types_data).to eq(expected_data) + end + end + end \ No newline at end of file From 97f51da623b3f9e97df8fba0d01aaa581d251320 Mon Sep 17 00:00:00 2001 From: Javier-Jimenez-18 Date: Fri, 15 Dec 2023 23:58:57 -0700 Subject: [PATCH 2/2] Fixed ipd_information_types_data method to return an array instead of a hash. Updated RSpec test file. --- app/models/study_json_record/processor_v2.rb | 7 ++++++- spec/models/study_json_record/processor_v2_spec.rb | 13 +++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/models/study_json_record/processor_v2.rb b/app/models/study_json_record/processor_v2.rb index a14aeda0..639ce38e 100644 --- a/app/models/study_json_record/processor_v2.rb +++ b/app/models/study_json_record/processor_v2.rb @@ -233,7 +233,12 @@ def ipd_information_types_data ipd_sharing_info_types = protocol_section.dig('ipdSharingStatementModule', 'infoTypes') return unless ipd_sharing_info_types - { nct_id: nct_id, name: ipd_sharing_info_types } + collection = [] + ipd_sharing_info_types.each do |info| + collection << { nct_id: nct_id, name: info } + end + + collection end def keywords_data diff --git a/spec/models/study_json_record/processor_v2_spec.rb b/spec/models/study_json_record/processor_v2_spec.rb index 1303ffc9..e875587b 100644 --- a/spec/models/study_json_record/processor_v2_spec.rb +++ b/spec/models/study_json_record/processor_v2_spec.rb @@ -331,14 +331,11 @@ describe '#ipd_information_types_data' do it 'should use JSON API to generate data that will be inserted into the ipd information types table' do - expected_data = { - nct_id: "NCT03630471", - name: [ - "STUDY_PROTOCOL", - "SAP", - "ICF" - ] - } + expected_data = [ + { nct_id: "NCT03630471", name: "STUDY_PROTOCOL" }, + { nct_id: "NCT03630471", name: "SAP" }, + { nct_id: "NCT03630471", name: "ICF" } + ] hash = JSON.parse(File.read('spec/support/json_data/NCT03630471.json')) processor = StudyJsonRecord::ProcessorV2.new(hash) expect(processor.ipd_information_types_data).to eq(expected_data)