Skip to content

Commit

Permalink
Merge pull request #1162 from griffithlab/check-outstanding-revisions
Browse files Browse the repository at this point in the history
check for disease usage in revisions in the case where there is no DOID
  • Loading branch information
acoffman authored Dec 5, 2024
2 parents 8bf9380 + d1dcb3b commit 1e5e042
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions server/app/lib/importer/disease_ontology_mirror.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ def delete_unprocessed_diseases

unprocessed_doids.each do |doid|
d = Disease.find_by(doid: doid)
revisions = Revision.where(field_name: 'disease_id').where(current_value: d.id).or(Revision.where(field_name: 'disease_id').where(suggested_value: d.id))
if d.evidence_items.count == 0 && d.assertions.count == 0 && d.source_suggestions.count == 0 && revisions.count == 0
if is_disease_with_no_relations?(d)
d.disease_aliases.clear
d.delete
else
Expand Down Expand Up @@ -121,7 +120,7 @@ def delete_unprocessed_diseases
end
end
Disease.where(doid: nil).each do |d|
if d.evidence_items.count == 0 && d.assertions.count == 0 && d.source_suggestions.count == 0
if is_disease_with_no_relations?(d)
d.disease_aliases.clear
d.delete
elsif ['Solid Tumor', 'Ventricular Dysfunction', 'Acute Mountain Sickness', 'Glioma', 'Low Bone Mineral Density'].include? d.name
Expand All @@ -135,6 +134,20 @@ def delete_unprocessed_diseases
end
end

def is_disease_with_no_relations?(d)
d.evidence_items.count == 0 &&
d.assertions.count == 0 &&
d.source_suggestions.count == 0 &&
revisions_count(d) == 0
end

def revisions_count(disease)
Revision.where(field_name: 'disease_id')
.where(current_value: disease.id)
.or(Revision.where(field_name: 'disease_id').where(suggested_value: disease.id))
.count
end

def url_from_doid(doid)
URI.parse("https://disease-ontology.org/api/metadata/DOID:#{doid}/")
end
Expand Down

0 comments on commit 1e5e042

Please sign in to comment.