Skip to content
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
8 changes: 7 additions & 1 deletion src/aind_data_schema/core/procedures.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ def validate_subject_specimen_ids(self):
# Return if no specimen procedures
if self.specimen_procedures:
subject_id = self.subject_id
specimen_ids = [spec_proc.specimen_id for spec_proc in self.specimen_procedures]
specimen_id_vars = [spec_proc.specimen_id for spec_proc in self.specimen_procedures]
specimen_ids = []
for spec_id_var in specimen_id_vars:
if isinstance(spec_id_var, str):
specimen_ids.append(spec_id_var)
else:
specimen_ids.extend(spec_id_var)

if any(not subject_specimen_id_compatibility(subject_id, spec_id) for spec_id in specimen_ids):
raise ValueError("specimen_id must be an extension of the subject_id.")
Expand Down
19 changes: 19 additions & 0 deletions tests/test_procedures.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,25 @@ def test_validate_subject_specimen_ids(self):
expected_exception = "specimen_id must be an extension of the subject_id."
self.assertIn(expected_exception, str(e.exception))

def test_validate_subject_specimen_id_list_valid(self):
"""Test that specimen_id accepts a list of strings when all contain subject_id"""

valid_procedure = Procedures(
subject_id="12345",
specimen_procedures=[
SpecimenProcedure(
specimen_id=["12345_001", "12345_002"],
procedure_type="Other",
start_date=date.fromisoformat("2020-10-10"),
end_date=date.fromisoformat("2020-10-11"),
experimenters=["Mam Moth"],
protocol_id=["10"],
notes="some notes",
)
],
)
self.assertIsNotNone(valid_procedure)

def test_craniotomy_position_validation(self):
"""Test validation for craniotomy position"""

Expand Down
Loading