Results and errors#

What the frozen Session methods return, and the two exceptions a caller is expected to catch. The names and fields on this page are frozen at 1.0 (API stability) unless the stability page lists them as tier 2.

Method

Returns

ingest()

IngestSummary

audit(), scan_pixel_content()

PhiReport of PhiFinding

lock_identities(), lock_identities_batch()

LockingResult, a list of Instance

recover_patient_identity()

Dict[str, Dict[str, Any]]: SOP Instance UID to the values its token holds

export(format="dicom")

ExportSummary

export(format="wfdb")

List[str], the paths written

discover_redaction_zones()

DiscoveryResult

get_cohort_report()

pandas.DataFrame

phi_status_summary()

Dict[str, Counter] of PhiStatus

redact(), reconcile_private_tags(), auto_remediate_config()

int

Import the two exceptions from the package: from isocenter import RedactionError, ExportError. Both subclass RuntimeError.

Summaries#

IngestSummary(ingested: int = 0, failures: List[Tuple[str, str]] = list(), declined: int = 0, skipped: int = 0, hidden: int = 0)#

What ingest() did with each file it found.

A file takes exactly one of five routes. A declined file is not recorded as imported, so a second offer of it declines it again.

Attributes:

Name

Type

Description

ingested

int

Files read into the graph.

failures

List[Tuple[str, str]]

(path, reason) per rejected file, the same pair that its ERROR audit row carries.

declined

int

