bhf_smarthealth.validate.metadata_validation#

Attributes#

logger

ENVIRONMENT_ID_REGISTRY

Registry of accetable regex patterns for IDs to be processed per RONIN environment

Classes#

Functions#

extract_metadata_from_filename(→ FileMetadata)

Extracts Sheffield ID (sheffield_id) and date metadata from a structured filename.

validate_metadata(→ None)

Compare metadata extracted from a filename to its internal contents. Raised error will contain a list of errors found.

process_metadata(→ FileMetadata)

Orchestrator function to ensure than extract_metadata and validate_metadata are run together.

Module Contents#

bhf_smarthealth.validate.metadata_validation.logger#
bhf_smarthealth.validate.metadata_validation.ENVIRONMENT_ID_REGISTRY#

Registry of accetable regex patterns for IDs to be processed per RONIN environment

class bhf_smarthealth.validate.metadata_validation.FileMetadata[source]#
filename: str#
sheffield_id: str | None#
file_date: str | None#
validated: bool = False#
bhf_smarthealth.validate.metadata_validation.extract_metadata_from_filename(filepath: pathlib.Path) → FileMetadata[source]#

Extracts Sheffield ID (sheffield_id) and date metadata from a structured filename.

The function assumes the filename adheres to a specific format:

<userid>_<YYYYMMDD>_<activity>.<json>

Parameters:

filepath (Path) – Path to file to extract metadata from

Returns:

FileMetadata dataclass object. If metadata cannot be extracted, the sheffield_id and date will be returned as None.

Return type:

FileMetadata

bhf_smarthealth.validate.metadata_validation.validate_metadata(filepath: pathlib.Path, metadata: FileMetadata, dates: str | list[str], internal_id: str | None = None) → None[source]#

Compare metadata extracted from a filename to its internal contents. Raised error will contain a list of errors found.

Parameters:
  • filepath (Path) – Path to file being processed

  • metadata (FileMetadata) – FileMetadata object containing the filename and extracted sheffield_id and date

  • dates (str | list[str]) – A list of the dates, or datetimes, inside the file being processed to be validated against the FileMetadata.date extracted from the filename

Raises:

MetadataValidationError – Raised if validation checks fail. Raised message contains a list of all errors found.

bhf_smarthealth.validate.metadata_validation.process_metadata(filepath: pathlib.Path | str, dates: str | list[str], internal_id: str | None = None) → FileMetadata[source]#

Orchestrator function to ensure than extract_metadata and validate_metadata are run together.

Parameters:
  • filepath (Path | str) – Path to file to be processed

  • dates (str | list[str]) – A list of the dates, or datetimes, inside the file being processed to be validated against the FileMetadata.date extracted from the filename

Returns:

FileMetadata object containing validated metadata

Return type:

FileMetadata

Raises:

MetadataValidationError – Raised by validate_metadata if any validation checks fail