From eb909404da6d6f19c72eaca33ea9ad8acb98c00e Mon Sep 17 00:00:00 2001 From: Megan Henning Date: Tue, 21 Feb 2017 11:25:46 -0600 Subject: [PATCH] Add modality raml --- api/config.py | 1 + raml/api.raml | 1 + raml/examples/input/modality-new.json | 8 ++ raml/examples/input/modality-update.json | 7 ++ raml/examples/output/modality-list.json | 10 +++ raml/examples/output/modality.json | 8 ++ raml/resources/modalities.raml | 77 +++++++++++++++++++ raml/schemas/definitions/modality.json | 30 ++++++++ raml/schemas/input/modality.json | 5 ++ raml/schemas/output/modality-list.json | 8 ++ raml/schemas/output/modality.json | 5 ++ .../integration_tests/abao/abao_test_hooks.js | 51 ++++++++++++ 12 files changed, 211 insertions(+) create mode 100644 raml/examples/input/modality-new.json create mode 100644 raml/examples/input/modality-update.json create mode 100644 raml/examples/output/modality-list.json create mode 100644 raml/examples/output/modality.json create mode 100644 raml/resources/modalities.raml create mode 100644 raml/schemas/definitions/modality.json create mode 100644 raml/schemas/input/modality.json create mode 100644 raml/schemas/output/modality-list.json create mode 100644 raml/schemas/output/modality.json diff --git a/api/config.py b/api/config.py index 36db429e7..d78148357 100644 --- a/api/config.py +++ b/api/config.py @@ -141,6 +141,7 @@ def apply_env_variables(config): 'file.json', 'group-new.json', 'group-update.json', + 'modality.json', 'note.json', 'packfile.json', 'permission.json', diff --git a/raml/api.raml b/raml/api.raml index 4d1aeeb64..32438df4a 100644 --- a/raml/api.raml +++ b/raml/api.raml @@ -51,6 +51,7 @@ resourceTypes: /gears: !include resources/gears.raml /devices: !include resources/devices.raml /rules: !include resources/rules.raml +/modalities: !include resources/modalities.raml /groups: !include resources/groups.raml /collections: !include resources/collections.raml /sessions: !include resources/sessions.raml diff --git a/raml/examples/input/modality-new.json b/raml/examples/input/modality-new.json new file mode 100644 index 000000000..19aebadf6 --- /dev/null +++ b/raml/examples/input/modality-new.json @@ -0,0 +1,8 @@ +{ + "_id": "MR", + "classifications": { + "Contrast": ["B0", "B1", "T1", "T2", "T2*", "PD", "MT", "ASL", "Perfusion", "Diffusion", "Spectroscopy", "Susceptibility", "Velocity", "Fingerprinting"], + "Intent": ["Structural", "Functional", "Localizer", "Shim", "Calibration"], + "Features": ["Quantitative", "Multi-Shell", "Multi-Echo", "Multi-Flip", "Multi-Band", "Steady-State", "3D", "Compressed-Sensing", "Eddy-Current-Corrected", "Fieldmap-Corrected", "Gradient-Unwarped", "Motion-Corrected", "Physio-Corrected"] + } +} diff --git a/raml/examples/input/modality-update.json b/raml/examples/input/modality-update.json new file mode 100644 index 000000000..9e5f424d7 --- /dev/null +++ b/raml/examples/input/modality-update.json @@ -0,0 +1,7 @@ +{ + "classifications": { + "Contrast": ["B0", "B1", "T1", "T2", "T2*", "PD", "MT", "ASL", "Perfusion", "Diffusion", "Spectroscopy", "Susceptibility", "Velocity", "Fingerprinting"], + "Intent": ["Structural", "Functional", "Localizer", "Shim", "Calibration"], + "Features": ["Quantitative", "Multi-Shell", "Multi-Echo", "Multi-Flip", "Multi-Band", "Steady-State", "3D", "Compressed-Sensing", "Eddy-Current-Corrected", "Fieldmap-Corrected", "Gradient-Unwarped", "Motion-Corrected", "Physio-Corrected"] + } +} diff --git a/raml/examples/output/modality-list.json b/raml/examples/output/modality-list.json new file mode 100644 index 000000000..59671c57a --- /dev/null +++ b/raml/examples/output/modality-list.json @@ -0,0 +1,10 @@ +[ + { + "_id": "MR", + "classifications": { + "Contrast": ["B0", "B1", "T1", "T2", "T2*", "PD", "MT", "ASL", "Perfusion", "Diffusion", "Spectroscopy", "Susceptibility", "Velocity", "Fingerprinting"], + "Intent": ["Structural", "Functional", "Localizer", "Shim", "Calibration"], + "Features": ["Quantitative", "Multi-Shell", "Multi-Echo", "Multi-Flip", "Multi-Band", "Steady-State", "3D", "Compressed-Sensing", "Eddy-Current-Corrected", "Fieldmap-Corrected", "Gradient-Unwarped", "Motion-Corrected", "Physio-Corrected"] + } + } +] diff --git a/raml/examples/output/modality.json b/raml/examples/output/modality.json new file mode 100644 index 000000000..19aebadf6 --- /dev/null +++ b/raml/examples/output/modality.json @@ -0,0 +1,8 @@ +{ + "_id": "MR", + "classifications": { + "Contrast": ["B0", "B1", "T1", "T2", "T2*", "PD", "MT", "ASL", "Perfusion", "Diffusion", "Spectroscopy", "Susceptibility", "Velocity", "Fingerprinting"], + "Intent": ["Structural", "Functional", "Localizer", "Shim", "Calibration"], + "Features": ["Quantitative", "Multi-Shell", "Multi-Echo", "Multi-Flip", "Multi-Band", "Steady-State", "3D", "Compressed-Sensing", "Eddy-Current-Corrected", "Fieldmap-Corrected", "Gradient-Unwarped", "Motion-Corrected", "Physio-Corrected"] + } +} diff --git a/raml/resources/modalities.raml b/raml/resources/modalities.raml new file mode 100644 index 000000000..a138eb029 --- /dev/null +++ b/raml/resources/modalities.raml @@ -0,0 +1,77 @@ +description: Utility functions for modalities and their acceptable classifications. +get: + description: | + List all modalities and their classifications. + Requires login. + responses: + 200: + body: + application/json: + example: !include ../examples/output/modality-list.json + schema: !include ../schemas/output/modality-list.json +post: + description: | + Insert a modality type and its classifications map. + Requires admin. + body: + application/json: + example: !include ../examples/input/modality-new.json + schema: !include ../schemas/input/modality.json + responses: + 200: + body: + application/json: + example: | + { + "inserted": "1" + } + +/{ModalityName}: + description: Perform actions with a specific modality + uriParameters: + ModalityName: + type: string + get: + description: | + Get modality details. + Requires login. + responses: + 200: + body: + application/json: + example: !include ../examples/output/modality.json + schema: !include ../schemas/output/modality.json + 404: + description: Modality not found + put: + description: | + Replace a modality's classifications map. + Requires admin. + body: + application/json: + example: !include ../examples/input/modality-update.json + schema: !include ../schemas/input/modality.json + responses: + 200: + body: + application/json: + example: | + { + "modified": "1" + } + 404: + description: Modality not found + delete: + description: | + Remove a modality. + Requires admin. + responses: + 200: + body: + application/json: + example: | + { + "modified": "1" + } + 404: + description: Modality not found diff --git a/raml/schemas/definitions/modality.json b/raml/schemas/definitions/modality.json new file mode 100644 index 000000000..cc8cab0bf --- /dev/null +++ b/raml/schemas/definitions/modality.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "definitions": { + "_id": { + "maxLength": 64, + "minLength": 2, + "pattern": "^[0-9a-zA-Z_-]*$" + }, + "classifications": { + "type": "object", + "patternProperties": { + "^[0-9a-zA-Z_-]*$":{ + "type": "array", + "items": { + "type": "string" + } + }, + }, + }, + "modality":{ + "type": "object", + "properties": { + "_id": {"$ref":"#/definitions/_id"}, + "classifications": {"$ref":"#/definitions/classifications"} + }, + "additionalProperties": false + } + } +} diff --git a/raml/schemas/input/modality.json b/raml/schemas/input/modality.json new file mode 100644 index 000000000..416053171 --- /dev/null +++ b/raml/schemas/input/modality.json @@ -0,0 +1,5 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "allOf":[{"$ref":"../definitions/modality.json#/definitions/modality"}], + "required": ["classifications"] +} diff --git a/raml/schemas/output/modality-list.json b/raml/schemas/output/modality-list.json new file mode 100644 index 000000000..08340eff8 --- /dev/null +++ b/raml/schemas/output/modality-list.json @@ -0,0 +1,8 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type":"array", + "items":{ + "allOf":[{"$ref":"../definitions/modality.json#/definitions/modality"}], + "required":["_id", "classifications"] + } +} diff --git a/raml/schemas/output/modality.json b/raml/schemas/output/modality.json new file mode 100644 index 000000000..5edcd7149 --- /dev/null +++ b/raml/schemas/output/modality.json @@ -0,0 +1,5 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "allOf":[{"$ref":"../definitions/modality.json#/definitions/modality"}], + "required": ["_id", "classifications"] +} diff --git a/test/integration_tests/abao/abao_test_hooks.js b/test/integration_tests/abao/abao_test_hooks.js index a4baa3ff8..6a45b86c2 100644 --- a/test/integration_tests/abao/abao_test_hooks.js +++ b/test/integration_tests/abao/abao_test_hooks.js @@ -23,6 +23,7 @@ var test_project_1 = null; var test_project_tag = 'test-project-tag'; var delete_project_id = ''; var device_id = 'bootstrapper_Bootstrapper' +var modality_name = 'MR' // Tests we're skipping, fix these @@ -1493,3 +1494,53 @@ hooks.before("GET /devices/{DeviceId} -> 404", function(test, done) { test.request.params.DeviceId = 'bad_device_id'; done(); }); + +hooks.before("GET /modalities/{ModalityName} -> 200", function(test, done) { + test.request.params.ModalityName = modality_name; + done(); +}); + +hooks.before("GET /modalities/{ModalityName} -> 404", function(test, done) { + test.request.params.ModalityName = 'bad_modality_name'; + done(); +}); + +hooks.before("POST /modalities/ -> 200", function(test, done) { + test.request.body = { + "_id":"MR", + "classifications": { + "intent": ["functional"] + } + } + done(); +}); + +hooks.before("PUT /modalities/{ModalityName} -> 200", function(test, done) { + test.request.params.ModalityName = modality_name; + test.request.body = { + "classifications": { + "intent": ["localizer"] + } + } + done(); +}); + +hooks.before("PUT /modalities/{ModalityName} -> 404", function(test, done) { + test.request.params.ModalityName = 'bad_modality_name'; + test.request.body = { + "classifications": { + "intent": ["localizer"] + } + } + done(); +}); + +hooks.before("DELETE /modalities/{ModalityName} -> 200", function(test, done) { + test.request.params.ModalityName = modality_name; + done(); +}); + +hooks.before("DELETE /modalities/{ModalityName} -> 404", function(test, done) { + test.request.params.ModalityName = 'bad_modality_name'; + done(); +});