Skip to content

Commit

Permalink
Add support for metadata references (#25)
Browse files Browse the repository at this point in the history
* add support for metadata references

* add more documentation

* use same alias scheme as other models
  • Loading branch information
mochic authored Jul 25, 2024
1 parent 16c2004 commit 940803f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/aind_slims_api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from aind_slims_api.models.user import SlimsUser
from aind_slims_api.models.waterlog_result import SlimsWaterlogResult
from aind_slims_api.models.waterlog_water_restriction import SlimsWaterRestrictionEvent
from aind_slims_api.models.metadata import SlimsMetadataReference

__all__ = [
"SlimsAttachment",
Expand All @@ -20,4 +21,5 @@
"SlimsUser",
"SlimsWaterlogResult",
"SlimsWaterRestrictionEvent",
"SlimsMetadataReference",
]
46 changes: 46 additions & 0 deletions src/aind_slims_api/models/metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Models for the metadata stored in SLIMS."""
from pydantic import Field
from typing import Optional
from aind_slims_api.models.base import SlimsBaseModel


class SlimsMetadataReference(SlimsBaseModel):
"""Model for an instance of the metadata reference in SLIMS. Metadata
content is added to metadata references in the form of attachments.
Examples
--------
>>> from aind_slims_api import SlimsClient
>>> from aind_slims_api import models
>>> client = SlimsClient()
### Read
>>> metadata_reference = client.fetch_model(
... models.SlimsMetadataReference,
... name="323_EPHYS1_OPTO_20240212"
... )
>>> attachments = client.fetch_attachments(metadata_reference)
>>> metadata = client.fetch_attachment_content(attachments[0])
>>> metadata.json()["rig_id"]
'323_EPHYS1_OPTO_2024-02-12'
### Write
>>> import json
>>> attachment_pk = client.add_attachment_content(
... metadata_reference,
... "test_metadata_attachment_name",
... json.dumps({"rig_id": "323_EPHYS1_OPTO_2024-02-12"})
... )
"""

name: str = Field(
...,
serialization_alias="rdrc_name",
validation_alias="rdrc_name",
)
pk: Optional[int] = Field(
None,
serialization_alias="rdrc_pk",
validation_alias="rdrc_pk",
)
_slims_table = "ReferenceDataRecord"
1 change: 1 addition & 0 deletions src/aind_slims_api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"ContentEvent",
"Unit",
"Result",
"ReferenceDataRecord",
"Test",
"User",
"Groups",
Expand Down

0 comments on commit 940803f

Please sign in to comment.