diff --git a/src/app/(container)/parcourir/pathologies/[letter]/page.tsx b/src/app/(container)/parcourir/pathologies/[letter]/page.tsx new file mode 100644 index 0000000..0d779ef --- /dev/null +++ b/src/app/(container)/parcourir/pathologies/[letter]/page.tsx @@ -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("substr", ["NomPatho", val(1), val(1)]).as("letter"), + ) + .orderBy("letter") + .groupBy("letter") + .execute(); +} + +async function getPathologyPage(letter: string): Promise { + return pdbmMySQL + .selectFrom("Patho") + .selectAll() + .where("NomPatho", "like", `${letter}%`) + .execute(); +} + +async function getLetters(): Promise { + 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 ( +
+
+

Liste des pathologies

+

+ {letters.map((a) => ( + <> + + {a} + {" "} + + ))} +

+
    + {pathos.map((patho, i) => ( +
  • + + {patho.NomPatho} + +
  • + ))} +
+
+
+ ); +} diff --git a/src/app/(container)/pathologie/[code]/page.tsx b/src/app/(container)/pathologie/[code]/page.tsx new file mode 100644 index 0000000..3f9de6c --- /dev/null +++ b/src/app/(container)/pathologie/[code]/page.tsx @@ -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 { + const patho = await pdbmMySQL + .selectFrom("Patho") + .selectAll() + .where("codePatho", "=", code) + .executeTakeFirst(); + + if (!patho) notFound(); + + return patho; +} + +async function getSpecialite(code: string): Promise { + 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 ( + <> + + + +

+ {medicaments.length} médicaments traitant la pathologie « anxiété » +

+ + + ); +} diff --git a/src/app/(container)/rechercher/page.tsx b/src/app/(container)/rechercher/page.tsx index 93c70f5..1e797b4 100644 --- a/src/app/(container)/rechercher/page.tsx +++ b/src/app/(container)/rechercher/page.tsx @@ -1,27 +1,13 @@ -import path from "node:path"; -import { readFileSync } from "node:fs"; import { Fragment } from "react"; -import { parse as csvParse } from "csv-parse/sync"; import Link from "next/link"; import { fr } from "@codegouvfr/react-dsfr"; -import Tag from "@codegouvfr/react-dsfr/Tag"; import { cx } from "@codegouvfr/react-dsfr/tools/cx"; -import { Specialite, SubstanceNom } from "@/db/pdbmMySQL/types"; -import { getAtcLabels } from "@/data/atc"; +import { SubstanceNom } from "@/db/pdbmMySQL/types"; import { getResults } from "@/db/search"; import { formatSpecName } from "@/displayUtils"; import AutocompleteSearch from "@/components/AutocompleteSearch"; - -const atcData = csvParse( - readFileSync( - path.join(process.cwd(), "src", "data", "CIS-ATC_2024-04-07.csv"), - ), -) as string[][]; -function getAtc(CIS: string) { - const atc = atcData.find((row) => row[0] === CIS); - return atc ? atc[1] : null; -} +import MedGroupSpecList from "@/components/MedGroupSpecList"; const SubstanceResult = ({ item }: { item: SubstanceNom }) => (
  • @@ -40,68 +26,6 @@ const SubstanceResult = ({ item }: { item: SubstanceNom }) => (
  • ); -const MedicamentGroupResult = async ({ - item, -}: { - item: { groupName: string; specialites: Specialite[] }; -}) => { - const atc = getAtc(item.specialites[0].SpecId); - const atcLabels = atc ? await getAtcLabels(atc) : null; - const [, subClass, substance] = atcLabels ? atcLabels : [null, null, null]; - return ( -
  • -
    -
    - - {formatSpecName(item.groupName)} - -
    -
    -
    - -
    -
      - {subClass && ( - - {subClass} - - )} - {substance && ( - - {substance} - - )} -
    -
    -
    -
      - {item.specialites?.map((specialite, i) => ( -
    • - - {formatSpecName(specialite.SpecDenom01) - .replace(`${formatSpecName(item.groupName)}, `, "") - .replace(formatSpecName(item.groupName), "")} - -
    • - ))} -
    -
  • - ); -}; - export default async function Page({ searchParams, }: { @@ -132,7 +56,11 @@ export default async function Page({ {"NomLib" in result ? ( ) : ( - + )} ))} diff --git a/src/app/(container)/substance/[id]/page.tsx b/src/app/(container)/substance/[id]/page.tsx index 66f1d34..2f70366 100644 --- a/src/app/(container)/substance/[id]/page.tsx +++ b/src/app/(container)/substance/[id]/page.tsx @@ -71,7 +71,7 @@ export default async function Page({ Médicaments contenant uniquement « {substance.NomLib} »
      - {Array.from(groupSpecialites(specialites).entries()).map( + {groupSpecialites(specialites).map( ([groupName, specialites]: [string, Specialite[]]) => (
    • {formatSpecName(groupName)} diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 6fff99c..1624fae 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -71,6 +71,17 @@ export default function RootLayout({ serviceTitle="" // hack pour que la tagline soit bien affichée serviceTagline="La référence officielle sur les données des médicaments" quickAccessItems={[headerFooterDisplayItem]} + navigation={[ + { + text: "Par ordre alphabétique", + menuLinks: [ + { + text: "Toutes les pathologies", + linkProps: { href: "/parcourir/pathologies/A" }, + }, + ], + }, + ]} /> {children}