Skip to content

Commit

Permalink
WIP what is even life
Browse files Browse the repository at this point in the history
  • Loading branch information
SeriousHorncat committed Dec 4, 2023
1 parent 43a5598 commit 48f1e46
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
24 changes: 13 additions & 11 deletions backend/src/routers/analysis_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,22 @@ def update_event(
except ValueError as exception:
raise HTTPException(status_code=409, detail=str(exception)) from exception

@router.post("/{analysis_name}/sections", response_model=Analysis)
@router.post("/{analysis_name}/sections", response_model=List[Section])
def add_analysis_section_content(
analysis_name: str,
type: SectionRowType,
updated_sections: List[Section],
upload_file: UploadFile = File(...),
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(type)
if(type == SectionRowType.TEXT):
update_analysis_sections_text_fields(analysis_name, updated_sections, repositories["analysis"])
return repositories["analysis"].find_by_name(analysis_name)
updated_analysis = repositories["analysis"].find_by_name(analysis_name)
updated_analysis_model = Analysis(**updated_analysis)
return updated_analysis_model.sections

section = updated_sections[0]

Expand All @@ -136,20 +138,20 @@ def add_analysis_section_content(
return repositories['analysis'].attach_section_supporting_evidence_file(
analysis_name, section.header, section.field_name, field_value_file
)
# TODO Verify what object type is being returned here, needs to be List[Section]

if(type ==SectionRowType.IMAGE):
repositories["analysis"].add_section_image(analysis_name, section.header, section.field_name, new_file_object_id)
return {'section': section.header, 'field': section.field_name, 'image_id': str(new_file_object_id)}
# TODO Verify what object type is being returned here, needs to be List[Section]

if( type == SectionRowType.LINK):
# section_name: str = Form(... field_name: str = Form(...),
link_name: str = Form(...),link: str = Form(...), comments: str = Form(...),

field_value_link = {"name": link_name, "data": link, "type": "link", "comments": comments}
field_value_link = {"name": section.value.name, "data": section.value.data, "type": "link", "comments": section.value.comments}

return repositories["analysis"].attach_section_supporting_evidence_link(
analysis_name, section_name, field_name, field_value_link
)
return repositories["analysis"].attach_section_supporting_evidence_link(
analysis_name, section.header, section.field_name, field_value_link
)
# TODO Verify what object type is being returned here, needs to be List[Section]

# UPDATE TO RETURN THAT IT IS AN INVALID TYPE THAT ISN"T SUPPORTED
print("ADDING TYPE NOT SUPPORTED YET, IN PROGRESS")
Expand Down Expand Up @@ -186,7 +188,7 @@ def add_file_to_bucket_repository(file_to_save, bucket_repository):
file_to_save.file, file_to_save.filename, file_to_save.content_type
)

def add_analysis_section_document_field(analysis_name, section_name, field_name, document_file, analysis_repository):
# def add_analysis_section_document_field(analysis_name, section_name, field_name, document_file, analysis_repository):

@router.put("/{analysis_name}/section/")
def attach_animal_model_system_report(
Expand Down
7 changes: 3 additions & 4 deletions backend/tests/integration/test_analysis_routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_update_analysis_section(client, mock_access_token, mock_repositories, u
]}, {
"header": "Medical Summary",
"content": [
{"fieldName": "Clinical Diagnosis", "value": ["Sed odio morbi quis commodo odio aenean sed. Hendrerit dolor magna eget lorem."]}
{"field_name": "Clinical Diagnosis", "value": ["Sed odio morbi quis commodo odio aenean sed. Hendrerit dolor magna eget lorem."]}
]}
]
mock_repositories["analysis"].collection.find_one.return_value = update_analysis_section_response_json
Expand All @@ -104,9 +104,8 @@ def test_update_analysis_section(client, mock_access_token, mock_repositories, u
json=updated_sections,
)
assert response.status_code == 200
mock_repositories["analysis"].collection.find_one_and_update.assert_called()
assert response.json()["name"] == "CPAM0047"
assert response.json()["sections"][0]["content"][1]["value"] == ["the quick brown fox jumps over the lazy dog."]
return_value = response.json()
assert return_value[0]["content"][1]["value"] == ["the quick brown fox jumps over the lazy dog."]


# We will come back to this later:
Expand Down

0 comments on commit 48f1e46

Please sign in to comment.