Skip to content

Health Software Common Practices

HSCP-T-018 · open test

AI notice in documents produced with an AI system

Serves HSCP-G-144, HSCP-G-250 · Recipe: HSCP-R-031

Code under the licence Apache 2.0 · Python 3.10 or later, standard library only, no network access

What the test checks

The artefact is the export of the documents of a period, one JSON object per document (JSON Lines): document, type, genere_par_ia, systeme (nom, version), usage, mention, remis (handed to the patient or to a third party), valide_par, valide_le.

The test accepts the export if each document produced with AI carries a system, a version, a use and a notice that contains the name and version of the system; and if each document handed out carries the professional who validated it, the validation date, and a notice that names this professional.

It reports, without rejecting, a document produced without AI that carries an AI notice.

Running the test

python3 verifier.py documents.jsonl

--json gives the answer in JSON. Exit code: 0 artefact accepted, 1 artefact rejected, 2 incorrect call. Python 3.10 or later, no dependencies.

Examples

  • exemples/valide/: a report handed out with its full notice, an internal summary with its notice, a report written without AI. Accepted.
  • exemples/refuse/: report without a notice, notice naming neither the right version nor the professional, result without a version, report handed out without validation, unreadable line. Rejected.

What the test does not say

  • It does not say that the notice is legible or well placed in the document: the review of the screenshots judges that.
  • It does not say that the patient was informed before use, or that the level of information was the right one.
  • It does not see documents that left the product by another route than the export.

Code

Download the test (zip archive: program, examples, README, licence) (9 KB) · verifier.py

The code and its messages are not translated (French).

#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0
# Copyright 2026 les contributeurs des Gestes communs du logiciel de santé
"""HSCP-T-018 : mention de l'IA dans les documents produits avec un système d'IA.

    python3 verifier.py <documents.jsonl> [--json]

Lit l'export des documents d'une période, un objet JSON par document (JSON Lines) : document, type, genere_par_ia,
systeme (nom, version), usage, mention, remis (booléen : remis au patient ou à un tiers), valide_par, valide_le.
Refus : ligne illisible ; champ obligatoire absent ; document produit avec l'IA sans mention, sans système, sans
version ou sans usage ; mention qui ne contient pas le nom et la version du système ; document remis sans
professionnel qui valide ni date de validation, ou dont la mention ne nomme pas ce professionnel.
Note seulement : document sans IA qui porte une mention d'IA.
Il ne dit pas que la mention est lisible ni que le patient a été informé.

Codes de retour : 0 pièce acceptée, 1 pièce refusée, 2 appel incorrect.
Bibliothèque standard seulement, aucun accès réseau.
"""
import argparse
import datetime as dt
import json
import sys

ID = "HSCP-T-018"


def verifier(chemin):
    refus, notes, n, ia = [], [], 0, 0
    for num, ligne in enumerate(open(chemin, encoding="utf-8"), 1):
        if not ligne.strip():
            continue
        try:
            e = json.loads(ligne)
            assert isinstance(e, dict)
        except (ValueError, AssertionError):
            refus.append(f"ligne {num} : objet JSON illisible")
            continue
        n += 1
        nom = f"document « {e.get('document') or 'ligne ' + str(num)} »"
        if not e.get("document") or not e.get("type") or not isinstance(e.get("genere_par_ia"), bool):
            refus.append(f"{nom} : document, type ou genere_par_ia absent")
            continue
        mention = str(e.get("mention") or "")
        if not e["genere_par_ia"]:
            if mention:
                notes.append(f"{nom} : mention d'IA sur un document produit sans IA")
            continue
        ia += 1
        s = e.get("systeme") or {}
        if not s.get("nom") or not s.get("version") or not e.get("usage"):
            refus.append(f"{nom} : système, version ou usage absent")
            continue
        if not mention:
            refus.append(f"{nom} : produit avec l'IA sans mention")
            continue
        if s["nom"] not in mention or str(s["version"]) not in mention:
            refus.append(f"{nom} : la mention ne nomme pas le système et sa version")
        if e.get("remis") is True:
            v = e.get("valide_par")
            try:
                dt.date.fromisoformat(str(e.get("valide_le")))
                date_ok = True
            except ValueError:
                date_ok = False
            if not v or not date_ok:
                refus.append(f"{nom} : remis sans professionnel qui valide ni date de validation")
            elif v not in mention:
                refus.append(f"{nom} : la mention ne nomme pas le professionnel qui a validé")
    if n == 0:
        refus.append("export vide")
    return refus, notes, n, ia


def main(argv):
    p = argparse.ArgumentParser(prog="verifier.py", description=__doc__.splitlines()[0])
    p.add_argument("export")
    p.add_argument("--json", action="store_true")
    try:
        a = p.parse_args(argv)
    except SystemExit:
        return 2
    try:
        refus, notes, n, ia = verifier(a.export)
    except OSError as e:
        print(f"{ID} : pièce illisible : {e}", file=sys.stderr)
        return 2
    if a.json:
        print(json.dumps({"test": ID, "accepte": not refus, "documents": n, "avec_ia": ia, "refus": refus, "notes": notes},
                         ensure_ascii=False, indent=2))
    else:
        print(f"{ID} : {'pièce acceptée' if not refus else 'pièce refusée'} ({n} document(s), dont {ia} avec l'IA)")
        for x in refus:
            print("  refus :", x)
        for x in notes:
            print("  note :", x)
    return 0 if not refus else 1


if __name__ == "__main__":
    sys.exit(main(sys.argv[1:]))

Files of the test