Skip to content

Commit 003614e

Browse files
author
Alexis Girault
committed
Select patient/study/series using a dynamic form
1 parent b4314dc commit 003614e

File tree

4 files changed

+94
-24
lines changed

4 files changed

+94
-24
lines changed

examples/Dicom/dist/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@
1414
<input name="inputFile" type="file" multiple>
1515
</div>
1616

17+
<!-- Serie selector -->
18+
<form name="dicomForm" id="dicomForm">
19+
Patient:
20+
<select id="patientSelect" size="1">
21+
<option value="" selected="selected">Select patient</option>
22+
</select>
23+
<br>
24+
Study:
25+
<select id="studySelect" size="1">
26+
<option value="" selected="selected">Please select patient first</option>
27+
</select>
28+
<br>
29+
Serie:
30+
<select id="serieSelect" size="1">
31+
<option value="" selected="selected">Please select study first</option>
32+
</select>
33+
</form>
34+
1735
<!-- File information -->
1836
<textarea readonly name="fileInformation">File information...</textarea>
1937

examples/Dicom/dist/styles.css

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ html, body {
55
textarea {
66
resize: none;
77
overflow-y: scroll;
8-
position: absolute;
9-
box-sizing: border-box;
108
width: 100%;
11-
height: 80%;
12-
bottom: 0px;
13-
left: 0px;
14-
top: 50px;
9+
height: 100%;
1510
}

examples/Dicom/src/dicomForm.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
function setupDicomForm(patientDict, callback) {
3+
const patientSelect = document.getElementById("patientSelect")
4+
const studySelect = document.getElementById("studySelect")
5+
const serieSelect = document.getElementById("serieSelect")
6+
7+
patientSelect.length = 1; // remove all options bar first
8+
const patients = Array.from(patientDict.values())
9+
patientDict.forEach((patient) => {
10+
const value = patient.name + " - " + patient.dateOfBirth
11+
patientSelect.options[patientSelect.options.length] = new Option(value, value);
12+
})
13+
14+
patientSelect.onchange = function () {
15+
studySelect.length = 1; // remove all options bar first
16+
serieSelect.length = 1; // remove all options bar first
17+
if (this.selectedIndex < 1) return; // done
18+
const patientId = this.selectedIndex - 1
19+
const patient = patients[patientId]
20+
patient.studyDict.forEach((study) => {
21+
const value = study.description + " - " + study.date
22+
studySelect.options[studySelect.options.length] = new Option(value, value);
23+
})
24+
}
25+
patientSelect.onchange(); // reset in case page is reloaded
26+
27+
studySelect.onchange = function () {
28+
serieSelect.length = 1; // remove all options bar first
29+
if (this.selectedIndex < 1) return; // done
30+
const patientId = patientSelect.selectedIndex - 1
31+
const patient = patients[patientId]
32+
const studies = Array.from(patient.studyDict.values())
33+
const studyId = this.selectedIndex - 1
34+
const study = studies[studyId]
35+
study.serieDict.forEach((serie) => {
36+
const value = serie.description + " - " + serie.modality
37+
serieSelect.options[serieSelect.options.length] = new Option(value, value);
38+
})
39+
}
40+
41+
serieSelect.onchange = function () {
42+
if (this.selectedIndex < 1) return; // done
43+
const patientId = patientSelect.selectedIndex - 1
44+
const patient = patients[patientId]
45+
const studies = Array.from(patient.studyDict.values())
46+
const studyId = studySelect.selectedIndex - 1
47+
const study = studies[studyId]
48+
const series = Array.from(study.serieDict.values())
49+
const serieId = this.selectedIndex - 1
50+
const serie = series[serieId]
51+
callback(serie.files)
52+
}
53+
}
54+
55+
export default setupDicomForm;

examples/Dicom/src/index.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import readImageDICOMFileSeries from 'itk/readImageDICOMFileSeries'
22
import PromiseFileReader from 'promise-file-reader'
33
import curry from 'curry'
44
import dicomParser from 'dicom-parser'
5+
6+
import setupDicomForm from './dicomForm'
57
import "regenerator-runtime/runtime";
68

79
const parseDICOMFiles = async (fileList) => {
@@ -221,7 +223,7 @@ class DICOMSerie {
221223
}
222224

223225
const outputFileInformation = curry(async function outputFileInformation (outputTextArea, event) {
224-
outputTextArea.textContent = "Loading..."
226+
outputTextArea.textContent = "Parsing..."
225227

226228
// Get files
227229
const dataTransfer = event.dataTransfer
@@ -231,23 +233,23 @@ const outputFileInformation = curry(async function outputFileInformation (output
231233
const patientDict = await parseDICOMFiles(files)
232234

233235
// Select DICOM serie
234-
const patient = patientDict.values().next().value
235-
const study = patient.studyDict.values().next().value
236-
const serie = study.serieDict.values().next().value
237-
238-
// Read DICOM serie
239-
const { image, webWorker } = await readImageDICOMFileSeries(null, serie.files)
240-
console.log(image)
241-
webWorker.terminate()
242-
243-
// Display
244-
function replacer (key, value) {
245-
if (!!value && value.byteLength !== undefined) {
246-
return String(value.slice(0, 6)) + '...'
247-
}
248-
return value
249-
}
250-
outputTextArea.textContent = JSON.stringify(image, replacer, 4)
236+
outputTextArea.textContent = "Please select serie..."
237+
setupDicomForm(patientDict, async (files) => {
238+
outputTextArea.textContent = "Loading..."
239+
240+
// Read DICOM serie
241+
const { image, webWorker } = await readImageDICOMFileSeries(null, files)
242+
webWorker.terminate()
243+
244+
// Display
245+
function replacer (key, value) {
246+
if (!!value && value.byteLength !== undefined) {
247+
return String(value.slice(0, 6)) + '...'
248+
}
249+
return value
250+
}
251+
outputTextArea.textContent = JSON.stringify(image, replacer, 4)
252+
})
251253
})
252254

253255
export { outputFileInformation }

0 commit comments

Comments
 (0)