-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate.js
executable file
·79 lines (70 loc) · 3.12 KB
/
generate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/node
var faker = require('faker');
var dateFormat = require('dateformat');
var fs = require('fs');
//for dicom SOP, Modality, see http://www.dicomlibrary.com/dicom/
//to generate brand new series (with a single instance), just run this without any argument (use default template)
//fill as many argument as you want to generate data based on parent.
//./generate.js <template.json> patient|study|series|instance
//console.log(faker.name.findName());
var mode = process.argv[2]||"patient";
var template_json = process.argv[3]||__dirname+"/template.json";
function genuid() {
//TODO - let's just use uuid for now..
return faker.random.uuid();
}
var headers_raw = fs.readFileSync(template_json);
var headers = JSON.parse(headers_raw.toString());
//fall through each section to modify more / less attributes
switch(mode) {
case "patient":
headers.PatientName = { "Alphabetic": faker.name.findName() };
headers.PatientID = faker.random.number(99999999);
var bday = faker.date.past(80);
headers.PatientBirthDate = dateFormat(bday, "yyyymmdd");
headers.PatientSex = faker.random.number(1)?'M':'F';
headers.PatientAge = "0"+faker.random.number(80)+"Y";
headers.PatientWeight = faker.random.number({min: 100, max: 300, precision:0.1});
//init study
//TODO..
case "study":
headers.StudyID = faker.random.number(9999);
headers.StudyInstanceUID = genuid();
var studydate = faker.date.past(5);
headers.StudyDate = dateFormat(studydate, "yyyymmdd");
headers.StudyTime = dateFormat(studydate, "hhMMss.l000");
headers.StudyDescription = faker.company.bsAdjective()+" "+faker.company.companyName();
//init series
//TODO...
case "series":
headers.SeriesNumber = faker.random.number(9999);
headers.SeriesInstanceUID = genuid();
var seriesdate = faker.date.past(3);
headers.SeriesDate = dateFormat(seriesdate, "yyyymmdd");
headers.SeriesTime = dateFormat(seriesdate, "hhMMss.l000");
headers.SeriesDescription = headers.StudyDescription +" / "+faker.company.catchPhrase();
//init instance
headers.InstanceNumber = 0;
headers.ImageIndex = headers.InstanceNumber;
headers.NumberOfSlices = 200; //TODO - how can I guess?
headers.SliceLocation=0.0;
case "instance":
headers.MediaStorageSOPInstanceUID = faker.random.uuid();
headers.SOPInstanceUID = headers.MediaStorageSOPInstanceUID;
headers.InstanceNumber+=1;
var instdate = faker.date.past(3);
headers.InstanceCreationDate = dateFormat(instdate, "yyyymmdd");
headers.InstanceCreationTime = dateFormat(instdate, "hhMMss.l000");
headers.ImageIndex = headers.InstanceNumber;
headers.SliceLocation+=1 + Math.random()/10;
headers.LargestImagePixelValue = -faker.random.number(10);
headers.WindowCenter = faker.random.number({min: -1000, max: 7000});
headers.WindowWidth = faker.random.number({min: 0, max: 35000});
headers.RescaleSlope = Math.random()/100*(Math.random()*5)
break;
default:
console.error("unknown generation mode");
}
//console.log(JSON.stringify(headers));
console.log(JSON.stringify(headers, null, 4));
//template.MediaStorageSOPClassUID =