-
Notifications
You must be signed in to change notification settings - Fork 5
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
[JN-1486] Referral source + skip pre-enroll + pre-fill pre-enroll #1280
Open
MatthewBemis
wants to merge
10
commits into
development
Choose a base branch
from
mb-jn-1486-referral-source
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d8a1472
schema
MatthewBemis 3d56994
intitial
MatthewBemis e9ca11a
skip pre-enroll
MatthewBemis eac468e
bubble down
MatthewBemis 2ff92c1
fix tests
MatthewBemis 0b3cfec
store on preenrollmentresponse
MatthewBemis d674f38
cleanup
MatthewBemis 61a581f
fix tests
MatthewBemis c7224b7
refactor
MatthewBemis 0f1346a
Merge branch 'development' into mb-jn-1486-referral-source
MatthewBemis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
9 changes: 9 additions & 0 deletions
9
core/src/main/resources/db/changelog/changesets/2024_12_02_pre_enroll_referral_source.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
databaseChangeLog: | ||
- changeSet: | ||
id: "pre_enroll_referral_source" | ||
author: mbemis | ||
changes: | ||
- addColumn: | ||
tableName: pre_enrollment_response | ||
columns: | ||
- column: { name: referral_source, type: text } |
This file contains 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
19 changes: 16 additions & 3 deletions
19
ui-admin/src/study/participants/survey/PreEnrollmentView.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
import React from 'react' | ||
import SurveyFullDataView from './SurveyFullDataView' | ||
import { Answer, PreregistrationResponse, Survey } from 'api/api' | ||
import { Answer, Survey } from 'api/api' | ||
import { StudyEnvContextT } from 'study/StudyEnvironmentRouter' | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
import { faCircleNodes } from '@fortawesome/free-solid-svg-icons' | ||
import { PreEnrollmentResponse, ReferralSource } from '@juniper/ui-core' | ||
|
||
/** show a preEnrollment response */ | ||
export default function PreEnrollmentView({ studyEnvContext, preEnrollResponse, preEnrollSurvey }: { | ||
studyEnvContext: StudyEnvContextT, preEnrollResponse?: PreregistrationResponse, preEnrollSurvey: Survey | ||
studyEnvContext: StudyEnvContextT, preEnrollResponse?: PreEnrollmentResponse, preEnrollSurvey: Survey | ||
}) { | ||
if (!preEnrollResponse) { | ||
return <span className="text-muted fst-italic"> no pre-enrollment data</span> | ||
} | ||
const answers: Answer[] = JSON.parse(preEnrollResponse.fullData) | ||
|
||
let parsedReferralSource | ||
if (preEnrollResponse.referralSource) { | ||
parsedReferralSource = JSON.parse(preEnrollResponse.referralSource) as ReferralSource | ||
} | ||
|
||
return <div> | ||
<h5>Pre-enrollment response</h5> | ||
{parsedReferralSource && <div className="border p-3 rounded-3 my-3"> | ||
<span><FontAwesomeIcon className={'fa-lg'} icon={faCircleNodes}/> This participant was referred by </span> | ||
<code>{parsedReferralSource.referringSite}</code> | ||
</div>} | ||
{preEnrollResponse && | ||
<SurveyFullDataView answers={answers} survey={preEnrollSurvey} studyEnvContext={studyEnvContext}/> | ||
<SurveyFullDataView answers={answers} survey={preEnrollSurvey} studyEnvContext={studyEnvContext}/> | ||
} | ||
</div> | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { useEffect, useState } from 'react' | ||
import { useSearchParams } from 'react-router-dom' | ||
import { Answer } from '@juniper/ui-core' | ||
|
||
export function useEnrollmentParams() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a great use of hooks |
||
const [searchParams] = useSearchParams() | ||
const [skipPreEnroll, setSkipPreEnroll] = useState(() => { | ||
return sessionStorage.getItem('skipPreEnroll') === 'true' | ||
}) | ||
const [referralSource, setReferralSource] = useState<string | null>(() => { | ||
return sessionStorage.getItem('referralSource') | ||
}) | ||
const [isProxyEnrollment, setIsProxyEnrollment] = useState(false) | ||
const [ppUserId, setPpUserId] = useState<string | null>(null) | ||
const [preFilledAnswers, setPreFilledAnswers] = useState<Answer[]>( | ||
parsePreFilledAnswers(sessionStorage.getItem('preFilledAnswers'))) | ||
|
||
function clearStoredEnrollmentParams() { | ||
sessionStorage.removeItem('skipPreEnroll') | ||
sessionStorage.removeItem('referralSource') | ||
sessionStorage.removeItem('preFilledAnswers') | ||
} | ||
|
||
function captureEnrollmentParams() { | ||
const skipPreEnrollParam = searchParams.get('skipPreEnroll') | ||
const referralSourceParam = searchParams.get('referralSource') | ||
const proxyEnrollmentParam = searchParams.get('isProxyEnrollment') | ||
const ppUserIdParam = searchParams.get('ppUserId') | ||
const preFilledAnswersParam = searchParams.get('preFilledAnswers') | ||
|
||
if (proxyEnrollmentParam === 'true') { | ||
setIsProxyEnrollment(true) | ||
} | ||
|
||
if (ppUserIdParam) { | ||
setPpUserId(ppUserIdParam) | ||
} | ||
|
||
// The following three params are stored in sessionStorage, so they persist across page reloads. | ||
// We want to do our best to avoid losing any information coming from referring sites | ||
|
||
if (skipPreEnrollParam === 'true') { | ||
sessionStorage.setItem('skipPreEnroll', 'true') | ||
setSkipPreEnroll(true) | ||
} | ||
|
||
if (referralSourceParam) { | ||
sessionStorage.setItem('referralSource', referralSourceParam) | ||
setReferralSource(referralSourceParam) | ||
} | ||
|
||
if (preFilledAnswersParam) { | ||
const answers = parsePreFilledAnswers(preFilledAnswersParam) | ||
sessionStorage.setItem('preFilledAnswers', JSON.stringify(answers)) | ||
setPreFilledAnswers(answers) | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
captureEnrollmentParams() | ||
}, [searchParams]) | ||
|
||
return { | ||
skipPreEnroll, referralSource, isProxyEnrollment, ppUserId, preFilledAnswers, | ||
captureEnrollmentParams, clearStoredEnrollmentParams | ||
} | ||
} | ||
|
||
const parsePreFilledAnswers = (preFilledAnswers: string | null): Answer[] => { | ||
if (!preFilledAnswers) { | ||
return [] | ||
} | ||
|
||
try { | ||
return JSON.parse(preFilledAnswers) as Answer[] | ||
} catch (error) { | ||
console.error('Failed to parse preFilledAnswers:', error) | ||
return [] | ||
} | ||
} |
Oops, something went wrong.
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.
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.
IDE didn't like this anymore, probably thanks to a dependency upgrade?