1
- const Tags = require ( "../../lib/dictionary/Tags" ) ;
2
- const TagLists = require ( "../../lib/model/TagLists" ) ;
3
1
const path = require ( "path" ) ;
4
2
const fs = require ( "fs" ) ;
5
- const JSONReader = require ( "../../lib/reader/JSONReader" ) ;
6
- const JSONWriter = require ( "../../lib/writer/JSONWriter" ) ;
7
3
const hashFactory = require ( "node-object-hash" ) ;
4
+ const Tags = require ( "../dictionary/Tags" ) ;
5
+ const TagLists = require ( "../model/TagLists" ) ;
6
+ const JSONReader = require ( "../reader/JSONReader" ) ;
7
+ const JSONWriter = require ( "../writer/JSONWriter" ) ;
8
+
8
9
const hasher = hashFactory ( ) ;
9
10
10
11
const getSeriesInstanceUid = ( seriesInstance ) =>
@@ -23,19 +24,6 @@ const getSeriesInstanceUid = (seriesInstance) =>
23
24
* level data multiple times when it already exists.
24
25
*/
25
26
class StudyData {
26
- deduplicated = [ ] ;
27
- extractData = { } ;
28
- // The list of already existing files read in to create this object
29
- existingFiles = [ ] ;
30
- // The read hashes is the hashes of the files that are read, both as groups and internally
31
- readHashes = { } ;
32
- // The deduplicated hashes are just the hashes for individual items
33
- deduplicatedHashes = { } ;
34
- sopInstances = { } ;
35
-
36
- // Used to track if new instances have been added.
37
- newInstancesAdded = 0 ;
38
-
39
27
constructor (
40
28
{
41
29
studyInstanceUid,
@@ -45,6 +33,18 @@ class StudyData {
45
33
} ,
46
34
{ isGroup }
47
35
) {
36
+ this . deduplicated = [ ] ;
37
+ this . extractData = { } ;
38
+ // The list of already existing files read in to create this object
39
+ this . existingFiles = [ ] ;
40
+ // The read hashes is the hashes of the files that are read, both as groups and internally
41
+ this . readHashes = { } ;
42
+ // The deduplicated hashes are just the hashes for individual items
43
+ this . deduplicatedHashes = { } ;
44
+ this . sopInstances = { } ;
45
+
46
+ // Used to track if new instances have been added.
47
+ this . newInstancesAdded = 0 ;
48
48
this . studyInstanceUid = studyInstanceUid ;
49
49
this . studyPath = studyPath ;
50
50
this . isGroup = isGroup ;
@@ -138,7 +138,7 @@ class StudyData {
138
138
console . log ( "No refs for" , deduplicated ) ;
139
139
return deduplicated ;
140
140
}
141
- const ret = Object . assign ( { } , deduplicated ) ;
141
+ const ret = { ... deduplicated } ;
142
142
for ( const hashKey of refs . Value ) {
143
143
const item = await this . getOrLoadExtract ( hashKey ) ;
144
144
Object . assign ( ret , item ) ;
@@ -161,23 +161,23 @@ class StudyData {
161
161
if ( ! this . isGroup ) return ;
162
162
// TODO - check the hash code on the added data, if it has already been seen then ignore this item.
163
163
if ( this . internalAddDeduplicated ( data ) ) {
164
- this . newInstancesAdded ++ ;
164
+ this . newInstancesAdded += 1 ;
165
165
}
166
166
}
167
167
168
168
/** Add the instance if not already present */
169
169
internalAddDeduplicated ( data , fileName = "internal" ) {
170
170
const hashValue = TagLists . addHash ( data , Tags . InstanceType ) ;
171
- if ( this . deduplicatedHashes [ hashValue ] ) {
171
+ if ( ! hashValue || this . deduplicatedHashes [ hashValue ] ) {
172
172
// console.log('Not adding', hashValue, 'because the hash exists');
173
- return ;
173
+ return false ;
174
174
}
175
175
const sopUID = data [ Tags . SOPInstanceUID ] ;
176
176
const sopValue = ( sopUID && sopUID . Value && sopUID . Value [ 0 ] ) || sopUID ;
177
177
const sopIndex = this . sopInstances [ sopValue ] ;
178
178
if ( ! sopValue ) {
179
179
console . warn ( "No sop value in " , data ) ;
180
- return ;
180
+ return false ;
181
181
}
182
182
this . deduplicatedHashes [ hashValue ] = data ;
183
183
this . readHashes [ hashValue ] = fileName ;
@@ -188,7 +188,8 @@ class StudyData {
188
188
this . sopInstances [ sopValue ] = this . deduplicated . length ;
189
189
this . deduplicated . push ( data ) ;
190
190
}
191
- return hashValue ;
191
+
192
+ return ! ! hashValue ;
192
193
}
193
194
194
195
async listJsonFiles ( dir ) {
@@ -259,7 +260,7 @@ class StudyData {
259
260
const refs = item [ Tags . DeduppedRef ] ;
260
261
if ( refs && refs . Value ) {
261
262
refs . Value . forEach ( ( hashValue ) => {
262
- this . readHashes [ hashValue ] = hashValue + " .gz" ;
263
+ this . readHashes [ hashValue ] = ` ${ hashValue } .gz` ;
263
264
} ) ;
264
265
}
265
266
} else {
@@ -327,7 +328,7 @@ class StudyData {
327
328
Value : [ instances . length ] ,
328
329
} ;
329
330
numberOfInstances += instances . length ;
330
- numberOfSeries ++ ;
331
+ numberOfSeries += 1 ;
331
332
seriesList . push ( seriesQuery ) ;
332
333
const modality = seriesQuery [ Tags . Modality ] . Value [ 0 ] ;
333
334
if ( modalitiesInStudy . indexOf ( modality ) == - 1 )
@@ -391,6 +392,7 @@ class StudyData {
391
392
return data ;
392
393
}
393
394
395
+ /* eslint-disable-next-line class-methods-use-this */
394
396
removeGz ( name ) {
395
397
const gzIndex = name . indexOf ( ".gz" ) ;
396
398
return ( gzIndex > 0 && name . substring ( 0 , gzIndex ) ) || name ;
@@ -410,7 +412,7 @@ class StudyData {
410
412
data [ Tags . DeduppedRef ] = {
411
413
vr : "CS" ,
412
414
Value : Object . keys ( this . readHashes ) . filter (
413
- ( hash ) => this . deduplicatedHashes [ hashValue ] == undefined
415
+ ( ) => this . deduplicatedHashes [ hashValue ] == undefined
414
416
) ,
415
417
} ;
416
418
await JSONWriter (
0 commit comments