Repository navigation
Conversation
When a profile is opened for a cohort (GET /{sourceKey}/person/{personId}
?cohort={id}), PersonService takes the first row of getCohorts.sql that
matches the cohort id as the index date. That query has no ORDER BY, and
cohort generation does not write a person's entries in date order, so for
a person with several entries in the cohort the profile can be indexed at
any of them: day 0, every record's start/end day, the observation period
offsets and the age at index all follow whichever row the database
returned first, and can change between databases or after the cohort is
regenerated.
Order the cohort rows by cohort definition and start date so the profile
is indexed at the person's first entry in the cohort.
Adds a test that builds a profile on the embedded Postgres database for a
person whose later cohort entry is stored before the earlier one.
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.
Fixes #2598
What was wrong
When a patient profile is requested for a cohort (
GET /{sourceKey}/person/{personId}?cohort={id}),PersonService.getPersonProfileuses the first row fromperson/sql/getCohorts.sqlwhose cohort id matches as the index date. That query has no ORDER BY, and cohort generation does not write a person's entries in date order. For a person with several entries in the cohort, the profile can therefore be indexed at any of them. Day 0, every record's start/end day, the observation period offsets and the age at index all follow whichever row the database returns first, and they can differ between databases or change after the cohort is regenerated.What changed
getCohorts.sqlnow orders the person's cohort rows bycohort_definition_id, cohort_start_date. The existingfindFirst()then picks the person's first entry in the requested cohort. Thecohortslist in the response comes back in a stable order too.PersonService.javaitself is unchanged.How it was tested
Added
PersonServiceCohortIndexTest, which builds a small CDM on the embedded Postgres test database. Person 1 has two entries in cohort 1 (2012-06-01 and 2018-03-01, with the 2018 row stored first) and one earlier entry in another cohort. The test checks that the profile for cohort 1 is indexed at 2012-06-01 (age at index, record start days, observation period offset).expected: 42 but was: 48(indexed at the 2018 entry).mvn test -DskipUnitTests=false -DskipITtests=true: Tests run: 170, Failures: 0, Errors: 0, Skipped: 5.