Source code for imednet.models.records

# pylint: disable=duplicate-code
"""Record (eCRF instance) models for iMedNet."""

from __future__ import annotations

from typing import Any

from pydantic import Field, RootModel

from imednet.models.base import ImednetBaseModel
from imednet.models.engine import ModelEngine


class Keyword(ImednetBaseModel):
    """A keyword or tag associated with a record."""


Keyword = ModelEngine.get_model('Keyword', Keyword)


class Record(ImednetBaseModel):
    """A data record for a subject, form, and visit."""


Record = ModelEngine.get_model('Record', Record)


[docs]class RecordJobResponse(ImednetBaseModel): """Response for a record-related job (batch operations, etc).""" job_id: str = Field("", alias="jobId") batch_id: str = Field("", alias="batchId") state: str = Field("", alias="state")
[docs]class RecordData(RootModel[dict[str, Any]]): """Arbitrary record data as a dictionary."""
[docs]class BaseRecordRequest(ImednetBaseModel): """Base class for record creation/update requests.""" form_key: str = Field("", alias="formKey") data: RecordData = Field(default_factory=lambda: RecordData({}), alias="data")
[docs]class RegisterSubjectRequest(BaseRecordRequest): """Payload for registering (enrolling) a new subject. Per the API documentation, registering a subject only requires ``formKey`` and ``siteName``. The system assigns the subject identifier upon creation. Do **not** include a ``subjectKey`` here — doing so causes the server to treat the request as an update and reject it when the key is unknown. """ site_name: str = Field( "", alias="siteName", description="Name of the site where the subject is enrolled" )
[docs]class UpdateScheduledRecordRequest(BaseRecordRequest): """Payload for updating an existing scheduled record.""" subject_key: str = Field("", alias="subjectKey") interval_name: str = Field("", alias="intervalName")
[docs]class CreateNewRecordRequest(BaseRecordRequest): """Payload for creating a new unscheduled record.""" subject_key: str = Field("", alias="subjectKey")