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

Task status check #136

Merged
merged 4 commits into from
Sep 13, 2023
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
17 changes: 16 additions & 1 deletion src/aind_metadata_service/labtracks/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,17 @@ class LabTracksProcedures(Enum):
RO_INJECTION = "RO Injection"


class LabTracksTaskStatuses(Enum):
"""LabTracks Task Status Options"""

FINISHED = "F"
SCHEDULED = "S"
CANCELLED = "C"
DELETED = "D"
ACCEPTED = "A"
DECLINED = "L"


class LabTracksResponseHandler:
"""This class will contain methods to handle the response from LabTracks"""

Expand Down Expand Up @@ -409,7 +420,11 @@ def map_response_to_procedures(
TaskSetQueryColumns.PROTOCOL_NUMBER.value
)
type_name = result.get(TaskSetQueryColumns.TYPE_NAME.value)
if type_name:
task_status = result.get(TaskSetQueryColumns.TASK_STATUS.value)
if (
type_name
and task_status == LabTracksTaskStatuses.FINISHED.value
):
if LabTracksProcedures.PERFUSION.value in type_name:
output_specimen_ids = [
result.get(TaskSetQueryColumns.TASK_OBJECT.value)
Expand Down
4 changes: 3 additions & 1 deletion src/aind_metadata_service/labtracks/query_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class TaskSetQueryColumns(Enum):
TASK_OBJECT = "task_object"
TYPE_NAME = "type_name"
PROTOCOL_NUMBER = "protocol_number"
TASK_STATUS = "task_status"


class LabTracksQueries:
Expand Down Expand Up @@ -62,7 +63,8 @@ def procedures_from_subject_id(subject_id: str) -> str:
f" {TaskSetQueryColumns.INVESTIGATOR_ID.value},"
f" TSO.TASK_OBJECT AS {TaskSetQueryColumns.TASK_OBJECT.value},"
f" AP.PROTOCOL_NUMBER AS "
f" {TaskSetQueryColumns.PROTOCOL_NUMBER.value}"
f" {TaskSetQueryColumns.PROTOCOL_NUMBER.value},"
f" TS.TASK_STATUS AS {TaskSetQueryColumns.TASK_STATUS.value}"
" FROM TASK_SET TS"
" INNER JOIN TASK_SET_OBJECT TSO "
" ON TS.ID = TSO.TASK_ID"
Expand Down
3 changes: 3 additions & 0 deletions tests/labtracks/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ class MockCursor:
["task_object"],
["type_name"],
["protocol_number"],
["task_status"],
]

@staticmethod
Expand All @@ -413,6 +414,7 @@ def fetchall():
decimal.Decimal("115977"),
"Perfusion",
decimal.Decimal("2002"),
"F",
],
[
decimal.Decimal("10000"),
Expand All @@ -423,6 +425,7 @@ def fetchall():
decimal.Decimal("115977"),
"RO Injection",
decimal.Decimal("2002"),
"F",
],
]

Expand Down
3 changes: 2 additions & 1 deletion tests/labtracks/test_query_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def test_procedures_from_id(self):
f" {TaskSetQueryColumns.INVESTIGATOR_ID.value},"
f" TSO.TASK_OBJECT AS {TaskSetQueryColumns.TASK_OBJECT.value},"
f" AP.PROTOCOL_NUMBER AS "
f" {TaskSetQueryColumns.PROTOCOL_NUMBER.value}"
f" {TaskSetQueryColumns.PROTOCOL_NUMBER.value},"
f" TS.TASK_STATUS AS {TaskSetQueryColumns.TASK_STATUS.value}"
" FROM TASK_SET TS"
" INNER JOIN TASK_SET_OBJECT TSO "
" ON TS.ID = TSO.TASK_ID"
Expand Down
13 changes: 13 additions & 0 deletions tests/labtracks/test_response_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ class TestResponseExamples:
"investigator_id": Decimal(28803),
"task_object": Decimal(115977),
"protocol_number": Decimal(2002),
"task_status": "F",
},
{
"id": Decimal(00000),
"task_type_id": Decimal(12345),
"type_name": "Perfusion Gel",
"date_start": datetime.datetime(2022, 10, 11, 0, 0),
"date_end": datetime.datetime(2022, 10, 11, 4, 30),
"investigator_id": Decimal(28803),
"task_object": Decimal(115977),
"protocol_number": Decimal(2002),
"task_status": "C",
},
{
"id": Decimal(10000),
Expand All @@ -99,6 +111,7 @@ class TestResponseExamples:
"investigator_id": Decimal(28803),
"task_object": Decimal(115977),
"protocol_number": Decimal(2002),
"task_status": "F",
},
]

Expand Down