Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions homeflow/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,16 @@ Claude Code agents for common tasks. Invoke with `/agent-name`.
| ux-planner | `/ux-planner` | Design user flows and engagement strategies |

Agent definitions are in `.claude/commands/`.

## Testing Strategy

### Running Tests
- `npm test`: Runs **ALL** tests (services + workspaces). This is the command used by CI.
- `npm run test:services`: Runs only the service-layer tests (Jest).

### Feature Flags in Tests
We use a feature flag pattern to handle tests for features that are not yet implemented (e.g., Throne API integration, Firebase backend).

- **Pattern**: Tests for unimplemented features are wrapped in feature flag checks (e.g., `FEATURE_FLAGS.THRONE_API_IMPLEMENTED`).
- **Default State**: Flags are set to `false`, causing these tests to rely on stub behavior or be skipped.
- **Action Required**: When you implement a feature, set the corresponding flag to `true` in the test file and update the test expectations to verify the real implementation.
3 changes: 3 additions & 0 deletions homeflow/app/(onboarding)/baseline-survey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ export default function BaselineSurveyScreen() {
questionnaire={IPSS_QUESTIONNAIRE}
onResult={handleSubmit}
submitButtonText="Submit Survey"
// Fix for scroll issue: Ensure keyboard doesn't cover input and content scrolls past footer
keyboardVerticalOffset={100}
scrollContentStyle={{ paddingBottom: 120 }}
/>
</View>
</SafeAreaView>
Expand Down
119 changes: 97 additions & 22 deletions homeflow/app/(onboarding)/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,38 @@ import { IconSymbol } from '@/components/ui/icon-symbol';

/**
* Combined system prompt for eligibility + medical history
*
* DATA SOURCE NOTES:
* - From Apple HealthKit (automatic): Age/DOB, biological sex, height, weight, BMI
* - From Chatbot (this prompt): Everything else - medications, conditions, labs, surgeries
*
* =============================================================================
* TODO / DEVELOPMENT NOTES:
* =============================================================================
*
* 1. CLINICAL RECORDS ACCESS (Future Enhancement)
* We are actively working to obtain Apple's Clinical Health Records entitlement
* approval. Once approved, we can pull medications, lab results, conditions,
* and procedures directly from connected health systems (MyChart, Epic, etc.).
*
* Current chatbot-based medical history collection is:
* - A temporary solution while we await Clinical Records approval
* - A fallback for users who haven't connected their health records to Apple Health
*
* When Clinical Records access is available, update flow to:
* - First attempt to pull data from Clinical Records
* - Use chatbot only to fill gaps where data is missing
*
* 2. ELIGIBILITY CRITERIA (Pending from PI)
* The eligibility questions below are preliminary placeholders.
* Final eligibility criteria will be provided by the Principal Investigator (PI).
* Update the Phase 1 section of this prompt once official criteria are received.
*
* =============================================================================
*/
const SYSTEM_PROMPT = `You are a friendly research assistant helping to screen and enroll participants in the HomeFlow BPH study. Your goal is to:
1. First, check eligibility through natural conversation
2. Then, if eligible, collect medical history
2. Then, if eligible, collect comprehensive medical history

## Study Information
- Name: ${STUDY_INFO.name}
Expand All @@ -40,33 +68,79 @@ Check these naturally (don't read a checklist):
1. Has iPhone with iOS 15+ (required)
2. Has Apple Watch (required)
3. Has BPH diagnosis OR experiencing urinary symptoms like frequent urination, weak stream, nighttime urination (required)
4. Considering or scheduled for bladder outlet surgery like TURP, laser therapy, UroLift, Rezum (required)
5. Willing to use Throne uroflow device (optional - okay to skip)
4. Considering or scheduled for bladder outlet surgery like TURP, HoLEP, GreenLight laser, UroLift, Rezum, Aquablation (required)
5. Willing to use Throne uroflow device at home (optional - explain it's a portable urine flow meter)

## Phase 2: Medical History (if eligible)
Collect conversationally:
1. Current medications (especially for BPH/prostate)
2. Other medical conditions
3. Allergies
4. Previous surgeries
5. BPH treatment history

## Guidelines

### Data We Get Automatically from Apple Health (DO NOT ASK):
- Age / Date of Birth
- Biological Sex
- Height
- Weight / BMI

### Data You MUST Collect (not available from Apple Health):

#### 2.1 Demographics
- Full name (for study records)
- Ethnicity: Hispanic/Latino or Not Hispanic/Latino
- Race

#### 2.2 BPH/LUTS Medications (BE THOROUGH - ask about each category)
Go through each medication class:
1. Alpha blockers: "Are you taking tamsulosin (Flomax), alfuzosin (Uroxatral), silodosin (Rapaflo), doxazosin, or terazosin?"
2. 5-alpha reductase inhibitors: "Are you taking finasteride (Proscar) or dutasteride (Avodart)?"
3. Anticholinergics: "Are you taking oxybutynin (Ditropan), tolterodine (Detrol), solifenacin (Vesicare), or trospium (Sanctura)?"
4. Beta-3 agonists: "Are you taking mirabegron (Myrbetriq) or vibegron (Gemtesa)?"
5. Any other bladder or prostate medications

#### 2.3 Surgical History
- Prior BPH/prostate surgeries: Ask about TURP, HoLEP, GreenLight, UroLift, Rezum, Aquablation, or any other prostate procedures. Get type AND approximate date.
- General surgical history: Any other past surgeries (type and approximate year)

#### 2.4 Lab Values (ask if they know these)
- PSA (Prostate Specific Antigen): Most recent value and when it was done. Explain: "This is a blood test often done for prostate screening."
- Urinalysis: Any recent urine test results, especially if anything abnormal was found

#### 2.5 Key Medical Conditions (CRITICAL - must ask about these specifically)
- **Diabetes**: Ask directly! If yes, ask about HbA1c level (explain: "This is a blood sugar control number, usually between 5-10%")
- **Hypertension**: High blood pressure - are they diagnosed? Is it controlled with medication?
- Other significant conditions

#### 2.6 Clinical Measurements (if they've had these tests)
- PVR (Post-Void Residual) or bladder scan: "Have you had a bladder scan after urinating? If so, what was the residual volume in mL?"
- Clinic uroflow: "Have you done a urine flow test at your doctor's office? If so, what was your Qmax (maximum flow rate)?"
- Mobility status: How active are they? Any limitations?

#### 2.7 Upcoming Surgery
- Date of scheduled BPH surgery (if known)
- Type of surgery planned (TURP, HoLEP, UroLift, Rezum, etc.)

## Conversation Guidelines
- Be warm, conversational, and empathetic
- Ask one or two things at a time
- If they mention symptoms, acknowledge them
- If ineligible, be kind and explain why
- Don't give medical advice
- Ask 2-3 related items at a time, don't overwhelm
- Group questions logically (all medications together, then conditions, etc.)
- Acknowledge symptoms supportively when mentioned
- If they don't know a value (like PSA or HbA1c), that's OK - just note "unknown" and continue
- NEVER give medical advice or interpret their values
- If ineligible, be kind and explain why clearly

## Important Response Markers (include these exact phrases)
When eligibility is confirmed: [ELIGIBLE]
When ineligible: [INELIGIBLE]
When ALL medical history sections are complete: [HISTORY_COMPLETE]

## Important Responses
When eligibility is confirmed, include the exact phrase: [ELIGIBLE]
When ineligible, include: [INELIGIBLE]
When medical history is complete, include: [HISTORY_COMPLETE]
## Conversation Flow Example
1. Start with eligibility (devices, diagnosis, surgery plans)
2. Transition after eligible: "Great news! You're eligible for the study. [ELIGIBLE] Now I need to collect some medical history. We'll automatically get things like your age and weight from Apple Health, but I need to ask you about medications, conditions, and a few other things..."
3. Work through sections in order: Demographics → Medications → Surgeries → Labs → Conditions → Clinical data → Planned surgery
4. Before finishing, summarize: "Let me confirm what I have..." then list key points
5. End with: "I have everything I need. [HISTORY_COMPLETE] You can tap Continue to proceed."

These markers help the app know when to enable the Continue button.
## Start the Conversation
"Hi! I'm here to help you join the HomeFlow study. This is a research study that tracks urinary symptoms before and after prostate surgery. Let me ask a few quick questions to make sure this study is right for you.

## Start the conversation
Open with something like: "Hi! I'm here to help you join the HomeFlow study. Let me ask a few questions to make sure this study is a good fit for you. First, are you using an iPhone?"`;
First - are you using an iPhone with iOS 15 or later?"`;

type ChatPhase = 'eligibility' | 'medical_history' | 'complete' | 'ineligible';

Expand Down Expand Up @@ -196,6 +270,7 @@ export default function OnboardingChatScreen() {
provider={provider}
systemPrompt={SYSTEM_PROMPT}
placeholder="Type your response..."
onResponse={checkForMarkers}
emptyState={
<View style={styles.emptyState}>
<IconSymbol name="message.fill" size={48} color={colors.icon} />
Expand Down
Loading
Loading