Skip to content

Commit

Permalink
nothing runs and its in progress, but wanna keep this moment in time …
Browse files Browse the repository at this point in the history
…in tact
  • Loading branch information
SeriousHorncat committed Dec 4, 2023
1 parent b4fe33f commit 43a5598
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 106 deletions.
81 changes: 39 additions & 42 deletions backend/src/routers/analysis_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,26 +119,41 @@ def add_analysis_section_content(
print(type)
if(type == SectionRowType.TEXT):
update_analysis_sections_text_fields(analysis_name, updated_sections, repositories["analysis"])
elif( type == SectionRowType.IMAGE or type == SectionRowType.DOCUMENT):
return repositories["analysis"].find_by_name(analysis_name)

section = updated_sections[0]

if( type == SectionRowType.IMAGE or type == SectionRowType.DOCUMENT):
try:
new_object_id = add_file_to_bucket_repository(upload_file, repositories["bucket"])
new_file_object_id = add_file_to_bucket_repository(upload_file, repositories["bucket"])
except Exception as exception:
raise HTTPException(status_code=500, detail=str(exception)) from exception
field_value_file = {
"name": upload_file.filename, "attachment_id": str(new_file_object_id), "type": "file", "comments": "" #removed the comments attribute?
}

if(type == SectionRowType.DOCUMENT):
return repositories['analysis'].attach_section_supporting_evidence_file(
analysis_name, section.header, section.field_name, field_value_file
)

# adding supportin evidence file
# field_value_file = {
# "name": upload_file.filename, "attachment_id": str(new_file_object_id), "type": "file", "comments": comments
# }
#
# return repositories['analysis'].attach_section_supporting_evidence_file(
# analysis_name, section_name, field_name, field_value_file
# )
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)}

else:
print(type)
print("ADDING TYPE NOT SUPPORTED YET, IN PROGRESS")
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}

return repositories["analysis"].attach_section_supporting_evidence_link(
analysis_name, section_name, field_name, field_value_link
)

# UPDATE TO RETURN THAT IT IS AN INVALID TYPE THAT ISN"T SUPPORTED
print("ADDING TYPE NOT SUPPORTED YET, IN PROGRESS")

return repositories["analysis"].find_by_name(analysis_name)

