Skip to content

Commit

Permalink
opensrp export: fix invalid facility references (#5476)
Browse files Browse the repository at this point in the history
Fixing some bugs that were seen only with production data.
  • Loading branch information
tfidfwastaken authored Sep 18, 2024
1 parent b2071b4 commit 0f02eb9
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/services/one_off/opensrp/appointment_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AppointmentExporter

def initialize(appointment, opensrp_mapping)
@appointment = appointment
@opensrp_ids = opensrp_mapping[@appointment.facility_id]
@opensrp_ids = opensrp_mapping[@appointment.patient.assigned_facility_id]
end

def export
Expand Down
2 changes: 1 addition & 1 deletion app/services/one_off/opensrp/blood_pressure_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class BloodPressureExporter

def initialize(blood_pressure, opensrp_mapping)
@blood_pressure = blood_pressure
@opensrp_ids = opensrp_mapping[@blood_pressure.facility_id]
@opensrp_ids = opensrp_mapping[@blood_pressure.patient.assigned_facility_id]
end

def encounter_id
Expand Down
3 changes: 1 addition & 2 deletions app/services/one_off/opensrp/blood_sugar_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ def initialize(blood_sugar_or_patient, opensrp_mapping)
if blood_sugar_or_patient.is_a?(Patient)
@patient = blood_sugar_or_patient
@blood_sugar = nil
@opensrp_ids = opensrp_mapping[@patient.assigned_facility_id]
else
@blood_sugar = blood_sugar_or_patient
@patient = @blood_sugar.patient
@opensrp_ids = opensrp_mapping[@blood_sugar.facility_id]
end
@opensrp_ids = opensrp_mapping[@patient.assigned_facility_id]
end

def export
Expand Down
2 changes: 1 addition & 1 deletion app/services/one_off/opensrp/encounter_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(encounters)
end

def generate
encounters.group_by { |encounter| encounter[:parent_id] }.map do |parent_id, child_encounters|
encounters.compact.group_by { |encounter| encounter[:parent_id] }.map do |parent_id, child_encounters|
opensrp_ids = child_encounters.first[:encounter_opensrp_ids]
first_child_encounter = child_encounters.first[:child_encounter]
patient_ref = first_child_encounter.subject
Expand Down
2 changes: 1 addition & 1 deletion app/services/one_off/opensrp/prescription_drug_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class PrescriptionDrugExporter

def initialize(prescription_drug, opensrp_mapping)
@prescription_drug = prescription_drug
@opensrp_ids = opensrp_mapping[@prescription_drug.facility_id]
@opensrp_ids = opensrp_mapping[@prescription_drug.patient.assigned_facility_id]
end

def export_dosage_flag
Expand Down
3 changes: 2 additions & 1 deletion lib/tasks/opensrp.rake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ namespace :opensrp do

resources = []
encounters = []
Patient.where(assigned_facility_id: OPENSRP_ORG_MAP.keys).each do |patient|
patients = Patient.where(assigned_facility_id: OPENSRP_ORG_MAP.keys)
patients.each do |patient|
patient_exporter = OneOff::Opensrp::PatientExporter.new(patient, OPENSRP_ORG_MAP)
resources << patient_exporter.export
resources << patient_exporter.export_registration_questionnaire_response
Expand Down

0 comments on commit 0f02eb9

Please sign in to comment.