diff --git a/src/aind_metadata_service/server.py b/src/aind_metadata_service/server.py index 6904af15..1294013c 100644 --- a/src/aind_metadata_service/server.py +++ b/src/aind_metadata_service/server.py @@ -17,7 +17,6 @@ LabTracksClient, LabTracksSettings, ) - from aind_metadata_service.response_handler import EtlResponse from aind_metadata_service.sharepoint.client import ( SharePointClient, diff --git a/src/aind_metadata_service/sharepoint/las2020/mapping.py b/src/aind_metadata_service/sharepoint/las2020/mapping.py index 1bfc972e..c342afc1 100644 --- a/src/aind_metadata_service/sharepoint/las2020/mapping.py +++ b/src/aind_metadata_service/sharepoint/las2020/mapping.py @@ -3,19 +3,19 @@ from datetime import date, datetime from decimal import Decimal, DecimalException from enum import Enum -from typing import Any, Optional, List +from typing import Any, List, Optional from aind_data_schema.core.procedures import ( - Surgery, - Side, IntraperitonealInjection, RetroOrbitalInjection, + Side, + Surgery, ViralMaterial, ) from aind_metadata_service.sharepoint.las2020.models import ( - LASList, Doseroute, + LASList, Rosop, ) diff --git a/src/aind_metadata_service/sharepoint/las2020/procedures.py b/src/aind_metadata_service/sharepoint/las2020/procedures.py index f0252370..6094b160 100644 --- a/src/aind_metadata_service/sharepoint/las2020/procedures.py +++ b/src/aind_metadata_service/sharepoint/las2020/procedures.py @@ -32,18 +32,22 @@ def get_procedures_from_sharepoint( ------- List[SubjectProcedure] """ - labtrack_alias = LASList.model_fields.get("title").alias - filter_string = f"substringof('{subject_id}', {labtrack_alias})" + title_alias = LASList.model_fields.get("title").alias + filter_string = f"substringof('{subject_id}', {title_alias})" list_view = client_context.web.lists.get_by_title(list_title) - client_context.load(list_view) - client_context.execute_query() - list_items = list_view.get_items().filter(filter_string) - client_context.load(list_items) - client_context.execute_query() + list_items = ( + list_view.items.paged(True) + .top(100) + .get() + .filter(filter_string) + .execute_query() + ) list_of_procedures = [] for list_item in list_items: - las_model = LASList.model_validate(list_item.to_json()) - mapped_model = MappedLASList(las=las_model) - procedure = mapped_model.get_procedure(subject_id=subject_id) - list_of_procedures.append(procedure) + list_item_json = list_item.to_json() + if subject_id in list_item_json[title_alias].split(" "): + las_model = LASList.model_validate(list_item.to_json()) + mapped_model = MappedLASList(las=las_model) + procedure = mapped_model.get_procedure(subject_id=subject_id) + list_of_procedures.append(procedure) return list_of_procedures diff --git a/tests/sharepoint/test_client.py b/tests/sharepoint/test_client.py index b2b1e4fd..d8f18a69 100644 --- a/tests/sharepoint/test_client.py +++ b/tests/sharepoint/test_client.py @@ -262,14 +262,21 @@ def test_las_data_mapped(self, mock_sharepoint_client: MagicMock): ) mock_list_view = MagicMock() inner_mock.web.lists.get_by_title.return_value = mock_list_view - mock_list_items = MagicMock() - mock_list_view.get_items.return_value = mock_list_items + mock_l_items = MagicMock() + list_item_2020_1 = self.list_items_2020[0][0] mock_list_item2020 = MagicMock() mock_list_item2020.to_json.return_value = list_item_2020_1 - mock_list_items.filter.side_effect = [ + + mock_get = MagicMock() + mock_l_items.paged.return_value.top.return_value.get.return_value = ( + mock_get + ) + + mock_get.filter.return_value.execute_query.side_effect = [ [mock_list_item2020], ] + mock_list_view.items = mock_l_items client = SharePointClient( nsb_site_url="some_url", @@ -282,7 +289,7 @@ def test_las_data_mapped(self, mock_sharepoint_client: MagicMock): ) expected_subject_procedures = [self.list_items_2020[0][1]] response2020 = client.get_procedure_info( - subject_id="12345", list_title="some_list_title2020" + subject_id="000000", list_title="some_list_title2020" ) json_response = response2020.map_to_json_response() actual_content = json.loads(json_response.body.decode("utf-8"))