14.1.20. crate_anon.anonymise.patient

crate_anon/anonymise/patient.py


Copyright (C) 2015, University of Cambridge, Department of Psychiatry. Created by Rudolf Cardinal (rnc1001@cam.ac.uk).

This file is part of CRATE.

CRATE is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

CRATE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with CRATE. If not, see <https://www.gnu.org/licenses/>.


Patient class for CRATE anonymiser. Represents patient-specific information like ID values and scrubbers.

class crate_anon.anonymise.patient.Patient(pid: int | str, debug: bool = False)[source]

Class representing a patient with patient-specific information, such as PIDs, RIDs, and scrubbers.

__init__(pid: int | str, debug: bool = False) None[source]

Build the scrubber based on data dictionary information, found via our singleton crate_anon.anonymise.config.Config.

Parameters:
  • pid – integer or string (usually integer) patient identifier

  • debug – turn on scrubber debugging?

is_unchanged() bool[source]

Has the scrubber changed, compared to the previous hashed version in the admin database?

property mandatory_scrubbers_unfulfilled: AbstractSet[str]

Returns a set of strings (each of the format db.table.column) for all “required scrubber” fields that have not yet had information seen for them (for this patient), and are therefore unfulfilled.

See also crate_anon.anonymise.dd.DataDictionary.get_mandatory_scrubber_sigs().

property mpid: int | str

Return the master patient ID (MPID).

property mrid: str

Returns the master RID (encrypted MPID).

property pid: int | str

Return the patient ID (PID).

property rid: str

Returns the RID (encrypted PID).

scrub(text: str) str[source]

Use our scrubber to scrub text.

Parameters:

text – the raw text, potentially containing sensitive information

Returns:

the de-identified text

property scrubber_hash: str

Return the hash of our scrubber (for change detection).

set_mpid(mpid: int | str) None[source]

Set the patient MPID.

property trid: int

Returns the transient integer RID (TRID).

crate_anon.anonymise.patient.gen_all_values_for_patient(session: Session, tablename: str, scrub_src_fieldinfo: List[ScrubSourceFieldInfo], pid_field: str, pid: int | str) Generator[List[Any], None, None][source]

Generate all sensitive (scrub_src) values for a given patient, from a given source table. Used to build the scrubber.

Parameters:
  • session – database session

  • tablename – source table

  • scrub_src_fieldinfo – list of information about the scrub-source fields

  • pid_field – field to query for patient ID

  • pid – patient ID

Yields:

rows, where each row is a list of values that matches scrub_src_fieldinfo.