-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Maud Royer <hello@maudroyer.fr>
- Loading branch information
Showing
10 changed files
with
317 additions
and
83 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
src/app/(container)/parcourir/pathologies/[letter]/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,76 @@ | ||
import { fr } from "@codegouvfr/react-dsfr"; | ||
import Link from "next/link"; | ||
import { Patho } from "@/db/pdbmMySQL/types"; | ||
import { pdbmMySQL } from "@/db/pdbmMySQL"; | ||
import { notFound } from "next/navigation"; | ||
|
||
export async function generateStaticParams(): Promise<{ letter: string }[]> { | ||
return pdbmMySQL | ||
.selectFrom("Patho") | ||
.select(({ fn, val }) => | ||
fn<string>("substr", ["NomPatho", val(1), val(1)]).as("letter"), | ||
) | ||
.orderBy("letter") | ||
.groupBy("letter") | ||
.execute(); | ||
} | ||
|
||
async function getPathologyPage(letter: string): Promise<Patho[]> { | ||
return pdbmMySQL | ||
.selectFrom("Patho") | ||
.selectAll() | ||
.where("NomPatho", "like", `${letter}%`) | ||
.execute(); | ||
} | ||
|
||
async function getLetters(): Promise<string[]> { | ||
return (await generateStaticParams()).map((r) => r.letter); | ||
} | ||
|
||
export default async function Page({ | ||
params: { letter }, | ||
}: { | ||
params: { letter: string }; | ||
}) { | ||
const letters = await getLetters(); | ||
const pathos = await getPathologyPage(letter); | ||
if (!pathos || !pathos.length) return notFound(); | ||
|
||
return ( | ||
<div className={fr.cx("fr-grid-row")}> | ||
<div className={fr.cx("fr-col-md-8")}> | ||
<h1 className={fr.cx("fr-h1", "fr-mb-8w")}>Liste des pathologies</h1> | ||
<p className={fr.cx("fr-text--lg")}> | ||
{letters.map((a) => ( | ||
<> | ||
<Link | ||
href={`/parcourir/pathologies/${a}`} | ||
key={a} | ||
className={fr.cx( | ||
"fr-link", | ||
"fr-link--lg", | ||
"fr-mr-3w", | ||
"fr-mb-3w", | ||
)} | ||
> | ||
{a} | ||
</Link>{" "} | ||
</> | ||
))} | ||
</p> | ||
<ul className={fr.cx("fr-raw-list")}> | ||
{pathos.map((patho, i) => ( | ||
<li key={i} className={fr.cx("fr-mb-1v")}> | ||
<Link | ||
href={`/pathologie/${patho.codePatho}`} | ||
className={fr.cx("fr-link")} | ||
> | ||
{patho.NomPatho} | ||
</Link> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
</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,71 @@ | ||
import { pdbmMySQL } from "@/db/pdbmMySQL"; | ||
import DefinitionBanner from "@/components/DefinitionBanner"; | ||
import { notFound } from "next/navigation"; | ||
import { Patho, Specialite } from "@/db/pdbmMySQL/types"; | ||
import { groupSpecialites } from "@/displayUtils"; | ||
import liste_CIS_MVP from "@/liste_CIS_MVP.json"; | ||
import { fr } from "@codegouvfr/react-dsfr"; | ||
import { MedGroupSpecListList } from "@/components/MedGroupSpecList"; | ||
import Breadcrumb from "@codegouvfr/react-dsfr/Breadcrumb"; | ||
|
||
export async function generateStaticParams(): Promise<{ code: string }[]> { | ||
return pdbmMySQL.selectFrom("Patho").select("codePatho as code").execute(); | ||
} | ||
|
||
async function getPatho(code: string): Promise<Patho> { | ||
const patho = await pdbmMySQL | ||
.selectFrom("Patho") | ||
.selectAll() | ||
.where("codePatho", "=", code) | ||
.executeTakeFirst(); | ||
|
||
if (!patho) notFound(); | ||
|
||
return patho; | ||
} | ||
|
||
async function getSpecialite(code: string): Promise<Specialite[]> { | ||
return pdbmMySQL | ||
.selectFrom("Specialite") | ||
.selectAll("Specialite") | ||
.leftJoin("Spec_Patho", "Specialite.SpecId", "Spec_Patho.SpecId") | ||
.where("Spec_Patho.codePatho", "=", code) | ||
.where("Specialite.SpecId", "in", liste_CIS_MVP) | ||
.execute(); | ||
} | ||
|
||
export default async function Page({ | ||
params: { code }, | ||
}: { | ||
params: { code: string }; | ||
}) { | ||
const patho = await getPatho(code); | ||
const specialites = await getSpecialite(code); | ||
const medicaments = groupSpecialites(specialites); | ||
return ( | ||
<> | ||
<Breadcrumb | ||
segments={[ | ||
{ label: "Accueil", linkProps: { href: "/" } }, | ||
{ | ||
label: "Listes des pathologies", | ||
linkProps: { | ||
href: `/parcourir/pathologies/${patho.NomPatho.slice(0, 1)}`, | ||
}, | ||
}, | ||
]} | ||
currentPageLabel={patho.NomPatho} | ||
/> | ||
<DefinitionBanner | ||
type="Pathologie" | ||
title={patho.NomPatho} | ||
definition="Définition de la pathologie" | ||
/> | ||
|
||
<h2 className={fr.cx("fr-h6", "fr-mt-4w")}> | ||
{medicaments.length} médicaments traitant la pathologie « anxiété » | ||
</h2> | ||
<MedGroupSpecListList items={medicaments} /> | ||
</> | ||
); | ||
} |
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,27 @@ | ||
import { fr } from "@codegouvfr/react-dsfr"; | ||
import Badge from "@codegouvfr/react-dsfr/Badge"; | ||
import Card from "@codegouvfr/react-dsfr/Card"; | ||
|
||
export default async function DefinitionBanner({ | ||
type, | ||
title, | ||
definition, | ||
}: { | ||
type: string; | ||
title: string; | ||
definition: string; | ||
}) { | ||
return ( | ||
<div className={fr.cx("fr-grid-row")}> | ||
<div className={fr.cx("fr-col-md-8")}> | ||
<Badge className={fr.cx("fr-badge--purple-glycine")}>{type}</Badge> | ||
<h1 className={fr.cx("fr-h1", "fr-mt-1w", "fr-mb-6w")}>{title}</h1> | ||
<div className={fr.cx("fr-grid-row")}> | ||
<div className={fr.cx("fr-col")}> | ||
<Card title="Définition" titleAs={"h6"} desc={definition} /> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.