Files refused because the session already holds their SOP Instance UID, as another instance’s UID or as a redacted instance’s UID before redaction. It also counts files whose Study Instance UID is held by a patient with a different Patient ID (#745). Each has a WARNING audit row and is not read into the store.

skipped

int

Files already in the store, not read again.

hidden

int

Files that the directory walk found whose name starts with . (.DS_Store, AppleDouble ._*). They are not read (#795). A directory whose name starts with . is walked, and a file named directly is read whatever its name.

failed

int

len(failures).

failures: List[Tuple[str, str]]#

(path, reason) per rejected file. It is the same pair that the ERROR audit row carries, so the summary and the trail cannot disagree.

property failed: int#

How many files were rejected.

ExportSummary(written_uids: List[str] = list(), failures: List[Tuple[str, str]] = list())#

What export(format="dicom") wrote, and what it did not.

Attributes:

Name

Type

Description

written_uids

List[str]

The SOP Instance UID of each instance that reached disk, and nothing else. An instance with no UID is not written and is in failures. An instance whose UID cannot name a file (export_file_name) is in failures too, under that UID. When the volume resolves two file names to one file, one instance’s write replaces the other’s file (#1020). From session.export(), the instance whose file was replaced is in failures too, and the instance that the file holds is here.

failures

List[Tuple[str, str]]

(entity_uid, details) per instance that did not reach disk, each with an audit row. The instances of one replaced file share one row, which names them all.

written

int

Files that reached disk, counted over distinct UIDs. Two instances that share a UID write one file.

failed

int

len(failures).

written_uids: List[str]#

SOP Instance UID of each instance that reached disk, and nothing else. A write needs the UID for its file meta, so an instance without one fails and is in failures, keyed UNKNOWN. It is never an output path, which names the Patient ID.

failures: List[Tuple[str, str]]#

(entity_uid, details) per instance that did not reach disk, already audited by _report_export_failures.

property written: int#

How many files reached disk.

It counts the de-duplicated UIDs. Two instances that share a UID write one file, and the second write replaces the first.

Returns:

The number of distinct written UIDs.

Return type:

int

property failed: int#

How many instances did not reach disk.

Findings#

PhiReport(findings: List[PhiFinding], failures: List[Tuple[str, str]] | None = None)#

A container for PHI findings that supports analysis and export.

A report works like the list of findings it wraps: you can iterate, index and measure it (len(report), report[0], for finding in report). It also adds DataFrame export.

Attributes:

Name

Type

Description

findings

List[PhiFinding]

The findings, one per report line.

failures

List[Tuple[str, str]]

(entity_uid, reason), one per instance that a pixel scan could not read in full. Either the instance’s pixels could not be loaded, or OCR raised on at least one of its frames. scan_pixel_content() fills it. An instance that failed on some frames keeps the findings of the frames that were read. It is always a list, never None. The list from audit() is always empty, because a failure in its workers raises instead.

to_dataframe()#

Convert the findings to a pandas DataFrame, one row each.

Returns:

A dataframe containing flattened finding details.

Return type:

pd.DataFrame

Raises:

ImportError – If pandas is not installed.

PhiFinding(entity_uid: str, entity_type: str, field_name: str, value: Any, reason: str, tag: str | None = None, patient_id: str | None = None, entity: Any = None, remediation_proposal: PhiRemediation | None = None, metadata: Dict[str, Any] = dict(), entity_path: Tuple = ())#

A potential PHI breach discovered during a scan: one report line.

Attributes:

Name

Type

Description

entity_uid

str

Unique identifier of the entity (PatientID, SOPInstanceUID).

entity_type

str

"Patient", "Study", "Series" or "Instance".

field_name

str

The specific field or tag description.

value

Any

The PHI value found.

reason

str

Why this was flagged (e.g. “Safe Harbor Rules”).

tag

Optional[str]

The DICOM tag (e.g., “0010,0010”).

patient_id

Optional[str]

Linkage for context.

entity

Any

The live object in session.store the finding names, or None when it cannot be found.

remediation_proposal

Optional[PhiRemediation]

The suggested fix, which anonymize() applies.

metadata

Dict[str, Any]

Context carried with the finding.

entity_path

Tuple

Route from the Instance to the item this was raised against, as (sequence_tag, index) steps. Empty means the Instance itself. It is the only way to rebind a finding to its sequence item after the finding crosses a process boundary.

PhiRemediation(action_type: str, target_attr: str, new_value: Any = None, original_value: Any = None, metadata: Dict[str, Any] = dict())#

Proposed action to fix a PHI finding.

Attributes:

Name

Type

Description

action_type

str

REMOVE_TAG, REPLACE_TAG or SHIFT_DATE.

target_attr

str

The attribute or tag to modify.

new_value

Any

The proposed new value (if known).

original_value

Any

The original value for audit/reversion.

metadata

Dict[str, Any]

Context metadata (e.g. patient linkage for date shifting).

Identity locks#

LockingResult(iterable=(), /)#

What lock_identities() returns. It is a list of the Instance objects that received an identity token. Its repr is one line (<LockingResult: N instances secured>), not every instance.

Exceptions#

RedactionError(failures, attempted)#

Redaction did not remove what it was asked to remove.

Raised after the whole pass, not at the first failure: the instances that could be redacted are redacted, and the failures are already in the audit log, so a caller that catches this still gets a compliance report that grades REVIEW_REQUIRED.

A RuntimeError subclass, so except RuntimeError catches it; its own class tells it from the export path’s bare RuntimeError exceptions, which mean nothing was written, where this means something unsafe is still in the graph.

Parameters:
  • failures (list) – (entity_uid, details) pairs, kept as self.failures.

  • attempted (int) – How many instances the pass targeted, kept as self.attempted.

ExportError(failures, attempted, folder=None)#

The export delivered nothing.

session.export() raises it when zero of N planned instances reached disk and at least one failed. This holds in both formats: the DICOM path, and WfdbExporter.export, where N is the waveform records attempted. The message says “instances” in both. A WFDB record is written from one waveform instance, and that instance’s UID names its failure, as for DICOM. It is not raised on a partial export.

One case leaves a file behind (#1020). In that case, every planned instance was written under file names that the volume resolved to one file, and that file could not be read back as any of them. No instance is reported as written, so this error is raised, and the folder holds that one file. The ERROR row keyed MULTIPLE says so.

It is raised last, after every record that the run produces. So a caller who catches it still holds a correct graph, a complete audit trail and a compliance report that grades REVIEW_REQUIRED. The DICOM path raises after the collision report, the recoverable-identity disclosure, the delivery counters, the EXPORT audit row and Done.. The WFDB path has none of the first three. It raises after each record’s ERROR or DATA_LOSS row and its own EXPORT row.

It is a RuntimeError subclass, so except RuntimeError catches it. write_tree raises a bare RuntimeError instead, for “this serializer could not write”.

Parameters:
  • failures (list) – (entity_uid, details) per instance that failed. It is kept as self.failures.

  • attempted (int) – How many instances were planned. It is kept as self.attempted.

  • folder (str, optional) – The output folder, named in the message.

Building a graph by hand#

isocenter.Builder is the frozen name of the class below. Only start_patient() is frozen, and the chain it starts is tier 2.

Builder#

DicomBuilder#

Build a Patient graph by hand, with no files behind it.

Import it as from isocenter import Builder:

patient = (Builder.start_patient("P123", "Doe^John")
           .add_study("1.2.3", "20240101")
           .add_series("1.2.3.1", "CT", 1)
           .end_series().end_study().build())
static start_patient(patient_id, name)#

Begin building a Patient.

Parameters:
  • patient_id (str) – The Patient ID. There is no id keyword: start_patient(id=...) raises TypeError.

  • name (str) – The Patient’s Name.

Returns:

A builder for the new patient.

Return type:

PatientBuilder