def get_all_prescriptions(patient_id): try: logging.info("received request from patients for all prescriptions") return prescriptions.get(patient_id=patient_id) except BaseException as bex: logging.error(bex.message) return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def all_requests(patient_id): try: logging.info("received request from patients for all pending requests") return request_documents.get(patient_id=patient_id) except BaseException as bex: logging.error(bex.message) return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def get_prescription_details(prescription_id): try: requester_id = request.args.get("requester_id") logging.info("received request from doctor for details prescription") return prescriptions.get_detail(prescription_id=prescription_id, requester_id=requester_id) except BaseException as bex: logging.error(bex.message) return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def get_all_requests(self, patient_id): query = "select * from permission_requests where " \ "patient_id = " + str(patient_id) + \ ";" cur = self.conn.cursor() cur.execute(query) list = cur.fetchall() data = serializer(data=list, table_schema=schema["medical_records"]) logging.info(" served all requests for patient") return data
def get_doctors(self, doctor_id): query = "select * from doctors where " \ "id = " + str(doctor_id) + \ ";" cur = self.conn.cursor() cur.execute(query) list = cur.fetchall() data = serializer(data=list, table_schema=schema["doctors"]) logging.info("served doctor by its id") return data
def get_pharmacists(self, pharmacist_id): query = "select * from pharmacists where " \ "id = " + str(pharmacist_id) + \ ";" cur = self.conn.cursor() cur.execute(query) list = cur.fetchall() data = serializer(data=list, table_schema=schema["pharmacists"]) logging.info("served pharmacist by its id") return data
def get_prescription(self, prescription_id): query = "select * from prescriptions where " \ "id = " + str(prescription_id) +\ ";" cur = self.conn.cursor() cur.execute(query) rows = cur.fetchone() details = serializer(data=rows, table_schema=schema["prescriptions"]) logging.info("retrived prescriptions from id") return details
def prescriptions_by_patient_id(self, patient_id): query = "select * from medical_records where " \ "patient_id = " + str(patient_id) + \ ";" cur = self.conn.cursor() cur.execute(query) list = cur.fetchall() data = serializer(data=list, table_schema=schema["medical_records"]) logging.info("served all medical_records of given patient") return data
def remove_permission(self, requester_id, patient_id, prescription_id, req_type): query = "delete from permissions where " \ "requester_id = '" + str(requester_id) + \ "'and patient_id = '" + str(patient_id) + \ "'and prescription_id = '" + str(prescription_id) + \ "'and requester_type = '" + req_type + \ "';" cur = self.conn.cursor() cur.execute(query) logging.info(" delete permission request into DB") return True
def get_prescription_for_patient(requester_id): try: logging.info( "received request from doctor for prescriptions of patient") patient_id = request.args.get("patient_id") req_type = request.args.get("req_type") return documents.get(requester_id=requester_id, patient_id=patient_id, req_type=req_type) except BaseException as bex: logging.error(bex.message) return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def grant_request(self, requester_id, patient_id, prescription_id, req_type): query = "insert into permissions (requester_id, patient_id, prescription_id,requester_type) " \ "values ('" + str(requester_id) + \ "','" + str(patient_id) + \ "','" + str(prescription_id) + \ "','" + req_type + \ "');" cur = self.conn.cursor() cur.execute(query) logging.info(" Insert permission request into DB") return True
def get_prescriptions(self, requester_id, patient_id, requester_type): query = "select * from permissions where " \ "requester_id = " + str(requester_id) + \ " and patient_id = " + str(patient_id) + \ " and requester_type = '" + str(requester_type) + \ "';" cur = self.conn.cursor() cur.execute(query) list = cur.fetchall() data = serializer(data=list, table_schema=schema["permissions"]) logging.info(" served prescription to doctors about patients") return data
def create_requests(requester_id): try: logging.info("received request for document permission") patient_id = request.form["patient_id"] req_type = request.form["req_type"] doc_type = request.form["doc_type"] return request_documents.post(requester_id=requester_id, patient_id=patient_id, req_type=req_type, doc_type=doc_type) except BaseException as bex: logging.error(bex.message) return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def reject_permissions(patient_id): try: logging.info("grant permission to requestee by patient") requester_id = request.form["requester_id"] req_type = request.form["req_type"] doc_type = request.form["doc_type"] return grant_requests.delete(requester_id=requester_id, patient_id=patient_id, req_type=req_type, doc_type=doc_type) except BaseException as bex: logging.error(bex.message) return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def remove_requests(self, requester_id, patient_id, req_type, doc_type): try: query = "delete from permission_requests where requester_id ='" + str(requester_id) + \ "'and patient_id ='" + str(patient_id) + \ "'and requester_type = '" + req_type + \ "'and doc_type = '" + doc_type + \ "';" cur = self.conn.cursor() cur.execute(query) logging.info(" remove permission request from DB") return True except BaseException as bex: logging.error(bex.message) return False
def remove_grant_permissions(patient_id): try: logging.info("remove grant permission to requestee by patient") requester_id = request.form["requester_id"] prescription_id = request.form["prescription_id"] req_type = request.form["req_type"] return grant_requests.remove_permission( requester_id=requester_id, patient_id=patient_id, prescription_id=prescription_id, req_type=req_type) except BaseException as bex: logging.error(bex.message) return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def create_request(self, requester_id, patient_id, requester_type, doc_type): try: query = "insert into permission_requests (requester_id, patient_id, requester_type, doc_type) " \ "values ('" + str(requester_id) + \ "','" + str(patient_id) + \ "','" + requester_type + \ "','" + doc_type + \ "');" cur = self.conn.cursor() cur.execute(query) logging.info(" Insert permission request into DB") return True except BaseException as bex: logging.error(bex.message) return False