diff --git a/epochs.py b/epochs.py index 14ef8273928d057c24548d4a92e8701f802e635d..fb62300dda39543e851497b755c6690b14ade99b 100644 --- a/epochs.py +++ b/epochs.py @@ -4,6 +4,7 @@ import json import webapp2 import bson.json_util +import nimsdata import nimsapiutil @@ -85,123 +86,12 @@ class Epoch(nimsapiutil.NIMSRequestHandler): '_id': { 'title': 'Database ID', }, - 'session': { - 'title': 'Session ID', - }, - 'timestamp': { - 'title': 'Timestamp', - }, - 'session_uid': { - 'title': 'DICOM UID', - 'type': 'string', - }, - 'datatype': { - 'title': 'Datatype', - 'type': 'string', - }, - 'series': { - 'title': 'Series', - 'type': 'integer', - }, - 'acquisition': { - 'title': 'Acquisition', - 'type': 'integer', - }, - 'description': { - 'title': 'Description', + 'uid': { + 'title': 'UID', 'type': 'string', - 'maxLength': 64, }, - 'protocol': { - 'title': 'Protocol', - 'type': 'string', - 'maxLength': 64, - }, - 'rx_coil': { - 'title': 'Coil', - 'type': 'string', - 'maxLength': 64, - }, - 'device': { - 'title': 'Device', - 'type': 'string', - 'maxLength': 64, - }, - 'size': { - 'title': 'Size', - 'type': 'array', - 'items': { - 'type': 'integer', - } - }, - 'acquisition_matrix': { - 'title': 'Acquisition Matrix', - 'type': 'array', - 'items': { - 'type': 'number', - } - }, - 'fov': { - 'title': 'Field of View', - 'type': 'array', - 'items': { - 'type': 'number', - } - }, - 'mm_per_voxel': { - 'title': 'mm per Voxel', - 'type': 'array', - 'items': { - 'type': 'number', - } - }, - 'flip_angle': { - 'title': 'Flip Angle', - 'type': 'integer', - }, - 'num_averages': { - 'title': 'Averages', - 'type': 'integer', - }, - 'num_bands': { - 'title': 'Bands', - 'type': 'integer', - }, - 'num_echos': { - 'title': 'Echos', - 'type': 'integer', - }, - 'num_slices': { - 'title': 'Slices', - 'type': 'integer', - }, - 'num_timepoints': { - 'title': 'Time Points', - 'type': 'integer', - }, - 'pixel_bandwidth': { - 'title': 'Pixel Bandwidth', - 'type': 'number', - }, - 'prescribed_duration': { - 'title': 'Prescribed Duration', - 'type': 'number', - }, - 'duration': { - 'title': 'Duration', - 'type': 'number', - }, - 'slice_encode_undersample': { - 'title': 'Slice Encode Undersample', - 'type': 'integer', - }, - 'te': { - 'title': 'Te', - 'type': 'number', - }, - 'tr': { - 'title': 'Tr', - 'type': 'number', + 'session': { + 'title': 'Session ID', }, 'files': { 'title': 'Files', @@ -213,6 +103,12 @@ class Epoch(nimsapiutil.NIMSRequestHandler): 'required': ['_id'], } + def schema(self, *args, **kwargs): + import copy + json_schema = copy.deepcopy(self.json_schema) + json_schema['properties'].update(nimsdata.nimsdicom.NIMSDicom.epoch_properties) + self.response.write(json.dumps(json_schema, default=bson.json_util.default)) + def get(self, eid): """Return one Epoch, conditionally with details.""" epoch = self.app.db.epochs.find_one({'_id': bson.objectid.ObjectId(eid)}) diff --git a/experiments.py b/experiments.py index c59785790ed8412b910a51779f2c3445b4903368..cb3a7fd1fca1f9e6fc05aad7325e3e55969ba116 100644 --- a/experiments.py +++ b/experiments.py @@ -22,17 +22,21 @@ class Experiments(nimsapiutil.NIMSRequestHandler): '_id': { 'title': 'Database ID', }, - 'firstname': { - 'title': 'First Name', - 'type': 'string', + 'timestamp': { + 'title': 'Timestamp', }, - 'lastname': { - 'title': 'Last Name', + 'group': { + 'title': 'Group', 'type': 'string', }, - 'email_hash': { + 'name': { + 'title': 'Name', 'type': 'string', }, + 'permissions': { + 'title': 'Permissions', + 'type': 'object', + }, } } } diff --git a/nimsapi.wsgi b/nimsapi.wsgi index 92ea735cd4e2f1eb7fdae127fe5deea7314e84f1..8f7b59ae06b0e0c7d4c2be599ae552a72471ade1 100644 --- a/nimsapi.wsgi +++ b/nimsapi.wsgi @@ -16,18 +16,20 @@ import webapp2 import nimsapi import nimsutil -logfile = '/var/local/log/nimsapi.log' +log_file = '/var/local/log/nimsapi.log' +pubkey_file = '/var/local/nims/internims/internims.pub' db_uri = 'mongodb://nims:cnimr750@cnifs.stanford.edu,cnibk.stanford.edu/nims?replicaSet=cni' stage_path = '/scratch/upload' -nimsutil.configure_log(logfile, False) +nimsutil.configure_log(log_file, False) db_client = pymongo.MongoReplicaSetClient(db_uri) if 'replicaSet' in db_uri else pymongo.MongoClient(db_uri) try: - pubkey = open('/var/local/nims/internims/NIMSpubkey.pub').read() -except IOError as e: + pubkey = open(pubkey_file).read() # FIXME: don't read too much + # FIXME: verify that this is a valid public key +except IOError: pubkey = None application = nimsapi.app -application.config = dict(stage_path=stage_path, site_id='demo_nims_coronal2', pubkey=pubkey) +application.config = dict(stage_path=stage_path, site_id='stanford-cni', pubkey=pubkey) application.db = db_client.get_default_database() diff --git a/nimsapiutil.py b/nimsapiutil.py index bc8f2827e617ac3f1062eafab3a938eb3c018dc7..c44e6e26bf12535047c7d56e111c3b9c07d6d532 100644 --- a/nimsapiutil.py +++ b/nimsapiutil.py @@ -144,4 +144,4 @@ class NIMSRequestHandler(webapp2.RequestHandler): self.response.write(r.content) def schema(self, *args, **kwargs): - self.response.write(json.dumps(self.json_schema, default=bson.json_util.default)) \ No newline at end of file + self.response.write(json.dumps(self.json_schema, default=bson.json_util.default)) diff --git a/sessions.py b/sessions.py index d0c43ce497be85b932dffe2af7c40a3c25300e09..a86cc17a98477758c370301be0353aca11767c7d 100644 --- a/sessions.py +++ b/sessions.py @@ -4,6 +4,7 @@ import json import webapp2 import bson.json_util +import nimsdata import nimsapiutil @@ -70,35 +71,20 @@ class Session(nimsapiutil.NIMSRequestHandler): '_id': { 'title': 'Database ID', }, + 'uid': { + 'title': 'UID', + 'type': 'string', + }, 'experiment': { 'title': 'Experiment ID', }, 'timestamp': { 'title': 'Timestamp', }, - 'uid': { - 'title': 'DICOM UID', - 'type': 'string', - }, - 'firstname': { - 'title': 'First Name', - 'type': 'string', - }, - 'lastname': { - 'title': 'Last Name', - 'type': 'string', - }, - 'patient_id': { - 'title': 'Patient ID', - 'type': 'string', - }, 'subject': { 'title': 'Subject Code', 'type': 'string', - }, - 'exam': { - 'title': 'Exam Number', - 'type': 'integer', + 'maxLength': 16, }, 'files': { 'title': 'Files', @@ -110,6 +96,12 @@ class Session(nimsapiutil.NIMSRequestHandler): 'required': ['_id', 'experiment', 'uid', 'patient_id', 'subject'], } + def schema(self, *args, **kwargs): + import copy + json_schema = copy.deepcopy(self.json_schema) + json_schema['properties'].update(nimsdata.NIMSData.session_properties) + self.response.write(json.dumps(json_schema, default=bson.json_util.default)) + def get(self, sid): """Return one Session, conditionally with details.""" session = self.app.db.sessions.find_one({'_id': bson.objectid.ObjectId(sid)})