-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.js
52 lines (43 loc) · 1.44 KB
/
import.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
const fs = require('fs');
const Promise = require('bluebird');
const path = require('path');
const argv = require('minimist')(process.argv.slice(2));
const _ = require('underscore');
const os = require('os');
const xnat = require("./index.js");
const help = function(){
console.error("Import a file to xnat");
console.error("Usage: node", process.argv[1],"-p <project id> --pid <patient id> --expid <experiment id> --sessid <session id> -f <converted dicom file>");
console.error("Options:");
console.error("-f <file to be uploaded>");
console.error("-p <project id>, project id in XNAT to upload the files.");
console.error("--pid <patient id>");
console.error("--expid <experiment id>");
console.error("--sessid <session id>");
}
if(!argv["p"] || !argv["f"] || !argv["pid"] || !argv["expid"] || !argv["sessid"] || argv["h"] || argv["help"]){
help();
process.exit(1);
}
var projectid = argv["p"];
var filename = argv["f"];
var patientid = argv["pid"];
var experimentid = argv["expid"];
var sessionid = argv["sessid"];
xnat.start()
.then(function(conf){
return xnat.createResources(projectid, patientid, experimentid, sessionid, "NRRD")
.catch(console.error)
.then(function(){
return xnat.uploadResourceFile(projectid, patientid, experimentid, sessionid, "NRRD", filename);
})
.catch(console.error);
})
.then(function(res){
console.log(res);
return xnat.logout();
})
.catch(function(error){
console.error(error);
return xnat.logout();
});