Skip to content

Commit

Permalink
Merge pull request #85 from betagouv/maud/pediatrics
Browse files Browse the repository at this point in the history
Pediatrics warnings
  • Loading branch information
jillro authored Jan 20, 2025
2 parents 2a19fa4 + 438d5f4 commit 8c88c5e
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 89 deletions.
194 changes: 105 additions & 89 deletions src/app/(container)/medicaments/[CIS]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import liste_CIS_MVP from "@/liste_CIS_MVP.json";
import type { FrIconClassName } from "@codegouvfr/react-dsfr/src/fr/generatedFromCss/classNames";
import Alert from "@codegouvfr/react-dsfr/Alert";
import { getPregnancyAlerts } from "@/data/grist/pregnancy";
import { getPediatrics } from "@/data/grist/pediatrics";
import PediatricsTags from "@/components/PediatricsTags";

export const dynamic = "error";
export const dynamicParams = true;
Expand Down Expand Up @@ -220,6 +222,8 @@ export default async function Page(props: {
composants.find((c) => c.SubsId.trim() === String(s.id)),
);

const pediatrics = await getPediatrics(CIS);

return (
<>
<Breadcrumb
Expand Down Expand Up @@ -252,12 +256,13 @@ export default async function Page(props: {
<h1 className={fr.cx("fr-h2")}>
{formatSpecName(specialite.SpecDenom01)}
</h1>
{pregnancyAlert && (
<div className={fr.cx("fr-grid-row", "fr-mb-2w")}>
<div className={fr.cx("fr-col-12", "fr-col-lg-9", "fr-col-md-10")}>
<div className={fr.cx("fr-grid-row")}>
<div className={fr.cx("fr-col-12", "fr-col-lg-9", "fr-col-md-10")}>
{pregnancyAlert && (
<Alert
severity={"warning"}
title={"Contre-indication grossesse"}
className={fr.cx("fr-mb-2w")}
description={
<p>
Ce médicament est contre-indiqué si vous êtes enceinte ou
Expand All @@ -270,93 +275,104 @@ export default async function Page(props: {
</p>
}
/>
</div>
</div>
)}
<section className={"fr-mb-4w"}>
<div className={"fr-mb-1w"}>
<ul className={fr.cx("fr-tags-group", "fr-mb-n1v")}>
<Tag
small
linkProps={{
href: `/atc/${atc2.code}`,
className: cx("fr-tag--custom-alt-class"),
}}
>
{atc2.label}
</Tag>
<Tag
small
linkProps={{
href: `/substances/${displaySimpleComposants(composants)
.map((s) => s.NomId.trim())
.join(",")}`,
className: cx("fr-tag--custom-alt-substance"),
}}
>
{displaySimpleComposants(composants)
.map((s) => s.NomLib.trim())
.join(", ")}
</Tag>
{isPrinceps && (
<Tag
small
iconId="fr-icon-capsule-fill"
linkProps={{
className: fr.cx("fr-tag--blue-ecume"),
href: `/generiques/${CIS}`,
}}
>
Princeps
</Tag>
)}
{specialite.SpecGeneId ? (
<Tag
small
iconId="fr-icon-capsule-fill"
linkProps={{
className: fr.cx("fr-tag--blue-ecume"),
href: `/generiques/${specialite.SpecGeneId}`,
}}
>
Générique
</Tag>
) : null}{" "}
{delivrance.length ? (
<Tag
small
iconId="fr-icon-file-text-fill"
nativeButtonProps={{
className: fr.cx("fr-tag--blue-ecume"),
}}
>
Sur ordonnance
</Tag>
) : null}
{pregnancyAlert && (
<Tag
small
iconId={"fr-icon--custom-pregnancy" as FrIconClassName}
linkProps={{
href: "#",
className: fr.cx("fr-tag--orange-terre-battue"),
}}
>
Contre-indication grossesse
</Tag>
)}
</ul>
</div>
<div className={"fr-mb-1w"}>
<span
className={["fr-icon--custom-molecule", fr.cx("fr-mr-1w")].join(
" ",
)}
/>
<b>Substance active</b> {displayCompleteComposants(composants)}
)}
{pediatrics?.contraindication && (
<Alert
severity={"warning"}
title={
"Il existe une contre-indication pédiatrique (vérifier selon l’âge)."
}
className={fr.cx("fr-mb-2w")}
/>
)}

<section className={"fr-mb-4w"}>
<div className={"fr-mb-1w"}>
<ul className={fr.cx("fr-tags-group", "fr-mb-n1v")}>
<Tag
small
linkProps={{
href: `/atc/${atc2.code}`,
className: cx("fr-tag--custom-alt-class"),
}}
>
{atc2.label}
</Tag>
<Tag
small
linkProps={{
href: `/substances/${displaySimpleComposants(composants)
.map((s) => s.NomId.trim())
.join(",")}`,
className: cx("fr-tag--custom-alt-substance"),
}}
>
{displaySimpleComposants(composants)
.map((s) => s.NomLib.trim())
.join(", ")}
</Tag>
{isPrinceps && (
<Tag
small
iconId="fr-icon-capsule-fill"
linkProps={{
className: fr.cx("fr-tag--blue-ecume"),
href: `/generiques/${CIS}`,
}}
>
Princeps
</Tag>
)}
{specialite.SpecGeneId ? (
<Tag
small
iconId="fr-icon-capsule-fill"
linkProps={{
className: fr.cx("fr-tag--blue-ecume"),
href: `/generiques/${specialite.SpecGeneId}`,
}}
>
Générique
</Tag>
) : null}{" "}
{delivrance.length ? (
<Tag
small
iconId="fr-icon-file-text-fill"
nativeButtonProps={{
className: fr.cx("fr-tag--blue-ecume"),
}}
>
Sur ordonnance
</Tag>
) : null}
{pregnancyAlert && (
<Tag
small
iconId={"fr-icon--custom-pregnancy" as FrIconClassName}
linkProps={{
href: "#",
className: fr.cx("fr-tag--orange-terre-battue"),
}}
>
Contre-indication grossesse
</Tag>
)}
{pediatrics && <PediatricsTags info={pediatrics} />}
</ul>
</div>
<div className={"fr-mb-1w"}>
<span
className={["fr-icon--custom-molecule", fr.cx("fr-mr-1w")].join(
" ",
)}
/>
<b>Substance active</b> {displayCompleteComposants(composants)}
</div>
<PresentationsList presentations={presentations} />
</section>
</div>
<PresentationsList presentations={presentations} />
</section>
</div>
{leaflet ? (
<div className={fr.cx("fr-grid-row")}>
<article
Expand Down
48 changes: 48 additions & 0 deletions src/components/PediatricsTags.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { PediatricsInfo } from "@/data/grist/pediatrics";
import Tag from "@codegouvfr/react-dsfr/Tag";
import React from "react";
import { fr } from "@codegouvfr/react-dsfr";
import type { FrIconClassName } from "@codegouvfr/react-dsfr/src/fr/generatedFromCss/classNames";

export default function PediatricsTags({ info }: { info: PediatricsInfo }) {
return (
<>
{info.indication && (
<Tag
small
iconId={"fr-icon--custom-bedroom-baby" as FrIconClassName}
linkProps={{
href: `#`,
className: fr.cx("fr-tag--green-emeraude"),
}}
>
Peut être utilisé chez l&apos;enfant selon l&apos;âge
</Tag>
)}
{info.contraindication && (
<Tag
small
iconId={"fr-icon--custom-bedroom-baby" as FrIconClassName}
linkProps={{
href: `#`,
className: fr.cx("fr-tag--orange-terre-battue"),
}}
>
Contre-indication chez l&apos;enfant selon l&apos;âge
</Tag>
)}
{info.doctorAdvice && (
<Tag
small
iconId={"fr-icon--custom-bedroom-baby" as FrIconClassName}
linkProps={{
href: `#`,
className: fr.cx("fr-tag--yellow-tournesol"),
}}
>
Utilisation chez l&apos;enfant sur avis médical
</Tag>
)}
</>
);
}
5 changes: 5 additions & 0 deletions src/customIcons/bedroom-baby.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/customIcons/customIcons.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.fr-icon--custom-bedroom-baby::before,
.fr-icon--custom-bedroom-baby::after {
mask-image:url('bedroom-baby.svg')
}

.fr-icon--custom-molecule::before,
.fr-icon--custom-molecule::after {
mask-image:url('molecule.svg')
Expand Down
49 changes: 49 additions & 0 deletions src/data/grist/pediatrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { getGristTableData } from "@/data/grist/index";

export interface PediatricsInfo {
indication: boolean;
contraindication: boolean;
doctorAdvice: boolean;
}

const isOuiOrNon = (value: any): value is "oui" | "non" =>
typeof value === "string" &&
(value.trim() === "oui" || value.trim() === "non");

export async function getPediatrics(
CIS: string,
): Promise<PediatricsInfo | undefined> {
const records = await getGristTableData("Pediatrie", [
"CIS",
"indication",
"contre_indication",
"avis",
]);

const record = records.find(
({ fields }) => fields.CIS.toString().trim() === CIS,
);

if (!record) {
return;
}

if (
!isOuiOrNon(record.fields.indication) ||
!isOuiOrNon(record.fields.contre_indication) ||
!isOuiOrNon(record.fields.avis)
) {
throw new Error(
`Unexpected value in pediatrics data for CIS ${CIS}: ${JSON.stringify(
record.fields,
)}`,
);
}

if (record)
return {
indication: record.fields.indication.trim() === "oui",
contraindication: record.fields.contre_indication.trim() === "oui",
doctorAdvice: record.fields.avis.trim() === "oui",
};
}

0 comments on commit 8c88c5e

Please sign in to comment.