Skip to content

Commit

Permalink
Merge pull request #23 from betagouv/maud/pathologies_definitions
Browse files Browse the repository at this point in the history
Add pathologies definitions
  • Loading branch information
jillro authored Oct 22, 2024
2 parents 6487189 + 54a251e commit eeed97f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/app/(container)/pathologie/[code]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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";
import { getPathologyDefinition } from "@/data/pathologies";

export async function generateStaticParams(): Promise<{ code: string }[]> {
return pdbmMySQL.selectFrom("Patho").select("codePatho as code").execute();
Expand All @@ -24,7 +25,7 @@ async function getPatho(code: string): Promise<Patho> {
return patho;
}

async function getSpecialite(code: string): Promise<Specialite[]> {
async function getPathoSpecialites(code: `${number}`): Promise<Specialite[]> {
return pdbmMySQL
.selectFrom("Specialite")
.selectAll("Specialite")
Expand All @@ -37,10 +38,11 @@ async function getSpecialite(code: string): Promise<Specialite[]> {
export default async function Page({
params: { code },
}: {
params: { code: string };
params: { code: `${number}` };
}) {
const patho = await getPatho(code);
const specialites = await getSpecialite(code);
const definition = await getPathologyDefinition(code);
const specialites = await getPathoSpecialites(code);
const medicaments = groupSpecialites(specialites);
return (
<>
Expand All @@ -59,7 +61,7 @@ export default async function Page({
<DefinitionBanner
type="Pathologie"
title={patho.NomPatho}
definition="Définition de la pathologie"
definition={definition}
/>

<h2 className={fr.cx("fr-h6", "fr-mt-4w")}>
Expand Down
7 changes: 5 additions & 2 deletions src/data/grist.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export async function getGristTableData(
import "server-only";
import { unstable_cache } from "next/cache";

export const getGristTableData = unstable_cache(async function (
tableId: string,
): Promise<{ id: number; fields: Record<string, string | number> }[]> {
const response = await fetch(
Expand All @@ -10,4 +13,4 @@ export async function getGristTableData(
},
);
return (await response.json()).records;
}
});
15 changes: 15 additions & 0 deletions src/data/pathologies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getGristTableData } from "@/data/grist";

export async function getPathologyDefinition(
code: `${number}`,
): Promise<string> {
const data = await getGristTableData("Pathologies");
const record = data.find(
(record: any) => record.fields.codePatho === Number(code),
);
if (!record) {
throw new Error(`Pathology code not found: ${code}`);
}

return record.fields.Definition_pathologie as string;
}

0 comments on commit eeed97f

Please sign in to comment.