Skip to content

Health Software Common Practices

HSCP-T-008 · open test

Purchase register: environmental and security criteria filled in, reuse justified

Serves HSCP-G-010 · Recipe: HSCP-R-021

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

What the test checks

The evidence is the purchase register, one JSON object per purchase (JSON Lines), following the recipe's data model:

Field Required Meaning
achat yes purchase identifier
categorie yes equipement, hebergement, prestation, composant or service-tiers
fournisseur yes supplier name
criteres_environnement yes list of critere, reponse objects (oui, non, non-renseigne)
criteres_securite yes same form
reemploi no true for refurbished equipment
equivalence_neuf for reuse reference of the statement that performance, efficiency and security are equivalent to new
usage_soins no true if the equipment is used in contact with patients
desinfection for reuse in contact with patients reference of the check of compatibility with hygiene procedures
decision yes action (retenu, reserve, ecarte), date, motif

The test accepts the register if each purchase has its category, at least one environmental criterion and one security criterion with an answer from the list, a dated and reasoned decision, and, for reused equipment, the proof of equivalence to new and, in contact with patients, the disinfection check.

It reports, without refusing, a purchase retained although the supplier filled in no environmental criterion.

Running the test

python3 verifier.py registre.jsonl

--json returns the answer as JSON. Exit code: 0 evidence accepted, 1 evidence refused, 2 incorrect call. Python 3.10 or later, no dependency.

Examples

  • exemples/valide/: refurbished tablets used at the patient's bedside, with an equivalence statement and a disinfection test; a third-party service retained with a reservation for lack of information on its impacts. Accepted.
  • exemples/refuse/: refurbished equipment with no security criterion, no statement and no disinfection test, decision without reason; a purchase outside the categories, with an answer outside the list and an undated decision. Refused.

What the test does not say

  • It does not say that the suppliers' answers are true, nor that the equivalence statement or the disinfection test are conclusive: that remains a review.
  • It does not say that the purchasing grid covers all categories or the right criteria.
  • It does not judge the decision: it checks that it exists, dated and reasoned.

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-008 : registre des achats, critères environnementaux et de sécurité renseignés, réemploi justifié.

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

Lit le registre, un objet JSON par achat (JSON Lines) : achat, categorie, fournisseur, criteres_environnement,
criteres_securite, reemploi, equivalence_neuf, usage_soins, desinfection, decision {action, date, motif}.
Refus : ligne illisible ; champ obligatoire absent ; catégorie hors liste ; achat en double ; aucun critère
environnemental ou aucun critère de sécurité ; réponse de critère hors liste (oui, non, non-renseigne) ; décision
absente, hors liste (retenu, reserve, ecarte), non datée ou sans motif ; équipement de réemploi sans preuve
d'équivalence au neuf ; équipement de réemploi au contact des patients sans vérification de désinfection.
Note seulement : achat retenu dont tous les critères environnementaux sont « non-renseigne ».
Il ne dit pas que les réponses des fournisseurs sont vraies.

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-008"
CATEGORIES = {"equipement", "hebergement", "prestation", "composant", "service-tiers"}
REPONSES = {"oui", "non", "non-renseigne"}
ACTIONS = {"retenu", "reserve", "ecarte"}
OBLIGATOIRES = ("achat", "categorie", "fournisseur", "criteres_environnement", "criteres_securite", "decision")


def criteres(nom, liste, famille, refus):
    if not isinstance(liste, list) or not liste:
        refus.append(f"{nom} : aucun critère {famille}")
        return []
    reponses = []
    for c in liste:
        if not isinstance(c, dict) or not c.get("critere") or c.get("reponse") not in REPONSES:
            refus.append(f"{nom} : critère {famille} sans nom ou réponse hors liste (oui, non, non-renseigne)")
            continue
        reponses.append(c["reponse"])
    return reponses


def verifier(chemin):
    refus, notes, vus, n = [], [], set(), 0
    for num, ligne in enumerate(open(chemin, encoding="utf-8"), 1):
        if not ligne.strip():
            continue
        try:
            a = json.loads(ligne)
            assert isinstance(a, dict)
        except (ValueError, AssertionError):
            refus.append(f"ligne {num} : objet JSON illisible")
            continue
        n += 1
        nom = str(a.get("achat") or f"ligne {num}")
        manque = [c for c in OBLIGATOIRES if a.get(c) in (None, "", [])]
        if manque:
            refus.append(f"{nom} : champ(s) absent(s) : {', '.join(manque)}")
        if nom in vus:
            refus.append(f"{nom} : achat en double")
        vus.add(nom)
        if a.get("categorie") and a["categorie"] not in CATEGORIES:
            refus.append(f"{nom} : catégorie hors liste")
        env = criteres(nom, a.get("criteres_environnement"), "environnemental", refus)
        criteres(nom, a.get("criteres_securite"), "de sécurité", refus)
        d = a.get("decision") if isinstance(a.get("decision"), dict) else {}
        if d.get("action") not in ACTIONS:
            refus.append(f"{nom} : décision hors liste (retenu, reserve, ecarte)")
        try:
            dt.date.fromisoformat(str(d.get("date")))
        except ValueError:
            refus.append(f"{nom} : décision non datée")
        if not d.get("motif"):
            refus.append(f"{nom} : décision sans motif")
        if a.get("reemploi") is True:
            if a.get("categorie") != "equipement":
                refus.append(f"{nom} : réemploi déclaré hors catégorie équipement")
            if not a.get("equivalence_neuf"):
                refus.append(f"{nom} : réemploi sans preuve d'équivalence au neuf (performances, efficience, sécurité)")
            if a.get("usage_soins") is True and not a.get("desinfection"):
                refus.append(f"{nom} : réemploi au contact des patients sans vérification de compatibilité avec la désinfection")
        if d.get("action") == "retenu" and env and all(r == "non-renseigne" for r in env):
            notes.append(f"{nom} : retenu sans aucun critère environnemental renseigné par le fournisseur")
    if n == 0:
        refus.append("registre vide")
    return refus, notes, n


def main(argv):
    p = argparse.ArgumentParser(prog="verifier.py", description=__doc__.splitlines()[0])
    p.add_argument("registre")
    p.add_argument("--json", action="store_true")
    try:
        a = p.parse_args(argv)
    except SystemExit:
        return 2
    try:
        refus, notes, n = verifier(a.registre)
    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, "achats": n, "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} achat(s))")
        for r in refus:
            print("  refus :", r)
        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