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 |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ingestedint
Files read into the graph.
failuresList[Tuple[str, str]]
(path, reason)per rejected file, the same pair that itsERRORaudit row carries.declinedint
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
WARNINGaudit row and is not read into the store.skippedint
Files already in the store, not read again.
hiddenint
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.failedint
len(failures).- failures: List[Tuple[str, str]]#
(path, reason)per rejected file. It is the same pair that theERRORaudit 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_uidsList[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 infailurestoo, under that UID. When the volume resolves two file names to one file, one instance’s write replaces the other’s file (#1020). Fromsession.export(), the instance whose file was replaced is infailurestoo, and the instance that the file holds is here.failuresList[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.writtenint
Files that reached disk, counted over distinct UIDs. Two instances that share a UID write one file.
failedint
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
findingsList[PhiFinding]
The findings, one per report line.
failuresList[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, neverNone. The list fromaudit()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_uidstr
Unique identifier of the entity (PatientID, SOPInstanceUID).
entity_typestr
"Patient","Study","Series"or"Instance".field_namestr
The specific field or tag description.
valueAny
The PHI value found.
reasonstr
Why this was flagged (e.g. “Safe Harbor Rules”).
tagOptional[str]
The DICOM tag (e.g., “0010,0010”).
patient_idOptional[str]
Linkage for context.
entityAny
The live object in
session.storethe finding names, or None when it cannot be found.remediation_proposalOptional[PhiRemediation]
The suggested fix, which
anonymize()applies.metadataDict[str, Any]
Context carried with the finding.
entity_pathTuple
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_typestr
REMOVE_TAG,REPLACE_TAGorSHIFT_DATE.target_attrstr
The attribute or tag to modify.
new_valueAny
The proposed new value (if known).
original_valueAny
The original value for audit/reversion.
metadataDict[str, Any]
Context metadata (e.g. patient linkage for date shifting).
Identity locks#
- LockingResult(iterable=(), /)#
What
lock_identities()returns. It is alistof theInstanceobjects 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
RuntimeErrorsubclass, soexcept RuntimeErrorcatches it; its own class tells it from the export path’s bareRuntimeErrorexceptions, which mean nothing was written, where this means something unsafe is still in the graph.- Parameters:
failures (list) –
(entity_uid, details)pairs, kept asself.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, andWfdbExporter.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
ERRORrow keyedMULTIPLEsays 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, theEXPORTaudit row andDone.. The WFDB path has none of the first three. It raises after each record’sERRORorDATA_LOSSrow and its ownEXPORTrow.It is a
RuntimeErrorsubclass, soexcept RuntimeErrorcatches it.write_treeraises a bareRuntimeErrorinstead, for “this serializer could not write”.- Parameters:
failures (list) –
(entity_uid, details)per instance that failed. It is kept asself.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
Patientgraph 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
idkeyword:start_patient(id=...)raisesTypeError.name (str) – The Patient’s Name.
- Returns:
A builder for the new patient.
- Return type:
PatientBuilder