From a615ed2b0aba2c553563045cda85c67c576b7f5e Mon Sep 17 00:00:00 2001 From: Michael Gurley Date: Tue, 30 Jun 2015 13:37:59 -0500 Subject: [PATCH] close #104 abstractable.remove_abstractions does not clean up abstractor_abstraction_group_members and abstractor_abstraction_groups * However, left a failing spec related to another issue unearthed. That the creation of abstractor abstraction groups does not seem to respect namespaces. References #126 --- lib/abstractor/abstractable.rb | 13 +++++++++++++ .../methods/models/abstractor_abstraction.rb | 2 +- spec/models/abstractor/imaging_spec.rb | 14 +++++++++++--- .../radiation_therapy_prescription_spec.rb | 17 +++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/lib/abstractor/abstractable.rb b/lib/abstractor/abstractable.rb index e1ae056..3afc1a3 100644 --- a/lib/abstractor/abstractable.rb +++ b/lib/abstractor/abstractable.rb @@ -185,6 +185,13 @@ def remove_abstractions(options = {}) options = { abstractor_abstractions: abstractor_abstractions }.merge(options) abstractor_abstractions = abstractor_abstractions_by_abstraction_schemas(options) end + abstractor_abstraction_groups = [] + abstractor_abstractions.each do |abstractor_abstraction| + if abstractor_abstraction.abstractor_abstraction_group + abstractor_abstraction_groups << abstractor_abstraction.abstractor_abstraction_group + end + end + abstractor_abstraction_groups.uniq! abstractor_abstractions.each do |abstractor_abstraction| if !options[:only_unreviewed] || (options[:only_unreviewed] && abstractor_abstraction.unreviewed?) abstractor_abstraction.abstractor_suggestions.each do |abstractor_suggestion| @@ -195,9 +202,15 @@ def remove_abstractions(options = {}) abstractor_abstraction.abstractor_indirect_sources.each do |abstractor_indirect_source| abstractor_indirect_source.destroy end + abstractor_abstraction.destroy end end + abstractor_abstraction_groups.each do |abstractor_abstraction_group| + if abstractor_abstraction_group.reload.abstractor_abstraction_group_members.empty? + abstractor_abstraction_group.destroy + end + end end ## diff --git a/lib/abstractor/methods/models/abstractor_abstraction.rb b/lib/abstractor/methods/models/abstractor_abstraction.rb index 7703918..e1691d0 100644 --- a/lib/abstractor/methods/models/abstractor_abstraction.rb +++ b/lib/abstractor/methods/models/abstractor_abstraction.rb @@ -13,7 +13,7 @@ def self.included(base) base.send :has_many, :abstractor_abstraction_sources, :through => :abstractor_abstractor_suggestions base.send :has_many, :abstractor_indirect_sources - base.send :has_one, :abstractor_abstraction_group_member + base.send :has_one, :abstractor_abstraction_group_member, dependent: :destroy base.send :has_one, :abstractor_abstraction_group, :through => :abstractor_abstraction_group_member base.send :has_one, :abstractor_abstraction_schema, :through => :abstractor_subject diff --git a/spec/models/abstractor/imaging_spec.rb b/spec/models/abstractor/imaging_spec.rb index e295136..0ee80e0 100644 --- a/spec/models/abstractor/imaging_spec.rb +++ b/spec/models/abstractor/imaging_spec.rb @@ -195,15 +195,24 @@ end #removing abstractions - it "removes abstractions in a namespace", focus: false do + it "removes abstractions and groups in a namespace", focus: false do @imaging_exam.abstract(namespace_type: @abstractor_subject_abstraction_schema_dat.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_dat.namespace_id) expect(@imaging_exam.reload.abstractor_abstractions_by_namespace(namespace_type: @abstractor_subject_abstraction_schema_dat.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_dat.namespace_id).size).to eq(5) expect(@imaging_exam.abstractor_abstractions_by_namespace(namespace_type: @abstractor_subject_abstraction_schema_recist_response.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_recist_response.namespace_id).size).to eq(5) + abstractor_abstraction_groups = [] + @imaging_exam.reload.abstractor_abstractions_by_namespace(namespace_type: @abstractor_subject_abstraction_schema_dat.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_dat.namespace_id).each do |abstractor_abstraction| + if abstractor_abstraction.abstractor_abstraction_group + abstractor_abstraction_groups << abstractor_abstraction.abstractor_abstraction_group + end + end @imaging_exam.remove_abstractions(namespace_type: @abstractor_subject_abstraction_schema_recist_response.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_recist_response.namespace_id) expect(@imaging_exam.reload.abstractor_abstractions_by_namespace(namespace_type: @abstractor_subject_abstraction_schema_dat.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_dat.namespace_id).size).to eq(5) expect(@imaging_exam.abstractor_abstractions_by_namespace(namespace_type: @abstractor_subject_abstraction_schema_recist_response.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_recist_response.namespace_id).size).to eq(0) + abstractor_abstraction_groups.each do |abstractor_abstraction_group| + expect(Abstractor::AbstractorAbstractionGroup.find(abstractor_abstraction_group.id)).to be_nil + end end it "will not remove reviewed abstractions in a namespace (if so instructed)", focus: false do @@ -466,12 +475,11 @@ expect(@imaging_exam.reload.detect_abstractor_abstraction(@abstractor_subject_abstraction_schema_diagnosis_duration_2)).to be_nil end - #removing abstractions it "removes abstractions in a namespace", focus: false do @imaging_exam.abstract(namespace_type: @abstractor_subject_abstraction_schema_moomin_minor.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_moomin_minor.namespace_id) expect(@imaging_exam.reload.abstractor_abstractions_by_namespace(namespace_type: @abstractor_subject_abstraction_schema_moomin_minor.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_moomin_minor.namespace_id).size).to eq(5) - expect(@imaging_exam.abstractor_abstractions_by_namespace(namespace_type: @abstractor_subject_abstraction_schema_moomin_major.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_moomin_major.namespace_id).size).to eq(3) + expect(@imaging_exam.reload.abstractor_abstractions_by_namespace(namespace_type: @abstractor_subject_abstraction_schema_moomin_major.namespace_type, namespace_id: @abstractor_subject_abstraction_schema_moomin_major.namespace_id).size).to eq(3) @imaging_exam.remove_abstractions( namespace_type: @abstractor_subject_abstraction_schema_moomin_major.namespace_type, diff --git a/spec/models/abstractor/radiation_therapy_prescription_spec.rb b/spec/models/abstractor/radiation_therapy_prescription_spec.rb index 8ffeadf..7ae5ea1 100644 --- a/spec/models/abstractor/radiation_therapy_prescription_spec.rb +++ b/spec/models/abstractor/radiation_therapy_prescription_spec.rb @@ -163,6 +163,23 @@ expect(radiation_therapy_prescription.reload.detect_abstractor_abstraction(@abstractor_subject_abstraction_schema_has_anatomical_location).abstractor_suggestions.select { |abstractor_suggestion| abstractor_suggestion.unknown }.size).to eq(1) end + #removing abstractions + it "removes grouped abstractor abstractions", focus: false do + radiation_therapy_prescription = FactoryGirl.create(:radiation_therapy_prescription, site_name: 'left parietal lobe') + radiation_therapy_prescription.abstract + abstractor_abstraction_groups = [] + radiation_therapy_prescription.abstractor_abstractions.each do |abstractor_abstraction| + abstractor_abstraction_groups << abstractor_abstraction.abstractor_abstraction_group + end + abstractor_abstraction_groups.uniq! + expect(radiation_therapy_prescription.abstractor_abstractions.size).to eq(2) + radiation_therapy_prescription.remove_abstractions + expect(radiation_therapy_prescription.reload.abstractor_abstractions.size).to eq(0) + abstractor_abstraction_groups.each do |abstractor_abstraction_group| + expect(Abstractor::AbstractorAbstractionGroup.where(id: abstractor_abstraction_group.id).first).to be_nil + end + end + #groups it "creates a abstractor abstraction group" do radiation_therapy_prescription = FactoryGirl.create(:radiation_therapy_prescription, site_name: 'left parietal lobe')