-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
30 lines (24 loc) · 966 Bytes
/
main.py
File metadata and controls
30 lines (24 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from flask import Flask, request, abort
from flask_restful import Resource, Api
from fhir.resources.humanname import HumanName
app = Flask(__name__)
api = Api(app)
@app.route('/humanname', methods=['GET'])
def humanname_api():
# convert request arg to dictionary
query = request.args.to_dict(flat=False)
# conver card. == 0..1 fields to a non-list
card1_field = ['use', 'text', 'family', 'period']
# for card 1 fields, validate input value numbers and tranform to non-iterable object
for field in card1_field:
# continue if field not passed in
if field not in query:
continue
# raise error if multiple values are passed in
if len(query[field]) > 1:
abort(400)
# convert to non-iterable item
query[field] = query[field][0]
return HumanName.parse_obj(query).json()
if __name__ == "__main__":
app.run(host = '0.0.0.0',port=5000)