-
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.
Merge pull request #85 from betagouv/maud/pediatrics
Pediatrics warnings
- Loading branch information
Showing
5 changed files
with
212 additions
and
89 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,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'enfant selon l'â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'enfant selon l'â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'enfant sur avis médical | ||
</Tag> | ||
)} | ||
</> | ||
); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,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", | ||
}; | ||
} |