-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import API: Fix incorrect patient IDs in patient-associated resources (…
…#5320) The patient identifiers were created incorrectly in the dependent resources. We accidentally added a namespace prefix that's used to identify the patient business identifier, rather than the patient itself (which does not use any kind of prefix). While refactoring the `translate_patient_id` method, it became clear that this utility had no usage across multiple FHIR resource importers, so we removed it and made the mixin interface smaller. Our specs also need rectification, they used the wrong patient creation logic. Since the business identifiers were created correctly, but the resources associated with those patients were not, we add a data migration to rectify the situation. It turns out that we have been creating these dependent resources with the `patient_id` set to the `id` of the business identifier, instead of the `patient_id` of the business identifier. This migration swaps out the `patient_id` of the dependent resource.
- Loading branch information
1 parent
5a02985
commit 7c2b070
Showing
11 changed files
with
46 additions
and
35 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
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
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
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
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
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,32 @@ | ||
# frozen_string_literal: true | ||
|
||
class FixIncorrectFhirTranslations < ActiveRecord::Migration[6.1] | ||
FACILITY_ID = "f472c5db-188f-4563-9bc7-9f86a6ed6403" | ||
|
||
def up | ||
unless CountryConfig.current_country?("Bangladesh") && ENV["SIMPLE_SERVER_ENV"] == "production" | ||
return print "FixIncorrectFhirTranslations is only for production Bangladesh" | ||
end | ||
|
||
patients_from_facility = Patient.where(assigned_facility_id: FACILITY_ID) | ||
patient_business_identifiers = patients_from_facility.flat_map(&:business_identifiers) | ||
patient_business_identifiers.each do |identifier| | ||
resources_to_update = [ | ||
*MedicalHistory.where(patient_id: identifier.id), | ||
*BloodPressure.where(patient_id: identifier.id), | ||
*BloodSugar.where(patient_id: identifier.id), | ||
*PrescriptionDrug.where(patient_id: identifier.id) | ||
] | ||
|
||
resources_to_update.each do |resource| | ||
puts "updating patient ID of #{resource.class.name}:#{resource.id} from #{resource.patient_id} to #{identifier.patient_id}" | ||
resource.patient_id = identifier.patient_id | ||
resource.save! | ||
end | ||
end | ||
end | ||
|
||
def down | ||
puts "FixIncorrectFhirTranslations cannot be reversed." | ||
end | ||
end |
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 |
---|---|---|
@@ -1 +1 @@ | ||
DataMigrate::Data.define(version: 20231018062055) | ||
DataMigrate::Data.define(version: 20231106123819) |
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
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
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
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