-
Notifications
You must be signed in to change notification settings - Fork 5
[JN-1619] Create new response and task for user if response was considered stale #1483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
private boolean shouldCreateNewLongitudinalTaskAndResponse(Integer createNewResponseAfterDays, Instant surveyResponseLastUpdatedAt) { | ||
if(createNewResponseAfterDays == null) { | ||
return false; | ||
} | ||
Instant cutoffTime = ZonedDateTime.now(ZoneOffset.UTC) | ||
.minusDays(createNewResponseAfterDays).toInstant(); | ||
return surveyResponseLastUpdatedAt.isBefore(cutoffTime); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about this ticket and another point of trickiness that I think we need to account for is - what happens if you want to edit a previous response?
Like, let's say you have 5 responses, and you realize the second one is incorrect - if you edit that second one, I'm assuming it should edit in place. But if you attempt to edit the latest one, it should make a new one.
I dunno if that's the right approach, but it feels right to me.
cc421cb
to
0ea37ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having trouble getting this to work.
See:
https://github.com/user-attachments/assets/ce1fa052-cb64-4cb2-9429-2bc957346463
It looks like for me the task id isn't updating, so it keeps creating new responses from the old task. Then, when I go back to the dashboard, it breaks the dashboard til I reload.
0ea37ce
to
b415646
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! works great! I'll add some tests for this alongside tests for the read-only history PR i'm starting on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, I like how this didn't require a lot of new code to accomplish. Some non-blocking code style nits
SurveyResponse priorResponse = dao.findOneWithAnswers(task.getSurveyResponseId()).orElse(null); | ||
SurveyResponse response; | ||
//if the survey is longitudinal and we're past the cutoff point for updating an existing response, we need to create a new response and task | ||
if (survey.getRecurrenceType() == RecurrenceType.LONGITUDINAL && priorResponse != null && shouldCreateNewLongitudinalTaskAndResponse(survey.getCreateNewResponseAfterDays(), priorResponse.getLastUpdatedAt())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be cleaner if you put more of this logic in the helper method, and also use a helper method for the task/response logic
if (shouldCreateNewTaskAndResponse(...)) {
taskAndResponse = createNewTaskAndResponse(...)
response = taskAndResponse.response
task = taskAndResponse.task
} else {
response = findOrCreateResponse(task, enrollee, enrollee.getParticipantUserId(), responseDto, portalId, operator);
}
Co-authored-by: Devon <[email protected]>
|
DESCRIPTION (include screenshots, and mobile screenshots for participant UX)
Adds the option for study staff to configure a longitudinal survey to create a new response and task if a response is edited after X days
Admin UX:

TO TEST: (simple manual steps for confirming core behavior -- used for pre-release checks)
Restart admin and participant API apps
Repopulate demo
Log in as [email protected]
Edit the response to the lifestyle survey
Since the survey is configured to create a new response if the last edit was >1 day ago, you should see a new task and response created with the new changes
Continue editing and confirm that the new edits are saved to the just-now-created task/response