Skip to content

Commit bdad0fa

Browse files
committed
Merge branch 'master' into feat/897/change-release-pattern
2 parents dbe3b5b + 8e897ed commit bdad0fa

27 files changed

Lines changed: 1273 additions & 106 deletions

app/next-client-app/api/concepts.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
"use server";
22
import request from "@/lib/api/request";
33
import { fetchAllPages } from "@/lib/api/utils";
4+
import { revalidatePath } from "next/cache";
45

56
const fetchKeys = {
67
conceptFilter: (filter: string) =>
78
`v2/omop/conceptsfilter/?concept_id__in=${filter}`,
89
addConcept: "v2/scanreports/concepts/",
910
deleteConcept: (conceptId: number) => `v2/scanreports/concepts/${conceptId}/`,
1011
scanreportConcepts: (filter?: string) => `v2/scanreports/concepts/?${filter}`,
12+
scanreportConceptDetail: (scanReportId: string, tableId: string, fieldId: string, valueId: string, conceptId: string) => `v3/scanreports/${scanReportId}/tables/${tableId}/fields/${fieldId}/values/${valueId}/concepts/${conceptId}/`,
1113
};
1214

1315
export async function getAllScanReportConcepts(
@@ -49,6 +51,22 @@ export async function addConcept(data: {}) {
4951
}
5052
}
5153

54+
export async function addConceptV3(data: {}, path: string) {
55+
try {
56+
await request(fetchKeys.addConcept, {
57+
method: "POST",
58+
headers: {
59+
"Content-type": "application/json",
60+
},
61+
body: JSON.stringify(data),
62+
});
63+
revalidatePath(path);
64+
} catch (error: any) {
65+
// Only return a response when there is an error
66+
return { errorMessage: error.message };
67+
}
68+
}
69+
5270
export async function deleteConcept(conceptId: number) {
5371
await request(fetchKeys.deleteConcept(conceptId), {
5472
method: "DELETE",
@@ -57,3 +75,40 @@ export async function deleteConcept(conceptId: number) {
5775
},
5876
});
5977
}
78+
79+
export async function deleteConceptV3(conceptId: number, path: string) {
80+
await request(fetchKeys.deleteConcept(conceptId), {
81+
method: "DELETE",
82+
headers: {
83+
"Content-type": "application/json",
84+
},
85+
});
86+
revalidatePath(path);
87+
}
88+
89+
export async function getScanReportConceptDetail(
90+
scanReportId: string,
91+
tableId: string,
92+
fieldId: string,
93+
valueId: string,
94+
conceptId: string,
95+
): Promise<ScanReportConceptDetailV3> {
96+
return await request(fetchKeys.scanreportConceptDetail(scanReportId, tableId, fieldId, valueId, conceptId));
97+
}
98+
99+
export async function updateScanReportConceptDetail(
100+
scanReportId: string,
101+
tableId: string,
102+
fieldId: string,
103+
valueId: string,
104+
conceptId: string,
105+
data: {},
106+
): Promise<ScanReportConceptDetailV3> {
107+
return await request(fetchKeys.scanreportConceptDetail(scanReportId, tableId, fieldId, valueId, conceptId), {
108+
method: "PATCH",
109+
headers: {
110+
"Content-type": "application/json",
111+
},
112+
body: JSON.stringify(data),
113+
});
114+
}

