-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from mikepsinn/develop
Conversation2Measurements, global variables, generic variables, measurements, etc.
- Loading branch information
Showing
47 changed files
with
1,030 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { conversation2measurements } from "@/lib/conversation2measurements"; | ||
import {postMeasurements} from "@/lib/dfda"; | ||
import {getUserId} from "@/lib/getUserId"; | ||
|
||
export async function POST(request: NextRequest) { | ||
let { statement, localDateTime, previousStatements } = await request.json(); | ||
|
||
try { | ||
const measurements = await conversation2measurements(statement, localDateTime, previousStatements); | ||
const userId = await getUserId(); | ||
if(userId){ | ||
await postMeasurements(measurements, userId) | ||
} | ||
return NextResponse.json({ success: true, measurements: measurements }); | ||
} catch (error) { | ||
console.error('Error in conversation2measurements:', error); | ||
return NextResponse.json({ success: false, message: 'Error in conversation2measurements' }); | ||
} | ||
} | ||
|
||
export async function GET(req: NextRequest) { | ||
const urlParams = Object.fromEntries(new URL(req.url).searchParams); | ||
const statement = urlParams.statement as string; | ||
const previousStatements = urlParams.previousStatements as string | null | undefined; | ||
const localDateTime = urlParams.localDateTime as string | null | undefined; | ||
|
||
try { | ||
const measurements = await conversation2measurements(statement, localDateTime, previousStatements); | ||
const userId = await getUserId(); | ||
if(userId){await postMeasurements(measurements, userId)} | ||
return NextResponse.json({ success: true, measurements: measurements }); | ||
} catch (error) { | ||
console.error('Error sending request to OpenAI:', error); | ||
return NextResponse.json({ success: false, message: 'Error sending request to OpenAI' }); | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
apps/nextjs/app/dashboard/globalVariables/[variableId]/charts/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,34 @@ | ||
import { Metadata } from "next" | ||
import { notFound, redirect } from "next/navigation" | ||
|
||
import { authOptions } from "@/lib/auth" | ||
import { getCurrentUser } from "@/lib/session" | ||
import { Shell } from "@/components/layout/shell" | ||
import { DashboardHeader } from "@/components/pages/dashboard/dashboard-header" | ||
import { GlobalVariableCharts } from '@/components/globalVariables/global-variable-charts'; | ||
|
||
export const metadata: Metadata = { | ||
title: "Global Variable Charts", | ||
} | ||
|
||
interface GlobalVariableEditProps { | ||
params: { variableId: string } | ||
} | ||
|
||
export default async function GlobalVariableChart({ params }: GlobalVariableEditProps) { | ||
const user = await getCurrentUser() | ||
|
||
if (!user) { | ||
redirect(authOptions?.pages?.signIn || "/signin") | ||
} | ||
const variableId = parseInt(params.variableId) | ||
return ( | ||
<Shell> | ||
<div className="grid grid-cols-1 gap-10"> | ||
<GlobalVariableCharts | ||
variableId={variableId} | ||
/> | ||
</div> | ||
</Shell> | ||
) | ||
} |
27 changes: 27 additions & 0 deletions
27
apps/nextjs/app/dashboard/globalVariables/[variableId]/not-found.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,27 @@ | ||
import Link from "next/link" | ||
|
||
import { buttonVariants } from "@/components/ui/button" | ||
import { EmptyPlaceholder } from "@/components/empty-placeholder" | ||
import { Icons } from "@/components/icons" | ||
|
||
export default function NotFound() { | ||
return ( | ||
<div className="flex items-center justify-center md:p-4 lg:p-8"> | ||
<EmptyPlaceholder className="mx-auto max-w-[800px]"> | ||
<div className="flex h-20 w-20 items-center justify-center rounded-full bg-muted"> | ||
<Icons.warning className="h-10 w-10" /> | ||
</div> | ||
<EmptyPlaceholder.Title>Not Found</EmptyPlaceholder.Title> | ||
<EmptyPlaceholder.Description> | ||
This globalVariable could not be found. Please try again. | ||
</EmptyPlaceholder.Description> | ||
<Link | ||
href="/dashboard" | ||
className={buttonVariants({ variant: "outline" })} | ||
> | ||
Go to Dashboard | ||
</Link> | ||
</EmptyPlaceholder> | ||
</div> | ||
) | ||
} |
51 changes: 51 additions & 0 deletions
51
apps/nextjs/app/dashboard/globalVariables/[variableId]/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,51 @@ | ||
import { Metadata } from "next" | ||
import { redirect } from "next/navigation" | ||
|
||
import { authOptions } from "@/lib/auth" | ||
import { getCurrentUser } from "@/lib/session" | ||
import { Shell } from "@/components/layout/shell" | ||
import { GlobalVariableOverview } from "@/components/globalVariables/global-variable-overview"; | ||
|
||
|
||
interface GlobalVariablePageProps { | ||
params: { variableId: number } | ||
searchParams: { from: string; to: string } | ||
} | ||
|
||
// export async function generateMetadata({ | ||
// params, | ||
// }: GlobalVariablePageProps): Promise<Metadata> { | ||
// const user = await getCurrentUser() | ||
// | ||
// if (!user) { | ||
// redirect(authOptions?.pages?.signIn || "/signin") | ||
// } | ||
// const response = await fetch(`/api/dfda/globalVariables?variableId=${params.variableId}&includeCharts=0`); | ||
// const globalVariables = await response.json(); | ||
// const globalVariable = globalVariables[0]; | ||
// | ||
// return { | ||
// title: globalVariable?.name || "Not Found", | ||
// description: globalVariable?.description, | ||
// } | ||
// } | ||
|
||
export default async function GlobalVariablePage({ | ||
params, | ||
searchParams, | ||
}: GlobalVariablePageProps) { | ||
const user = await getCurrentUser() | ||
|
||
if (!user) { | ||
redirect(authOptions?.pages?.signIn || "/signin") | ||
} | ||
|
||
return ( | ||
<Shell> | ||
<GlobalVariableOverview variableId={params.variableId} user={user} measurementsDateRange={{ | ||
from: searchParams.from, | ||
to: searchParams.to | ||
}} /> | ||
</Shell> | ||
) | ||
} |
51 changes: 51 additions & 0 deletions
51
apps/nextjs/app/dashboard/globalVariables/[variableId]/settings/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,51 @@ | ||
import { Metadata } from "next" | ||
import { notFound, redirect } from "next/navigation" | ||
|
||
import { authOptions } from "@/lib/auth" | ||
import { getCurrentUser } from "@/lib/session" | ||
import { GlobalVariableEditForm } from "@/components/globalVariables/global-variable-edit-form" | ||
import { Shell } from "@/components/layout/shell" | ||
import { DashboardHeader } from "@/components/pages/dashboard/dashboard-header" | ||
|
||
export const metadata: Metadata = { | ||
title: "GlobalVariable Settings", | ||
} | ||
|
||
interface GlobalVariableEditProps { | ||
params: { variableId: string } | ||
} | ||
|
||
export default async function GlobalVariableEdit({ params }: GlobalVariableEditProps) { | ||
const user = await getCurrentUser() | ||
|
||
if (!user) { | ||
redirect(authOptions?.pages?.signIn || "/signin") | ||
} | ||
|
||
const response = await fetch( | ||
`/api/dfda/globalVariables?variableId=${params.variableId}&includeCharts=0`) | ||
const globalVariables = await response.json() | ||
const globalVariable = globalVariables[0] | ||
|
||
if (!globalVariable) { | ||
notFound() | ||
} | ||
|
||
return ( | ||
<Shell> | ||
<DashboardHeader | ||
heading={globalVariable.name + " Settings"} | ||
text="Modify globalVariable details." | ||
/> | ||
<div className="grid grid-cols-1 gap-10"> | ||
<GlobalVariableEditForm | ||
globalVariable={{ | ||
id: globalVariable.id, | ||
name: globalVariable.name, | ||
description: globalVariable.description | ||
}} | ||
/> | ||
</div> | ||
</Shell> | ||
) | ||
} |
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,41 @@ | ||
import { Metadata } from "next" | ||
import { redirect } from "next/navigation" | ||
|
||
import { authOptions } from "@/lib/auth" | ||
import { getCurrentUser } from "@/lib/session" | ||
import { GlobalVariableAddButton } from "@/components/globalVariables/global-variable-add-button" | ||
import { Shell } from "@/components/layout/shell" | ||
import { DashboardHeader } from "@/components/pages/dashboard/dashboard-header" | ||
import {GenericVariableList} from "@/components/genericVariables/generic-variable-list"; | ||
|
||
|
||
export const metadata: Metadata = { | ||
title: "Your Variables", | ||
description: "Manage your treatments, symptoms, and other variables.", | ||
} | ||
|
||
export default async function GlobalVariablesPage() { | ||
const user = await getCurrentUser() | ||
|
||
if (!user) { | ||
redirect(authOptions?.pages?.signIn || "/signin") | ||
} | ||
|
||
// Define search parameters | ||
const searchParams = { | ||
includePublic: false, | ||
sort: 'createdAt', | ||
limit: 10, | ||
offset: 0, | ||
searchPhrase: "", | ||
}; | ||
|
||
return ( | ||
<Shell> | ||
<DashboardHeader heading="Your Variables" text="Manage your treatments, symptoms, and other variables."> | ||
<GlobalVariableAddButton /> | ||
</DashboardHeader> | ||
<GenericVariableList user={user} searchParams={searchParams} /> | ||
</Shell> | ||
) | ||
} |
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
Oops, something went wrong.