A custom form definition, also known as, form schema, is stored in XNAT as a JSON. Importing and exporting a custom form definition involves handling the JSON representing the form schema.
Note that at this point, the following advanced tracking features for custom form importing are not supported:
Form versioning
Form authoring
Restricting editing on an imported form
Saving to or importing from a form repository
There are two ways to import a form definition, viz. using the XNAT Form Builder or the Custom Form API.
While importing a form definition using the API, you will have to make sure that:
Using the API to import a form definition involves providing the meta-data about the form, that is,
A PUT to the endpoint xapi/customforms/save will save the form definition. A response of 201 implies that the form has been saved successfully and the API returns the form UUID assigned to the form.
curl -u XNAT_USER_NAME:PASSWORD -X PUT "YOUR_XNAT_URL_HERE/xapi/customforms/save" -H "Content-Type: application/json;charset=UTF-8" -d FORM_JSON_WITH_METADATA_HERE
The following json with form metadata, is a form that applies to the Subject datatype (lines 6-9), is not a site wide form (line 10) and applies to the project proj2 (lines 11-16). Line 19 onwards is the form schema.
{
"submission": {
"data": {
"zIndex": 10,
"xnatDatatype": {
"label": "Subject",
"value": "xnat:subjectData"
},
"isThisASiteWideConfiguration": "no",
"xnatProject": [
{
"label": "proj2",
"value": "proj2"
}
]
}
},
"builder": {
"display": "form",
"title": "Imported Form",
"settings": {},
"components": [
{
"label": "Text Field 01",
"key": "textField01",
"type": "textfield",
"input": true,
"tableView": true
}
]
}
}
A curl call to save the above json would look like:
curl -u XNAT_USER_NAME:PASSWORD -X PUT "YOUR_XNAT_URL_HERE/xapi/customforms/save" -H "Content-Type: application/json;charset=UTF-8" -d "{\"submission\":{\"data\":{\"zIndex\":10,\"xnatDatatype\":{\"label\":\"Subject\",\"value\":\"xnat:subjectData\"},\"isThisASiteWideConfiguration\":\"no\",\"xnatProject\":[{\"label\":\"proj2\",\"value\":\"proj2\"}]}},\"builder\":{\"display\":\"form\",\"title\":\"Imported Form\",\"settings\":{},\"components\":[{\"label\":\"Text Field 01\",\"key\":\"textField01\",\"type\":\"textfield\",\"input\":true,\"tableView\":true}]}}"
Like importing a form definition, exporting a form definition can be done using the XNAT Form Builder or the Custom Form API. However, using the Custom Form API is a more involved process and we would not recommend to the use the API to export the form.