-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #309 from Pixilib/dev
Dev
- Loading branch information
Showing
12 changed files
with
363 additions
and
112 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,113 @@ | ||
/** | ||
* Component for a modal to preview a study | ||
* @name PreviewStudy | ||
*/ | ||
|
||
import React, { useState } from "react"; | ||
import { getSeriesOfStudy } from "../../services/orthanc"; | ||
import { Colors, useCustomMutation, useCustomQuery, useCustomToast } from "../../utils"; | ||
|
||
import { Button, Modal, ProgressCircle, Spinner } from "../../ui"; | ||
import { ProcessingJob, Series } from "../../utils/types"; | ||
import { createProcessingJob, getProcessingJob } from "../../services/processing"; | ||
|
||
type AIStudyProps = { | ||
studyId: string; | ||
onClose: () => void; | ||
show: boolean; | ||
} | ||
|
||
const AiStudy: React.FC<AIStudyProps> = ({ studyId, onClose, show }) => { | ||
const { toastSuccess, toastError } = useCustomToast() | ||
|
||
const [selectedSeries, setSelectedSeries] = useState([]); | ||
const [jobId, setJobId] = useState<string | null>(null); | ||
|
||
const { data: series, isLoading } = useCustomQuery( | ||
['study', studyId, 'series'], | ||
() => getSeriesOfStudy(studyId), | ||
{ | ||
select: (instances: Series[]) => { | ||
return instances.sort((a, b) => a.mainDicomTags?.seriesDescription?.localeCompare(b.mainDicomTags?.seriesDescription ?? "") ?? 0) | ||
} | ||
} | ||
) | ||
|
||
const { data: jobData } = useCustomQuery<ProcessingJob[]>( | ||
['processing', jobId ?? ''], | ||
() => getProcessingJob(jobId), | ||
{ | ||
enabled: jobId != null, | ||
refetchInterval: 2000 | ||
} | ||
) | ||
|
||
const { mutate: createProcessingJobMutate } = useCustomMutation( | ||
({ jobType, jobPayload }) => createProcessingJob(jobType, jobPayload), | ||
[[]], | ||
{ | ||
onSuccess: (jobId) => { | ||
toastSuccess("Job Created " + jobId) | ||
setJobId(jobId) | ||
} | ||
} | ||
) | ||
|
||
const handleSeriesClick = (seriesId: string) => { | ||
if (selectedSeries.includes(seriesId)) { | ||
const newSelected = selectedSeries.filter((id) => id !== seriesId) | ||
setSelectedSeries(newSelected) | ||
|
||
} else { | ||
setSelectedSeries(previousSeries => [...previousSeries, seriesId]) | ||
} | ||
} | ||
|
||
const handleExecute = () => { | ||
if (selectedSeries.length !== 2) { | ||
toastError('Select only 2 series, PT and CT') | ||
return; | ||
} | ||
createProcessingJobMutate({ | ||
jobType: 'tmtv', | ||
jobPayload: { | ||
CtOrthancSeriesId: selectedSeries[0], | ||
PtOrthancSeriesId: selectedSeries[1], | ||
SendMaskToOrthancAs: ['seg'], | ||
WithFragmentedMask: true, | ||
} | ||
}) | ||
} | ||
|
||
console.log(jobData) | ||
if (isLoading) return <Spinner /> | ||
|
||
return ( | ||
<Modal show={show} size='xl'> | ||
<Modal.Header onClose={onClose} > | ||
<Modal.Title>AI Inference</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<div className={"flex justify-center gap-3"}> | ||
{ | ||
series?.map((series: Series) => { | ||
return ( | ||
<Button key={series.id} color={selectedSeries.includes(series.id) ? Colors.success : Colors.secondary} onClick={() => handleSeriesClick(series.id)} > | ||
{series.mainDicomTags.modality} - {series.mainDicomTags.seriesDescription} | ||
</Button> | ||
) | ||
}) | ||
} | ||
</div> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<div className={"flex justify-center"}> | ||
<Button color={Colors.success} onClick={handleExecute}>Execute TMTV Model</Button> | ||
{jobData && jobData.map(job => <ProgressCircle progress={job.progress} text={job.state} />)} | ||
</div> | ||
</Modal.Footer> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default AiStudy; |
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,57 @@ | ||
/** | ||
* Component for a modal to preview a study | ||
* @name PreviewStudy | ||
*/ | ||
|
||
import React from "react"; | ||
import { getSeriesOfStudy } from "../../services/orthanc"; | ||
import { useCustomQuery } from "../../utils"; | ||
|
||
import { Accordion, Modal, Spinner } from "../../ui"; | ||
import { Series } from "../../utils/types"; | ||
import { AccordionHeader } from "../../ui/Accordion"; | ||
import PreviewSeries from "../series/PreviewSeries"; | ||
|
||
type PreviewStudyProps = { | ||
studyId: string; | ||
onClose: () => void; | ||
show: boolean; | ||
} | ||
|
||
const PreviewStudy: React.FC<PreviewStudyProps> = ({ studyId, onClose, show }) => { | ||
|
||
const { data: series, isLoading } = useCustomQuery( | ||
['study', studyId, 'series'], | ||
() => getSeriesOfStudy(studyId), | ||
{ | ||
select: (instances: Series[]) => { | ||
return instances.sort((a, b) => a.mainDicomTags?.seriesDescription?.localeCompare(b.mainDicomTags?.seriesDescription ?? "") ?? 0) | ||
} | ||
} | ||
) | ||
|
||
if (isLoading) return <Spinner /> | ||
|
||
return ( | ||
<Modal show={show} size='xl'> | ||
<Modal.Header onClose={onClose} > | ||
<Modal.Title>Preview Study</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<div className={"flex flex-col w-full h-full gap-3"}> | ||
{ | ||
series?.map((series: Series) => { | ||
return ( | ||
<Accordion variant="secondary" header={<AccordionHeader variant="primary">{(series.mainDicomTags?.seriesDescription?.length ?? 0) > 0 ? series.mainDicomTags?.seriesDescription : "N/A"}</AccordionHeader>}> | ||
<PreviewSeries seriesId={series.id} /> | ||
</Accordion> | ||
) | ||
}) | ||
} | ||
</div> | ||
</Modal.Body> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default PreviewStudy; |
Oops, something went wrong.