-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
241 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from pathlib import Path | ||
from typing import Dict | ||
|
||
import yaml | ||
from fastapi import APIRouter | ||
from starlette.responses import JSONResponse | ||
from medperf.commands.result.submit import ResultSubmission | ||
from medperf.entities.result import Result | ||
from medperf.web_ui.results import results | ||
|
||
_drafts_result_submit: dict[str, ResultSubmission] = {} | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.post("/result_submit_draft/generate/", response_class=JSONResponse) | ||
async def get_submission(result_id: str): | ||
submission = ResultSubmission(result_id, approved=False) | ||
_drafts_result_submit[result_id] = submission | ||
submission.get_result() | ||
return {"results": yaml.dump(submission.result.results)} | ||
|
||
|
||
@router.post("/result_submit_draft/submit/", response_class=JSONResponse) | ||
async def submit_result(result_id: str): | ||
submission = _drafts_result_submit[result_id] | ||
try: | ||
submission.approved = True | ||
updated_result_dict = submission.result.upload() | ||
# real result id is modified after submission, thus updating it | ||
submission.to_permanent_path(updated_result_dict) | ||
result = Result(**updated_result_dict) | ||
results[result_id] = result | ||
submission.write(updated_result_dict) | ||
return {"result_id": result_id} | ||
except Exception as e: | ||
return JSONResponse({"error": f"Error moving to operational state: {str(e)}"}, 400) | ||
|
||
|
||
@router.get("/result_submit_draft/decline", response_class=JSONResponse) | ||
async def decline_result_submit(result_id: str): | ||
del _drafts_result_submit[result_id] | ||
return {"result_id": result_id, "op_declined": True} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from pathlib import Path | ||
from typing import Dict | ||
|
||
from medperf import config | ||
from medperf.account_management import get_medperf_user_data | ||
from medperf.entities.result import Result | ||
|
||
results: Dict[str, Result] = {} | ||
|
||
|
||
def fetch_all_results() -> None: | ||
for result_dir in Path(Result.get_storage_path()).iterdir(): | ||
result_id = result_dir.name | ||
if result_dir.is_dir(): | ||
try: | ||
if result_id.isdigit(): | ||
result_id = int(result_id) | ||
# Retrieve the result using the result ID | ||
result = Result.get(result_id) | ||
result_str_bmd_name = result.local_id | ||
results[result_str_bmd_name] = result | ||
except Exception as e: | ||
config.ui.print_error(f"Error retrieving result for {result_id}: {e}") | ||
|
||
for result in Result.all( | ||
filters={"owner": get_medperf_user_data()["id"]} | ||
): | ||
result_str_bmd_name = result.local_id | ||
results[result_str_bmd_name] = result | ||
|
Oops, something went wrong.