medmodels.medrecord.schema#

This module contains the schema classes for the medrecord module.

Classes

AttributeType(value[, names, module, ...])

Enumeration of attribute types.

AttributesSchema(attributes_schema)

A schema for a collection of attributes.

GroupSchema(*[, nodes, edges, strict])

A schema for a group of nodes and edges.

Schema(*[, groups, default, strict])

A schema for a collection of groups.

class AttributeType(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

Enumeration of attribute types.

Categorical = 1#
Continuous = 2#
Temporal = 3#
classmethod __contains__(value)#

Return True if value is in cls.

value is in cls if: 1) value is a member of cls, or 2) value is the value of one of the cls’s members.

__eq__(value)[source]#

Compares the AttributeType instance to another object for equality.

Parameters:

value (object) – The object to compare against.

Return type:

bool

Returns:

bool – True if the objects are equal, False otherwise.

classmethod __getitem__(name)#

Return the member matching name.

classmethod __iter__()#

Return members in definition order.

classmethod __len__()#

Return the number of members (no aliases)

__repr__()[source]#

Returns a string representation of the AttributeType instance.

Return type:

str

Returns:

str – String representation of the attribute type.

__str__()[source]#

Returns a string representation of the AttributeType instance.

Return type:

str

Returns:

str – String representation of the attribute type.

class AttributesSchema(attributes_schema)[source]#

Bases: object

A schema for a collection of attributes.

__contains__(key)[source]#

Checks if a given MedRecordAttribute is in the attributes schema.

Parameters:

key (MedRecordAttribute) – The attribute to check.

Return type:

bool

Returns:

bool – True if the attribute exists in the schema, False otherwise.

__eq__(value)[source]#

Compares the AttributesSchema instance to another object for equality.

Parameters:

value (object) – The object to compare against.

Return type:

bool

Returns:

bool – True if the objects are equal, False otherwise.

__getitem__(key)[source]#

Gets the type and optional attribute type for a given MedRecordAttribute.

Parameters:

key (MedRecordAttribute) – The attribute for which the data type is requested.

Return type:

Tuple[DataType, Optional[AttributeType]]

Returns:

Tuple[DataType, Optional[AttributeType]]

The data type and optional

attribute type of the given attribute.

__iter__()[source]#

Returns an iterator over the attributes schema.

Return type:

Iterator[Union[str, int]]

Returns:

Iterator – An iterator over the attribute keys.

__len__()[source]#

Returns the number of attributes in the schema.

Return type:

int

Returns:

int – The number of attributes.

__repr__()[source]#

Returns a string representation of the AttributesSchema instance.

Return type:

str

Returns:

str – String representation of the attribute schema.

get(key, default=None)[source]#

Gets the data type and optional attribute type for a given attribute.

It returns a default value if the attribute is not present.

Parameters:
  • key (MedRecordAttribute) – The attribute for which the data type is requested.

  • default (Optional[Tuple[DataType, Optional[AttributeType]]], optional) – The default data type and attribute type to return if the attribute is not found. Defaults to None.

Return type:

Optional[Tuple[DataType, Optional[AttributeType]]]

Returns:

Optional[Tuple[DataType, Optional[AttributeType]]]

The data type and

optional attribute type of the given attribute or the default value.

items()[source]#

Returns the attribute key-value pairs in the schema.

Returns:

ItemsView – A set-like object providing a view on D’s items.

keys()[source]#

Returns the attribute keys in the schema.

Returns:

KeysView – A view object displaying a list of dictionary’s keys.

values()[source]#

Returns the attribute values in the schema.

Returns:

ValuesView – A view object displaying a list of dictionary’s values.

class GroupSchema(*, nodes=None, edges=None, strict=False)[source]#

Bases: object

A schema for a group of nodes and edges.

property edges: AttributesSchema#

Returns the edge attributes in the GroupSchema instance.

Returns:

AttributesSchema

An AttributesSchema object containing the edge attributes

and their data types.

property nodes: AttributesSchema#

Returns the node attributes in the GroupSchema instance.

Returns:

AttributesSchema

An AttributesSchema object containing the node attributes

and their data types.

property strict: bool | None#

Indicates whether the GroupSchema instance is strict.

Returns:

Optional[bool] – True if the schema is strict, False otherwise.

class Schema(*, groups=None, default=None, strict=False)[source]#

Bases: object

A schema for a collection of groups.

property default: GroupSchema | None#

Retrieves the default group schema.

Returns:

Optional[GroupSchema]

The default group schema if it exists, otherwise

None.

group(group)[source]#

Retrieves the schema for a specific group.

Parameters:

group (Group) – The name of the group.

Return type:

GroupSchema

Returns:

GroupSchema – The schema for the specified group.

Raises:

ValueError – If the group does not exist in the schema.

property groups: List[str | int]#

Lists all the groups in the Schema instance.

Returns:

List[Group] – A list of groups.

property strict: bool | None#

Indicates whether the Schema instance is strict.

Returns:

Optional[bool] – True if the schema is strict, False otherwise.