Class: TagInCd
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- TagInCd
- Defined in:
- model/tag_in_cd.rb
Constant Summary collapse
- DECISION_YES =
"yes"
- DECISION_NO =
"no"
Class Method Summary collapse
- .approve_tag(cd, rs, tag, user_id) ⇒ Object
- .approve_tag_batch(cd_a, rs, tag, user_id) ⇒ Object
-
.cds_rs_tag(systematic_review, tag, only_pos = false, stage = nil) ⇒ Object
Retrievs the CD which uses a specific tag on a specific systematic review.
- .reject_tag(cd, rs, tag, user_id) ⇒ Object
- .reject_tag_batch(cd_a, rs, tag, user_id) ⇒ Object
-
.tags_rs(systematic_review) ⇒ Object
All the tags on a specific systematic review.
-
.tags_rs_cd(sr, cd) ⇒ Object
All the tags on a specific systematic review and canonical document.
Class Method Details
.approve_tag(cd, rs, tag, user_id) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'model/tag_in_cd.rb', line 80 def self.approve_tag(cd,rs,tag,user_id) raise(I18n::t(:Object_error)) if cd.nil? or rs.nil? or tag.nil? tag_in_cd_previous=TagInCd.where(:tag_id=>tag.id, :canonical_document_id=>cd.id, :systematic_review_id=>rs.id, :user_id=>user_id) if tag_in_cd_previous.empty? TagInCd.insert(:tag_id=>tag.id, :canonical_document_id=>cd.id, :systematic_review_id=>rs.id, :user_id=>user_id,:decision=>DECISION_YES) else tag_in_cd_previous.update(:decision=>DECISION_YES) end end |
.approve_tag_batch(cd_a, rs, tag, user_id) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'model/tag_in_cd.rb', line 57 def self.approve_tag_batch(cd_a,rs,tag,user_id) result=Result.new $db.transaction do cd_a.each do |cd| TagInCd.approve_tag(cd,rs,tag,user_id) end result.success(I18n::t(:Tag_assigned_to_canonical_documents, tag_text:tag.text, cd_ids:cd_a.map(&:id))) end result end |
.cds_rs_tag(systematic_review, tag, only_pos = false, stage = nil) ⇒ Object
Retrievs the CD which uses a specific tag on a specific systematic review
38 39 40 41 42 43 44 45 46 |
# File 'model/tag_in_cd.rb', line 38 def self.cds_rs_tag(systematic_review,tag,only_pos=false,stage=nil) sql_lista_cd="" if stage sql_lista_cd=" AND cd.id IN (#{systematic_review.cd_id_by_stage(stage).join(',')})" end sql_having=only_pos ? " HAVING n_pos>0 ":"" #$db["SELECT cd.*,SUM(IF(decision='yes',1,0)) n_pos, SUM(IF(decision='no',1,0)) n_neg FROM tag_in_cds tcd INNER JOIN canonical_documents cd ON tcd.canonical_document_id=cd.id WHERE tcd.tag_id=? AND tcd.systematic_review_id=? #{sql_lista_cd} GROUP BY canonical_document_id #{sql_having}", tag.id,systematic_review.id] $db["SELECT cd.*,SUM(CASE WHEN decision='yes' then 1 ELSE 0 END) AS n_pos, SUM(CASE WHEN decision='no' THEN 1 ELSE 0 END) AS n_neg FROM tag_in_cds tcd INNER JOIN canonical_documents cd ON tcd.canonical_document_id=cd.id WHERE tcd.tag_id=? AND tcd.systematic_review_id=? #{sql_lista_cd} GROUP BY canonical_document_id #{sql_having}", tag.id,systematic_review.id] end |
.reject_tag(cd, rs, tag, user_id) ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'model/tag_in_cd.rb', line 89 def self.reject_tag(cd,rs,tag,user_id) raise(I18n::t(:Object_error)) if cd.nil? or rs.nil? or tag.nil? tec_previo=TagInCd.where(:tag_id=>tag.id, :canonical_document_id=>cd.id, :systematic_review_id=>rs.id, :user_id=>user_id) if tec_previo.empty? TagInCd.insert(:tag_id=>tag.id, :canonical_document_id=>cd.id, :systematic_review_id=>rs.id, :user_id=>user_id,:decision=>DECISION_NO) else tec_previo.update(:decision=>DECISION_NO) end end |
.reject_tag_batch(cd_a, rs, tag, user_id) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'model/tag_in_cd.rb', line 69 def self.reject_tag_batch(cd_a,rs,tag,user_id) result=Result.new $db.transaction do cd_a.each do |cd| TagInCd.reject_tag(cd,rs,tag,user_id) end result.success(I18n::t(:Tag_removed_to_canonical_documents, tag_text:tag.text, cd_ids:cd_a.map(&:id))) end result end |
.tags_rs(systematic_review) ⇒ Object
All the tags on a specific systematic review
54 55 56 |
# File 'model/tag_in_cd.rb', line 54 def self.(systematic_review) Tag.inner_join(:tag_in_cds, :tag_id=>:id).where(:systematic_review_id=>systematic_review.id) end |
.tags_rs_cd(sr, cd) ⇒ Object
All the tags on a specific systematic review and canonical document
49 50 51 |
# File 'model/tag_in_cd.rb', line 49 def self.(sr,cd) Tag.inner_join(:tag_in_cds, :tag_id=>:id).where(:systematic_review_id=>sr.id, :canonical_document_id=>cd.id) end |