Audit trail#
session.store_backend is the session’s SQLite store. The methods below
read its audit rows and its flattened instance table. They are
documented but internal (see API stability). The words
in the rows are frozen. The methods that return them may change in a
minor 1.x release, never in a patch release, with a Breaking
CHANGELOG entry
(API stability). What
each action_type means is on
Analytics & Reporting.
- SqliteStore(db_path: str)#
The session’s SQLite store and pixel sidecar:
session.store_backend.It holds the Patient -> Study -> Series -> Instance hierarchy, the append-only
<name>_pixels.binsidecar, and the audit log, which a background thread writes.- get_audit_summary() Dict[str, int]#
Returns the number of audit rows for each action type.
Reads through the
flush_audit_queuebarrier, so every row enqueued before the call is counted.- Returns:
e.g., {‘REMEDIATION_REPLACE’: 1200, ‘EXPORT’: 1}
- Return type:
Dict[str, int]
- get_audit_errors() List[tuple]#
Every
ERRORandWARNINGaudit row, oldest first.Flushes the audit queue first, so every row enqueued before the call is included.
- Returns:
(timestamp, action_type, details)per row. It is empty if the query fails.- Return type:
List[tuple]
- get_audit_losses() List[tuple]#
Returns every
DATA_LOSSrow, with the scope that it was recorded under.This method is separate from
get_audit_errorsbecause the scopes grade differently. A loss scopedPRIVATEorSIGNALtakesvalidation_statustoREVIEW_REQUIRED. A loss scopedSTANDARDleaves it atPASS. Every loss is reported under “3.1 Data Loss”, never under “Exceptions & Errors”.A row whose
loss_scopeis NULL is older than the column and cannot be graded. Such a row is reported and left atPASS.- Returns:
(timestamp, entity_uid, details, loss_scope)
- Return type:
List[tuple]
- get_audit_declines() List[tuple]#
Every
REMEDIATION_DECLINEDrow: a value that the sweep left behind.A scan gap says that an element could not be read. A decline says that an element was read, that a remediation was proposed for it, and that the remediation did not run. So the value is still in the graph and will reach the exported file. The reason is in
details.Like every other audit reader, this method flushes the queue first, so a row still in the queue is counted.
- Returns:
(timestamp, entity_uid, details)
- Return type:
List[tuple]
- get_audit_scan_gaps() List[tuple]#
Every
SCAN_GAProw: an element that the PHI scan could not open.This method is separate from
get_audit_lossesbecause a scan gap is a different claim. A loss says that an element was dropped at ingest and cannot reach the output. A scan gap says that an element was kept whole and the scan could not read what is inside it.The row states only what ingest knew.
remove_private_tagsdecides later whether the element reaches the exported file, andgenerate_reportresolves that against the object graph.The result has no
loss_scopecolumn. Only an odd-group tag reaches the parse gate, so these rows are private by construction. The method selectselement_taginstead, which is NULL for a row written before that column existed.- Returns:
(timestamp, entity_uid, details, element_tag)
- Return type:
List[tuple]
- get_audit_drops() int#
The number of audit rows that a failed batch write dropped.
The rows themselves cannot be recovered, because a failed batch write loses them. A count above zero means that the audit table under-states what happened, and
generate_reportgrades such a count like an exception.Like every other audit reader, this method flushes the queue first, so a row still in the queue is counted if its write fails.
- Returns:
Rows dropped over this store object’s lifetime.
- Return type:
int
- get_flattened_instances(patient_ids: List[str] = None, instance_uids: List[str] = None, page_size: int = 500)#
An iterator of one flat dictionary per stored instance.
Use it to stream exports or analysis without loading the whole graph into RAM. The rows come back one page at a time, and no database handle is held between pages. So an iterator that is left part-consumed holds no lock and no read snapshot. This has two consequences:
Iteration is not one snapshot. Each page is its own query, so writes that land between pages are visible and rows deleted between pages are not returned.
Order is by
instances.id.
- Parameters:
patient_ids (Iterable[str], optional) – Restrict the rows to these Patient IDs. They are read the same way as every other
patient_idsin the package.Nonemeans every patient in the store. An empty iterable matches nobody, because it is a filter that selected nothing, not an absent filter. An iterator is read once, at the call. An ID that no patient holds is not counted here, unlike in theSessionmethods. The pages are separate reads, so there is no single moment at which an ID is or is not held.instance_uids (Iterable[str], optional) – Restrict the rows to these SOP Instance UIDs. The same rules apply:
Noneis no filter, and an empty iterable matches nobody. When both filters are given, the rows are their intersection.page_size (int, optional) – Rows per page. The default is 500. It trades resident memory against the number of queries. It must be an
int>= 1.
- Returns:
One dict per instance, keyed
patient_id,patient_name,study_instance_uid,study_date,series_instance_uid,modality,series_number,manufacturer,model_name,device_serial_number,sop_instance_uid,sop_class_uid,instance_number,file_path,pixel_offset,pixel_length,compress_algandattributes_json, with the values as stored.- Return type:
Iterator[dict]
- Raises:
ValueError – If
page_sizeis not a whole number >= 1. It is raised at the call, not on the firstnext().TypeError – If either filter is a bare
str, is bytes-like, is not iterable, or holds an element that is not astr. The message names such an element by position and type, never by value. It is raised at the call, andpage_sizeis checked first.