Skip to content

Commit a1723c8

Browse files
authored
Merge pull request #1330 from chhsiao1981/query-and-retrieve-pacs
able to create public feed after successfully waiting for the PACS.
2 parents 52fc3a2 + 590b0be commit a1723c8

File tree

11 files changed

+236
-33
lines changed

11 files changed

+236
-33
lines changed

src/api/api.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const collectionJsonItemToJson = (item: any) =>
7171
const collectionJsonToJson = (theData: any) =>
7272
theData.collection.items.map(collectionJsonItemToJson);
7373

74-
const callApi = <T>(
74+
const callApi = async <T>(
7575
endpoint: string,
7676
{
7777
query,
@@ -103,7 +103,7 @@ const callApi = <T>(
103103

104104
if (filename) {
105105
const filetext = paramsFiletext || "";
106-
return postFile(theEndpoint, filename, filetext);
106+
return await postFile(theEndpoint, filename, filetext);
107107
}
108108

109109
const token = getToken();
@@ -130,10 +130,10 @@ const callApi = <T>(
130130
body,
131131
};
132132

133-
return fetchCore<T>(theEndpoint, options);
133+
return await fetchCore<T>(theEndpoint, options);
134134
};
135135

136-
const postFile = <T>(
136+
const postFile = async <T>(
137137
theEndpoint: string,
138138
filename: string,
139139
filetext: string,
@@ -149,19 +149,19 @@ const postFile = <T>(
149149
Accept: "application/json",
150150
};
151151

152-
return fetchCore<T>(
152+
return await fetchCore<T>(
153153
theEndpoint,
154154
{ method: "POST", headers, body: formData },
155155
true,
156156
);
157157
};
158158

159-
const fetchCore = <T>(
159+
const fetchCore = async <T>(
160160
endpoint: string,
161161
options: RequestInit,
162162
isJson = false,
163163
): Promise<ApiResult<T>> => {
164-
return fetch(endpoint, options)
164+
return await fetch(endpoint, options)
165165
.then((res) => {
166166
const status = res.status;
167167
return res

src/api/serverApi.ts

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import api from "./api";
1+
import { dir } from "console";
2+
import api, { type ApiResult } from "./api";
23
import type {
34
Feed,
45
PluginInstance,
56
Plugin,
67
NodeInfo,
78
UploadPipeline,
9+
PACSSeries,
810
} from "./types";
911

1012
import YAML from "yaml";
@@ -15,7 +17,7 @@ export const GetFeedPluginInstances = (feedID: number) =>
1517
method: "get",
1618
});
1719

18-
export const GetFeed = (feedID: number) =>
20+
export const getFeed = (feedID: number) =>
1921
api<Feed>({
2022
endpoint: `/${feedID}/`,
2123
method: "get",
@@ -30,6 +32,15 @@ export const updateFeedName = (feedID: number, feedName: string) =>
3032
},
3133
});
3234

35+
export const updateFeedPublic = (feedID: number, isPublic = true) =>
36+
api<Feed>({
37+
endpoint: `/${feedID}/`,
38+
method: "put",
39+
json: {
40+
public: isPublic,
41+
},
42+
});
43+
3344
export const searchPluginsByName = (pluginName: string) =>
3445
api<Plugin[]>({
3546
endpoint: "/plugins/search/",
@@ -44,6 +55,7 @@ export const createPluginInstance = (pluginID: number, theDirs: string[]) =>
4455
endpoint: `/plugins/${pluginID}/instances/`,
4556
method: "post",
4657
json: {
58+
previous_id: null,
4759
dir: theDirs.join(","),
4860
},
4961
});
@@ -72,10 +84,69 @@ export const createWorkflow = (
7284
},
7385
});
7486

87+
type createFeedWithFilepathProp = {
88+
filepath: string;
89+
theName: string;
90+
tags: string[];
91+
patientID?: string;
92+
modality?: string;
93+
studyDate?: string;
94+
isPublic?: boolean;
95+
};
96+
export const createFeedWithFilepath = async ({
97+
filepath,
98+
theName,
99+
tags,
100+
patientID,
101+
modality,
102+
studyDate,
103+
isPublic,
104+
}: createFeedWithFilepathProp): Promise<ApiResult<Feed>> => {
105+
const pluginInstanceResult = await createPluginInstance(1, [filepath]);
106+
if (!pluginInstanceResult.data) {
107+
return {
108+
errmsg: pluginInstanceResult.errmsg,
109+
status: pluginInstanceResult.status,
110+
};
111+
}
112+
113+
const {
114+
data: { feed_id: feedID },
115+
} = pluginInstanceResult;
116+
117+
await updateFeedName(feedID, theName);
118+
119+
if (isPublic) {
120+
await updateFeedPublic(feedID, true);
121+
}
122+
123+
const feedResult = await getFeed(feedID);
124+
125+
return feedResult;
126+
};
127+
75128
export const createPipeline = (pipeline: UploadPipeline) =>
76129
api({
77130
endpoint: "/pipelines/sourcefiles/",
78131
method: "post",
79132
filename: "fname",
80133
filetext: YAML.stringify(pipeline),
81134
});
135+
136+
export const getPACSSeriesListByStudyUID = (studyUID: string) =>
137+
api<PACSSeries[]>({
138+
endpoint: "/pacs/series/search/",
139+
method: "get",
140+
query: {
141+
StudyInstanceUID: studyUID,
142+
},
143+
});
144+
145+
export const getPACSSeriesListBySeriesUID = (seriesUID: string) =>
146+
api<PACSSeries[]>({
147+
endpoint: "/pacs/series/search/",
148+
method: "get",
149+
query: {
150+
SeriesInstanceUID: seriesUID,
151+
},
152+
});

src/api/types.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,23 @@ export interface UploadPipeline {
9999
locked: false;
100100
plugin_tree: UploadPluginInfo[];
101101
}
102+
103+
export interface PACSSeries {
104+
id: number;
105+
creation_date: string; // yyyy-mm-ddTHH:MM:SS.ffffffTZ
106+
folder_path: string;
107+
PatientID: string;
108+
PatientName: string;
109+
PatientBirthDate: string;
110+
PatientAge: string;
111+
PatientSex: string;
112+
StudyDate: string;
113+
AccessionNumber: string;
114+
Modality: string;
115+
ProtocolName: string;
116+
StudyInstanceUID: string;
117+
StudyDescription: string;
118+
SeriesInstanceUID: string;
119+
SeriesDescription: string;
120+
pacs_identifier: string;
121+
}

src/components/CreateFeed/createFeedHelper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { computeWorkflowNodesInfo, getFullFeedName } from "./utils";
1414

1515
import {
1616
createWorkflow,
17-
GetFeed,
17+
getFeed,
1818
searchPluginsByName,
1919
createPluginInstance as serverCreatePluginInstance,
2020
updateFeedName,
@@ -111,7 +111,7 @@ const createFeedCore = async (
111111
}
112112

113113
const feedID = createdInstance.data?.feed_id || 0;
114-
const feed = GetFeed(feedID);
114+
const feed = getFeed(feedID);
115115

116116
await updateFeedName(feedID, fullFeedName);
117117

src/components/NewLibrary/components/operations/CreateAnalysis.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { MainRouterContext } from "../../../../routes";
2727
import Review from "../../../CreateFeed/Review";
2828
import { useQueryClient } from "@tanstack/react-query";
2929
import type { SelectionPayload } from "../../../../store/cart/types";
30-
import { GetFeed, GetFeedPluginInstances } from "../../../../api/serverApi";
30+
import { getFeed, GetFeedPluginInstances } from "../../../../api/serverApi";
3131
import type { Feed, PluginInstance } from "../../../../api/types";
3232
import { catchError } from "../../../../api/common";
3333

@@ -199,7 +199,7 @@ export default (props: Props) => {
199199
return { name: "", filename: "", theID: -1, createDateTime: "" };
200200
}
201201

202-
const feed = await GetFeed(feedID);
202+
const feed = await getFeed(feedID);
203203
if (!feed.data) {
204204
return { name: "", filename: "", theID: -1, createDateTime: "" };
205205
}

src/components/NewLibrary/utils/useOperations.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ export const useFolderOperations = (
400400
createFeed: () => {
401401
const defaultFeedName =
402402
selectedPaths.length > 1
403-
? "Feed created from your Library"
404-
: `Feed created for ${getFeedNameForSinglePath(selectedPaths[0])}`;
403+
? "Data created"
404+
: `Data created for ${getFeedNameForSinglePath(selectedPaths[0])}`;
405405
setModalState({
406406
type: "createFeed",
407407
isOpen: true,

src/components/NewStore/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ const Store: React.FC = () => {
253253
<>
254254
<Wrapper
255255
titleComponent={
256-
<InfoSection title="Import Packages" content="Work in Progress" />
256+
<InfoSection title="Import Package" content="Work in Progress" />
257257
}
258258
>
259259
<Toolbar isSticky id="store-toolbar" clearAllFilters={() => {}}>

0 commit comments

Comments
 (0)