Skip to content

Commit

Permalink
Merge pull request #812 from salimkanoun/Salim
Browse files Browse the repository at this point in the history
debug auto query
  • Loading branch information
salimkanoun authored May 25, 2023
2 parents 1a11013 + 0d3b5ad commit 8008cc4
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 101 deletions.
1 change: 0 additions & 1 deletion FrontEnd/src/actions/ExportList.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export function addToExportList(seriesArray, studiesArray) {
export function addStudiesToExportList(studiesArray) {
return async function (dispatch) {
for (const studyObject of studiesArray) {
console.log(studyObject)
try {
let seriesInfo = await apis.content.getSeriesDetailsOfStudy(studyObject.StudyOrthancID)
let series = seriesInfo.map(series => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default ({ robotId }) => {
}))
)


if (isLoading) return <Spinner />

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export default () => {
try {
let answer = await apis.anon.createAnonRobot(listToAnonymize, store.username) //wait for the robot's answer to know what do to next
successMessage('Anonymization started')
console.log(answer)
} catch (error) {
errorMessage(error.statusText)
}
Expand Down
46 changes: 41 additions & 5 deletions FrontEnd/src/components/AutoQuery/AutoQueryRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,42 @@ import QueryRoot from './Query/QueryRoot'
import ResultsRoot from './Results/ResultsRoot'
import MyRobotRoot from './MyRobot/MyRobotRoot'
import RobotHistoryRoot from './RobotHistory/RobotHistoryRoot'
import { useSelector } from 'react-redux'
import apis from '../../services/apis'
import Spinner from '../CommonComponents/Spinner'
import { useCustomQuery } from '../../services/ReactQuery/hooks'
import { errorMessage } from '../../tools/toastify'
import { keys } from '../../model/Constant'


const MyRobotWrapper = () => {

const store = useSelector(state => {
return {
username: state.OrthancTools.username,
}
})

const { isLoading, data : retrieveId } = useCustomQuery(
[keys.ROBOTS_KEY, store.username, keys.AUTOQUERY_KEY],
() => apis.task.getTaskOfUser(store.username, 'retrieve'),
() => errorMessage('Failed to retrieve robot list'),
(retrieveIds) => {
if (retrieveIds.length > 0) {
return retrieveIds[0]
} else {
return null
}
}
)

if (isLoading) return <Spinner />
if (retrieveId == null) return <></>

return (
<MyRobotRoot robotId={retrieveId} />
)
}

export default () => {

Expand All @@ -19,10 +55,10 @@ export default () => {
case TAB_QUERIES:
return <QueryRoot onQueryFinished={() => setCurrentComponent(TAB_RESULTS)} />
case TAB_RESULTS:
return <ResultsRoot onRobotCreated={() => setCurrentComponent(TAB_MYROBOT)}/>
return <ResultsRoot onRobotCreated={() => setCurrentComponent(TAB_MYROBOT)} />
case TAB_MYROBOT:
return <MyRobotRoot/>
case TAB_ROBOT_HISTORY:
return <MyRobotWrapper />
case TAB_ROBOT_HISTORY:
return <RobotHistoryRoot />
default:
break
Expand All @@ -33,11 +69,11 @@ export default () => {
<div>
<div className='mb-5'>
<div className="d-flex justify-content-start align-items-center pb-3">
<i className={"fas fa-recycle icone ico me-3"}></i><h2 className="card-title">Auto Retrieve</h2>
<i className={"fas fa-recycle icone ico me-3"}></i><h2 className="card-title">Auto Retrieve</h2>
</div>
<nav className="otjs-navmenu container-fluid">
<div className="otjs-navmenu-nav">

<li>
<Button
className={currentComponent === TAB_QUERIES ? 'otjs-navmenu-nav-link link-button-active link-button' : 'otjs-navmenu-nav-link link-button'}
Expand Down
89 changes: 48 additions & 41 deletions FrontEnd/src/components/AutoQuery/MyRobot/MyRobotRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import React, { useEffect, useMemo, useState } from 'react'
import { useSelector } from 'react-redux'

import { CircularProgressbar, CircularProgressbarWithChildren, buildStyles } from 'react-circular-progressbar'
import { Container, Row } from 'react-bootstrap'
import { Col, Container, ListGroup, Row } from 'react-bootstrap'

import apis from '../../../services/apis'
import MyRobotTableStudies from './MyRobotTableStudies'
import MyRobotTableSeries from './MyRobotTableSeries'
import { errorMessage } from '../../../tools/toastify'

export const ITEM_SUCCESS = 'completed'
export const ITEM_AWAITING = 'wait'
export const ITEM_AWAITING = 'waiting'
export const ITEM_PENDING = 'active'
export const ITEM_FAILED = 'failed'
export const ITEM_DELAYED = 'delayed'
Expand All @@ -21,21 +22,14 @@ export const ROBOT_COMPLETED = 'completed'
export const LEVEL_STUDY = 'study'
export const LEVEL_SERIES = 'series'

export default () => {
export default ({ robotId }) => {

const store = useSelector(state => {
return {
username: state.OrthancTools.username,
}
})

const [id, setId] = useState(null)
const [projectName, setProjectName] = useState(null)
const [creator, setCreator] = useState(null)
const [valid, setValid] = useState(null)
const [approved, setApproved] = useState(null)
const [valid, setValid] = useState(false)
const [approved, setApproved] = useState(false)
const [rows, setRows] = useState([])

const [totalPercentageProgress, setTotalPercentageProgress] = useState(0)
const [percentageFailure, setPercentageFailure] = useState(0)

Expand All @@ -48,11 +42,8 @@ export default () => {
}, [])

const refreshInfo = async () => {
let retrieveIds = await apis.task.getTaskOfUser(store.username, 'retrieve')
if (retrieveIds.length > 0) {
let response = await apis.task.getTask(retrieveIds[0]);
refreshHandler(response)
}
let response = await apis.task.getTask(robotId);
refreshHandler(response)
}

const refreshHandler = (response) => {
Expand All @@ -62,7 +53,6 @@ export default () => {
let newPercentageFailure = 0

response.details.items.forEach(item => {

rowsRetrieveList.push({
//Merge Modalities (study level) to modality column
Modality: item.ModalitiesInStudy,
Expand Down Expand Up @@ -92,17 +82,17 @@ export default () => {
//SK ICI CHECKER LE ITEMID dans le backend (eviter position et remplacer par un ID (actuelement aswerId mais mauvaise idee car existe qu'une fois executee))
const retryQueryHandler = async (itemId) => {
try {
await apis.retrieveRobot.deleteRobotItem(robotId, itemId)
await apis.retrieveRobot.retryRobotItem(robotId, itemId)
} catch (error) {
errorMessage(error?.data?.errorMessage ?? 'Delete Failed')
errorMessage(error?.data?.errorMessage ?? 'Retry Failed')
}
}

const deleteQueryHandler = async (itemId) => {
try {
await apis.retrieveRobot.retryRobotItem(robotId, itemId)
await apis.retrieveRobot.deleteRobotItem(robotId, itemId)
} catch (error) {
errorMessage(error?.data?.errorMessage ?? 'Retry Failed')
errorMessage(error?.data?.errorMessage ?? 'Delete Failed')
}
}

Expand All @@ -117,38 +107,55 @@ export default () => {
return (
<Container fluid>
<Row>
<h1 className="col"> Robot for user {creator}, project : {projectName} </h1>
<div className="col-md-2 text-right">
<CircularProgressbarWithChildren
value={totalPercentageProgress}
text={`Progress : ${totalPercentageProgress}%`}
styles={buildStyles({
textSize: '10px'
})}
>
{/* Foreground path */}
<CircularProgressbar
value={percentageFailure}
<Col className='d-flex align-items-center justify-content-center'>
<ListGroup variant="flush">
<ListGroup.Item>Robot for user {creator}</ListGroup.Item>
<ListGroup.Item>Project : {projectName}</ListGroup.Item>
<ListGroup.Item>Valid : {valid.toString()}</ListGroup.Item>
<ListGroup.Item>Approved : {approved.toString()}</ListGroup.Item>
</ListGroup>
</Col>
<Col className='d-flex justify-content-center'>
<div style={{ maxWidth: "200px" }}>
<CircularProgressbarWithChildren
value={totalPercentageProgress}
text={`Progress : ${totalPercentageProgress}%`}
styles={buildStyles({
trailColor: "transparent",
pathColor: "#f00"
textSize: '10px',
})}
/>
</CircularProgressbarWithChildren>
</div>
>
{/* Foreground path */}
<CircularProgressbar
value={percentageFailure}
styles={buildStyles({
trailColor: "transparent",
pathColor: "#f00"
})}
/>
</CircularProgressbarWithChildren>
</div>
</Col>
</Row>
{
studiesRows.length > 0 ?
<Row className='mt-5'>
<MyRobotTableStudies robotId={id} rows={studiesRows} />
<MyRobotTableStudies
onRetryItem={(id) => retryQueryHandler(id)}
onDeleteItem={(id) => deleteQueryHandler(id)}
rows={studiesRows}
/>
</Row>
:
null
}
{
seriesRows.length > 0 ?
<Row className='mt-5'>
<MyRobotTableSeries robotId={id} rows={seriesRows} />
<MyRobotTableSeries
onRetryItem={(id) => retryQueryHandler(id)}
onDeleteItem={(id) => deleteQueryHandler(id)}
rows={seriesRows}
/>
</Row>
:
null
Expand Down
41 changes: 17 additions & 24 deletions FrontEnd/src/components/AutoQuery/MyRobot/MyRobotTableSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,28 @@ export default ({ rows = [], onSelectRow, onRetryItem, onDeleteItem }) => {
},
{
accessorKey: 'Status',
header: 'Status',
cell: ({ row, getValue }) => {
const value = getValue()
return (
<div className={'d-flex'}>
<p>{value}</p>
{value === 'failed' ?
<Button type={"button"}
onClick={() => onRetryItem(row.original.AnswerId)}>
<RepeatSVG />
</Button>
:
null}
</div>
)
}
header: 'Status'
},
{
accessorKey: 'Remove',
header: 'Remove Query',
accessorKey: 'Actions',
header: 'Actions',
cell: ({ row }) => {
return row.original.approved === false ?
(
<Button className='otjs-button otjs-button-red'
onClick={() => onDeleteItem(row.original.AnswerId)} >
const status = row.original.Status
return (
<>
<Button
disabled={status !== 'failed'}
onClick={() => onRetryItem(row.original.id)}>
<RepeatSVG />
</Button>
<Button
className='otjs-button otjs-button-red'
disabled={status !== 'waiting'}
onClick={() => onDeleteItem(row.original.id)} >
Remove
</Button>
)
: null
</>
)
}
},
{
Expand Down
45 changes: 20 additions & 25 deletions FrontEnd/src/components/AutoQuery/MyRobot/MyRobotTableStudies.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useMemo, useState } from 'react'
import { Button, Dropdown } from 'react-bootstrap';
import { useDispatch } from 'react-redux';

import CommonTableV8 from '../../CommonComponents/RessourcesDisplay/ReactTableV8/CommonTableV8';
import OhifLink from '../../Viewers/OhifLink';
Expand All @@ -10,6 +11,7 @@ import { ReactComponent as XSVG } from '../../../assets/images/x-circle.svg'
import { ReactComponent as PendingSVG } from '../../../assets/images/pending.svg'
import { ReactComponent as RepeatSVG } from '../../../assets/images/arrow-repeat.svg'
import { ITEM_SUCCESS } from './MyRobotRoot';
import ExportDeleteSendButton from '../../CommonComponents/RessourcesDisplay/ExportDeleteSendButton';

export default ({ rows = [], onRetryItem, onDeleteItem }) => {

Expand Down Expand Up @@ -60,35 +62,28 @@ export default ({ rows = [], onRetryItem, onDeleteItem }) => {
},
{
accessorKey: 'Status',
header: 'Status',
cell: ({ row, getValue }) => {
const value = getValue()
return (
<div className={'d-flex'}>
<p>{value}</p>
{value === 'failed' ?
<Button type={"button"}
onClick={() => onRetryItem(row.original.AnswerId)}>
<RepeatSVG />
</Button>
:
null}
</div>
)
}
header: 'Status'
},
{
accessorKey: 'Remove',
header: 'Remove Query',
accessorKey: 'Actions',
header: 'Actions',
cell: ({ row }) => {
return row.original.approved === false ?
(
<Button className='otjs-button otjs-button-red'
onClick={() => onDeleteItem(row.original.AnswerId)} >
const status = row.original.Status
return (
<>
<Button
disabled={status !== 'failed'}
onClick={() => onRetryItem(row.original.id)}>
<RepeatSVG />
</Button>
<Button
className='otjs-button otjs-button-red'
disabled={status !== 'waiting'}
onClick={() => onDeleteItem(row.original.id)} >
Remove
</Button>
)
: null
</>
)
}
},
{
Expand Down Expand Up @@ -163,7 +158,7 @@ export default ({ rows = [], onRetryItem, onDeleteItem }) => {


const selectedRowKey = useMemo(() => {
let selectedRows = rows.filter((row) => selectedRowsIds.includes(row.RetrievedOrthancId))
let selectedRows = rows.filter((row) => selectedRowIds.includes(row.RetrievedOrthancId))
return selectedRows.map(selectedRow => selectedRow.id)
}, [selectedRowIds.length])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export default () => {
})
});
}).catch(error => {
console.log(error)
if (error.status !== 404) errorMessage(error.statusText + ' ' + error.message)
}).finally(() => {
setRows(rows)
Expand Down
Loading

0 comments on commit 8008cc4

Please sign in to comment.