Skip to content

Commit

Permalink
Fix 282 ghost procedures (#295)
Browse files Browse the repository at this point in the history
* returns none if no mapped procedures

* adds test case for no mapped las procs
  • Loading branch information
mekhlakapoor authored Nov 15, 2024
1 parent 96966fa commit 007c852
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 13 deletions.
19 changes: 11 additions & 8 deletions src/aind_metadata_service/sharepoint/las2020/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -2094,7 +2094,7 @@ def map_viral_materials(injectable_materials: List[InjectableMaterial]):
)
return viral_materials

def get_procedure(self, subject_id) -> Surgery:
def get_procedure(self, subject_id) -> Optional[Surgery]:
"""Return Surgery as best as possible from a record."""
subject_procedures = []
if self.has_ip_injection():
Expand All @@ -2118,10 +2118,13 @@ def get_procedure(self, subject_id) -> Surgery:
injection_materials=injection_materials,
)
subject_procedures.append(ro_injection)
return Surgery.model_construct(
experimenter_full_name=self.aind_author_id,
iacuc_protocol=self.aind_protocol,
start_date=self.aind_n_start_date,
end_date=self.aind_n_end_date,
procedures=subject_procedures,
)
if subject_procedures:
return Surgery.model_construct(
experimenter_full_name=self.aind_author_id,
iacuc_protocol=self.aind_protocol,
start_date=self.aind_n_start_date,
end_date=self.aind_n_end_date,
procedures=subject_procedures,
)
else:
return None
3 changes: 2 additions & 1 deletion src/aind_metadata_service/sharepoint/las2020/procedures.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ def get_procedures_from_sharepoint(
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)
if procedure:
list_of_procedures.append(procedure)
return list_of_procedures
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
null
250 changes: 250 additions & 0 deletions tests/resources/sharepoint/las2020/raw/list_item4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
{
"FileSystemObjectType": 0,
"Id": 6709,
"ServerRedirectedEmbedUri": null,
"ServerRedirectedEmbedUrl": "",
"ContentTypeId": "0x01005C6009AF417C4948814EADD3589ACE13",
"Title": "000000 000001",
"ComplianceAssetId": null,
"AuthorId": 5358,
"RequestStatus2": "New",
"Protocol": "2212 - Investigating Brain States",
"ProjectID": "AAV production 102-88-004-10",
"AccommodationComment": "This animal will be used for an acute ephys experiment on Friday morning.",
"ACSFID1": null,
"ACSFID2": null,
"ACSFID3": null,
"ACSFID4": null,
"ACSFID5": null,
"ACSFTime1": null,
"ACSFTime2": null,
"ACSFTime3": null,
"ACSFTime4": null,
"ACSFTime5": null,
"custcontact": null,
"CustomCom1": "Recover headpost, if possible.",
"CustomCom2": null,
"custpresent": false,
"doseduration": "30",
"doseRoute": "Intraperitoneal (IP)",
"doseSub": null,
"dosevolume": "70.4",
"doseWhere": null,
"Doxycycline": false,
"LTaID1": null,
"LTaID2": null,
"LTaID3": null,
"LTaID4": null,
"LTaID5": null,
"LTdate1": null,
"LTdate2": null,
"LTdate3": null,
"LTdate4": null,
"LTdate5": null,
"LTTask1": null,
"LTTask2": null,
"LTTask3": null,
"LTTask4": null,
"LTTask5": null,
"nEnd_x0020_Date": null,
"nROID1": "000000",
"nROID2": "000000",
"nROID3": "000001",
"nROID4": "000001",
"nROID5": "000001",
"nStart_x0020_Date": "2024-06-21T07:00:00Z",
"OCT": false,
"PostFix": "1xPBS+ 0.01%Azide",
"ReqAge1": null,
"ReqAge2": null,
"ReqAge3": null,
"Reqdate1": "2024-06-21T07:00:00Z",
"Reqdate2": null,
"Reqdate3": null,
"ReqPro1": "Tissue Collection",
"ReqPro2": null,
"ReqPro3": null,
"roEye1": "Behind Left",
"roEye2": "Behind Right",
"roEye3": "Behind Either",
"roEye4": null,
"roEye5": null,
"roSpinDown": "Yes",
"roSub1": "AiP12017",
"roSub2": "AiP1586",
"roSub3": "AiP12017",
"roSub4": "AiP12017",
"roSub5": "AiP1586",
"roVol1": "90",
"roVol2": "90 uL",
"roVol3": "89.9",
"roVol4": "90",
"roVol5": "90",
"roWhere": null,
"SpecDeliLoc": "Tissuecyte",
"TAM": false,
"TAMAge": null,
"TAMFreq": null,
"TCPrep": {
"0": "Mouse Cardiac Perfusion (SOP AF0075)"
},
"TCTiss": {
"0": "Brain"
},
"TMP": false,
"TMPAge": null,
"TMPFreq": null,
"LASComments": null,
"LIMSEntry": true,
"LIMSProject": "TempletonPsychedelics",
"LIMSWorkflow": "2p serial Imaging",
"roComment": null,
"ProjectLead2Id": 3212,
"ProjectLead2StringId": "3212",
"WellnessReport_x0028_No_x002F_Ye": false,
"QCDoorSheet": false,
"roIce": false,
"roSOP": null,
"roDiscard": true,
"roLIMS": null,
"icvID1": null,
"icvID2": null,
"icvID3": null,
"icvID4": null,
"icvID5": null,
"icvRoute1": null,
"icvRoute2": null,
"icvRoute3": null,
"icvRoute4": null,
"icvRoute5": null,
"icvSub1": null,
"icvSub2": null,
"icvSub3": null,
"icvSub4": null,
"icvSub5": null,
"WheretoObtainsubstance_x0028_ICV": null,
"Species": "Mouse",
"icvComment": null,
"Modified": "2024-05-20T18:28:26Z",
"icvLIMS": null,
"Created": "2024-05-13T17:59:22Z",
"LIMSWorkflow_x0020_2": null,
"OData__ColorTag": null,
"AfternoonPF": false,
"roSub1b": "AiP12017",
"roSub1c": "AiP12017",
"roSub1d": "AiP12017",
"roSub2b": null,
"roSub2c": null,
"roSub2d": null,
"roSub3b": null,
"roSub3c": null,
"roSub3d": null,
"roSub4b": null,
"roSub4c": null,
"roSub4d": null,
"roSub5b": null,
"roSub5c": null,
"roSub5d": null,
"roVolV1": null,
"roVolV1b": null,
"roVolV1c": null,
"roVolV1d": null,
"roVolV2": null,
"roVolV2b": null,
"roVolV2c": null,
"roVolV2d": null,
"roVolV3": null,
"roVolV3b": null,
"roVolV3c": null,
"roVolV3d": null,
"roVolV4": null,
"roVolV4b": null,
"roVolV4c": null,
"roVolV4d": null,
"roVolV5": null,
"roVolV5b": null,
"roVolV5c": null,
"roVolV5d": null,
"roTite1": "50",
"roTite1b": "50 gc/mL",
"roTite1c": null,
"roTite1d": null,
"roTite2": null,
"roTite2b": null,
"roTite2c": null,
"roTite2d": null,
"roTite3": null,
"roTite3b": null,
"roTite3c": null,
"roTite3d": null,
"roTite4": null,
"roTite4b": null,
"roTite4c": null,
"roTite4d": null,
"roTite5": null,
"roTite5b": null,
"roTite5c": null,
"roTite5d": null,
"roGC1": null,
"roGC1b": null,
"roGC1c": null,
"roGC1d": null,
"roGC2": null,
"roGC2b": null,
"roGC2c": null,
"roGC2d": null,
"roGC3": null,
"roGC3b": null,
"roGC3c": null,
"roGC3d": null,
"roGC4": null,
"roGC4b": null,
"roGC4c": null,
"roGC4d": null,
"roGC5": null,
"roGC5b": null,
"roGC5c": null,
"roGC5d": null,
"roLot1": "GT340C",
"roLot1b": null,
"roLot1c": null,
"roLot1d": null,
"roLot2": null,
"roLot2b": null,
"roLot2c": null,
"roLot2d": null,
"roLot3": null,
"roLot3b": null,
"roLot3c": null,
"roLot3d": null,
"roLot4": null,
"roLot4b": null,
"roLot4c": null,
"roLot4d": null,
"roLot5": null,
"roLot5b": null,
"roLot5c": null,
"roLot5d": null,
"roBox1": null,
"roBox2": null,
"roBox3": null,
"roBox4": null,
"roBox5": null,
"roTube1": "1",
"roTube2": "tube",
"roTube3": null,
"roTube4": null,
"roTube5": null,
"BCAge": null,
"BCGenotypes": null,
"BCType": null,
"BCVolume": null,
"BCTube": null,
"BCLocation": null,
"ID": 6709,
"EditorId": 538,
"OData__UIVersionString": "1.0",
"Attachments": false,
"GUID": "cd8a888b-4462-47e8-ba04-61e35515c697"
}
12 changes: 10 additions & 2 deletions tests/sharepoint/las2020/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,16 @@ def test_parser(self):
las_model = LASList.model_validate(raw_data)
mapper = MappedLASList(las=las_model)
mapped_procedure = mapper.get_procedure(subject_id="000000")
mapped_procedure_json = mapped_procedure.model_dump_json()
mapped_procedure_json_parsed = json.loads(mapped_procedure_json)
mapped_procedure_json = (
mapped_procedure.model_dump_json()
if mapped_procedure
else None
)
mapped_procedure_json_parsed = (
json.loads(mapped_procedure_json)
if mapped_procedure_json
else None
)
self.assertEqual(
expected_mapped_data, mapped_procedure_json_parsed
)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_response_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def test_multiple_items_response(self):
content=(
{
"message": f"Multiple Items Found. Validation Errors:"
f" {validation_error}, {validation_error}",
f" {validation_error}, {validation_error}",
"data": models_json,
}
),
Expand All @@ -239,7 +239,7 @@ def test_multiple_items_response_no_validation(self):
content=(
{
"message": "Multiple Items Found."
" Models have not been validated.",
" Models have not been validated.",
"data": models_json,
}
),
Expand Down

0 comments on commit 007c852

Please sign in to comment.