Skip to content

Commit

Permalink
Merge pull request #15 from HISMalawi/add/script-update-specimen-dist…
Browse files Browse the repository at this point in the history
…rict

update district for specimen with district null
  • Loading branch information
hopgausi authored Mar 12, 2024
2 parents b7fc4d8 + 4812191 commit 7c3c2a6
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions bin/fix_specimen_district.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

puts 'Initiating update...'
sending_facility_districts = Speciman.where("created_at > '2023-09-11' AND district IS NOT NULL")
.group('sending_facility, district').select('DISTINCT sending_facility, district')

sending_facility_districts.each do |send_facility_district|
puts "Updating district for ==> #{send_facility_district.sending_facility}"
Speciman.where("sending_facility = '#{send_facility_district.sending_facility}'
AND district IS NULL AND created_at > '2024-01-01'").update_all(district: send_facility_district.district)
end

missing_districts = [
{
sending_facility: 'Mwanza District Hospital',
district: 'Mwanza'
},
{
sending_facility: 'Lighthouse KCH',
district: 'Lilongwe'
}
]
missing_districts.each do |send_facility_district|
puts "Updating district for ==> #{send_facility_district[:sending_facility]}"
Speciman.where("sending_facility = '#{send_facility_district[:sending_facility]}'
AND district IS NULL AND created_at > '2024-01-01'").update_all(district: send_facility_district[:district])
end
puts 'Updating districts done'

0 comments on commit 7c3c2a6

Please sign in to comment.