-
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 #311 from Pixilib/salim2
Salim2
- Loading branch information
Showing
8 changed files
with
231 additions
and
41 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
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
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,39 @@ | ||
import { ProcessingJob } from "../utils/types"; | ||
import axios, { handleAxiosError } from "./axios"; | ||
|
||
export const createProcessingJob = ( | ||
jobType: string, | ||
jobPayload: Record<string, any> | ||
): Promise<string> => { | ||
const payload = { | ||
JobType: jobType, | ||
TmtvJob: jobPayload, | ||
}; | ||
|
||
return axios | ||
.post(`/api/processing`, payload) | ||
.then((response) => response.data.JobId) | ||
.catch(handleAxiosError); | ||
}; | ||
|
||
export const getProcessingJob = (jobId: string): Promise<ProcessingJob[]> => { | ||
return axios | ||
.get(`/api/processing/` + jobId) | ||
.then((response) => { | ||
const data = response.data; | ||
return data.map((jobdata) => ({ | ||
progress: jobdata.Progress, | ||
state: jobdata.State, | ||
id: jobdata.Id, | ||
results: jobdata.Results, | ||
})); | ||
}) | ||
.catch(handleAxiosError); | ||
}; | ||
|
||
export const deleteProcessingJob = (jobId: string): Promise<void> => { | ||
return axios | ||
.delete(`/api/processing/` + jobId) | ||
.then((response) => undefined) | ||
.catch(handleAxiosError); | ||
}; |
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