-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
169 lines (143 loc) · 4.77 KB
/
app.py
File metadata and controls
169 lines (143 loc) · 4.77 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import logging
from datetime import datetime
# import utils.html_markup as markup
# from config.config_rw import ConfigRW
from dashboards.nlp_dashboard import NlpDashboard
from flask import Flask
from flask import jsonify
from flask import redirect
from flask import render_template
from flask import request
from flask import url_for
from flask_cors import CORS
from inMemoryData.InMemoryManager import InMemoryManager
from inMemoryData.InMemoryManager import ActivityNote
import definitions
# from definitions import Settings
from utils.print_enh import print_begin
from utils.print_enh import print_end
import pandas as pdb
# think of using connexion for swagger implementation
app = Flask(__name__,
template_folder=f'{definitions.get_project_root()}/web',
static_folder=f'{definitions.get_project_root()}/web')
CORS(app)
my_ip_address = definitions.get_ip_address()
imm = InMemoryManager()
# def start_app() -> None:
current_logger = definitions.setup_logger(__name__, level=logging.DEBUG)
@app.route('/status')
def hello_world():
"""
See if the application is up and running.
:return: nothing
---
tag:
- status
"""
return f'<b>Hello World!</b> I\'m alive. prior_auth<p>'
@app.route('/', methods=['GET', 'POST'])
def login():
"""
Login
:return: redirects to the page
---
tag:
- login
"""
error = None
try:
user_name = request.form['userName']
except Exception:
user_name = ''
print_begin()
if request.method == 'POST' and user_name:
return redirect(url_for('main_page', display_name=user_name))
return render_template('login.html', error=error, user_name=user_name)
@app.route('/main_page/<display_name>')
def main_page(display_name):
"""
:param display_name:hwo to get requirements.
:return:
---
tags:
- main page
"""
# config_rw = ConfigRW(Settings.PRIOR_AUTH_SETTINGS.value)
print_begin()
ip_address = definitions.get_ip_address()
# server_options = markup.server_options(ip_address)
return render_template('DashboardPriorAuth.html', error=None,
def_server_option=ip_address,
display_name=display_name,
)
dashboard = NlpDashboard()
@app.route('/basic/<method_call>', methods=['POST'])
def main_dashboard(method_call):
"""
Main application call
:param method_call:
:return:
---
tags:
- main dashboard
"""
return dashboard.post(method_call)
@app.route('/search', methods=['GET', 'POST'])
def search_data():
"""
search for data with in pandas
:param speech_text:
:return:
---
tags:
- search text
"""
if request.method == "POST":
if not request.is_json:
return jsonify({"msg": "Missing JSON in request"}), 400
# {"author":"Roland","speech_text":"sister-in-law, Jill"}
author = request.json.get("author", None)
speech_text = request.json.get("speech_text", None)
else:
author = request.args.get('author')
speech_text = request.args.get('speech_text')
if not author:
return jsonify({"msg": "Missing author parameter"}), 400
if not speech_text:
return jsonify({"msg": "Missing search parameter"}), 400
InMemoryManager.dataframes_load(str(author))
return jsonify({"speech_text": f'{imm.dataframes_search(str(speech_text))}'}), 200
@app.route('/post', methods=['GET', 'POST'])
def post_data():
"""
search for data with in pandas
:param speech_text:
:return:
---
tags:
- search text
"""
if request.method == "POST":
if not request.is_json:
return jsonify({"msg": "Missing JSON in request"}), 400
author = request.json.get("author", None)
mbr_id = request.json.get("mbr_id", None)
case_id = request.json.get("case_id", None)
activity_type = request.json.get("activity_type", None)
note = request.json.get("note", None)
else:
author = request.args.get('author')
mbr_id = request.args.get('mbr_id')
case_id = request.args.get('case_id')
activity_type = request.args.get('activity_type')
note = request.args.get('note')
if not author:
return jsonify({"msg": "Missing author parameter"}), 400
if not activity_type:
return jsonify({"msg": "Missing activity parameter"}), 400
if not note:
return jsonify({"msg": "Missing note parameter"}), 400
my_activity = ActivityNote(Author=author, Mbr_Id=mbr_id, Case_Id=case_id, Activity_Type=activity_type, Note=note,
Date_Time=datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
return jsonify({"note added = ": f'{imm.workbook_add(my_activity)}'}), 200