Skip to content

Conversation

@aagrawalrtsl
Copy link
Contributor

This is the PR to merge the feature branch for screening to master

@aagrawalrtsl aagrawalrtsl added the do-not-merge don't merge this PR label Nov 19, 2025
## Because

**Story card:**
[sc-17007](https://app.shortcut.com/simpledotorg/story/17007/update-sync-api-for-suspected)
**PRD:** [Screening in
Simple](https://docs.google.com/document/d/1kWxOOAJEoH2yuj7eHJ9zn8ZHEdWbPrxH-RW8FYYBLnM/edit?tab=t.0)
Currently, Simple only tracks confirmed diagnoses for patients, which
limits the ability to record and follow suspected cases during community
and facility-based screening.
National NCD programs in India and Bangladesh require active
identification of undiagnosed adults (≥30 years) and tracking their
transition from suspected → diagnosed → under treatment.
By adding diagnosis date fields and `diagnosed_confirmed_at`, we can
accurately record when a patient is diagnosed with hypertension or
diabetes, maintain longitudinal data, and ensure proper syncing across
devices.

## This addresses
- Ensures every patient has a medical history record and adds support
for tracking diagnosis dates.
- Adds `htn_diagnosed_at` and `dm_diagnosed_at` in `medical_histories`
to store the date when a patient is confirmed with hypertension or
diabetes.
- Adds `diagnosed_confirmed_at` in `patients` to record the earliest
diagnosis date among hypertension and diabetes.
- Automatically updates `diagnosed_confirmed_at` when a new diagnosis
date is set.
- For existing records:
- Populate `diagnosed_confirmed_at` from `recorded_at` in the `patients`
table.
- Prevents changing an already recorded diagnosis date:
- Attempting to update `htn_diagnosed_at` returns: "Hypertension
diagnosis date has already been recorded and cannot be changed."
- Attempting to update `dm_diagnosed_at` returns: "Diabetes diagnosis
date has already been recorded and cannot be changed."


## Test instructions
1. Create a patient without any diagnosis:
- Confirm that `diagnosed_confirmed_at`, `htn_diagnosed_at`, and
`dm_diagnosed_at` are null in the database
2. Update the patient with a confirmed hypertension diagnosis:
- `htn_diagnosed_at` and `diagnosed_confirmed_at` should now be set to
the diagnosis date
   - `dm_diagnosed_at` should remain null
3. Later update the same patient with a confirmed diabetes diagnosis:
   - `dm_diagnosed_at` should be set
- `diagnosed_confirmed_at` should remain the earliest of the two
diagnosis dates
4. Attempt to change an already set `htn_diagnosed_at` or
`dm_diagnosed_at`:
   - Confirm that the respective validation error is returned
aagrawalrtsl and others added 20 commits November 20, 2025 17:27
…#5721)

**Story card:**
[sc-17153](https://app.shortcut.com/simpledotorg/story/17153/update-reporting-patient-states-to-not-include-screened-patients)

## Because

We are adding screened patients to the system and don't want them to
affect our reporting numbers.

## This addresses

We are using "diagnosed_confirmed_at" column in the patients column to
segregate between screened and regular patients.
A null value in this would mean that patient is still under screening,
hence exclude them.
A timestamp value in this marks the time when the first diagnosis of
patient was confirmed - resulting him being considered as a "regular"
patient. This timestamp denotes the time from when we would actually
start calculating it's actual "registration" to the program.

## Test instructions

Test suite

---------

Co-authored-by: Ayushi Agrawal <ayushiagrawal@RTSL-P172G93770.local>
#5727)

…er_months

**Story card:**
[sc-17154](https://app.shortcut.com/simpledotorg/story/17154/update-latest-blood-pressures-per-patient-per-months-to-not-include-screened-patients)

## Because

We want to exclude screening patients from
latest_blood_pressures_per_patient_per_months

## This addresses

Creating a new definition for
latest_blood_pressures_per_patient_per_months which only includes
patients where diagnosed_confirmed_at is not null.

Also, adding a new rake task which will refresh the view that have been
dropped and recreated as a result of dependencies.
This rake task will accept a comma separated list if views that needs to
be refreshed. If no argument is passed, it will do a refresh of the
default list

## Test instructions

Test suite

---------

Co-authored-by: Ayushi Agrawal <ayushiagrawal@RTSL-P172G93770.local>
…#5728)

**Story card:**
[sc-17155](https://app.shortcut.com/simpledotorg/story/17155/update-blood-pressures-per-facility-per-days-to-not-include-screened-patients)

## Because

We need to remove screened patients from our reporting views

## This addresses

New definition of blood_pressures_per_facility_per_days which excludes
patients where diagnosed_confirmed_at is null

## Test instructions

Test Suite

---------

Co-authored-by: Ayushi Agrawal <ayushiagrawal@RTSL-P172G93770.local>
)

**Story card:**
[sc-17157](https://app.shortcut.com/simpledotorg/story/17157/update-reporting-patient-blood-pressures-to-not-include-screened-patients)

## Because

We need to remove screened patients from our reporting views

## This addresses

New definition for reporting_patient_blood_pressures which excludes
patients where diagnosed_confirmed_at is null

## Test instructions

Suite test

---------

Co-authored-by: Ayushi Agrawal <ayushiagrawal@RTSL-P172G93770.local>
**Story card:**
[sc-17251](https://app.shortcut.com/simpledotorg/story/17251/backward-compatibility-risks-new-screening-existing-diagnosis-flow)

**PRD:**
https://docs.google.com/document/d/1kWxOOAJEoH2yuj7eHJ9zn8ZHEdWbPrxH-RW8FYYBLnM/edit?tab=t.0

## Because

We need to ensure backward compatibility for older screening records
where
`htn_diagnosed_at` and `dm_diagnosed_at` were not present.

## This addresses

- Adds logic to handle cases where both diagnosis dates are `nil`.
- If the patient is not suspected and has yes/no marked for HTN/DM,
we set `diagnosed_confirmed_at` to `recorded_at` (only if it was
previously nil).
- Ensures older patient records still receive a valid
`diagnosed_confirmed_at` value.

## Test instructions
For the test cases, please refer to the
**[PRD](https://docs.google.com/document/d/1kWxOOAJEoH2yuj7eHJ9zn8ZHEdWbPrxH-RW8FYYBLnM/edit?tab=t.0
)** section “Diagnosis date flow (HTN & DM)”.
**Story card:**
[sc-17159](https://app.shortcut.com/simpledotorg/story/17159/update-reporting-patient-blood-sugars-to-not-include-screened-patients)

## Because

We need to remove screened patients from our reporting views

## This addresses

New definition for reporting_patient_blood_sugars which excludes
patients where diagnosed_confirmed_at is null

## Test instructions

Suite test

Co-authored-by: Ayushi Agrawal <ayushiagrawal@RTSL-P172G93770.local>
#5733)

**Story card:**
[sc-17251](https://app.shortcut.com/simpledotorg/story/17251/backward-compatibility-risks-new-screening-existing-diagnosis-flow)

When an older APK creates a patient and submits hypertension: yes or
diabetes: yes without diagnosis dates, the backend now safely backfills
missing dates using the patient’s recorded_at.
Behavior
If hypertension: yes, then
```
htn_diagnosed_at = patient.recorded_at
diagnosed_confirmed_at = patient.recorded_at
```
If diabetes: yes, then
```
 dm_diagnosed_at = patient.recorded_at
 diagnosed_confirmed_at = patient.recorded_at
```
**Story card:**
[sc-17160](https://app.shortcut.com/simpledotorg/story/17160/update-reporting-overdue-calls-to-not-include-screened-patients)

## Because

We need to remove screened patients from our reporting views

## This addresses

New definition for reporting_overdue_calls which excludes patients where
diagnosed_confirmed_at is null

## Test instructions

Suite test

---------

Co-authored-by: Ayushi Agrawal <ayushiagrawal@RTSL-P172G93770.local>
**Story card:**
[sc-17161](https://app.shortcut.com/simpledotorg/story/17161/update-reporting-patient-visits-to-not-include-screened-patients)

## Because

We need to remove screened patients from our reporting views

## This addresses

New definition for reporting_patient_visits which excludes patients
where diagnosed_confirmed_at is null

## Test instructions

Suite test

Co-authored-by: Ayushi Agrawal <ayushiagrawal@RTSL-P172G93770.local>
**Story card:**
[sc-17162](https://app.shortcut.com/simpledotorg/story/17162/update-reporting-prescriptions-to-not-include-screened-patients)

## Because

We need to remove screened patients from our reporting views

## This addresses

New definition for reporting_prescriptions which excludes patients where
diagnosed_confirmed_at is null

## Test instructions

Suite test

Co-authored-by: Ayushi Agrawal <ayushiagrawal@RTSL-P172G93770.local>
**Story card:**
[sc-17163](https://app.shortcut.com/simpledotorg/story/17163/update-reporting-patient-follow-ups-to-not-include-screened-patients)

## Because

We need to remove screened patients from our reporting views

## This addresses

New definition for reporting_patient_follow_ups which excludes patients
where diagnosed_confirmed_at is null

## Test instructions

Suite test

---------

Co-authored-by: Ayushi Agrawal <ayushiagrawal@RTSL-P172G93770.local>
#5740)

**Story card:**
[sc-17164](https://app.shortcut.com/simpledotorg/story/17164/update-reporting-facility-appointment-scheduled-days-to-not-include-screened-patients)

## Because

We need to remove screened patients from our reporting views

## This addresses

New definition for reporting_facility_appointment_scheduled_days which
excludes patients where diagnosed_confirmed_at is null

## Test instructions

Suite test

Co-authored-by: Ayushi Agrawal <ayushiagrawal@RTSL-P172G93770.local>
**Story card:**
[sc-17428](https://app.shortcut.com/simpledotorg/story/17428/edge-case-set-diagnosis-dates-for-both-yes-and-no)

### Because

The app may send both htn_diagnosed_at and dm_diagnosed_at on
create/update if hypertension: yes/no and diabetes: yes/no, and the
backend must enforce consistent rules.

### **This addresses**

**Suspected enforcement** — if any diagnosis field is suspected in an
incoming record, the backend does not store the date for suspected
diagnosis store date for the another diagnosos ex: hypertension: yes ,
htn_diagnosed_at: new_date (stored), diabetes: suspected,
dm_diagnosed_at: nil.

**Suspected → confirmed** — allowed; backend accepts client-provided
dates when moving from suspected → yes/no, but only sets dates for
fields that do not already have confirmed dates on the server.

**Immutability** — once a confirmed *_diagnosed_at exists on the server,
it is not overwritten by later updates; incoming dates only populate
fields that are currently nil.

**Backfill rules** — backfill from patient.recorded_at runs only when
both diagnosed dates are nil and neither side is suspected.

**diagnosed_confirmed_at** — set only when no suspected diagnosis is
present; uses the earliest confirmed date and is never overwritten once
set.

### Tests updated

1. Specs updated to reflect the above contract.
3. Use test suite cases

**Run:**
`bundle exec rspec spec/models/medical_history_spec.rb
`

All tests should pass.
#5741)

…nd_registrations

**Story card:**
[sc-17166](https://app.shortcut.com/simpledotorg/story/17166/update-reporting-facility-daily-follow-ups-and-registrations-to-not-include-screened-patients)

## Because

We need to remove screened patients from our reporting views

## This addresses

New definition for reporting_facility_daily_follow_ups_and_registrations
which excludes patients where diagnosed_confirmed_at is null


## Test instructions

Suite test

---------

Co-authored-by: Ayushi Agrawal <ayushiagrawal@RTSL-P172G93770.local>
**Story card:**
[sc-17156](https://app.shortcut.com/simpledotorg/story/17156/update-materialized-patient-summaries-to-not-include-screened-patients)

## Because

We need to remove screened patients from our reporting views

## This addresses

New definition for materialized_patient_summaries which excludes
patients where diagnosed_confirmed_at is null

## Test instructions

Suite test

---------

Co-authored-by: Ayushi Agrawal <ayushiagrawal@RTSL-P172G93770.local>
@github-actions
Copy link
Contributor

This PR is stale. Please review/update it or close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge don't merge this PR stale-pr

Development

Successfully merging this pull request may close these issues.

3 participants