Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
salimkanoun committed Sep 7, 2024
1 parent 5b676b8 commit 5ccab7c
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
47 changes: 42 additions & 5 deletions src/content/studies/AiStudy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

import React, { useState } from "react";
import { getSeriesOfStudy } from "../../services/orthanc";
import { Colors, useCustomQuery } from "../../utils";
import { Colors, useCustomMutation, useCustomQuery, useCustomToast } from "../../utils";

import { Button, Modal, Spinner } from "../../ui";
import { Button, Modal, ProgressCircle, Spinner } from "../../ui";
import { Series } from "../../utils/types";
import { createProcessingJob, getProcessingJob } from "../../services/processing";

type AIStudyProps = {
studyId: string;
Expand All @@ -17,8 +18,10 @@ type AIStudyProps = {
}

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'],
Expand All @@ -30,6 +33,26 @@ const AiStudy: React.FC<AIStudyProps> = ({ studyId, onClose, show }) => {
}
)

const { data: jobData } = useCustomQuery(
['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)
Expand All @@ -41,9 +64,22 @@ const AiStudy: React.FC<AIStudyProps> = ({ studyId, onClose, show }) => {
}

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: ['MASK'],
WithFragmentedMask: true,
}
})
}

console.log(jobData)
if (isLoading) return <Spinner />

return (
Expand All @@ -56,7 +92,7 @@ const AiStudy: React.FC<AIStudyProps> = ({ studyId, onClose, show }) => {
{
series?.map((series: Series) => {
return (
<Button color={selectedSeries.includes(series.id) ? Colors.success : Colors.secondary} onClick={() => handleSeriesClick(series.id)} >
<Button key={series.id} color={selectedSeries.includes(series.id) ? Colors.success : Colors.secondary} onClick={() => handleSeriesClick(series.id)} >
{series.mainDicomTags.modality} - {series.mainDicomTags.seriesDescription}
</Button>
)
Expand All @@ -66,7 +102,8 @@ const AiStudy: React.FC<AIStudyProps> = ({ studyId, onClose, show }) => {
</Modal.Body>
<Modal.Footer>
<div className={"flex justify-center"}>
<Button color={Colors.success} onClick={() => { handleExecute }}>Execute TMTV Model</Button>
<Button color={Colors.success} onClick={handleExecute}>Execute TMTV Model</Button>
<ProgressCircle progress={10}/>
</div>
</Modal.Footer>
</Modal>
Expand Down
7 changes: 7 additions & 0 deletions src/services/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ export const getToken = () => {
return store?.getState()?.user.token
}

export const handleAxiosError = (error: any) => {
if (error.response) {
throw error.response;
}
throw error;
}

export default axios
31 changes: 31 additions & 0 deletions src/services/processing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import axios, { handleAxiosError } from "./axios";

export const createProcessingJob = (
jobType: string,
jobPayload: Record<string, any>
): Promise<string> => {
const payload = {
jobType,
TmtvJob: jobPayload,
};

return axios
.post(`/api/processing`, payload)
.then((response) => response.data.JobId)
.catch(handleAxiosError);
};

export const getProcessingJob = (jobId: string): Promise<string> => {
return axios
.get(`/api/processing/` + jobId)
.then((response) => response.data.JobId)
.catch(handleAxiosError);
};


export const deleteProcessingJob = (jobId: string): Promise<void> => {
return axios
.delete(`/api/processing/` + jobId)
.then((response) => undefined)
.catch(handleAxiosError);
};

0 comments on commit 5ccab7c

Please sign in to comment.