Skip to content

Health Software Common Practices

HSCP-T-021 · open test

Instructions for use of an AI system for the deployer, structured, dated and versioned

Serves HSCP-G-087, HSCP-G-218 · Recipe: HSCP-R-034

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 instructions for use of the version, exported as JSON with its sections: version, date, fournisseur, destination, usages_proscrits, population (inclusion, exclusion), fonctionnement, donnees (entrainement, validation), performances, sous_groupes, limites, donnees_entree, controle_humain, journaux, historique.

The test accepts the instructions if all sections are filled in; if each performance carries its indicator, its value, an interval that contains it and its validation population; if at least one subgroup is given, evaluated or not evaluated with its reason; if at least one limitation is written; and if the history contains a dated entry for the version of the instructions.

Running the test

python3 verifier.py notice.json

--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/: complete instructions for 3.2, two performances with interval and population, one evaluated subgroup and one not evaluated with its reason, two limitations, history up to date. Accepted.
  • exemples/refuse/: unreadable date, prohibited uses, subgroups and limitations missing, exclusion criterion missing, a performance without interval or population, an interval that does not contain the value, history without the current version. Rejected.

What the test does not say

  • It does not say that the figures are correct: they come from the evaluation of the version, which is checked separately.
  • It does not say that the instructions are understandable: the review by users judges that.
  • It does not say that earlier versions remain available.

Code

Download the test (zip archive: program, examples, README, licence) (10 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-021 : notice d'un système d'IA au déployeur, structurée, datée et versionnée.

    python3 verifier.py <notice.json> [--json]

Lit un objet JSON : version, date, fournisseur, destination, usages_proscrits, population (inclusion, exclusion),
fonctionnement, donnees (entrainement, validation), performances (indicateur, valeur, intervalle, population),
sous_groupes (groupe, indicateur, valeur, intervalle, ou evalue: false), limites, donnees_entree, controle_humain,
journaux, historique (version, date, changements).
Refus : fichier illisible ; rubrique absente ou vide ; date illisible ; performance sans indicateur, valeur,
intervalle ou population ; intervalle qui ne contient pas la valeur ; aucun sous-groupe ; aucune limite ;
historique sans entrée pour la version de la notice ; entrée d'historique sans date ou sans changement.
Il ne dit pas que les chiffres sont justes ni que la notice est compréhensible.

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-021"
RUBRIQUES = ("version", "date", "fournisseur", "destination", "usages_proscrits", "population", "fonctionnement",
             "donnees", "performances", "sous_groupes", "limites", "donnees_entree", "controle_humain", "journaux",
             "historique")


def nombre(v):
    return isinstance(v, (int, float)) and not isinstance(v, bool)


def jour(v):
    try:
        return dt.date.fromisoformat(str(v))
    except ValueError:
        return None


def perf(p, nom, refus, population=True):
    if not p.get("indicateur") or not nombre(p.get("valeur")):
        refus.append(f"{nom} : indicateur ou valeur absent")
        return
    i = p.get("intervalle")
    if not (isinstance(i, list) and len(i) == 2 and all(nombre(x) for x in i) and i[0] <= p["valeur"] <= i[1]):
        refus.append(f"{nom} : intervalle absent ou qui ne contient pas la valeur")
    if population and not p.get("population"):
        refus.append(f"{nom} : population de validation absente")


def verifier(d):
    refus = []
    absentes = [k for k in RUBRIQUES if d.get(k) in (None, "", [], {})]
    if absentes:
        refus.append(f"rubrique(s) absente(s) ou vide(s) : {', '.join(absentes)}")
    if d.get("date") and jour(d["date"]) is None:
        refus.append("date de la notice illisible")
    pop = d.get("population") or {}
    if isinstance(pop, dict) and (not pop.get("inclusion") or "exclusion" not in pop):
        refus.append("population : critères d'inclusion et d'exclusion attendus")
    for i, p in enumerate(d.get("performances") or [], 1):
        perf(p, f"performance {p.get('indicateur') or i}", refus)
    for i, g in enumerate(d.get("sous_groupes") or [], 1):
        nom = f"sous-groupe {g.get('groupe') or i}"
        if not g.get("groupe"):
            refus.append(f"{nom} : groupe non nommé")
        elif g.get("evalue") is False:
            if not g.get("motif"):
                refus.append(f"{nom} : non évalué sans motif")
        else:
            perf(g, nom, refus, population=False)
    h = d.get("historique") or []
    if d.get("version") and not any(str(e.get("version")) == str(d["version"]) for e in h):
        refus.append("historique sans entrée pour la version de la notice")
    for e in h:
        if jour(e.get("date")) is None or not e.get("changements"):
            refus.append(f"historique {e.get('version')} : date ou changements absents")
    return refus


def main(argv):
    p = argparse.ArgumentParser(prog="verifier.py", description=__doc__.splitlines()[0])
    p.add_argument("fichier")
    p.add_argument("--json", action="store_true")
    try:
        a = p.parse_args(argv)
    except SystemExit:
        return 2
    try:
        d = json.load(open(a.fichier, encoding="utf-8"))
        assert isinstance(d, dict)
    except (OSError, ValueError, AssertionError) as e:
        print(f"{ID} : pièce illisible : {e}", file=sys.stderr)
        return 2
    refus = verifier(d)
    if a.json:
        print(json.dumps({"test": ID, "accepte": not refus, "version": d.get("version"), "refus": refus},
                         ensure_ascii=False, indent=2))
    else:
        print(f"{ID} : {'pièce acceptée' if not refus else 'pièce refusée'} (notice {d.get('version')})")
        for x in refus:
            print("  refus :", x)
    return 0 if not refus else 1


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

Files of the test