forked from wishonia/wishonia
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create treatment page with meta-analysis
Introduced a new treatment page to display meta-analysis on safety and efficacy. Updated related components and actions to support fetching the meta-analysis based on treatment and condition names. Enhanced existing components for better user input handling using autocomplete options.
- Loading branch information
Showing
8 changed files
with
169 additions
and
27 deletions.
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
9 changes: 0 additions & 9 deletions
9
app/dfda/conditions/[conditionName]/treatements/[treatmentName]/page.tsx
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
app/dfda/conditions/[conditionName]/treatments/[treatmentName]/page.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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"use client" | ||
import React, { useEffect, useState } from 'react' | ||
import { useParams } from 'next/navigation' | ||
import { getMetaAnalysis } from '@/app/dfda/dfdaActions' | ||
import ArticleRenderer from '@/components/ArticleRenderer' | ||
import { ArticleWithRelations } from '@/lib/agents/researcher/researcher' | ||
import GlobalHealthOptimizationAgent from "@/components/landingPage/global-health-optimization-agent"; | ||
import { useSession } from 'next-auth/react' | ||
|
||
export default function TreatmentForConditionPage() { | ||
const { data: session, status } = useSession() | ||
const params = useParams() | ||
const [article, setArticle] = useState<ArticleWithRelations | null>(null) | ||
const [loading, setLoading] = useState(status === "loading") | ||
|
||
if (loading) { | ||
return <div>Loading...</div> | ||
} | ||
|
||
useEffect(() => { | ||
async function fetchMetaAnalysis() { | ||
debugger | ||
console.log("Fetching meta-analysis for", params.treatmentName, params.conditionName) | ||
if (typeof params.treatmentName === 'string' && typeof params.conditionName === 'string') { | ||
try { | ||
const metaAnalysis = await getMetaAnalysis(params.treatmentName, params.conditionName) | ||
setArticle(metaAnalysis) | ||
} catch (error) { | ||
console.error('Error fetching meta-analysis:', error) | ||
} finally { | ||
setLoading(false) | ||
} | ||
} | ||
} | ||
|
||
fetchMetaAnalysis() | ||
}, [params.treatmentName, params.conditionName]) | ||
|
||
if (loading) { | ||
return <div className="container mx-auto px-4 py-8"> | ||
<GlobalHealthOptimizationAgent /> | ||
</div> | ||
} | ||
|
||
if (!article) { | ||
return <div className="container mx-auto px-4 py-8">Failed to load meta-analysis.</div> | ||
} | ||
|
||
return ( | ||
<div className="container mx-auto px-4 py-8"> | ||
<ArticleRenderer article={article} currentUserId={session?.user?.id} /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
"use client" | ||
import React, { useEffect, useState } from 'react' | ||
import { useParams } from 'next/navigation' | ||
import { useSession } from 'next-auth/react' | ||
import ArticleRenderer from '@/components/ArticleRenderer' | ||
import { ArticleWithRelations } from '@/lib/agents/researcher/researcher' | ||
import GlobalHealthOptimizationAgent from "@/components/landingPage/global-health-optimization-agent" | ||
import { findOrCreateArticleByTopic } from "@/app/researcher/researcherActions" | ||
import { UserAuthForm } from "@/components/user/user-auth-form" | ||
|
||
export default function TreatmentPage() { | ||
const { data: session, status } = useSession() | ||
const params = useParams() | ||
const [article, setArticle] = useState<ArticleWithRelations | null>(null) | ||
const [loading, setLoading] = useState(true) | ||
const treatmentName = typeof params.treatmentName === 'string' ? decodeURIComponent(params.treatmentName) : '' | ||
|
||
useEffect(() => { | ||
async function fetchMetaAnalysis() { | ||
if (!session?.user?.id || !treatmentName) { | ||
setLoading(false) | ||
return | ||
} | ||
|
||
try { | ||
const metaAnalysis = await findOrCreateArticleByTopic( | ||
`Article on the Safety and Efficacy of ${treatmentName} for Various Conditions`, | ||
session.user.id | ||
) | ||
setArticle(metaAnalysis) | ||
} catch (error) { | ||
console.error('Error fetching meta-analysis:', error) | ||
} finally { | ||
setLoading(false) | ||
} | ||
} | ||
|
||
if (status === 'authenticated') { | ||
fetchMetaAnalysis() | ||
} else if (status === 'unauthenticated') { | ||
setLoading(false) | ||
} | ||
}, [treatmentName, session?.user?.id, status]) | ||
|
||
if (status === 'loading' || loading) { | ||
return ( | ||
<div className="container mx-auto px-4 py-8"> | ||
<GlobalHealthOptimizationAgent /> | ||
</div> | ||
) | ||
} | ||
|
||
if (!session?.user?.id) { | ||
return <UserAuthForm /> | ||
} | ||
|
||
if (!article) { | ||
return <div className="container mx-auto px-4 py-8">Failed to load meta-analysis.</div> | ||
} | ||
|
||
return ( | ||
<div className="container mx-auto px-4 py-8"> | ||
<h1 className="text-2xl font-bold mb-4">Treatment: {treatmentName}</h1> | ||
<ArticleRenderer article={article} currentUserId={session.user.id} /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react' | ||
import Link from 'next/link' | ||
import { fetchConditions } from '../dfdaActions' | ||
|
||
export default async function ConditionListPage() { | ||
const conditions = await fetchConditions() | ||
const sortedConditions = conditions.sort((a, b) => b.numberOfTreatments - a.numberOfTreatments) | ||
|
||
return ( | ||
<div className="container mx-auto px-4 py-8 space-y-8"> | ||
<h1 className="text-2xl font-bold">Conditions</h1> | ||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4"> | ||
{sortedConditions.map((condition) => ( | ||
<Link href={`/dfda/conditions/${condition.name}`} key={condition.id}> | ||
<div className="card p-4 rounded-lg shadow-md hover:shadow-lg transition-shadow duration-300"> | ||
<h2 className="text-lg font-semibold">{condition.name}</h2> | ||
<span className="inline-block mt-2 text-xs font-semibold px-2 py-1 rounded-full bg-opacity-20"> | ||
{condition.numberOfTreatments} Treatments | ||
</span> | ||
</div> | ||
</Link> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
} |