[BACK-4528] Skip patient summary updates older than the stored stats - #265
Open
toddkazakov wants to merge 1 commit into
Open
[BACK-4528] Skip patient summary updates older than the stored stats#265toddkazakov wants to merge 1 commit into
toddkazakov wants to merge 1 commit into
Conversation
ewollesen
approved these changes
Sep 3, 2026
| Expect(stored.BGM.Id).To(Equal(newest.BGM.Id)) | ||
| }) | ||
|
|
||
| It("keeps stats without a calculation date away from a report without one", func() { |
Contributor
There was a problem hiding this comment.
This test doesn't appear to match its name. It's not clear which was intended.
The test's name seems to indicate its testing the case where neither the existing summary or new summary have dates. The test itself however, tests a case where there's an existing date, but the new summary provides no date.
Maybe "keeps stats with a calculation date away from an update without one" is better?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
UpdatePatientSummary(POST /v1/patients/{patientId}/summary) unconditionally overwrites the storedcgmStats/bgmStats. Its reporters deliver at least once with no ordering guarantee, which allows a delayed report to arrive after one carrying a newer calculation and regress the stored stats until the user's next calculation.Today's CDC consumer (clinic-worker
patientsummary) is protected by Kafka partition ordering, but the upload-postprocess work processor in platform (which is taking over summary reporting — see platformupload-postprocess-work) is not: a processor reaped mid-report (>5-minute stall) can complete itsUpdatePatientSummaryafter another pod's retry already pushed newer stats. The EHR sync generates reports from this stored copy, so a regression is visible downstream.What
UpdateSummaryInAllClinicsnow applies each stats type only when the incomingdates.lastUpdatedDate(the calculation date) is not older than the stored one, using a$condpipeline update per type — each patient document and each stats type is compared independently, in the same singleUpdateMany.Rules (falling out of BSON comparison order, missing < null < date):
Equal dates still apply, so an at-least-once reporter re-delivering the same report remains idempotent.
updatedTimeis still always bumped and theErrSummaryNotFound(204) semantics for users who are not a patient of any clinic are unchanged, as is the nil-body unset path. The incoming stats are wrapped in$literalso they are stored verbatim rather than evaluated as aggregation expressions.Tests
New repository specs (against Mongo): stores when no stats exist; replaces on newer and on equal calculation dates; keeps stored stats against an older report and against an undated report; applies per type independently in one call (cgm replaced while bgm kept);
ErrSummaryNotFoundfor non-patients.go test ./patients/...green.