Skip to content

[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

Merged
merged 7 commits into from
Mar 28, 2025

Conversation

MatthewBemis
Copy link
Member

@MatthewBemis MatthewBemis commented Feb 14, 2025

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:
Screenshot 2025-02-14 at 2 16 35 PM

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

Comment on lines +139 to +152
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);
}

Copy link
Collaborator

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.

@MatthewBemis MatthewBemis changed the title [JN-1619] Create new response and task for user if last edit was N days ago [wip] [JN-1619] Create new response and task for user if response was considered stale Feb 26, 2025
@MatthewBemis MatthewBemis marked this pull request as ready for review February 27, 2025 14:12
Copy link
Collaborator

@connorlbark connorlbark left a 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.

Copy link
Collaborator

@connorlbark connorlbark left a 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

Copy link
Collaborator

@devonbush devonbush left a 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())) {
Copy link
Collaborator

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);
}

Copy link

@MatthewBemis MatthewBemis merged commit 523e478 into development Mar 28, 2025
17 checks passed
@MatthewBemis MatthewBemis deleted the mb-jn-1619-v2 branch March 28, 2025 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants