avniproject / Adolescent-Sewa-Rural

0 stars 0 forks source link

[ADSR Support] Fix Severe Malnutrition visit scheduling #19

Closed nupoorkhandelwal closed 4 months ago

nupoorkhandelwal commented 5 months ago

Support ticket

https://avni.freshdesk.com/a/tickets/3491

Context

Though currently there are no cases where a wrong Malnutrition is scheduled for any adolescent. But the followups should be scheduled only after checking the latest value of BMI, currently followup and cancel visit scheduling needs to be updated accordingly.

Tech tasks

nupoorkhandelwal commented 5 months ago
set role adsr;
with aggregate_data as (select program_enrolment_id, "BMI (kg/m²)", encounter_date_time
                        from adsr.individual_adolescent_annual_visit_baseline
                        where encounter_date_time is not null

                        union all

                        select program_enrolment_id, "BMI (kg/m²)", encounter_date_time
                        from adsr.individual_adolescent_annual_visit_endline
                        where encounter_date_time is not null)
select data.program_enrolment_id, enc.earliest_visit_date_time, enc.created_date_time,cancel.cancel_date_time
from (select row_number() OVER (PARTITION BY program_enrolment_id ORDER BY encounter_date_time desc) visit_number,
             program_enrolment_id,
             "BMI (kg/m²)"
      from aggregate_data) data
 join adsr.individual_adolescent_severe_malnutrition_followup enc on enc.program_enrolment_id = data.program_enrolment_id
 left join adsr.individual_adolescent_severe_malnutrition_followup cancel on cancel.id = enc.id
where "BMI (kg/m²)" > 14.5 and visit_number = 1
  and cancel.cancel_date_time is  null and enc.encounter_date_time is null;
Gojo-Taqi commented 4 months ago

Found an error while uploading bundle. Have created a ticket and assigned it to the product team. https://avni.freshdesk.com/a/tickets/3521

Dinesh2019 commented 4 months ago
Dinesh2019 commented 4 months ago

No Fix needed works as expected