scitran / core

RESTful API
https://scitran.github.io
MIT License
18 stars 18 forks source link

Add Modalities, Classification endpoints #1010

Open nagem opened 6 years ago

nagem commented 6 years ago

New endpoints:

GET /api/modalities - GET list of all modalities and their allowable classifications. GET /api/modalities/<modality_name> - GET a specific modality POST /api/modalities - Add a new modality. Required: _id (readable name) and classification, a map of allowable classifications. Requires superuser. Example request:

POST /api/modalities HTTP/1.1
Content-Type: application/json
{
    "_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"]
    }
}

PUT /api/modalities/<modality_name> - REPLACE a specific modality. Requires superuser. DELETE /api/modalities/<modality_name> - DELETE a specific modality. Requires superuser.

POST /api/<cont_name>/<cont_id>/files/<files_name>/classification - UPDATE an existing file's classification. Works similar to the info editing endpoint. Several options are allowed:

To push items to lists within classification, use add:

POST /api/acquisitions/0293840238/files/test.txt/classification
{
    "add": {
        "Contrast": ["B0"]
    }
}
# This will add "B0" to the "Contrast" key on the classification. It will create "Contrast" if the key does not exist and will not add "B0" if it is already in the list

To pull items from lists within classification, use delete:

POST /api/acquisitions/0293840238/files/test.txt/classification
{
    "delete": {
        "Intent": ["Structural"]
    }
}
# This will remove "Structural" from the "Intent" key on the classification. 

Note: add and delete can both be used in the same request.

To replace an entire classification, use replace:

POST /api/acquisitions/0293840238/files/test.txt/classification
{
    "replace": {
        "Contrast": ["B0", "Diffusion"]
        "Intent": ["Structural"]
    }
}
# This will set the `classification` key to the value of the `replace` key. 

Relevant Response Formats:

Success responses when editing a file (PUT /api/cont/cont_id/files/filename, POST /api/cont/cont_id/files/filename/info, POST /api/cont/cont_id/files/filename/classification) will be formatted like:

{
    'jobs_spawned': <int: number of jobs spawned because of this change>
}

Errors when attempting to edit a file's classification:

'Unknown modality. Classification must be set under "custom" key'
'Classification does not match format for modality <modality>. Unallowable key-value pairs: "key1:value1", "key1:value2", "key2:value1"'

TODO:

Breaking Changes:

Review Checklist

codecov-io commented 6 years ago

Codecov Report

Merging #1010 into master will increase coverage by 0.08%. The diff coverage is 94.77%.

@@            Coverage Diff             @@
##           master    #1010      +/-   ##
==========================================
+ Coverage   90.97%   91.05%   +0.08%     
==========================================
  Files          49       50       +1     
  Lines        7037     7145     +108     
==========================================
+ Hits         6402     6506     +104     
- Misses        635      639       +4
kofalt commented 6 years ago

@gsfr Just a head's up that this is a breaking change to gears and we should chat offline about our support strategy.

ryansanford commented 6 years ago

@nagem to make change to still pass measurements key for backwards compatibility. That behavior will be deprecated and removed in future.

nagem commented 6 years ago

@gsfr When should file modifications cause jobs to spawn? Info editing? Classification editing? Any editing?

nagem commented 6 years ago

@kofalt, @ambrussimon I am no longer fiddling with this and would appreciate your review when you have time available.