@@ -25,8 +25,9 @@ namespace :opensrp do
2525 facilities_to_export = config [ "facilities" ]
2626 time_boundaries = config [ "time_boundaries" ]
2727 using_time_boundaries = using_time_boundaries? config
28- report_start = DateTime . parse ( time_boundaries [ "report_start" ] ) if has_report_start? ( config )
29- report_end = DateTime . parse ( time_boundaries [ "report_end" ] ) if has_report_end? ( config )
28+ report_start = time_boundaries [ "report_start" ] if has_report_start? ( config )
29+ report_end = time_boundaries [ "report_end" ] if has_report_end? ( config )
30+ time_window = report_start ..report_end
3031
3132 logger . info "Time Boundaries: [#{ report_start } ..#{ report_end } ]"
3233
@@ -37,23 +38,27 @@ namespace :opensrp do
3738 logger . info "Preparing data for #{ patients . size } patients"
3839 patients . each do |patient |
3940 logger . debug "Preparing data for Patient[##{ patient . id } ]"
40- patient_exporter = OneOff ::Opensrp ::PatientExporter . new ( patient , facilities_to_export )
41- resources << patient_exporter . export
42- resources << patient_exporter . export_registration_questionnaire_response
43- encounters << patient_exporter . export_registration_encounter
41+ if time_window . cover? ( patient . recorded_at )
42+ patient_exporter = OneOff ::Opensrp ::PatientExporter . new ( patient , facilities_to_export )
43+ resources << patient_exporter . export
44+ resources << patient_exporter . export_registration_questionnaire_response
45+ encounters << patient_exporter . export_registration_encounter
46+ end
4447
4548 blood_pressures = patient . blood_pressures
46- blood_pressures = blood_pressures . where ( recorded_at : time_window ) . or ( updated_at : time_window ) if using_time_boundaries
49+ blood_pressures = blood_pressures . where ( recorded_at : time_window ) . or ( blood_pressures . where ( updated_at : time_window ) ) if using_time_boundaries
4750 logger . debug "Patient[##{ patient . id } ] has #{ blood_pressures . size } blood pressure readings."
4851 blood_pressures . each do |bp |
52+ bp_exporter = OneOff ::Opensrp ::BloodPressureExporter . new ( bp , facilities_to_export )
4953 resources << bp_exporter . export
5054 encounters << bp_exporter . export_encounter
5155 end
5256
5357 blood_sugars = patient . blood_sugars
54- blood_sugars = blood_sugars . where ( recorded_at : time_window ) . or ( updated_at : time_window ) if using_time_boundaries
58+ blood_sugars = blood_sugars . where ( recorded_at : time_window ) . or ( blood_sugars . where ( updated_at : time_window ) ) if using_time_boundaries
5559 logger . debug "Patient[##{ patient . id } ] has #{ blood_sugars . size } blood sugar readings."
56- blood_sugars . each do |bp |
60+ blood_sugars . each do |bs |
61+ bs_exporter = OneOff ::Opensrp ::BloodSugarExporter . new ( bs , facilities_to_export )
5762 if patient . medical_history . diabetes_no?
5863 resources << bs_exporter . export_no_diabetes_observation
5964 end
@@ -62,9 +67,10 @@ namespace :opensrp do
6267 end
6368
6469 prescription_drugs = patient . prescription_drugs
65- prescription_drugs = prescription_drugs . where ( created_at : time_window ) . or ( updated_at : time_window ) if using_time_boundaries
70+ prescription_drugs = prescription_drugs . where ( created_at : time_window ) . or ( prescription_drugs . where ( updated_at : time_window ) ) if using_time_boundaries
6671 logger . debug "Patient[##{ patient . id } ] has #{ prescription_drugs . size } drugs prescribed."
67- prescription_drugs . each do |bp |
72+ prescription_drugs . each do |drug |
73+ drug_exporter = OneOff ::Opensrp ::PrescriptionDrugExporter . new ( drug , facilities_to_export )
6874 resources << drug_exporter . export_dosage_flag
6975 encounters << drug_exporter . export_encounter
7076 end
@@ -75,9 +81,9 @@ namespace :opensrp do
7581 end
7682
7783 appointments = patient . appointments
78- appointments = appointments . where ( created_at : time_window ) . or ( updated_at : time_window ) if using_time_boundaries
84+ appointments = appointments . where ( created_at : time_window ) . or ( appointments . where ( updated_at : time_window ) ) if using_time_boundaries
7985 logger . debug "Patient[##{ patient . id } ] has #{ appointments . size } appointments."
80- appointments . each do |bp |
86+ appointments . each do |appointment |
8187 appointment_exporter = OneOff ::Opensrp ::AppointmentExporter . new ( appointment , facilities_to_export )
8288 resources << appointment_exporter . export
8389 if appointment . call_results . present?
@@ -109,11 +115,11 @@ namespace :opensrp do
109115 end
110116
111117 def has_report_start? ( config )
112- using_time_boundaries? ( config ) && time_boundaries . has_key? ( "report_start" )
118+ using_time_boundaries? ( config ) && config [ " time_boundaries" ] . has_key? ( "report_start" )
113119 end
114120
115121 def has_report_end? ( config )
116- using_time_boundaries? ( config ) && time_boundaries . has_key? ( "report_end" )
122+ using_time_boundaries? ( config ) && config [ " time_boundaries" ] . has_key? ( "report_end" )
117123 end
118124
119125 def create_audit_record ( facilities , patient )
0 commit comments