HSCP-T-013 · open test
Resource inventory: measured usage, non-production on demand, redundancy of critical components
What the test checks
The evidence is the resource inventory, one JSON object per component and per environment (JSON Lines), following the recipe's data model:
| Field | Required | Meaning |
|---|---|---|
composant |
yes | component name |
environnement |
yes | production, preproduction (staging), test or developpement (development) |
raison |
yes | purpose |
critique_soin |
yes | true if stopping it prevents access to care information |
utilisation |
yes | moyenne (average) and pointe (peak), shares between 0 and 1 |
mise_a_echelle |
yes | automatique (automatic), manuelle (manual) or aucune (none) |
horaires |
yes | permanent, plage (time window) or a-la-demande (on demand) |
instances |
yes | number of instances |
justification |
accepted gap | reason for a gap |
mesure_le |
yes | end of the measured period |
The test accepts the inventory if each component carries these fields with a recent measurement, if no non-production environment runs permanently, if no non-critical component keeps a peak usage below the threshold, and if each care-critical component is in production with at least two instances; a written justification lifts each of these three gaps.
It reports, without refusing, a variable load without automatic scaling.
Running the test
python3 verifier.py inventaire.jsonl --date 2026-12-02 --seuil 0.2 --mesure-jours 100
--date sets the check date (today by default), --seuil the peak usage below which a non-critical component must be downsized (0.2 by default), --mesure-jours the maximum age of the measurement (100 days by default), --json returns the answer in JSON. Exit code: 0 evidence accepted, 1 evidence refused, 2 incorrect call. Python 3.10 or later, no dependencies.
Examples
exemples/valide/: the patient record application and database, critical and redundant; night-time exports; a staging environment started on demand. Accepted, with the exports' variable load reported.exemples/refuse/: a critical component without redundancy, a permanent and oversized test environment, inconsistent usage measured ten months ago, a critical component outside production with a scaling value outside the list, a missing purpose. Refused.
What the test does not say
- It does not say that the inventory lists every component: the review compares it with the bill or the actual fleet.
- It does not say that care criticality is right, nor that the availability level suits the care provided.
- It does not say that no care processing was deferred: the review checks that.
Code
Download the test (zip archive: program, examples, README, licence) (11 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-013 : inventaire des ressources, usage mesuré, hors production à la demande, redondance des composants
critiques pour le soin.
python3 verifier.py <inventaire.jsonl> [--date AAAA-MM-JJ] [--seuil S] [--mesure-jours N] [--json]
Lit l'inventaire, un objet JSON par composant et par environnement (JSON Lines) : composant, environnement, raison,
critique_soin, utilisation {moyenne, pointe}, mise_a_echelle, horaires, instances, justification, mesure_le.
Refus : ligne illisible ; champ obligatoire absent ; environnement, mise à l'échelle ou horaires hors liste ; couple
composant et environnement en double ; utilisation hors de 0 à 1 ou moyenne au-dessus de la pointe ; mesure plus
ancienne que --mesure-jours jours (100 par défaut) ; sans justification : environnement hors production permanent,
composant non critique dont la pointe reste sous --seuil (0,2 par défaut), composant critique de production à moins de
deux instances ; composant critique hors production.
Note seulement : composant de production sans mise à l'échelle automatique dont la pointe dépasse le double de la
moyenne.
Il ne dit pas que l'inventaire est complet, ni que la criticité est juste.
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-013"
ENVIRONNEMENTS = {"production", "preproduction", "test", "developpement"}
ECHELLE = {"automatique", "manuelle", "aucune"}
HORAIRES = {"permanent", "plage", "a-la-demande"}
OBLIGATOIRES = ("composant", "environnement", "raison", "critique_soin", "utilisation", "mise_a_echelle", "horaires",
"instances", "mesure_le")
def jour(v):
try:
return dt.date.fromisoformat(str(v))
except ValueError:
return None
def part(v):
return isinstance(v, (int, float)) and not isinstance(v, bool) and 0 <= v <= 1
def verifier(chemin, aujourdhui, seuil, mesure_jours):
refus, notes, vus, n = [], [], set(), 0
for num, ligne in enumerate(open(chemin, encoding="utf-8"), 1):
if not ligne.strip():
continue
try:
c = json.loads(ligne)
assert isinstance(c, dict)
except (ValueError, AssertionError):
refus.append(f"ligne {num} : objet JSON illisible")
continue
n += 1
nom = f"{c.get('composant') or 'ligne ' + str(num)} ({c.get('environnement')})"
manque = [k for k in OBLIGATOIRES if c.get(k) in (None, "")]
if manque:
refus.append(f"{nom} : champ(s) absent(s) : {', '.join(manque)}")
continue
if nom in vus:
refus.append(f"{nom} : composant en double")
vus.add(nom)
env, just = c["environnement"], c.get("justification")
for champ, liste in (("environnement", ENVIRONNEMENTS), ("mise_a_echelle", ECHELLE), ("horaires", HORAIRES)):
if c[champ] not in liste:
refus.append(f"{nom} : {champ} hors liste")
u = c["utilisation"] if isinstance(c["utilisation"], dict) else {}
moy, pte = u.get("moyenne"), u.get("pointe")
if not (part(moy) and part(pte)) or moy > pte:
refus.append(f"{nom} : utilisation illisible (moyenne et pointe entre 0 et 1, moyenne sous la pointe)")
moy = pte = None
m = jour(c["mesure_le"])
if m is None or (aujourdhui - m).days > mesure_jours:
refus.append(f"{nom} : mesure illisible ou plus ancienne que {mesure_jours} jours")
inst = c["instances"]
if not isinstance(inst, int) or isinstance(inst, bool) or inst < 1:
refus.append(f"{nom} : nombre d'instances illisible")
inst = None
critique = c["critique_soin"] is True
if critique and env != "production":
refus.append(f"{nom} : composant critique pour le soin hors production")
if env != "production" and c["horaires"] == "permanent" and not just:
refus.append(f"{nom} : environnement hors production permanent sans justification")
if not critique and pte is not None and pte < seuil and not just:
refus.append(f"{nom} : pointe d'utilisation sous {seuil} sans réduction ni justification")
if critique and env == "production" and inst is not None and inst < 2 and not just:
refus.append(f"{nom} : composant critique pour le soin sans redondance ni justification")
if env == "production" and c["mise_a_echelle"] != "automatique" and moy and pte and pte > 2 * moy:
notes.append(f"{nom} : charge variable sans mise à l'échelle automatique")
if n == 0:
refus.append("inventaire vide")
return refus, notes, n
def main(argv):
p = argparse.ArgumentParser(prog="verifier.py", description=__doc__.splitlines()[0])
p.add_argument("inventaire")
p.add_argument("--date", default=dt.date.today().isoformat())
p.add_argument("--seuil", type=float, default=0.2)
p.add_argument("--mesure-jours", type=int, default=100)
p.add_argument("--json", action="store_true")
try:
a = p.parse_args(argv)
aujourdhui = dt.date.fromisoformat(a.date)
except (SystemExit, ValueError):
return 2
try:
refus, notes, n = verifier(a.inventaire, aujourdhui, a.seuil, a.mesure_jours)
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, "composants": 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} composant(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:]))