Skip to content

Commit 4d05e5e

Browse files
aagrawalrtslAyushi Agrawal
andauthored
initial commit for replacing Materialized reporting_patient_states wi… (#5703)
Replacing Materialized public.reporting_patient_states with a normal view **Story card:** [sc-16562](https://app.shortcut.com/simpledotorg/story/16562/replace-old-mat-view-to-the-new-partitioned-table-reporting-patient-states) ## Because We want to discard materialized reporting_patient_states ## This addresses We create a normal view reporting_patient_states under public schema. This will ensure that the existing dashboard and metabase reports don't break. In order to drop mat view reporting_patient_states, we need to first drop the views which is dependent on reporting_patient_states, and recreate them without data. We will have to refresh those mat views after this is deployed. ## Test instructions Clear the cache and restart the server. The dashboards should load fine. Suite tests. --------- Co-authored-by: Ayushi Agrawal <[email protected]>
1 parent 71c56f4 commit 4d05e5e

29 files changed

+1674
-267
lines changed

app/models/reports/patient_state.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class PatientState < Reports::View
1010
}, _prefix: :htn_care_state
1111

1212
def self.materialized?
13-
true
13+
false
1414
end
1515

1616
def self.partitioned?

app/services/refresh_reporting_views.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def benchmark_and_statsd(operation, partitioned_refresh = false)
125125
name = "reporting_views_refresh_duration_seconds"
126126
result = nil
127127
options_hash = {view: view}
128-
options_hash[:partitioned_refresh] = true if partitioned_refresh
128+
options_hash[:partitioned_refresh] = partitioned_refresh ? true : false
129129
Metrics.benchmark_and_gauge(name, options_hash) do
130130
result = yield
131131
end

db/migrate/20250925094123_discard_mat_view_reporting_patient_states.rb

Lines changed: 1563 additions & 0 deletions
Large diffs are not rendered by default.

db/structure.sql

Lines changed: 5 additions & 242 deletions
Original file line numberDiff line numberDiff line change
@@ -3594,143 +3594,13 @@ CREATE MATERIALIZED VIEW public.reporting_prescriptions AS
35943594
-- Name: reporting_patient_states; Type: MATERIALIZED VIEW; Schema: public; Owner: -
35953595
--
35963596

3597-
CREATE MATERIALIZED VIEW public.reporting_patient_states AS
3598-
SELECT DISTINCT ON (p.id, cal.month_date) p.id AS patient_id,
3599-
timezone('UTC'::text, timezone('UTC'::text, p.recorded_at)) AS recorded_at,
3600-
p.status,
3601-
p.gender,
3602-
p.age,
3603-
timezone('UTC'::text, timezone('UTC'::text, p.age_updated_at)) AS age_updated_at,
3604-
p.date_of_birth,
3605-
date_part('year'::text, COALESCE(age((p.date_of_birth)::timestamp with time zone), (make_interval(years => p.age) + age(p.age_updated_at)))) AS current_age,
3606-
cal.month_date,
3607-
cal.month,
3608-
cal.quarter,
3609-
cal.year,
3610-
cal.month_string,
3611-
cal.quarter_string,
3612-
mh.hypertension,
3613-
mh.prior_heart_attack,
3614-
mh.prior_stroke,
3615-
mh.chronic_kidney_disease,
3616-
mh.receiving_treatment_for_hypertension,
3617-
mh.diabetes,
3618-
p.assigned_facility_id,
3619-
assigned_facility.facility_size AS assigned_facility_size,
3620-
assigned_facility.facility_type AS assigned_facility_type,
3621-
assigned_facility.facility_region_slug AS assigned_facility_slug,
3622-
assigned_facility.facility_region_id AS assigned_facility_region_id,
3623-
assigned_facility.block_slug AS assigned_block_slug,
3624-
assigned_facility.block_region_id AS assigned_block_region_id,
3625-
assigned_facility.district_slug AS assigned_district_slug,
3626-
assigned_facility.district_region_id AS assigned_district_region_id,
3627-
assigned_facility.state_slug AS assigned_state_slug,
3628-
assigned_facility.state_region_id AS assigned_state_region_id,
3629-
assigned_facility.organization_slug AS assigned_organization_slug,
3630-
assigned_facility.organization_region_id AS assigned_organization_region_id,
3631-
p.registration_facility_id,
3632-
registration_facility.facility_size AS registration_facility_size,
3633-
registration_facility.facility_type AS registration_facility_type,
3634-
registration_facility.facility_region_slug AS registration_facility_slug,
3635-
registration_facility.facility_region_id AS registration_facility_region_id,
3636-
registration_facility.block_slug AS registration_block_slug,
3637-
registration_facility.block_region_id AS registration_block_region_id,
3638-
registration_facility.district_slug AS registration_district_slug,
3639-
registration_facility.district_region_id AS registration_district_region_id,
3640-
registration_facility.state_slug AS registration_state_slug,
3641-
registration_facility.state_region_id AS registration_state_region_id,
3642-
registration_facility.organization_slug AS registration_organization_slug,
3643-
registration_facility.organization_region_id AS registration_organization_region_id,
3644-
bps.blood_pressure_id,
3645-
bps.blood_pressure_facility_id AS bp_facility_id,
3646-
bps.blood_pressure_recorded_at AS bp_recorded_at,
3647-
bps.systolic,
3648-
bps.diastolic,
3649-
bss.blood_sugar_id,
3650-
bss.blood_sugar_facility_id AS bs_facility_id,
3651-
bss.blood_sugar_recorded_at AS bs_recorded_at,
3652-
bss.blood_sugar_type,
3653-
bss.blood_sugar_value,
3654-
bss.blood_sugar_risk_state,
3655-
visits.encounter_id,
3656-
visits.encounter_recorded_at,
3657-
visits.prescription_drug_id,
3658-
visits.prescription_drug_recorded_at,
3659-
visits.appointment_id,
3660-
visits.appointment_recorded_at,
3661-
visits.visited_facility_ids,
3662-
(((cal.year - date_part('year'::text, timezone(( SELECT current_setting('TIMEZONE'::text) AS current_setting), timezone('UTC'::text, p.recorded_at)))) * (12)::double precision) + (cal.month - date_part('month'::text, timezone(( SELECT current_setting('TIMEZONE'::text) AS current_setting), timezone('UTC'::text, p.recorded_at))))) AS months_since_registration,
3663-
(((cal.year - date_part('year'::text, timezone(( SELECT current_setting('TIMEZONE'::text) AS current_setting), timezone('UTC'::text, p.recorded_at)))) * (4)::double precision) + (cal.quarter - date_part('quarter'::text, timezone(( SELECT current_setting('TIMEZONE'::text) AS current_setting), timezone('UTC'::text, p.recorded_at))))) AS quarters_since_registration,
3664-
visits.months_since_visit,
3665-
visits.quarters_since_visit,
3666-
bps.months_since_bp,
3667-
bps.quarters_since_bp,
3668-
bss.months_since_bs,
3669-
bss.quarters_since_bs,
3670-
CASE
3671-
WHEN ((bps.systolic IS NULL) OR (bps.diastolic IS NULL)) THEN 'unknown'::text
3672-
WHEN ((bps.systolic < 140) AND (bps.diastolic < 90)) THEN 'controlled'::text
3673-
ELSE 'uncontrolled'::text
3674-
END AS last_bp_state,
3675-
CASE
3676-
WHEN ((p.status)::text = 'dead'::text) THEN 'dead'::text
3677-
WHEN (((((cal.year - date_part('year'::text, timezone(( SELECT current_setting('TIMEZONE'::text) AS current_setting), timezone('UTC'::text, p.recorded_at)))) * (12)::double precision) + (cal.month - date_part('month'::text, timezone(( SELECT current_setting('TIMEZONE'::text) AS current_setting), timezone('UTC'::text, p.recorded_at))))) < (12)::double precision) OR (visits.months_since_visit < (12)::double precision)) THEN 'under_care'::text
3678-
ELSE 'lost_to_follow_up'::text
3679-
END AS htn_care_state,
3680-
CASE
3681-
WHEN ((visits.months_since_visit >= (3)::double precision) OR (visits.months_since_visit IS NULL)) THEN 'missed_visit'::text
3682-
WHEN ((bps.months_since_bp >= (3)::double precision) OR (bps.months_since_bp IS NULL)) THEN 'visited_no_bp'::text
3683-
WHEN ((bps.systolic < 140) AND (bps.diastolic < 90)) THEN 'controlled'::text
3684-
ELSE 'uncontrolled'::text
3685-
END AS htn_treatment_outcome_in_last_3_months,
3686-
CASE
3687-
WHEN ((visits.months_since_visit >= (2)::double precision) OR (visits.months_since_visit IS NULL)) THEN 'missed_visit'::text
3688-
WHEN ((bps.months_since_bp >= (2)::double precision) OR (bps.months_since_bp IS NULL)) THEN 'visited_no_bp'::text
3689-
WHEN ((bps.systolic < 140) AND (bps.diastolic < 90)) THEN 'controlled'::text
3690-
ELSE 'uncontrolled'::text
3691-
END AS htn_treatment_outcome_in_last_2_months,
3692-
CASE
3693-
WHEN ((visits.quarters_since_visit >= (1)::double precision) OR (visits.quarters_since_visit IS NULL)) THEN 'missed_visit'::text
3694-
WHEN ((bps.quarters_since_bp >= (1)::double precision) OR (bps.quarters_since_bp IS NULL)) THEN 'visited_no_bp'::text
3695-
WHEN ((bps.systolic < 140) AND (bps.diastolic < 90)) THEN 'controlled'::text
3696-
ELSE 'uncontrolled'::text
3697-
END AS htn_treatment_outcome_in_quarter,
3698-
CASE
3699-
WHEN ((visits.months_since_visit >= (3)::double precision) OR (visits.months_since_visit IS NULL)) THEN 'missed_visit'::text
3700-
WHEN ((bss.months_since_bs >= (3)::double precision) OR (bss.months_since_bs IS NULL)) THEN 'visited_no_bs'::text
3701-
ELSE bss.blood_sugar_risk_state
3702-
END AS diabetes_treatment_outcome_in_last_3_months,
3703-
CASE
3704-
WHEN ((visits.months_since_visit >= (2)::double precision) OR (visits.months_since_visit IS NULL)) THEN 'missed_visit'::text
3705-
WHEN ((bss.months_since_bs >= (2)::double precision) OR (bss.months_since_bs IS NULL)) THEN 'visited_no_bs'::text
3706-
ELSE bss.blood_sugar_risk_state
3707-
END AS diabetes_treatment_outcome_in_last_2_months,
3708-
CASE
3709-
WHEN ((visits.quarters_since_visit >= (1)::double precision) OR (visits.quarters_since_visit IS NULL)) THEN 'missed_visit'::text
3710-
WHEN ((bss.quarters_since_bs >= (1)::double precision) OR (bss.quarters_since_bs IS NULL)) THEN 'visited_no_bs'::text
3711-
ELSE bss.blood_sugar_risk_state
3712-
END AS diabetes_treatment_outcome_in_quarter,
3713-
((current_meds.amlodipine > past_meds.amlodipine) OR (current_meds.telmisartan > past_meds.telmisartan) OR (current_meds.losartan > past_meds.losartan) OR (current_meds.atenolol > past_meds.atenolol) OR (current_meds.enalapril > past_meds.enalapril) OR (current_meds.chlorthalidone > past_meds.chlorthalidone) OR (current_meds.hydrochlorothiazide > past_meds.hydrochlorothiazide)) AS titrated
3714-
FROM (((((((((public.patients p
3715-
LEFT JOIN public.reporting_months cal ON ((to_char(timezone(( SELECT current_setting('TIMEZONE'::text) AS current_setting), timezone('UTC'::text, p.recorded_at)), 'YYYY-MM'::text) <= to_char((cal.month_date)::timestamp with time zone, 'YYYY-MM'::text))))
3716-
LEFT JOIN public.reporting_patient_blood_pressures bps ON (((p.id = bps.patient_id) AND (cal.month = bps.month) AND (cal.year = bps.year))))
3717-
LEFT JOIN public.reporting_patient_blood_sugars bss ON (((p.id = bss.patient_id) AND (cal.month = bss.month) AND (cal.year = bss.year))))
3718-
LEFT JOIN public.reporting_patient_visits visits ON (((p.id = visits.patient_id) AND (cal.month = visits.month) AND (cal.year = visits.year))))
3719-
LEFT JOIN public.medical_histories mh ON (((p.id = mh.patient_id) AND (mh.deleted_at IS NULL))))
3720-
LEFT JOIN public.reporting_prescriptions current_meds ON (((current_meds.patient_id = p.id) AND (cal.month_date = current_meds.month_date))))
3721-
LEFT JOIN public.reporting_prescriptions past_meds ON (((past_meds.patient_id = p.id) AND (cal.month_date = (past_meds.month_date + '1 mon'::interval)))))
3722-
JOIN public.reporting_facilities registration_facility ON ((registration_facility.facility_id = p.registration_facility_id)))
3723-
JOIN public.reporting_facilities assigned_facility ON ((assigned_facility.facility_id = p.assigned_facility_id)))
3724-
WHERE (p.deleted_at IS NULL)
3725-
ORDER BY p.id, cal.month_date
3726-
WITH NO DATA;
3727-
3597+
CREATE VIEW public.reporting_patient_states AS SELECT * FROM simple_reporting.reporting_patient_states;
37283598

37293599
--
3730-
-- Name: MATERIALIZED VIEW reporting_patient_states; Type: COMMENT; Schema: public; Owner: -
3600+
-- Name: VIEW reporting_patient_states; Type: COMMENT; Schema: public; Owner: -
37313601
--
37323602

3733-
COMMENT ON MATERIALIZED VIEW public.reporting_patient_states IS 'Monthly summary of a patient''s information and health indicators. This table has one row per patient, per month, from the month of the patient''s registration.';
3603+
COMMENT ON VIEW public.reporting_patient_states IS 'Monthly summary of a patient''s information and health indicators. This table has one row per patient, per month, from the month of the patient''s registration.';
37343604

37353605

37363606
--
@@ -7843,28 +7713,6 @@ CREATE UNIQUE INDEX index_reporting_facility_appointment_scheduled_days ON publi
78437713

78447714
CREATE INDEX index_reporting_patient_follow_ups_on_facility_id ON public.reporting_patient_follow_ups USING btree (facility_id);
78457715

7846-
7847-
--
7848-
-- Name: index_reporting_patient_states_on_age; Type: INDEX; Schema: public; Owner: -
7849-
--
7850-
7851-
CREATE INDEX index_reporting_patient_states_on_age ON public.reporting_patient_states USING btree (age);
7852-
7853-
7854-
--
7855-
-- Name: index_reporting_patient_states_on_gender; Type: INDEX; Schema: public; Owner: -
7856-
--
7857-
7858-
CREATE INDEX index_reporting_patient_states_on_gender ON public.reporting_patient_states USING btree (gender);
7859-
7860-
7861-
--
7862-
-- Name: index_reporting_patient_states_on_gender_and_age; Type: INDEX; Schema: public; Owner: -
7863-
--
7864-
7865-
CREATE INDEX index_reporting_patient_states_on_gender_and_age ON public.reporting_patient_states USING btree (gender, age);
7866-
7867-
78687716
--
78697717
-- Name: index_teleconsultations_on_facility_id; Type: INDEX; Schema: public; Owner: -
78707718
--
@@ -8032,77 +7880,6 @@ CREATE UNIQUE INDEX patient_blood_pressures_patient_id_month_date ON public.repo
80327880

80337881
CREATE UNIQUE INDEX patient_blood_sugars_month_date_patient_id ON public.reporting_patient_blood_sugars USING btree (month_date, patient_id);
80347882

8035-
8036-
--
8037-
-- Name: patient_states_assigned_block; Type: INDEX; Schema: public; Owner: -
8038-
--
8039-
8040-
CREATE INDEX patient_states_assigned_block ON public.reporting_patient_states USING btree (assigned_block_region_id);
8041-
8042-
8043-
--
8044-
-- Name: patient_states_assigned_district; Type: INDEX; Schema: public; Owner: -
8045-
--
8046-
8047-
CREATE INDEX patient_states_assigned_district ON public.reporting_patient_states USING btree (assigned_district_region_id);
8048-
8049-
8050-
--
8051-
-- Name: patient_states_assigned_facility; Type: INDEX; Schema: public; Owner: -
8052-
--
8053-
8054-
CREATE INDEX patient_states_assigned_facility ON public.reporting_patient_states USING btree (assigned_facility_region_id);
8055-
8056-
8057-
--
8058-
-- Name: patient_states_assigned_state; Type: INDEX; Schema: public; Owner: -
8059-
--
8060-
8061-
CREATE INDEX patient_states_assigned_state ON public.reporting_patient_states USING btree (assigned_state_region_id);
8062-
8063-
8064-
--
8065-
-- Name: patient_states_care_state; Type: INDEX; Schema: public; Owner: -
8066-
--
8067-
8068-
CREATE INDEX patient_states_care_state ON public.reporting_patient_states USING btree (hypertension, htn_care_state, htn_treatment_outcome_in_last_3_months);
8069-
8070-
8071-
--
8072-
-- Name: patient_states_month_date_assigned_facility; Type: INDEX; Schema: public; Owner: -
8073-
--
8074-
8075-
CREATE INDEX patient_states_month_date_assigned_facility ON public.reporting_patient_states USING btree (month_date, assigned_facility_id);
8076-
8077-
8078-
--
8079-
-- Name: patient_states_month_date_assigned_facility_region; Type: INDEX; Schema: public; Owner: -
8080-
--
8081-
8082-
CREATE INDEX patient_states_month_date_assigned_facility_region ON public.reporting_patient_states USING btree (month_date, assigned_facility_region_id);
8083-
8084-
8085-
--
8086-
-- Name: patient_states_month_date_patient_id; Type: INDEX; Schema: public; Owner: -
8087-
--
8088-
8089-
CREATE UNIQUE INDEX patient_states_month_date_patient_id ON public.reporting_patient_states USING btree (month_date, patient_id);
8090-
8091-
8092-
--
8093-
-- Name: patient_states_month_date_registration_facility; Type: INDEX; Schema: public; Owner: -
8094-
--
8095-
8096-
CREATE INDEX patient_states_month_date_registration_facility ON public.reporting_patient_states USING btree (month_date, registration_facility_id);
8097-
8098-
8099-
--
8100-
-- Name: patient_states_month_date_registration_facility_region; Type: INDEX; Schema: public; Owner: -
8101-
--
8102-
8103-
CREATE INDEX patient_states_month_date_registration_facility_region ON public.reporting_patient_states USING btree (month_date, registration_facility_region_id);
8104-
8105-
81067883
--
81077884
-- Name: patient_visits_patient_id_month_date; Type: INDEX; Schema: public; Owner: -
81087885
--
@@ -8123,21 +7900,6 @@ CREATE UNIQUE INDEX raw_to_clean_medicines_unique_name_and_dosage ON public.raw_
81237900

81247901
CREATE UNIQUE INDEX reporting_patient_follow_ups_unique_index ON public.reporting_patient_follow_ups USING btree (patient_id, user_id, facility_id, month_date);
81257902

8126-
8127-
--
8128-
-- Name: reporting_patient_states_bp_facility_id; Type: INDEX; Schema: public; Owner: -
8129-
--
8130-
8131-
CREATE INDEX reporting_patient_states_bp_facility_id ON public.reporting_patient_states USING btree (bp_facility_id);
8132-
8133-
8134-
--
8135-
-- Name: reporting_patient_states_titrated; Type: INDEX; Schema: public; Owner: -
8136-
--
8137-
8138-
CREATE INDEX reporting_patient_states_titrated ON public.reporting_patient_states USING btree (titrated);
8139-
8140-
81417903
--
81427904
-- Name: reporting_prescriptions_patient_month_date; Type: INDEX; Schema: public; Owner: -
81437905
--
@@ -8794,5 +8556,6 @@ INSERT INTO "schema_migrations" (version) VALUES
87948556
('20250828111954'),
87958557
('20250923223358'),
87968558
('20250924101441'),
8797-
('20250924102156');
8559+
('20250924102156'),
8560+
('20250925094123');
87988561

spec/controllers/my_facilities_controller_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
controlled.each { |patient| create(:bp_with_encounter, :under_control, patient: patient, facility: facility, user: supervisor) }
3535
end
3636
Timecop.freeze("January 15th 2021") do
37+
allow(Reports::PatientState).to receive(:get_refresh_months).and_return(ReportingHelpers.get_refresh_months_between_dates(Date.new(2020, 11, 1), Date.today))
3738
refresh_views
3839
get :bp_controlled, params: {}
3940
end
@@ -85,6 +86,7 @@
8586
end
8687

8788
Timecop.freeze("January 15th 2021") do
89+
allow(Reports::PatientState).to receive(:get_refresh_months).and_return(ReportingHelpers.get_refresh_months_between_dates(Date.new(2020, 11, 1), Date.today))
8890
refresh_views
8991
get :bp_not_controlled, params: {}
9092
end
@@ -151,6 +153,7 @@
151153
patients.each { |p| create(:bp_with_encounter, :under_control, facility: facility, patient: p) }
152154
end
153155
Timecop.freeze("January 15th 2021") do
156+
allow(Reports::PatientState).to receive(:get_refresh_months).and_return(ReportingHelpers.get_refresh_months_between_dates(Date.new(2020, 7, 1), Date.today))
154157
refresh_views
155158
get :csv_maker, params: {type: "controlled_patients"}
156159
end

spec/controllers/reports/regions_controller_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@
252252
patient = create(:patient, registration_facility: @facility, recorded_at: jan_2020.advance(months: -4))
253253
create(:bp_with_encounter, :under_control, recorded_at: jan_2020.advance(months: -1), patient: patient, facility: @facility)
254254
create(:bp_with_encounter, :hypertensive, recorded_at: jan_2020, facility: @facility)
255+
allow(Reports::PatientState).to receive(:get_refresh_months).and_return(ReportingHelpers.get_refresh_months_between_dates(jan_2020.advance(months: -4).to_date, Date.new(2020, 6, 1)))
255256
refresh_views
256257

257258
Timecop.freeze("June 1 2020") do
@@ -269,6 +270,7 @@
269270
patient = create(:patient, registration_facility: @facility, recorded_at: jan_2020.advance(months: -4))
270271
create(:bp_with_encounter, :under_control, recorded_at: jan_2020.advance(months: -1), patient: patient, facility: @facility)
271272
create(:bp_with_encounter, :hypertensive, recorded_at: jan_2020, facility: @facility)
273+
allow(Reports::PatientState).to receive(:get_refresh_months).and_return(ReportingHelpers.get_refresh_months_between_dates(jan_2020.advance(months: -4).to_date, Date.new(2020, 6, 1)))
272274
refresh_views
273275

274276
Timecop.freeze("June 1 2020") do
@@ -288,7 +290,7 @@
288290
patient_1 = create(:patient, registration_facility: @facility, recorded_at: "September 01 2019 00:00:00 UTC", registration_user: cvho)
289291
create(:bp_with_encounter, :under_control, recorded_at: "December 10th 2019", patient: patient_1, facility: @facility, user: cvho)
290292
create(:bp_with_encounter, :hypertensive, recorded_at: jan_2020, facility: @facility, user: cvho)
291-
293+
allow(Reports::PatientState).to receive(:get_refresh_months).and_return(ReportingHelpers.get_refresh_months_between_dates(Date.new(2019, 6, 1), Date.new(2020, 6, 1)))
292294
refresh_views
293295

294296
block = @facility.region.block_region
@@ -492,6 +494,7 @@
492494
patient = create(:patient, registration_facility: @facility, registration_user: cvho, recorded_at: jan_2020.advance(months: -1))
493495
create(:bp_with_encounter, :under_control, recorded_at: jan_2020.advance(months: -1), patient: patient, facility: @facility)
494496
create(:bp_with_encounter, :hypertensive, recorded_at: jan_2020, facility: @facility)
497+
allow(Reports::PatientState).to receive(:get_refresh_months).and_return(ReportingHelpers.get_refresh_months_between_dates(jan_2020.advance(months: -1).to_date, Date.new(2020, 6, 1)))
495498
refresh_views
496499

497500
Timecop.freeze("June 1 2020") do
@@ -507,6 +510,7 @@
507510
it "can retrieve quarterly cohort data" do
508511
patient = create(:patient, registration_facility: @facility, registration_user: cvho, recorded_at: jan_2020.advance(months: -2))
509512
create(:bp_with_encounter, :under_control, recorded_at: jan_2020 + 1.day, patient: patient, facility: @facility)
513+
allow(Reports::PatientState).to receive(:get_refresh_months).and_return(ReportingHelpers.get_refresh_months_between_dates(jan_2020.advance(months: -2).to_date, Date.new(2020, 6, 1)))
510514
refresh_views
511515

512516
Timecop.freeze("June 1 2020") do

spec/exporters/monthly_district_data/diabetes_data_exporter_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
create(:appointment, facility: @facility1, scheduled_date: Date.today, device_created_at: 63.days.ago, patient: create(:patient, :diabetes, recorded_at: 1.year.ago))
3737

3838
@months = @period.downto(5).reverse.map(&:to_s)
39-
39+
allow(Reports::PatientState).to receive(:get_refresh_months).and_return(ReportingHelpers.get_refresh_months_between_dates(2.years.ago.to_date, Date.today))
4040
RefreshReportingViews.refresh_v2
4141
end
4242

0 commit comments

Comments
 (0)