|
1 | | -import { readDicomTags, readImageDicomFileSeries } from "https://cdn.jsdelivr.net/npm/@itk-wasm/dicom@7.6.4/dist/bundle/index-worker-embedded.min.js"; |
2 | | -import { writeImage } from "https://cdn.jsdelivr.net/npm/@itk-wasm/image-io@1.6.1/dist/bundle/index-worker-embedded.min.js";; |
3 | | - |
| 1 | +import { |
| 2 | + readDicomTags, |
| 3 | + readImageDicomFileSeries, |
| 4 | +} from "https://cdn.jsdelivr.net/npm/@itk-wasm/dicom@7.6.4/dist/bundle/index-worker-embedded.min.js"; |
| 5 | +import { writeImage } from "https://cdn.jsdelivr.net/npm/@itk-wasm/image-io@1.6.1/dist/bundle/index-worker-embedded.min.js"; |
4 | 6 |
|
5 | 7 | const PATIENT_NAME_TAG = "0010|0010"; |
6 | 8 | const SERIE_DESCRIPTION_TAG = "0008|103e"; |
7 | 9 |
|
8 | | -const EXIT_SUCCESS = true |
9 | | -const EXIT_FAILURE = false |
| 10 | +const EXIT_SUCCESS = true; |
| 11 | +const EXIT_FAILURE = false; |
10 | 12 |
|
11 | 13 | // Notice the patient_name destructuring which match the inputs param to the widget on the python side |
12 | | -export async function validateDicomFilePatientName(dicom_file, { patient_name }) { |
13 | | - console.log({dicom_file}); |
14 | | - const options = { |
15 | | - tagsToRead: { tags: [SERIE_DESCRIPTION_TAG, PATIENT_NAME_TAG] } |
16 | | - } |
| 14 | +export async function validateDicomFilePatientName( |
| 15 | + dicom_file, |
| 16 | + { patient_name }, |
| 17 | +) { |
| 18 | + console.log({ dicom_file }); |
| 19 | + const options = { |
| 20 | + tagsToRead: { tags: [SERIE_DESCRIPTION_TAG, PATIENT_NAME_TAG] }, |
| 21 | + }; |
17 | 22 |
|
18 | | - const { tags } = await readDicomTags(dicom_file, options); |
19 | | - console.log({ tags }) |
| 23 | + const { tags } = await readDicomTags(dicom_file, options); |
| 24 | + console.log({ tags }); |
20 | 25 |
|
21 | | - for (const [tag_code, tag_value] of tags) { |
22 | | - if (tag_code === PATIENT_NAME_TAG) { |
23 | | - if (tag_value.trim() !== patient_name.trim() && tag_value !== "Anonymized") { |
24 | | - const output = { |
25 | | - expected: patient_name, |
26 | | - got: tag_value |
27 | | - }; |
28 | | - return { |
29 | | - status: EXIT_FAILURE, |
30 | | - outputs: [output] |
31 | | - }; |
32 | | - } |
33 | | - } |
| 26 | + for (const [tag_code, tag_value] of tags) { |
| 27 | + if (tag_code === PATIENT_NAME_TAG) { |
| 28 | + if ( |
| 29 | + tag_value.trim() !== patient_name.trim() && |
| 30 | + tag_value !== "Anonymized" |
| 31 | + ) { |
| 32 | + const output = { |
| 33 | + expected: patient_name, |
| 34 | + got: tag_value, |
| 35 | + }; |
| 36 | + return { |
| 37 | + status: EXIT_FAILURE, |
| 38 | + outputs: [output], |
| 39 | + }; |
| 40 | + } |
34 | 41 | } |
| 42 | + } |
35 | 43 |
|
36 | | - return { |
37 | | - status: EXIT_SUCCESS, |
38 | | - outputs: [ |
39 | | - dicom_file |
40 | | - ] |
41 | | - } |
| 44 | + return { |
| 45 | + status: EXIT_SUCCESS, |
| 46 | + outputs: [dicom_file], |
| 47 | + }; |
42 | 48 | } |
43 | 49 |
|
| 50 | +export async function generateNIFTIFromDicomFileSet( |
| 51 | + dicom_fileset, |
| 52 | + { output_file_name }, |
| 53 | +) { |
| 54 | + console.log(dicom_fileset); |
| 55 | + const inputs = await Promise.all( |
| 56 | + dicom_fileset.map(async (file) => { |
| 57 | + const buffer = await file.arrayBuffer(); |
| 58 | + return { |
| 59 | + path: file.name, |
| 60 | + data: new Uint8Array(buffer), |
| 61 | + }; |
| 62 | + }), |
| 63 | + ); |
44 | 64 |
|
45 | | -export async function generateNIFTIFromDicomFileSet(dicom_fileset, { output_file_name }) { |
46 | | - console.log(dicom_fileset); |
47 | | - const inputs = await Promise.all( |
48 | | - dicom_fileset.map(async (file) => { |
49 | | - const buffer = await file.arrayBuffer(); |
50 | | - return { |
51 | | - path: file.name, |
52 | | - data: new Uint8Array(buffer), |
53 | | - }; |
54 | | - }) |
55 | | - ); |
56 | | - |
57 | | - let image_result; |
58 | | - try { |
59 | | - image_result = await readImageDicomFileSeries({ inputImages: inputs, singleSortedSeries: true }); |
60 | | - } catch (e) { |
61 | | - return { |
62 | | - status: false, |
63 | | - outputs: "Error while reading DICOM file series" |
64 | | - } |
65 | | - } |
| 65 | + let image_result; |
| 66 | + try { |
| 67 | + image_result = await readImageDicomFileSeries({ |
| 68 | + inputImages: inputs, |
| 69 | + singleSortedSeries: true, |
| 70 | + }); |
| 71 | + } catch (e) { |
| 72 | + return { |
| 73 | + status: false, |
| 74 | + outputs: "Error while reading DICOM file series", |
| 75 | + }; |
| 76 | + } |
66 | 77 |
|
67 | | - const nifti_image_result = await writeImage( |
68 | | - image_result.outputImage, |
69 | | - output_file_name, |
70 | | - { mimeType: "image/nii" } |
71 | | - ); |
| 78 | + const nifti_image_result = await writeImage( |
| 79 | + image_result.outputImage, |
| 80 | + output_file_name, |
| 81 | + { mimeType: "image/nii" }, |
| 82 | + ); |
72 | 83 |
|
73 | | - const blob = new Blob([nifti_image_result.serializedImage.data.buffer]); |
| 84 | + const blob = new Blob([nifti_image_result.serializedImage.data.buffer]); |
74 | 85 |
|
75 | | - return { |
76 | | - status: true, |
77 | | - outputs: [new File([blob], output_file_name)], |
78 | | - } |
| 86 | + return { |
| 87 | + status: true, |
| 88 | + outputs: [new File([blob], output_file_name)], |
| 89 | + }; |
79 | 90 | } |
0 commit comments