diff --git a/app/services/one_off/opensrp/blood_sugar_exporter.rb b/app/services/one_off/opensrp/blood_sugar_exporter.rb index e862a9237f..ab34a58090 100644 --- a/app/services/one_off/opensrp/blood_sugar_exporter.rb +++ b/app/services/one_off/opensrp/blood_sugar_exporter.rb @@ -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 @@ -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 diff --git a/lib/tasks/opensrp.rake b/lib/tasks/opensrp.rake index e3f074ea81..659e4c6491 100644 --- a/lib/tasks/opensrp.rake +++ b/lib/tasks/opensrp.rake @@ -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|