Class: Buhos::QualityCriteriaProcessor
- Inherits:
-
Object
- Object
- Buhos::QualityCriteriaProcessor
- Defined in:
- lib/buhos/quality_criteria_processor.rb
Class Method Summary collapse
-
.add_criterion_to_rs(review, quality_criterion, scale, order = nil) ⇒ Object
Assign a Quality Criterion to a Systematic Review.
-
.change_criterion_name(review, quality_criterion, new_text) ⇒ Object
Try to change the name of the criterion.
- .change_sr_criterion_name(sr_qc, new_text) ⇒ Object
Class Method Details
.add_criterion_to_rs(review, quality_criterion, scale, order = nil) ⇒ Object
Assign a Quality Criterion to a Systematic Review
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/buhos/quality_criteria_processor.rb', line 34 def self.add_criterion_to_rs(review,quality_criterion, scale, order=nil) if order.nil? max_order=SrQualityCriterion.where(systematic_review_id:review[:id] ).max(:order) order= max_order.nil? ? 1 : max_order+1 end res=Result.new previous_sr_qc=SrQualityCriterion.where(systematic_review_id:review[:id], quality_criterion_id:quality_criterion[:id]) if previous_sr_qc.empty? SrQualityCriterion.insert(systematic_review_id:review[:id], quality_criterion_id:quality_criterion[:id], scale_id:scale[:id], order:order) res.success(I18n::t('quality_assesment.quality_criterion_assigned_to_rs',criterion:quality_criterion[:text], review:review[:name])) else res.error(I18n::t("quality_assesment.quality_criteria_already_defined", criterion:quality_criterion[:text])) end res end |
.change_criterion_name(review, quality_criterion, new_text) ⇒ Object
Try to change the name of the criterion. Only works if no other systematic review had it
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/buhos/quality_criteria_processor.rb', line 53 def self.change_criterion_name(review,quality_criterion,new_text) # Look if other review uses the criterion new_text=new_text.chomp.lstrip qc_id_old=quality_criterion[:id] sr_id=review[:id] raise ArgumentError, I18n::t('quality_assesment.criterion_cant_be_empty') unless new_text!="" other_reviews=SrQualityCriterion.where(quality_criterion_id: qc_id_old).exclude(systematic_review_id: sr_id) old_text=quality_criterion[:text] current_sr_qc=SrQualityCriterion[quality_criterion_id:qc_id_old, systematic_review_id: sr_id] res=Result.new if old_text==new_text res.error(I18n::t('quality_assesment.same_criterion')) elsif !CdQualityCriterion.where(systematic_review_id:sr_id, quality_criterion_id: qc_id_old).empty? res.error(I18n::t("quality_assesment.quality_already_used_delete_for_change", criterion:old_text)) else if other_reviews.empty? and !QualityCriterion[:text=>new_text] # we just can change the name directly on criterion quality_criterion.update(text:new_text) res.success(I18n::t('quality_assesment.change_text_criterion_to', old_text:old_text, new_text:new_text)) else # we have to create a new criterion, and delete the old one. But, if previous responses are available res.add_result(change_sr_criterion_name(current_sr_qc, new_text)) # we just stop the process and ask to delete and add manually end end res end |
.change_sr_criterion_name(sr_qc, new_text) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/buhos/quality_criteria_processor.rb', line 85 def self.change_sr_criterion_name(sr_qc, new_text ) res=Result.new sr_id=sr_qc[:systematic_review_id] res_add=add_criterion_to_rs(SystematicReview[sr_id], QualityCriterion.get_criterion(new_text), Scale[sr_qc[:scale_id]], sr_qc.order) if res_add.success? old_text=sr_qc[:text] sr_qc.delete res.success(I18n::t('quality_assesment.change_text_criterion_to', old_text:old_text, new_text:new_text)) else res.add_result(res_add) end res end |