From 1f322b4edb5396af2cfc4a625fd55e96056a78bf Mon Sep 17 00:00:00 2001 From: Mekhla Kapoor <54870020+mekhlakapoor@users.noreply.github.com> Date: Tue, 12 Sep 2023 16:34:08 -0700 Subject: [PATCH 1/4] checks task status --- src/aind_metadata_service/labtracks/client.py | 18 +++++++++++++++++- .../labtracks/query_builder.py | 4 +++- tests/labtracks/test_query_builder.py | 3 ++- tests/labtracks/test_response_handler.py | 13 +++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/aind_metadata_service/labtracks/client.py b/src/aind_metadata_service/labtracks/client.py index eb37c528..8908ab7f 100644 --- a/src/aind_metadata_service/labtracks/client.py +++ b/src/aind_metadata_service/labtracks/client.py @@ -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""" @@ -409,7 +420,12 @@ 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 not in [ + LabTracksTaskStatuses.Cancelled.value, + LabTracksTaskStatuses.Deleted.value, + LabTracksTaskStatuses.Declined.value, + ]: if LabTracksProcedures.PERFUSION.value in type_name: output_specimen_ids = [ result.get(TaskSetQueryColumns.TASK_OBJECT.value) diff --git a/src/aind_metadata_service/labtracks/query_builder.py b/src/aind_metadata_service/labtracks/query_builder.py index b6bb7928..c4cd9fa2 100644 --- a/src/aind_metadata_service/labtracks/query_builder.py +++ b/src/aind_metadata_service/labtracks/query_builder.py @@ -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: @@ -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" diff --git a/tests/labtracks/test_query_builder.py b/tests/labtracks/test_query_builder.py index f6bba4b7..9e69117b 100644 --- a/tests/labtracks/test_query_builder.py +++ b/tests/labtracks/test_query_builder.py @@ -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" diff --git a/tests/labtracks/test_response_handler.py b/tests/labtracks/test_response_handler.py index 856cfa1d..c2a36867 100644 --- a/tests/labtracks/test_response_handler.py +++ b/tests/labtracks/test_response_handler.py @@ -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), @@ -99,6 +111,7 @@ class TestResponseExamples: "investigator_id": Decimal(28803), "task_object": Decimal(115977), "protocol_number": Decimal(2002), + "task_status": "F", }, ] From b5fc6fa6ede30983c6e30bc3f748dbbaa797c425 Mon Sep 17 00:00:00 2001 From: Mekhla Kapoor <54870020+mekhlakapoor@users.noreply.github.com> Date: Tue, 12 Sep 2023 16:57:43 -0700 Subject: [PATCH 2/4] finished only --- src/aind_metadata_service/labtracks/client.py | 6 +----- tests/labtracks/test_client.py | 3 +++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/aind_metadata_service/labtracks/client.py b/src/aind_metadata_service/labtracks/client.py index 8908ab7f..d4a23fc3 100644 --- a/src/aind_metadata_service/labtracks/client.py +++ b/src/aind_metadata_service/labtracks/client.py @@ -421,11 +421,7 @@ def map_response_to_procedures( ) type_name = result.get(TaskSetQueryColumns.TYPE_NAME.value) task_status = result.get(TaskSetQueryColumns.TASK_STATUS.value) - if type_name and task_status not in [ - LabTracksTaskStatuses.Cancelled.value, - LabTracksTaskStatuses.Deleted.value, - LabTracksTaskStatuses.Declined.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) diff --git a/tests/labtracks/test_client.py b/tests/labtracks/test_client.py index 364d5c8d..ae2b0719 100644 --- a/tests/labtracks/test_client.py +++ b/tests/labtracks/test_client.py @@ -393,6 +393,7 @@ class MockCursor: ["task_object"], ["type_name"], ["protocol_number"], + ["task_status"] ] @staticmethod @@ -413,6 +414,7 @@ def fetchall(): decimal.Decimal("115977"), "Perfusion", decimal.Decimal("2002"), + "F" ], [ decimal.Decimal("10000"), @@ -423,6 +425,7 @@ def fetchall(): decimal.Decimal("115977"), "RO Injection", decimal.Decimal("2002"), + "F" ], ] From 1d92690b25b9ee9c7b6996c6ca8c1da71e8b0fd0 Mon Sep 17 00:00:00 2001 From: Mekhla Kapoor <54870020+mekhlakapoor@users.noreply.github.com> Date: Wed, 13 Sep 2023 10:22:14 -0700 Subject: [PATCH 3/4] caps --- src/aind_metadata_service/labtracks/client.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/aind_metadata_service/labtracks/client.py b/src/aind_metadata_service/labtracks/client.py index d4a23fc3..32a0596b 100644 --- a/src/aind_metadata_service/labtracks/client.py +++ b/src/aind_metadata_service/labtracks/client.py @@ -214,12 +214,12 @@ class LabTracksProcedures(Enum): class LabTracksTaskStatuses(Enum): """LabTracks Task Status Options""" - Finished = "F" - Scheduled = "S" - Cancelled = "C" - Deleted = "D" - Accepted = "A" - Declined = "L" + FINISHED = "F" + SCHEDULED = "S" + CANCELLED = "C" + DELETED = "D" + ACCEPTED = "A" + DECLINED = "L" class LabTracksResponseHandler: From e8e14fbfd1a8b12848d2dc6b7ca9b679b5ea8b4c Mon Sep 17 00:00:00 2001 From: Mekhla Kapoor <54870020+mekhlakapoor@users.noreply.github.com> Date: Wed, 13 Sep 2023 10:50:11 -0700 Subject: [PATCH 4/4] test fix --- src/aind_metadata_service/labtracks/client.py | 5 ++++- tests/labtracks/test_client.py | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/aind_metadata_service/labtracks/client.py b/src/aind_metadata_service/labtracks/client.py index 32a0596b..fe706140 100644 --- a/src/aind_metadata_service/labtracks/client.py +++ b/src/aind_metadata_service/labtracks/client.py @@ -421,7 +421,10 @@ def map_response_to_procedures( ) type_name = result.get(TaskSetQueryColumns.TYPE_NAME.value) task_status = result.get(TaskSetQueryColumns.TASK_STATUS.value) - if type_name and task_status == LabTracksTaskStatuses.Finished.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) diff --git a/tests/labtracks/test_client.py b/tests/labtracks/test_client.py index ae2b0719..634abbaa 100644 --- a/tests/labtracks/test_client.py +++ b/tests/labtracks/test_client.py @@ -393,7 +393,7 @@ class MockCursor: ["task_object"], ["type_name"], ["protocol_number"], - ["task_status"] + ["task_status"], ] @staticmethod @@ -414,7 +414,7 @@ def fetchall(): decimal.Decimal("115977"), "Perfusion", decimal.Decimal("2002"), - "F" + "F", ], [ decimal.Decimal("10000"), @@ -425,7 +425,7 @@ def fetchall(): decimal.Decimal("115977"), "RO Injection", decimal.Decimal("2002"), - "F" + "F", ], ]