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

PetCtCSVParser.checkTMTVThreshold   A

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 2
1
class PetCtCSVParser {
2
3
    constructor(csvFile){
4
        this.csvFile = csvFile
5
    }
6
7
    parseCSV(){
8
        let self = this
9
10
        return new Promise(function(complete, error) {
11
            Papa.parse(self.csvFile, {complete, error});
0 ignored issues
show
Bug introduced by
The variable Papa seems to be never declared. If this is a global, consider adding a /** global: Papa */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
12
        }).then(results => {
13
            self.papaResultArray = results.data
14
        }).then( () => {
15
            self._extractLineOfInterest()
16
        });
17
18
    }
19
20
    _extractLineOfInterest(){
21
        let parsedCSV = this.papaResultArray
22
23
        for(let i = 0 ; i < parsedCSV.length ; i++){
24
            //Search for empty line, the patient identification is just the line before
25
            if( parsedCSV[i].length>1 && parsedCSV[i][1].includes(" sum") ) {
26
                this.patientIdentificationLine = (i+1)
27
            }
28
            if( parsedCSV[i][0]=="SUVlo" ) {
29
                this.roiThresholdLine = (i+1)
30
            }
31
        }
32
        console.log(this.papaResultArray)
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
33
    }
34
35
    getTmtvValue(){
36
        return this.papaResultArray[(this.patientIdentificationLine - 1)][3]
37
    }
38
    getPatientId(){
39
        return this.papaResultArray[this.patientIdentificationLine][13]
40
    }
41
42
    getAcquisitionDate(){
43
        let dateString = this.papaResultArray[this.patientIdentificationLine][1].trim()
44
        let date = moment(dateString, "MMM D_YYYY").toDate();
45
        return date
46
    }
47
48
    getSuvLow(){
49
        return this.papaResultArray[this.roiThresholdLine][0]
50
    }
51
52
    getsuvHigh(){
53
        return this.papaResultArray[this.roiThresholdLine][1]
54
    }
55
56
    isUseSUV(){
57
        return Boolean(parseInt(this.papaResultArray[this.roiThresholdLine][4]))
58
    }
59
60
    isUseCT(){
61
        return Boolean(parseInt(this.papaResultArray[this.roiThresholdLine][5]))
62
    }
63
64
    checkAcquisition(patientId, date){
65
        return (this.getPatientId() == patientId && this.getAcquisitionDate().getTime() === date.getTime())
66
    }
67
68
    checkTMTVThreshold(suvLo, suvHigh=100){
69
        let checkSuvLo = true
70
        if(suvLo != null) checkSuvLo = (this.getSuvLow() == suvLo)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Best Practice introduced by
Comparing suvLo to null using the != operator is not safe. Consider using !== instead.
Loading history...
71
        return ( checkSuvLo && this.getsuvHigh()>=suvHigh && !this.isUseCT() && this.isUseSUV() )
72
    }
73
}
74
75