Passed
Branch master (6cdc89)
by Salim
07:05
created

src/assets/javascripts/uppyCsvPlugin.js   A

Complexity

Total Complexity 7
Complexity/F 1.17

Size

Lines of Code 55
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 36
dl 0
loc 55
rs 10
c 0
b 0
f 0
mnd 1
bc 1
fnc 6
bpm 0.1666
cpm 1.1666
noi 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A uppyCsvPlugin.js ➔ install 0 3 1
A uppyCsvPlugin.js ➔ uninstall 0 3 1
A uppyCsvPlugin.js ➔ constructor 0 15 1
A uppyCsvPlugin.js ➔ checkCSV 0 27 4
1
const UppyCsvPlugin = class UppyCsvPlugin extends Uppy.Core.Plugin {
2
3
  constructor (uppy, opts) {
4
    super(uppy, opts)
5
    this.id = opts.id
6
    this.type = opts.type
7
    this.checkCSV = this.checkCSV.bind(this)
8
9
    this.patientId = opts.patientId
10
    this.studyDate = new Date(opts.studyDate)
11
    this.suvLo = opts.suvLo
12
    this.suvHigh = opts.suvHigh
13
    this.useSuv = opts.useSuv
14
    this.useCT = opts.useCT
15
    this.notify = opts.notify
16
17
  }
18
19
  checkCSV(filesIDs){
20
      console.log(filesIDs)
21
      let file = this.uppy.getFile(filesIDs[0])
22
      console.log(file)
23
24
      let csvParser = new PetCtCSVParser(file.data)
25
26
      return csvParser.parseCSV().then( () => {
27
28
        let checkPatientIdentity = csvParser.checkAcquisition(this.patientId, this.studyDate)
29
        let checkThreshold = csvParser.checkTMTVThreshold(this.suvLo)
30
        this.notify({
31
          Tmtv : csvParser.getTmtvValue(),
32
          suvLo : csvParser.getSuvLow(),
33
          checkPatientIdentity : checkPatientIdentity,
34
          checkThreshold : checkThreshold
35
        })
36
        console.log(checkPatientIdentity)
37
        console.log(checkThreshold)
38
        return (checkPatientIdentity && checkThreshold)
39
      }).then((resultCheck)=> {
40
        if(!resultCheck) this.uppy.removeFile(file.id)
41
        else this.uppy.emit('preprocess-complete', file.id)
42
43
      })
44
45
  }
46
47
  install () {
48
    this.uppy.addPreProcessor(this.checkCSV)
49
  }
50
51
  uninstall () {
52
    this.uppy.removePreProcessor(this.checkCSV)
53
  }
54
55
}
56