def get(self, project_uuid, path): """ Get a aggregated overview of project data: """ q = { "aggs": { "by_userid": { "terms": { "field": "_user" }, "aggs": { "overall": { "avg": { "field": "overall", "missing": 0 } }, } } } } try: scroll = "1m" response = es.search(index="symptoms-index", doc_type="project", body=q, scroll=scroll) return jsonify(response["aggregations"]["by_userid"]["buckets"][0]) except: return jsonify([])
def create_default_doctor(data): data["roles"] = {"doctor": True} data["password"] = generate_password_hash(data["password"].encode()) doc = {'size': 10000, 'query': {'match_all': {}}} scroll = "1m" try: response = es.search(index="users-index", doc_type="user", body=doc, scroll=scroll, id=data["user_name"]) if response["hits"]["total"] > 0: # Admin already exists print("Default doctor already exists") return except: print("Create new default doctor user") # create the new user resp = es.index(index="users-index", doc_type="user", body=data, id=data["user_name"]) return resp
def read_all(self, generic_index, generic_type, scroll, sort): doc = {'size': 10000, 'query': {'match_all': {}}} print(generic_index, generic_type) response = es.search(index=generic_index, doc_type=generic_type, body=doc, scroll=scroll, sort=sort) return response
def get_admin_by_name(self, name): q = {"query": {"bool": {"must": [{"match_phrase": {"name": name}}]}}} scroll = "1m" try: response = es.search(index="users-index", doc_type="user", body=q, scroll=scroll) except: return [] # if response["hits"]["total"] > 0: # for user in response["hits"]["hits"]: # user["_source"].pop("password") return response["hits"]["hits"]
def get_all_admins(self): doc = {'size': 10000, 'query': {'match_all': {}}} scroll = "1m" try: response = es.search(index="users-index", doc_type="user", body=doc, scroll=scroll) except: return [] if response["hits"]["total"] > 0: for user in response["hits"]["hits"]: user["_source"].pop("password") return response["hits"]["hits"]
def get(self): """ Read all generic objects :return: """ q = {"query": {"term": {"roles.patient": True}}} scroll = "1m" try: response = es.search(index="users-index", doc_type="user", body=q, scroll=scroll) except: return [] return jsonify(response["hits"]["hits"])
def get_user_by_guid(self, guid): q = {"query": {"bool": {"must": [{"match": {"_id": guid}}]}}} scroll = "1m" try: response = es.search(index="users-index", doc_type="user", body=q, scroll=scroll) except: return [] if response["hits"]["total"] > 0: for user in response["hits"]["hits"]: user["_source"].pop("password") return response["hits"]["hits"]
def read_single_with_query(self, generic_index, generic_type, query): response = es.search(index=generic_index, doc_type=generic_type, body=query) return response
def read_single(self, generic_index, generic_type, guid): response = es.search(index=generic_index, doc_type=generic_type, id=guid) return response
def read_all_with_query(self, generic_index, generic_type, query): print(query) response = es.search(index=generic_index, doc_type=generic_type, body=query) return response
def get(self, patientID): q = { "aggs": { "by_userid": { "terms": { "field": "_user" }, "aggs": { "overall": { "avg": { "field": "overall", "missing": 0 } }, "swelling_of_feed": { "avg": { "field": "swelling_of_feed", "missing": 0 } }, "pain_other": { "avg": { "field": "pain_other", "missing": 0 } }, "blood_in_urine": { "avg": { "field": "blood_in_urine", "missing": 0 } }, "pain_whilst_sitting": { "avg": { "field": "pain_whilst_sitting", "missing": 0 } }, "weight_loss": { "avg": { "field": "weight_loss", "missing": 0 } }, "burning_during_urination": { "avg": { "field": "burning_during_urination", "missing": 0 } }, "fatigue": { "avg": { "field": "fatigue", "missing": 0 } }, } } } } try: scroll = "1m" response = es.search(index="symptoms-index", doc_type="symptom", body=q, scroll=scroll) return jsonify(response["aggregations"]["by_userid"]["buckets"][0]) except: return jsonify([])