Skip to content

Commit

Permalink
wip debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
SeriousHorncat committed Jan 22, 2024
1 parent 6f8ecd5 commit 2cfb3a7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
21 changes: 19 additions & 2 deletions backend/src/repository/analysis_collection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Collection with retrieves, creates, and modify analyses.
"""
import json
from typing import List
from uuid import uuid4

Expand Down Expand Up @@ -107,10 +108,26 @@ def update_analysis_nominator(self, analysis_name: str, nominator: str):
updated_analysis_document.pop("_id", None)
return updated_analysis_document

def update_analysis_sections(self, analysis_name: str, updated_sections: List[Section]):
def update_analysis_sections(self, analysis_name: str, updated_sections_json: List):
"""Updates each of the sections and fields within the sections if they exist in the database"""
for section in updated_sections:
# print("")
# print("the original")
print(type(updated_sections_json))
# print(updated_sections_json)
for section_str in updated_sections_json:
# print("in loop")
# print(section_str)
print(type(section_str))
print("what is going into the json loads")
print(section_str)
section_json = json.loads(section_str)
print(type(section_json))
print("what is the object of the result of json.loads")
# print(section_json)
section = Section(**section_json)
# print(section)
for field in section.content:

field_name, field_value = field["fieldName"], field["value"]
if "Nominator" == field_name:
self.update_analysis_nominator(analysis_name, '; '.join(field_value))
Expand Down
7 changes: 4 additions & 3 deletions backend/src/routers/analysis_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import List, Optional, Union

from fastapi import (
APIRouter, BackgroundTasks, Depends, HTTPException, File, status, UploadFile, Form, Response, Security
APIRouter, BackgroundTasks, Body, Depends, HTTPException, File, status, UploadFile, Form, Response, Security
)
from fastapi.responses import StreamingResponse

Expand Down Expand Up @@ -111,15 +111,16 @@ def update_event(
def update_analysis_sections(
analysis_name: str,
row_type: SectionRowType,
updated_sections: List = Form(...),
updated_sections: List[Section] = Body(...),
# upload_file: UploadFile = File(None),
repositories=Depends(database),
authorized=Security(get_authorization, scopes=["write"]) #pylint: disable=unused-argument
):
"""Updates the sections that have changes"""

print("UPDATING THE SECTIONS FROM THE SENT")
print(updated_sections)
print(type(updated_sections))

# print("Upload file exist?")
# print(upload_file)
if row_type == SectionRowType.TEXT:
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/integration/test_analysis_routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_import_analysis_with_phenotips_json(
def test_update_analysis_sections(client, mock_access_token, mock_repositories, cpam0047_analysis_json):
"""Testing if the update analysis endpoint updates an existing analysis"""

mock_updated_sections = [{
mock_updated_sections =[{
"header": "Brief",
"content": [{"fieldName": "Reason", "value": ["the quick brown fox jumps over the lazy dog."]},
{"fieldName": "Nominated", "value": ["Lorem ipsum dolor"]}]
Expand Down

0 comments on commit 2cfb3a7

Please sign in to comment.