Skip to content

Simpleback 34#5798

Open
sshinde-rtsl wants to merge 18 commits intomasterfrom
SIMPLEBACK-34
Open

Simpleback 34#5798
sshinde-rtsl wants to merge 18 commits intomasterfrom
SIMPLEBACK-34

Conversation

@sshinde-rtsl
Copy link
Copy Markdown
Contributor

Story card: SIMPLEBACK-34

Because

Enter the reason for raising this PR...

This addresses

Enter the details of what all this covers...

Test instructions

Enter detailed instructions for how to test this PR...

- Add migration to create patient_scores table (with existence check)
- Add PatientScore model with Mergeable concern
- Add Api::V4::PatientScoresController with sync_to_user only
- Add PatientScoreTransformer for response transformation
- Add patient_score schema to Api::V4::Models
- Add GET route for /patient_scores/sync
- Add factory and controller spec for patient_scores (sync_to_user only)
…t line 9724, which terminated the INSERT INTO schema_migrations statement early. The migration

 versions on lines 9725-9729 were left as orphaned SQL, causing the syntax error.
# Conflicts:
#	app/controllers/admin/deduplicate_patients_controller.rb
#	app/views/admin/deduplicate_patients/show.html.erb
#	db/structure.sql
Remove hardcoded Time.current for created_at/updated_at and let the
base transformer use the actual device_created_at/device_updated_at
from the record. This fixes pagination issues in sync.
Remove duplicate entry for migration 20260212195326 and fix
chronological ordering of migration entries.
Add data migration to fix sync pagination issue where bulk-inserted
PatientScores share the same updated_at timestamp, causing the
process_token to never advance.

The migration:
1. Finds timestamps with >1000 records clustered
2. If device_updated_at is well-distributed, uses that
3. Otherwise spreads by id with millisecond offsets
- Replace timestamp-only pagination with (updated_at, id) keyset pagination
- Add process token tracking for last_id to ensure no records are skipped
- Prevents duplicate/missed records when multiple scores share same timestamp
…stamps stored in process_token are UTC strings (ending with 'Z'),but the inherited to_time method converts them to local timezone.This causes incorrect comparisons when the server timezone differs from UTC, resulting in 0 records returned on subsequent sync requests.

Override other_facilities_processed_since and current_facility_processed_since to explicitly parse timestamps in UTC using to_time(:utc).
…ity bucket

Replace keyset pagination with simple OFFSET-based next_page counter in the
process_token. Patient scores now sync only for the current facility's
prioritized patients; the other-facilities bucket is dropped. Updates specs
to match the new token contract.
Previously the token reset next_page to 1 as soon as a partial page was
returned, so calling the endpoint again with the returned token re-fetched
the same records instead of returning empty. Now next_page advances on
every non-empty response (full or partial) and resets to 1 only when the
query returns zero records, giving clients a clear 'sync complete' signal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant