forked from BaobabHealthTrust/nlims_controller
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from HISMalawi/add/script-update-specimen-dist…
…rict update district for specimen with district null
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |