Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat 45 missing fields #46

Merged
merged 5 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/aind_slims_api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ def add_model(
exclude=fields_to_exclude,
**kwargs,
by_alias=True,
context="slims_post",
),
)
return type(model).model_validate(rtn)
Expand All @@ -377,9 +378,7 @@ def update_model(self, model: SlimsBaseModel, *args, **kwargs):
model._slims_table,
model.pk,
model.model_dump(
include=fields_to_include,
by_alias=True,
**kwargs,
include=fields_to_include, by_alias=True, **kwargs, context="slims_post"
),
)
return type(model).model_validate(rtn)
Expand Down
26 changes: 17 additions & 9 deletions src/aind_slims_api/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
import logging
from datetime import datetime
from typing import ClassVar, Optional

from pydantic import BaseModel, ValidationInfo, field_serializer, field_validator
from pydantic import (
BaseModel,
ValidationInfo,
field_serializer,
field_validator,
SerializationInfo,
)
from slims.internal import Column as SlimsColumn # type: ignore

from aind_slims_api.models.utils import _find_unit_spec
Expand Down Expand Up @@ -63,15 +68,18 @@ def _validate(cls, value, info: ValidationInfo):
return value

@field_serializer("*")
def _serialize(self, field, info):
"""Serialize a field, accounts for Quantities and datetime"""
def _serialize(self, field, info: SerializationInfo):
"""Serialize a field, accounts for Quantities and datetime."""
unit_spec = _find_unit_spec(self.model_fields[info.field_name])
if unit_spec and field is not None:
quantity = {
"amount": field,
"unit_display": unit_spec.preferred_unit,
}
return quantity
if info.context == "slims_post":
quantity = {
"amount": field,
"unit_display": unit_spec.preferred_unit,
}
return quantity
else:
return field
elif isinstance(field, datetime):
return int(field.timestamp() * 10**3)
else:
Expand Down
59 changes: 52 additions & 7 deletions src/aind_slims_api/models/ecephys_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ class SlimsGroupOfSessionsRunStep(SlimsExperimentRunStep):
serialization_alias="xprs_cf_activeMousePlatform",
validation_alias="xprs_cf_activeMousePlatform",
)
instrument_pk: Optional[int] = Field(
default=None,
serialization_alias="xprs_cf_fk_instrumentJson",
validation_alias="xprs_cf_fk_instrumentJson",
)
# TODO: add device calibrations once we have an example
# device_calibrations_attachment: Optional[str] = Field(
# default=None,
Expand Down Expand Up @@ -373,6 +378,26 @@ class SlimsEphysInsertionResult(SlimsBaseModel):
}


class SlimsInstrumentRdrc(SlimsBaseModel):
"""Model for Instrument Rdrc"""

pk: Optional[int] = Field(
default=None, serialization_alias="rdrc_pk", validation_alias="rdrc_pk"
)
name: Optional[str] = Field(
default=None, serialization_alias="rdrc_name", validation_alias="rdrc_name"
)
created_on: Optional[datetime] = Field(
default=None,
serialization_alias="rdrc_createdOn",
validation_alias="rdrc_createdOn",
)
_slims_table = "ReferenceDataRecord"
_base_fetch_filters: ClassVar[dict[str, str]] = {
"rdty_name": "AIND Instruments",
}


class SlimsDomeModuleRdrc(SlimsBaseModel):
"""Model for Dome Module Reference Data"""

Expand All @@ -392,15 +417,15 @@ class SlimsDomeModuleRdrc(SlimsBaseModel):
serialization_alias="rdrc_cf_probeName",
validation_alias="rdrc_cf_probeName",
)
primary_targeted_structure: Optional[str] = Field(
primary_targeted_structure_pk: Optional[int] = Field(
default=None,
serialization_alias="rdrc_cf_fk_primaryTargetedStructure_display",
validation_alias="rdrc_cf_fk_primaryTargetedStructure_display",
serialization_alias="rdrc_cf_fk_primaryTargetedStructure",
validation_alias="rdrc_cf_fk_primaryTargetedStructure",
)
secondary_targeted_structures: Optional[List] = Field(
secondary_targeted_structures_pk: Optional[List] = Field(
default=None,
serialization_alias="rdrc_cf_fk_secondaryTargetedStructures2_display",
validation_alias="rdrc_cf_fk_secondaryTargetedStructures2_display",
serialization_alias="rdrc_cf_fk_secondaryTargetedStructures",
validation_alias="rdrc_cf_fk_secondaryTargetedStructures",
)
arc_angle: Annotated[float | None, UnitSpec("degree", "°")] = Field(
default=None,
Expand Down Expand Up @@ -504,6 +529,26 @@ class SlimsDomeModuleRdrc(SlimsBaseModel):
}


class SlimsBrainStructureRdrc(SlimsBaseModel):
"""Model for Brain Structure Reference Data"""

pk: Optional[int] = Field(
default=None, serialization_alias="rdrc_pk", validation_alias="rdrc_pk"
)
name: Optional[str] = Field(
default=None, serialization_alias="rdrc_name", validation_alias="rdrc_name"
)
created_on: Optional[datetime] = Field(
default=None,
serialization_alias="rdrc_createdOn",
validation_alias="rdrc_createdOn",
)
_slims_table = "ReferenceDataRecord"
_base_fetch_filters: ClassVar[dict[str, str]] = {
"rdty_name": "CCF brain structures",
}


class SlimsFiberConnectionsRdrc(SlimsBaseModel):
"""Model for Fiber Connections Reference Data"""

Expand Down Expand Up @@ -539,7 +584,7 @@ class SlimsRewardDeliveryRdrc(SlimsBaseModel):

pk: Optional[int] = Field(serialization_alias="rdrc_pk", validation_alias="rdrc_pk")
reward_spouts_pk: Optional[int] = Field(
default=[],
default=None,
serialization_alias="rdrc_cf_fk_rewardSpouts",
validation_alias="rdrc_cf_fk_rewardSpouts",
)
Expand Down
Loading
Loading