care.emr.resources.base module

class EMRResource(*, meta: dict = {})

Bases: BaseModel

meta: dict
classmethod get_database_mapping()

Mapping of database fields to pydantic object

classmethod get_serializer_context(info)
classmethod perform_extra_serialization(mapping, obj, *args, **kwargs)
classmethod perform_extra_user_serialization(mapping, obj, user, *args, **kwargs)
is_update()
classmethod serialize(obj: None, user=None, *args, **kwargs)

Creates a pydantic object from a database object

get_context()
perform_extra_deserialization(is_update, obj)
de_serialize(obj=None, partial=False)

Creates a database object from a pydantic object

to_json()
classmethod serialize_audit_users(mapping, obj)
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'meta': FieldInfo(annotation=dict, required=False, default={})}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

class PeriodSpec(*, start: datetime | None = None, end: datetime | None = None)

Bases: BaseModel

start: datetime | None
end: datetime | None
validate_period()
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'end': FieldInfo(annotation=Union[datetime, NoneType], required=False, default=None), 'start': FieldInfo(annotation=Union[datetime, NoneType], required=False, default=None)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

model_string(model: Model) str

Returns a string representation of the model class.

e.g. “app_label.ModelName”

model_cache_key(db_model_name, model_name: str | None = None, pk: int | None = None) str

Generate a cache key for model data.

This function creates a standardized cache key format using database model name, model name and pk. The format is “db_model_name:pk:model_name” where pk and model_name are replaced with ‘*’ if not provided.

Parameters:
  • db_model_name – Name of the database model in format “app_label.ModelName”.

  • model_name (str | None) – Optional name of the model. Defaults to None.

  • pk (int | None) – Optional model ID. Defaults to None.

Returns:

Formatted cache key string in the format “db_model_name:id:model_name”

Return type:

str

Examples

>>> model_cache_key("emr.Patient", "BasicInfo", 123)
'serializers_cache:emr.Patient:123:BasicInfo'
>>> model_cache_key("emr.Doctor")
'serializers_cache:emr.Doctor:*:*'
model_from_cache(model: EMRResource, quiet=True, **kwargs) dict[str, Any] | None

Fetch a cacheable model instance from the cache or database.

cacheable(_model: EMRResource = None, use_base_manager=False) EMRResource

Decorator to mark a model as cacheable. This will set up the necessary signals to clear the cache when the model is saved or deleted, and will also set the __cacheable__ attribute to True on the model class

delete_model_cache(sender, instance, **kwargs) None

Signal handler to delete the cache for a model instance when it is saved or deleted.