Skip to content

Commit

Permalink
Merge pull request #136 from pyplati/flask-rest-location
Browse files Browse the repository at this point in the history
Update location args for flask restful
  • Loading branch information
pchlap authored May 29, 2022
2 parents 6aede66 + 72ae660 commit 59270e6
Showing 1 changed file with 84 additions and 23 deletions.
107 changes: 84 additions & 23 deletions platipy/backend/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,28 @@ def get(self, task_id):
class DicomLocationEndpoint(Resource):

parser = reqparse.RequestParser()
parser.add_argument("name", required=True, help="Name to identify this Dicom location")
parser.add_argument("host", required=True, help="Dicom location host name or IP address")
parser.add_argument("port", type=int, required=True, help="The port of the Dicom location")
parser.add_argument("ae_title", help="AE Title of the Dicom location")
parser.add_argument(
"name",
required=True,
help="Name to identify this Dicom location",
location="args",
)
parser.add_argument(
"host",
required=True,
help="Dicom location host name or IP address",
location="args",
)
parser.add_argument(
"port",
type=int,
required=True,
help="The port of the Dicom location",
location="args",
)
parser.add_argument(
"ae_title", help="AE Title of the Dicom location", location="args"
)

def get(self):

Expand Down Expand Up @@ -144,23 +162,36 @@ def get(self):
class DataObjectEndpoint(Resource):

parser = reqparse.RequestParser()
parser.add_argument("dataset", required=True, help="Dataset ID to add Data Object to")
parser.add_argument(
"dataset",
required=True,
help="Dataset ID to add Data Object to",
location="args",
)
parser.add_argument(
"type",
choices=("DICOM", "FILE"),
required=True,
help="DICOM for Dicom objects to be fetched from the Dataset Dicom Location. FILE for file sent with request.",
location="args",
)
parser.add_argument(
"dicom_retrieve",
choices=("MOVE", "GET", "SEND"),
help="Used for DICOM type. The Dicom objects will be retrieved using this method.",
location="args",
)
parser.add_argument("seriesUID", location="args")
parser.add_argument("meta_data", location="args")
parser.add_argument("file_name", location="args")
parser.add_argument(
"file_data", type=werkzeug.datastructures.FileStorage, location="files"
)
parser.add_argument(
"parent",
help="Data Object ID to which this data object should be linked",
location="args",
)
parser.add_argument("seriesUID")
parser.add_argument("meta_data")
parser.add_argument("file_name")
parser.add_argument("file_data", type=werkzeug.datastructures.FileStorage, location="files")
parser.add_argument("parent", help="Data Object ID to which this data object should be linked")

def get(self, dataobject_id):

Expand Down Expand Up @@ -190,7 +221,9 @@ def post(self):
# Get the parent dataset if one was given
parent = None
if args["parent"]:
parent = DataObject.query.filter_by(dataset_id=ds.id, id=args["parent"]).first()
parent = DataObject.query.filter_by(
dataset_id=ds.id, id=args["parent"]
).first()

if not parent:
return {"Error": "Parent Data Object not found"}, 404
Expand Down Expand Up @@ -380,7 +413,9 @@ def get(self, dataobject_id):
return {"Error": "File could not be found, perhaps it has expired"}, 404

logger.info("Downloading file: {0}".format(f))
return send_from_directory(os.path.dirname(f), os.path.basename(f), as_attachment=True)
return send_from_directory(
os.path.dirname(f), os.path.basename(f), as_attachment=True
)

return {"Error": "Data Object not found"}, 404

Expand All @@ -399,10 +434,16 @@ class DatasetEndpoint(Resource):

parser = reqparse.RequestParser()
parser.add_argument(
"from_dicom_location", help="ID of DicomLocation from which to retrieve DICOM data",
"from_dicom_location",
help="ID of DicomLocation from which to retrieve DICOM data",
location="args",
)
parser.add_argument(
"to_dicom_location",
help="ID of DicomLocation the send output data to",
location="args",
)
parser.add_argument("to_dicom_location", help="ID of DicomLocation the send output data to")
parser.add_argument("timeout", type=int, default=24)
parser.add_argument("timeout", type=int, default=24, location="args")

def get(self, dataset_id):

Expand Down Expand Up @@ -473,20 +514,31 @@ def get(self):

result = []
for a in app.algorithms:
result.append({"name": a, "default_settings": app.algorithms[a].default_settings})
result.append(
{"name": a, "default_settings": app.algorithms[a].default_settings}
)
return result


class TriggerEndpoint(Resource):

parser = reqparse.RequestParser()
parser.add_argument("algorithm", required=True, help="The name of the algorithm to trigger")
parser.add_argument(
"dataset", required=True, help="The ID of the dataset to pass to the algorithm"
"algorithm",
required=True,
help="The name of the algorithm to trigger",
location="args",
)
parser.add_argument(
"dataset",
required=True,
help="The ID of the dataset to pass to the algorithm",
location="args",
)
parser.add_argument(
"config",
help="JSON configuration for algorithm. Default configuration will be used if not set.",
location="args",
)

def post(self):
Expand All @@ -495,7 +547,11 @@ def post(self):

if not args["algorithm"] in app.algorithms:
return (
{"Error": "No algorithm found with name: {0}".format(args["algorithm"])},
{
"Error": "No algorithm found with name: {0}".format(
args["algorithm"]
)
},
404,
)

Expand Down Expand Up @@ -541,12 +597,17 @@ def post(self):
api.add_resource(DatasetReadyEndpoint, "/api/dataset/ready/<string:dataset_id>")

api.add_resource(DataObjectsEndpoint, "/api/dataobjects")
api.add_resource(DataObjectEndpoint, "/api/dataobject", "/api/dataobject/<string:dataobject_id>")
api.add_resource(DataObjectDownloadEndpoint, "/api/dataobject/download/<string:dataobject_id>")
api.add_resource(
DataObjectEndpoint, "/api/dataobject", "/api/dataobject/<string:dataobject_id>"
)
api.add_resource(
DataObjectDownloadEndpoint, "/api/dataobject/download/<string:dataobject_id>"
)

api.add_resource(AlgorithmEndpoint, "/api/algorithm")

api.add_resource(
DicomLocationEndpoint, "/api/dicomlocation", "/api/dicomlocation/<string:dicom_location_id>",
DicomLocationEndpoint,
"/api/dicomlocation",
"/api/dicomlocation/<string:dicom_location_id>",
)

0 comments on commit 59270e6

Please sign in to comment.