@router.put("/{analysis_name}/sections", response_model=Analysis)
def update_analysis_section_content(
Expand Down Expand Up @@ -173,9 +188,10 @@ def add_file_to_bucket_repository(file_to_save, bucket_repository):

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

@router.put("/{analysis_name}/section/attach/file")
@router.put("/{analysis_name}/section/")
def attach_animal_model_system_report(
analysis_name: str,
type: SectionRowType,
section_name: str = Form(...),
field_name: str = Form(...),
comments: str = Form(...),
Expand All @@ -201,9 +217,10 @@ def attach_animal_model_system_report(
)


@router.put("/{analysis_name}/section/remove/file")
@router.delete("/{analysis_name}/section/{id}")
def remove_animal_model_system_report(
analysis_name: str,
type: SectionRowType,
section_name: str = Form(...),
field_name: str = Form(...),
attachment_id: str = Form(...),
Expand All @@ -218,27 +235,7 @@ def remove_animal_model_system_report(
return repositories['analysis'].remove_section_supporting_evidence(analysis_name, section_name, field_name)


@router.put("/{analysis_name}/section/attach/link")
def attach_animal_model_system_imaging(
analysis_name: str,
section_name: str = Form(...),
field_name: str = Form(...),
link_name: str = Form(...),
link: str = Form(...),
comments: str = Form(...),
repositories=Depends(database),
authorized=Security(get_authorization, scopes=["write"]) #pylint: disable=unused-argument
):
""" Attaches a link as supporting evidence to an analysis section """

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

return repositories["analysis"].attach_section_supporting_evidence_link(
analysis_name, section_name, field_name, field_value_link
)


@router.put("/{analysis_name}/section/remove/link")
@router.delete("/{analysis_name}/section") ## Links
def remove_animal_model_system_imaging(
analysis_name: str,
section_name: str = Form(...),
Expand Down Expand Up @@ -270,7 +267,7 @@ def download(analysis_name: str, file_name: str, repositories=Depends(database))
return StreamingResponse(repositories['bucket'].stream_analysis_file_by_id(file['attachment_id']))


@router.post("/{analysis_name}/section/attach/image")
@router.post("/{analysis_name}/section/image")
def attach_section_image(
response: Response,
analysis_name: str,
Expand Down Expand Up @@ -303,7 +300,7 @@ def attach_section_image(
return {'section': section_name, 'field': field_name, 'image_id': str(new_file_object_id)}


@router.put("/{analysis_name}/section/update/{old_file_id}")
@router.put("/{analysis_name}/section/{old_file_id}")
def update_analysis_section_image(
analysis_name: str,
old_file_id: str,
Expand All @@ -322,7 +319,7 @@ def update_analysis_section_image(
return {'section': section_name, 'field': field_name, 'image_id': str(new_file_id)}


@router.delete("/{analysis_name}/section/remove/{file_id}")
@router.delete("/{analysis_name}/section/{file_id}")
def remove_analysis_section_image(
analysis_name: str,
file_id: str,
Expand All @@ -343,7 +340,7 @@ def remove_analysis_section_image(
raise HTTPException(status_code=500, detail=str(exception)) from exception


@router.post("/{analysis_name}/attach/file")
@router.post("/{analysis_name}/attachment/file")
def attach_supporting_evidence_file(
analysis_name: str, upload_file: UploadFile = File(...), comments: str = Form(...), repositories=Depends(database)
):
Expand All @@ -358,7 +355,7 @@ def attach_supporting_evidence_file(
)


@router.post("/{analysis_name}/attach/link")
@router.post("/{analysis_name}/attachment/?=link")
def attach_supporting_evidence_link(
analysis_name: str,
link_name: str = Form(...),
Expand Down
130 changes: 66 additions & 64 deletions frontend/src/models/analyses.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,19 @@ export default {
return Requests.postForm(url, fileUploadFormData);
},

async getSectionImage(fileId) {
const url = `/rosalution/api/analysis/download/${fileId}`;
return await Requests.getImage(url);
},

async attachSectionImage(analysisName, sectionName, field, image) {
const url = `/rosalution/api/analysis/${analysisName}/section/attach/image`;
const url = `/rosalution/api/analysis/${analysisName}/section/?=image`;

const section = {
'header': sectionName,
'content': [],
};
section.content.push({
'field_name': field,
});
const attachmentForm = {
'upload_file': image,
'section_name': sectionName,
'field_name': field,
'updated_sections': [section],
};

return await Requests.postForm(url, attachmentForm);
Expand Down Expand Up @@ -114,6 +115,63 @@ export default {

return success;
},

Check failure on line 118 in frontend/src/models/analyses.js

View workflow job for this annotation

GitHub Actions / nodejs-ci (20.8)

Trailing spaces not allowed

Check failure on line 119 in frontend/src/models/analyses.js

View workflow job for this annotation

GitHub Actions / nodejs-ci (20.8)

Trailing spaces not allowed
async attachSectionSupportingEvidence(analysisName, section, field, evidence) {
let url = `/rosalution/api/analysis/${analysisName}/section?=`;

const sectionToUpdate = {
'header': section,
'content': [],
};

const attachmentForm = {
'updated_sections': [],
};

if (evidence.type == 'document') {
attachmentForm['upload_file'] = evidence.data,
sectionToUpdate.content.push({
'field_name': field,
'value': {
'comments': evidence.comments ? evidence.comments : ' ', /** Required for now, inserting empty string */
},
});
url += 'file';
} else if ( evidence.type == 'link') {
sectionToUpdate.content.push({
'field_name': field,
'value': {
'name': evidence.name,
'data': evidence.data,
'comments': evidence.comments ? evidence.comments : ' ', /** Required for now, inserting empty string */
},
});
url += 'link';
}

attachmentForm['updated_sections'].push(sectionToUpdate);

if (null == attachmentForm) {
throw new Error(`Evidence attachment ${evidence} type is invalid.`);
}

return await Requests.postForm(url, attachmentForm);
},

async removeSectionSupportingEvidenceFile(analysisName, section, field, attachmentId) {
const url = `/rosalution/api/analysis/${analysisName}/section/${section}/field/${field}/?type=document,id=${attachmentId}`;

Check failure on line 163 in frontend/src/models/analyses.js

View workflow job for this annotation

GitHub Actions / nodejs-ci (20.8)

This line has a length of 127. Maximum allowed is 120
const success = await Requests.delete(url);
return success;
},

async removeSectionSupportingEvidenceLink(analysisName, section, field) {
const url = `/rosalution/api/analysis/${analysisName}/section/${section}/field/${field}/?type=link`;

const success = await Requests.delete(url);
return success;
},
// ******************************* RENAME BELOW TO ATTACHMENTS FROM SUPPORTING EVIDENCE

async attachSupportingEvidence(analysisName, evidence) {
let attachmentForm = null;
Expand Down Expand Up @@ -172,62 +230,6 @@ export default {
};
return await Requests.putForm(url, attachmentForm);
},

async attachSectionSupportingEvidence(analysisName, section, field, evidence) {
let attachmentForm = null;
let url = `/rosalution/api/analysis/${analysisName}/section/attach`;

if (evidence.type == 'file') {
attachmentForm = {
'section_name': section,
'field_name': field,
'upload_file': evidence.data,
'comments': evidence.comments ? evidence.comments : ' ', /** Required for now, inserting empty string */
};
url += '/file';
} else if ( evidence.type == 'link') {
attachmentForm = {
'section_name': section,
'field_name': field,
'link_name': evidence.name,
'link': evidence.data,
'comments': evidence.comments ? evidence.comments : ' ', /** Required for now, inserting empty string */
};
url += '/link';
}

if (null == attachmentForm) {
throw new Error(`Evidence attachment ${evidence} type is invalid.`);
}

return await Requests.putForm(url, attachmentForm);
},

async removeSectionSupportingEvidenceFile(analysisName, section, field, attachmentId) {
const url = `/rosalution/api/analysis/${analysisName}/section/remove/file`;

const attachmentForm = {
'section_name': section,
'field_name': field,
'attachment_id': attachmentId,
};

const success = await Requests.putForm(url, attachmentForm);
return success;
},

async removeSectionSupportingEvidenceLink(analysisName, section, field) {
const url = `/rosalution/api/analysis/${analysisName}/section/remove/link`;

const attachmentForm = {
'section_name': section,
'field_name': field,
};

const success = await Requests.putForm(url, attachmentForm);
return success;
},

};

const annotationRenderingTemporary = [
Expand Down

0 comments on commit 43a5598

Please sign in to comment.