Skip to content

Commit

Permalink
Merge pull request #850 from salimkanoun/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
salimkanoun authored Jun 29, 2023
2 parents c76ca66 + 3c153bf commit a916ac6
Show file tree
Hide file tree
Showing 19 changed files with 232 additions and 276 deletions.
8 changes: 2 additions & 6 deletions FrontEnd/src/components/Anonymize/Anonymize/AnonProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import { saveProfile } from '../../../actions/AnonList'

export default () => {

const store = useSelector(state => {
return {
profile: state.AnonList.profile
}
})
const profile = useSelector(state => state.AnonList.profile)

const dispatch = useDispatch()

Expand All @@ -22,7 +18,7 @@ export default () => {
const getProfileSelected = () => {
let index = -1
option.forEach(element => {
if (element.value === store.profile) {
if (element.value === profile) {
index = option.indexOf(element)
}
})
Expand Down
289 changes: 155 additions & 134 deletions FrontEnd/src/components/Anonymize/Anonymize/AnonymizePanel.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import React, { useMemo, useState } from "react"
import { useDispatch, useSelector } from "react-redux"
import { Button, Col, Container, Row } from 'react-bootstrap'
import React, { useMemo, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { Button, Col, Container, Row } from "react-bootstrap";

import apis from "../../../services/apis"
import AnonProfile from './AnonProfile'
import apis from "../../../services/apis";
import AnonProfile from "./AnonProfile";

import {
autoFill,
emptyAnonymizeList,
} from '../../../actions/AnonList'
import TableStudyAnonymize from "./TableStudyAnonymize"
import { errorMessage, successMessage } from "../../../tools/toastify"
import TablePatientAnonymize from "./TablePatientAnonymize"
import { autoFill, emptyAnonymizeList } from "../../../actions/AnonList";
import TableStudyAnonymize from "./TableStudyAnonymize";
import { errorMessage, successMessage } from "../../../tools/toastify";
import TablePatientAnonymize from "./TablePatientAnonymize";

/**
* This componnent wrapper allows to optimise the table by memoizing data
Expand All @@ -23,127 +20,151 @@ import TablePatientAnonymize from "./TablePatientAnonymize"
*/

export default () => {

const [currentPatient, setCurrentPatient] = useState('')
const [prefix, setPrefix] = useState('')

const dispatch = useDispatch()

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

const studiesData = useMemo(() => store.anonList
.filter(study => study.PatientOrthancID === currentPatient)
.map(study => ({
...study,
newStudyDescription: study.newStudyDescription ? study.newStudyDescription : study.StudyDescription,
newAccessionNumber: study.newAccessionNumber ? study.newAccessionNumber : 'OrthancToolsJS'
}))
, [store.anonList, currentPatient])

const testAllId = () => {
let answer = true
store.anonList.forEach((item) => {
if (item.ParentPatient.newPatientID === undefined)
answer = false
})
return answer
const [currentPatient, setCurrentPatient] = useState("");
const [prefix, setPrefix] = useState("");

const dispatch = useDispatch();

const anonList = useSelector((state) => state.AnonList.anonList);
const profile = useSelector((state) => state.AnonList.profile);
const username = useSelector((state) => state.OrthancTools.username);

const studiesData = useMemo(
() =>
anonList
.filter((study) => study.PatientOrthancID === currentPatient)
.map((study) => ({
...study,
newStudyDescription: study.newStudyDescription
? study.newStudyDescription
: study.StudyDescription,
newAccessionNumber: study.newAccessionNumber
? study.newAccessionNumber
: "OrthancToolsJS",
})),
[anonList.length, currentPatient]
);

const testAllId = () => {
let answer = true;
anonList.forEach((item) => {
if (item.ParentPatient.newPatientID === undefined) answer = false;
});
return answer;
};

const anonymize = async () => {
if (testAllId()) {
//check all id
let listToAnonymize = [];
anonList.forEach((element) => {
let anonItem = {
orthancStudyID: element.StudyOrthancID,
profile: profile,
newPatientName: element.ParentPatient.newPatientName,
newPatientID: element.ParentPatient.newPatientID,
newStudyDescription: element.newStudyDescription
? element.newStudyDescription
: element.StudyDescription,
newAccessionNumber: element.newAccessionNumber
? element.newAccessionNumber
: "OrthancToolsJS",
};

listToAnonymize.push(anonItem);
});

try {
await apis.anon.createAnonRobot(
listToAnonymize,
username
); //wait for the robot's answer to know what do to next
successMessage("Anonymization started");
} catch (error) {
errorMessage(error.statusText);
}
} else {
errorMessage("Fill all patient ID");
}

const anonymize = async () => {
if (testAllId()) { //check all id
let listToAnonymize = []
store.anonList.forEach(element => {
let anonItem = {
orthancStudyID: element.StudyOrthancID,
profile: store.profile,
newPatientName: element.ParentPatient.newPatientName,
newPatientID: element.ParentPatient.newPatientID,
newStudyDescription: element.newStudyDescription ? element.newStudyDescription : element.StudyDescription,
newAccessionNumber: element.newAccessionNumber ? element.newAccessionNumber : 'OrthancToolsJS'
}

listToAnonymize.push(anonItem)
})

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')
} catch (error) {
errorMessage(error.statusText)
};

const rowStyle = (PatientOrthancID) => {
if (PatientOrthancID === currentPatient) return { background: "peachPuff" };
};

const onChangePrefixHandler = (e) => {
setPrefix(e.target.value);
};

const onClickAutoFill = () => {
dispatch(autoFill(prefix));
};

const onClickEmpty = () => {
dispatch(emptyAnonymizeList());
};

return (
<Container fluid>
<Row className="mt-5">
<Col>
<TablePatientAnonymize
rowStyle={rowStyle}
setCurrentPatient={(PatientOrthancID) =>
setCurrentPatient(PatientOrthancID)
}

} else {
errorMessage('Fill all patient ID')
}
}

const rowStyle = (PatientOrthancID) => {
if (PatientOrthancID === currentPatient) return { background: 'peachPuff' }
}

const onChangePrefixHandler = (e) => {
setPrefix(e.target.value)
}

const onClickAutoFill = () => {
dispatch(autoFill(prefix))
}

const onClickEmpty = () => {
dispatch(emptyAnonymizeList())
}

return (
<Container fluid>
<Row className="mt-5">
<Col>
<TablePatientAnonymize rowStyle={rowStyle} setCurrentPatient={(PatientOrthancID) => setCurrentPatient(PatientOrthancID)} />

<Button className='otjs-button otjs-button-red mt-2 w-7'
onClick={onClickEmpty}>
Empty List
</Button>
</Col>
<Col>
<TableStudyAnonymize studies={studiesData} />
</Col>
</Row>

<Row className="mt-5">
<Col>
<Row className="align-items-center">
<Col sm={8}>
<input type='text' name='prefix' id='prefix' className='form-control'
placeholder='prefix'
onChange={onChangePrefixHandler} />
</Col>
<Col sm>
<Button variant='warning' className='otjs-button'
onClick={onClickAutoFill}>
AutoFill
</Button>
</Col>
</Row>
</Col>
<Col>
<AnonProfile />
</Col>
</Row>
<Row className="mt-4 border-top border-2 pt-4">
<Col className="text-center">
<Button className='otjs-button otjs-button-blue w-7'
onClick={() => anonymize()}>
Anonymize
</Button>
</Col>
</Row>
</Container>
)
}

/>

<Button
className="otjs-button otjs-button-red mt-2 w-7"
onClick={onClickEmpty}
>
Empty List
</Button>
</Col>
<Col>
<TableStudyAnonymize studies={studiesData} />
</Col>
</Row>

<Row className="mt-5">
<Col>
<Row className="align-items-center">
<Col sm={8}>
<input
type="text"
name="prefix"
id="prefix"
className="form-control"
placeholder="prefix"
onChange={onChangePrefixHandler}
/>
</Col>
<Col sm>
<Button
variant="warning"
className="otjs-button"
onClick={onClickAutoFill}
>
AutoFill
</Button>
</Col>
</Row>
</Col>
<Col>
<AnonProfile />
</Col>
</Row>
<Row className="mt-4 border-top border-2 pt-4">
<Col className="text-center">
<Button
className="otjs-button otjs-button-blue w-7"
onClick={() => anonymize()}
>
Anonymize
</Button>
</Col>
</Row>
</Container>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ export default ({ rowStyle, setCurrentPatient }) => {

const dispatch = useDispatch()

const store = useSelector(state => {
return {
anonList: state.AnonList.anonList,
}
})
const anonList = useSelector(state => state.AnonList.anonList)

const patients = useMemo(() => studyArrayToPatientArray(store.anonList), [store.anonList])
const patients = useMemo(() => studyArrayToPatientArray(anonList), [anonList.length])

const onRemovePatient = (PatientOrthancID) => {
dispatch(removePatientFromAnonList(PatientOrthancID))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ import { keys } from '../../../model/Constant'

export default () => {

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

const [currentTaskId, setCurrentTaskId] = useState(null)
const [successCount, setSuccesCount] = useState(0)
Expand All @@ -26,7 +22,7 @@ export default () => {
const [items, setItems] = useState([])

useEffect(() => {
apis.task.getTaskOfUser(store.username, 'anonymize').then(tasks => {
apis.task.getTaskOfUser(username, 'anonymize').then(tasks => {
if (Array.isArray(tasks) && tasks.length > 0) {
setCurrentTaskId(tasks[0])
}
Expand Down
10 changes: 3 additions & 7 deletions FrontEnd/src/components/AutoQuery/AutoQueryRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ import { keys } from '../../model/Constant'

const MyRobotWrapper = () => {

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

const { isLoading, data : retrieveId } = useCustomQuery(
[keys.ROBOTS_KEY, store.username, keys.AUTOQUERY_KEY],
() => apis.task.getTaskOfUser(store.username, 'retrieve'),
[keys.ROBOTS_KEY, username, keys.AUTOQUERY_KEY],
() => apis.task.getTaskOfUser(username, 'retrieve'),
() => errorMessage('Failed to retrieve robot list'),
(retrieveIds) => {
if (retrieveIds.length > 0) {
Expand Down
1 change: 0 additions & 1 deletion FrontEnd/src/components/AutoQuery/MyRobot/MyRobotRoot.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect, useMemo, useState } from 'react'
import { useSelector } from 'react-redux'

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

0 comments on commit a916ac6

Please sign in to comment.