app/next-client-app/api/files.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ export async function requestFile(
5151

5252
export async function downloadFile(
5353
scan_report_id: number,
54-
file_type?: string,
5554
file_id?: number
56-
): Promise<{ success: boolean; errorMessage?: string; data?: any }> {
55+
): Promise<{
56+
success: boolean;
57+
errorMessage?: string;
58+
data?: any;
59+
blob?: Blob;
60+
}> {
5761
try {
5862
if (!file_id) {
5963
// The case of SR exporting
@@ -66,19 +70,14 @@ export async function downloadFile(
6670

6771
return { success: true, data: base64String };
6872
} else {
69-
// The case of mapping rules file downloading
73+
// The case of mapping rules file downloading - use streaming for all file types
7074
const response = await request(
71-
fetchKeys.downloadFile(scan_report_id, file_id)
75+
fetchKeys.downloadFile(scan_report_id, file_id),
76+
{ download: true }
7277
);
73-
if (file_type == "mapping_json") {
74-
return { success: true, data: JSON.parse(response) };
75-
}
76-
if (file_type == "mapping_csv") {
77-
return { success: true, data: response };
78-
}
78+
// Return the blob directly
79+
return { success: true, blob: response as Blob };
7980
}
80-
81-
return { success: false, errorMessage: "Unsupported file type" };
8281
} catch (error: any) {
8382
return { success: false, errorMessage: error.message };
8483
}

app/next-client-app/api/scanreports.ts

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,32 @@ const fetchKeys = {
2020
field: (
2121
scanReportId: string | number,
2222
tableId: string | number,
23-
fieldId: string | number | undefined
23+
fieldId: string | number | undefined,
2424
) => `v2/scanreports/${scanReportId}/tables/${tableId}/fields/${fieldId}/`,
2525
fields: (scanReportId: string, tableId: string, filter?: string) =>
2626
`v2/scanreports/${scanReportId}/tables/${tableId}/fields/?${filter}`,
2727
values: (
2828
scanReportId: string,
2929
tableId: string,
3030
fieldId: string,
31-
filter?: string
31+
filter?: string,
3232
) =>
3333
`v2/scanreports/${scanReportId}/tables/${tableId}/fields/${fieldId}/values/?${filter}`,
34+
valuesV3: (
35+
scanReportId: string,
36+
tableId: string,
37+
fieldId: string,
38+
filter?: string,
39+
) =>
40+
`v3/scanreports/${scanReportId}/tables/${tableId}/fields/${fieldId}/values/?${filter}`,
3441
};
3542

3643
export async function getScanReports(
37-
filter: string | undefined
44+
filter: string | undefined,
3845
): Promise<PaginatedResponse<ScanReport>> {
3946
try {
4047
return await request<PaginatedResponse<ScanReport>>(
41-
fetchKeys.index(filter)
48+
fetchKeys.index(filter),
4249
);
4350
} catch (error) {
4451
console.warn("Failed to fetch data.");
@@ -71,7 +78,7 @@ export async function getScanReport(id: string): Promise<ScanReport | null> {
7178
export async function updateScanReport(
7279
id: number,
7380
data: {},
74-
needRedirect?: boolean
81+
needRedirect?: boolean,
7582
) {
7683
try {
7784
await request(fetchKeys.get(id), {
@@ -111,7 +118,7 @@ export async function deleteScanReport(id: number) {
111118
* @returns A object with a list of the users permissions.
112119
*/
113120
export async function getScanReportPermissions(
114-
id: string
121+
id: string,
115122
): Promise<PermissionsResponse> {
116123
try {
117124
return await request<PermissionsResponse>(fetchKeys.permissions(id));
@@ -123,11 +130,11 @@ export async function getScanReportPermissions(
123130

124131
export async function getScanReportTable(
125132
scanReportId: string,
126-
tableId: string
133+
tableId: string,
127134
): Promise<ScanReportTable> {
128135
try {
129136
return await request<ScanReportTable>(
130-
fetchKeys.table(scanReportId, tableId)
137+
fetchKeys.table(scanReportId, tableId),
131138
);
132139
} catch (error) {
133140
console.warn("Failed to fetch data.");
@@ -148,7 +155,7 @@ export async function getScanReportTable(
148155

149156
export async function getJobs(
150157
scanReportId: string,
151-
stage?: string
158+
stage?: string,
152159
): Promise<Job[] | null> {
153160
try {
154161
return await request<Job[] | null>(fetchKeys.jobs(scanReportId, stage));
@@ -161,7 +168,7 @@ export async function getJobs(
161168
export async function updateScanReportTable(
162169
scanReportId: string | number,
163170
tableId: string | number,
164-
data: {}
171+
data: {},
165172
) {
166173
try {
167174
await request(fetchKeys.table(scanReportId, tableId), {
@@ -179,11 +186,11 @@ export async function updateScanReportTable(
179186

180187
export async function getScanReportTables(
181188
scanReportId: string,
182-
filter: string | undefined
189+
filter: string | undefined,
183190
): Promise<PaginatedResponse<ScanReportTable>> {
184191
try {
185192
return await request<PaginatedResponse<ScanReportTable>>(
186-
fetchKeys.tables(scanReportId, filter)
193+
fetchKeys.tables(scanReportId, filter),
187194
);
188195
} catch (error) {
189196
console.warn("Failed to fetch data.");
@@ -194,11 +201,11 @@ export async function getScanReportTables(
194201
export async function getScanReportFields(
195202
scanReportId: string,
196203
tableId: string,
197-
filter: string | undefined
204+
filter: string | undefined,
198205
): Promise<PaginatedResponse<ScanReportField>> {
199206
try {
200207
return await request<PaginatedResponse<ScanReportField>>(
201-
fetchKeys.fields(scanReportId, tableId, filter)
208+
fetchKeys.fields(scanReportId, tableId, filter),
202209
);
203210
} catch (error) {
204211
console.warn("Failed to fetch data.");
@@ -209,11 +216,11 @@ export async function getScanReportFields(
209216
export async function getScanReportField(
210217
scanReportId: string,
211218
tableId: string,
212-
fieldId: string | number | undefined
219+
fieldId: string | number | undefined,
213220
): Promise<ScanReportField> {
214221
try {
215222
return await request<ScanReportField>(
216-
fetchKeys.field(scanReportId, tableId, fieldId)
223+
fetchKeys.field(scanReportId, tableId, fieldId),
217224
);
218225
} catch (error) {
219226
console.warn("Failed to fetch data. Passed ID could be null");
@@ -247,7 +254,7 @@ export async function updateScanReportField(
247254
scanReportId: string | number,
248255
tableId: string | number,
249256
fieldId: string,
250-
data: {}
257+
data: {},
251258
) {
252259
try {
253260
await request(fetchKeys.field(scanReportId, tableId, fieldId), {
@@ -265,11 +272,11 @@ export async function updateScanReportField(
265272
export async function getAllScanReportFields(
266273
scanReportId: string,
267274
tableId: string,
268-
filter: string | undefined
275+
filter: string | undefined,
269276
): Promise<ScanReportField[]> {
270277
try {
271278
return await fetchAllPages<ScanReportField>(
272-
fetchKeys.fields(scanReportId, tableId, filter)
279+
fetchKeys.fields(scanReportId, tableId, filter),
273280
);
274281
} catch (error) {
275282
console.warn("Failed to fetch data.");
@@ -281,11 +288,27 @@ export async function getScanReportValues(
281288
scanReportId: string,
282289
tableId: string,
283290
fieldId: string,
284-
filter: string | undefined
291+
filter: string | undefined,
285292
): Promise<PaginatedResponse<ScanReportValue>> {
286293
try {
287294
return await request<PaginatedResponse<ScanReportValue>>(
288-
fetchKeys.values(scanReportId, tableId, fieldId, filter)
295+
fetchKeys.values(scanReportId, tableId, fieldId, filter),
296+
);
297+
} catch (error) {
298+
console.warn("Failed to fetch data.");
299+
return { count: 0, next: null, previous: null, results: [] };
300+
}
301+
}
302+
303+
export async function getScanReportValuesV3(
304+
scanReportId: string,
305+
tableId: string,
306+
fieldId: string,
307+
filter: string | undefined,
308+
): Promise<PaginatedResponse<ScanReportValueV3>> {
309+
try {
310+
return await request<PaginatedResponse<ScanReportValueV3>>(
311+
fetchKeys.valuesV3(scanReportId, tableId, fieldId, filter),
289312
);
290313
} catch (error) {
291314
console.warn("Failed to fetch data.");

app/next-client-app/app/(protected)/scanreports/[id]/downloads/columns.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,12 @@ export const columns: ColumnDef<FileDownload>[] = [
6666
id: "Download",
6767
header: ({ column }) => <DataTableColumnHeader column={column} title="" />,
6868
cell: ({ row }) => {
69-
const { id, scan_report, file_type, name } = row.original;
69+
const { id, scan_report, name } = row.original;
7070
const handleDownload = async () => {
71-
const response = await downloadFile(scan_report, file_type.value, id);
72-
if (response.success) {
73-
// Based on the file type to process the data from the response accordingly
74-
if (file_type.value == "mapping_json") {
75-
const blob = new Blob([JSON.stringify(response.data)], {
76-
type: "application/json",
77-
});
78-
saveAs(blob, name);
79-
} else if (file_type.value == "mapping_csv") {
80-
const blob = new Blob([response.data], {
81-
type: "text/csv",
82-
});
83-
saveAs(blob, name);
84-
}
71+
const response = await downloadFile(scan_report, id);
72+
if (response.success && response.blob) {
73+
// Use the blob directly
74+
saveAs(response.blob, name);
8575
} else {
8676
toast.error(
8777
`Error downloading file: ${(response.errorMessage as any).message}`

0 commit comments

Comments
 (0)