Skip to content

Commit

Permalink
opensrp export: fixes to blood sugar exports (#5477)
Browse files Browse the repository at this point in the history
We discovered some data inconsistency issues caused by no_diabetes
observations for the Sri Lanka UAT data ingestion. This change fixes
that.
  • Loading branch information
tfidfwastaken authored Sep 27, 2024
1 parent 0f02eb9 commit ff176a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
13 changes: 4 additions & 9 deletions app/services/one_off/opensrp/blood_sugar_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ module Opensrp
class BloodSugarExporter
attr_reader :blood_sugar, :patient

def initialize(blood_sugar_or_patient, opensrp_mapping)
if blood_sugar_or_patient.is_a?(Patient)
@patient = blood_sugar_or_patient
@blood_sugar = nil
else
@blood_sugar = blood_sugar_or_patient
@patient = @blood_sugar.patient
end
def initialize(blood_sugar, opensrp_mapping)
@blood_sugar = blood_sugar
@patient = @blood_sugar.patient
@opensrp_ids = opensrp_mapping[@patient.assigned_facility_id]
end

Expand Down Expand Up @@ -151,7 +146,7 @@ def parent_encounter_id
end

def encounter_id
Digest::UUID.uuid_v5(Digest::UUID::DNS_NAMESPACE, blood_sugar&.id || "no_diabetes_#{patient.id}")
Digest::UUID.uuid_v5(Digest::UUID::DNS_NAMESPACE, blood_sugar&.id)
end

def meta
Expand Down
14 changes: 6 additions & 8 deletions lib/tasks/opensrp.rake
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ namespace :opensrp do
encounters << bp_exporter.export_encounter
end

if patient.medical_history.diabetes_no?
bs_exporter = OneOff::Opensrp::BloodSugarExporter.new(patient, OPENSRP_ORG_MAP)
resources << bs_exporter.export_no_diabetes_observation
else
patient.blood_sugars.each do |bs|
bs_exporter = OneOff::Opensrp::BloodSugarExporter.new(bs, OPENSRP_ORG_MAP)
resources << bs_exporter.export
encounters << bs_exporter.export_encounter
patient.blood_sugars.each do |bs|
bs_exporter = OneOff::Opensrp::BloodSugarExporter.new(bs, OPENSRP_ORG_MAP)
if patient.medical_history.diabetes_no?
resources << bs_exporter.export_no_diabetes_observation
end
resources << bs_exporter.export
encounters << bs_exporter.export_encounter
end

patient.prescription_drugs.each do |drug|
Expand Down

0 comments on commit ff176a9

Please sign in to comment.