Skip to content

pseudonymise

The pseudonymisation rule for the header of an EDF or EDF+ recording.

The rule rewrites three fields of the 256-byte fixed header and copies every other byte, so a file keeps its length, its signals and its time of day:

Bytes Field Becomes
8–87 local patient identification X X X X
88–167 local recording identification Startdate D X X X
168–175 start date 01.01.85 if dates are removed

Every field is padded with spaces to its width. D is the header's own start date subfield, written dd-MMM-yyyy, when dates are kept and that subfield is a valid date; otherwise it is X. With dates kept, the start date field is copied; with dates removed, it becomes 01.01.85, EDF+'s marker for an unknown date.

The rule is strict and small:

  • The header must be 256 bytes with version 0; anything else is refused.
  • D is kept only when the recording field's first subfield is exactly Startdate and the second is a real calendar date in the form dd-MMM-yyyy. The month is read in any case and written in upper case, as EDF+ requires. Any other recording field, including the free text of a plain EDF file, gives D = X; a kept date then stays in the start date field alone.
  • Bytes outside printable ASCII are not refused: the fields the rule writes are replaced whole, and every other byte is copied unchanged.
  • Applying the rule twice gives the same bytes as applying it once.

The cases in pseudonymisation_vectors.json, shipped beside this module, fix the rule's output for any implementation of it.

PSEUDONYMOUS_PATIENT = 'X X X X' module-attribute

The local patient identification after the rule: every EDF+ subfield unknown.

REMOVED_START_DATE = '01.01.85' module-attribute

The start date field after the rule, when dates are removed.

is_pseudonymised(fixed_header, *, keep_dates)

Whether an EDF fixed header already follows the pseudonymisation rule.

Parameters:

Name Type Description Default
fixed_header bytes

The first 256 bytes of an EDF or EDF+ file.

required
keep_dates bool

Whether the rule keeps the start date.

required

Returns:

Type Description
bool

True if applying the rule would change nothing.

Raises:

Type Description
ValueError

If fixed_header is not the fixed header of an EDF file.

pseudonymise_file_header(path, *, keep_dates)

Apply the pseudonymisation rule to the header of an EDF file, in place.

Only the first 256 bytes are read, and they are written back only if the rule changes them.

Parameters:

Name Type Description Default
path Path

The EDF or EDF+ file.

required
keep_dates bool

Keep the start date, or replace it with EDF+'s marker for an unknown date.

required

Returns:

Type Description
bool

True if the header was changed.

Raises:

Type Description
ValueError

If the file does not start with the fixed header of an EDF file.

pseudonymise_header(fixed_header, *, keep_dates)

Apply the pseudonymisation rule to an EDF fixed header.

Parameters:

Name Type Description Default
fixed_header bytes

The first 256 bytes of an EDF or EDF+ file.

required
keep_dates bool

Keep the start date, or replace it with EDF+'s marker for an unknown date.

required

Returns:

Type Description
bytes

The rewritten 256 bytes.

Raises:

Type Description
ValueError

If fixed_header is not the 256-byte fixed header of an EDF file with version 0.