Skip to content

Commit

Permalink
Feat 239 LAS surgeries (#241)
Browse files Browse the repository at this point in the history
* auto-generated schemas and mappings

* nsp to las, basic mappings (WIP)

* updates sharepoint client

* adds las sharepoint response to server

---------

Co-authored-by: jtyoung84 <[email protected]>
  • Loading branch information
mekhlakapoor and jtyoung84 authored Jun 26, 2024
1 parent ead0745 commit 219bf20
Show file tree
Hide file tree
Showing 14 changed files with 3,887 additions and 48 deletions.
13 changes: 9 additions & 4 deletions src/aind_metadata_service/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,13 @@ async def retrieve_procedures(subject_id, pickle: bool = False):
subject_id=subject_id,
list_title=sharepoint_settings.nsb_2023_list,
)
las2020_response = await run_in_threadpool(
sharepoint_client.get_procedure_info,
subject_id=subject_id,
list_title=sharepoint_settings.las_2020_list,
)
merged_response = sharepoint_client.merge_responses(
[lb_response, sp2019_response, sp2023_response]
[lb_response, sp2019_response, sp2023_response, las2020_response]
)
# integrate TARS response
mapper = TarsResponseHandler()
Expand Down Expand Up @@ -295,9 +300,9 @@ async def retrieve_procedures(subject_id, pickle: bool = False):
# smartsheet_response = await retrieve_protocols(
# protocol_name=protocol_name
# )
protocols_mapping[
protocol_name
] = model_response.map_to_json_response()
protocols_mapping[protocol_name] = (
model_response.map_to_json_response()
)
integrated_response = protocols_integrator.integrate_protocols(
response=integrated_response, protocols_mapping=protocols_mapping
)
Expand Down
68 changes: 48 additions & 20 deletions src/aind_metadata_service/sharepoint/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
from pydantic_settings import BaseSettings

from aind_metadata_service.response_handler import ModelResponse, StatusCodes
from aind_metadata_service.sharepoint.las2020.procedures import (
LAS2020Procedures,
)
from aind_metadata_service.sharepoint.nsb2019.procedures import (
NSB2019Procedures,
)
Expand All @@ -22,21 +25,31 @@ class SharepointSettings(BaseSettings):
"""Settings needed to connect to Sharepoint database"""

nsb_sharepoint_url: str = Field(
title="Sharepoint URL", description="URL of the sharepoint lists."
title="NSB Sharepoint URL",
description="URL of the NSB sharepoint lists.",
)
las_sharepoint_url: str = Field(
title="LAS Sharepoint URL",
description="URL of the LAS sharepoint lists.",
)
nsb_2019_list: str = Field(
default="SWR 2019-2022",
title="NSB 2019 List",
description="List name for 2019 database.",
description="List name for Neurosurgery and Behavior 2019 database.",
)
nsb_2023_list: str = Field(
default="SWR 2023-Present",
title="NSB 2023 List",
description="List name for 2023 database.",
description="List name for Neurosurgery and Behavior 2023 database.",
)
nsb_sharepoint_user: str = Field(title="User", description="Username.")
nsb_sharepoint_password: SecretStr = Field(
title="Password", description="Password."
las_2020_list: str = Field(
default="NSPRequest2020",
title="LAS 2020 List",
description="List name for LAS Non-surgical Procedures 2020 database.",
)
sharepoint_user: str = Field(title="NSB User", description="NSB Username.")
sharepoint_password: SecretStr = Field(
title="NSB Password", description="Password."
)


Expand All @@ -46,45 +59,56 @@ class SharePointClient:
def __init__(
self,
nsb_site_url: str,
las_site_url: str,
client_id: str,
client_secret: str,
nsb_2019_list_title: str,
nsb_2023_list_title: str,
las_2020_list_title: str,
) -> None:
"""
Initialize a client
Parameters
----------
nsb_site_url : str
sharepoint site url
sharepoint site url for nsb procedures
las_site_url : str
sharepoint site url for las procedures
client_id : str
username for principal account to access sharepoint
client_secret : str
password for principal account to access sharepoint
nsb_2019_list_title : str
Title for 2019 list
Title for nsb 2019 list
nsb_2023_list_title : str
Title for 2023 list
Title for nsb 2023 list
las_2020_list_title : str
Title for las 2020 list
"""
self.nsb_site_url = nsb_site_url
self.client_id = client_id
self.client_secret = client_secret
self.credentials = ClientCredential(self.client_id, self.client_secret)
self.nsb_client_context = ClientContext(
self.nsb_site_url
).with_credentials(self.credentials)
self.nsb_site_url = nsb_site_url
self.las_site_url = las_site_url
self.nsb_2019_list_title = nsb_2019_list_title
self.nsb_2023_list_title = nsb_2023_list_title
self.las_2020_list_title = las_2020_list_title

def get_client_context(self, site_url):
"""Construct client context with principal account"""
return ClientContext(site_url).with_credentials(self.credentials)

@classmethod
def from_settings(cls, settings: SharepointSettings):
"""Construct client from settings object."""
return cls(
nsb_site_url=settings.nsb_sharepoint_url,
client_id=settings.nsb_sharepoint_user,
client_secret=settings.nsb_sharepoint_password.get_secret_value(),
las_site_url=settings.las_sharepoint_url,
client_id=settings.sharepoint_user,
client_secret=settings.sharepoint_password.get_secret_value(),
nsb_2019_list_title=settings.nsb_2019_list,
nsb_2023_list_title=settings.nsb_2023_list,
las_2020_list_title=settings.las_2020_list,
)

def get_procedure_info(
Expand All @@ -107,16 +131,20 @@ def get_procedure_info(
"""
try:
nsb_ctx = self.nsb_client_context
if list_title == self.nsb_2019_list_title:
ctx = self.get_client_context(site_url=self.nsb_site_url)
mapper = NSB2019Procedures()
elif list_title == self.nsb_2023_list_title:
ctx = self.get_client_context(site_url=self.nsb_site_url)
mapper = NSB2023Procedures()
elif list_title == self.las_2020_list_title:
ctx = self.get_client_context(site_url=self.las_site_url)
mapper = LAS2020Procedures()
else:
raise Exception(f"Unknown NSB Sharepoint List: {list_title}")
subj_procedures = mapper.get_procedures_from_sharepoint(
subject_id=subject_id,
client_context=nsb_ctx,
client_context=ctx,
list_title=list_title,
)
procedures = self._handle_response_from_sharepoint(
Expand Down Expand Up @@ -240,9 +268,9 @@ def _merge_two_responses(
)
else:
left_procedures: List[Procedures] = left_model_response.aind_models
right_procedures: List[
Procedures
] = right_model_response.aind_models
right_procedures: List[Procedures] = (
right_model_response.aind_models
)
procedures = self._merge_procedures(
left_procedures=left_procedures,
right_procedures=right_procedures,
Expand Down
1 change: 1 addition & 0 deletions src/aind_metadata_service/sharepoint/las2020/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Package for NSP (Non-surgical procedures) modules."""
Loading

0 comments on commit 219bf20

Please sign in to comment.