{"id":28486449,"url":"https://github.com/juanprietob/xnat-rest","last_synced_at":"2025-07-03T08:32:16.730Z","repository":{"id":57401987,"uuid":"71923128","full_name":"juanprietob/xnat-rest","owner":"juanprietob","description":"xnat rest implemention for node using request library and promises","archived":false,"fork":false,"pushed_at":"2018-09-11T20:40:53.000Z","size":44,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-08T01:43:25.486Z","etag":null,"topics":["api","dicom","image","medical","rest","retrieve","upload","xnat"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/juanprietob.png","metadata":{"files":{"readme":"README.md","changelog":"changeSubjectLabel.js","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-25T17:43:24.000Z","updated_at":"2020-11-03T00:00:14.000Z","dependencies_parsed_at":"2022-09-15T18:40:38.432Z","dependency_job_id":null,"html_url":"https://github.com/juanprietob/xnat-rest","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/juanprietob/xnat-rest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanprietob%2Fxnat-rest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanprietob%2Fxnat-rest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanprietob%2Fxnat-rest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanprietob%2Fxnat-rest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juanprietob","download_url":"https://codeload.github.com/juanprietob/xnat-rest/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanprietob%2Fxnat-rest/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263290553,"owners_count":23443617,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","dicom","image","medical","rest","retrieve","upload","xnat"],"created_at":"2025-06-08T01:34:58.961Z","updated_at":"2025-07-03T08:32:16.718Z","avatar_url":"https://github.com/juanprietob.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xnat-rest\n\nUse xnat-rest API with this package. \n\n----\n\tnpm install xnat-rest\n----\n\nTo test this package please download some DICOM files to your directory and modify the test.js script with the folder name.\nThis package was tested with data available at [archive.org](https://archive.org/download/9889023420030505CT/98890234_20030505_CT.tar.bz2)\n\nRun all tests with\n\n----\n\tnpm test\n----\n\n\n## Usage: \n\nTo write your own application and query XNAT Rest API\n\n```javascript\n\n\tvar xnat = require('xnat-rest');\n\t\n\n\txnat.start()\n\t.then(function(){\n\t\t//Do operations with XNAT REST points\n\t})\n\t.catch(function(err){\n\t\tconsole.error(\"Login failed\")\n\t});\n\n```\n\nThe following operations are supported by this library\n\n```javascript\n\t\n\txnat.useDCMExtensionOn()\n\t\n\txnat.useDCMExtensionOff()\n\t\n\txnat.setUseDCMExtension(bool);\n\t\n\txnat.setAgentOptions(agentOptions);//Object to pass to the request library documentation is here https://github.com/request/request\n\t\n\txnat.setXnatUrl(url);//url = http://localhost:8080/xnat for example\n\t\n\txnat.getXnatUrl();\n\t\n\txnat.login(user);//Object with {\"user\":\"username\",\"password\":\"yourpass\"} given to the request lib documentation also in the 'auth' section https://github.com/request/request\n\t\n\txnat.dicomDump(filename);\n\t\n\txnat.getProjects();\n\t\n\txnat.getSubjects(projectid, subjectid);\n\t\n\txnat.getExperiments(projectid);\n\t\n\txnat.getSubject(projectid, subjectid);\n\t\n\txnat.setSubject(projectid, subjectid, params);\n\t\n\txnat.setExperiment(projectid, subjectid, experimentid, params);\n\t\n\txnat.getSubjectData(projectid, subjectid);\n\t\n\txnat.getSubjectFiles(projectid, subjectid);\n\t\n\txnat.getSubjectExperiments(projectid, subjectid);\n\t\n\txnat.getSubjectExperiment(projectid, subjectid, experimentid);\n\t\n\txnat.getSubjectSession(projectid, subjectid, sessionid);\n\t\n\txnat.createSubject(projectid, subjectid);\n\t\n\txnat.uploadImage(projectid, subjectid, experimentid, filename);\n\t\n\txnat.uploadConvertedImage(projectid, subjectid, experimentid, scanid, filename);\n\t\n\txnat.copyResource(projectid, source_subjectid, source_experimentid, source_scanid, source_resourceid, source_filename, dest_subjectid, dest_experimentid, dest_scanid, dest_resourceid, dest_filename);\n\n\txnat.moveResource(projectid, source_subjectid, source_experimentid, source_scanid, source_resourceid, source_filename, dest_subjectid, dest_experimentid, dest_scanid, dest_resourceid, dest_filename);\n\n\txnat.deleteResourceFile(projectid, subjectid, experimentid, scanid, resourceid, filename);\n\n\txnat.createResources(projectid, subjectid, experimentid, scanid, resourceName);\n\n\txnat.getResourceFiles(projectid, subjectid, experimentid, scanid, resource);\n\n\txnat.getResources(projectid, subjectid, experimentid, scanid);\n\n\txnat.uploadResourceFile(projectid, subjectid, experimentid, scanid, resourceid, filename);\n\n\txnat.search(id);\n\n\txnat.deleteConvertedImage(projectid, subjectid, experimentid, scanid, filename);\n\n\txnat.getScanFiles(projectid, subjectid, experimentid, scanid);\n\n\txnat.getScans(projectid, subjectid, experimentid);\n\n\txnat.deleteFile(uri);\n\n\txnat.triggerPipelines(projectid, subjectid, experimentid);\n\n\txnat.prearchive();\n\n\txnat.logout();\n\n\txnat.findFiles(directory);\n\n\txnat.promptUsernamePassword();\n\n\txnat.promptXnatUrl();\n\n\txnat.writeConfFile(conf);\n\n\txnat.setScanQualityLabels(projectid, labelfilename);\n\n\txnat.upload();\n\n\txnat.importConverted();\n\n\txnat.deleteConverted();\n\n\txnat.changeSubjectLabel();\n\n\txnat.setXnatUrlAndLogin(server, promptlogin);\n\n```\n\n\nTo upload files using this library create a file (index.js) and add:\n\n```javascript\n\tvar xnat = require('xnat-rest');\n\n\txnat.upload();\n```\n\n### Help:\n\n----\n\tUsage: node index.js -d \u003cdirectory\u003e -p \u003cproject id\u003e\n\tOptions:\n\t-d \u003cDICOM directory\u003e, directory with DICOM files.\n\t-p \u003cproject id\u003e, project id in XNAT to upload the files.\n\t--pid \u003cpatient id\u003e, If patient id is specified, the patient id won't be extracted from the DICOM file.\n\t--sessid \u003csession id\u003e, If session id is specified, the session id won't be extracted from the DICOM file.\n\t--server \u003cserver url\u003e, XNAT server url. When server is set, the user will be prompted for username and password\n\t--prompt , If set, forces prompt for login information again. It will use the previous server URL saved in the configuration file\n----\n\n## Documentation:\n\n### Usage simplified:\n\nThe function 'xnat.start()' will prompt for the xnat url, e.x., 'http://yourserver.com/xnat', then for username and password \nYou can then query and do operations on your xnat instance after that.\n\n```javascript\n\tconst Promise = require('bluebird');\n\tconst _ = require('underscore');\n\tconst xnat = require('xnat-rest');\n\n\tvar projectid = \"YourProjectId\";\n\tvar subjectid = \"SomeSubjectId\";\n\tvar sessionid = \"SomeSessionId\";\n\n\txnat.start()\n\t.then(function(){\n\t\treturn xnat.getSubjectExperiment(projectid, subjectid, sessionid);\n\t})\n\t.then(function(result){\n\t\tconsole.log(result);\n\t});\n```\n\n### Get all images from a given session\n\n```javascript\n\tconst xnat = require('xnat-rest');\n\tconst _ =  require('underscore');\n\tconst Promise = require('bluebird');\n\n\tvar projectid = \"YourProjectId\";\n\tvar subjectid = \"SomeSubjectId\";\n\tvar sessionid = \"SomeSessionId\";\n\n\txnat.getSubjectExperiment(projectid, subjectid, sessionid)\n\t.then(function(res){\n\t\t//This will give you the id of the acquired images in that session\n\t\tvar scan = [];\n\t\t_.each(res.items, function(item){\n\t\t\t_.each(item.children, function(children){\n\t\t\t\t_.each(children.items, function(items){\n\t\t\t\t\tscan.push(items.data_fields);\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\t\treturn scan;\n\t})\n\t.then(function(scan_items_data_fields){\n\t\t//This gives you ALL the available images for a given session\n\t\t// /data/archive/projects/{ID}/subjects/{ID | label}/experiments/{ID | label}/scans/{ID}/files\n\n        return Promise.map(scan_items_data_fields, function(data_fields){\n            return xnat.getScanFiles(projectid, subjectid, sessionid, data_fields.ID);\n        })\n        .then(function(res){\n             //to have a flat array with all the available files\n             return _.flatten(res);\n        });\n\t})\n\t.then(function(scan_files){\n\t\treturn Promise.map(scan_files, function(files){\n\t\t\treturn xnat.getFileStream(files.URI)\n\t\t\t.then(function(fstream){\n\t             // Do something with stream, pipe, write etc..\n\t        });\n\t});\n```\n\n### Upload a dicom directory to xnat\n\nCreate a script with the following code\n\n```javascript\n\tconst xnat = require('xnat-rest');\n\txnat.upload();\n```\n\nCall your script \n\n```bash\n\tnode yourscript.js -d /path/to/dicom/directory -p ProjectIdInXNAT\n```\n\n### User login to xnat instance:\n\n```javascript\n\n\tvar user = {\n\t\tuser: \"username\",\n\t\tpassword: \"password\"\n\t}\n\n\txnat.login(user)\n\t.then(function(){\n\t\tconsole.log(\"User is logged in.\")\n\t})\n\t.catch(function(err){\n\t\tconsole.error(\"Login failed\")\n\t});\n\n```\n\n### Dump dicom file in JSON format\n\n```javascript\n\txnat.dicomDump(filename)\n\t.then(function(jsonfile){\n\t\tconsole.log(jsonfile);\n\t});\n```\n\n\n### Get XNAT projects\n\nGet projects from xnat in json format\n\n```javascript\n\txnat.getProjects()\n\t.then(function(projects){\n\t\tconsole.log(projects);\n\t})\n```\n\n### Get XNAT subjects \n\nOptional parameters are projectid and subjectid.\n\n```javascript\n\n\txnat.getSubjects(projectid, subjectid)\n\t.then(function(subjects){\n\t\tconsole.log(subjects);\n\t});\n\n```\n\nRequired parameters when using function getSubject\n\n```javascript\n\txnat.getSubject(projectid, subjectid)\n\t.then(function(subject){\n\t\tconsole.log(subject);\n\t});\n```\n\n### Get XNAT experiments\n\nGet XNAT experiments, projectid is optional\n\n```javascript\n\txnat.getExperiments(projectid)\n\t.then(function(experiments){\n\t\tconsole.log(experiments);\n\t});\n```\n\n### Create subject\n\n```javascript\n\txnat.createSubject(projectid, subjectid)\n\t.then(function(res){\n\t\tconsole.log(res);\n\t})\n```\n\n### Upload dicom image\n\n```javascript\n\txnat.uploadImage(projectid, subjectid, sessionid, filename)\n\t.then(function(res){\n\t\tconsole.log(res);\n\t})\n```\n\n### Logout from xnat\n\n```javascript\n\txnat.logout()\n\t.then(function(){\n\t\tconsole.log(\"logout\");\n\t})\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuanprietob%2Fxnat-rest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuanprietob%2Fxnat-rest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuanprietob%2Fxnat-rest/lists"}