Skip to content

Commit 40b0fcc

Browse files
author
Alexis Girault
committed
Use javascript object instead of Map
1 parent 185f402 commit 40b0fcc

File tree

2 files changed

+44
-29
lines changed

2 files changed

+44
-29
lines changed

examples/Dicom/src/dicomForm.js

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,63 @@ function setupDicomForm(patientDict, callback) {
44
const studySelect = document.getElementById("studySelect")
55
const serieSelect = document.getElementById("serieSelect")
66

7-
patientSelect.length = 1; // remove all options bar first
8-
const patients = Array.from(patientDict.values())
9-
patientDict.forEach((patient) => {
7+
// Remove options
8+
var patients = []
9+
var studies = []
10+
var series = []
11+
patientSelect.length = 1;
12+
13+
// Add patients
14+
for (const key in patientDict) {
15+
const patient = patientDict[key]
16+
patients.push(patient)
1017
const value = patient.patientName + " - " + patient.patientDateOfBirth
1118
patientSelect.options[patientSelect.options.length] = new Option(value, value);
12-
})
19+
}
1320

1421
patientSelect.onchange = function () {
15-
studySelect.length = 1; // remove all options bar first
16-
serieSelect.length = 1; // remove all options bar first
22+
// Remove options
23+
studies = []
24+
series = []
25+
studySelect.length = 1;
26+
serieSelect.length = 1;
27+
1728
if (this.selectedIndex < 1) return; // done
29+
30+
// Add underneath studies
1831
const patientId = this.selectedIndex - 1
1932
const patient = patients[patientId]
20-
patient.studyDict.forEach((study) => {
33+
for (const key in patient.studyDict) {
34+
const study = patient.studyDict[key]
35+
studies.push(study)
2136
const value = study.studyDescription + " - " + study.studyDate
2237
studySelect.options[studySelect.options.length] = new Option(value, value);
23-
})
38+
}
2439
}
2540
patientSelect.onchange(); // reset in case page is reloaded
2641

2742
studySelect.onchange = function () {
28-
serieSelect.length = 1; // remove all options bar first
43+
// Remove options
44+
series = []
45+
serieSelect.length = 1;
46+
2947
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())
48+
49+
// Add underneath series
3350
const studyId = this.selectedIndex - 1
3451
const study = studies[studyId]
35-
study.serieDict.forEach((serie) => {
52+
for (const key in study.serieDict) {
53+
const serie = study.serieDict[key]
54+
series.push(serie)
3655
const value = serie.seriesDescription + " - " + serie.seriesModality
3756
serieSelect.options[serieSelect.options.length] = new Option(value, value);
38-
})
57+
}
3958
}
4059

4160
serieSelect.onchange = function () {
4261
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())
62+
63+
// Return files for serie
4964
const serieId = this.selectedIndex - 1
5065
const serie = series[serieId]
5166
callback(serie.files)

examples/Dicom/src/parseDicomFiles.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,18 @@ class DICOMPatient extends DICOMEntity {
7878

7979
constructor() {
8080
super()
81-
this.studyDict = new Map()
81+
this.studyDict = {}
8282
}
8383

8484
parseMetaData(dicomMetaData, file) {
8585
this.extractTags(dicomMetaData)
8686

8787
const tag = DICOMStudy.primaryTag
8888
const studyId = dicomMetaData.string(DICOM_DICTIONARY[tag])
89-
var study = this.studyDict.get(studyId)
89+
var study = this.studyDict[studyId]
9090
if (study === undefined) {
9191
study = new DICOMStudy()
92-
this.studyDict.set(studyId, study)
92+
this.studyDict[studyId] = study
9393
}
9494
study.parseMetaData(dicomMetaData, file)
9595
}
@@ -113,18 +113,18 @@ class DICOMStudy extends DICOMEntity {
113113

114114
constructor() {
115115
super()
116-
this.serieDict = new Map()
116+
this.serieDict = {}
117117
}
118118

119119
parseMetaData(dicomMetaData, file) {
120120
this.extractTags(dicomMetaData)
121121

122122
const tag = DICOMSerie.primaryTag
123123
const serieNumber = dicomMetaData.string(DICOM_DICTIONARY[tag])
124-
var serie = this.serieDict.get(serieNumber)
124+
var serie = this.serieDict[serieNumber]
125125
if (serie === undefined) {
126126
serie = new DICOMSerie()
127-
this.serieDict.set(serieNumber, serie)
127+
this.serieDict[serieNumber] = serie
128128
}
129129
serie.parseMetaData(dicomMetaData, file)
130130
}
@@ -161,7 +161,7 @@ class DICOMSerie extends DICOMEntity {
161161
}
162162

163163
const parseDicomFiles = async (fileList) => {
164-
var patientDict = new Map()
164+
var patientDict = {}
165165

166166
const parseFile = async (file) => {
167167
// Read
@@ -174,10 +174,10 @@ const parseDicomFiles = async (fileList) => {
174174
// Add to patientDict
175175
const tag = DICOMPatient.primaryTag
176176
const patientId = dicomMetaData.string(DICOM_DICTIONARY[tag])
177-
var patient = patientDict.get(patientId)
177+
var patient = patientDict[patientId]
178178
if (patient === undefined) {
179179
patient = new DICOMPatient()
180-
patientDict.set(patientId, patient)
180+
patientDict[patientId] = patient
181181
}
182182
patient.parseMetaData(dicomMetaData, file)
183183
}

0 commit comments

Comments
 (0)